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