@spscommerce/positioning 7.17.13 → 7.19.0
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.
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var W=Object.defineProperty;var $=(I,L,D)=>L in I?W(I,L,{enumerable:!0,configurable:!0,writable:!0,value:D}):I[L]=D;var C=(I,L,D)=>($(I,typeof L!="symbol"?L+"":L,D),D);(function(I,L){typeof exports=="object"&&typeof module<"u"?L(exports,require("@spscommerce/utils")):typeof define=="function"&&define.amd?define(["exports","@spscommerce/utils"],L):(I=typeof globalThis<"u"?globalThis:I||self,L(I.Positioning={},I.utils))})(this,function(I,L){var A;"use strict";var D=(e=>(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))(D||{}),B=(e=>(e.TOP_LEFT="top left",e.TOP_RIGHT="top right",e.BOTTOM_LEFT="bottom left",e.BOTTOM_RIGHT="bottom right",e))(B||{});const F={anchor:B.TOP_LEFT,offsets:[],position:D.TOP_LEFT};(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 e(t){try{return t.defaultView&&t.defaultView.frameElement||null}catch{return null}}var r=function(t){for(var n=t,o=e(n);o;)n=o.ownerDocument,o=e(n);return n}(window.document),c=[],f=null,d=null;function b(t){this.time=t.time,this.target=t.target,this.rootBounds=m(t.rootBounds),this.boundingClientRect=m(t.boundingClientRect),this.intersectionRect=m(t.intersectionRect||w()),this.isIntersecting=!!t.intersectionRect;var n=this.boundingClientRect,o=n.width*n.height,s=this.intersectionRect,a=s.width*s.height;o?this.intersectionRatio=Number((a/o).toFixed(4)):this.intersectionRatio=this.isIntersecting?1:0}function u(t,n){var o=n||{};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=[]}u.prototype.THROTTLE_TIMEOUT=100,u.prototype.POLL_INTERVAL=null,u.prototype.USE_MUTATION_OBSERVER=!0,u._setupCrossOriginUpdater=function(){return f||(f=function(t,n){!t||!n?d=w():d=x(t,n),c.forEach(function(o){o._checkForIntersections()})}),f},u._resetCrossOriginUpdater=function(){f=null,d=null},u.prototype.observe=function(t){var n=this._observationTargets.some(function(o){return o.element==t});if(!n){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()}},u.prototype.unobserve=function(t){this._observationTargets=this._observationTargets.filter(function(n){return n.element!=t}),this._unmonitorIntersections(t.ownerDocument),this._observationTargets.length==0&&this._unregisterInstance()},u.prototype.disconnect=function(){this._observationTargets=[],this._unmonitorAllIntersections(),this._unregisterInstance()},u.prototype.takeRecords=function(){var t=this._queuedEntries.slice();return this._queuedEntries=[],t},u.prototype._initThresholds=function(t){var n=t||[0];return Array.isArray(n)||(n=[n]),n.sort().filter(function(o,s,a){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!==a[s-1]})},u.prototype._parseRootMargin=function(t){var n=t||"0px",o=n.split(/\s+/).map(function(s){var a=/^(-?\d*\.?\d+)(px|%)$/.exec(s);if(!a)throw new Error("rootMargin must be specified in pixels or percent");return{value:parseFloat(a[1]),unit:a[2]}});return o[1]=o[1]||o[0],o[2]=o[2]||o[0],o[3]=o[3]||o[1],o},u.prototype._monitorIntersections=function(t){var n=t.defaultView;if(!!n&&this._monitoringDocuments.indexOf(t)==-1){var o=this._checkForIntersections,s=null,a=null;this.POLL_INTERVAL?s=n.setInterval(o,this.POLL_INTERVAL):(l(n,"resize",o,!0),l(t,"scroll",o,!0),this.USE_MUTATION_OBSERVER&&"MutationObserver"in n&&(a=new n.MutationObserver(o),a.observe(t,{attributes:!0,childList:!0,characterData:!0,subtree:!0}))),this._monitoringDocuments.push(t),this._monitoringUnsubscribes.push(function(){var O=t.defaultView;O&&(s&&O.clearInterval(s),p(O,"resize",o,!0)),p(t,"scroll",o,!0),a&&a.disconnect()});var E=this.root&&(this.root.ownerDocument||this.root)||r;if(t!=E){var y=e(t);y&&this._monitorIntersections(y.ownerDocument)}}},u.prototype._unmonitorIntersections=function(t){var n=this._monitoringDocuments.indexOf(t);if(n!=-1){var o=this.root&&(this.root.ownerDocument||this.root)||r,s=this._observationTargets.some(function(y){var O=y.element.ownerDocument;if(O==t)return!0;for(;O&&O!=o;){var M=e(O);if(O=M&&M.ownerDocument,O==t)return!0}return!1});if(!s){var a=this._monitoringUnsubscribes[n];if(this._monitoringDocuments.splice(n,1),this._monitoringUnsubscribes.splice(n,1),a(),t!=o){var E=e(t);E&&this._unmonitorIntersections(E.ownerDocument)}}}},u.prototype._unmonitorAllIntersections=function(){var t=this._monitoringUnsubscribes.slice(0);this._monitoringDocuments.length=0,this._monitoringUnsubscribes.length=0;for(var n=0;n<t.length;n++)t[n]()},u.prototype._checkForIntersections=function(){if(!(!this.root&&f&&!d)){var t=this._rootIsInDom(),n=t?this._getRootRect():w();this._observationTargets.forEach(function(o){var s=o.element,a=T(s),E=this._rootContainsTarget(s),y=o.entry,O=t&&E&&this._computeTargetAndRootIntersection(s,a,n),M=null;this._rootContainsTarget(s)?(!f||this.root)&&(M=n):M=w();var k=o.entry=new b({time:_(),target:s,boundingClientRect:a,rootBounds:M,intersectionRect:O});y?t&&E?this._hasCrossedThreshold(y,k)&&this._queuedEntries.push(k):y&&y.isIntersecting&&this._queuedEntries.push(k):this._queuedEntries.push(k)},this),this._queuedEntries.length&&this._callback(this.takeRecords(),this)}},u.prototype._computeTargetAndRootIntersection=function(t,n,o){if(window.getComputedStyle(t).display!="none"){for(var s=n,a=R(t),E=!1;!E&&a;){var y=null,O=a.nodeType==1?window.getComputedStyle(a):{};if(O.display=="none")return null;if(a==this.root||a.nodeType==9)if(E=!0,a==this.root||a==r)f&&!this.root?!d||d.width==0&&d.height==0?(a=null,y=null,s=null):y=d:y=o;else{var M=R(a),k=M&&T(M),j=M&&this._computeTargetAndRootIntersection(M,k,o);k&&j?(a=M,y=x(k,j)):(a=null,s=null)}else{var U=a.ownerDocument;a!=U.body&&a!=U.documentElement&&O.overflow!="visible"&&(y=T(a))}if(y&&(s=v(y,s)),!s)break;a=a&&R(a)}return s}},u.prototype._getRootRect=function(){var t;if(this.root&&!P(this.root))t=T(this.root);else{var n=P(this.root)?this.root:r,o=n.documentElement,s=n.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)},u.prototype._expandRectByRootMargin=function(t){var n=this._rootMarginValues.map(function(s,a){return s.unit=="px"?s.value:s.value*(a%2?t.width:t.height)/100}),o={top:t.top-n[0],right:t.right+n[1],bottom:t.bottom+n[2],left:t.left-n[3]};return o.width=o.right-o.left,o.height=o.bottom-o.top,o},u.prototype._hasCrossedThreshold=function(t,n){var o=t&&t.isIntersecting?t.intersectionRatio||0:-1,s=n.isIntersecting?n.intersectionRatio||0:-1;if(o!==s)for(var a=0;a<this.thresholds.length;a++){var E=this.thresholds[a];if(E==o||E==s||E<o!=E<s)return!0}},u.prototype._rootIsInDom=function(){return!this.root||h(r,this.root)},u.prototype._rootContainsTarget=function(t){var n=this.root&&(this.root.ownerDocument||this.root)||r;return h(n,t)&&(!this.root||n==t.ownerDocument)},u.prototype._registerInstance=function(){c.indexOf(this)<0&&c.push(this)},u.prototype._unregisterInstance=function(){var t=c.indexOf(this);t!=-1&&c.splice(t,1)};function _(){return window.performance&&performance.now&&performance.now()}function g(t,n){var o=null;return function(){o||(o=setTimeout(function(){t(),o=null},n))}}function l(t,n,o,s){typeof t.addEventListener=="function"?t.addEventListener(n,o,s||!1):typeof t.attachEvent=="function"&&t.attachEvent("on"+n,o)}function p(t,n,o,s){typeof t.removeEventListener=="function"?t.removeEventListener(n,o,s||!1):typeof t.detatchEvent=="function"&&t.detatchEvent("on"+n,o)}function v(t,n){var o=Math.max(t.top,n.top),s=Math.min(t.bottom,n.bottom),a=Math.max(t.left,n.left),E=Math.min(t.right,n.right),y=E-a,O=s-o;return y>=0&&O>=0&&{top:o,bottom:s,left:a,right:E,width:y,height:O}||null}function T(t){var n;try{n=t.getBoundingClientRect()}catch{}return n?(n.width&&n.height||(n={top:n.top,right:n.right,bottom:n.bottom,left:n.left,width:n.right-n.left,height:n.bottom-n.top}),n):w()}function w(){return{top:0,bottom:0,left:0,right:0,width:0,height:0}}function m(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 x(t,n){var o=n.top-t.top,s=n.left-t.left;return{top:o,left:s,height:n.height,width:n.width,bottom:o+n.height,right:s+n.width}}function h(t,n){for(var o=n;o;){if(o==t)return!0;o=R(o)}return!1}function R(t){var n=t.parentNode;return t.nodeType==9&&t!=r?e(t):(n&&n.assignedSlot&&(n=n.assignedSlot.parentNode),n&&n.nodeType==11&&n.host?n.host:n)}function P(t){return t&&t.nodeType===9}window.IntersectionObserver=u,window.IntersectionObserverEntry=b})();var N={exports:{}};(function(e){var r=Object.prototype.hasOwnProperty,c="~";function f(){}Object.create&&(f.prototype=Object.create(null),new f().__proto__||(c=!1));function d(g,l,p){this.fn=g,this.context=l,this.once=p||!1}function b(g,l,p,v,T){if(typeof p!="function")throw new TypeError("The listener must be a function");var w=new d(p,v||g,T),m=c?c+l:l;return g._events[m]?g._events[m].fn?g._events[m]=[g._events[m],w]:g._events[m].push(w):(g._events[m]=w,g._eventsCount++),g}function u(g,l){--g._eventsCount===0?g._events=new f:delete g._events[l]}function _(){this._events=new f,this._eventsCount=0}_.prototype.eventNames=function(){var l=[],p,v;if(this._eventsCount===0)return l;for(v in p=this._events)r.call(p,v)&&l.push(c?v.slice(1):v);return Object.getOwnPropertySymbols?l.concat(Object.getOwnPropertySymbols(p)):l},_.prototype.listeners=function(l){var p=c?c+l:l,v=this._events[p];if(!v)return[];if(v.fn)return[v.fn];for(var T=0,w=v.length,m=new Array(w);T<w;T++)m[T]=v[T].fn;return m},_.prototype.listenerCount=function(l){var p=c?c+l:l,v=this._events[p];return v?v.fn?1:v.length:0},_.prototype.emit=function(l,p,v,T,w,m){var x=c?c+l:l;if(!this._events[x])return!1;var h=this._events[x],R=arguments.length,P,t;if(h.fn){switch(h.once&&this.removeListener(l,h.fn,void 0,!0),R){case 1:return h.fn.call(h.context),!0;case 2:return h.fn.call(h.context,p),!0;case 3:return h.fn.call(h.context,p,v),!0;case 4:return h.fn.call(h.context,p,v,T),!0;case 5:return h.fn.call(h.context,p,v,T,w),!0;case 6:return h.fn.call(h.context,p,v,T,w,m),!0}for(t=1,P=new Array(R-1);t<R;t++)P[t-1]=arguments[t];h.fn.apply(h.context,P)}else{var n=h.length,o;for(t=0;t<n;t++)switch(h[t].once&&this.removeListener(l,h[t].fn,void 0,!0),R){case 1:h[t].fn.call(h[t].context);break;case 2:h[t].fn.call(h[t].context,p);break;case 3:h[t].fn.call(h[t].context,p,v);break;case 4:h[t].fn.call(h[t].context,p,v,T);break;default:if(!P)for(o=1,P=new Array(R-1);o<R;o++)P[o-1]=arguments[o];h[t].fn.apply(h[t].context,P)}}return!0},_.prototype.on=function(l,p,v){return b(this,l,p,v,!1)},_.prototype.once=function(l,p,v){return b(this,l,p,v,!0)},_.prototype.removeListener=function(l,p,v,T){var w=c?c+l:l;if(!this._events[w])return this;if(!p)return u(this,w),this;var m=this._events[w];if(m.fn)m.fn===p&&(!T||m.once)&&(!v||m.context===v)&&u(this,w);else{for(var x=0,h=[],R=m.length;x<R;x++)(m[x].fn!==p||T&&!m[x].once||v&&m[x].context!==v)&&h.push(m[x]);h.length?this._events[w]=h.length===1?h[0]:h:u(this,w)}return this},_.prototype.removeAllListeners=function(l){var p;return l?(p=c?c+l:l,this._events[p]&&u(this,p)):(this._events=new f,this._eventsCount=0),this},_.prototype.off=_.prototype.removeListener,_.prototype.addListener=_.prototype.on,_.prefixed=c,_.EventEmitter=_,e.exports=_})(N);var V=Object.defineProperty,G=Object.getOwnPropertyDescriptor,z=(e,r,c,f)=>{for(var d=f>1?void 0:f?G(r,c):r,b=e.length-1,u;b>=0;b--)(u=e[b])&&(d=(f?u(r,c,d):u(d))||d);return f&&d&&V(r,c,d),d};const S=60,i=(A=class{static on(e,r){i.events.on(e,r)}static off(e,r){i.events.off(e,r)}static once(e,r){i.events.once(e,r)}static checkCollisions(e,r){const c=r||Array.from(i.elements.keys()),f=e.getBoundingClientRect(),d=[];for(const b of c)if(b!==e){const u=b.getBoundingClientRect();u.left<=f.right&&u.right>=f.left&&u.top<=f.bottom&&u.bottom>=f.top&&d.push(b)}d.length&&i.onElementIntersection(e,d)}static isPositioned(e){return i.elements.has(e)}static getPositioningOptions(e){return i.elements.has(e)?i.elements.get(e):null}static position(e,r={}){const c={...F,...r};let f=e;for(;f!==document.body;)if(f=f.parentElement,f.classList.contains("sps-focused-task")){c.scrollParent=f,i.registeredScrollParents.has(f)||(i.registeredScrollParents.add(f),f.addEventListener("scroll",i.update));break}if(e.style.visibility="hidden",i.elements.size===0&&(window.addEventListener("resize",i.update),window.addEventListener("scroll",i.update)),!c.relativeTo)throw new Error("You must provide an element for the relativeTo option to position an element.");i.elements.set(e,c),L.onNextTick(()=>{i.fixElementPosition(e),i.viewportObserver.observe(e),e.style.visibility="",i.checkCollisions(e)})}static release(e){if(i.elements.has(e)){i.clearStyles(e);const r=i.elements.get(e);r.scrollParent&&(r.scrollParent.removeEventListener("scroll",i.update),i.registeredScrollParents.delete(r.scrollParent)),i.elements.delete(e),i.elements.size===0&&(window.removeEventListener("resize",i.update),window.removeEventListener("scroll",i.update)),i.viewportObserver.unobserve(e)}}static releaseAll(){for(const e of i.elements.keys())i.release(e)}static refresh(e){i.elements.has(e)&&(i.clearStyles(e),i.fixElementPosition(e),i.checkCollisions(e))}static refreshAll(){for(const e of i.elements.keys())i.refresh(e)}static reposition(e,r){if(i.elements.has(e)){const c=i.elements.get(e);i.elements.set(e,Object.assign(c,r)),i.refresh(e)}}static onViewportIntersection(e){for(const r of e){const c=Object.keys(IntersectionObserverEntry.prototype).reduce((f,d)=>({...f,[d]:r[d]}),{});c.rootBounds=c.rootBounds||i.getRootBounds(),i.events.emit("viewportIntersection",Object.freeze(c))}}static onElementIntersection(e,r){i.events.emit("elementIntersection",{target:e,intersectingWith:r})}static getRootBounds(){const e=Math.max(document.documentElement.clientWidth,window.innerWidth||0),r=Math.max(document.documentElement.clientHeight,window.innerHeight||0);return{x:0,y:S,left:0,top:S,right:e,bottom:r,height:r-S,width:e}}static clearStyles(e){Object.assign(e.style,{position:"",width:"",top:"",left:"",right:"",bottom:"",visibility:"",zIndex:""})}static fixElementPosition(e,r){if(!this.elements.has(e))return;const c=r||this.elements.get(e),f=this.getRootBounds(),d=e.getBoundingClientRect(),b=c.relativeTo.getBoundingClientRect(),{width:u}=c.useRelativeTargetWidth?b:d;Object.assign(e.style,{minWidth:`${u}px`,position:"fixed",zIndex:c.zIndex||""});let _,g;const l=c.position.split(" "),p=c.offsets[0]||0,v=c.offsets[1]||0;switch(_=0,g=0,l[0]){case"top":_=b.top-d.height-p;break;case"left":g=b.left-u-p;break;case"right":g=b.right+p;break;case"bottom":_=b.bottom+p;break;default:throw new Error(`${c.position} is not a valid position`)}switch(l[1]){case"left":g=b.left-v;break;case"top":_=b.top-v;break;case"middle":l[0]==="top"||l[0]==="bottom"?g=b.left+b.width/2-u/2+v:(l[0]==="left"||l[0]==="right")&&(_=b.top+b.height/2-d.height/2+v);break;case"bottom":_=b.bottom-d.height+v;break;case"right":g=b.right-u+v;break;default:throw new Error(`${c.position} is not a valid position`)}const T=_+d.height,w=g+d.width,m=`${Math.round(_)}px`,x=`${Math.round(f.bottom-T)}px`,h=`${Math.round(g)}px`,R=`${Math.round(f.right-w)}px`;switch(c.anchor){case B.TOP_LEFT:Object.assign(e.style,{top:m,bottom:"auto",left:h,right:"auto"});break;case B.TOP_RIGHT:Object.assign(e.style,{top:m,bottom:"auto",left:"auto",right:R});break;case B.BOTTOM_LEFT:Object.assign(e.style,{top:"auto",bottom:x,left:h,right:"auto"});break;case B.BOTTOM_RIGHT:Object.assign(e.style,{top:"auto",bottom:x,left:"auto",right:R});break}}static update(e){const r=i.elements.entries(),c=[];for(const[f,d]of r)(!e||e.target===document||e.target===d.scrollParent||e.target===window)&&(i.fixElementPosition(f,d),i.checkCollisions(f,c),c.push(f))}on(e,r){i.on(e,r)}off(e,r){i.off(e,r)}once(e,r){i.once(e,r)}isPositioned(e){return i.isPositioned(e)}getPositioningOptions(e){return i.getPositioningOptions(e)}position(e,r={}){i.position(e,r)}release(e){i.release(e)}releaseAll(){i.releaseAll()}refresh(e){i.refresh(e)}refreshAll(){i.refreshAll()}reposition(e,r){i.reposition(e,r)}},C(A,"elements",new Map),C(A,"registeredScrollParents",new Set),C(A,"events",new N.exports.EventEmitter),C(A,"viewportObserver",new IntersectionObserver(i.onViewportIntersection,{rootMargin:`-${S}px 0px 0px`,threshold:1})),A);let H=i;z([L.lockedToAnimationFrames],H,"update",1),I.DEFAULT_POSITIONING_OPTIONS=F,I.Position=D,I.PositionAnchor=B,I.PositioningService=H,Object.defineProperties(I,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
package/package.json
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spscommerce/positioning",
|
|
3
3
|
"description": "Service for positioning dropdown/popup elements.",
|
|
4
|
-
"version": "7.
|
|
4
|
+
"version": "7.19.0",
|
|
5
5
|
"author": "SPS Commerce",
|
|
6
6
|
"license": "UNLICENSED",
|
|
7
7
|
"repository": "https://github.com/spscommerce/woodland/tree/main/packages/@spscommerce/positioning",
|
|
8
8
|
"homepage": "https://github.com/spscommerce/woodland/tree/main/packages/@spscommerce/positioning#readme",
|
|
9
|
-
"module": "./lib/index.es.js",
|
|
10
9
|
"type": "module",
|
|
11
|
-
"
|
|
10
|
+
"module": "./lib/index.js",
|
|
11
|
+
"main": "./lib/index.umd.cjs",
|
|
12
12
|
"types": "./lib/index.d.ts",
|
|
13
13
|
"exports": {
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
"default": "./lib/index.
|
|
14
|
+
"require": "./lib/index.umd.cjs",
|
|
15
|
+
"import": "./lib/index.js",
|
|
16
|
+
"default": "./lib/index.js",
|
|
17
17
|
"types": "./lib/index.d.ts"
|
|
18
18
|
},
|
|
19
19
|
"publishConfig": {
|
|
Binary file
|
package/vite.config.js
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import path from
|
|
1
|
+
import path from "path";
|
|
2
2
|
|
|
3
|
-
import { defineConfig } from
|
|
3
|
+
import { defineConfig } from "vite";
|
|
4
4
|
|
|
5
|
-
import pkg from
|
|
5
|
+
import pkg from "./package.json";
|
|
6
6
|
|
|
7
7
|
export default defineConfig({
|
|
8
8
|
build: {
|
|
9
9
|
lib: {
|
|
10
|
-
entry: path.resolve(__dirname,
|
|
11
|
-
|
|
12
|
-
fileName:
|
|
10
|
+
entry: path.resolve(__dirname, "src/index.ts"),
|
|
11
|
+
name: "Positioning",
|
|
12
|
+
fileName: "index",
|
|
13
13
|
},
|
|
14
|
-
outDir: path.resolve(__dirname,
|
|
14
|
+
outDir: path.resolve(__dirname, "./lib"),
|
|
15
15
|
emptyOutDir: false,
|
|
16
16
|
rollupOptions: {
|
|
17
17
|
external: pkg.peerDependencies ? Object.keys(pkg.peerDependencies) : [],
|
|
18
18
|
},
|
|
19
19
|
},
|
|
20
|
-
});
|
|
20
|
+
});
|
package/lib/index.cjs.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";var j=Object.defineProperty;var V=(e,r,s)=>r in e?j(e,r,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[r]=s;var k=(e,r,s)=>(V(e,typeof r!="symbol"?r+"":r,s),s);Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const F=require("@spscommerce/utils");var A=(e=>(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))(A||{}),D=(e=>(e.TOP_LEFT="top left",e.TOP_RIGHT="top right",e.BOTTOM_LEFT="bottom left",e.BOTTOM_RIGHT="bottom right",e))(D||{});const N={anchor:D.TOP_LEFT,offsets:[],position:A.TOP_LEFT};(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 e(t){try{return t.defaultView&&t.defaultView.frameElement||null}catch{return null}}var r=function(t){for(var n=t,o=e(n);o;)n=o.ownerDocument,o=e(n);return n}(window.document),s=[],f=null,g=null;function b(t){this.time=t.time,this.target=t.target,this.rootBounds=m(t.rootBounds),this.boundingClientRect=m(t.boundingClientRect),this.intersectionRect=m(t.intersectionRect||w()),this.isIntersecting=!!t.intersectionRect;var n=this.boundingClientRect,o=n.width*n.height,a=this.intersectionRect,c=a.width*a.height;o?this.intersectionRatio=Number((c/o).toFixed(4)):this.intersectionRatio=this.isIntersecting?1:0}function l(t,n){var o=n||{};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(a){return a.value+a.unit}).join(" "),this._monitoringDocuments=[],this._monitoringUnsubscribes=[]}l.prototype.THROTTLE_TIMEOUT=100,l.prototype.POLL_INTERVAL=null,l.prototype.USE_MUTATION_OBSERVER=!0,l._setupCrossOriginUpdater=function(){return f||(f=function(t,n){!t||!n?g=w():g=x(t,n),s.forEach(function(o){o._checkForIntersections()})}),f},l._resetCrossOriginUpdater=function(){f=null,g=null},l.prototype.observe=function(t){var n=this._observationTargets.some(function(o){return o.element==t});if(!n){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()}},l.prototype.unobserve=function(t){this._observationTargets=this._observationTargets.filter(function(n){return n.element!=t}),this._unmonitorIntersections(t.ownerDocument),this._observationTargets.length==0&&this._unregisterInstance()},l.prototype.disconnect=function(){this._observationTargets=[],this._unmonitorAllIntersections(),this._unregisterInstance()},l.prototype.takeRecords=function(){var t=this._queuedEntries.slice();return this._queuedEntries=[],t},l.prototype._initThresholds=function(t){var n=t||[0];return Array.isArray(n)||(n=[n]),n.sort().filter(function(o,a,c){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!==c[a-1]})},l.prototype._parseRootMargin=function(t){var n=t||"0px",o=n.split(/\s+/).map(function(a){var c=/^(-?\d*\.?\d+)(px|%)$/.exec(a);if(!c)throw new Error("rootMargin must be specified in pixels or percent");return{value:parseFloat(c[1]),unit:c[2]}});return o[1]=o[1]||o[0],o[2]=o[2]||o[0],o[3]=o[3]||o[1],o},l.prototype._monitorIntersections=function(t){var n=t.defaultView;if(!!n&&this._monitoringDocuments.indexOf(t)==-1){var o=this._checkForIntersections,a=null,c=null;this.POLL_INTERVAL?a=n.setInterval(o,this.POLL_INTERVAL):(u(n,"resize",o,!0),u(t,"scroll",o,!0),this.USE_MUTATION_OBSERVER&&"MutationObserver"in n&&(c=new n.MutationObserver(o),c.observe(t,{attributes:!0,childList:!0,characterData:!0,subtree:!0}))),this._monitoringDocuments.push(t),this._monitoringUnsubscribes.push(function(){var O=t.defaultView;O&&(a&&O.clearInterval(a),p(O,"resize",o,!0)),p(t,"scroll",o,!0),c&&c.disconnect()});var E=this.root&&(this.root.ownerDocument||this.root)||r;if(t!=E){var y=e(t);y&&this._monitorIntersections(y.ownerDocument)}}},l.prototype._unmonitorIntersections=function(t){var n=this._monitoringDocuments.indexOf(t);if(n!=-1){var o=this.root&&(this.root.ownerDocument||this.root)||r,a=this._observationTargets.some(function(y){var O=y.element.ownerDocument;if(O==t)return!0;for(;O&&O!=o;){var R=e(O);if(O=R&&R.ownerDocument,O==t)return!0}return!1});if(!a){var c=this._monitoringUnsubscribes[n];if(this._monitoringDocuments.splice(n,1),this._monitoringUnsubscribes.splice(n,1),c(),t!=o){var E=e(t);E&&this._unmonitorIntersections(E.ownerDocument)}}}},l.prototype._unmonitorAllIntersections=function(){var t=this._monitoringUnsubscribes.slice(0);this._monitoringDocuments.length=0,this._monitoringUnsubscribes.length=0;for(var n=0;n<t.length;n++)t[n]()},l.prototype._checkForIntersections=function(){if(!(!this.root&&f&&!g)){var t=this._rootIsInDom(),n=t?this._getRootRect():w();this._observationTargets.forEach(function(o){var a=o.element,c=T(a),E=this._rootContainsTarget(a),y=o.entry,O=t&&E&&this._computeTargetAndRootIntersection(a,c,n),R=null;this._rootContainsTarget(a)?(!f||this.root)&&(R=n):R=w();var M=o.entry=new b({time:_(),target:a,boundingClientRect:c,rootBounds:R,intersectionRect:O});y?t&&E?this._hasCrossedThreshold(y,M)&&this._queuedEntries.push(M):y&&y.isIntersecting&&this._queuedEntries.push(M):this._queuedEntries.push(M)},this),this._queuedEntries.length&&this._callback(this.takeRecords(),this)}},l.prototype._computeTargetAndRootIntersection=function(t,n,o){if(window.getComputedStyle(t).display!="none"){for(var a=n,c=I(t),E=!1;!E&&c;){var y=null,O=c.nodeType==1?window.getComputedStyle(c):{};if(O.display=="none")return null;if(c==this.root||c.nodeType==9)if(E=!0,c==this.root||c==r)f&&!this.root?!g||g.width==0&&g.height==0?(c=null,y=null,a=null):y=g:y=o;else{var R=I(c),M=R&&T(R),C=R&&this._computeTargetAndRootIntersection(R,M,o);M&&C?(c=R,y=x(M,C)):(c=null,a=null)}else{var S=c.ownerDocument;c!=S.body&&c!=S.documentElement&&O.overflow!="visible"&&(y=T(c))}if(y&&(a=v(y,a)),!a)break;c=c&&I(c)}return a}},l.prototype._getRootRect=function(){var t;if(this.root&&!L(this.root))t=T(this.root);else{var n=L(this.root)?this.root:r,o=n.documentElement,a=n.body;t={top:0,left:0,right:o.clientWidth||a.clientWidth,width:o.clientWidth||a.clientWidth,bottom:o.clientHeight||a.clientHeight,height:o.clientHeight||a.clientHeight}}return this._expandRectByRootMargin(t)},l.prototype._expandRectByRootMargin=function(t){var n=this._rootMarginValues.map(function(a,c){return a.unit=="px"?a.value:a.value*(c%2?t.width:t.height)/100}),o={top:t.top-n[0],right:t.right+n[1],bottom:t.bottom+n[2],left:t.left-n[3]};return o.width=o.right-o.left,o.height=o.bottom-o.top,o},l.prototype._hasCrossedThreshold=function(t,n){var o=t&&t.isIntersecting?t.intersectionRatio||0:-1,a=n.isIntersecting?n.intersectionRatio||0:-1;if(o!==a)for(var c=0;c<this.thresholds.length;c++){var E=this.thresholds[c];if(E==o||E==a||E<o!=E<a)return!0}},l.prototype._rootIsInDom=function(){return!this.root||h(r,this.root)},l.prototype._rootContainsTarget=function(t){var n=this.root&&(this.root.ownerDocument||this.root)||r;return h(n,t)&&(!this.root||n==t.ownerDocument)},l.prototype._registerInstance=function(){s.indexOf(this)<0&&s.push(this)},l.prototype._unregisterInstance=function(){var t=s.indexOf(this);t!=-1&&s.splice(t,1)};function _(){return window.performance&&performance.now&&performance.now()}function d(t,n){var o=null;return function(){o||(o=setTimeout(function(){t(),o=null},n))}}function u(t,n,o,a){typeof t.addEventListener=="function"?t.addEventListener(n,o,a||!1):typeof t.attachEvent=="function"&&t.attachEvent("on"+n,o)}function p(t,n,o,a){typeof t.removeEventListener=="function"?t.removeEventListener(n,o,a||!1):typeof t.detatchEvent=="function"&&t.detatchEvent("on"+n,o)}function v(t,n){var o=Math.max(t.top,n.top),a=Math.min(t.bottom,n.bottom),c=Math.max(t.left,n.left),E=Math.min(t.right,n.right),y=E-c,O=a-o;return y>=0&&O>=0&&{top:o,bottom:a,left:c,right:E,width:y,height:O}||null}function T(t){var n;try{n=t.getBoundingClientRect()}catch{}return n?(n.width&&n.height||(n={top:n.top,right:n.right,bottom:n.bottom,left:n.left,width:n.right-n.left,height:n.bottom-n.top}),n):w()}function w(){return{top:0,bottom:0,left:0,right:0,width:0,height:0}}function m(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 x(t,n){var o=n.top-t.top,a=n.left-t.left;return{top:o,left:a,height:n.height,width:n.width,bottom:o+n.height,right:a+n.width}}function h(t,n){for(var o=n;o;){if(o==t)return!0;o=I(o)}return!1}function I(t){var n=t.parentNode;return t.nodeType==9&&t!=r?e(t):(n&&n.assignedSlot&&(n=n.assignedSlot.parentNode),n&&n.nodeType==11&&n.host?n.host:n)}function L(t){return t&&t.nodeType===9}window.IntersectionObserver=l,window.IntersectionObserverEntry=b})();var H={exports:{}};(function(e){var r=Object.prototype.hasOwnProperty,s="~";function f(){}Object.create&&(f.prototype=Object.create(null),new f().__proto__||(s=!1));function g(d,u,p){this.fn=d,this.context=u,this.once=p||!1}function b(d,u,p,v,T){if(typeof p!="function")throw new TypeError("The listener must be a function");var w=new g(p,v||d,T),m=s?s+u:u;return d._events[m]?d._events[m].fn?d._events[m]=[d._events[m],w]:d._events[m].push(w):(d._events[m]=w,d._eventsCount++),d}function l(d,u){--d._eventsCount===0?d._events=new f:delete d._events[u]}function _(){this._events=new f,this._eventsCount=0}_.prototype.eventNames=function(){var u=[],p,v;if(this._eventsCount===0)return u;for(v in p=this._events)r.call(p,v)&&u.push(s?v.slice(1):v);return Object.getOwnPropertySymbols?u.concat(Object.getOwnPropertySymbols(p)):u},_.prototype.listeners=function(u){var p=s?s+u:u,v=this._events[p];if(!v)return[];if(v.fn)return[v.fn];for(var T=0,w=v.length,m=new Array(w);T<w;T++)m[T]=v[T].fn;return m},_.prototype.listenerCount=function(u){var p=s?s+u:u,v=this._events[p];return v?v.fn?1:v.length:0},_.prototype.emit=function(u,p,v,T,w,m){var x=s?s+u:u;if(!this._events[x])return!1;var h=this._events[x],I=arguments.length,L,t;if(h.fn){switch(h.once&&this.removeListener(u,h.fn,void 0,!0),I){case 1:return h.fn.call(h.context),!0;case 2:return h.fn.call(h.context,p),!0;case 3:return h.fn.call(h.context,p,v),!0;case 4:return h.fn.call(h.context,p,v,T),!0;case 5:return h.fn.call(h.context,p,v,T,w),!0;case 6:return h.fn.call(h.context,p,v,T,w,m),!0}for(t=1,L=new Array(I-1);t<I;t++)L[t-1]=arguments[t];h.fn.apply(h.context,L)}else{var n=h.length,o;for(t=0;t<n;t++)switch(h[t].once&&this.removeListener(u,h[t].fn,void 0,!0),I){case 1:h[t].fn.call(h[t].context);break;case 2:h[t].fn.call(h[t].context,p);break;case 3:h[t].fn.call(h[t].context,p,v);break;case 4:h[t].fn.call(h[t].context,p,v,T);break;default:if(!L)for(o=1,L=new Array(I-1);o<I;o++)L[o-1]=arguments[o];h[t].fn.apply(h[t].context,L)}}return!0},_.prototype.on=function(u,p,v){return b(this,u,p,v,!1)},_.prototype.once=function(u,p,v){return b(this,u,p,v,!0)},_.prototype.removeListener=function(u,p,v,T){var w=s?s+u:u;if(!this._events[w])return this;if(!p)return l(this,w),this;var m=this._events[w];if(m.fn)m.fn===p&&(!T||m.once)&&(!v||m.context===v)&&l(this,w);else{for(var x=0,h=[],I=m.length;x<I;x++)(m[x].fn!==p||T&&!m[x].once||v&&m[x].context!==v)&&h.push(m[x]);h.length?this._events[w]=h.length===1?h[0]:h:l(this,w)}return this},_.prototype.removeAllListeners=function(u){var p;return u?(p=s?s+u:u,this._events[p]&&l(this,p)):(this._events=new f,this._eventsCount=0),this},_.prototype.off=_.prototype.removeListener,_.prototype.addListener=_.prototype.on,_.prefixed=s,_.EventEmitter=_,e.exports=_})(H);var G=Object.defineProperty,z=Object.getOwnPropertyDescriptor,W=(e,r,s,f)=>{for(var g=f>1?void 0:f?z(r,s):r,b=e.length-1,l;b>=0;b--)(l=e[b])&&(g=(f?l(r,s,g):l(g))||g);return f&&g&&G(r,s,g),g};const B=60;var P;const i=(P=class{static on(e,r){i.events.on(e,r)}static off(e,r){i.events.off(e,r)}static once(e,r){i.events.once(e,r)}static checkCollisions(e,r){const s=r||Array.from(i.elements.keys()),f=e.getBoundingClientRect(),g=[];for(const b of s)if(b!==e){const l=b.getBoundingClientRect();l.left<=f.right&&l.right>=f.left&&l.top<=f.bottom&&l.bottom>=f.top&&g.push(b)}g.length&&i.onElementIntersection(e,g)}static isPositioned(e){return i.elements.has(e)}static getPositioningOptions(e){return i.elements.has(e)?i.elements.get(e):null}static position(e,r={}){const s={...N,...r};let f=e;for(;f!==document.body;)if(f=f.parentElement,f.classList.contains("sps-focused-task")){s.scrollParent=f,i.registeredScrollParents.has(f)||(i.registeredScrollParents.add(f),f.addEventListener("scroll",i.update));break}if(e.style.visibility="hidden",i.elements.size===0&&(window.addEventListener("resize",i.update),window.addEventListener("scroll",i.update)),!s.relativeTo)throw new Error("You must provide an element for the relativeTo option to position an element.");i.elements.set(e,s),F.onNextTick(()=>{i.fixElementPosition(e),i.viewportObserver.observe(e),e.style.visibility="",i.checkCollisions(e)})}static release(e){if(i.elements.has(e)){i.clearStyles(e);const r=i.elements.get(e);r.scrollParent&&(r.scrollParent.removeEventListener("scroll",i.update),i.registeredScrollParents.delete(r.scrollParent)),i.elements.delete(e),i.elements.size===0&&(window.removeEventListener("resize",i.update),window.removeEventListener("scroll",i.update)),i.viewportObserver.unobserve(e)}}static releaseAll(){for(const e of i.elements.keys())i.release(e)}static refresh(e){i.elements.has(e)&&(i.clearStyles(e),i.fixElementPosition(e),i.checkCollisions(e))}static refreshAll(){for(const e of i.elements.keys())i.refresh(e)}static reposition(e,r){if(i.elements.has(e)){const s=i.elements.get(e);i.elements.set(e,Object.assign(s,r)),i.refresh(e)}}static onViewportIntersection(e){for(const r of e){const s=Object.keys(IntersectionObserverEntry.prototype).reduce((f,g)=>({...f,[g]:r[g]}),{});s.rootBounds=s.rootBounds||i.getRootBounds(),i.events.emit("viewportIntersection",Object.freeze(s))}}static onElementIntersection(e,r){i.events.emit("elementIntersection",{target:e,intersectingWith:r})}static getRootBounds(){const e=Math.max(document.documentElement.clientWidth,window.innerWidth||0),r=Math.max(document.documentElement.clientHeight,window.innerHeight||0);return{x:0,y:B,left:0,top:B,right:e,bottom:r,height:r-B,width:e}}static clearStyles(e){Object.assign(e.style,{position:"",width:"",top:"",left:"",right:"",bottom:"",visibility:"",zIndex:""})}static fixElementPosition(e,r){if(!this.elements.has(e))return;const s=r||this.elements.get(e),f=this.getRootBounds(),g=e.getBoundingClientRect(),b=s.relativeTo.getBoundingClientRect(),{width:l}=s.useRelativeTargetWidth?b:g;Object.assign(e.style,{minWidth:`${l}px`,position:"fixed",zIndex:s.zIndex||""});let _,d;const u=s.position.split(" "),p=s.offsets[0]||0,v=s.offsets[1]||0;switch(_=0,d=0,u[0]){case"top":_=b.top-g.height-p;break;case"left":d=b.left-l-p;break;case"right":d=b.right+p;break;case"bottom":_=b.bottom+p;break;default:throw new Error(`${s.position} is not a valid position`)}switch(u[1]){case"left":d=b.left-v;break;case"top":_=b.top-v;break;case"middle":u[0]==="top"||u[0]==="bottom"?d=b.left+b.width/2-l/2+v:(u[0]==="left"||u[0]==="right")&&(_=b.top+b.height/2-g.height/2+v);break;case"bottom":_=b.bottom-g.height+v;break;case"right":d=b.right-l+v;break;default:throw new Error(`${s.position} is not a valid position`)}const T=_+g.height,w=d+g.width,m=`${Math.round(_)}px`,x=`${Math.round(f.bottom-T)}px`,h=`${Math.round(d)}px`,I=`${Math.round(f.right-w)}px`;switch(s.anchor){case D.TOP_LEFT:Object.assign(e.style,{top:m,bottom:"auto",left:h,right:"auto"});break;case D.TOP_RIGHT:Object.assign(e.style,{top:m,bottom:"auto",left:"auto",right:I});break;case D.BOTTOM_LEFT:Object.assign(e.style,{top:"auto",bottom:x,left:h,right:"auto"});break;case D.BOTTOM_RIGHT:Object.assign(e.style,{top:"auto",bottom:x,left:"auto",right:I});break}}static update(e){const r=i.elements.entries(),s=[];for(const[f,g]of r)(!e||e.target===document||e.target===g.scrollParent||e.target===window)&&(i.fixElementPosition(f,g),i.checkCollisions(f,s),s.push(f))}on(e,r){i.on(e,r)}off(e,r){i.off(e,r)}once(e,r){i.once(e,r)}isPositioned(e){return i.isPositioned(e)}getPositioningOptions(e){return i.getPositioningOptions(e)}position(e,r={}){i.position(e,r)}release(e){i.release(e)}releaseAll(){i.releaseAll()}refresh(e){i.refresh(e)}refreshAll(){i.refreshAll()}reposition(e,r){i.reposition(e,r)}},k(P,"elements",new Map),k(P,"registeredScrollParents",new Set),k(P,"events",new H.exports.EventEmitter),k(P,"viewportObserver",new IntersectionObserver(i.onViewportIntersection,{rootMargin:`-${B}px 0px 0px`,threshold:1})),P);let U=i;W([F.lockedToAnimationFrames],U,"update",1);exports.DEFAULT_POSITIONING_OPTIONS=N;exports.Position=A;exports.PositionAnchor=D;exports.PositioningService=U;
|
|
File without changes
|