{"version":3,"file":"TextScrambler.CWmAsfTL.mjs","names":["useMemo","useState","useRef","useCallback","__esmMin","init_npm_react_18_3_1","te","pe","ce","init_jsx_runtime","ne","_e","de","useInView","init_framer_motion_DhsWWWsN","addPropertyControls","ControlType","init_framer_DxfB3JJo","TextScrambler","props","formattedText","formatAsJson","text","parsed","indentSpaces","displayText","setDisplayText","animationRef","containerRef","isInView","currentTextRef","isAnimatingRef","lastUpdateRef","colorMap","punctuationChars","map","insideQuotedValue","afterColonSpace","char","parenthesesColor","textColor","punctuationColor","chars","charsArray","characters","autoPlay","startAnimation","startTime","totalChars","charsLen","animate","timestamp","elapsed","progress","easedProgress","revealIndex","scrambled","i","loop","renderedContent","elements","textLength","currentColor","currentSegment","charColor","style","font","init_TextScrambler"],"sources":["https:/framerusercontent.com/modules/wcqWWoKMiAkLGOToSt7X/mNzurPUQrWV9hFJits0A/TextScrambler.js"],"sourcesContent":["// Text scrambler effect where each character animates to reveal a customizable word\n// Retains text spaces and line breaks (shift + enter)\n// Designed to show JSON code or any other text\nimport{jsx as _jsx}from\"react/jsx-runtime\";import{useEffect,useState,useRef,useMemo,useCallback,startTransition}from\"react\";import{addPropertyControls,ControlType}from\"framer\";import{useInView}from\"framer-motion\";/**\n * @framerSupportedLayoutWidth auto\n * @framerSupportedLayoutHeight auto\n */export default function TextScrambler(props){const{text=\"Hello World\\nThis is a test\",characters=\"!@#$%^&*()_+-=[]{}|;:,.<>?\",autoPlay=true,loop=false,textColor=\"#000000\",punctuationColor=\"#000000\",parenthesesColor=\"#000000\",font,formatAsJson=false,indentSpaces=2,style}=props;// Format JSON if enabled - memoized\nconst formattedText=useMemo(()=>{if(!formatAsJson)return text;try{const parsed=JSON.parse(text);return JSON.stringify(parsed,null,indentSpaces);}catch(e){return text;}},[text,formatAsJson,indentSpaces]);const[displayText,setDisplayText]=useState(formattedText);const animationRef=useRef(null);const containerRef=useRef(null);const isInView=useInView(containerRef,{once:true});const currentTextRef=useRef(formattedText);const isAnimatingRef=useRef(false);const lastUpdateRef=useRef(0);// Pre-calculate color map for each character - memoized\nconst colorMap=useMemo(()=>{const punctuationChars=/[{}\\[\\],;:]/;const map=new Array(formattedText.length);let insideQuotedValue=false;let afterColonSpace=false;for(let i=0;i<formattedText.length;i++){const char=formattedText[i];if(i>=2&&formattedText[i-1]===\" \"&&formattedText[i-2]===\":\"){afterColonSpace=true;}if(char==='\"'){if(afterColonSpace||insideQuotedValue){insideQuotedValue=!insideQuotedValue;map[i]=parenthesesColor;}else{map[i]=textColor;}afterColonSpace=false;}else if(char===\",\"||char===\"\\n\"&&!insideQuotedValue){if(char===\",\"){insideQuotedValue=false;}afterColonSpace=false;map[i]=punctuationChars.test(char)?punctuationColor:textColor;}else{if(insideQuotedValue&&char!==\"\\n\"){map[i]=parenthesesColor;}else if(punctuationChars.test(char)){map[i]=punctuationColor;}else{map[i]=textColor;}}}return map;},[formattedText,textColor,punctuationColor,parenthesesColor]);// Pre-split text into characters array - memoized\nconst chars=useMemo(()=>formattedText.split(\"\"),[formattedText]);const charsArray=useMemo(()=>characters.split(\"\"),[characters]);// Cancel animation and reset state when text changes\nuseEffect(()=>{if(currentTextRef.current!==formattedText){if(animationRef.current!==null){cancelAnimationFrame(animationRef.current);animationRef.current=null;}isAnimatingRef.current=false;setDisplayText(formattedText);currentTextRef.current=formattedText;if(autoPlay&&isInView){setTimeout(()=>startAnimation(),50);}}},[formattedText]);useEffect(()=>{if(autoPlay&&!isAnimatingRef.current&&isInView&&currentTextRef.current===formattedText){startAnimation();}return()=>{if(animationRef.current!==null){cancelAnimationFrame(animationRef.current);}};},[autoPlay,isInView]);const startAnimation=useCallback(()=>{if(isAnimatingRef.current)return;isAnimatingRef.current=true;const startTime=performance.now();const duration=1e3;const totalChars=chars.length;const charsLen=charsArray.length;const throttleMs=16// ~60fps max\n;const animate=timestamp=>{// Throttle updates to reduce re-renders\nif(timestamp-lastUpdateRef.current<throttleMs){animationRef.current=requestAnimationFrame(animate);return;}lastUpdateRef.current=timestamp;const elapsed=timestamp-startTime;const progress=Math.min(elapsed/duration,1);// Easing\nconst easedProgress=progress<.5?8*progress*progress*progress*progress:1-Math.pow(-2*progress+2,4)/2;const revealIndex=Math.floor(easedProgress*totalChars);// Build scrambled text in one pass\nlet scrambled=\"\";for(let i=0;i<totalChars;i++){const char=chars[i];if(char===\" \"||char===\"\\n\"){scrambled+=char;}else if(i<revealIndex){scrambled+=char;}else{scrambled+=charsArray[Math.floor(Math.random()*charsLen)];}}startTransition(()=>{setDisplayText(scrambled);});if(progress<1){animationRef.current=requestAnimationFrame(animate);}else{startTransition(()=>{setDisplayText(formattedText);});isAnimatingRef.current=false;if(loop){setTimeout(()=>startAnimation(),1e3);}}};animationRef.current=requestAnimationFrame(animate);},[chars,charsArray,formattedText,loop]);// Render with pre-calculated colors - optimized to reduce DOM elements\nconst renderedContent=useMemo(()=>{const elements=[];const textLength=displayText.length;let currentColor=colorMap[0]||textColor;let currentSegment=\"\";for(let i=0;i<textLength;i++){const char=displayText[i];const charColor=colorMap[i]||textColor;if(char===\"\\n\"){if(currentSegment){elements.push(/*#__PURE__*/_jsx(\"span\",{style:{color:currentColor},children:currentSegment},`seg-${elements.length}`));currentSegment=\"\";}elements.push(/*#__PURE__*/_jsx(\"br\",{},`br-${i}`));currentColor=colorMap[i+1]||textColor;}else if(charColor!==currentColor){if(currentSegment){elements.push(/*#__PURE__*/_jsx(\"span\",{style:{color:currentColor},children:currentSegment},`seg-${elements.length}`));}currentSegment=char;currentColor=charColor;}else{currentSegment+=char;}}if(currentSegment){elements.push(/*#__PURE__*/_jsx(\"span\",{style:{color:currentColor},children:currentSegment},`seg-${elements.length}`));}return elements;},[displayText,colorMap,textColor]);return /*#__PURE__*/_jsx(\"div\",{ref:containerRef,style:{...style,position:\"relative\",display:\"flex\",alignItems:\"flex-start\",width:\"100%\",height:\"100%\"},children:/*#__PURE__*/_jsx(\"div\",{style:{margin:0,padding:0,whiteSpace:\"pre-wrap\",wordBreak:\"break-word\",width:\"100%\",...font},children:renderedContent})});}addPropertyControls(TextScrambler,{text:{type:ControlType.String,title:\"Text\",defaultValue:\"Hello World\\nThis is a test\",displayTextArea:true},characters:{type:ControlType.String,title:\"Scramble Chars\",defaultValue:\"!@#$%^&*()_+-=[]{}|;:,.<>?\"},autoPlay:{type:ControlType.Boolean,title:\"Auto Play\",defaultValue:true,enabledTitle:\"On\",disabledTitle:\"Off\"},loop:{type:ControlType.Boolean,title:\"Loop\",defaultValue:false,enabledTitle:\"On\",disabledTitle:\"Off\"},textColor:{type:ControlType.Color,title:\"Text Color\",defaultValue:\"#000000\"},punctuationColor:{type:ControlType.Color,title:\"Punctuation Color\",defaultValue:\"#000000\"},parenthesesColor:{type:ControlType.Color,title:\"Parentheses Color\",defaultValue:\"#000000\"},font:{type:ControlType.Font,title:\"Font\",controls:\"extended\",defaultFontType:\"monospace\",defaultValue:{fontSize:\"15px\",variant:\"Medium\",letterSpacing:\"-0.01em\",lineHeight:\"1.3em\"}}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"TextScrambler\",\"slots\":[],\"annotations\":{\"framerSupportedLayoutHeight\":\"auto\",\"framerContractVersion\":\"1\",\"framerSupportedLayoutWidth\":\"auto\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./TextScrambler.map"],"mappings":"A,0PAMG,SAAwBkB,EAAc,EAAM,CAAC,GAAK,CAAC,OAAK;gBAA8B,aAAW,6BAA6B,WAAS,GAAK,OAAK,GAAM,YAAU,UAAU,mBAAiB,UAAU,mBAAiB,UAAU,OAAK,eAAa,GAAM,eAAa,EAAE,SAAOC,EAC5QC,EAAcpB,MAAY,CAAC,GAAG,CAACqB,EAAa,OAAOC,EAAK,GAAG,CAAC,IAAMC,EAAO,KAAK,MAAMD,CAAI,EAAE,OAAO,KAAK,UAAUC,EAAO,KAAKC,CAAY,CAAE,MAAS,CAAC,OAAOF,CAAK,CAAC,EAAE,CAACA,EAAKD,EAAaG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