{"version":3,"file":"ScrollColorChangeText.Co1kMA4o.mjs","names":["useRef","useState"],"sources":["https:/framerusercontent.com/modules/rcgdIjTxNCKihRNK232B/Gr8xZvJUtYglokwkiQAZ/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\":{\"framerContractVersion\":\"1\",\"framerSupportedLayoutWidth\":\"any\",\"framerSupportedLayoutHeight\":\"any\"}},\"__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,IAAI,EAAY,EAAaA,EAAO,IAAI,EAAO,CAAC,EAAgB,GAAoBC,EAAS,CAAe,EAAE,MAAc,CAAC,GAAU,IAAS,OAAY,OAAO,IAAM,MAAmB,CAAC,IAAM,EAAM,EAAO,WAA2B,EAAb,GAAO,SAA0B,EAAmB,CAAe,EAAY,GAAO,QAAyB,EAAmB,CAAc,MAA6B,EAAmB,CAAc,CAAC,CAAG,EAAoE,OAAlE,EAAe,EAAE,EAAO,iBAAiB,SAAS,CAAc,MAAY,EAAO,oBAAoB,SAAS,CAAc,CAAE,EAAE,CAAC,EAAgB,EAAe,CAAc,CAAC,EAAE,GAAK,CAAC,mBAAiB,EAAU,CAAC,OAAO,EAAa,OAAO,CAAC,YAAY,WAAW,CAAC,CAAC,EAAQ,EAAM,EAAK,MAAM,GAAG,EAAQ,EAAa,EAAK,QAAQ,KAAK,EAAE,CAAC,CAAC,OAC57B,CAAC,WAAS,GAAG,GAAiB,GAAM,CAAC,EAAE,OAAoB,EAAK,MAAM,CAAC,IAAI,EAAa,MAAM,CAAC,GAAG,EAAM,MAAM,SAAS,WAAW,QAAQ,OAAO,WAAW,SAAS,eAAe,SAAS,MAAM,OAAO,OAAO,MAAM,EAAE,SAAsB,EAAK,OAAO,CAAC,MAAM,CAAC,QAAQ,SAAS,SAAS,EAAgB,GAAG,CAAe,EAAE,SAAS,EAAM,KAAK,EAAK,IAAY,CAAC,IAAM,EAAc,EAAM,MAAM,EAAE,CAAS,CAAC,CAAC,KAAK,EA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