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