{"version":3,"file":"ScrollColorText.DF9Vt_yi.mjs","names":["useRef","useState","useMemo"],"sources":["https:/framerusercontent.com/modules/Eg3FD2VMSiG6Ue9dDSxI/gTB2u3gs1TN1dsC7iSAH/ScrollColorText.js"],"sourcesContent":["import{jsx as _jsx}from\"react/jsx-runtime\";import{useEffect,useRef,useState,startTransition,useMemo}from\"react\";import{addPropertyControls,ControlType,useIsStaticRenderer}from\"framer\";// Helper function to interpolate between two colors\nfunction interpolateColor(color1,color2,factor){// Parse hex colors\nconst c1=color1.startsWith(\"#\")?color1.slice(1):color1;const c2=color2.startsWith(\"#\")?color2.slice(1):color2;const r1=parseInt(c1.substring(0,2),16);const g1=parseInt(c1.substring(2,4),16);const b1=parseInt(c1.substring(4,6),16);const r2=parseInt(c2.substring(0,2),16);const g2=parseInt(c2.substring(2,4),16);const b2=parseInt(c2.substring(4,6),16);const r=Math.round(r1+(r2-r1)*factor);const g=Math.round(g1+(g2-g1)*factor);const b=Math.round(b1+(b2-b1)*factor);return`#${((1<<24)+(r<<16)+(g<<8)+b).toString(16).slice(1)}`;}/**\n * Scroll Text Progress\n *\n * A text component that changes color as you scroll, like a progress bar\n *\n * @framerSupportedLayoutWidth any-prefer-fixed\n * @framerSupportedLayoutHeight auto\n */export default function ScrollTextProgress(props){const{text=\"Scroll down to see this text change color progressively, like a progress bar filling up.\",colorStart=\"#CCCCCC\",colorEnd=\"#000000\",background,textStyle,speed=1,startTrigger=\"start\",style}=props;const containerRef=useRef(null);const[scrollProgress,setScrollProgress]=useState(0);const isStatic=useIsStaticRenderer();const rafRef=useRef(null);const lastProgressRef=useRef(0);// Split text into words\nconst words=useMemo(()=>text.split(/(\\s+)/),[text]);useEffect(()=>{if(!containerRef.current||isStatic)return;const handleScroll=()=>{// Cancel any pending animation frame\nif(rafRef.current!==null){cancelAnimationFrame(rafRef.current);}// Use requestAnimationFrame to throttle calculations\nrafRef.current=requestAnimationFrame(()=>{if(!containerRef.current)return;const rect=containerRef.current.getBoundingClientRect();const viewportHeight=window.innerHeight;const elementHeight=rect.height;const elementTop=rect.top;// Determine start position based on trigger point\nlet triggerPoint;if(startTrigger===\"start\"){// Animation starts when top of element reaches bottom of viewport\ntriggerPoint=viewportHeight;}else if(startTrigger===\"center\"){// Animation starts when top of element reaches center of viewport\ntriggerPoint=viewportHeight/2;}else{// Animation starts when top of element reaches top of viewport\ntriggerPoint=0;}// Calculate scroll distance needed (affected by speed)\n// Lower speed = more scroll distance needed = slower animation\nconst scrollDistance=elementHeight/speed;// Calculate progress based on how far element has scrolled past trigger point\nconst scrolledPastTrigger=triggerPoint-elementTop;let progress=scrolledPastTrigger/scrollDistance;// Clamp between 0 and 1\nprogress=Math.max(0,Math.min(1,progress));// Only update state if progress has changed significantly (reduces re-renders)\nif(Math.abs(progress-lastProgressRef.current)>.001){lastProgressRef.current=progress;startTransition(()=>setScrollProgress(progress));}});};window.addEventListener(\"scroll\",handleScroll,{passive:true});handleScroll()// Initial calculation\n;return()=>{window.removeEventListener(\"scroll\",handleScroll);if(rafRef.current!==null){cancelAnimationFrame(rafRef.current);}};},[isStatic,speed,startTrigger]);return /*#__PURE__*/_jsx(\"div\",{ref:containerRef,style:{...style,background,paddingTop:24,paddingBottom:24,overflow:\"hidden\"},children:/*#__PURE__*/_jsx(\"p\",{style:{margin:0,whiteSpace:\"pre-wrap\",wordBreak:\"break-word\",...textStyle},children:words.map((word,index)=>{// Calculate which word should be colored based on progress\nconst totalWords=words.filter(w=>w.trim().length>0).length;const wordIndex=words.slice(0,index+1).filter(w=>w.trim().length>0).length-1;// Calculate the progress range for this word\nconst wordStart=wordIndex/totalWords;const wordEnd=(wordIndex+1)/totalWords;// Calculate color based on scroll progress\nlet color;if(scrollProgress<=wordStart){// Before this word - use start color\ncolor=colorStart;}else if(scrollProgress>=wordEnd){// After this word - use end color\ncolor=colorEnd;}else{// During this word - interpolate\nconst wordProgress=(scrollProgress-wordStart)/(wordEnd-wordStart);color=interpolateColor(colorStart,colorEnd,wordProgress);}return /*#__PURE__*/_jsx(\"span\",{style:{color},children:word},index);})})});}addPropertyControls(ScrollTextProgress,{text:{type:ControlType.String,title:\"Text\",displayTextArea:true,defaultValue:\"Scroll down to see this text change color progressively, like a progress bar filling up.\"},textStyle:{type:ControlType.Font,title:\"Text Style\",controls:\"extended\",defaultFontType:\"sans-serif\"},colorStart:{type:ControlType.Color,title:\"Start Color\",defaultValue:\"#CCCCCC\"},colorEnd:{type:ControlType.Color,title:\"End Color\",defaultValue:\"#000000\"},background:{type:ControlType.Color,title:\"Background\",defaultValue:\"#FFFFFF\"},speed:{type:ControlType.Number,title:\"Speed\",defaultValue:1,min:.1,max:5,step:.1,displayStepper:false},startTrigger:{type:ControlType.Enum,title:\"Start Trigger\",options:[\"start\",\"center\",\"end\"],optionTitles:[\"Start\",\"Center\",\"End\"],defaultValue:\"start\"}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"ScrollTextProgress\",\"slots\":[],\"annotations\":{\"framerContractVersion\":\"1\",\"framerSupportedLayoutHeight\":\"auto\",\"framerSupportedLayoutWidth\":\"any-prefer-fixed\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./ScrollColorText.map"],"mappings":"4NACA,SAAS,EAAiB,EAAO,EAAO,EAAO,CAC/C,IAAM,EAAG,EAAO,WAAW,GAAG,EAAE,EAAO,MAAM,CAAC,EAAE,EAAa,EAAG,EAAO,WAAW,GAAG,EAAE,EAAO,MAAM,CAAC,EAAE,EAAa,EAAG,SAAS,EAAG,UAAU,EAAE,CAAC,EAAE,EAAE,EAAQ,EAAG,SAAS,EAAG,UAAU,EAAE,CAAC,EAAE,EAAE,EAAQ,EAAG,SAAS,EAAG,UAAU,EAAE,CAAC,EAAE,EAAE,EAAQ,EAAG,SAAS,EAAG,UAAU,EAAE,CAAC,EAAE,EAAE,EAAQ,EAAG,SAAS,EAAG,UAAU,EAAE,CAAC,EAAE,EAAE,EAAQ,EAAG,SAAS,EA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