{"version":3,"file":"ScrollColorChangeText.M1NTL-Om.mjs","names":["useRef","useState","useEffect","startTransition","_jsx","_jsxs","__esmMin","window","init_npm_react_18_3_1","te","init_ssg_sandbox_shims","_e","de","init_jsx_runtime","p","ce","addPropertyControls","init_framer_ChujFWHC","ControlType","useScroll","motion","init_framer_motion_1EwlFBEG","useTransform","ScrollColorChangeText","props","text","startColor","endColor","font","fontSizeDesktop","fontSizeTablet","fontSizeMobile","containerRef","currentFontSize","setCurrentFontSize","updateFontSize","width","scrollYProgress","words","totalLetters","fontSize","fontWithoutSize","word","wordIndex","lettersBefore","Word","isLastWord","letters","letter","index","start","end","Letter","opacity","color","init_ScrollColorChangeText"],"sources":["https:/framerusercontent.com/modules/8oMxIkJCTv97VaSmurqu/v2Kju3niy9J3iVCe2uHa/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\",\"framerSupportedLayoutHeight\":\"any\",\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./ScrollColorChangeText.map"],"mappings":"A,oRAIG,SAAwBuB,EAAsBC,EAAM,CAAC,GAAK,CAACC,OAAK,0BAA0BC,aAAW,UAAUC,WAAS,UAAUC,OAAKC,kBAAgB,GAAGC,iBAAe,GAAGC,iBAAe,IAAIP,EAAYQ,EAAahC,EAAO,IAAI,EAAO,CAACiC,EAAgBC,GAAoBjC,EAAS4B,CAAe,EAAE3B,MAAc,CAAC,GAAUK,IAAS,OAAY,OAAO,IAAM4B,MAAmB,CAAC,IAAMC,EAAM7B,EAAO,WAA2BJ,EAAbiC,GAAO,SAA0BF,EAAmBL,CAAe,EAAYO,GAAO,QAAyBF,EAAmBJ,CAAc,MAA6BI,EAAmBH,CAAc,CAAC,CAAG,EAAoE,OAAlEI,EAAe,EAAE5B,EAAO,iBAAiB,SAAS4B,CAAc,MAAY5B,EAAO,oBAAoB,SAAS4B,CAAc,CAAE,EAAE,CAACN,EAAgBC,EAAeC,CAAc,CAAC,EAAE,GAAK,CAACM,mBAAiBlB,EAAU,CAAC,OAAOa,EAAa,OAAO,CAAC,YAAY,WAAW,CAAC,CAAC,EAAQM,EAAMb,EAAK,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