{"version":3,"file":"NumberCounter.DPsA1rdD.mjs","names":["useRef","useState","decimals"],"sources":["https:/framerusercontent.com/modules/6PZ0C5Gk1SX8M0QsvQiE/aQSya34yqXDfHPU5Pr1U/NumberCounter.js"],"sourcesContent":["// Number counter with controls for size, speed, and captions\nimport{jsx as _jsx,jsxs as _jsxs}from\"react/jsx-runtime\";import{useEffect,useState,useRef,startTransition}from\"react\";import{addPropertyControls,ControlType}from\"framer\";import{useInView,useMotionValue,useSpring}from\"framer-motion\";/**\n * @framerSupportedLayoutWidth auto\n * @framerSupportedLayoutHeight auto\n */export default function NumberCounter(props){const{targetNumber,duration,prefix,suffix,caption,numberColor,captionColor,numberFont,captionFont,decimals,separator,numberFontWeight,numberFontStyle,captionFontWeight,captionFontStyle,numberSize,captionSize}=props;const ref=useRef(null);const isInView=useInView(ref,{once:true});const motionValue=useMotionValue(0);const springValue=useSpring(motionValue,{duration:duration*1e3,bounce:0});const[displayValue,setDisplayValue]=useState(\"0\");useEffect(()=>{if(isInView){motionValue.set(targetNumber);}},[isInView,targetNumber,motionValue]);useEffect(()=>{const unsubscribe=springValue.on(\"change\",latest=>{const formatted=formatNumber(latest,decimals,separator);startTransition(()=>setDisplayValue(formatted));});return()=>unsubscribe();},[springValue,decimals,separator]);function formatNumber(num,decimals,useSeparator){const fixed=num.toFixed(decimals);if(!useSeparator)return fixed;const parts=fixed.split(\".\");parts[0]=parts[0].replace(/\\B(?=(\\d{3})+(?!\\d))/g,\",\");return parts.join(\".\");}const isFixedWidth=props?.style&&props.style.width===\"100%\";const isFixedHeight=props?.style&&props.style.height===\"100%\";return /*#__PURE__*/_jsxs(\"div\",{ref:ref,style:{...props.style,position:\"relative\",display:\"flex\",flexDirection:\"column\",alignItems:\"center\",justifyContent:\"center\",gap:8,...isFixedWidth?{}:{width:\"max-content\"},...isFixedHeight?{}:{height:\"max-content\"}},children:[/*#__PURE__*/_jsxs(\"div\",{style:{display:\"flex\",alignItems:\"center\",color:numberColor,...numberFont,fontSize:`calc(${numberFont.fontSize} * ${numberSize})`,fontFamily:\"Inter, sans-serif\",fontWeight:numberFontWeight===\"bold\"?700:400,fontStyle:numberFontStyle,whiteSpace:\"nowrap\"},children:[prefix&&/*#__PURE__*/_jsx(\"span\",{style:{marginRight:4},children:prefix}),/*#__PURE__*/_jsx(\"span\",{children:displayValue}),suffix&&/*#__PURE__*/_jsx(\"span\",{style:{marginLeft:4},children:suffix})]}),caption&&/*#__PURE__*/_jsx(\"div\",{style:{color:captionColor,...captionFont,fontSize:`calc(${captionFont.fontSize} * ${captionSize})`,fontFamily:\"Inter, sans-serif\",fontWeight:captionFontWeight===\"bold\"?700:400,fontStyle:captionFontStyle,textAlign:\"center\"},children:caption})]});}addPropertyControls(NumberCounter,{targetNumber:{type:ControlType.Number,title:\"Target Number\",defaultValue:1e3,min:0,step:.1},duration:{type:ControlType.Number,title:\"Duration\",defaultValue:2,min:.1,max:10,step:.1,unit:\"s\"},decimals:{type:ControlType.Number,title:\"Decimals\",defaultValue:0,min:0,max:4,step:1,displayStepper:true},separator:{type:ControlType.Boolean,title:\"Separator\",defaultValue:true,enabledTitle:\"On\",disabledTitle:\"Off\"},prefix:{type:ControlType.String,title:\"Prefix\",defaultValue:\"\",placeholder:\"$\"},suffix:{type:ControlType.String,title:\"Suffix\",defaultValue:\"+\",placeholder:\"%\"},caption:{type:ControlType.String,title:\"Caption\",defaultValue:\"Happy Customers\",displayTextArea:true},numberSize:{type:ControlType.Number,title:\"Number Size\",defaultValue:1,min:.1,max:5,step:.1},captionSize:{type:ControlType.Number,title:\"Caption Size\",defaultValue:1,min:.1,max:5,step:.1},numberColor:{type:ControlType.Color,title:\"Number Color\",defaultValue:\"#000000\"},numberFontWeight:{type:ControlType.Enum,title:\"Number Weight\",options:[\"regular\",\"bold\"],optionTitles:[\"Regular\",\"Bold\"],defaultValue:\"bold\",displaySegmentedControl:true},numberFontStyle:{type:ControlType.Enum,title:\"Number Style\",options:[\"normal\",\"italic\"],optionTitles:[\"Normal\",\"Italic\"],defaultValue:\"normal\",displaySegmentedControl:true},captionColor:{type:ControlType.Color,title:\"Caption Color\",defaultValue:\"#CCCCCC\"},captionFontWeight:{type:ControlType.Enum,title:\"Caption Weight\",options:[\"regular\",\"bold\"],optionTitles:[\"Regular\",\"Bold\"],defaultValue:\"regular\",displaySegmentedControl:true},captionFontStyle:{type:ControlType.Enum,title:\"Caption Style\",options:[\"normal\",\"italic\"],optionTitles:[\"Normal\",\"Italic\"],defaultValue:\"normal\",displaySegmentedControl:true},numberFont:{type:ControlType.Font,title:\"Number Font\",defaultValue:{fontSize:\"40px\",letterSpacing:\"-0.04em\",lineHeight:\"1em\"},controls:\"extended\",defaultFontType:\"sans-serif\"},captionFont:{type:ControlType.Font,title:\"Caption Font\",defaultValue:{fontSize:\"15px\",letterSpacing:\"-0.01em\",lineHeight:\"1.3em\"},controls:\"extended\",defaultFontType:\"sans-serif\"}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"NumberCounter\",\"slots\":[],\"annotations\":{\"framerSupportedLayoutWidth\":\"auto\",\"framerContractVersion\":\"1\",\"framerSupportedLayoutHeight\":\"auto\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./NumberCounter.map"],"mappings":"qQAIG,SAAwB,EAAc,EAAM,CAAC,GAAK,CAAC,eAAa,WAAS,SAAO,SAAO,UAAQ,cAAY,eAAa,aAAW,cAAY,WAAS,YAAU,mBAAiB,kBAAgB,oBAAkB,mBAAiB,aAAW,eAAa,EAAY,EAAIA,EAAO,KAAK,CAAO,EAAS,EAAU,EAAI,CAAC,KAAK,GAAK,CAAC,CAAO,EAAY,EAAe,EAAE,CAAO,EAAY,EAAU,EAAY,CAAC,SAAS,EAAS,IAAI,OAAO,EAAE,CAAC,CAAM,CAAC,EAAa,GAAiBC,EAAS,IAAI,CAAC,MAAc,CAAI,GAAU,EAAY,IAAI,EAAa,EAAI,CAAC,EAAS,EAAa,EAAY,CA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