{"version":3,"file":"FitTextPro.BNJmc4jd.mjs","names":["useRef","useState"],"sources":["https:/framerusercontent.com/modules/GJuXhTka0conlKJYcO1E/Q4IAp6W8weU8z4h5m1ry/FitTextPro.js"],"sourcesContent":["// Text component with \"fit\" font size that scales to container and supports variable content\nimport{jsx as _jsx}from\"react/jsx-runtime\";import{addPropertyControls,ControlType}from\"framer\";import{useEffect,useRef,useState,startTransition}from\"react\";/**\n * @framerSupportedLayoutWidth fixed\n * @framerSupportedLayoutHeight any\n */export default function FitTextPro(props){const{text,textColor,font,letterSpacing,lineHeight,textAlign}=props;const containerRef=useRef(null);const textRef=useRef(null);const[fontSize,setFontSize]=useState(100);useEffect(()=>{const fitText=()=>{if(!containerRef.current||!textRef.current)return;const container=containerRef.current;const textElement=textRef.current;const containerWidth=container.clientWidth;// Ensure we have valid dimensions\nif(containerWidth<=0)return;let low=8// Minimum font size to prevent 1px issues\n;let high=1e3;let bestFit=8;let iterations=0;const maxIterations=30;while(low<=high&&iterations<maxIterations){iterations++;const mid=Math.floor((low+high)/2);textElement.style.fontSize=`${mid}px`;const textWidth=textElement.scrollWidth;// Only constrain by width, let height grow naturally\nif(textWidth<=containerWidth){bestFit=mid;low=mid+1;}else{high=mid-1;}}startTransition(()=>setFontSize(bestFit));};fitText();if(typeof window!==\"undefined\"){const resizeObserver=new ResizeObserver(()=>{fitText();});if(containerRef.current){resizeObserver.observe(containerRef.current);}return()=>{resizeObserver.disconnect();};}},[text,font,letterSpacing,lineHeight]);return /*#__PURE__*/_jsx(\"div\",{ref:containerRef,style:{width:\"100%\",height:\"100%\",display:\"flex\",alignItems:\"flex-start\",justifyContent:textAlign===\"left\"?\"flex-start\":textAlign===\"right\"?\"flex-end\":\"center\",overflow:\"visible\",position:\"relative\"},children:/*#__PURE__*/_jsx(\"div\",{ref:textRef,style:{fontSize:`${fontSize}px`,color:textColor,fontFamily:font?.fontFamily,fontWeight:font?.fontWeight,fontStyle:font?.fontStyle,letterSpacing:letterSpacing,lineHeight:lineHeight,textAlign:textAlign,whiteSpace:\"nowrap\",wordBreak:\"break-word\",maxWidth:\"100%\",position:\"relative\",visibility:\"visible\"},children:text})});}addPropertyControls(FitTextPro,{text:{type:ControlType.String,title:\"Text\",defaultValue:\"Fit Text Pro\",displayTextArea:true},textColor:{type:ControlType.Color,title:\"Color\",defaultValue:\"#000000\"},font:{type:ControlType.Font,title:\"Font\",controls:\"extended\",defaultFontType:\"sans-serif\",defaultValue:{variant:\"Bold\"}},letterSpacing:{type:ControlType.String,title:\"Letter Spacing\",defaultValue:\"-0.02em\"},lineHeight:{type:ControlType.String,title:\"Line Height\",defaultValue:\"1em\"},textAlign:{type:ControlType.Enum,title:\"Align\",options:[\"left\",\"center\",\"right\"],optionTitles:[\"Left\",\"Center\",\"Right\"],defaultValue:\"center\",displaySegmentedControl:true,description:\"Made by [Mo](https://framer.com/%40mogy-studio) at [Mogy Studio](https://mogy.studio)\"}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"FitTextPro\",\"slots\":[],\"annotations\":{\"framerSupportedLayoutWidth\":\"fixed\",\"framerSupportedLayoutHeight\":\"any\",\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./FitTextPro.map"],"mappings":"6MAIG,SAAwB,EAAW,EAAM,CAAC,GAAK,CAAC,OAAK,YAAU,OAAK,gBAAc,aAAW,aAAW,EAAY,EAAaA,EAAO,KAAK,CAAO,EAAQA,EAAO,KAAK,CAAM,CAAC,EAAS,GAAaC,EAAS,IAAI,CAG2J,OAH1J,MAAc,CAAC,IAAM,MAAY,CAAC,GAAG,CAAC,EAAa,SAAS,CAAC,EAAQ,QAAQ,OAAO,IAAM,EAAU,EAAa,QAAc,EAAY,EAAQ,QAAc,EAAe,EAAU,YAChZ,GAAG,GAAgB,EAAE,OAAO,IAAI,EAAI,EAC/B,EAAK,IAAQ,EAAQ,EAAM,EAAW,EAAyB,KAAM,GAAK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