Files
OverlayScrollbars/packages/overlayscrollbars/dist/overlayscrollbars.esm.min.js
T
2021-01-09 02:35:06 +01:00

1 line
12 KiB
JavaScript

const t=t=>null==t?""+t:Object.prototype.toString.call(t).replace(/^\[object (.+)\]$/,"$1").toLowerCase();function e(t){return"number"==typeof t}function n(t){return"string"==typeof t}function o(t){return"function"==typeof t}function r(t){return void 0===t}function i(t){return null===t}function s(t){return Array.isArray(t)}function c(t){return"object"==typeof t&&!s(t)&&!i(t)}function l(t){const n=!!t&&t.length;return s(t)||!o(t)&&e(n)&&n>-1&&n%1==0}function a(e){if(!e||!c(e)||"object"!==t(e))return!1;let n;const{hasOwnProperty:o}=Object.prototype,i=o.call(e,"constructor"),s=e.constructor&&e.constructor.prototype&&o.call(e.constructor.prototype,"isPrototypeOf");if(e.constructor&&!i&&!s)return!1;for(n in e);return r(n)||o.call(e,n)}function d(t){for(const e in t)return!1;return!0}function u(t,e,n,o){if(r(o))return n?n[t]:e;n&&(n[t]=o)}const v=(t,e)=>{null==t||t.removeAttribute(e)};function f(t,e){return u("scrollLeft",0,t,e)}function h(t,e){return u("scrollTop",0,t,e)}const b=/[^\x20\t\r\n\f]+/g,w=(t,e)=>{((t,e,o)=>{let r,i=0,s=!1;if(t&&n(e)){const n=e.match(b)||[];for(s=n.length>0;r=n[i++];)s=o(t.classList,r)&&s}})(t,e,(t,e)=>t.add(e))};function p(t,e){if(l(t))for(let n=0;n<t.length&&!1!==e(t[n],n,t);n++);else t&&p(Object.keys(t),n=>e(t[n],n,t));return t}const _=t=>{if(Array.from)return Array.from(t);const e=[];return p(t,t=>{e.push(t)}),e},g=(t,e)=>{t instanceof Set?t.forEach(t=>t&&t(e)):p(t,t=>t&&t(e))},m=Element.prototype,y=t=>t?_(t.childNodes):[],x=(t,e,n)=>{if(n){let o,r=e;t&&(l(n)?(o=document.createDocumentFragment(),p(n,t=>{t===r&&(r=t.previousSibling),o.appendChild(t)})):o=n,e&&(r?r!==e&&(r=r.nextSibling):r=t.firstChild),t.insertBefore(o,r))}},z=(t,e)=>{x(t,null,e)},O=(t,e)=>{x(t,t&&t.firstChild,e)},S=t=>{if(l(t))p(_(t),t=>S(t));else if(t){const n=(e=t)?e.parentElement:null;n&&n.removeChild(t)}var e},j=t=>{const e=document.createElement("div");return t&&function(t,e,n){if(r(n))return t?t.getAttribute(e):null;t&&t.setAttribute(e,n)}(e,"class",t),e},A=t=>{const e=j();return e.innerHTML=t.trim(),p(y(e),t=>S(t))},M={w:0,h:0},$=()=>({w:window.innerWidth,h:window.innerHeight}),k=t=>t?{w:t.offsetWidth,h:t.offsetHeight}:M;let L;const T=(t,e,n,o)=>{p(e.split(" "),e=>{t.removeEventListener(e,n,o)})},q=(t,e,n,o)=>{const r=(()=>{if(void 0===L){L=!1;try{window.addEventListener("test",null,Object.defineProperty({},"passive",{get:function(){L=!0}}))}catch(t){}}return L})(),i=r&&o&&o.o||!1,s=o&&o.s||!1,c=o&&o.u||!1,l=[],a=r?{passive:i,capture:s}:s;return p(e.split(" "),e=>{const o=c?r=>{t.removeEventListener(e,o,s),n&&n(r)}:n;l.push(T.bind(null,t,e,o,s)),t.addEventListener(e,o,a)}),g.bind(0,l)},P=t=>t.stopPropagation(),C=t=>t.preventDefault(),F=(t,e,n)=>{if(t&&e){let o=!0;return p(n,n=>{t[n]!==e[n]&&(o=!1)}),o}return!1},I=(t,e)=>F(t,e,["w","h"]),V=(t,e)=>F(t,e,["x","y"]),B=(t,e)=>F(t,e,["t","r","b","l"]),E=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),N=t=>t?Object.keys(t):[];function Y(t,e,n,r,c,l,d){const u=[e,n,r,c,l,d];return"object"==typeof t&&!i(t)||o(t)||(t={}),p(u,e=>{p(N(e),n=>{const o=e[n];if(t===o)return!0;const r=s(o);if(o&&(a(o)||r)){const e=t[n];let i=e;r&&!s(e)?i=[]:r||a(e)||(i={}),t[n]=Y(i,o)}else t[n]=o})}),t}const G={animationiterationcount:1,columncount:1,fillopacity:1,flexgrow:1,flexshrink:1,fontweight:1,lineheight:1,opacity:1,order:1,orphans:1,widows:1,zindex:1,zoom:1},J=(t,e)=>{const n=e?parseFloat(t):parseInt(t,10);return Number.isNaN(n)?0:n},K=(t,e,n)=>null!=e?e.getPropertyValue(n):t.style[n],R=(t,n,o)=>{try{t&&void 0!==t.style[n]&&(t.style[n]=((t,n)=>!G[t.toLowerCase()]&&e(n)?n+"px":n)(n,o))}catch(r){}};function U(t,e){const o=n(e);if(s(e)||o){let n=o?"":{};if(t){const r=window.getComputedStyle(t,null);n=o?K(t,r,e):e.reduce((e,n)=>(e[n]=K(t,r,n),e),n)}return n}p(N(e),n=>R(t,n,e[n]))}const W={x:0,y:0},X=t=>{const e=t?(t=>t.getBoundingClientRect())(t):0;return e?{x:e.left+window.pageYOffset,y:e.top+window.pageXOffset}:W},D=(t,e)=>{const{v:n,p:o}=e||{};let r,i=o;return(e,o)=>{const s=i,c=t(o,i,r),l=e||(n?!n(s,c):s!==c);return l&&(i=c,r=s),{_:i,g:r,m:l}}},H=t=>t.charAt(0).toUpperCase()+t.slice(1),Q=["-webkit-","-moz-","-o-","-ms-"],Z=["WebKit","Moz","O","MS","webkit","moz","o","ms"],tt={},et={},nt=t=>{let e=et[t];if(E(et,t))return e;const n=H(t),o=j().style;return p(Q,r=>{const i=r.replace(/-/g,""),s=[t,r+t,i+n,H(i)+n];return e=s.find(t=>void 0!==o[t]),!e}),et[t]=e,e},ot=t=>{let e=tt[t]||window[t];return E(tt,t)||(p(Z,n=>(e=e||window[n+H(t)],!e)),tt[t]=e),e},rt=(ot("MutationObserver"),ot("IntersectionObserver")),it=ot("ResizeObserver"),st=ot("cancelAnimationFrame"),ct=ot("requestAnimationFrame");var lt=function(t){var e={exports:{}};return t(e,e.exports),e.exports}((function(t){function e(){return t.exports=e=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(t[o]=n[o])}return t},e.apply(this,arguments)}t.exports=e}));const{stringify:at}=JSON,dt=["__TPL_","_TYPE__"],ut=["boolean","number","string","array","object","function","null"].reduce((t,e)=>(t[e]=dt[0]+e+dt[1],t),{}),vt=(e,o,i,c,l)=>{const u={},v=lt({},e);return p(N(o).filter(t=>E(e,t)),f=>{const h=r(i[f])?{}:i[f],b=e[f],w=o[f],_=a(w),g=l?l+".":"";if(_&&a(b)){const t=vt(b,w,h,c,g+f);u[f]=t.O,v[f]=t.S,p([v,u],t=>{d(t[f])&&delete t[f]})}else if(!_){let e=!1;const o=[],r=[],i=t(b);if(p(s(w)?w:[w],t=>{let s;p(ut,(e,n)=>{e===t&&(s=n)});const c=void 0===s;if(c&&n(b)){const n=t.split(" ");e=!!n.find(t=>t===b),o.push(...n)}else e=ut[i]===t;return r.push(c?ut.string:s),!e}),e){(s(b)||a(b)?at(b)!==at(h):b!==h)&&(u[f]=b)}else c&&console.warn(`The option "${g}${f}" wasn't set, because it doesn't accept the type [ ${i.toUpperCase()} ] with the value of "${b}".\r\nAccepted types are: [ ${r.join(", ").toUpperCase()} ].\r\n${o.length>0?`\r\nValid strings are: [ ${o.join(", ")} ].`:""}`);delete v[f]}}),{S:v,O:u}},ft=(t,e,n,o)=>vt(t,e,n||{},o||!1);let ht;const{abs:bt,round:wt}=Math,pt=(t,e)=>{z(t,e);const n=(o=e)?{w:o.clientWidth,h:o.clientHeight}:M;var o;const r=k(e);return{x:r.h-n.h,y:r.w-n.w}},_t=t=>{let e=!1;w(t,"os-viewport-scrollbar-styled");try{e="none"===U(t,"scrollbar-width")||"none"===window.getComputedStyle(t,"::-webkit-scrollbar").getPropertyValue("display")}catch(n){}return e},gt=(t,e)=>{U(t,{overflowX:"hidden",overflowY:"hidden",direction:"rtl"}),f(t,0);const n=X(t),o=X(e);f(t,-999);const r=X(e);return{i:n.x===o.x,n:o.x!==r.x}},mt=(t,e)=>{w(t,"os-environment-flexbox-glue");const n=k(t),o=k(e),r=I(o,n);w(t,"os-environment-flexbox-glue-max");const i=k(t),s=k(e),c=I(s,i);return r&&c},yt=()=>{const t=window.screen.deviceXDPI||0,e=window.screen.logicalXDPI||1;return window.devicePixelRatio||t/e},xt=()=>{const{body:t}=document,e=A('<div class="os-environment"><div></div></div>')[0],n=e.firstChild,o=new Set,r=pt(t,e),i={x:0===r.x,y:0===r.y},s={j:!1,A:r,M:i,$:_t(e),k:gt(e,n),L:mt(e,n),T(t){o.add(t)},q(t){o.delete(t)}};if(v(e,"style"),v(e,"class"),S(e),!i.x||!i.y){let n=$(),i=yt(),s=r;window.addEventListener("resize",()=>{if(o.size){const r=$(),c={w:r.w-n.w,h:r.h-n.h};if(0===c.w&&0===c.h)return;const l={w:bt(c.w),h:bt(c.h)},a={w:bt(wt(r.w/(n.w/100))),h:bt(wt(r.h/(n.h/100)))},d=yt(),u=l.w>2&&l.h>2,v=!((t,e)=>{const n=bt(t),o=bt(e);return!(n===o||n+1===o||n-1===o)})(a.w,a.h),f=d!==i&&i>0;if(u&&v&&f){const n=ht.A=pt(t,e);S(e),s.x===n.x&&s.y===n.y||g(o),s=n}n=r,i=d}})}return s},zt=()=>(ht||(ht=xt()),ht),Ot=(t,e)=>t&&e.split(".").reduce((t,e)=>t&&E(t,e)?t[e]:void 0,t),St=(t,e,n)=>{const{P:o,C:r}=function t(e){const n={P:{},C:{}};return p(N(e),o=>{const r=e[o];if(s(r))n.P[o]=r[1],n.C[o]=r[0];else{const e=t(r);n.P[o]=e.P,n.C[o]=e.C}}),n}(t),i=Y({},r,ft(e||{},o,null,!0).O),c=t=>{const{F:e,I:o}=t;n(!!e,t=>({_:Ot(i,t),m:e||void 0!==Ot(o,t)}))};return c({F:!0}),{C(t){if(t){const{O:e}=ft(t,o,i,!0);d(e)||(Y(i,e),c({I:e}))}return i},V:t=>{c({F:t})}}},jt={paddingAbsolute:[!1,ut.boolean],overflowBehavior:{x:["scroll","visible-hidden visible-scroll scroll hidden"],y:["scroll","visible-hidden visible-scroll scroll hidden"]}},At=nt("margin-inline-end"),Mt=nt("border-inline-end"),$t=(t,e)=>{const{host:n,padding:o,viewport:r,content:i}=t,s=[],c=zt(),l=c.M,a=c.$,d=(c.L,At&&Mt||a||l.y,D(()=>((t,e)=>{const n=e||"",o=n+"-top",r=n+"-right",i=n+"-bottom",s=n+"-left",c=U(t,[o,r,i,s]);return{t:J(c[o]),r:J(c[r]),b:J(c[i]),l:J(c[s])}})(n,"padding"),{v:B})),u=D(t=>({x:Math.max(0,Math.round(100*(t.B.w-t.N.w))/100),y:Math.max(0,Math.round(100*(t.B.h-t.N.h))/100)}),{v:V}),{C:v,V:f}=St(jt,e,(t,e)=>{const{_:n,m:r}=e("paddingAbsolute"),{_:s,m:c}=d(t);if(r||c){const t={t:0,r:0,b:0,l:0};n||(t.t=-s.t,t.r=-(s.r+s.l),t.b=-(s.b+s.t),t.l=-s.l),U(o,{top:t.t,left:t.l,"margin-right":t.r,"margin-bottom":t.b,"max-width":`calc(100% + ${-1*t.r}px)`})}const l=k(o),a=k(i),v=(f=i)?{w:f.scrollWidth,h:f.scrollHeight}:M;var f;const h=u(t,{B:v,N:{w:l.w+Math.max(0,a.w-v.w),h:l.h+Math.max(0,a.h-v.h)}}),{_:b,m:w}=h;console.log("overflowAmount",b),console.log("overflowAmountChanged",w)});return{C:v,V:f,Y:()=>{f()},G:(t,e)=>{const{m:n,_:o}=e;n&&U(i,{height:o?"auto":"100%"})},J(){g(s)}}},kt=t=>U(t,"direction"),Lt=(t,e,o)=>{const{K:r=!1,R:i=!1}=o||{},s=zt().k,c=A('<div class="os-size-observer"><div class="os-size-observer-listener"></div></div>')[0],l=c.firstChild,a=t=>{if(r){const t="rtl"===kt(c);f(c,t?s.n?-3333333:s.i?0:3333333:3333333),h(c,3333333)}e(n((t||{})._)?t:void 0)},d=[];let u=i?a:null;if(it){const t=new it(a);t.observe(l),d.push(()=>t.disconnect())}else{const t=A('<div class="os-size-observer-listener-item" dir="ltr"><div class="os-size-observer-listener-item"><div class="os-size-observer-listener-item-final"></div></div><div class="os-size-observer-listener-item"><div class="os-size-observer-listener-item-final" style="width: 200%; height: 200%"></div></div></div>');z(l,t),w(l,"os-size-observer-listener-scroll");const e=t[0],n=e.lastChild,o=e.firstChild,r=null==o?void 0:o.firstChild;let s,c=k(l),v=c,b=!1;const p=()=>{f(o,3333333),h(o,3333333),f(n,3333333),h(n,3333333)},_=()=>{s=0,b&&(c=v,a())},g=t=>(v=k(l),b=!t||!I(v,c),t&&b&&!s?(st(s),s=ct(_)):t||_(),p(),t&&(C(t),P(t)),!1);d.push(q(o,"scroll",g)),d.push(q(n,"scroll",g)),U(r,{width:3333333,height:3333333}),p(),u=i?()=>g():p}if(r){const t=D(()=>kt(c));d.push(q(c,"scroll",e=>{const n=t(),{_:o,m:r}=n;return r&&(U(l,"rtl"===o?{left:"auto",right:0}:{left:0,right:"auto"}),a(n)),C(e),P(e),!1}))}return u&&(w(c,"os-size-observer-appear"),d.push(q(c,"animationstart",u))),O(t,c),()=>{g(d),S(c)}},Tt=t=>{if(function(t){const e=window.HTMLElement;return!!(c(e)||o(e)?t instanceof e:t&&c(t)&&1===t.nodeType&&n(t.nodeName))}(t)){const e=((t,e)=>{if(t){return(m.matches||m.msMatchesSelector).call(t,e)}return!1})(t,"textarea")?j():t,n=j("os-padding"),o=j("os-viewport"),r=j("os-content");return z(n,o),z(o,r),z(r,y(t)),z(t,n),w(e,"os-host"),{target:t,host:e,padding:n,viewport:o,content:r}}const{host:e,padding:r,viewport:i,content:s}=t;return w(e,"os-host"),w(r,"os-padding"),w(i,"os-viewport"),w(s,"os-content"),t},qt=(t,e,n)=>{const o=Tt(t),r=[],{host:i}=o;r.push($t(o));Lt(i,t=>{p(r,t?e=>{e.U&&e.U(t)}:t=>{t.Y&&t.Y()})},{R:!0,K:!0}),((t,e)=>{const n=A('<div class="os-trinsic-observer"></div>')[0],o=[],r=D(t=>0===t.h||t.isIntersecting||t.intersectionRatio>0,{p:!1});if(rt){const i=new rt(t=>{if(t&&t.length>0){const n=t.pop();if(n){const t=r(0,n);t.m&&e(!1,t)}}},{root:t});i.observe(n),o.push(()=>i.disconnect())}else o.push(Lt(n,()=>{const t=k(n),o=r(0,t);o.m&&e(!1,o)}));O(t,n)})(i,(t,e)=>{p(r,n=>{n.G&&n.G(t,e)})})};export default()=>[zt(),qt(document.body),A(' <div class="os-host"> <div class="os-resize-observer-host"></div> <div class="os-padding"> <div class="os-viewport"> <div class="os-content"> fdfhdfgh </div> </div> </div> <div class="os-scrollbar os-scrollbar-horizontal"> <div class="os-scrollbar-track"> <div class="os-scrollbar-handle"></div> </div> </div> <div class="os-scrollbar os-scrollbar-vertical"> <div class="os-scrollbar-track"> <div class="os-scrollbar-handle"></div> </div> </div> <div class="os-scrollbar-corner"></div> </div>')];