UNPKG

zview-plus

Version:

基于 Vue3 的 UI 组件库

2 lines (1 loc) 1.96 kB
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("vue"),I=require("../../../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/throttle.js"),T=350,A=(t,s)=>{const n=a.ref(t.initialIndex),o=a.ref(null),w=a.ref(),h=a.ref(),{data:i}=t,d=a.ref(!1),v=a.ref(!0),y=a.computed(()=>t.direction==="vertical"),E=a.computed(()=>t.arrow!=="never"&&!a.unref(y)),M=I.default(e=>{u(e)},T),C=I.default(e=>{b(e)},T);function c(){o.value&&(clearInterval(o.value),o.value=null)}function r(){t.interval<=0||!t.autoplay||o.value||(o.value=setInterval(()=>H(),t.interval))}const H=()=>{const e=i.length;n.value<e-1||t.loop&&n.value<e?n.value=n.value+1:t.loop&&(n.value=0)};function u(e){const l=i.length;!t.loop&&(e<0||e>=l)||(t.loop&&(e<-1||e>l)&&(e=(e%l+l)%l),n.value=e,g())}function L(){d.value=!0,t.pauseOnHover&&c()}function O(){d.value=!1,r()}function S(e){n.value=e}function b(e){t.trigger==="hover"&&e!==n.value&&(n.value=e)}function k(){u(n.value-1)}function q(){u(n.value+1)}function g(){c(),r()}a.watch(()=>n.value,(e,l)=>{const f=i.length;e===-1||e===f||(e===0&&l===f?s("change",e,f-1):e===f-1&&l===-1?s("change",e,0):s("change",e,l))}),a.watch(()=>t.autoplay,e=>{e?r():c()}),a.watch(()=>t.loop,()=>{u(n.value)}),a.watch(()=>t.interval,()=>{g()}),a.watch(()=>t.data,()=>{t.data.length>0&&u(t.initialIndex)});const m=()=>{console.log(111),n.value===i.length?(v.value=!1,n.value=0,setTimeout(()=>v.value=!0,10)):n.value===-1&&(v.value=!1,n.value=i.length-1,setTimeout(()=>v.value=!0,10))};return a.onMounted(()=>{var e;r(),(e=h.value)==null||e.addEventListener("transitionend",m)}),a.onBeforeUnmount(()=>{var e;c(),(e=h.value)==null||e.removeEventListener("transitionend",m)}),{root:w,transitionItem:h,activeIndex:n,arrowDisplay:E,handleIndicatorClick:S,handleMouseEnter:L,handleMouseLeave:O,setActiveItem:u,prev:k,next:q,throttledArrowClick:M,throttledIndicatorHover:C,hover:d,animating:v}};exports.useCarousel=A;