@spscommerce/positioning 8.56.20 → 8.56.22
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 +9 -15
- package/lib/index.umd.cjs +1 -1
- package/package.json +2 -2
package/lib/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { lockedToAnimationFrames as e, onNextTick as t } from "@spscommerce/utils";
|
|
2
|
-
|
|
3
|
-
var n = Object.create, r = Object.defineProperty, i = Object.getOwnPropertyDescriptor, a = Object.getOwnPropertyNames, o = Object.getPrototypeOf, s = Object.prototype.hasOwnProperty, c = (e, t) => () => (t || (e((t = { exports: {} }).exports, t), e = null), t.exports), l = (e, t, n, o) => {
|
|
2
|
+
// \0rolldown/runtime.js
|
|
3
|
+
var n = Object.create, r = Object.defineProperty, i = Object.getOwnPropertyDescriptor, a = Object.getOwnPropertyNames, o = Object.getPrototypeOf, s = Object.prototype.hasOwnProperty, c = (e, t) => () => (t || (e((t = { exports: {} }).exports, t, t.exports), e = null), t.exports), l = (e, t, n, o) => {
|
|
4
4
|
if (t && typeof t == "object" || typeof t == "function") for (var c = a(t), l = 0, u = c.length, d; l < u; l++) d = c[l], !s.call(e, d) && d !== n && r(e, d, {
|
|
5
5
|
get: ((e) => t[e]).bind(null, d),
|
|
6
6
|
enumerable: !(o = i(t, d)) || o.enumerable
|
|
@@ -18,8 +18,7 @@ var n = Object.create, r = Object.defineProperty, i = Object.getOwnPropertyDescr
|
|
|
18
18
|
offsets: [],
|
|
19
19
|
position: d.TOP_LEFT
|
|
20
20
|
};
|
|
21
|
-
|
|
22
|
-
//#region ../../node_modules/.pnpm/intersection-observer@0.12.0/node_modules/intersection-observer/intersection-observer.js
|
|
21
|
+
// ../../node_modules/.pnpm/intersection-observer@0.12.0/node_modules/intersection-observer/intersection-observer.js
|
|
23
22
|
(function() {
|
|
24
23
|
if (typeof window != "object") return;
|
|
25
24
|
if ("IntersectionObserver" in window && "IntersectionObserverEntry" in window && "intersectionRatio" in window.IntersectionObserverEntry.prototype) {
|
|
@@ -305,8 +304,7 @@ var n = Object.create, r = Object.defineProperty, i = Object.getOwnPropertyDescr
|
|
|
305
304
|
}
|
|
306
305
|
window.IntersectionObserver = o, window.IntersectionObserverEntry = a;
|
|
307
306
|
})();
|
|
308
|
-
|
|
309
|
-
//#region ../../node_modules/.pnpm/eventemitter3@5.0.4/node_modules/eventemitter3/index.mjs
|
|
307
|
+
// ../../node_modules/.pnpm/eventemitter3@5.0.4/node_modules/eventemitter3/index.mjs
|
|
310
308
|
var m = /* @__PURE__ */ u((/* @__PURE__ */ c(((e, t) => {
|
|
311
309
|
var n = Object.prototype.hasOwnProperty, r = "~";
|
|
312
310
|
function i() {}
|
|
@@ -384,7 +382,7 @@ var m = /* @__PURE__ */ u((/* @__PURE__ */ c(((e, t) => {
|
|
|
384
382
|
if (!this._events[a]) return this;
|
|
385
383
|
if (!t) return s(this, a), this;
|
|
386
384
|
var o = this._events[a];
|
|
387
|
-
if (o.fn) o.fn
|
|
385
|
+
if (o.fn) o.fn !== t || i && !o.once || n && o.context !== n || s(this, a);
|
|
388
386
|
else {
|
|
389
387
|
for (var c = 0, l = [], u = o.length; c < u; c++) (o[c].fn !== t || i && !o[c].once || n && o[c].context !== n) && l.push(o[c]);
|
|
390
388
|
l.length ? this._events[a] = l.length === 1 ? l[0] : l : s(this, a);
|
|
@@ -395,21 +393,18 @@ var m = /* @__PURE__ */ u((/* @__PURE__ */ c(((e, t) => {
|
|
|
395
393
|
return e ? (t = r ? r + e : e, this._events[t] && s(this, t)) : (this._events = new i(), this._eventsCount = 0), this;
|
|
396
394
|
}, c.prototype.off = c.prototype.removeListener, c.prototype.addListener = c.prototype.on, c.prefixed = r, c.EventEmitter = c, t !== void 0 && (t.exports = c);
|
|
397
395
|
})))(), 1);
|
|
398
|
-
|
|
399
|
-
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/decorateMetadata.js
|
|
396
|
+
// \0@oxc-project+runtime@0.156.0/helpers/esm/decorateMetadata.js
|
|
400
397
|
function h(e, t) {
|
|
401
398
|
if (typeof Reflect == "object" && typeof Reflect.metadata == "function") return Reflect.metadata(e, t);
|
|
402
399
|
}
|
|
403
|
-
|
|
404
|
-
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/decorate.js
|
|
400
|
+
// \0@oxc-project+runtime@0.156.0/helpers/esm/decorate.js
|
|
405
401
|
function g(e, t, n, r) {
|
|
406
402
|
var i = arguments.length, a = i < 3 ? t : r === null ? r = Object.getOwnPropertyDescriptor(t, n) : r, o;
|
|
407
403
|
if (typeof Reflect == "object" && typeof Reflect.decorate == "function") a = Reflect.decorate(e, t, n, r);
|
|
408
404
|
else for (var s = e.length - 1; s >= 0; s--) (o = e[s]) && (a = (i < 3 ? o(a) : i > 3 ? o(t, n, a) : o(t, n)) || a);
|
|
409
405
|
return i > 3 && a && Object.defineProperty(t, n, a), a;
|
|
410
406
|
}
|
|
411
|
-
|
|
412
|
-
//#region src/positioning.service.ts
|
|
407
|
+
// src/positioning.service.ts
|
|
413
408
|
var _ = 60, v = class e {
|
|
414
409
|
static {
|
|
415
410
|
this.elements = /* @__PURE__ */ new Map();
|
|
@@ -603,7 +598,7 @@ var _ = 60, v = class e {
|
|
|
603
598
|
}
|
|
604
599
|
static update(t) {
|
|
605
600
|
let n = e.elements.entries(), r = [];
|
|
606
|
-
for (let [i, a] of n)
|
|
601
|
+
for (let [i, a] of n) t && t.target !== document && t.target !== a.scrollParent && t.target !== window || (e.fixElementPosition(i, a), e.checkCollisions(i, r), r.push(i));
|
|
607
602
|
}
|
|
608
603
|
on(t, n) {
|
|
609
604
|
e.on(t, n);
|
|
@@ -645,5 +640,4 @@ g([
|
|
|
645
640
|
h("design:paramtypes", [typeof Event > "u" ? Object : Event]),
|
|
646
641
|
h("design:returntype", void 0)
|
|
647
642
|
], v, "update", null);
|
|
648
|
-
//#endregion
|
|
649
643
|
export { p as DEFAULT_POSITIONING_OPTIONS, d as Position, f as PositionAnchor, v as PositioningService };
|
package/lib/index.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("@spscommerce/utils")):typeof define==`function`&&define.amd?define([`exports`,`@spscommerce/utils`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.Positioning={},e.spscommerceUtils))})(this,function(e,t){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var n=Object.create,r=Object.defineProperty,i=Object.getOwnPropertyDescriptor,a=Object.getOwnPropertyNames,o=Object.getPrototypeOf,s=Object.prototype.hasOwnProperty,c=(e,t)=>()=>(t||(e((t={exports:{}}).exports,t),e=null),t.exports),l=(e,t,n,o)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var c=a(t),l=0,u=c.length,d;l<u;l++)d=c[l],!s.call(e,d)&&d!==n&&r(e,d,{get:(e=>t[e]).bind(null,d),enumerable:!(o=i(t,d))||o.enumerable});return e},u=(e,t,i)=>(i=e==null?{}:n(o(e)),l(t||!e||!e.__esModule||!s.call(e,`default`)?r(i,`default`,{value:e,enumerable:!0}):i,e)),d=function(e){return e.TOP_LEFT=`top left`,e.TOP_MIDDLE=`top middle`,e.TOP_RIGHT=`top right`,e.RIGHT_TOP=`right top`,e.RIGHT_MIDDLE=`right middle`,e.RIGHT_BOTTOM=`right bottom`,e.BOTTOM_RIGHT=`bottom right`,e.BOTTOM_MIDDLE=`bottom middle`,e.BOTTOM_LEFT=`bottom left`,e.LEFT_BOTTOM=`left bottom`,e.LEFT_MIDDLE=`left middle`,e.LEFT_TOP=`left top`,e}({}),f=function(e){return e.TOP_LEFT=`top left`,e.TOP_RIGHT=`top right`,e.BOTTOM_LEFT=`bottom left`,e.BOTTOM_RIGHT=`bottom right`,e}({}),p={anchor:f.TOP_LEFT,offsets:[],position:d.TOP_LEFT};(function(){"use strict";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 e(e){try{return e.defaultView&&e.defaultView.frameElement||null}catch{return null}}var t=(function(t){for(var n=t,r=e(n);r;)n=r.ownerDocument,r=e(n);return n})(window.document),n=[],r=null,i=null;function a(e){this.time=e.time,this.target=e.target,this.rootBounds=m(e.rootBounds),this.boundingClientRect=m(e.boundingClientRect),this.intersectionRect=m(e.intersectionRect||p()),this.isIntersecting=!!e.intersectionRect;var t=this.boundingClientRect,n=t.width*t.height,r=this.intersectionRect,i=r.width*r.height;this.intersectionRatio=n?Number((i/n).toFixed(4)):+!!this.isIntersecting}function o(e,t){var n=t||{};if(typeof e!=`function`)throw Error(`callback must be a function`);if(n.root&&n.root.nodeType!=1&&n.root.nodeType!=9)throw Error(`root must be a Document or Element`);this._checkForIntersections=c(this._checkForIntersections.bind(this),this.THROTTLE_TIMEOUT),this._callback=e,this._observationTargets=[],this._queuedEntries=[],this._rootMarginValues=this._parseRootMargin(n.rootMargin),this.thresholds=this._initThresholds(n.threshold),this.root=n.root||null,this.rootMargin=this._rootMarginValues.map(function(e){return e.value+e.unit}).join(` `),this._monitoringDocuments=[],this._monitoringUnsubscribes=[]}o.prototype.THROTTLE_TIMEOUT=100,o.prototype.POLL_INTERVAL=null,o.prototype.USE_MUTATION_OBSERVER=!0,o._setupCrossOriginUpdater=function(){return r||=function(e,t){i=!e||!t?p():h(e,t),n.forEach(function(e){e._checkForIntersections()})},r},o._resetCrossOriginUpdater=function(){r=null,i=null},o.prototype.observe=function(e){if(!this._observationTargets.some(function(t){return t.element==e})){if(!(e&&e.nodeType==1))throw Error(`target must be an Element`);this._registerInstance(),this._observationTargets.push({element:e,entry:null}),this._monitorIntersections(e.ownerDocument),this._checkForIntersections()}},o.prototype.unobserve=function(e){this._observationTargets=this._observationTargets.filter(function(t){return t.element!=e}),this._unmonitorIntersections(e.ownerDocument),this._observationTargets.length==0&&this._unregisterInstance()},o.prototype.disconnect=function(){this._observationTargets=[],this._unmonitorAllIntersections(),this._unregisterInstance()},o.prototype.takeRecords=function(){var e=this._queuedEntries.slice();return this._queuedEntries=[],e},o.prototype._initThresholds=function(e){var t=e||[0];return Array.isArray(t)||(t=[t]),t.sort().filter(function(e,t,n){if(typeof e!=`number`||isNaN(e)||e<0||e>1)throw Error(`threshold must be a number between 0 and 1 inclusively`);return e!==n[t-1]})},o.prototype._parseRootMargin=function(e){var t=(e||`0px`).split(/\s+/).map(function(e){var t=/^(-?\d*\.?\d+)(px|%)$/.exec(e);if(!t)throw Error(`rootMargin must be specified in pixels or percent`);return{value:parseFloat(t[1]),unit:t[2]}});return t[1]=t[1]||t[0],t[2]=t[2]||t[0],t[3]=t[3]||t[1],t},o.prototype._monitorIntersections=function(n){var r=n.defaultView;if(r&&this._monitoringDocuments.indexOf(n)==-1){var i=this._checkForIntersections,a=null,o=null;if(this.POLL_INTERVAL?a=r.setInterval(i,this.POLL_INTERVAL):(l(r,`resize`,i,!0),l(n,`scroll`,i,!0),this.USE_MUTATION_OBSERVER&&`MutationObserver`in r&&(o=new r.MutationObserver(i),o.observe(n,{attributes:!0,childList:!0,characterData:!0,subtree:!0}))),this._monitoringDocuments.push(n),this._monitoringUnsubscribes.push(function(){var e=n.defaultView;e&&(a&&e.clearInterval(a),u(e,`resize`,i,!0)),u(n,`scroll`,i,!0),o&&o.disconnect()}),n!=(this.root&&(this.root.ownerDocument||this.root)||t)){var s=e(n);s&&this._monitorIntersections(s.ownerDocument)}}},o.prototype._unmonitorIntersections=function(n){var r=this._monitoringDocuments.indexOf(n);if(r!=-1){var i=this.root&&(this.root.ownerDocument||this.root)||t;if(!this._observationTargets.some(function(t){var r=t.element.ownerDocument;if(r==n)return!0;for(;r&&r!=i;){var a=e(r);if(r=a&&a.ownerDocument,r==n)return!0}return!1})){var a=this._monitoringUnsubscribes[r];if(this._monitoringDocuments.splice(r,1),this._monitoringUnsubscribes.splice(r,1),a(),n!=i){var o=e(n);o&&this._unmonitorIntersections(o.ownerDocument)}}}},o.prototype._unmonitorAllIntersections=function(){var e=this._monitoringUnsubscribes.slice(0);this._monitoringDocuments.length=0,this._monitoringUnsubscribes.length=0;for(var t=0;t<e.length;t++)e[t]()},o.prototype._checkForIntersections=function(){if(this.root||!r||i){var e=this._rootIsInDom(),t=e?this._getRootRect():p();this._observationTargets.forEach(function(n){var i=n.element,o=f(i),c=this._rootContainsTarget(i),l=n.entry,u=e&&c&&this._computeTargetAndRootIntersection(i,o,t),d=null;this._rootContainsTarget(i)?(!r||this.root)&&(d=t):d=p();var m=n.entry=new a({time:s(),target:i,boundingClientRect:o,rootBounds:d,intersectionRect:u});l?e&&c?this._hasCrossedThreshold(l,m)&&this._queuedEntries.push(m):l&&l.isIntersecting&&this._queuedEntries.push(m):this._queuedEntries.push(m)},this),this._queuedEntries.length&&this._callback(this.takeRecords(),this)}},o.prototype._computeTargetAndRootIntersection=function(e,n,a){if(window.getComputedStyle(e).display!=`none`){for(var o=n,s=_(e),c=!1;!c&&s;){var l=null,u=s.nodeType==1?window.getComputedStyle(s):{};if(u.display==`none`)return null;if(s==this.root||s.nodeType==9){if(c=!0,s==this.root||s==t)r&&!this.root?!i||i.width==0&&i.height==0?(s=null,l=null,o=null):l=i:l=a;else{var p=_(s),m=p&&f(p),g=p&&this._computeTargetAndRootIntersection(p,m,a);m&&g?(s=p,l=h(m,g)):(s=null,o=null)}}else{var v=s.ownerDocument;s!=v.body&&s!=v.documentElement&&u.overflow!=`visible`&&(l=f(s))}if(l&&(o=d(l,o)),!o)break;s&&=_(s)}return o}},o.prototype._getRootRect=function(){var e;if(this.root&&!v(this.root))e=f(this.root);else{var n=v(this.root)?this.root:t,r=n.documentElement,i=n.body;e={top:0,left:0,right:r.clientWidth||i.clientWidth,width:r.clientWidth||i.clientWidth,bottom:r.clientHeight||i.clientHeight,height:r.clientHeight||i.clientHeight}}return this._expandRectByRootMargin(e)},o.prototype._expandRectByRootMargin=function(e){var t=this._rootMarginValues.map(function(t,n){return t.unit==`px`?t.value:t.value*(n%2?e.width:e.height)/100}),n={top:e.top-t[0],right:e.right+t[1],bottom:e.bottom+t[2],left:e.left-t[3]};return n.width=n.right-n.left,n.height=n.bottom-n.top,n},o.prototype._hasCrossedThreshold=function(e,t){var n=e&&e.isIntersecting?e.intersectionRatio||0:-1,r=t.isIntersecting?t.intersectionRatio||0:-1;if(n!==r)for(var i=0;i<this.thresholds.length;i++){var a=this.thresholds[i];if(a==n||a==r||a<n!=a<r)return!0}},o.prototype._rootIsInDom=function(){return!this.root||g(t,this.root)},o.prototype._rootContainsTarget=function(e){var n=this.root&&(this.root.ownerDocument||this.root)||t;return g(n,e)&&(!this.root||n==e.ownerDocument)},o.prototype._registerInstance=function(){n.indexOf(this)<0&&n.push(this)},o.prototype._unregisterInstance=function(){var e=n.indexOf(this);e!=-1&&n.splice(e,1)};function s(){return window.performance&&performance.now&&performance.now()}function c(e,t){var n=null;return function(){n||=setTimeout(function(){e(),n=null},t)}}function l(e,t,n,r){typeof e.addEventListener==`function`?e.addEventListener(t,n,r||!1):typeof e.attachEvent==`function`&&e.attachEvent(`on`+t,n)}function u(e,t,n,r){typeof e.removeEventListener==`function`?e.removeEventListener(t,n,r||!1):typeof e.detatchEvent==`function`&&e.detatchEvent(`on`+t,n)}function d(e,t){var n=Math.max(e.top,t.top),r=Math.min(e.bottom,t.bottom),i=Math.max(e.left,t.left),a=Math.min(e.right,t.right),o=a-i,s=r-n;return o>=0&&s>=0&&{top:n,bottom:r,left:i,right:a,width:o,height:s}||null}function f(e){var t;try{t=e.getBoundingClientRect()}catch{}return t?(t.width&&t.height||(t={top:t.top,right:t.right,bottom:t.bottom,left:t.left,width:t.right-t.left,height:t.bottom-t.top}),t):p()}function p(){return{top:0,bottom:0,left:0,right:0,width:0,height:0}}function m(e){return!e||`x`in e?e:{top:e.top,y:e.top,bottom:e.bottom,left:e.left,x:e.left,right:e.right,width:e.width,height:e.height}}function h(e,t){var n=t.top-e.top,r=t.left-e.left;return{top:n,left:r,height:t.height,width:t.width,bottom:n+t.height,right:r+t.width}}function g(e,t){for(var n=t;n;){if(n==e)return!0;n=_(n)}return!1}function _(n){var r=n.parentNode;return n.nodeType==9&&n!=t?e(n):(r&&r.assignedSlot&&(r=r.assignedSlot.parentNode),r&&r.nodeType==11&&r.host?r.host:r)}function v(e){return e&&e.nodeType===9}window.IntersectionObserver=o,window.IntersectionObserverEntry=a})();var m=u(c(((e,t)=>{var n=Object.prototype.hasOwnProperty,r=`~`;function i(){}Object.create&&(i.prototype=Object.create(null),new i().__proto__||(r=!1));function a(e,t,n){this.fn=e,this.context=t,this.once=n||!1}function o(e,t,n,i,o){if(typeof n!=`function`)throw TypeError(`The listener must be a function`);var s=new a(n,i||e,o),c=r?r+t:t;return e._events[c]?e._events[c].fn?e._events[c]=[e._events[c],s]:e._events[c].push(s):(e._events[c]=s,e._eventsCount++),e}function s(e,t){--e._eventsCount===0?e._events=new i:delete e._events[t]}function c(){this._events=new i,this._eventsCount=0}c.prototype.eventNames=function(){var e=[],t,i;if(this._eventsCount===0)return e;for(i in t=this._events)n.call(t,i)&&e.push(r?i.slice(1):i);return Object.getOwnPropertySymbols?e.concat(Object.getOwnPropertySymbols(t)):e},c.prototype.listeners=function(e){var t=r?r+e:e,n=this._events[t];if(!n)return[];if(n.fn)return[n.fn];for(var i=0,a=n.length,o=Array(a);i<a;i++)o[i]=n[i].fn;return o},c.prototype.listenerCount=function(e){var t=r?r+e:e,n=this._events[t];return n?n.fn?1:n.length:0},c.prototype.emit=function(e,t,n,i,a,o){var s=r?r+e:e;if(!this._events[s])return!1;var c=this._events[s],l=arguments.length,u,d;if(c.fn){switch(c.once&&this.removeListener(e,c.fn,void 0,!0),l){case 1:return c.fn.call(c.context),!0;case 2:return c.fn.call(c.context,t),!0;case 3:return c.fn.call(c.context,t,n),!0;case 4:return c.fn.call(c.context,t,n,i),!0;case 5:return c.fn.call(c.context,t,n,i,a),!0;case 6:return c.fn.call(c.context,t,n,i,a,o),!0}for(d=1,u=Array(l-1);d<l;d++)u[d-1]=arguments[d];c.fn.apply(c.context,u)}else{var f=c.length,p;for(d=0;d<f;d++)switch(c[d].once&&this.removeListener(e,c[d].fn,void 0,!0),l){case 1:c[d].fn.call(c[d].context);break;case 2:c[d].fn.call(c[d].context,t);break;case 3:c[d].fn.call(c[d].context,t,n);break;case 4:c[d].fn.call(c[d].context,t,n,i);break;default:if(!u)for(p=1,u=Array(l-1);p<l;p++)u[p-1]=arguments[p];c[d].fn.apply(c[d].context,u)}}return!0},c.prototype.on=function(e,t,n){return o(this,e,t,n,!1)},c.prototype.once=function(e,t,n){return o(this,e,t,n,!0)},c.prototype.removeListener=function(e,t,n,i){var a=r?r+e:e;if(!this._events[a])return this;if(!t)return s(this,a),this;var o=this._events[a];if(o.fn)o.fn===t&&(!i||o.once)&&(!n||o.context===n)&&s(this,a);else{for(var c=0,l=[],u=o.length;c<u;c++)(o[c].fn!==t||i&&!o[c].once||n&&o[c].context!==n)&&l.push(o[c]);l.length?this._events[a]=l.length===1?l[0]:l:s(this,a)}return this},c.prototype.removeAllListeners=function(e){var t;return e?(t=r?r+e:e,this._events[t]&&s(this,t)):(this._events=new i,this._eventsCount=0),this},c.prototype.off=c.prototype.removeListener,c.prototype.addListener=c.prototype.on,c.prefixed=r,c.EventEmitter=c,t!==void 0&&(t.exports=c)}))(),1);function h(e,t){if(typeof Reflect==`object`&&typeof Reflect.metadata==`function`)return Reflect.metadata(e,t)}function g(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}var _=60,v=class e{static{this.elements=new Map}static{this.registeredScrollParents=new Set}static{this.events=new m.default}static{this.viewportObserver=new IntersectionObserver(e.onViewportIntersection,{rootMargin:`-${_}px 0px 0px`,threshold:1})}static on(t,n){e.events.on(t,n)}static off(t,n){e.events.off(t,n)}static once(t,n){e.events.once(t,n)}static checkCollisions(t,n){let r=n||Array.from(e.elements.keys()),i=t.getBoundingClientRect(),a=[];for(let e of r)if(e!==t){let t=e.getBoundingClientRect();t.left<=i.right&&t.right>=i.left&&t.top<=i.bottom&&t.bottom>=i.top&&a.push(e)}a.length&&e.onElementIntersection(t,a)}static isPositioned(t){return e.elements.has(t)}static getPositioningOptions(t){return e.elements.has(t)?e.elements.get(t):null}static position(n,r={}){let i={...p,...r},a=n;for(;a!==document.body;)if(a=a.parentElement,a.classList.contains(`sps-focused-task`)){i.scrollParent=a,e.registeredScrollParents.has(a)||(e.registeredScrollParents.add(a),a.addEventListener(`scroll`,e.update));break}if(n.style.visibility=`hidden`,e.elements.size===0&&(window.addEventListener(`resize`,e.update),window.addEventListener(`scroll`,e.update)),!i.relativeTo)throw Error(`You must provide an element for the relativeTo option to position an element.`);e.elements.set(n,i),(0,t.onNextTick)(()=>{e.fixElementPosition(n),e.viewportObserver.observe(n),n.style.visibility=``,e.checkCollisions(n)})}static release(t){if(e.elements.has(t)){e.clearStyles(t);let n=e.elements.get(t);n.scrollParent&&(n.scrollParent.removeEventListener(`scroll`,e.update),e.registeredScrollParents.delete(n.scrollParent)),e.elements.delete(t),e.elements.size===0&&(window.removeEventListener(`resize`,e.update),window.removeEventListener(`scroll`,e.update)),e.viewportObserver.unobserve(t)}}static releaseAll(){for(let t of e.elements.keys())e.release(t)}static refresh(t){e.elements.has(t)&&(e.clearStyles(t),e.fixElementPosition(t),e.checkCollisions(t))}static refreshAll(){for(let t of e.elements.keys())e.refresh(t)}static reposition(t,n){if(e.elements.has(t)){let r=e.elements.get(t);e.elements.set(t,Object.assign(r,n)),e.refresh(t)}}static onViewportIntersection(t){for(let n of t){let t=Object.keys(IntersectionObserverEntry.prototype).reduce((e,t)=>({...e,[t]:n[t]}),{});t.rootBounds=t.rootBounds||e.getRootBounds(),e.events.emit(`viewportIntersection`,Object.freeze(t))}}static onElementIntersection(t,n){e.events.emit(`elementIntersection`,{target:t,intersectingWith:n})}static getRootBounds(){let e=Math.max(document.documentElement.clientWidth,window.innerWidth||0),t=Math.max(document.documentElement.clientHeight,window.innerHeight||0);return{x:0,y:_,left:0,top:_,right:e,bottom:t,height:t-_,width:e}}static clearStyles(e){Object.assign(e.style,{position:``,width:``,top:``,left:``,right:``,bottom:``,visibility:``,zIndex:``})}static fixElementPosition(e,t){if(!this.elements.has(e))return;let n=t||this.elements.get(e),r=this.getRootBounds(),i=e.getBoundingClientRect(),a=n.relativeTo.getBoundingClientRect(),{width:o}=n.useRelativeTargetWidth?a:i;Object.assign(e.style,{minWidth:`${o}px`,position:`fixed`,zIndex:n.zIndex||``});let s,c,l=n.position.split(` `),u=n.offsets[0]||0,d=n.offsets[1]||0;switch(s=0,c=0,l[0]){case`top`:s=a.top-i.height-u;break;case`left`:c=a.left-o-u;break;case`right`:c=a.right+u;break;case`bottom`:s=a.bottom+u;break;default:throw Error(`${n.position} is not a valid position`)}switch(l[1]){case`left`:c=a.left-d;break;case`top`:s=a.top-d;break;case`middle`:l[0]===`top`||l[0]===`bottom`?c=a.left+a.width/2-o/2+d:(l[0]===`left`||l[0]===`right`)&&(s=a.top+a.height/2-i.height/2+d);break;case`bottom`:s=a.bottom-i.height+d;break;case`right`:c=a.right-o+d;break;default:throw Error(`${n.position} is not a valid position`)}let p=s+i.height,m=c+i.width,h=`${Math.round(s)}px`,g=`${Math.round(r.bottom-p)}px`,_=`${Math.round(c)}px`,v=`${Math.round(r.right-m)}px`;switch(n.anchor){case f.TOP_LEFT:Object.assign(e.style,{top:h,bottom:`auto`,left:_,right:`auto`});break;case f.TOP_RIGHT:Object.assign(e.style,{top:h,bottom:`auto`,left:`auto`,right:v});break;case f.BOTTOM_LEFT:Object.assign(e.style,{top:`auto`,bottom:g,left:_,right:`auto`});break;case f.BOTTOM_RIGHT:Object.assign(e.style,{top:`auto`,bottom:g,left:`auto`,right:v})}}static update(t){let n=e.elements.entries(),r=[];for(let[i,a]of n)(!t||t.target===document||t.target===a.scrollParent||t.target===window)&&(e.fixElementPosition(i,a),e.checkCollisions(i,r),r.push(i))}on(t,n){e.on(t,n)}off(t,n){e.off(t,n)}once(t,n){e.once(t,n)}isPositioned(t){return e.isPositioned(t)}getPositioningOptions(t){return e.getPositioningOptions(t)}position(t,n={}){e.position(t,n)}release(t){e.release(t)}releaseAll(){e.releaseAll()}refresh(t){e.refresh(t)}refreshAll(){e.refreshAll()}reposition(t,n){e.reposition(t,n)}};g([t.lockedToAnimationFrames,h(`design:type`,Function),h(`design:paramtypes`,[typeof Event>`u`?Object:Event]),h(`design:returntype`,void 0)],v,`update`,null),e.DEFAULT_POSITIONING_OPTIONS=p,e.Position=d,e.PositionAnchor=f,e.PositioningService=v});
|
|
1
|
+
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("@spscommerce/utils")):typeof define==`function`&&define.amd?define([`exports`,`@spscommerce/utils`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.Positioning={},e.spscommerceUtils))})(this,function(e,t){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var n=Object.create,r=Object.defineProperty,i=Object.getOwnPropertyDescriptor,a=Object.getOwnPropertyNames,o=Object.getPrototypeOf,s=Object.prototype.hasOwnProperty,c=(e,t)=>()=>(t||(e((t={exports:{}}).exports,t,t.exports),e=null),t.exports),l=(e,t,n,o)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var c=a(t),l=0,u=c.length,d;l<u;l++)d=c[l],!s.call(e,d)&&d!==n&&r(e,d,{get:(e=>t[e]).bind(null,d),enumerable:!(o=i(t,d))||o.enumerable});return e},u=(e,t,i)=>(i=e==null?{}:n(o(e)),l(t||!e||!e.__esModule||!s.call(e,`default`)?r(i,`default`,{value:e,enumerable:!0}):i,e)),d=function(e){return e.TOP_LEFT=`top left`,e.TOP_MIDDLE=`top middle`,e.TOP_RIGHT=`top right`,e.RIGHT_TOP=`right top`,e.RIGHT_MIDDLE=`right middle`,e.RIGHT_BOTTOM=`right bottom`,e.BOTTOM_RIGHT=`bottom right`,e.BOTTOM_MIDDLE=`bottom middle`,e.BOTTOM_LEFT=`bottom left`,e.LEFT_BOTTOM=`left bottom`,e.LEFT_MIDDLE=`left middle`,e.LEFT_TOP=`left top`,e}({}),f=function(e){return e.TOP_LEFT=`top left`,e.TOP_RIGHT=`top right`,e.BOTTOM_LEFT=`bottom left`,e.BOTTOM_RIGHT=`bottom right`,e}({}),p={anchor:f.TOP_LEFT,offsets:[],position:d.TOP_LEFT};(function(){"use strict";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 e(e){try{return e.defaultView&&e.defaultView.frameElement||null}catch{return null}}var t=(function(t){for(var n=t,r=e(n);r;)n=r.ownerDocument,r=e(n);return n})(window.document),n=[],r=null,i=null;function a(e){this.time=e.time,this.target=e.target,this.rootBounds=m(e.rootBounds),this.boundingClientRect=m(e.boundingClientRect),this.intersectionRect=m(e.intersectionRect||p()),this.isIntersecting=!!e.intersectionRect;var t=this.boundingClientRect,n=t.width*t.height,r=this.intersectionRect,i=r.width*r.height;this.intersectionRatio=n?Number((i/n).toFixed(4)):+!!this.isIntersecting}function o(e,t){var n=t||{};if(typeof e!=`function`)throw Error(`callback must be a function`);if(n.root&&n.root.nodeType!=1&&n.root.nodeType!=9)throw Error(`root must be a Document or Element`);this._checkForIntersections=c(this._checkForIntersections.bind(this),this.THROTTLE_TIMEOUT),this._callback=e,this._observationTargets=[],this._queuedEntries=[],this._rootMarginValues=this._parseRootMargin(n.rootMargin),this.thresholds=this._initThresholds(n.threshold),this.root=n.root||null,this.rootMargin=this._rootMarginValues.map(function(e){return e.value+e.unit}).join(` `),this._monitoringDocuments=[],this._monitoringUnsubscribes=[]}o.prototype.THROTTLE_TIMEOUT=100,o.prototype.POLL_INTERVAL=null,o.prototype.USE_MUTATION_OBSERVER=!0,o._setupCrossOriginUpdater=function(){return r||=function(e,t){i=!e||!t?p():h(e,t),n.forEach(function(e){e._checkForIntersections()})},r},o._resetCrossOriginUpdater=function(){r=null,i=null},o.prototype.observe=function(e){if(!this._observationTargets.some(function(t){return t.element==e})){if(!(e&&e.nodeType==1))throw Error(`target must be an Element`);this._registerInstance(),this._observationTargets.push({element:e,entry:null}),this._monitorIntersections(e.ownerDocument),this._checkForIntersections()}},o.prototype.unobserve=function(e){this._observationTargets=this._observationTargets.filter(function(t){return t.element!=e}),this._unmonitorIntersections(e.ownerDocument),this._observationTargets.length==0&&this._unregisterInstance()},o.prototype.disconnect=function(){this._observationTargets=[],this._unmonitorAllIntersections(),this._unregisterInstance()},o.prototype.takeRecords=function(){var e=this._queuedEntries.slice();return this._queuedEntries=[],e},o.prototype._initThresholds=function(e){var t=e||[0];return Array.isArray(t)||(t=[t]),t.sort().filter(function(e,t,n){if(typeof e!=`number`||isNaN(e)||e<0||e>1)throw Error(`threshold must be a number between 0 and 1 inclusively`);return e!==n[t-1]})},o.prototype._parseRootMargin=function(e){var t=(e||`0px`).split(/\s+/).map(function(e){var t=/^(-?\d*\.?\d+)(px|%)$/.exec(e);if(!t)throw Error(`rootMargin must be specified in pixels or percent`);return{value:parseFloat(t[1]),unit:t[2]}});return t[1]=t[1]||t[0],t[2]=t[2]||t[0],t[3]=t[3]||t[1],t},o.prototype._monitorIntersections=function(n){var r=n.defaultView;if(r&&this._monitoringDocuments.indexOf(n)==-1){var i=this._checkForIntersections,a=null,o=null;if(this.POLL_INTERVAL?a=r.setInterval(i,this.POLL_INTERVAL):(l(r,`resize`,i,!0),l(n,`scroll`,i,!0),this.USE_MUTATION_OBSERVER&&`MutationObserver`in r&&(o=new r.MutationObserver(i),o.observe(n,{attributes:!0,childList:!0,characterData:!0,subtree:!0}))),this._monitoringDocuments.push(n),this._monitoringUnsubscribes.push(function(){var e=n.defaultView;e&&(a&&e.clearInterval(a),u(e,`resize`,i,!0)),u(n,`scroll`,i,!0),o&&o.disconnect()}),n!=(this.root&&(this.root.ownerDocument||this.root)||t)){var s=e(n);s&&this._monitorIntersections(s.ownerDocument)}}},o.prototype._unmonitorIntersections=function(n){var r=this._monitoringDocuments.indexOf(n);if(r!=-1){var i=this.root&&(this.root.ownerDocument||this.root)||t;if(!this._observationTargets.some(function(t){var r=t.element.ownerDocument;if(r==n)return!0;for(;r&&r!=i;){var a=e(r);if(r=a&&a.ownerDocument,r==n)return!0}return!1})){var a=this._monitoringUnsubscribes[r];if(this._monitoringDocuments.splice(r,1),this._monitoringUnsubscribes.splice(r,1),a(),n!=i){var o=e(n);o&&this._unmonitorIntersections(o.ownerDocument)}}}},o.prototype._unmonitorAllIntersections=function(){var e=this._monitoringUnsubscribes.slice(0);this._monitoringDocuments.length=0,this._monitoringUnsubscribes.length=0;for(var t=0;t<e.length;t++)e[t]()},o.prototype._checkForIntersections=function(){if(this.root||!r||i){var e=this._rootIsInDom(),t=e?this._getRootRect():p();this._observationTargets.forEach(function(n){var i=n.element,o=f(i),c=this._rootContainsTarget(i),l=n.entry,u=e&&c&&this._computeTargetAndRootIntersection(i,o,t),d=null;this._rootContainsTarget(i)?(!r||this.root)&&(d=t):d=p();var m=n.entry=new a({time:s(),target:i,boundingClientRect:o,rootBounds:d,intersectionRect:u});l?e&&c?this._hasCrossedThreshold(l,m)&&this._queuedEntries.push(m):l&&l.isIntersecting&&this._queuedEntries.push(m):this._queuedEntries.push(m)},this),this._queuedEntries.length&&this._callback(this.takeRecords(),this)}},o.prototype._computeTargetAndRootIntersection=function(e,n,a){if(window.getComputedStyle(e).display!=`none`){for(var o=n,s=_(e),c=!1;!c&&s;){var l=null,u=s.nodeType==1?window.getComputedStyle(s):{};if(u.display==`none`)return null;if(s==this.root||s.nodeType==9){if(c=!0,s==this.root||s==t)r&&!this.root?!i||i.width==0&&i.height==0?(s=null,l=null,o=null):l=i:l=a;else{var p=_(s),m=p&&f(p),g=p&&this._computeTargetAndRootIntersection(p,m,a);m&&g?(s=p,l=h(m,g)):(s=null,o=null)}}else{var v=s.ownerDocument;s!=v.body&&s!=v.documentElement&&u.overflow!=`visible`&&(l=f(s))}if(l&&(o=d(l,o)),!o)break;s&&=_(s)}return o}},o.prototype._getRootRect=function(){var e;if(this.root&&!v(this.root))e=f(this.root);else{var n=v(this.root)?this.root:t,r=n.documentElement,i=n.body;e={top:0,left:0,right:r.clientWidth||i.clientWidth,width:r.clientWidth||i.clientWidth,bottom:r.clientHeight||i.clientHeight,height:r.clientHeight||i.clientHeight}}return this._expandRectByRootMargin(e)},o.prototype._expandRectByRootMargin=function(e){var t=this._rootMarginValues.map(function(t,n){return t.unit==`px`?t.value:t.value*(n%2?e.width:e.height)/100}),n={top:e.top-t[0],right:e.right+t[1],bottom:e.bottom+t[2],left:e.left-t[3]};return n.width=n.right-n.left,n.height=n.bottom-n.top,n},o.prototype._hasCrossedThreshold=function(e,t){var n=e&&e.isIntersecting?e.intersectionRatio||0:-1,r=t.isIntersecting?t.intersectionRatio||0:-1;if(n!==r)for(var i=0;i<this.thresholds.length;i++){var a=this.thresholds[i];if(a==n||a==r||a<n!=a<r)return!0}},o.prototype._rootIsInDom=function(){return!this.root||g(t,this.root)},o.prototype._rootContainsTarget=function(e){var n=this.root&&(this.root.ownerDocument||this.root)||t;return g(n,e)&&(!this.root||n==e.ownerDocument)},o.prototype._registerInstance=function(){n.indexOf(this)<0&&n.push(this)},o.prototype._unregisterInstance=function(){var e=n.indexOf(this);e!=-1&&n.splice(e,1)};function s(){return window.performance&&performance.now&&performance.now()}function c(e,t){var n=null;return function(){n||=setTimeout(function(){e(),n=null},t)}}function l(e,t,n,r){typeof e.addEventListener==`function`?e.addEventListener(t,n,r||!1):typeof e.attachEvent==`function`&&e.attachEvent(`on`+t,n)}function u(e,t,n,r){typeof e.removeEventListener==`function`?e.removeEventListener(t,n,r||!1):typeof e.detatchEvent==`function`&&e.detatchEvent(`on`+t,n)}function d(e,t){var n=Math.max(e.top,t.top),r=Math.min(e.bottom,t.bottom),i=Math.max(e.left,t.left),a=Math.min(e.right,t.right),o=a-i,s=r-n;return o>=0&&s>=0&&{top:n,bottom:r,left:i,right:a,width:o,height:s}||null}function f(e){var t;try{t=e.getBoundingClientRect()}catch{}return t?(t.width&&t.height||(t={top:t.top,right:t.right,bottom:t.bottom,left:t.left,width:t.right-t.left,height:t.bottom-t.top}),t):p()}function p(){return{top:0,bottom:0,left:0,right:0,width:0,height:0}}function m(e){return!e||`x`in e?e:{top:e.top,y:e.top,bottom:e.bottom,left:e.left,x:e.left,right:e.right,width:e.width,height:e.height}}function h(e,t){var n=t.top-e.top,r=t.left-e.left;return{top:n,left:r,height:t.height,width:t.width,bottom:n+t.height,right:r+t.width}}function g(e,t){for(var n=t;n;){if(n==e)return!0;n=_(n)}return!1}function _(n){var r=n.parentNode;return n.nodeType==9&&n!=t?e(n):(r&&r.assignedSlot&&(r=r.assignedSlot.parentNode),r&&r.nodeType==11&&r.host?r.host:r)}function v(e){return e&&e.nodeType===9}window.IntersectionObserver=o,window.IntersectionObserverEntry=a})();var m=u(c(((e,t)=>{var n=Object.prototype.hasOwnProperty,r=`~`;function i(){}Object.create&&(i.prototype=Object.create(null),new i().__proto__||(r=!1));function a(e,t,n){this.fn=e,this.context=t,this.once=n||!1}function o(e,t,n,i,o){if(typeof n!=`function`)throw TypeError(`The listener must be a function`);var s=new a(n,i||e,o),c=r?r+t:t;return e._events[c]?e._events[c].fn?e._events[c]=[e._events[c],s]:e._events[c].push(s):(e._events[c]=s,e._eventsCount++),e}function s(e,t){--e._eventsCount===0?e._events=new i:delete e._events[t]}function c(){this._events=new i,this._eventsCount=0}c.prototype.eventNames=function(){var e=[],t,i;if(this._eventsCount===0)return e;for(i in t=this._events)n.call(t,i)&&e.push(r?i.slice(1):i);return Object.getOwnPropertySymbols?e.concat(Object.getOwnPropertySymbols(t)):e},c.prototype.listeners=function(e){var t=r?r+e:e,n=this._events[t];if(!n)return[];if(n.fn)return[n.fn];for(var i=0,a=n.length,o=Array(a);i<a;i++)o[i]=n[i].fn;return o},c.prototype.listenerCount=function(e){var t=r?r+e:e,n=this._events[t];return n?n.fn?1:n.length:0},c.prototype.emit=function(e,t,n,i,a,o){var s=r?r+e:e;if(!this._events[s])return!1;var c=this._events[s],l=arguments.length,u,d;if(c.fn){switch(c.once&&this.removeListener(e,c.fn,void 0,!0),l){case 1:return c.fn.call(c.context),!0;case 2:return c.fn.call(c.context,t),!0;case 3:return c.fn.call(c.context,t,n),!0;case 4:return c.fn.call(c.context,t,n,i),!0;case 5:return c.fn.call(c.context,t,n,i,a),!0;case 6:return c.fn.call(c.context,t,n,i,a,o),!0}for(d=1,u=Array(l-1);d<l;d++)u[d-1]=arguments[d];c.fn.apply(c.context,u)}else{var f=c.length,p;for(d=0;d<f;d++)switch(c[d].once&&this.removeListener(e,c[d].fn,void 0,!0),l){case 1:c[d].fn.call(c[d].context);break;case 2:c[d].fn.call(c[d].context,t);break;case 3:c[d].fn.call(c[d].context,t,n);break;case 4:c[d].fn.call(c[d].context,t,n,i);break;default:if(!u)for(p=1,u=Array(l-1);p<l;p++)u[p-1]=arguments[p];c[d].fn.apply(c[d].context,u)}}return!0},c.prototype.on=function(e,t,n){return o(this,e,t,n,!1)},c.prototype.once=function(e,t,n){return o(this,e,t,n,!0)},c.prototype.removeListener=function(e,t,n,i){var a=r?r+e:e;if(!this._events[a])return this;if(!t)return s(this,a),this;var o=this._events[a];if(o.fn)o.fn!==t||i&&!o.once||n&&o.context!==n||s(this,a);else{for(var c=0,l=[],u=o.length;c<u;c++)(o[c].fn!==t||i&&!o[c].once||n&&o[c].context!==n)&&l.push(o[c]);l.length?this._events[a]=l.length===1?l[0]:l:s(this,a)}return this},c.prototype.removeAllListeners=function(e){var t;return e?(t=r?r+e:e,this._events[t]&&s(this,t)):(this._events=new i,this._eventsCount=0),this},c.prototype.off=c.prototype.removeListener,c.prototype.addListener=c.prototype.on,c.prefixed=r,c.EventEmitter=c,t!==void 0&&(t.exports=c)}))(),1);function h(e,t){if(typeof Reflect==`object`&&typeof Reflect.metadata==`function`)return Reflect.metadata(e,t)}function g(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}var _=60,v=class e{static{this.elements=new Map}static{this.registeredScrollParents=new Set}static{this.events=new m.default}static{this.viewportObserver=new IntersectionObserver(e.onViewportIntersection,{rootMargin:`-${_}px 0px 0px`,threshold:1})}static on(t,n){e.events.on(t,n)}static off(t,n){e.events.off(t,n)}static once(t,n){e.events.once(t,n)}static checkCollisions(t,n){let r=n||Array.from(e.elements.keys()),i=t.getBoundingClientRect(),a=[];for(let e of r)if(e!==t){let t=e.getBoundingClientRect();t.left<=i.right&&t.right>=i.left&&t.top<=i.bottom&&t.bottom>=i.top&&a.push(e)}a.length&&e.onElementIntersection(t,a)}static isPositioned(t){return e.elements.has(t)}static getPositioningOptions(t){return e.elements.has(t)?e.elements.get(t):null}static position(n,r={}){let i={...p,...r},a=n;for(;a!==document.body;)if(a=a.parentElement,a.classList.contains(`sps-focused-task`)){i.scrollParent=a,e.registeredScrollParents.has(a)||(e.registeredScrollParents.add(a),a.addEventListener(`scroll`,e.update));break}if(n.style.visibility=`hidden`,e.elements.size===0&&(window.addEventListener(`resize`,e.update),window.addEventListener(`scroll`,e.update)),!i.relativeTo)throw Error(`You must provide an element for the relativeTo option to position an element.`);e.elements.set(n,i),(0,t.onNextTick)(()=>{e.fixElementPosition(n),e.viewportObserver.observe(n),n.style.visibility=``,e.checkCollisions(n)})}static release(t){if(e.elements.has(t)){e.clearStyles(t);let n=e.elements.get(t);n.scrollParent&&(n.scrollParent.removeEventListener(`scroll`,e.update),e.registeredScrollParents.delete(n.scrollParent)),e.elements.delete(t),e.elements.size===0&&(window.removeEventListener(`resize`,e.update),window.removeEventListener(`scroll`,e.update)),e.viewportObserver.unobserve(t)}}static releaseAll(){for(let t of e.elements.keys())e.release(t)}static refresh(t){e.elements.has(t)&&(e.clearStyles(t),e.fixElementPosition(t),e.checkCollisions(t))}static refreshAll(){for(let t of e.elements.keys())e.refresh(t)}static reposition(t,n){if(e.elements.has(t)){let r=e.elements.get(t);e.elements.set(t,Object.assign(r,n)),e.refresh(t)}}static onViewportIntersection(t){for(let n of t){let t=Object.keys(IntersectionObserverEntry.prototype).reduce((e,t)=>({...e,[t]:n[t]}),{});t.rootBounds=t.rootBounds||e.getRootBounds(),e.events.emit(`viewportIntersection`,Object.freeze(t))}}static onElementIntersection(t,n){e.events.emit(`elementIntersection`,{target:t,intersectingWith:n})}static getRootBounds(){let e=Math.max(document.documentElement.clientWidth,window.innerWidth||0),t=Math.max(document.documentElement.clientHeight,window.innerHeight||0);return{x:0,y:_,left:0,top:_,right:e,bottom:t,height:t-_,width:e}}static clearStyles(e){Object.assign(e.style,{position:``,width:``,top:``,left:``,right:``,bottom:``,visibility:``,zIndex:``})}static fixElementPosition(e,t){if(!this.elements.has(e))return;let n=t||this.elements.get(e),r=this.getRootBounds(),i=e.getBoundingClientRect(),a=n.relativeTo.getBoundingClientRect(),{width:o}=n.useRelativeTargetWidth?a:i;Object.assign(e.style,{minWidth:`${o}px`,position:`fixed`,zIndex:n.zIndex||``});let s,c,l=n.position.split(` `),u=n.offsets[0]||0,d=n.offsets[1]||0;switch(s=0,c=0,l[0]){case`top`:s=a.top-i.height-u;break;case`left`:c=a.left-o-u;break;case`right`:c=a.right+u;break;case`bottom`:s=a.bottom+u;break;default:throw Error(`${n.position} is not a valid position`)}switch(l[1]){case`left`:c=a.left-d;break;case`top`:s=a.top-d;break;case`middle`:l[0]===`top`||l[0]===`bottom`?c=a.left+a.width/2-o/2+d:(l[0]===`left`||l[0]===`right`)&&(s=a.top+a.height/2-i.height/2+d);break;case`bottom`:s=a.bottom-i.height+d;break;case`right`:c=a.right-o+d;break;default:throw Error(`${n.position} is not a valid position`)}let p=s+i.height,m=c+i.width,h=`${Math.round(s)}px`,g=`${Math.round(r.bottom-p)}px`,_=`${Math.round(c)}px`,v=`${Math.round(r.right-m)}px`;switch(n.anchor){case f.TOP_LEFT:Object.assign(e.style,{top:h,bottom:`auto`,left:_,right:`auto`});break;case f.TOP_RIGHT:Object.assign(e.style,{top:h,bottom:`auto`,left:`auto`,right:v});break;case f.BOTTOM_LEFT:Object.assign(e.style,{top:`auto`,bottom:g,left:_,right:`auto`});break;case f.BOTTOM_RIGHT:Object.assign(e.style,{top:`auto`,bottom:g,left:`auto`,right:v})}}static update(t){let n=e.elements.entries(),r=[];for(let[i,a]of n)t&&t.target!==document&&t.target!==a.scrollParent&&t.target!==window||(e.fixElementPosition(i,a),e.checkCollisions(i,r),r.push(i))}on(t,n){e.on(t,n)}off(t,n){e.off(t,n)}once(t,n){e.once(t,n)}isPositioned(t){return e.isPositioned(t)}getPositioningOptions(t){return e.getPositioningOptions(t)}position(t,n={}){e.position(t,n)}release(t){e.release(t)}releaseAll(){e.releaseAll()}refresh(t){e.refresh(t)}refreshAll(){e.refreshAll()}reposition(t,n){e.reposition(t,n)}};g([t.lockedToAnimationFrames,h(`design:type`,Function),h(`design:paramtypes`,[typeof Event>`u`?Object:Event]),h(`design:returntype`,void 0)],v,`update`,null),e.DEFAULT_POSITIONING_OPTIONS=p,e.Position=d,e.PositionAnchor=f,e.PositioningService=v});
|
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.56.
|
|
4
|
+
"version": "8.56.22",
|
|
5
5
|
"author": "SPS Commerce",
|
|
6
6
|
"license": "UNLICENSED",
|
|
7
7
|
"repository": "https://github.com/spscommerce/woodland/tree/main/packages/@spscommerce/positioning",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"@spscommerce/utils": "^7.0.0 || ^8.0.0 || ^9.0.0"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@spscommerce/utils": "9.
|
|
26
|
+
"@spscommerce/utils": "9.5.0",
|
|
27
27
|
"raf-stub": "3.0.0"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|