{"version":3,"file":"TextStaggerCustom.DBgX9RI2.mjs","names":["useState","useRef","React"],"sources":["https:/framerusercontent.com/modules/RNsX3H5fDgUWCApSJXtQ/RMsIxRnX3lq9xkOitMCd/TextStaggerCustom.js"],"sourcesContent":["import{jsx as _jsx,jsxs as _jsxs}from\"react/jsx-runtime\";import{addPropertyControls,ControlType,RenderTarget}from\"framer\";import{motion}from\"framer-motion\";import React,{useRef,useState,useLayoutEffect}from\"react\";/**\n * @framerSupportedLayoutWidth any\n * @framerSupportedLayoutHeight auto\n */function getFontSizeForWidth(w,fontSizeMobile,fontSizeTablet,fontSizeDesktop){if(w<768)return fontSizeMobile;if(w<1024)return fontSizeTablet;return fontSizeDesktop;}// Live animation component — font size now tracks the REAL viewport width,\n// measured only in the browser (useLayoutEffect never runs during SSR),\n// and updates on resize instead of freezing at the first (possibly wrong) read.\nfunction TextStaggerLive({text,fontFamily,fontSizeDesktop,fontSizeTablet,fontSizeMobile,fontWeight,color,lineHeight,letterSpacing,stagger,duration,yOffset,style}){const[fontSize,setFontSize]=useState(null);const containerRef=useRef(null);const[wordLines,setWordLines]=useState(null);const words=text.split(\" \");// Measure the real viewport width — guaranteed client-side only.\nuseLayoutEffect(()=>{const updateFontSize=()=>{setFontSize(getFontSizeForWidth(window.innerWidth,fontSizeMobile,fontSizeTablet,fontSizeDesktop));};updateFontSize();window.addEventListener(\"resize\",updateFontSize);return()=>window.removeEventListener(\"resize\",updateFontSize);},[fontSizeMobile,fontSizeTablet,fontSizeDesktop]);// Recompute word→line mapping once we know the real font size\nuseLayoutEffect(()=>{if(!containerRef.current||fontSize===null)return;const spans=containerRef.current.querySelectorAll(\"[data-word-idx]\");const topMap=new Map;spans.forEach(span=>{const idx=parseInt(span.getAttribute(\"data-word-idx\"));const top=Math.round(span.getBoundingClientRect().top);if(!topMap.has(top))topMap.set(top,[]);topMap.get(top).push(idx);});const result={};let lineNum=0;[...topMap.entries()].sort(([a],[b])=>a-b).forEach(([,indices])=>{indices.forEach(idx=>{result[idx]=lineNum;});lineNum++;});setWordLines(result);},[fontSize,text]);// Not measured yet — stay hidden so nothing ever paints at the wrong size\nif(fontSize===null){return /*#__PURE__*/_jsx(\"div\",{style:{fontFamily,fontSize:fontSizeMobile,fontWeight,color,lineHeight,letterSpacing,overflow:\"visible\",paddingBottom:\"0.15em\",margin:0,padding:0,visibility:\"hidden\",...style},children:text});}return /*#__PURE__*/_jsx(\"div\",{ref:containerRef,style:{fontFamily,fontSize,fontWeight,color,lineHeight,letterSpacing,overflow:\"visible\",paddingBottom:\"0.15em\",margin:0,padding:0,...style},children:words.map((word,i)=>/*#__PURE__*/_jsxs(React.Fragment,{children:[wordLines!==null?/*#__PURE__*/_jsx(motion.span,{style:{display:\"inline-block\",overflow:\"visible\"},initial:{opacity:0,y:yOffset},animate:{opacity:1,y:0},transition:{duration,delay:wordLines[i]*stagger,ease:\"easeOut\"},children:word}):/*#__PURE__*/_jsx(\"span\",{\"data-word-idx\":i,style:{display:\"inline-block\",visibility:\"hidden\"},children:word}),i<words.length-1&&\" \"]},i))});}export default function TextStaggerCustom(props){const{text=\"Your text here\",fontFamily=\"Switzer, 'Helvetica Neue', sans-serif\",fontSizeDesktop=56,fontSizeTablet=40,fontSizeMobile=36,fontWeight=500,color=\"#000000\",lineHeight=1.1,letterSpacing=0,stagger=.14,duration=.6,yOffset=20,style}=props;const isCanvas=RenderTarget.current()===RenderTarget.canvas;// Canvas: static preview at desktop size\nif(isCanvas){return /*#__PURE__*/_jsx(\"div\",{style:{fontFamily,fontSize:fontSizeDesktop,fontWeight,color,lineHeight,letterSpacing,overflow:\"visible\",paddingBottom:\"0.15em\",margin:0,padding:0,...style},children:text});}return /*#__PURE__*/_jsx(TextStaggerLive,{text:text,fontFamily:fontFamily,fontSizeDesktop:fontSizeDesktop,fontSizeTablet:fontSizeTablet,fontSizeMobile:fontSizeMobile,fontWeight:fontWeight,color:color,lineHeight:lineHeight,letterSpacing:letterSpacing,stagger:stagger,duration:duration,yOffset:yOffset,style:style});}addPropertyControls(TextStaggerCustom,{text:{type:ControlType.String,title:\"Text\",defaultValue:\"Motion Designer & Art Director\",displayTextArea:true},fontFamily:{type:ControlType.String,title:\"Font\",defaultValue:\"Switzer, 'Helvetica Neue', sans-serif\"},fontSizeDesktop:{type:ControlType.Number,title:\"Size Desktop\",defaultValue:56,min:8,max:300,unit:\"px\"},fontSizeTablet:{type:ControlType.Number,title:\"Size Tablet\",defaultValue:40,min:8,max:300,unit:\"px\"},fontSizeMobile:{type:ControlType.Number,title:\"Size Mobile\",defaultValue:36,min:8,max:300,unit:\"px\"},fontWeight:{type:ControlType.Number,title:\"Weight\",defaultValue:500,min:100,max:900,step:100},color:{type:ControlType.Color,title:\"Color\",defaultValue:\"#000000\"},lineHeight:{type:ControlType.Number,title:\"Line Height\",defaultValue:1.1,min:.8,max:3,step:.05},letterSpacing:{type:ControlType.Number,title:\"Letter Spacing\",defaultValue:0,min:-5,max:20,step:.1,unit:\"px\"},stagger:{type:ControlType.Number,title:\"Stagger\",defaultValue:.14,step:.01,min:0,max:1},duration:{type:ControlType.Number,title:\"Duration\",defaultValue:.6,step:.05,min:.1,max:3},yOffset:{type:ControlType.Number,title:\"Y Offset\",defaultValue:20,min:0,max:100,unit:\"px\"}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"TextStaggerCustom\",\"slots\":[],\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./TextStaggerCustom.map"],"mappings":"4QAGG,SAAS,EAAoB,EAAE,EAAe,EAAe,EAAgB,CAAgE,OAA5D,EAAE,IAAW,EAAkB,EAAE,KAAY,EAAsB,CAAgB,CAGvK,SAAS,EAAgB,CAAC,OAAK,aAAW,kBAAgB,iBAAe,iBAAe,aAAW,QAAM,aAAW,gBAAc,UAAQ,WAAS,UAAQ,SAAO,CAAC,GAAK,CAAC,EAAS,GAAaA,EAAS,IAAI,EAAQ,E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