@canplot/react 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/canplot.mjs CHANGED
@@ -1,58 +1,72 @@
1
- var Xe = Object.defineProperty;
2
- var Fe = (e, t, n) => t in e ? Xe(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
3
- var X = (e, t, n) => Fe(e, typeof t != "symbol" ? t + "" : t, n);
4
- import { jsx as A, jsxs as me, Fragment as Ke } from "react/jsx-runtime";
5
- import ne, { version as Oe, createContext as pe, useRef as k, useCallback as Ye, forwardRef as ze, useState as O, useLayoutEffect as B, useMemo as G, useContext as H, useId as Be, useEffect as Ne } from "react";
6
- const W = (e, t, n) => Math.min(Math.max(e, t), n), wt = (e) => e.reduce((t, n) => t + (n ?? 0), 0), bt = (e, t) => {
1
+ var Oe = Object.defineProperty;
2
+ var Ke = (e, t, n) => t in e ? Oe(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
3
+ var K = (e, t, n) => Ke(e, typeof t != "symbol" ? t + "" : t, n);
4
+ import { jsxs as pe, jsx as R, Fragment as Fe } from "react/jsx-runtime";
5
+ import D, { version as Ye, createContext as ye, forwardRef as ze, useRef as A, useState as z, useLayoutEffect as $, useMemo as oe, useCallback as Be, useContext as q, useId as Ne, useEffect as $e } from "react";
6
+ const G = (e, t, n) => Math.min(Math.max(e, t), n), Mt = (e) => e.reduce((t, n) => t + (n ?? 0), 0), Et = (e, t) => {
7
7
  let n = 0;
8
8
  for (let s = 0; s < e.length; s++)
9
9
  Math.abs(e[s] - t) < Math.abs(e[n] - t) && (n = s);
10
10
  return n;
11
- }, $e = (e, t, n, s) => {
12
- const { min: o, max: i, origin: r } = _(e, n), c = s === "canvas" ? e.chartAreaCanvasPX : e.chartAreaCSS, a = (r === "x" ? c.width : c.height) / (i - o);
11
+ }, je = (e, t, n, s) => {
12
+ const { min: o, max: r, origin: c } = X(e, n), i = s === "canvas" ? e.chartAreaCanvasPX : e.chartAreaCSS, a = (c === "x" ? i.width : i.height) / (r - o);
13
13
  return t / a;
14
- }, _ = (e, t) => {
14
+ }, X = (e, t) => {
15
15
  const n = e.scales.find((s) => s.id === t);
16
16
  if (!n)
17
17
  throw new Error(`Scale ${t} not found`);
18
18
  return n;
19
- }, L = (e, t) => {
19
+ }, U = (e, t) => {
20
20
  const n = window.devicePixelRatio || 1;
21
21
  e.lineCap = t?.lineCap ?? "butt", e.lineDashOffset = n * (t?.lineDashOffset ?? 0), e.lineJoin = t?.lineJoin ?? "miter", e.lineWidth = n * (t?.lineWidth ?? 1), e.miterLimit = n * (t?.miterLimit ?? 10), e.strokeStyle = t?.strokeStyle ?? "black", e.fillStyle = t?.fillStyle ?? e.strokeStyle, e.font = t?.font ?? `${10 * n}px sans-serif`, e.textAlign = t?.textAlign ?? "start", e.direction = t?.direction ?? "inherit", e.textBaseline = t?.textBaseline ?? "alphabetic", e.fontKerning = t?.fontKerning ?? "auto";
22
- }, ye = (e, t, n, s) => {
23
- const o = s === "canvas" ? e.chartAreaCanvasPX : e.chartAreaCSS, { min: i, max: r, origin: c } = _(e, n), a = (c === "x" ? o.width : o.height) / (r - i);
22
+ }, ge = (e, t, n, s) => {
23
+ const o = s === "canvas" ? e.chartAreaCanvasPX : e.chartAreaCSS, { min: r, max: c, origin: i } = X(e, n), a = (i === "x" ? o.width : o.height) / (c - r);
24
24
  return t * a;
25
- }, q = (e, t, n, s) => {
26
- const { min: o, origin: i } = _(e, n), r = s === "canvas" ? e.chartAreaCanvasPX : e.chartAreaCSS, c = ye(e, t - o, n, s);
27
- return i === "x" ? W(
28
- r.x + c,
29
- r.x - 10 * r.width,
30
- r.x + 11 * r.width
31
- ) : W(
32
- r.y + r.height - c,
33
- r.y - 10 * r.height,
34
- r.y + 11 * r.height
25
+ }, Z = (e, t, n, s) => {
26
+ const { min: o, origin: r } = X(e, n), c = s === "canvas" ? e.chartAreaCanvasPX : e.chartAreaCSS, i = ge(e, t - o, n, s);
27
+ return r === "x" ? G(
28
+ c.x + i,
29
+ c.x - 10 * c.width,
30
+ c.x + 11 * c.width
31
+ ) : G(
32
+ c.y + c.height - i,
33
+ c.y - 10 * c.height,
34
+ c.y + 11 * c.height
35
35
  );
36
- }, xt = (e, t, n) => {
37
- const { min: s, max: o } = _(e, n);
38
- return W(t, s, o);
39
- }, $ = (e, t, n) => {
40
- const s = n === "canvas" ? e.chartAreaCanvasPX : e.chartAreaCSS;
41
- return W(t, s.x, s.x + s.width);
36
+ }, kt = (e, t, n) => {
37
+ const { min: s, max: o } = X(e, n);
38
+ return G(t, s, o);
42
39
  }, V = (e, t, n) => {
43
40
  const s = n === "canvas" ? e.chartAreaCanvasPX : e.chartAreaCSS;
44
- return W(t, s.y, s.y + s.height);
45
- }, he = (e, t, n) => {
46
- const { min: s, max: o } = _(e, n);
41
+ return G(t, s.x, s.x + s.width);
42
+ }, H = (e, t, n) => {
43
+ const s = n === "canvas" ? e.chartAreaCanvasPX : e.chartAreaCSS;
44
+ return G(t, s.y, s.y + s.height);
45
+ }, fe = (e, t, n) => {
46
+ const { min: s, max: o } = X(e, n);
47
47
  return t >= s && t <= o;
48
- }, U = (e, t, n, s) => {
49
- const { min: o, max: i, origin: r } = _(e, n), c = s === "canvas" ? e.chartAreaCanvasPX : e.chartAreaCSS, a = r === "x" ? (t - c.x) / c.width : (c.height - t + c.y) / c.height;
50
- return o + a * (i - o);
48
+ }, _ = (e, t, n, s) => {
49
+ const { min: o, max: r, origin: c } = X(e, n), i = s === "canvas" ? e.chartAreaCanvasPX : e.chartAreaCSS, a = c === "x" ? (t - i.x) / i.width : (i.height - t + i.y) / i.height;
50
+ return o + a * (r - o);
51
+ }, O = (e, t) => {
52
+ if (e === t) return !0;
53
+ if (e == null || t == null || typeof e != typeof t || typeof e != "object" || Array.isArray(e) !== Array.isArray(t)) return !1;
54
+ if (Array.isArray(e) && Array.isArray(t)) {
55
+ if (e.length !== t.length) return !1;
56
+ for (let o = 0; o < e.length; o++)
57
+ if (!O(e[o], t[o])) return !1;
58
+ return !0;
59
+ }
60
+ const n = Object.keys(e), s = Object.keys(t);
61
+ if (n.length !== s.length) return !1;
62
+ for (const o of n)
63
+ if (!Object.prototype.hasOwnProperty.call(t, o) || !O(e[o], t[o])) return !1;
64
+ return !0;
51
65
  }, Ve = (e) => {
52
66
  const { ctx: t, scales: n } = e;
53
67
  for (const s of n) {
54
68
  if (!s.axis) continue;
55
- t.save(), L(t, {
69
+ t.save(), U(t, {
56
70
  strokeStyle: "black",
57
71
  fillStyle: "black",
58
72
  lineWidth: 1,
@@ -63,77 +77,70 @@ const W = (e, t, n) => Math.min(Math.max(e, t), n), wt = (e) => e.reduce((t, n)
63
77
  if (s.axis.position === "bottom")
64
78
  t.beginPath(), t.moveTo(o.x, o.y), t.lineTo(o.x + o.width, o.y), t.stroke();
65
79
  else if (s.axis.position === "top") {
66
- const i = o.y + o.height;
67
- t.beginPath(), t.moveTo(o.x, i), t.lineTo(o.x + o.width, i), t.stroke();
80
+ const r = o.y + o.height;
81
+ t.beginPath(), t.moveTo(o.x, r), t.lineTo(o.x + o.width, r), t.stroke();
68
82
  }
69
83
  } else if (s.axis.position === "left") {
70
- const i = o.x + o.width;
71
- t.beginPath(), t.moveTo(i, o.y), t.lineTo(i, o.y + o.height), t.stroke();
84
+ const r = o.x + o.width;
85
+ t.beginPath(), t.moveTo(r, o.y), t.lineTo(r, o.y + o.height), t.stroke();
72
86
  } else s.axis.position === "right" && (t.beginPath(), t.moveTo(o.x, o.y), t.lineTo(o.x, o.y + o.height), t.stroke());
73
87
  t.restore();
74
88
  }
75
89
  };
76
- function je(e) {
90
+ function He(e) {
77
91
  return (t) => {
78
- for (const n of e) fe(n, t);
92
+ for (const n of e) me(n, t);
79
93
  };
80
94
  }
81
- function He(e) {
95
+ function We(e) {
82
96
  return (t) => {
83
97
  const n = [];
84
98
  for (const s of e) {
85
- const o = fe(s, t), i = typeof o == "function";
86
- n.push(i ? o : () => fe(s, null));
99
+ const o = me(s, t), r = typeof o == "function";
100
+ n.push(r ? o : () => me(s, null));
87
101
  }
88
102
  return () => {
89
103
  for (const s of n) s();
90
104
  };
91
105
  };
92
106
  }
93
- function fe(e, t) {
107
+ function me(e, t) {
94
108
  if (typeof e == "function")
95
109
  return e(t);
96
110
  e && (e.current = t);
97
111
  }
98
- var We = parseInt(Oe.split(".")[0], 10) >= 19 ? He : je;
99
- const Ee = pe({
112
+ var qe = parseInt(Ye.split(".")[0], 10) >= 19 ? We : He;
113
+ const Ee = ye({
100
114
  listeners: [],
101
115
  subscribe: () => () => {
102
116
  },
103
117
  notifyListeners: () => {
104
118
  }
105
- }), qe = () => {
119
+ }), Ge = () => {
106
120
  const e = [];
107
- return { listeners: e, subscribe: (s, o) => (e.push([o, s]), e.sort((i, r) => i[0] - r[0]), () => {
108
- const i = e.findIndex(([, r]) => r === s);
109
- i !== -1 && e.splice(i, 1);
121
+ return { listeners: e, subscribe: (s, o) => (e.push([o, s]), e.sort((r, c) => r[0] - c[0]), () => {
122
+ const r = e.findIndex(([, c]) => c === s);
123
+ r !== -1 && e.splice(r, 1);
110
124
  }), notifyListeners: () => {
111
125
  for (const [, s] of e)
112
126
  s();
113
127
  } };
114
- }, ve = pe(null), Re = pe(() => {
115
- }), Ge = ({ onRequestUpdate: e, children: t }) => {
116
- const n = k(e);
117
- n.current = e;
118
- const s = Ye(() => {
119
- n.current();
120
- }, [n]);
121
- return /* @__PURE__ */ A(Re.Provider, { value: s, children: t });
122
- }, ke = {
128
+ }, ve = ye(null), ke = ye(() => {
129
+ }), Ae = {
123
130
  TOP: 400,
124
131
  MIDDLE: 300,
125
132
  BOTTOM: 200,
126
133
  BACKGROUND: 100
127
134
  };
128
- class Ae {
135
+ class Re {
129
136
  constructor() {
130
- X(this, "_frame", null);
131
- X(this, "clampXPosToChartArea", (t, n = "canvas") => $(this.frame, t, n));
132
- X(this, "clampYPosToChartArea", (t, n = "canvas") => V(this.frame, t, n));
133
- X(this, "valToPos", (t, n, s = "canvas") => q(this.frame, t, n, s));
134
- X(this, "valToPxDistance", (t, n, s = "canvas") => ye(this.frame, t, n, s));
135
- X(this, "valFits", (t, n) => he(this.frame, t, n));
136
- X(this, "getScale", (t) => _(this.frame, t));
137
+ K(this, "_frame", null);
138
+ K(this, "clampXPosToChartArea", (t, n = "canvas") => V(this.frame, t, n));
139
+ K(this, "clampYPosToChartArea", (t, n = "canvas") => H(this.frame, t, n));
140
+ K(this, "valToPos", (t, n, s = "canvas") => Z(this.frame, t, n, s));
141
+ K(this, "valToPxDistance", (t, n, s = "canvas") => ge(this.frame, t, n, s));
142
+ K(this, "valFits", (t, n) => fe(this.frame, t, n));
143
+ K(this, "getScale", (t) => X(this.frame, t));
137
144
  }
138
145
  _updateFrame(t) {
139
146
  this._frame = t;
@@ -147,16 +154,16 @@ class Ae {
147
154
  return this.frame.ctx;
148
155
  }
149
156
  }
150
- const Tt = ze(({ configuration: e, children: t, style: n, className: s }, o) => {
151
- const i = k(null), r = k(null), c = Je(r), [a, l] = O(() => null);
152
- B(() => {
153
- l(Qe(e, c, i.current));
154
- }, [e, c, i]);
155
- const d = window.devicePixelRatio || 1;
156
- return /* @__PURE__ */ me(
157
+ const At = ze(({ configuration: e, children: t, style: n, className: s }, o) => {
158
+ const r = A(null), c = A(null), i = Je(c), [a, l] = z(() => null);
159
+ $(() => {
160
+ l(Qe(e, i, r.current));
161
+ }, [e, i, r]);
162
+ const m = window.devicePixelRatio || 1;
163
+ return /* @__PURE__ */ pe(
157
164
  "div",
158
165
  {
159
- ref: We([o, r]),
166
+ ref: qe([o, c]),
160
167
  className: s,
161
168
  style: {
162
169
  position: "relative",
@@ -165,21 +172,21 @@ const Tt = ze(({ configuration: e, children: t, style: n, className: s }, o) =>
165
172
  },
166
173
  "data-canplotroot": !0,
167
174
  children: [
168
- /* @__PURE__ */ A(
175
+ /* @__PURE__ */ R(
169
176
  "canvas",
170
177
  {
171
- ref: i,
172
- width: c.width * d,
173
- height: c.height * d,
178
+ ref: r,
179
+ width: i.width * m,
180
+ height: i.height * m,
174
181
  style: {
175
182
  inset: 0,
176
183
  position: "absolute",
177
- width: `${c.width}px`,
178
- height: `${c.height}px`
184
+ width: `${i.width}px`,
185
+ height: `${i.height}px`
179
186
  }
180
187
  }
181
188
  ),
182
- a && /* @__PURE__ */ A(Ze, { frame: a, children: t })
189
+ a && /* @__PURE__ */ R(Ze, { frame: a, children: t })
183
190
  ]
184
191
  }
185
192
  );
@@ -187,48 +194,44 @@ const Tt = ze(({ configuration: e, children: t, style: n, className: s }, o) =>
187
194
  frame: e,
188
195
  children: t
189
196
  }) => {
190
- const n = G(qe, []), [s, o] = O(0);
191
- B(() => {
197
+ const n = oe(Ge, []), [s, o] = z(0);
198
+ $(() => {
192
199
  e?.ctx.clearRect(0, 0, e.ctx.canvas.width, e.ctx.canvas.height);
193
200
  }, [e, s]);
194
- const i = k(null);
195
- return i.current = e, B(() => {
201
+ const r = A(null);
202
+ r.current = e, $(() => {
196
203
  n.subscribe(() => {
197
- i.current && Ve(i.current);
198
- }, ke.BOTTOM);
199
- }, [n]), B(() => {
200
- let r = null;
201
- return r = window.requestAnimationFrame(() => {
202
- r = null, n.notifyListeners();
204
+ r.current && Ve(r.current);
205
+ }, Ae.BOTTOM);
206
+ }, [n]), $(() => {
207
+ let i = null;
208
+ return i = window.requestAnimationFrame(() => {
209
+ i = null, n.notifyListeners();
203
210
  }), () => {
204
- r && cancelAnimationFrame(r);
211
+ i && cancelAnimationFrame(i);
205
212
  };
206
- }, [s, e, n]), /* @__PURE__ */ A(Ee.Provider, { value: n, children: /* @__PURE__ */ A(ve.Provider, { value: e, children: /* @__PURE__ */ A(
207
- Ge,
208
- {
209
- onRequestUpdate: () => {
210
- o((r) => r + 1);
211
- },
212
- children: t
213
- }
214
- ) }) });
213
+ }, [s, e, n]);
214
+ const c = Be(() => {
215
+ o((i) => i + 1);
216
+ }, [o]);
217
+ return /* @__PURE__ */ R(Ee.Provider, { value: n, children: /* @__PURE__ */ R(ke.Provider, { value: c, children: /* @__PURE__ */ R(ve.Provider, { value: e, children: t }) }) });
215
218
  }, Je = (e) => {
216
- const [t, n] = O({
219
+ const [t, n] = z({
217
220
  width: 0,
218
221
  height: 0
219
- }), [s] = O(() => new ResizeObserver((o) => {
220
- for (const i of o) {
221
- const r = Math.round(i.contentRect.width), c = Math.round(i.contentRect.height);
222
+ }), [s] = z(() => new ResizeObserver((o) => {
223
+ for (const r of o) {
224
+ const c = Math.round(r.contentRect.width), i = Math.round(r.contentRect.height);
222
225
  n(
223
- (a) => a.width !== r || a.height !== c ? { ...a, width: r, height: c } : a
226
+ (a) => a.width !== c || a.height !== i ? { ...a, width: c, height: i } : a
224
227
  );
225
228
  }
226
229
  }));
227
- return B(() => {
230
+ return $(() => {
228
231
  if (!e.current) return;
229
- const o = e.current.clientWidth, i = e.current.clientHeight;
232
+ const o = e.current.clientWidth, r = e.current.clientHeight;
230
233
  return n(
231
- (r) => r.width !== o || r.height !== i ? { ...r, width: o, height: i } : r
234
+ (c) => c.width !== o || c.height !== r ? { ...c, width: o, height: r } : c
232
235
  ), s.observe(e.current, { box: "border-box" }), () => s.disconnect();
233
236
  }, [s, e]), t;
234
237
  }, Qe = (e, t, n) => {
@@ -237,45 +240,45 @@ const Tt = ze(({ configuration: e, children: t, style: n, className: s }, o) =>
237
240
  const o = window.devicePixelRatio || 1;
238
241
  if (t.width === 0 || t.height === 0)
239
242
  return null;
240
- const i = {
243
+ const r = {
241
244
  x: e.padding.left,
242
245
  y: e.padding.top,
243
246
  width: t.width - e.padding.left - e.padding.right,
244
247
  height: t.height - e.padding.top - e.padding.bottom
245
248
  };
246
249
  for (const u of e.scales)
247
- u.axis && (u.origin === "x" ? (u.axis.position === "bottom" || u.axis.position === "top") && (i.height = Math.max(
250
+ u.axis && (u.origin === "x" ? (u.axis.position === "bottom" || u.axis.position === "top") && (r.height = Math.max(
248
251
  0,
249
- i.height - u.axis.size
250
- ), u.axis.position === "top" && (i.y += u.axis.size)) : (u.axis.position === "left" || u.axis.position === "right") && (i.width = Math.max(0, i.width - u.axis.size), u.axis.position === "left" && (i.x += u.axis.size)));
251
- const r = {
252
- x: i.x * o,
253
- y: i.y * o,
254
- width: i.width * o,
255
- height: i.height * o
256
- }, c = [];
257
- let a = e.padding.left * o, l = s.canvas.width - e.padding.right * o, d = s.canvas.height - e.padding.bottom * o, h = e.padding.top * o;
252
+ r.height - u.axis.size
253
+ ), u.axis.position === "top" && (r.y += u.axis.size)) : (u.axis.position === "left" || u.axis.position === "right") && (r.width = Math.max(0, r.width - u.axis.size), u.axis.position === "left" && (r.x += u.axis.size)));
254
+ const c = {
255
+ x: r.x * o,
256
+ y: r.y * o,
257
+ width: r.width * o,
258
+ height: r.height * o
259
+ }, i = [];
260
+ let a = e.padding.left * o, l = s.canvas.width - e.padding.right * o, m = s.canvas.height - e.padding.bottom * o, d = e.padding.top * o;
258
261
  for (const u of e.scales) {
259
262
  if (!u.axis) {
260
- c.push({ ...u, axis: null });
263
+ i.push({ ...u, axis: null });
261
264
  continue;
262
265
  }
263
- let f;
266
+ let h;
264
267
  if (u.origin === "x")
265
268
  switch (u.axis.position) {
266
269
  case "bottom":
267
- d -= u.axis.size * o, f = {
268
- x: i.x,
269
- y: d / o,
270
- width: i.width,
270
+ m -= u.axis.size * o, h = {
271
+ x: r.x,
272
+ y: m / o,
273
+ width: r.width,
271
274
  height: u.axis.size
272
275
  };
273
276
  break;
274
277
  case "top":
275
- h += u.axis.size * o, f = {
276
- x: i.x,
277
- y: h / o - u.axis.size,
278
- width: i.width,
278
+ d += u.axis.size * o, h = {
279
+ x: r.x,
280
+ y: d / o - u.axis.size,
281
+ width: r.width,
279
282
  height: u.axis.size
280
283
  };
281
284
  break;
@@ -286,37 +289,37 @@ const Tt = ze(({ configuration: e, children: t, style: n, className: s }, o) =>
286
289
  else
287
290
  switch (u.axis.position) {
288
291
  case "left":
289
- a += u.axis.size * o, f = {
292
+ a += u.axis.size * o, h = {
290
293
  x: a / o - u.axis.size,
291
- y: i.y,
294
+ y: r.y,
292
295
  width: u.axis.size,
293
- height: i.height
296
+ height: r.height
294
297
  };
295
298
  break;
296
299
  case "right":
297
- l -= u.axis.size * o, f = {
300
+ l -= u.axis.size * o, h = {
298
301
  x: l / o,
299
- y: i.y,
302
+ y: r.y,
300
303
  width: u.axis.size,
301
- height: i.height
304
+ height: r.height
302
305
  };
303
306
  break;
304
307
  case "top":
305
308
  case "bottom":
306
309
  throw new Error("Invalid axis position for y origin");
307
310
  }
308
- const v = {
309
- x: f.x * o,
310
- y: f.y * o,
311
- width: f.width * o,
312
- height: f.height * o
311
+ const y = {
312
+ x: h.x * o,
313
+ y: h.y * o,
314
+ width: h.width * o,
315
+ height: h.height * o
313
316
  };
314
- c.push({
317
+ i.push({
315
318
  ...u,
316
319
  axis: {
317
320
  ...u.axis,
318
- cssRect: f,
319
- canvasRect: v
321
+ cssRect: h,
322
+ canvasRect: y
320
323
  }
321
324
  });
322
325
  }
@@ -324,215 +327,227 @@ const Tt = ze(({ configuration: e, children: t, style: n, className: s }, o) =>
324
327
  ctx: s,
325
328
  dpr: o,
326
329
  padding: e.padding,
327
- scales: c,
328
- chartAreaCSS: i,
329
- chartAreaCanvasPX: r
330
+ scales: i,
331
+ chartAreaCSS: r,
332
+ chartAreaCanvasPX: c
330
333
  };
331
- }, N = (e, t, n) => {
332
- const s = H(ve), o = H(Re), i = H(Ee);
334
+ }, j = (e, t, n) => {
335
+ const s = q(ve), o = q(ke), r = q(Ee);
333
336
  if (!s || !o)
334
337
  throw new Error("useFrame must be used within a CanPlot component");
335
- const [r] = O(() => new Ae());
336
- r._updateFrame(s);
337
- const c = k(r);
338
- c.current = r;
339
- const a = k(t);
340
- a.current = t, B(() => i.subscribe(
338
+ const [c] = z(() => new Re());
339
+ c._updateFrame(s);
340
+ const i = A(c);
341
+ i.current = c;
342
+ const a = A(t);
343
+ a.current = t, $(() => r.subscribe(
341
344
  () => {
342
- a.current(r);
345
+ a.current(c);
343
346
  },
344
- typeof e == "number" ? e : ke[e]
345
- ), [i, e, r]), B(() => {
347
+ typeof e == "number" ? e : Ae[e]
348
+ ), [r, e, c]), $(() => {
346
349
  o();
347
350
  }, [o, ...n]);
348
- }, ge = () => {
349
- const e = H(ve);
351
+ }, De = () => {
352
+ const e = q(ve);
350
353
  if (!e)
351
354
  throw new Error("useFrame must be used within a CanPlot component");
352
- return G(() => {
353
- const t = new Ae();
355
+ return oe(() => {
356
+ const t = new Re();
354
357
  return t._updateFrame(e), t;
355
358
  }, [e]);
356
- }, St = ({ layer: e = "MIDDLE", data: t, xScaleId: n, yScaleId: s, style: o }) => (N(
359
+ }, et = ({ layer: e = "MIDDLE", data: t, xScaleId: n, yScaleId: s, style: o }) => (j(
357
360
  e,
358
- ({ ctx: i, clampXPosToChartArea: r, clampYPosToChartArea: c, valToPos: a }) => {
359
- i.save(), i.beginPath(), L(i, o);
361
+ ({ ctx: r, clampXPosToChartArea: c, clampYPosToChartArea: i, valToPos: a }) => {
362
+ r.save(), r.beginPath(), U(r, o);
360
363
  for (const l of t) {
361
- const d = r(a(l.x, n)), h = c(a(l.y, s));
362
- i.lineTo(d, h);
364
+ const m = c(a(l.x, n)), d = i(a(l.y, s));
365
+ r.lineTo(m, d);
363
366
  }
364
- i.stroke(), i.restore();
367
+ r.stroke(), r.restore();
365
368
  },
366
369
  [t, n, s, o]
367
- ), null), Ct = ({ layer: e = "MIDDLE", data: t, xScaleId: n, yScaleId: s, radius: o = 5, style: i, globalAlpha: r }) => (N(
370
+ ), null), Rt = D.memo(et, O), tt = ({
371
+ layer: e = "MIDDLE",
372
+ data: t,
373
+ xScaleId: n,
374
+ yScaleId: s,
375
+ xStrategy: o = "clip",
376
+ yStrategy: r = "clip",
377
+ radius: c = 5,
378
+ style: i,
379
+ globalAlpha: a
380
+ }) => (j(
368
381
  e,
369
- ({ ctx: c, valToPos: a, valFits: l }) => {
370
- c.save(), c.beginPath();
371
- const d = new Path2D();
372
- L(c, i), r !== void 0 && (c.globalAlpha = r);
373
- for (const h of t) {
374
- if (!l(h.x, n) || !l(h.y, s))
375
- continue;
376
- const m = a(h.x, n), u = a(h.y, s);
377
- d.moveTo(m + o, u), d.arc(m, u, o, 0, Math.PI * 2);
382
+ ({
383
+ ctx: l,
384
+ valToPos: m,
385
+ valFits: d,
386
+ clampXPosToChartArea: p,
387
+ clampYPosToChartArea: u
388
+ }) => {
389
+ l.save(), l.beginPath();
390
+ const h = new Path2D();
391
+ U(l, i), a !== void 0 && (l.globalAlpha = a);
392
+ for (const y of t) {
393
+ let f, g;
394
+ switch (o) {
395
+ case "clip":
396
+ if (!d(y.x, n))
397
+ continue;
398
+ f = m(y.x, n);
399
+ break;
400
+ case "clamp":
401
+ f = p(m(y.x, n), "canvas");
402
+ break;
403
+ }
404
+ switch (r) {
405
+ case "clip":
406
+ if (!d(y.y, s))
407
+ continue;
408
+ g = m(y.y, s);
409
+ break;
410
+ case "clamp":
411
+ g = u(m(y.y, s), "canvas");
412
+ break;
413
+ }
414
+ h.moveTo(f + c, g), h.arc(f, g, c, 0, Math.PI * 2);
378
415
  }
379
- c.fill(d), c.stroke(d), c.restore();
416
+ l.fill(h), l.stroke(h), l.restore();
380
417
  },
381
- [t, n, s, o, i, r]
382
- ), null), Pt = ({
418
+ [t, n, s, c, i, a]
419
+ ), null), Dt = D.memo(tt, O), nt = ({
383
420
  data: e,
384
421
  xScaleId: t,
385
422
  yScaleId: n,
386
423
  style: s,
387
424
  barWidth: o,
388
- xPositionOffset: i,
389
- radius: r,
390
- layer: c = "MIDDLE"
391
- }) => (N(
392
- c,
425
+ xPositionOffset: r,
426
+ radius: c,
427
+ layer: i = "MIDDLE"
428
+ }) => (j(
429
+ i,
393
430
  ({
394
431
  ctx: a,
395
432
  valToPxDistance: l,
396
- valToPos: d,
397
- clampXPosToChartArea: h,
398
- clampYPosToChartArea: m
433
+ valToPos: m,
434
+ clampXPosToChartArea: d,
435
+ clampYPosToChartArea: p
399
436
  }) => {
400
437
  if (e.length === 0) return;
401
- a.save(), L(a, s);
438
+ a.save(), U(a, s);
402
439
  const u = l(o, t);
403
440
  a.beginPath();
404
- for (const f of e) {
405
- const p = d(f.x, t) - u / 2 + i * u, g = m(d(0, n)), w = m(d(f.y, n)), T = g - w, b = h(p), y = h(p + u) - b;
406
- r ? a.roundRect(
407
- b,
441
+ for (const h of e) {
442
+ const f = m(h.x, t) - u / 2 + r * u, g = p(m(0, n)), w = p(m(h.y, n)), T = g - w, x = d(f), v = d(f + u) - x;
443
+ c ? a.roundRect(
444
+ x,
408
445
  w,
409
- y,
446
+ v,
410
447
  T,
411
- r
412
- ) : a.rect(b, w, y, T);
448
+ c
449
+ ) : a.rect(x, w, v, T);
413
450
  }
414
451
  a.closePath(), a.fill(), s?.strokeStyle && a.stroke(), a.restore();
415
452
  },
416
- [e, t, n, s, o, i, r]
417
- ), null), Mt = ({ layer: e = "MIDDLE", data: t, xScaleId: n, yScaleId: s, style: o }) => (N(
453
+ [e, t, n, s, o, r, c]
454
+ ), null), It = D.memo(nt, O), st = ({ layer: e = "MIDDLE", data: t, xScaleId: n, yScaleId: s, style: o }) => (j(
418
455
  e,
419
- ({ ctx: i, clampXPosToChartArea: r, clampYPosToChartArea: c, valToPos: a }) => {
456
+ ({ ctx: r, clampXPosToChartArea: c, clampYPosToChartArea: i, valToPos: a }) => {
420
457
  const l = [];
421
458
  for (const d of t) {
422
- const h = r(a(d.x, n)), m = c(a(d.y[0], s)), u = c(a(d.y[1], s));
423
- l.push({ x: h, y: m }), l.unshift({ x: h, y: u });
459
+ const p = c(a(d.x, n)), u = i(a(d.y[0], s)), h = i(a(d.y[1], s));
460
+ l.push({ x: p, y: u }), l.unshift({ x: p, y: h });
424
461
  }
425
- if (l.length > 0) {
426
- i.save(), i.beginPath(), L(i, o), i.moveTo(l[0].x, l[0].y);
462
+ const m = l[0];
463
+ if (m) {
464
+ r.save(), r.beginPath(), U(r, o), r.moveTo(m.x, m.y);
427
465
  for (const d of l)
428
- i.lineTo(d.x, d.y);
429
- i.closePath(), i.fill(), i.restore();
466
+ r.lineTo(d.x, d.y);
467
+ r.closePath(), r.fill(), r.restore();
430
468
  }
431
469
  },
432
470
  [t, n, s, o]
433
- ), null), Et = ({ layer: e = "MIDDLE", data: t, stroked: n, xScaleId: s, yScaleId: o, style: i }) => (N(
471
+ ), null), Lt = D.memo(st, O), ot = ({ layer: e = "MIDDLE", data: t, stroked: n, xScaleId: s, yScaleId: o, style: r }) => (j(
434
472
  e,
435
- ({ ctx: r, clampXPosToChartArea: c, clampYPosToChartArea: a, valToPos: l }) => {
436
- const d = [];
437
- for (const f of t) {
438
- const v = c(l(f.x, s)), p = a(l(f.y, o));
439
- d.push({ x: v, y: p });
473
+ ({ ctx: c, clampXPosToChartArea: i, clampYPosToChartArea: a, valToPos: l }) => {
474
+ const m = [];
475
+ for (const h of t) {
476
+ const y = i(l(h.x, s)), f = a(l(h.y, o));
477
+ m.push({ x: y, y: f });
440
478
  }
441
- const h = d.at(0), m = d.at(-1);
442
- if (!h || !m)
479
+ const d = m.at(0), p = m.at(-1);
480
+ if (!d || !p)
443
481
  return;
444
482
  const u = a(l(0, o));
445
- r.save(), r.beginPath(), L(r, i), r.moveTo(h.x, u);
446
- for (const f of d)
447
- r.lineTo(f.x, f.y);
448
- if (r.lineTo(m.x, u), r.closePath(), r.fill(), n) {
449
- r.beginPath(), r.moveTo(h.x, h.y);
450
- for (const f of d)
451
- r.lineTo(f.x, f.y);
452
- r.stroke();
483
+ c.save(), c.beginPath(), U(c, r), c.moveTo(d.x, u);
484
+ for (const h of m)
485
+ c.lineTo(h.x, h.y);
486
+ if (c.lineTo(p.x, u), c.closePath(), c.fill(), n) {
487
+ c.beginPath(), c.moveTo(d.x, d.y);
488
+ for (const h of m)
489
+ c.lineTo(h.x, h.y);
490
+ c.stroke();
453
491
  }
454
- r.restore();
492
+ c.restore();
455
493
  },
456
- [t, n, s, o, i]
457
- ), null), Rt = (e, t) => {
458
- const n = ge();
459
- return G(() => {
460
- const { valToPos: s, valFits: o, getScale: i, clampXPosToChartArea: r, clampYPosToChartArea: c } = n, a = {};
461
- for (const l in e) {
462
- const d = e[l];
463
- switch (d.exceeding) {
464
- case "discard": {
465
- if (o(d.value, d.scaleId)) {
466
- const h = s(d.value, d.scaleId, t);
467
- a[l] = h;
468
- }
469
- break;
470
- }
471
- case "clamp": {
472
- const h = s(d.value, d.scaleId, t);
473
- a[l] = i(d.scaleId)?.origin === "x" ? r(h, t) : c(h, t);
474
- break;
475
- }
476
- }
477
- }
478
- return a;
479
- }, [e, t, n]);
480
- }, kt = ({ layer: e = "BOTTOM", scaleId: t, tickStyle: n, labelStyle: s, labelGap: o, tickSize: i, ticks: r }) => (N(
494
+ [t, n, s, o, r]
495
+ ), null), Ut = D.memo(ot, O), rt = ({ layer: e = "BOTTOM", scaleId: t, tickStyle: n, labelStyle: s, labelGap: o, tickSize: r, ticks: c }) => (j(
481
496
  e,
482
- ({ ctx: c, valToPos: a, getScale: l, frame: d }) => {
483
- const h = l(t);
484
- if (!h || !h.axis || h.origin !== "x") return;
485
- const m = h.axis, u = m.position === "top" ? m.canvasRect.y + m.canvasRect.height : m.canvasRect.y, f = window.devicePixelRatio || 1, v = u, p = (i ?? 6) * f, g = m.position === "top" ? u - p : u + p, w = (o ?? 12) * f;
486
- c.save(), c.fontKerning = "auto", L(c, {
497
+ ({ ctx: i, valToPos: a, getScale: l, frame: m }) => {
498
+ const d = l(t);
499
+ if (!d || !d.axis || d.origin !== "x") return;
500
+ const p = d.axis, u = p.position === "top" ? p.canvasRect.y + p.canvasRect.height : p.canvasRect.y, h = window.devicePixelRatio || 1, y = u, f = (r ?? 6) * h, g = p.position === "top" ? u - f : u + f, w = (o ?? 12) * h;
501
+ i.save(), i.fontKerning = "auto", U(i, {
487
502
  ...n
488
- }), c.beginPath();
489
- const T = Array.isArray(r) ? r : r({ ...h, axis: m }, d);
490
- for (const { value: b } of T) {
491
- const y = a(b, t, "canvas");
492
- c.moveTo(y, v), c.lineTo(y, g);
503
+ }), i.beginPath();
504
+ const T = Array.isArray(c) ? c : c({ ...d, axis: p }, m);
505
+ for (const { value: x } of T) {
506
+ const v = a(x, t, "canvas");
507
+ i.moveTo(v, y), i.lineTo(v, g);
493
508
  }
494
- c.stroke(), c.restore(), c.save(), L(c, {
495
- textBaseline: m.position === "top" ? "bottom" : "top",
509
+ i.stroke(), i.restore(), i.save(), U(i, {
510
+ textBaseline: p.position === "top" ? "bottom" : "top",
496
511
  textAlign: "center",
497
512
  ...n,
498
513
  ...s
499
514
  });
500
- for (const { value: b, label: y } of T) {
501
- const x = a(b, t, "canvas"), S = y.split(`
515
+ for (const { value: x, label: v } of T) {
516
+ const b = a(x, t, "canvas"), S = v.split(`
502
517
  `);
503
518
  for (let E = 0; E < S.length; E++)
504
- c.fillText(S[E], x, g + f * 2 + E * w);
519
+ i.fillText(S[E], b, g + h * 2 + E * w);
505
520
  }
506
- c.restore();
521
+ i.restore();
507
522
  },
508
- [r, t, n, s]
509
- ), null), At = ({ layer: e = "BOTTOM", scaleId: t, tickStyle: n, labelStyle: s, labelGap: o, tickSize: i, ticks: r }) => (N(
523
+ [c, t, n, s]
524
+ ), null), _t = D.memo(rt, O), it = ({ layer: e = "BOTTOM", scaleId: t, tickStyle: n, labelStyle: s, labelGap: o, tickSize: r, ticks: c }) => (j(
510
525
  e,
511
- ({ ctx: c, valToPos: a, getScale: l, frame: d }) => {
512
- const h = l(t);
513
- if (!h || !h.axis || h.origin !== "y") return;
514
- const m = h.axis, u = m.position === "left" ? m.canvasRect.x + m.canvasRect.width : m.canvasRect.x, f = u, v = i ?? 6, p = m.position === "left" ? u - v : u + v, g = o ?? 12, w = Array.isArray(r) ? r : r({ ...h, axis: m }, d);
515
- c.save(), c.fontKerning = "auto", L(c, { ...n }), c.beginPath();
526
+ ({ ctx: i, valToPos: a, getScale: l, frame: m }) => {
527
+ const d = l(t);
528
+ if (!d || !d.axis || d.origin !== "y") return;
529
+ const p = d.axis, u = p.position === "left" ? p.canvasRect.x + p.canvasRect.width : p.canvasRect.x, h = u, y = r ?? 6, f = p.position === "left" ? u - y : u + y, g = o ?? 12, w = Array.isArray(c) ? c : c({ ...d, axis: p }, m);
530
+ i.save(), i.fontKerning = "auto", U(i, { ...n }), i.beginPath();
516
531
  for (const { value: T } of w) {
517
- const b = a(T, t, "canvas");
518
- c.moveTo(f, b), c.lineTo(p, b);
532
+ const x = a(T, t, "canvas");
533
+ i.moveTo(h, x), i.lineTo(f, x);
519
534
  }
520
- c.stroke(), c.restore(), c.save(), L(c, {
535
+ i.stroke(), i.restore(), i.save(), U(i, {
521
536
  textBaseline: "middle",
522
- textAlign: m.position === "left" ? "right" : "left",
537
+ textAlign: p.position === "left" ? "right" : "left",
523
538
  ...n,
524
539
  ...s
525
540
  });
526
- for (const { value: T, label: b } of w) {
527
- const y = a(T, t, "canvas"), x = b.split(`
541
+ for (const { value: T, label: x } of w) {
542
+ const v = a(T, t, "canvas"), b = x.split(`
528
543
  `);
529
- for (let S = 0; S < x.length; S++)
530
- c.fillText(` ${x[S]} `, p, y + S * g);
544
+ for (let S = 0; S < b.length; S++)
545
+ i.fillText(` ${b[S]} `, f, v + S * g);
531
546
  }
532
- c.restore();
547
+ i.restore();
533
548
  },
534
- [r, t, n, s]
535
- ), null), D = () => {
549
+ [c, t, n, s]
550
+ ), null), Xt = D.memo(it, O), I = () => {
536
551
  const e = [];
537
552
  return {
538
553
  addEventListener: (t, n) => (e.push({
@@ -548,69 +563,69 @@ const Tt = ze(({ configuration: e, children: t, style: n, className: s }, o) =>
548
563
  }
549
564
  };
550
565
  }, M = {
551
- dblclick: D(),
552
- click: D(),
553
- contextmenu: D(),
554
- move: D(),
555
- mousedown: D(),
556
- mouseup: D(),
557
- spanselect: D(),
558
- documentmouseup: D(),
559
- pressandwheel: D(),
560
- sync_move: D()
561
- }, I = (e, t, n) => {
562
- const s = ne.useRef(n);
563
- s.current = n, ne.useEffect(() => M[e].addEventListener(
566
+ dblclick: I(),
567
+ click: I(),
568
+ contextmenu: I(),
569
+ move: I(),
570
+ mousedown: I(),
571
+ mouseup: I(),
572
+ spanselect: I(),
573
+ documentmouseup: I(),
574
+ pressandwheel: I(),
575
+ sync_move: I()
576
+ }, L = (e, t, n) => {
577
+ const s = D.useRef(n);
578
+ s.current = n, D.useEffect(() => M[e].addEventListener(
564
579
  t,
565
- (i, r) => {
566
- s.current(r, i);
580
+ (r, c) => {
581
+ s.current(c, r);
567
582
  }
568
583
  ), [t, e, s]);
569
- }, we = ne.createContext(""), be = (e, t) => {
570
- const n = ne.useContext(we);
571
- return I(e, n, t);
572
- }, et = (e, t, n, s, o) => {
584
+ }, we = D.createContext(""), xe = (e, t) => {
585
+ const n = D.useContext(we);
586
+ return L(e, n, t);
587
+ }, ct = (e, t, n, s, o) => {
573
588
  if (!t) return;
574
- const i = s ?? n.scales.find((h) => h.origin === "x")?.id, r = o ?? n.scales.find((h) => h.origin === "y")?.id, c = e.clientX - t.left, a = i ? {
575
- scaleId: i,
576
- value: U(n, c, i, "css")
577
- } : null, l = e.clientY - t.top, d = r ? {
589
+ const r = s ?? n.scales.find((d) => d.origin === "x")?.id, c = o ?? n.scales.find((d) => d.origin === "y")?.id, i = e.clientX - t.left, a = r ? {
578
590
  scaleId: r,
579
- value: U(n, l, r, "css")
591
+ value: _(n, i, r, "css")
592
+ } : null, l = e.clientY - t.top, m = c ? {
593
+ scaleId: c,
594
+ value: _(n, l, c, "css")
580
595
  } : null;
581
- return { pointerSyncPosition: { x: a, y: d }, cssX: c, cssY: l };
582
- }, z = (e, t) => {
583
- const { x: n, y: s } = e, o = n && t.scales.some((r) => r.id === n.scaleId) ? q(t, n.value, n.scaleId, "css") : null, i = s && t.scales.some((r) => r.id === s.scaleId) ? q(t, s.value, s.scaleId, "css") : null;
596
+ return { pointerSyncPosition: { x: a, y: m }, cssX: i, cssY: l };
597
+ }, N = (e, t) => {
598
+ const { x: n, y: s } = e, o = n && t.scales.some((c) => c.id === n.scaleId) ? Z(t, n.value, n.scaleId, "css") : null, r = s && t.scales.some((c) => c.id === s.scaleId) ? Z(t, s.value, s.scaleId, "css") : null;
584
599
  return {
585
600
  cssX: o,
586
- cssY: i,
601
+ cssY: r,
587
602
  scaled: Object.fromEntries(
588
- t.scales.flatMap((r) => {
589
- const c = r.origin === "y" ? i : o;
590
- return c === null ? [] : [[r.id, U(t, c, r.id, "css")]];
603
+ t.scales.flatMap((c) => {
604
+ const i = c.origin === "y" ? r : o;
605
+ return i === null ? [] : [[c.id, _(t, i, c.id, "css")]];
591
606
  })
592
607
  )
593
608
  };
594
609
  }, Pe = (e, t, n) => {
595
- const s = q(
610
+ const s = Z(
596
611
  n,
597
612
  t.from,
598
613
  t.scaleId,
599
614
  "css"
600
- ), o = q(
615
+ ), o = Z(
601
616
  n,
602
617
  t.to,
603
618
  t.scaleId,
604
619
  "css"
605
- ), i = n.scales.flatMap(
606
- (r) => {
607
- if (r.origin !== e)
620
+ ), r = n.scales.flatMap(
621
+ (c) => {
622
+ if (c.origin !== e)
608
623
  return [];
609
- const c = U(n, s, r.id, "css"), a = U(n, o, r.id, "css");
624
+ const i = _(n, s, c.id, "css"), a = _(n, o, c.id, "css");
610
625
  return [
611
626
  {
612
- scaleId: r.id,
613
- from: c,
627
+ scaleId: c.id,
628
+ from: i,
614
629
  to: a
615
630
  }
616
631
  ];
@@ -619,71 +634,71 @@ const Tt = ze(({ configuration: e, children: t, style: n, className: s }, o) =>
619
634
  return {
620
635
  fromCSS: s,
621
636
  toCSS: o,
622
- scaled: i
637
+ scaled: r
623
638
  };
624
- }, Dt = ({
639
+ }, Ot = ({
625
640
  id: e,
626
641
  onClick: t,
627
642
  onDblClick: n,
628
643
  onMouseMove: s,
629
644
  onMouseDown: o,
630
- onMouseUp: i,
631
- onDocumentMouseUp: r,
632
- onSpanSelect: c,
645
+ onMouseUp: r,
646
+ onDocumentMouseUp: c,
647
+ onSpanSelect: i,
633
648
  onContextMenu: a,
634
649
  className: l,
635
- style: d,
636
- sync: h,
637
- innerChildren: m,
650
+ style: m,
651
+ sync: d,
652
+ innerChildren: p,
638
653
  children: u
639
654
  }) => {
640
- const f = Be();
641
- return I("dblclick", f, (v) => {
642
- n?.(v);
643
- }), I("click", f, (v) => {
644
- t?.(v);
645
- }), I("move", f, (v) => {
646
- s?.(v);
647
- }), I("mousedown", f, (v) => {
648
- o?.(v);
649
- }), I("mouseup", f, (v) => {
650
- i?.(v);
651
- }), I("documentmouseup", f, (v) => {
652
- r?.(v);
653
- }), I("spanselect", f, (v) => {
654
- c?.(v);
655
- }), I("contextmenu", f, (v) => {
656
- a?.(v);
657
- }), /* @__PURE__ */ me(we.Provider, { value: f, children: [
658
- /* @__PURE__ */ A(
659
- tt,
655
+ const h = Ne();
656
+ return L("dblclick", h, (y) => {
657
+ n?.(y);
658
+ }), L("click", h, (y) => {
659
+ t?.(y);
660
+ }), L("move", h, (y) => {
661
+ s?.(y);
662
+ }), L("mousedown", h, (y) => {
663
+ o?.(y);
664
+ }), L("mouseup", h, (y) => {
665
+ r?.(y);
666
+ }), L("documentmouseup", h, (y) => {
667
+ c?.(y);
668
+ }), L("spanselect", h, (y) => {
669
+ i?.(y);
670
+ }), L("contextmenu", h, (y) => {
671
+ a?.(y);
672
+ }), /* @__PURE__ */ pe(we.Provider, { value: h, children: [
673
+ /* @__PURE__ */ R(
674
+ at,
660
675
  {
661
676
  id: e,
662
677
  className: l,
663
- style: d,
664
- sync: h,
665
- children: m
678
+ style: m,
679
+ sync: d,
680
+ children: p
666
681
  }
667
682
  ),
668
683
  u
669
684
  ] });
670
- }, tt = ({ id: e, className: t, style: n, sync: s, children: o }) => {
671
- const i = k(null), r = ge().frame, c = k(r);
672
- c.current = r;
673
- const a = H(we), l = s?.key || a, d = k(null), h = k(null), m = k(null), u = () => {
674
- const p = i.current?.parentElement;
675
- if (p) {
676
- if (p.dataset.canplotroot === void 0)
685
+ }, at = ({ id: e, className: t, style: n, sync: s, children: o }) => {
686
+ const r = A(null), c = De().frame, i = A(c);
687
+ i.current = c;
688
+ const a = q(we), l = s?.key || a, m = A(null), d = A(null), p = A(null), u = () => {
689
+ const f = r.current?.parentElement;
690
+ if (f) {
691
+ if (f.dataset.canplotroot === void 0)
677
692
  throw new Error(
678
693
  "ChartAreaInteractions must be used within a CanPlot component"
679
694
  );
680
- return p.getBoundingClientRect();
695
+ return f.getBoundingClientRect();
681
696
  }
682
- }, f = (p, g) => {
683
- const w = et(
684
- p,
697
+ }, h = (f, g) => {
698
+ const w = ct(
699
+ f,
685
700
  u(),
686
- c.current,
701
+ i.current,
687
702
  s?.xViaScaleId,
688
703
  s?.yViaScaleId
689
704
  );
@@ -691,189 +706,189 @@ const Tt = ze(({ configuration: e, children: t, style: n, className: s }, o) =>
691
706
  w.pointerSyncPosition,
692
707
  { cssX: w.cssX, cssY: w.cssY },
693
708
  {
694
- ctrlKey: p.ctrlKey,
695
- altKey: p.altKey,
696
- shiftKey: p.shiftKey,
697
- metaKey: p.metaKey
709
+ ctrlKey: f.ctrlKey,
710
+ altKey: f.altKey,
711
+ shiftKey: f.shiftKey,
712
+ metaKey: f.metaKey
698
713
  }
699
714
  );
700
- }, v = k(f);
701
- return v.current = f, Ne(() => {
702
- const p = (y) => {
703
- const x = h.current;
704
- x && M.spanselect.dispatchEvent(a, {
705
- ...x,
715
+ }, y = A(h);
716
+ return y.current = h, $e(() => {
717
+ const f = (v) => {
718
+ const b = d.current;
719
+ b && M.spanselect.dispatchEvent(a, {
720
+ ...b,
706
721
  completed: !0
707
722
  }), M.documentmouseup.dispatchEvent(a, {
708
- frame: c.current,
723
+ frame: i.current,
709
724
  keys: {
710
- ctrlKey: y.ctrlKey,
711
- altKey: y.altKey,
712
- shiftKey: y.shiftKey,
713
- metaKey: y.metaKey
725
+ ctrlKey: v.ctrlKey,
726
+ altKey: v.altKey,
727
+ shiftKey: v.shiftKey,
728
+ metaKey: v.metaKey
714
729
  }
715
730
  });
716
- }, g = (y) => {
717
- const x = {
718
- ctrlKey: y.ctrlKey,
719
- altKey: y.altKey,
720
- shiftKey: y.shiftKey,
721
- metaKey: y.metaKey
722
- }, S = m.current;
723
- if (S && Object.entries(x).some(
731
+ }, g = (v) => {
732
+ const b = {
733
+ ctrlKey: v.ctrlKey,
734
+ altKey: v.altKey,
735
+ shiftKey: v.shiftKey,
736
+ metaKey: v.metaKey
737
+ }, S = p.current;
738
+ if (S && Object.entries(b).some(
724
739
  ([C, P]) => S.keys[C] !== P
725
740
  )) {
726
- const C = { ...S, keys: x };
727
- m.current = C, M.sync_move.dispatchEvent(l, C);
741
+ const C = { ...S, keys: b };
742
+ p.current = C, M.sync_move.dispatchEvent(l, C);
728
743
  }
729
- const E = h.current;
730
- if (E && Object.entries(x).some(
744
+ const E = d.current;
745
+ if (E && Object.entries(b).some(
731
746
  ([C, P]) => E.keys[C] !== P
732
747
  )) {
733
- y.stopPropagation(), y.preventDefault();
734
- const C = { ...E, keys: x };
735
- h.current = C, M.spanselect.dispatchEvent(a, C);
748
+ v.stopPropagation(), v.preventDefault();
749
+ const C = { ...E, keys: b };
750
+ d.current = C, M.spanselect.dispatchEvent(a, C);
736
751
  }
737
- }, w = (y) => {
738
- v.current(
739
- y,
740
- (x, { cssX: S, cssY: E }, C) => {
741
- const P = d.current;
742
- if (!P || !x.x || !x.y) return;
743
- const R = c.current, Y = P.xRangeCss.start, ie = S, re = P.yRangeCss.start, ce = E, ae = _(R, x.x.scaleId), le = _(R, x.y.scaleId);
744
- d.current = {
745
- xRangeCss: { start: Y, end: ie },
746
- yRangeCss: { start: re, end: ce }
752
+ }, w = (v) => {
753
+ y.current(
754
+ v,
755
+ (b, { cssX: S, cssY: E }, C) => {
756
+ const P = m.current;
757
+ if (!P || !b.x || !b.y) return;
758
+ const k = i.current, B = P.xRangeCss.start, ie = S, ce = P.yRangeCss.start, ae = E, le = X(k, b.x.scaleId), ue = X(k, b.y.scaleId);
759
+ m.current = {
760
+ xRangeCss: { start: B, end: ie },
761
+ yRangeCss: { start: ce, end: ae }
747
762
  };
748
- let j = "below_threshold";
749
- const ue = Math.abs(re - ce), de = Math.abs(Y - ie);
750
- ue < 10 && de < 10 ? j = "below_threshold" : ue > 30 && de > 30 ? j = "box" : ue > de ? j = "y" : j = "x";
763
+ let W = "below_threshold";
764
+ const he = Math.abs(ce - ae), de = Math.abs(B - ie);
765
+ he < 10 && de < 10 ? W = "below_threshold" : he > 30 && de > 30 ? W = "box" : he > de ? W = "y" : W = "x";
751
766
  const Te = {
752
- scaleId: ae.id,
753
- from: U(
754
- R,
755
- $(c.current, Y, "css"),
756
- ae.id,
767
+ scaleId: le.id,
768
+ from: _(
769
+ k,
770
+ V(i.current, B, "css"),
771
+ le.id,
757
772
  "css"
758
773
  ),
759
- to: U(
760
- R,
761
- $(c.current, ie, "css"),
762
- ae.id,
774
+ to: _(
775
+ k,
776
+ V(i.current, ie, "css"),
777
+ le.id,
763
778
  "css"
764
779
  )
765
780
  }, Se = {
766
- scaleId: le.id,
767
- from: U(
768
- R,
769
- V(c.current, re, "css"),
770
- le.id,
781
+ scaleId: ue.id,
782
+ from: _(
783
+ k,
784
+ H(i.current, ce, "css"),
785
+ ue.id,
771
786
  "css"
772
787
  ),
773
- to: U(
774
- R,
775
- V(c.current, ce, "css"),
776
- le.id,
788
+ to: _(
789
+ k,
790
+ H(i.current, ae, "css"),
791
+ ue.id,
777
792
  "css"
778
793
  )
779
- }, Z = Te && Pe("x", Te, c.current), J = Se && Pe("y", Se, c.current), Ue = Z?.scaled, _e = J?.scaled, Ce = {
780
- mode: j,
781
- frame: c.current,
794
+ }, J = Te && Pe("x", Te, i.current), Q = Se && Pe("y", Se, i.current), _e = J?.scaled, Xe = Q?.scaled, Ce = {
795
+ mode: W,
796
+ frame: i.current,
782
797
  completed: !1,
783
798
  x: {
784
- css: Z && {
785
- from: Z.fromCSS,
786
- to: Z.toCSS
787
- },
788
- scaled: Ue ?? []
789
- },
790
- y: {
791
799
  css: J && {
792
800
  from: J.fromCSS,
793
801
  to: J.toCSS
794
802
  },
795
803
  scaled: _e ?? []
796
804
  },
805
+ y: {
806
+ css: Q && {
807
+ from: Q.fromCSS,
808
+ to: Q.toCSS
809
+ },
810
+ scaled: Xe ?? []
811
+ },
797
812
  keys: C
798
813
  };
799
- h.current = Ce, M.spanselect.dispatchEvent(
814
+ d.current = Ce, M.spanselect.dispatchEvent(
800
815
  a,
801
816
  Ce
802
817
  );
803
818
  }
804
819
  );
805
- }, T = (y) => {
806
- v.current(y, (x, S, E) => {
807
- const C = z(
808
- x,
809
- c.current
820
+ }, T = (v) => {
821
+ y.current(v, (b, S, E) => {
822
+ const C = N(
823
+ b,
824
+ i.current
810
825
  );
811
826
  if (!C) return;
812
- if (Object.values(E).some((R) => R)) {
813
- y.preventDefault();
814
- const R = Math.abs(y.deltaY) > Math.abs(y.deltaX) ? y.deltaY : y.deltaX;
827
+ if (Object.values(E).some((k) => k)) {
828
+ v.preventDefault();
829
+ const k = Math.abs(v.deltaY) > Math.abs(v.deltaX) ? v.deltaY : v.deltaX;
815
830
  M.pressandwheel.dispatchEvent(a, {
816
831
  pointer: C,
817
- frame: c.current,
832
+ frame: i.current,
818
833
  keys: E,
819
- deltaX: y.deltaX,
820
- deltaY: y.deltaY,
821
- deltaAbs: R
834
+ deltaX: v.deltaX,
835
+ deltaY: v.deltaY,
836
+ deltaAbs: k
822
837
  });
823
838
  }
824
839
  });
825
840
  };
826
- document.addEventListener("mouseup", p), document.addEventListener("keydown", g), document.addEventListener("keyup", g), document.addEventListener("mousemove", w);
827
- const b = i.current;
828
- return b?.addEventListener("wheel", T, {
841
+ document.addEventListener("mouseup", f), document.addEventListener("keydown", g), document.addEventListener("keyup", g), document.addEventListener("mousemove", w);
842
+ const x = r.current;
843
+ return x?.addEventListener("wheel", T, {
829
844
  passive: !1
830
845
  }), () => {
831
- document.removeEventListener("mouseup", p), document.removeEventListener("keydown", g), document.removeEventListener("keyup", g), document.removeEventListener("mousemove", w), b?.removeEventListener("wheel", T);
846
+ document.removeEventListener("mouseup", f), document.removeEventListener("keydown", g), document.removeEventListener("keyup", g), document.removeEventListener("mousemove", w), x?.removeEventListener("wheel", T);
832
847
  };
833
- }, [c, a, l, v]), I("sync_move", l, (p) => {
834
- const g = p.positions ? z(
835
- p.positions,
836
- c.current
848
+ }, [i, a, l, y]), L("sync_move", l, (f) => {
849
+ const g = f.positions ? N(
850
+ f.positions,
851
+ i.current
837
852
  ) : null;
838
- m.current = p, M.move.dispatchEvent(a, {
839
- frame: c.current,
853
+ p.current = f, M.move.dispatchEvent(a, {
854
+ frame: i.current,
840
855
  pointer: g ?? null,
841
- keys: p.keys,
842
- source: p.originInteractionsId === a ? "own" : "sync"
856
+ keys: f.keys,
857
+ source: f.originInteractionsId === a ? "own" : "sync"
843
858
  });
844
- }), /* @__PURE__ */ A(
859
+ }), /* @__PURE__ */ R(
845
860
  "div",
846
861
  {
847
- ref: i,
862
+ ref: r,
848
863
  id: e,
849
864
  className: t,
850
865
  style: {
851
866
  position: "absolute",
852
- left: r.chartAreaCSS.x,
853
- top: r.chartAreaCSS.y,
854
- width: r.chartAreaCSS.width,
855
- height: r.chartAreaCSS.height,
867
+ left: c.chartAreaCSS.x,
868
+ top: c.chartAreaCSS.y,
869
+ width: c.chartAreaCSS.width,
870
+ height: c.chartAreaCSS.height,
856
871
  zIndex: 25,
857
872
  ...n
858
873
  },
859
- onDragStart: (p) => {
860
- p.preventDefault();
874
+ onDragStart: (f) => {
875
+ f.preventDefault();
861
876
  },
862
- onClick: (p) => {
863
- f(p, (g, w, T) => {
864
- const b = z(
877
+ onClick: (f) => {
878
+ h(f, (g, w, T) => {
879
+ const x = N(
865
880
  g,
866
- c.current
881
+ i.current
867
882
  );
868
- b && M.click.dispatchEvent(a, {
869
- pointer: b,
870
- frame: c.current,
883
+ x && M.click.dispatchEvent(a, {
884
+ pointer: x,
885
+ frame: i.current,
871
886
  keys: T
872
887
  });
873
888
  });
874
889
  },
875
- onMouseLeave: (p) => {
876
- f(p, (g, w, T) => {
890
+ onMouseLeave: (f) => {
891
+ h(f, (g, w, T) => {
877
892
  M.sync_move.dispatchEvent(l, {
878
893
  positions: null,
879
894
  keys: T,
@@ -881,8 +896,8 @@ const Tt = ze(({ configuration: e, children: t, style: n, className: s }, o) =>
881
896
  });
882
897
  });
883
898
  },
884
- onMouseMove: (p) => {
885
- f(p, (g, w, T) => {
899
+ onMouseMove: (f) => {
900
+ h(f, (g, w, T) => {
886
901
  M.sync_move.dispatchEvent(l, {
887
902
  positions: g,
888
903
  keys: T,
@@ -890,72 +905,72 @@ const Tt = ze(({ configuration: e, children: t, style: n, className: s }, o) =>
890
905
  });
891
906
  });
892
907
  },
893
- onMouseDown: (p) => {
894
- f(p, (g, { cssX: w, cssY: T }, b) => {
895
- const y = z(
908
+ onMouseDown: (f) => {
909
+ h(f, (g, { cssX: w, cssY: T }, x) => {
910
+ const v = N(
896
911
  g,
897
- c.current
912
+ i.current
898
913
  );
899
- y && (M.mousedown.dispatchEvent(a, {
900
- pointer: y,
901
- frame: c.current,
902
- keys: b
903
- }), d.current = {
914
+ v && (M.mousedown.dispatchEvent(a, {
915
+ pointer: v,
916
+ frame: i.current,
917
+ keys: x
918
+ }), m.current = {
904
919
  xRangeCss: { start: w, end: w },
905
920
  yRangeCss: { start: T, end: T }
906
921
  });
907
922
  });
908
923
  },
909
- onMouseUp: (p) => {
910
- f(p, (g, w, T) => {
911
- const b = z(
924
+ onMouseUp: (f) => {
925
+ h(f, (g, w, T) => {
926
+ const x = N(
912
927
  g,
913
- c.current
928
+ i.current
914
929
  );
915
- if (!b) return;
930
+ if (!x) return;
916
931
  M.mouseup.dispatchEvent(a, {
917
- frame: c.current,
918
- pointer: b,
932
+ frame: i.current,
933
+ pointer: x,
919
934
  keys: T
920
935
  });
921
- const y = h.current;
922
- h.current = null;
923
- const x = d.current;
924
- if (d.current = null, x && y) {
936
+ const v = d.current;
937
+ d.current = null;
938
+ const b = m.current;
939
+ if (m.current = null, b && v) {
925
940
  const S = {
926
- ...y,
941
+ ...v,
927
942
  keys: T,
928
943
  completed: !0
929
944
  };
930
- h.current = null, M.spanselect.dispatchEvent(
945
+ d.current = null, M.spanselect.dispatchEvent(
931
946
  a,
932
947
  S
933
948
  );
934
949
  }
935
950
  });
936
951
  },
937
- onContextMenu: (p) => {
938
- p.preventDefault(), f(p, (g, w, T) => {
939
- const b = z(
952
+ onContextMenu: (f) => {
953
+ f.preventDefault(), h(f, (g, w, T) => {
954
+ const x = N(
940
955
  g,
941
- c.current
956
+ i.current
942
957
  );
943
- b && M.contextmenu.dispatchEvent(a, {
944
- frame: c.current,
945
- pointer: b,
958
+ x && M.contextmenu.dispatchEvent(a, {
959
+ frame: i.current,
960
+ pointer: x,
946
961
  keys: T
947
962
  });
948
963
  });
949
964
  },
950
- onDoubleClick: (p) => {
951
- f(p, (g, w, T) => {
952
- const b = z(
965
+ onDoubleClick: (f) => {
966
+ h(f, (g, w, T) => {
967
+ const x = N(
953
968
  g,
954
- c.current
969
+ i.current
955
970
  );
956
- b && M.dblclick.dispatchEvent(a, {
957
- frame: c.current,
958
- pointer: b,
971
+ x && M.dblclick.dispatchEvent(a, {
972
+ frame: i.current,
973
+ pointer: x,
959
974
  keys: T
960
975
  });
961
976
  });
@@ -963,108 +978,108 @@ const Tt = ze(({ configuration: e, children: t, style: n, className: s }, o) =>
963
978
  children: o
964
979
  }
965
980
  );
966
- }, It = ({ data: e, renderTooltip: t, xScaleId: n }) => {
967
- const [s, o] = O(null);
968
- be("move", (r) => {
969
- o(r);
981
+ }, Kt = ({ data: e, renderTooltip: t, xScaleId: n }) => {
982
+ const [s, o] = z(null);
983
+ xe("move", (c) => {
984
+ o(c);
970
985
  });
971
- const i = G(() => {
986
+ const r = oe(() => {
972
987
  if (!s)
973
988
  return null;
974
- const { frame: r, pointer: c } = s, a = c?.scaled[n];
989
+ const { frame: c, pointer: i } = s, a = i?.scaled[n];
975
990
  if (a === void 0)
976
991
  return null;
977
992
  const l = [];
978
- let d = a;
979
- for (const h of e) {
980
- let m = null, u = 1 / 0;
981
- for (const [v, p] of h.points.entries()) {
982
- if (!he(r, p.x, n) || !he(r, p.y, h.yScaleId))
993
+ let m = a;
994
+ for (const d of e) {
995
+ let p = null, u = 1 / 0;
996
+ for (const [y, f] of d.points.entries()) {
997
+ if (!fe(c, f.x, n) || !fe(c, f.y, d.yScaleId))
983
998
  continue;
984
- const g = Math.abs(p.x - a);
985
- g < u && (u = g, m = v);
999
+ const g = Math.abs(f.x - a);
1000
+ g < u && (u = g, p = y);
986
1001
  }
987
- const f = h.points[m ?? -1];
988
- if (!f || ye(r, u, n, "css") > 30) {
989
- l.push({ seriesId: h.seriesId, y: null });
1002
+ const h = d.points[p ?? -1];
1003
+ if (!h || ge(c, u, n, "css") > 30) {
1004
+ l.push({ seriesId: d.seriesId, y: null });
990
1005
  continue;
991
1006
  }
992
- d = f.x, l.push({
993
- seriesId: h.seriesId,
994
- y: f.y
1007
+ m = h.x, l.push({
1008
+ seriesId: d.seriesId,
1009
+ y: h.y
995
1010
  });
996
1011
  }
997
1012
  return {
998
- frame: r,
999
- x: d,
1013
+ frame: c,
1014
+ x: m,
1000
1015
  points: l
1001
1016
  };
1002
1017
  }, [e, s, n]);
1003
- return t(i);
1004
- }, Lt = ({ makeXStyle: e, makeXClassName: t, makeYStyle: n, makeYClassName: s }) => {
1005
- const [o, i] = O(null);
1006
- if (be("move", (m) => {
1007
- i(m);
1018
+ return t(r);
1019
+ }, Ft = ({ makeXStyle: e, makeXClassName: t, makeYStyle: n, makeYClassName: s }) => {
1020
+ const [o, r] = z(null);
1021
+ if (xe("move", (p) => {
1022
+ r(p);
1008
1023
  }), !o)
1009
1024
  return null;
1010
- const { frame: r, pointer: c } = o, a = c?.cssX ?? null, l = c?.cssY ?? null, d = a ? $(r, a, "css") : 0, h = l ? V(r, l, "css") : 0;
1011
- return /* @__PURE__ */ me(Ke, { children: [
1012
- /* @__PURE__ */ A(
1025
+ const { frame: c, pointer: i } = o, a = i?.cssX ?? null, l = i?.cssY ?? null, m = a ? V(c, a, "css") : 0, d = l ? H(c, l, "css") : 0;
1026
+ return /* @__PURE__ */ pe(Fe, { children: [
1027
+ /* @__PURE__ */ R(
1013
1028
  "div",
1014
1029
  {
1015
- "data-show": !!c,
1030
+ "data-show": !!i,
1016
1031
  className: t?.(o),
1017
1032
  style: {
1018
1033
  position: "absolute",
1019
1034
  left: 0,
1020
1035
  visibility: a === null ? "hidden" : "visible",
1021
- top: r.chartAreaCSS.y,
1022
- height: r.chartAreaCSS.height,
1036
+ top: c.chartAreaCSS.y,
1037
+ height: c.chartAreaCSS.height,
1023
1038
  borderColor: "red",
1024
1039
  borderLeftWidth: "1px",
1025
1040
  borderLeftStyle: "solid",
1026
1041
  pointerEvents: "none",
1027
- opacity: c ? 1 : 0,
1028
- transform: `translateX(${d}px)`,
1042
+ opacity: i ? 1 : 0,
1043
+ transform: `translateX(${m}px)`,
1029
1044
  ...e?.(o)
1030
1045
  }
1031
1046
  }
1032
1047
  ),
1033
- /* @__PURE__ */ A(
1048
+ /* @__PURE__ */ R(
1034
1049
  "div",
1035
1050
  {
1036
1051
  className: s?.(o),
1037
- "data-show": !!c,
1052
+ "data-show": !!i,
1038
1053
  style: {
1039
1054
  position: "absolute",
1040
1055
  visibility: l === null ? "hidden" : "visible",
1041
1056
  top: 0,
1042
1057
  height: 0,
1043
1058
  borderTop: "solid 1px red",
1044
- left: r.chartAreaCSS.x,
1045
- width: r.chartAreaCSS.width,
1059
+ left: c.chartAreaCSS.x,
1060
+ width: c.chartAreaCSS.width,
1046
1061
  pointerEvents: "none",
1047
- opacity: c ? 1 : 0,
1048
- transform: `translateY(${h}px)`,
1062
+ opacity: i ? 1 : 0,
1063
+ transform: `translateY(${d}px)`,
1049
1064
  ...n?.(o)
1050
1065
  }
1051
1066
  }
1052
1067
  )
1053
1068
  ] });
1054
- }, Ut = ({ makeClassName: e, makeStyle: t }) => {
1055
- const [n, s] = O(null);
1056
- be("spanselect", (i) => {
1069
+ }, Yt = ({ makeClassName: e, makeStyle: t }) => {
1070
+ const [n, s] = z(null);
1071
+ xe("spanselect", (r) => {
1057
1072
  s(
1058
- i.mode === "below_threshold" || i.completed ? null : i
1073
+ r.mode === "below_threshold" || r.completed ? null : r
1059
1074
  );
1060
1075
  });
1061
- const o = G(() => {
1076
+ const o = oe(() => {
1062
1077
  if (!n || n.mode === "below_threshold")
1063
1078
  return null;
1064
- const i = n.mode === "y" ? -1 / 0 : n.x.css?.from ?? -1 / 0, r = n.mode === "y" ? 1 / 0 : n.x.css?.to ?? 1 / 0, c = n.mode === "x" ? -1 / 0 : n.y.css?.from ?? -1 / 0, a = n.mode === "x" ? 1 / 0 : n.y.css?.to ?? 1 / 0, l = $(n.frame, i, "css"), d = $(n.frame, r, "css"), h = V(n.frame, c, "css"), m = V(n.frame, a, "css"), u = Math.min(l, d), f = Math.min(h, m), v = Math.abs(d - l), p = Math.abs(m - h);
1065
- return { leftPx: u, topPx: f, widthPx: v, heightPx: p };
1079
+ const r = n.mode === "y" ? -1 / 0 : n.x.css?.from ?? -1 / 0, c = n.mode === "y" ? 1 / 0 : n.x.css?.to ?? 1 / 0, i = n.mode === "x" ? -1 / 0 : n.y.css?.from ?? -1 / 0, a = n.mode === "x" ? 1 / 0 : n.y.css?.to ?? 1 / 0, l = V(n.frame, r, "css"), m = V(n.frame, c, "css"), d = H(n.frame, i, "css"), p = H(n.frame, a, "css"), u = Math.min(l, m), h = Math.min(d, p), y = Math.abs(m - l), f = Math.abs(p - d);
1080
+ return { leftPx: u, topPx: h, widthPx: y, heightPx: f };
1066
1081
  }, [n]);
1067
- return /* @__PURE__ */ A(
1082
+ return /* @__PURE__ */ R(
1068
1083
  "div",
1069
1084
  {
1070
1085
  className: n ? e?.(n) : void 0,
@@ -1080,9 +1095,9 @@ const Tt = ze(({ configuration: e, children: t, style: n, className: s }, o) =>
1080
1095
  }
1081
1096
  }
1082
1097
  );
1083
- }, _t = ({ style: e, children: t, scaleId: n, ...s }) => {
1084
- const o = ge().getScale(n)?.axis;
1085
- return o ? /* @__PURE__ */ A(
1098
+ }, zt = ({ style: e, children: t, scaleId: n, ...s }) => {
1099
+ const o = De().getScale(n)?.axis;
1100
+ return o ? /* @__PURE__ */ R(
1086
1101
  "div",
1087
1102
  {
1088
1103
  style: {
@@ -1098,32 +1113,32 @@ const Tt = ze(({ configuration: e, children: t, style: n, className: s }, o) =>
1098
1113
  children: t
1099
1114
  }
1100
1115
  ) : null;
1101
- }, De = 60, nt = 30, Ie = "UTC", st = "en-GB", Xt = ({
1116
+ }, Ie = 60, lt = 30, Le = "UTC", ut = "en-GB", Bt = ({
1102
1117
  space: e,
1103
1118
  formatter: t,
1104
1119
  acceptableIncrements: n
1105
1120
  } = {}) => (s, o) => {
1106
- const { min: i, max: r } = s, c = [], a = window.devicePixelRatio || 1, l = (e ?? (s.origin === "x" ? De : nt)) * a, d = $e(
1121
+ const { min: r, max: c } = s, i = [], a = window.devicePixelRatio || 1, l = (e ?? (s.origin === "x" ? Ie : lt)) * a, m = je(
1107
1122
  o,
1108
1123
  l,
1109
1124
  s.id,
1110
1125
  "canvas"
1111
- ), h = n ?? Q, m = h.find((f) => f > d) ?? h.at(-1) ?? 1;
1112
- let u = i;
1113
- if (Math.abs(u % m) > Number.EPSILON) {
1114
- const f = (m - u % m) % m;
1115
- u += f;
1126
+ ), d = n ?? ee, p = d.find((h) => h > m) ?? d.at(-1) ?? 1;
1127
+ let u = r;
1128
+ if (Math.abs(u % p) > Number.EPSILON) {
1129
+ const h = (p - u % p) % p;
1130
+ u += h;
1116
1131
  }
1117
- for (; u <= r && c.length < 1e3; )
1118
- c.push(u), u += m;
1119
- return (t ?? ot)(c);
1120
- }, ot = (e) => {
1132
+ for (; u <= c && i.length < 1e3; )
1133
+ i.push(u), u += p;
1134
+ return (t ?? ht)(i);
1135
+ }, ht = (e) => {
1121
1136
  const t = Math.max(0, Math.ceil(-Math.log10(e[1] - e[0])));
1122
1137
  return e.map((n) => ({ value: n, label: n.toFixed(t) }));
1123
- }, Q = [];
1138
+ }, ee = [];
1124
1139
  for (let e = -12; e <= 12; e++)
1125
- Q.push(1 * 10 ** e), Q.push(2 * 10 ** e), Q.push(5 * 10 ** e);
1126
- const it = 1, Le = 1e3 * it, xe = 60 * Le, se = 60 * xe, oe = 24 * se, rt = 30 * oe, ct = 365 * oe, at = [
1140
+ ee.push(1 * 10 ** e), ee.push(2 * 10 ** e), ee.push(5 * 10 ** e);
1141
+ const dt = 1, Ue = 1e3 * dt, be = 60 * Ue, se = 60 * be, re = 24 * se, ft = 30 * re, mt = 365 * re, pt = [
1127
1142
  // second divisors
1128
1143
  [1, "milliseconds"],
1129
1144
  [2, "milliseconds"],
@@ -1175,93 +1190,93 @@ const it = 1, Le = 1e3 * it, xe = 60 * Le, se = 60 * xe, oe = 24 * se, rt = 30 *
1175
1190
  [25, "years"],
1176
1191
  [50, "years"],
1177
1192
  [100, "years"]
1178
- ], ee = (e) => {
1193
+ ], te = (e) => {
1179
1194
  const [t, n] = e;
1180
1195
  switch (n) {
1181
1196
  case "milliseconds":
1182
1197
  return t;
1183
1198
  case "seconds":
1184
- return t * Le;
1199
+ return t * Ue;
1185
1200
  case "minutes":
1186
- return t * xe;
1201
+ return t * be;
1187
1202
  case "hours":
1188
1203
  return t * se;
1189
1204
  case "days":
1190
- return t * oe;
1205
+ return t * re;
1191
1206
  case "months":
1192
- return t * rt;
1207
+ return t * ft;
1193
1208
  case "years":
1194
- return t * ct;
1209
+ return t * mt;
1195
1210
  }
1196
- }, lt = (e, t) => {
1211
+ }, yt = (e, t) => {
1197
1212
  const n = new Date(e);
1198
1213
  return n.setUTCMilliseconds(n.getUTCMilliseconds() + t), n.getTime();
1199
- }, ut = (e, t) => {
1214
+ }, gt = (e, t) => {
1200
1215
  const n = new Date(e);
1201
1216
  return n.setUTCSeconds(n.getUTCSeconds() + t), n.getTime();
1202
- }, dt = (e, t) => {
1217
+ }, vt = (e, t) => {
1203
1218
  const n = new Date(e);
1204
1219
  return n.setUTCMinutes(n.getUTCMinutes() + t), n.getTime();
1205
- }, ht = (e, t) => {
1220
+ }, wt = (e, t) => {
1206
1221
  const n = new Date(e);
1207
1222
  return n.setUTCHours(n.getUTCHours() + t), n.getTime();
1208
- }, ft = (e, t) => {
1223
+ }, xt = (e, t) => {
1209
1224
  const n = new Date(e);
1210
1225
  return n.setUTCDate(n.getUTCDate() + t), n.getTime();
1211
1226
  }, Me = (e, t) => {
1212
1227
  const n = new Date(e);
1213
1228
  return n.setUTCMonth(n.getUTCMonth() + t), n.getTime();
1214
- }, K = (e, t) => {
1229
+ }, Y = (e, t) => {
1215
1230
  const [n, s] = t;
1216
1231
  switch (s) {
1217
1232
  case "milliseconds":
1218
- return lt(e, n);
1233
+ return yt(e, n);
1219
1234
  case "seconds":
1220
- return ut(e, n);
1235
+ return gt(e, n);
1221
1236
  case "minutes":
1222
- return dt(e, n);
1237
+ return vt(e, n);
1223
1238
  case "hours":
1224
- return ht(e, n);
1239
+ return wt(e, n);
1225
1240
  case "days":
1226
- return ft(e, n);
1241
+ return xt(e, n);
1227
1242
  case "months":
1228
1243
  return Me(e, n);
1229
1244
  case "years":
1230
1245
  return Me(e, n * 12);
1231
1246
  }
1232
1247
  };
1233
- function te(e, t) {
1248
+ function ne(e, t) {
1234
1249
  const n = new Date(e), s = new Date(n.toLocaleString("en-US", { timeZone: t })), o = new Date(n.toLocaleString("en-US", { timeZone: "UTC" }));
1235
1250
  return (s.getTime() - o.getTime()) / (3600 * 1e3);
1236
1251
  }
1237
- const mt = (e, t, n = "UTC") => {
1252
+ const bt = (e, t, n = "UTC") => {
1238
1253
  const [s, o] = t;
1239
- let i = new Date(e);
1240
- const r = () => {
1241
- i.setUTCHours(-te(i, n), 0, 0, 0);
1254
+ let r = new Date(e);
1255
+ const c = () => {
1256
+ r.setUTCHours(-ne(r, n), 0, 0, 0);
1242
1257
  };
1243
1258
  switch (o) {
1244
1259
  case "milliseconds":
1245
- i.setUTCMilliseconds(
1246
- Math.ceil(i.getUTCMilliseconds() / s) * s
1260
+ r.setUTCMilliseconds(
1261
+ Math.ceil(r.getUTCMilliseconds() / s) * s
1247
1262
  );
1248
1263
  break;
1249
1264
  case "seconds":
1250
- i.setUTCSeconds(
1251
- Math.ceil(i.getUTCSeconds() / s) * s,
1265
+ r.setUTCSeconds(
1266
+ Math.ceil(r.getUTCSeconds() / s) * s,
1252
1267
  0
1253
1268
  );
1254
1269
  break;
1255
1270
  case "minutes":
1256
- i.setUTCMinutes(
1257
- Math.ceil(i.getTime() % se / xe / s) * s,
1271
+ r.setUTCMinutes(
1272
+ Math.ceil(r.getTime() % se / be / s) * s,
1258
1273
  0,
1259
1274
  0
1260
1275
  );
1261
1276
  break;
1262
1277
  case "hours":
1263
- i.setUTCHours(
1264
- Math.ceil(i.getTime() % oe / se / s) * s,
1278
+ r.setUTCHours(
1279
+ Math.ceil(r.getTime() % re / se / s) * s,
1265
1280
  0,
1266
1281
  0,
1267
1282
  0
@@ -1270,20 +1285,20 @@ const mt = (e, t, n = "UTC") => {
1270
1285
  case "days":
1271
1286
  case "months":
1272
1287
  case "years":
1273
- o === "months" ? i.setUTCDate(1) : o === "years" && i.setUTCMonth(0, 1), r(), i.getTime() < e && (i = new Date(K(i, [1, o])));
1288
+ o === "months" ? r.setUTCDate(1) : o === "years" && r.setUTCMonth(0, 1), c(), r.getTime() < e && (r = new Date(Y(r, [1, o])));
1274
1289
  break;
1275
1290
  }
1276
- return i.getTime();
1277
- }, Ft = ({
1278
- timeZone: e = Ie,
1279
- space: t = De,
1291
+ return r.getTime();
1292
+ }, Nt = ({
1293
+ timeZone: e = Le,
1294
+ space: t = Ie,
1280
1295
  formatter: n,
1281
1296
  locale: s,
1282
1297
  showTimezone: o
1283
- } = {}) => (i, r) => {
1284
- const { min: c, max: a } = i, l = Math.floor(r.chartAreaCanvasPX.width / t) + 1, h = (a - c) / l, [m, u] = at.find(
1285
- (w) => ee(w) >= h
1286
- ) ?? [1, "milliseconds"], f = mt(c, [m, u], e), v = te(f, e), p = [f];
1298
+ } = {}) => (r, c) => {
1299
+ const { min: i, max: a } = r, l = Math.floor(c.chartAreaCanvasPX.width / t) + 1, d = (a - i) / l, [p, u] = pt.find(
1300
+ (w) => te(w) >= d
1301
+ ) ?? [1, "milliseconds"], h = bt(i, [p, u], e), y = ne(h, e), f = [h];
1287
1302
  let g;
1288
1303
  for (; ; ) {
1289
1304
  switch (u) {
@@ -1291,31 +1306,31 @@ const mt = (e, t, n = "UTC") => {
1291
1306
  case "seconds":
1292
1307
  case "minutes":
1293
1308
  case "hours": {
1294
- g = K(f, [p.length * m, u]);
1309
+ g = Y(h, [f.length * p, u]);
1295
1310
  break;
1296
1311
  }
1297
1312
  case "days": {
1298
- const w = K(f, [
1299
- p.length * m,
1313
+ const w = Y(h, [
1314
+ f.length * p,
1300
1315
  u
1301
1316
  ]);
1302
- g = K(w, [
1303
- v - te(w, e),
1317
+ g = Y(w, [
1318
+ y - ne(w, e),
1304
1319
  "hours"
1305
1320
  ]);
1306
1321
  break;
1307
1322
  }
1308
1323
  case "months":
1309
1324
  case "years": {
1310
- const w = K(
1311
- K(K(f, [v, "hours"]), [
1312
- p.length * m,
1325
+ const w = Y(
1326
+ Y(Y(h, [y, "hours"]), [
1327
+ f.length * p,
1313
1328
  u
1314
1329
  ]),
1315
- [-v, "hours"]
1330
+ [-y, "hours"]
1316
1331
  );
1317
- g = K(w, [
1318
- v - te(w, e),
1332
+ g = Y(w, [
1333
+ y - ne(w, e),
1319
1334
  "hours"
1320
1335
  ]);
1321
1336
  break;
@@ -1323,16 +1338,16 @@ const mt = (e, t, n = "UTC") => {
1323
1338
  }
1324
1339
  if (g > a)
1325
1340
  break;
1326
- p.push(g);
1341
+ f.push(g);
1327
1342
  }
1328
- return (n ?? pt({
1343
+ return (n ?? Tt({
1329
1344
  locale: s,
1330
1345
  showTimezone: o,
1331
1346
  timeZone: e
1332
- }))(p);
1333
- }, F = (e, t, n) => e.find((s) => s.type === n)?.value !== t.find((s) => s.type === n)?.value, pt = ({
1334
- timeZone: e = Ie,
1335
- locale: t = st,
1347
+ }))(f);
1348
+ }, F = (e, t, n) => e.find((s) => s.type === n)?.value !== t.find((s) => s.type === n)?.value, Tt = ({
1349
+ timeZone: e = Le,
1350
+ locale: t = ut,
1336
1351
  showTimezone: n = !0
1337
1352
  }) => {
1338
1353
  const s = new Intl.DateTimeFormat(t, {
@@ -1348,71 +1363,71 @@ const mt = (e, t, n = "UTC") => {
1348
1363
  timeZone: e
1349
1364
  });
1350
1365
  return (o) => {
1351
- const i = o[1] - o[0], r = i < ee([1, "days"]), c = i < ee([1, "minutes"]), a = i < ee([1, "seconds"]);
1352
- return o.map((l) => ({ value: l, label: s.formatToParts(new Date(l)) })).map((l, d, h) => {
1353
- const m = h[d - 1], u = d === 0 || F(l.label, m.label, "year"), f = d === 0 || F(l.label, m.label, "day"), v = d === 0 || F(l.label, m.label, "month"), p = d === 0 || F(l.label, m.label, "hour"), g = d === 0 || F(l.label, m.label, "timeZoneName"), w = d === 0 || F(l.label, m.label, "minute"), T = d === 0 || F(l.label, m.label, "second"), b = d === 0 || F(l.label, m.label, "fractionalSecond"), y = [];
1354
- if (r && (p || w || g || T || b)) {
1355
- const x = l.label.find((P) => P.type === "hour")?.value, S = l.label.find((P) => P.type === "minute")?.value, E = l.label.find((P) => P.type === "timeZoneName")?.value;
1366
+ const r = o[1] - o[0], c = r < te([1, "days"]), i = r < te([1, "minutes"]), a = r < te([1, "seconds"]);
1367
+ return o.map((l) => ({ value: l, label: s.formatToParts(new Date(l)) })).map((l, m, d) => {
1368
+ const p = d[m - 1], u = m === 0 || F(l.label, p.label, "year"), h = m === 0 || F(l.label, p.label, "day"), y = m === 0 || F(l.label, p.label, "month"), f = m === 0 || F(l.label, p.label, "hour"), g = m === 0 || F(l.label, p.label, "timeZoneName"), w = m === 0 || F(l.label, p.label, "minute"), T = m === 0 || F(l.label, p.label, "second"), x = m === 0 || F(l.label, p.label, "fractionalSecond"), v = [];
1369
+ if (c && (f || w || g || T || x)) {
1370
+ const b = l.label.find((P) => P.type === "hour")?.value, S = l.label.find((P) => P.type === "minute")?.value, E = l.label.find((P) => P.type === "timeZoneName")?.value;
1356
1371
  let C = "";
1357
- if (c) {
1358
- const P = l.label.find((Y) => Y.type === "second")?.value, R = l.label.find(
1359
- (Y) => Y.type === "fractionalSecond"
1372
+ if (i) {
1373
+ const P = l.label.find((B) => B.type === "second")?.value, k = l.label.find(
1374
+ (B) => B.type === "fractionalSecond"
1360
1375
  )?.value;
1361
- C = `:${P}` + (a ? `.${R}` : "");
1376
+ C = `:${P}` + (a ? `.${k}` : "");
1362
1377
  }
1363
- y.push(
1364
- `${x}:${S}${C}` + (n && g ? ` ${E}` : "")
1378
+ v.push(
1379
+ `${b}:${S}${C}` + (n && g ? ` ${E}` : "")
1365
1380
  );
1366
1381
  }
1367
- return (f || v) && y.push(
1382
+ return (h || y) && v.push(
1368
1383
  [
1369
- l.label.find((x) => x.type === "month")?.value,
1370
- f && l.label.find((x) => x.type === "day")?.value
1384
+ l.label.find((b) => b.type === "month")?.value,
1385
+ h && l.label.find((b) => b.type === "day")?.value
1371
1386
  ].filter(Boolean).join(" ")
1372
- ), u && y.push(l.label.find((x) => x.type === "year")?.value), {
1387
+ ), u && v.push(l.label.find((b) => b.type === "year")?.value), {
1373
1388
  value: l.value,
1374
- label: y.filter((x) => x).join(`
1389
+ label: v.filter((b) => b).join(`
1375
1390
  `)
1376
1391
  };
1377
1392
  });
1378
1393
  };
1379
1394
  };
1380
1395
  export {
1381
- Mt as AreaPlot,
1382
- _t as AxisOverlay,
1383
- Pt as BarPlot,
1384
- ke as CANPLOT_LAYER,
1385
- Tt as CanPlot,
1386
- Dt as ChartAreaInteractions,
1387
- Lt as Crosshair,
1388
- Ae as FrameDrawer,
1389
- St as LinePlot,
1390
- Ct as ScatterPlot,
1391
- Ut as SelectBox,
1392
- Et as SparklinePlot,
1393
- It as TooltipsX,
1394
- kt as XTicks,
1395
- At as YTicks,
1396
- L as applyStyles,
1397
- W as clamp,
1398
- xt as clampUnfit,
1399
- $ as clampXPosToChartArea,
1400
- V as clampYPosToChartArea,
1401
- ot as defaultNumericalTicksFormatter,
1402
- bt as findClosestIndex,
1403
- _ as getScale,
1404
- Xt as makeLinearTicks,
1405
- pt as makeTimeTickFormat,
1406
- Ft as makeTimeTicks,
1407
- U as posToVal,
1408
- $e as pxToValDistance,
1409
- wt as sum,
1410
- N as useDrawEffect,
1411
- ge as useFrameState,
1412
- be as useInteractionsEvent,
1413
- Rt as useXPositioned,
1414
- he as valFits,
1415
- q as valToPos,
1416
- ye as valToPxDistance
1396
+ Lt as AreaPlot,
1397
+ zt as AxisOverlay,
1398
+ It as BarPlot,
1399
+ Ae as CANPLOT_LAYER,
1400
+ At as CanPlot,
1401
+ Ot as ChartAreaInteractions,
1402
+ Ft as Crosshair,
1403
+ Re as FrameDrawer,
1404
+ Rt as LinePlot,
1405
+ Dt as ScatterPlot,
1406
+ Yt as SelectBox,
1407
+ Ut as SparklinePlot,
1408
+ Kt as TooltipsX,
1409
+ _t as XTicks,
1410
+ Xt as YTicks,
1411
+ U as applyStyles,
1412
+ G as clamp,
1413
+ kt as clampUnfit,
1414
+ V as clampXPosToChartArea,
1415
+ H as clampYPosToChartArea,
1416
+ O as deepEqual,
1417
+ ht as defaultNumericalTicksFormatter,
1418
+ Et as findClosestIndex,
1419
+ X as getScale,
1420
+ Bt as makeLinearTicks,
1421
+ Tt as makeTimeTickFormat,
1422
+ Nt as makeTimeTicks,
1423
+ _ as posToVal,
1424
+ je as pxToValDistance,
1425
+ Mt as sum,
1426
+ j as useDrawEffect,
1427
+ De as useFrameState,
1428
+ xe as useInteractionsEvent,
1429
+ fe as valFits,
1430
+ Z as valToPos,
1431
+ ge as valToPxDistance
1417
1432
  };
1418
1433
  //# sourceMappingURL=canplot.mjs.map