@agile-team/mach-report 1.0.0 → 1.1.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-Do-x4E3Z.js +1138 -0
- package/dist/ReportPreview-kNbuSmbL.cjs +6 -0
- package/dist/index.cjs +5 -5
- package/dist/index.js +263 -250
- package/dist/pdf/font-loader.d.ts +2 -1
- package/dist/pdf.cjs +44 -44
- package/dist/pdf.js +1461 -1459
- package/dist/{plugin-D3QAPZ-7.js → plugin-CVYs7wAj.js} +1 -1
- package/dist/{plugin-qyCLVA7E.cjs → plugin-DxneRya8.cjs} +1 -1
- package/dist/render/canvas.d.ts +15 -0
- package/dist/style.css +1 -1
- package/dist/vue/ReportToolbar.d.ts +2 -2
- package/dist/vue/composables/usePrintExport.d.ts +12 -1
- package/dist/vue/config.d.ts +2 -0
- package/dist/vue/errors.d.ts +1 -1
- package/dist/vue-async.cjs +1 -1
- package/dist/vue-async.js +5 -5
- package/dist/vue.cjs +1 -1
- package/dist/vue.js +25 -24
- package/package.json +1 -1
- package/dist/ReportPreview-B3auzZDn.cjs +0 -6
- package/dist/ReportPreview-BZ0GyQHJ.js +0 -1071
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { h as ot, R as
|
|
2
|
-
import { C as
|
|
1
|
+
import { h as ot, R as Et, D as X, w as Z, L as Q, i as At, r as G, m as $t, a as V, b as ut, c as O, d as tt, p as K, e as Ht, f as pt, g as Nt, P as ht } from "./style-6ihHKVCM.js";
|
|
2
|
+
import { C as ye, j as we, k as Se, M as Te, S as xe, l as ke, n as ve, o as Pe, q as Ce, s as Ee, t as Ae, u as $e, v as He, x as Ne } from "./style-6ihHKVCM.js";
|
|
3
3
|
import { r as Rt } from "./grid-geometry-Bs8QXz1X.js";
|
|
4
4
|
function Bt(t) {
|
|
5
5
|
const e = /^(\d{4})[-/](\d{1,2})[-/](\d{1,2})$/.exec(t.trim());
|
|
@@ -50,21 +50,21 @@ function zt(t, e) {
|
|
|
50
50
|
const r = t[e.field];
|
|
51
51
|
if (r == null || r === "") return !1;
|
|
52
52
|
if (typeof e.value == "number") {
|
|
53
|
-
const
|
|
54
|
-
if (
|
|
53
|
+
const a = rt(r);
|
|
54
|
+
if (a == null) return !1;
|
|
55
55
|
switch (e.op) {
|
|
56
56
|
case ">":
|
|
57
|
-
return
|
|
57
|
+
return a > e.value;
|
|
58
58
|
case ">=":
|
|
59
|
-
return
|
|
59
|
+
return a >= e.value;
|
|
60
60
|
case "<":
|
|
61
|
-
return
|
|
61
|
+
return a < e.value;
|
|
62
62
|
case "<=":
|
|
63
|
-
return
|
|
63
|
+
return a <= e.value;
|
|
64
64
|
case "==":
|
|
65
|
-
return
|
|
65
|
+
return a === e.value;
|
|
66
66
|
case "!=":
|
|
67
|
-
return
|
|
67
|
+
return a !== e.value;
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
70
|
const n = String(r), o = String(e.value);
|
|
@@ -114,21 +114,21 @@ function bt(t, e, r, n = []) {
|
|
|
114
114
|
for (const i of ["leftMm", "topMm", "widthMm", "heightMm"])
|
|
115
115
|
_t(t, i, e, r);
|
|
116
116
|
t.leftMm != null && t.widthMm != null && (t.leftMm < -100 || t.widthMm < 0) && r.push({ path: e, message: "几何数值异常(leftMm<-100 或 widthMm<0)" });
|
|
117
|
-
const
|
|
118
|
-
|
|
117
|
+
const a = t.grid;
|
|
118
|
+
a !== void 0 && (!I(a) || !Array.isArray(a.cells) ? r.push({ path: `${e}.grid.cells`, message: "grid.cells 应为二维数组" }) : a.cells.forEach((i, c) => {
|
|
119
119
|
if (!Array.isArray(i)) {
|
|
120
|
-
r.push({ path: `${e}.grid.cells.${
|
|
120
|
+
r.push({ path: `${e}.grid.cells.${c}`, message: "行应为数组" });
|
|
121
121
|
return;
|
|
122
122
|
}
|
|
123
|
-
i.forEach((
|
|
124
|
-
|
|
125
|
-
bt(m, `${e}.grid.cells.${
|
|
123
|
+
i.forEach((d, h) => {
|
|
124
|
+
d != null && I(d) && Array.isArray(d.children) && d.children.forEach((m, l) => {
|
|
125
|
+
bt(m, `${e}.grid.cells.${c}.${h}.children.${l}`, r, n);
|
|
126
126
|
});
|
|
127
127
|
});
|
|
128
128
|
}));
|
|
129
|
-
const
|
|
130
|
-
|
|
131
|
-
(!I(i) || !Array.isArray(i.segments)) && r.push({ path: `${e}.richParagraphs.${
|
|
129
|
+
const s = t.richParagraphs;
|
|
130
|
+
s !== void 0 && (Array.isArray(s) ? s.forEach((i, c) => {
|
|
131
|
+
(!I(i) || !Array.isArray(i.segments)) && r.push({ path: `${e}.richParagraphs.${c}`, message: "段落缺少 segments 数组" });
|
|
132
132
|
}) : r.push({ path: `${e}.richParagraphs`, message: "richParagraphs 应为数组" }));
|
|
133
133
|
}
|
|
134
134
|
function Wt(t, e, r, n = []) {
|
|
@@ -136,11 +136,11 @@ function Wt(t, e, r, n = []) {
|
|
|
136
136
|
r.push({ path: e, message: "页应为对象" });
|
|
137
137
|
return;
|
|
138
138
|
}
|
|
139
|
-
const o = t.pageWidthMm,
|
|
140
|
-
(typeof o != "number" || !(o > 0 && o < 3e3)) && r.push({ path: `${e}.pageWidthMm`, message: `页宽非法: ${JSON.stringify(o)}` }), (typeof
|
|
141
|
-
const
|
|
142
|
-
|
|
143
|
-
(i,
|
|
139
|
+
const o = t.pageWidthMm, a = t.pageHeightMm;
|
|
140
|
+
(typeof o != "number" || !(o > 0 && o < 3e3)) && r.push({ path: `${e}.pageWidthMm`, message: `页宽非法: ${JSON.stringify(o)}` }), (typeof a != "number" || !(a > 0 && a < 5e3)) && r.push({ path: `${e}.pageHeightMm`, message: `页高非法: ${JSON.stringify(a)}` });
|
|
141
|
+
const s = t.components;
|
|
142
|
+
s !== void 0 && !Array.isArray(s) ? r.push({ path: `${e}.components`, message: "components 应为数组" }) : Array.isArray(s) && s.forEach(
|
|
143
|
+
(i, c) => bt(i, `${e}.components.${c}`, r, n)
|
|
144
144
|
);
|
|
145
145
|
}
|
|
146
146
|
function It(t) {
|
|
@@ -151,12 +151,12 @@ function It(t) {
|
|
|
151
151
|
message: t == null ? "渲染计划为空" : "渲染计划缺少 pages 数组"
|
|
152
152
|
});
|
|
153
153
|
else {
|
|
154
|
-
n.forEach((
|
|
154
|
+
n.forEach((a, s) => Wt(a, `$.pages.${s}`, e, r)), n.length > 2e3 && r.push({
|
|
155
155
|
path: "$.pages",
|
|
156
156
|
message: `页数异常大(${n.length} 页),渲染与打印耗时可能显著增加`
|
|
157
157
|
});
|
|
158
158
|
const o = n.reduce(
|
|
159
|
-
(
|
|
159
|
+
(a, s) => a + (I(s) && Array.isArray(s.components) ? s.components.length : 0),
|
|
160
160
|
0
|
|
161
161
|
);
|
|
162
162
|
o > 5e4 && r.push({
|
|
@@ -166,7 +166,7 @@ function It(t) {
|
|
|
166
166
|
}
|
|
167
167
|
return { ok: e.length === 0, errors: e, warnings: r };
|
|
168
168
|
}
|
|
169
|
-
function
|
|
169
|
+
function ce(t) {
|
|
170
170
|
const e = It(t);
|
|
171
171
|
if (!e.ok) {
|
|
172
172
|
const r = e.errors.slice(0, 3).map((n) => `${n.path}: ${n.message}`).join("; ");
|
|
@@ -207,7 +207,7 @@ function yt(t) {
|
|
|
207
207
|
function Gt(t, e) {
|
|
208
208
|
const r = t.fontSizePt ?? X, n = t.paddingMm ?? 1, o = t.columns.map(
|
|
209
209
|
(l) => l.style ? { align: "left", verticalAlign: "middle", ...l.style } : { align: "left", verticalAlign: "middle" }
|
|
210
|
-
),
|
|
210
|
+
), a = t.columns.map(
|
|
211
211
|
(l) => ({
|
|
212
212
|
bold: t.headerBold ?? !0,
|
|
213
213
|
align: "center",
|
|
@@ -215,35 +215,35 @@ function Gt(t, e) {
|
|
|
215
215
|
backgroundColor: t.headerBackgroundColor,
|
|
216
216
|
...l.style || {}
|
|
217
217
|
})
|
|
218
|
-
),
|
|
218
|
+
), s = t.columns.map((l) => l.header), i = s.map(
|
|
219
219
|
(l, f) => Z(
|
|
220
220
|
l,
|
|
221
221
|
t.columns[f].widthMm - n * 2,
|
|
222
222
|
{ fontSizePt: r, bold: t.headerBold ?? !0 },
|
|
223
223
|
e
|
|
224
224
|
)
|
|
225
|
-
),
|
|
225
|
+
), c = Math.max(...i.map((l) => l.length), 1), d = Ot(t, c), h = s.map((l, f) => ({
|
|
226
226
|
text: l,
|
|
227
|
-
style:
|
|
227
|
+
style: a[f]
|
|
228
228
|
})), m = t.border === !1 ? { borderTop: !1, borderRight: !1, borderBottom: !1, borderLeft: !1 } : { borderBottom: !0, borderLeft: !0, borderRight: !0, borderTop: !0 };
|
|
229
229
|
return {
|
|
230
230
|
fontSizePt: r,
|
|
231
231
|
paddingMm: n,
|
|
232
232
|
cellStyles: o,
|
|
233
233
|
borderStyle: m,
|
|
234
|
-
headerHeightMm:
|
|
235
|
-
headerGrid: { cells: [h], rowHeightsMm: [
|
|
234
|
+
headerHeightMm: d,
|
|
235
|
+
headerGrid: { cells: [h], rowHeightsMm: [d] },
|
|
236
236
|
columns: t.columns
|
|
237
237
|
};
|
|
238
238
|
}
|
|
239
239
|
function gt(t, e, r) {
|
|
240
240
|
const n = t.columns, o = new Array(n.length);
|
|
241
|
-
let
|
|
241
|
+
let a = 1;
|
|
242
242
|
for (let h = 0; h < n.length; h++) {
|
|
243
243
|
const m = n[h];
|
|
244
244
|
o[h] = m.format ? Mt(e[m.field], m.format) : yt(e[m.field]);
|
|
245
245
|
}
|
|
246
|
-
const
|
|
246
|
+
const s = new Array(n.length);
|
|
247
247
|
for (let h = 0; h < n.length; h++) {
|
|
248
248
|
const m = Z(
|
|
249
249
|
o[h],
|
|
@@ -251,12 +251,12 @@ function gt(t, e, r) {
|
|
|
251
251
|
{ fontSizePt: t.fontSizePt },
|
|
252
252
|
r
|
|
253
253
|
);
|
|
254
|
-
|
|
254
|
+
s[h] = m, m.length > a && (a = m.length);
|
|
255
255
|
}
|
|
256
|
-
const i = t.fontSizePt * Q * 25.4 / 72,
|
|
256
|
+
const i = t.fontSizePt * Q * 25.4 / 72, c = Math.max(
|
|
257
257
|
t.rowHeightFloorMm,
|
|
258
|
-
|
|
259
|
-
),
|
|
258
|
+
a * i + t.paddingMm * 2
|
|
259
|
+
), d = new Array(n.length);
|
|
260
260
|
for (let h = 0; h < n.length; h++) {
|
|
261
261
|
const m = n[h];
|
|
262
262
|
let l = t.cellStyles[h];
|
|
@@ -267,16 +267,16 @@ function gt(t, e, r) {
|
|
|
267
267
|
break;
|
|
268
268
|
}
|
|
269
269
|
}
|
|
270
|
-
|
|
270
|
+
d[h] = { text: o[h], style: l };
|
|
271
271
|
}
|
|
272
|
-
return { grid: { cells: [
|
|
272
|
+
return { grid: { cells: [d], rowHeightsMm: [c] }, heightMm: c };
|
|
273
273
|
}
|
|
274
274
|
function de(t, e, r = {}) {
|
|
275
|
-
const n = typeof r == "number" ? { mmPerRow: r } : r, o = n.mmPerRow ?? 0,
|
|
276
|
-
let
|
|
277
|
-
const
|
|
275
|
+
const n = typeof r == "number" ? { mmPerRow: r } : r, o = n.mmPerRow ?? 0, a = n.measurer ?? ot, s = [], i = [];
|
|
276
|
+
let c = 0;
|
|
277
|
+
const d = (m) => `${m}_${(++c).toString(36)}`, h = [];
|
|
278
278
|
for (const m of t.pages) {
|
|
279
|
-
const l = mt(m), f = () => jt(m, l), g = l.marginTopMm, w = [],
|
|
279
|
+
const l = mt(m), f = () => jt(m, l), g = l.marginTopMm, w = [], A = () => {
|
|
280
280
|
if (i.push({
|
|
281
281
|
pageWidthMm: l.widthMm,
|
|
282
282
|
pageHeightMm: l.heightMm,
|
|
@@ -309,9 +309,9 @@ function de(t, e, r = {}) {
|
|
|
309
309
|
continue;
|
|
310
310
|
}
|
|
311
311
|
const b = x, P = e[b.dataset];
|
|
312
|
-
Array.isArray(P) ||
|
|
313
|
-
const S = Array.isArray(P) ? P : [],
|
|
314
|
-
...Gt(k,
|
|
312
|
+
Array.isArray(P) || s.push(`数据集 ${b.dataset} 未提供数据,列表 ${b.id ?? ""} 输出为空`);
|
|
313
|
+
const S = Array.isArray(P) ? P : [], q = b.columns.reduce((p, M) => p + M.widthMm, 0), J = q > b.widthMm ? b.widthMm / q : 1, k = J === 1 ? b : { ...b, columns: b.columns.map((p) => ({ ...p, widthMm: p.widthMm * J })) }, $ = {
|
|
314
|
+
...Gt(k, a),
|
|
315
315
|
rowHeightFloorMm: k.rowHeightMm ?? 0
|
|
316
316
|
}, j = {
|
|
317
317
|
kind: "rect",
|
|
@@ -320,7 +320,7 @@ function de(t, e, r = {}) {
|
|
|
320
320
|
widthMm: b.widthMm,
|
|
321
321
|
heightMm: $.headerHeightMm,
|
|
322
322
|
grid: $.headerGrid,
|
|
323
|
-
nid:
|
|
323
|
+
nid: d("listh"),
|
|
324
324
|
style: $.borderStyle
|
|
325
325
|
};
|
|
326
326
|
let u = b.topMm;
|
|
@@ -330,7 +330,7 @@ function de(t, e, r = {}) {
|
|
|
330
330
|
H(l, u), u += $.headerHeightMm + o;
|
|
331
331
|
const L = (p) => {
|
|
332
332
|
if (u + p > f()) {
|
|
333
|
-
|
|
333
|
+
A();
|
|
334
334
|
const M = mt(m);
|
|
335
335
|
l.components = M.components, l.heightMm = M.heightMm, k.headerEveryPage !== !1 ? (H(l, b.topMm), u = b.topMm + $.headerHeightMm) : u = g;
|
|
336
336
|
}
|
|
@@ -342,18 +342,18 @@ function de(t, e, r = {}) {
|
|
|
342
342
|
widthMm: b.widthMm,
|
|
343
343
|
heightMm: M,
|
|
344
344
|
grid: p,
|
|
345
|
-
nid:
|
|
345
|
+
nid: d(T),
|
|
346
346
|
style: $.borderStyle
|
|
347
347
|
}), u += M;
|
|
348
|
-
}, N = () => gt($, {},
|
|
349
|
-
const D = [],
|
|
350
|
-
D.push({ text: p, colSpan:
|
|
351
|
-
for (let et =
|
|
348
|
+
}, N = () => gt($, {}, a).heightMm, C = (p, M, T, v) => {
|
|
349
|
+
const D = [], ct = Math.max(1, Math.min(v, k.columns.length));
|
|
350
|
+
D.push({ text: p, colSpan: ct, style: { bold: !0, ...T } });
|
|
351
|
+
for (let et = ct; et < k.columns.length; et++) {
|
|
352
352
|
const Ct = k.columns[et];
|
|
353
353
|
D.push({ text: M.get(Ct.field) ?? "", style: T });
|
|
354
354
|
}
|
|
355
|
-
const Pt = $.fontSizePt * Q * 25.4 / 72,
|
|
356
|
-
return { grid: { cells: [D], rowHeightsMm: [
|
|
355
|
+
const Pt = $.fontSizePt * Q * 25.4 / 72, dt = Math.max($.rowHeightFloorMm, Pt + $.paddingMm * 2);
|
|
356
|
+
return { grid: { cells: [D], rowHeightsMm: [dt] }, heightMm: dt };
|
|
357
357
|
}, _ = (p, M) => {
|
|
358
358
|
let T = 0;
|
|
359
359
|
for (const v of p) {
|
|
@@ -388,7 +388,7 @@ function de(t, e, r = {}) {
|
|
|
388
388
|
const lt = N();
|
|
389
389
|
for (const p of Y)
|
|
390
390
|
if (p.kind === "row") {
|
|
391
|
-
const M = gt($, p.row,
|
|
391
|
+
const M = gt($, p.row, a);
|
|
392
392
|
y(M.grid, M.heightMm, "listr");
|
|
393
393
|
} else if (p.kind === "groupHeader") {
|
|
394
394
|
const M = C(
|
|
@@ -422,18 +422,18 @@ function de(t, e, r = {}) {
|
|
|
422
422
|
);
|
|
423
423
|
y(v.grid, v.heightMm, "listgt");
|
|
424
424
|
} else
|
|
425
|
-
|
|
425
|
+
s.push(`列表 ${b.id ?? ""} 配置了 grandTotal 但未提供合计字段(groupBy.subtotal 或 grandTotal.fields)`);
|
|
426
426
|
}
|
|
427
427
|
}
|
|
428
|
-
|
|
428
|
+
A();
|
|
429
429
|
}
|
|
430
430
|
for (const m of h) {
|
|
431
431
|
const l = m.text;
|
|
432
432
|
typeof l == "string" && l.includes("{totalPages}") && (m.text = l.replace(/\{totalPages\}/g, String(i.length)));
|
|
433
433
|
}
|
|
434
434
|
return {
|
|
435
|
-
plan: { schemaVersion:
|
|
436
|
-
warnings:
|
|
435
|
+
plan: { schemaVersion: Et, pages: i },
|
|
436
|
+
warnings: s
|
|
437
437
|
};
|
|
438
438
|
}
|
|
439
439
|
const Vt = {
|
|
@@ -484,23 +484,23 @@ function wt(t, e, r) {
|
|
|
484
484
|
t.add("font-size", `${G(o.fontSizePx, 2)}px`);
|
|
485
485
|
}
|
|
486
486
|
function Yt(t, e, r, n, o) {
|
|
487
|
-
const
|
|
488
|
-
if (
|
|
489
|
-
const
|
|
487
|
+
const a = o.createElement("table");
|
|
488
|
+
if (a.className = B("grid", n), new z().add("width", "100%").add("height", "100%").add("border-collapse", "collapse").add("table-layout", t.colWidthsMm ? "fixed" : "auto").applyTo(a), t.colWidthsMm) {
|
|
489
|
+
const d = o.createElement("colgroup");
|
|
490
490
|
for (const h of t.colWidthsMm) {
|
|
491
491
|
const m = o.createElement("col");
|
|
492
|
-
new z().mm("width", h, r).applyTo(m),
|
|
492
|
+
new z().mm("width", h, r).applyTo(m), d.appendChild(m);
|
|
493
493
|
}
|
|
494
|
-
|
|
494
|
+
a.appendChild(d);
|
|
495
495
|
}
|
|
496
|
-
const
|
|
497
|
-
return t.cells.forEach((
|
|
496
|
+
const s = tt(e.style), i = O(e.style), c = s.inner ? `${G(i.widthPt * r / 72, 2)}px solid ${i.color}` : "";
|
|
497
|
+
return t.cells.forEach((d, h) => {
|
|
498
498
|
const m = o.createElement("tr");
|
|
499
|
-
m.className = B("row", n), t.rowHeightsMm?.[h] != null && new z().mm("height", t.rowHeightsMm[h], r).applyTo(m), (
|
|
499
|
+
m.className = B("row", n), t.rowHeightsMm?.[h] != null && new z().mm("height", t.rowHeightsMm[h], r).applyTo(m), (d || []).forEach((l) => {
|
|
500
500
|
const f = o.createElement("td");
|
|
501
501
|
f.className = B("cell", n), l?.colSpan && (f.colSpan = l.colSpan), l?.rowSpan && (f.rowSpan = l.rowSpan);
|
|
502
502
|
const g = new z();
|
|
503
|
-
if (
|
|
503
|
+
if (c && g.add("border", c), l?.style) {
|
|
504
504
|
const w = l.style;
|
|
505
505
|
g.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), g.add("font-size", `${G(V(w, r).fontSizePx, 2)}px`);
|
|
506
506
|
}
|
|
@@ -508,106 +508,106 @@ function Yt(t, e, r, n, o) {
|
|
|
508
508
|
for (const w of l.children)
|
|
509
509
|
f.appendChild(St(w, r, n, o));
|
|
510
510
|
m.appendChild(f);
|
|
511
|
-
}),
|
|
512
|
-
}),
|
|
511
|
+
}), a.appendChild(m);
|
|
512
|
+
}), a;
|
|
513
513
|
}
|
|
514
|
-
function
|
|
514
|
+
function qt(t, e, r, n) {
|
|
515
515
|
const o = n.createElement("div");
|
|
516
516
|
o.className = B("text", r);
|
|
517
|
-
const
|
|
517
|
+
const a = t.style || {}, s = 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 (wt(
|
|
521
|
+
if (wt(s, t, e), s.applyTo(o), ut(t)) {
|
|
522
522
|
const i = n.createElement("div");
|
|
523
523
|
i.className = B("rich", r);
|
|
524
|
-
for (const
|
|
525
|
-
const
|
|
526
|
-
|
|
527
|
-
for (const m of
|
|
524
|
+
for (const c of t.richParagraphs) {
|
|
525
|
+
const d = n.createElement("div");
|
|
526
|
+
d.className = B("paragraph", r), new z().add("text-align", c.align).add("line-height", c.lineHeight != null ? String(c.lineHeight) : void 0).mm("margin-top", c.spaceBeforeMm ?? 0, e).mm("margin-bottom", c.spaceAfterMm ?? 0, e).mm("text-indent", c.indentMm ?? 0, e).applyTo(d);
|
|
527
|
+
for (const m of c.segments || []) {
|
|
528
528
|
const l = n.createElement("span");
|
|
529
529
|
if (l.className = B("segment", r), l.textContent = m.kind === "field" ? m.field ?? "" : m.text ?? "", m.style) {
|
|
530
530
|
const f = new z().add("color", m.style.color).add("font-weight", m.style.bold ? "700" : void 0);
|
|
531
531
|
f.add("font-size", `${G(V(m.style, e).fontSizePx, 2)}px`), f.applyTo(l);
|
|
532
532
|
}
|
|
533
|
-
|
|
533
|
+
d.appendChild(l);
|
|
534
534
|
}
|
|
535
|
-
i.appendChild(
|
|
535
|
+
i.appendChild(d);
|
|
536
536
|
}
|
|
537
537
|
return o.appendChild(i), o;
|
|
538
538
|
}
|
|
539
539
|
if (Array.isArray(t.lines) && t.lines.length > 0) {
|
|
540
540
|
const i = n.createElement("div");
|
|
541
|
-
i.className = B("lines", r),
|
|
542
|
-
for (const
|
|
543
|
-
const
|
|
544
|
-
|
|
541
|
+
i.className = B("lines", r), a.lineHeight != null && new z().add("line-height", String(a.lineHeight)).applyTo(i);
|
|
542
|
+
for (const c of t.lines) {
|
|
543
|
+
const d = n.createElement("div");
|
|
544
|
+
d.className = B("line", r), d.textContent = c, i.appendChild(d);
|
|
545
545
|
}
|
|
546
546
|
return o.appendChild(i), o;
|
|
547
547
|
}
|
|
548
548
|
return o.textContent = t.text ?? "", o;
|
|
549
549
|
}
|
|
550
|
-
function
|
|
550
|
+
function Jt(t, e, r) {
|
|
551
551
|
const n = r.createElement("img");
|
|
552
552
|
return n.className = B("image", e), n.src = t.imageData, new z().add("width", "100%").add("height", "100%").add("object-fit", "contain").add("display", "block").applyTo(n), n.alt = t.kind, n;
|
|
553
553
|
}
|
|
554
554
|
function ft(t, e, r, n) {
|
|
555
555
|
const o = n.createElement("div");
|
|
556
556
|
o.className = B("shape", r);
|
|
557
|
-
const
|
|
558
|
-
return t.grid || t.kind === "rect" ? (i.top &&
|
|
557
|
+
const a = t.style || {}, s = O(a), i = tt(a), c = `${G(s.widthPt * e / 72, 2)}px solid ${s.color}`, d = new z();
|
|
558
|
+
return t.grid || t.kind === "rect" ? (i.top && d.add("border-top", c), i.right && d.add("border-right", c), i.bottom && d.add("border-bottom", c), i.left && d.add("border-left", c)) : t.kind === "ellipse" ? (i.inner && d.add("border", c).add("border-radius", "50%"), a.backgroundColor && d.add("background-color", a.backgroundColor)) : t.kind === "line" && d.add("height", "0").add("border-top", c), d.add("box-sizing", "border-box").add("width", "100%").add("height", "100%"), d.applyTo(o), o;
|
|
559
559
|
}
|
|
560
560
|
function St(t, e, r, n) {
|
|
561
561
|
const o = n.createElement("div");
|
|
562
562
|
o.className = `${B("comp", r)} mr-kind-${t.kind}`;
|
|
563
|
-
const
|
|
564
|
-
if (wt(
|
|
565
|
-
return o.appendChild(
|
|
563
|
+
const a = new z().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");
|
|
564
|
+
if (wt(a, t, e), a.applyTo(o), At(t))
|
|
565
|
+
return o.appendChild(Jt(t, r, n)), o;
|
|
566
566
|
if (t.kind === "text")
|
|
567
|
-
return o.appendChild(
|
|
567
|
+
return o.appendChild(qt(t, e, r, n)), o;
|
|
568
568
|
if (t.grid) {
|
|
569
569
|
const i = ft(t, e, r, n);
|
|
570
570
|
return i.appendChild(Yt(t.grid, t, e, r, n)), o.appendChild(i), o;
|
|
571
571
|
}
|
|
572
572
|
if (t.kind === "line" || t.kind === "rect" || t.kind === "ellipse" || t.kind === "chart")
|
|
573
573
|
return o.appendChild(ft(t, e, r, n)), o;
|
|
574
|
-
const
|
|
575
|
-
return
|
|
574
|
+
const s = n.createElement("div");
|
|
575
|
+
return s.className = B("unknown", r), s.textContent = t.fallbackText ?? "", o.appendChild(s), o;
|
|
576
576
|
}
|
|
577
577
|
function Ut(t, e, r, n) {
|
|
578
578
|
const o = n.createElement("div");
|
|
579
579
|
o.className = B("page", r), new z().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(o);
|
|
580
|
-
for (const
|
|
581
|
-
o.appendChild(St(
|
|
580
|
+
for (const a of t.components)
|
|
581
|
+
o.appendChild(St(a, e, r, n));
|
|
582
582
|
return o;
|
|
583
583
|
}
|
|
584
|
-
function
|
|
584
|
+
function he(t, e, r = {}) {
|
|
585
585
|
const n = r.dpi ?? 96, o = e.createElement("div");
|
|
586
|
-
return o.className = B("root", r), o.dataset.schemaVersion = t.schemaVersion, t.pages.forEach((
|
|
587
|
-
o.appendChild(Ut(
|
|
586
|
+
return o.className = B("root", r), o.dataset.schemaVersion = t.schemaVersion, t.pages.forEach((a) => {
|
|
587
|
+
o.appendChild(Ut(a, n, r, e));
|
|
588
588
|
}), o;
|
|
589
589
|
}
|
|
590
590
|
function Kt(t) {
|
|
591
|
-
const { pageHeightsPx: e, viewportHeightPx: r, scrollTopPx: n, overscan: o = 1, gapPx:
|
|
592
|
-
if (
|
|
591
|
+
const { pageHeightsPx: e, viewportHeightPx: r, scrollTopPx: n, overscan: o = 1, gapPx: a = 0 } = t, s = e.length;
|
|
592
|
+
if (s === 0)
|
|
593
593
|
return { start: 0, end: -1, padTopPx: 0, padBottomPx: 0 };
|
|
594
|
-
const i = Math.max(0,
|
|
595
|
-
|
|
596
|
-
for (let S = 0; S <
|
|
597
|
-
|
|
598
|
-
const
|
|
599
|
-
let m = 0, l = 0, f =
|
|
594
|
+
const i = Math.max(0, a), c = new Array(s + 1);
|
|
595
|
+
c[0] = 0;
|
|
596
|
+
for (let S = 0; S < s; S++)
|
|
597
|
+
c[S + 1] = c[S] + Math.max(0, e[S] ?? 0) + i;
|
|
598
|
+
const d = c[s], h = Math.max(0, n);
|
|
599
|
+
let m = 0, l = 0, f = s - 1;
|
|
600
600
|
for (; l <= f; ) {
|
|
601
601
|
const S = l + f >> 1;
|
|
602
|
-
|
|
602
|
+
c[S] <= h ? (m = S, l = S + 1) : f = S - 1;
|
|
603
603
|
}
|
|
604
|
-
const g = Math.max(0, Math.min(
|
|
605
|
-
let
|
|
606
|
-
for (l = 0, f =
|
|
604
|
+
const g = Math.max(0, Math.min(s - 1, m - o)), w = c[m] + Math.max(0, r);
|
|
605
|
+
let A = s - 1;
|
|
606
|
+
for (l = 0, f = s - 1; l <= f; ) {
|
|
607
607
|
const S = l + f >> 1;
|
|
608
|
-
|
|
608
|
+
c[S + 1] < w ? l = S + 1 : (A = S, f = S - 1);
|
|
609
609
|
}
|
|
610
|
-
const x = Math.min(
|
|
610
|
+
const x = Math.min(s - 1, A + o), b = c[g], P = Math.max(0, d - c[x + 1]);
|
|
611
611
|
return { start: g, end: x, padTopPx: b, padBottomPx: P };
|
|
612
612
|
}
|
|
613
613
|
const it = 96 / 25.4;
|
|
@@ -619,29 +619,29 @@ function Tt(t, e = 96) {
|
|
|
619
619
|
};
|
|
620
620
|
}
|
|
621
621
|
function Xt(t, e, r) {
|
|
622
|
-
const n = document.createElement("canvas"), { widthPx: o, heightPx:
|
|
623
|
-
n.width = Math.round(o * e), n.height = Math.round(
|
|
624
|
-
const
|
|
625
|
-
if (!
|
|
622
|
+
const n = document.createElement("canvas"), { widthPx: o, heightPx: a } = Tt(t, r);
|
|
623
|
+
n.width = Math.round(o * e), n.height = Math.round(a * e), n.style.width = `${o}px`, n.style.height = `${a}px`;
|
|
624
|
+
const s = n.getContext("2d");
|
|
625
|
+
if (!s)
|
|
626
626
|
throw new Error("当前环境不支持 Canvas 2D(测试需真浏览器,见 e2e/canvas.spec.ts)");
|
|
627
|
-
return
|
|
627
|
+
return s.scale(e, e), s.fillStyle = "#ffffff", s.fillRect(0, 0, o, a), { canvas: n, ctx: s };
|
|
628
628
|
}
|
|
629
|
-
function
|
|
629
|
+
function me(t, e = 96) {
|
|
630
630
|
return V(t, e).fontSizePx;
|
|
631
631
|
}
|
|
632
|
-
function xt(t, e, r, n, o,
|
|
633
|
-
t.font = `${e.bold ? "bold " : ""}${e.fontSizePx}px ${
|
|
634
|
-
const
|
|
635
|
-
`), h =
|
|
632
|
+
function xt(t, e, r, n, o, a, s, i = "top") {
|
|
633
|
+
t.font = `${e.bold ? "bold " : ""}${e.fontSizePx}px ${s}`, t.fillStyle = e.color, t.textBaseline = "alphabetic";
|
|
634
|
+
const c = e.fontSizePx * e.lineHeight, d = e.text === "" ? [""] : e.text.split(`
|
|
635
|
+
`), h = d.length * c;
|
|
636
636
|
let m = n;
|
|
637
|
-
i === "middle" ? m = n + (
|
|
637
|
+
i === "middle" ? m = n + (a - h) / 2 : i === "bottom" && (m = n + a - h), d.forEach((l, f) => {
|
|
638
638
|
t.textAlign = e.align === "center" ? "center" : e.align === "right" ? "right" : "left";
|
|
639
639
|
const g = e.align === "center" ? r + o / 2 : e.align === "right" ? r + o : r;
|
|
640
|
-
t.fillText(l, g, m + f *
|
|
640
|
+
t.fillText(l, g, m + f * c + e.fontSizePx * 0.8, o);
|
|
641
641
|
}), t.textAlign = "left";
|
|
642
642
|
}
|
|
643
|
-
function Zt(t, e, r, n, o,
|
|
644
|
-
const m = Rt(e,
|
|
643
|
+
function Zt(t, e, r, n, o, a, s, i, c, d, h) {
|
|
644
|
+
const m = Rt(e, a / i, s / i), l = tt(r.style), f = O(r.style);
|
|
645
645
|
for (const g of m.cells) {
|
|
646
646
|
const w = g.cell.style?.backgroundColor;
|
|
647
647
|
w && (t.fillStyle = w, t.fillRect(
|
|
@@ -652,15 +652,15 @@ function Zt(t, e, r, n, o, s, a, i, d, c, h) {
|
|
|
652
652
|
));
|
|
653
653
|
}
|
|
654
654
|
if (l.inner) {
|
|
655
|
-
t.strokeStyle = f.color, t.lineWidth = K(f.widthPt,
|
|
655
|
+
t.strokeStyle = f.color, t.lineWidth = K(f.widthPt, c);
|
|
656
656
|
for (const g of m.edges)
|
|
657
657
|
t.beginPath(), g.kind === "v" ? (t.moveTo(n + g.pos * i, o + g.from * i), t.lineTo(n + g.pos * i, o + g.to * i)) : (t.moveTo(n + g.from * i, o + g.pos * i), t.lineTo(n + g.to * i, o + g.pos * i)), t.stroke();
|
|
658
|
-
t.beginPath(), l.top && (t.moveTo(n, o), t.lineTo(n +
|
|
658
|
+
t.beginPath(), l.top && (t.moveTo(n, o), t.lineTo(n + a, o)), l.right && (t.moveTo(n + a, o), t.lineTo(n + a, o + s)), l.bottom && (t.moveTo(n + a, o + s), t.lineTo(n, o + s)), l.left && (t.moveTo(n, o + s), t.lineTo(n, o)), t.stroke();
|
|
659
659
|
}
|
|
660
660
|
for (const g of m.cells) {
|
|
661
661
|
const w = typeof g.cell.text == "string" ? g.cell.text : "";
|
|
662
662
|
if (!w) continue;
|
|
663
|
-
const
|
|
663
|
+
const A = g.cell.style, x = A?.fontSize ?? X, b = Z(
|
|
664
664
|
w,
|
|
665
665
|
g.widthMm - 1,
|
|
666
666
|
{ fontSizePt: x },
|
|
@@ -671,32 +671,32 @@ function Zt(t, e, r, n, o, s, a, i, d, c, h) {
|
|
|
671
671
|
t,
|
|
672
672
|
{
|
|
673
673
|
text: b,
|
|
674
|
-
fontSizePx: V(
|
|
675
|
-
bold:
|
|
676
|
-
color:
|
|
677
|
-
align:
|
|
674
|
+
fontSizePx: V(A, c).fontSizePx,
|
|
675
|
+
bold: A?.bold ?? !1,
|
|
676
|
+
color: A?.color ?? pt(r.style, Nt),
|
|
677
|
+
align: A?.align ?? "left",
|
|
678
678
|
lineHeight: Q
|
|
679
679
|
},
|
|
680
680
|
n + (g.xMm + 0.5) * i,
|
|
681
681
|
o + g.yMm * i,
|
|
682
682
|
Math.max(0, (g.widthMm - 1) * i),
|
|
683
683
|
g.heightMm * i,
|
|
684
|
-
|
|
685
|
-
|
|
684
|
+
d,
|
|
685
|
+
A?.verticalAlign ?? "middle"
|
|
686
686
|
);
|
|
687
687
|
}
|
|
688
688
|
}
|
|
689
|
-
function kt(t, e, r, n, o,
|
|
690
|
-
const
|
|
689
|
+
function kt(t, e, r, n, o, a) {
|
|
690
|
+
const s = e.leftMm * r, i = e.topMm * r, c = e.widthMm * r, d = e.heightMm * r, h = e.style ?? {};
|
|
691
691
|
if (e.grid) {
|
|
692
|
-
Zt(t, e.grid, e,
|
|
692
|
+
Zt(t, e.grid, e, s, i, c, d, r, n, o, a);
|
|
693
693
|
return;
|
|
694
694
|
}
|
|
695
695
|
switch (e.kind) {
|
|
696
696
|
case "text": {
|
|
697
697
|
const m = h.fontSize ?? X, l = ut(e) ? e.richParagraphs.map((f) => (f.segments ?? []).map((g) => g.text ?? g.field ?? "").join("")).join(`
|
|
698
698
|
`) : Array.isArray(e.lines) && e.lines.length > 0 ? e.lines.join(`
|
|
699
|
-
`) : Z(e.text ?? "", e.widthMm, { fontSizePt: m },
|
|
699
|
+
`) : Z(e.text ?? "", e.widthMm, { fontSizePt: m }, a).join(`
|
|
700
700
|
`);
|
|
701
701
|
xt(
|
|
702
702
|
t,
|
|
@@ -708,10 +708,10 @@ function kt(t, e, r, n, o, s) {
|
|
|
708
708
|
align: h.align ?? "left",
|
|
709
709
|
lineHeight: Ht(h)
|
|
710
710
|
},
|
|
711
|
-
|
|
711
|
+
s,
|
|
712
712
|
i,
|
|
713
|
-
d,
|
|
714
713
|
c,
|
|
714
|
+
d,
|
|
715
715
|
o,
|
|
716
716
|
h.verticalAlign
|
|
717
717
|
);
|
|
@@ -719,47 +719,59 @@ function kt(t, e, r, n, o, s) {
|
|
|
719
719
|
}
|
|
720
720
|
case "rect": {
|
|
721
721
|
const m = O(h), l = tt(h);
|
|
722
|
-
h.backgroundColor && (t.fillStyle = h.backgroundColor, t.fillRect(
|
|
722
|
+
h.backgroundColor && (t.fillStyle = h.backgroundColor, t.fillRect(s, i, c, d)), l.inner && (t.strokeStyle = m.color, t.lineWidth = K(m.widthPt, n), t.beginPath(), l.top && (t.moveTo(s, i), t.lineTo(s + c, i)), l.right && (t.moveTo(s + c, i), t.lineTo(s + c, i + d)), l.bottom && (t.moveTo(s + c, i + d), t.lineTo(s, i + d)), l.left && (t.moveTo(s, i + d), t.lineTo(s, i)), t.stroke());
|
|
723
723
|
break;
|
|
724
724
|
}
|
|
725
725
|
case "line": {
|
|
726
726
|
const m = O({ ...h, borderColor: h.lineColor ?? h.borderColor });
|
|
727
|
-
t.strokeStyle = m.color, t.lineWidth = K(m.widthPt, n), t.beginPath(), t.moveTo(
|
|
727
|
+
t.strokeStyle = m.color, t.lineWidth = K(m.widthPt, n), t.beginPath(), t.moveTo(s, i + d / 2), t.lineTo(s + c, i + d / 2), t.stroke();
|
|
728
728
|
break;
|
|
729
729
|
}
|
|
730
730
|
case "ellipse": {
|
|
731
731
|
const m = O(h);
|
|
732
|
-
t.strokeStyle = m.color, t.lineWidth = K(m.widthPt, n), h.backgroundColor && (t.fillStyle = h.backgroundColor, t.beginPath(), t.ellipse(
|
|
732
|
+
t.strokeStyle = m.color, t.lineWidth = K(m.widthPt, n), h.backgroundColor && (t.fillStyle = h.backgroundColor, t.beginPath(), t.ellipse(s + c / 2, i + d / 2, c / 2, d / 2, 0, 0, Math.PI * 2), t.fill()), t.beginPath(), t.ellipse(s + c / 2, i + d / 2, c / 2, d / 2, 0, 0, Math.PI * 2), t.stroke();
|
|
733
733
|
break;
|
|
734
734
|
}
|
|
735
735
|
}
|
|
736
736
|
}
|
|
737
|
-
function
|
|
737
|
+
async function ge(t, e = {}) {
|
|
738
|
+
if (typeof document > "u")
|
|
739
|
+
throw new Error("renderPlanToImages 需要浏览器环境(SSR/Node 请在客户端钩子中调用)");
|
|
740
|
+
const { format: r = "png", quality: n = 0.92, ...o } = e, { canvases: a } = Qt(t, o), s = r === "jpeg" ? "image/jpeg" : "image/png", i = [];
|
|
741
|
+
for (const c of a)
|
|
742
|
+
i.push(
|
|
743
|
+
await new Promise(
|
|
744
|
+
(d) => c.toBlob((h) => d(h), s, n)
|
|
745
|
+
) ?? new Blob([], { type: s })
|
|
746
|
+
);
|
|
747
|
+
return { blobs: i };
|
|
748
|
+
}
|
|
749
|
+
function Qt(t, e = {}) {
|
|
738
750
|
if (typeof document > "u")
|
|
739
751
|
throw new Error("renderPlanToCanvas 需要浏览器环境(SSR 请在客户端钩子中调用)");
|
|
740
|
-
const r = e.dpr ?? (typeof devicePixelRatio == "number" ? devicePixelRatio : 1), n = e.dpi ?? 96, o = n / 96 * it,
|
|
741
|
-
for (let h = i; h <=
|
|
752
|
+
const r = e.dpr ?? (typeof devicePixelRatio == "number" ? devicePixelRatio : 1), n = e.dpi ?? 96, o = n / 96 * it, a = e.fontFamily ?? '"Microsoft YaHei", sans-serif', s = e.measurer ?? ot, i = Math.max(0, e.start ?? 0), c = Math.min(t.pages.length - 1, e.end ?? t.pages.length - 1), d = [];
|
|
753
|
+
for (let h = i; h <= c; h++) {
|
|
742
754
|
const m = t.pages[h], { canvas: l, ctx: f } = Xt(m, r, n);
|
|
743
755
|
for (const g of m.components)
|
|
744
|
-
kt(f, g, o, n,
|
|
745
|
-
|
|
756
|
+
kt(f, g, o, n, a, s);
|
|
757
|
+
d.push(l);
|
|
746
758
|
}
|
|
747
|
-
return { canvases:
|
|
759
|
+
return { canvases: d };
|
|
748
760
|
}
|
|
749
|
-
function
|
|
750
|
-
const r = e.dpr ?? (typeof devicePixelRatio == "number" ? devicePixelRatio : 1), n = e.dpi ?? 96, o = n / 96 * it,
|
|
751
|
-
let f = null, g = null, w = null,
|
|
761
|
+
function fe(t, e = {}) {
|
|
762
|
+
const r = e.dpr ?? (typeof devicePixelRatio == "number" ? devicePixelRatio : 1), n = e.dpi ?? 96, o = n / 96 * it, a = e.fontFamily ?? '"Microsoft YaHei", sans-serif', s = e.measurer ?? ot, i = e.overscan ?? 1, c = e.gapPx ?? 18, d = e.pagesPerFrame ?? 1, h = t.pages.map((u) => u.pageHeightMm * o), m = Math.max(1, ...t.pages.map((u) => u.pageWidthMm * o)), l = { start: 0, end: -1 };
|
|
763
|
+
let f = null, g = null, w = null, A = null, x = [], b = 0, P = [];
|
|
752
764
|
function S() {
|
|
753
765
|
const u = f;
|
|
754
|
-
u.innerHTML = "", g = document.createElement("div"), g.style.cssText = `width:${m}px;margin:0 auto;`, w = document.createElement("div"),
|
|
766
|
+
u.innerHTML = "", g = document.createElement("div"), g.style.cssText = `width:${m}px;margin:0 auto;`, w = document.createElement("div"), A = document.createElement("div"), g.appendChild(w), x = [];
|
|
755
767
|
const H = Math.min(t.pages.length, 3 + i * 2);
|
|
756
768
|
for (let L = 0; L < H; L++) {
|
|
757
769
|
const y = document.createElement("div");
|
|
758
|
-
y.style.cssText = `margin:0 auto ${
|
|
770
|
+
y.style.cssText = `margin:0 auto ${c}px;box-shadow:0 2px 8px rgba(0,0,0,.35);background:#fff;`, g.appendChild(y), x.push(y);
|
|
759
771
|
}
|
|
760
|
-
g.appendChild(
|
|
772
|
+
g.appendChild(A), u.appendChild(g);
|
|
761
773
|
}
|
|
762
|
-
function
|
|
774
|
+
function q(u, H) {
|
|
763
775
|
const L = t.pages[H], { widthPx: y, heightPx: N } = Tt(L, n);
|
|
764
776
|
let C = u.firstElementChild;
|
|
765
777
|
(!C || C.tagName !== "CANVAS") && (C = document.createElement("canvas"), u.innerHTML = "", u.appendChild(C)), C.width = Math.round(y * r), C.height = Math.round(N * r), C.style.width = `${y}px`, C.style.height = `${N}px`;
|
|
@@ -767,14 +779,14 @@ function ge(t, e = {}) {
|
|
|
767
779
|
if (_) {
|
|
768
780
|
_.setTransform(1, 0, 0, 1, 0, 0), _.scale(r, r), _.fillStyle = "#ffffff", _.fillRect(0, 0, y, N);
|
|
769
781
|
for (const U of L.components)
|
|
770
|
-
kt(_, U, o, n,
|
|
782
|
+
kt(_, U, o, n, a, s);
|
|
771
783
|
C.dataset.canvasPage = String(H), u.style.height = `${N}px`, u.style.width = `${y}px`;
|
|
772
784
|
}
|
|
773
785
|
}
|
|
774
|
-
function
|
|
775
|
-
l.start = u.start, l.end = u.end, w.style.height = `${u.start *
|
|
786
|
+
function J(u) {
|
|
787
|
+
l.start = u.start, l.end = u.end, w.style.height = `${u.start * c + h.slice(0, u.start).reduce((y, N) => y + N, 0)}px`;
|
|
776
788
|
const H = t.pages.length - 1 - u.end;
|
|
777
|
-
|
|
789
|
+
A.style.height = `${H * c + h.slice(u.end + 1).reduce((y, N) => y + N, 0)}px`;
|
|
778
790
|
const L = u.end - u.start + 1;
|
|
779
791
|
x.forEach((y, N) => {
|
|
780
792
|
if (N < L) {
|
|
@@ -794,10 +806,10 @@ function ge(t, e = {}) {
|
|
|
794
806
|
function k() {
|
|
795
807
|
b || P.length === 0 || (b = requestAnimationFrame(() => {
|
|
796
808
|
b = 0;
|
|
797
|
-
let u = Math.max(1,
|
|
809
|
+
let u = Math.max(1, d);
|
|
798
810
|
for (; P.length > 0 && u-- > 0; ) {
|
|
799
811
|
const H = P.shift(), L = x[H - l.start];
|
|
800
|
-
L &&
|
|
812
|
+
L && q(L, H);
|
|
801
813
|
}
|
|
802
814
|
P.length > 0 && k();
|
|
803
815
|
}));
|
|
@@ -810,9 +822,9 @@ function ge(t, e = {}) {
|
|
|
810
822
|
viewportHeightPx: u.clientHeight,
|
|
811
823
|
scrollTopPx: u.scrollTop,
|
|
812
824
|
overscan: i,
|
|
813
|
-
gapPx:
|
|
825
|
+
gapPx: c
|
|
814
826
|
});
|
|
815
|
-
H.start !== l.start || H.end !== l.end ?
|
|
827
|
+
H.start !== l.start || H.end !== l.end ? J(H) : k();
|
|
816
828
|
}));
|
|
817
829
|
}
|
|
818
830
|
let j = null;
|
|
@@ -830,7 +842,7 @@ function ge(t, e = {}) {
|
|
|
830
842
|
}
|
|
831
843
|
};
|
|
832
844
|
}
|
|
833
|
-
function
|
|
845
|
+
function E(t, e) {
|
|
834
846
|
return typeof t == "number" && Number.isFinite(t) ? t : e;
|
|
835
847
|
}
|
|
836
848
|
function R(t, e = "") {
|
|
@@ -839,13 +851,13 @@ function R(t, e = "") {
|
|
|
839
851
|
function W(t) {
|
|
840
852
|
return typeof t == "object" && t !== null && !Array.isArray(t);
|
|
841
853
|
}
|
|
842
|
-
function
|
|
854
|
+
function te(t) {
|
|
843
855
|
return t === "Center" ? "center" : t === "Right" ? "right" : "left";
|
|
844
856
|
}
|
|
845
|
-
function
|
|
857
|
+
function ee(t) {
|
|
846
858
|
return t === "Center" ? "middle" : t === "Bottom" ? "bottom" : "top";
|
|
847
859
|
}
|
|
848
|
-
function
|
|
860
|
+
function ne(t) {
|
|
849
861
|
const e = parseFloat(R(t.FontSize, "10.5"));
|
|
850
862
|
return {
|
|
851
863
|
fontSize: Number.isFinite(e) ? e : 10.5,
|
|
@@ -855,8 +867,8 @@ function ee(t) {
|
|
|
855
867
|
underline: t.Underline === !0 || void 0,
|
|
856
868
|
color: R(t.FontColor) || void 0,
|
|
857
869
|
backgroundColor: R(t.BackgroundColor) || void 0,
|
|
858
|
-
align:
|
|
859
|
-
verticalAlign:
|
|
870
|
+
align: te(R(t.HorAlignment, "Left")),
|
|
871
|
+
verticalAlign: ee(R(t.VertAlignment, "Top")),
|
|
860
872
|
lineHeight: (() => {
|
|
861
873
|
const r = parseFloat(R(t.RowSpace, "1"));
|
|
862
874
|
return Number.isFinite(r) && r !== 1 ? r : void 0;
|
|
@@ -868,23 +880,23 @@ function ee(t) {
|
|
|
868
880
|
borderLeft: t.BorderLeft !== !1
|
|
869
881
|
};
|
|
870
882
|
}
|
|
871
|
-
function
|
|
883
|
+
function re(t, e) {
|
|
872
884
|
const r = R(t.uitype), n = {
|
|
873
885
|
kind: "text",
|
|
874
|
-
leftMm:
|
|
875
|
-
topMm:
|
|
876
|
-
widthMm:
|
|
877
|
-
heightMm:
|
|
886
|
+
leftMm: E(t.left, 0),
|
|
887
|
+
topMm: E(t.top, 0),
|
|
888
|
+
widthMm: E(t.width, 40),
|
|
889
|
+
heightMm: E(t.height, 8),
|
|
878
890
|
nid: R(t.nid) || void 0,
|
|
879
|
-
style:
|
|
891
|
+
style: ne(t)
|
|
880
892
|
};
|
|
881
893
|
switch (r) {
|
|
882
894
|
case "text": {
|
|
883
895
|
n.kind = "text";
|
|
884
896
|
const o = t.Text ?? t.text ?? t.Value;
|
|
885
897
|
n.text = o == null ? "" : String(o);
|
|
886
|
-
const
|
|
887
|
-
return Array.isArray(
|
|
898
|
+
const a = t.Lines ?? t.lines;
|
|
899
|
+
return Array.isArray(a) && (n.lines = a.map((s) => String(s))), n;
|
|
888
900
|
}
|
|
889
901
|
case "richtext":
|
|
890
902
|
return n.kind = "text", n.text = R(t.Text), e.push(`富文本 ${n.nid ?? ""} 导入为纯文本(版式细节可能损失)`), n;
|
|
@@ -897,15 +909,15 @@ function ne(t, e) {
|
|
|
897
909
|
n.kind = "rect";
|
|
898
910
|
const o = t.Cells ?? t.cells;
|
|
899
911
|
if (Array.isArray(o)) {
|
|
900
|
-
const
|
|
912
|
+
const a = {
|
|
901
913
|
cells: o.map(
|
|
902
|
-
(
|
|
914
|
+
(s) => Array.isArray(s) ? s.map((i) => ({
|
|
903
915
|
text: W(i) ? R(i.Text ?? i.text) : "",
|
|
904
|
-
colSpan: W(i) ?
|
|
916
|
+
colSpan: W(i) ? E(i.ColSpan, 1) : 1
|
|
905
917
|
})) : []
|
|
906
918
|
)
|
|
907
919
|
};
|
|
908
|
-
n.grid =
|
|
920
|
+
n.grid = a;
|
|
909
921
|
} else
|
|
910
922
|
n.fallbackText = "[table]", e.push(`表格 ${n.nid ?? ""} 缺少 Cells,导入为空框`);
|
|
911
923
|
return n;
|
|
@@ -916,13 +928,13 @@ function ne(t, e) {
|
|
|
916
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);
|
|
917
929
|
}
|
|
918
930
|
}
|
|
919
|
-
function
|
|
931
|
+
function ue(t) {
|
|
920
932
|
const e = [];
|
|
921
933
|
let r = null;
|
|
922
934
|
if (typeof t == "string")
|
|
923
935
|
try {
|
|
924
|
-
const
|
|
925
|
-
W(
|
|
936
|
+
const d = JSON.parse(t);
|
|
937
|
+
W(d) && (r = d);
|
|
926
938
|
} catch {
|
|
927
939
|
return {
|
|
928
940
|
template: { pages: [] },
|
|
@@ -932,47 +944,47 @@ function fe(t) {
|
|
|
932
944
|
else W(t) && (r = t);
|
|
933
945
|
if (!r)
|
|
934
946
|
return { template: { pages: [] }, warnings: ["content 为空"] };
|
|
935
|
-
const n = W(r.GlobalConfig) ? r.GlobalConfig : {}, o =
|
|
936
|
-
top:
|
|
937
|
-
bottom:
|
|
938
|
-
left:
|
|
939
|
-
right:
|
|
940
|
-
}, i = Array.isArray(r.children) ? r.children.filter((
|
|
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") : [];
|
|
941
953
|
i.length === 0 && e.push("content 中没有 uitype=page 的页节点");
|
|
942
|
-
const
|
|
943
|
-
const h =
|
|
954
|
+
const c = i.map((d) => {
|
|
955
|
+
const h = d, m = Array.isArray(h.children) ? h.children : [], l = [];
|
|
944
956
|
for (const f of m) {
|
|
945
957
|
if (!W(f)) continue;
|
|
946
|
-
const g =
|
|
958
|
+
const g = re(f, e);
|
|
947
959
|
g && l.push(g);
|
|
948
960
|
}
|
|
949
961
|
return {
|
|
950
|
-
widthMm:
|
|
951
|
-
heightMm:
|
|
952
|
-
marginTopMm:
|
|
953
|
-
marginBottomMm:
|
|
954
|
-
marginLeftMm:
|
|
955
|
-
marginRightMm:
|
|
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),
|
|
956
968
|
components: l
|
|
957
969
|
};
|
|
958
970
|
});
|
|
959
|
-
return
|
|
971
|
+
return c.length === 0 && (e.push("转换结果为空页,已回退一张空白页"), c.push({
|
|
960
972
|
widthMm: o,
|
|
961
|
-
heightMm:
|
|
962
|
-
...
|
|
973
|
+
heightMm: a,
|
|
974
|
+
...s,
|
|
963
975
|
components: []
|
|
964
|
-
})), { template: { pages:
|
|
976
|
+
})), { template: { pages: c }, warnings: e };
|
|
965
977
|
}
|
|
966
|
-
function
|
|
978
|
+
function oe(t, e, r) {
|
|
967
979
|
let n, o;
|
|
968
980
|
if (typeof t == "string") {
|
|
969
|
-
const
|
|
970
|
-
if (!
|
|
971
|
-
n =
|
|
981
|
+
const a = ht[t];
|
|
982
|
+
if (!a) throw new Error(`未知纸张预设 "${t}"(可用:${Object.keys(ht).join("/")})`);
|
|
983
|
+
n = a.widthMm, o = a.heightMm;
|
|
972
984
|
} else typeof t == "number" ? (n = t, o = e ?? 297) : (n = t.widthMm, o = t.heightMm);
|
|
973
985
|
return r ? { widthMm: o, heightMm: n } : { widthMm: n, heightMm: o };
|
|
974
986
|
}
|
|
975
|
-
class
|
|
987
|
+
class ie {
|
|
976
988
|
constructor() {
|
|
977
989
|
this.pages = [], this.pending = null, this.templateParams = void 0;
|
|
978
990
|
}
|
|
@@ -1001,18 +1013,18 @@ class oe {
|
|
|
1001
1013
|
*/
|
|
1002
1014
|
page(e = "a4", r = {}, n) {
|
|
1003
1015
|
this.collect();
|
|
1004
|
-
const
|
|
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: s, heightMm: i } = oe(
|
|
1005
1017
|
e,
|
|
1006
1018
|
typeof r == "number" ? r : void 0,
|
|
1007
|
-
|
|
1008
|
-
),
|
|
1009
|
-
return this.pending = new
|
|
1010
|
-
widthMm:
|
|
1019
|
+
a.landscape
|
|
1020
|
+
), c = a.margins ?? {};
|
|
1021
|
+
return this.pending = new se(this, {
|
|
1022
|
+
widthMm: s,
|
|
1011
1023
|
heightMm: i,
|
|
1012
|
-
marginTopMm:
|
|
1013
|
-
marginBottomMm:
|
|
1014
|
-
marginLeftMm:
|
|
1015
|
-
marginRightMm:
|
|
1024
|
+
marginTopMm: c.marginTopMm ?? 10,
|
|
1025
|
+
marginBottomMm: c.marginBottomMm ?? 10,
|
|
1026
|
+
marginLeftMm: c.marginLeftMm ?? 10,
|
|
1027
|
+
marginRightMm: c.marginRightMm ?? 10
|
|
1016
1028
|
}), this.pending;
|
|
1017
1029
|
}
|
|
1018
1030
|
collect() {
|
|
@@ -1024,7 +1036,7 @@ class oe {
|
|
|
1024
1036
|
return this.templateParams ? { params: this.templateParams, pages: this.pages } : { pages: this.pages };
|
|
1025
1037
|
}
|
|
1026
1038
|
}
|
|
1027
|
-
class
|
|
1039
|
+
class se {
|
|
1028
1040
|
constructor(e, r) {
|
|
1029
1041
|
this.parent = e, this.page = r, this.components = [];
|
|
1030
1042
|
}
|
|
@@ -1093,61 +1105,62 @@ class ie {
|
|
|
1093
1105
|
return this.done().build();
|
|
1094
1106
|
}
|
|
1095
1107
|
}
|
|
1096
|
-
function
|
|
1097
|
-
return new
|
|
1108
|
+
function pe() {
|
|
1109
|
+
return new ie();
|
|
1098
1110
|
}
|
|
1099
1111
|
export {
|
|
1100
|
-
|
|
1101
|
-
|
|
1112
|
+
ye as CSS_DPI,
|
|
1113
|
+
we as DEFAULT_BORDER_PT,
|
|
1102
1114
|
X as DEFAULT_FONT_PT,
|
|
1103
|
-
|
|
1115
|
+
Se as DEFAULT_STROKE_COLOR,
|
|
1104
1116
|
Nt as DEFAULT_TEXT_COLOR,
|
|
1105
1117
|
Q as LINE_HEIGHT,
|
|
1106
|
-
|
|
1118
|
+
Te as MM_PER_INCH,
|
|
1107
1119
|
ht as PAPER_SIZES,
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1120
|
+
se as PageBuilder,
|
|
1121
|
+
Et as RENDER_PLAN_SCHEMA_VERSION,
|
|
1122
|
+
xe as SCHEMA_VERSION_JH4J,
|
|
1123
|
+
ke as SCHEMA_VERSION_LOCAL,
|
|
1124
|
+
ve as SCHEMA_VERSION_MACH,
|
|
1125
|
+
ie as TemplateBuilder,
|
|
1126
|
+
ce as assertRenderPlan,
|
|
1127
|
+
Pe as charWidthEm,
|
|
1116
1128
|
B as classOf,
|
|
1117
1129
|
Kt as computePageWindow,
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1130
|
+
Ce as createCanvasMeasurer,
|
|
1131
|
+
fe as createCanvasPager,
|
|
1132
|
+
Ee as createHeuristicMeasurer,
|
|
1133
|
+
pe as createTemplate,
|
|
1122
1134
|
zt as evalStyleRule,
|
|
1123
1135
|
Mt as formatValue,
|
|
1124
1136
|
ot as heuristicMeasurer,
|
|
1125
|
-
|
|
1126
|
-
|
|
1137
|
+
ue as importJh4jTemplateContent,
|
|
1138
|
+
At as isImageBackedComponent,
|
|
1127
1139
|
ut as isRichText,
|
|
1128
1140
|
Tt as measurePageSizePx,
|
|
1129
1141
|
Ae as measureTextMm,
|
|
1130
1142
|
$t as mmToPx,
|
|
1131
|
-
|
|
1143
|
+
$e as mmToPxFactor,
|
|
1132
1144
|
de as paginateTemplate,
|
|
1133
1145
|
Bt as parseDateLocal,
|
|
1134
|
-
|
|
1146
|
+
me as planFontSizePx,
|
|
1135
1147
|
K as ptToPx,
|
|
1136
|
-
|
|
1148
|
+
He as pxToMm,
|
|
1137
1149
|
St as renderComponent,
|
|
1138
1150
|
Ut as renderPage,
|
|
1139
|
-
|
|
1140
|
-
|
|
1151
|
+
he as renderPlan,
|
|
1152
|
+
Qt as renderPlanToCanvas,
|
|
1153
|
+
ge as renderPlanToImages,
|
|
1141
1154
|
tt as resolveBoxBorders,
|
|
1142
1155
|
V as resolveFontSize,
|
|
1143
1156
|
Rt as resolveGridLayout,
|
|
1144
1157
|
Ht as resolveLineHeight,
|
|
1145
|
-
|
|
1158
|
+
oe as resolvePaper,
|
|
1146
1159
|
O as resolveStroke,
|
|
1147
1160
|
pt as resolveTextColor,
|
|
1148
1161
|
G as round,
|
|
1149
1162
|
rt as toNumber,
|
|
1150
|
-
|
|
1163
|
+
Ne as toRenderPlan,
|
|
1151
1164
|
bt as validateComponent,
|
|
1152
1165
|
Wt as validatePage,
|
|
1153
1166
|
It as validateRenderPlan,
|