{"version":3,"file":"ScrollRevealText.Po0JAkR2.mjs","names":["useRef","useState"],"sources":["https:/framerusercontent.com/modules/0qQpEaGjre7uNyCGzexD/GBhPCq6gb9eSsHiPHOlr/ScrollRevealText.js"],"sourcesContent":["import{jsx as _jsx,jsxs as _jsxs}from\"react/jsx-runtime\";import{useEffect,useRef,useState}from\"react\";import{addPropertyControls,ControlType}from\"framer\";export function ScrollRevealText({text=\"This is a scroll reveal text component. Each word fills in left to right, line by line.\",fontSize=48,fontWeight=600,lineHeight=1.2,baseColor=\"#CCCCCC\",fillColor=\"#000000\",offset=0,speed=1}){const containerRef=useRef(null);const wordRefs=useRef([]);const[progress,setProgress]=useState([]);const words=text.split(\" \").filter(Boolean);useEffect(()=>{setProgress(new Array(words.length).fill(0));},[text]);useEffect(()=>{const onScroll=()=>{if(!containerRef.current)return;const spans=wordRefs.current.filter(Boolean);if(!spans.length)return;const vh=window.innerHeight;const newProgress=[...progress];// Group words into lines by their Y position\nconst lineMap={};spans.forEach((span,i)=>{if(!span)return;const rect=span.getBoundingClientRect();const y=Math.round(rect.top);if(!lineMap[y])lineMap[y]=[];lineMap[y].push(i);});const lines=Object.keys(lineMap).map(Number).sort((a,b)=>a-b).map(y=>lineMap[y]);let allPrevLinesFull=true;for(let li=0;li<lines.length;li++){const line=lines[li];const firstSpan=spans[line[0]];if(!firstSpan)continue;const lineRect=firstSpan.getBoundingClientRect();const triggerPoint=vh*(1-.15*speed)+offset;const fillStart=triggerPoint;const fillEnd=fillStart-150*speed;const lineProgress=Math.min(1,Math.max(0,(lineRect.top-fillEnd)/(fillStart-fillEnd)));const lineFill=1-lineProgress;if(!allPrevLinesFull){// Don't fill this line until prev is done\nline.forEach(i=>{newProgress[i]=0;});}else{// Distribute fill across words in this line left to right\nconst totalWords=line.length;line.forEach((wordIdx,wi)=>{const wordStart=wi/totalWords;const wordEnd=(wi+1)/totalWords;const wordFill=Math.min(1,Math.max(0,(lineFill-wordStart)/(wordEnd-wordStart)));newProgress[wordIdx]=wordFill;});if(lineFill<1)allPrevLinesFull=false;}}setProgress(newProgress);};window.addEventListener(\"scroll\",onScroll,{passive:true});onScroll();return()=>window.removeEventListener(\"scroll\",onScroll);},[progress.length,offset,speed]);return /*#__PURE__*/_jsx(\"div\",{ref:containerRef,style:{width:\"100%\",height:\"100%\",display:\"flex\",alignItems:\"center\"},children:/*#__PURE__*/_jsx(\"p\",{style:{margin:0,fontSize,fontWeight,lineHeight,display:\"flex\",flexWrap:\"wrap\",gap:`0 ${fontSize*.28}px`},children:words.map((word,i)=>/*#__PURE__*/_jsxs(\"span\",{ref:el=>{wordRefs.current[i]=el;},style:{position:\"relative\",display:\"inline-block\",color:\"transparent\"},children:[/*#__PURE__*/_jsx(\"span\",{style:{position:\"absolute\",inset:0,color:baseColor,whiteSpace:\"pre\"},children:word}),/*#__PURE__*/_jsx(\"span\",{style:{position:\"absolute\",inset:0,color:fillColor,whiteSpace:\"pre\",clipPath:`inset(0 ${(1-(progress[i]??0))*100}% 0 0)`},children:word}),/*#__PURE__*/_jsx(\"span\",{style:{visibility:\"hidden\",whiteSpace:\"pre\"},children:word})]},i))})});}addPropertyControls(ScrollRevealText,{text:{type:ControlType.String,title:\"Text\",displayTextArea:true,defaultValue:\"This is a scroll reveal text component. Each word fills in left to right, line by line.\"},fontSize:{type:ControlType.Number,title:\"Font Size\",defaultValue:48,min:12,max:200,step:1},fontWeight:{type:ControlType.Number,title:\"Font Weight\",defaultValue:600,min:100,max:900,step:100},lineHeight:{type:ControlType.Number,title:\"Line Height\",defaultValue:1.2,min:.8,max:3,step:.05},baseColor:{type:ControlType.Color,title:\"Base Color\",defaultValue:\"#CCCCCC\"},fillColor:{type:ControlType.Color,title:\"Fill Color\",defaultValue:\"#000000\"},offset:{type:ControlType.Number,title:\"Offset\",defaultValue:0,min:-500,max:500,step:1},speed:{type:ControlType.Number,title:\"Speed\",defaultValue:1,min:.1,max:5,step:.1}});\nexport const __FramerMetadata__ = {\"exports\":{\"ScrollRevealText\":{\"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