@validationcloud/fractal-ui 1.77.0 → 1.78.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.
Files changed (33) hide show
  1. package/README.md +22 -0
  2. package/dist/charts.d.ts +2 -0
  3. package/dist/charts.js +29 -20
  4. package/dist/components/dropdown-menu/dropdown-menu.js +34 -26
  5. package/dist/components/echarts-renderer/geo/africa-countries.json.d.ts +2463 -0
  6. package/dist/components/echarts-renderer/geo/africa-countries.json.js +9 -0
  7. package/dist/components/echarts-renderer/geo/americas-countries.json.d.ts +4160 -0
  8. package/dist/components/echarts-renderer/geo/americas-countries.json.js +9 -0
  9. package/dist/components/echarts-renderer/geo/asia-countries.json.d.ts +4275 -0
  10. package/dist/components/echarts-renderer/geo/asia-countries.json.js +9 -0
  11. package/dist/components/echarts-renderer/geo/europe-countries.json.d.ts +2407 -0
  12. package/dist/components/echarts-renderer/geo/europe-countries.json.js +9 -0
  13. package/dist/components/echarts-renderer/geo/us-states.json.d.ts +1338 -0
  14. package/dist/components/echarts-renderer/geo/us-states.json.js +9 -0
  15. package/dist/components/echarts-renderer/geo/world-continents.json.d.ts +10639 -0
  16. package/dist/components/echarts-renderer/geo/world-continents.json.js +9 -0
  17. package/dist/components/echarts-renderer/geo/world-countries.json.d.ts +14549 -0
  18. package/dist/components/echarts-renderer/geo/world-countries.json.js +9 -0
  19. package/dist/components/echarts-renderer/geo/world-regions.json.d.ts +10621 -0
  20. package/dist/components/echarts-renderer/geo/world-regions.json.js +9 -0
  21. package/dist/components/echarts-renderer/map-centers.d.ts +2 -0
  22. package/dist/components/echarts-renderer/map-centers.js +13 -0
  23. package/dist/components/echarts-renderer/map-style.d.ts +12 -0
  24. package/dist/components/echarts-renderer/map-style.js +12 -0
  25. package/dist/components/echarts-renderer/natural-earth-projection.d.ts +29 -0
  26. package/dist/components/echarts-renderer/natural-earth-projection.js +64 -0
  27. package/dist/components/echarts-renderer/register-map.d.ts +24 -0
  28. package/dist/components/echarts-renderer/register-map.js +62 -0
  29. package/dist/components/echarts-renderer/use-chart-instance.js +38 -36
  30. package/dist/hooks/use-scroll-to-bottom.d.ts +4 -3
  31. package/dist/lib/render-chart-to-image.js +72 -43
  32. package/dist/maps.json +438 -0
  33. package/package.json +19 -4
@@ -1,56 +1,58 @@
1
1
  "use client";
2
- import { useRef as d, useState as T, useEffect as I, useCallback as S } from "react";
2
+ import { useRef as f, useState as T, useEffect as I, useCallback as S } from "react";
3
3
  import { calculateTitleLayout as m } from "./calculate-title-layout.js";
4
4
  import { replaceFormatterTokens as O } from "./formatters/replace-formatter-tokens.js";
5
5
  import { mergeThemeGraphicIntoOptions as R } from "./merge-theme-graphic-into-options.js";
6
+ import { getRequiredMapName as j, registerMapAsync as x } from "./register-map.js";
6
7
  import { sanitizeChartOptions as w } from "./sanitize-chart-options.js";
7
8
  const W = /* @__PURE__ */ new Set();
