number-flow 0.3.10 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -17,7 +17,7 @@ type KeyedPart = {
17
17
  key: NumberPartKey;
18
18
  };
19
19
  export type KeyedDigitPart = DigitPart & KeyedPart & {
20
- place: number;
20
+ pos: number;
21
21
  };
22
22
  export type KeyedSymbolPart = SymbolPart & KeyedPart;
23
23
  export type KeyedNumberPart = KeyedDigitPart | KeyedSymbolPart;
package/dist/index.d.ts CHANGED
@@ -5,25 +5,24 @@ export { prefersReducedMotion } from './styles';
5
5
  export { renderInnerHTML } from './ssr';
6
6
  export * from './formatter';
7
7
  export declare const canAnimate: boolean;
8
- type RawTrend = boolean | 'increasing' | 'decreasing';
9
- export { type RawTrend as Trend };
10
- declare enum Trend {
11
- UP = 1,
12
- DOWN = -1,
13
- NONE = 0
14
- }
8
+ export type Trend = number | ((oldValue: number, value: number) => number);
9
+ export type DigitOptions = {
10
+ max?: number;
11
+ };
12
+ export type Digits = Record<number, DigitOptions>;
15
13
  export interface Props {
16
14
  transformTiming: EffectTiming;
17
15
  spinTiming: EffectTiming | undefined;
18
16
  opacityTiming: EffectTiming;
19
17
  animated: boolean;
20
18
  respectMotionPreference: boolean;
21
- trend: RawTrend;
19
+ trend: Trend;
22
20
  continuous: boolean;
21
+ digits: Digits | undefined;
23
22
  }
