{"version":3,"file":"NumberCounter.gVmLTSWi.mjs","names":["useRef","useMemo"],"sources":["https:/framerusercontent.com/modules/eNtuj9dgdHVIpc2cOCyO/TA7A51JQYGssXLHmOY2r/NumberCounter.js"],"sourcesContent":["import{jsx as _jsx,jsxs as _jsxs}from\"react/jsx-runtime\";import{useEffect,useMemo,useRef}from\"react\";import{motion,animate,useInView,useMotionValue,useReducedMotion,useTransform}from\"framer-motion\";import{addPropertyControls,ControlType,RenderTarget}from\"framer\";// Height of one digit cell. A little taller than the font so glyphs\n// aren't clipped by the rolling window.\nconst CELL=\"1.15em\";const REEL=[0,1,2,3,4,5,6,7,8,9,0];const cell={display:\"block\",height:CELL,lineHeight:CELL};// A window onto a vertical reel of 0–9 (plus a trailing 0 so 9 → 0 wraps\n// seamlessly). `position` is the digit shown; fractions sit between two.\nfunction Reel({position,opacity}){const y=useTransform(()=>`${-((position.get()%10+10)%10)*(100/REEL.length)}%`);return /*#__PURE__*/_jsx(motion.span,{style:{display:\"block\",height:CELL,overflow:\"hidden\",opacity},children:/*#__PURE__*/_jsx(motion.span,{style:{display:\"block\",y,willChange:\"transform\"},children:REEL.map((n,i)=>/*#__PURE__*/_jsx(\"span\",{style:{...cell,textAlign:\"center\"},children:n},i))})});}// Odometer: every column is driven by the one counting value, and a column\n// only rolls while the column to its right passes from 9 to 0.\nfunction OdometerDigit({value,place,scale,threshold}){const position=useTransform(()=>{let units=value.get()*scale;const rounded=Math.round(units);if(Math.abs(units-rounded)<1e-6)units=rounded;const size=Math.pow(10,place);const v=units/size;if(place===0)return v%10;const whole=Math.floor(v);const rollStart=1-1/size;const frac=v-whole;return(whole+(frac>rollStart?(frac-rollStart)*size:0))%10;});// Leading zeros stay hidden until the count reaches them.\nconst opacity=useTransform(()=>value.get()>threshold?1:0);return /*#__PURE__*/_jsx(Reel,{position:position,opacity:threshold>0?opacity:1});}function OdometerSeparator({value,threshold,children}){const opacity=useTransform(()=>value.get()>threshold?1:0);return /*#__PURE__*/_jsx(motion.span,{style:{...cell,opacity:threshold>0?opacity:1},children:children});}// Slot machine: each column spins on its own to its final digit, one after\n// the other, and settles with a spring.\nfunction SlotDigit({digit,play,instant,delay,duration,spins,bounce}){const position=useMotionValue(instant?digit:0);useEffect(()=>{if(instant){position.set(digit);return;}if(!play){position.set(0);return;}const controls=animate(position,digit+spins*10,{type:\"spring\",duration,bounce,delay});return()=>controls.stop();},[play,instant,digit,delay,duration,spins,bounce]);return /*#__PURE__*/_jsx(Reel,{position:position,opacity:1});}/**\n * NUMBER COUNTER\n * Counts up to a number with rolling digit reels when it scrolls into\n * view. \"Odometer\" counts through every value like a mechanical counter;\n * \"Slot\" spins each digit into place one after another.\n *\n * @framerSupportedLayoutWidth auto\n * @framerSupportedLayoutHeight auto\n */export default function NumberCounter(props){const{mode,to,from,decimals,separator,prefix,suffix,font,color,duration,delay,stagger,spins,bounce,replay}=props;const ref=useRef(null);const inView=useInView(ref,{once:!replay,amount:.5});const reducedMotion=useReducedMotion();const isCanvas=RenderTarget.current()===RenderTarget.canvas;// On the canvas and for reduced motion, show the final number.\nconst instant=isCanvas||reducedMotion;const isSlot=mode===\"slot\";const start=isSlot?0:from;const value=useMotionValue(isCanvas?to:start);useEffect(()=>{if(isSlot)return;if(instant){value.set(to);return;}if(!inView){value.set(from);return;}const controls=animate(value,to,{duration,delay,ease:[.16,1,.3,1]});return()=>controls.stop();},[isSlot,instant,inView,from,to,duration,delay]);const format=useMemo(()=>new Intl.NumberFormat(\"en-US\",{minimumFractionDigits:decimals,maximumFractionDigits:decimals,useGrouping:separator}),[decimals,separator]);// Lay out enough columns for the widest number that will be shown.\nconst layoutText=format.format(isSlot?to:Math.max(from,to));const chars=Array.from(layoutText);const scale=Math.pow(10,decimals);const smallest=1/scale;let remaining=0;for(let i=0;i<chars.length;i++){if(chars[i]>=\"0\"&&chars[i]<=\"9\")remaining++;}let digitIndex=0;let lastThreshold=0;const columns=chars.map((char,i)=>{const key=chars.length-i;if(char>=\"0\"&&char<=\"9\"){remaining--;// Place 0 is the smallest displayed unit (after any decimals).\nconst place=remaining;const whole=place-decimals;// A column appears as the count starts rolling into it.\nlastThreshold=whole>0?Math.pow(10,whole)-smallest:0;if(isSlot){return /*#__PURE__*/_jsx(SlotDigit,{digit:Number(char),play:inView,instant:instant,delay:delay+digitIndex++*stagger,duration:duration,spins:spins,bounce:bounce},key);}return /*#__PURE__*/_jsx(OdometerDigit,{value:value,place:place,scale:scale,threshold:lastThreshold},key);}if(isSlot){return /*#__PURE__*/_jsx(\"span\",{style:cell,children:char},key);}return /*#__PURE__*/_jsx(OdometerSeparator,{value:value,threshold:lastThreshold,children:char},key);});return /*#__PURE__*/_jsxs(\"div\",{ref:ref,role:\"img\",\"aria-label\":`${prefix}${format.format(to)}${suffix}`,style:{display:\"flex\",width:\"max-content\",color,...font,lineHeight:CELL,fontVariantNumeric:\"tabular-nums\",whiteSpace:\"pre\",userSelect:\"none\"},children:[prefix&&/*#__PURE__*/_jsx(\"span\",{\"aria-hidden\":true,style:cell,children:prefix}),/*#__PURE__*/_jsx(\"span\",{\"aria-hidden\":true,style:{display:\"flex\"},children:columns}),suffix&&/*#__PURE__*/_jsx(\"span\",{\"aria-hidden\":true,style:cell,children:suffix})]});}NumberCounter.defaultProps={mode:\"odometer\",to:12480,from:0,decimals:0,separator:true,prefix:\"\",suffix:\"+\",color:\"#111111\",duration:2.4,delay:0,stagger:.08,spins:1,bounce:.25,replay:false};addPropertyControls(NumberCounter,{mode:{type:ControlType.Enum,title:\"Style\",options:[\"odometer\",\"slot\"],optionTitles:[\"Odometer\",\"Slot\"],displaySegmentedControl:true,defaultValue:\"odometer\"},to:{type:ControlType.Number,title:\"Number\",min:0,max:1e9,step:.01,defaultValue:12480},from:{type:ControlType.Number,title:\"Start From\",min:0,max:1e9,step:.01,defaultValue:0,hidden:props=>props.mode===\"slot\"},decimals:{type:ControlType.Number,title:\"Decimals\",min:0,max:3,step:1,displayStepper:true,defaultValue:0},separator:{type:ControlType.Boolean,title:\"Commas\",enabledTitle:\"1,000\",disabledTitle:\"1000\",defaultValue:true},prefix:{type:ControlType.String,title:\"Prefix\",placeholder:\"$\",defaultValue:\"\"},suffix:{type:ControlType.String,title:\"Suffix\",placeholder:\"+\",defaultValue:\"+\"},font:{type:ControlType.Font,title:\"Font\",controls:\"extended\",defaultFontType:\"sans-serif\",defaultValue:{fontSize:72,lineHeight:1}},color:{type:ControlType.Color,title:\"Color\",defaultValue:\"#111111\"},duration:{type:ControlType.Number,title:\"Duration\",min:.3,max:10,step:.1,unit:\"s\",defaultValue:2.4,description:\"In Slot style, this is the time each digit takes.\"},delay:{type:ControlType.Number,title:\"Delay\",min:0,max:5,step:.05,unit:\"s\",defaultValue:0},stagger:{type:ControlType.Number,title:\"Stagger\",min:0,max:.5,step:.01,unit:\"s\",defaultValue:.08,hidden:props=>props.mode!==\"slot\"},spins:{type:ControlType.Number,title:\"Extra Spins\",min:0,max:5,step:1,displayStepper:true,defaultValue:1,hidden:props=>props.mode!==\"slot\"},bounce:{type:ControlType.Number,title:\"Bounce\",min:0,max:.6,step:.05,defaultValue:.25,hidden:props=>props.mode!==\"slot\"},replay:{type:ControlType.Boolean,title:\"In View\",enabledTitle:\"Replay\",disabledTitle:\"Once\",defaultValue:false}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"NumberCounter\",\"slots\":[],\"annotations\":{\"framerSupportedLayoutWidth\":\"auto\",\"framerSupportedLayoutHeight\":\"auto\",\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./NumberCounter.map"],"mappings":"0RAIA,SAAS,EAAK,CAAC,WAAS,WAAS,CAAC,IAAM,EAAE,MAAiB,GAAG,GAAG,EAAS,IAAI,EAAE,GAAG,IAAI,KAAK,IAAI,EAAK,QAAQ,EAAE,EAAE,OAAoB,EAAK,EAAO,KAAK,CAAC,MAAM,CAAC,QAAQ,QAAQ,OAAO,EAAK,SAAS,SAAS,SAA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