{"version":3,"file":"WithRandomizedProjects.Baf29AHI.mjs","names":["useRef"],"sources":["https:/framerusercontent.com/modules/HTbUp71N5jeILNNqorwH/8gfsIM0uJefgLnK9MsJd/WithRandomizedProjects.js"],"sourcesContent":["// overrides/RandomizedProjects.tsx\n// Shows N RANDOM items from a Framer CMS Collection List. Apply to the\n// Collection List layer itself. Keep the Collection List UNLIMITED in\n// Framer — the override does the capping.\n//\n// One implementation, several counts: pick the export that matches how many\n// items the layer should show. They all share createRandomizedProjects below,\n// so a fix to the shuffle logic lands in every variant at once.\n//\n//   withRandomizedProjects     — 5 items (the original; existing layers keep\n//                                working unchanged)\n//   withRandomizedProjects2    — 2 items\n//   withRandomizedProjects3    — 3 items\n//   withRandomizedProjects4    — 4 items\n//   withRandomizedProjects6    — 6 items\n//   withRandomizedProjectsAll  — no cap, shuffle only\n//\n// Framer's Collection List generates its items internally — it ignores an\n// `items` prop and replaced React children — so the shuffle happens at the\n// DOM level. Crucially it must NOT be one-shot: Framer can re-render the\n// list after hydration or a CMS data refresh, which resets the DOM order\n// and wipes the inline display styles. When that happened after a one-shot\n// shuffle, every item became visible at once and the row squeezed into\n// letter-wide columns. A MutationObserver re-applies the shuffle + limit\n// whenever the list is rebuilt; a marker attribute + visibility check make\n// re-application idempotent so our own mutations don't loop.\nimport{jsx as _jsx}from\"react/jsx-runtime\";import{useEffect,useRef}from\"react\";/**\n * Builds a randomizing override for a given cap. `limit` of 0 shows every\n * item (shuffle only). Each cap gets its own marker attribute so two variants\n * on one page never read each other's \"already applied\" state and skip a pass.\n */function createRandomizedProjects(limit){const MARK=`data-rdr-shuffled-${limit}`;return function withRandomized(Component){return props=>{const ref=useRef(null);useEffect(()=>{const wrap=ref.current;if(!wrap)return;const findList=()=>{// Fast path: walk down an unbranched chain of wrappers.\nlet list=wrap.firstElementChild;while(list&&list.children.length===1&&list.firstElementChild){list=list.firstElementChild;}if(list&&list.children.length>1)return list;// Fallback: the chain branched before reaching the list\n// (a heading or filter row beside it, say). The item\n// container is the deepest element whose children are all\n// the same tag — that's the repeated CMS item.\n// Restricted to item-shaped tags so an <svg>'s <path>\n// children or a run of <span>s can't win the count.\nconst ITEM_TAGS=[\"DIV\",\"A\",\"LI\",\"ARTICLE\",\"SECTION\"];let best=null;let bestCount=1;wrap.querySelectorAll(\"div, ul, ol, section, article\").forEach(node=>{const el=node;const kids=Array.from(el.children);if(kids.length<=bestCount)return;const tag=kids[0].tagName;if(!ITEM_TAGS.includes(tag))return;if(!kids.every(k=>k.tagName===tag))return;best=el;bestCount=kids.length;});return best;};// An item is \"the current project\" when any link inside it\n// points at the page we're on — works on detail pages without\n// needing access to CMS slugs.\nconst norm=p=>decodeURIComponent(p).replace(/\\/+$/,\"\")||\"/\";const currentPath=norm(window.location.pathname);const isCurrent=el=>{const anchors=el.matches(\"a[href]\")?[el]:Array.from(el.querySelectorAll(\"a[href]\"));return anchors.some(a=>{try{return norm(new URL(a.href,window.location.origin).pathname)===currentPath;}catch{return false;}});};let warned=false;const apply=()=>{const list=findList();if(!list){if(!warned){warned=true;console.warn(`[RandomizedProjects] limit=${limit}: no item container found under this layer — the list is rendering unchanged.`);}return;}// Diagnostic: which variant owns this list.\nlist.setAttribute(\"data-rdr-limit\",String(limit));const items=Array.from(list.children);const excluded=items.filter(isCurrent);const candidates=items.filter(el=>!excluded.includes(el));const showCount=limit>0?Math.min(limit,candidates.length):candidates.length;// Already applied and intact? (Framer rebuilds create fresh\n// nodes without the marker; style resets break the counts.)\nconst intact=items.every(el=>el.hasAttribute(MARK))&&excluded.every(el=>el.style.display===\"none\")&&items.filter(el=>el.style.display!==\"none\").length===showCount;if(intact)return;for(let i=candidates.length-1;i>0;i--){const j=Math.floor(Math.random()*(i+1));[candidates[i],candidates[j]]=[candidates[j],candidates[i]];}[...candidates,...excluded].forEach((el,i)=>{el.setAttribute(MARK,\"1\");el.style.display=i<showCount&&!excluded.includes(el)?\"\":\"none\";list.appendChild(el);});};apply();// Re-apply whenever Framer rebuilds the list or resets styles.\n// rAF batches mutation storms into one pass per frame; the\n// idempotence check above stops our own writes from looping.\nlet raf=0;const mo=new MutationObserver(()=>{cancelAnimationFrame(raf);raf=requestAnimationFrame(apply);});mo.observe(wrap,{childList:true,subtree:true,attributes:true,attributeFilter:[\"style\"]});return()=>{cancelAnimationFrame(raf);mo.disconnect();};},[]);return /*#__PURE__*/_jsx(\"div\",{ref:ref,style:{display:\"contents\"},children:/*#__PURE__*/_jsx(Component,{...props})});};};}// Built once at module scope; the exports below are thin named wrappers so\n// each variant shows up under its own name in Framer's override picker.\nconst randomize2=createRandomizedProjects(2);const randomize3=createRandomizedProjects(3);const randomize4=createRandomizedProjects(4);const randomize5=createRandomizedProjects(5);const randomize6=createRandomizedProjects(6);const randomizeAll=createRandomizedProjects(0);export function withRandomizedProjects(Component){return randomize5(Component);}export function withRandomizedProjects2(Component){return randomize2(Component);}export function withRandomizedProjects3(Component){return randomize3(Component);}export function withRandomizedProjects4(Component){return randomize4(Component);}export function withRandomizedProjects6(Component){return randomize6(Component);}export function withRandomizedProjectsAll(Component){return randomizeAll(Component);}\nexport const __FramerMetadata__ = {\"exports\":{\"withRandomizedProjects4\":{\"type\":\"reactHoc\",\"name\":\"withRandomizedProjects4\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withRandomizedProjects6\":{\"type\":\"reactHoc\",\"name\":\"withRandomizedProjects6\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withRandomizedProjects3\":{\"type\":\"reactHoc\",\"name\":\"withRandomizedProjects3\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withRandomizedProjects\":{\"type\":\"reactHoc\",\"name\":\"withRandomizedProjects\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withRandomizedProjects2\":{\"type\":\"reactHoc\",\"name\":\"withRandomizedProjects2\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withRandomizedProjectsAll\":{\"type\":\"reactHoc\",\"name\":\"withRandomizedProjectsAll\",\"annotations\":{\"framerContractVersion\":\"1\"}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