@number-flow/vue 0.3.4 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +3 -0
- package/dist/index.js +447 -69
- package/dist/index.umd.cjs +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,39 +1,416 @@
|
|
|
1
|
-
import { defineComponent as
|
|
2
|
-
import { NumberFlowLite as
|
|
3
|
-
import { NumberFlowLite as
|
|
4
|
-
import { BROWSER as
|
|
5
|
-
const
|
|
1
|
+
import { defineComponent as V, provide as G, renderSlot as I, watch as z, nextTick as k, onUnmounted as D, ref as $, computed as C, inject as Y, openBlock as Z, createElementBlock as q, mergeProps as J, unref as A, onMounted as K, watchEffect as Q, toValue as P } from "vue";
|
|
2
|
+
import { NumberFlowLite as c, formatToData as tt, renderInnerHTML as et, define as it, canAnimate as st, prefersReducedMotion as b } from "number-flow";
|
|
3
|
+
import { NumberFlowLite as Rt } from "number-flow";
|
|
4
|
+
import { BROWSER as f } from "esm-env";
|
|
5
|
+
const W = Symbol(), St = /* @__PURE__ */ V({
|
|
6
6
|
__name: "NumberFlowGroup",
|
|
7
7
|
setup(a) {
|
|
8
|
-
const
|
|
9
|
-
let
|
|
10
|
-
return
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
const t = /* @__PURE__ */ new Set();
|
|
9
|
+
let e = !1;
|
|
10
|
+
return G(W, (s, r) => {
|
|
11
|
+
t.add(s), z(
|
|
12
|
+
r,
|
|
13
13
|
async () => {
|
|
14
|
-
|
|
15
|
-
var
|
|
16
|
-
!
|
|
17
|
-
}), await
|
|
14
|
+
e || (e = !0, t.forEach(async (n) => {
|
|
15
|
+
var o;
|
|
16
|
+
!n.value || !n.value.created || (n.value.willUpdate(), await k(), (o = n.value) == null || o.didUpdate());
|
|
17
|
+
}), await k(), e = !1);
|
|
18
18
|
}
|
|
19
19
|
// { flush: 'pre' } // default
|
|
20
|
-
),
|
|
21
|
-
|
|
20
|
+
), D(() => {
|
|
21
|
+
t.delete(s);
|
|
22
22
|
});
|
|
23
|
-
}), (
|
|
23
|
+
}), (s, r) => I(s.$slots, "default");
|
|
24
24
|
}
|
|
25
|
-
}),
|
|
25
|
+
}), u = (a, t, e) => {
|
|
26
|
+
const i = document.createElement(a), [s, r] = Array.isArray(t) ? [void 0, t] : [t, e];
|
|
27
|
+
return s && Object.assign(i, s), r == null || r.forEach((n) => i.appendChild(n)), i;
|
|
28
|
+
}, nt = (a, t) => {
|
|
29
|
+
var e;
|
|
30
|
+
return t === "left" ? a.offsetLeft : (((e = a.offsetParent instanceof HTMLElement ? a.offsetParent : null) == null ? void 0 : e.offsetWidth) ?? 0) - a.offsetWidth - a.offsetLeft;
|
|
31
|
+
}, at = (a) => a.offsetWidth > 0 && a.offsetHeight > 0;
|
|
32
|
+
function ot(a, t, { reverse: e = !1 } = {}) {
|
|
33
|
+
const i = a.length;
|
|
34
|
+
for (let s = e ? i - 1 : 0; e ? s >= 0 : s < i; e ? s-- : s++)
|
|
35
|
+
t(a[s], s);
|
|
36
|
+
}
|
|
37
|
+
const rt = String.raw, lt = f && typeof CSS < "u" && CSS.supports && CSS.supports("animation-timing-function", "linear(1,2)"), ht = f && typeof CSS < "u" && CSS.supports && CSS.supports("line-height", "mod(1,1)"), M = f && typeof matchMedia < "u" ? matchMedia("(prefers-reduced-motion: reduce)") : null, y = "--_number-flow-d-opacity", E = "--_number-flow-d-width", _ = "--_number-flow-dx", R = "--_number-flow-d", dt = (() => {
|
|
38
|
+
try {
|
|
39
|
+
return CSS.registerProperty({
|
|
40
|
+
name: y,
|
|
41
|
+
syntax: "<number>",
|
|
42
|
+
inherits: !1,
|
|
43
|
+
initialValue: "0"
|
|
44
|
+
}), CSS.registerProperty({
|
|
45
|
+
name: _,
|
|
46
|
+
syntax: "<length>",
|
|
47
|
+
inherits: !0,
|
|
48
|
+
initialValue: "0px"
|
|
49
|
+
}), CSS.registerProperty({
|
|
50
|
+
name: E,
|
|
51
|
+
syntax: "<number>",
|
|
52
|
+
inherits: !1,
|
|
53
|
+
initialValue: "0"
|
|
54
|
+
}), CSS.registerProperty({
|
|
55
|
+
name: R,
|
|
56
|
+
syntax: "<number>",
|
|
57
|
+
inherits: !0,
|
|
58
|
+
initialValue: "0"
|
|
59
|
+
}), !0;
|
|
60
|
+
} catch {
|
|
61
|
+
return !1;
|
|
62
|
+
}
|
|
63
|
+
})(), ct = "var(--number-flow-char-height, 1em)", p = "var(--number-flow-mask-height, 0.25em)", L = `calc(${p} / 2)`, x = "var(--number-flow-mask-width, 0.5em)", m = `calc(${x} / var(--scale-x))`, g = "#000 0, transparent 71%", N = rt`:host{display:inline-block;direction:ltr;white-space:nowrap;isolation:isolate;line-height:${ct} !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(${E}) / var(--width));transform:translateX(var(${_})) scaleX(var(--scale-x));margin:0 calc(-1 * ${x});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 ${p},#000 calc(100% - ${p}),transparent 100% ),radial-gradient(at bottom right,${g}),radial-gradient(at bottom left,${g}),radial-gradient(at top left,${g}),radial-gradient(at top right,${g});-webkit-mask-size:100% calc(100% - ${p} * 2),calc(100% - ${m} * 2) 100%,${m} ${p},${m} ${p},${m} ${p},${m} ${p};-webkit-mask-position:center,center,top left,top right,bottom right,bottom left;-webkit-mask-repeat:no-repeat}.number__inner{padding:${L} ${x};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__exiting,.symbol__exiting{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:${L} 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:not(.is-current){position:absolute;top:0;left:50%;transform:translateX(-50%) translateY(var(--y))}.digit:not(.is-spinning) .digit__num:not(.is-current){display:none}.symbol__value{display:inline-block;mix-blend-mode:plus-lighter;white-space:pre}.section--justify-left .symbol__exiting{left:0}.section--justify-right .symbol__exiting{right:0}.animate-presence{opacity:calc(1 + var(${y}))}`, pt = f ? HTMLElement : class {
|
|
64
|
+
}, ut = ht && lt && dt;
|
|
65
|
+
let v;
|
|
66
|
+
class mt extends pt {
|
|
67
|
+
constructor() {
|
|
68
|
+
super(), this.created = !1, this.manual = !1;
|
|
69
|
+
const { animated: t, ...e } = this.constructor.defaultProps;
|
|
70
|
+
this._animated = this.computedAnimated = t, Object.assign(this, e);
|
|
71
|
+
}
|
|
72
|
+
get animated() {
|
|
73
|
+
return this._animated;
|
|
74
|
+
}
|
|
75
|
+
set animated(t) {
|
|
76
|
+
var e;
|
|
77
|
+
this.animated !== t && (this._animated = t, (e = this.shadowRoot) == null || e.getAnimations().forEach((i) => i.finish()));
|
|
78
|
+
}
|
|
79
|
+
set data(t) {
|
|
80
|
+
var e;
|
|
81
|
+
if (t == null)
|
|
82
|
+
return;
|
|
83
|
+
const { pre: i, integer: s, fraction: r, post: n, value: o } = t;
|
|
84
|
+
if (this.created) {
|
|
85
|
+
const l = this._data;
|
|
86
|
+
this._data = t, this.computedTrend = typeof this.trend == "function" ? this.trend(l.value, o) : this.trend, this.computedAnimated = ut && this._animated && (!this.respectMotionPreference || !(M != null && M.matches)) && // https://github.com/barvian/number-flow/issues/9
|
|
87
|
+
at(this), (e = this.plugins) == null || e.forEach((h) => {
|
|
88
|
+
var d;
|
|
89
|
+
return (d = h.onUpdate) == null ? void 0 : d.call(h, t, l, this);
|
|
90
|
+
}), this.manual || this.willUpdate(), this._pre.update(i), this._num.update({ integer: s, fraction: r }), this._post.update(n), this.manual || this.didUpdate();
|
|
91
|
+
} else {
|
|
92
|
+
if (this._data = t, this.attachShadow({ mode: "open" }), typeof CSSStyleSheet < "u" && this.shadowRoot.adoptedStyleSheets)
|
|
93
|
+
v || (v = new CSSStyleSheet(), v.replaceSync(N)), this.shadowRoot.adoptedStyleSheets = [v];
|
|
94
|
+
else {
|
|
95
|
+
const l = document.createElement("style");
|
|
96
|
+
l.textContent = N, this.shadowRoot.appendChild(l);
|
|
97
|
+
}
|
|
98
|
+
this._pre = new F(this, i, {
|
|
99
|
+
justify: "right",
|
|
100
|
+
part: "left"
|
|
101
|
+
}), this.shadowRoot.appendChild(this._pre.el), this._num = new ft(this, s, r), this.shadowRoot.appendChild(this._num.el), this._post = new F(this, n, {
|
|
102
|
+
justify: "left",
|
|
103
|
+
part: "right"
|
|
104
|
+
}), this.shadowRoot.appendChild(this._post.el);
|
|
105
|
+
}
|
|
106
|
+
this.created = !0;
|
|
107
|
+
}
|
|
108
|
+
willUpdate() {
|
|
109
|
+
this._pre.willUpdate(), this._num.willUpdate(), this._post.willUpdate();
|
|
110
|
+
}
|
|
111
|
+
didUpdate() {
|
|
112
|
+
if (!this.computedAnimated)
|
|
113
|
+
return;
|
|
114
|
+
this._abortAnimationsFinish ? this._abortAnimationsFinish.abort() : this.dispatchEvent(new Event("animationsstart")), this._pre.didUpdate(), this._num.didUpdate(), this._post.didUpdate();
|
|
115
|
+
const t = new AbortController();
|
|
116
|
+
Promise.all(this.shadowRoot.getAnimations().map((e) => e.finished)).then(() => {
|
|
117
|
+
t.signal.aborted || (this.dispatchEvent(new Event("animationsfinish")), this._abortAnimationsFinish = void 0);
|
|
118
|
+
}), this._abortAnimationsFinish = t;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
mt.defaultProps = {
|
|
122
|
+
transformTiming: {
|
|
123
|
+
duration: 900,
|
|
124
|
+
// Make sure to keep this minified:
|
|
125
|
+
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)"
|
|
126
|
+
},
|
|
127
|
+
spinTiming: void 0,
|
|
128
|
+
opacityTiming: { duration: 450, easing: "ease-out" },
|
|
129
|
+
animated: !0,
|
|
130
|
+
trend: (a, t) => Math.sign(t - a),
|
|
131
|
+
respectMotionPreference: !0,
|
|
132
|
+
plugins: void 0,
|
|
133
|
+
digits: void 0
|
|
134
|
+
};
|
|
135
|
+
class ft {
|
|
136
|
+
constructor(t, e, i, { className: s, ...r } = {}) {
|
|
137
|
+
this.flow = t, this._integer = new B(t, e, {
|
|
138
|
+
justify: "right",
|
|
139
|
+
part: "integer"
|
|
140
|
+
}), this._fraction = new B(t, i, {
|
|
141
|
+
justify: "left",
|
|
142
|
+
part: "fraction"
|
|
143
|
+
}), this._inner = u("span", {
|
|
144
|
+
className: "number__inner"
|
|
145
|
+
}, [this._integer.el, this._fraction.el]), this.el = u("span", {
|
|
146
|
+
...r,
|
|
147
|
+
part: "number",
|
|
148
|
+
className: `number ${s ?? ""}`
|
|
149
|
+
}, [this._inner]);
|
|
150
|
+
}
|
|
151
|
+
willUpdate() {
|
|
152
|
+
this._prevWidth = this.el.offsetWidth, this._prevLeft = this.el.getBoundingClientRect().left, this._integer.willUpdate(), this._fraction.willUpdate();
|
|
153
|
+
}
|
|
154
|
+
update({ integer: t, fraction: e }) {
|
|
155
|
+
this._integer.update(t), this._fraction.update(e);
|
|
156
|
+
}
|
|
157
|
+
didUpdate() {
|
|
158
|
+
const t = this.el.getBoundingClientRect();
|
|
159
|
+
this._integer.didUpdate(), this._fraction.didUpdate();
|
|
160
|
+
const e = this._prevLeft - t.left, i = this.el.offsetWidth, s = this._prevWidth - i;
|
|
161
|
+
this.el.style.setProperty("--width", String(i)), this.el.animate({
|
|
162
|
+
[_]: [`${e}px`, "0px"],
|
|
163
|
+
[E]: [s, 0]
|
|
164
|
+
}, {
|
|
165
|
+
...this.flow.transformTiming,
|
|
166
|
+
composite: "accumulate"
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
class X {
|
|
171
|
+
constructor(t, e, { justify: i, className: s, ...r }, n) {
|
|
172
|
+
this.flow = t, this.children = /* @__PURE__ */ new Map(), this.onCharRemove = (l) => () => {
|
|
173
|
+
this.children.delete(l);
|
|
174
|
+
}, this.justify = i;
|
|
175
|
+
const o = e.map((l) => this.addChar(l).el);
|
|
176
|
+
this.el = u("span", {
|
|
177
|
+
...r,
|
|
178
|
+
className: `section section--justify-${i} ${s ?? ""}`
|
|
179
|
+
}, n ? n(o) : o);
|
|
180
|
+
}
|
|
181
|
+
addChar(t, { startDigitsAtZero: e = !1, ...i } = {}) {
|
|
182
|
+
const s = t.type === "integer" || t.type === "fraction" ? new H(this, t.type, e ? 0 : t.value, t.pos, {
|
|
183
|
+
...i,
|
|
184
|
+
onRemove: this.onCharRemove(t.key)
|
|
185
|
+
}) : new gt(this, t.type, t.value, {
|
|
186
|
+
...i,
|
|
187
|
+
onRemove: this.onCharRemove(t.key)
|
|
188
|
+
});
|
|
189
|
+
return this.children.set(t.key, s), s;
|
|
190
|
+
}
|
|
191
|
+
unpop(t) {
|
|
192
|
+
t.el.classList.remove("section__exiting"), t.el.style.top = "", t.el.style[this.justify] = "";
|
|
193
|
+
}
|
|
194
|
+
pop(t) {
|
|
195
|
+
t.forEach((e) => {
|
|
196
|
+
e.el.style.top = `${e.el.offsetTop}px`, e.el.style[this.justify] = `${nt(e.el, this.justify)}px`;
|
|
197
|
+
}), t.forEach((e) => {
|
|
198
|
+
e.el.classList.add("section__exiting"), e.present = !1;
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
addNewAndUpdateExisting(t) {
|
|
202
|
+
const e = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Map(), s = this.justify === "left", r = s ? "prepend" : "append";
|
|
203
|
+
if (ot(t, (n) => {
|
|
204
|
+
let o;
|
|
205
|
+
this.children.has(n.key) ? (o = this.children.get(n.key), i.set(n, o), this.unpop(o), o.present = !0) : (o = this.addChar(n, { startDigitsAtZero: !0, animateIn: !0 }), e.set(n, o)), this.el[r](o.el);
|
|
206
|
+
}, { reverse: s }), this.flow.computedAnimated) {
|
|
207
|
+
const n = this.el.getBoundingClientRect();
|
|
208
|
+
e.forEach((o) => {
|
|
209
|
+
o.willUpdate(n);
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
e.forEach((n, o) => {
|
|
213
|
+
n.update(o.value);
|
|
214
|
+
}), i.forEach((n, o) => {
|
|
215
|
+
n.update(o.value);
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
willUpdate() {
|
|
219
|
+
const t = this.el.getBoundingClientRect();
|
|
220
|
+
this._prevOffset = t[this.justify], this.children.forEach((e) => e.willUpdate(t));
|
|
221
|
+
}
|
|
222
|
+
didUpdate() {
|
|
223
|
+
const t = this.el.getBoundingClientRect();
|
|
224
|
+
this.children.forEach((s) => s.didUpdate(t));
|
|
225
|
+
const e = t[this.justify], i = this._prevOffset - e;
|
|
226
|
+
i && this.children.size && this.el.animate({
|
|
227
|
+
transform: [`translateX(${i}px)`, "none"]
|
|
228
|
+
}, {
|
|
229
|
+
...this.flow.transformTiming,
|
|
230
|
+
composite: "accumulate"
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
class B extends X {
|
|
235
|
+
update(t) {
|
|
236
|
+
const e = /* @__PURE__ */ new Map();
|
|
237
|
+
this.children.forEach((i, s) => {
|
|
238
|
+
t.find((r) => r.key === s) || e.set(s, i), this.unpop(i);
|
|
239
|
+
}), this.addNewAndUpdateExisting(t), e.forEach((i) => {
|
|
240
|
+
i instanceof H && i.update(0);
|
|
241
|
+
}), this.pop(e);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
class F extends X {
|
|
245
|
+
update(t) {
|
|
246
|
+
const e = /* @__PURE__ */ new Map();
|
|
247
|
+
this.children.forEach((i, s) => {
|
|
248
|
+
t.find((r) => r.key === s) || e.set(s, i);
|
|
249
|
+
}), this.pop(e), this.addNewAndUpdateExisting(t);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
class T {
|
|
253
|
+
constructor(t, e, { onRemove: i, animateIn: s = !1 } = {}) {
|
|
254
|
+
this.flow = t, this.el = e, this._present = !0, this._remove = () => {
|
|
255
|
+
var r;
|
|
256
|
+
this.el.remove(), (r = this._onRemove) == null || r.call(this);
|
|
257
|
+
}, this.el.classList.add("animate-presence"), this.flow.computedAnimated && s && this.el.animate({
|
|
258
|
+
[y]: [-0.9999, 0]
|
|
259
|
+
}, {
|
|
260
|
+
...this.flow.opacityTiming,
|
|
261
|
+
composite: "accumulate"
|
|
262
|
+
}), this._onRemove = i;
|
|
263
|
+
}
|
|
264
|
+
get present() {
|
|
265
|
+
return this._present;
|
|
266
|
+
}
|
|
267
|
+
set present(t) {
|
|
268
|
+
if (this._present !== t) {
|
|
269
|
+
if (this._present = t, !this.flow.computedAnimated) {
|
|
270
|
+
t || this._remove();
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
this.el.style.setProperty("--_number-flow-d-opacity", t ? "0" : "-.999"), this.el.animate({
|
|
274
|
+
[y]: t ? [-0.9999, 0] : [0.999, 0]
|
|
275
|
+
}, {
|
|
276
|
+
...this.flow.opacityTiming,
|
|
277
|
+
composite: "accumulate"
|
|
278
|
+
}), t ? this.flow.removeEventListener("animationsfinish", this._remove) : this.flow.addEventListener("animationsfinish", this._remove, {
|
|
279
|
+
once: !0
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
class O extends T {
|
|
285
|
+
constructor(t, e, i, s) {
|
|
286
|
+
super(t.flow, i, s), this.section = t, this.value = e, this.el = i;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
class H extends O {
|
|
290
|
+
constructor(t, e, i, s, r) {
|
|
291
|
+
var n, o;
|
|
292
|
+
const l = (((o = (n = t.flow.digits) == null ? void 0 : n[s]) == null ? void 0 : o.max) ?? 9) + 1, h = Array.from({ length: l }).map((U, w) => {
|
|
293
|
+
const j = u("span", { className: `digit__num${w === i ? " is-current" : ""}` }, [document.createTextNode(String(w))]);
|
|
294
|
+
return j.style.setProperty("--n", String(w)), j;
|
|
295
|
+
}), d = u("span", {
|
|
296
|
+
part: `digit ${e}-digit`,
|
|
297
|
+
className: "digit"
|
|
298
|
+
}, h);
|
|
299
|
+
d.style.setProperty("--current", String(i)), d.style.setProperty("--length", String(l)), super(t, i, d, r), this.pos = s, this._onAnimationsFinish = () => {
|
|
300
|
+
this.el.classList.remove("is-spinning");
|
|
301
|
+
}, this._numbers = h, this.length = l;
|
|
302
|
+
}
|
|
303
|
+
willUpdate(t) {
|
|
304
|
+
const e = this.el.getBoundingClientRect();
|
|
305
|
+
this._prevValue = this.value;
|
|
306
|
+
const i = e[this.section.justify] - t[this.section.justify], s = e.width / 2;
|
|
307
|
+
this._prevCenter = this.section.justify === "left" ? i + s : i - s;
|
|
308
|
+
}
|
|
309
|
+
update(t) {
|
|
310
|
+
var e, i;
|
|
311
|
+
(e = this._numbers[this.value]) == null || e.classList.remove("is-current"), this.el.style.setProperty("--current", String(t)), (i = this._numbers[t]) == null || i.classList.add("is-current"), this.value = t;
|
|
312
|
+
}
|
|
313
|
+
didUpdate(t) {
|
|
314
|
+
const e = this.el.getBoundingClientRect(), i = e[this.section.justify] - t[this.section.justify], s = e.width / 2, r = this.section.justify === "left" ? i + s : i - s, n = this._prevCenter - r;
|
|
315
|
+
n && this.el.animate({
|
|
316
|
+
transform: [`translateX(${n}px)`, "none"]
|
|
317
|
+
}, {
|
|
318
|
+
...this.flow.transformTiming,
|
|
319
|
+
composite: "accumulate"
|
|
320
|
+
});
|
|
321
|
+
const o = this.getSpin();
|
|
322
|
+
o && (this.el.classList.add("is-spinning"), this.el.animate({
|
|
323
|
+
[R]: [-o, 0]
|
|
324
|
+
}, {
|
|
325
|
+
...this.flow.spinTiming ?? this.flow.transformTiming,
|
|
326
|
+
composite: "accumulate"
|
|
327
|
+
}), this.flow.addEventListener("animationsfinish", this._onAnimationsFinish, { once: !0 }));
|
|
328
|
+
}
|
|
329
|
+
getSpin() {
|
|
330
|
+
var t;
|
|
331
|
+
if (this.flow.plugins)
|
|
332
|
+
for (const s of this.flow.plugins) {
|
|
333
|
+
const r = (t = s.getSpin) == null ? void 0 : t.call(s, this.value, this._prevValue, this);
|
|
334
|
+
if (r != null)
|
|
335
|
+
return r;
|
|
336
|
+
}
|
|
337
|
+
const e = this.value - this._prevValue, i = this.flow.computedTrend || Math.sign(e);
|
|
338
|
+
return i < 0 && this.value > this._prevValue ? this.value - this.length - this._prevValue : i > 0 && this.value < this._prevValue ? this.length - this._prevValue + this.value : e;
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
class gt extends O {
|
|
342
|
+
constructor(t, e, i, s) {
|
|
343
|
+
const r = u("span", {
|
|
344
|
+
className: "symbol__value",
|
|
345
|
+
textContent: i
|
|
346
|
+
});
|
|
347
|
+
super(t, i, u("span", {
|
|
348
|
+
part: `symbol ${e}`,
|
|
349
|
+
className: "symbol"
|
|
350
|
+
}, [r]), s), this.type = e, this._children = /* @__PURE__ */ new Map(), this._onChildRemove = (n) => () => {
|
|
351
|
+
this._children.delete(n);
|
|
352
|
+
}, this._children.set(i, new T(this.flow, r, {
|
|
353
|
+
onRemove: this._onChildRemove(i)
|
|
354
|
+
}));
|
|
355
|
+
}
|
|
356
|
+
willUpdate(t) {
|
|
357
|
+
if (this.type === "decimal")
|
|
358
|
+
return;
|
|
359
|
+
const e = this.el.getBoundingClientRect();
|
|
360
|
+
this._prevOffset = e[this.section.justify] - t[this.section.justify];
|
|
361
|
+
}
|
|
362
|
+
update(t) {
|
|
363
|
+
if (this.value !== t) {
|
|
364
|
+
const e = this._children.get(this.value);
|
|
365
|
+
if (e.present = !1, e.el.classList.add("symbol__exiting"), this._children.has(t)) {
|
|
366
|
+
const i = this._children.get(t);
|
|
367
|
+
i.present = !0, i.el.classList.remove("symbol__exiting");
|
|
368
|
+
} else {
|
|
369
|
+
const i = u("span", {
|
|
370
|
+
className: "symbol__value",
|
|
371
|
+
textContent: t
|
|
372
|
+
});
|
|
373
|
+
this.el.appendChild(i), this._children.set(t, new T(this.flow, i, {
|
|
374
|
+
animateIn: !0,
|
|
375
|
+
onRemove: this._onChildRemove(t)
|
|
376
|
+
}));
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
this.value = t;
|
|
380
|
+
}
|
|
381
|
+
didUpdate(t) {
|
|
382
|
+
if (this.type === "decimal")
|
|
383
|
+
return;
|
|
384
|
+
const e = this.el.getBoundingClientRect()[this.section.justify] - t[this.section.justify], i = this._prevOffset - e;
|
|
385
|
+
i && this.el.animate({
|
|
386
|
+
transform: [`translateX(${i}px)`, "none"]
|
|
387
|
+
}, { ...this.flow.transformTiming, composite: "accumulate" });
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
const vt = (a, t) => a == null ? t : t == null ? a : Math.max(a, t), S = /* @__PURE__ */ new WeakMap(), $t = {
|
|
391
|
+
onUpdate(a, t, e) {
|
|
392
|
+
if (S.set(e, void 0), !e.computedTrend)
|
|
393
|
+
return;
|
|
394
|
+
const i = t.integer.concat(t.fraction).filter((o) => o.type === "integer" || o.type === "fraction"), s = a.integer.concat(a.fraction).filter((o) => o.type === "integer" || o.type === "fraction"), r = i.find((o) => !s.find((l) => l.pos === o.pos && l.value === o.value)), n = s.find((o) => !i.find((l) => o.pos === l.pos && o.value === l.value));
|
|
395
|
+
S.set(e, vt(r == null ? void 0 : r.pos, n == null ? void 0 : n.pos));
|
|
396
|
+
},
|
|
397
|
+
getSpin(a, t, e) {
|
|
398
|
+
const i = a - t, s = S.get(e.flow);
|
|
399
|
+
if (!i && s != null && s >= e.pos)
|
|
400
|
+
return e.length * e.flow.computedTrend;
|
|
401
|
+
}
|
|
402
|
+
}, yt = ["aria-label", "manual", "trend", "plugins", "animated", "transformTiming", "spinTiming", "opacityTiming", "respectMotionPreference", "data-will-change", "digits", "innerHTML", "data"], Ct = /* @__PURE__ */ V({
|
|
26
403
|
inheritAttrs: !1,
|
|
27
404
|
__name: "index",
|
|
28
405
|
props: {
|
|
29
|
-
transformTiming: { default: () =>
|
|
30
|
-
spinTiming: { default: () =>
|
|
31
|
-
opacityTiming: { default: () =>
|
|
32
|
-
animated: { type: Boolean, default: () =>
|
|
33
|
-
respectMotionPreference: { type: Boolean, default: () =>
|
|
34
|
-
trend: { type: [Number, Function], default: () =>
|
|
35
|
-
|
|
36
|
-
digits: { default: () =>
|
|
406
|
+
transformTiming: { default: () => c.defaultProps.transformTiming },
|
|
407
|
+
spinTiming: { default: () => c.defaultProps.spinTiming },
|
|
408
|
+
opacityTiming: { default: () => c.defaultProps.opacityTiming },
|
|
409
|
+
animated: { type: Boolean, default: () => c.defaultProps.animated },
|
|
410
|
+
respectMotionPreference: { type: Boolean, default: () => c.defaultProps.respectMotionPreference },
|
|
411
|
+
trend: { type: [Number, Function], default: () => c.defaultProps.trend },
|
|
412
|
+
plugins: { default: () => c.defaultProps.plugins },
|
|
413
|
+
digits: { default: () => c.defaultProps.digits },
|
|
37
414
|
locales: {},
|
|
38
415
|
format: {},
|
|
39
416
|
value: {},
|
|
@@ -42,59 +419,60 @@ const w = Symbol(), j = /* @__PURE__ */ h({
|
|
|
42
419
|
willChange: { type: Boolean, default: !1 }
|
|
43
420
|
},
|
|
44
421
|
emits: ["animationsstart", "animationsfinish"],
|
|
45
|
-
setup(a, { expose:
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
const
|
|
49
|
-
return
|
|
422
|
+
setup(a, { expose: t, emit: e }) {
|
|
423
|
+
const i = $();
|
|
424
|
+
t({ el: i });
|
|
425
|
+
const s = e, r = C(() => new Intl.NumberFormat(a.locales, a.format)), n = C(() => tt(a.value, r.value, a.prefix, a.suffix)), o = f ? void 0 : et(n.value), l = Y(W, void 0);
|
|
426
|
+
return l == null || l(i, n), (h, d) => (Z(), q("number-flow-vue", J({
|
|
50
427
|
ref_key: "el",
|
|
51
|
-
ref:
|
|
52
|
-
"aria-label":
|
|
53
|
-
},
|
|
428
|
+
ref: i,
|
|
429
|
+
"aria-label": n.value.valueAsString
|
|
430
|
+
}, h.$attrs, {
|
|
54
431
|
role: "img",
|
|
55
|
-
manual: !!
|
|
56
|
-
trend:
|
|
57
|
-
|
|
58
|
-
animated:
|
|
59
|
-
transformTiming:
|
|
60
|
-
spinTiming:
|
|
61
|
-
opacityTiming:
|
|
62
|
-
respectMotionPreference:
|
|
63
|
-
"data-will-change":
|
|
64
|
-
digits:
|
|
65
|
-
innerHTML:
|
|
432
|
+
manual: !!A(l),
|
|
433
|
+
trend: h.trend,
|
|
434
|
+
plugins: h.plugins,
|
|
435
|
+
animated: h.animated,
|
|
436
|
+
transformTiming: h.transformTiming,
|
|
437
|
+
spinTiming: h.spinTiming,
|
|
438
|
+
opacityTiming: h.opacityTiming,
|
|
439
|
+
respectMotionPreference: h.respectMotionPreference,
|
|
440
|
+
"data-will-change": h.willChange ? "" : void 0,
|
|
441
|
+
digits: h.digits,
|
|
442
|
+
innerHTML: A(o),
|
|
66
443
|
"data-allow-mismatch": "",
|
|
67
|
-
onAnimationsstart: d[0] || (d[0] = (
|
|
68
|
-
onAnimationsfinish: d[1] || (d[1] = (
|
|
69
|
-
data:
|
|
70
|
-
}), null, 16,
|
|
444
|
+
onAnimationsstart: d[0] || (d[0] = (U) => s("animationsstart")),
|
|
445
|
+
onAnimationsfinish: d[1] || (d[1] = (U) => s("animationsfinish")),
|
|
446
|
+
data: n.value
|
|
447
|
+
}), null, 16, yt));
|
|
71
448
|
}
|
|
72
449
|
});
|
|
73
|
-
|
|
74
|
-
function
|
|
450
|
+
it("number-flow-vue", c);
|
|
451
|
+
function xt({
|
|
75
452
|
respectMotionPreference: a = !0
|
|
76
453
|
} = {}) {
|
|
77
|
-
const
|
|
78
|
-
return
|
|
79
|
-
var
|
|
80
|
-
|
|
81
|
-
}),
|
|
82
|
-
var
|
|
83
|
-
if (!
|
|
84
|
-
const
|
|
85
|
-
|
|
454
|
+
const t = $(!1), e = $(!1);
|
|
455
|
+
return K(() => {
|
|
456
|
+
var i;
|
|
457
|
+
t.value = st, e.value = ((i = b) == null ? void 0 : i.matches) ?? !1;
|
|
458
|
+
}), Q((i) => {
|
|
459
|
+
var r;
|
|
460
|
+
if (!P(a)) return;
|
|
461
|
+
const s = ({ matches: n }) => {
|
|
462
|
+
e.value = n;
|
|
86
463
|
};
|
|
87
|
-
(
|
|
88
|
-
var
|
|
89
|
-
(
|
|
464
|
+
(r = b) == null || r.addEventListener("change", s), i(() => {
|
|
465
|
+
var n;
|
|
466
|
+
(n = b) == null || n.removeEventListener("change", s);
|
|
90
467
|
});
|
|
91
|
-
}),
|
|
92
|
-
() =>
|
|
468
|
+
}), C(
|
|
469
|
+
() => t.value && (!P(a) || !e.value)
|
|
93
470
|
);
|
|
94
471
|
}
|
|
95
472
|
export {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
473
|
+
Rt as NumberFlowElement,
|
|
474
|
+
St as NumberFlowGroup,
|
|
475
|
+
$t as continuous,
|
|
476
|
+
Ct as default,
|
|
477
|
+
xt as useCanAnimate
|
|
100
478
|
};
|
package/dist/index.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(i,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("vue"),require("number-flow"),require("esm-env")):typeof define=="function"&&define.amd?define(["exports","vue","number-flow","esm-env"],e):(i=typeof globalThis<"u"?globalThis:i||self,e(i["number-flow-vue"]={},i.Vue,i.NumberFlow,i.Env))})(this,function(i,e,t,g){"use strict";const p=Symbol(),T=e.defineComponent({__name:"NumberFlowGroup",setup(s){const d=new Set;let l=!1;const a=(o,u)=>{d.add(o),e.watch(u,async()=>{l||(l=!0,d.forEach(async n=>{var f;!n.value||!n.value.created||(n.value.willUpdate(),await e.nextTick(),(f=n.value)==null||f.didUpdate())}),await e.nextTick(),l=!1)}),e.onUnmounted(()=>{d.delete(o)})};return e.provide(p,a),(o,u)=>e.renderSlot(o.$slots,"default")}}),h=["aria-label","manual","trend","continuous","animated","transformTiming","spinTiming","opacityTiming","respectMotionPreference","data-will-change","digits","innerHTML","data"],y=e.defineComponent({inheritAttrs:!1,__name:"index",props:{transformTiming:{default:()=>t.NumberFlowLite.defaultProps.transformTiming},spinTiming:{default:()=>t.NumberFlowLite.defaultProps.spinTiming},opacityTiming:{default:()=>t.NumberFlowLite.defaultProps.opacityTiming},animated:{type:Boolean,default:()=>t.NumberFlowLite.defaultProps.animated},respectMotionPreference:{type:Boolean,default:()=>t.NumberFlowLite.defaultProps.respectMotionPreference},trend:{type:[Number,Function],default:()=>t.NumberFlowLite.defaultProps.trend},continuous:{type:Boolean,default:()=>t.NumberFlowLite.defaultProps.continuous},digits:{default:()=>t.NumberFlowLite.defaultProps.digits},locales:{},format:{},value:{},prefix:{},suffix:{},willChange:{type:Boolean,default:!1}},emits:["animationsstart","animationsfinish"],setup(s,{expose:d,emit:l}){const a=e.ref();d({el:a});const o=l,u=e.computed(()=>new Intl.NumberFormat(s.locales,s.format)),n=e.computed(()=>t.formatToData(s.value,u.value,s.prefix,s.suffix)),f=g.BROWSER?void 0:t.renderInnerHTML(n.value),m=e.inject(p,void 0);return m==null||m(a,n),(r,c)=>(e.openBlock(),e.createElementBlock("number-flow-vue",e.mergeProps({ref_key:"el",ref:a,"aria-label":n.value.valueAsString},r.$attrs,{role:"img",manual:!!e.unref(m),trend:r.trend,continuous:r.continuous,animated:r.animated,transformTiming:r.transformTiming,spinTiming:r.spinTiming,opacityTiming:r.opacityTiming,respectMotionPreference:r.respectMotionPreference,"data-will-change":r.willChange?"":void 0,digits:r.digits,innerHTML:e.unref(f),"data-allow-mismatch":"",onAnimationsstart:c[0]||(c[0]=L=>o("animationsstart")),onAnimationsfinish:c[1]||(c[1]=L=>o("animationsfinish")),data:n.value}),null,16,h))}});t.define("number-flow-vue",t.NumberFlowLite);function N({respectMotionPreference:s=!0}={}){const d=e.ref(!1),l=e.ref(!1);return e.onMounted(()=>{var a;d.value=t.canAnimate,l.value=((a=t.prefersReducedMotion)==null?void 0:a.matches)??!1}),e.watchEffect(a=>{var u;if(!e.toValue(s))return;const o=({matches:n})=>{l.value=n};(u=t.prefersReducedMotion)==null||u.addEventListener("change",o),a(()=>{var n;(n=t.prefersReducedMotion)==null||n.removeEventListener("change",o)})}),e.computed(()=>d.value&&(!e.toValue(s)||!l.value))}Object.defineProperty(i,"NumberFlowElement",{enumerable:!0,get:()=>t.NumberFlowLite}),i.NumberFlowGroup=T,i.default=y,i.useCanAnimate=N,Object.defineProperties(i,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
|
1
|
+
(function(p,l){typeof exports=="object"&&typeof module<"u"?l(exports,require("vue"),require("number-flow"),require("esm-env")):typeof define=="function"&&define.amd?define(["exports","vue","number-flow","esm-env"],l):(p=typeof globalThis<"u"?globalThis:p||self,l(p["number-flow-vue"]={},p.Vue,p.NumberFlow,p.Env))})(this,function(p,l,d,y){"use strict";const E=Symbol(),W=l.defineComponent({__name:"NumberFlowGroup",setup(a){const t=new Set;let e=!1;const i=(n,r)=>{t.add(n),l.watch(r,async()=>{e||(e=!0,t.forEach(async s=>{var o;!s.value||!s.value.created||(s.value.willUpdate(),await l.nextTick(),(o=s.value)==null||o.didUpdate())}),await l.nextTick(),e=!1)}),l.onUnmounted(()=>{t.delete(n)})};return l.provide(E,i),(n,r)=>l.renderSlot(n.$slots,"default")}}),f=(a,t,e)=>{const i=document.createElement(a),[n,r]=Array.isArray(t)?[void 0,t]:[t,e];return n&&Object.assign(i,n),r==null||r.forEach(s=>i.appendChild(s)),i},O=(a,t)=>{var e;return t==="left"?a.offsetLeft:(((e=a.offsetParent instanceof HTMLElement?a.offsetParent:null)==null?void 0:e.offsetWidth)??0)-a.offsetWidth-a.offsetLeft},X=a=>a.offsetWidth>0&&a.offsetHeight>0;function F(a,t,{reverse:e=!1}={}){const i=a.length;for(let n=e?i-1:0;e?n>=0:n<i;e?n--:n++)t(a[n],n)}const H=String.raw,I=y.BROWSER&&typeof CSS<"u"&&CSS.supports&&CSS.supports("animation-timing-function","linear(1,2)"),q=y.BROWSER&&typeof CSS<"u"&&CSS.supports&&CSS.supports("line-height","mod(1,1)"),j=y.BROWSER&&typeof matchMedia<"u"?matchMedia("(prefers-reduced-motion: reduce)"):null,v="--_number-flow-d-opacity",S="--_number-flow-d-width",_="--_number-flow-dx",C="--_number-flow-d",z=(()=>{try{return CSS.registerProperty({name:v,syntax:"<number>",inherits:!1,initialValue:"0"}),CSS.registerProperty({name:_,syntax:"<length>",inherits:!0,initialValue:"0px"}),CSS.registerProperty({name:S,syntax:"<number>",inherits:!1,initialValue:"0"}),CSS.registerProperty({name:C,syntax:"<number>",inherits:!0,initialValue:"0"}),!0}catch{return!1}})(),D="var(--number-flow-char-height, 1em)",m="var(--number-flow-mask-height, 0.25em)",L=`calc(${m} / 2)`,$="var(--number-flow-mask-width, 0.5em)",g=`calc(${$} / var(--scale-x))`,w="#000 0, transparent 71%",U=H`:host{display:inline-block;direction:ltr;white-space:nowrap;isolation:isolate;line-height:${D} !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(${S}) / var(--width));transform:translateX(var(${_})) scaleX(var(--scale-x));margin:0 calc(-1 * ${$});position:relative;-webkit-mask-image:linear-gradient(to right,transparent 0,#000 ${g},#000 calc(100% - ${g}),transparent ),linear-gradient(to bottom,transparent 0,#000 ${m},#000 calc(100% - ${m}),transparent 100% ),radial-gradient(at bottom right,${w}),radial-gradient(at bottom left,${w}),radial-gradient(at top left,${w}),radial-gradient(at top right,${w});-webkit-mask-size:100% calc(100% - ${m} * 2),calc(100% - ${g} * 2) 100%,${g} ${m},${g} ${m},${g} ${m},${g} ${m};-webkit-mask-position:center,center,top left,top right,bottom right,bottom left;-webkit-mask-repeat:no-repeat}.number__inner{padding:${L} ${$};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__exiting,.symbol__exiting{margin:0 !important;position:absolute !important;z-index:-1}.digit{display:inline-block;position:relative;--c:var(--current) + var(${C})}.digit__num,.number .section::after{padding:${L} 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:not(.is-current){position:absolute;top:0;left:50%;transform:translateX(-50%) translateY(var(--y))}.digit:not(.is-spinning) .digit__num:not(.is-current){display:none}.symbol__value{display:inline-block;mix-blend-mode:plus-lighter;white-space:pre}.section--justify-left .symbol__exiting{left:0}.section--justify-right .symbol__exiting{right:0}.animate-presence{opacity:calc(1 + var(${v}))}`,G=y.BROWSER?HTMLElement:class{},Y=q&&I&&z;let b;class Z extends G{constructor(){super(),this.created=!1,this.manual=!1;const{animated:t,...e}=this.constructor.defaultProps;this._animated=this.computedAnimated=t,Object.assign(this,e)}get animated(){return this._animated}set animated(t){var e;this.animated!==t&&(this._animated=t,(e=this.shadowRoot)==null||e.getAnimations().forEach(i=>i.finish()))}set data(t){var e;if(t==null)return;const{pre:i,integer:n,fraction:r,post:s,value:o}=t;if(this.created){const h=this._data;this._data=t,this.computedTrend=typeof this.trend=="function"?this.trend(h.value,o):this.trend,this.computedAnimated=Y&&this._animated&&(!this.respectMotionPreference||!(j!=null&&j.matches))&&X(this),(e=this.plugins)==null||e.forEach(c=>{var u;return(u=c.onUpdate)==null?void 0:u.call(c,t,h,this)}),this.manual||this.willUpdate(),this._pre.update(i),this._num.update({integer:n,fraction:r}),this._post.update(s),this.manual||this.didUpdate()}else{if(this._data=t,this.attachShadow({mode:"open"}),typeof CSSStyleSheet<"u"&&this.shadowRoot.adoptedStyleSheets)b||(b=new CSSStyleSheet,b.replaceSync(U)),this.shadowRoot.adoptedStyleSheets=[b];else{const h=document.createElement("style");h.textContent=U,this.shadowRoot.appendChild(h)}this._pre=new A(this,i,{justify:"right",part:"left"}),this.shadowRoot.appendChild(this._pre.el),this._num=new J(this,n,r),this.shadowRoot.appendChild(this._num.el),this._post=new A(this,s,{justify:"left",part:"right"}),this.shadowRoot.appendChild(this._post.el)}this.created=!0}willUpdate(){this._pre.willUpdate(),this._num.willUpdate(),this._post.willUpdate()}didUpdate(){if(!this.computedAnimated)return;this._abortAnimationsFinish?this._abortAnimationsFinish.abort():this.dispatchEvent(new Event("animationsstart")),this._pre.didUpdate(),this._num.didUpdate(),this._post.didUpdate();const t=new AbortController;Promise.all(this.shadowRoot.getAnimations().map(e=>e.finished)).then(()=>{t.signal.aborted||(this.dispatchEvent(new Event("animationsfinish")),this._abortAnimationsFinish=void 0)}),this._abortAnimationsFinish=t}}Z.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:(a,t)=>Math.sign(t-a),respectMotionPreference:!0,plugins:void 0,digits:void 0};class J{constructor(t,e,i,{className:n,...r}={}){this.flow=t,this._integer=new k(t,e,{justify:"right",part:"integer"}),this._fraction=new k(t,i,{justify:"left",part:"fraction"}),this._inner=f("span",{className:"number__inner"},[this._integer.el,this._fraction.el]),this.el=f("span",{...r,part:"number",className:`number ${n??""}`},[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,n=this._prevWidth-i;this.el.style.setProperty("--width",String(i)),this.el.animate({[_]:[`${e}px`,"0px"],[S]:[n,0]},{...this.flow.transformTiming,composite:"accumulate"})}}class P{constructor(t,e,{justify:i,className:n,...r},s){this.flow=t,this.children=new Map,this.onCharRemove=h=>()=>{this.children.delete(h)},this.justify=i;const o=e.map(h=>this.addChar(h).el);this.el=f("span",{...r,className:`section section--justify-${i} ${n??""}`},s?s(o):o)}addChar(t,{startDigitsAtZero:e=!1,...i}={}){const n=t.type==="integer"||t.type==="fraction"?new N(this,t.type,e?0:t.value,t.pos,{...i,onRemove:this.onCharRemove(t.key)}):new K(this,t.type,t.value,{...i,onRemove:this.onCharRemove(t.key)});return this.children.set(t.key,n),n}unpop(t){t.el.classList.remove("section__exiting"),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.classList.add("section__exiting"),e.present=!1})}addNewAndUpdateExisting(t){const e=new Map,i=new Map,n=this.justify==="left",r=n?"prepend":"append";if(F(t,s=>{let o;this.children.has(s.key)?(o=this.children.get(s.key),i.set(s,o),this.unpop(o),o.present=!0):(o=this.addChar(s,{startDigitsAtZero:!0,animateIn:!0}),e.set(s,o)),this.el[r](o.el)},{reverse:n}),this.flow.computedAnimated){const s=this.el.getBoundingClientRect();e.forEach(o=>{o.willUpdate(s)})}e.forEach((s,o)=>{s.update(o.value)}),i.forEach((s,o)=>{s.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(n=>n.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 k extends P{update(t){const e=new Map;this.children.forEach((i,n)=>{t.find(r=>r.key===n)||e.set(n,i),this.unpop(i)}),this.addNewAndUpdateExisting(t),e.forEach(i=>{i instanceof N&&i.update(0)}),this.pop(e)}}class A extends P{update(t){const e=new Map;this.children.forEach((i,n)=>{t.find(r=>r.key===n)||e.set(n,i)}),this.pop(e),this.addNewAndUpdateExisting(t)}}class R{constructor(t,e,{onRemove:i,animateIn:n=!1}={}){this.flow=t,this.el=e,this._present=!0,this._remove=()=>{var r;this.el.remove(),(r=this._onRemove)==null||r.call(this)},this.el.classList.add("animate-presence"),this.flow.computedAnimated&&n&&this.el.animate({[v]:[-.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,!this.flow.computedAnimated){t||this._remove();return}this.el.style.setProperty("--_number-flow-d-opacity",t?"0":"-.999"),this.el.animate({[v]: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 M extends R{constructor(t,e,i,n){super(t.flow,i,n),this.section=t,this.value=e,this.el=i}}class N extends M{constructor(t,e,i,n,r){var s,o;const h=(((o=(s=t.flow.digits)==null?void 0:s[n])==null?void 0:o.max)??9)+1,c=Array.from({length:h}).map((B,x)=>{const V=f("span",{className:`digit__num${x===i?" is-current":""}`},[document.createTextNode(String(x))]);return V.style.setProperty("--n",String(x)),V}),u=f("span",{part:`digit ${e}-digit`,className:"digit"},c);u.style.setProperty("--current",String(i)),u.style.setProperty("--length",String(h)),super(t,i,u,r),this.pos=n,this._onAnimationsFinish=()=>{this.el.classList.remove("is-spinning")},this._numbers=c,this.length=h}willUpdate(t){const e=this.el.getBoundingClientRect();this._prevValue=this.value;const i=e[this.section.justify]-t[this.section.justify],n=e.width/2;this._prevCenter=this.section.justify==="left"?i+n:i-n}update(t){var e,i;(e=this._numbers[this.value])==null||e.classList.remove("is-current"),this.el.style.setProperty("--current",String(t)),(i=this._numbers[t])==null||i.classList.add("is-current"),this.value=t}didUpdate(t){const e=this.el.getBoundingClientRect(),i=e[this.section.justify]-t[this.section.justify],n=e.width/2,r=this.section.justify==="left"?i+n:i-n,s=this._prevCenter-r;s&&this.el.animate({transform:[`translateX(${s}px)`,"none"]},{...this.flow.transformTiming,composite:"accumulate"});const o=this.getSpin();o&&(this.el.classList.add("is-spinning"),this.el.animate({[C]:[-o,0]},{...this.flow.spinTiming??this.flow.transformTiming,composite:"accumulate"}),this.flow.addEventListener("animationsfinish",this._onAnimationsFinish,{once:!0}))}getSpin(){var t;if(this.flow.plugins)for(const n of this.flow.plugins){const r=(t=n.getSpin)==null?void 0:t.call(n,this.value,this._prevValue,this);if(r!=null)return r}const e=this.value-this._prevValue,i=this.flow.computedTrend||Math.sign(e);return i<0&&this.value>this._prevValue?this.value-this.length-this._prevValue:i>0&&this.value<this._prevValue?this.length-this._prevValue+this.value:e}}class K extends M{constructor(t,e,i,n){const r=f("span",{className:"symbol__value",textContent:i});super(t,i,f("span",{part:`symbol ${e}`,className:"symbol"},[r]),n),this.type=e,this._children=new Map,this._onChildRemove=s=>()=>{this._children.delete(s)},this._children.set(i,new R(this.flow,r,{onRemove:this._onChildRemove(i)}))}willUpdate(t){if(this.type==="decimal")return;const e=this.el.getBoundingClientRect();this._prevOffset=e[this.section.justify]-t[this.section.justify]}update(t){if(this.value!==t){const e=this._children.get(this.value);if(e.present=!1,e.el.classList.add("symbol__exiting"),this._children.has(t)){const i=this._children.get(t);i.present=!0,i.el.classList.remove("symbol__exiting")}else{const i=f("span",{className:"symbol__value",textContent:t});this.el.appendChild(i),this._children.set(t,new R(this.flow,i,{animateIn:!0,onRemove:this._onChildRemove(t)}))}}this.value=t}didUpdate(t){if(this.type==="decimal")return;const e=this.el.getBoundingClientRect()[this.section.justify]-t[this.section.justify],i=this._prevOffset-e;i&&this.el.animate({transform:[`translateX(${i}px)`,"none"]},{...this.flow.transformTiming,composite:"accumulate"})}}const Q=(a,t)=>a==null?t:t==null?a:Math.max(a,t),T=new WeakMap,tt={onUpdate(a,t,e){if(T.set(e,void 0),!e.computedTrend)return;const i=t.integer.concat(t.fraction).filter(o=>o.type==="integer"||o.type==="fraction"),n=a.integer.concat(a.fraction).filter(o=>o.type==="integer"||o.type==="fraction"),r=i.find(o=>!n.find(h=>h.pos===o.pos&&h.value===o.value)),s=n.find(o=>!i.find(h=>o.pos===h.pos&&o.value===h.value));T.set(e,Q(r==null?void 0:r.pos,s==null?void 0:s.pos))},getSpin(a,t,e){const i=a-t,n=T.get(e.flow);if(!i&&n!=null&&n>=e.pos)return e.length*e.flow.computedTrend}},et=["aria-label","manual","trend","plugins","animated","transformTiming","spinTiming","opacityTiming","respectMotionPreference","data-will-change","digits","innerHTML","data"],it=l.defineComponent({inheritAttrs:!1,__name:"index",props:{transformTiming:{default:()=>d.NumberFlowLite.defaultProps.transformTiming},spinTiming:{default:()=>d.NumberFlowLite.defaultProps.spinTiming},opacityTiming:{default:()=>d.NumberFlowLite.defaultProps.opacityTiming},animated:{type:Boolean,default:()=>d.NumberFlowLite.defaultProps.animated},respectMotionPreference:{type:Boolean,default:()=>d.NumberFlowLite.defaultProps.respectMotionPreference},trend:{type:[Number,Function],default:()=>d.NumberFlowLite.defaultProps.trend},plugins:{default:()=>d.NumberFlowLite.defaultProps.plugins},digits:{default:()=>d.NumberFlowLite.defaultProps.digits},locales:{},format:{},value:{},prefix:{},suffix:{},willChange:{type:Boolean,default:!1}},emits:["animationsstart","animationsfinish"],setup(a,{expose:t,emit:e}){const i=l.ref();t({el:i});const n=e,r=l.computed(()=>new Intl.NumberFormat(a.locales,a.format)),s=l.computed(()=>d.formatToData(a.value,r.value,a.prefix,a.suffix)),o=y.BROWSER?void 0:d.renderInnerHTML(s.value),h=l.inject(E,void 0);return h==null||h(i,s),(c,u)=>(l.openBlock(),l.createElementBlock("number-flow-vue",l.mergeProps({ref_key:"el",ref:i,"aria-label":s.value.valueAsString},c.$attrs,{role:"img",manual:!!l.unref(h),trend:c.trend,plugins:c.plugins,animated:c.animated,transformTiming:c.transformTiming,spinTiming:c.spinTiming,opacityTiming:c.opacityTiming,respectMotionPreference:c.respectMotionPreference,"data-will-change":c.willChange?"":void 0,digits:c.digits,innerHTML:l.unref(o),"data-allow-mismatch":"",onAnimationsstart:u[0]||(u[0]=B=>n("animationsstart")),onAnimationsfinish:u[1]||(u[1]=B=>n("animationsfinish")),data:s.value}),null,16,et))}});d.define("number-flow-vue",d.NumberFlowLite);function nt({respectMotionPreference:a=!0}={}){const t=l.ref(!1),e=l.ref(!1);return l.onMounted(()=>{var i;t.value=d.canAnimate,e.value=((i=d.prefersReducedMotion)==null?void 0:i.matches)??!1}),l.watchEffect(i=>{var r;if(!l.toValue(a))return;const n=({matches:s})=>{e.value=s};(r=d.prefersReducedMotion)==null||r.addEventListener("change",n),i(()=>{var s;(s=d.prefersReducedMotion)==null||s.removeEventListener("change",n)})}),l.computed(()=>t.value&&(!l.toValue(a)||!e.value))}Object.defineProperty(p,"NumberFlowElement",{enumerable:!0,get:()=>d.NumberFlowLite}),p.NumberFlowGroup=W,p.continuous=tt,p.default=it,p.useCanAnimate=nt,Object.defineProperties(p,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"version": "0.
|
|
7
|
+
"version": "0.4.0",
|
|
8
8
|
"author": {
|
|
9
9
|
"name": "Maxwell Barvian",
|
|
10
10
|
"email": "max@barvian.me",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
47
|
"esm-env": "^1.1.4",
|
|
48
|
-
"number-flow": "0.
|
|
48
|
+
"number-flow": "0.5.0"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"@playwright/test": "^1.48.0",
|