{"version":3,"file":"ScrollText.C77B_6bd.mjs","names":["useRef","useState","useCallback"],"sources":["https:/framerusercontent.com/modules/RZdvlBlmxGB5sRoTFFZB/VyrLrT9diGxEgsX3l9YR/ScrollText.js"],"sourcesContent":["import{jsx as _jsx,jsxs as _jsxs}from\"react/jsx-runtime\";import{addPropertyControls,ControlType,RenderTarget}from\"framer\";import{useRef,useEffect,useState,useCallback}from\"react\";/**\n * @framerDisableUnlink\n * @framerSupportedLayoutWidth any\n * @framerSupportedLayoutHeight any\n */export default function FillTextOnScroll(props){const{text=\"Add your text here. This component fills text with color as you scroll.\",effect=\"fade\",baseColor=\"rgba(255,255,255,0.2)\",fillColor=\"#FFFFFF\",font={},triggerOffset=\"normal\",playOnce=false,htmlTag=\"p\"}=props;const containerRef=useRef(null);const[elements,setElements]=useState([]);const progressRef=useRef(0);const[progress,setProgress]=useState(0);const rafRef=useRef(null);const hasCompletedRef=useRef(false);const isEditor=RenderTarget.current()===RenderTarget.canvas;useEffect(()=>{if(!text)return;const parts=[];text.split(/\\n/).forEach((line,lineIndex,lines)=>{const words=line.split(/\\s+/).filter(Boolean);words.forEach(w=>{parts.push({text:w+\" \",break:false});});if(lineIndex<lines.length-1){parts.push({text:\"\\n\",break:true});}});setElements(parts);},[text]);const updateProgress=useCallback(()=>{const container=containerRef.current;if(!container)return;const offsetMap={early:.9,normal:.7,late:.5};const triggerStart=offsetMap[triggerOffset]||.7;const rect=container.getBoundingClientRect();const windowHeight=window.innerHeight;const start=windowHeight*triggerStart;const end=windowHeight*.2;const rawProgress=(start-rect.top)/(start-end);const clampedProgress=Math.min(Math.max(rawProgress,0),1);if(clampedProgress>=1)hasCompletedRef.current=true;if(clampedProgress!==progressRef.current){progressRef.current=clampedProgress;setProgress(clampedProgress);}},[triggerOffset]);useEffect(()=>{if(isEditor){setProgress(.4);return;}const handleScroll=()=>{if(playOnce&&hasCompletedRef.current)return;if(rafRef.current)cancelAnimationFrame(rafRef.current);rafRef.current=requestAnimationFrame(updateProgress);};window.addEventListener(\"scroll\",handleScroll,{passive:true});updateProgress();return()=>{window.removeEventListener(\"scroll\",handleScroll);if(rafRef.current)cancelAnimationFrame(rafRef.current);};},[triggerOffset,playOnce,isEditor,updateProgress]);const getWordProgress=(index,total)=>{const wordProgress=progress*total-index;return Math.min(Math.max(wordProgress,0),1);};const Tag=htmlTag;const{fontSize,lineHeight,letterSpacing,...fontRest}=font||{};const sharedStyle={...fontRest,fontSize,lineHeight,letterSpacing,userSelect:\"auto\",margin:0,padding:0,overflow:\"visible\"};return /*#__PURE__*/_jsxs(\"div\",{ref:containerRef,style:{...props.style,width:\"100%\",overflow:\"visible\"},children:[\" \",/*#__PURE__*/_jsx(Tag,{style:sharedStyle,children:elements.map((item,i)=>{if(item.break){return /*#__PURE__*/_jsx(\"br\",{},i);}const wp=getWordProgress(i,elements.length);const isFilled=wp>=.5;const effectStyles={fade:{color:isFilled?fillColor:baseColor,transition:\"color 0.3s ease-out\",filter:\"none\"},blur:{color:isFilled?fillColor:baseColor,transition:\"color 0.4s ease-out, filter 0.4s ease-out\",filter:isFilled?\"blur(0px)\":\"blur(4px)\"},snap:{color:isFilled?fillColor:baseColor,transition:\"none\",filter:\"none\"}};return /*#__PURE__*/_jsx(\"span\",{style:{...effectStyles[effect]},children:item.text},i);})})]});}FillTextOnScroll.displayName=\"Fill Text on Scroll\";addPropertyControls(FillTextOnScroll,{text:{type:ControlType.String,title:\"Text\",defaultValue:\"Add your text here. This component fills text with color as you scroll.\",displayTextArea:true},effect:{type:ControlType.Enum,title:\"Effect\",options:[\"fade\",\"blur\",\"snap\"],optionTitles:[\"Fade\",\"Blur\",\"Snap\"],defaultValue:\"fade\"},baseColor:{type:ControlType.Color,title:\"Base Color\",defaultValue:\"rgba(255,255,255,0.2)\"},fillColor:{type:ControlType.Color,title:\"Fill Color\",defaultValue:\"#FFFFFF\"},font:{type:ControlType.Font,title:\"Font\",controls:\"extended\",displayTextAlignment:true,displayFontSize:false,defaultFontType:\"sans-serif\"},htmlTag:{type:ControlType.Enum,title:\"HTML Tag\",options:[\"h1\",\"h2\",\"h3\",\"h4\",\"h5\",\"h6\",\"p\",\"span\"],optionTitles:[\"H1\",\"H2\",\"H3\",\"H4\",\"H5\",\"H6\",\"P\",\"Span\"],defaultValue:\"p\"},triggerOffset:{type:ControlType.Enum,title:\"Trigger\",options:[\"early\",\"normal\",\"late\"],optionTitles:[\"Early\",\"Normal\",\"Late\"],defaultValue:\"normal\",displaySegmentedControl:true},playOnce:{type:ControlType.Boolean,title:\"Play Once\",defaultValue:false}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"FillTextOnScroll\",\"slots\":[],\"annotations\":{\"framerSupportedLayoutHeight\":\"any\",\"framerContractVersion\":\"1\",\"framerDisableUnlink\":\"* @framerSupportedLayoutWidth any\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./ScrollText.map"],"mappings":"sNAIG,SAAwB,EAAiB,EAAM,CAAC,GAAK,CAAC,OAAK,0EAA0E,SAAO,OAAO,YAAU,wBAAwB,YAAU,UAAU,OAAK,CAAC,EAAE,gBAAc,SAAS,WAAS,GAAM,UAAQ,KAAK,EAAY,EAAaA,EAAO,IAAI,EAAO,CAAC,EAAS,GAAaC,EAAS,CAAC,CAAC,EAAQ,EAAYD,EAAO,CAAC,EAAO,CAAC,EAAS,GAAaC,EAAS,CAAC,EAAQ,EAAOD,EAAO,IAAI,EAAQ,EAAgBA,EAAO,EAAK,EAAQ,EAAS,EAAa,QAAQ,IAAI,EAAa,OAAO,MAAc,CAAC,GAAG,CAAC,EAAK,OAAO,IAAM,EAAM,CAAC,EAAE,EAAK,MAAM,IAAI,CAAC,CAAC,SAAS,EAAK,EAAU,IAAQ,CAA+C,EAA7B,MAAM,KAAK,CAAC,CAAC,OAAO,OAAa,CAAC,CAAC,QAAQ,GAAG,CAAC,EAAM,KAAK,CAAC,KAAK,EAAE,IAAI,MAAM,EAAK,CAAC,CA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