{"version":3,"file":"AutoCounter.Cwe-EfM3.mjs","names":["useState","useRef","useMemo"],"sources":["https:/framerusercontent.com/modules/OiXmDncYqr3d6CyBaxmD/RqjHOfk0kvkwQsLAMeam/AutoCounter.js"],"sourcesContent":["// Counter component that animates from a start value to an end value automatically in a Framer project\nimport{jsx as _jsx}from\"react/jsx-runtime\";import{useState,useEffect,useRef,useMemo,startTransition}from\"react\";import{addPropertyControls,ControlType,useIsStaticRenderer}from\"framer\";/**\n * Auto Counter\n *\n * Animates a number from a start value to an end value automatically.\n *\n * @framerIntrinsicWidth 120\n * @framerIntrinsicHeight 40\n *\n * @framerSupportedLayoutWidth any-prefer-fixed\n * @framerSupportedLayoutHeight any-prefer-fixed\n */export default function AutoCounter(props){const{startValue,endValue,duration,decimals,prefix,suffix,color,font,autoplay,style}=props;const isStatic=useIsStaticRenderer();const[currentValue,setCurrentValue]=useState(startValue);const animationFrameRef=useRef(null);const startTimeRef=useRef(null);const resetAndSet=value=>{if(animationFrameRef.current!==null&&typeof window!==\"undefined\"){window.cancelAnimationFrame(animationFrameRef.current);animationFrameRef.current=null;}startTransition(()=>{setCurrentValue(value);});startTimeRef.current=null;};useEffect(()=>{if(!autoplay||duration<=0){resetAndSet(endValue);return;}if(isStatic||typeof window===\"undefined\"){resetAndSet(endValue);return;}resetAndSet(startValue);const totalDurationMs=duration*1e3;const start=startValue;const change=endValue-startValue;const step=timestamp=>{if(startTimeRef.current===null){startTimeRef.current=timestamp;}const elapsed=timestamp-startTimeRef.current;const t=Math.min(elapsed/totalDurationMs,1);// Ease-out quad\nconst easedT=1-(1-t)*(1-t);const value=start+change*easedT;startTransition(()=>{setCurrentValue(value);});if(t<1){animationFrameRef.current=window.requestAnimationFrame(step);}else{animationFrameRef.current=null;}};animationFrameRef.current=window.requestAnimationFrame(step);return()=>{if(animationFrameRef.current!==null&&typeof window!==\"undefined\"){window.cancelAnimationFrame(animationFrameRef.current);}animationFrameRef.current=null;startTimeRef.current=null;};},[startValue,endValue,duration,autoplay,isStatic]);const formattedValue=useMemo(()=>{const factor=Math.pow(10,Math.max(0,decimals));const rounded=Math.round(currentValue*factor)/factor;return rounded.toFixed(Math.max(0,decimals));},[currentValue,decimals]);const text=useMemo(()=>`${prefix}${formattedValue}${suffix}`,[prefix,formattedValue,suffix]);const isWidthFixed=style&&style.width===\"100%\";const isHeightFixed=style&&style.height===\"100%\";return /*#__PURE__*/_jsx(\"div\",{style:{position:\"relative\",display:\"flex\",alignItems:\"center\",justifyContent:\"flex-start\",width:\"100%\",height:\"100%\",...style},children:/*#__PURE__*/_jsx(\"span\",{style:{color,...font,display:\"inline-block\",whiteSpace:\"nowrap\",...isWidthFixed?{}:{width:\"max-content\",minWidth:\"max-content\"},...isHeightFixed?{}:{}},\"aria-live\":\"polite\",children:text})});}addPropertyControls(AutoCounter,{startValue:{type:ControlType.Number,title:\"Start\",defaultValue:0,min:-1e6,max:1e6,step:1,displayStepper:false},endValue:{type:ControlType.Number,title:\"End\",defaultValue:100,min:-1e6,max:1e6,step:1,displayStepper:false},duration:{type:ControlType.Number,title:\"Duration\",defaultValue:2,min:.1,max:20,step:.1,unit:\"s\",displayStepper:false},decimals:{type:ControlType.Number,title:\"Decimals\",defaultValue:0,min:0,max:6,step:1,displayStepper:true},prefix:{type:ControlType.String,title:\"Prefix\",defaultValue:\"\",placeholder:\"$, +, etc.\"},suffix:{type:ControlType.String,title:\"Suffix\",defaultValue:\"\",placeholder:\"%, k, etc.\"},color:{type:ControlType.Color,title:\"Color\",defaultValue:\"#000000\"},font:{type:ControlType.Font,title:\"Font\",defaultValue:{fontSize:\"32px\",variant:\"Bold\",letterSpacing:\"-0.03em\",lineHeight:\"1em\"},controls:\"extended\",defaultFontType:\"sans-serif\"},autoplay:{type:ControlType.Boolean,title:\"Autoplay\",defaultValue:true,enabledTitle:\"On\",disabledTitle:\"Off\"}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"AutoCounter\",\"slots\":[],\"annotations\":{\"framerIntrinsicWidth\":\"120\",\"framerSupportedLayoutWidth\":\"any-prefer-fixed\",\"framerIntrinsicHeight\":\"40\",\"framerContractVersion\":\"1\",\"framerSupportedLayoutHeight\":\"any-prefer-fixed\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./AutoCounter.map"],"mappings":"4NAWG,SAAwB,EAAY,EAAM,CAAC,GAAK,CAAC,aAAW,WAAS,WAAS,WAAS,SAAO,SAAO,QAAM,OAAK,WAAS,SAAO,EAAY,EAAS,GAAqB,CAAM,CAAC,EAAa,GAAiBA,EAAS,EAAW,CAAO,EAAkBC,EAAO,KAAK,CAAO,EAAaA,EAAO,KAAK,CAAO,EAAY,GAAO,CAAI,EAAkB,UAAU,MAAa,IAAS,SAAa,EAAO,qBAAqB,EAAkB,QAAQ,CAAC,EAAkB,QAAQ,MAAM,MAAoB,CAAC,EAAgB,EAAM,EAAG,CAAC,EAAa,QAAQ,MAAO,MAAc,CAAC,GAAG,CAAC,GAAU,GAAU,EAAE,CAAC,EAAY,EAAS,CAAC,OAAQ,GAAG,GAAiB,IAAS,OAAY,CAAC,EAAY,EAAS,CAAC,OAAQ,EAAY,EAAW,CAAC,IAAM,EAAgB,EAAS,IAAU,EAAM,EAAiB,EAAO,EAAS,EAAiB,EAAK,GAAW,CAAI,EAAa,UAAU,OAAM,EAAa,QAAQ,GAAW,IAAM,EAAQ,EAAU,EAAa,QAAc,EAAE,KAAK,IAAI,EAAQ,EAAgB,EAAE,CAC37B,EAAM,EAAM,GAAhC,GAAG,EAAE,IAAI,EAAE,IAAmC,MAAoB,CAAC,EAAgB,EAAM,EAAG,CAAI,EAAE,EAAG,EAAkB,QAAQ,EAAO,sBAAsB,EAAK,CAAO,EAAkB,QAAQ,MAAqE,MAA7D,GAAkB,QAAQ,EAAO,sBAAsB,EAAK,KAAW,CAAI,EAAkB,UAAU,MAAa,IAAS,QAAa,EAAO,qBAAqB,EAAkB,QAAQ,CAAE,EAAkB,QAA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