number-flow 0.2.3 → 0.3.1
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/LICENSE.md +21 -0
- package/dist/formatter.d.ts +5 -3
- package/dist/index.d.ts +22 -9
- package/dist/index.js +1 -1
- package/dist/index.mjs +342 -334
- package/dist/styles.d.ts +10 -3
- package/dist/util/dom.d.ts +0 -1
- package/dist/util/math.d.ts +1 -0
- package/package.json +9 -4
- package/dist/util/animate.d.ts +0 -6
package/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Maxwell Barvian
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/formatter.d.ts
CHANGED
|
@@ -12,24 +12,26 @@ type SymbolPart = {
|
|
|
12
12
|
type: Exclude<NumberPartType, 'integer' | 'fraction'>;
|
|
13
13
|
value: string;
|
|
14
14
|
};
|
|
15
|
-
export type NumberPart = DigitPart | SymbolPart;
|
|
16
15
|
export type NumberPartKey = string;
|
|
17
16
|
type KeyedPart = {
|
|
18
17
|
key: NumberPartKey;
|
|
19
18
|
};
|
|
20
|
-
export type KeyedDigitPart = DigitPart & KeyedPart
|
|
19
|
+
export type KeyedDigitPart = DigitPart & KeyedPart & {
|
|
20
|
+
place: number;
|
|
21
|
+
};
|
|
21
22
|
export type KeyedSymbolPart = SymbolPart & KeyedPart;
|
|
22
23
|
export type KeyedNumberPart = KeyedDigitPart | KeyedSymbolPart;
|
|
23
24
|
export type Format = Omit<Intl.NumberFormatOptions, 'notation'> & {
|
|
24
25
|
notation?: Exclude<Intl.NumberFormatOptions['notation'], 'scientific' | 'engineering'>;
|
|
25
26
|
};
|
|
26
|
-
export type Value = Parameters<typeof Intl.NumberFormat.prototype.formatToParts>[0]
|
|
27
|
+
export type Value = Exclude<Parameters<typeof Intl.NumberFormat.prototype.formatToParts>[0], bigint>;
|
|
27
28
|
export declare function partitionParts(value: Value, formatter: Intl.NumberFormat): {
|
|
28
29
|
pre: KeyedNumberPart[];
|
|
29
30
|
integer: KeyedNumberPart[];
|
|
30
31
|
fraction: KeyedNumberPart[];
|
|
31
32
|
post: KeyedNumberPart[];
|
|
32
33
|
formatted: string;
|
|
34
|
+
value: number;
|
|
33
35
|
};
|
|
34
36
|
export type PartitionedParts = ReturnType<typeof partitionParts>;
|
|
35
37
|
export {};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,19 +1,32 @@
|
|
|
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;
|
|
16
|
-
|
|
22
|
+
respectMotionPreference: boolean;
|
|
23
|
+
trend: RawTrend;
|
|
24
|
+
continuous: boolean;
|
|
25
|
+
get startingPlace(): number | undefined;
|
|
26
|
+
get computedTrend(): Trend | undefined;
|
|
27
|
+
set parts(parts: PartitionedParts | undefined);
|
|
17
28
|
willUpdate(): void;
|
|
18
29
|
didUpdate(): void;
|
|
30
|
+
get animated(): boolean;
|
|
31
|
+
set animated(val: boolean);
|
|
19
32
|
}
|
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 Z=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 w=(a,t,e)=>{const i=document.createElement(a),[s,r]=Array.isArray(t)?[void 0,t]:[t,e];return s&&Object.assign(i,s),r==null||r.forEach(l=>i.appendChild(l)),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=[],r=[],l=[],o={},p=c=>{const f=o[c]==null?o[c]=0:++o[c];return`${c}:${f}`};let u="",m=!1,N=!1;for(const c of e){u+=c.value;const f=c.type==="minusSign"||c.type==="plusSign"?"sign":c.type;f==="integer"?(m=!0,s.push(...c.value.split("").map(J=>({type:f,value:parseInt(J)})))):f==="group"?s.push({type:f,value:c.value}):f==="decimal"?(N=!0,r.push({type:f,value:c.value,key:p(f)})):f==="fraction"?r.push(...c.value.split("").map(J=>({type:f,value:parseInt(J),key:p(f),place:-1-o[f]}))):(m||N?l:i).push({type:f,value:c.value,key:p(f)})}const d=[];for(let c=s.length-1;c>=0;c--){const f=s[c];d.unshift(f.type==="integer"?{...f,key:p(f.type),place:o[f.type]}:{...f,key:p(f.type)})}return{pre:i,integer:d,fraction:r,post:l,formatted:u,value:typeof a=="string"?parseFloat(a):a}}const yt=Z.BROWSER?HTMLElement:class{},vt=String.raw,_t=Z.BROWSER&&typeof CSS<"u"&&CSS.supports("line-height","mod(1,1)"),O=Z.BROWSER?matchMedia("(prefers-reduced-motion: reduce)"):null,Y="--_number-flow-d-opacity",it="--_number-flow-d-width",q="--_number-flow-dx",st="--_number-flow-d",bt=(()=>{try{return CSS.registerProperty({name:Y,syntax:"<number>",inherits:!1,initialValue:"0"}),CSS.registerProperty({name:q,syntax:"<length>",inherits:!0,initialValue:"0px"}),CSS.registerProperty({name:it,syntax:"<number>",inherits:!1,initialValue:"0"}),CSS.registerProperty({name:st,syntax:"<number>",inherits:!0,initialValue:"0"}),!0}catch{return!1}})(),rt="var(--number-flow-char-height, 1em)",g="var(--number-flow-mask-height, 0.25em)",C=`calc(${g} / 2)`,Q="var(--number-flow-mask-width, 0.5em)",S=`calc(${Q} / var(--scale-x))`,T="#000 0, transparent 71%",lt="span",St=({willChange:a})=>({fontKerning:"none",display:"inline-block",lineHeight:rt,padding:`${g} 0`,willChange:a?"transform":void 0}),nt=vt`:host{display:inline-flex;align-items:baseline;direction:ltr;white-space:nowrap;position:relative;line-height:${rt} !important;isolation:isolate;}::slotted(${lt}){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(${it}) / var(--width));transform:translateX(var(${q})) scaleX(var(--scale-x));margin:0 calc(-1 * ${Q});position:relative;z-index:-1;overflow:clip;-webkit-mask-image:linear-gradient( to right,transparent 0,#000 ${S},#000 calc(100% - ${S}),transparent ),linear-gradient( to bottom,transparent 0,#000 ${g},#000 calc(100% - ${g}),transparent 100% ),radial-gradient(at bottom right,${T}),radial-gradient(at bottom left,${T}),radial-gradient(at top left,${T}),radial-gradient(at top right,${T});-webkit-mask-size:100% calc(100% - ${g} * 2),calc(100% - ${S} * 2) 100%,${S} ${g},${S} ${g},${S} ${g},${S} ${g};-webkit-mask-position:center,center,top left,top right,bottom right,bottom left;-webkit-mask-repeat:no-repeat;}.number__inner{padding:0 ${Q};transform:scaleX(calc(1 / var(--scale-x))) translateX(calc(-1 * var(${q})));}.section{display:inline-flex;align-items:baseline;padding-bottom:${C};padding-top:${C};position:relative;isolation:isolate;}.section::after{content:'\200b';display:block;padding:${C} 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(${st});}:host([data-will-change]) .digit,:host([data-will-change]) .digit__num{will-change:transform;}.digit__num{display:block;padding:${C} 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:${C} 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(${Y}));}`,kt=(a,t)=>{if(a!=null&&t==null)return a;if(a==null&&t!=null)return t;if(a!=null&&t!=null)return Math.max(a,t)};var F,B,k,x,E,y,P,R,W,D,$,M,H,V,X,U,z,j,L,v,I,tt,_,G,K;const ht=_t&&bt;var b;(function(a){a[a.UP=1]="UP",a[a.DOWN=-1]="DOWN",a[a.NONE=0]="NONE"})(b||(b={}));const 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 A;class xt extends yt{constructor(){super(...arguments),this.transformTiming=ft,this.opacityTiming=ct,F.set(this,!0),this.manual=!1,this.respectMotionPreference=!0,B.set(this,!1),k.set(this,void 0),x.set(this,void 0),E.set(this,void 0),this.trend=!0,y.set(this,void 0),this.continuous=!1,P.set(this,void 0),R.set(this,void 0),W.set(this,void 0)}static define(){Z.BROWSER&&customElements.define("number-flow",this)}get startingPlace(){return n(this,P,"f")}get computedTrend(){return n(this,y,"f")}set parts(t){if(t==null)return;const{pre:e,integer:i,fraction:s,post:r,value:l}=t;if(n(this,B,"f")){const o=n(this,R,"f");if(h(this,R,t,"f"),this.trend===!0?h(this,y,Math.sign(l-o.value),"f"):this.trend==="increasing"?h(this,y,b.UP,"f"):this.trend==="decreasing"?h(this,y,b.DOWN,"f"):h(this,y,b.NONE,"f"),h(this,P,void 0,"f"),n(this,y,"f")!==b.NONE&&this.continuous){const p=o.integer.concat(o.fraction).filter(d=>d.type==="integer"||d.type==="fraction"),u=t.integer.concat(t.fraction).filter(d=>d.type==="integer"||d.type==="fraction"),m=p.find(d=>!u.find(c=>c.place===d.place&&c.value===d.value)),N=u.find(d=>!p.find(c=>d.place===c.place&&d.value===c.value));h(this,P,kt(m==null?void 0:m.place,N==null?void 0:N.place),"f")}this.manual||this.willUpdate(),n(this,k,"f").update(e),n(this,x,"f").update({integer:i,fraction:s}),n(this,E,"f").update(r),this.manual||this.didUpdate()}else{if(h(this,R,t,"f"),this.attachShadow({mode:"open"}),typeof CSSStyleSheet<"u"&&this.shadowRoot.adoptedStyleSheets)A||(A=new CSSStyleSheet,A.replaceSync(nt)),this.shadowRoot.adoptedStyleSheets=[A];else{const o=document.createElement("style");o.textContent=nt,this.shadowRoot.appendChild(o)}this.shadowRoot.appendChild(w("slot")),h(this,k,new ot(this,e,{inert:!0,ariaHidden:"true",justify:"right"}),"f"),this.shadowRoot.appendChild(n(this,k,"f").el),h(this,x,new Et(this,i,s,{inert:!0,ariaHidden:"true"}),"f"),this.shadowRoot.appendChild(n(this,x,"f").el),h(this,E,new ot(this,r,{inert:!0,ariaHidden:"true",justify:"left"}),"f"),this.shadowRoot.appendChild(n(this,E,"f").el)}h(this,B,!0,"f")}willUpdate(){this.animated&&(n(this,k,"f").willUpdate(),n(this,x,"f").willUpdate(),n(this,E,"f").willUpdate())}didUpdate(){if(!this.animated)return;n(this,W,"f")?n(this,W,"f").abort():this.dispatchEvent(new Event("animationsstart")),n(this,k,"f").didUpdate(),n(this,x,"f").didUpdate(),n(this,E,"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,W,void 0,"f"))}),h(this,W,t,"f")}get animated(){return ht&&n(this,F,"f")&&(!this.respectMotionPreference||!(O!=null&&O.matches))}set animated(t){var e;this.animated!==t&&(h(this,F,t,"f"),(e=this.shadowRoot)==null||e.getAnimations().forEach(i=>i.finish()))}}F=new WeakMap,B=new WeakMap,k=new WeakMap,x=new WeakMap,E=new WeakMap,y=new WeakMap,P=new WeakMap,R=new WeakMap,W=new WeakMap;class Et{constructor(t,e,i,{className:s,...r}={}){this.flow=t,D.set(this,void 0),$.set(this,void 0),M.set(this,void 0),H.set(this,void 0),V.set(this,void 0),h(this,$,new at(t,e,{justify:"right"}),"f"),h(this,M,new at(t,i,{justify:"left"}),"f"),h(this,D,w("span",{className:"number__inner"},[n(this,$,"f").el,n(this,M,"f").el]),"f"),this.el=w("span",{...r,className:`number ${s??""}`},[n(this,D,"f")])}willUpdate(){h(this,H,this.el.offsetWidth,"f"),h(this,V,this.el.getBoundingClientRect().left,"f"),n(this,$,"f").willUpdate(),n(this,M,"f").willUpdate()}update({integer:t,fraction:e}){n(this,$,"f").update(t),n(this,M,"f").update(e)}didUpdate(){const t=this.el.getBoundingClientRect();n(this,$,"f").didUpdate(),n(this,M,"f").didUpdate();const e=n(this,V,"f")-t.left,i=this.el.offsetWidth,s=n(this,H,"f")-i;this.el.style.setProperty("--width",String(i)),this.el.animate({[q]:[`${e}px`,"0px"],[it]:[s,0]},{...this.flow.transformTiming,composite:"accumulate"})}}D=new WeakMap,$=new WeakMap,M=new WeakMap,H=new WeakMap,V=new WeakMap;class dt{constructor(t,e,{justify:i,className:s,...r},l){this.flow=t,this.children=new Map,this.onCharRemove=p=>()=>{this.children.delete(p)},X.set(this,void 0),this.justify=i;const o=e.map(p=>this.addChar(p).el);this.el=w("span",{...r,className:`section section--justify-${i} ${s??""}`},l?l(o):o)}addChar(t,{startDigitsAtZero:e=!1,...i}={}){const s=t.type==="integer"||t.type==="fraction"?new ut(this,t.type,e?0:t.value,t.place,{...i,onRemove:this.onCharRemove(t.key)}):new $t(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",r=s?"prepend":"append";if(gt(t,l=>{let o;this.children.has(l.key)?(o=this.children.get(l.key),i.set(l,o),this.unpop(o),o.present=!0):(o=this.addChar(l,{startDigitsAtZero:!0,animateIn:!0}),e.set(l,o)),this.el[r](o.el)},{reverse:s}),this.flow.animated){const l=this.el.getBoundingClientRect();e.forEach(o=>{o.willUpdate(l)})}e.forEach((l,o)=>{l.update(o.value)}),i.forEach((l,o)=>{l.update(o.value)})}willUpdate(){const t=this.el.getBoundingClientRect();h(this,X,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,X,"f")-e;this.el.animate({transform:[`translateX(${i}px)`,"none"]},{...this.flow.transformTiming,composite:"accumulate"})}}X=new WeakMap;class at extends dt{update(t){const e=new Map;this.children.forEach((i,s)=>{t.find(r=>r.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 ot extends dt{update(t){const e=new Map;this.children.forEach((i,s)=>{t.find(r=>r.key===s)||e.set(s,i)}),this.pop(e),this.addNewAndUpdateExisting(t)}}class et{constructor(t,e,{onRemove:i,animateIn:s=!1}={}){this.flow=t,this.el=e,U.set(this,!0),z.set(this,void 0),j.set(this,()=>{var r;this.el.remove(),(r=n(this,z,"f"))==null||r.call(this)}),this.el.classList.add("animate-presence"),this.flow.animated&&s&&this.el.animate({[Y]:[-.9999,0]},{...this.flow.opacityTiming,composite:"accumulate"}),h(this,z,i,"f")}get present(){return n(this,U,"f")}set present(t){if(n(this,U,"f")!==t){if(h(this,U,t,"f"),!this.flow.animated){t||n(this,j,"f").call(this);return}this.el.style.setProperty("--_number-flow-d-opacity",t?"0":"-.999"),this.el.animate({[Y]:t?[-.9999,0]:[.999,0]},{...this.flow.opacityTiming,composite:"accumulate"}),t?this.flow.removeEventListener("animationsfinish",n(this,j,"f")):this.flow.addEventListener("animationsfinish",n(this,j,"f"),{once:!0})}}}U=new WeakMap,z=new WeakMap,j=new WeakMap;class pt extends et{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,r){const l=Array.from({length:10}).map((p,u)=>{const m=w("span",{className:`digit__num${u===i?" is-current":""}`},[document.createTextNode(String(u))]);return m.style.setProperty("--n",String(u)),m}),o=w("span",{className:"digit"},l);o.style.setProperty("--current",String(i)),super(t,i,o,r),this.place=s,L.set(this,void 0),v.set(this,void 0),I.set(this,void 0),tt.set(this,()=>{this.el.classList.remove("is-spinning")}),h(this,L,l,"f")}willUpdate(t){const e=this.el.getBoundingClientRect();h(this,v,this.value,"f");const i=e[this.section.justify]-t[this.section.justify],s=e.width/2;h(this,I,this.section.justify==="left"?i+s:i-s,"f")}update(t){var e,i;(e=n(this,L,"f")[this.value])==null||e.classList.remove("is-current"),this.el.style.setProperty("--current",String(t)),(i=n(this,L,"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,r=this.section.justify==="left"?i+s:i-s;this.el.animate({transform:[`translateX(${n(this,I,"f")-r}px)`,"none"]},{...this.flow.transformTiming,composite:"accumulate"});const l=this.diff;l&&(this.el.classList.add("is-spinning"),this.el.animate({[st]:[-l,0]},{...this.flow.spinTiming??this.flow.transformTiming,composite:"accumulate"}),this.flow.addEventListener("animationsfinish",n(this,tt,"f"),{once:!0}))}get diff(){let t=this.flow.computedTrend;const e=this.value-n(this,v,"f");return!e&&this.flow.startingPlace!=null&&this.flow.startingPlace>=this.place?10*t:(t||(t=Math.sign(e)),t===b.DOWN&&this.value>n(this,v,"f")?this.value-10-n(this,v,"f"):t===b.UP&&this.value<n(this,v,"f")?10-n(this,v,"f")+this.value:e)}}L=new WeakMap,v=new WeakMap,I=new WeakMap,tt=new WeakMap;class $t extends pt{constructor(t,e,i,s){const r=w("span",{className:"symbol__value",textContent:i});super(t,i,w("span",{className:"symbol"},[r]),s),this.type=e,_.set(this,new Map),G.set(this,void 0),K.set(this,l=>()=>{n(this,_,"f").delete(l)}),n(this,_,"f").set(i,new et(this.flow,r,{onRemove:n(this,K,"f").call(this,i)}))}willUpdate(t){if(this.type==="decimal")return;const e=this.el.getBoundingClientRect();h(this,G,e[this.section.justify]-t[this.section.justify],"f")}update(t){if(this.value!==t){const e=n(this,_,"f").get(this.value);if(e.present=!1,e.el.classList.add("symbol__exiting"),n(this,_,"f").has(t)){const i=n(this,_,"f").get(t);i.present=!0,i.el.classList.remove("symbol__exiting")}else{const i=w("span",{className:"symbol__value",textContent:t});this.el.appendChild(i),n(this,_,"f").set(t,new et(this.flow,i,{animateIn:!0,onRemove:n(this,K,"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,G,"f")-i}px)`,"none"]},{...this.flow.transformTiming,composite:"accumulate"})}}_=new WeakMap,G=new WeakMap,K=new WeakMap;exports.NumberFlowLite=xt;exports.SlottedTag=lt;exports.canAnimate=ht;exports.defaultOpacityTiming=ct;exports.defaultTransformTiming=ft;exports.partitionParts=wt;exports.prefersReducedMotion=O;exports.slottedStyles=St;
|
package/dist/index.mjs
CHANGED
|
@@ -1,435 +1,443 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
throw TypeError(
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
return
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
1
|
+
import { BROWSER as Z } 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 w = (a, t, e) => {
|
|
14
|
+
const i = document.createElement(a), [s, r] = Array.isArray(t) ? [void 0, t] : [t, e];
|
|
15
|
+
return s && Object.assign(i, s), r == null || r.forEach((l) => i.appendChild(l)), 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
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
25
|
+
function $t(a, t) {
|
|
26
|
+
const e = t.formatToParts(a), i = [], s = [], r = [], l = [], o = {}, p = (c) => {
|
|
27
|
+
const f = o[c] == null ? o[c] = 0 : ++o[c];
|
|
28
|
+
return `${c}:${f}`;
|
|
29
|
+
};
|
|
30
|
+
let u = "", m = !1, N = !1;
|
|
31
|
+
for (const c of e) {
|
|
32
|
+
u += c.value;
|
|
33
|
+
const f = c.type === "minusSign" || c.type === "plusSign" ? "sign" : c.type;
|
|
34
|
+
f === "integer" ? (m = !0, s.push(...c.value.split("").map((q) => ({ type: f, value: parseInt(q) })))) : f === "group" ? s.push({ type: f, value: c.value }) : f === "decimal" ? (N = !0, r.push({ type: f, value: c.value, key: p(f) })) : f === "fraction" ? r.push(...c.value.split("").map((q) => ({
|
|
35
|
+
type: f,
|
|
36
|
+
value: parseInt(q),
|
|
37
|
+
key: p(f),
|
|
38
|
+
place: -1 - o[f]
|
|
39
|
+
}))) : (m || N ? l : i).push({
|
|
40
|
+
type: f,
|
|
41
|
+
value: c.value,
|
|
42
|
+
key: p(f)
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
const d = [];
|
|
46
|
+
for (let c = s.length - 1; c >= 0; c--) {
|
|
47
|
+
const f = s[c];
|
|
48
|
+
d.unshift(f.type === "integer" ? {
|
|
49
|
+
...f,
|
|
50
|
+
key: p(f.type),
|
|
51
|
+
place: o[f.type]
|
|
52
|
+
} : {
|
|
53
|
+
...f,
|
|
54
|
+
key: p(f.type)
|
|
33
55
|
});
|
|
34
56
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
57
|
+
return {
|
|
58
|
+
pre: i,
|
|
59
|
+
integer: d,
|
|
60
|
+
fraction: r,
|
|
61
|
+
post: l,
|
|
62
|
+
formatted: u,
|
|
63
|
+
value: typeof a == "string" ? parseFloat(a) : a
|
|
64
|
+
};
|
|
39
65
|
}
|
|
40
|
-
const
|
|
41
|
-
},
|
|
42
|
-
if (rt)
|
|
66
|
+
const pt = Z ? HTMLElement : class {
|
|
67
|
+
}, ut = String.raw, mt = Z && typeof CSS < "u" && CSS.supports("line-height", "mod(1,1)"), J = Z ? matchMedia("(prefers-reduced-motion: reduce)") : null, K = "--_number-flow-d-opacity", it = "--_number-flow-d-width", Y = "--_number-flow-dx", st = "--_number-flow-d", gt = (() => {
|
|
43
68
|
try {
|
|
44
|
-
CSS.registerProperty({
|
|
45
|
-
name:
|
|
69
|
+
return CSS.registerProperty({
|
|
70
|
+
name: K,
|
|
46
71
|
syntax: "<number>",
|
|
47
72
|
inherits: !1,
|
|
48
|
-
initialValue: "
|
|
49
|
-
})
|
|
73
|
+
initialValue: "0"
|
|
74
|
+
}), CSS.registerProperty({
|
|
75
|
+
name: Y,
|
|
76
|
+
syntax: "<length>",
|
|
77
|
+
inherits: !0,
|
|
78
|
+
initialValue: "0px"
|
|
79
|
+
}), CSS.registerProperty({
|
|
80
|
+
name: it,
|
|
81
|
+
syntax: "<number>",
|
|
82
|
+
inherits: !1,
|
|
83
|
+
initialValue: "0"
|
|
84
|
+
}), CSS.registerProperty({
|
|
85
|
+
name: st,
|
|
86
|
+
syntax: "<number>",
|
|
87
|
+
inherits: !0,
|
|
88
|
+
initialValue: "0"
|
|
89
|
+
}), !0;
|
|
50
90
|
} catch {
|
|
91
|
+
return !1;
|
|
51
92
|
}
|
|
52
|
-
|
|
93
|
+
})(), rt = "var(--number-flow-char-height, 1em)", g = "var(--number-flow-mask-height, 0.25em)", C = `calc(${g} / 2)`, Q = "var(--number-flow-mask-width, 0.5em)", S = `calc(${Q} / var(--scale-x))`, T = "#000 0, transparent 71%", wt = "span", Et = ({ willChange: a }) => ({
|
|
53
94
|
fontKerning: "none",
|
|
54
95
|
display: "inline-block",
|
|
55
|
-
lineHeight:
|
|
56
|
-
padding: `${g} 0
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
if (
|
|
64
|
-
return
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
}
|
|
74
|
-
const ot = (n, i, t) => n + (i - n) * t, $t = { duration: 500, easing: "ease-out" }, ht = bt ? {
|
|
96
|
+
lineHeight: rt,
|
|
97
|
+
padding: `${g} 0`,
|
|
98
|
+
willChange: a ? "transform" : void 0
|
|
99
|
+
}), nt = ut`:host{display:inline-flex;align-items:baseline;direction:ltr;white-space:nowrap;position:relative;line-height:${rt} !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(${it}) / var(--width));transform:translateX(var(${Y})) scaleX(var(--scale-x));margin:0 calc(-1 * ${Q});position:relative;z-index:-1;overflow:clip;-webkit-mask-image:linear-gradient( to right,transparent 0,#000 ${S},#000 calc(100% - ${S}),transparent ),linear-gradient( to bottom,transparent 0,#000 ${g},#000 calc(100% - ${g}),transparent 100% ),radial-gradient(at bottom right,${T}),radial-gradient(at bottom left,${T}),radial-gradient(at top left,${T}),radial-gradient(at top right,${T});-webkit-mask-size:100% calc(100% - ${g} * 2),calc(100% - ${S} * 2) 100%,${S} ${g},${S} ${g},${S} ${g},${S} ${g};-webkit-mask-position:center,center,top left,top right,bottom right,bottom left;-webkit-mask-repeat:no-repeat;}.number__inner{padding:0 ${Q};transform:scaleX(calc(1 / var(--scale-x))) translateX(calc(-1 * var(${Y})));}.section{display:inline-flex;align-items:baseline;padding-bottom:${C};padding-top:${C};position:relative;isolation:isolate;}.section::after{content:'\200b';display:block;padding:${C} 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(${st});}:host([data-will-change]) .digit,:host([data-will-change]) .digit__num{will-change:transform;}.digit__num{display:block;padding:${C} 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:${C} 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(${K}));}`, yt = (a, t) => {
|
|
100
|
+
if (a != null && t == null)
|
|
101
|
+
return a;
|
|
102
|
+
if (a == null && t != null)
|
|
103
|
+
return t;
|
|
104
|
+
if (a != null && t != null)
|
|
105
|
+
return Math.max(a, t);
|
|
106
|
+
};
|
|
107
|
+
var F, D, x, k, $, y, P, U, W, O, E, M, B, H, V, j, X, L, R, v, z, tt, _, I, G;
|
|
108
|
+
const vt = mt && gt;
|
|
109
|
+
var b;
|
|
110
|
+
(function(a) {
|
|
111
|
+
a[a.UP = 1] = "UP", a[a.DOWN = -1] = "DOWN", a[a.NONE = 0] = "NONE";
|
|
112
|
+
})(b || (b = {}));
|
|
113
|
+
const _t = { duration: 450, easing: "ease-out" }, bt = {
|
|
75
114
|
duration: 900,
|
|
115
|
+
// Make sure to keep this minified:
|
|
76
116
|
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 {
|
|
117
|
+
};
|
|
118
|
+
let A;
|
|
119
|
+
class Mt extends pt {
|
|
85
120
|
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);
|
|
121
|
+
super(...arguments), this.transformTiming = bt, this.opacityTiming = _t, F.set(this, !0), this.manual = !1, this.respectMotionPreference = !0, D.set(this, !1), x.set(this, void 0), k.set(this, void 0), $.set(this, void 0), this.trend = !0, y.set(this, void 0), this.continuous = !1, P.set(this, void 0), U.set(this, void 0), W.set(this, void 0);
|
|
97
122
|
}
|
|
98
123
|
static define() {
|
|
99
|
-
|
|
124
|
+
Z && customElements.define("number-flow", this);
|
|
125
|
+
}
|
|
126
|
+
get startingPlace() {
|
|
127
|
+
return n(this, P, "f");
|
|
128
|
+
}
|
|
129
|
+
get computedTrend() {
|
|
130
|
+
return n(this, y, "f");
|
|
100
131
|
}
|
|
101
132
|
set parts(t) {
|
|
102
133
|
if (t == null)
|
|
103
134
|
return;
|
|
104
|
-
const { pre:
|
|
105
|
-
if (
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
135
|
+
const { pre: e, integer: i, fraction: s, post: r, value: l } = t;
|
|
136
|
+
if (n(this, D, "f")) {
|
|
137
|
+
const o = n(this, U, "f");
|
|
138
|
+
if (h(this, U, t, "f"), this.trend === !0 ? h(this, y, Math.sign(l - o.value), "f") : this.trend === "increasing" ? h(this, y, b.UP, "f") : this.trend === "decreasing" ? h(this, y, b.DOWN, "f") : h(this, y, b.NONE, "f"), h(this, P, void 0, "f"), n(this, y, "f") !== b.NONE && this.continuous) {
|
|
139
|
+
const p = o.integer.concat(o.fraction).filter((d) => d.type === "integer" || d.type === "fraction"), u = t.integer.concat(t.fraction).filter((d) => d.type === "integer" || d.type === "fraction"), m = p.find((d) => !u.find((c) => c.place === d.place && c.value === d.value)), N = u.find((d) => !p.find((c) => d.place === c.place && d.value === c.value));
|
|
140
|
+
h(this, P, yt(m == null ? void 0 : m.place, N == null ? void 0 : N.place), "f");
|
|
141
|
+
}
|
|
142
|
+
this.manual || this.willUpdate(), n(this, x, "f").update(e), n(this, k, "f").update({ integer: i, fraction: s }), n(this, $, "f").update(r), this.manual || this.didUpdate();
|
|
143
|
+
} else {
|
|
144
|
+
if (h(this, U, t, "f"), this.attachShadow({ mode: "open" }), typeof CSSStyleSheet < "u" && this.shadowRoot.adoptedStyleSheets)
|
|
145
|
+
A || (A = new CSSStyleSheet(), A.replaceSync(nt)), this.shadowRoot.adoptedStyleSheets = [A];
|
|
110
146
|
else {
|
|
111
|
-
const
|
|
112
|
-
|
|
147
|
+
const o = document.createElement("style");
|
|
148
|
+
o.textContent = nt, this.shadowRoot.appendChild(o);
|
|
113
149
|
}
|
|
114
|
-
this.shadowRoot.appendChild(
|
|
115
|
-
// part: 'pre',
|
|
116
|
-
inert: !0,
|
|
117
|
-
ariaHidden: "true",
|
|
118
|
-
justify: "right"
|
|
119
|
-
})), this.shadowRoot.appendChild(o(this, b).el), h(this, C, new at(this, e, {
|
|
120
|
-
// part: 'integer',
|
|
150
|
+
this.shadowRoot.appendChild(w("slot")), h(this, x, new ot(this, e, {
|
|
121
151
|
inert: !0,
|
|
122
152
|
ariaHidden: "true",
|
|
123
153
|
justify: "right"
|
|
124
|
-
})), this.shadowRoot.appendChild(
|
|
125
|
-
// part: 'fraction',
|
|
154
|
+
}), "f"), this.shadowRoot.appendChild(n(this, x, "f").el), h(this, k, new St(this, i, s, {
|
|
126
155
|
inert: !0,
|
|
127
|
-
ariaHidden: "true"
|
|
128
|
-
|
|
129
|
-
})), this.shadowRoot.appendChild(o(this, k).el), h(this, v, new lt(this, l, {
|
|
130
|
-
// part: 'post',
|
|
156
|
+
ariaHidden: "true"
|
|
157
|
+
}), "f"), this.shadowRoot.appendChild(n(this, k, "f").el), h(this, $, new ot(this, r, {
|
|
131
158
|
inert: !0,
|
|
132
159
|
ariaHidden: "true",
|
|
133
160
|
justify: "left"
|
|
134
|
-
})), this.shadowRoot.appendChild(
|
|
161
|
+
}), "f"), this.shadowRoot.appendChild(n(this, $, "f").el);
|
|
135
162
|
}
|
|
136
|
-
h(this,
|
|
163
|
+
h(this, D, !0, "f");
|
|
137
164
|
}
|
|
138
165
|
willUpdate() {
|
|
139
|
-
|
|
140
|
-
o(this, b).willUpdate(t), o(this, C).willUpdate(t), o(this, k).willUpdate(t), o(this, v).willUpdate(t);
|
|
166
|
+
this.animated && (n(this, x, "f").willUpdate(), n(this, k, "f").willUpdate(), n(this, $, "f").willUpdate());
|
|
141
167
|
}
|
|
142
168
|
didUpdate() {
|
|
143
|
-
|
|
144
|
-
|
|
169
|
+
if (!this.animated)
|
|
170
|
+
return;
|
|
171
|
+
n(this, W, "f") ? n(this, W, "f").abort() : this.dispatchEvent(new Event("animationsstart")), n(this, x, "f").didUpdate(), n(this, k, "f").didUpdate(), n(this, $, "f").didUpdate();
|
|
172
|
+
const t = new AbortController();
|
|
173
|
+
Promise.all(this.shadowRoot.getAnimations().map((e) => e.finished)).then(() => {
|
|
174
|
+
t.signal.aborted || (this.dispatchEvent(new Event("animationsfinish")), h(this, W, void 0, "f"));
|
|
175
|
+
}), h(this, W, t, "f");
|
|
176
|
+
}
|
|
177
|
+
get animated() {
|
|
178
|
+
return vt && n(this, F, "f") && (!this.respectMotionPreference || !(J != null && J.matches));
|
|
179
|
+
}
|
|
180
|
+
set animated(t) {
|
|
181
|
+
var e;
|
|
182
|
+
this.animated !== t && (h(this, F, t, "f"), (e = this.shadowRoot) == null || e.getAnimations().forEach((i) => i.finish()));
|
|
145
183
|
}
|
|
146
184
|
}
|
|
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;
|
|
185
|
+
F = /* @__PURE__ */ new WeakMap(), D = /* @__PURE__ */ new WeakMap(), x = /* @__PURE__ */ new WeakMap(), k = /* @__PURE__ */ new WeakMap(), $ = /* @__PURE__ */ new WeakMap(), y = /* @__PURE__ */ new WeakMap(), P = /* @__PURE__ */ new WeakMap(), U = /* @__PURE__ */ new WeakMap(), W = /* @__PURE__ */ new WeakMap();
|
|
186
|
+
class St {
|
|
187
|
+
constructor(t, e, i, { className: s, ...r } = {}) {
|
|
188
|
+
this.flow = t, O.set(this, void 0), E.set(this, void 0), M.set(this, void 0), B.set(this, void 0), H.set(this, void 0), h(this, E, new at(t, e, {
|
|
189
|
+
justify: "right"
|
|
190
|
+
}), "f"), h(this, M, new at(t, i, {
|
|
191
|
+
justify: "left"
|
|
192
|
+
}), "f"), h(this, O, w("span", {
|
|
193
|
+
className: "number__inner"
|
|
194
|
+
}, [n(this, E, "f").el, n(this, M, "f").el]), "f"), this.el = w("span", {
|
|
195
|
+
...r,
|
|
196
|
+
className: `number ${s ?? ""}`
|
|
197
|
+
}, [n(this, O, "f")]);
|
|
174
198
|
}
|
|
175
|
-
|
|
176
|
-
|
|
199
|
+
willUpdate() {
|
|
200
|
+
h(this, B, this.el.offsetWidth, "f"), h(this, H, this.el.getBoundingClientRect().left, "f"), n(this, E, "f").willUpdate(), n(this, M, "f").willUpdate();
|
|
177
201
|
}
|
|
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
|
-
});
|
|
202
|
+
update({ integer: t, fraction: e }) {
|
|
203
|
+
n(this, E, "f").update(t), n(this, M, "f").update(e);
|
|
184
204
|
}
|
|
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);
|
|
205
|
+
didUpdate() {
|
|
206
|
+
const t = this.el.getBoundingClientRect();
|
|
207
|
+
n(this, E, "f").didUpdate(), n(this, M, "f").didUpdate();
|
|
208
|
+
const e = n(this, H, "f") - t.left, i = this.el.offsetWidth, s = n(this, B, "f") - i;
|
|
209
|
+
this.el.style.setProperty("--width", String(i)), this.el.animate({
|
|
210
|
+
[Y]: [`${e}px`, "0px"],
|
|
211
|
+
[it]: [s, 0]
|
|
212
|
+
}, {
|
|
213
|
+
...this.flow.transformTiming,
|
|
214
|
+
composite: "accumulate"
|
|
198
215
|
});
|
|
199
216
|
}
|
|
200
217
|
}
|
|
201
|
-
|
|
202
|
-
class
|
|
203
|
-
constructor(t,
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
218
|
+
O = /* @__PURE__ */ new WeakMap(), E = /* @__PURE__ */ new WeakMap(), M = /* @__PURE__ */ new WeakMap(), B = /* @__PURE__ */ new WeakMap(), H = /* @__PURE__ */ new WeakMap();
|
|
219
|
+
class lt {
|
|
220
|
+
constructor(t, e, { justify: i, className: s, ...r }, l) {
|
|
221
|
+
this.flow = t, this.children = /* @__PURE__ */ new Map(), this.onCharRemove = (p) => () => {
|
|
222
|
+
this.children.delete(p);
|
|
223
|
+
}, V.set(this, void 0), this.justify = i;
|
|
224
|
+
const o = e.map((p) => this.addChar(p).el);
|
|
225
|
+
this.el = w("span", {
|
|
226
|
+
...r,
|
|
227
|
+
className: `section section--justify-${i} ${s ?? ""}`
|
|
228
|
+
}, l ? l(o) : o);
|
|
229
|
+
}
|
|
230
|
+
addChar(t, { startDigitsAtZero: e = !1, ...i } = {}) {
|
|
231
|
+
const s = t.type === "integer" || t.type === "fraction" ? new ct(this, t.type, e ? 0 : t.value, t.place, {
|
|
232
|
+
...i,
|
|
233
|
+
onRemove: this.onCharRemove(t.key)
|
|
234
|
+
}) : new xt(this, t.type, t.value, {
|
|
235
|
+
...i,
|
|
236
|
+
onRemove: this.onCharRemove(t.key)
|
|
237
|
+
});
|
|
238
|
+
return this.children.set(t.key, s), s;
|
|
220
239
|
}
|
|
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));
|
|
240
|
+
unpop(t) {
|
|
241
|
+
t.el.classList.remove("section__exiting"), t.el.style[this.justify] = "";
|
|
226
242
|
}
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
}), this.pop(s);
|
|
243
|
+
pop(t) {
|
|
244
|
+
t.forEach((e) => {
|
|
245
|
+
e.el.style[this.justify] = `${ft(e.el, this.justify)}px`;
|
|
246
|
+
}), t.forEach((e) => {
|
|
247
|
+
e.el.classList.add("section__exiting"), e.present = !1;
|
|
248
|
+
});
|
|
234
249
|
}
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
250
|
+
addNewAndUpdateExisting(t) {
|
|
251
|
+
const e = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Map(), s = this.justify === "left", r = s ? "prepend" : "append";
|
|
252
|
+
if (dt(t, (l) => {
|
|
253
|
+
let o;
|
|
254
|
+
this.children.has(l.key) ? (o = this.children.get(l.key), i.set(l, o), this.unpop(o), o.present = !0) : (o = this.addChar(l, { startDigitsAtZero: !0, animateIn: !0 }), e.set(l, o)), this.el[r](o.el);
|
|
255
|
+
}, { reverse: s }), this.flow.animated) {
|
|
256
|
+
const l = this.el.getBoundingClientRect();
|
|
257
|
+
e.forEach((o) => {
|
|
258
|
+
o.willUpdate(l);
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
e.forEach((l, o) => {
|
|
262
|
+
l.update(o.value);
|
|
263
|
+
}), i.forEach((l, o) => {
|
|
264
|
+
l.update(o.value);
|
|
265
|
+
});
|
|
247
266
|
}
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
class lt extends dt {
|
|
252
|
-
constructor() {
|
|
253
|
-
super(...arguments);
|
|
254
|
-
r(this, H);
|
|
255
|
-
r(this, P);
|
|
267
|
+
willUpdate() {
|
|
268
|
+
const t = this.el.getBoundingClientRect();
|
|
269
|
+
h(this, V, t[this.justify], "f"), this.children.forEach((e) => e.willUpdate(t));
|
|
256
270
|
}
|
|
257
|
-
|
|
258
|
-
const
|
|
259
|
-
|
|
271
|
+
didUpdate() {
|
|
272
|
+
const t = this.el.getBoundingClientRect();
|
|
273
|
+
this.children.forEach((s) => s.didUpdate(t));
|
|
274
|
+
const e = t[this.justify], i = n(this, V, "f") - e;
|
|
275
|
+
this.el.animate({
|
|
276
|
+
transform: [`translateX(${i}px)`, "none"]
|
|
277
|
+
}, {
|
|
278
|
+
...this.flow.transformTiming,
|
|
279
|
+
composite: "accumulate"
|
|
280
|
+
});
|
|
260
281
|
}
|
|
282
|
+
}
|
|
283
|
+
V = /* @__PURE__ */ new WeakMap();
|
|
284
|
+
class at extends lt {
|
|
261
285
|
update(t) {
|
|
262
|
-
const
|
|
263
|
-
this.children.forEach((
|
|
264
|
-
t.find((
|
|
265
|
-
}), this.
|
|
286
|
+
const e = /* @__PURE__ */ new Map();
|
|
287
|
+
this.children.forEach((i, s) => {
|
|
288
|
+
t.find((r) => r.key === s) || e.set(s, i), this.unpop(i);
|
|
289
|
+
}), this.addNewAndUpdateExisting(t), e.forEach((i) => {
|
|
290
|
+
i instanceof ct && i.update(0);
|
|
291
|
+
}), this.pop(e);
|
|
266
292
|
}
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
const
|
|
271
|
-
this.children.forEach((
|
|
272
|
-
|
|
273
|
-
}, this.
|
|
293
|
+
}
|
|
294
|
+
class ot extends lt {
|
|
295
|
+
update(t) {
|
|
296
|
+
const e = /* @__PURE__ */ new Map();
|
|
297
|
+
this.children.forEach((i, s) => {
|
|
298
|
+
t.find((r) => r.key === s) || e.set(s, i);
|
|
299
|
+
}), this.pop(e), this.addNewAndUpdateExisting(t);
|
|
274
300
|
}
|
|
275
301
|
}
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
}, i.fadeTiming), h(this, W, s);
|
|
302
|
+
class et {
|
|
303
|
+
constructor(t, e, { onRemove: i, animateIn: s = !1 } = {}) {
|
|
304
|
+
this.flow = t, this.el = e, j.set(this, !0), X.set(this, void 0), L.set(this, () => {
|
|
305
|
+
var r;
|
|
306
|
+
this.el.remove(), (r = n(this, X, "f")) == null || r.call(this);
|
|
307
|
+
}), this.el.classList.add("animate-presence"), this.flow.animated && s && this.el.animate({
|
|
308
|
+
[K]: [-0.9999, 0]
|
|
309
|
+
}, {
|
|
310
|
+
...this.flow.opacityTiming,
|
|
311
|
+
composite: "accumulate"
|
|
312
|
+
}), h(this, X, i, "f");
|
|
288
313
|
}
|
|
289
314
|
get present() {
|
|
290
|
-
return
|
|
315
|
+
return n(this, j, "f");
|
|
291
316
|
}
|
|
292
|
-
set present(
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
opacity
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
317
|
+
set present(t) {
|
|
318
|
+
if (n(this, j, "f") !== t) {
|
|
319
|
+
if (h(this, j, t, "f"), !this.flow.animated) {
|
|
320
|
+
t || n(this, L, "f").call(this);
|
|
321
|
+
return;
|
|
322
|
+
}
|
|
323
|
+
this.el.style.setProperty("--_number-flow-d-opacity", t ? "0" : "-.999"), this.el.animate({
|
|
324
|
+
[K]: t ? [-0.9999, 0] : [0.999, 0]
|
|
325
|
+
}, {
|
|
326
|
+
...this.flow.opacityTiming,
|
|
327
|
+
composite: "accumulate"
|
|
328
|
+
}), t ? this.flow.removeEventListener("animationsfinish", n(this, L, "f")) : this.flow.addEventListener("animationsfinish", n(this, L, "f"), {
|
|
329
|
+
once: !0
|
|
330
|
+
});
|
|
331
|
+
}
|
|
303
332
|
}
|
|
304
333
|
}
|
|
305
|
-
j = new WeakMap(),
|
|
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;
|
|
334
|
+
j = /* @__PURE__ */ new WeakMap(), X = /* @__PURE__ */ new WeakMap(), L = /* @__PURE__ */ new WeakMap();
|
|
335
|
+
class ht extends et {
|
|
336
|
+
constructor(t, e, i, s) {
|
|
337
|
+
super(t.flow, i, s), this.section = t, this.value = e, this.el = i;
|
|
313
338
|
}
|
|
314
339
|
}
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
}
|
|
323
|
-
r(this,
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
r(this, z);
|
|
327
|
-
r(this, O);
|
|
328
|
-
r(this, D);
|
|
340
|
+
class ct extends ht {
|
|
341
|
+
constructor(t, e, i, s, r) {
|
|
342
|
+
const l = Array.from({ length: 10 }).map((p, u) => {
|
|
343
|
+
const m = w("span", { className: `digit__num${u === i ? " is-current" : ""}` }, [document.createTextNode(String(u))]);
|
|
344
|
+
return m.style.setProperty("--n", String(u)), m;
|
|
345
|
+
}), o = w("span", {
|
|
346
|
+
className: "digit"
|
|
347
|
+
}, l);
|
|
348
|
+
o.style.setProperty("--current", String(i)), super(t, i, o, r), this.place = s, R.set(this, void 0), v.set(this, void 0), z.set(this, void 0), tt.set(this, () => {
|
|
349
|
+
this.el.classList.remove("is-spinning");
|
|
350
|
+
}), h(this, R, l, "f");
|
|
329
351
|
}
|
|
330
352
|
willUpdate(t) {
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
h(this, z, this.section.justify === "left" ? e + a : e - a);
|
|
353
|
+
const e = this.el.getBoundingClientRect();
|
|
354
|
+
h(this, v, this.value, "f");
|
|
355
|
+
const i = e[this.section.justify] - t[this.section.justify], s = e.width / 2;
|
|
356
|
+
h(this, z, this.section.justify === "left" ? i + s : i - s, "f");
|
|
336
357
|
}
|
|
337
358
|
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
|
-
]);
|
|
359
|
+
var e, i;
|
|
360
|
+
(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;
|
|
347
361
|
}
|
|
348
362
|
didUpdate(t) {
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
h(this, O, this.el.animate({
|
|
353
|
-
transform: [et ? f : `${f} ${c}`, "none"]
|
|
363
|
+
const e = this.el.getBoundingClientRect(), i = e[this.section.justify] - t[this.section.justify], s = e.width / 2, r = this.section.justify === "left" ? i + s : i - s;
|
|
364
|
+
this.el.animate({
|
|
365
|
+
transform: [`translateX(${n(this, z, "f") - r}px)`, "none"]
|
|
354
366
|
}, {
|
|
355
|
-
...this.flow.
|
|
367
|
+
...this.flow.transformTiming,
|
|
356
368
|
composite: "accumulate"
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
369
|
+
});
|
|
370
|
+
const l = this.diff;
|
|
371
|
+
l && (this.el.classList.add("is-spinning"), this.el.animate({
|
|
372
|
+
[st]: [-l, 0]
|
|
360
373
|
}, {
|
|
361
|
-
...this.flow.
|
|
374
|
+
...this.flow.spinTiming ?? this.flow.transformTiming,
|
|
362
375
|
composite: "accumulate"
|
|
363
|
-
}));
|
|
376
|
+
}), this.flow.addEventListener("animationsfinish", n(this, tt, "f"), { once: !0 }));
|
|
377
|
+
}
|
|
378
|
+
get diff() {
|
|
379
|
+
let t = this.flow.computedTrend;
|
|
380
|
+
const e = this.value - n(this, v, "f");
|
|
381
|
+
return !e && this.flow.startingPlace != null && this.flow.startingPlace >= this.place ? 10 * t : (t || (t = Math.sign(e)), t === b.DOWN && this.value > n(this, v, "f") ? this.value - 10 - n(this, v, "f") : t === b.UP && this.value < n(this, v, "f") ? 10 - n(this, v, "f") + this.value : e);
|
|
364
382
|
}
|
|
365
383
|
}
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
const l = y("span", {
|
|
384
|
+
R = /* @__PURE__ */ new WeakMap(), v = /* @__PURE__ */ new WeakMap(), z = /* @__PURE__ */ new WeakMap(), tt = /* @__PURE__ */ new WeakMap();
|
|
385
|
+
class xt extends ht {
|
|
386
|
+
constructor(t, e, i, s) {
|
|
387
|
+
const r = w("span", {
|
|
371
388
|
className: "symbol__value",
|
|
372
|
-
textContent:
|
|
389
|
+
textContent: i
|
|
373
390
|
});
|
|
374
|
-
super(t,
|
|
391
|
+
super(t, i, w("span", {
|
|
375
392
|
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)
|
|
393
|
+
}, [r]), s), this.type = e, _.set(this, /* @__PURE__ */ new Map()), I.set(this, void 0), G.set(this, (l) => () => {
|
|
394
|
+
n(this, _, "f").delete(l);
|
|
395
|
+
}), n(this, _, "f").set(i, new et(this.flow, r, {
|
|
396
|
+
onRemove: n(this, G, "f").call(this, i)
|
|
386
397
|
}));
|
|
387
398
|
}
|
|
388
399
|
willUpdate(t) {
|
|
389
400
|
if (this.type === "decimal")
|
|
390
401
|
return;
|
|
391
|
-
const
|
|
392
|
-
h(this, I,
|
|
402
|
+
const e = this.el.getBoundingClientRect();
|
|
403
|
+
h(this, I, e[this.section.justify] - t[this.section.justify], "f");
|
|
393
404
|
}
|
|
394
405
|
update(t) {
|
|
395
406
|
if (this.value !== t) {
|
|
396
|
-
const
|
|
397
|
-
if (
|
|
398
|
-
const
|
|
399
|
-
|
|
407
|
+
const e = n(this, _, "f").get(this.value);
|
|
408
|
+
if (e.present = !1, e.el.classList.add("symbol__exiting"), n(this, _, "f").has(t)) {
|
|
409
|
+
const i = n(this, _, "f").get(t);
|
|
410
|
+
i.present = !0, i.el.classList.remove("symbol__exiting");
|
|
400
411
|
} else {
|
|
401
|
-
const
|
|
412
|
+
const i = w("span", {
|
|
402
413
|
className: "symbol__value",
|
|
403
414
|
textContent: t
|
|
404
415
|
});
|
|
405
|
-
this.el.appendChild(
|
|
416
|
+
this.el.appendChild(i), n(this, _, "f").set(t, new et(this.flow, i, {
|
|
406
417
|
animateIn: !0,
|
|
407
|
-
onRemove:
|
|
418
|
+
onRemove: n(this, G, "f").call(this, t)
|
|
408
419
|
}));
|
|
409
420
|
}
|
|
410
421
|
}
|
|
411
422
|
this.value = t;
|
|
412
423
|
}
|
|
413
424
|
didUpdate(t) {
|
|
414
|
-
var a;
|
|
415
425
|
if (this.type === "decimal")
|
|
416
426
|
return;
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
}, this.flow.xTiming));
|
|
427
|
+
const i = this.el.getBoundingClientRect()[this.section.justify] - t[this.section.justify];
|
|
428
|
+
this.el.animate({
|
|
429
|
+
transform: [`translateX(${n(this, I, "f") - i}px)`, "none"]
|
|
430
|
+
}, { ...this.flow.transformTiming, composite: "accumulate" });
|
|
422
431
|
}
|
|
423
432
|
}
|
|
424
|
-
|
|
433
|
+
_ = /* @__PURE__ */ new WeakMap(), I = /* @__PURE__ */ new WeakMap(), G = /* @__PURE__ */ new WeakMap();
|
|
425
434
|
export {
|
|
426
435
|
Mt as NumberFlowLite,
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
bt as supportsLinear
|
|
436
|
+
wt as SlottedTag,
|
|
437
|
+
vt as canAnimate,
|
|
438
|
+
_t as defaultOpacityTiming,
|
|
439
|
+
bt as defaultTransformTiming,
|
|
440
|
+
$t as partitionParts,
|
|
441
|
+
J as prefersReducedMotion,
|
|
442
|
+
Et as slottedStyles
|
|
435
443
|
};
|
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 {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const max: (n1?: number, n2?: number) => number | undefined;
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "0.
|
|
6
|
+
"version": "0.3.1",
|
|
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;
|