mirror of
https://github.com/tenrok/OverlayScrollbars.git
synced 2026-06-22 03:10:37 +03:00
1 line
12 KiB
JavaScript
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,e,n,o){if(r(o))return n?n[t]:e;n&&(n[t]=o)}const u=(t,e)=>{null==t||t.removeAttribute(e)};function v(t,e){return d("scrollLeft",0,t,e)}function f(t,e){return d("scrollTop",0,t,e)}const h=/[^\x20\t\r\n\f]+/g,p=(t,e)=>{((t,e,o)=>{let r,i=0,s=!1;if(t&&n(e)){const n=e.match(h)||[];for(s=n.length>0;r=n[i++];)s=o(t.classList,r)&&s}})(t,e,(t,e)=>t.add(e))};function b(t,e){if(l(t))for(let n=0;n<t.length&&!1!==e(t[n],n,t);n++);else t&&b(Object.keys(t),n=>e(t[n],n,t));return t}const w=t=>{if(Array.from)return Array.from(t);const e=[];return b(t,t=>{e.push(t)}),e},_=t=>{t instanceof Set?t.forEach(t=>t&&t()):b(t,t=>t&&t())},g=(t,e)=>((t,e)=>{if(t){return(Element.prototype.matches||Element.prototype.msMatchesSelector).call(t,e)}return!1})(t,e),m=t=>t?w(t.childNodes):[],y=(t,e,n)=>{if(n){let o,r=e;t&&(l(n)?(o=document.createDocumentFragment(),b(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))}},x=(t,e)=>{y(t,null,e)},z=(t,e)=>{y(t,t&&t.firstChild,e)},O=t=>{if(l(t))b(w(t),t=>O(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},S=t=>{const e=j();return e.innerHTML=t.trim(),b(m(e),t=>O(t))},$={w:0,h:0},A=()=>({w:window.innerWidth,h:window.innerHeight}),k=t=>t?{w:t.offsetWidth,h:t.offsetHeight}:$;let q;const L=(t,e,n,o)=>{b(e.split(" "),e=>{t.removeEventListener(e,n,o)})},T=(t,e,n,o)=>{const r=(()=>{if(void 0===q){q=!1;try{window.addEventListener("test",null,Object.defineProperty({},"passive",{get:function(){q=!0}}))}catch(t){}}return q})(),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 b(e.split(" "),e=>{const o=c?r=>{t.removeEventListener(e,o,s),n&&n(r)}:n;l.push(L.bind(null,t,e,o,s)),t.addEventListener(e,o,a)}),_.bind(0,l)},E=t=>t.stopPropagation(),P=t=>t.preventDefault(),F=(t,e,n)=>{if(t&&e){let o=!0;return b(n,n=>{t[n]!==e[n]&&(o=!1)}),o}return!1},I=(t,e)=>F(t,e,["w","h"]),M=(t,e)=>F(t,e,["t","r","b","l"]),V=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),B=t=>t?Object.keys(t):[];function C(t,e,n,r,c,l,d){const u=[e,n,r,c,l,d];return"object"==typeof t&&!i(t)||o(t)||(t={}),b(u,e=>{b(B(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]=C(i,o)}else t[n]=o})}),t}const N={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},R=(t,e)=>{const n=e?parseFloat(t):parseInt(t,10);return Number.isNaN(n)?0:n},Y=(t,e,n)=>null!=e?e.getPropertyValue(n):t.style[n],D=(t,n,o)=>{try{t&&void 0!==t.style[n]&&(t.style[n]=((t,n)=>!N[t.toLowerCase()]&&e(n)?n+"px":n)(n,o))}catch(r){}};function G(t,e){const o=n(e);if(s(e)||o){let n=o?"":{};if(t){const r=window.getComputedStyle(t,null);n=o?Y(t,r,e):e.reduce((e,n)=>(e[n]=Y(t,r,n),e),n)}return n}b(B(e),n=>D(t,n,e[n]))}const J={x:0,y:0},K=t=>{const e=t?(t=>t.getBoundingClientRect())(t):0;return e?{x:e.left+window.pageYOffset,y:e.top+window.pageXOffset}:J},U=(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}}},W=t=>t.charAt(0).toUpperCase()+t.slice(1),X=["-webkit-","-moz-","-o-","-ms-"],H=["WebKit","Moz","O","MS","webkit","moz","o","ms"],Q={},Z={},tt=t=>{let e=Z[t];if(V(Z,t))return e;const n=W(t),o=j().style;return b(X,r=>{const i=r.replace(/-/g,""),s=[t,r+t,i+n,W(i)+n];return e=s.find(t=>void 0!==o[t]),!e}),Z[t]=e,e},et=t=>{let e=Q[t]||window[t];return V(Q,t)||(b(H,n=>(e=e||window[n+W(t)],!e)),Q[t]=e),e};et("ResizeObserver");var nt=function(t,e,n){return t(n={path:e,exports:{},require:function(t,e){return function(){throw new Error("Dynamic requires are not currently supported by @rollup/plugin-commonjs")}(null==e&&n.path)}},n.exports),n.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:ot}=JSON,rt=["__TPL_","_TYPE__"],it=["boolean","number","string","array","object","function","null"].reduce((t,e)=>(t[e]=rt[0]+e+rt[1],t),{}),st=(e,o,i,c,l)=>{const d={},u=nt({},e);return b(B(o).filter(t=>V(e,t)),v=>{const f=r(i[v])?{}:i[v],h=e[v],p=o[v],w=a(p),_=l?l+".":"";if(w&&a(h)){const t=st(h,p,f,c,_+v);d[v]=t.O,u[v]=t.j,b([u,d],t=>{(function(t){for(const e in t)return!1;return!0})(t[v])&&delete t[v]})}else if(!w){let e=!1;const o=[],r=[],i=t(h);if(b(s(p)?p:[p],t=>{let s;b(it,(e,n)=>{e===t&&(s=n)});const c=void 0===s;if(c&&n(h)){const n=t.split(" ");e=!!n.find(t=>t===h),o.push(...n)}else e=it[i]===t;return r.push(c?it.string:s),!e}),e){(s(h)||a(h)?ot(h)!==ot(f):h!==f)&&(d[v]=h)}else c&&console.warn(`The option "${_}${v}" wasn't set, because it doesn't accept the type [ ${i.toUpperCase()} ] with the value of "${h}".\r\nAccepted types are: [ ${r.join(", ").toUpperCase()} ].\r\n${o.length>0?`\r\nValid strings are: [ ${o.join(", ")} ].`:""}`);delete u[v]}}),{j:u,O:d}},ct=(t,e,n,o)=>st(t,e,n||{},o||!1);let lt;const{abs:at,round:dt}=Math,ut=(t,e)=>{x(t,e);const n=(o=e)?{w:o.clientWidth,h:o.clientHeight}:$;var o;const r=k(e);return{x:r.h-n.h,y:r.w-n.w}},vt=t=>{let e=!1;p(t,"os-viewport-scrollbar-styled");try{e="none"===G(t,"scrollbar-width")||"none"===window.getComputedStyle(t,"::-webkit-scrollbar").getPropertyValue("display")}catch(n){}return e},ft=(t,e)=>{G(t,{overflowX:"hidden",overflowY:"hidden",direction:"rtl"}),v(t,0);const n=K(t),o=K(e);v(t,-999);const r=K(e);return{i:n.x===o.x,n:o.x!==r.x}},ht=(t,e)=>{p(t,"flexbox-glue");const n=k(t),o=k(e),r=I(o,n);p(t,"flexbox-glue-max");const i=k(t),s=k(e),c=I(s,i);return r&&c},pt=()=>{const t=window.screen.deviceXDPI||0,e=window.screen.logicalXDPI||1;return window.devicePixelRatio||t/e},bt=()=>{const{body:t}=document,e=S('<div id="os-environment"><div></div></div>')[0],n=e.firstChild,o=new Set,r=ut(t,e),i={x:0===r.x,y:0===r.y},s={S:!1,$:r,A:i,k:vt(e),q:ft(e,n),L:ht(e,n),T(t){o.add(t)},P(t){o.delete(t)}};if(u(e,"style"),u(e,"class"),O(e),!i.x||!i.y){let n=A(),i=pt(),s=r;window.addEventListener("resize",()=>{if(o.size){const r=A(),c={w:r.w-n.w,h:r.h-n.h};if(0===c.w&&0===c.h)return;const l={w:at(c.w),h:at(c.h)},a={w:at(dt(r.w/(n.w/100))),h:at(dt(r.h/(n.h/100)))},d=pt(),u=l.w>2&&l.h>2,v=!((t,e)=>{const n=at(t),o=at(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=lt.$=ut(t,e);O(e),s.x===n.x&&s.y===n.y||_(o),s=n}n=r,i=d}})}return s},wt=()=>(lt||(lt=bt()),lt),_t=(t,e)=>t&&e.split(".").reduce((t,e)=>t&&V(t,e)?t[e]:void 0,t),gt=(t,e,n)=>{const{F:o,I:r}=function t(e){const n={F:{},I:{}};return b(B(e),o=>{const r=e[o];if(s(r))n.F[o]=r[1],n.I[o]=r[0];else{const e=t(r);n.F[o]=e.F,n.I[o]=e.I}}),n}(t),i=C({},r,ct(e||{},o,null,!0).O),c=t=>{const{M:e,V:o}=t;n(!!e,t=>({_:_t(i,t),m:e||void 0!==_t(o,t)}))};return c({M:!0}),{I(t){if(t){const{O:e}=ct(t,o,i,!0);C(i,e),c({V:e})}return i},B:t=>{c({M:t})}}},mt={paddingAbsolute:[!1,it.boolean],overflowBehavior:{x:["scroll","visible-hidden visible-scroll scroll hidden"],y:["scroll","visible-hidden visible-scroll scroll hidden"]}},yt=tt("margin-inline-end"),xt=tt("border-inline-end"),zt=(t,e)=>{const{host:n,padding:o,viewport:r,content:i}=t,s=[],c=wt(),l=c.A,a=c.k,d=(c.L,yt&&xt||a||l.y,U(()=>((t,e)=>{const n=e||"",o=n+"-top",r=n+"-right",i=n+"-bottom",s=n+"-left",c=G(t,[o,r,i,s]);return{t:R(c[o]),r:R(c[r]),b:R(c[i]),l:R(c[s])}})(n,"padding"),{v:M})),{I:u,B:v}=gt(mt,e,(t,e)=>{const{_:n,m:r}=e("paddingAbsolute"),{_:i,m:s}=d(t);if(r||s){const t={t:0,r:0,b:0,l:0};n||(t.t=-i.t,t.r=-(i.r+i.l),t.b=-(i.b+i.t),t.l=-i.l),a||(t.r-=c.$.y,t.b-=c.$.x),G(o,{top:t.t,left:t.l,"margin-right":t.r,"margin-bottom":t.b,"max-width":`calc(100% + ${-1*t.r}px)`})}});return{I:u,B:v,C:()=>{v()},N:(t,e)=>{const{m:n,_:o}=e;n&&G(i,{height:o?"auto":"100%"})},R(){_(s)}}},Ot=et("ResizeObserver"),jt=cancelAnimationFrame,St=requestAnimationFrame,$t=t=>G(t,"direction"),At=(t,e,o)=>{const{Y:r=!1,D:i=!1}=o||{},s=wt().q,c=S('<div class="os-size-observer"><div class="os-size-observer-listener"></div></div>')[0],l=c.firstChild,a=t=>{if(r){const t="rtl"===$t(c);v(c,t?s.n?-3333333:s.i?0:3333333:3333333),f(c,3333333)}e(n((t||{})._)?t:void 0)},d=[];let u=i?a:null;if(Ot){const t=new Ot(a);t.observe(l),d.push(()=>t.disconnect())}else{const t=S('<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>');x(l,t),p(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),h=c,b=!1;const w=()=>{v(o,3333333),f(o,3333333),v(n,3333333),f(n,3333333)},_=()=>{s=0,b&&(c=h,a())},g=t=>(h=k(l),b=!t||!I(h,c),t&&b&&!s?(jt(s),s=St(_)):t||_(),w(),t&&(P(t),E(t)),!1);d.push(T(o,"scroll",g)),d.push(T(n,"scroll",g)),G(r,{width:3333333,height:3333333}),w(),u=i?()=>g():w}if(r){const t=U(()=>$t(c));d.push(T(c,"scroll",e=>{const n=t(),{_:o,m:r}=n;return r&&(G(l,"rtl"===o?{left:"auto",right:0}:{left:0,right:"auto"}),a(n)),P(e),E(e),!1}))}return u&&(p(c,"os-size-observer-appear"),d.push(T(c,"animationstart",u))),z(t,c),()=>{_(d),O(c)}},kt=et("IntersectionObserver"),qt=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=g(t,"textarea")?j():t,n=j("os-padding"),o=j("os-viewport"),r=j("os-content");return x(n,o),x(o,r),x(r,m(t)),x(t,n),p(e,"os-host"),{target:t,host:e,padding:n,viewport:o,content:r}}const{host:e,padding:r,viewport:i,content:s}=t;return p(e,"os-host"),p(r,"os-padding"),p(i,"os-viewport"),p(s,"os-content"),t},Lt=(t,e,n)=>{const o=qt(t),r=[],{host:i}=o;r.push(zt(o));At(i,t=>{b(r,t?e=>{e.G&&e.G(t)}:t=>{t.C&&t.C()})},{D:!0,Y:!0}),((t,e)=>{const n=S('<div class="os-trinsic-observer"></div>')[0],o=[],r=U(t=>0===t.h||t.isIntersecting||t.intersectionRatio>0,{p:!1});if(kt){const i=new kt(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(At(n,()=>{const t=k(n),o=r(0,t);o.m&&e(!1,o)}));z(t,n)})(i,(t,e)=>{b(r,n=>{n.N&&n.N(t,e)})})};export default()=>[wt(),Lt(document.body),S(' <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>')]; |