{"version":3,"file":"text_reveal_scroll_helper.DW2dSsGo.mjs","names":["React.useRef","React.useState"],"sources":["https:/framerusercontent.com/modules/xDgp5el32fHNjPkyEMsb/LirnDto51pVA3JgXzXlM/text_reveal_scroll_helper.js"],"sourcesContent":["import{jsx as _jsx,jsxs as _jsxs}from\"react/jsx-runtime\";import*as React from\"react\";import{addPropertyControls,ControlType,RenderTarget}from\"framer\";// ─── Sibling DOM Traversal ────────────────────────────────────────────────────\nfunction findTargetEl(overlayRef){if(!overlayRef.current)return null;let node=overlayRef.current;while(node){const parent=node.parentElement;if(!parent)break;const siblings=Array.from(parent.children);const selfIndex=siblings.indexOf(node);for(let i=0;i<siblings.length;i++){if(i===selfIndex)continue;const found=siblings[i].classList.contains(\"framer-text\")?siblings[i]:siblings[i].querySelector(\".framer-text\");if(found)return found;}node=parent;}return null;}// ─── MODE: Characters ─────────────────────────────────────────────────────────\n// Wraps every character in display:inline span — preserves all CSS variables\nfunction wrapChars(el,dimOpacity){const spans=[];function walk(node){if(node.nodeType===Node.TEXT_NODE){const text=node.textContent||\"\";if(!text)return;const frag=document.createDocumentFragment();for(const char of text){const span=document.createElement(\"span\");span.textContent=char;// display:inline preserves letter-spacing & font CSS variables\n// display:inline-block creates a box model that breaks spacing\nspan.style.cssText=`display:inline;opacity:${dimOpacity};will-change:opacity;`;spans.push(span);frag.appendChild(span);}node.parentNode?.replaceChild(frag,node);}else if(node.nodeType===Node.ELEMENT_NODE){// Clone childNodes before iterating — we mutate during walk\nArray.from(node.childNodes).forEach(walk);}}walk(el);return spans;}// ─── MODE: Words ──────────────────────────────────────────────────────────────\n// Splits on whitespace, wraps each word in display:inline span.\n// Spaces are re-inserted as plain text nodes so layout is unaffected.\nfunction wrapWords(el,dimOpacity){const spans=[];const walker=document.createTreeWalker(el,NodeFilter.SHOW_TEXT);const textNodes=[];let n;while(n=walker.nextNode()){const t=n;if(t.textContent?.trim())textNodes.push(t);}textNodes.forEach(textNode=>{const raw=textNode.textContent||\"\";// Split keeping whitespace tokens so we can restore spaces\nconst tokens=raw.split(/(\\s+)/);const frag=document.createDocumentFragment();tokens.forEach(token=>{if(!token)return;if(/^\\s+$/.test(token)){// Preserve spaces as plain text — never wrap whitespace\nfrag.appendChild(document.createTextNode(token));return;}const span=document.createElement(\"span\");span.textContent=token;span.style.cssText=`display:inline;opacity:${dimOpacity};will-change:opacity;`;spans.push(span);frag.appendChild(span);});textNode.parentNode?.replaceChild(frag,textNode);});return spans;}/**\n * @framerDisableUnlink\n * @framerIntrinsicWidth 140\n * @framerIntrinsicHeight 24\n * @framerSupportedLayoutWidth any\n * @framerSupportedLayoutHeight any\n */export default function TextRevealScroll({revealMode=\"chars\",startOffset=90,endOffset=30,dimOpacity=.2,showCanvas=true,style}){const overlayRef=React.useRef(null);const segmentsRef=React.useRef([]);const splitDoneRef=React.useRef(false);// Refs keep scroll closure values fresh without re-registering the listener\nconst startOffsetRef=React.useRef(startOffset);const endOffsetRef=React.useRef(endOffset);const dimOpacityRef=React.useRef(dimOpacity);const revealModeRef=React.useRef(revealMode);startOffsetRef.current=startOffset;endOffsetRef.current=endOffset;dimOpacityRef.current=dimOpacity;revealModeRef.current=revealMode;const isCanvas=RenderTarget.current()===RenderTarget.canvas;// Two-phase render guard — never access DOM during SSR\nconst[isClient,setIsClient]=React.useState(false);React.useEffect(()=>setIsClient(true),[]);// Reset split when mode changes so segments are rebuilt cleanly\nReact.useEffect(()=>{splitDoneRef.current=false;segmentsRef.current=[];},[revealMode]);React.useEffect(()=>{if(!isClient||isCanvas)return;const initTimer=setTimeout(()=>{if(splitDoneRef.current)return;const textElement=findTargetEl(overlayRef);if(!textElement)return;// Dispatch to the correct wrap function based on mode\nconst segments=revealModeRef.current===\"words\"?wrapWords(textElement,dimOpacityRef.current):wrapChars(textElement,dimOpacityRef.current);if(segments.length===0)return;segmentsRef.current=segments;splitDoneRef.current=true;// ── Scroll-scrub reveal ───────────────────────────────────────────\nconst updateReveal=()=>{const el=findTargetEl(overlayRef);if(!el)return;const rect=el.getBoundingClientRect();const vh=window.innerHeight;const startPx=vh*(startOffsetRef.current/100);const endPx=vh*(endOffsetRef.current/100);// totalRange accounts for element height so long blocks\n// continue revealing as the user scrolls through them\nconst totalRange=rect.height+(startPx-endPx);const scrolled=startPx-rect.top;const progress=Math.min(Math.max(scrolled/totalRange,0),1);const total=segmentsRef.current.length;const litCount=Math.floor(progress*total);segmentsRef.current.forEach((seg,i)=>{if(i<litCount){seg.style.opacity=\"1\";}else if(i===litCount){// Fractional fade on the frontier segment for smooth feel\nconst frac=progress*total-litCount;seg.style.opacity=String(dimOpacityRef.current+frac*(1-dimOpacityRef.current));}else{seg.style.opacity=String(dimOpacityRef.current);}});};updateReveal();window.addEventListener(\"scroll\",updateReveal,{passive:true});window.addEventListener(\"resize\",updateReveal,{passive:true});// MutationObserver handles late-rendering CMS content\nconst observer=new MutationObserver(updateReveal);observer.observe(document.body,{childList:true,subtree:true});return()=>{window.removeEventListener(\"scroll\",updateReveal);window.removeEventListener(\"resize\",updateReveal);observer.disconnect();};},150);return()=>clearTimeout(initTimer);},[isClient,isCanvas,revealMode]);// ── Canvas placeholder ────────────────────────────────────────────────────\nif(isCanvas){if(!showCanvas)return /*#__PURE__*/_jsx(\"div\",{style:{width:\"100%\",height:\"100%\"}});const modeLabel=revealMode===\"words\"?\"Words\":\"Chars\";return /*#__PURE__*/_jsx(\"div\",{style:{width:\"140px\",height:\"24px\",display:\"flex\",alignItems:\"center\",justifyContent:\"center\",background:\"rgba(99,102,241,0.08)\",border:\"1.5px dashed rgba(99,102,241,0.5)\",borderRadius:6,color:\"rgba(99,102,241,0.8)\",fontFamily:\"monospace\",pointerEvents:\"none\",userSelect:\"none\",padding:\"4px 2px\",overflow:\"hidden\",letterSpacing:\"-0.06em\"},children:/*#__PURE__*/_jsxs(\"span\",{style:{fontSize:11},children:[\"✦ Text Reveal \\xb7 \",modeLabel]})});}// ── Live overlay — invisible, covers sibling text ─────────────────────────\nreturn /*#__PURE__*/_jsx(\"div\",{ref:overlayRef,style:{position:\"absolute\",inset:0,pointerEvents:\"none\",background:\"transparent\"}});}TextRevealScroll.displayName=\"Text Reveal Scroll - Helper\";addPropertyControls(TextRevealScroll,{revealMode:{type:ControlType.Enum,title:\"Reveal By\",defaultValue:\"chars\",options:[\"chars\",\"words\"],optionTitles:[\"Characters\",\"Words\"],displaySegmentedControl:true,segmentedControlDirection:\"vertical\",description:\"Reveal text character by character or word by word.\"},startOffset:{type:ControlType.Number,title:\"Start %\",defaultValue:90,min:0,max:100,step:1,unit:\"%\",description:\"Viewport % from top where reveal begins.\"},endOffset:{type:ControlType.Number,title:\"End %\",defaultValue:30,min:0,max:100,step:1,unit:\"%\",description:\"Viewport % from top where reveal completes.\"},dimOpacity:{type:ControlType.Number,title:\"Dim Opacity\",defaultValue:.2,min:0,max:1,step:.05,description:\"Opacity of unrevealed segments.\"},showCanvas:{type:ControlType.Boolean,title:\"Canvas Preview\",defaultValue:true,enabledTitle:\"Visible\",disabledTitle:\"Hidden\",description:\"Show or hide the component placeholder on the canvas.\\n\\nMade with ❤️ by [Soyeb](https://framer.link/project)\\n*Version:* 1.0.0\"}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"TextRevealScroll\",\"slots\":[],\"annotations\":{\"framerDisableUnlink\":\"* @framerIntrinsicWidth 140\",\"framerSupportedLayoutWidth\":\"any\",\"framerIntrinsicHeight\":\"24\",\"framerContractVersion\":\"1\",\"framerSupportedLayoutHeight\":\"any\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./text_reveal_scroll_helper.map"],"mappings":"oNACA,SAAS,EAAa,EAAW,CAAC,GAAG,CAAC,EAAW,QAAQ,OAAO,KAAK,IAAI,EAAK,EAAW,QAAQ,KAAM,GAAK,CAAC,IAAM,EAAO,EAAK,cAAc,GAAG,CAAC,EAAO,MAAM,IAAM,EAAS,MAAM,KAAK,EAAO,QAAQ,EAAQ,EAAU,EAAS,QAAQ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