{"version":3,"file":"Scroll_Text_Reveal.B112exmp.mjs","names":["useRef","useState","useMemo","useCallback"],"sources":["https:/framerusercontent.com/modules/h6ugFP0QCY1iCc690Zs4/j98cPH9IatievOIW3fru/Scroll_Text_Reveal.js"],"sourcesContent":["import{jsx as _jsx,jsxs as _jsxs}from\"react/jsx-runtime\";import{useRef,useEffect,useState,useMemo,startTransition,useCallback}from\"react\";import{addPropertyControls,ControlType,useIsStaticRenderer}from\"framer\";import{useInView}from\"framer-motion\";/**\n * Scroll Text Animation\n *\n * @framerSupportedLayoutWidth any-prefer-fixed\n * @framerSupportedLayoutHeight auto\n */export default function TextReveal(props){const{text=\"This is a sample text that will animate as you scroll. Each word or letter will activate and change color based on your scroll position.\",animationType=\"word\",inactiveColor=\"#666666\",activeColor=\"#FFFFFF\",font,animationSpeed=50,triggerOffset=.8,smoothTransition=true,textAlign=\"left\",style}=props;const containerRef=useRef(null);const isInView=useInView(containerRef,{margin:\"0px 0px -20% 0px\"});const isStatic=useIsStaticRenderer();const[scrollProgress,setScrollProgress]=useState(0);const rafRef=useRef();const lastScrollTime=useRef(0);const textSegments=useMemo(()=>{if(animationType===\"word\"){// Split by spaces while preserving whitespace and line breaks\nreturn text.split(/(\\s+)/).filter(segment=>segment.length>0);}else{// For letter mode, split each character including line breaks\nreturn text.split(\"\");}},[text,animationType]);const updateScrollProgress=useCallback(()=>{if(!containerRef.current)return;const rect=containerRef.current.getBoundingClientRect();const windowHeight=window.innerHeight;const elementTop=rect.top;const elementHeight=rect.height;const elementBottom=rect.bottom;// Calculate scroll progress based on element position\nconst startTrigger=windowHeight*triggerOffset;// End trigger should ensure animation completes when element still has 35% left to scroll away\n// This means when element bottom is at 65% of viewport height from top\nconst endTrigger=windowHeight*.65;let progress=0;// Check if element bottom is still in viewport\nif(elementBottom>endTrigger&&elementTop<=startTrigger){// Calculate progress based on how much the element has moved through the viewport\nconst totalDistance=startTrigger+elementHeight-endTrigger;const currentDistance=startTrigger-elementTop;progress=Math.min(1,Math.max(0,currentDistance/totalDistance));}else if(elementBottom<=endTrigger){progress=1;}// Apply easing function for smoother animation\nif(smoothTransition){progress=progress*progress*(3-2*progress)// Smoothstep function\n;}progress=Math.max(0,Math.min(1,progress));startTransition(()=>setScrollProgress(progress));},[triggerOffset,smoothTransition]);useEffect(()=>{if(isStatic||!isInView)return;const handleScroll=()=>{const now=Date.now();if(now-lastScrollTime.current<16)return;// Throttle to ~60fps\nlastScrollTime.current=now;if(rafRef.current){cancelAnimationFrame(rafRef.current);}rafRef.current=requestAnimationFrame(updateScrollProgress);};updateScrollProgress();window.addEventListener(\"scroll\",handleScroll,{passive:true});window.addEventListener(\"resize\",updateScrollProgress,{passive:true});return()=>{window.removeEventListener(\"scroll\",handleScroll);window.removeEventListener(\"resize\",updateScrollProgress);if(rafRef.current){cancelAnimationFrame(rafRef.current);}};},[isInView,isStatic,updateScrollProgress]);const activeSegmentCount=Math.floor(scrollProgress*textSegments.length);if(isStatic){return /*#__PURE__*/_jsxs(\"div\",{ref:containerRef,style:{...style,position:\"relative\",width:\"100%\",whiteSpace:\"pre-wrap\",wordWrap:\"break-word\",textAlign,...font},children:[/*#__PURE__*/_jsx(\"span\",{style:{color:activeColor},children:text.substring(0,Math.floor(text.length*.3))}),/*#__PURE__*/_jsx(\"span\",{style:{color:inactiveColor},children:text.substring(Math.floor(text.length*.3))})]});}return /*#__PURE__*/_jsx(\"div\",{ref:containerRef,style:{...style,position:\"relative\",width:\"100%\",whiteSpace:\"pre-wrap\",wordWrap:\"break-word\",textAlign,...font},children:textSegments.map((segment,index)=>{const isActive=index<activeSegmentCount;const isCurrentlyActivating=index===Math.floor(activeSegmentCount)&&scrollProgress>0;const segmentColor=isActive?activeColor:inactiveColor;const transition=isCurrentlyActivating&&smoothTransition?`color ${animationSpeed}ms cubic-bezier(0.4, 0, 0.2, 1)`:\"none\";return /*#__PURE__*/_jsx(\"span\",{style:{color:segmentColor,transition,whiteSpace:\"pre-wrap\",willChange:\"color\"},children:segment},index);})});}addPropertyControls(TextReveal,{text:{type:ControlType.String,title:\"Text\",defaultValue:\"This is a sample text that will animate as you scroll. Each word or letter will activate and change color based on your scroll position.\",displayTextArea:true},animationType:{type:ControlType.Enum,title:\"Animation Type\",options:[\"word\",\"letter\"],defaultValue:\"word\",displaySegmentedControl:true},inactiveColor:{type:ControlType.Color,title:\"Inactive Color\",defaultValue:\"#666666\"},activeColor:{type:ControlType.Color,title:\"Active Color\",defaultValue:\"#FFFFFF\"},font:{type:ControlType.Font,title:\"Font\",defaultValue:{fontSize:\"24px\",variant:\"Medium\",letterSpacing:\"-0.01em\",lineHeight:\"1.4em\"},controls:\"extended\",defaultFontType:\"sans-serif\"},textAlign:{type:ControlType.Enum,title:\"Text Align\",options:[\"left\",\"center\",\"right\",\"justify\"],defaultValue:\"left\",displaySegmentedControl:true},animationSpeed:{type:ControlType.Number,title:\"Animation Speed\",defaultValue:50,min:10,max:500,step:10,unit:\"ms\"},triggerOffset:{type:ControlType.Number,title:\"Trigger Offset\",defaultValue:.8,min:.1,max:1,step:.1,unit:\"\"},smoothTransition:{type:ControlType.Boolean,title:\"Smooth Transition\",defaultValue:true,enabledTitle:\"On\",disabledTitle:\"Off\"}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"TextReveal\",\"slots\":[],\"annotations\":{\"framerSupportedLayoutWidth\":\"any-prefer-fixed\",\"framerContractVersion\":\"1\",\"framerSupportedLayoutHeight\":\"auto\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./Scroll_Text_Reveal.map"],"mappings":"sRAKG,SAAwB,EAAW,EAAM,CAAC,GAAK,CAAC,OAAK,2IAA2I,gBAAc,OAAO,gBAAc,UAAU,cAAY,UAAU,OAAK,iBAAe,GAAG,gBAAc,GAAG,mBAAiB,GAAK,YAAU,OAAO,SAAO,EAAY,EAAaA,EAAO,KAAK,CAAO,EAAS,EAAU,EAAa,CAAC,OAAO,mBAAmB,CAAC,CA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