@aico-test/shared
Advanced tools
| declare const TEXT_SIZE_THRESHOLD = 9; | ||
| declare const TEXT_MAX_SIZE = 40; | ||
| declare const CONTAINER_MINI_HEIGHT = 3; | ||
| declare const CONTAINER_MINI_WIDTH = 3; | ||
| declare enum NodeType { | ||
| CONTAINER = "CONTAINER Node", | ||
| FORM_ITEM = "FORM_ITEM Node", | ||
| BUTTON = "BUTTON Node", | ||
| IMG = "IMG Node", | ||
| TEXT = "TEXT Node", | ||
| POSITION = "POSITION Node" | ||
| } | ||
| export { CONTAINER_MINI_HEIGHT, CONTAINER_MINI_WIDTH, NodeType, TEXT_MAX_SIZE, TEXT_SIZE_THRESHOLD }; |
| export { } |
| import { NodeType } from './constants.js'; | ||
| import { B as BaseElement, E as ElementTreeNode } from './index-305e7a7e.js'; | ||
| declare function descriptionOfTree<ElementType extends BaseElement = BaseElement>(tree: ElementTreeNode<ElementType>, truncateTextLength?: number, filterNonTextContent?: boolean): string; | ||
| declare function treeToList<T extends BaseElement>(tree: ElementTreeNode<T>): T[]; | ||
| declare function traverseTree<T extends BaseElement, ReturnNodeType extends BaseElement>(tree: ElementTreeNode<T>, onNode: (node: T) => ReturnNodeType): ElementTreeNode<ReturnNodeType>; | ||
| interface WebElementInfo extends ElementInfo { | ||
| zoom: number; | ||
| screenWidth?: number; | ||
| screenHeight?: number; | ||
| } | ||
| interface WebElementNode { | ||
| node: WebElementInfo | null; | ||
| children: WebElementNode[]; | ||
| } | ||
| declare function extractTextWithPosition$1(initNode: globalThis.Node, debugMode?: boolean): WebElementInfo[]; | ||
| declare function extractTreeNodeAsString(initNode: globalThis.Node, debugMode?: boolean): string; | ||
| declare function extractTreeNode(initNode: globalThis.Node, debugMode?: boolean): WebElementNode; | ||
| declare function extractTextWithPosition(initNode: globalThis.Document): ElementInfo[]; | ||
| interface ElementInfo { | ||
| id: string; | ||
| indexId: number; | ||
| nodeHashId: string; | ||
| locator: string; | ||
| attributes: { | ||
| nodeType: NodeType; | ||
| [key: string]: string; | ||
| }; | ||
| nodeType: NodeType; | ||
| content: string; | ||
| rect: { | ||
| left: number; | ||
| top: number; | ||
| width: number; | ||
| height: number; | ||
| }; | ||
| center: [number, number]; | ||
| } | ||
| interface ElementNode { | ||
| node: ElementInfo | null; | ||
| children: ElementNode[]; | ||
| } | ||
| export { type ElementInfo, type ElementNode, extractTextWithPosition as clientExtractTextWithPosition, descriptionOfTree, traverseTree, treeToList, extractTreeNode as webExtractNodeTree, extractTreeNodeAsString as webExtractNodeTreeAsString, extractTextWithPosition$1 as webExtractTextWithPosition }; |
| interface PkgInfo { | ||
| name: string; | ||
| version: string; | ||
| dir: string; | ||
| } | ||
| declare function getRunningPkgInfo(dir?: string): PkgInfo | null; | ||
| /** | ||
| * Find the nearest package.json file recursively | ||
| * @param {string} dir - Home directory | ||
| * @returns {string|null} - The most recent package.json file path or null | ||
| */ | ||
| declare function findNearestPackageJson(dir: string): string | null; | ||
| declare function getExtraReturnLogic(tree?: boolean): Promise<string | null>; | ||
| export { findNearestPackageJson, getExtraReturnLogic, getRunningPkgInfo }; |
| import { Buffer } from 'node:buffer'; | ||
| import Jimp from 'jimp'; | ||
| import { NodeType } from './constants.js'; | ||
| import { R as Rect } from './index-305e7a7e.js'; | ||
| interface Size { | ||
| width: number; | ||
| height: number; | ||
| dpr?: number; | ||
| } | ||
| interface ImageInfo extends Size { | ||
| jimpImage: Jimp; | ||
| } | ||
| /** | ||
| * Retrieves the dimensions of an image asynchronously | ||
| * | ||
| * @param image - The image data, which can be a string path or a buffer | ||
| * @returns A Promise that resolves to an object containing the width and height of the image | ||
| * @throws Error if the image data is invalid | ||
| */ | ||
| declare function imageInfo(image: string | Buffer | Jimp): Promise<ImageInfo>; | ||
| /** | ||
| * Retrieves the dimensions of an image from a base64-encoded string | ||
| * | ||
| * @param imageBase64 - The base64-encoded image data | ||
| * @returns A Promise that resolves to an object containing the width and height of the image | ||
| * @throws Error if the image data is invalid | ||
| */ | ||
| declare function imageInfoOfBase64(imageBase64: string): Promise<ImageInfo>; | ||
| declare function bufferFromBase64(imageBase64: string): Promise<Buffer>; | ||
| /** | ||
| * Encodes an image file to a base64 encoded string | ||
| * | ||
| * @param image The path of the image file | ||
| * @param withHeader Determine whether to return data including the file header information, the default is true | ||
| * | ||
| * @returns The base64 encoded string of the image file, which may or may not include header information depending on the withHeader parameter | ||
| * | ||
| * @throws When the image type is not supported, an error will be thrown | ||
| */ | ||
| declare function base64Encoded(image: string, withHeader?: boolean): string; | ||
| /** | ||
| /** | ||
| * Saves a Base64-encoded image to a file | ||
| * | ||
| * @param options - An object containing the Base64-encoded image data and the output file path | ||
| * @param options.base64Data - The Base64-encoded image data | ||
| * @param options.outputPath - The path where the image will be saved | ||
| * @throws Error if there is an error during the saving process | ||
| */ | ||
| declare function saveBase64Image(options: { | ||
| base64Data: string; | ||
| outputPath: string; | ||
| }): Promise<void>; | ||
| /** | ||
| * Transforms an image path into a base64-encoded string | ||
| * @param inputPath - The path of the image file to be encoded | ||
| * @returns A Promise that resolves to a base64-encoded string representing the image file | ||
| */ | ||
| declare function transformImgPathToBase64(inputPath: string): Promise<string>; | ||
| /** | ||
| * Resizes an image from a base64-encoded string | ||
| * | ||
| * @param base64Data - A base64-encoded string representing the image | ||
| * @returns A Promise that resolves to a base64-encoded string representing the resized image | ||
| * @throws An error if the width or height cannot be determined from the metadata | ||
| */ | ||
| declare function resizeImg(inputData: Buffer, newSize: { | ||
| width: number; | ||
| height: number; | ||
| }): Promise<Buffer>; | ||
| declare function resizeImgBase64(inputBase64: string, newSize: { | ||
| width: number; | ||
| height: number; | ||
| }): Promise<string>; | ||
| /** | ||
| * Calculates new dimensions for an image while maintaining its aspect ratio. | ||
| * | ||
| * This function is designed to resize an image to fit within a specified maximum width and height | ||
| * while maintaining the original aspect ratio. If the original width or height exceeds the maximum | ||
| * dimensions, the image will be scaled down to fit. | ||
| * | ||
| * @param {number} originalWidth - The original width of the image. | ||
| * @param {number} originalHeight - The original height of the image. | ||
| * @returns {Object} An object containing the new width and height. | ||
| * @throws {Error} Throws an error if the width or height is not a positive number. | ||
| */ | ||
| declare function zoomForGPT4o(originalWidth: number, originalHeight: number): { | ||
| width: number; | ||
| height: number; | ||
| }; | ||
| /** | ||
| * Trims an image and returns the trimming information, including the offset from the left and top edges, and the trimmed width and height | ||
| * | ||
| * @param image - The image to be trimmed. This can be a file path or a Buffer object containing the image data | ||
| * @returns A Promise that resolves to an object containing the trimming information. If the image does not need to be trimmed, this object will be null | ||
| */ | ||
| declare function trimImage(image: string | Buffer): Promise<{ | ||
| trimOffsetLeft: number; | ||
| trimOffsetTop: number; | ||
| width: number; | ||
| height: number; | ||
| } | null>; | ||
| declare function paddingToMatchBlock(imageBase64: string, blockSize?: number): Promise<string>; | ||
| type ElementType = { | ||
| locator?: string; | ||
| rect: Rect; | ||
| center?: [number, number]; | ||
| id?: string; | ||
| indexId: number; | ||
| attributes?: { | ||
| nodeType: NodeType; | ||
| [key: string]: string; | ||
| }; | ||
| }; | ||
| declare const compositeElementInfoImg: (options: { | ||
| inputImgBase64: string; | ||
| elementsPositionInfo: Array<ElementType>; | ||
| size?: { | ||
| width: number; | ||
| height: number; | ||
| }; | ||
| annotationPadding?: number; | ||
| }) => Promise<string>; | ||
| declare const processImageElementInfo: (options: { | ||
| inputImgBase64: string; | ||
| elementsPositionInfo: Array<ElementType>; | ||
| elementsPositionInfoWithoutText: Array<ElementType>; | ||
| }) => Promise<{ | ||
| compositeElementInfoImgBase64: string; | ||
| compositeElementInfoImgWithoutTextBase64: string; | ||
| }>; | ||
| declare function drawBoxOnImage(options: { | ||
| inputImgBase64: string; | ||
| rect: { | ||
| x: number; | ||
| y: number; | ||
| }; | ||
| }): Promise<string>; | ||
| declare function savePositionImg(options: { | ||
| inputImgBase64: string; | ||
| rect: { | ||
| x: number; | ||
| y: number; | ||
| }; | ||
| outputPath: string; | ||
| }): Promise<void>; | ||
| export { base64Encoded, bufferFromBase64, compositeElementInfoImg, drawBoxOnImage, imageInfo, imageInfoOfBase64, paddingToMatchBlock, processImageElementInfo, resizeImg, resizeImgBase64, saveBase64Image, savePositionImg, transformImgPathToBase64, trimImage, zoomForGPT4o }; |
| import { NodeType } from './constants.js'; | ||
| interface Point { | ||
| left: number; | ||
| top: number; | ||
| } | ||
| interface Size { | ||
| width: number; | ||
| height: number; | ||
| dpr?: number; | ||
| } | ||
| type Rect = Point & Size & { | ||
| zoom?: number; | ||
| }; | ||
| declare abstract class BaseElement { | ||
| abstract id: string; | ||
| abstract indexId?: number; | ||
| abstract attributes: { | ||
| nodeType: NodeType; | ||
| [key: string]: string; | ||
| }; | ||
| abstract content: string; | ||
| abstract rect: Rect; | ||
| abstract center: [number, number]; | ||
| abstract locator?: string; | ||
| } | ||
| interface ElementTreeNode<ElementType extends BaseElement = BaseElement> { | ||
| node: ElementType | null; | ||
| children: ElementTreeNode<ElementType>[]; | ||
| } | ||
| export { BaseElement as B, type ElementTreeNode as E, type Rect as R }; |
| /** | ||
| * @license | ||
| * Copyright 2017 Google Inc. | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
| /** | ||
| * @internal | ||
| */ | ||
| interface KeyDefinition { | ||
| keyCode?: number; | ||
| shiftKeyCode?: number; | ||
| key?: string; | ||
| shiftKey?: string; | ||
| code?: string; | ||
| text?: string; | ||
| shiftText?: string; | ||
| location?: number; | ||
| } | ||
| /** | ||
| * All the valid keys that can be passed to functions that take user input, such | ||
| * as {@link Keyboard.press | keyboard.press } | ||
| * | ||
| * @public | ||
| */ | ||
| type KeyInput = '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' | 'Power' | 'Eject' | 'Abort' | 'Help' | 'Backspace' | 'Tab' | 'Numpad5' | 'NumpadEnter' | 'Enter' | '\r' | '\n' | 'ShiftLeft' | 'ShiftRight' | 'ControlLeft' | 'ControlRight' | 'AltLeft' | 'AltRight' | 'Pause' | 'CapsLock' | 'Escape' | 'Convert' | 'NonConvert' | 'Space' | 'Numpad9' | 'PageUp' | 'Numpad3' | 'PageDown' | 'End' | 'Numpad1' | 'Home' | 'Numpad7' | 'ArrowLeft' | 'Numpad4' | 'Numpad8' | 'ArrowUp' | 'ArrowRight' | 'Numpad6' | 'Numpad2' | 'ArrowDown' | 'Select' | 'Open' | 'PrintScreen' | 'Insert' | 'Numpad0' | 'Delete' | 'NumpadDecimal' | 'Digit0' | 'Digit1' | 'Digit2' | 'Digit3' | 'Digit4' | 'Digit5' | 'Digit6' | 'Digit7' | 'Digit8' | 'Digit9' | 'KeyA' | 'KeyB' | 'KeyC' | 'KeyD' | 'KeyE' | 'KeyF' | 'KeyG' | 'KeyH' | 'KeyI' | 'KeyJ' | 'KeyK' | 'KeyL' | 'KeyM' | 'KeyN' | 'KeyO' | 'KeyP' | 'KeyQ' | 'KeyR' | 'KeyS' | 'KeyT' | 'KeyU' | 'KeyV' | 'KeyW' | 'KeyX' | 'KeyY' | 'KeyZ' | 'MetaLeft' | 'MetaRight' | 'ContextMenu' | 'NumpadMultiply' | 'NumpadAdd' | 'NumpadSubtract' | 'NumpadDivide' | 'F1' | 'F2' | 'F3' | 'F4' | 'F5' | 'F6' | 'F7' | 'F8' | 'F9' | 'F10' | 'F11' | 'F12' | 'F13' | 'F14' | 'F15' | 'F16' | 'F17' | 'F18' | 'F19' | 'F20' | 'F21' | 'F22' | 'F23' | 'F24' | 'NumLock' | 'ScrollLock' | 'AudioVolumeMute' | 'AudioVolumeDown' | 'AudioVolumeUp' | 'MediaTrackNext' | 'MediaTrackPrevious' | 'MediaStop' | 'MediaPlayPause' | 'Semicolon' | 'Equal' | 'NumpadEqual' | 'Comma' | 'Minus' | 'Period' | 'Slash' | 'Backquote' | 'BracketLeft' | 'Backslash' | 'BracketRight' | 'Quote' | 'AltGraph' | 'Props' | 'Cancel' | 'Clear' | 'Shift' | 'Control' | 'Alt' | 'Accept' | 'ModeChange' | ' ' | 'Print' | 'Execute' | '\u0000' | 'a' | 'b' | 'c' | 'd' | 'e' | 'f' | 'g' | 'h' | 'i' | 'j' | 'k' | 'l' | 'm' | 'n' | 'o' | 'p' | 'q' | 'r' | 's' | 't' | 'u' | 'v' | 'w' | 'x' | 'y' | 'z' | 'Meta' | '*' | '+' | '-' | '/' | ';' | '=' | ',' | '.' | '`' | '[' | '\\' | ']' | "'" | 'Attn' | 'CrSel' | 'ExSel' | 'EraseEof' | 'Play' | 'ZoomOut' | ')' | '!' | '@' | '#' | '$' | '%' | '^' | '&' | '(' | 'A' | 'B' | 'C' | 'D' | 'E' | 'F' | 'G' | 'H' | 'I' | 'J' | 'K' | 'L' | 'M' | 'N' | 'O' | 'P' | 'Q' | 'R' | 'S' | 'T' | 'U' | 'V' | 'W' | 'X' | 'Y' | 'Z' | ':' | '<' | '_' | '>' | '?' | '~' | '{' | '|' | '}' | '"' | 'SoftLeft' | 'SoftRight' | 'Camera' | 'Call' | 'EndCall' | 'VolumeDown' | 'VolumeUp'; | ||
| /** | ||
| * @internal | ||
| */ | ||
| declare const _keyDefinitions: Readonly<Record<KeyInput, KeyDefinition>>; | ||
| declare const getKeyDefinition: (key: string) => KeyInput; | ||
| declare const isMac: boolean; | ||
| declare function transformHotkeyInput(keyInput: string): string[]; | ||
| export { type KeyDefinition, type KeyInput, _keyDefinitions, getKeyDefinition, isMac, transformHotkeyInput }; |
| import debug from 'debug'; | ||
| declare const ifInBrowser: boolean; | ||
| declare function uuid(): string; | ||
| declare function getDebug(topic: string): debug.Debugger; | ||
| declare function enableDebug(topic: string): void; | ||
| declare function generateHashId(rect: any, content?: string): string; | ||
| /** | ||
| * A utility function that asserts a condition and throws an error with a message if the condition is false. | ||
| * | ||
| * @param condition - The condition to assert | ||
| * @param message - The error message to throw if the condition is false | ||
| * @throws Error with the provided message if the condition is false | ||
| */ | ||
| declare function assert(condition: any, message?: string): asserts condition; | ||
| export { assert, enableDebug, generateHashId, getDebug, ifInBrowser, uuid }; |
| import { existsSync, readFileSync } from 'node:fs'; | ||
| import { dirname, join } from 'node:path'; | ||
| import path from 'node:path'; | ||
| import { assert, ifInBrowser } from '../utils'; | ||
| interface PkgInfo { | ||
| name: string; | ||
| version: string; | ||
| dir: string; | ||
| } | ||
| const pkgCacheMap: Record<string, PkgInfo> = {}; | ||
| export function getRunningPkgInfo(dir?: string): PkgInfo | null { | ||
| if (ifInBrowser) { | ||
| return null; | ||
| } | ||
| const dirToCheck = dir || process.cwd(); | ||
| if (pkgCacheMap[dirToCheck]) { | ||
| return pkgCacheMap[dirToCheck]; | ||
| } | ||
| const pkgDir = findNearestPackageJson(dirToCheck); | ||
| const pkgJsonFile = pkgDir ? join(pkgDir, 'package.json') : null; | ||
| if (pkgDir && pkgJsonFile) { | ||
| const { name, version } = JSON.parse(readFileSync(pkgJsonFile, 'utf-8')); | ||
| pkgCacheMap[dirToCheck] = { | ||
| name: name || 'midscene-unknown-package-name', | ||
| version: version || '0.0.0', | ||
| dir: pkgDir, | ||
| }; | ||
| return pkgCacheMap[dirToCheck]; | ||
| } | ||
| return { | ||
| name: 'midscene-unknown-package-name', | ||
| version: '0.0.0', | ||
| dir: dirToCheck, | ||
| }; | ||
| } | ||
| /** | ||
| * Find the nearest package.json file recursively | ||
| * @param {string} dir - Home directory | ||
| * @returns {string|null} - The most recent package.json file path or null | ||
| */ | ||
| export function findNearestPackageJson(dir: string): string | null { | ||
| const packageJsonPath = join(dir, 'package.json'); | ||
| if (existsSync(packageJsonPath)) { | ||
| return dir; | ||
| } | ||
| const parentDir = dirname(dir); | ||
| // Return null if the root directory has been reached | ||
| if (parentDir === dir) { | ||
| return null; | ||
| } | ||
| return findNearestPackageJson(parentDir); | ||
| } | ||
| export async function getExtraReturnLogic(tree = false) { | ||
| if (ifInBrowser) { | ||
| return null; | ||
| } | ||
| // Get __dirname equivalent in Node.js environment | ||
| const currentFilePath = __filename; | ||
| const pathDir = findNearestPackageJson(dirname(currentFilePath)); | ||
| assert(pathDir, `can't find pathDir, with ${dirname}`); | ||
| const scriptPath = path.join(pathDir, './dist/script/htmlElement.js'); | ||
| const elementInfosScriptContent = readFileSync(scriptPath, 'utf-8'); | ||
| if (tree) { | ||
| return `${elementInfosScriptContent}midscene_element_inspector.webExtractNodeTree()`; | ||
| } | ||
| return `${elementInfosScriptContent}midscene_element_inspector.webExtractTextWithPosition()`; | ||
| } |
+26
-622
@@ -1,570 +0,1 @@ | ||
| var __create = Object.create; | ||
| var __defProp = Object.defineProperty; | ||
| var __defProps = Object.defineProperties; | ||
| var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
| var __getOwnPropDescs = Object.getOwnPropertyDescriptors; | ||
| var __getOwnPropNames = Object.getOwnPropertyNames; | ||
| var __getOwnPropSymbols = Object.getOwnPropertySymbols; | ||
| var __getProtoOf = Object.getPrototypeOf; | ||
| var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
| var __propIsEnum = Object.prototype.propertyIsEnumerable; | ||
| var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; | ||
| var __spreadValues = (a, b) => { | ||
| for (var prop in b || (b = {})) | ||
| if (__hasOwnProp.call(b, prop)) | ||
| __defNormalProp(a, prop, b[prop]); | ||
| if (__getOwnPropSymbols) | ||
| for (var prop of __getOwnPropSymbols(b)) { | ||
| if (__propIsEnum.call(b, prop)) | ||
| __defNormalProp(a, prop, b[prop]); | ||
| } | ||
| return a; | ||
| }; | ||
| var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b)); | ||
| var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, { | ||
| get: (a, b) => (typeof require !== "undefined" ? require : a)[b] | ||
| }) : x)(function(x) { | ||
| if (typeof require !== "undefined") | ||
| return require.apply(this, arguments); | ||
| throw Error('Dynamic require of "' + x + '" is not supported'); | ||
| }); | ||
| var __commonJS = (cb, mod) => function __require2() { | ||
| return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports; | ||
| }; | ||
| var __copyProps = (to, from, except, desc) => { | ||
| if (from && typeof from === "object" || typeof from === "function") { | ||
| for (let key of __getOwnPropNames(from)) | ||
| if (!__hasOwnProp.call(to, key) && key !== except) | ||
| __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); | ||
| } | ||
| return to; | ||
| }; | ||
| var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( | ||
| // If the importer is in node compatibility mode or this is not an ESM | ||
| // file that has been converted to a CommonJS file using a Babel- | ||
| // compatible transform (i.e. "__esModule" has not been set), then set | ||
| // "default" to the CommonJS "module.exports" for node compatibility. | ||
| isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, | ||
| mod | ||
| )); | ||
| // ../../node_modules/.pnpm/js-sha256@0.11.0/node_modules/js-sha256/src/sha256.js | ||
| var require_sha256 = __commonJS({ | ||
| "../../node_modules/.pnpm/js-sha256@0.11.0/node_modules/js-sha256/src/sha256.js"(exports, module) { | ||
| "use strict"; | ||
| (function() { | ||
| "use strict"; | ||
| var ERROR = "input is invalid type"; | ||
| var WINDOW = typeof window === "object"; | ||
| var root = WINDOW ? window : {}; | ||
| if (root.JS_SHA256_NO_WINDOW) { | ||
| WINDOW = false; | ||
| } | ||
| var WEB_WORKER = !WINDOW && typeof self === "object"; | ||
| var NODE_JS = !root.JS_SHA256_NO_NODE_JS && typeof process === "object" && process.versions && process.versions.node; | ||
| if (NODE_JS) { | ||
| root = global; | ||
| } else if (WEB_WORKER) { | ||
| root = self; | ||
| } | ||
| var COMMON_JS = !root.JS_SHA256_NO_COMMON_JS && typeof module === "object" && module.exports; | ||
| var AMD = typeof define === "function" && define.amd; | ||
| var ARRAY_BUFFER = !root.JS_SHA256_NO_ARRAY_BUFFER && typeof ArrayBuffer !== "undefined"; | ||
| var HEX_CHARS = "0123456789abcdef".split(""); | ||
| var EXTRA = [-2147483648, 8388608, 32768, 128]; | ||
| var SHIFT = [24, 16, 8, 0]; | ||
| var K = [ | ||
| 1116352408, | ||
| 1899447441, | ||
| 3049323471, | ||
| 3921009573, | ||
| 961987163, | ||
| 1508970993, | ||
| 2453635748, | ||
| 2870763221, | ||
| 3624381080, | ||
| 310598401, | ||
| 607225278, | ||
| 1426881987, | ||
| 1925078388, | ||
| 2162078206, | ||
| 2614888103, | ||
| 3248222580, | ||
| 3835390401, | ||
| 4022224774, | ||
| 264347078, | ||
| 604807628, | ||
| 770255983, | ||
| 1249150122, | ||
| 1555081692, | ||
| 1996064986, | ||
| 2554220882, | ||
| 2821834349, | ||
| 2952996808, | ||
| 3210313671, | ||
| 3336571891, | ||
| 3584528711, | ||
| 113926993, | ||
| 338241895, | ||
| 666307205, | ||
| 773529912, | ||
| 1294757372, | ||
| 1396182291, | ||
| 1695183700, | ||
| 1986661051, | ||
| 2177026350, | ||
| 2456956037, | ||
| 2730485921, | ||
| 2820302411, | ||
| 3259730800, | ||
| 3345764771, | ||
| 3516065817, | ||
| 3600352804, | ||
| 4094571909, | ||
| 275423344, | ||
| 430227734, | ||
| 506948616, | ||
| 659060556, | ||
| 883997877, | ||
| 958139571, | ||
| 1322822218, | ||
| 1537002063, | ||
| 1747873779, | ||
| 1955562222, | ||
| 2024104815, | ||
| 2227730452, | ||
| 2361852424, | ||
| 2428436474, | ||
| 2756734187, | ||
| 3204031479, | ||
| 3329325298 | ||
| ]; | ||
| var OUTPUT_TYPES = ["hex", "array", "digest", "arrayBuffer"]; | ||
| var blocks = []; | ||
| if (root.JS_SHA256_NO_NODE_JS || !Array.isArray) { | ||
| Array.isArray = function(obj) { | ||
| return Object.prototype.toString.call(obj) === "[object Array]"; | ||
| }; | ||
| } | ||
| if (ARRAY_BUFFER && (root.JS_SHA256_NO_ARRAY_BUFFER_IS_VIEW || !ArrayBuffer.isView)) { | ||
| ArrayBuffer.isView = function(obj) { | ||
| return typeof obj === "object" && obj.buffer && obj.buffer.constructor === ArrayBuffer; | ||
| }; | ||
| } | ||
| var createOutputMethod = function(outputType, is224) { | ||
| return function(message) { | ||
| return new Sha256(is224, true).update(message)[outputType](); | ||
| }; | ||
| }; | ||
| var createMethod = function(is224) { | ||
| var method = createOutputMethod("hex", is224); | ||
| if (NODE_JS) { | ||
| method = nodeWrap(method, is224); | ||
| } | ||
| method.create = function() { | ||
| return new Sha256(is224); | ||
| }; | ||
| method.update = function(message) { | ||
| return method.create().update(message); | ||
| }; | ||
| for (var i = 0; i < OUTPUT_TYPES.length; ++i) { | ||
| var type = OUTPUT_TYPES[i]; | ||
| method[type] = createOutputMethod(type, is224); | ||
| } | ||
| return method; | ||
| }; | ||
| var nodeWrap = function(method, is224) { | ||
| var crypto = __require("crypto"); | ||
| var Buffer2 = __require("buffer").Buffer; | ||
| var algorithm = is224 ? "sha224" : "sha256"; | ||
| var bufferFrom; | ||
| if (Buffer2.from && !root.JS_SHA256_NO_BUFFER_FROM) { | ||
| bufferFrom = Buffer2.from; | ||
| } else { | ||
| bufferFrom = function(message) { | ||
| return new Buffer2(message); | ||
| }; | ||
| } | ||
| var nodeMethod = function(message) { | ||
| if (typeof message === "string") { | ||
| return crypto.createHash(algorithm).update(message, "utf8").digest("hex"); | ||
| } else { | ||
| if (message === null || message === void 0) { | ||
| throw new Error(ERROR); | ||
| } else if (message.constructor === ArrayBuffer) { | ||
| message = new Uint8Array(message); | ||
| } | ||
| } | ||
| if (Array.isArray(message) || ArrayBuffer.isView(message) || message.constructor === Buffer2) { | ||
| return crypto.createHash(algorithm).update(bufferFrom(message)).digest("hex"); | ||
| } else { | ||
| return method(message); | ||
| } | ||
| }; | ||
| return nodeMethod; | ||
| }; | ||
| var createHmacOutputMethod = function(outputType, is224) { | ||
| return function(key, message) { | ||
| return new HmacSha256(key, is224, true).update(message)[outputType](); | ||
| }; | ||
| }; | ||
| var createHmacMethod = function(is224) { | ||
| var method = createHmacOutputMethod("hex", is224); | ||
| method.create = function(key) { | ||
| return new HmacSha256(key, is224); | ||
| }; | ||
| method.update = function(key, message) { | ||
| return method.create(key).update(message); | ||
| }; | ||
| for (var i = 0; i < OUTPUT_TYPES.length; ++i) { | ||
| var type = OUTPUT_TYPES[i]; | ||
| method[type] = createHmacOutputMethod(type, is224); | ||
| } | ||
| return method; | ||
| }; | ||
| function Sha256(is224, sharedMemory) { | ||
| if (sharedMemory) { | ||
| blocks[0] = blocks[16] = blocks[1] = blocks[2] = blocks[3] = blocks[4] = blocks[5] = blocks[6] = blocks[7] = blocks[8] = blocks[9] = blocks[10] = blocks[11] = blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0; | ||
| this.blocks = blocks; | ||
| } else { | ||
| this.blocks = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; | ||
| } | ||
| if (is224) { | ||
| this.h0 = 3238371032; | ||
| this.h1 = 914150663; | ||
| this.h2 = 812702999; | ||
| this.h3 = 4144912697; | ||
| this.h4 = 4290775857; | ||
| this.h5 = 1750603025; | ||
| this.h6 = 1694076839; | ||
| this.h7 = 3204075428; | ||
| } else { | ||
| this.h0 = 1779033703; | ||
| this.h1 = 3144134277; | ||
| this.h2 = 1013904242; | ||
| this.h3 = 2773480762; | ||
| this.h4 = 1359893119; | ||
| this.h5 = 2600822924; | ||
| this.h6 = 528734635; | ||
| this.h7 = 1541459225; | ||
| } | ||
| this.block = this.start = this.bytes = this.hBytes = 0; | ||
| this.finalized = this.hashed = false; | ||
| this.first = true; | ||
| this.is224 = is224; | ||
| } | ||
| Sha256.prototype.update = function(message) { | ||
| if (this.finalized) { | ||
| return; | ||
| } | ||
| var notString, type = typeof message; | ||
| if (type !== "string") { | ||
| if (type === "object") { | ||
| if (message === null) { | ||
| throw new Error(ERROR); | ||
| } else if (ARRAY_BUFFER && message.constructor === ArrayBuffer) { | ||
| message = new Uint8Array(message); | ||
| } else if (!Array.isArray(message)) { | ||
| if (!ARRAY_BUFFER || !ArrayBuffer.isView(message)) { | ||
| throw new Error(ERROR); | ||
| } | ||
| } | ||
| } else { | ||
| throw new Error(ERROR); | ||
| } | ||
| notString = true; | ||
| } | ||
| var code, index = 0, i, length = message.length, blocks2 = this.blocks; | ||
| while (index < length) { | ||
| if (this.hashed) { | ||
| this.hashed = false; | ||
| blocks2[0] = this.block; | ||
| this.block = blocks2[16] = blocks2[1] = blocks2[2] = blocks2[3] = blocks2[4] = blocks2[5] = blocks2[6] = blocks2[7] = blocks2[8] = blocks2[9] = blocks2[10] = blocks2[11] = blocks2[12] = blocks2[13] = blocks2[14] = blocks2[15] = 0; | ||
| } | ||
| if (notString) { | ||
| for (i = this.start; index < length && i < 64; ++index) { | ||
| blocks2[i >>> 2] |= message[index] << SHIFT[i++ & 3]; | ||
| } | ||
| } else { | ||
| for (i = this.start; index < length && i < 64; ++index) { | ||
| code = message.charCodeAt(index); | ||
| if (code < 128) { | ||
| blocks2[i >>> 2] |= code << SHIFT[i++ & 3]; | ||
| } else if (code < 2048) { | ||
| blocks2[i >>> 2] |= (192 | code >>> 6) << SHIFT[i++ & 3]; | ||
| blocks2[i >>> 2] |= (128 | code & 63) << SHIFT[i++ & 3]; | ||
| } else if (code < 55296 || code >= 57344) { | ||
| blocks2[i >>> 2] |= (224 | code >>> 12) << SHIFT[i++ & 3]; | ||
| blocks2[i >>> 2] |= (128 | code >>> 6 & 63) << SHIFT[i++ & 3]; | ||
| blocks2[i >>> 2] |= (128 | code & 63) << SHIFT[i++ & 3]; | ||
| } else { | ||
| code = 65536 + ((code & 1023) << 10 | message.charCodeAt(++index) & 1023); | ||
| blocks2[i >>> 2] |= (240 | code >>> 18) << SHIFT[i++ & 3]; | ||
| blocks2[i >>> 2] |= (128 | code >>> 12 & 63) << SHIFT[i++ & 3]; | ||
| blocks2[i >>> 2] |= (128 | code >>> 6 & 63) << SHIFT[i++ & 3]; | ||
| blocks2[i >>> 2] |= (128 | code & 63) << SHIFT[i++ & 3]; | ||
| } | ||
| } | ||
| } | ||
| this.lastByteIndex = i; | ||
| this.bytes += i - this.start; | ||
| if (i >= 64) { | ||
| this.block = blocks2[16]; | ||
| this.start = i - 64; | ||
| this.hash(); | ||
| this.hashed = true; | ||
| } else { | ||
| this.start = i; | ||
| } | ||
| } | ||
| if (this.bytes > 4294967295) { | ||
| this.hBytes += this.bytes / 4294967296 << 0; | ||
| this.bytes = this.bytes % 4294967296; | ||
| } | ||
| return this; | ||
| }; | ||
| Sha256.prototype.finalize = function() { | ||
| if (this.finalized) { | ||
| return; | ||
| } | ||
| this.finalized = true; | ||
| var blocks2 = this.blocks, i = this.lastByteIndex; | ||
| blocks2[16] = this.block; | ||
| blocks2[i >>> 2] |= EXTRA[i & 3]; | ||
| this.block = blocks2[16]; | ||
| if (i >= 56) { | ||
| if (!this.hashed) { | ||
| this.hash(); | ||
| } | ||
| blocks2[0] = this.block; | ||
| blocks2[16] = blocks2[1] = blocks2[2] = blocks2[3] = blocks2[4] = blocks2[5] = blocks2[6] = blocks2[7] = blocks2[8] = blocks2[9] = blocks2[10] = blocks2[11] = blocks2[12] = blocks2[13] = blocks2[14] = blocks2[15] = 0; | ||
| } | ||
| blocks2[14] = this.hBytes << 3 | this.bytes >>> 29; | ||
| blocks2[15] = this.bytes << 3; | ||
| this.hash(); | ||
| }; | ||
| Sha256.prototype.hash = function() { | ||
| var a = this.h0, b = this.h1, c = this.h2, d = this.h3, e = this.h4, f = this.h5, g = this.h6, h = this.h7, blocks2 = this.blocks, j, s0, s1, maj, t1, t2, ch, ab, da, cd, bc; | ||
| for (j = 16; j < 64; ++j) { | ||
| t1 = blocks2[j - 15]; | ||
| s0 = (t1 >>> 7 | t1 << 25) ^ (t1 >>> 18 | t1 << 14) ^ t1 >>> 3; | ||
| t1 = blocks2[j - 2]; | ||
| s1 = (t1 >>> 17 | t1 << 15) ^ (t1 >>> 19 | t1 << 13) ^ t1 >>> 10; | ||
| blocks2[j] = blocks2[j - 16] + s0 + blocks2[j - 7] + s1 << 0; | ||
| } | ||
| bc = b & c; | ||
| for (j = 0; j < 64; j += 4) { | ||
| if (this.first) { | ||
| if (this.is224) { | ||
| ab = 300032; | ||
| t1 = blocks2[0] - 1413257819; | ||
| h = t1 - 150054599 << 0; | ||
| d = t1 + 24177077 << 0; | ||
| } else { | ||
| ab = 704751109; | ||
| t1 = blocks2[0] - 210244248; | ||
| h = t1 - 1521486534 << 0; | ||
| d = t1 + 143694565 << 0; | ||
| } | ||
| this.first = false; | ||
| } else { | ||
| s0 = (a >>> 2 | a << 30) ^ (a >>> 13 | a << 19) ^ (a >>> 22 | a << 10); | ||
| s1 = (e >>> 6 | e << 26) ^ (e >>> 11 | e << 21) ^ (e >>> 25 | e << 7); | ||
| ab = a & b; | ||
| maj = ab ^ a & c ^ bc; | ||
| ch = e & f ^ ~e & g; | ||
| t1 = h + s1 + ch + K[j] + blocks2[j]; | ||
| t2 = s0 + maj; | ||
| h = d + t1 << 0; | ||
| d = t1 + t2 << 0; | ||
| } | ||
| s0 = (d >>> 2 | d << 30) ^ (d >>> 13 | d << 19) ^ (d >>> 22 | d << 10); | ||
| s1 = (h >>> 6 | h << 26) ^ (h >>> 11 | h << 21) ^ (h >>> 25 | h << 7); | ||
| da = d & a; | ||
| maj = da ^ d & b ^ ab; | ||
| ch = h & e ^ ~h & f; | ||
| t1 = g + s1 + ch + K[j + 1] + blocks2[j + 1]; | ||
| t2 = s0 + maj; | ||
| g = c + t1 << 0; | ||
| c = t1 + t2 << 0; | ||
| s0 = (c >>> 2 | c << 30) ^ (c >>> 13 | c << 19) ^ (c >>> 22 | c << 10); | ||
| s1 = (g >>> 6 | g << 26) ^ (g >>> 11 | g << 21) ^ (g >>> 25 | g << 7); | ||
| cd = c & d; | ||
| maj = cd ^ c & a ^ da; | ||
| ch = g & h ^ ~g & e; | ||
| t1 = f + s1 + ch + K[j + 2] + blocks2[j + 2]; | ||
| t2 = s0 + maj; | ||
| f = b + t1 << 0; | ||
| b = t1 + t2 << 0; | ||
| s0 = (b >>> 2 | b << 30) ^ (b >>> 13 | b << 19) ^ (b >>> 22 | b << 10); | ||
| s1 = (f >>> 6 | f << 26) ^ (f >>> 11 | f << 21) ^ (f >>> 25 | f << 7); | ||
| bc = b & c; | ||
| maj = bc ^ b & d ^ cd; | ||
| ch = f & g ^ ~f & h; | ||
| t1 = e + s1 + ch + K[j + 3] + blocks2[j + 3]; | ||
| t2 = s0 + maj; | ||
| e = a + t1 << 0; | ||
| a = t1 + t2 << 0; | ||
| this.chromeBugWorkAround = true; | ||
| } | ||
| this.h0 = this.h0 + a << 0; | ||
| this.h1 = this.h1 + b << 0; | ||
| this.h2 = this.h2 + c << 0; | ||
| this.h3 = this.h3 + d << 0; | ||
| this.h4 = this.h4 + e << 0; | ||
| this.h5 = this.h5 + f << 0; | ||
| this.h6 = this.h6 + g << 0; | ||
| this.h7 = this.h7 + h << 0; | ||
| }; | ||
| Sha256.prototype.hex = function() { | ||
| this.finalize(); | ||
| var h0 = this.h0, h1 = this.h1, h2 = this.h2, h3 = this.h3, h4 = this.h4, h5 = this.h5, h6 = this.h6, h7 = this.h7; | ||
| var hex = HEX_CHARS[h0 >>> 28 & 15] + HEX_CHARS[h0 >>> 24 & 15] + HEX_CHARS[h0 >>> 20 & 15] + HEX_CHARS[h0 >>> 16 & 15] + HEX_CHARS[h0 >>> 12 & 15] + HEX_CHARS[h0 >>> 8 & 15] + HEX_CHARS[h0 >>> 4 & 15] + HEX_CHARS[h0 & 15] + HEX_CHARS[h1 >>> 28 & 15] + HEX_CHARS[h1 >>> 24 & 15] + HEX_CHARS[h1 >>> 20 & 15] + HEX_CHARS[h1 >>> 16 & 15] + HEX_CHARS[h1 >>> 12 & 15] + HEX_CHARS[h1 >>> 8 & 15] + HEX_CHARS[h1 >>> 4 & 15] + HEX_CHARS[h1 & 15] + HEX_CHARS[h2 >>> 28 & 15] + HEX_CHARS[h2 >>> 24 & 15] + HEX_CHARS[h2 >>> 20 & 15] + HEX_CHARS[h2 >>> 16 & 15] + HEX_CHARS[h2 >>> 12 & 15] + HEX_CHARS[h2 >>> 8 & 15] + HEX_CHARS[h2 >>> 4 & 15] + HEX_CHARS[h2 & 15] + HEX_CHARS[h3 >>> 28 & 15] + HEX_CHARS[h3 >>> 24 & 15] + HEX_CHARS[h3 >>> 20 & 15] + HEX_CHARS[h3 >>> 16 & 15] + HEX_CHARS[h3 >>> 12 & 15] + HEX_CHARS[h3 >>> 8 & 15] + HEX_CHARS[h3 >>> 4 & 15] + HEX_CHARS[h3 & 15] + HEX_CHARS[h4 >>> 28 & 15] + HEX_CHARS[h4 >>> 24 & 15] + HEX_CHARS[h4 >>> 20 & 15] + HEX_CHARS[h4 >>> 16 & 15] + HEX_CHARS[h4 >>> 12 & 15] + HEX_CHARS[h4 >>> 8 & 15] + HEX_CHARS[h4 >>> 4 & 15] + HEX_CHARS[h4 & 15] + HEX_CHARS[h5 >>> 28 & 15] + HEX_CHARS[h5 >>> 24 & 15] + HEX_CHARS[h5 >>> 20 & 15] + HEX_CHARS[h5 >>> 16 & 15] + HEX_CHARS[h5 >>> 12 & 15] + HEX_CHARS[h5 >>> 8 & 15] + HEX_CHARS[h5 >>> 4 & 15] + HEX_CHARS[h5 & 15] + HEX_CHARS[h6 >>> 28 & 15] + HEX_CHARS[h6 >>> 24 & 15] + HEX_CHARS[h6 >>> 20 & 15] + HEX_CHARS[h6 >>> 16 & 15] + HEX_CHARS[h6 >>> 12 & 15] + HEX_CHARS[h6 >>> 8 & 15] + HEX_CHARS[h6 >>> 4 & 15] + HEX_CHARS[h6 & 15]; | ||
| if (!this.is224) { | ||
| hex += HEX_CHARS[h7 >>> 28 & 15] + HEX_CHARS[h7 >>> 24 & 15] + HEX_CHARS[h7 >>> 20 & 15] + HEX_CHARS[h7 >>> 16 & 15] + HEX_CHARS[h7 >>> 12 & 15] + HEX_CHARS[h7 >>> 8 & 15] + HEX_CHARS[h7 >>> 4 & 15] + HEX_CHARS[h7 & 15]; | ||
| } | ||
| return hex; | ||
| }; | ||
| Sha256.prototype.toString = Sha256.prototype.hex; | ||
| Sha256.prototype.digest = function() { | ||
| this.finalize(); | ||
| var h0 = this.h0, h1 = this.h1, h2 = this.h2, h3 = this.h3, h4 = this.h4, h5 = this.h5, h6 = this.h6, h7 = this.h7; | ||
| var arr = [ | ||
| h0 >>> 24 & 255, | ||
| h0 >>> 16 & 255, | ||
| h0 >>> 8 & 255, | ||
| h0 & 255, | ||
| h1 >>> 24 & 255, | ||
| h1 >>> 16 & 255, | ||
| h1 >>> 8 & 255, | ||
| h1 & 255, | ||
| h2 >>> 24 & 255, | ||
| h2 >>> 16 & 255, | ||
| h2 >>> 8 & 255, | ||
| h2 & 255, | ||
| h3 >>> 24 & 255, | ||
| h3 >>> 16 & 255, | ||
| h3 >>> 8 & 255, | ||
| h3 & 255, | ||
| h4 >>> 24 & 255, | ||
| h4 >>> 16 & 255, | ||
| h4 >>> 8 & 255, | ||
| h4 & 255, | ||
| h5 >>> 24 & 255, | ||
| h5 >>> 16 & 255, | ||
| h5 >>> 8 & 255, | ||
| h5 & 255, | ||
| h6 >>> 24 & 255, | ||
| h6 >>> 16 & 255, | ||
| h6 >>> 8 & 255, | ||
| h6 & 255 | ||
| ]; | ||
| if (!this.is224) { | ||
| arr.push(h7 >>> 24 & 255, h7 >>> 16 & 255, h7 >>> 8 & 255, h7 & 255); | ||
| } | ||
| return arr; | ||
| }; | ||
| Sha256.prototype.array = Sha256.prototype.digest; | ||
| Sha256.prototype.arrayBuffer = function() { | ||
| this.finalize(); | ||
| var buffer = new ArrayBuffer(this.is224 ? 28 : 32); | ||
| var dataView = new DataView(buffer); | ||
| dataView.setUint32(0, this.h0); | ||
| dataView.setUint32(4, this.h1); | ||
| dataView.setUint32(8, this.h2); | ||
| dataView.setUint32(12, this.h3); | ||
| dataView.setUint32(16, this.h4); | ||
| dataView.setUint32(20, this.h5); | ||
| dataView.setUint32(24, this.h6); | ||
| if (!this.is224) { | ||
| dataView.setUint32(28, this.h7); | ||
| } | ||
| return buffer; | ||
| }; | ||
| function HmacSha256(key, is224, sharedMemory) { | ||
| var i, type = typeof key; | ||
| if (type === "string") { | ||
| var bytes = [], length = key.length, index = 0, code; | ||
| for (i = 0; i < length; ++i) { | ||
| code = key.charCodeAt(i); | ||
| if (code < 128) { | ||
| bytes[index++] = code; | ||
| } else if (code < 2048) { | ||
| bytes[index++] = 192 | code >>> 6; | ||
| bytes[index++] = 128 | code & 63; | ||
| } else if (code < 55296 || code >= 57344) { | ||
| bytes[index++] = 224 | code >>> 12; | ||
| bytes[index++] = 128 | code >>> 6 & 63; | ||
| bytes[index++] = 128 | code & 63; | ||
| } else { | ||
| code = 65536 + ((code & 1023) << 10 | key.charCodeAt(++i) & 1023); | ||
| bytes[index++] = 240 | code >>> 18; | ||
| bytes[index++] = 128 | code >>> 12 & 63; | ||
| bytes[index++] = 128 | code >>> 6 & 63; | ||
| bytes[index++] = 128 | code & 63; | ||
| } | ||
| } | ||
| key = bytes; | ||
| } else { | ||
| if (type === "object") { | ||
| if (key === null) { | ||
| throw new Error(ERROR); | ||
| } else if (ARRAY_BUFFER && key.constructor === ArrayBuffer) { | ||
| key = new Uint8Array(key); | ||
| } else if (!Array.isArray(key)) { | ||
| if (!ARRAY_BUFFER || !ArrayBuffer.isView(key)) { | ||
| throw new Error(ERROR); | ||
| } | ||
| } | ||
| } else { | ||
| throw new Error(ERROR); | ||
| } | ||
| } | ||
| if (key.length > 64) { | ||
| key = new Sha256(is224, true).update(key).array(); | ||
| } | ||
| var oKeyPad = [], iKeyPad = []; | ||
| for (i = 0; i < 64; ++i) { | ||
| var b = key[i] || 0; | ||
| oKeyPad[i] = 92 ^ b; | ||
| iKeyPad[i] = 54 ^ b; | ||
| } | ||
| Sha256.call(this, is224, sharedMemory); | ||
| this.update(iKeyPad); | ||
| this.oKeyPad = oKeyPad; | ||
| this.inner = true; | ||
| this.sharedMemory = sharedMemory; | ||
| } | ||
| HmacSha256.prototype = new Sha256(); | ||
| HmacSha256.prototype.finalize = function() { | ||
| Sha256.prototype.finalize.call(this); | ||
| if (this.inner) { | ||
| this.inner = false; | ||
| var innerHash = this.array(); | ||
| Sha256.call(this, this.is224, this.sharedMemory); | ||
| this.update(this.oKeyPad); | ||
| this.update(innerHash); | ||
| Sha256.prototype.finalize.call(this); | ||
| } | ||
| }; | ||
| var exports2 = createMethod(); | ||
| exports2.sha256 = exports2; | ||
| exports2.sha224 = createMethod(true); | ||
| exports2.sha256.hmac = createHmacMethod(); | ||
| exports2.sha224.hmac = createHmacMethod(true); | ||
| if (COMMON_JS) { | ||
| module.exports = exports2; | ||
| } else { | ||
| root.sha256 = exports2.sha256; | ||
| root.sha224 = exports2.sha224; | ||
| if (AMD) { | ||
| define(function() { | ||
| return exports2; | ||
| }); | ||
| } | ||
| } | ||
| })(); | ||
| } | ||
| }); | ||
| // src/constants/index.ts | ||
@@ -643,3 +74,4 @@ var CONTAINER_MINI_HEIGHT = 3; | ||
| // src/utils.ts | ||
| var import_js_sha256 = __toESM(require_sha256()); | ||
| import { sha256 } from "js-sha256"; | ||
| import debug from "debug"; | ||
| var hashMap = {}; | ||
@@ -653,3 +85,3 @@ function generateHashId(rect, content = "") { | ||
| let slicedHash = ""; | ||
| const hashHex = import_js_sha256.sha256.create().update(combined).hex(); | ||
| const hashHex = sha256.create().update(combined).hex(); | ||
| const toLetters = (hex) => { | ||
@@ -803,6 +235,6 @@ return hex.split("").map((char) => { | ||
| } | ||
| if (el == null ? void 0 : el.contains(topElement)) { | ||
| if (el?.contains(topElement)) { | ||
| return false; | ||
| } | ||
| if (topElement == null ? void 0 : topElement.contains(el)) { | ||
| if (topElement?.contains(el)) { | ||
| return false; | ||
@@ -869,3 +301,3 @@ } | ||
| const parentUntilNonStatic = (currentNode) => { | ||
| let parent2 = currentNode == null ? void 0 : currentNode.parentElement; | ||
| let parent2 = currentNode?.parentElement; | ||
| while (parent2) { | ||
@@ -936,24 +368,4 @@ const style = currentWindow.getComputedStyle(parent2); | ||
| } | ||
| var nodeHashCacheList = []; | ||
| if (typeof window !== "undefined") { | ||
| window.midsceneNodeHashCacheList = window.midsceneNodeHashCacheList || []; | ||
| nodeHashCacheList = window.midsceneNodeHashCacheList; | ||
| } | ||
| function resetNodeHashCacheList() { | ||
| if (typeof window !== "undefined") { | ||
| nodeHashCacheList = window.midsceneNodeHashCacheList || []; | ||
| window.midsceneNodeHashCacheList = []; | ||
| } else { | ||
| nodeHashCacheList = []; | ||
| } | ||
| } | ||
| function midsceneGenerateHash(node, content, rect) { | ||
| var _a; | ||
| if (node && nodeHashCacheList.find((item) => item.node === node)) { | ||
| return ((_a = nodeHashCacheList.find((item) => item.node === node)) == null ? void 0 : _a.id) || ""; | ||
| } | ||
| const slicedHash = generateHashId(rect, content); | ||
| if (node && typeof window !== "undefined") { | ||
| window.midsceneNodeHashCacheList.push({ node, id: slicedHash }); | ||
| } | ||
| return slicedHash; | ||
@@ -990,3 +402,2 @@ } | ||
| function collectElementInfo(node, currentWindow, currentDocument, baseZoom = 1, basePoint = { left: 0, top: 0 }) { | ||
| var _a; | ||
| const rect = visibleRect(node, currentWindow, currentDocument, baseZoom); | ||
@@ -1022,6 +433,7 @@ if (!rect || rect.width < CONTAINER_MINI_WIDTH || rect.height < CONTAINER_MINI_HEIGHT) { | ||
| indexId: indexId++, | ||
| attributes: __spreadProps(__spreadValues({}, attributes), { | ||
| attributes: { | ||
| ...attributes, | ||
| htmlTagName: `<${tagName}>`, | ||
| nodeType: "FORM_ITEM Node" /* FORM_ITEM */ | ||
| }), | ||
| }, | ||
| content: valueContent.trim(), | ||
@@ -1051,6 +463,7 @@ rect, | ||
| locator: selector, | ||
| attributes: __spreadProps(__spreadValues({}, attributes), { | ||
| attributes: { | ||
| ...attributes, | ||
| htmlTagName: tagNameOfNode(node), | ||
| nodeType: "BUTTON Node" /* BUTTON */ | ||
| }), | ||
| }, | ||
| content, | ||
@@ -1077,8 +490,10 @@ rect, | ||
| locator: selector, | ||
| attributes: __spreadProps(__spreadValues(__spreadValues({}, attributes), node.nodeName.toLowerCase() === "svg" ? { | ||
| svgContent: "true" | ||
| } : {}), { | ||
| attributes: { | ||
| ...attributes, | ||
| ...node.nodeName.toLowerCase() === "svg" ? { | ||
| svgContent: "true" | ||
| } : {}, | ||
| nodeType: "IMG Node" /* IMG */, | ||
| htmlTagName: tagNameOfNode(node) | ||
| }), | ||
| }, | ||
| nodeType: "IMG Node" /* IMG */, | ||
@@ -1098,3 +513,3 @@ content: "", | ||
| if (isTextElement(node)) { | ||
| const text = (_a = node.textContent) == null ? void 0 : _a.trim().replace(/\n+/g, " "); | ||
| const text = node.textContent?.trim().replace(/\n+/g, " "); | ||
| if (!text) { | ||
@@ -1116,6 +531,7 @@ return null; | ||
| locator: selector, | ||
| attributes: __spreadProps(__spreadValues({}, attributes), { | ||
| attributes: { | ||
| ...attributes, | ||
| nodeType: "TEXT Node" /* TEXT */, | ||
| htmlTagName: tagNameOfNode(node) | ||
| }), | ||
| }, | ||
| center: [ | ||
@@ -1144,6 +560,7 @@ Math.round(rect.left + rect.width / 2), | ||
| locator: selector, | ||
| attributes: __spreadProps(__spreadValues({}, attributes), { | ||
| attributes: { | ||
| ...attributes, | ||
| nodeType: "CONTAINER Node" /* CONTAINER */, | ||
| htmlTagName: tagNameOfNode(node) | ||
| }), | ||
| }, | ||
| content: "", | ||
@@ -1179,3 +596,2 @@ rect, | ||
| setDebugMode(debugMode2); | ||
| resetNodeHashCacheList(); | ||
| indexId = 0; | ||
@@ -1208,3 +624,3 @@ const topDocument = getTopDocument(); | ||
| }; | ||
| if ((elementInfo == null ? void 0 : elementInfo.nodeType) === "BUTTON Node" /* BUTTON */ || (elementInfo == null ? void 0 : elementInfo.nodeType) === "IMG Node" /* IMG */ || (elementInfo == null ? void 0 : elementInfo.nodeType) === "TEXT Node" /* TEXT */ || (elementInfo == null ? void 0 : elementInfo.nodeType) === "FORM_ITEM Node" /* FORM_ITEM */ || (elementInfo == null ? void 0 : elementInfo.nodeType) === "CONTAINER Node" /* CONTAINER */) { | ||
| if (elementInfo?.nodeType === "BUTTON Node" /* BUTTON */ || elementInfo?.nodeType === "IMG Node" /* IMG */ || elementInfo?.nodeType === "TEXT Node" /* TEXT */ || elementInfo?.nodeType === "FORM_ITEM Node" /* FORM_ITEM */ || elementInfo?.nodeType === "CONTAINER Node" /* CONTAINER */) { | ||
| return nodeInfo; | ||
@@ -1270,13 +686,1 @@ } | ||
| setMidsceneVisibleRectOnWindow(); | ||
| /*! Bundled license information: | ||
| js-sha256/src/sha256.js: | ||
| (** | ||
| * [js-sha256]{@link https://github.com/emn178/js-sha256} | ||
| * | ||
| * @version 0.11.0 | ||
| * @author Chen, Yi-Cyuan [emn178@gmail.com] | ||
| * @copyright Chen, Yi-Cyuan 2014-2024 | ||
| * @license MIT | ||
| *) | ||
| */ |
+37
-636
@@ -1,570 +0,1 @@ | ||
| var __create = Object.create; | ||
| var __defProp = Object.defineProperty; | ||
| var __defProps = Object.defineProperties; | ||
| var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
| var __getOwnPropDescs = Object.getOwnPropertyDescriptors; | ||
| var __getOwnPropNames = Object.getOwnPropertyNames; | ||
| var __getOwnPropSymbols = Object.getOwnPropertySymbols; | ||
| var __getProtoOf = Object.getPrototypeOf; | ||
| var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
| var __propIsEnum = Object.prototype.propertyIsEnumerable; | ||
| var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; | ||
| var __spreadValues = (a, b) => { | ||
| for (var prop in b || (b = {})) | ||
| if (__hasOwnProp.call(b, prop)) | ||
| __defNormalProp(a, prop, b[prop]); | ||
| if (__getOwnPropSymbols) | ||
| for (var prop of __getOwnPropSymbols(b)) { | ||
| if (__propIsEnum.call(b, prop)) | ||
| __defNormalProp(a, prop, b[prop]); | ||
| } | ||
| return a; | ||
| }; | ||
| var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b)); | ||
| var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, { | ||
| get: (a, b) => (typeof require !== "undefined" ? require : a)[b] | ||
| }) : x)(function(x) { | ||
| if (typeof require !== "undefined") | ||
| return require.apply(this, arguments); | ||
| throw Error('Dynamic require of "' + x + '" is not supported'); | ||
| }); | ||
| var __commonJS = (cb, mod) => function __require2() { | ||
| return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports; | ||
| }; | ||
| var __copyProps = (to, from, except, desc) => { | ||
| if (from && typeof from === "object" || typeof from === "function") { | ||
| for (let key of __getOwnPropNames(from)) | ||
| if (!__hasOwnProp.call(to, key) && key !== except) | ||
| __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); | ||
| } | ||
| return to; | ||
| }; | ||
| var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( | ||
| // If the importer is in node compatibility mode or this is not an ESM | ||
| // file that has been converted to a CommonJS file using a Babel- | ||
| // compatible transform (i.e. "__esModule" has not been set), then set | ||
| // "default" to the CommonJS "module.exports" for node compatibility. | ||
| isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, | ||
| mod | ||
| )); | ||
| // ../../node_modules/.pnpm/js-sha256@0.11.0/node_modules/js-sha256/src/sha256.js | ||
| var require_sha256 = __commonJS({ | ||
| "../../node_modules/.pnpm/js-sha256@0.11.0/node_modules/js-sha256/src/sha256.js"(exports, module) { | ||
| "use strict"; | ||
| (function() { | ||
| "use strict"; | ||
| var ERROR = "input is invalid type"; | ||
| var WINDOW = typeof window === "object"; | ||
| var root = WINDOW ? window : {}; | ||
| if (root.JS_SHA256_NO_WINDOW) { | ||
| WINDOW = false; | ||
| } | ||
| var WEB_WORKER = !WINDOW && typeof self === "object"; | ||
| var NODE_JS = !root.JS_SHA256_NO_NODE_JS && typeof process === "object" && process.versions && process.versions.node; | ||
| if (NODE_JS) { | ||
| root = global; | ||
| } else if (WEB_WORKER) { | ||
| root = self; | ||
| } | ||
| var COMMON_JS = !root.JS_SHA256_NO_COMMON_JS && typeof module === "object" && module.exports; | ||
| var AMD = typeof define === "function" && define.amd; | ||
| var ARRAY_BUFFER = !root.JS_SHA256_NO_ARRAY_BUFFER && typeof ArrayBuffer !== "undefined"; | ||
| var HEX_CHARS = "0123456789abcdef".split(""); | ||
| var EXTRA = [-2147483648, 8388608, 32768, 128]; | ||
| var SHIFT = [24, 16, 8, 0]; | ||
| var K = [ | ||
| 1116352408, | ||
| 1899447441, | ||
| 3049323471, | ||
| 3921009573, | ||
| 961987163, | ||
| 1508970993, | ||
| 2453635748, | ||
| 2870763221, | ||
| 3624381080, | ||
| 310598401, | ||
| 607225278, | ||
| 1426881987, | ||
| 1925078388, | ||
| 2162078206, | ||
| 2614888103, | ||
| 3248222580, | ||
| 3835390401, | ||
| 4022224774, | ||
| 264347078, | ||
| 604807628, | ||
| 770255983, | ||
| 1249150122, | ||
| 1555081692, | ||
| 1996064986, | ||
| 2554220882, | ||
| 2821834349, | ||
| 2952996808, | ||
| 3210313671, | ||
| 3336571891, | ||
| 3584528711, | ||
| 113926993, | ||
| 338241895, | ||
| 666307205, | ||
| 773529912, | ||
| 1294757372, | ||
| 1396182291, | ||
| 1695183700, | ||
| 1986661051, | ||
| 2177026350, | ||
| 2456956037, | ||
| 2730485921, | ||
| 2820302411, | ||
| 3259730800, | ||
| 3345764771, | ||
| 3516065817, | ||
| 3600352804, | ||
| 4094571909, | ||
| 275423344, | ||
| 430227734, | ||
| 506948616, | ||
| 659060556, | ||
| 883997877, | ||
| 958139571, | ||
| 1322822218, | ||
| 1537002063, | ||
| 1747873779, | ||
| 1955562222, | ||
| 2024104815, | ||
| 2227730452, | ||
| 2361852424, | ||
| 2428436474, | ||
| 2756734187, | ||
| 3204031479, | ||
| 3329325298 | ||
| ]; | ||
| var OUTPUT_TYPES = ["hex", "array", "digest", "arrayBuffer"]; | ||
| var blocks = []; | ||
| if (root.JS_SHA256_NO_NODE_JS || !Array.isArray) { | ||
| Array.isArray = function(obj) { | ||
| return Object.prototype.toString.call(obj) === "[object Array]"; | ||
| }; | ||
| } | ||
| if (ARRAY_BUFFER && (root.JS_SHA256_NO_ARRAY_BUFFER_IS_VIEW || !ArrayBuffer.isView)) { | ||
| ArrayBuffer.isView = function(obj) { | ||
| return typeof obj === "object" && obj.buffer && obj.buffer.constructor === ArrayBuffer; | ||
| }; | ||
| } | ||
| var createOutputMethod = function(outputType, is224) { | ||
| return function(message) { | ||
| return new Sha256(is224, true).update(message)[outputType](); | ||
| }; | ||
| }; | ||
| var createMethod = function(is224) { | ||
| var method = createOutputMethod("hex", is224); | ||
| if (NODE_JS) { | ||
| method = nodeWrap(method, is224); | ||
| } | ||
| method.create = function() { | ||
| return new Sha256(is224); | ||
| }; | ||
| method.update = function(message) { | ||
| return method.create().update(message); | ||
| }; | ||
| for (var i = 0; i < OUTPUT_TYPES.length; ++i) { | ||
| var type = OUTPUT_TYPES[i]; | ||
| method[type] = createOutputMethod(type, is224); | ||
| } | ||
| return method; | ||
| }; | ||
| var nodeWrap = function(method, is224) { | ||
| var crypto = __require("crypto"); | ||
| var Buffer2 = __require("buffer").Buffer; | ||
| var algorithm = is224 ? "sha224" : "sha256"; | ||
| var bufferFrom; | ||
| if (Buffer2.from && !root.JS_SHA256_NO_BUFFER_FROM) { | ||
| bufferFrom = Buffer2.from; | ||
| } else { | ||
| bufferFrom = function(message) { | ||
| return new Buffer2(message); | ||
| }; | ||
| } | ||
| var nodeMethod = function(message) { | ||
| if (typeof message === "string") { | ||
| return crypto.createHash(algorithm).update(message, "utf8").digest("hex"); | ||
| } else { | ||
| if (message === null || message === void 0) { | ||
| throw new Error(ERROR); | ||
| } else if (message.constructor === ArrayBuffer) { | ||
| message = new Uint8Array(message); | ||
| } | ||
| } | ||
| if (Array.isArray(message) || ArrayBuffer.isView(message) || message.constructor === Buffer2) { | ||
| return crypto.createHash(algorithm).update(bufferFrom(message)).digest("hex"); | ||
| } else { | ||
| return method(message); | ||
| } | ||
| }; | ||
| return nodeMethod; | ||
| }; | ||
| var createHmacOutputMethod = function(outputType, is224) { | ||
| return function(key, message) { | ||
| return new HmacSha256(key, is224, true).update(message)[outputType](); | ||
| }; | ||
| }; | ||
| var createHmacMethod = function(is224) { | ||
| var method = createHmacOutputMethod("hex", is224); | ||
| method.create = function(key) { | ||
| return new HmacSha256(key, is224); | ||
| }; | ||
| method.update = function(key, message) { | ||
| return method.create(key).update(message); | ||
| }; | ||
| for (var i = 0; i < OUTPUT_TYPES.length; ++i) { | ||
| var type = OUTPUT_TYPES[i]; | ||
| method[type] = createHmacOutputMethod(type, is224); | ||
| } | ||
| return method; | ||
| }; | ||
| function Sha256(is224, sharedMemory) { | ||
| if (sharedMemory) { | ||
| blocks[0] = blocks[16] = blocks[1] = blocks[2] = blocks[3] = blocks[4] = blocks[5] = blocks[6] = blocks[7] = blocks[8] = blocks[9] = blocks[10] = blocks[11] = blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0; | ||
| this.blocks = blocks; | ||
| } else { | ||
| this.blocks = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; | ||
| } | ||
| if (is224) { | ||
| this.h0 = 3238371032; | ||
| this.h1 = 914150663; | ||
| this.h2 = 812702999; | ||
| this.h3 = 4144912697; | ||
| this.h4 = 4290775857; | ||
| this.h5 = 1750603025; | ||
| this.h6 = 1694076839; | ||
| this.h7 = 3204075428; | ||
| } else { | ||
| this.h0 = 1779033703; | ||
| this.h1 = 3144134277; | ||
| this.h2 = 1013904242; | ||
| this.h3 = 2773480762; | ||
| this.h4 = 1359893119; | ||
| this.h5 = 2600822924; | ||
| this.h6 = 528734635; | ||
| this.h7 = 1541459225; | ||
| } | ||
| this.block = this.start = this.bytes = this.hBytes = 0; | ||
| this.finalized = this.hashed = false; | ||
| this.first = true; | ||
| this.is224 = is224; | ||
| } | ||
| Sha256.prototype.update = function(message) { | ||
| if (this.finalized) { | ||
| return; | ||
| } | ||
| var notString, type = typeof message; | ||
| if (type !== "string") { | ||
| if (type === "object") { | ||
| if (message === null) { | ||
| throw new Error(ERROR); | ||
| } else if (ARRAY_BUFFER && message.constructor === ArrayBuffer) { | ||
| message = new Uint8Array(message); | ||
| } else if (!Array.isArray(message)) { | ||
| if (!ARRAY_BUFFER || !ArrayBuffer.isView(message)) { | ||
| throw new Error(ERROR); | ||
| } | ||
| } | ||
| } else { | ||
| throw new Error(ERROR); | ||
| } | ||
| notString = true; | ||
| } | ||
| var code, index = 0, i, length = message.length, blocks2 = this.blocks; | ||
| while (index < length) { | ||
| if (this.hashed) { | ||
| this.hashed = false; | ||
| blocks2[0] = this.block; | ||
| this.block = blocks2[16] = blocks2[1] = blocks2[2] = blocks2[3] = blocks2[4] = blocks2[5] = blocks2[6] = blocks2[7] = blocks2[8] = blocks2[9] = blocks2[10] = blocks2[11] = blocks2[12] = blocks2[13] = blocks2[14] = blocks2[15] = 0; | ||
| } | ||
| if (notString) { | ||
| for (i = this.start; index < length && i < 64; ++index) { | ||
| blocks2[i >>> 2] |= message[index] << SHIFT[i++ & 3]; | ||
| } | ||
| } else { | ||
| for (i = this.start; index < length && i < 64; ++index) { | ||
| code = message.charCodeAt(index); | ||
| if (code < 128) { | ||
| blocks2[i >>> 2] |= code << SHIFT[i++ & 3]; | ||
| } else if (code < 2048) { | ||
| blocks2[i >>> 2] |= (192 | code >>> 6) << SHIFT[i++ & 3]; | ||
| blocks2[i >>> 2] |= (128 | code & 63) << SHIFT[i++ & 3]; | ||
| } else if (code < 55296 || code >= 57344) { | ||
| blocks2[i >>> 2] |= (224 | code >>> 12) << SHIFT[i++ & 3]; | ||
| blocks2[i >>> 2] |= (128 | code >>> 6 & 63) << SHIFT[i++ & 3]; | ||
| blocks2[i >>> 2] |= (128 | code & 63) << SHIFT[i++ & 3]; | ||
| } else { | ||
| code = 65536 + ((code & 1023) << 10 | message.charCodeAt(++index) & 1023); | ||
| blocks2[i >>> 2] |= (240 | code >>> 18) << SHIFT[i++ & 3]; | ||
| blocks2[i >>> 2] |= (128 | code >>> 12 & 63) << SHIFT[i++ & 3]; | ||
| blocks2[i >>> 2] |= (128 | code >>> 6 & 63) << SHIFT[i++ & 3]; | ||
| blocks2[i >>> 2] |= (128 | code & 63) << SHIFT[i++ & 3]; | ||
| } | ||
| } | ||
| } | ||
| this.lastByteIndex = i; | ||
| this.bytes += i - this.start; | ||
| if (i >= 64) { | ||
| this.block = blocks2[16]; | ||
| this.start = i - 64; | ||
| this.hash(); | ||
| this.hashed = true; | ||
| } else { | ||
| this.start = i; | ||
| } | ||
| } | ||
| if (this.bytes > 4294967295) { | ||
| this.hBytes += this.bytes / 4294967296 << 0; | ||
| this.bytes = this.bytes % 4294967296; | ||
| } | ||
| return this; | ||
| }; | ||
| Sha256.prototype.finalize = function() { | ||
| if (this.finalized) { | ||
| return; | ||
| } | ||
| this.finalized = true; | ||
| var blocks2 = this.blocks, i = this.lastByteIndex; | ||
| blocks2[16] = this.block; | ||
| blocks2[i >>> 2] |= EXTRA[i & 3]; | ||
| this.block = blocks2[16]; | ||
| if (i >= 56) { | ||
| if (!this.hashed) { | ||
| this.hash(); | ||
| } | ||
| blocks2[0] = this.block; | ||
| blocks2[16] = blocks2[1] = blocks2[2] = blocks2[3] = blocks2[4] = blocks2[5] = blocks2[6] = blocks2[7] = blocks2[8] = blocks2[9] = blocks2[10] = blocks2[11] = blocks2[12] = blocks2[13] = blocks2[14] = blocks2[15] = 0; | ||
| } | ||
| blocks2[14] = this.hBytes << 3 | this.bytes >>> 29; | ||
| blocks2[15] = this.bytes << 3; | ||
| this.hash(); | ||
| }; | ||
| Sha256.prototype.hash = function() { | ||
| var a = this.h0, b = this.h1, c = this.h2, d = this.h3, e = this.h4, f = this.h5, g = this.h6, h = this.h7, blocks2 = this.blocks, j, s0, s1, maj, t1, t2, ch, ab, da, cd, bc; | ||
| for (j = 16; j < 64; ++j) { | ||
| t1 = blocks2[j - 15]; | ||
| s0 = (t1 >>> 7 | t1 << 25) ^ (t1 >>> 18 | t1 << 14) ^ t1 >>> 3; | ||
| t1 = blocks2[j - 2]; | ||
| s1 = (t1 >>> 17 | t1 << 15) ^ (t1 >>> 19 | t1 << 13) ^ t1 >>> 10; | ||
| blocks2[j] = blocks2[j - 16] + s0 + blocks2[j - 7] + s1 << 0; | ||
| } | ||
| bc = b & c; | ||
| for (j = 0; j < 64; j += 4) { | ||
| if (this.first) { | ||
| if (this.is224) { | ||
| ab = 300032; | ||
| t1 = blocks2[0] - 1413257819; | ||
| h = t1 - 150054599 << 0; | ||
| d = t1 + 24177077 << 0; | ||
| } else { | ||
| ab = 704751109; | ||
| t1 = blocks2[0] - 210244248; | ||
| h = t1 - 1521486534 << 0; | ||
| d = t1 + 143694565 << 0; | ||
| } | ||
| this.first = false; | ||
| } else { | ||
| s0 = (a >>> 2 | a << 30) ^ (a >>> 13 | a << 19) ^ (a >>> 22 | a << 10); | ||
| s1 = (e >>> 6 | e << 26) ^ (e >>> 11 | e << 21) ^ (e >>> 25 | e << 7); | ||
| ab = a & b; | ||
| maj = ab ^ a & c ^ bc; | ||
| ch = e & f ^ ~e & g; | ||
| t1 = h + s1 + ch + K[j] + blocks2[j]; | ||
| t2 = s0 + maj; | ||
| h = d + t1 << 0; | ||
| d = t1 + t2 << 0; | ||
| } | ||
| s0 = (d >>> 2 | d << 30) ^ (d >>> 13 | d << 19) ^ (d >>> 22 | d << 10); | ||
| s1 = (h >>> 6 | h << 26) ^ (h >>> 11 | h << 21) ^ (h >>> 25 | h << 7); | ||
| da = d & a; | ||
| maj = da ^ d & b ^ ab; | ||
| ch = h & e ^ ~h & f; | ||
| t1 = g + s1 + ch + K[j + 1] + blocks2[j + 1]; | ||
| t2 = s0 + maj; | ||
| g = c + t1 << 0; | ||
| c = t1 + t2 << 0; | ||
| s0 = (c >>> 2 | c << 30) ^ (c >>> 13 | c << 19) ^ (c >>> 22 | c << 10); | ||
| s1 = (g >>> 6 | g << 26) ^ (g >>> 11 | g << 21) ^ (g >>> 25 | g << 7); | ||
| cd = c & d; | ||
| maj = cd ^ c & a ^ da; | ||
| ch = g & h ^ ~g & e; | ||
| t1 = f + s1 + ch + K[j + 2] + blocks2[j + 2]; | ||
| t2 = s0 + maj; | ||
| f = b + t1 << 0; | ||
| b = t1 + t2 << 0; | ||
| s0 = (b >>> 2 | b << 30) ^ (b >>> 13 | b << 19) ^ (b >>> 22 | b << 10); | ||
| s1 = (f >>> 6 | f << 26) ^ (f >>> 11 | f << 21) ^ (f >>> 25 | f << 7); | ||
| bc = b & c; | ||
| maj = bc ^ b & d ^ cd; | ||
| ch = f & g ^ ~f & h; | ||
| t1 = e + s1 + ch + K[j + 3] + blocks2[j + 3]; | ||
| t2 = s0 + maj; | ||
| e = a + t1 << 0; | ||
| a = t1 + t2 << 0; | ||
| this.chromeBugWorkAround = true; | ||
| } | ||
| this.h0 = this.h0 + a << 0; | ||
| this.h1 = this.h1 + b << 0; | ||
| this.h2 = this.h2 + c << 0; | ||
| this.h3 = this.h3 + d << 0; | ||
| this.h4 = this.h4 + e << 0; | ||
| this.h5 = this.h5 + f << 0; | ||
| this.h6 = this.h6 + g << 0; | ||
| this.h7 = this.h7 + h << 0; | ||
| }; | ||
| Sha256.prototype.hex = function() { | ||
| this.finalize(); | ||
| var h0 = this.h0, h1 = this.h1, h2 = this.h2, h3 = this.h3, h4 = this.h4, h5 = this.h5, h6 = this.h6, h7 = this.h7; | ||
| var hex = HEX_CHARS[h0 >>> 28 & 15] + HEX_CHARS[h0 >>> 24 & 15] + HEX_CHARS[h0 >>> 20 & 15] + HEX_CHARS[h0 >>> 16 & 15] + HEX_CHARS[h0 >>> 12 & 15] + HEX_CHARS[h0 >>> 8 & 15] + HEX_CHARS[h0 >>> 4 & 15] + HEX_CHARS[h0 & 15] + HEX_CHARS[h1 >>> 28 & 15] + HEX_CHARS[h1 >>> 24 & 15] + HEX_CHARS[h1 >>> 20 & 15] + HEX_CHARS[h1 >>> 16 & 15] + HEX_CHARS[h1 >>> 12 & 15] + HEX_CHARS[h1 >>> 8 & 15] + HEX_CHARS[h1 >>> 4 & 15] + HEX_CHARS[h1 & 15] + HEX_CHARS[h2 >>> 28 & 15] + HEX_CHARS[h2 >>> 24 & 15] + HEX_CHARS[h2 >>> 20 & 15] + HEX_CHARS[h2 >>> 16 & 15] + HEX_CHARS[h2 >>> 12 & 15] + HEX_CHARS[h2 >>> 8 & 15] + HEX_CHARS[h2 >>> 4 & 15] + HEX_CHARS[h2 & 15] + HEX_CHARS[h3 >>> 28 & 15] + HEX_CHARS[h3 >>> 24 & 15] + HEX_CHARS[h3 >>> 20 & 15] + HEX_CHARS[h3 >>> 16 & 15] + HEX_CHARS[h3 >>> 12 & 15] + HEX_CHARS[h3 >>> 8 & 15] + HEX_CHARS[h3 >>> 4 & 15] + HEX_CHARS[h3 & 15] + HEX_CHARS[h4 >>> 28 & 15] + HEX_CHARS[h4 >>> 24 & 15] + HEX_CHARS[h4 >>> 20 & 15] + HEX_CHARS[h4 >>> 16 & 15] + HEX_CHARS[h4 >>> 12 & 15] + HEX_CHARS[h4 >>> 8 & 15] + HEX_CHARS[h4 >>> 4 & 15] + HEX_CHARS[h4 & 15] + HEX_CHARS[h5 >>> 28 & 15] + HEX_CHARS[h5 >>> 24 & 15] + HEX_CHARS[h5 >>> 20 & 15] + HEX_CHARS[h5 >>> 16 & 15] + HEX_CHARS[h5 >>> 12 & 15] + HEX_CHARS[h5 >>> 8 & 15] + HEX_CHARS[h5 >>> 4 & 15] + HEX_CHARS[h5 & 15] + HEX_CHARS[h6 >>> 28 & 15] + HEX_CHARS[h6 >>> 24 & 15] + HEX_CHARS[h6 >>> 20 & 15] + HEX_CHARS[h6 >>> 16 & 15] + HEX_CHARS[h6 >>> 12 & 15] + HEX_CHARS[h6 >>> 8 & 15] + HEX_CHARS[h6 >>> 4 & 15] + HEX_CHARS[h6 & 15]; | ||
| if (!this.is224) { | ||
| hex += HEX_CHARS[h7 >>> 28 & 15] + HEX_CHARS[h7 >>> 24 & 15] + HEX_CHARS[h7 >>> 20 & 15] + HEX_CHARS[h7 >>> 16 & 15] + HEX_CHARS[h7 >>> 12 & 15] + HEX_CHARS[h7 >>> 8 & 15] + HEX_CHARS[h7 >>> 4 & 15] + HEX_CHARS[h7 & 15]; | ||
| } | ||
| return hex; | ||
| }; | ||
| Sha256.prototype.toString = Sha256.prototype.hex; | ||
| Sha256.prototype.digest = function() { | ||
| this.finalize(); | ||
| var h0 = this.h0, h1 = this.h1, h2 = this.h2, h3 = this.h3, h4 = this.h4, h5 = this.h5, h6 = this.h6, h7 = this.h7; | ||
| var arr = [ | ||
| h0 >>> 24 & 255, | ||
| h0 >>> 16 & 255, | ||
| h0 >>> 8 & 255, | ||
| h0 & 255, | ||
| h1 >>> 24 & 255, | ||
| h1 >>> 16 & 255, | ||
| h1 >>> 8 & 255, | ||
| h1 & 255, | ||
| h2 >>> 24 & 255, | ||
| h2 >>> 16 & 255, | ||
| h2 >>> 8 & 255, | ||
| h2 & 255, | ||
| h3 >>> 24 & 255, | ||
| h3 >>> 16 & 255, | ||
| h3 >>> 8 & 255, | ||
| h3 & 255, | ||
| h4 >>> 24 & 255, | ||
| h4 >>> 16 & 255, | ||
| h4 >>> 8 & 255, | ||
| h4 & 255, | ||
| h5 >>> 24 & 255, | ||
| h5 >>> 16 & 255, | ||
| h5 >>> 8 & 255, | ||
| h5 & 255, | ||
| h6 >>> 24 & 255, | ||
| h6 >>> 16 & 255, | ||
| h6 >>> 8 & 255, | ||
| h6 & 255 | ||
| ]; | ||
| if (!this.is224) { | ||
| arr.push(h7 >>> 24 & 255, h7 >>> 16 & 255, h7 >>> 8 & 255, h7 & 255); | ||
| } | ||
| return arr; | ||
| }; | ||
| Sha256.prototype.array = Sha256.prototype.digest; | ||
| Sha256.prototype.arrayBuffer = function() { | ||
| this.finalize(); | ||
| var buffer = new ArrayBuffer(this.is224 ? 28 : 32); | ||
| var dataView = new DataView(buffer); | ||
| dataView.setUint32(0, this.h0); | ||
| dataView.setUint32(4, this.h1); | ||
| dataView.setUint32(8, this.h2); | ||
| dataView.setUint32(12, this.h3); | ||
| dataView.setUint32(16, this.h4); | ||
| dataView.setUint32(20, this.h5); | ||
| dataView.setUint32(24, this.h6); | ||
| if (!this.is224) { | ||
| dataView.setUint32(28, this.h7); | ||
| } | ||
| return buffer; | ||
| }; | ||
| function HmacSha256(key, is224, sharedMemory) { | ||
| var i, type = typeof key; | ||
| if (type === "string") { | ||
| var bytes = [], length = key.length, index = 0, code; | ||
| for (i = 0; i < length; ++i) { | ||
| code = key.charCodeAt(i); | ||
| if (code < 128) { | ||
| bytes[index++] = code; | ||
| } else if (code < 2048) { | ||
| bytes[index++] = 192 | code >>> 6; | ||
| bytes[index++] = 128 | code & 63; | ||
| } else if (code < 55296 || code >= 57344) { | ||
| bytes[index++] = 224 | code >>> 12; | ||
| bytes[index++] = 128 | code >>> 6 & 63; | ||
| bytes[index++] = 128 | code & 63; | ||
| } else { | ||
| code = 65536 + ((code & 1023) << 10 | key.charCodeAt(++i) & 1023); | ||
| bytes[index++] = 240 | code >>> 18; | ||
| bytes[index++] = 128 | code >>> 12 & 63; | ||
| bytes[index++] = 128 | code >>> 6 & 63; | ||
| bytes[index++] = 128 | code & 63; | ||
| } | ||
| } | ||
| key = bytes; | ||
| } else { | ||
| if (type === "object") { | ||
| if (key === null) { | ||
| throw new Error(ERROR); | ||
| } else if (ARRAY_BUFFER && key.constructor === ArrayBuffer) { | ||
| key = new Uint8Array(key); | ||
| } else if (!Array.isArray(key)) { | ||
| if (!ARRAY_BUFFER || !ArrayBuffer.isView(key)) { | ||
| throw new Error(ERROR); | ||
| } | ||
| } | ||
| } else { | ||
| throw new Error(ERROR); | ||
| } | ||
| } | ||
| if (key.length > 64) { | ||
| key = new Sha256(is224, true).update(key).array(); | ||
| } | ||
| var oKeyPad = [], iKeyPad = []; | ||
| for (i = 0; i < 64; ++i) { | ||
| var b = key[i] || 0; | ||
| oKeyPad[i] = 92 ^ b; | ||
| iKeyPad[i] = 54 ^ b; | ||
| } | ||
| Sha256.call(this, is224, sharedMemory); | ||
| this.update(iKeyPad); | ||
| this.oKeyPad = oKeyPad; | ||
| this.inner = true; | ||
| this.sharedMemory = sharedMemory; | ||
| } | ||
| HmacSha256.prototype = new Sha256(); | ||
| HmacSha256.prototype.finalize = function() { | ||
| Sha256.prototype.finalize.call(this); | ||
| if (this.inner) { | ||
| this.inner = false; | ||
| var innerHash = this.array(); | ||
| Sha256.call(this, this.is224, this.sharedMemory); | ||
| this.update(this.oKeyPad); | ||
| this.update(innerHash); | ||
| Sha256.prototype.finalize.call(this); | ||
| } | ||
| }; | ||
| var exports2 = createMethod(); | ||
| exports2.sha256 = exports2; | ||
| exports2.sha224 = createMethod(true); | ||
| exports2.sha256.hmac = createHmacMethod(); | ||
| exports2.sha224.hmac = createHmacMethod(true); | ||
| if (COMMON_JS) { | ||
| module.exports = exports2; | ||
| } else { | ||
| root.sha256 = exports2.sha256; | ||
| root.sha224 = exports2.sha224; | ||
| if (AMD) { | ||
| define(function() { | ||
| return exports2; | ||
| }); | ||
| } | ||
| } | ||
| })(); | ||
| } | ||
| }); | ||
| // src/extractor/tree.ts | ||
@@ -611,3 +42,2 @@ function truncateText(text, maxLength = 150) { | ||
| function buildContentTree(node, indent = 0) { | ||
| var _a; | ||
| let before = ""; | ||
@@ -629,3 +59,3 @@ let contentWithIndent = ""; | ||
| let nodeTypeString; | ||
| if ((_a = node.node.attributes) == null ? void 0 : _a.htmlTagName) { | ||
| if (node.node.attributes?.htmlTagName) { | ||
| nodeTypeString = node.node.attributes.htmlTagName.replace(/[<>]/g, ""); | ||
@@ -767,3 +197,4 @@ } else { | ||
| // src/utils.ts | ||
| var import_js_sha256 = __toESM(require_sha256()); | ||
| import { sha256 } from "js-sha256"; | ||
| import debug from "debug"; | ||
| var hashMap = {}; | ||
@@ -777,3 +208,3 @@ function generateHashId(rect, content = "") { | ||
| let slicedHash = ""; | ||
| const hashHex = import_js_sha256.sha256.create().update(combined).hex(); | ||
| const hashHex = sha256.create().update(combined).hex(); | ||
| const toLetters = (hex) => { | ||
@@ -927,6 +358,6 @@ return hex.split("").map((char) => { | ||
| } | ||
| if (el == null ? void 0 : el.contains(topElement)) { | ||
| if (el?.contains(topElement)) { | ||
| return false; | ||
| } | ||
| if (topElement == null ? void 0 : topElement.contains(el)) { | ||
| if (topElement?.contains(el)) { | ||
| return false; | ||
@@ -993,3 +424,3 @@ } | ||
| const parentUntilNonStatic = (currentNode) => { | ||
| let parent2 = currentNode == null ? void 0 : currentNode.parentElement; | ||
| let parent2 = currentNode?.parentElement; | ||
| while (parent2) { | ||
@@ -1060,24 +491,4 @@ const style = currentWindow.getComputedStyle(parent2); | ||
| } | ||
| var nodeHashCacheList = []; | ||
| if (typeof window !== "undefined") { | ||
| window.midsceneNodeHashCacheList = window.midsceneNodeHashCacheList || []; | ||
| nodeHashCacheList = window.midsceneNodeHashCacheList; | ||
| } | ||
| function resetNodeHashCacheList() { | ||
| if (typeof window !== "undefined") { | ||
| nodeHashCacheList = window.midsceneNodeHashCacheList || []; | ||
| window.midsceneNodeHashCacheList = []; | ||
| } else { | ||
| nodeHashCacheList = []; | ||
| } | ||
| } | ||
| function midsceneGenerateHash(node, content, rect) { | ||
| var _a; | ||
| if (node && nodeHashCacheList.find((item) => item.node === node)) { | ||
| return ((_a = nodeHashCacheList.find((item) => item.node === node)) == null ? void 0 : _a.id) || ""; | ||
| } | ||
| const slicedHash = generateHashId(rect, content); | ||
| if (node && typeof window !== "undefined") { | ||
| window.midsceneNodeHashCacheList.push({ node, id: slicedHash }); | ||
| } | ||
| return slicedHash; | ||
@@ -1104,3 +515,2 @@ } | ||
| function collectElementInfo(node, currentWindow, currentDocument, baseZoom = 1, basePoint = { left: 0, top: 0 }) { | ||
| var _a; | ||
| const rect = visibleRect(node, currentWindow, currentDocument, baseZoom); | ||
@@ -1136,6 +546,7 @@ if (!rect || rect.width < CONTAINER_MINI_WIDTH || rect.height < CONTAINER_MINI_HEIGHT) { | ||
| indexId: indexId++, | ||
| attributes: __spreadProps(__spreadValues({}, attributes), { | ||
| attributes: { | ||
| ...attributes, | ||
| htmlTagName: `<${tagName}>`, | ||
| nodeType: "FORM_ITEM Node" /* FORM_ITEM */ | ||
| }), | ||
| }, | ||
| content: valueContent.trim(), | ||
@@ -1165,6 +576,7 @@ rect, | ||
| locator: selector, | ||
| attributes: __spreadProps(__spreadValues({}, attributes), { | ||
| attributes: { | ||
| ...attributes, | ||
| htmlTagName: tagNameOfNode(node), | ||
| nodeType: "BUTTON Node" /* BUTTON */ | ||
| }), | ||
| }, | ||
| content, | ||
@@ -1191,8 +603,10 @@ rect, | ||
| locator: selector, | ||
| attributes: __spreadProps(__spreadValues(__spreadValues({}, attributes), node.nodeName.toLowerCase() === "svg" ? { | ||
| svgContent: "true" | ||
| } : {}), { | ||
| attributes: { | ||
| ...attributes, | ||
| ...node.nodeName.toLowerCase() === "svg" ? { | ||
| svgContent: "true" | ||
| } : {}, | ||
| nodeType: "IMG Node" /* IMG */, | ||
| htmlTagName: tagNameOfNode(node) | ||
| }), | ||
| }, | ||
| nodeType: "IMG Node" /* IMG */, | ||
@@ -1212,3 +626,3 @@ content: "", | ||
| if (isTextElement(node)) { | ||
| const text = (_a = node.textContent) == null ? void 0 : _a.trim().replace(/\n+/g, " "); | ||
| const text = node.textContent?.trim().replace(/\n+/g, " "); | ||
| if (!text) { | ||
@@ -1230,6 +644,7 @@ return null; | ||
| locator: selector, | ||
| attributes: __spreadProps(__spreadValues({}, attributes), { | ||
| attributes: { | ||
| ...attributes, | ||
| nodeType: "TEXT Node" /* TEXT */, | ||
| htmlTagName: tagNameOfNode(node) | ||
| }), | ||
| }, | ||
| center: [ | ||
@@ -1258,6 +673,7 @@ Math.round(rect.left + rect.width / 2), | ||
| locator: selector, | ||
| attributes: __spreadProps(__spreadValues({}, attributes), { | ||
| attributes: { | ||
| ...attributes, | ||
| nodeType: "CONTAINER Node" /* CONTAINER */, | ||
| htmlTagName: tagNameOfNode(node) | ||
| }), | ||
| }, | ||
| content: "", | ||
@@ -1297,3 +713,2 @@ rect, | ||
| setDebugMode(debugMode2); | ||
| resetNodeHashCacheList(); | ||
| indexId = 0; | ||
@@ -1326,3 +741,3 @@ const topDocument = getTopDocument(); | ||
| }; | ||
| if ((elementInfo == null ? void 0 : elementInfo.nodeType) === "BUTTON Node" /* BUTTON */ || (elementInfo == null ? void 0 : elementInfo.nodeType) === "IMG Node" /* IMG */ || (elementInfo == null ? void 0 : elementInfo.nodeType) === "TEXT Node" /* TEXT */ || (elementInfo == null ? void 0 : elementInfo.nodeType) === "FORM_ITEM Node" /* FORM_ITEM */ || (elementInfo == null ? void 0 : elementInfo.nodeType) === "CONTAINER Node" /* CONTAINER */) { | ||
| if (elementInfo?.nodeType === "BUTTON Node" /* BUTTON */ || elementInfo?.nodeType === "IMG Node" /* IMG */ || elementInfo?.nodeType === "TEXT Node" /* TEXT */ || elementInfo?.nodeType === "FORM_ITEM Node" /* FORM_ITEM */ || elementInfo?.nodeType === "CONTAINER Node" /* CONTAINER */) { | ||
| return nodeInfo; | ||
@@ -1385,3 +800,2 @@ } | ||
| function getNodeAttributes2(node) { | ||
| var _a; | ||
| const attrs = {}; | ||
@@ -1392,3 +806,3 @@ if (node && node.nodeType === 1) { | ||
| const attr = element.attributes[i]; | ||
| attrs[attr.nodeName] = (_a = attr.nodeValue) != null ? _a : ""; | ||
| attrs[attr.nodeName] = attr.nodeValue ?? ""; | ||
| } | ||
@@ -1399,7 +813,6 @@ } | ||
| function getRect2(attributes) { | ||
| var _a, _b, _c, _d; | ||
| const x = Math.round(Number.parseFloat((_a = attributes.x) != null ? _a : "0")); | ||
| const y = Math.round(Number.parseFloat((_b = attributes.y) != null ? _b : "0")); | ||
| const width = Math.round(Number.parseFloat((_c = attributes.width) != null ? _c : "0")); | ||
| const height = Math.round(Number.parseFloat((_d = attributes.height) != null ? _d : "0")); | ||
| const x = Math.round(Number.parseFloat(attributes.x ?? "0")); | ||
| const y = Math.round(Number.parseFloat(attributes.y ?? "0")); | ||
| const width = Math.round(Number.parseFloat(attributes.width ?? "0")); | ||
| const height = Math.round(Number.parseFloat(attributes.height ?? "0")); | ||
| return { | ||
@@ -1413,5 +826,4 @@ left: Math.max(0, Math.floor(x)), | ||
| function validTextNodeContent(node) { | ||
| var _a; | ||
| if (node.nodeType === 3) { | ||
| return ((_a = node.nodeValue) == null ? void 0 : _a.trim()) || ""; | ||
| return node.nodeValue?.trim() || ""; | ||
| } | ||
@@ -1526,5 +938,6 @@ return ""; | ||
| locator: xpath, | ||
| attributes: __spreadValues({ | ||
| nodeType | ||
| }, attributes), | ||
| attributes: { | ||
| nodeType, | ||
| ...attributes | ||
| }, | ||
| content: text, | ||
@@ -1556,13 +969,1 @@ rect, | ||
| }; | ||
| /*! Bundled license information: | ||
| js-sha256/src/sha256.js: | ||
| (** | ||
| * [js-sha256]{@link https://github.com/emn178/js-sha256} | ||
| * | ||
| * @version 0.11.0 | ||
| * @author Chen, Yi-Cyuan [emn178@gmail.com] | ||
| * @copyright Chen, Yi-Cyuan 2014-2024 | ||
| * @license MIT | ||
| *) | ||
| */ |
+2
-1
@@ -13,3 +13,4 @@ interface PkgInfo { | ||
| declare function findNearestPackageJson(dir: string): string | null; | ||
| declare function getExtraReturnLogic(tree?: boolean): Promise<string | null>; | ||
| export { findNearestPackageJson, getRunningPkgInfo }; | ||
| export { findNearestPackageJson, getExtraReturnLogic, getRunningPkgInfo }; |
+29
-2
@@ -1,6 +0,18 @@ | ||
| // src/fs/index.ts | ||
| // src/node/fs.ts | ||
| import { existsSync, readFileSync } from "fs"; | ||
| import { dirname, join } from "path"; | ||
| import path from "path"; | ||
| // src/utils.ts | ||
| import { sha256 } from "js-sha256"; | ||
| import debug from "debug"; | ||
| var ifInBrowser = typeof window !== "undefined"; | ||
| function assert(condition, message) { | ||
| if (!condition) { | ||
| throw new Error(message || "Assertion failed"); | ||
| } | ||
| } | ||
| // src/node/fs.ts | ||
| var pkgCacheMap = {}; | ||
| var ifInBrowser = typeof window !== "undefined"; | ||
| function getRunningPkgInfo(dir) { | ||
@@ -42,5 +54,20 @@ if (ifInBrowser) { | ||
| } | ||
| async function getExtraReturnLogic(tree = false) { | ||
| if (ifInBrowser) { | ||
| return null; | ||
| } | ||
| const currentFilePath = __filename; | ||
| const pathDir = findNearestPackageJson(dirname(currentFilePath)); | ||
| assert(pathDir, `can't find pathDir, with ${dirname}`); | ||
| const scriptPath = path.join(pathDir, "./dist/script/htmlElement.js"); | ||
| const elementInfosScriptContent = readFileSync(scriptPath, "utf-8"); | ||
| if (tree) { | ||
| return `${elementInfosScriptContent}midscene_element_inspector.webExtractNodeTree()`; | ||
| } | ||
| return `${elementInfosScriptContent}midscene_element_inspector.webExtractTextWithPosition()`; | ||
| } | ||
| export { | ||
| findNearestPackageJson, | ||
| getExtraReturnLogic, | ||
| getRunningPkgInfo | ||
| }; |
+203
-228
@@ -1,26 +0,4 @@ | ||
| var __pow = Math.pow; | ||
| var __async = (__this, __arguments, generator) => { | ||
| return new Promise((resolve, reject) => { | ||
| var fulfilled = (value) => { | ||
| try { | ||
| step(generator.next(value)); | ||
| } catch (e) { | ||
| reject(e); | ||
| } | ||
| }; | ||
| var rejected = (value) => { | ||
| try { | ||
| step(generator.throw(value)); | ||
| } catch (e) { | ||
| reject(e); | ||
| } | ||
| }; | ||
| var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected); | ||
| step((generator = generator.apply(__this, __arguments)).next()); | ||
| }); | ||
| }; | ||
| // src/img/info.ts | ||
| import assert from "assert"; | ||
| import { Buffer as Buffer2 } from "buffer"; | ||
| import { Buffer } from "buffer"; | ||
| import { readFileSync } from "fs"; | ||
@@ -30,45 +8,37 @@ | ||
| var ifInBrowser = typeof window !== "undefined"; | ||
| function getJimp() { | ||
| return __async(this, null, function* () { | ||
| if (ifInBrowser) { | ||
| yield import("jimp/browser/lib/jimp.js"); | ||
| return window.Jimp; | ||
| } | ||
| return (yield import("jimp")).default; | ||
| }); | ||
| async function getJimp() { | ||
| if (ifInBrowser) { | ||
| await import("jimp/browser/lib/jimp.js"); | ||
| return window.Jimp; | ||
| } | ||
| return (await import("jimp")).default; | ||
| } | ||
| // src/img/info.ts | ||
| function imageInfo(image) { | ||
| return __async(this, null, function* () { | ||
| const Jimp = yield getJimp(); | ||
| let jimpImage; | ||
| if (typeof image === "string") { | ||
| jimpImage = yield Jimp.read(image); | ||
| } else if (Buffer2.isBuffer(image)) { | ||
| jimpImage = yield Jimp.read(image); | ||
| } else if (image instanceof Jimp) { | ||
| jimpImage = image; | ||
| } else { | ||
| throw new Error("Invalid image input: must be a string path or a Buffer"); | ||
| } | ||
| const { width, height } = jimpImage.bitmap; | ||
| assert( | ||
| width && height, | ||
| `Invalid image: ${typeof image === "string" ? image : "Buffer"}` | ||
| ); | ||
| return { width, height, jimpImage }; | ||
| }); | ||
| async function imageInfo(image) { | ||
| const Jimp = await getJimp(); | ||
| let jimpImage; | ||
| if (typeof image === "string") { | ||
| jimpImage = await Jimp.read(image); | ||
| } else if (Buffer.isBuffer(image)) { | ||
| jimpImage = await Jimp.read(image); | ||
| } else if (image instanceof Jimp) { | ||
| jimpImage = image; | ||
| } else { | ||
| throw new Error("Invalid image input: must be a string path or a Buffer"); | ||
| } | ||
| const { width, height } = jimpImage.bitmap; | ||
| assert( | ||
| width && height, | ||
| `Invalid image: ${typeof image === "string" ? image : "Buffer"}` | ||
| ); | ||
| return { width, height, jimpImage }; | ||
| } | ||
| function imageInfoOfBase64(imageBase64) { | ||
| return __async(this, null, function* () { | ||
| const buffer = yield bufferFromBase64(imageBase64); | ||
| return imageInfo(buffer); | ||
| }); | ||
| async function imageInfoOfBase64(imageBase64) { | ||
| const buffer = await bufferFromBase64(imageBase64); | ||
| return imageInfo(buffer); | ||
| } | ||
| function bufferFromBase64(imageBase64) { | ||
| return __async(this, null, function* () { | ||
| const base64Data = imageBase64.replace(/^data:image\/\w+;base64,/, ""); | ||
| return Buffer2.from(base64Data, "base64"); | ||
| }); | ||
| async function bufferFromBase64(imageBase64) { | ||
| const base64Data = imageBase64.replace(/^data:image\/\w+;base64,/, ""); | ||
| return Buffer.from(base64Data, "base64"); | ||
| } | ||
@@ -91,66 +61,71 @@ function base64Encoded(image, withHeader = true) { | ||
| import assert2 from "assert"; | ||
| import { Buffer as Buffer3 } from "buffer"; | ||
| function saveBase64Image(options) { | ||
| return __async(this, null, function* () { | ||
| const { base64Data, outputPath } = options; | ||
| const base64Image = base64Data.split(";base64,").pop() || base64Data; | ||
| const imageBuffer = Buffer3.from(base64Image, "base64"); | ||
| const Jimp = yield getJimp(); | ||
| const image = yield Jimp.read(imageBuffer); | ||
| yield image.writeAsync(outputPath); | ||
| }); | ||
| import { Buffer as Buffer2 } from "buffer"; | ||
| import getDebug from "debug"; | ||
| var debugImg = getDebug("img"); | ||
| async function saveBase64Image(options) { | ||
| debugImg(`saveBase64Image start: ${options.outputPath}`); | ||
| const { base64Data, outputPath } = options; | ||
| const base64Image = base64Data.split(";base64,").pop() || base64Data; | ||
| const imageBuffer = Buffer2.from(base64Image, "base64"); | ||
| const Jimp = await getJimp(); | ||
| const image = await Jimp.read(imageBuffer); | ||
| await image.writeAsync(outputPath); | ||
| debugImg(`saveBase64Image done: ${options.outputPath}`); | ||
| } | ||
| function transformImgPathToBase64(inputPath) { | ||
| return __async(this, null, function* () { | ||
| const Jimp = yield getJimp(); | ||
| const image = yield Jimp.read(inputPath); | ||
| const buffer = yield image.getBufferAsync(Jimp.MIME_JPEG); | ||
| return buffer.toString("base64"); | ||
| }); | ||
| async function transformImgPathToBase64(inputPath) { | ||
| debugImg(`transformImgPathToBase64 start: ${inputPath}`); | ||
| const Jimp = await getJimp(); | ||
| const image = await Jimp.read(inputPath); | ||
| const buffer = await image.getBufferAsync(Jimp.MIME_JPEG); | ||
| const res = buffer.toString("base64"); | ||
| debugImg(`transformImgPathToBase64 done: ${inputPath}`); | ||
| return res; | ||
| } | ||
| function resizeImg(inputData, newSize) { | ||
| return __async(this, null, function* () { | ||
| if (typeof inputData === "string") | ||
| throw Error("inputData is base64, use resizeImgBase64 instead"); | ||
| assert2( | ||
| newSize && newSize.width > 0 && newSize.height > 0, | ||
| "newSize must be positive" | ||
| ); | ||
| const Jimp = yield getJimp(); | ||
| const image = yield Jimp.read(inputData); | ||
| const { width, height } = image.bitmap; | ||
| if (!width || !height) { | ||
| throw Error("Undefined width or height from the input image."); | ||
| } | ||
| if (newSize.width === width && newSize.height === height) { | ||
| return inputData; | ||
| } | ||
| image.resize(newSize.width, newSize.height, Jimp.RESIZE_NEAREST_NEIGHBOR); | ||
| image.quality(90); | ||
| const resizedBuffer = yield image.getBufferAsync(Jimp.MIME_JPEG); | ||
| return resizedBuffer; | ||
| }); | ||
| async function resizeImg(inputData, newSize) { | ||
| if (typeof inputData === "string") | ||
| throw Error("inputData is base64, use resizeImgBase64 instead"); | ||
| assert2( | ||
| newSize && newSize.width > 0 && newSize.height > 0, | ||
| "newSize must be positive" | ||
| ); | ||
| debugImg(`resizeImg start, target size: ${newSize.width}x${newSize.height}`); | ||
| const Jimp = await getJimp(); | ||
| const image = await Jimp.read(inputData); | ||
| const { width, height } = image.bitmap; | ||
| if (!width || !height) { | ||
| throw Error("Undefined width or height from the input image."); | ||
| } | ||
| if (newSize.width === width && newSize.height === height) { | ||
| return inputData; | ||
| } | ||
| image.resize(newSize.width, newSize.height, Jimp.RESIZE_NEAREST_NEIGHBOR); | ||
| image.quality(90); | ||
| const resizedBuffer = await image.getBufferAsync(Jimp.MIME_JPEG); | ||
| debugImg(`resizeImg done, target size: ${newSize.width}x${newSize.height}`); | ||
| return resizedBuffer; | ||
| } | ||
| function bufferFromBase642(base64) { | ||
| return __async(this, null, function* () { | ||
| const splitFlag = ";base64,"; | ||
| const dataSplitted = base64.split(splitFlag); | ||
| if (dataSplitted.length !== 2) { | ||
| throw Error("Invalid base64 data"); | ||
| } | ||
| return Buffer3.from(dataSplitted[1], "base64"); | ||
| }); | ||
| async function bufferFromBase642(base64) { | ||
| const splitFlag = ";base64,"; | ||
| const dataSplitted = base64.split(splitFlag); | ||
| if (dataSplitted.length !== 2) { | ||
| throw Error("Invalid base64 data"); | ||
| } | ||
| debugImg(`bufferFromBase64 start: ${base64}`); | ||
| const res = Buffer2.from(dataSplitted[1], "base64"); | ||
| debugImg(`bufferFromBase64 done: ${base64}`); | ||
| return res; | ||
| } | ||
| function resizeImgBase64(inputBase64, newSize) { | ||
| return __async(this, null, function* () { | ||
| const splitFlag = ";base64,"; | ||
| const dataSplitted = inputBase64.split(splitFlag); | ||
| if (dataSplitted.length !== 2) { | ||
| throw Error("Invalid base64 data"); | ||
| } | ||
| const imageBuffer = Buffer3.from(dataSplitted[1], "base64"); | ||
| const buffer = yield resizeImg(imageBuffer, newSize); | ||
| const content = buffer.toString("base64"); | ||
| return `${dataSplitted[0]}${splitFlag}${content}`; | ||
| }); | ||
| async function resizeImgBase64(inputBase64, newSize) { | ||
| debugImg(`resizeImgBase64 start: ${inputBase64}`); | ||
| const splitFlag = ";base64,"; | ||
| const dataSplitted = inputBase64.split(splitFlag); | ||
| if (dataSplitted.length !== 2) { | ||
| throw Error("Invalid base64 data"); | ||
| } | ||
| const imageBuffer = Buffer2.from(dataSplitted[1], "base64"); | ||
| const buffer = await resizeImg(imageBuffer, newSize); | ||
| const content = buffer.toString("base64"); | ||
| const res = `${dataSplitted[0]}${splitFlag}${content}`; | ||
| debugImg(`resizeImgBase64 done: ${inputBase64}`); | ||
| return res; | ||
| } | ||
@@ -176,43 +151,41 @@ function zoomForGPT4o(originalWidth, originalHeight) { | ||
| } | ||
| function trimImage(image) { | ||
| return __async(this, null, function* () { | ||
| const Jimp = yield getJimp(); | ||
| const jimpImage = yield Jimp.read( | ||
| Buffer3.isBuffer(image) ? image : Buffer3.from(image) | ||
| ); | ||
| const { width, height } = jimpImage.bitmap; | ||
| if (width <= 3 || height <= 3) { | ||
| return null; | ||
| } | ||
| const trimmedImage = jimpImage.autocrop(); | ||
| const { width: trimmedWidth, height: trimmedHeight } = trimmedImage.bitmap; | ||
| const trimOffsetLeft = (width - trimmedWidth) / 2; | ||
| const trimOffsetTop = (height - trimmedHeight) / 2; | ||
| if (trimOffsetLeft === 0 && trimOffsetTop === 0) { | ||
| return null; | ||
| } | ||
| return { | ||
| trimOffsetLeft: -trimOffsetLeft, | ||
| trimOffsetTop: -trimOffsetTop, | ||
| width: trimmedWidth, | ||
| height: trimmedHeight | ||
| }; | ||
| }); | ||
| async function trimImage(image) { | ||
| const Jimp = await getJimp(); | ||
| const jimpImage = await Jimp.read( | ||
| Buffer2.isBuffer(image) ? image : Buffer2.from(image) | ||
| ); | ||
| const { width, height } = jimpImage.bitmap; | ||
| if (width <= 3 || height <= 3) { | ||
| return null; | ||
| } | ||
| const trimmedImage = jimpImage.autocrop(); | ||
| const { width: trimmedWidth, height: trimmedHeight } = trimmedImage.bitmap; | ||
| const trimOffsetLeft = (width - trimmedWidth) / 2; | ||
| const trimOffsetTop = (height - trimmedHeight) / 2; | ||
| if (trimOffsetLeft === 0 && trimOffsetTop === 0) { | ||
| return null; | ||
| } | ||
| return { | ||
| trimOffsetLeft: -trimOffsetLeft, | ||
| trimOffsetTop: -trimOffsetTop, | ||
| width: trimmedWidth, | ||
| height: trimmedHeight | ||
| }; | ||
| } | ||
| function paddingToMatchBlock(imageBase64, blockSize = 28) { | ||
| return __async(this, null, function* () { | ||
| const Jimp = yield getJimp(); | ||
| const imageBuffer = yield bufferFromBase642(imageBase64); | ||
| const image = yield Jimp.read(imageBuffer); | ||
| const { width, height } = image.bitmap; | ||
| const targetWidth = Math.ceil(width / blockSize) * blockSize; | ||
| const targetHeight = Math.ceil(height / blockSize) * blockSize; | ||
| if (targetWidth === width && targetHeight === height) { | ||
| return imageBase64; | ||
| } | ||
| const paddedImage = new Jimp(targetWidth, targetHeight, 4294967295); | ||
| paddedImage.composite(image, 0, 0); | ||
| const base64 = yield paddedImage.getBase64Async(Jimp.MIME_JPEG); | ||
| return base64; | ||
| }); | ||
| async function paddingToMatchBlock(imageBase64, blockSize = 28) { | ||
| debugImg("paddingToMatchBlock start"); | ||
| const Jimp = await getJimp(); | ||
| const imageBuffer = await bufferFromBase642(imageBase64); | ||
| const image = await Jimp.read(imageBuffer); | ||
| const { width, height } = image.bitmap; | ||
| const targetWidth = Math.ceil(width / blockSize) * blockSize; | ||
| const targetHeight = Math.ceil(height / blockSize) * blockSize; | ||
| if (targetWidth === width && targetHeight === height) { | ||
| return imageBase64; | ||
| } | ||
| const paddedImage = new Jimp(targetWidth, targetHeight, 4294967295); | ||
| paddedImage.composite(image, 0, 0); | ||
| const base64 = await paddedImage.getBase64Async(Jimp.MIME_JPEG); | ||
| debugImg("paddingToMatchBlock done"); | ||
| return base64; | ||
| } | ||
@@ -223,4 +196,4 @@ | ||
| var cachedFont = null; | ||
| var createSvgOverlay = (elements, imageWidth, imageHeight, boxPadding = 5) => __async(void 0, null, function* () { | ||
| const Jimp = yield getJimp(); | ||
| var createSvgOverlay = async (elements, imageWidth, imageHeight, boxPadding = 5) => { | ||
| const Jimp = await getJimp(); | ||
| const image = new Jimp(imageWidth, imageHeight, 0); | ||
@@ -259,8 +232,8 @@ const colors = [ | ||
| paddedRect.height, | ||
| function(x, y, idx) { | ||
| (x, y, idx) => { | ||
| if (x === paddedRect.left || x === paddedRect.left + paddedRect.width - 1 || y === paddedRect.top || y === paddedRect.top + paddedRect.height - 1) { | ||
| this.bitmap.data[idx + 0] = color.rect >> 24 & 255; | ||
| this.bitmap.data[idx + 1] = color.rect >> 16 & 255; | ||
| this.bitmap.data[idx + 2] = color.rect >> 8 & 255; | ||
| this.bitmap.data[idx + 3] = color.rect & 255; | ||
| image.bitmap.data[idx + 0] = color.rect >> 24 & 255; | ||
| image.bitmap.data[idx + 1] = color.rect >> 16 & 255; | ||
| image.bitmap.data[idx + 2] = color.rect >> 8 & 255; | ||
| image.bitmap.data[idx + 3] = color.rect & 255; | ||
| } | ||
@@ -301,10 +274,16 @@ } | ||
| } | ||
| image.scan(rectX, rectY, rectWidth, rectHeight, function(x, y, idx) { | ||
| this.bitmap.data[idx + 0] = color.rect >> 24 & 255; | ||
| this.bitmap.data[idx + 1] = color.rect >> 16 & 255; | ||
| this.bitmap.data[idx + 2] = color.rect >> 8 & 255; | ||
| this.bitmap.data[idx + 3] = color.rect & 255; | ||
| }); | ||
| image.scan( | ||
| rectX, | ||
| rectY, | ||
| rectWidth, | ||
| rectHeight, | ||
| (x, y, idx) => { | ||
| image.bitmap.data[idx + 0] = color.rect >> 24 & 255; | ||
| image.bitmap.data[idx + 1] = color.rect >> 16 & 255; | ||
| image.bitmap.data[idx + 2] = color.rect >> 8 & 255; | ||
| image.bitmap.data[idx + 3] = color.rect & 255; | ||
| } | ||
| ); | ||
| try { | ||
| cachedFont = cachedFont || (yield Jimp.loadFont(Jimp.FONT_SANS_16_WHITE)); | ||
| cachedFont = cachedFont || await Jimp.loadFont(Jimp.FONT_SANS_16_WHITE); | ||
| } catch (error) { | ||
@@ -327,4 +306,4 @@ console.error("Error loading font", error); | ||
| return image; | ||
| }); | ||
| var compositeElementInfoImg = (options) => __async(void 0, null, function* () { | ||
| }; | ||
| var compositeElementInfoImg = async (options) => { | ||
| assert3(options.inputImgBase64, "inputImgBase64 is required"); | ||
@@ -334,3 +313,3 @@ let width = 0; | ||
| let jimpImage; | ||
| const Jimp = yield getJimp(); | ||
| const Jimp = await getJimp(); | ||
| if (options.size) { | ||
@@ -341,3 +320,3 @@ width = options.size.width; | ||
| if (!width || !height) { | ||
| const info = yield imageInfoOfBase64(options.inputImgBase64); | ||
| const info = await imageInfoOfBase64(options.inputImgBase64); | ||
| width = info.width; | ||
@@ -347,4 +326,4 @@ height = info.height; | ||
| } else { | ||
| const imageBuffer = yield bufferFromBase64(options.inputImgBase64); | ||
| jimpImage = yield Jimp.read(imageBuffer); | ||
| const imageBuffer = await bufferFromBase64(options.inputImgBase64); | ||
| jimpImage = await Jimp.read(imageBuffer); | ||
| const imageBitmap = jimpImage.bitmap; | ||
@@ -359,4 +338,4 @@ if (imageBitmap.width !== width || imageBitmap.height !== height) { | ||
| const { elementsPositionInfo } = options; | ||
| const result = yield Promise.resolve(jimpImage).then((image) => __async(void 0, null, function* () { | ||
| const svgOverlay = yield createSvgOverlay( | ||
| const result = await Promise.resolve(jimpImage).then(async (image) => { | ||
| const svgOverlay = await createSvgOverlay( | ||
| elementsPositionInfo, | ||
@@ -367,4 +346,4 @@ width, | ||
| ); | ||
| const svgImage = yield Jimp.read(svgOverlay); | ||
| const compositeImage = yield image.composite(svgImage, 0, 0, { | ||
| const svgImage = await Jimp.read(svgOverlay); | ||
| const compositeImage = await image.composite(svgImage, 0, 0, { | ||
| mode: Jimp.BLEND_SOURCE_OVER, | ||
@@ -375,12 +354,12 @@ opacitySource: 1, | ||
| return compositeImage; | ||
| })).then((compositeImage) => __async(void 0, null, function* () { | ||
| }).then(async (compositeImage) => { | ||
| compositeImage.quality(90); | ||
| const base64 = yield compositeImage.getBase64Async(Jimp.MIME_JPEG); | ||
| const base64 = await compositeImage.getBase64Async(Jimp.MIME_JPEG); | ||
| return base64; | ||
| })).catch((error) => { | ||
| }).catch((error) => { | ||
| throw error; | ||
| }); | ||
| return result; | ||
| }); | ||
| var processImageElementInfo = (options) => __async(void 0, null, function* () { | ||
| }; | ||
| var processImageElementInfo = async (options) => { | ||
| const base64Image = options.inputImgBase64.split(";base64,").pop(); | ||
@@ -391,3 +370,3 @@ assert3(base64Image, "base64Image is undefined"); | ||
| compositeElementInfoImgWithoutTextBase64 | ||
| ] = yield Promise.all([ | ||
| ] = await Promise.all([ | ||
| compositeElementInfoImg({ | ||
@@ -406,43 +385,39 @@ inputImgBase64: options.inputImgBase64, | ||
| }; | ||
| }); | ||
| }; | ||
| // src/img/draw-box.ts | ||
| function drawBoxOnImage(options) { | ||
| return __async(this, null, function* () { | ||
| const { inputImgBase64, rect } = options; | ||
| const color = { r: 255, g: 0, b: 0, a: 255 }; | ||
| const Jimp = yield getJimp(); | ||
| const imageBuffer = yield bufferFromBase64(inputImgBase64); | ||
| const image = yield Jimp.read(imageBuffer); | ||
| const centerX = rect.x; | ||
| const centerY = rect.y; | ||
| const radius = 5; | ||
| image.scan( | ||
| Math.floor(centerX - radius), | ||
| Math.floor(centerY - radius), | ||
| radius * 2, | ||
| radius * 2, | ||
| function(x, y, idx) { | ||
| const distance = Math.sqrt(__pow(x - centerX, 2) + __pow(y - centerY, 2)); | ||
| if (distance <= radius) { | ||
| this.bitmap.data[idx + 0] = color.r; | ||
| this.bitmap.data[idx + 1] = color.g; | ||
| this.bitmap.data[idx + 2] = color.b; | ||
| this.bitmap.data[idx + 3] = color.a; | ||
| } | ||
| async function drawBoxOnImage(options) { | ||
| const { inputImgBase64, rect } = options; | ||
| const color = { r: 255, g: 0, b: 0, a: 255 }; | ||
| const Jimp = await getJimp(); | ||
| const imageBuffer = await bufferFromBase64(inputImgBase64); | ||
| const image = await Jimp.read(imageBuffer); | ||
| const centerX = rect.x; | ||
| const centerY = rect.y; | ||
| const radius = 5; | ||
| image.scan( | ||
| Math.floor(centerX - radius), | ||
| Math.floor(centerY - radius), | ||
| radius * 2, | ||
| radius * 2, | ||
| (x, y, idx) => { | ||
| const distance = Math.sqrt((x - centerX) ** 2 + (y - centerY) ** 2); | ||
| if (distance <= radius) { | ||
| image.bitmap.data[idx + 0] = color.r; | ||
| image.bitmap.data[idx + 1] = color.g; | ||
| image.bitmap.data[idx + 2] = color.b; | ||
| image.bitmap.data[idx + 3] = color.a; | ||
| } | ||
| ); | ||
| image.quality(90); | ||
| const resultBase64 = yield image.getBase64Async(Jimp.MIME_JPEG); | ||
| return resultBase64; | ||
| }); | ||
| } | ||
| ); | ||
| image.quality(90); | ||
| const resultBase64 = await image.getBase64Async(Jimp.MIME_JPEG); | ||
| return resultBase64; | ||
| } | ||
| function savePositionImg(options) { | ||
| return __async(this, null, function* () { | ||
| const { inputImgBase64, rect, outputPath } = options; | ||
| const imgBase64 = yield drawBoxOnImage({ inputImgBase64, rect }); | ||
| yield saveBase64Image({ | ||
| base64Data: imgBase64, | ||
| outputPath | ||
| }); | ||
| async function savePositionImg(options) { | ||
| const { inputImgBase64, rect, outputPath } = options; | ||
| const imgBase64 = await drawBoxOnImage({ inputImgBase64, rect }); | ||
| await saveBase64Image({ | ||
| base64Data: imgBase64, | ||
| outputPath | ||
| }); | ||
@@ -449,0 +424,0 @@ } |
+13
-1
@@ -0,5 +1,17 @@ | ||
| import debug from 'debug'; | ||
| declare const ifInBrowser: boolean; | ||
| declare function uuid(): string; | ||
| declare function getDebug(topic: string): debug.Debugger; | ||
| declare function enableDebug(topic: string): void; | ||
| declare function generateHashId(rect: any, content?: string): string; | ||
| /** | ||
| * A utility function that asserts a condition and throws an error with a message if the condition is false. | ||
| * | ||
| * @param condition - The condition to assert | ||
| * @param message - The error message to throw if the condition is false | ||
| * @throws Error with the provided message if the condition is false | ||
| */ | ||
| declare function assert(condition: any, message?: string): asserts condition; | ||
| export { generateHashId, ifInBrowser, uuid }; | ||
| export { assert, enableDebug, generateHashId, getDebug, ifInBrowser, uuid }; |
+18
-566
@@ -1,555 +0,4 @@ | ||
| var __create = Object.create; | ||
| var __defProp = Object.defineProperty; | ||
| var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
| var __getOwnPropNames = Object.getOwnPropertyNames; | ||
| var __getProtoOf = Object.getPrototypeOf; | ||
| var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
| var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, { | ||
| get: (a, b) => (typeof require !== "undefined" ? require : a)[b] | ||
| }) : x)(function(x) { | ||
| if (typeof require !== "undefined") | ||
| return require.apply(this, arguments); | ||
| throw Error('Dynamic require of "' + x + '" is not supported'); | ||
| }); | ||
| var __commonJS = (cb, mod) => function __require2() { | ||
| return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports; | ||
| }; | ||
| var __copyProps = (to, from, except, desc) => { | ||
| if (from && typeof from === "object" || typeof from === "function") { | ||
| for (let key of __getOwnPropNames(from)) | ||
| if (!__hasOwnProp.call(to, key) && key !== except) | ||
| __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); | ||
| } | ||
| return to; | ||
| }; | ||
| var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( | ||
| // If the importer is in node compatibility mode or this is not an ESM | ||
| // file that has been converted to a CommonJS file using a Babel- | ||
| // compatible transform (i.e. "__esModule" has not been set), then set | ||
| // "default" to the CommonJS "module.exports" for node compatibility. | ||
| isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, | ||
| mod | ||
| )); | ||
| // ../../node_modules/.pnpm/js-sha256@0.11.0/node_modules/js-sha256/src/sha256.js | ||
| var require_sha256 = __commonJS({ | ||
| "../../node_modules/.pnpm/js-sha256@0.11.0/node_modules/js-sha256/src/sha256.js"(exports, module) { | ||
| "use strict"; | ||
| (function() { | ||
| "use strict"; | ||
| var ERROR = "input is invalid type"; | ||
| var WINDOW = typeof window === "object"; | ||
| var root = WINDOW ? window : {}; | ||
| if (root.JS_SHA256_NO_WINDOW) { | ||
| WINDOW = false; | ||
| } | ||
| var WEB_WORKER = !WINDOW && typeof self === "object"; | ||
| var NODE_JS = !root.JS_SHA256_NO_NODE_JS && typeof process === "object" && process.versions && process.versions.node; | ||
| if (NODE_JS) { | ||
| root = global; | ||
| } else if (WEB_WORKER) { | ||
| root = self; | ||
| } | ||
| var COMMON_JS = !root.JS_SHA256_NO_COMMON_JS && typeof module === "object" && module.exports; | ||
| var AMD = typeof define === "function" && define.amd; | ||
| var ARRAY_BUFFER = !root.JS_SHA256_NO_ARRAY_BUFFER && typeof ArrayBuffer !== "undefined"; | ||
| var HEX_CHARS = "0123456789abcdef".split(""); | ||
| var EXTRA = [-2147483648, 8388608, 32768, 128]; | ||
| var SHIFT = [24, 16, 8, 0]; | ||
| var K = [ | ||
| 1116352408, | ||
| 1899447441, | ||
| 3049323471, | ||
| 3921009573, | ||
| 961987163, | ||
| 1508970993, | ||
| 2453635748, | ||
| 2870763221, | ||
| 3624381080, | ||
| 310598401, | ||
| 607225278, | ||
| 1426881987, | ||
| 1925078388, | ||
| 2162078206, | ||
| 2614888103, | ||
| 3248222580, | ||
| 3835390401, | ||
| 4022224774, | ||
| 264347078, | ||
| 604807628, | ||
| 770255983, | ||
| 1249150122, | ||
| 1555081692, | ||
| 1996064986, | ||
| 2554220882, | ||
| 2821834349, | ||
| 2952996808, | ||
| 3210313671, | ||
| 3336571891, | ||
| 3584528711, | ||
| 113926993, | ||
| 338241895, | ||
| 666307205, | ||
| 773529912, | ||
| 1294757372, | ||
| 1396182291, | ||
| 1695183700, | ||
| 1986661051, | ||
| 2177026350, | ||
| 2456956037, | ||
| 2730485921, | ||
| 2820302411, | ||
| 3259730800, | ||
| 3345764771, | ||
| 3516065817, | ||
| 3600352804, | ||
| 4094571909, | ||
| 275423344, | ||
| 430227734, | ||
| 506948616, | ||
| 659060556, | ||
| 883997877, | ||
| 958139571, | ||
| 1322822218, | ||
| 1537002063, | ||
| 1747873779, | ||
| 1955562222, | ||
| 2024104815, | ||
| 2227730452, | ||
| 2361852424, | ||
| 2428436474, | ||
| 2756734187, | ||
| 3204031479, | ||
| 3329325298 | ||
| ]; | ||
| var OUTPUT_TYPES = ["hex", "array", "digest", "arrayBuffer"]; | ||
| var blocks = []; | ||
| if (root.JS_SHA256_NO_NODE_JS || !Array.isArray) { | ||
| Array.isArray = function(obj) { | ||
| return Object.prototype.toString.call(obj) === "[object Array]"; | ||
| }; | ||
| } | ||
| if (ARRAY_BUFFER && (root.JS_SHA256_NO_ARRAY_BUFFER_IS_VIEW || !ArrayBuffer.isView)) { | ||
| ArrayBuffer.isView = function(obj) { | ||
| return typeof obj === "object" && obj.buffer && obj.buffer.constructor === ArrayBuffer; | ||
| }; | ||
| } | ||
| var createOutputMethod = function(outputType, is224) { | ||
| return function(message) { | ||
| return new Sha256(is224, true).update(message)[outputType](); | ||
| }; | ||
| }; | ||
| var createMethod = function(is224) { | ||
| var method = createOutputMethod("hex", is224); | ||
| if (NODE_JS) { | ||
| method = nodeWrap(method, is224); | ||
| } | ||
| method.create = function() { | ||
| return new Sha256(is224); | ||
| }; | ||
| method.update = function(message) { | ||
| return method.create().update(message); | ||
| }; | ||
| for (var i = 0; i < OUTPUT_TYPES.length; ++i) { | ||
| var type = OUTPUT_TYPES[i]; | ||
| method[type] = createOutputMethod(type, is224); | ||
| } | ||
| return method; | ||
| }; | ||
| var nodeWrap = function(method, is224) { | ||
| var crypto = __require("crypto"); | ||
| var Buffer2 = __require("buffer").Buffer; | ||
| var algorithm = is224 ? "sha224" : "sha256"; | ||
| var bufferFrom; | ||
| if (Buffer2.from && !root.JS_SHA256_NO_BUFFER_FROM) { | ||
| bufferFrom = Buffer2.from; | ||
| } else { | ||
| bufferFrom = function(message) { | ||
| return new Buffer2(message); | ||
| }; | ||
| } | ||
| var nodeMethod = function(message) { | ||
| if (typeof message === "string") { | ||
| return crypto.createHash(algorithm).update(message, "utf8").digest("hex"); | ||
| } else { | ||
| if (message === null || message === void 0) { | ||
| throw new Error(ERROR); | ||
| } else if (message.constructor === ArrayBuffer) { | ||
| message = new Uint8Array(message); | ||
| } | ||
| } | ||
| if (Array.isArray(message) || ArrayBuffer.isView(message) || message.constructor === Buffer2) { | ||
| return crypto.createHash(algorithm).update(bufferFrom(message)).digest("hex"); | ||
| } else { | ||
| return method(message); | ||
| } | ||
| }; | ||
| return nodeMethod; | ||
| }; | ||
| var createHmacOutputMethod = function(outputType, is224) { | ||
| return function(key, message) { | ||
| return new HmacSha256(key, is224, true).update(message)[outputType](); | ||
| }; | ||
| }; | ||
| var createHmacMethod = function(is224) { | ||
| var method = createHmacOutputMethod("hex", is224); | ||
| method.create = function(key) { | ||
| return new HmacSha256(key, is224); | ||
| }; | ||
| method.update = function(key, message) { | ||
| return method.create(key).update(message); | ||
| }; | ||
| for (var i = 0; i < OUTPUT_TYPES.length; ++i) { | ||
| var type = OUTPUT_TYPES[i]; | ||
| method[type] = createHmacOutputMethod(type, is224); | ||
| } | ||
| return method; | ||
| }; | ||
| function Sha256(is224, sharedMemory) { | ||
| if (sharedMemory) { | ||
| blocks[0] = blocks[16] = blocks[1] = blocks[2] = blocks[3] = blocks[4] = blocks[5] = blocks[6] = blocks[7] = blocks[8] = blocks[9] = blocks[10] = blocks[11] = blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0; | ||
| this.blocks = blocks; | ||
| } else { | ||
| this.blocks = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; | ||
| } | ||
| if (is224) { | ||
| this.h0 = 3238371032; | ||
| this.h1 = 914150663; | ||
| this.h2 = 812702999; | ||
| this.h3 = 4144912697; | ||
| this.h4 = 4290775857; | ||
| this.h5 = 1750603025; | ||
| this.h6 = 1694076839; | ||
| this.h7 = 3204075428; | ||
| } else { | ||
| this.h0 = 1779033703; | ||
| this.h1 = 3144134277; | ||
| this.h2 = 1013904242; | ||
| this.h3 = 2773480762; | ||
| this.h4 = 1359893119; | ||
| this.h5 = 2600822924; | ||
| this.h6 = 528734635; | ||
| this.h7 = 1541459225; | ||
| } | ||
| this.block = this.start = this.bytes = this.hBytes = 0; | ||
| this.finalized = this.hashed = false; | ||
| this.first = true; | ||
| this.is224 = is224; | ||
| } | ||
| Sha256.prototype.update = function(message) { | ||
| if (this.finalized) { | ||
| return; | ||
| } | ||
| var notString, type = typeof message; | ||
| if (type !== "string") { | ||
| if (type === "object") { | ||
| if (message === null) { | ||
| throw new Error(ERROR); | ||
| } else if (ARRAY_BUFFER && message.constructor === ArrayBuffer) { | ||
| message = new Uint8Array(message); | ||
| } else if (!Array.isArray(message)) { | ||
| if (!ARRAY_BUFFER || !ArrayBuffer.isView(message)) { | ||
| throw new Error(ERROR); | ||
| } | ||
| } | ||
| } else { | ||
| throw new Error(ERROR); | ||
| } | ||
| notString = true; | ||
| } | ||
| var code, index = 0, i, length = message.length, blocks2 = this.blocks; | ||
| while (index < length) { | ||
| if (this.hashed) { | ||
| this.hashed = false; | ||
| blocks2[0] = this.block; | ||
| this.block = blocks2[16] = blocks2[1] = blocks2[2] = blocks2[3] = blocks2[4] = blocks2[5] = blocks2[6] = blocks2[7] = blocks2[8] = blocks2[9] = blocks2[10] = blocks2[11] = blocks2[12] = blocks2[13] = blocks2[14] = blocks2[15] = 0; | ||
| } | ||
| if (notString) { | ||
| for (i = this.start; index < length && i < 64; ++index) { | ||
| blocks2[i >>> 2] |= message[index] << SHIFT[i++ & 3]; | ||
| } | ||
| } else { | ||
| for (i = this.start; index < length && i < 64; ++index) { | ||
| code = message.charCodeAt(index); | ||
| if (code < 128) { | ||
| blocks2[i >>> 2] |= code << SHIFT[i++ & 3]; | ||
| } else if (code < 2048) { | ||
| blocks2[i >>> 2] |= (192 | code >>> 6) << SHIFT[i++ & 3]; | ||
| blocks2[i >>> 2] |= (128 | code & 63) << SHIFT[i++ & 3]; | ||
| } else if (code < 55296 || code >= 57344) { | ||
| blocks2[i >>> 2] |= (224 | code >>> 12) << SHIFT[i++ & 3]; | ||
| blocks2[i >>> 2] |= (128 | code >>> 6 & 63) << SHIFT[i++ & 3]; | ||
| blocks2[i >>> 2] |= (128 | code & 63) << SHIFT[i++ & 3]; | ||
| } else { | ||
| code = 65536 + ((code & 1023) << 10 | message.charCodeAt(++index) & 1023); | ||
| blocks2[i >>> 2] |= (240 | code >>> 18) << SHIFT[i++ & 3]; | ||
| blocks2[i >>> 2] |= (128 | code >>> 12 & 63) << SHIFT[i++ & 3]; | ||
| blocks2[i >>> 2] |= (128 | code >>> 6 & 63) << SHIFT[i++ & 3]; | ||
| blocks2[i >>> 2] |= (128 | code & 63) << SHIFT[i++ & 3]; | ||
| } | ||
| } | ||
| } | ||
| this.lastByteIndex = i; | ||
| this.bytes += i - this.start; | ||
| if (i >= 64) { | ||
| this.block = blocks2[16]; | ||
| this.start = i - 64; | ||
| this.hash(); | ||
| this.hashed = true; | ||
| } else { | ||
| this.start = i; | ||
| } | ||
| } | ||
| if (this.bytes > 4294967295) { | ||
| this.hBytes += this.bytes / 4294967296 << 0; | ||
| this.bytes = this.bytes % 4294967296; | ||
| } | ||
| return this; | ||
| }; | ||
| Sha256.prototype.finalize = function() { | ||
| if (this.finalized) { | ||
| return; | ||
| } | ||
| this.finalized = true; | ||
| var blocks2 = this.blocks, i = this.lastByteIndex; | ||
| blocks2[16] = this.block; | ||
| blocks2[i >>> 2] |= EXTRA[i & 3]; | ||
| this.block = blocks2[16]; | ||
| if (i >= 56) { | ||
| if (!this.hashed) { | ||
| this.hash(); | ||
| } | ||
| blocks2[0] = this.block; | ||
| blocks2[16] = blocks2[1] = blocks2[2] = blocks2[3] = blocks2[4] = blocks2[5] = blocks2[6] = blocks2[7] = blocks2[8] = blocks2[9] = blocks2[10] = blocks2[11] = blocks2[12] = blocks2[13] = blocks2[14] = blocks2[15] = 0; | ||
| } | ||
| blocks2[14] = this.hBytes << 3 | this.bytes >>> 29; | ||
| blocks2[15] = this.bytes << 3; | ||
| this.hash(); | ||
| }; | ||
| Sha256.prototype.hash = function() { | ||
| var a = this.h0, b = this.h1, c = this.h2, d = this.h3, e = this.h4, f = this.h5, g = this.h6, h = this.h7, blocks2 = this.blocks, j, s0, s1, maj, t1, t2, ch, ab, da, cd, bc; | ||
| for (j = 16; j < 64; ++j) { | ||
| t1 = blocks2[j - 15]; | ||
| s0 = (t1 >>> 7 | t1 << 25) ^ (t1 >>> 18 | t1 << 14) ^ t1 >>> 3; | ||
| t1 = blocks2[j - 2]; | ||
| s1 = (t1 >>> 17 | t1 << 15) ^ (t1 >>> 19 | t1 << 13) ^ t1 >>> 10; | ||
| blocks2[j] = blocks2[j - 16] + s0 + blocks2[j - 7] + s1 << 0; | ||
| } | ||
| bc = b & c; | ||
| for (j = 0; j < 64; j += 4) { | ||
| if (this.first) { | ||
| if (this.is224) { | ||
| ab = 300032; | ||
| t1 = blocks2[0] - 1413257819; | ||
| h = t1 - 150054599 << 0; | ||
| d = t1 + 24177077 << 0; | ||
| } else { | ||
| ab = 704751109; | ||
| t1 = blocks2[0] - 210244248; | ||
| h = t1 - 1521486534 << 0; | ||
| d = t1 + 143694565 << 0; | ||
| } | ||
| this.first = false; | ||
| } else { | ||
| s0 = (a >>> 2 | a << 30) ^ (a >>> 13 | a << 19) ^ (a >>> 22 | a << 10); | ||
| s1 = (e >>> 6 | e << 26) ^ (e >>> 11 | e << 21) ^ (e >>> 25 | e << 7); | ||
| ab = a & b; | ||
| maj = ab ^ a & c ^ bc; | ||
| ch = e & f ^ ~e & g; | ||
| t1 = h + s1 + ch + K[j] + blocks2[j]; | ||
| t2 = s0 + maj; | ||
| h = d + t1 << 0; | ||
| d = t1 + t2 << 0; | ||
| } | ||
| s0 = (d >>> 2 | d << 30) ^ (d >>> 13 | d << 19) ^ (d >>> 22 | d << 10); | ||
| s1 = (h >>> 6 | h << 26) ^ (h >>> 11 | h << 21) ^ (h >>> 25 | h << 7); | ||
| da = d & a; | ||
| maj = da ^ d & b ^ ab; | ||
| ch = h & e ^ ~h & f; | ||
| t1 = g + s1 + ch + K[j + 1] + blocks2[j + 1]; | ||
| t2 = s0 + maj; | ||
| g = c + t1 << 0; | ||
| c = t1 + t2 << 0; | ||
| s0 = (c >>> 2 | c << 30) ^ (c >>> 13 | c << 19) ^ (c >>> 22 | c << 10); | ||
| s1 = (g >>> 6 | g << 26) ^ (g >>> 11 | g << 21) ^ (g >>> 25 | g << 7); | ||
| cd = c & d; | ||
| maj = cd ^ c & a ^ da; | ||
| ch = g & h ^ ~g & e; | ||
| t1 = f + s1 + ch + K[j + 2] + blocks2[j + 2]; | ||
| t2 = s0 + maj; | ||
| f = b + t1 << 0; | ||
| b = t1 + t2 << 0; | ||
| s0 = (b >>> 2 | b << 30) ^ (b >>> 13 | b << 19) ^ (b >>> 22 | b << 10); | ||
| s1 = (f >>> 6 | f << 26) ^ (f >>> 11 | f << 21) ^ (f >>> 25 | f << 7); | ||
| bc = b & c; | ||
| maj = bc ^ b & d ^ cd; | ||
| ch = f & g ^ ~f & h; | ||
| t1 = e + s1 + ch + K[j + 3] + blocks2[j + 3]; | ||
| t2 = s0 + maj; | ||
| e = a + t1 << 0; | ||
| a = t1 + t2 << 0; | ||
| this.chromeBugWorkAround = true; | ||
| } | ||
| this.h0 = this.h0 + a << 0; | ||
| this.h1 = this.h1 + b << 0; | ||
| this.h2 = this.h2 + c << 0; | ||
| this.h3 = this.h3 + d << 0; | ||
| this.h4 = this.h4 + e << 0; | ||
| this.h5 = this.h5 + f << 0; | ||
| this.h6 = this.h6 + g << 0; | ||
| this.h7 = this.h7 + h << 0; | ||
| }; | ||
| Sha256.prototype.hex = function() { | ||
| this.finalize(); | ||
| var h0 = this.h0, h1 = this.h1, h2 = this.h2, h3 = this.h3, h4 = this.h4, h5 = this.h5, h6 = this.h6, h7 = this.h7; | ||
| var hex = HEX_CHARS[h0 >>> 28 & 15] + HEX_CHARS[h0 >>> 24 & 15] + HEX_CHARS[h0 >>> 20 & 15] + HEX_CHARS[h0 >>> 16 & 15] + HEX_CHARS[h0 >>> 12 & 15] + HEX_CHARS[h0 >>> 8 & 15] + HEX_CHARS[h0 >>> 4 & 15] + HEX_CHARS[h0 & 15] + HEX_CHARS[h1 >>> 28 & 15] + HEX_CHARS[h1 >>> 24 & 15] + HEX_CHARS[h1 >>> 20 & 15] + HEX_CHARS[h1 >>> 16 & 15] + HEX_CHARS[h1 >>> 12 & 15] + HEX_CHARS[h1 >>> 8 & 15] + HEX_CHARS[h1 >>> 4 & 15] + HEX_CHARS[h1 & 15] + HEX_CHARS[h2 >>> 28 & 15] + HEX_CHARS[h2 >>> 24 & 15] + HEX_CHARS[h2 >>> 20 & 15] + HEX_CHARS[h2 >>> 16 & 15] + HEX_CHARS[h2 >>> 12 & 15] + HEX_CHARS[h2 >>> 8 & 15] + HEX_CHARS[h2 >>> 4 & 15] + HEX_CHARS[h2 & 15] + HEX_CHARS[h3 >>> 28 & 15] + HEX_CHARS[h3 >>> 24 & 15] + HEX_CHARS[h3 >>> 20 & 15] + HEX_CHARS[h3 >>> 16 & 15] + HEX_CHARS[h3 >>> 12 & 15] + HEX_CHARS[h3 >>> 8 & 15] + HEX_CHARS[h3 >>> 4 & 15] + HEX_CHARS[h3 & 15] + HEX_CHARS[h4 >>> 28 & 15] + HEX_CHARS[h4 >>> 24 & 15] + HEX_CHARS[h4 >>> 20 & 15] + HEX_CHARS[h4 >>> 16 & 15] + HEX_CHARS[h4 >>> 12 & 15] + HEX_CHARS[h4 >>> 8 & 15] + HEX_CHARS[h4 >>> 4 & 15] + HEX_CHARS[h4 & 15] + HEX_CHARS[h5 >>> 28 & 15] + HEX_CHARS[h5 >>> 24 & 15] + HEX_CHARS[h5 >>> 20 & 15] + HEX_CHARS[h5 >>> 16 & 15] + HEX_CHARS[h5 >>> 12 & 15] + HEX_CHARS[h5 >>> 8 & 15] + HEX_CHARS[h5 >>> 4 & 15] + HEX_CHARS[h5 & 15] + HEX_CHARS[h6 >>> 28 & 15] + HEX_CHARS[h6 >>> 24 & 15] + HEX_CHARS[h6 >>> 20 & 15] + HEX_CHARS[h6 >>> 16 & 15] + HEX_CHARS[h6 >>> 12 & 15] + HEX_CHARS[h6 >>> 8 & 15] + HEX_CHARS[h6 >>> 4 & 15] + HEX_CHARS[h6 & 15]; | ||
| if (!this.is224) { | ||
| hex += HEX_CHARS[h7 >>> 28 & 15] + HEX_CHARS[h7 >>> 24 & 15] + HEX_CHARS[h7 >>> 20 & 15] + HEX_CHARS[h7 >>> 16 & 15] + HEX_CHARS[h7 >>> 12 & 15] + HEX_CHARS[h7 >>> 8 & 15] + HEX_CHARS[h7 >>> 4 & 15] + HEX_CHARS[h7 & 15]; | ||
| } | ||
| return hex; | ||
| }; | ||
| Sha256.prototype.toString = Sha256.prototype.hex; | ||
| Sha256.prototype.digest = function() { | ||
| this.finalize(); | ||
| var h0 = this.h0, h1 = this.h1, h2 = this.h2, h3 = this.h3, h4 = this.h4, h5 = this.h5, h6 = this.h6, h7 = this.h7; | ||
| var arr = [ | ||
| h0 >>> 24 & 255, | ||
| h0 >>> 16 & 255, | ||
| h0 >>> 8 & 255, | ||
| h0 & 255, | ||
| h1 >>> 24 & 255, | ||
| h1 >>> 16 & 255, | ||
| h1 >>> 8 & 255, | ||
| h1 & 255, | ||
| h2 >>> 24 & 255, | ||
| h2 >>> 16 & 255, | ||
| h2 >>> 8 & 255, | ||
| h2 & 255, | ||
| h3 >>> 24 & 255, | ||
| h3 >>> 16 & 255, | ||
| h3 >>> 8 & 255, | ||
| h3 & 255, | ||
| h4 >>> 24 & 255, | ||
| h4 >>> 16 & 255, | ||
| h4 >>> 8 & 255, | ||
| h4 & 255, | ||
| h5 >>> 24 & 255, | ||
| h5 >>> 16 & 255, | ||
| h5 >>> 8 & 255, | ||
| h5 & 255, | ||
| h6 >>> 24 & 255, | ||
| h6 >>> 16 & 255, | ||
| h6 >>> 8 & 255, | ||
| h6 & 255 | ||
| ]; | ||
| if (!this.is224) { | ||
| arr.push(h7 >>> 24 & 255, h7 >>> 16 & 255, h7 >>> 8 & 255, h7 & 255); | ||
| } | ||
| return arr; | ||
| }; | ||
| Sha256.prototype.array = Sha256.prototype.digest; | ||
| Sha256.prototype.arrayBuffer = function() { | ||
| this.finalize(); | ||
| var buffer = new ArrayBuffer(this.is224 ? 28 : 32); | ||
| var dataView = new DataView(buffer); | ||
| dataView.setUint32(0, this.h0); | ||
| dataView.setUint32(4, this.h1); | ||
| dataView.setUint32(8, this.h2); | ||
| dataView.setUint32(12, this.h3); | ||
| dataView.setUint32(16, this.h4); | ||
| dataView.setUint32(20, this.h5); | ||
| dataView.setUint32(24, this.h6); | ||
| if (!this.is224) { | ||
| dataView.setUint32(28, this.h7); | ||
| } | ||
| return buffer; | ||
| }; | ||
| function HmacSha256(key, is224, sharedMemory) { | ||
| var i, type = typeof key; | ||
| if (type === "string") { | ||
| var bytes = [], length = key.length, index = 0, code; | ||
| for (i = 0; i < length; ++i) { | ||
| code = key.charCodeAt(i); | ||
| if (code < 128) { | ||
| bytes[index++] = code; | ||
| } else if (code < 2048) { | ||
| bytes[index++] = 192 | code >>> 6; | ||
| bytes[index++] = 128 | code & 63; | ||
| } else if (code < 55296 || code >= 57344) { | ||
| bytes[index++] = 224 | code >>> 12; | ||
| bytes[index++] = 128 | code >>> 6 & 63; | ||
| bytes[index++] = 128 | code & 63; | ||
| } else { | ||
| code = 65536 + ((code & 1023) << 10 | key.charCodeAt(++i) & 1023); | ||
| bytes[index++] = 240 | code >>> 18; | ||
| bytes[index++] = 128 | code >>> 12 & 63; | ||
| bytes[index++] = 128 | code >>> 6 & 63; | ||
| bytes[index++] = 128 | code & 63; | ||
| } | ||
| } | ||
| key = bytes; | ||
| } else { | ||
| if (type === "object") { | ||
| if (key === null) { | ||
| throw new Error(ERROR); | ||
| } else if (ARRAY_BUFFER && key.constructor === ArrayBuffer) { | ||
| key = new Uint8Array(key); | ||
| } else if (!Array.isArray(key)) { | ||
| if (!ARRAY_BUFFER || !ArrayBuffer.isView(key)) { | ||
| throw new Error(ERROR); | ||
| } | ||
| } | ||
| } else { | ||
| throw new Error(ERROR); | ||
| } | ||
| } | ||
| if (key.length > 64) { | ||
| key = new Sha256(is224, true).update(key).array(); | ||
| } | ||
| var oKeyPad = [], iKeyPad = []; | ||
| for (i = 0; i < 64; ++i) { | ||
| var b = key[i] || 0; | ||
| oKeyPad[i] = 92 ^ b; | ||
| iKeyPad[i] = 54 ^ b; | ||
| } | ||
| Sha256.call(this, is224, sharedMemory); | ||
| this.update(iKeyPad); | ||
| this.oKeyPad = oKeyPad; | ||
| this.inner = true; | ||
| this.sharedMemory = sharedMemory; | ||
| } | ||
| HmacSha256.prototype = new Sha256(); | ||
| HmacSha256.prototype.finalize = function() { | ||
| Sha256.prototype.finalize.call(this); | ||
| if (this.inner) { | ||
| this.inner = false; | ||
| var innerHash = this.array(); | ||
| Sha256.call(this, this.is224, this.sharedMemory); | ||
| this.update(this.oKeyPad); | ||
| this.update(innerHash); | ||
| Sha256.prototype.finalize.call(this); | ||
| } | ||
| }; | ||
| var exports2 = createMethod(); | ||
| exports2.sha256 = exports2; | ||
| exports2.sha224 = createMethod(true); | ||
| exports2.sha256.hmac = createHmacMethod(); | ||
| exports2.sha224.hmac = createHmacMethod(true); | ||
| if (COMMON_JS) { | ||
| module.exports = exports2; | ||
| } else { | ||
| root.sha256 = exports2.sha256; | ||
| root.sha224 = exports2.sha224; | ||
| if (AMD) { | ||
| define(function() { | ||
| return exports2; | ||
| }); | ||
| } | ||
| } | ||
| })(); | ||
| } | ||
| }); | ||
| // src/utils.ts | ||
| var import_js_sha256 = __toESM(require_sha256()); | ||
| import { sha256 } from "js-sha256"; | ||
| import debug from "debug"; | ||
| var ifInBrowser = typeof window !== "undefined"; | ||
@@ -560,2 +9,9 @@ function uuid() { | ||
| var hashMap = {}; | ||
| var topicPrefix = "midscene"; | ||
| function getDebug(topic) { | ||
| return debug(`${topicPrefix}:${topic}`); | ||
| } | ||
| function enableDebug(topic) { | ||
| debug.enable(`${topicPrefix}:${topic}`); | ||
| } | ||
| function generateHashId(rect, content = "") { | ||
@@ -568,3 +24,3 @@ const combined = JSON.stringify({ | ||
| let slicedHash = ""; | ||
| const hashHex = import_js_sha256.sha256.create().update(combined).hex(); | ||
| const hashHex = sha256.create().update(combined).hex(); | ||
| const toLetters = (hex) => { | ||
@@ -588,18 +44,14 @@ return hex.split("").map((char) => { | ||
| } | ||
| function assert(condition, message) { | ||
| if (!condition) { | ||
| throw new Error(message || "Assertion failed"); | ||
| } | ||
| } | ||
| export { | ||
| assert, | ||
| enableDebug, | ||
| generateHashId, | ||
| getDebug, | ||
| ifInBrowser, | ||
| uuid | ||
| }; | ||
| /*! Bundled license information: | ||
| js-sha256/src/sha256.js: | ||
| (** | ||
| * [js-sha256]{@link https://github.com/emn178/js-sha256} | ||
| * | ||
| * @version 0.11.0 | ||
| * @author Chen, Yi-Cyuan [emn178@gmail.com] | ||
| * @copyright Chen, Yi-Cyuan 2014-2024 | ||
| * @license MIT | ||
| *) | ||
| */ |
+25
-591
| "use strict"; | ||
| var __create = Object.create; | ||
| var __defProp = Object.defineProperty; | ||
| var __defProps = Object.defineProperties; | ||
| var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
| var __getOwnPropDescs = Object.getOwnPropertyDescriptors; | ||
| var __getOwnPropNames = Object.getOwnPropertyNames; | ||
| var __getOwnPropSymbols = Object.getOwnPropertySymbols; | ||
| var __getProtoOf = Object.getPrototypeOf; | ||
| var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
| var __propIsEnum = Object.prototype.propertyIsEnumerable; | ||
| var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; | ||
| var __spreadValues = (a, b) => { | ||
| for (var prop in b || (b = {})) | ||
| if (__hasOwnProp.call(b, prop)) | ||
| __defNormalProp(a, prop, b[prop]); | ||
| if (__getOwnPropSymbols) | ||
| for (var prop of __getOwnPropSymbols(b)) { | ||
| if (__propIsEnum.call(b, prop)) | ||
| __defNormalProp(a, prop, b[prop]); | ||
| } | ||
| return a; | ||
| }; | ||
| var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b)); | ||
| var __commonJS = (cb, mod) => function __require() { | ||
| return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports; | ||
| }; | ||
| var __copyProps = (to, from, except, desc) => { | ||
@@ -45,521 +25,2 @@ if (from && typeof from === "object" || typeof from === "function") { | ||
| // ../../node_modules/.pnpm/js-sha256@0.11.0/node_modules/js-sha256/src/sha256.js | ||
| var require_sha256 = __commonJS({ | ||
| "../../node_modules/.pnpm/js-sha256@0.11.0/node_modules/js-sha256/src/sha256.js"(exports, module2) { | ||
| "use strict"; | ||
| (function() { | ||
| "use strict"; | ||
| var ERROR = "input is invalid type"; | ||
| var WINDOW = typeof window === "object"; | ||
| var root = WINDOW ? window : {}; | ||
| if (root.JS_SHA256_NO_WINDOW) { | ||
| WINDOW = false; | ||
| } | ||
| var WEB_WORKER = !WINDOW && typeof self === "object"; | ||
| var NODE_JS = !root.JS_SHA256_NO_NODE_JS && typeof process === "object" && process.versions && process.versions.node; | ||
| if (NODE_JS) { | ||
| root = global; | ||
| } else if (WEB_WORKER) { | ||
| root = self; | ||
| } | ||
| var COMMON_JS = !root.JS_SHA256_NO_COMMON_JS && typeof module2 === "object" && module2.exports; | ||
| var AMD = typeof define === "function" && define.amd; | ||
| var ARRAY_BUFFER = !root.JS_SHA256_NO_ARRAY_BUFFER && typeof ArrayBuffer !== "undefined"; | ||
| var HEX_CHARS = "0123456789abcdef".split(""); | ||
| var EXTRA = [-2147483648, 8388608, 32768, 128]; | ||
| var SHIFT = [24, 16, 8, 0]; | ||
| var K = [ | ||
| 1116352408, | ||
| 1899447441, | ||
| 3049323471, | ||
| 3921009573, | ||
| 961987163, | ||
| 1508970993, | ||
| 2453635748, | ||
| 2870763221, | ||
| 3624381080, | ||
| 310598401, | ||
| 607225278, | ||
| 1426881987, | ||
| 1925078388, | ||
| 2162078206, | ||
| 2614888103, | ||
| 3248222580, | ||
| 3835390401, | ||
| 4022224774, | ||
| 264347078, | ||
| 604807628, | ||
| 770255983, | ||
| 1249150122, | ||
| 1555081692, | ||
| 1996064986, | ||
| 2554220882, | ||
| 2821834349, | ||
| 2952996808, | ||
| 3210313671, | ||
| 3336571891, | ||
| 3584528711, | ||
| 113926993, | ||
| 338241895, | ||
| 666307205, | ||
| 773529912, | ||
| 1294757372, | ||
| 1396182291, | ||
| 1695183700, | ||
| 1986661051, | ||
| 2177026350, | ||
| 2456956037, | ||
| 2730485921, | ||
| 2820302411, | ||
| 3259730800, | ||
| 3345764771, | ||
| 3516065817, | ||
| 3600352804, | ||
| 4094571909, | ||
| 275423344, | ||
| 430227734, | ||
| 506948616, | ||
| 659060556, | ||
| 883997877, | ||
| 958139571, | ||
| 1322822218, | ||
| 1537002063, | ||
| 1747873779, | ||
| 1955562222, | ||
| 2024104815, | ||
| 2227730452, | ||
| 2361852424, | ||
| 2428436474, | ||
| 2756734187, | ||
| 3204031479, | ||
| 3329325298 | ||
| ]; | ||
| var OUTPUT_TYPES = ["hex", "array", "digest", "arrayBuffer"]; | ||
| var blocks = []; | ||
| if (root.JS_SHA256_NO_NODE_JS || !Array.isArray) { | ||
| Array.isArray = function(obj) { | ||
| return Object.prototype.toString.call(obj) === "[object Array]"; | ||
| }; | ||
| } | ||
| if (ARRAY_BUFFER && (root.JS_SHA256_NO_ARRAY_BUFFER_IS_VIEW || !ArrayBuffer.isView)) { | ||
| ArrayBuffer.isView = function(obj) { | ||
| return typeof obj === "object" && obj.buffer && obj.buffer.constructor === ArrayBuffer; | ||
| }; | ||
| } | ||
| var createOutputMethod = function(outputType, is224) { | ||
| return function(message) { | ||
| return new Sha256(is224, true).update(message)[outputType](); | ||
| }; | ||
| }; | ||
| var createMethod = function(is224) { | ||
| var method = createOutputMethod("hex", is224); | ||
| if (NODE_JS) { | ||
| method = nodeWrap(method, is224); | ||
| } | ||
| method.create = function() { | ||
| return new Sha256(is224); | ||
| }; | ||
| method.update = function(message) { | ||
| return method.create().update(message); | ||
| }; | ||
| for (var i = 0; i < OUTPUT_TYPES.length; ++i) { | ||
| var type = OUTPUT_TYPES[i]; | ||
| method[type] = createOutputMethod(type, is224); | ||
| } | ||
| return method; | ||
| }; | ||
| var nodeWrap = function(method, is224) { | ||
| var crypto = require("crypto"); | ||
| var Buffer2 = require("buffer").Buffer; | ||
| var algorithm = is224 ? "sha224" : "sha256"; | ||
| var bufferFrom; | ||
| if (Buffer2.from && !root.JS_SHA256_NO_BUFFER_FROM) { | ||
| bufferFrom = Buffer2.from; | ||
| } else { | ||
| bufferFrom = function(message) { | ||
| return new Buffer2(message); | ||
| }; | ||
| } | ||
| var nodeMethod = function(message) { | ||
| if (typeof message === "string") { | ||
| return crypto.createHash(algorithm).update(message, "utf8").digest("hex"); | ||
| } else { | ||
| if (message === null || message === void 0) { | ||
| throw new Error(ERROR); | ||
| } else if (message.constructor === ArrayBuffer) { | ||
| message = new Uint8Array(message); | ||
| } | ||
| } | ||
| if (Array.isArray(message) || ArrayBuffer.isView(message) || message.constructor === Buffer2) { | ||
| return crypto.createHash(algorithm).update(bufferFrom(message)).digest("hex"); | ||
| } else { | ||
| return method(message); | ||
| } | ||
| }; | ||
| return nodeMethod; | ||
| }; | ||
| var createHmacOutputMethod = function(outputType, is224) { | ||
| return function(key, message) { | ||
| return new HmacSha256(key, is224, true).update(message)[outputType](); | ||
| }; | ||
| }; | ||
| var createHmacMethod = function(is224) { | ||
| var method = createHmacOutputMethod("hex", is224); | ||
| method.create = function(key) { | ||
| return new HmacSha256(key, is224); | ||
| }; | ||
| method.update = function(key, message) { | ||
| return method.create(key).update(message); | ||
| }; | ||
| for (var i = 0; i < OUTPUT_TYPES.length; ++i) { | ||
| var type = OUTPUT_TYPES[i]; | ||
| method[type] = createHmacOutputMethod(type, is224); | ||
| } | ||
| return method; | ||
| }; | ||
| function Sha256(is224, sharedMemory) { | ||
| if (sharedMemory) { | ||
| blocks[0] = blocks[16] = blocks[1] = blocks[2] = blocks[3] = blocks[4] = blocks[5] = blocks[6] = blocks[7] = blocks[8] = blocks[9] = blocks[10] = blocks[11] = blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0; | ||
| this.blocks = blocks; | ||
| } else { | ||
| this.blocks = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; | ||
| } | ||
| if (is224) { | ||
| this.h0 = 3238371032; | ||
| this.h1 = 914150663; | ||
| this.h2 = 812702999; | ||
| this.h3 = 4144912697; | ||
| this.h4 = 4290775857; | ||
| this.h5 = 1750603025; | ||
| this.h6 = 1694076839; | ||
| this.h7 = 3204075428; | ||
| } else { | ||
| this.h0 = 1779033703; | ||
| this.h1 = 3144134277; | ||
| this.h2 = 1013904242; | ||
| this.h3 = 2773480762; | ||
| this.h4 = 1359893119; | ||
| this.h5 = 2600822924; | ||
| this.h6 = 528734635; | ||
| this.h7 = 1541459225; | ||
| } | ||
| this.block = this.start = this.bytes = this.hBytes = 0; | ||
| this.finalized = this.hashed = false; | ||
| this.first = true; | ||
| this.is224 = is224; | ||
| } | ||
| Sha256.prototype.update = function(message) { | ||
| if (this.finalized) { | ||
| return; | ||
| } | ||
| var notString, type = typeof message; | ||
| if (type !== "string") { | ||
| if (type === "object") { | ||
| if (message === null) { | ||
| throw new Error(ERROR); | ||
| } else if (ARRAY_BUFFER && message.constructor === ArrayBuffer) { | ||
| message = new Uint8Array(message); | ||
| } else if (!Array.isArray(message)) { | ||
| if (!ARRAY_BUFFER || !ArrayBuffer.isView(message)) { | ||
| throw new Error(ERROR); | ||
| } | ||
| } | ||
| } else { | ||
| throw new Error(ERROR); | ||
| } | ||
| notString = true; | ||
| } | ||
| var code, index = 0, i, length = message.length, blocks2 = this.blocks; | ||
| while (index < length) { | ||
| if (this.hashed) { | ||
| this.hashed = false; | ||
| blocks2[0] = this.block; | ||
| this.block = blocks2[16] = blocks2[1] = blocks2[2] = blocks2[3] = blocks2[4] = blocks2[5] = blocks2[6] = blocks2[7] = blocks2[8] = blocks2[9] = blocks2[10] = blocks2[11] = blocks2[12] = blocks2[13] = blocks2[14] = blocks2[15] = 0; | ||
| } | ||
| if (notString) { | ||
| for (i = this.start; index < length && i < 64; ++index) { | ||
| blocks2[i >>> 2] |= message[index] << SHIFT[i++ & 3]; | ||
| } | ||
| } else { | ||
| for (i = this.start; index < length && i < 64; ++index) { | ||
| code = message.charCodeAt(index); | ||
| if (code < 128) { | ||
| blocks2[i >>> 2] |= code << SHIFT[i++ & 3]; | ||
| } else if (code < 2048) { | ||
| blocks2[i >>> 2] |= (192 | code >>> 6) << SHIFT[i++ & 3]; | ||
| blocks2[i >>> 2] |= (128 | code & 63) << SHIFT[i++ & 3]; | ||
| } else if (code < 55296 || code >= 57344) { | ||
| blocks2[i >>> 2] |= (224 | code >>> 12) << SHIFT[i++ & 3]; | ||
| blocks2[i >>> 2] |= (128 | code >>> 6 & 63) << SHIFT[i++ & 3]; | ||
| blocks2[i >>> 2] |= (128 | code & 63) << SHIFT[i++ & 3]; | ||
| } else { | ||
| code = 65536 + ((code & 1023) << 10 | message.charCodeAt(++index) & 1023); | ||
| blocks2[i >>> 2] |= (240 | code >>> 18) << SHIFT[i++ & 3]; | ||
| blocks2[i >>> 2] |= (128 | code >>> 12 & 63) << SHIFT[i++ & 3]; | ||
| blocks2[i >>> 2] |= (128 | code >>> 6 & 63) << SHIFT[i++ & 3]; | ||
| blocks2[i >>> 2] |= (128 | code & 63) << SHIFT[i++ & 3]; | ||
| } | ||
| } | ||
| } | ||
| this.lastByteIndex = i; | ||
| this.bytes += i - this.start; | ||
| if (i >= 64) { | ||
| this.block = blocks2[16]; | ||
| this.start = i - 64; | ||
| this.hash(); | ||
| this.hashed = true; | ||
| } else { | ||
| this.start = i; | ||
| } | ||
| } | ||
| if (this.bytes > 4294967295) { | ||
| this.hBytes += this.bytes / 4294967296 << 0; | ||
| this.bytes = this.bytes % 4294967296; | ||
| } | ||
| return this; | ||
| }; | ||
| Sha256.prototype.finalize = function() { | ||
| if (this.finalized) { | ||
| return; | ||
| } | ||
| this.finalized = true; | ||
| var blocks2 = this.blocks, i = this.lastByteIndex; | ||
| blocks2[16] = this.block; | ||
| blocks2[i >>> 2] |= EXTRA[i & 3]; | ||
| this.block = blocks2[16]; | ||
| if (i >= 56) { | ||
| if (!this.hashed) { | ||
| this.hash(); | ||
| } | ||
| blocks2[0] = this.block; | ||
| blocks2[16] = blocks2[1] = blocks2[2] = blocks2[3] = blocks2[4] = blocks2[5] = blocks2[6] = blocks2[7] = blocks2[8] = blocks2[9] = blocks2[10] = blocks2[11] = blocks2[12] = blocks2[13] = blocks2[14] = blocks2[15] = 0; | ||
| } | ||
| blocks2[14] = this.hBytes << 3 | this.bytes >>> 29; | ||
| blocks2[15] = this.bytes << 3; | ||
| this.hash(); | ||
| }; | ||
| Sha256.prototype.hash = function() { | ||
| var a = this.h0, b = this.h1, c = this.h2, d = this.h3, e = this.h4, f = this.h5, g = this.h6, h = this.h7, blocks2 = this.blocks, j, s0, s1, maj, t1, t2, ch, ab, da, cd, bc; | ||
| for (j = 16; j < 64; ++j) { | ||
| t1 = blocks2[j - 15]; | ||
| s0 = (t1 >>> 7 | t1 << 25) ^ (t1 >>> 18 | t1 << 14) ^ t1 >>> 3; | ||
| t1 = blocks2[j - 2]; | ||
| s1 = (t1 >>> 17 | t1 << 15) ^ (t1 >>> 19 | t1 << 13) ^ t1 >>> 10; | ||
| blocks2[j] = blocks2[j - 16] + s0 + blocks2[j - 7] + s1 << 0; | ||
| } | ||
| bc = b & c; | ||
| for (j = 0; j < 64; j += 4) { | ||
| if (this.first) { | ||
| if (this.is224) { | ||
| ab = 300032; | ||
| t1 = blocks2[0] - 1413257819; | ||
| h = t1 - 150054599 << 0; | ||
| d = t1 + 24177077 << 0; | ||
| } else { | ||
| ab = 704751109; | ||
| t1 = blocks2[0] - 210244248; | ||
| h = t1 - 1521486534 << 0; | ||
| d = t1 + 143694565 << 0; | ||
| } | ||
| this.first = false; | ||
| } else { | ||
| s0 = (a >>> 2 | a << 30) ^ (a >>> 13 | a << 19) ^ (a >>> 22 | a << 10); | ||
| s1 = (e >>> 6 | e << 26) ^ (e >>> 11 | e << 21) ^ (e >>> 25 | e << 7); | ||
| ab = a & b; | ||
| maj = ab ^ a & c ^ bc; | ||
| ch = e & f ^ ~e & g; | ||
| t1 = h + s1 + ch + K[j] + blocks2[j]; | ||
| t2 = s0 + maj; | ||
| h = d + t1 << 0; | ||
| d = t1 + t2 << 0; | ||
| } | ||
| s0 = (d >>> 2 | d << 30) ^ (d >>> 13 | d << 19) ^ (d >>> 22 | d << 10); | ||
| s1 = (h >>> 6 | h << 26) ^ (h >>> 11 | h << 21) ^ (h >>> 25 | h << 7); | ||
| da = d & a; | ||
| maj = da ^ d & b ^ ab; | ||
| ch = h & e ^ ~h & f; | ||
| t1 = g + s1 + ch + K[j + 1] + blocks2[j + 1]; | ||
| t2 = s0 + maj; | ||
| g = c + t1 << 0; | ||
| c = t1 + t2 << 0; | ||
| s0 = (c >>> 2 | c << 30) ^ (c >>> 13 | c << 19) ^ (c >>> 22 | c << 10); | ||
| s1 = (g >>> 6 | g << 26) ^ (g >>> 11 | g << 21) ^ (g >>> 25 | g << 7); | ||
| cd = c & d; | ||
| maj = cd ^ c & a ^ da; | ||
| ch = g & h ^ ~g & e; | ||
| t1 = f + s1 + ch + K[j + 2] + blocks2[j + 2]; | ||
| t2 = s0 + maj; | ||
| f = b + t1 << 0; | ||
| b = t1 + t2 << 0; | ||
| s0 = (b >>> 2 | b << 30) ^ (b >>> 13 | b << 19) ^ (b >>> 22 | b << 10); | ||
| s1 = (f >>> 6 | f << 26) ^ (f >>> 11 | f << 21) ^ (f >>> 25 | f << 7); | ||
| bc = b & c; | ||
| maj = bc ^ b & d ^ cd; | ||
| ch = f & g ^ ~f & h; | ||
| t1 = e + s1 + ch + K[j + 3] + blocks2[j + 3]; | ||
| t2 = s0 + maj; | ||
| e = a + t1 << 0; | ||
| a = t1 + t2 << 0; | ||
| this.chromeBugWorkAround = true; | ||
| } | ||
| this.h0 = this.h0 + a << 0; | ||
| this.h1 = this.h1 + b << 0; | ||
| this.h2 = this.h2 + c << 0; | ||
| this.h3 = this.h3 + d << 0; | ||
| this.h4 = this.h4 + e << 0; | ||
| this.h5 = this.h5 + f << 0; | ||
| this.h6 = this.h6 + g << 0; | ||
| this.h7 = this.h7 + h << 0; | ||
| }; | ||
| Sha256.prototype.hex = function() { | ||
| this.finalize(); | ||
| var h0 = this.h0, h1 = this.h1, h2 = this.h2, h3 = this.h3, h4 = this.h4, h5 = this.h5, h6 = this.h6, h7 = this.h7; | ||
| var hex = HEX_CHARS[h0 >>> 28 & 15] + HEX_CHARS[h0 >>> 24 & 15] + HEX_CHARS[h0 >>> 20 & 15] + HEX_CHARS[h0 >>> 16 & 15] + HEX_CHARS[h0 >>> 12 & 15] + HEX_CHARS[h0 >>> 8 & 15] + HEX_CHARS[h0 >>> 4 & 15] + HEX_CHARS[h0 & 15] + HEX_CHARS[h1 >>> 28 & 15] + HEX_CHARS[h1 >>> 24 & 15] + HEX_CHARS[h1 >>> 20 & 15] + HEX_CHARS[h1 >>> 16 & 15] + HEX_CHARS[h1 >>> 12 & 15] + HEX_CHARS[h1 >>> 8 & 15] + HEX_CHARS[h1 >>> 4 & 15] + HEX_CHARS[h1 & 15] + HEX_CHARS[h2 >>> 28 & 15] + HEX_CHARS[h2 >>> 24 & 15] + HEX_CHARS[h2 >>> 20 & 15] + HEX_CHARS[h2 >>> 16 & 15] + HEX_CHARS[h2 >>> 12 & 15] + HEX_CHARS[h2 >>> 8 & 15] + HEX_CHARS[h2 >>> 4 & 15] + HEX_CHARS[h2 & 15] + HEX_CHARS[h3 >>> 28 & 15] + HEX_CHARS[h3 >>> 24 & 15] + HEX_CHARS[h3 >>> 20 & 15] + HEX_CHARS[h3 >>> 16 & 15] + HEX_CHARS[h3 >>> 12 & 15] + HEX_CHARS[h3 >>> 8 & 15] + HEX_CHARS[h3 >>> 4 & 15] + HEX_CHARS[h3 & 15] + HEX_CHARS[h4 >>> 28 & 15] + HEX_CHARS[h4 >>> 24 & 15] + HEX_CHARS[h4 >>> 20 & 15] + HEX_CHARS[h4 >>> 16 & 15] + HEX_CHARS[h4 >>> 12 & 15] + HEX_CHARS[h4 >>> 8 & 15] + HEX_CHARS[h4 >>> 4 & 15] + HEX_CHARS[h4 & 15] + HEX_CHARS[h5 >>> 28 & 15] + HEX_CHARS[h5 >>> 24 & 15] + HEX_CHARS[h5 >>> 20 & 15] + HEX_CHARS[h5 >>> 16 & 15] + HEX_CHARS[h5 >>> 12 & 15] + HEX_CHARS[h5 >>> 8 & 15] + HEX_CHARS[h5 >>> 4 & 15] + HEX_CHARS[h5 & 15] + HEX_CHARS[h6 >>> 28 & 15] + HEX_CHARS[h6 >>> 24 & 15] + HEX_CHARS[h6 >>> 20 & 15] + HEX_CHARS[h6 >>> 16 & 15] + HEX_CHARS[h6 >>> 12 & 15] + HEX_CHARS[h6 >>> 8 & 15] + HEX_CHARS[h6 >>> 4 & 15] + HEX_CHARS[h6 & 15]; | ||
| if (!this.is224) { | ||
| hex += HEX_CHARS[h7 >>> 28 & 15] + HEX_CHARS[h7 >>> 24 & 15] + HEX_CHARS[h7 >>> 20 & 15] + HEX_CHARS[h7 >>> 16 & 15] + HEX_CHARS[h7 >>> 12 & 15] + HEX_CHARS[h7 >>> 8 & 15] + HEX_CHARS[h7 >>> 4 & 15] + HEX_CHARS[h7 & 15]; | ||
| } | ||
| return hex; | ||
| }; | ||
| Sha256.prototype.toString = Sha256.prototype.hex; | ||
| Sha256.prototype.digest = function() { | ||
| this.finalize(); | ||
| var h0 = this.h0, h1 = this.h1, h2 = this.h2, h3 = this.h3, h4 = this.h4, h5 = this.h5, h6 = this.h6, h7 = this.h7; | ||
| var arr = [ | ||
| h0 >>> 24 & 255, | ||
| h0 >>> 16 & 255, | ||
| h0 >>> 8 & 255, | ||
| h0 & 255, | ||
| h1 >>> 24 & 255, | ||
| h1 >>> 16 & 255, | ||
| h1 >>> 8 & 255, | ||
| h1 & 255, | ||
| h2 >>> 24 & 255, | ||
| h2 >>> 16 & 255, | ||
| h2 >>> 8 & 255, | ||
| h2 & 255, | ||
| h3 >>> 24 & 255, | ||
| h3 >>> 16 & 255, | ||
| h3 >>> 8 & 255, | ||
| h3 & 255, | ||
| h4 >>> 24 & 255, | ||
| h4 >>> 16 & 255, | ||
| h4 >>> 8 & 255, | ||
| h4 & 255, | ||
| h5 >>> 24 & 255, | ||
| h5 >>> 16 & 255, | ||
| h5 >>> 8 & 255, | ||
| h5 & 255, | ||
| h6 >>> 24 & 255, | ||
| h6 >>> 16 & 255, | ||
| h6 >>> 8 & 255, | ||
| h6 & 255 | ||
| ]; | ||
| if (!this.is224) { | ||
| arr.push(h7 >>> 24 & 255, h7 >>> 16 & 255, h7 >>> 8 & 255, h7 & 255); | ||
| } | ||
| return arr; | ||
| }; | ||
| Sha256.prototype.array = Sha256.prototype.digest; | ||
| Sha256.prototype.arrayBuffer = function() { | ||
| this.finalize(); | ||
| var buffer = new ArrayBuffer(this.is224 ? 28 : 32); | ||
| var dataView = new DataView(buffer); | ||
| dataView.setUint32(0, this.h0); | ||
| dataView.setUint32(4, this.h1); | ||
| dataView.setUint32(8, this.h2); | ||
| dataView.setUint32(12, this.h3); | ||
| dataView.setUint32(16, this.h4); | ||
| dataView.setUint32(20, this.h5); | ||
| dataView.setUint32(24, this.h6); | ||
| if (!this.is224) { | ||
| dataView.setUint32(28, this.h7); | ||
| } | ||
| return buffer; | ||
| }; | ||
| function HmacSha256(key, is224, sharedMemory) { | ||
| var i, type = typeof key; | ||
| if (type === "string") { | ||
| var bytes = [], length = key.length, index = 0, code; | ||
| for (i = 0; i < length; ++i) { | ||
| code = key.charCodeAt(i); | ||
| if (code < 128) { | ||
| bytes[index++] = code; | ||
| } else if (code < 2048) { | ||
| bytes[index++] = 192 | code >>> 6; | ||
| bytes[index++] = 128 | code & 63; | ||
| } else if (code < 55296 || code >= 57344) { | ||
| bytes[index++] = 224 | code >>> 12; | ||
| bytes[index++] = 128 | code >>> 6 & 63; | ||
| bytes[index++] = 128 | code & 63; | ||
| } else { | ||
| code = 65536 + ((code & 1023) << 10 | key.charCodeAt(++i) & 1023); | ||
| bytes[index++] = 240 | code >>> 18; | ||
| bytes[index++] = 128 | code >>> 12 & 63; | ||
| bytes[index++] = 128 | code >>> 6 & 63; | ||
| bytes[index++] = 128 | code & 63; | ||
| } | ||
| } | ||
| key = bytes; | ||
| } else { | ||
| if (type === "object") { | ||
| if (key === null) { | ||
| throw new Error(ERROR); | ||
| } else if (ARRAY_BUFFER && key.constructor === ArrayBuffer) { | ||
| key = new Uint8Array(key); | ||
| } else if (!Array.isArray(key)) { | ||
| if (!ARRAY_BUFFER || !ArrayBuffer.isView(key)) { | ||
| throw new Error(ERROR); | ||
| } | ||
| } | ||
| } else { | ||
| throw new Error(ERROR); | ||
| } | ||
| } | ||
| if (key.length > 64) { | ||
| key = new Sha256(is224, true).update(key).array(); | ||
| } | ||
| var oKeyPad = [], iKeyPad = []; | ||
| for (i = 0; i < 64; ++i) { | ||
| var b = key[i] || 0; | ||
| oKeyPad[i] = 92 ^ b; | ||
| iKeyPad[i] = 54 ^ b; | ||
| } | ||
| Sha256.call(this, is224, sharedMemory); | ||
| this.update(iKeyPad); | ||
| this.oKeyPad = oKeyPad; | ||
| this.inner = true; | ||
| this.sharedMemory = sharedMemory; | ||
| } | ||
| HmacSha256.prototype = new Sha256(); | ||
| HmacSha256.prototype.finalize = function() { | ||
| Sha256.prototype.finalize.call(this); | ||
| if (this.inner) { | ||
| this.inner = false; | ||
| var innerHash = this.array(); | ||
| Sha256.call(this, this.is224, this.sharedMemory); | ||
| this.update(this.oKeyPad); | ||
| this.update(innerHash); | ||
| Sha256.prototype.finalize.call(this); | ||
| } | ||
| }; | ||
| var exports2 = createMethod(); | ||
| exports2.sha256 = exports2; | ||
| exports2.sha224 = createMethod(true); | ||
| exports2.sha256.hmac = createHmacMethod(); | ||
| exports2.sha224.hmac = createHmacMethod(true); | ||
| if (COMMON_JS) { | ||
| module2.exports = exports2; | ||
| } else { | ||
| root.sha256 = exports2.sha256; | ||
| root.sha224 = exports2.sha224; | ||
| if (AMD) { | ||
| define(function() { | ||
| return exports2; | ||
| }); | ||
| } | ||
| } | ||
| })(); | ||
| } | ||
| }); | ||
| // src/constants/index.ts | ||
@@ -638,3 +99,4 @@ var CONTAINER_MINI_HEIGHT = 3; | ||
| // src/utils.ts | ||
| var import_js_sha256 = __toESM(require_sha256()); | ||
| var import_js_sha256 = require("js-sha256"); | ||
| var import_debug = __toESM(require("debug")); | ||
| var hashMap = {}; | ||
@@ -797,6 +259,6 @@ function generateHashId(rect, content = "") { | ||
| } | ||
| if (el == null ? void 0 : el.contains(topElement)) { | ||
| if (el?.contains(topElement)) { | ||
| return false; | ||
| } | ||
| if (topElement == null ? void 0 : topElement.contains(el)) { | ||
| if (topElement?.contains(el)) { | ||
| return false; | ||
@@ -863,3 +325,3 @@ } | ||
| const parentUntilNonStatic = (currentNode) => { | ||
| let parent2 = currentNode == null ? void 0 : currentNode.parentElement; | ||
| let parent2 = currentNode?.parentElement; | ||
| while (parent2) { | ||
@@ -930,24 +392,4 @@ const style = currentWindow.getComputedStyle(parent2); | ||
| } | ||
| var nodeHashCacheList = []; | ||
| if (typeof window !== "undefined") { | ||
| window.midsceneNodeHashCacheList = window.midsceneNodeHashCacheList || []; | ||
| nodeHashCacheList = window.midsceneNodeHashCacheList; | ||
| } | ||
| function resetNodeHashCacheList() { | ||
| if (typeof window !== "undefined") { | ||
| nodeHashCacheList = window.midsceneNodeHashCacheList || []; | ||
| window.midsceneNodeHashCacheList = []; | ||
| } else { | ||
| nodeHashCacheList = []; | ||
| } | ||
| } | ||
| function midsceneGenerateHash(node, content, rect) { | ||
| var _a; | ||
| if (node && nodeHashCacheList.find((item) => item.node === node)) { | ||
| return ((_a = nodeHashCacheList.find((item) => item.node === node)) == null ? void 0 : _a.id) || ""; | ||
| } | ||
| const slicedHash = generateHashId(rect, content); | ||
| if (node && typeof window !== "undefined") { | ||
| window.midsceneNodeHashCacheList.push({ node, id: slicedHash }); | ||
| } | ||
| return slicedHash; | ||
@@ -984,3 +426,2 @@ } | ||
| function collectElementInfo(node, currentWindow, currentDocument, baseZoom = 1, basePoint = { left: 0, top: 0 }) { | ||
| var _a; | ||
| const rect = visibleRect(node, currentWindow, currentDocument, baseZoom); | ||
@@ -1016,6 +457,7 @@ if (!rect || rect.width < CONTAINER_MINI_WIDTH || rect.height < CONTAINER_MINI_HEIGHT) { | ||
| indexId: indexId++, | ||
| attributes: __spreadProps(__spreadValues({}, attributes), { | ||
| attributes: { | ||
| ...attributes, | ||
| htmlTagName: `<${tagName}>`, | ||
| nodeType: "FORM_ITEM Node" /* FORM_ITEM */ | ||
| }), | ||
| }, | ||
| content: valueContent.trim(), | ||
@@ -1045,6 +487,7 @@ rect, | ||
| locator: selector, | ||
| attributes: __spreadProps(__spreadValues({}, attributes), { | ||
| attributes: { | ||
| ...attributes, | ||
| htmlTagName: tagNameOfNode(node), | ||
| nodeType: "BUTTON Node" /* BUTTON */ | ||
| }), | ||
| }, | ||
| content, | ||
@@ -1071,8 +514,10 @@ rect, | ||
| locator: selector, | ||
| attributes: __spreadProps(__spreadValues(__spreadValues({}, attributes), node.nodeName.toLowerCase() === "svg" ? { | ||
| svgContent: "true" | ||
| } : {}), { | ||
| attributes: { | ||
| ...attributes, | ||
| ...node.nodeName.toLowerCase() === "svg" ? { | ||
| svgContent: "true" | ||
| } : {}, | ||
| nodeType: "IMG Node" /* IMG */, | ||
| htmlTagName: tagNameOfNode(node) | ||
| }), | ||
| }, | ||
| nodeType: "IMG Node" /* IMG */, | ||
@@ -1092,3 +537,3 @@ content: "", | ||
| if (isTextElement(node)) { | ||
| const text = (_a = node.textContent) == null ? void 0 : _a.trim().replace(/\n+/g, " "); | ||
| const text = node.textContent?.trim().replace(/\n+/g, " "); | ||
| if (!text) { | ||
@@ -1110,6 +555,7 @@ return null; | ||
| locator: selector, | ||
| attributes: __spreadProps(__spreadValues({}, attributes), { | ||
| attributes: { | ||
| ...attributes, | ||
| nodeType: "TEXT Node" /* TEXT */, | ||
| htmlTagName: tagNameOfNode(node) | ||
| }), | ||
| }, | ||
| center: [ | ||
@@ -1138,6 +584,7 @@ Math.round(rect.left + rect.width / 2), | ||
| locator: selector, | ||
| attributes: __spreadProps(__spreadValues({}, attributes), { | ||
| attributes: { | ||
| ...attributes, | ||
| nodeType: "CONTAINER Node" /* CONTAINER */, | ||
| htmlTagName: tagNameOfNode(node) | ||
| }), | ||
| }, | ||
| content: "", | ||
@@ -1173,3 +620,2 @@ rect, | ||
| setDebugMode(debugMode2); | ||
| resetNodeHashCacheList(); | ||
| indexId = 0; | ||
@@ -1202,3 +648,3 @@ const topDocument = getTopDocument(); | ||
| }; | ||
| if ((elementInfo == null ? void 0 : elementInfo.nodeType) === "BUTTON Node" /* BUTTON */ || (elementInfo == null ? void 0 : elementInfo.nodeType) === "IMG Node" /* IMG */ || (elementInfo == null ? void 0 : elementInfo.nodeType) === "TEXT Node" /* TEXT */ || (elementInfo == null ? void 0 : elementInfo.nodeType) === "FORM_ITEM Node" /* FORM_ITEM */ || (elementInfo == null ? void 0 : elementInfo.nodeType) === "CONTAINER Node" /* CONTAINER */) { | ||
| if (elementInfo?.nodeType === "BUTTON Node" /* BUTTON */ || elementInfo?.nodeType === "IMG Node" /* IMG */ || elementInfo?.nodeType === "TEXT Node" /* TEXT */ || elementInfo?.nodeType === "FORM_ITEM Node" /* FORM_ITEM */ || elementInfo?.nodeType === "CONTAINER Node" /* CONTAINER */) { | ||
| return nodeInfo; | ||
@@ -1264,13 +710,1 @@ } | ||
| setMidsceneVisibleRectOnWindow(); | ||
| /*! Bundled license information: | ||
| js-sha256/src/sha256.js: | ||
| (** | ||
| * [js-sha256]{@link https://github.com/emn178/js-sha256} | ||
| * | ||
| * @version 0.11.0 | ||
| * @author Chen, Yi-Cyuan [emn178@gmail.com] | ||
| * @copyright Chen, Yi-Cyuan 2014-2024 | ||
| * @license MIT | ||
| *) | ||
| */ |
+36
-605
| "use strict"; | ||
| var __create = Object.create; | ||
| var __defProp = Object.defineProperty; | ||
| var __defProps = Object.defineProperties; | ||
| var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
| var __getOwnPropDescs = Object.getOwnPropertyDescriptors; | ||
| var __getOwnPropNames = Object.getOwnPropertyNames; | ||
| var __getOwnPropSymbols = Object.getOwnPropertySymbols; | ||
| var __getProtoOf = Object.getPrototypeOf; | ||
| var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
| var __propIsEnum = Object.prototype.propertyIsEnumerable; | ||
| var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; | ||
| var __spreadValues = (a, b) => { | ||
| for (var prop in b || (b = {})) | ||
| if (__hasOwnProp.call(b, prop)) | ||
| __defNormalProp(a, prop, b[prop]); | ||
| if (__getOwnPropSymbols) | ||
| for (var prop of __getOwnPropSymbols(b)) { | ||
| if (__propIsEnum.call(b, prop)) | ||
| __defNormalProp(a, prop, b[prop]); | ||
| } | ||
| return a; | ||
| }; | ||
| var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b)); | ||
| var __commonJS = (cb, mod) => function __require() { | ||
| return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports; | ||
| }; | ||
| var __export = (target, all) => { | ||
@@ -50,521 +30,2 @@ for (var name in all) | ||
| // ../../node_modules/.pnpm/js-sha256@0.11.0/node_modules/js-sha256/src/sha256.js | ||
| var require_sha256 = __commonJS({ | ||
| "../../node_modules/.pnpm/js-sha256@0.11.0/node_modules/js-sha256/src/sha256.js"(exports, module2) { | ||
| "use strict"; | ||
| (function() { | ||
| "use strict"; | ||
| var ERROR = "input is invalid type"; | ||
| var WINDOW = typeof window === "object"; | ||
| var root = WINDOW ? window : {}; | ||
| if (root.JS_SHA256_NO_WINDOW) { | ||
| WINDOW = false; | ||
| } | ||
| var WEB_WORKER = !WINDOW && typeof self === "object"; | ||
| var NODE_JS = !root.JS_SHA256_NO_NODE_JS && typeof process === "object" && process.versions && process.versions.node; | ||
| if (NODE_JS) { | ||
| root = global; | ||
| } else if (WEB_WORKER) { | ||
| root = self; | ||
| } | ||
| var COMMON_JS = !root.JS_SHA256_NO_COMMON_JS && typeof module2 === "object" && module2.exports; | ||
| var AMD = typeof define === "function" && define.amd; | ||
| var ARRAY_BUFFER = !root.JS_SHA256_NO_ARRAY_BUFFER && typeof ArrayBuffer !== "undefined"; | ||
| var HEX_CHARS = "0123456789abcdef".split(""); | ||
| var EXTRA = [-2147483648, 8388608, 32768, 128]; | ||
| var SHIFT = [24, 16, 8, 0]; | ||
| var K = [ | ||
| 1116352408, | ||
| 1899447441, | ||
| 3049323471, | ||
| 3921009573, | ||
| 961987163, | ||
| 1508970993, | ||
| 2453635748, | ||
| 2870763221, | ||
| 3624381080, | ||
| 310598401, | ||
| 607225278, | ||
| 1426881987, | ||
| 1925078388, | ||
| 2162078206, | ||
| 2614888103, | ||
| 3248222580, | ||
| 3835390401, | ||
| 4022224774, | ||
| 264347078, | ||
| 604807628, | ||
| 770255983, | ||
| 1249150122, | ||
| 1555081692, | ||
| 1996064986, | ||
| 2554220882, | ||
| 2821834349, | ||
| 2952996808, | ||
| 3210313671, | ||
| 3336571891, | ||
| 3584528711, | ||
| 113926993, | ||
| 338241895, | ||
| 666307205, | ||
| 773529912, | ||
| 1294757372, | ||
| 1396182291, | ||
| 1695183700, | ||
| 1986661051, | ||
| 2177026350, | ||
| 2456956037, | ||
| 2730485921, | ||
| 2820302411, | ||
| 3259730800, | ||
| 3345764771, | ||
| 3516065817, | ||
| 3600352804, | ||
| 4094571909, | ||
| 275423344, | ||
| 430227734, | ||
| 506948616, | ||
| 659060556, | ||
| 883997877, | ||
| 958139571, | ||
| 1322822218, | ||
| 1537002063, | ||
| 1747873779, | ||
| 1955562222, | ||
| 2024104815, | ||
| 2227730452, | ||
| 2361852424, | ||
| 2428436474, | ||
| 2756734187, | ||
| 3204031479, | ||
| 3329325298 | ||
| ]; | ||
| var OUTPUT_TYPES = ["hex", "array", "digest", "arrayBuffer"]; | ||
| var blocks = []; | ||
| if (root.JS_SHA256_NO_NODE_JS || !Array.isArray) { | ||
| Array.isArray = function(obj) { | ||
| return Object.prototype.toString.call(obj) === "[object Array]"; | ||
| }; | ||
| } | ||
| if (ARRAY_BUFFER && (root.JS_SHA256_NO_ARRAY_BUFFER_IS_VIEW || !ArrayBuffer.isView)) { | ||
| ArrayBuffer.isView = function(obj) { | ||
| return typeof obj === "object" && obj.buffer && obj.buffer.constructor === ArrayBuffer; | ||
| }; | ||
| } | ||
| var createOutputMethod = function(outputType, is224) { | ||
| return function(message) { | ||
| return new Sha256(is224, true).update(message)[outputType](); | ||
| }; | ||
| }; | ||
| var createMethod = function(is224) { | ||
| var method = createOutputMethod("hex", is224); | ||
| if (NODE_JS) { | ||
| method = nodeWrap(method, is224); | ||
| } | ||
| method.create = function() { | ||
| return new Sha256(is224); | ||
| }; | ||
| method.update = function(message) { | ||
| return method.create().update(message); | ||
| }; | ||
| for (var i = 0; i < OUTPUT_TYPES.length; ++i) { | ||
| var type = OUTPUT_TYPES[i]; | ||
| method[type] = createOutputMethod(type, is224); | ||
| } | ||
| return method; | ||
| }; | ||
| var nodeWrap = function(method, is224) { | ||
| var crypto = require("crypto"); | ||
| var Buffer2 = require("buffer").Buffer; | ||
| var algorithm = is224 ? "sha224" : "sha256"; | ||
| var bufferFrom; | ||
| if (Buffer2.from && !root.JS_SHA256_NO_BUFFER_FROM) { | ||
| bufferFrom = Buffer2.from; | ||
| } else { | ||
| bufferFrom = function(message) { | ||
| return new Buffer2(message); | ||
| }; | ||
| } | ||
| var nodeMethod = function(message) { | ||
| if (typeof message === "string") { | ||
| return crypto.createHash(algorithm).update(message, "utf8").digest("hex"); | ||
| } else { | ||
| if (message === null || message === void 0) { | ||
| throw new Error(ERROR); | ||
| } else if (message.constructor === ArrayBuffer) { | ||
| message = new Uint8Array(message); | ||
| } | ||
| } | ||
| if (Array.isArray(message) || ArrayBuffer.isView(message) || message.constructor === Buffer2) { | ||
| return crypto.createHash(algorithm).update(bufferFrom(message)).digest("hex"); | ||
| } else { | ||
| return method(message); | ||
| } | ||
| }; | ||
| return nodeMethod; | ||
| }; | ||
| var createHmacOutputMethod = function(outputType, is224) { | ||
| return function(key, message) { | ||
| return new HmacSha256(key, is224, true).update(message)[outputType](); | ||
| }; | ||
| }; | ||
| var createHmacMethod = function(is224) { | ||
| var method = createHmacOutputMethod("hex", is224); | ||
| method.create = function(key) { | ||
| return new HmacSha256(key, is224); | ||
| }; | ||
| method.update = function(key, message) { | ||
| return method.create(key).update(message); | ||
| }; | ||
| for (var i = 0; i < OUTPUT_TYPES.length; ++i) { | ||
| var type = OUTPUT_TYPES[i]; | ||
| method[type] = createHmacOutputMethod(type, is224); | ||
| } | ||
| return method; | ||
| }; | ||
| function Sha256(is224, sharedMemory) { | ||
| if (sharedMemory) { | ||
| blocks[0] = blocks[16] = blocks[1] = blocks[2] = blocks[3] = blocks[4] = blocks[5] = blocks[6] = blocks[7] = blocks[8] = blocks[9] = blocks[10] = blocks[11] = blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0; | ||
| this.blocks = blocks; | ||
| } else { | ||
| this.blocks = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; | ||
| } | ||
| if (is224) { | ||
| this.h0 = 3238371032; | ||
| this.h1 = 914150663; | ||
| this.h2 = 812702999; | ||
| this.h3 = 4144912697; | ||
| this.h4 = 4290775857; | ||
| this.h5 = 1750603025; | ||
| this.h6 = 1694076839; | ||
| this.h7 = 3204075428; | ||
| } else { | ||
| this.h0 = 1779033703; | ||
| this.h1 = 3144134277; | ||
| this.h2 = 1013904242; | ||
| this.h3 = 2773480762; | ||
| this.h4 = 1359893119; | ||
| this.h5 = 2600822924; | ||
| this.h6 = 528734635; | ||
| this.h7 = 1541459225; | ||
| } | ||
| this.block = this.start = this.bytes = this.hBytes = 0; | ||
| this.finalized = this.hashed = false; | ||
| this.first = true; | ||
| this.is224 = is224; | ||
| } | ||
| Sha256.prototype.update = function(message) { | ||
| if (this.finalized) { | ||
| return; | ||
| } | ||
| var notString, type = typeof message; | ||
| if (type !== "string") { | ||
| if (type === "object") { | ||
| if (message === null) { | ||
| throw new Error(ERROR); | ||
| } else if (ARRAY_BUFFER && message.constructor === ArrayBuffer) { | ||
| message = new Uint8Array(message); | ||
| } else if (!Array.isArray(message)) { | ||
| if (!ARRAY_BUFFER || !ArrayBuffer.isView(message)) { | ||
| throw new Error(ERROR); | ||
| } | ||
| } | ||
| } else { | ||
| throw new Error(ERROR); | ||
| } | ||
| notString = true; | ||
| } | ||
| var code, index = 0, i, length = message.length, blocks2 = this.blocks; | ||
| while (index < length) { | ||
| if (this.hashed) { | ||
| this.hashed = false; | ||
| blocks2[0] = this.block; | ||
| this.block = blocks2[16] = blocks2[1] = blocks2[2] = blocks2[3] = blocks2[4] = blocks2[5] = blocks2[6] = blocks2[7] = blocks2[8] = blocks2[9] = blocks2[10] = blocks2[11] = blocks2[12] = blocks2[13] = blocks2[14] = blocks2[15] = 0; | ||
| } | ||
| if (notString) { | ||
| for (i = this.start; index < length && i < 64; ++index) { | ||
| blocks2[i >>> 2] |= message[index] << SHIFT[i++ & 3]; | ||
| } | ||
| } else { | ||
| for (i = this.start; index < length && i < 64; ++index) { | ||
| code = message.charCodeAt(index); | ||
| if (code < 128) { | ||
| blocks2[i >>> 2] |= code << SHIFT[i++ & 3]; | ||
| } else if (code < 2048) { | ||
| blocks2[i >>> 2] |= (192 | code >>> 6) << SHIFT[i++ & 3]; | ||
| blocks2[i >>> 2] |= (128 | code & 63) << SHIFT[i++ & 3]; | ||
| } else if (code < 55296 || code >= 57344) { | ||
| blocks2[i >>> 2] |= (224 | code >>> 12) << SHIFT[i++ & 3]; | ||
| blocks2[i >>> 2] |= (128 | code >>> 6 & 63) << SHIFT[i++ & 3]; | ||
| blocks2[i >>> 2] |= (128 | code & 63) << SHIFT[i++ & 3]; | ||
| } else { | ||
| code = 65536 + ((code & 1023) << 10 | message.charCodeAt(++index) & 1023); | ||
| blocks2[i >>> 2] |= (240 | code >>> 18) << SHIFT[i++ & 3]; | ||
| blocks2[i >>> 2] |= (128 | code >>> 12 & 63) << SHIFT[i++ & 3]; | ||
| blocks2[i >>> 2] |= (128 | code >>> 6 & 63) << SHIFT[i++ & 3]; | ||
| blocks2[i >>> 2] |= (128 | code & 63) << SHIFT[i++ & 3]; | ||
| } | ||
| } | ||
| } | ||
| this.lastByteIndex = i; | ||
| this.bytes += i - this.start; | ||
| if (i >= 64) { | ||
| this.block = blocks2[16]; | ||
| this.start = i - 64; | ||
| this.hash(); | ||
| this.hashed = true; | ||
| } else { | ||
| this.start = i; | ||
| } | ||
| } | ||
| if (this.bytes > 4294967295) { | ||
| this.hBytes += this.bytes / 4294967296 << 0; | ||
| this.bytes = this.bytes % 4294967296; | ||
| } | ||
| return this; | ||
| }; | ||
| Sha256.prototype.finalize = function() { | ||
| if (this.finalized) { | ||
| return; | ||
| } | ||
| this.finalized = true; | ||
| var blocks2 = this.blocks, i = this.lastByteIndex; | ||
| blocks2[16] = this.block; | ||
| blocks2[i >>> 2] |= EXTRA[i & 3]; | ||
| this.block = blocks2[16]; | ||
| if (i >= 56) { | ||
| if (!this.hashed) { | ||
| this.hash(); | ||
| } | ||
| blocks2[0] = this.block; | ||
| blocks2[16] = blocks2[1] = blocks2[2] = blocks2[3] = blocks2[4] = blocks2[5] = blocks2[6] = blocks2[7] = blocks2[8] = blocks2[9] = blocks2[10] = blocks2[11] = blocks2[12] = blocks2[13] = blocks2[14] = blocks2[15] = 0; | ||
| } | ||
| blocks2[14] = this.hBytes << 3 | this.bytes >>> 29; | ||
| blocks2[15] = this.bytes << 3; | ||
| this.hash(); | ||
| }; | ||
| Sha256.prototype.hash = function() { | ||
| var a = this.h0, b = this.h1, c = this.h2, d = this.h3, e = this.h4, f = this.h5, g = this.h6, h = this.h7, blocks2 = this.blocks, j, s0, s1, maj, t1, t2, ch, ab, da, cd, bc; | ||
| for (j = 16; j < 64; ++j) { | ||
| t1 = blocks2[j - 15]; | ||
| s0 = (t1 >>> 7 | t1 << 25) ^ (t1 >>> 18 | t1 << 14) ^ t1 >>> 3; | ||
| t1 = blocks2[j - 2]; | ||
| s1 = (t1 >>> 17 | t1 << 15) ^ (t1 >>> 19 | t1 << 13) ^ t1 >>> 10; | ||
| blocks2[j] = blocks2[j - 16] + s0 + blocks2[j - 7] + s1 << 0; | ||
| } | ||
| bc = b & c; | ||
| for (j = 0; j < 64; j += 4) { | ||
| if (this.first) { | ||
| if (this.is224) { | ||
| ab = 300032; | ||
| t1 = blocks2[0] - 1413257819; | ||
| h = t1 - 150054599 << 0; | ||
| d = t1 + 24177077 << 0; | ||
| } else { | ||
| ab = 704751109; | ||
| t1 = blocks2[0] - 210244248; | ||
| h = t1 - 1521486534 << 0; | ||
| d = t1 + 143694565 << 0; | ||
| } | ||
| this.first = false; | ||
| } else { | ||
| s0 = (a >>> 2 | a << 30) ^ (a >>> 13 | a << 19) ^ (a >>> 22 | a << 10); | ||
| s1 = (e >>> 6 | e << 26) ^ (e >>> 11 | e << 21) ^ (e >>> 25 | e << 7); | ||
| ab = a & b; | ||
| maj = ab ^ a & c ^ bc; | ||
| ch = e & f ^ ~e & g; | ||
| t1 = h + s1 + ch + K[j] + blocks2[j]; | ||
| t2 = s0 + maj; | ||
| h = d + t1 << 0; | ||
| d = t1 + t2 << 0; | ||
| } | ||
| s0 = (d >>> 2 | d << 30) ^ (d >>> 13 | d << 19) ^ (d >>> 22 | d << 10); | ||
| s1 = (h >>> 6 | h << 26) ^ (h >>> 11 | h << 21) ^ (h >>> 25 | h << 7); | ||
| da = d & a; | ||
| maj = da ^ d & b ^ ab; | ||
| ch = h & e ^ ~h & f; | ||
| t1 = g + s1 + ch + K[j + 1] + blocks2[j + 1]; | ||
| t2 = s0 + maj; | ||
| g = c + t1 << 0; | ||
| c = t1 + t2 << 0; | ||
| s0 = (c >>> 2 | c << 30) ^ (c >>> 13 | c << 19) ^ (c >>> 22 | c << 10); | ||
| s1 = (g >>> 6 | g << 26) ^ (g >>> 11 | g << 21) ^ (g >>> 25 | g << 7); | ||
| cd = c & d; | ||
| maj = cd ^ c & a ^ da; | ||
| ch = g & h ^ ~g & e; | ||
| t1 = f + s1 + ch + K[j + 2] + blocks2[j + 2]; | ||
| t2 = s0 + maj; | ||
| f = b + t1 << 0; | ||
| b = t1 + t2 << 0; | ||
| s0 = (b >>> 2 | b << 30) ^ (b >>> 13 | b << 19) ^ (b >>> 22 | b << 10); | ||
| s1 = (f >>> 6 | f << 26) ^ (f >>> 11 | f << 21) ^ (f >>> 25 | f << 7); | ||
| bc = b & c; | ||
| maj = bc ^ b & d ^ cd; | ||
| ch = f & g ^ ~f & h; | ||
| t1 = e + s1 + ch + K[j + 3] + blocks2[j + 3]; | ||
| t2 = s0 + maj; | ||
| e = a + t1 << 0; | ||
| a = t1 + t2 << 0; | ||
| this.chromeBugWorkAround = true; | ||
| } | ||
| this.h0 = this.h0 + a << 0; | ||
| this.h1 = this.h1 + b << 0; | ||
| this.h2 = this.h2 + c << 0; | ||
| this.h3 = this.h3 + d << 0; | ||
| this.h4 = this.h4 + e << 0; | ||
| this.h5 = this.h5 + f << 0; | ||
| this.h6 = this.h6 + g << 0; | ||
| this.h7 = this.h7 + h << 0; | ||
| }; | ||
| Sha256.prototype.hex = function() { | ||
| this.finalize(); | ||
| var h0 = this.h0, h1 = this.h1, h2 = this.h2, h3 = this.h3, h4 = this.h4, h5 = this.h5, h6 = this.h6, h7 = this.h7; | ||
| var hex = HEX_CHARS[h0 >>> 28 & 15] + HEX_CHARS[h0 >>> 24 & 15] + HEX_CHARS[h0 >>> 20 & 15] + HEX_CHARS[h0 >>> 16 & 15] + HEX_CHARS[h0 >>> 12 & 15] + HEX_CHARS[h0 >>> 8 & 15] + HEX_CHARS[h0 >>> 4 & 15] + HEX_CHARS[h0 & 15] + HEX_CHARS[h1 >>> 28 & 15] + HEX_CHARS[h1 >>> 24 & 15] + HEX_CHARS[h1 >>> 20 & 15] + HEX_CHARS[h1 >>> 16 & 15] + HEX_CHARS[h1 >>> 12 & 15] + HEX_CHARS[h1 >>> 8 & 15] + HEX_CHARS[h1 >>> 4 & 15] + HEX_CHARS[h1 & 15] + HEX_CHARS[h2 >>> 28 & 15] + HEX_CHARS[h2 >>> 24 & 15] + HEX_CHARS[h2 >>> 20 & 15] + HEX_CHARS[h2 >>> 16 & 15] + HEX_CHARS[h2 >>> 12 & 15] + HEX_CHARS[h2 >>> 8 & 15] + HEX_CHARS[h2 >>> 4 & 15] + HEX_CHARS[h2 & 15] + HEX_CHARS[h3 >>> 28 & 15] + HEX_CHARS[h3 >>> 24 & 15] + HEX_CHARS[h3 >>> 20 & 15] + HEX_CHARS[h3 >>> 16 & 15] + HEX_CHARS[h3 >>> 12 & 15] + HEX_CHARS[h3 >>> 8 & 15] + HEX_CHARS[h3 >>> 4 & 15] + HEX_CHARS[h3 & 15] + HEX_CHARS[h4 >>> 28 & 15] + HEX_CHARS[h4 >>> 24 & 15] + HEX_CHARS[h4 >>> 20 & 15] + HEX_CHARS[h4 >>> 16 & 15] + HEX_CHARS[h4 >>> 12 & 15] + HEX_CHARS[h4 >>> 8 & 15] + HEX_CHARS[h4 >>> 4 & 15] + HEX_CHARS[h4 & 15] + HEX_CHARS[h5 >>> 28 & 15] + HEX_CHARS[h5 >>> 24 & 15] + HEX_CHARS[h5 >>> 20 & 15] + HEX_CHARS[h5 >>> 16 & 15] + HEX_CHARS[h5 >>> 12 & 15] + HEX_CHARS[h5 >>> 8 & 15] + HEX_CHARS[h5 >>> 4 & 15] + HEX_CHARS[h5 & 15] + HEX_CHARS[h6 >>> 28 & 15] + HEX_CHARS[h6 >>> 24 & 15] + HEX_CHARS[h6 >>> 20 & 15] + HEX_CHARS[h6 >>> 16 & 15] + HEX_CHARS[h6 >>> 12 & 15] + HEX_CHARS[h6 >>> 8 & 15] + HEX_CHARS[h6 >>> 4 & 15] + HEX_CHARS[h6 & 15]; | ||
| if (!this.is224) { | ||
| hex += HEX_CHARS[h7 >>> 28 & 15] + HEX_CHARS[h7 >>> 24 & 15] + HEX_CHARS[h7 >>> 20 & 15] + HEX_CHARS[h7 >>> 16 & 15] + HEX_CHARS[h7 >>> 12 & 15] + HEX_CHARS[h7 >>> 8 & 15] + HEX_CHARS[h7 >>> 4 & 15] + HEX_CHARS[h7 & 15]; | ||
| } | ||
| return hex; | ||
| }; | ||
| Sha256.prototype.toString = Sha256.prototype.hex; | ||
| Sha256.prototype.digest = function() { | ||
| this.finalize(); | ||
| var h0 = this.h0, h1 = this.h1, h2 = this.h2, h3 = this.h3, h4 = this.h4, h5 = this.h5, h6 = this.h6, h7 = this.h7; | ||
| var arr = [ | ||
| h0 >>> 24 & 255, | ||
| h0 >>> 16 & 255, | ||
| h0 >>> 8 & 255, | ||
| h0 & 255, | ||
| h1 >>> 24 & 255, | ||
| h1 >>> 16 & 255, | ||
| h1 >>> 8 & 255, | ||
| h1 & 255, | ||
| h2 >>> 24 & 255, | ||
| h2 >>> 16 & 255, | ||
| h2 >>> 8 & 255, | ||
| h2 & 255, | ||
| h3 >>> 24 & 255, | ||
| h3 >>> 16 & 255, | ||
| h3 >>> 8 & 255, | ||
| h3 & 255, | ||
| h4 >>> 24 & 255, | ||
| h4 >>> 16 & 255, | ||
| h4 >>> 8 & 255, | ||
| h4 & 255, | ||
| h5 >>> 24 & 255, | ||
| h5 >>> 16 & 255, | ||
| h5 >>> 8 & 255, | ||
| h5 & 255, | ||
| h6 >>> 24 & 255, | ||
| h6 >>> 16 & 255, | ||
| h6 >>> 8 & 255, | ||
| h6 & 255 | ||
| ]; | ||
| if (!this.is224) { | ||
| arr.push(h7 >>> 24 & 255, h7 >>> 16 & 255, h7 >>> 8 & 255, h7 & 255); | ||
| } | ||
| return arr; | ||
| }; | ||
| Sha256.prototype.array = Sha256.prototype.digest; | ||
| Sha256.prototype.arrayBuffer = function() { | ||
| this.finalize(); | ||
| var buffer = new ArrayBuffer(this.is224 ? 28 : 32); | ||
| var dataView = new DataView(buffer); | ||
| dataView.setUint32(0, this.h0); | ||
| dataView.setUint32(4, this.h1); | ||
| dataView.setUint32(8, this.h2); | ||
| dataView.setUint32(12, this.h3); | ||
| dataView.setUint32(16, this.h4); | ||
| dataView.setUint32(20, this.h5); | ||
| dataView.setUint32(24, this.h6); | ||
| if (!this.is224) { | ||
| dataView.setUint32(28, this.h7); | ||
| } | ||
| return buffer; | ||
| }; | ||
| function HmacSha256(key, is224, sharedMemory) { | ||
| var i, type = typeof key; | ||
| if (type === "string") { | ||
| var bytes = [], length = key.length, index = 0, code; | ||
| for (i = 0; i < length; ++i) { | ||
| code = key.charCodeAt(i); | ||
| if (code < 128) { | ||
| bytes[index++] = code; | ||
| } else if (code < 2048) { | ||
| bytes[index++] = 192 | code >>> 6; | ||
| bytes[index++] = 128 | code & 63; | ||
| } else if (code < 55296 || code >= 57344) { | ||
| bytes[index++] = 224 | code >>> 12; | ||
| bytes[index++] = 128 | code >>> 6 & 63; | ||
| bytes[index++] = 128 | code & 63; | ||
| } else { | ||
| code = 65536 + ((code & 1023) << 10 | key.charCodeAt(++i) & 1023); | ||
| bytes[index++] = 240 | code >>> 18; | ||
| bytes[index++] = 128 | code >>> 12 & 63; | ||
| bytes[index++] = 128 | code >>> 6 & 63; | ||
| bytes[index++] = 128 | code & 63; | ||
| } | ||
| } | ||
| key = bytes; | ||
| } else { | ||
| if (type === "object") { | ||
| if (key === null) { | ||
| throw new Error(ERROR); | ||
| } else if (ARRAY_BUFFER && key.constructor === ArrayBuffer) { | ||
| key = new Uint8Array(key); | ||
| } else if (!Array.isArray(key)) { | ||
| if (!ARRAY_BUFFER || !ArrayBuffer.isView(key)) { | ||
| throw new Error(ERROR); | ||
| } | ||
| } | ||
| } else { | ||
| throw new Error(ERROR); | ||
| } | ||
| } | ||
| if (key.length > 64) { | ||
| key = new Sha256(is224, true).update(key).array(); | ||
| } | ||
| var oKeyPad = [], iKeyPad = []; | ||
| for (i = 0; i < 64; ++i) { | ||
| var b = key[i] || 0; | ||
| oKeyPad[i] = 92 ^ b; | ||
| iKeyPad[i] = 54 ^ b; | ||
| } | ||
| Sha256.call(this, is224, sharedMemory); | ||
| this.update(iKeyPad); | ||
| this.oKeyPad = oKeyPad; | ||
| this.inner = true; | ||
| this.sharedMemory = sharedMemory; | ||
| } | ||
| HmacSha256.prototype = new Sha256(); | ||
| HmacSha256.prototype.finalize = function() { | ||
| Sha256.prototype.finalize.call(this); | ||
| if (this.inner) { | ||
| this.inner = false; | ||
| var innerHash = this.array(); | ||
| Sha256.call(this, this.is224, this.sharedMemory); | ||
| this.update(this.oKeyPad); | ||
| this.update(innerHash); | ||
| Sha256.prototype.finalize.call(this); | ||
| } | ||
| }; | ||
| var exports2 = createMethod(); | ||
| exports2.sha256 = exports2; | ||
| exports2.sha224 = createMethod(true); | ||
| exports2.sha256.hmac = createHmacMethod(); | ||
| exports2.sha224.hmac = createHmacMethod(true); | ||
| if (COMMON_JS) { | ||
| module2.exports = exports2; | ||
| } else { | ||
| root.sha256 = exports2.sha256; | ||
| root.sha224 = exports2.sha224; | ||
| if (AMD) { | ||
| define(function() { | ||
| return exports2; | ||
| }); | ||
| } | ||
| } | ||
| })(); | ||
| } | ||
| }); | ||
| // src/extractor/index.ts | ||
@@ -624,3 +85,2 @@ var extractor_exports = {}; | ||
| function buildContentTree(node, indent = 0) { | ||
| var _a; | ||
| let before = ""; | ||
@@ -642,3 +102,3 @@ let contentWithIndent = ""; | ||
| let nodeTypeString; | ||
| if ((_a = node.node.attributes) == null ? void 0 : _a.htmlTagName) { | ||
| if (node.node.attributes?.htmlTagName) { | ||
| nodeTypeString = node.node.attributes.htmlTagName.replace(/[<>]/g, ""); | ||
@@ -780,3 +240,4 @@ } else { | ||
| // src/utils.ts | ||
| var import_js_sha256 = __toESM(require_sha256()); | ||
| var import_js_sha256 = require("js-sha256"); | ||
| var import_debug = __toESM(require("debug")); | ||
| var hashMap = {}; | ||
@@ -939,6 +400,6 @@ function generateHashId(rect, content = "") { | ||
| } | ||
| if (el == null ? void 0 : el.contains(topElement)) { | ||
| if (el?.contains(topElement)) { | ||
| return false; | ||
| } | ||
| if (topElement == null ? void 0 : topElement.contains(el)) { | ||
| if (topElement?.contains(el)) { | ||
| return false; | ||
@@ -1005,3 +466,3 @@ } | ||
| const parentUntilNonStatic = (currentNode) => { | ||
| let parent2 = currentNode == null ? void 0 : currentNode.parentElement; | ||
| let parent2 = currentNode?.parentElement; | ||
| while (parent2) { | ||
@@ -1072,24 +533,4 @@ const style = currentWindow.getComputedStyle(parent2); | ||
| } | ||
| var nodeHashCacheList = []; | ||
| if (typeof window !== "undefined") { | ||
| window.midsceneNodeHashCacheList = window.midsceneNodeHashCacheList || []; | ||
| nodeHashCacheList = window.midsceneNodeHashCacheList; | ||
| } | ||
| function resetNodeHashCacheList() { | ||
| if (typeof window !== "undefined") { | ||
| nodeHashCacheList = window.midsceneNodeHashCacheList || []; | ||
| window.midsceneNodeHashCacheList = []; | ||
| } else { | ||
| nodeHashCacheList = []; | ||
| } | ||
| } | ||
| function midsceneGenerateHash(node, content, rect) { | ||
| var _a; | ||
| if (node && nodeHashCacheList.find((item) => item.node === node)) { | ||
| return ((_a = nodeHashCacheList.find((item) => item.node === node)) == null ? void 0 : _a.id) || ""; | ||
| } | ||
| const slicedHash = generateHashId(rect, content); | ||
| if (node && typeof window !== "undefined") { | ||
| window.midsceneNodeHashCacheList.push({ node, id: slicedHash }); | ||
| } | ||
| return slicedHash; | ||
@@ -1116,3 +557,2 @@ } | ||
| function collectElementInfo(node, currentWindow, currentDocument, baseZoom = 1, basePoint = { left: 0, top: 0 }) { | ||
| var _a; | ||
| const rect = visibleRect(node, currentWindow, currentDocument, baseZoom); | ||
@@ -1148,6 +588,7 @@ if (!rect || rect.width < CONTAINER_MINI_WIDTH || rect.height < CONTAINER_MINI_HEIGHT) { | ||
| indexId: indexId++, | ||
| attributes: __spreadProps(__spreadValues({}, attributes), { | ||
| attributes: { | ||
| ...attributes, | ||
| htmlTagName: `<${tagName}>`, | ||
| nodeType: "FORM_ITEM Node" /* FORM_ITEM */ | ||
| }), | ||
| }, | ||
| content: valueContent.trim(), | ||
@@ -1177,6 +618,7 @@ rect, | ||
| locator: selector, | ||
| attributes: __spreadProps(__spreadValues({}, attributes), { | ||
| attributes: { | ||
| ...attributes, | ||
| htmlTagName: tagNameOfNode(node), | ||
| nodeType: "BUTTON Node" /* BUTTON */ | ||
| }), | ||
| }, | ||
| content, | ||
@@ -1203,8 +645,10 @@ rect, | ||
| locator: selector, | ||
| attributes: __spreadProps(__spreadValues(__spreadValues({}, attributes), node.nodeName.toLowerCase() === "svg" ? { | ||
| svgContent: "true" | ||
| } : {}), { | ||
| attributes: { | ||
| ...attributes, | ||
| ...node.nodeName.toLowerCase() === "svg" ? { | ||
| svgContent: "true" | ||
| } : {}, | ||
| nodeType: "IMG Node" /* IMG */, | ||
| htmlTagName: tagNameOfNode(node) | ||
| }), | ||
| }, | ||
| nodeType: "IMG Node" /* IMG */, | ||
@@ -1224,3 +668,3 @@ content: "", | ||
| if (isTextElement(node)) { | ||
| const text = (_a = node.textContent) == null ? void 0 : _a.trim().replace(/\n+/g, " "); | ||
| const text = node.textContent?.trim().replace(/\n+/g, " "); | ||
| if (!text) { | ||
@@ -1242,6 +686,7 @@ return null; | ||
| locator: selector, | ||
| attributes: __spreadProps(__spreadValues({}, attributes), { | ||
| attributes: { | ||
| ...attributes, | ||
| nodeType: "TEXT Node" /* TEXT */, | ||
| htmlTagName: tagNameOfNode(node) | ||
| }), | ||
| }, | ||
| center: [ | ||
@@ -1270,6 +715,7 @@ Math.round(rect.left + rect.width / 2), | ||
| locator: selector, | ||
| attributes: __spreadProps(__spreadValues({}, attributes), { | ||
| attributes: { | ||
| ...attributes, | ||
| nodeType: "CONTAINER Node" /* CONTAINER */, | ||
| htmlTagName: tagNameOfNode(node) | ||
| }), | ||
| }, | ||
| content: "", | ||
@@ -1309,3 +755,2 @@ rect, | ||
| setDebugMode(debugMode2); | ||
| resetNodeHashCacheList(); | ||
| indexId = 0; | ||
@@ -1338,3 +783,3 @@ const topDocument = getTopDocument(); | ||
| }; | ||
| if ((elementInfo == null ? void 0 : elementInfo.nodeType) === "BUTTON Node" /* BUTTON */ || (elementInfo == null ? void 0 : elementInfo.nodeType) === "IMG Node" /* IMG */ || (elementInfo == null ? void 0 : elementInfo.nodeType) === "TEXT Node" /* TEXT */ || (elementInfo == null ? void 0 : elementInfo.nodeType) === "FORM_ITEM Node" /* FORM_ITEM */ || (elementInfo == null ? void 0 : elementInfo.nodeType) === "CONTAINER Node" /* CONTAINER */) { | ||
| if (elementInfo?.nodeType === "BUTTON Node" /* BUTTON */ || elementInfo?.nodeType === "IMG Node" /* IMG */ || elementInfo?.nodeType === "TEXT Node" /* TEXT */ || elementInfo?.nodeType === "FORM_ITEM Node" /* FORM_ITEM */ || elementInfo?.nodeType === "CONTAINER Node" /* CONTAINER */) { | ||
| return nodeInfo; | ||
@@ -1397,3 +842,2 @@ } | ||
| function getNodeAttributes2(node) { | ||
| var _a; | ||
| const attrs = {}; | ||
@@ -1404,3 +848,3 @@ if (node && node.nodeType === 1) { | ||
| const attr = element.attributes[i]; | ||
| attrs[attr.nodeName] = (_a = attr.nodeValue) != null ? _a : ""; | ||
| attrs[attr.nodeName] = attr.nodeValue ?? ""; | ||
| } | ||
@@ -1411,7 +855,6 @@ } | ||
| function getRect2(attributes) { | ||
| var _a, _b, _c, _d; | ||
| const x = Math.round(Number.parseFloat((_a = attributes.x) != null ? _a : "0")); | ||
| const y = Math.round(Number.parseFloat((_b = attributes.y) != null ? _b : "0")); | ||
| const width = Math.round(Number.parseFloat((_c = attributes.width) != null ? _c : "0")); | ||
| const height = Math.round(Number.parseFloat((_d = attributes.height) != null ? _d : "0")); | ||
| const x = Math.round(Number.parseFloat(attributes.x ?? "0")); | ||
| const y = Math.round(Number.parseFloat(attributes.y ?? "0")); | ||
| const width = Math.round(Number.parseFloat(attributes.width ?? "0")); | ||
| const height = Math.round(Number.parseFloat(attributes.height ?? "0")); | ||
| return { | ||
@@ -1425,5 +868,4 @@ left: Math.max(0, Math.floor(x)), | ||
| function validTextNodeContent(node) { | ||
| var _a; | ||
| if (node.nodeType === 3) { | ||
| return ((_a = node.nodeValue) == null ? void 0 : _a.trim()) || ""; | ||
| return node.nodeValue?.trim() || ""; | ||
| } | ||
@@ -1538,5 +980,6 @@ return ""; | ||
| locator: xpath, | ||
| attributes: __spreadValues({ | ||
| nodeType | ||
| }, attributes), | ||
| attributes: { | ||
| nodeType, | ||
| ...attributes | ||
| }, | ||
| content: text, | ||
@@ -1569,13 +1012,1 @@ rect, | ||
| }); | ||
| /*! Bundled license information: | ||
| js-sha256/src/sha256.js: | ||
| (** | ||
| * [js-sha256]{@link https://github.com/emn178/js-sha256} | ||
| * | ||
| * @version 0.11.0 | ||
| * @author Chen, Yi-Cyuan [emn178@gmail.com] | ||
| * @copyright Chen, Yi-Cyuan 2014-2024 | ||
| * @license MIT | ||
| *) | ||
| */ |
+2
-1
@@ -13,3 +13,4 @@ interface PkgInfo { | ||
| declare function findNearestPackageJson(dir: string): string | null; | ||
| declare function getExtraReturnLogic(tree?: boolean): Promise<string | null>; | ||
| export { findNearestPackageJson, getRunningPkgInfo }; | ||
| export { findNearestPackageJson, getExtraReturnLogic, getRunningPkgInfo }; |
+40
-2
| "use strict"; | ||
| var __create = Object.create; | ||
| var __defProp = Object.defineProperty; | ||
| var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
| var __getOwnPropNames = Object.getOwnPropertyNames; | ||
| var __getProtoOf = Object.getPrototypeOf; | ||
| var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
@@ -18,8 +20,17 @@ var __export = (target, all) => { | ||
| }; | ||
| var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( | ||
| // If the importer is in node compatibility mode or this is not an ESM | ||
| // file that has been converted to a CommonJS file using a Babel- | ||
| // compatible transform (i.e. "__esModule" has not been set), then set | ||
| // "default" to the CommonJS "module.exports" for node compatibility. | ||
| isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, | ||
| mod | ||
| )); | ||
| var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); | ||
| // src/fs/index.ts | ||
| // src/node/fs.ts | ||
| var fs_exports = {}; | ||
| __export(fs_exports, { | ||
| findNearestPackageJson: () => findNearestPackageJson, | ||
| getExtraReturnLogic: () => getExtraReturnLogic, | ||
| getRunningPkgInfo: () => getRunningPkgInfo | ||
@@ -30,4 +41,16 @@ }); | ||
| var import_node_path = require("path"); | ||
| var import_node_path2 = __toESM(require("path")); | ||
| // src/utils.ts | ||
| var import_js_sha256 = require("js-sha256"); | ||
| var import_debug = __toESM(require("debug")); | ||
| var ifInBrowser = typeof window !== "undefined"; | ||
| function assert(condition, message) { | ||
| if (!condition) { | ||
| throw new Error(message || "Assertion failed"); | ||
| } | ||
| } | ||
| // src/node/fs.ts | ||
| var pkgCacheMap = {}; | ||
| var ifInBrowser = typeof window !== "undefined"; | ||
| function getRunningPkgInfo(dir) { | ||
@@ -69,6 +92,21 @@ if (ifInBrowser) { | ||
| } | ||
| async function getExtraReturnLogic(tree = false) { | ||
| if (ifInBrowser) { | ||
| return null; | ||
| } | ||
| const currentFilePath = __filename; | ||
| const pathDir = findNearestPackageJson((0, import_node_path.dirname)(currentFilePath)); | ||
| assert(pathDir, `can't find pathDir, with ${import_node_path.dirname}`); | ||
| const scriptPath = import_node_path2.default.join(pathDir, "./dist/script/htmlElement.js"); | ||
| const elementInfosScriptContent = (0, import_node_fs.readFileSync)(scriptPath, "utf-8"); | ||
| if (tree) { | ||
| return `${elementInfosScriptContent}midscene_element_inspector.webExtractNodeTree()`; | ||
| } | ||
| return `${elementInfosScriptContent}midscene_element_inspector.webExtractTextWithPosition()`; | ||
| } | ||
| // Annotate the CommonJS export names for ESM import in node: | ||
| 0 && (module.exports = { | ||
| findNearestPackageJson, | ||
| getExtraReturnLogic, | ||
| getRunningPkgInfo | ||
| }); |
+201
-225
@@ -8,3 +8,2 @@ "use strict"; | ||
| var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
| var __pow = Math.pow; | ||
| var __export = (target, all) => { | ||
@@ -31,22 +30,2 @@ for (var name in all) | ||
| var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); | ||
| var __async = (__this, __arguments, generator) => { | ||
| return new Promise((resolve, reject) => { | ||
| var fulfilled = (value) => { | ||
| try { | ||
| step(generator.next(value)); | ||
| } catch (e) { | ||
| reject(e); | ||
| } | ||
| }; | ||
| var rejected = (value) => { | ||
| try { | ||
| step(generator.throw(value)); | ||
| } catch (e) { | ||
| reject(e); | ||
| } | ||
| }; | ||
| var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected); | ||
| step((generator = generator.apply(__this, __arguments)).next()); | ||
| }); | ||
| }; | ||
@@ -81,45 +60,37 @@ // src/img/index.ts | ||
| var ifInBrowser = typeof window !== "undefined"; | ||
| function getJimp() { | ||
| return __async(this, null, function* () { | ||
| if (ifInBrowser) { | ||
| yield import("jimp/browser/lib/jimp.js"); | ||
| return window.Jimp; | ||
| } | ||
| return (yield import("jimp")).default; | ||
| }); | ||
| async function getJimp() { | ||
| if (ifInBrowser) { | ||
| await import("jimp/browser/lib/jimp.js"); | ||
| return window.Jimp; | ||
| } | ||
| return (await import("jimp")).default; | ||
| } | ||
| // src/img/info.ts | ||
| function imageInfo(image) { | ||
| return __async(this, null, function* () { | ||
| const Jimp = yield getJimp(); | ||
| let jimpImage; | ||
| if (typeof image === "string") { | ||
| jimpImage = yield Jimp.read(image); | ||
| } else if (import_node_buffer.Buffer.isBuffer(image)) { | ||
| jimpImage = yield Jimp.read(image); | ||
| } else if (image instanceof Jimp) { | ||
| jimpImage = image; | ||
| } else { | ||
| throw new Error("Invalid image input: must be a string path or a Buffer"); | ||
| } | ||
| const { width, height } = jimpImage.bitmap; | ||
| (0, import_node_assert.default)( | ||
| width && height, | ||
| `Invalid image: ${typeof image === "string" ? image : "Buffer"}` | ||
| ); | ||
| return { width, height, jimpImage }; | ||
| }); | ||
| async function imageInfo(image) { | ||
| const Jimp = await getJimp(); | ||
| let jimpImage; | ||
| if (typeof image === "string") { | ||
| jimpImage = await Jimp.read(image); | ||
| } else if (import_node_buffer.Buffer.isBuffer(image)) { | ||
| jimpImage = await Jimp.read(image); | ||
| } else if (image instanceof Jimp) { | ||
| jimpImage = image; | ||
| } else { | ||
| throw new Error("Invalid image input: must be a string path or a Buffer"); | ||
| } | ||
| const { width, height } = jimpImage.bitmap; | ||
| (0, import_node_assert.default)( | ||
| width && height, | ||
| `Invalid image: ${typeof image === "string" ? image : "Buffer"}` | ||
| ); | ||
| return { width, height, jimpImage }; | ||
| } | ||
| function imageInfoOfBase64(imageBase64) { | ||
| return __async(this, null, function* () { | ||
| const buffer = yield bufferFromBase64(imageBase64); | ||
| return imageInfo(buffer); | ||
| }); | ||
| async function imageInfoOfBase64(imageBase64) { | ||
| const buffer = await bufferFromBase64(imageBase64); | ||
| return imageInfo(buffer); | ||
| } | ||
| function bufferFromBase64(imageBase64) { | ||
| return __async(this, null, function* () { | ||
| const base64Data = imageBase64.replace(/^data:image\/\w+;base64,/, ""); | ||
| return import_node_buffer.Buffer.from(base64Data, "base64"); | ||
| }); | ||
| async function bufferFromBase64(imageBase64) { | ||
| const base64Data = imageBase64.replace(/^data:image\/\w+;base64,/, ""); | ||
| return import_node_buffer.Buffer.from(base64Data, "base64"); | ||
| } | ||
@@ -143,65 +114,70 @@ function base64Encoded(image, withHeader = true) { | ||
| var import_node_buffer2 = require("buffer"); | ||
| function saveBase64Image(options) { | ||
| return __async(this, null, function* () { | ||
| const { base64Data, outputPath } = options; | ||
| const base64Image = base64Data.split(";base64,").pop() || base64Data; | ||
| const imageBuffer = import_node_buffer2.Buffer.from(base64Image, "base64"); | ||
| const Jimp = yield getJimp(); | ||
| const image = yield Jimp.read(imageBuffer); | ||
| yield image.writeAsync(outputPath); | ||
| }); | ||
| var import_debug = __toESM(require("debug")); | ||
| var debugImg = (0, import_debug.default)("img"); | ||
| async function saveBase64Image(options) { | ||
| debugImg(`saveBase64Image start: ${options.outputPath}`); | ||
| const { base64Data, outputPath } = options; | ||
| const base64Image = base64Data.split(";base64,").pop() || base64Data; | ||
| const imageBuffer = import_node_buffer2.Buffer.from(base64Image, "base64"); | ||
| const Jimp = await getJimp(); | ||
| const image = await Jimp.read(imageBuffer); | ||
| await image.writeAsync(outputPath); | ||
| debugImg(`saveBase64Image done: ${options.outputPath}`); | ||
| } | ||
| function transformImgPathToBase64(inputPath) { | ||
| return __async(this, null, function* () { | ||
| const Jimp = yield getJimp(); | ||
| const image = yield Jimp.read(inputPath); | ||
| const buffer = yield image.getBufferAsync(Jimp.MIME_JPEG); | ||
| return buffer.toString("base64"); | ||
| }); | ||
| async function transformImgPathToBase64(inputPath) { | ||
| debugImg(`transformImgPathToBase64 start: ${inputPath}`); | ||
| const Jimp = await getJimp(); | ||
| const image = await Jimp.read(inputPath); | ||
| const buffer = await image.getBufferAsync(Jimp.MIME_JPEG); | ||
| const res = buffer.toString("base64"); | ||
| debugImg(`transformImgPathToBase64 done: ${inputPath}`); | ||
| return res; | ||
| } | ||
| function resizeImg(inputData, newSize) { | ||
| return __async(this, null, function* () { | ||
| if (typeof inputData === "string") | ||
| throw Error("inputData is base64, use resizeImgBase64 instead"); | ||
| (0, import_node_assert2.default)( | ||
| newSize && newSize.width > 0 && newSize.height > 0, | ||
| "newSize must be positive" | ||
| ); | ||
| const Jimp = yield getJimp(); | ||
| const image = yield Jimp.read(inputData); | ||
| const { width, height } = image.bitmap; | ||
| if (!width || !height) { | ||
| throw Error("Undefined width or height from the input image."); | ||
| } | ||
| if (newSize.width === width && newSize.height === height) { | ||
| return inputData; | ||
| } | ||
| image.resize(newSize.width, newSize.height, Jimp.RESIZE_NEAREST_NEIGHBOR); | ||
| image.quality(90); | ||
| const resizedBuffer = yield image.getBufferAsync(Jimp.MIME_JPEG); | ||
| return resizedBuffer; | ||
| }); | ||
| async function resizeImg(inputData, newSize) { | ||
| if (typeof inputData === "string") | ||
| throw Error("inputData is base64, use resizeImgBase64 instead"); | ||
| (0, import_node_assert2.default)( | ||
| newSize && newSize.width > 0 && newSize.height > 0, | ||
| "newSize must be positive" | ||
| ); | ||
| debugImg(`resizeImg start, target size: ${newSize.width}x${newSize.height}`); | ||
| const Jimp = await getJimp(); | ||
| const image = await Jimp.read(inputData); | ||
| const { width, height } = image.bitmap; | ||
| if (!width || !height) { | ||
| throw Error("Undefined width or height from the input image."); | ||
| } | ||
| if (newSize.width === width && newSize.height === height) { | ||
| return inputData; | ||
| } | ||
| image.resize(newSize.width, newSize.height, Jimp.RESIZE_NEAREST_NEIGHBOR); | ||
| image.quality(90); | ||
| const resizedBuffer = await image.getBufferAsync(Jimp.MIME_JPEG); | ||
| debugImg(`resizeImg done, target size: ${newSize.width}x${newSize.height}`); | ||
| return resizedBuffer; | ||
| } | ||
| function bufferFromBase642(base64) { | ||
| return __async(this, null, function* () { | ||
| const splitFlag = ";base64,"; | ||
| const dataSplitted = base64.split(splitFlag); | ||
| if (dataSplitted.length !== 2) { | ||
| throw Error("Invalid base64 data"); | ||
| } | ||
| return import_node_buffer2.Buffer.from(dataSplitted[1], "base64"); | ||
| }); | ||
| async function bufferFromBase642(base64) { | ||
| const splitFlag = ";base64,"; | ||
| const dataSplitted = base64.split(splitFlag); | ||
| if (dataSplitted.length !== 2) { | ||
| throw Error("Invalid base64 data"); | ||
| } | ||
| debugImg(`bufferFromBase64 start: ${base64}`); | ||
| const res = import_node_buffer2.Buffer.from(dataSplitted[1], "base64"); | ||
| debugImg(`bufferFromBase64 done: ${base64}`); | ||
| return res; | ||
| } | ||
| function resizeImgBase64(inputBase64, newSize) { | ||
| return __async(this, null, function* () { | ||
| const splitFlag = ";base64,"; | ||
| const dataSplitted = inputBase64.split(splitFlag); | ||
| if (dataSplitted.length !== 2) { | ||
| throw Error("Invalid base64 data"); | ||
| } | ||
| const imageBuffer = import_node_buffer2.Buffer.from(dataSplitted[1], "base64"); | ||
| const buffer = yield resizeImg(imageBuffer, newSize); | ||
| const content = buffer.toString("base64"); | ||
| return `${dataSplitted[0]}${splitFlag}${content}`; | ||
| }); | ||
| async function resizeImgBase64(inputBase64, newSize) { | ||
| debugImg(`resizeImgBase64 start: ${inputBase64}`); | ||
| const splitFlag = ";base64,"; | ||
| const dataSplitted = inputBase64.split(splitFlag); | ||
| if (dataSplitted.length !== 2) { | ||
| throw Error("Invalid base64 data"); | ||
| } | ||
| const imageBuffer = import_node_buffer2.Buffer.from(dataSplitted[1], "base64"); | ||
| const buffer = await resizeImg(imageBuffer, newSize); | ||
| const content = buffer.toString("base64"); | ||
| const res = `${dataSplitted[0]}${splitFlag}${content}`; | ||
| debugImg(`resizeImgBase64 done: ${inputBase64}`); | ||
| return res; | ||
| } | ||
@@ -227,43 +203,41 @@ function zoomForGPT4o(originalWidth, originalHeight) { | ||
| } | ||
| function trimImage(image) { | ||
| return __async(this, null, function* () { | ||
| const Jimp = yield getJimp(); | ||
| const jimpImage = yield Jimp.read( | ||
| import_node_buffer2.Buffer.isBuffer(image) ? image : import_node_buffer2.Buffer.from(image) | ||
| ); | ||
| const { width, height } = jimpImage.bitmap; | ||
| if (width <= 3 || height <= 3) { | ||
| return null; | ||
| } | ||
| const trimmedImage = jimpImage.autocrop(); | ||
| const { width: trimmedWidth, height: trimmedHeight } = trimmedImage.bitmap; | ||
| const trimOffsetLeft = (width - trimmedWidth) / 2; | ||
| const trimOffsetTop = (height - trimmedHeight) / 2; | ||
| if (trimOffsetLeft === 0 && trimOffsetTop === 0) { | ||
| return null; | ||
| } | ||
| return { | ||
| trimOffsetLeft: -trimOffsetLeft, | ||
| trimOffsetTop: -trimOffsetTop, | ||
| width: trimmedWidth, | ||
| height: trimmedHeight | ||
| }; | ||
| }); | ||
| async function trimImage(image) { | ||
| const Jimp = await getJimp(); | ||
| const jimpImage = await Jimp.read( | ||
| import_node_buffer2.Buffer.isBuffer(image) ? image : import_node_buffer2.Buffer.from(image) | ||
| ); | ||
| const { width, height } = jimpImage.bitmap; | ||
| if (width <= 3 || height <= 3) { | ||
| return null; | ||
| } | ||
| const trimmedImage = jimpImage.autocrop(); | ||
| const { width: trimmedWidth, height: trimmedHeight } = trimmedImage.bitmap; | ||
| const trimOffsetLeft = (width - trimmedWidth) / 2; | ||
| const trimOffsetTop = (height - trimmedHeight) / 2; | ||
| if (trimOffsetLeft === 0 && trimOffsetTop === 0) { | ||
| return null; | ||
| } | ||
| return { | ||
| trimOffsetLeft: -trimOffsetLeft, | ||
| trimOffsetTop: -trimOffsetTop, | ||
| width: trimmedWidth, | ||
| height: trimmedHeight | ||
| }; | ||
| } | ||
| function paddingToMatchBlock(imageBase64, blockSize = 28) { | ||
| return __async(this, null, function* () { | ||
| const Jimp = yield getJimp(); | ||
| const imageBuffer = yield bufferFromBase642(imageBase64); | ||
| const image = yield Jimp.read(imageBuffer); | ||
| const { width, height } = image.bitmap; | ||
| const targetWidth = Math.ceil(width / blockSize) * blockSize; | ||
| const targetHeight = Math.ceil(height / blockSize) * blockSize; | ||
| if (targetWidth === width && targetHeight === height) { | ||
| return imageBase64; | ||
| } | ||
| const paddedImage = new Jimp(targetWidth, targetHeight, 4294967295); | ||
| paddedImage.composite(image, 0, 0); | ||
| const base64 = yield paddedImage.getBase64Async(Jimp.MIME_JPEG); | ||
| return base64; | ||
| }); | ||
| async function paddingToMatchBlock(imageBase64, blockSize = 28) { | ||
| debugImg("paddingToMatchBlock start"); | ||
| const Jimp = await getJimp(); | ||
| const imageBuffer = await bufferFromBase642(imageBase64); | ||
| const image = await Jimp.read(imageBuffer); | ||
| const { width, height } = image.bitmap; | ||
| const targetWidth = Math.ceil(width / blockSize) * blockSize; | ||
| const targetHeight = Math.ceil(height / blockSize) * blockSize; | ||
| if (targetWidth === width && targetHeight === height) { | ||
| return imageBase64; | ||
| } | ||
| const paddedImage = new Jimp(targetWidth, targetHeight, 4294967295); | ||
| paddedImage.composite(image, 0, 0); | ||
| const base64 = await paddedImage.getBase64Async(Jimp.MIME_JPEG); | ||
| debugImg("paddingToMatchBlock done"); | ||
| return base64; | ||
| } | ||
@@ -274,4 +248,4 @@ | ||
| var cachedFont = null; | ||
| var createSvgOverlay = (elements, imageWidth, imageHeight, boxPadding = 5) => __async(void 0, null, function* () { | ||
| const Jimp = yield getJimp(); | ||
| var createSvgOverlay = async (elements, imageWidth, imageHeight, boxPadding = 5) => { | ||
| const Jimp = await getJimp(); | ||
| const image = new Jimp(imageWidth, imageHeight, 0); | ||
@@ -310,8 +284,8 @@ const colors = [ | ||
| paddedRect.height, | ||
| function(x, y, idx) { | ||
| (x, y, idx) => { | ||
| if (x === paddedRect.left || x === paddedRect.left + paddedRect.width - 1 || y === paddedRect.top || y === paddedRect.top + paddedRect.height - 1) { | ||
| this.bitmap.data[idx + 0] = color.rect >> 24 & 255; | ||
| this.bitmap.data[idx + 1] = color.rect >> 16 & 255; | ||
| this.bitmap.data[idx + 2] = color.rect >> 8 & 255; | ||
| this.bitmap.data[idx + 3] = color.rect & 255; | ||
| image.bitmap.data[idx + 0] = color.rect >> 24 & 255; | ||
| image.bitmap.data[idx + 1] = color.rect >> 16 & 255; | ||
| image.bitmap.data[idx + 2] = color.rect >> 8 & 255; | ||
| image.bitmap.data[idx + 3] = color.rect & 255; | ||
| } | ||
@@ -352,10 +326,16 @@ } | ||
| } | ||
| image.scan(rectX, rectY, rectWidth, rectHeight, function(x, y, idx) { | ||
| this.bitmap.data[idx + 0] = color.rect >> 24 & 255; | ||
| this.bitmap.data[idx + 1] = color.rect >> 16 & 255; | ||
| this.bitmap.data[idx + 2] = color.rect >> 8 & 255; | ||
| this.bitmap.data[idx + 3] = color.rect & 255; | ||
| }); | ||
| image.scan( | ||
| rectX, | ||
| rectY, | ||
| rectWidth, | ||
| rectHeight, | ||
| (x, y, idx) => { | ||
| image.bitmap.data[idx + 0] = color.rect >> 24 & 255; | ||
| image.bitmap.data[idx + 1] = color.rect >> 16 & 255; | ||
| image.bitmap.data[idx + 2] = color.rect >> 8 & 255; | ||
| image.bitmap.data[idx + 3] = color.rect & 255; | ||
| } | ||
| ); | ||
| try { | ||
| cachedFont = cachedFont || (yield Jimp.loadFont(Jimp.FONT_SANS_16_WHITE)); | ||
| cachedFont = cachedFont || await Jimp.loadFont(Jimp.FONT_SANS_16_WHITE); | ||
| } catch (error) { | ||
@@ -378,4 +358,4 @@ console.error("Error loading font", error); | ||
| return image; | ||
| }); | ||
| var compositeElementInfoImg = (options) => __async(void 0, null, function* () { | ||
| }; | ||
| var compositeElementInfoImg = async (options) => { | ||
| (0, import_node_assert3.default)(options.inputImgBase64, "inputImgBase64 is required"); | ||
@@ -385,3 +365,3 @@ let width = 0; | ||
| let jimpImage; | ||
| const Jimp = yield getJimp(); | ||
| const Jimp = await getJimp(); | ||
| if (options.size) { | ||
@@ -392,3 +372,3 @@ width = options.size.width; | ||
| if (!width || !height) { | ||
| const info = yield imageInfoOfBase64(options.inputImgBase64); | ||
| const info = await imageInfoOfBase64(options.inputImgBase64); | ||
| width = info.width; | ||
@@ -398,4 +378,4 @@ height = info.height; | ||
| } else { | ||
| const imageBuffer = yield bufferFromBase64(options.inputImgBase64); | ||
| jimpImage = yield Jimp.read(imageBuffer); | ||
| const imageBuffer = await bufferFromBase64(options.inputImgBase64); | ||
| jimpImage = await Jimp.read(imageBuffer); | ||
| const imageBitmap = jimpImage.bitmap; | ||
@@ -410,4 +390,4 @@ if (imageBitmap.width !== width || imageBitmap.height !== height) { | ||
| const { elementsPositionInfo } = options; | ||
| const result = yield Promise.resolve(jimpImage).then((image) => __async(void 0, null, function* () { | ||
| const svgOverlay = yield createSvgOverlay( | ||
| const result = await Promise.resolve(jimpImage).then(async (image) => { | ||
| const svgOverlay = await createSvgOverlay( | ||
| elementsPositionInfo, | ||
@@ -418,4 +398,4 @@ width, | ||
| ); | ||
| const svgImage = yield Jimp.read(svgOverlay); | ||
| const compositeImage = yield image.composite(svgImage, 0, 0, { | ||
| const svgImage = await Jimp.read(svgOverlay); | ||
| const compositeImage = await image.composite(svgImage, 0, 0, { | ||
| mode: Jimp.BLEND_SOURCE_OVER, | ||
@@ -426,12 +406,12 @@ opacitySource: 1, | ||
| return compositeImage; | ||
| })).then((compositeImage) => __async(void 0, null, function* () { | ||
| }).then(async (compositeImage) => { | ||
| compositeImage.quality(90); | ||
| const base64 = yield compositeImage.getBase64Async(Jimp.MIME_JPEG); | ||
| const base64 = await compositeImage.getBase64Async(Jimp.MIME_JPEG); | ||
| return base64; | ||
| })).catch((error) => { | ||
| }).catch((error) => { | ||
| throw error; | ||
| }); | ||
| return result; | ||
| }); | ||
| var processImageElementInfo = (options) => __async(void 0, null, function* () { | ||
| }; | ||
| var processImageElementInfo = async (options) => { | ||
| const base64Image = options.inputImgBase64.split(";base64,").pop(); | ||
@@ -442,3 +422,3 @@ (0, import_node_assert3.default)(base64Image, "base64Image is undefined"); | ||
| compositeElementInfoImgWithoutTextBase64 | ||
| ] = yield Promise.all([ | ||
| ] = await Promise.all([ | ||
| compositeElementInfoImg({ | ||
@@ -457,43 +437,39 @@ inputImgBase64: options.inputImgBase64, | ||
| }; | ||
| }); | ||
| }; | ||
| // src/img/draw-box.ts | ||
| function drawBoxOnImage(options) { | ||
| return __async(this, null, function* () { | ||
| const { inputImgBase64, rect } = options; | ||
| const color = { r: 255, g: 0, b: 0, a: 255 }; | ||
| const Jimp = yield getJimp(); | ||
| const imageBuffer = yield bufferFromBase64(inputImgBase64); | ||
| const image = yield Jimp.read(imageBuffer); | ||
| const centerX = rect.x; | ||
| const centerY = rect.y; | ||
| const radius = 5; | ||
| image.scan( | ||
| Math.floor(centerX - radius), | ||
| Math.floor(centerY - radius), | ||
| radius * 2, | ||
| radius * 2, | ||
| function(x, y, idx) { | ||
| const distance = Math.sqrt(__pow(x - centerX, 2) + __pow(y - centerY, 2)); | ||
| if (distance <= radius) { | ||
| this.bitmap.data[idx + 0] = color.r; | ||
| this.bitmap.data[idx + 1] = color.g; | ||
| this.bitmap.data[idx + 2] = color.b; | ||
| this.bitmap.data[idx + 3] = color.a; | ||
| } | ||
| async function drawBoxOnImage(options) { | ||
| const { inputImgBase64, rect } = options; | ||
| const color = { r: 255, g: 0, b: 0, a: 255 }; | ||
| const Jimp = await getJimp(); | ||
| const imageBuffer = await bufferFromBase64(inputImgBase64); | ||
| const image = await Jimp.read(imageBuffer); | ||
| const centerX = rect.x; | ||
| const centerY = rect.y; | ||
| const radius = 5; | ||
| image.scan( | ||
| Math.floor(centerX - radius), | ||
| Math.floor(centerY - radius), | ||
| radius * 2, | ||
| radius * 2, | ||
| (x, y, idx) => { | ||
| const distance = Math.sqrt((x - centerX) ** 2 + (y - centerY) ** 2); | ||
| if (distance <= radius) { | ||
| image.bitmap.data[idx + 0] = color.r; | ||
| image.bitmap.data[idx + 1] = color.g; | ||
| image.bitmap.data[idx + 2] = color.b; | ||
| image.bitmap.data[idx + 3] = color.a; | ||
| } | ||
| ); | ||
| image.quality(90); | ||
| const resultBase64 = yield image.getBase64Async(Jimp.MIME_JPEG); | ||
| return resultBase64; | ||
| }); | ||
| } | ||
| ); | ||
| image.quality(90); | ||
| const resultBase64 = await image.getBase64Async(Jimp.MIME_JPEG); | ||
| return resultBase64; | ||
| } | ||
| function savePositionImg(options) { | ||
| return __async(this, null, function* () { | ||
| const { inputImgBase64, rect, outputPath } = options; | ||
| const imgBase64 = yield drawBoxOnImage({ inputImgBase64, rect }); | ||
| yield saveBase64Image({ | ||
| base64Data: imgBase64, | ||
| outputPath | ||
| }); | ||
| async function savePositionImg(options) { | ||
| const { inputImgBase64, rect, outputPath } = options; | ||
| const imgBase64 = await drawBoxOnImage({ inputImgBase64, rect }); | ||
| await saveBase64Image({ | ||
| base64Data: imgBase64, | ||
| outputPath | ||
| }); | ||
@@ -500,0 +476,0 @@ } |
+13
-1
@@ -0,5 +1,17 @@ | ||
| import debug from 'debug'; | ||
| declare const ifInBrowser: boolean; | ||
| declare function uuid(): string; | ||
| declare function getDebug(topic: string): debug.Debugger; | ||
| declare function enableDebug(topic: string): void; | ||
| declare function generateHashId(rect: any, content?: string): string; | ||
| /** | ||
| * A utility function that asserts a condition and throws an error with a message if the condition is false. | ||
| * | ||
| * @param condition - The condition to assert | ||
| * @param message - The error message to throw if the condition is false | ||
| * @throws Error with the provided message if the condition is false | ||
| */ | ||
| declare function assert(condition: any, message?: string): asserts condition; | ||
| export { generateHashId, ifInBrowser, uuid }; | ||
| export { assert, enableDebug, generateHashId, getDebug, ifInBrowser, uuid }; |
+20
-535
@@ -8,5 +8,2 @@ "use strict"; | ||
| var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
| var __commonJS = (cb, mod) => function __require() { | ||
| return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports; | ||
| }; | ||
| var __export = (target, all) => { | ||
@@ -34,525 +31,9 @@ for (var name in all) | ||
| // ../../node_modules/.pnpm/js-sha256@0.11.0/node_modules/js-sha256/src/sha256.js | ||
| var require_sha256 = __commonJS({ | ||
| "../../node_modules/.pnpm/js-sha256@0.11.0/node_modules/js-sha256/src/sha256.js"(exports, module2) { | ||
| "use strict"; | ||
| (function() { | ||
| "use strict"; | ||
| var ERROR = "input is invalid type"; | ||
| var WINDOW = typeof window === "object"; | ||
| var root = WINDOW ? window : {}; | ||
| if (root.JS_SHA256_NO_WINDOW) { | ||
| WINDOW = false; | ||
| } | ||
| var WEB_WORKER = !WINDOW && typeof self === "object"; | ||
| var NODE_JS = !root.JS_SHA256_NO_NODE_JS && typeof process === "object" && process.versions && process.versions.node; | ||
| if (NODE_JS) { | ||
| root = global; | ||
| } else if (WEB_WORKER) { | ||
| root = self; | ||
| } | ||
| var COMMON_JS = !root.JS_SHA256_NO_COMMON_JS && typeof module2 === "object" && module2.exports; | ||
| var AMD = typeof define === "function" && define.amd; | ||
| var ARRAY_BUFFER = !root.JS_SHA256_NO_ARRAY_BUFFER && typeof ArrayBuffer !== "undefined"; | ||
| var HEX_CHARS = "0123456789abcdef".split(""); | ||
| var EXTRA = [-2147483648, 8388608, 32768, 128]; | ||
| var SHIFT = [24, 16, 8, 0]; | ||
| var K = [ | ||
| 1116352408, | ||
| 1899447441, | ||
| 3049323471, | ||
| 3921009573, | ||
| 961987163, | ||
| 1508970993, | ||
| 2453635748, | ||
| 2870763221, | ||
| 3624381080, | ||
| 310598401, | ||
| 607225278, | ||
| 1426881987, | ||
| 1925078388, | ||
| 2162078206, | ||
| 2614888103, | ||
| 3248222580, | ||
| 3835390401, | ||
| 4022224774, | ||
| 264347078, | ||
| 604807628, | ||
| 770255983, | ||
| 1249150122, | ||
| 1555081692, | ||
| 1996064986, | ||
| 2554220882, | ||
| 2821834349, | ||
| 2952996808, | ||
| 3210313671, | ||
| 3336571891, | ||
| 3584528711, | ||
| 113926993, | ||
| 338241895, | ||
| 666307205, | ||
| 773529912, | ||
| 1294757372, | ||
| 1396182291, | ||
| 1695183700, | ||
| 1986661051, | ||
| 2177026350, | ||
| 2456956037, | ||
| 2730485921, | ||
| 2820302411, | ||
| 3259730800, | ||
| 3345764771, | ||
| 3516065817, | ||
| 3600352804, | ||
| 4094571909, | ||
| 275423344, | ||
| 430227734, | ||
| 506948616, | ||
| 659060556, | ||
| 883997877, | ||
| 958139571, | ||
| 1322822218, | ||
| 1537002063, | ||
| 1747873779, | ||
| 1955562222, | ||
| 2024104815, | ||
| 2227730452, | ||
| 2361852424, | ||
| 2428436474, | ||
| 2756734187, | ||
| 3204031479, | ||
| 3329325298 | ||
| ]; | ||
| var OUTPUT_TYPES = ["hex", "array", "digest", "arrayBuffer"]; | ||
| var blocks = []; | ||
| if (root.JS_SHA256_NO_NODE_JS || !Array.isArray) { | ||
| Array.isArray = function(obj) { | ||
| return Object.prototype.toString.call(obj) === "[object Array]"; | ||
| }; | ||
| } | ||
| if (ARRAY_BUFFER && (root.JS_SHA256_NO_ARRAY_BUFFER_IS_VIEW || !ArrayBuffer.isView)) { | ||
| ArrayBuffer.isView = function(obj) { | ||
| return typeof obj === "object" && obj.buffer && obj.buffer.constructor === ArrayBuffer; | ||
| }; | ||
| } | ||
| var createOutputMethod = function(outputType, is224) { | ||
| return function(message) { | ||
| return new Sha256(is224, true).update(message)[outputType](); | ||
| }; | ||
| }; | ||
| var createMethod = function(is224) { | ||
| var method = createOutputMethod("hex", is224); | ||
| if (NODE_JS) { | ||
| method = nodeWrap(method, is224); | ||
| } | ||
| method.create = function() { | ||
| return new Sha256(is224); | ||
| }; | ||
| method.update = function(message) { | ||
| return method.create().update(message); | ||
| }; | ||
| for (var i = 0; i < OUTPUT_TYPES.length; ++i) { | ||
| var type = OUTPUT_TYPES[i]; | ||
| method[type] = createOutputMethod(type, is224); | ||
| } | ||
| return method; | ||
| }; | ||
| var nodeWrap = function(method, is224) { | ||
| var crypto = require("crypto"); | ||
| var Buffer2 = require("buffer").Buffer; | ||
| var algorithm = is224 ? "sha224" : "sha256"; | ||
| var bufferFrom; | ||
| if (Buffer2.from && !root.JS_SHA256_NO_BUFFER_FROM) { | ||
| bufferFrom = Buffer2.from; | ||
| } else { | ||
| bufferFrom = function(message) { | ||
| return new Buffer2(message); | ||
| }; | ||
| } | ||
| var nodeMethod = function(message) { | ||
| if (typeof message === "string") { | ||
| return crypto.createHash(algorithm).update(message, "utf8").digest("hex"); | ||
| } else { | ||
| if (message === null || message === void 0) { | ||
| throw new Error(ERROR); | ||
| } else if (message.constructor === ArrayBuffer) { | ||
| message = new Uint8Array(message); | ||
| } | ||
| } | ||
| if (Array.isArray(message) || ArrayBuffer.isView(message) || message.constructor === Buffer2) { | ||
| return crypto.createHash(algorithm).update(bufferFrom(message)).digest("hex"); | ||
| } else { | ||
| return method(message); | ||
| } | ||
| }; | ||
| return nodeMethod; | ||
| }; | ||
| var createHmacOutputMethod = function(outputType, is224) { | ||
| return function(key, message) { | ||
| return new HmacSha256(key, is224, true).update(message)[outputType](); | ||
| }; | ||
| }; | ||
| var createHmacMethod = function(is224) { | ||
| var method = createHmacOutputMethod("hex", is224); | ||
| method.create = function(key) { | ||
| return new HmacSha256(key, is224); | ||
| }; | ||
| method.update = function(key, message) { | ||
| return method.create(key).update(message); | ||
| }; | ||
| for (var i = 0; i < OUTPUT_TYPES.length; ++i) { | ||
| var type = OUTPUT_TYPES[i]; | ||
| method[type] = createHmacOutputMethod(type, is224); | ||
| } | ||
| return method; | ||
| }; | ||
| function Sha256(is224, sharedMemory) { | ||
| if (sharedMemory) { | ||
| blocks[0] = blocks[16] = blocks[1] = blocks[2] = blocks[3] = blocks[4] = blocks[5] = blocks[6] = blocks[7] = blocks[8] = blocks[9] = blocks[10] = blocks[11] = blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0; | ||
| this.blocks = blocks; | ||
| } else { | ||
| this.blocks = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; | ||
| } | ||
| if (is224) { | ||
| this.h0 = 3238371032; | ||
| this.h1 = 914150663; | ||
| this.h2 = 812702999; | ||
| this.h3 = 4144912697; | ||
| this.h4 = 4290775857; | ||
| this.h5 = 1750603025; | ||
| this.h6 = 1694076839; | ||
| this.h7 = 3204075428; | ||
| } else { | ||
| this.h0 = 1779033703; | ||
| this.h1 = 3144134277; | ||
| this.h2 = 1013904242; | ||
| this.h3 = 2773480762; | ||
| this.h4 = 1359893119; | ||
| this.h5 = 2600822924; | ||
| this.h6 = 528734635; | ||
| this.h7 = 1541459225; | ||
| } | ||
| this.block = this.start = this.bytes = this.hBytes = 0; | ||
| this.finalized = this.hashed = false; | ||
| this.first = true; | ||
| this.is224 = is224; | ||
| } | ||
| Sha256.prototype.update = function(message) { | ||
| if (this.finalized) { | ||
| return; | ||
| } | ||
| var notString, type = typeof message; | ||
| if (type !== "string") { | ||
| if (type === "object") { | ||
| if (message === null) { | ||
| throw new Error(ERROR); | ||
| } else if (ARRAY_BUFFER && message.constructor === ArrayBuffer) { | ||
| message = new Uint8Array(message); | ||
| } else if (!Array.isArray(message)) { | ||
| if (!ARRAY_BUFFER || !ArrayBuffer.isView(message)) { | ||
| throw new Error(ERROR); | ||
| } | ||
| } | ||
| } else { | ||
| throw new Error(ERROR); | ||
| } | ||
| notString = true; | ||
| } | ||
| var code, index = 0, i, length = message.length, blocks2 = this.blocks; | ||
| while (index < length) { | ||
| if (this.hashed) { | ||
| this.hashed = false; | ||
| blocks2[0] = this.block; | ||
| this.block = blocks2[16] = blocks2[1] = blocks2[2] = blocks2[3] = blocks2[4] = blocks2[5] = blocks2[6] = blocks2[7] = blocks2[8] = blocks2[9] = blocks2[10] = blocks2[11] = blocks2[12] = blocks2[13] = blocks2[14] = blocks2[15] = 0; | ||
| } | ||
| if (notString) { | ||
| for (i = this.start; index < length && i < 64; ++index) { | ||
| blocks2[i >>> 2] |= message[index] << SHIFT[i++ & 3]; | ||
| } | ||
| } else { | ||
| for (i = this.start; index < length && i < 64; ++index) { | ||
| code = message.charCodeAt(index); | ||
| if (code < 128) { | ||
| blocks2[i >>> 2] |= code << SHIFT[i++ & 3]; | ||
| } else if (code < 2048) { | ||
| blocks2[i >>> 2] |= (192 | code >>> 6) << SHIFT[i++ & 3]; | ||
| blocks2[i >>> 2] |= (128 | code & 63) << SHIFT[i++ & 3]; | ||
| } else if (code < 55296 || code >= 57344) { | ||
| blocks2[i >>> 2] |= (224 | code >>> 12) << SHIFT[i++ & 3]; | ||
| blocks2[i >>> 2] |= (128 | code >>> 6 & 63) << SHIFT[i++ & 3]; | ||
| blocks2[i >>> 2] |= (128 | code & 63) << SHIFT[i++ & 3]; | ||
| } else { | ||
| code = 65536 + ((code & 1023) << 10 | message.charCodeAt(++index) & 1023); | ||
| blocks2[i >>> 2] |= (240 | code >>> 18) << SHIFT[i++ & 3]; | ||
| blocks2[i >>> 2] |= (128 | code >>> 12 & 63) << SHIFT[i++ & 3]; | ||
| blocks2[i >>> 2] |= (128 | code >>> 6 & 63) << SHIFT[i++ & 3]; | ||
| blocks2[i >>> 2] |= (128 | code & 63) << SHIFT[i++ & 3]; | ||
| } | ||
| } | ||
| } | ||
| this.lastByteIndex = i; | ||
| this.bytes += i - this.start; | ||
| if (i >= 64) { | ||
| this.block = blocks2[16]; | ||
| this.start = i - 64; | ||
| this.hash(); | ||
| this.hashed = true; | ||
| } else { | ||
| this.start = i; | ||
| } | ||
| } | ||
| if (this.bytes > 4294967295) { | ||
| this.hBytes += this.bytes / 4294967296 << 0; | ||
| this.bytes = this.bytes % 4294967296; | ||
| } | ||
| return this; | ||
| }; | ||
| Sha256.prototype.finalize = function() { | ||
| if (this.finalized) { | ||
| return; | ||
| } | ||
| this.finalized = true; | ||
| var blocks2 = this.blocks, i = this.lastByteIndex; | ||
| blocks2[16] = this.block; | ||
| blocks2[i >>> 2] |= EXTRA[i & 3]; | ||
| this.block = blocks2[16]; | ||
| if (i >= 56) { | ||
| if (!this.hashed) { | ||
| this.hash(); | ||
| } | ||
| blocks2[0] = this.block; | ||
| blocks2[16] = blocks2[1] = blocks2[2] = blocks2[3] = blocks2[4] = blocks2[5] = blocks2[6] = blocks2[7] = blocks2[8] = blocks2[9] = blocks2[10] = blocks2[11] = blocks2[12] = blocks2[13] = blocks2[14] = blocks2[15] = 0; | ||
| } | ||
| blocks2[14] = this.hBytes << 3 | this.bytes >>> 29; | ||
| blocks2[15] = this.bytes << 3; | ||
| this.hash(); | ||
| }; | ||
| Sha256.prototype.hash = function() { | ||
| var a = this.h0, b = this.h1, c = this.h2, d = this.h3, e = this.h4, f = this.h5, g = this.h6, h = this.h7, blocks2 = this.blocks, j, s0, s1, maj, t1, t2, ch, ab, da, cd, bc; | ||
| for (j = 16; j < 64; ++j) { | ||
| t1 = blocks2[j - 15]; | ||
| s0 = (t1 >>> 7 | t1 << 25) ^ (t1 >>> 18 | t1 << 14) ^ t1 >>> 3; | ||
| t1 = blocks2[j - 2]; | ||
| s1 = (t1 >>> 17 | t1 << 15) ^ (t1 >>> 19 | t1 << 13) ^ t1 >>> 10; | ||
| blocks2[j] = blocks2[j - 16] + s0 + blocks2[j - 7] + s1 << 0; | ||
| } | ||
| bc = b & c; | ||
| for (j = 0; j < 64; j += 4) { | ||
| if (this.first) { | ||
| if (this.is224) { | ||
| ab = 300032; | ||
| t1 = blocks2[0] - 1413257819; | ||
| h = t1 - 150054599 << 0; | ||
| d = t1 + 24177077 << 0; | ||
| } else { | ||
| ab = 704751109; | ||
| t1 = blocks2[0] - 210244248; | ||
| h = t1 - 1521486534 << 0; | ||
| d = t1 + 143694565 << 0; | ||
| } | ||
| this.first = false; | ||
| } else { | ||
| s0 = (a >>> 2 | a << 30) ^ (a >>> 13 | a << 19) ^ (a >>> 22 | a << 10); | ||
| s1 = (e >>> 6 | e << 26) ^ (e >>> 11 | e << 21) ^ (e >>> 25 | e << 7); | ||
| ab = a & b; | ||
| maj = ab ^ a & c ^ bc; | ||
| ch = e & f ^ ~e & g; | ||
| t1 = h + s1 + ch + K[j] + blocks2[j]; | ||
| t2 = s0 + maj; | ||
| h = d + t1 << 0; | ||
| d = t1 + t2 << 0; | ||
| } | ||
| s0 = (d >>> 2 | d << 30) ^ (d >>> 13 | d << 19) ^ (d >>> 22 | d << 10); | ||
| s1 = (h >>> 6 | h << 26) ^ (h >>> 11 | h << 21) ^ (h >>> 25 | h << 7); | ||
| da = d & a; | ||
| maj = da ^ d & b ^ ab; | ||
| ch = h & e ^ ~h & f; | ||
| t1 = g + s1 + ch + K[j + 1] + blocks2[j + 1]; | ||
| t2 = s0 + maj; | ||
| g = c + t1 << 0; | ||
| c = t1 + t2 << 0; | ||
| s0 = (c >>> 2 | c << 30) ^ (c >>> 13 | c << 19) ^ (c >>> 22 | c << 10); | ||
| s1 = (g >>> 6 | g << 26) ^ (g >>> 11 | g << 21) ^ (g >>> 25 | g << 7); | ||
| cd = c & d; | ||
| maj = cd ^ c & a ^ da; | ||
| ch = g & h ^ ~g & e; | ||
| t1 = f + s1 + ch + K[j + 2] + blocks2[j + 2]; | ||
| t2 = s0 + maj; | ||
| f = b + t1 << 0; | ||
| b = t1 + t2 << 0; | ||
| s0 = (b >>> 2 | b << 30) ^ (b >>> 13 | b << 19) ^ (b >>> 22 | b << 10); | ||
| s1 = (f >>> 6 | f << 26) ^ (f >>> 11 | f << 21) ^ (f >>> 25 | f << 7); | ||
| bc = b & c; | ||
| maj = bc ^ b & d ^ cd; | ||
| ch = f & g ^ ~f & h; | ||
| t1 = e + s1 + ch + K[j + 3] + blocks2[j + 3]; | ||
| t2 = s0 + maj; | ||
| e = a + t1 << 0; | ||
| a = t1 + t2 << 0; | ||
| this.chromeBugWorkAround = true; | ||
| } | ||
| this.h0 = this.h0 + a << 0; | ||
| this.h1 = this.h1 + b << 0; | ||
| this.h2 = this.h2 + c << 0; | ||
| this.h3 = this.h3 + d << 0; | ||
| this.h4 = this.h4 + e << 0; | ||
| this.h5 = this.h5 + f << 0; | ||
| this.h6 = this.h6 + g << 0; | ||
| this.h7 = this.h7 + h << 0; | ||
| }; | ||
| Sha256.prototype.hex = function() { | ||
| this.finalize(); | ||
| var h0 = this.h0, h1 = this.h1, h2 = this.h2, h3 = this.h3, h4 = this.h4, h5 = this.h5, h6 = this.h6, h7 = this.h7; | ||
| var hex = HEX_CHARS[h0 >>> 28 & 15] + HEX_CHARS[h0 >>> 24 & 15] + HEX_CHARS[h0 >>> 20 & 15] + HEX_CHARS[h0 >>> 16 & 15] + HEX_CHARS[h0 >>> 12 & 15] + HEX_CHARS[h0 >>> 8 & 15] + HEX_CHARS[h0 >>> 4 & 15] + HEX_CHARS[h0 & 15] + HEX_CHARS[h1 >>> 28 & 15] + HEX_CHARS[h1 >>> 24 & 15] + HEX_CHARS[h1 >>> 20 & 15] + HEX_CHARS[h1 >>> 16 & 15] + HEX_CHARS[h1 >>> 12 & 15] + HEX_CHARS[h1 >>> 8 & 15] + HEX_CHARS[h1 >>> 4 & 15] + HEX_CHARS[h1 & 15] + HEX_CHARS[h2 >>> 28 & 15] + HEX_CHARS[h2 >>> 24 & 15] + HEX_CHARS[h2 >>> 20 & 15] + HEX_CHARS[h2 >>> 16 & 15] + HEX_CHARS[h2 >>> 12 & 15] + HEX_CHARS[h2 >>> 8 & 15] + HEX_CHARS[h2 >>> 4 & 15] + HEX_CHARS[h2 & 15] + HEX_CHARS[h3 >>> 28 & 15] + HEX_CHARS[h3 >>> 24 & 15] + HEX_CHARS[h3 >>> 20 & 15] + HEX_CHARS[h3 >>> 16 & 15] + HEX_CHARS[h3 >>> 12 & 15] + HEX_CHARS[h3 >>> 8 & 15] + HEX_CHARS[h3 >>> 4 & 15] + HEX_CHARS[h3 & 15] + HEX_CHARS[h4 >>> 28 & 15] + HEX_CHARS[h4 >>> 24 & 15] + HEX_CHARS[h4 >>> 20 & 15] + HEX_CHARS[h4 >>> 16 & 15] + HEX_CHARS[h4 >>> 12 & 15] + HEX_CHARS[h4 >>> 8 & 15] + HEX_CHARS[h4 >>> 4 & 15] + HEX_CHARS[h4 & 15] + HEX_CHARS[h5 >>> 28 & 15] + HEX_CHARS[h5 >>> 24 & 15] + HEX_CHARS[h5 >>> 20 & 15] + HEX_CHARS[h5 >>> 16 & 15] + HEX_CHARS[h5 >>> 12 & 15] + HEX_CHARS[h5 >>> 8 & 15] + HEX_CHARS[h5 >>> 4 & 15] + HEX_CHARS[h5 & 15] + HEX_CHARS[h6 >>> 28 & 15] + HEX_CHARS[h6 >>> 24 & 15] + HEX_CHARS[h6 >>> 20 & 15] + HEX_CHARS[h6 >>> 16 & 15] + HEX_CHARS[h6 >>> 12 & 15] + HEX_CHARS[h6 >>> 8 & 15] + HEX_CHARS[h6 >>> 4 & 15] + HEX_CHARS[h6 & 15]; | ||
| if (!this.is224) { | ||
| hex += HEX_CHARS[h7 >>> 28 & 15] + HEX_CHARS[h7 >>> 24 & 15] + HEX_CHARS[h7 >>> 20 & 15] + HEX_CHARS[h7 >>> 16 & 15] + HEX_CHARS[h7 >>> 12 & 15] + HEX_CHARS[h7 >>> 8 & 15] + HEX_CHARS[h7 >>> 4 & 15] + HEX_CHARS[h7 & 15]; | ||
| } | ||
| return hex; | ||
| }; | ||
| Sha256.prototype.toString = Sha256.prototype.hex; | ||
| Sha256.prototype.digest = function() { | ||
| this.finalize(); | ||
| var h0 = this.h0, h1 = this.h1, h2 = this.h2, h3 = this.h3, h4 = this.h4, h5 = this.h5, h6 = this.h6, h7 = this.h7; | ||
| var arr = [ | ||
| h0 >>> 24 & 255, | ||
| h0 >>> 16 & 255, | ||
| h0 >>> 8 & 255, | ||
| h0 & 255, | ||
| h1 >>> 24 & 255, | ||
| h1 >>> 16 & 255, | ||
| h1 >>> 8 & 255, | ||
| h1 & 255, | ||
| h2 >>> 24 & 255, | ||
| h2 >>> 16 & 255, | ||
| h2 >>> 8 & 255, | ||
| h2 & 255, | ||
| h3 >>> 24 & 255, | ||
| h3 >>> 16 & 255, | ||
| h3 >>> 8 & 255, | ||
| h3 & 255, | ||
| h4 >>> 24 & 255, | ||
| h4 >>> 16 & 255, | ||
| h4 >>> 8 & 255, | ||
| h4 & 255, | ||
| h5 >>> 24 & 255, | ||
| h5 >>> 16 & 255, | ||
| h5 >>> 8 & 255, | ||
| h5 & 255, | ||
| h6 >>> 24 & 255, | ||
| h6 >>> 16 & 255, | ||
| h6 >>> 8 & 255, | ||
| h6 & 255 | ||
| ]; | ||
| if (!this.is224) { | ||
| arr.push(h7 >>> 24 & 255, h7 >>> 16 & 255, h7 >>> 8 & 255, h7 & 255); | ||
| } | ||
| return arr; | ||
| }; | ||
| Sha256.prototype.array = Sha256.prototype.digest; | ||
| Sha256.prototype.arrayBuffer = function() { | ||
| this.finalize(); | ||
| var buffer = new ArrayBuffer(this.is224 ? 28 : 32); | ||
| var dataView = new DataView(buffer); | ||
| dataView.setUint32(0, this.h0); | ||
| dataView.setUint32(4, this.h1); | ||
| dataView.setUint32(8, this.h2); | ||
| dataView.setUint32(12, this.h3); | ||
| dataView.setUint32(16, this.h4); | ||
| dataView.setUint32(20, this.h5); | ||
| dataView.setUint32(24, this.h6); | ||
| if (!this.is224) { | ||
| dataView.setUint32(28, this.h7); | ||
| } | ||
| return buffer; | ||
| }; | ||
| function HmacSha256(key, is224, sharedMemory) { | ||
| var i, type = typeof key; | ||
| if (type === "string") { | ||
| var bytes = [], length = key.length, index = 0, code; | ||
| for (i = 0; i < length; ++i) { | ||
| code = key.charCodeAt(i); | ||
| if (code < 128) { | ||
| bytes[index++] = code; | ||
| } else if (code < 2048) { | ||
| bytes[index++] = 192 | code >>> 6; | ||
| bytes[index++] = 128 | code & 63; | ||
| } else if (code < 55296 || code >= 57344) { | ||
| bytes[index++] = 224 | code >>> 12; | ||
| bytes[index++] = 128 | code >>> 6 & 63; | ||
| bytes[index++] = 128 | code & 63; | ||
| } else { | ||
| code = 65536 + ((code & 1023) << 10 | key.charCodeAt(++i) & 1023); | ||
| bytes[index++] = 240 | code >>> 18; | ||
| bytes[index++] = 128 | code >>> 12 & 63; | ||
| bytes[index++] = 128 | code >>> 6 & 63; | ||
| bytes[index++] = 128 | code & 63; | ||
| } | ||
| } | ||
| key = bytes; | ||
| } else { | ||
| if (type === "object") { | ||
| if (key === null) { | ||
| throw new Error(ERROR); | ||
| } else if (ARRAY_BUFFER && key.constructor === ArrayBuffer) { | ||
| key = new Uint8Array(key); | ||
| } else if (!Array.isArray(key)) { | ||
| if (!ARRAY_BUFFER || !ArrayBuffer.isView(key)) { | ||
| throw new Error(ERROR); | ||
| } | ||
| } | ||
| } else { | ||
| throw new Error(ERROR); | ||
| } | ||
| } | ||
| if (key.length > 64) { | ||
| key = new Sha256(is224, true).update(key).array(); | ||
| } | ||
| var oKeyPad = [], iKeyPad = []; | ||
| for (i = 0; i < 64; ++i) { | ||
| var b = key[i] || 0; | ||
| oKeyPad[i] = 92 ^ b; | ||
| iKeyPad[i] = 54 ^ b; | ||
| } | ||
| Sha256.call(this, is224, sharedMemory); | ||
| this.update(iKeyPad); | ||
| this.oKeyPad = oKeyPad; | ||
| this.inner = true; | ||
| this.sharedMemory = sharedMemory; | ||
| } | ||
| HmacSha256.prototype = new Sha256(); | ||
| HmacSha256.prototype.finalize = function() { | ||
| Sha256.prototype.finalize.call(this); | ||
| if (this.inner) { | ||
| this.inner = false; | ||
| var innerHash = this.array(); | ||
| Sha256.call(this, this.is224, this.sharedMemory); | ||
| this.update(this.oKeyPad); | ||
| this.update(innerHash); | ||
| Sha256.prototype.finalize.call(this); | ||
| } | ||
| }; | ||
| var exports2 = createMethod(); | ||
| exports2.sha256 = exports2; | ||
| exports2.sha224 = createMethod(true); | ||
| exports2.sha256.hmac = createHmacMethod(); | ||
| exports2.sha224.hmac = createHmacMethod(true); | ||
| if (COMMON_JS) { | ||
| module2.exports = exports2; | ||
| } else { | ||
| root.sha256 = exports2.sha256; | ||
| root.sha224 = exports2.sha224; | ||
| if (AMD) { | ||
| define(function() { | ||
| return exports2; | ||
| }); | ||
| } | ||
| } | ||
| })(); | ||
| } | ||
| }); | ||
| // src/utils.ts | ||
| var utils_exports = {}; | ||
| __export(utils_exports, { | ||
| assert: () => assert, | ||
| enableDebug: () => enableDebug, | ||
| generateHashId: () => generateHashId, | ||
| getDebug: () => getDebug, | ||
| ifInBrowser: () => ifInBrowser, | ||
@@ -562,3 +43,4 @@ uuid: () => uuid | ||
| module.exports = __toCommonJS(utils_exports); | ||
| var import_js_sha256 = __toESM(require_sha256()); | ||
| var import_js_sha256 = require("js-sha256"); | ||
| var import_debug = __toESM(require("debug")); | ||
| var ifInBrowser = typeof window !== "undefined"; | ||
@@ -569,2 +51,9 @@ function uuid() { | ||
| var hashMap = {}; | ||
| var topicPrefix = "midscene"; | ||
| function getDebug(topic) { | ||
| return (0, import_debug.default)(`${topicPrefix}:${topic}`); | ||
| } | ||
| function enableDebug(topic) { | ||
| import_debug.default.enable(`${topicPrefix}:${topic}`); | ||
| } | ||
| function generateHashId(rect, content = "") { | ||
@@ -596,19 +85,15 @@ const combined = JSON.stringify({ | ||
| } | ||
| function assert(condition, message) { | ||
| if (!condition) { | ||
| throw new Error(message || "Assertion failed"); | ||
| } | ||
| } | ||
| // Annotate the CommonJS export names for ESM import in node: | ||
| 0 && (module.exports = { | ||
| assert, | ||
| enableDebug, | ||
| generateHashId, | ||
| getDebug, | ||
| ifInBrowser, | ||
| uuid | ||
| }); | ||
| /*! Bundled license information: | ||
| js-sha256/src/sha256.js: | ||
| (** | ||
| * [js-sha256]{@link https://github.com/emn178/js-sha256} | ||
| * | ||
| * @version 0.11.0 | ||
| * @author Chen, Yi-Cyuan [emn178@gmail.com] | ||
| * @copyright Chen, Yi-Cyuan 2014-2024 | ||
| * @license MIT | ||
| *) | ||
| */ |
@@ -573,2 +573,468 @@ "use strict"; | ||
| // ../../node_modules/.pnpm/ms@2.1.3/node_modules/ms/index.js | ||
| var require_ms = __commonJS({ | ||
| "../../node_modules/.pnpm/ms@2.1.3/node_modules/ms/index.js"(exports, module) { | ||
| "use strict"; | ||
| var s = 1e3; | ||
| var m = s * 60; | ||
| var h = m * 60; | ||
| var d = h * 24; | ||
| var w = d * 7; | ||
| var y = d * 365.25; | ||
| module.exports = function(val, options) { | ||
| options = options || {}; | ||
| var type = typeof val; | ||
| if (type === "string" && val.length > 0) { | ||
| return parse(val); | ||
| } else if (type === "number" && isFinite(val)) { | ||
| return options.long ? fmtLong(val) : fmtShort(val); | ||
| } | ||
| throw new Error( | ||
| "val is not a non-empty string or a valid number. val=" + JSON.stringify(val) | ||
| ); | ||
| }; | ||
| function parse(str) { | ||
| str = String(str); | ||
| if (str.length > 100) { | ||
| return; | ||
| } | ||
| var match = /^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec( | ||
| str | ||
| ); | ||
| if (!match) { | ||
| return; | ||
| } | ||
| var n = parseFloat(match[1]); | ||
| var type = (match[2] || "ms").toLowerCase(); | ||
| switch (type) { | ||
| case "years": | ||
| case "year": | ||
| case "yrs": | ||
| case "yr": | ||
| case "y": | ||
| return n * y; | ||
| case "weeks": | ||
| case "week": | ||
| case "w": | ||
| return n * w; | ||
| case "days": | ||
| case "day": | ||
| case "d": | ||
| return n * d; | ||
| case "hours": | ||
| case "hour": | ||
| case "hrs": | ||
| case "hr": | ||
| case "h": | ||
| return n * h; | ||
| case "minutes": | ||
| case "minute": | ||
| case "mins": | ||
| case "min": | ||
| case "m": | ||
| return n * m; | ||
| case "seconds": | ||
| case "second": | ||
| case "secs": | ||
| case "sec": | ||
| case "s": | ||
| return n * s; | ||
| case "milliseconds": | ||
| case "millisecond": | ||
| case "msecs": | ||
| case "msec": | ||
| case "ms": | ||
| return n; | ||
| default: | ||
| return void 0; | ||
| } | ||
| } | ||
| function fmtShort(ms) { | ||
| var msAbs = Math.abs(ms); | ||
| if (msAbs >= d) { | ||
| return Math.round(ms / d) + "d"; | ||
| } | ||
| if (msAbs >= h) { | ||
| return Math.round(ms / h) + "h"; | ||
| } | ||
| if (msAbs >= m) { | ||
| return Math.round(ms / m) + "m"; | ||
| } | ||
| if (msAbs >= s) { | ||
| return Math.round(ms / s) + "s"; | ||
| } | ||
| return ms + "ms"; | ||
| } | ||
| function fmtLong(ms) { | ||
| var msAbs = Math.abs(ms); | ||
| if (msAbs >= d) { | ||
| return plural(ms, msAbs, d, "day"); | ||
| } | ||
| if (msAbs >= h) { | ||
| return plural(ms, msAbs, h, "hour"); | ||
| } | ||
| if (msAbs >= m) { | ||
| return plural(ms, msAbs, m, "minute"); | ||
| } | ||
| if (msAbs >= s) { | ||
| return plural(ms, msAbs, s, "second"); | ||
| } | ||
| return ms + " ms"; | ||
| } | ||
| function plural(ms, msAbs, n, name) { | ||
| var isPlural = msAbs >= n * 1.5; | ||
| return Math.round(ms / n) + " " + name + (isPlural ? "s" : ""); | ||
| } | ||
| } | ||
| }); | ||
| // ../../node_modules/.pnpm/debug@4.4.0_supports-color@5.5.0/node_modules/debug/src/common.js | ||
| var require_common = __commonJS({ | ||
| "../../node_modules/.pnpm/debug@4.4.0_supports-color@5.5.0/node_modules/debug/src/common.js"(exports, module) { | ||
| "use strict"; | ||
| function setup(env) { | ||
| createDebug.debug = createDebug; | ||
| createDebug.default = createDebug; | ||
| createDebug.coerce = coerce; | ||
| createDebug.disable = disable; | ||
| createDebug.enable = enable; | ||
| createDebug.enabled = enabled; | ||
| createDebug.humanize = require_ms(); | ||
| createDebug.destroy = destroy; | ||
| Object.keys(env).forEach((key) => { | ||
| createDebug[key] = env[key]; | ||
| }); | ||
| createDebug.names = []; | ||
| createDebug.skips = []; | ||
| createDebug.formatters = {}; | ||
| function selectColor(namespace) { | ||
| let hash = 0; | ||
| for (let i = 0; i < namespace.length; i++) { | ||
| hash = (hash << 5) - hash + namespace.charCodeAt(i); | ||
| hash |= 0; | ||
| } | ||
| return createDebug.colors[Math.abs(hash) % createDebug.colors.length]; | ||
| } | ||
| createDebug.selectColor = selectColor; | ||
| function createDebug(namespace) { | ||
| let prevTime; | ||
| let enableOverride = null; | ||
| let namespacesCache; | ||
| let enabledCache; | ||
| function debug2(...args) { | ||
| if (!debug2.enabled) { | ||
| return; | ||
| } | ||
| const self2 = debug2; | ||
| const curr = Number(/* @__PURE__ */ new Date()); | ||
| const ms = curr - (prevTime || curr); | ||
| self2.diff = ms; | ||
| self2.prev = prevTime; | ||
| self2.curr = curr; | ||
| prevTime = curr; | ||
| args[0] = createDebug.coerce(args[0]); | ||
| if (typeof args[0] !== "string") { | ||
| args.unshift("%O"); | ||
| } | ||
| let index = 0; | ||
| args[0] = args[0].replace(/%([a-zA-Z%])/g, (match, format) => { | ||
| if (match === "%%") { | ||
| return "%"; | ||
| } | ||
| index++; | ||
| const formatter = createDebug.formatters[format]; | ||
| if (typeof formatter === "function") { | ||
| const val = args[index]; | ||
| match = formatter.call(self2, val); | ||
| args.splice(index, 1); | ||
| index--; | ||
| } | ||
| return match; | ||
| }); | ||
| createDebug.formatArgs.call(self2, args); | ||
| const logFn = self2.log || createDebug.log; | ||
| logFn.apply(self2, args); | ||
| } | ||
| debug2.namespace = namespace; | ||
| debug2.useColors = createDebug.useColors(); | ||
| debug2.color = createDebug.selectColor(namespace); | ||
| debug2.extend = extend; | ||
| debug2.destroy = createDebug.destroy; | ||
| Object.defineProperty(debug2, "enabled", { | ||
| enumerable: true, | ||
| configurable: false, | ||
| get: () => { | ||
| if (enableOverride !== null) { | ||
| return enableOverride; | ||
| } | ||
| if (namespacesCache !== createDebug.namespaces) { | ||
| namespacesCache = createDebug.namespaces; | ||
| enabledCache = createDebug.enabled(namespace); | ||
| } | ||
| return enabledCache; | ||
| }, | ||
| set: (v) => { | ||
| enableOverride = v; | ||
| } | ||
| }); | ||
| if (typeof createDebug.init === "function") { | ||
| createDebug.init(debug2); | ||
| } | ||
| return debug2; | ||
| } | ||
| function extend(namespace, delimiter) { | ||
| const newDebug = createDebug(this.namespace + (typeof delimiter === "undefined" ? ":" : delimiter) + namespace); | ||
| newDebug.log = this.log; | ||
| return newDebug; | ||
| } | ||
| function enable(namespaces) { | ||
| createDebug.save(namespaces); | ||
| createDebug.namespaces = namespaces; | ||
| createDebug.names = []; | ||
| createDebug.skips = []; | ||
| const split = (typeof namespaces === "string" ? namespaces : "").trim().replace(" ", ",").split(",").filter(Boolean); | ||
| for (const ns of split) { | ||
| if (ns[0] === "-") { | ||
| createDebug.skips.push(ns.slice(1)); | ||
| } else { | ||
| createDebug.names.push(ns); | ||
| } | ||
| } | ||
| } | ||
| function matchesTemplate(search, template) { | ||
| let searchIndex = 0; | ||
| let templateIndex = 0; | ||
| let starIndex = -1; | ||
| let matchIndex = 0; | ||
| while (searchIndex < search.length) { | ||
| if (templateIndex < template.length && (template[templateIndex] === search[searchIndex] || template[templateIndex] === "*")) { | ||
| if (template[templateIndex] === "*") { | ||
| starIndex = templateIndex; | ||
| matchIndex = searchIndex; | ||
| templateIndex++; | ||
| } else { | ||
| searchIndex++; | ||
| templateIndex++; | ||
| } | ||
| } else if (starIndex !== -1) { | ||
| templateIndex = starIndex + 1; | ||
| matchIndex++; | ||
| searchIndex = matchIndex; | ||
| } else { | ||
| return false; | ||
| } | ||
| } | ||
| while (templateIndex < template.length && template[templateIndex] === "*") { | ||
| templateIndex++; | ||
| } | ||
| return templateIndex === template.length; | ||
| } | ||
| function disable() { | ||
| const namespaces = [ | ||
| ...createDebug.names, | ||
| ...createDebug.skips.map((namespace) => "-" + namespace) | ||
| ].join(","); | ||
| createDebug.enable(""); | ||
| return namespaces; | ||
| } | ||
| function enabled(name) { | ||
| for (const skip of createDebug.skips) { | ||
| if (matchesTemplate(name, skip)) { | ||
| return false; | ||
| } | ||
| } | ||
| for (const ns of createDebug.names) { | ||
| if (matchesTemplate(name, ns)) { | ||
| return true; | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
| function coerce(val) { | ||
| if (val instanceof Error) { | ||
| return val.stack || val.message; | ||
| } | ||
| return val; | ||
| } | ||
| function destroy() { | ||
| console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."); | ||
| } | ||
| createDebug.enable(createDebug.load()); | ||
| return createDebug; | ||
| } | ||
| module.exports = setup; | ||
| } | ||
| }); | ||
| // ../../node_modules/.pnpm/debug@4.4.0_supports-color@5.5.0/node_modules/debug/src/browser.js | ||
| var require_browser = __commonJS({ | ||
| "../../node_modules/.pnpm/debug@4.4.0_supports-color@5.5.0/node_modules/debug/src/browser.js"(exports, module) { | ||
| "use strict"; | ||
| exports.formatArgs = formatArgs; | ||
| exports.save = save; | ||
| exports.load = load; | ||
| exports.useColors = useColors; | ||
| exports.storage = localstorage(); | ||
| exports.destroy = (() => { | ||
| let warned = false; | ||
| return () => { | ||
| if (!warned) { | ||
| warned = true; | ||
| console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."); | ||
| } | ||
| }; | ||
| })(); | ||
| exports.colors = [ | ||
| "#0000CC", | ||
| "#0000FF", | ||
| "#0033CC", | ||
| "#0033FF", | ||
| "#0066CC", | ||
| "#0066FF", | ||
| "#0099CC", | ||
| "#0099FF", | ||
| "#00CC00", | ||
| "#00CC33", | ||
| "#00CC66", | ||
| "#00CC99", | ||
| "#00CCCC", | ||
| "#00CCFF", | ||
| "#3300CC", | ||
| "#3300FF", | ||
| "#3333CC", | ||
| "#3333FF", | ||
| "#3366CC", | ||
| "#3366FF", | ||
| "#3399CC", | ||
| "#3399FF", | ||
| "#33CC00", | ||
| "#33CC33", | ||
| "#33CC66", | ||
| "#33CC99", | ||
| "#33CCCC", | ||
| "#33CCFF", | ||
| "#6600CC", | ||
| "#6600FF", | ||
| "#6633CC", | ||
| "#6633FF", | ||
| "#66CC00", | ||
| "#66CC33", | ||
| "#9900CC", | ||
| "#9900FF", | ||
| "#9933CC", | ||
| "#9933FF", | ||
| "#99CC00", | ||
| "#99CC33", | ||
| "#CC0000", | ||
| "#CC0033", | ||
| "#CC0066", | ||
| "#CC0099", | ||
| "#CC00CC", | ||
| "#CC00FF", | ||
| "#CC3300", | ||
| "#CC3333", | ||
| "#CC3366", | ||
| "#CC3399", | ||
| "#CC33CC", | ||
| "#CC33FF", | ||
| "#CC6600", | ||
| "#CC6633", | ||
| "#CC9900", | ||
| "#CC9933", | ||
| "#CCCC00", | ||
| "#CCCC33", | ||
| "#FF0000", | ||
| "#FF0033", | ||
| "#FF0066", | ||
| "#FF0099", | ||
| "#FF00CC", | ||
| "#FF00FF", | ||
| "#FF3300", | ||
| "#FF3333", | ||
| "#FF3366", | ||
| "#FF3399", | ||
| "#FF33CC", | ||
| "#FF33FF", | ||
| "#FF6600", | ||
| "#FF6633", | ||
| "#FF9900", | ||
| "#FF9933", | ||
| "#FFCC00", | ||
| "#FFCC33" | ||
| ]; | ||
| function useColors() { | ||
| if (typeof window !== "undefined" && window.process && (window.process.type === "renderer" || window.process.__nwjs)) { | ||
| return true; | ||
| } | ||
| if (typeof navigator !== "undefined" && navigator.userAgent && navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)) { | ||
| return false; | ||
| } | ||
| let m; | ||
| return typeof document !== "undefined" && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance || // Is firebug? http://stackoverflow.com/a/398120/376773 | ||
| typeof window !== "undefined" && window.console && (window.console.firebug || window.console.exception && window.console.table) || // Is firefox >= v31? | ||
| // https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages | ||
| typeof navigator !== "undefined" && navigator.userAgent && (m = navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)) && parseInt(m[1], 10) >= 31 || // Double check webkit in userAgent just in case we are in a worker | ||
| typeof navigator !== "undefined" && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/); | ||
| } | ||
| function formatArgs(args) { | ||
| args[0] = (this.useColors ? "%c" : "") + this.namespace + (this.useColors ? " %c" : " ") + args[0] + (this.useColors ? "%c " : " ") + "+" + module.exports.humanize(this.diff); | ||
| if (!this.useColors) { | ||
| return; | ||
| } | ||
| const c = "color: " + this.color; | ||
| args.splice(1, 0, c, "color: inherit"); | ||
| let index = 0; | ||
| let lastC = 0; | ||
| args[0].replace(/%[a-zA-Z%]/g, (match) => { | ||
| if (match === "%%") { | ||
| return; | ||
| } | ||
| index++; | ||
| if (match === "%c") { | ||
| lastC = index; | ||
| } | ||
| }); | ||
| args.splice(lastC, 0, c); | ||
| } | ||
| exports.log = console.debug || console.log || (() => { | ||
| }); | ||
| function save(namespaces) { | ||
| try { | ||
| if (namespaces) { | ||
| exports.storage.setItem("debug", namespaces); | ||
| } else { | ||
| exports.storage.removeItem("debug"); | ||
| } | ||
| } catch (error) { | ||
| } | ||
| } | ||
| function load() { | ||
| let r; | ||
| try { | ||
| r = exports.storage.getItem("debug"); | ||
| } catch (error) { | ||
| } | ||
| if (!r && typeof process !== "undefined" && "env" in process) { | ||
| r = process.env.DEBUG; | ||
| } | ||
| return r; | ||
| } | ||
| function localstorage() { | ||
| try { | ||
| return localStorage; | ||
| } catch (error) { | ||
| } | ||
| } | ||
| module.exports = require_common()(exports); | ||
| var { formatters } = module.exports; | ||
| formatters.j = function(v) { | ||
| try { | ||
| return JSON.stringify(v); | ||
| } catch (error) { | ||
| return "[UnexpectedJSONParseError]: " + error.message; | ||
| } | ||
| }; | ||
| } | ||
| }); | ||
| // src/constants/index.ts | ||
@@ -648,2 +1114,3 @@ var CONTAINER_MINI_HEIGHT = 3; | ||
| var import_js_sha256 = __toESM(require_sha256()); | ||
| var import_debug = __toESM(require_browser()); | ||
| var hashMap = {}; | ||
@@ -937,24 +1404,4 @@ function generateHashId(rect, content = "") { | ||
| } | ||
| var nodeHashCacheList = []; | ||
| if (typeof window !== "undefined") { | ||
| window.midsceneNodeHashCacheList = window.midsceneNodeHashCacheList || []; | ||
| nodeHashCacheList = window.midsceneNodeHashCacheList; | ||
| } | ||
| function resetNodeHashCacheList() { | ||
| if (typeof window !== "undefined") { | ||
| nodeHashCacheList = window.midsceneNodeHashCacheList || []; | ||
| window.midsceneNodeHashCacheList = []; | ||
| } else { | ||
| nodeHashCacheList = []; | ||
| } | ||
| } | ||
| function midsceneGenerateHash(node, content, rect) { | ||
| var _a; | ||
| if (node && nodeHashCacheList.find((item) => item.node === node)) { | ||
| return ((_a = nodeHashCacheList.find((item) => item.node === node)) == null ? void 0 : _a.id) || ""; | ||
| } | ||
| const slicedHash = generateHashId(rect, content); | ||
| if (node && typeof window !== "undefined") { | ||
| window.midsceneNodeHashCacheList.push({ node, id: slicedHash }); | ||
| } | ||
| return slicedHash; | ||
@@ -1173,3 +1620,2 @@ } | ||
| setDebugMode(debugMode2); | ||
| resetNodeHashCacheList(); | ||
| indexId = 0; | ||
@@ -1176,0 +1622,0 @@ const topDocument = getTopDocument(); |
+24
-140
| { | ||
| "name": "@aico-test/shared", | ||
| "version": "6.0.0", | ||
| "version": "7.0.0", | ||
| "types": "./src/index.ts", | ||
@@ -9,47 +9,10 @@ "type": "commonjs", | ||
| "exports": { | ||
| ".": { | ||
| "types": "./src/index.ts", | ||
| "require": "./dist/lib/index.js", | ||
| "import": "./dist/es/index.js" | ||
| }, | ||
| "./constants": { | ||
| "types": "./src/constants/index.ts", | ||
| "require": "./dist/lib/constants.js", | ||
| "import": "./dist/es/constants.js" | ||
| }, | ||
| "./fs": { | ||
| "types": "./src/fs/index.ts", | ||
| "require": "./dist/lib/fs.js", | ||
| "import": "./dist/es/fs.js" | ||
| }, | ||
| "./img": { | ||
| "types": "./src/img/index.ts", | ||
| "require": "./dist/lib/img.js", | ||
| "import": "./dist/es/img.js" | ||
| }, | ||
| "./browser/img": { | ||
| "types": "./src/img/index.ts", | ||
| "require": "./dist/browser/img.js", | ||
| "import": "./dist/browser/img.js" | ||
| }, | ||
| "./utils": { | ||
| "types": "./src/utils.ts", | ||
| "require": "./dist/lib/utils.js", | ||
| "import": "./dist/es/utils.js" | ||
| }, | ||
| "./extractor": { | ||
| "types": "./src/extractor/index.ts", | ||
| "require": "./dist/lib/extractor.js", | ||
| "import": "./dist/es/extractor.js" | ||
| }, | ||
| "./extractor-debug": { | ||
| "types": "./src/extractor/debug.ts", | ||
| "require": "./dist/lib/extractor-debug.js", | ||
| "import": "./dist/es/extractor-debug.js" | ||
| }, | ||
| "./keyboard-layout": { | ||
| "types": "./src/us-keyboard-layout.ts", | ||
| "require": "./dist/lib/us-keyboard-layout.js", | ||
| "import": "./dist/es/us-keyboard-layout.js" | ||
| } | ||
| ".": "./dist/lib/index.js", | ||
| "./constants": "./dist/lib/constants.js", | ||
| "./fs": "./dist/lib/fs.js", | ||
| "./img": "./dist/lib/img.js", | ||
| "./utils": "./dist/lib/utils.js", | ||
| "./extractor": "./dist/lib/extractor.js", | ||
| "./extractor-debug": "./dist/lib/extractor-debug.js", | ||
| "./keyboard-layout": "./dist/lib/us-keyboard-layout.js" | ||
| }, | ||
@@ -59,27 +22,24 @@ "typesVersions": { | ||
| ".": [ | ||
| "./src/index.ts" | ||
| "./dist/types/index.d.ts" | ||
| ], | ||
| "constants": [ | ||
| "./src/constants/index.ts" | ||
| "./dist/types/constants.d.ts" | ||
| ], | ||
| "img": [ | ||
| "./src/img/index.ts" | ||
| "./dist/types/img.d.ts" | ||
| ], | ||
| "browser/img": [ | ||
| "./src/img/index.ts" | ||
| ], | ||
| "fs": [ | ||
| "./src/fs/index.ts" | ||
| "./dist/types/fs.d.ts" | ||
| ], | ||
| "utils": [ | ||
| "./src/utils.ts" | ||
| "./dist/types/utils.d.ts" | ||
| ], | ||
| "extractor": [ | ||
| "./src/extractor/index.ts" | ||
| "./dist/types/extractor.d.ts" | ||
| ], | ||
| "extractor-debug": [ | ||
| "./src/extractor/debug.ts" | ||
| "./dist/types/extractor-debug.d.ts" | ||
| ], | ||
| "keyboard-layout": [ | ||
| "./src/us-keyboard-layout.ts" | ||
| "./dist/types/us-keyboard-layout.d.ts" | ||
| ] | ||
@@ -113,8 +73,10 @@ } | ||
| "dependencies": { | ||
| "jimp": "0.22.12" | ||
| "debug": "4.4.0", | ||
| "jimp": "0.22.12", | ||
| "js-sha256": "0.11.0" | ||
| }, | ||
| "devDependencies": { | ||
| "@modern-js/module-tools": "2.60.6", | ||
| "@types/node": "^18.19.76", | ||
| "js-sha256": "0.11.0", | ||
| "@types/debug": "4.1.12", | ||
| "@types/node": "^18.0.0", | ||
| "rimraf": "~3.0.2", | ||
@@ -127,82 +89,4 @@ "typescript": "~5.0.4", | ||
| "access": "public", | ||
| "registry": "https://registry.npmjs.org/", | ||
| "exports": { | ||
| ".": { | ||
| "types": "./dist/lib/index.d.ts", | ||
| "require": "./dist/lib/index.js", | ||
| "import": "./dist/es/index.js" | ||
| }, | ||
| "./constants": { | ||
| "types": "./dist/lib/constants.d.ts", | ||
| "require": "./dist/lib/constants.js", | ||
| "import": "./dist/es/constants.js" | ||
| }, | ||
| "./fs": { | ||
| "types": "./dist/lib/fs.d.ts", | ||
| "require": "./dist/lib/fs.js", | ||
| "import": "./dist/es/fs.js" | ||
| }, | ||
| "./img": { | ||
| "types": "./dist/lib/img.d.ts", | ||
| "require": "./dist/lib/img.js", | ||
| "import": "./dist/es/img.js" | ||
| }, | ||
| "./browser/img": { | ||
| "types": "./dist/browser/img.d.ts", | ||
| "require": "./dist/browser/img.js", | ||
| "import": "./dist/browser/img.js" | ||
| }, | ||
| "./utils": { | ||
| "types": "./dist/lib/utils.d.ts", | ||
| "require": "./dist/lib/utils.js", | ||
| "import": "./dist/es/utils.js" | ||
| }, | ||
| "./extractor": { | ||
| "types": "./dist/lib/extractor.d.ts", | ||
| "require": "./dist/lib/extractor.js", | ||
| "import": "./dist/es/extractor.js" | ||
| }, | ||
| "./extractor-debug": { | ||
| "types": "./dist/lib/extractor-debug.d.ts", | ||
| "require": "./dist/lib/extractor-debug.js", | ||
| "import": "./dist/es/extractor-debug.js" | ||
| }, | ||
| "./keyboard-layout": { | ||
| "types": "./dist/lib/us-keyboard-layout.d.ts", | ||
| "require": "./dist/lib/us-keyboard-layout.js", | ||
| "import": "./dist/es/us-keyboard-layout.js" | ||
| } | ||
| }, | ||
| "typesVersions": { | ||
| "*": { | ||
| ".": [ | ||
| "./dist/lib/index.d.ts" | ||
| ], | ||
| "constants": [ | ||
| "./dist/lib/constants.d.ts" | ||
| ], | ||
| "img": [ | ||
| "./dist/lib/img.d.ts" | ||
| ], | ||
| "browser/img": [ | ||
| "./dist/browser/img.d.ts" | ||
| ], | ||
| "fs": [ | ||
| "./dist/lib/fs.d.ts" | ||
| ], | ||
| "utils": [ | ||
| "./dist/lib/utils.d.ts" | ||
| ], | ||
| "extractor": [ | ||
| "./dist/lib/extractor.d.ts" | ||
| ], | ||
| "extractor-debug": [ | ||
| "./dist/lib/extractor-debug.d.ts" | ||
| ], | ||
| "keyboard-layout": [ | ||
| "./dist/lib/us-keyboard-layout.d.ts" | ||
| ] | ||
| } | ||
| } | ||
| "registry": "https://registry.npmjs.org/" | ||
| } | ||
| } | ||
| } |
@@ -5,2 +5,2 @@ export { | ||
| TEXT_SIZE_THRESHOLD, | ||
| } from '../constants'; | ||
| } from '../constants/index'; |
@@ -1,2 +0,2 @@ | ||
| import type { NodeType } from '../constants'; | ||
| import type { NodeType } from '../constants/index'; | ||
@@ -3,0 +3,0 @@ export interface ElementInfo { |
@@ -444,20 +444,2 @@ import { generateHashId } from '../utils'; | ||
| let nodeHashCacheList: { node: Node; id: string }[] = []; | ||
| if (typeof window !== 'undefined') { | ||
| (window as any).midsceneNodeHashCacheList = | ||
| (window as any).midsceneNodeHashCacheList || []; | ||
| nodeHashCacheList = (window as any).midsceneNodeHashCacheList; | ||
| } | ||
| const hashMap: Record<string, string> = {}; // id - combined | ||
| // for each run, reset the cache list | ||
| export function resetNodeHashCacheList() { | ||
| if (typeof window !== 'undefined') { | ||
| nodeHashCacheList = (window as any).midsceneNodeHashCacheList || []; | ||
| (window as any).midsceneNodeHashCacheList = []; | ||
| } else { | ||
| nodeHashCacheList = []; | ||
| } | ||
| } | ||
| export function midsceneGenerateHash( | ||
@@ -468,9 +450,3 @@ node: globalThis.Node | null, | ||
| ): string { | ||
| if (node && nodeHashCacheList.find((item) => item.node === node)) { | ||
| return nodeHashCacheList.find((item) => item.node === node)?.id || ''; | ||
| } | ||
| const slicedHash = generateHashId(rect, content); | ||
| if (node && typeof window !== 'undefined') { | ||
| (window as any).midsceneNodeHashCacheList.push({ node, id: slicedHash }); | ||
| } | ||
@@ -477,0 +453,0 @@ // Returns the first 10 characters as a short hash |
@@ -6,3 +6,3 @@ import type { ElementInfo } from '.'; | ||
| NodeType, | ||
| } from '../constants'; | ||
| } from '../constants/index'; | ||
| import type { Point } from '../types'; | ||
@@ -24,3 +24,2 @@ import { | ||
| midsceneGenerateHash, | ||
| resetNodeHashCacheList, | ||
| setDataForNode, | ||
@@ -297,3 +296,2 @@ setDebugMode, | ||
| setDebugMode(debugMode); | ||
| resetNodeHashCacheList(); | ||
| indexId = 0; | ||
@@ -300,0 +298,0 @@ |
+17
-11
@@ -65,3 +65,3 @@ import assert from 'node:assert'; | ||
| paddedRect.height, | ||
| function (x, y, idx) { | ||
| (x: number, y: number, idx: number): void => { | ||
| if ( | ||
@@ -73,6 +73,6 @@ x === paddedRect.left || | ||
| ) { | ||
| this.bitmap.data[idx + 0] = (color.rect >> 24) & 0xff; // R | ||
| this.bitmap.data[idx + 1] = (color.rect >> 16) & 0xff; // G | ||
| this.bitmap.data[idx + 2] = (color.rect >> 8) & 0xff; // B | ||
| this.bitmap.data[idx + 3] = color.rect & 0xff; // A | ||
| image.bitmap.data[idx + 0] = (color.rect >> 24) & 0xff; // R | ||
| image.bitmap.data[idx + 1] = (color.rect >> 16) & 0xff; // G | ||
| image.bitmap.data[idx + 2] = (color.rect >> 8) & 0xff; // B | ||
| image.bitmap.data[idx + 3] = color.rect & 0xff; // A | ||
| } | ||
@@ -155,8 +155,14 @@ }, | ||
| // Draw text background | ||
| image.scan(rectX, rectY, rectWidth, rectHeight, function (x, y, idx) { | ||
| this.bitmap.data[idx + 0] = (color.rect >> 24) & 0xff; // R | ||
| this.bitmap.data[idx + 1] = (color.rect >> 16) & 0xff; // G | ||
| this.bitmap.data[idx + 2] = (color.rect >> 8) & 0xff; // B | ||
| this.bitmap.data[idx + 3] = color.rect & 0xff; // A | ||
| }); | ||
| image.scan( | ||
| rectX, | ||
| rectY, | ||
| rectWidth, | ||
| rectHeight, | ||
| (x: number, y: number, idx: number): void => { | ||
| image.bitmap.data[idx + 0] = (color.rect >> 24) & 0xff; // R | ||
| image.bitmap.data[idx + 1] = (color.rect >> 16) & 0xff; // G | ||
| image.bitmap.data[idx + 2] = (color.rect >> 8) & 0xff; // B | ||
| image.bitmap.data[idx + 3] = color.rect & 0xff; // A | ||
| }, | ||
| ); | ||
| // Draw text (simplified, as Jimp doesn't have built-in text drawing) | ||
@@ -163,0 +169,0 @@ try { |
@@ -28,3 +28,3 @@ import type { Rect } from '../types'; | ||
| radius * 2, | ||
| function (x, y, idx) { | ||
| (x: number, y: number, idx: number) => { | ||
| // Calculate distance from current pixel to center | ||
@@ -35,6 +35,6 @@ const distance = Math.sqrt((x - centerX) ** 2 + (y - centerY) ** 2); | ||
| if (distance <= radius) { | ||
| this.bitmap.data[idx + 0] = color.r; | ||
| this.bitmap.data[idx + 1] = color.g; | ||
| this.bitmap.data[idx + 2] = color.b; | ||
| this.bitmap.data[idx + 3] = color.a; | ||
| image.bitmap.data[idx + 0] = color.r; | ||
| image.bitmap.data[idx + 1] = color.g; | ||
| image.bitmap.data[idx + 2] = color.b; | ||
| image.bitmap.data[idx + 3] = color.a; | ||
| } | ||
@@ -41,0 +41,0 @@ }, |
@@ -0,1 +1,2 @@ | ||
| // @ts-ignore | ||
| import type Jimp from 'jimp/browser/lib/jimp.js'; | ||
@@ -6,2 +7,3 @@ | ||
| if (ifInBrowser) { | ||
| // @ts-ignore | ||
| await import('jimp/browser/lib/jimp.js'); | ||
@@ -11,3 +13,4 @@ return (window as any).Jimp; | ||
| // return Jimp; | ||
| // @ts-ignore | ||
| return (await import('jimp')).default; | ||
| } |
+20
-3
| import assert from 'node:assert'; | ||
| import { Buffer } from 'node:buffer'; | ||
| import getDebug from 'debug'; | ||
| import getJimp from './get-jimp'; | ||
| const debugImg = getDebug('img'); | ||
| /** | ||
@@ -18,2 +20,3 @@ /** | ||
| }): Promise<void> { | ||
| debugImg(`saveBase64Image start: ${options.outputPath}`); | ||
| const { base64Data, outputPath } = options; | ||
@@ -30,2 +33,3 @@ // Remove the base64 data prefix (if any) | ||
| await image.writeAsync(outputPath); | ||
| debugImg(`saveBase64Image done: ${options.outputPath}`); | ||
| } | ||
@@ -40,6 +44,9 @@ | ||
| // Use Jimp to process images and generate base64 data | ||
| debugImg(`transformImgPathToBase64 start: ${inputPath}`); | ||
| const Jimp = await getJimp(); | ||
| const image = await Jimp.read(inputPath); | ||
| const buffer = await image.getBufferAsync(Jimp.MIME_JPEG); | ||
| return buffer.toString('base64'); | ||
| const res = buffer.toString('base64'); | ||
| debugImg(`transformImgPathToBase64 done: ${inputPath}`); | ||
| return res; | ||
| } | ||
@@ -69,2 +76,3 @@ | ||
| debugImg(`resizeImg start, target size: ${newSize.width}x${newSize.height}`); | ||
| const Jimp = await getJimp(); | ||
@@ -85,2 +93,3 @@ const image = await Jimp.read(inputData); | ||
| const resizedBuffer = await image.getBufferAsync(Jimp.MIME_JPEG); | ||
| debugImg(`resizeImg done, target size: ${newSize.width}x${newSize.height}`); | ||
@@ -96,3 +105,6 @@ return resizedBuffer; | ||
| } | ||
| return Buffer.from(dataSplitted[1], 'base64'); | ||
| debugImg(`bufferFromBase64 start: ${base64}`); | ||
| const res = Buffer.from(dataSplitted[1], 'base64'); | ||
| debugImg(`bufferFromBase64 done: ${base64}`); | ||
| return res; | ||
| } | ||
@@ -107,2 +119,3 @@ | ||
| ): Promise<string> { | ||
| debugImg(`resizeImgBase64 start: ${inputBase64}`); | ||
| const splitFlag = ';base64,'; | ||
@@ -117,3 +130,5 @@ const dataSplitted = inputBase64.split(splitFlag); | ||
| const content = buffer.toString('base64'); | ||
| return `${dataSplitted[0]}${splitFlag}${content}`; | ||
| const res = `${dataSplitted[0]}${splitFlag}${content}`; | ||
| debugImg(`resizeImgBase64 done: ${inputBase64}`); | ||
| return res; | ||
| } | ||
@@ -207,2 +222,3 @@ | ||
| export async function paddingToMatchBlock(imageBase64: string, blockSize = 28) { | ||
| debugImg('paddingToMatchBlock start'); | ||
| const Jimp = await getJimp(); | ||
@@ -226,3 +242,4 @@ const imageBuffer = await bufferFromBase64(imageBase64); | ||
| const base64 = await paddedImage.getBase64Async(Jimp.MIME_JPEG); | ||
| debugImg('paddingToMatchBlock done'); | ||
| return base64; | ||
| } |
+24
-0
| import { sha256 } from 'js-sha256'; | ||
| import debug from 'debug'; | ||
| export const ifInBrowser = typeof window !== 'undefined'; | ||
@@ -11,2 +13,11 @@ | ||
| const topicPrefix = 'midscene'; | ||
| export function getDebug(topic: string) { | ||
| return debug(`${topicPrefix}:${topic}`); | ||
| } | ||
| export function enableDebug(topic: string) { | ||
| debug.enable(`${topicPrefix}:${topic}`); | ||
| } | ||
| export function generateHashId(rect: any, content = '') { | ||
@@ -48,1 +59,14 @@ // Combine the input into a string | ||
| } | ||
| /** | ||
| * A utility function that asserts a condition and throws an error with a message if the condition is false. | ||
| * | ||
| * @param condition - The condition to assert | ||
| * @param message - The error message to throw if the condition is false | ||
| * @throws Error with the provided message if the condition is false | ||
| */ | ||
| export function assert(condition: any, message?: string): asserts condition { | ||
| if (!condition) { | ||
| throw new Error(message || 'Assertion failed'); | ||
| } | ||
| } |
| declare const TEXT_SIZE_THRESHOLD = 9; | ||
| declare const TEXT_MAX_SIZE = 40; | ||
| declare const CONTAINER_MINI_HEIGHT = 3; | ||
| declare const CONTAINER_MINI_WIDTH = 3; | ||
| declare enum NodeType { | ||
| CONTAINER = "CONTAINER Node", | ||
| FORM_ITEM = "FORM_ITEM Node", | ||
| BUTTON = "BUTTON Node", | ||
| IMG = "IMG Node", | ||
| TEXT = "TEXT Node", | ||
| POSITION = "POSITION Node" | ||
| } | ||
| export { CONTAINER_MINI_HEIGHT, CONTAINER_MINI_WIDTH, NodeType, TEXT_MAX_SIZE, TEXT_SIZE_THRESHOLD }; |
| "use strict"; | ||
| var __defProp = Object.defineProperty; | ||
| var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
| var __getOwnPropNames = Object.getOwnPropertyNames; | ||
| var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
| var __export = (target, all) => { | ||
| for (var name in all) | ||
| __defProp(target, name, { get: all[name], enumerable: true }); | ||
| }; | ||
| var __copyProps = (to, from, except, desc) => { | ||
| if (from && typeof from === "object" || typeof from === "function") { | ||
| for (let key of __getOwnPropNames(from)) | ||
| if (!__hasOwnProp.call(to, key) && key !== except) | ||
| __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); | ||
| } | ||
| return to; | ||
| }; | ||
| var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); | ||
| // src/constants/index.ts | ||
| var constants_exports = {}; | ||
| __export(constants_exports, { | ||
| CONTAINER_MINI_HEIGHT: () => CONTAINER_MINI_HEIGHT, | ||
| CONTAINER_MINI_WIDTH: () => CONTAINER_MINI_WIDTH, | ||
| NodeType: () => NodeType, | ||
| TEXT_MAX_SIZE: () => TEXT_MAX_SIZE, | ||
| TEXT_SIZE_THRESHOLD: () => TEXT_SIZE_THRESHOLD | ||
| }); | ||
| module.exports = __toCommonJS(constants_exports); | ||
| var TEXT_SIZE_THRESHOLD = 9; | ||
| var TEXT_MAX_SIZE = 40; | ||
| var CONTAINER_MINI_HEIGHT = 3; | ||
| var CONTAINER_MINI_WIDTH = 3; | ||
| var NodeType = /* @__PURE__ */ ((NodeType2) => { | ||
| NodeType2["CONTAINER"] = "CONTAINER Node"; | ||
| NodeType2["FORM_ITEM"] = "FORM_ITEM Node"; | ||
| NodeType2["BUTTON"] = "BUTTON Node"; | ||
| NodeType2["IMG"] = "IMG Node"; | ||
| NodeType2["TEXT"] = "TEXT Node"; | ||
| NodeType2["POSITION"] = "POSITION Node"; | ||
| return NodeType2; | ||
| })(NodeType || {}); |
| export { } |
| "use strict"; | ||
| var __create = Object.create; | ||
| var __defProp = Object.defineProperty; | ||
| var __defProps = Object.defineProperties; | ||
| var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
| var __getOwnPropDescs = Object.getOwnPropertyDescriptors; | ||
| var __getOwnPropNames = Object.getOwnPropertyNames; | ||
| var __getOwnPropSymbols = Object.getOwnPropertySymbols; | ||
| var __getProtoOf = Object.getPrototypeOf; | ||
| var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
| var __propIsEnum = Object.prototype.propertyIsEnumerable; | ||
| var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; | ||
| var __spreadValues = (a, b) => { | ||
| for (var prop in b || (b = {})) | ||
| if (__hasOwnProp.call(b, prop)) | ||
| __defNormalProp(a, prop, b[prop]); | ||
| if (__getOwnPropSymbols) | ||
| for (var prop of __getOwnPropSymbols(b)) { | ||
| if (__propIsEnum.call(b, prop)) | ||
| __defNormalProp(a, prop, b[prop]); | ||
| } | ||
| return a; | ||
| }; | ||
| var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b)); | ||
| var __commonJS = (cb, mod) => function __require() { | ||
| return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports; | ||
| }; | ||
| var __copyProps = (to, from, except, desc) => { | ||
| if (from && typeof from === "object" || typeof from === "function") { | ||
| for (let key of __getOwnPropNames(from)) | ||
| if (!__hasOwnProp.call(to, key) && key !== except) | ||
| __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); | ||
| } | ||
| return to; | ||
| }; | ||
| var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( | ||
| // If the importer is in node compatibility mode or this is not an ESM | ||
| // file that has been converted to a CommonJS file using a Babel- | ||
| // compatible transform (i.e. "__esModule" has not been set), then set | ||
| // "default" to the CommonJS "module.exports" for node compatibility. | ||
| isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, | ||
| mod | ||
| )); | ||
| // resolve-false:/empty-stub | ||
| var require_empty_stub = __commonJS({ | ||
| "resolve-false:/empty-stub"(exports, module2) { | ||
| "use strict"; | ||
| module2.exports = {}; | ||
| } | ||
| }); | ||
| // ../../node_modules/.pnpm/js-sha256@0.11.0/node_modules/js-sha256/src/sha256.js | ||
| var require_sha256 = __commonJS({ | ||
| "../../node_modules/.pnpm/js-sha256@0.11.0/node_modules/js-sha256/src/sha256.js"(exports, module2) { | ||
| "use strict"; | ||
| (function() { | ||
| "use strict"; | ||
| var ERROR = "input is invalid type"; | ||
| var WINDOW = typeof window === "object"; | ||
| var root = WINDOW ? window : {}; | ||
| if (root.JS_SHA256_NO_WINDOW) { | ||
| WINDOW = false; | ||
| } | ||
| var WEB_WORKER = !WINDOW && typeof self === "object"; | ||
| var NODE_JS = !root.JS_SHA256_NO_NODE_JS && typeof process === "object" && process.versions && process.versions.node; | ||
| if (NODE_JS) { | ||
| root = global; | ||
| } else if (WEB_WORKER) { | ||
| root = self; | ||
| } | ||
| var COMMON_JS = !root.JS_SHA256_NO_COMMON_JS && typeof module2 === "object" && module2.exports; | ||
| var AMD = typeof define === "function" && define.amd; | ||
| var ARRAY_BUFFER = !root.JS_SHA256_NO_ARRAY_BUFFER && typeof ArrayBuffer !== "undefined"; | ||
| var HEX_CHARS = "0123456789abcdef".split(""); | ||
| var EXTRA = [-2147483648, 8388608, 32768, 128]; | ||
| var SHIFT = [24, 16, 8, 0]; | ||
| var K = [ | ||
| 1116352408, | ||
| 1899447441, | ||
| 3049323471, | ||
| 3921009573, | ||
| 961987163, | ||
| 1508970993, | ||
| 2453635748, | ||
| 2870763221, | ||
| 3624381080, | ||
| 310598401, | ||
| 607225278, | ||
| 1426881987, | ||
| 1925078388, | ||
| 2162078206, | ||
| 2614888103, | ||
| 3248222580, | ||
| 3835390401, | ||
| 4022224774, | ||
| 264347078, | ||
| 604807628, | ||
| 770255983, | ||
| 1249150122, | ||
| 1555081692, | ||
| 1996064986, | ||
| 2554220882, | ||
| 2821834349, | ||
| 2952996808, | ||
| 3210313671, | ||
| 3336571891, | ||
| 3584528711, | ||
| 113926993, | ||
| 338241895, | ||
| 666307205, | ||
| 773529912, | ||
| 1294757372, | ||
| 1396182291, | ||
| 1695183700, | ||
| 1986661051, | ||
| 2177026350, | ||
| 2456956037, | ||
| 2730485921, | ||
| 2820302411, | ||
| 3259730800, | ||
| 3345764771, | ||
| 3516065817, | ||
| 3600352804, | ||
| 4094571909, | ||
| 275423344, | ||
| 430227734, | ||
| 506948616, | ||
| 659060556, | ||
| 883997877, | ||
| 958139571, | ||
| 1322822218, | ||
| 1537002063, | ||
| 1747873779, | ||
| 1955562222, | ||
| 2024104815, | ||
| 2227730452, | ||
| 2361852424, | ||
| 2428436474, | ||
| 2756734187, | ||
| 3204031479, | ||
| 3329325298 | ||
| ]; | ||
| var OUTPUT_TYPES = ["hex", "array", "digest", "arrayBuffer"]; | ||
| var blocks = []; | ||
| if (root.JS_SHA256_NO_NODE_JS || !Array.isArray) { | ||
| Array.isArray = function(obj) { | ||
| return Object.prototype.toString.call(obj) === "[object Array]"; | ||
| }; | ||
| } | ||
| if (ARRAY_BUFFER && (root.JS_SHA256_NO_ARRAY_BUFFER_IS_VIEW || !ArrayBuffer.isView)) { | ||
| ArrayBuffer.isView = function(obj) { | ||
| return typeof obj === "object" && obj.buffer && obj.buffer.constructor === ArrayBuffer; | ||
| }; | ||
| } | ||
| var createOutputMethod = function(outputType, is224) { | ||
| return function(message) { | ||
| return new Sha256(is224, true).update(message)[outputType](); | ||
| }; | ||
| }; | ||
| var createMethod = function(is224) { | ||
| var method = createOutputMethod("hex", is224); | ||
| if (NODE_JS) { | ||
| method = nodeWrap(method, is224); | ||
| } | ||
| method.create = function() { | ||
| return new Sha256(is224); | ||
| }; | ||
| method.update = function(message) { | ||
| return method.create().update(message); | ||
| }; | ||
| for (var i = 0; i < OUTPUT_TYPES.length; ++i) { | ||
| var type = OUTPUT_TYPES[i]; | ||
| method[type] = createOutputMethod(type, is224); | ||
| } | ||
| return method; | ||
| }; | ||
| var nodeWrap = function(method, is224) { | ||
| var crypto = require_empty_stub(); | ||
| var Buffer2 = require_empty_stub().Buffer; | ||
| var algorithm = is224 ? "sha224" : "sha256"; | ||
| var bufferFrom; | ||
| if (Buffer2.from && !root.JS_SHA256_NO_BUFFER_FROM) { | ||
| bufferFrom = Buffer2.from; | ||
| } else { | ||
| bufferFrom = function(message) { | ||
| return new Buffer2(message); | ||
| }; | ||
| } | ||
| var nodeMethod = function(message) { | ||
| if (typeof message === "string") { | ||
| return crypto.createHash(algorithm).update(message, "utf8").digest("hex"); | ||
| } else { | ||
| if (message === null || message === void 0) { | ||
| throw new Error(ERROR); | ||
| } else if (message.constructor === ArrayBuffer) { | ||
| message = new Uint8Array(message); | ||
| } | ||
| } | ||
| if (Array.isArray(message) || ArrayBuffer.isView(message) || message.constructor === Buffer2) { | ||
| return crypto.createHash(algorithm).update(bufferFrom(message)).digest("hex"); | ||
| } else { | ||
| return method(message); | ||
| } | ||
| }; | ||
| return nodeMethod; | ||
| }; | ||
| var createHmacOutputMethod = function(outputType, is224) { | ||
| return function(key, message) { | ||
| return new HmacSha256(key, is224, true).update(message)[outputType](); | ||
| }; | ||
| }; | ||
| var createHmacMethod = function(is224) { | ||
| var method = createHmacOutputMethod("hex", is224); | ||
| method.create = function(key) { | ||
| return new HmacSha256(key, is224); | ||
| }; | ||
| method.update = function(key, message) { | ||
| return method.create(key).update(message); | ||
| }; | ||
| for (var i = 0; i < OUTPUT_TYPES.length; ++i) { | ||
| var type = OUTPUT_TYPES[i]; | ||
| method[type] = createHmacOutputMethod(type, is224); | ||
| } | ||
| return method; | ||
| }; | ||
| function Sha256(is224, sharedMemory) { | ||
| if (sharedMemory) { | ||
| blocks[0] = blocks[16] = blocks[1] = blocks[2] = blocks[3] = blocks[4] = blocks[5] = blocks[6] = blocks[7] = blocks[8] = blocks[9] = blocks[10] = blocks[11] = blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0; | ||
| this.blocks = blocks; | ||
| } else { | ||
| this.blocks = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; | ||
| } | ||
| if (is224) { | ||
| this.h0 = 3238371032; | ||
| this.h1 = 914150663; | ||
| this.h2 = 812702999; | ||
| this.h3 = 4144912697; | ||
| this.h4 = 4290775857; | ||
| this.h5 = 1750603025; | ||
| this.h6 = 1694076839; | ||
| this.h7 = 3204075428; | ||
| } else { | ||
| this.h0 = 1779033703; | ||
| this.h1 = 3144134277; | ||
| this.h2 = 1013904242; | ||
| this.h3 = 2773480762; | ||
| this.h4 = 1359893119; | ||
| this.h5 = 2600822924; | ||
| this.h6 = 528734635; | ||
| this.h7 = 1541459225; | ||
| } | ||
| this.block = this.start = this.bytes = this.hBytes = 0; | ||
| this.finalized = this.hashed = false; | ||
| this.first = true; | ||
| this.is224 = is224; | ||
| } | ||
| Sha256.prototype.update = function(message) { | ||
| if (this.finalized) { | ||
| return; | ||
| } | ||
| var notString, type = typeof message; | ||
| if (type !== "string") { | ||
| if (type === "object") { | ||
| if (message === null) { | ||
| throw new Error(ERROR); | ||
| } else if (ARRAY_BUFFER && message.constructor === ArrayBuffer) { | ||
| message = new Uint8Array(message); | ||
| } else if (!Array.isArray(message)) { | ||
| if (!ARRAY_BUFFER || !ArrayBuffer.isView(message)) { | ||
| throw new Error(ERROR); | ||
| } | ||
| } | ||
| } else { | ||
| throw new Error(ERROR); | ||
| } | ||
| notString = true; | ||
| } | ||
| var code, index = 0, i, length = message.length, blocks2 = this.blocks; | ||
| while (index < length) { | ||
| if (this.hashed) { | ||
| this.hashed = false; | ||
| blocks2[0] = this.block; | ||
| this.block = blocks2[16] = blocks2[1] = blocks2[2] = blocks2[3] = blocks2[4] = blocks2[5] = blocks2[6] = blocks2[7] = blocks2[8] = blocks2[9] = blocks2[10] = blocks2[11] = blocks2[12] = blocks2[13] = blocks2[14] = blocks2[15] = 0; | ||
| } | ||
| if (notString) { | ||
| for (i = this.start; index < length && i < 64; ++index) { | ||
| blocks2[i >>> 2] |= message[index] << SHIFT[i++ & 3]; | ||
| } | ||
| } else { | ||
| for (i = this.start; index < length && i < 64; ++index) { | ||
| code = message.charCodeAt(index); | ||
| if (code < 128) { | ||
| blocks2[i >>> 2] |= code << SHIFT[i++ & 3]; | ||
| } else if (code < 2048) { | ||
| blocks2[i >>> 2] |= (192 | code >>> 6) << SHIFT[i++ & 3]; | ||
| blocks2[i >>> 2] |= (128 | code & 63) << SHIFT[i++ & 3]; | ||
| } else if (code < 55296 || code >= 57344) { | ||
| blocks2[i >>> 2] |= (224 | code >>> 12) << SHIFT[i++ & 3]; | ||
| blocks2[i >>> 2] |= (128 | code >>> 6 & 63) << SHIFT[i++ & 3]; | ||
| blocks2[i >>> 2] |= (128 | code & 63) << SHIFT[i++ & 3]; | ||
| } else { | ||
| code = 65536 + ((code & 1023) << 10 | message.charCodeAt(++index) & 1023); | ||
| blocks2[i >>> 2] |= (240 | code >>> 18) << SHIFT[i++ & 3]; | ||
| blocks2[i >>> 2] |= (128 | code >>> 12 & 63) << SHIFT[i++ & 3]; | ||
| blocks2[i >>> 2] |= (128 | code >>> 6 & 63) << SHIFT[i++ & 3]; | ||
| blocks2[i >>> 2] |= (128 | code & 63) << SHIFT[i++ & 3]; | ||
| } | ||
| } | ||
| } | ||
| this.lastByteIndex = i; | ||
| this.bytes += i - this.start; | ||
| if (i >= 64) { | ||
| this.block = blocks2[16]; | ||
| this.start = i - 64; | ||
| this.hash(); | ||
| this.hashed = true; | ||
| } else { | ||
| this.start = i; | ||
| } | ||
| } | ||
| if (this.bytes > 4294967295) { | ||
| this.hBytes += this.bytes / 4294967296 << 0; | ||
| this.bytes = this.bytes % 4294967296; | ||
| } | ||
| return this; | ||
| }; | ||
| Sha256.prototype.finalize = function() { | ||
| if (this.finalized) { | ||
| return; | ||
| } | ||
| this.finalized = true; | ||
| var blocks2 = this.blocks, i = this.lastByteIndex; | ||
| blocks2[16] = this.block; | ||
| blocks2[i >>> 2] |= EXTRA[i & 3]; | ||
| this.block = blocks2[16]; | ||
| if (i >= 56) { | ||
| if (!this.hashed) { | ||
| this.hash(); | ||
| } | ||
| blocks2[0] = this.block; | ||
| blocks2[16] = blocks2[1] = blocks2[2] = blocks2[3] = blocks2[4] = blocks2[5] = blocks2[6] = blocks2[7] = blocks2[8] = blocks2[9] = blocks2[10] = blocks2[11] = blocks2[12] = blocks2[13] = blocks2[14] = blocks2[15] = 0; | ||
| } | ||
| blocks2[14] = this.hBytes << 3 | this.bytes >>> 29; | ||
| blocks2[15] = this.bytes << 3; | ||
| this.hash(); | ||
| }; | ||
| Sha256.prototype.hash = function() { | ||
| var a = this.h0, b = this.h1, c = this.h2, d = this.h3, e = this.h4, f = this.h5, g = this.h6, h = this.h7, blocks2 = this.blocks, j, s0, s1, maj, t1, t2, ch, ab, da, cd, bc; | ||
| for (j = 16; j < 64; ++j) { | ||
| t1 = blocks2[j - 15]; | ||
| s0 = (t1 >>> 7 | t1 << 25) ^ (t1 >>> 18 | t1 << 14) ^ t1 >>> 3; | ||
| t1 = blocks2[j - 2]; | ||
| s1 = (t1 >>> 17 | t1 << 15) ^ (t1 >>> 19 | t1 << 13) ^ t1 >>> 10; | ||
| blocks2[j] = blocks2[j - 16] + s0 + blocks2[j - 7] + s1 << 0; | ||
| } | ||
| bc = b & c; | ||
| for (j = 0; j < 64; j += 4) { | ||
| if (this.first) { | ||
| if (this.is224) { | ||
| ab = 300032; | ||
| t1 = blocks2[0] - 1413257819; | ||
| h = t1 - 150054599 << 0; | ||
| d = t1 + 24177077 << 0; | ||
| } else { | ||
| ab = 704751109; | ||
| t1 = blocks2[0] - 210244248; | ||
| h = t1 - 1521486534 << 0; | ||
| d = t1 + 143694565 << 0; | ||
| } | ||
| this.first = false; | ||
| } else { | ||
| s0 = (a >>> 2 | a << 30) ^ (a >>> 13 | a << 19) ^ (a >>> 22 | a << 10); | ||
| s1 = (e >>> 6 | e << 26) ^ (e >>> 11 | e << 21) ^ (e >>> 25 | e << 7); | ||
| ab = a & b; | ||
| maj = ab ^ a & c ^ bc; | ||
| ch = e & f ^ ~e & g; | ||
| t1 = h + s1 + ch + K[j] + blocks2[j]; | ||
| t2 = s0 + maj; | ||
| h = d + t1 << 0; | ||
| d = t1 + t2 << 0; | ||
| } | ||
| s0 = (d >>> 2 | d << 30) ^ (d >>> 13 | d << 19) ^ (d >>> 22 | d << 10); | ||
| s1 = (h >>> 6 | h << 26) ^ (h >>> 11 | h << 21) ^ (h >>> 25 | h << 7); | ||
| da = d & a; | ||
| maj = da ^ d & b ^ ab; | ||
| ch = h & e ^ ~h & f; | ||
| t1 = g + s1 + ch + K[j + 1] + blocks2[j + 1]; | ||
| t2 = s0 + maj; | ||
| g = c + t1 << 0; | ||
| c = t1 + t2 << 0; | ||
| s0 = (c >>> 2 | c << 30) ^ (c >>> 13 | c << 19) ^ (c >>> 22 | c << 10); | ||
| s1 = (g >>> 6 | g << 26) ^ (g >>> 11 | g << 21) ^ (g >>> 25 | g << 7); | ||
| cd = c & d; | ||
| maj = cd ^ c & a ^ da; | ||
| ch = g & h ^ ~g & e; | ||
| t1 = f + s1 + ch + K[j + 2] + blocks2[j + 2]; | ||
| t2 = s0 + maj; | ||
| f = b + t1 << 0; | ||
| b = t1 + t2 << 0; | ||
| s0 = (b >>> 2 | b << 30) ^ (b >>> 13 | b << 19) ^ (b >>> 22 | b << 10); | ||
| s1 = (f >>> 6 | f << 26) ^ (f >>> 11 | f << 21) ^ (f >>> 25 | f << 7); | ||
| bc = b & c; | ||
| maj = bc ^ b & d ^ cd; | ||
| ch = f & g ^ ~f & h; | ||
| t1 = e + s1 + ch + K[j + 3] + blocks2[j + 3]; | ||
| t2 = s0 + maj; | ||
| e = a + t1 << 0; | ||
| a = t1 + t2 << 0; | ||
| this.chromeBugWorkAround = true; | ||
| } | ||
| this.h0 = this.h0 + a << 0; | ||
| this.h1 = this.h1 + b << 0; | ||
| this.h2 = this.h2 + c << 0; | ||
| this.h3 = this.h3 + d << 0; | ||
| this.h4 = this.h4 + e << 0; | ||
| this.h5 = this.h5 + f << 0; | ||
| this.h6 = this.h6 + g << 0; | ||
| this.h7 = this.h7 + h << 0; | ||
| }; | ||
| Sha256.prototype.hex = function() { | ||
| this.finalize(); | ||
| var h0 = this.h0, h1 = this.h1, h2 = this.h2, h3 = this.h3, h4 = this.h4, h5 = this.h5, h6 = this.h6, h7 = this.h7; | ||
| var hex = HEX_CHARS[h0 >>> 28 & 15] + HEX_CHARS[h0 >>> 24 & 15] + HEX_CHARS[h0 >>> 20 & 15] + HEX_CHARS[h0 >>> 16 & 15] + HEX_CHARS[h0 >>> 12 & 15] + HEX_CHARS[h0 >>> 8 & 15] + HEX_CHARS[h0 >>> 4 & 15] + HEX_CHARS[h0 & 15] + HEX_CHARS[h1 >>> 28 & 15] + HEX_CHARS[h1 >>> 24 & 15] + HEX_CHARS[h1 >>> 20 & 15] + HEX_CHARS[h1 >>> 16 & 15] + HEX_CHARS[h1 >>> 12 & 15] + HEX_CHARS[h1 >>> 8 & 15] + HEX_CHARS[h1 >>> 4 & 15] + HEX_CHARS[h1 & 15] + HEX_CHARS[h2 >>> 28 & 15] + HEX_CHARS[h2 >>> 24 & 15] + HEX_CHARS[h2 >>> 20 & 15] + HEX_CHARS[h2 >>> 16 & 15] + HEX_CHARS[h2 >>> 12 & 15] + HEX_CHARS[h2 >>> 8 & 15] + HEX_CHARS[h2 >>> 4 & 15] + HEX_CHARS[h2 & 15] + HEX_CHARS[h3 >>> 28 & 15] + HEX_CHARS[h3 >>> 24 & 15] + HEX_CHARS[h3 >>> 20 & 15] + HEX_CHARS[h3 >>> 16 & 15] + HEX_CHARS[h3 >>> 12 & 15] + HEX_CHARS[h3 >>> 8 & 15] + HEX_CHARS[h3 >>> 4 & 15] + HEX_CHARS[h3 & 15] + HEX_CHARS[h4 >>> 28 & 15] + HEX_CHARS[h4 >>> 24 & 15] + HEX_CHARS[h4 >>> 20 & 15] + HEX_CHARS[h4 >>> 16 & 15] + HEX_CHARS[h4 >>> 12 & 15] + HEX_CHARS[h4 >>> 8 & 15] + HEX_CHARS[h4 >>> 4 & 15] + HEX_CHARS[h4 & 15] + HEX_CHARS[h5 >>> 28 & 15] + HEX_CHARS[h5 >>> 24 & 15] + HEX_CHARS[h5 >>> 20 & 15] + HEX_CHARS[h5 >>> 16 & 15] + HEX_CHARS[h5 >>> 12 & 15] + HEX_CHARS[h5 >>> 8 & 15] + HEX_CHARS[h5 >>> 4 & 15] + HEX_CHARS[h5 & 15] + HEX_CHARS[h6 >>> 28 & 15] + HEX_CHARS[h6 >>> 24 & 15] + HEX_CHARS[h6 >>> 20 & 15] + HEX_CHARS[h6 >>> 16 & 15] + HEX_CHARS[h6 >>> 12 & 15] + HEX_CHARS[h6 >>> 8 & 15] + HEX_CHARS[h6 >>> 4 & 15] + HEX_CHARS[h6 & 15]; | ||
| if (!this.is224) { | ||
| hex += HEX_CHARS[h7 >>> 28 & 15] + HEX_CHARS[h7 >>> 24 & 15] + HEX_CHARS[h7 >>> 20 & 15] + HEX_CHARS[h7 >>> 16 & 15] + HEX_CHARS[h7 >>> 12 & 15] + HEX_CHARS[h7 >>> 8 & 15] + HEX_CHARS[h7 >>> 4 & 15] + HEX_CHARS[h7 & 15]; | ||
| } | ||
| return hex; | ||
| }; | ||
| Sha256.prototype.toString = Sha256.prototype.hex; | ||
| Sha256.prototype.digest = function() { | ||
| this.finalize(); | ||
| var h0 = this.h0, h1 = this.h1, h2 = this.h2, h3 = this.h3, h4 = this.h4, h5 = this.h5, h6 = this.h6, h7 = this.h7; | ||
| var arr = [ | ||
| h0 >>> 24 & 255, | ||
| h0 >>> 16 & 255, | ||
| h0 >>> 8 & 255, | ||
| h0 & 255, | ||
| h1 >>> 24 & 255, | ||
| h1 >>> 16 & 255, | ||
| h1 >>> 8 & 255, | ||
| h1 & 255, | ||
| h2 >>> 24 & 255, | ||
| h2 >>> 16 & 255, | ||
| h2 >>> 8 & 255, | ||
| h2 & 255, | ||
| h3 >>> 24 & 255, | ||
| h3 >>> 16 & 255, | ||
| h3 >>> 8 & 255, | ||
| h3 & 255, | ||
| h4 >>> 24 & 255, | ||
| h4 >>> 16 & 255, | ||
| h4 >>> 8 & 255, | ||
| h4 & 255, | ||
| h5 >>> 24 & 255, | ||
| h5 >>> 16 & 255, | ||
| h5 >>> 8 & 255, | ||
| h5 & 255, | ||
| h6 >>> 24 & 255, | ||
| h6 >>> 16 & 255, | ||
| h6 >>> 8 & 255, | ||
| h6 & 255 | ||
| ]; | ||
| if (!this.is224) { | ||
| arr.push(h7 >>> 24 & 255, h7 >>> 16 & 255, h7 >>> 8 & 255, h7 & 255); | ||
| } | ||
| return arr; | ||
| }; | ||
| Sha256.prototype.array = Sha256.prototype.digest; | ||
| Sha256.prototype.arrayBuffer = function() { | ||
| this.finalize(); | ||
| var buffer = new ArrayBuffer(this.is224 ? 28 : 32); | ||
| var dataView = new DataView(buffer); | ||
| dataView.setUint32(0, this.h0); | ||
| dataView.setUint32(4, this.h1); | ||
| dataView.setUint32(8, this.h2); | ||
| dataView.setUint32(12, this.h3); | ||
| dataView.setUint32(16, this.h4); | ||
| dataView.setUint32(20, this.h5); | ||
| dataView.setUint32(24, this.h6); | ||
| if (!this.is224) { | ||
| dataView.setUint32(28, this.h7); | ||
| } | ||
| return buffer; | ||
| }; | ||
| function HmacSha256(key, is224, sharedMemory) { | ||
| var i, type = typeof key; | ||
| if (type === "string") { | ||
| var bytes = [], length = key.length, index = 0, code; | ||
| for (i = 0; i < length; ++i) { | ||
| code = key.charCodeAt(i); | ||
| if (code < 128) { | ||
| bytes[index++] = code; | ||
| } else if (code < 2048) { | ||
| bytes[index++] = 192 | code >>> 6; | ||
| bytes[index++] = 128 | code & 63; | ||
| } else if (code < 55296 || code >= 57344) { | ||
| bytes[index++] = 224 | code >>> 12; | ||
| bytes[index++] = 128 | code >>> 6 & 63; | ||
| bytes[index++] = 128 | code & 63; | ||
| } else { | ||
| code = 65536 + ((code & 1023) << 10 | key.charCodeAt(++i) & 1023); | ||
| bytes[index++] = 240 | code >>> 18; | ||
| bytes[index++] = 128 | code >>> 12 & 63; | ||
| bytes[index++] = 128 | code >>> 6 & 63; | ||
| bytes[index++] = 128 | code & 63; | ||
| } | ||
| } | ||
| key = bytes; | ||
| } else { | ||
| if (type === "object") { | ||
| if (key === null) { | ||
| throw new Error(ERROR); | ||
| } else if (ARRAY_BUFFER && key.constructor === ArrayBuffer) { | ||
| key = new Uint8Array(key); | ||
| } else if (!Array.isArray(key)) { | ||
| if (!ARRAY_BUFFER || !ArrayBuffer.isView(key)) { | ||
| throw new Error(ERROR); | ||
| } | ||
| } | ||
| } else { | ||
| throw new Error(ERROR); | ||
| } | ||
| } | ||
| if (key.length > 64) { | ||
| key = new Sha256(is224, true).update(key).array(); | ||
| } | ||
| var oKeyPad = [], iKeyPad = []; | ||
| for (i = 0; i < 64; ++i) { | ||
| var b = key[i] || 0; | ||
| oKeyPad[i] = 92 ^ b; | ||
| iKeyPad[i] = 54 ^ b; | ||
| } | ||
| Sha256.call(this, is224, sharedMemory); | ||
| this.update(iKeyPad); | ||
| this.oKeyPad = oKeyPad; | ||
| this.inner = true; | ||
| this.sharedMemory = sharedMemory; | ||
| } | ||
| HmacSha256.prototype = new Sha256(); | ||
| HmacSha256.prototype.finalize = function() { | ||
| Sha256.prototype.finalize.call(this); | ||
| if (this.inner) { | ||
| this.inner = false; | ||
| var innerHash = this.array(); | ||
| Sha256.call(this, this.is224, this.sharedMemory); | ||
| this.update(this.oKeyPad); | ||
| this.update(innerHash); | ||
| Sha256.prototype.finalize.call(this); | ||
| } | ||
| }; | ||
| var exports2 = createMethod(); | ||
| exports2.sha256 = exports2; | ||
| exports2.sha224 = createMethod(true); | ||
| exports2.sha256.hmac = createHmacMethod(); | ||
| exports2.sha224.hmac = createHmacMethod(true); | ||
| if (COMMON_JS) { | ||
| module2.exports = exports2; | ||
| } else { | ||
| root.sha256 = exports2.sha256; | ||
| root.sha224 = exports2.sha224; | ||
| if (AMD) { | ||
| define(function() { | ||
| return exports2; | ||
| }); | ||
| } | ||
| } | ||
| })(); | ||
| } | ||
| }); | ||
| // src/constants/index.ts | ||
| var CONTAINER_MINI_HEIGHT = 3; | ||
| var CONTAINER_MINI_WIDTH = 3; | ||
| // src/extractor/dom-util.ts | ||
| function isFormElement(node) { | ||
| return node instanceof HTMLElement && (node.tagName.toLowerCase() === "input" || node.tagName.toLowerCase() === "textarea" || node.tagName.toLowerCase() === "select" || node.tagName.toLowerCase() === "option"); | ||
| } | ||
| function isButtonElement(node) { | ||
| return node instanceof HTMLElement && node.tagName.toLowerCase() === "button"; | ||
| } | ||
| function isImgElement(node) { | ||
| if (!includeBaseElement(node) && node instanceof Element) { | ||
| const computedStyle = window.getComputedStyle(node); | ||
| const backgroundImage = computedStyle.getPropertyValue("background-image"); | ||
| if (backgroundImage !== "none") { | ||
| return true; | ||
| } | ||
| } | ||
| if (isIconfont(node)) { | ||
| return true; | ||
| } | ||
| return node instanceof HTMLElement && node.tagName.toLowerCase() === "img" || node instanceof SVGElement && node.tagName.toLowerCase() === "svg"; | ||
| } | ||
| function isIconfont(node) { | ||
| if (node instanceof Element) { | ||
| const computedStyle = window.getComputedStyle(node); | ||
| const fontFamilyValue = computedStyle.fontFamily || ""; | ||
| return fontFamilyValue.toLowerCase().indexOf("iconfont") >= 0; | ||
| } | ||
| return false; | ||
| } | ||
| function isTextElement(node) { | ||
| return node.nodeName.toLowerCase() === "#text" && !isIconfont(node); | ||
| } | ||
| function isContainerElement(node) { | ||
| if (!(node instanceof HTMLElement)) | ||
| return false; | ||
| if (includeBaseElement(node)) { | ||
| return false; | ||
| } | ||
| const computedStyle = window.getComputedStyle(node); | ||
| const backgroundColor = computedStyle.getPropertyValue("background-color"); | ||
| if (backgroundColor) { | ||
| return true; | ||
| } | ||
| return false; | ||
| } | ||
| function includeBaseElement(node) { | ||
| if (!(node instanceof HTMLElement)) | ||
| return false; | ||
| if (node.innerText) { | ||
| return true; | ||
| } | ||
| const includeList = [ | ||
| "svg", | ||
| "button", | ||
| "input", | ||
| "textarea", | ||
| "select", | ||
| "option", | ||
| "img" | ||
| ]; | ||
| for (const tagName of includeList) { | ||
| const element = node.querySelectorAll(tagName); | ||
| if (element.length > 0) { | ||
| return true; | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
| // src/utils.ts | ||
| var import_js_sha256 = __toESM(require_sha256()); | ||
| var hashMap = {}; | ||
| function generateHashId(rect, content = "") { | ||
| const combined = JSON.stringify({ | ||
| content, | ||
| rect | ||
| }); | ||
| let sliceLength = 5; | ||
| let slicedHash = ""; | ||
| const hashHex = import_js_sha256.sha256.create().update(combined).hex(); | ||
| const toLetters = (hex) => { | ||
| return hex.split("").map((char) => { | ||
| const code = Number.parseInt(char, 16); | ||
| return String.fromCharCode(97 + code % 26); | ||
| }).join(""); | ||
| }; | ||
| const hashLetters = toLetters(hashHex); | ||
| while (sliceLength < hashLetters.length - 1) { | ||
| slicedHash = hashLetters.slice(0, sliceLength); | ||
| if (hashMap[slicedHash] && hashMap[slicedHash] !== combined) { | ||
| sliceLength++; | ||
| continue; | ||
| } | ||
| hashMap[slicedHash] = combined; | ||
| break; | ||
| } | ||
| return slicedHash; | ||
| } | ||
| // src/extractor/util.ts | ||
| var MAX_VALUE_LENGTH = 300; | ||
| var debugMode = false; | ||
| function setDebugMode(mode) { | ||
| debugMode = mode; | ||
| } | ||
| function getDebugMode() { | ||
| return debugMode; | ||
| } | ||
| function logger(..._msg) { | ||
| if (!debugMode) { | ||
| return; | ||
| } | ||
| console.log(..._msg); | ||
| } | ||
| var taskIdKey = "_midscene_retrieve_task_id"; | ||
| function selectorForValue(val) { | ||
| return `[${taskIdKey}='${val}']`; | ||
| } | ||
| function setDataForNode(node, nodeHash, setToParentNode, currentWindow) { | ||
| const taskId = taskIdKey; | ||
| if (!(node instanceof currentWindow.HTMLElement)) { | ||
| return ""; | ||
| } | ||
| if (!taskId) { | ||
| console.error("No task id found"); | ||
| return ""; | ||
| } | ||
| const selector = selectorForValue(nodeHash); | ||
| if (getDebugMode()) { | ||
| if (setToParentNode) { | ||
| if (node.parentNode instanceof currentWindow.HTMLElement) { | ||
| node.parentNode.setAttribute(taskIdKey, nodeHash.toString()); | ||
| } | ||
| } else { | ||
| node.setAttribute(taskIdKey, nodeHash.toString()); | ||
| } | ||
| } | ||
| return selector; | ||
| } | ||
| function isElementPartiallyInViewport(rect, currentWindow, currentDocument) { | ||
| const elementHeight = rect.height; | ||
| const elementWidth = rect.width; | ||
| const viewportRect = { | ||
| left: 0, | ||
| top: 0, | ||
| width: currentWindow.innerWidth || currentDocument.documentElement.clientWidth, | ||
| height: currentWindow.innerHeight || currentDocument.documentElement.clientHeight, | ||
| right: currentWindow.innerWidth || currentDocument.documentElement.clientWidth, | ||
| bottom: currentWindow.innerHeight || currentDocument.documentElement.clientHeight, | ||
| x: 0, | ||
| y: 0, | ||
| zoom: 1 | ||
| }; | ||
| const overlapRect = overlappedRect(rect, viewportRect); | ||
| if (!overlapRect) { | ||
| return false; | ||
| } | ||
| const visibleArea = overlapRect.width * overlapRect.height; | ||
| const totalArea = elementHeight * elementWidth; | ||
| return visibleArea / totalArea >= 2 / 3; | ||
| } | ||
| function getPseudoElementContent(element, currentWindow) { | ||
| if (!(element instanceof currentWindow.HTMLElement)) { | ||
| return { before: "", after: "" }; | ||
| } | ||
| const beforeContent = currentWindow.getComputedStyle(element, "::before").getPropertyValue("content"); | ||
| const afterContent = currentWindow.getComputedStyle(element, "::after").getPropertyValue("content"); | ||
| return { | ||
| before: beforeContent === "none" ? "" : beforeContent.replace(/"/g, ""), | ||
| after: afterContent === "none" ? "" : afterContent.replace(/"/g, "") | ||
| }; | ||
| } | ||
| function overlappedRect(rect1, rect2) { | ||
| const left = Math.max(rect1.left, rect2.left); | ||
| const top = Math.max(rect1.top, rect2.top); | ||
| const right = Math.min(rect1.right, rect2.right); | ||
| const bottom = Math.min(rect1.bottom, rect2.bottom); | ||
| if (left < right && top < bottom) { | ||
| return { | ||
| left, | ||
| top, | ||
| right, | ||
| bottom, | ||
| width: right - left, | ||
| height: bottom - top, | ||
| x: left, | ||
| y: top, | ||
| zoom: 1 | ||
| }; | ||
| } | ||
| return null; | ||
| } | ||
| function getRect(el, baseZoom, currentWindow) { | ||
| let originalRect; | ||
| let newZoom = 1; | ||
| if (!(el instanceof currentWindow.HTMLElement)) { | ||
| const range = currentWindow.document.createRange(); | ||
| range.selectNodeContents(el); | ||
| originalRect = range.getBoundingClientRect(); | ||
| } else { | ||
| originalRect = el.getBoundingClientRect(); | ||
| if (!("currentCSSZoom" in el)) { | ||
| newZoom = Number.parseFloat(currentWindow.getComputedStyle(el).zoom) || 1; | ||
| } | ||
| } | ||
| const zoom = newZoom * baseZoom; | ||
| return { | ||
| width: originalRect.width * zoom, | ||
| height: originalRect.height * zoom, | ||
| left: originalRect.left * zoom, | ||
| top: originalRect.top * zoom, | ||
| right: originalRect.right * zoom, | ||
| bottom: originalRect.bottom * zoom, | ||
| x: originalRect.x * zoom, | ||
| y: originalRect.y * zoom, | ||
| zoom | ||
| }; | ||
| } | ||
| var isElementCovered = (el, rect, currentWindow) => { | ||
| const x = rect.left + rect.width / 2; | ||
| const y = rect.top + rect.height / 2; | ||
| const topElement = currentWindow.document.elementFromPoint(x, y); | ||
| if (!topElement) { | ||
| return false; | ||
| } | ||
| if (topElement === el) { | ||
| return false; | ||
| } | ||
| if (el == null ? void 0 : el.contains(topElement)) { | ||
| return false; | ||
| } | ||
| if (topElement == null ? void 0 : topElement.contains(el)) { | ||
| return false; | ||
| } | ||
| const rectOfTopElement = getRect(topElement, 1, currentWindow); | ||
| const overlapRect = overlappedRect(rect, rectOfTopElement); | ||
| if (!overlapRect) { | ||
| return false; | ||
| } | ||
| logger(el, "Element is covered by another element", { | ||
| topElement, | ||
| el, | ||
| rect, | ||
| x, | ||
| y | ||
| }); | ||
| return true; | ||
| }; | ||
| function visibleRect(el, currentWindow, currentDocument, baseZoom = 1) { | ||
| if (!el) { | ||
| logger(el, "Element is not in the DOM hierarchy"); | ||
| return false; | ||
| } | ||
| if (!(el instanceof currentWindow.HTMLElement) && el.nodeType !== Node.TEXT_NODE && el.nodeName.toLowerCase() !== "svg") { | ||
| logger(el, "Element is not in the DOM hierarchy"); | ||
| return false; | ||
| } | ||
| if (el instanceof currentWindow.HTMLElement) { | ||
| const style = currentWindow.getComputedStyle(el); | ||
| if (style.display === "none" || style.visibility === "hidden" || style.opacity === "0" && el.tagName !== "INPUT") { | ||
| logger(el, "Element is hidden"); | ||
| return false; | ||
| } | ||
| } | ||
| const rect = getRect(el, baseZoom, currentWindow); | ||
| if (rect.width === 0 && rect.height === 0) { | ||
| logger(el, "Element has no size"); | ||
| return false; | ||
| } | ||
| if (baseZoom === 1 && isElementCovered(el, rect, currentWindow)) { | ||
| return false; | ||
| } | ||
| const scrollLeft = currentWindow.pageXOffset || currentDocument.documentElement.scrollLeft; | ||
| const scrollTop = currentWindow.pageYOffset || currentDocument.documentElement.scrollTop; | ||
| const viewportWidth = currentWindow.innerWidth || currentDocument.documentElement.clientWidth; | ||
| const viewportHeight = currentWindow.innerHeight || currentDocument.documentElement.clientHeight; | ||
| const isPartiallyInViewport = isElementPartiallyInViewport( | ||
| rect, | ||
| currentWindow, | ||
| currentDocument | ||
| ); | ||
| if (!isPartiallyInViewport) { | ||
| logger(el, "Element is completely outside the viewport", { | ||
| rect, | ||
| viewportHeight, | ||
| viewportWidth, | ||
| scrollTop, | ||
| scrollLeft | ||
| }); | ||
| return false; | ||
| } | ||
| let parent = el; | ||
| const parentUntilNonStatic = (currentNode) => { | ||
| let parent2 = currentNode == null ? void 0 : currentNode.parentElement; | ||
| while (parent2) { | ||
| const style = currentWindow.getComputedStyle(parent2); | ||
| if (style.position !== "static") { | ||
| return parent2; | ||
| } | ||
| parent2 = parent2.parentElement; | ||
| } | ||
| return null; | ||
| }; | ||
| while (parent && parent !== currentDocument.body) { | ||
| if (!(parent instanceof currentWindow.HTMLElement)) { | ||
| parent = parent.parentElement; | ||
| continue; | ||
| } | ||
| const parentStyle = currentWindow.getComputedStyle(parent); | ||
| if (parentStyle.overflow === "hidden") { | ||
| const parentRect = getRect(parent, 1, currentWindow); | ||
| const tolerance = 10; | ||
| if (rect.right < parentRect.left - tolerance || rect.left > parentRect.right + tolerance || rect.bottom < parentRect.top - tolerance || rect.top > parentRect.bottom + tolerance) { | ||
| logger(el, "element is partially or totally hidden by an ancestor", { | ||
| rect, | ||
| parentRect | ||
| }); | ||
| return false; | ||
| } | ||
| } | ||
| if (parentStyle.position === "fixed" || parentStyle.position === "sticky") { | ||
| break; | ||
| } | ||
| if (parentStyle.position === "absolute") { | ||
| parent = parentUntilNonStatic(parent); | ||
| } else { | ||
| parent = parent.parentElement; | ||
| } | ||
| } | ||
| return { | ||
| left: Math.round(rect.left), | ||
| top: Math.round(rect.top), | ||
| width: Math.round(rect.width), | ||
| height: Math.round(rect.height), | ||
| zoom: rect.zoom | ||
| }; | ||
| } | ||
| function getNodeAttributes(node, currentWindow) { | ||
| if (!node || !(node instanceof currentWindow.HTMLElement) || !node.attributes) { | ||
| return {}; | ||
| } | ||
| const attributesList = Array.from(node.attributes).map((attr) => { | ||
| if (attr.name === "class") { | ||
| return [attr.name, `.${attr.value.split(" ").join(".")}`]; | ||
| } | ||
| if (!attr.value) { | ||
| return []; | ||
| } | ||
| let value = attr.value; | ||
| if (value.startsWith("data:image")) { | ||
| value = "image"; | ||
| } | ||
| if (value.length > MAX_VALUE_LENGTH) { | ||
| value = `${value.slice(0, MAX_VALUE_LENGTH)}...`; | ||
| } | ||
| return [attr.name, value]; | ||
| }); | ||
| return Object.fromEntries(attributesList); | ||
| } | ||
| var nodeHashCacheList = []; | ||
| if (typeof window !== "undefined") { | ||
| window.midsceneNodeHashCacheList = window.midsceneNodeHashCacheList || []; | ||
| nodeHashCacheList = window.midsceneNodeHashCacheList; | ||
| } | ||
| function resetNodeHashCacheList() { | ||
| if (typeof window !== "undefined") { | ||
| nodeHashCacheList = window.midsceneNodeHashCacheList || []; | ||
| window.midsceneNodeHashCacheList = []; | ||
| } else { | ||
| nodeHashCacheList = []; | ||
| } | ||
| } | ||
| function midsceneGenerateHash(node, content, rect) { | ||
| var _a; | ||
| if (node && nodeHashCacheList.find((item) => item.node === node)) { | ||
| return ((_a = nodeHashCacheList.find((item) => item.node === node)) == null ? void 0 : _a.id) || ""; | ||
| } | ||
| const slicedHash = generateHashId(rect, content); | ||
| if (node && typeof window !== "undefined") { | ||
| window.midsceneNodeHashCacheList.push({ node, id: slicedHash }); | ||
| } | ||
| return slicedHash; | ||
| } | ||
| function setMidsceneVisibleRectOnWindow() { | ||
| if (typeof window !== "undefined") { | ||
| window.midsceneVisibleRect = visibleRect; | ||
| } | ||
| } | ||
| function setExtractTextWithPositionOnWindow() { | ||
| if (typeof window !== "undefined") { | ||
| window.extractTextWithPosition = extractTextWithPosition; | ||
| } | ||
| } | ||
| function getTopDocument() { | ||
| const container = document.body || document; | ||
| return container; | ||
| } | ||
| // src/extractor/web-extractor.ts | ||
| var indexId = 0; | ||
| function tagNameOfNode(node) { | ||
| let tagName = ""; | ||
| if (node instanceof HTMLElement) { | ||
| tagName = node.tagName.toLowerCase(); | ||
| } | ||
| const parentElement = node.parentElement; | ||
| if (parentElement && parentElement instanceof HTMLElement) { | ||
| tagName = parentElement.tagName.toLowerCase(); | ||
| } | ||
| return tagName ? `<${tagName}>` : ""; | ||
| } | ||
| function collectElementInfo(node, currentWindow, currentDocument, baseZoom = 1, basePoint = { left: 0, top: 0 }) { | ||
| var _a; | ||
| const rect = visibleRect(node, currentWindow, currentDocument, baseZoom); | ||
| if (!rect || rect.width < CONTAINER_MINI_WIDTH || rect.height < CONTAINER_MINI_HEIGHT) { | ||
| return null; | ||
| } | ||
| if (basePoint.left !== 0 || basePoint.top !== 0) { | ||
| rect.left += basePoint.left; | ||
| rect.top += basePoint.top; | ||
| } | ||
| if (rect.height >= window.innerHeight && rect.width >= window.innerWidth) { | ||
| return null; | ||
| } | ||
| if (isFormElement(node)) { | ||
| const attributes = getNodeAttributes(node, currentWindow); | ||
| let valueContent = attributes.value || attributes.placeholder || node.textContent || ""; | ||
| const nodeHashId = midsceneGenerateHash(node, valueContent, rect); | ||
| const selector = setDataForNode(node, nodeHashId, false, currentWindow); | ||
| const tagName = node.tagName.toLowerCase(); | ||
| if (node.tagName.toLowerCase() === "select") { | ||
| const selectedOption = node.options[node.selectedIndex]; | ||
| valueContent = selectedOption.textContent || ""; | ||
| } | ||
| if ((node.tagName.toLowerCase() === "input" || node.tagName.toLowerCase() === "textarea") && node.value) { | ||
| valueContent = node.value; | ||
| } | ||
| const elementInfo = { | ||
| id: nodeHashId, | ||
| nodeHashId, | ||
| locator: selector, | ||
| nodeType: "FORM_ITEM Node" /* FORM_ITEM */, | ||
| indexId: indexId++, | ||
| attributes: __spreadProps(__spreadValues({}, attributes), { | ||
| htmlTagName: `<${tagName}>`, | ||
| nodeType: "FORM_ITEM Node" /* FORM_ITEM */ | ||
| }), | ||
| content: valueContent.trim(), | ||
| rect, | ||
| center: [ | ||
| Math.round(rect.left + rect.width / 2), | ||
| Math.round(rect.top + rect.height / 2) | ||
| ], | ||
| zoom: rect.zoom, | ||
| screenWidth: currentWindow.innerWidth, | ||
| screenHeight: currentWindow.innerHeight | ||
| }; | ||
| return elementInfo; | ||
| } | ||
| if (isButtonElement(node)) { | ||
| const attributes = getNodeAttributes(node, currentWindow); | ||
| const pseudo = getPseudoElementContent(node, currentWindow); | ||
| const content = node.innerText || pseudo.before || pseudo.after || ""; | ||
| const nodeHashId = midsceneGenerateHash(node, content, rect); | ||
| const selector = setDataForNode(node, nodeHashId, false, currentWindow); | ||
| const elementInfo = { | ||
| id: nodeHashId, | ||
| indexId: indexId++, | ||
| nodeHashId, | ||
| nodeType: "BUTTON Node" /* BUTTON */, | ||
| locator: selector, | ||
| attributes: __spreadProps(__spreadValues({}, attributes), { | ||
| htmlTagName: tagNameOfNode(node), | ||
| nodeType: "BUTTON Node" /* BUTTON */ | ||
| }), | ||
| content, | ||
| rect, | ||
| center: [ | ||
| Math.round(rect.left + rect.width / 2), | ||
| Math.round(rect.top + rect.height / 2) | ||
| ], | ||
| zoom: rect.zoom, | ||
| screenWidth: currentWindow.innerWidth, | ||
| screenHeight: currentWindow.innerHeight | ||
| }; | ||
| return elementInfo; | ||
| } | ||
| if (isImgElement(node)) { | ||
| const attributes = getNodeAttributes(node, currentWindow); | ||
| const nodeHashId = midsceneGenerateHash(node, "", rect); | ||
| const selector = setDataForNode(node, nodeHashId, false, currentWindow); | ||
| const elementInfo = { | ||
| id: nodeHashId, | ||
| indexId: indexId++, | ||
| nodeHashId, | ||
| locator: selector, | ||
| attributes: __spreadProps(__spreadValues(__spreadValues({}, attributes), node.nodeName.toLowerCase() === "svg" ? { | ||
| svgContent: "true" | ||
| } : {}), { | ||
| nodeType: "IMG Node" /* IMG */, | ||
| htmlTagName: tagNameOfNode(node) | ||
| }), | ||
| nodeType: "IMG Node" /* IMG */, | ||
| content: "", | ||
| rect, | ||
| center: [ | ||
| Math.round(rect.left + rect.width / 2), | ||
| Math.round(rect.top + rect.height / 2) | ||
| ], | ||
| zoom: rect.zoom, | ||
| screenWidth: currentWindow.innerWidth, | ||
| screenHeight: currentWindow.innerHeight | ||
| }; | ||
| return elementInfo; | ||
| } | ||
| if (isTextElement(node)) { | ||
| const text = (_a = node.textContent) == null ? void 0 : _a.trim().replace(/\n+/g, " "); | ||
| if (!text) { | ||
| return null; | ||
| } | ||
| const attributes = getNodeAttributes(node, currentWindow); | ||
| const attributeKeys = Object.keys(attributes); | ||
| if (!text.trim() && attributeKeys.length === 0) { | ||
| return null; | ||
| } | ||
| const nodeHashId = midsceneGenerateHash(node, text, rect); | ||
| const selector = setDataForNode(node, nodeHashId, true, currentWindow); | ||
| const elementInfo = { | ||
| id: nodeHashId, | ||
| indexId: indexId++, | ||
| nodeHashId, | ||
| nodeType: "TEXT Node" /* TEXT */, | ||
| locator: selector, | ||
| attributes: __spreadProps(__spreadValues({}, attributes), { | ||
| nodeType: "TEXT Node" /* TEXT */, | ||
| htmlTagName: tagNameOfNode(node) | ||
| }), | ||
| center: [ | ||
| Math.round(rect.left + rect.width / 2), | ||
| Math.round(rect.top + rect.height / 2) | ||
| ], | ||
| // attributes, | ||
| content: text, | ||
| rect, | ||
| zoom: rect.zoom, | ||
| screenWidth: currentWindow.innerWidth, | ||
| screenHeight: currentWindow.innerHeight | ||
| }; | ||
| return elementInfo; | ||
| } | ||
| if (isContainerElement(node)) { | ||
| const attributes = getNodeAttributes(node, currentWindow); | ||
| const nodeHashId = midsceneGenerateHash(node, "", rect); | ||
| const selector = setDataForNode(node, nodeHashId, false, currentWindow); | ||
| const elementInfo = { | ||
| id: nodeHashId, | ||
| nodeHashId, | ||
| indexId: indexId++, | ||
| nodeType: "CONTAINER Node" /* CONTAINER */, | ||
| locator: selector, | ||
| attributes: __spreadProps(__spreadValues({}, attributes), { | ||
| nodeType: "CONTAINER Node" /* CONTAINER */, | ||
| htmlTagName: tagNameOfNode(node) | ||
| }), | ||
| content: "", | ||
| rect, | ||
| center: [ | ||
| Math.round(rect.left + rect.width / 2), | ||
| Math.round(rect.top + rect.height / 2) | ||
| ], | ||
| zoom: rect.zoom, | ||
| screenWidth: currentWindow.innerWidth, | ||
| screenHeight: currentWindow.innerHeight | ||
| }; | ||
| return elementInfo; | ||
| } | ||
| return null; | ||
| } | ||
| function extractTextWithPosition(initNode, debugMode2 = false) { | ||
| const elementNode = extractTreeNode(initNode, debugMode2); | ||
| const elementInfoArray = []; | ||
| function dfsTopChildren(node) { | ||
| if (node.node) { | ||
| elementInfoArray.push(node.node); | ||
| } | ||
| for (let i = 0; i < node.children.length; i++) { | ||
| dfsTopChildren(node.children[i]); | ||
| } | ||
| } | ||
| dfsTopChildren({ children: elementNode.children, node: elementNode.node }); | ||
| return elementInfoArray; | ||
| } | ||
| function extractTreeNode(initNode, debugMode2 = false) { | ||
| setDebugMode(debugMode2); | ||
| resetNodeHashCacheList(); | ||
| indexId = 0; | ||
| const topDocument = getTopDocument(); | ||
| const startNode = initNode || topDocument; | ||
| const topChildren = []; | ||
| function dfs(node, currentWindow, currentDocument, baseZoom = 1, basePoint = { left: 0, top: 0 }) { | ||
| if (!node) { | ||
| return null; | ||
| } | ||
| if (node.nodeType && node.nodeType === 10) { | ||
| return null; | ||
| } | ||
| const elementInfo = collectElementInfo( | ||
| node, | ||
| currentWindow, | ||
| currentDocument, | ||
| baseZoom, | ||
| basePoint | ||
| ); | ||
| if (node instanceof currentWindow.HTMLIFrameElement) { | ||
| if (node.contentWindow && node.contentWindow) { | ||
| return null; | ||
| } | ||
| } | ||
| const nodeInfo = { | ||
| node: elementInfo, | ||
| children: [] | ||
| }; | ||
| if ((elementInfo == null ? void 0 : elementInfo.nodeType) === "BUTTON Node" /* BUTTON */ || (elementInfo == null ? void 0 : elementInfo.nodeType) === "IMG Node" /* IMG */ || (elementInfo == null ? void 0 : elementInfo.nodeType) === "TEXT Node" /* TEXT */ || (elementInfo == null ? void 0 : elementInfo.nodeType) === "FORM_ITEM Node" /* FORM_ITEM */ || (elementInfo == null ? void 0 : elementInfo.nodeType) === "CONTAINER Node" /* CONTAINER */) { | ||
| return nodeInfo; | ||
| } | ||
| const rect = getRect(node, baseZoom, currentWindow); | ||
| for (let i = 0; i < node.childNodes.length; i++) { | ||
| logger("will dfs", node.childNodes[i]); | ||
| const childNodeInfo = dfs( | ||
| node.childNodes[i], | ||
| currentWindow, | ||
| currentDocument, | ||
| rect.zoom, | ||
| basePoint | ||
| ); | ||
| if (childNodeInfo) { | ||
| nodeInfo.children.push(childNodeInfo); | ||
| } | ||
| } | ||
| return nodeInfo; | ||
| } | ||
| const rootNodeInfo = dfs(startNode, window, document, 1, { | ||
| left: 0, | ||
| top: 0 | ||
| }); | ||
| if (rootNodeInfo) { | ||
| topChildren.push(rootNodeInfo); | ||
| } | ||
| if (startNode === topDocument) { | ||
| const iframes = document.querySelectorAll("iframe"); | ||
| for (let i = 0; i < iframes.length; i++) { | ||
| const iframe = iframes[i]; | ||
| if (iframe.contentDocument && iframe.contentWindow) { | ||
| const iframeInfo = collectElementInfo(iframe, window, document, 1); | ||
| if (iframeInfo) { | ||
| const iframeChildren = dfs( | ||
| iframe.contentDocument.body, | ||
| iframe.contentWindow, | ||
| iframe.contentDocument, | ||
| 1, | ||
| { | ||
| left: iframeInfo.rect.left, | ||
| top: iframeInfo.rect.top | ||
| } | ||
| ); | ||
| if (iframeChildren) { | ||
| topChildren.push(iframeChildren); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| return { | ||
| node: null, | ||
| children: topChildren | ||
| }; | ||
| } | ||
| // src/extractor/debug.ts | ||
| console.log(extractTextWithPosition(document.body, true)); | ||
| console.log(JSON.stringify(extractTextWithPosition(document.body, true))); | ||
| setExtractTextWithPositionOnWindow(); | ||
| setMidsceneVisibleRectOnWindow(); | ||
| /*! Bundled license information: | ||
| js-sha256/src/sha256.js: | ||
| (** | ||
| * [js-sha256]{@link https://github.com/emn178/js-sha256} | ||
| * | ||
| * @version 0.11.0 | ||
| * @author Chen, Yi-Cyuan [emn178@gmail.com] | ||
| * @copyright Chen, Yi-Cyuan 2014-2024 | ||
| * @license MIT | ||
| *) | ||
| */ |
| import { NodeType } from './constants.js'; | ||
| import { B as BaseElement, E as ElementTreeNode } from './index-305e7a7e.js'; | ||
| declare function descriptionOfTree<ElementType extends BaseElement = BaseElement>(tree: ElementTreeNode<ElementType>, truncateTextLength?: number, filterNonTextContent?: boolean): string; | ||
| declare function treeToList<T extends BaseElement>(tree: ElementTreeNode<T>): T[]; | ||
| declare function traverseTree<T extends BaseElement, ReturnNodeType extends BaseElement>(tree: ElementTreeNode<T>, onNode: (node: T) => ReturnNodeType): ElementTreeNode<ReturnNodeType>; | ||
| interface WebElementInfo extends ElementInfo { | ||
| zoom: number; | ||
| screenWidth?: number; | ||
| screenHeight?: number; | ||
| } | ||
| interface WebElementNode { | ||
| node: WebElementInfo | null; | ||
| children: WebElementNode[]; | ||
| } | ||
| declare function extractTextWithPosition$1(initNode: globalThis.Node, debugMode?: boolean): WebElementInfo[]; | ||
| declare function extractTreeNodeAsString(initNode: globalThis.Node, debugMode?: boolean): string; | ||
| declare function extractTreeNode(initNode: globalThis.Node, debugMode?: boolean): WebElementNode; | ||
| declare function extractTextWithPosition(initNode: globalThis.Document): ElementInfo[]; | ||
| interface ElementInfo { | ||
| id: string; | ||
| indexId: number; | ||
| nodeHashId: string; | ||
| locator: string; | ||
| attributes: { | ||
| nodeType: NodeType; | ||
| [key: string]: string; | ||
| }; | ||
| nodeType: NodeType; | ||
| content: string; | ||
| rect: { | ||
| left: number; | ||
| top: number; | ||
| width: number; | ||
| height: number; | ||
| }; | ||
| center: [number, number]; | ||
| } | ||
| interface ElementNode { | ||
| node: ElementInfo | null; | ||
| children: ElementNode[]; | ||
| } | ||
| export { type ElementInfo, type ElementNode, extractTextWithPosition as clientExtractTextWithPosition, descriptionOfTree, traverseTree, treeToList, extractTreeNode as webExtractNodeTree, extractTreeNodeAsString as webExtractNodeTreeAsString, extractTextWithPosition$1 as webExtractTextWithPosition }; |
| "use strict"; | ||
| var __create = Object.create; | ||
| var __defProp = Object.defineProperty; | ||
| var __defProps = Object.defineProperties; | ||
| var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
| var __getOwnPropDescs = Object.getOwnPropertyDescriptors; | ||
| var __getOwnPropNames = Object.getOwnPropertyNames; | ||
| var __getOwnPropSymbols = Object.getOwnPropertySymbols; | ||
| var __getProtoOf = Object.getPrototypeOf; | ||
| var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
| var __propIsEnum = Object.prototype.propertyIsEnumerable; | ||
| var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; | ||
| var __spreadValues = (a, b) => { | ||
| for (var prop in b || (b = {})) | ||
| if (__hasOwnProp.call(b, prop)) | ||
| __defNormalProp(a, prop, b[prop]); | ||
| if (__getOwnPropSymbols) | ||
| for (var prop of __getOwnPropSymbols(b)) { | ||
| if (__propIsEnum.call(b, prop)) | ||
| __defNormalProp(a, prop, b[prop]); | ||
| } | ||
| return a; | ||
| }; | ||
| var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b)); | ||
| var __commonJS = (cb, mod) => function __require() { | ||
| return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports; | ||
| }; | ||
| var __export = (target, all) => { | ||
| for (var name in all) | ||
| __defProp(target, name, { get: all[name], enumerable: true }); | ||
| }; | ||
| var __copyProps = (to, from, except, desc) => { | ||
| if (from && typeof from === "object" || typeof from === "function") { | ||
| for (let key of __getOwnPropNames(from)) | ||
| if (!__hasOwnProp.call(to, key) && key !== except) | ||
| __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); | ||
| } | ||
| return to; | ||
| }; | ||
| var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( | ||
| // If the importer is in node compatibility mode or this is not an ESM | ||
| // file that has been converted to a CommonJS file using a Babel- | ||
| // compatible transform (i.e. "__esModule" has not been set), then set | ||
| // "default" to the CommonJS "module.exports" for node compatibility. | ||
| isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, | ||
| mod | ||
| )); | ||
| var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); | ||
| // resolve-false:/empty-stub | ||
| var require_empty_stub = __commonJS({ | ||
| "resolve-false:/empty-stub"(exports, module2) { | ||
| "use strict"; | ||
| module2.exports = {}; | ||
| } | ||
| }); | ||
| // ../../node_modules/.pnpm/js-sha256@0.11.0/node_modules/js-sha256/src/sha256.js | ||
| var require_sha256 = __commonJS({ | ||
| "../../node_modules/.pnpm/js-sha256@0.11.0/node_modules/js-sha256/src/sha256.js"(exports, module2) { | ||
| "use strict"; | ||
| (function() { | ||
| "use strict"; | ||
| var ERROR = "input is invalid type"; | ||
| var WINDOW = typeof window === "object"; | ||
| var root = WINDOW ? window : {}; | ||
| if (root.JS_SHA256_NO_WINDOW) { | ||
| WINDOW = false; | ||
| } | ||
| var WEB_WORKER = !WINDOW && typeof self === "object"; | ||
| var NODE_JS = !root.JS_SHA256_NO_NODE_JS && typeof process === "object" && process.versions && process.versions.node; | ||
| if (NODE_JS) { | ||
| root = global; | ||
| } else if (WEB_WORKER) { | ||
| root = self; | ||
| } | ||
| var COMMON_JS = !root.JS_SHA256_NO_COMMON_JS && typeof module2 === "object" && module2.exports; | ||
| var AMD = typeof define === "function" && define.amd; | ||
| var ARRAY_BUFFER = !root.JS_SHA256_NO_ARRAY_BUFFER && typeof ArrayBuffer !== "undefined"; | ||
| var HEX_CHARS = "0123456789abcdef".split(""); | ||
| var EXTRA = [-2147483648, 8388608, 32768, 128]; | ||
| var SHIFT = [24, 16, 8, 0]; | ||
| var K = [ | ||
| 1116352408, | ||
| 1899447441, | ||
| 3049323471, | ||
| 3921009573, | ||
| 961987163, | ||
| 1508970993, | ||
| 2453635748, | ||
| 2870763221, | ||
| 3624381080, | ||
| 310598401, | ||
| 607225278, | ||
| 1426881987, | ||
| 1925078388, | ||
| 2162078206, | ||
| 2614888103, | ||
| 3248222580, | ||
| 3835390401, | ||
| 4022224774, | ||
| 264347078, | ||
| 604807628, | ||
| 770255983, | ||
| 1249150122, | ||
| 1555081692, | ||
| 1996064986, | ||
| 2554220882, | ||
| 2821834349, | ||
| 2952996808, | ||
| 3210313671, | ||
| 3336571891, | ||
| 3584528711, | ||
| 113926993, | ||
| 338241895, | ||
| 666307205, | ||
| 773529912, | ||
| 1294757372, | ||
| 1396182291, | ||
| 1695183700, | ||
| 1986661051, | ||
| 2177026350, | ||
| 2456956037, | ||
| 2730485921, | ||
| 2820302411, | ||
| 3259730800, | ||
| 3345764771, | ||
| 3516065817, | ||
| 3600352804, | ||
| 4094571909, | ||
| 275423344, | ||
| 430227734, | ||
| 506948616, | ||
| 659060556, | ||
| 883997877, | ||
| 958139571, | ||
| 1322822218, | ||
| 1537002063, | ||
| 1747873779, | ||
| 1955562222, | ||
| 2024104815, | ||
| 2227730452, | ||
| 2361852424, | ||
| 2428436474, | ||
| 2756734187, | ||
| 3204031479, | ||
| 3329325298 | ||
| ]; | ||
| var OUTPUT_TYPES = ["hex", "array", "digest", "arrayBuffer"]; | ||
| var blocks = []; | ||
| if (root.JS_SHA256_NO_NODE_JS || !Array.isArray) { | ||
| Array.isArray = function(obj) { | ||
| return Object.prototype.toString.call(obj) === "[object Array]"; | ||
| }; | ||
| } | ||
| if (ARRAY_BUFFER && (root.JS_SHA256_NO_ARRAY_BUFFER_IS_VIEW || !ArrayBuffer.isView)) { | ||
| ArrayBuffer.isView = function(obj) { | ||
| return typeof obj === "object" && obj.buffer && obj.buffer.constructor === ArrayBuffer; | ||
| }; | ||
| } | ||
| var createOutputMethod = function(outputType, is224) { | ||
| return function(message) { | ||
| return new Sha256(is224, true).update(message)[outputType](); | ||
| }; | ||
| }; | ||
| var createMethod = function(is224) { | ||
| var method = createOutputMethod("hex", is224); | ||
| if (NODE_JS) { | ||
| method = nodeWrap(method, is224); | ||
| } | ||
| method.create = function() { | ||
| return new Sha256(is224); | ||
| }; | ||
| method.update = function(message) { | ||
| return method.create().update(message); | ||
| }; | ||
| for (var i = 0; i < OUTPUT_TYPES.length; ++i) { | ||
| var type = OUTPUT_TYPES[i]; | ||
| method[type] = createOutputMethod(type, is224); | ||
| } | ||
| return method; | ||
| }; | ||
| var nodeWrap = function(method, is224) { | ||
| var crypto = require_empty_stub(); | ||
| var Buffer2 = require_empty_stub().Buffer; | ||
| var algorithm = is224 ? "sha224" : "sha256"; | ||
| var bufferFrom; | ||
| if (Buffer2.from && !root.JS_SHA256_NO_BUFFER_FROM) { | ||
| bufferFrom = Buffer2.from; | ||
| } else { | ||
| bufferFrom = function(message) { | ||
| return new Buffer2(message); | ||
| }; | ||
| } | ||
| var nodeMethod = function(message) { | ||
| if (typeof message === "string") { | ||
| return crypto.createHash(algorithm).update(message, "utf8").digest("hex"); | ||
| } else { | ||
| if (message === null || message === void 0) { | ||
| throw new Error(ERROR); | ||
| } else if (message.constructor === ArrayBuffer) { | ||
| message = new Uint8Array(message); | ||
| } | ||
| } | ||
| if (Array.isArray(message) || ArrayBuffer.isView(message) || message.constructor === Buffer2) { | ||
| return crypto.createHash(algorithm).update(bufferFrom(message)).digest("hex"); | ||
| } else { | ||
| return method(message); | ||
| } | ||
| }; | ||
| return nodeMethod; | ||
| }; | ||
| var createHmacOutputMethod = function(outputType, is224) { | ||
| return function(key, message) { | ||
| return new HmacSha256(key, is224, true).update(message)[outputType](); | ||
| }; | ||
| }; | ||
| var createHmacMethod = function(is224) { | ||
| var method = createHmacOutputMethod("hex", is224); | ||
| method.create = function(key) { | ||
| return new HmacSha256(key, is224); | ||
| }; | ||
| method.update = function(key, message) { | ||
| return method.create(key).update(message); | ||
| }; | ||
| for (var i = 0; i < OUTPUT_TYPES.length; ++i) { | ||
| var type = OUTPUT_TYPES[i]; | ||
| method[type] = createHmacOutputMethod(type, is224); | ||
| } | ||
| return method; | ||
| }; | ||
| function Sha256(is224, sharedMemory) { | ||
| if (sharedMemory) { | ||
| blocks[0] = blocks[16] = blocks[1] = blocks[2] = blocks[3] = blocks[4] = blocks[5] = blocks[6] = blocks[7] = blocks[8] = blocks[9] = blocks[10] = blocks[11] = blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0; | ||
| this.blocks = blocks; | ||
| } else { | ||
| this.blocks = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; | ||
| } | ||
| if (is224) { | ||
| this.h0 = 3238371032; | ||
| this.h1 = 914150663; | ||
| this.h2 = 812702999; | ||
| this.h3 = 4144912697; | ||
| this.h4 = 4290775857; | ||
| this.h5 = 1750603025; | ||
| this.h6 = 1694076839; | ||
| this.h7 = 3204075428; | ||
| } else { | ||
| this.h0 = 1779033703; | ||
| this.h1 = 3144134277; | ||
| this.h2 = 1013904242; | ||
| this.h3 = 2773480762; | ||
| this.h4 = 1359893119; | ||
| this.h5 = 2600822924; | ||
| this.h6 = 528734635; | ||
| this.h7 = 1541459225; | ||
| } | ||
| this.block = this.start = this.bytes = this.hBytes = 0; | ||
| this.finalized = this.hashed = false; | ||
| this.first = true; | ||
| this.is224 = is224; | ||
| } | ||
| Sha256.prototype.update = function(message) { | ||
| if (this.finalized) { | ||
| return; | ||
| } | ||
| var notString, type = typeof message; | ||
| if (type !== "string") { | ||
| if (type === "object") { | ||
| if (message === null) { | ||
| throw new Error(ERROR); | ||
| } else if (ARRAY_BUFFER && message.constructor === ArrayBuffer) { | ||
| message = new Uint8Array(message); | ||
| } else if (!Array.isArray(message)) { | ||
| if (!ARRAY_BUFFER || !ArrayBuffer.isView(message)) { | ||
| throw new Error(ERROR); | ||
| } | ||
| } | ||
| } else { | ||
| throw new Error(ERROR); | ||
| } | ||
| notString = true; | ||
| } | ||
| var code, index = 0, i, length = message.length, blocks2 = this.blocks; | ||
| while (index < length) { | ||
| if (this.hashed) { | ||
| this.hashed = false; | ||
| blocks2[0] = this.block; | ||
| this.block = blocks2[16] = blocks2[1] = blocks2[2] = blocks2[3] = blocks2[4] = blocks2[5] = blocks2[6] = blocks2[7] = blocks2[8] = blocks2[9] = blocks2[10] = blocks2[11] = blocks2[12] = blocks2[13] = blocks2[14] = blocks2[15] = 0; | ||
| } | ||
| if (notString) { | ||
| for (i = this.start; index < length && i < 64; ++index) { | ||
| blocks2[i >>> 2] |= message[index] << SHIFT[i++ & 3]; | ||
| } | ||
| } else { | ||
| for (i = this.start; index < length && i < 64; ++index) { | ||
| code = message.charCodeAt(index); | ||
| if (code < 128) { | ||
| blocks2[i >>> 2] |= code << SHIFT[i++ & 3]; | ||
| } else if (code < 2048) { | ||
| blocks2[i >>> 2] |= (192 | code >>> 6) << SHIFT[i++ & 3]; | ||
| blocks2[i >>> 2] |= (128 | code & 63) << SHIFT[i++ & 3]; | ||
| } else if (code < 55296 || code >= 57344) { | ||
| blocks2[i >>> 2] |= (224 | code >>> 12) << SHIFT[i++ & 3]; | ||
| blocks2[i >>> 2] |= (128 | code >>> 6 & 63) << SHIFT[i++ & 3]; | ||
| blocks2[i >>> 2] |= (128 | code & 63) << SHIFT[i++ & 3]; | ||
| } else { | ||
| code = 65536 + ((code & 1023) << 10 | message.charCodeAt(++index) & 1023); | ||
| blocks2[i >>> 2] |= (240 | code >>> 18) << SHIFT[i++ & 3]; | ||
| blocks2[i >>> 2] |= (128 | code >>> 12 & 63) << SHIFT[i++ & 3]; | ||
| blocks2[i >>> 2] |= (128 | code >>> 6 & 63) << SHIFT[i++ & 3]; | ||
| blocks2[i >>> 2] |= (128 | code & 63) << SHIFT[i++ & 3]; | ||
| } | ||
| } | ||
| } | ||
| this.lastByteIndex = i; | ||
| this.bytes += i - this.start; | ||
| if (i >= 64) { | ||
| this.block = blocks2[16]; | ||
| this.start = i - 64; | ||
| this.hash(); | ||
| this.hashed = true; | ||
| } else { | ||
| this.start = i; | ||
| } | ||
| } | ||
| if (this.bytes > 4294967295) { | ||
| this.hBytes += this.bytes / 4294967296 << 0; | ||
| this.bytes = this.bytes % 4294967296; | ||
| } | ||
| return this; | ||
| }; | ||
| Sha256.prototype.finalize = function() { | ||
| if (this.finalized) { | ||
| return; | ||
| } | ||
| this.finalized = true; | ||
| var blocks2 = this.blocks, i = this.lastByteIndex; | ||
| blocks2[16] = this.block; | ||
| blocks2[i >>> 2] |= EXTRA[i & 3]; | ||
| this.block = blocks2[16]; | ||
| if (i >= 56) { | ||
| if (!this.hashed) { | ||
| this.hash(); | ||
| } | ||
| blocks2[0] = this.block; | ||
| blocks2[16] = blocks2[1] = blocks2[2] = blocks2[3] = blocks2[4] = blocks2[5] = blocks2[6] = blocks2[7] = blocks2[8] = blocks2[9] = blocks2[10] = blocks2[11] = blocks2[12] = blocks2[13] = blocks2[14] = blocks2[15] = 0; | ||
| } | ||
| blocks2[14] = this.hBytes << 3 | this.bytes >>> 29; | ||
| blocks2[15] = this.bytes << 3; | ||
| this.hash(); | ||
| }; | ||
| Sha256.prototype.hash = function() { | ||
| var a = this.h0, b = this.h1, c = this.h2, d = this.h3, e = this.h4, f = this.h5, g = this.h6, h = this.h7, blocks2 = this.blocks, j, s0, s1, maj, t1, t2, ch, ab, da, cd, bc; | ||
| for (j = 16; j < 64; ++j) { | ||
| t1 = blocks2[j - 15]; | ||
| s0 = (t1 >>> 7 | t1 << 25) ^ (t1 >>> 18 | t1 << 14) ^ t1 >>> 3; | ||
| t1 = blocks2[j - 2]; | ||
| s1 = (t1 >>> 17 | t1 << 15) ^ (t1 >>> 19 | t1 << 13) ^ t1 >>> 10; | ||
| blocks2[j] = blocks2[j - 16] + s0 + blocks2[j - 7] + s1 << 0; | ||
| } | ||
| bc = b & c; | ||
| for (j = 0; j < 64; j += 4) { | ||
| if (this.first) { | ||
| if (this.is224) { | ||
| ab = 300032; | ||
| t1 = blocks2[0] - 1413257819; | ||
| h = t1 - 150054599 << 0; | ||
| d = t1 + 24177077 << 0; | ||
| } else { | ||
| ab = 704751109; | ||
| t1 = blocks2[0] - 210244248; | ||
| h = t1 - 1521486534 << 0; | ||
| d = t1 + 143694565 << 0; | ||
| } | ||
| this.first = false; | ||
| } else { | ||
| s0 = (a >>> 2 | a << 30) ^ (a >>> 13 | a << 19) ^ (a >>> 22 | a << 10); | ||
| s1 = (e >>> 6 | e << 26) ^ (e >>> 11 | e << 21) ^ (e >>> 25 | e << 7); | ||
| ab = a & b; | ||
| maj = ab ^ a & c ^ bc; | ||
| ch = e & f ^ ~e & g; | ||
| t1 = h + s1 + ch + K[j] + blocks2[j]; | ||
| t2 = s0 + maj; | ||
| h = d + t1 << 0; | ||
| d = t1 + t2 << 0; | ||
| } | ||
| s0 = (d >>> 2 | d << 30) ^ (d >>> 13 | d << 19) ^ (d >>> 22 | d << 10); | ||
| s1 = (h >>> 6 | h << 26) ^ (h >>> 11 | h << 21) ^ (h >>> 25 | h << 7); | ||
| da = d & a; | ||
| maj = da ^ d & b ^ ab; | ||
| ch = h & e ^ ~h & f; | ||
| t1 = g + s1 + ch + K[j + 1] + blocks2[j + 1]; | ||
| t2 = s0 + maj; | ||
| g = c + t1 << 0; | ||
| c = t1 + t2 << 0; | ||
| s0 = (c >>> 2 | c << 30) ^ (c >>> 13 | c << 19) ^ (c >>> 22 | c << 10); | ||
| s1 = (g >>> 6 | g << 26) ^ (g >>> 11 | g << 21) ^ (g >>> 25 | g << 7); | ||
| cd = c & d; | ||
| maj = cd ^ c & a ^ da; | ||
| ch = g & h ^ ~g & e; | ||
| t1 = f + s1 + ch + K[j + 2] + blocks2[j + 2]; | ||
| t2 = s0 + maj; | ||
| f = b + t1 << 0; | ||
| b = t1 + t2 << 0; | ||
| s0 = (b >>> 2 | b << 30) ^ (b >>> 13 | b << 19) ^ (b >>> 22 | b << 10); | ||
| s1 = (f >>> 6 | f << 26) ^ (f >>> 11 | f << 21) ^ (f >>> 25 | f << 7); | ||
| bc = b & c; | ||
| maj = bc ^ b & d ^ cd; | ||
| ch = f & g ^ ~f & h; | ||
| t1 = e + s1 + ch + K[j + 3] + blocks2[j + 3]; | ||
| t2 = s0 + maj; | ||
| e = a + t1 << 0; | ||
| a = t1 + t2 << 0; | ||
| this.chromeBugWorkAround = true; | ||
| } | ||
| this.h0 = this.h0 + a << 0; | ||
| this.h1 = this.h1 + b << 0; | ||
| this.h2 = this.h2 + c << 0; | ||
| this.h3 = this.h3 + d << 0; | ||
| this.h4 = this.h4 + e << 0; | ||
| this.h5 = this.h5 + f << 0; | ||
| this.h6 = this.h6 + g << 0; | ||
| this.h7 = this.h7 + h << 0; | ||
| }; | ||
| Sha256.prototype.hex = function() { | ||
| this.finalize(); | ||
| var h0 = this.h0, h1 = this.h1, h2 = this.h2, h3 = this.h3, h4 = this.h4, h5 = this.h5, h6 = this.h6, h7 = this.h7; | ||
| var hex = HEX_CHARS[h0 >>> 28 & 15] + HEX_CHARS[h0 >>> 24 & 15] + HEX_CHARS[h0 >>> 20 & 15] + HEX_CHARS[h0 >>> 16 & 15] + HEX_CHARS[h0 >>> 12 & 15] + HEX_CHARS[h0 >>> 8 & 15] + HEX_CHARS[h0 >>> 4 & 15] + HEX_CHARS[h0 & 15] + HEX_CHARS[h1 >>> 28 & 15] + HEX_CHARS[h1 >>> 24 & 15] + HEX_CHARS[h1 >>> 20 & 15] + HEX_CHARS[h1 >>> 16 & 15] + HEX_CHARS[h1 >>> 12 & 15] + HEX_CHARS[h1 >>> 8 & 15] + HEX_CHARS[h1 >>> 4 & 15] + HEX_CHARS[h1 & 15] + HEX_CHARS[h2 >>> 28 & 15] + HEX_CHARS[h2 >>> 24 & 15] + HEX_CHARS[h2 >>> 20 & 15] + HEX_CHARS[h2 >>> 16 & 15] + HEX_CHARS[h2 >>> 12 & 15] + HEX_CHARS[h2 >>> 8 & 15] + HEX_CHARS[h2 >>> 4 & 15] + HEX_CHARS[h2 & 15] + HEX_CHARS[h3 >>> 28 & 15] + HEX_CHARS[h3 >>> 24 & 15] + HEX_CHARS[h3 >>> 20 & 15] + HEX_CHARS[h3 >>> 16 & 15] + HEX_CHARS[h3 >>> 12 & 15] + HEX_CHARS[h3 >>> 8 & 15] + HEX_CHARS[h3 >>> 4 & 15] + HEX_CHARS[h3 & 15] + HEX_CHARS[h4 >>> 28 & 15] + HEX_CHARS[h4 >>> 24 & 15] + HEX_CHARS[h4 >>> 20 & 15] + HEX_CHARS[h4 >>> 16 & 15] + HEX_CHARS[h4 >>> 12 & 15] + HEX_CHARS[h4 >>> 8 & 15] + HEX_CHARS[h4 >>> 4 & 15] + HEX_CHARS[h4 & 15] + HEX_CHARS[h5 >>> 28 & 15] + HEX_CHARS[h5 >>> 24 & 15] + HEX_CHARS[h5 >>> 20 & 15] + HEX_CHARS[h5 >>> 16 & 15] + HEX_CHARS[h5 >>> 12 & 15] + HEX_CHARS[h5 >>> 8 & 15] + HEX_CHARS[h5 >>> 4 & 15] + HEX_CHARS[h5 & 15] + HEX_CHARS[h6 >>> 28 & 15] + HEX_CHARS[h6 >>> 24 & 15] + HEX_CHARS[h6 >>> 20 & 15] + HEX_CHARS[h6 >>> 16 & 15] + HEX_CHARS[h6 >>> 12 & 15] + HEX_CHARS[h6 >>> 8 & 15] + HEX_CHARS[h6 >>> 4 & 15] + HEX_CHARS[h6 & 15]; | ||
| if (!this.is224) { | ||
| hex += HEX_CHARS[h7 >>> 28 & 15] + HEX_CHARS[h7 >>> 24 & 15] + HEX_CHARS[h7 >>> 20 & 15] + HEX_CHARS[h7 >>> 16 & 15] + HEX_CHARS[h7 >>> 12 & 15] + HEX_CHARS[h7 >>> 8 & 15] + HEX_CHARS[h7 >>> 4 & 15] + HEX_CHARS[h7 & 15]; | ||
| } | ||
| return hex; | ||
| }; | ||
| Sha256.prototype.toString = Sha256.prototype.hex; | ||
| Sha256.prototype.digest = function() { | ||
| this.finalize(); | ||
| var h0 = this.h0, h1 = this.h1, h2 = this.h2, h3 = this.h3, h4 = this.h4, h5 = this.h5, h6 = this.h6, h7 = this.h7; | ||
| var arr = [ | ||
| h0 >>> 24 & 255, | ||
| h0 >>> 16 & 255, | ||
| h0 >>> 8 & 255, | ||
| h0 & 255, | ||
| h1 >>> 24 & 255, | ||
| h1 >>> 16 & 255, | ||
| h1 >>> 8 & 255, | ||
| h1 & 255, | ||
| h2 >>> 24 & 255, | ||
| h2 >>> 16 & 255, | ||
| h2 >>> 8 & 255, | ||
| h2 & 255, | ||
| h3 >>> 24 & 255, | ||
| h3 >>> 16 & 255, | ||
| h3 >>> 8 & 255, | ||
| h3 & 255, | ||
| h4 >>> 24 & 255, | ||
| h4 >>> 16 & 255, | ||
| h4 >>> 8 & 255, | ||
| h4 & 255, | ||
| h5 >>> 24 & 255, | ||
| h5 >>> 16 & 255, | ||
| h5 >>> 8 & 255, | ||
| h5 & 255, | ||
| h6 >>> 24 & 255, | ||
| h6 >>> 16 & 255, | ||
| h6 >>> 8 & 255, | ||
| h6 & 255 | ||
| ]; | ||
| if (!this.is224) { | ||
| arr.push(h7 >>> 24 & 255, h7 >>> 16 & 255, h7 >>> 8 & 255, h7 & 255); | ||
| } | ||
| return arr; | ||
| }; | ||
| Sha256.prototype.array = Sha256.prototype.digest; | ||
| Sha256.prototype.arrayBuffer = function() { | ||
| this.finalize(); | ||
| var buffer = new ArrayBuffer(this.is224 ? 28 : 32); | ||
| var dataView = new DataView(buffer); | ||
| dataView.setUint32(0, this.h0); | ||
| dataView.setUint32(4, this.h1); | ||
| dataView.setUint32(8, this.h2); | ||
| dataView.setUint32(12, this.h3); | ||
| dataView.setUint32(16, this.h4); | ||
| dataView.setUint32(20, this.h5); | ||
| dataView.setUint32(24, this.h6); | ||
| if (!this.is224) { | ||
| dataView.setUint32(28, this.h7); | ||
| } | ||
| return buffer; | ||
| }; | ||
| function HmacSha256(key, is224, sharedMemory) { | ||
| var i, type = typeof key; | ||
| if (type === "string") { | ||
| var bytes = [], length = key.length, index = 0, code; | ||
| for (i = 0; i < length; ++i) { | ||
| code = key.charCodeAt(i); | ||
| if (code < 128) { | ||
| bytes[index++] = code; | ||
| } else if (code < 2048) { | ||
| bytes[index++] = 192 | code >>> 6; | ||
| bytes[index++] = 128 | code & 63; | ||
| } else if (code < 55296 || code >= 57344) { | ||
| bytes[index++] = 224 | code >>> 12; | ||
| bytes[index++] = 128 | code >>> 6 & 63; | ||
| bytes[index++] = 128 | code & 63; | ||
| } else { | ||
| code = 65536 + ((code & 1023) << 10 | key.charCodeAt(++i) & 1023); | ||
| bytes[index++] = 240 | code >>> 18; | ||
| bytes[index++] = 128 | code >>> 12 & 63; | ||
| bytes[index++] = 128 | code >>> 6 & 63; | ||
| bytes[index++] = 128 | code & 63; | ||
| } | ||
| } | ||
| key = bytes; | ||
| } else { | ||
| if (type === "object") { | ||
| if (key === null) { | ||
| throw new Error(ERROR); | ||
| } else if (ARRAY_BUFFER && key.constructor === ArrayBuffer) { | ||
| key = new Uint8Array(key); | ||
| } else if (!Array.isArray(key)) { | ||
| if (!ARRAY_BUFFER || !ArrayBuffer.isView(key)) { | ||
| throw new Error(ERROR); | ||
| } | ||
| } | ||
| } else { | ||
| throw new Error(ERROR); | ||
| } | ||
| } | ||
| if (key.length > 64) { | ||
| key = new Sha256(is224, true).update(key).array(); | ||
| } | ||
| var oKeyPad = [], iKeyPad = []; | ||
| for (i = 0; i < 64; ++i) { | ||
| var b = key[i] || 0; | ||
| oKeyPad[i] = 92 ^ b; | ||
| iKeyPad[i] = 54 ^ b; | ||
| } | ||
| Sha256.call(this, is224, sharedMemory); | ||
| this.update(iKeyPad); | ||
| this.oKeyPad = oKeyPad; | ||
| this.inner = true; | ||
| this.sharedMemory = sharedMemory; | ||
| } | ||
| HmacSha256.prototype = new Sha256(); | ||
| HmacSha256.prototype.finalize = function() { | ||
| Sha256.prototype.finalize.call(this); | ||
| if (this.inner) { | ||
| this.inner = false; | ||
| var innerHash = this.array(); | ||
| Sha256.call(this, this.is224, this.sharedMemory); | ||
| this.update(this.oKeyPad); | ||
| this.update(innerHash); | ||
| Sha256.prototype.finalize.call(this); | ||
| } | ||
| }; | ||
| var exports2 = createMethod(); | ||
| exports2.sha256 = exports2; | ||
| exports2.sha224 = createMethod(true); | ||
| exports2.sha256.hmac = createHmacMethod(); | ||
| exports2.sha224.hmac = createHmacMethod(true); | ||
| if (COMMON_JS) { | ||
| module2.exports = exports2; | ||
| } else { | ||
| root.sha256 = exports2.sha256; | ||
| root.sha224 = exports2.sha224; | ||
| if (AMD) { | ||
| define(function() { | ||
| return exports2; | ||
| }); | ||
| } | ||
| } | ||
| })(); | ||
| } | ||
| }); | ||
| // src/extractor/index.ts | ||
| var extractor_exports = {}; | ||
| __export(extractor_exports, { | ||
| clientExtractTextWithPosition: () => extractTextWithPosition2, | ||
| descriptionOfTree: () => descriptionOfTree, | ||
| traverseTree: () => traverseTree, | ||
| treeToList: () => treeToList, | ||
| webExtractNodeTree: () => extractTreeNode, | ||
| webExtractNodeTreeAsString: () => extractTreeNodeAsString, | ||
| webExtractTextWithPosition: () => extractTextWithPosition | ||
| }); | ||
| module.exports = __toCommonJS(extractor_exports); | ||
| // src/extractor/tree.ts | ||
| function truncateText(text, maxLength = 150) { | ||
| if (typeof text === "undefined") { | ||
| return ""; | ||
| } | ||
| if (typeof text === "object") { | ||
| text = JSON.stringify(text); | ||
| } | ||
| if (typeof text === "number") { | ||
| return text.toString(); | ||
| } | ||
| if (typeof text === "string" && text.length > maxLength) { | ||
| return `${text.slice(0, maxLength)}...`; | ||
| } | ||
| if (typeof text === "string") { | ||
| return text.trim(); | ||
| } | ||
| return ""; | ||
| } | ||
| function trimAttributes(attributes, truncateTextLength) { | ||
| const tailorAttributes = Object.keys(attributes).reduce( | ||
| (res, currentKey) => { | ||
| const attributeVal = attributes[currentKey]; | ||
| if (currentKey === "style" || currentKey === "src" || currentKey === "htmlTagName" || currentKey === "nodeType") { | ||
| return res; | ||
| } | ||
| res[currentKey] = truncateText(attributeVal, truncateTextLength); | ||
| return res; | ||
| }, | ||
| {} | ||
| ); | ||
| return tailorAttributes; | ||
| } | ||
| var nodeSizeThreshold = 4; | ||
| function descriptionOfTree(tree, truncateTextLength, filterNonTextContent = false) { | ||
| const attributesString = (kv) => { | ||
| return Object.entries(kv).map( | ||
| ([key, value]) => `${key}="${truncateText(value, truncateTextLength)}"` | ||
| ).join(" "); | ||
| }; | ||
| function buildContentTree(node, indent = 0) { | ||
| var _a; | ||
| let before = ""; | ||
| let contentWithIndent = ""; | ||
| let after = ""; | ||
| let emptyNode = true; | ||
| const indentStr = " ".repeat(indent); | ||
| let children = ""; | ||
| for (let i = 0; i < (node.children || []).length; i++) { | ||
| const childContent = buildContentTree(node.children[i], indent + 1); | ||
| if (childContent) { | ||
| children += ` | ||
| ${childContent}`; | ||
| } | ||
| } | ||
| if (node.node && node.node.rect.width > nodeSizeThreshold && node.node.rect.height > nodeSizeThreshold && (!filterNonTextContent || filterNonTextContent && node.node.content)) { | ||
| emptyNode = false; | ||
| let nodeTypeString; | ||
| if ((_a = node.node.attributes) == null ? void 0 : _a.htmlTagName) { | ||
| nodeTypeString = node.node.attributes.htmlTagName.replace(/[<>]/g, ""); | ||
| } else { | ||
| nodeTypeString = node.node.attributes.nodeType.replace(/\sNode$/, "").toLowerCase(); | ||
| } | ||
| const markerId = node.node.indexId; | ||
| const markerIdString = markerId ? `markerId="${markerId}"` : ""; | ||
| const rectAttribute = node.node.rect ? { | ||
| left: node.node.rect.left, | ||
| top: node.node.rect.top, | ||
| width: node.node.rect.width, | ||
| height: node.node.rect.height | ||
| } : {}; | ||
| before = `<${nodeTypeString} id="${node.node.id}" ${markerIdString} ${attributesString(trimAttributes(node.node.attributes || {}, truncateTextLength))} ${attributesString(rectAttribute)}>`; | ||
| const content = truncateText(node.node.content, truncateTextLength); | ||
| contentWithIndent = content ? ` | ||
| ${indentStr} ${content}` : ""; | ||
| after = `</${nodeTypeString}>`; | ||
| } else if (!filterNonTextContent) { | ||
| if (!children.trim().startsWith("<>")) { | ||
| before = "<>"; | ||
| contentWithIndent = ""; | ||
| after = "</>"; | ||
| } | ||
| } | ||
| if (emptyNode && !children.trim()) { | ||
| return ""; | ||
| } | ||
| const result2 = `${indentStr}${before}${contentWithIndent}${children} | ||
| ${indentStr}${after}`; | ||
| if (result2.trim()) { | ||
| return result2; | ||
| } | ||
| return ""; | ||
| } | ||
| const result = buildContentTree(tree); | ||
| return result.replace(/^\s*\n/gm, ""); | ||
| } | ||
| function treeToList(tree) { | ||
| const result = []; | ||
| function dfs(node) { | ||
| if (node.node) { | ||
| result.push(node.node); | ||
| } | ||
| for (const child of node.children) { | ||
| dfs(child); | ||
| } | ||
| } | ||
| dfs(tree); | ||
| return result; | ||
| } | ||
| function traverseTree(tree, onNode) { | ||
| function dfs(node) { | ||
| if (node.node) { | ||
| node.node = onNode(node.node); | ||
| } | ||
| for (const child of node.children) { | ||
| dfs(child); | ||
| } | ||
| } | ||
| dfs(tree); | ||
| return tree; | ||
| } | ||
| // src/constants/index.ts | ||
| var CONTAINER_MINI_HEIGHT = 3; | ||
| var CONTAINER_MINI_WIDTH = 3; | ||
| // src/extractor/dom-util.ts | ||
| function isFormElement(node) { | ||
| return node instanceof HTMLElement && (node.tagName.toLowerCase() === "input" || node.tagName.toLowerCase() === "textarea" || node.tagName.toLowerCase() === "select" || node.tagName.toLowerCase() === "option"); | ||
| } | ||
| function isButtonElement(node) { | ||
| return node instanceof HTMLElement && node.tagName.toLowerCase() === "button"; | ||
| } | ||
| function isImgElement(node) { | ||
| if (!includeBaseElement(node) && node instanceof Element) { | ||
| const computedStyle = window.getComputedStyle(node); | ||
| const backgroundImage = computedStyle.getPropertyValue("background-image"); | ||
| if (backgroundImage !== "none") { | ||
| return true; | ||
| } | ||
| } | ||
| if (isIconfont(node)) { | ||
| return true; | ||
| } | ||
| return node instanceof HTMLElement && node.tagName.toLowerCase() === "img" || node instanceof SVGElement && node.tagName.toLowerCase() === "svg"; | ||
| } | ||
| function isIconfont(node) { | ||
| if (node instanceof Element) { | ||
| const computedStyle = window.getComputedStyle(node); | ||
| const fontFamilyValue = computedStyle.fontFamily || ""; | ||
| return fontFamilyValue.toLowerCase().indexOf("iconfont") >= 0; | ||
| } | ||
| return false; | ||
| } | ||
| function isTextElement(node) { | ||
| return node.nodeName.toLowerCase() === "#text" && !isIconfont(node); | ||
| } | ||
| function isContainerElement(node) { | ||
| if (!(node instanceof HTMLElement)) | ||
| return false; | ||
| if (includeBaseElement(node)) { | ||
| return false; | ||
| } | ||
| const computedStyle = window.getComputedStyle(node); | ||
| const backgroundColor = computedStyle.getPropertyValue("background-color"); | ||
| if (backgroundColor) { | ||
| return true; | ||
| } | ||
| return false; | ||
| } | ||
| function includeBaseElement(node) { | ||
| if (!(node instanceof HTMLElement)) | ||
| return false; | ||
| if (node.innerText) { | ||
| return true; | ||
| } | ||
| const includeList = [ | ||
| "svg", | ||
| "button", | ||
| "input", | ||
| "textarea", | ||
| "select", | ||
| "option", | ||
| "img" | ||
| ]; | ||
| for (const tagName of includeList) { | ||
| const element = node.querySelectorAll(tagName); | ||
| if (element.length > 0) { | ||
| return true; | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
| // src/utils.ts | ||
| var import_js_sha256 = __toESM(require_sha256()); | ||
| var hashMap = {}; | ||
| function generateHashId(rect, content = "") { | ||
| const combined = JSON.stringify({ | ||
| content, | ||
| rect | ||
| }); | ||
| let sliceLength = 5; | ||
| let slicedHash = ""; | ||
| const hashHex = import_js_sha256.sha256.create().update(combined).hex(); | ||
| const toLetters = (hex) => { | ||
| return hex.split("").map((char) => { | ||
| const code = Number.parseInt(char, 16); | ||
| return String.fromCharCode(97 + code % 26); | ||
| }).join(""); | ||
| }; | ||
| const hashLetters = toLetters(hashHex); | ||
| while (sliceLength < hashLetters.length - 1) { | ||
| slicedHash = hashLetters.slice(0, sliceLength); | ||
| if (hashMap[slicedHash] && hashMap[slicedHash] !== combined) { | ||
| sliceLength++; | ||
| continue; | ||
| } | ||
| hashMap[slicedHash] = combined; | ||
| break; | ||
| } | ||
| return slicedHash; | ||
| } | ||
| // src/extractor/util.ts | ||
| var MAX_VALUE_LENGTH = 300; | ||
| var debugMode = false; | ||
| function setDebugMode(mode) { | ||
| debugMode = mode; | ||
| } | ||
| function getDebugMode() { | ||
| return debugMode; | ||
| } | ||
| function logger(..._msg) { | ||
| if (!debugMode) { | ||
| return; | ||
| } | ||
| console.log(..._msg); | ||
| } | ||
| var taskIdKey = "_midscene_retrieve_task_id"; | ||
| function selectorForValue(val) { | ||
| return `[${taskIdKey}='${val}']`; | ||
| } | ||
| function setDataForNode(node, nodeHash, setToParentNode, currentWindow) { | ||
| const taskId = taskIdKey; | ||
| if (!(node instanceof currentWindow.HTMLElement)) { | ||
| return ""; | ||
| } | ||
| if (!taskId) { | ||
| console.error("No task id found"); | ||
| return ""; | ||
| } | ||
| const selector = selectorForValue(nodeHash); | ||
| if (getDebugMode()) { | ||
| if (setToParentNode) { | ||
| if (node.parentNode instanceof currentWindow.HTMLElement) { | ||
| node.parentNode.setAttribute(taskIdKey, nodeHash.toString()); | ||
| } | ||
| } else { | ||
| node.setAttribute(taskIdKey, nodeHash.toString()); | ||
| } | ||
| } | ||
| return selector; | ||
| } | ||
| function isElementPartiallyInViewport(rect, currentWindow, currentDocument) { | ||
| const elementHeight = rect.height; | ||
| const elementWidth = rect.width; | ||
| const viewportRect = { | ||
| left: 0, | ||
| top: 0, | ||
| width: currentWindow.innerWidth || currentDocument.documentElement.clientWidth, | ||
| height: currentWindow.innerHeight || currentDocument.documentElement.clientHeight, | ||
| right: currentWindow.innerWidth || currentDocument.documentElement.clientWidth, | ||
| bottom: currentWindow.innerHeight || currentDocument.documentElement.clientHeight, | ||
| x: 0, | ||
| y: 0, | ||
| zoom: 1 | ||
| }; | ||
| const overlapRect = overlappedRect(rect, viewportRect); | ||
| if (!overlapRect) { | ||
| return false; | ||
| } | ||
| const visibleArea = overlapRect.width * overlapRect.height; | ||
| const totalArea = elementHeight * elementWidth; | ||
| return visibleArea / totalArea >= 2 / 3; | ||
| } | ||
| function getPseudoElementContent(element, currentWindow) { | ||
| if (!(element instanceof currentWindow.HTMLElement)) { | ||
| return { before: "", after: "" }; | ||
| } | ||
| const beforeContent = currentWindow.getComputedStyle(element, "::before").getPropertyValue("content"); | ||
| const afterContent = currentWindow.getComputedStyle(element, "::after").getPropertyValue("content"); | ||
| return { | ||
| before: beforeContent === "none" ? "" : beforeContent.replace(/"/g, ""), | ||
| after: afterContent === "none" ? "" : afterContent.replace(/"/g, "") | ||
| }; | ||
| } | ||
| function overlappedRect(rect1, rect2) { | ||
| const left = Math.max(rect1.left, rect2.left); | ||
| const top = Math.max(rect1.top, rect2.top); | ||
| const right = Math.min(rect1.right, rect2.right); | ||
| const bottom = Math.min(rect1.bottom, rect2.bottom); | ||
| if (left < right && top < bottom) { | ||
| return { | ||
| left, | ||
| top, | ||
| right, | ||
| bottom, | ||
| width: right - left, | ||
| height: bottom - top, | ||
| x: left, | ||
| y: top, | ||
| zoom: 1 | ||
| }; | ||
| } | ||
| return null; | ||
| } | ||
| function getRect(el, baseZoom, currentWindow) { | ||
| let originalRect; | ||
| let newZoom = 1; | ||
| if (!(el instanceof currentWindow.HTMLElement)) { | ||
| const range = currentWindow.document.createRange(); | ||
| range.selectNodeContents(el); | ||
| originalRect = range.getBoundingClientRect(); | ||
| } else { | ||
| originalRect = el.getBoundingClientRect(); | ||
| if (!("currentCSSZoom" in el)) { | ||
| newZoom = Number.parseFloat(currentWindow.getComputedStyle(el).zoom) || 1; | ||
| } | ||
| } | ||
| const zoom = newZoom * baseZoom; | ||
| return { | ||
| width: originalRect.width * zoom, | ||
| height: originalRect.height * zoom, | ||
| left: originalRect.left * zoom, | ||
| top: originalRect.top * zoom, | ||
| right: originalRect.right * zoom, | ||
| bottom: originalRect.bottom * zoom, | ||
| x: originalRect.x * zoom, | ||
| y: originalRect.y * zoom, | ||
| zoom | ||
| }; | ||
| } | ||
| var isElementCovered = (el, rect, currentWindow) => { | ||
| const x = rect.left + rect.width / 2; | ||
| const y = rect.top + rect.height / 2; | ||
| const topElement = currentWindow.document.elementFromPoint(x, y); | ||
| if (!topElement) { | ||
| return false; | ||
| } | ||
| if (topElement === el) { | ||
| return false; | ||
| } | ||
| if (el == null ? void 0 : el.contains(topElement)) { | ||
| return false; | ||
| } | ||
| if (topElement == null ? void 0 : topElement.contains(el)) { | ||
| return false; | ||
| } | ||
| const rectOfTopElement = getRect(topElement, 1, currentWindow); | ||
| const overlapRect = overlappedRect(rect, rectOfTopElement); | ||
| if (!overlapRect) { | ||
| return false; | ||
| } | ||
| logger(el, "Element is covered by another element", { | ||
| topElement, | ||
| el, | ||
| rect, | ||
| x, | ||
| y | ||
| }); | ||
| return true; | ||
| }; | ||
| function visibleRect(el, currentWindow, currentDocument, baseZoom = 1) { | ||
| if (!el) { | ||
| logger(el, "Element is not in the DOM hierarchy"); | ||
| return false; | ||
| } | ||
| if (!(el instanceof currentWindow.HTMLElement) && el.nodeType !== Node.TEXT_NODE && el.nodeName.toLowerCase() !== "svg") { | ||
| logger(el, "Element is not in the DOM hierarchy"); | ||
| return false; | ||
| } | ||
| if (el instanceof currentWindow.HTMLElement) { | ||
| const style = currentWindow.getComputedStyle(el); | ||
| if (style.display === "none" || style.visibility === "hidden" || style.opacity === "0" && el.tagName !== "INPUT") { | ||
| logger(el, "Element is hidden"); | ||
| return false; | ||
| } | ||
| } | ||
| const rect = getRect(el, baseZoom, currentWindow); | ||
| if (rect.width === 0 && rect.height === 0) { | ||
| logger(el, "Element has no size"); | ||
| return false; | ||
| } | ||
| if (baseZoom === 1 && isElementCovered(el, rect, currentWindow)) { | ||
| return false; | ||
| } | ||
| const scrollLeft = currentWindow.pageXOffset || currentDocument.documentElement.scrollLeft; | ||
| const scrollTop = currentWindow.pageYOffset || currentDocument.documentElement.scrollTop; | ||
| const viewportWidth = currentWindow.innerWidth || currentDocument.documentElement.clientWidth; | ||
| const viewportHeight = currentWindow.innerHeight || currentDocument.documentElement.clientHeight; | ||
| const isPartiallyInViewport = isElementPartiallyInViewport( | ||
| rect, | ||
| currentWindow, | ||
| currentDocument | ||
| ); | ||
| if (!isPartiallyInViewport) { | ||
| logger(el, "Element is completely outside the viewport", { | ||
| rect, | ||
| viewportHeight, | ||
| viewportWidth, | ||
| scrollTop, | ||
| scrollLeft | ||
| }); | ||
| return false; | ||
| } | ||
| let parent = el; | ||
| const parentUntilNonStatic = (currentNode) => { | ||
| let parent2 = currentNode == null ? void 0 : currentNode.parentElement; | ||
| while (parent2) { | ||
| const style = currentWindow.getComputedStyle(parent2); | ||
| if (style.position !== "static") { | ||
| return parent2; | ||
| } | ||
| parent2 = parent2.parentElement; | ||
| } | ||
| return null; | ||
| }; | ||
| while (parent && parent !== currentDocument.body) { | ||
| if (!(parent instanceof currentWindow.HTMLElement)) { | ||
| parent = parent.parentElement; | ||
| continue; | ||
| } | ||
| const parentStyle = currentWindow.getComputedStyle(parent); | ||
| if (parentStyle.overflow === "hidden") { | ||
| const parentRect = getRect(parent, 1, currentWindow); | ||
| const tolerance = 10; | ||
| if (rect.right < parentRect.left - tolerance || rect.left > parentRect.right + tolerance || rect.bottom < parentRect.top - tolerance || rect.top > parentRect.bottom + tolerance) { | ||
| logger(el, "element is partially or totally hidden by an ancestor", { | ||
| rect, | ||
| parentRect | ||
| }); | ||
| return false; | ||
| } | ||
| } | ||
| if (parentStyle.position === "fixed" || parentStyle.position === "sticky") { | ||
| break; | ||
| } | ||
| if (parentStyle.position === "absolute") { | ||
| parent = parentUntilNonStatic(parent); | ||
| } else { | ||
| parent = parent.parentElement; | ||
| } | ||
| } | ||
| return { | ||
| left: Math.round(rect.left), | ||
| top: Math.round(rect.top), | ||
| width: Math.round(rect.width), | ||
| height: Math.round(rect.height), | ||
| zoom: rect.zoom | ||
| }; | ||
| } | ||
| function getNodeAttributes(node, currentWindow) { | ||
| if (!node || !(node instanceof currentWindow.HTMLElement) || !node.attributes) { | ||
| return {}; | ||
| } | ||
| const attributesList = Array.from(node.attributes).map((attr) => { | ||
| if (attr.name === "class") { | ||
| return [attr.name, `.${attr.value.split(" ").join(".")}`]; | ||
| } | ||
| if (!attr.value) { | ||
| return []; | ||
| } | ||
| let value = attr.value; | ||
| if (value.startsWith("data:image")) { | ||
| value = "image"; | ||
| } | ||
| if (value.length > MAX_VALUE_LENGTH) { | ||
| value = `${value.slice(0, MAX_VALUE_LENGTH)}...`; | ||
| } | ||
| return [attr.name, value]; | ||
| }); | ||
| return Object.fromEntries(attributesList); | ||
| } | ||
| var nodeHashCacheList = []; | ||
| if (typeof window !== "undefined") { | ||
| window.midsceneNodeHashCacheList = window.midsceneNodeHashCacheList || []; | ||
| nodeHashCacheList = window.midsceneNodeHashCacheList; | ||
| } | ||
| function resetNodeHashCacheList() { | ||
| if (typeof window !== "undefined") { | ||
| nodeHashCacheList = window.midsceneNodeHashCacheList || []; | ||
| window.midsceneNodeHashCacheList = []; | ||
| } else { | ||
| nodeHashCacheList = []; | ||
| } | ||
| } | ||
| function midsceneGenerateHash(node, content, rect) { | ||
| var _a; | ||
| if (node && nodeHashCacheList.find((item) => item.node === node)) { | ||
| return ((_a = nodeHashCacheList.find((item) => item.node === node)) == null ? void 0 : _a.id) || ""; | ||
| } | ||
| const slicedHash = generateHashId(rect, content); | ||
| if (node && typeof window !== "undefined") { | ||
| window.midsceneNodeHashCacheList.push({ node, id: slicedHash }); | ||
| } | ||
| return slicedHash; | ||
| } | ||
| function getTopDocument() { | ||
| const container = document.body || document; | ||
| return container; | ||
| } | ||
| // src/extractor/web-extractor.ts | ||
| var indexId = 0; | ||
| function tagNameOfNode(node) { | ||
| let tagName = ""; | ||
| if (node instanceof HTMLElement) { | ||
| tagName = node.tagName.toLowerCase(); | ||
| } | ||
| const parentElement = node.parentElement; | ||
| if (parentElement && parentElement instanceof HTMLElement) { | ||
| tagName = parentElement.tagName.toLowerCase(); | ||
| } | ||
| return tagName ? `<${tagName}>` : ""; | ||
| } | ||
| function collectElementInfo(node, currentWindow, currentDocument, baseZoom = 1, basePoint = { left: 0, top: 0 }) { | ||
| var _a; | ||
| const rect = visibleRect(node, currentWindow, currentDocument, baseZoom); | ||
| if (!rect || rect.width < CONTAINER_MINI_WIDTH || rect.height < CONTAINER_MINI_HEIGHT) { | ||
| return null; | ||
| } | ||
| if (basePoint.left !== 0 || basePoint.top !== 0) { | ||
| rect.left += basePoint.left; | ||
| rect.top += basePoint.top; | ||
| } | ||
| if (rect.height >= window.innerHeight && rect.width >= window.innerWidth) { | ||
| return null; | ||
| } | ||
| if (isFormElement(node)) { | ||
| const attributes = getNodeAttributes(node, currentWindow); | ||
| let valueContent = attributes.value || attributes.placeholder || node.textContent || ""; | ||
| const nodeHashId = midsceneGenerateHash(node, valueContent, rect); | ||
| const selector = setDataForNode(node, nodeHashId, false, currentWindow); | ||
| const tagName = node.tagName.toLowerCase(); | ||
| if (node.tagName.toLowerCase() === "select") { | ||
| const selectedOption = node.options[node.selectedIndex]; | ||
| valueContent = selectedOption.textContent || ""; | ||
| } | ||
| if ((node.tagName.toLowerCase() === "input" || node.tagName.toLowerCase() === "textarea") && node.value) { | ||
| valueContent = node.value; | ||
| } | ||
| const elementInfo = { | ||
| id: nodeHashId, | ||
| nodeHashId, | ||
| locator: selector, | ||
| nodeType: "FORM_ITEM Node" /* FORM_ITEM */, | ||
| indexId: indexId++, | ||
| attributes: __spreadProps(__spreadValues({}, attributes), { | ||
| htmlTagName: `<${tagName}>`, | ||
| nodeType: "FORM_ITEM Node" /* FORM_ITEM */ | ||
| }), | ||
| content: valueContent.trim(), | ||
| rect, | ||
| center: [ | ||
| Math.round(rect.left + rect.width / 2), | ||
| Math.round(rect.top + rect.height / 2) | ||
| ], | ||
| zoom: rect.zoom, | ||
| screenWidth: currentWindow.innerWidth, | ||
| screenHeight: currentWindow.innerHeight | ||
| }; | ||
| return elementInfo; | ||
| } | ||
| if (isButtonElement(node)) { | ||
| const attributes = getNodeAttributes(node, currentWindow); | ||
| const pseudo = getPseudoElementContent(node, currentWindow); | ||
| const content = node.innerText || pseudo.before || pseudo.after || ""; | ||
| const nodeHashId = midsceneGenerateHash(node, content, rect); | ||
| const selector = setDataForNode(node, nodeHashId, false, currentWindow); | ||
| const elementInfo = { | ||
| id: nodeHashId, | ||
| indexId: indexId++, | ||
| nodeHashId, | ||
| nodeType: "BUTTON Node" /* BUTTON */, | ||
| locator: selector, | ||
| attributes: __spreadProps(__spreadValues({}, attributes), { | ||
| htmlTagName: tagNameOfNode(node), | ||
| nodeType: "BUTTON Node" /* BUTTON */ | ||
| }), | ||
| content, | ||
| rect, | ||
| center: [ | ||
| Math.round(rect.left + rect.width / 2), | ||
| Math.round(rect.top + rect.height / 2) | ||
| ], | ||
| zoom: rect.zoom, | ||
| screenWidth: currentWindow.innerWidth, | ||
| screenHeight: currentWindow.innerHeight | ||
| }; | ||
| return elementInfo; | ||
| } | ||
| if (isImgElement(node)) { | ||
| const attributes = getNodeAttributes(node, currentWindow); | ||
| const nodeHashId = midsceneGenerateHash(node, "", rect); | ||
| const selector = setDataForNode(node, nodeHashId, false, currentWindow); | ||
| const elementInfo = { | ||
| id: nodeHashId, | ||
| indexId: indexId++, | ||
| nodeHashId, | ||
| locator: selector, | ||
| attributes: __spreadProps(__spreadValues(__spreadValues({}, attributes), node.nodeName.toLowerCase() === "svg" ? { | ||
| svgContent: "true" | ||
| } : {}), { | ||
| nodeType: "IMG Node" /* IMG */, | ||
| htmlTagName: tagNameOfNode(node) | ||
| }), | ||
| nodeType: "IMG Node" /* IMG */, | ||
| content: "", | ||
| rect, | ||
| center: [ | ||
| Math.round(rect.left + rect.width / 2), | ||
| Math.round(rect.top + rect.height / 2) | ||
| ], | ||
| zoom: rect.zoom, | ||
| screenWidth: currentWindow.innerWidth, | ||
| screenHeight: currentWindow.innerHeight | ||
| }; | ||
| return elementInfo; | ||
| } | ||
| if (isTextElement(node)) { | ||
| const text = (_a = node.textContent) == null ? void 0 : _a.trim().replace(/\n+/g, " "); | ||
| if (!text) { | ||
| return null; | ||
| } | ||
| const attributes = getNodeAttributes(node, currentWindow); | ||
| const attributeKeys = Object.keys(attributes); | ||
| if (!text.trim() && attributeKeys.length === 0) { | ||
| return null; | ||
| } | ||
| const nodeHashId = midsceneGenerateHash(node, text, rect); | ||
| const selector = setDataForNode(node, nodeHashId, true, currentWindow); | ||
| const elementInfo = { | ||
| id: nodeHashId, | ||
| indexId: indexId++, | ||
| nodeHashId, | ||
| nodeType: "TEXT Node" /* TEXT */, | ||
| locator: selector, | ||
| attributes: __spreadProps(__spreadValues({}, attributes), { | ||
| nodeType: "TEXT Node" /* TEXT */, | ||
| htmlTagName: tagNameOfNode(node) | ||
| }), | ||
| center: [ | ||
| Math.round(rect.left + rect.width / 2), | ||
| Math.round(rect.top + rect.height / 2) | ||
| ], | ||
| // attributes, | ||
| content: text, | ||
| rect, | ||
| zoom: rect.zoom, | ||
| screenWidth: currentWindow.innerWidth, | ||
| screenHeight: currentWindow.innerHeight | ||
| }; | ||
| return elementInfo; | ||
| } | ||
| if (isContainerElement(node)) { | ||
| const attributes = getNodeAttributes(node, currentWindow); | ||
| const nodeHashId = midsceneGenerateHash(node, "", rect); | ||
| const selector = setDataForNode(node, nodeHashId, false, currentWindow); | ||
| const elementInfo = { | ||
| id: nodeHashId, | ||
| nodeHashId, | ||
| indexId: indexId++, | ||
| nodeType: "CONTAINER Node" /* CONTAINER */, | ||
| locator: selector, | ||
| attributes: __spreadProps(__spreadValues({}, attributes), { | ||
| nodeType: "CONTAINER Node" /* CONTAINER */, | ||
| htmlTagName: tagNameOfNode(node) | ||
| }), | ||
| content: "", | ||
| rect, | ||
| center: [ | ||
| Math.round(rect.left + rect.width / 2), | ||
| Math.round(rect.top + rect.height / 2) | ||
| ], | ||
| zoom: rect.zoom, | ||
| screenWidth: currentWindow.innerWidth, | ||
| screenHeight: currentWindow.innerHeight | ||
| }; | ||
| return elementInfo; | ||
| } | ||
| return null; | ||
| } | ||
| function extractTextWithPosition(initNode, debugMode2 = false) { | ||
| const elementNode = extractTreeNode(initNode, debugMode2); | ||
| const elementInfoArray = []; | ||
| function dfsTopChildren(node) { | ||
| if (node.node) { | ||
| elementInfoArray.push(node.node); | ||
| } | ||
| for (let i = 0; i < node.children.length; i++) { | ||
| dfsTopChildren(node.children[i]); | ||
| } | ||
| } | ||
| dfsTopChildren({ children: elementNode.children, node: elementNode.node }); | ||
| return elementInfoArray; | ||
| } | ||
| function extractTreeNodeAsString(initNode, debugMode2 = false) { | ||
| const elementNode = extractTreeNode(initNode, debugMode2); | ||
| return descriptionOfTree(elementNode); | ||
| } | ||
| function extractTreeNode(initNode, debugMode2 = false) { | ||
| setDebugMode(debugMode2); | ||
| resetNodeHashCacheList(); | ||
| indexId = 0; | ||
| const topDocument = getTopDocument(); | ||
| const startNode = initNode || topDocument; | ||
| const topChildren = []; | ||
| function dfs(node, currentWindow, currentDocument, baseZoom = 1, basePoint = { left: 0, top: 0 }) { | ||
| if (!node) { | ||
| return null; | ||
| } | ||
| if (node.nodeType && node.nodeType === 10) { | ||
| return null; | ||
| } | ||
| const elementInfo = collectElementInfo( | ||
| node, | ||
| currentWindow, | ||
| currentDocument, | ||
| baseZoom, | ||
| basePoint | ||
| ); | ||
| if (node instanceof currentWindow.HTMLIFrameElement) { | ||
| if (node.contentWindow && node.contentWindow) { | ||
| return null; | ||
| } | ||
| } | ||
| const nodeInfo = { | ||
| node: elementInfo, | ||
| children: [] | ||
| }; | ||
| if ((elementInfo == null ? void 0 : elementInfo.nodeType) === "BUTTON Node" /* BUTTON */ || (elementInfo == null ? void 0 : elementInfo.nodeType) === "IMG Node" /* IMG */ || (elementInfo == null ? void 0 : elementInfo.nodeType) === "TEXT Node" /* TEXT */ || (elementInfo == null ? void 0 : elementInfo.nodeType) === "FORM_ITEM Node" /* FORM_ITEM */ || (elementInfo == null ? void 0 : elementInfo.nodeType) === "CONTAINER Node" /* CONTAINER */) { | ||
| return nodeInfo; | ||
| } | ||
| const rect = getRect(node, baseZoom, currentWindow); | ||
| for (let i = 0; i < node.childNodes.length; i++) { | ||
| logger("will dfs", node.childNodes[i]); | ||
| const childNodeInfo = dfs( | ||
| node.childNodes[i], | ||
| currentWindow, | ||
| currentDocument, | ||
| rect.zoom, | ||
| basePoint | ||
| ); | ||
| if (childNodeInfo) { | ||
| nodeInfo.children.push(childNodeInfo); | ||
| } | ||
| } | ||
| return nodeInfo; | ||
| } | ||
| const rootNodeInfo = dfs(startNode, window, document, 1, { | ||
| left: 0, | ||
| top: 0 | ||
| }); | ||
| if (rootNodeInfo) { | ||
| topChildren.push(rootNodeInfo); | ||
| } | ||
| if (startNode === topDocument) { | ||
| const iframes = document.querySelectorAll("iframe"); | ||
| for (let i = 0; i < iframes.length; i++) { | ||
| const iframe = iframes[i]; | ||
| if (iframe.contentDocument && iframe.contentWindow) { | ||
| const iframeInfo = collectElementInfo(iframe, window, document, 1); | ||
| if (iframeInfo) { | ||
| const iframeChildren = dfs( | ||
| iframe.contentDocument.body, | ||
| iframe.contentWindow, | ||
| iframe.contentDocument, | ||
| 1, | ||
| { | ||
| left: iframeInfo.rect.left, | ||
| top: iframeInfo.rect.top | ||
| } | ||
| ); | ||
| if (iframeChildren) { | ||
| topChildren.push(iframeChildren); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| return { | ||
| node: null, | ||
| children: topChildren | ||
| }; | ||
| } | ||
| // src/extractor/client-extractor.ts | ||
| function getNodeAttributes2(node) { | ||
| var _a; | ||
| const attrs = {}; | ||
| if (node && node.nodeType === 1) { | ||
| const element = node; | ||
| for (let i = 0; i < element.attributes.length; i++) { | ||
| const attr = element.attributes[i]; | ||
| attrs[attr.nodeName] = (_a = attr.nodeValue) != null ? _a : ""; | ||
| } | ||
| } | ||
| return attrs; | ||
| } | ||
| function getRect2(attributes) { | ||
| var _a, _b, _c, _d; | ||
| const x = Math.round(Number.parseFloat((_a = attributes.x) != null ? _a : "0")); | ||
| const y = Math.round(Number.parseFloat((_b = attributes.y) != null ? _b : "0")); | ||
| const width = Math.round(Number.parseFloat((_c = attributes.width) != null ? _c : "0")); | ||
| const height = Math.round(Number.parseFloat((_d = attributes.height) != null ? _d : "0")); | ||
| return { | ||
| left: Math.max(0, Math.floor(x)), | ||
| top: Math.max(0, Math.floor(y)), | ||
| width: Math.max(0, width), | ||
| height: Math.max(0, height) | ||
| }; | ||
| } | ||
| function validTextNodeContent(node) { | ||
| var _a; | ||
| if (node.nodeType === 3) { | ||
| return ((_a = node.nodeValue) == null ? void 0 : _a.trim()) || ""; | ||
| } | ||
| return ""; | ||
| } | ||
| function getXPathForElement(element) { | ||
| if (element.nodeType !== 1) { | ||
| return ""; | ||
| } | ||
| const getIndex = (sib, name) => { | ||
| let count = 1; | ||
| for (let cur = sib.previousSibling; cur; cur = cur.previousSibling) { | ||
| if (cur.nodeType === 1 && cur.nodeName === name) { | ||
| count++; | ||
| } | ||
| } | ||
| return count; | ||
| }; | ||
| const buildAttributePart = (elem) => { | ||
| const attributes = ["id", "resource-id", "content-desc", "class"]; | ||
| for (const attr of attributes) { | ||
| if (elem.hasAttribute(attr)) { | ||
| const value = elem.getAttribute(attr); | ||
| if (value && value.trim() !== "") { | ||
| return `[@${attr}="${value}"]`; | ||
| } | ||
| } | ||
| } | ||
| return ""; | ||
| }; | ||
| const getPath = (node, path = "") => { | ||
| if (node.parentNode) { | ||
| path = getPath(node.parentNode, path); | ||
| } | ||
| if (node.nodeType === 1) { | ||
| const elem = node; | ||
| const tagName = elem.nodeName.toLowerCase(); | ||
| let part = `/${tagName}`; | ||
| const attributePart = buildAttributePart(elem); | ||
| if (attributePart) { | ||
| part += attributePart; | ||
| } else { | ||
| const index = getIndex(node, node.nodeName); | ||
| if (index > 1) { | ||
| part += `[${index}]`; | ||
| } | ||
| } | ||
| path += part; | ||
| } | ||
| return path; | ||
| }; | ||
| return getPath(element); | ||
| } | ||
| function extractTextWithPosition2(initNode) { | ||
| const elementInfoArray = []; | ||
| let nodeIndex = 1; | ||
| function dfs(node, parentNode = null) { | ||
| if (!node) { | ||
| return; | ||
| } | ||
| const currentNodeDes = { node, children: [] }; | ||
| if (parentNode) { | ||
| parentNode.children.push(currentNodeDes); | ||
| } | ||
| collectElementInfo2(node); | ||
| if (node.childNodes && node.childNodes.length > 0) { | ||
| for (let i = 0; i < node.childNodes.length; i++) { | ||
| dfs(node.childNodes[i], currentNodeDes); | ||
| } | ||
| } | ||
| } | ||
| function collectElementInfo2(node) { | ||
| const attributes = getNodeAttributes2(node); | ||
| const rect = getRect2(attributes); | ||
| const nodeHashId = midsceneGenerateHash(null, attributes.placeholder, rect); | ||
| const text = validTextNodeContent(node); | ||
| let nodeType; | ||
| switch (node.nodeName.toUpperCase()) { | ||
| case "TEXT": | ||
| nodeType = "TEXT Node" /* TEXT */; | ||
| break; | ||
| case "IMAGE": | ||
| nodeType = "IMG Node" /* IMG */; | ||
| break; | ||
| case "BUTTON": | ||
| nodeType = "BUTTON Node" /* BUTTON */; | ||
| break; | ||
| case "SEARCHINPUT": | ||
| case "TEXTINPUT": | ||
| case "INPUT": | ||
| nodeType = "FORM_ITEM Node" /* FORM_ITEM */; | ||
| break; | ||
| case "NAV": | ||
| case "LIST": | ||
| case "CELL": | ||
| nodeType = "CONTAINER Node" /* CONTAINER */; | ||
| break; | ||
| default: | ||
| if (attributes.id === "android:id/input" || attributes.id === "android:id/inputArea") { | ||
| nodeType = "FORM_ITEM Node" /* FORM_ITEM */; | ||
| } else { | ||
| nodeType = "CONTAINER Node" /* CONTAINER */; | ||
| } | ||
| break; | ||
| } | ||
| const xpath = getXPathForElement(node); | ||
| const elementInfo = { | ||
| id: nodeHashId, | ||
| indexId: nodeIndex++, | ||
| nodeHashId, | ||
| locator: xpath, | ||
| attributes: __spreadValues({ | ||
| nodeType | ||
| }, attributes), | ||
| content: text, | ||
| rect, | ||
| center: [ | ||
| Math.round(rect.left + rect.width / 2), | ||
| Math.round(rect.top + rect.height / 2) | ||
| ], | ||
| nodeType | ||
| }; | ||
| if (elementInfo.nodeType !== "CONTAINER Node" /* CONTAINER */) { | ||
| elementInfoArray.push(elementInfo); | ||
| } | ||
| } | ||
| const rootNode = initNode; | ||
| const rootDescriptor = { node: rootNode, children: [] }; | ||
| dfs(rootNode, rootDescriptor); | ||
| return elementInfoArray; | ||
| } | ||
| /*! Bundled license information: | ||
| js-sha256/src/sha256.js: | ||
| (** | ||
| * [js-sha256]{@link https://github.com/emn178/js-sha256} | ||
| * | ||
| * @version 0.11.0 | ||
| * @author Chen, Yi-Cyuan [emn178@gmail.com] | ||
| * @copyright Chen, Yi-Cyuan 2014-2024 | ||
| * @license MIT | ||
| *) | ||
| */ |
| interface PkgInfo { | ||
| name: string; | ||
| version: string; | ||
| dir: string; | ||
| } | ||
| declare function getRunningPkgInfo(dir?: string): PkgInfo | null; | ||
| /** | ||
| * Find the nearest package.json file recursively | ||
| * @param {string} dir - Home directory | ||
| * @returns {string|null} - The most recent package.json file path or null | ||
| */ | ||
| declare function findNearestPackageJson(dir: string): string | null; | ||
| export { findNearestPackageJson, getRunningPkgInfo }; |
| "use strict"; | ||
| var __defProp = Object.defineProperty; | ||
| var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
| var __getOwnPropNames = Object.getOwnPropertyNames; | ||
| var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
| var __export = (target, all) => { | ||
| for (var name in all) | ||
| __defProp(target, name, { get: all[name], enumerable: true }); | ||
| }; | ||
| var __copyProps = (to, from, except, desc) => { | ||
| if (from && typeof from === "object" || typeof from === "function") { | ||
| for (let key of __getOwnPropNames(from)) | ||
| if (!__hasOwnProp.call(to, key) && key !== except) | ||
| __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); | ||
| } | ||
| return to; | ||
| }; | ||
| var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); | ||
| // src/fs/index.ts | ||
| var fs_exports = {}; | ||
| __export(fs_exports, { | ||
| findNearestPackageJson: () => findNearestPackageJson, | ||
| getRunningPkgInfo: () => getRunningPkgInfo | ||
| }); | ||
| module.exports = __toCommonJS(fs_exports); | ||
| var import_node_fs = require("fs"); | ||
| var import_node_path = require("path"); | ||
| var pkgCacheMap = {}; | ||
| var ifInBrowser = typeof window !== "undefined"; | ||
| function getRunningPkgInfo(dir) { | ||
| if (ifInBrowser) { | ||
| return null; | ||
| } | ||
| const dirToCheck = dir || process.cwd(); | ||
| if (pkgCacheMap[dirToCheck]) { | ||
| return pkgCacheMap[dirToCheck]; | ||
| } | ||
| const pkgDir = findNearestPackageJson(dirToCheck); | ||
| const pkgJsonFile = pkgDir ? (0, import_node_path.join)(pkgDir, "package.json") : null; | ||
| if (pkgDir && pkgJsonFile) { | ||
| const { name, version } = JSON.parse((0, import_node_fs.readFileSync)(pkgJsonFile, "utf-8")); | ||
| pkgCacheMap[dirToCheck] = { | ||
| name: name || "midscene-unknown-package-name", | ||
| version: version || "0.0.0", | ||
| dir: pkgDir | ||
| }; | ||
| return pkgCacheMap[dirToCheck]; | ||
| } | ||
| return { | ||
| name: "midscene-unknown-package-name", | ||
| version: "0.0.0", | ||
| dir: dirToCheck | ||
| }; | ||
| } | ||
| function findNearestPackageJson(dir) { | ||
| const packageJsonPath = (0, import_node_path.join)(dir, "package.json"); | ||
| if ((0, import_node_fs.existsSync)(packageJsonPath)) { | ||
| return dir; | ||
| } | ||
| const parentDir = (0, import_node_path.dirname)(dir); | ||
| if (parentDir === dir) { | ||
| return null; | ||
| } | ||
| return findNearestPackageJson(parentDir); | ||
| } |
| import { Buffer } from 'node:buffer'; | ||
| import Jimp from 'jimp'; | ||
| import { NodeType } from './constants.js'; | ||
| import { R as Rect } from './index-305e7a7e.js'; | ||
| interface Size { | ||
| width: number; | ||
| height: number; | ||
| dpr?: number; | ||
| } | ||
| interface ImageInfo extends Size { | ||
| jimpImage: Jimp; | ||
| } | ||
| /** | ||
| * Retrieves the dimensions of an image asynchronously | ||
| * | ||
| * @param image - The image data, which can be a string path or a buffer | ||
| * @returns A Promise that resolves to an object containing the width and height of the image | ||
| * @throws Error if the image data is invalid | ||
| */ | ||
| declare function imageInfo(image: string | Buffer | Jimp): Promise<ImageInfo>; | ||
| /** | ||
| * Retrieves the dimensions of an image from a base64-encoded string | ||
| * | ||
| * @param imageBase64 - The base64-encoded image data | ||
| * @returns A Promise that resolves to an object containing the width and height of the image | ||
| * @throws Error if the image data is invalid | ||
| */ | ||
| declare function imageInfoOfBase64(imageBase64: string): Promise<ImageInfo>; | ||
| declare function bufferFromBase64(imageBase64: string): Promise<Buffer>; | ||
| /** | ||
| * Encodes an image file to a base64 encoded string | ||
| * | ||
| * @param image The path of the image file | ||
| * @param withHeader Determine whether to return data including the file header information, the default is true | ||
| * | ||
| * @returns The base64 encoded string of the image file, which may or may not include header information depending on the withHeader parameter | ||
| * | ||
| * @throws When the image type is not supported, an error will be thrown | ||
| */ | ||
| declare function base64Encoded(image: string, withHeader?: boolean): string; | ||
| /** | ||
| /** | ||
| * Saves a Base64-encoded image to a file | ||
| * | ||
| * @param options - An object containing the Base64-encoded image data and the output file path | ||
| * @param options.base64Data - The Base64-encoded image data | ||
| * @param options.outputPath - The path where the image will be saved | ||
| * @throws Error if there is an error during the saving process | ||
| */ | ||
| declare function saveBase64Image(options: { | ||
| base64Data: string; | ||
| outputPath: string; | ||
| }): Promise<void>; | ||
| /** | ||
| * Transforms an image path into a base64-encoded string | ||
| * @param inputPath - The path of the image file to be encoded | ||
| * @returns A Promise that resolves to a base64-encoded string representing the image file | ||
| */ | ||
| declare function transformImgPathToBase64(inputPath: string): Promise<string>; | ||
| /** | ||
| * Resizes an image from a base64-encoded string | ||
| * | ||
| * @param base64Data - A base64-encoded string representing the image | ||
| * @returns A Promise that resolves to a base64-encoded string representing the resized image | ||
| * @throws An error if the width or height cannot be determined from the metadata | ||
| */ | ||
| declare function resizeImg(inputData: Buffer, newSize: { | ||
| width: number; | ||
| height: number; | ||
| }): Promise<Buffer>; | ||
| declare function resizeImgBase64(inputBase64: string, newSize: { | ||
| width: number; | ||
| height: number; | ||
| }): Promise<string>; | ||
| /** | ||
| * Calculates new dimensions for an image while maintaining its aspect ratio. | ||
| * | ||
| * This function is designed to resize an image to fit within a specified maximum width and height | ||
| * while maintaining the original aspect ratio. If the original width or height exceeds the maximum | ||
| * dimensions, the image will be scaled down to fit. | ||
| * | ||
| * @param {number} originalWidth - The original width of the image. | ||
| * @param {number} originalHeight - The original height of the image. | ||
| * @returns {Object} An object containing the new width and height. | ||
| * @throws {Error} Throws an error if the width or height is not a positive number. | ||
| */ | ||
| declare function zoomForGPT4o(originalWidth: number, originalHeight: number): { | ||
| width: number; | ||
| height: number; | ||
| }; | ||
| /** | ||
| * Trims an image and returns the trimming information, including the offset from the left and top edges, and the trimmed width and height | ||
| * | ||
| * @param image - The image to be trimmed. This can be a file path or a Buffer object containing the image data | ||
| * @returns A Promise that resolves to an object containing the trimming information. If the image does not need to be trimmed, this object will be null | ||
| */ | ||
| declare function trimImage(image: string | Buffer): Promise<{ | ||
| trimOffsetLeft: number; | ||
| trimOffsetTop: number; | ||
| width: number; | ||
| height: number; | ||
| } | null>; | ||
| declare function paddingToMatchBlock(imageBase64: string, blockSize?: number): Promise<string>; | ||
| type ElementType = { | ||
| locator?: string; | ||
| rect: Rect; | ||
| center?: [number, number]; | ||
| id?: string; | ||
| indexId: number; | ||
| attributes?: { | ||
| nodeType: NodeType; | ||
| [key: string]: string; | ||
| }; | ||
| }; | ||
| declare const compositeElementInfoImg: (options: { | ||
| inputImgBase64: string; | ||
| elementsPositionInfo: Array<ElementType>; | ||
| size?: { | ||
| width: number; | ||
| height: number; | ||
| }; | ||
| annotationPadding?: number; | ||
| }) => Promise<string>; | ||
| declare const processImageElementInfo: (options: { | ||
| inputImgBase64: string; | ||
| elementsPositionInfo: Array<ElementType>; | ||
| elementsPositionInfoWithoutText: Array<ElementType>; | ||
| }) => Promise<{ | ||
| compositeElementInfoImgBase64: string; | ||
| compositeElementInfoImgWithoutTextBase64: string; | ||
| }>; | ||
| declare function drawBoxOnImage(options: { | ||
| inputImgBase64: string; | ||
| rect: { | ||
| x: number; | ||
| y: number; | ||
| }; | ||
| }): Promise<string>; | ||
| declare function savePositionImg(options: { | ||
| inputImgBase64: string; | ||
| rect: { | ||
| x: number; | ||
| y: number; | ||
| }; | ||
| outputPath: string; | ||
| }): Promise<void>; | ||
| export { base64Encoded, bufferFromBase64, compositeElementInfoImg, drawBoxOnImage, imageInfo, imageInfoOfBase64, paddingToMatchBlock, processImageElementInfo, resizeImg, resizeImgBase64, saveBase64Image, savePositionImg, transformImgPathToBase64, trimImage, zoomForGPT4o }; |
| "use strict"; | ||
| var __create = Object.create; | ||
| var __defProp = Object.defineProperty; | ||
| var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
| var __getOwnPropNames = Object.getOwnPropertyNames; | ||
| var __getProtoOf = Object.getPrototypeOf; | ||
| var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
| var __pow = Math.pow; | ||
| var __export = (target, all) => { | ||
| for (var name in all) | ||
| __defProp(target, name, { get: all[name], enumerable: true }); | ||
| }; | ||
| var __copyProps = (to, from, except, desc) => { | ||
| if (from && typeof from === "object" || typeof from === "function") { | ||
| for (let key of __getOwnPropNames(from)) | ||
| if (!__hasOwnProp.call(to, key) && key !== except) | ||
| __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); | ||
| } | ||
| return to; | ||
| }; | ||
| var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( | ||
| // If the importer is in node compatibility mode or this is not an ESM | ||
| // file that has been converted to a CommonJS file using a Babel- | ||
| // compatible transform (i.e. "__esModule" has not been set), then set | ||
| // "default" to the CommonJS "module.exports" for node compatibility. | ||
| isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, | ||
| mod | ||
| )); | ||
| var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); | ||
| var __async = (__this, __arguments, generator) => { | ||
| return new Promise((resolve, reject) => { | ||
| var fulfilled = (value) => { | ||
| try { | ||
| step(generator.next(value)); | ||
| } catch (e) { | ||
| reject(e); | ||
| } | ||
| }; | ||
| var rejected = (value) => { | ||
| try { | ||
| step(generator.throw(value)); | ||
| } catch (e) { | ||
| reject(e); | ||
| } | ||
| }; | ||
| var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected); | ||
| step((generator = generator.apply(__this, __arguments)).next()); | ||
| }); | ||
| }; | ||
| // src/img/index.ts | ||
| var img_exports = {}; | ||
| __export(img_exports, { | ||
| base64Encoded: () => base64Encoded, | ||
| bufferFromBase64: () => bufferFromBase64, | ||
| compositeElementInfoImg: () => compositeElementInfoImg, | ||
| drawBoxOnImage: () => drawBoxOnImage, | ||
| imageInfo: () => imageInfo, | ||
| imageInfoOfBase64: () => imageInfoOfBase64, | ||
| paddingToMatchBlock: () => paddingToMatchBlock, | ||
| processImageElementInfo: () => processImageElementInfo, | ||
| resizeImg: () => resizeImg, | ||
| resizeImgBase64: () => resizeImgBase64, | ||
| saveBase64Image: () => saveBase64Image, | ||
| savePositionImg: () => savePositionImg, | ||
| transformImgPathToBase64: () => transformImgPathToBase64, | ||
| trimImage: () => trimImage, | ||
| zoomForGPT4o: () => zoomForGPT4o | ||
| }); | ||
| module.exports = __toCommonJS(img_exports); | ||
| // src/img/info.ts | ||
| var import_node_assert = __toESM(require("assert")); | ||
| var import_node_buffer = require("buffer"); | ||
| var import_node_fs = require("fs"); | ||
| // src/img/get-jimp.ts | ||
| var ifInBrowser = typeof window !== "undefined"; | ||
| function getJimp() { | ||
| return __async(this, null, function* () { | ||
| if (ifInBrowser) { | ||
| yield import("jimp/browser/lib/jimp.js"); | ||
| return window.Jimp; | ||
| } | ||
| return (yield import("jimp")).default; | ||
| }); | ||
| } | ||
| // src/img/info.ts | ||
| function imageInfo(image) { | ||
| return __async(this, null, function* () { | ||
| const Jimp = yield getJimp(); | ||
| let jimpImage; | ||
| if (typeof image === "string") { | ||
| jimpImage = yield Jimp.read(image); | ||
| } else if (import_node_buffer.Buffer.isBuffer(image)) { | ||
| jimpImage = yield Jimp.read(image); | ||
| } else if (image instanceof Jimp) { | ||
| jimpImage = image; | ||
| } else { | ||
| throw new Error("Invalid image input: must be a string path or a Buffer"); | ||
| } | ||
| const { width, height } = jimpImage.bitmap; | ||
| (0, import_node_assert.default)( | ||
| width && height, | ||
| `Invalid image: ${typeof image === "string" ? image : "Buffer"}` | ||
| ); | ||
| return { width, height, jimpImage }; | ||
| }); | ||
| } | ||
| function imageInfoOfBase64(imageBase64) { | ||
| return __async(this, null, function* () { | ||
| const buffer = yield bufferFromBase64(imageBase64); | ||
| return imageInfo(buffer); | ||
| }); | ||
| } | ||
| function bufferFromBase64(imageBase64) { | ||
| return __async(this, null, function* () { | ||
| const base64Data = imageBase64.replace(/^data:image\/\w+;base64,/, ""); | ||
| return import_node_buffer.Buffer.from(base64Data, "base64"); | ||
| }); | ||
| } | ||
| function base64Encoded(image, withHeader = true) { | ||
| const imageBuffer = (0, import_node_fs.readFileSync)(image); | ||
| if (!withHeader) { | ||
| return imageBuffer.toString("base64"); | ||
| } | ||
| if (image.endsWith("png")) { | ||
| return `data:image/png;base64,${imageBuffer.toString("base64")}`; | ||
| } | ||
| if (image.endsWith("jpg") || image.endsWith("jpeg")) { | ||
| return `data:image/jpeg;base64,${imageBuffer.toString("base64")}`; | ||
| } | ||
| throw new Error("unsupported image type"); | ||
| } | ||
| // src/img/transform.ts | ||
| var import_node_assert2 = __toESM(require("assert")); | ||
| var import_node_buffer2 = require("buffer"); | ||
| function saveBase64Image(options) { | ||
| return __async(this, null, function* () { | ||
| const { base64Data, outputPath } = options; | ||
| const base64Image = base64Data.split(";base64,").pop() || base64Data; | ||
| const imageBuffer = import_node_buffer2.Buffer.from(base64Image, "base64"); | ||
| const Jimp = yield getJimp(); | ||
| const image = yield Jimp.read(imageBuffer); | ||
| yield image.writeAsync(outputPath); | ||
| }); | ||
| } | ||
| function transformImgPathToBase64(inputPath) { | ||
| return __async(this, null, function* () { | ||
| const Jimp = yield getJimp(); | ||
| const image = yield Jimp.read(inputPath); | ||
| const buffer = yield image.getBufferAsync(Jimp.MIME_JPEG); | ||
| return buffer.toString("base64"); | ||
| }); | ||
| } | ||
| function resizeImg(inputData, newSize) { | ||
| return __async(this, null, function* () { | ||
| if (typeof inputData === "string") | ||
| throw Error("inputData is base64, use resizeImgBase64 instead"); | ||
| (0, import_node_assert2.default)( | ||
| newSize && newSize.width > 0 && newSize.height > 0, | ||
| "newSize must be positive" | ||
| ); | ||
| const Jimp = yield getJimp(); | ||
| const image = yield Jimp.read(inputData); | ||
| const { width, height } = image.bitmap; | ||
| if (!width || !height) { | ||
| throw Error("Undefined width or height from the input image."); | ||
| } | ||
| if (newSize.width === width && newSize.height === height) { | ||
| return inputData; | ||
| } | ||
| image.resize(newSize.width, newSize.height, Jimp.RESIZE_NEAREST_NEIGHBOR); | ||
| image.quality(90); | ||
| const resizedBuffer = yield image.getBufferAsync(Jimp.MIME_JPEG); | ||
| return resizedBuffer; | ||
| }); | ||
| } | ||
| function bufferFromBase642(base64) { | ||
| return __async(this, null, function* () { | ||
| const splitFlag = ";base64,"; | ||
| const dataSplitted = base64.split(splitFlag); | ||
| if (dataSplitted.length !== 2) { | ||
| throw Error("Invalid base64 data"); | ||
| } | ||
| return import_node_buffer2.Buffer.from(dataSplitted[1], "base64"); | ||
| }); | ||
| } | ||
| function resizeImgBase64(inputBase64, newSize) { | ||
| return __async(this, null, function* () { | ||
| const splitFlag = ";base64,"; | ||
| const dataSplitted = inputBase64.split(splitFlag); | ||
| if (dataSplitted.length !== 2) { | ||
| throw Error("Invalid base64 data"); | ||
| } | ||
| const imageBuffer = import_node_buffer2.Buffer.from(dataSplitted[1], "base64"); | ||
| const buffer = yield resizeImg(imageBuffer, newSize); | ||
| const content = buffer.toString("base64"); | ||
| return `${dataSplitted[0]}${splitFlag}${content}`; | ||
| }); | ||
| } | ||
| function zoomForGPT4o(originalWidth, originalHeight) { | ||
| const maxWidth = 2048; | ||
| const maxHeight = 768; | ||
| let newWidth = originalWidth; | ||
| let newHeight = originalHeight; | ||
| const aspectRatio = originalWidth / originalHeight; | ||
| if (originalWidth > maxWidth) { | ||
| newWidth = maxWidth; | ||
| newHeight = newWidth / aspectRatio; | ||
| } | ||
| if (newHeight > maxHeight) { | ||
| newHeight = maxHeight; | ||
| newWidth = newHeight * aspectRatio; | ||
| } | ||
| return { | ||
| width: Math.round(newWidth), | ||
| height: Math.round(newHeight) | ||
| }; | ||
| } | ||
| function trimImage(image) { | ||
| return __async(this, null, function* () { | ||
| const Jimp = yield getJimp(); | ||
| const jimpImage = yield Jimp.read( | ||
| import_node_buffer2.Buffer.isBuffer(image) ? image : import_node_buffer2.Buffer.from(image) | ||
| ); | ||
| const { width, height } = jimpImage.bitmap; | ||
| if (width <= 3 || height <= 3) { | ||
| return null; | ||
| } | ||
| const trimmedImage = jimpImage.autocrop(); | ||
| const { width: trimmedWidth, height: trimmedHeight } = trimmedImage.bitmap; | ||
| const trimOffsetLeft = (width - trimmedWidth) / 2; | ||
| const trimOffsetTop = (height - trimmedHeight) / 2; | ||
| if (trimOffsetLeft === 0 && trimOffsetTop === 0) { | ||
| return null; | ||
| } | ||
| return { | ||
| trimOffsetLeft: -trimOffsetLeft, | ||
| trimOffsetTop: -trimOffsetTop, | ||
| width: trimmedWidth, | ||
| height: trimmedHeight | ||
| }; | ||
| }); | ||
| } | ||
| function paddingToMatchBlock(imageBase64, blockSize = 28) { | ||
| return __async(this, null, function* () { | ||
| const Jimp = yield getJimp(); | ||
| const imageBuffer = yield bufferFromBase642(imageBase64); | ||
| const image = yield Jimp.read(imageBuffer); | ||
| const { width, height } = image.bitmap; | ||
| const targetWidth = Math.ceil(width / blockSize) * blockSize; | ||
| const targetHeight = Math.ceil(height / blockSize) * blockSize; | ||
| if (targetWidth === width && targetHeight === height) { | ||
| return imageBase64; | ||
| } | ||
| const paddedImage = new Jimp(targetWidth, targetHeight, 4294967295); | ||
| paddedImage.composite(image, 0, 0); | ||
| const base64 = yield paddedImage.getBase64Async(Jimp.MIME_JPEG); | ||
| return base64; | ||
| }); | ||
| } | ||
| // src/img/box-select.ts | ||
| var import_node_assert3 = __toESM(require("assert")); | ||
| var cachedFont = null; | ||
| var createSvgOverlay = (elements, imageWidth, imageHeight, boxPadding = 5) => __async(void 0, null, function* () { | ||
| const Jimp = yield getJimp(); | ||
| const image = new Jimp(imageWidth, imageHeight, 0); | ||
| const colors = [ | ||
| { rect: 3324182783, text: 4294967295 }, | ||
| // red, white | ||
| { rect: 65535, text: 4294967295 }, | ||
| // blue, white | ||
| { rect: 2336560127, text: 4294967295 }, | ||
| // brown, white | ||
| { rect: 1048258559, text: 4294967295 }, | ||
| // green, white | ||
| { rect: 1342206975, text: 4294967295 } | ||
| // purple, white | ||
| ]; | ||
| for (let index = 0; index < elements.length; index++) { | ||
| const element = elements[index]; | ||
| const color = colors[index % colors.length]; | ||
| const paddedRect = { | ||
| left: Math.max(0, element.rect.left - boxPadding), | ||
| top: Math.max(0, element.rect.top - boxPadding), | ||
| width: Math.min( | ||
| imageWidth - element.rect.left, | ||
| element.rect.width + boxPadding * 2 | ||
| ), | ||
| height: Math.min( | ||
| imageHeight - element.rect.top, | ||
| element.rect.height + boxPadding * 2 | ||
| ) | ||
| }; | ||
| image.scan( | ||
| paddedRect.left, | ||
| paddedRect.top, | ||
| paddedRect.width, | ||
| paddedRect.height, | ||
| function(x, y, idx) { | ||
| if (x === paddedRect.left || x === paddedRect.left + paddedRect.width - 1 || y === paddedRect.top || y === paddedRect.top + paddedRect.height - 1) { | ||
| this.bitmap.data[idx + 0] = color.rect >> 24 & 255; | ||
| this.bitmap.data[idx + 1] = color.rect >> 16 & 255; | ||
| this.bitmap.data[idx + 2] = color.rect >> 8 & 255; | ||
| this.bitmap.data[idx + 3] = color.rect & 255; | ||
| } | ||
| } | ||
| ); | ||
| const textWidth = element.indexId.toString().length * 8; | ||
| const textHeight = 12; | ||
| const rectWidth = textWidth + 5; | ||
| const rectHeight = textHeight + 4; | ||
| let rectX = paddedRect.left - rectWidth; | ||
| let rectY = paddedRect.top + paddedRect.height / 2 - textHeight / 2 - 2; | ||
| const checkOverlap = (x, y) => { | ||
| return elements.slice(0, index).some((otherElement) => { | ||
| return x < otherElement.rect.left + otherElement.rect.width && x + rectWidth > otherElement.rect.left && y < otherElement.rect.top + otherElement.rect.height && y + rectHeight > otherElement.rect.top; | ||
| }); | ||
| }; | ||
| const isWithinBounds = (x, y) => { | ||
| return x >= 0 && x + rectWidth <= imageWidth && y >= 0 && y + rectHeight <= imageHeight; | ||
| }; | ||
| if (checkOverlap(rectX, rectY) || !isWithinBounds(rectX, rectY)) { | ||
| if (!checkOverlap(paddedRect.left, paddedRect.top - rectHeight - 2) && isWithinBounds(paddedRect.left, paddedRect.top - rectHeight - 2)) { | ||
| rectX = paddedRect.left; | ||
| rectY = paddedRect.top - rectHeight - 2; | ||
| } else if (!checkOverlap( | ||
| paddedRect.left, | ||
| paddedRect.top + paddedRect.height + 2 | ||
| ) && isWithinBounds(paddedRect.left, paddedRect.top + paddedRect.height + 2)) { | ||
| rectX = paddedRect.left; | ||
| rectY = paddedRect.top + paddedRect.height + 2; | ||
| } else if (!checkOverlap(paddedRect.left + paddedRect.width + 2, paddedRect.top) && isWithinBounds(paddedRect.left + paddedRect.width + 2, paddedRect.top)) { | ||
| rectX = paddedRect.left + paddedRect.width + 2; | ||
| rectY = paddedRect.top; | ||
| } else { | ||
| rectX = paddedRect.left; | ||
| rectY = paddedRect.top + 2; | ||
| } | ||
| } | ||
| image.scan(rectX, rectY, rectWidth, rectHeight, function(x, y, idx) { | ||
| this.bitmap.data[idx + 0] = color.rect >> 24 & 255; | ||
| this.bitmap.data[idx + 1] = color.rect >> 16 & 255; | ||
| this.bitmap.data[idx + 2] = color.rect >> 8 & 255; | ||
| this.bitmap.data[idx + 3] = color.rect & 255; | ||
| }); | ||
| try { | ||
| cachedFont = cachedFont || (yield Jimp.loadFont(Jimp.FONT_SANS_16_WHITE)); | ||
| } catch (error) { | ||
| console.error("Error loading font", error); | ||
| } | ||
| image.print( | ||
| cachedFont, | ||
| rectX, | ||
| rectY, | ||
| { | ||
| text: element.indexId.toString(), | ||
| alignmentX: Jimp.HORIZONTAL_ALIGN_CENTER, | ||
| alignmentY: Jimp.VERTICAL_ALIGN_MIDDLE | ||
| }, | ||
| rectWidth, | ||
| rectHeight | ||
| ); | ||
| } | ||
| return image; | ||
| }); | ||
| var compositeElementInfoImg = (options) => __async(void 0, null, function* () { | ||
| (0, import_node_assert3.default)(options.inputImgBase64, "inputImgBase64 is required"); | ||
| let width = 0; | ||
| let height = 0; | ||
| let jimpImage; | ||
| const Jimp = yield getJimp(); | ||
| if (options.size) { | ||
| width = options.size.width; | ||
| height = options.size.height; | ||
| } | ||
| if (!width || !height) { | ||
| const info = yield imageInfoOfBase64(options.inputImgBase64); | ||
| width = info.width; | ||
| height = info.height; | ||
| jimpImage = info.jimpImage; | ||
| } else { | ||
| const imageBuffer = yield bufferFromBase64(options.inputImgBase64); | ||
| jimpImage = yield Jimp.read(imageBuffer); | ||
| const imageBitmap = jimpImage.bitmap; | ||
| if (imageBitmap.width !== width || imageBitmap.height !== height) { | ||
| jimpImage.resize(width, height, Jimp.RESIZE_NEAREST_NEIGHBOR); | ||
| } | ||
| } | ||
| if (!width || !height) { | ||
| throw Error("Image processing failed because width or height is undefined"); | ||
| } | ||
| const { elementsPositionInfo } = options; | ||
| const result = yield Promise.resolve(jimpImage).then((image) => __async(void 0, null, function* () { | ||
| const svgOverlay = yield createSvgOverlay( | ||
| elementsPositionInfo, | ||
| width, | ||
| height, | ||
| options.annotationPadding | ||
| ); | ||
| const svgImage = yield Jimp.read(svgOverlay); | ||
| const compositeImage = yield image.composite(svgImage, 0, 0, { | ||
| mode: Jimp.BLEND_SOURCE_OVER, | ||
| opacitySource: 1, | ||
| opacityDest: 1 | ||
| }); | ||
| return compositeImage; | ||
| })).then((compositeImage) => __async(void 0, null, function* () { | ||
| compositeImage.quality(90); | ||
| const base64 = yield compositeImage.getBase64Async(Jimp.MIME_JPEG); | ||
| return base64; | ||
| })).catch((error) => { | ||
| throw error; | ||
| }); | ||
| return result; | ||
| }); | ||
| var processImageElementInfo = (options) => __async(void 0, null, function* () { | ||
| const base64Image = options.inputImgBase64.split(";base64,").pop(); | ||
| (0, import_node_assert3.default)(base64Image, "base64Image is undefined"); | ||
| const [ | ||
| compositeElementInfoImgBase64, | ||
| compositeElementInfoImgWithoutTextBase64 | ||
| ] = yield Promise.all([ | ||
| compositeElementInfoImg({ | ||
| inputImgBase64: options.inputImgBase64, | ||
| elementsPositionInfo: options.elementsPositionInfo | ||
| }), | ||
| compositeElementInfoImg({ | ||
| inputImgBase64: options.inputImgBase64, | ||
| elementsPositionInfo: options.elementsPositionInfoWithoutText | ||
| }) | ||
| ]); | ||
| return { | ||
| compositeElementInfoImgBase64, | ||
| compositeElementInfoImgWithoutTextBase64 | ||
| }; | ||
| }); | ||
| // src/img/draw-box.ts | ||
| function drawBoxOnImage(options) { | ||
| return __async(this, null, function* () { | ||
| const { inputImgBase64, rect } = options; | ||
| const color = { r: 255, g: 0, b: 0, a: 255 }; | ||
| const Jimp = yield getJimp(); | ||
| const imageBuffer = yield bufferFromBase64(inputImgBase64); | ||
| const image = yield Jimp.read(imageBuffer); | ||
| const centerX = rect.x; | ||
| const centerY = rect.y; | ||
| const radius = 5; | ||
| image.scan( | ||
| Math.floor(centerX - radius), | ||
| Math.floor(centerY - radius), | ||
| radius * 2, | ||
| radius * 2, | ||
| function(x, y, idx) { | ||
| const distance = Math.sqrt(__pow(x - centerX, 2) + __pow(y - centerY, 2)); | ||
| if (distance <= radius) { | ||
| this.bitmap.data[idx + 0] = color.r; | ||
| this.bitmap.data[idx + 1] = color.g; | ||
| this.bitmap.data[idx + 2] = color.b; | ||
| this.bitmap.data[idx + 3] = color.a; | ||
| } | ||
| } | ||
| ); | ||
| image.quality(90); | ||
| const resultBase64 = yield image.getBase64Async(Jimp.MIME_JPEG); | ||
| return resultBase64; | ||
| }); | ||
| } | ||
| function savePositionImg(options) { | ||
| return __async(this, null, function* () { | ||
| const { inputImgBase64, rect, outputPath } = options; | ||
| const imgBase64 = yield drawBoxOnImage({ inputImgBase64, rect }); | ||
| yield saveBase64Image({ | ||
| base64Data: imgBase64, | ||
| outputPath | ||
| }); | ||
| }); | ||
| } |
| import { NodeType } from './constants.js'; | ||
| interface Point { | ||
| left: number; | ||
| top: number; | ||
| } | ||
| interface Size { | ||
| width: number; | ||
| height: number; | ||
| dpr?: number; | ||
| } | ||
| type Rect = Point & Size & { | ||
| zoom?: number; | ||
| }; | ||
| declare abstract class BaseElement { | ||
| abstract id: string; | ||
| abstract indexId?: number; | ||
| abstract attributes: { | ||
| nodeType: NodeType; | ||
| [key: string]: string; | ||
| }; | ||
| abstract content: string; | ||
| abstract rect: Rect; | ||
| abstract center: [number, number]; | ||
| abstract locator?: string; | ||
| } | ||
| interface ElementTreeNode<ElementType extends BaseElement = BaseElement> { | ||
| node: ElementType | null; | ||
| children: ElementTreeNode<ElementType>[]; | ||
| } | ||
| export { BaseElement as B, type ElementTreeNode as E, type Rect as R }; |
| declare const _default: {}; | ||
| export { _default as default }; |
| "use strict"; | ||
| var __defProp = Object.defineProperty; | ||
| var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
| var __getOwnPropNames = Object.getOwnPropertyNames; | ||
| var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
| var __export = (target, all) => { | ||
| for (var name in all) | ||
| __defProp(target, name, { get: all[name], enumerable: true }); | ||
| }; | ||
| var __copyProps = (to, from, except, desc) => { | ||
| if (from && typeof from === "object" || typeof from === "function") { | ||
| for (let key of __getOwnPropNames(from)) | ||
| if (!__hasOwnProp.call(to, key) && key !== except) | ||
| __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); | ||
| } | ||
| return to; | ||
| }; | ||
| var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); | ||
| // src/index.ts | ||
| var src_exports = {}; | ||
| __export(src_exports, { | ||
| default: () => src_default | ||
| }); | ||
| module.exports = __toCommonJS(src_exports); | ||
| var src_default = {}; |
| /** | ||
| * @license | ||
| * Copyright 2017 Google Inc. | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
| /** | ||
| * @internal | ||
| */ | ||
| interface KeyDefinition { | ||
| keyCode?: number; | ||
| shiftKeyCode?: number; | ||
| key?: string; | ||
| shiftKey?: string; | ||
| code?: string; | ||
| text?: string; | ||
| shiftText?: string; | ||
| location?: number; | ||
| } | ||
| /** | ||
| * All the valid keys that can be passed to functions that take user input, such | ||
| * as {@link Keyboard.press | keyboard.press } | ||
| * | ||
| * @public | ||
| */ | ||
| type KeyInput = '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' | 'Power' | 'Eject' | 'Abort' | 'Help' | 'Backspace' | 'Tab' | 'Numpad5' | 'NumpadEnter' | 'Enter' | '\r' | '\n' | 'ShiftLeft' | 'ShiftRight' | 'ControlLeft' | 'ControlRight' | 'AltLeft' | 'AltRight' | 'Pause' | 'CapsLock' | 'Escape' | 'Convert' | 'NonConvert' | 'Space' | 'Numpad9' | 'PageUp' | 'Numpad3' | 'PageDown' | 'End' | 'Numpad1' | 'Home' | 'Numpad7' | 'ArrowLeft' | 'Numpad4' | 'Numpad8' | 'ArrowUp' | 'ArrowRight' | 'Numpad6' | 'Numpad2' | 'ArrowDown' | 'Select' | 'Open' | 'PrintScreen' | 'Insert' | 'Numpad0' | 'Delete' | 'NumpadDecimal' | 'Digit0' | 'Digit1' | 'Digit2' | 'Digit3' | 'Digit4' | 'Digit5' | 'Digit6' | 'Digit7' | 'Digit8' | 'Digit9' | 'KeyA' | 'KeyB' | 'KeyC' | 'KeyD' | 'KeyE' | 'KeyF' | 'KeyG' | 'KeyH' | 'KeyI' | 'KeyJ' | 'KeyK' | 'KeyL' | 'KeyM' | 'KeyN' | 'KeyO' | 'KeyP' | 'KeyQ' | 'KeyR' | 'KeyS' | 'KeyT' | 'KeyU' | 'KeyV' | 'KeyW' | 'KeyX' | 'KeyY' | 'KeyZ' | 'MetaLeft' | 'MetaRight' | 'ContextMenu' | 'NumpadMultiply' | 'NumpadAdd' | 'NumpadSubtract' | 'NumpadDivide' | 'F1' | 'F2' | 'F3' | 'F4' | 'F5' | 'F6' | 'F7' | 'F8' | 'F9' | 'F10' | 'F11' | 'F12' | 'F13' | 'F14' | 'F15' | 'F16' | 'F17' | 'F18' | 'F19' | 'F20' | 'F21' | 'F22' | 'F23' | 'F24' | 'NumLock' | 'ScrollLock' | 'AudioVolumeMute' | 'AudioVolumeDown' | 'AudioVolumeUp' | 'MediaTrackNext' | 'MediaTrackPrevious' | 'MediaStop' | 'MediaPlayPause' | 'Semicolon' | 'Equal' | 'NumpadEqual' | 'Comma' | 'Minus' | 'Period' | 'Slash' | 'Backquote' | 'BracketLeft' | 'Backslash' | 'BracketRight' | 'Quote' | 'AltGraph' | 'Props' | 'Cancel' | 'Clear' | 'Shift' | 'Control' | 'Alt' | 'Accept' | 'ModeChange' | ' ' | 'Print' | 'Execute' | '\u0000' | 'a' | 'b' | 'c' | 'd' | 'e' | 'f' | 'g' | 'h' | 'i' | 'j' | 'k' | 'l' | 'm' | 'n' | 'o' | 'p' | 'q' | 'r' | 's' | 't' | 'u' | 'v' | 'w' | 'x' | 'y' | 'z' | 'Meta' | '*' | '+' | '-' | '/' | ';' | '=' | ',' | '.' | '`' | '[' | '\\' | ']' | "'" | 'Attn' | 'CrSel' | 'ExSel' | 'EraseEof' | 'Play' | 'ZoomOut' | ')' | '!' | '@' | '#' | '$' | '%' | '^' | '&' | '(' | 'A' | 'B' | 'C' | 'D' | 'E' | 'F' | 'G' | 'H' | 'I' | 'J' | 'K' | 'L' | 'M' | 'N' | 'O' | 'P' | 'Q' | 'R' | 'S' | 'T' | 'U' | 'V' | 'W' | 'X' | 'Y' | 'Z' | ':' | '<' | '_' | '>' | '?' | '~' | '{' | '|' | '}' | '"' | 'SoftLeft' | 'SoftRight' | 'Camera' | 'Call' | 'EndCall' | 'VolumeDown' | 'VolumeUp'; | ||
| /** | ||
| * @internal | ||
| */ | ||
| declare const _keyDefinitions: Readonly<Record<KeyInput, KeyDefinition>>; | ||
| declare const getKeyDefinition: (key: string) => KeyInput; | ||
| declare const isMac: boolean; | ||
| declare function transformHotkeyInput(keyInput: string): string[]; | ||
| export { type KeyDefinition, type KeyInput, _keyDefinitions, getKeyDefinition, isMac, transformHotkeyInput }; |
| "use strict"; | ||
| var __defProp = Object.defineProperty; | ||
| var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
| var __getOwnPropNames = Object.getOwnPropertyNames; | ||
| var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
| var __export = (target, all) => { | ||
| for (var name in all) | ||
| __defProp(target, name, { get: all[name], enumerable: true }); | ||
| }; | ||
| var __copyProps = (to, from, except, desc) => { | ||
| if (from && typeof from === "object" || typeof from === "function") { | ||
| for (let key of __getOwnPropNames(from)) | ||
| if (!__hasOwnProp.call(to, key) && key !== except) | ||
| __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); | ||
| } | ||
| return to; | ||
| }; | ||
| var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); | ||
| // src/us-keyboard-layout.ts | ||
| var us_keyboard_layout_exports = {}; | ||
| __export(us_keyboard_layout_exports, { | ||
| _keyDefinitions: () => _keyDefinitions, | ||
| getKeyDefinition: () => getKeyDefinition, | ||
| isMac: () => isMac, | ||
| transformHotkeyInput: () => transformHotkeyInput | ||
| }); | ||
| module.exports = __toCommonJS(us_keyboard_layout_exports); | ||
| var _keyDefinitions = { | ||
| "0": { keyCode: 48, key: "0", code: "Digit0" }, | ||
| "1": { keyCode: 49, key: "1", code: "Digit1" }, | ||
| "2": { keyCode: 50, key: "2", code: "Digit2" }, | ||
| "3": { keyCode: 51, key: "3", code: "Digit3" }, | ||
| "4": { keyCode: 52, key: "4", code: "Digit4" }, | ||
| "5": { keyCode: 53, key: "5", code: "Digit5" }, | ||
| "6": { keyCode: 54, key: "6", code: "Digit6" }, | ||
| "7": { keyCode: 55, key: "7", code: "Digit7" }, | ||
| "8": { keyCode: 56, key: "8", code: "Digit8" }, | ||
| "9": { keyCode: 57, key: "9", code: "Digit9" }, | ||
| Power: { key: "Power", code: "Power" }, | ||
| Eject: { key: "Eject", code: "Eject" }, | ||
| Abort: { keyCode: 3, code: "Abort", key: "Cancel" }, | ||
| Help: { keyCode: 6, code: "Help", key: "Help" }, | ||
| Backspace: { keyCode: 8, code: "Backspace", key: "Backspace" }, | ||
| Tab: { keyCode: 9, code: "Tab", key: "Tab" }, | ||
| Numpad5: { | ||
| keyCode: 12, | ||
| shiftKeyCode: 101, | ||
| key: "Clear", | ||
| code: "Numpad5", | ||
| shiftKey: "5", | ||
| location: 3 | ||
| }, | ||
| NumpadEnter: { | ||
| keyCode: 13, | ||
| code: "NumpadEnter", | ||
| key: "Enter", | ||
| text: "\r", | ||
| location: 3 | ||
| }, | ||
| Enter: { keyCode: 13, code: "Enter", key: "Enter", text: "\r" }, | ||
| "\r": { keyCode: 13, code: "Enter", key: "Enter", text: "\r" }, | ||
| "\n": { keyCode: 13, code: "Enter", key: "Enter", text: "\r" }, | ||
| ShiftLeft: { keyCode: 16, code: "ShiftLeft", key: "Shift", location: 1 }, | ||
| ShiftRight: { keyCode: 16, code: "ShiftRight", key: "Shift", location: 2 }, | ||
| ControlLeft: { | ||
| keyCode: 17, | ||
| code: "ControlLeft", | ||
| key: "Control", | ||
| location: 1 | ||
| }, | ||
| ControlRight: { | ||
| keyCode: 17, | ||
| code: "ControlRight", | ||
| key: "Control", | ||
| location: 2 | ||
| }, | ||
| AltLeft: { keyCode: 18, code: "AltLeft", key: "Alt", location: 1 }, | ||
| AltRight: { keyCode: 18, code: "AltRight", key: "Alt", location: 2 }, | ||
| Pause: { keyCode: 19, code: "Pause", key: "Pause" }, | ||
| CapsLock: { keyCode: 20, code: "CapsLock", key: "CapsLock" }, | ||
| Escape: { keyCode: 27, code: "Escape", key: "Escape" }, | ||
| Convert: { keyCode: 28, code: "Convert", key: "Convert" }, | ||
| NonConvert: { keyCode: 29, code: "NonConvert", key: "NonConvert" }, | ||
| Space: { keyCode: 32, code: "Space", key: " " }, | ||
| Numpad9: { | ||
| keyCode: 33, | ||
| shiftKeyCode: 105, | ||
| key: "PageUp", | ||
| code: "Numpad9", | ||
| shiftKey: "9", | ||
| location: 3 | ||
| }, | ||
| PageUp: { keyCode: 33, code: "PageUp", key: "PageUp" }, | ||
| Numpad3: { | ||
| keyCode: 34, | ||
| shiftKeyCode: 99, | ||
| key: "PageDown", | ||
| code: "Numpad3", | ||
| shiftKey: "3", | ||
| location: 3 | ||
| }, | ||
| PageDown: { keyCode: 34, code: "PageDown", key: "PageDown" }, | ||
| End: { keyCode: 35, code: "End", key: "End" }, | ||
| Numpad1: { | ||
| keyCode: 35, | ||
| shiftKeyCode: 97, | ||
| key: "End", | ||
| code: "Numpad1", | ||
| shiftKey: "1", | ||
| location: 3 | ||
| }, | ||
| Home: { keyCode: 36, code: "Home", key: "Home" }, | ||
| Numpad7: { | ||
| keyCode: 36, | ||
| shiftKeyCode: 103, | ||
| key: "Home", | ||
| code: "Numpad7", | ||
| shiftKey: "7", | ||
| location: 3 | ||
| }, | ||
| ArrowLeft: { keyCode: 37, code: "ArrowLeft", key: "ArrowLeft" }, | ||
| Numpad4: { | ||
| keyCode: 37, | ||
| shiftKeyCode: 100, | ||
| key: "ArrowLeft", | ||
| code: "Numpad4", | ||
| shiftKey: "4", | ||
| location: 3 | ||
| }, | ||
| Numpad8: { | ||
| keyCode: 38, | ||
| shiftKeyCode: 104, | ||
| key: "ArrowUp", | ||
| code: "Numpad8", | ||
| shiftKey: "8", | ||
| location: 3 | ||
| }, | ||
| ArrowUp: { keyCode: 38, code: "ArrowUp", key: "ArrowUp" }, | ||
| ArrowRight: { keyCode: 39, code: "ArrowRight", key: "ArrowRight" }, | ||
| Numpad6: { | ||
| keyCode: 39, | ||
| shiftKeyCode: 102, | ||
| key: "ArrowRight", | ||
| code: "Numpad6", | ||
| shiftKey: "6", | ||
| location: 3 | ||
| }, | ||
| Numpad2: { | ||
| keyCode: 40, | ||
| shiftKeyCode: 98, | ||
| key: "ArrowDown", | ||
| code: "Numpad2", | ||
| shiftKey: "2", | ||
| location: 3 | ||
| }, | ||
| ArrowDown: { keyCode: 40, code: "ArrowDown", key: "ArrowDown" }, | ||
| Select: { keyCode: 41, code: "Select", key: "Select" }, | ||
| Open: { keyCode: 43, code: "Open", key: "Execute" }, | ||
| PrintScreen: { keyCode: 44, code: "PrintScreen", key: "PrintScreen" }, | ||
| Insert: { keyCode: 45, code: "Insert", key: "Insert" }, | ||
| Numpad0: { | ||
| keyCode: 45, | ||
| shiftKeyCode: 96, | ||
| key: "Insert", | ||
| code: "Numpad0", | ||
| shiftKey: "0", | ||
| location: 3 | ||
| }, | ||
| Delete: { keyCode: 46, code: "Delete", key: "Delete" }, | ||
| NumpadDecimal: { | ||
| keyCode: 46, | ||
| shiftKeyCode: 110, | ||
| code: "NumpadDecimal", | ||
| key: "\0", | ||
| shiftKey: ".", | ||
| location: 3 | ||
| }, | ||
| Digit0: { keyCode: 48, code: "Digit0", shiftKey: ")", key: "0" }, | ||
| Digit1: { keyCode: 49, code: "Digit1", shiftKey: "!", key: "1" }, | ||
| Digit2: { keyCode: 50, code: "Digit2", shiftKey: "@", key: "2" }, | ||
| Digit3: { keyCode: 51, code: "Digit3", shiftKey: "#", key: "3" }, | ||
| Digit4: { keyCode: 52, code: "Digit4", shiftKey: "$", key: "4" }, | ||
| Digit5: { keyCode: 53, code: "Digit5", shiftKey: "%", key: "5" }, | ||
| Digit6: { keyCode: 54, code: "Digit6", shiftKey: "^", key: "6" }, | ||
| Digit7: { keyCode: 55, code: "Digit7", shiftKey: "&", key: "7" }, | ||
| Digit8: { keyCode: 56, code: "Digit8", shiftKey: "*", key: "8" }, | ||
| Digit9: { keyCode: 57, code: "Digit9", shiftKey: "(", key: "9" }, | ||
| KeyA: { keyCode: 65, code: "KeyA", shiftKey: "A", key: "a" }, | ||
| KeyB: { keyCode: 66, code: "KeyB", shiftKey: "B", key: "b" }, | ||
| KeyC: { keyCode: 67, code: "KeyC", shiftKey: "C", key: "c" }, | ||
| KeyD: { keyCode: 68, code: "KeyD", shiftKey: "D", key: "d" }, | ||
| KeyE: { keyCode: 69, code: "KeyE", shiftKey: "E", key: "e" }, | ||
| KeyF: { keyCode: 70, code: "KeyF", shiftKey: "F", key: "f" }, | ||
| KeyG: { keyCode: 71, code: "KeyG", shiftKey: "G", key: "g" }, | ||
| KeyH: { keyCode: 72, code: "KeyH", shiftKey: "H", key: "h" }, | ||
| KeyI: { keyCode: 73, code: "KeyI", shiftKey: "I", key: "i" }, | ||
| KeyJ: { keyCode: 74, code: "KeyJ", shiftKey: "J", key: "j" }, | ||
| KeyK: { keyCode: 75, code: "KeyK", shiftKey: "K", key: "k" }, | ||
| KeyL: { keyCode: 76, code: "KeyL", shiftKey: "L", key: "l" }, | ||
| KeyM: { keyCode: 77, code: "KeyM", shiftKey: "M", key: "m" }, | ||
| KeyN: { keyCode: 78, code: "KeyN", shiftKey: "N", key: "n" }, | ||
| KeyO: { keyCode: 79, code: "KeyO", shiftKey: "O", key: "o" }, | ||
| KeyP: { keyCode: 80, code: "KeyP", shiftKey: "P", key: "p" }, | ||
| KeyQ: { keyCode: 81, code: "KeyQ", shiftKey: "Q", key: "q" }, | ||
| KeyR: { keyCode: 82, code: "KeyR", shiftKey: "R", key: "r" }, | ||
| KeyS: { keyCode: 83, code: "KeyS", shiftKey: "S", key: "s" }, | ||
| KeyT: { keyCode: 84, code: "KeyT", shiftKey: "T", key: "t" }, | ||
| KeyU: { keyCode: 85, code: "KeyU", shiftKey: "U", key: "u" }, | ||
| KeyV: { keyCode: 86, code: "KeyV", shiftKey: "V", key: "v" }, | ||
| KeyW: { keyCode: 87, code: "KeyW", shiftKey: "W", key: "w" }, | ||
| KeyX: { keyCode: 88, code: "KeyX", shiftKey: "X", key: "x" }, | ||
| KeyY: { keyCode: 89, code: "KeyY", shiftKey: "Y", key: "y" }, | ||
| KeyZ: { keyCode: 90, code: "KeyZ", shiftKey: "Z", key: "z" }, | ||
| MetaLeft: { keyCode: 91, code: "MetaLeft", key: "Meta", location: 1 }, | ||
| MetaRight: { keyCode: 92, code: "MetaRight", key: "Meta", location: 2 }, | ||
| ContextMenu: { keyCode: 93, code: "ContextMenu", key: "ContextMenu" }, | ||
| NumpadMultiply: { | ||
| keyCode: 106, | ||
| code: "NumpadMultiply", | ||
| key: "*", | ||
| location: 3 | ||
| }, | ||
| NumpadAdd: { keyCode: 107, code: "NumpadAdd", key: "+", location: 3 }, | ||
| NumpadSubtract: { | ||
| keyCode: 109, | ||
| code: "NumpadSubtract", | ||
| key: "-", | ||
| location: 3 | ||
| }, | ||
| NumpadDivide: { keyCode: 111, code: "NumpadDivide", key: "/", location: 3 }, | ||
| F1: { keyCode: 112, code: "F1", key: "F1" }, | ||
| F2: { keyCode: 113, code: "F2", key: "F2" }, | ||
| F3: { keyCode: 114, code: "F3", key: "F3" }, | ||
| F4: { keyCode: 115, code: "F4", key: "F4" }, | ||
| F5: { keyCode: 116, code: "F5", key: "F5" }, | ||
| F6: { keyCode: 117, code: "F6", key: "F6" }, | ||
| F7: { keyCode: 118, code: "F7", key: "F7" }, | ||
| F8: { keyCode: 119, code: "F8", key: "F8" }, | ||
| F9: { keyCode: 120, code: "F9", key: "F9" }, | ||
| F10: { keyCode: 121, code: "F10", key: "F10" }, | ||
| F11: { keyCode: 122, code: "F11", key: "F11" }, | ||
| F12: { keyCode: 123, code: "F12", key: "F12" }, | ||
| F13: { keyCode: 124, code: "F13", key: "F13" }, | ||
| F14: { keyCode: 125, code: "F14", key: "F14" }, | ||
| F15: { keyCode: 126, code: "F15", key: "F15" }, | ||
| F16: { keyCode: 127, code: "F16", key: "F16" }, | ||
| F17: { keyCode: 128, code: "F17", key: "F17" }, | ||
| F18: { keyCode: 129, code: "F18", key: "F18" }, | ||
| F19: { keyCode: 130, code: "F19", key: "F19" }, | ||
| F20: { keyCode: 131, code: "F20", key: "F20" }, | ||
| F21: { keyCode: 132, code: "F21", key: "F21" }, | ||
| F22: { keyCode: 133, code: "F22", key: "F22" }, | ||
| F23: { keyCode: 134, code: "F23", key: "F23" }, | ||
| F24: { keyCode: 135, code: "F24", key: "F24" }, | ||
| NumLock: { keyCode: 144, code: "NumLock", key: "NumLock" }, | ||
| ScrollLock: { keyCode: 145, code: "ScrollLock", key: "ScrollLock" }, | ||
| AudioVolumeMute: { | ||
| keyCode: 173, | ||
| code: "AudioVolumeMute", | ||
| key: "AudioVolumeMute" | ||
| }, | ||
| AudioVolumeDown: { | ||
| keyCode: 174, | ||
| code: "AudioVolumeDown", | ||
| key: "AudioVolumeDown" | ||
| }, | ||
| AudioVolumeUp: { keyCode: 175, code: "AudioVolumeUp", key: "AudioVolumeUp" }, | ||
| MediaTrackNext: { | ||
| keyCode: 176, | ||
| code: "MediaTrackNext", | ||
| key: "MediaTrackNext" | ||
| }, | ||
| MediaTrackPrevious: { | ||
| keyCode: 177, | ||
| code: "MediaTrackPrevious", | ||
| key: "MediaTrackPrevious" | ||
| }, | ||
| MediaStop: { keyCode: 178, code: "MediaStop", key: "MediaStop" }, | ||
| MediaPlayPause: { | ||
| keyCode: 179, | ||
| code: "MediaPlayPause", | ||
| key: "MediaPlayPause" | ||
| }, | ||
| Semicolon: { keyCode: 186, code: "Semicolon", shiftKey: ":", key: ";" }, | ||
| Equal: { keyCode: 187, code: "Equal", shiftKey: "+", key: "=" }, | ||
| NumpadEqual: { keyCode: 187, code: "NumpadEqual", key: "=", location: 3 }, | ||
| Comma: { keyCode: 188, code: "Comma", shiftKey: "<", key: "," }, | ||
| Minus: { keyCode: 189, code: "Minus", shiftKey: "_", key: "-" }, | ||
| Period: { keyCode: 190, code: "Period", shiftKey: ">", key: "." }, | ||
| Slash: { keyCode: 191, code: "Slash", shiftKey: "?", key: "/" }, | ||
| Backquote: { keyCode: 192, code: "Backquote", shiftKey: "~", key: "`" }, | ||
| BracketLeft: { keyCode: 219, code: "BracketLeft", shiftKey: "{", key: "[" }, | ||
| Backslash: { keyCode: 220, code: "Backslash", shiftKey: "|", key: "\\" }, | ||
| BracketRight: { keyCode: 221, code: "BracketRight", shiftKey: "}", key: "]" }, | ||
| Quote: { keyCode: 222, code: "Quote", shiftKey: '"', key: "'" }, | ||
| AltGraph: { keyCode: 225, code: "AltGraph", key: "AltGraph" }, | ||
| Props: { keyCode: 247, code: "Props", key: "CrSel" }, | ||
| Cancel: { keyCode: 3, key: "Cancel", code: "Abort" }, | ||
| Clear: { keyCode: 12, key: "Clear", code: "Numpad5", location: 3 }, | ||
| Shift: { keyCode: 16, key: "Shift", code: "ShiftLeft", location: 1 }, | ||
| Control: { keyCode: 17, key: "Control", code: "ControlLeft", location: 1 }, | ||
| Alt: { keyCode: 18, key: "Alt", code: "AltLeft", location: 1 }, | ||
| Accept: { keyCode: 30, key: "Accept" }, | ||
| ModeChange: { keyCode: 31, key: "ModeChange" }, | ||
| " ": { keyCode: 32, key: " ", code: "Space" }, | ||
| Print: { keyCode: 42, key: "Print" }, | ||
| Execute: { keyCode: 43, key: "Execute", code: "Open" }, | ||
| "\0": { keyCode: 46, key: "\0", code: "NumpadDecimal", location: 3 }, | ||
| a: { keyCode: 65, key: "a", code: "KeyA" }, | ||
| b: { keyCode: 66, key: "b", code: "KeyB" }, | ||
| c: { keyCode: 67, key: "c", code: "KeyC" }, | ||
| d: { keyCode: 68, key: "d", code: "KeyD" }, | ||
| e: { keyCode: 69, key: "e", code: "KeyE" }, | ||
| f: { keyCode: 70, key: "f", code: "KeyF" }, | ||
| g: { keyCode: 71, key: "g", code: "KeyG" }, | ||
| h: { keyCode: 72, key: "h", code: "KeyH" }, | ||
| i: { keyCode: 73, key: "i", code: "KeyI" }, | ||
| j: { keyCode: 74, key: "j", code: "KeyJ" }, | ||
| k: { keyCode: 75, key: "k", code: "KeyK" }, | ||
| l: { keyCode: 76, key: "l", code: "KeyL" }, | ||
| m: { keyCode: 77, key: "m", code: "KeyM" }, | ||
| n: { keyCode: 78, key: "n", code: "KeyN" }, | ||
| o: { keyCode: 79, key: "o", code: "KeyO" }, | ||
| p: { keyCode: 80, key: "p", code: "KeyP" }, | ||
| q: { keyCode: 81, key: "q", code: "KeyQ" }, | ||
| r: { keyCode: 82, key: "r", code: "KeyR" }, | ||
| s: { keyCode: 83, key: "s", code: "KeyS" }, | ||
| t: { keyCode: 84, key: "t", code: "KeyT" }, | ||
| u: { keyCode: 85, key: "u", code: "KeyU" }, | ||
| v: { keyCode: 86, key: "v", code: "KeyV" }, | ||
| w: { keyCode: 87, key: "w", code: "KeyW" }, | ||
| x: { keyCode: 88, key: "x", code: "KeyX" }, | ||
| y: { keyCode: 89, key: "y", code: "KeyY" }, | ||
| z: { keyCode: 90, key: "z", code: "KeyZ" }, | ||
| Meta: { keyCode: 91, key: "Meta", code: "MetaLeft", location: 1 }, | ||
| "*": { keyCode: 106, key: "*", code: "NumpadMultiply", location: 3 }, | ||
| "+": { keyCode: 107, key: "+", code: "NumpadAdd", location: 3 }, | ||
| "-": { keyCode: 109, key: "-", code: "NumpadSubtract", location: 3 }, | ||
| "/": { keyCode: 111, key: "/", code: "NumpadDivide", location: 3 }, | ||
| ";": { keyCode: 186, key: ";", code: "Semicolon" }, | ||
| "=": { keyCode: 187, key: "=", code: "Equal" }, | ||
| ",": { keyCode: 188, key: ",", code: "Comma" }, | ||
| ".": { keyCode: 190, key: ".", code: "Period" }, | ||
| "`": { keyCode: 192, key: "`", code: "Backquote" }, | ||
| "[": { keyCode: 219, key: "[", code: "BracketLeft" }, | ||
| "\\": { keyCode: 220, key: "\\", code: "Backslash" }, | ||
| "]": { keyCode: 221, key: "]", code: "BracketRight" }, | ||
| "'": { keyCode: 222, key: "'", code: "Quote" }, | ||
| Attn: { keyCode: 246, key: "Attn" }, | ||
| CrSel: { keyCode: 247, key: "CrSel", code: "Props" }, | ||
| ExSel: { keyCode: 248, key: "ExSel" }, | ||
| EraseEof: { keyCode: 249, key: "EraseEof" }, | ||
| Play: { keyCode: 250, key: "Play" }, | ||
| ZoomOut: { keyCode: 251, key: "ZoomOut" }, | ||
| ")": { keyCode: 48, key: ")", code: "Digit0" }, | ||
| "!": { keyCode: 49, key: "!", code: "Digit1" }, | ||
| "@": { keyCode: 50, key: "@", code: "Digit2" }, | ||
| "#": { keyCode: 51, key: "#", code: "Digit3" }, | ||
| $: { keyCode: 52, key: "$", code: "Digit4" }, | ||
| "%": { keyCode: 53, key: "%", code: "Digit5" }, | ||
| "^": { keyCode: 54, key: "^", code: "Digit6" }, | ||
| "&": { keyCode: 55, key: "&", code: "Digit7" }, | ||
| "(": { keyCode: 57, key: "(", code: "Digit9" }, | ||
| A: { keyCode: 65, key: "A", code: "KeyA" }, | ||
| B: { keyCode: 66, key: "B", code: "KeyB" }, | ||
| C: { keyCode: 67, key: "C", code: "KeyC" }, | ||
| D: { keyCode: 68, key: "D", code: "KeyD" }, | ||
| E: { keyCode: 69, key: "E", code: "KeyE" }, | ||
| F: { keyCode: 70, key: "F", code: "KeyF" }, | ||
| G: { keyCode: 71, key: "G", code: "KeyG" }, | ||
| H: { keyCode: 72, key: "H", code: "KeyH" }, | ||
| I: { keyCode: 73, key: "I", code: "KeyI" }, | ||
| J: { keyCode: 74, key: "J", code: "KeyJ" }, | ||
| K: { keyCode: 75, key: "K", code: "KeyK" }, | ||
| L: { keyCode: 76, key: "L", code: "KeyL" }, | ||
| M: { keyCode: 77, key: "M", code: "KeyM" }, | ||
| N: { keyCode: 78, key: "N", code: "KeyN" }, | ||
| O: { keyCode: 79, key: "O", code: "KeyO" }, | ||
| P: { keyCode: 80, key: "P", code: "KeyP" }, | ||
| Q: { keyCode: 81, key: "Q", code: "KeyQ" }, | ||
| R: { keyCode: 82, key: "R", code: "KeyR" }, | ||
| S: { keyCode: 83, key: "S", code: "KeyS" }, | ||
| T: { keyCode: 84, key: "T", code: "KeyT" }, | ||
| U: { keyCode: 85, key: "U", code: "KeyU" }, | ||
| V: { keyCode: 86, key: "V", code: "KeyV" }, | ||
| W: { keyCode: 87, key: "W", code: "KeyW" }, | ||
| X: { keyCode: 88, key: "X", code: "KeyX" }, | ||
| Y: { keyCode: 89, key: "Y", code: "KeyY" }, | ||
| Z: { keyCode: 90, key: "Z", code: "KeyZ" }, | ||
| ":": { keyCode: 186, key: ":", code: "Semicolon" }, | ||
| "<": { keyCode: 188, key: "<", code: "Comma" }, | ||
| _: { keyCode: 189, key: "_", code: "Minus" }, | ||
| ">": { keyCode: 190, key: ">", code: "Period" }, | ||
| "?": { keyCode: 191, key: "?", code: "Slash" }, | ||
| "~": { keyCode: 192, key: "~", code: "Backquote" }, | ||
| "{": { keyCode: 219, key: "{", code: "BracketLeft" }, | ||
| "|": { keyCode: 220, key: "|", code: "Backslash" }, | ||
| "}": { keyCode: 221, key: "}", code: "BracketRight" }, | ||
| '"': { keyCode: 222, key: '"', code: "Quote" }, | ||
| SoftLeft: { key: "SoftLeft", code: "SoftLeft", location: 4 }, | ||
| SoftRight: { key: "SoftRight", code: "SoftRight", location: 4 }, | ||
| Camera: { keyCode: 44, key: "Camera", code: "Camera", location: 4 }, | ||
| Call: { key: "Call", code: "Call", location: 4 }, | ||
| EndCall: { keyCode: 95, key: "EndCall", code: "EndCall", location: 4 }, | ||
| VolumeDown: { | ||
| keyCode: 182, | ||
| key: "VolumeDown", | ||
| code: "VolumeDown", | ||
| location: 4 | ||
| }, | ||
| VolumeUp: { keyCode: 183, key: "VolumeUp", code: "VolumeUp", location: 4 } | ||
| }; | ||
| var lowerCaseKeyDefinitions = Object.entries(_keyDefinitions).reduce( | ||
| (acc, [key, definition]) => { | ||
| const lowerKey = key.toLowerCase(); | ||
| if (lowerKey !== key) { | ||
| acc[lowerKey] = definition; | ||
| } | ||
| return acc; | ||
| }, | ||
| {} | ||
| ); | ||
| var getKeyDefinition = (key) => { | ||
| const lowerKey = key.toLowerCase(); | ||
| if (lowerCaseKeyDefinitions[lowerKey]) { | ||
| return lowerCaseKeyDefinitions[lowerKey].key; | ||
| } | ||
| return key; | ||
| }; | ||
| var isMac = typeof window !== "undefined" ? /Mac|iPod|iPhone|iPad/.test(window.navigator.platform) : process.platform === "darwin"; | ||
| var keyMap = { | ||
| return: _keyDefinitions.Enter.key, | ||
| enter: _keyDefinitions.Enter.key, | ||
| ctrl: isMac ? _keyDefinitions.Meta.key : _keyDefinitions.Control.key, | ||
| shift: _keyDefinitions.Shift.key, | ||
| alt: _keyDefinitions.Alt.key, | ||
| space: _keyDefinitions.Space.key, | ||
| "page down": _keyDefinitions.PageDown.key, | ||
| pagedown: _keyDefinitions.PageDown.key, | ||
| "page up": _keyDefinitions.PageUp.key, | ||
| pageup: _keyDefinitions.PageUp.key | ||
| }; | ||
| function transformHotkeyInput(keyInput) { | ||
| if (keyMap[keyInput.toLowerCase()]) { | ||
| return [getKeyDefinition(keyMap[keyInput.toLowerCase()])]; | ||
| } | ||
| return keyInput.split(" ").map((key) => { | ||
| return getKeyDefinition(keyMap[key.toLowerCase()] || key); | ||
| }); | ||
| } | ||
| /** | ||
| * @license | ||
| * Copyright 2017 Google Inc. | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ |
| declare const ifInBrowser: boolean; | ||
| declare function uuid(): string; | ||
| declare function generateHashId(rect: any, content?: string): string; | ||
| export { generateHashId, ifInBrowser, uuid }; |
| "use strict"; | ||
| var __create = Object.create; | ||
| var __defProp = Object.defineProperty; | ||
| var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
| var __getOwnPropNames = Object.getOwnPropertyNames; | ||
| var __getProtoOf = Object.getPrototypeOf; | ||
| var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
| var __commonJS = (cb, mod) => function __require() { | ||
| return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports; | ||
| }; | ||
| var __export = (target, all) => { | ||
| for (var name in all) | ||
| __defProp(target, name, { get: all[name], enumerable: true }); | ||
| }; | ||
| var __copyProps = (to, from, except, desc) => { | ||
| if (from && typeof from === "object" || typeof from === "function") { | ||
| for (let key of __getOwnPropNames(from)) | ||
| if (!__hasOwnProp.call(to, key) && key !== except) | ||
| __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); | ||
| } | ||
| return to; | ||
| }; | ||
| var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( | ||
| // If the importer is in node compatibility mode or this is not an ESM | ||
| // file that has been converted to a CommonJS file using a Babel- | ||
| // compatible transform (i.e. "__esModule" has not been set), then set | ||
| // "default" to the CommonJS "module.exports" for node compatibility. | ||
| isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, | ||
| mod | ||
| )); | ||
| var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); | ||
| // resolve-false:/empty-stub | ||
| var require_empty_stub = __commonJS({ | ||
| "resolve-false:/empty-stub"(exports, module2) { | ||
| "use strict"; | ||
| module2.exports = {}; | ||
| } | ||
| }); | ||
| // ../../node_modules/.pnpm/js-sha256@0.11.0/node_modules/js-sha256/src/sha256.js | ||
| var require_sha256 = __commonJS({ | ||
| "../../node_modules/.pnpm/js-sha256@0.11.0/node_modules/js-sha256/src/sha256.js"(exports, module2) { | ||
| "use strict"; | ||
| (function() { | ||
| "use strict"; | ||
| var ERROR = "input is invalid type"; | ||
| var WINDOW = typeof window === "object"; | ||
| var root = WINDOW ? window : {}; | ||
| if (root.JS_SHA256_NO_WINDOW) { | ||
| WINDOW = false; | ||
| } | ||
| var WEB_WORKER = !WINDOW && typeof self === "object"; | ||
| var NODE_JS = !root.JS_SHA256_NO_NODE_JS && typeof process === "object" && process.versions && process.versions.node; | ||
| if (NODE_JS) { | ||
| root = global; | ||
| } else if (WEB_WORKER) { | ||
| root = self; | ||
| } | ||
| var COMMON_JS = !root.JS_SHA256_NO_COMMON_JS && typeof module2 === "object" && module2.exports; | ||
| var AMD = typeof define === "function" && define.amd; | ||
| var ARRAY_BUFFER = !root.JS_SHA256_NO_ARRAY_BUFFER && typeof ArrayBuffer !== "undefined"; | ||
| var HEX_CHARS = "0123456789abcdef".split(""); | ||
| var EXTRA = [-2147483648, 8388608, 32768, 128]; | ||
| var SHIFT = [24, 16, 8, 0]; | ||
| var K = [ | ||
| 1116352408, | ||
| 1899447441, | ||
| 3049323471, | ||
| 3921009573, | ||
| 961987163, | ||
| 1508970993, | ||
| 2453635748, | ||
| 2870763221, | ||
| 3624381080, | ||
| 310598401, | ||
| 607225278, | ||
| 1426881987, | ||
| 1925078388, | ||
| 2162078206, | ||
| 2614888103, | ||
| 3248222580, | ||
| 3835390401, | ||
| 4022224774, | ||
| 264347078, | ||
| 604807628, | ||
| 770255983, | ||
| 1249150122, | ||
| 1555081692, | ||
| 1996064986, | ||
| 2554220882, | ||
| 2821834349, | ||
| 2952996808, | ||
| 3210313671, | ||
| 3336571891, | ||
| 3584528711, | ||
| 113926993, | ||
| 338241895, | ||
| 666307205, | ||
| 773529912, | ||
| 1294757372, | ||
| 1396182291, | ||
| 1695183700, | ||
| 1986661051, | ||
| 2177026350, | ||
| 2456956037, | ||
| 2730485921, | ||
| 2820302411, | ||
| 3259730800, | ||
| 3345764771, | ||
| 3516065817, | ||
| 3600352804, | ||
| 4094571909, | ||
| 275423344, | ||
| 430227734, | ||
| 506948616, | ||
| 659060556, | ||
| 883997877, | ||
| 958139571, | ||
| 1322822218, | ||
| 1537002063, | ||
| 1747873779, | ||
| 1955562222, | ||
| 2024104815, | ||
| 2227730452, | ||
| 2361852424, | ||
| 2428436474, | ||
| 2756734187, | ||
| 3204031479, | ||
| 3329325298 | ||
| ]; | ||
| var OUTPUT_TYPES = ["hex", "array", "digest", "arrayBuffer"]; | ||
| var blocks = []; | ||
| if (root.JS_SHA256_NO_NODE_JS || !Array.isArray) { | ||
| Array.isArray = function(obj) { | ||
| return Object.prototype.toString.call(obj) === "[object Array]"; | ||
| }; | ||
| } | ||
| if (ARRAY_BUFFER && (root.JS_SHA256_NO_ARRAY_BUFFER_IS_VIEW || !ArrayBuffer.isView)) { | ||
| ArrayBuffer.isView = function(obj) { | ||
| return typeof obj === "object" && obj.buffer && obj.buffer.constructor === ArrayBuffer; | ||
| }; | ||
| } | ||
| var createOutputMethod = function(outputType, is224) { | ||
| return function(message) { | ||
| return new Sha256(is224, true).update(message)[outputType](); | ||
| }; | ||
| }; | ||
| var createMethod = function(is224) { | ||
| var method = createOutputMethod("hex", is224); | ||
| if (NODE_JS) { | ||
| method = nodeWrap(method, is224); | ||
| } | ||
| method.create = function() { | ||
| return new Sha256(is224); | ||
| }; | ||
| method.update = function(message) { | ||
| return method.create().update(message); | ||
| }; | ||
| for (var i = 0; i < OUTPUT_TYPES.length; ++i) { | ||
| var type = OUTPUT_TYPES[i]; | ||
| method[type] = createOutputMethod(type, is224); | ||
| } | ||
| return method; | ||
| }; | ||
| var nodeWrap = function(method, is224) { | ||
| var crypto = require_empty_stub(); | ||
| var Buffer2 = require_empty_stub().Buffer; | ||
| var algorithm = is224 ? "sha224" : "sha256"; | ||
| var bufferFrom; | ||
| if (Buffer2.from && !root.JS_SHA256_NO_BUFFER_FROM) { | ||
| bufferFrom = Buffer2.from; | ||
| } else { | ||
| bufferFrom = function(message) { | ||
| return new Buffer2(message); | ||
| }; | ||
| } | ||
| var nodeMethod = function(message) { | ||
| if (typeof message === "string") { | ||
| return crypto.createHash(algorithm).update(message, "utf8").digest("hex"); | ||
| } else { | ||
| if (message === null || message === void 0) { | ||
| throw new Error(ERROR); | ||
| } else if (message.constructor === ArrayBuffer) { | ||
| message = new Uint8Array(message); | ||
| } | ||
| } | ||
| if (Array.isArray(message) || ArrayBuffer.isView(message) || message.constructor === Buffer2) { | ||
| return crypto.createHash(algorithm).update(bufferFrom(message)).digest("hex"); | ||
| } else { | ||
| return method(message); | ||
| } | ||
| }; | ||
| return nodeMethod; | ||
| }; | ||
| var createHmacOutputMethod = function(outputType, is224) { | ||
| return function(key, message) { | ||
| return new HmacSha256(key, is224, true).update(message)[outputType](); | ||
| }; | ||
| }; | ||
| var createHmacMethod = function(is224) { | ||
| var method = createHmacOutputMethod("hex", is224); | ||
| method.create = function(key) { | ||
| return new HmacSha256(key, is224); | ||
| }; | ||
| method.update = function(key, message) { | ||
| return method.create(key).update(message); | ||
| }; | ||
| for (var i = 0; i < OUTPUT_TYPES.length; ++i) { | ||
| var type = OUTPUT_TYPES[i]; | ||
| method[type] = createHmacOutputMethod(type, is224); | ||
| } | ||
| return method; | ||
| }; | ||
| function Sha256(is224, sharedMemory) { | ||
| if (sharedMemory) { | ||
| blocks[0] = blocks[16] = blocks[1] = blocks[2] = blocks[3] = blocks[4] = blocks[5] = blocks[6] = blocks[7] = blocks[8] = blocks[9] = blocks[10] = blocks[11] = blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0; | ||
| this.blocks = blocks; | ||
| } else { | ||
| this.blocks = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; | ||
| } | ||
| if (is224) { | ||
| this.h0 = 3238371032; | ||
| this.h1 = 914150663; | ||
| this.h2 = 812702999; | ||
| this.h3 = 4144912697; | ||
| this.h4 = 4290775857; | ||
| this.h5 = 1750603025; | ||
| this.h6 = 1694076839; | ||
| this.h7 = 3204075428; | ||
| } else { | ||
| this.h0 = 1779033703; | ||
| this.h1 = 3144134277; | ||
| this.h2 = 1013904242; | ||
| this.h3 = 2773480762; | ||
| this.h4 = 1359893119; | ||
| this.h5 = 2600822924; | ||
| this.h6 = 528734635; | ||
| this.h7 = 1541459225; | ||
| } | ||
| this.block = this.start = this.bytes = this.hBytes = 0; | ||
| this.finalized = this.hashed = false; | ||
| this.first = true; | ||
| this.is224 = is224; | ||
| } | ||
| Sha256.prototype.update = function(message) { | ||
| if (this.finalized) { | ||
| return; | ||
| } | ||
| var notString, type = typeof message; | ||
| if (type !== "string") { | ||
| if (type === "object") { | ||
| if (message === null) { | ||
| throw new Error(ERROR); | ||
| } else if (ARRAY_BUFFER && message.constructor === ArrayBuffer) { | ||
| message = new Uint8Array(message); | ||
| } else if (!Array.isArray(message)) { | ||
| if (!ARRAY_BUFFER || !ArrayBuffer.isView(message)) { | ||
| throw new Error(ERROR); | ||
| } | ||
| } | ||
| } else { | ||
| throw new Error(ERROR); | ||
| } | ||
| notString = true; | ||
| } | ||
| var code, index = 0, i, length = message.length, blocks2 = this.blocks; | ||
| while (index < length) { | ||
| if (this.hashed) { | ||
| this.hashed = false; | ||
| blocks2[0] = this.block; | ||
| this.block = blocks2[16] = blocks2[1] = blocks2[2] = blocks2[3] = blocks2[4] = blocks2[5] = blocks2[6] = blocks2[7] = blocks2[8] = blocks2[9] = blocks2[10] = blocks2[11] = blocks2[12] = blocks2[13] = blocks2[14] = blocks2[15] = 0; | ||
| } | ||
| if (notString) { | ||
| for (i = this.start; index < length && i < 64; ++index) { | ||
| blocks2[i >>> 2] |= message[index] << SHIFT[i++ & 3]; | ||
| } | ||
| } else { | ||
| for (i = this.start; index < length && i < 64; ++index) { | ||
| code = message.charCodeAt(index); | ||
| if (code < 128) { | ||
| blocks2[i >>> 2] |= code << SHIFT[i++ & 3]; | ||
| } else if (code < 2048) { | ||
| blocks2[i >>> 2] |= (192 | code >>> 6) << SHIFT[i++ & 3]; | ||
| blocks2[i >>> 2] |= (128 | code & 63) << SHIFT[i++ & 3]; | ||
| } else if (code < 55296 || code >= 57344) { | ||
| blocks2[i >>> 2] |= (224 | code >>> 12) << SHIFT[i++ & 3]; | ||
| blocks2[i >>> 2] |= (128 | code >>> 6 & 63) << SHIFT[i++ & 3]; | ||
| blocks2[i >>> 2] |= (128 | code & 63) << SHIFT[i++ & 3]; | ||
| } else { | ||
| code = 65536 + ((code & 1023) << 10 | message.charCodeAt(++index) & 1023); | ||
| blocks2[i >>> 2] |= (240 | code >>> 18) << SHIFT[i++ & 3]; | ||
| blocks2[i >>> 2] |= (128 | code >>> 12 & 63) << SHIFT[i++ & 3]; | ||
| blocks2[i >>> 2] |= (128 | code >>> 6 & 63) << SHIFT[i++ & 3]; | ||
| blocks2[i >>> 2] |= (128 | code & 63) << SHIFT[i++ & 3]; | ||
| } | ||
| } | ||
| } | ||
| this.lastByteIndex = i; | ||
| this.bytes += i - this.start; | ||
| if (i >= 64) { | ||
| this.block = blocks2[16]; | ||
| this.start = i - 64; | ||
| this.hash(); | ||
| this.hashed = true; | ||
| } else { | ||
| this.start = i; | ||
| } | ||
| } | ||
| if (this.bytes > 4294967295) { | ||
| this.hBytes += this.bytes / 4294967296 << 0; | ||
| this.bytes = this.bytes % 4294967296; | ||
| } | ||
| return this; | ||
| }; | ||
| Sha256.prototype.finalize = function() { | ||
| if (this.finalized) { | ||
| return; | ||
| } | ||
| this.finalized = true; | ||
| var blocks2 = this.blocks, i = this.lastByteIndex; | ||
| blocks2[16] = this.block; | ||
| blocks2[i >>> 2] |= EXTRA[i & 3]; | ||
| this.block = blocks2[16]; | ||
| if (i >= 56) { | ||
| if (!this.hashed) { | ||
| this.hash(); | ||
| } | ||
| blocks2[0] = this.block; | ||
| blocks2[16] = blocks2[1] = blocks2[2] = blocks2[3] = blocks2[4] = blocks2[5] = blocks2[6] = blocks2[7] = blocks2[8] = blocks2[9] = blocks2[10] = blocks2[11] = blocks2[12] = blocks2[13] = blocks2[14] = blocks2[15] = 0; | ||
| } | ||
| blocks2[14] = this.hBytes << 3 | this.bytes >>> 29; | ||
| blocks2[15] = this.bytes << 3; | ||
| this.hash(); | ||
| }; | ||
| Sha256.prototype.hash = function() { | ||
| var a = this.h0, b = this.h1, c = this.h2, d = this.h3, e = this.h4, f = this.h5, g = this.h6, h = this.h7, blocks2 = this.blocks, j, s0, s1, maj, t1, t2, ch, ab, da, cd, bc; | ||
| for (j = 16; j < 64; ++j) { | ||
| t1 = blocks2[j - 15]; | ||
| s0 = (t1 >>> 7 | t1 << 25) ^ (t1 >>> 18 | t1 << 14) ^ t1 >>> 3; | ||
| t1 = blocks2[j - 2]; | ||
| s1 = (t1 >>> 17 | t1 << 15) ^ (t1 >>> 19 | t1 << 13) ^ t1 >>> 10; | ||
| blocks2[j] = blocks2[j - 16] + s0 + blocks2[j - 7] + s1 << 0; | ||
| } | ||
| bc = b & c; | ||
| for (j = 0; j < 64; j += 4) { | ||
| if (this.first) { | ||
| if (this.is224) { | ||
| ab = 300032; | ||
| t1 = blocks2[0] - 1413257819; | ||
| h = t1 - 150054599 << 0; | ||
| d = t1 + 24177077 << 0; | ||
| } else { | ||
| ab = 704751109; | ||
| t1 = blocks2[0] - 210244248; | ||
| h = t1 - 1521486534 << 0; | ||
| d = t1 + 143694565 << 0; | ||
| } | ||
| this.first = false; | ||
| } else { | ||
| s0 = (a >>> 2 | a << 30) ^ (a >>> 13 | a << 19) ^ (a >>> 22 | a << 10); | ||
| s1 = (e >>> 6 | e << 26) ^ (e >>> 11 | e << 21) ^ (e >>> 25 | e << 7); | ||
| ab = a & b; | ||
| maj = ab ^ a & c ^ bc; | ||
| ch = e & f ^ ~e & g; | ||
| t1 = h + s1 + ch + K[j] + blocks2[j]; | ||
| t2 = s0 + maj; | ||
| h = d + t1 << 0; | ||
| d = t1 + t2 << 0; | ||
| } | ||
| s0 = (d >>> 2 | d << 30) ^ (d >>> 13 | d << 19) ^ (d >>> 22 | d << 10); | ||
| s1 = (h >>> 6 | h << 26) ^ (h >>> 11 | h << 21) ^ (h >>> 25 | h << 7); | ||
| da = d & a; | ||
| maj = da ^ d & b ^ ab; | ||
| ch = h & e ^ ~h & f; | ||
| t1 = g + s1 + ch + K[j + 1] + blocks2[j + 1]; | ||
| t2 = s0 + maj; | ||
| g = c + t1 << 0; | ||
| c = t1 + t2 << 0; | ||
| s0 = (c >>> 2 | c << 30) ^ (c >>> 13 | c << 19) ^ (c >>> 22 | c << 10); | ||
| s1 = (g >>> 6 | g << 26) ^ (g >>> 11 | g << 21) ^ (g >>> 25 | g << 7); | ||
| cd = c & d; | ||
| maj = cd ^ c & a ^ da; | ||
| ch = g & h ^ ~g & e; | ||
| t1 = f + s1 + ch + K[j + 2] + blocks2[j + 2]; | ||
| t2 = s0 + maj; | ||
| f = b + t1 << 0; | ||
| b = t1 + t2 << 0; | ||
| s0 = (b >>> 2 | b << 30) ^ (b >>> 13 | b << 19) ^ (b >>> 22 | b << 10); | ||
| s1 = (f >>> 6 | f << 26) ^ (f >>> 11 | f << 21) ^ (f >>> 25 | f << 7); | ||
| bc = b & c; | ||
| maj = bc ^ b & d ^ cd; | ||
| ch = f & g ^ ~f & h; | ||
| t1 = e + s1 + ch + K[j + 3] + blocks2[j + 3]; | ||
| t2 = s0 + maj; | ||
| e = a + t1 << 0; | ||
| a = t1 + t2 << 0; | ||
| this.chromeBugWorkAround = true; | ||
| } | ||
| this.h0 = this.h0 + a << 0; | ||
| this.h1 = this.h1 + b << 0; | ||
| this.h2 = this.h2 + c << 0; | ||
| this.h3 = this.h3 + d << 0; | ||
| this.h4 = this.h4 + e << 0; | ||
| this.h5 = this.h5 + f << 0; | ||
| this.h6 = this.h6 + g << 0; | ||
| this.h7 = this.h7 + h << 0; | ||
| }; | ||
| Sha256.prototype.hex = function() { | ||
| this.finalize(); | ||
| var h0 = this.h0, h1 = this.h1, h2 = this.h2, h3 = this.h3, h4 = this.h4, h5 = this.h5, h6 = this.h6, h7 = this.h7; | ||
| var hex = HEX_CHARS[h0 >>> 28 & 15] + HEX_CHARS[h0 >>> 24 & 15] + HEX_CHARS[h0 >>> 20 & 15] + HEX_CHARS[h0 >>> 16 & 15] + HEX_CHARS[h0 >>> 12 & 15] + HEX_CHARS[h0 >>> 8 & 15] + HEX_CHARS[h0 >>> 4 & 15] + HEX_CHARS[h0 & 15] + HEX_CHARS[h1 >>> 28 & 15] + HEX_CHARS[h1 >>> 24 & 15] + HEX_CHARS[h1 >>> 20 & 15] + HEX_CHARS[h1 >>> 16 & 15] + HEX_CHARS[h1 >>> 12 & 15] + HEX_CHARS[h1 >>> 8 & 15] + HEX_CHARS[h1 >>> 4 & 15] + HEX_CHARS[h1 & 15] + HEX_CHARS[h2 >>> 28 & 15] + HEX_CHARS[h2 >>> 24 & 15] + HEX_CHARS[h2 >>> 20 & 15] + HEX_CHARS[h2 >>> 16 & 15] + HEX_CHARS[h2 >>> 12 & 15] + HEX_CHARS[h2 >>> 8 & 15] + HEX_CHARS[h2 >>> 4 & 15] + HEX_CHARS[h2 & 15] + HEX_CHARS[h3 >>> 28 & 15] + HEX_CHARS[h3 >>> 24 & 15] + HEX_CHARS[h3 >>> 20 & 15] + HEX_CHARS[h3 >>> 16 & 15] + HEX_CHARS[h3 >>> 12 & 15] + HEX_CHARS[h3 >>> 8 & 15] + HEX_CHARS[h3 >>> 4 & 15] + HEX_CHARS[h3 & 15] + HEX_CHARS[h4 >>> 28 & 15] + HEX_CHARS[h4 >>> 24 & 15] + HEX_CHARS[h4 >>> 20 & 15] + HEX_CHARS[h4 >>> 16 & 15] + HEX_CHARS[h4 >>> 12 & 15] + HEX_CHARS[h4 >>> 8 & 15] + HEX_CHARS[h4 >>> 4 & 15] + HEX_CHARS[h4 & 15] + HEX_CHARS[h5 >>> 28 & 15] + HEX_CHARS[h5 >>> 24 & 15] + HEX_CHARS[h5 >>> 20 & 15] + HEX_CHARS[h5 >>> 16 & 15] + HEX_CHARS[h5 >>> 12 & 15] + HEX_CHARS[h5 >>> 8 & 15] + HEX_CHARS[h5 >>> 4 & 15] + HEX_CHARS[h5 & 15] + HEX_CHARS[h6 >>> 28 & 15] + HEX_CHARS[h6 >>> 24 & 15] + HEX_CHARS[h6 >>> 20 & 15] + HEX_CHARS[h6 >>> 16 & 15] + HEX_CHARS[h6 >>> 12 & 15] + HEX_CHARS[h6 >>> 8 & 15] + HEX_CHARS[h6 >>> 4 & 15] + HEX_CHARS[h6 & 15]; | ||
| if (!this.is224) { | ||
| hex += HEX_CHARS[h7 >>> 28 & 15] + HEX_CHARS[h7 >>> 24 & 15] + HEX_CHARS[h7 >>> 20 & 15] + HEX_CHARS[h7 >>> 16 & 15] + HEX_CHARS[h7 >>> 12 & 15] + HEX_CHARS[h7 >>> 8 & 15] + HEX_CHARS[h7 >>> 4 & 15] + HEX_CHARS[h7 & 15]; | ||
| } | ||
| return hex; | ||
| }; | ||
| Sha256.prototype.toString = Sha256.prototype.hex; | ||
| Sha256.prototype.digest = function() { | ||
| this.finalize(); | ||
| var h0 = this.h0, h1 = this.h1, h2 = this.h2, h3 = this.h3, h4 = this.h4, h5 = this.h5, h6 = this.h6, h7 = this.h7; | ||
| var arr = [ | ||
| h0 >>> 24 & 255, | ||
| h0 >>> 16 & 255, | ||
| h0 >>> 8 & 255, | ||
| h0 & 255, | ||
| h1 >>> 24 & 255, | ||
| h1 >>> 16 & 255, | ||
| h1 >>> 8 & 255, | ||
| h1 & 255, | ||
| h2 >>> 24 & 255, | ||
| h2 >>> 16 & 255, | ||
| h2 >>> 8 & 255, | ||
| h2 & 255, | ||
| h3 >>> 24 & 255, | ||
| h3 >>> 16 & 255, | ||
| h3 >>> 8 & 255, | ||
| h3 & 255, | ||
| h4 >>> 24 & 255, | ||
| h4 >>> 16 & 255, | ||
| h4 >>> 8 & 255, | ||
| h4 & 255, | ||
| h5 >>> 24 & 255, | ||
| h5 >>> 16 & 255, | ||
| h5 >>> 8 & 255, | ||
| h5 & 255, | ||
| h6 >>> 24 & 255, | ||
| h6 >>> 16 & 255, | ||
| h6 >>> 8 & 255, | ||
| h6 & 255 | ||
| ]; | ||
| if (!this.is224) { | ||
| arr.push(h7 >>> 24 & 255, h7 >>> 16 & 255, h7 >>> 8 & 255, h7 & 255); | ||
| } | ||
| return arr; | ||
| }; | ||
| Sha256.prototype.array = Sha256.prototype.digest; | ||
| Sha256.prototype.arrayBuffer = function() { | ||
| this.finalize(); | ||
| var buffer = new ArrayBuffer(this.is224 ? 28 : 32); | ||
| var dataView = new DataView(buffer); | ||
| dataView.setUint32(0, this.h0); | ||
| dataView.setUint32(4, this.h1); | ||
| dataView.setUint32(8, this.h2); | ||
| dataView.setUint32(12, this.h3); | ||
| dataView.setUint32(16, this.h4); | ||
| dataView.setUint32(20, this.h5); | ||
| dataView.setUint32(24, this.h6); | ||
| if (!this.is224) { | ||
| dataView.setUint32(28, this.h7); | ||
| } | ||
| return buffer; | ||
| }; | ||
| function HmacSha256(key, is224, sharedMemory) { | ||
| var i, type = typeof key; | ||
| if (type === "string") { | ||
| var bytes = [], length = key.length, index = 0, code; | ||
| for (i = 0; i < length; ++i) { | ||
| code = key.charCodeAt(i); | ||
| if (code < 128) { | ||
| bytes[index++] = code; | ||
| } else if (code < 2048) { | ||
| bytes[index++] = 192 | code >>> 6; | ||
| bytes[index++] = 128 | code & 63; | ||
| } else if (code < 55296 || code >= 57344) { | ||
| bytes[index++] = 224 | code >>> 12; | ||
| bytes[index++] = 128 | code >>> 6 & 63; | ||
| bytes[index++] = 128 | code & 63; | ||
| } else { | ||
| code = 65536 + ((code & 1023) << 10 | key.charCodeAt(++i) & 1023); | ||
| bytes[index++] = 240 | code >>> 18; | ||
| bytes[index++] = 128 | code >>> 12 & 63; | ||
| bytes[index++] = 128 | code >>> 6 & 63; | ||
| bytes[index++] = 128 | code & 63; | ||
| } | ||
| } | ||
| key = bytes; | ||
| } else { | ||
| if (type === "object") { | ||
| if (key === null) { | ||
| throw new Error(ERROR); | ||
| } else if (ARRAY_BUFFER && key.constructor === ArrayBuffer) { | ||
| key = new Uint8Array(key); | ||
| } else if (!Array.isArray(key)) { | ||
| if (!ARRAY_BUFFER || !ArrayBuffer.isView(key)) { | ||
| throw new Error(ERROR); | ||
| } | ||
| } | ||
| } else { | ||
| throw new Error(ERROR); | ||
| } | ||
| } | ||
| if (key.length > 64) { | ||
| key = new Sha256(is224, true).update(key).array(); | ||
| } | ||
| var oKeyPad = [], iKeyPad = []; | ||
| for (i = 0; i < 64; ++i) { | ||
| var b = key[i] || 0; | ||
| oKeyPad[i] = 92 ^ b; | ||
| iKeyPad[i] = 54 ^ b; | ||
| } | ||
| Sha256.call(this, is224, sharedMemory); | ||
| this.update(iKeyPad); | ||
| this.oKeyPad = oKeyPad; | ||
| this.inner = true; | ||
| this.sharedMemory = sharedMemory; | ||
| } | ||
| HmacSha256.prototype = new Sha256(); | ||
| HmacSha256.prototype.finalize = function() { | ||
| Sha256.prototype.finalize.call(this); | ||
| if (this.inner) { | ||
| this.inner = false; | ||
| var innerHash = this.array(); | ||
| Sha256.call(this, this.is224, this.sharedMemory); | ||
| this.update(this.oKeyPad); | ||
| this.update(innerHash); | ||
| Sha256.prototype.finalize.call(this); | ||
| } | ||
| }; | ||
| var exports2 = createMethod(); | ||
| exports2.sha256 = exports2; | ||
| exports2.sha224 = createMethod(true); | ||
| exports2.sha256.hmac = createHmacMethod(); | ||
| exports2.sha224.hmac = createHmacMethod(true); | ||
| if (COMMON_JS) { | ||
| module2.exports = exports2; | ||
| } else { | ||
| root.sha256 = exports2.sha256; | ||
| root.sha224 = exports2.sha224; | ||
| if (AMD) { | ||
| define(function() { | ||
| return exports2; | ||
| }); | ||
| } | ||
| } | ||
| })(); | ||
| } | ||
| }); | ||
| // src/utils.ts | ||
| var utils_exports = {}; | ||
| __export(utils_exports, { | ||
| generateHashId: () => generateHashId, | ||
| ifInBrowser: () => ifInBrowser, | ||
| uuid: () => uuid | ||
| }); | ||
| module.exports = __toCommonJS(utils_exports); | ||
| var import_js_sha256 = __toESM(require_sha256()); | ||
| var ifInBrowser = typeof window !== "undefined"; | ||
| function uuid() { | ||
| return Math.random().toString(36).substring(2, 15); | ||
| } | ||
| var hashMap = {}; | ||
| function generateHashId(rect, content = "") { | ||
| const combined = JSON.stringify({ | ||
| content, | ||
| rect | ||
| }); | ||
| let sliceLength = 5; | ||
| let slicedHash = ""; | ||
| const hashHex = import_js_sha256.sha256.create().update(combined).hex(); | ||
| const toLetters = (hex) => { | ||
| return hex.split("").map((char) => { | ||
| const code = Number.parseInt(char, 16); | ||
| return String.fromCharCode(97 + code % 26); | ||
| }).join(""); | ||
| }; | ||
| const hashLetters = toLetters(hashHex); | ||
| while (sliceLength < hashLetters.length - 1) { | ||
| slicedHash = hashLetters.slice(0, sliceLength); | ||
| if (hashMap[slicedHash] && hashMap[slicedHash] !== combined) { | ||
| sliceLength++; | ||
| continue; | ||
| } | ||
| hashMap[slicedHash] = combined; | ||
| break; | ||
| } | ||
| return slicedHash; | ||
| } | ||
| /*! Bundled license information: | ||
| js-sha256/src/sha256.js: | ||
| (** | ||
| * [js-sha256]{@link https://github.com/emn178/js-sha256} | ||
| * | ||
| * @version 0.11.0 | ||
| * @author Chen, Yi-Cyuan [emn178@gmail.com] | ||
| * @copyright Chen, Yi-Cyuan 2014-2024 | ||
| * @license MIT | ||
| *) | ||
| */ |
| import { existsSync, readFileSync } from 'node:fs'; | ||
| import { dirname, join } from 'node:path'; | ||
| interface PkgInfo { | ||
| name: string; | ||
| version: string; | ||
| dir: string; | ||
| } | ||
| const pkgCacheMap: Record<string, PkgInfo> = {}; | ||
| const ifInBrowser = typeof window !== 'undefined'; | ||
| export function getRunningPkgInfo(dir?: string): PkgInfo | null { | ||
| if (ifInBrowser) { | ||
| return null; | ||
| } | ||
| const dirToCheck = dir || process.cwd(); | ||
| if (pkgCacheMap[dirToCheck]) { | ||
| return pkgCacheMap[dirToCheck]; | ||
| } | ||
| const pkgDir = findNearestPackageJson(dirToCheck); | ||
| const pkgJsonFile = pkgDir ? join(pkgDir, 'package.json') : null; | ||
| if (pkgDir && pkgJsonFile) { | ||
| const { name, version } = JSON.parse(readFileSync(pkgJsonFile, 'utf-8')); | ||
| pkgCacheMap[dirToCheck] = { | ||
| name: name || 'midscene-unknown-package-name', | ||
| version: version || '0.0.0', | ||
| dir: pkgDir, | ||
| }; | ||
| return pkgCacheMap[dirToCheck]; | ||
| } | ||
| return { | ||
| name: 'midscene-unknown-package-name', | ||
| version: '0.0.0', | ||
| dir: dirToCheck, | ||
| }; | ||
| } | ||
| /** | ||
| * Find the nearest package.json file recursively | ||
| * @param {string} dir - Home directory | ||
| * @returns {string|null} - The most recent package.json file path or null | ||
| */ | ||
| export function findNearestPackageJson(dir: string): string | null { | ||
| const packageJsonPath = join(dir, 'package.json'); | ||
| if (existsSync(packageJsonPath)) { | ||
| return dir; | ||
| } | ||
| const parentDir = dirname(dir); | ||
| // Return null if the root directory has been reached | ||
| if (parentDir === dir) { | ||
| return null; | ||
| } | ||
| return findNearestPackageJson(parentDir); | ||
| } |
Sorry, the diff of this file is too big to display
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
445622
-37.6%3
200%69
-11.54%12886
-34.95%+ Added
+ Added
+ Added
+ Added
+ Added