webmarker-js 0.3.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +2 -2
- package/chrome-extension/dist/index.d.ts +72 -0
- package/chrome-extension/dist/main.js +1069 -0
- package/chrome-extension/dist/module.js +1048 -0
- package/dist/index.d.ts +10 -2
- package/dist/main.js +66 -55
- package/dist/module.js +66 -55
- package/package.json +2 -1
- package/src/index.ts +114 -78
@@ -0,0 +1,1048 @@
|
|
1
|
+
var __defProp = Object.defineProperty;
|
2
|
+
var __defProps = Object.defineProperties;
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
8
|
+
var __spreadValues = (a, b) => {
|
9
|
+
for (var prop in b || (b = {}))
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
12
|
+
if (__getOwnPropSymbols)
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
14
|
+
if (__propIsEnum.call(b, prop))
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
16
|
+
}
|
17
|
+
return a;
|
18
|
+
};
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
20
|
+
var __async = (__this, __arguments, generator) => {
|
21
|
+
return new Promise((resolve, reject) => {
|
22
|
+
var fulfilled = (value) => {
|
23
|
+
try {
|
24
|
+
step(generator.next(value));
|
25
|
+
} catch (e) {
|
26
|
+
reject(e);
|
27
|
+
}
|
28
|
+
};
|
29
|
+
var rejected = (value) => {
|
30
|
+
try {
|
31
|
+
step(generator.throw(value));
|
32
|
+
} catch (e) {
|
33
|
+
reject(e);
|
34
|
+
}
|
35
|
+
};
|
36
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
37
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
38
|
+
});
|
39
|
+
};
|
40
|
+
|
41
|
+
// node_modules/@floating-ui/utils/dist/floating-ui.utils.mjs
|
42
|
+
var min = Math.min;
|
43
|
+
var max = Math.max;
|
44
|
+
var round = Math.round;
|
45
|
+
var floor = Math.floor;
|
46
|
+
var createCoords = (v) => ({
|
47
|
+
x: v,
|
48
|
+
y: v
|
49
|
+
});
|
50
|
+
function getSide(placement) {
|
51
|
+
return placement.split("-")[0];
|
52
|
+
}
|
53
|
+
function getAlignment(placement) {
|
54
|
+
return placement.split("-")[1];
|
55
|
+
}
|
56
|
+
function getOppositeAxis(axis) {
|
57
|
+
return axis === "x" ? "y" : "x";
|
58
|
+
}
|
59
|
+
function getAxisLength(axis) {
|
60
|
+
return axis === "y" ? "height" : "width";
|
61
|
+
}
|
62
|
+
function getSideAxis(placement) {
|
63
|
+
return ["top", "bottom"].includes(getSide(placement)) ? "y" : "x";
|
64
|
+
}
|
65
|
+
function getAlignmentAxis(placement) {
|
66
|
+
return getOppositeAxis(getSideAxis(placement));
|
67
|
+
}
|
68
|
+
function rectToClientRect(rect) {
|
69
|
+
const {
|
70
|
+
x,
|
71
|
+
y,
|
72
|
+
width,
|
73
|
+
height
|
74
|
+
} = rect;
|
75
|
+
return {
|
76
|
+
width,
|
77
|
+
height,
|
78
|
+
top: y,
|
79
|
+
left: x,
|
80
|
+
right: x + width,
|
81
|
+
bottom: y + height,
|
82
|
+
x,
|
83
|
+
y
|
84
|
+
};
|
85
|
+
}
|
86
|
+
|
87
|
+
// node_modules/@floating-ui/core/dist/floating-ui.core.mjs
|
88
|
+
function computeCoordsFromPlacement(_ref, placement, rtl) {
|
89
|
+
let {
|
90
|
+
reference,
|
91
|
+
floating
|
92
|
+
} = _ref;
|
93
|
+
const sideAxis = getSideAxis(placement);
|
94
|
+
const alignmentAxis = getAlignmentAxis(placement);
|
95
|
+
const alignLength = getAxisLength(alignmentAxis);
|
96
|
+
const side = getSide(placement);
|
97
|
+
const isVertical = sideAxis === "y";
|
98
|
+
const commonX = reference.x + reference.width / 2 - floating.width / 2;
|
99
|
+
const commonY = reference.y + reference.height / 2 - floating.height / 2;
|
100
|
+
const commonAlign = reference[alignLength] / 2 - floating[alignLength] / 2;
|
101
|
+
let coords;
|
102
|
+
switch (side) {
|
103
|
+
case "top":
|
104
|
+
coords = {
|
105
|
+
x: commonX,
|
106
|
+
y: reference.y - floating.height
|
107
|
+
};
|
108
|
+
break;
|
109
|
+
case "bottom":
|
110
|
+
coords = {
|
111
|
+
x: commonX,
|
112
|
+
y: reference.y + reference.height
|
113
|
+
};
|
114
|
+
break;
|
115
|
+
case "right":
|
116
|
+
coords = {
|
117
|
+
x: reference.x + reference.width,
|
118
|
+
y: commonY
|
119
|
+
};
|
120
|
+
break;
|
121
|
+
case "left":
|
122
|
+
coords = {
|
123
|
+
x: reference.x - floating.width,
|
124
|
+
y: commonY
|
125
|
+
};
|
126
|
+
break;
|
127
|
+
default:
|
128
|
+
coords = {
|
129
|
+
x: reference.x,
|
130
|
+
y: reference.y
|
131
|
+
};
|
132
|
+
}
|
133
|
+
switch (getAlignment(placement)) {
|
134
|
+
case "start":
|
135
|
+
coords[alignmentAxis] -= commonAlign * (rtl && isVertical ? -1 : 1);
|
136
|
+
break;
|
137
|
+
case "end":
|
138
|
+
coords[alignmentAxis] += commonAlign * (rtl && isVertical ? -1 : 1);
|
139
|
+
break;
|
140
|
+
}
|
141
|
+
return coords;
|
142
|
+
}
|
143
|
+
var computePosition = (reference, floating, config) => __async(void 0, null, function* () {
|
144
|
+
const {
|
145
|
+
placement = "bottom",
|
146
|
+
strategy = "absolute",
|
147
|
+
middleware = [],
|
148
|
+
platform: platform2
|
149
|
+
} = config;
|
150
|
+
const validMiddleware = middleware.filter(Boolean);
|
151
|
+
const rtl = yield platform2.isRTL == null ? void 0 : platform2.isRTL(floating);
|
152
|
+
let rects = yield platform2.getElementRects({
|
153
|
+
reference,
|
154
|
+
floating,
|
155
|
+
strategy
|
156
|
+
});
|
157
|
+
let {
|
158
|
+
x,
|
159
|
+
y
|
160
|
+
} = computeCoordsFromPlacement(rects, placement, rtl);
|
161
|
+
let statefulPlacement = placement;
|
162
|
+
let middlewareData = {};
|
163
|
+
let resetCount = 0;
|
164
|
+
for (let i = 0; i < validMiddleware.length; i++) {
|
165
|
+
const {
|
166
|
+
name,
|
167
|
+
fn
|
168
|
+
} = validMiddleware[i];
|
169
|
+
const {
|
170
|
+
x: nextX,
|
171
|
+
y: nextY,
|
172
|
+
data,
|
173
|
+
reset
|
174
|
+
} = yield fn({
|
175
|
+
x,
|
176
|
+
y,
|
177
|
+
initialPlacement: placement,
|
178
|
+
placement: statefulPlacement,
|
179
|
+
strategy,
|
180
|
+
middlewareData,
|
181
|
+
rects,
|
182
|
+
platform: platform2,
|
183
|
+
elements: {
|
184
|
+
reference,
|
185
|
+
floating
|
186
|
+
}
|
187
|
+
});
|
188
|
+
x = nextX != null ? nextX : x;
|
189
|
+
y = nextY != null ? nextY : y;
|
190
|
+
middlewareData = __spreadProps(__spreadValues({}, middlewareData), {
|
191
|
+
[name]: __spreadValues(__spreadValues({}, middlewareData[name]), data)
|
192
|
+
});
|
193
|
+
if (reset && resetCount <= 50) {
|
194
|
+
resetCount++;
|
195
|
+
if (typeof reset === "object") {
|
196
|
+
if (reset.placement) {
|
197
|
+
statefulPlacement = reset.placement;
|
198
|
+
}
|
199
|
+
if (reset.rects) {
|
200
|
+
rects = reset.rects === true ? yield platform2.getElementRects({
|
201
|
+
reference,
|
202
|
+
floating,
|
203
|
+
strategy
|
204
|
+
}) : reset.rects;
|
205
|
+
}
|
206
|
+
({
|
207
|
+
x,
|
208
|
+
y
|
209
|
+
} = computeCoordsFromPlacement(rects, statefulPlacement, rtl));
|
210
|
+
}
|
211
|
+
i = -1;
|
212
|
+
}
|
213
|
+
}
|
214
|
+
return {
|
215
|
+
x,
|
216
|
+
y,
|
217
|
+
placement: statefulPlacement,
|
218
|
+
strategy,
|
219
|
+
middlewareData
|
220
|
+
};
|
221
|
+
});
|
222
|
+
|
223
|
+
// node_modules/@floating-ui/utils/dist/floating-ui.utils.dom.mjs
|
224
|
+
function getNodeName(node) {
|
225
|
+
if (isNode(node)) {
|
226
|
+
return (node.nodeName || "").toLowerCase();
|
227
|
+
}
|
228
|
+
return "#document";
|
229
|
+
}
|
230
|
+
function getWindow(node) {
|
231
|
+
var _node$ownerDocument;
|
232
|
+
return (node == null || (_node$ownerDocument = node.ownerDocument) == null ? void 0 : _node$ownerDocument.defaultView) || window;
|
233
|
+
}
|
234
|
+
function getDocumentElement(node) {
|
235
|
+
var _ref;
|
236
|
+
return (_ref = (isNode(node) ? node.ownerDocument : node.document) || window.document) == null ? void 0 : _ref.documentElement;
|
237
|
+
}
|
238
|
+
function isNode(value) {
|
239
|
+
return value instanceof Node || value instanceof getWindow(value).Node;
|
240
|
+
}
|
241
|
+
function isElement(value) {
|
242
|
+
return value instanceof Element || value instanceof getWindow(value).Element;
|
243
|
+
}
|
244
|
+
function isHTMLElement(value) {
|
245
|
+
return value instanceof HTMLElement || value instanceof getWindow(value).HTMLElement;
|
246
|
+
}
|
247
|
+
function isShadowRoot(value) {
|
248
|
+
if (typeof ShadowRoot === "undefined") {
|
249
|
+
return false;
|
250
|
+
}
|
251
|
+
return value instanceof ShadowRoot || value instanceof getWindow(value).ShadowRoot;
|
252
|
+
}
|
253
|
+
function isOverflowElement(element) {
|
254
|
+
const {
|
255
|
+
overflow,
|
256
|
+
overflowX,
|
257
|
+
overflowY,
|
258
|
+
display
|
259
|
+
} = getComputedStyle(element);
|
260
|
+
return /auto|scroll|overlay|hidden|clip/.test(overflow + overflowY + overflowX) && !["inline", "contents"].includes(display);
|
261
|
+
}
|
262
|
+
function isTableElement(element) {
|
263
|
+
return ["table", "td", "th"].includes(getNodeName(element));
|
264
|
+
}
|
265
|
+
function isContainingBlock(element) {
|
266
|
+
const webkit = isWebKit();
|
267
|
+
const css = getComputedStyle(element);
|
268
|
+
return css.transform !== "none" || css.perspective !== "none" || (css.containerType ? css.containerType !== "normal" : false) || !webkit && (css.backdropFilter ? css.backdropFilter !== "none" : false) || !webkit && (css.filter ? css.filter !== "none" : false) || ["transform", "perspective", "filter"].some((value) => (css.willChange || "").includes(value)) || ["paint", "layout", "strict", "content"].some((value) => (css.contain || "").includes(value));
|
269
|
+
}
|
270
|
+
function getContainingBlock(element) {
|
271
|
+
let currentNode = getParentNode(element);
|
272
|
+
while (isHTMLElement(currentNode) && !isLastTraversableNode(currentNode)) {
|
273
|
+
if (isContainingBlock(currentNode)) {
|
274
|
+
return currentNode;
|
275
|
+
}
|
276
|
+
currentNode = getParentNode(currentNode);
|
277
|
+
}
|
278
|
+
return null;
|
279
|
+
}
|
280
|
+
function isWebKit() {
|
281
|
+
if (typeof CSS === "undefined" || !CSS.supports) return false;
|
282
|
+
return CSS.supports("-webkit-backdrop-filter", "none");
|
283
|
+
}
|
284
|
+
function isLastTraversableNode(node) {
|
285
|
+
return ["html", "body", "#document"].includes(getNodeName(node));
|
286
|
+
}
|
287
|
+
function getComputedStyle(element) {
|
288
|
+
return getWindow(element).getComputedStyle(element);
|
289
|
+
}
|
290
|
+
function getNodeScroll(element) {
|
291
|
+
if (isElement(element)) {
|
292
|
+
return {
|
293
|
+
scrollLeft: element.scrollLeft,
|
294
|
+
scrollTop: element.scrollTop
|
295
|
+
};
|
296
|
+
}
|
297
|
+
return {
|
298
|
+
scrollLeft: element.pageXOffset,
|
299
|
+
scrollTop: element.pageYOffset
|
300
|
+
};
|
301
|
+
}
|
302
|
+
function getParentNode(node) {
|
303
|
+
if (getNodeName(node) === "html") {
|
304
|
+
return node;
|
305
|
+
}
|
306
|
+
const result = (
|
307
|
+
// Step into the shadow DOM of the parent of a slotted node.
|
308
|
+
node.assignedSlot || // DOM Element detected.
|
309
|
+
node.parentNode || // ShadowRoot detected.
|
310
|
+
isShadowRoot(node) && node.host || // Fallback.
|
311
|
+
getDocumentElement(node)
|
312
|
+
);
|
313
|
+
return isShadowRoot(result) ? result.host : result;
|
314
|
+
}
|
315
|
+
function getNearestOverflowAncestor(node) {
|
316
|
+
const parentNode = getParentNode(node);
|
317
|
+
if (isLastTraversableNode(parentNode)) {
|
318
|
+
return node.ownerDocument ? node.ownerDocument.body : node.body;
|
319
|
+
}
|
320
|
+
if (isHTMLElement(parentNode) && isOverflowElement(parentNode)) {
|
321
|
+
return parentNode;
|
322
|
+
}
|
323
|
+
return getNearestOverflowAncestor(parentNode);
|
324
|
+
}
|
325
|
+
function getOverflowAncestors(node, list, traverseIframes) {
|
326
|
+
var _node$ownerDocument2;
|
327
|
+
if (list === void 0) {
|
328
|
+
list = [];
|
329
|
+
}
|
330
|
+
if (traverseIframes === void 0) {
|
331
|
+
traverseIframes = true;
|
332
|
+
}
|
333
|
+
const scrollableAncestor = getNearestOverflowAncestor(node);
|
334
|
+
const isBody = scrollableAncestor === ((_node$ownerDocument2 = node.ownerDocument) == null ? void 0 : _node$ownerDocument2.body);
|
335
|
+
const win = getWindow(scrollableAncestor);
|
336
|
+
if (isBody) {
|
337
|
+
return list.concat(win, win.visualViewport || [], isOverflowElement(scrollableAncestor) ? scrollableAncestor : [], win.frameElement && traverseIframes ? getOverflowAncestors(win.frameElement) : []);
|
338
|
+
}
|
339
|
+
return list.concat(scrollableAncestor, getOverflowAncestors(scrollableAncestor, [], traverseIframes));
|
340
|
+
}
|
341
|
+
|
342
|
+
// node_modules/@floating-ui/dom/dist/floating-ui.dom.mjs
|
343
|
+
function getCssDimensions(element) {
|
344
|
+
const css = getComputedStyle(element);
|
345
|
+
let width = parseFloat(css.width) || 0;
|
346
|
+
let height = parseFloat(css.height) || 0;
|
347
|
+
const hasOffset = isHTMLElement(element);
|
348
|
+
const offsetWidth = hasOffset ? element.offsetWidth : width;
|
349
|
+
const offsetHeight = hasOffset ? element.offsetHeight : height;
|
350
|
+
const shouldFallback = round(width) !== offsetWidth || round(height) !== offsetHeight;
|
351
|
+
if (shouldFallback) {
|
352
|
+
width = offsetWidth;
|
353
|
+
height = offsetHeight;
|
354
|
+
}
|
355
|
+
return {
|
356
|
+
width,
|
357
|
+
height,
|
358
|
+
$: shouldFallback
|
359
|
+
};
|
360
|
+
}
|
361
|
+
function unwrapElement(element) {
|
362
|
+
return !isElement(element) ? element.contextElement : element;
|
363
|
+
}
|
364
|
+
function getScale(element) {
|
365
|
+
const domElement = unwrapElement(element);
|
366
|
+
if (!isHTMLElement(domElement)) {
|
367
|
+
return createCoords(1);
|
368
|
+
}
|
369
|
+
const rect = domElement.getBoundingClientRect();
|
370
|
+
const {
|
371
|
+
width,
|
372
|
+
height,
|
373
|
+
$
|
374
|
+
} = getCssDimensions(domElement);
|
375
|
+
let x = ($ ? round(rect.width) : rect.width) / width;
|
376
|
+
let y = ($ ? round(rect.height) : rect.height) / height;
|
377
|
+
if (!x || !Number.isFinite(x)) {
|
378
|
+
x = 1;
|
379
|
+
}
|
380
|
+
if (!y || !Number.isFinite(y)) {
|
381
|
+
y = 1;
|
382
|
+
}
|
383
|
+
return {
|
384
|
+
x,
|
385
|
+
y
|
386
|
+
};
|
387
|
+
}
|
388
|
+
var noOffsets = /* @__PURE__ */ createCoords(0);
|
389
|
+
function getVisualOffsets(element) {
|
390
|
+
const win = getWindow(element);
|
391
|
+
if (!isWebKit() || !win.visualViewport) {
|
392
|
+
return noOffsets;
|
393
|
+
}
|
394
|
+
return {
|
395
|
+
x: win.visualViewport.offsetLeft,
|
396
|
+
y: win.visualViewport.offsetTop
|
397
|
+
};
|
398
|
+
}
|
399
|
+
function shouldAddVisualOffsets(element, isFixed, floatingOffsetParent) {
|
400
|
+
if (isFixed === void 0) {
|
401
|
+
isFixed = false;
|
402
|
+
}
|
403
|
+
if (!floatingOffsetParent || isFixed && floatingOffsetParent !== getWindow(element)) {
|
404
|
+
return false;
|
405
|
+
}
|
406
|
+
return isFixed;
|
407
|
+
}
|
408
|
+
function getBoundingClientRect(element, includeScale, isFixedStrategy, offsetParent) {
|
409
|
+
if (includeScale === void 0) {
|
410
|
+
includeScale = false;
|
411
|
+
}
|
412
|
+
if (isFixedStrategy === void 0) {
|
413
|
+
isFixedStrategy = false;
|
414
|
+
}
|
415
|
+
const clientRect = element.getBoundingClientRect();
|
416
|
+
const domElement = unwrapElement(element);
|
417
|
+
let scale = createCoords(1);
|
418
|
+
if (includeScale) {
|
419
|
+
if (offsetParent) {
|
420
|
+
if (isElement(offsetParent)) {
|
421
|
+
scale = getScale(offsetParent);
|
422
|
+
}
|
423
|
+
} else {
|
424
|
+
scale = getScale(element);
|
425
|
+
}
|
426
|
+
}
|
427
|
+
const visualOffsets = shouldAddVisualOffsets(domElement, isFixedStrategy, offsetParent) ? getVisualOffsets(domElement) : createCoords(0);
|
428
|
+
let x = (clientRect.left + visualOffsets.x) / scale.x;
|
429
|
+
let y = (clientRect.top + visualOffsets.y) / scale.y;
|
430
|
+
let width = clientRect.width / scale.x;
|
431
|
+
let height = clientRect.height / scale.y;
|
432
|
+
if (domElement) {
|
433
|
+
const win = getWindow(domElement);
|
434
|
+
const offsetWin = offsetParent && isElement(offsetParent) ? getWindow(offsetParent) : offsetParent;
|
435
|
+
let currentWin = win;
|
436
|
+
let currentIFrame = currentWin.frameElement;
|
437
|
+
while (currentIFrame && offsetParent && offsetWin !== currentWin) {
|
438
|
+
const iframeScale = getScale(currentIFrame);
|
439
|
+
const iframeRect = currentIFrame.getBoundingClientRect();
|
440
|
+
const css = getComputedStyle(currentIFrame);
|
441
|
+
const left = iframeRect.left + (currentIFrame.clientLeft + parseFloat(css.paddingLeft)) * iframeScale.x;
|
442
|
+
const top = iframeRect.top + (currentIFrame.clientTop + parseFloat(css.paddingTop)) * iframeScale.y;
|
443
|
+
x *= iframeScale.x;
|
444
|
+
y *= iframeScale.y;
|
445
|
+
width *= iframeScale.x;
|
446
|
+
height *= iframeScale.y;
|
447
|
+
x += left;
|
448
|
+
y += top;
|
449
|
+
currentWin = getWindow(currentIFrame);
|
450
|
+
currentIFrame = currentWin.frameElement;
|
451
|
+
}
|
452
|
+
}
|
453
|
+
return rectToClientRect({
|
454
|
+
width,
|
455
|
+
height,
|
456
|
+
x,
|
457
|
+
y
|
458
|
+
});
|
459
|
+
}
|
460
|
+
var topLayerSelectors = [":popover-open", ":modal"];
|
461
|
+
function isTopLayer(element) {
|
462
|
+
return topLayerSelectors.some((selector) => {
|
463
|
+
try {
|
464
|
+
return element.matches(selector);
|
465
|
+
} catch (e) {
|
466
|
+
return false;
|
467
|
+
}
|
468
|
+
});
|
469
|
+
}
|
470
|
+
function convertOffsetParentRelativeRectToViewportRelativeRect(_ref) {
|
471
|
+
let {
|
472
|
+
elements,
|
473
|
+
rect,
|
474
|
+
offsetParent,
|
475
|
+
strategy
|
476
|
+
} = _ref;
|
477
|
+
const isFixed = strategy === "fixed";
|
478
|
+
const documentElement = getDocumentElement(offsetParent);
|
479
|
+
const topLayer = elements ? isTopLayer(elements.floating) : false;
|
480
|
+
if (offsetParent === documentElement || topLayer && isFixed) {
|
481
|
+
return rect;
|
482
|
+
}
|
483
|
+
let scroll = {
|
484
|
+
scrollLeft: 0,
|
485
|
+
scrollTop: 0
|
486
|
+
};
|
487
|
+
let scale = createCoords(1);
|
488
|
+
const offsets = createCoords(0);
|
489
|
+
const isOffsetParentAnElement = isHTMLElement(offsetParent);
|
490
|
+
if (isOffsetParentAnElement || !isOffsetParentAnElement && !isFixed) {
|
491
|
+
if (getNodeName(offsetParent) !== "body" || isOverflowElement(documentElement)) {
|
492
|
+
scroll = getNodeScroll(offsetParent);
|
493
|
+
}
|
494
|
+
if (isHTMLElement(offsetParent)) {
|
495
|
+
const offsetRect = getBoundingClientRect(offsetParent);
|
496
|
+
scale = getScale(offsetParent);
|
497
|
+
offsets.x = offsetRect.x + offsetParent.clientLeft;
|
498
|
+
offsets.y = offsetRect.y + offsetParent.clientTop;
|
499
|
+
}
|
500
|
+
}
|
501
|
+
return {
|
502
|
+
width: rect.width * scale.x,
|
503
|
+
height: rect.height * scale.y,
|
504
|
+
x: rect.x * scale.x - scroll.scrollLeft * scale.x + offsets.x,
|
505
|
+
y: rect.y * scale.y - scroll.scrollTop * scale.y + offsets.y
|
506
|
+
};
|
507
|
+
}
|
508
|
+
function getClientRects(element) {
|
509
|
+
return Array.from(element.getClientRects());
|
510
|
+
}
|
511
|
+
function getWindowScrollBarX(element) {
|
512
|
+
return getBoundingClientRect(getDocumentElement(element)).left + getNodeScroll(element).scrollLeft;
|
513
|
+
}
|
514
|
+
function getDocumentRect(element) {
|
515
|
+
const html = getDocumentElement(element);
|
516
|
+
const scroll = getNodeScroll(element);
|
517
|
+
const body = element.ownerDocument.body;
|
518
|
+
const width = max(html.scrollWidth, html.clientWidth, body.scrollWidth, body.clientWidth);
|
519
|
+
const height = max(html.scrollHeight, html.clientHeight, body.scrollHeight, body.clientHeight);
|
520
|
+
let x = -scroll.scrollLeft + getWindowScrollBarX(element);
|
521
|
+
const y = -scroll.scrollTop;
|
522
|
+
if (getComputedStyle(body).direction === "rtl") {
|
523
|
+
x += max(html.clientWidth, body.clientWidth) - width;
|
524
|
+
}
|
525
|
+
return {
|
526
|
+
width,
|
527
|
+
height,
|
528
|
+
x,
|
529
|
+
y
|
530
|
+
};
|
531
|
+
}
|
532
|
+
function getViewportRect(element, strategy) {
|
533
|
+
const win = getWindow(element);
|
534
|
+
const html = getDocumentElement(element);
|
535
|
+
const visualViewport = win.visualViewport;
|
536
|
+
let width = html.clientWidth;
|
537
|
+
let height = html.clientHeight;
|
538
|
+
let x = 0;
|
539
|
+
let y = 0;
|
540
|
+
if (visualViewport) {
|
541
|
+
width = visualViewport.width;
|
542
|
+
height = visualViewport.height;
|
543
|
+
const visualViewportBased = isWebKit();
|
544
|
+
if (!visualViewportBased || visualViewportBased && strategy === "fixed") {
|
545
|
+
x = visualViewport.offsetLeft;
|
546
|
+
y = visualViewport.offsetTop;
|
547
|
+
}
|
548
|
+
}
|
549
|
+
return {
|
550
|
+
width,
|
551
|
+
height,
|
552
|
+
x,
|
553
|
+
y
|
554
|
+
};
|
555
|
+
}
|
556
|
+
function getInnerBoundingClientRect(element, strategy) {
|
557
|
+
const clientRect = getBoundingClientRect(element, true, strategy === "fixed");
|
558
|
+
const top = clientRect.top + element.clientTop;
|
559
|
+
const left = clientRect.left + element.clientLeft;
|
560
|
+
const scale = isHTMLElement(element) ? getScale(element) : createCoords(1);
|
561
|
+
const width = element.clientWidth * scale.x;
|
562
|
+
const height = element.clientHeight * scale.y;
|
563
|
+
const x = left * scale.x;
|
564
|
+
const y = top * scale.y;
|
565
|
+
return {
|
566
|
+
width,
|
567
|
+
height,
|
568
|
+
x,
|
569
|
+
y
|
570
|
+
};
|
571
|
+
}
|
572
|
+
function getClientRectFromClippingAncestor(element, clippingAncestor, strategy) {
|
573
|
+
let rect;
|
574
|
+
if (clippingAncestor === "viewport") {
|
575
|
+
rect = getViewportRect(element, strategy);
|
576
|
+
} else if (clippingAncestor === "document") {
|
577
|
+
rect = getDocumentRect(getDocumentElement(element));
|
578
|
+
} else if (isElement(clippingAncestor)) {
|
579
|
+
rect = getInnerBoundingClientRect(clippingAncestor, strategy);
|
580
|
+
} else {
|
581
|
+
const visualOffsets = getVisualOffsets(element);
|
582
|
+
rect = __spreadProps(__spreadValues({}, clippingAncestor), {
|
583
|
+
x: clippingAncestor.x - visualOffsets.x,
|
584
|
+
y: clippingAncestor.y - visualOffsets.y
|
585
|
+
});
|
586
|
+
}
|
587
|
+
return rectToClientRect(rect);
|
588
|
+
}
|
589
|
+
function hasFixedPositionAncestor(element, stopNode) {
|
590
|
+
const parentNode = getParentNode(element);
|
591
|
+
if (parentNode === stopNode || !isElement(parentNode) || isLastTraversableNode(parentNode)) {
|
592
|
+
return false;
|
593
|
+
}
|
594
|
+
return getComputedStyle(parentNode).position === "fixed" || hasFixedPositionAncestor(parentNode, stopNode);
|
595
|
+
}
|
596
|
+
function getClippingElementAncestors(element, cache) {
|
597
|
+
const cachedResult = cache.get(element);
|
598
|
+
if (cachedResult) {
|
599
|
+
return cachedResult;
|
600
|
+
}
|
601
|
+
let result = getOverflowAncestors(element, [], false).filter((el) => isElement(el) && getNodeName(el) !== "body");
|
602
|
+
let currentContainingBlockComputedStyle = null;
|
603
|
+
const elementIsFixed = getComputedStyle(element).position === "fixed";
|
604
|
+
let currentNode = elementIsFixed ? getParentNode(element) : element;
|
605
|
+
while (isElement(currentNode) && !isLastTraversableNode(currentNode)) {
|
606
|
+
const computedStyle = getComputedStyle(currentNode);
|
607
|
+
const currentNodeIsContaining = isContainingBlock(currentNode);
|
608
|
+
if (!currentNodeIsContaining && computedStyle.position === "fixed") {
|
609
|
+
currentContainingBlockComputedStyle = null;
|
610
|
+
}
|
611
|
+
const shouldDropCurrentNode = elementIsFixed ? !currentNodeIsContaining && !currentContainingBlockComputedStyle : !currentNodeIsContaining && computedStyle.position === "static" && !!currentContainingBlockComputedStyle && ["absolute", "fixed"].includes(currentContainingBlockComputedStyle.position) || isOverflowElement(currentNode) && !currentNodeIsContaining && hasFixedPositionAncestor(element, currentNode);
|
612
|
+
if (shouldDropCurrentNode) {
|
613
|
+
result = result.filter((ancestor) => ancestor !== currentNode);
|
614
|
+
} else {
|
615
|
+
currentContainingBlockComputedStyle = computedStyle;
|
616
|
+
}
|
617
|
+
currentNode = getParentNode(currentNode);
|
618
|
+
}
|
619
|
+
cache.set(element, result);
|
620
|
+
return result;
|
621
|
+
}
|
622
|
+
function getClippingRect(_ref) {
|
623
|
+
let {
|
624
|
+
element,
|
625
|
+
boundary,
|
626
|
+
rootBoundary,
|
627
|
+
strategy
|
628
|
+
} = _ref;
|
629
|
+
const elementClippingAncestors = boundary === "clippingAncestors" ? isTopLayer(element) ? [] : getClippingElementAncestors(element, this._c) : [].concat(boundary);
|
630
|
+
const clippingAncestors = [...elementClippingAncestors, rootBoundary];
|
631
|
+
const firstClippingAncestor = clippingAncestors[0];
|
632
|
+
const clippingRect = clippingAncestors.reduce((accRect, clippingAncestor) => {
|
633
|
+
const rect = getClientRectFromClippingAncestor(element, clippingAncestor, strategy);
|
634
|
+
accRect.top = max(rect.top, accRect.top);
|
635
|
+
accRect.right = min(rect.right, accRect.right);
|
636
|
+
accRect.bottom = min(rect.bottom, accRect.bottom);
|
637
|
+
accRect.left = max(rect.left, accRect.left);
|
638
|
+
return accRect;
|
639
|
+
}, getClientRectFromClippingAncestor(element, firstClippingAncestor, strategy));
|
640
|
+
return {
|
641
|
+
width: clippingRect.right - clippingRect.left,
|
642
|
+
height: clippingRect.bottom - clippingRect.top,
|
643
|
+
x: clippingRect.left,
|
644
|
+
y: clippingRect.top
|
645
|
+
};
|
646
|
+
}
|
647
|
+
function getDimensions(element) {
|
648
|
+
const {
|
649
|
+
width,
|
650
|
+
height
|
651
|
+
} = getCssDimensions(element);
|
652
|
+
return {
|
653
|
+
width,
|
654
|
+
height
|
655
|
+
};
|
656
|
+
}
|
657
|
+
function getRectRelativeToOffsetParent(element, offsetParent, strategy) {
|
658
|
+
const isOffsetParentAnElement = isHTMLElement(offsetParent);
|
659
|
+
const documentElement = getDocumentElement(offsetParent);
|
660
|
+
const isFixed = strategy === "fixed";
|
661
|
+
const rect = getBoundingClientRect(element, true, isFixed, offsetParent);
|
662
|
+
let scroll = {
|
663
|
+
scrollLeft: 0,
|
664
|
+
scrollTop: 0
|
665
|
+
};
|
666
|
+
const offsets = createCoords(0);
|
667
|
+
if (isOffsetParentAnElement || !isOffsetParentAnElement && !isFixed) {
|
668
|
+
if (getNodeName(offsetParent) !== "body" || isOverflowElement(documentElement)) {
|
669
|
+
scroll = getNodeScroll(offsetParent);
|
670
|
+
}
|
671
|
+
if (isOffsetParentAnElement) {
|
672
|
+
const offsetRect = getBoundingClientRect(offsetParent, true, isFixed, offsetParent);
|
673
|
+
offsets.x = offsetRect.x + offsetParent.clientLeft;
|
674
|
+
offsets.y = offsetRect.y + offsetParent.clientTop;
|
675
|
+
} else if (documentElement) {
|
676
|
+
offsets.x = getWindowScrollBarX(documentElement);
|
677
|
+
}
|
678
|
+
}
|
679
|
+
const x = rect.left + scroll.scrollLeft - offsets.x;
|
680
|
+
const y = rect.top + scroll.scrollTop - offsets.y;
|
681
|
+
return {
|
682
|
+
x,
|
683
|
+
y,
|
684
|
+
width: rect.width,
|
685
|
+
height: rect.height
|
686
|
+
};
|
687
|
+
}
|
688
|
+
function isStaticPositioned(element) {
|
689
|
+
return getComputedStyle(element).position === "static";
|
690
|
+
}
|
691
|
+
function getTrueOffsetParent(element, polyfill) {
|
692
|
+
if (!isHTMLElement(element) || getComputedStyle(element).position === "fixed") {
|
693
|
+
return null;
|
694
|
+
}
|
695
|
+
if (polyfill) {
|
696
|
+
return polyfill(element);
|
697
|
+
}
|
698
|
+
return element.offsetParent;
|
699
|
+
}
|
700
|
+
function getOffsetParent(element, polyfill) {
|
701
|
+
const win = getWindow(element);
|
702
|
+
if (isTopLayer(element)) {
|
703
|
+
return win;
|
704
|
+
}
|
705
|
+
if (!isHTMLElement(element)) {
|
706
|
+
let svgOffsetParent = getParentNode(element);
|
707
|
+
while (svgOffsetParent && !isLastTraversableNode(svgOffsetParent)) {
|
708
|
+
if (isElement(svgOffsetParent) && !isStaticPositioned(svgOffsetParent)) {
|
709
|
+
return svgOffsetParent;
|
710
|
+
}
|
711
|
+
svgOffsetParent = getParentNode(svgOffsetParent);
|
712
|
+
}
|
713
|
+
return win;
|
714
|
+
}
|
715
|
+
let offsetParent = getTrueOffsetParent(element, polyfill);
|
716
|
+
while (offsetParent && isTableElement(offsetParent) && isStaticPositioned(offsetParent)) {
|
717
|
+
offsetParent = getTrueOffsetParent(offsetParent, polyfill);
|
718
|
+
}
|
719
|
+
if (offsetParent && isLastTraversableNode(offsetParent) && isStaticPositioned(offsetParent) && !isContainingBlock(offsetParent)) {
|
720
|
+
return win;
|
721
|
+
}
|
722
|
+
return offsetParent || getContainingBlock(element) || win;
|
723
|
+
}
|
724
|
+
var getElementRects = function(data) {
|
725
|
+
return __async(this, null, function* () {
|
726
|
+
const getOffsetParentFn = this.getOffsetParent || getOffsetParent;
|
727
|
+
const getDimensionsFn = this.getDimensions;
|
728
|
+
const floatingDimensions = yield getDimensionsFn(data.floating);
|
729
|
+
return {
|
730
|
+
reference: getRectRelativeToOffsetParent(data.reference, yield getOffsetParentFn(data.floating), data.strategy),
|
731
|
+
floating: {
|
732
|
+
x: 0,
|
733
|
+
y: 0,
|
734
|
+
width: floatingDimensions.width,
|
735
|
+
height: floatingDimensions.height
|
736
|
+
}
|
737
|
+
};
|
738
|
+
});
|
739
|
+
};
|
740
|
+
function isRTL(element) {
|
741
|
+
return getComputedStyle(element).direction === "rtl";
|
742
|
+
}
|
743
|
+
var platform = {
|
744
|
+
convertOffsetParentRelativeRectToViewportRelativeRect,
|
745
|
+
getDocumentElement,
|
746
|
+
getClippingRect,
|
747
|
+
getOffsetParent,
|
748
|
+
getElementRects,
|
749
|
+
getClientRects,
|
750
|
+
getDimensions,
|
751
|
+
getScale,
|
752
|
+
isElement,
|
753
|
+
isRTL
|
754
|
+
};
|
755
|
+
function observeMove(element, onMove) {
|
756
|
+
let io = null;
|
757
|
+
let timeoutId;
|
758
|
+
const root = getDocumentElement(element);
|
759
|
+
function cleanup() {
|
760
|
+
var _io;
|
761
|
+
clearTimeout(timeoutId);
|
762
|
+
(_io = io) == null || _io.disconnect();
|
763
|
+
io = null;
|
764
|
+
}
|
765
|
+
function refresh(skip, threshold) {
|
766
|
+
if (skip === void 0) {
|
767
|
+
skip = false;
|
768
|
+
}
|
769
|
+
if (threshold === void 0) {
|
770
|
+
threshold = 1;
|
771
|
+
}
|
772
|
+
cleanup();
|
773
|
+
const {
|
774
|
+
left,
|
775
|
+
top,
|
776
|
+
width,
|
777
|
+
height
|
778
|
+
} = element.getBoundingClientRect();
|
779
|
+
if (!skip) {
|
780
|
+
onMove();
|
781
|
+
}
|
782
|
+
if (!width || !height) {
|
783
|
+
return;
|
784
|
+
}
|
785
|
+
const insetTop = floor(top);
|
786
|
+
const insetRight = floor(root.clientWidth - (left + width));
|
787
|
+
const insetBottom = floor(root.clientHeight - (top + height));
|
788
|
+
const insetLeft = floor(left);
|
789
|
+
const rootMargin = -insetTop + "px " + -insetRight + "px " + -insetBottom + "px " + -insetLeft + "px";
|
790
|
+
const options = {
|
791
|
+
rootMargin,
|
792
|
+
threshold: max(0, min(1, threshold)) || 1
|
793
|
+
};
|
794
|
+
let isFirstUpdate = true;
|
795
|
+
function handleObserve(entries) {
|
796
|
+
const ratio = entries[0].intersectionRatio;
|
797
|
+
if (ratio !== threshold) {
|
798
|
+
if (!isFirstUpdate) {
|
799
|
+
return refresh();
|
800
|
+
}
|
801
|
+
if (!ratio) {
|
802
|
+
timeoutId = setTimeout(() => {
|
803
|
+
refresh(false, 1e-7);
|
804
|
+
}, 1e3);
|
805
|
+
} else {
|
806
|
+
refresh(false, ratio);
|
807
|
+
}
|
808
|
+
}
|
809
|
+
isFirstUpdate = false;
|
810
|
+
}
|
811
|
+
try {
|
812
|
+
io = new IntersectionObserver(handleObserve, __spreadProps(__spreadValues({}, options), {
|
813
|
+
// Handle <iframe>s
|
814
|
+
root: root.ownerDocument
|
815
|
+
}));
|
816
|
+
} catch (e) {
|
817
|
+
io = new IntersectionObserver(handleObserve, options);
|
818
|
+
}
|
819
|
+
io.observe(element);
|
820
|
+
}
|
821
|
+
refresh(true);
|
822
|
+
return cleanup;
|
823
|
+
}
|
824
|
+
function autoUpdate(reference, floating, update, options) {
|
825
|
+
if (options === void 0) {
|
826
|
+
options = {};
|
827
|
+
}
|
828
|
+
const {
|
829
|
+
ancestorScroll = true,
|
830
|
+
ancestorResize = true,
|
831
|
+
elementResize = typeof ResizeObserver === "function",
|
832
|
+
layoutShift = typeof IntersectionObserver === "function",
|
833
|
+
animationFrame = false
|
834
|
+
} = options;
|
835
|
+
const referenceEl = unwrapElement(reference);
|
836
|
+
const ancestors = ancestorScroll || ancestorResize ? [...referenceEl ? getOverflowAncestors(referenceEl) : [], ...getOverflowAncestors(floating)] : [];
|
837
|
+
ancestors.forEach((ancestor) => {
|
838
|
+
ancestorScroll && ancestor.addEventListener("scroll", update, {
|
839
|
+
passive: true
|
840
|
+
});
|
841
|
+
ancestorResize && ancestor.addEventListener("resize", update);
|
842
|
+
});
|
843
|
+
const cleanupIo = referenceEl && layoutShift ? observeMove(referenceEl, update) : null;
|
844
|
+
let reobserveFrame = -1;
|
845
|
+
let resizeObserver = null;
|
846
|
+
if (elementResize) {
|
847
|
+
resizeObserver = new ResizeObserver((_ref) => {
|
848
|
+
let [firstEntry] = _ref;
|
849
|
+
if (firstEntry && firstEntry.target === referenceEl && resizeObserver) {
|
850
|
+
resizeObserver.unobserve(floating);
|
851
|
+
cancelAnimationFrame(reobserveFrame);
|
852
|
+
reobserveFrame = requestAnimationFrame(() => {
|
853
|
+
var _resizeObserver;
|
854
|
+
(_resizeObserver = resizeObserver) == null || _resizeObserver.observe(floating);
|
855
|
+
});
|
856
|
+
}
|
857
|
+
update();
|
858
|
+
});
|
859
|
+
if (referenceEl && !animationFrame) {
|
860
|
+
resizeObserver.observe(referenceEl);
|
861
|
+
}
|
862
|
+
resizeObserver.observe(floating);
|
863
|
+
}
|
864
|
+
let frameId;
|
865
|
+
let prevRefRect = animationFrame ? getBoundingClientRect(reference) : null;
|
866
|
+
if (animationFrame) {
|
867
|
+
frameLoop();
|
868
|
+
}
|
869
|
+
function frameLoop() {
|
870
|
+
const nextRefRect = getBoundingClientRect(reference);
|
871
|
+
if (prevRefRect && (nextRefRect.x !== prevRefRect.x || nextRefRect.y !== prevRefRect.y || nextRefRect.width !== prevRefRect.width || nextRefRect.height !== prevRefRect.height)) {
|
872
|
+
update();
|
873
|
+
}
|
874
|
+
prevRefRect = nextRefRect;
|
875
|
+
frameId = requestAnimationFrame(frameLoop);
|
876
|
+
}
|
877
|
+
update();
|
878
|
+
return () => {
|
879
|
+
var _resizeObserver2;
|
880
|
+
ancestors.forEach((ancestor) => {
|
881
|
+
ancestorScroll && ancestor.removeEventListener("scroll", update);
|
882
|
+
ancestorResize && ancestor.removeEventListener("resize", update);
|
883
|
+
});
|
884
|
+
cleanupIo == null || cleanupIo();
|
885
|
+
(_resizeObserver2 = resizeObserver) == null || _resizeObserver2.disconnect();
|
886
|
+
resizeObserver = null;
|
887
|
+
if (animationFrame) {
|
888
|
+
cancelAnimationFrame(frameId);
|
889
|
+
}
|
890
|
+
};
|
891
|
+
}
|
892
|
+
var computePosition2 = (reference, floating, options) => {
|
893
|
+
const cache = /* @__PURE__ */ new Map();
|
894
|
+
const mergedOptions = __spreadValues({
|
895
|
+
platform
|
896
|
+
}, options);
|
897
|
+
const platformWithCache = __spreadProps(__spreadValues({}, mergedOptions.platform), {
|
898
|
+
_c: cache
|
899
|
+
});
|
900
|
+
return computePosition(reference, floating, __spreadProps(__spreadValues({}, mergedOptions), {
|
901
|
+
platform: platformWithCache
|
902
|
+
}));
|
903
|
+
};
|
904
|
+
|
905
|
+
// src/index.ts
|
906
|
+
var cleanupFns = [];
|
907
|
+
function mark(options = {}) {
|
908
|
+
try {
|
909
|
+
const {
|
910
|
+
selector = "button, input, a, select, textarea",
|
911
|
+
getLabel = (_, index) => index.toString(),
|
912
|
+
markAttribute = "data-mark-label",
|
913
|
+
markPlacement = "top-start",
|
914
|
+
markStyle = {
|
915
|
+
backgroundColor: "red",
|
916
|
+
color: "white",
|
917
|
+
padding: "2px 4px",
|
918
|
+
fontSize: "12px",
|
919
|
+
fontWeight: "bold"
|
920
|
+
},
|
921
|
+
boundingBoxStyle = {
|
922
|
+
outline: "2px dashed red",
|
923
|
+
backgroundColor: "transparent"
|
924
|
+
},
|
925
|
+
showBoundingBoxes = true,
|
926
|
+
containerElement = document.body,
|
927
|
+
viewPortOnly = false,
|
928
|
+
markClass = "",
|
929
|
+
boundingBoxClass = ""
|
930
|
+
} = options;
|
931
|
+
const isInViewport = (el) => {
|
932
|
+
const rect = el.getBoundingClientRect();
|
933
|
+
return rect.top < window.innerHeight && rect.bottom >= 0;
|
934
|
+
};
|
935
|
+
const elements = Array.from(
|
936
|
+
containerElement.querySelectorAll(selector)
|
937
|
+
).filter((el) => !viewPortOnly || isInViewport(el));
|
938
|
+
const markedElements = {};
|
939
|
+
const fragment = document.createDocumentFragment();
|
940
|
+
elements.forEach((element, index) => {
|
941
|
+
const label = getLabel(element, index);
|
942
|
+
const markElement = createMark(
|
943
|
+
element,
|
944
|
+
index,
|
945
|
+
markStyle,
|
946
|
+
label,
|
947
|
+
markPlacement,
|
948
|
+
markClass
|
949
|
+
);
|
950
|
+
fragment.appendChild(markElement);
|
951
|
+
const boundingBoxElement = showBoundingBoxes ? createBoundingBox(element, boundingBoxStyle, label, boundingBoxClass) : void 0;
|
952
|
+
if (boundingBoxElement) {
|
953
|
+
fragment.appendChild(boundingBoxElement);
|
954
|
+
}
|
955
|
+
markedElements[label] = { element, markElement, boundingBoxElement };
|
956
|
+
element.setAttribute(markAttribute, label);
|
957
|
+
});
|
958
|
+
document.body.appendChild(fragment);
|
959
|
+
document.documentElement.setAttribute("data-marked", "true");
|
960
|
+
return markedElements;
|
961
|
+
} catch (error) {
|
962
|
+
console.error("Error in mark function:", error);
|
963
|
+
throw error;
|
964
|
+
}
|
965
|
+
}
|
966
|
+
function createMark(element, index, style, label, markPlacement = "top-start", markClass) {
|
967
|
+
const markElement = document.createElement("div");
|
968
|
+
markElement.className = `webmarker ${markClass}`.trim();
|
969
|
+
markElement.id = `webmarker-${label}`;
|
970
|
+
markElement.textContent = label;
|
971
|
+
markElement.setAttribute("aria-hidden", "true");
|
972
|
+
positionElement(markElement, element, markPlacement, (x, y) => {
|
973
|
+
Object.assign(markElement.style, {
|
974
|
+
left: `${x}px`,
|
975
|
+
top: `${y}px`
|
976
|
+
});
|
977
|
+
});
|
978
|
+
applyStyle(
|
979
|
+
markElement,
|
980
|
+
{
|
981
|
+
zIndex: "999999999",
|
982
|
+
position: "absolute",
|
983
|
+
pointerEvents: "none"
|
984
|
+
},
|
985
|
+
typeof style === "function" ? style(element, index) : style
|
986
|
+
);
|
987
|
+
return markElement;
|
988
|
+
}
|
989
|
+
function createBoundingBox(element, style, label, boundingBoxClass) {
|
990
|
+
const boundingBoxElement = document.createElement("div");
|
991
|
+
boundingBoxElement.className = `webmarker-bounding-box ${boundingBoxClass}`.trim();
|
992
|
+
boundingBoxElement.id = `webmarker-bounding-box-${label}`;
|
993
|
+
boundingBoxElement.setAttribute("aria-hidden", "true");
|
994
|
+
positionElement(boundingBoxElement, element, "top-start", (x, y) => {
|
995
|
+
const { width, height } = element.getBoundingClientRect();
|
996
|
+
Object.assign(boundingBoxElement.style, {
|
997
|
+
left: `${x}px`,
|
998
|
+
top: `${y}px`,
|
999
|
+
width: `${width}px`,
|
1000
|
+
height: `${height}px`
|
1001
|
+
});
|
1002
|
+
});
|
1003
|
+
applyStyle(
|
1004
|
+
boundingBoxElement,
|
1005
|
+
{
|
1006
|
+
zIndex: "999999999",
|
1007
|
+
position: "absolute",
|
1008
|
+
pointerEvents: "none"
|
1009
|
+
},
|
1010
|
+
typeof style === "function" ? style(element, parseInt(label)) : style
|
1011
|
+
);
|
1012
|
+
return boundingBoxElement;
|
1013
|
+
}
|
1014
|
+
function positionElement(target, anchor, placement, updateCallback) {
|
1015
|
+
function updatePosition() {
|
1016
|
+
computePosition2(anchor, target, { placement }).then(({ x, y }) => {
|
1017
|
+
updateCallback(x, y);
|
1018
|
+
});
|
1019
|
+
}
|
1020
|
+
cleanupFns.push(autoUpdate(anchor, target, updatePosition));
|
1021
|
+
}
|
1022
|
+
function applyStyle(element, defaultStyle, customStyle) {
|
1023
|
+
Object.assign(element.style, defaultStyle, customStyle);
|
1024
|
+
}
|
1025
|
+
function unmark() {
|
1026
|
+
var _a;
|
1027
|
+
const markAttribute = ((_a = document.querySelector("[data-mark-label]")) == null ? void 0 : _a.getAttribute("data-mark-label")) ? "data-mark-label" : "data-webmarker-label";
|
1028
|
+
document.querySelectorAll(`[${markAttribute}]`).forEach((el) => {
|
1029
|
+
el.removeAttribute(markAttribute);
|
1030
|
+
});
|
1031
|
+
document.querySelectorAll(".webmarker, .webmarker-bounding-box").forEach((el) => el.remove());
|
1032
|
+
document.documentElement.removeAttribute("data-marked");
|
1033
|
+
cleanupFns.forEach((fn) => fn());
|
1034
|
+
cleanupFns = [];
|
1035
|
+
}
|
1036
|
+
function isMarked() {
|
1037
|
+
return document.documentElement.hasAttribute("data-marked");
|
1038
|
+
}
|
1039
|
+
if (typeof window !== "undefined") {
|
1040
|
+
window["mark"] = mark;
|
1041
|
+
window["unmark"] = unmark;
|
1042
|
+
window["isMarked"] = isMarked;
|
1043
|
+
}
|
1044
|
+
export {
|
1045
|
+
isMarked,
|
1046
|
+
mark,
|
1047
|
+
unmark
|
1048
|
+
};
|