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