{"version":3,"file":"ScrollColorChangeText.BxA2nwFc.mjs","names":["useRef","useState","__esmMin","init_ssg_sandbox_shims","te","init_npm_react_18_3_1","_e","p","ce","de","window","useTransform","motion","useScroll","init_framer_motion_DhsWWWsN","init_framer_BWFVvmND","addPropertyControls","ControlType","ScrollColorChangeText","props","containerRef","currentFontSize","setCurrentFontSize","fontSizeDesktop","updateFontSize","width","fontSizeTablet","fontSizeMobile","words","text","totalLetters","fontWithoutSize","font","lettersBefore","wordIndex","Word","letters","word","start","index","end","Letter","isLastWord","opacity","scrollYProgress","color","startColor","endColor","letter","init_ScrollColorChangeText","init_jsx_runtime"],"sources":["https:/framerusercontent.com/modules/5WhfMhg4WdGz99GQKo5w/K5P4A4FleMLmuIN1NHeV/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}=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 0.8\",\"start 0.2\"]});const words=text.split(\" \");const totalLetters=text.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,...fontWithoutSize},children:words.map((word,wordIndex)=>{const lettersBefore=words.slice(0,wordIndex).join(\"\").length;return /*#__PURE__*/_jsx(Word,{word:word,scrollYProgress:scrollYProgress,lettersBefore:lettersBefore,totalLetters:totalLetters,startColor:startColor,endColor:endColor,isLastWord:wordIndex===words.length-1},wordIndex);})})});}function Word({word,scrollYProgress,lettersBefore,totalLetters,startColor,endColor,isLastWord}){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\"},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\"},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\"}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"ScrollColorChangeText\",\"slots\":[],\"annotations\":{\"framerSupportedLayoutWidth\":\"any\",\"framerContractVersion\":\"1\",\"framerSupportedLayoutHeight\":\"any\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./ScrollColorChangeText.map"],"mappings":"A,yQAIG,SAAwBkB,EAAsB,EAAM,CAAC,GAAK,CAAC,OAAK,0BAA0B,aAAW,UAAU,WAAS,UAAU,OAAK,kBAAgB,GAAG,iBAAe,GAAG,iBAAe,IAAIC,EAAYC,EAAapB,EAAO,IAAI,EAAO,CAACqB,EAAgBC,GAAoBrB,EAASsB,CAAe,EAAEf,MAAc,CAAC,GAAUE,IAAS,OAAY,OAAO,IAAMc,MAAmB,CAAC,IAAMC,EAAMf,EAAO,WAA2BN,EAAbqB,GAAO,SAA0BH,EAAmBC,CAAe,EAAYE,GAAO,QAAyBH,EAAmBI,CAAc,MAA6BJ,EAAmBK,CAAc,CAAC,CAAG,EAAoE,OAAlEH,EAAe,EAAEd,EAAO,iBAAiB,SAASc,CAAc,MAAYd,EAAO,oBAAoB,SAASc,CAAc,CAAE,EAAE,CAACD,EAAgBG,EAAeC,CAAc,CAAC,EAAE,GAAK,CAAC,mBAAiBd,EAAU,CAAC,OAAOO,EAAa,OAAO,CAAC,YAAY,WAAW,CAAC,CAAC,EAAQQ,EAAMC,EAAK,MAAM,GAAG,EAAQC,EAAaD,EAAK,QAAQ,KAAK,EAAE,C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