{"version":3,"file":"ScrollHighlightText.0jpRnH_B.mjs","names":["useRef","useState"],"sources":["https:/framerusercontent.com/modules/3SDDgHkGC58Ph0I4tssn/awVrA6QLONoy3lcFV9PT/ScrollHighlightText.js"],"sourcesContent":["// Scroll-based text highlighter with customizable formatting and highlight settings\nimport{jsx as _jsx}from\"react/jsx-runtime\";import{useEffect,useState,useRef,startTransition}from\"react\";import{addPropertyControls,ControlType,useInView}from\"framer\";/**\n * Scroll Highlight Text\n *\n * A text component that highlights based on scroll position with customizable formatting\n *\n * @framerIntrinsicWidth 400\n * @framerIntrinsicHeight 100\n *\n * @framerSupportedLayoutWidth any-prefer-fixed\n * @framerSupportedLayoutHeight auto\n */export default function ScrollHighlightText(props){const{text,font,inactiveColor,activeColor,scrollTrigger,scrollOffset,animationDuration,scrollRange,ariaLabel,role,semanticTag,style}=props;const containerRef=useRef(null);const[scrollProgress,setScrollProgress]=useState(0);const[hasBeenInView,setHasBeenInView]=useState(false);const isInView=useInView(containerRef,{once:true,amount:0});useEffect(()=>{if(isInView&&!hasBeenInView){startTransition(()=>{setHasBeenInView(true);});}},[isInView,hasBeenInView]);useEffect(()=>{if(typeof window===\"undefined\"||!hasBeenInView)return;const handleScroll=()=>{if(!containerRef.current)return;const rect=containerRef.current.getBoundingClientRect();const viewportHeight=window.innerHeight;let triggerPoint;if(scrollTrigger===\"top\"){triggerPoint=viewportHeight-scrollOffset;}else if(scrollTrigger===\"center\"){triggerPoint=viewportHeight/2-scrollOffset;}else{triggerPoint=0-scrollOffset;}const elementTop=rect.top;const startScroll=triggerPoint;const endScroll=triggerPoint-scrollRange;let progress=0;if(elementTop<=startScroll&&elementTop>=endScroll){progress=(startScroll-elementTop)/scrollRange;}else if(elementTop<endScroll){progress=1;}startTransition(()=>{setScrollProgress(Math.max(0,Math.min(1,progress)));});};handleScroll();window.addEventListener(\"scroll\",handleScroll,{passive:true});window.addEventListener(\"resize\",handleScroll,{passive:true});return()=>{window.removeEventListener(\"scroll\",handleScroll);window.removeEventListener(\"resize\",handleScroll);};},[scrollTrigger,scrollOffset,scrollRange,hasBeenInView]);const words=text.split(/(\\s+)/);const totalWords=words.filter(word=>word.trim().length>0).length;let wordIndex=0;const isFixedWidth=style?.width===\"100%\";const Tag=semanticTag;return /*#__PURE__*/_jsx(\"div\",{ref:containerRef,style:{...style,position:\"relative\",display:\"inline-block\",...isFixedWidth?{}:{width:\"max-content\"}},children:/*#__PURE__*/_jsx(Tag,{style:{...font,display:\"inline-block\",margin:0},\"aria-label\":ariaLabel||text,role:role||undefined,children:words.map((word,index)=>{const isWhitespace=word.trim().length===0;if(!isWhitespace){const currentWordIndex=wordIndex;wordIndex++;const wordProgress=currentWordIndex/totalWords;const isActive=scrollProgress>=wordProgress;return /*#__PURE__*/_jsx(\"span\",{style:{color:isActive?activeColor:inactiveColor,transition:`color ${animationDuration}ms ease-out`},children:word},index);}return /*#__PURE__*/_jsx(\"span\",{children:word},index);})})});}addPropertyControls(ScrollHighlightText,{text:{type:ControlType.String,title:\"Text\",defaultValue:\"Scroll to highlight this text word by word as you scroll down the page\",displayTextArea:true},semanticTag:{type:ControlType.Enum,title:\"HTML Tag\",options:[\"p\",\"h1\",\"h2\",\"h3\",\"h4\",\"h5\",\"h6\",\"span\"],optionTitles:[\"Paragraph\",\"Heading 1\",\"Heading 2\",\"Heading 3\",\"Heading 4\",\"Heading 5\",\"Heading 6\",\"Span\"],defaultValue:\"p\"},ariaLabel:{type:ControlType.String,title:\"Aria Label\",defaultValue:\"\",placeholder:\"Optional accessibility label\"},role:{type:ControlType.String,title:\"ARIA Role\",defaultValue:\"\",placeholder:\"e.g., heading, article\"},font:{type:ControlType.Font,title:\"Font\",defaultValue:{fontSize:\"32px\",variant:\"Semibold\",letterSpacing:\"-0.03em\",lineHeight:\"1.2em\"},controls:\"extended\",defaultFontType:\"sans-serif\"},inactiveColor:{type:ControlType.Color,title:\"Inactive Color\",defaultValue:\"#CCCCCC\"},activeColor:{type:ControlType.Color,title:\"Active Color\",defaultValue:\"#000000\"},scrollTrigger:{type:ControlType.Enum,title:\"Trigger Point\",options:[\"top\",\"center\",\"bottom\"],optionTitles:[\"Top\",\"Center\",\"Bottom\"],defaultValue:\"center\",displaySegmentedControl:true},scrollOffset:{type:ControlType.Number,title:\"Scroll Offset\",defaultValue:0,min:-500,max:500,step:10,unit:\"px\"},scrollRange:{type:ControlType.Number,title:\"Scroll Range\",defaultValue:400,min:100,max:2e3,step:50,unit:\"px\"},animationDuration:{type:ControlType.Number,title:\"Animation Duration\",defaultValue:300,min:100,max:2e3,step:100,unit:\"ms\"}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"ScrollHighlightText\",\"slots\":[],\"annotations\":{\"framerIntrinsicWidth\":\"400\",\"framerContractVersion\":\"1\",\"framerSupportedLayoutWidth\":\"any-prefer-fixed\",\"framerIntrinsicHeight\":\"100\",\"framerSupportedLayoutHeight\":\"auto\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./ScrollHighlightText.map"],"mappings":"uPAWG,SAAwB,EAAoB,EAAM,CAAC,GAAK,CAAC,OAAK,OAAK,gBAAc,cAAY,gBAAc,eAAa,oBAAkB,cAAY,YAAU,OAAK,cAAY,SAAO,EAAY,EAAaA,EAAO,IAAI,EAAO,CAAC,EAAe,GAAmBC,EAAS,CAAC,EAAO,CAAC,EAAc,GAAkBA,EAAS,EAAK,EAAQ,EAAS,EAAU,EAAa,CAAC,KAAK,GAAK,OAAO,CAAC,CAAC,EAAE,MAAc,CAAI,GAAU,CAAC,GAAe,MAAoB,CAAC,EAAiB,EAAI,CAAE,CAAC,CAAG,EAAE,CAAC,EAAS,CAAa,CAAC,EAAE,MAAc,CAAC,GAAU,IAAS,QAAa,CAAC,EAAc,OAAO,IAAM,MAAiB,CAAC,GAAG,CAAC,EAAa,QAAQ,OAAO,IAAM,EAAK,EAAa,QAAQ,sBAAsB,EAAQ,EAAe,EAAO,YAAgB,EAAa,AAAu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