import{g as s,S as n}from"./ScrollTrigger.C8IefbVz.js";class u{constructor(){this.initialized=!1,this.scrollTriggers=[],this.boundAnimate=this.animate.bind(this),this.boundResizeHandler=this.resizeHandler.bind(this),this.resizeTimer=null}init(){typeof window>"u"||(this.initialized&&this.destroy(),s.registerPlugin(n),this.initialized=!0,document.addEventListener("astro:page-load",this.boundAnimate),this.boundAnimate(),this.setupResizeHandler())}animate(){this.destroyTriggers();const e=document.querySelectorAll(".golden-thread-svg");e.length!==0&&(e.forEach(t=>{const d=t.querySelectorAll("[data-thread]"),a=t.closest("section")||t.parentElement;if(!a){console.warn("No parent section found for golden thread SVG");return}d.forEach(r=>{if(!(r instanceof SVGPathElement)){console.warn("Invalid golden thread element:",r);return}try{const i=r.getTotalLength(),l=r.getAttribute("data-thread")||"default";s.set(r,{strokeDasharray:i,strokeDashoffset:i});const h=n.create({trigger:a,start:"top 70%",end:"bottom 30%",scrub:this.getScrubValue(l),animation:s.to(r,{strokeDashoffset:0,ease:"power2.inOut"}),onRefresh:()=>{const c=r.getTotalLength();s.set(r,{strokeDasharray:c})}});this.scrollTriggers.push(h)}catch(i){console.error("Error animating golden thread:",i)}})}),n.refresh())}getScrubValue(e){return{main:1.5,secondary:1.2,default:1}[e]||1}destroyTriggers(){this.scrollTriggers.forEach(e=>{e&&typeof e.kill=="function"&&e.kill()}),this.scrollTriggers=[]}resizeHandler(){n.refresh(),this.scrollTriggers.forEach(e=>{e&&e.vars&&e.vars.onRefresh&&e.vars.onRefresh()})}setupResizeHandler(){window.addEventListener("resize",()=>{clearTimeout(this.resizeTimer),this.resizeTimer=setTimeout(()=>{this.boundResizeHandler()},200)})}destroy(){this.destroyTriggers(),document.removeEventListener("astro:page-load",this.boundAnimate),window.removeEventListener("resize",this.boundResizeHandler),this.resizeTimer&&(clearTimeout(this.resizeTimer),this.resizeTimer=null),this.initialized=!1}}if(typeof window<"u"){const o=new u;o.init(),window.goldenThreadAnimator=o}
