mirror of
https://github.com/tenrok/OverlayScrollbars.git
synced 2026-06-19 18:10:35 +03:00
11 lines
27 KiB
JavaScript
11 lines
27 KiB
JavaScript
/*!
|
|
* OverlayScrollbars
|
|
* Version: 2.0.0-beta.0
|
|
*
|
|
* Copyright (c) Rene Haas | KingSora.
|
|
* https://github.com/KingSora
|
|
*
|
|
* Released under the MIT license.
|
|
*/
|
|
|
|
function t(e,n){if(w(e))for(let t=0;t<e.length&&!1!==n(e[t],t,e);t++);else e&&t(Object.keys(e),(t=>n(e[t],t,e)));return e}function e(e,n){const o=d(n);if(p(n)||o){let t=o?"":{};if(e){const r=window.getComputedStyle(e,null);t=o?yt(e,r,n):n.reduce(((t,n)=>(t[n]=yt(e,r,n),t)),t)}return t}e&&t(L(n),(t=>mt(e,t,n[t])))}const n=(t,e)=>{const{o:n,u:o,_:r}=t;let i,s=n;const l=(t,e)=>{const n=s,l=t,c=e||(o?!o(n,l):n!==l);return(c||r)&&(s=l,i=n),[s,c,i]};return[e?t=>l(e(s,i),t):l,t=>[s,!!t,i]]},o=Node.ELEMENT_NODE,{toString:r,hasOwnProperty:i}=Object.prototype,s=t=>void 0===t,l=t=>null===t,c=t=>s(t)||l(t)?`${t}`:r.call(t).replace(/^\[object (.+)\]$/,"$1").toLowerCase(),a=t=>"number"==typeof t,d=t=>"string"==typeof t,u=t=>"boolean"==typeof t,h=t=>"function"==typeof t,p=t=>Array.isArray(t),f=t=>"object"==typeof t&&!p(t)&&!l(t),w=t=>{const e=!!t&&t.length,n=a(e)&&e>-1&&e%1==0;return!(!(p(t)||!h(t)&&n)||e>0&&f(t)&&!(e-1 in t))},g=t=>{if(!t||!f(t)||"object"!==c(t))return!1;let e;const n="constructor",o=t[n],r=o&&o.prototype,l=i.call(t,n),a=r&&i.call(r,"isPrototypeOf");if(o&&!l&&!a)return!1;for(e in t);return s(e)||i.call(t,e)},b=t=>{const e=HTMLElement;return!!t&&(e?t instanceof e:t.nodeType===o)},v=t=>{const e=Element;return!!t&&(e?t instanceof e:t.nodeType===o)},y=(t,e,n)=>t.indexOf(e,n),m=(t,e,n)=>(n||d(e)||!w(e)?t.push(e):Array.prototype.push.apply(t,e),t),x=e=>{const n=Array.from,o=[];return n&&e?n(e):(e instanceof Set?e.forEach((t=>{m(o,t)})):t(e,(t=>{m(o,t)})),o)},$=t=>!!t&&0===t.length,O=(e,n,o)=>{t(e,(t=>t&&t.apply(void 0,n||[]))),!o&&(e.length=0)},S=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),L=t=>t?Object.keys(t):[],C=(e,n,o,r,i,s,c)=>{const a=[n,o,r,i,s,c];return"object"==typeof e&&!l(e)||h(e)||(e={}),t(a,(n=>{t(L(n),(t=>{const o=n[t];if(e===o)return!0;const r=p(o);if(o&&(g(o)||r)){const n=e[t];let i=n;r&&!p(n)?i=[]:r||g(n)||(i={}),e[t]=C(i,o)}else e[t]=o}))})),e},E=t=>{for(const e in t)return!1;return!0},P=(t,e,n,o)=>{if(s(o))return n?n[t]:e;n&&(d(o)||a(o))&&(n[t]=o)},A=(t,e,n)=>{if(s(n))return t?t.getAttribute(e):null;t&&t.setAttribute(e,n)},M=(t,e,n,o)=>{if(n){const r=A(t,e)||"",i=new Set(r.split(" "));i[o?"add":"delete"](n),A(t,e,x(i).join(" ").trim())}},R=(t,e)=>{t&&t.removeAttribute(e)},z=(t,e)=>P("scrollLeft",0,t,e),D=(t,e)=>P("scrollTop",0,t,e),T=Element.prototype,k=(t,e)=>{const n=[],o=e?v(e)?e:null:document;return o?m(n,o.querySelectorAll(t)):n},B=(t,e)=>!!v(t)&&(T.matches||T.msMatchesSelector).call(t,e),H=t=>t?x(t.childNodes):[],I=t=>t?t.parentElement:null,X=(t,e)=>{if(v(t)){const n=T.closest;if(n)return n.call(t,e);do{if(B(t,e))return t;t=I(t)}while(t)}return null},Y=(e,n,o)=>{if(o&&e){let r,i=n;w(o)?(r=document.createDocumentFragment(),t(o,(t=>{t===i&&(i=t.previousSibling),r.appendChild(t)}))):r=o,n&&(i?i!==n&&(i=i.nextSibling):i=e.firstChild),e.insertBefore(r,i||null)}},V=(t,e)=>{Y(t,null,e)},F=(t,e)=>{Y(I(t),t&&t.nextSibling,e)},j=e=>{if(w(e))t(x(e),(t=>j(t)));else if(e){const t=I(e);t&&t.removeChild(e)}},_=t=>{const e=document.createElement("div");return t&&A(e,"class",t),e},N=e=>{const n=_();return n.innerHTML=e.trim(),t(H(n),(t=>j(t)))},W=t=>t.charAt(0).toUpperCase()+t.slice(1),Z=["-webkit-","-moz-","-o-","-ms-"],G=["WebKit","Moz","O","MS","webkit","moz","o","ms"],K={},q={},J=e=>{let n=q[e];if(S(q,e))return n;const o=W(e),r=_().style;return t(Z,(t=>{const i=t.replace(/-/g,""),s=[e,t+e,i+o,W(i)+o];return!(n=s.find((t=>void 0!==r[t])))})),q[e]=n||""},U=e=>{let n=K[e]||window[e];return S(K,e)||(t(G,(t=>(n=n||window[t+W(e)],!n))),K[e]=n),n},Q=U("MutationObserver"),tt=U("IntersectionObserver"),et=U("ResizeObserver"),nt=U("cancelAnimationFrame"),ot=U("requestAnimationFrame"),rt=window.setTimeout,it=window.clearTimeout,st=/[^\x20\t\r\n\f]+/g,lt=(t,e,n)=>{const o=t&&t.classList;let r,i=0,s=!1;if(o&&e&&d(e)){const t=e.match(st)||[];for(s=t.length>0;r=t[i++];)s=!!n(o,r)&&s}return s},ct=(t,e)=>{lt(t,e,((t,e)=>t.remove(e)))},at=(t,e)=>(lt(t,e,((t,e)=>t.add(e))),ct.bind(0,t,e)),dt=(e,n,o,r)=>{if(e&&n){let i=!0;return t(o,(t=>{(r?r(e[t]):e[t])!==(r?r(n[t]):n[t])&&(i=!1)})),i}return!1},ut=(t,e)=>dt(t,e,["w","h"]),ht=(t,e)=>dt(t,e,["x","y"]),pt=(t,e)=>dt(t,e,["t","r","b","l"]),ft=(t,e,n)=>dt(t,e,["width","height"],n&&(t=>Math.round(t))),wt=()=>{},gt=(t,e)=>{let n,o,r,i=wt;const{g:s,v:l,p:c}=e||{},d=function(e){i(),it(n),n=o=void 0,i=wt,t.apply(this,e)},u=t=>c&&o?c(o,t):t,p=()=>{i!==wt&&d(u(r)||r)},f=function(){const t=x(arguments),e=h(s)?s():s,c=a(e)&&e>=0;if(c){const s=h(l)?l():l,c=a(s)&&s>=0,f=e>0?rt:ot,w=e>0?it:nt,g=u(t)||t,b=d.bind(0,g);i();const v=f(b,e);i=()=>w(v),c&&!n&&(n=rt(p,s)),o=r=g}else d(t)};return f.m=p,f},bt={opacity:1,zindex:1},vt=(t,e)=>{const n=e?parseFloat(t):parseInt(t,10);return n==n?n:0},yt=(t,e,n)=>null!=e?e[n]||e.getPropertyValue(n):t.style[n],mt=(t,e,n)=>{try{const{style:o}=t;s(o[e])?o.setProperty(e,n):o[e]=((t,e)=>!bt[t.toLowerCase()]&&a(e)?`${e}px`:e)(e,n)}catch(T){}},xt=t=>"rtl"===e(t,"direction"),$t=(t,n,o)=>{const r=n?`${n}-`:"",i=o?`-${o}`:"",s=`${r}top${i}`,l=`${r}right${i}`,c=`${r}bottom${i}`,a=`${r}left${i}`,d=e(t,[s,l,c,a]);return{t:vt(d[s]),r:vt(d[l]),b:vt(d[c]),l:vt(d[a])}},{round:Ot}=Math,St={w:0,h:0},Lt=t=>t?{w:t.offsetWidth,h:t.offsetHeight}:St,Ct=t=>t?{w:t.clientWidth,h:t.clientHeight}:St,Et=t=>t?{w:t.scrollWidth,h:t.scrollHeight}:St,Pt=t=>{const n=parseFloat(e(t,"height"))||0,o=parseFloat(e(t,"width"))||0;return{w:o-Ot(o),h:n-Ot(n)}},At=t=>t.getBoundingClientRect();let Mt;const Rt=t=>t.split(" "),zt=(e,n,o,r)=>{t(Rt(n),(t=>{e.removeEventListener(t,o,r)}))},Dt=(e,n,o,r)=>{var i;const l=(()=>{if(s(Mt)){Mt=!1;try{window.addEventListener("test",null,Object.defineProperty({},"passive",{get(){Mt=!0}}))}catch(e){}}return Mt})(),c=null!=(i=l&&r&&r.S)?i:l,a=r&&r.$||!1,d=r&&r.C||!1,u=[],h=l?{passive:c,capture:a}:a;return t(Rt(n),(t=>{const n=d?r=>{e.removeEventListener(t,n,a),o&&o(r)}:o;m(u,zt.bind(null,e,t,n,a)),e.addEventListener(t,n,h)})),O.bind(0,u)},Tt=t=>t.stopPropagation(),kt={x:0,y:0},Bt=t=>{const e=t?At(t):0;return e?{x:e.left+window.pageYOffset,y:e.top+window.pageXOffset}:kt},Ht=(e,n)=>{t(p(n)?n:[n],e)},It=e=>{const n=new Map,o=(t,e)=>{if(t){const o=n.get(t);Ht((t=>{o&&o[t?"delete":"clear"](t)}),e)}else n.forEach((t=>{t.clear()})),n.clear()},r=(t,e)=>{const r=n.get(t)||new Set;return n.set(t,r),Ht((t=>{t&&r.add(t)}),e),o.bind(0,t,e)};return t(L(e),(t=>{r(t,e[t])})),[r,o,(e,o)=>{const r=n.get(e);t(x(r),(t=>{o&&!$(o)?t.apply(0,o):t()}))}]},Xt=t=>JSON.stringify(t,((t,e)=>{if(h(e))throw new Error;return e})),Yt={paddingAbsolute:!1,showNativeOverlaidScrollbars:!1,updating:{elementEvents:[["img","load"]],debounce:[0,33],attributes:null,ignoreMutation:null},overflow:{x:"scroll",y:"scroll"},scrollbars:{theme:"os-theme-dark",visibility:"auto",autoHide:"never",autoHideDelay:1300,dragScroll:!0,clickScroll:!1,pointers:["mouse","touch","pen"]}},Vt=(e,n)=>{const o={};return t(L(n).concat(L(e)),(t=>{const r=e[t],i=n[t];if(f(r)&&f(i))C(o[t]={},Vt(r,i));else if(S(n,t)&&i!==r){let e=!0;if(p(r)||p(i))try{Xt(r)===Xt(i)&&(e=!1)}catch(K){}e&&(o[t]=i)}})),o},Ft="os-environment",jt=`${Ft}-flexbox-glue`,_t=`${jt}-max`,Nt="data-overlayscrollbars",Wt=`${Nt}-overflow-x`,Zt=`${Nt}-overflow-y`,Gt="overflowVisible",Kt="scrollbarHidden",qt="updating",Jt="os-padding",Ut="os-viewport",Qt=`${Ut}-arrange`,te="os-content",ee=`${Ut}-scrollbar-hidden`,ne=`os-overflow-visible`,oe="os-size-observer",re=`${oe}-appear`,ie=`${oe}-listener`,se=`${ie}-scroll`,le=`${ie}-item`,ce=`${le}-final`,ae="os-trinsic-observer",de="os-scrollbar",ue=`${de}-rtl`,he=`${de}-horizontal`,pe=`${de}-vertical`,fe=`${de}-track`,we=`${de}-handle`,ge=`${de}-visible`,be=`${de}-cornerless`,ve=`${de}-transitionless`,ye=`${de}-interaction`,me=`${de}-unusable`,xe=`${de}-auto-hidden`,$e=`${fe}-interactive`,Oe=`${we}-interactive`,Se={},Le=()=>Se,Ce="__osOptionsValidationPlugin",Ee=3333333,Pe="scroll",Ae="__osSizeObserverPlugin",Me={[Ae]:{O:(t,n,o)=>{const r=N(`<div class="${le}" dir="ltr"><div class="${le}"><div class="${ce}"></div></div><div class="${le}"><div class="${ce}" style="width: 200%; height: 200%"></div></div></div>`);V(t,r),at(t,se);const i=r[0],s=i.lastChild,l=i.firstChild,c=null==l?void 0:l.firstChild;let a,d=Lt(i),u=d,h=!1;const p=()=>{z(l,Ee),D(l,Ee),z(s,Ee),D(s,Ee)},f=t=>{a=0,h&&(d=u,n(!0===t))},w=t=>{u=Lt(i),h=!t||!ut(u,d),t?(Tt(t),h&&!a&&(nt(a),a=ot(f))):f(!1===t),p()},g=m([],[Dt(l,Pe,w),Dt(s,Pe,w)]);return e(c,{width:Ee,height:Ee}),ot(p),[o?w.bind(0,!1):p,g]}}};let Re=0;const{round:ze,abs:De}=Math,Te="__osScrollbarsHidingPlugin",ke={[Te]:{T:t=>{const{A:e,I:n,L:o}=t,r=!(o||e||!n.x&&!n.y)&&document.createElement("style");return r&&(A(r,"id",`${Qt}-${Re}`),Re++),r},H:(n,o,r,i,s,l,c)=>[(t,o,l,c)=>{if(n){const{P:n}=s(),{D:a,M:d}=t,{x:u,y:h}=d,{x:p,y:f}=a,w=n[c?"paddingRight":"paddingLeft"],g=n.paddingTop,b=o.w+l.w,v=o.h+l.h,y={w:f&&h?`${f+b-w}px`:"",h:p&&u?`${p+v-g}px`:""};if(i){const{sheet:t}=i;if(t){const{cssRules:e}=t;if(e){e.length||t.insertRule(`#${A(i,"id")} + .${Qt}::before {}`,0);const n=e[0].style;n.width=y.w,n.height=y.h}}}else e(r,{"--os-vaw":y.w,"--os-vah":y.h})}return n},(i,a,d)=>{if(n){const u=d||l(i),{P:h}=s(),{M:p}=u,{x:f,y:w}=p,g={},b=e=>t(e.split(" "),(t=>{g[t]=h[t]}));f&&b("marginBottom paddingTop paddingBottom"),w&&b("marginLeft marginRight paddingLeft paddingRight");const v=e(r,L(g));return ct(r,Qt),o||(g.height=""),e(r,g),[()=>{c(u,a,n,v),e(r,v),at(r,Qt)},u]}return[wt]}],R:()=>{let t={w:0,h:0},e=0;return(n,o,r)=>{const i={w:window.innerWidth,h:window.innerHeight},s={w:i.w-t.w,h:i.h-t.h};if(0===s.w&&0===s.h)return;const l=De(s.w),c=De(s.h),a={w:De(ze(i.w/(t.w/100))),h:De(ze(i.h/(t.h/100)))},d=(()=>{const t=window.screen.deviceXDPI||0,e=window.screen.logicalXDPI||1;return window.devicePixelRatio||t/e})(),u=l>2&&c>2,h=!((t,e)=>{const n=De(t),o=De(e);return!(n===o||n+1===o||n-1===o)})(a.w,a.h);if(u&&h&&d!==e&&d>0){const[t,e]=o();C(n.k,t),e&&r()}t=i,e=d}}}};let Be;const He=(t,e,n,o)=>{V(t,e);const r=Ct(e),i=Lt(e),s=Pt(n);return o&&j(e),{x:i.h-r.h+s.h,y:i.w-r.w+s.w}},Ie=(t,n)=>{const o="hidden";e(t,{overflowX:o,overflowY:o,direction:"rtl"}),z(t,0);const r=Bt(t),i=Bt(n);z(t,-999);const s=Bt(n);return{i:r.x===i.x,n:i.x!==s.x}},Xe=(t,e)=>{const n=at(t,jt),o=At(t),r=At(e),i=ft(r,o,!0),s=at(t,_t),l=At(t),c=At(e),a=ft(c,l,!0);return n(),s(),i&&a},Ye=()=>(Be||(Be=(()=>{const{body:t}=document,o=N(`<div class="${Ft}"><div></div></div>`)[0],r=o.firstChild,[i,,s]=It(),[l,c]=n({o:He(t,o,r),u:ht},He.bind(0,t,o,r,!0)),[a]=c(),d=(t=>{let n=!1;const o=at(t,ee);try{n="none"===e(t,J("scrollbar-width"))||"none"===window.getComputedStyle(t,"::-webkit-scrollbar").getPropertyValue("display")}catch(r){}return o(),n})(o),u={x:0===a.x,y:0===a.y},h={host:null,padding:!d,viewport:t=>d&&t===t.ownerDocument.body&&t,content:!1,scrollbarsSlot:!0,cancel:{nativeScrollbarsOverlaid:!0,body:null}},p=C({},Yt),f={k:a,I:u,A:d,L:"-1"===e(o,"zIndex"),B:Ie(o,r),V:Xe(o,r),j:t=>i("_",t),Y:C.bind(0,{},h),q(t){C(h,t)},F:C.bind(0,{},p),G(t){C(p,t)},N:C({},h),U:C({},p)};if(R(o,"style"),j(o),!(d||u.x&&u.y)){let t;window.addEventListener("resize",(()=>{const e=Le()[Te];t=t||e&&e.R(),t&&t(f,l,s.bind(0,"_"))}))}return f})()),Be),Ve=(t,e)=>h(t)?t.apply(0,e):t,Fe=(t,e,n,o)=>{const r=s(o)?n:o;return Ve(r,t)||e()},je=(t,e,n,o)=>{const r=s(o)?n:o,i=Ve(r,t);return!!i&&(b(i)?i:e())},_e=new WeakMap,Ne=t=>_e.get(t),We=(t,e)=>t?e.split(".").reduce(((t,e)=>t&&S(t,e)?t[e]:void 0),t):void 0,Ze=(t,e,n)=>o=>[We(t,o),n||void 0!==We(e,o)],Ge=t=>{let e=t;return[()=>e,t=>{e=C({},e,t)}]},Ke="tabindex",qe=_.bind(0,""),Je=t=>{V(I(t),H(t)),j(t)},Ue=t=>{const e=Ye(),{Y:n,A:o}=e,r=Le()[Te],i=r&&r.T,{host:s,viewport:l,padding:c,content:a}=n(),d=b(t),u=d?{}:t,{host:h,padding:p,viewport:f,content:w}=u,g=d?t:u.target,v=B(g,"textarea"),x=g.ownerDocument,$=g===x.body,S=x.defaultView,C=Fe.bind(0,[g]),E=je.bind(0,[g]),P=C(qe,l,f),z=P===g,D=z&&$,T=!z&&S.top===S&&x.activeElement===g,k={J:g,K:v?C(qe,s,h):g,Z:P,tt:!z&&E(qe,c,p),nt:!z&&E(qe,a,w),ot:!z&&!o&&i&&i(e),st:D?x.documentElement:P,et:D?x:P,ct:S,rt:x,it:v,W:$,lt:d,X:z,ut:(t,e)=>z?((t,e,n)=>{const o=A(t,Nt)||"";return new Set(o.split(" ")).has(n)})(P,0,e):((t,e)=>lt(t,e,((t,e)=>t.contains(e))))(P,t),dt:(t,e,n)=>z?M(P,Nt,e,n):(n?at:ct)(P,t)},X=L(k).reduce(((t,e)=>{const n=k[e];return m(t,!(!n||I(n))&&n)}),[]),_=t=>t?y(X,t)>-1:null,{J:N,K:W,tt:Z,Z:G,nt:K,ot:q}=k,J=[],U=v&&_(W);let Q=v?N:H([K,G,Z,W,N].find((t=>!1===_(t))));const tt=K||G;return[k,()=>{const t=((t,e)=>(A(t,Nt,e),R.bind(0,t,Nt)))(W,z?"viewport":"host"),e=at(Z,Jt),n=at(G,!z&&Ut),r=at(K,te),i=D?at(I(g),ee):wt;if(U&&(F(N,W),m(J,(()=>{F(W,N),j(W)}))),V(tt,Q),V(W,Z),V(Z||W,!z&&G),V(G,K),m(J,(()=>{i(),t(),R(G,Wt),R(G,Zt),_(K)&&Je(K),_(G)&&Je(G),_(Z)&&Je(Z),e(),n(),r()})),o&&!z&&m(J,ct.bind(0,G,ee)),q&&(((t,e)=>{Y(I(t),t,e)})(G,q),m(J,j.bind(0,q))),T){const t=A(G,Ke);A(G,Ke,"-1"),G.focus();const e=Dt(x,"pointerdown keydown",(()=>{t?A(G,Ke,t):R(G,Ke),e()}))}Q=0},O.bind(0,J)]},Qe=(t,n)=>{const{nt:o}=t,[r]=n;return t=>{const{V:n}=Ye(),{ft:i}=r(),{_t:s}=t,l=(o||!n)&&s;return l&&e(o,{height:i?"":"100%"}),{ht:l,gt:l}}},tn=(t,o)=>{const[r,i]=o,{K:s,tt:l,Z:c,X:a}=t,[d,u]=n({u:pt,o:$t()},$t.bind(0,s,"padding",""));return(t,n,o)=>{let[s,h]=u(o);const{A:p,V:f}=Ye(),{vt:w}=r(),{ht:g,gt:b,wt:v}=t,[y,m]=n("paddingAbsolute");(g||h||!f&&b)&&([s,h]=d(o));const x=!a&&(m||v||h);if(x){const t=!y||!l&&!p,n=s.r+s.l,o=s.t+s.b,r={marginRight:t&&!w?-n:0,marginBottom:t?-o:0,marginLeft:t&&w?-n:0,top:t?-s.t:0,right:t?w?-s.r:"auto":0,left:t?w?"auto":-s.l:0,width:t?`calc(100% + ${n}px)`:""},a={paddingTop:t?s.t:0,paddingRight:t?s.r:0,paddingBottom:t?s.b:0,paddingLeft:t?s.l:0};e(l||c,r),e(c,a),i({tt:s,bt:!t,P:l?a:C({},r,a)})}return{yt:x}}},{max:en}=Math,nn=en.bind(0,0),on="visible",rn="hidden",sn=42,ln={u:ut,o:{w:0,h:0}},cn={u:ht,o:{x:rn,y:rn}},an=(t,e,n)=>n?at(t,e):ct(t,e),dn=t=>0===t.indexOf(on),un=(t,o)=>{const[r,i]=o,{K:s,tt:l,Z:c,ot:a,X:d,dt:u,W:h,ct:p}=t,{k:f,V:w,A:g,I:b}=Ye(),v=Le()[Te],y=!d&&!g&&(b.x||b.y),m=h&&d,[x,$]=n(ln,Pt.bind(0,c)),[O,S]=n(ln,Et.bind(0,c)),[L,C]=n(ln),[E,P]=n(ln),[R]=n(cn),z=(t,n)=>{if(e(c,{height:""}),n){const{bt:n,tt:o}=r(),{St:i,D:l}=t,a=Pt(s),d=Ct(s),u="content-box"===e(c,"boxSizing"),h=n||u?o.b+o.t:0,p=!(b.x&&u);e(c,{height:d.h+a.h+(i.x&&p?l.x:0)-h})}},D=(t,n)=>{const o=g||t?0:sn,r=(t,r,i)=>{const s=e(c,t),l="scroll"===(n?n[t]:s);return[s,l,l&&!g?r?o:i:0,r&&!!o]},[i,s,l,a]=r("overflowX",b.x,f.x),[d,u,h,p]=r("overflowY",b.y,f.y);return{xt:{x:i,y:d},St:{x:s,y:u},D:{x:l,y:h},M:{x:a,y:p}}},T=(t,e,n,o)=>{const{D:i,M:s}=t,{x:l,y:c}=s,{x:a,y:d}=i,{P:u}=r(),h=e?"marginLeft":"marginRight",p=e?"paddingLeft":"paddingRight",f=u[h],w=u.marginBottom,g=u[p],b=u.paddingBottom;o.width=`calc(100% + ${d+-1*f}px)`,o[h]=-d+f,o.marginBottom=-a+w,n&&(o[p]=g+(c?d:0),o.paddingBottom=b+(l?a:0))},[k,B]=v?v.H(y,w,c,a,r,D,T):[()=>y,()=>[wt]];return(t,n,o)=>{const{ht:a,$t:h,gt:f,yt:v,_t:y,wt:H}=t,{ft:I,vt:X}=r(),[Y,V]=n("showNativeOverlaidScrollbars"),[F,j]=n("overflow"),_=Y&&b.x&&b.y,N=!d&&!w&&(a||f||h||V||y),W=dn(F.x),Z=dn(F.y),G=W||Z;let K,q=$(o),J=S(o),U=C(o),Q=P(o);if(V&&g&&u(ee,Kt,!_),N&&(K=D(_),z(K,I)),a||v||f||H||V){G&&u(ne,Gt,!1);const[t,e]=B(_,X,K),[n,r]=q=x(o),[i,s]=J=O(o),l=Ct(c);let a=i,d=l;t(),(s||r||V)&&e&&!_&&k(e,i,n,X)&&(d=Ct(c),a=Et(c));const h={w:nn(en(i.w,a.w)+n.w),h:nn(en(i.h,a.h)+n.h)},f={w:nn(m?p.innerWidth:d.w+nn(l.w-i.w)+n.w),h:nn(m?p.innerHeight:d.h+nn(l.h-i.h)+n.h)};Q=E(f),U=L(((t,e)=>{const n=window.devicePixelRatio%1!=0?1:0,o={w:nn(t.w-e.w),h:nn(t.h-e.h)};return{w:o.w>n?o.w:0,h:o.h>n?o.h:0}})(h,f),o)}const[tt,et]=Q,[nt,ot]=U,[rt,it]=J,[st,lt]=q,ct={x:nt.w>0,y:nt.h>0},at=W&&Z&&(ct.x||ct.y)||W&&ct.x&&!ct.y||Z&&ct.y&&!ct.x;if(v||H||lt||it||et||ot||j||V||N){const t={marginRight:0,marginBottom:0,marginLeft:0,width:"",overflowY:"",overflowX:""},n=((t,e,n,o)=>{const r=(t,e)=>{const n=dn(t),o=e&&n&&t.replace(`${on}-`,"")||"";return[e&&!n?t:"",dn(o)?"hidden":o]},[i,s]=r(n.x,e.x),[l,c]=r(n.y,e.y);return o.overflowX=s&&l?s:i,o.overflowY=c&&i?c:l,D(t,o)})(_,ct,F,t),o=k(n,rt,st,X);d||T(n,X,o,t),N&&z(n,I),d?(A(s,Wt,t.overflowX),A(s,Zt,t.overflowY)):e(c,t)}M(s,Nt,Gt,at),an(l,ne,at),!d&&an(c,ne,G);const[dt,ut]=R(D(_).xt);return i({xt:dt,Ct:{x:tt.w,y:tt.h},Ot:{x:nt.w,y:nt.h},Et:ct}),{Tt:ut,At:et,zt:ot}}},hn=(e,n,o)=>{const r={},i=n||{};return t(L(e).concat(L(i)),(t=>{const n=e[t],s=i[t];r[t]=!!(o||n||s)})),r},pn=3333333,fn=t=>t&&(t.height||t.width),wn=(t,e,o)=>{const{It:r=!1,Lt:i=!1}=o||{},s=Le()[Ae],{B:l}=Ye(),c=N(`<div class="${oe}"><div class="${ie}"></div></div>`)[0],a=c.firstChild,d=xt.bind(0,t),[h]=n({o:void 0,_:!0,u:(t,e)=>!(!t||!fn(t)&&fn(e))}),w=t=>{const n=p(t)&&t.length>0&&f(t[0]),o=!n&&u(t[0]);let i=!1,s=!1,a=!0;if(n){const[e,,n]=h(t.pop().contentRect),o=fn(e),r=fn(n);i=!n||!o,s=!r&&o,a=!i}else o?[,a]=t:s=!0===t;if(r&&a){const e=o?t[0]:xt(c);z(c,e?l.n?-pn:l.i?0:pn:pn),D(c,pn)}i||e({ht:!o,Ht:o?t:void 0,Lt:!!s})},g=[];let b=!!i&&w;return[()=>{O(g),j(c)},()=>{if(et){const t=new et(w);t.observe(a),m(g,(()=>{t.disconnect()}))}else if(s){const[t,e]=s.O(a,w,i);b=t,m(g,e)}if(r){const[t]=n({o:!d()},d);m(g,Dt(c,"scroll",(e=>{const n=t(),[o,r]=n;r&&(ct(a,"ltr rtl"),at(a,o?"rtl":"ltr"),w(n)),Tt(e)})))}b&&(at(c,re),m(g,Dt(c,"animationstart",b,{C:!!et}))),V(t,c)}]},gn=(t,e)=>{let o;const r=_(ae),i=[],[s]=n({o:!1}),l=(t,n)=>{if(t){const o=s((t=>0===t.h||t.isIntersecting||t.intersectionRatio>0)(t)),[,r]=o;if(r)return!n&&e(o),[o]}},c=(t,e)=>{if(t&&t.length>0)return l(t.pop(),e)};return[()=>{O(i),j(r)},()=>{if(tt)o=new tt((t=>c(t)),{root:t}),o.observe(r),m(i,(()=>{o.disconnect()}));else{const t=()=>{const t=Lt(r);l(t)},[e,n]=wn(r,t);m(i,e),n(),t()}V(t,r)},()=>{if(o)return c(o.takeRecords(),!0)}]},bn=(e,n,o,r)=>{let i=!1;const{Pt:s,Dt:l,Mt:c,Rt:a,kt:u,Bt:h}=r||{},p=gt((()=>{i&&o(!0)}),{g:33,v:99}),[f,w]=((e,n,o)=>{let r,i=!1;const s=s=>{if(o){const l=o.reduce(((t,n)=>{if(n){const o=n[0],r=n[1],i=r&&o&&(s?s(o):k(o,e));i&&i.length&&r&&d(r)&&m(t,[i,r.trim()],!0)}return t}),[]);t(l,(e=>t(e[0],(t=>{const o=e[1],s=r.get(t);if(s){const t=s[0],e=s[1];t===o&&e()}const l=Dt(t,o,(e=>{i?(l(),r.delete(t)):n(e)}));r.set(t,[o,l])}))))}};return o&&(r=new WeakMap,s()),[()=>{i=!0},s]})(e,p,c),g=l||[],b=(s||[]).concat(g),v=(i,s)=>{const l=u||wt,c=h||wt,p=[],f=[];let b=!1,v=!1,x=!1;return t(i,(t=>{const{attributeName:o,target:i,type:s,oldValue:u,addedNodes:h}=t,w="attributes"===s,$="childList"===s,O=e===i,S=w&&d(o)?A(i,o):0,L=0!==S&&u!==S,C=y(g,o)>-1&&L;if(n&&!O){const n=!w,s=w&&C,d=s&&a&&B(i,a),p=(d?!l(i,o,u,S):n||s)&&!c(t,!!d,e,r);m(f,h),v=v||p,x=x||$}!n&&O&&L&&!l(i,o,u,S)&&(m(p,o),b=b||C)})),x&&!$(f)&&w((t=>f.reduce(((e,n)=>(m(e,k(t,n)),B(n,t)?m(e,n):e)),[]))),n?(!s&&v&&o(!1),[!1]):!$(p)||b?(!s&&o(p,b),[p,b]):void 0},x=new Q((t=>v(t)));return x.observe(e,{attributes:!0,attributeOldValue:!0,attributeFilter:b,subtree:n,childList:n,characterData:n}),i=!0,[()=>{i&&(f(),x.disconnect(),i=!1)},()=>{if(i){p.m();const t=x.takeRecords();return!$(t)&&v(t,!0)}}]},vn=`[${Nt}]`,yn=`.${Ut}`,mn=["tabindex"],xn=["wrap","cols","rows"],$n=["id","class","style","open"],On=(e,o,r)=>{let i,s,l;const[,c]=o,{K:u,Z:f,nt:w,it:g,X:b,ut:x,dt:$}=e,{V:O}=Ye(),[S]=n({u:ut,o:{w:0,h:0}},(()=>{const t=x(ne,Gt),e=x(Qt,""),n=e&&z(f),o=e&&D(f);$(ne,Gt),$(Qt,""),$("",qt,!0);const r=Et(w),i=Et(f),s=Pt(f);return $(ne,Gt,t),$(Qt,"",e),$("",qt),z(f,n),D(f,o),{w:i.w+r.w+s.w,h:i.h+r.h+s.h}})),E=g?xn:$n.concat(xn),P=gt(r,{g:()=>i,v:()=>s,p(t,e){const[n]=t,[o]=e;return[L(n).concat(L(o)).reduce(((t,e)=>(t[e]=n[e]||o[e],t)),{})]}}),M=e=>{t(e||mn,(t=>{if(y(mn,t)>-1){const e=A(u,t);d(e)?A(f,t,e):R(f,t)}}))},T=(t,e)=>{const[n,o]=t,i={_t:o};return c({ft:n}),!e&&r(i),i},k=({ht:t,Ht:e,Lt:n})=>{const o=!t||n?r:P;let i=!1;if(e){const[t,n]=e;i=n,c({vt:t})}o({ht:t,wt:i})},B=(t,e)=>{const[,n]=S(),o={gt:n};return n&&!e&&(t?r:P)(o),o},H=(t,e,n)=>{const o={$t:e};return e?!n&&P(o):b||M(t),o},[I,Y,V]=w||!O?gn(u,T):[wt,wt,wt],[F,j]=b?[wt,wt]:wn(u,k,{Lt:!0,It:!0}),[_,N]=bn(u,!1,H,{Dt:$n,Pt:$n.concat(mn)}),W=b&&et&&new et(k.bind(0,{ht:!0}));return W&&W.observe(u),M(),[()=>{I(),F(),l&&l[0](),W&&W.disconnect(),_()},()=>{j(),Y()},()=>{const t={},e=N(),n=V(),o=l&&l[1]();return e&&C(t,H.apply(0,m(e,!0))),n&&C(t,T.apply(0,m(n,!0))),o&&C(t,B.apply(0,m(o,!0))),t},t=>{const[e]=t("updating.ignoreMutation"),[n,o]=t("updating.attributes"),[r,c]=t("updating.elementEvents"),[d,u]=t("updating.debounce"),g=t=>h(e)&&e(t);if((c||o)&&(l&&(l[1](),l[0]()),l=bn(w||f,!0,B,{Dt:E.concat(n||[]),Pt:E.concat(n||[]),Mt:r,Rt:vn,Bt:(t,e)=>{const{target:n,attributeName:o}=t;return!(e||!o||b)&&((t,e,n)=>{const o=t&&X(t,e),r=t&&((t,e)=>{const n=e?v(e)?e:null:document;return n?n.querySelector(t):null})(n,o),i=X(r,e)===o;return!(!o||!r)&&(o===t||r===t||i&&X(X(t,n),e)!==o)})(n,vn,yn)||!!X(n,`.${de}`)||!!g(t)}})),u)if(P.m(),p(d)){const t=d[0],e=d[1];i=!!a(t)&&t,s=!!a(e)&&e}else a(d)?(i=d,s=!1):(i=!1,s=!1)}]},Sn={x:0,y:0},Ln={tt:{t:0,r:0,b:0,l:0},bt:!1,P:{marginRight:0,marginBottom:0,marginLeft:0,paddingTop:0,paddingRight:0,paddingBottom:0,paddingLeft:0},Ct:Sn,Ot:Sn,xt:{x:"hidden",y:"hidden"},Et:{x:!1,y:!1},ft:!1,vt:!1},{round:Cn}=Math,En=t=>({x:t.clientX,y:t.clientY}),Pn=(t,e)=>Dt(t,"mousedown",Dt.bind(0,e,"click",Tt,{C:!0,$:!0}),{$:!0}),An=(t,e,n,o,r,i)=>{const{B:s}=Ye(),{qt:l,Ft:c,Gt:a}=n,d=`scroll${i?"Left":"Top"}`,u=`${i?"x":"y"}`,h=`${i?"w":"h"}`,p=(t,e,n)=>p=>{const{Ot:f}=r(),w=(En(p)[u]-e)*n/(Lt(c)[h]-Lt(l)[h])*f[u],g=xt(a)&&i?s.n||s.i?1:-1:1;o[d]=t+w*g};return Dt(l,"pointerdown",(n=>{if(((t,e,n)=>{const o=e.scrollbars,{button:r,isPrimary:i,pointerType:s}=t,{pointers:l}=o;return 0===r&&i&&o["dragScroll"]&&(l||[]).includes(s)})(n,t)){const t=Dt(e,"selectstart",(t=>(t=>t.preventDefault())(t)),{S:!1}),r=Dt(l,"pointermove",p(o[d]||0,En(n)[u],1/(t=>{const{width:e,height:n}=At(t),{w:o,h:r}=Lt(t);return{x:Cn(e)/o||1,y:Cn(n)/r||1}})(o)[u]));Dt(l,"pointerup",(e=>{t(),r(),l.releasePointerCapture(e.pointerId)}),{C:!0}),l.setPointerCapture(n.pointerId)}}))},{min:Mn,max:Rn,abs:zn,round:Dn}=Math,Tn=(t,e,n,o)=>{if(o){const t=n?"x":"y",{Ot:e,Ct:r}=o,i=r[t],s=e[t];return Rn(0,Mn(1,i/(i+s)))}const r=n?"w":"h",i=Lt(t)[r],s=Lt(e)[r];return Rn(0,Mn(1,i/s))},kn=(n,o,r)=>{const{Y:i}=Ye(),{scrollbarsSlot:s}=i(),{rt:l,J:c,K:a,Z:d,lt:h,st:p}=o,{scrollbarsSlot:f}=h?{}:n,w=je([c,a,d],(()=>a),s,f),g=(e,n,o)=>{const r=o?at:ct;t(e,(t=>{r(t.Gt,n)}))},b=(n,o)=>{t(n,(t=>{const[n,r]=o(t);e(n,r)}))},v=(t,e,n)=>{b(t,(t=>{const{qt:o,Ft:r}=t;return[o,{[n?"width":"height"]:`${(100*Tn(o,r,n,e)).toFixed(3)}%`}]}))},y=(t,e,n)=>{const o=n?"X":"Y";b(t,(t=>{const{qt:r,Ft:i,Gt:s}=t,l=((t,e,n,o,r,i)=>{const{B:s}=Ye(),l=i?"x":"y",c=i?"Left":"Top",{Ot:a}=o,d=Dn(a[l]),u=zn(n[`scroll${c}`]),h=i&&r,p=s.i?u:d-u,f=Mn(1,(h?p:u)/d),w=Tn(t,e,i);return 1/w*(1-w)*f})(r,i,p,e,xt(s),n);return[r,{transform:l==l?`translate${o}(${(100*l).toFixed(3)}%)`:""}]}))},x=[],S=[],L=[],C=(t,e,n)=>{const o=u(n),r=!o||!n;(!o||n)&&g(S,t,e),r&&g(L,t,e)},E=t=>{const e=t?he:pe,n=t?S:L,o=$(n)?ve:"",i=_(`${de} ${e} ${o}`),s=_(fe),c=_(we),a={Gt:i,Ft:s,qt:c};return V(i,s),V(s,c),m(n,a),m(x,[j.bind(0,i),r(a,C,l,p,t)]),a},P=E.bind(0,!0),A=E.bind(0,!1);return P(),A(),[{Nt:t=>{v(S,t,!0),v(L,t)},Ut:t=>{y(S,t,!0),y(L,t)},Wt:C,Xt:{Jt:S,Kt:P,Zt:b.bind(0,S)},Qt:{Jt:L,Kt:A,Zt:b.bind(0,L)}},()=>{V(w,S[0].Gt),V(w,L[0].Gt),rt((()=>{C(ve)}),300)},O.bind(0,x)]},Bn=t=>{let e;const n=t?rt:ot,o=t?it:nt;return[r=>{o(e),e=n(r,h(t)?t():t)},()=>o(e)]},Hn=(e,n,o)=>{const{F:r,j:i}=Ye(),c=Le(),a=b(e),d=a?e:e.target,u=Ne(d);if(n&&!u){let u=!1;const p=c[Ce],f=t=>{const e=t||{},n=p&&p.O;return n?n(e,!0):e},w=C({},r(),f(n)),[g,b,v]=It(o),[y,m,x]=((e,n)=>{const o=Ze(n,{}),r=Ge(Ln),[i,s,l]=It(),[c]=r,[a,d,u]=Ue(e),h=((e,n)=>{const{J:o,Z:r,dt:i,X:s}=e,{A:l,I:c,V:a}=Ye(),d=!l&&(c.x||c.y),u=[Qe(e,n),tn(e,n),un(e,n)];return(e,n,l)=>{const c=hn(C({ht:!1,yt:!1,wt:!1,_t:!1,At:!1,zt:!1,Tt:!1,$t:!1,gt:!1},n),{},l),h=d||!a,p=h&&z(r),f=h&&D(r);i("",qt,!0);let w=c;return t(u,(t=>{w=hn(w,t(w,e,!!l)||{},l)})),z(r,p),D(r,f),i("",qt),s||(z(o,0),D(o,0)),w}})(a,r),p=(t,e,n)=>{const o=L(t).some((e=>t[e]));(o||!E(e)||n)&&l("u",[t,e,n])},[f,w,g,b]=On(a,r,(t=>{p(h(o,t),{},!1)})),v=c.bind(0);return v.Vt=t=>{i("u",t)},v.jt=()=>{const{J:t,Z:e}=a,n=z(t),o=D(t);w(),d(),z(e,n),D(e,o)},v.Yt=a,[(t,e)=>{const o=Ze(n,t,e);b(o),p(h(o,g(),e),t,!!e)},v,()=>{s(),f(),u()}]})(e,w),[$,S,P]=((t,e,n)=>{let o,r,i,s,l,c=0;const a=Ge({}),[d]=a,[u,h]=Bn(),[p,f]=Bn(),[w,g]=Bn(100),[b,v]=Bn(100),[y,m]=Bn((()=>c)),[x,$,S]=kn(t,n.Yt,((t,e)=>(n,o,r,i,s)=>{const{Gt:l}=n;return O.bind(0,[Dt(l,"pointerenter",(()=>{o(ye,!0)})),Dt(l,"pointerleave pointercancel",(()=>{o(ye)})),Pn(l,r),An(t,r,n,i,e,s)])})(e,n)),{K:L,Z:C,st:E,et:P,X:A,W:M}=n.Yt,{Xt:R,Qt:T,Wt:k,Nt:B,Ut:H}=x,{Zt:X}=R,{Zt:Y}=T,V=t=>{const{Gt:e}=t,n=A&&!M&&I(e)===C&&e;return[n,{transform:n?`translate(${z(E)}px, ${D(E)}px)`:""}]},F=(t,e)=>{if(m(),t)k(xe);else{const t=()=>k(xe,!0);c>0&&!e?y(t):t()}},j=()=>{s=r,s&&F(!0)},_=[g,m,v,f,h,S,Dt(L,"pointerover",j,{C:!0}),Dt(L,"pointerenter",j),Dt(L,"pointerleave",(()=>{s=!1,r&&F(!1)})),Dt(L,"pointermove",(()=>{o&&u((()=>{g(),F(!0),b((()=>{o&&F(!1)}))}))})),Dt(P,"scroll",(()=>{p((()=>{H(n()),i&&F(!0),w((()=>{i&&!s&&F(!1)}))})),A&&X(V),A&&Y(V)}))],N=d.bind(0);return N.Yt=x,N.jt=$,[(t,s,a)=>{const{At:d,zt:u,Tt:h,wt:p}=a,f=Ze(e,t,s),w=n(),{Ot:g,xt:b,vt:v}=w,[y,m]=f("scrollbars.theme"),[x,$]=f("scrollbars.visibility"),[O,S]=f("scrollbars.autoHide"),[L]=f("scrollbars.autoHideDelay"),[C,E]=f("scrollbars.dragScroll"),[P,A]=f("scrollbars.clickScroll"),R=d||u||p||s,z=h||$||s,D=(t,e)=>{const n="visible"===x||"auto"===x&&"scroll"===t;return k(ge,n,e),n};if(c=L,m&&(k(l),k(y,!0),l=y),S&&(o="move"===O,r="leave"===O,i="never"!==O,F(!i,!0)),E&&k(Oe,C),A&&k($e,P),z){const t=D(b.x,!0),e=D(b.y,!1);k(be,!(t&&e))}R&&(B(w),H(w),k(me,!g.x,!0),k(me,!g.y,!1),k(ue,v&&!M))},N,O.bind(0,_)]})(e,w,m),A=(t,e)=>{y(t,!!e)},M=i(A.bind(0,{},!0)),R=t=>{(t=>{_e.delete(t)})(d),M(),P(),x(),u=!0,v("destroyed",[T,!!t]),b()},T={options(t){if(t){const e=Vt(w,f(t));E(e)||(C(w,e),A(e))}return C({},w)},on:g,off:(t,e)=>{t&&e&&b(t,e)},state(){const{Ct:t,Ot:e,xt:n,Et:o,tt:r,bt:i,vt:s}=m();return C({},{overflowEdge:t,overflowAmount:e,overflowStyle:n,hasOverflow:o,padding:r,paddingAbsolute:i,directionRTL:s,destroyed:u})},elements(){const{J:t,K:e,tt:n,Z:o,nt:r,st:i,et:s}=m.Yt,{Xt:l,Qt:c}=S.Yt,a=t=>{const{qt:e,Ft:n,Gt:o}=t;return{scrollbar:o,track:n,handle:e}},d=t=>{const{Jt:e,Kt:n}=t,o=a(e[0]);return C({},o,{clone:()=>{const t=a(n());return $({},!0,{}),t}})};return C({},{target:t,host:e,padding:n||o,viewport:o,content:r||o,scrollOffsetElement:i,scrollEventElement:s,scrollbarHorizontal:d(l),scrollbarVertical:d(c)})},update:t=>(A({},t),T),destroy:R.bind(0)};return m.Vt(((t,e,n)=>{$(e,n,t)})),t(L(c),(t=>{const e=c[t];h(e)&&e(Hn,T)})),((t,e)=>{const{nativeScrollbarsOverlaid:n,body:o}=t||{},{W:r,X:i}=e,{Y:c,I:a}=Ye(),{nativeScrollbarsOverlaid:d,body:u}=c().cancel,h=null!=n?n:d,p=s(o)?u:o,f=(a.x||a.y)&&h,w=r&&(l(p)?!i:p);return!!f||!!w})(!a&&e.cancel,m.Yt)?(R(!0),T):(m.jt(),S.jt(),((t,e)=>{_e.set(t,e)})(d,T),v("initialized",[T]),m.Vt(((t,e,n)=>{const{ht:o,wt:r,_t:i,At:s,zt:l,Tt:c,gt:a,$t:d}=t;v("updated",[T,{updateHints:{sizeChanged:o,directionChanged:r,heightIntrinsicChanged:i,overflowEdgeChanged:s,overflowAmountChanged:l,overflowStyleChanged:c,contentMutation:a,hostMutation:d},changedOptions:e,force:n}])})),T.update(!0))}return u};Hn.plugin=e=>{t(p(e)?e:[e],(t=>{const e=L(t)[0];Se[e]=t[e]}))},Hn.valid=t=>{const e=t&&t.elements,n=h(e)&&e();return g(n)&&!!Ne(n.target)},Hn.env=()=>{const{k:t,I:e,A:n,B:o,V:r,L:i,N:s,U:l,Y:c,q:a,F:d,G:u}=Ye();return C({},{scrollbarsSize:t,scrollbarsOverlaid:e,scrollbarsHiding:n,rtlScrollBehavior:o,flexboxGlue:r,cssCustomProperties:i,staticDefaultInitialization:s,staticDefaultOptions:l,getDefaultInitialization:c,setDefaultInitialization:a,getDefaultOptions:d,setDefaultOptions:u})};export{Hn as OverlayScrollbars,ke as scrollbarsHidingPlugin,Me as sizeObserverPlugin}; |