el-carousel-item-910e0d1d.js 8.8 KB

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