{"version":3,"file":"SingleLineFitOverride.CZ447UmE.mjs","names":["useRef","useState","useCallback","useMemo"],"sources":["https:/framerusercontent.com/modules/uolMzctJxICygw9kZ7zT/O9lAYhqjmK4qVBvSdAiL/SingleLineFitOverride.js"],"sourcesContent":["// User request: Create code OVERRIDE export withSingleLineFit for an existing Framer canvas RichText title. Keep canvas content CMS binding typography and structure intact. Need continuous responsive fit to container width, never wrap, preserve descenders. Existing font Instrument Serif normal 400, desktop cap112px tablet80 phone56 (read computed original font as cap per current responsive styles). Existing width1fr heightauto. Override should wrap existing component HOC, forward/merge refs safely, observe available width via ResizeObserver and content changes and fonts ready, measure intrinsic unwrapped text width and scale font-size down as necessary, apply to rich text paragraph/heading descendants where Framer explicit sizes otherwise defeat inheritance. nowrap and line-height1.1 with overflow visible. Avoid observer loops and don't progressively use previously shrunk font as cap. Honor responsive max fonts on breakpoint changes. SSR safe, cleanup. No new widget/component, just override; return export id. Inspect existing code patterns/dependencies first.\nimport{jsx as _jsx}from\"react/jsx-runtime\";import{forwardRef,startTransition,useCallback,useEffect,useMemo,useRef,useState}from\"react\";function assignRef(ref,value){if(!ref)return;if(typeof ref===\"function\"){ref(value);return;}ref.current=value;}export function withSingleLineFit(Component){return /*#__PURE__*/forwardRef(function WithSingleLineFit(props,forwardedRef){const WrappedComponent=Component;const wrappedRef=useRef(null);const frameRef=useRef(null);const[targetVersion,setTargetVersion]=useState(0);const baseInlineFontSizeRef=useRef(new WeakMap);const getTextNodes=useCallback(targetRoot=>{const matches=Array.from(targetRoot.querySelectorAll(\"h1,h2,h3,h4,h5,h6,p\"));const tag=targetRoot.tagName.toLowerCase();if(tag===\"p\"||/^h[1-6]$/.test(tag))matches.unshift(targetRoot);const unique=[];const seen=new Set;for(const node of matches){if(!seen.has(node)){unique.push(node);seen.add(node);}}return unique;},[]);const measureIntrinsicWidth=useCallback(node=>{if(typeof window===\"undefined\"||typeof document===\"undefined\")return 0;const range=document.createRange();range.selectNodeContents(node);const rect=range.getBoundingClientRect();const fromRange=rect.width;if(Number.isFinite(fromRange)&&fromRange>0)return fromRange;const clone=node.cloneNode(true);clone.style.position=\"absolute\";clone.style.left=\"-99999px\";clone.style.top=\"0\";clone.style.width=\"max-content\";clone.style.maxWidth=\"none\";clone.style.whiteSpace=\"nowrap\";clone.style.visibility=\"hidden\";clone.style.pointerEvents=\"none\";document.body.appendChild(clone);const fallback=clone.getBoundingClientRect().width;clone.remove();return Number.isFinite(fallback)?fallback:0;},[]);const scheduleFit=useCallback(()=>{if(typeof window===\"undefined\")return;if(frameRef.current!==null)window.cancelAnimationFrame(frameRef.current);frameRef.current=window.requestAnimationFrame(()=>{frameRef.current=null;const targetRoot=wrappedRef.current;if(!targetRoot)return;const availableWidth=targetRoot.clientWidth;if(!availableWidth||!Number.isFinite(availableWidth))return;const textNodes=getTextNodes(targetRoot);if(textNodes.length===0)return;const baseSizes=textNodes.map(node=>{if(!baseInlineFontSizeRef.current.has(node)){baseInlineFontSizeRef.current.set(node,node.style.fontSize||\"\");}node.style.setProperty(\"font-size\",baseInlineFontSizeRef.current.get(node)??\"\",\"\");const computed=parseFloat(window.getComputedStyle(node).fontSize||\"0\");return Number.isFinite(computed)&&computed>0?computed:1;});textNodes.forEach((node,index)=>{node.style.setProperty(\"white-space\",\"nowrap\",\"important\");node.style.setProperty(\"line-height\",\"1.1\",\"important\");node.style.setProperty(\"overflow\",\"visible\",\"important\");node.style.setProperty(\"max-width\",\"none\",\"important\");node.style.setProperty(\"font-size\",`${baseSizes[index]}px`,\"important\");});const intrinsicWidth=textNodes.reduce((maxWidth,node)=>{const width=measureIntrinsicWidth(node);return Math.max(maxWidth,width);},0);if(!intrinsicWidth||!Number.isFinite(intrinsicWidth))return;const safety=2;const scale=Math.min(1,Math.max(.01,(availableWidth-safety)/(intrinsicWidth+safety)));textNodes.forEach((node,index)=>{const nextSize=Math.max(1,baseSizes[index]*scale);node.style.setProperty(\"font-size\",`${nextSize}px`,\"important\");});});},[getTextNodes,measureIntrinsicWidth]);const mergedWrappedRef=useMemo(()=>node=>{wrappedRef.current=node;assignRef(forwardedRef,node);startTransition(()=>{setTargetVersion(value=>value+1);});},[forwardedRef]);useEffect(()=>{if(typeof window===\"undefined\")return;const targetRoot=wrappedRef.current;if(!targetRoot)return;scheduleFit();const resizeObserver=typeof ResizeObserver!==\"undefined\"?new ResizeObserver(()=>{scheduleFit();}):null;resizeObserver?.observe(targetRoot);const mutationObserver=typeof MutationObserver!==\"undefined\"?new MutationObserver(()=>{scheduleFit();}):null;mutationObserver?.observe(targetRoot,{childList:true,characterData:true,subtree:true});const onWindowResize=()=>scheduleFit();window.addEventListener(\"resize\",onWindowResize);const fonts=typeof document!==\"undefined\"?document.fonts:null;const onFontsReady=()=>scheduleFit();if(fonts?.ready?.then)fonts.ready.then(onFontsReady).catch(()=>null);if(fonts?.addEventListener)fonts.addEventListener(\"loadingdone\",onFontsReady);return()=>{resizeObserver?.disconnect();mutationObserver?.disconnect();window.removeEventListener(\"resize\",onWindowResize);if(fonts?.removeEventListener)fonts.removeEventListener(\"loadingdone\",onFontsReady);if(frameRef.current!==null){window.cancelAnimationFrame(frameRef.current);frameRef.current=null;}};},[scheduleFit,targetVersion]);return /*#__PURE__*/_jsx(WrappedComponent,{...props,ref:mergedWrappedRef,style:{...props.style,whiteSpace:\"nowrap\",overflow:\"visible\"}});});}\nexport const __FramerMetadata__ = {\"exports\":{\"withSingleLineFit\":{\"type\":\"reactHoc\",\"name\":\"withSingleLineFit\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./SingleLineFitOverride.map"],"mappings":"0KACuI,SAAS,EAAU,EAAI,EAAM,CAAK,KAAW,IAAG,OAAO,GAAM,WAAW,CAAC,EAAI,CAAK,EAAE,MAAO,CAAC,EAAI,QAAQ,CAAb,CAAmB,CAAC,SAAgB,EAAkB,EAAU,CAAC,OAAoB,EAAW,SAA2B,EAAM,EAAa,CAAC,IAAM,EAAiB,EAA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