mirror of
https://github.com/tenrok/OverlayScrollbars.git
synced 2026-06-22 00:20:38 +03:00
1 line
7.4 KiB
JavaScript
1 line
7.4 KiB
JavaScript
function r(r){return"number"==typeof r}function t(r){return"string"==typeof r}function e(r){return Array.isArray(r)}function n(t){const n=!!t&&t.length;return e(t)||!function(r){return"function"==typeof r}(t)&&r(n)&&n>-1&&n%1==0}function o(r,t,e,n){if(void 0===n)return e?e[r]:t;e&&(e[r]=n)}const i=(r,t)=>{null==r||r.removeAttribute(t)};function s(r,t){return o("scrollLeft",0,r,t)}function l(r,t){return o("scrollTop",0,r,t)}const c=/[^\x20\t\r\n\f]+/g,a=(r,e)=>{((r,e,n)=>{let o,i=0,s=!1;if(r&&t(e)){const t=e.match(c)||[];for(s=t.length>0;o=t[i++];)s=n(r.classList,o)&&s}})(r,e,(r,t)=>r.add(t))};function d(r,t){if(n(r))for(let e=0;e<r.length&&!1!==t(r[e],e,r);e++);else r&&d(Object.keys(r),e=>t(r[e],e,r));return r}const u=r=>{if(Array.from)return Array.from(r);const t=[];return d(r,r=>{t.push(r)}),t},v=r=>{r instanceof Set?r.forEach(r=>r&&r()):d(r,r=>r&&r())},f=(r,t,e)=>{if(e){let o,i=t;r&&(n(e)?(o=document.createDocumentFragment(),d(e,r=>{r===i&&(i=r.previousSibling),o.appendChild(r)})):o=e,t&&(i?i!==t&&(i=i.nextSibling):i=r.firstChild),r.insertBefore(o,i))}},w=(r,t)=>{f(r,null,t)},b=(r,t)=>{f(r,r&&r.firstChild,t)},h=r=>{if(n(r))d(u(r),r=>h(r));else if(r){const e=(t=r)?t.parentElement:null;e&&e.removeChild(r)}var t},m=r=>{const t=document.createElement("div");return t.innerHTML=r.trim(),d((e=t)?u(e.childNodes):[],r=>h(r));var e},p={w:0,h:0},y=()=>({w:window.innerWidth,h:window.innerHeight}),x=r=>r?{w:r.offsetWidth,h:r.offsetHeight}:p;let z;const g=(r,t,e,n)=>{d(t.split(" "),t=>{r.removeEventListener(t,e,n)})},_=(r,t,e,n)=>{const o=(()=>{if(void 0===z){z=!1;try{window.addEventListener("test",null,Object.defineProperty({},"passive",{get:function(){z=!0}}))}catch(r){}}return z})(),i=o&&n&&n.t||!1,s=n&&n.o||!1,l=n&&n.s||!1,c=[],a=o?{passive:i,capture:s}:s;return d(t.split(" "),t=>{const n=l?o=>{r.removeEventListener(t,n,s),e&&e(o)}:e;c.push(g.bind(null,r,t,n,s)),r.addEventListener(t,n,a)}),v.bind(0,c)},O=r=>r.stopPropagation(),S=r=>r.preventDefault(),j=(r,t)=>((r,t,e)=>{if(r&&t){let n=!0;return d(e,e=>{r[e]!==t[e]&&(n=!1)}),n}return!1})(r,t,["w","h"]),k={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},A=(r,t,e)=>null!=t?t.getPropertyValue(e):r.style[e],L=(t,e,n)=>{try{t&&void 0!==t.style[e]&&(t.style[e]=((t,e)=>!k[t.toLowerCase()]&&r(e)?e+"px":e)(e,n))}catch(o){}};function q(r,n){const o=t(n);if(e(n)||o){let t=o?"":{};if(r){const e=window.getComputedStyle(r,null);t=o?A(r,e,n):n.reduce((t,n)=>(t[n]=A(r,e,n),t),t)}return t}var i;d((i=n)?Object.keys(i):[],t=>L(r,t,n[t]))}const M={x:0,y:0},T=r=>{const t=r?(r=>r.getBoundingClientRect())(r):0;return t?{x:t.left+window.pageYOffset,y:t.top+window.pageXOffset}:M},E=["WebKit","Moz","O","MS","webkit","moz","o","ms"],F={},I=r=>{let t=F[r]||window[r];return e=F,n=r,Object.prototype.hasOwnProperty.call(e,n)||(d(E,e=>{var n;return t=t||window[e+(n=r,n.charAt(0).toUpperCase()+n.slice(1))],!t}),F[r]=t),t;var e,n};I("ResizeObserver");!function(r,t,e){r(e={path:t,exports:{},require:function(r,t){return function(){throw new Error("Dynamic requires are not currently supported by @rollup/plugin-commonjs")}(null==t&&e.path)}},e.exports),e.exports}((function(r){function t(){return r.exports=t=Object.assign||function(r){for(var t=1;t<arguments.length;t++){var e=arguments[t];for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(r[n]=e[n])}return r},t.apply(this,arguments)}r.exports=t}));const P=["__TPL_","_TYPE__"];["boolean","number","string","array","object","function","null"].reduce((r,t)=>(r[t]=P[0]+t+P[1],r),{});let R;const{abs:Y,round:B}=Math,D=(r,t)=>{w(r,t);const e=(n=t)?{w:n.clientWidth,h:n.clientHeight}:p;var n;const o=x(t);return{x:o.h-e.h,y:o.w-e.w}},G=r=>{let t=!1;a(r,"os-viewport-scrollbar-styled");try{t="none"===q(r,"scrollbar-width")||"none"===window.getComputedStyle(r,"::-webkit-scrollbar").getPropertyValue("display")}catch(e){}return t},K=(r,t)=>{q(r,{overflowX:"hidden",overflowY:"hidden",direction:"rtl"}),s(r,0);const e=T(r),n=T(t);s(r,-999);const o=T(t);return{i:e.x===n.x,n:n.x!==o.x}},U=(r,t)=>{a(r,"flexbox-glue");const e=x(r),n=x(t),o=j(n,e);a(r,"flexbox-glue-max");const i=x(r),s=x(t),l=j(s,i);return o&&l},W=()=>{const r=window.screen.deviceXDPI||0,t=window.screen.logicalXDPI||1;return window.devicePixelRatio||r/t},X=()=>{const{body:r}=document,t=m('<div id="os-environment"><div></div></div>')[0],e=t.firstChild,n=new Set,o=D(r,t),s={x:0===o.x,y:0===o.y},l={l:!1,u:o,v:s,m:G(t),p:K(t,e),g:U(t,e),_(r){n.add(r)},O(r){n.delete(r)}};if(i(t,"style"),i(t,"class"),h(t),!s.x||!s.y){let e=y(),i=W(),s=o;window.addEventListener("resize",()=>{if(n.size){const o=y(),l={w:o.w-e.w,h:o.h-e.h};if(0===l.w&&0===l.h)return;const c={w:Y(l.w),h:Y(l.h)},a={w:Y(B(o.w/(e.w/100))),h:Y(B(o.h/(e.h/100)))},d=W(),u=c.w>2&&c.h>2,f=!((r,t)=>{const e=Y(r),n=Y(t);return!(e===n||e+1===n||e-1===n)})(a.w,a.h),w=d!==i&&i>0;if(u&&f&&w){const e=R.u=D(r,t);h(t),s.x===e.x&&s.y===e.y||v(n),s=e}e=o,i=d}})}return l},C=()=>(R||(R=X()),R),H=I("ResizeObserver"),J=cancelAnimationFrame,N=requestAnimationFrame,Q=r=>q(r,"direction"),V=(r,e,n)=>{const{S:o=!1,j:i=!1}=n||{},c=C().p,d=m('<div class="os-size-observer"><div class="os-size-observer-listener"></div></div>')[0],u=d.firstChild,f=r=>{if(o){const r="rtl"===Q(d);s(d,r?c.n?-3333333:c.i?0:3333333:3333333),l(d,3333333)}e(t(r)?r:void 0)},p=[];let y=i?f:null;if(H){const r=new H(f);r.observe(u),p.push(()=>r.disconnect())}else{const r=m('<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>');w(u,r);const t=r[0],e=t.lastChild,n=t.firstChild,o=null==n?void 0:n.firstChild;let c,a=x(u),d=a,v=!1;const b=()=>{s(n,3333333),l(n,3333333),s(e,3333333),l(e,3333333)},h=function(){c=0,v&&(a=d,f())},z=r=>(d=x(u),v=!r||!j(d,a),r&&v&&!c?(J(c),c=N(h)):r||h(),b(),r&&(S(r),O(r)),!1);p.push(_(n,"scroll",z)),p.push(_(e,"scroll",z)),q(o,{width:3333333,height:3333333}),b(),y=i?z:b}if(o){let r;p.push(_(d,"scroll",t=>{const e=Q(d);return e!==r&&(q(u,"rtl"===e?{left:"auto",right:0}:{left:0,right:"auto"}),r=e,f(e)),S(t),O(t),!1}))}return y&&(a(d,"os-size-observer-appear"),p.push(_(d,"animationstart",y))),b(r,d),()=>{v(p),h(d)}},Z=I("IntersectionObserver"),$=(r,t)=>{const e=m('<div class="os-trinsic-observer"></div>')[0],n=[];let o=!1;if(Z){const i=new Z(r=>{if(r&&r.length>0){const e=r.pop();if(e){const r=e.isIntersecting||e.intersectionRatio>0;r!==o&&(t(!1,r),o=r)}}},{root:r});i.observe(e),n.push(()=>i.disconnect())}else n.push(V(e,()=>{const r=0===x(e).h;r!==o&&(t(!1,r),o=r)}));return b(r,e),()=>{v(n),h(e)}};export default()=>[C(),V(document.body,()=>{}),$(document.body,()=>{}),m(' <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>')]; |