{"version":3,"file":"static/static-page.mjs","sources":["../../../src/static/static-page.ts"],"sourcesContent":["import type {\n  DeviceAction,\n  Point,\n  ScreenshotRef,\n  UIContext,\n} from '@midscene/core';\nimport type { AbstractInterface } from '@midscene/core/device';\nimport {\n  type InputPrimitives,\n  defineActionsFromInputPrimitives,\n} from '@midscene/core/device';\nimport { ERROR_CODE_NOT_IMPLEMENTED_AS_DESIGNED } from '@midscene/shared/common';\n\nconst ThrowNotImplemented = (methodName: string) => {\n  throw new Error(\n    `The method \"${methodName}\" is not implemented as designed since this is a static UI context. (${ERROR_CODE_NOT_IMPLEMENTED_AS_DESIGNED})`,\n  );\n};\n\ntype SerializedStaticScreenshot = {\n  base64?: unknown;\n  _base64?: unknown;\n  type?: unknown;\n} & Partial<Omit<ScreenshotRef, 'type'>>;\n\ntype StaticPageUIContext = Omit<\n  UIContext,\n  'deprecatedDpr' | 'screenshot'\n> & {\n  screenshot: UIContext['screenshot'] | SerializedStaticScreenshot;\n};\n\nfunction screenshotBase64FromContext(\n  screenshot: StaticPageUIContext['screenshot'],\n): string {\n  const record = screenshot as SerializedStaticScreenshot;\n  const base64 = record.base64 ?? record._base64;\n  if (typeof base64 === 'string') {\n    return base64;\n  }\n\n  if (record.type === 'midscene_screenshot_ref') {\n    throw new Error(\n      'StaticPage screenshot is a serialized reference without base64 data',\n    );\n  }\n\n  throw new Error(\n    'StaticPage screenshot must include base64 data before execution',\n  );\n}\n\nexport default class StaticPage implements AbstractInterface {\n  interfaceType = 'static';\n\n  private uiContext: StaticPageUIContext;\n  readonly inputPrimitives: InputPrimitives = {\n    pointer: {\n      tap: async () => ThrowNotImplemented('Tap'),\n      rightClick: async () => ThrowNotImplemented('RightClick'),\n      hover: async () => ThrowNotImplemented('Hover'),\n      dragAndDrop: async () => ThrowNotImplemented('DragAndDrop'),\n    },\n    keyboard: {\n      typeText: async () => ThrowNotImplemented('Input'),\n      keyboardPress: async () => ThrowNotImplemented('KeyboardPress'),\n      clearInput: async () => ThrowNotImplemented('ClearInput'),\n    },\n    touch: {\n      swipe: async () => ThrowNotImplemented('Swipe'),\n    },\n    scroll: {\n      scroll: async () => ThrowNotImplemented('Scroll'),\n    },\n  };\n\n  constructor(uiContext: StaticPageUIContext) {\n    this.uiContext = uiContext;\n  }\n\n  actionSpace(): DeviceAction[] {\n    // Return available actions for static page - they will throw \"not implemented\" errors when executed\n    // but need to be available for planning phase\n    return defineActionsFromInputPrimitives(this.inputPrimitives, {\n      size: () => this.size(),\n    });\n  }\n\n  async evaluateJavaScript<T = unknown>(script: string): Promise<T> {\n    return ThrowNotImplemented('evaluateJavaScript');\n  }\n\n  // @deprecated\n  async getElementsInfo() {\n    return ThrowNotImplemented('getElementsInfo');\n  }\n\n  async getElementsNodeTree() {\n    return ThrowNotImplemented('getElementsNodeTree');\n  }\n\n  async getXpathsByPoint(point: Point) {\n    return ThrowNotImplemented('getXpathsByPoint');\n  }\n\n  async getElementInfoByXpath(xpath: string) {\n    return ThrowNotImplemented('getElementInfoByXpath');\n  }\n\n  async size() {\n    return {\n      ...this.uiContext.shotSize,\n    };\n  }\n\n  async screenshotBase64() {\n    return screenshotBase64FromContext(this.uiContext.screenshot);\n  }\n\n  async url() {\n    return Promise.resolve('https://static_page_without_url');\n  }\n\n  async scrollUntilTop(startingPoint?: Point) {\n    return ThrowNotImplemented('scrollUntilTop');\n  }\n\n  async scrollUntilBottom(startingPoint?: Point) {\n    return ThrowNotImplemented('scrollUntilBottom');\n  }\n\n  async scrollUntilLeft(startingPoint?: Point) {\n    return ThrowNotImplemented('scrollUntilLeft');\n  }\n\n  async scrollUntilRight(startingPoint?: Point) {\n    return ThrowNotImplemented('scrollUntilRight');\n  }\n\n  async scrollUp(distance?: number, startingPoint?: Point) {\n    return ThrowNotImplemented('scrollUp');\n  }\n\n  async scrollDown(distance?: number, startingPoint?: Point) {\n    return ThrowNotImplemented('scrollDown');\n  }\n\n  async scrollLeft(distance?: number, startingPoint?: Point) {\n    return ThrowNotImplemented('scrollLeft');\n  }\n\n  async scrollRight(distance?: number, startingPoint?: Point) {\n    return ThrowNotImplemented('scrollRight');\n  }\n\n  async clearInput() {\n    return ThrowNotImplemented('clearInput');\n  }\n\n  mouse = {\n    click: ThrowNotImplemented.bind(null, 'mouse.click'),\n    wheel: ThrowNotImplemented.bind(null, 'mouse.wheel'),\n    move: ThrowNotImplemented.bind(null, 'mouse.move'),\n    drag: ThrowNotImplemented.bind(null, 'mouse.drag'),\n  };\n\n  keyboard = {\n    type: ThrowNotImplemented.bind(null, 'keyboard.type'),\n    press: ThrowNotImplemented.bind(null, 'keyboard.press'),\n  };\n\n  async destroy(): Promise<void> {\n    //\n  }\n\n  updateContext(newContext: StaticPageUIContext): void {\n    this.uiContext = newContext;\n  }\n}\n"],"names":["ThrowNotImplemented","methodName","Error","ERROR_CODE_NOT_IMPLEMENTED_AS_DESIGNED","screenshotBase64FromContext","screenshot","record","base64","StaticPage","defineActionsFromInputPrimitives","script","point","xpath","Promise","startingPoint","distance","newContext","uiContext"],"mappings":";;;;;;;;;;;;AAaA,MAAMA,sBAAsB,CAACC;IAC3B,MAAM,IAAIC,MACR,CAAC,YAAY,EAAED,WAAW,qEAAqE,EAAEE,uCAAuC,CAAC,CAAC;AAE9I;AAeA,SAASC,4BACPC,UAA6C;IAE7C,MAAMC,SAASD;IACf,MAAME,SAASD,OAAO,MAAM,IAAIA,OAAO,OAAO;IAC9C,IAAI,AAAkB,YAAlB,OAAOC,QACT,OAAOA;IAGT,IAAID,AAAgB,8BAAhBA,OAAO,IAAI,EACb,MAAM,IAAIJ,MACR;IAIJ,MAAM,IAAIA,MACR;AAEJ;AAEe,MAAMM;IA4BnB,cAA8B;QAG5B,OAAOC,iCAAiC,IAAI,CAAC,eAAe,EAAE;YAC5D,MAAM,IAAM,IAAI,CAAC,IAAI;QACvB;IACF;IAEA,MAAM,mBAAgCC,MAAc,EAAc;QAChE,OAAOV,oBAAoB;IAC7B;IAGA,MAAM,kBAAkB;QACtB,OAAOA,oBAAoB;IAC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