mirror of
https://github.com/tenrok/OverlayScrollbars.git
synced 2026-06-22 17:40:37 +03:00
1 line
5.4 KiB
JavaScript
1 line
5.4 KiB
JavaScript
function n(n){return"number"==typeof n}function r(n){return"string"==typeof n}function t(n){return Array.isArray(n)}function o(r){const o=!!r&&r.length;return t(r)||!function(n){return"function"==typeof n}(r)&&n(o)&&o>-1&&o%1==0}function e(n,r){return function(n,r,t,o){if(void 0===o)return t?t[n]:r;t&&(t[n]=o)}("scrollLeft",0,n,r)}const i=/[^\x20\t\r\n\f]+/g,s=(n,t)=>{((n,t,o)=>{let e,s=0,c=!1;if(n&&r(t)){const r=t.match(i)||[];for(c=r.length>0;e=r[s++];)c=o(n.classList,e)&&c}})(n,t,(n,r)=>n.add(r))};function c(n,r){if(o(n))for(let t=0;t<n.length&&!1!==r(n[t],t,n);t++);else n&&c(Object.keys(n),t=>r(n[t],t,n));return n}const l=n=>{if(Array.from)return Array.from(n);const r=[];return c(n,n=>{r.push(n)}),r},a=(n,r)=>{((n,r,t)=>{if(t){let e,i=r;n&&(o(t)?(e=document.createDocumentFragment(),c(t,n=>{n===i&&(i=n.previousSibling),e.appendChild(n)})):e=t,r&&(i?i!==r&&(i=i.nextSibling):i=n.firstChild),n.insertBefore(e,i))}})(n,null,r)},d=n=>{if(o(n))c(l(n),n=>d(n));else if(n){const t=(r=n)?r.parentElement:null;t&&t.removeChild(n)}var r},u=n=>{const r=document.createElement("div");return r.innerHTML=n.trim(),c((t=r)?l(t.childNodes):[],n=>d(n));var t},v={w:0,h:0},f=()=>({w:window.innerWidth,h:window.innerHeight}),w={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},h=(n,r,t)=>null!=r?r.getPropertyValue(t):n.style[t],b=(r,t,o)=>{try{r&&void 0!==r.style[t]&&(r.style[t]=((r,t)=>!w[r.toLowerCase()]&&n(t)?t+"px":t)(t,o))}catch(e){}};function p(n,o){const e=r(o);if(t(o)||e){let r=e?"":{};if(n){const t=window.getComputedStyle(n,null);r=e?h(n,t,o):o.reduce((r,o)=>(r[o]=h(n,t,o),r),r)}return r}var i;c((i=o)?Object.keys(i):[],r=>b(n,r,o[r]))}const y={x:0,y:0},m=n=>{const r=n?(n=>n.getBoundingClientRect())(n):0;return r?{x:r.left+window.pageYOffset,y:r.top+window.pageXOffset}:y};var g=function(n,r){var t=r.get(n);if(!t)throw new TypeError("attempted to get private field on non-instance");return t.get?t.get.call(n):t.value};var x=function(n,r,t){var o=r.get(n);if(!o)throw new TypeError("attempted to set private field on non-instance");if(o.set)o.set.call(n,t);else{if(!o.writable)throw new TypeError("attempted to set read only private field");o.value=t}return t};const z=["WebKit","Moz","O","MS","webkit","moz","o","ms"],O={},j=n=>{let r=O[n]||window[n];return t=O,o=n,Object.prototype.hasOwnProperty.call(t,o)||(c(z,t=>{var o;return r=r||window[t+(o=n,o.charAt(0).toUpperCase()+o.slice(1))],!r}),O[n]=r),r;var t,o};j("ResizeObserver");!function(n,r,t){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 o in t)Object.prototype.hasOwnProperty.call(t,o)&&(n[o]=t[o])}return n},r.apply(this,arguments)}n.exports=r}));const k=["__TPL_","_TYPE__"],{abs:_,round:E}=(["boolean","number","string","array","object","function","null"].reduce((n,r)=>(n[r]=k[0]+r+k[1],n),{}),Math),T=(n,r)=>{a(n,r);const t=(o=r)?{w:o.clientWidth,h:o.clientHeight}:v;var o;const e=(n=>n?{w:n.offsetWidth,h:n.offsetHeight}:v)(r);return{x:e.h-t.h,y:e.w-t.w}},L=()=>{const n=window.screen.deviceXDPI||0,r=window.screen.logicalXDPI||1;return window.devicePixelRatio||n/r};var M=new WeakMap;class A{constructor(){M.set(this,{writable:!0,value:void 0}),x(this,M,new Set);const n=this,{body:r}=document,t=u('<div id="os-envornment"><div></div></div>')[0],o=t.firstChild,i=T(r,t),c={x:0===i.x,y:0===i.y};var l,a;if(n.t=!1,n.o=i,n.s=c,n.l=(n=>{let r=!1;s(n,"os-viewport-native-scrollbars-invisible");try{r="none"===p(n,"scrollbar-width")||"none"===window.getComputedStyle(n,"::-webkit-scrollbar").getPropertyValue("display")}catch(t){}return r})(t),n.u=((n,r)=>{p(n,{overflowX:"hidden",overflowY:"hidden",direction:"rtl"}),e(n,0);const t=m(n),o=m(r);e(n,-999);const i=m(r);return{i:t.x===o.x,n:o.x!==i.x}})(t,o),n.v=(()=>{let n=!1;try{window.addEventListener("test",null,Object.defineProperty({},"passive",{get:function(){n=!0}}))}catch(r){}return n})(),n.p=!!j("ResizeObserver"),a="style",null==(l=t)||l.removeAttribute(a),d(t),!c.x||!c.y){let o=f(),e=L();const i=g(this,M);window.addEventListener("resize",()=>{if(i.size){const s=f(),c={w:s.w-o.w,h:s.h-o.h};if(0===c.w&&0===c.h)return;const l={w:_(c.w),h:_(c.h)},a={w:_(E(s.w/(o.w/100))),h:_(E(s.h/(o.h/100)))},u=L(),v=l.w>2&&l.h>2,w=!((n,r)=>{const t=_(n),o=_(r);return!(t===o||t+1===o||t-1===o)})(a.w,a.h),h=u!==e&&e>0,b=v&&w&&h,p=n.o;let y;b&&(y=n.o=T(r,t),d(t),p.x===y.x&&p.y===y.y||i.forEach(r=>r&&r(n))),o=s,e=u}})}}addListener(n){g(this,M).add(n)}removeListener(n){g(this,M).delete(n)}}export default()=>[new A,u(' <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>')]; |