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