tiny-spark 0.2.8-beta.2 → 0.2.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -17
- package/dist/react/TinySparkChart.js +0 -533
package/package.json
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tiny-spark",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.2.
|
|
4
|
+
"version": "0.2.9",
|
|
5
|
+
"type": "module",
|
|
5
6
|
"description": "An elegant, reactive and responsive sparkline chart solution without dependency.",
|
|
6
7
|
"author": "Alec Lloyd Probert",
|
|
7
8
|
"main": "dist/tiny-spark.umd.js",
|
|
@@ -20,29 +21,14 @@
|
|
|
20
21
|
"homepage": "https://tiny-spark.graphieros.com/",
|
|
21
22
|
"scripts": {
|
|
22
23
|
"dev": "vite",
|
|
23
|
-
"build": "tsc && vite build
|
|
24
|
-
},
|
|
25
|
-
"exports": {
|
|
26
|
-
".": {
|
|
27
|
-
"import": "./dist/tiny-spark.es.js",
|
|
28
|
-
"require": "./dist/tiny-spark.umd.js"
|
|
29
|
-
},
|
|
30
|
-
"./react": {
|
|
31
|
-
"import": "./dist/react/TinySparkChart.js",
|
|
32
|
-
"require": "./dist/react/TinySparkChart.js",
|
|
33
|
-
"default": "./dist/react/TinySparkChart.js"
|
|
34
|
-
}
|
|
24
|
+
"build": "tsc && vite build"
|
|
35
25
|
},
|
|
36
26
|
"files": [
|
|
37
27
|
"dist"
|
|
38
28
|
],
|
|
39
29
|
"devDependencies": {
|
|
40
30
|
"@types/node": "^22.13.13",
|
|
41
|
-
"@types/react": "^19.0.12",
|
|
42
31
|
"typescript": "~5.7.2",
|
|
43
32
|
"vite": "^6.2.3"
|
|
44
|
-
},
|
|
45
|
-
"peerDependencies": {
|
|
46
|
-
"react": ">=16.8.0"
|
|
47
33
|
}
|
|
48
34
|
}
|
|
@@ -1,533 +0,0 @@
|
|
|
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
|
-
};
|