@midscene/shared
Advanced tools
Comparing version 0.10.5 to 0.10.6-beta-20250207060931.0
import { Buffer } from 'node:buffer'; | ||
import Jimp from 'jimp'; | ||
import { NodeType } from './constants.js'; | ||
import { R as Rect } from './index-305e7a7e.js'; | ||
interface Size$1 { | ||
interface Size { | ||
width: number; | ||
@@ -10,3 +11,3 @@ height: number; | ||
} | ||
interface ImageInfo extends Size$1 { | ||
interface ImageInfo extends Size { | ||
jimpImage: Jimp; | ||
@@ -107,12 +108,2 @@ } | ||
interface Point { | ||
left: number; | ||
top: number; | ||
} | ||
interface Size { | ||
width: number; | ||
height: number; | ||
} | ||
type Rect = Point & Size; | ||
type ElementType = { | ||
@@ -119,0 +110,0 @@ locator?: string; |
@@ -176,3 +176,3 @@ "use strict"; | ||
); | ||
image.quality(75); | ||
image.quality(90); | ||
const resizedBuffer = yield image.getBufferAsync(Jimp.MIME_JPEG); | ||
@@ -381,3 +381,3 @@ return resizedBuffer; | ||
})).then((compositeImage) => __async(void 0, null, function* () { | ||
compositeImage.quality(75); | ||
compositeImage.quality(90); | ||
const base64 = yield compositeImage.getBase64Async(Jimp.MIME_JPEG); | ||
@@ -438,3 +438,3 @@ return base64; | ||
); | ||
image.quality(75); | ||
image.quality(90); | ||
const resultBase64 = yield image.getBase64Async(Jimp.MIME_JPEG); | ||
@@ -441,0 +441,0 @@ return resultBase64; |
declare const ifInBrowser: boolean; | ||
declare function uuid(): string; | ||
declare function getFrameId(): number; | ||
declare function setFrameId(id: number): void; | ||
declare function generateHashId(rect: any, content?: string): string; | ||
export { generateHashId, getFrameId, ifInBrowser, setFrameId, uuid }; | ||
export { generateHashId, ifInBrowser, uuid }; |
@@ -564,5 +564,3 @@ "use strict"; | ||
generateHashId: () => generateHashId, | ||
getFrameId: () => getFrameId, | ||
ifInBrowser: () => ifInBrowser, | ||
setFrameId: () => setFrameId, | ||
uuid: () => uuid | ||
@@ -577,20 +575,19 @@ }); | ||
var hashMap = {}; | ||
var frameId = 0; | ||
function getFrameId() { | ||
return frameId; | ||
} | ||
function setFrameId(id) { | ||
frameId = id; | ||
} | ||
function generateHashId(rect, content = "") { | ||
const combined = JSON.stringify({ | ||
content, | ||
rect, | ||
_midscene_frame_id: getFrameId() | ||
rect | ||
}); | ||
let sliceLength = 8; | ||
let sliceLength = 5; | ||
let slicedHash = ""; | ||
const hashHex = import_js_sha256.sha256.create().update(combined).hex(); | ||
while (sliceLength < hashHex.length - 1) { | ||
slicedHash = hashHex.slice(0, sliceLength); | ||
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) { | ||
@@ -597,0 +594,0 @@ sliceLength++; |
import { Buffer } from 'node:buffer'; | ||
import Jimp from 'jimp'; | ||
import { NodeType } from './constants.js'; | ||
import { R as Rect } from './index-305e7a7e.js'; | ||
interface Size$1 { | ||
interface Size { | ||
width: number; | ||
@@ -10,3 +11,3 @@ height: number; | ||
} | ||
interface ImageInfo extends Size$1 { | ||
interface ImageInfo extends Size { | ||
jimpImage: Jimp; | ||
@@ -107,12 +108,2 @@ } | ||
interface Point { | ||
left: number; | ||
top: number; | ||
} | ||
interface Size { | ||
width: number; | ||
height: number; | ||
} | ||
type Rect = Point & Size; | ||
type ElementType = { | ||
@@ -119,0 +110,0 @@ locator?: string; |
@@ -127,3 +127,3 @@ var __pow = Math.pow; | ||
); | ||
image.quality(75); | ||
image.quality(90); | ||
const resizedBuffer = yield image.getBufferAsync(Jimp.MIME_JPEG); | ||
@@ -332,3 +332,3 @@ return resizedBuffer; | ||
})).then((compositeImage) => __async(void 0, null, function* () { | ||
compositeImage.quality(75); | ||
compositeImage.quality(90); | ||
const base64 = yield compositeImage.getBase64Async(Jimp.MIME_JPEG); | ||
@@ -389,3 +389,3 @@ return base64; | ||
); | ||
image.quality(75); | ||
image.quality(90); | ||
const resultBase64 = yield image.getBase64Async(Jimp.MIME_JPEG); | ||
@@ -392,0 +392,0 @@ return resultBase64; |
declare const ifInBrowser: boolean; | ||
declare function uuid(): string; | ||
declare function getFrameId(): number; | ||
declare function setFrameId(id: number): void; | ||
declare function generateHashId(rect: any, content?: string): string; | ||
export { generateHashId, getFrameId, ifInBrowser, setFrameId, uuid }; | ||
export { generateHashId, ifInBrowser, uuid }; |
@@ -560,20 +560,19 @@ var __create = Object.create; | ||
var hashMap = {}; | ||
var frameId = 0; | ||
function getFrameId() { | ||
return frameId; | ||
} | ||
function setFrameId(id) { | ||
frameId = id; | ||
} | ||
function generateHashId(rect, content = "") { | ||
const combined = JSON.stringify({ | ||
content, | ||
rect, | ||
_midscene_frame_id: getFrameId() | ||
rect | ||
}); | ||
let sliceLength = 8; | ||
let sliceLength = 5; | ||
let slicedHash = ""; | ||
const hashHex = import_js_sha256.sha256.create().update(combined).hex(); | ||
while (sliceLength < hashHex.length - 1) { | ||
slicedHash = hashHex.slice(0, sliceLength); | ||
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) { | ||
@@ -590,5 +589,3 @@ sliceLength++; | ||
generateHashId, | ||
getFrameId, | ||
ifInBrowser, | ||
setFrameId, | ||
uuid | ||
@@ -595,0 +592,0 @@ }; |
import { Buffer } from 'node:buffer'; | ||
import Jimp from 'jimp'; | ||
import { NodeType } from './constants.js'; | ||
import { R as Rect } from './index-305e7a7e.js'; | ||
interface Size$1 { | ||
interface Size { | ||
width: number; | ||
@@ -10,3 +11,3 @@ height: number; | ||
} | ||
interface ImageInfo extends Size$1 { | ||
interface ImageInfo extends Size { | ||
jimpImage: Jimp; | ||
@@ -107,12 +108,2 @@ } | ||
interface Point { | ||
left: number; | ||
top: number; | ||
} | ||
interface Size { | ||
width: number; | ||
height: number; | ||
} | ||
type Rect = Point & Size; | ||
type ElementType = { | ||
@@ -119,0 +110,0 @@ locator?: string; |
@@ -176,3 +176,3 @@ "use strict"; | ||
); | ||
image.quality(75); | ||
image.quality(90); | ||
const resizedBuffer = yield image.getBufferAsync(Jimp.MIME_JPEG); | ||
@@ -381,3 +381,3 @@ return resizedBuffer; | ||
})).then((compositeImage) => __async(void 0, null, function* () { | ||
compositeImage.quality(75); | ||
compositeImage.quality(90); | ||
const base64 = yield compositeImage.getBase64Async(Jimp.MIME_JPEG); | ||
@@ -438,3 +438,3 @@ return base64; | ||
); | ||
image.quality(75); | ||
image.quality(90); | ||
const resultBase64 = yield image.getBase64Async(Jimp.MIME_JPEG); | ||
@@ -441,0 +441,0 @@ return resultBase64; |
declare const ifInBrowser: boolean; | ||
declare function uuid(): string; | ||
declare function getFrameId(): number; | ||
declare function setFrameId(id: number): void; | ||
declare function generateHashId(rect: any, content?: string): string; | ||
export { generateHashId, getFrameId, ifInBrowser, setFrameId, uuid }; | ||
export { generateHashId, ifInBrowser, uuid }; |
@@ -556,5 +556,3 @@ "use strict"; | ||
generateHashId: () => generateHashId, | ||
getFrameId: () => getFrameId, | ||
ifInBrowser: () => ifInBrowser, | ||
setFrameId: () => setFrameId, | ||
uuid: () => uuid | ||
@@ -569,20 +567,19 @@ }); | ||
var hashMap = {}; | ||
var frameId = 0; | ||
function getFrameId() { | ||
return frameId; | ||
} | ||
function setFrameId(id) { | ||
frameId = id; | ||
} | ||
function generateHashId(rect, content = "") { | ||
const combined = JSON.stringify({ | ||
content, | ||
rect, | ||
_midscene_frame_id: getFrameId() | ||
rect | ||
}); | ||
let sliceLength = 8; | ||
let sliceLength = 5; | ||
let slicedHash = ""; | ||
const hashHex = import_js_sha256.sha256.create().update(combined).hex(); | ||
while (sliceLength < hashHex.length - 1) { | ||
slicedHash = hashHex.slice(0, sliceLength); | ||
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) { | ||
@@ -600,5 +597,3 @@ sliceLength++; | ||
generateHashId, | ||
getFrameId, | ||
ifInBrowser, | ||
setFrameId, | ||
uuid | ||
@@ -605,0 +600,0 @@ }); |
{ | ||
"name": "@midscene/shared", | ||
"version": "0.10.5", | ||
"version": "0.10.6-beta-20250207060931.0", | ||
"repository": "https://github.com/web-infra-dev/midscene", | ||
@@ -41,2 +41,12 @@ "homepage": "https://midscenejs.com/", | ||
}, | ||
"./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": { | ||
@@ -68,2 +78,8 @@ "types": "./dist/lib/us-keyboard-layout.d.ts", | ||
], | ||
"extractor": [ | ||
"./dist/lib/extractor.d.ts" | ||
], | ||
"extractor-debug": [ | ||
"./dist/lib/extractor-debug.d.ts" | ||
], | ||
"keyboard-layout": [ | ||
@@ -98,3 +114,5 @@ "./dist/lib/us-keyboard-layout.d.ts" | ||
"dev": "modern dev", | ||
"build": "modern build", | ||
"build": "npm run build:pkg && npm run build:script", | ||
"build:pkg": "modern build -c ./modern.config.ts", | ||
"build:script": "modern build -c ./modern.inspect.config.ts", | ||
"build:watch": "modern build -w", | ||
@@ -101,0 +119,0 @@ "reset": "rimraf ./**/node_modules", |
import assert from 'node:assert'; | ||
import type { Buffer } from 'node:buffer'; | ||
import type { Rect } from '@/types'; | ||
import type Jimp from 'jimp'; | ||
import type { NodeType } from '../constants'; | ||
import type { Rect } from '../types'; | ||
import getJimp from './get-jimp'; | ||
@@ -241,3 +241,3 @@ import { bufferFromBase64, imageInfo, imageInfoOfBase64 } from './index'; | ||
.then(async (compositeImage: Jimp) => { | ||
compositeImage.quality(75); | ||
compositeImage.quality(90); | ||
const base64 = await compositeImage.getBase64Async(Jimp.MIME_JPEG); | ||
@@ -244,0 +244,0 @@ return base64; |
@@ -1,3 +0,2 @@ | ||
import type { Buffer } from 'node:buffer'; | ||
import type { Rect } from '@/types'; | ||
import type { Rect } from '../types'; | ||
import getJimp from './get-jimp'; | ||
@@ -44,3 +43,3 @@ import { bufferFromBase64 } from './info'; | ||
// Convert back to base64 | ||
image.quality(75); | ||
image.quality(90); | ||
const resultBase64 = await image.getBase64Async(Jimp.MIME_JPEG); | ||
@@ -47,0 +46,0 @@ return resultBase64; |
@@ -75,3 +75,3 @@ import { Buffer } from 'node:buffer'; | ||
); | ||
image.quality(75); | ||
image.quality(90); | ||
const resizedBuffer = await image.getBufferAsync(Jimp.MIME_JPEG); | ||
@@ -78,0 +78,0 @@ |
@@ -0,1 +1,3 @@ | ||
import type { NodeType } from '../constants'; | ||
export interface Point { | ||
@@ -7,6 +9,33 @@ left: number; | ||
export interface Size { | ||
width: number; | ||
width: number; // device independent window size | ||
height: number; | ||
dpr?: number; // the scale factor of the screenshots | ||
} | ||
export type Rect = Point & Size; | ||
export type Rect = Point & Size & { zoom?: number }; | ||
export abstract class BaseElement { | ||
abstract id: string; | ||
abstract indexId?: number; // markerId for web | ||
abstract attributes: { | ||
nodeType: NodeType; | ||
[key: string]: string; | ||
}; | ||
abstract content: string; | ||
abstract rect: Rect; | ||
abstract center: [number, number]; | ||
abstract locator?: string; | ||
} | ||
export interface ElementTreeNode< | ||
ElementType extends BaseElement = BaseElement, | ||
> { | ||
node: ElementType | null; | ||
children: ElementTreeNode<ElementType>[]; | ||
} |
@@ -11,12 +11,2 @@ import { sha256 } from 'js-sha256'; | ||
let frameId = 0; | ||
export function getFrameId(): number { | ||
return frameId; | ||
} | ||
export function setFrameId(id: number) { | ||
frameId = id; | ||
} | ||
export function generateHashId(rect: any, content = '') { | ||
@@ -27,11 +17,24 @@ // Combine the input into a string | ||
rect, | ||
_midscene_frame_id: getFrameId(), | ||
}); | ||
// Generates the sha-256 hash value | ||
let sliceLength = 8; | ||
// Generates the sha-256 hash value and converts to a-z chars | ||
let sliceLength = 5; | ||
let slicedHash = ''; | ||
const hashHex = sha256.create().update(combined).hex(); | ||
while (sliceLength < hashHex.length - 1) { | ||
slicedHash = hashHex.slice(0, sliceLength); | ||
// Convert hex to a-z by mapping each hex char to a letter | ||
const toLetters = (hex: string) => { | ||
return hex | ||
.split('') | ||
.map((char) => { | ||
const code = Number.parseInt(char, 16); | ||
return String.fromCharCode(97 + (code % 26)); // 97 is 'a' in ASCII | ||
}) | ||
.join(''); | ||
}; | ||
const hashLetters = toLetters(hashHex); | ||
while (sliceLength < hashLetters.length - 1) { | ||
slicedHash = hashLetters.slice(0, sliceLength); | ||
if (hashMap[slicedHash] && hashMap[slicedHash] !== combined) { | ||
@@ -38,0 +41,0 @@ sliceLength++; |
706992
79
19648
34
16