import{t,i,n,c,m,e,d,r,u,U,p}from"./chunk-p42kdtn4.js";import{_,v,h,f}from"./chunk-92mz45yw.js";var Me=(l)=>Number.parseFloat(getComputedStyle(l).fontSize)*0.3,B=(l)=>{let a=Me(l),T=l.getBoundingClientRect().height+a;return{hidden:`inset(${-T}px ${-a}px ${T}px ${-a}px)`,visible:`inset(${-a}px ${-a}px ${-a}px ${-a}px)`,exited:`inset(${T}px ${-a}px ${-T}px ${-a}px)`}};var we=1500,Le=3,Ae=0.5,Ce=0.02,ae=()=>`+=${Math.max(1,Math.min(c.height*Ae,t.maxScroll(window)))}`,_e=()=>`top top-=${Math.max(1,Math.min(c.height*Ce,t.maxScroll(window)-1))}`;function se(l,a={}){let{ease:T="none",snap:x,instantStart:E=!0,onToggle:A}=a,b=!1,w=null,X=()=>a.duration??l.duration(),G=(s)=>{let S=l.progress(),y=S>0?S-0.0001:0.0001;l.progress(y).progress(s)},K=(s,S)=>{w?.kill(),w=null;let y=b?1:0,L=Math.abs(y-l.progress());if(s||i||x?.()||L===0)return G(y),!0;return w=n.to(l,{progress:y,duration:X()*L/S,ease:T,overwrite:!0,onComplete:()=>{w=null}}),!1},H=(s,S=!1,y=0)=>{if(s===b&&(!S||w))return;let L=s!==b;b=s;let O=K(S,n.utils.clamp(1,Le,Math.abs(y)/we));if(L||O)A?.(b,O)},k=t.create({trigger:document.documentElement,start:_e,end:"max",invalidateOnRefresh:!0,onEnter:(s)=>H(!0,!1,s.getVelocity()),onLeaveBack:(s)=>H(!1,!1,s.getVelocity())}),I=()=>k.scroll()>=k.start;return H(I(),E),{get on(){return b},sync:(s=!0)=>H(I(),s),kill:()=>{k.kill(),w?.kill(),w=null}}}var Oe="5%",ie=110,ce="power2.inOut",Pe=0.5,Re=0.6,ue=new Set(["P","H1","H2","H3","H4","H5","H6","BLOCKQUOTE","PRE","LI","FIGCAPTION"]),He=Array.from(ue).join(","),ke=new Set(["SCRIPT","STYLE","NOSCRIPT","TEMPLATE","IFRAME","VIDEO","AUDIO","CANVAS","SVG"]),De=(l,a,T)=>{let x=l?.trim().toLowerCase();return a.includes(x)?x:T},W=(l,a,T,x)=>{let E=Number.parseFloat(l??"");return Number.isFinite(E)?Math.min(x,Math.max(T,E)):a},Z=(l)=>_(l.textContent),Ie=(l)=>Array.from(l.childNodes).some((a)=>a.nodeType===Node.TEXT_NODE&&_(a.textContent)),Ne=(l)=>l.querySelector(He)!==null,ge=(l)=>h(l)||Ie(l)||!Ne(l),Fe=(l)=>{let a=[],T=(x)=>{Array.from(x.children).forEach((E)=>{if(!(E instanceof HTMLElement))return;if(ke.has(E.tagName)||!Z(E))return;if(ue.has(E.tagName)||ge(E)){a.push(E);return}T(E)})};return T(l),a},Be=(l)=>Array.from(l.querySelectorAll(":scope.w-dyn-items > .w-dyn-item, :scope > .w-dyn-items > .w-dyn-item")).filter(Z),Ge=(l)=>{if(!Z(l))return[];let a=Be(l);if(a.length)return a;if(ge(l))return[l];let T=Fe(l);return T.length?T:[l]};function $e(l,a={}){let T=Ge(l);if(!T.length){e(()=>{l.dataset.revealTextState="empty"}),r(()=>{delete l.dataset.revealTextState});return}let x=v(a.revealTextType);l.dataset.revealTextMode=x;let E=a.revealTextTrigger?.trim().toLowerCase(),A=E==="load"||E!==void 0&&U(E)?E:"inview",b=W(a.revealTextDuration,m.in.duration,0.2,2),w=W(a.revealTextStagger,m.stagger[x],0,0.2),X=De(a.revealTextFrom,["start","end","center","edges","random"],"start"),G={each:w,from:X},K=a.revealTextStagger===void 0?m.stagger.items:w,H=W(a.revealTextDelay,0,0,5),k=a.revealTextExit?.trim().toLowerCase()==="scroll",I=k&&a.revealTextPin!==void 0,s=[],S=[],y=null,L=0,O=null,q=A!=="inview"&&A!=="load",V=!q,z=null,Y=null,P=!1,R=!1,ee=!1,pe=new Set(["pending","splitting"]),M=(o)=>{if(l.dataset.revealTextState=o,q&&pe.has(o))l.dataset.revealTextGated="";else delete l.dataset.revealTextGated},de=()=>n.timeline({scrollTrigger:{trigger:document.documentElement,start:"top top",end:ae,scrub:!0,invalidateOnRefresh:!0}}),te=(o,g)=>{let C=o.toggle!==null;return o.toggle?.kill(),o.animation=g,o.toggle=se(g,{duration:g.duration()*Pe,instantStart:C}),g},ne=()=>n.timeline({paused:!0}),me=()=>{if(!I||y)return;let o=de(),g=()=>o.scrollTrigger?o.scrollTrigger.end-o.scrollTrigger.start:0;o.fromTo(l,{y:0},{y:g,ease:"none"}),y=o},Te=()=>{y?.kill(),y=null,n.set(l,{clearProps:"transform"})},Ee=()=>{S.forEach((o)=>{if(o.toggle?.kill(),o.toggle=null,o.animation?.kill(),o.animation=null,o.split)o.split.revert();else n.set(o.target,{clearProps:"transform,opacity"})}),S=[]},re=()=>{if(!k||ee||S.length>0)return;S=T.map((o)=>{let g={target:o,split:null,animation:null,toggle:null};if(!h(o))return te(g,ne().to(o,{...I&&o===l?{}:{y:"-0.75em"},opacity:0,duration:b,ease:ce})),g;return g.split=f(o,{type:x,onSplit:({items:C})=>te(g,ne().fromTo(C,{yPercent:0,clipPath:(F,D)=>B(D).visible},{yPercent:-ie,clipPath:(F,D)=>B(D).exited,duration:b,stagger:G,ease:ce}))}),g})},fe=()=>{if(R)return;R=!0,N?.stop(),s.forEach((o)=>{o.target.removeAttribute("data-reveal-text-target")}),M("complete"),re()},j=(o,g)=>{if(o.done)return;if(o.done=!0,o.animation=null,g)g.revert(),o.split=null;else n.set(o.target,{clearProps:"transform,opacity,willChange"});if(o.target.removeAttribute("data-reveal-text-target"),L-=1,L<=0)fe()},oe=()=>{if(R||P)return;P=!0,M("running"),s.forEach((o)=>o.animation?.play())},xe=()=>{if(V)return;V=!0,oe()},N=A==="inview"?u(l,{autoStart:!1,once:!0,threshold:0,offset:a.revealTextOffset||Oe,callback:({isIn:o})=>{if(!o)return;Y=p("preloader",oe)}}):null,Q=()=>{if(N?.stop(),Ee(),Te(),s.forEach((o)=>{if(o.animation?.kill(),o.animation=null,o.split?.revert(),o.split=null,o.mode==="block")n.set(o.target,{clearProps:"transform,opacity,willChange"});o.target.removeAttribute("data-reveal-text-target")}),s=[],L=0,!R)P=!1,M("idle")},ve=(o,g)=>{let C=f(o.target,{type:x,onSplit:({items:F,handle:D})=>{if(!F.length){j(o,D);return}let le=n.fromTo(F,{yPercent:ie,clipPath:(be,J)=>B(J).hidden},{yPercent:0,clipPath:(be,J)=>B(J).visible,duration:b,stagger:G,delay:g,ease:m.in.ease,paused:!P,onStart:()=>{M("running"),n.set(F,{willChange:"transform,clip-path"})},onComplete:()=>j(o,D)});return o.animation=le,le}});o.split=o.done?null:C},Se=(o,g)=>{o.animation=n.from(o.target,{y:"0.75em",opacity:0,duration:b,delay:g,ease:m.in.ease,paused:!P,onStart:()=>{M("running"),n.set(o.target,{willChange:"transform,opacity"})},onComplete:()=>j(o)})},he=()=>{if(me(),R){M("complete"),re();return}P=A==="load"||q&&V,M("splitting"),s=T.map((o)=>({target:o,mode:h(o)?"split":"block",split:null,animation:null,done:!1})),L=s.length;try{if(s.forEach((o,g)=>{o.target.dataset.revealTextTarget="";let C=H+Math.min(g*K,Re);if(o.mode==="split")ve(o,C);else Se(o,C)}),M(P?"running":"ready"),A==="inview")N?.start()}catch(o){Q(),R=!0,M("error"),console.warn("[reveal-text] SplitText initialization failed",o)}},ye=()=>{if(i){R=!0,N?.stop(),M("reduced");return}O=n.context(()=>(he(),Q),l)};e(()=>{if(!V)z=p(A,xe);M("pending")}),d(ye),r(()=>{if(ee=!0,z?.(),z=null,Y?.(),Y=null,O)O.revert(),O=null;else Q();N?.destroy(),delete l.dataset.revealTextState,delete l.dataset.revealTextMode,delete l.dataset.revealTextGated})}export{$e as default};