{"version":3,"file":"RollingText.CIHSShPb.mjs","names":["useRef","useMemo","props","useState","baseTextStyle"],"sources":["https:/framerusercontent.com/modules/11qmS7i5y43wChit0SzP/QswL23iud8mSmm1T4Sni/RollingText.js"],"sourcesContent":["import{jsx as _jsx,jsxs as _jsxs}from\"react/jsx-runtime\";import{useMemo,useRef,useState,useEffect,startTransition}from\"react\";import{addPropertyControls,ControlType,useIsStaticRenderer}from\"framer\";import{useInView}from\"framer-motion\";/**\n * Rolling Text Appear Animation\n *\n * @framerIntrinsicWidth 400\n * @framerIntrinsicHeight 80\n *\n * @framerSupportedLayoutWidth any-prefer-fixed\n * @framerSupportedLayoutHeight any-prefer-fixed\n *\n * User goal:\n * Maak een text appear rolling animation. In de control panel wil ik die font styles, font kleur, Align en context aanpassen.\n * NOTE: Awaiting clarification from user about the exact desired \"stopwatch\" effect.\n */export default function RollingText(props){const{text,font,color,align,duration,delayBetween,repeatCount,style}=props;const isStatic=useIsStaticRenderer();const containerRef=useRef(null);const isInView=useInView(containerRef,{once:true,margin:\"-10% 0px\"});const words=useMemo(()=>{if(!text)return[];// Split text into words/tokens, ignoring extra spaces. Spaces should not be counted as separate slots.\nconst rawTokens=text.split(\" \");const tokens=rawTokens.filter(token=>token.length>0);return tokens.map((token,wordIndex)=>({key:`word-${wordIndex}-${token}`,chars:token.split(\"\").map((ch,charIndex)=>({char:ch,key:`w${wordIndex}-c${charIndex}-${ch}`}))}));},[text]);const isFixedWidth=style&&style.width===\"100%\";const isFixedHeight=style&&style.height===\"100%\";const baseTextStyle={...font,color,textAlign:align,whiteSpace:\"pre-wrap\"};const renderWordWithStyle=content=>{return /*#__PURE__*/_jsx(\"span\",{style:{...baseTextStyle,display:\"inline-block\"},children:content});};// Character component that shows random numbers before settling on the final character\nfunction AnimatedChar(props){const{finalChar,isActive,totalDuration,delay,baseTextStyle}=props;const[displayChar,setDisplayChar]=useState(\"\");useEffect(()=>{const isDigit=/[0-9]/.test(finalChar);// Only run the random number effect for numeric characters.\n// For letters, symbols, and spaces, just show the final character directly.\nif(!isDigit){startTransition(()=>{setDisplayChar(finalChar);});return;}// For numeric characters, don't show the final value until the animation has run\nif(!isActive){startTransition(()=>{setDisplayChar(\"\");});return;}let intervalId;let timeoutId;const startAnimation=()=>{const safeDuration=Math.max(totalDuration,.1);const startTime=Date.now();intervalId=window.setInterval(()=>{const elapsedSeconds=(Date.now()-startTime)/1e3;if(elapsedSeconds>=safeDuration){if(intervalId!==undefined){window.clearInterval(intervalId);}startTransition(()=>{setDisplayChar(finalChar);});}else{const randomDigit=Math.floor(Math.random()*10).toString();startTransition(()=>{setDisplayChar(randomDigit);});}},50);};if(typeof window!==\"undefined\"){if(delay>0){timeoutId=window.setTimeout(startAnimation,delay*1e3);}else{startAnimation();}}return()=>{if(typeof window!==\"undefined\"){if(intervalId!==undefined){window.clearInterval(intervalId);}if(timeoutId!==undefined){window.clearTimeout(timeoutId);}}};},[isActive,finalChar,totalDuration,delay]);return /*#__PURE__*/_jsx(\"span\",{style:{...baseTextStyle,display:\"inline-block\"},children:displayChar});}if(isStatic){return /*#__PURE__*/_jsx(\"div\",{ref:containerRef,style:{...style,position:\"relative\",display:\"flex\",alignItems:\"center\",justifyContent:align===\"left\"?\"flex-start\":align===\"center\"?\"center\":\"flex-end\",overflow:\"hidden\",width:isFixedWidth?\"100%\":\"max-content\",height:isFixedHeight?\"100%\":\"auto\"},children:/*#__PURE__*/_jsx(\"span\",{style:{...baseTextStyle,width:isFixedWidth?\"100%\":\"max-content\"},children:text})});}return /*#__PURE__*/_jsx(\"div\",{ref:containerRef,style:{...style,position:\"relative\",display:\"flex\",alignItems:\"center\",justifyContent:align===\"left\"?\"flex-start\":align===\"center\"?\"center\":\"flex-end\",overflow:\"hidden\",width:isFixedWidth?\"100%\":\"max-content\",height:isFixedHeight?\"100%\":\"auto\"},children:/*#__PURE__*/_jsx(\"div\",{style:{display:\"inline-flex\",flexWrap:\"wrap\",alignItems:\"baseline\",justifyContent:align===\"left\"?\"flex-start\":align===\"center\"?\"center\":\"flex-end\",width:isFixedWidth?\"100%\":\"max-content\",perspective:800},children:words.map((word,wordIndex)=>/*#__PURE__*/_jsxs(\"span\",{style:{display:\"inline-flex\",alignItems:\"baseline\"},children:[word.chars.map(item=>{const isDigit=/[0-9]/.test(item.char);// For non-numeric characters (letters, symbols), render them statically without any animation.\n    if(!isDigit){return /*#__PURE__*/_jsx(\"span\",{style:{...baseTextStyle,display:\"inline-block\"},children:item.char},item.key);}return /*#__PURE__*/_jsx(AnimatedChar,{finalChar:item.char,isActive:isInView,totalDuration:duration*(Math.max(0,repeatCount)+1),delay:wordIndex*delayBetween,baseTextStyle:baseTextStyle},item.key);}),wordIndex<words.length-1&&/*#__PURE__*/_jsx(\"span\",{style:{...baseTextStyle,display:\"inline-block\"},children:\" \"})]},word.key))})});}addPropertyControls(RollingText,{text:{type:ControlType.String,title:\"Text\",defaultValue:\"Dit is een rolling text animatie in Framer.\",displayTextArea:true},font:{type:ControlType.Font,title:\"Font\",defaultValue:{fontSize:\"32px\",variant:\"Semibold\",letterSpacing:\"-0.03em\",lineHeight:\"1.1em\",textAlign:\"left\"},controls:\"extended\",defaultFontType:\"sans-serif\"},color:{type:ControlType.Color,title:\"Font Color\",defaultValue:\"#000000\"},align:{type:ControlType.Enum,title:\"Align\",defaultValue:\"left\",options:[\"left\",\"center\",\"right\"],optionTitles:[\"Left\",\"Center\",\"Right\"],displaySegmentedControl:true},duration:{type:ControlType.Number,title:\"Character Duration\",defaultValue:.5,min:.1,max:2,step:.05,unit:\"s\"},delayBetween:{type:ControlType.Number,title:\"Delay Between\",defaultValue:.05,min:0,max:.5,step:.01,unit:\"s\"},repeatCount:{type:ControlType.Number,title:\"Loop Count\",defaultValue:4,min:0,max:20,step:1}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"RollingText\",\"slots\":[],\"annotations\":{\"framerSupportedLayoutHeight\":\"any-prefer-fixed\",\"framerContractVersion\":\"1\",\"framer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