{"version":3,"file":"TypewriterEffect.DFIJHb6Y.mjs","names":["useState","useRef","useMemo","_Fragment"],"sources":["https:/framerusercontent.com/modules/UzgWzncXGLdKPMyqtKHF/VOMYF9ZQmmJj5Eas6Hap/TypewriterEffect.js"],"sourcesContent":["// Dynamic Typing Animation Component with Customizable Cursor and Typography\nimport{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from\"react/jsx-runtime\";import{useState,useEffect,useRef,useMemo,startTransition}from\"react\";import{addPropertyControls,ControlType}from\"framer\";/**\n * Dynamic Typing Animation\n *\n * @framerSupportedLayoutWidth auto\n * @framerSupportedLayoutHeight auto\n */export default function TypewriterEffect(props){const{words=[{word:\"Hello\"},{word:\"World\"},{word:\"Framer\"}],loop,typingSpeed,deletingSpeed,pauseDuration,cursorColor,cursorWidth,cursorHeight,font,italicFont,textColor,style}=props;const isFixedWidth=!!(style&&style.width===\"100%\");const[displayed,setDisplayed]=useState(\"\");const[isDeleting,setIsDeleting]=useState(false);const[wordIndex,setWordIndex]=useState(0);const[charIndex,setCharIndex]=useState(0);const[pause,setPause]=useState(false);const[showCursor,setShowCursor]=useState(true);const timeoutRef=useRef(null);const blinkRef=useRef(null);const currentWord=words.length>0?words[wordIndex%words.length].word:\"\";const isLastWord=words.length>0?wordIndex%words.length===words.length-1:true;const currentItalic=words.length>0?!!words[wordIndex%words.length].italic:false;const currentItalicWord=words.length>0?words[wordIndex%words.length].italicWord:undefined;const renderDisplayed=useMemo(()=>{const fullItalic=currentItalic&&!currentItalicWord;if(fullItalic){return /*#__PURE__*/_jsx(\"span\",{style:{...italicFont},children:displayed});}const target=(currentItalicWord||\"\").trim();if(!target){return /*#__PURE__*/_jsx(\"span\",{children:displayed});}const escapeRegExp=s=>s.replace(/[.*+?^${}()|[\\\\]\\\\\\\\]/g,\"\\\\$&\");const full=currentWord;let matchIndex=-1;let matchLength=0;try{const re=new RegExp(`(^|\\\\s|[\\\\.,!?:;\\\\-()\\\\[\\\\]\"'])(${escapeRegExp(target)})(?=$|\\\\s|[\\\\.,!?:;\\\\-()\\\\[\\\\]\"'])`);const m=full.match(re);if(m&&typeof m.index===\"number\"){matchIndex=m.index+(m[1]?.length||0);matchLength=m[2]?.length||target.length;}}catch(e){// ignore\n}if(matchIndex<0){matchIndex=full.indexOf(target);matchLength=target.length;}if(matchIndex<0){return /*#__PURE__*/_jsx(\"span\",{children:displayed});}const displayedLen=displayed.length;const a0=0;const a1=Math.min(displayedLen,matchIndex);const b0=Math.min(displayedLen,matchIndex);const b1=Math.min(displayedLen,matchIndex+matchLength);const c0=Math.min(displayedLen,matchIndex+matchLength);const c1=displayedLen;const before=displayed.slice(a0,a1);const ital=displayed.slice(b0,b1);const after=displayed.slice(c0,c1);return /*#__PURE__*/_jsxs(_Fragment,{children:[before.length>0&&/*#__PURE__*/_jsx(\"span\",{children:before}),ital.length>0&&/*#__PURE__*/_jsx(\"span\",{style:{...italicFont},children:ital}),after.length>0&&/*#__PURE__*/_jsx(\"span\",{children:after})]});},[currentItalic,currentItalicWord,currentWord,displayed,italicFont]);// Typing/Deleting Effect\nuseEffect(()=>{if(typeof window===\"undefined\")return;if(pause)return;if(timeoutRef.current)clearTimeout(timeoutRef.current);let delay=typingSpeed;if(!isDeleting&&charIndex<currentWord.length){delay=typingSpeed;timeoutRef.current=window.setTimeout(()=>{startTransition(()=>{setDisplayed(currentWord.slice(0,charIndex+1));setCharIndex(charIndex+1);});},delay);}else if(!isDeleting&&charIndex===currentWord.length){if(!loop&&isLastWord){timeoutRef.current=window.setTimeout(()=>{startTransition(()=>setPause(true));},pauseDuration);return()=>{if(timeoutRef.current)clearTimeout(timeoutRef.current);};}// Pause at end of word\ntimeoutRef.current=window.setTimeout(()=>{startTransition(()=>setIsDeleting(true));},pauseDuration);}else if(isDeleting&&charIndex>0){delay=deletingSpeed;timeoutRef.current=window.setTimeout(()=>{startTransition(()=>{setDisplayed(currentWord.slice(0,charIndex-1));setCharIndex(charIndex-1);});},delay);}else if(isDeleting&&charIndex===0){// Pause before next word\ntimeoutRef.current=window.setTimeout(()=>{startTransition(()=>{setIsDeleting(false);setWordIndex((wordIndex+1)%words.length);});},pauseDuration);}return()=>{if(timeoutRef.current)clearTimeout(timeoutRef.current);};},[charIndex,isDeleting,pause,wordIndex,currentWord,isLastWord,loop,typingSpeed,deletingSpeed,pauseDuration,words.length]);// Reset charIndex when wordIndex changes\nuseEffect(()=>{if(!isDeleting){startTransition(()=>setCharIndex(0));}},[wordIndex,isDeleting]);// Blinking Cursor Effect\nuseEffect(()=>{if(typeof window===\"undefined\")return;if(blinkRef.current)clearInterval(blinkRef.current);blinkRef.current=window.setInterval(()=>{startTransition(()=>setShowCursor(v=>!v));},500);return()=>{if(blinkRef.current)clearInterval(blinkRef.current);};},[]);// Font size for cursor height calculation\nconst fontSize=useMemo(()=>{if(font&&font.fontSize){if(typeof font.fontSize===\"string\"&&font.fontSize.endsWith(\"px\")){return parseFloat(font.fontSize);}else if(typeof font.fontSize===\"number\"){return font.fontSize;}}return 32;},[font]);return /*#__PURE__*/_jsxs(\"span\",{style:{...style,...font,color:textColor,display:\"inline-block\",minWidth:1,minHeight:1,width:isFixedWidth?\"100%\":\"max-content\",whiteSpace:\"pre-wrap\",overflowWrap:\"anywhere\"},\"aria-live\":\"polite\",children:[/*#__PURE__*/_jsx(\"span\",{style:{display:\"inline\"},children:renderDisplayed}),/*#__PURE__*/_jsx(\"span\",{\"aria-hidden\":\"true\",style:{display:\"inline-block\",background:cursorColor,width:cursorWidth,height:fontSize*(cursorHeight/100),marginLeft:2,marginRight:2,verticalAlign:\"bottom\",opacity:showCursor?1:0,transition:\"opacity 0.1s\",borderRadius:2}})]});}addPropertyControls(TypewriterEffect,{loop:{type:ControlType.Boolean,title:\"Loop\",defaultValue:true,enabledTitle:\"Yes\",disabledTitle:\"No\"},words:{type:ControlType.Array,title:\"Words\",control:{type:ControlType.Object,controls:{word:{type:ControlType.String,defaultValue:\"Hello\"},italic:{type:ControlType.Boolean,defaultValue:false},italicWord:{type:ControlType.String,title:\"Italic Word\",defaultValue:\"\",placeholder:\"with\"}}},defaultValue:[{word:\"Hello\"},{word:\"World\"},{word:\"Framer\"}],maxCount:10},typingSpeed:{type:ControlType.Number,title:\"Typing Speed\",defaultValue:100,min:20,max:500,unit:\"ms\",step:5},deletingSpeed:{type:ControlType.Number,title:\"Deleting Speed\",defaultValue:60,min:10,max:500,unit:\"ms\",step:5},pauseDuration:{type:ControlType.Number,title:\"Pause Duration\",defaultValue:1e3,min:200,max:3e3,unit:\"ms\",step:50},cursorColor:{type:ControlType.Color,title:\"Cursor Color\",defaultValue:\"#FFFFFF\"},cursorWidth:{type:ControlType.Number,title:\"Cursor Width\",defaultValue:2,min:1,max:8,unit:\"px\",step:1},cursorHeight:{type:ControlType.Number,title:\"Cursor Height\",defaultValue:100,min:50,max:120,unit:\"%\",step:1},font:{type:ControlType.Font,title:\"Font\",controls:\"extended\",defaultFontType:\"sans-serif\",defaultValue:{fontSize:\"32px\",variant:\"Bold\",letterSpacing:\"-0.01em\",lineHeight:\"1.2em\"}},italicFont:{type:ControlType.Font,title:\"Italic Font\",controls:\"extended\",defaultFontType:\"sans-serif\",defaultValue:{fontSize:\"32px\",variant:\"Bold Italic\",letterSpacing:\"-0.01em\",lineHeight:\"1.2em\"}},textColor:{type:ControlType.Color,title:\"Text Color\",defaultValue:\"#FFFFFF\"}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"TypewriterEffect\",\"slots\":[],\"annotations\":{\"framerSupportedLayoutHeight\":\"auto\",\"framerSupportedLayoutWidth\":\"auto\",\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./TypewriterEffect.map"],"mappings":"kOAMG,SAAwB,EAAiB,EAAM,CAAC,GAAK,CAAC,QAAM,CAAC,CAAC,KAAK,OAAO,EAAE,CAAC,KAAK,OAAO,EAAE,CAAC,KAAK,QAAQ,CAAC,EAAE,OAAK,cAAY,gBA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