{"version":3,"file":"TextRevealOnScroll.CpFesCfb.mjs","names":["useRef","useState"],"sources":["https:/framerusercontent.com/modules/iDsmYU2fhXZ0UOq8cFqV/pSwdC9zNVbtjwneM36hw/TextRevealOnScroll.js"],"sourcesContent":["// Text Reveal on Scroll\n// Reveals text per letter, word, or line as you scroll past. Base color and reveal color are configurable.\nimport{jsx as _jsx}from\"react/jsx-runtime\";import{useRef,useEffect,useState,startTransition}from\"react\";import{addPropertyControls,ControlType,useIsStaticRenderer}from\"framer\";function splitText(text,mode){if(mode===\"letter\")return text.split(\"\").map((c,i)=>({key:i,value:c}));if(mode===\"word\")return text.split(/(\\s+)/).map((w,i)=>({key:i,value:w}));if(mode===\"line\")return text.split(/(\\n)/).map((l,i)=>({key:i,value:l}));return[{key:0,value:text}];}/**\n * Text Reveal on Scroll\n *\n * @framerSupportedLayoutWidth auto\n * @framerSupportedLayoutHeight auto\n */export default function TextRevealOnScroll(props){const{text,revealMode,baseColor,revealColor,font,revealDistance,style}=props;const isStatic=useIsStaticRenderer();const containerRef=useRef(null);const[revealProgress,setRevealProgress]=useState(0);useEffect(()=>{if(isStatic){startTransition(()=>setRevealProgress(1));return;}function onScroll(){if(!containerRef.current)return;const rect=containerRef.current.getBoundingClientRect();const windowHeight=window.innerHeight||document.documentElement.clientHeight;// Calculate how much of the component is visible\nconst visible=Math.min(windowHeight,Math.max(0,windowHeight-rect.top));const total=Math.min(windowHeight,rect.height);let progress=visible/(total+revealDistance);progress=Math.max(0,Math.min(1,progress));startTransition(()=>setRevealProgress(progress));}window.addEventListener(\"scroll\",onScroll,{passive:true});window.addEventListener(\"resize\",onScroll);onScroll();return()=>{window.removeEventListener(\"scroll\",onScroll);window.removeEventListener(\"resize\",onScroll);};},[isStatic,revealDistance]);const items=splitText(text,revealMode);const revealedCount=Math.round(items.length*revealProgress);return /*#__PURE__*/_jsx(\"div\",{ref:containerRef,style:{...style,position:\"relative\",display:\"block\",color:baseColor,...font,whiteSpace:revealMode===\"line\"?\"pre-line\":\"pre-wrap\"},children:items.map((item,i)=>/*#__PURE__*/_jsx(\"span\",{style:{color:i<revealedCount?revealColor:baseColor,transition:\"color 0.4s cubic-bezier(.4,0,.2,1)\",...font},\"aria-hidden\":\"true\",children:item.value},item.key))});}addPropertyControls(TextRevealOnScroll,{text:{type:ControlType.String,title:\"Text\",defaultValue:\"Reveal this text as you scroll.\",displayTextArea:true},revealMode:{type:ControlType.Enum,title:\"Reveal By\",options:[\"letter\",\"word\",\"line\"],optionTitles:[\"Letter\",\"Word\",\"Line\"],defaultValue:\"letter\",displaySegmentedControl:true},baseColor:{type:ControlType.Color,title:\"Base Color\",defaultValue:\"#CCCCCC\"},revealColor:{type:ControlType.Color,title:\"Reveal Color\",defaultValue:\"#222222\"},font:{type:ControlType.Font,title:\"Font\",controls:\"extended\",defaultFontType:\"sans-serif\",defaultValue:{fontSize:\"32px\",variant:\"Semibold\",letterSpacing:\"-0.01em\",lineHeight:\"1.2em\"}},revealDistance:{type:ControlType.Number,title:\"Reveal Distance\",defaultValue:100,min:0,max:500,unit:\"px\"}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"TextRevealOnScroll\",\"slots\":[],\"annotations\":{\"framerSupportedLayoutWidth\":\"auto\",\"framerSupportedLayoutHeight\":\"auto\",\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./TextRevealOnScroll.map"],"mappings":"gNAEgL,SAAS,EAAU,EAAK,EAAK,CAA2N,OAAvN,IAAO,SAAgB,EAAK,MAAM,GAAG,CAAC,KAAK,EAAE,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,CAAI,IAAO,OAAc,EAAK,MAAM,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,CAAI,IAAO,OAAc,EAAK,MAAM,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,IAAI,EAAE,MAAM,EA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