import{ay as P,J as a,L as g,i as S,a3 as W,a4 as L,az as I,aA as k,E as z,q as B,a$ as C,R as N,_ as $}from"./index-BRUnowC8.js";const q=30,F=2e3,U=4e3,M=1e3,V=P({__name:"MarqueeText",props:{sync:{},disabled:{type:Boolean}},setup(f){const e=a(null),n=a(null),m=a(0),y=a(0),c=a(0),u=a(!1),v=a(!1),h=a(!1),i=f;let s=i.sync?._registerAnimation();g(()=>i.sync,t=>{s!==void 0&&s.unregister(),s=t?._registerAnimation(),b()});const d=S(()=>Math.max(y.value-m.value,0)),o=S(()=>d.value/q*1e3),O=S(()=>({transform:`translateX(${-c.value}px)`,transition:u.value?`transform ${o.value}ms linear`:`transform ${M}ms ease-in-out`}));let r=null;const _=(t,l)=>Promise.race([new Promise(p=>setTimeout(p,t)),new Promise((p,E)=>l.addEventListener("abort",E,{once:!0}))]),b=async()=>{if(r&&!r.signal.aborted&&r.abort(),u.value=!1,c.value=0,i.disabled===!0||d.value<=0||o.value<=0||!v.value){s?.unregister();return}s?.setScrollingDuration(o.value),r=new AbortController;const t=r;try{for(await _(200,t.signal);!t.signal.aborted;){s!==void 0&&await Promise.race([s.sync(),new Promise((E,T)=>t.signal.addEventListener("abort",T,{once:!0}))]),u.value=!1,c.value=0;const p=(s?.maxDuration()??o.value)-o.value;await _((h.value?0:M+F)+p,t.signal),h.value=!1,u.value=!0,c.value=d.value,await _(o.value+U,t.signal)}}catch{u.value=!1,c.value=0}},D=new ResizeObserver(()=>{e.value&&(m.value=e.value.clientWidth)}),R=new MutationObserver(()=>{n.value&&(y.value=n.value.scrollWidth)}),w=new IntersectionObserver(t=>{const[l]=t;v.value=l.isIntersecting},{threshold:0}),x=()=>{N(()=>{!e.value||!n.value||(y.value=n.value.scrollWidth,m.value=e.value.clientWidth)}),!(!e.value||!n.value)&&(R.observe(n.value,{childList:!0,subtree:!0,characterData:!0,attributes:!0,attributeFilter:["style","class"]}),D.observe(e.value),w.observe(e.value))},A=()=>{r&&(r.abort(),r=null),s?.unregister(),R.disconnect(),D.disconnect(),w.disconnect(),v.value=!1};return W(()=>{i.disabled!==!0&&x()}),L(()=>{A()}),g([d,v,()=>i.disabled],()=>{b()},{flush:"post"}),g(()=>i.disabled,()=>{i.disabled===!0?A():(h.value=!0,x())}),(t,l)=>(k(),I("div",{ref_key:"containerRef",ref:e,class:"container"},[z("div",{ref_key:"scrollingRef",ref:n,class:"scrolling",style:B(O.value)},[C(t.$slots,"default",{},void 0,!0)],4)],512))}}),J=$(V,[["__scopeId","data-v-6e5989d8"]]);class Y{parentSync;id;promiseResolver=null;constructor(e){this.parentSync=e,this.id=Symbol()}setScrollingDuration(e){e>0?this.parentSync._componentDurations.set(this.id,e):this.unregister()}maxDuration(){return this.parentSync._componentDurations.size===0?0:Math.max(...this.parentSync._componentDurations.values())}sync(){return new Promise(e=>{this.promiseResolver=e,this.parentSync._pendingSync.push(e),this.parentSync._tryResolveWaiting()})}unregister(){if(this.promiseResolver){const e=this.parentSync._pendingSync.indexOf(this.promiseResolver);e>-1&&this.parentSync._pendingSync.splice(e,1),this.promiseResolver(),this.promiseResolver=null}this.parentSync._componentDurations.delete(this.id),this.parentSync._tryResolveWaiting()}}class X{_componentDurations;_pendingSync;constructor(){this._componentDurations=new Map,this._pendingSync=[]}_registerAnimation(){return new Y(this)}_tryResolveWaiting(){if(this._pendingSync?.length===this._componentDurations.size){const e=this._pendingSync;this._pendingSync=[];for(const n of e)n()}}}export{J as M,X as a};
