UNPKG

ucc-utils

Version:
1 lines 2.19 kB
function e(e){"@swc/helpers - typeof";return e&&typeof Symbol!=="undefined"&&e.constructor===Symbol?"symbol":typeof e}import"../chunk-JZXLCA2E.mjs";import{debounce as t,throttle as n,isFunction as o,isNil as i}from"lodash-es";import{onMounted as r,isRef as d,onUnmounted as u}from"vue";var l=function(){return{}},s=l;var c={count:0};function a(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};var t=e.isOrderly,n=t===void 0?!0:t;return n?++c.count+"":Math.random().toString(36).substr(2,9)}var f=(typeof window==="undefined"?"undefined":e(window))=="object"&&window.Object===Object?window:(typeof globalThis==="undefined"?"undefined":e(globalThis))=="object"&&globalThis.Object===Object?globalThis:(typeof global==="undefined"?"undefined":e(global))=="object"&&global.Object===Object?global:(typeof self==="undefined"?"undefined":e(self))=="object"&&self.Object===Object?self:Function("return this")();function v(e){var n=e.debounceOpt,r=n===void 0?{}:n,d=e.immediate,u=d===void 0?!1:d,l=e.isResize,s=l===void 0?!0:l,c=e.resizeTimeout,a=c===void 0?300:c,v=e.rootFontSize,b=e.afterRefreshCallback,m=e.beforeRefreshCallback,h=v,p=function(){o(m)&&m(h),i(h)&&(h=(f===null||f===void 0?void 0:f.innerWidth)?(f===null||f===void 0?void 0:f.innerWidth)/100:16),document.documentElement.style.fontSize="".concat(h,"px"),o(b)&&b(h)},w=t(p,a,r),g=function(e){h=e,p()};s&&window.addEventListener("resize",w);var j=s?function(){return window.removeEventListener("resize",w)}:function(){};return u&&p(),{destory:j,rootFontSize:v,refreshRootFontSize:p,refreshRootFontSizeDebounce:w,setRootFontSize:g}}function b(e,i,l){var s=arguments.length>3&&arguments[3]!==void 0?arguments[3]:{};var c=null,a=function(){c&&c.removeEventListener(i,l)};return s.debounce&&(l=t(l,s.debounce)),s.throttle&&(l=n(l,s.throttle)),r(function(){e&&(c=d(e)?e.value:o(e)?e():e,c.addEventListener(i,l,s),s.immediate&&l(new Event(i)))}),u(function(){var e;a(),(s.debounce||s.throttle)&&((e=l.cancel)===null||e===void 0?void 0:e.call(l))}),a}var m={useDragSelect:s,useRootFontSize:v,useNextId:a,useEventListener:b};export{m as default,s as useDragSelect,b as useEventListener,a as useNextId,v as useRootFontSize};