{"version":3,"file":"TextRotate.Ps1OZIkL.mjs","names":["useState","useMemo","useCallback"],"sources":["https:/framerusercontent.com/modules/1A4Z1knWIRCgiEHT0qIn/8KLdkrrBQr3MpUOujVNK/TextRotate.js"],"sourcesContent":["// Get Started: https://www.framer.com/developers\nimport{jsx as _jsx,jsxs as _jsxs}from\"react/jsx-runtime\";import{addPropertyControls,ControlType}from\"framer\";import{motion,AnimatePresence}from\"framer-motion\";import{forwardRef,useCallback,useEffect,useImperativeHandle,useMemo,useState}from\"react\";// Helper function to split text into characters with support for unicode and emojis\nconst splitIntoCharacters=text=>{if(typeof Intl!==\"undefined\"&&\"Segmenter\"in Intl){const segmenter=new Intl.Segmenter(\"en\",{granularity:\"grapheme\"});return Array.from(segmenter.segment(text),({segment})=>segment);}return Array.from(text);};// TextRotate component\nconst TextRotate=/*#__PURE__*/forwardRef(({texts,transition={type:\"spring\",damping:25,stiffness:300},initial={y:\"100%\",opacity:0},animate={y:0,opacity:1},exit={y:\"-120%\",opacity:0},rotationInterval=2e3,staggerDuration=0,staggerFrom=\"first\",loop=true,auto=true,splitBy=\"characters\",onNext,mainClassName,splitLevelClassName,elementLevelClassName,...props},ref)=>{const[currentTextIndex,setCurrentTextIndex]=useState(0);const elements=useMemo(()=>{const currentText=texts[currentTextIndex];if(!currentText)return[];if(splitBy===\"characters\"){const words=currentText.split(\" \");return words.map((word,i)=>({characters:splitIntoCharacters(word),needsSpace:i!==words.length-1}));}// Handle words, lines, or custom split\nconst parts=splitBy===\"words\"?currentText.split(\" \"):splitBy===\"lines\"?currentText.split(\"\\n\"):currentText.split(splitBy);return parts.map((part,i)=>({characters:[part],needsSpace:i!==parts.length-1}));},[texts,currentTextIndex,splitBy]);const getStaggerDelay=useCallback((index,totalChars)=>{const total=totalChars;if(staggerFrom===\"first\")return index*staggerDuration;if(staggerFrom===\"last\")return(total-1-index)*staggerDuration;if(staggerFrom===\"center\"){const center=Math.floor(total/2);return Math.abs(center-index)*staggerDuration;}if(staggerFrom===\"random\"){const randomIndex=Math.floor(Math.random()*total);return Math.abs(randomIndex-index)*staggerDuration;}return Math.abs(Number(staggerFrom)-index)*staggerDuration;},[staggerFrom,staggerDuration]);const handleIndexChange=useCallback(newIndex=>{setCurrentTextIndex(newIndex);onNext?.(newIndex);},[onNext]);const next=useCallback(()=>{const nextIndex=currentTextIndex===texts.length-1?loop?0:currentTextIndex:currentTextIndex+1;if(nextIndex!==currentTextIndex){handleIndexChange(nextIndex);}},[currentTextIndex,texts.length,loop,handleIndexChange]);const previous=useCallback(()=>{const prevIndex=currentTextIndex===0?loop?texts.length-1:currentTextIndex:currentTextIndex-1;if(prevIndex!==currentTextIndex){handleIndexChange(prevIndex);}},[currentTextIndex,texts.length,loop,handleIndexChange]);const jumpTo=useCallback(index=>{const validIndex=Math.max(0,Math.min(index,texts.length-1));if(validIndex!==currentTextIndex){handleIndexChange(validIndex);}},[texts.length,currentTextIndex,handleIndexChange]);const reset=useCallback(()=>{if(currentTextIndex!==0){handleIndexChange(0);}},[currentTextIndex,handleIndexChange]);useImperativeHandle(ref,()=>({next,previous,jumpTo,reset}),[next,previous,jumpTo,reset]);useEffect(()=>{if(!auto)return;const intervalId=setInterval(next,rotationInterval);return()=>clearInterval(intervalId);},[next,rotationInterval,auto]);return /*#__PURE__*/_jsxs(motion.span,{style:{display:\"flex\",flexWrap:\"wrap\",whiteSpace:\"pre-wrap\",...mainClassName},...props,layout:true,transition:transition,children:[/*#__PURE__*/_jsx(\"span\",{style:{position:\"absolute\",left:\"-10000px\",width:\"1px\",height:\"1px\",overflow:\"hidden\"},children:texts[currentTextIndex]}),/*#__PURE__*/_jsx(AnimatePresence,{mode:\"wait\",initial:false,children:/*#__PURE__*/_jsx(motion.span,{style:{display:\"flex\",flexWrap:\"wrap\",...splitBy===\"lines\"&&{flexDirection:\"column\",width:\"100%\"}},layout:true,\"aria-hidden\":\"true\",children:elements.map((wordObj,wordIndex,array)=>{const previousCharsCount=array.slice(0,wordIndex).reduce((sum,word)=>sum+word.characters.length,0);return /*#__PURE__*/_jsxs(\"span\",{style:{display:\"inline-flex\",...splitLevelClassName},children:[wordObj.characters.map((char,charIndex)=>/*#__PURE__*/_jsx(motion.span,{initial:initial,animate:animate,exit:exit,transition:{...transition,delay:getStaggerDelay(previousCharsCount+charIndex,array.reduce((sum,word)=>sum+word.characters.length,0))},style:{display:\"inline-block\",...elementLevelClassName},children:char},charIndex)),wordObj.needsSpace&&/*#__PURE__*/_jsx(\"span\",{style:{whiteSpace:\"pre\"},children:\" \"})]},wordIndex);})},currentTextIndex)})]});});export default function TextRotatePreview(props){const{prefixText,texts,font,textColor,backgroundColor,highlightColor,rotationInterval,staggerDuration,staggerFrom,borderRadius,padding}=props;const mainStyle={color:highlightColor,backgroundColor:backgroundColor,padding:`${padding}px`,borderRadius:`${borderRadius}px`,overflow:\"hidden\",display:\"flex\",justifyContent:\"center\",alignItems:\"center\"};const splitLevelStyle={overflow:\"hidden\",paddingBottom:\"2px\"};return /*#__PURE__*/_jsx(\"div\",{style:{...font,width:\"100%\",height:\"100%\",color:textColor,display:\"flex\",flexDirection:\"row\",alignItems:\"center\",justifyContent:\"center\",overflow:\"hidden\",padding:\"24px\"},children:/*#__PURE__*/_jsxs(motion.p,{style:{display:\"flex\",whiteSpace:\"pre\",alignItems:\"baseline\"},layout:true,children:[/*#__PURE__*/_jsxs(motion.span,{style:{paddingTop:\"4px\"},layout:true,transition:{type:\"spring\",damping:30,stiffness:400},children:[prefixText,\" \"]}),/*#__PURE__*/_jsx(TextRotate,{texts:texts,mainClassName:mainStyle,staggerFrom:staggerFrom,initial:{y:\"100%\"},animate:{y:0},exit:{y:\"-120%\"},staggerDuration:staggerDuration,splitLevelClassName:splitLevelStyle,transition:{type:\"spring\",damping:30,stiffness:400},rotationInterval:rotationInterval})]})});}addPropertyControls(TextRotatePreview,{prefixText:{title:\"Prefix Text\",type:ControlType.String,defaultValue:\"Make it\"},texts:{title:\"Rotating Texts\",type:ControlType.Array,propertyControl:{type:ControlType.String,defaultValue:\"Text\"},defaultValue:[\"work!\",\"fancy ✽\",\"right\",\"fast\",\"fun\",\"rock\",\"🕶️🕶️🕶️\"]},font:{type:ControlType.Font,controls:\"extended\",displayFontSize:true,displayTextAlignment:true,defaultFontType:\"sans-serif\",defaultValue:{fontSize:48,letterSpacing:.1,lineHeight:\"1\"}},textColor:{title:\"Text Color\",type:ControlType.Color,defaultValue:\"#000000\"},highlightColor:{title:\"Highlight Text Color\",type:ControlType.Color,defaultValue:\"#ffffff\"},backgroundColor:{title:\"Highlight Background\",type:ControlType.Color,defaultValue:\"#ff5941\"},borderRadius:{title:\"Border Radius\",type:ControlType.Number,defaultValue:8,min:0,max:50,step:1,unit:\"px\"},padding:{title:\"Highlight Padding\",type:ControlType.Number,defaultValue:8,min:2,max:30,step:1,unit:\"px\"},rotationInterval:{title:\"Rotation Interval\",type:ControlType.Number,defaultValue:2e3,min:500,max:1e4,step:100,unit:\"ms\"},staggerDuration:{title:\"Stagger Duration\",type:ControlType.Number,defaultValue:.025,min:0,max:.2,step:.005,unit:\"s\"},staggerFrom:{title:\"Stagger From\",type:ControlType.Enum,options:[\"first\",\"last\",\"center\",\"random\"],optionTitles:[\"First\",\"Last\",\"Center\",\"Random\"],defaultValue:\"last\"}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"TextRotatePreview\",\"slots\":[],\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./TextRotate.map"],"mappings":"4QAI4mG,SAAwB,EAAkB,EAAM,CAAC,GAAK,CAAC,aAAW,QAAM,OAAK,YAAU,kBAAgB,iBAAe,mBAAiB,kBAAgB,cAAY,eAAa,WAAS,EAAY,EAAU,CAAC,MAAM,EAA+B,kBAAgB,QAAQ,GAAG,EAAQ,IAAI,aAAa,GAAG,EAAa,IAAI,SAAS,SAAS,QAAQ,OAAO,eAAe,SAAS,WAAW,SAAS,CAAO,EAAgB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