import{u as Wt,a as Nt,b as jt,c as Mt,d as V,e as Yt,i as _,f as et,g as Ut}from"./@vant-DKhawVSW.js";import{u as Xt,r as w,a as it,i as yt,w as O,g as Lt,m as M,c as E,q as b,s as Q,e as st,f as Vt,b as qt,t as $t,n as I,v as Gt,x as Kt,y as At}from"./@vue-DuIk5FiX.js";function St(){}const Zt=Object.assign,xt=typeof window<"u",nt=e=>e!==null&&typeof e=="object",N=e=>e!=null,Qt=e=>typeof e=="function",Ct=e=>typeof e=="number"||/^\d+(\.\d+)?$/.test(e),Jt=()=>xt?/ios|iphone|ipad|ipod/.test(navigator.userAgent.toLowerCase()):!1;function dt(e,t){const i=t.split(".");let s=e;return i.forEach(n=>{var r;s=nt(s)&&(r=s[n])!=null?r:""}),s}const A=[Number,String],D={type:Boolean,default:!0},K=e=>({type:A,default:e}),j=e=>({type:String,default:e});Jt();const te=e=>e.stopPropagation();function ee(e,t){(typeof e.cancelable!="boolean"||e.cancelable)&&e.preventDefault(),t&&te(e)}function ht(e){const t=Xt(e);if(!t)return!1;const i=window.getComputedStyle(t),s=i.display==="none",n=t.offsetParent===null&&i.position!=="fixed";return s||n}const{width:ie,height:se}=Wt();function S(e){if(N(e))return Ct(e)?"".concat(e,"px"):String(e)}const ne=/-(\w)/g,It=e=>e.replace(ne,(t,i)=>i.toUpperCase()),Z=(e,t,i)=>Math.min(Math.max(e,t),i),{hasOwnProperty:re}=Object.prototype;function oe(e,t,i){const s=t[i];N(s)&&(!re.call(e,i)||!nt(s)?e[i]=s:e[i]=Bt(Object(e[i]),s))}function Bt(e,t){return Object.keys(t).forEach(i=>{oe(e,t,i)}),e}var ae={name:"姓名",tel:"电话",save:"保存",clear:"清空",cancel:"取消",confirm:"确认",delete:"删除",loading:"加载中...",noCoupon:"暂无优惠券",nameEmpty:"请填写姓名",addContact:"添加联系人",telInvalid:"请填写正确的电话",vanCalendar:{end:"结束",start:"开始",title:"日期选择",weekdays:["日","一","二","三","四","五","六"],monthTitle:(e,t)=>"".concat(e,"年").concat(t,"月"),rangePrompt:e=>"最多选择 ".concat(e," 天")},vanCascader:{select:"请选择"},vanPagination:{prev:"上一页",next:"下一页"},vanPullRefresh:{pulling:"下拉即可刷新...",loosing:"释放即可刷新..."},vanSubmitBar:{label:"合计:"},vanCoupon:{unlimited:"无门槛",discount:e=>"".concat(e,"折"),condition:e=>"满".concat(e,"元可用")},vanCouponCell:{title:"优惠券",count:e=>"".concat(e,"张可用")},vanCouponList:{exchange:"兑换",close:"不使用",enable:"可用",disabled:"不可用",placeholder:"输入优惠码"},vanAddressEdit:{area:"地区",areaEmpty:"请选择地区",addressEmpty:"请填写详细地址",addressDetail:"详细地址",defaultAddress:"设为默认收货地址"},vanAddressList:{add:"新增地址"}};const ft=w("zh-CN"),vt=it({"zh-CN":ae}),le={messages(){return vt[ft.value]},use(e,t){ft.value=e,this.add({[e]:t})},add(e={}){Bt(vt,e)}};var ue=le;function ce(e){const t=It(e)+".";return(i,...s)=>{const n=ue.messages(),r=dt(n,t+i)||dt(n,i);return Qt(r)?r(...s):r}}function J(e,t){return t?typeof t=="string"?" ".concat(e,"--").concat(t):Array.isArray(t)?t.reduce((i,s)=>i+J(e,s),""):Object.keys(t).reduce((i,s)=>i+(t[s]?J(e,s):""),""):""}function de(e){return(t,i)=>(t&&typeof t!="string"&&(i=t,t=""),t=t?"".concat(e,"__").concat(t):e,"".concat(t).concat(J(t,i)))}function F(e){const t="van-".concat(e);return[t,de(t),ce(t)]}const gt=5;function Y(e){return e.install=t=>{const{name:i}=e;i&&(t.component(i,e),t.component(It("-".concat(i)),e))},e}const he=Symbol();function fe(e){const t=yt(he,null);t&&O(t,i=>{i&&e()})}function zt(e){const t=Lt();t&&Zt(t.proxy,e)}const[ve,pt]=F("badge"),ge={dot:Boolean,max:A,tag:j("div"),color:String,offset:Array,content:A,showZero:D,position:j("top-right")};var pe=M({name:ve,props:ge,setup(e,{slots:t}){const i=()=>{if(t.content)return!0;const{content:o,showZero:h}=e;return N(o)&&o!==""&&(h||o!==0&&o!=="0")},s=()=>{const{dot:o,max:h,content:c}=e;if(!o&&i())return t.content?t.content():N(h)&&Ct(c)&&+c>+h?"".concat(h,"+"):c},n=o=>o.startsWith("-")?o.replace("-",""):"-".concat(o),r=E(()=>{const o={background:e.color};if(e.offset){const[h,c]=e.offset,{position:l}=e,[u,f]=l.split("-");t.default?(typeof c=="number"?o[u]=S(u==="top"?c:-c):o[u]=u==="top"?S(c):n(c),typeof h=="number"?o[f]=S(f==="left"?h:-h):o[f]=f==="left"?S(h):n(h)):(o.marginTop=S(c),o.marginLeft=S(h))}return o}),a=()=>{if(i()||e.dot)return b("div",{class:pt([e.position,{dot:e.dot,fixed:!!t.default}]),style:r.value},[s()])};return()=>{if(t.default){const{tag:o}=e;return b(o,{class:pt("wrapper")},{default:()=>[t.default(),a()]})}return a()}}});const me=Y(pe),[be,Qe]=F("config-provider"),Ee=Symbol(be),[we,mt]=F("icon"),ye=e=>e==null?void 0:e.includes("/"),Le={dot:Boolean,tag:j("i"),name:String,size:A,badge:A,color:String,badgeProps:Object,classPrefix:String};var $e=M({name:we,props:Le,setup(e,{slots:t}){const i=yt(Ee,null),s=E(()=>e.classPrefix||(i==null?void 0:i.iconPrefix)||mt());return()=>{const{tag:n,dot:r,name:a,size:o,badge:h,color:c}=e,l=ye(a);return b(me,Q({dot:r,tag:n,class:[s.value,l?"":"".concat(s.value,"-").concat(a)],style:{color:c,fontSize:S(o)},content:h},e.badgeProps),{default:()=>{var u;return[(u=t.default)==null?void 0:u.call(t),l&&b("img",{class:mt("image"),src:a},null)]}})}}});const Ae=Y($e);function Se(e,t){return e>t?"horizontal":t>e?"vertical":""}function xe(){const e=w(0),t=w(0),i=w(0),s=w(0),n=w(0),r=w(0),a=w(""),o=w(!0),h=()=>a.value==="vertical",c=()=>a.value==="horizontal",l=()=>{i.value=0,s.value=0,n.value=0,r.value=0,a.value="",o.value=!0};return{move:m=>{const L=m.touches[0];i.value=(L.clientX<0?0:L.clientX)-e.value,s.value=L.clientY-t.value,n.value=Math.abs(i.value),r.value=Math.abs(s.value);const x=10;(!a.value||n.value<x&&r.value<x)&&(a.value=Se(n.value,r.value)),o.value&&(n.value>gt||r.value>gt)&&(o.value=!1)},start:m=>{l(),e.value=m.touches[0].clientX,t.value=m.touches[0].clientY},reset:l,startX:e,startY:t,deltaX:i,deltaY:s,offsetX:n,offsetY:r,direction:a,isVertical:h,isHorizontal:c,isTap:o}}const[Ot,q]=F("swipe"),Ce={loop:D,width:A,height:A,vertical:Boolean,autoplay:K(0),duration:K(500),touchable:D,lazyRender:Boolean,initialSwipe:K(0),indicatorColor:String,showIndicators:D,stopPropagation:D},Dt=Symbol(Ot);var Ie=M({name:Ot,props:Ce,emits:["change","dragStart","dragEnd"],setup(e,{emit:t,slots:i}){const s=w(),n=w(),r=it({rect:null,width:0,height:0,offset:0,active:0,swiping:!1});let a=!1;const o=xe(),{children:h,linkChildren:c}=Nt(Dt),l=E(()=>h.length),u=E(()=>r[e.vertical?"height":"width"]),f=E(()=>e.vertical?o.deltaY.value:o.deltaX.value),m=E(()=>r.rect?(e.vertical?r.rect.height:r.rect.width)-u.value*l.value:0),L=E(()=>u.value?Math.ceil(Math.abs(m.value)/u.value):l.value),x=E(()=>l.value*u.value),v=E(()=>(r.active+l.value)%l.value),B=E(()=>{const d=e.vertical?"vertical":"horizontal";return o.direction.value===d}),U=E(()=>{const d={transitionDuration:"".concat(r.swiping?0:e.duration,"ms"),transform:"translate".concat(e.vertical?"Y":"X","(").concat(+r.offset.toFixed(2),"px)")};if(u.value){const p=e.vertical?"height":"width",g=e.vertical?"width":"height";d[p]="".concat(x.value,"px"),d[g]=e[g]?"".concat(e[g],"px"):""}return d}),Tt=d=>{const{active:p}=r;return d?e.loop?Z(p+d,-1,l.value):Z(p+d,0,L.value):p},rt=(d,p=0)=>{let g=d*u.value;e.loop||(g=Math.min(g,-m.value));let $=p-g;return e.loop||($=Z($,m.value,0)),$},C=({pace:d=0,offset:p=0,emitChange:g})=>{if(l.value<=1)return;const{active:$}=r,y=Tt(d),k=rt(y,p);if(e.loop){if(h[0]&&k!==m.value){const G=k<m.value;h[0].setOffset(G?x.value:0)}if(h[l.value-1]&&k!==0){const G=k>0;h[l.value-1].setOffset(G?-x.value:0)}}r.active=y,r.offset=k,g&&y!==$&&t("change",v.value)},X=()=>{r.swiping=!0,r.active<=-1?C({pace:l.value}):r.active>=l.value&&C({pace:-l.value})},Pt=()=>{X(),o.reset(),V(()=>{r.swiping=!1,C({pace:-1,emitChange:!0})})},ot=()=>{X(),o.reset(),V(()=>{r.swiping=!1,C({pace:1,emitChange:!0})})};let at;const R=()=>clearTimeout(at),H=()=>{R(),+e.autoplay>0&&l.value>1&&(at=setTimeout(()=>{ot(),H()},+e.autoplay))},T=(d=+e.initialSwipe)=>{if(!s.value)return;const p=()=>{var g,$;if(!ht(s)){const y={width:s.value.offsetWidth,height:s.value.offsetHeight};r.rect=y,r.width=+((g=e.width)!=null?g:y.width),r.height=+(($=e.height)!=null?$:y.height)}l.value&&(d=Math.min(l.value-1,d),d===-1&&(d=l.value-1)),r.active=d,r.swiping=!0,r.offset=rt(d),h.forEach(y=>{y.setOffset(0)}),H()};ht(s)?I().then(p):p()},lt=()=>T(r.active);let ut;const _t=d=>{!e.touchable||d.touches.length>1||(o.start(d),a=!1,ut=Date.now(),R(),X())},Ft=d=>{e.touchable&&r.swiping&&(o.move(d),B.value&&(!e.loop&&(r.active===0&&f.value>0||r.active===l.value-1&&f.value<0)||(ee(d,e.stopPropagation),C({offset:f.value}),a||(t("dragStart",{index:v.value}),a=!0))))},ct=()=>{if(!e.touchable||!r.swiping)return;const d=Date.now()-ut,p=f.value/d;if((Math.abs(p)>.25||Math.abs(f.value)>u.value/2)&&B.value){const $=e.vertical?o.offsetY.value:o.offsetX.value;let y=0;e.loop?y=$>0?f.value>0?-1:1:0:y=-Math[f.value>0?"ceil":"floor"](f.value/u.value),C({pace:y,emitChange:!0})}else f.value&&C({pace:0});a=!1,r.swiping=!1,t("dragEnd",{index:v.value}),H()},Rt=(d,p={})=>{X(),o.reset(),V(()=>{let g;e.loop&&d===l.value?g=r.active===0?0:d:g=d%l.value,p.immediate?V(()=>{r.swiping=!1}):r.swiping=!1,C({pace:g-r.active,emitChange:!0})})},Ht=(d,p)=>{const g=p===v.value,$=g?{backgroundColor:e.indicatorColor}:void 0;return b("i",{style:$,class:q("indicator",{active:g})},null)},kt=()=>{if(i.indicator)return i.indicator({active:v.value,total:l.value});if(e.showIndicators&&l.value>1)return b("div",{class:q("indicators",{vertical:e.vertical})},[Array(l.value).fill("").map(Ht)])};return zt({prev:Pt,next:ot,state:r,resize:lt,swipeTo:Rt}),c({size:u,props:e,count:l,activeIndicator:v}),O(()=>e.initialSwipe,d=>T(+d)),O(l,()=>T(r.active)),O(()=>e.autoplay,H),O([ie,se,()=>e.width,()=>e.height],lt),O(jt(),d=>{d==="visible"?H():R()}),st(T),Vt(()=>T(r.active)),fe(()=>T(r.active)),qt(R),$t(R),Mt("touchmove",Ft,{target:n}),()=>{var d;return b("div",{ref:s,class:q()},[b("div",{ref:n,style:U.value,class:q("track",{vertical:e.vertical}),onTouchstartPassive:_t,onTouchend:ct,onTouchcancel:ct},[(d=i.default)==null?void 0:d.call(i)]),kt()])}}});const Je=Y(Ie),[Be,ze]=F("swipe-item");var Oe=M({name:Be,setup(e,{slots:t}){let i;const s=it({offset:0,inited:!1,mounted:!1}),{parent:n,index:r}=Yt(Dt);if(!n)return;const a=E(()=>{const c={},{vertical:l}=n.props;return n.size.value&&(c[l?"height":"width"]="".concat(n.size.value,"px")),s.offset&&(c.transform="translate".concat(l?"Y":"X","(").concat(s.offset,"px)")),c}),o=E(()=>{const{loop:c,lazyRender:l}=n.props;if(!l||i)return!0;if(!s.mounted)return!1;const u=n.activeIndicator.value,f=n.count.value-1,m=u===0&&c?f:u-1,L=u===f&&c?0:u+1;return i=r.value===u||r.value===m||r.value===L,i}),h=c=>{s.offset=c};return st(()=>{I(()=>{s.mounted=!0})}),zt({setOffset:h}),()=>{var c;return b("div",{class:ze(),style:a.value},[o.value?(c=t.default)==null?void 0:c.call(t):null])}}});const ti=Y(Oe),bt=_&&"IntersectionObserver"in window&&"IntersectionObserverEntry"in window&&"intersectionRatio"in window.IntersectionObserverEntry.prototype,z={event:"event",observer:"observer"};function W(e,t){if(!e.length)return;const i=e.indexOf(t);if(i>-1)return e.splice(i,1)}function Et(e,t){if(e.tagName!=="IMG"||!e.getAttribute("data-srcset"))return;let i=e.getAttribute("data-srcset");const n=e.parentNode.offsetWidth*t;let r,a,o;i=i.trim().split(",");const h=i.map(u=>(u=u.trim(),r=u.lastIndexOf(" "),r===-1?(a=u,o=999998):(a=u.substr(0,r),o=parseInt(u.substr(r+1,u.length-r-2),10)),[o,a]));h.sort((u,f)=>{if(u[0]<f[0])return 1;if(u[0]>f[0])return-1;if(u[0]===f[0]){if(f[1].indexOf(".webp",f[1].length-5)!==-1)return 1;if(u[1].indexOf(".webp",u[1].length-5)!==-1)return-1}return 0});let c="",l;for(let u=0;u<h.length;u++){l=h[u],c=l[1];const f=h[u+1];if(f&&f[0]<n){c=l[1];break}else if(!f){c=l[1];break}}return c}const De=(e=1)=>_&&window.devicePixelRatio||e;function Te(){if(!_)return!1;let e=!0;try{const t=document.createElement("canvas");t.getContext&&t.getContext("2d")&&(e=t.toDataURL("image/webp").indexOf("data:image/webp")===0)}catch(t){e=!1}return e}function Pe(e,t){let i=null,s=0;return function(...n){if(i)return;const r=Date.now()-s,a=()=>{s=Date.now(),i=!1,e.apply(this,n)};r>=t?a():i=setTimeout(a,t)}}function _e(e,t,i){e.addEventListener(t,i,{capture:!1,passive:!0})}function Fe(e,t,i){e.removeEventListener(t,i,!1)}const tt=(e,t,i)=>{const s=new Image;if(!e||!e.src)return i(new Error("image src is required"));s.src=e.src,e.cors&&(s.crossOrigin=e.cors),s.onload=()=>t({naturalHeight:s.naturalHeight,naturalWidth:s.naturalWidth,src:s.src}),s.onerror=n=>i(n)};class Re{constructor({max:t}){this.options={max:t||100},this.caches=[]}has(t){return this.caches.indexOf(t)>-1}add(t){this.has(t)||(this.caches.push(t),this.caches.length>this.options.max&&this.free())}free(){this.caches.shift()}}const[He,P]=F("image"),ke={src:String,alt:String,fit:String,position:String,round:Boolean,block:Boolean,width:A,height:A,radius:A,lazyLoad:Boolean,iconSize:A,showError:D,errorIcon:j("photo-fail"),iconPrefix:String,showLoading:D,loadingIcon:j("photo"),crossorigin:String,referrerpolicy:String};var We=M({name:He,props:ke,emits:["load","error"],setup(e,{emit:t,slots:i}){const s=w(!1),n=w(!0),r=w(),{$Lazyload:a}=Lt().proxy,o=E(()=>{const v={width:S(e.width),height:S(e.height)};return N(e.radius)&&(v.overflow="hidden",v.borderRadius=S(e.radius)),v});O(()=>e.src,()=>{s.value=!1,n.value=!0});const h=v=>{n.value&&(n.value=!1,t("load",v))},c=()=>{const v=new Event("load");Object.defineProperty(v,"target",{value:r.value,enumerable:!0}),h(v)},l=v=>{s.value=!0,n.value=!1,t("error",v)},u=(v,B,U)=>U?U():b(Ae,{name:v,size:e.iconSize,class:B,classPrefix:e.iconPrefix},null),f=()=>{if(n.value&&e.showLoading)return b("div",{class:P("loading")},[u(e.loadingIcon,P("loading-icon"),i.loading)]);if(s.value&&e.showError)return b("div",{class:P("error")},[u(e.errorIcon,P("error-icon"),i.error)])},m=()=>{if(s.value||!e.src)return;const v={alt:e.alt,class:P("img"),style:{objectFit:e.fit,objectPosition:e.position},crossorigin:e.crossorigin,referrerpolicy:e.referrerpolicy};return e.lazyLoad?Gt(b("img",Q({ref:r},v),null),[[Kt("lazy"),e.src]]):b("img",Q({ref:r,src:e.src,onLoad:h,onError:l},v),null)},L=({el:v})=>{const B=()=>{v===r.value&&n.value&&c()};r.value?B():I(B)},x=({el:v})=>{v===r.value&&!s.value&&l()};return a&&xt&&(a.$on("loaded",L),a.$on("error",x),$t(()=>{a.$off("loaded",L),a.$off("error",x)})),st(()=>{I(()=>{var v;(v=r.value)!=null&&v.complete&&!e.lazyLoad&&c()})}),()=>{var v;return b("div",{class:P({round:e.round,block:e.block}),style:o.value},[m(),f(),(v=i.default)==null?void 0:v.call(i)])}}});const ei=Y(We);class Ne{constructor({el:t,src:i,error:s,loading:n,bindType:r,$parent:a,options:o,cors:h,elRenderer:c,imageCache:l}){this.el=t,this.src=i,this.error=s,this.loading=n,this.bindType=r,this.attempt=0,this.cors=h,this.naturalHeight=0,this.naturalWidth=0,this.options=o,this.$parent=a,this.elRenderer=c,this.imageCache=l,this.performanceData={loadStart:0,loadEnd:0},this.filter(),this.initState(),this.render("loading",!1)}initState(){"dataset"in this.el?this.el.dataset.src=this.src:this.el.setAttribute("data-src",this.src),this.state={loading:!1,error:!1,loaded:!1,rendered:!1}}record(t){this.performanceData[t]=Date.now()}update({src:t,loading:i,error:s}){const n=this.src;this.src=t,this.loading=i,this.error=s,this.filter(),n!==this.src&&(this.attempt=0,this.initState())}checkInView(){const t=et(this.el);return t.top<window.innerHeight*this.options.preLoad&&t.bottom>this.options.preLoadTop&&t.left<window.innerWidth*this.options.preLoad&&t.right>0}filter(){Object.keys(this.options.filter).forEach(t=>{this.options.filter[t](this,this.options)})}renderLoading(t){this.state.loading=!0,tt({src:this.loading,cors:this.cors},()=>{this.render("loading",!1),this.state.loading=!1,t()},()=>{t(),this.state.loading=!1})}load(t=St){if(this.attempt>this.options.attempt-1&&this.state.error){t();return}if(!(this.state.rendered&&this.state.loaded)){if(this.imageCache.has(this.src))return this.state.loaded=!0,this.render("loaded",!0),this.state.rendered=!0,t();this.renderLoading(()=>{var i,s;this.attempt++,(s=(i=this.options.adapter).beforeLoad)==null||s.call(i,this,this.options),this.record("loadStart"),tt({src:this.src,cors:this.cors},n=>{this.naturalHeight=n.naturalHeight,this.naturalWidth=n.naturalWidth,this.state.loaded=!0,this.state.error=!1,this.record("loadEnd"),this.render("loaded",!1),this.state.rendered=!0,this.imageCache.add(this.src),t()},n=>{!this.options.silent&&console.error(n),this.state.error=!0,this.state.loaded=!1,this.render("error",!1)})})}}render(t,i){this.elRenderer(this,t,i)}performance(){let t="loading",i=0;return this.state.loaded&&(t="loaded",i=(this.performanceData.loadEnd-this.performanceData.loadStart)/1e3),this.state.error&&(t="error"),{src:this.src,state:t,time:i}}$destroy(){this.el=null,this.src=null,this.error=null,this.loading=null,this.bindType=null,this.attempt=0}}const wt="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7",je=["scroll","wheel","mousewheel","resize","animationend","transitionend","touchmove"],Me={rootMargin:"0px",threshold:0};function Ye(){return class{constructor({preLoad:t,error:i,throttleWait:s,preLoadTop:n,dispatchEvent:r,loading:a,attempt:o,silent:h=!0,scale:c,listenEvents:l,filter:u,adapter:f,observer:m,observerOptions:L}){this.mode=z.event,this.listeners=[],this.targetIndex=0,this.targets=[],this.options={silent:h,dispatchEvent:!!r,throttleWait:s||200,preLoad:t||1.3,preLoadTop:n||0,error:i||wt,loading:a||wt,attempt:o||3,scale:c||De(c),ListenEvents:l||je,supportWebp:Te(),filter:u||{},adapter:f||{},observer:!!m,observerOptions:L||Me},this.initEvent(),this.imageCache=new Re({max:200}),this.lazyLoadHandler=Pe(this.lazyLoadHandler.bind(this),this.options.throttleWait),this.setMode(this.options.observer?z.observer:z.event)}config(t={}){Object.assign(this.options,t)}performance(){return this.listeners.map(t=>t.performance())}addLazyBox(t){this.listeners.push(t),_&&(this.addListenerTarget(window),this.observer&&this.observer.observe(t.el),t.$el&&t.$el.parentNode&&this.addListenerTarget(t.$el.parentNode))}add(t,i,s){if(this.listeners.some(a=>a.el===t))return this.update(t,i),I(this.lazyLoadHandler);const n=this.valueFormatter(i.value);let{src:r}=n;I(()=>{r=Et(t,this.options.scale)||r,this.observer&&this.observer.observe(t);const a=Object.keys(i.modifiers)[0];let o;a&&(o=s.context.$refs[a],o=o?o.$el||o:document.getElementById(a)),o||(o=Ut(t));const h=new Ne({bindType:i.arg,$parent:o,el:t,src:r,loading:n.loading,error:n.error,cors:n.cors,elRenderer:this.elRenderer.bind(this),options:this.options,imageCache:this.imageCache});this.listeners.push(h),_&&(this.addListenerTarget(window),this.addListenerTarget(o)),this.lazyLoadHandler(),I(()=>this.lazyLoadHandler())})}update(t,i,s){const n=this.valueFormatter(i.value);let{src:r}=n;r=Et(t,this.options.scale)||r;const a=this.listeners.find(o=>o.el===t);a?a.update({src:r,error:n.error,loading:n.loading}):this.add(t,i,s),this.observer&&(this.observer.unobserve(t),this.observer.observe(t)),this.lazyLoadHandler(),I(()=>this.lazyLoadHandler())}remove(t){if(!t)return;this.observer&&this.observer.unobserve(t);const i=this.listeners.find(s=>s.el===t);i&&(this.removeListenerTarget(i.$parent),this.removeListenerTarget(window),W(this.listeners,i),i.$destroy())}removeComponent(t){t&&(W(this.listeners,t),this.observer&&this.observer.unobserve(t.el),t.$parent&&t.$el.parentNode&&this.removeListenerTarget(t.$el.parentNode),this.removeListenerTarget(window))}setMode(t){!bt&&t===z.observer&&(t=z.event),this.mode=t,t===z.event?(this.observer&&(this.listeners.forEach(i=>{this.observer.unobserve(i.el)}),this.observer=null),this.targets.forEach(i=>{this.initListen(i.el,!0)})):(this.targets.forEach(i=>{this.initListen(i.el,!1)}),this.initIntersectionObserver())}addListenerTarget(t){if(!t)return;let i=this.targets.find(s=>s.el===t);return i?i.childrenCount++:(i={el:t,id:++this.targetIndex,childrenCount:1,listened:!0},this.mode===z.event&&this.initListen(i.el,!0),this.targets.push(i)),this.targetIndex}removeListenerTarget(t){this.targets.forEach((i,s)=>{i.el===t&&(i.childrenCount--,i.childrenCount||(this.initListen(i.el,!1),this.targets.splice(s,1),i=null))})}initListen(t,i){this.options.ListenEvents.forEach(s=>(i?_e:Fe)(t,s,this.lazyLoadHandler))}initEvent(){this.Event={listeners:{loading:[],loaded:[],error:[]}},this.$on=(t,i)=>{this.Event.listeners[t]||(this.Event.listeners[t]=[]),this.Event.listeners[t].push(i)},this.$once=(t,i)=>{const s=(...n)=>{this.$off(t,s),i.apply(this,n)};this.$on(t,s)},this.$off=(t,i)=>{if(!i){if(!this.Event.listeners[t])return;this.Event.listeners[t].length=0;return}W(this.Event.listeners[t],i)},this.$emit=(t,i,s)=>{this.Event.listeners[t]&&this.Event.listeners[t].forEach(n=>n(i,s))}}lazyLoadHandler(){const t=[];this.listeners.forEach(i=>{(!i.el||!i.el.parentNode)&&t.push(i),i.checkInView()&&i.load()}),t.forEach(i=>{W(this.listeners,i),i.$destroy()})}initIntersectionObserver(){bt&&(this.observer=new IntersectionObserver(this.observerHandler.bind(this),this.options.observerOptions),this.listeners.length&&this.listeners.forEach(t=>{this.observer.observe(t.el)}))}observerHandler(t){t.forEach(i=>{i.isIntersecting&&this.listeners.forEach(s=>{if(s.el===i.target){if(s.state.loaded)return this.observer.unobserve(s.el);s.load()}})})}elRenderer(t,i,s){if(!t.el)return;const{el:n,bindType:r}=t;let a;switch(i){case"loading":a=t.loading;break;case"error":a=t.error;break;default:({src:a}=t);break}if(r?n.style[r]='url("'+a+'")':n.getAttribute("src")!==a&&n.setAttribute("src",a),n.setAttribute("lazy",i),this.$emit(i,t,s),this.options.adapter[i]&&this.options.adapter[i](t,this.options),this.options.dispatchEvent){const o=new CustomEvent(i,{detail:t});n.dispatchEvent(o)}}valueFormatter(t){let i=t,{loading:s,error:n}=this.options;return nt(t)&&({src:i}=t,s=t.loading||this.options.loading,n=t.error||this.options.error),{src:i,loading:s,error:n}}}}var Ue=e=>({props:{tag:{type:String,default:"div"}},emits:["show"],render(){return At(this.tag,this.show&&this.$slots.default?this.$slots.default():null)},data(){return{el:null,state:{loaded:!1},show:!1}},mounted(){this.el=this.$el,e.addLazyBox(this),e.lazyLoadHandler()},beforeUnmount(){e.removeComponent(this)},methods:{checkInView(){const t=et(this.$el);return _&&t.top<window.innerHeight*e.options.preLoad&&t.bottom>0&&t.left<window.innerWidth*e.options.preLoad&&t.right>0},load(){this.show=!0,this.state.loaded=!0,this.$emit("show",this)},destroy(){return this.$destroy}}});const Xe={selector:"img"};class Ve{constructor({el:t,binding:i,vnode:s,lazy:n}){this.el=null,this.vnode=s,this.binding=i,this.options={},this.lazy=n,this.queue=[],this.update({el:t,binding:i})}update({el:t,binding:i}){this.el=t,this.options=Object.assign({},Xe,i.value),this.getImgs().forEach(n=>{this.lazy.add(n,Object.assign({},this.binding,{value:{src:"dataset"in n?n.dataset.src:n.getAttribute("data-src"),error:("dataset"in n?n.dataset.error:n.getAttribute("data-error"))||this.options.error,loading:("dataset"in n?n.dataset.loading:n.getAttribute("data-loading"))||this.options.loading}}),this.vnode)})}getImgs(){return Array.from(this.el.querySelectorAll(this.options.selector))}clear(){this.getImgs().forEach(i=>this.lazy.remove(i)),this.vnode=null,this.binding=null,this.lazy=null}}class qe{constructor({lazy:t}){this.lazy=t,this.queue=[]}bind(t,i,s){const n=new Ve({el:t,binding:i,vnode:s,lazy:this.lazy});this.queue.push(n)}update(t,i,s){const n=this.queue.find(r=>r.el===t);n&&n.update({el:t,binding:i,vnode:s})}unbind(t){const i=this.queue.find(s=>s.el===t);i&&(i.clear(),W(this.queue,i))}}var Ge=e=>({props:{src:[String,Object],tag:{type:String,default:"img"}},render(){var t,i;return At(this.tag,{src:this.renderSrc},(i=(t=this.$slots).default)==null?void 0:i.call(t))},data(){return{el:null,options:{src:"",error:"",loading:"",attempt:e.options.attempt},state:{loaded:!1,error:!1,attempt:0},renderSrc:""}},watch:{src(){this.init(),e.addLazyBox(this),e.lazyLoadHandler()}},created(){this.init()},mounted(){this.el=this.$el,e.addLazyBox(this),e.lazyLoadHandler()},beforeUnmount(){e.removeComponent(this)},methods:{init(){const{src:t,loading:i,error:s}=e.valueFormatter(this.src);this.state.loaded=!1,this.options.src=t,this.options.error=s,this.options.loading=i,this.renderSrc=this.options.loading},checkInView(){const t=et(this.$el);return t.top<window.innerHeight*e.options.preLoad&&t.bottom>0&&t.left<window.innerWidth*e.options.preLoad&&t.right>0},load(t=St){if(this.state.attempt>this.options.attempt-1&&this.state.error){t();return}const{src:i}=this.options;tt({src:i},({src:s})=>{this.renderSrc=s,this.state.loaded=!0},()=>{this.state.attempt++,this.renderSrc=this.options.error,this.state.error=!0})}}});const si={install(e,t={}){const i=Ye(),s=new i(t),n=new qe({lazy:s});e.config.globalProperties.$Lazyload=s,t.lazyComponent&&e.component("LazyComponent",Ue(s)),t.lazyImage&&e.component("LazyImage",Ge(s)),e.directive("lazy",{beforeMount:s.add.bind(s),updated:s.update.bind(s),unmounted:s.remove.bind(s)}),e.directive("lazy-container",{beforeMount:n.bind.bind(n),updated:n.update.bind(n),unmounted:n.unbind.bind(n)})}};export{ei as I,si as L,ti as S,Je as a};
