{"version":3,"file":"TextScrambler.DFhrKYri.mjs","names":["React.useState","React.useRef"],"sources":["https:/framerusercontent.com/modules/N9j1CZ9Nb4EUHUC5QrQR/zYlpOGgDufc5s1BNdm6W/TextScrambler.js"],"sourcesContent":["// Text scrambler effect with customizable word\nimport{jsx as _jsx}from\"react/jsx-runtime\";import*as React from\"react\";import{addPropertyControls,ControlType,useIsOnFramerCanvas,RenderTarget}from\"framer\";const CHARS=\"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()_+-=<>?\".split(\"\");/**\n * TextScrambler\n *\n * @framerIntrinsicWidth 320\n * @framerIntrinsicHeight 60\n *\n * @framerSupportedLayoutWidth any-prefer-fixed\n * @framerSupportedLayoutHeight fixed\n */function TextScrambler(props){const{text=\"Scrambled!\",duration=1.2,font,color,scrambleColor,scrambleSpeed}=props;const isCanvas=useIsOnFramerCanvas()||RenderTarget.current()===RenderTarget.thumbnail;const[display,setDisplay]=React.useState(text);const[done,setDone]=React.useState(false);const raf=React.useRef();const startTime=React.useRef();const prevText=React.useRef(text);const scrambleState=React.useRef({});React.useEffect(()=>{if(isCanvas){setDisplay(text);setDone(true);return;}setDone(false);let delayTimeout;let repeatTimeout;function startScramble(){scrambleState.current={revealed:Array(text.length).fill(false),output:Array(text.length).fill(\"\")};for(let i=0;i<text.length;i++){scrambleState.current.output[i]=CHARS[Math.floor(Math.random()*CHARS.length)];}setDisplay(scrambleState.current.output.join(\"\"));startTime.current=undefined;raf.current=requestAnimationFrame(animate);}function animate(now){if(!startTime.current)startTime.current=now;const elapsed=(now-startTime.current)/1e3;let progress=Math.min(1,elapsed/duration);let charsToReveal=Math.floor(progress*text.length);for(let i=0;i<text.length;i++){if(i<charsToReveal){scrambleState.current.output[i]=text[i];scrambleState.current.revealed[i]=true;}else if(!scrambleState.current.revealed[i]){scrambleState.current.output[i]=CHARS[Math.floor(Math.random()*CHARS.length)];}}setDisplay(scrambleState.current.output.join(\"\"));if(progress<1){raf.current=requestAnimationFrame(animate);}else{setDisplay(text);setDone(true);if(props.repeat){repeatTimeout=setTimeout(()=>{setDone(false);startScramble();},(props.repeatPause||1)*1e3);}}}if(props.delay&&props.delay>0){delayTimeout=setTimeout(()=>{startScramble();},props.delay*1e3);}else{startScramble();}return()=>{cancelAnimationFrame(raf.current);clearTimeout(delayTimeout);clearTimeout(repeatTimeout);startTime.current=undefined;};},[text,duration,scrambleSpeed,isCanvas,props.delay,props.repeat,props.repeatPause]);React.useEffect(()=>{if(prevText.current!==text){setDone(false);prevText.current=text;}},[text]);return /*#__PURE__*/_jsx(\"div\",{style:{...props.style,position:\"relative\",width:\"100%\",height:\"100%\",display:\"flex\",alignItems:\"center\",justifyContent:props.alignment===\"left\"?\"flex-start\":props.alignment===\"right\"?\"flex-end\":\"center\",color:color,...font,fontFamily:font?.fontFamily||\"inherit\",fontSize:font?.fontSize||32,letterSpacing:font?.letterSpacing,lineHeight:font?.lineHeight,fontWeight:(()=>{const v=font?.variant?.toLowerCase?.()||\"\";if(v.includes(\"bold\"))return 700;if(v.includes(\"semibold\"))return 600;if(v.includes(\"medium\"))return 500;if(v.includes(\"regular\"))return 400;if(v.includes(\"light\"))return 300;return undefined;})(),userSelect:\"none\",whiteSpace:\"pre\",overflow:\"hidden\",textAlign:props.alignment||\"center\"},\"aria-label\":text,children:display.split(\"\").map((char,i)=>/*#__PURE__*/_jsx(\"span\",{style:{color:done||display[i]===text[i]?color:scrambleColor,transition:\"color 0.5s cubic-bezier(0.4,0,0.2,1)\",willChange:\"color\"},children:char},i))});}addPropertyControls(TextScrambler,{text:{type:ControlType.String,title:\"Text\",defaultValue:\"Scrambled!\",placeholder:\"Type your text…\"},duration:{type:ControlType.Number,title:\"Duration\",min:.3,max:5,step:.1,defaultValue:1.2,unit:\"s\"},scrambleSpeed:{type:ControlType.Number,title:\"Scramble Speed\",min:.5,max:3,step:.1,defaultValue:1},delay:{type:ControlType.Number,title:\"Delay\",min:0,max:5,step:.1,defaultValue:0,unit:\"s\"},color:{type:ControlType.Color,title:\"Text Color\",defaultValue:\"#000000\"},scrambleColor:{type:ControlType.Color,title:\"Scramble Color\",defaultValue:\"#CCCCCC\"},font:{type:ControlType.Font,title:\"Font\",controls:\"extended\",defaultFontType:\"sans-serif\",defaultValue:{fontSize:\"32px\",variant:\"Semibold\",letterSpacing:\"-0.03em\",lineHeight:\"1em\"}},alignment:{type:ControlType.Enum,title:\"Alignment\",options:[\"left\",\"center\",\"right\"],optionTitles:[\"Left\",\"Center\",\"Right\"],defaultValue:\"center\"},repeat:{type:ControlType.Boolean,title:\"Repeat\",defaultValue:false,enabledTitle:\"Yes\",disabledTitle:\"No\"},repeatPause:{type:ControlType.Number,title:\"Repeat Pause\",min:.2,max:10,step:.1,defaultValue:1,unit:\"s\",hidden:props=>!props.repeat}});export default TextScrambler;\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"TextScrambler\",\"slots\":[],\"annotations\":{\"framerSupportedLayoutWidth\":\"any-prefer-fixed\",\"framerIntrinsicHeight\":\"60\",\"framerSupportedLayoutHeight\":\"fixed\",\"framerIntrinsicWidth\":\"320\",\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./TextScrambler.map"],"mappings":"mMASG,SAAS,EAAc,EAAM,CAAC,GAAK,CAAC,OAAK,aAAa,WAAS,IAAI,OAAK,QAAM,gBAAc,iBAAe,EAAY,EAAS,GAAqB,EAAE,EAAa,SAAS,GAAG,EAAa,UAAe,CAAC,EAAQ,GAAYA,EAAe,EAAK,CAAM,CAAC,EAAK,GAASA,EAAe,GAAM,CAAO,EAAIC,GAAc,CAAO,EAAUA,GAAc,CAAO,EAASA,EAAa,EAAK,CAAO,EAAcA,EAAa,EAAE,CAAC,CAAslD,OAArlD,MAAoB,CAAC,GAAG,EAAS,CAAC,EAAW,EAAK,CAAC,EAAQ,GAAK,CAAC,OAAQ,EAAQ,GAAM,CA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