@agile-team/mach-report 0.4.0 → 0.6.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-DWLjYi_p.js +527 -0
- package/dist/ReportPreview-rBtmbu3W.cjs +6 -0
- package/dist/_commonjsHelpers-DKOUU3wS.cjs +1 -0
- package/dist/_commonjsHelpers-DaMA6jEr.js +8 -0
- package/dist/builder/template-builder.d.ts +3 -3
- package/dist/compat/jh4j-template.d.ts +1 -1
- package/dist/index.cjs +6 -0
- package/dist/index.d.cts +13 -0
- package/dist/index.d.ts +13 -13
- package/dist/index.js +919 -14
- package/dist/layout/paginate.d.ts +2 -2
- package/dist/manager/api.d.ts +1 -1
- package/dist/manager/index.d.ts +2 -2
- package/dist/manager.cjs +1 -0
- package/dist/manager.d.cts +5 -0
- package/dist/manager.d.ts +1 -1
- package/dist/manager.js +104 -6
- package/dist/pdf/index.d.ts +2 -2
- package/dist/pdf/render-pdf.d.ts +10 -4
- package/dist/pdf.cjs +84 -0
- package/dist/pdf.d.cts +6 -0
- package/dist/pdf.d.ts +1 -1
- package/dist/pdf.js +36152 -7
- package/dist/plugin-BIJxGHZX.cjs +1 -0
- package/dist/plugin-DrV67_VW.js +89 -0
- package/dist/render/canvas.d.ts +2 -2
- package/dist/render/dom.d.ts +1 -1
- package/dist/render/grid-geometry.d.ts +1 -1
- package/dist/render/style.d.ts +1 -8
- package/dist/schema/validate.d.ts +1 -1
- package/dist/sql/compile.d.ts +1 -1
- package/dist/sql/index.d.ts +4 -4
- package/dist/sql.cjs +68 -0
- package/dist/sql.d.cts +5 -0
- package/dist/sql.d.ts +1 -1
- package/dist/sql.js +40794 -6
- package/dist/style-B3vxGDZd.cjs +3 -0
- package/dist/style-B7Xfo5I-.js +255 -0
- package/dist/style.css +1 -0
- package/dist/vue/ReportPreview.d.ts +141 -0
- package/dist/vue/ReportToolbar.d.ts +25 -0
- package/dist/vue/adapters.d.ts +37 -0
- package/dist/vue/async.d.cts +146 -0
- package/dist/vue/async.d.ts +146 -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/index.d.cts +11 -0
- package/dist/vue/index.d.ts +11 -0
- package/dist/vue/injection-keys.d.ts +12 -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 +34 -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 +44 -0
- package/package.json +84 -17
- package/dist/builder/template-builder.js +0 -153
- package/dist/builder/template-builder.js.map +0 -1
- package/dist/compat/jh4j-template.js +0 -196
- package/dist/compat/jh4j-template.js.map +0 -1
- package/dist/defaults.js +0 -28
- package/dist/defaults.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/layout/paginate.js +0 -197
- package/dist/layout/paginate.js.map +0 -1
- package/dist/layout/textwrap.js +0 -173
- package/dist/layout/textwrap.js.map +0 -1
- package/dist/manager/api.js +0 -101
- package/dist/manager/api.js.map +0 -1
- package/dist/manager/index.js +0 -3
- package/dist/manager/index.js.map +0 -1
- package/dist/manager/types.js +0 -8
- package/dist/manager/types.js.map +0 -1
- package/dist/manager.js.map +0 -1
- package/dist/pdf/font-loader.js +0 -84
- package/dist/pdf/font-loader.js.map +0 -1
- package/dist/pdf/index.js +0 -3
- package/dist/pdf/index.js.map +0 -1
- package/dist/pdf/render-pdf.js +0 -284
- package/dist/pdf/render-pdf.js.map +0 -1
- package/dist/pdf.js.map +0 -1
- package/dist/render/canvas.js +0 -402
- package/dist/render/canvas.js.map +0 -1
- package/dist/render/dom.js +0 -311
- package/dist/render/dom.js.map +0 -1
- package/dist/render/grid-geometry.js +0 -131
- package/dist/render/grid-geometry.js.map +0 -1
- package/dist/render/style.js +0 -39
- package/dist/render/style.js.map +0 -1
- package/dist/render/window.js +0 -58
- package/dist/render/window.js.map +0 -1
- package/dist/schema/render-plan.js +0 -25
- package/dist/schema/render-plan.js.map +0 -1
- package/dist/schema/validate.js +0 -129
- package/dist/schema/validate.js.map +0 -1
- package/dist/sql/ast-check.js +0 -44
- package/dist/sql/ast-check.js.map +0 -1
- package/dist/sql/compile.js +0 -145
- package/dist/sql/compile.js.map +0 -1
- package/dist/sql/expr.js +0 -123
- package/dist/sql/expr.js.map +0 -1
- package/dist/sql/index.js +0 -5
- package/dist/sql/index.js.map +0 -1
- package/dist/sql/tokenizer.js +0 -124
- package/dist/sql/tokenizer.js.map +0 -1
- package/dist/sql.js.map +0 -1
- package/dist/units.js +0 -26
- package/dist/units.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,14 +1,919 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
1
|
+
import { h as V, R as at, D as j, w as O, L as J, i as st, r as F, m as lt, a as _, b as X, c as z, d as G, p as D, e as dt, f as Z, g as ht, j as ct, P as U } from "./style-B7Xfo5I-.js";
|
|
2
|
+
import { C as qt, k as Ut, l as Kt, M as Yt, S as Xt, n as Zt, o as Qt, q as te, s as ee, t as ne, u as ie, v as re, x as oe, y as ae } from "./style-B7Xfo5I-.js";
|
|
3
|
+
const mt = /* @__PURE__ */ new Set([
|
|
4
|
+
"text",
|
|
5
|
+
"image",
|
|
6
|
+
"barcode",
|
|
7
|
+
"qrcode",
|
|
8
|
+
"chart",
|
|
9
|
+
"line",
|
|
10
|
+
"rect",
|
|
11
|
+
"ellipse"
|
|
12
|
+
]);
|
|
13
|
+
function L(t) {
|
|
14
|
+
return typeof t == "object" && t !== null && !Array.isArray(t);
|
|
15
|
+
}
|
|
16
|
+
function gt(t, n, i, e) {
|
|
17
|
+
const r = t[n];
|
|
18
|
+
r != null && (typeof r != "number" || !Number.isFinite(r)) && e.push({ path: `${i}.${n}`, message: `应为有限数字,实际 ${JSON.stringify(r)}` });
|
|
19
|
+
}
|
|
20
|
+
function Q(t, n, i, e = []) {
|
|
21
|
+
if (!L(t)) {
|
|
22
|
+
i.push({ path: n, message: "组件应为对象" });
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
const r = t.kind;
|
|
26
|
+
typeof r != "string" ? i.push({ path: `${n}.kind`, message: "组件缺少 kind 字符串" }) : mt.has(r) || e.push({
|
|
27
|
+
path: `${n}.kind`,
|
|
28
|
+
message: `未知组件类型 ${JSON.stringify(r)},将以兜底方式渲染`
|
|
29
|
+
});
|
|
30
|
+
for (const o of ["leftMm", "topMm", "widthMm", "heightMm"])
|
|
31
|
+
gt(t, o, n, i);
|
|
32
|
+
t.leftMm != null && t.widthMm != null && (t.leftMm < -100 || t.widthMm < 0) && i.push({ path: n, message: "几何数值异常(leftMm<-100 或 widthMm<0)" });
|
|
33
|
+
const l = t.grid;
|
|
34
|
+
l !== void 0 && (!L(l) || !Array.isArray(l.cells) ? i.push({ path: `${n}.grid.cells`, message: "grid.cells 应为二维数组" }) : l.cells.forEach((o, s) => {
|
|
35
|
+
if (!Array.isArray(o)) {
|
|
36
|
+
i.push({ path: `${n}.grid.cells.${s}`, message: "行应为数组" });
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
o.forEach((d, h) => {
|
|
40
|
+
d != null && L(d) && Array.isArray(d.children) && d.children.forEach((c, m) => {
|
|
41
|
+
Q(c, `${n}.grid.cells.${s}.${h}.children.${m}`, i, e);
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
}));
|
|
45
|
+
const a = t.richParagraphs;
|
|
46
|
+
a !== void 0 && (Array.isArray(a) ? a.forEach((o, s) => {
|
|
47
|
+
(!L(o) || !Array.isArray(o.segments)) && i.push({ path: `${n}.richParagraphs.${s}`, message: "段落缺少 segments 数组" });
|
|
48
|
+
}) : i.push({ path: `${n}.richParagraphs`, message: "richParagraphs 应为数组" }));
|
|
49
|
+
}
|
|
50
|
+
function ft(t, n, i, e = []) {
|
|
51
|
+
if (!L(t)) {
|
|
52
|
+
i.push({ path: n, message: "页应为对象" });
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
const r = t.pageWidthMm, l = t.pageHeightMm;
|
|
56
|
+
(typeof r != "number" || !(r > 0 && r < 3e3)) && i.push({ path: `${n}.pageWidthMm`, message: `页宽非法: ${JSON.stringify(r)}` }), (typeof l != "number" || !(l > 0 && l < 5e3)) && i.push({ path: `${n}.pageHeightMm`, message: `页高非法: ${JSON.stringify(l)}` });
|
|
57
|
+
const a = t.components;
|
|
58
|
+
a !== void 0 && !Array.isArray(a) ? i.push({ path: `${n}.components`, message: "components 应为数组" }) : Array.isArray(a) && a.forEach(
|
|
59
|
+
(o, s) => Q(o, `${n}.components.${s}`, i, e)
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
function ut(t) {
|
|
63
|
+
const n = [], i = [], e = L(t) ? t.pages : void 0;
|
|
64
|
+
return Array.isArray(e) ? e.forEach((r, l) => ft(r, `$.pages.${l}`, n, i)) : n.push({
|
|
65
|
+
path: "$.pages",
|
|
66
|
+
message: t == null ? "渲染计划为空" : "渲染计划缺少 pages 数组"
|
|
67
|
+
}), { ok: n.length === 0, errors: n, warnings: i };
|
|
68
|
+
}
|
|
69
|
+
function Ft(t) {
|
|
70
|
+
const n = ut(t);
|
|
71
|
+
if (!n.ok) {
|
|
72
|
+
const i = n.errors.slice(0, 3).map((e) => `${e.path}: ${e.message}`).join("; ");
|
|
73
|
+
throw new Error(`渲染计划校验失败(${n.errors.length} 处): ${i}`);
|
|
74
|
+
}
|
|
75
|
+
return t.pages;
|
|
76
|
+
}
|
|
77
|
+
function K(t) {
|
|
78
|
+
return {
|
|
79
|
+
widthMm: t.widthMm,
|
|
80
|
+
heightMm: t.heightMm,
|
|
81
|
+
marginTopMm: t.marginTopMm ?? 0,
|
|
82
|
+
marginBottomMm: t.marginBottomMm ?? 0,
|
|
83
|
+
marginLeftMm: t.marginLeftMm ?? 0,
|
|
84
|
+
marginRightMm: t.marginRightMm ?? 0,
|
|
85
|
+
components: []
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
function pt(t, n) {
|
|
89
|
+
return n.heightMm - (t.marginBottomMm ?? n.marginBottomMm);
|
|
90
|
+
}
|
|
91
|
+
function Mt(t, n) {
|
|
92
|
+
const e = (t.fontSizePt ?? j) * J * 25.4 / 72, r = (t.paddingMm ?? 1) * 2;
|
|
93
|
+
return Math.max(t.rowHeightMm ?? 0, n * e + r);
|
|
94
|
+
}
|
|
95
|
+
function bt(t) {
|
|
96
|
+
if (t == null) return "";
|
|
97
|
+
if (typeof t == "string") return t;
|
|
98
|
+
if (typeof t == "number") return String(t);
|
|
99
|
+
if (typeof t == "boolean") return t ? "是" : "否";
|
|
100
|
+
if (t instanceof Date) return t.toISOString().slice(0, 10);
|
|
101
|
+
try {
|
|
102
|
+
return JSON.stringify(t);
|
|
103
|
+
} catch {
|
|
104
|
+
return String(t);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
function yt(t, n) {
|
|
108
|
+
const i = t.fontSizePt ?? j, e = t.paddingMm ?? 1, r = t.columns.map(
|
|
109
|
+
(m) => m.style ? { align: "left", verticalAlign: "middle", ...m.style } : { align: "left", verticalAlign: "middle" }
|
|
110
|
+
), l = t.columns.map(
|
|
111
|
+
(m) => ({
|
|
112
|
+
bold: t.headerBold ?? !0,
|
|
113
|
+
align: "center",
|
|
114
|
+
verticalAlign: "middle",
|
|
115
|
+
backgroundColor: t.headerBackgroundColor,
|
|
116
|
+
...m.style || {}
|
|
117
|
+
})
|
|
118
|
+
), a = t.columns.map((m) => m.header), o = a.map(
|
|
119
|
+
(m, f) => O(
|
|
120
|
+
m,
|
|
121
|
+
t.columns[f].widthMm - e * 2,
|
|
122
|
+
{ fontSizePt: i, bold: t.headerBold ?? !0 },
|
|
123
|
+
n
|
|
124
|
+
)
|
|
125
|
+
), s = Math.max(...o.map((m) => m.length), 1), d = Mt(t, s), h = a.map((m, f) => ({
|
|
126
|
+
text: m,
|
|
127
|
+
style: l[f]
|
|
128
|
+
})), c = t.border === !1 ? { borderTop: !1, borderRight: !1, borderBottom: !1, borderLeft: !1 } : { borderBottom: !0, borderLeft: !0, borderRight: !0, borderTop: !0 };
|
|
129
|
+
return {
|
|
130
|
+
fontSizePt: i,
|
|
131
|
+
paddingMm: e,
|
|
132
|
+
cellStyles: r,
|
|
133
|
+
borderStyle: c,
|
|
134
|
+
headerHeightMm: d,
|
|
135
|
+
headerGrid: { cells: [h], rowHeightsMm: [d] },
|
|
136
|
+
columns: t.columns
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
function wt(t, n, i) {
|
|
140
|
+
const e = t.columns, r = new Array(e.length);
|
|
141
|
+
let l = 1;
|
|
142
|
+
for (let h = 0; h < e.length; h++)
|
|
143
|
+
r[h] = bt(n[e[h].field]);
|
|
144
|
+
const a = new Array(e.length);
|
|
145
|
+
for (let h = 0; h < e.length; h++) {
|
|
146
|
+
const c = O(
|
|
147
|
+
r[h],
|
|
148
|
+
e[h].widthMm - t.paddingMm * 2,
|
|
149
|
+
{ fontSizePt: t.fontSizePt },
|
|
150
|
+
i
|
|
151
|
+
);
|
|
152
|
+
a[h] = c, c.length > l && (l = c.length);
|
|
153
|
+
}
|
|
154
|
+
const o = t.fontSizePt * J * 25.4 / 72, s = Math.max(
|
|
155
|
+
t.rowHeightFloorMm,
|
|
156
|
+
l * o + t.paddingMm * 2
|
|
157
|
+
), d = new Array(e.length);
|
|
158
|
+
for (let h = 0; h < e.length; h++)
|
|
159
|
+
d[h] = { text: r[h], style: t.cellStyles[h] };
|
|
160
|
+
return { grid: { cells: [d], rowHeightsMm: [s] }, heightMm: s };
|
|
161
|
+
}
|
|
162
|
+
function _t(t, n, i = {}) {
|
|
163
|
+
const e = typeof i == "number" ? { mmPerRow: i } : i, r = e.mmPerRow ?? 0, l = e.measurer ?? V, a = [], o = [];
|
|
164
|
+
let s = 0;
|
|
165
|
+
const d = (h) => `${h}_${(++s).toString(36)}`;
|
|
166
|
+
for (const h of t.pages) {
|
|
167
|
+
const c = K(h), m = () => pt(h, c), f = c.marginTopMm, g = () => {
|
|
168
|
+
o.push({
|
|
169
|
+
pageWidthMm: c.widthMm,
|
|
170
|
+
pageHeightMm: c.heightMm,
|
|
171
|
+
marginTopMm: c.marginTopMm,
|
|
172
|
+
marginBottomMm: c.marginBottomMm,
|
|
173
|
+
marginLeftMm: c.marginLeftMm,
|
|
174
|
+
marginRightMm: c.marginRightMm,
|
|
175
|
+
components: c.components
|
|
176
|
+
});
|
|
177
|
+
};
|
|
178
|
+
for (const b of h.components) {
|
|
179
|
+
if (b.kind !== "list") {
|
|
180
|
+
c.components.push(b);
|
|
181
|
+
continue;
|
|
182
|
+
}
|
|
183
|
+
const p = b, C = n[p.dataset];
|
|
184
|
+
Array.isArray(C) || a.push(`数据集 ${p.dataset} 未提供数据,列表 ${p.id ?? ""} 输出为空`);
|
|
185
|
+
const v = Array.isArray(C) ? C : [], E = p.columns.reduce((y, S) => y + S.widthMm, 0), w = E > p.widthMm ? p.widthMm / E : 1, W = w === 1 ? p : { ...p, columns: p.columns.map((y) => ({ ...y, widthMm: y.widthMm * w })) }, R = {
|
|
186
|
+
...yt(W, l),
|
|
187
|
+
rowHeightFloorMm: W.rowHeightMm ?? 0
|
|
188
|
+
}, I = {
|
|
189
|
+
kind: "rect",
|
|
190
|
+
leftMm: p.leftMm,
|
|
191
|
+
topMm: 0,
|
|
192
|
+
widthMm: p.widthMm,
|
|
193
|
+
heightMm: R.headerHeightMm,
|
|
194
|
+
grid: R.headerGrid,
|
|
195
|
+
nid: d("listh"),
|
|
196
|
+
style: R.borderStyle
|
|
197
|
+
};
|
|
198
|
+
let H = p.topMm;
|
|
199
|
+
const u = (y, S) => {
|
|
200
|
+
y.components.push({ ...I, topMm: S });
|
|
201
|
+
};
|
|
202
|
+
u(c, H), H += R.headerHeightMm + r;
|
|
203
|
+
for (let y = 0; y < v.length; y++) {
|
|
204
|
+
const S = wt(R, v[y], l);
|
|
205
|
+
if (H + S.heightMm > m()) {
|
|
206
|
+
g();
|
|
207
|
+
const M = K(h);
|
|
208
|
+
c.components = M.components, c.heightMm = M.heightMm, W.headerEveryPage !== !1 ? (u(c, p.topMm), H = p.topMm + R.headerHeightMm) : H = f;
|
|
209
|
+
}
|
|
210
|
+
c.components.push({
|
|
211
|
+
kind: "rect",
|
|
212
|
+
leftMm: p.leftMm,
|
|
213
|
+
topMm: H,
|
|
214
|
+
widthMm: p.widthMm,
|
|
215
|
+
heightMm: S.heightMm,
|
|
216
|
+
grid: S.grid,
|
|
217
|
+
nid: d("listr"),
|
|
218
|
+
style: R.borderStyle
|
|
219
|
+
}), H += S.heightMm;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
g();
|
|
223
|
+
}
|
|
224
|
+
return {
|
|
225
|
+
plan: { schemaVersion: at, pages: o },
|
|
226
|
+
warnings: a
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
const St = {
|
|
230
|
+
root: "mr-root",
|
|
231
|
+
page: "mr-page",
|
|
232
|
+
comp: "mr-comp",
|
|
233
|
+
text: "mr-text",
|
|
234
|
+
lines: "mr-lines",
|
|
235
|
+
line: "mr-line",
|
|
236
|
+
rich: "mr-rich",
|
|
237
|
+
paragraph: "mr-paragraph",
|
|
238
|
+
segment: "mr-segment",
|
|
239
|
+
image: "mr-image",
|
|
240
|
+
shape: "mr-shape",
|
|
241
|
+
grid: "mr-grid",
|
|
242
|
+
row: "mr-row",
|
|
243
|
+
cell: "mr-cell",
|
|
244
|
+
unknown: "mr-unknown"
|
|
245
|
+
};
|
|
246
|
+
function x(t, n) {
|
|
247
|
+
return n?.classNames?.[t] ?? St[t];
|
|
248
|
+
}
|
|
249
|
+
class $ {
|
|
250
|
+
constructor() {
|
|
251
|
+
this.props = [];
|
|
252
|
+
}
|
|
253
|
+
add(n, i) {
|
|
254
|
+
return i == null || i === !1 || i === "" ? this : (this.props.push([n, String(i)]), this);
|
|
255
|
+
}
|
|
256
|
+
mm(n, i, e, r = 2) {
|
|
257
|
+
return this.add(n, `${F(lt(i, e), r)}px`);
|
|
258
|
+
}
|
|
259
|
+
toString() {
|
|
260
|
+
let n = "";
|
|
261
|
+
for (const [i, e] of this.props)
|
|
262
|
+
n += `${i}:${e};`;
|
|
263
|
+
return n;
|
|
264
|
+
}
|
|
265
|
+
applyTo(n) {
|
|
266
|
+
const i = this.toString();
|
|
267
|
+
i && (n.style.cssText = i);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
function tt(t, n, i) {
|
|
271
|
+
const e = n.style || {};
|
|
272
|
+
t.add("color", e.color).add("background-color", e.backgroundColor).add("font-family", e.fontFamily).add("font-weight", e.bold ? "700" : void 0).add("font-style", e.italic ? "italic" : void 0).add("text-decoration", e.underline ? "underline" : void 0).add("letter-spacing", e.letterSpacing != null ? `${e.letterSpacing}pt` : void 0).add("opacity", e.opacity != null ? String(e.opacity) : void 0).add("transform", e.rotateDeg ? `rotate(${e.rotateDeg}deg)` : void 0);
|
|
273
|
+
const r = _(e, i);
|
|
274
|
+
t.add("font-size", `${F(r.fontSizePx, 2)}px`);
|
|
275
|
+
}
|
|
276
|
+
function Tt(t, n, i, e, r) {
|
|
277
|
+
const l = r.createElement("table");
|
|
278
|
+
if (l.className = x("grid", e), new $().add("width", "100%").add("height", "100%").add("border-collapse", "collapse").add("table-layout", t.colWidthsMm ? "fixed" : "auto").applyTo(l), t.colWidthsMm) {
|
|
279
|
+
const d = r.createElement("colgroup");
|
|
280
|
+
for (const h of t.colWidthsMm) {
|
|
281
|
+
const c = r.createElement("col");
|
|
282
|
+
new $().mm("width", h, i).applyTo(c), d.appendChild(c);
|
|
283
|
+
}
|
|
284
|
+
l.appendChild(d);
|
|
285
|
+
}
|
|
286
|
+
const a = G(n.style), o = z(n.style), s = a.inner ? `${F(o.widthPt * i / 72, 2)}px solid ${o.color}` : "";
|
|
287
|
+
return t.cells.forEach((d, h) => {
|
|
288
|
+
const c = r.createElement("tr");
|
|
289
|
+
c.className = x("row", e), t.rowHeightsMm?.[h] != null && new $().mm("height", t.rowHeightsMm[h], i).applyTo(c), (d || []).forEach((m) => {
|
|
290
|
+
const f = r.createElement("td");
|
|
291
|
+
f.className = x("cell", e), m?.colSpan && (f.colSpan = m.colSpan), m?.rowSpan && (f.rowSpan = m.rowSpan);
|
|
292
|
+
const g = new $();
|
|
293
|
+
if (s && g.add("border", s), m?.style) {
|
|
294
|
+
const b = m.style;
|
|
295
|
+
g.add("text-align", b.align).add("vertical-align", b.verticalAlign).add("background-color", b.backgroundColor).add("color", b.color).add("font-weight", b.bold ? "700" : void 0), g.add("font-size", `${F(_(b, i).fontSizePx, 2)}px`);
|
|
296
|
+
}
|
|
297
|
+
if (g.applyTo(f), m?.text != null && (f.textContent = m.text), m?.children?.length)
|
|
298
|
+
for (const b of m.children)
|
|
299
|
+
f.appendChild(et(b, i, e, r));
|
|
300
|
+
c.appendChild(f);
|
|
301
|
+
}), l.appendChild(c);
|
|
302
|
+
}), l;
|
|
303
|
+
}
|
|
304
|
+
function vt(t, n, i, e) {
|
|
305
|
+
const r = e.createElement("div");
|
|
306
|
+
r.className = x("text", i);
|
|
307
|
+
const l = t.style || {}, a = new $().add("text-align", l.align).add("display", "flex").add("flex-direction", "column").add(
|
|
308
|
+
"justify-content",
|
|
309
|
+
l.verticalAlign === "middle" ? "center" : l.verticalAlign === "bottom" ? "flex-end" : "flex-start"
|
|
310
|
+
).add("overflow", "hidden");
|
|
311
|
+
if (tt(a, t, n), a.applyTo(r), X(t)) {
|
|
312
|
+
const o = e.createElement("div");
|
|
313
|
+
o.className = x("rich", i);
|
|
314
|
+
for (const s of t.richParagraphs) {
|
|
315
|
+
const d = e.createElement("div");
|
|
316
|
+
d.className = x("paragraph", i), new $().add("text-align", s.align).add("line-height", s.lineHeight != null ? String(s.lineHeight) : void 0).mm("margin-top", s.spaceBeforeMm ?? 0, n).mm("margin-bottom", s.spaceAfterMm ?? 0, n).mm("text-indent", s.indentMm ?? 0, n).applyTo(d);
|
|
317
|
+
for (const c of s.segments || []) {
|
|
318
|
+
const m = e.createElement("span");
|
|
319
|
+
if (m.className = x("segment", i), m.textContent = c.kind === "field" ? c.field ?? "" : c.text ?? "", c.style) {
|
|
320
|
+
const f = new $().add("color", c.style.color).add("font-weight", c.style.bold ? "700" : void 0);
|
|
321
|
+
f.add("font-size", `${F(_(c.style, n).fontSizePx, 2)}px`), f.applyTo(m);
|
|
322
|
+
}
|
|
323
|
+
d.appendChild(m);
|
|
324
|
+
}
|
|
325
|
+
o.appendChild(d);
|
|
326
|
+
}
|
|
327
|
+
return r.appendChild(o), r;
|
|
328
|
+
}
|
|
329
|
+
if (Array.isArray(t.lines) && t.lines.length > 0) {
|
|
330
|
+
const o = e.createElement("div");
|
|
331
|
+
o.className = x("lines", i), l.lineHeight != null && new $().add("line-height", String(l.lineHeight)).applyTo(o);
|
|
332
|
+
for (const s of t.lines) {
|
|
333
|
+
const d = e.createElement("div");
|
|
334
|
+
d.className = x("line", i), d.textContent = s, o.appendChild(d);
|
|
335
|
+
}
|
|
336
|
+
return r.appendChild(o), r;
|
|
337
|
+
}
|
|
338
|
+
return r.textContent = t.text ?? "", r;
|
|
339
|
+
}
|
|
340
|
+
function kt(t, n, i) {
|
|
341
|
+
const e = i.createElement("img");
|
|
342
|
+
return e.className = x("image", n), e.src = t.imageData, new $().add("width", "100%").add("height", "100%").add("object-fit", "contain").add("display", "block").applyTo(e), e.alt = t.kind, e;
|
|
343
|
+
}
|
|
344
|
+
function Y(t, n, i, e) {
|
|
345
|
+
const r = e.createElement("div");
|
|
346
|
+
r.className = x("shape", i);
|
|
347
|
+
const l = t.style || {}, a = z(l), o = G(l), s = `${F(a.widthPt * n / 72, 2)}px solid ${a.color}`, d = new $();
|
|
348
|
+
return t.grid || t.kind === "rect" ? (o.top && d.add("border-top", s), o.right && d.add("border-right", s), o.bottom && d.add("border-bottom", s), o.left && d.add("border-left", s)) : t.kind === "ellipse" ? (o.inner && d.add("border", s).add("border-radius", "50%"), l.backgroundColor && d.add("background-color", l.backgroundColor)) : t.kind === "line" && d.add("height", "0").add("border-top", s), d.add("box-sizing", "border-box").add("width", "100%").add("height", "100%"), d.applyTo(r), r;
|
|
349
|
+
}
|
|
350
|
+
function et(t, n, i, e) {
|
|
351
|
+
const r = e.createElement("div");
|
|
352
|
+
r.className = `${x("comp", i)} mr-kind-${t.kind}`;
|
|
353
|
+
const l = new $().add("position", "absolute").mm("left", t.leftMm, n).mm("top", t.topMm, n).mm("width", t.widthMm, n).mm("height", t.heightMm, n).add("box-sizing", "border-box");
|
|
354
|
+
if (tt(l, t, n), l.applyTo(r), st(t))
|
|
355
|
+
return r.appendChild(kt(t, i, e)), r;
|
|
356
|
+
if (t.kind === "text")
|
|
357
|
+
return r.appendChild(vt(t, n, i, e)), r;
|
|
358
|
+
if (t.grid) {
|
|
359
|
+
const o = Y(t, n, i, e);
|
|
360
|
+
return o.appendChild(Tt(t.grid, t, n, i, e)), r.appendChild(o), r;
|
|
361
|
+
}
|
|
362
|
+
if (t.kind === "line" || t.kind === "rect" || t.kind === "ellipse" || t.kind === "chart")
|
|
363
|
+
return r.appendChild(Y(t, n, i, e)), r;
|
|
364
|
+
const a = e.createElement("div");
|
|
365
|
+
return a.className = x("unknown", i), a.textContent = t.fallbackText ?? "", r.appendChild(a), r;
|
|
366
|
+
}
|
|
367
|
+
function xt(t, n, i, e) {
|
|
368
|
+
const r = e.createElement("div");
|
|
369
|
+
r.className = x("page", i), new $().add("position", "relative").mm("width", t.pageWidthMm, n).mm("height", t.pageHeightMm, n).add("background-color", "#fff").add("overflow", "hidden").add("box-sizing", "border-box").applyTo(r);
|
|
370
|
+
for (const l of t.components)
|
|
371
|
+
r.appendChild(et(l, n, i, e));
|
|
372
|
+
return r;
|
|
373
|
+
}
|
|
374
|
+
function Wt(t, n, i = {}) {
|
|
375
|
+
const e = i.dpi ?? 96, r = n.createElement("div");
|
|
376
|
+
return r.className = x("root", i), r.dataset.schemaVersion = t.schemaVersion, t.pages.forEach((l) => {
|
|
377
|
+
r.appendChild(xt(l, e, i, n));
|
|
378
|
+
}), r;
|
|
379
|
+
}
|
|
380
|
+
function Ct(t) {
|
|
381
|
+
const { pageHeightsPx: n, viewportHeightPx: i, scrollTopPx: e, overscan: r = 1, gapPx: l = 0 } = t, a = n.length;
|
|
382
|
+
if (a === 0)
|
|
383
|
+
return { start: 0, end: -1, padTopPx: 0, padBottomPx: 0 };
|
|
384
|
+
const o = Math.max(0, l), s = new Array(a + 1);
|
|
385
|
+
s[0] = 0;
|
|
386
|
+
for (let w = 0; w < a; w++)
|
|
387
|
+
s[w + 1] = s[w] + Math.max(0, n[w] ?? 0) + o;
|
|
388
|
+
const d = s[a], h = Math.max(0, e);
|
|
389
|
+
let c = 0, m = 0, f = a - 1;
|
|
390
|
+
for (; m <= f; ) {
|
|
391
|
+
const w = m + f >> 1;
|
|
392
|
+
s[w] <= h ? (c = w, m = w + 1) : f = w - 1;
|
|
393
|
+
}
|
|
394
|
+
const g = Math.max(0, Math.min(a - 1, c - r)), b = s[c] + Math.max(0, i);
|
|
395
|
+
let p = a - 1;
|
|
396
|
+
for (m = 0, f = a - 1; m <= f; ) {
|
|
397
|
+
const w = m + f >> 1;
|
|
398
|
+
s[w + 1] < b ? m = w + 1 : (p = w, f = w - 1);
|
|
399
|
+
}
|
|
400
|
+
const C = Math.min(a - 1, p + r), v = s[g], E = Math.max(0, d - s[C + 1]);
|
|
401
|
+
return { start: g, end: C, padTopPx: v, padBottomPx: E };
|
|
402
|
+
}
|
|
403
|
+
const q = 96 / 25.4;
|
|
404
|
+
function nt(t, n = 96) {
|
|
405
|
+
const i = n / 96 * q;
|
|
406
|
+
return {
|
|
407
|
+
widthPx: Math.max(1, Math.round(t.pageWidthMm * i)),
|
|
408
|
+
heightPx: Math.max(1, Math.round(t.pageHeightMm * i))
|
|
409
|
+
};
|
|
410
|
+
}
|
|
411
|
+
function Pt(t, n, i) {
|
|
412
|
+
const e = document.createElement("canvas"), { widthPx: r, heightPx: l } = nt(t, i);
|
|
413
|
+
e.width = Math.round(r * n), e.height = Math.round(l * n), e.style.width = `${r}px`, e.style.height = `${l}px`;
|
|
414
|
+
const a = e.getContext("2d");
|
|
415
|
+
if (!a)
|
|
416
|
+
throw new Error("当前环境不支持 Canvas 2D(测试需真浏览器,见 e2e/canvas.spec.ts)");
|
|
417
|
+
return a.scale(n, n), a.fillStyle = "#ffffff", a.fillRect(0, 0, r, l), { canvas: e, ctx: a };
|
|
418
|
+
}
|
|
419
|
+
function It(t, n = 96) {
|
|
420
|
+
return _(t, n).fontSizePx;
|
|
421
|
+
}
|
|
422
|
+
function it(t, n, i, e, r, l, a, o = "top") {
|
|
423
|
+
t.font = `${n.bold ? "bold " : ""}${n.fontSizePx}px ${a}`, t.fillStyle = n.color, t.textBaseline = "alphabetic";
|
|
424
|
+
const s = n.fontSizePx * n.lineHeight, d = n.text === "" ? [""] : n.text.split(`
|
|
425
|
+
`), h = d.length * s;
|
|
426
|
+
let c = e;
|
|
427
|
+
o === "middle" ? c = e + (l - h) / 2 : o === "bottom" && (c = e + l - h), d.forEach((m, f) => {
|
|
428
|
+
t.textAlign = n.align === "center" ? "center" : n.align === "right" ? "right" : "left";
|
|
429
|
+
const g = n.align === "center" ? i + r / 2 : n.align === "right" ? i + r : i;
|
|
430
|
+
t.fillText(m, g, c + f * s + n.fontSizePx * 0.8, r);
|
|
431
|
+
}), t.textAlign = "left";
|
|
432
|
+
}
|
|
433
|
+
function At(t, n, i, e, r, l, a, o, s, d, h) {
|
|
434
|
+
const c = ht(n, l / o, a / o), m = G(i.style), f = z(i.style);
|
|
435
|
+
for (const g of c.cells) {
|
|
436
|
+
const b = g.cell.style?.backgroundColor;
|
|
437
|
+
b && (t.fillStyle = b, t.fillRect(
|
|
438
|
+
e + g.xMm * o,
|
|
439
|
+
r + g.yMm * o,
|
|
440
|
+
g.widthMm * o,
|
|
441
|
+
g.heightMm * o
|
|
442
|
+
));
|
|
443
|
+
}
|
|
444
|
+
if (m.inner) {
|
|
445
|
+
t.strokeStyle = f.color, t.lineWidth = D(f.widthPt, s);
|
|
446
|
+
for (const g of c.edges)
|
|
447
|
+
t.beginPath(), g.kind === "v" ? (t.moveTo(e + g.pos * o, r + g.from * o), t.lineTo(e + g.pos * o, r + g.to * o)) : (t.moveTo(e + g.from * o, r + g.pos * o), t.lineTo(e + g.to * o, r + g.pos * o)), t.stroke();
|
|
448
|
+
t.beginPath(), m.top && (t.moveTo(e, r), t.lineTo(e + l, r)), m.right && (t.moveTo(e + l, r), t.lineTo(e + l, r + a)), m.bottom && (t.moveTo(e + l, r + a), t.lineTo(e, r + a)), m.left && (t.moveTo(e, r + a), t.lineTo(e, r)), t.stroke();
|
|
449
|
+
}
|
|
450
|
+
for (const g of c.cells) {
|
|
451
|
+
const b = typeof g.cell.text == "string" ? g.cell.text : "";
|
|
452
|
+
if (!b) continue;
|
|
453
|
+
const p = g.cell.style, C = p?.fontSize ?? j, v = O(
|
|
454
|
+
b,
|
|
455
|
+
g.widthMm - 1,
|
|
456
|
+
{ fontSizePt: C },
|
|
457
|
+
h
|
|
458
|
+
).join(`
|
|
459
|
+
`);
|
|
460
|
+
it(
|
|
461
|
+
t,
|
|
462
|
+
{
|
|
463
|
+
text: v,
|
|
464
|
+
fontSizePx: _(p, s).fontSizePx,
|
|
465
|
+
bold: p?.bold ?? !1,
|
|
466
|
+
color: p?.color ?? Z(i.style, ct),
|
|
467
|
+
align: p?.align ?? "left",
|
|
468
|
+
lineHeight: J
|
|
469
|
+
},
|
|
470
|
+
e + (g.xMm + 0.5) * o,
|
|
471
|
+
r + g.yMm * o,
|
|
472
|
+
Math.max(0, (g.widthMm - 1) * o),
|
|
473
|
+
g.heightMm * o,
|
|
474
|
+
d,
|
|
475
|
+
p?.verticalAlign ?? "middle"
|
|
476
|
+
);
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
function rt(t, n, i, e, r, l) {
|
|
480
|
+
const a = n.leftMm * i, o = n.topMm * i, s = n.widthMm * i, d = n.heightMm * i, h = n.style ?? {};
|
|
481
|
+
if (n.grid) {
|
|
482
|
+
At(t, n.grid, n, a, o, s, d, i, e, r, l);
|
|
483
|
+
return;
|
|
484
|
+
}
|
|
485
|
+
switch (n.kind) {
|
|
486
|
+
case "text": {
|
|
487
|
+
const c = h.fontSize ?? j, m = X(n) ? n.richParagraphs.map((f) => (f.segments ?? []).map((g) => g.text ?? g.field ?? "").join("")).join(`
|
|
488
|
+
`) : Array.isArray(n.lines) && n.lines.length > 0 ? n.lines.join(`
|
|
489
|
+
`) : O(n.text ?? "", n.widthMm, { fontSizePt: c }, l).join(`
|
|
490
|
+
`);
|
|
491
|
+
it(
|
|
492
|
+
t,
|
|
493
|
+
{
|
|
494
|
+
text: m,
|
|
495
|
+
fontSizePx: _(h, e).fontSizePx,
|
|
496
|
+
bold: h.bold ?? !1,
|
|
497
|
+
color: Z(h),
|
|
498
|
+
align: h.align ?? "left",
|
|
499
|
+
lineHeight: dt(h)
|
|
500
|
+
},
|
|
501
|
+
a,
|
|
502
|
+
o,
|
|
503
|
+
s,
|
|
504
|
+
d,
|
|
505
|
+
r,
|
|
506
|
+
h.verticalAlign
|
|
507
|
+
);
|
|
508
|
+
break;
|
|
509
|
+
}
|
|
510
|
+
case "rect": {
|
|
511
|
+
const c = z(h), m = G(h);
|
|
512
|
+
h.backgroundColor && (t.fillStyle = h.backgroundColor, t.fillRect(a, o, s, d)), m.inner && (t.strokeStyle = c.color, t.lineWidth = D(c.widthPt, e), t.beginPath(), m.top && (t.moveTo(a, o), t.lineTo(a + s, o)), m.right && (t.moveTo(a + s, o), t.lineTo(a + s, o + d)), m.bottom && (t.moveTo(a + s, o + d), t.lineTo(a, o + d)), m.left && (t.moveTo(a, o + d), t.lineTo(a, o)), t.stroke());
|
|
513
|
+
break;
|
|
514
|
+
}
|
|
515
|
+
case "line": {
|
|
516
|
+
const c = z({ ...h, borderColor: h.lineColor ?? h.borderColor });
|
|
517
|
+
t.strokeStyle = c.color, t.lineWidth = D(c.widthPt, e), t.beginPath(), t.moveTo(a, o + d / 2), t.lineTo(a + s, o + d / 2), t.stroke();
|
|
518
|
+
break;
|
|
519
|
+
}
|
|
520
|
+
case "ellipse": {
|
|
521
|
+
const c = z(h);
|
|
522
|
+
t.strokeStyle = c.color, t.lineWidth = D(c.widthPt, e), h.backgroundColor && (t.fillStyle = h.backgroundColor, t.beginPath(), t.ellipse(a + s / 2, o + d / 2, s / 2, d / 2, 0, 0, Math.PI * 2), t.fill()), t.beginPath(), t.ellipse(a + s / 2, o + d / 2, s / 2, d / 2, 0, 0, Math.PI * 2), t.stroke();
|
|
523
|
+
break;
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
function Dt(t, n = {}) {
|
|
528
|
+
const i = n.dpr ?? (typeof devicePixelRatio == "number" ? devicePixelRatio : 1), e = n.dpi ?? 96, r = e / 96 * q, l = n.fontFamily ?? '"Microsoft YaHei", sans-serif', a = n.measurer ?? V, o = Math.max(0, n.start ?? 0), s = Math.min(t.pages.length - 1, n.end ?? t.pages.length - 1), d = [];
|
|
529
|
+
for (let h = o; h <= s; h++) {
|
|
530
|
+
const c = t.pages[h], { canvas: m, ctx: f } = Pt(c, i, e);
|
|
531
|
+
for (const g of c.components)
|
|
532
|
+
rt(f, g, r, e, l, a);
|
|
533
|
+
d.push(m);
|
|
534
|
+
}
|
|
535
|
+
return { canvases: d };
|
|
536
|
+
}
|
|
537
|
+
function jt(t, n = {}) {
|
|
538
|
+
const i = n.dpr ?? (typeof devicePixelRatio == "number" ? devicePixelRatio : 1), e = n.dpi ?? 96, r = e / 96 * q, l = n.fontFamily ?? '"Microsoft YaHei", sans-serif', a = n.measurer ?? V, o = n.overscan ?? 1, s = n.gapPx ?? 18, d = n.pagesPerFrame ?? 1, h = t.pages.map((u) => u.pageHeightMm * r), c = Math.max(1, ...t.pages.map((u) => u.pageWidthMm * r)), m = { start: 0, end: -1 };
|
|
539
|
+
let f = null, g = null, b = null, p = null, C = [], v = 0, E = [];
|
|
540
|
+
function w() {
|
|
541
|
+
const u = f;
|
|
542
|
+
u.innerHTML = "", g = document.createElement("div"), g.style.cssText = `width:${c}px;margin:0 auto;`, b = document.createElement("div"), p = document.createElement("div"), g.appendChild(b), C = [];
|
|
543
|
+
const y = Math.min(t.pages.length, 3 + o * 2);
|
|
544
|
+
for (let S = 0; S < y; S++) {
|
|
545
|
+
const M = document.createElement("div");
|
|
546
|
+
M.style.cssText = `margin:0 auto ${s}px;box-shadow:0 2px 8px rgba(0,0,0,.35);background:#fff;`, g.appendChild(M), C.push(M);
|
|
547
|
+
}
|
|
548
|
+
g.appendChild(p), u.appendChild(g);
|
|
549
|
+
}
|
|
550
|
+
function W(u, y) {
|
|
551
|
+
const S = t.pages[y], { widthPx: M, heightPx: P } = nt(S, e);
|
|
552
|
+
let A = u.firstElementChild;
|
|
553
|
+
(!A || A.tagName !== "CANVAS") && (A = document.createElement("canvas"), u.innerHTML = "", u.appendChild(A)), A.width = Math.round(M * i), A.height = Math.round(P * i), A.style.width = `${M}px`, A.style.height = `${P}px`;
|
|
554
|
+
const N = A.getContext("2d");
|
|
555
|
+
if (N) {
|
|
556
|
+
N.setTransform(1, 0, 0, 1, 0, 0), N.scale(i, i), N.fillStyle = "#ffffff", N.fillRect(0, 0, M, P);
|
|
557
|
+
for (const ot of S.components)
|
|
558
|
+
rt(N, ot, r, e, l, a);
|
|
559
|
+
A.dataset.canvasPage = String(y), u.style.height = `${P}px`, u.style.width = `${M}px`;
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
function R(u) {
|
|
563
|
+
m.start = u.start, m.end = u.end, b.style.height = `${u.start * s + h.slice(0, u.start).reduce((M, P) => M + P, 0)}px`;
|
|
564
|
+
const y = t.pages.length - 1 - u.end;
|
|
565
|
+
p.style.height = `${y * s + h.slice(u.end + 1).reduce((M, P) => M + P, 0)}px`;
|
|
566
|
+
const S = u.end - u.start + 1;
|
|
567
|
+
C.forEach((M, P) => {
|
|
568
|
+
if (P < S) {
|
|
569
|
+
M.style.display = "";
|
|
570
|
+
const A = u.start + P;
|
|
571
|
+
M.style.height = `${h[A] ?? 0}px`;
|
|
572
|
+
} else
|
|
573
|
+
M.style.display = "none";
|
|
574
|
+
}), E = [];
|
|
575
|
+
for (let M = u.start; M <= u.end; M++) {
|
|
576
|
+
const P = C[M - u.start];
|
|
577
|
+
if (!P) continue;
|
|
578
|
+
P.firstElementChild?.dataset?.canvasPage !== String(M) && E.push(M);
|
|
579
|
+
}
|
|
580
|
+
I();
|
|
581
|
+
}
|
|
582
|
+
function I() {
|
|
583
|
+
v || E.length === 0 || (v = requestAnimationFrame(() => {
|
|
584
|
+
v = 0;
|
|
585
|
+
let u = Math.max(1, d);
|
|
586
|
+
for (; E.length > 0 && u-- > 0; ) {
|
|
587
|
+
const y = E.shift(), S = C[y - m.start];
|
|
588
|
+
S && W(S, y);
|
|
589
|
+
}
|
|
590
|
+
E.length > 0 && I();
|
|
591
|
+
}));
|
|
592
|
+
}
|
|
593
|
+
function H() {
|
|
594
|
+
v || (v = requestAnimationFrame(() => {
|
|
595
|
+
v = 0;
|
|
596
|
+
const u = f, y = Ct({
|
|
597
|
+
pageHeightsPx: h,
|
|
598
|
+
viewportHeightPx: u.clientHeight,
|
|
599
|
+
scrollTopPx: u.scrollTop,
|
|
600
|
+
overscan: o,
|
|
601
|
+
gapPx: s
|
|
602
|
+
});
|
|
603
|
+
y.start !== m.start || y.end !== m.end ? R(y) : I();
|
|
604
|
+
}));
|
|
605
|
+
}
|
|
606
|
+
return {
|
|
607
|
+
attach(u) {
|
|
608
|
+
f = u, w(), u.addEventListener("scroll", H, { passive: !0 }), H();
|
|
609
|
+
},
|
|
610
|
+
destroy() {
|
|
611
|
+
v && cancelAnimationFrame(v), v = 0, f?.removeEventListener("scroll", H), E = [], g?.remove(), f = null;
|
|
612
|
+
},
|
|
613
|
+
window() {
|
|
614
|
+
return { ...m };
|
|
615
|
+
}
|
|
616
|
+
};
|
|
617
|
+
}
|
|
618
|
+
function T(t, n) {
|
|
619
|
+
return typeof t == "number" && Number.isFinite(t) ? t : n;
|
|
620
|
+
}
|
|
621
|
+
function k(t, n = "") {
|
|
622
|
+
return typeof t == "string" ? t : n;
|
|
623
|
+
}
|
|
624
|
+
function B(t) {
|
|
625
|
+
return typeof t == "object" && t !== null && !Array.isArray(t);
|
|
626
|
+
}
|
|
627
|
+
function Et(t) {
|
|
628
|
+
return t === "Center" ? "center" : t === "Right" ? "right" : "left";
|
|
629
|
+
}
|
|
630
|
+
function $t(t) {
|
|
631
|
+
return t === "Center" ? "middle" : t === "Bottom" ? "bottom" : "top";
|
|
632
|
+
}
|
|
633
|
+
function Ht(t) {
|
|
634
|
+
const n = parseFloat(k(t.FontSize, "10.5"));
|
|
635
|
+
return {
|
|
636
|
+
fontSize: Number.isFinite(n) ? n : 10.5,
|
|
637
|
+
fontFamily: k(t.FontFamily, "黑体") || void 0,
|
|
638
|
+
bold: k(t.FontWeight) === "bold" || void 0,
|
|
639
|
+
italic: k(t.FontStyle) === "italic" || void 0,
|
|
640
|
+
underline: t.Underline === !0 || void 0,
|
|
641
|
+
color: k(t.FontColor) || void 0,
|
|
642
|
+
backgroundColor: k(t.BackgroundColor) || void 0,
|
|
643
|
+
align: Et(k(t.HorAlignment, "Left")),
|
|
644
|
+
verticalAlign: $t(k(t.VertAlignment, "Top")),
|
|
645
|
+
lineHeight: (() => {
|
|
646
|
+
const i = parseFloat(k(t.RowSpace, "1"));
|
|
647
|
+
return Number.isFinite(i) && i !== 1 ? i : void 0;
|
|
648
|
+
})(),
|
|
649
|
+
borderColor: k(t.BorderColor) || void 0,
|
|
650
|
+
borderTop: t.BorderTop !== !1,
|
|
651
|
+
borderRight: t.BorderRight !== !1,
|
|
652
|
+
borderBottom: t.BorderBottom !== !1,
|
|
653
|
+
borderLeft: t.BorderLeft !== !1
|
|
654
|
+
};
|
|
655
|
+
}
|
|
656
|
+
function Rt(t, n) {
|
|
657
|
+
const i = k(t.uitype), e = {
|
|
658
|
+
kind: "text",
|
|
659
|
+
leftMm: T(t.left, 0),
|
|
660
|
+
topMm: T(t.top, 0),
|
|
661
|
+
widthMm: T(t.width, 40),
|
|
662
|
+
heightMm: T(t.height, 8),
|
|
663
|
+
nid: k(t.nid) || void 0,
|
|
664
|
+
style: Ht(t)
|
|
665
|
+
};
|
|
666
|
+
switch (i) {
|
|
667
|
+
case "text": {
|
|
668
|
+
e.kind = "text";
|
|
669
|
+
const r = t.Text ?? t.text ?? t.Value;
|
|
670
|
+
e.text = r == null ? "" : String(r);
|
|
671
|
+
const l = t.Lines ?? t.lines;
|
|
672
|
+
return Array.isArray(l) && (e.lines = l.map((a) => String(a))), e;
|
|
673
|
+
}
|
|
674
|
+
case "richtext":
|
|
675
|
+
return e.kind = "text", e.text = k(t.Text), n.push(`富文本 ${e.nid ?? ""} 导入为纯文本(版式细节可能损失)`), e;
|
|
676
|
+
case "image":
|
|
677
|
+
case "barcode":
|
|
678
|
+
case "qrcode":
|
|
679
|
+
case "chart":
|
|
680
|
+
return e.kind = i === "image" ? "image" : i, e.fallbackText = `[${i}]`, n.push(`图片类组件 ${e.nid ?? ""} 需运行时数据(imageData),已导入为占位`), e;
|
|
681
|
+
case "table": {
|
|
682
|
+
e.kind = "rect";
|
|
683
|
+
const r = t.Cells ?? t.cells;
|
|
684
|
+
if (Array.isArray(r)) {
|
|
685
|
+
const l = {
|
|
686
|
+
cells: r.map(
|
|
687
|
+
(a) => Array.isArray(a) ? a.map((o) => ({
|
|
688
|
+
text: B(o) ? k(o.Text ?? o.text) : "",
|
|
689
|
+
colSpan: B(o) ? T(o.ColSpan, 1) : 1
|
|
690
|
+
})) : []
|
|
691
|
+
)
|
|
692
|
+
};
|
|
693
|
+
e.grid = l;
|
|
694
|
+
} else
|
|
695
|
+
e.fallbackText = "[table]", n.push(`表格 ${e.nid ?? ""} 缺少 Cells,导入为空框`);
|
|
696
|
+
return e;
|
|
697
|
+
}
|
|
698
|
+
case "subreport":
|
|
699
|
+
return n.push(`子报表 ${e.nid ?? ""} 暂不支持导入,已跳过`), null;
|
|
700
|
+
default:
|
|
701
|
+
return k(t.ShapeType) === "hline" || i === "hline" || i === "vline" ? (e.kind = "line", e) : i === "rect" || i === "oval" || i === "shape" ? (e.kind = i === "oval" ? "ellipse" : "rect", e) : (n.push(`未知组件类型 ${i},已跳过`), null);
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
function Ot(t) {
|
|
705
|
+
const n = [];
|
|
706
|
+
let i = null;
|
|
707
|
+
if (typeof t == "string")
|
|
708
|
+
try {
|
|
709
|
+
const d = JSON.parse(t);
|
|
710
|
+
B(d) && (i = d);
|
|
711
|
+
} catch {
|
|
712
|
+
return {
|
|
713
|
+
template: { pages: [] },
|
|
714
|
+
warnings: ["content 不是合法 JSON"]
|
|
715
|
+
};
|
|
716
|
+
}
|
|
717
|
+
else B(t) && (i = t);
|
|
718
|
+
if (!i)
|
|
719
|
+
return { template: { pages: [] }, warnings: ["content 为空"] };
|
|
720
|
+
const e = B(i.GlobalConfig) ? i.GlobalConfig : {}, r = T(e.paperWidthMm, 210), l = T(e.paperHeightMm, 297), a = {
|
|
721
|
+
top: T(e.marginTop, 10),
|
|
722
|
+
bottom: T(e.marginBottom, 10),
|
|
723
|
+
left: T(e.marginLeft, 10),
|
|
724
|
+
right: T(e.marginRight, 10)
|
|
725
|
+
}, o = Array.isArray(i.children) ? i.children.filter((d) => B(d) && k(d.uitype) === "page") : [];
|
|
726
|
+
o.length === 0 && n.push("content 中没有 uitype=page 的页节点");
|
|
727
|
+
const s = o.map((d) => {
|
|
728
|
+
const h = d, c = Array.isArray(h.children) ? h.children : [], m = [];
|
|
729
|
+
for (const f of c) {
|
|
730
|
+
if (!B(f)) continue;
|
|
731
|
+
const g = Rt(f, n);
|
|
732
|
+
g && m.push(g);
|
|
733
|
+
}
|
|
734
|
+
return {
|
|
735
|
+
widthMm: T(h.width, r),
|
|
736
|
+
heightMm: T(h.DesignHeight, l),
|
|
737
|
+
marginTopMm: T(h.MarginTop, a.top),
|
|
738
|
+
marginBottomMm: T(h.MarginBottom, a.bottom),
|
|
739
|
+
marginLeftMm: T(h.MarginLeft, a.left),
|
|
740
|
+
marginRightMm: T(h.MarginRight, a.right),
|
|
741
|
+
components: m
|
|
742
|
+
};
|
|
743
|
+
});
|
|
744
|
+
return s.length === 0 && (n.push("转换结果为空页,已回退一张空白页"), s.push({
|
|
745
|
+
widthMm: r,
|
|
746
|
+
heightMm: l,
|
|
747
|
+
...a,
|
|
748
|
+
components: []
|
|
749
|
+
})), { template: { pages: s }, warnings: n };
|
|
750
|
+
}
|
|
751
|
+
function Bt(t, n, i) {
|
|
752
|
+
let e, r;
|
|
753
|
+
if (typeof t == "string") {
|
|
754
|
+
const l = U[t];
|
|
755
|
+
if (!l) throw new Error(`未知纸张预设 "${t}"(可用:${Object.keys(U).join("/")})`);
|
|
756
|
+
e = l.widthMm, r = l.heightMm;
|
|
757
|
+
} else typeof t == "number" ? (e = t, r = n ?? 297) : (e = t.widthMm, r = t.heightMm);
|
|
758
|
+
return i ? { widthMm: r, heightMm: e } : { widthMm: e, heightMm: r };
|
|
759
|
+
}
|
|
760
|
+
class Nt {
|
|
761
|
+
constructor() {
|
|
762
|
+
this.pages = [], this.pending = null;
|
|
763
|
+
}
|
|
764
|
+
/**
|
|
765
|
+
* 新建页。纸张支持三种写法:
|
|
766
|
+
* - 预设名:.page("a4", { landscape: true, margins: {...} })
|
|
767
|
+
* - 数字:.page(210, 297)(第三参数兼容旧 margins 对象或新 options)
|
|
768
|
+
* - 对象:.page({ widthMm: 210, heightMm: 297 })
|
|
769
|
+
*/
|
|
770
|
+
page(n = "a4", i = {}, e) {
|
|
771
|
+
this.collect();
|
|
772
|
+
const l = e != null && !("margins" in e) && !("landscape" in e) && ("marginTopMm" in e || "marginBottomMm" in e || "marginLeftMm" in e || "marginRightMm" in e) ? { margins: e } : e ?? {}, { widthMm: a, heightMm: o } = Bt(
|
|
773
|
+
n,
|
|
774
|
+
typeof i == "number" ? i : void 0,
|
|
775
|
+
l.landscape
|
|
776
|
+
), s = l.margins ?? {};
|
|
777
|
+
return this.pending = new Lt(this, {
|
|
778
|
+
widthMm: a,
|
|
779
|
+
heightMm: o,
|
|
780
|
+
marginTopMm: s.marginTopMm ?? 10,
|
|
781
|
+
marginBottomMm: s.marginBottomMm ?? 10,
|
|
782
|
+
marginLeftMm: s.marginLeftMm ?? 10,
|
|
783
|
+
marginRightMm: s.marginRightMm ?? 10
|
|
784
|
+
}), this.pending;
|
|
785
|
+
}
|
|
786
|
+
collect() {
|
|
787
|
+
this.pending && (this.pages.push(this.pending.buildPage()), this.pending = null);
|
|
788
|
+
}
|
|
789
|
+
build() {
|
|
790
|
+
if (this.collect(), this.pages.length === 0)
|
|
791
|
+
throw new Error("模板至少需要一页:先调用 .page() 添加内容");
|
|
792
|
+
return { pages: this.pages };
|
|
793
|
+
}
|
|
794
|
+
}
|
|
795
|
+
class Lt {
|
|
796
|
+
constructor(n, i) {
|
|
797
|
+
this.parent = n, this.page = i, this.components = [];
|
|
798
|
+
}
|
|
799
|
+
text(n, i = {}, e = {}) {
|
|
800
|
+
return this.components.push({
|
|
801
|
+
kind: "text",
|
|
802
|
+
leftMm: i.leftMm ?? 0,
|
|
803
|
+
topMm: i.topMm ?? 0,
|
|
804
|
+
widthMm: i.widthMm ?? 60,
|
|
805
|
+
heightMm: i.heightMm ?? 8,
|
|
806
|
+
text: n,
|
|
807
|
+
style: e
|
|
808
|
+
}), this;
|
|
809
|
+
}
|
|
810
|
+
list(n, i, e, r = {}) {
|
|
811
|
+
return this.components.push({
|
|
812
|
+
kind: "list",
|
|
813
|
+
leftMm: i.leftMm ?? 10,
|
|
814
|
+
topMm: i.topMm ?? 30,
|
|
815
|
+
widthMm: i.widthMm ?? 180,
|
|
816
|
+
dataset: n,
|
|
817
|
+
columns: e,
|
|
818
|
+
...r
|
|
819
|
+
}), this;
|
|
820
|
+
}
|
|
821
|
+
rect(n, i = {}) {
|
|
822
|
+
return this.components.push({ kind: "rect", ...n, style: i }), this;
|
|
823
|
+
}
|
|
824
|
+
line(n, i, e, r = {}) {
|
|
825
|
+
return this.components.push({
|
|
826
|
+
kind: "line",
|
|
827
|
+
leftMm: n,
|
|
828
|
+
topMm: i,
|
|
829
|
+
widthMm: e,
|
|
830
|
+
heightMm: 0.5,
|
|
831
|
+
style: r
|
|
832
|
+
}), this;
|
|
833
|
+
}
|
|
834
|
+
barcode(n, i) {
|
|
835
|
+
return this.components.push({
|
|
836
|
+
kind: "barcode",
|
|
837
|
+
leftMm: i.leftMm ?? 0,
|
|
838
|
+
topMm: i.topMm ?? 0,
|
|
839
|
+
widthMm: i.widthMm ?? 40,
|
|
840
|
+
heightMm: i.heightMm ?? 12,
|
|
841
|
+
fallbackText: n
|
|
842
|
+
}), this;
|
|
843
|
+
}
|
|
844
|
+
qrcode(n, i, e, r) {
|
|
845
|
+
return this.components.push({
|
|
846
|
+
kind: "qrcode",
|
|
847
|
+
leftMm: e,
|
|
848
|
+
topMm: r,
|
|
849
|
+
widthMm: i,
|
|
850
|
+
heightMm: i,
|
|
851
|
+
fallbackText: n
|
|
852
|
+
}), this;
|
|
853
|
+
}
|
|
854
|
+
buildPage() {
|
|
855
|
+
return { ...this.page, components: this.components };
|
|
856
|
+
}
|
|
857
|
+
done() {
|
|
858
|
+
return this.parent;
|
|
859
|
+
}
|
|
860
|
+
build() {
|
|
861
|
+
return this.done().build();
|
|
862
|
+
}
|
|
863
|
+
}
|
|
864
|
+
function Gt() {
|
|
865
|
+
return new Nt();
|
|
866
|
+
}
|
|
867
|
+
export {
|
|
868
|
+
qt as CSS_DPI,
|
|
869
|
+
Ut as DEFAULT_BORDER_PT,
|
|
870
|
+
j as DEFAULT_FONT_PT,
|
|
871
|
+
Kt as DEFAULT_STROKE_COLOR,
|
|
872
|
+
ct as DEFAULT_TEXT_COLOR,
|
|
873
|
+
J as LINE_HEIGHT,
|
|
874
|
+
Yt as MM_PER_INCH,
|
|
875
|
+
U as PAPER_SIZES,
|
|
876
|
+
Lt as PageBuilder,
|
|
877
|
+
at as RENDER_PLAN_SCHEMA_VERSION,
|
|
878
|
+
Xt as SCHEMA_VERSION_JH4J,
|
|
879
|
+
Zt as SCHEMA_VERSION_LOCAL,
|
|
880
|
+
Qt as SCHEMA_VERSION_MACH,
|
|
881
|
+
Nt as TemplateBuilder,
|
|
882
|
+
Ft as assertRenderPlan,
|
|
883
|
+
te as charWidthEm,
|
|
884
|
+
x as classOf,
|
|
885
|
+
Ct as computePageWindow,
|
|
886
|
+
ee as createCanvasMeasurer,
|
|
887
|
+
jt as createCanvasPager,
|
|
888
|
+
ne as createHeuristicMeasurer,
|
|
889
|
+
Gt as createTemplate,
|
|
890
|
+
V as heuristicMeasurer,
|
|
891
|
+
Ot as importJh4jTemplateContent,
|
|
892
|
+
st as isImageBackedComponent,
|
|
893
|
+
X as isRichText,
|
|
894
|
+
nt as measurePageSizePx,
|
|
895
|
+
ie as measureTextMm,
|
|
896
|
+
lt as mmToPx,
|
|
897
|
+
re as mmToPxFactor,
|
|
898
|
+
_t as paginateTemplate,
|
|
899
|
+
It as planFontSizePx,
|
|
900
|
+
D as ptToPx,
|
|
901
|
+
oe as pxToMm,
|
|
902
|
+
et as renderComponent,
|
|
903
|
+
xt as renderPage,
|
|
904
|
+
Wt as renderPlan,
|
|
905
|
+
Dt as renderPlanToCanvas,
|
|
906
|
+
G as resolveBoxBorders,
|
|
907
|
+
_ as resolveFontSize,
|
|
908
|
+
ht as resolveGridLayout,
|
|
909
|
+
dt as resolveLineHeight,
|
|
910
|
+
Bt as resolvePaper,
|
|
911
|
+
z as resolveStroke,
|
|
912
|
+
Z as resolveTextColor,
|
|
913
|
+
F as round,
|
|
914
|
+
ae as toRenderPlan,
|
|
915
|
+
Q as validateComponent,
|
|
916
|
+
ft as validatePage,
|
|
917
|
+
ut as validateRenderPlan,
|
|
918
|
+
O as wrapText
|
|
919
|
+
};
|