{"version":3,"file":"withExtenalTrackingLink.fGeoKFaU.mjs","names":["useRef"],"sources":["https:/framerusercontent.com/modules/8UwtyVA7VFojGLKjD7dg/84NoU4Yv4guZt1ngoRKI/withExtenalTrackingLink.js"],"sourcesContent":["import{jsx as _jsx}from\"react/jsx-runtime\";import{useEffect,useRef}from\"react\";export function withExtenalTrackingLink(Component){return props=>{const localRef=useRef(null);useEffect(()=>{const element=localRef.current;if(!element){return;}let cancelled=false;let observer=null;let retryTimer=null;const apply=()=>{if(cancelled){return;}const did=window?.posthog?.get_distinct_id?.();if(!did){return false;}findTarget(element).forEach(a=>applyTracking(a,did));return true;};// 1) Try immediately\nif(!apply()){// 2) Small retry loop if PostHog not ready yet\nlet attempts=0;const tick=()=>{if(apply()||attempts++>10){return;// ~10 retries\n}retryTimer=window.setTimeout(tick,150);};tick();}// 3) Watch for href/DOM changes and re-apply\nobserver=new MutationObserver(()=>apply());observer.observe(element,{subtree:true,childList:true,attributes:true,attributeFilter:[\"href\"]});// 4) Click-time safety net\nconst onClick=e=>{const did=window?.posthog?.get_distinct_id?.();if(!did){return;}const target=e.target;const a=target?.closest?.(\"a[href]\");if(a){applyTracking(a,did);}};element.addEventListener(\"click\",onClick,{capture:true});return()=>{cancelled=true;if(observer){observer.disconnect();}if(retryTimer){window.clearTimeout(retryTimer);}element.removeEventListener(\"click\",onClick,{capture:true});};},[]);// Make sure the ref reaches the real <a>. If the inner component already forwards a ref,\n// you can merge them; otherwise rely on localRef.\nreturn /*#__PURE__*/_jsx(Component,{...props,ref:localRef});};}function findTarget(root){if(root instanceof HTMLAnchorElement&&root.hasAttribute(\"href\")){return[root];}return Array.from(root.querySelectorAll(\"a[href]\"));}function applyTracking(element,did){try{const href=element.getAttribute(\"href\");if(!href){return;}const url=new URL(href,window.location.origin);if(!/^https?:$/.test(url.protocol)){return;}if(url.searchParams.get(\"did\")===did){return;}url.searchParams.set(\"did\",did);element.setAttribute(\"href\",url.toString());}catch(error){// ignoring invalid hrefs (e.g., javascript:, malformed, etc.)\n}}\nexport const __FramerMetadata__ = {\"exports\":{\"withExtenalTrackingLink\":{\"type\":\"reactHoc\",\"name\":\"withExtenalTrackingLink\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./withExtenalTrackingLink.map"],"mappings":"2MAA+E,SAAgB,EAAwB,EAAU,CAAC,MAAO,IAAO,CAAC,IAAM,EAASA,EAAO,KAAK,CAO5K,OAP6K,MAAc,CAAC,IAAM,EAAQ,EAAS,QAAQ,GAAG,CAAC,EAAS,OAAQ,IAAI,EAAU,GAAU,EAAS,KAAS,EAAW,KAAW,MAAU,CAAC,GAAG,EAAW,OAAQ,IAAM,EAAI,GAAQ,SAAS,mBAAmB,CAA6E,OAAxE,GAAmB,EAAW,EAAQ,CAAC,QAAQ,GAAG,EAAc,EAAE,EAAI,CAAC,CAAQ,IAAnE,IAChZ,GAAG,CAAC,GAAO,CAAC,CACZ,IAAI,EAAS,EAAQ,MAAS,CAAI,GAAO,EAAE,IAAW,KACrD,EAAW,EAAO,WAAW,EAAK,IAAI,GAAG,GAAM,CAChD,EAAS,IAAI,qBAAqB,GAAO,CAAC,CAAC,EAAS,QAAQ,EAAQ,CAAC,QAAQ,GAAK,UAAU,GAAK,WAAW,GAAK,gBAAgB,CAAC,OAAO,CAAC,CAAC,CAC3I,IAAM,EAAQ,GAAG,CAAC,IAAM,EAAI,GAAQ,SAAS,mBAAmB,CAAC,GAAG,CAAC,EAAK,OAA8B,IAAM,EAAf,EAAE,QAAuB,UAAU,UAAU,CAAI,GAAG,EAAc,EAAE,EAAI,EAA6D,OAAzD,EAAQ,iBAAiB,QAAQ,EAAQ,CAAC,QAAQ,GAAK,CAAC,KAAW,CAAC,EAAU,GAAQ,GAAU,EAAS,YAAY,CAAK,GAAY,EAAO,aAAa,EAAW,CAAE,EAAQ,oBAAoB,QAAQ,EAAQ,CAAC,QAAQ,GAAK,CAAC,GAAK,EAAE,CAAC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