{"version":3,"file":"CMSRandomiserHTML.CpErb0Nm.mjs","names":["useState","React"],"sources":["https:/framerusercontent.com/modules/ZnIYAQaFxcVdJ6bSVTHC/DvFTSnk88TwSxMtbsQvS/CMSRandomiserHTML.js"],"sourcesContent":["import{jsx as _jsx,jsxs as _jsxs}from\"react/jsx-runtime\";import React,{useState,useEffect}from\"react\";import{addPropertyControls,ControlType,RenderTarget}from\"framer\";import{motion}from\"framer-motion\";/**\n * @framerDisableUnlink\n *\n * @framerSupportedLayoutWidth any-prefer-fixed\n * @framerSupportedLayoutHeight auto\n * @framerIntrinsicWidth 600\n * @framerSupportedLayoutHeight auto\n */export default function CMSShuffler(props){const isCanvas=RenderTarget.current()===RenderTarget.canvas;const[extractedItems,setExtractedItems]=useState([]);const[shuffledItems,setShuffledItems]=useState([]);const BROADCAST_ID=\"3.14px solid transparent\";const shuffleArray=array=>{const shuffled=[...array];for(let i=shuffled.length-1;i>0;i--){const j=Math.floor(Math.random()*(i+1));[shuffled[i],shuffled[j]]=[shuffled[j],shuffled[i]];}return shuffled;};const extractTextFromElement=element=>{if(!element)return[];const textElements=[];const allElements=element.querySelectorAll(\"*[data-framer-name]\");allElements.forEach(el=>{const name=el.getAttribute(\"data-framer-name\");const text=el.textContent?.trim();if(text&&text.length>0){textElements.push({name:name,text:text});}});return textElements;};const getActualCMSItems=broadcaster=>{let items=Array.from(broadcaster.children);if(items.length===1){const singleChild=items[0];const grandChildren=Array.from(singleChild.children);if(grandChildren.length>1){items=grandChildren;}else if(grandChildren.length===1){const greatGrandChildren=Array.from(grandChildren[0].children);if(greatGrandChildren.length>1){items=greatGrandChildren;}}}return items;};const handleAnimationComplete=()=>{if(isCanvas)return;const broadcaster=document.querySelector('[style*=\"3.14px solid transparent\"]');if(broadcaster){const items=getActualCMSItems(broadcaster);const allItems=[];items.forEach((item,index)=>{const textElements=extractTextFromElement(item);allItems.push({itemNumber:index+1,textElements:textElements,element:item.cloneNode(true)});});setExtractedItems(allItems);}};useEffect(()=>{if(extractedItems.length>0){let itemsToShuffle=shuffleArray(extractedItems);if(props.addLimit&&props.itemLimit>0){itemsToShuffle=itemsToShuffle.slice(0,props.itemLimit);}setShuffledItems(itemsToShuffle);}},[extractedItems,props.addLimit,props.itemLimit]);const getLayoutStyle=()=>{switch(props.layout){case\"vertical\":return{display:\"flex\",flexDirection:\"column\",gap:`${props.gapY}px`};case\"horizontal\":return{display:\"flex\",flexDirection:\"row\",gap:`${props.gapX}px`,flexWrap:\"wrap\"};case\"grid\":return{display:\"grid\",gridTemplateColumns:`repeat(${props.columns}, 1fr)`,columnGap:`${props.gapX}px`,rowGap:`${props.gapY}px`};default:return{display:\"flex\",flexDirection:\"column\",gap:`${props.gapY}px`};}};const getItemStyle=()=>{if(props.layout===\"horizontal\"){return{flex:\"0 0 auto\",minWidth:\"200px\"};}return{};};const hasCollection=props.collection&&React.Children.toArray(props.collection).filter(Boolean).length>0;if(isCanvas){if(!hasCollection){return /*#__PURE__*/_jsxs(\"div\",{style:{display:\"flex\",flexDirection:\"column\",alignItems:\"center\",textAlign:\"center\",justifyContent:\"center\",height:\"100%\",backgroundColor:\"rgba(153, 102, 255, 0.1)\",padding:\"40px\",gap:\"12px\"},children:[/*#__PURE__*/_jsx(\"span\",{role:\"img\",\"aria-label\":\"icon\",style:{fontSize:\"32px\"},children:\"🔀\"}),/*#__PURE__*/_jsxs(\"div\",{children:[/*#__PURE__*/_jsx(\"h3\",{style:{margin:0,fontSize:\"14px\",color:\"#96F\",fontWeight:600},children:\"CMS Shuffler\"}),/*#__PURE__*/_jsx(\"p\",{style:{margin:\"4px 0 0 0\",fontSize:\"12px\",color:\"rgba(153, 102, 255, 0.7)\"},children:\"Connect to a CMS to begin\"})]})]});}const canvasItemCount=props.addLimit?props.itemLimit:12;return /*#__PURE__*/_jsx(\"div\",{style:{overflow:\"visible\"},children:/*#__PURE__*/_jsx(\"div\",{style:getLayoutStyle(),children:Array.from({length:canvasItemCount},(_,num)=>/*#__PURE__*/_jsx(\"div\",{style:{...getItemStyle(),height:\"200px\"},children:/*#__PURE__*/_jsx(\"div\",{style:{backgroundColor:\"rgba(153, 102, 255, 0.2)\",height:\"100%\",borderRadius:\"8px\"}})},num))})});}if(!hasCollection){return /*#__PURE__*/_jsxs(\"div\",{style:{display:\"flex\",flexDirection:\"column\",alignItems:\"center\",textAlign:\"center\",justifyContent:\"center\",padding:\"40px\",gap:\"12px\"},children:[/*#__PURE__*/_jsx(\"span\",{role:\"img\",\"aria-label\":\"icon\",style:{fontSize:\"32px\"},children:\"🔀\"}),/*#__PURE__*/_jsxs(\"div\",{children:[/*#__PURE__*/_jsx(\"h3\",{style:{margin:0,fontSize:\"16px\",color:\"#666\",fontWeight:600},children:\"No CMS Collection Connected\"}),/*#__PURE__*/_jsx(\"p\",{style:{margin:\"4px 0 0 0\",fontSize:\"14px\",color:\"#999\"},children:\"Please connect to a CMS collection\"})]})]});}return /*#__PURE__*/_jsxs(\"div\",{style:{overflow:\"visible\"},children:[/*#__PURE__*/_jsx(motion.div,{style:{border:\"3.14px solid transparent\",opacity:0,position:\"absolute\",pointerEvents:\"none\"},animate:{scale:1},transition:{duration:.1},onAnimationComplete:handleAnimationComplete,children:props.collection}),shuffledItems.length===0?/*#__PURE__*/_jsx(\"div\",{children:\"Loading...\"}):/*#__PURE__*/_jsx(\"div\",{style:getLayoutStyle(),children:shuffledItems.map((item,index)=>/*#__PURE__*/_jsx(\"div\",{style:getItemStyle(),children:/*#__PURE__*/_jsx(\"div\",{dangerouslySetInnerHTML:{__html:item.element.outerHTML}})},index))})]});}CMSShuffler.defaultProps={layout:\"vertical\",columns:2,gapX:16,gapY:16,addLimit:false,itemLimit:12};addPropertyControls(CMSShuffler,{collection:{type:ControlType.ComponentInstance,title:\"Collection\",description:\"v1.0 \\n[via SegmentUI](https://www.segmentUI.com)\"},layout:{type:ControlType.Enum,title:\"Layout\",options:[\"vertical\",\"horizontal\",\"grid\"],optionTitles:[\"Vertical Stack\",\"Horizontal Stack\",\"Grid\"],defaultValue:\"vertical\"},columns:{type:ControlType.Number,title:\"Grid Columns\",min:1,max:6,step:1,defaultValue:2,hidden:props=>props.layout!==\"grid\"},gapX:{type:ControlType.Number,title:\"Gap X\",min:0,max:100,unit:\"px\",defaultValue:16},gapY:{type:ControlType.Number,title:\"Gap Y\",min:0,max:100,unit:\"px\",defaultValue:16},addLimit:{type:ControlType.Boolean,title:\"Add Limit\",defaultValue:false},itemLimit:{type:ControlType.Number,title:\"Item Limit\",min:1,max:100,step:1,defaultValue:12,hidden:props=>!props.addLimit}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"CMSShuffler\",\"slots\":[],\"annotations\":{\"framerSupportedLayoutWidth\":\"any-prefer-fixed\",\"framerDisableUnlink\":\"*\",\"framerContractVersion\":\"1\",\"framerSupportedLayoutHeight\":\"auto\",\"framerIntrinsicWidth\":\"600\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./CMSRandomiserHTML.map"],"mappings":"wPAOG,SAAwB,EAAY,EAAM,CAAC,IAAM,EAAS,EAAa,SAAS,GAAG,EAAa,OAAY,CAAC,EAAe,GAAmBA,EAAS,EAAE,CAAC,CAAM,CAAC,EAAc,GAAkBA,EAAS,EAAE,CAAC,CAAqD,EAAa,GAAO,CAAC,IAAM,EAAS,CAAC,GAAG,EAAM,CAAC,IAAI,IAAI,EAAE,EAAS,OAAO,EAAE,EAAE,EAAE,IAAI,CAAC,IAAM,EAAE,KAAK,MAAM,KAAK,QAAQ,EAAE,EAAE,GAAG,CAAC,CAAC,EAAS,GAAG,EAAS,IAAI,CAAC,EAAS,GAAG,EAAS,GAAG,CAAE,OAAO,GAAiB,EAAuB,GAAS,CAAC,GAAG,CAAC,EAAQ,MAAM,EAAE,CAAC,IAAM,EAAa,EAAE,CAAkP,OAA/N,EAAQ,iBAAiB,sBAAsB,CAAa,QAAQ,GAAI,CAAC,IAAM,EAAK,EAAG,aAAa,mBAAmB,CAAO,E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