@canplot/react 0.5.2 → 0.5.3

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,8 +1,8 @@
1
- var Ye = Object.defineProperty;
2
- var Be = (e, t, n) => t in e ? Ye(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
3
- var F = (e, t, n) => Be(e, typeof t != "symbol" ? t + "" : t, n);
4
- import { jsxs as pe, jsx as R, Fragment as ze } from "react/jsx-runtime";
5
- import D, { version as Ne, createContext as ye, forwardRef as $e, useRef as k, useState as B, useMemo as Z, useLayoutEffect as $, useCallback as je, useContext as q, useId as Ve, useEffect as He } from "react";
1
+ var Be = Object.defineProperty;
2
+ var ze = (e, t, n) => t in e ? Be(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
3
+ var F = (e, t, n) => ze(e, typeof t != "symbol" ? t + "" : t, n);
4
+ import { jsxs as pe, jsx as R, Fragment as Ne } from "react/jsx-runtime";
5
+ import D, { version as $e, createContext as ye, forwardRef as je, useRef as k, useState as B, useMemo as Z, useLayoutEffect as $, useCallback as Ve, useContext as q, useEffect as ke, useId as He } from "react";
6
6
  const re = (e, t, n) => Math.min(Math.max(e, t), n), kt = (e) => e.reduce((t, n) => t + (n ?? 0), 0), Rt = (e, t) => {
7
7
  let n = 0;
8
8
  for (let s = 0; s < e.length; s++)
@@ -124,8 +124,8 @@ function me(e, t) {
124
124
  return e(t);
125
125
  e && (e.current = t);
126
126
  }
127
- var Je = parseInt(Ne.split(".")[0], 10) >= 19 ? Ze : Ge;
128
- const ke = ye({
127
+ var Je = parseInt($e.split(".")[0], 10) >= 19 ? Ze : Ge;
128
+ const Re = ye({
129
129
  listeners: [],
130
130
  subscribe: () => () => {
131
131
  },
@@ -140,14 +140,14 @@ const ke = ye({
140
140
  for (const [, s] of e)
141
141
  s();
142
142
  } };
143
- }, ve = ye(null), Re = ye(() => {
144
- }), De = {
143
+ }, ve = ye(null), De = ye(() => {
144
+ }), Ie = {
145
145
  TOP: 400,
146
146
  MIDDLE: 300,
147
147
  BOTTOM: 200,
148
148
  BACKGROUND: 100
149
149
  };
150
- class Ie {
150
+ class Le {
151
151
  constructor() {
152
152
  F(this, "_frame", null);
153
153
  F(this, "clampXPosToChartArea", (t, n = "canvas") => V(this.frame, t, n));
@@ -169,7 +169,7 @@ class Ie {
169
169
  return this.frame.ctx;
170
170
  }
171
171
  }
172
- const Dt = $e(({ configuration: e, children: t, style: n, className: s }, o) => {
172
+ const Dt = je(({ configuration: e, children: t, style: n, className: s }, o) => {
173
173
  const r = k(null), i = k(null), c = tt(i), [l, u] = B(null), f = Z(
174
174
  () => nt(e, c, l),
175
175
  [e, c, l]
@@ -220,7 +220,7 @@ const Dt = $e(({ configuration: e, children: t, style: n, className: s }, o) =>
220
220
  r.current = e, $(() => {
221
221
  n.subscribe(() => {
222
222
  r.current && qe(r.current);
223
- }, De.BOTTOM);
223
+ }, Ie.BOTTOM);
224
224
  }, [n]), $(() => {
225
225
  let c = null;
226
226
  return c = window.requestAnimationFrame(() => {
@@ -229,10 +229,10 @@ const Dt = $e(({ configuration: e, children: t, style: n, className: s }, o) =>
229
229
  c && cancelAnimationFrame(c);
230
230
  };
231
231
  }, [s, e, n]);
232
- const i = je(() => {
232
+ const i = Ve(() => {
233
233
  o((c) => c + 1);
234
234
  }, [o]);
235
- return /* @__PURE__ */ R(ke.Provider, { value: n, children: /* @__PURE__ */ R(Re.Provider, { value: i, children: /* @__PURE__ */ R(ve.Provider, { value: e, children: t }) }) });
235
+ return /* @__PURE__ */ R(Re.Provider, { value: n, children: /* @__PURE__ */ R(De.Provider, { value: i, children: /* @__PURE__ */ R(ve.Provider, { value: e, children: t }) }) });
236
236
  }, tt = (e) => {
237
237
  const [t, n] = B({
238
238
  width: 0,
@@ -350,28 +350,35 @@ const Dt = $e(({ configuration: e, children: t, style: n, className: s }, o) =>
350
350
  chartAreaCanvasPX: r
351
351
  };
352
352
  }, j = (e, t, n) => {
353
- const s = q(ve), o = q(Re), r = q(ke);
353
+ const s = q(ve), o = q(De), r = q(Re);
354
354
  if (!s || !o)
355
355
  throw new Error("useFrame must be used within a CanPlot component");
356
- const [i] = B(() => new Ie());
356
+ const [i] = B(() => new Le());
357
357
  i._updateFrame(s);
358
358
  const c = k(i);
359
359
  c.current = i;
360
360
  const l = k(t);
361
- l.current = t, $(() => r.subscribe(
362
- () => {
363
- l.current(i);
364
- },
365
- typeof e == "number" ? e : De[e]
366
- ), [r, e, i]), $(() => {
361
+ l.current = t, $(() => {
362
+ const u = r.subscribe(
363
+ () => {
364
+ l.current(i);
365
+ },
366
+ typeof e == "number" ? e : Ie[e]
367
+ );
368
+ return () => {
369
+ u();
370
+ };
371
+ }, [r, e, i]), $(() => {
367
372
  o();
368
- }, [o, ...n]);
369
- }, Le = () => {
373
+ }, [o, ...n]), ke(() => () => {
374
+ o();
375
+ }, [o]);
376
+ }, Ue = () => {
370
377
  const e = q(ve);
371
378
  if (!e)
372
379
  throw new Error("useFrame must be used within a CanPlot component");
373
380
  return Z(() => {
374
- const t = new Ie();
381
+ const t = new Le();
375
382
  return t._updateFrame(e), t;
376
383
  }, [e]);
377
384
  }, st = ({ layer: e = "MIDDLE", data: t, xScaleId: n, yScaleId: s, style: o }) => (j(
@@ -564,7 +571,7 @@ const Dt = $e(({ configuration: e, children: t, style: n, className: s }, o) =>
564
571
  ...n,
565
572
  ...s,
566
573
  // alter font size for DPR
567
- font: Ue(s?.font ?? n?.font)
574
+ font: _e(s?.font ?? n?.font)
568
575
  });
569
576
  for (const { value: b, label: v } of x) {
570
577
  const T = l(b, t, "canvas");
@@ -603,7 +610,7 @@ const Dt = $e(({ configuration: e, children: t, style: n, className: s }, o) =>
603
610
  ...n,
604
611
  ...s,
605
612
  // alter font size for DPR
606
- font: Ue(s?.font ?? n?.font)
613
+ font: _e(s?.font ?? n?.font)
607
614
  });
608
615
  for (const { value: x, label: b } of w) {
609
616
  const v = l(x, t, "canvas");
@@ -617,7 +624,7 @@ const Dt = $e(({ configuration: e, children: t, style: n, className: s }, o) =>
617
624
  c.restore();
618
625
  },
619
626
  [i, t, n, s]
620
- ), null), Ft = D.memo(lt, O), Ue = (e) => {
627
+ ), null), Ft = D.memo(lt, O), _e = (e) => {
621
628
  if (e)
622
629
  try {
623
630
  return e.replace(/(\d+)px/, (t, n) => `${parseInt(n) * window.devicePixelRatio || 1}px`);
@@ -732,7 +739,7 @@ const Dt = $e(({ configuration: e, children: t, style: n, className: s }, o) =>
732
739
  innerChildren: a,
733
740
  children: p
734
741
  }) => {
735
- const h = Ve();
742
+ const h = He();
736
743
  return L("dblclick", h, (y) => {
737
744
  n?.(y);
738
745
  }), L("click", h, (y) => {
@@ -763,7 +770,7 @@ const Dt = $e(({ configuration: e, children: t, style: n, className: s }, o) =>
763
770
  p
764
771
  ] });
765
772
  }, ht = ({ id: e, className: t, style: n, sync: s, children: o }) => {
766
- const r = k(null), i = Le().frame, c = k(i);
773
+ const r = k(null), i = Ue().frame, c = k(i);
767
774
  c.current = i;
768
775
  const l = q(we), u = s?.key || l, f = k(null), m = k(null), a = k(null), p = () => {
769
776
  const d = r.current?.parentElement;
@@ -793,7 +800,7 @@ const Dt = $e(({ configuration: e, children: t, style: n, className: s }, o) =>
793
800
  }
794
801
  );
795
802
  }, y = k(h);
796
- return y.current = h, He(() => {
803
+ return y.current = h, ke(() => {
797
804
  const d = (v) => {
798
805
  const T = m.current;
799
806
  T && M.spanselect.dispatchEvent(l, {
@@ -882,7 +889,7 @@ const Dt = $e(({ configuration: e, children: t, style: n, className: s }, o) =>
882
889
  "y",
883
890
  { scaleId: Q.id, from: Se, to: Pe },
884
891
  c.current
885
- ), Fe = ee?.scaled, Ke = te?.scaled, Me = {
892
+ ), Ke = ee?.scaled, Ye = te?.scaled, Me = {
886
893
  mode: W,
887
894
  frame: c.current,
888
895
  completed: !1,
@@ -891,14 +898,14 @@ const Dt = $e(({ configuration: e, children: t, style: n, className: s }, o) =>
891
898
  from: ee.fromCSS,
892
899
  to: ee.toCSS
893
900
  } : void 0,
894
- scaled: Fe ?? []
901
+ scaled: Ke ?? []
895
902
  },
896
903
  y: {
897
904
  css: te ? {
898
905
  from: te.fromCSS,
899
906
  to: te.toCSS
900
907
  } : void 0,
901
- scaled: Ke ?? []
908
+ scaled: Ye ?? []
902
909
  },
903
910
  keys: S
904
911
  };
@@ -1114,7 +1121,7 @@ const Dt = $e(({ configuration: e, children: t, style: n, className: s }, o) =>
1114
1121
  }), !o)
1115
1122
  return null;
1116
1123
  const { frame: i, pointer: c } = o, l = c?.cssX ?? null, u = c?.cssY ?? null, f = l ? V(i, l, "css") : 0, m = u ? H(i, u, "css") : 0;
1117
- return /* @__PURE__ */ pe(ze, { children: [
1124
+ return /* @__PURE__ */ pe(Ne, { children: [
1118
1125
  /* @__PURE__ */ R(
1119
1126
  "div",
1120
1127
  {
@@ -1187,7 +1194,7 @@ const Dt = $e(({ configuration: e, children: t, style: n, className: s }, o) =>
1187
1194
  }
1188
1195
  );
1189
1196
  }, Nt = ({ style: e, children: t, scaleId: n, ...s }) => {
1190
- const o = Le().getScale(n)?.axis;
1197
+ const o = Ue().getScale(n)?.axis;
1191
1198
  return o ? /* @__PURE__ */ R(
1192
1199
  "div",
1193
1200
  {
@@ -1204,12 +1211,12 @@ const Dt = $e(({ configuration: e, children: t, style: n, className: s }, o) =>
1204
1211
  children: t
1205
1212
  }
1206
1213
  ) : null;
1207
- }, _e = 60, dt = 30, Xe = "UTC", ft = "en-GB", $t = ({
1214
+ }, Xe = 60, dt = 30, Oe = "UTC", ft = "en-GB", $t = ({
1208
1215
  space: e,
1209
1216
  formatter: t,
1210
1217
  acceptableIncrements: n
1211
1218
  } = {}) => (s, o) => {
1212
- const { min: r, max: i } = s, c = [], l = window.devicePixelRatio || 1, u = (e ?? (s.origin === "x" ? _e : dt)) * l, f = We(
1219
+ const { min: r, max: i } = s, c = [], l = window.devicePixelRatio || 1, u = (e ?? (s.origin === "x" ? Xe : dt)) * l, f = We(
1213
1220
  o,
1214
1221
  u,
1215
1222
  s.id,
@@ -1232,7 +1239,7 @@ const Dt = $e(({ configuration: e, children: t, style: n, className: s }, o) =>
1232
1239
  }, ne = [];
1233
1240
  for (let e = -12; e <= 12; e++)
1234
1241
  ne.push(1 * 10 ** e), ne.push(2 * 10 ** e), ne.push(5 * 10 ** e);
1235
- const pt = 1, Oe = 1e3 * pt, be = 60 * Oe, ie = 60 * be, ce = 24 * ie, yt = 30 * ce, gt = 365 * ce, vt = [
1242
+ const pt = 1, Fe = 1e3 * pt, be = 60 * Fe, ie = 60 * be, ce = 24 * ie, yt = 30 * ce, gt = 365 * ce, vt = [
1236
1243
  // second divisors
1237
1244
  [1, "milliseconds"],
1238
1245
  [2, "milliseconds"],
@@ -1290,7 +1297,7 @@ const pt = 1, Oe = 1e3 * pt, be = 60 * Oe, ie = 60 * be, ce = 24 * ie, yt = 30 *
1290
1297
  case "milliseconds":
1291
1298
  return t;
1292
1299
  case "seconds":
1293
- return t * Oe;
1300
+ return t * Fe;
1294
1301
  case "minutes":
1295
1302
  return t * be;
1296
1303
  case "hours":
@@ -1384,8 +1391,8 @@ const St = (e, t, n = "UTC") => {
1384
1391
  }
1385
1392
  return r.getTime();
1386
1393
  }, jt = ({
1387
- timeZone: e = Xe,
1388
- space: t = _e,
1394
+ timeZone: e = Oe,
1395
+ space: t = Xe,
1389
1396
  formatter: n,
1390
1397
  locale: s,
1391
1398
  showTimezone: o
@@ -1440,7 +1447,7 @@ const St = (e, t, n = "UTC") => {
1440
1447
  timeZone: e
1441
1448
  }))(d);
1442
1449
  }, K = (e, t, n) => e.find((s) => s.type === n)?.value !== t.find((s) => s.type === n)?.value, Pt = ({
1443
- timeZone: e = Xe,
1450
+ timeZone: e = Oe,
1444
1451
  locale: t = ft,
1445
1452
  showTimezone: n = !0
1446
1453
  }) => {
@@ -1490,11 +1497,11 @@ export {
1490
1497
  _t as AreaPlot,
1491
1498
  Nt as AxisOverlay,
1492
1499
  Ut as BarPlot,
1493
- De as CANPLOT_LAYER,
1500
+ Ie as CANPLOT_LAYER,
1494
1501
  Dt as CanPlot,
1495
1502
  Kt as ChartAreaInteractions,
1496
1503
  Bt as Crosshair,
1497
- Ie as FrameDrawer,
1504
+ Le as FrameDrawer,
1498
1505
  It as LinePlot,
1499
1506
  Lt as ScatterPlot,
1500
1507
  zt as SelectBox,
@@ -1517,7 +1524,7 @@ export {
1517
1524
  We as pxToValDistance,
1518
1525
  kt as sum,
1519
1526
  j as useDrawEffect,
1520
- Le as useFrameState,
1527
+ Ue as useFrameState,
1521
1528
  xe as useInteractionsEvent,
1522
1529
  fe as valFits,
1523
1530
  G as valToPos,