{"version":3,"file":"ShuffleCollectionItems.DEdRsdQE.mjs","names":["useRef","useCallback"],"sources":["https:/framerusercontent.com/modules/snqnaI7RdsCWRxOTwiAQ/0q8RO7WdcsMl4k5dLFmM/ShuffleCollectionItems.js"],"sourcesContent":["// User request: Rewrite the existing ShuffleCollectionItems override from scratch to use stable visual ordering (CSS order) so CMS work-card thumbnails reshuffle per fresh page load, survive reconciliation, avoid DOM reparenting, and clean up styles on unmount.\nimport{jsx as _jsx}from\"react/jsx-runtime\";import{forwardRef,useCallback,useEffect,useRef}from\"react\";function getElementTextSignals(element){return[element.getAttribute(\"data-framer-name\")||\"\",element.getAttribute(\"aria-label\")||\"\",element.getAttribute(\"data-framer-component-type\")||\"\",element.getAttribute(\"role\")||\"\",element.getAttribute(\"class\")||\"\"].join(\" \").toLowerCase();}function isExcludedElement(element){const text=getElementTextSignals(element);if(text.includes(\"empty\"))return true;if(text.includes(\"no results\"))return true;if(text.includes(\"loading\"))return true;if(element.hasAttribute(\"data-framer-empty-state\"))return true;if((element.getAttribute(\"aria-hidden\")||\"\").toLowerCase()===\"true\")return true;return false;}function isVisibleElement(element){if((element.getAttribute(\"aria-hidden\")||\"\").toLowerCase()===\"true\")return false;if(typeof window!==\"undefined\"){const style=window.getComputedStyle(element);if(style.display===\"none\"||style.visibility===\"hidden\")return false;}return true;}function hasClickableLink(element){const directLink=element.matches(\"a[href], [role='link']\");if(directLink)return true;return element.querySelector(\"a[href], [role='link']\")!==null;}function hasNestedCardLikeTree(element){const descendantElements=element.querySelectorAll(\"*\").length;const hasMediaOrTextNode=element.querySelector(\"img, picture, video, canvas, svg, h1, h2, h3, h4, h5, h6, p, [data-framer-name], [data-framer-component-type]\");return descendantElements>=4&&hasMediaOrTextNode!==null;}function isPotentialCardWrapper(element){if(isExcludedElement(element))return false;if(!isVisibleElement(element))return false;return hasClickableLink(element)||hasNestedCardLikeTree(element);}function getWrapperSignature(element){const tag=element.tagName.toLowerCase();const directChildrenBucket=Math.min(element.children.length,4);const descendantBucket=Math.min(element.querySelectorAll(\"*\").length,10);const linkFlag=hasClickableLink(element)?1:0;return`${tag}|${directChildrenBucket}|${descendantBucket}|${linkFlag}`;}function getStructurallySimilarVisibleWrappers(container){const directChildren=Array.from(container.children).filter(child=>child instanceof HTMLElement);if(directChildren.length<2)return[];const candidates=directChildren.filter(child=>isPotentialCardWrapper(child));if(candidates.length<2)return[];const groups=new Map;for(const candidate of candidates){const signature=getWrapperSignature(candidate);const group=groups.get(signature)??[];group.push(candidate);groups.set(signature,group);}let bestGroup=[];for(const group of groups.values()){if(group.length>bestGroup.length){bestGroup=group;}}return bestGroup.length>=2?bestGroup:[];}function shuffleIndices(count){const indices=Array.from({length:count},(_,i)=>i);for(let i=indices.length-1;i>0;i--){const j=Math.floor(Math.random()*(i+1));[indices[i],indices[j]]=[indices[j],indices[i]];}return indices;}function buildStableShuffledOrder(count){const order=shuffleIndices(count);const sameOrder=order.every((value,index)=>value===index);if(!sameOrder)return order;const fallback=[...order];const swapWith=count>2?count-1:1;[fallback[0],fallback[swapWith]]=[fallback[swapWith],fallback[0]];return fallback;}function getDepthWithinRoot(root,node){let depth=0;let current=node.parentElement;while(current&&current!==root){depth+=1;current=current.parentElement;}return depth;}function findBestContainer(root){const rootWrappers=getStructurallySimilarVisibleWrappers(root);if(rootWrappers.length>=2){return{container:root,wrappers:rootWrappers};}const descendants=Array.from(root.querySelectorAll(\"*\")).filter(node=>node instanceof HTMLElement);let bestMatch=null;for(const node of descendants){if(isExcludedElement(node))continue;const wrappers=getStructurallySimilarVisibleWrappers(node);if(wrappers.length<2)continue;const depth=getDepthWithinRoot(root,node);if(!bestMatch||depth>bestMatch.depth||depth===bestMatch.depth&&wrappers.length>bestMatch.wrappers.length){bestMatch={container:node,wrappers,depth};}}return bestMatch?{container:bestMatch.container,wrappers:bestMatch.wrappers}:null;}export function ShuffleCollectionItems(Component){return /*#__PURE__*/forwardRef(function ShuffleCollectionItemsOverride(props,ref){const rootRef=useRef(null);const observerRef=useRef(null);const retryTimerRef=useRef(null);const reorderMapRef=useRef(null);const isApplyingRef=useRef(false);const touchedStylesRef=useRef(new Map);const setRootRef=useCallback(node=>{rootRef.current=node;if(typeof ref===\"function\"){ref(node);}else if(ref&&typeof ref===\"object\"){ref.current=node;}},[ref]);const clearRetryTimer=useCallback(()=>{if(retryTimerRef.current!==null&&typeof window!==\"undefined\"){window.clearTimeout(retryTimerRef.current);retryTimerRef.current=null;}},[]);const clearObserver=useCallback(()=>{if(observerRef.current){observerRef.current.disconnect();observerRef.current=null;}},[]);const cleanupAppliedStyles=useCallback(()=>{touchedStylesRef.current.forEach((previousOrder,element)=>{if(previousOrder){element.style.order=previousOrder;}else{element.style.removeProperty(\"order\");}});touchedStylesRef.current.clear();},[]);const applyOrReapplyVisualOrder=useCallback(()=>{const root=rootRef.current;if(!root)return false;const match=findBestContainer(root);if(!match)return false;const{wrappers}=match;const visibleItems=wrappers.filter(wrapper=>wrapper.getAttribute(\"aria-hidden\")!==\"true\");if(visibleItems.length<2)return false;if(!reorderMapRef.current){reorderMapRef.current=buildStableShuffledOrder(visibleItems.length);}const orderMap=reorderMapRef.current;if(!orderMap)return false;isApplyingRef.current=true;for(let i=0;i<visibleItems.length;i++){const element=visibleItems[i];if(!touchedStylesRef.current.has(element)){touchedStylesRef.current.set(element,element.style.order);}const mappedOrder=i<orderMap.length?orderMap[i]:i;element.style.order=String(mappedOrder);}isApplyingRef.current=false;return true;},[]);useEffect(()=>{if(typeof window===\"undefined\"||typeof MutationObserver===\"undefined\")return;let stopped=false;const startedAt=Date.now();const maxDurationMs=8e3;const retryDelayMs=150;const run=()=>{if(stopped)return;const applied=applyOrReapplyVisualOrder();if(!applied&&Date.now()-startedAt<maxDurationMs){clearRetryTimer();retryTimerRef.current=window.setTimeout(run,retryDelayMs);}};run();if(rootRef.current){observerRef.current=new MutationObserver(()=>{if(stopped||isApplyingRef.current)return;applyOrReapplyVisualOrder();});observerRef.current.observe(rootRef.current,{childList:true,subtree:true});}return()=>{stopped=true;clearRetryTimer();clearObserver();cleanupAppliedStyles();reorderMapRef.current=null;};},[applyOrReapplyVisualOrder,clearObserver,clearRetryTimer,cleanupAppliedStyles]);return /*#__PURE__*/_jsx(Component,{ref:setRootRef,...props});});}\nexport const __FramerMetadata__ = {\"exports\":{\"ShuffleCollectionItems\":{\"type\":\"reactHoc\",\"name\":\"ShuffleCollectionItems\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./ShuffleCollectionItems.map"],"mappings":"qJACsG,SAAS,EAAsB,EAAQ,CAAC,MAAM,CAAC,EAAQ,aAAa,kBAAkB,GAAG,GAAG,EAAQ,aAAa,YAAY,GAAG,GAAG,EAAQ,aAAa,4BAA4B,GAAG,GAAG,EAAQ,aAAa,MAAM,GAAG,GAAG,EAAQ,aAAa,OAAO,GAAG,EAAE,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,YAAY,CAAE,CAAC,SAAS,EAAkB,EAAQ,CAAC,IAAM,EAAK,EAAsB,CAAO,EAA0Q,MAAhF,GAArL,EAAK,SAAS,OAAO,GAAiB,EAAK,SAAS,YAAY,GAAiB,EAAK,SAAS,SAAS,GAAiB,EAAQ,aAAa,yBAAyB,IAAkB,EAAQ,aAAa,aAAa,GAAG,GAAA,CAAI,YAAY,IAAI,OAAgC,CAAC,SAAS,EAAiB,EAAQ,CAAC,IAAI,EAAQ,aAAa,aAAa,GAAG,GAAA,CAAI,YAAY,IAAI,OAAO,MAAO,GAAM,GAAU,IAAS,OAAY,CAAC,IAAM,EAAM,EAAO,iBAAiB,CAAO,EAAE,GAAG,EAAM,UAAU,QAAQ,EAAM,aAAa,SAAS,MAAO,EAAM,CAAC,MAAO,EAAK,CAAC,SAAS,EAAiB,EAAQ,CAAsF,OAApE,EAAQ,QAAQ,wBAAsC,EAAS,GAAY,EAAQ,cAAc,wBAAwB,IAAI,IAAK,CAAC,SAAS,EAAsB,EAAQ,CAAC,IAAM,E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