{"version":3,"file":"ScrollRevealText.BbOOgMEO.mjs","names":["useRef","useState","__esmMin","init_ssg_sandbox_shims","init_npm_react_18_3_1","window","ce","init_jsx_runtime","c","p","_e","de","addPropertyControls","init_framer_BisrWwwE","ControlType","ScrollRevealText","containerRef","wordRefs","progress","setProgress","words","text","onScroll","spans","vh","newProgress","lineMap","span","rect","y","i","lines","a","b","allPrevLinesFull","li","line","firstSpan","lineRect","fillStart","speed","offset","fillEnd","lineFill","totalWords","wordStart","wi","wordEnd","wordFill","wordIdx","fontSize","el","baseColor","word","fillColor","init_ScrollRevealText"],"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\":{\"type\":\"reactComponent\",\"name\":\"ScrollRevealText\",\"slots\":[],\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./ScrollRevealText.map"],"mappings":"A,6MAA0J,SAAgBe,EAAiB,CAAC,OAAK,0FAA0F,WAAS,GAAG,aAAW,IAAI,aAAW,IAAI,YAAU,UAAU,YAAU,UAAU,SAAO,EAAE,QAAM,GAAG,CAAC,IAAMC,EAAahB,EAAO,IAAI,EAAQiB,EAASjB,EAAO,CAAC,CAAC,EAAO,CAACkB,EAASC,GAAalB,EAAS,CAAC,CAAC,EAAQmB,EAAMC,EAAK,MAAM,GAAG,CAAC,CAAC,OAAO,OAAO,EAGpE,OAHsEf,MAAc,CAACa,EAAgB,MAAMC,EAAM,MAAM,CAAC,CAAC,KAAK,CAAC,CAAC,CAAE,EAAE,CAACC,CAAI,CAAC,EAAEf,MAAc,CAAC,IAAMgB,MAAa,CAAC,GAAG,CAACN,EAAa,QAAQ,OAAO,IAAMO,EAAMN,EAAS,QAAQ,OAAO,OAAO,EAAE,GAAG,CAACM,EAAM,OAAO,OAAO,IAAMC,EAAGnB,EAAO,YAAkBoB,EAAY,CAAC,GAAGP,CAAQ,EACjxBQ,EAAQ,CAAC,EAAEH,EAAM,SAAS,EAAK,IAAI,CAAC,GAAG,CAACI,EAAK,OAAO,IAAMC,EAAKD,EAAK,sBAAsB,EAAQE,EAAE,KAAK,MAAMD,EAAK,GAAG,EA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