123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799 |
- "use strict";
- /**
- * Copyright 2022 Google LLC.
- * Copyright (c) Microsoft Corporation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- Object.defineProperty(exports, "__esModule", { value: true });
- exports.Input = exports.Session = exports.Cdp = exports.BrowsingContext = exports.Script = exports.CommonDataTypes = exports.parseObject = void 0;
- /**
- * @fileoverview Provides parsing and validator for WebDriver BiDi protocol.
- * Parser types should match the `../protocol` types.
- */
- const zod_1 = require("zod");
- const protocol_js_1 = require("../protocol/protocol.js");
- const MAX_INT = 9007199254740991;
- function parseObject(obj, schema) {
- const parseResult = schema.safeParse(obj);
- if (parseResult.success) {
- return parseResult.data;
- }
- const errorMessage = parseResult.error.errors
- .map((e) => `${e.message} in ` +
- `${e.path.map((p) => JSON.stringify(p)).join('/')}.`)
- .join(' ');
- throw new protocol_js_1.Message.InvalidArgumentException(errorMessage);
- }
- exports.parseObject = parseObject;
- const UnicodeCharacterSchema = zod_1.z.string().refine((value) => {
- // The spread is a little hack so JS gives us an array of unicode characters
- // to measure.
- return [...value].length === 1;
- });
- var CommonDataTypes;
- (function (CommonDataTypes) {
- CommonDataTypes.SharedReferenceSchema = zod_1.z.object({
- sharedId: zod_1.z.string().min(1),
- handle: zod_1.z.string().optional(),
- });
- CommonDataTypes.RemoteReferenceSchema = zod_1.z.object({
- handle: zod_1.z.string().min(1),
- });
- // UndefinedValue = {
- // type: "undefined",
- // }
- const UndefinedValueSchema = zod_1.z.object({ type: zod_1.z.literal('undefined') });
- // NullValue = {
- // type: "null",
- // }
- const NullValueSchema = zod_1.z.object({ type: zod_1.z.literal('null') });
- // StringValue = {
- // type: "string",
- // value: text,
- // }
- const StringValueSchema = zod_1.z.object({
- type: zod_1.z.literal('string'),
- value: zod_1.z.string(),
- });
- // SpecialNumber = "NaN" / "-0" / "Infinity" / "-Infinity";
- const SpecialNumberSchema = zod_1.z.enum(['NaN', '-0', 'Infinity', '-Infinity']);
- // NumberValue = {
- // type: "number",
- // value: number / SpecialNumber,
- // }
- const NumberValueSchema = zod_1.z.object({
- type: zod_1.z.literal('number'),
- value: zod_1.z.union([SpecialNumberSchema, zod_1.z.number()]),
- });
- // BooleanValue = {
- // type: "boolean",
- // value: bool,
- // }
- const BooleanValueSchema = zod_1.z.object({
- type: zod_1.z.literal('boolean'),
- value: zod_1.z.boolean(),
- });
- // BigIntValue = {
- // type: "bigint",
- // value: text,
- // }
- const BigIntValueSchema = zod_1.z.object({
- type: zod_1.z.literal('bigint'),
- value: zod_1.z.string(),
- });
- const PrimitiveProtocolValueSchema = zod_1.z.union([
- UndefinedValueSchema,
- NullValueSchema,
- StringValueSchema,
- NumberValueSchema,
- BooleanValueSchema,
- BigIntValueSchema,
- ]);
- CommonDataTypes.LocalValueSchema = zod_1.z.lazy(() => zod_1.z.union([
- PrimitiveProtocolValueSchema,
- ArrayLocalValueSchema,
- DateLocalValueSchema,
- MapLocalValueSchema,
- ObjectLocalValueSchema,
- RegExpLocalValueSchema,
- SetLocalValueSchema,
- ]));
- // Order is important, as `parse` is processed in the same order.
- // `SharedReferenceSchema`->`RemoteReferenceSchema`->`LocalValueSchema`.
- const LocalOrRemoteValueSchema = zod_1.z.union([
- CommonDataTypes.SharedReferenceSchema,
- CommonDataTypes.RemoteReferenceSchema,
- CommonDataTypes.LocalValueSchema,
- ]);
- // ListLocalValue = [*LocalValue];
- const ListLocalValueSchema = zod_1.z.array(LocalOrRemoteValueSchema);
- // ArrayLocalValue = {
- // type: "array",
- // value: ListLocalValue,
- // }
- const ArrayLocalValueSchema = zod_1.z.object({
- type: zod_1.z.literal('array'),
- value: ListLocalValueSchema,
- });
- // DateLocalValue = {
- // type: "date",
- // value: text
- // }
- const DateLocalValueSchema = zod_1.z.object({
- type: zod_1.z.literal('date'),
- value: zod_1.z.string().min(1),
- });
- // MappingLocalValue = [*[(LocalValue / text), LocalValue]];
- const MappingLocalValueSchema = zod_1.z.tuple([
- zod_1.z.union([zod_1.z.string(), LocalOrRemoteValueSchema]),
- LocalOrRemoteValueSchema,
- ]);
- // MapLocalValue = {
- // type: "map",
- // value: MappingLocalValue,
- // }
- const MapLocalValueSchema = zod_1.z.object({
- type: zod_1.z.literal('map'),
- value: zod_1.z.array(MappingLocalValueSchema),
- });
- // ObjectLocalValue = {
- // type: "object",
- // value: MappingLocalValue,
- // }
- const ObjectLocalValueSchema = zod_1.z.object({
- type: zod_1.z.literal('object'),
- value: zod_1.z.array(MappingLocalValueSchema),
- });
- // RegExpLocalValue = {
- // type: "regexp",
- // value: RegExpValue,
- // }
- const RegExpLocalValueSchema = zod_1.z.object({
- type: zod_1.z.literal('regexp'),
- value: zod_1.z.object({
- pattern: zod_1.z.string(),
- flags: zod_1.z.string().optional(),
- }),
- });
- // SetLocalValue = {
- // type: "set",
- // value: ListLocalValue,
- // }
- const SetLocalValueSchema = zod_1.z.lazy(() => zod_1.z.object({
- type: zod_1.z.literal('set'),
- value: ListLocalValueSchema,
- }));
- // BrowsingContext = text;
- CommonDataTypes.BrowsingContextSchema = zod_1.z.string();
- CommonDataTypes.MaxDepthSchema = zod_1.z.number().int().nonnegative().max(MAX_INT);
- })(CommonDataTypes = exports.CommonDataTypes || (exports.CommonDataTypes = {}));
- /** @see https://w3c.github.io/webdriver-bidi/#module-script */
- var Script;
- (function (Script) {
- const RealmTypeSchema = zod_1.z.enum([
- 'window',
- 'dedicated-worker',
- 'shared-worker',
- 'service-worker',
- 'worker',
- 'paint-worklet',
- 'audio-worklet',
- 'worklet',
- ]);
- Script.GetRealmsParametersSchema = zod_1.z.object({
- context: CommonDataTypes.BrowsingContextSchema.optional(),
- type: RealmTypeSchema.optional(),
- });
- function parseGetRealmsParams(params) {
- return parseObject(params, Script.GetRealmsParametersSchema);
- }
- Script.parseGetRealmsParams = parseGetRealmsParams;
- // ContextTarget = {
- // context: BrowsingContext,
- // ?sandbox: text
- // }
- const ContextTargetSchema = zod_1.z.object({
- context: CommonDataTypes.BrowsingContextSchema,
- sandbox: zod_1.z.string().optional(),
- });
- // RealmTarget = {realm: Realm};
- const RealmTargetSchema = zod_1.z.object({
- realm: zod_1.z.string().min(1),
- });
- // Target = (
- // RealmTarget //
- // ContextTarget
- // );
- // Order is important, as `parse` is processed in the same order.
- // `RealmTargetSchema` has higher priority.
- const TargetSchema = zod_1.z.union([RealmTargetSchema, ContextTargetSchema]);
- // ResultOwnership = "root" / "none"
- const ResultOwnershipSchema = zod_1.z.enum(['root', 'none']);
- // SerializationOptions = {
- // ?maxDomDepth: (js-uint / null) .default 0,
- // ?maxObjectDepth: (js-uint / null) .default null,
- // ?includeShadowTree: ("none" / "open" / "all") .default "none",
- // }
- const SerializationOptionsSchema = zod_1.z.object({
- maxDomDepth: zod_1.z
- .union([zod_1.z.null(), zod_1.z.number().int().nonnegative()])
- .optional(),
- maxObjectDepth: zod_1.z
- .union([zod_1.z.null(), zod_1.z.number().int().nonnegative().max(MAX_INT)])
- .optional(),
- includeShadowTree: zod_1.z.enum(['none', 'open', 'all']).optional(),
- });
- // script.EvaluateParameters = {
- // expression: text,
- // target: script.Target,
- // awaitPromise: bool,
- // ?resultOwnership: script.ResultOwnership,
- // ?serializationOptions: script.SerializationOptions,
- // }
- const EvaluateParametersSchema = zod_1.z.object({
- expression: zod_1.z.string(),
- awaitPromise: zod_1.z.boolean(),
- target: TargetSchema,
- resultOwnership: ResultOwnershipSchema.optional(),
- serializationOptions: SerializationOptionsSchema.optional(),
- });
- function parseEvaluateParams(params) {
- return parseObject(params, EvaluateParametersSchema);
- }
- Script.parseEvaluateParams = parseEvaluateParams;
- // DisownParameters = {
- // handles: [Handle]
- // target: script.Target;
- // }
- const DisownParametersSchema = zod_1.z.object({
- target: TargetSchema,
- handles: zod_1.z.array(zod_1.z.string()),
- });
- function parseDisownParams(params) {
- return parseObject(params, DisownParametersSchema);
- }
- Script.parseDisownParams = parseDisownParams;
- const ChannelSchema = zod_1.z.string();
- const ChannelPropertiesSchema = zod_1.z.object({
- channel: ChannelSchema,
- serializationOptions: SerializationOptionsSchema.optional(),
- ownership: ResultOwnershipSchema.optional(),
- });
- Script.ChannelValueSchema = zod_1.z.object({
- type: zod_1.z.literal('channel'),
- value: ChannelPropertiesSchema,
- });
- Script.PreloadScriptSchema = zod_1.z.string();
- Script.AddPreloadScriptParametersSchema = zod_1.z.object({
- functionDeclaration: zod_1.z.string(),
- arguments: zod_1.z.array(Script.ChannelValueSchema).optional(),
- sandbox: zod_1.z.string().optional(),
- context: CommonDataTypes.BrowsingContextSchema.optional(),
- });
- function parseAddPreloadScriptParams(params) {
- return parseObject(params, Script.AddPreloadScriptParametersSchema);
- }
- Script.parseAddPreloadScriptParams = parseAddPreloadScriptParams;
- Script.RemovePreloadScriptParametersSchema = zod_1.z.object({
- script: Script.PreloadScriptSchema,
- });
- function parseRemovePreloadScriptParams(params) {
- return parseObject(params, Script.RemovePreloadScriptParametersSchema);
- }
- Script.parseRemovePreloadScriptParams = parseRemovePreloadScriptParams;
- // ArgumentValue = (
- // RemoteReference //
- // LocalValue //
- // script.Channel
- // );
- const ArgumentValueSchema = zod_1.z.union([
- CommonDataTypes.RemoteReferenceSchema,
- CommonDataTypes.SharedReferenceSchema,
- CommonDataTypes.LocalValueSchema,
- Script.ChannelValueSchema,
- ]);
- // CallFunctionParameters = {
- // functionDeclaration: text,
- // awaitPromise: bool,
- // target: script.Target,
- // ?arguments: [*script.ArgumentValue],
- // ?resultOwnership: script.ResultOwnership,
- // ?serializationOptions: script.SerializationOptions,
- // ?this: script.ArgumentValue,
- // }
- const CallFunctionParametersSchema = zod_1.z.object({
- functionDeclaration: zod_1.z.string(),
- awaitPromise: zod_1.z.boolean(),
- target: TargetSchema,
- arguments: zod_1.z.array(ArgumentValueSchema).optional(),
- resultOwnership: ResultOwnershipSchema.optional(),
- serializationOptions: SerializationOptionsSchema.optional(),
- this: ArgumentValueSchema.optional(),
- });
- function parseCallFunctionParams(params) {
- return parseObject(params, CallFunctionParametersSchema);
- }
- Script.parseCallFunctionParams = parseCallFunctionParams;
- })(Script = exports.Script || (exports.Script = {}));
- /** @see https://w3c.github.io/webdriver-bidi/#module-browsingContext */
- var BrowsingContext;
- (function (BrowsingContext) {
- // GetTreeParameters = {
- // ?maxDepth: js-uint,
- // ?root: browsingContext.BrowsingContext,
- // }
- const GetTreeParametersSchema = zod_1.z.object({
- maxDepth: CommonDataTypes.MaxDepthSchema.optional(),
- root: CommonDataTypes.BrowsingContextSchema.optional(),
- });
- function parseGetTreeParams(params) {
- return parseObject(params, GetTreeParametersSchema);
- }
- BrowsingContext.parseGetTreeParams = parseGetTreeParams;
- // ReadinessState = "none" / "interactive" / "complete"
- const ReadinessStateSchema = zod_1.z.enum(['none', 'interactive', 'complete']);
- // BrowsingContextNavigateParameters = {
- // context: BrowsingContext,
- // url: text,
- // ?wait: ReadinessState,
- // }
- // ReadinessState = "none" / "interactive" / "complete"
- const NavigateParametersSchema = zod_1.z.object({
- context: CommonDataTypes.BrowsingContextSchema,
- url: zod_1.z.string().url(),
- wait: ReadinessStateSchema.optional(),
- });
- function parseNavigateParams(params) {
- return parseObject(params, NavigateParametersSchema);
- }
- BrowsingContext.parseNavigateParams = parseNavigateParams;
- const ReloadParametersSchema = zod_1.z.object({
- context: CommonDataTypes.BrowsingContextSchema,
- ignoreCache: zod_1.z.boolean().optional(),
- wait: ReadinessStateSchema.optional(),
- });
- function parseReloadParams(params) {
- return parseObject(params, ReloadParametersSchema);
- }
- BrowsingContext.parseReloadParams = parseReloadParams;
- // BrowsingContextCreateType = "tab" / "window"
- // BrowsingContextCreateParameters = {
- // type: BrowsingContextCreateType
- // }
- const CreateParametersSchema = zod_1.z.object({
- type: zod_1.z.enum(['tab', 'window']),
- referenceContext: CommonDataTypes.BrowsingContextSchema.optional(),
- });
- function parseCreateParams(params) {
- return parseObject(params, CreateParametersSchema);
- }
- BrowsingContext.parseCreateParams = parseCreateParams;
- // BrowsingContextCloseParameters = {
- // context: BrowsingContext
- // }
- const CloseParametersSchema = zod_1.z.object({
- context: CommonDataTypes.BrowsingContextSchema,
- });
- function parseCloseParams(params) {
- return parseObject(params, CloseParametersSchema);
- }
- BrowsingContext.parseCloseParams = parseCloseParams;
- // browsingContext.CaptureScreenshotParameters = {
- // context: browsingContext.BrowsingContext
- // }
- const CaptureScreenshotParametersSchema = zod_1.z.object({
- context: CommonDataTypes.BrowsingContextSchema,
- });
- function parseCaptureScreenshotParams(params) {
- return parseObject(params, CaptureScreenshotParametersSchema);
- }
- BrowsingContext.parseCaptureScreenshotParams = parseCaptureScreenshotParams;
- // All units are in cm.
- // PrintPageParameters = {
- // ?height: (float .ge 0.0) .default 27.94,
- // ?width: (float .ge 0.0) .default 21.59,
- // }
- const PrintPageParametersSchema = zod_1.z.object({
- height: zod_1.z.number().nonnegative().optional(),
- width: zod_1.z.number().nonnegative().optional(),
- });
- // All units are in cm.
- // PrintMarginParameters = {
- // ?bottom: (float .ge 0.0) .default 1.0,
- // ?left: (float .ge 0.0) .default 1.0,
- // ?right: (float .ge 0.0) .default 1.0,
- // ?top: (float .ge 0.0) .default 1.0,
- // }
- const PrintMarginParametersSchema = zod_1.z.object({
- bottom: zod_1.z.number().nonnegative().optional(),
- left: zod_1.z.number().nonnegative().optional(),
- right: zod_1.z.number().nonnegative().optional(),
- top: zod_1.z.number().nonnegative().optional(),
- });
- /** @see https://w3c.github.io/webdriver/#dfn-parse-a-page-range */
- const PrintPageRangesSchema = zod_1.z
- .array(zod_1.z.union([zod_1.z.string().min(1), zod_1.z.number().int().nonnegative()]))
- .refine((pageRanges) => {
- return pageRanges.every((pageRange) => {
- const match = String(pageRange).match(
- // matches: '2' | '2-' | '-2' | '2-4'
- /^(?:(?:\d+)|(?:\d+[-])|(?:[-]\d+)|(?:(?<start>\d+)[-](?<end>\d+)))$/);
- // If a page range is specified, validate start <= end.
- const { start, end } = match?.groups ?? {};
- if (start && end && Number(start) > Number(end)) {
- return false;
- }
- return match;
- });
- });
- // PrintParameters = {
- // context: browsingContext.BrowsingContext,
- // ?background: bool .default false,
- // ?margin: browsingContext.PrintMarginParameters,
- // ?orientation: ("portrait" / "landscape") .default "portrait",
- // ?page: browsingContext.PrintPageParameters,
- // ?pageRanges: [*(js-uint / text)],
- // ?scale: 0.1..2.0 .default 1.0,
- // ?shrinkToFit: bool .default true,
- // }
- const PrintParametersSchema = zod_1.z.object({
- context: CommonDataTypes.BrowsingContextSchema,
- background: zod_1.z.boolean().optional(),
- margin: PrintMarginParametersSchema.optional(),
- orientation: zod_1.z.enum(['portrait', 'landscape']).optional(),
- page: PrintPageParametersSchema.optional(),
- pageRanges: PrintPageRangesSchema.optional(),
- scale: zod_1.z.number().min(0.1).max(2.0).optional(),
- shrinkToFit: zod_1.z.boolean().optional(),
- });
- function parsePrintParams(params) {
- return parseObject(params, PrintParametersSchema);
- }
- BrowsingContext.parsePrintParams = parsePrintParams;
- // browsingContext.Viewport = {
- // width: js-uint,
- // height: js-uint,
- // }
- const ViewportSchema = zod_1.z.object({
- width: zod_1.z.number().int().nonnegative(),
- height: zod_1.z.number().int().nonnegative(),
- });
- // browsingContext.SetViewportParameters = {
- // context: browsingContext.BrowsingContext,
- // viewport: emulation.Viewport / null
- // }
- const SetViewportActionSchema = zod_1.z.object({
- context: CommonDataTypes.BrowsingContextSchema,
- viewport: zod_1.z.union([zod_1.z.null(), ViewportSchema]),
- });
- function parseSetViewportParams(params) {
- return parseObject(params, SetViewportActionSchema);
- }
- BrowsingContext.parseSetViewportParams = parseSetViewportParams;
- })(BrowsingContext = exports.BrowsingContext || (exports.BrowsingContext = {}));
- var Cdp;
- (function (Cdp) {
- const SendCommandParamsSchema = zod_1.z.object({
- // Allowing any cdpMethod, and casting to proper type later on.
- method: zod_1.z.string(),
- // `passthrough` allows object to have any fields.
- // https://github.com/colinhacks/zod#passthrough
- params: zod_1.z.object({}).passthrough().optional(),
- session: zod_1.z.string().optional(),
- });
- function parseSendCommandParams(params) {
- return parseObject(params, SendCommandParamsSchema);
- }
- Cdp.parseSendCommandParams = parseSendCommandParams;
- const GetSessionParamsSchema = zod_1.z.object({
- context: CommonDataTypes.BrowsingContextSchema,
- });
- function parseGetSessionParams(params) {
- return parseObject(params, GetSessionParamsSchema);
- }
- Cdp.parseGetSessionParams = parseGetSessionParams;
- })(Cdp = exports.Cdp || (exports.Cdp = {}));
- /** @see https://w3c.github.io/webdriver-bidi/#module-session */
- var Session;
- (function (Session) {
- const BiDiSubscriptionRequestParametersEventsSchema = zod_1.z.enum([
- protocol_js_1.BrowsingContext.AllEvents,
- ...Object.values(protocol_js_1.BrowsingContext.EventNames),
- protocol_js_1.Log.AllEvents,
- ...Object.values(protocol_js_1.Log.EventNames),
- protocol_js_1.Network.AllEvents,
- ...Object.values(protocol_js_1.Network.EventNames),
- protocol_js_1.Script.AllEvents,
- ...Object.values(protocol_js_1.Script.EventNames),
- ]);
- // BiDi+ events
- const CdpSubscriptionRequestParametersEventsSchema = zod_1.z.custom((value) => {
- return typeof value === 'string' && value.startsWith('cdp.');
- }, 'Not a CDP event');
- const SubscriptionRequestParametersEventsSchema = zod_1.z.union([
- BiDiSubscriptionRequestParametersEventsSchema,
- CdpSubscriptionRequestParametersEventsSchema,
- ]);
- // SessionSubscriptionRequest = {
- // events: [*text],
- // ?contexts: [*BrowsingContext],
- // }
- const SubscriptionRequestParametersSchema = zod_1.z.object({
- events: zod_1.z.array(SubscriptionRequestParametersEventsSchema),
- contexts: zod_1.z.array(CommonDataTypes.BrowsingContextSchema).optional(),
- });
- function parseSubscribeParams(params) {
- return parseObject(params, SubscriptionRequestParametersSchema);
- }
- Session.parseSubscribeParams = parseSubscribeParams;
- })(Session = exports.Session || (exports.Session = {}));
- /** @see https://w3c.github.io/webdriver-bidi/#module-input */
- var Input;
- (function (Input) {
- // input.ElementOrigin = {
- // type: "element",
- // element: script.SharedReference
- // }
- const ElementOriginSchema = zod_1.z.object({
- type: zod_1.z.literal('element'),
- element: CommonDataTypes.SharedReferenceSchema,
- });
- // input.Origin = "viewport" / "pointer" / input.ElementOrigin
- const OriginSchema = zod_1.z.union([
- zod_1.z.literal('viewport'),
- zod_1.z.literal('pointer'),
- ElementOriginSchema,
- ]);
- // input.PauseAction = {
- // type: "pause",
- // ? duration: js-uint
- // }
- const PauseActionSchema = zod_1.z.object({
- type: zod_1.z.literal(protocol_js_1.Input.ActionType.Pause),
- duration: zod_1.z.number().nonnegative().int().optional(),
- });
- // input.KeyDownAction = {
- // type: "keyDown",
- // value: text
- // }
- const KeyDownActionSchema = zod_1.z.object({
- type: zod_1.z.literal(protocol_js_1.Input.ActionType.KeyDown),
- value: UnicodeCharacterSchema,
- });
- // input.KeyUpAction = {
- // type: "keyUp",
- // value: text
- // }
- const KeyUpActionSchema = zod_1.z.object({
- type: zod_1.z.literal(protocol_js_1.Input.ActionType.KeyUp),
- value: UnicodeCharacterSchema,
- });
- // input.TiltProperties = (
- // ? tiltX: -90..90 .default 0,
- // ? tiltY: -90..90 .default 0,
- // )
- const TiltPropertiesSchema = zod_1.z.object({
- tiltX: zod_1.z.number().min(-90).max(90).int().default(0).optional(),
- tiltY: zod_1.z.number().min(-90).max(90).int().default(0).optional(),
- });
- // input.AngleProperties = (
- // ? altitudeAngle: float .default 0.0,
- // ? azimuthAngle: float .default 0.0,
- // )
- const AnglePropertiesSchema = zod_1.z.object({
- altitudeAngle: zod_1.z
- .number()
- .nonnegative()
- .max(Math.PI / 2)
- .default(0.0)
- .optional(),
- azimuthAngle: zod_1.z
- .number()
- .nonnegative()
- .max(2 * Math.PI)
- .default(0.0)
- .optional(),
- });
- // input.PointerCommonProperties = (
- // ? width: js-uint .default 1,
- // ? height: js-uint .default 1,
- // ? pressure: float .default 0.0,
- // ? tangentialPressure: float .default 0.0,
- // ? twist: 0..359 .default 0,
- // (input.TiltProperties // input.AngleProperties)
- // )
- const PointerCommonPropertiesSchema = zod_1.z
- .object({
- width: zod_1.z.number().nonnegative().int().default(1),
- height: zod_1.z.number().nonnegative().int().default(1),
- pressure: zod_1.z.number().min(0.0).max(1.0).default(0.0),
- tangentialPressure: zod_1.z.number().min(-1.0).max(1.0).default(0.0),
- twist: zod_1.z.number().nonnegative().max(359).int().default(0),
- })
- .and(zod_1.z.union([TiltPropertiesSchema, AnglePropertiesSchema]));
- // input.PointerUpAction = {
- // type: "pointerUp",
- // button: js-uint,
- // input.PointerCommonProperties
- // }
- const PointerUpActionSchema = zod_1.z
- .object({
- type: zod_1.z.literal(protocol_js_1.Input.ActionType.PointerUp),
- button: zod_1.z.number().nonnegative().int(),
- })
- .and(PointerCommonPropertiesSchema);
- // input.PointerDownAction = {
- // type: "pointerDown",
- // button: js-uint,
- // input.PointerCommonProperties
- // }
- const PointerDownActionSchema = zod_1.z
- .object({
- type: zod_1.z.literal(protocol_js_1.Input.ActionType.PointerDown),
- button: zod_1.z.number().nonnegative().int(),
- })
- .and(PointerCommonPropertiesSchema);
- // input.PointerMoveAction = {
- // type: "pointerMove",
- // x: js-int,
- // y: js-int,
- // ? duration: js-uint,
- // ? origin: input.Origin,
- // input.PointerCommonProperties
- // }
- const PointerMoveActionSchema = zod_1.z
- .object({
- type: zod_1.z.literal(protocol_js_1.Input.ActionType.PointerMove),
- x: zod_1.z.number().int(),
- y: zod_1.z.number().int(),
- duration: zod_1.z.number().nonnegative().int().optional(),
- origin: OriginSchema.optional().default('viewport'),
- })
- .and(PointerCommonPropertiesSchema);
- // input.WheelScrollAction = {
- // type: "scroll",
- // x: js-int,
- // y: js-int,
- // deltaX: js-int,
- // deltaY: js-int,
- // ? duration: js-uint,
- // ? origin: input.Origin .default "viewport",
- // }
- const WheelScrollActionSchema = zod_1.z.object({
- type: zod_1.z.literal(protocol_js_1.Input.ActionType.Scroll),
- x: zod_1.z.number().int(),
- y: zod_1.z.number().int(),
- deltaX: zod_1.z.number().int(),
- deltaY: zod_1.z.number().int(),
- duration: zod_1.z.number().nonnegative().int().optional(),
- origin: OriginSchema.optional().default('viewport'),
- });
- // input.WheelSourceAction = (
- // input.PauseAction //
- // input.WheelScrollAction
- // )
- const WheelSourceActionSchema = zod_1.z.discriminatedUnion('type', [
- PauseActionSchema,
- WheelScrollActionSchema,
- ]);
- // input.WheelSourceActions = {
- // type: "wheel",
- // id: text,
- // actions: [*input.WheelSourceAction]
- // }
- const WheelSourceActionsSchema = zod_1.z.object({
- type: zod_1.z.literal(protocol_js_1.Input.SourceActionsType.Wheel),
- id: zod_1.z.string(),
- actions: zod_1.z.array(WheelSourceActionSchema),
- });
- // input.PointerSourceAction = (
- // input.PauseAction //
- // input.PointerDownAction //
- // input.PointerUpAction //
- // input.PointerMoveAction
- // )
- const PointerSourceActionSchema = zod_1.z.union([
- PauseActionSchema,
- PointerDownActionSchema,
- PointerUpActionSchema,
- PointerMoveActionSchema,
- ]);
- // input.PointerType = "mouse" / "pen" / "touch"
- const PointerTypeSchema = zod_1.z.nativeEnum(protocol_js_1.Input.PointerType);
- // input.PointerParameters = {
- // ? pointerType: input.PointerType .default "mouse"
- // }
- const PointerParametersSchema = zod_1.z.object({
- pointerType: PointerTypeSchema.optional().default(protocol_js_1.Input.PointerType.Mouse),
- });
- // input.PointerSourceActions = {
- // type: "pointer",
- // id: text,
- // ? parameters: input.PointerParameters,
- // actions: [*input.PointerSourceAction]
- // }
- const PointerSourceActionsSchema = zod_1.z.object({
- type: zod_1.z.literal(protocol_js_1.Input.SourceActionsType.Pointer),
- id: zod_1.z.string(),
- parameters: PointerParametersSchema.optional(),
- actions: zod_1.z.array(PointerSourceActionSchema),
- });
- // input.KeySourceAction = (
- // input.PauseAction //
- // input.KeyDownAction //
- // input.KeyUpAction
- // )
- const KeySourceActionSchema = zod_1.z.discriminatedUnion('type', [
- PauseActionSchema,
- KeyDownActionSchema,
- KeyUpActionSchema,
- ]);
- // input.KeySourceActions = {
- // type: "key",
- // id: text,
- // actions: [*input.KeySourceAction]
- // }
- const KeySourceActionsSchema = zod_1.z.object({
- type: zod_1.z.literal(protocol_js_1.Input.SourceActionsType.Key),
- id: zod_1.z.string(),
- actions: zod_1.z.array(KeySourceActionSchema),
- });
- // input.NoneSourceAction = input.PauseAction
- const NoneSourceActionSchema = PauseActionSchema;
- // input.NoneSourceActions = {
- // type: "none",
- // id: text,
- // actions: [*input.NoneSourceAction]
- // }
- const NoneSourceActionsSchema = zod_1.z.object({
- type: zod_1.z.literal(protocol_js_1.Input.SourceActionsType.None),
- id: zod_1.z.string(),
- actions: zod_1.z.array(NoneSourceActionSchema),
- });
- // input.SourceActions = (
- // input.NoneSourceActions //
- // input.KeySourceActions //
- // input.PointerSourceActions //
- // input.WheelSourceActions
- // )
- const SourceActionsSchema = zod_1.z.discriminatedUnion('type', [
- NoneSourceActionsSchema,
- KeySourceActionsSchema,
- PointerSourceActionsSchema,
- WheelSourceActionsSchema,
- ]);
- // input.PerformActionsParameters = {
- // context: browsingContext.BrowsingContext,
- // actions: [*input.SourceActions]
- // }
- const PerformActionsParametersSchema = zod_1.z.object({
- context: CommonDataTypes.BrowsingContextSchema,
- actions: zod_1.z.array(SourceActionsSchema),
- });
- function parsePerformActionsParams(params) {
- return parseObject(params, PerformActionsParametersSchema);
- }
- Input.parsePerformActionsParams = parsePerformActionsParams;
- // input.ReleaseActionsParameters = {
- // context: browsingContext.BrowsingContext,
- // }
- const ReleaseActionsParametersSchema = zod_1.z.object({
- context: CommonDataTypes.BrowsingContextSchema,
- });
- function parseReleaseActionsParams(params) {
- return parseObject(params, ReleaseActionsParametersSchema);
- }
- Input.parseReleaseActionsParams = parseReleaseActionsParams;
- })(Input = exports.Input || (exports.Input = {}));
- //# sourceMappingURL=protocol-parser.js.map
|