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