el-carousel-item-052c6ff5.js 8.6 KB

1
  1. import{az as te,bp as Te,et as Le,al as le,aT as Be,r as m,J as A,a as e,bs as Ae,K as V,aM as $e,k as oe,cY as Oe,aw as Pe,aU as Re,c3 as Ve,c5 as ze,d as q,aB as ne,o as H,c as $,g as F,q as se,w as J,v as z,Y as N,aR as D,f as Y,aS as re,bR as De,a3 as j,$ as ie,O as K,bS as Ye,aC as ue,at as ce,F as je,n as Ke,t as We,aD as ve,aO as qe,e as Fe,l as Je,bE as Ue,aE as Xe,aI as Ze,__tla as Ge}from"./index-2eab2d23.js";import{t as de,__tla as Qe}from"./el-image-viewer-5d14bc77.js";let he,pe,ea=Promise.all([(()=>{try{return Ge}catch{}})(),(()=>{try{return Qe}catch{}})()]).then(async()=>{const fe=te({initialIndex:{type:Number,default:0},height:{type:String,default:""},trigger:{type:String,values:["hover","click"],default:"hover"},autoplay:{type:Boolean,default:!0},interval:{type:Number,default:3e3},indicatorPosition:{type:String,values:["","none","outside"],default:""},arrow:{type:String,values:["always","hover","never"],default:"hover"},type:{type:String,values:["","card"],default:""},loop:{type:Boolean,default:!0},direction:{type:String,values:["horizontal","vertical"],default:"horizontal"},pauseOnHover:{type:Boolean,default:!0}}),me={change:(o,T)=>[o,T].every(Te)},U=Symbol("carouselContextKey"),ge=(o,T,i)=>{const{children:r,addChild:L,removeChild:g}=Le(le(),"ElCarouselItem"),S=Be(),n=m(-1),d=m(null),I=m(!1),h=m(),k=m(0),y=m(!0),_=A(()=>o.arrow!=="never"&&!e(u)),C=A(()=>r.value.some(a=>a.props.label.toString().length>0)),M=A(()=>o.type==="card"),u=A(()=>o.direction==="vertical"),f=A(()=>o.height!=="auto"?{height:o.height}:{height:`${k.value}px`,overflow:"hidden"}),O=de(a=>{w(a)},300,{trailing:!0}),P=de(a=>{(function(t){o.trigger==="hover"&&t!==n.value&&(n.value=t)})(a)},300);function x(){d.value&&(clearInterval(d.value),d.value=null)}function E(){o.interval<=0||!o.autoplay||d.value||(d.value=setInterval(()=>B(),o.interval))}const B=()=>{n.value<r.value.length-1?n.value=n.value+1:o.loop&&(n.value=0)};function w(a){if(Ae(a)){const c=r.value.filter(b=>b.props.name===a);c.length>0&&(a=r.value.indexOf(c[0]))}if(a=Number(a),Number.isNaN(a)||a!==Math.floor(a))return;const t=r.value.length,s=n.value;n.value=a<0?o.loop?t-1:0:a>=t?o.loop?0:t-1:a,s===n.value&&v(s),l()}function v(a){r.value.forEach((t,s)=>{t.translateItem(s,n.value,a)})}function l(){x(),o.pauseOnHover||E()}V(()=>n.value,(a,t)=>{v(t),y.value&&(a%=2,t%=2),t>-1&&T("change",a,t)}),V(()=>o.autoplay,a=>{a?E():x()}),V(()=>o.loop,()=>{w(n.value)}),V(()=>o.interval,()=>{l()});const p=$e();return oe(()=>{V(()=>r.value,()=>{r.value.length>0&&w(o.initialIndex)},{immediate:!0}),p.value=Oe(h.value,()=>{v()}),E()}),Pe(()=>{x(),h.value&&p.value&&p.value.stop()}),Re(U,{root:h,isCardType:M,isVertical:u,items:r,loop:o.loop,addItem:L,removeItem:g,setActiveItem:w,setContainerHeight:function(a){o.height==="auto"&&(k.value=a)}}),{root:h,activeIndex:n,arrowDisplay:_,hasLabel:C,hover:I,isCardType:M,items:r,isVertical:u,containerStyle:f,isItemsTwoLength:y,handleButtonEnter:function(a){e(u)||r.value.forEach((t,s)=>{a===function(c,b){var W,Z,G,Q;const R=e(r),ee=R.length;if(ee===0||!c.states.inStage)return!1;const Se=b+1,Me=b-1,ae=ee-1,xe=R[ae].states.active,Ee=R[0].states.active,He=(Z=(W=R[Se])==null?void 0:W.states)==null?void 0:Z.active,Ne=(Q=(G=R[Me])==null?void 0:G.states)==null?void 0:Q.active;return b===ae&&Ee||He?"left":!!(b===0&&xe||Ne)&&"right"}(t,s)&&(t.states.hover=!0)})},handleButtonLeave:function(){e(u)||r.value.forEach(a=>{a.states.hover=!1})},handleIndicatorClick:function(a){n.value=a},handleMouseEnter:function(){I.value=!0,o.pauseOnHover&&x()},handleMouseLeave:function(){I.value=!1,E()},setActiveItem:w,prev:function(){w(n.value-1)},next:function(){w(n.value+1)},PlaceholderItem:function(){var a;const t=(a=S.default)==null?void 0:a.call(S);if(!t)return null;const s=Ve(t).filter(c=>ze(c)&&c.type.name==="ElCarouselItem");return(s==null?void 0:s.length)===2&&o.loop&&!M.value?(y.value=!0,s):(y.value=!1,null)},isTwoLengthShow:a=>!y.value||(n.value<=1?a<=1:a>1),throttledArrowClick:O,throttledIndicatorHover:P}},ye=["onMouseenter","onClick"],Ie={key:0},Ce=q({name:"ElCarousel"});var we=ve(q({...Ce,props:fe,emits:me,setup(o,{expose:T,emit:i}){const r=o,{root:L,activeIndex:g,arrowDisplay:S,hasLabel:n,hover:d,isCardType:I,items:h,isVertical:k,containerStyle:y,handleButtonEnter:_,handleButtonLeave:C,handleIndicatorClick:M,handleMouseEnter:u,handleMouseLeave:f,setActiveItem:O,prev:P,next:x,PlaceholderItem:E,isTwoLengthShow:B,throttledArrowClick:w,throttledIndicatorHover:v}=ge(r,i),l=ne("carousel"),p=A(()=>{const t=[l.b(),l.m(r.direction)];return e(I)&&t.push(l.m("card")),t}),a=A(()=>{const t=[l.e("indicators"),l.em("indicators",r.direction)];return e(n)&&t.push(l.em("indicators","labels")),r.indicatorPosition==="outside"&&t.push(l.em("indicators","outside")),e(k)&&t.push(l.em("indicators","right")),t});return T({setActiveItem:O,prev:P,next:x}),(t,s)=>(H(),$("div",{ref_key:"root",ref:L,class:N(e(p)),onMouseenter:s[6]||(s[6]=D((...c)=>e(u)&&e(u)(...c),["stop"])),onMouseleave:s[7]||(s[7]=D((...c)=>e(f)&&e(f)(...c),["stop"]))},[F("div",{class:N(e(l).e("container")),style:ce(e(y))},[e(S)?(H(),se(ie,{key:0,name:"carousel-arrow-left",persisted:""},{default:J(()=>[z(F("button",{type:"button",class:N([e(l).e("arrow"),e(l).em("arrow","left")]),onMouseenter:s[0]||(s[0]=c=>e(_)("left")),onMouseleave:s[1]||(s[1]=(...c)=>e(C)&&e(C)(...c)),onClick:s[2]||(s[2]=D(c=>e(w)(e(g)-1),["stop"]))},[Y(e(re),null,{default:J(()=>[Y(e(De))]),_:1})],34),[[j,(t.arrow==="always"||e(d))&&(r.loop||e(g)>0)]])]),_:1})):K("v-if",!0),e(S)?(H(),se(ie,{key:1,name:"carousel-arrow-right",persisted:""},{default:J(()=>[z(F("button",{type:"button",class:N([e(l).e("arrow"),e(l).em("arrow","right")]),onMouseenter:s[3]||(s[3]=c=>e(_)("right")),onMouseleave:s[4]||(s[4]=(...c)=>e(C)&&e(C)(...c)),onClick:s[5]||(s[5]=D(c=>e(w)(e(g)+1),["stop"]))},[Y(e(re),null,{default:J(()=>[Y(e(Ye))]),_:1})],34),[[j,(t.arrow==="always"||e(d))&&(r.loop||e(g)<e(h).length-1)]])]),_:1})):K("v-if",!0),Y(e(E)),ue(t.$slots,"default")],6),t.indicatorPosition!=="none"?(H(),$("ul",{key:0,class:N(e(a))},[(H(!0),$(je,null,Ke(e(h),(c,b)=>z((H(),$("li",{key:b,class:N([e(l).e("indicator"),e(l).em("indicator",t.direction),e(l).is("active",b===e(g))]),onMouseenter:W=>e(v)(b),onClick:D(W=>e(M)(b),["stop"])},[F("button",{class:N(e(l).e("button"))},[e(n)?(H(),$("span",Ie,We(c.props.label),1)):K("v-if",!0)],2)],42,ye)),[[j,e(B)(b)]])),128))],2)):K("v-if",!0)],34))}}),[["__file","/home/runner/work/element-plus/element-plus/packages/components/carousel/src/carousel.vue"]]);const be=te({name:{type:String,default:""},label:{type:[String,Number],default:""}}),ke=(o,T)=>{const i=qe(U),r=le(),L=.83,g=m(),S=m(!1),n=m(0),d=m(1),I=m(!1),h=m(!1),k=m(!1),y=m(!1),{isCardType:_,isVertical:C}=i,M=(u,f,O)=>{var P;const x=e(_),E=(P=i.items.value.length)!=null?P:Number.NaN,B=u===f;x||Ue(O)||(y.value=B||u===O),!B&&E>2&&i.loop&&(u=function(v,l,p){const a=p-1,t=p/2;return l===0&&v===a?-1:l===a&&v===0?p:v<l-1&&l-v>=t?p+1:v>l+1&&v-l>=t?-2:v}(u,f,E));const w=e(C);I.value=B,x?(k.value=Math.round(Math.abs(u-f))<=1,n.value=function(v,l){var p,a;const t=e(C)?((p=i.root.value)==null?void 0:p.offsetHeight)||0:((a=i.root.value)==null?void 0:a.offsetWidth)||0;return k.value?t*(1.17*(v-l)+1)/4:v<l?-1.83*t/4:3.83*t/4}(u,f),d.value=e(I)?1:L):n.value=function(v,l,p){const a=i.root.value;return a?((p?a.offsetHeight:a.offsetWidth)||0)*(v-l):0}(u,f,w),h.value=!0,B&&g.value&&i.setContainerHeight(g.value.offsetHeight)};return oe(()=>{i.addItem({props:o,states:Fe({hover:S,translate:n,scale:d,active:I,ready:h,inStage:k,animating:y}),uid:r.uid,translateItem:M})}),Je(()=>{i.removeItem(r.uid)}),{carouselItemRef:g,active:I,animating:y,hover:S,inStage:k,isVertical:C,translate:n,isCardType:_,scale:d,ready:h,handleItemClick:function(){if(i&&e(_)){const u=i.items.value.findIndex(({uid:f})=>f===r.uid);i.setActiveItem(u)}}}},_e=q({name:"ElCarouselItem"});var X=ve(q({..._e,props:be,setup(o){const T=o,i=ne("carousel"),{carouselItemRef:r,active:L,animating:g,hover:S,inStage:n,isVertical:d,translate:I,isCardType:h,scale:k,ready:y,handleItemClick:_}=ke(T),C=A(()=>({transform:[`${"translate"+(e(d)?"Y":"X")}(${e(I)}px)`,`scale(${e(k)})`].join(" ")}));return(M,u)=>z((H(),$("div",{ref_key:"carouselItemRef",ref:r,class:N([e(i).e("item"),e(i).is("active",e(L)),e(i).is("in-stage",e(n)),e(i).is("hover",e(S)),e(i).is("animating",e(g)),{[e(i).em("item","card")]:e(h),[e(i).em("item","card-vertical")]:e(h)&&e(d)}]),style:ce(e(C)),onClick:u[0]||(u[0]=(...f)=>e(_)&&e(_)(...f))},[e(h)?z((H(),$("div",{key:0,class:N(e(i).e("mask"))},null,2)),[[j,!e(L)]]):K("v-if",!0),ue(M.$slots,"default")],6)),[[j,e(y)]])}}),[["__file","/home/runner/work/element-plus/element-plus/packages/components/carousel/src/carousel-item.vue"]]);pe=Xe(we,{CarouselItem:X}),he=Ze(X)});export{he as E,ea as __tla,pe as a};