number-flow 0.2.2 → 0.3.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.
@@ -23,13 +23,14 @@ export type KeyedNumberPart = KeyedDigitPart | KeyedSymbolPart;
23
23
  export type Format = Omit<Intl.NumberFormatOptions, 'notation'> & {
24
24
  notation?: Exclude<Intl.NumberFormatOptions['notation'], 'scientific' | 'engineering'>;
25
25
  };
26
- export type Value = Parameters<typeof Intl.NumberFormat.prototype.formatToParts>[0];
26
+ export type Value = Exclude<Parameters<typeof Intl.NumberFormat.prototype.formatToParts>[0], bigint>;
27
27
  export declare function partitionParts(value: Value, formatter: Intl.NumberFormat): {
28
28
  pre: KeyedNumberPart[];
29
29
  integer: KeyedNumberPart[];
30
30
  fraction: KeyedNumberPart[];
31
31
  post: KeyedNumberPart[];
32
32
  formatted: string;
33
+ value: number;
33
34
  };
34
35
  export type PartitionedParts = ReturnType<typeof partitionParts>;
35
36
  export {};
package/dist/index.d.ts CHANGED
@@ -1,19 +1,30 @@
1
1
  import { type PartitionedParts } from './formatter';
2
2
  import { ServerSafeHTMLElement } from './ssr';
3
- export { SlottedTag, slottedStyles, supportsAnimationComposition, supportsLinear } from './styles';
3
+ export { SlottedTag, slottedStyles, prefersReducedMotion } from './styles';
4
4
  export * from './formatter';
