@agile-team/mach-report 0.5.0 → 0.7.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/ReportPreview-CrVeTKu1.cjs +6 -0
- package/dist/ReportPreview-DgsOdO4y.js +559 -0
- package/dist/_commonjsHelpers-DKOUU3wS.cjs +1 -0
- package/dist/_commonjsHelpers-DaMA6jEr.js +8 -0
- package/dist/builder/template-builder.d.ts +53 -0
- package/dist/compat/jh4j-template.d.ts +12 -0
- package/dist/defaults.d.ts +27 -0
- package/dist/index.cjs +6 -1663
- package/dist/index.d.cts +13 -344
- package/dist/index.d.ts +13 -344
- package/dist/index.js +744 -1415
- package/dist/layout/paginate.d.ts +51 -0
- package/dist/layout/textwrap.d.ts +36 -0
- package/dist/manager/api.d.ts +45 -0
- package/dist/manager/index.d.ts +2 -0
- package/dist/manager/types.d.ts +50 -0
- package/dist/manager.cjs +1 -122
- package/dist/manager.d.cts +5 -97
- package/dist/manager.d.ts +5 -97
- package/dist/manager.js +66 -81
- package/dist/pdf/font-loader.d.ts +5 -0
- package/dist/pdf/index.d.ts +2 -0
- package/dist/pdf/render-pdf.d.ts +25 -0
- package/dist/pdf.cjs +84 -52530
- package/dist/pdf.d.cts +4 -31
- package/dist/pdf.d.ts +4 -31
- package/dist/pdf.js +22843 -39218
- package/dist/plugin-Cl-IqCqx.cjs +1 -0
- package/dist/plugin-Dp3kKWiQ.js +92 -0
- package/dist/render/canvas.d.ts +61 -0
- package/dist/render/dom.d.ts +10 -0
- package/dist/render/grid-geometry.d.ts +41 -0
- package/dist/render/style.d.ts +33 -0
- package/dist/render/window.d.ts +23 -0
- package/dist/schema/render-plan.d.ts +96 -0
- package/dist/schema/validate.d.ts +15 -0
- package/dist/sql/ast-check.d.ts +14 -0
- package/dist/sql/compile.d.ts +31 -0
- package/dist/sql/expr.d.ts +21 -0
- package/dist/sql/index.d.ts +4 -0
- package/dist/sql/tokenizer.d.ts +25 -0
- package/dist/sql.cjs +68 -45207
- package/dist/sql.d.cts +3 -93
- package/dist/sql.d.ts +3 -93
- package/dist/sql.js +37213 -41613
- package/dist/style-B3vxGDZd.cjs +3 -0
- package/dist/style-B7Xfo5I-.js +255 -0
- package/dist/style.css +1 -0
- package/dist/units.d.ts +11 -0
- package/dist/vue/ReportPreview.d.ts +165 -0
- package/dist/vue/ReportToolbar.d.ts +25 -0
- package/dist/vue/adapters.d.ts +40 -0
- package/dist/vue/async.d.cts +275 -0
- package/dist/vue/async.d.ts +275 -0
- package/dist/vue/composables/usePageWindow.d.ts +28 -0
- package/dist/vue/composables/usePrintExport.d.ts +19 -0
- package/dist/vue/composables/useZoom.d.ts +15 -0
- package/dist/vue/config.d.ts +79 -0
- package/dist/vue/controller.d.ts +24 -0
- package/dist/vue/errors.d.ts +16 -0
- package/dist/vue/index.d.cts +13 -0
- package/dist/vue/index.d.ts +13 -0
- package/dist/vue/injection-keys.d.ts +14 -0
- package/dist/vue/local-adapter.d.ts +12 -0
- package/dist/vue/pdf-exporter.d.ts +13 -0
- package/dist/vue/plugin.d.ts +294 -0
- package/dist/vue-async.cjs +1 -0
- package/dist/vue-async.js +17 -0
- package/dist/vue.cjs +1 -0
- package/dist/vue.js +53 -0
- package/package.json +44 -6
- package/dist/textwrap-DWzM7pt1.d.cts +0 -135
- package/dist/textwrap-DWzM7pt1.d.ts +0 -135
package/dist/index.js
CHANGED
|
@@ -1,61 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var DEFAULT_BORDER_PT = 0.75;
|
|
5
|
-
var DEFAULT_STROKE_COLOR = "#333333";
|
|
6
|
-
var DEFAULT_TEXT_COLOR = "#000000";
|
|
7
|
-
var SCHEMA_VERSION_MACH = "1.0.0-mach";
|
|
8
|
-
var SCHEMA_VERSION_LOCAL = "mach-local";
|
|
9
|
-
var SCHEMA_VERSION_JH4J = "jh4j-compatible";
|
|
10
|
-
|
|
11
|
-
// src/units.ts
|
|
12
|
-
var MM_PER_INCH = 25.4;
|
|
13
|
-
var CSS_DPI = 96;
|
|
14
|
-
function mmToPxFactor(dpi = CSS_DPI) {
|
|
15
|
-
return dpi / MM_PER_INCH;
|
|
16
|
-
}
|
|
17
|
-
function mmToPx(value, dpi = CSS_DPI) {
|
|
18
|
-
return (value || 0) * mmToPxFactor(dpi);
|
|
19
|
-
}
|
|
20
|
-
function pxToMm(value, dpi = CSS_DPI) {
|
|
21
|
-
return value / mmToPxFactor(dpi);
|
|
22
|
-
}
|
|
23
|
-
function ptToPx(pt, dpi = CSS_DPI) {
|
|
24
|
-
return pt * dpi / 72;
|
|
25
|
-
}
|
|
26
|
-
function round(value, digits) {
|
|
27
|
-
const f = 10 ** digits;
|
|
28
|
-
return Math.round(value * f) / f;
|
|
29
|
-
}
|
|
30
|
-
var PAPER_SIZES = {
|
|
31
|
-
a3: { widthMm: 297, heightMm: 420 },
|
|
32
|
-
a4: { widthMm: 210, heightMm: 297 },
|
|
33
|
-
a5: { widthMm: 148, heightMm: 210 },
|
|
34
|
-
b4: { widthMm: 250, heightMm: 353 },
|
|
35
|
-
b5: { widthMm: 176, heightMm: 250 }
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
// src/schema/render-plan.ts
|
|
39
|
-
var RENDER_PLAN_SCHEMA_VERSION = SCHEMA_VERSION_MACH;
|
|
40
|
-
function toRenderPlan(response) {
|
|
41
|
-
if (response && response.code != null && response.code !== 200) {
|
|
42
|
-
throw new Error(String(response.message || "\u6E32\u67D3\u8BA1\u5212\u52A0\u8F7D\u5931\u8D25"));
|
|
43
|
-
}
|
|
44
|
-
const pages = response?.data?.pages;
|
|
45
|
-
return {
|
|
46
|
-
schemaVersion: RENDER_PLAN_SCHEMA_VERSION,
|
|
47
|
-
pages: Array.isArray(pages) ? pages : []
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
function isImageBackedComponent(comp) {
|
|
51
|
-
return (comp.kind === "image" || comp.kind === "barcode" || comp.kind === "qrcode" || comp.kind === "chart") && !!comp.imageData;
|
|
52
|
-
}
|
|
53
|
-
function isRichText(comp) {
|
|
54
|
-
return comp.kind === "text" && Array.isArray(comp.richParagraphs) && comp.richParagraphs.length > 0;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// src/schema/validate.ts
|
|
58
|
-
var KNOWN_KINDS = /* @__PURE__ */ new Set([
|
|
1
|
+
import { h as J, R as se, D as j, w as G, L as q, i as le, r as _, m as de, a as W, b as Z, c as F, d as V, p as O, e as he, f as Q, g as ce, j as me, P as K } from "./style-B7Xfo5I-.js";
|
|
2
|
+
import { C as Ue, k as Ke, l as Ye, M as Xe, S as Ze, n as Qe, o as et, q as tt, s as nt, t as it, u as rt, v as ot, x as at, y as st } from "./style-B7Xfo5I-.js";
|
|
3
|
+
const ge = /* @__PURE__ */ new Set([
|
|
59
4
|
"text",
|
|
60
5
|
"image",
|
|
61
6
|
"barcode",
|
|
@@ -65,569 +10,239 @@ var KNOWN_KINDS = /* @__PURE__ */ new Set([
|
|
|
65
10
|
"rect",
|
|
66
11
|
"ellipse"
|
|
67
12
|
]);
|
|
68
|
-
function
|
|
69
|
-
return typeof
|
|
13
|
+
function L(e) {
|
|
14
|
+
return typeof e == "object" && e !== null && !Array.isArray(e);
|
|
70
15
|
}
|
|
71
|
-
function
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
if (typeof v !== "number" || !Number.isFinite(v)) {
|
|
75
|
-
errors.push({ path: `${path}.${key}`, message: `\u5E94\u4E3A\u6709\u9650\u6570\u5B57\uFF0C\u5B9E\u9645 ${JSON.stringify(v)}` });
|
|
76
|
-
}
|
|
16
|
+
function fe(e, n, i, t) {
|
|
17
|
+
const r = e[n];
|
|
18
|
+
r != null && (typeof r != "number" || !Number.isFinite(r)) && t.push({ path: `${i}.${n}`, message: `应为有限数字,实际 ${JSON.stringify(r)}` });
|
|
77
19
|
}
|
|
78
|
-
function
|
|
79
|
-
if (!
|
|
80
|
-
|
|
20
|
+
function ee(e, n, i, t = []) {
|
|
21
|
+
if (!L(e)) {
|
|
22
|
+
i.push({ path: n, message: "组件应为对象" });
|
|
81
23
|
return;
|
|
82
24
|
}
|
|
83
|
-
const
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
const grid = comp["grid"];
|
|
101
|
-
if (grid !== void 0) {
|
|
102
|
-
if (!isObj(grid) || !Array.isArray(grid["cells"])) {
|
|
103
|
-
errors.push({ path: `${path}.grid.cells`, message: "grid.cells \u5E94\u4E3A\u4E8C\u7EF4\u6570\u7EC4" });
|
|
104
|
-
} else {
|
|
105
|
-
grid["cells"].forEach((row, ri) => {
|
|
106
|
-
if (!Array.isArray(row)) {
|
|
107
|
-
errors.push({ path: `${path}.grid.cells.${ri}`, message: "\u884C\u5E94\u4E3A\u6570\u7EC4" });
|
|
108
|
-
return;
|
|
109
|
-
}
|
|
110
|
-
row.forEach((cell, ci) => {
|
|
111
|
-
if (cell === void 0 || cell === null) return;
|
|
112
|
-
if (isObj(cell) && Array.isArray(cell["children"])) {
|
|
113
|
-
cell["children"].forEach((child, ki) => {
|
|
114
|
-
validateComponent(child, `${path}.grid.cells.${ri}.${ci}.children.${ki}`, errors, warnings);
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
});
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
const rich = comp["richParagraphs"];
|
|
122
|
-
if (rich !== void 0) {
|
|
123
|
-
if (!Array.isArray(rich)) {
|
|
124
|
-
errors.push({ path: `${path}.richParagraphs`, message: "richParagraphs \u5E94\u4E3A\u6570\u7EC4" });
|
|
125
|
-
} else {
|
|
126
|
-
rich.forEach((para, i) => {
|
|
127
|
-
if (!isObj(para) || !Array.isArray(para["segments"])) {
|
|
128
|
-
errors.push({ path: `${path}.richParagraphs.${i}`, message: "\u6BB5\u843D\u7F3A\u5C11 segments \u6570\u7EC4" });
|
|
129
|
-
}
|
|
25
|
+
const r = e.kind;
|
|
26
|
+
typeof r != "string" ? i.push({ path: `${n}.kind`, message: "组件缺少 kind 字符串" }) : ge.has(r) || t.push({
|
|
27
|
+
path: `${n}.kind`,
|
|
28
|
+
message: `未知组件类型 ${JSON.stringify(r)},将以兜底方式渲染`
|
|
29
|
+
});
|
|
30
|
+
for (const o of ["leftMm", "topMm", "widthMm", "heightMm"])
|
|
31
|
+
fe(e, o, n, i);
|
|
32
|
+
e.leftMm != null && e.widthMm != null && (e.leftMm < -100 || e.widthMm < 0) && i.push({ path: n, message: "几何数值异常(leftMm<-100 或 widthMm<0)" });
|
|
33
|
+
const s = e.grid;
|
|
34
|
+
s !== void 0 && (!L(s) || !Array.isArray(s.cells) ? i.push({ path: `${n}.grid.cells`, message: "grid.cells 应为二维数组" }) : s.cells.forEach((o, l) => {
|
|
35
|
+
if (!Array.isArray(o)) {
|
|
36
|
+
i.push({ path: `${n}.grid.cells.${l}`, message: "行应为数组" });
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
o.forEach((d, h) => {
|
|
40
|
+
d != null && L(d) && Array.isArray(d.children) && d.children.forEach((c, m) => {
|
|
41
|
+
ee(c, `${n}.grid.cells.${l}.${h}.children.${m}`, i, t);
|
|
130
42
|
});
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
43
|
+
});
|
|
44
|
+
}));
|
|
45
|
+
const a = e.richParagraphs;
|
|
46
|
+
a !== void 0 && (Array.isArray(a) ? a.forEach((o, l) => {
|
|
47
|
+
(!L(o) || !Array.isArray(o.segments)) && i.push({ path: `${n}.richParagraphs.${l}`, message: "段落缺少 segments 数组" });
|
|
48
|
+
}) : i.push({ path: `${n}.richParagraphs`, message: "richParagraphs 应为数组" }));
|
|
49
|
+
}
|
|
50
|
+
function ue(e, n, i, t = []) {
|
|
51
|
+
if (!L(e)) {
|
|
52
|
+
i.push({ path: n, message: "页应为对象" });
|
|
137
53
|
return;
|
|
138
54
|
}
|
|
139
|
-
const
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
errors.push({ path: `${path}.pageHeightMm`, message: `\u9875\u9AD8\u975E\u6CD5: ${JSON.stringify(h)}` });
|
|
146
|
-
}
|
|
147
|
-
const comps = page["components"];
|
|
148
|
-
if (comps !== void 0 && !Array.isArray(comps)) {
|
|
149
|
-
errors.push({ path: `${path}.components`, message: "components \u5E94\u4E3A\u6570\u7EC4" });
|
|
150
|
-
} else if (Array.isArray(comps)) {
|
|
151
|
-
comps.forEach(
|
|
152
|
-
(comp, i) => validateComponent(comp, `${path}.components.${i}`, errors, warnings)
|
|
153
|
-
);
|
|
154
|
-
}
|
|
55
|
+
const r = e.pageWidthMm, s = e.pageHeightMm;
|
|
56
|
+
(typeof r != "number" || !(r > 0 && r < 3e3)) && i.push({ path: `${n}.pageWidthMm`, message: `页宽非法: ${JSON.stringify(r)}` }), (typeof s != "number" || !(s > 0 && s < 5e3)) && i.push({ path: `${n}.pageHeightMm`, message: `页高非法: ${JSON.stringify(s)}` });
|
|
57
|
+
const a = e.components;
|
|
58
|
+
a !== void 0 && !Array.isArray(a) ? i.push({ path: `${n}.components`, message: "components 应为数组" }) : Array.isArray(a) && a.forEach(
|
|
59
|
+
(o, l) => ee(o, `${n}.components.${l}`, i, t)
|
|
60
|
+
);
|
|
155
61
|
}
|
|
156
|
-
function
|
|
157
|
-
const
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
if (!Array.isArray(pages)) {
|
|
161
|
-
errors.push({
|
|
62
|
+
function pe(e) {
|
|
63
|
+
const n = [], i = [], t = L(e) ? e.pages : void 0;
|
|
64
|
+
if (!Array.isArray(t))
|
|
65
|
+
n.push({
|
|
162
66
|
path: "$.pages",
|
|
163
|
-
message:
|
|
67
|
+
message: e == null ? "渲染计划为空" : "渲染计划缺少 pages 数组"
|
|
68
|
+
});
|
|
69
|
+
else {
|
|
70
|
+
t.forEach((s, a) => ue(s, `$.pages.${a}`, n, i)), t.length > 2e3 && i.push({
|
|
71
|
+
path: "$.pages",
|
|
72
|
+
message: `页数异常大(${t.length} 页),渲染与打印耗时可能显著增加`
|
|
73
|
+
});
|
|
74
|
+
const r = t.reduce(
|
|
75
|
+
(s, a) => s + (L(a) && Array.isArray(a.components) ? a.components.length : 0),
|
|
76
|
+
0
|
|
77
|
+
);
|
|
78
|
+
r > 5e4 && i.push({
|
|
79
|
+
path: "$.pages",
|
|
80
|
+
message: `组件总数异常大(${r} 个),可能触发浏览器性能限制`
|
|
164
81
|
});
|
|
165
|
-
} else {
|
|
166
|
-
pages.forEach((page, i) => validatePage(page, `$.pages.${i}`, errors, warnings));
|
|
167
|
-
}
|
|
168
|
-
return { ok: errors.length === 0, errors, warnings };
|
|
169
|
-
}
|
|
170
|
-
function assertRenderPlan(input) {
|
|
171
|
-
const result = validateRenderPlan(input);
|
|
172
|
-
if (!result.ok) {
|
|
173
|
-
const head = result.errors.slice(0, 3).map((e) => `${e.path}: ${e.message}`).join("; ");
|
|
174
|
-
throw new Error(`\u6E32\u67D3\u8BA1\u5212\u6821\u9A8C\u5931\u8D25(${result.errors.length} \u5904): ${head}`);
|
|
175
|
-
}
|
|
176
|
-
return input.pages;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
// src/layout/textwrap.ts
|
|
180
|
-
var CJK_RE = /[\u3000-\u9fff\uff00-\uffef]/;
|
|
181
|
-
var LATIN_CLASS = new Uint8Array(128);
|
|
182
|
-
{
|
|
183
|
-
for (const ch of "iljtf.,:;'`|!()[]") LATIN_CLASS[ch.charCodeAt(0)] = 1;
|
|
184
|
-
for (const ch of "mwMW@") LATIN_CLASS[ch.charCodeAt(0)] = 2;
|
|
185
|
-
for (let c = 48; c <= 57; c++) LATIN_CLASS[c] = 3;
|
|
186
|
-
for (let c = 65; c <= 90; c++) LATIN_CLASS[c] = 4;
|
|
187
|
-
LATIN_CLASS[32] = 5;
|
|
188
|
-
}
|
|
189
|
-
var LATIN_WIDTH = [0.54, 0.26, 0.95, 0.59, 0.67, 0.3];
|
|
190
|
-
function charWidthEm(ch) {
|
|
191
|
-
const code = ch.charCodeAt(0);
|
|
192
|
-
if (code < 128) return LATIN_WIDTH[LATIN_CLASS[code]];
|
|
193
|
-
if (CJK_RE.test(ch)) return 1;
|
|
194
|
-
if (/[A-Z]/.test(ch)) return 0.67;
|
|
195
|
-
return 0.54;
|
|
196
|
-
}
|
|
197
|
-
var heuristicMeasurer = {
|
|
198
|
-
measureMm(text, options) {
|
|
199
|
-
const { fontSizePt, bold = false, letterSpacingPt = 0 } = options;
|
|
200
|
-
const ptToMm = 25.4 / 72;
|
|
201
|
-
let units = 0;
|
|
202
|
-
for (const ch of text) {
|
|
203
|
-
units += charWidthEm(ch);
|
|
204
|
-
}
|
|
205
|
-
if (bold) units *= 1.04;
|
|
206
|
-
return (units * fontSizePt + letterSpacingPt * text.length) * ptToMm;
|
|
207
|
-
}
|
|
208
|
-
};
|
|
209
|
-
function createHeuristicMeasurer() {
|
|
210
|
-
return heuristicMeasurer;
|
|
211
|
-
}
|
|
212
|
-
function measureTextMm(text, options) {
|
|
213
|
-
return heuristicMeasurer.measureMm(text, options);
|
|
214
|
-
}
|
|
215
|
-
function createCanvasMeasurer(getCtx2d) {
|
|
216
|
-
let ctx;
|
|
217
|
-
return {
|
|
218
|
-
measureMm(text, options) {
|
|
219
|
-
if (ctx === void 0) ctx = getCtx2d();
|
|
220
|
-
if (!ctx) return heuristicMeasurer.measureMm(text, options);
|
|
221
|
-
const px = options.fontSizePt * 96 / 72;
|
|
222
|
-
ctx.font = `${options.bold ? "bold " : ""}${px}px sans-serif`;
|
|
223
|
-
return ctx.measureText(text).width * 25.4 / 96;
|
|
224
|
-
}
|
|
225
|
-
};
|
|
226
|
-
}
|
|
227
|
-
function tokenize(text, options, measurer) {
|
|
228
|
-
const atoms = [];
|
|
229
|
-
let word = "";
|
|
230
|
-
let wordWidth = 0;
|
|
231
|
-
const flush = () => {
|
|
232
|
-
if (word) {
|
|
233
|
-
atoms.push({ text: word, widthMm: wordWidth, cjk: false });
|
|
234
|
-
word = "";
|
|
235
|
-
wordWidth = 0;
|
|
236
|
-
}
|
|
237
|
-
};
|
|
238
|
-
for (const ch of text) {
|
|
239
|
-
if (ch === "\n") {
|
|
240
|
-
flush();
|
|
241
|
-
atoms.push({ text: "\n", widthMm: 0, cjk: false, br: true });
|
|
242
|
-
continue;
|
|
243
|
-
}
|
|
244
|
-
if (ch === " ") {
|
|
245
|
-
flush();
|
|
246
|
-
atoms.push({ text: ch, widthMm: measurer.measureMm(ch, options), cjk: false, space: true });
|
|
247
|
-
continue;
|
|
248
|
-
}
|
|
249
|
-
if (CJK_RE.test(ch)) {
|
|
250
|
-
flush();
|
|
251
|
-
atoms.push({ text: ch, widthMm: measurer.measureMm(ch, options), cjk: true });
|
|
252
|
-
continue;
|
|
253
|
-
}
|
|
254
|
-
word += ch;
|
|
255
|
-
wordWidth += measurer.measureMm(ch, options);
|
|
256
82
|
}
|
|
257
|
-
|
|
258
|
-
return atoms;
|
|
83
|
+
return { ok: n.length === 0, errors: n, warnings: i };
|
|
259
84
|
}
|
|
260
|
-
function
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
const pushLine = () => {
|
|
266
|
-
lines.push(current);
|
|
267
|
-
current = "";
|
|
268
|
-
currentWidth = 0;
|
|
269
|
-
};
|
|
270
|
-
for (const atom of tokenize(text, options, measurer)) {
|
|
271
|
-
if (atom.br) {
|
|
272
|
-
pushLine();
|
|
273
|
-
continue;
|
|
274
|
-
}
|
|
275
|
-
if (currentWidth + atom.widthMm <= maxWidthMm) {
|
|
276
|
-
current += atom.text;
|
|
277
|
-
currentWidth += atom.widthMm;
|
|
278
|
-
continue;
|
|
279
|
-
}
|
|
280
|
-
if (atom.space) {
|
|
281
|
-
pushLine();
|
|
282
|
-
continue;
|
|
283
|
-
}
|
|
284
|
-
if (atom.cjk) {
|
|
285
|
-
if (current.length > 0) pushLine();
|
|
286
|
-
current = atom.text;
|
|
287
|
-
currentWidth = atom.widthMm;
|
|
288
|
-
continue;
|
|
289
|
-
}
|
|
290
|
-
if (current.length > 0) pushLine();
|
|
291
|
-
if (atom.widthMm <= maxWidthMm) {
|
|
292
|
-
current = atom.text;
|
|
293
|
-
currentWidth = atom.widthMm;
|
|
294
|
-
continue;
|
|
295
|
-
}
|
|
296
|
-
for (const ch of atom.text) {
|
|
297
|
-
const chWidth = measurer.measureMm(ch, options);
|
|
298
|
-
if (currentWidth + chWidth > maxWidthMm && current.length > 0) {
|
|
299
|
-
pushLine();
|
|
300
|
-
}
|
|
301
|
-
current += ch;
|
|
302
|
-
currentWidth += chWidth;
|
|
303
|
-
}
|
|
85
|
+
function _e(e) {
|
|
86
|
+
const n = pe(e);
|
|
87
|
+
if (!n.ok) {
|
|
88
|
+
const i = n.errors.slice(0, 3).map((t) => `${t.path}: ${t.message}`).join("; ");
|
|
89
|
+
throw new Error(`渲染计划校验失败(${n.errors.length} 处): ${i}`);
|
|
304
90
|
}
|
|
305
|
-
|
|
306
|
-
return lines;
|
|
91
|
+
return e.pages;
|
|
307
92
|
}
|
|
308
|
-
|
|
309
|
-
// src/layout/paginate.ts
|
|
310
|
-
function makeWorkingPage(page) {
|
|
93
|
+
function Y(e) {
|
|
311
94
|
return {
|
|
312
|
-
widthMm:
|
|
313
|
-
heightMm:
|
|
314
|
-
marginTopMm:
|
|
315
|
-
marginBottomMm:
|
|
316
|
-
marginLeftMm:
|
|
317
|
-
marginRightMm:
|
|
95
|
+
widthMm: e.widthMm,
|
|
96
|
+
heightMm: e.heightMm,
|
|
97
|
+
marginTopMm: e.marginTopMm ?? 0,
|
|
98
|
+
marginBottomMm: e.marginBottomMm ?? 0,
|
|
99
|
+
marginLeftMm: e.marginLeftMm ?? 0,
|
|
100
|
+
marginRightMm: e.marginRightMm ?? 0,
|
|
318
101
|
components: []
|
|
319
102
|
};
|
|
320
103
|
}
|
|
321
|
-
function
|
|
322
|
-
return
|
|
104
|
+
function Me(e, n) {
|
|
105
|
+
return n.heightMm - (e.marginBottomMm ?? n.marginBottomMm);
|
|
323
106
|
}
|
|
324
|
-
function
|
|
325
|
-
const
|
|
326
|
-
|
|
327
|
-
const padding = (list.paddingMm ?? 1) * 2;
|
|
328
|
-
return Math.max(list.rowHeightMm ?? 0, lines * lineMm + padding);
|
|
107
|
+
function be(e, n) {
|
|
108
|
+
const t = (e.fontSizePt ?? j) * q * 25.4 / 72, r = (e.paddingMm ?? 1) * 2;
|
|
109
|
+
return Math.max(e.rowHeightMm ?? 0, n * t + r);
|
|
329
110
|
}
|
|
330
|
-
function
|
|
331
|
-
if (
|
|
332
|
-
if (typeof
|
|
333
|
-
if (typeof
|
|
334
|
-
if (typeof
|
|
335
|
-
if (
|
|
111
|
+
function ye(e) {
|
|
112
|
+
if (e == null) return "";
|
|
113
|
+
if (typeof e == "string") return e;
|
|
114
|
+
if (typeof e == "number") return String(e);
|
|
115
|
+
if (typeof e == "boolean") return e ? "是" : "否";
|
|
116
|
+
if (e instanceof Date) return e.toISOString().slice(0, 10);
|
|
336
117
|
try {
|
|
337
|
-
return JSON.stringify(
|
|
118
|
+
return JSON.stringify(e);
|
|
338
119
|
} catch {
|
|
339
|
-
return String(
|
|
120
|
+
return String(e);
|
|
340
121
|
}
|
|
341
122
|
}
|
|
342
|
-
function
|
|
343
|
-
const
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
(
|
|
347
|
-
|
|
348
|
-
const headerCellStyles = list.columns.map(
|
|
349
|
-
(col) => ({
|
|
350
|
-
bold: list.headerBold ?? true,
|
|
123
|
+
function we(e, n) {
|
|
124
|
+
const i = e.fontSizePt ?? j, t = e.paddingMm ?? 1, r = e.columns.map(
|
|
125
|
+
(m) => m.style ? { align: "left", verticalAlign: "middle", ...m.style } : { align: "left", verticalAlign: "middle" }
|
|
126
|
+
), s = e.columns.map(
|
|
127
|
+
(m) => ({
|
|
128
|
+
bold: e.headerBold ?? !0,
|
|
351
129
|
align: "center",
|
|
352
130
|
verticalAlign: "middle",
|
|
353
|
-
backgroundColor:
|
|
354
|
-
...
|
|
131
|
+
backgroundColor: e.headerBackgroundColor,
|
|
132
|
+
...m.style || {}
|
|
355
133
|
})
|
|
356
|
-
)
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
{ fontSizePt, bold: list.headerBold ?? true },
|
|
363
|
-
measurer
|
|
134
|
+
), a = e.columns.map((m) => m.header), o = a.map(
|
|
135
|
+
(m, u) => G(
|
|
136
|
+
m,
|
|
137
|
+
e.columns[u].widthMm - t * 2,
|
|
138
|
+
{ fontSizePt: i, bold: e.headerBold ?? !0 },
|
|
139
|
+
n
|
|
364
140
|
)
|
|
365
|
-
)
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
text,
|
|
370
|
-
style: headerCellStyles[i]
|
|
371
|
-
}));
|
|
372
|
-
const borderStyle = list.border === false ? { borderTop: false, borderRight: false, borderBottom: false, borderLeft: false } : { borderBottom: true, borderLeft: true, borderRight: true, borderTop: true };
|
|
141
|
+
), l = Math.max(...o.map((m) => m.length), 1), d = be(e, l), h = a.map((m, u) => ({
|
|
142
|
+
text: m,
|
|
143
|
+
style: s[u]
|
|
144
|
+
})), c = e.border === !1 ? { borderTop: !1, borderRight: !1, borderBottom: !1, borderLeft: !1 } : { borderBottom: !0, borderLeft: !0, borderRight: !0, borderTop: !0 };
|
|
373
145
|
return {
|
|
374
|
-
fontSizePt,
|
|
375
|
-
paddingMm,
|
|
376
|
-
cellStyles,
|
|
377
|
-
borderStyle,
|
|
378
|
-
headerHeightMm:
|
|
379
|
-
headerGrid: { cells: [
|
|
380
|
-
columns:
|
|
146
|
+
fontSizePt: i,
|
|
147
|
+
paddingMm: t,
|
|
148
|
+
cellStyles: r,
|
|
149
|
+
borderStyle: c,
|
|
150
|
+
headerHeightMm: d,
|
|
151
|
+
headerGrid: { cells: [h], rowHeightsMm: [d] },
|
|
152
|
+
columns: e.columns
|
|
381
153
|
};
|
|
382
154
|
}
|
|
383
|
-
function
|
|
384
|
-
const columns =
|
|
385
|
-
|
|
386
|
-
let
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
{ fontSizePt: inter.fontSizePt },
|
|
396
|
-
measurer
|
|
155
|
+
function Se(e, n, i) {
|
|
156
|
+
const t = e.columns, r = new Array(t.length);
|
|
157
|
+
let s = 1;
|
|
158
|
+
for (let h = 0; h < t.length; h++)
|
|
159
|
+
r[h] = ye(n[t[h].field]);
|
|
160
|
+
const a = new Array(t.length);
|
|
161
|
+
for (let h = 0; h < t.length; h++) {
|
|
162
|
+
const c = G(
|
|
163
|
+
r[h],
|
|
164
|
+
t[h].widthMm - e.paddingMm * 2,
|
|
165
|
+
{ fontSizePt: e.fontSizePt },
|
|
166
|
+
i
|
|
397
167
|
);
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
const contentBottom = () => toContentBottom(tplPage, current);
|
|
423
|
-
const contentTop = current.marginTopMm;
|
|
424
|
-
const pushCurrent = () => {
|
|
425
|
-
pages.push({
|
|
426
|
-
pageWidthMm: current.widthMm,
|
|
427
|
-
pageHeightMm: current.heightMm,
|
|
428
|
-
marginTopMm: current.marginTopMm,
|
|
429
|
-
marginBottomMm: current.marginBottomMm,
|
|
430
|
-
marginLeftMm: current.marginLeftMm,
|
|
431
|
-
marginRightMm: current.marginRightMm,
|
|
432
|
-
components: current.components
|
|
168
|
+
a[h] = c, c.length > s && (s = c.length);
|
|
169
|
+
}
|
|
170
|
+
const o = e.fontSizePt * q * 25.4 / 72, l = Math.max(
|
|
171
|
+
e.rowHeightFloorMm,
|
|
172
|
+
s * o + e.paddingMm * 2
|
|
173
|
+
), d = new Array(t.length);
|
|
174
|
+
for (let h = 0; h < t.length; h++)
|
|
175
|
+
d[h] = { text: r[h], style: e.cellStyles[h] };
|
|
176
|
+
return { grid: { cells: [d], rowHeightsMm: [l] }, heightMm: l };
|
|
177
|
+
}
|
|
178
|
+
function We(e, n, i = {}) {
|
|
179
|
+
const t = typeof i == "number" ? { mmPerRow: i } : i, r = t.mmPerRow ?? 0, s = t.measurer ?? J, a = [], o = [];
|
|
180
|
+
let l = 0;
|
|
181
|
+
const d = (h) => `${h}_${(++l).toString(36)}`;
|
|
182
|
+
for (const h of e.pages) {
|
|
183
|
+
const c = Y(h), m = () => Me(h, c), u = c.marginTopMm, g = () => {
|
|
184
|
+
o.push({
|
|
185
|
+
pageWidthMm: c.widthMm,
|
|
186
|
+
pageHeightMm: c.heightMm,
|
|
187
|
+
marginTopMm: c.marginTopMm,
|
|
188
|
+
marginBottomMm: c.marginBottomMm,
|
|
189
|
+
marginLeftMm: c.marginLeftMm,
|
|
190
|
+
marginRightMm: c.marginRightMm,
|
|
191
|
+
components: c.components
|
|
433
192
|
});
|
|
434
193
|
};
|
|
435
|
-
for (const
|
|
436
|
-
if (
|
|
437
|
-
|
|
194
|
+
for (const M of h.components) {
|
|
195
|
+
if (M.kind !== "list") {
|
|
196
|
+
c.components.push(M);
|
|
438
197
|
continue;
|
|
439
198
|
}
|
|
440
|
-
const
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
const columnsWidth = list.columns.reduce((s, c) => s + c.widthMm, 0);
|
|
447
|
-
const scale = columnsWidth > list.widthMm ? list.widthMm / columnsWidth : 1;
|
|
448
|
-
const scaledList = scale === 1 ? list : { ...list, columns: list.columns.map((c) => ({ ...c, widthMm: c.widthMm * scale })) };
|
|
449
|
-
const inter = {
|
|
450
|
-
...interList(scaledList, measurer),
|
|
451
|
-
rowHeightFloorMm: scaledList.rowHeightMm ?? 0
|
|
452
|
-
};
|
|
453
|
-
const headerComp = {
|
|
199
|
+
const p = M, k = n[p.dataset];
|
|
200
|
+
Array.isArray(k) || a.push(`数据集 ${p.dataset} 未提供数据,列表 ${p.id ?? ""} 输出为空`);
|
|
201
|
+
const T = Array.isArray(k) ? k : [], E = p.columns.reduce((f, b) => f + b.widthMm, 0), w = E > p.widthMm ? p.widthMm / E : 1, I = w === 1 ? p : { ...p, columns: p.columns.map((f) => ({ ...f, widthMm: f.widthMm * w })) }, R = {
|
|
202
|
+
...we(I, s),
|
|
203
|
+
rowHeightFloorMm: I.rowHeightMm ?? 0
|
|
204
|
+
}, D = {
|
|
454
205
|
kind: "rect",
|
|
455
|
-
leftMm:
|
|
206
|
+
leftMm: p.leftMm,
|
|
456
207
|
topMm: 0,
|
|
457
|
-
widthMm:
|
|
458
|
-
heightMm:
|
|
459
|
-
grid:
|
|
460
|
-
nid:
|
|
461
|
-
style:
|
|
208
|
+
widthMm: p.widthMm,
|
|
209
|
+
heightMm: R.headerHeightMm,
|
|
210
|
+
grid: R.headerGrid,
|
|
211
|
+
nid: d("listh"),
|
|
212
|
+
style: R.borderStyle
|
|
462
213
|
};
|
|
463
|
-
let
|
|
464
|
-
const
|
|
465
|
-
|
|
214
|
+
let $ = p.topMm;
|
|
215
|
+
const B = (f, b) => {
|
|
216
|
+
f.components.push({ ...D, topMm: b });
|
|
466
217
|
};
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
current.components = next.components;
|
|
475
|
-
current.heightMm = next.heightMm;
|
|
476
|
-
if (scaledList.headerEveryPage !== false) {
|
|
477
|
-
placeHeader(current, list.topMm);
|
|
478
|
-
y = list.topMm + inter.headerHeightMm;
|
|
479
|
-
} else {
|
|
480
|
-
y = contentTop;
|
|
481
|
-
}
|
|
218
|
+
B(c, $), $ += R.headerHeightMm + r;
|
|
219
|
+
for (let f = 0; f < T.length; f++) {
|
|
220
|
+
const b = Se(R, T[f], s);
|
|
221
|
+
if ($ + b.heightMm > m()) {
|
|
222
|
+
g();
|
|
223
|
+
const P = Y(h);
|
|
224
|
+
c.components = P.components, c.heightMm = P.heightMm, I.headerEveryPage !== !1 ? (B(c, p.topMm), $ = p.topMm + R.headerHeightMm) : $ = u;
|
|
482
225
|
}
|
|
483
|
-
|
|
226
|
+
c.components.push({
|
|
484
227
|
kind: "rect",
|
|
485
|
-
leftMm:
|
|
486
|
-
topMm:
|
|
487
|
-
widthMm:
|
|
488
|
-
heightMm:
|
|
489
|
-
grid:
|
|
490
|
-
nid:
|
|
491
|
-
style:
|
|
492
|
-
});
|
|
493
|
-
y += rowGrid.heightMm;
|
|
228
|
+
leftMm: p.leftMm,
|
|
229
|
+
topMm: $,
|
|
230
|
+
widthMm: p.widthMm,
|
|
231
|
+
heightMm: b.heightMm,
|
|
232
|
+
grid: b.grid,
|
|
233
|
+
nid: d("listr"),
|
|
234
|
+
style: R.borderStyle
|
|
235
|
+
}), $ += b.heightMm;
|
|
494
236
|
}
|
|
495
237
|
}
|
|
496
|
-
|
|
238
|
+
g();
|
|
497
239
|
}
|
|
498
240
|
return {
|
|
499
|
-
plan: { schemaVersion:
|
|
500
|
-
warnings
|
|
241
|
+
plan: { schemaVersion: se, pages: o },
|
|
242
|
+
warnings: a
|
|
501
243
|
};
|
|
502
244
|
}
|
|
503
|
-
|
|
504
|
-
// src/render/grid-geometry.ts
|
|
505
|
-
function cumulate(sizesMm, totalMm) {
|
|
506
|
-
const n = sizesMm.length;
|
|
507
|
-
if (n === 0) return [];
|
|
508
|
-
const sum = sizesMm.reduce((s, v) => s + v, 0);
|
|
509
|
-
const scale = sum > 0 && totalMm > 0 ? totalMm / sum : 1;
|
|
510
|
-
const out = [];
|
|
511
|
-
let acc = 0;
|
|
512
|
-
for (let i = 0; i < n; i++) {
|
|
513
|
-
const size = Math.max(0, sizesMm[i] * scale);
|
|
514
|
-
out.push({ pos: acc, size });
|
|
515
|
-
acc += size;
|
|
516
|
-
}
|
|
517
|
-
return out;
|
|
518
|
-
}
|
|
519
|
-
function resolveGridLayout(grid, compWidthMm, compHeightMm) {
|
|
520
|
-
const rowsRaw = grid.cells ?? [];
|
|
521
|
-
const rowCount = Math.max(rowsRaw.length, 1);
|
|
522
|
-
const colCount = grid.colWidthsMm?.length ?? Math.max(1, ...rowsRaw.map((r) => Array.isArray(r) ? r.length : 0));
|
|
523
|
-
const widths = grid.colWidthsMm?.length ? cumulate(grid.colWidthsMm, compWidthMm) : Array.from({ length: colCount }, (_, i) => ({
|
|
524
|
-
pos: compWidthMm * i / colCount,
|
|
525
|
-
size: compWidthMm / colCount
|
|
526
|
-
}));
|
|
527
|
-
const colPos = (ci) => ci <= 0 ? 0 : ci >= colCount ? widths[widths.length - 1].pos + widths[widths.length - 1].size : widths[ci].pos;
|
|
528
|
-
const heights = grid.rowHeightsMm?.length ? cumulate(grid.rowHeightsMm, compHeightMm) : Array.from({ length: rowCount }, (_, i) => ({
|
|
529
|
-
pos: compHeightMm * i / rowCount,
|
|
530
|
-
size: compHeightMm / rowCount
|
|
531
|
-
}));
|
|
532
|
-
const rowPos = (ri) => ri <= 0 ? 0 : ri >= rowCount ? heights[heights.length - 1].pos + heights[heights.length - 1].size : heights[ri].pos;
|
|
533
|
-
const occupied = /* @__PURE__ */ new Set();
|
|
534
|
-
const key = (r, c) => `${r}:${c}`;
|
|
535
|
-
const cells = [];
|
|
536
|
-
const vBridge = /* @__PURE__ */ new Set();
|
|
537
|
-
const hBridge = /* @__PURE__ */ new Set();
|
|
538
|
-
const vKey = (c, r) => `v${c}:${r}`;
|
|
539
|
-
const hKey = (r, c) => `h${r}:${c}`;
|
|
540
|
-
rowsRaw.forEach((row, ri) => {
|
|
541
|
-
if (!Array.isArray(row)) return;
|
|
542
|
-
let ci = 0;
|
|
543
|
-
for (const cell of row) {
|
|
544
|
-
while (ci < colCount && occupied.has(key(ri, ci))) ci++;
|
|
545
|
-
if (ci >= colCount) break;
|
|
546
|
-
const colSpan = Math.max(1, Math.min(cell?.colSpan ?? 1, colCount - ci));
|
|
547
|
-
const rowSpan = Math.max(1, cell?.rowSpan ?? 1);
|
|
548
|
-
const rowEnd = Math.min(rowCount, ri + rowSpan);
|
|
549
|
-
const colEnd = Math.min(colCount, ci + colSpan);
|
|
550
|
-
for (let dr = ri; dr < rowEnd; dr++) {
|
|
551
|
-
for (let dc = ci; dc < colEnd; dc++) {
|
|
552
|
-
occupied.add(key(dr, dc));
|
|
553
|
-
}
|
|
554
|
-
}
|
|
555
|
-
for (let c = ci + 1; c < colEnd; c++) {
|
|
556
|
-
for (let r = ri; r < rowEnd; r++) vBridge.add(vKey(c, r));
|
|
557
|
-
}
|
|
558
|
-
for (let r = ri + 1; r < rowEnd; r++) {
|
|
559
|
-
for (let c = ci; c < colEnd; c++) hBridge.add(hKey(r, c));
|
|
560
|
-
}
|
|
561
|
-
const xMm = colPos(ci);
|
|
562
|
-
const yMm = rowPos(ri);
|
|
563
|
-
cells.push({
|
|
564
|
-
ri,
|
|
565
|
-
ci,
|
|
566
|
-
cell: cell ?? {},
|
|
567
|
-
xMm,
|
|
568
|
-
yMm,
|
|
569
|
-
widthMm: colPos(colEnd) - xMm,
|
|
570
|
-
heightMm: rowPos(rowEnd) - yMm
|
|
571
|
-
});
|
|
572
|
-
ci = colEnd;
|
|
573
|
-
}
|
|
574
|
-
});
|
|
575
|
-
const edges = [];
|
|
576
|
-
for (let c = 1; c < colCount; c++) {
|
|
577
|
-
let runStart = -1;
|
|
578
|
-
for (let r = 0; r <= rowCount; r++) {
|
|
579
|
-
const open = r < rowCount && !vBridge.has(vKey(c, r));
|
|
580
|
-
if (open && runStart < 0) runStart = r;
|
|
581
|
-
if (!open && runStart >= 0) {
|
|
582
|
-
edges.push({ kind: "v", pos: colPos(c), from: rowPos(runStart), to: rowPos(r) });
|
|
583
|
-
runStart = -1;
|
|
584
|
-
}
|
|
585
|
-
}
|
|
586
|
-
}
|
|
587
|
-
for (let r = 1; r < rowCount; r++) {
|
|
588
|
-
let runStart = -1;
|
|
589
|
-
for (let c = 0; c <= colCount; c++) {
|
|
590
|
-
const open = c < colCount && !hBridge.has(hKey(r, c));
|
|
591
|
-
if (open && runStart < 0) runStart = c;
|
|
592
|
-
if (!open && runStart >= 0) {
|
|
593
|
-
edges.push({ kind: "h", pos: rowPos(r), from: colPos(runStart), to: colPos(c) });
|
|
594
|
-
runStart = -1;
|
|
595
|
-
}
|
|
596
|
-
}
|
|
597
|
-
}
|
|
598
|
-
return { columns: widths, rows: heights, cells, edges };
|
|
599
|
-
}
|
|
600
|
-
|
|
601
|
-
// src/render/style.ts
|
|
602
|
-
function resolveFontSize(style, dpi = 96, defaultPt = DEFAULT_FONT_PT) {
|
|
603
|
-
if (style?.fontSizePx != null) {
|
|
604
|
-
return { fontSizePt: style.fontSizePx * 72 / dpi, fontSizePx: style.fontSizePx };
|
|
605
|
-
}
|
|
606
|
-
const pt = style?.fontSize ?? defaultPt;
|
|
607
|
-
return { fontSizePt: pt, fontSizePx: ptToPx(pt, dpi) };
|
|
608
|
-
}
|
|
609
|
-
function resolveStroke(style, fallbackColor = DEFAULT_STROKE_COLOR) {
|
|
610
|
-
return {
|
|
611
|
-
color: style?.borderColor ?? style?.lineColor ?? fallbackColor,
|
|
612
|
-
widthPt: style?.lineWidthPt ?? DEFAULT_BORDER_PT
|
|
613
|
-
};
|
|
614
|
-
}
|
|
615
|
-
function resolveTextColor(style, fallback = DEFAULT_TEXT_COLOR) {
|
|
616
|
-
return style?.color ?? fallback;
|
|
617
|
-
}
|
|
618
|
-
function resolveLineHeight(style) {
|
|
619
|
-
return style?.lineHeight ?? LINE_HEIGHT;
|
|
620
|
-
}
|
|
621
|
-
function resolveBoxBorders(style) {
|
|
622
|
-
const top = style?.borderTop !== false;
|
|
623
|
-
const right = style?.borderRight !== false;
|
|
624
|
-
const bottom = style?.borderBottom !== false;
|
|
625
|
-
const left = style?.borderLeft !== false;
|
|
626
|
-
return { top, right, bottom, left, inner: top || right || bottom || left };
|
|
627
|
-
}
|
|
628
|
-
|
|
629
|
-
// src/render/dom.ts
|
|
630
|
-
var CLS = {
|
|
245
|
+
const Te = {
|
|
631
246
|
root: "mr-root",
|
|
632
247
|
page: "mr-page",
|
|
633
248
|
comp: "mr-comp",
|
|
@@ -644,848 +259,528 @@ var CLS = {
|
|
|
644
259
|
cell: "mr-cell",
|
|
645
260
|
unknown: "mr-unknown"
|
|
646
261
|
};
|
|
647
|
-
function
|
|
648
|
-
return
|
|
262
|
+
function C(e, n) {
|
|
263
|
+
return n?.classNames?.[e] ?? Te[e];
|
|
649
264
|
}
|
|
650
|
-
|
|
265
|
+
class H {
|
|
651
266
|
constructor() {
|
|
652
267
|
this.props = [];
|
|
653
268
|
}
|
|
654
|
-
add(
|
|
655
|
-
|
|
656
|
-
this.props.push([prop, String(value)]);
|
|
657
|
-
return this;
|
|
269
|
+
add(n, i) {
|
|
270
|
+
return i == null || i === !1 || i === "" ? this : (this.props.push([n, String(i)]), this);
|
|
658
271
|
}
|
|
659
|
-
mm(
|
|
660
|
-
return this.add(
|
|
272
|
+
mm(n, i, t, r = 2) {
|
|
273
|
+
return this.add(n, `${_(de(i, t), r)}px`);
|
|
661
274
|
}
|
|
662
275
|
toString() {
|
|
663
|
-
let
|
|
664
|
-
for (const [
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
if (grid.rowHeightsMm?.[ri] != null) {
|
|
700
|
-
new StyleBag().mm("height", grid.rowHeightsMm[ri], dpi).applyTo(rowEl);
|
|
701
|
-
}
|
|
702
|
-
(row || []).forEach((cell) => {
|
|
703
|
-
const cellEl = doc.createElement("td");
|
|
704
|
-
cellEl.className = classOf("cell", options);
|
|
705
|
-
if (cell?.colSpan) cellEl.colSpan = cell.colSpan;
|
|
706
|
-
if (cell?.rowSpan) cellEl.rowSpan = cell.rowSpan;
|
|
707
|
-
const cellBag = new StyleBag();
|
|
708
|
-
if (border) cellBag.add("border", border);
|
|
709
|
-
if (cell?.style) {
|
|
710
|
-
const st = cell.style;
|
|
711
|
-
cellBag.add("text-align", st.align).add("vertical-align", st.verticalAlign).add("background-color", st.backgroundColor).add("color", st.color).add("font-weight", st.bold ? "700" : void 0);
|
|
712
|
-
cellBag.add("font-size", `${round(resolveFontSize(st, dpi).fontSizePx, 2)}px`);
|
|
713
|
-
}
|
|
714
|
-
cellBag.applyTo(cellEl);
|
|
715
|
-
if (cell?.text != null) cellEl.textContent = cell.text;
|
|
716
|
-
if (cell?.children?.length) {
|
|
717
|
-
for (const child of cell.children) {
|
|
718
|
-
cellEl.appendChild(renderComponent(child, dpi, options, doc));
|
|
719
|
-
}
|
|
276
|
+
let n = "";
|
|
277
|
+
for (const [i, t] of this.props)
|
|
278
|
+
n += `${i}:${t};`;
|
|
279
|
+
return n;
|
|
280
|
+
}
|
|
281
|
+
applyTo(n) {
|
|
282
|
+
const i = this.toString();
|
|
283
|
+
i && (n.style.cssText = i);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
function te(e, n, i) {
|
|
287
|
+
const t = n.style || {};
|
|
288
|
+
e.add("color", t.color).add("background-color", t.backgroundColor).add("font-family", t.fontFamily).add("font-weight", t.bold ? "700" : void 0).add("font-style", t.italic ? "italic" : void 0).add("text-decoration", t.underline ? "underline" : void 0).add("letter-spacing", t.letterSpacing != null ? `${t.letterSpacing}pt` : void 0).add("opacity", t.opacity != null ? String(t.opacity) : void 0).add("transform", t.rotateDeg ? `rotate(${t.rotateDeg}deg)` : void 0);
|
|
289
|
+
const r = W(t, i);
|
|
290
|
+
e.add("font-size", `${_(r.fontSizePx, 2)}px`);
|
|
291
|
+
}
|
|
292
|
+
function ve(e, n, i, t, r) {
|
|
293
|
+
const s = r.createElement("table");
|
|
294
|
+
if (s.className = C("grid", t), new H().add("width", "100%").add("height", "100%").add("border-collapse", "collapse").add("table-layout", e.colWidthsMm ? "fixed" : "auto").applyTo(s), e.colWidthsMm) {
|
|
295
|
+
const d = r.createElement("colgroup");
|
|
296
|
+
for (const h of e.colWidthsMm) {
|
|
297
|
+
const c = r.createElement("col");
|
|
298
|
+
new H().mm("width", h, i).applyTo(c), d.appendChild(c);
|
|
299
|
+
}
|
|
300
|
+
s.appendChild(d);
|
|
301
|
+
}
|
|
302
|
+
const a = V(n.style), o = F(n.style), l = a.inner ? `${_(o.widthPt * i / 72, 2)}px solid ${o.color}` : "";
|
|
303
|
+
return e.cells.forEach((d, h) => {
|
|
304
|
+
const c = r.createElement("tr");
|
|
305
|
+
c.className = C("row", t), e.rowHeightsMm?.[h] != null && new H().mm("height", e.rowHeightsMm[h], i).applyTo(c), (d || []).forEach((m) => {
|
|
306
|
+
const u = r.createElement("td");
|
|
307
|
+
u.className = C("cell", t), m?.colSpan && (u.colSpan = m.colSpan), m?.rowSpan && (u.rowSpan = m.rowSpan);
|
|
308
|
+
const g = new H();
|
|
309
|
+
if (l && g.add("border", l), m?.style) {
|
|
310
|
+
const M = m.style;
|
|
311
|
+
g.add("text-align", M.align).add("vertical-align", M.verticalAlign).add("background-color", M.backgroundColor).add("color", M.color).add("font-weight", M.bold ? "700" : void 0), g.add("font-size", `${_(W(M, i).fontSizePx, 2)}px`);
|
|
720
312
|
}
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
}
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
const
|
|
313
|
+
if (g.applyTo(u), m?.text != null && (u.textContent = m.text), m?.children?.length)
|
|
314
|
+
for (const M of m.children)
|
|
315
|
+
u.appendChild(ne(M, i, t, r));
|
|
316
|
+
c.appendChild(u);
|
|
317
|
+
}), s.appendChild(c);
|
|
318
|
+
}), s;
|
|
319
|
+
}
|
|
320
|
+
function Ce(e, n, i, t) {
|
|
321
|
+
const r = t.createElement("div");
|
|
322
|
+
r.className = C("text", i);
|
|
323
|
+
const s = e.style || {}, a = new H().add("text-align", s.align).add("display", "flex").add("flex-direction", "column").add(
|
|
732
324
|
"justify-content",
|
|
733
325
|
s.verticalAlign === "middle" ? "center" : s.verticalAlign === "bottom" ? "flex-end" : "flex-start"
|
|
734
326
|
).add("overflow", "hidden");
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
const
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
const
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
const segEl = doc.createElement("span");
|
|
747
|
-
segEl.className = classOf("segment", options);
|
|
748
|
-
segEl.textContent = seg.kind === "field" ? seg.field ?? "" : seg.text ?? "";
|
|
749
|
-
if (seg.style) {
|
|
750
|
-
const segBag = new StyleBag().add("color", seg.style.color).add("font-weight", seg.style.bold ? "700" : void 0);
|
|
751
|
-
segBag.add("font-size", `${round(resolveFontSize(seg.style, dpi).fontSizePx, 2)}px`);
|
|
752
|
-
segBag.applyTo(segEl);
|
|
327
|
+
if (te(a, e, n), a.applyTo(r), Z(e)) {
|
|
328
|
+
const o = t.createElement("div");
|
|
329
|
+
o.className = C("rich", i);
|
|
330
|
+
for (const l of e.richParagraphs) {
|
|
331
|
+
const d = t.createElement("div");
|
|
332
|
+
d.className = C("paragraph", i), new H().add("text-align", l.align).add("line-height", l.lineHeight != null ? String(l.lineHeight) : void 0).mm("margin-top", l.spaceBeforeMm ?? 0, n).mm("margin-bottom", l.spaceAfterMm ?? 0, n).mm("text-indent", l.indentMm ?? 0, n).applyTo(d);
|
|
333
|
+
for (const c of l.segments || []) {
|
|
334
|
+
const m = t.createElement("span");
|
|
335
|
+
if (m.className = C("segment", i), m.textContent = c.kind === "field" ? c.field ?? "" : c.text ?? "", c.style) {
|
|
336
|
+
const u = new H().add("color", c.style.color).add("font-weight", c.style.bold ? "700" : void 0);
|
|
337
|
+
u.add("font-size", `${_(W(c.style, n).fontSizePx, 2)}px`), u.applyTo(m);
|
|
753
338
|
}
|
|
754
|
-
|
|
339
|
+
d.appendChild(m);
|
|
755
340
|
}
|
|
756
|
-
|
|
757
|
-
}
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
const
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
if (
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
}
|
|
813
|
-
|
|
814
|
-
const wrap = doc.createElement("div");
|
|
815
|
-
wrap.className = `${classOf("comp", options)} mr-kind-${comp.kind}`;
|
|
816
|
-
const bag = new StyleBag().add("position", "absolute").mm("left", comp.leftMm, dpi).mm("top", comp.topMm, dpi).mm("width", comp.widthMm, dpi).mm("height", comp.heightMm, dpi).add("box-sizing", "border-box");
|
|
817
|
-
applyComponentStyle(bag, comp, dpi);
|
|
818
|
-
bag.applyTo(wrap);
|
|
819
|
-
if (isImageBackedComponent(comp)) {
|
|
820
|
-
wrap.appendChild(renderImage(comp, options, doc));
|
|
821
|
-
return wrap;
|
|
822
|
-
}
|
|
823
|
-
if (comp.kind === "text") {
|
|
824
|
-
wrap.appendChild(renderText(comp, dpi, options, doc));
|
|
825
|
-
return wrap;
|
|
826
|
-
}
|
|
827
|
-
if (comp.grid) {
|
|
828
|
-
const shape = renderShape(comp, dpi, options, doc);
|
|
829
|
-
shape.appendChild(renderGrid(comp.grid, comp, dpi, options, doc));
|
|
830
|
-
wrap.appendChild(shape);
|
|
831
|
-
return wrap;
|
|
832
|
-
}
|
|
833
|
-
if (comp.kind === "line" || comp.kind === "rect" || comp.kind === "ellipse" || comp.kind === "chart") {
|
|
834
|
-
wrap.appendChild(renderShape(comp, dpi, options, doc));
|
|
835
|
-
return wrap;
|
|
836
|
-
}
|
|
837
|
-
const ph = doc.createElement("div");
|
|
838
|
-
ph.className = classOf("unknown", options);
|
|
839
|
-
ph.textContent = comp.fallbackText ?? "";
|
|
840
|
-
wrap.appendChild(ph);
|
|
841
|
-
return wrap;
|
|
842
|
-
}
|
|
843
|
-
function renderPage(page, dpi, options, doc) {
|
|
844
|
-
const el = doc.createElement("div");
|
|
845
|
-
el.className = classOf("page", options);
|
|
846
|
-
new StyleBag().add("position", "relative").mm("width", page.pageWidthMm, dpi).mm("height", page.pageHeightMm, dpi).add("background-color", "#fff").add("overflow", "hidden").add("box-sizing", "border-box").applyTo(el);
|
|
847
|
-
for (const comp of page.components) {
|
|
848
|
-
el.appendChild(renderComponent(comp, dpi, options, doc));
|
|
849
|
-
}
|
|
850
|
-
return el;
|
|
851
|
-
}
|
|
852
|
-
function renderPlan(plan, doc, options = {}) {
|
|
853
|
-
const dpi = options.dpi ?? 96;
|
|
854
|
-
const root = doc.createElement("div");
|
|
855
|
-
root.className = classOf("root", options);
|
|
856
|
-
root.dataset.schemaVersion = plan.schemaVersion;
|
|
857
|
-
plan.pages.forEach((page) => {
|
|
858
|
-
root.appendChild(renderPage(page, dpi, options, doc));
|
|
859
|
-
});
|
|
860
|
-
return root;
|
|
861
|
-
}
|
|
862
|
-
|
|
863
|
-
// src/render/window.ts
|
|
864
|
-
function computePageWindow(input) {
|
|
865
|
-
const { pageHeightsPx, viewportHeightPx, scrollTopPx, overscan = 1, gapPx = 0 } = input;
|
|
866
|
-
const n = pageHeightsPx.length;
|
|
867
|
-
if (n === 0) {
|
|
341
|
+
o.appendChild(d);
|
|
342
|
+
}
|
|
343
|
+
return r.appendChild(o), r;
|
|
344
|
+
}
|
|
345
|
+
if (Array.isArray(e.lines) && e.lines.length > 0) {
|
|
346
|
+
const o = t.createElement("div");
|
|
347
|
+
o.className = C("lines", i), s.lineHeight != null && new H().add("line-height", String(s.lineHeight)).applyTo(o);
|
|
348
|
+
for (const l of e.lines) {
|
|
349
|
+
const d = t.createElement("div");
|
|
350
|
+
d.className = C("line", i), d.textContent = l, o.appendChild(d);
|
|
351
|
+
}
|
|
352
|
+
return r.appendChild(o), r;
|
|
353
|
+
}
|
|
354
|
+
return r.textContent = e.text ?? "", r;
|
|
355
|
+
}
|
|
356
|
+
function ke(e, n, i) {
|
|
357
|
+
const t = i.createElement("img");
|
|
358
|
+
return t.className = C("image", n), t.src = e.imageData, new H().add("width", "100%").add("height", "100%").add("object-fit", "contain").add("display", "block").applyTo(t), t.alt = e.kind, t;
|
|
359
|
+
}
|
|
360
|
+
function X(e, n, i, t) {
|
|
361
|
+
const r = t.createElement("div");
|
|
362
|
+
r.className = C("shape", i);
|
|
363
|
+
const s = e.style || {}, a = F(s), o = V(s), l = `${_(a.widthPt * n / 72, 2)}px solid ${a.color}`, d = new H();
|
|
364
|
+
return e.grid || e.kind === "rect" ? (o.top && d.add("border-top", l), o.right && d.add("border-right", l), o.bottom && d.add("border-bottom", l), o.left && d.add("border-left", l)) : e.kind === "ellipse" ? (o.inner && d.add("border", l).add("border-radius", "50%"), s.backgroundColor && d.add("background-color", s.backgroundColor)) : e.kind === "line" && d.add("height", "0").add("border-top", l), d.add("box-sizing", "border-box").add("width", "100%").add("height", "100%"), d.applyTo(r), r;
|
|
365
|
+
}
|
|
366
|
+
function ne(e, n, i, t) {
|
|
367
|
+
const r = t.createElement("div");
|
|
368
|
+
r.className = `${C("comp", i)} mr-kind-${e.kind}`;
|
|
369
|
+
const s = new H().add("position", "absolute").mm("left", e.leftMm, n).mm("top", e.topMm, n).mm("width", e.widthMm, n).mm("height", e.heightMm, n).add("box-sizing", "border-box");
|
|
370
|
+
if (te(s, e, n), s.applyTo(r), le(e))
|
|
371
|
+
return r.appendChild(ke(e, i, t)), r;
|
|
372
|
+
if (e.kind === "text")
|
|
373
|
+
return r.appendChild(Ce(e, n, i, t)), r;
|
|
374
|
+
if (e.grid) {
|
|
375
|
+
const o = X(e, n, i, t);
|
|
376
|
+
return o.appendChild(ve(e.grid, e, n, i, t)), r.appendChild(o), r;
|
|
377
|
+
}
|
|
378
|
+
if (e.kind === "line" || e.kind === "rect" || e.kind === "ellipse" || e.kind === "chart")
|
|
379
|
+
return r.appendChild(X(e, n, i, t)), r;
|
|
380
|
+
const a = t.createElement("div");
|
|
381
|
+
return a.className = C("unknown", i), a.textContent = e.fallbackText ?? "", r.appendChild(a), r;
|
|
382
|
+
}
|
|
383
|
+
function xe(e, n, i, t) {
|
|
384
|
+
const r = t.createElement("div");
|
|
385
|
+
r.className = C("page", i), new H().add("position", "relative").mm("width", e.pageWidthMm, n).mm("height", e.pageHeightMm, n).add("background-color", "#fff").add("overflow", "hidden").add("box-sizing", "border-box").applyTo(r);
|
|
386
|
+
for (const s of e.components)
|
|
387
|
+
r.appendChild(ne(s, n, i, t));
|
|
388
|
+
return r;
|
|
389
|
+
}
|
|
390
|
+
function Ie(e, n, i = {}) {
|
|
391
|
+
const t = i.dpi ?? 96, r = n.createElement("div");
|
|
392
|
+
return r.className = C("root", i), r.dataset.schemaVersion = e.schemaVersion, e.pages.forEach((s) => {
|
|
393
|
+
r.appendChild(xe(s, t, i, n));
|
|
394
|
+
}), r;
|
|
395
|
+
}
|
|
396
|
+
function Pe(e) {
|
|
397
|
+
const { pageHeightsPx: n, viewportHeightPx: i, scrollTopPx: t, overscan: r = 1, gapPx: s = 0 } = e, a = n.length;
|
|
398
|
+
if (a === 0)
|
|
868
399
|
return { start: 0, end: -1, padTopPx: 0, padBottomPx: 0 };
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
let
|
|
881
|
-
|
|
882
|
-
const
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
const
|
|
891
|
-
const target = offsets[cover] + Math.max(0, viewportHeightPx);
|
|
892
|
-
let visibleEnd = n - 1;
|
|
893
|
-
lo = 0;
|
|
894
|
-
hi = n - 1;
|
|
895
|
-
while (lo <= hi) {
|
|
896
|
-
const mid = lo + hi >> 1;
|
|
897
|
-
if (offsets[mid + 1] < target) {
|
|
898
|
-
lo = mid + 1;
|
|
899
|
-
} else {
|
|
900
|
-
visibleEnd = mid;
|
|
901
|
-
hi = mid - 1;
|
|
902
|
-
}
|
|
903
|
-
}
|
|
904
|
-
const end = Math.min(n - 1, visibleEnd + overscan);
|
|
905
|
-
const padTopPx = offsets[start];
|
|
906
|
-
const padBottomPx = Math.max(0, total - offsets[end + 1]);
|
|
907
|
-
return { start, end, padTopPx, padBottomPx };
|
|
908
|
-
}
|
|
909
|
-
|
|
910
|
-
// src/render/canvas.ts
|
|
911
|
-
var PX_PER_MM_BASE = 96 / 25.4;
|
|
912
|
-
function measurePageSizePx(page, dpi = 96) {
|
|
913
|
-
const pxPerMm = dpi / 96 * PX_PER_MM_BASE;
|
|
400
|
+
const o = Math.max(0, s), l = new Array(a + 1);
|
|
401
|
+
l[0] = 0;
|
|
402
|
+
for (let w = 0; w < a; w++)
|
|
403
|
+
l[w + 1] = l[w] + Math.max(0, n[w] ?? 0) + o;
|
|
404
|
+
const d = l[a], h = Math.max(0, t);
|
|
405
|
+
let c = 0, m = 0, u = a - 1;
|
|
406
|
+
for (; m <= u; ) {
|
|
407
|
+
const w = m + u >> 1;
|
|
408
|
+
l[w] <= h ? (c = w, m = w + 1) : u = w - 1;
|
|
409
|
+
}
|
|
410
|
+
const g = Math.max(0, Math.min(a - 1, c - r)), M = l[c] + Math.max(0, i);
|
|
411
|
+
let p = a - 1;
|
|
412
|
+
for (m = 0, u = a - 1; m <= u; ) {
|
|
413
|
+
const w = m + u >> 1;
|
|
414
|
+
l[w + 1] < M ? m = w + 1 : (p = w, u = w - 1);
|
|
415
|
+
}
|
|
416
|
+
const k = Math.min(a - 1, p + r), T = l[g], E = Math.max(0, d - l[k + 1]);
|
|
417
|
+
return { start: g, end: k, padTopPx: T, padBottomPx: E };
|
|
418
|
+
}
|
|
419
|
+
const U = 96 / 25.4;
|
|
420
|
+
function ie(e, n = 96) {
|
|
421
|
+
const i = n / 96 * U;
|
|
914
422
|
return {
|
|
915
|
-
widthPx: Math.max(1, Math.round(
|
|
916
|
-
heightPx: Math.max(1, Math.round(
|
|
423
|
+
widthPx: Math.max(1, Math.round(e.pageWidthMm * i)),
|
|
424
|
+
heightPx: Math.max(1, Math.round(e.pageHeightMm * i))
|
|
917
425
|
};
|
|
918
426
|
}
|
|
919
|
-
function
|
|
920
|
-
const
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
const
|
|
943
|
-
const
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
const
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
}
|
|
971
|
-
if (borders.inner) {
|
|
972
|
-
ctx.strokeStyle = stroke.color;
|
|
973
|
-
ctx.lineWidth = ptToPx(stroke.widthPt, dpi);
|
|
974
|
-
for (const e of layout.edges) {
|
|
975
|
-
ctx.beginPath();
|
|
976
|
-
if (e.kind === "v") {
|
|
977
|
-
ctx.moveTo(x + e.pos * pxPerMm, y + e.from * pxPerMm);
|
|
978
|
-
ctx.lineTo(x + e.pos * pxPerMm, y + e.to * pxPerMm);
|
|
979
|
-
} else {
|
|
980
|
-
ctx.moveTo(x + e.from * pxPerMm, y + e.pos * pxPerMm);
|
|
981
|
-
ctx.lineTo(x + e.to * pxPerMm, y + e.pos * pxPerMm);
|
|
982
|
-
}
|
|
983
|
-
ctx.stroke();
|
|
984
|
-
}
|
|
985
|
-
ctx.beginPath();
|
|
986
|
-
if (borders.top) {
|
|
987
|
-
ctx.moveTo(x, y);
|
|
988
|
-
ctx.lineTo(x + w, y);
|
|
989
|
-
}
|
|
990
|
-
if (borders.right) {
|
|
991
|
-
ctx.moveTo(x + w, y);
|
|
992
|
-
ctx.lineTo(x + w, y + h);
|
|
993
|
-
}
|
|
994
|
-
if (borders.bottom) {
|
|
995
|
-
ctx.moveTo(x + w, y + h);
|
|
996
|
-
ctx.lineTo(x, y + h);
|
|
997
|
-
}
|
|
998
|
-
if (borders.left) {
|
|
999
|
-
ctx.moveTo(x, y + h);
|
|
1000
|
-
ctx.lineTo(x, y);
|
|
1001
|
-
}
|
|
1002
|
-
ctx.stroke();
|
|
1003
|
-
}
|
|
1004
|
-
for (const box of layout.cells) {
|
|
1005
|
-
const text = typeof box.cell.text === "string" ? box.cell.text : "";
|
|
1006
|
-
if (!text) continue;
|
|
1007
|
-
const st = box.cell.style;
|
|
1008
|
-
const fontSizePt = st?.fontSize ?? DEFAULT_FONT_PT;
|
|
1009
|
-
const lines = wrapText(
|
|
1010
|
-
text,
|
|
1011
|
-
box.widthMm - 1,
|
|
1012
|
-
{ fontSizePt },
|
|
1013
|
-
measurer
|
|
1014
|
-
).join("\n");
|
|
1015
|
-
drawTextBlock(
|
|
1016
|
-
ctx,
|
|
427
|
+
function Ae(e, n, i) {
|
|
428
|
+
const t = document.createElement("canvas"), { widthPx: r, heightPx: s } = ie(e, i);
|
|
429
|
+
t.width = Math.round(r * n), t.height = Math.round(s * n), t.style.width = `${r}px`, t.style.height = `${s}px`;
|
|
430
|
+
const a = t.getContext("2d");
|
|
431
|
+
if (!a)
|
|
432
|
+
throw new Error("当前环境不支持 Canvas 2D(测试需真浏览器,见 e2e/canvas.spec.ts)");
|
|
433
|
+
return a.scale(n, n), a.fillStyle = "#ffffff", a.fillRect(0, 0, r, s), { canvas: t, ctx: a };
|
|
434
|
+
}
|
|
435
|
+
function De(e, n = 96) {
|
|
436
|
+
return W(e, n).fontSizePx;
|
|
437
|
+
}
|
|
438
|
+
function re(e, n, i, t, r, s, a, o = "top") {
|
|
439
|
+
e.font = `${n.bold ? "bold " : ""}${n.fontSizePx}px ${a}`, e.fillStyle = n.color, e.textBaseline = "alphabetic";
|
|
440
|
+
const l = n.fontSizePx * n.lineHeight, d = n.text === "" ? [""] : n.text.split(`
|
|
441
|
+
`), h = d.length * l;
|
|
442
|
+
let c = t;
|
|
443
|
+
o === "middle" ? c = t + (s - h) / 2 : o === "bottom" && (c = t + s - h), d.forEach((m, u) => {
|
|
444
|
+
e.textAlign = n.align === "center" ? "center" : n.align === "right" ? "right" : "left";
|
|
445
|
+
const g = n.align === "center" ? i + r / 2 : n.align === "right" ? i + r : i;
|
|
446
|
+
e.fillText(m, g, c + u * l + n.fontSizePx * 0.8, r);
|
|
447
|
+
}), e.textAlign = "left";
|
|
448
|
+
}
|
|
449
|
+
function Ee(e, n, i, t, r, s, a, o, l, d, h) {
|
|
450
|
+
const c = ce(n, s / o, a / o), m = V(i.style), u = F(i.style);
|
|
451
|
+
for (const g of c.cells) {
|
|
452
|
+
const M = g.cell.style?.backgroundColor;
|
|
453
|
+
M && (e.fillStyle = M, e.fillRect(
|
|
454
|
+
t + g.xMm * o,
|
|
455
|
+
r + g.yMm * o,
|
|
456
|
+
g.widthMm * o,
|
|
457
|
+
g.heightMm * o
|
|
458
|
+
));
|
|
459
|
+
}
|
|
460
|
+
if (m.inner) {
|
|
461
|
+
e.strokeStyle = u.color, e.lineWidth = O(u.widthPt, l);
|
|
462
|
+
for (const g of c.edges)
|
|
463
|
+
e.beginPath(), g.kind === "v" ? (e.moveTo(t + g.pos * o, r + g.from * o), e.lineTo(t + g.pos * o, r + g.to * o)) : (e.moveTo(t + g.from * o, r + g.pos * o), e.lineTo(t + g.to * o, r + g.pos * o)), e.stroke();
|
|
464
|
+
e.beginPath(), m.top && (e.moveTo(t, r), e.lineTo(t + s, r)), m.right && (e.moveTo(t + s, r), e.lineTo(t + s, r + a)), m.bottom && (e.moveTo(t + s, r + a), e.lineTo(t, r + a)), m.left && (e.moveTo(t, r + a), e.lineTo(t, r)), e.stroke();
|
|
465
|
+
}
|
|
466
|
+
for (const g of c.cells) {
|
|
467
|
+
const M = typeof g.cell.text == "string" ? g.cell.text : "";
|
|
468
|
+
if (!M) continue;
|
|
469
|
+
const p = g.cell.style, k = p?.fontSize ?? j, T = G(
|
|
470
|
+
M,
|
|
471
|
+
g.widthMm - 1,
|
|
472
|
+
{ fontSizePt: k },
|
|
473
|
+
h
|
|
474
|
+
).join(`
|
|
475
|
+
`);
|
|
476
|
+
re(
|
|
477
|
+
e,
|
|
1017
478
|
{
|
|
1018
|
-
text:
|
|
1019
|
-
fontSizePx:
|
|
1020
|
-
bold:
|
|
1021
|
-
color:
|
|
1022
|
-
align:
|
|
1023
|
-
lineHeight:
|
|
479
|
+
text: T,
|
|
480
|
+
fontSizePx: W(p, l).fontSizePx,
|
|
481
|
+
bold: p?.bold ?? !1,
|
|
482
|
+
color: p?.color ?? Q(i.style, me),
|
|
483
|
+
align: p?.align ?? "left",
|
|
484
|
+
lineHeight: q
|
|
1024
485
|
},
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
Math.max(0, (
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
486
|
+
t + (g.xMm + 0.5) * o,
|
|
487
|
+
r + g.yMm * o,
|
|
488
|
+
Math.max(0, (g.widthMm - 1) * o),
|
|
489
|
+
g.heightMm * o,
|
|
490
|
+
d,
|
|
491
|
+
p?.verticalAlign ?? "middle"
|
|
1031
492
|
);
|
|
1032
493
|
}
|
|
1033
494
|
}
|
|
1034
|
-
function
|
|
1035
|
-
const
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
const h = comp.heightMm * pxPerMm;
|
|
1039
|
-
const s = comp.style ?? {};
|
|
1040
|
-
if (comp.grid) {
|
|
1041
|
-
drawGrid(ctx, comp.grid, comp, x, y, w, h, pxPerMm, dpi, fontFamily, measurer);
|
|
495
|
+
function oe(e, n, i, t, r, s) {
|
|
496
|
+
const a = n.leftMm * i, o = n.topMm * i, l = n.widthMm * i, d = n.heightMm * i, h = n.style ?? {};
|
|
497
|
+
if (n.grid) {
|
|
498
|
+
Ee(e, n.grid, n, a, o, l, d, i, t, r, s);
|
|
1042
499
|
return;
|
|
1043
500
|
}
|
|
1044
|
-
switch (
|
|
501
|
+
switch (n.kind) {
|
|
1045
502
|
case "text": {
|
|
1046
|
-
const
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
503
|
+
const c = h.fontSize ?? j, m = Z(n) ? n.richParagraphs.map((u) => (u.segments ?? []).map((g) => g.text ?? g.field ?? "").join("")).join(`
|
|
504
|
+
`) : Array.isArray(n.lines) && n.lines.length > 0 ? n.lines.join(`
|
|
505
|
+
`) : G(n.text ?? "", n.widthMm, { fontSizePt: c }, s).join(`
|
|
506
|
+
`);
|
|
507
|
+
re(
|
|
508
|
+
e,
|
|
1050
509
|
{
|
|
1051
|
-
text,
|
|
1052
|
-
fontSizePx:
|
|
1053
|
-
bold:
|
|
1054
|
-
color:
|
|
1055
|
-
align:
|
|
1056
|
-
lineHeight:
|
|
510
|
+
text: m,
|
|
511
|
+
fontSizePx: W(h, t).fontSizePx,
|
|
512
|
+
bold: h.bold ?? !1,
|
|
513
|
+
color: Q(h),
|
|
514
|
+
align: h.align ?? "left",
|
|
515
|
+
lineHeight: he(h)
|
|
1057
516
|
},
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
517
|
+
a,
|
|
518
|
+
o,
|
|
519
|
+
l,
|
|
520
|
+
d,
|
|
521
|
+
r,
|
|
522
|
+
h.verticalAlign
|
|
1064
523
|
);
|
|
1065
524
|
break;
|
|
1066
525
|
}
|
|
1067
526
|
case "rect": {
|
|
1068
|
-
const
|
|
1069
|
-
|
|
1070
|
-
if (s.backgroundColor) {
|
|
1071
|
-
ctx.fillStyle = s.backgroundColor;
|
|
1072
|
-
ctx.fillRect(x, y, w, h);
|
|
1073
|
-
}
|
|
1074
|
-
if (borders.inner) {
|
|
1075
|
-
ctx.strokeStyle = stroke.color;
|
|
1076
|
-
ctx.lineWidth = ptToPx(stroke.widthPt, dpi);
|
|
1077
|
-
ctx.beginPath();
|
|
1078
|
-
if (borders.top) {
|
|
1079
|
-
ctx.moveTo(x, y);
|
|
1080
|
-
ctx.lineTo(x + w, y);
|
|
1081
|
-
}
|
|
1082
|
-
if (borders.right) {
|
|
1083
|
-
ctx.moveTo(x + w, y);
|
|
1084
|
-
ctx.lineTo(x + w, y + h);
|
|
1085
|
-
}
|
|
1086
|
-
if (borders.bottom) {
|
|
1087
|
-
ctx.moveTo(x + w, y + h);
|
|
1088
|
-
ctx.lineTo(x, y + h);
|
|
1089
|
-
}
|
|
1090
|
-
if (borders.left) {
|
|
1091
|
-
ctx.moveTo(x, y + h);
|
|
1092
|
-
ctx.lineTo(x, y);
|
|
1093
|
-
}
|
|
1094
|
-
ctx.stroke();
|
|
1095
|
-
}
|
|
527
|
+
const c = F(h), m = V(h);
|
|
528
|
+
h.backgroundColor && (e.fillStyle = h.backgroundColor, e.fillRect(a, o, l, d)), m.inner && (e.strokeStyle = c.color, e.lineWidth = O(c.widthPt, t), e.beginPath(), m.top && (e.moveTo(a, o), e.lineTo(a + l, o)), m.right && (e.moveTo(a + l, o), e.lineTo(a + l, o + d)), m.bottom && (e.moveTo(a + l, o + d), e.lineTo(a, o + d)), m.left && (e.moveTo(a, o + d), e.lineTo(a, o)), e.stroke());
|
|
1096
529
|
break;
|
|
1097
530
|
}
|
|
1098
531
|
case "line": {
|
|
1099
|
-
const
|
|
1100
|
-
|
|
1101
|
-
ctx.lineWidth = ptToPx(stroke.widthPt, dpi);
|
|
1102
|
-
ctx.beginPath();
|
|
1103
|
-
ctx.moveTo(x, y + h / 2);
|
|
1104
|
-
ctx.lineTo(x + w, y + h / 2);
|
|
1105
|
-
ctx.stroke();
|
|
532
|
+
const c = F({ ...h, borderColor: h.lineColor ?? h.borderColor });
|
|
533
|
+
e.strokeStyle = c.color, e.lineWidth = O(c.widthPt, t), e.beginPath(), e.moveTo(a, o + d / 2), e.lineTo(a + l, o + d / 2), e.stroke();
|
|
1106
534
|
break;
|
|
1107
535
|
}
|
|
1108
536
|
case "ellipse": {
|
|
1109
|
-
const
|
|
1110
|
-
|
|
1111
|
-
ctx.lineWidth = ptToPx(stroke.widthPt, dpi);
|
|
1112
|
-
if (s.backgroundColor) {
|
|
1113
|
-
ctx.fillStyle = s.backgroundColor;
|
|
1114
|
-
ctx.beginPath();
|
|
1115
|
-
ctx.ellipse(x + w / 2, y + h / 2, w / 2, h / 2, 0, 0, Math.PI * 2);
|
|
1116
|
-
ctx.fill();
|
|
1117
|
-
}
|
|
1118
|
-
ctx.beginPath();
|
|
1119
|
-
ctx.ellipse(x + w / 2, y + h / 2, w / 2, h / 2, 0, 0, Math.PI * 2);
|
|
1120
|
-
ctx.stroke();
|
|
537
|
+
const c = F(h);
|
|
538
|
+
e.strokeStyle = c.color, e.lineWidth = O(c.widthPt, t), h.backgroundColor && (e.fillStyle = h.backgroundColor, e.beginPath(), e.ellipse(a + l / 2, o + d / 2, l / 2, d / 2, 0, 0, Math.PI * 2), e.fill()), e.beginPath(), e.ellipse(a + l / 2, o + d / 2, l / 2, d / 2, 0, 0, Math.PI * 2), e.stroke();
|
|
1121
539
|
break;
|
|
1122
540
|
}
|
|
1123
541
|
}
|
|
1124
542
|
}
|
|
1125
|
-
function
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
const
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
const
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
}
|
|
1182
|
-
function
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
slot.appendChild(canvas);
|
|
1190
|
-
}
|
|
1191
|
-
canvas.width = Math.round(w * dpr);
|
|
1192
|
-
canvas.height = Math.round(h * dpr);
|
|
1193
|
-
canvas.style.width = `${w}px`;
|
|
1194
|
-
canvas.style.height = `${h}px`;
|
|
1195
|
-
const ctx = canvas.getContext("2d");
|
|
1196
|
-
if (!ctx) return;
|
|
1197
|
-
ctx.setTransform(1, 0, 0, 1, 0, 0);
|
|
1198
|
-
ctx.scale(dpr, dpr);
|
|
1199
|
-
ctx.fillStyle = "#ffffff";
|
|
1200
|
-
ctx.fillRect(0, 0, w, h);
|
|
1201
|
-
for (const comp of page.components) {
|
|
1202
|
-
drawComponent(ctx, comp, pxPerMm, dpi, fontFamily, measurer);
|
|
1203
|
-
}
|
|
1204
|
-
canvas.dataset.canvasPage = String(pageIndex);
|
|
1205
|
-
slot.style.height = `${h}px`;
|
|
1206
|
-
slot.style.width = `${w}px`;
|
|
1207
|
-
}
|
|
1208
|
-
function applyWindow(win) {
|
|
1209
|
-
windowState.start = win.start;
|
|
1210
|
-
windowState.end = win.end;
|
|
1211
|
-
topSpacer.style.height = `${win.start * gapPx + pageHeightsPx.slice(0, win.start).reduce((s, h) => s + h, 0)}px`;
|
|
1212
|
-
const below = plan.pages.length - 1 - win.end;
|
|
1213
|
-
bottomSpacer.style.height = `${below * gapPx + pageHeightsPx.slice(win.end + 1).reduce((s, h) => s + h, 0)}px`;
|
|
1214
|
-
const used = win.end - win.start + 1;
|
|
1215
|
-
slots.forEach((slot, i) => {
|
|
1216
|
-
if (i < used) {
|
|
1217
|
-
slot.style.display = "";
|
|
1218
|
-
const pageIndex = win.start + i;
|
|
1219
|
-
slot.style.height = `${pageHeightsPx[pageIndex] ?? 0}px`;
|
|
1220
|
-
} else {
|
|
1221
|
-
slot.style.display = "none";
|
|
543
|
+
function Oe(e, n = {}) {
|
|
544
|
+
if (typeof document > "u")
|
|
545
|
+
throw new Error("renderPlanToCanvas 需要浏览器环境(SSR 请在客户端钩子中调用)");
|
|
546
|
+
const i = n.dpr ?? (typeof devicePixelRatio == "number" ? devicePixelRatio : 1), t = n.dpi ?? 96, r = t / 96 * U, s = n.fontFamily ?? '"Microsoft YaHei", sans-serif', a = n.measurer ?? J, o = Math.max(0, n.start ?? 0), l = Math.min(e.pages.length - 1, n.end ?? e.pages.length - 1), d = [];
|
|
547
|
+
for (let h = o; h <= l; h++) {
|
|
548
|
+
const c = e.pages[h], { canvas: m, ctx: u } = Ae(c, i, t);
|
|
549
|
+
for (const g of c.components)
|
|
550
|
+
oe(u, g, r, t, s, a);
|
|
551
|
+
d.push(m);
|
|
552
|
+
}
|
|
553
|
+
return { canvases: d };
|
|
554
|
+
}
|
|
555
|
+
function je(e, n = {}) {
|
|
556
|
+
const i = n.dpr ?? (typeof devicePixelRatio == "number" ? devicePixelRatio : 1), t = n.dpi ?? 96, r = t / 96 * U, s = n.fontFamily ?? '"Microsoft YaHei", sans-serif', a = n.measurer ?? J, o = n.overscan ?? 1, l = n.gapPx ?? 18, d = n.pagesPerFrame ?? 1, h = e.pages.map((f) => f.pageHeightMm * r), c = Math.max(1, ...e.pages.map((f) => f.pageWidthMm * r)), m = { start: 0, end: -1 };
|
|
557
|
+
let u = null, g = null, M = null, p = null, k = [], T = 0, E = [];
|
|
558
|
+
function w() {
|
|
559
|
+
const f = u;
|
|
560
|
+
f.innerHTML = "", g = document.createElement("div"), g.style.cssText = `width:${c}px;margin:0 auto;`, M = document.createElement("div"), p = document.createElement("div"), g.appendChild(M), k = [];
|
|
561
|
+
const b = Math.min(e.pages.length, 3 + o * 2);
|
|
562
|
+
for (let P = 0; P < b; P++) {
|
|
563
|
+
const y = document.createElement("div");
|
|
564
|
+
y.style.cssText = `margin:0 auto ${l}px;box-shadow:0 2px 8px rgba(0,0,0,.35);background:#fff;`, g.appendChild(y), k.push(y);
|
|
565
|
+
}
|
|
566
|
+
g.appendChild(p), f.appendChild(g);
|
|
567
|
+
}
|
|
568
|
+
function I(f, b) {
|
|
569
|
+
const P = e.pages[b], { widthPx: y, heightPx: x } = ie(P, t);
|
|
570
|
+
let A = f.firstElementChild;
|
|
571
|
+
(!A || A.tagName !== "CANVAS") && (A = document.createElement("canvas"), f.innerHTML = "", f.appendChild(A)), A.width = Math.round(y * i), A.height = Math.round(x * i), A.style.width = `${y}px`, A.style.height = `${x}px`;
|
|
572
|
+
const z = A.getContext("2d");
|
|
573
|
+
if (z) {
|
|
574
|
+
z.setTransform(1, 0, 0, 1, 0, 0), z.scale(i, i), z.fillStyle = "#ffffff", z.fillRect(0, 0, y, x);
|
|
575
|
+
for (const ae of P.components)
|
|
576
|
+
oe(z, ae, r, t, s, a);
|
|
577
|
+
A.dataset.canvasPage = String(b), f.style.height = `${x}px`, f.style.width = `${y}px`;
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
function R(f) {
|
|
581
|
+
m.start = f.start, m.end = f.end, M.style.height = `${f.start * l + h.slice(0, f.start).reduce((y, x) => y + x, 0)}px`;
|
|
582
|
+
const b = e.pages.length - 1 - f.end;
|
|
583
|
+
p.style.height = `${b * l + h.slice(f.end + 1).reduce((y, x) => y + x, 0)}px`;
|
|
584
|
+
const P = f.end - f.start + 1;
|
|
585
|
+
k.forEach((y, x) => {
|
|
586
|
+
if (x < P) {
|
|
587
|
+
y.style.display = "";
|
|
588
|
+
const A = f.start + x;
|
|
589
|
+
y.style.height = `${h[A] ?? 0}px`;
|
|
590
|
+
} else
|
|
591
|
+
y.style.display = "none";
|
|
592
|
+
}), E = [];
|
|
593
|
+
for (let y = f.start; y <= f.end; y++) {
|
|
594
|
+
const x = k[y - f.start];
|
|
595
|
+
if (!x) continue;
|
|
596
|
+
x.firstElementChild?.dataset?.canvasPage !== String(y) && E.push(y);
|
|
597
|
+
}
|
|
598
|
+
D();
|
|
599
|
+
}
|
|
600
|
+
function D() {
|
|
601
|
+
T || E.length === 0 || (T = requestAnimationFrame(() => {
|
|
602
|
+
T = 0;
|
|
603
|
+
let f = Math.max(1, d);
|
|
604
|
+
for (; E.length > 0 && f-- > 0; ) {
|
|
605
|
+
const b = E.shift(), P = k[b - m.start];
|
|
606
|
+
P && I(P, b);
|
|
1222
607
|
}
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
raf = requestAnimationFrame(() => {
|
|
1236
|
-
raf = 0;
|
|
1237
|
-
let budget = Math.max(1, pagesPerFrame);
|
|
1238
|
-
while (queued.length > 0 && budget-- > 0) {
|
|
1239
|
-
const pageIndex = queued.shift();
|
|
1240
|
-
const slot = slots[pageIndex - windowState.start];
|
|
1241
|
-
if (slot) drawPageInto(slot, pageIndex);
|
|
1242
|
-
}
|
|
1243
|
-
if (queued.length > 0) scheduleFrame();
|
|
1244
|
-
});
|
|
1245
|
-
}
|
|
1246
|
-
function onScroll() {
|
|
1247
|
-
if (raf) return;
|
|
1248
|
-
raf = requestAnimationFrame(() => {
|
|
1249
|
-
raf = 0;
|
|
1250
|
-
const vp = viewport;
|
|
1251
|
-
const win = computePageWindow({
|
|
1252
|
-
pageHeightsPx,
|
|
1253
|
-
viewportHeightPx: vp.clientHeight,
|
|
1254
|
-
scrollTopPx: vp.scrollTop,
|
|
1255
|
-
overscan,
|
|
1256
|
-
gapPx
|
|
608
|
+
E.length > 0 && D();
|
|
609
|
+
}));
|
|
610
|
+
}
|
|
611
|
+
function $() {
|
|
612
|
+
T || (T = requestAnimationFrame(() => {
|
|
613
|
+
T = 0;
|
|
614
|
+
const f = u, b = Pe({
|
|
615
|
+
pageHeightsPx: h,
|
|
616
|
+
viewportHeightPx: f.clientHeight,
|
|
617
|
+
scrollTopPx: f.scrollTop,
|
|
618
|
+
overscan: o,
|
|
619
|
+
gapPx: l
|
|
1257
620
|
});
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
} else {
|
|
1261
|
-
scheduleFrame();
|
|
1262
|
-
}
|
|
1263
|
-
});
|
|
621
|
+
b.start !== m.start || b.end !== m.end ? R(b) : D();
|
|
622
|
+
}));
|
|
1264
623
|
}
|
|
624
|
+
let B = null;
|
|
1265
625
|
return {
|
|
1266
|
-
attach(
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
onScroll();
|
|
626
|
+
attach(f) {
|
|
627
|
+
if (typeof document > "u")
|
|
628
|
+
throw new Error("createCanvasPager 需要浏览器环境(SSR 请在客户端钩子中调用 attach)");
|
|
629
|
+
u = f, w(), f.addEventListener("scroll", $, { passive: !0 }), typeof ResizeObserver < "u" && (B = new ResizeObserver(() => $()), B.observe(f)), $();
|
|
1271
630
|
},
|
|
1272
631
|
destroy() {
|
|
1273
|
-
|
|
1274
|
-
raf = 0;
|
|
1275
|
-
viewport?.removeEventListener("scroll", onScroll);
|
|
1276
|
-
queued = [];
|
|
1277
|
-
contentEl?.remove();
|
|
1278
|
-
viewport = null;
|
|
632
|
+
T && cancelAnimationFrame(T), T = 0, B?.disconnect(), B = null, u?.removeEventListener("scroll", $), E = [], g?.remove(), u = null;
|
|
1279
633
|
},
|
|
1280
634
|
window() {
|
|
1281
|
-
return { ...
|
|
635
|
+
return { ...m };
|
|
1282
636
|
}
|
|
1283
637
|
};
|
|
1284
638
|
}
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
function num(v, fallback) {
|
|
1288
|
-
return typeof v === "number" && Number.isFinite(v) ? v : fallback;
|
|
639
|
+
function S(e, n) {
|
|
640
|
+
return typeof e == "number" && Number.isFinite(e) ? e : n;
|
|
1289
641
|
}
|
|
1290
|
-
function
|
|
1291
|
-
return typeof
|
|
642
|
+
function v(e, n = "") {
|
|
643
|
+
return typeof e == "string" ? e : n;
|
|
1292
644
|
}
|
|
1293
|
-
function
|
|
1294
|
-
return typeof
|
|
645
|
+
function N(e) {
|
|
646
|
+
return typeof e == "object" && e !== null && !Array.isArray(e);
|
|
1295
647
|
}
|
|
1296
|
-
function
|
|
1297
|
-
|
|
1298
|
-
if (h === "Right") return "right";
|
|
1299
|
-
return "left";
|
|
648
|
+
function $e(e) {
|
|
649
|
+
return e === "Center" ? "center" : e === "Right" ? "right" : "left";
|
|
1300
650
|
}
|
|
1301
|
-
function
|
|
1302
|
-
|
|
1303
|
-
if (v === "Bottom") return "bottom";
|
|
1304
|
-
return "top";
|
|
651
|
+
function He(e) {
|
|
652
|
+
return e === "Center" ? "middle" : e === "Bottom" ? "bottom" : "top";
|
|
1305
653
|
}
|
|
1306
|
-
function
|
|
1307
|
-
const
|
|
654
|
+
function Re(e) {
|
|
655
|
+
const n = parseFloat(v(e.FontSize, "10.5"));
|
|
1308
656
|
return {
|
|
1309
|
-
fontSize: Number.isFinite(
|
|
1310
|
-
fontFamily:
|
|
1311
|
-
bold:
|
|
1312
|
-
italic:
|
|
1313
|
-
underline:
|
|
1314
|
-
color:
|
|
1315
|
-
backgroundColor:
|
|
1316
|
-
align:
|
|
1317
|
-
verticalAlign:
|
|
657
|
+
fontSize: Number.isFinite(n) ? n : 10.5,
|
|
658
|
+
fontFamily: v(e.FontFamily, "黑体") || void 0,
|
|
659
|
+
bold: v(e.FontWeight) === "bold" || void 0,
|
|
660
|
+
italic: v(e.FontStyle) === "italic" || void 0,
|
|
661
|
+
underline: e.Underline === !0 || void 0,
|
|
662
|
+
color: v(e.FontColor) || void 0,
|
|
663
|
+
backgroundColor: v(e.BackgroundColor) || void 0,
|
|
664
|
+
align: $e(v(e.HorAlignment, "Left")),
|
|
665
|
+
verticalAlign: He(v(e.VertAlignment, "Top")),
|
|
1318
666
|
lineHeight: (() => {
|
|
1319
|
-
const
|
|
1320
|
-
return Number.isFinite(
|
|
667
|
+
const i = parseFloat(v(e.RowSpace, "1"));
|
|
668
|
+
return Number.isFinite(i) && i !== 1 ? i : void 0;
|
|
1321
669
|
})(),
|
|
1322
|
-
borderColor:
|
|
1323
|
-
borderTop:
|
|
1324
|
-
borderRight:
|
|
1325
|
-
borderBottom:
|
|
1326
|
-
borderLeft:
|
|
670
|
+
borderColor: v(e.BorderColor) || void 0,
|
|
671
|
+
borderTop: e.BorderTop !== !1,
|
|
672
|
+
borderRight: e.BorderRight !== !1,
|
|
673
|
+
borderBottom: e.BorderBottom !== !1,
|
|
674
|
+
borderLeft: e.BorderLeft !== !1
|
|
1327
675
|
};
|
|
1328
676
|
}
|
|
1329
|
-
function
|
|
1330
|
-
const
|
|
1331
|
-
const comp = {
|
|
677
|
+
function Be(e, n) {
|
|
678
|
+
const i = v(e.uitype), t = {
|
|
1332
679
|
kind: "text",
|
|
1333
|
-
leftMm:
|
|
1334
|
-
topMm:
|
|
1335
|
-
widthMm:
|
|
1336
|
-
heightMm:
|
|
1337
|
-
nid:
|
|
1338
|
-
style:
|
|
680
|
+
leftMm: S(e.left, 0),
|
|
681
|
+
topMm: S(e.top, 0),
|
|
682
|
+
widthMm: S(e.width, 40),
|
|
683
|
+
heightMm: S(e.height, 8),
|
|
684
|
+
nid: v(e.nid) || void 0,
|
|
685
|
+
style: Re(e)
|
|
1339
686
|
};
|
|
1340
|
-
switch (
|
|
687
|
+
switch (i) {
|
|
1341
688
|
case "text": {
|
|
1342
|
-
|
|
1343
|
-
const
|
|
1344
|
-
|
|
1345
|
-
const
|
|
1346
|
-
|
|
1347
|
-
comp.lines = lines.map((l) => String(l));
|
|
1348
|
-
}
|
|
1349
|
-
return comp;
|
|
689
|
+
t.kind = "text";
|
|
690
|
+
const r = e.Text ?? e.text ?? e.Value;
|
|
691
|
+
t.text = r == null ? "" : String(r);
|
|
692
|
+
const s = e.Lines ?? e.lines;
|
|
693
|
+
return Array.isArray(s) && (t.lines = s.map((a) => String(a))), t;
|
|
1350
694
|
}
|
|
1351
695
|
case "richtext":
|
|
1352
|
-
|
|
1353
|
-
comp.text = str(node["Text"]);
|
|
1354
|
-
warnings.push(`\u5BCC\u6587\u672C ${comp.nid ?? ""} \u5BFC\u5165\u4E3A\u7EAF\u6587\u672C\uFF08\u7248\u5F0F\u7EC6\u8282\u53EF\u80FD\u635F\u5931\uFF09`);
|
|
1355
|
-
return comp;
|
|
696
|
+
return t.kind = "text", t.text = v(e.Text), n.push(`富文本 ${t.nid ?? ""} 导入为纯文本(版式细节可能损失)`), t;
|
|
1356
697
|
case "image":
|
|
1357
698
|
case "barcode":
|
|
1358
699
|
case "qrcode":
|
|
1359
700
|
case "chart":
|
|
1360
|
-
|
|
1361
|
-
comp.fallbackText = `[${uitype}]`;
|
|
1362
|
-
warnings.push(`\u56FE\u7247\u7C7B\u7EC4\u4EF6 ${comp.nid ?? ""} \u9700\u8FD0\u884C\u65F6\u6570\u636E\uFF08imageData\uFF09\uFF0C\u5DF2\u5BFC\u5165\u4E3A\u5360\u4F4D`);
|
|
1363
|
-
return comp;
|
|
701
|
+
return t.kind = i === "image" ? "image" : i, t.fallbackText = `[${i}]`, n.push(`图片类组件 ${t.nid ?? ""} 需运行时数据(imageData),已导入为占位`), t;
|
|
1364
702
|
case "table": {
|
|
1365
|
-
|
|
1366
|
-
const
|
|
1367
|
-
if (Array.isArray(
|
|
1368
|
-
const
|
|
1369
|
-
cells:
|
|
1370
|
-
(
|
|
1371
|
-
text:
|
|
1372
|
-
colSpan:
|
|
703
|
+
t.kind = "rect";
|
|
704
|
+
const r = e.Cells ?? e.cells;
|
|
705
|
+
if (Array.isArray(r)) {
|
|
706
|
+
const s = {
|
|
707
|
+
cells: r.map(
|
|
708
|
+
(a) => Array.isArray(a) ? a.map((o) => ({
|
|
709
|
+
text: N(o) ? v(o.Text ?? o.text) : "",
|
|
710
|
+
colSpan: N(o) ? S(o.ColSpan, 1) : 1
|
|
1373
711
|
})) : []
|
|
1374
712
|
)
|
|
1375
713
|
};
|
|
1376
|
-
|
|
1377
|
-
} else
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
}
|
|
1381
|
-
return comp;
|
|
714
|
+
t.grid = s;
|
|
715
|
+
} else
|
|
716
|
+
t.fallbackText = "[table]", n.push(`表格 ${t.nid ?? ""} 缺少 Cells,导入为空框`);
|
|
717
|
+
return t;
|
|
1382
718
|
}
|
|
1383
719
|
case "subreport":
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
if (str(node["ShapeType"]) === "hline" || uitype === "hline") {
|
|
1388
|
-
comp.kind = "line";
|
|
1389
|
-
return comp;
|
|
1390
|
-
}
|
|
1391
|
-
if (uitype === "vline") {
|
|
1392
|
-
comp.kind = "line";
|
|
1393
|
-
return comp;
|
|
1394
|
-
}
|
|
1395
|
-
if (uitype === "rect" || uitype === "oval" || uitype === "shape") {
|
|
1396
|
-
comp.kind = uitype === "oval" ? "ellipse" : "rect";
|
|
1397
|
-
return comp;
|
|
1398
|
-
}
|
|
1399
|
-
warnings.push(`\u672A\u77E5\u7EC4\u4EF6\u7C7B\u578B ${uitype}\uFF0C\u5DF2\u8DF3\u8FC7`);
|
|
1400
|
-
return null;
|
|
1401
|
-
}
|
|
720
|
+
return n.push(`子报表 ${t.nid ?? ""} 暂不支持导入,已跳过`), null;
|
|
721
|
+
default:
|
|
722
|
+
return v(e.ShapeType) === "hline" || i === "hline" || i === "vline" ? (t.kind = "line", t) : i === "rect" || i === "oval" || i === "shape" ? (t.kind = i === "oval" ? "ellipse" : "rect", t) : (n.push(`未知组件类型 ${i},已跳过`), null);
|
|
1402
723
|
}
|
|
1403
724
|
}
|
|
1404
|
-
function
|
|
1405
|
-
const
|
|
1406
|
-
let
|
|
1407
|
-
if (typeof
|
|
725
|
+
function Ge(e) {
|
|
726
|
+
const n = [];
|
|
727
|
+
let i = null;
|
|
728
|
+
if (typeof e == "string")
|
|
1408
729
|
try {
|
|
1409
|
-
const
|
|
1410
|
-
|
|
730
|
+
const d = JSON.parse(e);
|
|
731
|
+
N(d) && (i = d);
|
|
1411
732
|
} catch {
|
|
1412
733
|
return {
|
|
1413
734
|
template: { pages: [] },
|
|
1414
|
-
warnings: ["content
|
|
735
|
+
warnings: ["content 不是合法 JSON"]
|
|
1415
736
|
};
|
|
1416
737
|
}
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
if (pageNodes.length === 0) {
|
|
1434
|
-
warnings.push("content \u4E2D\u6CA1\u6709 uitype=page \u7684\u9875\u8282\u70B9");
|
|
1435
|
-
}
|
|
1436
|
-
const pages = pageNodes.map((raw) => {
|
|
1437
|
-
const node = raw;
|
|
1438
|
-
const elements = Array.isArray(node["children"]) ? node["children"] : [];
|
|
1439
|
-
const components = [];
|
|
1440
|
-
for (const el of elements) {
|
|
1441
|
-
if (!isRaw(el)) continue;
|
|
1442
|
-
const converted = convertElement(el, warnings);
|
|
1443
|
-
if (converted) components.push(converted);
|
|
738
|
+
else N(e) && (i = e);
|
|
739
|
+
if (!i)
|
|
740
|
+
return { template: { pages: [] }, warnings: ["content 为空"] };
|
|
741
|
+
const t = N(i.GlobalConfig) ? i.GlobalConfig : {}, r = S(t.paperWidthMm, 210), s = S(t.paperHeightMm, 297), a = {
|
|
742
|
+
top: S(t.marginTop, 10),
|
|
743
|
+
bottom: S(t.marginBottom, 10),
|
|
744
|
+
left: S(t.marginLeft, 10),
|
|
745
|
+
right: S(t.marginRight, 10)
|
|
746
|
+
}, o = Array.isArray(i.children) ? i.children.filter((d) => N(d) && v(d.uitype) === "page") : [];
|
|
747
|
+
o.length === 0 && n.push("content 中没有 uitype=page 的页节点");
|
|
748
|
+
const l = o.map((d) => {
|
|
749
|
+
const h = d, c = Array.isArray(h.children) ? h.children : [], m = [];
|
|
750
|
+
for (const u of c) {
|
|
751
|
+
if (!N(u)) continue;
|
|
752
|
+
const g = Be(u, n);
|
|
753
|
+
g && m.push(g);
|
|
1444
754
|
}
|
|
1445
755
|
return {
|
|
1446
|
-
widthMm:
|
|
1447
|
-
heightMm:
|
|
1448
|
-
marginTopMm:
|
|
1449
|
-
marginBottomMm:
|
|
1450
|
-
marginLeftMm:
|
|
1451
|
-
marginRightMm:
|
|
1452
|
-
components
|
|
756
|
+
widthMm: S(h.width, r),
|
|
757
|
+
heightMm: S(h.DesignHeight, s),
|
|
758
|
+
marginTopMm: S(h.MarginTop, a.top),
|
|
759
|
+
marginBottomMm: S(h.MarginBottom, a.bottom),
|
|
760
|
+
marginLeftMm: S(h.MarginLeft, a.left),
|
|
761
|
+
marginRightMm: S(h.MarginRight, a.right),
|
|
762
|
+
components: m
|
|
1453
763
|
};
|
|
1454
764
|
});
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
const preset = PAPER_SIZES[paper];
|
|
1473
|
-
if (!preset) throw new Error(`\u672A\u77E5\u7EB8\u5F20\u9884\u8BBE "${paper}"\uFF08\u53EF\u7528\uFF1A${Object.keys(PAPER_SIZES).join("/")}\uFF09`);
|
|
1474
|
-
widthMm = preset.widthMm;
|
|
1475
|
-
heightMm = preset.heightMm;
|
|
1476
|
-
} else if (typeof paper === "number") {
|
|
1477
|
-
widthMm = paper;
|
|
1478
|
-
heightMm = heightArg ?? 297;
|
|
1479
|
-
} else {
|
|
1480
|
-
widthMm = paper.widthMm;
|
|
1481
|
-
heightMm = paper.heightMm;
|
|
1482
|
-
}
|
|
1483
|
-
return landscape ? { widthMm: heightMm, heightMm: widthMm } : { widthMm, heightMm };
|
|
1484
|
-
}
|
|
1485
|
-
var TemplateBuilder = class {
|
|
765
|
+
return l.length === 0 && (n.push("转换结果为空页,已回退一张空白页"), l.push({
|
|
766
|
+
widthMm: r,
|
|
767
|
+
heightMm: s,
|
|
768
|
+
...a,
|
|
769
|
+
components: []
|
|
770
|
+
})), { template: { pages: l }, warnings: n };
|
|
771
|
+
}
|
|
772
|
+
function Ne(e, n, i) {
|
|
773
|
+
let t, r;
|
|
774
|
+
if (typeof e == "string") {
|
|
775
|
+
const s = K[e];
|
|
776
|
+
if (!s) throw new Error(`未知纸张预设 "${e}"(可用:${Object.keys(K).join("/")})`);
|
|
777
|
+
t = s.widthMm, r = s.heightMm;
|
|
778
|
+
} else typeof e == "number" ? (t = e, r = n ?? 297) : (t = e.widthMm, r = e.heightMm);
|
|
779
|
+
return i ? { widthMm: r, heightMm: t } : { widthMm: t, heightMm: r };
|
|
780
|
+
}
|
|
781
|
+
class Le {
|
|
1486
782
|
constructor() {
|
|
1487
|
-
this.pages = [];
|
|
1488
|
-
this.pending = null;
|
|
783
|
+
this.pages = [], this.pending = null;
|
|
1489
784
|
}
|
|
1490
785
|
/**
|
|
1491
786
|
* 新建页。纸张支持三种写法:
|
|
@@ -1493,106 +788,89 @@ var TemplateBuilder = class {
|
|
|
1493
788
|
* - 数字:.page(210, 297)(第三参数兼容旧 margins 对象或新 options)
|
|
1494
789
|
* - 对象:.page({ widthMm: 210, heightMm: 297 })
|
|
1495
790
|
*/
|
|
1496
|
-
page(
|
|
791
|
+
page(n = "a4", i = {}, t) {
|
|
1497
792
|
this.collect();
|
|
1498
|
-
const
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
marginLeftMm: margins.marginLeftMm ?? 10,
|
|
1512
|
-
marginRightMm: margins.marginRightMm ?? 10
|
|
1513
|
-
});
|
|
1514
|
-
return this.pending;
|
|
793
|
+
const s = t != null && !("margins" in t) && !("landscape" in t) && ("marginTopMm" in t || "marginBottomMm" in t || "marginLeftMm" in t || "marginRightMm" in t) ? { margins: t } : t ?? {}, { widthMm: a, heightMm: o } = Ne(
|
|
794
|
+
n,
|
|
795
|
+
typeof i == "number" ? i : void 0,
|
|
796
|
+
s.landscape
|
|
797
|
+
), l = s.margins ?? {};
|
|
798
|
+
return this.pending = new ze(this, {
|
|
799
|
+
widthMm: a,
|
|
800
|
+
heightMm: o,
|
|
801
|
+
marginTopMm: l.marginTopMm ?? 10,
|
|
802
|
+
marginBottomMm: l.marginBottomMm ?? 10,
|
|
803
|
+
marginLeftMm: l.marginLeftMm ?? 10,
|
|
804
|
+
marginRightMm: l.marginRightMm ?? 10
|
|
805
|
+
}), this.pending;
|
|
1515
806
|
}
|
|
1516
807
|
collect() {
|
|
1517
|
-
|
|
1518
|
-
this.pages.push(this.pending.buildPage());
|
|
1519
|
-
this.pending = null;
|
|
1520
|
-
}
|
|
808
|
+
this.pending && (this.pages.push(this.pending.buildPage()), this.pending = null);
|
|
1521
809
|
}
|
|
1522
810
|
build() {
|
|
1523
|
-
this.collect()
|
|
1524
|
-
|
|
1525
|
-
throw new Error("\u6A21\u677F\u81F3\u5C11\u9700\u8981\u4E00\u9875\uFF1A\u5148\u8C03\u7528 .page() \u6DFB\u52A0\u5185\u5BB9");
|
|
1526
|
-
}
|
|
811
|
+
if (this.collect(), this.pages.length === 0)
|
|
812
|
+
throw new Error("模板至少需要一页:先调用 .page() 添加内容");
|
|
1527
813
|
return { pages: this.pages };
|
|
1528
814
|
}
|
|
1529
|
-
}
|
|
1530
|
-
|
|
1531
|
-
constructor(
|
|
1532
|
-
this.parent =
|
|
1533
|
-
this.page = page;
|
|
1534
|
-
this.components = [];
|
|
815
|
+
}
|
|
816
|
+
class ze {
|
|
817
|
+
constructor(n, i) {
|
|
818
|
+
this.parent = n, this.page = i, this.components = [];
|
|
1535
819
|
}
|
|
1536
|
-
text(
|
|
1537
|
-
this.components.push({
|
|
820
|
+
text(n, i = {}, t = {}) {
|
|
821
|
+
return this.components.push({
|
|
1538
822
|
kind: "text",
|
|
1539
|
-
leftMm:
|
|
1540
|
-
topMm:
|
|
1541
|
-
widthMm:
|
|
1542
|
-
heightMm:
|
|
1543
|
-
text:
|
|
1544
|
-
style
|
|
1545
|
-
});
|
|
1546
|
-
|
|
1547
|
-
}
|
|
1548
|
-
|
|
1549
|
-
this.components.push({
|
|
823
|
+
leftMm: i.leftMm ?? 0,
|
|
824
|
+
topMm: i.topMm ?? 0,
|
|
825
|
+
widthMm: i.widthMm ?? 60,
|
|
826
|
+
heightMm: i.heightMm ?? 8,
|
|
827
|
+
text: n,
|
|
828
|
+
style: t
|
|
829
|
+
}), this;
|
|
830
|
+
}
|
|
831
|
+
list(n, i, t, r = {}) {
|
|
832
|
+
return this.components.push({
|
|
1550
833
|
kind: "list",
|
|
1551
|
-
leftMm:
|
|
1552
|
-
topMm:
|
|
1553
|
-
widthMm:
|
|
1554
|
-
dataset,
|
|
1555
|
-
columns,
|
|
1556
|
-
...
|
|
1557
|
-
});
|
|
1558
|
-
|
|
1559
|
-
}
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
line(leftMm, topMm, widthMm, style = {}) {
|
|
1565
|
-
this.components.push({
|
|
834
|
+
leftMm: i.leftMm ?? 10,
|
|
835
|
+
topMm: i.topMm ?? 30,
|
|
836
|
+
widthMm: i.widthMm ?? 180,
|
|
837
|
+
dataset: n,
|
|
838
|
+
columns: t,
|
|
839
|
+
...r
|
|
840
|
+
}), this;
|
|
841
|
+
}
|
|
842
|
+
rect(n, i = {}) {
|
|
843
|
+
return this.components.push({ kind: "rect", ...n, style: i }), this;
|
|
844
|
+
}
|
|
845
|
+
line(n, i, t, r = {}) {
|
|
846
|
+
return this.components.push({
|
|
1566
847
|
kind: "line",
|
|
1567
|
-
leftMm,
|
|
1568
|
-
topMm,
|
|
1569
|
-
widthMm,
|
|
848
|
+
leftMm: n,
|
|
849
|
+
topMm: i,
|
|
850
|
+
widthMm: t,
|
|
1570
851
|
heightMm: 0.5,
|
|
1571
|
-
style
|
|
1572
|
-
});
|
|
1573
|
-
return this;
|
|
852
|
+
style: r
|
|
853
|
+
}), this;
|
|
1574
854
|
}
|
|
1575
|
-
barcode(
|
|
1576
|
-
this.components.push({
|
|
855
|
+
barcode(n, i) {
|
|
856
|
+
return this.components.push({
|
|
1577
857
|
kind: "barcode",
|
|
1578
|
-
leftMm:
|
|
1579
|
-
topMm:
|
|
1580
|
-
widthMm:
|
|
1581
|
-
heightMm:
|
|
1582
|
-
fallbackText:
|
|
1583
|
-
});
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
this.components.push({
|
|
858
|
+
leftMm: i.leftMm ?? 0,
|
|
859
|
+
topMm: i.topMm ?? 0,
|
|
860
|
+
widthMm: i.widthMm ?? 40,
|
|
861
|
+
heightMm: i.heightMm ?? 12,
|
|
862
|
+
fallbackText: n
|
|
863
|
+
}), this;
|
|
864
|
+
}
|
|
865
|
+
qrcode(n, i, t, r) {
|
|
866
|
+
return this.components.push({
|
|
1588
867
|
kind: "qrcode",
|
|
1589
|
-
leftMm,
|
|
1590
|
-
topMm,
|
|
1591
|
-
widthMm:
|
|
1592
|
-
heightMm:
|
|
1593
|
-
fallbackText:
|
|
1594
|
-
});
|
|
1595
|
-
return this;
|
|
868
|
+
leftMm: t,
|
|
869
|
+
topMm: r,
|
|
870
|
+
widthMm: i,
|
|
871
|
+
heightMm: i,
|
|
872
|
+
fallbackText: n
|
|
873
|
+
}), this;
|
|
1596
874
|
}
|
|
1597
875
|
buildPage() {
|
|
1598
876
|
return { ...this.page, components: this.components };
|
|
@@ -1603,9 +881,60 @@ var PageBuilder = class {
|
|
|
1603
881
|
build() {
|
|
1604
882
|
return this.done().build();
|
|
1605
883
|
}
|
|
1606
|
-
};
|
|
1607
|
-
function createTemplate() {
|
|
1608
|
-
return new TemplateBuilder();
|
|
1609
884
|
}
|
|
1610
|
-
|
|
1611
|
-
|
|
885
|
+
function Ve() {
|
|
886
|
+
return new Le();
|
|
887
|
+
}
|
|
888
|
+
export {
|
|
889
|
+
Ue as CSS_DPI,
|
|
890
|
+
Ke as DEFAULT_BORDER_PT,
|
|
891
|
+
j as DEFAULT_FONT_PT,
|
|
892
|
+
Ye as DEFAULT_STROKE_COLOR,
|
|
893
|
+
me as DEFAULT_TEXT_COLOR,
|
|
894
|
+
q as LINE_HEIGHT,
|
|
895
|
+
Xe as MM_PER_INCH,
|
|
896
|
+
K as PAPER_SIZES,
|
|
897
|
+
ze as PageBuilder,
|
|
898
|
+
se as RENDER_PLAN_SCHEMA_VERSION,
|
|
899
|
+
Ze as SCHEMA_VERSION_JH4J,
|
|
900
|
+
Qe as SCHEMA_VERSION_LOCAL,
|
|
901
|
+
et as SCHEMA_VERSION_MACH,
|
|
902
|
+
Le as TemplateBuilder,
|
|
903
|
+
_e as assertRenderPlan,
|
|
904
|
+
tt as charWidthEm,
|
|
905
|
+
C as classOf,
|
|
906
|
+
Pe as computePageWindow,
|
|
907
|
+
nt as createCanvasMeasurer,
|
|
908
|
+
je as createCanvasPager,
|
|
909
|
+
it as createHeuristicMeasurer,
|
|
910
|
+
Ve as createTemplate,
|
|
911
|
+
J as heuristicMeasurer,
|
|
912
|
+
Ge as importJh4jTemplateContent,
|
|
913
|
+
le as isImageBackedComponent,
|
|
914
|
+
Z as isRichText,
|
|
915
|
+
ie as measurePageSizePx,
|
|
916
|
+
rt as measureTextMm,
|
|
917
|
+
de as mmToPx,
|
|
918
|
+
ot as mmToPxFactor,
|
|
919
|
+
We as paginateTemplate,
|
|
920
|
+
De as planFontSizePx,
|
|
921
|
+
O as ptToPx,
|
|
922
|
+
at as pxToMm,
|
|
923
|
+
ne as renderComponent,
|
|
924
|
+
xe as renderPage,
|
|
925
|
+
Ie as renderPlan,
|
|
926
|
+
Oe as renderPlanToCanvas,
|
|
927
|
+
V as resolveBoxBorders,
|
|
928
|
+
W as resolveFontSize,
|
|
929
|
+
ce as resolveGridLayout,
|
|
930
|
+
he as resolveLineHeight,
|
|
931
|
+
Ne as resolvePaper,
|
|
932
|
+
F as resolveStroke,
|
|
933
|
+
Q as resolveTextColor,
|
|
934
|
+
_ as round,
|
|
935
|
+
st as toRenderPlan,
|
|
936
|
+
ee as validateComponent,
|
|
937
|
+
ue as validatePage,
|
|
938
|
+
pe as validateRenderPlan,
|
|
939
|
+
G as wrapText
|
|
940
|
+
};
|