vuux
Version:
Vue3 Nuxt3 Nuxt4 组件库
2 lines (1 loc) • 1.31 kB
JavaScript
;Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("vue"),E=(o,u,s)=>{const i=a.ref(o.position),r=a.ref(!1),d=a.ref(0),l=a.computed(()=>o.height==="auto"?"auto":o.height),m=()=>{d.value+=1},t=e=>{if(!r.value||!u.value)return;e.cancelable&&e.preventDefault();const v=u.value.getBoundingClientRect(),f=(e instanceof MouseEvent?e.clientX:e.touches[0].clientX)-v.left,c=Math.max(0,Math.min(100,f/v.width*100));i.value=c,s("drag",Math.round(c))},n=()=>{r.value=!1,window.removeEventListener("mousemove",t),window.removeEventListener("touchmove",t),window.removeEventListener("mouseup",n),window.removeEventListener("touchend",n)},w=e=>{e.cancelable&&e.preventDefault(),r.value=!0,window.addEventListener("mousemove",t),window.addEventListener("touchmove",t,{passive:!1}),window.addEventListener("mouseup",n),window.addEventListener("touchend",n)},h=()=>{i.value=o.position,s("drag",Math.round(o.position))},g=e=>{i.value=Math.max(0,Math.min(100,e)),s("drag",i.value)};return a.onUnmounted(()=>{window.removeEventListener("mousemove",t),window.removeEventListener("touchmove",t),window.removeEventListener("mouseup",n),window.removeEventListener("touchend",n)}),{position:i,containerHeight:l,onLoad:m,startDrag:w,resetPosition:h,setPosition:g}};exports.useImageCompare=E;