el-carousel-item-90fd7986.js 8.8 KB

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