{"version":3,"file":"WordStack.CfteGDx8.mjs","names":["useState","useMemo","containerWidth","positions","p"],"sources":["https:/framerusercontent.com/modules/wFPWrD7zDSKspfPmTnwb/FvtzDmIjULQktGCmV0RK/WordStack.js"],"sourcesContent":["// Component that distributes single words in a fixed-width stack with wrapping and repetition control\nimport{jsx as _jsx}from\"react/jsx-runtime\";import{addPropertyControls,ControlType}from\"framer\";import{useMemo,useState,useEffect,startTransition}from\"react\";/**\n * @framerSupportedLayoutWidth any-prefer-fixed\n * @framerSupportedLayoutHeight auto\n */export default function WordStack(props){const{items=[{text:\"Hello\",repetitions:3,textColor:\"#000000\"},{text:\"World\",repetitions:2,textColor:\"#000000\"}],font,verticalGap,fillColors=[\"#FF5588\",\"#8855FF\",\"#0099FF\",\"#22CC66\",\"#FFBB00\"],rotate90=false,noRepetition=false,appearDelayValues=[200],dynamic=false,dynamicMinTime=500,dynamicMaxTime=3e3,zIndexMin=1,zIndexMax=10,xOffsetValues=[0],style}=props;const[containerWidth,setContainerWidth]=useState(0);const containerRef=useState(null)[0];const textRefs=useState([])[0];const allWords=useMemo(()=>{const words=[];const maxRepetitions=Math.max(...items.map(item=>item.repetitions));for(let i=0;i<maxRepetitions;i++){items.forEach(item=>{if(i<item.repetitions){let randomFill=fillColors[Math.floor(Math.random()*fillColors.length)];// If noRepetition is enabled, ensure no more than 2 consecutive same colors\nif(noRepetition&&words.length>=2){const lastColor=words[words.length-1].fill;const secondLastColor=words[words.length-2].fill;// If last two colors are the same, pick a different color\nif(lastColor===secondLastColor){const availableColors=fillColors.filter(color=>color!==lastColor);if(availableColors.length>0){randomFill=availableColors[Math.floor(Math.random()*availableColors.length)];}}}// Randomly decide if this text layer should be rotated\nconst shouldRotate=rotate90&&Math.random()>.5;// Pick random z-index from range\nconst randomZIndex=Math.floor(Math.random()*(zIndexMax-zIndexMin+1))+zIndexMin;// Pick random X offset from array\nconst randomXOffset=xOffsetValues.length>0?xOffsetValues[Math.floor(Math.random()*xOffsetValues.length)]:0;words.push({text:item.text,color:item.textColor,fill:randomFill,rotate:shouldRotate,zIndex:randomZIndex,xOffset:randomXOffset});}});}return words;},[items,fillColors,rotate90,noRepetition,zIndexMin,zIndexMax,xOffsetValues]);// Calculate positions for absolute positioning\nconst positions=useMemo(()=>{if(!style?.width||typeof style.width!==\"string\")return[];const containerWidth=parseFloat(style.width)||800;const positions=[];let currentX=0;let currentY=0;let lineHeight=0;allWords.forEach((word,index)=>{// Estimate text width (rough approximation)\nconst fontSize=parseFloat(font?.fontSize||\"22\");const estimatedWidth=word.text.length*fontSize*.6;// Check if we need to wrap to next line\nif(currentX+estimatedWidth>containerWidth&&currentX>0){currentX=0;currentY+=lineHeight+verticalGap;lineHeight=0;}positions.push({x:currentX,y:currentY});// Update for next iteration\ncurrentX+=estimatedWidth+12;lineHeight=Math.max(lineHeight,fontSize*1.2);});return positions;},[allWords,style?.width,font,verticalGap]);// Calculate total height based on positions\nconst totalHeight=useMemo(()=>{if(positions.length===0)return 100// Minimum height\n;const fontSize=parseFloat(font?.fontSize||\"22\");const maxY=Math.max(...positions.map(p=>p.y));const calculatedHeight=maxY+fontSize*1.2+20// Add padding\n;return Math.max(calculatedHeight,100)// Ensure minimum height of 100px\n;},[positions,font]);const[visibleIndices,setVisibleIndices]=useState(new Set);const[dynamicVisibility,setDynamicVisibility]=useState(new Map);useEffect(()=>{// Show all immediately\nstartTransition(()=>setVisibleIndices(new Set(allWords.map((_,i)=>i))));},[allWords]);// Dynamic animation effect\nuseEffect(()=>{if(!dynamic){// Reset dynamic visibility when disabled\nstartTransition(()=>setDynamicVisibility(new Map));return;}// Initialize all as visible\nconst initialVisibility=new Map;allWords.forEach((_,index)=>{initialVisibility.set(index,true);});startTransition(()=>setDynamicVisibility(initialVisibility));const timers=[];// For each text layer, set up a random animation loop\nallWords.forEach((_,index)=>{const animateLayer=()=>{// Random delay before toggling (between dynamicMinTime and dynamicMaxTime)\nconst delay=Math.random()*(dynamicMaxTime-dynamicMinTime)+dynamicMinTime;const timer=window.setTimeout(()=>{startTransition(()=>{setDynamicVisibility(prev=>{const newMap=new Map(prev);newMap.set(index,!prev.get(index));return newMap;});});// Schedule next toggle\nanimateLayer();},delay);timers.push(timer);};// Start animation for this layer with initial random delay\nconst initialDelay=Math.random()*(dynamicMaxTime-dynamicMinTime);const initialTimer=window.setTimeout(()=>{animateLayer();},initialDelay);timers.push(initialTimer);});return()=>{timers.forEach(timer=>clearTimeout(timer));};},[dynamic,allWords,dynamicMinTime,dynamicMaxTime]);return /*#__PURE__*/_jsx(\"div\",{style:{width:\"100%\",height:totalHeight,minHeight:100,position:\"relative\"},children:allWords.map((word,index)=>/*#__PURE__*/_jsx(\"span\",{style:{...font,color:word.color,backgroundColor:word.fill,whiteSpace:\"nowrap\",position:\"absolute\",left:(positions[index]?.x||0)+word.xOffset,top:positions[index]?.y||0,transform:word.rotate?\"rotate(-90deg)\":\"\",opacity:dynamic?dynamicVisibility.get(index)?1:0:1,transition:\"none\",zIndex:word.zIndex},children:word.text},index))});}addPropertyControls(WordStack,{items:{type:ControlType.Array,title:\"Text Items\",control:{type:ControlType.Object,controls:{text:{type:ControlType.String,title:\"Text\",defaultValue:\"Word\"},repetitions:{type:ControlType.Number,title:\"Repetitions\",defaultValue:1,min:1,max:100,step:1},textColor:{type:ControlType.Color,title:\"Text Color\",defaultValue:\"#000000\"}}},defaultValue:[{text:\"Hello\",repetitions:3,textColor:\"#000000\"},{text:\"World\",repetitions:2,textColor:\"#000000\"},{text:\"Framer\",repetitions:4,textColor:\"#000000\"}]},fillColors:{type:ControlType.Array,title:\"Fill Colors\",control:{type:ControlType.Color},defaultValue:[\"#FF5588\",\"#8855FF\",\"#0099FF\",\"#22CC66\",\"#FFBB00\"]},font:{type:ControlType.Font,title:\"Font\",controls:\"extended\",defaultFontType:\"sans-serif\",defaultValue:{fontSize:\"22px\",variant:\"Semibold\",letterSpacing:\"-0.01em\",lineHeight:\"1.2em\"}},verticalGap:{type:ControlType.Number,title:\"Vertical Gap\",defaultValue:12,min:-50,max:50,step:1,unit:\"px\"},rotate90:{type:ControlType.Boolean,title:\"Rotate 90\",defaultValue:false,enabledTitle:\"On\",disabledTitle:\"Off\"},noRepetition:{type:ControlType.Boolean,title:\"No Repetition\",defaultValue:false,enabledTitle:\"On\",disabledTitle:\"Off\"},dynamic:{type:ControlType.Boolean,title:\"Dynamic\",defaultValue:false,enabledTitle:\"On\",disabledTitle:\"Off\"},dynamicMinTime:{type:ControlType.Number,title:\"Dynamic Min Time\",defaultValue:500,min:100,max:5e3,step:100,unit:\"ms\",hidden:({dynamic})=>!dynamic},dynamicMaxTime:{type:ControlType.Number,title:\"Dynamic Max Time\",defaultValue:3e3,min:100,max:1e4,step:100,unit:\"ms\",hidden:({dynamic})=>!dynamic},zIndexMin:{type:ControlType.Number,title:\"Z-Index Min\",defaultValue:1,min:-100,max:100,step:1},zIndexMax:{type:ControlType.Number,title:\"Z-Index Max\",defaultValue:10,min:-100,max:100,step:1},xOffsetValues:{type:ControlType.Array,title:\"X Offset Values\",control:{type:ControlType.Number,min:-200,max:200,step:1,unit:\"px\"},defaultValue:[0]}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"WordStack\",\"slots\":[],\"annotations\":{\"framerSupportedLayoutHeight\":\"auto\",\"framerContractVersion\":\"1\",\"framerSupportedLayoutWidth\":\"any-prefer-fixed\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./WordStack.map"],"mappings":"8MAIG,SAAwB,EAAU,EAAM,CAAC,GAAK,CAAC,QAAM,CAAC,CAAC,KAAK,QAAQ,YAAY,EAAE,UAAU,UAAU,CAAC,CAAC,KAAK,QAAQ,YAAY,EAAE,UAAU,UAAU,CAAC,CAAC,OAAK,cAAY,aAAW,CAAC,UAAU,UAAU,UAAU,UAAU,UAAU,CAAC,WAAS,GAAM,eAAa,GAAM,oBAAkB,CAAC,IAAI,CAAC,UAAQ,GAAM,iBAAe,IAAI,iBAAe,IA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