{"version":3,"file":"Counter.FIIE2jVZ.mjs","names":["useState","useRef"],"sources":["https:/framerusercontent.com/modules/ykqJxSkWyKD94zFPRcbZ/7iGwaqUXfaHO80sLI4zW/Counter.js"],"sourcesContent":["import{jsx as _jsx,jsxs as _jsxs}from\"react/jsx-runtime\";import{useState,useEffect,useRef}from\"react\";import{motion}from\"framer-motion\";import{addPropertyControls,ControlType}from\"framer\";const CounterStyles={container:{display:\"flex\",justifyContent:\"center\",alignItems:\"center\"}};export function Counter(props){const{start,end,gapSize,prefixText,suffixText,prefixFont,suffixFont,prefixColor,suffixColor,decimalSeparatorType,textSize,selectedFont,textColor,startOnViewport,restartOnViewport,incrementType,duration}=props;const[count,setCount]=useState(start);const[isVisible,setIsVisible]=useState(false);const[hasAnimated,setHasAnimated]=useState(false)// Track if animation has played\n;const containerRef=useRef(null);useEffect(()=>{const observer=new IntersectionObserver(([entry])=>{setIsVisible(entry.isIntersecting);});if(containerRef.current)observer.observe(containerRef.current);return()=>{if(containerRef.current)observer.unobserve(containerRef.current);};},[]);useEffect(()=>{if(!isVisible||hasAnimated)return;// Don't animate if already animated\nlet startTime;const totalFrames=duration/1e3*60// 60 FPS, with the user-defined duration\n;const increment=end/totalFrames// Calculate per frame increment\n;const animateCounter=timestamp=>{if(!startTime)startTime=timestamp;const elapsed=timestamp-startTime;const progress=Math.min(elapsed/duration,1)// Normalize progress (0 to 1)\n;setCount(Math.floor(progress*end))// Update count based on progress\n;if(progress<1){requestAnimationFrame(animateCounter)// Continue animating\n;}else{setHasAnimated(true)// Mark animation as completed\n;}};// Start animation when first visible\nrequestAnimationFrame(animateCounter);},[isVisible,hasAnimated,end,duration])// Now listening to duration as well\n;// Handle restarting when going out of viewport\nuseEffect(()=>{if(restartOnViewport&&isVisible&&hasAnimated){// Reset the count and animation state when re-entering the viewport\nsetCount(start);setHasAnimated(false)// Reset animation flag\n;}},[isVisible,restartOnViewport,hasAnimated,start]);const formatNumber=number=>{if(decimalSeparatorType===\"comma\"){return number.toLocaleString(\"en-US\");}else if(decimalSeparatorType===\"period\"){return number.toLocaleString(\"en-US\").replace(/,/g,\".\");}else{return number.toFixed(incrementType===\"integer\"?0:1);}};return /*#__PURE__*/_jsxs(motion.div,{ref:containerRef,style:{...CounterStyles.container,gap:`${gapSize}px`,flexDirection:\"row\",alignItems:\"center\",fontSize:`${textSize}px`,fontFamily:selectedFont.fontFamily,fontWeight:selectedFont.fontWeight,color:textColor},children:[/*#__PURE__*/_jsx(\"span\",{style:{fontFamily:prefixFont.fontFamily,fontWeight:prefixFont.fontWeight,color:prefixColor},children:prefixText}),/*#__PURE__*/_jsx(\"span\",{children:formatNumber(count)}),/*#__PURE__*/_jsx(\"span\",{style:{fontFamily:suffixFont.fontFamily,fontWeight:suffixFont.fontWeight,color:suffixColor},children:suffixText})]});}Counter.defaultProps={start:0,end:100,prefixText:\"\",suffixText:\"\",loop:false,decimalSeparatorType:\"comma\",textSize:36,selectedFont:{fontFamily:\"Inter\",fontWeight:500,systemFont:true},textColor:\"#D3D3D3\",startOnViewport:false,incrementType:\"integer\",restartOnViewport:false,duration:2500};addPropertyControls(Counter,{startOnViewport:{type:ControlType.Boolean,title:\"Viewport\",defaultValue:false,enabledTitle:\"On\",disabledTitle:\"Off\"},restartOnViewport:{type:ControlType.Boolean,title:\"Replay\",defaultValue:false,enabledTitle:\"Yes\",disabledTitle:\"No\"},selectedFont:{title:\"Font\",type:ControlType.Font,defaultValue:{fontFamily:\"Inter\",fontWeight:500,systemFont:true}},textSize:{title:\"Font Size\",type:ControlType.Number,min:8,max:240,step:1},textColor:{type:ControlType.Color,title:\"Font Color\"},start:{type:ControlType.Number,title:\"Start Number\",defaultValue:0,displayStepper:true},end:{type:ControlType.Number,title:\"End Number\",defaultValue:10,displayStepper:true},duration:{// New property control for duration\ntype:ControlType.Number,title:\"Animation Duration (ms)\",defaultValue:2500,min:500,max:1e4,step:100},decimalSeparatorType:{type:ControlType.Enum,title:\"Separator\",defaultValue:\"comma\",options:[\"comma\",\"period\",\"none\"],optionTitles:[\"Comma (1,000)\",\"Decimal (1.000)\",\"None\"]},incrementType:{type:ControlType.Enum,title:\"Increment Type\",defaultValue:\"integer\",options:[\"integer\",\"decimal\"],optionTitles:[\"Integer\",\"Decimal\"]},prefixText:{type:ControlType.String,title:\"Prefix\",defaultValue:\"\"},prefixFont:{title:\"Prefix Font\",type:ControlType.Font,defaultValue:{fontFamily:\"Inter\",fontWeight:500,systemFont:true}},prefixColor:{type:ControlType.Color,title:\"Prefix Color\"},suffixText:{type:ControlType.String,title:\"Suffix\",defaultValue:\"\"},suffixFont:{title:\"Suffix Font\",type:ControlType.Font,defaultValue:{fontFamily:\"Inter\",fontWeight:500,systemFont:true}},suffixColor:{type:ControlType.Color,title:\"Suffix Color\"},gapSize:{type:ControlType.Number,title:\"Gap Size\",defaultValue:4,min:0,max:100,step:4},loop:{type:ControlType.Boolean,title:\"Loop Animation\",defaultValue:false,enabledTitle:\"On\",disabledTitle:\"Off\"}});\nexport const __FramerMetadata__ = {\"exports\":{\"Counter\":{\"type\":\"reactComponent\",\"name\":\"Counter\",\"slots\":[],\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./Counter.map"],"mappings":"yWAAyR,SAAgB,EAAQ,EAAM,CAAC,GAAK,CAAC,QAAM,MAAI,UAAQ,aAAW,aAAW,aAAW,aAAW,cAAY,cAAY,uBAAqB,WAAS,eAAa,YAAU,kBAAgB,oBAAkB,gBAAc,YAAU,EAAW,CAAC,EAAM,GAAUA,EAAS,EAAM,CAAM,CAAC,EAAU,GAAcA,EAAS,GAAM,CAAM,CAAC,EAAY,GAAgBA,EAAS,GAAM,CACvoB,EAAaC,EAAO,KAAK,CAAC,MAAc,CAAC,IAAM,EAAS,IAAI,sBAAsB,CAAC,KAAS,CAAC,EAAa,EAAM,eAAe,EAAG,CAAgE,OAA5D,EAAa,SAAQ,EAAS,QAAQ,EAAa,QAAQ,KAAW,CAAI,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