8
- function L({ options: o, theme: t }) {
9
- const n = d(null), c = d(null), y = d(o), C = d(t?.config), z = d(t?.config.graphic), [b, v] = T(!1);
10
- y.current = o, C.current = t?.config, z.current = t?.config.graphic, I(() => {
11
- const s = n.current;
9
+ function B({ options: i, theme: t }) {
10
+ const e = f(null), o = f(null), y = f(i), C = f(t?.config), z = f(t?.config.graphic), [b, v] = T(!1);
11
+ y.current = i, C.current = t?.config, z.current = t?.config.graphic, I(() => {
12
+ const s = e.current;
12
13
  if (!s) return;
13
- let r = !0, e;
14
- const f = new ResizeObserver((i) => {
15
- const a = i[0], u = c.current;
16
- if (!a || !u) return;
17
- const p = a.contentRect.width, g = w(y.current), l = O(g), h = m(l, p, C.current);
18
- u.setOption(R(h, z.current), {
14
+ let r = !0, n;
15
+ const d = new ResizeObserver((c) => {
16
+ const u = c[0], a = o.current;
17
+ if (!u || !a) return;
18
+ const p = u.contentRect.width, g = w(y.current), l = O(g), h = m(l, p, C.current);
19
+ a.setOption(R(h, z.current), {
19
20
  replaceMerge: ["graphic"]
20
- }), u.resize();
21
+ }), a.resize();
21
22
  });
22
- return f.observe(s), (async () => {
23
+ return d.observe(s), (async () => {
23
24
  try {
24
- const i = await import("echarts");
25
- if (!r || !n.current) return;
26
- if (t && !W.has(t.name)) {
27
- const { graphic: h, ...F } = t.config;
28
- i.registerTheme(t.name, F), W.add(t.name);
25
+ const c = await import("echarts");
26
+ if (!r || !e.current) return;
27
+ const u = j(i);
28
+ if (u && await x(c, u), t && !W.has(t.name)) {
29
+ const { graphic: F, ...M } = t.config;
30
+ c.registerTheme(t.name, M), W.add(t.name);
29
31
  }
30
- const a = i.getInstanceByDom(n.current);
31
- a && a.dispose(), e = i.init(n.current, t?.name, {
32
+ const a = c.getInstanceByDom(e.current);
33
+ a && a.dispose(), n = c.init(e.current, t?.name, {
32
34
  renderer: "svg"
33
- }), c.current = e;
34
- const u = n.current.clientWidth, p = w(o), g = O(p), l = m(g, u, t?.config);
35
- e.setOption(R(l, t?.config.graphic), {
35
+ }), o.current = n;
36
+ const p = e.current.clientWidth, g = w(i), l = O(g), h = m(l, p, t?.config);
37
+ n.setOption(R(h, t?.config.graphic), {
36
38
  replaceMerge: ["graphic"]
37
- }), e.resize(), v(!0);
38
- } catch (i) {
39
- console.error("Failed to load echarts", i);
39
+ }), n.resize(), v(!0);
40
+ } catch (c) {
41
+ console.error("Failed to load echarts", c);
40
42
  }
41
43
  })(), () => {
42
- r = !1, f.disconnect(), e && e.dispose(), c.current = null, v(!1);
44
+ r = !1, d.disconnect(), n && n.dispose(), o.current = null, v(!1);
43
45
  };
44
- }, [t, o]), I(() => {
45
- if (!b || !c.current || !n.current) return;
46
- const s = n.current.clientWidth, r = w(o), e = O(r), f = m(e, s, t?.config);
47
- c.current.setOption(R(f, t?.config.graphic), {
46
+ }, [t, i]), I(() => {
47
+ if (!b || !o.current || !e.current) return;
48
+ const s = e.current.clientWidth, r = w(i), n = O(r), d = m(n, s, t?.config);
49
+ o.current.setOption(R(d, t?.config.graphic), {
48
50
  replaceMerge: ["graphic"]
49
51
  });
50
- }, [b, o, t?.config, t?.config.graphic]);
52
+ }, [b, i, t?.config, t?.config.graphic]);
51
53
  const k = S(async () => {
52
- if (!c.current) return;
53
- const s = c.current.getDataURL({
54
+ if (!o.current) return;
55
+ const s = o.current.getDataURL({
54
56
  type: "png",
55
57
  pixelRatio: 2,
56
58
  backgroundColor: "#fff"
@@ -58,10 +60,10 @@ function L({ options: o, theme: t }) {
58
60
  r.download = `chart-${(/* @__PURE__ */ new Date()).toISOString()}.png`, r.href = s, document.body.appendChild(r), r.click(), document.body.removeChild(r);
59
61
  }, []);
60
62
  return {
61
- containerRef: n,
63
+ containerRef: e,
62
64
  downloadChart: k
63
65
  };
64
66
  }
65
67
  export {
66
- L as useChartInstance
68
+ B as useChartInstance
67
69
  };
@@ -1,12 +1,13 @@
1
1
  type UseScrollToBottomOptions = {
2
2
  readonly threshold?: number;
3
3
  };
4
- export declare function useScrollToBottom({ threshold }?: UseScrollToBottomOptions): {
5
- containerRef: import('react').RefObject<HTMLDivElement | null>;
6
- endRef: import('react').RefObject<HTMLDivElement | null>;
4
+ type UseScrollToBottomReturn = {
5
+ containerRef: React.RefObject<HTMLDivElement | null>;
6
+ endRef: React.RefObject<HTMLDivElement | null>;
7
7
  isAtBottom: boolean;
8
8
  scrollToBottom: (behavior?: ScrollBehavior) => void;
9
9
  onViewportEnter: () => void;
10
10
  onViewportLeave: () => void;
11
11
  };
12
+ export declare function useScrollToBottom({ threshold }?: UseScrollToBottomOptions): UseScrollToBottomReturn;
12
13
  export {};
@@ -1,33 +1,51 @@
1
- import * as p from "echarts";
2
- import { randomUUID as C } from "node:crypto";
3
- import { writeFileSync as F, mkdtempSync as O } from "node:fs";
4
- import { tmpdir as b } from "node:os";
5
- import h from "node:path";
6
- import { Image as I, Canvas as S, FontLibrary as j } from "skia-canvas";
7
- import { calculateTitleLayout as w } from "../components/echarts-renderer/calculate-title-layout.js";
8
- import { isChartTheme as v } from "../components/echarts-renderer/chart-theme.js";
9
- import { replaceFormatterTokens as A } from "../components/echarts-renderer/formatters/replace-formatter-tokens.js";
10
- import { mergeThemeGraphicIntoOptions as D } from "../components/echarts-renderer/merge-theme-graphic-into-options.js";
11
- globalThis.Image = I;
12
- const l = /* @__PURE__ */ new Set();
13
- let m;
14
- function E() {
15
- return m || (m = O(h.join(b(), "chart-fonts-"))), m;
1
+ import * as d from "echarts";
2
+ import { writeFileSync as w, mkdtempSync as N } from "node:fs";
3
+ import { tmpdir as T } from "node:os";
4
+ import y from "node:path";
5
+ import { Image as C, Canvas as S, FontLibrary as G } from "skia-canvas";
6
+ import { calculateTitleLayout as F } from "../components/echarts-renderer/calculate-title-layout.js";
7
+ import { isChartTheme as b } from "../components/echarts-renderer/chart-theme.js";
8
+ import { replaceFormatterTokens as J } from "../components/echarts-renderer/formatters/replace-formatter-tokens.js";
9
+ import A from "../components/echarts-renderer/geo/africa-countries.json.js";
10
+ import I from "../components/echarts-renderer/geo/americas-countries.json.js";
11
+ import j from "../components/echarts-renderer/geo/asia-countries.json.js";
12
+ import E from "../components/echarts-renderer/geo/europe-countries.json.js";
13
+ import M from "../components/echarts-renderer/geo/us-states.json.js";
14
+ import R from "../components/echarts-renderer/geo/world-continents.json.js";
15
+ import P from "../components/echarts-renderer/geo/world-countries.json.js";
16
+ import k from "../components/echarts-renderer/geo/world-regions.json.js";
17
+ import { mergeThemeGraphicIntoOptions as v } from "../components/echarts-renderer/merge-theme-graphic-into-options.js";
18
+ import { getRequiredMapName as x, isMapName as D, registerMapSync as _ } from "../components/echarts-renderer/register-map.js";
19
+ const $ = {
20
+ "world-countries": P,
21
+ "world-continents": R,
22
+ "world-regions": k,
23
+ "us-states": M,
24
+ "europe-countries": E,
25
+ "americas-countries": I,
26
+ "asia-countries": j,
27
+ "africa-countries": A
28
+ };
29
+ globalThis.Image = C;
30
+ const g = /* @__PURE__ */ new Set();
31
+ let f;
32
+ function z() {
33
+ return f || (f = N(y.join(T(), "chart-fonts-"))), f;
16
34
  }
17
- function N(r) {
35
+ function L(r) {
18
36
  for (const t of r)
19
- if (!l.has(t.family))
37
+ if (!g.has(t.family))
20
38
  try {
21
- const e = E(), n = t.data.map((i, s) => {
22
- const o = h.join(e, `${t.family}-${String(s)}.ttf`);
23
- return F(o, i), o;
39
+ const e = z(), o = t.data.map((a, m) => {
40
+ const n = y.join(e, `${t.family}-${String(m)}.ttf`);
41
+ return w(n, a), n;
24
42
  });
25
- j.use(t.family, n), l.add(t.family);
43
+ G.use(t.family, o), g.add(t.family);
26
44
  } catch (e) {
27
45
  console.warn(`Failed to register ${t.family} fonts, charts will use fallback font:`, e);
28
46
  }
29
47
  }
30
- const P = /* @__PURE__ */ new Set([
48
+ const V = /* @__PURE__ */ new Set([
31
49
  "aria",
32
50
  // Tries to set DOM attributes which node-canvas doesn't implement
33
51
  "toolbox",
@@ -39,41 +57,52 @@ const P = /* @__PURE__ */ new Set([
39
57
  "axisPointer"
40
58
  // Crosshair on hover
41
59
  ]);
42
- function $(r) {
60
+ function q(r) {
43
61
  if (!r || typeof r != "object" || Array.isArray(r))
44
62
  return { animation: !1 };
45
63
  const t = Object.fromEntries(
46
- Object.entries(r).filter(([e]) => !P.has(e))
64
+ Object.entries(r).filter(([e]) => !V.has(e))
47
65
  );
48
66
  return t.animation = !1, t;
49
67
  }
50
- function k({
68
+ function B(r) {
69
+ const t = new S(r.width, r.height);
70
+ return t.getContext("2d").drawImage(r, 0, 0), t;
71
+ }
72
+ function U({
51
73
  option: r,
52
74
  theme: t,
53
75
  fonts: e,
54
- width: n = 800,
55
- height: i = 600,
56
- devicePixelRatio: s = 2
76
+ width: o = 800,
77
+ height: a = 600,
78
+ devicePixelRatio: m = 2
57
79
  }) {
58
- e?.length && N(e);
59
- let o, a, c;
80
+ e?.length && L(e);
81
+ let n, s, p;
60
82
  if (t) {
61
- a = v(t) ? t.config : t, c = a.graphic, o = `theme-${C()}`;
62
- const { graphic: x, ...T } = a;
63
- p.registerTheme(o, T);
83
+ s = b(t) ? t.config : t, p = s.graphic;
84
+ const { graphic: h, ...c } = s;
85
+ n = c;
64
86
  }
65
- const f = new S(n, i), u = p.init(f, o, {
87
+ const i = x(r);
88
+ i && (D(i) ? _(d, i, $[i]) : console.warn(`Unknown map name for server-side rendering: "${i}"`));
89
+ const l = new S(o, a), u = d.init(l, n, {
66
90
  renderer: "canvas",
67
- devicePixelRatio: s,
68
- width: n,
69
- height: i
70
- }), g = $(r), d = A(g), y = w(d, n, a);
71
- return u.setOption(D(y, c), { replaceMerge: ["graphic"] }), f;
91
+ devicePixelRatio: m,
92
+ width: o,
93
+ height: a
94
+ });
95
+ try {
96
+ const h = q(r), c = J(h), O = F(c, o, s);
97
+ return u.setOption(v(O, p), { replaceMerge: ["graphic"] }), B(l);
98
+ } finally {
99
+ u.dispose();
100
+ }
72
101
  }
73
- function W(r) {
74
- return k(r).toBufferSync("png");
102
+ function ft(r) {
103
+ return U(r).toBufferSync("png");
75
104
  }
76
105
  export {
77
- k as renderChartToCanvas,
78
- W as renderChartToImage
106
+ U as renderChartToCanvas,
107
+ ft as renderChartToImage
79
108
  };