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