{"version":3,"file":"TextScrambler.C4dtEFHT.mjs","names":["useState","useRef"],"sources":["https:/framerusercontent.com/modules/rYy98HgXMqG5J8XkNd91/OaceHfBz7HwMrJVTONJZ/TextScrambler.js"],"sourcesContent":["// Lightweight text scrambler with matrix-style decrypt effect\n// Animates on appear and hover with character-by-character reveal\nimport{jsx as _jsx}from\"react/jsx-runtime\";import{useEffect,useRef,useState,startTransition}from\"react\";import{addPropertyControls,ControlType,useInView}from\"framer\";const CHARS=\"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*\";/**\n * Text Scrambler\n *\n * @framerIntrinsicWidth 300\n * @framerIntrinsicHeight 50\n *\n * @framerSupportedLayoutWidth auto\n * @framerSupportedLayoutHeight auto\n */export default function TextScrambler(props){const{text=\"DECRYPT\",font,color,scrambleSpeed=50,animateOnHover=true,animation={trigger:\"inView\",repeat:false,repeatDelay:2,delay:0,direction:\"leftToRight\"}}=props;const[displayText,setDisplayText]=useState(\" \".repeat(text.length));const[isAnimating,setIsAnimating]=useState(false);const ref=useRef(null);const isInView=useInView(ref,{once:animation.trigger===\"inView\"&&!animation.repeat,amount:.5});const animationRef=useRef(null);const hasAnimatedRef=useRef(false);const repeatTimeoutRef=useRef(null);const duration=600;const scramble=()=>{if(isAnimating)return;startTransition(()=>setIsAnimating(true));const chars=text.split(\"\");const resolved=new Array(chars.length).fill(false);const startTime=Date.now();// Calculate frame interval based on scramble speed percentage\n// Higher percentage = more scrambles = shorter interval between updates\nconst frameInterval=Math.max(16,duration/(chars.length*(scrambleSpeed/10)));let lastFrameTime=startTime;// Create resolve order based on direction\nlet resolveOrder;if(animation.direction===\"leftToRight\"){resolveOrder=chars.map((_,i)=>i);}else if(animation.direction===\"rightToLeft\"){resolveOrder=chars.map((_,i)=>chars.length-1-i);}else{// Random order\nresolveOrder=chars.map((_,i)=>i).sort(()=>Math.random()-.5);}const animate=()=>{const now=Date.now();const elapsed=now-startTime;const progress=Math.min(elapsed/duration,1);// Only update if enough time has passed (throttle based on scramble speed)\nif(now-lastFrameTime<frameInterval&&progress<1){animationRef.current=requestAnimationFrame(animate);return;}lastFrameTime=now;// Determine which characters should be resolved based on progress\nconst resolveCount=Math.floor(progress*chars.length);const newText=chars.map((char,i)=>{// If already resolved, keep the original character\nif(resolved[i])return char;// Check if this character should be resolved based on the order\nconst orderIndex=resolveOrder.indexOf(i);if(orderIndex<resolveCount){resolved[i]=true;return char;}// Keep spaces as spaces\nif(char===\" \")return\" \";// Otherwise, show random scrambled character\nreturn CHARS[Math.floor(Math.random()*CHARS.length)];}).join(\"\");startTransition(()=>setDisplayText(newText));if(progress<1){animationRef.current=requestAnimationFrame(animate);}else{startTransition(()=>{setDisplayText(text);setIsAnimating(false);});animationRef.current=null;}};animationRef.current=requestAnimationFrame(animate);};// Animate on appear or in view\nuseEffect(()=>{// Only animate on hover if animateOnHover is true and trigger is not hoverOnly\nif(animation.trigger===\"hoverOnly\"){// Always show the text so user knows where to hover\nif(displayText!==text){startTransition(()=>setDisplayText(text));}return;}const shouldAnimate=animation.trigger===\"onAppear\"||animation.trigger===\"inView\"&&isInView;if(shouldAnimate&&!hasAnimatedRef.current){hasAnimatedRef.current=true;const timer=setTimeout(()=>{scramble();// Set up repeat if enabled\nif(animation.repeat){const scheduleRepeat=()=>{repeatTimeoutRef.current=window.setTimeout(()=>{scramble();scheduleRepeat();},duration+animation.repeatDelay*1e3);};scheduleRepeat();}},animation.delay*1e3);return()=>{clearTimeout(timer);if(repeatTimeoutRef.current){clearTimeout(repeatTimeoutRef.current);}};}},[isInView,animation.trigger,animation.repeat,animation.repeatDelay,duration]);// Update displayText when text prop changes\nuseEffect(()=>{if(!isAnimating){startTransition(()=>setDisplayText(\" \".repeat(text.length)));}hasAnimatedRef.current=false;},[text]);// Cleanup animation on unmount\nuseEffect(()=>{return()=>{if(animationRef.current){cancelAnimationFrame(animationRef.current);}if(repeatTimeoutRef.current){clearTimeout(repeatTimeoutRef.current);}};},[]);const handleMouseEnter=()=>{if(!animateOnHover)return;// Clear any ongoing repeat animation\nif(repeatTimeoutRef.current){clearTimeout(repeatTimeoutRef.current);repeatTimeoutRef.current=null;}if(animationRef.current){cancelAnimationFrame(animationRef.current);animationRef.current=null;}startTransition(()=>{setIsAnimating(false);setDisplayText(text);});setTimeout(()=>{scramble();// Restart repeat cycle after hover animation if repeat is enabled\nif(animation.repeat){const scheduleRepeat=()=>{repeatTimeoutRef.current=window.setTimeout(()=>{scramble();scheduleRepeat();},duration+animation.repeatDelay*1e3);};scheduleRepeat();}},50);};// Check for reduced motion preference\nconst prefersReducedMotion=typeof window!==\"undefined\"&&window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;return /*#__PURE__*/_jsx(\"div\",{ref:ref,onMouseEnter:handleMouseEnter,style:{...props.style,position:\"relative\",display:\"inline-block\",width:\"max-content\",color,cursor:animateOnHover?\"pointer\":\"default\",userSelect:\"none\",...font},children:/*#__PURE__*/_jsx(\"span\",{style:{display:\"inline-block\",whiteSpace:\"pre\"},children:prefersReducedMotion?text:displayText})});}addPropertyControls(TextScrambler,{text:{type:ControlType.String,title:\"Text\",defaultValue:\"DECRYPT\"},font:{type:ControlType.Font,title:\"Font\",controls:\"extended\",defaultFontType:\"sans-serif\",defaultValue:{fontSize:\"32px\",variant:\"Bold\",letterSpacing:\"0.05em\",lineHeight:\"1em\"}},color:{type:ControlType.Color,title:\"Color\",defaultValue:\"#000000\"},scrambleSpeed:{type:ControlType.Number,title:\"Scramble Speed\",defaultValue:50,min:10,max:100,step:5,unit:\"%\"},animateOnHover:{type:ControlType.Boolean,title:\"Animate on Hover\",defaultValue:true,enabledTitle:\"On\",disabledTitle:\"Off\"},animation:{type:ControlType.Object,title:\"Animation\",controls:{trigger:{type:ControlType.Enum,title:\"Trigger\",options:[\"inView\",\"onAppear\",\"hoverOnly\"],optionTitles:[\"In View\",\"On Appear\",\"On Hover Only\"],defaultValue:\"inView\"},direction:{type:ControlType.Enum,title:\"Direction\",options:[\"leftToRight\",\"rightToLeft\",\"random\"],optionTitles:[\"Left to Right\",\"Right to Left\",\"Random\"],defaultValue:\"leftToRight\"},repeat:{type:ControlType.Boolean,title:\"Repeat\",defaultValue:false,enabledTitle:\"On\",disabledTitle:\"Off\"},repeatDelay:{type:ControlType.Number,title:\"Repeat Delay\",defaultValue:2,min:.1,max:10,step:.1,unit:\"s\"},delay:{type:ControlType.Number,title:\"Delay\",defaultValue:0,min:0,max:10,step:.1,unit:\"s\"}}}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"TextScrambler\",\"slots\":[],\"annotations\":{\"framerSupportedLayoutHeight\":\"auto\",\"framerSupportedLayoutWidth\":\"auto\",\"framerIntrinsicWidth\":\"300\",\"framerContractVersion\":\"1\",\"framerIntrinsicHeight\":\"50\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./TextScrambler.map"],"mappings":"uPAUG,SAAwB,EAAc,EAAM,CAAC,GAAK,CAAC,OAAK,UAAU,OAAK,QAAM,gBAAc,GAAG,iBAAe,GAAK,YAAU,CAAC,QAAQ,SAAS,OAAO,GAAM,YAAY,EAAE,MAAM,EAAE,UAAU,aAAa,GAAG,EAAW,CAAC,EAAY,GAAgBA,EAAS,IAAI,OAAO,EAAK,MAAM,CAAC,EAAO,CAAC,EAAY,GAAgBA,EAAS,EAAK,EAAQ,EAAIC,EAAO,IAAI,EAAQ,EAAS,EAAU,EAAI,CAAC,KAAK,EAAU,UAAU,UAAU,CAAC,EAAU,OAAO,OAAO,EAAE,CAAC,EAAQ,EAAaA,EAAO,IAAI,EAAQ,EAAeA,EAAO,EAAK,EAAQ,EAAiBA,EAAO,IAAI,EAA2B,MAAa,CAAC,GAAG,EAAY,OAAO,MAAoB,EAAe,EAAI,CAAC,EAAE,IAAM,EAAM,EAAK,MAAM,EAAE,EAAQ,EAAa,MAAM,EAAM,MAAM,CAAC,CAAC,KAAK,EAAK,EAAQ,EAAU,KAAK,IAAI,EAE/uB,EAA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