number-flow 0.2.0 → 0.2.2
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/index.d.ts +0 -4
- package/dist/index.js +1 -439
- package/dist/index.mjs +440 -0
- package/dist/styles.d.ts +2 -2
- package/package.json +7 -5
- package/dist/index.cjs +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -2,10 +2,6 @@ import { type PartitionedParts } from './formatter';
|
|
|
2
2
|
import { ServerSafeHTMLElement } from './ssr';
|
|
3
3
|
export { SlottedTag, slottedStyles, supportsAnimationComposition, supportsLinear } from './styles';
|
|
4
4
|
export * from './formatter';
|
|
5
|
-
export declare const defaultXTimingLinearDuration = 900;
|
|
6
|
-
export declare const defaultXTimingLinearPoints: number[];
|
|
7
|
-
export declare const defaultXTimingFallbackDuration = 900;
|
|
8
|
-
export declare const defaultXTimingFallbackPoints: number[];
|
|
9
5
|
export declare const defaultFadeTiming: EffectTiming;
|
|
10
6
|
export declare const defaultXTiming: EffectTiming;
|
|
11
7
|
export declare const defaultYTiming: EffectTiming;
|
package/dist/index.js
CHANGED
|
@@ -1,439 +1 @@
|
|
|
1
|
-
var ut = Object.defineProperty;
|
|
2
|
-
var Q = (n) => {
|
|
3
|
-
throw TypeError(n);
|
|
4
|
-
};
|
|
5
|
-
var mt = (n, i, t) => i in n ? ut(n, i, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[i] = t;
|
|
6
|
-
var u = (n, i, t) => mt(n, typeof i != "symbol" ? i + "" : i, t), tt = (n, i, t) => i.has(n) || Q("Cannot " + t);
|
|
7
|
-
var o = (n, i, t) => (tt(n, i, "read from private field"), t ? t.call(n) : i.get(n)), r = (n, i, t) => i.has(n) ? Q("Cannot add the same private member more than once") : i instanceof WeakSet ? i.add(n) : i.set(n, t), h = (n, i, t, s) => (tt(n, i, "write to private field"), s ? s.call(n, t) : i.set(n, t), t);
|
|
8
|
-
import { BROWSER as Y } from "esm-env";
|
|
9
|
-
const y = (n, i, t) => {
|
|
10
|
-
const s = document.createElement(n), [e, a] = Array.isArray(i) ? [void 0, i] : [i, t];
|
|
11
|
-
return e && Object.assign(s, e), a == null || a.forEach((l) => s.appendChild(l)), s;
|
|
12
|
-
}, gt = (n, i) => {
|
|
13
|
-
typeof Element.prototype.replaceChildren > "u" ? (n.innerHTML = "", i.forEach((t) => n.appendChild(t))) : n.replaceChildren(...i);
|
|
14
|
-
}, yt = (n, i) => {
|
|
15
|
-
var t;
|
|
16
|
-
return i === "left" ? n.offsetLeft : (((t = n.offsetParent instanceof HTMLElement ? n.offsetParent : null) == null ? void 0 : t.offsetWidth) ?? 0) - n.offsetWidth - n.offsetLeft;
|
|
17
|
-
};
|
|
18
|
-
function wt(n, i, { reverse: t = !1 } = {}) {
|
|
19
|
-
const s = n.length;
|
|
20
|
-
for (let e = t ? s - 1 : 0; t ? e >= 0 : e < s; t ? e-- : e++)
|
|
21
|
-
i(n[e], e);
|
|
22
|
-
}
|
|
23
|
-
function Nt(n, i) {
|
|
24
|
-
const t = i.formatToParts(n), s = [], e = [], a = [], l = [], f = {}, c = (p) => (f[p] || (f[p] = 0), `${p}:${f[p]++}`);
|
|
25
|
-
let d = "", x = !1, U = !1;
|
|
26
|
-
for (const p of t) {
|
|
27
|
-
d += p.value;
|
|
28
|
-
const m = p.type === "minusSign" || p.type === "plusSign" ? "sign" : p.type;
|
|
29
|
-
m === "integer" ? (x = !0, e.push(...p.value.split("").map((q) => ({ type: m, value: parseInt(q) })))) : m === "group" ? e.push({ type: m, value: p.value }) : m === "decimal" ? (U = !0, a.push({ type: m, value: p.value, key: c(m) })) : m === "fraction" ? a.push(...p.value.split("").map((q) => ({ type: m, value: parseInt(q), key: c(m) }))) : (x || U ? l : s).push({
|
|
30
|
-
type: m,
|
|
31
|
-
value: p.value,
|
|
32
|
-
key: c(m)
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
const _ = [];
|
|
36
|
-
for (let p = e.length - 1; p >= 0; p--)
|
|
37
|
-
_.unshift({ ...e[p], key: c(e[p].type) });
|
|
38
|
-
return { pre: s, integer: _, fraction: a, post: l, formatted: d };
|
|
39
|
-
}
|
|
40
|
-
const xt = Y ? HTMLElement : class {
|
|
41
|
-
}, _t = String.raw, bt = Y && typeof CSS < "u" && CSS.supports("transition-timing-function", "linear(1, 2)"), rt = Y && typeof CSS < "u" && typeof CSS.registerProperty < "u", et = Y && typeof CSS < "u" && typeof CSS.supports("animation-composition", "accumulate") < "u";
|
|
42
|
-
if (rt)
|
|
43
|
-
try {
|
|
44
|
-
CSS.registerProperty({
|
|
45
|
-
name: "--_number-flow-scale-x",
|
|
46
|
-
syntax: "<number>",
|
|
47
|
-
inherits: !1,
|
|
48
|
-
initialValue: "1"
|
|
49
|
-
});
|
|
50
|
-
} catch {
|
|
51
|
-
}
|
|
52
|
-
const ct = "var(--number-flow-char-height, 1em)", g = "var(--number-flow-mask-height, 0.15em)", E = "var(--number-flow-mask-width, 0.5em)", Z = `${E} * 1/var(--_number-flow-scale-x)`, it = `calc(${Z})`, st = `linear-gradient(to bottom, transparent 0, #000 ${g}, #000 calc(100% - ${g}), transparent 100%)`, K = "#000 0, transparent 71%", kt = "span", Bt = {
|
|
53
|
-
fontKerning: "none",
|
|
54
|
-
display: "inline-block",
|
|
55
|
-
lineHeight: ct,
|
|
56
|
-
padding: `${g} 0`
|
|
57
|
-
}, nt = _t`:host{display:inline-block;direction:ltr;user-select:none;pointer-events:none;white-space:nowrap;position:relative;line-height:${ct} !important;isolation:isolate;}::slotted(${kt}){position:absolute;left:0;top:0;color:transparent !important;z-index:-1;user-select:text;pointer-events:auto;}.section{display:inline-block;padding-bottom:${g};padding-top:${g};vertical-align:top;user-select:none;}.section:not(.section--masked),.section--masked .section__inner{position:relative;isolation:isolate;}.section__inner{display:inline-block;transform-origin:inherit;}.section--justify-left{transform-origin:center left;}.section--justify-right{transform-origin:center right;}.section--masked{overflow:clip;position:relative;z-index:-1;--_number-flow-scale-x:1;-webkit-mask-repeat:no-repeat;-webkit-mask-size:calc(100% - ${Z}) 100%,100% calc(100% - ${g} * 2),${it} ${g},${it} ${g};}.section--masked.section--justify-left{padding-right:${E};margin-right:calc(-1 * ${E});-webkit-mask-image:${st},linear-gradient(to right,#000 0,#000 calc(100% - ${Z}),transparent 100%),radial-gradient(at bottom left,${K}),radial-gradient(at top left,${K});-webkit-mask-position:left,center,right top,right bottom;}.section--masked.section--justify-right{padding-left:${E};margin-left:calc(-1 * ${E});-webkit-mask-image:${st},linear-gradient(to left,#000 0,#000 calc(100% - ${Z}),transparent 100%),radial-gradient(at bottom right,${K}),radial-gradient(at top right,${K});-webkit-mask-position:right,center,left top,left bottom;}.section__exiting{position:absolute !important;z-index:-1;}.digit{display:inline-block;position:relative;}.digit__stack{display:flex;flex-direction:column;align-items:center;gap:${g};position:absolute;width:100%;}.digit__stack > *{display:inline-block;}.digit__lt{bottom:calc(100% + ${g});}.digit__gt{top:calc(100% + ${g});}.symbol{display:inline-block;position:relative;isolation:isolate;}.symbol__value{display:inline-block;white-space:pre;}.symbol__exiting{position:absolute;z-index:-1;}.section--justify-left .symbol__exiting{left:0;}.section--justify-right .symbol__exiting{right:0;}`;
|
|
58
|
-
function Ct(n, i, t = 60) {
|
|
59
|
-
const s = Math.trunc(n / 1e3 * t);
|
|
60
|
-
return Array.from({ length: s }, (e, a) => i(a / (s - 1)));
|
|
61
|
-
}
|
|
62
|
-
function $t(n, i, t = 60) {
|
|
63
|
-
if (rt)
|
|
64
|
-
return [i(0), i(1)];
|
|
65
|
-
const s = Math.max(Math.trunc(n / 1e3 * t), 0), e = Array.from({ length: s }, (a, l) => ({
|
|
66
|
-
...i(l / s),
|
|
67
|
-
offset: (l + 0.5) / s
|
|
68
|
-
}));
|
|
69
|
-
return e.unshift({
|
|
70
|
-
...i(0),
|
|
71
|
-
offset: 0
|
|
72
|
-
}), e;
|
|
73
|
-
}
|
|
74
|
-
const ot = (n, i, t) => n + (i - n) * t, vt = 900, St = [0, 0.0050235113985758065, 0.018768235438646315, 0.0394665067267097, 0.06561435806809059, 0.09593671402266707, 0.12935688367555642, 0.16496984329827014, 0.2020188582086, 0.2398750451603972, 0.2780195227408494, 0.316027838175776, 0.35355639522427323, 0.3903306400002338, 0.42613479005042487, 0.4608029172568362, 0.494211217479539, 0.5262713196397582, 0.5569245044497536, 0.5861367184830215, 0.6138942829733466, 0.6402002088371546, 0.6650710401106178, 0.688534157441182, 0.7106254816148533, 0.7313875244620506, 0.7508677409782638, 0.7691171422207626, 0.7861891335875677, 0.8021385475282429, 0.8170208436473976, 0.830891452602792, 0.8438052432253264, 0.8558160949464902, 0.8669765599529741, 0.8773376015362415, 0.8869483969005642, 0.8958561942662493, 0.9041062154819053, 0.9117415965639958, 0.9188033596342844, 0.9253304106443357, 0.9313595580771787, 0.9369255485137984, 0.9420611155589194, 0.9467970391476751, 0.9511622127120402, 0.9551837160819846, 0.9588868923388109, 0.9622954271337615, 0.9654314292396703, 0.9683155113223428, 0.9709668701061009, 0.9734033652684989, 0.9756415965361696, 0.9776969785701735, 0.9795838133278193, 0.9813153596710892, 0.9829039000616127, 0.9843608042404175, 0.985696589839041, 0.986920979908387, 0.9880429573842098, 0.989070816534304, 0.990012211453356, 0.9908742016877166, 0.9916632950848158, 0.9923854879711473, 0.9930463027692117, 0.9936508231680027, 0.994203726963899, 0.9947093166895601, 0.9951715481478591, 0.9955940569663103, 0.9959801832850321, 0.9963329946882337, 0.9966553074856583, 0.9969497064465007, 0.9972185630841328, 0.9974640525856172, 0.9976881694755444, 0.9978927420992383, 0.9980794460059083, 0.998249816307907, 0.9984052590879293, 0.998547061921768, 0.9986764035801687, 0.9987943629693811, 0.9989019273662413, 1], jt = 900, Rt = [0.32, 0.72, 0, 1], Ut = { duration: 500, easing: "ease-out" }, ht = bt ? {
|
|
75
|
-
duration: vt,
|
|
76
|
-
easing: `linear(${St.join(",")})`
|
|
77
|
-
} : {
|
|
78
|
-
duration: jt,
|
|
79
|
-
// Spring-like cubic-bezier stolen from Vaul: https://vaul.emilkowal.ski/
|
|
80
|
-
easing: `cubic-bezier(${Rt.join(",")})`
|
|
81
|
-
}, Et = ht;
|
|
82
|
-
let G;
|
|
83
|
-
var T, b, k, C, $;
|
|
84
|
-
class Lt extends xt {
|
|
85
|
-
constructor() {
|
|
86
|
-
super(...arguments);
|
|
87
|
-
u(this, "xTiming", ht);
|
|
88
|
-
u(this, "yTiming", Et);
|
|
89
|
-
u(this, "fadeTiming", Ut);
|
|
90
|
-
u(this, "root", !1);
|
|
91
|
-
u(this, "manual", !1);
|
|
92
|
-
r(this, T, !1);
|
|
93
|
-
r(this, b);
|
|
94
|
-
r(this, k);
|
|
95
|
-
r(this, C);
|
|
96
|
-
r(this, $);
|
|
97
|
-
}
|
|
98
|
-
static define() {
|
|
99
|
-
Y && customElements.define("number-flow", this);
|
|
100
|
-
}
|
|
101
|
-
set parts(t) {
|
|
102
|
-
if (t == null)
|
|
103
|
-
return;
|
|
104
|
-
const { pre: s, integer: e, fraction: a, post: l } = t;
|
|
105
|
-
if (o(this, T))
|
|
106
|
-
this.manual || this.willUpdate(), o(this, b).update(s), o(this, k).update(e), o(this, C).update(a), o(this, $).update(l), this.manual || this.didUpdate();
|
|
107
|
-
else {
|
|
108
|
-
if (this.attachShadow({ mode: "open" }), typeof CSSStyleSheet < "u" && this.shadowRoot.adoptedStyleSheets)
|
|
109
|
-
G || (G = new CSSStyleSheet(), G.replaceSync(nt)), this.shadowRoot.adoptedStyleSheets = [G];
|
|
110
|
-
else {
|
|
111
|
-
const f = document.createElement("style");
|
|
112
|
-
f.textContent = nt, this.shadowRoot.appendChild(f);
|
|
113
|
-
}
|
|
114
|
-
this.shadowRoot.appendChild(y("slot")), h(this, b, new lt(this, s, {
|
|
115
|
-
// part: 'pre',
|
|
116
|
-
inert: !0,
|
|
117
|
-
ariaHidden: "true",
|
|
118
|
-
justify: "right"
|
|
119
|
-
})), this.shadowRoot.appendChild(o(this, b).el), h(this, k, new at(this, e, {
|
|
120
|
-
// part: 'integer',
|
|
121
|
-
inert: !0,
|
|
122
|
-
ariaHidden: "true",
|
|
123
|
-
justify: "right"
|
|
124
|
-
})), this.shadowRoot.appendChild(o(this, k).el), h(this, C, new at(this, a, {
|
|
125
|
-
// part: 'fraction',
|
|
126
|
-
inert: !0,
|
|
127
|
-
ariaHidden: "true",
|
|
128
|
-
justify: "left"
|
|
129
|
-
})), this.shadowRoot.appendChild(o(this, C).el), h(this, $, new lt(this, l, {
|
|
130
|
-
// part: 'post',
|
|
131
|
-
inert: !0,
|
|
132
|
-
ariaHidden: "true",
|
|
133
|
-
justify: "left"
|
|
134
|
-
})), this.shadowRoot.appendChild(o(this, $).el);
|
|
135
|
-
}
|
|
136
|
-
h(this, T, !0);
|
|
137
|
-
}
|
|
138
|
-
willUpdate() {
|
|
139
|
-
const t = this.root ? this.getBoundingClientRect() : new DOMRect();
|
|
140
|
-
o(this, b).willUpdate(t), o(this, k).willUpdate(t), o(this, C).willUpdate(t), o(this, $).willUpdate(t);
|
|
141
|
-
}
|
|
142
|
-
didUpdate() {
|
|
143
|
-
const t = this.root ? this.getBoundingClientRect() : new DOMRect();
|
|
144
|
-
o(this, b).didUpdate(t), o(this, k).didUpdate(t), o(this, C).didUpdate(t), o(this, $).didUpdate(t);
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
T = new WeakMap(), b = new WeakMap(), k = new WeakMap(), C = new WeakMap(), $ = new WeakMap();
|
|
148
|
-
class dt {
|
|
149
|
-
constructor(i, t, { justify: s, className: e, ...a }, l) {
|
|
150
|
-
u(this, "flow");
|
|
151
|
-
u(this, "el");
|
|
152
|
-
u(this, "justify");
|
|
153
|
-
// All children in the DOM:
|
|
154
|
-
u(this, "children", /* @__PURE__ */ new Map());
|
|
155
|
-
u(this, "onCharRemove", (i) => () => {
|
|
156
|
-
this.children.delete(i);
|
|
157
|
-
});
|
|
158
|
-
this.flow = i, this.justify = s;
|
|
159
|
-
const f = t.map((c) => this.addChar(c).el);
|
|
160
|
-
f.push(document.createTextNode("")), this.el = y("span", {
|
|
161
|
-
...a,
|
|
162
|
-
className: `section section--justify-${s} ${e ?? ""}`
|
|
163
|
-
}, l ? l(f) : f);
|
|
164
|
-
}
|
|
165
|
-
addChar(i, { startDigitsAtZero: t = !1, ...s } = {}) {
|
|
166
|
-
const e = i.type === "integer" || i.type === "fraction" ? new pt(this, i.type, t ? 0 : i.value, {
|
|
167
|
-
...s,
|
|
168
|
-
onRemove: this.onCharRemove(i.key)
|
|
169
|
-
}) : new Tt(this, i.type, i.value, {
|
|
170
|
-
...s,
|
|
171
|
-
onRemove: this.onCharRemove(i.key)
|
|
172
|
-
});
|
|
173
|
-
return this.children.set(i.key, e), e;
|
|
174
|
-
}
|
|
175
|
-
unpop(i) {
|
|
176
|
-
i.el.classList.remove("section__exiting"), i.el.style[this.justify] = "";
|
|
177
|
-
}
|
|
178
|
-
pop(i) {
|
|
179
|
-
i.forEach((t) => {
|
|
180
|
-
t.el.style[this.justify] = `${yt(t.el, this.justify)}px`;
|
|
181
|
-
}), i.forEach((t) => {
|
|
182
|
-
t.el.classList.add("section__exiting"), t.present = !1;
|
|
183
|
-
});
|
|
184
|
-
}
|
|
185
|
-
addNewAndUpdateExisting(i, t = this.el) {
|
|
186
|
-
const s = /* @__PURE__ */ new Map(), e = /* @__PURE__ */ new Map(), a = this.justify === "left", l = a ? "prepend" : "append";
|
|
187
|
-
wt(i, (c) => {
|
|
188
|
-
let d;
|
|
189
|
-
this.children.has(c.key) ? (d = this.children.get(c.key), e.set(c, d), this.unpop(d), d.present = !0) : (d = this.addChar(c, { startDigitsAtZero: !0, animateIn: !0 }), s.set(c, d)), t[l](d.el);
|
|
190
|
-
}, { reverse: a });
|
|
191
|
-
const f = t.getBoundingClientRect();
|
|
192
|
-
s.forEach((c) => {
|
|
193
|
-
c.willUpdate(f);
|
|
194
|
-
}), s.forEach((c, d) => {
|
|
195
|
-
c.update(d.value);
|
|
196
|
-
}), e.forEach((c, d) => {
|
|
197
|
-
c.update(d.value);
|
|
198
|
-
});
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
var v, M, A, N, B, L;
|
|
202
|
-
class at extends dt {
|
|
203
|
-
constructor(t, s, { className: e, ...a }) {
|
|
204
|
-
let l;
|
|
205
|
-
super(t, s, {
|
|
206
|
-
...a,
|
|
207
|
-
className: `${e ?? ""} section--masked`
|
|
208
|
-
}, (f) => [
|
|
209
|
-
l = y("span", {
|
|
210
|
-
className: "section__inner"
|
|
211
|
-
}, f)
|
|
212
|
-
]);
|
|
213
|
-
r(this, v);
|
|
214
|
-
r(this, M);
|
|
215
|
-
r(this, A);
|
|
216
|
-
r(this, N);
|
|
217
|
-
r(this, B);
|
|
218
|
-
r(this, L);
|
|
219
|
-
h(this, v, l);
|
|
220
|
-
}
|
|
221
|
-
willUpdate(t) {
|
|
222
|
-
const s = this.el.getBoundingClientRect();
|
|
223
|
-
h(this, M, s.width), h(this, A, s[this.justify] - t[this.justify]);
|
|
224
|
-
const e = o(this, v).getBoundingClientRect();
|
|
225
|
-
this.children.forEach((a) => a.willUpdate(e));
|
|
226
|
-
}
|
|
227
|
-
update(t) {
|
|
228
|
-
const s = /* @__PURE__ */ new Map();
|
|
229
|
-
this.children.forEach((e, a) => {
|
|
230
|
-
t.find((l) => l.key === a) || s.set(a, e), this.unpop(e);
|
|
231
|
-
}), this.addNewAndUpdateExisting(t, o(this, v)), s.forEach((e) => {
|
|
232
|
-
e instanceof pt && e.update(0);
|
|
233
|
-
}), this.pop(s);
|
|
234
|
-
}
|
|
235
|
-
didUpdate(t) {
|
|
236
|
-
var c, d, x, U;
|
|
237
|
-
(c = o(this, N)) == null || c.cancel(), (d = o(this, L)) == null || d.cancel(), (x = o(this, B)) == null || x.cancel();
|
|
238
|
-
const s = this.el.getBoundingClientRect(), e = s[this.justify] - t[this.justify], a = o(this, A) - e, l = Math.max(o(this, M), 0.01) / Math.max(s.width, 0.01), f = o(this, v).getBoundingClientRect();
|
|
239
|
-
this.children.forEach((_) => _.didUpdate(f)), h(this, N, this.el.animate({
|
|
240
|
-
transform: [`translateX(${a}px) scaleX(${l})`, "none"]
|
|
241
|
-
}, this.flow.xTiming)), l !== 1 && (h(this, L, (U = o(this, v)) == null ? void 0 : U.animate({
|
|
242
|
-
// 1/x isn't linear so we need to do sampling:
|
|
243
|
-
transform: Ct(1e3, (_) => `scaleX(${1 / ot(l, 1, _)})`)
|
|
244
|
-
}, this.flow.xTiming)), h(this, B, this.el.animate($t(1e3, (_) => ({
|
|
245
|
-
"--_number-flow-scale-x": ot(l, 1, _)
|
|
246
|
-
})), this.flow.xTiming)));
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
v = new WeakMap(), M = new WeakMap(), A = new WeakMap(), N = new WeakMap(), B = new WeakMap(), L = new WeakMap();
|
|
250
|
-
var P, H;
|
|
251
|
-
class lt extends dt {
|
|
252
|
-
constructor() {
|
|
253
|
-
super(...arguments);
|
|
254
|
-
r(this, P);
|
|
255
|
-
r(this, H);
|
|
256
|
-
}
|
|
257
|
-
willUpdate(t) {
|
|
258
|
-
const s = this.el.getBoundingClientRect();
|
|
259
|
-
h(this, P, s[this.justify] - t[this.justify]), this.children.forEach((e) => e.willUpdate(s));
|
|
260
|
-
}
|
|
261
|
-
update(t) {
|
|
262
|
-
const s = /* @__PURE__ */ new Map();
|
|
263
|
-
this.children.forEach((e, a) => {
|
|
264
|
-
t.find((l) => l.key === a) || s.set(a, e);
|
|
265
|
-
}), this.pop(s), this.addNewAndUpdateExisting(t);
|
|
266
|
-
}
|
|
267
|
-
didUpdate(t) {
|
|
268
|
-
var a;
|
|
269
|
-
(a = o(this, H)) == null || a.cancel();
|
|
270
|
-
const s = this.el.getBoundingClientRect(), e = s[this.justify] - t[this.justify];
|
|
271
|
-
this.children.forEach((l) => l.didUpdate(s)), h(this, H, this.el.animate({
|
|
272
|
-
transform: [`translateX(${o(this, P) - e}px)`, "none"]
|
|
273
|
-
}, this.flow.xTiming));
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
P = new WeakMap(), H = new WeakMap();
|
|
277
|
-
var j, X, R;
|
|
278
|
-
class J {
|
|
279
|
-
constructor(i, t, { onRemove: s, animateIn: e = !1 } = {}) {
|
|
280
|
-
u(this, "flow");
|
|
281
|
-
u(this, "el");
|
|
282
|
-
r(this, j, !0);
|
|
283
|
-
r(this, X);
|
|
284
|
-
r(this, R);
|
|
285
|
-
this.flow = i, this.el = t, e && this.el.animate({
|
|
286
|
-
opacity: ["0", "1"]
|
|
287
|
-
}, i.fadeTiming), h(this, X, s);
|
|
288
|
-
}
|
|
289
|
-
get present() {
|
|
290
|
-
return o(this, j);
|
|
291
|
-
}
|
|
292
|
-
set present(i) {
|
|
293
|
-
var s;
|
|
294
|
-
if (o(this, j) === i)
|
|
295
|
-
return;
|
|
296
|
-
const t = getComputedStyle(this.el).getPropertyValue("opacity");
|
|
297
|
-
(s = o(this, R)) == null || s.cancel(), h(this, R, this.el.animate({
|
|
298
|
-
opacity: [t, i ? "1" : "0"]
|
|
299
|
-
}, this.flow.fadeTiming)), i || (o(this, R).onfinish = () => {
|
|
300
|
-
var e;
|
|
301
|
-
this.el.remove(), (e = o(this, X)) == null || e.call(this);
|
|
302
|
-
}), h(this, j, i);
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
j = new WeakMap(), X = new WeakMap(), R = new WeakMap();
|
|
306
|
-
class ft extends J {
|
|
307
|
-
constructor(t, s, e, a) {
|
|
308
|
-
super(t.flow, e, a);
|
|
309
|
-
u(this, "section");
|
|
310
|
-
u(this, "value");
|
|
311
|
-
u(this, "el");
|
|
312
|
-
this.section = t, this.value = s, this.el = e;
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
var S, W, D, z, O;
|
|
316
|
-
class pt extends ft {
|
|
317
|
-
constructor(t, s, e, a) {
|
|
318
|
-
super(t, e, y("span", {
|
|
319
|
-
className: "digit",
|
|
320
|
-
// part: `digit ${type} ${value}`,
|
|
321
|
-
textContent: e + ""
|
|
322
|
-
}), a);
|
|
323
|
-
r(this, S);
|
|
324
|
-
// Relative to parent:
|
|
325
|
-
r(this, W);
|
|
326
|
-
r(this, D);
|
|
327
|
-
r(this, z);
|
|
328
|
-
r(this, O);
|
|
329
|
-
}
|
|
330
|
-
willUpdate(t) {
|
|
331
|
-
h(this, S, this.value);
|
|
332
|
-
const s = this.el.getBoundingClientRect();
|
|
333
|
-
h(this, W, s.y - t.y);
|
|
334
|
-
const e = s[this.section.justify] - t[this.section.justify], a = s.width / 2;
|
|
335
|
-
h(this, D, this.section.justify === "left" ? e + a : e - a);
|
|
336
|
-
}
|
|
337
|
-
update(t) {
|
|
338
|
-
this.value = t, o(this, S) !== t && gt(this.el, [
|
|
339
|
-
...t === 0 ? [] : [
|
|
340
|
-
y("span", { className: "digit__stack digit__lt" }, Array.from({ length: t }, (s, e) => y("span", { textContent: e + "" })))
|
|
341
|
-
],
|
|
342
|
-
document.createTextNode(t + ""),
|
|
343
|
-
...t === 9 ? [] : [
|
|
344
|
-
y("span", { className: "digit__stack digit__gt" }, Array.from({ length: 9 - t }, (s, e) => y("span", { textContent: t + e + 1 + "" })))
|
|
345
|
-
]
|
|
346
|
-
]);
|
|
347
|
-
}
|
|
348
|
-
didUpdate(t) {
|
|
349
|
-
var d, x;
|
|
350
|
-
(d = o(this, z)) == null || d.cancel(), o(this, S) !== this.value && ((x = o(this, O)) == null || x.cancel());
|
|
351
|
-
const s = this.el.getBoundingClientRect(), e = s[this.section.justify] - t[this.section.justify], a = s.width / 2, l = this.section.justify === "left" ? e + a : e - a, f = `translateX(${o(this, D) - l}px)`, c = `translateY(calc((100% + ${g}) * ${this.value - o(this, S)} + ${o(this, W)}px))`;
|
|
352
|
-
h(this, z, this.el.animate({
|
|
353
|
-
transform: [et ? f : `${f} ${c}`, "none"]
|
|
354
|
-
}, {
|
|
355
|
-
...this.flow.xTiming,
|
|
356
|
-
composite: "accumulate"
|
|
357
|
-
// in case there's an in-flight y animation
|
|
358
|
-
})), et && o(this, S) !== this.value && h(this, O, this.el.animate({
|
|
359
|
-
transform: [c, "none"]
|
|
360
|
-
}, {
|
|
361
|
-
...this.flow.yTiming,
|
|
362
|
-
composite: "accumulate"
|
|
363
|
-
}));
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
S = new WeakMap(), W = new WeakMap(), D = new WeakMap(), z = new WeakMap(), O = new WeakMap();
|
|
367
|
-
var w, F, I, V;
|
|
368
|
-
class Tt extends ft {
|
|
369
|
-
constructor(t, s, e, a) {
|
|
370
|
-
const l = y("span", {
|
|
371
|
-
className: "symbol__value",
|
|
372
|
-
textContent: e
|
|
373
|
-
});
|
|
374
|
-
super(t, e, y("span", {
|
|
375
|
-
className: "symbol"
|
|
376
|
-
}, [l]), a);
|
|
377
|
-
u(this, "type");
|
|
378
|
-
r(this, w, /* @__PURE__ */ new Map());
|
|
379
|
-
r(this, F);
|
|
380
|
-
r(this, I, (t) => () => {
|
|
381
|
-
o(this, w).delete(t);
|
|
382
|
-
});
|
|
383
|
-
r(this, V);
|
|
384
|
-
this.type = s, o(this, w).set(e, new J(this.flow, l, {
|
|
385
|
-
onRemove: o(this, I).call(this, e)
|
|
386
|
-
}));
|
|
387
|
-
}
|
|
388
|
-
willUpdate(t) {
|
|
389
|
-
if (this.type === "decimal")
|
|
390
|
-
return;
|
|
391
|
-
const s = this.el.getBoundingClientRect();
|
|
392
|
-
h(this, F, s[this.section.justify] - t[this.section.justify]);
|
|
393
|
-
}
|
|
394
|
-
update(t) {
|
|
395
|
-
if (this.value !== t) {
|
|
396
|
-
const s = o(this, w).get(this.value);
|
|
397
|
-
if (s.present = !1, s.el.classList.add("symbol__exiting"), o(this, w).has(t)) {
|
|
398
|
-
const e = o(this, w).get(t);
|
|
399
|
-
e.present = !0, e.el.classList.remove("symbol__exiting");
|
|
400
|
-
} else {
|
|
401
|
-
const e = y("span", {
|
|
402
|
-
className: "symbol__value",
|
|
403
|
-
textContent: t
|
|
404
|
-
});
|
|
405
|
-
this.el.appendChild(e), o(this, w).set(t, new J(this.flow, e, {
|
|
406
|
-
animateIn: !0,
|
|
407
|
-
onRemove: o(this, I).call(this, t)
|
|
408
|
-
}));
|
|
409
|
-
}
|
|
410
|
-
}
|
|
411
|
-
this.value = t;
|
|
412
|
-
}
|
|
413
|
-
didUpdate(t) {
|
|
414
|
-
var a;
|
|
415
|
-
if (this.type === "decimal")
|
|
416
|
-
return;
|
|
417
|
-
(a = o(this, V)) == null || a.cancel();
|
|
418
|
-
const e = this.el.getBoundingClientRect()[this.section.justify] - t[this.section.justify];
|
|
419
|
-
h(this, V, this.el.animate({
|
|
420
|
-
transform: [`translateX(${o(this, F) - e}px)`, "none"]
|
|
421
|
-
}, this.flow.xTiming));
|
|
422
|
-
}
|
|
423
|
-
}
|
|
424
|
-
w = new WeakMap(), F = new WeakMap(), I = new WeakMap(), V = new WeakMap();
|
|
425
|
-
export {
|
|
426
|
-
Lt as NumberFlowLite,
|
|
427
|
-
kt as SlottedTag,
|
|
428
|
-
Ut as defaultFadeTiming,
|
|
429
|
-
ht as defaultXTiming,
|
|
430
|
-
jt as defaultXTimingFallbackDuration,
|
|
431
|
-
Rt as defaultXTimingFallbackPoints,
|
|
432
|
-
vt as defaultXTimingLinearDuration,
|
|
433
|
-
St as defaultXTimingLinearPoints,
|
|
434
|
-
Et as defaultYTiming,
|
|
435
|
-
Nt as partitionParts,
|
|
436
|
-
Bt as slottedStyles,
|
|
437
|
-
et as supportsAnimationComposition,
|
|
438
|
-
bt as supportsLinear
|
|
439
|
-
};
|
|
1
|
+
"use strict";var wt=Object.defineProperty;var et=n=>{throw TypeError(n)};var xt=(n,i,t)=>i in n?wt(n,i,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[i]=t;var u=(n,i,t)=>xt(n,typeof i!="symbol"?i+"":i,t),it=(n,i,t)=>i.has(n)||et("Cannot "+t);var o=(n,i,t)=>(it(n,i,"read from private field"),t?t.call(n):i.get(n)),r=(n,i,t)=>i.has(n)?et("Cannot add the same private member more than once"):i instanceof WeakSet?i.add(n):i.set(n,t),h=(n,i,t,s)=>(it(n,i,"write to private field"),s?s.call(n,t):i.set(n,t),t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const V=require("esm-env"),y=(n,i,t)=>{const s=document.createElement(n),[e,a]=Array.isArray(i)?[void 0,i]:[i,t];return e&&Object.assign(s,e),a==null||a.forEach(l=>s.appendChild(l)),s},_t=(n,i)=>{typeof Element.prototype.replaceChildren>"u"?(n.innerHTML="",i.forEach(t=>n.appendChild(t))):n.replaceChildren(...i)},bt=(n,i)=>{var t;return i==="left"?n.offsetLeft:(((t=n.offsetParent instanceof HTMLElement?n.offsetParent:null)==null?void 0:t.offsetWidth)??0)-n.offsetWidth-n.offsetLeft};function St(n,i,{reverse:t=!1}={}){const s=n.length;for(let e=t?s-1:0;t?e>=0:e<s;t?e--:e++)i(n[e],e)}function Ct(n,i){const t=i.formatToParts(n),s=[],e=[],a=[],l=[],f={},c=p=>(f[p]||(f[p]=0),`${p}:${f[p]++}`);let d="",x=!1,E=!1;for(const p of t){d+=p.value;const m=p.type==="minusSign"||p.type==="plusSign"?"sign":p.type;m==="integer"?(x=!0,e.push(...p.value.split("").map(Z=>({type:m,value:parseInt(Z)})))):m==="group"?e.push({type:m,value:p.value}):m==="decimal"?(E=!0,a.push({type:m,value:p.value,key:c(m)})):m==="fraction"?a.push(...p.value.split("").map(Z=>({type:m,value:parseInt(Z),key:c(m)}))):(x||E?l:s).push({type:m,value:p.value,key:c(m)})}const _=[];for(let p=e.length-1;p>=0;p--)_.unshift({...e[p],key:c(e[p].type)});return{pre:s,integer:_,fraction:a,post:l,formatted:d}}const vt=V.BROWSER?HTMLElement:class{},kt=String.raw,ct=V.BROWSER&&typeof CSS<"u"&&CSS.supports("transition-timing-function","linear(1, 2)"),ht=V.BROWSER&&typeof CSS<"u"&&typeof CSS.registerProperty<"u",J=V.BROWSER&&typeof CSS<"u"&&typeof CSS.supports("animation-composition","accumulate")<"u";if(ht)try{CSS.registerProperty({name:"--_number-flow-scale-x",syntax:"<number>",inherits:!1,initialValue:"1"})}catch{}const dt="var(--number-flow-char-height, 1em)",g="var(--number-flow-mask-height, 0.25em)",T="var(--number-flow-mask-width, 0.5em)",G=`${T} * 1/var(--_number-flow-scale-x)`,st=`calc(${G})`,nt=`linear-gradient(to bottom, transparent 0, #000 ${g}, #000 calc(100% - ${g}), transparent 100%)`,K="#000 0, transparent 71%",ft="span",$t={fontKerning:"none",display:"inline-block",lineHeight:dt,padding:`${g} 0`},ot=kt`:host{display:inline-block;direction:ltr;user-select:none;pointer-events:none;white-space:nowrap;position:relative;line-height:${dt} !important;isolation:isolate;}::slotted(${ft}){position:absolute;left:0;top:0;color:transparent !important;z-index:-1;user-select:text;pointer-events:auto;}.section{display:inline-block;padding-bottom:${g};padding-top:${g};vertical-align:top;user-select:none;}.section:not(.section--masked),.section--masked .section__inner{position:relative;isolation:isolate;}.section__inner{display:inline-block;transform-origin:inherit;}.section--justify-left{transform-origin:center left;}.section--justify-right{transform-origin:center right;}.section--masked{overflow:clip;position:relative;z-index:-1;--_number-flow-scale-x:1;-webkit-mask-repeat:no-repeat;-webkit-mask-size:calc(100% - ${G}) 100%,100% calc(100% - ${g} * 2),${st} ${g},${st} ${g};}.section--masked.section--justify-left{padding-right:${T};margin-right:calc(-1 * ${T});-webkit-mask-image:${nt},linear-gradient(to right,#000 0,#000 calc(100% - ${G}),transparent 100%),radial-gradient(at bottom left,${K}),radial-gradient(at top left,${K});-webkit-mask-position:left,center,right top,right bottom;}.section--masked.section--justify-right{padding-left:${T};margin-left:calc(-1 * ${T});-webkit-mask-image:${nt},linear-gradient(to left,#000 0,#000 calc(100% - ${G}),transparent 100%),radial-gradient(at bottom right,${K}),radial-gradient(at top right,${K});-webkit-mask-position:right,center,left top,left bottom;}.section__exiting{position:absolute !important;z-index:-1;}.digit{display:inline-block;position:relative;}.digit__stack{display:flex;flex-direction:column;align-items:center;gap:${g};position:absolute;width:100%;}.digit__stack > *{display:inline-block;}.digit__lt{bottom:calc(100% + ${g});}.digit__gt{top:calc(100% + ${g});}.symbol{display:inline-block;position:relative;isolation:isolate;}.symbol__value{display:inline-block;white-space:pre;}.symbol__exiting{position:absolute;z-index:-1;}.section--justify-left .symbol__exiting{left:0;}.section--justify-right .symbol__exiting{right:0;}`;function Rt(n,i,t=60){const s=Math.trunc(n/1e3*t);return Array.from({length:s},(e,a)=>i(a/(s-1)))}function jt(n,i,t=60){if(ht)return[i(0),i(1)];const s=Math.max(Math.trunc(n/1e3*t),0),e=Array.from({length:s},(a,l)=>({...i(l/s),offset:(l+.5)/s}));return e.unshift({...i(0),offset:0}),e}const at=(n,i,t)=>n+(i-n)*t,pt={duration:500,easing:"ease-out",endDelay:400,fill:"forwards"},tt=ct?{duration:900,easing:"linear(0,.005,.019,.039,.066,.096,.129,.165,.202,.24,.278,.316,.354,.39,.426,.461,.494,.526,.557,.586,.614,.64,.665,.689,.711,.731,.751,.769,.786,.802,.817,.831,.844,.856,.867,.877,.887,.896,.904,.912,.919,.925,.931,.937,.942,.947,.951,.955,.959,.962,.965,.968,.971,.973,.976,.978,.98,.981,.983,.984,.986,.987,.988,.989,.99,.991,.992,.992,.993,.994,.994,.995,.995,.996,.996,.9963,.9967,.9969,.9972,.9975,.9977,.9979,.9981,.9982,.9984,.9985,.9987,.9988,.9989,1)"}:{duration:900,easing:"cubic-bezier(.32,.72,0,1)"},ut=tt;let q;var U,b,S,C,v;class Et extends vt{constructor(){super(...arguments);u(this,"xTiming",tt);u(this,"yTiming",ut);u(this,"fadeTiming",pt);u(this,"root",!1);u(this,"manual",!1);r(this,U,!1);r(this,b);r(this,S);r(this,C);r(this,v)}static define(){V.BROWSER&&customElements.define("number-flow",this)}set parts(t){if(t==null)return;const{pre:s,integer:e,fraction:a,post:l}=t;if(o(this,U))this.manual||this.willUpdate(),o(this,b).update(s),o(this,S).update(e),o(this,C).update(a),o(this,v).update(l),this.manual||this.didUpdate();else{if(this.attachShadow({mode:"open"}),typeof CSSStyleSheet<"u"&&this.shadowRoot.adoptedStyleSheets)q||(q=new CSSStyleSheet,q.replaceSync(ot)),this.shadowRoot.adoptedStyleSheets=[q];else{const f=document.createElement("style");f.textContent=ot,this.shadowRoot.appendChild(f)}this.shadowRoot.appendChild(y("slot")),h(this,b,new rt(this,s,{inert:!0,ariaHidden:"true",justify:"right"})),this.shadowRoot.appendChild(o(this,b).el),h(this,S,new lt(this,e,{inert:!0,ariaHidden:"true",justify:"right"})),this.shadowRoot.appendChild(o(this,S).el),h(this,C,new lt(this,a,{inert:!0,ariaHidden:"true",justify:"left"})),this.shadowRoot.appendChild(o(this,C).el),h(this,v,new rt(this,l,{inert:!0,ariaHidden:"true",justify:"left"})),this.shadowRoot.appendChild(o(this,v).el)}h(this,U,!0)}willUpdate(){const t=this.root?this.getBoundingClientRect():new DOMRect;o(this,b).willUpdate(t),o(this,S).willUpdate(t),o(this,C).willUpdate(t),o(this,v).willUpdate(t)}didUpdate(){const t=this.root?this.getBoundingClientRect():new DOMRect;o(this,b).didUpdate(t),o(this,S).didUpdate(t),o(this,C).didUpdate(t),o(this,v).didUpdate(t)}}U=new WeakMap,b=new WeakMap,S=new WeakMap,C=new WeakMap,v=new WeakMap;class mt{constructor(i,t,{justify:s,className:e,...a},l){u(this,"flow");u(this,"el");u(this,"justify");u(this,"children",new Map);u(this,"onCharRemove",i=>()=>{this.children.delete(i)});this.flow=i,this.justify=s;const f=t.map(c=>this.addChar(c).el);f.push(document.createTextNode("")),this.el=y("span",{...a,className:`section section--justify-${s} ${e??""}`},l?l(f):f)}addChar(i,{startDigitsAtZero:t=!1,...s}={}){const e=i.type==="integer"||i.type==="fraction"?new yt(this,i.type,t?0:i.value,{...s,onRemove:this.onCharRemove(i.key)}):new Tt(this,i.type,i.value,{...s,onRemove:this.onCharRemove(i.key)});return this.children.set(i.key,e),e}unpop(i){i.el.classList.remove("section__exiting"),i.el.style[this.justify]=""}pop(i){i.forEach(t=>{t.el.style[this.justify]=`${bt(t.el,this.justify)}px`}),i.forEach(t=>{t.el.classList.add("section__exiting"),t.present=!1})}addNewAndUpdateExisting(i,t=this.el){const s=new Map,e=new Map,a=this.justify==="left",l=a?"prepend":"append";St(i,c=>{let d;this.children.has(c.key)?(d=this.children.get(c.key),e.set(c,d),this.unpop(d),d.present=!0):(d=this.addChar(c,{startDigitsAtZero:!0,animateIn:!0}),s.set(c,d)),t[l](d.el)},{reverse:a});const f=t.getBoundingClientRect();s.forEach(c=>{c.willUpdate(f)}),s.forEach((c,d)=>{c.update(d.value)}),e.forEach((c,d)=>{c.update(d.value)})}}var k,M,A,B,N,L;class lt extends mt{constructor(t,s,{className:e,...a}){let l;super(t,s,{...a,className:`${e??""} section--masked`},f=>[l=y("span",{className:"section__inner"},f)]);r(this,k);r(this,M);r(this,A);r(this,B);r(this,N);r(this,L);h(this,k,l)}willUpdate(t){const s=this.el.getBoundingClientRect();h(this,M,s.width),h(this,A,s[this.justify]-t[this.justify]);const e=o(this,k).getBoundingClientRect();this.children.forEach(a=>a.willUpdate(e))}update(t){const s=new Map;this.children.forEach((e,a)=>{t.find(l=>l.key===a)||s.set(a,e),this.unpop(e)}),this.addNewAndUpdateExisting(t,o(this,k)),s.forEach(e=>{e instanceof yt&&e.update(0)}),this.pop(s)}didUpdate(t){var c,d,x,E;(c=o(this,B))==null||c.cancel(),(d=o(this,L))==null||d.cancel(),(x=o(this,N))==null||x.cancel();const s=this.el.getBoundingClientRect(),e=s[this.justify]-t[this.justify],a=o(this,A)-e,l=Math.max(o(this,M),.01)/Math.max(s.width,.01),f=o(this,k).getBoundingClientRect();this.children.forEach(_=>_.didUpdate(f)),h(this,B,this.el.animate({transform:[`translateX(${a}px) scaleX(${l})`,"none"]},this.flow.xTiming)),l!==1&&(h(this,L,(E=o(this,k))==null?void 0:E.animate({transform:Rt(1e3,_=>`scaleX(${1/at(l,1,_)})`)},this.flow.xTiming)),h(this,N,this.el.animate(jt(1e3,_=>({"--_number-flow-scale-x":at(l,1,_)})),this.flow.xTiming)))}}k=new WeakMap,M=new WeakMap,A=new WeakMap,B=new WeakMap,N=new WeakMap,L=new WeakMap;var W,P;class rt extends mt{constructor(){super(...arguments);r(this,W);r(this,P)}willUpdate(t){const s=this.el.getBoundingClientRect();h(this,W,s[this.justify]-t[this.justify]),this.children.forEach(e=>e.willUpdate(s))}update(t){const s=new Map;this.children.forEach((e,a)=>{t.find(l=>l.key===a)||s.set(a,e)}),this.pop(s),this.addNewAndUpdateExisting(t)}didUpdate(t){var a;(a=o(this,P))==null||a.cancel();const s=this.el.getBoundingClientRect(),e=s[this.justify]-t[this.justify];this.children.forEach(l=>l.didUpdate(s)),h(this,P,this.el.animate({transform:[`translateX(${o(this,W)-e}px)`,"none"]},this.flow.xTiming))}}W=new WeakMap,P=new WeakMap;var R,H,j;class Q{constructor(i,t,{onRemove:s,animateIn:e=!1}={}){u(this,"flow");u(this,"el");r(this,R,!0);r(this,H);r(this,j);this.flow=i,this.el=t,e&&this.el.animate({opacity:["0","1"]},i.fadeTiming),h(this,H,s)}get present(){return o(this,R)}set present(i){var s;if(o(this,R)===i)return;const t=getComputedStyle(this.el).getPropertyValue("opacity");(s=o(this,j))==null||s.cancel(),h(this,j,this.el.animate({opacity:[t,i?"1":"0"]},this.flow.fadeTiming)),i||(o(this,j).onfinish=()=>{var e;this.el.remove(),(e=o(this,H))==null||e.call(this)}),h(this,R,i)}}R=new WeakMap,H=new WeakMap,j=new WeakMap;class gt extends Q{constructor(t,s,e,a){super(t.flow,e,a);u(this,"section");u(this,"value");u(this,"el");this.section=t,this.value=s,this.el=e}}var $,O,X,z,D;class yt extends gt{constructor(t,s,e,a){super(t,e,y("span",{className:"digit",textContent:e+""}),a);r(this,$);r(this,O);r(this,X);r(this,z);r(this,D)}willUpdate(t){h(this,$,this.value);const s=this.el.getBoundingClientRect();h(this,O,s.y-t.y);const e=s[this.section.justify]-t[this.section.justify],a=s.width/2;h(this,X,this.section.justify==="left"?e+a:e-a)}update(t){this.value=t,o(this,$)!==t&&_t(this.el,[...t===0?[]:[y("span",{className:"digit__stack digit__lt"},Array.from({length:t},(s,e)=>y("span",{textContent:e+""})))],document.createTextNode(t+""),...t===9?[]:[y("span",{className:"digit__stack digit__gt"},Array.from({length:9-t},(s,e)=>y("span",{textContent:t+e+1+""})))]])}didUpdate(t){var d,x;(d=o(this,z))==null||d.cancel(),o(this,$)!==this.value&&((x=o(this,D))==null||x.cancel());const s=this.el.getBoundingClientRect(),e=s[this.section.justify]-t[this.section.justify],a=s.width/2,l=this.section.justify==="left"?e+a:e-a,f=`translateX(${o(this,X)-l}px)`,c=`translateY(calc((100% + ${g}) * ${this.value-o(this,$)} + ${o(this,O)}px))`;h(this,z,this.el.animate({transform:[J?f:`${f} ${c}`,"none"]},{...this.flow.xTiming,composite:"accumulate"})),J&&o(this,$)!==this.value&&h(this,D,this.el.animate({transform:[c,"none"]},{...this.flow.yTiming,composite:"accumulate"}))}}$=new WeakMap,O=new WeakMap,X=new WeakMap,z=new WeakMap,D=new WeakMap;var w,F,I,Y;class Tt extends gt{constructor(t,s,e,a){const l=y("span",{className:"symbol__value",textContent:e});super(t,e,y("span",{className:"symbol"},[l]),a);u(this,"type");r(this,w,new Map);r(this,F);r(this,I,t=>()=>{o(this,w).delete(t)});r(this,Y);this.type=s,o(this,w).set(e,new Q(this.flow,l,{onRemove:o(this,I).call(this,e)}))}willUpdate(t){if(this.type==="decimal")return;const s=this.el.getBoundingClientRect();h(this,F,s[this.section.justify]-t[this.section.justify])}update(t){if(this.value!==t){const s=o(this,w).get(this.value);if(s.present=!1,s.el.classList.add("symbol__exiting"),o(this,w).has(t)){const e=o(this,w).get(t);e.present=!0,e.el.classList.remove("symbol__exiting")}else{const e=y("span",{className:"symbol__value",textContent:t});this.el.appendChild(e),o(this,w).set(t,new Q(this.flow,e,{animateIn:!0,onRemove:o(this,I).call(this,t)}))}}this.value=t}didUpdate(t){var a;if(this.type==="decimal")return;(a=o(this,Y))==null||a.cancel();const e=this.el.getBoundingClientRect()[this.section.justify]-t[this.section.justify];h(this,Y,this.el.animate({transform:[`translateX(${o(this,F)-e}px)`,"none"]},this.flow.xTiming))}}w=new WeakMap,F=new WeakMap,I=new WeakMap,Y=new WeakMap;exports.NumberFlowLite=Et;exports.SlottedTag=ft;exports.defaultFadeTiming=pt;exports.defaultXTiming=tt;exports.defaultYTiming=ut;exports.partitionParts=Ct;exports.slottedStyles=$t;exports.supportsAnimationComposition=J;exports.supportsLinear=ct;
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,440 @@
|
|
|
1
|
+
var ut = Object.defineProperty;
|
|
2
|
+
var Q = (n) => {
|
|
3
|
+
throw TypeError(n);
|
|
4
|
+
};
|
|
5
|
+
var mt = (n, i, t) => i in n ? ut(n, i, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[i] = t;
|
|
6
|
+
var u = (n, i, t) => mt(n, typeof i != "symbol" ? i + "" : i, t), tt = (n, i, t) => i.has(n) || Q("Cannot " + t);
|
|
7
|
+
var o = (n, i, t) => (tt(n, i, "read from private field"), t ? t.call(n) : i.get(n)), r = (n, i, t) => i.has(n) ? Q("Cannot add the same private member more than once") : i instanceof WeakSet ? i.add(n) : i.set(n, t), h = (n, i, t, s) => (tt(n, i, "write to private field"), s ? s.call(n, t) : i.set(n, t), t);
|
|
8
|
+
import { BROWSER as Y } from "esm-env";
|
|
9
|
+
const y = (n, i, t) => {
|
|
10
|
+
const s = document.createElement(n), [e, a] = Array.isArray(i) ? [void 0, i] : [i, t];
|
|
11
|
+
return e && Object.assign(s, e), a == null || a.forEach((l) => s.appendChild(l)), s;
|
|
12
|
+
}, gt = (n, i) => {
|
|
13
|
+
typeof Element.prototype.replaceChildren > "u" ? (n.innerHTML = "", i.forEach((t) => n.appendChild(t))) : n.replaceChildren(...i);
|
|
14
|
+
}, yt = (n, i) => {
|
|
15
|
+
var t;
|
|
16
|
+
return i === "left" ? n.offsetLeft : (((t = n.offsetParent instanceof HTMLElement ? n.offsetParent : null) == null ? void 0 : t.offsetWidth) ?? 0) - n.offsetWidth - n.offsetLeft;
|
|
17
|
+
};
|
|
18
|
+
function wt(n, i, { reverse: t = !1 } = {}) {
|
|
19
|
+
const s = n.length;
|
|
20
|
+
for (let e = t ? s - 1 : 0; t ? e >= 0 : e < s; t ? e-- : e++)
|
|
21
|
+
i(n[e], e);
|
|
22
|
+
}
|
|
23
|
+
function Et(n, i) {
|
|
24
|
+
const t = i.formatToParts(n), s = [], e = [], a = [], l = [], f = {}, c = (p) => (f[p] || (f[p] = 0), `${p}:${f[p]++}`);
|
|
25
|
+
let d = "", x = !1, U = !1;
|
|
26
|
+
for (const p of t) {
|
|
27
|
+
d += p.value;
|
|
28
|
+
const m = p.type === "minusSign" || p.type === "plusSign" ? "sign" : p.type;
|
|
29
|
+
m === "integer" ? (x = !0, e.push(...p.value.split("").map((q) => ({ type: m, value: parseInt(q) })))) : m === "group" ? e.push({ type: m, value: p.value }) : m === "decimal" ? (U = !0, a.push({ type: m, value: p.value, key: c(m) })) : m === "fraction" ? a.push(...p.value.split("").map((q) => ({ type: m, value: parseInt(q), key: c(m) }))) : (x || U ? l : s).push({
|
|
30
|
+
type: m,
|
|
31
|
+
value: p.value,
|
|
32
|
+
key: c(m)
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
const _ = [];
|
|
36
|
+
for (let p = e.length - 1; p >= 0; p--)
|
|
37
|
+
_.unshift({ ...e[p], key: c(e[p].type) });
|
|
38
|
+
return { pre: s, integer: _, fraction: a, post: l, formatted: d };
|
|
39
|
+
}
|
|
40
|
+
const xt = Y ? HTMLElement : class {
|
|
41
|
+
}, _t = String.raw, bt = Y && typeof CSS < "u" && CSS.supports("transition-timing-function", "linear(1, 2)"), rt = Y && typeof CSS < "u" && typeof CSS.registerProperty < "u", et = Y && typeof CSS < "u" && typeof CSS.supports("animation-composition", "accumulate") < "u";
|
|
42
|
+
if (rt)
|
|
43
|
+
try {
|
|
44
|
+
CSS.registerProperty({
|
|
45
|
+
name: "--_number-flow-scale-x",
|
|
46
|
+
syntax: "<number>",
|
|
47
|
+
inherits: !1,
|
|
48
|
+
initialValue: "1"
|
|
49
|
+
});
|
|
50
|
+
} catch {
|
|
51
|
+
}
|
|
52
|
+
const ct = "var(--number-flow-char-height, 1em)", g = "var(--number-flow-mask-height, 0.25em)", E = "var(--number-flow-mask-width, 0.5em)", Z = `${E} * 1/var(--_number-flow-scale-x)`, it = `calc(${Z})`, st = `linear-gradient(to bottom, transparent 0, #000 ${g}, #000 calc(100% - ${g}), transparent 100%)`, K = "#000 0, transparent 71%", Ct = "span", Tt = {
|
|
53
|
+
fontKerning: "none",
|
|
54
|
+
display: "inline-block",
|
|
55
|
+
lineHeight: ct,
|
|
56
|
+
padding: `${g} 0`
|
|
57
|
+
}, nt = _t`:host{display:inline-block;direction:ltr;user-select:none;pointer-events:none;white-space:nowrap;position:relative;line-height:${ct} !important;isolation:isolate;}::slotted(${Ct}){position:absolute;left:0;top:0;color:transparent !important;z-index:-1;user-select:text;pointer-events:auto;}.section{display:inline-block;padding-bottom:${g};padding-top:${g};vertical-align:top;user-select:none;}.section:not(.section--masked),.section--masked .section__inner{position:relative;isolation:isolate;}.section__inner{display:inline-block;transform-origin:inherit;}.section--justify-left{transform-origin:center left;}.section--justify-right{transform-origin:center right;}.section--masked{overflow:clip;position:relative;z-index:-1;--_number-flow-scale-x:1;-webkit-mask-repeat:no-repeat;-webkit-mask-size:calc(100% - ${Z}) 100%,100% calc(100% - ${g} * 2),${it} ${g},${it} ${g};}.section--masked.section--justify-left{padding-right:${E};margin-right:calc(-1 * ${E});-webkit-mask-image:${st},linear-gradient(to right,#000 0,#000 calc(100% - ${Z}),transparent 100%),radial-gradient(at bottom left,${K}),radial-gradient(at top left,${K});-webkit-mask-position:left,center,right top,right bottom;}.section--masked.section--justify-right{padding-left:${E};margin-left:calc(-1 * ${E});-webkit-mask-image:${st},linear-gradient(to left,#000 0,#000 calc(100% - ${Z}),transparent 100%),radial-gradient(at bottom right,${K}),radial-gradient(at top right,${K});-webkit-mask-position:right,center,left top,left bottom;}.section__exiting{position:absolute !important;z-index:-1;}.digit{display:inline-block;position:relative;}.digit__stack{display:flex;flex-direction:column;align-items:center;gap:${g};position:absolute;width:100%;}.digit__stack > *{display:inline-block;}.digit__lt{bottom:calc(100% + ${g});}.digit__gt{top:calc(100% + ${g});}.symbol{display:inline-block;position:relative;isolation:isolate;}.symbol__value{display:inline-block;white-space:pre;}.symbol__exiting{position:absolute;z-index:-1;}.section--justify-left .symbol__exiting{left:0;}.section--justify-right .symbol__exiting{right:0;}`;
|
|
58
|
+
function kt(n, i, t = 60) {
|
|
59
|
+
const s = Math.trunc(n / 1e3 * t);
|
|
60
|
+
return Array.from({ length: s }, (e, a) => i(a / (s - 1)));
|
|
61
|
+
}
|
|
62
|
+
function vt(n, i, t = 60) {
|
|
63
|
+
if (rt)
|
|
64
|
+
return [i(0), i(1)];
|
|
65
|
+
const s = Math.max(Math.trunc(n / 1e3 * t), 0), e = Array.from({ length: s }, (a, l) => ({
|
|
66
|
+
...i(l / s),
|
|
67
|
+
offset: (l + 0.5) / s
|
|
68
|
+
}));
|
|
69
|
+
return e.unshift({
|
|
70
|
+
...i(0),
|
|
71
|
+
offset: 0
|
|
72
|
+
}), e;
|
|
73
|
+
}
|
|
74
|
+
const ot = (n, i, t) => n + (i - n) * t, $t = {
|
|
75
|
+
duration: 500,
|
|
76
|
+
easing: "ease-out",
|
|
77
|
+
endDelay: 400,
|
|
78
|
+
fill: "forwards"
|
|
79
|
+
}, ht = bt ? {
|
|
80
|
+
duration: 900,
|
|
81
|
+
easing: "linear(0,.005,.019,.039,.066,.096,.129,.165,.202,.24,.278,.316,.354,.39,.426,.461,.494,.526,.557,.586,.614,.64,.665,.689,.711,.731,.751,.769,.786,.802,.817,.831,.844,.856,.867,.877,.887,.896,.904,.912,.919,.925,.931,.937,.942,.947,.951,.955,.959,.962,.965,.968,.971,.973,.976,.978,.98,.981,.983,.984,.986,.987,.988,.989,.99,.991,.992,.992,.993,.994,.994,.995,.995,.996,.996,.9963,.9967,.9969,.9972,.9975,.9977,.9979,.9981,.9982,.9984,.9985,.9987,.9988,.9989,1)"
|
|
82
|
+
} : {
|
|
83
|
+
duration: 900,
|
|
84
|
+
// Spring-like cubic-bezier stolen from Vaul: https://vaul.emilkowal.ski/
|
|
85
|
+
easing: "cubic-bezier(.32,.72,0,1)"
|
|
86
|
+
}, St = ht;
|
|
87
|
+
let G;
|
|
88
|
+
var T, b, C, k, v;
|
|
89
|
+
class Mt extends xt {
|
|
90
|
+
constructor() {
|
|
91
|
+
super(...arguments);
|
|
92
|
+
u(this, "xTiming", ht);
|
|
93
|
+
u(this, "yTiming", St);
|
|
94
|
+
u(this, "fadeTiming", $t);
|
|
95
|
+
u(this, "root", !1);
|
|
96
|
+
u(this, "manual", !1);
|
|
97
|
+
r(this, T, !1);
|
|
98
|
+
r(this, b);
|
|
99
|
+
r(this, C);
|
|
100
|
+
r(this, k);
|
|
101
|
+
r(this, v);
|
|
102
|
+
}
|
|
103
|
+
static define() {
|
|
104
|
+
Y && customElements.define("number-flow", this);
|
|
105
|
+
}
|
|
106
|
+
set parts(t) {
|
|
107
|
+
if (t == null)
|
|
108
|
+
return;
|
|
109
|
+
const { pre: s, integer: e, fraction: a, post: l } = t;
|
|
110
|
+
if (o(this, T))
|
|
111
|
+
this.manual || this.willUpdate(), o(this, b).update(s), o(this, C).update(e), o(this, k).update(a), o(this, v).update(l), this.manual || this.didUpdate();
|
|
112
|
+
else {
|
|
113
|
+
if (this.attachShadow({ mode: "open" }), typeof CSSStyleSheet < "u" && this.shadowRoot.adoptedStyleSheets)
|
|
114
|
+
G || (G = new CSSStyleSheet(), G.replaceSync(nt)), this.shadowRoot.adoptedStyleSheets = [G];
|
|
115
|
+
else {
|
|
116
|
+
const f = document.createElement("style");
|
|
117
|
+
f.textContent = nt, this.shadowRoot.appendChild(f);
|
|
118
|
+
}
|
|
119
|
+
this.shadowRoot.appendChild(y("slot")), h(this, b, new lt(this, s, {
|
|
120
|
+
// part: 'pre',
|
|
121
|
+
inert: !0,
|
|
122
|
+
ariaHidden: "true",
|
|
123
|
+
justify: "right"
|
|
124
|
+
})), this.shadowRoot.appendChild(o(this, b).el), h(this, C, new at(this, e, {
|
|
125
|
+
// part: 'integer',
|
|
126
|
+
inert: !0,
|
|
127
|
+
ariaHidden: "true",
|
|
128
|
+
justify: "right"
|
|
129
|
+
})), this.shadowRoot.appendChild(o(this, C).el), h(this, k, new at(this, a, {
|
|
130
|
+
// part: 'fraction',
|
|
131
|
+
inert: !0,
|
|
132
|
+
ariaHidden: "true",
|
|
133
|
+
justify: "left"
|
|
134
|
+
})), this.shadowRoot.appendChild(o(this, k).el), h(this, v, new lt(this, l, {
|
|
135
|
+
// part: 'post',
|
|
136
|
+
inert: !0,
|
|
137
|
+
ariaHidden: "true",
|
|
138
|
+
justify: "left"
|
|
139
|
+
})), this.shadowRoot.appendChild(o(this, v).el);
|
|
140
|
+
}
|
|
141
|
+
h(this, T, !0);
|
|
142
|
+
}
|
|
143
|
+
willUpdate() {
|
|
144
|
+
const t = this.root ? this.getBoundingClientRect() : new DOMRect();
|
|
145
|
+
o(this, b).willUpdate(t), o(this, C).willUpdate(t), o(this, k).willUpdate(t), o(this, v).willUpdate(t);
|
|
146
|
+
}
|
|
147
|
+
didUpdate() {
|
|
148
|
+
const t = this.root ? this.getBoundingClientRect() : new DOMRect();
|
|
149
|
+
o(this, b).didUpdate(t), o(this, C).didUpdate(t), o(this, k).didUpdate(t), o(this, v).didUpdate(t);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
T = new WeakMap(), b = new WeakMap(), C = new WeakMap(), k = new WeakMap(), v = new WeakMap();
|
|
153
|
+
class dt {
|
|
154
|
+
constructor(i, t, { justify: s, className: e, ...a }, l) {
|
|
155
|
+
u(this, "flow");
|
|
156
|
+
u(this, "el");
|
|
157
|
+
u(this, "justify");
|
|
158
|
+
// All children in the DOM:
|
|
159
|
+
u(this, "children", /* @__PURE__ */ new Map());
|
|
160
|
+
u(this, "onCharRemove", (i) => () => {
|
|
161
|
+
this.children.delete(i);
|
|
162
|
+
});
|
|
163
|
+
this.flow = i, this.justify = s;
|
|
164
|
+
const f = t.map((c) => this.addChar(c).el);
|
|
165
|
+
f.push(document.createTextNode("")), this.el = y("span", {
|
|
166
|
+
...a,
|
|
167
|
+
className: `section section--justify-${s} ${e ?? ""}`
|
|
168
|
+
}, l ? l(f) : f);
|
|
169
|
+
}
|
|
170
|
+
addChar(i, { startDigitsAtZero: t = !1, ...s } = {}) {
|
|
171
|
+
const e = i.type === "integer" || i.type === "fraction" ? new pt(this, i.type, t ? 0 : i.value, {
|
|
172
|
+
...s,
|
|
173
|
+
onRemove: this.onCharRemove(i.key)
|
|
174
|
+
}) : new jt(this, i.type, i.value, {
|
|
175
|
+
...s,
|
|
176
|
+
onRemove: this.onCharRemove(i.key)
|
|
177
|
+
});
|
|
178
|
+
return this.children.set(i.key, e), e;
|
|
179
|
+
}
|
|
180
|
+
unpop(i) {
|
|
181
|
+
i.el.classList.remove("section__exiting"), i.el.style[this.justify] = "";
|
|
182
|
+
}
|
|
183
|
+
pop(i) {
|
|
184
|
+
i.forEach((t) => {
|
|
185
|
+
t.el.style[this.justify] = `${yt(t.el, this.justify)}px`;
|
|
186
|
+
}), i.forEach((t) => {
|
|
187
|
+
t.el.classList.add("section__exiting"), t.present = !1;
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
addNewAndUpdateExisting(i, t = this.el) {
|
|
191
|
+
const s = /* @__PURE__ */ new Map(), e = /* @__PURE__ */ new Map(), a = this.justify === "left", l = a ? "prepend" : "append";
|
|
192
|
+
wt(i, (c) => {
|
|
193
|
+
let d;
|
|
194
|
+
this.children.has(c.key) ? (d = this.children.get(c.key), e.set(c, d), this.unpop(d), d.present = !0) : (d = this.addChar(c, { startDigitsAtZero: !0, animateIn: !0 }), s.set(c, d)), t[l](d.el);
|
|
195
|
+
}, { reverse: a });
|
|
196
|
+
const f = t.getBoundingClientRect();
|
|
197
|
+
s.forEach((c) => {
|
|
198
|
+
c.willUpdate(f);
|
|
199
|
+
}), s.forEach((c, d) => {
|
|
200
|
+
c.update(d.value);
|
|
201
|
+
}), e.forEach((c, d) => {
|
|
202
|
+
c.update(d.value);
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
var $, M, A, N, B, L;
|
|
207
|
+
class at extends dt {
|
|
208
|
+
constructor(t, s, { className: e, ...a }) {
|
|
209
|
+
let l;
|
|
210
|
+
super(t, s, {
|
|
211
|
+
...a,
|
|
212
|
+
className: `${e ?? ""} section--masked`
|
|
213
|
+
}, (f) => [
|
|
214
|
+
l = y("span", {
|
|
215
|
+
className: "section__inner"
|
|
216
|
+
}, f)
|
|
217
|
+
]);
|
|
218
|
+
r(this, $);
|
|
219
|
+
r(this, M);
|
|
220
|
+
r(this, A);
|
|
221
|
+
r(this, N);
|
|
222
|
+
r(this, B);
|
|
223
|
+
r(this, L);
|
|
224
|
+
h(this, $, l);
|
|
225
|
+
}
|
|
226
|
+
willUpdate(t) {
|
|
227
|
+
const s = this.el.getBoundingClientRect();
|
|
228
|
+
h(this, M, s.width), h(this, A, s[this.justify] - t[this.justify]);
|
|
229
|
+
const e = o(this, $).getBoundingClientRect();
|
|
230
|
+
this.children.forEach((a) => a.willUpdate(e));
|
|
231
|
+
}
|
|
232
|
+
update(t) {
|
|
233
|
+
const s = /* @__PURE__ */ new Map();
|
|
234
|
+
this.children.forEach((e, a) => {
|
|
235
|
+
t.find((l) => l.key === a) || s.set(a, e), this.unpop(e);
|
|
236
|
+
}), this.addNewAndUpdateExisting(t, o(this, $)), s.forEach((e) => {
|
|
237
|
+
e instanceof pt && e.update(0);
|
|
238
|
+
}), this.pop(s);
|
|
239
|
+
}
|
|
240
|
+
didUpdate(t) {
|
|
241
|
+
var c, d, x, U;
|
|
242
|
+
(c = o(this, N)) == null || c.cancel(), (d = o(this, L)) == null || d.cancel(), (x = o(this, B)) == null || x.cancel();
|
|
243
|
+
const s = this.el.getBoundingClientRect(), e = s[this.justify] - t[this.justify], a = o(this, A) - e, l = Math.max(o(this, M), 0.01) / Math.max(s.width, 0.01), f = o(this, $).getBoundingClientRect();
|
|
244
|
+
this.children.forEach((_) => _.didUpdate(f)), h(this, N, this.el.animate({
|
|
245
|
+
transform: [`translateX(${a}px) scaleX(${l})`, "none"]
|
|
246
|
+
}, this.flow.xTiming)), l !== 1 && (h(this, L, (U = o(this, $)) == null ? void 0 : U.animate({
|
|
247
|
+
// 1/x isn't linear so we need to do sampling:
|
|
248
|
+
transform: kt(1e3, (_) => `scaleX(${1 / ot(l, 1, _)})`)
|
|
249
|
+
}, this.flow.xTiming)), h(this, B, this.el.animate(vt(1e3, (_) => ({
|
|
250
|
+
"--_number-flow-scale-x": ot(l, 1, _)
|
|
251
|
+
})), this.flow.xTiming)));
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
$ = new WeakMap(), M = new WeakMap(), A = new WeakMap(), N = new WeakMap(), B = new WeakMap(), L = new WeakMap();
|
|
255
|
+
var H, P;
|
|
256
|
+
class lt extends dt {
|
|
257
|
+
constructor() {
|
|
258
|
+
super(...arguments);
|
|
259
|
+
r(this, H);
|
|
260
|
+
r(this, P);
|
|
261
|
+
}
|
|
262
|
+
willUpdate(t) {
|
|
263
|
+
const s = this.el.getBoundingClientRect();
|
|
264
|
+
h(this, H, s[this.justify] - t[this.justify]), this.children.forEach((e) => e.willUpdate(s));
|
|
265
|
+
}
|
|
266
|
+
update(t) {
|
|
267
|
+
const s = /* @__PURE__ */ new Map();
|
|
268
|
+
this.children.forEach((e, a) => {
|
|
269
|
+
t.find((l) => l.key === a) || s.set(a, e);
|
|
270
|
+
}), this.pop(s), this.addNewAndUpdateExisting(t);
|
|
271
|
+
}
|
|
272
|
+
didUpdate(t) {
|
|
273
|
+
var a;
|
|
274
|
+
(a = o(this, P)) == null || a.cancel();
|
|
275
|
+
const s = this.el.getBoundingClientRect(), e = s[this.justify] - t[this.justify];
|
|
276
|
+
this.children.forEach((l) => l.didUpdate(s)), h(this, P, this.el.animate({
|
|
277
|
+
transform: [`translateX(${o(this, H) - e}px)`, "none"]
|
|
278
|
+
}, this.flow.xTiming));
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
H = new WeakMap(), P = new WeakMap();
|
|
282
|
+
var j, W, R;
|
|
283
|
+
class J {
|
|
284
|
+
constructor(i, t, { onRemove: s, animateIn: e = !1 } = {}) {
|
|
285
|
+
u(this, "flow");
|
|
286
|
+
u(this, "el");
|
|
287
|
+
r(this, j, !0);
|
|
288
|
+
r(this, W);
|
|
289
|
+
r(this, R);
|
|
290
|
+
this.flow = i, this.el = t, e && this.el.animate({
|
|
291
|
+
opacity: ["0", "1"]
|
|
292
|
+
}, i.fadeTiming), h(this, W, s);
|
|
293
|
+
}
|
|
294
|
+
get present() {
|
|
295
|
+
return o(this, j);
|
|
296
|
+
}
|
|
297
|
+
set present(i) {
|
|
298
|
+
var s;
|
|
299
|
+
if (o(this, j) === i)
|
|
300
|
+
return;
|
|
301
|
+
const t = getComputedStyle(this.el).getPropertyValue("opacity");
|
|
302
|
+
(s = o(this, R)) == null || s.cancel(), h(this, R, this.el.animate({
|
|
303
|
+
opacity: [t, i ? "1" : "0"]
|
|
304
|
+
}, this.flow.fadeTiming)), i || (o(this, R).onfinish = () => {
|
|
305
|
+
var e;
|
|
306
|
+
this.el.remove(), (e = o(this, W)) == null || e.call(this);
|
|
307
|
+
}), h(this, j, i);
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
j = new WeakMap(), W = new WeakMap(), R = new WeakMap();
|
|
311
|
+
class ft extends J {
|
|
312
|
+
constructor(t, s, e, a) {
|
|
313
|
+
super(t.flow, e, a);
|
|
314
|
+
u(this, "section");
|
|
315
|
+
u(this, "value");
|
|
316
|
+
u(this, "el");
|
|
317
|
+
this.section = t, this.value = s, this.el = e;
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
var S, X, z, D, O;
|
|
321
|
+
class pt extends ft {
|
|
322
|
+
constructor(t, s, e, a) {
|
|
323
|
+
super(t, e, y("span", {
|
|
324
|
+
className: "digit",
|
|
325
|
+
// part: `digit ${type} ${value}`,
|
|
326
|
+
textContent: e + ""
|
|
327
|
+
}), a);
|
|
328
|
+
r(this, S);
|
|
329
|
+
// Relative to parent:
|
|
330
|
+
r(this, X);
|
|
331
|
+
r(this, z);
|
|
332
|
+
r(this, D);
|
|
333
|
+
r(this, O);
|
|
334
|
+
}
|
|
335
|
+
willUpdate(t) {
|
|
336
|
+
h(this, S, this.value);
|
|
337
|
+
const s = this.el.getBoundingClientRect();
|
|
338
|
+
h(this, X, s.y - t.y);
|
|
339
|
+
const e = s[this.section.justify] - t[this.section.justify], a = s.width / 2;
|
|
340
|
+
h(this, z, this.section.justify === "left" ? e + a : e - a);
|
|
341
|
+
}
|
|
342
|
+
update(t) {
|
|
343
|
+
this.value = t, o(this, S) !== t && gt(this.el, [
|
|
344
|
+
...t === 0 ? [] : [
|
|
345
|
+
y("span", { className: "digit__stack digit__lt" }, Array.from({ length: t }, (s, e) => y("span", { textContent: e + "" })))
|
|
346
|
+
],
|
|
347
|
+
document.createTextNode(t + ""),
|
|
348
|
+
...t === 9 ? [] : [
|
|
349
|
+
y("span", { className: "digit__stack digit__gt" }, Array.from({ length: 9 - t }, (s, e) => y("span", { textContent: t + e + 1 + "" })))
|
|
350
|
+
]
|
|
351
|
+
]);
|
|
352
|
+
}
|
|
353
|
+
didUpdate(t) {
|
|
354
|
+
var d, x;
|
|
355
|
+
(d = o(this, D)) == null || d.cancel(), o(this, S) !== this.value && ((x = o(this, O)) == null || x.cancel());
|
|
356
|
+
const s = this.el.getBoundingClientRect(), e = s[this.section.justify] - t[this.section.justify], a = s.width / 2, l = this.section.justify === "left" ? e + a : e - a, f = `translateX(${o(this, z) - l}px)`, c = `translateY(calc((100% + ${g}) * ${this.value - o(this, S)} + ${o(this, X)}px))`;
|
|
357
|
+
h(this, D, this.el.animate({
|
|
358
|
+
transform: [et ? f : `${f} ${c}`, "none"]
|
|
359
|
+
}, {
|
|
360
|
+
...this.flow.xTiming,
|
|
361
|
+
composite: "accumulate"
|
|
362
|
+
// in case there's an in-flight y animation
|
|
363
|
+
})), et && o(this, S) !== this.value && h(this, O, this.el.animate({
|
|
364
|
+
transform: [c, "none"]
|
|
365
|
+
}, {
|
|
366
|
+
...this.flow.yTiming,
|
|
367
|
+
composite: "accumulate"
|
|
368
|
+
}));
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
S = new WeakMap(), X = new WeakMap(), z = new WeakMap(), D = new WeakMap(), O = new WeakMap();
|
|
372
|
+
var w, I, F, V;
|
|
373
|
+
class jt extends ft {
|
|
374
|
+
constructor(t, s, e, a) {
|
|
375
|
+
const l = y("span", {
|
|
376
|
+
className: "symbol__value",
|
|
377
|
+
textContent: e
|
|
378
|
+
});
|
|
379
|
+
super(t, e, y("span", {
|
|
380
|
+
className: "symbol"
|
|
381
|
+
}, [l]), a);
|
|
382
|
+
u(this, "type");
|
|
383
|
+
r(this, w, /* @__PURE__ */ new Map());
|
|
384
|
+
r(this, I);
|
|
385
|
+
r(this, F, (t) => () => {
|
|
386
|
+
o(this, w).delete(t);
|
|
387
|
+
});
|
|
388
|
+
r(this, V);
|
|
389
|
+
this.type = s, o(this, w).set(e, new J(this.flow, l, {
|
|
390
|
+
onRemove: o(this, F).call(this, e)
|
|
391
|
+
}));
|
|
392
|
+
}
|
|
393
|
+
willUpdate(t) {
|
|
394
|
+
if (this.type === "decimal")
|
|
395
|
+
return;
|
|
396
|
+
const s = this.el.getBoundingClientRect();
|
|
397
|
+
h(this, I, s[this.section.justify] - t[this.section.justify]);
|
|
398
|
+
}
|
|
399
|
+
update(t) {
|
|
400
|
+
if (this.value !== t) {
|
|
401
|
+
const s = o(this, w).get(this.value);
|
|
402
|
+
if (s.present = !1, s.el.classList.add("symbol__exiting"), o(this, w).has(t)) {
|
|
403
|
+
const e = o(this, w).get(t);
|
|
404
|
+
e.present = !0, e.el.classList.remove("symbol__exiting");
|
|
405
|
+
} else {
|
|
406
|
+
const e = y("span", {
|
|
407
|
+
className: "symbol__value",
|
|
408
|
+
textContent: t
|
|
409
|
+
});
|
|
410
|
+
this.el.appendChild(e), o(this, w).set(t, new J(this.flow, e, {
|
|
411
|
+
animateIn: !0,
|
|
412
|
+
onRemove: o(this, F).call(this, t)
|
|
413
|
+
}));
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
this.value = t;
|
|
417
|
+
}
|
|
418
|
+
didUpdate(t) {
|
|
419
|
+
var a;
|
|
420
|
+
if (this.type === "decimal")
|
|
421
|
+
return;
|
|
422
|
+
(a = o(this, V)) == null || a.cancel();
|
|
423
|
+
const e = this.el.getBoundingClientRect()[this.section.justify] - t[this.section.justify];
|
|
424
|
+
h(this, V, this.el.animate({
|
|
425
|
+
transform: [`translateX(${o(this, I) - e}px)`, "none"]
|
|
426
|
+
}, this.flow.xTiming));
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
w = new WeakMap(), I = new WeakMap(), F = new WeakMap(), V = new WeakMap();
|
|
430
|
+
export {
|
|
431
|
+
Mt as NumberFlowLite,
|
|
432
|
+
Ct as SlottedTag,
|
|
433
|
+
$t as defaultFadeTiming,
|
|
434
|
+
ht as defaultXTiming,
|
|
435
|
+
St as defaultYTiming,
|
|
436
|
+
Et as partitionParts,
|
|
437
|
+
Tt as slottedStyles,
|
|
438
|
+
et as supportsAnimationComposition,
|
|
439
|
+
bt as supportsLinear
|
|
440
|
+
};
|
package/dist/styles.d.ts
CHANGED
|
@@ -2,13 +2,13 @@ export declare const supportsLinear: boolean;
|
|
|
2
2
|
export declare const supportsAtProperty: boolean;
|
|
3
3
|
export declare const supportsAnimationComposition: boolean;
|
|
4
4
|
export declare const charHeight = "var(--number-flow-char-height, 1em)";
|
|
5
|
-
export declare const maskHeight = "var(--number-flow-mask-height, 0.
|
|
5
|
+
export declare const maskHeight = "var(--number-flow-mask-height, 0.25em)";
|
|
6
6
|
export declare const SlottedTag = "span";
|
|
7
7
|
export declare const slottedStyles: {
|
|
8
8
|
readonly fontKerning: "none";
|
|
9
9
|
readonly display: "inline-block";
|
|
10
10
|
readonly lineHeight: "var(--number-flow-char-height, 1em)";
|
|
11
|
-
readonly padding: "var(--number-flow-mask-height, 0.
|
|
11
|
+
readonly padding: "var(--number-flow-mask-height, 0.25em) 0";
|
|
12
12
|
};
|
|
13
13
|
declare const styles: string;
|
|
14
14
|
export default styles;
|
package/package.json
CHANGED
|
@@ -3,14 +3,13 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"
|
|
7
|
-
"version": "0.2.0",
|
|
6
|
+
"version": "0.2.2",
|
|
8
7
|
"author": {
|
|
9
8
|
"name": "Maxwell Barvian",
|
|
10
9
|
"email": "max@barvian.me",
|
|
11
10
|
"url": "https://barvian.me"
|
|
12
11
|
},
|
|
13
|
-
"description": "A
|
|
12
|
+
"description": "A component to transition and format numbers.",
|
|
14
13
|
"license": "MIT",
|
|
15
14
|
"homepage": "https://number-flow.barvian.me/",
|
|
16
15
|
"repository": {
|
|
@@ -33,11 +32,14 @@
|
|
|
33
32
|
"dist",
|
|
34
33
|
"README.md"
|
|
35
34
|
],
|
|
35
|
+
"main": "./dist/index.js",
|
|
36
|
+
"module": "./dist/index.mjs",
|
|
37
|
+
"types": "./dist/index.d.ts",
|
|
36
38
|
"exports": {
|
|
37
39
|
".": {
|
|
38
40
|
"types": "./dist/index.d.ts",
|
|
39
|
-
"
|
|
40
|
-
"require": "./dist/index.
|
|
41
|
+
"import": "./dist/index.mjs",
|
|
42
|
+
"require": "./dist/index.js"
|
|
41
43
|
}
|
|
42
44
|
},
|
|
43
45
|
"devDependencies": {
|
package/dist/index.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";var St=Object.defineProperty;var et=n=>{throw TypeError(n)};var kt=(n,i,t)=>i in n?St(n,i,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[i]=t;var u=(n,i,t)=>kt(n,typeof i!="symbol"?i+"":i,t),it=(n,i,t)=>i.has(n)||et("Cannot "+t);var o=(n,i,t)=>(it(n,i,"read from private field"),t?t.call(n):i.get(n)),r=(n,i,t)=>i.has(n)?et("Cannot add the same private member more than once"):i instanceof WeakSet?i.add(n):i.set(n,t),h=(n,i,t,s)=>(it(n,i,"write to private field"),s?s.call(n,t):i.set(n,t),t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const V=require("esm-env"),y=(n,i,t)=>{const s=document.createElement(n),[e,a]=Array.isArray(i)?[void 0,i]:[i,t];return e&&Object.assign(s,e),a==null||a.forEach(l=>s.appendChild(l)),s},Ct=(n,i)=>{typeof Element.prototype.replaceChildren>"u"?(n.innerHTML="",i.forEach(t=>n.appendChild(t))):n.replaceChildren(...i)},vt=(n,i)=>{var t;return i==="left"?n.offsetLeft:(((t=n.offsetParent instanceof HTMLElement?n.offsetParent:null)==null?void 0:t.offsetWidth)??0)-n.offsetWidth-n.offsetLeft};function $t(n,i,{reverse:t=!1}={}){const s=n.length;for(let e=t?s-1:0;t?e>=0:e<s;t?e--:e++)i(n[e],e)}function Rt(n,i){const t=i.formatToParts(n),s=[],e=[],a=[],l=[],f={},c=p=>(f[p]||(f[p]=0),`${p}:${f[p]++}`);let d="",b=!1,T=!1;for(const p of t){d+=p.value;const m=p.type==="minusSign"||p.type==="plusSign"?"sign":p.type;m==="integer"?(b=!0,e.push(...p.value.split("").map(Z=>({type:m,value:parseInt(Z)})))):m==="group"?e.push({type:m,value:p.value}):m==="decimal"?(T=!0,a.push({type:m,value:p.value,key:c(m)})):m==="fraction"?a.push(...p.value.split("").map(Z=>({type:m,value:parseInt(Z),key:c(m)}))):(b||T?l:s).push({type:m,value:p.value,key:c(m)})}const x=[];for(let p=e.length-1;p>=0;p--)x.unshift({...e[p],key:c(e[p].type)});return{pre:s,integer:x,fraction:a,post:l,formatted:d}}const jt=V.BROWSER?HTMLElement:class{},Tt=String.raw,ct=V.BROWSER&&typeof CSS<"u"&&CSS.supports("transition-timing-function","linear(1, 2)"),ht=V.BROWSER&&typeof CSS<"u"&&typeof CSS.registerProperty<"u",J=V.BROWSER&&typeof CSS<"u"&&typeof CSS.supports("animation-composition","accumulate")<"u";if(ht)try{CSS.registerProperty({name:"--_number-flow-scale-x",syntax:"<number>",inherits:!1,initialValue:"1"})}catch{}const dt="var(--number-flow-char-height, 1em)",g="var(--number-flow-mask-height, 0.15em)",E="var(--number-flow-mask-width, 0.5em)",G=`${E} * 1/var(--_number-flow-scale-x)`,st=`calc(${G})`,nt=`linear-gradient(to bottom, transparent 0, #000 ${g}, #000 calc(100% - ${g}), transparent 100%)`,K="#000 0, transparent 71%",ft="span",Et={fontKerning:"none",display:"inline-block",lineHeight:dt,padding:`${g} 0`},ot=Tt`:host{display:inline-block;direction:ltr;user-select:none;pointer-events:none;white-space:nowrap;position:relative;line-height:${dt} !important;isolation:isolate;}::slotted(${ft}){position:absolute;left:0;top:0;color:transparent !important;z-index:-1;user-select:text;pointer-events:auto;}.section{display:inline-block;padding-bottom:${g};padding-top:${g};vertical-align:top;user-select:none;}.section:not(.section--masked),.section--masked .section__inner{position:relative;isolation:isolate;}.section__inner{display:inline-block;transform-origin:inherit;}.section--justify-left{transform-origin:center left;}.section--justify-right{transform-origin:center right;}.section--masked{overflow:clip;position:relative;z-index:-1;--_number-flow-scale-x:1;-webkit-mask-repeat:no-repeat;-webkit-mask-size:calc(100% - ${G}) 100%,100% calc(100% - ${g} * 2),${st} ${g},${st} ${g};}.section--masked.section--justify-left{padding-right:${E};margin-right:calc(-1 * ${E});-webkit-mask-image:${nt},linear-gradient(to right,#000 0,#000 calc(100% - ${G}),transparent 100%),radial-gradient(at bottom left,${K}),radial-gradient(at top left,${K});-webkit-mask-position:left,center,right top,right bottom;}.section--masked.section--justify-right{padding-left:${E};margin-left:calc(-1 * ${E});-webkit-mask-image:${nt},linear-gradient(to left,#000 0,#000 calc(100% - ${G}),transparent 100%),radial-gradient(at bottom right,${K}),radial-gradient(at top right,${K});-webkit-mask-position:right,center,left top,left bottom;}.section__exiting{position:absolute !important;z-index:-1;}.digit{display:inline-block;position:relative;}.digit__stack{display:flex;flex-direction:column;align-items:center;gap:${g};position:absolute;width:100%;}.digit__stack > *{display:inline-block;}.digit__lt{bottom:calc(100% + ${g});}.digit__gt{top:calc(100% + ${g});}.symbol{display:inline-block;position:relative;isolation:isolate;}.symbol__value{display:inline-block;white-space:pre;}.symbol__exiting{position:absolute;z-index:-1;}.section--justify-left .symbol__exiting{left:0;}.section--justify-right .symbol__exiting{right:0;}`;function Ut(n,i,t=60){const s=Math.trunc(n/1e3*t);return Array.from({length:s},(e,a)=>i(a/(s-1)))}function Mt(n,i,t=60){if(ht)return[i(0),i(1)];const s=Math.max(Math.trunc(n/1e3*t),0),e=Array.from({length:s},(a,l)=>({...i(l/s),offset:(l+.5)/s}));return e.unshift({...i(0),offset:0}),e}const at=(n,i,t)=>n+(i-n)*t,pt=900,ut=[0,.0050235113985758065,.018768235438646315,.0394665067267097,.06561435806809059,.09593671402266707,.12935688367555642,.16496984329827014,.2020188582086,.2398750451603972,.2780195227408494,.316027838175776,.35355639522427323,.3903306400002338,.42613479005042487,.4608029172568362,.494211217479539,.5262713196397582,.5569245044497536,.5861367184830215,.6138942829733466,.6402002088371546,.6650710401106178,.688534157441182,.7106254816148533,.7313875244620506,.7508677409782638,.7691171422207626,.7861891335875677,.8021385475282429,.8170208436473976,.830891452602792,.8438052432253264,.8558160949464902,.8669765599529741,.8773376015362415,.8869483969005642,.8958561942662493,.9041062154819053,.9117415965639958,.9188033596342844,.9253304106443357,.9313595580771787,.9369255485137984,.9420611155589194,.9467970391476751,.9511622127120402,.9551837160819846,.9588868923388109,.9622954271337615,.9654314292396703,.9683155113223428,.9709668701061009,.9734033652684989,.9756415965361696,.9776969785701735,.9795838133278193,.9813153596710892,.9829039000616127,.9843608042404175,.985696589839041,.986920979908387,.9880429573842098,.989070816534304,.990012211453356,.9908742016877166,.9916632950848158,.9923854879711473,.9930463027692117,.9936508231680027,.994203726963899,.9947093166895601,.9951715481478591,.9955940569663103,.9959801832850321,.9963329946882337,.9966553074856583,.9969497064465007,.9972185630841328,.9974640525856172,.9976881694755444,.9978927420992383,.9980794460059083,.998249816307907,.9984052590879293,.998547061921768,.9986764035801687,.9987943629693811,.9989019273662413,1],mt=900,gt=[.32,.72,0,1],yt={duration:500,easing:"ease-out"},tt=ct?{duration:pt,easing:`linear(${ut.join(",")})`}:{duration:mt,easing:`cubic-bezier(${gt.join(",")})`},wt=tt;let q;var U,_,S,k,C;class At extends jt{constructor(){super(...arguments);u(this,"xTiming",tt);u(this,"yTiming",wt);u(this,"fadeTiming",yt);u(this,"root",!1);u(this,"manual",!1);r(this,U,!1);r(this,_);r(this,S);r(this,k);r(this,C)}static define(){V.BROWSER&&customElements.define("number-flow",this)}set parts(t){if(t==null)return;const{pre:s,integer:e,fraction:a,post:l}=t;if(o(this,U))this.manual||this.willUpdate(),o(this,_).update(s),o(this,S).update(e),o(this,k).update(a),o(this,C).update(l),this.manual||this.didUpdate();else{if(this.attachShadow({mode:"open"}),typeof CSSStyleSheet<"u"&&this.shadowRoot.adoptedStyleSheets)q||(q=new CSSStyleSheet,q.replaceSync(ot)),this.shadowRoot.adoptedStyleSheets=[q];else{const f=document.createElement("style");f.textContent=ot,this.shadowRoot.appendChild(f)}this.shadowRoot.appendChild(y("slot")),h(this,_,new rt(this,s,{inert:!0,ariaHidden:"true",justify:"right"})),this.shadowRoot.appendChild(o(this,_).el),h(this,S,new lt(this,e,{inert:!0,ariaHidden:"true",justify:"right"})),this.shadowRoot.appendChild(o(this,S).el),h(this,k,new lt(this,a,{inert:!0,ariaHidden:"true",justify:"left"})),this.shadowRoot.appendChild(o(this,k).el),h(this,C,new rt(this,l,{inert:!0,ariaHidden:"true",justify:"left"})),this.shadowRoot.appendChild(o(this,C).el)}h(this,U,!0)}willUpdate(){const t=this.root?this.getBoundingClientRect():new DOMRect;o(this,_).willUpdate(t),o(this,S).willUpdate(t),o(this,k).willUpdate(t),o(this,C).willUpdate(t)}didUpdate(){const t=this.root?this.getBoundingClientRect():new DOMRect;o(this,_).didUpdate(t),o(this,S).didUpdate(t),o(this,k).didUpdate(t),o(this,C).didUpdate(t)}}U=new WeakMap,_=new WeakMap,S=new WeakMap,k=new WeakMap,C=new WeakMap;class bt{constructor(i,t,{justify:s,className:e,...a},l){u(this,"flow");u(this,"el");u(this,"justify");u(this,"children",new Map);u(this,"onCharRemove",i=>()=>{this.children.delete(i)});this.flow=i,this.justify=s;const f=t.map(c=>this.addChar(c).el);f.push(document.createTextNode("")),this.el=y("span",{...a,className:`section section--justify-${s} ${e??""}`},l?l(f):f)}addChar(i,{startDigitsAtZero:t=!1,...s}={}){const e=i.type==="integer"||i.type==="fraction"?new _t(this,i.type,t?0:i.value,{...s,onRemove:this.onCharRemove(i.key)}):new Bt(this,i.type,i.value,{...s,onRemove:this.onCharRemove(i.key)});return this.children.set(i.key,e),e}unpop(i){i.el.classList.remove("section__exiting"),i.el.style[this.justify]=""}pop(i){i.forEach(t=>{t.el.style[this.justify]=`${vt(t.el,this.justify)}px`}),i.forEach(t=>{t.el.classList.add("section__exiting"),t.present=!1})}addNewAndUpdateExisting(i,t=this.el){const s=new Map,e=new Map,a=this.justify==="left",l=a?"prepend":"append";$t(i,c=>{let d;this.children.has(c.key)?(d=this.children.get(c.key),e.set(c,d),this.unpop(d),d.present=!0):(d=this.addChar(c,{startDigitsAtZero:!0,animateIn:!0}),s.set(c,d)),t[l](d.el)},{reverse:a});const f=t.getBoundingClientRect();s.forEach(c=>{c.willUpdate(f)}),s.forEach((c,d)=>{c.update(d.value)}),e.forEach((c,d)=>{c.update(d.value)})}}var v,M,A,B,L,N;class lt extends bt{constructor(t,s,{className:e,...a}){let l;super(t,s,{...a,className:`${e??""} section--masked`},f=>[l=y("span",{className:"section__inner"},f)]);r(this,v);r(this,M);r(this,A);r(this,B);r(this,L);r(this,N);h(this,v,l)}willUpdate(t){const s=this.el.getBoundingClientRect();h(this,M,s.width),h(this,A,s[this.justify]-t[this.justify]);const e=o(this,v).getBoundingClientRect();this.children.forEach(a=>a.willUpdate(e))}update(t){const s=new Map;this.children.forEach((e,a)=>{t.find(l=>l.key===a)||s.set(a,e),this.unpop(e)}),this.addNewAndUpdateExisting(t,o(this,v)),s.forEach(e=>{e instanceof _t&&e.update(0)}),this.pop(s)}didUpdate(t){var c,d,b,T;(c=o(this,B))==null||c.cancel(),(d=o(this,N))==null||d.cancel(),(b=o(this,L))==null||b.cancel();const s=this.el.getBoundingClientRect(),e=s[this.justify]-t[this.justify],a=o(this,A)-e,l=Math.max(o(this,M),.01)/Math.max(s.width,.01),f=o(this,v).getBoundingClientRect();this.children.forEach(x=>x.didUpdate(f)),h(this,B,this.el.animate({transform:[`translateX(${a}px) scaleX(${l})`,"none"]},this.flow.xTiming)),l!==1&&(h(this,N,(T=o(this,v))==null?void 0:T.animate({transform:Ut(1e3,x=>`scaleX(${1/at(l,1,x)})`)},this.flow.xTiming)),h(this,L,this.el.animate(Mt(1e3,x=>({"--_number-flow-scale-x":at(l,1,x)})),this.flow.xTiming)))}}v=new WeakMap,M=new WeakMap,A=new WeakMap,B=new WeakMap,L=new WeakMap,N=new WeakMap;var P,X;class rt extends bt{constructor(){super(...arguments);r(this,P);r(this,X)}willUpdate(t){const s=this.el.getBoundingClientRect();h(this,P,s[this.justify]-t[this.justify]),this.children.forEach(e=>e.willUpdate(s))}update(t){const s=new Map;this.children.forEach((e,a)=>{t.find(l=>l.key===a)||s.set(a,e)}),this.pop(s),this.addNewAndUpdateExisting(t)}didUpdate(t){var a;(a=o(this,X))==null||a.cancel();const s=this.el.getBoundingClientRect(),e=s[this.justify]-t[this.justify];this.children.forEach(l=>l.didUpdate(s)),h(this,X,this.el.animate({transform:[`translateX(${o(this,P)-e}px)`,"none"]},this.flow.xTiming))}}P=new WeakMap,X=new WeakMap;var R,W,j;class Q{constructor(i,t,{onRemove:s,animateIn:e=!1}={}){u(this,"flow");u(this,"el");r(this,R,!0);r(this,W);r(this,j);this.flow=i,this.el=t,e&&this.el.animate({opacity:["0","1"]},i.fadeTiming),h(this,W,s)}get present(){return o(this,R)}set present(i){var s;if(o(this,R)===i)return;const t=getComputedStyle(this.el).getPropertyValue("opacity");(s=o(this,j))==null||s.cancel(),h(this,j,this.el.animate({opacity:[t,i?"1":"0"]},this.flow.fadeTiming)),i||(o(this,j).onfinish=()=>{var e;this.el.remove(),(e=o(this,W))==null||e.call(this)}),h(this,R,i)}}R=new WeakMap,W=new WeakMap,j=new WeakMap;class xt extends Q{constructor(t,s,e,a){super(t.flow,e,a);u(this,"section");u(this,"value");u(this,"el");this.section=t,this.value=s,this.el=e}}var $,H,O,D,F;class _t extends xt{constructor(t,s,e,a){super(t,e,y("span",{className:"digit",textContent:e+""}),a);r(this,$);r(this,H);r(this,O);r(this,D);r(this,F)}willUpdate(t){h(this,$,this.value);const s=this.el.getBoundingClientRect();h(this,H,s.y-t.y);const e=s[this.section.justify]-t[this.section.justify],a=s.width/2;h(this,O,this.section.justify==="left"?e+a:e-a)}update(t){this.value=t,o(this,$)!==t&&Ct(this.el,[...t===0?[]:[y("span",{className:"digit__stack digit__lt"},Array.from({length:t},(s,e)=>y("span",{textContent:e+""})))],document.createTextNode(t+""),...t===9?[]:[y("span",{className:"digit__stack digit__gt"},Array.from({length:9-t},(s,e)=>y("span",{textContent:t+e+1+""})))]])}didUpdate(t){var d,b;(d=o(this,D))==null||d.cancel(),o(this,$)!==this.value&&((b=o(this,F))==null||b.cancel());const s=this.el.getBoundingClientRect(),e=s[this.section.justify]-t[this.section.justify],a=s.width/2,l=this.section.justify==="left"?e+a:e-a,f=`translateX(${o(this,O)-l}px)`,c=`translateY(calc((100% + ${g}) * ${this.value-o(this,$)} + ${o(this,H)}px))`;h(this,D,this.el.animate({transform:[J?f:`${f} ${c}`,"none"]},{...this.flow.xTiming,composite:"accumulate"})),J&&o(this,$)!==this.value&&h(this,F,this.el.animate({transform:[c,"none"]},{...this.flow.yTiming,composite:"accumulate"}))}}$=new WeakMap,H=new WeakMap,O=new WeakMap,D=new WeakMap,F=new WeakMap;var w,z,I,Y;class Bt extends xt{constructor(t,s,e,a){const l=y("span",{className:"symbol__value",textContent:e});super(t,e,y("span",{className:"symbol"},[l]),a);u(this,"type");r(this,w,new Map);r(this,z);r(this,I,t=>()=>{o(this,w).delete(t)});r(this,Y);this.type=s,o(this,w).set(e,new Q(this.flow,l,{onRemove:o(this,I).call(this,e)}))}willUpdate(t){if(this.type==="decimal")return;const s=this.el.getBoundingClientRect();h(this,z,s[this.section.justify]-t[this.section.justify])}update(t){if(this.value!==t){const s=o(this,w).get(this.value);if(s.present=!1,s.el.classList.add("symbol__exiting"),o(this,w).has(t)){const e=o(this,w).get(t);e.present=!0,e.el.classList.remove("symbol__exiting")}else{const e=y("span",{className:"symbol__value",textContent:t});this.el.appendChild(e),o(this,w).set(t,new Q(this.flow,e,{animateIn:!0,onRemove:o(this,I).call(this,t)}))}}this.value=t}didUpdate(t){var a;if(this.type==="decimal")return;(a=o(this,Y))==null||a.cancel();const e=this.el.getBoundingClientRect()[this.section.justify]-t[this.section.justify];h(this,Y,this.el.animate({transform:[`translateX(${o(this,z)-e}px)`,"none"]},this.flow.xTiming))}}w=new WeakMap,z=new WeakMap,I=new WeakMap,Y=new WeakMap;exports.NumberFlowLite=At;exports.SlottedTag=ft;exports.defaultFadeTiming=yt;exports.defaultXTiming=tt;exports.defaultXTimingFallbackDuration=mt;exports.defaultXTimingFallbackPoints=gt;exports.defaultXTimingLinearDuration=pt;exports.defaultXTimingLinearPoints=ut;exports.defaultYTiming=wt;exports.partitionParts=Rt;exports.slottedStyles=Et;exports.supportsAnimationComposition=J;exports.supportsLinear=ct;
|