24
23
  export declare class NumberFlowLite extends ServerSafeHTMLElement implements Props {
25
24
  /**
26
- * Use `private _private` properties instead of `_private` to avoid _private polyfill and
25
+ * Use `private _private` properties instead of `#private` to avoid # polyfill and
27
26
  * reduce bundle size. Also, use `readonly` properties instead of getters to save on bundle
28
27
  * size, even though you have to do gross stuff like `(this as Mutable<...>)` until TS
29
28
  * supports e.g. https://github.com/microsoft/TypeScript/issues/37487
@@ -33,8 +32,9 @@ export declare class NumberFlowLite extends ServerSafeHTMLElement implements Pro
33
32
  spinTiming: EffectTiming | undefined;
34
33
  opacityTiming: EffectTiming;
35
34
  respectMotionPreference: boolean;
36
- trend: RawTrend;
35
+ trend: Trend;
37
36
  continuous: boolean;
37
+ digits: Digits | undefined;
38
38
  private _animated;
39
39
  get animated(): boolean;
40
40
  set animated(val: boolean);
@@ -44,9 +44,9 @@ export declare class NumberFlowLite extends ServerSafeHTMLElement implements Pro
44
44
  private _num?;
45
45
  private _post?;
46
46
  private _computedTrend?;
47
- get computedTrend(): Trend | undefined;
48
- private _startingPlace?;
49
- get startingPlace(): number | null | undefined;
47
+ get computedTrend(): number | undefined;
48
+ private _startingPos?;
49
+ get startingPos(): number | null | undefined;
50
50
  private _computedAnimated;
51
51
  get computedAnimated(): boolean;
52
52
  private _data?;
package/dist/index.js CHANGED
@@ -1,10 +1,10 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const v=require("esm-env"),y=(s,t,e)=>{const i=document.createElement(s),[n,r]=Array.isArray(t)?[void 0,t]:[t,e];return n&&Object.assign(i,n),r==null||r.forEach(o=>i.appendChild(o)),i},X=(s,t)=>{var e;return t==="left"?s.offsetLeft:(((e=s.offsetParent instanceof HTMLElement?s.offsetParent:null)==null?void 0:e.offsetWidth)??0)-s.offsetWidth-s.offsetLeft},I=s=>s.offsetWidth>0&&s.offsetHeight>0,z=(s,t)=>{if(!(!v.BROWSER||customElements.get(s)===t))return customElements.define(s,t)};function Y(s,t,{reverse:e=!1}={}){const i=s.length;for(let n=e?i-1:0;e?n>=0:n<i;e?n--:n++)t(s[n],n)}function q(s,t,e,i){const n=t.formatToParts(s);e&&n.unshift({type:"prefix",value:e}),i&&n.push({type:"suffix",value:i});const r=[],o=[],a=[],u=[],p={},d=c=>`${c}:${p[c]=(p[c]??-1)+1}`;let w="",h=!1,m=!1;for(const c of n){w+=c.value;const l=c.type==="minusSign"||c.type==="plusSign"?"sign":c.type;l==="integer"?(h=!0,o.push(...c.value.split("").map(P=>({type:l,value:parseInt(P)})))):l==="group"?o.push({type:l,value:c.value}):l==="decimal"?(m=!0,a.push({type:l,value:c.value,key:d(l)})):l==="fraction"?a.push(...c.value.split("").map(P=>({type:l,value:parseInt(P),key:d(l),place:-1-p[l]}))):(h||m?u:r).push({type:l,value:c.value,key:d(l)})}const j=[];for(let c=o.length-1;c>=0;c--){const l=o[c];j.unshift(l.type==="integer"?{...l,key:d(l.type),place:p[l.type]}:{...l,key:d(l.type)})}return{pre:r,integer:j,fraction:a,post:u,valueAsString:w,value:typeof s=="string"?parseFloat(s):s}}const G=String.raw,O=String.raw,K=v.BROWSER&&typeof CSS<"u"&&CSS.supports&&CSS.supports("animation-timing-function","linear(1,2)"),Z=v.BROWSER&&typeof CSS<"u"&&CSS.supports&&CSS.supports("line-height","mod(1,1)"),x=v.BROWSER&&typeof matchMedia<"u"?matchMedia("(prefers-reduced-motion: reduce)"):null,R="--_number-flow-d-opacity",U="--_number-flow-d-width",C="--_number-flow-dx",A="--_number-flow-d",J=(()=>{try{return CSS.registerProperty({name:R,syntax:"<number>",inherits:!1,initialValue:"0"}),CSS.registerProperty({name:C,syntax:"<length>",inherits:!0,initialValue:"0px"}),CSS.registerProperty({name:U,syntax:"<number>",inherits:!1,initialValue:"0"}),CSS.registerProperty({name:A,syntax:"<number>",inherits:!0,initialValue:"0"}),!0}catch{return!1}})(),N="var(--number-flow-char-height, 1em)",f="var(--number-flow-mask-height, 0.25em)",E=`calc(${f} / 2)`,k="var(--number-flow-mask-width, 0.5em)",_=`calc(${k} / var(--scale-x))`,b="#000 0, transparent 71%",L=O`:host{display:inline-block;direction:ltr;white-space:nowrap;line-height:${N} !important;isolation:isolate;}.number,.number__inner{display:inline-block;transform-origin:left top;}:host([data-will-change]) :is(.number,.number__inner,.section,.digit,.digit__num,.symbol){will-change:transform;}.number{--scale-x:calc(1 + var(${U}) / var(--width));transform:translateX(var(${C})) scaleX(var(--scale-x));margin:0 calc(-1 * ${k});position:relative;z-index:-1;-webkit-mask-image:linear-gradient( to right,transparent 0,#000 ${_},#000 calc(100% - ${_}),transparent ),linear-gradient( to bottom,transparent 0,#000 ${f},#000 calc(100% - ${f}),transparent 100% ),radial-gradient(at bottom right,${b}),radial-gradient(at bottom left,${b}),radial-gradient(at top left,${b}),radial-gradient(at top right,${b});-webkit-mask-size:100% calc(100% - ${f} * 2),calc(100% - ${_} * 2) 100%,${_} ${f},${_} ${f},${_} ${f},${_} ${f};-webkit-mask-position:center,center,top left,top right,bottom right,bottom left;-webkit-mask-repeat:no-repeat;}.number__inner{padding:${E} ${k};transform:scaleX(calc(1 / var(--scale-x))) translateX(calc(-1 * var(${C})));}.section{display:inline-block;position:relative;isolation:isolate;}.section::after{content:'\200b';display:inline-block;padding:${E} 0;}.section--justify-left{transform-origin:center left;}.section--justify-right{transform-origin:center right;}.section__exiting,.symbol__exiting{margin:0 !important;position:absolute !important;z-index:-1;}.digit{display:inline-block;position:relative;--c:var(--current) + var(${A});}.digit__num{display:inline-block;padding:${E} 0;--offset-raw:mod(10 + var(--n) - mod(var(--c),10),10);--offset:calc(var(--offset-raw) - 10 * round(down,var(--offset-raw) / 5,1));--y:clamp(-100%,var(--offset) * 100%,100%);transform:translateY(var(--y));}.digit__num:not(.is-current){position:absolute;top:0;left:50%;transform:translateX(-50%) translateY(var(--y));}.digit:not(.is-spinning) .digit__num:not(.is-current){display:none;}.symbol{display:inline-block;position:relative;isolation:isolate;}.symbol__value{display:inline-block;mix-blend-mode:plus-lighter;white-space:pre;}.section--justify-left .symbol__exiting{left:0;}.section--justify-right .symbol__exiting{right:0;}.animate-presence{opacity:calc(1 + var(${R}));}`,Q=v.BROWSER?HTMLElement:class{},tt=O`:host{display:inline-block;direction:ltr;white-space:nowrap;line-height:${N} !important;}span{display:inline-block;}:host([data-will-change]) span{will-change:transform;}.number,.digit{padding:${E} 0;}.symbol{white-space:pre;}`,et=s=>`<span class="${s.type==="integer"||s.type==="fraction"?"digit":"symbol"}" part="${s.type==="integer"||s.type==="fraction"?`digit ${s.type}-digit`:s.type}">${s.value}</span>`,S=(s,t)=>`<span part="${t}">${s.reduce((e,i)=>e+et(i),"")}</span>`,it=s=>G`<template shadowroot="open" shadowrootmode="open"
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const v=require("esm-env"),g=(n,t,e)=>{const i=document.createElement(n),[s,a]=Array.isArray(t)?[void 0,t]:[t,e];return s&&Object.assign(i,s),a==null||a.forEach(r=>i.appendChild(r)),i},X=(n,t)=>{var e;return t==="left"?n.offsetLeft:(((e=n.offsetParent instanceof HTMLElement?n.offsetParent:null)==null?void 0:e.offsetWidth)??0)-n.offsetWidth-n.offsetLeft},D=n=>n.offsetWidth>0&&n.offsetHeight>0,I=(n,t)=>{if(!(!v.BROWSER||customElements.get(n)===t))return customElements.define(n,t)};function z(n,t,{reverse:e=!1}={}){const i=n.length;for(let s=e?i-1:0;e?s>=0:s<i;e?s--:s++)t(n[s],s)}function Y(n,t,e,i){const s=t.formatToParts(n);e&&s.unshift({type:"prefix",value:e}),i&&s.push({type:"suffix",value:i});const a=[],r=[],o=[],d=[],u={},p=c=>`${c}:${u[c]=(u[c]??-1)+1}`;let y="",h=!1,f=!1;for(const c of s){y+=c.value;const l=c.type==="minusSign"||c.type==="plusSign"?"sign":c.type;l==="integer"?(h=!0,r.push(...c.value.split("").map(E=>({type:l,value:parseInt(E)})))):l==="group"?r.push({type:l,value:c.value}):l==="decimal"?(f=!0,o.push({type:l,value:c.value,key:p(l)})):l==="fraction"?o.push(...c.value.split("").map(E=>({type:l,value:parseInt(E),key:p(l),pos:-1-u[l]}))):(h||f?d:a).push({type:l,value:c.value,key:p(l)})}const j=[];for(let c=r.length-1;c>=0;c--){const l=r[c];j.unshift(l.type==="integer"?{...l,key:p(l.type),pos:u[l.type]}:{...l,key:p(l.type)})}return{pre:a,integer:j,fraction:o,post:d,valueAsString:y,value:typeof n=="string"?parseFloat(n):n}}const q=String.raw,W=String.raw,G=v.BROWSER&&typeof CSS<"u"&&CSS.supports&&CSS.supports("animation-timing-function","linear(1,2)"),K=v.BROWSER&&typeof CSS<"u"&&CSS.supports&&CSS.supports("line-height","mod(1,1)"),$=v.BROWSER&&typeof matchMedia<"u"?matchMedia("(prefers-reduced-motion: reduce)"):null,R="--_number-flow-d-opacity",T="--_number-flow-d-width",C="--_number-flow-dx",A="--_number-flow-d",Z=(()=>{try{return CSS.registerProperty({name:R,syntax:"<number>",inherits:!1,initialValue:"0"}),CSS.registerProperty({name:C,syntax:"<length>",inherits:!0,initialValue:"0px"}),CSS.registerProperty({name:T,syntax:"<number>",inherits:!1,initialValue:"0"}),CSS.registerProperty({name:A,syntax:"<number>",inherits:!0,initialValue:"0"}),!0}catch{return!1}})(),U="var(--number-flow-char-height, 1em)",m="var(--number-flow-mask-height, 0.25em)",x=`calc(${m} / 2)`,P="var(--number-flow-mask-width, 0.5em)",_=`calc(${P} / var(--scale-x))`,w="#000 0, transparent 71%",L=W`:host{display:inline-block;direction:ltr;white-space:nowrap;line-height:${U} !important;isolation:isolate}.number,.number__inner{display:inline-block;transform-origin:left top}:host([data-will-change]) :is(.number,.number__inner,.section,.digit,.digit__num,.symbol){will-change:transform}.number{--scale-x:calc(1 + var(${T}) / var(--width));transform:translateX(var(${C})) scaleX(var(--scale-x));margin:0 calc(-1 * ${P});position:relative;-webkit-mask-image:linear-gradient(to right,transparent 0,#000 ${_},#000 calc(100% - ${_}),transparent ),linear-gradient(to bottom,transparent 0,#000 ${m},#000 calc(100% - ${m}),transparent 100% ),radial-gradient(at bottom right,${w}),radial-gradient(at bottom left,${w}),radial-gradient(at top left,${w}),radial-gradient(at top right,${w});-webkit-mask-size:100% calc(100% - ${m} * 2),calc(100% - ${_} * 2) 100%,${_} ${m},${_} ${m},${_} ${m},${_} ${m};-webkit-mask-position:center,center,top left,top right,bottom right,bottom left;-webkit-mask-repeat:no-repeat}.number__inner{padding:${x} ${P};transform:scaleX(calc(1 / var(--scale-x))) translateX(calc(-1 * var(${C})))}:host > :not(.number){z-index:5}.section,.symbol{display:inline-block;position:relative;isolation:isolate}.section::after{content:'\200b';display:inline-block;padding:${x} 0}.section--justify-left{transform-origin:center left}.section--justify-right{transform-origin:center right}.section__exiting,.symbol__exiting{margin:0 !important;position:absolute !important;z-index:-1}.digit{display:inline-block;position:relative;--c:var(--current) + var(${A})}.digit__num{display:inline-block;padding:${x} 0;--offset-raw:mod(var(--length) + var(--n) - mod(var(--c),var(--length)),var(--length));--offset:calc(var(--offset-raw) - var(--length) * round(down,var(--offset-raw) / (var(--length)/2),1));--y:clamp(-100%,var(--offset) * 100%,100%);transform:translateY(var(--y))}.digit__num:not(.is-current){position:absolute;top:0;left:50%;transform:translateX(-50%) translateY(var(--y))}.digit:not(.is-spinning) .digit__num:not(.is-current){display:none}.symbol__value{display:inline-block;mix-blend-mode:plus-lighter;white-space:pre}.section--justify-left .symbol__exiting{left:0}.section--justify-right .symbol__exiting{right:0}.animate-presence{opacity:calc(1 + var(${R}))}`,J=v.BROWSER?HTMLElement:class{},Q=W`:host{display:inline-block;direction:ltr;white-space:nowrap;line-height:${U} !important}span{display:inline-block}:host([data-will-change]) span{will-change:transform}.number,.digit{padding:${x} 0}.symbol{white-space:pre}`,tt=n=>`<span class="${n.type==="integer"||n.type==="fraction"?"digit":"symbol"}" part="${n.type==="integer"||n.type==="fraction"?`digit ${n.type}-digit`:n.type}">${n.value}</span>`,b=(n,t)=>`<span part="${t}">${n.reduce((e,i)=>e+tt(i),"")}</span>`,et=n=>q`<template shadowroot="open" shadowrootmode="open"
2
2
  ><style>
3
- ${tt}</style
4
- >${S(s.pre,"left")}<span part="number" class="number"
5
- >${S(s.integer,"integer")}${S(s.fraction,"fraction")}</span
6
- >${S(s.post,"right")}</template
3
+ ${Q}</style
4
+ >${b(n.pre,"left")}<span part="number" class="number"
5
+ >${b(n.integer,"integer")}${b(n.fraction,"fraction")}</span
6
+ >${b(n.post,"right")}</template
7
7
  ><span
8
- style="font-kerning: none; display: inline-block; line-height: ${N} !important; padding: ${f} 0;"
9
- >${s.valueAsString}</span
10
- >`,st=(s,t)=>s!=null&&t==null?s:s==null&&t!=null?t:s!=null&&t!=null?Math.max(s,t):null,V=Z&&K&&J;var g;(function(s){s[s.UP=1]="UP",s[s.DOWN=-1]="DOWN",s[s.NONE=0]="NONE"})(g||(g={}));let $;class B extends Q{constructor(){super(...arguments),this.transformTiming=this.constructor.defaultProps.transformTiming,this.spinTiming=this.constructor.defaultProps.spinTiming,this.opacityTiming=this.constructor.defaultProps.opacityTiming,this.respectMotionPreference=this.constructor.defaultProps.respectMotionPreference,this.trend=this.constructor.defaultProps.trend,this.continuous=this.constructor.defaultProps.continuous,this._animated=this.constructor.defaultProps.animated,this._created=!1,this._computedAnimated=this._animated,this.manual=!1}get animated(){return this._animated}set animated(t){var e;this.animated!==t&&(this._animated=t,(e=this.shadowRoot)==null||e.getAnimations().forEach(i=>i.finish()))}get created(){return this._created}get computedTrend(){return this._computedTrend}get startingPlace(){return this._startingPlace}get computedAnimated(){return this._computedAnimated}set data(t){if(t==null)return;const{pre:e,integer:i,fraction:n,post:r,value:o}=t;if(this._created){const a=this._data;if(this._data=t,this.trend===!0?this._computedTrend=Math.sign(o-a.value):this.trend==="increasing"?this._computedTrend=g.UP:this.trend==="decreasing"?this._computedTrend=g.DOWN:this._computedTrend=g.NONE,this._startingPlace=void 0,this._computedTrend!==g.NONE&&this.continuous){const u=a.integer.concat(a.fraction).filter(h=>h.type==="integer"||h.type==="fraction"),p=t.integer.concat(t.fraction).filter(h=>h.type==="integer"||h.type==="fraction"),d=u.find(h=>!p.find(m=>m.place===h.place&&m.value===h.value)),w=p.find(h=>!u.find(m=>h.place===m.place&&h.value===m.value));this._startingPlace=st(d==null?void 0:d.place,w==null?void 0:w.place)}this._computedAnimated=V&&this._animated&&(!this.respectMotionPreference||!(x!=null&&x.matches))&&I(this),this.manual||this.willUpdate(),this._pre.update(e),this._num.update({integer:i,fraction:n}),this._post.update(r),this.manual||this.didUpdate()}else{if(this._data=t,this.attachShadow({mode:"open"}),typeof CSSStyleSheet<"u"&&this.shadowRoot.adoptedStyleSheets)$||($=new CSSStyleSheet,$.replaceSync(L)),this.shadowRoot.adoptedStyleSheets=[$];else{const a=document.createElement("style");a.textContent=L,this.shadowRoot.appendChild(a)}this._pre=new W(this,e,{justify:"right",part:"left"}),this.shadowRoot.appendChild(this._pre.el),this._num=new nt(this,i,n),this.shadowRoot.appendChild(this._num.el),this._post=new W(this,r,{justify:"left",part:"right"}),this.shadowRoot.appendChild(this._post.el)}this._created=!0}willUpdate(){this._pre.willUpdate(),this._num.willUpdate(),this._post.willUpdate()}didUpdate(){if(!this._computedAnimated)return;this._abortAnimationsFinish?this._abortAnimationsFinish.abort():this.dispatchEvent(new Event("animationsstart")),this._pre.didUpdate(),this._num.didUpdate(),this._post.didUpdate();const t=new AbortController;Promise.all(this.shadowRoot.getAnimations().map(e=>e.finished)).then(()=>{t.signal.aborted||(this.dispatchEvent(new Event("animationsfinish")),this._abortAnimationsFinish=void 0)}),this._abortAnimationsFinish=t}}B.defaultProps={transformTiming:{duration:900,easing:"linear(0,.005,.019,.039,.066,.096,.129,.165,.202,.24,.278,.316,.354,.39,.426,.461,.494,.526,.557,.586,.614,.64,.665,.689,.711,.731,.751,.769,.786,.802,.817,.831,.844,.856,.867,.877,.887,.896,.904,.912,.919,.925,.931,.937,.942,.947,.951,.955,.959,.962,.965,.968,.971,.973,.976,.978,.98,.981,.983,.984,.986,.987,.988,.989,.99,.991,.992,.992,.993,.994,.994,.995,.995,.996,.996,.9963,.9967,.9969,.9972,.9975,.9977,.9979,.9981,.9982,.9984,.9985,.9987,.9988,.9989,1)"},spinTiming:void 0,opacityTiming:{duration:450,easing:"ease-out"},animated:!0,trend:!0,continuous:!1,respectMotionPreference:!0};class nt{constructor(t,e,i,{className:n,...r}={}){this.flow=t,this._integer=new M(t,e,{justify:"right",part:"integer"}),this._fraction=new M(t,i,{justify:"left",part:"fraction"}),this._inner=y("span",{className:"number__inner"},[this._integer.el,this._fraction.el]),this.el=y("span",{...r,part:"number",className:`number ${n??""}`},[this._inner])}willUpdate(){this._prevWidth=this.el.offsetWidth,this._prevLeft=this.el.getBoundingClientRect().left,this._integer.willUpdate(),this._fraction.willUpdate()}update({integer:t,fraction:e}){this._integer.update(t),this._fraction.update(e)}didUpdate(){const t=this.el.getBoundingClientRect();this._integer.didUpdate(),this._fraction.didUpdate();const e=this._prevLeft-t.left,i=this.el.offsetWidth,n=this._prevWidth-i;this.el.style.setProperty("--width",String(i)),this.el.animate({[C]:[`${e}px`,"0px"],[U]:[n,0]},{...this.flow.transformTiming,composite:"accumulate"})}}class D{constructor(t,e,{justify:i,className:n,...r},o){this.flow=t,this.children=new Map,this.onCharRemove=u=>()=>{this.children.delete(u)},this.justify=i;const a=e.map(u=>this.addChar(u).el);this.el=y("span",{...r,className:`section section--justify-${i} ${n??""}`},o?o(a):a)}addChar(t,{startDigitsAtZero:e=!1,...i}={}){const n=t.type==="integer"||t.type==="fraction"?new H(this,t.type,e?0:t.value,t.place,{...i,onRemove:this.onCharRemove(t.key)}):new at(this,t.type,t.value,{...i,onRemove:this.onCharRemove(t.key)});return this.children.set(t.key,n),n}unpop(t){t.el.classList.remove("section__exiting"),t.el.style.top="",t.el.style[this.justify]=""}pop(t){t.forEach(e=>{e.el.style.top=`${e.el.offsetTop}px`,e.el.style[this.justify]=`${X(e.el,this.justify)}px`}),t.forEach(e=>{e.el.classList.add("section__exiting"),e.present=!1})}addNewAndUpdateExisting(t){const e=new Map,i=new Map,n=this.justify==="left",r=n?"prepend":"append";if(Y(t,o=>{let a;this.children.has(o.key)?(a=this.children.get(o.key),i.set(o,a),this.unpop(a),a.present=!0):(a=this.addChar(o,{startDigitsAtZero:!0,animateIn:!0}),e.set(o,a)),this.el[r](a.el)},{reverse:n}),this.flow.computedAnimated){const o=this.el.getBoundingClientRect();e.forEach(a=>{a.willUpdate(o)})}e.forEach((o,a)=>{o.update(a.value)}),i.forEach((o,a)=>{o.update(a.value)})}willUpdate(){const t=this.el.getBoundingClientRect();this._prevOffset=t[this.justify],this.children.forEach(e=>e.willUpdate(t))}didUpdate(){const t=this.el.getBoundingClientRect();this.children.forEach(n=>n.didUpdate(t));const e=t[this.justify],i=this._prevOffset-e;i&&this.children.size&&this.el.animate({transform:[`translateX(${i}px)`,"none"]},{...this.flow.transformTiming,composite:"accumulate"})}}class M extends D{update(t){const e=new Map;this.children.forEach((i,n)=>{t.find(r=>r.key===n)||e.set(n,i),this.unpop(i)}),this.addNewAndUpdateExisting(t),e.forEach(i=>{i instanceof H&&i.update(0)}),this.pop(e)}}class W extends D{update(t){const e=new Map;this.children.forEach((i,n)=>{t.find(r=>r.key===n)||e.set(n,i)}),this.pop(e),this.addNewAndUpdateExisting(t)}}class T{constructor(t,e,{onRemove:i,animateIn:n=!1}={}){this.flow=t,this.el=e,this._present=!0,this._remove=()=>{var r;this.el.remove(),(r=this._onRemove)==null||r.call(this)},this.el.classList.add("animate-presence"),this.flow.computedAnimated&&n&&this.el.animate({[R]:[-.9999,0]},{...this.flow.opacityTiming,composite:"accumulate"}),this._onRemove=i}get present(){return this._present}set present(t){if(this._present!==t){if(this._present=t,!this.flow.computedAnimated){t||this._remove();return}this.el.style.setProperty("--_number-flow-d-opacity",t?"0":"-.999"),this.el.animate({[R]:t?[-.9999,0]:[.999,0]},{...this.flow.opacityTiming,composite:"accumulate"}),t?this.flow.removeEventListener("animationsfinish",this._remove):this.flow.addEventListener("animationsfinish",this._remove,{once:!0})}}}class F extends T{constructor(t,e,i,n){super(t.flow,i,n),this.section=t,this.value=e,this.el=i}}class H extends F{constructor(t,e,i,n,r){const o=Array.from({length:10}).map((u,p)=>{const d=y("span",{className:`digit__num${p===i?" is-current":""}`},[document.createTextNode(String(p))]);return d.style.setProperty("--n",String(p)),d}),a=y("span",{part:`digit ${e}-digit`,className:"digit"},o);a.style.setProperty("--current",String(i)),super(t,i,a,r),this.place=n,this._onAnimationsFinish=()=>{this.el.classList.remove("is-spinning")},this._numbers=o}willUpdate(t){const e=this.el.getBoundingClientRect();this._prevValue=this.value;const i=e[this.section.justify]-t[this.section.justify],n=e.width/2;this._prevCenter=this.section.justify==="left"?i+n:i-n}update(t){var e,i;(e=this._numbers[this.value])==null||e.classList.remove("is-current"),this.el.style.setProperty("--current",String(t)),(i=this._numbers[t])==null||i.classList.add("is-current"),this.value=t}didUpdate(t){const e=this.el.getBoundingClientRect(),i=e[this.section.justify]-t[this.section.justify],n=e.width/2,r=this.section.justify==="left"?i+n:i-n,o=this._prevCenter-r;o&&this.el.animate({transform:[`translateX(${o}px)`,"none"]},{...this.flow.transformTiming,composite:"accumulate"});const a=this.diff;a&&(this.el.classList.add("is-spinning"),this.el.animate({[A]:[-a,0]},{...this.flow.spinTiming??this.flow.transformTiming,composite:"accumulate"}),this.flow.addEventListener("animationsfinish",this._onAnimationsFinish,{once:!0}))}get diff(){let t=this.flow.computedTrend;const e=this.value-this._prevValue;return!e&&this.flow.startingPlace!=null&&this.flow.startingPlace>=this.place?10*t:(t||(t=Math.sign(e)),t===g.DOWN&&this.value>this._prevValue?this.value-10-this._prevValue:t===g.UP&&this.value<this._prevValue?10-this._prevValue+this.value:e)}}class at extends F{constructor(t,e,i,n){const r=y("span",{className:"symbol__value",textContent:i});super(t,i,y("span",{part:e,className:"symbol"},[r]),n),this.type=e,this._children=new Map,this._onChildRemove=o=>()=>{this._children.delete(o)},this._children.set(i,new T(this.flow,r,{onRemove:this._onChildRemove(i)}))}willUpdate(t){if(this.type==="decimal")return;const e=this.el.getBoundingClientRect();this._prevOffset=e[this.section.justify]-t[this.section.justify]}update(t){if(this.value!==t){const e=this._children.get(this.value);if(e.present=!1,e.el.classList.add("symbol__exiting"),this._children.has(t)){const i=this._children.get(t);i.present=!0,i.el.classList.remove("symbol__exiting")}else{const i=y("span",{className:"symbol__value",textContent:t});this.el.appendChild(i),this._children.set(t,new T(this.flow,i,{animateIn:!0,onRemove:this._onChildRemove(t)}))}}this.value=t}didUpdate(t){if(this.type==="decimal")return;const i=this.el.getBoundingClientRect()[this.section.justify]-t[this.section.justify],n=this._prevOffset-i;n&&this.el.animate({transform:[`translateX(${n}px)`,"none"]},{...this.flow.transformTiming,composite:"accumulate"})}}exports.NumberFlowLite=B;exports.canAnimate=V;exports.define=z;exports.formatToData=q;exports.prefersReducedMotion=x;exports.renderInnerHTML=it;
8
+ style="font-kerning: none; display: inline-block; line-height: ${U} !important; padding: ${m} 0;"
9
+ >${n.valueAsString}</span
10
+ >`,it=(n,t)=>n==null?t:t==null?n:Math.max(n,t),V=K&&G&&Z;let S;class B extends J{constructor(){super(...arguments),this.transformTiming=this.constructor.defaultProps.transformTiming,this.spinTiming=this.constructor.defaultProps.spinTiming,this.opacityTiming=this.constructor.defaultProps.opacityTiming,this.respectMotionPreference=this.constructor.defaultProps.respectMotionPreference,this.trend=this.constructor.defaultProps.trend,this.continuous=this.constructor.defaultProps.continuous,this.digits=this.constructor.defaultProps.digits,this._animated=this.constructor.defaultProps.animated,this._created=!1,this._computedAnimated=this._animated,this.manual=!1}get animated(){return this._animated}set animated(t){var e;this.animated!==t&&(this._animated=t,(e=this.shadowRoot)==null||e.getAnimations().forEach(i=>i.finish()))}get created(){return this._created}get computedTrend(){return this._computedTrend}get startingPos(){return this._startingPos}get computedAnimated(){return this._computedAnimated}set data(t){if(t==null)return;const{pre:e,integer:i,fraction:s,post:a,value:r}=t;if(this._created){const o=this._data;if(this._data=t,this._computedTrend=typeof this.trend=="function"?this.trend(o.value,r):this.trend,this._startingPos=void 0,this._computedTrend&&this.continuous){const d=o.integer.concat(o.fraction).filter(h=>h.type==="integer"||h.type==="fraction"),u=t.integer.concat(t.fraction).filter(h=>h.type==="integer"||h.type==="fraction"),p=d.find(h=>!u.find(f=>f.pos===h.pos&&f.value===h.value)),y=u.find(h=>!d.find(f=>h.pos===f.pos&&h.value===f.value));this._startingPos=it(p==null?void 0:p.pos,y==null?void 0:y.pos)}this._computedAnimated=V&&this._animated&&(!this.respectMotionPreference||!($!=null&&$.matches))&&D(this),this.manual||this.willUpdate(),this._pre.update(e),this._num.update({integer:i,fraction:s}),this._post.update(a),this.manual||this.didUpdate()}else{if(this._data=t,this.attachShadow({mode:"open"}),typeof CSSStyleSheet<"u"&&this.shadowRoot.adoptedStyleSheets)S||(S=new CSSStyleSheet,S.replaceSync(L)),this.shadowRoot.adoptedStyleSheets=[S];else{const o=document.createElement("style");o.textContent=L,this.shadowRoot.appendChild(o)}this._pre=new N(this,e,{justify:"right",part:"left"}),this.shadowRoot.appendChild(this._pre.el),this._num=new st(this,i,s),this.shadowRoot.appendChild(this._num.el),this._post=new N(this,a,{justify:"left",part:"right"}),this.shadowRoot.appendChild(this._post.el)}this._created=!0}willUpdate(){this._pre.willUpdate(),this._num.willUpdate(),this._post.willUpdate()}didUpdate(){if(!this._computedAnimated)return;this._abortAnimationsFinish?this._abortAnimationsFinish.abort():this.dispatchEvent(new Event("animationsstart")),this._pre.didUpdate(),this._num.didUpdate(),this._post.didUpdate();const t=new AbortController;Promise.all(this.shadowRoot.getAnimations().map(e=>e.finished)).then(()=>{t.signal.aborted||(this.dispatchEvent(new Event("animationsfinish")),this._abortAnimationsFinish=void 0)}),this._abortAnimationsFinish=t}}B.defaultProps={transformTiming:{duration:900,easing:"linear(0,.005,.019,.039,.066,.096,.129,.165,.202,.24,.278,.316,.354,.39,.426,.461,.494,.526,.557,.586,.614,.64,.665,.689,.711,.731,.751,.769,.786,.802,.817,.831,.844,.856,.867,.877,.887,.896,.904,.912,.919,.925,.931,.937,.942,.947,.951,.955,.959,.962,.965,.968,.971,.973,.976,.978,.98,.981,.983,.984,.986,.987,.988,.989,.99,.991,.992,.992,.993,.994,.994,.995,.995,.996,.996,.9963,.9967,.9969,.9972,.9975,.9977,.9979,.9981,.9982,.9984,.9985,.9987,.9988,.9989,1)"},spinTiming:void 0,opacityTiming:{duration:450,easing:"ease-out"},animated:!0,trend:(n,t)=>Math.sign(t-n),continuous:!1,respectMotionPreference:!0,digits:void 0};class st{constructor(t,e,i,{className:s,...a}={}){this.flow=t,this._integer=new M(t,e,{justify:"right",part:"integer"}),this._fraction=new M(t,i,{justify:"left",part:"fraction"}),this._inner=g("span",{className:"number__inner"},[this._integer.el,this._fraction.el]),this.el=g("span",{...a,part:"number",className:`number ${s??""}`},[this._inner])}willUpdate(){this._prevWidth=this.el.offsetWidth,this._prevLeft=this.el.getBoundingClientRect().left,this._integer.willUpdate(),this._fraction.willUpdate()}update({integer:t,fraction:e}){this._integer.update(t),this._fraction.update(e)}didUpdate(){const t=this.el.getBoundingClientRect();this._integer.didUpdate(),this._fraction.didUpdate();const e=this._prevLeft-t.left,i=this.el.offsetWidth,s=this._prevWidth-i;this.el.style.setProperty("--width",String(i)),this.el.animate({[C]:[`${e}px`,"0px"],[T]:[s,0]},{...this.flow.transformTiming,composite:"accumulate"})}}class O{constructor(t,e,{justify:i,className:s,...a},r){this.flow=t,this.children=new Map,this.onCharRemove=d=>()=>{this.children.delete(d)},this.justify=i;const o=e.map(d=>this.addChar(d).el);this.el=g("span",{...a,className:`section section--justify-${i} ${s??""}`},r?r(o):o)}addChar(t,{startDigitsAtZero:e=!1,...i}={}){const s=t.type==="integer"||t.type==="fraction"?new H(this,t.type,e?0:t.value,t.pos,{...i,onRemove:this.onCharRemove(t.key)}):new nt(this,t.type,t.value,{...i,onRemove:this.onCharRemove(t.key)});return this.children.set(t.key,s),s}unpop(t){t.el.classList.remove("section__exiting"),t.el.style.top="",t.el.style[this.justify]=""}pop(t){t.forEach(e=>{e.el.style.top=`${e.el.offsetTop}px`,e.el.style[this.justify]=`${X(e.el,this.justify)}px`}),t.forEach(e=>{e.el.classList.add("section__exiting"),e.present=!1})}addNewAndUpdateExisting(t){const e=new Map,i=new Map,s=this.justify==="left",a=s?"prepend":"append";if(z(t,r=>{let o;this.children.has(r.key)?(o=this.children.get(r.key),i.set(r,o),this.unpop(o),o.present=!0):(o=this.addChar(r,{startDigitsAtZero:!0,animateIn:!0}),e.set(r,o)),this.el[a](o.el)},{reverse:s}),this.flow.computedAnimated){const r=this.el.getBoundingClientRect();e.forEach(o=>{o.willUpdate(r)})}e.forEach((r,o)=>{r.update(o.value)}),i.forEach((r,o)=>{r.update(o.value)})}willUpdate(){const t=this.el.getBoundingClientRect();this._prevOffset=t[this.justify],this.children.forEach(e=>e.willUpdate(t))}didUpdate(){const t=this.el.getBoundingClientRect();this.children.forEach(s=>s.didUpdate(t));const e=t[this.justify],i=this._prevOffset-e;i&&this.children.size&&this.el.animate({transform:[`translateX(${i}px)`,"none"]},{...this.flow.transformTiming,composite:"accumulate"})}}class M extends O{update(t){const e=new Map;this.children.forEach((i,s)=>{t.find(a=>a.key===s)||e.set(s,i),this.unpop(i)}),this.addNewAndUpdateExisting(t),e.forEach(i=>{i instanceof H&&i.update(0)}),this.pop(e)}}class N extends O{update(t){const e=new Map;this.children.forEach((i,s)=>{t.find(a=>a.key===s)||e.set(s,i)}),this.pop(e),this.addNewAndUpdateExisting(t)}}class k{constructor(t,e,{onRemove:i,animateIn:s=!1}={}){this.flow=t,this.el=e,this._present=!0,this._remove=()=>{var a;this.el.remove(),(a=this._onRemove)==null||a.call(this)},this.el.classList.add("animate-presence"),this.flow.computedAnimated&&s&&this.el.animate({[R]:[-.9999,0]},{...this.flow.opacityTiming,composite:"accumulate"}),this._onRemove=i}get present(){return this._present}set present(t){if(this._present!==t){if(this._present=t,!this.flow.computedAnimated){t||this._remove();return}this.el.style.setProperty("--_number-flow-d-opacity",t?"0":"-.999"),this.el.animate({[R]:t?[-.9999,0]:[.999,0]},{...this.flow.opacityTiming,composite:"accumulate"}),t?this.flow.removeEventListener("animationsfinish",this._remove):this.flow.addEventListener("animationsfinish",this._remove,{once:!0})}}}class F extends k{constructor(t,e,i,s){super(t.flow,i,s),this.section=t,this.value=e,this.el=i}}class H extends F{constructor(t,e,i,s,a){var u,p;const r=(((p=(u=t.flow.digits)==null?void 0:u[s])==null?void 0:p.max)??9)+1,o=Array.from({length:r}).map((y,h)=>{const f=g("span",{className:`digit__num${h===i?" is-current":""}`},[document.createTextNode(String(h))]);return f.style.setProperty("--n",String(h)),f}),d=g("span",{part:`digit ${e}-digit`,className:"digit"},o);d.style.setProperty("--current",String(i)),d.style.setProperty("--length",String(r)),super(t,i,d,a),this.pos=s,this._onAnimationsFinish=()=>{this.el.classList.remove("is-spinning")},this._numbers=o,this._length=r}willUpdate(t){const e=this.el.getBoundingClientRect();this._prevValue=this.value;const i=e[this.section.justify]-t[this.section.justify],s=e.width/2;this._prevCenter=this.section.justify==="left"?i+s:i-s}update(t){var e,i;(e=this._numbers[this.value])==null||e.classList.remove("is-current"),this.el.style.setProperty("--current",String(t)),(i=this._numbers[t])==null||i.classList.add("is-current"),this.value=t}didUpdate(t){const e=this.el.getBoundingClientRect(),i=e[this.section.justify]-t[this.section.justify],s=e.width/2,a=this.section.justify==="left"?i+s:i-s,r=this._prevCenter-a;r&&this.el.animate({transform:[`translateX(${r}px)`,"none"]},{...this.flow.transformTiming,composite:"accumulate"});const o=this.diff;o&&(this.el.classList.add("is-spinning"),this.el.animate({[A]:[-o,0]},{...this.flow.spinTiming??this.flow.transformTiming,composite:"accumulate"}),this.flow.addEventListener("animationsfinish",this._onAnimationsFinish,{once:!0}))}get diff(){let t=this.flow.computedTrend;const e=this.value-this._prevValue;return!e&&this.flow.startingPos!=null&&this.flow.startingPos>=this.pos?this._length*t:(t||(t=Math.sign(e)),t<0&&this.value>this._prevValue?this.value-this._length-this._prevValue:t>0&&this.value<this._prevValue?this._length-this._prevValue+this.value:e)}}class nt extends F{constructor(t,e,i,s){const a=g("span",{className:"symbol__value",textContent:i});super(t,i,g("span",{part:e,className:"symbol"},[a]),s),this.type=e,this._children=new Map,this._onChildRemove=r=>()=>{this._children.delete(r)},this._children.set(i,new k(this.flow,a,{onRemove:this._onChildRemove(i)}))}willUpdate(t){if(this.type==="decimal")return;const e=this.el.getBoundingClientRect();this._prevOffset=e[this.section.justify]-t[this.section.justify]}update(t){if(this.value!==t){const e=this._children.get(this.value);if(e.present=!1,e.el.classList.add("symbol__exiting"),this._children.has(t)){const i=this._children.get(t);i.present=!0,i.el.classList.remove("symbol__exiting")}else{const i=g("span",{className:"symbol__value",textContent:t});this.el.appendChild(i),this._children.set(t,new k(this.flow,i,{animateIn:!0,onRemove:this._onChildRemove(t)}))}}this.value=t}didUpdate(t){if(this.type==="decimal")return;const i=this.el.getBoundingClientRect()[this.section.justify]-t[this.section.justify],s=this._prevOffset-i;s&&this.el.animate({transform:[`translateX(${s}px)`,"none"]},{...this.flow.transformTiming,composite:"accumulate"})}}exports.NumberFlowLite=B;exports.canAnimate=V;exports.define=I;exports.formatToData=Y;exports.prefersReducedMotion=$;exports.renderInnerHTML=et;
package/dist/index.mjs CHANGED
@@ -1,78 +1,78 @@
1
- import { BROWSER as v } from "esm-env";
2
- const y = (s, t, e) => {
3
- const i = document.createElement(s), [n, r] = Array.isArray(t) ? [void 0, t] : [t, e];
4
- return n && Object.assign(i, n), r == null || r.forEach((o) => i.appendChild(o)), i;
5
- }, F = (s, t) => {
1
+ import { BROWSER as w } from "esm-env";
2
+ const g = (n, t, e) => {
3
+ const i = document.createElement(n), [s, a] = Array.isArray(t) ? [void 0, t] : [t, e];
4
+ return s && Object.assign(i, s), a == null || a.forEach((r) => i.appendChild(r)), i;
5
+ }, H = (n, t) => {
6
6
  var e;
7
- return t === "left" ? s.offsetLeft : (((e = s.offsetParent instanceof HTMLElement ? s.offsetParent : null) == null ? void 0 : e.offsetWidth) ?? 0) - s.offsetWidth - s.offsetLeft;
8
- }, H = (s) => s.offsetWidth > 0 && s.offsetHeight > 0, nt = (s, t) => {
9
- if (!(!v || customElements.get(s) === t))
10
- return customElements.define(s, t);
7
+ return t === "left" ? n.offsetLeft : (((e = n.offsetParent instanceof HTMLElement ? n.offsetParent : null) == null ? void 0 : e.offsetWidth) ?? 0) - n.offsetWidth - n.offsetLeft;
8
+ }, X = (n) => n.offsetWidth > 0 && n.offsetHeight > 0, st = (n, t) => {
9
+ if (!(!w || customElements.get(n) === t))
10
+ return customElements.define(n, t);
11
11
  };
12
- function X(s, t, { reverse: e = !1 } = {}) {
13
- const i = s.length;
14
- for (let n = e ? i - 1 : 0; e ? n >= 0 : n < i; e ? n-- : n++)
15
- t(s[n], n);
12
+ function D(n, t, { reverse: e = !1 } = {}) {
13
+ const i = n.length;
14
+ for (let s = e ? i - 1 : 0; e ? s >= 0 : s < i; e ? s-- : s++)
15
+ t(n[s], s);
16
16
  }
17
- function at(s, t, e, i) {
18
- const n = t.formatToParts(s);
19
- e && n.unshift({ type: "prefix", value: e }), i && n.push({ type: "suffix", value: i });
20
- const r = [], o = [], a = [], u = [], p = {}, d = (c) => `${c}:${p[c] = (p[c] ?? -1) + 1}`;
21
- let w = "", h = !1, m = !1;
22
- for (const c of n) {
23
- w += c.value;
17
+ function nt(n, t, e, i) {
18
+ const s = t.formatToParts(n);
19
+ e && s.unshift({ type: "prefix", value: e }), i && s.push({ type: "suffix", value: i });
20
+ const a = [], r = [], o = [], d = [], u = {}, p = (c) => `${c}:${u[c] = (u[c] ?? -1) + 1}`;
21
+ let y = "", h = !1, f = !1;
22
+ for (const c of s) {
23
+ y += c.value;
24
24
  const l = c.type === "minusSign" || c.type === "plusSign" ? "sign" : c.type;
25
- l === "integer" ? (h = !0, o.push(...c.value.split("").map((P) => ({ type: l, value: parseInt(P) })))) : l === "group" ? o.push({ type: l, value: c.value }) : l === "decimal" ? (m = !0, a.push({ type: l, value: c.value, key: d(l) })) : l === "fraction" ? a.push(...c.value.split("").map((P) => ({
25
+ l === "integer" ? (h = !0, r.push(...c.value.split("").map((k) => ({ type: l, value: parseInt(k) })))) : l === "group" ? r.push({ type: l, value: c.value }) : l === "decimal" ? (f = !0, o.push({ type: l, value: c.value, key: p(l) })) : l === "fraction" ? o.push(...c.value.split("").map((k) => ({
26
26
  type: l,
27
- value: parseInt(P),
28
- key: d(l),
29
- place: -1 - p[l]
30
- }))) : (h || m ? u : r).push({
27
+ value: parseInt(k),
28
+ key: p(l),
29
+ pos: -1 - u[l]
30
+ }))) : (h || f ? d : a).push({
31
31
  type: l,
32
32
  value: c.value,
33
- key: d(l)
33
+ key: p(l)
34
34
  });
35
35
  }
36
36
  const j = [];
37
- for (let c = o.length - 1; c >= 0; c--) {
38
- const l = o[c];
37
+ for (let c = r.length - 1; c >= 0; c--) {
38
+ const l = r[c];
39
39
  j.unshift(l.type === "integer" ? {
40
40
  ...l,
41
- key: d(l.type),
42
- place: p[l.type]
41
+ key: p(l.type),
42
+ pos: u[l.type]
43
43
  } : {
44
44
  ...l,
45
- key: d(l.type)
45
+ key: p(l.type)
46
46
  });
47
47
  }
48
48
  return {
49
- pre: r,
49
+ pre: a,
50
50
  integer: j,
51
- fraction: a,
52
- post: u,
53
- valueAsString: w,
54
- value: typeof s == "string" ? parseFloat(s) : s
51
+ fraction: o,
52
+ post: d,
53
+ valueAsString: y,
54
+ value: typeof n == "string" ? parseFloat(n) : n
55
55
  };
56
56
  }
57
- const I = String.raw, V = String.raw, z = v && typeof CSS < "u" && CSS.supports && CSS.supports("animation-timing-function", "linear(1,2)"), Y = v && typeof CSS < "u" && CSS.supports && CSS.supports("line-height", "mod(1,1)"), k = v && typeof matchMedia < "u" ? matchMedia("(prefers-reduced-motion: reduce)") : null, C = "--_number-flow-d-opacity", A = "--_number-flow-d-width", E = "--_number-flow-dx", T = "--_number-flow-d", G = (() => {
57
+ const I = String.raw, V = String.raw, O = w && typeof CSS < "u" && CSS.supports && CSS.supports("animation-timing-function", "linear(1,2)"), z = w && typeof CSS < "u" && CSS.supports && CSS.supports("line-height", "mod(1,1)"), P = w && typeof matchMedia < "u" ? matchMedia("(prefers-reduced-motion: reduce)") : null, x = "--_number-flow-d-opacity", T = "--_number-flow-d-width", C = "--_number-flow-dx", A = "--_number-flow-d", Y = (() => {
58
58
  try {
59
59
  return CSS.registerProperty({
60
- name: C,
60
+ name: x,
61
61
  syntax: "<number>",
62
62
  inherits: !1,
63
63
  initialValue: "0"
64
64
  }), CSS.registerProperty({
65
- name: E,
65
+ name: C,
66
66
  syntax: "<length>",
67
67
  inherits: !0,
68
68
  initialValue: "0px"
69
69
  }), CSS.registerProperty({
70
- name: A,
70
+ name: T,
71
71
  syntax: "<number>",
72
72
  inherits: !1,
73
73
  initialValue: "0"
74
74
  }), CSS.registerProperty({
75
- name: T,
75
+ name: A,
76
76
  syntax: "<number>",
77
77
  inherits: !0,
78
78
  initialValue: "0"
@@ -80,28 +80,24 @@ const I = String.raw, V = String.raw, z = v && typeof CSS < "u" && CSS.supports
80
80
  } catch {
81
81
  return !1;
82
82
  }
83
- })(), N = "var(--number-flow-char-height, 1em)", f = "var(--number-flow-mask-height, 0.25em)", x = `calc(${f} / 2)`, R = "var(--number-flow-mask-width, 0.5em)", _ = `calc(${R} / var(--scale-x))`, b = "#000 0, transparent 71%", L = V`:host{display:inline-block;direction:ltr;white-space:nowrap;line-height:${N} !important;isolation:isolate;}.number,.number__inner{display:inline-block;transform-origin:left top;}:host([data-will-change]) :is(.number,.number__inner,.section,.digit,.digit__num,.symbol){will-change:transform;}.number{--scale-x:calc(1 + var(${A}) / var(--width));transform:translateX(var(${E})) scaleX(var(--scale-x));margin:0 calc(-1 * ${R});position:relative;z-index:-1;-webkit-mask-image:linear-gradient( to right,transparent 0,#000 ${_},#000 calc(100% - ${_}),transparent ),linear-gradient( to bottom,transparent 0,#000 ${f},#000 calc(100% - ${f}),transparent 100% ),radial-gradient(at bottom right,${b}),radial-gradient(at bottom left,${b}),radial-gradient(at top left,${b}),radial-gradient(at top right,${b});-webkit-mask-size:100% calc(100% - ${f} * 2),calc(100% - ${_} * 2) 100%,${_} ${f},${_} ${f},${_} ${f},${_} ${f};-webkit-mask-position:center,center,top left,top right,bottom right,bottom left;-webkit-mask-repeat:no-repeat;}.number__inner{padding:${x} ${R};transform:scaleX(calc(1 / var(--scale-x))) translateX(calc(-1 * var(${E})));}.section{display:inline-block;position:relative;isolation:isolate;}.section::after{content:'\200b';display:inline-block;padding:${x} 0;}.section--justify-left{transform-origin:center left;}.section--justify-right{transform-origin:center right;}.section__exiting,.symbol__exiting{margin:0 !important;position:absolute !important;z-index:-1;}.digit{display:inline-block;position:relative;--c:var(--current) + var(${T});}.digit__num{display:inline-block;padding:${x} 0;--offset-raw:mod(10 + var(--n) - mod(var(--c),10),10);--offset:calc(var(--offset-raw) - 10 * round(down,var(--offset-raw) / 5,1));--y:clamp(-100%,var(--offset) * 100%,100%);transform:translateY(var(--y));}.digit__num:not(.is-current){position:absolute;top:0;left:50%;transform:translateX(-50%) translateY(var(--y));}.digit:not(.is-spinning) .digit__num:not(.is-current){display:none;}.symbol{display:inline-block;position:relative;isolation:isolate;}.symbol__value{display:inline-block;mix-blend-mode:plus-lighter;white-space:pre;}.section--justify-left .symbol__exiting{left:0;}.section--justify-right .symbol__exiting{right:0;}.animate-presence{opacity:calc(1 + var(${C}));}`, K = v ? HTMLElement : class {
84
- }, Z = V`:host{display:inline-block;direction:ltr;white-space:nowrap;line-height:${N} !important;}span{display:inline-block;}:host([data-will-change]) span{will-change:transform;}.number,.digit{padding:${x} 0;}.symbol{white-space:pre;}`, q = (s) => `<span class="${s.type === "integer" || s.type === "fraction" ? "digit" : "symbol"}" part="${s.type === "integer" || s.type === "fraction" ? `digit ${s.type}-digit` : s.type}">${s.value}</span>`, $ = (s, t) => `<span part="${t}">${s.reduce((e, i) => e + q(i), "")}</span>`, ot = (s) => (
83
+ })(), U = "var(--number-flow-char-height, 1em)", m = "var(--number-flow-mask-height, 0.25em)", S = `calc(${m} / 2)`, E = "var(--number-flow-mask-width, 0.5em)", _ = `calc(${E} / var(--scale-x))`, v = "#000 0, transparent 71%", L = V`:host{display:inline-block;direction:ltr;white-space:nowrap;line-height:${U} !important;isolation:isolate}.number,.number__inner{display:inline-block;transform-origin:left top}:host([data-will-change]) :is(.number,.number__inner,.section,.digit,.digit__num,.symbol){will-change:transform}.number{--scale-x:calc(1 + var(${T}) / var(--width));transform:translateX(var(${C})) scaleX(var(--scale-x));margin:0 calc(-1 * ${E});position:relative;-webkit-mask-image:linear-gradient(to right,transparent 0,#000 ${_},#000 calc(100% - ${_}),transparent ),linear-gradient(to bottom,transparent 0,#000 ${m},#000 calc(100% - ${m}),transparent 100% ),radial-gradient(at bottom right,${v}),radial-gradient(at bottom left,${v}),radial-gradient(at top left,${v}),radial-gradient(at top right,${v});-webkit-mask-size:100% calc(100% - ${m} * 2),calc(100% - ${_} * 2) 100%,${_} ${m},${_} ${m},${_} ${m},${_} ${m};-webkit-mask-position:center,center,top left,top right,bottom right,bottom left;-webkit-mask-repeat:no-repeat}.number__inner{padding:${S} ${E};transform:scaleX(calc(1 / var(--scale-x))) translateX(calc(-1 * var(${C})))}:host > :not(.number){z-index:5}.section,.symbol{display:inline-block;position:relative;isolation:isolate}.section::after{content:'\200b';display:inline-block;padding:${S} 0}.section--justify-left{transform-origin:center left}.section--justify-right{transform-origin:center right}.section__exiting,.symbol__exiting{margin:0 !important;position:absolute !important;z-index:-1}.digit{display:inline-block;position:relative;--c:var(--current) + var(${A})}.digit__num{display:inline-block;padding:${S} 0;--offset-raw:mod(var(--length) + var(--n) - mod(var(--c),var(--length)),var(--length));--offset:calc(var(--offset-raw) - var(--length) * round(down,var(--offset-raw) / (var(--length)/2),1));--y:clamp(-100%,var(--offset) * 100%,100%);transform:translateY(var(--y))}.digit__num:not(.is-current){position:absolute;top:0;left:50%;transform:translateX(-50%) translateY(var(--y))}.digit:not(.is-spinning) .digit__num:not(.is-current){display:none}.symbol__value{display:inline-block;mix-blend-mode:plus-lighter;white-space:pre}.section--justify-left .symbol__exiting{left:0}.section--justify-right .symbol__exiting{right:0}.animate-presence{opacity:calc(1 + var(${x}))}`, G = w ? HTMLElement : class {
84
+ }, K = V`:host{display:inline-block;direction:ltr;white-space:nowrap;line-height:${U} !important}span{display:inline-block}:host([data-will-change]) span{will-change:transform}.number,.digit{padding:${S} 0}.symbol{white-space:pre}`, Z = (n) => `<span class="${n.type === "integer" || n.type === "fraction" ? "digit" : "symbol"}" part="${n.type === "integer" || n.type === "fraction" ? `digit ${n.type}-digit` : n.type}">${n.value}</span>`, b = (n, t) => `<span part="${t}">${n.reduce((e, i) => e + Z(i), "")}</span>`, ot = (n) => (
85
85
  // shadowroot="open" non-standard attribute for old Chrome:
86
86
  I`<template shadowroot="open" shadowrootmode="open"
87
87
  ><style>
88
- ${Z}</style
89
- >${$(s.pre, "left")}<span part="number" class="number"
90
- >${$(s.integer, "integer")}${$(s.fraction, "fraction")}</span
91
- >${$(s.post, "right")}</template
88
+ ${K}</style
89
+ >${b(n.pre, "left")}<span part="number" class="number"
90
+ >${b(n.integer, "integer")}${b(n.fraction, "fraction")}</span
91
+ >${b(n.post, "right")}</template
92
92
  ><span
93
- style="font-kerning: none; display: inline-block; line-height: ${N} !important; padding: ${f} 0;"
94
- >${s.valueAsString}</span
93
+ style="font-kerning: none; display: inline-block; line-height: ${U} !important; padding: ${m} 0;"
94
+ >${n.valueAsString}</span
95
95
  >`
96
- ), J = (s, t) => s != null && t == null ? s : s == null && t != null ? t : s != null && t != null ? Math.max(s, t) : null, Q = Y && z && G;
97
- var g;
98
- (function(s) {
99
- s[s.UP = 1] = "UP", s[s.DOWN = -1] = "DOWN", s[s.NONE = 0] = "NONE";
100
- })(g || (g = {}));
101
- let S;
102
- class tt extends K {
96
+ ), q = (n, t) => n == null ? t : t == null ? n : Math.max(n, t), J = z && O && Y;
97
+ let $;
98
+ class Q extends G {
103
99
  constructor() {
104
- super(...arguments), this.transformTiming = this.constructor.defaultProps.transformTiming, this.spinTiming = this.constructor.defaultProps.spinTiming, this.opacityTiming = this.constructor.defaultProps.opacityTiming, this.respectMotionPreference = this.constructor.defaultProps.respectMotionPreference, this.trend = this.constructor.defaultProps.trend, this.continuous = this.constructor.defaultProps.continuous, this._animated = this.constructor.defaultProps.animated, this._created = !1, this._computedAnimated = this._animated, this.manual = !1;
100
+ super(...arguments), this.transformTiming = this.constructor.defaultProps.transformTiming, this.spinTiming = this.constructor.defaultProps.spinTiming, this.opacityTiming = this.constructor.defaultProps.opacityTiming, this.respectMotionPreference = this.constructor.defaultProps.respectMotionPreference, this.trend = this.constructor.defaultProps.trend, this.continuous = this.constructor.defaultProps.continuous, this.digits = this.constructor.defaultProps.digits, this._animated = this.constructor.defaultProps.animated, this._created = !1, this._computedAnimated = this._animated, this.manual = !1;
105
101
  }
106
102
  get animated() {
107
103
  return this._animated;
@@ -116,8 +112,8 @@ class tt extends K {
116
112
  get computedTrend() {
117
113
  return this._computedTrend;
118
114
  }
119
- get startingPlace() {
120
- return this._startingPlace;
115
+ get startingPos() {
116
+ return this._startingPos;
121
117
  }
122
118
  get computedAnimated() {
123
119
  return this._computedAnimated;
@@ -125,26 +121,26 @@ class tt extends K {
125
121
  set data(t) {
126
122
  if (t == null)
127
123
  return;
128
- const { pre: e, integer: i, fraction: n, post: r, value: o } = t;
124
+ const { pre: e, integer: i, fraction: s, post: a, value: r } = t;
129
125
  if (this._created) {
130
- const a = this._data;
131
- if (this._data = t, this.trend === !0 ? this._computedTrend = Math.sign(o - a.value) : this.trend === "increasing" ? this._computedTrend = g.UP : this.trend === "decreasing" ? this._computedTrend = g.DOWN : this._computedTrend = g.NONE, this._startingPlace = void 0, this._computedTrend !== g.NONE && this.continuous) {
132
- const u = a.integer.concat(a.fraction).filter((h) => h.type === "integer" || h.type === "fraction"), p = t.integer.concat(t.fraction).filter((h) => h.type === "integer" || h.type === "fraction"), d = u.find((h) => !p.find((m) => m.place === h.place && m.value === h.value)), w = p.find((h) => !u.find((m) => h.place === m.place && h.value === m.value));
133
- this._startingPlace = J(d == null ? void 0 : d.place, w == null ? void 0 : w.place);
126
+ const o = this._data;
127
+ if (this._data = t, this._computedTrend = typeof this.trend == "function" ? this.trend(o.value, r) : this.trend, this._startingPos = void 0, this._computedTrend && this.continuous) {
128
+ const d = o.integer.concat(o.fraction).filter((h) => h.type === "integer" || h.type === "fraction"), u = t.integer.concat(t.fraction).filter((h) => h.type === "integer" || h.type === "fraction"), p = d.find((h) => !u.find((f) => f.pos === h.pos && f.value === h.value)), y = u.find((h) => !d.find((f) => h.pos === f.pos && h.value === f.value));
129
+ this._startingPos = q(p == null ? void 0 : p.pos, y == null ? void 0 : y.pos);
134
130
  }
135
- this._computedAnimated = Q && this._animated && (!this.respectMotionPreference || !(k != null && k.matches)) && // https://github.com/barvian/number-flow/issues/9
136
- H(this), this.manual || this.willUpdate(), this._pre.update(e), this._num.update({ integer: i, fraction: n }), this._post.update(r), this.manual || this.didUpdate();
131
+ this._computedAnimated = J && this._animated && (!this.respectMotionPreference || !(P != null && P.matches)) && // https://github.com/barvian/number-flow/issues/9
132
+ X(this), this.manual || this.willUpdate(), this._pre.update(e), this._num.update({ integer: i, fraction: s }), this._post.update(a), this.manual || this.didUpdate();
137
133
  } else {
138
134
  if (this._data = t, this.attachShadow({ mode: "open" }), typeof CSSStyleSheet < "u" && this.shadowRoot.adoptedStyleSheets)
139
- S || (S = new CSSStyleSheet(), S.replaceSync(L)), this.shadowRoot.adoptedStyleSheets = [S];
135
+ $ || ($ = new CSSStyleSheet(), $.replaceSync(L)), this.shadowRoot.adoptedStyleSheets = [$];
140
136
  else {
141
- const a = document.createElement("style");
142
- a.textContent = L, this.shadowRoot.appendChild(a);
137
+ const o = document.createElement("style");
138
+ o.textContent = L, this.shadowRoot.appendChild(o);
143
139
  }
144
- this._pre = new W(this, e, {
140
+ this._pre = new N(this, e, {
145
141
  justify: "right",
146
142
  part: "left"
147
- }), this.shadowRoot.appendChild(this._pre.el), this._num = new et(this, i, n), this.shadowRoot.appendChild(this._num.el), this._post = new W(this, r, {
143
+ }), this.shadowRoot.appendChild(this._pre.el), this._num = new tt(this, i, s), this.shadowRoot.appendChild(this._num.el), this._post = new N(this, a, {
148
144
  justify: "left",
149
145
  part: "right"
150
146
  }), this.shadowRoot.appendChild(this._post.el);
@@ -164,7 +160,7 @@ class tt extends K {
164
160
  }), this._abortAnimationsFinish = t;
165
161
  }
166
162
  }
167
- tt.defaultProps = {
163
+ Q.defaultProps = {
168
164
  transformTiming: {
169
165
  duration: 900,
170
166
  // Make sure to keep this minified:
@@ -173,24 +169,25 @@ tt.defaultProps = {
173
169
  spinTiming: void 0,
174
170
  opacityTiming: { duration: 450, easing: "ease-out" },
175
171
  animated: !0,
176
- trend: !0,
172
+ trend: (n, t) => Math.sign(t - n),
177
173
  continuous: !1,
178
- respectMotionPreference: !0
174
+ respectMotionPreference: !0,
175
+ digits: void 0
179
176
  };
180
- class et {
181
- constructor(t, e, i, { className: n, ...r } = {}) {
177
+ class tt {
178
+ constructor(t, e, i, { className: s, ...a } = {}) {
182
179
  this.flow = t, this._integer = new M(t, e, {
183
180
  justify: "right",
184
181
  part: "integer"
185
182
  }), this._fraction = new M(t, i, {
186
183
  justify: "left",
187
184
  part: "fraction"
188
- }), this._inner = y("span", {
185
+ }), this._inner = g("span", {
189
186
  className: "number__inner"
190
- }, [this._integer.el, this._fraction.el]), this.el = y("span", {
191
- ...r,
187
+ }, [this._integer.el, this._fraction.el]), this.el = g("span", {
188
+ ...a,
192
189
  part: "number",
193
- className: `number ${n ?? ""}`
190
+ className: `number ${s ?? ""}`
194
191
  }, [this._inner]);
195
192
  }
196
193
  willUpdate() {
@@ -202,62 +199,62 @@ class et {
202
199
  didUpdate() {
203
200
  const t = this.el.getBoundingClientRect();
204
201
  this._integer.didUpdate(), this._fraction.didUpdate();
205
- const e = this._prevLeft - t.left, i = this.el.offsetWidth, n = this._prevWidth - i;
202
+ const e = this._prevLeft - t.left, i = this.el.offsetWidth, s = this._prevWidth - i;
206
203
  this.el.style.setProperty("--width", String(i)), this.el.animate({
207
- [E]: [`${e}px`, "0px"],
208
- [A]: [n, 0]
204
+ [C]: [`${e}px`, "0px"],
205
+ [T]: [s, 0]
209
206
  }, {
210
207
  ...this.flow.transformTiming,
211
208
  composite: "accumulate"
212
209
  });
213
210
  }
214
211
  }
215
- class O {
216
- constructor(t, e, { justify: i, className: n, ...r }, o) {
217
- this.flow = t, this.children = /* @__PURE__ */ new Map(), this.onCharRemove = (u) => () => {
218
- this.children.delete(u);
212
+ class W {
213
+ constructor(t, e, { justify: i, className: s, ...a }, r) {
214
+ this.flow = t, this.children = /* @__PURE__ */ new Map(), this.onCharRemove = (d) => () => {
215
+ this.children.delete(d);
219
216
  }, this.justify = i;
220
- const a = e.map((u) => this.addChar(u).el);
221
- this.el = y("span", {
222
- ...r,
223
- className: `section section--justify-${i} ${n ?? ""}`
224
- }, o ? o(a) : a);
217
+ const o = e.map((d) => this.addChar(d).el);
218
+ this.el = g("span", {
219
+ ...a,
220
+ className: `section section--justify-${i} ${s ?? ""}`
221
+ }, r ? r(o) : o);
225
222
  }
226
223
  addChar(t, { startDigitsAtZero: e = !1, ...i } = {}) {
227
- const n = t.type === "integer" || t.type === "fraction" ? new D(this, t.type, e ? 0 : t.value, t.place, {
224
+ const s = t.type === "integer" || t.type === "fraction" ? new F(this, t.type, e ? 0 : t.value, t.pos, {
228
225
  ...i,
229
226
  onRemove: this.onCharRemove(t.key)
230
- }) : new it(this, t.type, t.value, {
227
+ }) : new et(this, t.type, t.value, {
231
228
  ...i,
232
229
  onRemove: this.onCharRemove(t.key)
233
230
  });
234
- return this.children.set(t.key, n), n;
231
+ return this.children.set(t.key, s), s;
235
232
  }
236
233
  unpop(t) {
237
234
  t.el.classList.remove("section__exiting"), t.el.style.top = "", t.el.style[this.justify] = "";
238
235
  }
239
236
  pop(t) {
240
237
  t.forEach((e) => {
241
- e.el.style.top = `${e.el.offsetTop}px`, e.el.style[this.justify] = `${F(e.el, this.justify)}px`;
238
+ e.el.style.top = `${e.el.offsetTop}px`, e.el.style[this.justify] = `${H(e.el, this.justify)}px`;
242
239
  }), t.forEach((e) => {
243
240
  e.el.classList.add("section__exiting"), e.present = !1;
244
241
  });
245
242
  }
246
243
  addNewAndUpdateExisting(t) {
247
- const e = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Map(), n = this.justify === "left", r = n ? "prepend" : "append";
248
- if (X(t, (o) => {
249
- let a;
250
- this.children.has(o.key) ? (a = this.children.get(o.key), i.set(o, a), this.unpop(a), a.present = !0) : (a = this.addChar(o, { startDigitsAtZero: !0, animateIn: !0 }), e.set(o, a)), this.el[r](a.el);
251
- }, { reverse: n }), this.flow.computedAnimated) {
252
- const o = this.el.getBoundingClientRect();
253
- e.forEach((a) => {
254
- a.willUpdate(o);
244
+ const e = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Map(), s = this.justify === "left", a = s ? "prepend" : "append";
245
+ if (D(t, (r) => {
246
+ let o;
247
+ this.children.has(r.key) ? (o = this.children.get(r.key), i.set(r, o), this.unpop(o), o.present = !0) : (o = this.addChar(r, { startDigitsAtZero: !0, animateIn: !0 }), e.set(r, o)), this.el[a](o.el);
248
+ }, { reverse: s }), this.flow.computedAnimated) {
249
+ const r = this.el.getBoundingClientRect();
250
+ e.forEach((o) => {
251
+ o.willUpdate(r);
255
252
  });
256
253
  }
257
- e.forEach((o, a) => {
258
- o.update(a.value);
259
- }), i.forEach((o, a) => {
260
- o.update(a.value);
254
+ e.forEach((r, o) => {
255
+ r.update(o.value);
256
+ }), i.forEach((r, o) => {
257
+ r.update(o.value);
261
258
  });
262
259
  }
263
260
  willUpdate() {
@@ -266,7 +263,7 @@ class O {
266
263
  }
267
264
  didUpdate() {
268
265
  const t = this.el.getBoundingClientRect();
269
- this.children.forEach((n) => n.didUpdate(t));
266
+ this.children.forEach((s) => s.didUpdate(t));
270
267
  const e = t[this.justify], i = this._prevOffset - e;
271
268
  i && this.children.size && this.el.animate({
272
269
  transform: [`translateX(${i}px)`, "none"]
@@ -276,31 +273,31 @@ class O {
276
273
  });
277
274
  }
278
275
  }
279
- class M extends O {
276
+ class M extends W {
280
277
  update(t) {
281
278
  const e = /* @__PURE__ */ new Map();
282
- this.children.forEach((i, n) => {
283
- t.find((r) => r.key === n) || e.set(n, i), this.unpop(i);
279
+ this.children.forEach((i, s) => {
280
+ t.find((a) => a.key === s) || e.set(s, i), this.unpop(i);
284
281
  }), this.addNewAndUpdateExisting(t), e.forEach((i) => {
285
- i instanceof D && i.update(0);
282
+ i instanceof F && i.update(0);
286
283
  }), this.pop(e);
287
284
  }
288
285
  }
289
- class W extends O {
286
+ class N extends W {
290
287
  update(t) {
291
288
  const e = /* @__PURE__ */ new Map();
292
- this.children.forEach((i, n) => {
293
- t.find((r) => r.key === n) || e.set(n, i);
289
+ this.children.forEach((i, s) => {
290
+ t.find((a) => a.key === s) || e.set(s, i);
294
291
  }), this.pop(e), this.addNewAndUpdateExisting(t);
295
292
  }
296
293
  }
297
- class U {
298
- constructor(t, e, { onRemove: i, animateIn: n = !1 } = {}) {
294
+ class R {
295
+ constructor(t, e, { onRemove: i, animateIn: s = !1 } = {}) {
299
296
  this.flow = t, this.el = e, this._present = !0, this._remove = () => {
300
- var r;
301
- this.el.remove(), (r = this._onRemove) == null || r.call(this);
302
- }, this.el.classList.add("animate-presence"), this.flow.computedAnimated && n && this.el.animate({
303
- [C]: [-0.9999, 0]
297
+ var a;
298
+ this.el.remove(), (a = this._onRemove) == null || a.call(this);
299
+ }, this.el.classList.add("animate-presence"), this.flow.computedAnimated && s && this.el.animate({
300
+ [x]: [-0.9999, 0]
304
301
  }, {
305
302
  ...this.flow.opacityTiming,
306
303
  composite: "accumulate"
@@ -316,7 +313,7 @@ class U {
316
313
  return;
317
314
  }
318
315
  this.el.style.setProperty("--_number-flow-d-opacity", t ? "0" : "-.999"), this.el.animate({
319
- [C]: t ? [-0.9999, 0] : [0.999, 0]
316
+ [x]: t ? [-0.9999, 0] : [0.999, 0]
320
317
  }, {
321
318
  ...this.flow.opacityTiming,
322
319
  composite: "accumulate"
@@ -326,45 +323,46 @@ class U {
326
323
  }
327
324
  }
328
325
  }
329
- class B extends U {
330
- constructor(t, e, i, n) {
331
- super(t.flow, i, n), this.section = t, this.value = e, this.el = i;
326
+ class B extends R {
327
+ constructor(t, e, i, s) {
328
+ super(t.flow, i, s), this.section = t, this.value = e, this.el = i;
332
329
  }
333
330
  }
334
- class D extends B {
335
- constructor(t, e, i, n, r) {
336
- const o = Array.from({ length: 10 }).map((u, p) => {
337
- const d = y("span", { className: `digit__num${p === i ? " is-current" : ""}` }, [document.createTextNode(String(p))]);
338
- return d.style.setProperty("--n", String(p)), d;
339
- }), a = y("span", {
331
+ class F extends B {
332
+ constructor(t, e, i, s, a) {
333
+ var u, p;
334
+ const r = (((p = (u = t.flow.digits) == null ? void 0 : u[s]) == null ? void 0 : p.max) ?? 9) + 1, o = Array.from({ length: r }).map((y, h) => {
335
+ const f = g("span", { className: `digit__num${h === i ? " is-current" : ""}` }, [document.createTextNode(String(h))]);
336
+ return f.style.setProperty("--n", String(h)), f;
337
+ }), d = g("span", {
340
338
  part: `digit ${e}-digit`,
341
339
  className: "digit"
342
340
  }, o);
343
- a.style.setProperty("--current", String(i)), super(t, i, a, r), this.place = n, this._onAnimationsFinish = () => {
341
+ d.style.setProperty("--current", String(i)), d.style.setProperty("--length", String(r)), super(t, i, d, a), this.pos = s, this._onAnimationsFinish = () => {
344
342
  this.el.classList.remove("is-spinning");
345
- }, this._numbers = o;
343
+ }, this._numbers = o, this._length = r;
346
344
  }
347
345
  willUpdate(t) {
348
346
  const e = this.el.getBoundingClientRect();
349
347
  this._prevValue = this.value;
350
- const i = e[this.section.justify] - t[this.section.justify], n = e.width / 2;
351
- this._prevCenter = this.section.justify === "left" ? i + n : i - n;
348
+ const i = e[this.section.justify] - t[this.section.justify], s = e.width / 2;
349
+ this._prevCenter = this.section.justify === "left" ? i + s : i - s;
352
350
  }
353
351
  update(t) {
354
352
  var e, i;
355
353
  (e = this._numbers[this.value]) == null || e.classList.remove("is-current"), this.el.style.setProperty("--current", String(t)), (i = this._numbers[t]) == null || i.classList.add("is-current"), this.value = t;
356
354
  }
357
355
  didUpdate(t) {
358
- const e = this.el.getBoundingClientRect(), i = e[this.section.justify] - t[this.section.justify], n = e.width / 2, r = this.section.justify === "left" ? i + n : i - n, o = this._prevCenter - r;
359
- o && this.el.animate({
360
- transform: [`translateX(${o}px)`, "none"]
356
+ const e = this.el.getBoundingClientRect(), i = e[this.section.justify] - t[this.section.justify], s = e.width / 2, a = this.section.justify === "left" ? i + s : i - s, r = this._prevCenter - a;
357
+ r && this.el.animate({
358
+ transform: [`translateX(${r}px)`, "none"]
361
359
  }, {
362
360
  ...this.flow.transformTiming,
363
361
  composite: "accumulate"
364
362
  });
365
- const a = this.diff;
366
- a && (this.el.classList.add("is-spinning"), this.el.animate({
367
- [T]: [-a, 0]
363
+ const o = this.diff;
364
+ o && (this.el.classList.add("is-spinning"), this.el.animate({
365
+ [A]: [-o, 0]
368
366
  }, {
369
367
  ...this.flow.spinTiming ?? this.flow.transformTiming,
370
368
  composite: "accumulate"
@@ -373,21 +371,21 @@ class D extends B {
373
371
  get diff() {
374
372
  let t = this.flow.computedTrend;
375
373
  const e = this.value - this._prevValue;
376
- return !e && this.flow.startingPlace != null && this.flow.startingPlace >= this.place ? 10 * t : (t || (t = Math.sign(e)), t === g.DOWN && this.value > this._prevValue ? this.value - 10 - this._prevValue : t === g.UP && this.value < this._prevValue ? 10 - this._prevValue + this.value : e);
374
+ return !e && this.flow.startingPos != null && this.flow.startingPos >= this.pos ? this._length * t : (t || (t = Math.sign(e)), t < 0 && this.value > this._prevValue ? this.value - this._length - this._prevValue : t > 0 && this.value < this._prevValue ? this._length - this._prevValue + this.value : e);
377
375
  }
378
376
  }
379
- class it extends B {
380
- constructor(t, e, i, n) {
381
- const r = y("span", {
377
+ class et extends B {
378
+ constructor(t, e, i, s) {
379
+ const a = g("span", {
382
380
  className: "symbol__value",
383
381
  textContent: i
384
382
  });
385
- super(t, i, y("span", {
383
+ super(t, i, g("span", {
386
384
  part: e,
387
385
  className: "symbol"
388
- }, [r]), n), this.type = e, this._children = /* @__PURE__ */ new Map(), this._onChildRemove = (o) => () => {
389
- this._children.delete(o);
390
- }, this._children.set(i, new U(this.flow, r, {
386
+ }, [a]), s), this.type = e, this._children = /* @__PURE__ */ new Map(), this._onChildRemove = (r) => () => {
387
+ this._children.delete(r);
388
+ }, this._children.set(i, new R(this.flow, a, {
391
389
  onRemove: this._onChildRemove(i)
392
390
  }));
393
391
  }
@@ -404,11 +402,11 @@ class it extends B {
404
402
  const i = this._children.get(t);
405
403
  i.present = !0, i.el.classList.remove("symbol__exiting");
406
404
  } else {
407
- const i = y("span", {
405
+ const i = g("span", {
408
406
  className: "symbol__value",
409
407
  textContent: t
410
408
  });
411
- this.el.appendChild(i), this._children.set(t, new U(this.flow, i, {
409
+ this.el.appendChild(i), this._children.set(t, new R(this.flow, i, {
412
410
  animateIn: !0,
413
411
  onRemove: this._onChildRemove(t)
414
412
  }));
@@ -419,17 +417,17 @@ class it extends B {
419
417
  didUpdate(t) {
420
418
  if (this.type === "decimal")
421
419
  return;
422
- const i = this.el.getBoundingClientRect()[this.section.justify] - t[this.section.justify], n = this._prevOffset - i;
423
- n && this.el.animate({
424
- transform: [`translateX(${n}px)`, "none"]
420
+ const i = this.el.getBoundingClientRect()[this.section.justify] - t[this.section.justify], s = this._prevOffset - i;
421
+ s && this.el.animate({
422
+ transform: [`translateX(${s}px)`, "none"]
425
423
  }, { ...this.flow.transformTiming, composite: "accumulate" });
426
424
  }
427
425
  }
428
426
  export {
429
- tt as NumberFlowLite,
430
- Q as canAnimate,
431
- nt as define,
432
- at as formatToData,
433
- k as prefersReducedMotion,
427
+ Q as NumberFlowLite,
428
+ J as canAnimate,
429
+ st as define,
430
+ nt as formatToData,
431
+ P as prefersReducedMotion,
434
432
  ot as renderInnerHTML
435
433
  };
@@ -1 +1 @@
1
- export declare const max: (n1?: number, n2?: number) => number | null;
1
+ export declare const max: (n1?: number, n2?: number) => number | undefined;
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "0.3.10",
6
+ "version": "0.4.0",
7
7
  "author": {
8
8
  "name": "Maxwell Barvian",
9
9
  "email": "max@barvian.me",