{"version":3,"file":"ScrollColorChangeText.Bdlss00d.mjs","names":["useRef","useState"],"sources":["https:/framerusercontent.com/modules/m0MbHsD9QsTEqMt2ksX0/v8a9loiWFIuw5lGUOT2b/ScrollColorChangeText.js"],"sourcesContent":["// Text opacity letters component that changes color on scroll\nimport{jsx as _jsx,jsxs as _jsxs}from\"react/jsx-runtime\";import{useScroll,useTransform,motion}from\"framer-motion\";import{useRef,useState,useEffect,startTransition}from\"react\";import{addPropertyControls,ControlType}from\"framer\";/**\n * @framerSupportedLayoutWidth any\n * @framerSupportedLayoutHeight any\n */export default function ScrollColorChangeText(props){const{text=\"Scroll to see the magic\",startColor=\"#CCCCCC\",endColor=\"#000000\",font,fontSizeDesktop=40,fontSizeTablet=32,fontSizeMobile=24,scrollDelay=0,lastWordsCount=0,lastWordsStartColor=\"#CCCCCC\",lastWordsEndColor=\"#FF0000\",customWordColors=[],wordSpacing=1}=props;const containerRef=useRef(null);const[currentFontSize,setCurrentFontSize]=useState(fontSizeDesktop);useEffect(()=>{if(typeof window===\"undefined\")return;const updateFontSize=()=>{const width=window.innerWidth;if(width>=1024){startTransition(()=>setCurrentFontSize(fontSizeDesktop));}else if(width>=768){startTransition(()=>setCurrentFontSize(fontSizeTablet));}else{startTransition(()=>setCurrentFontSize(fontSizeMobile));}};updateFontSize();window.addEventListener(\"resize\",updateFontSize);return()=>window.removeEventListener(\"resize\",updateFontSize);},[fontSizeDesktop,fontSizeTablet,fontSizeMobile]);const{scrollYProgress}=useScroll({target:containerRef,offset:[\"start 1.2\",\"start 0.5\"]});// Apply delay to scroll progress by adjusting the input range\nconst delayedScrollProgress=useTransform(scrollYProgress,[scrollDelay,1],[0,1]);// Split text by line breaks first, then by words\nconst lines=text.split(/\\\\n|\\n/);const allWords=text.replace(/\\\\n|\\n/g,\" \").split(\" \");const totalLetters=text.replace(/\\\\n|\\n/g,\"\").replace(/ /g,\"\").length;// Remove fontSize from font object to let our state handle it\nconst{fontSize,...fontWithoutSize}=font||{};return /*#__PURE__*/_jsx(\"div\",{ref:containerRef,style:{...props.style,position:\"relative\",display:\"flex\",alignItems:\"center\",justifyContent:\"center\",width:\"100%\",height:\"100%\"},children:/*#__PURE__*/_jsx(\"span\",{style:{display:\"inline\",fontSize:currentFontSize,textAlign:\"center\",...fontWithoutSize},children:lines.map((line,lineIndex)=>{const words=line.split(\" \");const wordsBefore=lines.slice(0,lineIndex).join(\" \").split(\" \").filter(w=>w.length>0).length;return /*#__PURE__*/_jsxs(\"span\",{children:[words.map((word,wordIndexInLine)=>{const globalWordIndex=wordsBefore+wordIndexInLine;const lettersBefore=allWords.slice(0,globalWordIndex).join(\"\").length;// Check if this word has custom colors\nconst customColor=customWordColors.find(c=>c.wordIndex===globalWordIndex);let wordStartColor=startColor;let wordEndColor=endColor;if(customColor){wordStartColor=customColor.startColor;wordEndColor=customColor.endColor;}else if(globalWordIndex>=allWords.length-lastWordsCount){wordStartColor=lastWordsStartColor;wordEndColor=lastWordsEndColor;}return /*#__PURE__*/_jsx(Word,{word:word,scrollYProgress:delayedScrollProgress,lettersBefore:lettersBefore,totalLetters:totalLetters,startColor:wordStartColor,endColor:wordEndColor,isLastWord:lineIndex===lines.length-1&&wordIndexInLine===words.length-1,wordSpacing:wordSpacing},wordIndexInLine);}),lineIndex<lines.length-1&&/*#__PURE__*/_jsx(\"br\",{})]},lineIndex);})})});}function Word({word,scrollYProgress,lettersBefore,totalLetters,startColor,endColor,isLastWord,wordSpacing}){const letters=word.split(\"\");return /*#__PURE__*/_jsxs(\"span\",{style:{display:\"inline-block\",whiteSpace:\"nowrap\"},children:[letters.map((letter,index)=>{const absoluteIndex=lettersBefore+index;const start=absoluteIndex/totalLetters;const end=start+1/totalLetters;return /*#__PURE__*/_jsx(Letter,{letter:letter,scrollYProgress:scrollYProgress,start:start,end:end,startColor:startColor,endColor:endColor},index);}),!isLastWord&&/*#__PURE__*/_jsx(\"span\",{style:{display:\"inline\",width:`${wordSpacing}ch`},children:\"\\xa0\"})]});}function Letter({letter,scrollYProgress,start,end,startColor,endColor}){const opacity=useTransform(scrollYProgress,[start,end],[.2,1]);const color=useTransform(scrollYProgress,[start,end],[startColor,endColor]);return /*#__PURE__*/_jsx(motion.span,{style:{opacity,color,display:letter===\" \"?\"inline\":\"inline-block\"},children:letter===\" \"?\"\\xa0\":letter});}addPropertyControls(ScrollColorChangeText,{text:{type:ControlType.String,title:\"Text\",defaultValue:\"Scroll to see the magic\",displayTextArea:true},startColor:{type:ControlType.Color,title:\"Start Color\",defaultValue:\"#CCCCCC\"},endColor:{type:ControlType.Color,title:\"End Color\",defaultValue:\"#000000\"},customWordColors:{type:ControlType.Array,title:\"Custom Words\",control:{type:ControlType.Object,controls:{wordIndex:{type:ControlType.Number,title:\"Word Index\",defaultValue:0,min:0,step:1,displayStepper:true},startColor:{type:ControlType.Color,title:\"Start Color\",defaultValue:\"#CCCCCC\"},endColor:{type:ControlType.Color,title:\"End Color\",defaultValue:\"#FF0000\"}}},defaultValue:[]},lastWordsCount:{type:ControlType.Number,title:\"Last Words\",defaultValue:1,min:0,max:20,step:1,displayStepper:true},lastWordsStartColor:{type:ControlType.Color,title:\"Last Words Start\",defaultValue:\"#CCCCCC\",hidden:({lastWordsCount})=>lastWordsCount===0},lastWordsEndColor:{type:ControlType.Color,title:\"Last Words End\",defaultValue:\"#0099FF\",hidden:({lastWordsCount})=>lastWordsCount===0},wordSpacing:{type:ControlType.Number,title:\"Word Spacing\",defaultValue:1,min:0,max:5,step:.1},font:{type:ControlType.Font,title:\"Font\",controls:\"extended\",defaultFontType:\"sans-serif\",defaultValue:{variant:\"Bold\",letterSpacing:\"-0.04em\",lineHeight:\"1em\"}},fontSizeDesktop:{type:ControlType.Number,title:\"Desktop Size\",defaultValue:40,min:12,max:200,step:1,unit:\"px\"},fontSizeTablet:{type:ControlType.Number,title:\"Tablet Size\",defaultValue:32,min:12,max:200,step:1,unit:\"px\"},fontSizeMobile:{type:ControlType.Number,title:\"Mobile Size\",defaultValue:24,min:12,max:200,step:1,unit:\"px\"},scrollDelay:{type:ControlType.Number,title:\"Scroll Delay\",defaultValue:0,min:0,max:1,step:.1,displayStepper:true}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"ScrollColorChangeText\",\"slots\":[],\"annotations\":{\"framerSupportedLayoutWidth\":\"any\",\"framerSupportedLayoutHeight\":\"any\",\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./ScrollColorChangeText.map"],"mappings":"8QAIG,SAAwB,EAAsB,EAAM,CAAC,GAAK,CAAC,OAAK,0BAA0B,aAAW,UAAU,WAAS,UAAU,OAAK,kBAAgB,GAAG,iBAAe,GAAG,iBAAe,GAAG,cAAY,EAAE,iBAAe,EAAE,sBAAoB,UAAU,oBAAkB,UAAU,mBAAiB,EAAE,CAAC,cAAY,GAAG,EAAY,EAAaA,EAAO,KAAK,CAAM,CAAC,EAAgB,GAAoBC,EAAS,EAAgB,CAAC,MAAc,CAAC,GAAU,IAAS,OAAY,OAAO,IAAM,MAAmB,CAAC,IAAM,EAAM,EAAO,WAA2B,EAAb,GAAO,SAA0B,EAAmB,EAAgB,CAAW,GAAO,QAAyB,EAAmB,EAAe,KAA4B,EAAmB,EAAe,CAAC,EAAsE,OAAlE,GAAgB,CAAC,EAAO,iBAAiB,SAAS,EAAe,KAAW,EAAO,oBAAoB,SAAS,EAAe,EAAG,CAAC,EAAgB,EAAe,EAAe,CAAC,CAAC,GAAK,CAAC,mBAAiB,EAAU,CAAC,OAAO,EAAa,OAAO,CAAC,YAAY,YAAY,CAAC,CAAC,CACh/B,EAAsB,EAAa,EAAgB,CAAC,EAAY,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CACzE,EAAM,EAAK,MAAM,SAAS,CAAO,EAAS,EAAK,QAAQ,UAAU,IAAI,CAAC,MAAM,IAAI,CAAO,EAAa,EAAK,QAAQ,UAAU,GAAG,CAAC,QAAQ,KAAK,GAAG,CAAC,O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