{"version":3,"file":"Type.649sqGL2.mjs","names":["useMemo","useState","useRef"],"sources":["https:/framerusercontent.com/modules/bEEkGQtWe5f0a8lIDYiw/L6MCrVeSX0HG39dhA6MU/Type.js"],"sourcesContent":["// Typewriter (H1 styling only). Types each item, clears, then types the next.\n// Use the single-line \"Copy\" field as your per-instance variant.\n// Choose how to split Copy into items via \"Split By\".\n// SSR safe for Framer Publish.\nimport{jsx as _jsx,jsxs as _jsxs}from\"react/jsx-runtime\";import{useEffect,useMemo,useRef,useState,startTransition}from\"react\";import{addPropertyControls,ControlType}from\"framer\";const tagOptions=[\"h1\",\"p\"];const tagTitles=[\"H1\",\"P\"];function getFontByTag(tag,h1Font){// Inherit by default. Only apply h1Font if provided.\nreturn h1Font||{};}export default function Typewriter(props){const{tag,copy,text,autoplay,loop,typingSpeed,pause,color,h1Font,cursor,cursorColor,splitBy,style}=props;const isBrowser=typeof window!==\"undefined\";// Build items from the one-line Copy, or fall back to text array if present\nconst lines=useMemo(()=>{const base=copy!=null?String(copy):Array.isArray(text)?text.join(\" \"):text!=null?String(text):\"\";const mode=splitBy??\",\";const delim=mode===\"newline\"?/\\r?\\n/:mode===\"space\"?/\\s+/:mode===\"|\"?/\\|/:mode===\"/\"?/\\//:/,/;return base.split(delim).map(s=>s.trim()).filter(Boolean);},[copy,text,splitBy]);const[displayed,setDisplayed]=useState(\"\");const[wordIndex,setWordIndex]=useState(0);const[charIndex,setCharIndex]=useState(0);const[isDone,setIsDone]=useState(!autoplay);const[showCursor,setShowCursor]=useState(true);const timerRef=useRef(null);const blinkRef=useRef(null);// Main typing loop\nuseEffect(()=>{if(!isBrowser)return;if(!autoplay||isDone)return;if(!lines.length){setIsDone(true);return;}if(timerRef.current){clearTimeout(timerRef.current);timerRef.current=null;}const current=lines[wordIndex]??\"\";// Still typing this item\nif(charIndex<current.length){timerRef.current=setTimeout(()=>{startTransition(()=>{setDisplayed(current.slice(0,charIndex+1));setCharIndex(charIndex+1);});},Math.max(0,Number(typingSpeed)||0));return;}// Finished this item\nconst isLast=wordIndex===lines.length-1;if(!loop&&isLast){setIsDone(true);return;}// Pause, then clear and move to next\ntimerRef.current=setTimeout(()=>{startTransition(()=>{const next=(wordIndex+1)%lines.length;setWordIndex(next);setCharIndex(0);setDisplayed(\"\");});},Math.max(0,Number(pause)||0)*1e3);return()=>{if(timerRef.current){clearTimeout(timerRef.current);timerRef.current=null;}};},[isBrowser,autoplay,isDone,lines,wordIndex,charIndex,typingSpeed,pause,loop]);// Reset when autoplay or copy changes\nuseEffect(()=>{if(!isBrowser)return;if(autoplay){startTransition(()=>{setDisplayed(\"\");setWordIndex(0);setCharIndex(0);setIsDone(false);});}else{startTransition(()=>{const first=lines[0]??\"\";setDisplayed(first);setWordIndex(0);setCharIndex(first.length);setIsDone(true);});}},[isBrowser,autoplay,lines]);// Cursor blink\nuseEffect(()=>{if(!isBrowser)return;if(blinkRef.current)clearInterval(blinkRef.current);blinkRef.current=setInterval(()=>setShowCursor(v=>!v),500);return()=>{if(blinkRef.current)clearInterval(blinkRef.current);blinkRef.current=null;};},[isBrowser]);// Variable for font styles\nconst fontStyles=useMemo(()=>{return{...getFontByTag(tag,h1Font),color};},[tag,h1Font,color]);const Tag=tag||\"h1\";const isFixedWidth=style&&style.width===\"100%\";return /*#__PURE__*/_jsx(\"div\",{style:{display:\"inline-block\",position:\"relative\",width:\"100%\",height:\"100%\"},children:/*#__PURE__*/_jsxs(Tag,{style:{...style,...fontStyles,minWidth:isFixedWidth?undefined:\"max-content\",margin:0,padding:0,display:\"inline-block\",whiteSpace:\"pre-wrap\"},children:[displayed,/*#__PURE__*/_jsx(\"span\",{style:{color:cursorColor,opacity:showCursor&&!isDone?1:0,fontWeight:fontStyles?.fontWeight,fontSize:fontStyles?.fontSize,fontFamily:fontStyles?.fontFamily,marginLeft:2,transition:\"opacity 0.2s\"},\"aria-hidden\":\"true\",children:cursor})]})});}// Framer controls\naddPropertyControls(Typewriter,{tag:{type:ControlType.Enum,title:\"Tag\",options:tagOptions,optionTitles:tagTitles,defaultValue:\"h1\",displaySegmentedControl:true},// Single-line copy field, acts as your per-instance variant\ncopy:{type:ControlType.String,title:\"Copy\",defaultValue:\"healing., hope., what’s next?\",displayTextArea:false,placeholder:\"word1, word2, word3\"},// How to split the Copy string into items\nsplitBy:{type:ControlType.Enum,title:\"Split By\",options:[\",\",\"|\",\"/\",\"space\",\"newline\"],optionTitles:[\",\",\"|\",\"/\",\"space\",\"newline\"],defaultValue:\",\",displaySegmentedControl:true},autoplay:{type:ControlType.Boolean,title:\"Autoplay\",defaultValue:true,enabledTitle:\"Yes\",disabledTitle:\"No\"},loop:{type:ControlType.Boolean,title:\"Loop\",defaultValue:true,enabledTitle:\"Yes\",disabledTitle:\"No\"},typingSpeed:{type:ControlType.Number,title:\"Typing Speed (ms)\",defaultValue:120,min:0,max:2e3,step:10},pause:{type:ControlType.Number,title:\"Pause After Item (s)\",defaultValue:1,min:0,max:10,step:.1},color:{type:ControlType.Color,title:\"Colour\",defaultValue:\"#fff\"},h1Font:{type:ControlType.Font,title:\"H1 Font\",controls:\"extended\",defaultFontType:\"sans-serif\",defaultValue:{fontSize:\"40px\",variant:\"Bold\",letterSpacing:\"-0.04em\",lineHeight:\"1em\"}},cursor:{type:ControlType.String,title:\"Cursor\",defaultValue:\"|\"},cursorColor:{type:ControlType.Color,title:\"Cursor\",defaultValue:\"#FF9900\"}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"Typewriter\",\"slots\":[],\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./Type.map"],"mappings":"2NAIyO,SAAS,EAAa,EAAI,EAAO,CAC1Q,OAAO,GAAQ,EAAE,CAAE,SAAwB,EAAW,EAAM,CAAC,GAAK,CAAC,MAAI,OAAK,OAAK,WAAS,OAAK,cAAY,QAAM,QAAM,SAAO,SAAO,cAAY,UAAQ,SAAO,EAAY,EAAiB,IAA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