webmarker-js 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +2 -2
- package/dist/{types.d.ts → index.d.ts} +8 -8
- package/dist/main.js +1021 -274
- package/dist/module.js +1015 -282
- package/esbuild.config.js +28 -0
- package/package.json +10 -10
- package/src/index.ts +3 -3
- package/test-results/.last-run.json +4 -0
- package/dist/main.js.map +0 -1
- package/dist/module.js.map +0 -1
- package/dist/types.d.ts.map +0 -1
@@ -0,0 +1,28 @@
|
|
1
|
+
const esbuild = require("esbuild");
|
2
|
+
const { dtsPlugin } = require("esbuild-plugin-d.ts");
|
3
|
+
|
4
|
+
esbuild
|
5
|
+
.build({
|
6
|
+
entryPoints: ["src/index.ts"],
|
7
|
+
bundle: true,
|
8
|
+
outfile: "dist/main.js",
|
9
|
+
format: "iife",
|
10
|
+
globalName: "WebMarker",
|
11
|
+
platform: "browser",
|
12
|
+
target: ["es2015"],
|
13
|
+
plugins: [dtsPlugin()],
|
14
|
+
jsx: "transform",
|
15
|
+
})
|
16
|
+
.catch(() => process.exit(1));
|
17
|
+
|
18
|
+
esbuild
|
19
|
+
.build({
|
20
|
+
entryPoints: ["src/index.ts"],
|
21
|
+
bundle: true,
|
22
|
+
outfile: "dist/module.js",
|
23
|
+
format: "esm",
|
24
|
+
platform: "browser",
|
25
|
+
target: ["es2015"],
|
26
|
+
jsx: "transform",
|
27
|
+
})
|
28
|
+
.catch(() => process.exit(1));
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "webmarker-js",
|
3
|
-
"version": "0.0.
|
3
|
+
"version": "0.0.5",
|
4
4
|
"description": "A library for marking web pages for Set-of-Mark (SoM) prompting with vision-language models.",
|
5
5
|
"source": "src/index.ts",
|
6
6
|
"main": "dist/main.js",
|
@@ -8,12 +8,13 @@
|
|
8
8
|
"types": "dist/types.d.ts",
|
9
9
|
"scripts": {
|
10
10
|
"test": "jest",
|
11
|
-
"build": "
|
12
|
-
"demo:start": "
|
13
|
-
"demo:build": "
|
11
|
+
"build": "node esbuild.config.js",
|
12
|
+
"demo:start": "esbuild demo/index.js --bundle --servedir=demo --outdir=demo/dist --loader:.js=jsx",
|
13
|
+
"demo:build": "esbuild demo/index.js --bundle --minify --outdir=demo/dist",
|
14
14
|
"docs:dev": "cd docs && next",
|
15
15
|
"docs:build": "cd docs && next build",
|
16
|
-
"docs:start": "cd docs && next start"
|
16
|
+
"docs:start": "cd docs && next start",
|
17
|
+
"test:playwright": "cd test/playwright && npx playwright test"
|
17
18
|
},
|
18
19
|
"author": "Reid Barber",
|
19
20
|
"license": "MIT",
|
@@ -24,19 +25,18 @@
|
|
24
25
|
"@mdx-js/loader": "^3.0.1",
|
25
26
|
"@mdx-js/react": "^3.0.1",
|
26
27
|
"@next/mdx": "^14.2.3",
|
27
|
-
"@
|
28
|
-
"@parcel/transformer-typescript-tsc": "^2.12.0",
|
29
|
-
"@parcel/transformer-typescript-types": "2.12.0",
|
30
|
-
"@parcel/validator-typescript": "^2.12.0",
|
28
|
+
"@playwright/test": "^1.46.1",
|
31
29
|
"@types/mdx": "^2.0.13",
|
30
|
+
"@types/node": "^22.5.1",
|
32
31
|
"autoprefixer": "^10.4.19",
|
33
32
|
"babel-jest": "^29.7.0",
|
33
|
+
"esbuild": "^0.23.1",
|
34
|
+
"esbuild-plugin-d.ts": "^1.3.0",
|
34
35
|
"jest": "^29.7.0",
|
35
36
|
"jest-environment-jsdom": "^29.7.0",
|
36
37
|
"next": "^14.2.3",
|
37
38
|
"nextra": "^2.13.4",
|
38
39
|
"nextra-theme-docs": "^2.13.4",
|
39
|
-
"parcel": "^2.12.0",
|
40
40
|
"postcss": "^8.4.38",
|
41
41
|
"process": "^0.11.10",
|
42
42
|
"react": "^18.3.1",
|
package/src/index.ts
CHANGED
@@ -74,7 +74,7 @@ let cleanupFns: (() => void)[] = [];
|
|
74
74
|
|
75
75
|
async function mark(
|
76
76
|
options: MarkOptions = {}
|
77
|
-
): Promise<
|
77
|
+
): Promise<Record<string, MarkedElement>> {
|
78
78
|
const {
|
79
79
|
selector = "button, input, a, select, textarea",
|
80
80
|
markStyle = {
|
@@ -101,7 +101,7 @@ async function mark(
|
|
101
101
|
(el) => !viewPortOnly || el.getBoundingClientRect().top < window.innerHeight
|
102
102
|
);
|
103
103
|
|
104
|
-
const markedElements
|
104
|
+
const markedElements: Record<string, MarkedElement> = {};
|
105
105
|
|
106
106
|
await Promise.all(
|
107
107
|
elements.map(async (element, index) => {
|
@@ -112,7 +112,7 @@ async function mark(
|
|
112
112
|
? createMask(element, maskStyle, label)
|
113
113
|
: undefined;
|
114
114
|
|
115
|
-
markedElements
|
115
|
+
markedElements[label] = { element, markElement, maskElement };
|
116
116
|
element.setAttribute("data-webmarkeredby", `webmarker-${label}`);
|
117
117
|
})
|
118
118
|
);
|
package/dist/main.js.map
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"mappings":";;;;;;;;;;;A,I,kC,a,U,S,I,S,O,E,U,E,C,E,S;I,S,M,K;Q,O,iB,I,Q,I,E,S,O;Y,Q;Q;I;I,O,I,C,K,C,I,O,C,E,S,O,E,M;Q,S,U,K;Y,I;gB,K,U,I,C;Y,E,O,G;gB,O;Y;Q;Q,S,S,K;Y,I;gB,K,S,C,Q,C;Y,E,O,G;gB,O;Y;Q;Q,S,K,M;Y,O,I,G,Q,O,K,I,M,O,K,E,I,C,W;Q;Q,K,A,C,Y,U,K,C,S,c,E,C,E,I;I;A;A,I,oC,a,U,W,I,S,O,E,I;I,I,I;Q,O;Q,M;Y,I,C,C,E,G,G,M,C,C,E;Y,O,C,C,E;Q;Q,M,E;Q,K,E;I,G,G,G,G;I,O,I;Q,M,K;Q,S,K;Q,U,K;I,G,O,W,c,C,C,C,O,Q,C,G;Q,O,I;I,C,G;I,S,K,C;Q,O,S,C;Y,O,K;gB;gB;a;Q;I;I,S,K,E;Q,I,G,M,I,U;Q,M,K,C,I,G,E,C,E,I,C,I,C,C,G,E,I;Y,I,I,G,K,C,I,E,C,E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AEA,SAAS;IACP,OAAO,SAAS,eAAe,CAAC,YAAY,CAAC;AAC/C;AAEA,MAAM,CAAC,OAAO,GAAG;AACjB,MAAM,CAAC,SAAS,GAAG;AACnB,MAAM,CAAC,WAAW,GAAG","sources":["src/index.ts"],"sourcesContent":["import { autoUpdate, computePosition } from \"@floating-ui/dom\";\n\ntype Placement =\n | \"top\"\n | \"top-start\"\n | \"top-end\"\n | \"right\"\n | \"right-start\"\n | \"right-end\"\n | \"bottom\"\n | \"bottom-start\"\n | \"bottom-end\"\n | \"left\"\n | \"left-start\"\n | \"left-end\";\n\ninterface MarkOptions {\n /**\n * A CSS selector to specify the elements to be marked.\n */\n selector?: string;\n /**\n * A CSS style to apply to the label element.\n * You can also specify a function that returns a CSS style object.\n */\n markStyle?:\n | Readonly<Partial<CSSStyleDeclaration>>\n | ((element: Element) => Readonly<Partial<CSSStyleDeclaration>>);\n /**\n * The placement of the mark relative to the element.\n *\n * @default 'top-start'\n */\n markPlacement?: Placement;\n /**\n * A CSS style to apply to the bounding box element.\n * You can also specify a function that returns a CSS style object.\n * Bounding boxes are only shown if `showMasks` is `true`.\n */\n maskStyle?:\n | Readonly<Partial<CSSStyleDeclaration>>\n | ((element: Element) => Readonly<Partial<CSSStyleDeclaration>>);\n /**\n * Whether or not to show bounding boxes around the elements.\n *\n * @default true\n */\n showMasks?: boolean;\n /**\n * Provide a function for generating labels.\n * By default, labels are generated as numbers starting from 0.\n */\n labelGenerator?: (element: Element, index: number) => string;\n /**\n * Provide a container element to query the elements to be marked.\n * By default, the container element is `document.body`.\n */\n containerElement?: Element;\n /**\n * Only mark elements that are visible in the current viewport\n *\n * @default false\n */\n viewPortOnly?: boolean;\n}\n\ninterface MarkedElement {\n element: Element;\n markElement: HTMLElement;\n maskElement?: HTMLElement;\n}\n\nlet cleanupFns: (() => void)[] = [];\n\nasync function mark(\n options: MarkOptions = {}\n): Promise<Map<string, MarkedElement>> {\n const {\n selector = \"button, input, a, select, textarea\",\n markStyle = {\n backgroundColor: \"red\",\n color: \"white\",\n padding: \"2px 4px\",\n fontSize: \"12px\",\n fontWeight: \"bold\",\n },\n markPlacement = \"top-start\",\n maskStyle = {\n outline: \"2px dashed red\",\n backgroundColor: \"transparent\",\n },\n showMasks = true,\n labelGenerator = (_, index) => index.toString(),\n containerElement = document.body,\n viewPortOnly = false,\n } = options;\n\n const elements = Array.from(\n containerElement.querySelectorAll(selector)\n ).filter(\n (el) => !viewPortOnly || el.getBoundingClientRect().top < window.innerHeight\n );\n\n const markedElements = new Map<string, MarkedElement>();\n\n await Promise.all(\n elements.map(async (element, index) => {\n const label = labelGenerator(element, index);\n const markElement = createMark(element, markStyle, label, markPlacement);\n\n const maskElement = showMasks\n ? createMask(element, maskStyle, label)\n : undefined;\n\n markedElements.set(label, { element, markElement, maskElement });\n element.setAttribute(\"data-webmarkeredby\", `webmarker-${label}`);\n })\n );\n\n document.documentElement.dataset.webmarkered = \"true\";\n return markedElements;\n}\n\nfunction createMark(\n element: Element,\n style:\n | Readonly<Partial<CSSStyleDeclaration>>\n | ((element: Element) => Readonly<Partial<CSSStyleDeclaration>>),\n label: string,\n markPlacement: Placement = \"top-start\"\n): HTMLElement {\n const markElement = document.createElement(\"div\");\n markElement.className = \"webmarker\";\n markElement.id = `webmarker-${label}`;\n markElement.textContent = label;\n document.body.appendChild(markElement);\n positionMark(markElement, element, markPlacement);\n applyStyle(\n markElement,\n {\n zIndex: \"999999999\",\n position: \"absolute\",\n pointerEvents: \"none\",\n },\n typeof style === \"function\" ? style(element) : style\n );\n return markElement;\n}\n\nfunction createMask(\n element: Element,\n style:\n | Readonly<Partial<CSSStyleDeclaration>>\n | ((element: Element) => Readonly<Partial<CSSStyleDeclaration>>),\n label: string\n): HTMLElement {\n const maskElement = document.createElement(\"div\");\n maskElement.className = \"webmarkermask\";\n maskElement.id = `webmarkermask-${label}`;\n document.body.appendChild(maskElement);\n positionMask(maskElement, element);\n applyStyle(\n maskElement,\n {\n zIndex: \"999999999\",\n position: \"absolute\",\n pointerEvents: \"none\",\n },\n typeof style === \"function\" ? style(element) : style\n );\n return maskElement;\n}\n\nfunction positionMark(\n markElement: HTMLElement,\n element: Element,\n markPlacement: Placement\n) {\n async function updatePosition() {\n const { x, y } = await computePosition(element, markElement, {\n placement: markPlacement,\n });\n Object.assign(markElement.style, {\n left: `${x}px`,\n top: `${y}px`,\n });\n }\n\n cleanupFns.push(autoUpdate(element, markElement, updatePosition));\n}\n\nasync function positionMask(mask: HTMLElement, element: Element) {\n const { width, height } = element.getBoundingClientRect();\n async function updatePosition() {\n const { x: maskX, y: maskY } = await computePosition(element, mask, {\n placement: \"top-start\",\n });\n Object.assign(mask.style, {\n left: `${maskX}px`,\n top: `${maskY + height}px`,\n width: `${width}px`,\n height: `${height}px`,\n });\n }\n cleanupFns.push(autoUpdate(element, mask, updatePosition));\n}\n\nfunction applyStyle(\n element: HTMLElement,\n defaultStyle: Readonly<Partial<CSSStyleDeclaration>>,\n customStyle: Readonly<Partial<CSSStyleDeclaration>>\n): void {\n Object.assign(element.style, defaultStyle, customStyle);\n}\n\nfunction unmark(): void {\n document\n .querySelectorAll(\".webmarker, .webmarkermask\")\n .forEach((el) => el.remove());\n document.documentElement.removeAttribute(\"data-webmarkered\");\n cleanupFns.forEach((fn) => fn());\n cleanupFns = [];\n}\n\nfunction isMarked(): boolean {\n return document.documentElement.hasAttribute(\"data-webmarkered\");\n}\n\nwindow[\"mark\"] = mark;\nwindow[\"unmark\"] = unmark;\nwindow[\"isMarked\"] = isMarked;\n\nexport { mark, unmark, isMarked };\nexport type { MarkOptions, MarkedElement, Placement };\n"],"names":[],"version":3,"file":"main.js.map"}
|
package/dist/module.js.map
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"mappings":";;;A,I,kC,a,U,S,I,S,O,E,U,E,C,E,S;I,S,M,K;Q,O,iB,I,Q,I,E,S,O;Y,Q;Q;I;I,O,I,C,K,C,I,O,C,E,S,O,E,M;Q,S,U,K;Y,I;gB,K,U,I,C;Y,E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E,S,E;YAXK,KAAoB,QAAQ,qBAAqB,IAA/C,QAAK,GAAA,KAAA,EAAE,SAAM,GAAA,MAAA;YAYrB,iCAAW,IAAI,CAAC,CAAA,GAAA,iBAAA,EAAW,SAAS,MAAM;Y,O;gB,E,Q;a;Q;I;AAC3C;AAED,SAAS,iCACP,OAAoB,EACpB,YAAoD,EACpD,WAAmD;IAEnD,OAAO,MAAM,CAAC,QAAQ,KAAK,EAAE,cAAc;AAC7C;AAEA,SAAS;IACP,SACG,gBAAgB,CAAC,8BACjB,OAAO,CAAC,SAAC,EAAE;QAAK,OAAA,GAAG,MAAM;IAAT;IACnB,SAAS,eAAe,CAAC,eAAe,CAAC;IACzC,iCAAW,OAAO,CAAC,SAAC,EAAE;QAAK,OAAA;IAAA;IAC3B,mCAAa,EAAE;AACjB;AAEA,SAAS;IACP,OAAO,SAAS,eAAe,CAAC,YAAY,CAAC;AAC/C;AAEA,MAAM,CAAC,OAAO,GAAG;AACjB,MAAM,CAAC,SAAS,GAAG;AACnB,MAAM,CAAC,WAAW,GAAG","sources":["src/index.ts"],"sourcesContent":["import { autoUpdate, computePosition } from \"@floating-ui/dom\";\n\ntype Placement =\n | \"top\"\n | \"top-start\"\n | \"top-end\"\n | \"right\"\n | \"right-start\"\n | \"right-end\"\n | \"bottom\"\n | \"bottom-start\"\n | \"bottom-end\"\n | \"left\"\n | \"left-start\"\n | \"left-end\";\n\ninterface MarkOptions {\n /**\n * A CSS selector to specify the elements to be marked.\n */\n selector?: string;\n /**\n * A CSS style to apply to the label element.\n * You can also specify a function that returns a CSS style object.\n */\n markStyle?:\n | Readonly<Partial<CSSStyleDeclaration>>\n | ((element: Element) => Readonly<Partial<CSSStyleDeclaration>>);\n /**\n * The placement of the mark relative to the element.\n *\n * @default 'top-start'\n */\n markPlacement?: Placement;\n /**\n * A CSS style to apply to the bounding box element.\n * You can also specify a function that returns a CSS style object.\n * Bounding boxes are only shown if `showMasks` is `true`.\n */\n maskStyle?:\n | Readonly<Partial<CSSStyleDeclaration>>\n | ((element: Element) => Readonly<Partial<CSSStyleDeclaration>>);\n /**\n * Whether or not to show bounding boxes around the elements.\n *\n * @default true\n */\n showMasks?: boolean;\n /**\n * Provide a function for generating labels.\n * By default, labels are generated as numbers starting from 0.\n */\n labelGenerator?: (element: Element, index: number) => string;\n /**\n * Provide a container element to query the elements to be marked.\n * By default, the container element is `document.body`.\n */\n containerElement?: Element;\n /**\n * Only mark elements that are visible in the current viewport\n *\n * @default false\n */\n viewPortOnly?: boolean;\n}\n\ninterface MarkedElement {\n element: Element;\n markElement: HTMLElement;\n maskElement?: HTMLElement;\n}\n\nlet cleanupFns: (() => void)[] = [];\n\nasync function mark(\n options: MarkOptions = {}\n): Promise<Map<string, MarkedElement>> {\n const {\n selector = \"button, input, a, select, textarea\",\n markStyle = {\n backgroundColor: \"red\",\n color: \"white\",\n padding: \"2px 4px\",\n fontSize: \"12px\",\n fontWeight: \"bold\",\n },\n markPlacement = \"top-start\",\n maskStyle = {\n outline: \"2px dashed red\",\n backgroundColor: \"transparent\",\n },\n showMasks = true,\n labelGenerator = (_, index) => index.toString(),\n containerElement = document.body,\n viewPortOnly = false,\n } = options;\n\n const elements = Array.from(\n containerElement.querySelectorAll(selector)\n ).filter(\n (el) => !viewPortOnly || el.getBoundingClientRect().top < window.innerHeight\n );\n\n const markedElements = new Map<string, MarkedElement>();\n\n await Promise.all(\n elements.map(async (element, index) => {\n const label = labelGenerator(element, index);\n const markElement = createMark(element, markStyle, label, markPlacement);\n\n const maskElement = showMasks\n ? createMask(element, maskStyle, label)\n : undefined;\n\n markedElements.set(label, { element, markElement, maskElement });\n element.setAttribute(\"data-webmarkeredby\", `webmarker-${label}`);\n })\n );\n\n document.documentElement.dataset.webmarkered = \"true\";\n return markedElements;\n}\n\nfunction createMark(\n element: Element,\n style:\n | Readonly<Partial<CSSStyleDeclaration>>\n | ((element: Element) => Readonly<Partial<CSSStyleDeclaration>>),\n label: string,\n markPlacement: Placement = \"top-start\"\n): HTMLElement {\n const markElement = document.createElement(\"div\");\n markElement.className = \"webmarker\";\n markElement.id = `webmarker-${label}`;\n markElement.textContent = label;\n document.body.appendChild(markElement);\n positionMark(markElement, element, markPlacement);\n applyStyle(\n markElement,\n {\n zIndex: \"999999999\",\n position: \"absolute\",\n pointerEvents: \"none\",\n },\n typeof style === \"function\" ? style(element) : style\n );\n return markElement;\n}\n\nfunction createMask(\n element: Element,\n style:\n | Readonly<Partial<CSSStyleDeclaration>>\n | ((element: Element) => Readonly<Partial<CSSStyleDeclaration>>),\n label: string\n): HTMLElement {\n const maskElement = document.createElement(\"div\");\n maskElement.className = \"webmarkermask\";\n maskElement.id = `webmarkermask-${label}`;\n document.body.appendChild(maskElement);\n positionMask(maskElement, element);\n applyStyle(\n maskElement,\n {\n zIndex: \"999999999\",\n position: \"absolute\",\n pointerEvents: \"none\",\n },\n typeof style === \"function\" ? style(element) : style\n );\n return maskElement;\n}\n\nfunction positionMark(\n markElement: HTMLElement,\n element: Element,\n markPlacement: Placement\n) {\n async function updatePosition() {\n const { x, y } = await computePosition(element, markElement, {\n placement: markPlacement,\n });\n Object.assign(markElement.style, {\n left: `${x}px`,\n top: `${y}px`,\n });\n }\n\n cleanupFns.push(autoUpdate(element, markElement, updatePosition));\n}\n\nasync function positionMask(mask: HTMLElement, element: Element) {\n const { width, height } = element.getBoundingClientRect();\n async function updatePosition() {\n const { x: maskX, y: maskY } = await computePosition(element, mask, {\n placement: \"top-start\",\n });\n Object.assign(mask.style, {\n left: `${maskX}px`,\n top: `${maskY + height}px`,\n width: `${width}px`,\n height: `${height}px`,\n });\n }\n cleanupFns.push(autoUpdate(element, mask, updatePosition));\n}\n\nfunction applyStyle(\n element: HTMLElement,\n defaultStyle: Readonly<Partial<CSSStyleDeclaration>>,\n customStyle: Readonly<Partial<CSSStyleDeclaration>>\n): void {\n Object.assign(element.style, defaultStyle, customStyle);\n}\n\nfunction unmark(): void {\n document\n .querySelectorAll(\".webmarker, .webmarkermask\")\n .forEach((el) => el.remove());\n document.documentElement.removeAttribute(\"data-webmarkered\");\n cleanupFns.forEach((fn) => fn());\n cleanupFns = [];\n}\n\nfunction isMarked(): boolean {\n return document.documentElement.hasAttribute(\"data-webmarkered\");\n}\n\nwindow[\"mark\"] = mark;\nwindow[\"unmark\"] = unmark;\nwindow[\"isMarked\"] = isMarked;\n\nexport { mark, unmark, isMarked };\nexport type { MarkOptions, MarkedElement, Placement };\n"],"names":[],"version":3,"file":"module.js.map"}
|
package/dist/types.d.ts.map
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"mappings":"AAEA,wBACI,KAAK,GACL,WAAW,GACX,SAAS,GACT,OAAO,GACP,aAAa,GACb,WAAW,GACX,QAAQ,GACR,cAAc,GACd,YAAY,GACZ,MAAM,GACN,YAAY,GACZ,UAAU,CAAC;AAEf;IACE;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;OAGG;IACH,SAAS,CAAC,EACN,QAAQ,CAAC,OAAO,CAAC,mBAAmB,CAAC,CAAC,GACtC,CAAC,CAAC,OAAO,EAAE,OAAO,KAAK,QAAQ,CAAC,OAAO,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAC;IACnE;;;;OAIG;IACH,aAAa,CAAC,EAAE,SAAS,CAAC;IAC1B;;;;OAIG;IACH,SAAS,CAAC,EACN,QAAQ,CAAC,OAAO,CAAC,mBAAmB,CAAC,CAAC,GACtC,CAAC,CAAC,OAAO,EAAE,OAAO,KAAK,QAAQ,CAAC,OAAO,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAC;IACnE;;;;OAIG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB;;;OAGG;IACH,cAAc,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC;IAC7D;;;OAGG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B;;;;OAIG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB;AAED;IACE,OAAO,EAAE,OAAO,CAAC;IACjB,WAAW,EAAE,WAAW,CAAC;IACzB,WAAW,CAAC,EAAE,WAAW,CAAC;CAC3B;AAID,qBACE,OAAO,GAAE,WAAgB,GACxB,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC,CA6CrC;AA8FD,0BAAmB,IAAI,CAOtB;AAED,4BAAqB,OAAO,CAE3B","sources":["src/src/index.ts","src/index.ts"],"sourcesContent":[null,"import { autoUpdate, computePosition } from \"@floating-ui/dom\";\n\ntype Placement =\n | \"top\"\n | \"top-start\"\n | \"top-end\"\n | \"right\"\n | \"right-start\"\n | \"right-end\"\n | \"bottom\"\n | \"bottom-start\"\n | \"bottom-end\"\n | \"left\"\n | \"left-start\"\n | \"left-end\";\n\ninterface MarkOptions {\n /**\n * A CSS selector to specify the elements to be marked.\n */\n selector?: string;\n /**\n * A CSS style to apply to the label element.\n * You can also specify a function that returns a CSS style object.\n */\n markStyle?:\n | Readonly<Partial<CSSStyleDeclaration>>\n | ((element: Element) => Readonly<Partial<CSSStyleDeclaration>>);\n /**\n * The placement of the mark relative to the element.\n *\n * @default 'top-start'\n */\n markPlacement?: Placement;\n /**\n * A CSS style to apply to the bounding box element.\n * You can also specify a function that returns a CSS style object.\n * Bounding boxes are only shown if `showMasks` is `true`.\n */\n maskStyle?:\n | Readonly<Partial<CSSStyleDeclaration>>\n | ((element: Element) => Readonly<Partial<CSSStyleDeclaration>>);\n /**\n * Whether or not to show bounding boxes around the elements.\n *\n * @default true\n */\n showMasks?: boolean;\n /**\n * Provide a function for generating labels.\n * By default, labels are generated as numbers starting from 0.\n */\n labelGenerator?: (element: Element, index: number) => string;\n /**\n * Provide a container element to query the elements to be marked.\n * By default, the container element is `document.body`.\n */\n containerElement?: Element;\n /**\n * Only mark elements that are visible in the current viewport\n *\n * @default false\n */\n viewPortOnly?: boolean;\n}\n\ninterface MarkedElement {\n element: Element;\n markElement: HTMLElement;\n maskElement?: HTMLElement;\n}\n\nlet cleanupFns: (() => void)[] = [];\n\nasync function mark(\n options: MarkOptions = {}\n): Promise<Map<string, MarkedElement>> {\n const {\n selector = \"button, input, a, select, textarea\",\n markStyle = {\n backgroundColor: \"red\",\n color: \"white\",\n padding: \"2px 4px\",\n fontSize: \"12px\",\n fontWeight: \"bold\",\n },\n markPlacement = \"top-start\",\n maskStyle = {\n outline: \"2px dashed red\",\n backgroundColor: \"transparent\",\n },\n showMasks = true,\n labelGenerator = (_, index) => index.toString(),\n containerElement = document.body,\n viewPortOnly = false,\n } = options;\n\n const elements = Array.from(\n containerElement.querySelectorAll(selector)\n ).filter(\n (el) => !viewPortOnly || el.getBoundingClientRect().top < window.innerHeight\n );\n\n const markedElements = new Map<string, MarkedElement>();\n\n await Promise.all(\n elements.map(async (element, index) => {\n const label = labelGenerator(element, index);\n const markElement = createMark(element, markStyle, label, markPlacement);\n\n const maskElement = showMasks\n ? createMask(element, maskStyle, label)\n : undefined;\n\n markedElements.set(label, { element, markElement, maskElement });\n element.setAttribute(\"data-webmarkeredby\", `webmarker-${label}`);\n })\n );\n\n document.documentElement.dataset.webmarkered = \"true\";\n return markedElements;\n}\n\nfunction createMark(\n element: Element,\n style:\n | Readonly<Partial<CSSStyleDeclaration>>\n | ((element: Element) => Readonly<Partial<CSSStyleDeclaration>>),\n label: string,\n markPlacement: Placement = \"top-start\"\n): HTMLElement {\n const markElement = document.createElement(\"div\");\n markElement.className = \"webmarker\";\n markElement.id = `webmarker-${label}`;\n markElement.textContent = label;\n document.body.appendChild(markElement);\n positionMark(markElement, element, markPlacement);\n applyStyle(\n markElement,\n {\n zIndex: \"999999999\",\n position: \"absolute\",\n pointerEvents: \"none\",\n },\n typeof style === \"function\" ? style(element) : style\n );\n return markElement;\n}\n\nfunction createMask(\n element: Element,\n style:\n | Readonly<Partial<CSSStyleDeclaration>>\n | ((element: Element) => Readonly<Partial<CSSStyleDeclaration>>),\n label: string\n): HTMLElement {\n const maskElement = document.createElement(\"div\");\n maskElement.className = \"webmarkermask\";\n maskElement.id = `webmarkermask-${label}`;\n document.body.appendChild(maskElement);\n positionMask(maskElement, element);\n applyStyle(\n maskElement,\n {\n zIndex: \"999999999\",\n position: \"absolute\",\n pointerEvents: \"none\",\n },\n typeof style === \"function\" ? style(element) : style\n );\n return maskElement;\n}\n\nfunction positionMark(\n markElement: HTMLElement,\n element: Element,\n markPlacement: Placement\n) {\n async function updatePosition() {\n const { x, y } = await computePosition(element, markElement, {\n placement: markPlacement,\n });\n Object.assign(markElement.style, {\n left: `${x}px`,\n top: `${y}px`,\n });\n }\n\n cleanupFns.push(autoUpdate(element, markElement, updatePosition));\n}\n\nasync function positionMask(mask: HTMLElement, element: Element) {\n const { width, height } = element.getBoundingClientRect();\n async function updatePosition() {\n const { x: maskX, y: maskY } = await computePosition(element, mask, {\n placement: \"top-start\",\n });\n Object.assign(mask.style, {\n left: `${maskX}px`,\n top: `${maskY + height}px`,\n width: `${width}px`,\n height: `${height}px`,\n });\n }\n cleanupFns.push(autoUpdate(element, mask, updatePosition));\n}\n\nfunction applyStyle(\n element: HTMLElement,\n defaultStyle: Readonly<Partial<CSSStyleDeclaration>>,\n customStyle: Readonly<Partial<CSSStyleDeclaration>>\n): void {\n Object.assign(element.style, defaultStyle, customStyle);\n}\n\nfunction unmark(): void {\n document\n .querySelectorAll(\".webmarker, .webmarkermask\")\n .forEach((el) => el.remove());\n document.documentElement.removeAttribute(\"data-webmarkered\");\n cleanupFns.forEach((fn) => fn());\n cleanupFns = [];\n}\n\nfunction isMarked(): boolean {\n return document.documentElement.hasAttribute(\"data-webmarkered\");\n}\n\nwindow[\"mark\"] = mark;\nwindow[\"unmark\"] = unmark;\nwindow[\"isMarked\"] = isMarked;\n\nexport { mark, unmark, isMarked };\nexport type { MarkOptions, MarkedElement, Placement };\n"],"names":[],"version":3,"file":"types.d.ts.map"}
|