Loading
function(e,t,i){i.d(t,{W:()=>a,t:()=>l});var s=i(477900),n=i(582128),o=i(121894);class r{registeredNodes=new Map;visibleComponents=new Set;animatingComponents=new Set;observer;constructor(e=!1){if(e)return;this.observer=new window.IntersectionObserver(e=>{(0,o.r)(()=>{e.forEach(e=>{let t=this.registeredNodes.get(e.target);null==t||(e.intersectionRatio>=.7?this.handleVisible(e,t):this.handleNotVisible(e,t))})})},{threshold:.7})}handleVisible(e,t){if(this.visibleComponents.has(e.target))return;let i=Math.abs(e.intersectionRect.bottom-Number(e.rootBounds?.bottom))<Math.abs(e.intersectionRect.top-Number(e.rootBounds?.top));i?this.visibleComponents=new Set([e.target,...this.visibleComponents]):this.visibleComponents.add(e.target);let s=i||this.animatingComponents.size<100;s?this.animatingComponents.add(e.target):this.animatingComponents.delete(e.target),t.updateState(s),s&&this.visibleComponents.size>100&&this.stopNodeFromAnimating()}handleNotVisible(e,t){this.visibleComponents.has(e.target)&&(t.updateState(!1),this.visibleComponents.delete(e.target),this.animatingComponents.delete(e.target),this.potentiallyAnimateNewNode())}stopNodeFromAnimating(){let e=Array.from(this.visibleComponents);for(let t=e.length-1;t>=0;t--){let i=e[t];if(this.animatingComponents.has(i)){let e=this.registeredNodes.get(i);e?.updateState(!1),this.animatingComponents.delete(i);return}}}potentiallyAnimateNewNode(){if(this.animatingComponents.size<100&&this.visibleComponents.size>this.animatingComponents.size){for(let e of this.visibleComponents)if(!this.animatingComponents.has(e)){let t=this.registeredNodes.get(e);t?.updateState(!0),this.animatingComponents.add(e);return}}}registerNode(e,t){if(this.registeredNodes.has(e))throw Error("ThoughtfullyAnimated.registeredNode: Unable to register an already registered node...");return this.registeredNodes.set(e,{updateState:t}),this.observer?.observe(e),()=>{this.unregisterNode(e)}}unregisterNode(e){this.registeredNodes.delete(e),this.animatingComponents.delete(e),this.visibleComponents.delete(e),this.observer?.unobserve(e),this.potentiallyAnimateNewNode()}cleanUp(){this.observer?.disconnect(),this.registeredNodes.clear(),this.visibleComponents.clear()}}let a=n.createContext({manager:new r(!0),useThoughtfullyAnimated:()=>({animate:!0,registerRef:()=>{}})});function l(e){let{children:t}=e,[i]=n.useState(()=>{let e=new r;return{manager:e,useThoughtfullyAnimated(){let t=n.useRef(null),[i,s]=n.useState(!1);return{animate:i,registerRef:n.useCallback(i=>{null!=t.current&&e.unregisterNode(t.current),t.current=i,null!=t.current&&e.registerNode(t.current,s)},[])}}}});return n.useEffect(()=>()=>i.manager.cleanUp(),[i.manager]),(0,s.jsx)(a.Provider,{value:i,children:t})}}