tiny-spark 0.2.7 → 0.2.8-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,533 @@
1
+ import mt, { useRef as bt, useEffect as gt } from "react";
2
+ var U = { exports: {} }, Y = {};
3
+ /**
4
+ * @license React
5
+ * react-jsx-runtime.production.js
6
+ *
7
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
8
+ *
9
+ * This source code is licensed under the MIT license found in the
10
+ * LICENSE file in the root directory of this source tree.
11
+ */
12
+ var et;
13
+ function pt() {
14
+ if (et) return Y;
15
+ et = 1;
16
+ var t = Symbol.for("react.transitional.element"), n = Symbol.for("react.fragment");
17
+ function s(o, a, i) {
18
+ var d = null;
19
+ if (i !== void 0 && (d = "" + i), a.key !== void 0 && (d = "" + a.key), "key" in a) {
20
+ i = {};
21
+ for (var r in a)
22
+ r !== "key" && (i[r] = a[r]);
23
+ } else i = a;
24
+ return a = i.ref, {
25
+ $$typeof: t,
26
+ type: o,
27
+ key: d,
28
+ ref: a !== void 0 ? a : null,
29
+ props: i
30
+ };
31
+ }
32
+ return Y.Fragment = n, Y.jsx = s, Y.jsxs = s, Y;
33
+ }
34
+ var V = {};
35
+ /**
36
+ * @license React
37
+ * react-jsx-runtime.development.js
38
+ *
39
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
40
+ *
41
+ * This source code is licensed under the MIT license found in the
42
+ * LICENSE file in the root directory of this source tree.
43
+ */
44
+ var rt;
45
+ function ht() {
46
+ return rt || (rt = 1, process.env.NODE_ENV !== "production" && function() {
47
+ function t(e) {
48
+ if (e == null) return null;
49
+ if (typeof e == "function")
50
+ return e.$$typeof === u ? null : e.displayName || e.name || null;
51
+ if (typeof e == "string") return e;
52
+ switch (e) {
53
+ case w:
54
+ return "Fragment";
55
+ case v:
56
+ return "Profiler";
57
+ case M:
58
+ return "StrictMode";
59
+ case W:
60
+ return "Suspense";
61
+ case F:
62
+ return "SuspenseList";
63
+ case E:
64
+ return "Activity";
65
+ }
66
+ if (typeof e == "object")
67
+ switch (typeof e.tag == "number" && console.error(
68
+ "Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."
69
+ ), e.$$typeof) {
70
+ case j:
71
+ return "Portal";
72
+ case O:
73
+ return (e.displayName || "Context") + ".Provider";
74
+ case N:
75
+ return (e._context.displayName || "Context") + ".Consumer";
76
+ case $:
77
+ var c = e.render;
78
+ return e = e.displayName, e || (e = c.displayName || c.name || "", e = e !== "" ? "ForwardRef(" + e + ")" : "ForwardRef"), e;
79
+ case D:
80
+ return c = e.displayName || null, c !== null ? c : t(e.type) || "Memo";
81
+ case m:
82
+ c = e._payload, e = e._init;
83
+ try {
84
+ return t(e(c));
85
+ } catch {
86
+ }
87
+ }
88
+ return null;
89
+ }
90
+ function n(e) {
91
+ return "" + e;
92
+ }
93
+ function s(e) {
94
+ try {
95
+ n(e);
96
+ var c = !1;
97
+ } catch {
98
+ c = !0;
99
+ }
100
+ if (c) {
101
+ c = console;
102
+ var f = c.error, h = typeof Symbol == "function" && Symbol.toStringTag && e[Symbol.toStringTag] || e.constructor.name || "Object";
103
+ return f.call(
104
+ c,
105
+ "The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",
106
+ h
107
+ ), n(e);
108
+ }
109
+ }
110
+ function o(e) {
111
+ if (e === w) return "<>";
112
+ if (typeof e == "object" && e !== null && e.$$typeof === m)
113
+ return "<...>";
114
+ try {
115
+ var c = t(e);
116
+ return c ? "<" + c + ">" : "<...>";
117
+ } catch {
118
+ return "<...>";
119
+ }
120
+ }
121
+ function a() {
122
+ var e = S.A;
123
+ return e === null ? null : e.getOwner();
124
+ }
125
+ function i() {
126
+ return Error("react-stack-top-frame");
127
+ }
128
+ function d(e) {
129
+ if (g.call(e, "key")) {
130
+ var c = Object.getOwnPropertyDescriptor(e, "key").get;
131
+ if (c && c.isReactWarning) return !1;
132
+ }
133
+ return e.key !== void 0;
134
+ }
135
+ function r(e, c) {
136
+ function f() {
137
+ X || (X = !0, console.error(
138
+ "%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",
139
+ c
140
+ ));
141
+ }
142
+ f.isReactWarning = !0, Object.defineProperty(e, "key", {
143
+ get: f,
144
+ configurable: !0
145
+ });
146
+ }
147
+ function b() {
148
+ var e = t(this.type);
149
+ return Z[e] || (Z[e] = !0, console.error(
150
+ "Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release."
151
+ )), e = this.props.ref, e !== void 0 ? e : null;
152
+ }
153
+ function p(e, c, f, h, L, k, B, H) {
154
+ return f = k.ref, e = {
155
+ $$typeof: P,
156
+ type: e,
157
+ key: c,
158
+ props: k,
159
+ _owner: L
160
+ }, (f !== void 0 ? f : null) !== null ? Object.defineProperty(e, "ref", {
161
+ enumerable: !1,
162
+ get: b
163
+ }) : Object.defineProperty(e, "ref", { enumerable: !1, value: null }), e._store = {}, Object.defineProperty(e._store, "validated", {
164
+ configurable: !1,
165
+ enumerable: !1,
166
+ writable: !0,
167
+ value: 0
168
+ }), Object.defineProperty(e, "_debugInfo", {
169
+ configurable: !1,
170
+ enumerable: !1,
171
+ writable: !0,
172
+ value: null
173
+ }), Object.defineProperty(e, "_debugStack", {
174
+ configurable: !1,
175
+ enumerable: !1,
176
+ writable: !0,
177
+ value: B
178
+ }), Object.defineProperty(e, "_debugTask", {
179
+ configurable: !1,
180
+ enumerable: !1,
181
+ writable: !0,
182
+ value: H
183
+ }), Object.freeze && (Object.freeze(e.props), Object.freeze(e)), e;
184
+ }
185
+ function l(e, c, f, h, L, k, B, H) {
186
+ var y = c.children;
187
+ if (y !== void 0)
188
+ if (h)
189
+ if (dt(y)) {
190
+ for (h = 0; h < y.length; h++)
191
+ _(y[h]);
192
+ Object.freeze && Object.freeze(y);
193
+ } else
194
+ console.error(
195
+ "React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead."
196
+ );
197
+ else _(y);
198
+ if (g.call(c, "key")) {
199
+ y = t(e);
200
+ var T = Object.keys(c).filter(function(ft) {
201
+ return ft !== "key";
202
+ });
203
+ h = 0 < T.length ? "{key: someKey, " + T.join(": ..., ") + ": ...}" : "{key: someKey}", tt[y + h] || (T = 0 < T.length ? "{" + T.join(": ..., ") + ": ...}" : "{}", console.error(
204
+ `A props object containing a "key" prop is being spread into JSX:
205
+ let props = %s;
206
+ <%s {...props} />
207
+ React keys must be passed directly to JSX without using spread:
208
+ let props = %s;
209
+ <%s key={someKey} {...props} />`,
210
+ h,
211
+ y,
212
+ T,
213
+ y
214
+ ), tt[y + h] = !0);
215
+ }
216
+ if (y = null, f !== void 0 && (s(f), y = "" + f), d(c) && (s(c.key), y = "" + c.key), "key" in c) {
217
+ f = {};
218
+ for (var J in c)
219
+ J !== "key" && (f[J] = c[J]);
220
+ } else f = c;
221
+ return y && r(
222
+ f,
223
+ typeof e == "function" ? e.displayName || e.name || "Unknown" : e
224
+ ), p(
225
+ e,
226
+ y,
227
+ k,
228
+ L,
229
+ a(),
230
+ f,
231
+ B,
232
+ H
233
+ );
234
+ }
235
+ function _(e) {
236
+ typeof e == "object" && e !== null && e.$$typeof === P && e._store && (e._store.validated = 1);
237
+ }
238
+ var A = mt, P = Symbol.for("react.transitional.element"), j = Symbol.for("react.portal"), w = Symbol.for("react.fragment"), M = Symbol.for("react.strict_mode"), v = Symbol.for("react.profiler"), N = Symbol.for("react.consumer"), O = Symbol.for("react.context"), $ = Symbol.for("react.forward_ref"), W = Symbol.for("react.suspense"), F = Symbol.for("react.suspense_list"), D = Symbol.for("react.memo"), m = Symbol.for("react.lazy"), E = Symbol.for("react.activity"), u = Symbol.for("react.client.reference"), S = A.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, g = Object.prototype.hasOwnProperty, dt = Array.isArray, q = console.createTask ? console.createTask : function() {
239
+ return null;
240
+ };
241
+ A = {
242
+ "react-stack-bottom-frame": function(e) {
243
+ return e();
244
+ }
245
+ };
246
+ var X, Z = {}, K = A["react-stack-bottom-frame"].bind(
247
+ A,
248
+ i
249
+ )(), Q = q(o(i)), tt = {};
250
+ V.Fragment = w, V.jsx = function(e, c, f, h, L) {
251
+ var k = 1e4 > S.recentlyCreatedOwnerStacks++;
252
+ return l(
253
+ e,
254
+ c,
255
+ f,
256
+ !1,
257
+ h,
258
+ L,
259
+ k ? Error("react-stack-top-frame") : K,
260
+ k ? q(o(e)) : Q
261
+ );
262
+ }, V.jsxs = function(e, c, f, h, L) {
263
+ var k = 1e4 > S.recentlyCreatedOwnerStacks++;
264
+ return l(
265
+ e,
266
+ c,
267
+ f,
268
+ !0,
269
+ h,
270
+ L,
271
+ k ? Error("react-stack-top-frame") : K,
272
+ k ? q(o(e)) : Q
273
+ );
274
+ };
275
+ }()), V;
276
+ }
277
+ var nt;
278
+ function yt() {
279
+ return nt || (nt = 1, process.env.NODE_ENV === "production" ? U.exports = pt() : U.exports = ht()), U.exports;
280
+ }
281
+ var Et = yt();
282
+ const I = "http://www.w3.org/2000/svg", z = 1e3;
283
+ var ct = /* @__PURE__ */ ((t) => (t.BAR = "data-bar", t.LINE = "data-line", t.SET = "data-set", t.RESPONSIVE = "data-responsive", t))(ct || {}), R = /* @__PURE__ */ ((t) => (t.ANIMATION = "animation", t.AREA_COLOR = "areaColor", t.CURVE = "curve", t.DATES = "dates", t.INDICATOR_COLOR = "indicatorColor", t.INDICATOR_WIDTH = "indicatorWidth", t.LINE_COLOR = "lineColor", t.LINE_THICKNESS = "lineThickness", t.NUMBER_LOCALE = "numberLocale", t.NUMBER_ROUNDING = "numberRounding", t.NUMBER_SHOW_ON = "numberShowOn", t.PLOT_COLOR = "plotColor", t.PLOT_RADIUS = "plotRadius", t.SET = "set", t))(R || {});
284
+ function vt(t) {
285
+ const { width: n, height: s } = t.parentElement.getBoundingClientRect(), o = { width: 300, height: 100 }, a = `0 0 ${n || o.width} ${s || o.height}`, i = document.createElementNS(I, "svg"), d = t.dataset.id;
286
+ return i.id = d, i.setAttribute("viewBox", a), i.style.width = "100%", i.style.height = "100%", {
287
+ svg: i,
288
+ svgId: d,
289
+ width: n || o.width,
290
+ height: s || o.height
291
+ };
292
+ }
293
+ function C(t, n = 0) {
294
+ return isNaN(t) ? n : t;
295
+ }
296
+ function ot(t) {
297
+ let n = [];
298
+ for (let s = 0; s < t.length; s += 1)
299
+ n.push(`${C(t[s].x)},${C(t[s].y)} `);
300
+ return n.join(" ").trim();
301
+ }
302
+ function st(t) {
303
+ if (t.length < 1) return "0,0";
304
+ const n = t.length - 1, s = [`${C(t[0].x)},${C(t[0].y)}`], o = [], a = [], i = [], d = [];
305
+ for (let r = 0; r < n; r += 1)
306
+ o[r] = t[r + 1].x - t[r].x, a[r] = t[r + 1].y - t[r].y, i[r] = a[r] / o[r];
307
+ d[0] = i[0], d[n] = i[n - 1];
308
+ for (let r = 1; r < n; r += 1)
309
+ if (i[r - 1] * i[r] <= 0)
310
+ d[r] = 0;
311
+ else {
312
+ const b = 2 * i[r - 1] * i[r] / (i[r - 1] + i[r]);
313
+ d[r] = b;
314
+ }
315
+ for (let r = 0; r < n; r += 1) {
316
+ const b = t[r].x, p = t[r].y, l = t[r + 1].x, _ = t[r + 1].y, A = d[r], P = d[r + 1], j = b + (l - b) / 3, w = p + A * (l - b) / 3, M = l - (l - b) / 3, v = _ - P * (l - b) / 3;
317
+ s.push(`C ${C(j)},${C(w)} ${C(M)},${C(v)} ${C(l)},${C(_)}`);
318
+ }
319
+ return s.join(" ");
320
+ }
321
+ function St(t, n = z) {
322
+ t.style.opacity = "1";
323
+ const s = t.getTotalLength();
324
+ t.style.strokeDasharray = String(s), t.style.strokeDashoffset = String(s), t.getBoundingClientRect(), t.style.transition = `stroke-dashoffset ${n}ms ease-in-out`, t.style.strokeDashoffset = "0", t.addEventListener("transitionend", function o() {
325
+ t.style.transition = "", t.removeEventListener("transitionend", o);
326
+ });
327
+ }
328
+ function xt(t, n, s = z) {
329
+ n.style.opacity = "1";
330
+ const o = n.getBBox(), a = o.width, i = document.createElementNS("http://www.w3.org/2000/svg", "clipPath"), d = "clip-" + Math.random().toString(36).substr(2, 9);
331
+ i.setAttribute("id", d);
332
+ const r = document.createElementNS("http://www.w3.org/2000/svg", "rect");
333
+ r.setAttribute("x", o.x.toString()), r.setAttribute("y", o.y.toString()), r.setAttribute("width", "0"), r.setAttribute("height", o.height.toString()), i.appendChild(r);
334
+ let b = t.querySelector("defs");
335
+ b || (b = document.createElementNS("http://www.w3.org/2000/svg", "defs"), t.insertBefore(b, t.firstChild)), b.appendChild(i), n.setAttribute("clip-path", `url(#${d})`), r.style.transition = `width ${s}ms ease-out`, r.getBoundingClientRect(), r.setAttribute("width", a.toString()), r.addEventListener("transitionend", function p() {
336
+ n.removeAttribute("clip-path"), i.parentNode && i.parentNode.removeChild(i), r.removeEventListener("transitionend", p);
337
+ });
338
+ }
339
+ function Rt() {
340
+ return document.querySelectorAll(".tiny-spark");
341
+ }
342
+ function ut(t, n) {
343
+ return Object.keys(t.dataset).includes(n);
344
+ }
345
+ function x(t, n, s) {
346
+ return ut(t, n) ? t.dataset[n] : s;
347
+ }
348
+ function wt(t, n) {
349
+ const s = new MutationObserver((o) => {
350
+ for (const a of o)
351
+ if (a.type === "attributes" && a.attributeName && Object.values(ct).includes(a.attributeName)) {
352
+ n();
353
+ break;
354
+ }
355
+ });
356
+ return s.observe(t, { attributes: !0 }), s;
357
+ }
358
+ function Ot(t) {
359
+ if (!t) return {
360
+ color: "#1A1A1A",
361
+ backgroundColor: "#FFFFFF"
362
+ };
363
+ const n = window.getComputedStyle(t), s = n.getPropertyValue("color") || "#1A1A1A", o = n.getPropertyValue("background-color"), a = n.getPropertyValue("background");
364
+ return { color: s, backgroundColor: o || a || "#FFFFFF" };
365
+ }
366
+ function _t() {
367
+ return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(t) {
368
+ const n = Math.random() * 16 | 0;
369
+ return (t == "x" ? n : n & 3 | 8).toString(16);
370
+ });
371
+ }
372
+ function Nt(t) {
373
+ const n = t.getAttribute("data-set");
374
+ if (!n) return [];
375
+ try {
376
+ const s = JSON.parse(n);
377
+ return Array.isArray(s) && s.every((o) => typeof o == "number" || [null, void 0].includes(o)) ? s : (console.warn("data-set is not an array of numbers."), []);
378
+ } catch (s) {
379
+ return console.error("Error parsing data-set:", s), [];
380
+ }
381
+ }
382
+ function kt(t) {
383
+ const n = t.getAttribute("data-dates");
384
+ if (!n) return [];
385
+ try {
386
+ const s = JSON.parse(n);
387
+ return Array.isArray(s) && s.every((o) => typeof o == "string") ? s : (console.warn("data-dates is not an array of strings"), []);
388
+ } catch (s) {
389
+ return console.error("Error parsing data-dates", s), [];
390
+ }
391
+ }
392
+ function it(t) {
393
+ return {
394
+ min: Math.min(...t),
395
+ max: Math.max(...t)
396
+ };
397
+ }
398
+ function lt() {
399
+ return new Promise((t) => setTimeout(t, 0));
400
+ }
401
+ function Ct(t, n) {
402
+ const s = String(x(t, R.NUMBER_LOCALE, navigator.language || "en-US")), o = Number(String(x(t, R.NUMBER_ROUNDING, 0)));
403
+ return n.toLocaleString(s, {
404
+ useGrouping: !0,
405
+ minimumFractionDigits: o,
406
+ maximumFractionDigits: o
407
+ });
408
+ }
409
+ function At(t, n, s) {
410
+ if (!t.createSVGPoint || !t.getScreenCTM)
411
+ throw new Error("Your browser does not support SVG coordinate transformation.");
412
+ const o = t.getScreenCTM();
413
+ if (!o)
414
+ throw new Error("Cannot obtain the screen CTM.");
415
+ const a = t.createSVGPoint();
416
+ a.x = n, a.y = s;
417
+ const i = a.matrixTransform(o);
418
+ return { x: i.x, y: i.y };
419
+ }
420
+ function at(t, n, s, o, a) {
421
+ if (Pt(o), !a) return;
422
+ const { x: i, y: d } = At(t, s.x, s.y), r = document.createElement("div");
423
+ r.style.opacity = "0", r.classList.add("tiny-spark-tooltip"), r.setAttribute("id", `tooltip_${o}`), r.style.pointerEvents = "none", r.style.position = "fixed", r.style.top = d + "px", r.style.left = i + "px", r.style.width = "fit-content", r.innerHTML = `
424
+ <div class="tiny-spark-tooltip-content">${s.d ? `${s.d}: ` : ""}${[null, void 0].includes(s.v) ? "-" : Ct(n, Number(s.v))}</div>
425
+ `, document.body.appendChild(r), lt().then(() => {
426
+ const { width: b, height: p } = r.getBoundingClientRect();
427
+ r.style.left = `${i - b / 2}px`, r.style.top = `${d - p - Number(String(Number(x(n, R.PLOT_RADIUS, 3)) * 1.5))}px`;
428
+ }).then(() => {
429
+ r.style.opacity = "1";
430
+ });
431
+ }
432
+ function Pt(t) {
433
+ const n = document.getElementById(`tooltip_${t}`);
434
+ n == null || n.remove();
435
+ }
436
+ function $t(t) {
437
+ t.innerHTML = "";
438
+ }
439
+ function Lt(t, n) {
440
+ let s = n;
441
+ $t(t);
442
+ const { svg: o, svgId: a, width: i, height: d } = vt(t), { color: r, backgroundColor: b } = Ot(t), p = { T: 12, R: 12, B: 12, L: 12 }, l = {
443
+ left: p.L,
444
+ top: p.T,
445
+ width: i - p.L - p.R,
446
+ height: d - p.T - p.B,
447
+ bottom: d - p.B
448
+ }, _ = Nt(t), { min: A } = it(_), P = _.map((m) => [null, void 0].includes(m) ? m : m + (A < 0 ? Math.abs(A) : 0)), { max: j } = it(P), w = l.width / (_.length - 1) === 1 / 0 ? l.width : l.width / (_.length - 1), M = kt(t), v = P.map((m, E) => {
449
+ const u = {
450
+ w: P.length === 1 ? w / 2 : 0,
451
+ h: P.length === 1 ? l.height / 2 : 0
452
+ };
453
+ return {
454
+ y: (1 - (m || 0) / j) * l.height + p.T + u.h,
455
+ x: l.left + w * E + u.w,
456
+ v: m,
457
+ d: M[E] || null
458
+ };
459
+ }), N = [...v].filter(({ v: m }) => ![null, void 0].includes(m)), O = document.createElementNS(I, "path");
460
+ O.classList.add("tiny-spark-line-path"), !t.dataset.curve || t.dataset.curve === "true" ? O.setAttribute("d", `M ${st(N)}`) : O.setAttribute("d", `M ${ot(N)}`), O.setAttribute("fill", "none"), O.setAttribute("stroke", String(x(t, R.LINE_COLOR, r))), O.setAttribute("stroke-width", String(x(t, R.LINE_THICKNESS, 2))), O.setAttribute("stroke-linecap", "round");
461
+ const $ = document.createElementNS(I, "path");
462
+ $.classList.add("tiny-spark-line-area");
463
+ const W = t.getAttribute("data-animation");
464
+ W === "true" && s && (O.style.opacity = "0", $.style.opacity = "0"), v.length && (!t.dataset.curve || t.dataset.curve === "true" ? $.setAttribute("d", `M ${N[0].x},${l.bottom} ${st(N)} L ${N.at(-1).x},${l.bottom} Z`) : $.setAttribute("d", `M ${N[0].x},${l.bottom} ${ot(N)} L ${N.at(-1).x},${l.bottom} Z`)), $.setAttribute("fill", String(x(t, R.AREA_COLOR, "transparent"))), v.length > 1 && (o.appendChild($), o.appendChild(O));
465
+ const F = [];
466
+ v.forEach((m, E) => {
467
+ const u = document.createElementNS(I, "line");
468
+ u.classList.add("tiny-spark-indicator"), u.setAttribute("id", `indicator_${a}_${E}`), u.setAttribute("x1", String(l.left + (v.length === 1 ? l.width / 2 : E * w))), u.setAttribute("x2", String(l.left + (v.length === 1 ? l.width / 2 : E * w))), u.setAttribute("y1", String(l.top)), u.setAttribute("y2", String(l.bottom)), u.setAttribute("stroke", String(x(t, R.INDICATOR_COLOR, "#1A1A1A"))), u.setAttribute("stroke-width", String(x(t, R.INDICATOR_WIDTH, "1"))), u.setAttribute("stroke-linecap", "round"), u.style.pointerEvents = "none", u.style.opacity = "0", F.push(u), o.appendChild(u);
469
+ });
470
+ let D = [];
471
+ Number(String(x(t, R.PLOT_RADIUS, 0))) > 0 && v.forEach(({ x: m, y: E, v: u }, S) => {
472
+ if (![null, void 0].includes(u)) {
473
+ const g = document.createElementNS(I, "circle");
474
+ g.classList.add("tiny-spark-datapoint-circle"), g.classList.add(`circle-${a}`), g.setAttribute("id", `circle_${a}_${S}`), g.setAttribute("cx", String(m || 0)), g.setAttribute("cy", String(E || 0)), g.setAttribute("r", String(x(t, R.PLOT_RADIUS, 3))), g.setAttribute("fill", String(x(t, R.PLOT_COLOR, String(x(t, "lineColor", r))))), g.setAttribute("stroke", b), g.style.opacity = "0", g.style.transition = `opacity ${S * (z * 2 / v.length)}ms ease-in`, o.appendChild(g), D.push(g);
475
+ }
476
+ }), v.forEach((m, E) => {
477
+ const u = document.createElementNS(I, "rect");
478
+ u.classList.add("tiny-spark-tooltip-trap"), u.setAttribute("x", `${v.length === 1 ? 0 : l.left + E * w - w / 2}`), u.setAttribute("y", `${l.top}`), u.setAttribute("height", `${l.height}`), u.setAttribute("width", `${w}`), u.setAttribute("fill", "transparent"), u.addEventListener("mouseenter", () => {
479
+ at(o, t, m, a, !0);
480
+ const S = document.getElementById(`circle_${a}_${E}`);
481
+ S == null || S.setAttribute("r", String(Number(x(t, R.PLOT_RADIUS, 3)) * 1.5)), F[E].style.opacity = "1";
482
+ }), u.addEventListener("mouseout", () => {
483
+ at(o, t, m, a, !1);
484
+ const S = document.getElementById(`circle_${a}_${E}`);
485
+ S == null || S.setAttribute("r", String(Number(x(t, R.PLOT_RADIUS, 3)))), F.forEach((g) => g.style.opacity = "0");
486
+ }), o.appendChild(u);
487
+ }), W === "true" && s ? lt().then(() => {
488
+ D.forEach((m) => {
489
+ m.style.opacity = "1";
490
+ }), St(O), xt(o, $);
491
+ }) : D.forEach((m) => {
492
+ m.style.opacity = "1";
493
+ }), t.appendChild(o);
494
+ }
495
+ function Tt() {
496
+ const t = Rt();
497
+ t.length && Array.from(t).forEach((n) => {
498
+ const s = _t();
499
+ n.setAttribute("data-id", s);
500
+ const o = n;
501
+ It(o), o.__renderCount = 0, G(o), wt(o, () => G(o));
502
+ const a = new ResizeObserver((d) => {
503
+ d.forEach(() => G(o));
504
+ });
505
+ o.parentElement && a.observe(o.parentElement), new MutationObserver((d) => {
506
+ d.forEach((r) => {
507
+ r.type === "attributes" && r.attributeName && r.attributeName.startsWith("data-") && G(o);
508
+ });
509
+ }).observe(o, { attributes: !0 });
510
+ });
511
+ }
512
+ function G(t) {
513
+ ut(t, "set") && Lt(t, t.__renderCount < 2), t.__renderCount += 1;
514
+ }
515
+ function It(t) {
516
+ t.dataset.set || console.error(
517
+ `Tiny-spark exception:
518
+
519
+ [data-set] data attribute is missing.
520
+ Provide an array of numbers, for example:
521
+
522
+ data-set="[1, 2, 3]"`
523
+ );
524
+ }
525
+ const Mt = (t) => {
526
+ const n = bt(null);
527
+ return gt(() => {
528
+ n.current && Tt();
529
+ }, []), /* @__PURE__ */ Et.jsx("div", { ref: n, className: "tiny-spark", ...t });
530
+ };
531
+ export {
532
+ Mt as TinySparkChart
533
+ };
@@ -1,28 +1,28 @@
1
- const A = "http://www.w3.org/2000/svg";
2
- var B = /* @__PURE__ */ ((t) => (t.BAR = "data-bar", t.LINE = "data-line", t.SET = "data-set", t.RESPONSIVE = "data-responsive", t))(B || {}), h = /* @__PURE__ */ ((t) => (t.ANIMATION = "animation", t.AREA_COLOR = "areaColor", t.CURVE = "curve", t.DATES = "dates", t.INDICATOR_COLOR = "indicatorColor", t.INDICATOR_WIDTH = "indicatorWidth", t.LINE_COLOR = "lineColor", t.LINE_THICKNESS = "lineThickness", t.NUMBER_LOCALE = "numberLocale", t.NUMBER_ROUNDING = "numberRounding", t.NUMBER_SHOW_ON = "numberShowOn", t.PLOT_COLOR = "plotColor", t.PLOT_RADIUS = "plotRadius", t.SET = "set", t))(h || {});
3
- function U(t) {
4
- const { width: n, height: r } = t.parentElement.getBoundingClientRect(), o = { width: 300, height: 100 }, s = `0 0 ${n || o.width} ${r || o.height}`, i = document.createElementNS(A, "svg"), u = t.dataset.id;
1
+ const L = "http://www.w3.org/2000/svg";
2
+ var V = /* @__PURE__ */ ((t) => (t.BAR = "data-bar", t.LINE = "data-line", t.SET = "data-set", t.RESPONSIVE = "data-responsive", t))(V || {}), h = /* @__PURE__ */ ((t) => (t.ANIMATION = "animation", t.AREA_COLOR = "areaColor", t.CURVE = "curve", t.DATES = "dates", t.INDICATOR_COLOR = "indicatorColor", t.INDICATOR_WIDTH = "indicatorWidth", t.LINE_COLOR = "lineColor", t.LINE_THICKNESS = "lineThickness", t.NUMBER_LOCALE = "numberLocale", t.NUMBER_ROUNDING = "numberRounding", t.NUMBER_SHOW_ON = "numberShowOn", t.PLOT_COLOR = "plotColor", t.PLOT_RADIUS = "plotRadius", t.SET = "set", t))(h || {});
3
+ function G(t) {
4
+ const { width: n, height: o } = t.parentElement.getBoundingClientRect(), r = { width: 300, height: 100 }, s = `0 0 ${n || r.width} ${o || r.height}`, i = document.createElementNS(L, "svg"), u = t.dataset.id;
5
5
  return i.id = u, i.setAttribute("viewBox", s), i.style.width = "100%", i.style.height = "100%", {
6
6
  svg: i,
7
7
  svgId: u,
8
- width: n || o.width,
9
- height: r || o.height
8
+ width: n || r.width,
9
+ height: o || r.height
10
10
  };
11
11
  }
12
12
  function S(t, n = 0) {
13
13
  return isNaN(t) ? n : t;
14
14
  }
15
- function P(t) {
15
+ function M(t) {
16
16
  let n = [];
17
- for (let r = 0; r < t.length; r += 1)
18
- n.push(`${S(t[r].x)},${S(t[r].y)} `);
17
+ for (let o = 0; o < t.length; o += 1)
18
+ n.push(`${S(t[o].x)},${S(t[o].y)} `);
19
19
  return n.join(" ").trim();
20
20
  }
21
- function F(t) {
21
+ function P(t) {
22
22
  if (t.length < 1) return "0,0";
23
- const n = t.length - 1, r = [`${S(t[0].x)},${S(t[0].y)}`], o = [], s = [], i = [], u = [];
23
+ const n = t.length - 1, o = [`${S(t[0].x)},${S(t[0].y)}`], r = [], s = [], i = [], u = [];
24
24
  for (let e = 0; e < n; e += 1)
25
- o[e] = t[e + 1].x - t[e].x, s[e] = t[e + 1].y - t[e].y, i[e] = s[e] / o[e];
25
+ r[e] = t[e + 1].x - t[e].x, s[e] = t[e + 1].y - t[e].y, i[e] = s[e] / r[e];
26
26
  u[0] = i[0], u[n] = i[n - 1];
27
27
  for (let e = 1; e < n; e += 1)
28
28
  if (i[e - 1] * i[e] <= 0)
@@ -32,208 +32,206 @@ function F(t) {
32
32
  u[e] = d;
33
33
  }
34
34
  for (let e = 0; e < n; e += 1) {
35
- const d = t[e].x, C = t[e].y, g = t[e + 1].x, c = t[e + 1].y, O = u[e], $ = u[e + 1], L = d + (g - d) / 3, k = C + O * (g - d) / 3, N = g - (g - d) / 3, I = c - $ * (g - d) / 3;
36
- r.push(`C ${S(L)},${S(k)} ${S(N)},${S(I)} ${S(g)},${S(c)}`);
35
+ const d = t[e].x, g = t[e].y, c = t[e + 1].x, C = t[e + 1].y, A = u[e], O = u[e + 1], E = d + (c - d) / 3, N = g + A * (c - d) / 3, k = c - (c - d) / 3, m = C - O * (c - d) / 3;
36
+ o.push(`C ${S(E)},${S(N)} ${S(k)},${S(m)} ${S(c)},${S(C)}`);
37
37
  }
38
- return r.join(" ");
38
+ return o.join(" ");
39
39
  }
40
- function W(t, n = 1e3) {
40
+ function U(t, n = 1e3) {
41
41
  t.style.opacity = "1";
42
- const r = t.getTotalLength();
43
- t.style.strokeDasharray = String(r), t.style.strokeDashoffset = String(r), t.getBoundingClientRect(), t.style.transition = `stroke-dashoffset ${n}ms ease-in-out`, t.style.strokeDashoffset = "0", t.addEventListener("transitionend", function o() {
44
- t.style.transition = "", t.removeEventListener("transitionend", o);
42
+ const o = t.getTotalLength();
43
+ t.style.strokeDasharray = String(o), t.style.strokeDashoffset = String(o), t.getBoundingClientRect(), t.style.transition = `stroke-dashoffset ${n}ms ease-in-out`, t.style.strokeDashoffset = "0", t.addEventListener("transitionend", function r() {
44
+ t.style.transition = "", t.removeEventListener("transitionend", r);
45
45
  });
46
46
  }
47
- function j(t, n, r = 1e3) {
47
+ function W(t, n, o = 1e3) {
48
48
  n.style.opacity = "1";
49
- const o = n.getBBox(), s = o.width, i = document.createElementNS("http://www.w3.org/2000/svg", "clipPath"), u = "clip-" + Math.random().toString(36).substr(2, 9);
49
+ const r = n.getBBox(), s = r.width, i = document.createElementNS("http://www.w3.org/2000/svg", "clipPath"), u = "clip-" + Math.random().toString(36).substr(2, 9);
50
50
  i.setAttribute("id", u);
51
51
  const e = document.createElementNS("http://www.w3.org/2000/svg", "rect");
52
- e.setAttribute("x", o.x.toString()), e.setAttribute("y", o.y.toString()), e.setAttribute("width", "0"), e.setAttribute("height", o.height.toString()), i.appendChild(e);
52
+ e.setAttribute("x", r.x.toString()), e.setAttribute("y", r.y.toString()), e.setAttribute("width", "0"), e.setAttribute("height", r.height.toString()), i.appendChild(e);
53
53
  let d = t.querySelector("defs");
54
- d || (d = document.createElementNS("http://www.w3.org/2000/svg", "defs"), t.insertBefore(d, t.firstChild)), d.appendChild(i), n.setAttribute("clip-path", `url(#${u})`), e.style.transition = `width ${r}ms ease-out`, e.getBoundingClientRect(), e.setAttribute("width", s.toString()), e.addEventListener("transitionend", function C() {
55
- n.removeAttribute("clip-path"), i.parentNode && i.parentNode.removeChild(i), e.removeEventListener("transitionend", C);
54
+ d || (d = document.createElementNS("http://www.w3.org/2000/svg", "defs"), t.insertBefore(d, t.firstChild)), d.appendChild(i), n.setAttribute("clip-path", `url(#${u})`), e.style.transition = `width ${o}ms ease-out`, e.getBoundingClientRect(), e.setAttribute("width", s.toString()), e.addEventListener("transitionend", function g() {
55
+ n.removeAttribute("clip-path"), i.parentNode && i.parentNode.removeChild(i), e.removeEventListener("transitionend", g);
56
56
  });
57
57
  }
58
- function q() {
58
+ function j() {
59
59
  return document.querySelectorAll(".tiny-spark");
60
60
  }
61
- function H(t, n) {
61
+ function B(t, n) {
62
62
  return Object.keys(t.dataset).includes(n);
63
63
  }
64
- function y(t, n, r) {
65
- return H(t, n) ? t.dataset[n] : r;
64
+ function y(t, n, o) {
65
+ return B(t, n) ? t.dataset[n] : o;
66
66
  }
67
- function J(t, n) {
68
- const r = new MutationObserver((o) => {
69
- for (const s of o)
70
- if (s.type === "attributes" && s.attributeName && Object.values(B).includes(s.attributeName)) {
67
+ function q(t, n) {
68
+ const o = new MutationObserver((r) => {
69
+ for (const s of r)
70
+ if (s.type === "attributes" && s.attributeName && Object.values(V).includes(s.attributeName)) {
71
71
  n();
72
72
  break;
73
73
  }
74
74
  });
75
- return r.observe(t, { attributes: !0 }), r;
75
+ return o.observe(t, { attributes: !0 }), o;
76
76
  }
77
- function K(t) {
77
+ function J(t) {
78
78
  if (!t) return {
79
79
  color: "#1A1A1A",
80
80
  backgroundColor: "#FFFFFF"
81
81
  };
82
- const n = window.getComputedStyle(t), r = n.getPropertyValue("color") || "#1A1A1A", o = n.getPropertyValue("background-color"), s = n.getPropertyValue("background");
83
- return { color: r, backgroundColor: o || s || "#FFFFFF" };
82
+ const n = window.getComputedStyle(t), o = n.getPropertyValue("color") || "#1A1A1A", r = n.getPropertyValue("background-color"), s = n.getPropertyValue("background");
83
+ return { color: o, backgroundColor: r || s || "#FFFFFF" };
84
84
  }
85
- function X() {
85
+ function K() {
86
86
  return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(t) {
87
87
  const n = Math.random() * 16 | 0;
88
88
  return (t == "x" ? n : n & 3 | 8).toString(16);
89
89
  });
90
90
  }
91
- function Y(t) {
91
+ function X(t) {
92
92
  const n = t.getAttribute("data-set");
93
93
  if (!n) return [];
94
94
  try {
95
- const r = JSON.parse(n);
96
- return Array.isArray(r) && r.every((o) => typeof o == "number" || [null, void 0].includes(o)) ? r : (console.warn("data-set is not an array of numbers."), []);
97
- } catch (r) {
98
- return console.error("Error parsing data-set:", r), [];
95
+ const o = JSON.parse(n);
96
+ return Array.isArray(o) && o.every((r) => typeof r == "number" || [null, void 0].includes(r)) ? o : (console.warn("data-set is not an array of numbers."), []);
97
+ } catch (o) {
98
+ return console.error("Error parsing data-set:", o), [];
99
99
  }
100
100
  }
101
- function z(t) {
101
+ function Y(t) {
102
102
  const n = t.getAttribute("data-dates");
103
103
  if (!n) return [];
104
104
  try {
105
- const r = JSON.parse(n);
106
- return Array.isArray(r) && r.every((o) => typeof o == "string") ? r : (console.warn("data-dates is not an array of strings"), []);
107
- } catch (r) {
108
- return console.error("Error parsing data-dates", r), [];
105
+ const o = JSON.parse(n);
106
+ return Array.isArray(o) && o.every((r) => typeof r == "string") ? o : (console.warn("data-dates is not an array of strings"), []);
107
+ } catch (o) {
108
+ return console.error("Error parsing data-dates", o), [];
109
109
  }
110
110
  }
111
- function D(t) {
111
+ function F(t) {
112
112
  return {
113
113
  min: Math.min(...t),
114
114
  max: Math.max(...t)
115
115
  };
116
116
  }
117
- function G() {
117
+ function H() {
118
118
  return new Promise((t) => setTimeout(t, 0));
119
119
  }
120
- function Z(t, n) {
121
- const r = String(y(t, h.NUMBER_LOCALE, navigator.language || "en-US")), o = Number(String(y(t, h.NUMBER_ROUNDING, 0)));
122
- return n.toLocaleString(r, {
120
+ function z(t, n) {
121
+ const o = String(y(t, h.NUMBER_LOCALE, navigator.language || "en-US")), r = Number(String(y(t, h.NUMBER_ROUNDING, 0)));
122
+ return n.toLocaleString(o, {
123
123
  useGrouping: !0,
124
- minimumFractionDigits: o,
125
- maximumFractionDigits: o
124
+ minimumFractionDigits: r,
125
+ maximumFractionDigits: r
126
126
  });
127
127
  }
128
- function Q(t, n, r) {
128
+ function Z(t, n, o) {
129
129
  if (!t.createSVGPoint || !t.getScreenCTM)
130
130
  throw new Error("Your browser does not support SVG coordinate transformation.");
131
- const o = t.getScreenCTM();
132
- if (!o)
131
+ const r = t.getScreenCTM();
132
+ if (!r)
133
133
  throw new Error("Cannot obtain the screen CTM.");
134
134
  const s = t.createSVGPoint();
135
- s.x = n, s.y = r;
136
- const i = s.matrixTransform(o);
135
+ s.x = n, s.y = o;
136
+ const i = s.matrixTransform(r);
137
137
  return { x: i.x, y: i.y };
138
138
  }
139
- function V(t, n, r, o, s) {
140
- if (T(o), !s) return;
141
- const { x: i, y: u } = Q(t, r.x, r.y), e = document.createElement("div");
142
- e.style.opacity = "0", e.classList.add("tiny-spark-tooltip"), e.setAttribute("id", `tooltip_${o}`), e.style.pointerEvents = "none", e.style.position = "fixed", e.style.top = u + "px", e.style.left = i + "px", e.style.width = "fit-content", e.innerHTML = `
143
- <div class="tiny-spark-tooltip-content">${r.d ? `${r.d}: ` : ""}${[null, void 0].includes(r.v) ? "-" : Z(n, Number(r.v))}</div>
144
- `, document.body.appendChild(e), G().then(() => {
145
- const { width: d, height: C } = e.getBoundingClientRect();
146
- e.style.left = `${i - d / 2}px`, e.style.top = `${u - C - Number(String(Number(y(n, h.PLOT_RADIUS, 3)) * 1.5))}px`;
139
+ function D(t, n, o, r, s) {
140
+ if (Q(r), !s) return;
141
+ const { x: i, y: u } = Z(t, o.x, o.y), e = document.createElement("div");
142
+ e.style.opacity = "0", e.classList.add("tiny-spark-tooltip"), e.setAttribute("id", `tooltip_${r}`), e.style.pointerEvents = "none", e.style.position = "fixed", e.style.top = u + "px", e.style.left = i + "px", e.style.width = "fit-content", e.innerHTML = `
143
+ <div class="tiny-spark-tooltip-content">${o.d ? `${o.d}: ` : ""}${[null, void 0].includes(o.v) ? "-" : z(n, Number(o.v))}</div>
144
+ `, document.body.appendChild(e), H().then(() => {
145
+ const { width: d, height: g } = e.getBoundingClientRect();
146
+ e.style.left = `${i - d / 2}px`, e.style.top = `${u - g - Number(String(Number(y(n, h.PLOT_RADIUS, 3)) * 1.5))}px`;
147
147
  }).then(() => {
148
148
  e.style.opacity = "1";
149
149
  });
150
150
  }
151
- function T(t) {
151
+ function Q(t) {
152
152
  const n = document.getElementById(`tooltip_${t}`);
153
153
  n == null || n.remove();
154
154
  }
155
- function tt(t) {
155
+ function T(t) {
156
156
  t.innerHTML = "";
157
157
  }
158
- function et(t, n) {
159
- const r = t.dataset.id;
160
- console.log({ uid: r });
158
+ function tt(t, n) {
161
159
  let o = n;
162
- tt(t);
163
- const { svg: s, svgId: i, width: u, height: e } = U(t), { color: d, backgroundColor: C } = K(t), g = { T: 12, R: 12, B: 12, L: 12 }, c = {
160
+ T(t);
161
+ const { svg: r, svgId: s, width: i, height: u } = G(t), { color: e, backgroundColor: d } = J(t), g = { T: 12, R: 12, B: 12, L: 12 }, c = {
164
162
  left: g.L,
165
163
  top: g.T,
166
- width: u - g.L - g.R,
167
- height: e - g.T - g.B,
168
- bottom: e - g.B
169
- }, O = Y(t), { min: $ } = D(O), L = O.map((l) => [null, void 0].includes(l) ? l : l + ($ < 0 ? Math.abs($) : 0)), { max: k } = D(L), N = c.width / (O.length - 1) === 1 / 0 ? c.width : c.width / (O.length - 1), I = z(t), m = L.map((l, b) => {
164
+ width: i - g.L - g.R,
165
+ height: u - g.T - g.B,
166
+ bottom: u - g.B
167
+ }, C = X(t), { min: A } = F(C), O = C.map((l) => [null, void 0].includes(l) ? l : l + (A < 0 ? Math.abs(A) : 0)), { max: E } = F(O), N = c.width / (C.length - 1) === 1 / 0 ? c.width : c.width / (C.length - 1), k = Y(t), m = O.map((l, b) => {
170
168
  const a = {
171
- w: L.length === 1 ? N / 2 : 0,
172
- h: L.length === 1 ? c.height / 2 : 0
169
+ w: O.length === 1 ? N / 2 : 0,
170
+ h: O.length === 1 ? c.height / 2 : 0
173
171
  };
174
172
  return {
175
- y: (1 - (l || 0) / k) * c.height + g.T + a.h,
173
+ y: (1 - (l || 0) / E) * c.height + g.T + a.h,
176
174
  x: c.left + N * b + a.w,
177
175
  v: l,
178
- d: I[b] || null
176
+ d: k[b] || null
179
177
  };
180
- }), v = [...m].filter(({ v: l }) => ![null, void 0].includes(l)), p = document.createElementNS(A, "path");
181
- p.classList.add("tiny-spark-line-path"), !t.dataset.curve || t.dataset.curve === "true" ? p.setAttribute("d", `M ${F(v)}`) : p.setAttribute("d", `M ${P(v)}`), p.setAttribute("fill", "none"), p.setAttribute("stroke", String(y(t, h.LINE_COLOR, d))), p.setAttribute("stroke-width", String(y(t, h.LINE_THICKNESS, 2))), p.setAttribute("stroke-linecap", "round");
182
- const w = document.createElementNS(A, "path");
178
+ }), v = [...m].filter(({ v: l }) => ![null, void 0].includes(l)), p = document.createElementNS(L, "path");
179
+ p.classList.add("tiny-spark-line-path"), !t.dataset.curve || t.dataset.curve === "true" ? p.setAttribute("d", `M ${P(v)}`) : p.setAttribute("d", `M ${M(v)}`), p.setAttribute("fill", "none"), p.setAttribute("stroke", String(y(t, h.LINE_COLOR, e))), p.setAttribute("stroke-width", String(y(t, h.LINE_THICKNESS, 2))), p.setAttribute("stroke-linecap", "round");
180
+ const w = document.createElementNS(L, "path");
183
181
  w.classList.add("tiny-spark-line-area");
184
- const M = t.getAttribute("data-animation");
185
- M === "true" && o && (p.style.opacity = "0", w.style.opacity = "0"), m.length && (!t.dataset.curve || t.dataset.curve === "true" ? w.setAttribute("d", `M ${v[0].x},${c.bottom} ${F(v)} L ${v.at(-1).x},${c.bottom} Z`) : w.setAttribute("d", `M ${v[0].x},${c.bottom} ${P(v)} L ${v.at(-1).x},${c.bottom} Z`)), w.setAttribute("fill", String(y(t, h.AREA_COLOR, "transparent"))), m.length > 1 && (s.appendChild(w), s.appendChild(p));
186
- const R = [];
182
+ const _ = t.getAttribute("data-animation");
183
+ _ === "true" && o && (p.style.opacity = "0", w.style.opacity = "0"), m.length && (!t.dataset.curve || t.dataset.curve === "true" ? w.setAttribute("d", `M ${v[0].x},${c.bottom} ${P(v)} L ${v.at(-1).x},${c.bottom} Z`) : w.setAttribute("d", `M ${v[0].x},${c.bottom} ${M(v)} L ${v.at(-1).x},${c.bottom} Z`)), w.setAttribute("fill", String(y(t, h.AREA_COLOR, "transparent"))), m.length > 1 && (r.appendChild(w), r.appendChild(p));
184
+ const I = [];
187
185
  m.forEach((l, b) => {
188
- const a = document.createElementNS(A, "line");
189
- a.classList.add("tiny-spark-indicator"), a.setAttribute("id", `indicator_${i}_${b}`), a.setAttribute("x1", String(c.left + (m.length === 1 ? c.width / 2 : b * N))), a.setAttribute("x2", String(c.left + (m.length === 1 ? c.width / 2 : b * N))), a.setAttribute("y1", String(c.top)), a.setAttribute("y2", String(c.bottom)), a.setAttribute("stroke", String(y(t, h.INDICATOR_COLOR, "#1A1A1A"))), a.setAttribute("stroke-width", String(y(t, h.INDICATOR_WIDTH, "1"))), a.setAttribute("stroke-linecap", "round"), a.style.pointerEvents = "none", a.style.opacity = "0", R.push(a), s.appendChild(a);
186
+ const a = document.createElementNS(L, "line");
187
+ a.classList.add("tiny-spark-indicator"), a.setAttribute("id", `indicator_${s}_${b}`), a.setAttribute("x1", String(c.left + (m.length === 1 ? c.width / 2 : b * N))), a.setAttribute("x2", String(c.left + (m.length === 1 ? c.width / 2 : b * N))), a.setAttribute("y1", String(c.top)), a.setAttribute("y2", String(c.bottom)), a.setAttribute("stroke", String(y(t, h.INDICATOR_COLOR, "#1A1A1A"))), a.setAttribute("stroke-width", String(y(t, h.INDICATOR_WIDTH, "1"))), a.setAttribute("stroke-linecap", "round"), a.style.pointerEvents = "none", a.style.opacity = "0", I.push(a), r.appendChild(a);
190
188
  });
191
- let _ = [];
189
+ let R = [];
192
190
  Number(String(y(t, h.PLOT_RADIUS, 0))) > 0 && m.forEach(({ x: l, y: b, v: a }, x) => {
193
191
  if (![null, void 0].includes(a)) {
194
- const f = document.createElementNS(A, "circle");
195
- f.classList.add("tiny-spark-datapoint-circle"), f.classList.add(`circle-${i}`), f.setAttribute("id", `circle_${i}_${x}`), f.setAttribute("cx", String(l || 0)), f.setAttribute("cy", String(b || 0)), f.setAttribute("r", String(y(t, h.PLOT_RADIUS, 3))), f.setAttribute("fill", String(y(t, h.PLOT_COLOR, String(y(t, "lineColor", d))))), f.setAttribute("stroke", C), f.style.opacity = "0", f.style.transition = `opacity ${x * (1e3 * 2 / m.length)}ms ease-in`, s.appendChild(f), _.push(f);
192
+ const f = document.createElementNS(L, "circle");
193
+ f.classList.add("tiny-spark-datapoint-circle"), f.classList.add(`circle-${s}`), f.setAttribute("id", `circle_${s}_${x}`), f.setAttribute("cx", String(l || 0)), f.setAttribute("cy", String(b || 0)), f.setAttribute("r", String(y(t, h.PLOT_RADIUS, 3))), f.setAttribute("fill", String(y(t, h.PLOT_COLOR, String(y(t, "lineColor", e))))), f.setAttribute("stroke", d), f.style.opacity = "0", f.style.transition = `opacity ${x * (1e3 * 2 / m.length)}ms ease-in`, r.appendChild(f), R.push(f);
196
194
  }
197
195
  }), m.forEach((l, b) => {
198
- const a = document.createElementNS(A, "rect");
196
+ const a = document.createElementNS(L, "rect");
199
197
  a.classList.add("tiny-spark-tooltip-trap"), a.setAttribute("x", `${m.length === 1 ? 0 : c.left + b * N - N / 2}`), a.setAttribute("y", `${c.top}`), a.setAttribute("height", `${c.height}`), a.setAttribute("width", `${N}`), a.setAttribute("fill", "transparent"), a.addEventListener("mouseenter", () => {
200
- V(s, t, l, i, !0);
201
- const x = document.getElementById(`circle_${i}_${b}`);
202
- x == null || x.setAttribute("r", String(Number(y(t, h.PLOT_RADIUS, 3)) * 1.5)), R[b].style.opacity = "1";
198
+ D(r, t, l, s, !0);
199
+ const x = document.getElementById(`circle_${s}_${b}`);
200
+ x == null || x.setAttribute("r", String(Number(y(t, h.PLOT_RADIUS, 3)) * 1.5)), I[b].style.opacity = "1";
203
201
  }), a.addEventListener("mouseout", () => {
204
- V(s, t, l, i, !1);
205
- const x = document.getElementById(`circle_${i}_${b}`);
206
- x == null || x.setAttribute("r", String(Number(y(t, h.PLOT_RADIUS, 3)))), R.forEach((f) => f.style.opacity = "0");
207
- }), s.appendChild(a);
208
- }), M === "true" && o ? G().then(() => {
209
- _.forEach((l) => {
202
+ D(r, t, l, s, !1);
203
+ const x = document.getElementById(`circle_${s}_${b}`);
204
+ x == null || x.setAttribute("r", String(Number(y(t, h.PLOT_RADIUS, 3)))), I.forEach((f) => f.style.opacity = "0");
205
+ }), r.appendChild(a);
206
+ }), _ === "true" && o ? H().then(() => {
207
+ R.forEach((l) => {
210
208
  l.style.opacity = "1";
211
- }), W(p), j(s, w);
212
- }) : _.forEach((l) => {
209
+ }), U(p), W(r, w);
210
+ }) : R.forEach((l) => {
213
211
  l.style.opacity = "1";
214
- }), t.appendChild(s);
212
+ }), t.appendChild(r);
215
213
  }
216
- function rt() {
217
- const t = q();
214
+ function nt() {
215
+ const t = j();
218
216
  t.length && Array.from(t).forEach((n) => {
219
- const r = X();
220
- n.setAttribute("data-id", r);
221
- const o = n;
222
- nt(o), o.__renderCount = 0, E(o), J(o, () => E(o));
217
+ const o = K();
218
+ n.setAttribute("data-id", o);
219
+ const r = n;
220
+ et(r), r.__renderCount = 0, $(r), q(r, () => $(r));
223
221
  const s = new ResizeObserver((u) => {
224
- u.forEach(() => E(o));
222
+ u.forEach(() => $(r));
225
223
  });
226
- o.parentElement && s.observe(o.parentElement), new MutationObserver((u) => {
224
+ r.parentElement && s.observe(r.parentElement), new MutationObserver((u) => {
227
225
  u.forEach((e) => {
228
- e.type === "attributes" && e.attributeName && e.attributeName.startsWith("data-") && E(o);
226
+ e.type === "attributes" && e.attributeName && e.attributeName.startsWith("data-") && $(r);
229
227
  });
230
- }).observe(o, { attributes: !0 });
228
+ }).observe(r, { attributes: !0 });
231
229
  });
232
230
  }
233
- function E(t) {
234
- H(t, "set") && et(t, t.__renderCount < 2), t.__renderCount += 1;
231
+ function $(t) {
232
+ B(t, "set") && tt(t, t.__renderCount < 2), t.__renderCount += 1;
235
233
  }
236
- function nt(t) {
234
+ function et(t) {
237
235
  t.dataset.set || console.error(
238
236
  `Tiny-spark exception:
239
237
 
@@ -243,10 +241,10 @@ Provide an array of numbers, for example:
243
241
  data-set="[1, 2, 3]"`
244
242
  );
245
243
  }
246
- function ot(t) {
244
+ function rt(t) {
247
245
  return JSON.stringify(t);
248
246
  }
249
247
  export {
250
- rt as render,
251
- ot as tinyFormat
248
+ nt as render,
249
+ rt as tinyFormat
252
250
  };
@@ -1,8 +1,8 @@
1
- (function(O,p){typeof exports=="object"&&typeof module<"u"?p(exports):typeof define=="function"&&define.amd?define(["exports"],p):(O=typeof globalThis<"u"?globalThis:O||self,p(O.TinySpark={}))})(this,function(O){"use strict";const p="http://www.w3.org/2000/svg";var P=(t=>(t.BAR="data-bar",t.LINE="data-line",t.SET="data-set",t.RESPONSIVE="data-responsive",t))(P||{}),f=(t=>(t.ANIMATION="animation",t.AREA_COLOR="areaColor",t.CURVE="curve",t.DATES="dates",t.INDICATOR_COLOR="indicatorColor",t.INDICATOR_WIDTH="indicatorWidth",t.LINE_COLOR="lineColor",t.LINE_THICKNESS="lineThickness",t.NUMBER_LOCALE="numberLocale",t.NUMBER_ROUNDING="numberRounding",t.NUMBER_SHOW_ON="numberShowOn",t.PLOT_COLOR="plotColor",t.PLOT_RADIUS="plotRadius",t.SET="set",t))(f||{});function j(t){const{width:n,height:r}=t.parentElement.getBoundingClientRect(),o={width:300,height:100},s=`0 0 ${n||o.width} ${r||o.height}`,i=document.createElementNS(p,"svg"),u=t.dataset.id;return i.id=u,i.setAttribute("viewBox",s),i.style.width="100%",i.style.height="100%",{svg:i,svgId:u,width:n||o.width,height:r||o.height}}function m(t,n=0){return isNaN(t)?n:t}function F(t){let n=[];for(let r=0;r<t.length;r+=1)n.push(`${m(t[r].x)},${m(t[r].y)} `);return n.join(" ").trim()}function D(t){if(t.length<1)return"0,0";const n=t.length-1,r=[`${m(t[0].x)},${m(t[0].y)}`],o=[],s=[],i=[],u=[];for(let e=0;e<n;e+=1)o[e]=t[e+1].x-t[e].x,s[e]=t[e+1].y-t[e].y,i[e]=s[e]/o[e];u[0]=i[0],u[n]=i[n-1];for(let e=1;e<n;e+=1)if(i[e-1]*i[e]<=0)u[e]=0;else{const d=2*i[e-1]*i[e]/(i[e-1]+i[e]);u[e]=d}for(let e=0;e<n;e+=1){const d=t[e].x,w=t[e].y,g=t[e+1].x,c=t[e+1].y,A=u[e],k=u[e+1],$=d+(g-d)/3,I=w+A*(g-d)/3,v=g-(g-d)/3,M=c-k*(g-d)/3;r.push(`C ${m($)},${m(I)} ${m(v)},${m(M)} ${m(g)},${m(c)}`)}return r.join(" ")}function W(t,n=1e3){t.style.opacity="1";const r=t.getTotalLength();t.style.strokeDasharray=String(r),t.style.strokeDashoffset=String(r),t.getBoundingClientRect(),t.style.transition=`stroke-dashoffset ${n}ms ease-in-out`,t.style.strokeDashoffset="0",t.addEventListener("transitionend",function o(){t.style.transition="",t.removeEventListener("transitionend",o)})}function q(t,n,r=1e3){n.style.opacity="1";const o=n.getBBox(),s=o.width,i=document.createElementNS("http://www.w3.org/2000/svg","clipPath"),u="clip-"+Math.random().toString(36).substr(2,9);i.setAttribute("id",u);const e=document.createElementNS("http://www.w3.org/2000/svg","rect");e.setAttribute("x",o.x.toString()),e.setAttribute("y",o.y.toString()),e.setAttribute("width","0"),e.setAttribute("height",o.height.toString()),i.appendChild(e);let d=t.querySelector("defs");d||(d=document.createElementNS("http://www.w3.org/2000/svg","defs"),t.insertBefore(d,t.firstChild)),d.appendChild(i),n.setAttribute("clip-path",`url(#${u})`),e.style.transition=`width ${r}ms ease-out`,e.getBoundingClientRect(),e.setAttribute("width",s.toString()),e.addEventListener("transitionend",function w(){n.removeAttribute("clip-path"),i.parentNode&&i.parentNode.removeChild(i),e.removeEventListener("transitionend",w)})}function J(){return document.querySelectorAll(".tiny-spark")}function V(t,n){return Object.keys(t.dataset).includes(n)}function y(t,n,r){return V(t,n)?t.dataset[n]:r}function K(t,n){const r=new MutationObserver(o=>{for(const s of o)if(s.type==="attributes"&&s.attributeName&&Object.values(P).includes(s.attributeName)){n();break}});return r.observe(t,{attributes:!0}),r}function X(t){if(!t)return{color:"#1A1A1A",backgroundColor:"#FFFFFF"};const n=window.getComputedStyle(t),r=n.getPropertyValue("color")||"#1A1A1A",o=n.getPropertyValue("background-color"),s=n.getPropertyValue("background");return{color:r,backgroundColor:o||s||"#FFFFFF"}}function Y(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(t){const n=Math.random()*16|0;return(t=="x"?n:n&3|8).toString(16)})}function z(t){const n=t.getAttribute("data-set");if(!n)return[];try{const r=JSON.parse(n);return Array.isArray(r)&&r.every(o=>typeof o=="number"||[null,void 0].includes(o))?r:(console.warn("data-set is not an array of numbers."),[])}catch(r){return console.error("Error parsing data-set:",r),[]}}function Z(t){const n=t.getAttribute("data-dates");if(!n)return[];try{const r=JSON.parse(n);return Array.isArray(r)&&r.every(o=>typeof o=="string")?r:(console.warn("data-dates is not an array of strings"),[])}catch(r){return console.error("Error parsing data-dates",r),[]}}function B(t){return{min:Math.min(...t),max:Math.max(...t)}}function H(){return new Promise(t=>setTimeout(t,0))}function Q(t,n){const r=String(y(t,f.NUMBER_LOCALE,navigator.language||"en-US")),o=Number(String(y(t,f.NUMBER_ROUNDING,0)));return n.toLocaleString(r,{useGrouping:!0,minimumFractionDigits:o,maximumFractionDigits:o})}function T(t,n,r){if(!t.createSVGPoint||!t.getScreenCTM)throw new Error("Your browser does not support SVG coordinate transformation.");const o=t.getScreenCTM();if(!o)throw new Error("Cannot obtain the screen CTM.");const s=t.createSVGPoint();s.x=n,s.y=r;const i=s.matrixTransform(o);return{x:i.x,y:i.y}}function G(t,n,r,o,s){if(tt(o),!s)return;const{x:i,y:u}=T(t,r.x,r.y),e=document.createElement("div");e.style.opacity="0",e.classList.add("tiny-spark-tooltip"),e.setAttribute("id",`tooltip_${o}`),e.style.pointerEvents="none",e.style.position="fixed",e.style.top=u+"px",e.style.left=i+"px",e.style.width="fit-content",e.innerHTML=`
2
- <div class="tiny-spark-tooltip-content">${r.d?`${r.d}: `:""}${[null,void 0].includes(r.v)?"-":Q(n,Number(r.v))}</div>
3
- `,document.body.appendChild(e),H().then(()=>{const{width:d,height:w}=e.getBoundingClientRect();e.style.left=`${i-d/2}px`,e.style.top=`${u-w-Number(String(Number(y(n,f.PLOT_RADIUS,3))*1.5))}px`}).then(()=>{e.style.opacity="1"})}function tt(t){const n=document.getElementById(`tooltip_${t}`);n==null||n.remove()}function et(t){t.innerHTML=""}function nt(t,n){const r=t.dataset.id;console.log({uid:r});let o=n;et(t);const{svg:s,svgId:i,width:u,height:e}=j(t),{color:d,backgroundColor:w}=X(t),g={T:12,R:12,B:12,L:12},c={left:g.L,top:g.T,width:u-g.L-g.R,height:e-g.T-g.B,bottom:e-g.B},A=z(t),{min:k}=B(A),$=A.map(l=>[null,void 0].includes(l)?l:l+(k<0?Math.abs(k):0)),{max:I}=B($),v=c.width/(A.length-1)===1/0?c.width:c.width/(A.length-1),M=Z(t),S=$.map((l,b)=>{const a={w:$.length===1?v/2:0,h:$.length===1?c.height/2:0};return{y:(1-(l||0)/I)*c.height+g.T+a.h,x:c.left+v*b+a.w,v:l,d:M[b]||null}}),C=[...S].filter(({v:l})=>![null,void 0].includes(l)),x=document.createElementNS(p,"path");x.classList.add("tiny-spark-line-path"),!t.dataset.curve||t.dataset.curve==="true"?x.setAttribute("d",`M ${D(C)}`):x.setAttribute("d",`M ${F(C)}`),x.setAttribute("fill","none"),x.setAttribute("stroke",String(y(t,f.LINE_COLOR,d))),x.setAttribute("stroke-width",String(y(t,f.LINE_THICKNESS,2))),x.setAttribute("stroke-linecap","round");const L=document.createElementNS(p,"path");L.classList.add("tiny-spark-line-area");const U=t.getAttribute("data-animation");U==="true"&&o&&(x.style.opacity="0",L.style.opacity="0"),S.length&&(!t.dataset.curve||t.dataset.curve==="true"?L.setAttribute("d",`M ${C[0].x},${c.bottom} ${D(C)} L ${C.at(-1).x},${c.bottom} Z`):L.setAttribute("d",`M ${C[0].x},${c.bottom} ${F(C)} L ${C.at(-1).x},${c.bottom} Z`)),L.setAttribute("fill",String(y(t,f.AREA_COLOR,"transparent"))),S.length>1&&(s.appendChild(L),s.appendChild(x));const R=[];S.forEach((l,b)=>{const a=document.createElementNS(p,"line");a.classList.add("tiny-spark-indicator"),a.setAttribute("id",`indicator_${i}_${b}`),a.setAttribute("x1",String(c.left+(S.length===1?c.width/2:b*v))),a.setAttribute("x2",String(c.left+(S.length===1?c.width/2:b*v))),a.setAttribute("y1",String(c.top)),a.setAttribute("y2",String(c.bottom)),a.setAttribute("stroke",String(y(t,f.INDICATOR_COLOR,"#1A1A1A"))),a.setAttribute("stroke-width",String(y(t,f.INDICATOR_WIDTH,"1"))),a.setAttribute("stroke-linecap","round"),a.style.pointerEvents="none",a.style.opacity="0",R.push(a),s.appendChild(a)});let _=[];Number(String(y(t,f.PLOT_RADIUS,0)))>0&&S.forEach(({x:l,y:b,v:a},N)=>{if(![null,void 0].includes(a)){const h=document.createElementNS(p,"circle");h.classList.add("tiny-spark-datapoint-circle"),h.classList.add(`circle-${i}`),h.setAttribute("id",`circle_${i}_${N}`),h.setAttribute("cx",String(l||0)),h.setAttribute("cy",String(b||0)),h.setAttribute("r",String(y(t,f.PLOT_RADIUS,3))),h.setAttribute("fill",String(y(t,f.PLOT_COLOR,String(y(t,"lineColor",d))))),h.setAttribute("stroke",w),h.style.opacity="0",h.style.transition=`opacity ${N*(1e3*2/S.length)}ms ease-in`,s.appendChild(h),_.push(h)}}),S.forEach((l,b)=>{const a=document.createElementNS(p,"rect");a.classList.add("tiny-spark-tooltip-trap"),a.setAttribute("x",`${S.length===1?0:c.left+b*v-v/2}`),a.setAttribute("y",`${c.top}`),a.setAttribute("height",`${c.height}`),a.setAttribute("width",`${v}`),a.setAttribute("fill","transparent"),a.addEventListener("mouseenter",()=>{G(s,t,l,i,!0);const N=document.getElementById(`circle_${i}_${b}`);N==null||N.setAttribute("r",String(Number(y(t,f.PLOT_RADIUS,3))*1.5)),R[b].style.opacity="1"}),a.addEventListener("mouseout",()=>{G(s,t,l,i,!1);const N=document.getElementById(`circle_${i}_${b}`);N==null||N.setAttribute("r",String(Number(y(t,f.PLOT_RADIUS,3)))),R.forEach(h=>h.style.opacity="0")}),s.appendChild(a)}),U==="true"&&o?H().then(()=>{_.forEach(l=>{l.style.opacity="1"}),W(x),q(s,L)}):_.forEach(l=>{l.style.opacity="1"}),t.appendChild(s)}function rt(){const t=J();t.length&&Array.from(t).forEach(n=>{const r=Y();n.setAttribute("data-id",r);const o=n;ot(o),o.__renderCount=0,E(o),K(o,()=>E(o));const s=new ResizeObserver(u=>{u.forEach(()=>E(o))});o.parentElement&&s.observe(o.parentElement),new MutationObserver(u=>{u.forEach(e=>{e.type==="attributes"&&e.attributeName&&e.attributeName.startsWith("data-")&&E(o)})}).observe(o,{attributes:!0})})}function E(t){V(t,"set")&&nt(t,t.__renderCount<2),t.__renderCount+=1}function ot(t){t.dataset.set||console.error(`Tiny-spark exception:
1
+ (function(O,m){typeof exports=="object"&&typeof module<"u"?m(exports):typeof define=="function"&&define.amd?define(["exports"],m):(O=typeof globalThis<"u"?globalThis:O||self,m(O.TinySpark={}))})(this,function(O){"use strict";const m="http://www.w3.org/2000/svg";var _=(t=>(t.BAR="data-bar",t.LINE="data-line",t.SET="data-set",t.RESPONSIVE="data-responsive",t))(_||{}),g=(t=>(t.ANIMATION="animation",t.AREA_COLOR="areaColor",t.CURVE="curve",t.DATES="dates",t.INDICATOR_COLOR="indicatorColor",t.INDICATOR_WIDTH="indicatorWidth",t.LINE_COLOR="lineColor",t.LINE_THICKNESS="lineThickness",t.NUMBER_LOCALE="numberLocale",t.NUMBER_ROUNDING="numberRounding",t.NUMBER_SHOW_ON="numberShowOn",t.PLOT_COLOR="plotColor",t.PLOT_RADIUS="plotRadius",t.SET="set",t))(g||{});function U(t){const{width:n,height:o}=t.parentElement.getBoundingClientRect(),r={width:300,height:100},s=`0 0 ${n||r.width} ${o||r.height}`,i=document.createElementNS(m,"svg"),u=t.dataset.id;return i.id=u,i.setAttribute("viewBox",s),i.style.width="100%",i.style.height="100%",{svg:i,svgId:u,width:n||r.width,height:o||r.height}}function S(t,n=0){return isNaN(t)?n:t}function P(t){let n=[];for(let o=0;o<t.length;o+=1)n.push(`${S(t[o].x)},${S(t[o].y)} `);return n.join(" ").trim()}function F(t){if(t.length<1)return"0,0";const n=t.length-1,o=[`${S(t[0].x)},${S(t[0].y)}`],r=[],s=[],i=[],u=[];for(let e=0;e<n;e+=1)r[e]=t[e+1].x-t[e].x,s[e]=t[e+1].y-t[e].y,i[e]=s[e]/r[e];u[0]=i[0],u[n]=i[n-1];for(let e=1;e<n;e+=1)if(i[e-1]*i[e]<=0)u[e]=0;else{const d=2*i[e-1]*i[e]/(i[e-1]+i[e]);u[e]=d}for(let e=0;e<n;e+=1){const d=t[e].x,y=t[e].y,c=t[e+1].x,w=t[e+1].y,E=u[e],A=u[e+1],k=d+(c-d)/3,v=y+E*(c-d)/3,I=c-(c-d)/3,p=w-A*(c-d)/3;o.push(`C ${S(k)},${S(v)} ${S(I)},${S(p)} ${S(c)},${S(w)}`)}return o.join(" ")}function j(t,n=1e3){t.style.opacity="1";const o=t.getTotalLength();t.style.strokeDasharray=String(o),t.style.strokeDashoffset=String(o),t.getBoundingClientRect(),t.style.transition=`stroke-dashoffset ${n}ms ease-in-out`,t.style.strokeDashoffset="0",t.addEventListener("transitionend",function r(){t.style.transition="",t.removeEventListener("transitionend",r)})}function W(t,n,o=1e3){n.style.opacity="1";const r=n.getBBox(),s=r.width,i=document.createElementNS("http://www.w3.org/2000/svg","clipPath"),u="clip-"+Math.random().toString(36).substr(2,9);i.setAttribute("id",u);const e=document.createElementNS("http://www.w3.org/2000/svg","rect");e.setAttribute("x",r.x.toString()),e.setAttribute("y",r.y.toString()),e.setAttribute("width","0"),e.setAttribute("height",r.height.toString()),i.appendChild(e);let d=t.querySelector("defs");d||(d=document.createElementNS("http://www.w3.org/2000/svg","defs"),t.insertBefore(d,t.firstChild)),d.appendChild(i),n.setAttribute("clip-path",`url(#${u})`),e.style.transition=`width ${o}ms ease-out`,e.getBoundingClientRect(),e.setAttribute("width",s.toString()),e.addEventListener("transitionend",function y(){n.removeAttribute("clip-path"),i.parentNode&&i.parentNode.removeChild(i),e.removeEventListener("transitionend",y)})}function q(){return document.querySelectorAll(".tiny-spark")}function D(t,n){return Object.keys(t.dataset).includes(n)}function f(t,n,o){return D(t,n)?t.dataset[n]:o}function J(t,n){const o=new MutationObserver(r=>{for(const s of r)if(s.type==="attributes"&&s.attributeName&&Object.values(_).includes(s.attributeName)){n();break}});return o.observe(t,{attributes:!0}),o}function K(t){if(!t)return{color:"#1A1A1A",backgroundColor:"#FFFFFF"};const n=window.getComputedStyle(t),o=n.getPropertyValue("color")||"#1A1A1A",r=n.getPropertyValue("background-color"),s=n.getPropertyValue("background");return{color:o,backgroundColor:r||s||"#FFFFFF"}}function X(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(t){const n=Math.random()*16|0;return(t=="x"?n:n&3|8).toString(16)})}function Y(t){const n=t.getAttribute("data-set");if(!n)return[];try{const o=JSON.parse(n);return Array.isArray(o)&&o.every(r=>typeof r=="number"||[null,void 0].includes(r))?o:(console.warn("data-set is not an array of numbers."),[])}catch(o){return console.error("Error parsing data-set:",o),[]}}function z(t){const n=t.getAttribute("data-dates");if(!n)return[];try{const o=JSON.parse(n);return Array.isArray(o)&&o.every(r=>typeof r=="string")?o:(console.warn("data-dates is not an array of strings"),[])}catch(o){return console.error("Error parsing data-dates",o),[]}}function V(t){return{min:Math.min(...t),max:Math.max(...t)}}function B(){return new Promise(t=>setTimeout(t,0))}function Z(t,n){const o=String(f(t,g.NUMBER_LOCALE,navigator.language||"en-US")),r=Number(String(f(t,g.NUMBER_ROUNDING,0)));return n.toLocaleString(o,{useGrouping:!0,minimumFractionDigits:r,maximumFractionDigits:r})}function Q(t,n,o){if(!t.createSVGPoint||!t.getScreenCTM)throw new Error("Your browser does not support SVG coordinate transformation.");const r=t.getScreenCTM();if(!r)throw new Error("Cannot obtain the screen CTM.");const s=t.createSVGPoint();s.x=n,s.y=o;const i=s.matrixTransform(r);return{x:i.x,y:i.y}}function H(t,n,o,r,s){if(T(r),!s)return;const{x:i,y:u}=Q(t,o.x,o.y),e=document.createElement("div");e.style.opacity="0",e.classList.add("tiny-spark-tooltip"),e.setAttribute("id",`tooltip_${r}`),e.style.pointerEvents="none",e.style.position="fixed",e.style.top=u+"px",e.style.left=i+"px",e.style.width="fit-content",e.innerHTML=`
2
+ <div class="tiny-spark-tooltip-content">${o.d?`${o.d}: `:""}${[null,void 0].includes(o.v)?"-":Z(n,Number(o.v))}</div>
3
+ `,document.body.appendChild(e),B().then(()=>{const{width:d,height:y}=e.getBoundingClientRect();e.style.left=`${i-d/2}px`,e.style.top=`${u-y-Number(String(Number(f(n,g.PLOT_RADIUS,3))*1.5))}px`}).then(()=>{e.style.opacity="1"})}function T(t){const n=document.getElementById(`tooltip_${t}`);n==null||n.remove()}function tt(t){t.innerHTML=""}function et(t,n){let o=n;tt(t);const{svg:r,svgId:s,width:i,height:u}=U(t),{color:e,backgroundColor:d}=K(t),y={T:12,R:12,B:12,L:12},c={left:y.L,top:y.T,width:i-y.L-y.R,height:u-y.T-y.B,bottom:u-y.B},w=Y(t),{min:E}=V(w),A=w.map(l=>[null,void 0].includes(l)?l:l+(E<0?Math.abs(E):0)),{max:k}=V(A),v=c.width/(w.length-1)===1/0?c.width:c.width/(w.length-1),I=z(t),p=A.map((l,b)=>{const a={w:A.length===1?v/2:0,h:A.length===1?c.height/2:0};return{y:(1-(l||0)/k)*c.height+y.T+a.h,x:c.left+v*b+a.w,v:l,d:I[b]||null}}),C=[...p].filter(({v:l})=>![null,void 0].includes(l)),x=document.createElementNS(m,"path");x.classList.add("tiny-spark-line-path"),!t.dataset.curve||t.dataset.curve==="true"?x.setAttribute("d",`M ${F(C)}`):x.setAttribute("d",`M ${P(C)}`),x.setAttribute("fill","none"),x.setAttribute("stroke",String(f(t,g.LINE_COLOR,e))),x.setAttribute("stroke-width",String(f(t,g.LINE_THICKNESS,2))),x.setAttribute("stroke-linecap","round");const L=document.createElementNS(m,"path");L.classList.add("tiny-spark-line-area");const G=t.getAttribute("data-animation");G==="true"&&o&&(x.style.opacity="0",L.style.opacity="0"),p.length&&(!t.dataset.curve||t.dataset.curve==="true"?L.setAttribute("d",`M ${C[0].x},${c.bottom} ${F(C)} L ${C.at(-1).x},${c.bottom} Z`):L.setAttribute("d",`M ${C[0].x},${c.bottom} ${P(C)} L ${C.at(-1).x},${c.bottom} Z`)),L.setAttribute("fill",String(f(t,g.AREA_COLOR,"transparent"))),p.length>1&&(r.appendChild(L),r.appendChild(x));const M=[];p.forEach((l,b)=>{const a=document.createElementNS(m,"line");a.classList.add("tiny-spark-indicator"),a.setAttribute("id",`indicator_${s}_${b}`),a.setAttribute("x1",String(c.left+(p.length===1?c.width/2:b*v))),a.setAttribute("x2",String(c.left+(p.length===1?c.width/2:b*v))),a.setAttribute("y1",String(c.top)),a.setAttribute("y2",String(c.bottom)),a.setAttribute("stroke",String(f(t,g.INDICATOR_COLOR,"#1A1A1A"))),a.setAttribute("stroke-width",String(f(t,g.INDICATOR_WIDTH,"1"))),a.setAttribute("stroke-linecap","round"),a.style.pointerEvents="none",a.style.opacity="0",M.push(a),r.appendChild(a)});let R=[];Number(String(f(t,g.PLOT_RADIUS,0)))>0&&p.forEach(({x:l,y:b,v:a},N)=>{if(![null,void 0].includes(a)){const h=document.createElementNS(m,"circle");h.classList.add("tiny-spark-datapoint-circle"),h.classList.add(`circle-${s}`),h.setAttribute("id",`circle_${s}_${N}`),h.setAttribute("cx",String(l||0)),h.setAttribute("cy",String(b||0)),h.setAttribute("r",String(f(t,g.PLOT_RADIUS,3))),h.setAttribute("fill",String(f(t,g.PLOT_COLOR,String(f(t,"lineColor",e))))),h.setAttribute("stroke",d),h.style.opacity="0",h.style.transition=`opacity ${N*(1e3*2/p.length)}ms ease-in`,r.appendChild(h),R.push(h)}}),p.forEach((l,b)=>{const a=document.createElementNS(m,"rect");a.classList.add("tiny-spark-tooltip-trap"),a.setAttribute("x",`${p.length===1?0:c.left+b*v-v/2}`),a.setAttribute("y",`${c.top}`),a.setAttribute("height",`${c.height}`),a.setAttribute("width",`${v}`),a.setAttribute("fill","transparent"),a.addEventListener("mouseenter",()=>{H(r,t,l,s,!0);const N=document.getElementById(`circle_${s}_${b}`);N==null||N.setAttribute("r",String(Number(f(t,g.PLOT_RADIUS,3))*1.5)),M[b].style.opacity="1"}),a.addEventListener("mouseout",()=>{H(r,t,l,s,!1);const N=document.getElementById(`circle_${s}_${b}`);N==null||N.setAttribute("r",String(Number(f(t,g.PLOT_RADIUS,3)))),M.forEach(h=>h.style.opacity="0")}),r.appendChild(a)}),G==="true"&&o?B().then(()=>{R.forEach(l=>{l.style.opacity="1"}),j(x),W(r,L)}):R.forEach(l=>{l.style.opacity="1"}),t.appendChild(r)}function nt(){const t=q();t.length&&Array.from(t).forEach(n=>{const o=X();n.setAttribute("data-id",o);const r=n;rt(r),r.__renderCount=0,$(r),J(r,()=>$(r));const s=new ResizeObserver(u=>{u.forEach(()=>$(r))});r.parentElement&&s.observe(r.parentElement),new MutationObserver(u=>{u.forEach(e=>{e.type==="attributes"&&e.attributeName&&e.attributeName.startsWith("data-")&&$(r)})}).observe(r,{attributes:!0})})}function $(t){D(t,"set")&&et(t,t.__renderCount<2),t.__renderCount+=1}function rt(t){t.dataset.set||console.error(`Tiny-spark exception:
4
4
 
5
5
  [data-set] data attribute is missing.
6
6
  Provide an array of numbers, for example:
7
7
 
8
- data-set="[1, 2, 3]"`)}function it(t){return JSON.stringify(t)}O.render=rt,O.tinyFormat=it,Object.defineProperty(O,Symbol.toStringTag,{value:"Module"})});
8
+ data-set="[1, 2, 3]"`)}function ot(t){return JSON.stringify(t)}O.render=nt,O.tinyFormat=ot,Object.defineProperty(O,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "tiny-spark",
3
3
  "private": false,
4
- "version": "0.2.7",
4
+ "version": "0.2.8-beta.1",
5
5
  "type": "module",
6
6
  "description": "An elegant, reactive and responsive sparkline chart solution without dependency.",
7
7
  "author": "Alec Lloyd Probert",
@@ -21,14 +21,28 @@
21
21
  "homepage": "https://tiny-spark.graphieros.com/",
22
22
  "scripts": {
23
23
  "dev": "vite",
24
- "build": "tsc && vite build"
24
+ "build": "tsc && vite build --config vite.config.core.js && vite build --config vite.config.react.js"
25
+ },
26
+ "exports": {
27
+ ".": {
28
+ "import": "./dist/tiny-spark.es.js",
29
+ "require": "./dist/tiny-spark.umd.js"
30
+ },
31
+ "./react": {
32
+ "import": "./dist/react/TinySparkChart.js",
33
+ "default": "./dist/react/TinySparkChart.js"
34
+ }
25
35
  },
26
36
  "files": [
27
37
  "dist"
28
38
  ],
29
39
  "devDependencies": {
30
40
  "@types/node": "^22.13.13",
41
+ "@types/react": "^19.0.12",
31
42
  "typescript": "~5.7.2",
32
43
  "vite": "^6.2.3"
44
+ },
45
+ "peerDependencies": {
46
+ "react": ">=16.8.0"
33
47
  }
34
48
  }