{"version":3,"file":"WordRevealScroll.BAJdn_TU.mjs","names":["useRef","useMemo","_Fragment"],"sources":["https:/framerusercontent.com/modules/840lM0qYeiCJakau2D7H/rwK8zK6y5zOlM7GXHT0V/WordRevealScroll.js"],"sourcesContent":["// Word by word text reveal on scroll\nimport{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from\"react/jsx-runtime\";import{useScroll,useTransform,motion}from\"framer-motion\";import{useRef,useMemo}from\"react\";import{addPropertyControls,ControlType}from\"framer\";/**\n * @framerSupportedLayoutWidth any\n * @framerSupportedLayoutHeight auto\n */export default function WordRevealScroll(props){const{text=\"Scroll down to reveal this text word by word as you move through the page\",font,activeColor,inactiveColor,scrollSection=\"start end, end start\"}=props;const containerRef=useRef(null);const offset=useMemo(()=>{return scrollSection.split(\",\").map(s=>s.trim());},[scrollSection]);const{scrollYProgress}=useScroll({target:containerRef,offset:offset});const words=useMemo(()=>text.split(\" \"),[text]);const{textAlign,...restFont}=font||{};// Split text into lines, then words per line\nconst lines=useMemo(()=>text.split(\"\\n\"),[text]);return /*#__PURE__*/_jsx(\"div\",{ref:containerRef,style:{...props.style,position:\"relative\",width:\"100%\",boxSizing:\"border-box\"},children:/*#__PURE__*/_jsx(\"div\",{style:{...restFont,margin:0,display:\"flex\",flexDirection:\"column\",gap:\"0.5em\",justifyContent:textAlign===\"center\"?\"center\":textAlign===\"right\"?\"flex-end\":\"flex-start\",alignItems:textAlign===\"center\"?\"center\":textAlign===\"right\"?\"flex-end\":\"flex-start\",width:\"100%\",boxSizing:\"border-box\",wordBreak:\"break-word\",textAlign:textAlign||\"left\"},children:(()=>{// Calculate total number of words for accurate progress mapping\nlet wordCount=0;const lineWordCounts=lines.map(line=>line.split(\" \").length);const totalWords=lineWordCounts.reduce((a,b)=>a+b,0);let globalWordIdx=0;return lines.map((line,lineIdx)=>{const lineWords=line.split(\" \");return /*#__PURE__*/_jsx(\"span\",{style:{display:\"inline-block\",width:\"100%\",textAlign:textAlign||\"left\"},children:lineWords.map((word,wordIdx)=>{const start=globalWordIdx/totalWords;const end=(globalWordIdx+1)/totalWords;const el=/*#__PURE__*/_jsx(Word,{word:word,progress:scrollYProgress,range:[start,end],activeColor:activeColor,inactiveColor:inactiveColor},wordIdx);globalWordIdx++;// Add a space after each word except the last in the line\nreturn /*#__PURE__*/_jsxs(_Fragment,{children:[el,wordIdx<lineWords.length-1?\" \":null]});})},lineIdx);});})()})});}function Word({word,progress,range,activeColor,inactiveColor}){const opacity=useTransform(progress,range,[.2,1]);const color=useTransform(progress,range,[inactiveColor,activeColor]);// Format word: bold if active, normal if inactive\nreturn /*#__PURE__*/_jsx(motion.span,{style:{opacity,color,fontWeight:700,transition:\"font-weight 0.2s\"},children:word});}addPropertyControls(WordRevealScroll,{text:{type:ControlType.String,title:\"Text\",defaultValue:\"Scroll down to reveal this text word by word as you move through the page\",displayTextArea:true},scrollSection:{type:ControlType.Enum,title:\"Scroll Section\",options:[\"start end, end start\",\"start start, end end\",\"start center, end center\",\"center end, center start\",\"center center, center center\"],optionTitles:[\"Full Range\",\"Viewport Entry/Exit\",\"Center Aligned\",\"Center Trigger\",\"Center Only\"],defaultValue:\"start end, end start\"},font:{type:ControlType.Font,title:\"Font\",controls:\"extended\",defaultFontType:\"sans-serif\",defaultValue:{fontSize:\"40px\",variant:\"Bold\",letterSpacing:\"-0.04em\",lineHeight:\"1.2em\"}},activeColor:{type:ControlType.Color,title:\"Active Color\",defaultValue:\"#000000\"},inactiveColor:{type:ControlType.Color,title:\"Inactive Color\",defaultValue:\"#CCCCCC\"}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"WordRevealScroll\",\"slots\":[],\"annotations\":{\"framerSupportedLayoutHeight\":\"auto\",\"framerContractVersion\":\"1\",\"framerSupportedLayoutWidth\":\"any\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./WordRevealScroll.map"],"mappings":"+PAIG,SAAwB,EAAiB,EAAM,CAAC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