number-flow 0.5.2 → 0.5.4
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/README.md +11 -1
- package/dist/group.d.ts +18 -0
- package/dist/group.js +1 -0
- package/dist/group.mjs +40 -0
- package/dist/index.d.ts +32 -5
- package/dist/index.js +1 -1
- package/dist/index.mjs +29 -46
- package/dist/lite-B614HEDD.js +12 -0
- package/dist/{continuous-dVP5sYQl.mjs → lite-D-JHjRWt.mjs} +163 -122
- package/dist/lite.d.ts +24 -4
- package/dist/lite.js +1 -0
- package/dist/lite.mjs +12 -0
- package/dist/plugins/index.d.ts +2 -1
- package/dist/plugins.js +1 -1
- package/dist/plugins.mjs +14 -2
- package/package.json +12 -2
- package/dist/continuous-DyFEzKlu.js +0 -10
package/README.md
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
[](https://number-flow.barvian.me/vanilla)
|
|
2
|
+
|
|
1
3
|
# NumberFlow
|
|
2
4
|
|
|
3
|
-
|
|
5
|
+
An animated number component.
|
|
6
|
+
|
|
7
|
+
[](https://npmjs.com/package/number-flow)
|
|
8
|
+
[](https://bundlephobia.com/package/number-flow@latest)
|
|
9
|
+
[](https://x.com/mbarvian)
|
|
10
|
+
|
|
11
|
+
## Documentation
|
|
12
|
+
|
|
13
|
+
For full documentation, visit [number-flow.barvian.me/vanilla](https://number-flow.barvian.me/vanilla).
|
package/dist/group.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ServerSafeHTMLElement } from './ssr';
|
|
2
|
+
import NumberFlow from '.';
|
|
3
|
+
export default class NumberFlowGroup extends ServerSafeHTMLElement {
|
|
4
|
+
private _mutationObserver?;
|
|
5
|
+
connectedCallback(): void;
|
|
6
|
+
private _flows;
|
|
7
|
+
_addDescendant: (flow: NumberFlow) => void;
|
|
8
|
+
_removeDescendant: (flow: NumberFlow) => void;
|
|
9
|
+
private _onDescendantConnected;
|
|
10
|
+
private _updating;
|
|
11
|
+
private _onDescendantUpdate;
|
|
12
|
+
disconnectedCallback(): void;
|
|
13
|
+
}
|
|
14
|
+
declare global {
|
|
15
|
+
interface HTMLElementTagNameMap {
|
|
16
|
+
'number-flow-group': NumberFlowGroup;
|
|
17
|
+
}
|
|
18
|
+
}
|
package/dist/group.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const n=require("./lite-B614HEDD.js"),t=require("./index.js");class i extends n.ServerSafeHTMLElement{constructor(){super(...arguments),this._flows=new Set,this._addDescendant=e=>{e.batched=!0,this._flows.add(e)},this._removeDescendant=e=>{e.batched=!1,this._flows.delete(e)},this._onDescendantConnected=e=>{this._addDescendant(e.target)},this._updating=!1,this._onDescendantUpdate=()=>{this._updating||(this._updating=!0,this._flows.forEach(e=>{e.created&&(e.willUpdate(),queueMicrotask(()=>{e.connected&&e.didUpdate()}))}),queueMicrotask(()=>{this._updating=!1}))}}connectedCallback(){this.querySelectorAll("number-flow").forEach(e=>{this._addDescendant(e)}),this.addEventListener(t.CONNECT_EVENT,this._onDescendantConnected),this.addEventListener(t.UPDATE_EVENT,this._onDescendantUpdate),this._mutationObserver??(this._mutationObserver=new MutationObserver(e=>{e.forEach(r=>{r.removedNodes.forEach(s=>{s instanceof t.default&&this._removeDescendant(s)})})})),this._mutationObserver.observe(this,{childList:!0,subtree:!0})}disconnectedCallback(){var e;this.removeEventListener(t.CONNECT_EVENT,this._onDescendantConnected),this.removeEventListener(t.UPDATE_EVENT,this._onDescendantUpdate),(e=this._mutationObserver)==null||e.disconnect()}}n.define("number-flow-group",i);module.exports=i;
|
package/dist/group.mjs
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { d as a, S as r } from "./lite-D-JHjRWt.mjs";
|
|
2
|
+
import d, { CONNECT_EVENT as s, UPDATE_EVENT as n } from "./index.mjs";
|
|
3
|
+
class o extends r {
|
|
4
|
+
constructor() {
|
|
5
|
+
super(...arguments), this._flows = /* @__PURE__ */ new Set(), this._addDescendant = (e) => {
|
|
6
|
+
e.batched = !0, this._flows.add(e);
|
|
7
|
+
}, this._removeDescendant = (e) => {
|
|
8
|
+
e.batched = !1, this._flows.delete(e);
|
|
9
|
+
}, this._onDescendantConnected = (e) => {
|
|
10
|
+
this._addDescendant(e.target);
|
|
11
|
+
}, this._updating = !1, this._onDescendantUpdate = () => {
|
|
12
|
+
this._updating || (this._updating = !0, this._flows.forEach((e) => {
|
|
13
|
+
e.created && (e.willUpdate(), queueMicrotask(() => {
|
|
14
|
+
e.connected && e.didUpdate();
|
|
15
|
+
}));
|
|
16
|
+
}), queueMicrotask(() => {
|
|
17
|
+
this._updating = !1;
|
|
18
|
+
}));
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
connectedCallback() {
|
|
22
|
+
this.querySelectorAll("number-flow").forEach((e) => {
|
|
23
|
+
this._addDescendant(e);
|
|
24
|
+
}), this.addEventListener(s, this._onDescendantConnected), this.addEventListener(n, this._onDescendantUpdate), this._mutationObserver ?? (this._mutationObserver = new MutationObserver((e) => {
|
|
25
|
+
e.forEach((i) => {
|
|
26
|
+
i.removedNodes.forEach((t) => {
|
|
27
|
+
t instanceof d && this._removeDescendant(t);
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
})), this._mutationObserver.observe(this, { childList: !0, subtree: !0 });
|
|
31
|
+
}
|
|
32
|
+
disconnectedCallback() {
|
|
33
|
+
var e;
|
|
34
|
+
this.removeEventListener(s, this._onDescendantConnected), this.removeEventListener(n, this._onDescendantUpdate), (e = this._mutationObserver) == null || e.disconnect();
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
a("number-flow-group", o);
|
|
38
|
+
export {
|
|
39
|
+
o as default
|
|
40
|
+
};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,33 @@
|
|
|
1
|
+
import NumberFlowLite from './lite';
|
|
2
|
+
import { type Value, type Format } from './formatter';
|
|
1
3
|
export * from './lite';
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
export declare const CONNECT_EVENT = "number-flow-connect";
|
|
5
|
+
export declare const UPDATE_EVENT = "number-flow-update";
|
|
6
|
+
export declare const renderInnerHTML: (value: Value, { locales, format, numberPrefix: prefix, numberSuffix: suffix }?: {
|
|
7
|
+
locales?: Intl.LocalesArgument;
|
|
8
|
+
format?: Intl.NumberFormatOptions;
|
|
9
|
+
numberPrefix?: string;
|
|
10
|
+
numberSuffix?: string;
|
|
11
|
+
}) => string;
|
|
12
|
+
export default class NumberFlow extends NumberFlowLite {
|
|
13
|
+
/**
|
|
14
|
+
* @internal for grouping
|
|
15
|
+
*/
|
|
16
|
+
connected: boolean;
|
|
17
|
+
connectedCallback(): void;
|
|
18
|
+
disconnectedCallback(): void;
|
|
19
|
+
format?: Format;
|
|
20
|
+
locales?: Intl.LocalesArgument;
|
|
21
|
+
numberPrefix?: string;
|
|
22
|
+
numberSuffix?: string;
|
|
23
|
+
private _formatter?;
|
|
24
|
+
private _prevFormat?;
|
|
25
|
+
private _prevLocales?;
|
|
26
|
+
private _value?;
|
|
27
|
+
update(value?: Value): void;
|
|
28
|
+
}
|
|
29
|
+
declare global {
|
|
30
|
+
interface HTMLElementTagNameMap {
|
|
31
|
+
'number-flow': NumberFlow;
|
|
32
|
+
}
|
|
33
|
+
}
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("./lite-B614HEDD.js"),l=require("./plugins.js"),r="number-flow-connect",s="number-flow-update",f=(n,{locales:t,format:i,numberPrefix:a,numberSuffix:u}={})=>{const c=e.formatToData(n,new Intl.NumberFormat(t,i),a,u);return e.renderInnerHTML(c)};class o extends e.NumberFlowLite{constructor(){super(...arguments),this.connected=!1}connectedCallback(){this.connected=!0,this.dispatchEvent(new Event(r,{bubbles:!0}))}disconnectedCallback(){this.connected=!1}update(t){(!this._formatter||this._prevFormat!==this.format||this._prevLocales!==this.locales)&&(this._formatter=new Intl.NumberFormat(this.locales,this.format),this._prevFormat=this.format,this._prevLocales=this.locales),t!=null&&(this._value=t),this.dispatchEvent(new Event(s,{bubbles:!0})),this.data=e.formatToData(this._value,this._formatter,this.numberPrefix,this.numberSuffix)}}e.define("number-flow",o);exports.Digit=e.Digit;exports.canAnimate=e.canAnimate;exports.define=e.define;exports.formatToData=e.formatToData;exports.prefersReducedMotion=e.prefersReducedMotion;exports.continuous=l.continuous;exports.CONNECT_EVENT=r;exports.UPDATE_EVENT=s;exports.default=o;exports.renderInnerHTML=f;
|
package/dist/index.mjs
CHANGED
|
@@ -1,51 +1,34 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
value: t.value,
|
|
18
|
-
key: s(e)
|
|
19
|
-
});
|
|
1
|
+
import { d as i, N as c, f as r, r as u } from "./lite-D-JHjRWt.mjs";
|
|
2
|
+
import { D as _, c as E, p as v } from "./lite-D-JHjRWt.mjs";
|
|
3
|
+
import { continuous as N } from "./plugins.mjs";
|
|
4
|
+
const l = "number-flow-connect", m = "number-flow-update", d = (e, { locales: t, format: s, numberPrefix: n, numberSuffix: a } = {}) => {
|
|
5
|
+
const o = r(e, new Intl.NumberFormat(t, s), n, a);
|
|
6
|
+
return u(o);
|
|
7
|
+
};
|
|
8
|
+
class f extends c {
|
|
9
|
+
constructor() {
|
|
10
|
+
super(...arguments), this.connected = !1;
|
|
11
|
+
}
|
|
12
|
+
connectedCallback() {
|
|
13
|
+
this.connected = !0, this.dispatchEvent(new Event(l, { bubbles: !0 }));
|
|
14
|
+
}
|
|
15
|
+
disconnectedCallback() {
|
|
16
|
+
this.connected = !1;
|
|
20
17
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const e = a[t];
|
|
24
|
-
m.unshift(e.type === "integer" ? {
|
|
25
|
-
...e,
|
|
26
|
-
key: s(e.type),
|
|
27
|
-
pos: o[e.type]
|
|
28
|
-
} : {
|
|
29
|
-
...e,
|
|
30
|
-
key: s(e.type)
|
|
31
|
-
});
|
|
18
|
+
update(t) {
|
|
19
|
+
(!this._formatter || this._prevFormat !== this.format || this._prevLocales !== this.locales) && (this._formatter = new Intl.NumberFormat(this.locales, this.format), this._prevFormat = this.format, this._prevLocales = this.locales), t != null && (this._value = t), this.dispatchEvent(new Event(m, { bubbles: !0 })), this.data = r(this._value, this._formatter, this.numberPrefix, this.numberSuffix);
|
|
32
20
|
}
|
|
33
|
-
return {
|
|
34
|
-
pre: f,
|
|
35
|
-
integer: m,
|
|
36
|
-
fraction: p,
|
|
37
|
-
post: c,
|
|
38
|
-
valueAsString: y,
|
|
39
|
-
value: typeof n == "string" ? parseFloat(n) : n
|
|
40
|
-
};
|
|
41
21
|
}
|
|
22
|
+
i("number-flow", f);
|
|
42
23
|
export {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
24
|
+
l as CONNECT_EVENT,
|
|
25
|
+
_ as Digit,
|
|
26
|
+
m as UPDATE_EVENT,
|
|
27
|
+
E as canAnimate,
|
|
28
|
+
N as continuous,
|
|
29
|
+
f as default,
|
|
30
|
+
i as define,
|
|
31
|
+
r as formatToData,
|
|
32
|
+
v as prefersReducedMotion,
|
|
33
|
+
d as renderInnerHTML
|
|
51
34
|
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";const _=require("esm-env");require("./plugins.js");const u=(n,t,e)=>{const i=document.createElement(n),[s,a]=Array.isArray(t)?[void 0,t]:[t,e];return s&&Object.assign(i,s),a==null||a.forEach(o=>i.appendChild(o)),i},I=(n,t)=>{var e;return t==="left"?n.offsetLeft:(((e=n.offsetParent instanceof HTMLElement?n.offsetParent:null)==null?void 0:e.offsetWidth)??0)-n.offsetWidth-n.offsetLeft},X=n=>n.offsetWidth>0&&n.offsetHeight>0,z=(n,t)=>{_.BROWSER&&customElements.get(n)!==t&&customElements.define(n,t)};function q(n,t,{reverse:e=!1}={}){const i=n.length;for(let s=e?i-1:0;e?s>=0:s<i;e?s--:s++)t(n[s],s)}function Y(n,t,e,i){const s=t.formatToParts(n);e&&s.unshift({type:"prefix",value:e}),i&&s.push({type:"suffix",value:i});const a=[],o=[],r=[],c=[],d={},p=h=>`${h}:${d[h]=(d[h]??-1)+1}`;let E="",g=!1,y=!1;for(const h of s){E+=h.value;const l=h.type==="minusSign"||h.type==="plusSign"?"sign":h.type;l==="integer"?(g=!0,o.push(...h.value.split("").map(x=>({type:l,value:parseInt(x)})))):l==="group"?o.push({type:l,value:h.value}):l==="decimal"?(y=!0,r.push({type:l,value:h.value,key:p(l)})):l==="fraction"?r.push(...h.value.split("").map(x=>({type:l,value:parseInt(x),key:p(l),pos:-1-d[l]}))):(g||y?c:a).push({type:l,value:h.value,key:p(l)})}const P=[];for(let h=o.length-1;h>=0;h--){const l=o[h];P.unshift(l.type==="integer"?{...l,key:p(l.type),pos:d[l.type]}:{...l,key:p(l.type)})}return{pre:a,integer:P,fraction:r,post:c,valueAsString:E,value:typeof n=="string"?parseFloat(n):n}}const G=String.raw,V=String.raw,K=_.BROWSER&&typeof CSS<"u"&&CSS.supports&&CSS.supports("animation-timing-function","linear(1,2)"),Z=_.BROWSER&&typeof CSS<"u"&&CSS.supports&&CSS.supports("line-height","mod(1,1)"),S=_.BROWSER&&typeof matchMedia<"u"?matchMedia("(prefers-reduced-motion: reduce)"):null,$="--_number-flow-d-opacity",U="--_number-flow-d-width",C="--_number-flow-dx",j="--_number-flow-d",J=(()=>{try{return CSS.registerProperty({name:$,syntax:"<number>",inherits:!1,initialValue:"0"}),CSS.registerProperty({name:C,syntax:"<length>",inherits:!0,initialValue:"0px"}),CSS.registerProperty({name:U,syntax:"<number>",inherits:!1,initialValue:"0"}),CSS.registerProperty({name:j,syntax:"<number>",inherits:!0,initialValue:"0"}),!0}catch{return!1}})(),T="var(--number-flow-char-height, 1em)",f="var(--number-flow-mask-height, 0.25em)",R=`calc(${f} / 2)`,A="var(--number-flow-mask-width, 0.5em)",m=`calc(${A} / var(--scale-x))`,w="#000 0, transparent 71%",L=V`:host{display:inline-block;direction:ltr;white-space:nowrap;isolation:isolate;line-height:${T} !important}.number,.number__inner{display:inline-block;transform-origin:left top}:host([data-will-change]) :is(.number,.number__inner,.section,.digit,.digit__num,.symbol){will-change:transform}.number{--scale-x:calc(1 + var(${U}) / var(--width));transform:translateX(var(${C})) scaleX(var(--scale-x));margin:0 calc(-1 * ${A});position:relative;-webkit-mask-image:linear-gradient(to right,transparent 0,#000 ${m},#000 calc(100% - ${m}),transparent ),linear-gradient(to bottom,transparent 0,#000 ${f},#000 calc(100% - ${f}),transparent 100% ),radial-gradient(at bottom right,${w}),radial-gradient(at bottom left,${w}),radial-gradient(at top left,${w}),radial-gradient(at top right,${w});-webkit-mask-size:100% calc(100% - ${f} * 2),calc(100% - ${m} * 2) 100%,${m} ${f},${m} ${f},${m} ${f},${m} ${f};-webkit-mask-position:center,center,top left,top right,bottom right,bottom left;-webkit-mask-repeat:no-repeat}.number__inner{padding:${R} ${A};transform:scaleX(calc(1 / var(--scale-x))) translateX(calc(-1 * var(${C})))}:host > :not(.number){z-index:5}.section,.symbol{display:inline-block;position:relative;isolation:isolate}.section::after{content:'\200b';display:inline-block}.section--justify-left{transform-origin:center left}.section--justify-right{transform-origin:center right}.section > [inert],.symbol > [inert]{margin:0 !important;position:absolute !important;z-index:-1}.digit{display:inline-block;position:relative;--c:var(--current) + var(${j})}.digit__num,.number .section::after{padding:${R} 0}.digit__num{display:inline-block;--offset-raw:mod(var(--length) + var(--n) - mod(var(--c),var(--length)),var(--length));--offset:calc( var(--offset-raw) - var(--length) * round(down,var(--offset-raw) / (var(--length) / 2),1) );--y:clamp(-100%,var(--offset) * 100%,100%);transform:translateY(var(--y))}.digit__num[inert]{position:absolute;top:0;left:50%;transform:translateX(-50%) translateY(var(--y))}.digit:not(.is-spinning) .digit__num[inert]{display:none}.symbol__value{display:inline-block;mix-blend-mode:plus-lighter;white-space:pre}.section--justify-left .symbol > [inert]{left:0}.section--justify-right .symbol > [inert]{right:0}.animate-presence{opacity:calc(1 + var(${$}))}`,B=_.BROWSER?HTMLElement:class{},Q=V`:host{display:inline-block;direction:ltr;white-space:nowrap;line-height:${T} !important}span{display:inline-block}:host([data-will-change]) span{will-change:transform}.number,.digit{padding:${R} 0}.symbol{white-space:pre}`,tt=n=>`<span class="${n.type==="integer"||n.type==="fraction"?"digit":"symbol"}" part="${n.type==="integer"||n.type==="fraction"?`digit ${n.type}-digit`:`symbol ${n.type}`}">${n.value}</span>`,v=(n,t)=>`<span part="${t}">${n.reduce((e,i)=>e+tt(i),"")}</span>`,et=n=>G`<template shadowroot="open" shadowrootmode="open"
|
|
2
|
+
><style>
|
|
3
|
+
${Q}</style
|
|
4
|
+
><span role="img" aria-label="${n.valueAsString}"
|
|
5
|
+
>${v(n.pre,"left")}<span part="number" class="number"
|
|
6
|
+
>${v(n.integer,"integer")}${v(n.fraction,"fraction")}</span
|
|
7
|
+
>${v(n.post,"right")}</span
|
|
8
|
+
></template
|
|
9
|
+
><span
|
|
10
|
+
style="font-kerning: none; display: inline-block; line-height: ${T} !important; padding: ${f} 0;"
|
|
11
|
+
>${n.valueAsString}</span
|
|
12
|
+
>`,D=Z&&K&&J;let b;class H extends B{constructor(){super(),this.created=!1,this.batched=!1;const{animated:t,...e}=this.constructor.defaultProps;this._animated=this.computedAnimated=t,Object.assign(this,e)}get animated(){return this._animated}set animated(t){var e;this.animated!==t&&(this._animated=t,(e=this.shadowRoot)==null||e.getAnimations().forEach(i=>i.finish()))}set data(t){var r;if(t==null)return;const{pre:e,integer:i,fraction:s,post:a,value:o}=t;if(this.created){const c=this._data;this._data=t,this.computedTrend=typeof this.trend=="function"?this.trend(c.value,o):this.trend,this.computedAnimated=D&&this._animated&&(!this.respectMotionPreference||!(S!=null&&S.matches))&&X(this),(r=this.plugins)==null||r.forEach(d=>{var p;return(p=d.onUpdate)==null?void 0:p.call(d,t,c,this)}),this.batched||this.willUpdate(),this._pre.update(e),this._num.update({integer:i,fraction:s}),this._post.update(a),this.batched||this.didUpdate()}else{if(this._data=t,this.attachShadow({mode:"open"}),this._internals??(this._internals=this.attachInternals()),this._internals.role="img",typeof CSSStyleSheet<"u"&&this.shadowRoot.adoptedStyleSheets)b||(b=new CSSStyleSheet,b.replaceSync(L)),this.shadowRoot.adoptedStyleSheets=[b];else{const c=document.createElement("style");c.textContent=L,this.shadowRoot.appendChild(c)}this._pre=new N(this,e,{justify:"right",part:"left"}),this.shadowRoot.appendChild(this._pre.el),this._num=new it(this,i,s),this.shadowRoot.appendChild(this._num.el),this._post=new N(this,a,{justify:"left",part:"right"}),this.shadowRoot.appendChild(this._post.el),this.created=!0}this._internals.ariaLabel=t.valueAsString}willUpdate(){this._pre.willUpdate(),this._num.willUpdate(),this._post.willUpdate()}didUpdate(){if(!this.computedAnimated)return;this._abortAnimationsFinish?this._abortAnimationsFinish.abort():this.dispatchEvent(new Event("animationsstart")),this._pre.didUpdate(),this._num.didUpdate(),this._post.didUpdate();const t=new AbortController;Promise.all(this.shadowRoot.getAnimations().map(e=>e.finished)).then(()=>{t.signal.aborted||(this.dispatchEvent(new Event("animationsfinish")),this._abortAnimationsFinish=void 0)}),this._abortAnimationsFinish=t}}H.defaultProps={transformTiming:{duration:900,easing:"linear(0,.005,.019,.039,.066,.096,.129,.165,.202,.24,.278,.316,.354,.39,.426,.461,.494,.526,.557,.586,.614,.64,.665,.689,.711,.731,.751,.769,.786,.802,.817,.831,.844,.856,.867,.877,.887,.896,.904,.912,.919,.925,.931,.937,.942,.947,.951,.955,.959,.962,.965,.968,.971,.973,.976,.978,.98,.981,.983,.984,.986,.987,.988,.989,.99,.991,.992,.992,.993,.994,.994,.995,.995,.996,.996,.9963,.9967,.9969,.9972,.9975,.9977,.9979,.9981,.9982,.9984,.9985,.9987,.9988,.9989,1)"},spinTiming:void 0,opacityTiming:{duration:450,easing:"ease-out"},animated:!0,trend:(n,t)=>Math.sign(t-n),respectMotionPreference:!0,plugins:void 0,digits:void 0};class it{constructor(t,e,i,{className:s,...a}={}){this.flow=t,this._integer=new W(t,e,{justify:"right",part:"integer"}),this._fraction=new W(t,i,{justify:"left",part:"fraction"}),this._inner=u("span",{className:"number__inner"},[this._integer.el,this._fraction.el]),this.el=u("span",{...a,part:"number",className:`number ${s??""}`},[this._inner])}willUpdate(){this._prevWidth=this.el.offsetWidth,this._prevLeft=this.el.getBoundingClientRect().left,this._integer.willUpdate(),this._fraction.willUpdate()}update({integer:t,fraction:e}){this._integer.update(t),this._fraction.update(e)}didUpdate(){const t=this.el.getBoundingClientRect();this._integer.didUpdate(),this._fraction.didUpdate();const e=this._prevLeft-t.left,i=this.el.offsetWidth,s=this._prevWidth-i;this.el.style.setProperty("--width",String(i)),this.el.animate({[C]:[`${e}px`,"0px"],[U]:[s,0]},{...this.flow.transformTiming,composite:"accumulate"})}}class O{constructor(t,e,{justify:i,className:s,...a},o){this.flow=t,this.children=new Map,this.onCharRemove=c=>()=>{this.children.delete(c)},this.justify=i;const r=e.map(c=>this.addChar(c).el);this.el=u("span",{...a,className:`section section--justify-${i} ${s??""}`},o?o(r):r)}addChar(t,{startDigitsAtZero:e=!1,...i}={}){const s=t.type==="integer"||t.type==="fraction"?new M(this,t.type,e?0:t.value,t.pos,{...i,onRemove:this.onCharRemove(t.key)}):new st(this,t.type,t.value,{...i,onRemove:this.onCharRemove(t.key)});return this.children.set(t.key,s),s}unpop(t){t.el.removeAttribute("inert"),t.el.style.top="",t.el.style[this.justify]=""}pop(t){t.forEach(e=>{e.el.style.top=`${e.el.offsetTop}px`,e.el.style[this.justify]=`${I(e.el,this.justify)}px`}),t.forEach(e=>{e.el.setAttribute("inert",""),e.present=!1})}addNewAndUpdateExisting(t){const e=new Map,i=new Map,s=this.justify==="left",a=s?"prepend":"append";if(q(t,o=>{let r;this.children.has(o.key)?(r=this.children.get(o.key),i.set(o,r),this.unpop(r),r.present=!0):(r=this.addChar(o,{startDigitsAtZero:!0,animateIn:!0}),e.set(o,r)),this.el[a](r.el)},{reverse:s}),this.flow.computedAnimated){const o=this.el.getBoundingClientRect();e.forEach(r=>{r.willUpdate(o)})}e.forEach((o,r)=>{o.update(r.value)}),i.forEach((o,r)=>{o.update(r.value)})}willUpdate(){const t=this.el.getBoundingClientRect();this._prevOffset=t[this.justify],this.children.forEach(e=>e.willUpdate(t))}didUpdate(){const t=this.el.getBoundingClientRect();this.children.forEach(s=>s.didUpdate(t));const e=t[this.justify],i=this._prevOffset-e;i&&this.children.size&&this.el.animate({transform:[`translateX(${i}px)`,"none"]},{...this.flow.transformTiming,composite:"accumulate"})}}class W extends O{update(t){const e=new Map;this.children.forEach((i,s)=>{t.find(a=>a.key===s)||e.set(s,i),this.unpop(i)}),this.addNewAndUpdateExisting(t),e.forEach(i=>{i instanceof M&&i.update(0)}),this.pop(e)}}class N extends O{update(t){const e=new Map;this.children.forEach((i,s)=>{t.find(a=>a.key===s)||e.set(s,i)}),this.pop(e),this.addNewAndUpdateExisting(t)}}class k{constructor(t,e,{onRemove:i,animateIn:s=!1}={}){this.flow=t,this.el=e,this._present=!0,this._remove=()=>{var a;this.el.remove(),(a=this._onRemove)==null||a.call(this)},this.el.classList.add("animate-presence"),this.flow.computedAnimated&&s&&this.el.animate({[$]:[-.9999,0]},{...this.flow.opacityTiming,composite:"accumulate"}),this._onRemove=i}get present(){return this._present}set present(t){if(this._present!==t){if(this._present=t,t?this.el.removeAttribute("inert"):this.el.setAttribute("inert",""),!this.flow.computedAnimated){t||this._remove();return}this.el.style.setProperty("--_number-flow-d-opacity",t?"0":"-.999"),this.el.animate({[$]:t?[-.9999,0]:[.999,0]},{...this.flow.opacityTiming,composite:"accumulate"}),t?this.flow.removeEventListener("animationsfinish",this._remove):this.flow.addEventListener("animationsfinish",this._remove,{once:!0})}}}class F extends k{constructor(t,e,i,s){super(t.flow,i,s),this.section=t,this.value=e,this.el=i}}class M extends F{constructor(t,e,i,s,a){var d,p;const o=(((p=(d=t.flow.digits)==null?void 0:d[s])==null?void 0:p.max)??9)+1,r=Array.from({length:o}).map((E,g)=>{const y=u("span",{className:"digit__num"},[document.createTextNode(String(g))]);return g!==i&&y.setAttribute("inert",""),y.style.setProperty("--n",String(g)),y}),c=u("span",{part:`digit ${e}-digit`,className:"digit"},r);c.style.setProperty("--current",String(i)),c.style.setProperty("--length",String(o)),super(t,i,c,a),this.pos=s,this._onAnimationsFinish=()=>{this.el.classList.remove("is-spinning")},this._numbers=r,this.length=o}willUpdate(t){const e=this.el.getBoundingClientRect();this._prevValue=this.value;const i=e[this.section.justify]-t[this.section.justify],s=e.width/2;this._prevCenter=this.section.justify==="left"?i+s:i-s}update(t){this.el.style.setProperty("--current",String(t)),this._numbers.forEach((e,i)=>i===t?e.removeAttribute("inert"):e.setAttribute("inert","")),this.value=t}didUpdate(t){const e=this.el.getBoundingClientRect(),i=e[this.section.justify]-t[this.section.justify],s=e.width/2,a=this.section.justify==="left"?i+s:i-s,o=this._prevCenter-a;o&&this.el.animate({transform:[`translateX(${o}px)`,"none"]},{...this.flow.transformTiming,composite:"accumulate"});const r=this.getDelta();r&&(this.el.classList.add("is-spinning"),this.el.animate({[j]:[-r,0]},{...this.flow.spinTiming??this.flow.transformTiming,composite:"accumulate"}),this.flow.addEventListener("animationsfinish",this._onAnimationsFinish,{once:!0}))}getDelta(){var i;if(this.flow.plugins)for(const s of this.flow.plugins){const a=(i=s.getDelta)==null?void 0:i.call(s,this.value,this._prevValue,this);if(a!=null)return a}const t=this.value-this._prevValue,e=this.flow.computedTrend||Math.sign(t);return e<0&&this.value>this._prevValue?this.value-this.length-this._prevValue:e>0&&this.value<this._prevValue?this.length-this._prevValue+this.value:t}}class st extends F{constructor(t,e,i,s){const a=u("span",{className:"symbol__value",textContent:i});super(t,i,u("span",{part:`symbol ${e}`,className:"symbol"},[a]),s),this.type=e,this._children=new Map,this._onChildRemove=o=>()=>{this._children.delete(o)},this._children.set(i,new k(this.flow,a,{onRemove:this._onChildRemove(i)}))}willUpdate(t){if(this.type==="decimal")return;const e=this.el.getBoundingClientRect();this._prevOffset=e[this.section.justify]-t[this.section.justify]}update(t){if(this.value!==t){const e=this._children.get(this.value);e&&(e.present=!1);const i=this._children.get(t);if(i)i.present=!0;else{const s=u("span",{className:"symbol__value",textContent:t});this.el.appendChild(s),this._children.set(t,new k(this.flow,s,{animateIn:!0,onRemove:this._onChildRemove(t)}))}}this.value=t}didUpdate(t){if(this.type==="decimal")return;const i=this.el.getBoundingClientRect()[this.section.justify]-t[this.section.justify],s=this._prevOffset-i;s&&this.el.animate({transform:[`translateX(${s}px)`,"none"]},{...this.flow.transformTiming,composite:"accumulate"})}}exports.Digit=M;exports.NumberFlowLite=H;exports.ServerSafeHTMLElement=B;exports.canAnimate=D;exports.define=z;exports.formatToData=Y;exports.prefersReducedMotion=S;exports.renderInnerHTML=et;
|
|
@@ -1,37 +1,78 @@
|
|
|
1
|
-
import { BROWSER as
|
|
2
|
-
|
|
1
|
+
import { BROWSER as _ } from "esm-env";
|
|
2
|
+
import "./plugins.mjs";
|
|
3
|
+
const u = (n, t, e) => {
|
|
3
4
|
const i = document.createElement(n), [s, a] = Array.isArray(t) ? [void 0, t] : [t, e];
|
|
4
|
-
return s && Object.assign(i, s), a == null || a.forEach((
|
|
5
|
-
},
|
|
5
|
+
return s && Object.assign(i, s), a == null || a.forEach((o) => i.appendChild(o)), i;
|
|
6
|
+
}, F = (n, t) => {
|
|
6
7
|
var e;
|
|
7
8
|
return t === "left" ? n.offsetLeft : (((e = n.offsetParent instanceof HTMLElement ? n.offsetParent : null) == null ? void 0 : e.offsetWidth) ?? 0) - n.offsetWidth - n.offsetLeft;
|
|
8
|
-
},
|
|
9
|
-
|
|
9
|
+
}, H = (n) => n.offsetWidth > 0 && n.offsetHeight > 0, st = (n, t) => {
|
|
10
|
+
_ && customElements.get(n) !== t && customElements.define(n, t);
|
|
10
11
|
};
|
|
11
|
-
function
|
|
12
|
+
function X(n, t, { reverse: e = !1 } = {}) {
|
|
12
13
|
const i = n.length;
|
|
13
14
|
for (let s = e ? i - 1 : 0; e ? s >= 0 : s < i; e ? s-- : s++)
|
|
14
15
|
t(n[s], s);
|
|
15
16
|
}
|
|
16
|
-
|
|
17
|
+
function nt(n, t, e, i) {
|
|
18
|
+
const s = t.formatToParts(n);
|
|
19
|
+
e && s.unshift({ type: "prefix", value: e }), i && s.push({ type: "suffix", value: i });
|
|
20
|
+
const a = [], o = [], r = [], c = [], d = {}, p = (h) => `${h}:${d[h] = (d[h] ?? -1) + 1}`;
|
|
21
|
+
let C = "", g = !1, y = !1;
|
|
22
|
+
for (const h of s) {
|
|
23
|
+
C += h.value;
|
|
24
|
+
const l = h.type === "minusSign" || h.type === "plusSign" ? "sign" : h.type;
|
|
25
|
+
l === "integer" ? (g = !0, o.push(...h.value.split("").map((x) => ({ type: l, value: parseInt(x) })))) : l === "group" ? o.push({ type: l, value: h.value }) : l === "decimal" ? (y = !0, r.push({ type: l, value: h.value, key: p(l) })) : l === "fraction" ? r.push(...h.value.split("").map((x) => ({
|
|
26
|
+
type: l,
|
|
27
|
+
value: parseInt(x),
|
|
28
|
+
key: p(l),
|
|
29
|
+
pos: -1 - d[l]
|
|
30
|
+
}))) : (g || y ? c : a).push({
|
|
31
|
+
type: l,
|
|
32
|
+
value: h.value,
|
|
33
|
+
key: p(l)
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
const T = [];
|
|
37
|
+
for (let h = o.length - 1; h >= 0; h--) {
|
|
38
|
+
const l = o[h];
|
|
39
|
+
T.unshift(l.type === "integer" ? {
|
|
40
|
+
...l,
|
|
41
|
+
key: p(l.type),
|
|
42
|
+
pos: d[l.type]
|
|
43
|
+
} : {
|
|
44
|
+
...l,
|
|
45
|
+
key: p(l.type)
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
return {
|
|
49
|
+
pre: a,
|
|
50
|
+
integer: T,
|
|
51
|
+
fraction: r,
|
|
52
|
+
post: c,
|
|
53
|
+
valueAsString: C,
|
|
54
|
+
value: typeof n == "string" ? parseFloat(n) : n
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
const I = String.raw, V = String.raw, O = _ && typeof CSS < "u" && CSS.supports && CSS.supports("animation-timing-function", "linear(1,2)"), z = _ && typeof CSS < "u" && CSS.supports && CSS.supports("line-height", "mod(1,1)"), A = _ && typeof matchMedia < "u" ? matchMedia("(prefers-reduced-motion: reduce)") : null, $ = "--_number-flow-d-opacity", U = "--_number-flow-d-width", S = "--_number-flow-dx", j = "--_number-flow-d", Y = (() => {
|
|
17
58
|
try {
|
|
18
59
|
return CSS.registerProperty({
|
|
19
|
-
name:
|
|
60
|
+
name: $,
|
|
20
61
|
syntax: "<number>",
|
|
21
62
|
inherits: !1,
|
|
22
63
|
initialValue: "0"
|
|
23
64
|
}), CSS.registerProperty({
|
|
24
|
-
name:
|
|
65
|
+
name: S,
|
|
25
66
|
syntax: "<length>",
|
|
26
67
|
inherits: !0,
|
|
27
68
|
initialValue: "0px"
|
|
28
69
|
}), CSS.registerProperty({
|
|
29
|
-
name:
|
|
70
|
+
name: U,
|
|
30
71
|
syntax: "<number>",
|
|
31
72
|
inherits: !1,
|
|
32
73
|
initialValue: "0"
|
|
33
74
|
}), CSS.registerProperty({
|
|
34
|
-
name:
|
|
75
|
+
name: j,
|
|
35
76
|
syntax: "<number>",
|
|
36
77
|
inherits: !0,
|
|
37
78
|
initialValue: "0"
|
|
@@ -39,24 +80,26 @@ const D = String.raw, M = String.raw, H = m && typeof CSS < "u" && CSS.supports
|
|
|
39
80
|
} catch {
|
|
40
81
|
return !1;
|
|
41
82
|
}
|
|
42
|
-
})(),
|
|
43
|
-
},
|
|
83
|
+
})(), P = "var(--number-flow-char-height, 1em)", f = "var(--number-flow-mask-height, 0.25em)", k = `calc(${f} / 2)`, E = "var(--number-flow-mask-width, 0.5em)", m = `calc(${E} / var(--scale-x))`, w = "#000 0, transparent 71%", M = V`:host{display:inline-block;direction:ltr;white-space:nowrap;isolation:isolate;line-height:${P} !important}.number,.number__inner{display:inline-block;transform-origin:left top}:host([data-will-change]) :is(.number,.number__inner,.section,.digit,.digit__num,.symbol){will-change:transform}.number{--scale-x:calc(1 + var(${U}) / var(--width));transform:translateX(var(${S})) scaleX(var(--scale-x));margin:0 calc(-1 * ${E});position:relative;-webkit-mask-image:linear-gradient(to right,transparent 0,#000 ${m},#000 calc(100% - ${m}),transparent ),linear-gradient(to bottom,transparent 0,#000 ${f},#000 calc(100% - ${f}),transparent 100% ),radial-gradient(at bottom right,${w}),radial-gradient(at bottom left,${w}),radial-gradient(at top left,${w}),radial-gradient(at top right,${w});-webkit-mask-size:100% calc(100% - ${f} * 2),calc(100% - ${m} * 2) 100%,${m} ${f},${m} ${f},${m} ${f},${m} ${f};-webkit-mask-position:center,center,top left,top right,bottom right,bottom left;-webkit-mask-repeat:no-repeat}.number__inner{padding:${k} ${E};transform:scaleX(calc(1 / var(--scale-x))) translateX(calc(-1 * var(${S})))}:host > :not(.number){z-index:5}.section,.symbol{display:inline-block;position:relative;isolation:isolate}.section::after{content:'\200b';display:inline-block}.section--justify-left{transform-origin:center left}.section--justify-right{transform-origin:center right}.section > [inert],.symbol > [inert]{margin:0 !important;position:absolute !important;z-index:-1}.digit{display:inline-block;position:relative;--c:var(--current) + var(${j})}.digit__num,.number .section::after{padding:${k} 0}.digit__num{display:inline-block;--offset-raw:mod(var(--length) + var(--n) - mod(var(--c),var(--length)),var(--length));--offset:calc( var(--offset-raw) - var(--length) * round(down,var(--offset-raw) / (var(--length) / 2),1) );--y:clamp(-100%,var(--offset) * 100%,100%);transform:translateY(var(--y))}.digit__num[inert]{position:absolute;top:0;left:50%;transform:translateX(-50%) translateY(var(--y))}.digit:not(.is-spinning) .digit__num[inert]{display:none}.symbol__value{display:inline-block;mix-blend-mode:plus-lighter;white-space:pre}.section--justify-left .symbol > [inert]{left:0}.section--justify-right .symbol > [inert]{right:0}.animate-presence{opacity:calc(1 + var(${$}))}`, G = _ ? HTMLElement : class {
|
|
84
|
+
}, K = V`:host{display:inline-block;direction:ltr;white-space:nowrap;line-height:${P} !important}span{display:inline-block}:host([data-will-change]) span{will-change:transform}.number,.digit{padding:${k} 0}.symbol{white-space:pre}`, Z = (n) => `<span class="${n.type === "integer" || n.type === "fraction" ? "digit" : "symbol"}" part="${n.type === "integer" || n.type === "fraction" ? `digit ${n.type}-digit` : `symbol ${n.type}`}">${n.value}</span>`, v = (n, t) => `<span part="${t}">${n.reduce((e, i) => e + Z(i), "")}</span>`, at = (n) => (
|
|
44
85
|
// shadowroot="open" non-standard attribute for old Chrome:
|
|
45
|
-
|
|
86
|
+
I`<template shadowroot="open" shadowrootmode="open"
|
|
46
87
|
><style>
|
|
47
|
-
${
|
|
48
|
-
|
|
49
|
-
>${
|
|
50
|
-
|
|
88
|
+
${K}</style
|
|
89
|
+
><span role="img" aria-label="${n.valueAsString}"
|
|
90
|
+
>${v(n.pre, "left")}<span part="number" class="number"
|
|
91
|
+
>${v(n.integer, "integer")}${v(n.fraction, "fraction")}</span
|
|
92
|
+
>${v(n.post, "right")}</span
|
|
93
|
+
></template
|
|
51
94
|
><span
|
|
52
|
-
style="font-kerning: none; display: inline-block; line-height: ${
|
|
95
|
+
style="font-kerning: none; display: inline-block; line-height: ${P} !important; padding: ${f} 0;"
|
|
53
96
|
>${n.valueAsString}</span
|
|
54
97
|
>`
|
|
55
|
-
),
|
|
56
|
-
let
|
|
57
|
-
class
|
|
98
|
+
), q = z && O && Y;
|
|
99
|
+
let b;
|
|
100
|
+
class J extends G {
|
|
58
101
|
constructor() {
|
|
59
|
-
super(), this.created = !1, this.
|
|
102
|
+
super(), this.created = !1, this.batched = !1;
|
|
60
103
|
const { animated: t, ...e } = this.constructor.defaultProps;
|
|
61
104
|
this._animated = this.computedAnimated = t, Object.assign(this, e);
|
|
62
105
|
}
|
|
@@ -67,38 +110,47 @@ class G extends O {
|
|
|
67
110
|
var e;
|
|
68
111
|
this.animated !== t && (this._animated = t, (e = this.shadowRoot) == null || e.getAnimations().forEach((i) => i.finish()));
|
|
69
112
|
}
|
|
113
|
+
/**
|
|
114
|
+
* @internal
|
|
115
|
+
*/
|
|
70
116
|
set data(t) {
|
|
71
|
-
var
|
|
117
|
+
var r;
|
|
72
118
|
if (t == null)
|
|
73
119
|
return;
|
|
74
|
-
const { pre: e, integer: i, fraction: s, post: a, value:
|
|
120
|
+
const { pre: e, integer: i, fraction: s, post: a, value: o } = t;
|
|
75
121
|
if (this.created) {
|
|
76
|
-
const
|
|
77
|
-
this._data = t, this.computedTrend = typeof this.trend == "function" ? this.trend(
|
|
78
|
-
|
|
79
|
-
var
|
|
80
|
-
return (
|
|
81
|
-
}), this.
|
|
122
|
+
const c = this._data;
|
|
123
|
+
this._data = t, this.computedTrend = typeof this.trend == "function" ? this.trend(c.value, o) : this.trend, this.computedAnimated = q && this._animated && (!this.respectMotionPreference || !(A != null && A.matches)) && // https://github.com/barvian/number-flow/issues/9
|
|
124
|
+
H(this), (r = this.plugins) == null || r.forEach((d) => {
|
|
125
|
+
var p;
|
|
126
|
+
return (p = d.onUpdate) == null ? void 0 : p.call(d, t, c, this);
|
|
127
|
+
}), this.batched || this.willUpdate(), this._pre.update(e), this._num.update({ integer: i, fraction: s }), this._post.update(a), this.batched || this.didUpdate();
|
|
82
128
|
} else {
|
|
83
|
-
if (this._data = t, this.attachShadow({ mode: "open" }), typeof CSSStyleSheet < "u" && this.shadowRoot.adoptedStyleSheets)
|
|
84
|
-
|
|
129
|
+
if (this._data = t, this.attachShadow({ mode: "open" }), this._internals ?? (this._internals = this.attachInternals()), this._internals.role = "img", typeof CSSStyleSheet < "u" && this.shadowRoot.adoptedStyleSheets)
|
|
130
|
+
b || (b = new CSSStyleSheet(), b.replaceSync(M)), this.shadowRoot.adoptedStyleSheets = [b];
|
|
85
131
|
else {
|
|
86
|
-
const
|
|
87
|
-
|
|
132
|
+
const c = document.createElement("style");
|
|
133
|
+
c.textContent = M, this.shadowRoot.appendChild(c);
|
|
88
134
|
}
|
|
89
|
-
this._pre = new
|
|
135
|
+
this._pre = new N(this, e, {
|
|
90
136
|
justify: "right",
|
|
91
137
|
part: "left"
|
|
92
|
-
}), this.shadowRoot.appendChild(this._pre.el), this._num = new
|
|
138
|
+
}), this.shadowRoot.appendChild(this._pre.el), this._num = new Q(this, i, s), this.shadowRoot.appendChild(this._num.el), this._post = new N(this, a, {
|
|
93
139
|
justify: "left",
|
|
94
140
|
part: "right"
|
|
95
|
-
}), this.shadowRoot.appendChild(this._post.el);
|
|
141
|
+
}), this.shadowRoot.appendChild(this._post.el), this.created = !0;
|
|
96
142
|
}
|
|
97
|
-
this.
|
|
143
|
+
this._internals.ariaLabel = t.valueAsString;
|
|
98
144
|
}
|
|
145
|
+
/**
|
|
146
|
+
* @internal
|
|
147
|
+
*/
|
|
99
148
|
willUpdate() {
|
|
100
149
|
this._pre.willUpdate(), this._num.willUpdate(), this._post.willUpdate();
|
|
101
150
|
}
|
|
151
|
+
/**
|
|
152
|
+
* @internal
|
|
153
|
+
*/
|
|
102
154
|
didUpdate() {
|
|
103
155
|
if (!this.computedAnimated)
|
|
104
156
|
return;
|
|
@@ -109,7 +161,7 @@ class G extends O {
|
|
|
109
161
|
}), this._abortAnimationsFinish = t;
|
|
110
162
|
}
|
|
111
163
|
}
|
|
112
|
-
|
|
164
|
+
J.defaultProps = {
|
|
113
165
|
transformTiming: {
|
|
114
166
|
duration: 900,
|
|
115
167
|
// Make sure to keep this minified:
|
|
@@ -123,17 +175,17 @@ G.defaultProps = {
|
|
|
123
175
|
plugins: void 0,
|
|
124
176
|
digits: void 0
|
|
125
177
|
};
|
|
126
|
-
class
|
|
178
|
+
class Q {
|
|
127
179
|
constructor(t, e, i, { className: s, ...a } = {}) {
|
|
128
|
-
this.flow = t, this._integer = new
|
|
180
|
+
this.flow = t, this._integer = new L(t, e, {
|
|
129
181
|
justify: "right",
|
|
130
182
|
part: "integer"
|
|
131
|
-
}), this._fraction = new
|
|
183
|
+
}), this._fraction = new L(t, i, {
|
|
132
184
|
justify: "left",
|
|
133
185
|
part: "fraction"
|
|
134
|
-
}), this._inner =
|
|
186
|
+
}), this._inner = u("span", {
|
|
135
187
|
className: "number__inner"
|
|
136
|
-
}, [this._integer.el, this._fraction.el]), this.el =
|
|
188
|
+
}, [this._integer.el, this._fraction.el]), this.el = u("span", {
|
|
137
189
|
...a,
|
|
138
190
|
part: "number",
|
|
139
191
|
className: `number ${s ?? ""}`
|
|
@@ -150,30 +202,30 @@ class Z {
|
|
|
150
202
|
this._integer.didUpdate(), this._fraction.didUpdate();
|
|
151
203
|
const e = this._prevLeft - t.left, i = this.el.offsetWidth, s = this._prevWidth - i;
|
|
152
204
|
this.el.style.setProperty("--width", String(i)), this.el.animate({
|
|
153
|
-
[
|
|
154
|
-
[
|
|
205
|
+
[S]: [`${e}px`, "0px"],
|
|
206
|
+
[U]: [s, 0]
|
|
155
207
|
}, {
|
|
156
208
|
...this.flow.transformTiming,
|
|
157
209
|
composite: "accumulate"
|
|
158
210
|
});
|
|
159
211
|
}
|
|
160
212
|
}
|
|
161
|
-
class
|
|
162
|
-
constructor(t, e, { justify: i, className: s, ...a },
|
|
163
|
-
this.flow = t, this.children = /* @__PURE__ */ new Map(), this.onCharRemove = (
|
|
164
|
-
this.children.delete(
|
|
213
|
+
class W {
|
|
214
|
+
constructor(t, e, { justify: i, className: s, ...a }, o) {
|
|
215
|
+
this.flow = t, this.children = /* @__PURE__ */ new Map(), this.onCharRemove = (c) => () => {
|
|
216
|
+
this.children.delete(c);
|
|
165
217
|
}, this.justify = i;
|
|
166
|
-
const
|
|
167
|
-
this.el =
|
|
218
|
+
const r = e.map((c) => this.addChar(c).el);
|
|
219
|
+
this.el = u("span", {
|
|
168
220
|
...a,
|
|
169
221
|
className: `section section--justify-${i} ${s ?? ""}`
|
|
170
|
-
},
|
|
222
|
+
}, o ? o(r) : r);
|
|
171
223
|
}
|
|
172
224
|
addChar(t, { startDigitsAtZero: e = !1, ...i } = {}) {
|
|
173
|
-
const s = t.type === "integer" || t.type === "fraction" ? new
|
|
225
|
+
const s = t.type === "integer" || t.type === "fraction" ? new D(this, t.type, e ? 0 : t.value, t.pos, {
|
|
174
226
|
...i,
|
|
175
227
|
onRemove: this.onCharRemove(t.key)
|
|
176
|
-
}) : new
|
|
228
|
+
}) : new tt(this, t.type, t.value, {
|
|
177
229
|
...i,
|
|
178
230
|
onRemove: this.onCharRemove(t.key)
|
|
179
231
|
});
|
|
@@ -184,26 +236,26 @@ class P {
|
|
|
184
236
|
}
|
|
185
237
|
pop(t) {
|
|
186
238
|
t.forEach((e) => {
|
|
187
|
-
e.el.style.top = `${e.el.offsetTop}px`, e.el.style[this.justify] = `${
|
|
239
|
+
e.el.style.top = `${e.el.offsetTop}px`, e.el.style[this.justify] = `${F(e.el, this.justify)}px`;
|
|
188
240
|
}), t.forEach((e) => {
|
|
189
241
|
e.el.setAttribute("inert", ""), e.present = !1;
|
|
190
242
|
});
|
|
191
243
|
}
|
|
192
244
|
addNewAndUpdateExisting(t) {
|
|
193
245
|
const e = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Map(), s = this.justify === "left", a = s ? "prepend" : "append";
|
|
194
|
-
if (
|
|
195
|
-
let
|
|
196
|
-
this.children.has(
|
|
246
|
+
if (X(t, (o) => {
|
|
247
|
+
let r;
|
|
248
|
+
this.children.has(o.key) ? (r = this.children.get(o.key), i.set(o, r), this.unpop(r), r.present = !0) : (r = this.addChar(o, { startDigitsAtZero: !0, animateIn: !0 }), e.set(o, r)), this.el[a](r.el);
|
|
197
249
|
}, { reverse: s }), this.flow.computedAnimated) {
|
|
198
|
-
const
|
|
199
|
-
e.forEach((
|
|
200
|
-
|
|
250
|
+
const o = this.el.getBoundingClientRect();
|
|
251
|
+
e.forEach((r) => {
|
|
252
|
+
r.willUpdate(o);
|
|
201
253
|
});
|
|
202
254
|
}
|
|
203
|
-
e.forEach((
|
|
204
|
-
|
|
205
|
-
}), i.forEach((
|
|
206
|
-
|
|
255
|
+
e.forEach((o, r) => {
|
|
256
|
+
o.update(r.value);
|
|
257
|
+
}), i.forEach((o, r) => {
|
|
258
|
+
o.update(r.value);
|
|
207
259
|
});
|
|
208
260
|
}
|
|
209
261
|
willUpdate() {
|
|
@@ -222,17 +274,17 @@ class P {
|
|
|
222
274
|
});
|
|
223
275
|
}
|
|
224
276
|
}
|
|
225
|
-
class
|
|
277
|
+
class L extends W {
|
|
226
278
|
update(t) {
|
|
227
279
|
const e = /* @__PURE__ */ new Map();
|
|
228
280
|
this.children.forEach((i, s) => {
|
|
229
281
|
t.find((a) => a.key === s) || e.set(s, i), this.unpop(i);
|
|
230
282
|
}), this.addNewAndUpdateExisting(t), e.forEach((i) => {
|
|
231
|
-
i instanceof
|
|
283
|
+
i instanceof D && i.update(0);
|
|
232
284
|
}), this.pop(e);
|
|
233
285
|
}
|
|
234
286
|
}
|
|
235
|
-
class
|
|
287
|
+
class N extends W {
|
|
236
288
|
update(t) {
|
|
237
289
|
const e = /* @__PURE__ */ new Map();
|
|
238
290
|
this.children.forEach((i, s) => {
|
|
@@ -240,13 +292,13 @@ class T extends P {
|
|
|
240
292
|
}), this.pop(e), this.addNewAndUpdateExisting(t);
|
|
241
293
|
}
|
|
242
294
|
}
|
|
243
|
-
class
|
|
295
|
+
class R {
|
|
244
296
|
constructor(t, e, { onRemove: i, animateIn: s = !1 } = {}) {
|
|
245
297
|
this.flow = t, this.el = e, this._present = !0, this._remove = () => {
|
|
246
298
|
var a;
|
|
247
299
|
this.el.remove(), (a = this._onRemove) == null || a.call(this);
|
|
248
300
|
}, this.el.classList.add("animate-presence"), this.flow.computedAnimated && s && this.el.animate({
|
|
249
|
-
[
|
|
301
|
+
[$]: [-0.9999, 0]
|
|
250
302
|
}, {
|
|
251
303
|
...this.flow.opacityTiming,
|
|
252
304
|
composite: "accumulate"
|
|
@@ -262,7 +314,7 @@ class E {
|
|
|
262
314
|
return;
|
|
263
315
|
}
|
|
264
316
|
this.el.style.setProperty("--_number-flow-d-opacity", t ? "0" : "-.999"), this.el.animate({
|
|
265
|
-
[
|
|
317
|
+
[$]: t ? [-0.9999, 0] : [0.999, 0]
|
|
266
318
|
}, {
|
|
267
319
|
...this.flow.opacityTiming,
|
|
268
320
|
composite: "accumulate"
|
|
@@ -272,26 +324,26 @@ class E {
|
|
|
272
324
|
}
|
|
273
325
|
}
|
|
274
326
|
}
|
|
275
|
-
class
|
|
327
|
+
class B extends R {
|
|
276
328
|
constructor(t, e, i, s) {
|
|
277
329
|
super(t.flow, i, s), this.section = t, this.value = e, this.el = i;
|
|
278
330
|
}
|
|
279
331
|
}
|
|
280
|
-
class
|
|
332
|
+
class D extends B {
|
|
281
333
|
constructor(t, e, i, s, a) {
|
|
282
|
-
var
|
|
283
|
-
const
|
|
284
|
-
const
|
|
285
|
-
document.createTextNode(String(
|
|
334
|
+
var d, p;
|
|
335
|
+
const o = (((p = (d = t.flow.digits) == null ? void 0 : d[s]) == null ? void 0 : p.max) ?? 9) + 1, r = Array.from({ length: o }).map((C, g) => {
|
|
336
|
+
const y = u("span", { className: "digit__num" }, [
|
|
337
|
+
document.createTextNode(String(g))
|
|
286
338
|
]);
|
|
287
|
-
return
|
|
288
|
-
}),
|
|
339
|
+
return g !== i && y.setAttribute("inert", ""), y.style.setProperty("--n", String(g)), y;
|
|
340
|
+
}), c = u("span", {
|
|
289
341
|
part: `digit ${e}-digit`,
|
|
290
342
|
className: "digit"
|
|
291
|
-
},
|
|
292
|
-
|
|
343
|
+
}, r);
|
|
344
|
+
c.style.setProperty("--current", String(i)), c.style.setProperty("--length", String(o)), super(t, i, c, a), this.pos = s, this._onAnimationsFinish = () => {
|
|
293
345
|
this.el.classList.remove("is-spinning");
|
|
294
|
-
}, this._numbers =
|
|
346
|
+
}, this._numbers = r, this.length = o;
|
|
295
347
|
}
|
|
296
348
|
willUpdate(t) {
|
|
297
349
|
const e = this.el.getBoundingClientRect();
|
|
@@ -303,16 +355,16 @@ class L extends N {
|
|
|
303
355
|
this.el.style.setProperty("--current", String(t)), this._numbers.forEach((e, i) => i === t ? e.removeAttribute("inert") : e.setAttribute("inert", "")), this.value = t;
|
|
304
356
|
}
|
|
305
357
|
didUpdate(t) {
|
|
306
|
-
const e = this.el.getBoundingClientRect(), i = e[this.section.justify] - t[this.section.justify], s = e.width / 2, a = this.section.justify === "left" ? i + s : i - s,
|
|
307
|
-
|
|
308
|
-
transform: [`translateX(${
|
|
358
|
+
const e = this.el.getBoundingClientRect(), i = e[this.section.justify] - t[this.section.justify], s = e.width / 2, a = this.section.justify === "left" ? i + s : i - s, o = this._prevCenter - a;
|
|
359
|
+
o && this.el.animate({
|
|
360
|
+
transform: [`translateX(${o}px)`, "none"]
|
|
309
361
|
}, {
|
|
310
362
|
...this.flow.transformTiming,
|
|
311
363
|
composite: "accumulate"
|
|
312
364
|
});
|
|
313
|
-
const
|
|
314
|
-
|
|
315
|
-
[
|
|
365
|
+
const r = this.getDelta();
|
|
366
|
+
r && (this.el.classList.add("is-spinning"), this.el.animate({
|
|
367
|
+
[j]: [-r, 0]
|
|
316
368
|
}, {
|
|
317
369
|
...this.flow.spinTiming ?? this.flow.transformTiming,
|
|
318
370
|
composite: "accumulate"
|
|
@@ -330,18 +382,18 @@ class L extends N {
|
|
|
330
382
|
return e < 0 && this.value > this._prevValue ? this.value - this.length - this._prevValue : e > 0 && this.value < this._prevValue ? this.length - this._prevValue + this.value : t;
|
|
331
383
|
}
|
|
332
384
|
}
|
|
333
|
-
class
|
|
385
|
+
class tt extends B {
|
|
334
386
|
constructor(t, e, i, s) {
|
|
335
|
-
const a =
|
|
387
|
+
const a = u("span", {
|
|
336
388
|
className: "symbol__value",
|
|
337
389
|
textContent: i
|
|
338
390
|
});
|
|
339
|
-
super(t, i,
|
|
391
|
+
super(t, i, u("span", {
|
|
340
392
|
part: `symbol ${e}`,
|
|
341
393
|
className: "symbol"
|
|
342
|
-
}, [a]), s), this.type = e, this._children = /* @__PURE__ */ new Map(), this._onChildRemove = (
|
|
343
|
-
this._children.delete(
|
|
344
|
-
}, this._children.set(i, new
|
|
394
|
+
}, [a]), s), this.type = e, this._children = /* @__PURE__ */ new Map(), this._onChildRemove = (o) => () => {
|
|
395
|
+
this._children.delete(o);
|
|
396
|
+
}, this._children.set(i, new R(this.flow, a, {
|
|
345
397
|
onRemove: this._onChildRemove(i)
|
|
346
398
|
}));
|
|
347
399
|
}
|
|
@@ -354,15 +406,16 @@ class q extends N {
|
|
|
354
406
|
update(t) {
|
|
355
407
|
if (this.value !== t) {
|
|
356
408
|
const e = this._children.get(this.value);
|
|
357
|
-
|
|
358
|
-
|
|
409
|
+
e && (e.present = !1);
|
|
410
|
+
const i = this._children.get(t);
|
|
411
|
+
if (i)
|
|
359
412
|
i.present = !0;
|
|
360
|
-
|
|
361
|
-
const
|
|
413
|
+
else {
|
|
414
|
+
const s = u("span", {
|
|
362
415
|
className: "symbol__value",
|
|
363
416
|
textContent: t
|
|
364
417
|
});
|
|
365
|
-
this.el.appendChild(
|
|
418
|
+
this.el.appendChild(s), this._children.set(t, new R(this.flow, s, {
|
|
366
419
|
animateIn: !0,
|
|
367
420
|
onRemove: this._onChildRemove(t)
|
|
368
421
|
}));
|
|
@@ -379,25 +432,13 @@ class q extends N {
|
|
|
379
432
|
}, { ...this.flow.transformTiming, composite: "accumulate" });
|
|
380
433
|
}
|
|
381
434
|
}
|
|
382
|
-
const J = (n, t) => n == null ? t : t == null ? n : Math.max(n, t), S = /* @__PURE__ */ new WeakMap(), it = {
|
|
383
|
-
onUpdate(n, t, e) {
|
|
384
|
-
if (S.set(e, void 0), !e.computedTrend)
|
|
385
|
-
return;
|
|
386
|
-
const i = t.integer.concat(t.fraction).filter((o) => o.type === "integer" || o.type === "fraction"), s = n.integer.concat(n.fraction).filter((o) => o.type === "integer" || o.type === "fraction"), a = i.find((o) => !s.find((l) => l.pos === o.pos && l.value === o.value)), r = s.find((o) => !i.find((l) => o.pos === l.pos && o.value === l.value));
|
|
387
|
-
S.set(e, J(a == null ? void 0 : a.pos, r == null ? void 0 : r.pos));
|
|
388
|
-
},
|
|
389
|
-
getDelta(n, t, e) {
|
|
390
|
-
const i = n - t, s = S.get(e.flow);
|
|
391
|
-
if (!i && s != null && s >= e.pos)
|
|
392
|
-
return e.length * e.flow.computedTrend;
|
|
393
|
-
}
|
|
394
|
-
};
|
|
395
435
|
export {
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
436
|
+
D,
|
|
437
|
+
J as N,
|
|
438
|
+
G as S,
|
|
439
|
+
q as c,
|
|
440
|
+
st as d,
|
|
441
|
+
nt as f,
|
|
442
|
+
A as p,
|
|
443
|
+
at as r
|
|
403
444
|
};
|
package/dist/lite.d.ts
CHANGED
|
@@ -2,6 +2,11 @@ import { type HTMLProps, type Justify } from './util/dom';
|
|
|
2
2
|
import { type KeyedDigitPart, type KeyedNumberPart, type KeyedSymbolPart, type Data } from './formatter';
|
|
3
3
|
import { ServerSafeHTMLElement } from './ssr';
|
|
4
4
|
import type { Plugin } from './plugins';
|
|
5
|
+
export { define } from './util/dom';
|
|
6
|
+
export { prefersReducedMotion } from './styles';
|
|
7
|
+
export { renderInnerHTML } from './ssr';
|
|
8
|
+
export * from './plugins';
|
|
9
|
+
export * from './formatter';
|
|
5
10
|
export declare const canAnimate: boolean;
|
|
6
11
|
export type Trend = number | ((oldValue: number, value: number) => number);
|
|
7
12
|
export type DigitOptions = {
|
|
@@ -18,9 +23,12 @@ export interface Props {
|
|
|
18
23
|
plugins?: Plugin[];
|
|
19
24
|
digits: Digits | undefined;
|
|
20
25
|
}
|
|
21
|
-
export interface NumberFlowLite extends Props {
|
|
26
|
+
export default interface NumberFlowLite extends Props {
|
|
22
27
|
}
|
|
23
|
-
|
|
28
|
+
/**
|
|
29
|
+
* @internal Used for framework wrappers
|
|
30
|
+
*/
|
|
31
|
+
export default class NumberFlowLite extends ServerSafeHTMLElement implements Props {
|
|
24
32
|
/**
|
|
25
33
|
* Use `private _private` properties instead of `#private` to avoid # polyfill and
|
|
26
34
|
* reduce bundle size. Also, use `readonly` properties instead of getters to save on bundle
|
|
@@ -38,11 +46,24 @@ export declare class NumberFlowLite extends ServerSafeHTMLElement implements Pro
|
|
|
38
46
|
private _post?;
|
|
39
47
|
readonly computedTrend?: number;
|
|
40
48
|
readonly computedAnimated: boolean;
|
|
49
|
+
private _internals?;
|
|
41
50
|
private _data?;
|
|
42
|
-
|
|
51
|
+
/**
|
|
52
|
+
* @internal
|
|
53
|
+
*/
|
|
54
|
+
batched: boolean;
|
|
55
|
+
/**
|
|
56
|
+
* @internal
|
|
57
|
+
*/
|
|
43
58
|
set data(data: Data | undefined);
|
|
59
|
+
/**
|
|
60
|
+
* @internal
|
|
61
|
+
*/
|
|
44
62
|
willUpdate(): void;
|
|
45
63
|
private _abortAnimationsFinish?;
|
|
64
|
+
/**
|
|
65
|
+
* @internal
|
|
66
|
+
*/
|
|
46
67
|
didUpdate(): void;
|
|
47
68
|
}
|
|
48
69
|
type SectionProps = {
|
|
@@ -114,4 +135,3 @@ declare class Sym extends Char<KeyedSymbolPart> {
|
|
|
114
135
|
update(value: KeyedSymbolPart['value']): void;
|
|
115
136
|
didUpdate(parentRect: DOMRect): void;
|
|
116
137
|
}
|
|
117
|
-
export {};
|
package/dist/lite.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("./lite-B614HEDD.js"),t=require("./plugins.js");exports.Digit=e.Digit;exports.canAnimate=e.canAnimate;exports.default=e.NumberFlowLite;exports.define=e.define;exports.formatToData=e.formatToData;exports.prefersReducedMotion=e.prefersReducedMotion;exports.renderInnerHTML=e.renderInnerHTML;exports.continuous=t.continuous;
|
package/dist/lite.mjs
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { D as r, c as o, N as n, d as s, f as t, p as f, r as d } from "./lite-D-JHjRWt.mjs";
|
|
2
|
+
import { continuous as c } from "./plugins.mjs";
|
|
3
|
+
export {
|
|
4
|
+
r as Digit,
|
|
5
|
+
o as canAnimate,
|
|
6
|
+
c as continuous,
|
|
7
|
+
n as default,
|
|
8
|
+
s as define,
|
|
9
|
+
t as formatToData,
|
|
10
|
+
f as prefersReducedMotion,
|
|
11
|
+
d as renderInnerHTML
|
|
12
|
+
};
|
package/dist/plugins/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import type NumberFlowLite from '../lite';
|
|
2
|
+
import type { Digit } from '../lite';
|
|
2
3
|
import type { Data } from '../formatter';
|
|
3
4
|
export type Plugin = {
|
|
4
5
|
onUpdate?(data: Data, prev: Data, context: NumberFlowLite): void;
|
package/dist/plugins.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=(e,n)=>e==null?n:n==null?e:Math.max(e,n),a=new WeakMap,f={onUpdate(e,n,o){if(a.set(o,void 0),!o.computedTrend)return;const s=n.integer.concat(n.fraction).filter(t=>t.type==="integer"||t.type==="fraction"),r=e.integer.concat(e.fraction).filter(t=>t.type==="integer"||t.type==="fraction"),u=s.find(t=>!r.find(c=>c.pos===t.pos&&c.value===t.value)),i=r.find(t=>!s.find(c=>t.pos===c.pos&&t.value===c.value));a.set(o,l(u==null?void 0:u.pos,i==null?void 0:i.pos))},getDelta(e,n,o){const s=e-n,r=a.get(o.flow);if(!s&&r!=null&&r>=o.pos)return o.length*o.flow.computedTrend}};exports.continuous=f;
|
package/dist/plugins.mjs
CHANGED
|
@@ -1,4 +1,16 @@
|
|
|
1
|
-
|
|
1
|
+
const f = (e, n) => e == null ? n : n == null ? e : Math.max(e, n), i = /* @__PURE__ */ new WeakMap(), l = {
|
|
2
|
+
onUpdate(e, n, o) {
|
|
3
|
+
if (i.set(o, void 0), !o.computedTrend)
|
|
4
|
+
return;
|
|
5
|
+
const s = n.integer.concat(n.fraction).filter((t) => t.type === "integer" || t.type === "fraction"), r = e.integer.concat(e.fraction).filter((t) => t.type === "integer" || t.type === "fraction"), u = s.find((t) => !r.find((c) => c.pos === t.pos && c.value === t.value)), a = r.find((t) => !s.find((c) => t.pos === c.pos && t.value === c.value));
|
|
6
|
+
i.set(o, f(u == null ? void 0 : u.pos, a == null ? void 0 : a.pos));
|
|
7
|
+
},
|
|
8
|
+
getDelta(e, n, o) {
|
|
9
|
+
const s = e - n, r = i.get(o.flow);
|
|
10
|
+
if (!s && r != null && r >= o.pos)
|
|
11
|
+
return o.length * o.flow.computedTrend;
|
|
12
|
+
}
|
|
13
|
+
};
|
|
2
14
|
export {
|
|
3
|
-
|
|
15
|
+
l as continuous
|
|
4
16
|
};
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "0.5.
|
|
6
|
+
"version": "0.5.4",
|
|
7
7
|
"author": {
|
|
8
8
|
"name": "Maxwell Barvian",
|
|
9
9
|
"email": "max@barvian.me",
|
|
@@ -41,6 +41,16 @@
|
|
|
41
41
|
"import": "./dist/index.mjs",
|
|
42
42
|
"require": "./dist/index.js"
|
|
43
43
|
},
|
|
44
|
+
"./lite": {
|
|
45
|
+
"types": "./dist/lite.d.ts",
|
|
46
|
+
"import": "./dist/lite.mjs",
|
|
47
|
+
"require": "./dist/lite.js"
|
|
48
|
+
},
|
|
49
|
+
"./group": {
|
|
50
|
+
"types": "./dist/group.d.ts",
|
|
51
|
+
"import": "./dist/group.mjs",
|
|
52
|
+
"require": "./dist/group.js"
|
|
53
|
+
},
|
|
44
54
|
"./plugins": {
|
|
45
55
|
"types": "./dist/plugins/index.d.ts",
|
|
46
56
|
"import": "./dist/plugins.mjs",
|
|
@@ -67,6 +77,6 @@
|
|
|
67
77
|
"scripts": {
|
|
68
78
|
"build": "vite build --mode production",
|
|
69
79
|
"dev": "vite build --mode development --watch",
|
|
70
|
-
"test
|
|
80
|
+
"test": "pnpm -r --workspace-concurrency 1 --filter=\"./test/apps/*\" test"
|
|
71
81
|
}
|
|
72
82
|
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
"use strict";const m=require("esm-env"),c=(n,t,e)=>{const i=document.createElement(n),[s,r]=Array.isArray(t)?[void 0,t]:[t,e];return s&&Object.assign(i,s),r==null||r.forEach(a=>i.appendChild(a)),i},B=(n,t)=>{var e;return t==="left"?n.offsetLeft:(((e=n.offsetParent instanceof HTMLElement?n.offsetParent:null)==null?void 0:e.offsetWidth)??0)-n.offsetWidth-n.offsetLeft},O=n=>n.offsetWidth>0&&n.offsetHeight>0,D=(n,t)=>{m.BROWSER&&customElements.get(n)!==t&&customElements.define(n,t)};function H(n,t,{reverse:e=!1}={}){const i=n.length;for(let s=e?i-1:0;e?s>=0:s<i;e?s--:s++)t(n[s],s)}const F=String.raw,P=String.raw,X=m.BROWSER&&typeof CSS<"u"&&CSS.supports&&CSS.supports("animation-timing-function","linear(1,2)"),z=m.BROWSER&&typeof CSS<"u"&&CSS.supports&&CSS.supports("line-height","mod(1,1)"),_=m.BROWSER&&typeof matchMedia<"u"?matchMedia("(prefers-reduced-motion: reduce)"):null,w="--_number-flow-d-opacity",R="--_number-flow-d-width",v="--_number-flow-dx",A="--_number-flow-d",I=(()=>{try{return CSS.registerProperty({name:w,syntax:"<number>",inherits:!1,initialValue:"0"}),CSS.registerProperty({name:v,syntax:"<length>",inherits:!0,initialValue:"0px"}),CSS.registerProperty({name:R,syntax:"<number>",inherits:!1,initialValue:"0"}),CSS.registerProperty({name:A,syntax:"<number>",inherits:!0,initialValue:"0"}),!0}catch{return!1}})(),k="var(--number-flow-char-height, 1em)",h="var(--number-flow-mask-height, 0.25em)",x=`calc(${h} / 2)`,C="var(--number-flow-mask-width, 0.5em)",d=`calc(${C} / var(--scale-x))`,u="#000 0, transparent 71%",j=P`:host{display:inline-block;direction:ltr;white-space:nowrap;isolation:isolate;line-height:${k} !important}.number,.number__inner{display:inline-block;transform-origin:left top}:host([data-will-change]) :is(.number,.number__inner,.section,.digit,.digit__num,.symbol){will-change:transform}.number{--scale-x:calc(1 + var(${R}) / var(--width));transform:translateX(var(${v})) scaleX(var(--scale-x));margin:0 calc(-1 * ${C});position:relative;-webkit-mask-image:linear-gradient(to right,transparent 0,#000 ${d},#000 calc(100% - ${d}),transparent ),linear-gradient(to bottom,transparent 0,#000 ${h},#000 calc(100% - ${h}),transparent 100% ),radial-gradient(at bottom right,${u}),radial-gradient(at bottom left,${u}),radial-gradient(at top left,${u}),radial-gradient(at top right,${u});-webkit-mask-size:100% calc(100% - ${h} * 2),calc(100% - ${d} * 2) 100%,${d} ${h},${d} ${h},${d} ${h},${d} ${h};-webkit-mask-position:center,center,top left,top right,bottom right,bottom left;-webkit-mask-repeat:no-repeat}.number:not(:has(.digit.is-spinning)){-webkit-mask-image:none}.number__inner{padding:${x} ${C};transform:scaleX(calc(1 / var(--scale-x))) translateX(calc(-1 * var(${v})))}:host > :not(.number){z-index:5}.section,.symbol{display:inline-block;position:relative;isolation:isolate}.section::after{content:'\200b';display:inline-block}.section--justify-left{transform-origin:center left}.section--justify-right{transform-origin:center right}.section > [inert],.symbol > [inert]{margin:0 !important;position:absolute !important;z-index:-1}.digit{display:inline-block;position:relative;--c:var(--current) + var(${A})}.digit__num,.number .section::after{padding:${x} 0}.digit__num{display:inline-block;--offset-raw:mod(var(--length) + var(--n) - mod(var(--c),var(--length)),var(--length));--offset:calc( var(--offset-raw) - var(--length) * round(down,var(--offset-raw) / (var(--length) / 2),1) );--y:clamp(-100%,var(--offset) * 100%,100%);transform:translateY(var(--y))}.digit__num[inert]{position:absolute;top:0;left:50%;transform:translateX(-50%) translateY(var(--y))}.digit:not(.is-spinning) .digit__num[inert]{display:none}.symbol__value{display:inline-block;mix-blend-mode:plus-lighter;white-space:pre}.section--justify-left .symbol > [inert]{left:0}.section--justify-right .symbol > [inert]{right:0}.animate-presence{opacity:calc(1 + var(${w}))}`,Y=m.BROWSER?HTMLElement:class{},q=P`:host{display:inline-block;direction:ltr;white-space:nowrap;line-height:${k} !important}span{display:inline-block}:host([data-will-change]) span{will-change:transform}.number,.digit{padding:${x} 0}.symbol{white-space:pre}`,G=n=>`<span class="${n.type==="integer"||n.type==="fraction"?"digit":"symbol"}" part="${n.type==="integer"||n.type==="fraction"?`digit ${n.type}-digit`:`symbol ${n.type}`}">${n.value}</span>`,g=(n,t)=>`<span part="${t}">${n.reduce((e,i)=>e+G(i),"")}</span>`,Z=n=>F`<template shadowroot="open" shadowrootmode="open"
|
|
2
|
-
><style>
|
|
3
|
-
${q}</style
|
|
4
|
-
>${g(n.pre,"left")}<span part="number" class="number"
|
|
5
|
-
>${g(n.integer,"integer")}${g(n.fraction,"fraction")}</span
|
|
6
|
-
>${g(n.post,"right")}</template
|
|
7
|
-
><span
|
|
8
|
-
style="font-kerning: none; display: inline-block; line-height: ${k} !important; padding: ${h} 0;"
|
|
9
|
-
>${n.valueAsString}</span
|
|
10
|
-
>`,L=z&&X&&I;let y;class W extends Y{constructor(){super(),this.created=!1,this.manual=!1;const{animated:t,...e}=this.constructor.defaultProps;this._animated=this.computedAnimated=t,Object.assign(this,e)}get animated(){return this._animated}set animated(t){var e;this.animated!==t&&(this._animated=t,(e=this.shadowRoot)==null||e.getAnimations().forEach(i=>i.finish()))}set data(t){var o;if(t==null)return;const{pre:e,integer:i,fraction:s,post:r,value:a}=t;if(this.created){const l=this._data;this._data=t,this.computedTrend=typeof this.trend=="function"?this.trend(l.value,a):this.trend,this.computedAnimated=L&&this._animated&&(!this.respectMotionPreference||!(_!=null&&_.matches))&&O(this),(o=this.plugins)==null||o.forEach(p=>{var f;return(f=p.onUpdate)==null?void 0:f.call(p,t,l,this)}),this.manual||this.willUpdate(),this._pre.update(e),this._num.update({integer:i,fraction:s}),this._post.update(r),this.manual||this.didUpdate()}else{if(this._data=t,this.attachShadow({mode:"open"}),typeof CSSStyleSheet<"u"&&this.shadowRoot.adoptedStyleSheets)y||(y=new CSSStyleSheet,y.replaceSync(j)),this.shadowRoot.adoptedStyleSheets=[y];else{const l=document.createElement("style");l.textContent=j,this.shadowRoot.appendChild(l)}this._pre=new T(this,e,{justify:"right",part:"left"}),this.shadowRoot.appendChild(this._pre.el),this._num=new J(this,i,s),this.shadowRoot.appendChild(this._num.el),this._post=new T(this,r,{justify:"left",part:"right"}),this.shadowRoot.appendChild(this._post.el)}this.created=!0}willUpdate(){this._pre.willUpdate(),this._num.willUpdate(),this._post.willUpdate()}didUpdate(){if(!this.computedAnimated)return;this._abortAnimationsFinish?this._abortAnimationsFinish.abort():this.dispatchEvent(new Event("animationsstart")),this._pre.didUpdate(),this._num.didUpdate(),this._post.didUpdate();const t=new AbortController;Promise.all(this.shadowRoot.getAnimations().map(e=>e.finished)).then(()=>{t.signal.aborted||(this.dispatchEvent(new Event("animationsfinish")),this._abortAnimationsFinish=void 0)}),this._abortAnimationsFinish=t}}W.defaultProps={transformTiming:{duration:900,easing:"linear(0,.005,.019,.039,.066,.096,.129,.165,.202,.24,.278,.316,.354,.39,.426,.461,.494,.526,.557,.586,.614,.64,.665,.689,.711,.731,.751,.769,.786,.802,.817,.831,.844,.856,.867,.877,.887,.896,.904,.912,.919,.925,.931,.937,.942,.947,.951,.955,.959,.962,.965,.968,.971,.973,.976,.978,.98,.981,.983,.984,.986,.987,.988,.989,.99,.991,.992,.992,.993,.994,.994,.995,.995,.996,.996,.9963,.9967,.9969,.9972,.9975,.9977,.9979,.9981,.9982,.9984,.9985,.9987,.9988,.9989,1)"},spinTiming:void 0,opacityTiming:{duration:450,easing:"ease-out"},animated:!0,trend:(n,t)=>Math.sign(t-n),respectMotionPreference:!0,plugins:void 0,digits:void 0};class J{constructor(t,e,i,{className:s,...r}={}){this.flow=t,this._integer=new M(t,e,{justify:"right",part:"integer"}),this._fraction=new M(t,i,{justify:"left",part:"fraction"}),this._inner=c("span",{className:"number__inner"},[this._integer.el,this._fraction.el]),this.el=c("span",{...r,part:"number",className:`number ${s??""}`},[this._inner])}willUpdate(){this._prevWidth=this.el.offsetWidth,this._prevLeft=this.el.getBoundingClientRect().left,this._integer.willUpdate(),this._fraction.willUpdate()}update({integer:t,fraction:e}){this._integer.update(t),this._fraction.update(e)}didUpdate(){const t=this.el.getBoundingClientRect();this._integer.didUpdate(),this._fraction.didUpdate();const e=this._prevLeft-t.left,i=this.el.offsetWidth,s=this._prevWidth-i;this.el.style.setProperty("--width",String(i)),this.el.animate({[v]:[`${e}px`,"0px"],[R]:[s,0]},{...this.flow.transformTiming,composite:"accumulate"})}}class N{constructor(t,e,{justify:i,className:s,...r},a){this.flow=t,this.children=new Map,this.onCharRemove=l=>()=>{this.children.delete(l)},this.justify=i;const o=e.map(l=>this.addChar(l).el);this.el=c("span",{...r,className:`section section--justify-${i} ${s??""}`},a?a(o):o)}addChar(t,{startDigitsAtZero:e=!1,...i}={}){const s=t.type==="integer"||t.type==="fraction"?new U(this,t.type,e?0:t.value,t.pos,{...i,onRemove:this.onCharRemove(t.key)}):new K(this,t.type,t.value,{...i,onRemove:this.onCharRemove(t.key)});return this.children.set(t.key,s),s}unpop(t){t.el.removeAttribute("inert"),t.el.style.top="",t.el.style[this.justify]=""}pop(t){t.forEach(e=>{e.el.style.top=`${e.el.offsetTop}px`,e.el.style[this.justify]=`${B(e.el,this.justify)}px`}),t.forEach(e=>{e.el.setAttribute("inert",""),e.present=!1})}addNewAndUpdateExisting(t){const e=new Map,i=new Map,s=this.justify==="left",r=s?"prepend":"append";if(H(t,a=>{let o;this.children.has(a.key)?(o=this.children.get(a.key),i.set(a,o),this.unpop(o),o.present=!0):(o=this.addChar(a,{startDigitsAtZero:!0,animateIn:!0}),e.set(a,o)),this.el[r](o.el)},{reverse:s}),this.flow.computedAnimated){const a=this.el.getBoundingClientRect();e.forEach(o=>{o.willUpdate(a)})}e.forEach((a,o)=>{a.update(o.value)}),i.forEach((a,o)=>{a.update(o.value)})}willUpdate(){const t=this.el.getBoundingClientRect();this._prevOffset=t[this.justify],this.children.forEach(e=>e.willUpdate(t))}didUpdate(){const t=this.el.getBoundingClientRect();this.children.forEach(s=>s.didUpdate(t));const e=t[this.justify],i=this._prevOffset-e;i&&this.children.size&&this.el.animate({transform:[`translateX(${i}px)`,"none"]},{...this.flow.transformTiming,composite:"accumulate"})}}class M extends N{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 U&&i.update(0)}),this.pop(e)}}class T extends N{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 E{constructor(t,e,{onRemove:i,animateIn:s=!1}={}){this.flow=t,this.el=e,this._present=!0,this._remove=()=>{var r;this.el.remove(),(r=this._onRemove)==null||r.call(this)},this.el.classList.add("animate-presence"),this.flow.computedAnimated&&s&&this.el.animate({[w]:[-.9999,0]},{...this.flow.opacityTiming,composite:"accumulate"}),this._onRemove=i}get present(){return this._present}set present(t){if(this._present!==t){if(this._present=t,t?this.el.removeAttribute("inert"):this.el.setAttribute("inert",""),!this.flow.computedAnimated){t||this._remove();return}this.el.style.setProperty("--_number-flow-d-opacity",t?"0":"-.999"),this.el.animate({[w]:t?[-.9999,0]:[.999,0]},{...this.flow.opacityTiming,composite:"accumulate"}),t?this.flow.removeEventListener("animationsfinish",this._remove):this.flow.addEventListener("animationsfinish",this._remove,{once:!0})}}}class V extends E{constructor(t,e,i,s){super(t.flow,i,s),this.section=t,this.value=e,this.el=i}}class U extends V{constructor(t,e,i,s,r){var p,f;const a=(((f=(p=t.flow.digits)==null?void 0:p[s])==null?void 0:f.max)??9)+1,o=Array.from({length:a}).map((et,b)=>{const $=c("span",{className:"digit__num"},[document.createTextNode(String(b))]);return b!==i&&$.setAttribute("inert",""),$.style.setProperty("--n",String(b)),$}),l=c("span",{part:`digit ${e}-digit`,className:"digit"},o);l.style.setProperty("--current",String(i)),l.style.setProperty("--length",String(a)),super(t,i,l,r),this.pos=s,this._onAnimationsFinish=()=>{this.el.classList.remove("is-spinning")},this._numbers=o,this.length=a}willUpdate(t){const e=this.el.getBoundingClientRect();this._prevValue=this.value;const i=e[this.section.justify]-t[this.section.justify],s=e.width/2;this._prevCenter=this.section.justify==="left"?i+s:i-s}update(t){this.el.style.setProperty("--current",String(t)),this._numbers.forEach((e,i)=>i===t?e.removeAttribute("inert"):e.setAttribute("inert","")),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,a=this._prevCenter-r;a&&this.el.animate({transform:[`translateX(${a}px)`,"none"]},{...this.flow.transformTiming,composite:"accumulate"});const o=this.getDelta();o&&(this.el.classList.add("is-spinning"),this.el.animate({[A]:[-o,0]},{...this.flow.spinTiming??this.flow.transformTiming,composite:"accumulate"}),this.flow.addEventListener("animationsfinish",this._onAnimationsFinish,{once:!0}))}getDelta(){var i;if(this.flow.plugins)for(const s of this.flow.plugins){const r=(i=s.getDelta)==null?void 0:i.call(s,this.value,this._prevValue,this);if(r!=null)return r}const t=this.value-this._prevValue,e=this.flow.computedTrend||Math.sign(t);return e<0&&this.value>this._prevValue?this.value-this.length-this._prevValue:e>0&&this.value<this._prevValue?this.length-this._prevValue+this.value:t}}class K extends V{constructor(t,e,i,s){const r=c("span",{className:"symbol__value",textContent:i});super(t,i,c("span",{part:`symbol ${e}`,className:"symbol"},[r]),s),this.type=e,this._children=new Map,this._onChildRemove=a=>()=>{this._children.delete(a)},this._children.set(i,new E(this.flow,r,{onRemove:this._onChildRemove(i)}))}willUpdate(t){if(this.type==="decimal")return;const e=this.el.getBoundingClientRect();this._prevOffset=e[this.section.justify]-t[this.section.justify]}update(t){if(this.value!==t){const e=this._children.get(this.value);if(e.present=!1,this._children.has(t)){const i=this._children.get(t);i.present=!0}else{const i=c("span",{className:"symbol__value",textContent:t});this.el.appendChild(i),this._children.set(t,new E(this.flow,i,{animateIn:!0,onRemove:this._onChildRemove(t)}))}}this.value=t}didUpdate(t){if(this.type==="decimal")return;const i=this.el.getBoundingClientRect()[this.section.justify]-t[this.section.justify],s=this._prevOffset-i;s&&this.el.animate({transform:[`translateX(${s}px)`,"none"]},{...this.flow.transformTiming,composite:"accumulate"})}}const Q=(n,t)=>n==null?t:t==null?n:Math.max(n,t),S=new WeakMap,tt={onUpdate(n,t,e){if(S.set(e,void 0),!e.computedTrend)return;const i=t.integer.concat(t.fraction).filter(o=>o.type==="integer"||o.type==="fraction"),s=n.integer.concat(n.fraction).filter(o=>o.type==="integer"||o.type==="fraction"),r=i.find(o=>!s.find(l=>l.pos===o.pos&&l.value===o.value)),a=s.find(o=>!i.find(l=>o.pos===l.pos&&o.value===l.value));S.set(e,Q(r==null?void 0:r.pos,a==null?void 0:a.pos))},getDelta(n,t,e){const i=n-t,s=S.get(e.flow);if(!i&&s!=null&&s>=e.pos)return e.length*e.flow.computedTrend}};exports.Digit=U;exports.NumberFlowLite=W;exports.canAnimate=L;exports.continuous=tt;exports.define=D;exports.prefersReducedMotion=_;exports.renderInnerHTML=Z;
|