@aico-test/shared
Advanced tools
| type DebugFunction = (...args: unknown[]) => void; | ||
| declare function getDebug(topic: string): DebugFunction; | ||
| declare function enableDebug(topic: string): void; | ||
| declare function cleanupLogStreams(): void; | ||
| export { type DebugFunction, cleanupLogStreams, enableDebug, getDebug }; |
| // src/logger.ts | ||
| import fs2 from "fs"; | ||
| import path2 from "path"; | ||
| import debug from "debug"; | ||
| // src/common.ts | ||
| import fs from "fs"; | ||
| import path from "path"; | ||
| var isNodeEnv = typeof process !== "undefined" && process.versions != null && process.versions.node != null; | ||
| var getMidsceneRunLogPath = () => { | ||
| const basePath = path.join(process.cwd(), "midscene_run"); | ||
| if (!fs.existsSync(basePath)) { | ||
| fs.mkdirSync(basePath, { recursive: true }); | ||
| } | ||
| const logPath = path.join(basePath, "log"); | ||
| if (!fs.existsSync(logPath)) { | ||
| fs.mkdirSync(logPath, { recursive: true }); | ||
| } | ||
| return logPath; | ||
| }; | ||
| var logDir = isNodeEnv ? getMidsceneRunLogPath() : ""; | ||
| // src/logger.ts | ||
| var topicPrefix = "midscene"; | ||
| var logStreams = /* @__PURE__ */ new Map(); | ||
| function getLogStream(topic) { | ||
| const topicFileName = topic.replace(/:/g, "-"); | ||
| if (!logStreams.has(topicFileName)) { | ||
| const logFile = path2.join(logDir, `${topicFileName}.log`); | ||
| const stream = fs2.createWriteStream(logFile, { flags: "a" }); | ||
| logStreams.set(topicFileName, stream); | ||
| } | ||
| return logStreams.get(topicFileName); | ||
| } | ||
| function writeLogToFile(topic, message) { | ||
| if (!isNodeEnv) | ||
| return; | ||
| const stream = getLogStream(topic); | ||
| const timestamp = (/* @__PURE__ */ new Date()).toISOString(); | ||
| stream.write(`[${timestamp}] ${message} | ||
| `); | ||
| } | ||
| function getDebug(topic) { | ||
| return (...args) => { | ||
| const message = args.map( | ||
| (arg) => typeof arg === "object" ? JSON.stringify(arg) : String(arg) | ||
| ).join(" "); | ||
| if (isNodeEnv) { | ||
| writeLogToFile(topic, message); | ||
| } | ||
| const debugFn = debug(`${topicPrefix}:${topic}`); | ||
| debugFn(...args); | ||
| }; | ||
| } | ||
| function enableDebug(topic) { | ||
| if (isNodeEnv) { | ||
| return; | ||
| } | ||
| debug.enable(`${topicPrefix}:${topic}`); | ||
| } | ||
| function cleanupLogStreams() { | ||
| if (!isNodeEnv) | ||
| return; | ||
| for (const stream of logStreams.values()) { | ||
| stream.end(); | ||
| } | ||
| logStreams.clear(); | ||
| } | ||
| export { | ||
| cleanupLogStreams, | ||
| enableDebug, | ||
| getDebug | ||
| }; |
| type DebugFunction = (...args: unknown[]) => void; | ||
| declare function getDebug(topic: string): DebugFunction; | ||
| declare function enableDebug(topic: string): void; | ||
| declare function cleanupLogStreams(): void; | ||
| export { type DebugFunction, cleanupLogStreams, enableDebug, getDebug }; |
| "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 __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); | ||
| // src/logger.ts | ||
| var logger_exports = {}; | ||
| __export(logger_exports, { | ||
| cleanupLogStreams: () => cleanupLogStreams, | ||
| enableDebug: () => enableDebug, | ||
| getDebug: () => getDebug | ||
| }); | ||
| module.exports = __toCommonJS(logger_exports); | ||
| var import_node_fs2 = __toESM(require("fs")); | ||
| var import_node_path2 = __toESM(require("path")); | ||
| var import_debug = __toESM(require("debug")); | ||
| // src/common.ts | ||
| var import_node_fs = __toESM(require("fs")); | ||
| var import_node_path = __toESM(require("path")); | ||
| var isNodeEnv = typeof process !== "undefined" && process.versions != null && process.versions.node != null; | ||
| var getMidsceneRunLogPath = () => { | ||
| const basePath = import_node_path.default.join(process.cwd(), "midscene_run"); | ||
| if (!import_node_fs.default.existsSync(basePath)) { | ||
| import_node_fs.default.mkdirSync(basePath, { recursive: true }); | ||
| } | ||
| const logPath = import_node_path.default.join(basePath, "log"); | ||
| if (!import_node_fs.default.existsSync(logPath)) { | ||
| import_node_fs.default.mkdirSync(logPath, { recursive: true }); | ||
| } | ||
| return logPath; | ||
| }; | ||
| var logDir = isNodeEnv ? getMidsceneRunLogPath() : ""; | ||
| // src/logger.ts | ||
| var topicPrefix = "midscene"; | ||
| var logStreams = /* @__PURE__ */ new Map(); | ||
| function getLogStream(topic) { | ||
| const topicFileName = topic.replace(/:/g, "-"); | ||
| if (!logStreams.has(topicFileName)) { | ||
| const logFile = import_node_path2.default.join(logDir, `${topicFileName}.log`); | ||
| const stream = import_node_fs2.default.createWriteStream(logFile, { flags: "a" }); | ||
| logStreams.set(topicFileName, stream); | ||
| } | ||
| return logStreams.get(topicFileName); | ||
| } | ||
| function writeLogToFile(topic, message) { | ||
| if (!isNodeEnv) | ||
| return; | ||
| const stream = getLogStream(topic); | ||
| const timestamp = (/* @__PURE__ */ new Date()).toISOString(); | ||
| stream.write(`[${timestamp}] ${message} | ||
| `); | ||
| } | ||
| function getDebug(topic) { | ||
| return (...args) => { | ||
| const message = args.map( | ||
| (arg) => typeof arg === "object" ? JSON.stringify(arg) : String(arg) | ||
| ).join(" "); | ||
| if (isNodeEnv) { | ||
| writeLogToFile(topic, message); | ||
| } | ||
| const debugFn = (0, import_debug.default)(`${topicPrefix}:${topic}`); | ||
| debugFn(...args); | ||
| }; | ||
| } | ||
| function enableDebug(topic) { | ||
| if (isNodeEnv) { | ||
| return; | ||
| } | ||
| import_debug.default.enable(`${topicPrefix}:${topic}`); | ||
| } | ||
| function cleanupLogStreams() { | ||
| if (!isNodeEnv) | ||
| return; | ||
| for (const stream of logStreams.values()) { | ||
| stream.end(); | ||
| } | ||
| logStreams.clear(); | ||
| } | ||
| // Annotate the CommonJS export names for ESM import in node: | ||
| 0 && (module.exports = { | ||
| cleanupLogStreams, | ||
| enableDebug, | ||
| getDebug | ||
| }); |
| type DebugFunction = (...args: unknown[]) => void; | ||
| declare function getDebug(topic: string): DebugFunction; | ||
| declare function enableDebug(topic: string): void; | ||
| declare function cleanupLogStreams(): void; | ||
| export { type DebugFunction, cleanupLogStreams, enableDebug, getDebug }; |
| import fs from 'node:fs'; | ||
| import path from 'node:path'; | ||
| // Define locally for now to avoid import issues | ||
| export const isNodeEnv = | ||
| typeof process !== 'undefined' && | ||
| process.versions != null && | ||
| process.versions.node != null; | ||
| /** | ||
| * Get the path to the midscene_run directory or a subdirectory within it. | ||
| * Creates the directory if it doesn't exist. | ||
| * | ||
| * @param subdir - Optional subdirectory name (e.g., 'log', 'report') | ||
| * @returns The absolute path to the requested directory | ||
| */ | ||
| export const getMidsceneRunLogPath = (): string => { | ||
| const basePath = path.join(process.cwd(), 'midscene_run'); | ||
| // Create a base directory | ||
| if (!fs.existsSync(basePath)) { | ||
| fs.mkdirSync(basePath, { recursive: true }); | ||
| } | ||
| // Create a log directory | ||
| const logPath = path.join(basePath, 'log'); | ||
| if (!fs.existsSync(logPath)) { | ||
| fs.mkdirSync(logPath, { recursive: true }); | ||
| } | ||
| return logPath; | ||
| }; | ||
| export const logDir = isNodeEnv ? getMidsceneRunLogPath() : ''; |
| import fs from 'node:fs'; | ||
| import path from 'node:path'; | ||
| import debug from 'debug'; | ||
| import { isNodeEnv, logDir } from './common'; | ||
| const topicPrefix = 'midscene'; | ||
| // Map to store file streams | ||
| const logStreams = new Map<string, fs.WriteStream>(); | ||
| // Function to get or create a log stream | ||
| function getLogStream(topic: string): fs.WriteStream { | ||
| const topicFileName = topic.replace(/:/g, '-'); | ||
| if (!logStreams.has(topicFileName)) { | ||
| const logFile = path.join(logDir, `${topicFileName}.log`); | ||
| const stream = fs.createWriteStream(logFile, { flags: 'a' }); | ||
| logStreams.set(topicFileName, stream); | ||
| } | ||
| return logStreams.get(topicFileName)!; | ||
| } | ||
| // Function to write log to file | ||
| function writeLogToFile(topic: string, message: string): void { | ||
| if (!isNodeEnv) return; | ||
| const stream = getLogStream(topic); | ||
| const timestamp = new Date().toISOString(); | ||
| stream.write(`[${timestamp}] ${message}\n`); | ||
| } | ||
| export type DebugFunction = (...args: unknown[]) => void; | ||
| export function getDebug(topic: string): DebugFunction { | ||
| // Create a wrapper function that handles both file logging and debug output | ||
| return (...args: unknown[]): void => { | ||
| const message = args | ||
| .map((arg) => | ||
| typeof arg === 'object' ? JSON.stringify(arg) : String(arg), | ||
| ) | ||
| .join(' '); | ||
| if (isNodeEnv) { | ||
| writeLogToFile(topic, message); | ||
| } | ||
| const debugFn = debug(`${topicPrefix}:${topic}`) as DebugFunction; | ||
| debugFn(...args); | ||
| }; | ||
| } | ||
| export function enableDebug(topic: string): void { | ||
| if (isNodeEnv) { | ||
| // In Node.js, we don't need to enable debug as we're using file logging | ||
| return; | ||
| } | ||
| debug.enable(`${topicPrefix}:${topic}`); | ||
| } | ||
| // Cleanup function to close all log streams | ||
| export function cleanupLogStreams(): void { | ||
| if (!isNodeEnv) return; | ||
| for (const stream of logStreams.values()) { | ||
| stream.end(); | ||
| } | ||
| logStreams.clear(); | ||
| } |
@@ -75,3 +75,2 @@ // src/constants/index.ts | ||
| import { sha256 } from "js-sha256"; | ||
| import debug from "debug"; | ||
| var hashMap = {}; | ||
@@ -78,0 +77,0 @@ function generateHashId(rect, content = "") { |
@@ -196,3 +196,2 @@ // src/extractor/tree.ts | ||
| import { sha256 } from "js-sha256"; | ||
| import debug from "debug"; | ||
| var hashMap = {}; | ||
@@ -199,0 +198,0 @@ function generateHashId(rect, content = "") { |
+0
-1
@@ -8,3 +8,2 @@ // src/node/fs.ts | ||
| import { sha256 } from "js-sha256"; | ||
| import debug from "debug"; | ||
| var ifInBrowser = typeof window !== "undefined"; | ||
@@ -11,0 +10,0 @@ function assert(condition, message) { |
+7
-3
| import { Buffer } from 'node:buffer'; | ||
| import Jimp from 'jimp'; | ||
| import { R as Rect } from './index-305e7a7e.js'; | ||
| import { NodeType } from './constants.js'; | ||
| import { R as Rect } from './index-305e7a7e.js'; | ||
@@ -105,3 +105,7 @@ interface Size { | ||
| } | null>; | ||
| declare function paddingToMatchBlock(imageBase64: string, blockSize?: number): Promise<string>; | ||
| declare function jimpFromBase64(base64: string): Promise<Jimp>; | ||
| declare function paddingToMatchBlock(image: Jimp, blockSize?: number): Promise<Jimp>; | ||
| declare function paddingToMatchBlockByBase64(imageBase64: string, blockSize?: number): Promise<string>; | ||
| declare function cropByRect(imageBase64: string, rect: Rect, paddingImage: boolean): Promise<string>; | ||
| declare function jimpToBase64(image: Jimp): Promise<string>; | ||
@@ -153,2 +157,2 @@ type ElementType = { | ||
| export { base64Encoded, bufferFromBase64, compositeElementInfoImg, drawBoxOnImage, imageInfo, imageInfoOfBase64, paddingToMatchBlock, processImageElementInfo, resizeImg, resizeImgBase64, saveBase64Image, savePositionImg, transformImgPathToBase64, trimImage, zoomForGPT4o }; | ||
| export { base64Encoded, bufferFromBase64, compositeElementInfoImg, cropByRect, drawBoxOnImage, imageInfo, imageInfoOfBase64, jimpFromBase64, jimpToBase64, paddingToMatchBlock, paddingToMatchBlockByBase64, processImageElementInfo, resizeImg, resizeImgBase64, saveBase64Image, savePositionImg, transformImgPathToBase64, trimImage, zoomForGPT4o }; |
+33
-9
@@ -99,3 +99,3 @@ // src/img/info.ts | ||
| } | ||
| image.resize(newSize.width, newSize.height, Jimp.RESIZE_NEAREST_NEIGHBOR); | ||
| image.resize(newSize.width, newSize.height, Jimp.RESIZE_BICUBIC); | ||
| image.quality(90); | ||
@@ -173,7 +173,9 @@ const resizedBuffer = await image.getBufferAsync(Jimp.MIME_JPEG); | ||
| } | ||
| async function paddingToMatchBlock(imageBase64, blockSize = 28) { | ||
| async function jimpFromBase64(base64) { | ||
| const Jimp = await getJimp(); | ||
| const imageBuffer = await bufferFromBase642(base64); | ||
| return Jimp.read(imageBuffer); | ||
| } | ||
| async function paddingToMatchBlock(image, 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; | ||
@@ -183,10 +185,28 @@ const targetWidth = Math.ceil(width / blockSize) * blockSize; | ||
| if (targetWidth === width && targetHeight === height) { | ||
| return imageBase64; | ||
| return image; | ||
| } | ||
| const Jimp = await getJimp(); | ||
| 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; | ||
| return paddedImage; | ||
| } | ||
| async function paddingToMatchBlockByBase64(imageBase64, blockSize = 28) { | ||
| const jimpImage = await jimpFromBase64(imageBase64); | ||
| const paddedImage = await paddingToMatchBlock(jimpImage, blockSize); | ||
| return jimpToBase64(paddedImage); | ||
| } | ||
| async function cropByRect(imageBase64, rect, paddingImage) { | ||
| const jimpImage = await jimpFromBase64(imageBase64); | ||
| const { left, top, width, height } = rect; | ||
| jimpImage.crop(left, top, width, height); | ||
| if (paddingImage) { | ||
| const paddedImage = await paddingToMatchBlock(jimpImage); | ||
| return jimpToBase64(paddedImage); | ||
| } | ||
| return jimpToBase64(jimpImage); | ||
| } | ||
| async function jimpToBase64(image) { | ||
| const Jimp = await getJimp(); | ||
| return image.getBase64Async(Jimp.MIME_JPEG); | ||
| } | ||
@@ -417,6 +437,10 @@ // src/img/box-select.ts | ||
| compositeElementInfoImg, | ||
| cropByRect, | ||
| drawBoxOnImage, | ||
| imageInfo, | ||
| imageInfoOfBase64, | ||
| jimpFromBase64, | ||
| jimpToBase64, | ||
| paddingToMatchBlock, | ||
| paddingToMatchBlockByBase64, | ||
| processImageElementInfo, | ||
@@ -423,0 +447,0 @@ resizeImg, |
@@ -1,7 +0,3 @@ | ||
| 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; | ||
@@ -16,3 +12,5 @@ /** | ||
| declare function assert(condition: any, message?: string): asserts condition; | ||
| type GlobalScope = typeof window | typeof globalThis | typeof self | undefined; | ||
| declare function getGlobalScope(): GlobalScope; | ||
| export { assert, enableDebug, generateHashId, getDebug, ifInBrowser, uuid }; | ||
| export { assert, generateHashId, getGlobalScope, ifInBrowser, uuid }; |
+13
-10
| // src/utils.ts | ||
| import { sha256 } from "js-sha256"; | ||
| import debug from "debug"; | ||
| var ifInBrowser = typeof window !== "undefined"; | ||
@@ -9,9 +8,2 @@ 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 = "") { | ||
@@ -48,9 +40,20 @@ const combined = JSON.stringify({ | ||
| } | ||
| function getGlobalScope() { | ||
| if (typeof window !== "undefined") { | ||
| return window; | ||
| } | ||
| if (typeof globalThis !== "undefined") { | ||
| return globalThis; | ||
| } | ||
| if (typeof self !== "undefined") { | ||
| return self; | ||
| } | ||
| return void 0; | ||
| } | ||
| export { | ||
| assert, | ||
| enableDebug, | ||
| generateHashId, | ||
| getDebug, | ||
| getGlobalScope, | ||
| 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 __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 | ||
| )); | ||
@@ -99,3 +77,2 @@ // src/constants/index.ts | ||
| var import_js_sha256 = require("js-sha256"); | ||
| var import_debug = __toESM(require("debug")); | ||
| var hashMap = {}; | ||
@@ -102,0 +79,0 @@ function generateHashId(rect, content = "") { |
| "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; | ||
@@ -20,10 +18,2 @@ 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); | ||
@@ -239,3 +229,2 @@ | ||
| var import_js_sha256 = require("js-sha256"); | ||
| var import_debug = __toESM(require("debug")); | ||
| var hashMap = {}; | ||
@@ -242,0 +231,0 @@ function generateHashId(rect, content = "") { |
+0
-1
@@ -44,3 +44,2 @@ "use strict"; | ||
| var import_js_sha256 = require("js-sha256"); | ||
| var import_debug = __toESM(require("debug")); | ||
| var ifInBrowser = typeof window !== "undefined"; | ||
@@ -47,0 +46,0 @@ function assert(condition, message) { |
| import { Buffer } from 'node:buffer'; | ||
| import Jimp from 'jimp'; | ||
| import { R as Rect } from './index-305e7a7e.js'; | ||
| import { NodeType } from './constants.js'; | ||
| import { R as Rect } from './index-305e7a7e.js'; | ||
@@ -105,3 +105,7 @@ interface Size { | ||
| } | null>; | ||
| declare function paddingToMatchBlock(imageBase64: string, blockSize?: number): Promise<string>; | ||
| declare function jimpFromBase64(base64: string): Promise<Jimp>; | ||
| declare function paddingToMatchBlock(image: Jimp, blockSize?: number): Promise<Jimp>; | ||
| declare function paddingToMatchBlockByBase64(imageBase64: string, blockSize?: number): Promise<string>; | ||
| declare function cropByRect(imageBase64: string, rect: Rect, paddingImage: boolean): Promise<string>; | ||
| declare function jimpToBase64(image: Jimp): Promise<string>; | ||
@@ -153,2 +157,2 @@ type ElementType = { | ||
| export { base64Encoded, bufferFromBase64, compositeElementInfoImg, drawBoxOnImage, imageInfo, imageInfoOfBase64, paddingToMatchBlock, processImageElementInfo, resizeImg, resizeImgBase64, saveBase64Image, savePositionImg, transformImgPathToBase64, trimImage, zoomForGPT4o }; | ||
| export { base64Encoded, bufferFromBase64, compositeElementInfoImg, cropByRect, drawBoxOnImage, imageInfo, imageInfoOfBase64, jimpFromBase64, jimpToBase64, paddingToMatchBlock, paddingToMatchBlockByBase64, processImageElementInfo, resizeImg, resizeImgBase64, saveBase64Image, savePositionImg, transformImgPathToBase64, trimImage, zoomForGPT4o }; |
+37
-9
@@ -36,6 +36,10 @@ "use strict"; | ||
| compositeElementInfoImg: () => compositeElementInfoImg, | ||
| cropByRect: () => cropByRect, | ||
| drawBoxOnImage: () => drawBoxOnImage, | ||
| imageInfo: () => imageInfo, | ||
| imageInfoOfBase64: () => imageInfoOfBase64, | ||
| jimpFromBase64: () => jimpFromBase64, | ||
| jimpToBase64: () => jimpToBase64, | ||
| paddingToMatchBlock: () => paddingToMatchBlock, | ||
| paddingToMatchBlockByBase64: () => paddingToMatchBlockByBase64, | ||
| processImageElementInfo: () => processImageElementInfo, | ||
@@ -150,3 +154,3 @@ resizeImg: () => resizeImg, | ||
| } | ||
| image.resize(newSize.width, newSize.height, Jimp.RESIZE_NEAREST_NEIGHBOR); | ||
| image.resize(newSize.width, newSize.height, Jimp.RESIZE_BICUBIC); | ||
| image.quality(90); | ||
@@ -224,7 +228,9 @@ const resizedBuffer = await image.getBufferAsync(Jimp.MIME_JPEG); | ||
| } | ||
| async function paddingToMatchBlock(imageBase64, blockSize = 28) { | ||
| async function jimpFromBase64(base64) { | ||
| const Jimp = await getJimp(); | ||
| const imageBuffer = await bufferFromBase642(base64); | ||
| return Jimp.read(imageBuffer); | ||
| } | ||
| async function paddingToMatchBlock(image, 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; | ||
@@ -234,10 +240,28 @@ const targetWidth = Math.ceil(width / blockSize) * blockSize; | ||
| if (targetWidth === width && targetHeight === height) { | ||
| return imageBase64; | ||
| return image; | ||
| } | ||
| const Jimp = await getJimp(); | ||
| 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; | ||
| return paddedImage; | ||
| } | ||
| async function paddingToMatchBlockByBase64(imageBase64, blockSize = 28) { | ||
| const jimpImage = await jimpFromBase64(imageBase64); | ||
| const paddedImage = await paddingToMatchBlock(jimpImage, blockSize); | ||
| return jimpToBase64(paddedImage); | ||
| } | ||
| async function cropByRect(imageBase64, rect, paddingImage) { | ||
| const jimpImage = await jimpFromBase64(imageBase64); | ||
| const { left, top, width, height } = rect; | ||
| jimpImage.crop(left, top, width, height); | ||
| if (paddingImage) { | ||
| const paddedImage = await paddingToMatchBlock(jimpImage); | ||
| return jimpToBase64(paddedImage); | ||
| } | ||
| return jimpToBase64(jimpImage); | ||
| } | ||
| async function jimpToBase64(image) { | ||
| const Jimp = await getJimp(); | ||
| return image.getBase64Async(Jimp.MIME_JPEG); | ||
| } | ||
@@ -469,6 +493,10 @@ // src/img/box-select.ts | ||
| compositeElementInfoImg, | ||
| cropByRect, | ||
| drawBoxOnImage, | ||
| imageInfo, | ||
| imageInfoOfBase64, | ||
| jimpFromBase64, | ||
| jimpToBase64, | ||
| paddingToMatchBlock, | ||
| paddingToMatchBlockByBase64, | ||
| processImageElementInfo, | ||
@@ -475,0 +503,0 @@ resizeImg, |
@@ -1,7 +0,3 @@ | ||
| 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; | ||
@@ -16,3 +12,5 @@ /** | ||
| declare function assert(condition: any, message?: string): asserts condition; | ||
| type GlobalScope = typeof window | typeof globalThis | typeof self | undefined; | ||
| declare function getGlobalScope(): GlobalScope; | ||
| export { assert, enableDebug, generateHashId, getDebug, ifInBrowser, uuid }; | ||
| export { assert, generateHashId, getGlobalScope, ifInBrowser, uuid }; |
+14
-22
| "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; | ||
@@ -20,10 +18,2 @@ 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); | ||
@@ -35,5 +25,4 @@ | ||
| assert: () => assert, | ||
| enableDebug: () => enableDebug, | ||
| generateHashId: () => generateHashId, | ||
| getDebug: () => getDebug, | ||
| getGlobalScope: () => getGlobalScope, | ||
| ifInBrowser: () => ifInBrowser, | ||
@@ -44,3 +33,2 @@ uuid: () => uuid | ||
| var import_js_sha256 = require("js-sha256"); | ||
| var import_debug = __toESM(require("debug")); | ||
| var ifInBrowser = typeof window !== "undefined"; | ||
@@ -51,9 +39,2 @@ 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 = "") { | ||
@@ -90,10 +71,21 @@ const combined = JSON.stringify({ | ||
| } | ||
| function getGlobalScope() { | ||
| if (typeof window !== "undefined") { | ||
| return window; | ||
| } | ||
| if (typeof globalThis !== "undefined") { | ||
| return globalThis; | ||
| } | ||
| if (typeof self !== "undefined") { | ||
| return self; | ||
| } | ||
| return void 0; | ||
| } | ||
| // Annotate the CommonJS export names for ESM import in node: | ||
| 0 && (module.exports = { | ||
| assert, | ||
| enableDebug, | ||
| generateHashId, | ||
| getDebug, | ||
| getGlobalScope, | ||
| ifInBrowser, | ||
| uuid | ||
| }); |
@@ -573,468 +573,2 @@ "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 | ||
@@ -1114,3 +648,2 @@ var CONTAINER_MINI_HEIGHT = 3; | ||
| var import_js_sha256 = __toESM(require_sha256()); | ||
| var import_debug = __toESM(require_browser()); | ||
| var hashMap = {}; | ||
@@ -1117,0 +650,0 @@ function generateHashId(rect, content = "") { |
| import { Buffer } from 'node:buffer'; | ||
| import Jimp from 'jimp'; | ||
| import { R as Rect } from './index-305e7a7e.js'; | ||
| import { NodeType } from './constants.js'; | ||
| import { R as Rect } from './index-305e7a7e.js'; | ||
@@ -105,3 +105,7 @@ interface Size { | ||
| } | null>; | ||
| declare function paddingToMatchBlock(imageBase64: string, blockSize?: number): Promise<string>; | ||
| declare function jimpFromBase64(base64: string): Promise<Jimp>; | ||
| declare function paddingToMatchBlock(image: Jimp, blockSize?: number): Promise<Jimp>; | ||
| declare function paddingToMatchBlockByBase64(imageBase64: string, blockSize?: number): Promise<string>; | ||
| declare function cropByRect(imageBase64: string, rect: Rect, paddingImage: boolean): Promise<string>; | ||
| declare function jimpToBase64(image: Jimp): Promise<string>; | ||
@@ -153,2 +157,2 @@ type ElementType = { | ||
| export { base64Encoded, bufferFromBase64, compositeElementInfoImg, drawBoxOnImage, imageInfo, imageInfoOfBase64, paddingToMatchBlock, processImageElementInfo, resizeImg, resizeImgBase64, saveBase64Image, savePositionImg, transformImgPathToBase64, trimImage, zoomForGPT4o }; | ||
| export { base64Encoded, bufferFromBase64, compositeElementInfoImg, cropByRect, drawBoxOnImage, imageInfo, imageInfoOfBase64, jimpFromBase64, jimpToBase64, paddingToMatchBlock, paddingToMatchBlockByBase64, processImageElementInfo, resizeImg, resizeImgBase64, saveBase64Image, savePositionImg, transformImgPathToBase64, trimImage, zoomForGPT4o }; |
@@ -1,7 +0,3 @@ | ||
| 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; | ||
@@ -16,3 +12,5 @@ /** | ||
| declare function assert(condition: any, message?: string): asserts condition; | ||
| type GlobalScope = typeof window | typeof globalThis | typeof self | undefined; | ||
| declare function getGlobalScope(): GlobalScope; | ||
| export { assert, enableDebug, generateHashId, getDebug, ifInBrowser, uuid }; | ||
| export { assert, generateHashId, getGlobalScope, ifInBrowser, uuid }; |
+9
-5
| { | ||
| "name": "@aico-test/shared", | ||
| "version": "7.0.0", | ||
| "types": "./src/index.ts", | ||
| "type": "commonjs", | ||
| "version": "8.0.0", | ||
| "types": "./dist/types/index.d.ts", | ||
| "main": "./dist/lib/index.js", | ||
@@ -16,3 +15,4 @@ "module": "./dist/es/index.js", | ||
| "./extractor-debug": "./dist/lib/extractor-debug.js", | ||
| "./keyboard-layout": "./dist/lib/us-keyboard-layout.js" | ||
| "./keyboard-layout": "./dist/lib/us-keyboard-layout.js", | ||
| "./logger": "./dist/lib/logger.js" | ||
| }, | ||
@@ -44,2 +44,5 @@ "typesVersions": { | ||
| "./dist/types/us-keyboard-layout.d.ts" | ||
| ], | ||
| "logger": [ | ||
| "./dist/types/logger.d.ts" | ||
| ] | ||
@@ -81,4 +84,5 @@ } | ||
| "@types/node": "^18.0.0", | ||
| "dotenv": "16.4.5", | ||
| "rimraf": "~3.0.2", | ||
| "typescript": "~5.0.4", | ||
| "typescript": "^5.8.2", | ||
| "vitest": "3.0.5" | ||
@@ -85,0 +89,0 @@ }, |
| import type { ElementInfo } from './'; | ||
| import { NodeType } from './constants'; | ||
| import { generateId, midsceneGenerateHash } from './util'; | ||
| import { midsceneGenerateHash } from './util'; | ||
| // https://github.com/appium/appium/tree/master/packages/universal-xml-plugin | ||
| // Definition of NodeDescriptor interface | ||
@@ -7,0 +6,0 @@ interface NodeDescriptor { |
+4
-0
@@ -15,4 +15,8 @@ export { | ||
| paddingToMatchBlock, | ||
| paddingToMatchBlockByBase64, | ||
| cropByRect, | ||
| jimpFromBase64, | ||
| jimpToBase64, | ||
| } from './transform'; | ||
| export { processImageElementInfo, compositeElementInfoImg } from './box-select'; | ||
| export { drawBoxOnImage, savePositionImg } from './draw-box'; |
+46
-10
| import assert from 'node:assert'; | ||
| import { Buffer } from 'node:buffer'; | ||
| import getDebug from 'debug'; | ||
| import type Jimp from 'jimp'; | ||
| import type { Rect } from 'src/types'; | ||
| import getJimp from './get-jimp'; | ||
| const debugImg = getDebug('img'); | ||
@@ -86,3 +88,3 @@ /** | ||
| image.resize(newSize.width, newSize.height, Jimp.RESIZE_NEAREST_NEIGHBOR); | ||
| image.resize(newSize.width, newSize.height, Jimp.RESIZE_BICUBIC); | ||
| image.quality(90); | ||
@@ -214,7 +216,14 @@ const resizedBuffer = await image.getBufferAsync(Jimp.MIME_JPEG); | ||
| export async function paddingToMatchBlock(imageBase64: string, blockSize = 28) { | ||
| export async function jimpFromBase64(base64: string): Promise<Jimp> { | ||
| const Jimp = await getJimp(); | ||
| const imageBuffer = await bufferFromBase64(base64); | ||
| return Jimp.read(imageBuffer); | ||
| } | ||
| // https://help.aliyun.com/zh/model-studio/user-guide/vision/ | ||
| export async function paddingToMatchBlock( | ||
| image: Jimp, | ||
| blockSize = 28, | ||
| ): Promise<Jimp> { | ||
| debugImg('paddingToMatchBlock start'); | ||
| const Jimp = await getJimp(); | ||
| const imageBuffer = await bufferFromBase64(imageBase64); | ||
| const image = await Jimp.read(imageBuffer); | ||
| const { width, height } = image.bitmap; | ||
@@ -226,5 +235,6 @@ | ||
| if (targetWidth === width && targetHeight === height) { | ||
| return imageBase64; | ||
| return image; | ||
| } | ||
| const Jimp = await getJimp(); | ||
| const paddedImage = new Jimp(targetWidth, targetHeight, 0xffffffff); | ||
@@ -234,6 +244,32 @@ | ||
| paddedImage.composite(image, 0, 0); | ||
| return paddedImage; | ||
| } | ||
| const base64 = await paddedImage.getBase64Async(Jimp.MIME_JPEG); | ||
| debugImg('paddingToMatchBlock done'); | ||
| return base64; | ||
| export async function paddingToMatchBlockByBase64( | ||
| imageBase64: string, | ||
| blockSize = 28, | ||
| ): Promise<string> { | ||
| const jimpImage = await jimpFromBase64(imageBase64); | ||
| const paddedImage = await paddingToMatchBlock(jimpImage, blockSize); | ||
| return jimpToBase64(paddedImage); | ||
| } | ||
| export async function cropByRect( | ||
| imageBase64: string, | ||
| rect: Rect, | ||
| paddingImage: boolean, | ||
| ): Promise<string> { | ||
| const jimpImage = await jimpFromBase64(imageBase64); | ||
| const { left, top, width, height } = rect; | ||
| jimpImage.crop(left, top, width, height); | ||
| if (paddingImage) { | ||
| const paddedImage = await paddingToMatchBlock(jimpImage); | ||
| return jimpToBase64(paddedImage); | ||
| } | ||
| return jimpToBase64(jimpImage); | ||
| } | ||
| export async function jimpToBase64(image: Jimp): Promise<string> { | ||
| const Jimp = await getJimp(); | ||
| return image.getBase64Async(Jimp.MIME_JPEG); | ||
| } |
+20
-14
| import { sha256 } from 'js-sha256'; | ||
| import debug from 'debug'; | ||
| export const ifInBrowser = typeof window !== 'undefined'; | ||
| export function uuid() { | ||
| export function uuid(): string { | ||
| return Math.random().toString(36).substring(2, 15); | ||
@@ -13,12 +11,3 @@ } | ||
| 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 = '') { | ||
| export function generateHashId(rect: any, content = ''): string { | ||
| // Combine the input into a string | ||
@@ -36,3 +25,3 @@ const combined = JSON.stringify({ | ||
| // Convert hex to a-z by mapping each hex char to a letter | ||
| const toLetters = (hex: string) => { | ||
| const toLetters = (hex: string): string => { | ||
| return hex | ||
@@ -73,1 +62,18 @@ .split('') | ||
| } | ||
| type GlobalScope = typeof window | typeof globalThis | typeof self | undefined; | ||
| export function getGlobalScope(): GlobalScope { | ||
| if (typeof window !== 'undefined') { | ||
| return window; | ||
| } | ||
| if (typeof globalThis !== 'undefined') { | ||
| return globalThis; | ||
| } | ||
| if (typeof self !== 'undefined') { | ||
| return self; | ||
| } | ||
| return undefined; | ||
| } |
Sorry, the diff of this file is too big to display
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
76
10.14%426746
-4.24%7
16.67%12296
-4.58%9
28.57%