{"version":3,"file":"WithSaveScroll.DcJ2j8Tt.mjs","names":["__esmMin","le","init_ssg_sandbox_shims","window","c","J","init_jsx_runtime","init_npm_react_18_3_1","normalizeSitePath","pathname","isDetailPath","currentScrollY","readMemory","raw","STORAGE_KEY","value","writeMemory","memory","clearMemory","rememberListPosition","event","lastPointerSaveAt","target","anchor","url","detailPath","markReturning","restoreListPosition","globalWindow","RESTORE_GUARD","cancelled","frame","correctionTimers","cleanup","timer","cancelByUser","consume","applyPosition","matchingAnchor","rect","delta","pageHeight","useListScrollMemory","currentPath","cancelRestore","withSaveScroll","Component","props","withListScroll","withBack","init_WithSaveScroll"],"sources":["https:/framerusercontent.com/modules/7BVReceWGidcBVBQyJY1/4Bq6W8CdYrJIrbBlxeCD/WithSaveScroll.js"],"sourcesContent":["import{jsx as _jsx}from\"react/jsx-runtime\";import{forwardRef,useLayoutEffect}from\"react\";const STORAGE_KEY=\"gallery-scroll-return-v4\";const RESTORE_GUARD=\"__galleryScrollRestoreV4\";let lastPointerSaveAt=0;function normalizeSitePath(pathname){return pathname.replace(/^\\/s\\/app\\.[^/]+/,\"\")||\"/\";}function isDetailPath(pathname){return/^\\/photo\\/[^/]+/.test(pathname)||/^\\/photo-de-creative\\/[^/]+/.test(pathname)||/^\\/series\\/photo\\/[^/]+/.test(pathname);}function currentScrollY(){return Math.max(window.scrollY,document.documentElement.scrollTop,document.body?.scrollTop??0);}function readMemory(){try{const raw=window.sessionStorage.getItem(STORAGE_KEY);if(!raw)return null;const value=JSON.parse(raw);if(typeof value.listPath!==\"string\"||typeof value.detailPath!==\"string\"||!Number.isFinite(value.y)||value.anchorTop!==undefined&&!Number.isFinite(value.anchorTop)||typeof value.returning!==\"boolean\")return null;return value;}catch{return null;}}function writeMemory(memory){try{window.sessionStorage.setItem(STORAGE_KEY,JSON.stringify(memory));}catch{}}function clearMemory(){try{window.sessionStorage.removeItem(STORAGE_KEY);}catch{}}function rememberListPosition(event){if(event.type===\"click\"&&Date.now()-lastPointerSaveAt<1e3)return;if(event.type===\"pointerdown\")lastPointerSaveAt=Date.now();const target=event.target;if(!(target instanceof Element))return;const anchor=target.closest(\"a[href]\");if(!anchor)return;try{const url=new URL(anchor.href,window.location.href);const detailPath=normalizeSitePath(url.pathname);if(url.origin!==window.location.origin||!isDetailPath(detailPath))return;if(\"scrollRestoration\"in window.history){window.history.scrollRestoration=\"manual\";}writeMemory({listPath:normalizeSitePath(window.location.pathname),detailPath,y:currentScrollY(),anchorTop:anchor.getBoundingClientRect().top,returning:false});}catch{}}function markReturning(){const memory=readMemory();if(memory)writeMemory({...memory,returning:true});return memory;}function restoreListPosition(memory){const globalWindow=window;if(globalWindow[RESTORE_GUARD])return()=>{};globalWindow[RESTORE_GUARD]=true;let cancelled=false;let frame=0;let correctionTimers=[];const cleanup=consume=>{if(cancelled)return;cancelled=true;window.cancelAnimationFrame(frame);correctionTimers.forEach(timer=>window.clearTimeout(timer));if(\"scrollRestoration\"in window.history){window.history.scrollRestoration=\"auto\";}window.removeEventListener(\"wheel\",cancelByUser);window.removeEventListener(\"touchmove\",cancelByUser);window.removeEventListener(\"keydown\",cancelByUser);window.removeEventListener(\"pointerdown\",cancelByUser);globalWindow[RESTORE_GUARD]=false;if(consume)clearMemory();};const cancelByUser=()=>cleanup(true);window.addEventListener(\"wheel\",cancelByUser,{passive:true});window.addEventListener(\"touchmove\",cancelByUser,{passive:true});window.addEventListener(\"keydown\",cancelByUser);window.addEventListener(\"pointerdown\",cancelByUser,{passive:true});const applyPosition=()=>{const matchingAnchor=Array.from(document.querySelectorAll(\"a[href]\")).find(anchor=>{const rect=anchor.getBoundingClientRect();if(rect.width<=0||rect.height<=0)return false;try{return normalizeSitePath(new URL(anchor.href,window.location.href).pathname)===memory.detailPath;}catch{return false;}});if(matchingAnchor&&Number.isFinite(memory.anchorTop)){const delta=matchingAnchor.getBoundingClientRect().top-memory.anchorTop;if(Math.abs(delta)>1){window.scrollBy({top:delta,left:0,behavior:\"auto\"});}return;}const pageHeight=Math.max(document.documentElement.scrollHeight,document.body?.scrollHeight??0);window.scrollTo({top:Math.min(memory.y,Math.max(0,pageHeight-window.innerHeight)),left:0,behavior:\"auto\"});};applyPosition();frame=window.requestAnimationFrame(applyPosition);correctionTimers.push(window.setTimeout(applyPosition,80));correctionTimers.push(window.setTimeout(applyPosition,250));correctionTimers.push(window.setTimeout(()=>{if(cancelled)return;applyPosition();cleanup(true);},600));return()=>cleanup(false);}function useListScrollMemory(){useLayoutEffect(()=>{document.addEventListener(\"pointerdown\",rememberListPosition,true);document.addEventListener(\"click\",rememberListPosition,true);const memory=readMemory();const currentPath=normalizeSitePath(window.location.pathname);const cancelRestore=memory?.returning&&memory.listPath===currentPath?restoreListPosition(memory):()=>{};return()=>{cancelRestore();document.removeEventListener(\"pointerdown\",rememberListPosition,true);document.removeEventListener(\"click\",rememberListPosition,true);};},[]);}export function withSaveScroll(Component){return /*#__PURE__*/forwardRef((props,ref)=>/*#__PURE__*/_jsx(Component,{ref:ref,...props,onPointerDownCapture:event=>{props.onPointerDownCapture?.(event);rememberListPosition(event.nativeEvent??event);},onClickCapture:event=>{props.onClickCapture?.(event);rememberListPosition(event.nativeEvent??event);}}));}export function withListScroll(Component){return /*#__PURE__*/forwardRef((props,ref)=>{useListScrollMemory();return /*#__PURE__*/_jsx(Component,{ref:ref,...props});});}export function withRememberScroll(Component){return withListScroll(Component);}export function withSaveReturnPage(Component){return withListScroll(Component);}export function withBack(Component){return /*#__PURE__*/forwardRef((props,ref)=>/*#__PURE__*/_jsx(Component,{ref:ref,...props,onClick:event=>{event.preventDefault();event.stopPropagation();const memory=markReturning();const currentPath=normalizeSitePath(window.location.pathname);if(memory&&memory.detailPath===currentPath){window.history.back();return;}const target=event.currentTarget;const anchor=target.closest(\"a[href]\");if(anchor)anchor.click();else window.history.back();}}));}\nexport const __FramerMetadata__ = {\"exports\":{\"withRememberScroll\":{\"type\":\"reactHoc\",\"name\":\"withRememberScroll\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withSaveScroll\":{\"type\":\"reactHoc\",\"name\":\"withSaveScroll\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withBack\":{\"type\":\"reactHoc\",\"name\":\"withBack\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withSaveReturnPage\":{\"type\":\"reactHoc\",\"name\":\"withSaveReturnPage\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withListScroll\":{\"type\":\"reactHoc\",\"name\":\"withListScroll\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./WithSaveScroll.map"],"mappings":"A,uIAA6M,SAASQ,EAAkB,EAAS,CAAC,OAAOC,EAAS,QAAQ,mBAAmB,EAAE,GAAG,GAAI,CAAC,SAASC,EAAa,EAAS,CAAC,MAAM,kBAAkB,KAAKD,CAAQ,GAAG,8BAA8B,KAAKA,CAAQ,GAAG,0BAA0B,KAAKA,CAAQ,CAAE,CAAC,SAASE,GAAgB,CAAC,OAAO,KAAK,IAAIR,EAAO,QAAQ,SAAS,gBAAgB,UAAU,SAAS,MAAM,WAAW,CAAC,CAAE,CAAC,SAASS,GAAY,CAAC,GAAG,CAAC,IAAMC,EAAIV,EAAO,eAAe,QAAQW,CAAW,EAAE,GAAG,CAACD,EAAI,OAAO,KAAK,IAAME,EAAM,KAAK,MAAMF,CAAG,EAAqN,OAAhN,OAAOE,EAAM,UAAW,UAAU,OAAOA,EAAM,YAAa,UAAU,CAAC,OAAO,SAASA,EAAM,CAAC,GAAGA,EAAM,YAAY,IAAA,IAAW,CAAC,OAAO,SAASA,EAAM,SAAS,GAAG,OAAOA,EAAM,WAAY,UAAiB,KAAYA,CAAM,MAAM,CAAC,OAAO,IAAK,CAAC,CAAC,SAASC,EAAY,EAAO,CAAC,GAAG,CAACb,EAAO,eAAe,QAAQW,EAAY,KAAK,UAAUG,CAAM,CAAC,CAAE,MAAM,CAAC,CAAC,CAAC,SAASC,GAAa,CAAC,GAAG,CAACf,EAA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