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