{"version":3,"file":"RandomArticlePreview.DgFNV9Ff.mjs","names":["useRef","useMemo","useCallback","Children","__esmMin","window","j","z","pe","init_ssg_sandbox_shims","init_npm_react_18_3_1","de","K","ne","c","p","ce","addPropertyControls","init_framer_B6PCHH0A","useIsStaticRenderer","ControlType","RandomArticlePreview","props","shellRef","frameRef","observerRef","selectedIdsRef","staticRenderer","articlePathRegex","normalizePathname","pathname","isArticlePath","getAnchorPath","rawHref","anchor","url","normalized","elementContainsArticleLink","el","anchors","findCardAndListRoot","current","shell","parent","siblings","matchingSiblingCount","sibling","sampleIds","pool","ids","i","temp","count","applySelection","currentPath","groups","id","located","existing","entry","selectedRoot","rootCandidates","root","candidates","pooled","pooledCards","item","child","idsInOrder","selectedIds","kept","needed","remaining","selectedSet","previouslyMarked","run","observer","enhancedContent","content","node","element","elementStyle","hasRenderableContent","has","style","init_RandomArticlePreview","init_jsx_runtime"],"sources":["https:/framerusercontent.com/modules/x1Q5GGmSBtcMskfAjGg7/aSHjqbSQ8FTHYYxjDtlO/RandomArticlePreview.js"],"sourcesContent":["import{jsx as _jsx,jsxs as _jsxs}from\"react/jsx-runtime\";import{Children,cloneElement,isValidElement,useCallback,useEffect,useMemo,useRef}from\"react\";import{addPropertyControls,ControlType,useIsStaticRenderer}from\"framer\";/**\n * @framerSupportedLayoutWidth any-prefer-fixed\n * @framerSupportedLayoutHeight auto\n */export default function RandomArticlePreview(props){const{content,style}=props;const shellRef=useRef(null);const frameRef=useRef(null);const observerRef=useRef(null);const selectedIdsRef=useRef([]);const staticRenderer=useIsStaticRenderer();const articlePathRegex=useMemo(()=>/^\\/articles\\/[^/]+\\/?$/i,[]);const normalizePathname=useCallback(pathname=>{return pathname.replace(/\\/+$/,\"\")||\"/\";},[]);const isArticlePath=useCallback(pathname=>articlePathRegex.test(pathname),[articlePathRegex]);const getAnchorPath=useCallback(anchor=>{if(typeof window===\"undefined\")return null;const rawHref=anchor.getAttribute(\"href\");if(!rawHref)return null;try{const url=new URL(rawHref,window.location.origin);const normalized=normalizePathname(url.pathname);if(!isArticlePath(normalized))return null;return normalized;}catch(_error){return null;}},[isArticlePath,normalizePathname]);const elementContainsArticleLink=useCallback(el=>{if(el instanceof HTMLAnchorElement){const ownPath=getAnchorPath(el);if(ownPath)return true;}const anchors=el.querySelectorAll(\"a[href]\");for(const anchor of anchors){const path=getAnchorPath(anchor);if(path)return true;}return false;},[getAnchorPath]);const findCardAndListRoot=useCallback((anchor,shell)=>{let current=anchor;while(current&&current!==shell){const parent=current.parentElement;if(!parent||parent===shell)return null;const siblings=Array.from(parent.children);let matchingSiblingCount=0;for(const sibling of siblings){if(elementContainsArticleLink(sibling))matchingSiblingCount+=1;if(matchingSiblingCount>=2){return{cardEl:current,listRoot:parent};}}current=parent;}return null;},[elementContainsArticleLink]);const sampleIds=useCallback((ids,count)=>{const pool=[...ids];for(let i=pool.length-1;i>0;i--){const j=Math.floor(Math.random()*(i+1));const temp=pool[i];pool[i]=pool[j];pool[j]=temp;}return pool.slice(0,count);},[]);const applySelection=useCallback(()=>{if(typeof window===\"undefined\")return;const shell=shellRef.current;if(!shell)return;const currentPath=normalizePathname(window.location.pathname);const anchors=Array.from(shell.querySelectorAll(\"a[href]\"));const groups=new Map;for(const anchor of anchors){const id=getAnchorPath(anchor);if(!id)continue;const located=findCardAndListRoot(anchor,shell);if(!located)continue;const existing=groups.get(located.listRoot)??[];if(!existing.some(entry=>entry.cardEl===located.cardEl)){existing.push({id,cardEl:located.cardEl});groups.set(located.listRoot,existing);}}let selectedRoot=null;let rootCandidates=[];for(const[root,candidates]of groups.entries()){if(candidates.length>rootCandidates.length){selectedRoot=root;rootCandidates=candidates;}}if(!selectedRoot||rootCandidates.length===0)return;const pooled=rootCandidates.slice(0,20);const pooledCards=pooled.map(item=>item.cardEl);for(const child of pooledCards){child.removeAttribute(\"data-random-selected\");}const eligible=pooled.filter(item=>item.id!==currentPath);const idsInOrder=eligible.map(item=>item.id);if(idsInOrder.length===0)return;let selectedIds=[];if(staticRenderer){selectedIds=idsInOrder.slice(0,3);}else if(selectedIdsRef.current.length===0){selectedIds=sampleIds(idsInOrder,Math.min(3,idsInOrder.length));}else{const kept=selectedIdsRef.current.filter(id=>idsInOrder.includes(id));const needed=Math.max(0,3-kept.length);if(needed===0){selectedIds=kept.slice(0,3);}else{const remaining=idsInOrder.filter(id=>!kept.includes(id));selectedIds=[...kept,...sampleIds(remaining,needed)].slice(0,3);}}if(selectedIds.length===0)return;selectedIdsRef.current=selectedIds;const selectedSet=new Set(selectedIds);for(const item of pooled){if(selectedSet.has(item.id)){item.cardEl.setAttribute(\"data-random-selected\",\"true\");}}const previouslyMarked=Array.from(shell.querySelectorAll('[data-random-article-list=\"true\"]'));for(const root of previouslyMarked){if(root!==selectedRoot){root.removeAttribute(\"data-random-article-list\");root.removeAttribute(\"data-random-ready\");}}selectedRoot.setAttribute(\"data-random-article-list\",\"true\");selectedRoot.setAttribute(\"data-random-ready\",\"true\");},[findCardAndListRoot,getAnchorPath,normalizePathname,sampleIds,staticRenderer]);useEffect(()=>{if(typeof window===\"undefined\")return;const shell=shellRef.current;if(!shell)return;const run=()=>{if(frameRef.current!==null){window.cancelAnimationFrame(frameRef.current);}frameRef.current=window.requestAnimationFrame(()=>{applySelection();});};run();const observer=new MutationObserver(()=>{run();});observer.observe(shell,{childList:true,subtree:true});observerRef.current=observer;return()=>{if(frameRef.current!==null){window.cancelAnimationFrame(frameRef.current);frameRef.current=null;}if(observerRef.current){observerRef.current.disconnect();observerRef.current=null;}};},[applySelection]);const enhancedContent=useMemo(()=>{return Children.map(content,node=>{if(!/*#__PURE__*/isValidElement(node))return node;const element=node;const elementStyle=element.props?.style??{};return /*#__PURE__*/cloneElement(element,{...element.props,\"data-random-prehide-root\":\"true\",style:{...elementStyle,position:\"relative\",left:undefined,top:undefined,width:\"100%\",height:\"auto\"}});});},[content]);const hasRenderableContent=useMemo(()=>{let has=false;Children.forEach(content,node=>{if(node!==null&&node!==undefined&&node!==false)has=true;});return has;},[content]);return /*#__PURE__*/_jsxs(\"div\",{ref:shellRef,className:\"random-article-preview-shell\",style:{position:\"relative\",...{containerType:\"inline-size\"},minHeight:hasRenderableContent?undefined:360,...style},children:[/*#__PURE__*/_jsx(\"style\",{children:`\n                [data-random-prehide-root=\"true\"]:not([data-random-ready=\"true\"]) > :nth-child(n + 4) {\n                    display: none !important;\n                }\n                [data-random-article-list=\"true\"][data-random-ready=\"true\"] > :not([data-random-selected=\"true\"]) {\n                    display: none !important;\n                }\n                @container (max-width: 600px) {\n                    .random-article-preview-shell [data-random-prehide-root=\"true\"],\n                    .random-article-preview-shell [data-random-article-list=\"true\"] {\n                        grid-template-columns: 1fr !important;\n                    }\n                }\n            `}),enhancedContent]});}addPropertyControls(RandomArticlePreview,{content:{type:ControlType.ComponentInstance,title:\"Content\"}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"RandomArticlePreview\",\"slots\":[\"content\"],\"annotations\":{\"framerSupportedLayoutWidth\":\"any-prefer-fixed\",\"framerSupportedLayoutHeight\":\"auto\",\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./RandomArticlePreview.map"],"mappings":"A,4OAGG,SAAwBqB,EAAqB,EAAM,CAAC,GAAK,CAAC,UAAQ,SAAOC,EAAYC,EAASvB,EAAO,IAAI,EAAQwB,EAASxB,EAAO,IAAI,EAAQyB,EAAYzB,EAAO,IAAI,EAAQ0B,EAAe1B,EAAO,CAAC,CAAC,EAAQ2B,EAAeR,EAAoB,EAAQS,EAAiB3B,MAAY,0BAA0B,CAAC,CAAC,EAAQ4B,EAAkB3B,EAAY,GAAkB4B,EAAS,QAAQ,OAAO,EAAE,GAAG,IAAM,CAAC,CAAC,EAAQC,EAAc7B,EAAY,GAAU0B,EAAiB,KAAKE,CAAQ,EAAE,CAACF,CAAgB,CAAC,EAAQI,EAAc9B,EAAY,GAAQ,CAAC,GAAUG,IAAS,OAAY,OAAO,KA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