@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.
- package/dist/lib/font-data.d.ts +17 -0
- package/dist/lib/font-data.js +19 -0
- package/dist/lib/render-chart-to-image.d.ts +13 -1
- package/dist/lib/render-chart-to-image.js +47 -55
- package/dist/lib/render-mavrik-chart-to-image.js +20 -14
- package/package.json +4 -3
- package/dist/fonts/Poppins-Bold.ttf +0 -0
- package/dist/fonts/Poppins-Medium.ttf +0 -0
- package/dist/fonts/Poppins-Regular.ttf +0 -0
- package/dist/fonts/Poppins-SemiBold.ttf +0 -0
|
@@ -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
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
-
|
|
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
|
|
50
|
-
if (!
|
|
40
|
+
function E(r) {
|
|
41
|
+
if (!r || typeof r != "object" || Array.isArray(r))
|
|
51
42
|
return { animation: !1 };
|
|
52
|
-
const
|
|
53
|
-
Object.entries(
|
|
43
|
+
const t = Object.fromEntries(
|
|
44
|
+
Object.entries(r).filter(([e]) => !D.has(e))
|
|
54
45
|
);
|
|
55
|
-
return
|
|
46
|
+
return t.animation = !1, t;
|
|
56
47
|
}
|
|
57
|
-
function
|
|
58
|
-
option:
|
|
59
|
-
theme:
|
|
60
|
-
|
|
48
|
+
function L({
|
|
49
|
+
option: r,
|
|
50
|
+
theme: t,
|
|
51
|
+
fonts: e,
|
|
52
|
+
includeWatermark: i = !1,
|
|
61
53
|
width: o = 800,
|
|
62
|
-
height:
|
|
63
|
-
devicePixelRatio:
|
|
54
|
+
height: n = 600,
|
|
55
|
+
devicePixelRatio: a = 2
|
|
64
56
|
}) {
|
|
65
|
-
|
|
66
|
-
let
|
|
67
|
-
|
|
68
|
-
const
|
|
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:
|
|
62
|
+
devicePixelRatio: a,
|
|
71
63
|
width: o,
|
|
72
|
-
height:
|
|
64
|
+
height: n
|
|
73
65
|
});
|
|
74
66
|
try {
|
|
75
|
-
const
|
|
76
|
-
return c.setOption(
|
|
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
|
-
|
|
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 {
|
|
3
|
-
|
|
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:
|
|
6
|
-
width:
|
|
7
|
-
height:
|
|
8
|
-
devicePixelRatio:
|
|
10
|
+
includeWatermark: o = !1,
|
|
11
|
+
width: r = 800,
|
|
12
|
+
height: i = 600,
|
|
13
|
+
devicePixelRatio: m = 2
|
|
9
14
|
}) {
|
|
10
|
-
const
|
|
11
|
-
return
|
|
15
|
+
const t = n(e);
|
|
16
|
+
return P({
|
|
12
17
|
option: e,
|
|
13
|
-
theme:
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
-
|
|
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.
|
|
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
|