{"version":3,"file":"Counter.DJBUpcEx.mjs","names":["useRef"],"sources":["https:/framerusercontent.com/modules/vPX5aHEYmYVkHyIVREAU/e9M0C0K34Q3kKU46KWxj/Counter.js"],"sourcesContent":["// Number Counter Component with animated counting effect\nimport{jsx as _jsx,jsxs as _jsxs}from\"react/jsx-runtime\";import{useEffect,useRef,startTransition}from\"react\";import{useInView,useMotionValue,useSpring}from\"framer-motion\";import{addPropertyControls,ControlType,useIsStaticRenderer}from\"framer\";/**\n * @framerSupportedLayoutWidth auto\n * @framerSupportedLayoutHeight auto\n */export default function Counter(props){const{from=0,to=100,direction=\"up\",delay=0,duration=2,prefix=\"\",suffix=\"\",font,color,useSeparateColors=false,prefixColor,suffixColor}=props;const numberRef=useRef(null);const motionValue=useMotionValue(direction===\"down\"?to:from);const isStatic=useIsStaticRenderer();const damping=60+20*(1/duration);const stiffness=400*(1/duration);const springValue=useSpring(motionValue,{damping,stiffness,restDelta:.001,restSpeed:.01});const isInView=useInView(numberRef,{once:true,margin:\"0px\"});const getDecimalPlaces=num=>{const str=num.toString();if(str.includes(\".\")){const decimals=str.split(\".\")[1];if(parseInt(decimals)!==0){return decimals.length;}}return 0;};const maxDecimals=Math.max(getDecimalPlaces(from),getDecimalPlaces(to));useEffect(()=>{if(numberRef.current){const initialValue=direction===\"down\"?to:from;const formattedValue=formatNumber(initialValue);numberRef.current.textContent=formattedValue;}},[from,to,direction,maxDecimals]);useEffect(()=>{if(isStatic)return;if(isInView){const timeoutId=setTimeout(()=>{startTransition(()=>{motionValue.set(direction===\"down\"?from:to);});},delay*1e3);return()=>{clearTimeout(timeoutId);};}},[isInView,motionValue,direction,from,to,delay,isStatic]);const formatNumber=value=>{const hasDecimals=maxDecimals>0;const options={useGrouping:false,minimumFractionDigits:hasDecimals?maxDecimals:0,maximumFractionDigits:hasDecimals?maxDecimals:0};const formattedNumber=Intl.NumberFormat(\"en-US\",options).format(value);return formattedNumber;};useEffect(()=>{if(isStatic)return;const unsubscribe=springValue.on(\"change\",latest=>{if(numberRef.current){const formattedValue=formatNumber(latest);numberRef.current.textContent=formattedValue;}});return()=>unsubscribe();},[springValue,maxDecimals,isStatic]);const isFixedWidth=props?.style&&props.style.width===\"100%\";return /*#__PURE__*/_jsx(\"div\",{style:{...props.style,...isFixedWidth?{}:{minWidth:\"max-content\"},display:\"flex\",flexDirection:\"column\",alignItems:\"center\",gap:\"8px\"},children:/*#__PURE__*/_jsxs(\"span\",{style:{...font},children:[prefix&&/*#__PURE__*/_jsx(\"span\",{style:{color:useSeparateColors?prefixColor:color},children:prefix}),/*#__PURE__*/_jsx(\"span\",{ref:numberRef,style:{color}}),suffix&&/*#__PURE__*/_jsx(\"span\",{style:{color:useSeparateColors?suffixColor:color},children:suffix})]})});}addPropertyControls(Counter,{direction:{type:ControlType.Enum,title:\"Direction\",options:[\"up\",\"down\"],optionTitles:[\"Count Up\",\"Count Down\"],defaultValue:\"up\"},from:{type:ControlType.Number,title:\"From\",defaultValue:0,step:.1},to:{type:ControlType.Number,title:\"To\",defaultValue:100,step:.1},delay:{type:ControlType.Number,title:\"Delay\",defaultValue:0,min:0,max:5,step:.1,unit:\"s\"},duration:{type:ControlType.Number,title:\"Duration\",defaultValue:2,min:.1,max:10,step:.1,unit:\"s\"},prefix:{type:ControlType.String,title:\"Prefix\",defaultValue:\"\",placeholder:\"e.g. $\"},suffix:{type:ControlType.String,title:\"Suffix\",defaultValue:\"\",placeholder:\"e.g. %\"},color:{type:ControlType.Color,title:\"Text Color\",defaultValue:\"#000000\"},useSeparateColors:{type:ControlType.Boolean,title:\"Separate Colors\",defaultValue:false,enabledTitle:\"Custom\",disabledTitle:\"Same\"},prefixColor:{type:ControlType.Color,title:\"Prefix Color\",defaultValue:\"#000000\",hidden:({useSeparateColors})=>!useSeparateColors},suffixColor:{type:ControlType.Color,title:\"Suffix Color\",defaultValue:\"#000000\",hidden:({useSeparateColors})=>!useSeparateColors},font:{type:ControlType.Font,title:\"Font\",defaultValue:{fontSize:\"32px\",variant:\"Bold\",letterSpacing:\"-0.03em\",lineHeight:\"1em\"},controls:\"extended\",defaultFontType:\"sans-serif\"}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"Counter\",\"slots\":[],\"annotations\":{\"framerSupportedLayoutWidth\":\"auto\",\"framerContractVersion\":\"1\",\"framerSupportedLayoutHeight\":\"auto\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./Counter.map"],"mappings":"uQAIG,SAAwB,EAAQ,EAAM,CAAC,GAAK,CAAC,OAAK,EAAE,KAAG,IAAI,YAAU,KAAK,QAAM,EAAE,WAAS,EAAE,SAAO,GAAG,SAAO,GAAG,OAAK,QAAM,oBAAkB,GAAM,cAAY,eAAa,EAAY,EAAUA,EAAO,KAAK,CAAO,EAAY,EAAe,IAAY,OAAO,EAAG,EAAK,CAAO,EAAS,GAAqB,CAAyE,EAAY,EAAU,EAAY,CAAC,QAA7F,GAAO,EAAE,EAAN,GAAkG,UAA7D,EAAE,EAAP,IAA4E,UAAU,KAAK,UAAU,IAAI,CAAC,CAAO,EAAS,EAAU,EAAU,CAAC,KAAK,GAAK,OAAO,MAAM,CAAC,CAAO,EAAiB,GAAK,CAAC,IAAM,EAAI,EAAI,UAAU,CAAC,GAAG,EAAI,SAAS,IAAI,CAAC,CAAC,IAAM,EAAS,EAAI,MAAM,IAAI,CAAC,GAAG,GAAG,SAAS,EAAS,GAAG,EAAG,OAAO,EAAS,OAAS,MAAO,IAAU,EAAY,KAAK,IAAI,EAAiB,EAAK,CAAC,EAAiB,EAAG,CAAC,CAAC,MAAc,CAAC,GAAG,EAAU,QAAQ,CAA+C,IAAM,EAAe,EAAhD,IAAY,OAAO,EAAG,EAAoD,CAAC,EAAU,QAAQ,YAAY,IAAkB,CAAC,EAAK,EAAG,EAAU,EAAY,CAAC,CAAC,MAAc,CAAI,OAAmB,EAAS,CAAC,IAAM,EAAU,eAAe,CAAC,MAAoB,CAAC,EAAY,IAA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