import{s as me}from"./CAnBmJm0.js";import{e as pe,p as ge,D as we,q as he,c,a as N,G as g,g as i,F as R,s as j,K as F,n as M,v as w,h as s,o as f,a3 as xe,H as ke,_ as ye}from"./DamWCzlT.js";const be={class:"custom-carousel__container"},Ce=["onClick"],_e=["aria-label","onClick"],Me=pe({__name:"CustomCarousel",props:{items:{},slidesPerView:{default:1},breakpoints:{default:()=>({})},autoplay:{type:Boolean,default:!1},autoplayInterval:{default:3e3},loop:{type:Boolean,default:!1},arrows:{type:Boolean,default:!0},pagination:{type:Boolean,default:!1},gap:{default:0},arrowOffset:{default:0},arrowSize:{default:60},paginationOffset:{default:16}},emits:["click"],setup(v,{expose:H,emit:K}){const t=v,U=K,a=w(0),Z=w(),m=w(!1),y=w(!1),b=w(0);function u(){const e=b.value;if(e===0)return t.slidesPerView;const n=Object.keys(t.breakpoints).map(Number).sort((o,l)=>l-o);for(const o of n)if(e>=o)return t.breakpoints[o]??t.slidesPerView;return t.slidesPerView}const I=s(()=>u());function d(){return t.loop?u():0}const q=s(()=>!t.loop||t.items.length===0?[]:t.items.slice(0,d())),G=s(()=>!t.loop||t.items.length===0?[]:t.items.slice(-d())),J=s(()=>t.loop?[...G.value,...t.items,...q.value]:t.items);function p(){const e=u();return t.items.length<=e?0:t.items.length-e}function S(){return t.loop?d():0}const Q=s(()=>{const n=100/u();return-(a.value*n)}),ee=s(()=>({transform:`translateX(${Q.value}%)`,transition:m.value?"transform 0.5s ease":"none"})),te=s(()=>({flex:`0 0 ${100/u()}%`,paddingLeft:`${t.gap/32}rem`,paddingRight:`${t.gap/32}rem`})),ne=s(()=>({left:`${t.arrowOffset/16}rem`,width:`${t.arrowSize/16}rem`,height:`${t.arrowSize/16}rem`})),oe=s(()=>({right:`${t.arrowOffset/16}rem`,width:`${t.arrowSize/16}rem`,height:`${t.arrowSize/16}rem`}));function L(e){if(!t.loop)return e;const n=d();let o=e-n;return o<0&&(o=t.items.length+o),o>=t.items.length&&(o=o-t.items.length),o}function r(e,n=!1){m.value&&!n||(m.value=!n,a.value=e,n||setTimeout(()=>{if(m.value=!1,t.loop){const o=d(),l=S(),A=p();a.value>=t.items.length+o?(a.value=l,r(a.value,!0)):a.value<0&&(a.value=l+A,r(a.value,!0))}else{const o=p();a.value<0&&(a.value=0),a.value>o&&(a.value=o)}},500))}function V(){const e=p();(t.loop||a.value<e)&&r(a.value+1)}function ae(){(t.loop||a.value>0)&&r(a.value-1)}function $(){const e=u(),n=p();if(t.loop)r(a.value+e);else if(a.value<n){const o=Math.min(a.value+e,n);r(o)}}function T(){const e=u();if(t.loop)r(a.value-e);else if(a.value>0){const n=Math.max(a.value-e,0);r(n)}}function z(e){const n=d();r(t.loop?e+n:e)}function re(e,n){const o=L(n);U("click",e,o)}let h=null;function D(){const e=u();!t.autoplay||t.items.length<=e||(C(),h=me(()=>{!y.value&&!m.value&&V()},t.autoplayInterval))}function C(){h&&(clearInterval(h),h=null)}function le(){y.value=!0}function se(){y.value=!1}let _=0,P=0,x=!1,k=!1;function B(e,n){m.value||(x=!0,k=!1,_=e,P=n)}function X(e,n){if(!x)return;const o=Math.abs(e-_),l=Math.abs(n-P);o>l&&o>5&&(k=!0)}function O(e){if(!x||(x=!1,!k))return;const n=e-_,o=50;n>o?T():n<-o&&$()}function ie(e){e.preventDefault(),B(e.clientX,e.clientY)}function ue(e){X(e.clientX,e.clientY)}function E(e){O(e.clientX)}function ce(e){const n=e.touches[0];n&&B(n.clientX,n.clientY)}function fe(e){const n=e.touches[0];n&&(X(n.clientX,n.clientY),k&&e.preventDefault())}function de(e){const n=e.changedTouches[0];n&&O(n.clientX)}const W=s(()=>p()+1),ve=s(()=>{if(!t.loop)return a.value;const e=d(),n=p();return Math.max(0,Math.min(a.value-e,n))});function Y(){b.value=window.innerWidth}return ge(()=>{b.value=window.innerWidth,a.value=S(),D(),window.addEventListener("resize",Y)}),we(()=>{C(),window.removeEventListener("resize",Y)}),he(()=>t.autoplay,e=>{e?D():C()}),H({next:V,prev:ae,slideTo:r,goToPage:z}),(e,n)=>(f(),c("div",{class:"custom-carousel",onMouseenter:le,onMouseleave:se},[N("div",be,[N("div",{ref_key:"trackRef",ref:Z,class:"custom-carousel__track",style:g(i(ee)),onMousedown:ie,onMousemove:ue,onMouseup:E,onMouseleave:E,onTouchstart:ce,onTouchmove:fe,onTouchend:de},[(f(!0),c(R,null,j(i(J),(o,l)=>(f(),c("div",{key:l,class:"custom-carousel__slide",style:g(i(te)),onClick:A=>re(o,l)},[xe(e.$slots,"default",{item:o,index:L(l)},void 0,!0)],12,Ce))),128))],36)]),v.arrows&&v.items.length>i(I)?(f(),c("button",{key:0,type:"button",class:"custom-carousel__arrow custom-carousel__arrow--prev",style:g(i(ne)),"aria-label":"上一个",onClick:T},[...n[0]||(n[0]=[F('<svg viewBox="0 0 60 60" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" data-v-6e030fbf><g id="页面-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd" data-v-6e030fbf><g id="福达股份演示-2备份-5" transform="translate(-140, -3375)" data-v-6e030fbf><g id="编组-35" transform="translate(140, 3375)" data-v-6e030fbf><g id="1.通用/2.Icon图标/Line线性/Down" transform="translate(29.7345, 30.2655) rotate(-270) translate(-29.7345, -30.2655)translate(13.8053, 14.3363)" data-v-6e030fbf><g id="up" transform="translate(0, -0)" data-v-6e030fbf><rect id="矩形" opacity="0" fill-rule="nonzero" x="0" y="1.77270388e-13" width="31.8584071" height="31.8584071" data-v-6e030fbf></rect><path id="路径" d="M27.3787126,7.96460177 L25.0453332,7.96460177 C24.8866634,7.96460177 24.7373271,8.04238108 24.6439919,8.16993916 L15.8051507,20.3532909 L6.96630942,8.16993916 C6.87297424,8.04238108 6.72363796,7.96460177 6.56496816,7.96460177 L4.23158873,7.96460177 C4.02936251,7.96460177 3.91113796,8.19482854 4.02936251,8.35972069 L14.999357,23.4831305 C15.3975871,24.0306969 16.2127143,24.0306969 16.6078332,23.4831305 L27.5778277,8.35972069 C27.6991634,8.19482854 27.5809388,7.96460177 27.3787126,7.96460177 Z" fill="currentColor" data-v-6e030fbf></path></g></g><circle id="椭圆形" stroke="currentColor" stroke-width="3" cx="30" cy="30" r="28.5" data-v-6e030fbf></circle></g></g></g></svg>',1)])],4)):M("",!0),v.arrows&&v.items.length>i(I)?(f(),c("button",{key:1,type:"button",class:"custom-carousel__arrow custom-carousel__arrow--next",style:g(i(oe)),"aria-label":"下一个",onClick:$},[...n[1]||(n[1]=[F('<svg viewBox="0 0 60 60" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" data-v-6e030fbf><g id="页面-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd" data-v-6e030fbf><g id="福达股份演示-2备份-5" transform="translate(-1720, -3375)" data-v-6e030fbf><g id="编组-35备份" transform="translate(1720, 3375)" data-v-6e030fbf><g id="up" transform="translate(29.7345, 30.2655) scale(-1, 1) rotate(-270) translate(-29.7345, -30.2655)translate(13.8053, 14.3363)" data-v-6e030fbf><rect id="矩形" opacity="0" fill-rule="nonzero" x="0" y="0" width="31.8584071" height="31.8584071" data-v-6e030fbf></rect><path id="路径" d="M27.3787126,7.96460177 L25.0453332,7.96460177 C24.8866634,7.96460177 24.7373271,8.04238108 24.6439919,8.16993916 L15.8051507,20.3532909 L6.96630942,8.16993916 C6.87297424,8.04238108 6.72363796,7.96460177 6.56496816,7.96460177 L4.23158873,7.96460177 C4.02936251,7.96460177 3.91113796,8.19482854 4.02936251,8.35972069 L14.999357,23.4831305 C15.3975871,24.0306969 16.2127143,24.0306969 16.6078332,23.4831305 L27.5778277,8.35972069 C27.6991634,8.19482854 27.5809388,7.96460177 27.3787126,7.96460177 Z" fill="currentColor" data-v-6e030fbf></path></g><circle id="椭圆形" stroke="currentColor" stroke-width="3" cx="30" cy="30" r="28.5" data-v-6e030fbf></circle></g></g></g></svg>',1)])],4)):M("",!0),v.pagination&&i(W)>1?(f(),c("div",{key:2,class:"custom-carousel__pagination",style:g({marginTop:`${t.paginationOffset/16}rem`})},[(f(!0),c(R,null,j(i(W),o=>(f(),c("button",{key:o,type:"button",class:ke(["custom-carousel__pagination-dot",{"custom-carousel__pagination-dot--active":o-1===i(ve)}]),"aria-label":`跳转到第 ${o} 页`,onClick:l=>z(o-1)},null,10,_e))),128))],4)):M("",!0)],32))}}),Le=Object.assign(ye(Me,[["__scopeId","data-v-6e030fbf"]]),{__name:"CustomCarousel"});export{Le as _};
