@validationcloud/fractal-ui 1.57.0 → 1.58.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.
@@ -1,6 +1,18 @@
1
+ /** Font family registration for server-side chart rendering */
2
+ export interface FontRegistration {
3
+ /** Font family name (e.g., 'Poppins', 'Inter') */
4
+ family: string;
5
+ /** Font data buffers for each weight/style variant */
6
+ data: readonly Buffer[];
7
+ }
1
8
  export interface RenderChartToImageOptions {
2
9
  option: unknown;
3
10
  theme?: Record<string, unknown>;
11
+ /**
12
+ * Fonts to register before rendering. Each font family is registered once
13
+ * and cached for subsequent renders.
14
+ */
15
+ fonts?: FontRegistration[];
4
16
  /**
5
17
  * Adds Validation Cloud watermark graphic to the chart option before rendering.
6
18
  *
@@ -32,4 +44,4 @@ export interface RenderChartToImageOptions {
32
44
  * });
33
45
  * ```
34
46
  */
35
- export declare function renderChartToImage({ option, theme, includeWatermark, width, height, devicePixelRatio, }: RenderChartToImageOptions): Buffer;
47
+ export declare function renderChartToImage({ option, theme, fonts, includeWatermark, width, height, devicePixelRatio, }: RenderChartToImageOptions): Buffer;
@@ -1,40 +1,31 @@
1
1
  import * as p from "echarts";
2
- import { randomUUID as y } from "node:crypto";
3
- import e from "node:path";
4
- import { fileURLToPath as O } from "node:url";
5
- import { Image as b, Canvas as g, FontLibrary as h } from "skia-canvas";
6
- import { calculateTitleLayout as j } from "../components/echarts-renderer/calculate-title-layout.js";
7
- import { addWatermarkToOptions as P } from "../components/echarts-renderer/watermark-graphic.js";
8
- globalThis.Image = b;
9
- let s = !1;
10
- function T() {
11
- if (!s)
12
- try {
13
- const t = e.dirname(O(import.meta.url)), r = [
14
- // dist/src/lib -> dist/fonts (packaged) OR src/lib -> src/fonts (dev)
15
- e.resolve(t, "../../fonts"),
16
- // dist/lib -> dist/fonts (packaged)
17
- e.resolve(t, "../fonts")
18
- ];
19
- let n;
20
- for (const o of r)
21
- try {
22
- h.use("Poppins", [
23
- e.join(o, "Poppins-Regular.ttf"),
24
- e.join(o, "Poppins-Medium.ttf"),
25
- e.join(o, "Poppins-SemiBold.ttf"),
26
- e.join(o, "Poppins-Bold.ttf")
27
- ]), s = !0;
28
- return;
29
- } catch (a) {
30
- n = a;
31
- }
32
- throw n;
33
- } catch (t) {
34
- console.warn("Failed to register Poppins fonts, charts will use fallback font:", t), s = !0;
35
- }
2
+ import { randomUUID as h } from "node:crypto";
3
+ import { writeFileSync as O, mkdtempSync as T } from "node:fs";
4
+ import { tmpdir as b } from "node:os";
5
+ import d from "node:path";
6
+ import { Image as j, Canvas as F, FontLibrary as S } from "skia-canvas";
7
+ import { calculateTitleLayout as I } from "../components/echarts-renderer/calculate-title-layout.js";
8
+ import { addWatermarkToOptions as C } from "../components/echarts-renderer/watermark-graphic.js";
9
+ globalThis.Image = j;
10
+ const u = /* @__PURE__ */ new Set();
11
+ let f;
12
+ function w() {
13
+ return f || (f = T(d.join(b(), "chart-fonts-"))), f;
36
14
  }
37
- const I = /* @__PURE__ */ new Set([
15
+ function A(r) {
16
+ for (const t of r)
17
+ if (!u.has(t.family))
18
+ try {
19
+ const e = w(), i = t.data.map((o, n) => {
20
+ const a = d.join(e, `${t.family}-${String(n)}.ttf`);
21
+ return O(a, o), a;
22
+ });
23
+ S.use(t.family, i), u.add(t.family);
24
+ } catch (e) {
25
+ console.warn(`Failed to register ${t.family} fonts, charts will use fallback font:`, e);
26
+ }
27
+ }
28
+ const D = /* @__PURE__ */ new Set([
38
29
  "aria",
39
30
  // Tries to set DOM attributes which node-canvas doesn't implement
40
31
  "toolbox",
@@ -46,38 +37,39 @@ const I = /* @__PURE__ */ new Set([
46
37
  "axisPointer"
47
38
  // Crosshair on hover
48
39
  ]);
49
- function v(t) {
50
- if (!t || typeof t != "object" || Array.isArray(t))
40
+ function E(r) {
41
+ if (!r || typeof r != "object" || Array.isArray(r))
51
42
  return { animation: !1 };
52
- const r = Object.fromEntries(
53
- Object.entries(t).filter(([n]) => !I.has(n))
43
+ const t = Object.fromEntries(
44
+ Object.entries(r).filter(([e]) => !D.has(e))
54
45
  );
55
- return r.animation = !1, r;
46
+ return t.animation = !1, t;
56
47
  }
57
- function S({
58
- option: t,
59
- theme: r,
60
- includeWatermark: n = !1,
48
+ function L({
49
+ option: r,
50
+ theme: t,
51
+ fonts: e,
52
+ includeWatermark: i = !1,
61
53
  width: o = 800,
62
- height: a = 600,
63
- devicePixelRatio: m = 2
54
+ height: n = 600,
55
+ devicePixelRatio: a = 2
64
56
  }) {
65
- T();
66
- let i;
67
- r && typeof r == "object" && (i = `theme-${y()}`, p.registerTheme(i, r));
68
- const f = new g(o, a), c = p.init(f, i, {
57
+ e?.length && A(e);
58
+ let s;
59
+ t && typeof t == "object" && (s = `theme-${h()}`, p.registerTheme(s, t));
60
+ const m = new F(o, n), c = p.init(m, s, {
69
61
  renderer: "canvas",
70
- devicePixelRatio: m,
62
+ devicePixelRatio: a,
71
63
  width: o,
72
- height: a
64
+ height: n
73
65
  });
74
66
  try {
75
- const u = v(t), l = j(u, o, r), d = n ? P(l) : l;
76
- return c.setOption(d), f.toBufferSync("png");
67
+ const y = E(r), l = I(y, o, t), g = i ? C(l) : l;
68
+ return c.setOption(g), m.toBufferSync("png");
77
69
  } finally {
78
70
  c.dispose();
79
71
  }
80
72
  }
81
73
  export {
82
- S as renderChartToImage
74
+ L as renderChartToImage
83
75
  };
@@ -1,22 +1,28 @@
1
1
  import { selectMavrikTheme as n } from "../components/echarts-renderer/mavrik-theme.js";
2
- import { renderChartToImage as f } from "./render-chart-to-image.js";
3
- function c({
2
+ import { PoppinsRegular as p, PoppinsMedium as a, PoppinsSemiBold as s, PoppinsBold as f } from "./font-data.js";
3
+ import { renderChartToImage as P } from "./render-chart-to-image.js";
4
+ const d = {
5
+ family: "Poppins",
6
+ data: [p, a, s, f]
7
+ };
8
+ function g({
4
9
  option: e,
5
- includeWatermark: r = !1,
6
- width: t = 800,
7
- height: m = 600,
8
- devicePixelRatio: o = 2
10
+ includeWatermark: o = !1,
11
+ width: r = 800,
12
+ height: i = 600,
13
+ devicePixelRatio: m = 2
9
14
  }) {
10
- const a = n(e);
11
- return f({
15
+ const t = n(e);
16
+ return P({
12
17
  option: e,
13
- theme: a.config,
14
- includeWatermark: r,
15
- width: t,
16
- height: m,
17
- devicePixelRatio: o
18
+ theme: t.config,
19
+ fonts: [d],
20
+ includeWatermark: o,
21
+ width: r,
22
+ height: i,
23
+ devicePixelRatio: m
18
24
  });
19
25
  }
20
26
  export {
21
- c as renderMavrikChartToImage
27
+ g as renderMavrikChartToImage
22
28
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@validationcloud/fractal-ui",
3
3
  "private": false,
4
- "version": "1.57.0",
4
+ "version": "1.58.0",
5
5
  "module": "./dist/index.js",
6
6
  "type": "module",
7
7
  "files": [
@@ -18,7 +18,7 @@
18
18
  "url": "https://github.com/validationcloud/fractal-ui/issues"
19
19
  },
20
20
  "scripts": {
21
- "prebuild": "pnpm run generate:theme",
21
+ "prebuild": "pnpm run generate:theme && pnpm run generate:fonts",
22
22
  "build": "vite build",
23
23
  "lint": "eslint",
24
24
  "storybook": "storybook dev -p 6006",
@@ -28,7 +28,8 @@
28
28
  "typecheck": "tsc -b --noEmit",
29
29
  "test": "vitest run",
30
30
  "prepublishOnly": "pnpm build",
31
- "generate:theme": "node --experimental-transform-types scripts/generate-mavrik-theme.ts && prettier --write src/components/echarts-renderer/mavrik-theme*.json"
31
+ "generate:theme": "node --experimental-transform-types scripts/generate-mavrik-theme.ts && prettier --write src/components/echarts-renderer/mavrik-theme*.json",
32
+ "generate:fonts": "node --experimental-transform-types scripts/generate-font-data.ts && prettier --write src/lib/font-data.ts"
32
33
  },
33
34
  "exports": {
34
35
  ".": {
Binary file
Binary file
Binary file
Binary file