@agile-team/mach-report 0.6.0 → 0.8.0

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