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