{"version":3,"file":"DynamicTitle.DUS2saEC.mjs","names":["useRef","useState","useLayoutEffect","useEffect"],"sources":["https:/framerusercontent.com/modules/BLQArgTOJAzxmVq0neS3/C6T2Eca1EYxUeUA4m1rn/DynamicTitle.js"],"sourcesContent":["// Title component with dynamic font size based on text length\nimport{jsx as _jsx,jsxs as _jsxs}from\"react/jsx-runtime\";import{useEffect,useLayoutEffect,useRef,useState}from\"react\";import{addPropertyControls,ControlType}from\"framer\";// Measure before paint on the client; useLayoutEffect warns during SSR.\nconst useIsomorphicLayoutEffect=typeof window!==\"undefined\"?useLayoutEffect:useEffect;// Approximate glyph width in em for bold uppercase text. Only drives the\n// CSS-only size shown before hydration; the real size is measured.\nconst CHAR_WIDTH_RATIO=.68;/**\n * @framerSupportedLayoutWidth any-prefer-fixed\n * @framerSupportedLayoutHeight any-prefer-fixed\n */export default function DynamicTitle(props){// Semantic tag for the visible text. span (default) keeps the old\n// behaviour; h1/h2 lets a page use the big title as its real heading.\nconst Tag=props.tag??\"span\";const{text=\"Dynamic Title\",textColor=\"#000000\",font,breakLongWords=true,textAlign=\"center\",style}=props;const containerRef=useRef(null);const measureRef=useRef(null);const[fontSize,setFontSize]=useState(null);const breakLines=breakLongWords&&text.length>15;const words=text.split(/\\s+/).filter(Boolean);// The widest thing that must fit: the whole string on one line, or the\n// longest word when wrapping (line breaking never splits a word).\nconst longestUnit=breakLines?words.reduce((a,b)=>b.length>a.length?b:a,\"\"):text;// One word per line so the measurer's width is the widest word's width,\n// regardless of which word has the most characters.\nconst measureText=breakLines?words.join(\"\\n\"):text;// Pre-hydration size: scales with the container via cqw, so server-rendered\n// HTML paints near the final size instead of at the 1000px probe size.\nconst estimatedFontSize=`${(100/(Math.max(longestUnit.length,1)*CHAR_WIDTH_RATIO)).toFixed(3)}cqw`;useIsomorphicLayoutEffect(()=>{const container=containerRef.current;const measurer=measureRef.current;if(!container||!measurer)return;const fit=()=>{const containerWidth=container.offsetWidth;if(!containerWidth)return;measurer.style.fontSize=\"100px\";const measuredWidth=measurer.getBoundingClientRect().width;if(!measuredWidth)return;let size=Math.max(1,Math.floor(100*containerWidth/measuredWidth));measurer.style.fontSize=`${size}px`;while(size>1&&measurer.getBoundingClientRect().width>containerWidth){size-=1;measurer.style.fontSize=`${size}px`;}setFontSize(size);};fit();const resizeObserver=new ResizeObserver(fit);resizeObserver.observe(container);// Fallback fonts measure differently; re-fit once webfonts are in.\nlet cancelled=false;if(typeof document!==\"undefined\"&&document.fonts?.ready){document.fonts.ready.then(()=>{if(!cancelled)fit();});}return()=>{cancelled=true;resizeObserver.disconnect();};},[text,breakLines,JSON.stringify(font??{})]);return /*#__PURE__*/_jsxs(\"div\",{ref:containerRef,style:{...style,position:\"relative\",width:\"100%\",display:\"flex\",alignItems:\"flex-end\",justifyContent:textAlign===\"left\"?\"flex-start\":textAlign===\"right\"?\"flex-end\":\"center\",overflow:\"hidden\",// containerType is missing from Framer's bundled CSS types\n...{containerType:\"inline-size\"}},children:[/*#__PURE__*/_jsx(Tag,{style:{margin:0,...font,fontSize:fontSize!==null?`${fontSize}px`:estimatedFontSize,color:textColor,whiteSpace:breakLines?\"normal\":\"nowrap\",lineHeight:1,textTransform:\"uppercase\",textAlign:textAlign,width:\"100%\"},children:text}),/*#__PURE__*/_jsx(\"span\",{ref:measureRef,\"aria-hidden\":\"true\",style:{...font,position:\"absolute\",left:0,top:0,visibility:\"hidden\",whiteSpace:breakLines?\"pre\":\"nowrap\",lineHeight:1,textTransform:\"uppercase\",pointerEvents:\"none\"},children:measureText})]});}addPropertyControls(DynamicTitle,{tag:{type:ControlType.Enum,title:\"Tag\",options:[\"span\",\"h1\",\"h2\"],optionTitles:[\"Span\",\"H1\",\"H2\"],defaultValue:\"span\"},text:{type:ControlType.String,title:\"Text\",defaultValue:\"Dynamic Title\"},breakLongWords:{type:ControlType.Boolean,title:\"Break Lines (>15 chars)\",defaultValue:true,enabledTitle:\"On\",disabledTitle:\"Off\"},textColor:{type:ControlType.Color,title:\"Text Color\",defaultValue:\"#000000\"},font:{type:ControlType.Font,title:\"Font\",controls:\"extended\",defaultFontType:\"sans-serif\",defaultValue:{variant:\"Bold\",letterSpacing:\"-0.04em\"}},textAlign:{type:ControlType.Enum,title:\"Text Align\",options:[\"left\",\"center\",\"right\"],optionTitles:[\"Left\",\"Center\",\"Right\"],defaultValue:\"center\",displaySegmentedControl:true}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"DynamicTitle\",\"slots\":[],\"annotations\":{\"framerContractVersion\":\"1\",\"framerSupportedLayoutWidth\":\"any-prefer-fixed\",\"framerSupportedLayoutHeight\":\"any-prefer-fixed\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./DynamicTitle.map"],"mappings":"oNAOG,SAAwB,EAAa,EAAM,CAE9C,IAAM,EAAI,EAAM,KAAK,OAAY,CAAC,OAAK,gBAAgB,YAAU,UAAU,OAAK,iBAAe,GAAK,YAAU,SAAS,SAAO,EAAY,EAAaA,EAAO,IAAI,EAAQ,EAAWA,EAAO,IAAI,EAAO,CAAC,EAAS,GAAaC,EAAS,IAAI,EAAQ,EAAW,GAAgB,EAAK,OAAO,GAAS,EAAM,EAAK,MAAM,KAAK,CAAC,CAAC,OAAO,OAAO,EAEnU,EAAY,EAAW,EAAM,QAAQ,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE,EAAE,EAErE,EAAY,EAAW,EAAM,KAAK;CAAI,EAAE,EAExC,EAAkB,IAAI,KAAK,KAAK,IAAI,EAAY,OAAO,CAAC,EAAE,GAAA,CAAmB,QAAQ,CAAC,EAAE,KAC4I,OADvI,MAA8B,CAAC,IAAM,EAAU,EAAa,QAAc,EAAS,EAAW,QAAQ,GAAG,CAAC,GAAW,CAAC,EAAS,OAAO,IAAM,MAAQ,CAAC,IAAM,EAAe,EAAU,YAAY,GAAG,CAAC,EAAe,OAAO,EAAS,MAAM,SAAS,QAAQ,IAAM,EAA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