2 lines
4.6 KiB
JavaScript
2 lines
4.6 KiB
JavaScript
function ee(e){return typeof e=="object"&&e!=null&&e.nodeType===1}function te(e,t){return(!t||e!=="hidden")&&e!=="visible"&&e!=="clip"}function z(e,t){if(e.clientHeight<e.scrollHeight||e.clientWidth<e.scrollWidth){var r=getComputedStyle(e,null);return te(r.overflowY,t)||te(r.overflowX,t)||function(o){var n=function(i){if(!i.ownerDocument||!i.ownerDocument.defaultView)return null;try{return i.ownerDocument.defaultView.frameElement}catch{return null}}(o);return!!n&&(n.clientHeight<o.scrollHeight||n.clientWidth<o.scrollWidth)}(e)}return!1}function D(e,t,r,o,n,i,s,p){return i<e&&s>t||i>e&&s<t?0:i<=e&&p<=r||s>=t&&p>=r?i-e-o:s>t&&p<r||i<e&&p>r?s-t+n:0}var re=function(e,t){var r=window,o=t.scrollMode,n=t.block,i=t.inline,s=t.boundary,p=t.skipOverflowHiddenElements,le=typeof s=="function"?s:function(se){return se!==s};if(!ee(e))throw new TypeError("Invalid target");for(var F,K,C=document.scrollingElement||document.documentElement,_=[],a=e;ee(a)&&le(a);){if((a=(K=(F=a).parentElement)==null?F.getRootNode().host||null:K)===C){_.push(a);break}a!=null&&a===document.body&&z(a)&&!z(document.documentElement)||a!=null&&z(a,p)&&_.push(a)}for(var v=r.visualViewport?r.visualViewport.width:innerWidth,w=r.visualViewport?r.visualViewport.height:innerHeight,b=window.scrollX||pageXOffset,y=window.scrollY||pageYOffset,m=e.getBoundingClientRect(),O=m.height,x=m.width,E=m.top,X=m.right,Y=m.bottom,H=m.left,c=n==="start"||n==="nearest"?E:n==="end"?Y:E+O/2,f=i==="center"?H+x/2:i==="end"?X:H,A=[],N=0;N<_.length;N++){var l=_[N],g=l.getBoundingClientRect(),W=g.height,P=g.width,M=g.top,Z=g.right,$=g.bottom,j=g.left;if(o==="if-needed"&&E>=0&&H>=0&&Y<=w&&X<=v&&E>=M&&Y<=$&&H>=j&&X<=Z)return A;var L=getComputedStyle(l),k=parseInt(L.borderLeftWidth,10),V=parseInt(L.borderTopWidth,10),I=parseInt(L.borderRightWidth,10),S=parseInt(L.borderBottomWidth,10),u=0,d=0,T="offsetWidth"in l?l.offsetWidth-l.clientWidth-k-I:0,q="offsetHeight"in l?l.offsetHeight-l.clientHeight-V-S:0,G="offsetWidth"in l?l.offsetWidth===0?0:P/l.offsetWidth:0,J="offsetHeight"in l?l.offsetHeight===0?0:W/l.offsetHeight:0;if(C===l)u=n==="start"?c:n==="end"?c-w:n==="nearest"?D(y,y+w,w,V,S,y+c,y+c+O,O):c-w/2,d=i==="start"?f:i==="center"?f-v/2:i==="end"?f-v:D(b,b+v,v,k,I,b+f,b+f+x,x),u=Math.max(0,u+y),d=Math.max(0,d+b);else{u=n==="start"?c-M-V:n==="end"?c-$+S+q:n==="nearest"?D(M,$,W,V,S+q,c,c+O,O):c-(M+W/2)+q/2,d=i==="start"?f-j-k:i==="center"?f-(j+P/2)+T/2:i==="end"?f-Z+I+T:D(j,Z,P,k,I+T,f,f+x,x);var R=l.scrollLeft,B=l.scrollTop;c+=B-(u=Math.max(0,Math.min(B+u/J,l.scrollHeight-W/J+q))),f+=R-(d=Math.max(0,Math.min(R+d/G,l.scrollWidth-P/G+T)))}A.push({el:l,top:u,left:d})}return A},ae=Object.defineProperty,ce=Object.defineProperties,fe=Object.getOwnPropertyDescriptors,ne=Object.getOwnPropertySymbols,ue=Object.prototype.hasOwnProperty,de=Object.prototype.propertyIsEnumerable,ie=(e,t,r)=>t in e?ae(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,he=(e,t)=>{for(var r in t||(t={}))ue.call(t,r)&&ie(e,r,t[r]);if(ne)for(var r of ne(t))de.call(t,r)&&ie(e,r,t[r]);return e},pe=(e,t)=>ce(e,fe(t));const we=["xxl","xl","lg","md","sm","xs"],Q={xs:"(max-width: 575px)",sm:"(min-width: 576px)",md:"(min-width: 768px)",lg:"(min-width: 992px)",xl:"(min-width: 1200px)",xxl:"(min-width: 1600px)"};let h=[],me=-1,U={};const be={matchHandlers:{},dispatch(e,t){return U=e,h.length<1?!1:(h.forEach(r=>{r.func(U,t)}),!0)},subscribe(e){h.length===0&&this.register();const t=(++me).toString();return h.push({token:t,func:e}),e(U,null),t},unsubscribe(e){h=h.filter(t=>t.token!==e),h.length===0&&this.unregister()},unregister(){Object.keys(Q).forEach(e=>{const t=Q[e];if(!t)return;const r=this.matchHandlers[t];r&&r.mql&&r.listener&&(r.mql.removeEventListener?r.mql.removeEventListener("change",r.listener):r.mql.removeListener(r.listener))})},register(){Object.keys(Q).forEach(e=>{const t=Q[e];if(!t)return;const r=({matches:n})=>{this.dispatch(pe(he({},U),{[e]:n}),e)},o=window.matchMedia(t);o.addEventListener?o.addEventListener("change",r):o.addListener(r),this.matchHandlers[t]={mql:o,listener:r},r(o)})}};function oe(e){return e===Object(e)&&Object.keys(e).length!==0}function ge(e,t){t===void 0&&(t="auto");var r="scrollBehavior"in document.body.style;e.forEach(function(o){var n=o.el,i=o.top,s=o.left;n.scroll&&r?n.scroll({top:i,left:s,behavior:t}):(n.scrollTop=i,n.scrollLeft=s)})}function ve(e){return e===!1?{block:"end",inline:"nearest"}:oe(e)?e:{block:"start",inline:"nearest"}}function ye(e,t){var r=e.isConnected||e.ownerDocument.documentElement.contains(e);if(oe(t)&&typeof t.behavior=="function")return t.behavior(r?re(e,t):[]);if(r){var o=ve(t);return ge(re(e,o),o.behavior)}}export{we as a,be as r,ye as s};
|