number-flow 0.2.3 → 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.
- package/dist/formatter.d.ts +2 -1
- package/dist/index.d.ts +19 -8
- package/dist/index.js +1 -1
- package/dist/index.mjs +316 -335
- package/dist/styles.d.ts +10 -3
- package/dist/util/dom.d.ts +0 -1
- package/package.json +9 -4
- package/dist/util/animate.d.ts +0 -6
package/dist/formatter.d.ts
CHANGED
|
@@ -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,
|
|
3
|
+
export { SlottedTag, slottedStyles, prefersReducedMotion } from './styles';
|
|
4
4
|
export * from './formatter';
|
|
5
|
-
export declare const
|
|
6
|
-
|
|
7
|
-
export
|
|
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
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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"},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,435 +1,416 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
throw TypeError(
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
return
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
|
19
|
-
const
|
|
20
|
-
for (let
|
|
21
|
-
|
|
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
|
|
24
|
-
const
|
|
25
|
-
let
|
|
26
|
-
for (const
|
|
27
|
-
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
type:
|
|
31
|
-
value:
|
|
32
|
-
key:
|
|
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
|
|
37
|
-
|
|
38
|
-
return {
|
|
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
|
|
41
|
-
},
|
|
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:
|
|
52
|
+
return CSS.registerProperty({
|
|
53
|
+
name: X,
|
|
46
54
|
syntax: "<number>",
|
|
47
55
|
inherits: !1,
|
|
48
|
-
initialValue: "
|
|
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
|
-
|
|
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:
|
|
56
|
-
padding: `${
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
function
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
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 = { duration: 500, easing: "ease-out" }, 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 = {
|
|
75
93
|
duration: 900,
|
|
94
|
+
// Make sure to keep this minified:
|
|
76
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)"
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
easing: "cubic-bezier(.32,.72,0,1)"
|
|
81
|
-
}, St = ht;
|
|
82
|
-
let G;
|
|
83
|
-
var T, b, C, k, v;
|
|
84
|
-
class Mt extends xt {
|
|
96
|
+
};
|
|
97
|
+
let j;
|
|
98
|
+
class Et extends pt {
|
|
85
99
|
constructor() {
|
|
86
|
-
super(...arguments);
|
|
87
|
-
u(this, "xTiming", ht);
|
|
88
|
-
u(this, "yTiming", St);
|
|
89
|
-
u(this, "fadeTiming", $t);
|
|
90
|
-
u(this, "root", !1);
|
|
91
|
-
u(this, "manual", !1);
|
|
92
|
-
r(this, T, !1);
|
|
93
|
-
r(this, b);
|
|
94
|
-
r(this, C);
|
|
95
|
-
r(this, k);
|
|
96
|
-
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);
|
|
97
101
|
}
|
|
98
102
|
static define() {
|
|
99
|
-
|
|
103
|
+
I && customElements.define("number-flow", this);
|
|
104
|
+
}
|
|
105
|
+
getComputedTrend() {
|
|
106
|
+
return n(this, S, "f");
|
|
100
107
|
}
|
|
101
108
|
set parts(t) {
|
|
102
109
|
if (t == null)
|
|
103
110
|
return;
|
|
104
|
-
const { pre:
|
|
105
|
-
if (
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
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];
|
|
110
118
|
else {
|
|
111
|
-
const
|
|
112
|
-
|
|
119
|
+
const l = document.createElement("style");
|
|
120
|
+
l.textContent = st, this.shadowRoot.appendChild(l);
|
|
113
121
|
}
|
|
114
|
-
this.shadowRoot.appendChild(
|
|
115
|
-
// part: 'pre',
|
|
122
|
+
this.shadowRoot.appendChild(g("slot")), h(this, _, new at(this, e, {
|
|
116
123
|
inert: !0,
|
|
117
124
|
ariaHidden: "true",
|
|
118
125
|
justify: "right"
|
|
119
|
-
})), this.shadowRoot.appendChild(
|
|
120
|
-
// part: 'integer',
|
|
126
|
+
}), "f"), this.shadowRoot.appendChild(n(this, _, "f").el), h(this, v, new bt(this, i, s, {
|
|
121
127
|
inert: !0,
|
|
122
|
-
ariaHidden: "true"
|
|
123
|
-
|
|
124
|
-
})), this.shadowRoot.appendChild(o(this, C).el), h(this, k, new at(this, a, {
|
|
125
|
-
// part: 'fraction',
|
|
128
|
+
ariaHidden: "true"
|
|
129
|
+
}), "f"), this.shadowRoot.appendChild(n(this, v, "f").el), h(this, b, new at(this, o, {
|
|
126
130
|
inert: !0,
|
|
127
131
|
ariaHidden: "true",
|
|
128
132
|
justify: "left"
|
|
129
|
-
})), this.shadowRoot.appendChild(
|
|
130
|
-
// part: 'post',
|
|
131
|
-
inert: !0,
|
|
132
|
-
ariaHidden: "true",
|
|
133
|
-
justify: "left"
|
|
134
|
-
})), this.shadowRoot.appendChild(o(this, v).el);
|
|
133
|
+
}), "f"), this.shadowRoot.appendChild(n(this, b, "f").el);
|
|
135
134
|
}
|
|
136
|
-
h(this,
|
|
135
|
+
h(this, L, !0, "f");
|
|
137
136
|
}
|
|
138
137
|
willUpdate() {
|
|
139
|
-
|
|
140
|
-
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());
|
|
141
139
|
}
|
|
142
140
|
didUpdate() {
|
|
143
|
-
|
|
144
|
-
|
|
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()));
|
|
145
155
|
}
|
|
146
156
|
}
|
|
147
|
-
|
|
148
|
-
class
|
|
149
|
-
constructor(
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
f.push(document.createTextNode("")), this.el = y("span", {
|
|
161
|
-
...a,
|
|
162
|
-
className: `section section--justify-${s} ${e ?? ""}`
|
|
163
|
-
}, l ? l(f) : f);
|
|
164
|
-
}
|
|
165
|
-
addChar(i, { startDigitsAtZero: t = !1, ...s } = {}) {
|
|
166
|
-
const e = i.type === "integer" || i.type === "fraction" ? new pt(this, i.type, t ? 0 : i.value, {
|
|
167
|
-
...s,
|
|
168
|
-
onRemove: this.onCharRemove(i.key)
|
|
169
|
-
}) : new jt(this, i.type, i.value, {
|
|
170
|
-
...s,
|
|
171
|
-
onRemove: this.onCharRemove(i.key)
|
|
172
|
-
});
|
|
173
|
-
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")]);
|
|
174
170
|
}
|
|
175
|
-
|
|
176
|
-
|
|
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();
|
|
177
173
|
}
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
t.el.style[this.justify] = `${yt(t.el, this.justify)}px`;
|
|
181
|
-
}), i.forEach((t) => {
|
|
182
|
-
t.el.classList.add("section__exiting"), t.present = !1;
|
|
183
|
-
});
|
|
174
|
+
update({ integer: t, fraction: e }) {
|
|
175
|
+
n(this, x, "f").update(t), n(this, k, "f").update(e);
|
|
184
176
|
}
|
|
185
|
-
|
|
186
|
-
const
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
c.update(d.value);
|
|
196
|
-
}), e.forEach((c, d) => {
|
|
197
|
-
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"
|
|
198
187
|
});
|
|
199
188
|
}
|
|
200
189
|
}
|
|
201
|
-
|
|
202
|
-
class
|
|
203
|
-
constructor(t,
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
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;
|
|
220
211
|
}
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
h(this, M, s.width), h(this, A, s[this.justify] - t[this.justify]);
|
|
224
|
-
const e = o(this, $).getBoundingClientRect();
|
|
225
|
-
this.children.forEach((a) => a.willUpdate(e));
|
|
212
|
+
unpop(t) {
|
|
213
|
+
t.el.classList.remove("section__exiting"), t.el.style[this.justify] = "";
|
|
226
214
|
}
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
}), 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
|
+
});
|
|
234
221
|
}
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
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
|
+
});
|
|
247
238
|
}
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
class lt extends dt {
|
|
252
|
-
constructor() {
|
|
253
|
-
super(...arguments);
|
|
254
|
-
r(this, H);
|
|
255
|
-
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));
|
|
256
242
|
}
|
|
257
|
-
|
|
258
|
-
const
|
|
259
|
-
|
|
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
|
+
});
|
|
260
253
|
}
|
|
254
|
+
}
|
|
255
|
+
F = /* @__PURE__ */ new WeakMap();
|
|
256
|
+
class nt extends lt {
|
|
261
257
|
update(t) {
|
|
262
|
-
const
|
|
263
|
-
this.children.forEach((
|
|
264
|
-
t.find((
|
|
265
|
-
}), this.
|
|
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);
|
|
266
264
|
}
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
const
|
|
271
|
-
this.children.forEach((
|
|
272
|
-
|
|
273
|
-
}, this.
|
|
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);
|
|
274
272
|
}
|
|
275
273
|
}
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
}, 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");
|
|
288
285
|
}
|
|
289
286
|
get present() {
|
|
290
|
-
return
|
|
287
|
+
return n(this, W, "f");
|
|
291
288
|
}
|
|
292
|
-
set present(
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
opacity
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
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
|
+
}
|
|
303
304
|
}
|
|
304
305
|
}
|
|
305
|
-
|
|
306
|
-
class
|
|
307
|
-
constructor(t,
|
|
308
|
-
super(t.flow, e,
|
|
309
|
-
u(this, "section");
|
|
310
|
-
u(this, "value");
|
|
311
|
-
u(this, "el");
|
|
312
|
-
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;
|
|
313
310
|
}
|
|
314
311
|
}
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
}
|
|
323
|
-
r(this,
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
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;
|
|
329
327
|
}
|
|
330
328
|
willUpdate(t) {
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
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");
|
|
336
333
|
}
|
|
337
334
|
update(t) {
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
y("span", { className: "digit__stack digit__lt" }, Array.from({ length: t }, (s, e) => y("span", { textContent: e + "" })))
|
|
341
|
-
],
|
|
342
|
-
document.createTextNode(t + ""),
|
|
343
|
-
...t === 9 ? [] : [
|
|
344
|
-
y("span", { className: "digit__stack digit__gt" }, Array.from({ length: 9 - t }, (s, e) => y("span", { textContent: t + e + 1 + "" })))
|
|
345
|
-
]
|
|
346
|
-
]);
|
|
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;
|
|
347
337
|
}
|
|
348
338
|
didUpdate(t) {
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
h(this, O, this.el.animate({
|
|
353
|
-
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"]
|
|
354
342
|
}, {
|
|
355
|
-
...this.flow.
|
|
343
|
+
...this.flow.transformTiming,
|
|
356
344
|
composite: "accumulate"
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
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]
|
|
360
351
|
}, {
|
|
361
|
-
...this.flow.
|
|
352
|
+
...this.flow.spinTiming ?? this.flow.transformTiming,
|
|
362
353
|
composite: "accumulate"
|
|
363
|
-
}));
|
|
354
|
+
}), this.flow.addEventListener("animationsfinish", n(this, Z, "f"), { once: !0 });
|
|
364
355
|
}
|
|
365
356
|
}
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
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", {
|
|
371
361
|
className: "symbol__value",
|
|
372
|
-
textContent:
|
|
362
|
+
textContent: i
|
|
373
363
|
});
|
|
374
|
-
super(t,
|
|
364
|
+
super(t, i, g("span", {
|
|
375
365
|
className: "symbol"
|
|
376
|
-
}, [
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
r(this, F, (t) => () => {
|
|
381
|
-
o(this, w).delete(t);
|
|
382
|
-
});
|
|
383
|
-
r(this, V);
|
|
384
|
-
this.type = s, o(this, w).set(e, new J(this.flow, l, {
|
|
385
|
-
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)
|
|
386
370
|
}));
|
|
387
371
|
}
|
|
388
372
|
willUpdate(t) {
|
|
389
373
|
if (this.type === "decimal")
|
|
390
374
|
return;
|
|
391
|
-
const
|
|
392
|
-
h(this,
|
|
375
|
+
const e = this.el.getBoundingClientRect();
|
|
376
|
+
h(this, H, e[this.section.justify] - t[this.section.justify], "f");
|
|
393
377
|
}
|
|
394
378
|
update(t) {
|
|
395
379
|
if (this.value !== t) {
|
|
396
|
-
const
|
|
397
|
-
if (
|
|
398
|
-
const
|
|
399
|
-
|
|
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");
|
|
400
384
|
} else {
|
|
401
|
-
const
|
|
385
|
+
const i = g("span", {
|
|
402
386
|
className: "symbol__value",
|
|
403
387
|
textContent: t
|
|
404
388
|
});
|
|
405
|
-
this.el.appendChild(
|
|
389
|
+
this.el.appendChild(i), n(this, w, "f").set(t, new q(this.flow, i, {
|
|
406
390
|
animateIn: !0,
|
|
407
|
-
onRemove:
|
|
391
|
+
onRemove: n(this, V, "f").call(this, t)
|
|
408
392
|
}));
|
|
409
393
|
}
|
|
410
394
|
}
|
|
411
395
|
this.value = t;
|
|
412
396
|
}
|
|
413
397
|
didUpdate(t) {
|
|
414
|
-
var a;
|
|
415
398
|
if (this.type === "decimal")
|
|
416
399
|
return;
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
}, 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" });
|
|
422
404
|
}
|
|
423
405
|
}
|
|
424
|
-
w = new WeakMap(),
|
|
406
|
+
w = /* @__PURE__ */ new WeakMap(), H = /* @__PURE__ */ new WeakMap(), V = /* @__PURE__ */ new WeakMap();
|
|
425
407
|
export {
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
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
|
|
435
416
|
};
|
package/dist/styles.d.ts
CHANGED
|
@@ -1,14 +1,21 @@
|
|
|
1
|
-
export declare const
|
|
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;
|
package/dist/util/dom.d.ts
CHANGED
|
@@ -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.
|
|
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
|
-
"
|
|
52
|
+
"playwright": "^1.48.0",
|
|
53
|
+
"tslib": "^2.7.0",
|
|
51
54
|
"typescript": "^5.6.2",
|
|
52
|
-
"
|
|
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
|
}
|
package/dist/util/animate.d.ts
DELETED
|
@@ -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;
|