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 1.15.0 to 2.0.0

2

lib/index.esm.js
'use client';
import n,{memo as e,useState as t,useRef as r,useEffect as a,forwardRef as i,useMemo as o,useCallback as u,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 a in e=arguments[t])Object.prototype.hasOwnProperty.call(e,a)&&(n[a]=e[a]);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,a=0,i=e.length;a<i;a++)!r&&a in e||(r||(r=Array.prototype.slice.call(e,0,a)),r[a]=e[a]);return n.concat(r||Array.prototype.slice.call(e))}([],n,!0),r=t.length-1;r>0;r-=1){var a=Math.floor(Math.random()*(r+1));e=[t[a],t[r]],t[r]=e[0],t[a]=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],a=document.createElement("style");a.type="text/css","top"===t&&r.firstChild?r.insertBefore(a,r.firstChild):r.appendChild(a),a.styleSheet?a.styleSheet.cssText=n:a.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 C="undefined"!=typeof window?n.useLayoutEffect:n.useEffect;var A=e((function(e){var i=e.charClassName,o=e.numbersRef,u=e.active,l=e.isChanged,f=e.effectiveDuration,m=e.delay,p=e.value,y=e.startValue,g=e.dummyList,b=e.hasInfiniteList,A=e.valueClassName,E=e.reverse,w=e.sequentialAnimationMode,M=e.useMonospaceWidth,S=t(!1),k=S[0],T=S[1],j=t(p),q=j[0],D=j[1],L=r(),O=r(p),W=r(null),B=t(w?g:v(g)),V=B[0],X=B[1],Y=t(0),H=Y[0],I=Y[1],P=t(0),R=P[0],F=P[1],G=t(!1),Z=G[0],J=G[1],U=H*(g.length+1),z="object"!=typeof p&&h(p);C((function(){J(!0)}),[]),C((function(){var n,e;I(null!==(e=null===(n=W.current)||void 0===n?void 0:n.offsetHeight)&&void 0!==e?e:0)}),[Z]),C((function(){if(z&&M){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=W.current)||void 0===e||e.appendChild(r);var a=r.getBoundingClientRect().width;return null===(t=W.current)||void 0===t||t.removeChild(r),a})),e=Math.max.apply(Math,n);F(e)}}),[z,M,Z]),a((function(){u?requestAnimationFrame((function(){T(u)})):T(u)}),[u]),a((function(){k&&(L.current=O.current,O.current=p,setTimeout((function(){return D(p)}),w?0:1e3*f*1.3/g.length+1e3*m))}),[k,p,f,m,g.length,w]),a((function(){X(w?g:v(g))}),[p,g,w]);var K=function(){return V.map((function(e,t){return n.createElement("span",{key:t,className:x,"aria-hidden":"true"},e)}))};return n.createElement("span",{className:s(_,i),style:{display:"inline-block",width:Z&&M?R:void 0,height:Z?H:void 0}},n.createElement("span",{ref:o,className:N,style:c({transition:"none",transform:E?"translateY(-".concat(U,"px)"):"translateY(0px)"},k&&l&&{transform:E?"translateY(0px)":"translateY(-".concat(U,"px)"),transition:"transform ".concat(f,"s ").concat(m,"s ease-in-out")})},Z?n.createElement(n.Fragment,null,n.createElement("span",{className:x,"aria-hidden":"true",style:{height:H}},w&&(E?q:L.current),!w&&(E?q:null!=y?y:q)),K(),n.createElement("span",{className:s(x,A),ref:W},w&&(E?L.current:q),!w&&(E&&null!=y?y:q)),b?K():null):n.createElement("span",{className:x,"aria-hidden":"true"},y||q)))}));var E=[",","."," "];var w=e(i((function(e,i){var c,v,_,N,x,C,w,M,S=e.value,k=e.startValue,T=e.startValueOnce,j=void 0!==T&&T,q=e.duration,D=void 0===q?.7:q,L=e.dummyCharacters,O=e.dummyCharacterCount,W=void 0===O?6:O,B=e.autoAnimationStart,V=void 0===B||B,X=e.containerClassName,Y=e.charClassName,H=e.separatorClassName,I=e.animateUnchanged,P=void 0!==I&&I,R=e.hasInfiniteList,F=void 0!==R&&R,G=e.valueClassName,Z=e.sequentialAnimationMode,J=void 0!==Z&&Z,U=e.useMonospaceWidth,z=void 0!==U&&U,K=e.direction,Q=e.debounceDelay,$=function(n,e){var r=t(n),i=r[0],o=r[1];return a((function(){if(0===e)return o(n);var t=setTimeout((function(){o(n)}),e);return function(){clearTimeout(t)}}),[n,e]),i}(S,null!=Q?Q:0),nn=o((function(){return function(n){return Array.isArray(n)&&y(n[0])}($)?"":JSON.stringify($)}),[$]),en=t(!1),tn=en[0],rn=en[1],an=r(),on=r(null),un=r($),ln=r(k),cn=r(0),sn=r(0),dn=t([]),fn=dn[0],mn=dn[1],vn=r(),pn=t(0),hn=pn[0],yn=pn[1],gn=null!==(v=null===(c=an.current)||void 0===c?void 0:c.dummyCharacterCount)&&void 0!==v?v:W,_n=null!==(N=null===(_=an.current)||void 0===_?void 0:_.duration)&&void 0!==N?N:D;a((function(){mn(d(0,gn-1).map((function(n){if(!L)return m(0,10);var e=n>=L.length?m(0,L.length):n;return L[e]})))}),[L,gn]),o((function(){un.current!==$&&(ln.current=un.current,un.current=$)}),[$]);var bn=Array.isArray(ln.current)?ln.current:null!==(C=null===(x=ln.current)||void 0===x?void 0:x.toString().split(""))&&void 0!==C?C:[],Nn=Array.isArray(un.current)?un.current:null!==(M=null===(w=un.current)||void 0===w?void 0:w.toString().split(""))&&void 0!==M?M:[],xn=o((function(){return Array.isArray($)?$:null==$?void 0:$.toString().split("")}),[$]),Cn=o((function(){return Array.isArray(k)?k:null==k?void 0:k.toString().split("")}),[k]),An=bn.length!==Nn.length,En=[];Nn.forEach((function(n,e){var t=Nn.length-e-1;(Nn[t]!==bn[t]||An||P)&&En.push(t)})),En.reverse();var wn=o((function(){return Math.min(.1,_n/xn.length)}),[_n,xn.length]),Mn=u((function(){vn.current&&clearTimeout(vn.current),rn(!1),cn.current=sn.current,cn.current+=1,vn.current=setTimeout((function(){sn.current+=1,rn(!0)}),20)}),[]),Sn=u((function(n){ln.current=void 0,an.current=n,Mn()}),[Mn]),kn=u((function(n){var e=null!=k&&0===cn.current?k:ln.current;if(null==e||!h(e)||!h($))return[];var t=Number(p(e)),r=Number(p($)),a=Number(t.toString()[n]||0),i=Number(r.toString()[n]||0);return t<r?f((a+1)%10,i):f((i+1)%10,a)}),[$,k]),Tn=u((function(){yn((function(n){return n+1}))}),[]);a((function(){null!=ln.current&&Mn()}),[nn,Mn,V]),a((function(){V&&Mn()}),[V,Mn]),l(i,(function(){return{startAnimation:Sn,refreshStyles:Tn}}));var jn=-1;return n.createElement("span",{key:hn,className:s(X,g)},xn.map((function(e,t){var r,a,i=En.includes(t),o=(i?En.indexOf(t):0)*wn,u=ln.current,l=j&&cn.current>1,c=null!=$&&null!=u&&h($)&&h(u)&&p($)<p(u);return(null===(r=an.current)||void 0===r?void 0:r.direction)&&(c="top-down"===(null===(a=an.current)||void 0===a?void 0:a.direction)),K&&(c="top-down"===K),!y(e)&&E.includes(e)?n.createElement("span",{key:Nn.length-t-1,className:s(b,H)},e):(jn+=1,n.createElement(A,{key:Nn.length-t-1,numbersRef:on,active:tn,isChanged:i,charClassName:Y,effectiveDuration:_n,delay:o,value:e,startValue:l||null==Cn?void 0:Cn[t],dummyList:J?kn(jn):fn,hasInfiniteList:F,valueClassName:G,reverse:c,sequentialAnimationMode:J,useMonospaceWidth:z}))})))})));export{w 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},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};
//# 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 a in n=arguments[t])Object.prototype.hasOwnProperty.call(n,a)&&(e[a]=n[a]);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},a=function(e,n){for(var t=[],r=e;r!==n;)t.push(r),10===(r+=1)&&(r=0);return t},u=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,a=0,u=n.length;a<u;a++)!r&&a in n||(r||(r=Array.prototype.slice.call(n,0,a)),r[a]=n[a]);return e.concat(r||Array.prototype.slice.call(n))}([],e,!0),r=t.length-1;r>0;r-=1){var a=Math.floor(Math.random()*(r+1));n=[t[a],t[r]],t[r]=n[0],t[a]=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],a=document.createElement("style");a.type="text/css","top"===t&&r.firstChild?r.insertBefore(a,r.firstChild):r.appendChild(a),a.styleSheet?a.styleSheet.cssText=e:a.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(a){var u=a.charClassName,o=a.numbersRef,s=a.active,c=a.isChanged,f=a.effectiveDuration,h=a.delay,y=a.value,g=a.startValue,_=a.dummyList,b=a.hasInfiniteList,C=a.valueClassName,N=a.reverse,E=a.sequentialAnimationMode,x=a.useMonospaceWidth,S=e.useState(!1),A=S[0],M=S[1],k=e.useState(y),w=k[0],R=k[1],T=e.useRef(),j=e.useRef(y),q=e.useRef(null),D=e.useState(E?_:i(_)),L=D[0],O=D[1],W=e.useState(0),B=W[0],H=W[1],I=e.useState(0),V=I[0],X=I[1],Y=e.useState(!1),P=Y[0],F=Y[1],G=B*(_.length+1),Z="object"!=typeof y&&l(y);p((function(){F(!0)}),[]),p((function(){var e,n;H(null!==(n=null===(e=q.current)||void 0===e?void 0:e.offsetHeight)&&void 0!==n?n:0)}),[P]),p((function(){if(Z&&x){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=q.current)||void 0===n||n.appendChild(r);var a=r.getBoundingClientRect().width;return null===(t=q.current)||void 0===t||t.removeChild(r),a})),n=Math.max.apply(Math,e);X(n)}}),[Z,x,P]),e.useEffect((function(){s?requestAnimationFrame((function(){M(s)})):M(s)}),[s]),e.useEffect((function(){A&&(T.current=j.current,j.current=y,setTimeout((function(){return R(y)}),E?0:1e3*f*1.3/_.length+1e3*h))}),[A,y,f,h,_.length,E]),e.useEffect((function(){O(E?_:i(_))}),[y,_,E]);var J=function(){return L.map((function(n,t){return e.createElement("span",{key:t,className:v,"aria-hidden":"true"},n)}))};return e.createElement("span",{className:t(d,u),style:{display:"inline-block",width:P&&x?V:void 0,height:P?B:void 0}},e.createElement("span",{ref:o,className:m,style:n({transition:"none",transform:N?"translateY(-".concat(G,"px)"):"translateY(0px)"},A&&c&&{transform:N?"translateY(0px)":"translateY(-".concat(G,"px)"),transition:"transform ".concat(f,"s ").concat(h,"s ease-in-out")})},P?e.createElement(e.Fragment,null,e.createElement("span",{className:v,"aria-hidden":"true",style:{height:B}},E&&(N?w:T.current),!E&&(N?w:null!=g?g:w)),J(),e.createElement("span",{className:t(v,C),ref:q},E&&(N?T.current:w),!E&&(N&&null!=g?g:w)),b?J():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,p,g,_,b,C,N=n.value,E=n.startValue,x=n.startValueOnce,S=void 0!==x&&x,A=n.duration,M=void 0===A?.7:A,k=n.dummyCharacters,w=n.dummyCharacterCount,R=void 0===w?6:w,T=n.autoAnimationStart,j=void 0===T||T,q=n.containerClassName,D=n.charClassName,L=n.separatorClassName,O=n.animateUnchanged,W=void 0!==O&&O,B=n.hasInfiniteList,H=void 0!==B&&B,I=n.valueClassName,V=n.sequentialAnimationMode,X=void 0!==V&&V,Y=n.useMonospaceWidth,P=void 0!==Y&&Y,F=n.direction,G=n.debounceDelay,Z=function(n,t){var r=e.useState(n),a=r[0],u=r[1];return e.useEffect((function(){if(0===t)return u(n);var e=setTimeout((function(){u(n)}),t);return function(){clearTimeout(e)}}),[n,t]),a}(N,null!=G?G:0),J=e.useMemo((function(){return function(e){return Array.isArray(e)&&s(e[0])}(Z)?"":JSON.stringify(Z)}),[Z]),U=e.useState(!1),z=U[0],K=U[1],Q=e.useRef(),$=e.useRef(null),ee=e.useRef(Z),ne=e.useRef(E),te=e.useRef(0),re=e.useRef(0),ae=e.useState([]),ue=ae[0],ie=ae[1],oe=e.useRef(),le=e.useState(0),se=le[0],ce=le[1],de=null!==(m=null===(d=Q.current)||void 0===d?void 0:d.dummyCharacterCount)&&void 0!==m?m:R,fe=null!==(p=null===(v=Q.current)||void 0===v?void 0:v.duration)&&void 0!==p?p:M;e.useEffect((function(){ie(r(0,de-1).map((function(e){if(!k)return u(0,10);var n=e>=k.length?u(0,k.length):e;return k[n]})))}),[k,de]),e.useMemo((function(){ee.current!==Z&&(ne.current=ee.current,ee.current=Z)}),[Z]);var me=Array.isArray(ne.current)?ne.current:null!==(_=null===(g=ne.current)||void 0===g?void 0:g.toString().split(""))&&void 0!==_?_:[],ve=Array.isArray(ee.current)?ee.current:null!==(C=null===(b=ee.current)||void 0===b?void 0:b.toString().split(""))&&void 0!==C?C:[],pe=e.useMemo((function(){return Array.isArray(Z)?Z:null==Z?void 0:Z.toString().split("")}),[Z]),he=e.useMemo((function(){return Array.isArray(E)?E:null==E?void 0:E.toString().split("")}),[E]),ye=me.length!==ve.length,ge=[];ve.forEach((function(e,n){var t=ve.length-n-1;(ve[t]!==me[t]||ye||W)&&ge.push(t)})),ge.reverse();var _e=e.useMemo((function(){return Math.min(.1,fe/pe.length)}),[fe,pe.length]),be=e.useCallback((function(){oe.current&&clearTimeout(oe.current),K(!1),te.current=re.current,te.current+=1,oe.current=setTimeout((function(){re.current+=1,K(!0)}),20)}),[]),Ce=e.useCallback((function(e){ne.current=void 0,Q.current=e,be()}),[be]),Ne=e.useCallback((function(e){var n=null!=E&&0===te.current?E:ne.current;if(null==n||!l(n)||!l(Z))return[];var t=Number(o(n)),r=Number(o(Z)),u=Number(t.toString()[e]||0),i=Number(r.toString()[e]||0);return t<r?a((u+1)%10,i):a((i+1)%10,u)}),[Z,E]),Ee=e.useCallback((function(){ce((function(e){return e+1}))}),[]);e.useEffect((function(){null!=ne.current&&be()}),[J,be,j]),e.useEffect((function(){j&&be()}),[j,be]),e.useImperativeHandle(i,(function(){return{startAnimation:Ce,refreshStyles:Ee}}));var xe=-1;return e.createElement("span",{key:se,className:t(q,c)},pe.map((function(n,r){var a,u,i=ge.includes(r),c=(i?ge.indexOf(r):0)*_e,d=ne.current,m=S&&te.current>1,v=null!=Z&&null!=d&&l(Z)&&l(d)&&o(Z)<o(d);return(null===(a=Q.current)||void 0===a?void 0:a.direction)&&(v="top-down"===(null===(u=Q.current)||void 0===u?void 0:u.direction)),F&&(v="top-down"===F),!s(n)&&y.includes(n)?e.createElement("span",{key:ve.length-r-1,className:t(f,L)},n):(xe+=1,e.createElement(h,{key:ve.length-r-1,numbersRef:$,active:z,isChanged:i,charClassName:D,effectiveDuration:fe,delay:c,value:n,startValue:m||null==he?void 0:he[r],dummyList:X?Ne(xe):ue,hasInfiniteList:H,valueClassName:I,reverse:v,sequentialAnimationMode:X,useMonospaceWidth:P}))})))})));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))},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;
//# sourceMappingURL=index.js.map
{
"name": "react-slot-counter",
"version": "1.15.0",
"version": "2.0.0",
"description": "Make Your Numbers Pop: Simple and Dynamic Counters for Your UI",

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

# react-slot-counter 🎰
> 🎉 New in 2.0.0: Major bug fixes! Check out the CHANGELOG for all the details.
Make Your Numbers Pop 🌟: Simple and Dynamic Counters for Your UI

@@ -4,0 +6,0 @@

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