number-flow 0.5.7 → 0.5.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/group.js +1 -1
- package/dist/group.mjs +1 -1
- package/dist/index.js +1 -1
- package/dist/index.mjs +2 -2
- package/dist/{lite-CzDvSY_4.mjs → lite-BtgQ9jUv.mjs} +59 -65
- package/dist/lite-DH1kEhrb.js +12 -0
- package/dist/lite.js +1 -1
- package/dist/lite.mjs +1 -1
- package/package.json +1 -1
- package/dist/lite-B8p0lZvR.js +0 -12
package/dist/group.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const n=require("./lite-
|
|
1
|
+
"use strict";const n=require("./lite-DH1kEhrb.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
CHANGED
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("./lite-
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("./lite-DH1kEhrb.js"),l=require("./plugins.js"),n="number-flow-connect",s="number-flow-update",f=(r,{locales:t,format:o,numberPrefix:a,numberSuffix:u}={})=>{const c=e.formatToData(r,new Intl.NumberFormat(t,o),a,u);return e.renderInnerHTML(c)};class i extends e.NumberFlowLite{constructor(){super(...arguments),this.connected=!1}connectedCallback(){this.connected=!0,this.dispatchEvent(new Event(n,{bubbles:!0}))}disconnectedCallback(){this.connected=!1}get value(){return this._value}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",i);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=n;exports.UPDATE_EVENT=s;exports.default=i;exports.renderInnerHTML=f;
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { d as i, N as u, f as r, r as c } from "./lite-
|
|
2
|
-
import { D as _, c as v, p as E } from "./lite-
|
|
1
|
+
import { d as i, N as u, f as r, r as c } from "./lite-BtgQ9jUv.mjs";
|
|
2
|
+
import { D as _, c as v, p as E } from "./lite-BtgQ9jUv.mjs";
|
|
3
3
|
import { continuous as N } from "./plugins.mjs";
|
|
4
4
|
const l = "number-flow-connect", m = "number-flow-update", d = (t, { locales: e, format: s, numberPrefix: n, numberSuffix: a } = {}) => {
|
|
5
5
|
const o = r(t, new Intl.NumberFormat(e, s), n, a);
|
|
@@ -3,18 +3,18 @@ import "./plugins.mjs";
|
|
|
3
3
|
const m = (n, t, e) => {
|
|
4
4
|
const i = document.createElement(n), [s, a] = Array.isArray(t) ? [void 0, t] : [t, e];
|
|
5
5
|
return s && Object.assign(i, s), a == null || a.forEach((r) => i.appendChild(r)), i;
|
|
6
|
-
},
|
|
6
|
+
}, B = (n, t) => {
|
|
7
7
|
var e;
|
|
8
8
|
return t === "left" ? n.offsetLeft : (((e = n.offsetParent instanceof HTMLElement ? n.offsetParent : null) == null ? void 0 : e.offsetWidth) ?? 0) - n.offsetWidth - n.offsetLeft;
|
|
9
|
-
},
|
|
10
|
-
_ && customElements.get(n)
|
|
9
|
+
}, D = (n) => n.offsetWidth > 0 && n.offsetHeight > 0, it = (n, t) => {
|
|
10
|
+
_ && !customElements.get(n) && customElements.define(n, t);
|
|
11
11
|
};
|
|
12
|
-
function
|
|
12
|
+
function F(n, t, { reverse: e = !1 } = {}) {
|
|
13
13
|
const i = n.length;
|
|
14
14
|
for (let s = e ? i - 1 : 0; e ? s >= 0 : s < i; e ? s-- : s++)
|
|
15
15
|
t(n[s], s);
|
|
16
16
|
}
|
|
17
|
-
function
|
|
17
|
+
function st(n, t, e, i) {
|
|
18
18
|
const s = t.formatToParts(n);
|
|
19
19
|
e && s.unshift({ type: "prefix", value: e }), i && s.push({ type: "suffix", value: i });
|
|
20
20
|
const a = [], r = [], o = [], c = [], d = {}, p = (h) => `${h}:${d[h] = (d[h] ?? -1) + 1}`;
|
|
@@ -22,9 +22,9 @@ function nt(n, t, e, i) {
|
|
|
22
22
|
for (const h of s) {
|
|
23
23
|
x += h.value;
|
|
24
24
|
const l = h.type === "minusSign" || h.type === "plusSign" ? "sign" : h.type;
|
|
25
|
-
l === "integer" ? (g = !0, r.push(...h.value.split("").map((
|
|
25
|
+
l === "integer" ? (g = !0, r.push(...h.value.split("").map((S) => ({ type: l, value: parseInt(S) })))) : l === "group" ? r.push({ type: l, value: h.value }) : l === "decimal" ? (y = !0, o.push({ type: l, value: h.value, key: p(l) })) : l === "fraction" ? o.push(...h.value.split("").map((S) => ({
|
|
26
26
|
type: l,
|
|
27
|
-
value: parseInt(
|
|
27
|
+
value: parseInt(S),
|
|
28
28
|
key: p(l),
|
|
29
29
|
pos: -1 - d[l]
|
|
30
30
|
}))) : (g || y ? c : a).push({
|
|
@@ -33,10 +33,10 @@ function nt(n, t, e, i) {
|
|
|
33
33
|
key: p(l)
|
|
34
34
|
});
|
|
35
35
|
}
|
|
36
|
-
const
|
|
36
|
+
const P = [];
|
|
37
37
|
for (let h = r.length - 1; h >= 0; h--) {
|
|
38
38
|
const l = r[h];
|
|
39
|
-
|
|
39
|
+
P.unshift(l.type === "integer" ? {
|
|
40
40
|
...l,
|
|
41
41
|
key: p(l.type),
|
|
42
42
|
pos: d[l.type]
|
|
@@ -47,29 +47,29 @@ function nt(n, t, e, i) {
|
|
|
47
47
|
}
|
|
48
48
|
return {
|
|
49
49
|
pre: a,
|
|
50
|
-
integer:
|
|
50
|
+
integer: P,
|
|
51
51
|
fraction: o,
|
|
52
52
|
post: c,
|
|
53
53
|
valueAsString: x,
|
|
54
54
|
value: typeof n == "string" ? parseFloat(n) : n
|
|
55
55
|
};
|
|
56
56
|
}
|
|
57
|
-
const
|
|
57
|
+
const H = String.raw, L = String.raw, X = _ && (() => {
|
|
58
58
|
try {
|
|
59
59
|
document.createElement("div").animate({ opacity: 0 }, { easing: "linear(0, 1)" });
|
|
60
60
|
} catch {
|
|
61
61
|
return !1;
|
|
62
62
|
}
|
|
63
63
|
return !0;
|
|
64
|
-
})(),
|
|
64
|
+
})(), I = _ && typeof CSS < "u" && CSS.supports && CSS.supports("line-height", "mod(1,1)"), A = _ && typeof matchMedia < "u" ? matchMedia("(prefers-reduced-motion: reduce)") : null, b = "--_number-flow-d-opacity", U = "--_number-flow-d-width", $ = "--_number-flow-dx", R = "--_number-flow-d", O = (() => {
|
|
65
65
|
try {
|
|
66
66
|
return CSS.registerProperty({
|
|
67
|
-
name:
|
|
67
|
+
name: b,
|
|
68
68
|
syntax: "<number>",
|
|
69
69
|
inherits: !1,
|
|
70
70
|
initialValue: "0"
|
|
71
71
|
}), CSS.registerProperty({
|
|
72
|
-
name:
|
|
72
|
+
name: $,
|
|
73
73
|
syntax: "<length>",
|
|
74
74
|
inherits: !0,
|
|
75
75
|
initialValue: "0px"
|
|
@@ -79,7 +79,7 @@ const I = String.raw, V = String.raw, O = _ && (() => {
|
|
|
79
79
|
inherits: !1,
|
|
80
80
|
initialValue: "0"
|
|
81
81
|
}), CSS.registerProperty({
|
|
82
|
-
name:
|
|
82
|
+
name: R,
|
|
83
83
|
syntax: "<number>",
|
|
84
84
|
inherits: !0,
|
|
85
85
|
initialValue: "0"
|
|
@@ -87,24 +87,23 @@ const I = String.raw, V = String.raw, O = _ && (() => {
|
|
|
87
87
|
} catch {
|
|
88
88
|
return !1;
|
|
89
89
|
}
|
|
90
|
-
})(),
|
|
91
|
-
},
|
|
90
|
+
})(), j = "var(--number-flow-char-height, 1em)", f = "var(--number-flow-mask-height, 0.25em)", C = `calc(${f} / 2)`, k = "var(--number-flow-mask-width, 0.5em)", u = `calc(${k} / var(--scale-x))`, v = "#000 0, transparent 71%", z = L`:host{display:inline-block;direction:ltr;white-space:nowrap;isolation:isolate;line-height:${j} !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(${$})) scaleX(var(--scale-x));margin:0 calc(-1 * ${k});position:relative;-webkit-mask-image:linear-gradient(to right,transparent 0,#000 ${u},#000 calc(100% - ${u}),transparent ),linear-gradient(to bottom,transparent 0,#000 ${f},#000 calc(100% - ${f}),transparent 100% ),radial-gradient(at bottom right,${v}),radial-gradient(at bottom left,${v}),radial-gradient(at top left,${v}),radial-gradient(at top right,${v});-webkit-mask-size:100% calc(100% - ${f} * 2),calc(100% - ${u} * 2) 100%,${u} ${f},${u} ${f},${u} ${f},${u} ${f};-webkit-mask-position:center,center,top left,top right,bottom right,bottom left;-webkit-mask-repeat:no-repeat}.number__inner{padding:${C} ${k};transform:scaleX(calc(1 / var(--scale-x))) translateX(calc(-1 * var(${$})))}: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(${R})}.digit__num,.number .section::after{padding:${C} 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}))}`, Y = _ ? HTMLElement : class {
|
|
91
|
+
}, G = L`:host{display:inline-block;direction:ltr;white-space:nowrap;line-height:${j} !important}span{display:inline-block}:host([data-will-change]) span{will-change:transform}.number,.digit{padding:${C} 0}.symbol{white-space:pre}`, K = (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>`, w = (n, t) => `<span part="${t}">${n.reduce((e, i) => e + K(i), "")}</span>`, nt = (n) => (
|
|
92
92
|
// shadowroot="open" non-standard attribute for old Chrome:
|
|
93
|
-
|
|
93
|
+
H`<template shadowroot="open" shadowrootmode="open"
|
|
94
94
|
><style>
|
|
95
|
-
${
|
|
95
|
+
${G}</style
|
|
96
96
|
><span role="img" aria-label="${n.valueAsString}"
|
|
97
|
-
>${
|
|
98
|
-
>${
|
|
99
|
-
>${
|
|
97
|
+
>${w(n.pre, "left")}<span part="number" class="number"
|
|
98
|
+
>${w(n.integer, "integer")}${w(n.fraction, "fraction")}</span
|
|
99
|
+
>${w(n.post, "right")}</span
|
|
100
100
|
></template
|
|
101
101
|
><span
|
|
102
|
-
style="font-kerning: none; display: inline-block; line-height: ${
|
|
102
|
+
style="font-kerning: none; display: inline-block; line-height: ${j} !important; padding: ${f} 0;"
|
|
103
103
|
>${n.valueAsString}</span
|
|
104
104
|
>`
|
|
105
|
-
),
|
|
106
|
-
|
|
107
|
-
class J extends G {
|
|
105
|
+
), Z = I && X && O;
|
|
106
|
+
class q extends Y {
|
|
108
107
|
constructor() {
|
|
109
108
|
super(), this.created = !1, this.batched = !1;
|
|
110
109
|
const { animated: t, ...e } = this.constructor.defaultProps;
|
|
@@ -127,8 +126,8 @@ class J extends G {
|
|
|
127
126
|
const { pre: e, integer: i, fraction: s, post: a, value: r } = t;
|
|
128
127
|
if (this.created) {
|
|
129
128
|
const c = this._data;
|
|
130
|
-
this._data = t, this.computedTrend = typeof this.trend == "function" ? this.trend(c.value, r) : this.trend, this.computedAnimated =
|
|
131
|
-
|
|
129
|
+
this._data = t, this.computedTrend = typeof this.trend == "function" ? this.trend(c.value, r) : this.trend, this.computedAnimated = Z && this._animated && (!this.respectMotionPreference || !(A != null && A.matches)) && // https://github.com/barvian/number-flow/issues/9
|
|
130
|
+
D(this), (o = this.plugins) == null || o.forEach((d) => {
|
|
132
131
|
var p;
|
|
133
132
|
return (p = d.onUpdate) == null ? void 0 : p.call(d, t, c, this);
|
|
134
133
|
}), this.batched || this.willUpdate(), this._pre.update(e), this._num.update({ integer: i, fraction: s }), this._post.update(a), this.batched || this.didUpdate();
|
|
@@ -138,16 +137,11 @@ class J extends G {
|
|
|
138
137
|
this._internals ?? (this._internals = this.attachInternals()), this._internals.role = "img";
|
|
139
138
|
} catch {
|
|
140
139
|
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
else {
|
|
144
|
-
const c = document.createElement("style");
|
|
145
|
-
c.textContent = M, this.shadowRoot.appendChild(c);
|
|
146
|
-
}
|
|
147
|
-
this._pre = new N(this, e, {
|
|
140
|
+
const c = document.createElement("style");
|
|
141
|
+
c.textContent = z, this.shadowRoot.appendChild(c), this._pre = new M(this, e, {
|
|
148
142
|
justify: "right",
|
|
149
143
|
part: "left"
|
|
150
|
-
}), this.shadowRoot.appendChild(this._pre.el), this._num = new
|
|
144
|
+
}), this.shadowRoot.appendChild(this._pre.el), this._num = new J(this, i, s), this.shadowRoot.appendChild(this._num.el), this._post = new M(this, a, {
|
|
151
145
|
justify: "left",
|
|
152
146
|
part: "right"
|
|
153
147
|
}), this.shadowRoot.appendChild(this._post.el), this.created = !0;
|
|
@@ -176,7 +170,7 @@ class J extends G {
|
|
|
176
170
|
}), this._abortAnimationsFinish = t;
|
|
177
171
|
}
|
|
178
172
|
}
|
|
179
|
-
|
|
173
|
+
q.defaultProps = {
|
|
180
174
|
transformTiming: {
|
|
181
175
|
duration: 900,
|
|
182
176
|
// Make sure to keep this minified:
|
|
@@ -190,12 +184,12 @@ J.defaultProps = {
|
|
|
190
184
|
plugins: void 0,
|
|
191
185
|
digits: void 0
|
|
192
186
|
};
|
|
193
|
-
class
|
|
187
|
+
class J {
|
|
194
188
|
constructor(t, e, i, { className: s, ...a } = {}) {
|
|
195
|
-
this.flow = t, this._integer = new
|
|
189
|
+
this.flow = t, this._integer = new T(t, e, {
|
|
196
190
|
justify: "right",
|
|
197
191
|
part: "integer"
|
|
198
|
-
}), this._fraction = new
|
|
192
|
+
}), this._fraction = new T(t, i, {
|
|
199
193
|
justify: "left",
|
|
200
194
|
part: "fraction"
|
|
201
195
|
}), this._inner = m("span", {
|
|
@@ -217,7 +211,7 @@ class Q {
|
|
|
217
211
|
this._integer.didUpdate(), this._fraction.didUpdate();
|
|
218
212
|
const e = this._prevLeft - t.left, i = this.el.offsetWidth, s = this._prevWidth - i;
|
|
219
213
|
this.el.style.setProperty("--width", String(i)), this.el.animate({
|
|
220
|
-
[
|
|
214
|
+
[$]: [`${e}px`, "0px"],
|
|
221
215
|
[U]: [s, 0]
|
|
222
216
|
}, {
|
|
223
217
|
...this.flow.transformTiming,
|
|
@@ -225,7 +219,7 @@ class Q {
|
|
|
225
219
|
});
|
|
226
220
|
}
|
|
227
221
|
}
|
|
228
|
-
class
|
|
222
|
+
class N {
|
|
229
223
|
constructor(t, e, { justify: i, className: s, ...a }, r) {
|
|
230
224
|
this.flow = t, this.children = /* @__PURE__ */ new Map(), this.onCharRemove = (c) => () => {
|
|
231
225
|
this.children.delete(c);
|
|
@@ -237,10 +231,10 @@ class W {
|
|
|
237
231
|
}, r ? r(o) : o);
|
|
238
232
|
}
|
|
239
233
|
addChar(t, { startDigitsAtZero: e = !1, ...i } = {}) {
|
|
240
|
-
const s = t.type === "integer" || t.type === "fraction" ? new
|
|
234
|
+
const s = t.type === "integer" || t.type === "fraction" ? new W(this, t.type, e ? 0 : t.value, t.pos, {
|
|
241
235
|
...i,
|
|
242
236
|
onRemove: this.onCharRemove(t.key)
|
|
243
|
-
}) : new
|
|
237
|
+
}) : new Q(this, t.type, t.value, {
|
|
244
238
|
...i,
|
|
245
239
|
onRemove: this.onCharRemove(t.key)
|
|
246
240
|
});
|
|
@@ -251,14 +245,14 @@ class W {
|
|
|
251
245
|
}
|
|
252
246
|
pop(t) {
|
|
253
247
|
t.forEach((e) => {
|
|
254
|
-
e.el.style.top = `${e.el.offsetTop}px`, e.el.style[this.justify] = `${
|
|
248
|
+
e.el.style.top = `${e.el.offsetTop}px`, e.el.style[this.justify] = `${B(e.el, this.justify)}px`;
|
|
255
249
|
}), t.forEach((e) => {
|
|
256
250
|
e.el.setAttribute("inert", ""), e.present = !1;
|
|
257
251
|
});
|
|
258
252
|
}
|
|
259
253
|
addNewAndUpdateExisting(t) {
|
|
260
254
|
const e = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Map(), s = this.justify === "left", a = s ? "prepend" : "append";
|
|
261
|
-
if (
|
|
255
|
+
if (F(t, (r) => {
|
|
262
256
|
let o;
|
|
263
257
|
this.children.has(r.key) ? (o = this.children.get(r.key), i.set(r, o), this.unpop(o), o.present = !0) : (o = this.addChar(r, { startDigitsAtZero: !0, animateIn: !0 }), e.set(r, o)), this.el[a](o.el);
|
|
264
258
|
}, { reverse: s }), this.flow.computedAnimated) {
|
|
@@ -289,17 +283,17 @@ class W {
|
|
|
289
283
|
});
|
|
290
284
|
}
|
|
291
285
|
}
|
|
292
|
-
class
|
|
286
|
+
class T extends N {
|
|
293
287
|
update(t) {
|
|
294
288
|
const e = /* @__PURE__ */ new Map();
|
|
295
289
|
this.children.forEach((i, s) => {
|
|
296
290
|
t.find((a) => a.key === s) || e.set(s, i), this.unpop(i);
|
|
297
291
|
}), this.addNewAndUpdateExisting(t), e.forEach((i) => {
|
|
298
|
-
i instanceof
|
|
292
|
+
i instanceof W && i.update(0);
|
|
299
293
|
}), this.pop(e);
|
|
300
294
|
}
|
|
301
295
|
}
|
|
302
|
-
class
|
|
296
|
+
class M extends N {
|
|
303
297
|
update(t) {
|
|
304
298
|
const e = /* @__PURE__ */ new Map();
|
|
305
299
|
this.children.forEach((i, s) => {
|
|
@@ -307,13 +301,13 @@ class N extends W {
|
|
|
307
301
|
}), this.pop(e), this.addNewAndUpdateExisting(t);
|
|
308
302
|
}
|
|
309
303
|
}
|
|
310
|
-
class
|
|
304
|
+
class E {
|
|
311
305
|
constructor(t, e, { onRemove: i, animateIn: s = !1 } = {}) {
|
|
312
306
|
this.flow = t, this.el = e, this._present = !0, this._remove = () => {
|
|
313
307
|
var a;
|
|
314
308
|
this.el.remove(), (a = this._onRemove) == null || a.call(this);
|
|
315
309
|
}, this.el.classList.add("animate-presence"), this.flow.computedAnimated && s && this.el.animate({
|
|
316
|
-
[
|
|
310
|
+
[b]: [-0.9999, 0]
|
|
317
311
|
}, {
|
|
318
312
|
...this.flow.opacityTiming,
|
|
319
313
|
composite: "accumulate"
|
|
@@ -329,7 +323,7 @@ class R {
|
|
|
329
323
|
return;
|
|
330
324
|
}
|
|
331
325
|
this.el.style.setProperty("--_number-flow-d-opacity", t ? "0" : "-.999"), this.el.animate({
|
|
332
|
-
[
|
|
326
|
+
[b]: t ? [-0.9999, 0] : [0.999, 0]
|
|
333
327
|
}, {
|
|
334
328
|
...this.flow.opacityTiming,
|
|
335
329
|
composite: "accumulate"
|
|
@@ -339,12 +333,12 @@ class R {
|
|
|
339
333
|
}
|
|
340
334
|
}
|
|
341
335
|
}
|
|
342
|
-
class
|
|
336
|
+
class V extends E {
|
|
343
337
|
constructor(t, e, i, s) {
|
|
344
338
|
super(t.flow, i, s), this.section = t, this.value = e, this.el = i;
|
|
345
339
|
}
|
|
346
340
|
}
|
|
347
|
-
class
|
|
341
|
+
class W extends V {
|
|
348
342
|
constructor(t, e, i, s, a) {
|
|
349
343
|
var d, p;
|
|
350
344
|
const r = (((p = (d = t.flow.digits) == null ? void 0 : d[s]) == null ? void 0 : p.max) ?? 9) + 1, o = Array.from({ length: r }).map((x, g) => {
|
|
@@ -379,7 +373,7 @@ class D extends B {
|
|
|
379
373
|
});
|
|
380
374
|
const o = this.getDelta();
|
|
381
375
|
o && (this.el.classList.add("is-spinning"), this.el.animate({
|
|
382
|
-
[
|
|
376
|
+
[R]: [-o, 0]
|
|
383
377
|
}, {
|
|
384
378
|
...this.flow.spinTiming ?? this.flow.transformTiming,
|
|
385
379
|
composite: "accumulate"
|
|
@@ -397,7 +391,7 @@ class D extends B {
|
|
|
397
391
|
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;
|
|
398
392
|
}
|
|
399
393
|
}
|
|
400
|
-
class
|
|
394
|
+
class Q extends V {
|
|
401
395
|
constructor(t, e, i, s) {
|
|
402
396
|
const a = m("span", {
|
|
403
397
|
className: "symbol__value",
|
|
@@ -408,7 +402,7 @@ class tt extends B {
|
|
|
408
402
|
className: "symbol"
|
|
409
403
|
}, [a]), s), this.type = e, this._children = /* @__PURE__ */ new Map(), this._onChildRemove = (r) => () => {
|
|
410
404
|
this._children.delete(r);
|
|
411
|
-
}, this._children.set(i, new
|
|
405
|
+
}, this._children.set(i, new E(this.flow, a, {
|
|
412
406
|
onRemove: this._onChildRemove(i)
|
|
413
407
|
}));
|
|
414
408
|
}
|
|
@@ -430,7 +424,7 @@ class tt extends B {
|
|
|
430
424
|
className: "symbol__value",
|
|
431
425
|
textContent: t
|
|
432
426
|
});
|
|
433
|
-
this.el.appendChild(s), this._children.set(t, new
|
|
427
|
+
this.el.appendChild(s), this._children.set(t, new E(this.flow, s, {
|
|
434
428
|
animateIn: !0,
|
|
435
429
|
onRemove: this._onChildRemove(t)
|
|
436
430
|
}));
|
|
@@ -448,12 +442,12 @@ class tt extends B {
|
|
|
448
442
|
}
|
|
449
443
|
}
|
|
450
444
|
export {
|
|
451
|
-
D,
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
445
|
+
W as D,
|
|
446
|
+
q as N,
|
|
447
|
+
Y as S,
|
|
448
|
+
Z as c,
|
|
449
|
+
it as d,
|
|
450
|
+
st as f,
|
|
457
451
|
A as p,
|
|
458
|
-
|
|
452
|
+
nt as r
|
|
459
453
|
};
|
|
@@ -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(r=>i.appendChild(r)),i},O=(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},F=n=>n.offsetWidth>0&&n.offsetHeight>0,I=(n,t)=>{_.BROWSER&&!customElements.get(n)&&customElements.define(n,t)};function X(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 z(n,t,e,i){const s=t.formatToParts(n);e&&s.unshift({type:"prefix",value:e}),i&&s.push({type:"suffix",value:i});const a=[],r=[],o=[],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,r.push(...h.value.split("").map(x=>({type:l,value:parseInt(x)})))):l==="group"?r.push({type:l,value:h.value}):l==="decimal"?(y=!0,o.push({type:l,value:h.value,key:p(l)})):l==="fraction"?o.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 M=[];for(let h=r.length-1;h>=0;h--){const l=r[h];M.unshift(l.type==="integer"?{...l,key:p(l.type),pos:d[l.type]}:{...l,key:p(l.type)})}return{pre:a,integer:M,fraction:o,post:c,valueAsString:E,value:typeof n=="string"?parseFloat(n):n}}const q=String.raw,W=String.raw,Y=_.BROWSER&&(()=>{try{document.createElement("div").animate({opacity:0},{easing:"linear(0, 1)"})}catch{return!1}return!0})(),G=_.BROWSER&&typeof CSS<"u"&&CSS.supports&&CSS.supports("line-height","mod(1,1)"),b=_.BROWSER&&typeof matchMedia<"u"?matchMedia("(prefers-reduced-motion: reduce)"):null,$="--_number-flow-d-opacity",k="--_number-flow-d-width",S="--_number-flow-dx",U="--_number-flow-d",K=(()=>{try{return CSS.registerProperty({name:$,syntax:"<number>",inherits:!1,initialValue:"0"}),CSS.registerProperty({name:S,syntax:"<length>",inherits:!0,initialValue:"0px"}),CSS.registerProperty({name:k,syntax:"<number>",inherits:!1,initialValue:"0"}),CSS.registerProperty({name:U,syntax:"<number>",inherits:!0,initialValue:"0"}),!0}catch{return!1}})(),j="var(--number-flow-char-height, 1em)",f="var(--number-flow-mask-height, 0.25em)",A=`calc(${f} / 2)`,R="var(--number-flow-mask-width, 0.5em)",m=`calc(${R} / var(--scale-x))`,v="#000 0, transparent 71%",Z=W`:host{display:inline-block;direction:ltr;white-space:nowrap;isolation:isolate;line-height:${j} !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(${k}) / var(--width));transform:translateX(var(${S})) scaleX(var(--scale-x));margin:0 calc(-1 * ${R});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,${v}),radial-gradient(at bottom left,${v}),radial-gradient(at top left,${v}),radial-gradient(at top right,${v});-webkit-mask-size:100% calc(100% - ${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:${A} ${R};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(${U})}.digit__num,.number .section::after{padding:${A} 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(${$}))}`,N=_.BROWSER?HTMLElement:class{},J=W`:host{display:inline-block;direction:ltr;white-space:nowrap;line-height:${j} !important}span{display:inline-block}:host([data-will-change]) span{will-change:transform}.number,.digit{padding:${A} 0}.symbol{white-space:pre}`,Q=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>`,w=(n,t)=>`<span part="${t}">${n.reduce((e,i)=>e+Q(i),"")}</span>`,tt=n=>q`<template shadowroot="open" shadowrootmode="open"
|
|
2
|
+
><style>
|
|
3
|
+
${J}</style
|
|
4
|
+
><span role="img" aria-label="${n.valueAsString}"
|
|
5
|
+
>${w(n.pre,"left")}<span part="number" class="number"
|
|
6
|
+
>${w(n.integer,"integer")}${w(n.fraction,"fraction")}</span
|
|
7
|
+
>${w(n.post,"right")}</span
|
|
8
|
+
></template
|
|
9
|
+
><span
|
|
10
|
+
style="font-kerning: none; display: inline-block; line-height: ${j} !important; padding: ${f} 0;"
|
|
11
|
+
>${n.valueAsString}</span
|
|
12
|
+
>`,V=G&&Y&&K;class B extends N{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 o;if(t==null)return;const{pre:e,integer:i,fraction:s,post:a,value:r}=t;if(this.created){const c=this._data;this._data=t,this.computedTrend=typeof this.trend=="function"?this.trend(c.value,r):this.trend,this.computedAnimated=V&&this._animated&&(!this.respectMotionPreference||!(b!=null&&b.matches))&&F(this),(o=this.plugins)==null||o.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{this._data=t,this.attachShadow({mode:"open"});try{this._internals??(this._internals=this.attachInternals()),this._internals.role="img"}catch{}const c=document.createElement("style");c.textContent=Z,this.shadowRoot.appendChild(c),this._pre=new L(this,e,{justify:"right",part:"left"}),this.shadowRoot.appendChild(this._pre.el),this._num=new et(this,i,s),this.shadowRoot.appendChild(this._num.el),this._post=new L(this,a,{justify:"left",part:"right"}),this.shadowRoot.appendChild(this._post.el),this.created=!0}try{this._internals.ariaLabel=t.valueAsString}catch{}}willUpdate(){this._pre.willUpdate(),this._num.willUpdate(),this._post.willUpdate()}didUpdate(){if(!this.computedAnimated)return;this._abortAnimationsFinish?this._abortAnimationsFinish.abort():this.dispatchEvent(new Event("animationsstart")),this._pre.didUpdate(),this._num.didUpdate(),this._post.didUpdate();const t=new AbortController;Promise.all(this.shadowRoot.getAnimations().map(e=>e.finished)).then(()=>{t.signal.aborted||(this.dispatchEvent(new Event("animationsfinish")),this._abortAnimationsFinish=void 0)}),this._abortAnimationsFinish=t}}B.defaultProps={transformTiming:{duration:900,easing:"linear(0,.005,.019,.039,.066,.096,.129,.165,.202,.24,.278,.316,.354,.39,.426,.461,.494,.526,.557,.586,.614,.64,.665,.689,.711,.731,.751,.769,.786,.802,.817,.831,.844,.856,.867,.877,.887,.896,.904,.912,.919,.925,.931,.937,.942,.947,.951,.955,.959,.962,.965,.968,.971,.973,.976,.978,.98,.981,.983,.984,.986,.987,.988,.989,.99,.991,.992,.992,.993,.994,.994,.995,.995,.996,.996,.9963,.9967,.9969,.9972,.9975,.9977,.9979,.9981,.9982,.9984,.9985,.9987,.9988,.9989,1)"},spinTiming:void 0,opacityTiming:{duration:450,easing:"ease-out"},animated:!0,trend:(n,t)=>Math.sign(t-n),respectMotionPreference:!0,plugins:void 0,digits:void 0};class et{constructor(t,e,i,{className:s,...a}={}){this.flow=t,this._integer=new P(t,e,{justify:"right",part:"integer"}),this._fraction=new P(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({[S]:[`${e}px`,"0px"],[k]:[s,0]},{...this.flow.transformTiming,composite:"accumulate"})}}class D{constructor(t,e,{justify:i,className:s,...a},r){this.flow=t,this.children=new Map,this.onCharRemove=c=>()=>{this.children.delete(c)},this.justify=i;const o=e.map(c=>this.addChar(c).el);this.el=u("span",{...a,className:`section section--justify-${i} ${s??""}`},r?r(o):o)}addChar(t,{startDigitsAtZero:e=!1,...i}={}){const s=t.type==="integer"||t.type==="fraction"?new T(this,t.type,e?0:t.value,t.pos,{...i,onRemove:this.onCharRemove(t.key)}):new it(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]=`${O(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(X(t,r=>{let o;this.children.has(r.key)?(o=this.children.get(r.key),i.set(r,o),this.unpop(o),o.present=!0):(o=this.addChar(r,{startDigitsAtZero:!0,animateIn:!0}),e.set(r,o)),this.el[a](o.el)},{reverse:s}),this.flow.computedAnimated){const r=this.el.getBoundingClientRect();e.forEach(o=>{o.willUpdate(r)})}e.forEach((r,o)=>{r.update(o.value)}),i.forEach((r,o)=>{r.update(o.value)})}willUpdate(){const t=this.el.getBoundingClientRect();this._prevOffset=t[this.justify],this.children.forEach(e=>e.willUpdate(t))}didUpdate(){const t=this.el.getBoundingClientRect();this.children.forEach(s=>s.didUpdate(t));const e=t[this.justify],i=this._prevOffset-e;i&&this.children.size&&this.el.animate({transform:[`translateX(${i}px)`,"none"]},{...this.flow.transformTiming,composite:"accumulate"})}}class P extends D{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 T&&i.update(0)}),this.pop(e)}}class L extends D{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 C{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 H extends C{constructor(t,e,i,s){super(t.flow,i,s),this.section=t,this.value=e,this.el=i}}class T extends H{constructor(t,e,i,s,a){var d,p;const r=(((p=(d=t.flow.digits)==null?void 0:d[s])==null?void 0:p.max)??9)+1,o=Array.from({length:r}).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"},o);c.style.setProperty("--current",String(i)),c.style.setProperty("--length",String(r)),super(t,i,c,a),this.pos=s,this._onAnimationsFinish=()=>{this.el.classList.remove("is-spinning")},this._numbers=o,this.length=r}willUpdate(t){const e=this.el.getBoundingClientRect();this._prevValue=this.value;const i=e[this.section.justify]-t[this.section.justify],s=e.width/2;this._prevCenter=this.section.justify==="left"?i+s:i-s}update(t){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,r=this._prevCenter-a;r&&this.el.animate({transform:[`translateX(${r}px)`,"none"]},{...this.flow.transformTiming,composite:"accumulate"});const o=this.getDelta();o&&(this.el.classList.add("is-spinning"),this.el.animate({[U]:[-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 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 it extends H{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=r=>()=>{this._children.delete(r)},this._children.set(i,new C(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 C(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=T;exports.NumberFlowLite=B;exports.ServerSafeHTMLElement=N;exports.canAnimate=V;exports.define=I;exports.formatToData=z;exports.prefersReducedMotion=b;exports.renderInnerHTML=tt;
|
package/dist/lite.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("./lite-
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("./lite-DH1kEhrb.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
CHANGED
package/package.json
CHANGED
package/dist/lite-B8p0lZvR.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
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(r=>i.appendChild(r)),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=[],r=[],o=[],c=[],d={},p=h=>`${h}:${d[h]=(d[h]??-1)+1}`;let x="",g=!1,y=!1;for(const h of s){x+=h.value;const l=h.type==="minusSign"||h.type==="plusSign"?"sign":h.type;l==="integer"?(g=!0,r.push(...h.value.split("").map(R=>({type:l,value:parseInt(R)})))):l==="group"?r.push({type:l,value:h.value}):l==="decimal"?(y=!0,o.push({type:l,value:h.value,key:p(l)})):l==="fraction"?o.push(...h.value.split("").map(R=>({type:l,value:parseInt(R),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=r.length-1;h>=0;h--){const l=r[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:o,post:c,valueAsString:x,value:typeof n=="string"?parseFloat(n):n}}const G=String.raw,V=String.raw,K=_.BROWSER&&(()=>{try{document.createElement("div").animate({opacity:0},{easing:"linear(0, 1)"})}catch{return!1}return!0})(),Z=_.BROWSER&&typeof CSS<"u"&&CSS.supports&&CSS.supports("line-height","mod(1,1)"),$=_.BROWSER&&typeof matchMedia<"u"?matchMedia("(prefers-reduced-motion: reduce)"):null,S="--_number-flow-d-opacity",U="--_number-flow-d-width",E="--_number-flow-dx",j="--_number-flow-d",J=(()=>{try{return CSS.registerProperty({name:S,syntax:"<number>",inherits:!1,initialValue:"0"}),CSS.registerProperty({name:E,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)",C=`calc(${f} / 2)`,A="var(--number-flow-mask-width, 0.5em)",m=`calc(${A} / var(--scale-x))`,v="#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(${E})) 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,${v}),radial-gradient(at bottom left,${v}),radial-gradient(at top left,${v}),radial-gradient(at top right,${v});-webkit-mask-size:100% calc(100% - ${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:${C} ${A};transform:scaleX(calc(1 / var(--scale-x))) translateX(calc(-1 * var(${E})))}: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:${C} 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(${S}))}`,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:${C} 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>`,w=(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
|
-
>${w(n.pre,"left")}<span part="number" class="number"
|
|
6
|
-
>${w(n.integer,"integer")}${w(n.fraction,"fraction")}</span
|
|
7
|
-
>${w(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 o;if(t==null)return;const{pre:e,integer:i,fraction:s,post:a,value:r}=t;if(this.created){const c=this._data;this._data=t,this.computedTrend=typeof this.trend=="function"?this.trend(c.value,r):this.trend,this.computedAnimated=D&&this._animated&&(!this.respectMotionPreference||!($!=null&&$.matches))&&X(this),(o=this.plugins)==null||o.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{this._data=t,this.attachShadow({mode:"open"});try{this._internals??(this._internals=this.attachInternals()),this._internals.role="img"}catch{}if(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}try{this._internals.ariaLabel=t.valueAsString}catch{}}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({[E]:[`${e}px`,"0px"],[U]:[s,0]},{...this.flow.transformTiming,composite:"accumulate"})}}class O{constructor(t,e,{justify:i,className:s,...a},r){this.flow=t,this.children=new Map,this.onCharRemove=c=>()=>{this.children.delete(c)},this.justify=i;const o=e.map(c=>this.addChar(c).el);this.el=u("span",{...a,className:`section section--justify-${i} ${s??""}`},r?r(o):o)}addChar(t,{startDigitsAtZero:e=!1,...i}={}){const s=t.type==="integer"||t.type==="fraction"?new 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,r=>{let o;this.children.has(r.key)?(o=this.children.get(r.key),i.set(r,o),this.unpop(o),o.present=!0):(o=this.addChar(r,{startDigitsAtZero:!0,animateIn:!0}),e.set(r,o)),this.el[a](o.el)},{reverse:s}),this.flow.computedAnimated){const r=this.el.getBoundingClientRect();e.forEach(o=>{o.willUpdate(r)})}e.forEach((r,o)=>{r.update(o.value)}),i.forEach((r,o)=>{r.update(o.value)})}willUpdate(){const t=this.el.getBoundingClientRect();this._prevOffset=t[this.justify],this.children.forEach(e=>e.willUpdate(t))}didUpdate(){const t=this.el.getBoundingClientRect();this.children.forEach(s=>s.didUpdate(t));const e=t[this.justify],i=this._prevOffset-e;i&&this.children.size&&this.el.animate({transform:[`translateX(${i}px)`,"none"]},{...this.flow.transformTiming,composite:"accumulate"})}}class 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({[S]:[-.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({[S]: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 r=(((p=(d=t.flow.digits)==null?void 0:d[s])==null?void 0:p.max)??9)+1,o=Array.from({length:r}).map((x,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"},o);c.style.setProperty("--current",String(i)),c.style.setProperty("--length",String(r)),super(t,i,c,a),this.pos=s,this._onAnimationsFinish=()=>{this.el.classList.remove("is-spinning")},this._numbers=o,this.length=r}willUpdate(t){const e=this.el.getBoundingClientRect();this._prevValue=this.value;const i=e[this.section.justify]-t[this.section.justify],s=e.width/2;this._prevCenter=this.section.justify==="left"?i+s:i-s}update(t){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,r=this._prevCenter-a;r&&this.el.animate({transform:[`translateX(${r}px)`,"none"]},{...this.flow.transformTiming,composite:"accumulate"});const o=this.getDelta();o&&(this.el.classList.add("is-spinning"),this.el.animate({[j]:[-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 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=r=>()=>{this._children.delete(r)},this._children.set(i,new k(this.flow,a,{onRemove:this._onChildRemove(i)}))}willUpdate(t){if(this.type==="decimal")return;const e=this.el.getBoundingClientRect();this._prevOffset=e[this.section.justify]-t[this.section.justify]}update(t){if(this.value!==t){const e=this._children.get(this.value);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=$;exports.renderInnerHTML=et;
|