{"version":3,"file":"GlitchText.5BUtKBpu.mjs","names":["useState","useRef","useMemo"],"sources":["https:/framerusercontent.com/modules/uKBwpebjo9Xm0WYtm9az/KIGe3GLZojMvcL7jtSvd/GlitchText.js"],"sourcesContent":["// Glitch text component that triggers animation when in view with configurable properties\nimport{jsx as _jsx}from\"react/jsx-runtime\";import{useEffect,useState,useRef,useMemo,startTransition}from\"react\";import{addPropertyControls,ControlType,RenderTarget}from\"framer\";import{useInView}from\"framer-motion\";/**\n * Scramble Text Component\n *\n * A text component that scrambles characters when it comes into view.\n * @framerSupportedLayoutWidth auto\n * @framerSupportedLayoutHeight auto\n * @framerDisableUnlink\n */export default function GlitchText(props){const{text=\"Title\",font,textTransform=\"inherit\",tag=\"span\",color=\"#000000\",scrambledColor=\"#CCFF00\",chars=\"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()_+-=[]{}|;:,.<>?\",scramblePercent=30,speed=50,duration=1e3,enableInView=true,trigger=false}=props;const[displayText,setDisplayText]=useState(text.split(\"\"));const[revealedIndices,setRevealedIndices]=useState(new Set);const[scramblingIndices,setScramblingIndices]=useState(new Set);const ref=useRef(null);const isInView=useInView(ref,{once:true,amount:.5});const animationRef=useRef(null);const hasAnimated=useRef(false);const prevTrigger=useRef(trigger);// Reset animation state when text changes\nuseEffect(()=>{hasAnimated.current=false;setDisplayText(text.split(\"\"));setRevealedIndices(new Set);},[text]);// Reset animation when trigger changes (for manual triggering)\nuseEffect(()=>{if(!enableInView){if(trigger!==prevTrigger.current){prevTrigger.current=trigger;hasAnimated.current=false;setDisplayText(text.split(\"\"));setRevealedIndices(new Set);setScramblingIndices(new Set);}else if(!trigger){// When trigger is false, show original text\nsetDisplayText(text.split(\"\"));setRevealedIndices(new Set(text.split(\"\").map((_,i)=>i)));setScramblingIndices(new Set);}}},[trigger,enableInView,text]);useEffect(()=>{const shouldAnimate=enableInView?isInView:trigger;if(!shouldAnimate)return;// Don't animate on canvas\nif(RenderTarget.current()===RenderTarget.canvas){// Show final state on canvas\nsetDisplayText(text.split(\"\"));setRevealedIndices(new Set(text.split(\"\").map((_,i)=>i)));setScramblingIndices(new Set);return;}// For manual triggering, allow re-animation\nif(!enableInView){hasAnimated.current=false;}if(hasAnimated.current)return;hasAnimated.current=true;const textArray=text.split(\"\");const totalChars=textArray.length;// Different animation logic based on mode\nif(!enableInView){// Simple scramble mode for trigger - scramble letters randomly\nconst totalAnimationTime=duration*1.5// Total time for the glitch effect\n;const maxSimultaneous=3+Math.floor(Math.random()*2)// 3-4 letters at once\n;// Create waves of scrambling\nconst numWaves=Math.ceil(textArray.length/maxSimultaneous)*2// Multiple passes\n;const waveInterval=totalAnimationTime/numWaves;const letterTimings=textArray.map((_,index)=>{// Assign each letter to random waves\nconst numScrambles=2+Math.floor(Math.random()*2)// Each letter scrambles 2-3 times\n;const scrambles=[];for(let i=0;i<numScrambles;i++){const waveIndex=Math.floor(Math.random()*numWaves);const startTime=waveIndex*waveInterval+Math.random()*waveInterval*.3;const scrambleDuration=150+Math.random()*150// 150-300ms per scramble\n;scrambles.push({startTime,endTime:startTime+scrambleDuration});}return scrambles;});// Calculate the maximum end time to know when animation is complete\nconst maxEndTime=Math.max(...letterTimings.flat().map(t=>t.endTime));const totalFrames=Math.ceil(maxEndTime/speed);let currentFrame=0;const animate=()=>{if(currentFrame>=totalFrames){startTransition(()=>{setDisplayText(textArray);setRevealedIndices(new Set(textArray.map((_,i)=>i)));setScramblingIndices(new Set);});return;}const currentTime=currentFrame*speed;const newDisplayText=textArray.map((char,index)=>{if(char===\" \")return\" \";const scrambles=letterTimings[index];const isCurrentlyScrambling=scrambles.some(s=>currentTime>=s.startTime&&currentTime<s.endTime);if(isCurrentlyScrambling){return chars[Math.floor(Math.random()*chars.length)];}else{return char;}});const newRevealedIndices=new Set;const newScramblingIndices=new Set;textArray.forEach((_,index)=>{const scrambles=letterTimings[index];const isCurrentlyScrambling=scrambles.some(s=>currentTime>=s.startTime&&currentTime<s.endTime);const allFinished=scrambles.every(s=>currentTime>=s.endTime);if(allFinished){newRevealedIndices.add(index);}else if(isCurrentlyScrambling){newScramblingIndices.add(index);}});startTransition(()=>{setDisplayText(newDisplayText);setRevealedIndices(newRevealedIndices);setScramblingIndices(newScramblingIndices);});currentFrame++;animationRef.current=window.setTimeout(animate,speed/2);};animate();}else{// Reveal mode for in-view\nconst scrambleDuration=Math.ceil(duration*(scramblePercent/100));const revealInterval=duration/totalChars;const totalFrames=Math.ceil(duration/speed);let currentFrame=0;const animate=()=>{if(currentFrame>=totalFrames){startTransition(()=>{setDisplayText(textArray);setRevealedIndices(new Set(textArray.map((_,i)=>i)));});return;}const currentTime=currentFrame*speed;const newDisplayText=[...textArray];const newRevealedIndices=new Set;textArray.forEach((char,index)=>{const charStartTime=index*revealInterval;const charEndTime=charStartTime+scrambleDuration;if(currentTime<charStartTime){// Not started yet\nnewDisplayText[index]=\"\";}else if(currentTime>=charStartTime&&currentTime<charEndTime){// Scrambling phase\nif(char===\" \"){newDisplayText[index]=\" \";}else{newDisplayText[index]=chars[Math.floor(Math.random()*chars.length)];}}else{// Revealed\nnewDisplayText[index]=char;newRevealedIndices.add(index);}});startTransition(()=>{setDisplayText(newDisplayText);setRevealedIndices(newRevealedIndices);});currentFrame++;animationRef.current=window.setTimeout(animate,speed/3);};animate();}return()=>{if(animationRef.current!==null){clearTimeout(animationRef.current);animationRef.current=null;}};},[isInView,text,chars,scramblePercent,speed,duration,enableInView,trigger]);const renderText=useMemo(()=>{return displayText.map((char,index)=>{const isRevealed=revealedIndices.has(index);const isScrambling=scramblingIndices.has(index);// Determine color based on state\nlet textColor=color;if(enableInView){// In reveal mode, use scrambled color only if not revealed yet and animation has started\nif(!isRevealed&&hasAnimated.current){textColor=scrambledColor;}}else{// In trigger mode, use scrambled color only when actively scrambling\nif(isScrambling){textColor=scrambledColor;}}return /*#__PURE__*/_jsx(\"span\",{style:{color:textColor,transition:\"color 0.1s ease\"},children:char},index);});},[displayText,revealedIndices,scramblingIndices,color,scrambledColor,enableInView]);const Tag=tag;return /*#__PURE__*/_jsx(\"div\",{ref:ref,style:{position:\"relative\",width:\"max-content\",minWidth:\"max-content\",minHeight:5},children:/*#__PURE__*/_jsx(Tag,{style:{...font,textTransform,display:\"block\",whiteSpace:\"pre\",margin:0,padding:0},children:renderText})});}addPropertyControls(GlitchText,{text:{type:ControlType.String,title:\"Text\",defaultValue:\"Title\"},font:{type:ControlType.Font,title:\"Font\",controls:\"extended\",defaultFontType:\"sans-serif\",defaultValue:{fontSize:\"40px\",variant:\"Bold\",letterSpacing:\"-0.04em\",lineHeight:\"1em\"}},textTransform:{type:ControlType.Enum,title:\"Transform\",options:[\"inherit\",\"lowercase\",\"uppercase\",\"capitalize\"],optionTitles:[\"Inherit\",\"Lowercase\",\"Uppercase\",\"Capitalize\"],defaultValue:\"inherit\",displaySegmentedControl:true},tag:{type:ControlType.Enum,title:\"Tag\",options:[\"h1\",\"h2\",\"h3\",\"h4\",\"h5\",\"h6\",\"p\",\"span\",\"div\"],optionTitles:[\"H1\",\"H2\",\"H3\",\"H4\",\"H5\",\"H6\",\"P\",\"Span\",\"Div\"],defaultValue:\"span\"},color:{type:ControlType.Color,title:\"Color\",defaultValue:\"#000000\"},scrambledColor:{type:ControlType.Color,title:\"Scrambled\",defaultValue:\"#CCFF00\"},chars:{type:ControlType.String,title:\"Chars\",defaultValue:\"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()_+-=[]{}|;:,.<>?\",displayTextArea:true},scramblePercent:{type:ControlType.Number,title:\"Scramble %\",defaultValue:30,min:0,max:100,step:1,unit:\"%\"},speed:{type:ControlType.Number,title:\"Speed\",defaultValue:50,min:10,max:200,step:10,unit:\"ms\"},duration:{type:ControlType.Number,title:\"Duration\",defaultValue:1e3,min:100,max:5e3,step:100,unit:\"ms\"},enableInView:{type:ControlType.Boolean,title:\"In View\",defaultValue:true,enabledTitle:\"On\",disabledTitle:\"Off\",description:\"Component made by [Joseph Alexander](https://launchnow.design/?utm_source=codecomponent)\"},trigger:{type:ControlType.Boolean,title:\"Trigger\",defaultValue:false,enabledTitle:\"Yes\",disabledTitle:\"No\",hidden:({enableInView})=>enableInView}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"GlitchText\",\"slots\":[],\"annotations\":{\"framerDisableUnlink\":\"\",\"framerSupportedLayoutHeight\":\"auto\",\"framerContractVersion\":\"1\",\"framerSupportedLayoutWidth\":\"auto\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./GlitchText.map"],"mappings":"6QAQG,SAAwB,EAAW,EAAM,CAAC,GAAK,CAAC,OAAK,QAAQ,OAAK,gBAAc,UAAU,MAAI,OAAO,QAAM,UAAU,iBAAe,UAAU,QAAM,2FAA2F,kBAAgB,GAAG,QAAM,GAAG,WAAS,IAAI,eAAa,GAAK,UAAQ,IAAO,EAAW,CAAC,EAAY,GAAgBA,EAAS,EAAK,MAAM,GAAG,CAAC,CAAM,CAAC,EAAgB,GAAoBA,EAAS,IAAI,IAAI,CAAM,CAAC,EAAkB,GAAsBA,EAAS,IAAI,IAAI,CAAO,EAAIC,EAAO,KAAK,CAAO,EAAS,EAAU,EAAI,CAAC,KAAK,GAAK,OAAO,GAAG,CAAC,CAAO,EAAaA,EAAO,KAAK,CAAO,EAAYA,EAAO,GAAM,CAAO,EAAYA,EAAO,EAAQ,CACrqB,MAAc,CAAC,EAAY,QAAQ,GAAM,EAAe,EAAK,MAAM,GAAG,CAAC,CAAC,EAAmB,IAAI,IAAI,EAAG,CAAC,EAAK,CAAC,CAC7G,MAAc,CAAK,IAAiB,IAAU,EAAY,QAAkK,IAC5N,EAAe,EAAK,MAAM,GAAG,CAAC,CAAC,EAAmB,IAAI,IAAI,EAAK,MAAM,GAAG,CAAC,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAqB,IAAI,IAAI,GADnD,EAA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