UNPKG

vexip-ui

Version:

A Vue 3 UI library, Highly customizability, full TypeScript, performance pretty good

3 lines (2 loc) 2.92 kB
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("vue"),d=require("@vexip-ui/hooks"),u=require("@vexip-ui/utils"),K=require("./helper.cjs");function N({mode:i,disabled:R,appear:g,scrollX:p,scrollY:m,onResize:b,onBeforeRefresh:x,onAfterRefresh:M}){const{manualRef:s,triggerUpdate:T}=d.useManualRef(),{isRtl:w}=d.useRtl(),S=l.ref(),e=l.reactive({el:S,scrollWidth:0,offsetWidth:0,scrollHeight:0,offsetHeight:0}),o=s(0),n=s(0),P=s(0),q=s(0),a=l.computed(()=>e.el?e.scrollWidth-e.offsetWidth:0),f=l.computed(()=>e.el?e.scrollHeight-e.offsetHeight:0),F=l.computed(()=>!R.value&&i.value!=="vertical"&&!!e.el&&e.scrollWidth>e.offsetWidth),B=l.computed(()=>!R.value&&i.value!=="horizontal"&&!!e.el&&e.scrollHeight>e.offsetHeight),U=l.computed(()=>e.el?u.boundRange(e.offsetWidth/(e.scrollWidth||1)*100,5,99):35),D=l.computed(()=>e.el?u.boundRange(e.offsetHeight/(e.scrollHeight||1)*100,5,99):35);l.watch(S,()=>{C()}),l.watch(p,t=>{W(t)}),l.watch(m,t=>{y(t)});function W(t){o.value=u.boundRange(t,0,a.value),E()}function y(t){n.value=u.boundRange(t,0,f.value),E()}function E(){e.el&&e.el.scrollTo({top:n.value,left:w.value?-o.value:o.value,behavior:"instant"})}const{isMounted:L}=d.useMounted();function C(){!e.el||d.isHiddenElement(e.el)||(e.scrollWidth=e.el.scrollWidth,e.offsetWidth=e.el.offsetWidth,e.scrollHeight=e.el.scrollHeight,e.offsetHeight=e.el.offsetHeight,i.value!=="vertical"&&W(!L.value&&g.value?p.value:o.value||0),i.value!=="horizontal"&&y(!L.value&&g.value?m.value:n.value||0),k(),T())}function k(){e.el&&(P.value=w.value?-u.multipleFixed(o.value/(a.value||1),100,2):u.multipleFixed(o.value/(a.value||1),100,2),q.value=u.multipleFixed(n.value/(f.value||1),100,2))}function G(t){H(),b==null||b(t)}l.onMounted(()=>{H(),g.value&&v(p.value,m.value)});const H=u.debounceMinor(()=>new Promise(t=>{typeof x=="function"&&x(),C(),setTimeout(()=>{typeof M=="function"&&M(),t()},0)}));function v(t,r,c=500){return new Promise(h=>{e.el&&((!F.value||Math.abs(o.value-t)<.01)&&(t=o.value),(!B.value||Math.abs(n.value-r)<.01)&&(r=n.value),K.animateScrollTo({duration:c,el:e.el,xFrom:o.value,xTo:u.boundRange(t,0,a.value),yFrom:n.value,yTo:u.boundRange(r,0,f.value),callback:h}))})}function I(t,r,c=500){return v(o.value+t,n.value+r,c)}function J(t,r,c=0){if(!e.el||(typeof t=="string"&&(t=e.el.querySelector(t)),!u.isElement(t)))return Promise.resolve();const h=e.el.getBoundingClientRect(),z=t.getBoundingClientRect();let j=0,O=0;return i.value!=="vertical"&&(j=z.left-h.left+c),i.value!=="horizontal"&&(O=z.top-h.top+c),v(j,O,r)}return{contentEl:S,content:e,x:o,y:n,percentX:P,percentY:q,xScrollLimit:a,yScrollLimit:f,enableXScroll:F,enableYScroll:B,xBarLength:U,yBarLength:D,handleResize:u.debounce(G),setScrollX:W,setScrollY:y,computePercent:k,refresh:H,scrollTo:v,scrollBy:I,scrollToElement:J,triggerUpdate:T}}exports.useScrollWrapper=N; //# sourceMappingURL=hooks.cjs.map