{
  "version": 3,
  "sources": ["ssg:https://framerusercontent.com/modules/rJporMW2N2hibV1UFZHh/y3l0m54xbr0lYJeV6jIq/WithFocus.js"],
  "sourcesContent": ["import{jsx as _jsx}from\"react/jsx-runtime\";import{useEffect,useRef,useCallback}from\"react\";/**\n * Helper function that finds the next header element (h1-h6) after a given target element.\n */function findNextHeader(targetEl){// Get all headers on the page\nconst headers=Array.from(document.querySelectorAll(\"h1, h2, h3, h4, h5, h6\"));// Get the target's top position relative to the document\nconst targetTop=targetEl.getBoundingClientRect().top+window.scrollY;// Filter for headers that come after the target element\nconst nextHeaders=headers.filter(header=>{const headerTop=header.getBoundingClientRect().top+window.scrollY;return headerTop>targetTop;});if(nextHeaders.length===0)return null;// Sort headers by their top offset and return the first one\nnextHeaders.sort((a,b)=>{const aTop=a.getBoundingClientRect().top+window.scrollY;const bTop=b.getBoundingClientRect().top+window.scrollY;return aTop-bTop;});return nextHeaders[0];}// Define a higher-order component that moves focus within the page\nexport function withInPageFocus(Component){return function FocusWrapper(props){const containerRef=useRef(null);const targetRef=useRef(null);const targetHeaderRef=useRef(null);console.log(\"withInPageFocus props\");console.log(props);// @ts-expect-error\nconst{link,href,...restProps}=props;const targetId=link?.split(\"#\")[1]??href?.split(\"#\")[1]??\"\";useEffect(()=>{targetRef.current=document.getElementById(targetId);targetHeaderRef.current=findNextHeader(document.getElementById(targetId));},[]);useEffect(()=>{console.log(\"printing targetRef\",targetRef.current);console.log(\"printing headerRef\",targetHeaderRef.current);},[targetRef.current,targetHeaderRef.current]);const handleClick=useCallback(event=>{// Prevent the default in-page jump behavior\nevent.preventDefault();if(!targetRef.current)return;targetRef.current.scrollIntoView({behavior:\"instant\"});targetHeaderRef.current.focus();},[targetId]);return /*#__PURE__*/_jsx(Component,{...restProps,role:\"link\",onClick:handleClick});};}export function withInPageFocus2(Component){return function FocusWrapper(props){console.log(\"withInPageFocus2 props\");console.log(props);return /*#__PURE__*/_jsx(Component,{...props});};}\nexport const __FramerMetadata__ = {\"exports\":{\"withInPageFocus\":{\"type\":\"reactHoc\",\"name\":\"withInPageFocus\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withInPageFocus2\":{\"type\":\"reactHoc\",\"name\":\"withInPageFocus2\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./WithFocus.map"],
  "mappings": "uGAEG,SAASA,EAAeC,EAAS,CACpC,IAAMC,EAAQ,MAAM,KAAK,SAAS,iBAAiB,wBAAwB,CAAC,EACtEC,EAAUF,EAAS,sBAAsB,EAAE,IAAIG,EAAO,QACtDC,EAAYH,EAAQ,OAAOI,GAAyBA,EAAO,sBAAsB,EAAE,IAAIF,EAAO,QAAyBD,CAAW,EAAE,OAAGE,EAAY,SAAS,EAAS,MAC3KA,EAAY,KAAK,CAACE,EAAEC,IAAI,CAAC,IAAMC,EAAKF,EAAE,sBAAsB,EAAE,IAAIH,EAAO,QAAcM,EAAKF,EAAE,sBAAsB,EAAE,IAAIJ,EAAO,QAAQ,OAAOK,EAAKC,CAAK,CAAC,EAASL,EAAY,CAAC,EAAE,CAC5K,SAASM,EAAgBC,EAAU,CAAC,OAAO,SAAsBC,EAAM,CAAC,IAAMC,EAAaC,EAAO,IAAI,EAAQC,EAAUD,EAAO,IAAI,EAAQE,EAAgBF,EAAO,IAAI,EAAE,QAAQ,IAAI,uBAAuB,EAAE,QAAQ,IAAIF,CAAK,EACrO,GAAK,CAAC,KAAAK,EAAK,KAAAC,EAAK,GAAGC,CAAS,EAAEP,EAAYQ,EAASH,GAAM,MAAM,GAAG,EAAE,CAAC,GAAGC,GAAM,MAAM,GAAG,EAAE,CAAC,GAAG,GAAGG,EAAU,IAAI,CAACN,EAAU,QAAQ,SAAS,eAAeK,CAAQ,EAAEJ,EAAgB,QAAQjB,EAAe,SAAS,eAAeqB,CAAQ,CAAC,CAAE,EAAE,CAAC,CAAC,EAAEC,EAAU,IAAI,CAAC,QAAQ,IAAI,qBAAqBN,EAAU,OAAO,EAAE,QAAQ,IAAI,qBAAqBC,EAAgB,OAAO,CAAE,EAAE,CAACD,EAAU,QAAQC,EAAgB,OAAO,CAAC,EAAE,IAAMM,EAAYC,EAAYC,GAAO,CACpcA,EAAM,eAAe,EAAMT,EAAU,UAAeA,EAAU,QAAQ,eAAe,CAAC,SAAS,SAAS,CAAC,EAAEC,EAAgB,QAAQ,MAAM,EAAE,EAAE,CAACI,CAAQ,CAAC,EAAE,OAAoBK,EAAKd,EAAU,CAAC,GAAGQ,EAAU,KAAK,OAAO,QAAQG,CAAW,CAAC,CAAE,CAAE",
  "names": ["findNextHeader", "targetEl", "headers", "targetTop", "window", "nextHeaders", "header", "a", "b", "aTop", "bTop", "withInPageFocus", "Component", "props", "containerRef", "pe", "targetRef", "targetHeaderRef", "link", "href", "restProps", "targetId", "ue", "handleClick", "te", "event", "p"]
}
