{"version":3,"file":"ScrollPositionOverrides.DBjXmA4T.mjs","names":["useCallback"],"sources":["https:/framerusercontent.com/modules/Kq2EyMXInYJMNhUnr8UG/ugXtwvATyxSEW1oZLn7U/ScrollPositionOverrides.js"],"sourcesContent":["import{jsx as _jsx}from\"react/jsx-runtime\";import{forwardRef,useCallback,useEffect}from\"react\";// User request: Create two Framer code overrides to preserve Collection page scroll position between /artworks and /artworks/[slug] detail pages, including browser back and a back-link fallback.\nconst SCROLL_KEY=\"khair.collection.scrollY\";const RESTORE_FLAG_KEY=\"khair.collection.restorePending\";const COLLECTION_PATH=\"/artworks\";const NAV_FOCUS_CLASS=\"khair-nav-focus-scope\";const NAV_FOCUS_STYLE_ID=\"khair-nav-focus-style\";const NAV_ACTIVE_CLASS=\"khair-nav-active\";function isBrowser(){return typeof window!==\"undefined\"&&typeof document!==\"undefined\";}function readStoredScrollY(){if(!isBrowser())return null;try{const raw=window.sessionStorage?.getItem(SCROLL_KEY);if(!raw)return null;const parsed=Number(raw);return Number.isFinite(parsed)?parsed:null;}catch{return null;}}function writeStoredScrollY(value){if(!isBrowser())return;try{window.sessionStorage?.setItem(SCROLL_KEY,String(Math.max(0,Math.round(value))));}catch{// no-op\n}}function setRestorePending(){if(!isBrowser())return;try{window.sessionStorage?.setItem(RESTORE_FLAG_KEY,\"1\");}catch{// no-op\n}}function clearRestorePending(){if(!isBrowser())return;try{window.sessionStorage?.removeItem(RESTORE_FLAG_KEY);}catch{// no-op\n}}function getRestorePending(){if(!isBrowser())return false;try{return window.sessionStorage?.getItem(RESTORE_FLAG_KEY)===\"1\";}catch{return false;}}function isCollectionPath(pathname){return pathname===COLLECTION_PATH;}function isArtworkDetailPath(pathname){return pathname.startsWith(`${COLLECTION_PATH}/`)&&pathname!==COLLECTION_PATH;}function getAnchorFromEventTarget(target){if(!isBrowser()||!(target instanceof Element))return null;return target.closest(\"a[href]\");}export function CollectionScrollMemory(Component){return /*#__PURE__*/forwardRef(function CollectionScrollMemoryOverride(props,ref){const restoreScrollIfNeeded=useCallback(()=>{if(!isBrowser())return;if(!isCollectionPath(window.location.pathname))return;const storedY=readStoredScrollY();if(storedY==null)return;let attempts=0;const maxAttempts=10;const tick=()=>{if(!isBrowser())return;window.scrollTo(0,storedY);attempts+=1;if(attempts<maxAttempts){window.setTimeout(()=>{window.requestAnimationFrame(tick);},80);}else{clearRestorePending();}};window.requestAnimationFrame(tick);},[]);useEffect(()=>{if(!isBrowser())return;const shouldRestore=isCollectionPath(window.location.pathname)&&(getRestorePending()||readStoredScrollY()!==null);if(shouldRestore){restoreScrollIfNeeded();}const saveCurrentScroll=()=>{if(!isBrowser())return;writeStoredScrollY(window.scrollY||window.pageYOffset||0);};const handlePageHide=()=>{saveCurrentScroll();};const handleBeforeUnload=()=>{saveCurrentScroll();};window.addEventListener(\"pagehide\",handlePageHide);window.addEventListener(\"beforeunload\",handleBeforeUnload);return()=>{window.removeEventListener(\"pagehide\",handlePageHide);window.removeEventListener(\"beforeunload\",handleBeforeUnload);};},[restoreScrollIfNeeded]);const onClickCapture=useCallback(event=>{props?.[\"onClickCapture\"]?.(event);if(!isBrowser())return;const anchor=getAnchorFromEventTarget(event?.target??null);if(!anchor)return;try{const url=new URL(anchor.getAttribute(\"href\")||\"\",window.location.href);if(url.origin!==window.location.origin)return;if(isArtworkDetailPath(url.pathname)){writeStoredScrollY(window.scrollY||window.pageYOffset||0);setRestorePending();}}catch{// no-op\n}},[props]);return /*#__PURE__*/_jsx(Component,{ref:ref,...props,onClickCapture:onClickCapture});});}export function BackToCollectionPosition(Component){return /*#__PURE__*/forwardRef(function BackToCollectionPositionOverride(props,ref){const onClick=useCallback(event=>{if(event?.preventDefault)event.preventDefault();props?.[\"onClick\"]?.(event);if(!isBrowser())return;const storedY=readStoredScrollY();const hasStored=storedY!==null;const canGoBack=window.history.length>1;if(hasStored&&canGoBack){setRestorePending();window.history.back();return;}writeStoredScrollY(hasStored?storedY:0);setRestorePending();window.location.assign(COLLECTION_PATH);},[props]);return /*#__PURE__*/_jsx(Component,{ref:ref,...props,onClick:onClick});});}export function NavigationLinkFocus(Component){return /*#__PURE__*/forwardRef(function NavigationLinkFocusOverride(props,ref){const updateActiveNavLinks=useCallback(()=>{if(!isBrowser())return;const normalizePath=pathname=>{if(!pathname)return\"/\";if(pathname===\"/\")return\"/\";return pathname.endsWith(\"/\")?pathname.slice(0,-1):pathname;};const currentPath=normalizePath(window.location.pathname);const wrappers=document.querySelectorAll(`.${NAV_FOCUS_CLASS}`);wrappers.forEach(wrapper=>{const links=wrapper.querySelectorAll(\"a[href]\");links.forEach(link=>{if(!(link instanceof HTMLAnchorElement))return;let targetPath=\"\";try{const targetUrl=new URL(link.getAttribute(\"href\")||\"\",window.location.href);if(targetUrl.origin!==window.location.origin){link.classList.remove(NAV_ACTIVE_CLASS);return;}targetPath=normalizePath(targetUrl.pathname);}catch{link.classList.remove(NAV_ACTIVE_CLASS);return;}let isActive=false;if(currentPath===\"/\"){isActive=targetPath===\"/\";}else if(currentPath.startsWith(\"/artworks/\")){isActive=targetPath===\"/artworks\";}else if(currentPath.startsWith(\"/artists/\")){isActive=targetPath===\"/artists\";}else{isActive=targetPath===currentPath;}if(isActive){link.classList.add(NAV_ACTIVE_CLASS);}else{link.classList.remove(NAV_ACTIVE_CLASS);}});});},[]);useEffect(()=>{if(!isBrowser())return;if(document.getElementById(NAV_FOCUS_STYLE_ID))return;const styleTag=document.createElement(\"style\");styleTag.id=NAV_FOCUS_STYLE_ID;styleTag.textContent=`\n                .${NAV_FOCUS_CLASS} a:focus-visible {\n                    outline: 1px solid currentColor;\n                    outline-offset: 4px;\n                    text-decoration: underline;\n                    text-underline-offset: 4px;\n                }\n                .${NAV_FOCUS_CLASS} a.${NAV_ACTIVE_CLASS} {\n                    text-decoration: underline;\n                    text-underline-offset: 4px;\n                    text-decoration-thickness: 1px;\n                }\n            `;document.head.appendChild(styleTag);},[]);useEffect(()=>{if(!isBrowser())return;const updateSoon=()=>{window.requestAnimationFrame(()=>{updateActiveNavLinks();});};updateSoon();const handleClick=()=>{updateSoon();};const handlePopState=()=>{updateSoon();};document.addEventListener(\"click\",handleClick,true);window.addEventListener(\"popstate\",handlePopState);return()=>{document.removeEventListener(\"click\",handleClick,true);window.removeEventListener(\"popstate\",handlePopState);};},[updateActiveNavLinks]);const className=typeof props?.className===\"string\"&&props.className.includes(NAV_FOCUS_CLASS)?props.className:props?.className?`${props.className} ${NAV_FOCUS_CLASS}`:NAV_FOCUS_CLASS;return /*#__PURE__*/_jsx(Component,{ref:ref,...props,className:className});});}\nexport const __FramerMetadata__ = {\"exports\":{\"NavigationLinkFocus\":{\"type\":\"reactHoc\",\"name\":\"NavigationLinkFocus\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"CollectionScrollMemory\":{\"type\":\"reactHoc\",\"name\":\"CollectionScrollMemory\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"BackToCollectionPosition\":{\"type\":\"reactHoc\",\"name\":\"BackToCollectionPosition\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./ScrollPositionOverrides.map"],"mappings":"8IACgR,SAAS,GAAW,CAAC,OAAc,IAAS,QAAa,OAAO,SAAW,IAAa,SAAS,GAAmB,CAAC,GAAG,CAAC,GAAW,CAAC,OAAO,KAAK,GAAG,CAAC,IAAM,EAAI,EAAO,gBAAgB,QAAQ,EAAW,CAAC,GAAG,CAAC,EAAI,OAAO,KAAK,IAAM,EAAO,OAAO,EAAI,CAAC,OAAO,OAAO,SAAS,EAAO,CAAC,EAAO,UAAW,CAAC,OAAO,MAAO,SAAS,EAAmB,EAAM,CAAK,MAAW,CAAQ,GAAG,CAAC,EAAO,gBAAgB,QAAQ,EAAW,OAAO,KAAK,IAAI,EAAE,KAAK,MAAM,EAAM,CAAC,CAAC,CAAC,MAAO,GAC1tB,SAAS,GAAmB,CAAK,MAAW,CAAQ,GAAG,CAAC,EAAO,gBAAgB,QAAQ,EAAiB,IAAI,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