@spscommerce/positioning 8.45.4 → 8.45.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.js +72 -67
- package/lib/index.umd.cjs +1 -1
- package/package.json +5 -5
package/lib/index.js
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
|
-
import { onNextTick as
|
|
2
|
-
var S = /* @__PURE__ */ ((
|
|
1
|
+
import { onNextTick as j, lockedToAnimationFrames as U } from "@spscommerce/utils";
|
|
2
|
+
var S = /* @__PURE__ */ ((d) => (d.TOP_LEFT = "top left", d.TOP_MIDDLE = "top middle", d.TOP_RIGHT = "top right", d.RIGHT_TOP = "right top", d.RIGHT_MIDDLE = "right middle", d.RIGHT_BOTTOM = "right bottom", d.BOTTOM_RIGHT = "bottom right", d.BOTTOM_MIDDLE = "bottom middle", d.BOTTOM_LEFT = "bottom left", d.LEFT_BOTTOM = "left bottom", d.LEFT_MIDDLE = "left middle", d.LEFT_TOP = "left top", d))(S || {}), M = /* @__PURE__ */ ((d) => (d.TOP_LEFT = "top left", d.TOP_RIGHT = "top right", d.BOTTOM_LEFT = "bottom left", d.BOTTOM_RIGHT = "bottom right", d))(M || {});
|
|
3
3
|
const V = {
|
|
4
4
|
anchor: M.TOP_LEFT,
|
|
5
5
|
offsets: [],
|
|
6
6
|
position: S.TOP_LEFT
|
|
7
7
|
};
|
|
8
|
+
function q(d) {
|
|
9
|
+
return d && d.__esModule && Object.prototype.hasOwnProperty.call(d, "default") ? d.default : d;
|
|
10
|
+
}
|
|
8
11
|
var A = {}, F;
|
|
9
|
-
function
|
|
10
|
-
return F || (F = 1, function() {
|
|
12
|
+
function G() {
|
|
13
|
+
return F || (F = 1, (function() {
|
|
11
14
|
if (typeof window != "object")
|
|
12
15
|
return;
|
|
13
16
|
if ("IntersectionObserver" in window && "IntersectionObserverEntry" in window && "intersectionRatio" in window.IntersectionObserverEntry.prototype) {
|
|
@@ -22,18 +25,18 @@ function q() {
|
|
|
22
25
|
);
|
|
23
26
|
return;
|
|
24
27
|
}
|
|
25
|
-
function
|
|
28
|
+
function d(t) {
|
|
26
29
|
try {
|
|
27
30
|
return t.defaultView && t.defaultView.frameElement || null;
|
|
28
31
|
} catch {
|
|
29
32
|
return null;
|
|
30
33
|
}
|
|
31
34
|
}
|
|
32
|
-
var n = function(t) {
|
|
33
|
-
for (var e = t, o =
|
|
34
|
-
e = o.ownerDocument, o =
|
|
35
|
+
var n = (function(t) {
|
|
36
|
+
for (var e = t, o = d(e); o; )
|
|
37
|
+
e = o.ownerDocument, o = d(e);
|
|
35
38
|
return e;
|
|
36
|
-
}(window.document), i = [], p = null, f = null;
|
|
39
|
+
})(window.document), i = [], p = null, f = null;
|
|
37
40
|
function w(t) {
|
|
38
41
|
this.time = t.time, this.target = t.target, this.rootBounds = b(t.rootBounds), this.boundingClientRect = b(t.boundingClientRect), this.intersectionRect = b(t.intersectionRect || y()), this.isIntersecting = !!t.intersectionRect;
|
|
39
42
|
var e = this.boundingClientRect, o = e.width * e.height, s = this.intersectionRect, u = s.width * s.height;
|
|
@@ -45,7 +48,7 @@ function q() {
|
|
|
45
48
|
throw new Error("callback must be a function");
|
|
46
49
|
if (o.root && o.root.nodeType != 1 && o.root.nodeType != 9)
|
|
47
50
|
throw new Error("root must be a Document or Element");
|
|
48
|
-
this._checkForIntersections =
|
|
51
|
+
this._checkForIntersections = g(
|
|
49
52
|
this._checkForIntersections.bind(this),
|
|
50
53
|
this.THROTTLE_TIMEOUT
|
|
51
54
|
), this._callback = t, this._observationTargets = [], this._queuedEntries = [], this._rootMarginValues = this._parseRootMargin(o.rootMargin), this.thresholds = this._initThresholds(o.threshold), this.root = o.root || null, this.rootMargin = this._rootMarginValues.map(function(s) {
|
|
@@ -54,7 +57,7 @@ function q() {
|
|
|
54
57
|
}
|
|
55
58
|
a.prototype.THROTTLE_TIMEOUT = 100, a.prototype.POLL_INTERVAL = null, a.prototype.USE_MUTATION_OBSERVER = !0, a._setupCrossOriginUpdater = function() {
|
|
56
59
|
return p || (p = function(t, e) {
|
|
57
|
-
!t || !e ? f = y() : f =
|
|
60
|
+
!t || !e ? f = y() : f = R(t, e), i.forEach(function(o) {
|
|
58
61
|
o._checkForIntersections();
|
|
59
62
|
});
|
|
60
63
|
}), p;
|
|
@@ -108,7 +111,7 @@ function q() {
|
|
|
108
111
|
});
|
|
109
112
|
var O = this.root && (this.root.ownerDocument || this.root) || n;
|
|
110
113
|
if (t != O) {
|
|
111
|
-
var E =
|
|
114
|
+
var E = d(t);
|
|
112
115
|
E && this._monitorIntersections(E.ownerDocument);
|
|
113
116
|
}
|
|
114
117
|
}
|
|
@@ -120,7 +123,7 @@ function q() {
|
|
|
120
123
|
if (I == t)
|
|
121
124
|
return !0;
|
|
122
125
|
for (; I && I != o; ) {
|
|
123
|
-
var L =
|
|
126
|
+
var L = d(I);
|
|
124
127
|
if (I = L && L.ownerDocument, I == t)
|
|
125
128
|
return !0;
|
|
126
129
|
}
|
|
@@ -129,7 +132,7 @@ function q() {
|
|
|
129
132
|
if (!s) {
|
|
130
133
|
var u = this._monitoringUnsubscribes[e];
|
|
131
134
|
if (this._monitoringDocuments.splice(e, 1), this._monitoringUnsubscribes.splice(e, 1), u(), t != o) {
|
|
132
|
-
var O =
|
|
135
|
+
var O = d(t);
|
|
133
136
|
O && this._unmonitorIntersections(O.ownerDocument);
|
|
134
137
|
}
|
|
135
138
|
}
|
|
@@ -166,7 +169,7 @@ function q() {
|
|
|
166
169
|
p && !this.root ? !f || f.width == 0 && f.height == 0 ? (u = null, E = null, s = null) : E = f : E = o;
|
|
167
170
|
else {
|
|
168
171
|
var L = _(u), D = L && T(L), B = L && this._computeTargetAndRootIntersection(L, D, o);
|
|
169
|
-
D && B ? (u = L, E =
|
|
172
|
+
D && B ? (u = L, E = R(D, B)) : (u = null, s = null);
|
|
170
173
|
}
|
|
171
174
|
else {
|
|
172
175
|
var C = u.ownerDocument;
|
|
@@ -179,10 +182,10 @@ function q() {
|
|
|
179
182
|
}
|
|
180
183
|
}, a.prototype._getRootRect = function() {
|
|
181
184
|
var t;
|
|
182
|
-
if (this.root && !
|
|
185
|
+
if (this.root && !x(this.root))
|
|
183
186
|
t = T(this.root);
|
|
184
187
|
else {
|
|
185
|
-
var e =
|
|
188
|
+
var e = x(this.root) ? this.root : n, o = e.documentElement, s = e.body;
|
|
186
189
|
t = {
|
|
187
190
|
top: 0,
|
|
188
191
|
left: 0,
|
|
@@ -225,7 +228,7 @@ function q() {
|
|
|
225
228
|
function m() {
|
|
226
229
|
return window.performance && performance.now && performance.now();
|
|
227
230
|
}
|
|
228
|
-
function
|
|
231
|
+
function g(t, e) {
|
|
229
232
|
var o = null;
|
|
230
233
|
return function() {
|
|
231
234
|
o || (o = setTimeout(function() {
|
|
@@ -287,7 +290,7 @@ function q() {
|
|
|
287
290
|
height: t.height
|
|
288
291
|
};
|
|
289
292
|
}
|
|
290
|
-
function
|
|
293
|
+
function R(t, e) {
|
|
291
294
|
var o = e.top - t.top, s = e.left - t.left;
|
|
292
295
|
return {
|
|
293
296
|
top: o,
|
|
@@ -308,33 +311,33 @@ function q() {
|
|
|
308
311
|
function _(t) {
|
|
309
312
|
var e = t.parentNode;
|
|
310
313
|
return t.nodeType == /* DOCUMENT */
|
|
311
|
-
9 && t != n ?
|
|
314
|
+
9 && t != n ? d(t) : (e && e.assignedSlot && (e = e.assignedSlot.parentNode), e && e.nodeType == 11 && e.host ? e.host : e);
|
|
312
315
|
}
|
|
313
|
-
function
|
|
316
|
+
function x(t) {
|
|
314
317
|
return t && t.nodeType === 9;
|
|
315
318
|
}
|
|
316
319
|
window.IntersectionObserver = a, window.IntersectionObserverEntry = w;
|
|
317
|
-
}()), A;
|
|
320
|
+
})()), A;
|
|
318
321
|
}
|
|
319
|
-
|
|
322
|
+
G();
|
|
320
323
|
var P = { exports: {} }, H;
|
|
321
|
-
function
|
|
322
|
-
return H || (H = 1, function(
|
|
324
|
+
function z() {
|
|
325
|
+
return H || (H = 1, (function(d) {
|
|
323
326
|
var n = Object.prototype.hasOwnProperty, i = "~";
|
|
324
327
|
function p() {
|
|
325
328
|
}
|
|
326
329
|
Object.create && (p.prototype = /* @__PURE__ */ Object.create(null), new p().__proto__ || (i = !1));
|
|
327
|
-
function f(
|
|
328
|
-
this.fn =
|
|
330
|
+
function f(g, c, l) {
|
|
331
|
+
this.fn = g, this.context = c, this.once = l || !1;
|
|
329
332
|
}
|
|
330
|
-
function w(
|
|
333
|
+
function w(g, c, l, v, T) {
|
|
331
334
|
if (typeof l != "function")
|
|
332
335
|
throw new TypeError("The listener must be a function");
|
|
333
|
-
var y = new f(l, v ||
|
|
334
|
-
return
|
|
336
|
+
var y = new f(l, v || g, T), b = i ? i + c : c;
|
|
337
|
+
return g._events[b] ? g._events[b].fn ? g._events[b] = [g._events[b], y] : g._events[b].push(y) : (g._events[b] = y, g._eventsCount++), g;
|
|
335
338
|
}
|
|
336
|
-
function a(
|
|
337
|
-
--
|
|
339
|
+
function a(g, c) {
|
|
340
|
+
--g._eventsCount === 0 ? g._events = new p() : delete g._events[c];
|
|
338
341
|
}
|
|
339
342
|
function m() {
|
|
340
343
|
this._events = new p(), this._eventsCount = 0;
|
|
@@ -356,9 +359,9 @@ function G() {
|
|
|
356
359
|
var l = i ? i + c : c, v = this._events[l];
|
|
357
360
|
return v ? v.fn ? 1 : v.length : 0;
|
|
358
361
|
}, m.prototype.emit = function(c, l, v, T, y, b) {
|
|
359
|
-
var
|
|
360
|
-
if (!this._events[
|
|
361
|
-
var h = this._events[
|
|
362
|
+
var R = i ? i + c : c;
|
|
363
|
+
if (!this._events[R]) return !1;
|
|
364
|
+
var h = this._events[R], _ = arguments.length, x, t;
|
|
362
365
|
if (h.fn) {
|
|
363
366
|
switch (h.once && this.removeListener(c, h.fn, void 0, !0), _) {
|
|
364
367
|
case 1:
|
|
@@ -374,9 +377,9 @@ function G() {
|
|
|
374
377
|
case 6:
|
|
375
378
|
return h.fn.call(h.context, l, v, T, y, b), !0;
|
|
376
379
|
}
|
|
377
|
-
for (t = 1,
|
|
378
|
-
|
|
379
|
-
h.fn.apply(h.context,
|
|
380
|
+
for (t = 1, x = new Array(_ - 1); t < _; t++)
|
|
381
|
+
x[t - 1] = arguments[t];
|
|
382
|
+
h.fn.apply(h.context, x);
|
|
380
383
|
} else {
|
|
381
384
|
var e = h.length, o;
|
|
382
385
|
for (t = 0; t < e; t++)
|
|
@@ -394,9 +397,9 @@ function G() {
|
|
|
394
397
|
h[t].fn.call(h[t].context, l, v, T);
|
|
395
398
|
break;
|
|
396
399
|
default:
|
|
397
|
-
if (!
|
|
398
|
-
|
|
399
|
-
h[t].fn.apply(h[t].context,
|
|
400
|
+
if (!x) for (o = 1, x = new Array(_ - 1); o < _; o++)
|
|
401
|
+
x[o - 1] = arguments[o];
|
|
402
|
+
h[t].fn.apply(h[t].context, x);
|
|
400
403
|
}
|
|
401
404
|
}
|
|
402
405
|
return !0;
|
|
@@ -413,21 +416,23 @@ function G() {
|
|
|
413
416
|
if (b.fn)
|
|
414
417
|
b.fn === l && (!T || b.once) && (!v || b.context === v) && a(this, y);
|
|
415
418
|
else {
|
|
416
|
-
for (var
|
|
417
|
-
(b[
|
|
419
|
+
for (var R = 0, h = [], _ = b.length; R < _; R++)
|
|
420
|
+
(b[R].fn !== l || T && !b[R].once || v && b[R].context !== v) && h.push(b[R]);
|
|
418
421
|
h.length ? this._events[y] = h.length === 1 ? h[0] : h : a(this, y);
|
|
419
422
|
}
|
|
420
423
|
return this;
|
|
421
424
|
}, m.prototype.removeAllListeners = function(c) {
|
|
422
425
|
var l;
|
|
423
426
|
return c ? (l = i ? i + c : c, this._events[l] && a(this, l)) : (this._events = new p(), this._eventsCount = 0), this;
|
|
424
|
-
}, m.prototype.off = m.prototype.removeListener, m.prototype.addListener = m.prototype.on, m.prefixed = i, m.EventEmitter = m,
|
|
425
|
-
}(P)), P.exports;
|
|
427
|
+
}, m.prototype.off = m.prototype.removeListener, m.prototype.addListener = m.prototype.on, m.prefixed = i, m.EventEmitter = m, d.exports = m;
|
|
428
|
+
})(P)), P.exports;
|
|
426
429
|
}
|
|
427
|
-
var
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
430
|
+
var W = z();
|
|
431
|
+
const $ = /* @__PURE__ */ q(W);
|
|
432
|
+
var Y = Object.defineProperty, J = Object.getOwnPropertyDescriptor, K = (d, n, i, p) => {
|
|
433
|
+
for (var f = J(n, i), w = d.length - 1, a; w >= 0; w--)
|
|
434
|
+
(a = d[w]) && (f = a(n, i, f) || f);
|
|
435
|
+
return f && Y(n, i, f), f;
|
|
431
436
|
};
|
|
432
437
|
const k = 60;
|
|
433
438
|
var r;
|
|
@@ -480,7 +485,7 @@ const N = (r = class {
|
|
|
480
485
|
throw new Error(
|
|
481
486
|
"You must provide an element for the relativeTo option to position an element."
|
|
482
487
|
);
|
|
483
|
-
r.elements.set(n, p),
|
|
488
|
+
r.elements.set(n, p), j(() => {
|
|
484
489
|
r.fixElementPosition(n), r.viewportObserver.observe(n), n.style.visibility = "", r.checkCollisions(n);
|
|
485
490
|
});
|
|
486
491
|
}
|
|
@@ -560,11 +565,11 @@ const N = (r = class {
|
|
|
560
565
|
position: "fixed",
|
|
561
566
|
zIndex: p.zIndex || ""
|
|
562
567
|
});
|
|
563
|
-
let
|
|
568
|
+
let g, c;
|
|
564
569
|
const l = p.position.split(" "), v = p.offsets[0] || 0, T = p.offsets[1] || 0;
|
|
565
|
-
switch (
|
|
570
|
+
switch (g = 0, c = 0, l[0]) {
|
|
566
571
|
case "top":
|
|
567
|
-
|
|
572
|
+
g = a.top - w.height - v;
|
|
568
573
|
break;
|
|
569
574
|
case "left":
|
|
570
575
|
c = a.left - m - v;
|
|
@@ -573,7 +578,7 @@ const N = (r = class {
|
|
|
573
578
|
c = a.right + v;
|
|
574
579
|
break;
|
|
575
580
|
case "bottom":
|
|
576
|
-
|
|
581
|
+
g = a.bottom + v;
|
|
577
582
|
break;
|
|
578
583
|
default:
|
|
579
584
|
throw new Error(`${p.position} is not a valid position`);
|
|
@@ -583,13 +588,13 @@ const N = (r = class {
|
|
|
583
588
|
c = a.left - T;
|
|
584
589
|
break;
|
|
585
590
|
case "top":
|
|
586
|
-
|
|
591
|
+
g = a.top - T;
|
|
587
592
|
break;
|
|
588
593
|
case "middle":
|
|
589
|
-
l[0] === "top" || l[0] === "bottom" ? c = a.left + a.width / 2 - m / 2 + T : (l[0] === "left" || l[0] === "right") && (
|
|
594
|
+
l[0] === "top" || l[0] === "bottom" ? c = a.left + a.width / 2 - m / 2 + T : (l[0] === "left" || l[0] === "right") && (g = a.top + a.height / 2 - w.height / 2 + T);
|
|
590
595
|
break;
|
|
591
596
|
case "bottom":
|
|
592
|
-
|
|
597
|
+
g = a.bottom - w.height + T;
|
|
593
598
|
break;
|
|
594
599
|
case "right":
|
|
595
600
|
c = a.right - m + T;
|
|
@@ -597,11 +602,11 @@ const N = (r = class {
|
|
|
597
602
|
default:
|
|
598
603
|
throw new Error(`${p.position} is not a valid position`);
|
|
599
604
|
}
|
|
600
|
-
const y =
|
|
605
|
+
const y = g + w.height, b = c + w.width, R = `${Math.round(g)}px`, h = `${Math.round(f.bottom - y)}px`, _ = `${Math.round(c)}px`, x = `${Math.round(f.right - b)}px`;
|
|
601
606
|
switch (p.anchor) {
|
|
602
607
|
case M.TOP_LEFT:
|
|
603
608
|
Object.assign(n.style, {
|
|
604
|
-
top:
|
|
609
|
+
top: R,
|
|
605
610
|
bottom: "auto",
|
|
606
611
|
left: _,
|
|
607
612
|
right: "auto"
|
|
@@ -609,10 +614,10 @@ const N = (r = class {
|
|
|
609
614
|
break;
|
|
610
615
|
case M.TOP_RIGHT:
|
|
611
616
|
Object.assign(n.style, {
|
|
612
|
-
top:
|
|
617
|
+
top: R,
|
|
613
618
|
bottom: "auto",
|
|
614
619
|
left: "auto",
|
|
615
|
-
right:
|
|
620
|
+
right: x
|
|
616
621
|
});
|
|
617
622
|
break;
|
|
618
623
|
case M.BOTTOM_LEFT:
|
|
@@ -628,7 +633,7 @@ const N = (r = class {
|
|
|
628
633
|
top: "auto",
|
|
629
634
|
bottom: h,
|
|
630
635
|
left: "auto",
|
|
631
|
-
right:
|
|
636
|
+
right: x
|
|
632
637
|
});
|
|
633
638
|
break;
|
|
634
639
|
}
|
|
@@ -672,20 +677,20 @@ const N = (r = class {
|
|
|
672
677
|
reposition(n, i) {
|
|
673
678
|
r.reposition(n, i);
|
|
674
679
|
}
|
|
675
|
-
}, r.elements = /* @__PURE__ */ new Map(), r.registeredScrollParents = /* @__PURE__ */ new Set(), r.events = new
|
|
680
|
+
}, r.elements = /* @__PURE__ */ new Map(), r.registeredScrollParents = /* @__PURE__ */ new Set(), r.events = new $(), r.viewportObserver = new IntersectionObserver(
|
|
676
681
|
r.onViewportIntersection,
|
|
677
682
|
{
|
|
678
683
|
rootMargin: `-${k}px 0px 0px`,
|
|
679
684
|
threshold: 1
|
|
680
685
|
}
|
|
681
686
|
), r);
|
|
682
|
-
|
|
683
|
-
|
|
687
|
+
K([
|
|
688
|
+
U
|
|
684
689
|
], N, "update");
|
|
685
|
-
let
|
|
690
|
+
let X = N;
|
|
686
691
|
export {
|
|
687
692
|
V as DEFAULT_POSITIONING_OPTIONS,
|
|
688
693
|
S as Position,
|
|
689
694
|
M as PositionAnchor,
|
|
690
|
-
|
|
695
|
+
X as PositioningService
|
|
691
696
|
};
|
package/lib/index.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(D,k){typeof exports=="object"&&typeof module<"u"?k(exports,require("@spscommerce/utils")):typeof define=="function"&&define.amd?define(["exports","@spscommerce/utils"],k):(D=typeof globalThis<"u"?globalThis:D||self,k(D.Positioning={},D.utils))})(this,function(D,k){"use strict";var r;var A=(g=>(g.TOP_LEFT="top left",g.TOP_MIDDLE="top middle",g.TOP_RIGHT="top right",g.RIGHT_TOP="right top",g.RIGHT_MIDDLE="right middle",g.RIGHT_BOTTOM="right bottom",g.BOTTOM_RIGHT="bottom right",g.BOTTOM_MIDDLE="bottom middle",g.BOTTOM_LEFT="bottom left",g.LEFT_BOTTOM="left bottom",g.LEFT_MIDDLE="left middle",g.LEFT_TOP="left top",g))(A||{}),P=(g=>(g.TOP_LEFT="top left",g.TOP_RIGHT="top right",g.BOTTOM_LEFT="bottom left",g.BOTTOM_RIGHT="bottom right",g))(P||{});const F={anchor:P.TOP_LEFT,offsets:[],position:A.TOP_LEFT};var S={},N;function q(){return N||(N=1,function(){if(typeof window!="object")return;if("IntersectionObserver"in window&&"IntersectionObserverEntry"in window&&"intersectionRatio"in window.IntersectionObserverEntry.prototype){"isIntersecting"in window.IntersectionObserverEntry.prototype||Object.defineProperty(window.IntersectionObserverEntry.prototype,"isIntersecting",{get:function(){return this.intersectionRatio>0}});return}function g(t){try{return t.defaultView&&t.defaultView.frameElement||null}catch{return null}}var n=function(t){for(var e=t,o=g(e);o;)e=o.ownerDocument,o=g(e);return e}(window.document),i=[],p=null,f=null;function w(t){this.time=t.time,this.target=t.target,this.rootBounds=b(t.rootBounds),this.boundingClientRect=b(t.boundingClientRect),this.intersectionRect=b(t.intersectionRect||y()),this.isIntersecting=!!t.intersectionRect;var e=this.boundingClientRect,o=e.width*e.height,s=this.intersectionRect,u=s.width*s.height;o?this.intersectionRatio=Number((u/o).toFixed(4)):this.intersectionRatio=this.isIntersecting?1:0}function a(t,e){var o=e||{};if(typeof t!="function")throw new Error("callback must be a function");if(o.root&&o.root.nodeType!=1&&o.root.nodeType!=9)throw new Error("root must be a Document or Element");this._checkForIntersections=d(this._checkForIntersections.bind(this),this.THROTTLE_TIMEOUT),this._callback=t,this._observationTargets=[],this._queuedEntries=[],this._rootMarginValues=this._parseRootMargin(o.rootMargin),this.thresholds=this._initThresholds(o.threshold),this.root=o.root||null,this.rootMargin=this._rootMarginValues.map(function(s){return s.value+s.unit}).join(" "),this._monitoringDocuments=[],this._monitoringUnsubscribes=[]}a.prototype.THROTTLE_TIMEOUT=100,a.prototype.POLL_INTERVAL=null,a.prototype.USE_MUTATION_OBSERVER=!0,a._setupCrossOriginUpdater=function(){return p||(p=function(t,e){!t||!e?f=y():f=R(t,e),i.forEach(function(o){o._checkForIntersections()})}),p},a._resetCrossOriginUpdater=function(){p=null,f=null},a.prototype.observe=function(t){var e=this._observationTargets.some(function(o){return o.element==t});if(!e){if(!(t&&t.nodeType==1))throw new Error("target must be an Element");this._registerInstance(),this._observationTargets.push({element:t,entry:null}),this._monitorIntersections(t.ownerDocument),this._checkForIntersections()}},a.prototype.unobserve=function(t){this._observationTargets=this._observationTargets.filter(function(e){return e.element!=t}),this._unmonitorIntersections(t.ownerDocument),this._observationTargets.length==0&&this._unregisterInstance()},a.prototype.disconnect=function(){this._observationTargets=[],this._unmonitorAllIntersections(),this._unregisterInstance()},a.prototype.takeRecords=function(){var t=this._queuedEntries.slice();return this._queuedEntries=[],t},a.prototype._initThresholds=function(t){var e=t||[0];return Array.isArray(e)||(e=[e]),e.sort().filter(function(o,s,u){if(typeof o!="number"||isNaN(o)||o<0||o>1)throw new Error("threshold must be a number between 0 and 1 inclusively");return o!==u[s-1]})},a.prototype._parseRootMargin=function(t){var e=t||"0px",o=e.split(/\s+/).map(function(s){var u=/^(-?\d*\.?\d+)(px|%)$/.exec(s);if(!u)throw new Error("rootMargin must be specified in pixels or percent");return{value:parseFloat(u[1]),unit:u[2]}});return o[1]=o[1]||o[0],o[2]=o[2]||o[0],o[3]=o[3]||o[1],o},a.prototype._monitorIntersections=function(t){var e=t.defaultView;if(e&&this._monitoringDocuments.indexOf(t)==-1){var o=this._checkForIntersections,s=null,u=null;this.POLL_INTERVAL?s=e.setInterval(o,this.POLL_INTERVAL):(c(e,"resize",o,!0),c(t,"scroll",o,!0),this.USE_MUTATION_OBSERVER&&"MutationObserver"in e&&(u=new e.MutationObserver(o),u.observe(t,{attributes:!0,childList:!0,characterData:!0,subtree:!0}))),this._monitoringDocuments.push(t),this._monitoringUnsubscribes.push(function(){var I=t.defaultView;I&&(s&&I.clearInterval(s),l(I,"resize",o,!0)),l(t,"scroll",o,!0),u&&u.disconnect()});var O=this.root&&(this.root.ownerDocument||this.root)||n;if(t!=O){var E=g(t);E&&this._monitorIntersections(E.ownerDocument)}}},a.prototype._unmonitorIntersections=function(t){var e=this._monitoringDocuments.indexOf(t);if(e!=-1){var o=this.root&&(this.root.ownerDocument||this.root)||n,s=this._observationTargets.some(function(E){var I=E.element.ownerDocument;if(I==t)return!0;for(;I&&I!=o;){var L=g(I);if(I=L&&L.ownerDocument,I==t)return!0}return!1});if(!s){var u=this._monitoringUnsubscribes[e];if(this._monitoringDocuments.splice(e,1),this._monitoringUnsubscribes.splice(e,1),u(),t!=o){var O=g(t);O&&this._unmonitorIntersections(O.ownerDocument)}}}},a.prototype._unmonitorAllIntersections=function(){var t=this._monitoringUnsubscribes.slice(0);this._monitoringDocuments.length=0,this._monitoringUnsubscribes.length=0;for(var e=0;e<t.length;e++)t[e]()},a.prototype._checkForIntersections=function(){if(!(!this.root&&p&&!f)){var t=this._rootIsInDom(),e=t?this._getRootRect():y();this._observationTargets.forEach(function(o){var s=o.element,u=T(s),O=this._rootContainsTarget(s),E=o.entry,I=t&&O&&this._computeTargetAndRootIntersection(s,u,e),L=null;this._rootContainsTarget(s)?(!p||this.root)&&(L=e):L=y();var M=o.entry=new w({time:m(),target:s,boundingClientRect:u,rootBounds:L,intersectionRect:I});E?t&&O?this._hasCrossedThreshold(E,M)&&this._queuedEntries.push(M):E&&E.isIntersecting&&this._queuedEntries.push(M):this._queuedEntries.push(M)},this),this._queuedEntries.length&&this._callback(this.takeRecords(),this)}},a.prototype._computeTargetAndRootIntersection=function(t,e,o){if(window.getComputedStyle(t).display!="none"){for(var s=e,u=_(t),O=!1;!O&&u;){var E=null,I=u.nodeType==1?window.getComputedStyle(u):{};if(I.display=="none")return null;if(u==this.root||u.nodeType==9)if(O=!0,u==this.root||u==n)p&&!this.root?!f||f.width==0&&f.height==0?(u=null,E=null,s=null):E=f:E=o;else{var L=_(u),M=L&&T(L),U=L&&this._computeTargetAndRootIntersection(L,M,o);M&&U?(u=L,E=R(M,U)):(u=null,s=null)}else{var V=u.ownerDocument;u!=V.body&&u!=V.documentElement&&I.overflow!="visible"&&(E=T(u))}if(E&&(s=v(E,s)),!s)break;u=u&&_(u)}return s}},a.prototype._getRootRect=function(){var t;if(this.root&&!x(this.root))t=T(this.root);else{var e=x(this.root)?this.root:n,o=e.documentElement,s=e.body;t={top:0,left:0,right:o.clientWidth||s.clientWidth,width:o.clientWidth||s.clientWidth,bottom:o.clientHeight||s.clientHeight,height:o.clientHeight||s.clientHeight}}return this._expandRectByRootMargin(t)},a.prototype._expandRectByRootMargin=function(t){var e=this._rootMarginValues.map(function(s,u){return s.unit=="px"?s.value:s.value*(u%2?t.width:t.height)/100}),o={top:t.top-e[0],right:t.right+e[1],bottom:t.bottom+e[2],left:t.left-e[3]};return o.width=o.right-o.left,o.height=o.bottom-o.top,o},a.prototype._hasCrossedThreshold=function(t,e){var o=t&&t.isIntersecting?t.intersectionRatio||0:-1,s=e.isIntersecting?e.intersectionRatio||0:-1;if(o!==s)for(var u=0;u<this.thresholds.length;u++){var O=this.thresholds[u];if(O==o||O==s||O<o!=O<s)return!0}},a.prototype._rootIsInDom=function(){return!this.root||h(n,this.root)},a.prototype._rootContainsTarget=function(t){var e=this.root&&(this.root.ownerDocument||this.root)||n;return h(e,t)&&(!this.root||e==t.ownerDocument)},a.prototype._registerInstance=function(){i.indexOf(this)<0&&i.push(this)},a.prototype._unregisterInstance=function(){var t=i.indexOf(this);t!=-1&&i.splice(t,1)};function m(){return window.performance&&performance.now&&performance.now()}function d(t,e){var o=null;return function(){o||(o=setTimeout(function(){t(),o=null},e))}}function c(t,e,o,s){typeof t.addEventListener=="function"?t.addEventListener(e,o,s):typeof t.attachEvent=="function"&&t.attachEvent("on"+e,o)}function l(t,e,o,s){typeof t.removeEventListener=="function"?t.removeEventListener(e,o,s):typeof t.detatchEvent=="function"&&t.detatchEvent("on"+e,o)}function v(t,e){var o=Math.max(t.top,e.top),s=Math.min(t.bottom,e.bottom),u=Math.max(t.left,e.left),O=Math.min(t.right,e.right),E=O-u,I=s-o;return E>=0&&I>=0&&{top:o,bottom:s,left:u,right:O,width:E,height:I}||null}function T(t){var e;try{e=t.getBoundingClientRect()}catch{}return e?(e.width&&e.height||(e={top:e.top,right:e.right,bottom:e.bottom,left:e.left,width:e.right-e.left,height:e.bottom-e.top}),e):y()}function y(){return{top:0,bottom:0,left:0,right:0,width:0,height:0}}function b(t){return!t||"x"in t?t:{top:t.top,y:t.top,bottom:t.bottom,left:t.left,x:t.left,right:t.right,width:t.width,height:t.height}}function R(t,e){var o=e.top-t.top,s=e.left-t.left;return{top:o,left:s,height:e.height,width:e.width,bottom:o+e.height,right:s+e.width}}function h(t,e){for(var o=e;o;){if(o==t)return!0;o=_(o)}return!1}function _(t){var e=t.parentNode;return t.nodeType==9&&t!=n?g(t):(e&&e.assignedSlot&&(e=e.assignedSlot.parentNode),e&&e.nodeType==11&&e.host?e.host:e)}function x(t){return t&&t.nodeType===9}window.IntersectionObserver=a,window.IntersectionObserverEntry=w}()),S}q();var C={exports:{}},H;function G(){return H||(H=1,function(g){var n=Object.prototype.hasOwnProperty,i="~";function p(){}Object.create&&(p.prototype=Object.create(null),new p().__proto__||(i=!1));function f(d,c,l){this.fn=d,this.context=c,this.once=l||!1}function w(d,c,l,v,T){if(typeof l!="function")throw new TypeError("The listener must be a function");var y=new f(l,v||d,T),b=i?i+c:c;return d._events[b]?d._events[b].fn?d._events[b]=[d._events[b],y]:d._events[b].push(y):(d._events[b]=y,d._eventsCount++),d}function a(d,c){--d._eventsCount===0?d._events=new p:delete d._events[c]}function m(){this._events=new p,this._eventsCount=0}m.prototype.eventNames=function(){var c=[],l,v;if(this._eventsCount===0)return c;for(v in l=this._events)n.call(l,v)&&c.push(i?v.slice(1):v);return Object.getOwnPropertySymbols?c.concat(Object.getOwnPropertySymbols(l)):c},m.prototype.listeners=function(c){var l=i?i+c:c,v=this._events[l];if(!v)return[];if(v.fn)return[v.fn];for(var T=0,y=v.length,b=new Array(y);T<y;T++)b[T]=v[T].fn;return b},m.prototype.listenerCount=function(c){var l=i?i+c:c,v=this._events[l];return v?v.fn?1:v.length:0},m.prototype.emit=function(c,l,v,T,y,b){var R=i?i+c:c;if(!this._events[R])return!1;var h=this._events[R],_=arguments.length,x,t;if(h.fn){switch(h.once&&this.removeListener(c,h.fn,void 0,!0),_){case 1:return h.fn.call(h.context),!0;case 2:return h.fn.call(h.context,l),!0;case 3:return h.fn.call(h.context,l,v),!0;case 4:return h.fn.call(h.context,l,v,T),!0;case 5:return h.fn.call(h.context,l,v,T,y),!0;case 6:return h.fn.call(h.context,l,v,T,y,b),!0}for(t=1,x=new Array(_-1);t<_;t++)x[t-1]=arguments[t];h.fn.apply(h.context,x)}else{var e=h.length,o;for(t=0;t<e;t++)switch(h[t].once&&this.removeListener(c,h[t].fn,void 0,!0),_){case 1:h[t].fn.call(h[t].context);break;case 2:h[t].fn.call(h[t].context,l);break;case 3:h[t].fn.call(h[t].context,l,v);break;case 4:h[t].fn.call(h[t].context,l,v,T);break;default:if(!x)for(o=1,x=new Array(_-1);o<_;o++)x[o-1]=arguments[o];h[t].fn.apply(h[t].context,x)}}return!0},m.prototype.on=function(c,l,v){return w(this,c,l,v,!1)},m.prototype.once=function(c,l,v){return w(this,c,l,v,!0)},m.prototype.removeListener=function(c,l,v,T){var y=i?i+c:c;if(!this._events[y])return this;if(!l)return a(this,y),this;var b=this._events[y];if(b.fn)b.fn===l&&(!T||b.once)&&(!v||b.context===v)&&a(this,y);else{for(var R=0,h=[],_=b.length;R<_;R++)(b[R].fn!==l||T&&!b[R].once||v&&b[R].context!==v)&&h.push(b[R]);h.length?this._events[y]=h.length===1?h[0]:h:a(this,y)}return this},m.prototype.removeAllListeners=function(c){var l;return c?(l=i?i+c:c,this._events[l]&&a(this,l)):(this._events=new p,this._eventsCount=0),this},m.prototype.off=m.prototype.removeListener,m.prototype.addListener=m.prototype.on,m.prefixed=i,m.EventEmitter=m,g.exports=m}(C)),C.exports}var z=G(),W=Object.defineProperty,$=Object.getOwnPropertyDescriptor,Y=(g,n,i,p)=>{for(var f=$(n,i),w=g.length-1,a;w>=0;w--)(a=g[w])&&(f=a(n,i,f)||f);return f&&W(n,i,f),f};const B=60,j=(r=class{static on(n,i){r.events.on(n,i)}static off(n,i){r.events.off(n,i)}static once(n,i){r.events.once(n,i)}static checkCollisions(n,i){const p=i||Array.from(r.elements.keys()),f=n.getBoundingClientRect(),w=[];for(const a of p)if(a!==n){const m=a.getBoundingClientRect();m.left<=f.right&&m.right>=f.left&&m.top<=f.bottom&&m.bottom>=f.top&&w.push(a)}w.length&&r.onElementIntersection(n,w)}static isPositioned(n){return r.elements.has(n)}static getPositioningOptions(n){return r.elements.has(n)?r.elements.get(n):null}static position(n,i={}){const p={...F,...i};let f=n;for(;f!==document.body;)if(f=f.parentElement,f.classList.contains("sps-focused-task")){p.scrollParent=f,r.registeredScrollParents.has(f)||(r.registeredScrollParents.add(f),f.addEventListener("scroll",r.update));break}if(n.style.visibility="hidden",r.elements.size===0&&(window.addEventListener("resize",r.update),window.addEventListener("scroll",r.update)),!p.relativeTo)throw new Error("You must provide an element for the relativeTo option to position an element.");r.elements.set(n,p),k.onNextTick(()=>{r.fixElementPosition(n),r.viewportObserver.observe(n),n.style.visibility="",r.checkCollisions(n)})}static release(n){if(r.elements.has(n)){r.clearStyles(n);const i=r.elements.get(n);i.scrollParent&&(i.scrollParent.removeEventListener("scroll",r.update),r.registeredScrollParents.delete(i.scrollParent)),r.elements.delete(n),r.elements.size===0&&(window.removeEventListener("resize",r.update),window.removeEventListener("scroll",r.update)),r.viewportObserver.unobserve(n)}}static releaseAll(){for(const n of r.elements.keys())r.release(n)}static refresh(n){r.elements.has(n)&&(r.clearStyles(n),r.fixElementPosition(n),r.checkCollisions(n))}static refreshAll(){for(const n of r.elements.keys())r.refresh(n)}static reposition(n,i){if(r.elements.has(n)){const p=r.elements.get(n);r.elements.set(n,Object.assign(p,i)),r.refresh(n)}}static onViewportIntersection(n){for(const i of n){const p=Object.keys(IntersectionObserverEntry.prototype).reduce((f,w)=>({...f,[w]:i[w]}),{});p.rootBounds=p.rootBounds||r.getRootBounds(),r.events.emit("viewportIntersection",Object.freeze(p))}}static onElementIntersection(n,i){r.events.emit("elementIntersection",{target:n,intersectingWith:i})}static getRootBounds(){const n=Math.max(document.documentElement.clientWidth,window.innerWidth||0),i=Math.max(document.documentElement.clientHeight,window.innerHeight||0);return{x:0,y:B,left:0,top:B,right:n,bottom:i,height:i-B,width:n}}static clearStyles(n){Object.assign(n.style,{position:"",width:"",top:"",left:"",right:"",bottom:"",visibility:"",zIndex:""})}static fixElementPosition(n,i){if(!this.elements.has(n))return;const p=i||this.elements.get(n),f=this.getRootBounds(),w=n.getBoundingClientRect(),a=p.relativeTo.getBoundingClientRect(),{width:m}=p.useRelativeTargetWidth?a:w;Object.assign(n.style,{minWidth:`${m}px`,position:"fixed",zIndex:p.zIndex||""});let d,c;const l=p.position.split(" "),v=p.offsets[0]||0,T=p.offsets[1]||0;switch(d=0,c=0,l[0]){case"top":d=a.top-w.height-v;break;case"left":c=a.left-m-v;break;case"right":c=a.right+v;break;case"bottom":d=a.bottom+v;break;default:throw new Error(`${p.position} is not a valid position`)}switch(l[1]){case"left":c=a.left-T;break;case"top":d=a.top-T;break;case"middle":l[0]==="top"||l[0]==="bottom"?c=a.left+a.width/2-m/2+T:(l[0]==="left"||l[0]==="right")&&(d=a.top+a.height/2-w.height/2+T);break;case"bottom":d=a.bottom-w.height+T;break;case"right":c=a.right-m+T;break;default:throw new Error(`${p.position} is not a valid position`)}const y=d+w.height,b=c+w.width,R=`${Math.round(d)}px`,h=`${Math.round(f.bottom-y)}px`,_=`${Math.round(c)}px`,x=`${Math.round(f.right-b)}px`;switch(p.anchor){case P.TOP_LEFT:Object.assign(n.style,{top:R,bottom:"auto",left:_,right:"auto"});break;case P.TOP_RIGHT:Object.assign(n.style,{top:R,bottom:"auto",left:"auto",right:x});break;case P.BOTTOM_LEFT:Object.assign(n.style,{top:"auto",bottom:h,left:_,right:"auto"});break;case P.BOTTOM_RIGHT:Object.assign(n.style,{top:"auto",bottom:h,left:"auto",right:x});break}}static update(n){const i=r.elements.entries(),p=[];for(const[f,w]of i)(!n||n.target===document||n.target===w.scrollParent||n.target===window)&&(r.fixElementPosition(f,w),r.checkCollisions(f,p),p.push(f))}on(n,i){r.on(n,i)}off(n,i){r.off(n,i)}once(n,i){r.once(n,i)}isPositioned(n){return r.isPositioned(n)}getPositioningOptions(n){return r.getPositioningOptions(n)}position(n,i={}){r.position(n,i)}release(n){r.release(n)}releaseAll(){r.releaseAll()}refresh(n){r.refresh(n)}refreshAll(){r.refreshAll()}reposition(n,i){r.reposition(n,i)}},r.elements=new Map,r.registeredScrollParents=new Set,r.events=new z.EventEmitter,r.viewportObserver=new IntersectionObserver(r.onViewportIntersection,{rootMargin:`-${B}px 0px 0px`,threshold:1}),r);Y([k.lockedToAnimationFrames],j,"update");let J=j;D.DEFAULT_POSITIONING_OPTIONS=F,D.Position=A,D.PositionAnchor=P,D.PositioningService=J,Object.defineProperty(D,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(D,k){typeof exports=="object"&&typeof module<"u"?k(exports,require("@spscommerce/utils")):typeof define=="function"&&define.amd?define(["exports","@spscommerce/utils"],k):(D=typeof globalThis<"u"?globalThis:D||self,k(D.Positioning={},D.utils))})(this,(function(D,k){"use strict";var r;var C=(d=>(d.TOP_LEFT="top left",d.TOP_MIDDLE="top middle",d.TOP_RIGHT="top right",d.RIGHT_TOP="right top",d.RIGHT_MIDDLE="right middle",d.RIGHT_BOTTOM="right bottom",d.BOTTOM_RIGHT="bottom right",d.BOTTOM_MIDDLE="bottom middle",d.BOTTOM_LEFT="bottom left",d.LEFT_BOTTOM="left bottom",d.LEFT_MIDDLE="left middle",d.LEFT_TOP="left top",d))(C||{}),P=(d=>(d.TOP_LEFT="top left",d.TOP_RIGHT="top right",d.BOTTOM_LEFT="bottom left",d.BOTTOM_RIGHT="bottom right",d))(P||{});const F={anchor:P.TOP_LEFT,offsets:[],position:C.TOP_LEFT};function q(d){return d&&d.__esModule&&Object.prototype.hasOwnProperty.call(d,"default")?d.default:d}var S={},N;function G(){return N||(N=1,(function(){if(typeof window!="object")return;if("IntersectionObserver"in window&&"IntersectionObserverEntry"in window&&"intersectionRatio"in window.IntersectionObserverEntry.prototype){"isIntersecting"in window.IntersectionObserverEntry.prototype||Object.defineProperty(window.IntersectionObserverEntry.prototype,"isIntersecting",{get:function(){return this.intersectionRatio>0}});return}function d(t){try{return t.defaultView&&t.defaultView.frameElement||null}catch{return null}}var n=(function(t){for(var e=t,o=d(e);o;)e=o.ownerDocument,o=d(e);return e})(window.document),i=[],p=null,f=null;function w(t){this.time=t.time,this.target=t.target,this.rootBounds=b(t.rootBounds),this.boundingClientRect=b(t.boundingClientRect),this.intersectionRect=b(t.intersectionRect||y()),this.isIntersecting=!!t.intersectionRect;var e=this.boundingClientRect,o=e.width*e.height,s=this.intersectionRect,u=s.width*s.height;o?this.intersectionRatio=Number((u/o).toFixed(4)):this.intersectionRatio=this.isIntersecting?1:0}function a(t,e){var o=e||{};if(typeof t!="function")throw new Error("callback must be a function");if(o.root&&o.root.nodeType!=1&&o.root.nodeType!=9)throw new Error("root must be a Document or Element");this._checkForIntersections=g(this._checkForIntersections.bind(this),this.THROTTLE_TIMEOUT),this._callback=t,this._observationTargets=[],this._queuedEntries=[],this._rootMarginValues=this._parseRootMargin(o.rootMargin),this.thresholds=this._initThresholds(o.threshold),this.root=o.root||null,this.rootMargin=this._rootMarginValues.map(function(s){return s.value+s.unit}).join(" "),this._monitoringDocuments=[],this._monitoringUnsubscribes=[]}a.prototype.THROTTLE_TIMEOUT=100,a.prototype.POLL_INTERVAL=null,a.prototype.USE_MUTATION_OBSERVER=!0,a._setupCrossOriginUpdater=function(){return p||(p=function(t,e){!t||!e?f=y():f=R(t,e),i.forEach(function(o){o._checkForIntersections()})}),p},a._resetCrossOriginUpdater=function(){p=null,f=null},a.prototype.observe=function(t){var e=this._observationTargets.some(function(o){return o.element==t});if(!e){if(!(t&&t.nodeType==1))throw new Error("target must be an Element");this._registerInstance(),this._observationTargets.push({element:t,entry:null}),this._monitorIntersections(t.ownerDocument),this._checkForIntersections()}},a.prototype.unobserve=function(t){this._observationTargets=this._observationTargets.filter(function(e){return e.element!=t}),this._unmonitorIntersections(t.ownerDocument),this._observationTargets.length==0&&this._unregisterInstance()},a.prototype.disconnect=function(){this._observationTargets=[],this._unmonitorAllIntersections(),this._unregisterInstance()},a.prototype.takeRecords=function(){var t=this._queuedEntries.slice();return this._queuedEntries=[],t},a.prototype._initThresholds=function(t){var e=t||[0];return Array.isArray(e)||(e=[e]),e.sort().filter(function(o,s,u){if(typeof o!="number"||isNaN(o)||o<0||o>1)throw new Error("threshold must be a number between 0 and 1 inclusively");return o!==u[s-1]})},a.prototype._parseRootMargin=function(t){var e=t||"0px",o=e.split(/\s+/).map(function(s){var u=/^(-?\d*\.?\d+)(px|%)$/.exec(s);if(!u)throw new Error("rootMargin must be specified in pixels or percent");return{value:parseFloat(u[1]),unit:u[2]}});return o[1]=o[1]||o[0],o[2]=o[2]||o[0],o[3]=o[3]||o[1],o},a.prototype._monitorIntersections=function(t){var e=t.defaultView;if(e&&this._monitoringDocuments.indexOf(t)==-1){var o=this._checkForIntersections,s=null,u=null;this.POLL_INTERVAL?s=e.setInterval(o,this.POLL_INTERVAL):(c(e,"resize",o,!0),c(t,"scroll",o,!0),this.USE_MUTATION_OBSERVER&&"MutationObserver"in e&&(u=new e.MutationObserver(o),u.observe(t,{attributes:!0,childList:!0,characterData:!0,subtree:!0}))),this._monitoringDocuments.push(t),this._monitoringUnsubscribes.push(function(){var I=t.defaultView;I&&(s&&I.clearInterval(s),l(I,"resize",o,!0)),l(t,"scroll",o,!0),u&&u.disconnect()});var E=this.root&&(this.root.ownerDocument||this.root)||n;if(t!=E){var O=d(t);O&&this._monitorIntersections(O.ownerDocument)}}},a.prototype._unmonitorIntersections=function(t){var e=this._monitoringDocuments.indexOf(t);if(e!=-1){var o=this.root&&(this.root.ownerDocument||this.root)||n,s=this._observationTargets.some(function(O){var I=O.element.ownerDocument;if(I==t)return!0;for(;I&&I!=o;){var L=d(I);if(I=L&&L.ownerDocument,I==t)return!0}return!1});if(!s){var u=this._monitoringUnsubscribes[e];if(this._monitoringDocuments.splice(e,1),this._monitoringUnsubscribes.splice(e,1),u(),t!=o){var E=d(t);E&&this._unmonitorIntersections(E.ownerDocument)}}}},a.prototype._unmonitorAllIntersections=function(){var t=this._monitoringUnsubscribes.slice(0);this._monitoringDocuments.length=0,this._monitoringUnsubscribes.length=0;for(var e=0;e<t.length;e++)t[e]()},a.prototype._checkForIntersections=function(){if(!(!this.root&&p&&!f)){var t=this._rootIsInDom(),e=t?this._getRootRect():y();this._observationTargets.forEach(function(o){var s=o.element,u=T(s),E=this._rootContainsTarget(s),O=o.entry,I=t&&E&&this._computeTargetAndRootIntersection(s,u,e),L=null;this._rootContainsTarget(s)?(!p||this.root)&&(L=e):L=y();var M=o.entry=new w({time:m(),target:s,boundingClientRect:u,rootBounds:L,intersectionRect:I});O?t&&E?this._hasCrossedThreshold(O,M)&&this._queuedEntries.push(M):O&&O.isIntersecting&&this._queuedEntries.push(M):this._queuedEntries.push(M)},this),this._queuedEntries.length&&this._callback(this.takeRecords(),this)}},a.prototype._computeTargetAndRootIntersection=function(t,e,o){if(window.getComputedStyle(t).display!="none"){for(var s=e,u=_(t),E=!1;!E&&u;){var O=null,I=u.nodeType==1?window.getComputedStyle(u):{};if(I.display=="none")return null;if(u==this.root||u.nodeType==9)if(E=!0,u==this.root||u==n)p&&!this.root?!f||f.width==0&&f.height==0?(u=null,O=null,s=null):O=f:O=o;else{var L=_(u),M=L&&T(L),U=L&&this._computeTargetAndRootIntersection(L,M,o);M&&U?(u=L,O=R(M,U)):(u=null,s=null)}else{var V=u.ownerDocument;u!=V.body&&u!=V.documentElement&&I.overflow!="visible"&&(O=T(u))}if(O&&(s=v(O,s)),!s)break;u=u&&_(u)}return s}},a.prototype._getRootRect=function(){var t;if(this.root&&!x(this.root))t=T(this.root);else{var e=x(this.root)?this.root:n,o=e.documentElement,s=e.body;t={top:0,left:0,right:o.clientWidth||s.clientWidth,width:o.clientWidth||s.clientWidth,bottom:o.clientHeight||s.clientHeight,height:o.clientHeight||s.clientHeight}}return this._expandRectByRootMargin(t)},a.prototype._expandRectByRootMargin=function(t){var e=this._rootMarginValues.map(function(s,u){return s.unit=="px"?s.value:s.value*(u%2?t.width:t.height)/100}),o={top:t.top-e[0],right:t.right+e[1],bottom:t.bottom+e[2],left:t.left-e[3]};return o.width=o.right-o.left,o.height=o.bottom-o.top,o},a.prototype._hasCrossedThreshold=function(t,e){var o=t&&t.isIntersecting?t.intersectionRatio||0:-1,s=e.isIntersecting?e.intersectionRatio||0:-1;if(o!==s)for(var u=0;u<this.thresholds.length;u++){var E=this.thresholds[u];if(E==o||E==s||E<o!=E<s)return!0}},a.prototype._rootIsInDom=function(){return!this.root||h(n,this.root)},a.prototype._rootContainsTarget=function(t){var e=this.root&&(this.root.ownerDocument||this.root)||n;return h(e,t)&&(!this.root||e==t.ownerDocument)},a.prototype._registerInstance=function(){i.indexOf(this)<0&&i.push(this)},a.prototype._unregisterInstance=function(){var t=i.indexOf(this);t!=-1&&i.splice(t,1)};function m(){return window.performance&&performance.now&&performance.now()}function g(t,e){var o=null;return function(){o||(o=setTimeout(function(){t(),o=null},e))}}function c(t,e,o,s){typeof t.addEventListener=="function"?t.addEventListener(e,o,s):typeof t.attachEvent=="function"&&t.attachEvent("on"+e,o)}function l(t,e,o,s){typeof t.removeEventListener=="function"?t.removeEventListener(e,o,s):typeof t.detatchEvent=="function"&&t.detatchEvent("on"+e,o)}function v(t,e){var o=Math.max(t.top,e.top),s=Math.min(t.bottom,e.bottom),u=Math.max(t.left,e.left),E=Math.min(t.right,e.right),O=E-u,I=s-o;return O>=0&&I>=0&&{top:o,bottom:s,left:u,right:E,width:O,height:I}||null}function T(t){var e;try{e=t.getBoundingClientRect()}catch{}return e?(e.width&&e.height||(e={top:e.top,right:e.right,bottom:e.bottom,left:e.left,width:e.right-e.left,height:e.bottom-e.top}),e):y()}function y(){return{top:0,bottom:0,left:0,right:0,width:0,height:0}}function b(t){return!t||"x"in t?t:{top:t.top,y:t.top,bottom:t.bottom,left:t.left,x:t.left,right:t.right,width:t.width,height:t.height}}function R(t,e){var o=e.top-t.top,s=e.left-t.left;return{top:o,left:s,height:e.height,width:e.width,bottom:o+e.height,right:s+e.width}}function h(t,e){for(var o=e;o;){if(o==t)return!0;o=_(o)}return!1}function _(t){var e=t.parentNode;return t.nodeType==9&&t!=n?d(t):(e&&e.assignedSlot&&(e=e.assignedSlot.parentNode),e&&e.nodeType==11&&e.host?e.host:e)}function x(t){return t&&t.nodeType===9}window.IntersectionObserver=a,window.IntersectionObserverEntry=w})()),S}G();var A={exports:{}},H;function z(){return H||(H=1,(function(d){var n=Object.prototype.hasOwnProperty,i="~";function p(){}Object.create&&(p.prototype=Object.create(null),new p().__proto__||(i=!1));function f(g,c,l){this.fn=g,this.context=c,this.once=l||!1}function w(g,c,l,v,T){if(typeof l!="function")throw new TypeError("The listener must be a function");var y=new f(l,v||g,T),b=i?i+c:c;return g._events[b]?g._events[b].fn?g._events[b]=[g._events[b],y]:g._events[b].push(y):(g._events[b]=y,g._eventsCount++),g}function a(g,c){--g._eventsCount===0?g._events=new p:delete g._events[c]}function m(){this._events=new p,this._eventsCount=0}m.prototype.eventNames=function(){var c=[],l,v;if(this._eventsCount===0)return c;for(v in l=this._events)n.call(l,v)&&c.push(i?v.slice(1):v);return Object.getOwnPropertySymbols?c.concat(Object.getOwnPropertySymbols(l)):c},m.prototype.listeners=function(c){var l=i?i+c:c,v=this._events[l];if(!v)return[];if(v.fn)return[v.fn];for(var T=0,y=v.length,b=new Array(y);T<y;T++)b[T]=v[T].fn;return b},m.prototype.listenerCount=function(c){var l=i?i+c:c,v=this._events[l];return v?v.fn?1:v.length:0},m.prototype.emit=function(c,l,v,T,y,b){var R=i?i+c:c;if(!this._events[R])return!1;var h=this._events[R],_=arguments.length,x,t;if(h.fn){switch(h.once&&this.removeListener(c,h.fn,void 0,!0),_){case 1:return h.fn.call(h.context),!0;case 2:return h.fn.call(h.context,l),!0;case 3:return h.fn.call(h.context,l,v),!0;case 4:return h.fn.call(h.context,l,v,T),!0;case 5:return h.fn.call(h.context,l,v,T,y),!0;case 6:return h.fn.call(h.context,l,v,T,y,b),!0}for(t=1,x=new Array(_-1);t<_;t++)x[t-1]=arguments[t];h.fn.apply(h.context,x)}else{var e=h.length,o;for(t=0;t<e;t++)switch(h[t].once&&this.removeListener(c,h[t].fn,void 0,!0),_){case 1:h[t].fn.call(h[t].context);break;case 2:h[t].fn.call(h[t].context,l);break;case 3:h[t].fn.call(h[t].context,l,v);break;case 4:h[t].fn.call(h[t].context,l,v,T);break;default:if(!x)for(o=1,x=new Array(_-1);o<_;o++)x[o-1]=arguments[o];h[t].fn.apply(h[t].context,x)}}return!0},m.prototype.on=function(c,l,v){return w(this,c,l,v,!1)},m.prototype.once=function(c,l,v){return w(this,c,l,v,!0)},m.prototype.removeListener=function(c,l,v,T){var y=i?i+c:c;if(!this._events[y])return this;if(!l)return a(this,y),this;var b=this._events[y];if(b.fn)b.fn===l&&(!T||b.once)&&(!v||b.context===v)&&a(this,y);else{for(var R=0,h=[],_=b.length;R<_;R++)(b[R].fn!==l||T&&!b[R].once||v&&b[R].context!==v)&&h.push(b[R]);h.length?this._events[y]=h.length===1?h[0]:h:a(this,y)}return this},m.prototype.removeAllListeners=function(c){var l;return c?(l=i?i+c:c,this._events[l]&&a(this,l)):(this._events=new p,this._eventsCount=0),this},m.prototype.off=m.prototype.removeListener,m.prototype.addListener=m.prototype.on,m.prefixed=i,m.EventEmitter=m,d.exports=m})(A)),A.exports}var W=z();const $=q(W);var Y=Object.defineProperty,J=Object.getOwnPropertyDescriptor,K=(d,n,i,p)=>{for(var f=J(n,i),w=d.length-1,a;w>=0;w--)(a=d[w])&&(f=a(n,i,f)||f);return f&&Y(n,i,f),f};const B=60,j=(r=class{static on(n,i){r.events.on(n,i)}static off(n,i){r.events.off(n,i)}static once(n,i){r.events.once(n,i)}static checkCollisions(n,i){const p=i||Array.from(r.elements.keys()),f=n.getBoundingClientRect(),w=[];for(const a of p)if(a!==n){const m=a.getBoundingClientRect();m.left<=f.right&&m.right>=f.left&&m.top<=f.bottom&&m.bottom>=f.top&&w.push(a)}w.length&&r.onElementIntersection(n,w)}static isPositioned(n){return r.elements.has(n)}static getPositioningOptions(n){return r.elements.has(n)?r.elements.get(n):null}static position(n,i={}){const p={...F,...i};let f=n;for(;f!==document.body;)if(f=f.parentElement,f.classList.contains("sps-focused-task")){p.scrollParent=f,r.registeredScrollParents.has(f)||(r.registeredScrollParents.add(f),f.addEventListener("scroll",r.update));break}if(n.style.visibility="hidden",r.elements.size===0&&(window.addEventListener("resize",r.update),window.addEventListener("scroll",r.update)),!p.relativeTo)throw new Error("You must provide an element for the relativeTo option to position an element.");r.elements.set(n,p),k.onNextTick(()=>{r.fixElementPosition(n),r.viewportObserver.observe(n),n.style.visibility="",r.checkCollisions(n)})}static release(n){if(r.elements.has(n)){r.clearStyles(n);const i=r.elements.get(n);i.scrollParent&&(i.scrollParent.removeEventListener("scroll",r.update),r.registeredScrollParents.delete(i.scrollParent)),r.elements.delete(n),r.elements.size===0&&(window.removeEventListener("resize",r.update),window.removeEventListener("scroll",r.update)),r.viewportObserver.unobserve(n)}}static releaseAll(){for(const n of r.elements.keys())r.release(n)}static refresh(n){r.elements.has(n)&&(r.clearStyles(n),r.fixElementPosition(n),r.checkCollisions(n))}static refreshAll(){for(const n of r.elements.keys())r.refresh(n)}static reposition(n,i){if(r.elements.has(n)){const p=r.elements.get(n);r.elements.set(n,Object.assign(p,i)),r.refresh(n)}}static onViewportIntersection(n){for(const i of n){const p=Object.keys(IntersectionObserverEntry.prototype).reduce((f,w)=>({...f,[w]:i[w]}),{});p.rootBounds=p.rootBounds||r.getRootBounds(),r.events.emit("viewportIntersection",Object.freeze(p))}}static onElementIntersection(n,i){r.events.emit("elementIntersection",{target:n,intersectingWith:i})}static getRootBounds(){const n=Math.max(document.documentElement.clientWidth,window.innerWidth||0),i=Math.max(document.documentElement.clientHeight,window.innerHeight||0);return{x:0,y:B,left:0,top:B,right:n,bottom:i,height:i-B,width:n}}static clearStyles(n){Object.assign(n.style,{position:"",width:"",top:"",left:"",right:"",bottom:"",visibility:"",zIndex:""})}static fixElementPosition(n,i){if(!this.elements.has(n))return;const p=i||this.elements.get(n),f=this.getRootBounds(),w=n.getBoundingClientRect(),a=p.relativeTo.getBoundingClientRect(),{width:m}=p.useRelativeTargetWidth?a:w;Object.assign(n.style,{minWidth:`${m}px`,position:"fixed",zIndex:p.zIndex||""});let g,c;const l=p.position.split(" "),v=p.offsets[0]||0,T=p.offsets[1]||0;switch(g=0,c=0,l[0]){case"top":g=a.top-w.height-v;break;case"left":c=a.left-m-v;break;case"right":c=a.right+v;break;case"bottom":g=a.bottom+v;break;default:throw new Error(`${p.position} is not a valid position`)}switch(l[1]){case"left":c=a.left-T;break;case"top":g=a.top-T;break;case"middle":l[0]==="top"||l[0]==="bottom"?c=a.left+a.width/2-m/2+T:(l[0]==="left"||l[0]==="right")&&(g=a.top+a.height/2-w.height/2+T);break;case"bottom":g=a.bottom-w.height+T;break;case"right":c=a.right-m+T;break;default:throw new Error(`${p.position} is not a valid position`)}const y=g+w.height,b=c+w.width,R=`${Math.round(g)}px`,h=`${Math.round(f.bottom-y)}px`,_=`${Math.round(c)}px`,x=`${Math.round(f.right-b)}px`;switch(p.anchor){case P.TOP_LEFT:Object.assign(n.style,{top:R,bottom:"auto",left:_,right:"auto"});break;case P.TOP_RIGHT:Object.assign(n.style,{top:R,bottom:"auto",left:"auto",right:x});break;case P.BOTTOM_LEFT:Object.assign(n.style,{top:"auto",bottom:h,left:_,right:"auto"});break;case P.BOTTOM_RIGHT:Object.assign(n.style,{top:"auto",bottom:h,left:"auto",right:x});break}}static update(n){const i=r.elements.entries(),p=[];for(const[f,w]of i)(!n||n.target===document||n.target===w.scrollParent||n.target===window)&&(r.fixElementPosition(f,w),r.checkCollisions(f,p),p.push(f))}on(n,i){r.on(n,i)}off(n,i){r.off(n,i)}once(n,i){r.once(n,i)}isPositioned(n){return r.isPositioned(n)}getPositioningOptions(n){return r.getPositioningOptions(n)}position(n,i={}){r.position(n,i)}release(n){r.release(n)}releaseAll(){r.releaseAll()}refresh(n){r.refresh(n)}refreshAll(){r.refreshAll()}reposition(n,i){r.reposition(n,i)}},r.elements=new Map,r.registeredScrollParents=new Set,r.events=new $,r.viewportObserver=new IntersectionObserver(r.onViewportIntersection,{rootMargin:`-${B}px 0px 0px`,threshold:1}),r);K([k.lockedToAnimationFrames],j,"update");let Q=j;D.DEFAULT_POSITIONING_OPTIONS=F,D.Position=C,D.PositionAnchor=P,D.PositioningService=Q,Object.defineProperty(D,Symbol.toStringTag,{value:"Module"})}));
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spscommerce/positioning",
|
|
3
3
|
"description": "Service for positioning dropdown/popup elements.",
|
|
4
|
-
"version": "8.45.
|
|
4
|
+
"version": "8.45.6",
|
|
5
5
|
"author": "SPS Commerce",
|
|
6
6
|
"license": "UNLICENSED",
|
|
7
7
|
"repository": "https://github.com/spscommerce/woodland/tree/main/packages/@spscommerce/positioning",
|
|
@@ -20,14 +20,14 @@
|
|
|
20
20
|
"access": "public"
|
|
21
21
|
},
|
|
22
22
|
"peerDependencies": {
|
|
23
|
-
"@spscommerce/utils": "^7.0.0 || ^8.0.0"
|
|
23
|
+
"@spscommerce/utils": "^7.0.0 || ^8.0.0 || ^9.0.0"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@spscommerce/utils": "
|
|
27
|
-
"raf-stub": "
|
|
26
|
+
"@spscommerce/utils": "9.0.3",
|
|
27
|
+
"raf-stub": "3.0.0"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"eventemitter3": "
|
|
30
|
+
"eventemitter3": "5.0.4",
|
|
31
31
|
"intersection-observer": "0.12.0"
|
|
32
32
|
},
|
|
33
33
|
"scripts": {
|