import{t,i,e,d,r,p}from"./chunk-p42kdtn4.js";import{f}from"./chunk-92mz45yw.js";var b=(o)=>{let l=Number.parseFloat(o??"");return Number.isFinite(l)&&l>0?l:0},v="roll-text";function w(o,l){l.forEach((c,g)=>{let n=c;n.classList.add("roll-text_char"),n.style.setProperty("--roll-dir",g%2===0?"-1":"1")}),o.style.setProperty("--roll-icon-char",String(l.length+1))}var T="data-roll-enter-state",x=["--roll-on","--roll-stagger-on","--roll-duration"],S=v;function H(o,l){let c=o.querySelector("[data-roll-label]"),g=!o.classList.contains(S),n=null,u=null,h=0,L=0,E=null,P=l.rollEnter!==void 0,m=()=>{x.forEach((s)=>o.style.removeProperty(s)),o.setAttribute(T,"done")},R=(s)=>{let y=getComputedStyle(o).getPropertyValue(s).trim(),a=Number.parseFloat(y);if(!Number.isFinite(a))return 0;return y.endsWith("ms")?a/1000:a},A=()=>{o.style.setProperty("--roll-on","2"),o.style.setProperty("--roll-stagger-on","1"),o.style.setProperty("--roll-duration","var(--motion--duration-slowest)"),o.setAttribute(T,"ready");let s=()=>{let a=n?.chars.length??0,M=R("--roll-duration")+R("--roll-stagger")*(a+1);o.style.setProperty("--roll-on","0"),o.setAttribute(T,"playing"),h=window.setTimeout(m,M*1000+50)},y=()=>{u=t.create({trigger:o,start:l.rollEnterStart||"top 90%",once:!0,onEnter:()=>{let a=b(l.rollDelay)*1000;L=window.setTimeout(s,a)}})};E=p(l.rollAfter,y)},_=(s)=>{w(o,s)},C=()=>{if(!c){if(P)m();return}if(n=f(c,{type:"chars",onSplit:(s)=>{_(s.chars)}}),P&&!u)if(i)m();else A()};e(()=>{o.classList.add(S)}),d(C),r(()=>{if(u?.kill(),u=null,window.clearTimeout(h),window.clearTimeout(L),E?.(),E=null,x.forEach((s)=>o.style.removeProperty(s)),o.removeAttribute(T),n?.revert(),n=null,o.style.removeProperty("--roll-icon-char"),g)o.classList.remove(S)})}export{H as default};