Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-slot-counter

Package Overview
Dependencies
Maintainers
1
Versions
47
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-slot-counter - npm Package Compare versions

Comparing version 2.0.0 to 2.0.1

3

lib/components/Slot.d.ts

@@ -17,5 +17,6 @@ import React, { RefObject } from 'react';

useMonospaceWidth: boolean;
maxNumberWidth?: number;
}
declare function Slot({ charClassName, numbersRef, active, isChanged, effectiveDuration, delay, value, startValue, dummyList, hasInfiniteList, valueClassName, reverse, sequentialAnimationMode, useMonospaceWidth, }: Props): JSX.Element;
declare function Slot({ charClassName, numbersRef, active, isChanged, effectiveDuration, delay, value, startValue, dummyList, hasInfiniteList, valueClassName, reverse, sequentialAnimationMode, useMonospaceWidth, maxNumberWidth, }: Props): JSX.Element;
declare const _default: React.MemoExoticComponent<typeof Slot>;
export default _default;
'use client';
import n,{memo as e,useState as t,useRef as r,useEffect as i,forwardRef as a,useMemo as u,useCallback as o,useImperativeHandle as l}from"react";var c=function(){return c=Object.assign||function(n){for(var e,t=1,r=arguments.length;t<r;t++)for(var i in e=arguments[t])Object.prototype.hasOwnProperty.call(e,i)&&(n[i]=e[i]);return n},c.apply(this,arguments)};var s=function(){for(var n=[],e=0;e<arguments.length;e++)n[e]=arguments[e];return n.filter(Boolean).join(" ")},d=function(n,e){for(var t=[],r=n;r<e;r+=1)t.push(r);return t},f=function(n,e){for(var t=[],r=n;r!==e;)t.push(r),10===(r+=1)&&(r=0);return t},m=function(n,e){var t=Math.random()*(e-n);return Math.floor(t+n)},v=function(n){for(var e,t=function(n,e,t){if(t||2===arguments.length)for(var r,i=0,a=e.length;i<a;i++)!r&&i in e||(r||(r=Array.prototype.slice.call(e,0,i)),r[i]=e[i]);return n.concat(r||Array.prototype.slice.call(e))}([],n,!0),r=t.length-1;r>0;r-=1){var i=Math.floor(Math.random()*(r+1));e=[t[i],t[r]],t[r]=e[0],t[i]=e[1]}return t},p=function(n){return"number"==typeof n?n:(Array.isArray(n)?n.join(""):n).replace(/[,.]/g,"")},h=function(n){return"object"!=typeof n&&!Number.isNaN(p(n))},y=function(n){return"object"==typeof n};var g="index-module_slot_wrap__ZT-DX",_="index-module_slot__DpPgW",b="index-module_separator__7GhtE",N="index-module_numbers__sqlqm",x="index-module_num__j6XH3";!function(n,e){void 0===e&&(e={});var t=e.insertAt;if(n&&"undefined"!=typeof document){var r=document.head||document.getElementsByTagName("head")[0],i=document.createElement("style");i.type="text/css","top"===t&&r.firstChild?r.insertBefore(i,r.firstChild):r.appendChild(i),i.styleSheet?i.styleSheet.cssText=n:i.appendChild(document.createTextNode(n))}}(".index-module_slot_wrap__ZT-DX {\n display: inline-block;\n white-space: nowrap;\n}\n\n.index-module_slot__DpPgW {\n display: inline-block;\n overflow: hidden;\n text-align: center;\n vertical-align: bottom;\n will-change: transform;\n}\n\n.index-module_separator__7GhtE {\n display: inline-block;\n vertical-align: bottom;\n text-align: center;\n}\n\n.index-module_numbers__sqlqm {\n display: block;\n}\n\n.index-module_num__j6XH3 {\n display: block;\n}");var A="undefined"!=typeof window?n.useLayoutEffect:n.useEffect;var C=e((function(e){var a,u,o=e.charClassName,l=e.numbersRef,f=e.active,m=e.isChanged,p=e.effectiveDuration,y=e.delay,g=e.value,b=e.startValue,C=e.dummyList,E=e.hasInfiniteList,S=e.valueClassName,w=e.reverse,M=e.sequentialAnimationMode,j=e.useMonospaceWidth,k=t(!1),T=k[0],q=k[1],D=t(g),L=D[0],O=D[1],W=r(),B=r(g),V=r(null),X=t(M?C:v(C)),Y=X[0],F=X[1],H=t(0),I=H[0],P=H[1],R=t(0),G=R[0],Z=R[1],J=t(!1),U=J[0],z=J[1],K=I*(C.length+1),Q="object"!=typeof g&&h(g);A((function(){z(!0)}),[]),A((function(){var n,e;P(null!==(e=null===(n=V.current)||void 0===n?void 0:n.offsetHeight)&&void 0!==e?e:0)}),[U]),A((function(){if(Q&&j){var n=d(0,10).map((function(n){var e,t,r=document.createElement("div");r.style.position="absolute",r.style.top="0",r.style.left="-9999px",r.style.visibility="hidden",r.textContent=n.toString(),null===(e=V.current)||void 0===e||e.appendChild(r);var i=r.getBoundingClientRect().width;return null===(t=V.current)||void 0===t||t.removeChild(r),i})),e=Math.max.apply(Math,n);Z(e)}}),[Q,j,U]),i((function(){f?requestAnimationFrame((function(){q(f)})):q(f)}),[f]),i((function(){T&&(W.current=B.current,B.current=g,setTimeout((function(){return O(g)}),M?0:1e3*p*1.3/C.length+1e3*y))}),[T,g,p,y,C.length,M]),i((function(){F(M?C:v(C))}),[g,C,M]);var $=function(){return Y.map((function(e,t){return n.createElement("span",{key:t,className:x,"aria-hidden":"true"},e)}))},nn=w?L:null!=b?b:L;M&&(nn=w?L:null!==(a=null!=b?b:W.current)&&void 0!==a?a:L);var en=w&&null!=b?b:L;return M&&(en=w&&null!==(u=null!=b?b:W.current)&&void 0!==u?u:L),n.createElement("span",{className:s(_,o),style:{display:"inline-block",width:U&&j?G:void 0,height:U?I:void 0}},n.createElement("span",{ref:l,className:N,style:c({transition:"none",transform:w?"translateY(-".concat(K,"px)"):"translateY(0px)"},T&&m&&{transform:w?"translateY(0px)":"translateY(-".concat(K,"px)"),transition:"transform ".concat(p,"s ").concat(y,"s ease-in-out")})},U?n.createElement(n.Fragment,null,n.createElement("span",{className:x,"aria-hidden":"true",style:{height:I}},nn),$(),n.createElement("span",{className:s(x,S),ref:V},en),E?$():null):n.createElement("span",{className:x,"aria-hidden":"true"},b||L)))}));var E=[",","."," "];var S=e(a((function(e,a){var c,v,_,N,x,A,S,w,M,j,k=e.value,T=e.startValue,q=e.startValueOnce,D=void 0!==q&&q,L=e.duration,O=void 0===L?.7:L,W=e.dummyCharacters,B=e.dummyCharacterCount,V=void 0===B?6:B,X=e.autoAnimationStart,Y=void 0===X||X,F=e.containerClassName,H=e.charClassName,I=e.separatorClassName,P=e.animateUnchanged,R=void 0!==P&&P,G=e.hasInfiniteList,Z=void 0!==G&&G,J=e.valueClassName,U=e.sequentialAnimationMode,z=void 0!==U&&U,K=e.useMonospaceWidth,Q=void 0!==K&&K,$=e.direction,nn=e.debounceDelay,en=function(n,e){var r=t(n),a=r[0],u=r[1];return i((function(){if(0===e)return u(n);var t=setTimeout((function(){u(n)}),e);return function(){clearTimeout(t)}}),[n,e]),a}(k,null!=nn?nn:0),tn=u((function(){return function(n){return Array.isArray(n)&&y(n[0])}(en)?"":"object"==typeof en?JSON.stringify(en):en.toString()}),[en]),rn=t(!1),an=rn[0],un=rn[1],on=r(),ln=r(null),cn=r(T),sn=r(null==T||Y?en:T),dn=r(T),fn=r(0),mn=r(0),vn=t([]),pn=vn[0],hn=vn[1],yn=r(),gn=t(0),_n=gn[0],bn=gn[1],Nn=r(!1),xn=null!=T&&(!D||fn.current<1),An=null!==(v=null===(c=on.current)||void 0===c?void 0:c.dummyCharacterCount)&&void 0!==v?v:V,Cn=null!==(N=null===(_=on.current)||void 0===_?void 0:_.duration)&&void 0!==N?N:O;i((function(){hn(d(0,An-1).map((function(n){if(!W)return m(0,10);var e=n>=W.length?m(0,W.length):n;return W[e]})))}),[W,An]),sn.current!==en&&Nn.current&&mn.current>0&&(dn.current=sn.current,sn.current=en);var En=Array.isArray(dn.current)?dn.current:null!==(A=null===(x=dn.current)||void 0===x?void 0:x.toString().split(""))&&void 0!==A?A:[],Sn=Array.isArray(sn.current)?sn.current:null!==(w=null===(S=sn.current)||void 0===S?void 0:S.toString().split(""))&&void 0!==w?w:[],wn=Array.isArray(cn.current)?cn.current:null!==(j=null===(M=cn.current)||void 0===M?void 0:M.toString().split(""))&&void 0!==j?j:[],Mn=u((function(){return Array.isArray(en)?en:null==en?void 0:en.toString().split("")}),[en]),jn=u((function(){return Array.isArray(T)?T:null==T?void 0:T.toString().split("")}),[T]),kn=En.length!==Sn.length,Tn=[];Sn.forEach((function(n,e){var t=Sn.length-e-1,r=xn?wn:En;(Sn[t]!==r[t]||kn||R)&&Tn.push(t)})),Tn.reverse();var qn=u((function(){return Math.min(.1,Cn/Mn.length)}),[Cn,Mn.length]),Dn=o((function(){yn.current&&clearTimeout(yn.current),un(!1),fn.current=mn.current,fn.current+=1,yn.current=setTimeout((function(){mn.current+=1,un(!0)}),20)}),[]),Ln=o((function(n){null==T||D||(dn.current=void 0),on.current=n,Dn()}),[T,D,Dn]),On=o((function(n){var e=xn?T:dn.current;if(null==e||!h(e)||!h(en))return[];var t=Number(p(e)),r=Number(p(en)),i=Number(t.toString()[n]||0),a=Number(r.toString()[n]||0);return t<r?f((i+1)%10,a):f((a+1)%10,i)}),[xn,en,T]),Wn=o((function(){bn((function(n){return n+1}))}),[]);i((function(){null!=dn.current&&(cn.current&&!Nn.current||Dn())}),[tn,Dn]),i((function(){Y&&Dn()}),[Y,Dn]),i((function(){requestAnimationFrame((function(){Nn.current=!0}))}),[]),l(a,(function(){return{startAnimation:Ln,refreshStyles:Wn}}));var Bn=T&&!Y&&0===fn.current?jn||[]:Mn,Vn=((null==jn?void 0:jn.length)||0)-Bn.length,Xn=-1;return n.createElement("span",{key:_n,className:s(F,g)},Bn.map((function(e,t){var r,i,a=Tn.includes(t),u=(a?Tn.indexOf(t):0)*qn,o=dn.current,l=null!=T&&!!D&&fn.current>1,c=null!=en&&null!=o&&h(en)&&h(o)&&p(en)<p(o);return(null===(r=on.current)||void 0===r?void 0:r.direction)&&(c="top-down"===(null===(i=on.current)||void 0===i?void 0:i.direction)),$&&(c="top-down"===$),!y(e)&&E.includes(e)?n.createElement("span",{key:Sn.length-t-1,className:s(b,I)},e):(Xn+=1,n.createElement(C,{key:Sn.length-t-1,numbersRef:ln,active:an,isChanged:a,charClassName:H,effectiveDuration:Cn,delay:u,value:e,startValue:l||null==jn?void 0:jn[t-Vn],dummyList:z?On(Xn):pn,hasInfiniteList:Z,valueClassName:J,reverse:c,sequentialAnimationMode:z,useMonospaceWidth:Q}))})))})));export{S as default};
import n,{memo as e,useState as t,useRef as r,useEffect as i,forwardRef as a,useMemo as u,useCallback as o,useImperativeHandle as l}from"react";var c=function(){return c=Object.assign||function(n){for(var e,t=1,r=arguments.length;t<r;t++)for(var i in e=arguments[t])Object.prototype.hasOwnProperty.call(e,i)&&(n[i]=e[i]);return n},c.apply(this,arguments)};var s=function(){for(var n=[],e=0;e<arguments.length;e++)n[e]=arguments[e];return n.filter(Boolean).join(" ")},d=function(n,e){for(var t=[],r=n;r<e;r+=1)t.push(r);return t},f=function(n,e){for(var t=[],r=n;r!==e;)t.push(r),10===(r+=1)&&(r=0);return t},m=function(n,e){var t=Math.random()*(e-n);return Math.floor(t+n)},v=function(n){for(var e,t=function(n,e,t){if(t||2===arguments.length)for(var r,i=0,a=e.length;i<a;i++)!r&&i in e||(r||(r=Array.prototype.slice.call(e,0,i)),r[i]=e[i]);return n.concat(r||Array.prototype.slice.call(e))}([],n,!0),r=t.length-1;r>0;r-=1){var i=Math.floor(Math.random()*(r+1));e=[t[i],t[r]],t[r]=e[0],t[i]=e[1]}return t},h=function(n){return"number"==typeof n?n:(Array.isArray(n)?n.join(""):n).replace(/[,.]/g,"")},p=function(n){return"object"!=typeof n&&!Number.isNaN(h(n))},y=function(n){return"object"==typeof n};var g="index-module_slot_wrap__ZT-DX",_="index-module_slot__DpPgW",b="index-module_separator__7GhtE",N="index-module_numbers__sqlqm",x="index-module_num__j6XH3";!function(n,e){void 0===e&&(e={});var t=e.insertAt;if(n&&"undefined"!=typeof document){var r=document.head||document.getElementsByTagName("head")[0],i=document.createElement("style");i.type="text/css","top"===t&&r.firstChild?r.insertBefore(i,r.firstChild):r.appendChild(i),i.styleSheet?i.styleSheet.cssText=n:i.appendChild(document.createTextNode(n))}}(".index-module_slot_wrap__ZT-DX {\n display: inline-block;\n white-space: nowrap;\n}\n\n.index-module_slot__DpPgW {\n display: inline-block;\n overflow: hidden;\n text-align: center;\n vertical-align: bottom;\n will-change: transform;\n}\n\n.index-module_separator__7GhtE {\n display: inline-block;\n vertical-align: bottom;\n text-align: center;\n}\n\n.index-module_numbers__sqlqm {\n display: block;\n}\n\n.index-module_num__j6XH3 {\n display: block;\n}");var A="undefined"!=typeof window?n.useLayoutEffect:n.useEffect;var C=e((function(e){var a,u,o=e.charClassName,l=e.numbersRef,d=e.active,f=e.isChanged,m=e.effectiveDuration,h=e.delay,p=e.value,y=e.startValue,g=e.dummyList,b=e.hasInfiniteList,C=e.valueClassName,E=e.reverse,S=e.sequentialAnimationMode,w=e.useMonospaceWidth,M=e.maxNumberWidth,k=t(!1),T=k[0],j=k[1],q=t(p),D=q[0],W=q[1],L=r(),O=r(p),B=r(null),V=t(S?g:v(g)),X=V[0],Y=V[1],F=t(0),H=F[0],I=F[1],P=t(!1),R=P[0],G=P[1],Z=H*(g.length+1);A((function(){G(!0)}),[]),A((function(){var n,e;I(null!==(e=null===(n=B.current)||void 0===n?void 0:n.offsetHeight)&&void 0!==e?e:0)}),[R]),i((function(){d?requestAnimationFrame((function(){j(d)})):j(d)}),[d]),i((function(){T&&(L.current=O.current,O.current=p,setTimeout((function(){return W(p)}),S?0:1e3*m*1.3/g.length+1e3*h))}),[T,p,m,h,g.length,S]),i((function(){Y(S?g:v(g))}),[p,g,S]);var J=function(){return X.map((function(e,t){return n.createElement("span",{key:t,className:x,"aria-hidden":"true"},e)}))},U=E?D:null!=y?y:D;S&&(U=E?D:null!==(a=null!=y?y:L.current)&&void 0!==a?a:D);var z=E&&null!=y?y:D;return S&&(z=E&&null!==(u=null!=y?y:L.current)&&void 0!==u?u:D),n.createElement("span",{className:s(_,o),style:{display:"inline-block",width:R&&w?M:void 0,height:R?H:void 0}},n.createElement("span",{ref:l,className:N,style:c({transition:"none",transform:E?"translateY(-".concat(Z,"px)"):"translateY(0px)"},T&&f&&{transform:E?"translateY(0px)":"translateY(-".concat(Z,"px)"),transition:"transform ".concat(m,"s ").concat(h,"s ease-in-out")})},R?n.createElement(n.Fragment,null,n.createElement("span",{className:x,"aria-hidden":"true",style:{height:H}},U),J(),n.createElement("span",{className:s(x,C),ref:B},z),b?J():null):n.createElement("span",{className:x,"aria-hidden":"true"},y||D)))}));var E=[",","."," "];var S=e(a((function(e,a){var c,v,_,N,x,S,w,M,k,T,j=e.value,q=e.startValue,D=e.startValueOnce,W=void 0!==D&&D,L=e.duration,O=void 0===L?.7:L,B=e.dummyCharacters,V=e.dummyCharacterCount,X=void 0===V?6:V,Y=e.autoAnimationStart,F=void 0===Y||Y,H=e.containerClassName,I=e.charClassName,P=e.separatorClassName,R=e.animateUnchanged,G=void 0!==R&&R,Z=e.hasInfiniteList,J=void 0!==Z&&Z,U=e.valueClassName,z=e.sequentialAnimationMode,K=void 0!==z&&z,Q=e.useMonospaceWidth,$=void 0!==Q&&Q,nn=e.direction,en=e.debounceDelay,tn=function(n,e){var r=t(n),a=r[0],u=r[1];return i((function(){if(0===e)return u(n);var t=setTimeout((function(){u(n)}),e);return function(){clearTimeout(t)}}),[n,e]),a}(j,null!=en?en:0),rn=u((function(){return function(n){return Array.isArray(n)&&y(n[0])}(tn)?"":"object"==typeof tn?JSON.stringify(tn):tn.toString()}),[tn]),an=t(!1),un=an[0],on=an[1],ln=r(),cn=r(null),sn=r(q),dn=r(null==q||F?tn:q),fn=r(q),mn=r(0),vn=r(0),hn=t([]),pn=hn[0],yn=hn[1],gn=r(),_n=t(0),bn=_n[0],Nn=_n[1],xn=t(),An=xn[0],Cn=xn[1],En=r(!1),Sn=null!=q&&(!W||mn.current<1),wn=null!==(v=null===(c=ln.current)||void 0===c?void 0:c.dummyCharacterCount)&&void 0!==v?v:X,Mn=null!==(N=null===(_=ln.current)||void 0===_?void 0:_.duration)&&void 0!==N?N:O;A((function(){var n,e=cn.current;if(e&&$){var t=function(){var n=d(0,10).map((function(n){var t=document.createElement("span");t.style.position="absolute",t.style.top="0",t.style.left="-9999px",t.style.visibility="hidden",t.textContent=n.toString(),e.appendChild(t);var r=t.getBoundingClientRect().width;return e.removeChild(t),r})),t=Math.max.apply(Math,n);Cn(t)};t(),null===(n=document.fonts)||void 0===n||n.ready.then((function(){t()}))}}),[]),i((function(){yn(d(0,wn-1).map((function(n){if(!B)return m(0,10);var e=n>=B.length?m(0,B.length):n;return B[e]})))}),[B,wn]),dn.current!==tn&&En.current&&vn.current>0&&(fn.current=dn.current,dn.current=tn);var kn=Array.isArray(fn.current)?fn.current:null!==(S=null===(x=fn.current)||void 0===x?void 0:x.toString().split(""))&&void 0!==S?S:[],Tn=Array.isArray(dn.current)?dn.current:null!==(M=null===(w=dn.current)||void 0===w?void 0:w.toString().split(""))&&void 0!==M?M:[],jn=Array.isArray(sn.current)?sn.current:null!==(T=null===(k=sn.current)||void 0===k?void 0:k.toString().split(""))&&void 0!==T?T:[],qn=u((function(){return Array.isArray(tn)?tn:null==tn?void 0:tn.toString().split("")}),[tn]),Dn=u((function(){return Array.isArray(q)?q:null==q?void 0:q.toString().split("")}),[q]),Wn=kn.length!==Tn.length,Ln=[];Tn.forEach((function(n,e){var t=Tn.length-e-1,r=Sn?jn:kn;(Tn[t]!==r[t]||Wn||G)&&Ln.push(t)})),Ln.reverse();var On=u((function(){return Math.min(.1,Mn/qn.length)}),[Mn,qn.length]),Bn=o((function(){gn.current&&clearTimeout(gn.current),on(!1),mn.current=vn.current,mn.current+=1,gn.current=setTimeout((function(){vn.current+=1,on(!0)}),20)}),[]),Vn=o((function(n){null==q||W||(fn.current=void 0),ln.current=n,Bn()}),[q,W,Bn]),Xn=o((function(n){var e=Sn?q:fn.current;if(null==e||!p(e)||!p(tn))return[];var t=Number(h(e)),r=Number(h(tn)),i=Number(t.toString()[n]||0),a=Number(r.toString()[n]||0);return t<r?f((i+1)%10,a):f((a+1)%10,i)}),[Sn,tn,q]),Yn=o((function(){Nn((function(n){return n+1}))}),[]);i((function(){(En.current||null!=fn.current)&&(!En.current&&sn.current||Bn())}),[rn,Bn]),i((function(){F&&Bn()}),[F,Bn]),i((function(){requestAnimationFrame((function(){En.current=!0}))}),[]),l(a,(function(){return{startAnimation:Vn,refreshStyles:Yn}}));var Fn=q&&!F&&0===mn.current?Dn||[]:qn,Hn=((null==Dn?void 0:Dn.length)||0)-Fn.length,In=-1;return n.createElement("span",{key:bn,className:s(H,g)},Fn.map((function(e,t){var r,i,a=Ln.includes(t),u=(a?Ln.indexOf(t):0)*On,o=fn.current,l=null!=q&&!!W&&mn.current>1,c=null!=tn&&null!=o&&p(tn)&&p(o)&&h(tn)<h(o);return(null===(r=ln.current)||void 0===r?void 0:r.direction)&&(c="top-down"===(null===(i=ln.current)||void 0===i?void 0:i.direction)),nn&&(c="top-down"===nn),!y(e)&&E.includes(e)?n.createElement("span",{key:Tn.length-t-1,className:s(b,P)},e):(In+=1,n.createElement(C,{key:Tn.length-t-1,maxNumberWidth:An,numbersRef:cn,active:un,isChanged:a,charClassName:I,effectiveDuration:Mn,delay:u,value:e,startValue:l||null==Dn?void 0:Dn[t-Hn],dummyList:K&&(!F||vn.current>1)?Xn(In):pn,hasInfiniteList:J,valueClassName:U,reverse:c,sequentialAnimationMode:K,useMonospaceWidth:$}))})))})));export{S as default};
//# sourceMappingURL=index.esm.js.map
'use client';
"use strict";var e=require("react"),n=function(){return n=Object.assign||function(e){for(var n,t=1,r=arguments.length;t<r;t++)for(var u in n=arguments[t])Object.prototype.hasOwnProperty.call(n,u)&&(e[u]=n[u]);return e},n.apply(this,arguments)};var t=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];return e.filter(Boolean).join(" ")},r=function(e,n){for(var t=[],r=e;r<n;r+=1)t.push(r);return t},u=function(e,n){for(var t=[],r=e;r!==n;)t.push(r),10===(r+=1)&&(r=0);return t},a=function(e,n){var t=Math.random()*(n-e);return Math.floor(t+e)},i=function(e){for(var n,t=function(e,n,t){if(t||2===arguments.length)for(var r,u=0,a=n.length;u<a;u++)!r&&u in n||(r||(r=Array.prototype.slice.call(n,0,u)),r[u]=n[u]);return e.concat(r||Array.prototype.slice.call(n))}([],e,!0),r=t.length-1;r>0;r-=1){var u=Math.floor(Math.random()*(r+1));n=[t[u],t[r]],t[r]=n[0],t[u]=n[1]}return t},o=function(e){return"number"==typeof e?e:(Array.isArray(e)?e.join(""):e).replace(/[,.]/g,"")},l=function(e){return"object"!=typeof e&&!Number.isNaN(o(e))},s=function(e){return"object"==typeof e};var c="index-module_slot_wrap__ZT-DX",d="index-module_slot__DpPgW",f="index-module_separator__7GhtE",m="index-module_numbers__sqlqm",v="index-module_num__j6XH3";!function(e,n){void 0===n&&(n={});var t=n.insertAt;if(e&&"undefined"!=typeof document){var r=document.head||document.getElementsByTagName("head")[0],u=document.createElement("style");u.type="text/css","top"===t&&r.firstChild?r.insertBefore(u,r.firstChild):r.appendChild(u),u.styleSheet?u.styleSheet.cssText=e:u.appendChild(document.createTextNode(e))}}(".index-module_slot_wrap__ZT-DX {\n display: inline-block;\n white-space: nowrap;\n}\n\n.index-module_slot__DpPgW {\n display: inline-block;\n overflow: hidden;\n text-align: center;\n vertical-align: bottom;\n will-change: transform;\n}\n\n.index-module_separator__7GhtE {\n display: inline-block;\n vertical-align: bottom;\n text-align: center;\n}\n\n.index-module_numbers__sqlqm {\n display: block;\n}\n\n.index-module_num__j6XH3 {\n display: block;\n}");var p="undefined"!=typeof window?e.useLayoutEffect:e.useEffect;var h=e.memo((function(u){var a,o,s=u.charClassName,c=u.numbersRef,f=u.active,h=u.isChanged,y=u.effectiveDuration,g=u.delay,_=u.value,b=u.startValue,C=u.dummyList,E=u.hasInfiniteList,N=u.valueClassName,x=u.reverse,A=u.sequentialAnimationMode,S=u.useMonospaceWidth,M=e.useState(!1),R=M[0],k=M[1],w=e.useState(_),j=w[0],q=w[1],T=e.useRef(),D=e.useRef(_),L=e.useRef(null),O=e.useState(A?C:i(C)),W=O[0],B=O[1],H=e.useState(0),I=H[0],V=H[1],X=e.useState(0),Y=X[0],F=X[1],P=e.useState(!1),G=P[0],Z=P[1],J=I*(C.length+1),U="object"!=typeof _&&l(_);p((function(){Z(!0)}),[]),p((function(){var e,n;V(null!==(n=null===(e=L.current)||void 0===e?void 0:e.offsetHeight)&&void 0!==n?n:0)}),[G]),p((function(){if(U&&S){var e=r(0,10).map((function(e){var n,t,r=document.createElement("div");r.style.position="absolute",r.style.top="0",r.style.left="-9999px",r.style.visibility="hidden",r.textContent=e.toString(),null===(n=L.current)||void 0===n||n.appendChild(r);var u=r.getBoundingClientRect().width;return null===(t=L.current)||void 0===t||t.removeChild(r),u})),n=Math.max.apply(Math,e);F(n)}}),[U,S,G]),e.useEffect((function(){f?requestAnimationFrame((function(){k(f)})):k(f)}),[f]),e.useEffect((function(){R&&(T.current=D.current,D.current=_,setTimeout((function(){return q(_)}),A?0:1e3*y*1.3/C.length+1e3*g))}),[R,_,y,g,C.length,A]),e.useEffect((function(){B(A?C:i(C))}),[_,C,A]);var z=function(){return W.map((function(n,t){return e.createElement("span",{key:t,className:v,"aria-hidden":"true"},n)}))},K=x?j:null!=b?b:j;A&&(K=x?j:null!==(a=null!=b?b:T.current)&&void 0!==a?a:j);var Q=x&&null!=b?b:j;return A&&(Q=x&&null!==(o=null!=b?b:T.current)&&void 0!==o?o:j),e.createElement("span",{className:t(d,s),style:{display:"inline-block",width:G&&S?Y:void 0,height:G?I:void 0}},e.createElement("span",{ref:c,className:m,style:n({transition:"none",transform:x?"translateY(-".concat(J,"px)"):"translateY(0px)"},R&&h&&{transform:x?"translateY(0px)":"translateY(-".concat(J,"px)"),transition:"transform ".concat(y,"s ").concat(g,"s ease-in-out")})},G?e.createElement(e.Fragment,null,e.createElement("span",{className:v,"aria-hidden":"true",style:{height:I}},K),z(),e.createElement("span",{className:t(v,N),ref:L},Q),E?z():null):e.createElement("span",{className:v,"aria-hidden":"true"},b||j)))}));var y=[",","."," "];var g=e.memo(e.forwardRef((function(n,i){var d,m,v,p,g,_,b,C,E,N,x=n.value,A=n.startValue,S=n.startValueOnce,M=void 0!==S&&S,R=n.duration,k=void 0===R?.7:R,w=n.dummyCharacters,j=n.dummyCharacterCount,q=void 0===j?6:j,T=n.autoAnimationStart,D=void 0===T||T,L=n.containerClassName,O=n.charClassName,W=n.separatorClassName,B=n.animateUnchanged,H=void 0!==B&&B,I=n.hasInfiniteList,V=void 0!==I&&I,X=n.valueClassName,Y=n.sequentialAnimationMode,F=void 0!==Y&&Y,P=n.useMonospaceWidth,G=void 0!==P&&P,Z=n.direction,J=n.debounceDelay,U=function(n,t){var r=e.useState(n),u=r[0],a=r[1];return e.useEffect((function(){if(0===t)return a(n);var e=setTimeout((function(){a(n)}),t);return function(){clearTimeout(e)}}),[n,t]),u}(x,null!=J?J:0),z=e.useMemo((function(){return function(e){return Array.isArray(e)&&s(e[0])}(U)?"":"object"==typeof U?JSON.stringify(U):U.toString()}),[U]),K=e.useState(!1),Q=K[0],$=K[1],ee=e.useRef(),ne=e.useRef(null),te=e.useRef(A),re=e.useRef(null==A||D?U:A),ue=e.useRef(A),ae=e.useRef(0),ie=e.useRef(0),oe=e.useState([]),le=oe[0],se=oe[1],ce=e.useRef(),de=e.useState(0),fe=de[0],me=de[1],ve=e.useRef(!1),pe=null!=A&&(!M||ae.current<1),he=null!==(m=null===(d=ee.current)||void 0===d?void 0:d.dummyCharacterCount)&&void 0!==m?m:q,ye=null!==(p=null===(v=ee.current)||void 0===v?void 0:v.duration)&&void 0!==p?p:k;e.useEffect((function(){se(r(0,he-1).map((function(e){if(!w)return a(0,10);var n=e>=w.length?a(0,w.length):e;return w[n]})))}),[w,he]),re.current!==U&&ve.current&&ie.current>0&&(ue.current=re.current,re.current=U);var ge=Array.isArray(ue.current)?ue.current:null!==(_=null===(g=ue.current)||void 0===g?void 0:g.toString().split(""))&&void 0!==_?_:[],_e=Array.isArray(re.current)?re.current:null!==(C=null===(b=re.current)||void 0===b?void 0:b.toString().split(""))&&void 0!==C?C:[],be=Array.isArray(te.current)?te.current:null!==(N=null===(E=te.current)||void 0===E?void 0:E.toString().split(""))&&void 0!==N?N:[],Ce=e.useMemo((function(){return Array.isArray(U)?U:null==U?void 0:U.toString().split("")}),[U]),Ee=e.useMemo((function(){return Array.isArray(A)?A:null==A?void 0:A.toString().split("")}),[A]),Ne=ge.length!==_e.length,xe=[];_e.forEach((function(e,n){var t=_e.length-n-1,r=pe?be:ge;(_e[t]!==r[t]||Ne||H)&&xe.push(t)})),xe.reverse();var Ae=e.useMemo((function(){return Math.min(.1,ye/Ce.length)}),[ye,Ce.length]),Se=e.useCallback((function(){ce.current&&clearTimeout(ce.current),$(!1),ae.current=ie.current,ae.current+=1,ce.current=setTimeout((function(){ie.current+=1,$(!0)}),20)}),[]),Me=e.useCallback((function(e){null==A||M||(ue.current=void 0),ee.current=e,Se()}),[A,M,Se]),Re=e.useCallback((function(e){var n=pe?A:ue.current;if(null==n||!l(n)||!l(U))return[];var t=Number(o(n)),r=Number(o(U)),a=Number(t.toString()[e]||0),i=Number(r.toString()[e]||0);return t<r?u((a+1)%10,i):u((i+1)%10,a)}),[pe,U,A]),ke=e.useCallback((function(){me((function(e){return e+1}))}),[]);e.useEffect((function(){null!=ue.current&&(te.current&&!ve.current||Se())}),[z,Se]),e.useEffect((function(){D&&Se()}),[D,Se]),e.useEffect((function(){requestAnimationFrame((function(){ve.current=!0}))}),[]),e.useImperativeHandle(i,(function(){return{startAnimation:Me,refreshStyles:ke}}));var we=A&&!D&&0===ae.current?Ee||[]:Ce,je=((null==Ee?void 0:Ee.length)||0)-we.length,qe=-1;return e.createElement("span",{key:fe,className:t(L,c)},we.map((function(n,r){var u,a,i=xe.includes(r),c=(i?xe.indexOf(r):0)*Ae,d=ue.current,m=null!=A&&!!M&&ae.current>1,v=null!=U&&null!=d&&l(U)&&l(d)&&o(U)<o(d);return(null===(u=ee.current)||void 0===u?void 0:u.direction)&&(v="top-down"===(null===(a=ee.current)||void 0===a?void 0:a.direction)),Z&&(v="top-down"===Z),!s(n)&&y.includes(n)?e.createElement("span",{key:_e.length-r-1,className:t(f,W)},n):(qe+=1,e.createElement(h,{key:_e.length-r-1,numbersRef:ne,active:Q,isChanged:i,charClassName:O,effectiveDuration:ye,delay:c,value:n,startValue:m||null==Ee?void 0:Ee[r-je],dummyList:F?Re(qe):le,hasInfiniteList:V,valueClassName:X,reverse:v,sequentialAnimationMode:F,useMonospaceWidth:G}))})))})));module.exports=g;
"use strict";var e=require("react"),n=function(){return n=Object.assign||function(e){for(var n,t=1,r=arguments.length;t<r;t++)for(var u in n=arguments[t])Object.prototype.hasOwnProperty.call(n,u)&&(e[u]=n[u]);return e},n.apply(this,arguments)};var t=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];return e.filter(Boolean).join(" ")},r=function(e,n){for(var t=[],r=e;r<n;r+=1)t.push(r);return t},u=function(e,n){for(var t=[],r=e;r!==n;)t.push(r),10===(r+=1)&&(r=0);return t},a=function(e,n){var t=Math.random()*(n-e);return Math.floor(t+e)},i=function(e){for(var n,t=function(e,n,t){if(t||2===arguments.length)for(var r,u=0,a=n.length;u<a;u++)!r&&u in n||(r||(r=Array.prototype.slice.call(n,0,u)),r[u]=n[u]);return e.concat(r||Array.prototype.slice.call(n))}([],e,!0),r=t.length-1;r>0;r-=1){var u=Math.floor(Math.random()*(r+1));n=[t[u],t[r]],t[r]=n[0],t[u]=n[1]}return t},o=function(e){return"number"==typeof e?e:(Array.isArray(e)?e.join(""):e).replace(/[,.]/g,"")},l=function(e){return"object"!=typeof e&&!Number.isNaN(o(e))},c=function(e){return"object"==typeof e};var s="index-module_slot_wrap__ZT-DX",d="index-module_slot__DpPgW",f="index-module_separator__7GhtE",m="index-module_numbers__sqlqm",v="index-module_num__j6XH3";!function(e,n){void 0===n&&(n={});var t=n.insertAt;if(e&&"undefined"!=typeof document){var r=document.head||document.getElementsByTagName("head")[0],u=document.createElement("style");u.type="text/css","top"===t&&r.firstChild?r.insertBefore(u,r.firstChild):r.appendChild(u),u.styleSheet?u.styleSheet.cssText=e:u.appendChild(document.createTextNode(e))}}(".index-module_slot_wrap__ZT-DX {\n display: inline-block;\n white-space: nowrap;\n}\n\n.index-module_slot__DpPgW {\n display: inline-block;\n overflow: hidden;\n text-align: center;\n vertical-align: bottom;\n will-change: transform;\n}\n\n.index-module_separator__7GhtE {\n display: inline-block;\n vertical-align: bottom;\n text-align: center;\n}\n\n.index-module_numbers__sqlqm {\n display: block;\n}\n\n.index-module_num__j6XH3 {\n display: block;\n}");var h="undefined"!=typeof window?e.useLayoutEffect:e.useEffect;var p=e.memo((function(r){var u,a,o=r.charClassName,l=r.numbersRef,c=r.active,s=r.isChanged,f=r.effectiveDuration,p=r.delay,y=r.value,g=r.startValue,b=r.dummyList,_=r.hasInfiniteList,N=r.valueClassName,C=r.reverse,x=r.sequentialAnimationMode,E=r.useMonospaceWidth,A=r.maxNumberWidth,S=e.useState(!1),M=S[0],R=S[1],k=e.useState(y),w=k[0],q=k[1],T=e.useRef(),j=e.useRef(y),D=e.useRef(null),W=e.useState(x?b:i(b)),L=W[0],O=W[1],B=e.useState(0),H=B[0],I=B[1],V=e.useState(!1),X=V[0],Y=V[1],F=H*(b.length+1);h((function(){Y(!0)}),[]),h((function(){var e,n;I(null!==(n=null===(e=D.current)||void 0===e?void 0:e.offsetHeight)&&void 0!==n?n:0)}),[X]),e.useEffect((function(){c?requestAnimationFrame((function(){R(c)})):R(c)}),[c]),e.useEffect((function(){M&&(T.current=j.current,j.current=y,setTimeout((function(){return q(y)}),x?0:1e3*f*1.3/b.length+1e3*p))}),[M,y,f,p,b.length,x]),e.useEffect((function(){O(x?b:i(b))}),[y,b,x]);var P=function(){return L.map((function(n,t){return e.createElement("span",{key:t,className:v,"aria-hidden":"true"},n)}))},G=C?w:null!=g?g:w;x&&(G=C?w:null!==(u=null!=g?g:T.current)&&void 0!==u?u:w);var Z=C&&null!=g?g:w;return x&&(Z=C&&null!==(a=null!=g?g:T.current)&&void 0!==a?a:w),e.createElement("span",{className:t(d,o),style:{display:"inline-block",width:X&&E?A:void 0,height:X?H:void 0}},e.createElement("span",{ref:l,className:m,style:n({transition:"none",transform:C?"translateY(-".concat(F,"px)"):"translateY(0px)"},M&&s&&{transform:C?"translateY(0px)":"translateY(-".concat(F,"px)"),transition:"transform ".concat(f,"s ").concat(p,"s ease-in-out")})},X?e.createElement(e.Fragment,null,e.createElement("span",{className:v,"aria-hidden":"true",style:{height:H}},G),P(),e.createElement("span",{className:t(v,N),ref:D},Z),_?P():null):e.createElement("span",{className:v,"aria-hidden":"true"},g||w)))}));var y=[",","."," "];var g=e.memo(e.forwardRef((function(n,i){var d,m,v,g,b,_,N,C,x,E,A=n.value,S=n.startValue,M=n.startValueOnce,R=void 0!==M&&M,k=n.duration,w=void 0===k?.7:k,q=n.dummyCharacters,T=n.dummyCharacterCount,j=void 0===T?6:T,D=n.autoAnimationStart,W=void 0===D||D,L=n.containerClassName,O=n.charClassName,B=n.separatorClassName,H=n.animateUnchanged,I=void 0!==H&&H,V=n.hasInfiniteList,X=void 0!==V&&V,Y=n.valueClassName,F=n.sequentialAnimationMode,P=void 0!==F&&F,G=n.useMonospaceWidth,Z=void 0!==G&&G,J=n.direction,U=n.debounceDelay,z=function(n,t){var r=e.useState(n),u=r[0],a=r[1];return e.useEffect((function(){if(0===t)return a(n);var e=setTimeout((function(){a(n)}),t);return function(){clearTimeout(e)}}),[n,t]),u}(A,null!=U?U:0),K=e.useMemo((function(){return function(e){return Array.isArray(e)&&c(e[0])}(z)?"":"object"==typeof z?JSON.stringify(z):z.toString()}),[z]),Q=e.useState(!1),$=Q[0],ee=Q[1],ne=e.useRef(),te=e.useRef(null),re=e.useRef(S),ue=e.useRef(null==S||W?z:S),ae=e.useRef(S),ie=e.useRef(0),oe=e.useRef(0),le=e.useState([]),ce=le[0],se=le[1],de=e.useRef(),fe=e.useState(0),me=fe[0],ve=fe[1],he=e.useState(),pe=he[0],ye=he[1],ge=e.useRef(!1),be=null!=S&&(!R||ie.current<1),_e=null!==(m=null===(d=ne.current)||void 0===d?void 0:d.dummyCharacterCount)&&void 0!==m?m:j,Ne=null!==(g=null===(v=ne.current)||void 0===v?void 0:v.duration)&&void 0!==g?g:w;h((function(){var e,n=te.current;if(n&&Z){var t=function(){var e=r(0,10).map((function(e){var t=document.createElement("span");t.style.position="absolute",t.style.top="0",t.style.left="-9999px",t.style.visibility="hidden",t.textContent=e.toString(),n.appendChild(t);var r=t.getBoundingClientRect().width;return n.removeChild(t),r})),t=Math.max.apply(Math,e);ye(t)};t(),null===(e=document.fonts)||void 0===e||e.ready.then((function(){t()}))}}),[]),e.useEffect((function(){se(r(0,_e-1).map((function(e){if(!q)return a(0,10);var n=e>=q.length?a(0,q.length):e;return q[n]})))}),[q,_e]),ue.current!==z&&ge.current&&oe.current>0&&(ae.current=ue.current,ue.current=z);var Ce=Array.isArray(ae.current)?ae.current:null!==(_=null===(b=ae.current)||void 0===b?void 0:b.toString().split(""))&&void 0!==_?_:[],xe=Array.isArray(ue.current)?ue.current:null!==(C=null===(N=ue.current)||void 0===N?void 0:N.toString().split(""))&&void 0!==C?C:[],Ee=Array.isArray(re.current)?re.current:null!==(E=null===(x=re.current)||void 0===x?void 0:x.toString().split(""))&&void 0!==E?E:[],Ae=e.useMemo((function(){return Array.isArray(z)?z:null==z?void 0:z.toString().split("")}),[z]),Se=e.useMemo((function(){return Array.isArray(S)?S:null==S?void 0:S.toString().split("")}),[S]),Me=Ce.length!==xe.length,Re=[];xe.forEach((function(e,n){var t=xe.length-n-1,r=be?Ee:Ce;(xe[t]!==r[t]||Me||I)&&Re.push(t)})),Re.reverse();var ke=e.useMemo((function(){return Math.min(.1,Ne/Ae.length)}),[Ne,Ae.length]),we=e.useCallback((function(){de.current&&clearTimeout(de.current),ee(!1),ie.current=oe.current,ie.current+=1,de.current=setTimeout((function(){oe.current+=1,ee(!0)}),20)}),[]),qe=e.useCallback((function(e){null==S||R||(ae.current=void 0),ne.current=e,we()}),[S,R,we]),Te=e.useCallback((function(e){var n=be?S:ae.current;if(null==n||!l(n)||!l(z))return[];var t=Number(o(n)),r=Number(o(z)),a=Number(t.toString()[e]||0),i=Number(r.toString()[e]||0);return t<r?u((a+1)%10,i):u((i+1)%10,a)}),[be,z,S]),je=e.useCallback((function(){ve((function(e){return e+1}))}),[]);e.useEffect((function(){(ge.current||null!=ae.current)&&(!ge.current&&re.current||we())}),[K,we]),e.useEffect((function(){W&&we()}),[W,we]),e.useEffect((function(){requestAnimationFrame((function(){ge.current=!0}))}),[]),e.useImperativeHandle(i,(function(){return{startAnimation:qe,refreshStyles:je}}));var De=S&&!W&&0===ie.current?Se||[]:Ae,We=((null==Se?void 0:Se.length)||0)-De.length,Le=-1;return e.createElement("span",{key:me,className:t(L,s)},De.map((function(n,r){var u,a,i=Re.includes(r),s=(i?Re.indexOf(r):0)*ke,d=ae.current,m=null!=S&&!!R&&ie.current>1,v=null!=z&&null!=d&&l(z)&&l(d)&&o(z)<o(d);return(null===(u=ne.current)||void 0===u?void 0:u.direction)&&(v="top-down"===(null===(a=ne.current)||void 0===a?void 0:a.direction)),J&&(v="top-down"===J),!c(n)&&y.includes(n)?e.createElement("span",{key:xe.length-r-1,className:t(f,B)},n):(Le+=1,e.createElement(p,{key:xe.length-r-1,maxNumberWidth:pe,numbersRef:te,active:$,isChanged:i,charClassName:O,effectiveDuration:Ne,delay:s,value:n,startValue:m||null==Se?void 0:Se[r-We],dummyList:P&&(!W||oe.current>1)?Te(Le):ce,hasInfiniteList:X,valueClassName:Y,reverse:v,sequentialAnimationMode:P,useMonospaceWidth:Z}))})))})));module.exports=g;
//# sourceMappingURL=index.js.map
{
"name": "react-slot-counter",
"version": "2.0.0",
"version": "2.0.1",
"description": "Make Your Numbers Pop: Simple and Dynamic Counters for Your UI",

@@ -5,0 +5,0 @@ "author": "almond-bongbong",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc