el-carousel-item-2e1a3f88.js 8.8 KB

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