{"version":3,"file":"ScrollColorChangeText.DiNfEMJA.mjs","names":["useRef","useState","useMemo","useCallback"],"sources":["https:/framerusercontent.com/modules/HpsApo08rij5XUR0lGtw/I1n3QWhvQeX0v4EJSKSh/ScrollColorChangeText.js"],"sourcesContent":["// User request: Create a reusable, canvas-insertable Framer code component named ScrollColorChangeText that splits heading text into character spans (preserving spaces) and progressively interpolates each character color from muted rgb(180,180,180) to readable rgb(12,12,12) based on scroll position with a gentle left-to-right sweep, using a requestAnimationFrame-backed scroll listener (not time-based), respecting reduced motion, rendering as a centered 100%-width h2, matching Home About heading typography across breakpoints, and exposing controls for text, mutedColor, activeColor, and transitionRange.\nimport{jsx as _jsx}from\"react/jsx-runtime\";import{useCallback,useEffect,useMemo,useRef,useState,startTransition}from\"react\";import{addPropertyControls,ControlType,useIsStaticRenderer}from\"framer\";function clamp(value,min,max){return Math.min(max,Math.max(min,value));}function parseColorToRGB(color){const normalized=color.trim();const shortHex=/^#([a-f\\d]{3})$/i.exec(normalized);if(shortHex){const h=shortHex[1];return{r:parseInt(h[0]+h[0],16),g:parseInt(h[1]+h[1],16),b:parseInt(h[2]+h[2],16)};}const longHex=/^#([a-f\\d]{6})$/i.exec(normalized);if(longHex){const h=longHex[1];return{r:parseInt(h.slice(0,2),16),g:parseInt(h.slice(2,4),16),b:parseInt(h.slice(4,6),16)};}const rgb=/^rgb\\(\\s*(\\d+),\\s*(\\d+),\\s*(\\d+)\\s*\\)$/i.exec(normalized);if(rgb){return{r:clamp(Number(rgb[1]),0,255),g:clamp(Number(rgb[2]),0,255),b:clamp(Number(rgb[3]),0,255)};}return{r:180,g:180,b:180};}function mixColor(from,to,progress){const p=clamp(progress,0,1);const r=Math.round(from.r+(to.r-from.r)*p);const g=Math.round(from.g+(to.g-from.g)*p);const b=Math.round(from.b+(to.b-from.b)*p);return`rgb(${r}, ${g}, ${b})`;}/**\n * @framerSupportedLayoutWidth any-prefer-fixed\n * @framerSupportedLayoutHeight auto\n */export default function ScrollColorChangeText(props){const{text=\"The Sharks Studio team has spent years filming real properties. Today, we open our doors to train the next generation.\",mutedColor=\"rgb(180,180,180)\",activeColor=\"rgb(12,12,12)\",transitionRange=.26,typographyStyle=\"Heading\"}=props;const isStatic=useIsStaticRenderer();const elementRef=useRef(null);const spansRef=useRef([]);const rafIdRef=useRef(null);const[fontSize,setFontSize]=useState(50);const[reduceMotion,setReduceMotion]=useState(false);const chars=useMemo(()=>Array.from(text),[text]);const mutedRgb=useMemo(()=>parseColorToRGB(mutedColor),[mutedColor]);const activeRgb=useMemo(()=>parseColorToRGB(activeColor),[activeColor]);const updateTypography=useCallback(()=>{if(typeof window===\"undefined\")return;if(typographyStyle===\"Body\"){startTransition(()=>setFontSize(20));return;}const width=window.innerWidth;const nextSize=width>=1280?50:width>=992?46:38;startTransition(()=>setFontSize(nextSize));},[typographyStyle]);const paintFromScroll=useCallback(()=>{rafIdRef.current=null;if(typeof window===\"undefined\")return;const root=elementRef.current;if(!root)return;const rect=root.getBoundingClientRect();const viewportHeight=window.innerHeight||1;const startY=viewportHeight*.9;const endY=viewportHeight*.12-rect.height;const denominator=Math.max(1,startY-endY);const baseProgress=clamp((startY-rect.top)/denominator,0,1);const range=Math.max(.08,transitionRange);const maxStagger=Math.max(0,1-range);const count=Math.max(chars.length-1,1);for(let i=0;i<chars.length;i++){const span=spansRef.current[i];if(!span)continue;const stagger=i/count*maxStagger;const local=(baseProgress-stagger)/range;span.style.color=mixColor(mutedRgb,activeRgb,local);}},[activeRgb,chars.length,mutedRgb,transitionRange]);const requestPaint=useCallback(()=>{if(rafIdRef.current!==null)return;if(typeof window===\"undefined\")return;rafIdRef.current=window.requestAnimationFrame(paintFromScroll);},[paintFromScroll]);useEffect(()=>{if(typeof window===\"undefined\")return;updateTypography();const onResize=()=>{updateTypography();requestPaint();};window.addEventListener(\"resize\",onResize);return()=>window.removeEventListener(\"resize\",onResize);},[requestPaint,updateTypography]);useEffect(()=>{if(typeof window===\"undefined\")return;const mediaQuery=window.matchMedia(\"(prefers-reduced-motion: reduce)\");const apply=()=>{startTransition(()=>setReduceMotion(mediaQuery.matches));};apply();mediaQuery.addEventListener(\"change\",apply);return()=>mediaQuery.removeEventListener(\"change\",apply);},[]);useEffect(()=>{if(isStatic||reduceMotion)return;if(typeof window===\"undefined\")return;requestPaint();const onScroll=()=>requestPaint();window.addEventListener(\"scroll\",onScroll,{passive:true});document.addEventListener(\"scroll\",onScroll,{passive:true,capture:true});window.addEventListener(\"orientationchange\",onScroll);return()=>{window.removeEventListener(\"scroll\",onScroll);document.removeEventListener(\"scroll\",onScroll,true);window.removeEventListener(\"orientationchange\",onScroll);if(rafIdRef.current!==null){window.cancelAnimationFrame(rafIdRef.current);rafIdRef.current=null;}};},[isStatic,reduceMotion,requestPaint]);const immediateColor=reduceMotion||isStatic?activeColor:undefined;const isBody=typographyStyle===\"Body\";const ElementTag=isBody?\"p\":\"h2\";return /*#__PURE__*/_jsx(ElementTag,{ref:elementRef,style:{position:\"relative\",width:\"100%\",margin:0,textAlign:isBody?\"left\":\"center\",fontFamily:'\"Manrope\", sans-serif',fontWeight:isBody?500:400,fontSize:`${fontSize}px`,lineHeight:isBody?1.4:1.2,letterSpacing:isBody?\"normal\":\"-2.5px\",color:immediateColor,whiteSpace:\"normal\",overflowWrap:\"break-word\"},children:chars.map((char,index)=>/*#__PURE__*/_jsx(\"span\",{ref:node=>{spansRef.current[index]=node;},style:{color:immediateColor??mutedColor,whiteSpace:\"pre-wrap\"},children:char},`${char}-${index}`))});}addPropertyControls(ScrollColorChangeText,{typographyStyle:{type:ControlType.Enum,title:\"Style\",defaultValue:\"Heading\",options:[\"Heading\",\"Body\"],optionTitles:[\"Heading\",\"Body\"],displaySegmentedControl:true},text:{type:ControlType.String,title:\"Text\",defaultValue:\"The Sharks Studio team has spent years filming real properties. Today, we open our doors to train the next generation.\",displayTextArea:true},mutedColor:{type:ControlType.Color,title:\"Muted\",defaultValue:\"rgb(180,180,180)\"},activeColor:{type:ControlType.Color,title:\"Active\",defaultValue:\"rgb(12,12,12)\"},transitionRange:{type:ControlType.Number,title:\"Range\",defaultValue:.26,min:.05,max:1,step:.01}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"ScrollColorChangeText\",\"slots\":[],\"annotations\":{\"framerContractVersion\":\"1\",\"framerSupportedLayoutWidth\":\"any-prefer-fixed\",\"framerSupportedLayoutHeight\":\"auto\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./ScrollColorChangeText.map"],"mappings":"mOACoM,SAAS,EAAM,EAAM,EAAI,EAAI,CAAC,OAAO,KAAK,IAAI,EAAI,KAAK,IAAI,EAAI,CAAK,CAAC,CAAE,CAAC,SAAS,EAAgB,EAAM,CAAC,IAAM,EAAW,EAAM,KAAK,EAAQ,EAAS,mBAAmB,KAAK,CAAU,EAAE,GAAG,EAAS,CAAC,IAAM,EAAE,EAAS,GAAG,MAAM,CAAC,EAAE,SAAS,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE,EAAE,SAAS,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE,EAAE,SAAS,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,CAAE,CAAC,IAAM,EAAQ,mBAAmB,KAAK,CAAU,EAAE,GAAG,EAAQ,CAAC,IAAM,EAAE,EAAQ,GAAG,MAAM,CAAC,EAAE,SAAS,EAAE,MAAM,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC,CAAE,CAAC,IAAM,EAAI,0CAA0C,KAAK,CAAU,EAA6G,OAAxG,EAAW,CAAC,EAAE,EAAM,OAAO,EAAI,EAAE,EAAE,EAAE,GAAG,EAAE,EAAE,EAAM,OAAO,EAAI,EAAE,EAAE,EAAE,GAAG,EAAE,EAAE,EAAM,OAAO,EAAI,EAAE,EAAE,EAAE,GAAG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