{"version":3,"file":"Random_CMS.DN8olx08.mjs","names":["React.useRef","__esmMin","init_npm_react_18_3_1","window","init_ssg_sandbox_shims","ce","init_jsx_runtime","c","de","addPropertyControls","ControlType","init_framer_B6PCHH0A","useIsStaticRenderer","recomputeList","entries","listRegistry","list","a","b","rank","useLimit","limit","cryptoRandom","buf","Random_CMS","selfRef","instanceIdRef","isActive","raw","listRef","item","hops","MAX_CLIMB","instanceId","originalOrder","originalDisplay","randomize","style","init_Random_CMS","props"],"sources":["https:/framerusercontent.com/modules/S2ZLaeVhXheK4LBZ5QJW/gu26ZjtG45ioCbURTAps/Random_CMS.js"],"sourcesContent":["import{jsx as _jsx}from\"react/jsx-runtime\";import*as React from\"react\";import{addPropertyControls,ControlType,useIsStaticRenderer}from\"framer\";const MAX_CLIMB=12// safety bound only — real stop condition is reaching `list`\n;const listRegistry=new WeakMap;function recomputeList(list,useLimit,limit){const entries=listRegistry.get(list);if(!entries)return;const members=Array.from(entries.values()).sort((a,b)=>a.order-b.order);members.forEach((m,rank)=>{// Each instance's own item element is the only node ever touched\n// here — never a sibling's. `members` is only used to compute\n// this instance's rank among elements it's already allowed to\n// write to (its own).\nm.item.style.order=String(rank);m.item.style.display=useLimit&&rank>=limit?\"none\":\"\";});}function cryptoRandom(){const buf=new Uint32Array(1);crypto.getRandomValues(buf);return buf[0]/(4294967295+1);}/**\n * Shuffles and/or limits CMS items. Only touches elements it owns a direct\n * relationship to: the connected `list` (explicitly linked by the user,\n * same pattern as a Scroll Section connection) and its own item container\n * (found by climbing parents from itself until reaching the connected\n * list — never an open-ended search).\n *\n * Place one instance of this component inside each CMS item template, and\n * connect the same `list` (the CMS list's own wrapper/Stack) on every one.\n *\n * @framerSupportedLayoutWidth any\n * @framerSupportedLayoutHeight any\n * @framerDisableUnlink\n */export default function Random_CMS({listRef,randomize=true,useLimit=true,limit=4,style}){const selfRef=React.useRef(null);const instanceIdRef=React.useRef(Symbol(\"random-cms-instance\"));const isStatic=useIsStaticRenderer();const isActive=!isStatic;React.useEffect(()=>{if(typeof window===\"undefined\"||!isActive)return;let list=null;const raw=listRef;if(raw instanceof HTMLElement){list=raw;}else if(raw?.current instanceof HTMLElement){list=raw.current;}else if(raw?.node instanceof HTMLElement){list=raw.node;}else if(raw?.ref?.current instanceof HTMLElement){list=raw.ref.current;}if(!list)return;// Climb from self until we reach a direct child of the connected\n// list. This stops as soon as it hits `list` — it never searches\n// past it, and `list` itself is only reachable because the user\n// explicitly connected it, not because the component went looking\n// for it.\nlet item=selfRef.current;let hops=0;while(item&&item.parentElement!==list&&hops<MAX_CLIMB){item=item.parentElement;hops++;}if(!item||item.parentElement!==list)return;const instanceId=instanceIdRef.current;const originalOrder=item.style.order;const originalDisplay=item.style.display;let entries=listRegistry.get(list);if(!entries){entries=new Map;listRegistry.set(list,entries);}entries.set(instanceId,{order:randomize?cryptoRandom():0,item});recomputeList(list,useLimit,limit);return()=>{const e=listRegistry.get(list);e?.delete(instanceId);if(e&&e.size>0)recomputeList(list,useLimit,limit);item.style.order=originalOrder;item.style.display=originalDisplay;};},[isActive,listRef,randomize,useLimit,limit]);return /*#__PURE__*/_jsx(\"div\",{ref:selfRef,style:{...style,position:\"absolute\",width:0,height:0,pointerEvents:\"none\",overflow:\"hidden\"}});}addPropertyControls(Random_CMS,{listRef:{// @ts-ignore — scroll section reference control, reused here to\n// let the user explicitly connect the CMS list container.\ntype:ControlType.ScrollSectionRef,title:\"List\",description:\"Add it inside your CMS List Item.\\n\\nThen, create a Scroll Section on your main CMS and name it something like *“random-cms”*.\"},randomize:{type:ControlType.Boolean,title:\"Randomize\",defaultValue:true,enabledTitle:\"On\",disabledTitle:\"Off\",description:\"See more components from [Iklil Najma M](https://dub.sh/artevo)\"},useLimit:{type:ControlType.Boolean,title:\"Use Limit\",defaultValue:true,enabledTitle:\"On\",disabledTitle:\"Off\",description:\"Limit how many CMS items are shown.\"},limit:{type:ControlType.Number,title:\"Limit\",defaultValue:4,min:1,max:50,step:1,displayStepper:true,description:\"Max number of items to display. The rest will be hidden.\",hidden:props=>!props.useLimit}});Random_CMS.displayName=\"Random CMS\";\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"Random_CMS\",\"slots\":[],\"annotations\":{\"framerSupportedLayoutHeight\":\"any\",\"framerSupportedLayoutWidth\":\"any\",\"framerContractVersion\":\"1\",\"framerDisableUnlink\":\"\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./Random_CMS.map"],"mappings":"A,uMACgC,SAASa,EAAc,EAAK,EAAS,EAAM,CAAC,IAAMC,EAAQC,EAAa,IAAIC,CAAI,EAAMF,GAAuF,MAApD,KAAKA,EAAQ,OAAO,CAAC,CAAC,CAAC,MAAM,EAAE,IAAIG,EAAE,MAAMC,EAAE,KAAa,CAAC,CAAC,SAAS,EAAE,IAAO,CAItO,EAAE,KAAK,MAAM,MAAM,OAAOC,CAAI,EAAE,EAAE,KAAK,MAAM,QAAQC,GAAUD,GAAME,EAAM,OAAO,EAAG,CAAC,CAAE,CAAC,SAASC,GAAc,CAAC,IAAMC,kBAAI,IAAI,YAAY,CAAC,EAA8B,OAA5B,OAAO,gBAAgBA,CAAG,EAASA,EAAI,GAAI,UAAc,CAapM,SAAwBC,EAAW,CAAC,UAAQ,YAAU,GAAK,WAAS,GAAK,QAAM,EAAE,SAAO,CAAC,IAAMC,EAAQzB,EAAa,IAAI,EAAQ0B,EAAc1B,EAAa,OAAO,qBAAqB,CAAC,EAA6C2B,EAAS,CAArCf,EAA6C,EAK0c,OALxcP,MAAoB,CAAC,GAAUF,IAAS,QAAa,CAACwB,EAAS,OAAO,IAAIX,EAAK,KAAWY,EAAIC,EAAiP,GAAtOD,aAAe,YAAa,EAAKA,EAAaA,GAAK,mBAAmB,YAAa,EAAKA,EAAI,QAAiBA,GAAK,gBAAgB,YAAa,EAAKA,EAAI,KAAcA,GAAK,KAAK,mBAAmB,cAAa,EAAKA,EAAI,IAAI,SAAY,CAACZ,EAAK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