5
- export declare const defaultFadeTiming: EffectTiming;
6
- export declare const defaultXTiming: EffectTiming;
7
- export declare const defaultYTiming: EffectTiming;
5
+ export declare const canAnimate: boolean;
6
+ type RawTrend = boolean | 'increasing' | 'decreasing';
7
+ export { type RawTrend as Trend };
8
+ declare enum Trend {
9
+ UP = 1,
10
+ DOWN = -1,
11
+ NONE = 0
12
+ }
13
+ export declare const defaultOpacityTiming: EffectTiming;
14
+ export declare const defaultTransformTiming: EffectTiming;
8
15
  export declare class NumberFlowLite extends ServerSafeHTMLElement {
9
16
  #private;
10
17
  static define(): void;
11
- xTiming: EffectTiming;
12
- yTiming: EffectTiming;
13
- fadeTiming: EffectTiming;
14
- root: boolean;
18
+ transformTiming: EffectTiming;
19
+ spinTiming?: EffectTiming;
20
+ opacityTiming: EffectTiming;
15
21
  manual: boolean;
22
+ respectMotionPreference: boolean;
23
+ trend: RawTrend;
24
+ getComputedTrend(): Trend | undefined;
16
25
  set parts(newVal: PartitionedParts | undefined);
17
26
  willUpdate(): void;
18
27
  didUpdate(): void;
28
+ get animated(): boolean;
29
+ set animated(val: boolean);
19
30
  }
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var wt=Object.defineProperty;var et=n=>{throw TypeError(n)};var xt=(n,i,t)=>i in n?wt(n,i,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[i]=t;var u=(n,i,t)=>xt(n,typeof i!="symbol"?i+"":i,t),it=(n,i,t)=>i.has(n)||et("Cannot "+t);var o=(n,i,t)=>(it(n,i,"read from private field"),t?t.call(n):i.get(n)),r=(n,i,t)=>i.has(n)?et("Cannot add the same private member more than once"):i instanceof WeakSet?i.add(n):i.set(n,t),h=(n,i,t,s)=>(it(n,i,"write to private field"),s?s.call(n,t):i.set(n,t),t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const V=require("esm-env"),y=(n,i,t)=>{const s=document.createElement(n),[e,a]=Array.isArray(i)?[void 0,i]:[i,t];return e&&Object.assign(s,e),a==null||a.forEach(l=>s.appendChild(l)),s},_t=(n,i)=>{typeof Element.prototype.replaceChildren>"u"?(n.innerHTML="",i.forEach(t=>n.appendChild(t))):n.replaceChildren(...i)},bt=(n,i)=>{var t;return i==="left"?n.offsetLeft:(((t=n.offsetParent instanceof HTMLElement?n.offsetParent:null)==null?void 0:t.offsetWidth)??0)-n.offsetWidth-n.offsetLeft};function St(n,i,{reverse:t=!1}={}){const s=n.length;for(let e=t?s-1:0;t?e>=0:e<s;t?e--:e++)i(n[e],e)}function Ct(n,i){const t=i.formatToParts(n),s=[],e=[],a=[],l=[],f={},c=p=>(f[p]||(f[p]=0),`${p}:${f[p]++}`);let d="",x=!1,E=!1;for(const p of t){d+=p.value;const m=p.type==="minusSign"||p.type==="plusSign"?"sign":p.type;m==="integer"?(x=!0,e.push(...p.value.split("").map(Z=>({type:m,value:parseInt(Z)})))):m==="group"?e.push({type:m,value:p.value}):m==="decimal"?(E=!0,a.push({type:m,value:p.value,key:c(m)})):m==="fraction"?a.push(...p.value.split("").map(Z=>({type:m,value:parseInt(Z),key:c(m)}))):(x||E?l:s).push({type:m,value:p.value,key:c(m)})}const _=[];for(let p=e.length-1;p>=0;p--)_.unshift({...e[p],key:c(e[p].type)});return{pre:s,integer:_,fraction:a,post:l,formatted:d}}const vt=V.BROWSER?HTMLElement:class{},kt=String.raw,ct=V.BROWSER&&typeof CSS<"u"&&CSS.supports("transition-timing-function","linear(1, 2)"),ht=V.BROWSER&&typeof CSS<"u"&&typeof CSS.registerProperty<"u",J=V.BROWSER&&typeof CSS<"u"&&typeof CSS.supports("animation-composition","accumulate")<"u";if(ht)try{CSS.registerProperty({name:"--_number-flow-scale-x",syntax:"<number>",inherits:!1,initialValue:"1"})}catch{}const dt="var(--number-flow-char-height, 1em)",g="var(--number-flow-mask-height, 0.25em)",T="var(--number-flow-mask-width, 0.5em)",G=`${T} * 1/var(--_number-flow-scale-x)`,st=`calc(${G})`,nt=`linear-gradient(to bottom, transparent 0, #000 ${g}, #000 calc(100% - ${g}), transparent 100%)`,K="#000 0, transparent 71%",ft="span",$t={fontKerning:"none",display:"inline-block",lineHeight:dt,padding:`${g} 0`},ot=kt`:host{display:inline-block;direction:ltr;user-select:none;pointer-events:none;white-space:nowrap;position:relative;line-height:${dt} !important;isolation:isolate;}::slotted(${ft}){position:absolute;left:0;top:0;color:transparent !important;z-index:-1;user-select:text;pointer-events:auto;}.section{display:inline-block;padding-bottom:${g};padding-top:${g};vertical-align:top;user-select:none;}.section:not(.section--masked),.section--masked .section__inner{position:relative;isolation:isolate;}.section__inner{display:inline-block;transform-origin:inherit;}.section--justify-left{transform-origin:center left;}.section--justify-right{transform-origin:center right;}.section--masked{overflow:clip;position:relative;z-index:-1;--_number-flow-scale-x:1;-webkit-mask-repeat:no-repeat;-webkit-mask-size:calc(100% - ${G}) 100%,100% calc(100% - ${g} * 2),${st} ${g},${st} ${g};}.section--masked.section--justify-left{padding-right:${T};margin-right:calc(-1 * ${T});-webkit-mask-image:${nt},linear-gradient(to right,#000 0,#000 calc(100% - ${G}),transparent 100%),radial-gradient(at bottom left,${K}),radial-gradient(at top left,${K});-webkit-mask-position:left,center,right top,right bottom;}.section--masked.section--justify-right{padding-left:${T};margin-left:calc(-1 * ${T});-webkit-mask-image:${nt},linear-gradient(to left,#000 0,#000 calc(100% - ${G}),transparent 100%),radial-gradient(at bottom right,${K}),radial-gradient(at top right,${K});-webkit-mask-position:right,center,left top,left bottom;}.section__exiting{position:absolute !important;z-index:-1;}.digit{display:inline-block;position:relative;}.digit__stack{display:flex;flex-direction:column;align-items:center;gap:${g};position:absolute;width:100%;}.digit__stack > *{display:inline-block;}.digit__lt{bottom:calc(100% + ${g});}.digit__gt{top:calc(100% + ${g});}.symbol{display:inline-block;position:relative;isolation:isolate;}.symbol__value{display:inline-block;white-space:pre;}.symbol__exiting{position:absolute;z-index:-1;}.section--justify-left .symbol__exiting{left:0;}.section--justify-right .symbol__exiting{right:0;}`;function Rt(n,i,t=60){const s=Math.trunc(n/1e3*t);return Array.from({length:s},(e,a)=>i(a/(s-1)))}function jt(n,i,t=60){if(ht)return[i(0),i(1)];const s=Math.max(Math.trunc(n/1e3*t),0),e=Array.from({length:s},(a,l)=>({...i(l/s),offset:(l+.5)/s}));return e.unshift({...i(0),offset:0}),e}const at=(n,i,t)=>n+(i-n)*t,pt={duration:500,easing:"ease-out",endDelay:400,fill:"forwards"},tt=ct?{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)"}:{duration:900,easing:"cubic-bezier(.32,.72,0,1)"},ut=tt;let q;var U,b,S,C,v;class Et extends vt{constructor(){super(...arguments);u(this,"xTiming",tt);u(this,"yTiming",ut);u(this,"fadeTiming",pt);u(this,"root",!1);u(this,"manual",!1);r(this,U,!1);r(this,b);r(this,S);r(this,C);r(this,v)}static define(){V.BROWSER&&customElements.define("number-flow",this)}set parts(t){if(t==null)return;const{pre:s,integer:e,fraction:a,post:l}=t;if(o(this,U))this.manual||this.willUpdate(),o(this,b).update(s),o(this,S).update(e),o(this,C).update(a),o(this,v).update(l),this.manual||this.didUpdate();else{if(this.attachShadow({mode:"open"}),typeof CSSStyleSheet<"u"&&this.shadowRoot.adoptedStyleSheets)q||(q=new CSSStyleSheet,q.replaceSync(ot)),this.shadowRoot.adoptedStyleSheets=[q];else{const f=document.createElement("style");f.textContent=ot,this.shadowRoot.appendChild(f)}this.shadowRoot.appendChild(y("slot")),h(this,b,new rt(this,s,{inert:!0,ariaHidden:"true",justify:"right"})),this.shadowRoot.appendChild(o(this,b).el),h(this,S,new lt(this,e,{inert:!0,ariaHidden:"true",justify:"right"})),this.shadowRoot.appendChild(o(this,S).el),h(this,C,new lt(this,a,{inert:!0,ariaHidden:"true",justify:"left"})),this.shadowRoot.appendChild(o(this,C).el),h(this,v,new rt(this,l,{inert:!0,ariaHidden:"true",justify:"left"})),this.shadowRoot.appendChild(o(this,v).el)}h(this,U,!0)}willUpdate(){const t=this.root?this.getBoundingClientRect():new DOMRect;o(this,b).willUpdate(t),o(this,S).willUpdate(t),o(this,C).willUpdate(t),o(this,v).willUpdate(t)}didUpdate(){const t=this.root?this.getBoundingClientRect():new DOMRect;o(this,b).didUpdate(t),o(this,S).didUpdate(t),o(this,C).didUpdate(t),o(this,v).didUpdate(t)}}U=new WeakMap,b=new WeakMap,S=new WeakMap,C=new WeakMap,v=new WeakMap;class mt{constructor(i,t,{justify:s,className:e,...a},l){u(this,"flow");u(this,"el");u(this,"justify");u(this,"children",new Map);u(this,"onCharRemove",i=>()=>{this.children.delete(i)});this.flow=i,this.justify=s;const f=t.map(c=>this.addChar(c).el);f.push(document.createTextNode("​")),this.el=y("span",{...a,className:`section section--justify-${s} ${e??""}`},l?l(f):f)}addChar(i,{startDigitsAtZero:t=!1,...s}={}){const e=i.type==="integer"||i.type==="fraction"?new yt(this,i.type,t?0:i.value,{...s,onRemove:this.onCharRemove(i.key)}):new Tt(this,i.type,i.value,{...s,onRemove:this.onCharRemove(i.key)});return this.children.set(i.key,e),e}unpop(i){i.el.classList.remove("section__exiting"),i.el.style[this.justify]=""}pop(i){i.forEach(t=>{t.el.style[this.justify]=`${bt(t.el,this.justify)}px`}),i.forEach(t=>{t.el.classList.add("section__exiting"),t.present=!1})}addNewAndUpdateExisting(i,t=this.el){const s=new Map,e=new Map,a=this.justify==="left",l=a?"prepend":"append";St(i,c=>{let d;this.children.has(c.key)?(d=this.children.get(c.key),e.set(c,d),this.unpop(d),d.present=!0):(d=this.addChar(c,{startDigitsAtZero:!0,animateIn:!0}),s.set(c,d)),t[l](d.el)},{reverse:a});const f=t.getBoundingClientRect();s.forEach(c=>{c.willUpdate(f)}),s.forEach((c,d)=>{c.update(d.value)}),e.forEach((c,d)=>{c.update(d.value)})}}var k,M,A,B,N,L;class lt extends mt{constructor(t,s,{className:e,...a}){let l;super(t,s,{...a,className:`${e??""} section--masked`},f=>[l=y("span",{className:"section__inner"},f)]);r(this,k);r(this,M);r(this,A);r(this,B);r(this,N);r(this,L);h(this,k,l)}willUpdate(t){const s=this.el.getBoundingClientRect();h(this,M,s.width),h(this,A,s[this.justify]-t[this.justify]);const e=o(this,k).getBoundingClientRect();this.children.forEach(a=>a.willUpdate(e))}update(t){const s=new Map;this.children.forEach((e,a)=>{t.find(l=>l.key===a)||s.set(a,e),this.unpop(e)}),this.addNewAndUpdateExisting(t,o(this,k)),s.forEach(e=>{e instanceof yt&&e.update(0)}),this.pop(s)}didUpdate(t){var c,d,x,E;(c=o(this,B))==null||c.cancel(),(d=o(this,L))==null||d.cancel(),(x=o(this,N))==null||x.cancel();const s=this.el.getBoundingClientRect(),e=s[this.justify]-t[this.justify],a=o(this,A)-e,l=Math.max(o(this,M),.01)/Math.max(s.width,.01),f=o(this,k).getBoundingClientRect();this.children.forEach(_=>_.didUpdate(f)),h(this,B,this.el.animate({transform:[`translateX(${a}px) scaleX(${l})`,"none"]},this.flow.xTiming)),l!==1&&(h(this,L,(E=o(this,k))==null?void 0:E.animate({transform:Rt(1e3,_=>`scaleX(${1/at(l,1,_)})`)},this.flow.xTiming)),h(this,N,this.el.animate(jt(1e3,_=>({"--_number-flow-scale-x":at(l,1,_)})),this.flow.xTiming)))}}k=new WeakMap,M=new WeakMap,A=new WeakMap,B=new WeakMap,N=new WeakMap,L=new WeakMap;var W,P;class rt extends mt{constructor(){super(...arguments);r(this,W);r(this,P)}willUpdate(t){const s=this.el.getBoundingClientRect();h(this,W,s[this.justify]-t[this.justify]),this.children.forEach(e=>e.willUpdate(s))}update(t){const s=new Map;this.children.forEach((e,a)=>{t.find(l=>l.key===a)||s.set(a,e)}),this.pop(s),this.addNewAndUpdateExisting(t)}didUpdate(t){var a;(a=o(this,P))==null||a.cancel();const s=this.el.getBoundingClientRect(),e=s[this.justify]-t[this.justify];this.children.forEach(l=>l.didUpdate(s)),h(this,P,this.el.animate({transform:[`translateX(${o(this,W)-e}px)`,"none"]},this.flow.xTiming))}}W=new WeakMap,P=new WeakMap;var R,H,j;class Q{constructor(i,t,{onRemove:s,animateIn:e=!1}={}){u(this,"flow");u(this,"el");r(this,R,!0);r(this,H);r(this,j);this.flow=i,this.el=t,e&&this.el.animate({opacity:["0","1"]},i.fadeTiming),h(this,H,s)}get present(){return o(this,R)}set present(i){var s;if(o(this,R)===i)return;const t=getComputedStyle(this.el).getPropertyValue("opacity");(s=o(this,j))==null||s.cancel(),h(this,j,this.el.animate({opacity:[t,i?"1":"0"]},this.flow.fadeTiming)),i||(o(this,j).onfinish=()=>{var e;this.el.remove(),(e=o(this,H))==null||e.call(this)}),h(this,R,i)}}R=new WeakMap,H=new WeakMap,j=new WeakMap;class gt extends Q{constructor(t,s,e,a){super(t.flow,e,a);u(this,"section");u(this,"value");u(this,"el");this.section=t,this.value=s,this.el=e}}var $,O,X,z,D;class yt extends gt{constructor(t,s,e,a){super(t,e,y("span",{className:"digit",textContent:e+""}),a);r(this,$);r(this,O);r(this,X);r(this,z);r(this,D)}willUpdate(t){h(this,$,this.value);const s=this.el.getBoundingClientRect();h(this,O,s.y-t.y);const e=s[this.section.justify]-t[this.section.justify],a=s.width/2;h(this,X,this.section.justify==="left"?e+a:e-a)}update(t){this.value=t,o(this,$)!==t&&_t(this.el,[...t===0?[]:[y("span",{className:"digit__stack digit__lt"},Array.from({length:t},(s,e)=>y("span",{textContent:e+""})))],document.createTextNode(t+""),...t===9?[]:[y("span",{className:"digit__stack digit__gt"},Array.from({length:9-t},(s,e)=>y("span",{textContent:t+e+1+""})))]])}didUpdate(t){var d,x;(d=o(this,z))==null||d.cancel(),o(this,$)!==this.value&&((x=o(this,D))==null||x.cancel());const s=this.el.getBoundingClientRect(),e=s[this.section.justify]-t[this.section.justify],a=s.width/2,l=this.section.justify==="left"?e+a:e-a,f=`translateX(${o(this,X)-l}px)`,c=`translateY(calc((100% + ${g}) * ${this.value-o(this,$)} + ${o(this,O)}px))`;h(this,z,this.el.animate({transform:[J?f:`${f} ${c}`,"none"]},{...this.flow.xTiming,composite:"accumulate"})),J&&o(this,$)!==this.value&&h(this,D,this.el.animate({transform:[c,"none"]},{...this.flow.yTiming,composite:"accumulate"}))}}$=new WeakMap,O=new WeakMap,X=new WeakMap,z=new WeakMap,D=new WeakMap;var w,F,I,Y;class Tt extends gt{constructor(t,s,e,a){const l=y("span",{className:"symbol__value",textContent:e});super(t,e,y("span",{className:"symbol"},[l]),a);u(this,"type");r(this,w,new Map);r(this,F);r(this,I,t=>()=>{o(this,w).delete(t)});r(this,Y);this.type=s,o(this,w).set(e,new Q(this.flow,l,{onRemove:o(this,I).call(this,e)}))}willUpdate(t){if(this.type==="decimal")return;const s=this.el.getBoundingClientRect();h(this,F,s[this.section.justify]-t[this.section.justify])}update(t){if(this.value!==t){const s=o(this,w).get(this.value);if(s.present=!1,s.el.classList.add("symbol__exiting"),o(this,w).has(t)){const e=o(this,w).get(t);e.present=!0,e.el.classList.remove("symbol__exiting")}else{const e=y("span",{className:"symbol__value",textContent:t});this.el.appendChild(e),o(this,w).set(t,new Q(this.flow,e,{animateIn:!0,onRemove:o(this,I).call(this,t)}))}}this.value=t}didUpdate(t){var a;if(this.type==="decimal")return;(a=o(this,Y))==null||a.cancel();const e=this.el.getBoundingClientRect()[this.section.justify]-t[this.section.justify];h(this,Y,this.el.animate({transform:[`translateX(${o(this,F)-e}px)`,"none"]},this.flow.xTiming))}}w=new WeakMap,F=new WeakMap,I=new WeakMap,Y=new WeakMap;exports.NumberFlowLite=Et;exports.SlottedTag=ft;exports.defaultFadeTiming=pt;exports.defaultXTiming=tt;exports.defaultYTiming=ut;exports.partitionParts=Ct;exports.slottedStyles=$t;exports.supportsAnimationComposition=J;exports.supportsLinear=ct;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const G=require("esm-env");function n(a,t,e,i){if(e==="a"&&!i)throw new TypeError("Private accessor was defined without a getter");if(typeof t=="function"?a!==t||!i:!t.has(a))throw new TypeError("Cannot read private member from an object whose class did not declare it");return e==="m"?i:e==="a"?i.call(a):i?i.value:t.get(a)}function h(a,t,e,i,s){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof t=="function"?a!==t||!s:!t.has(a))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?s.call(a,e):s?s.value=e:t.set(a,e),e}const g=(a,t,e)=>{const i=document.createElement(a),[s,o]=Array.isArray(t)?[void 0,t]:[t,e];return s&&Object.assign(i,s),o==null||o.forEach(r=>i.appendChild(r)),i},mt=(a,t)=>{var e;return t==="left"?a.offsetLeft:(((e=a.offsetParent instanceof HTMLElement?a.offsetParent:null)==null?void 0:e.offsetWidth)??0)-a.offsetWidth-a.offsetLeft};function gt(a,t,{reverse:e=!1}={}){const i=a.length;for(let s=e?i-1:0;e?s>=0:s<i;e?s--:s++)t(a[s],s)}function wt(a,t){const e=t.formatToParts(a),i=[],s=[],o=[],r=[],l={},f=c=>(l[c]||(l[c]=0),`${c}:${l[c]++}`);let $="",tt=!1,et=!1;for(const c of e){$+=c.value;const d=c.type==="minusSign"||c.type==="plusSign"?"sign":c.type;d==="integer"?(tt=!0,s.push(...c.value.split("").map(K=>({type:d,value:parseInt(K)})))):d==="group"?s.push({type:d,value:c.value}):d==="decimal"?(et=!0,o.push({type:d,value:c.value,key:f(d)})):d==="fraction"?o.push(...c.value.split("").map(K=>({type:d,value:parseInt(K),key:f(d)}))):(tt||et?r:i).push({type:d,value:c.value,key:f(d)})}const it=[];for(let c=s.length-1;c>=0;c--)it.unshift({...s[c],key:f(s[c].type)});return{pre:i,integer:it,fraction:o,post:r,formatted:$,value:typeof a=="string"?parseFloat(a):a}}const yt=G.BROWSER?HTMLElement:class{},_t=String.raw,vt=G.BROWSER&&typeof CSS<"u"&&CSS.supports("line-height","mod(1,1)"),T=G.BROWSER?matchMedia("(prefers-reduced-motion: reduce)"):null,z="--_number-flow-d-opacity",J="--_number-flow-d-width",I="--_number-flow-dx",Q="--_number-flow-d",bt=(()=>{try{return CSS.registerProperty({name:z,syntax:"<number>",inherits:!1,initialValue:"0"}),CSS.registerProperty({name:I,syntax:"<length>",inherits:!0,initialValue:"0px"}),CSS.registerProperty({name:J,syntax:"<number>",inherits:!1,initialValue:"0"}),CSS.registerProperty({name:Q,syntax:"<number>",inherits:!0,initialValue:"0"}),!0}catch{return!1}})(),ot="var(--number-flow-char-height, 1em)",m="var(--number-flow-mask-height, 0.25em)",N=`calc(${m} / 2)`,Y="var(--number-flow-mask-width, 0.5em)",y=`calc(${Y} / var(--scale-x))`,P="#000 0, transparent 71%",rt="span",St=({willChange:a})=>({fontKerning:"none",display:"inline-block",lineHeight:ot,padding:`${m} 0`,willChange:a?"transform":void 0}),st=_t`:host{display:inline-flex;align-items:baseline;direction:ltr;white-space:nowrap;position:relative;line-height:${ot} !important;isolation:isolate;}::slotted(${rt}){position:absolute;left:0;top:0;color:transparent !important;z-index:-5;}:host > .number,:host > .section{pointer-events:none;user-select:none;}.number,.number__inner{display:inline-flex;align-items:baseline;transform-origin:left top;}:host([data-will-change]) .number,:host([data-will-change]) .number__inner{will-change:transform;}.number{--scale-x:calc(1 + var(${J}) / var(--width));transform:translateX(var(${I})) scaleX(var(--scale-x));margin:0 calc(-1 * ${Y});position:relative;z-index:-1;overflow:clip;-webkit-mask-image:linear-gradient( to right,transparent 0,#000 ${y},#000 calc(100% - ${y}),transparent ),linear-gradient( to bottom,transparent 0,#000 ${m},#000 calc(100% - ${m}),transparent 100% ),radial-gradient(at bottom right,${P}),radial-gradient(at bottom left,${P}),radial-gradient(at top left,${P}),radial-gradient(at top right,${P});-webkit-mask-size:100% calc(100% - ${m} * 2),calc(100% - ${y} * 2) 100%,${y} ${m},${y} ${m},${y} ${m},${y} ${m};-webkit-mask-position:center,center,top left,top right,bottom right,bottom left;-webkit-mask-repeat:no-repeat;}.number__inner{padding:0 ${Y};transform:scaleX(calc(1 / var(--scale-x))) translateX(calc(-1 * var(${I})));}.section{display:inline-flex;align-items:baseline;padding-bottom:${N};padding-top:${N};position:relative;isolation:isolate;}.section::after{content:'\200b';display:block;padding:${N} 0;}:host([data-will-change]) .section{will-change:transform;}.section--justify-left{transform-origin:center left;}.section--justify-right{transform-origin:center right;}.section__exiting{position:absolute !important;z-index:-1;}.digit{display:block;position:relative;--c:var(--current) + var(${Q});}:host([data-will-change]) .digit,:host([data-will-change]) .digit__num{will-change:transform;}.digit__num{display:block;padding:${N} 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-flex;align-items:baseline;position:relative;isolation:isolate;padding:${N} 0;}:host([data-will-change]) .symbol{will-change:transform;}.symbol__value{display:block;white-space:pre;}.symbol__exiting{position:absolute;z-index:-1;}.section--justify-left .symbol__exiting{left:0;}.section--justify-right .symbol__exiting{right:0;}.animate-presence{opacity:calc(1 + var(${z}));}`;var j,L,_,v,b,S,W,x,A,E,k,O,F,D,C,B,M,R,u,H,q,w,V,X;const lt=vt&&bt;var p;(function(a){a[a.UP=1]="UP",a[a.DOWN=-1]="DOWN",a[a.NONE=0]="NONE"})(p||(p={}));const ht=(a,t)=>{if(t!=null)return a>t?p.UP:a<t?p.DOWN:p.NONE},ct={duration:450,easing:"ease-out"},ft={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)"};let U;class Et extends yt{constructor(){super(...arguments),this.transformTiming=ft,this.opacityTiming=ct,j.set(this,!0),this.manual=!1,this.respectMotionPreference=!0,L.set(this,!1),_.set(this,void 0),v.set(this,void 0),b.set(this,void 0),this.trend=!0,S.set(this,void 0),W.set(this,void 0),x.set(this,void 0)}static define(){G.BROWSER&&customElements.define("number-flow",this)}getComputedTrend(){return n(this,S,"f")}set parts(t){if(t==null)return;const{pre:e,integer:i,fraction:s,post:o,value:r}=t;if(n(this,L,"f")){const l=n(this,W,"f");h(this,W,r,"f"),this.trend===!0?h(this,S,ht(r,l),"f"):this.trend==="increasing"?h(this,S,p.UP,"f"):this.trend==="decreasing"?h(this,S,p.DOWN,"f"):h(this,S,p.NONE,"f"),this.manual||this.willUpdate(),n(this,_,"f").update(e),n(this,v,"f").update({integer:i,fraction:s}),n(this,b,"f").update(o),this.manual||this.didUpdate()}else{if(h(this,W,r,"f"),this.attachShadow({mode:"open"}),typeof CSSStyleSheet<"u"&&this.shadowRoot.adoptedStyleSheets)U||(U=new CSSStyleSheet,U.replaceSync(st)),this.shadowRoot.adoptedStyleSheets=[U];else{const l=document.createElement("style");l.textContent=st,this.shadowRoot.appendChild(l)}this.shadowRoot.appendChild(g("slot")),h(this,_,new at(this,e,{inert:!0,ariaHidden:"true",justify:"right"}),"f"),this.shadowRoot.appendChild(n(this,_,"f").el),h(this,v,new kt(this,i,s,{inert:!0,ariaHidden:"true"}),"f"),this.shadowRoot.appendChild(n(this,v,"f").el),h(this,b,new at(this,o,{inert:!0,ariaHidden:"true",justify:"left"}),"f"),this.shadowRoot.appendChild(n(this,b,"f").el)}h(this,L,!0,"f")}willUpdate(){this.animated&&(n(this,_,"f").willUpdate(),n(this,v,"f").willUpdate(),n(this,b,"f").willUpdate())}didUpdate(){if(!this.animated)return;n(this,x,"f")?n(this,x,"f").abort():this.dispatchEvent(new Event("animationsstart")),n(this,_,"f").didUpdate(),n(this,v,"f").didUpdate(),n(this,b,"f").didUpdate();const t=new AbortController;Promise.all(this.shadowRoot.getAnimations().map(e=>e.finished)).then(()=>{t.signal.aborted||(this.dispatchEvent(new Event("animationsfinish")),h(this,x,void 0,"f"))}),h(this,x,t,"f")}get animated(){return lt&&n(this,j,"f")&&(!this.respectMotionPreference||!(T!=null&&T.matches))}set animated(t){var e;this.animated!==t&&(h(this,j,t,"f"),(e=this.shadowRoot)==null||e.getAnimations().forEach(i=>i.finish()))}}j=new WeakMap,L=new WeakMap,_=new WeakMap,v=new WeakMap,b=new WeakMap,S=new WeakMap,W=new WeakMap,x=new WeakMap;class kt{constructor(t,e,i,{className:s,...o}={}){this.flow=t,A.set(this,void 0),E.set(this,void 0),k.set(this,void 0),O.set(this,void 0),F.set(this,void 0),h(this,E,new nt(t,e,{justify:"right"}),"f"),h(this,k,new nt(t,i,{justify:"left"}),"f"),h(this,A,g("span",{className:"number__inner"},[n(this,E,"f").el,n(this,k,"f").el]),"f"),this.el=g("span",{...o,className:`number ${s??""}`},[n(this,A,"f")])}willUpdate(){h(this,O,this.el.offsetWidth,"f"),h(this,F,this.el.getBoundingClientRect().left,"f"),n(this,E,"f").willUpdate(),n(this,k,"f").willUpdate()}update({integer:t,fraction:e}){n(this,E,"f").update(t),n(this,k,"f").update(e)}didUpdate(){const t=this.el.getBoundingClientRect();n(this,E,"f").didUpdate(),n(this,k,"f").didUpdate();const e=n(this,F,"f")-t.left,i=this.el.offsetWidth,s=n(this,O,"f")-i;this.el.style.setProperty("--width",String(i)),this.el.animate({[I]:[`${e}px`,"0px"],[J]:[s,0]},{...this.flow.transformTiming,composite:"accumulate"})}}A=new WeakMap,E=new WeakMap,k=new WeakMap,O=new WeakMap,F=new WeakMap;class dt{constructor(t,e,{justify:i,className:s,...o},r){this.flow=t,this.children=new Map,this.onCharRemove=f=>()=>{this.children.delete(f)},D.set(this,void 0),this.justify=i;const l=e.map(f=>this.addChar(f).el);this.el=g("span",{...o,className:`section section--justify-${i} ${s??""}`},r?r(l):l)}addChar(t,{startDigitsAtZero:e=!1,...i}={}){const s=t.type==="integer"||t.type==="fraction"?new ut(this,t.type,e?0:t.value,{...i,onRemove:this.onCharRemove(t.key)}):new xt(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[this.justify]=""}pop(t){t.forEach(e=>{e.el.style[this.justify]=`${mt(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",o=s?"prepend":"append";if(gt(t,r=>{let l;this.children.has(r.key)?(l=this.children.get(r.key),i.set(r,l),this.unpop(l),l.present=!0):(l=this.addChar(r,{startDigitsAtZero:!0,animateIn:!0}),e.set(r,l)),this.el[o](l.el)},{reverse:s}),this.flow.animated){const r=this.el.getBoundingClientRect();e.forEach(l=>{l.willUpdate(r)})}e.forEach((r,l)=>{r.update(l.value)}),i.forEach((r,l)=>{r.update(l.value)})}willUpdate(){const t=this.el.getBoundingClientRect();h(this,D,t[this.justify],"f"),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=n(this,D,"f")-e;this.el.animate({transform:[`translateX(${i}px)`,"none"]},{...this.flow.transformTiming,composite:"accumulate"})}}D=new WeakMap;class nt extends dt{update(t){const e=new Map;this.children.forEach((i,s)=>{t.find(o=>o.key===s)||e.set(s,i),this.unpop(i)}),this.addNewAndUpdateExisting(t),e.forEach(i=>{i instanceof ut&&i.update(0)}),this.pop(e)}}class at extends dt{update(t){const e=new Map;this.children.forEach((i,s)=>{t.find(o=>o.key===s)||e.set(s,i)}),this.pop(e),this.addNewAndUpdateExisting(t)}}class Z{constructor(t,e,{onRemove:i,animateIn:s=!1}={}){this.flow=t,this.el=e,C.set(this,!0),B.set(this,void 0),M.set(this,()=>{var o;this.el.remove(),(o=n(this,B,"f"))==null||o.call(this)}),this.el.classList.add("animate-presence"),this.flow.animated&&s&&this.el.animate({[z]:[-.9999,0]},{...this.flow.opacityTiming,composite:"accumulate"}),h(this,B,i,"f")}get present(){return n(this,C,"f")}set present(t){if(n(this,C,"f")!==t){if(h(this,C,t,"f"),!this.flow.animated){t||n(this,M,"f").call(this);return}this.el.style.setProperty("--_number-flow-d-opacity",t?"0":"-.999"),this.el.animate({[z]:t?[-.9999,0]:[.999,0]},{...this.flow.opacityTiming,composite:"accumulate"}),t?this.flow.removeEventListener("animationsfinish",n(this,M,"f")):this.flow.addEventListener("animationsfinish",n(this,M,"f"),{once:!0})}}}C=new WeakMap,B=new WeakMap,M=new WeakMap;class pt extends Z{constructor(t,e,i,s){super(t.flow,i,s),this.section=t,this.value=e,this.el=i}}class ut extends pt{constructor(t,e,i,s){const o=Array.from({length:10}).map((l,f)=>{const $=g("span",{className:`digit__num${f===i?" is-current":""}`},[document.createTextNode(String(f))]);return $.style.setProperty("--n",String(f)),$}),r=g("span",{className:"digit"},o);r.style.setProperty("--current",String(i)),super(t,i,r,s),R.set(this,void 0),u.set(this,void 0),H.set(this,void 0),q.set(this,()=>{this.el.classList.remove("is-spinning")}),h(this,R,o,"f")}get trend(){const t=this.flow.getComputedTrend();return t===p.NONE?ht(this.value,n(this,u,"f")):t}willUpdate(t){const e=this.el.getBoundingClientRect();h(this,u,this.value,"f");const i=e[this.section.justify]-t[this.section.justify],s=e.width/2;h(this,H,this.section.justify==="left"?i+s:i-s,"f")}update(t){var e,i;(e=n(this,R,"f")[this.value])==null||e.classList.remove("is-current"),this.el.style.setProperty("--current",String(t)),(i=n(this,R,"f")[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,o=this.section.justify==="left"?i+s:i-s;if(this.el.animate({transform:[`translateX(${n(this,H,"f")-o}px)`,"none"]},{...this.flow.transformTiming,composite:"accumulate"}),this.value===n(this,u,"f"))return;const r=this.trend;let l=this.value-n(this,u,"f");r===p.DOWN&&this.value>n(this,u,"f")&&(l=this.value-10-n(this,u,"f")),r===p.UP&&this.value<n(this,u,"f")&&(l=10-n(this,u,"f")+this.value),this.el.classList.add("is-spinning"),this.el.animate({[Q]:[-l,0]},{...this.flow.spinTiming??this.flow.transformTiming,composite:"accumulate"}),this.flow.addEventListener("animationsfinish",n(this,q,"f"),{once:!0})}}R=new WeakMap,u=new WeakMap,H=new WeakMap,q=new WeakMap;class xt extends pt{constructor(t,e,i,s){const o=g("span",{className:"symbol__value",textContent:i});super(t,i,g("span",{className:"symbol"},[o]),s),this.type=e,w.set(this,new Map),V.set(this,void 0),X.set(this,r=>()=>{n(this,w,"f").delete(r)}),n(this,w,"f").set(i,new Z(this.flow,o,{onRemove:n(this,X,"f").call(this,i)}))}willUpdate(t){if(this.type==="decimal")return;const e=this.el.getBoundingClientRect();h(this,V,e[this.section.justify]-t[this.section.justify],"f")}update(t){if(this.value!==t){const e=n(this,w,"f").get(this.value);if(e.present=!1,e.el.classList.add("symbol__exiting"),n(this,w,"f").has(t)){const i=n(this,w,"f").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),n(this,w,"f").set(t,new Z(this.flow,i,{animateIn:!0,onRemove:n(this,X,"f").call(this,t)}))}}this.value=t}didUpdate(t){if(this.type==="decimal")return;const i=this.el.getBoundingClientRect()[this.section.justify]-t[this.section.justify];this.el.animate({transform:[`translateX(${n(this,V,"f")-i}px)`,"none"]},{...this.flow.transformTiming,composite:"accumulate"})}}w=new WeakMap,V=new WeakMap,X=new WeakMap;exports.NumberFlowLite=Et;exports.SlottedTag=rt;exports.canAnimate=lt;exports.defaultOpacityTiming=ct;exports.defaultTransformTiming=ft;exports.partitionParts=wt;exports.prefersReducedMotion=T;exports.slottedStyles=St;
package/dist/index.mjs CHANGED
@@ -1,440 +1,416 @@
1
- var ut = Object.defineProperty;
2
- var Q = (n) => {
3
- throw TypeError(n);
4
- };
5
- var mt = (n, i, t) => i in n ? ut(n, i, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[i] = t;
6
- var u = (n, i, t) => mt(n, typeof i != "symbol" ? i + "" : i, t), tt = (n, i, t) => i.has(n) || Q("Cannot " + t);
7
- var o = (n, i, t) => (tt(n, i, "read from private field"), t ? t.call(n) : i.get(n)), r = (n, i, t) => i.has(n) ? Q("Cannot add the same private member more than once") : i instanceof WeakSet ? i.add(n) : i.set(n, t), h = (n, i, t, s) => (tt(n, i, "write to private field"), s ? s.call(n, t) : i.set(n, t), t);
8
- import { BROWSER as Y } from "esm-env";
9
- const y = (n, i, t) => {
10
- const s = document.createElement(n), [e, a] = Array.isArray(i) ? [void 0, i] : [i, t];
11
- return e && Object.assign(s, e), a == null || a.forEach((l) => s.appendChild(l)), s;
12
- }, gt = (n, i) => {
13
- typeof Element.prototype.replaceChildren > "u" ? (n.innerHTML = "", i.forEach((t) => n.appendChild(t))) : n.replaceChildren(...i);
14
- }, yt = (n, i) => {
15
- var t;
16
- return i === "left" ? n.offsetLeft : (((t = n.offsetParent instanceof HTMLElement ? n.offsetParent : null) == null ? void 0 : t.offsetWidth) ?? 0) - n.offsetWidth - n.offsetLeft;
1
+ import { BROWSER as I } from "esm-env";
2
+ function n(a, t, e, i) {
3
+ if (e === "a" && !i) throw new TypeError("Private accessor was defined without a getter");
4
+ if (typeof t == "function" ? a !== t || !i : !t.has(a)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
5
+ return e === "m" ? i : e === "a" ? i.call(a) : i ? i.value : t.get(a);
6
+ }
7
+ function h(a, t, e, i, s) {
8
+ if (i === "m") throw new TypeError("Private method is not writable");
9
+ if (i === "a" && !s) throw new TypeError("Private accessor was defined without a setter");
10
+ if (typeof t == "function" ? a !== t || !s : !t.has(a)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
11
+ return i === "a" ? s.call(a, e) : s ? s.value = e : t.set(a, e), e;
12
+ }
13
+ const g = (a, t, e) => {
14
+ const i = document.createElement(a), [s, o] = Array.isArray(t) ? [void 0, t] : [t, e];
15
+ return s && Object.assign(i, s), o == null || o.forEach((r) => i.appendChild(r)), i;
16
+ }, ft = (a, t) => {
17
+ var e;
18
+ return t === "left" ? a.offsetLeft : (((e = a.offsetParent instanceof HTMLElement ? a.offsetParent : null) == null ? void 0 : e.offsetWidth) ?? 0) - a.offsetWidth - a.offsetLeft;
17
19
  };
18
- function wt(n, i, { reverse: t = !1 } = {}) {
19
- const s = n.length;
20
- for (let e = t ? s - 1 : 0; t ? e >= 0 : e < s; t ? e-- : e++)
21
- i(n[e], e);
20
+ function dt(a, t, { reverse: e = !1 } = {}) {
21
+ const i = a.length;
22
+ for (let s = e ? i - 1 : 0; e ? s >= 0 : s < i; e ? s-- : s++)
23
+ t(a[s], s);
22
24
  }
23
- function Et(n, i) {
24
- const t = i.formatToParts(n), s = [], e = [], a = [], l = [], f = {}, c = (p) => (f[p] || (f[p] = 0), `${p}:${f[p]++}`);
25
- let d = "", x = !1, U = !1;
26
- for (const p of t) {
27
- d += p.value;
28
- const m = p.type === "minusSign" || p.type === "plusSign" ? "sign" : p.type;
29
- m === "integer" ? (x = !0, e.push(...p.value.split("").map((q) => ({ type: m, value: parseInt(q) })))) : m === "group" ? e.push({ type: m, value: p.value }) : m === "decimal" ? (U = !0, a.push({ type: m, value: p.value, key: c(m) })) : m === "fraction" ? a.push(...p.value.split("").map((q) => ({ type: m, value: parseInt(q), key: c(m) }))) : (x || U ? l : s).push({
30
- type: m,
31
- value: p.value,
32
- key: c(m)
25
+ function kt(a, t) {
26
+ const e = t.formatToParts(a), i = [], s = [], o = [], r = [], l = {}, f = (c) => (l[c] || (l[c] = 0), `${c}:${l[c]++}`);
27
+ let E = "", tt = !1, et = !1;
28
+ for (const c of e) {
29
+ E += c.value;
30
+ const d = c.type === "minusSign" || c.type === "plusSign" ? "sign" : c.type;
31
+ d === "integer" ? (tt = !0, s.push(...c.value.split("").map((G) => ({ type: d, value: parseInt(G) })))) : d === "group" ? s.push({ type: d, value: c.value }) : d === "decimal" ? (et = !0, o.push({ type: d, value: c.value, key: f(d) })) : d === "fraction" ? o.push(...c.value.split("").map((G) => ({ type: d, value: parseInt(G), key: f(d) }))) : (tt || et ? r : i).push({
32
+ type: d,
33
+ value: c.value,
34
+ key: f(d)
33
35
  });
34
36
  }
35
- const _ = [];
36
- for (let p = e.length - 1; p >= 0; p--)
37
- _.unshift({ ...e[p], key: c(e[p].type) });
38
- return { pre: s, integer: _, fraction: a, post: l, formatted: d };
37
+ const it = [];
38
+ for (let c = s.length - 1; c >= 0; c--)
39
+ it.unshift({ ...s[c], key: f(s[c].type) });
40
+ return {
41
+ pre: i,
42
+ integer: it,
43
+ fraction: o,
44
+ post: r,
45
+ formatted: E,
46
+ value: typeof a == "string" ? parseFloat(a) : a
47
+ };
39
48
  }
40
- const xt = Y ? HTMLElement : class {
41
- }, _t = String.raw, bt = Y && typeof CSS < "u" && CSS.supports("transition-timing-function", "linear(1, 2)"), rt = Y && typeof CSS < "u" && typeof CSS.registerProperty < "u", et = Y && typeof CSS < "u" && typeof CSS.supports("animation-composition", "accumulate") < "u";
42
- if (rt)
49
+ const pt = I ? HTMLElement : class {
50
+ }, ut = String.raw, mt = I && typeof CSS < "u" && CSS.supports("line-height", "mod(1,1)"), K = I ? matchMedia("(prefers-reduced-motion: reduce)") : null, X = "--_number-flow-d-opacity", J = "--_number-flow-d-width", z = "--_number-flow-dx", Q = "--_number-flow-d", gt = (() => {
43
51
  try {
44
- CSS.registerProperty({
45
- name: "--_number-flow-scale-x",
52
+ return CSS.registerProperty({
53
+ name: X,
46
54
  syntax: "<number>",
47
55
  inherits: !1,
48
- initialValue: "1"
49
- });
56
+ initialValue: "0"
57
+ }), CSS.registerProperty({
58
+ name: z,
59
+ syntax: "<length>",
60
+ inherits: !0,
61
+ initialValue: "0px"
62
+ }), CSS.registerProperty({
63
+ name: J,
64
+ syntax: "<number>",
65
+ inherits: !1,
66
+ initialValue: "0"
67
+ }), CSS.registerProperty({
68
+ name: Q,
69
+ syntax: "<number>",
70
+ inherits: !0,
71
+ initialValue: "0"
72
+ }), !0;
50
73
  } catch {
74
+ return !1;
51
75
  }
52
- const ct = "var(--number-flow-char-height, 1em)", g = "var(--number-flow-mask-height, 0.25em)", E = "var(--number-flow-mask-width, 0.5em)", Z = `${E} * 1/var(--_number-flow-scale-x)`, it = `calc(${Z})`, st = `linear-gradient(to bottom, transparent 0, #000 ${g}, #000 calc(100% - ${g}), transparent 100%)`, K = "#000 0, transparent 71%", Ct = "span", Tt = {
76
+ })(), ot = "var(--number-flow-char-height, 1em)", m = "var(--number-flow-mask-height, 0.25em)", N = `calc(${m} / 2)`, Y = "var(--number-flow-mask-width, 0.5em)", y = `calc(${Y} / var(--scale-x))`, P = "#000 0, transparent 71%", wt = "span", $t = ({ willChange: a }) => ({
53
77
  fontKerning: "none",
54
78
  display: "inline-block",
55
- lineHeight: ct,
56
- padding: `${g} 0`
57
- }, nt = _t`:host{display:inline-block;direction:ltr;user-select:none;pointer-events:none;white-space:nowrap;position:relative;line-height:${ct} !important;isolation:isolate;}::slotted(${Ct}){position:absolute;left:0;top:0;color:transparent !important;z-index:-1;user-select:text;pointer-events:auto;}.section{display:inline-block;padding-bottom:${g};padding-top:${g};vertical-align:top;user-select:none;}.section:not(.section--masked),.section--masked .section__inner{position:relative;isolation:isolate;}.section__inner{display:inline-block;transform-origin:inherit;}.section--justify-left{transform-origin:center left;}.section--justify-right{transform-origin:center right;}.section--masked{overflow:clip;position:relative;z-index:-1;--_number-flow-scale-x:1;-webkit-mask-repeat:no-repeat;-webkit-mask-size:calc(100% - ${Z}) 100%,100% calc(100% - ${g} * 2),${it} ${g},${it} ${g};}.section--masked.section--justify-left{padding-right:${E};margin-right:calc(-1 * ${E});-webkit-mask-image:${st},linear-gradient(to right,#000 0,#000 calc(100% - ${Z}),transparent 100%),radial-gradient(at bottom left,${K}),radial-gradient(at top left,${K});-webkit-mask-position:left,center,right top,right bottom;}.section--masked.section--justify-right{padding-left:${E};margin-left:calc(-1 * ${E});-webkit-mask-image:${st},linear-gradient(to left,#000 0,#000 calc(100% - ${Z}),transparent 100%),radial-gradient(at bottom right,${K}),radial-gradient(at top right,${K});-webkit-mask-position:right,center,left top,left bottom;}.section__exiting{position:absolute !important;z-index:-1;}.digit{display:inline-block;position:relative;}.digit__stack{display:flex;flex-direction:column;align-items:center;gap:${g};position:absolute;width:100%;}.digit__stack > *{display:inline-block;}.digit__lt{bottom:calc(100% + ${g});}.digit__gt{top:calc(100% + ${g});}.symbol{display:inline-block;position:relative;isolation:isolate;}.symbol__value{display:inline-block;white-space:pre;}.symbol__exiting{position:absolute;z-index:-1;}.section--justify-left .symbol__exiting{left:0;}.section--justify-right .symbol__exiting{right:0;}`;
58
- function kt(n, i, t = 60) {
59
- const s = Math.trunc(n / 1e3 * t);
60
- return Array.from({ length: s }, (e, a) => i(a / (s - 1)));
61
- }
62
- function vt(n, i, t = 60) {
63
- if (rt)
64
- return [i(0), i(1)];
65
- const s = Math.max(Math.trunc(n / 1e3 * t), 0), e = Array.from({ length: s }, (a, l) => ({
66
- ...i(l / s),
67
- offset: (l + 0.5) / s
68
- }));
69
- return e.unshift({
70
- ...i(0),
71
- offset: 0
72
- }), e;
73
- }
74
- const ot = (n, i, t) => n + (i - n) * t, $t = {
75
- duration: 500,
76
- easing: "ease-out",
77
- endDelay: 400,
78
- fill: "forwards"
79
- }, ht = bt ? {
79
+ lineHeight: ot,
80
+ padding: `${m} 0`,
81
+ willChange: a ? "transform" : void 0
82
+ }), st = ut`:host{display:inline-flex;align-items:baseline;direction:ltr;white-space:nowrap;position:relative;line-height:${ot} !important;isolation:isolate;}::slotted(${wt}){position:absolute;left:0;top:0;color:transparent !important;z-index:-5;}:host > .number,:host > .section{pointer-events:none;user-select:none;}.number,.number__inner{display:inline-flex;align-items:baseline;transform-origin:left top;}:host([data-will-change]) .number,:host([data-will-change]) .number__inner{will-change:transform;}.number{--scale-x:calc(1 + var(${J}) / var(--width));transform:translateX(var(${z})) scaleX(var(--scale-x));margin:0 calc(-1 * ${Y});position:relative;z-index:-1;overflow:clip;-webkit-mask-image:linear-gradient( to right,transparent 0,#000 ${y},#000 calc(100% - ${y}),transparent ),linear-gradient( to bottom,transparent 0,#000 ${m},#000 calc(100% - ${m}),transparent 100% ),radial-gradient(at bottom right,${P}),radial-gradient(at bottom left,${P}),radial-gradient(at top left,${P}),radial-gradient(at top right,${P});-webkit-mask-size:100% calc(100% - ${m} * 2),calc(100% - ${y} * 2) 100%,${y} ${m},${y} ${m},${y} ${m},${y} ${m};-webkit-mask-position:center,center,top left,top right,bottom right,bottom left;-webkit-mask-repeat:no-repeat;}.number__inner{padding:0 ${Y};transform:scaleX(calc(1 / var(--scale-x))) translateX(calc(-1 * var(${z})));}.section{display:inline-flex;align-items:baseline;padding-bottom:${N};padding-top:${N};position:relative;isolation:isolate;}.section::after{content:'\200b';display:block;padding:${N} 0;}:host([data-will-change]) .section{will-change:transform;}.section--justify-left{transform-origin:center left;}.section--justify-right{transform-origin:center right;}.section__exiting{position:absolute !important;z-index:-1;}.digit{display:block;position:relative;--c:var(--current) + var(${Q});}:host([data-will-change]) .digit,:host([data-will-change]) .digit__num{will-change:transform;}.digit__num{display:block;padding:${N} 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-flex;align-items:baseline;position:relative;isolation:isolate;padding:${N} 0;}:host([data-will-change]) .symbol{will-change:transform;}.symbol__value{display:block;white-space:pre;}.symbol__exiting{position:absolute;z-index:-1;}.section--justify-left .symbol__exiting{left:0;}.section--justify-right .symbol__exiting{right:0;}.animate-presence{opacity:calc(1 + var(${X}));}`;
83
+ var R, L, _, v, b, S, C, $, T, x, k, A, D, F, W, O, M, U, u, B, Z, w, H, V;
84
+ const yt = mt && gt;
85
+ var p;
86
+ (function(a) {
87
+ a[a.UP = 1] = "UP", a[a.DOWN = -1] = "DOWN", a[a.NONE = 0] = "NONE";
88
+ })(p || (p = {}));
89
+ const rt = (a, t) => {
90
+ if (t != null)
91
+ return a > t ? p.UP : a < t ? p.DOWN : p.NONE;
92
+ }, _t = { duration: 450, easing: "ease-out" }, vt = {
80
93
  duration: 900,
94
+ // Make sure to keep this minified:
81
95
  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)"
82
- } : {
83
- duration: 900,
84
- // Spring-like cubic-bezier stolen from Vaul: https://vaul.emilkowal.ski/
85
- easing: "cubic-bezier(.32,.72,0,1)"
86
- }, St = ht;
87
- let G;
88
- var T, b, C, k, v;
89
- class Mt extends xt {
96
+ };
97
+ let j;
98
+ class Et extends pt {
90
99
  constructor() {
91
- super(...arguments);
92
- u(this, "xTiming", ht);
93
- u(this, "yTiming", St);
94
- u(this, "fadeTiming", $t);
95
- u(this, "root", !1);
96
- u(this, "manual", !1);
97
- r(this, T, !1);
98
- r(this, b);
99
- r(this, C);
100
- r(this, k);
101
- r(this, v);
100
+ super(...arguments), this.transformTiming = vt, this.opacityTiming = _t, R.set(this, !0), this.manual = !1, this.respectMotionPreference = !0, L.set(this, !1), _.set(this, void 0), v.set(this, void 0), b.set(this, void 0), this.trend = !0, S.set(this, void 0), C.set(this, void 0), $.set(this, void 0);
102
101
  }
103
102
  static define() {
104
- Y && customElements.define("number-flow", this);
103
+ I && customElements.define("number-flow", this);
104
+ }
105
+ getComputedTrend() {
106
+ return n(this, S, "f");
105
107
  }
106
108
  set parts(t) {
107
109
  if (t == null)
108
110
  return;
109
- const { pre: s, integer: e, fraction: a, post: l } = t;
110
- if (o(this, T))
111
- this.manual || this.willUpdate(), o(this, b).update(s), o(this, C).update(e), o(this, k).update(a), o(this, v).update(l), this.manual || this.didUpdate();
112
- else {
113
- if (this.attachShadow({ mode: "open" }), typeof CSSStyleSheet < "u" && this.shadowRoot.adoptedStyleSheets)
114
- G || (G = new CSSStyleSheet(), G.replaceSync(nt)), this.shadowRoot.adoptedStyleSheets = [G];
111
+ const { pre: e, integer: i, fraction: s, post: o, value: r } = t;
112
+ if (n(this, L, "f")) {
113
+ const l = n(this, C, "f");
114
+ h(this, C, r, "f"), this.trend === !0 ? h(this, S, rt(r, l), "f") : this.trend === "increasing" ? h(this, S, p.UP, "f") : this.trend === "decreasing" ? h(this, S, p.DOWN, "f") : h(this, S, p.NONE, "f"), this.manual || this.willUpdate(), n(this, _, "f").update(e), n(this, v, "f").update({ integer: i, fraction: s }), n(this, b, "f").update(o), this.manual || this.didUpdate();
115
+ } else {
116
+ if (h(this, C, r, "f"), this.attachShadow({ mode: "open" }), typeof CSSStyleSheet < "u" && this.shadowRoot.adoptedStyleSheets)
117
+ j || (j = new CSSStyleSheet(), j.replaceSync(st)), this.shadowRoot.adoptedStyleSheets = [j];
115
118
  else {
116
- const f = document.createElement("style");
117
- f.textContent = nt, this.shadowRoot.appendChild(f);
119
+ const l = document.createElement("style");
120
+ l.textContent = st, this.shadowRoot.appendChild(l);
118
121
  }
119
- this.shadowRoot.appendChild(y("slot")), h(this, b, new lt(this, s, {
120
- // part: 'pre',
122
+ this.shadowRoot.appendChild(g("slot")), h(this, _, new at(this, e, {
121
123
  inert: !0,
122
124
  ariaHidden: "true",
123
125
  justify: "right"
124
- })), this.shadowRoot.appendChild(o(this, b).el), h(this, C, new at(this, e, {
125
- // part: 'integer',
126
+ }), "f"), this.shadowRoot.appendChild(n(this, _, "f").el), h(this, v, new bt(this, i, s, {
126
127
  inert: !0,
127
- ariaHidden: "true",
128
- justify: "right"
129
- })), this.shadowRoot.appendChild(o(this, C).el), h(this, k, new at(this, a, {
130
- // part: 'fraction',
128
+ ariaHidden: "true"
129
+ }), "f"), this.shadowRoot.appendChild(n(this, v, "f").el), h(this, b, new at(this, o, {
131
130
  inert: !0,
132
131
  ariaHidden: "true",
133
132
  justify: "left"
134
- })), this.shadowRoot.appendChild(o(this, k).el), h(this, v, new lt(this, l, {
135
- // part: 'post',
136
- inert: !0,
137
- ariaHidden: "true",
138
- justify: "left"
139
- })), this.shadowRoot.appendChild(o(this, v).el);
133
+ }), "f"), this.shadowRoot.appendChild(n(this, b, "f").el);
140
134
  }
141
- h(this, T, !0);
135
+ h(this, L, !0, "f");
142
136
  }
143
137
  willUpdate() {
144
- const t = this.root ? this.getBoundingClientRect() : new DOMRect();
145
- o(this, b).willUpdate(t), o(this, C).willUpdate(t), o(this, k).willUpdate(t), o(this, v).willUpdate(t);
138
+ this.animated && (n(this, _, "f").willUpdate(), n(this, v, "f").willUpdate(), n(this, b, "f").willUpdate());
146
139
  }
147
140
  didUpdate() {
148
- const t = this.root ? this.getBoundingClientRect() : new DOMRect();
149
- o(this, b).didUpdate(t), o(this, C).didUpdate(t), o(this, k).didUpdate(t), o(this, v).didUpdate(t);
141
+ if (!this.animated)
142
+ return;
143
+ n(this, $, "f") ? n(this, $, "f").abort() : this.dispatchEvent(new Event("animationsstart")), n(this, _, "f").didUpdate(), n(this, v, "f").didUpdate(), n(this, b, "f").didUpdate();
144
+ const t = new AbortController();
145
+ Promise.all(this.shadowRoot.getAnimations().map((e) => e.finished)).then(() => {
146
+ t.signal.aborted || (this.dispatchEvent(new Event("animationsfinish")), h(this, $, void 0, "f"));
147
+ }), h(this, $, t, "f");
148
+ }
149
+ get animated() {
150
+ return yt && n(this, R, "f") && (!this.respectMotionPreference || !(K != null && K.matches));
151
+ }
152
+ set animated(t) {
153
+ var e;
154
+ this.animated !== t && (h(this, R, t, "f"), (e = this.shadowRoot) == null || e.getAnimations().forEach((i) => i.finish()));
150
155
  }
151
156
  }
152
- T = new WeakMap(), b = new WeakMap(), C = new WeakMap(), k = new WeakMap(), v = new WeakMap();
153
- class dt {
154
- constructor(i, t, { justify: s, className: e, ...a }, l) {
155
- u(this, "flow");
156
- u(this, "el");
157
- u(this, "justify");
158
- // All children in the DOM:
159
- u(this, "children", /* @__PURE__ */ new Map());
160
- u(this, "onCharRemove", (i) => () => {
161
- this.children.delete(i);
162
- });
163
- this.flow = i, this.justify = s;
164
- const f = t.map((c) => this.addChar(c).el);
165
- f.push(document.createTextNode("​")), this.el = y("span", {
166
- ...a,
167
- className: `section section--justify-${s} ${e ?? ""}`
168
- }, l ? l(f) : f);
169
- }
170
- addChar(i, { startDigitsAtZero: t = !1, ...s } = {}) {
171
- const e = i.type === "integer" || i.type === "fraction" ? new pt(this, i.type, t ? 0 : i.value, {
172
- ...s,
173
- onRemove: this.onCharRemove(i.key)
174
- }) : new jt(this, i.type, i.value, {
175
- ...s,
176
- onRemove: this.onCharRemove(i.key)
177
- });
178
- return this.children.set(i.key, e), e;
157
+ R = /* @__PURE__ */ new WeakMap(), L = /* @__PURE__ */ new WeakMap(), _ = /* @__PURE__ */ new WeakMap(), v = /* @__PURE__ */ new WeakMap(), b = /* @__PURE__ */ new WeakMap(), S = /* @__PURE__ */ new WeakMap(), C = /* @__PURE__ */ new WeakMap(), $ = /* @__PURE__ */ new WeakMap();
158
+ class bt {
159
+ constructor(t, e, i, { className: s, ...o } = {}) {
160
+ this.flow = t, T.set(this, void 0), x.set(this, void 0), k.set(this, void 0), A.set(this, void 0), D.set(this, void 0), h(this, x, new nt(t, e, {
161
+ justify: "right"
162
+ }), "f"), h(this, k, new nt(t, i, {
163
+ justify: "left"
164
+ }), "f"), h(this, T, g("span", {
165
+ className: "number__inner"
166
+ }, [n(this, x, "f").el, n(this, k, "f").el]), "f"), this.el = g("span", {
167
+ ...o,
168
+ className: `number ${s ?? ""}`
169
+ }, [n(this, T, "f")]);
179
170
  }
180
- unpop(i) {
181
- i.el.classList.remove("section__exiting"), i.el.style[this.justify] = "";
171
+ willUpdate() {
172
+ h(this, A, this.el.offsetWidth, "f"), h(this, D, this.el.getBoundingClientRect().left, "f"), n(this, x, "f").willUpdate(), n(this, k, "f").willUpdate();
182
173
  }
183
- pop(i) {
184
- i.forEach((t) => {
185
- t.el.style[this.justify] = `${yt(t.el, this.justify)}px`;
186
- }), i.forEach((t) => {
187
- t.el.classList.add("section__exiting"), t.present = !1;
188
- });
174
+ update({ integer: t, fraction: e }) {
175
+ n(this, x, "f").update(t), n(this, k, "f").update(e);
189
176
  }
190
- addNewAndUpdateExisting(i, t = this.el) {
191
- const s = /* @__PURE__ */ new Map(), e = /* @__PURE__ */ new Map(), a = this.justify === "left", l = a ? "prepend" : "append";
192
- wt(i, (c) => {
193
- let d;
194
- this.children.has(c.key) ? (d = this.children.get(c.key), e.set(c, d), this.unpop(d), d.present = !0) : (d = this.addChar(c, { startDigitsAtZero: !0, animateIn: !0 }), s.set(c, d)), t[l](d.el);
195
- }, { reverse: a });
196
- const f = t.getBoundingClientRect();
197
- s.forEach((c) => {
198
- c.willUpdate(f);
199
- }), s.forEach((c, d) => {
200
- c.update(d.value);
201
- }), e.forEach((c, d) => {
202
- c.update(d.value);
177
+ didUpdate() {
178
+ const t = this.el.getBoundingClientRect();
179
+ n(this, x, "f").didUpdate(), n(this, k, "f").didUpdate();
180
+ const e = n(this, D, "f") - t.left, i = this.el.offsetWidth, s = n(this, A, "f") - i;
181
+ this.el.style.setProperty("--width", String(i)), this.el.animate({
182
+ [z]: [`${e}px`, "0px"],
183
+ [J]: [s, 0]
184
+ }, {
185
+ ...this.flow.transformTiming,
186
+ composite: "accumulate"
203
187
  });
204
188
  }
205
189
  }
206
- var $, M, A, N, B, L;
207
- class at extends dt {
208
- constructor(t, s, { className: e, ...a }) {
209
- let l;
210
- super(t, s, {
211
- ...a,
212
- className: `${e ?? ""} section--masked`
213
- }, (f) => [
214
- l = y("span", {
215
- className: "section__inner"
216
- }, f)
217
- ]);
218
- r(this, $);
219
- r(this, M);
220
- r(this, A);
221
- r(this, N);
222
- r(this, B);
223
- r(this, L);
224
- h(this, $, l);
190
+ T = /* @__PURE__ */ new WeakMap(), x = /* @__PURE__ */ new WeakMap(), k = /* @__PURE__ */ new WeakMap(), A = /* @__PURE__ */ new WeakMap(), D = /* @__PURE__ */ new WeakMap();
191
+ class lt {
192
+ constructor(t, e, { justify: i, className: s, ...o }, r) {
193
+ this.flow = t, this.children = /* @__PURE__ */ new Map(), this.onCharRemove = (f) => () => {
194
+ this.children.delete(f);
195
+ }, F.set(this, void 0), this.justify = i;
196
+ const l = e.map((f) => this.addChar(f).el);
197
+ this.el = g("span", {
198
+ ...o,
199
+ className: `section section--justify-${i} ${s ?? ""}`
200
+ }, r ? r(l) : l);
201
+ }
202
+ addChar(t, { startDigitsAtZero: e = !1, ...i } = {}) {
203
+ const s = t.type === "integer" || t.type === "fraction" ? new ct(this, t.type, e ? 0 : t.value, {
204
+ ...i,
205
+ onRemove: this.onCharRemove(t.key)
206
+ }) : new St(this, t.type, t.value, {
207
+ ...i,
208
+ onRemove: this.onCharRemove(t.key)
209
+ });
210
+ return this.children.set(t.key, s), s;
225
211
  }
226
- willUpdate(t) {
227
- const s = this.el.getBoundingClientRect();
228
- h(this, M, s.width), h(this, A, s[this.justify] - t[this.justify]);
229
- const e = o(this, $).getBoundingClientRect();
230
- this.children.forEach((a) => a.willUpdate(e));
212
+ unpop(t) {
213
+ t.el.classList.remove("section__exiting"), t.el.style[this.justify] = "";
231
214
  }
232
- update(t) {
233
- const s = /* @__PURE__ */ new Map();
234
- this.children.forEach((e, a) => {
235
- t.find((l) => l.key === a) || s.set(a, e), this.unpop(e);
236
- }), this.addNewAndUpdateExisting(t, o(this, $)), s.forEach((e) => {
237
- e instanceof pt && e.update(0);
238
- }), this.pop(s);
215
+ pop(t) {
216
+ t.forEach((e) => {
217
+ e.el.style[this.justify] = `${ft(e.el, this.justify)}px`;
218
+ }), t.forEach((e) => {
219
+ e.el.classList.add("section__exiting"), e.present = !1;
220
+ });
239
221
  }
240
- didUpdate(t) {
241
- var c, d, x, U;
242
- (c = o(this, N)) == null || c.cancel(), (d = o(this, L)) == null || d.cancel(), (x = o(this, B)) == null || x.cancel();
243
- const s = this.el.getBoundingClientRect(), e = s[this.justify] - t[this.justify], a = o(this, A) - e, l = Math.max(o(this, M), 0.01) / Math.max(s.width, 0.01), f = o(this, $).getBoundingClientRect();
244
- this.children.forEach((_) => _.didUpdate(f)), h(this, N, this.el.animate({
245
- transform: [`translateX(${a}px) scaleX(${l})`, "none"]
246
- }, this.flow.xTiming)), l !== 1 && (h(this, L, (U = o(this, $)) == null ? void 0 : U.animate({
247
- // 1/x isn't linear so we need to do sampling:
248
- transform: kt(1e3, (_) => `scaleX(${1 / ot(l, 1, _)})`)
249
- }, this.flow.xTiming)), h(this, B, this.el.animate(vt(1e3, (_) => ({
250
- "--_number-flow-scale-x": ot(l, 1, _)
251
- })), this.flow.xTiming)));
222
+ addNewAndUpdateExisting(t) {
223
+ const e = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Map(), s = this.justify === "left", o = s ? "prepend" : "append";
224
+ if (dt(t, (r) => {
225
+ let l;
226
+ this.children.has(r.key) ? (l = this.children.get(r.key), i.set(r, l), this.unpop(l), l.present = !0) : (l = this.addChar(r, { startDigitsAtZero: !0, animateIn: !0 }), e.set(r, l)), this.el[o](l.el);
227
+ }, { reverse: s }), this.flow.animated) {
228
+ const r = this.el.getBoundingClientRect();
229
+ e.forEach((l) => {
230
+ l.willUpdate(r);
231
+ });
232
+ }
233
+ e.forEach((r, l) => {
234
+ r.update(l.value);
235
+ }), i.forEach((r, l) => {
236
+ r.update(l.value);
237
+ });
252
238
  }
253
- }
254
- $ = new WeakMap(), M = new WeakMap(), A = new WeakMap(), N = new WeakMap(), B = new WeakMap(), L = new WeakMap();
255
- var H, P;
256
- class lt extends dt {
257
- constructor() {
258
- super(...arguments);
259
- r(this, H);
260
- r(this, P);
239
+ willUpdate() {
240
+ const t = this.el.getBoundingClientRect();
241
+ h(this, F, t[this.justify], "f"), this.children.forEach((e) => e.willUpdate(t));
261
242
  }
262
- willUpdate(t) {
263
- const s = this.el.getBoundingClientRect();
264
- h(this, H, s[this.justify] - t[this.justify]), this.children.forEach((e) => e.willUpdate(s));
243
+ didUpdate() {
244
+ const t = this.el.getBoundingClientRect();
245
+ this.children.forEach((s) => s.didUpdate(t));
246
+ const e = t[this.justify], i = n(this, F, "f") - e;
247
+ this.el.animate({
248
+ transform: [`translateX(${i}px)`, "none"]
249
+ }, {
250
+ ...this.flow.transformTiming,
251
+ composite: "accumulate"
252
+ });
265
253
  }
254
+ }
255
+ F = /* @__PURE__ */ new WeakMap();
256
+ class nt extends lt {
266
257
  update(t) {
267
- const s = /* @__PURE__ */ new Map();
268
- this.children.forEach((e, a) => {
269
- t.find((l) => l.key === a) || s.set(a, e);
270
- }), this.pop(s), this.addNewAndUpdateExisting(t);
258
+ const e = /* @__PURE__ */ new Map();
259
+ this.children.forEach((i, s) => {
260
+ t.find((o) => o.key === s) || e.set(s, i), this.unpop(i);
261
+ }), this.addNewAndUpdateExisting(t), e.forEach((i) => {
262
+ i instanceof ct && i.update(0);
263
+ }), this.pop(e);
271
264
  }
272
- didUpdate(t) {
273
- var a;
274
- (a = o(this, P)) == null || a.cancel();
275
- const s = this.el.getBoundingClientRect(), e = s[this.justify] - t[this.justify];
276
- this.children.forEach((l) => l.didUpdate(s)), h(this, P, this.el.animate({
277
- transform: [`translateX(${o(this, H) - e}px)`, "none"]
278
- }, this.flow.xTiming));
265
+ }
266
+ class at extends lt {
267
+ update(t) {
268
+ const e = /* @__PURE__ */ new Map();
269
+ this.children.forEach((i, s) => {
270
+ t.find((o) => o.key === s) || e.set(s, i);
271
+ }), this.pop(e), this.addNewAndUpdateExisting(t);
279
272
  }
280
273
  }
281
- H = new WeakMap(), P = new WeakMap();
282
- var j, W, R;
283
- class J {
284
- constructor(i, t, { onRemove: s, animateIn: e = !1 } = {}) {
285
- u(this, "flow");
286
- u(this, "el");
287
- r(this, j, !0);
288
- r(this, W);
289
- r(this, R);
290
- this.flow = i, this.el = t, e && this.el.animate({
291
- opacity: ["0", "1"]
292
- }, i.fadeTiming), h(this, W, s);
274
+ class q {
275
+ constructor(t, e, { onRemove: i, animateIn: s = !1 } = {}) {
276
+ this.flow = t, this.el = e, W.set(this, !0), O.set(this, void 0), M.set(this, () => {
277
+ var o;
278
+ this.el.remove(), (o = n(this, O, "f")) == null || o.call(this);
279
+ }), this.el.classList.add("animate-presence"), this.flow.animated && s && this.el.animate({
280
+ [X]: [-0.9999, 0]
281
+ }, {
282
+ ...this.flow.opacityTiming,
283
+ composite: "accumulate"
284
+ }), h(this, O, i, "f");
293
285
  }
294
286
  get present() {
295
- return o(this, j);
287
+ return n(this, W, "f");
296
288
  }
297
- set present(i) {
298
- var s;
299
- if (o(this, j) === i)
300
- return;
301
- const t = getComputedStyle(this.el).getPropertyValue("opacity");
302
- (s = o(this, R)) == null || s.cancel(), h(this, R, this.el.animate({
303
- opacity: [t, i ? "1" : "0"]
304
- }, this.flow.fadeTiming)), i || (o(this, R).onfinish = () => {
305
- var e;
306
- this.el.remove(), (e = o(this, W)) == null || e.call(this);
307
- }), h(this, j, i);
289
+ set present(t) {
290
+ if (n(this, W, "f") !== t) {
291
+ if (h(this, W, t, "f"), !this.flow.animated) {
292
+ t || n(this, M, "f").call(this);
293
+ return;
294
+ }
295
+ this.el.style.setProperty("--_number-flow-d-opacity", t ? "0" : "-.999"), this.el.animate({
296
+ [X]: t ? [-0.9999, 0] : [0.999, 0]
297
+ }, {
298
+ ...this.flow.opacityTiming,
299
+ composite: "accumulate"
300
+ }), t ? this.flow.removeEventListener("animationsfinish", n(this, M, "f")) : this.flow.addEventListener("animationsfinish", n(this, M, "f"), {
301
+ once: !0
302
+ });
303
+ }
308
304
  }
309
305
  }
310
- j = new WeakMap(), W = new WeakMap(), R = new WeakMap();
311
- class ft extends J {
312
- constructor(t, s, e, a) {
313
- super(t.flow, e, a);
314
- u(this, "section");
315
- u(this, "value");
316
- u(this, "el");
317
- this.section = t, this.value = s, this.el = e;
306
+ W = /* @__PURE__ */ new WeakMap(), O = /* @__PURE__ */ new WeakMap(), M = /* @__PURE__ */ new WeakMap();
307
+ class ht extends q {
308
+ constructor(t, e, i, s) {
309
+ super(t.flow, i, s), this.section = t, this.value = e, this.el = i;
318
310
  }
319
311
  }
320
- var S, X, z, D, O;
321
- class pt extends ft {
322
- constructor(t, s, e, a) {
323
- super(t, e, y("span", {
324
- className: "digit",
325
- // part: `digit ${type} ${value}`,
326
- textContent: e + ""
327
- }), a);
328
- r(this, S);
329
- // Relative to parent:
330
- r(this, X);
331
- r(this, z);
332
- r(this, D);
333
- r(this, O);
312
+ class ct extends ht {
313
+ constructor(t, e, i, s) {
314
+ const o = Array.from({ length: 10 }).map((l, f) => {
315
+ const E = g("span", { className: `digit__num${f === i ? " is-current" : ""}` }, [document.createTextNode(String(f))]);
316
+ return E.style.setProperty("--n", String(f)), E;
317
+ }), r = g("span", {
318
+ className: "digit"
319
+ }, o);
320
+ r.style.setProperty("--current", String(i)), super(t, i, r, s), U.set(this, void 0), u.set(this, void 0), B.set(this, void 0), Z.set(this, () => {
321
+ this.el.classList.remove("is-spinning");
322
+ }), h(this, U, o, "f");
323
+ }
324
+ get trend() {
325
+ const t = this.flow.getComputedTrend();
326
+ return t === p.NONE ? rt(this.value, n(this, u, "f")) : t;
334
327
  }
335
328
  willUpdate(t) {
336
- h(this, S, this.value);
337
- const s = this.el.getBoundingClientRect();
338
- h(this, X, s.y - t.y);
339
- const e = s[this.section.justify] - t[this.section.justify], a = s.width / 2;
340
- h(this, z, this.section.justify === "left" ? e + a : e - a);
329
+ const e = this.el.getBoundingClientRect();
330
+ h(this, u, this.value, "f");
331
+ const i = e[this.section.justify] - t[this.section.justify], s = e.width / 2;
332
+ h(this, B, this.section.justify === "left" ? i + s : i - s, "f");
341
333
  }
342
334
  update(t) {
343
- this.value = t, o(this, S) !== t && gt(this.el, [
344
- ...t === 0 ? [] : [
345
- y("span", { className: "digit__stack digit__lt" }, Array.from({ length: t }, (s, e) => y("span", { textContent: e + "" })))
346
- ],
347
- document.createTextNode(t + ""),
348
- ...t === 9 ? [] : [
349
- y("span", { className: "digit__stack digit__gt" }, Array.from({ length: 9 - t }, (s, e) => y("span", { textContent: t + e + 1 + "" })))
350
- ]
351
- ]);
335
+ var e, i;
336
+ (e = n(this, U, "f")[this.value]) == null || e.classList.remove("is-current"), this.el.style.setProperty("--current", String(t)), (i = n(this, U, "f")[t]) == null || i.classList.add("is-current"), this.value = t;
352
337
  }
353
338
  didUpdate(t) {
354
- var d, x;
355
- (d = o(this, D)) == null || d.cancel(), o(this, S) !== this.value && ((x = o(this, O)) == null || x.cancel());
356
- const s = this.el.getBoundingClientRect(), e = s[this.section.justify] - t[this.section.justify], a = s.width / 2, l = this.section.justify === "left" ? e + a : e - a, f = `translateX(${o(this, z) - l}px)`, c = `translateY(calc((100% + ${g}) * ${this.value - o(this, S)} + ${o(this, X)}px))`;
357
- h(this, D, this.el.animate({
358
- transform: [et ? f : `${f} ${c}`, "none"]
339
+ const e = this.el.getBoundingClientRect(), i = e[this.section.justify] - t[this.section.justify], s = e.width / 2, o = this.section.justify === "left" ? i + s : i - s;
340
+ if (this.el.animate({
341
+ transform: [`translateX(${n(this, B, "f") - o}px)`, "none"]
359
342
  }, {
360
- ...this.flow.xTiming,
343
+ ...this.flow.transformTiming,
361
344
  composite: "accumulate"
362
- // in case there's an in-flight y animation
363
- })), et && o(this, S) !== this.value && h(this, O, this.el.animate({
364
- transform: [c, "none"]
345
+ }), this.value === n(this, u, "f"))
346
+ return;
347
+ const r = this.trend;
348
+ let l = this.value - n(this, u, "f");
349
+ r === p.DOWN && this.value > n(this, u, "f") && (l = this.value - 10 - n(this, u, "f")), r === p.UP && this.value < n(this, u, "f") && (l = 10 - n(this, u, "f") + this.value), this.el.classList.add("is-spinning"), this.el.animate({
350
+ [Q]: [-l, 0]
365
351
  }, {
366
- ...this.flow.yTiming,
352
+ ...this.flow.spinTiming ?? this.flow.transformTiming,
367
353
  composite: "accumulate"
368
- }));
354
+ }), this.flow.addEventListener("animationsfinish", n(this, Z, "f"), { once: !0 });
369
355
  }
370
356
  }
371
- S = new WeakMap(), X = new WeakMap(), z = new WeakMap(), D = new WeakMap(), O = new WeakMap();
372
- var w, I, F, V;
373
- class jt extends ft {
374
- constructor(t, s, e, a) {
375
- const l = y("span", {
357
+ U = /* @__PURE__ */ new WeakMap(), u = /* @__PURE__ */ new WeakMap(), B = /* @__PURE__ */ new WeakMap(), Z = /* @__PURE__ */ new WeakMap();
358
+ class St extends ht {
359
+ constructor(t, e, i, s) {
360
+ const o = g("span", {
376
361
  className: "symbol__value",
377
- textContent: e
362
+ textContent: i
378
363
  });
379
- super(t, e, y("span", {
364
+ super(t, i, g("span", {
380
365
  className: "symbol"
381
- }, [l]), a);
382
- u(this, "type");
383
- r(this, w, /* @__PURE__ */ new Map());
384
- r(this, I);
385
- r(this, F, (t) => () => {
386
- o(this, w).delete(t);
387
- });
388
- r(this, V);
389
- this.type = s, o(this, w).set(e, new J(this.flow, l, {
390
- onRemove: o(this, F).call(this, e)
366
+ }, [o]), s), this.type = e, w.set(this, /* @__PURE__ */ new Map()), H.set(this, void 0), V.set(this, (r) => () => {
367
+ n(this, w, "f").delete(r);
368
+ }), n(this, w, "f").set(i, new q(this.flow, o, {
369
+ onRemove: n(this, V, "f").call(this, i)
391
370
  }));
392
371
  }
393
372
  willUpdate(t) {
394
373
  if (this.type === "decimal")
395
374
  return;
396
- const s = this.el.getBoundingClientRect();
397
- h(this, I, s[this.section.justify] - t[this.section.justify]);
375
+ const e = this.el.getBoundingClientRect();
376
+ h(this, H, e[this.section.justify] - t[this.section.justify], "f");
398
377
  }
399
378
  update(t) {
400
379
  if (this.value !== t) {
401
- const s = o(this, w).get(this.value);
402
- if (s.present = !1, s.el.classList.add("symbol__exiting"), o(this, w).has(t)) {
403
- const e = o(this, w).get(t);
404
- e.present = !0, e.el.classList.remove("symbol__exiting");
380
+ const e = n(this, w, "f").get(this.value);
381
+ if (e.present = !1, e.el.classList.add("symbol__exiting"), n(this, w, "f").has(t)) {
382
+ const i = n(this, w, "f").get(t);
383
+ i.present = !0, i.el.classList.remove("symbol__exiting");
405
384
  } else {
406
- const e = y("span", {
385
+ const i = g("span", {
407
386
  className: "symbol__value",
408
387
  textContent: t
409
388
  });
410
- this.el.appendChild(e), o(this, w).set(t, new J(this.flow, e, {
389
+ this.el.appendChild(i), n(this, w, "f").set(t, new q(this.flow, i, {
411
390
  animateIn: !0,
412
- onRemove: o(this, F).call(this, t)
391
+ onRemove: n(this, V, "f").call(this, t)
413
392
  }));
414
393
  }
415
394
  }
416
395
  this.value = t;
417
396
  }
418
397
  didUpdate(t) {
419
- var a;
420
398
  if (this.type === "decimal")
421
399
  return;
422
- (a = o(this, V)) == null || a.cancel();
423
- const e = this.el.getBoundingClientRect()[this.section.justify] - t[this.section.justify];
424
- h(this, V, this.el.animate({
425
- transform: [`translateX(${o(this, I) - e}px)`, "none"]
426
- }, this.flow.xTiming));
400
+ const i = this.el.getBoundingClientRect()[this.section.justify] - t[this.section.justify];
401
+ this.el.animate({
402
+ transform: [`translateX(${n(this, H, "f") - i}px)`, "none"]
403
+ }, { ...this.flow.transformTiming, composite: "accumulate" });
427
404
  }
428
405
  }
429
- w = new WeakMap(), I = new WeakMap(), F = new WeakMap(), V = new WeakMap();
406
+ w = /* @__PURE__ */ new WeakMap(), H = /* @__PURE__ */ new WeakMap(), V = /* @__PURE__ */ new WeakMap();
430
407
  export {
431
- Mt as NumberFlowLite,
432
- Ct as SlottedTag,
433
- $t as defaultFadeTiming,
434
- ht as defaultXTiming,
435
- St as defaultYTiming,
436
- Et as partitionParts,
437
- Tt as slottedStyles,
438
- et as supportsAnimationComposition,
439
- bt as supportsLinear
408
+ Et as NumberFlowLite,
409
+ wt as SlottedTag,
410
+ yt as canAnimate,
411
+ _t as defaultOpacityTiming,
412
+ vt as defaultTransformTiming,
413
+ kt as partitionParts,
414
+ K as prefersReducedMotion,
415
+ $t as slottedStyles
440
416
  };
package/dist/styles.d.ts CHANGED
@@ -1,14 +1,21 @@
1
- export declare const supportsLinear: boolean;
1
+ export declare const supportsMod: boolean;
2
+ export declare const prefersReducedMotion: MediaQueryList | null;
3
+ export declare const opacityDeltaVar = "--_number-flow-d-opacity";
4
+ export declare const widthDeltaVar = "--_number-flow-d-width";
5
+ export declare const dxVar = "--_number-flow-dx";
6
+ export declare const deltaVar = "--_number-flow-d";
2
7
  export declare const supportsAtProperty: boolean;
3
- export declare const supportsAnimationComposition: boolean;
4
8
  export declare const charHeight = "var(--number-flow-char-height, 1em)";
5
9
  export declare const maskHeight = "var(--number-flow-mask-height, 0.25em)";
6
10
  export declare const SlottedTag = "span";
7
- export declare const slottedStyles: {
11
+ export declare const slottedStyles: ({ willChange }: {
12
+ willChange?: boolean;
13
+ }) => {
8
14
  readonly fontKerning: "none";
9
15
  readonly display: "inline-block";
10
16
  readonly lineHeight: "var(--number-flow-char-height, 1em)";
11
17
  readonly padding: "var(--number-flow-mask-height, 0.25em) 0";
18
+ readonly willChange: "transform" | undefined;
12
19
  };
13
20
  declare const styles: string;
14
21
  export default styles;
@@ -5,7 +5,6 @@ export type HTMLProps<K extends keyof HTMLElementTagNameMap> = Partial<ExcludeRe
5
5
  part: string;
6
6
  }>;
7
7
  export declare const createElement: <K extends keyof HTMLElementTagNameMap>(tagName: K, optionsOrChildren?: HTMLProps<K> | Node[], _children?: Node[]) => HTMLElementTagNameMap[K];
8
- export declare const replaceChildren: (el: HTMLElement, children: Node[]) => void;
9
8
  export type Justify = 'left' | 'right';
10
9
  export declare const offset: (el: HTMLElement, justify: Justify) => number;
11
10
  export {};
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "0.2.2",
6
+ "version": "0.3.0",
7
7
  "author": {
8
8
  "name": "Maxwell Barvian",
9
9
  "email": "max@barvian.me",
@@ -44,18 +44,23 @@
44
44
  },
45
45
  "devDependencies": {
46
46
  "@rollup/plugin-typescript": "^12.1.0",
47
+ "@testing-library/dom": "^10.4.0",
48
+ "@vitest/browser": "^2.1.2",
47
49
  "babel-plugin-styled-components": "^2.1.4",
48
50
  "magic-string": "^0.30.11",
49
51
  "parse-literals": "^1.2.1",
50
- "vite": "^5.4.3",
52
+ "playwright": "^1.48.0",
53
+ "tslib": "^2.7.0",
51
54
  "typescript": "^5.6.2",
52
- "tslib": "^2.7.0"
55
+ "vite": "^5.4.3",
56
+ "vitest": "^2.1.2"
53
57
  },
54
58
  "dependencies": {
55
59
  "esm-env": "^1.0.0"
56
60
  },
57
61
  "scripts": {
58
62
  "build": "vite build --mode production",
59
- "dev": "vite build --mode development --watch"
63
+ "dev": "vite build --mode development --watch",
64
+ "test:unit": "vitest"
60
65
  }
61
66
  }
@@ -1,6 +0,0 @@
1
- export declare function frames<F extends string | (number | null)>(durationMs: number, frame: (t: number) => F, fps?: number): F[];
2
- export type CustomPropertyKeyframes = {
3
- [property: `--${string}`]: string | number | null | undefined;
4
- };
5
- export declare function customPropertyFrames(durationMs: number, frame: (t: number) => CustomPropertyKeyframes, fps?: number): CustomPropertyKeyframes[];
6
- export declare const lerp: (min: number, max: number, weight: number) => number;