mirror of
https://github.com/tenrok/OverlayScrollbars.git
synced 2026-06-20 23:30:35 +03:00
1 line
13 KiB
JavaScript
1 line
13 KiB
JavaScript
!function(n,r){"object"==typeof exports&&"undefined"!=typeof module?module.exports=r():"function"==typeof define&&define.amd?define(r):(n="undefined"!=typeof globalThis?globalThis:n||self).OverlayScrollbars=r()}(this,(function(){"use strict";var n=function(n){return null==n?""+n:Object.prototype.toString.call(n).replace(/^\[object (.+)\]$/,"$1").toLowerCase()};function r(n){return"number"==typeof n}function t(n){return"string"==typeof n}function i(n){return"function"==typeof n}function e(n){return void 0===n}function o(n){return null===n}function u(n){return Array.isArray(n)}function c(n){return"object"==typeof n&&!u(n)&&!o(n)}function f(n){var t=!!n&&n.length;return u(n)||!i(n)&&r(t)&&t>-1&&t%1==0}function a(r){if(!r||!c(r)||"object"!==n(r))return!1;var t,i=Object.prototype.hasOwnProperty,o=i.call(r,"constructor"),u=r.constructor&&r.constructor.prototype&&i.call(r.constructor.prototype,"isPrototypeOf");if(r.constructor&&!o&&!u)return!1;for(t in r);return e(t)||i.call(r,t)}function s(n,r,t,i){if(e(i))return t?t[n]:r;t&&(t[n]=i)}var l=function(n,r){null==n||n.removeAttribute(r)};function v(n,r){return s("scrollLeft",0,n,r)}function d(n,r){return s("scrollTop",0,n,r)}var b=/[^\x20\t\r\n\f]+/g,h=function(n,r){!function(n,r,i){var e,o=0,u=!1;if(n&&t(r)){var c=r.match(b)||[];for(u=c.length>0;e=c[o++];)u=i(n.classList,e)&&u}}(n,r,(function(n,r){return n.add(r)}))};function p(n,r){if(f(n))for(var t=0;t<n.length&&!1!==r(n[t],t,n);t++);else n&&p(Object.keys(n),(function(t){return r(n[t],t,n)}));return n}var w,m=function(n){if(Array.from)return Array.from(n);var r=[];return p(n,(function(n){r.push(n)})),r},g=function(n){n instanceof Set?n.forEach((function(n){return n&&n()})):p(n,(function(n){return n&&n()}))},_=function(n,r){return function(n,r){return!!n&&(Element.prototype.matches||Element.prototype.msMatchesSelector).call(n,r)}(n,r)},y=function(n){return n?m(n.childNodes):[]},x=function(n,r,t){if(t){var i,e=r;n&&(f(t)?(i=document.createDocumentFragment(),p(t,(function(n){n===e&&(e=n.previousSibling),i.appendChild(n)}))):i=t,r&&(e?e!==r&&(e=e.nextSibling):e=n.firstChild),n.insertBefore(i,e))}},z=function(n,r){x(n,null,r)},O=function(n,r){x(n,n&&n.firstChild,r)},j=function n(r){if(f(r))p(m(r),(function(r){return n(r)}));else if(r){var t=(i=r)?i.parentElement:null;t&&t.removeChild(r)}var i},S=function(n){var r=document.createElement("div");return n&&function(n,r,t){if(e(t))return n?n.getAttribute(r):null;n&&n.setAttribute(r,t)}(r,"class",n),r},A=function(n){var r=S();return r.innerHTML=n.trim(),p(y(r),(function(n){return j(n)}))},T={w:0,h:0},k=function(){return{w:window.innerWidth,h:window.innerHeight}},L=function(n){return n?{w:n.offsetWidth,h:n.offsetHeight}:T},q=function(n,r,t,i){p(r.split(" "),(function(r){n.removeEventListener(r,t,i)}))},E=function(n,r,t,i){var e=function(){if(void 0===w){w=!1;try{window.addEventListener("test",null,Object.defineProperty({},"passive",{get:function(){w=!0}}))}catch(n){}}return w}(),o=e&&i&&i.o||!1,u=i&&i.u||!1,c=i&&i.s||!1,f=[],a=e?{passive:o,capture:u}:u;return p(r.split(" "),(function(r){var i=c?function(e){n.removeEventListener(r,i,u),t&&t(e)}:t;f.push(q.bind(null,n,r,i,u)),n.addEventListener(r,i,a)})),g.bind(0,f)},M=function(n){return n.stopPropagation()},F=function(n){return n.preventDefault()},I=function(n,r,t){if(n&&r){var i=!0;return p(t,(function(t){n[t]!==r[t]&&(i=!1)})),i}return!1},P=function(n,r){return I(n,r,["w","h"])},B=function(n,r){return I(n,r,["t","r","b","l"])},C=function(n,r){return Object.prototype.hasOwnProperty.call(n,r)},N=function(n){return n?Object.keys(n):[]};function R(n,r,t,e,c,f,s){var l=[r,t,e,c,f,s];return"object"==typeof n&&!o(n)||i(n)||(n={}),p(l,(function(r){p(N(r),(function(t){var i=r[t];if(n===i)return!0;var e=u(i);if(i&&(a(i)||e)){var o=n[t],c=o;e&&!u(o)?c=[]:e||a(o)||(c={}),n[t]=R(c,i)}else n[t]=i}))})),n}var V={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},Y=function(n,r){var t=r?parseFloat(n):parseInt(n,10);return Number.isNaN(t)?0:t},$=function(n,r,t){return null!=r?r.getPropertyValue(t):n.style[t]},D=function(n,t,i){try{n&&void 0!==n.style[t]&&(n.style[t]=function(n,t){return!V[n.toLowerCase()]&&r(t)?t+"px":t}(t,i))}catch(e){}};function G(n,r){var i=t(r);if(u(r)||i){var e=i?"":{};if(n){var o=window.getComputedStyle(n,null);e=i?$(n,o,r):r.reduce((function(r,t){return r[t]=$(n,o,t),r}),e)}return e}p(N(r),(function(t){return D(n,t,r[t])}))}var J={x:0,y:0},K=function(n){var r=n?function(n){return n.getBoundingClientRect()}(n):0;return r?{x:r.left+window.pageYOffset,y:r.top+window.pageXOffset}:J},U=function(n,r){var t,i=r||{},e=i.v,o=i.p;return function(r,i){var u=o,c=n(i,o,t),f=r||(e?!e(u,c):u!==c);return f&&(o=c,t=u),{m:o,g:t,_:f}}},W=function(n){return n.charAt(0).toUpperCase()+n.slice(1)},X=["-webkit-","-moz-","-o-","-ms-"],H=["WebKit","Moz","O","MS","webkit","moz","o","ms"],Q={},Z={},nn=function(n){var r=Z[n];if(C(Z,n))return r;var t=W(n),i=S().style;return p(X,(function(e){var o=e.replace(/-/g,""),u=[n,e+n,o+t,W(o)+t];return!(r=u.find((function(n){return void 0!==i[n]})))})),Z[n]=r,r},rn=function(n){var r=Q[n]||window[n];return C(Q,n)||(p(H,(function(t){return!(r=r||window[t+W(n)])})),Q[n]=r),r};rn("ResizeObserver");var tn,en=function(n,r,t){return n(t={path:r,exports:{},require:function(n,r){return function(){throw new Error("Dynamic requires are not currently supported by @rollup/plugin-commonjs")}(null==r&&t.path)}},t.exports),t.exports}((function(n){function r(){return n.exports=r=Object.assign||function(n){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&(n[i]=t[i])}return n},r.apply(this,arguments)}n.exports=r})),on=JSON.stringify,un=["__TPL_","_TYPE__"],cn=["boolean","number","string","array","object","function","null"].reduce((function(n,r){return n[r]=un[0]+r+un[1],n}),{}),fn=function(r,i,o,c){return function r(i,o,c,f,s){var l={},v=en({},i);return p(N(o).filter((function(n){return C(i,n)})),(function(d){var b=e(c[d])?{}:c[d],h=i[d],w=o[d],m=a(w),g=s?s+".":"";if(m&&a(h)){var _=r(h,w,b,f,g+d);l[d]=_.O,v[d]=_.j,p([v,l],(function(n){(function(n){for(var r in n)return!1;return!0})(n[d])&&delete n[d]}))}else if(!m){var y=!1,x=[],z=[],O=n(h);if(p(u(w)?w:[w],(function(n){var r;p(cn,(function(t,i){t===n&&(r=i)}));var i=void 0===r;if(i&&t(h)){var e=n.split(" ");y=!!e.find((function(n){return n===h})),x.push.apply(x,e)}else y=cn[O]===n;return z.push(i?cn.string:r),!y})),y)(u(h)||a(h)?on(h)!==on(b):h!==b)&&(l[d]=h);else f&&console.warn('The option "'+g+d+"\" wasn't set, because it doesn't accept the type [ "+O.toUpperCase()+' ] with the value of "'+h+'".\r\nAccepted types are: [ '+z.join(", ").toUpperCase()+" ].\r\n"+(x.length>0?"\r\nValid strings are: [ "+x.join(", ")+" ].":""));delete v[d]}})),{j:v,O:l}}(r,i,o||{},c||!1)};var an=Math.abs,sn=Math.round,ln=function(n,r){z(n,r);var t,i=(t=r)?{w:t.clientWidth,h:t.clientHeight}:T,e=L(r);return{x:e.h-i.h,y:e.w-i.w}},vn=function(n){var r=!1;h(n,"os-viewport-scrollbar-styled");try{r="none"===G(n,"scrollbar-width")||"none"===window.getComputedStyle(n,"::-webkit-scrollbar").getPropertyValue("display")}catch(t){}return r},dn=function(n,r){G(n,{overflowX:"hidden",overflowY:"hidden",direction:"rtl"}),v(n,0);var t=K(n),i=K(r);v(n,-999);var e=K(r);return{i:t.x===i.x,n:i.x!==e.x}},bn=function(n,r){h(n,"flexbox-glue");var t=L(n),i=L(r),e=P(i,t);h(n,"flexbox-glue-max");var o=L(n),u=L(r),c=P(u,o);return e&&c},hn=function(){var n=window.screen.deviceXDPI||0,r=window.screen.logicalXDPI||1;return window.devicePixelRatio||n/r},pn=function(){var n=document.body,r=A('<div id="os-environment"><div></div></div>')[0],t=r.firstChild,i=new Set,e=ln(n,r),o={x:0===e.x,y:0===e.y},u={S:!1,A:e,T:o,k:vn(r),L:dn(r,t),q:bn(r,t),M:function(n){i.add(n)},F:function(n){i.delete(n)}};if(l(r,"style"),l(r,"class"),j(r),!o.x||!o.y){var c=k(),f=hn(),a=e;window.addEventListener("resize",(function(){if(i.size){var t=k(),e={w:t.w-c.w,h:t.h-c.h};if(0===e.w&&0===e.h)return;var o={w:an(e.w),h:an(e.h)},u={w:an(sn(t.w/(c.w/100))),h:an(sn(t.h/(c.h/100)))},s=hn(),l=o.w>2&&o.h>2,v=(b=u.h,h=an(u.w),p=an(b),!(h!==p&&h+1!==p&&h-1!==p));if(l&&v&&(s!==f&&f>0)){var d=tn.A=ln(n,r);j(r),a.x===d.x&&a.y===d.y||g(i),a=d}c=t,f=s}var b,h,p}))}return u},wn=function(){return tn||(tn=pn()),tn},mn=function(n,r){return n&&r.split(".").reduce((function(n,r){return n&&C(n,r)?n[r]:void 0}),n)},gn=function(n,r,t){var i=function n(r){var t={I:{},P:{}};return p(N(r),(function(i){var e=r[i];if(u(e))t.I[i]=e[1],t.P[i]=e[0];else{var o=n(e);t.I[i]=o.I,t.P[i]=o.P}})),t}(n),e=i.I,o=R({},i.P,fn(r||{},e,null,!0).O),c=function(n){var r=n.B,i=n.C;t(!!r,(function(n){return{m:mn(o,n),_:r||void 0!==mn(i,n)}}))};return c({B:!0}),{P:function(n){if(n){var r=fn(n,e,o,!0).O;R(o,r),c({C:r})}return o},N:function(n){c({B:n})}}},_n={paddingAbsolute:[!1,cn.boolean],overflowBehavior:{x:["scroll","visible-hidden visible-scroll scroll hidden"],y:["scroll","visible-hidden visible-scroll scroll hidden"]}},yn=nn("margin-inline-end"),xn=nn("border-inline-end"),zn=function(n,r){var t=n.host,i=n.padding,e=(n.viewport,n.content),o=[],u=wn(),c=u.T,f=u.k,a=(u.q,yn&&xn||f||c.y,U((function(){return u=G(t,[r=(n="padding"||"")+"-top",i=n+"-right",e=n+"-bottom",o=n+"-left"]),{t:Y(u[r]),r:Y(u[i]),b:Y(u[e]),l:Y(u[o])};var n,r,i,e,o,u}),{v:B})),s=gn(_n,r,(function(n,r){var t=r("paddingAbsolute"),e=t.m,o=t._,c=a(n),s=c.m,l=c._;if(o||l){var v={t:0,r:0,b:0,l:0};e||(v.t=-s.t,v.r=-(s.r+s.l),v.b=-(s.b+s.t),v.l=-s.l),f||(v.r-=u.A.y,v.b-=u.A.x),G(i,{top:v.t,left:v.l,"margin-right":v.r,"margin-bottom":v.b,"max-width":"calc(100% + "+-1*v.r+"px)"})}})),l=s.P,v=s.N;return{P:l,N:v,R:function(){v()},V:function(n,r){var t=r._,i=r.m;t&&G(e,{height:i?"auto":"100%"})},Y:function(){g(o)}}},On=rn("ResizeObserver"),jn=cancelAnimationFrame,Sn=requestAnimationFrame,An=function(n){return G(n,"direction")},Tn=function(n,r,i){var e=i||{},o=e.$,u=void 0!==o&&o,c=e.D,f=void 0!==c&&c,a=wn().L,s=A('<div class="os-size-observer"><div class="os-size-observer-listener"></div></div>')[0],l=s.firstChild,b=function(n){if(u){var i="rtl"===An(s);v(s,i?a.n?-3333333:a.i?0:3333333:3333333),d(s,3333333)}r(t((n||{}).m)?n:void 0)},p=[],w=f?b:null;if(On){var m=new On(b);m.observe(l),p.push((function(){return m.disconnect()}))}else{var _=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,_),h(l,"os-size-observer-listener-scroll");var y,x=_[0],S=x.lastChild,T=x.firstChild,k=null==T?void 0:T.firstChild,q=L(l),I=q,B=!1,C=function(){v(T,3333333),d(T,3333333),v(S,3333333),d(S,3333333)},N=function(){y=0,B&&(q=I,b())},R=function(n){return I=L(l),B=!n||!P(I,q),n&&B&&!y?(jn(y),y=Sn(N)):n||N(),C(),n&&(F(n),M(n)),!1};p.push(E(T,"scroll",R)),p.push(E(S,"scroll",R)),G(k,{width:3333333,height:3333333}),C(),w=f?function(){return R()}:C}if(u){var V=U((function(){return An(s)}));p.push(E(s,"scroll",(function(n){var r=V(),t=r.m;return r._&&(G(l,"rtl"===t?{left:"auto",right:0}:{left:0,right:"auto"}),b(r)),F(n),M(n),!1})))}return w&&(h(s,"os-size-observer-appear"),p.push(E(s,"animationstart",w))),O(n,s),function(){g(p),j(s)}},kn=rn("IntersectionObserver"),Ln=function(n){if(f=n,c(a=window.HTMLElement)||i(a)?f instanceof a:f&&c(f)&&1===f.nodeType&&t(f.nodeName)){var r=_(n,"textarea")?S():n,e=S("os-padding"),o=S("os-viewport"),u=S("os-content");return z(e,o),z(o,u),z(u,y(n)),z(n,e),h(r,"os-host"),{target:n,host:r,padding:e,viewport:o,content:u}}var f,a,s=n.host,l=n.padding,v=n.viewport,d=n.content;return h(s,"os-host"),h(l,"os-padding"),h(v,"os-viewport"),h(d,"os-content"),n},qn=function(n,r,t){var i=Ln(n),e=[],o=i.host;e.push(zn(i));Tn(o,(function(n){p(e,n?function(r){r.G&&r.G(n)}:function(n){n.R&&n.R()})}),{D:!0,$:!0}),function(n,r){var t=A('<div class="os-trinsic-observer"></div>')[0],i=[],e=U((function(n){return 0===n.h||n.isIntersecting||n.intersectionRatio>0}),{p:!1});if(kn){var o=new kn((function(n){if(n&&n.length>0){var t=n.pop();if(t){var i=e(0,t);i._&&r(!1,i)}}}),{root:n});o.observe(t),i.push((function(){return o.disconnect()}))}else i.push(Tn(t,(function(){var n=L(t),i=e(0,n);i._&&r(!1,i)})));O(n,t)}(o,(function(n,r){p(e,(function(t){t.V&&t.V(n,r)}))}))};return function(){return[wn(),qn(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>')]}})); |