@agile-team/mach-report 2.13.0 → 2.14.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 (97) hide show
  1. package/README.md +10 -2
  2. package/dist/ExcelBindingWizard-CLT2p7P3.cjs +1 -0
  3. package/dist/ExcelBindingWizard-CvsWR8Ga.js +1485 -0
  4. package/dist/{ParamEditor-BLaE5q5W.js → ParamEditor-CflQV3eQ.js} +191 -187
  5. package/dist/ParamEditor-vIDzvpPV.cjs +1 -0
  6. package/dist/ReportBatchPanel-DkxTzBkD.cjs +1 -0
  7. package/dist/{ReportBatchPanel-CW2HV9I8.js → ReportBatchPanel-LqVgiqp7.js} +3 -3
  8. package/dist/ReportPreview-CvbqLUzM.cjs +6 -0
  9. package/dist/ReportPreview-D_ywJ_-H.js +4533 -0
  10. package/dist/{ReportTemplateLibrary-BZB-XWjj.js → ReportTemplateLibrary-MjWEtc7X.js} +1 -1
  11. package/dist/ReportTemplateLibrary-cQ1sqNYo.cjs +1 -0
  12. package/dist/RuleEditor-BaR6xUiI.cjs +1 -0
  13. package/dist/RuleEditor-ChuXMlei.js +2037 -0
  14. package/dist/TemplateOutlinePanel-BHKP89Xz.cjs +1 -0
  15. package/dist/TemplateOutlinePanel-Dci6aRn1.js +96 -0
  16. package/dist/TemplateReusePanel-B7Gmyc1z.js +388 -0
  17. package/dist/TemplateReusePanel-CY5eO2Sh.cjs +1 -0
  18. package/dist/TemplateReviewPanel-DjlX3xpt.js +592 -0
  19. package/dist/TemplateReviewPanel-JvZe9_4G.cjs +1 -0
  20. package/dist/{batch-mRqhhhjt.js → batch-DzaTNLWI.js} +23 -16
  21. package/dist/batch-xMkqYiTr.cjs +1 -0
  22. package/dist/config-0UIohTS7.cjs +1 -0
  23. package/dist/{config-XVwG87IA.js → config-Dt9NtCPl.js} +223 -186
  24. package/dist/data-explanation-BktvER5B.cjs +1 -0
  25. package/dist/data-explanation-C_J6jYNi.js +16 -0
  26. package/dist/designer-Ci1LizA9.js +5020 -0
  27. package/dist/designer-rtmVIIdN.cjs +2 -0
  28. package/dist/designer.cjs +1 -2
  29. package/dist/designer.d.cts +290 -3
  30. package/dist/designer.d.ts +290 -3
  31. package/dist/designer.js +21 -4312
  32. package/dist/font-loader-DHto6Lra.js +297 -0
  33. package/dist/font-loader-vhCT8znW.cjs +1 -0
  34. package/dist/index.cjs +8 -8
  35. package/dist/index.d.cts +157 -1
  36. package/dist/index.d.ts +157 -1
  37. package/dist/index.js +720 -639
  38. package/dist/{template-review-PgEe_Wr9.js → json-snapshot-BeFT3Tso.js} +795 -585
  39. package/dist/json-snapshot-D1NTP2oI.cjs +2 -0
  40. package/dist/pdf-8UPQebOE.js +36288 -0
  41. package/dist/pdf-AyJGb22z.cjs +101 -0
  42. package/dist/pdf.cjs +1 -101
  43. package/dist/pdf.js +9 -36579
  44. package/dist/plugin-BGKf-Tqg.js +22 -0
  45. package/dist/{plugin-DzS6pxTA.cjs → plugin-CktLH_Iy.cjs} +1 -1
  46. package/dist/{region-binding-workflow-CcUq8W2Q.js → region-binding-workflow-DEJbhpCv.js} +1 -1
  47. package/dist/server/node.d.cts +46 -11
  48. package/dist/server/node.d.ts +46 -11
  49. package/dist/server-node.cjs +1 -1
  50. package/dist/server-node.js +294 -280
  51. package/dist/server.cjs +1 -1
  52. package/dist/server.d.cts +107 -12
  53. package/dist/server.d.ts +107 -12
  54. package/dist/server.js +711 -451
  55. package/dist/style.css +1 -1
  56. package/dist/template-bindings-BJR4k7qZ.cjs +1 -0
  57. package/dist/template-bindings-Daui7hLF.js +252 -0
  58. package/dist/template-fragments-CLkGo6To.js +187 -0
  59. package/dist/template-fragments-DFUpq5QM.cjs +1 -0
  60. package/dist/template-outline-B3xVkzSv.cjs +1 -0
  61. package/dist/template-outline-CFenM1PV.js +88 -0
  62. package/dist/{template-registry-BjE1VS6g.js → template-registry-COXDEJEM.js} +1 -1
  63. package/dist/{useLocalDraft-C07SYRnC.js → useLocalDraft-BnhcxXk_.js} +1 -1
  64. package/dist/{useLocalDraft-Yiw1wFgI.cjs → useLocalDraft-CioIfDb6.cjs} +1 -1
  65. package/dist/{validate-DbgEM1Hh.js → validate-CkQBWCeg.js} +3 -3
  66. package/dist/vue/async.d.cts +68 -2
  67. package/dist/vue/async.d.ts +68 -2
  68. package/dist/vue/index.d.cts +117 -3
  69. package/dist/vue/index.d.ts +117 -3
  70. package/dist/vue-async.cjs +1 -1
  71. package/dist/vue-async.js +5 -5
  72. package/dist/vue.cjs +1 -1
  73. package/dist/vue.js +78 -71
  74. package/dist/{workbook-session-BPb3TMnT.js → workbook-session-BfK1yHOO.js} +1 -1
  75. package/dist/worker.cjs +1 -1
  76. package/dist/worker.d.cts +46 -11
  77. package/dist/worker.d.ts +46 -11
  78. package/dist/worker.js +59 -55
  79. package/dist/xlsx.js +3 -3
  80. package/package.json +1 -1
  81. package/dist/ExcelBindingWizard-CeAf4QSE.js +0 -1465
  82. package/dist/ExcelBindingWizard-y0mT-AHR.cjs +0 -1
  83. package/dist/ParamEditor-MBBC7lUE.cjs +0 -1
  84. package/dist/ReportBatchPanel-Fp1ePFag.cjs +0 -1
  85. package/dist/ReportPreview-BN6fk7Wz.cjs +0 -6
  86. package/dist/ReportPreview-D2Jkyh1U.js +0 -4243
  87. package/dist/ReportTemplateLibrary-5fk5CQBO.cjs +0 -1
  88. package/dist/RuleEditor-ChRzNQuF.cjs +0 -1
  89. package/dist/RuleEditor-DzAmW5YH.js +0 -2024
  90. package/dist/TemplateReviewPanel-BKofGrV9.js +0 -222
  91. package/dist/TemplateReviewPanel-DwtOcLue.cjs +0 -1
  92. package/dist/batch-Bt3Fd27Z.cjs +0 -1
  93. package/dist/config-Bb7RiIO5.cjs +0 -1
  94. package/dist/plugin-D4wizDXB.js +0 -22
  95. package/dist/record-bindings-By_UKZ2g.cjs +0 -1
  96. package/dist/record-bindings-D-5jQlTj.js +0 -196
  97. package/dist/template-review-DGwWOoCv.cjs +0 -2
package/dist/index.js CHANGED
@@ -1,28 +1,32 @@
1
- import { D as Z, a as xe } from "./defaults-DXhiM1ZD.js";
2
- import { b as Hn, c as _n, d as Bn, L as jn, S as Wn } from "./defaults-DXhiM1ZD.js";
3
- import { R as Un, e as Vn, f as qn, p as Yn, b as Jn, t as Kn, d as Xn } from "./record-bindings-D-5jQlTj.js";
4
- import { a as H, r as _, b as Q, c as j, d as Ee, m as ie, e as Te, p as O, f as Se, P as J } from "./style-CQ1PK8ZB.js";
5
- import { C as Qn, M as er, g as tr, h as nr } from "./style-CQ1PK8ZB.js";
6
- import { i as ee, a as Ce } from "./render-plan-Ck6koX9L.js";
7
- import { R as ir } from "./render-plan-Ck6koX9L.js";
8
- import { a as ar, v as sr, b as lr, c as cr } from "./validate-DbgEM1Hh.js";
9
- import { v as Ve } from "./dataset-H5pFuQGU.js";
10
- import { d as mr } from "./dataset-H5pFuQGU.js";
11
- import { h as oe, r as ae, w as Re } from "./assets-Q0wUwNrV.js";
12
- import { O as gr, c as ur, a as fr, b as pr, m as wr } from "./assets-Q0wUwNrV.js";
13
- import { R as se, d as qe, a as Ye, p as Je } from "./template-review-PgEe_Wr9.js";
14
- import { D as br, P as yr, b as Mr, c as xr, e as Er, f as Tr, g as Sr, h as Cr, i as Rr, j as Pr, k as Ar, l as kr, m as Ir, n as Nr, o as $r, q as Lr, r as Dr, s as Fr, t as Or, u as zr, v as Hr, w as _r, x as Br, y as jr, z as Wr } from "./template-review-PgEe_Wr9.js";
15
- import { r as Pe } from "./grid-geometry-BNptEcMm.js";
16
- import { r as Ae } from "./grid-strokes-DyyG1q_o.js";
17
- import { r as G, n as ke, O as Ke } from "./capabilities-CK_7hizc.js";
18
- import { i as Ur } from "./capabilities-CK_7hizc.js";
19
- import { o as Xe } from "./progress-7OSZbFok.js";
20
- import { c as Ze } from "./page-window-index-CIuT4BAv.js";
21
- import { v as Ie, R as Ne, p as I } from "./template-registry-BjE1VS6g.js";
22
- import { a as qr, c as Yr, d as Jr, s as Kr, b as Xr } from "./template-registry-BjE1VS6g.js";
23
- import { R as Qr, a as ei, f as ti, i as ni, b as ri, c as ii, p as oi, r as ai, v as si, d as li } from "./param-validation-BlHHXs6u.js";
24
- import { T as di, c as mi, v as hi } from "./tree-CqcQ99NM.js";
25
- const Qe = {
1
+ import { D as te, a as Ce } from "./defaults-DXhiM1ZD.js";
2
+ import { b as Xn, c as Zn, d as Qn, L as er, S as tr } from "./defaults-DXhiM1ZD.js";
3
+ import { R as rr, e as ir, f as ar, p as or, b as sr, t as lr, d as cr } from "./template-bindings-Daui7hLF.js";
4
+ import { a as j, r as U, b as ne, c as G, d as Re, m as se, e as Pe, p as W, f as Ae, P as Z } from "./style-CQ1PK8ZB.js";
5
+ import { C as dr, M as hr, g as gr, h as fr } from "./style-CQ1PK8ZB.js";
6
+ import { i as re, a as $e } from "./render-plan-Ck6koX9L.js";
7
+ import { R as pr } from "./render-plan-Ck6koX9L.js";
8
+ import { v as Xe } from "./validate-CkQBWCeg.js";
9
+ import { a as br, b as yr, c as vr } from "./validate-CkQBWCeg.js";
10
+ import { v as Ze } from "./dataset-H5pFuQGU.js";
11
+ import { d as xr } from "./dataset-H5pFuQGU.js";
12
+ import { h as le, r as ce, w as ke } from "./assets-Q0wUwNrV.js";
13
+ import { O as Sr, c as Tr, a as Cr, b as Rr, m as Pr } from "./assets-Q0wUwNrV.js";
14
+ import { R as me, d as Qe, a as et, p as tt, s as nt } from "./json-snapshot-BeFT3Tso.js";
15
+ import { D as $r, P as kr, b as Ir, c as Nr, e as Lr, f as Dr, g as Fr, h as Or, i as Hr, j as zr, k as Br, l as Wr, m as _r, n as jr, o as Ur, q as Gr, r as Vr, t as qr, u as Jr, v as Yr, w as Kr, x as Xr, y as Zr, z as Qr, A as ei, B as ti } from "./json-snapshot-BeFT3Tso.js";
16
+ import { r as Ie } from "./grid-geometry-BNptEcMm.js";
17
+ import { r as Ne } from "./grid-strokes-DyyG1q_o.js";
18
+ import { r as q, n as Le, O as rt } from "./capabilities-CK_7hizc.js";
19
+ import { i as ri } from "./capabilities-CK_7hizc.js";
20
+ import { o as it } from "./progress-7OSZbFok.js";
21
+ import { c as at } from "./page-window-index-CIuT4BAv.js";
22
+ import { v as De, R as Fe, p as N } from "./template-registry-COXDEJEM.js";
23
+ import { a as ai, c as oi, d as si, s as li, b as ci } from "./template-registry-COXDEJEM.js";
24
+ import { R as di, a as hi, f as gi, i as fi, b as ui, c as pi, p as wi, r as bi, v as yi, d as vi } from "./param-validation-BlHHXs6u.js";
25
+ import { h as xi, i as Ei, a as Si } from "./data-explanation-C_J6jYNi.js";
26
+ import { c as Ci, i as Ri, t as Pi } from "./template-outline-CFenM1PV.js";
27
+ import { a as $i, c as ki, i as Ii, b as Ni } from "./template-fragments-CLkGo6To.js";
28
+ import { T as Di, c as Fi, v as Oi } from "./tree-CqcQ99NM.js";
29
+ const ot = {
26
30
  root: "mr-root",
27
31
  page: "mr-page",
28
32
  comp: "mr-comp",
@@ -39,10 +43,10 @@ const Qe = {
39
43
  cell: "mr-cell",
40
44
  unknown: "mr-unknown"
41
45
  };
42
- function E(e, t) {
43
- return t?.classNames?.[e] ?? Qe[e];
46
+ function T(e, t) {
47
+ return t?.classNames?.[e] ?? ot[e];
44
48
  }
45
- class et {
49
+ class st {
46
50
  constructor() {
47
51
  this.props = [];
48
52
  }
@@ -50,7 +54,7 @@ class et {
50
54
  return n == null || n === !1 || n === "" ? this : (this.props.push([t, String(n)]), this);
51
55
  }
52
56
  mm(t, n, r, i = 2) {
53
- return this.add(t, `${H(ie(n, r), i)}px`);
57
+ return this.add(t, `${j(se(n, r), i)}px`);
54
58
  }
55
59
  toString() {
56
60
  let t = "";
@@ -63,145 +67,145 @@ class et {
63
67
  n && (t.style.cssText = n);
64
68
  }
65
69
  }
66
- function y(e, t = "unset") {
67
- return new et().add("all", t).add("display", e).add("box-sizing", "border-box");
70
+ function v(e, t = "unset") {
71
+ return new st().add("all", t).add("display", e).add("box-sizing", "border-box");
68
72
  }
69
- function $e(e, t, n) {
70
- e.add("color", t.color).add("font-family", t.fontFamily).add("font-weight", t.bold != null ? t.bold ? "700" : "400" : void 0).add("font-style", t.italic != null ? t.italic ? "italic" : "normal" : void 0).add("text-decoration", t.underline != null ? t.underline ? "underline" : "none" : void 0).add("letter-spacing", t.letterSpacing != null ? `${t.letterSpacing}pt` : void 0).add("line-height", String(Q(t))).add("text-align", t.align);
71
- const r = _(t, n);
72
- e.add("font-size", `${H(r.fontSizePx, 2)}px`);
73
+ function Oe(e, t, n) {
74
+ e.add("color", t.color).add("font-family", t.fontFamily).add("font-weight", t.bold != null ? t.bold ? "700" : "400" : void 0).add("font-style", t.italic != null ? t.italic ? "italic" : "normal" : void 0).add("text-decoration", t.underline != null ? t.underline ? "underline" : "none" : void 0).add("letter-spacing", t.letterSpacing != null ? `${t.letterSpacing}pt` : void 0).add("line-height", String(ne(t))).add("text-align", t.align);
75
+ const r = U(t, n);
76
+ e.add("font-size", `${j(r.fontSizePx, 2)}px`);
73
77
  }
74
- function tt(e, t, n) {
78
+ function lt(e, t, n) {
75
79
  const r = t.style ?? {};
76
- $e(e, r, n), e.add("background-color", r.backgroundColor).add("opacity", r.opacity != null ? String(r.opacity) : void 0).add("transform", r.rotateDeg ? `rotate(${r.rotateDeg}deg)` : void 0);
80
+ Oe(e, r, n), e.add("background-color", r.backgroundColor).add("opacity", r.opacity != null ? String(r.opacity) : void 0).add("transform", r.rotateDeg ? `rotate(${r.rotateDeg}deg)` : void 0);
77
81
  }
78
- function nt(e, t, n, r, i, o) {
82
+ function ct(e, t, n, r, i, o) {
79
83
  const s = e.cell, a = o.createElement("td");
80
- a.className = E("cell", i), a.dataset.mrRowIndex = String(e.ri), a.dataset.mrColumnIndex = String(e.ci), a.setAttribute("role", t.table?.role === "header" ? "columnheader" : "cell"), s.colSpan && (a.colSpan = s.colSpan), s.rowSpan && (a.rowSpan = s.rowSpan);
81
- const l = Te(t.style, s.style), c = y("block").add("position", "absolute").mm("left", e.xMm, r).mm("top", e.yMm, r).mm("width", e.widthMm, r).mm("height", e.heightMm, r).add("background-color", l.backgroundColor).add("vertical-align", l.verticalAlign ?? "middle");
82
- $e(c, l, r), c.applyTo(a);
83
- const d = o.createElement("div");
84
- d.className = "mr-cell-content", y("flex").add("position", "absolute").mm("left", n + (s.indentMm ?? 0), r).mm("right", n, r).mm("top", n, r).mm("bottom", n, r).add("flex-direction", "column").add("justify-content", l.verticalAlign === "top" ? "flex-start" : l.verticalAlign === "bottom" ? "flex-end" : "center").add("overflow-wrap", "anywhere").add("overflow", "hidden").applyTo(d), s.text != null && d.append(s.text);
85
- for (const m of s.children ?? []) d.appendChild(Le(m, r, i, o));
86
- return a.appendChild(d), a;
87
- }
88
- function rt(e, t, n, r) {
89
- return Ae(e, t).map((i) => {
90
- const o = `${H(i.widthPt * n / 72, 2)}px solid ${i.color}`, s = r.createElement("div");
84
+ a.className = T("cell", i), a.dataset.mrRowIndex = String(e.ri), a.dataset.mrColumnIndex = String(e.ci), a.setAttribute("role", t.table?.role === "header" ? "columnheader" : "cell"), s.colSpan && (a.colSpan = s.colSpan), s.rowSpan && (a.rowSpan = s.rowSpan);
85
+ const l = Pe(t.style, s.style), c = v("block").add("position", "absolute").mm("left", e.xMm, r).mm("top", e.yMm, r).mm("width", e.widthMm, r).mm("height", e.heightMm, r).add("background-color", l.backgroundColor).add("vertical-align", l.verticalAlign ?? "middle");
86
+ Oe(c, l, r), c.applyTo(a);
87
+ const m = o.createElement("div");
88
+ m.className = "mr-cell-content", v("flex").add("position", "absolute").mm("left", n + (s.indentMm ?? 0), r).mm("right", n, r).mm("top", n, r).mm("bottom", n, r).add("flex-direction", "column").add("justify-content", l.verticalAlign === "top" ? "flex-start" : l.verticalAlign === "bottom" ? "flex-end" : "center").add("overflow-wrap", "anywhere").add("overflow", "hidden").applyTo(m), s.text != null && m.append(s.text);
89
+ for (const d of s.children ?? []) m.appendChild(He(d, r, i, o));
90
+ return a.appendChild(m), a;
91
+ }
92
+ function mt(e, t, n, r) {
93
+ return Ne(e, t).map((i) => {
94
+ const o = `${j(i.widthPt * n / 72, 2)}px solid ${i.color}`, s = r.createElement("div");
91
95
  s.className = "mr-grid-edge", s.setAttribute("aria-hidden", "true");
92
96
  const a = i.kind === "h";
93
- return y("block").add("position", "absolute").add("pointer-events", "none").mm("left", a ? i.from : i.pos, n).mm("top", a ? i.pos : i.from, n).mm("width", a ? i.to - i.from : 0, n).mm("height", a ? 0 : i.to - i.from, n).add(a ? "border-top" : "border-left", o).applyTo(s), s;
97
+ return v("block").add("position", "absolute").add("pointer-events", "none").mm("left", a ? i.from : i.pos, n).mm("top", a ? i.pos : i.from, n).mm("width", a ? i.to - i.from : 0, n).mm("height", a ? 0 : i.to - i.from, n).add(a ? "border-top" : "border-left", o).applyTo(s), s;
94
98
  });
95
99
  }
96
- function it(e, t, n, r, i) {
100
+ function dt(e, t, n, r, i) {
97
101
  const o = i.createElement("table");
98
- o.className = E("grid", r), o.setAttribute("role", "table"), y("block").add("position", "relative").add("width", "100%").add("height", "100%").applyTo(o);
99
- const s = Pe(e, t.widthMm, t.heightMm), a = i.createElement("tbody");
100
- y("contents").applyTo(a), o.appendChild(a);
102
+ o.className = T("grid", r), o.setAttribute("role", "table"), v("block").add("position", "relative").add("width", "100%").add("height", "100%").applyTo(o);
103
+ const s = Ie(e, t.widthMm, t.heightMm), a = i.createElement("tbody");
104
+ v("contents").applyTo(a), o.appendChild(a);
101
105
  const l = e.cells.map(() => {
102
- const d = i.createElement("tr");
103
- return d.className = E("row", r), d.setAttribute("role", "row"), y("contents").applyTo(d), a.appendChild(d), d;
106
+ const m = i.createElement("tr");
107
+ return m.className = T("row", r), m.setAttribute("role", "row"), v("contents").applyTo(m), a.appendChild(m), m;
104
108
  });
105
- for (const d of s.cells)
106
- l[d.ri].appendChild(nt(d, t, e.paddingMm ?? 0.5, n, r, i));
109
+ for (const m of s.cells)
110
+ l[m.ri].appendChild(ct(m, t, e.paddingMm ?? 0.5, n, r, i));
107
111
  const c = i.createElement("div");
108
- return y("block").add("position", "relative").add("width", "100%").add("height", "100%").applyTo(c), c.append(o, ...rt(s, t, n, i)), c;
112
+ return v("block").add("position", "relative").add("width", "100%").add("height", "100%").applyTo(c), c.append(o, ...mt(s, t, n, i)), c;
109
113
  }
110
- function ot(e, t, n, r) {
114
+ function ht(e, t, n, r) {
111
115
  const i = r.createElement("div");
112
- i.className = E("paragraph", n), y("block").add("text-align", e.align).add("line-height", e.lineHeight != null ? String(e.lineHeight) : void 0).mm("margin-top", e.spaceBeforeMm ?? 0, t).mm("margin-bottom", e.spaceAfterMm ?? 0, t).mm("text-indent", e.indentMm ?? 0, t).applyTo(i);
116
+ i.className = T("paragraph", n), v("block").add("text-align", e.align).add("line-height", e.lineHeight != null ? String(e.lineHeight) : void 0).mm("margin-top", e.spaceBeforeMm ?? 0, t).mm("margin-bottom", e.spaceAfterMm ?? 0, t).mm("text-indent", e.indentMm ?? 0, t).applyTo(i);
113
117
  for (const o of e.segments || []) {
114
118
  const s = r.createElement("span");
115
- s.className = E("segment", n), s.textContent = o.kind === "field" ? o.field ?? "" : o.text ?? "";
116
- const a = y("inline");
119
+ s.className = T("segment", n), s.textContent = o.kind === "field" ? o.field ?? "" : o.text ?? "";
120
+ const a = v("inline");
117
121
  if (o.style) {
118
122
  const l = o.style;
119
- a.add("color", l.color).add("font-family", l.fontFamily).add("font-weight", l.bold != null ? l.bold ? "700" : "400" : void 0).add("font-style", l.italic != null ? l.italic ? "italic" : "normal" : void 0).add("text-decoration", l.underline != null ? l.underline ? "underline" : "none" : void 0), (l.fontSize != null || l.fontSizePx != null) && a.add("font-size", `${H(_(l, t).fontSizePx, 2)}px`);
123
+ a.add("color", l.color).add("font-family", l.fontFamily).add("font-weight", l.bold != null ? l.bold ? "700" : "400" : void 0).add("font-style", l.italic != null ? l.italic ? "italic" : "normal" : void 0).add("text-decoration", l.underline != null ? l.underline ? "underline" : "none" : void 0), (l.fontSize != null || l.fontSizePx != null) && a.add("font-size", `${j(U(l, t).fontSizePx, 2)}px`);
120
124
  }
121
125
  a.applyTo(s), i.appendChild(s);
122
126
  }
123
127
  return i;
124
128
  }
125
- function at(e, t, n, r) {
126
- if (Ce(e)) {
129
+ function gt(e, t, n, r) {
130
+ if ($e(e)) {
127
131
  const i = r.createElement("div");
128
- i.className = E("rich", n), y("block").applyTo(i);
129
- for (const o of e.richParagraphs) i.appendChild(ot(o, t, n, r));
132
+ i.className = T("rich", n), v("block").applyTo(i);
133
+ for (const o of e.richParagraphs) i.appendChild(ht(o, t, n, r));
130
134
  return i;
131
135
  }
132
136
  if (Array.isArray(e.lines) && e.lines.length > 0) {
133
137
  const i = r.createElement("div");
134
- i.className = E("lines", n), y("block").applyTo(i);
138
+ i.className = T("lines", n), v("block").applyTo(i);
135
139
  for (const o of e.lines) {
136
140
  const s = r.createElement("div");
137
- s.className = E("line", n), s.textContent = o, y("block").add("white-space", "pre").add("min-height", "1lh").applyTo(s), i.appendChild(s);
141
+ s.className = T("line", n), s.textContent = o, v("block").add("white-space", "pre").add("min-height", "1lh").applyTo(s), i.appendChild(s);
138
142
  }
139
143
  return i;
140
144
  }
141
145
  return e.text ?? "";
142
146
  }
143
- function st(e, t, n, r) {
147
+ function ft(e, t, n, r) {
144
148
  const i = r.createElement("div");
145
- i.className = E("text", n);
149
+ i.className = T("text", n);
146
150
  const o = e.style || {};
147
- return y("flex").add("width", "100%").add("height", "100%").add("flex-direction", "column").add("justify-content", o.verticalAlign === "middle" ? "center" : o.verticalAlign === "bottom" ? "flex-end" : "flex-start").add("overflow-wrap", "anywhere").add("overflow", "hidden").applyTo(i), i.append(at(e, t, n, r)), i;
151
+ return v("flex").add("width", "100%").add("height", "100%").add("flex-direction", "column").add("justify-content", o.verticalAlign === "middle" ? "center" : o.verticalAlign === "bottom" ? "flex-end" : "flex-start").add("overflow-wrap", "anywhere").add("overflow", "hidden").applyTo(i), i.append(gt(e, t, n, r)), i;
148
152
  }
149
- function lt(e, t, n) {
153
+ function ut(e, t, n) {
150
154
  const r = n.createElement("img");
151
- return r.className = E("image", t), r.src = e.imageData, y("block").add("width", "100%").add("height", "100%").add("object-fit", "contain").applyTo(r), r.alt = e.kind, r;
155
+ return r.className = T("image", t), r.src = e.imageData, v("block").add("width", "100%").add("height", "100%").add("object-fit", "contain").applyTo(r), r.alt = e.kind, r;
152
156
  }
153
- function fe(e, t, n, r) {
157
+ function be(e, t, n, r) {
154
158
  const i = r.createElement("div");
155
- i.className = E("shape", n);
156
- const o = e.style || {}, s = j(o), a = Ee(o), l = `${H(s.widthPt * t / 72, 2)}px solid ${s.color}`, c = y("block");
159
+ i.className = T("shape", n);
160
+ const o = e.style || {}, s = G(o), a = Re(o), l = `${j(s.widthPt * t / 72, 2)}px solid ${s.color}`, c = v("block");
157
161
  return e.grid ? c.add("position", "relative") : e.kind === "rect" ? (a.top && c.add("border-top", l), a.right && c.add("border-right", l), a.bottom && c.add("border-bottom", l), a.left && c.add("border-left", l)) : e.kind === "ellipse" ? (a.inner && c.add("border", l).add("border-radius", "50%"), o.backgroundColor && c.add("background-color", o.backgroundColor)) : e.kind === "line" && c.add("height", "0").add("border-top", l), c.add("box-sizing", "border-box").add("width", "100%").add("height", "100%"), c.applyTo(i), i;
158
162
  }
159
- function ct(e, t, n) {
160
- const r = n.createElementNS("http://www.w3.org/2000/svg", "svg"), i = ie(e.widthMm, t), o = ie(e.heightMm, t);
163
+ function pt(e, t, n) {
164
+ const r = n.createElementNS("http://www.w3.org/2000/svg", "svg"), i = se(e.widthMm, t), o = se(e.heightMm, t);
161
165
  r.setAttribute("width", String(Math.max(1, i))), r.setAttribute("height", String(Math.max(1, o))), r.setAttribute("aria-hidden", "true"), r.style.overflow = "visible", r.style.display = "block";
162
166
  const s = n.createElementNS("http://www.w3.org/2000/svg", "line");
163
167
  s.setAttribute("x1", "0"), s.setAttribute("x2", String(i)), s.setAttribute("y1", e.lineDirection === "up" ? String(o) : "0"), s.setAttribute("y2", e.lineDirection === "up" ? "0" : String(o));
164
- const a = j({ ...e.style, borderColor: e.style?.lineColor ?? e.style?.borderColor });
168
+ const a = G({ ...e.style, borderColor: e.style?.lineColor ?? e.style?.borderColor });
165
169
  return s.setAttribute("stroke", a.color), s.setAttribute("stroke-width", String(a.widthPt * t / 72)), r.appendChild(s), r;
166
170
  }
167
- function Le(e, t, n, r) {
171
+ function He(e, t, n, r) {
168
172
  const i = r.createElement("div");
169
- i.className = `${E("comp", n)} mr-kind-${e.kind}`;
170
- const o = y("block").add("position", "absolute").mm("left", e.leftMm, t).mm("top", e.topMm, t).mm("width", e.widthMm, t).mm("height", e.heightMm, t).add("box-sizing", "border-box");
171
- if (tt(o, e, t), o.applyTo(i), ee(e))
172
- return i.appendChild(lt(e, n, r)), i;
173
+ i.className = `${T("comp", n)} mr-kind-${e.kind}`;
174
+ const o = v("block").add("position", "absolute").mm("left", e.leftMm, t).mm("top", e.topMm, t).mm("width", e.widthMm, t).mm("height", e.heightMm, t).add("box-sizing", "border-box");
175
+ if (lt(o, e, t), o.applyTo(i), re(e))
176
+ return i.appendChild(ut(e, n, r)), i;
173
177
  if (e.kind === "text")
174
- return i.appendChild(st(e, t, n, r)), i;
178
+ return i.appendChild(ft(e, t, n, r)), i;
175
179
  if (e.grid) {
176
- const a = fe(e, t, n, r);
177
- return a.appendChild(it(e.grid, e, t, n, r)), i.appendChild(a), i;
180
+ const a = be(e, t, n, r);
181
+ return a.appendChild(dt(e.grid, e, t, n, r)), i.appendChild(a), i;
178
182
  }
179
183
  if (e.kind === "line" && e.lineDirection)
180
- return i.appendChild(ct(e, t, r)), i;
184
+ return i.appendChild(pt(e, t, r)), i;
181
185
  if (e.kind === "line" || e.kind === "rect" || e.kind === "ellipse")
182
- return i.appendChild(fe(e, t, n, r)), i;
186
+ return i.appendChild(be(e, t, n, r)), i;
183
187
  const s = r.createElement("div");
184
- return s.className = E("unknown", n), y("block").applyTo(s), s.textContent = e.fallbackText ?? `[${e.kind}]`, s.dataset.mrUnsupported = e.kind, s.setAttribute("role", "note"), i.appendChild(s), i;
188
+ return s.className = T("unknown", n), v("block").applyTo(s), s.textContent = e.fallbackText ?? `[${e.kind}]`, s.dataset.mrUnsupported = e.kind, s.setAttribute("role", "note"), i.appendChild(s), i;
185
189
  }
186
- function dt(e, t, n, r) {
190
+ function wt(e, t, n, r) {
187
191
  const i = r.createElement("div");
188
- return i.className = E("page", n), y("block", "initial").add("position", "relative").add("font-family", Z).add("font-size", `${H(_(void 0, t).fontSizePx, 2)}px`).add("line-height", String(Q(void 0))).add("white-space", "pre-wrap").add("direction", "ltr").mm("width", e.pageWidthMm, t).mm("height", e.pageHeightMm, t).add("background-color", "#fff").add("color", xe).add("overflow", "hidden").add("box-sizing", "border-box").applyTo(i), e.components.forEach((o, s) => {
189
- const a = Le(o, t, n, r);
192
+ return i.className = T("page", n), v("block", "initial").add("position", "relative").add("font-family", te).add("font-size", `${j(U(void 0, t).fontSizePx, 2)}px`).add("line-height", String(ne(void 0))).add("white-space", "pre-wrap").add("direction", "ltr").mm("width", e.pageWidthMm, t).mm("height", e.pageHeightMm, t).add("background-color", "#fff").add("color", Ce).add("overflow", "hidden").add("box-sizing", "border-box").applyTo(i), e.components.forEach((o, s) => {
193
+ const a = He(o, t, n, r);
190
194
  a.dataset.mrComponentIndex = String(s), i.appendChild(a);
191
195
  }), i;
192
196
  }
193
- function wn(e, t, n = {}) {
197
+ function Pn(e, t, n = {}) {
194
198
  const r = n.dpi ?? 96;
195
- G(e, "dom", n);
199
+ q(e, "dom", n);
196
200
  const i = t.createElement("div");
197
- return i.className = E("root", n), y("block").applyTo(i), i.dataset.schemaVersion = e.schemaVersion, e.pages.forEach((o) => {
198
- i.appendChild(dt(o, r, n, t));
201
+ return i.className = T("root", n), v("block").applyTo(i), i.dataset.schemaVersion = e.schemaVersion, e.pages.forEach((o) => {
202
+ i.appendChild(wt(o, r, n, t));
199
203
  }), i;
200
204
  }
201
- function R(e) {
205
+ function $(e) {
202
206
  if (e?.aborted) throw e.reason ?? new DOMException("The operation was aborted.", "AbortError");
203
207
  }
204
- const mt = (e, t) => (R(t), /^data:image\/(?:png|jpe?g|webp|gif|svg\+xml)[;,]/i.test(e) ? new Promise((n, r) => {
208
+ const bt = (e, t) => ($(t), /^data:image\/(?:png|jpe?g|webp|gif|svg\+xml)[;,]/i.test(e) ? new Promise((n, r) => {
205
209
  const i = new Image(), o = () => {
206
210
  i.onload = null, i.onerror = null, t?.removeEventListener("abort", s);
207
211
  }, s = () => {
@@ -213,199 +217,199 @@ const mt = (e, t) => (R(t), /^data:image\/(?:png|jpe?g|webp|gif|svg\+xml)[;,]/i.
213
217
  o(), r(new Error("Image could not be decoded for Canvas output."));
214
218
  }, t?.addEventListener("abort", s, { once: !0 }), i.src = e;
215
219
  }) : Promise.reject(new TypeError("Canvas imageData must be an image data URL; provide imageLoader for other sources.")));
216
- function ht(e, t, n) {
217
- return R(n), n ? new Promise((r, i) => {
220
+ function yt(e, t, n) {
221
+ return $(n), n ? new Promise((r, i) => {
218
222
  const o = () => i(n.reason ?? new DOMException("The operation was aborted.", "AbortError"));
219
223
  n.addEventListener("abort", o, { once: !0 }), Promise.resolve().then(() => e(t, n)).then(r, i).finally(() => n.removeEventListener("abort", o));
220
224
  }) : e(t);
221
225
  }
222
- async function gt(e, t, n) {
226
+ async function vt(e, t, n) {
223
227
  const r = /* @__PURE__ */ new Map();
224
228
  for (const i of e.components)
225
- !ee(i) || r.has(i.imageData) || r.set(i.imageData, await ht(t, i.imageData, n));
226
- return R(n), r;
229
+ !re(i) || r.has(i.imageData) || r.set(i.imageData, await yt(t, i.imageData, n));
230
+ return $(n), r;
227
231
  }
228
- function ut(e, t, n, r, i, o) {
232
+ function Mt(e, t, n, r, i, o) {
229
233
  const s = t, a = s.naturalWidth ?? s.width ?? i, l = s.naturalHeight ?? s.height ?? o;
230
234
  if (a <= 0 || l <= 0) throw new RangeError("Decoded Canvas image dimensions must be positive.");
231
- const c = Math.min(i / a, o / l), d = a * c, m = l * c;
232
- e.drawImage(t, n + (i - d) / 2, r + (o - m) / 2, d, m);
235
+ const c = Math.min(i / a, o / l), m = a * c, d = l * c;
236
+ e.drawImage(t, n + (i - m) / 2, r + (o - d) / 2, m, d);
233
237
  }
234
- function ft(e) {
235
- return Ze(e.pageHeightsPx, e.gapPx).window(e.viewportHeightPx, e.scrollTopPx, e.overscan);
238
+ function xt(e) {
239
+ return at(e.pageHeightsPx, e.gapPx).window(e.viewportHeightPx, e.scrollTopPx, e.overscan);
236
240
  }
237
- const le = 96 / 25.4;
238
- function ce(e, t = 96) {
239
- const n = t / 96 * le;
241
+ const de = 96 / 25.4;
242
+ function he(e, t = 96) {
243
+ const n = t / 96 * de;
240
244
  return {
241
245
  widthPx: Math.max(1, Math.round(e.pageWidthMm * n)),
242
246
  heightPx: Math.max(1, Math.round(e.pageHeightMm * n))
243
247
  };
244
248
  }
245
- function De(e, t, n, r = 64e6) {
249
+ function ze(e, t, n, r = 64e6) {
246
250
  if (!Number.isFinite(t) || t <= 0 || !Number.isFinite(n) || n <= 0) throw new RangeError("Canvas dpr and dpi must be positive finite numbers.");
247
251
  if (!Number.isFinite(r) || r <= 0) throw new RangeError("maxCanvasPixels must be positive and finite.");
248
- const i = ce(e, n), o = Math.round(i.widthPx * t), s = Math.round(i.heightPx * t);
252
+ const i = he(e, n), o = Math.round(i.widthPx * t), s = Math.round(i.heightPx * t);
249
253
  if (!Number.isSafeInteger(o) || !Number.isSafeInteger(s) || o * s > r) throw new RangeError("Canvas page exceeds maxCanvasPixels; reduce resolution or split the report.");
250
254
  return { width: o, height: s };
251
255
  }
252
- function Fe(e, t, n, r) {
253
- const i = document.createElement("canvas"), { widthPx: o, heightPx: s } = ce(e, n), a = De(e, t, n, r);
256
+ function Be(e, t, n, r) {
257
+ const i = document.createElement("canvas"), { widthPx: o, heightPx: s } = he(e, n), a = ze(e, t, n, r);
254
258
  i.width = a.width, i.height = a.height, i.style.width = `${o}px`, i.style.height = `${s}px`;
255
259
  const l = i.getContext("2d");
256
260
  if (!l)
257
261
  throw new Error("当前环境不支持 Canvas 2D(测试需真浏览器,见 e2e/canvas.spec.ts)");
258
262
  return l.scale(t, t), l.fillStyle = "#ffffff", l.fillRect(0, 0, o, s), { canvas: i, ctx: l };
259
263
  }
260
- function vn(e, t = 96) {
261
- return _(e, t).fontSizePx;
264
+ function An(e, t = 96) {
265
+ return U(e, t).fontSizePx;
262
266
  }
263
- function Oe(e, t, n, r, i, o, s, a = "top") {
267
+ function We(e, t, n, r, i, o, s, a = "top") {
264
268
  e.font = `${t.italic ? "italic " : ""}${t.bold ? "bold " : ""}${t.fontSizePx}px ${s}`, "letterSpacing" in e && (e.letterSpacing = "0px"), e.fillStyle = t.color, e.textBaseline = "alphabetic";
265
269
  const l = t.fontSizePx * t.lineHeight, c = t.text === "" ? [""] : t.text.split(`
266
- `), d = c.length * l;
267
- let m = r;
268
- a === "middle" ? m = r + (o - d) / 2 : a === "bottom" && (m = r + o - d), c.forEach((h, g) => {
269
- pt(e, h, t, n, m + g * l + t.fontSizePx * 0.8, i);
270
+ `), m = c.length * l;
271
+ let d = r;
272
+ a === "middle" ? d = r + (o - m) / 2 : a === "bottom" && (d = r + o - m), c.forEach((h, g) => {
273
+ Et(e, h, t, n, d + g * l + t.fontSizePx * 0.8, i);
270
274
  }), e.textAlign = "left";
271
275
  }
272
- function pt(e, t, n, r, i, o) {
276
+ function Et(e, t, n, r, i, o) {
273
277
  const s = Array.from(t), a = n.letterSpacingPx ?? 0;
274
278
  if (!a) {
275
279
  e.textAlign = n.align === "center" ? "center" : n.align === "right" ? "right" : "left";
276
- const m = n.align === "center" ? r + o / 2 : n.align === "right" ? r + o : r;
277
- e.fillText(t, m, i);
280
+ const d = n.align === "center" ? r + o / 2 : n.align === "right" ? r + o : r;
281
+ e.fillText(t, d, i);
278
282
  return;
279
283
  }
280
284
  const l = e.measureText(t).width + Math.max(0, s.length - 1) * a, c = n.align === "center" ? r + (o - l) / 2 : n.align === "right" ? r + o - l : r;
281
285
  e.textAlign = "left";
282
- let d = "";
283
- s.forEach((m, h) => {
284
- e.fillText(m, c + e.measureText(d).width + h * a, i), d += m;
286
+ let m = "";
287
+ s.forEach((d, h) => {
288
+ e.fillText(d, c + e.measureText(m).width + h * a, i), m += d;
285
289
  });
286
290
  }
287
- function wt(e, t, n, r, i, o, s) {
288
- for (const a of Ae(t, n))
289
- e.strokeStyle = a.color, e.lineWidth = O(a.widthPt, s), e.beginPath(), a.kind === "v" ? (e.moveTo(r + a.pos * o, i + a.from * o), e.lineTo(r + a.pos * o, i + a.to * o)) : (e.moveTo(r + a.from * o, i + a.pos * o), e.lineTo(r + a.to * o, i + a.pos * o)), e.stroke();
291
+ function St(e, t, n, r, i, o, s) {
292
+ for (const a of Ne(t, n))
293
+ e.strokeStyle = a.color, e.lineWidth = W(a.widthPt, s), e.beginPath(), a.kind === "v" ? (e.moveTo(r + a.pos * o, i + a.from * o), e.lineTo(r + a.pos * o, i + a.to * o)) : (e.moveTo(r + a.from * o, i + a.pos * o), e.lineTo(r + a.to * o, i + a.pos * o)), e.stroke();
290
294
  }
291
- function vt(e, t, n, r, i, o) {
295
+ function Tt(e, t, n, r, i, o) {
292
296
  e.beginPath(), t.top && (e.moveTo(n, r), e.lineTo(n + i, r)), t.right && (e.moveTo(n + i, r), e.lineTo(n + i, r + o)), t.bottom && (e.moveTo(n + i, r + o), e.lineTo(n, r + o)), t.left && (e.moveTo(n, r + o), e.lineTo(n, r)), e.stroke();
293
297
  }
294
- function bt(e, t, n, r, i, o, s, a, l, c, d) {
295
- const m = Pe(t, o / a, s / a);
296
- for (const g of m.cells) {
298
+ function Ct(e, t, n, r, i, o, s, a, l, c, m) {
299
+ const d = Ie(t, o / a, s / a);
300
+ for (const g of d.cells) {
297
301
  const f = g.cell.style?.backgroundColor ?? n.style?.backgroundColor;
298
302
  f && (e.fillStyle = f, e.fillRect(r + g.xMm * a, i + g.yMm * a, g.widthMm * a, g.heightMm * a));
299
303
  }
300
- wt(e, m, n, r, i, a, l);
304
+ St(e, d, n, r, i, a, l);
301
305
  const h = t.paddingMm ?? 0.5;
302
- for (const g of m.cells) {
306
+ for (const g of d.cells) {
303
307
  const f = g.cell.text ?? "";
304
308
  if (!f) continue;
305
- const v = Te(n.style, g.cell.style), N = _(v, l), C = g.cell.indentMm ?? 0, T = Math.max(0, g.widthMm - 2 * h - C), A = Re(f, T, { fontSizePt: N.fontSizePt, bold: v.bold, italic: v.italic, fontFamily: v.fontFamily ?? c, letterSpacingPt: v.letterSpacing }, d).join(`
309
+ const w = Pe(n.style, g.cell.style), C = U(w, l), x = g.cell.indentMm ?? 0, M = Math.max(0, g.widthMm - 2 * h - x), R = ke(f, M, { fontSizePt: C.fontSizePt, bold: w.bold, italic: w.italic, fontFamily: w.fontFamily ?? c, letterSpacingPt: w.letterSpacing }, m).join(`
306
310
  `);
307
- Oe(
311
+ We(
308
312
  e,
309
313
  {
310
- text: A,
311
- fontSizePx: N.fontSizePx,
312
- bold: v.bold ?? !1,
313
- italic: v.italic,
314
- color: Se(v, xe),
315
- align: v.align ?? "left",
316
- lineHeight: Q(v),
317
- letterSpacingPx: O(v.letterSpacing ?? 0, l)
314
+ text: R,
315
+ fontSizePx: C.fontSizePx,
316
+ bold: w.bold ?? !1,
317
+ italic: w.italic,
318
+ color: Ae(w, Ce),
319
+ align: w.align ?? "left",
320
+ lineHeight: ne(w),
321
+ letterSpacingPx: W(w.letterSpacing ?? 0, l)
318
322
  },
319
- r + (g.xMm + h + C) * a,
323
+ r + (g.xMm + h + x) * a,
320
324
  i + (g.yMm + h) * a,
321
- T * a,
325
+ M * a,
322
326
  Math.max(0, g.heightMm - 2 * h) * a,
323
- v.fontFamily ?? c,
324
- v.verticalAlign ?? "middle"
327
+ w.fontFamily ?? c,
328
+ w.verticalAlign ?? "middle"
325
329
  );
326
330
  }
327
331
  }
328
- function yt(e, t, n, r, i, o, s, a, l) {
329
- const c = t.style ?? {}, d = _(c, s), m = Ce(t) ? t.richParagraphs.map((h) => h.segments.map((g) => g.text ?? g.field ?? "").join("")).join(`
332
+ function Rt(e, t, n, r, i, o, s, a, l) {
333
+ const c = t.style ?? {}, m = U(c, s), d = $e(t) ? t.richParagraphs.map((h) => h.segments.map((g) => g.text ?? g.field ?? "").join("")).join(`
330
334
  `) : t.lines?.length ? t.lines.join(`
331
- `) : Re(t.text ?? "", t.widthMm, { fontSizePt: d.fontSizePt, bold: c.bold, italic: c.italic, fontFamily: c.fontFamily ?? a, letterSpacingPt: c.letterSpacing }, l).join(`
335
+ `) : ke(t.text ?? "", t.widthMm, { fontSizePt: m.fontSizePt, bold: c.bold, italic: c.italic, fontFamily: c.fontFamily ?? a, letterSpacingPt: c.letterSpacing }, l).join(`
332
336
  `);
333
- Oe(e, {
334
- text: m,
335
- fontSizePx: d.fontSizePx,
337
+ We(e, {
338
+ text: d,
339
+ fontSizePx: m.fontSizePx,
336
340
  bold: c.bold ?? !1,
337
341
  italic: c.italic,
338
- color: Se(c),
342
+ color: Ae(c),
339
343
  align: c.align ?? "left",
340
- lineHeight: Q(c),
341
- letterSpacingPx: O(c.letterSpacing ?? 0, s)
344
+ lineHeight: ne(c),
345
+ letterSpacingPx: W(c.letterSpacing ?? 0, s)
342
346
  }, n, r, i, o, c.fontFamily ?? a, c.verticalAlign);
343
347
  }
344
- function de(e, t, n, r, i, o, s) {
345
- const a = t.leftMm * n, l = t.topMm * n, c = t.widthMm * n, d = t.heightMm * n, m = t.style ?? {};
346
- if (ee(t)) {
348
+ function ge(e, t, n, r, i, o, s) {
349
+ const a = t.leftMm * n, l = t.topMm * n, c = t.widthMm * n, m = t.heightMm * n, d = t.style ?? {};
350
+ if (re(t)) {
347
351
  const h = s?.get(t.imageData);
348
- h ? ut(e, h, a, l, c, d) : pe(e, t, a, l, c, d);
352
+ h ? Mt(e, h, a, l, c, m) : ye(e, t, a, l, c, m);
349
353
  return;
350
354
  }
351
355
  if (t.grid) {
352
- bt(e, t.grid, t, a, l, c, d, n, r, i, o);
356
+ Ct(e, t.grid, t, a, l, c, m, n, r, i, o);
353
357
  return;
354
358
  }
355
359
  switch (t.kind) {
356
360
  case "text": {
357
- yt(e, t, a, l, c, d, r, i, o);
361
+ Rt(e, t, a, l, c, m, r, i, o);
358
362
  break;
359
363
  }
360
364
  case "rect": {
361
- const h = j(m), g = Ee(m);
362
- m.backgroundColor && (e.fillStyle = m.backgroundColor, e.fillRect(a, l, c, d)), g.inner && (e.strokeStyle = h.color, e.lineWidth = O(h.widthPt, r), vt(e, g, a, l, c, d));
365
+ const h = G(d), g = Re(d);
366
+ d.backgroundColor && (e.fillStyle = d.backgroundColor, e.fillRect(a, l, c, m)), g.inner && (e.strokeStyle = h.color, e.lineWidth = W(h.widthPt, r), Tt(e, g, a, l, c, m));
363
367
  break;
364
368
  }
365
369
  case "line": {
366
- const h = j({ ...m, borderColor: m.lineColor ?? m.borderColor });
367
- e.strokeStyle = h.color, e.lineWidth = O(h.widthPt, r), e.beginPath();
368
- const g = t.lineDirection === "up" ? l + d : t.lineDirection === "down" ? l : l + d / 2, f = t.lineDirection === "up" ? l : t.lineDirection === "down" ? l + d : l + d / 2;
370
+ const h = G({ ...d, borderColor: d.lineColor ?? d.borderColor });
371
+ e.strokeStyle = h.color, e.lineWidth = W(h.widthPt, r), e.beginPath();
372
+ const g = t.lineDirection === "up" ? l + m : t.lineDirection === "down" ? l : l + m / 2, f = t.lineDirection === "up" ? l : t.lineDirection === "down" ? l + m : l + m / 2;
369
373
  e.moveTo(a, g), e.lineTo(a + c, f), e.stroke();
370
374
  break;
371
375
  }
372
376
  case "ellipse": {
373
- const h = j(m);
374
- e.strokeStyle = h.color, e.lineWidth = O(h.widthPt, r), m.backgroundColor && (e.fillStyle = m.backgroundColor, e.beginPath(), e.ellipse(a + c / 2, l + d / 2, c / 2, d / 2, 0, 0, Math.PI * 2), e.fill()), e.beginPath(), e.ellipse(a + c / 2, l + d / 2, c / 2, d / 2, 0, 0, Math.PI * 2), e.stroke();
377
+ const h = G(d);
378
+ e.strokeStyle = h.color, e.lineWidth = W(h.widthPt, r), d.backgroundColor && (e.fillStyle = d.backgroundColor, e.beginPath(), e.ellipse(a + c / 2, l + m / 2, c / 2, m / 2, 0, 0, Math.PI * 2), e.fill()), e.beginPath(), e.ellipse(a + c / 2, l + m / 2, c / 2, m / 2, 0, 0, Math.PI * 2), e.stroke();
375
379
  break;
376
380
  }
377
381
  default:
378
- pe(e, t, a, l, c, d);
382
+ ye(e, t, a, l, c, m);
379
383
  break;
380
384
  }
381
385
  }
382
- function pe(e, t, n, r, i, o) {
386
+ function ye(e, t, n, r, i, o) {
383
387
  e.save(), e.strokeStyle = "#94a3b8", e.strokeRect(n, r, i, o), e.fillStyle = "#64748b", e.font = "12px sans-serif", e.fillText(t.fallbackText ?? `[${t.kind}]`, n + 3, r + 14), e.restore();
384
388
  }
385
- async function bn(e, t = {}) {
389
+ async function $n(e, t = {}) {
386
390
  if (typeof document > "u")
387
391
  throw new Error("renderPlanToImages 需要浏览器环境(SSR/Node 请在客户端钩子中调用)");
388
392
  const { format: n = "png", quality: r = 0.92, ...i } = t;
389
393
  if (n !== "png" && n !== "jpeg") throw new TypeError("Image format must be png or jpeg.");
390
394
  if (!Number.isFinite(r) || r < 0 || r > 1) throw new RangeError("Image quality must be between 0 and 1.");
391
- R(t.signal);
392
- const o = await ae(e, { ...t, format: "canvas" });
395
+ $(t.signal);
396
+ const o = await ce(e, { ...t, format: "canvas" });
393
397
  e = o.plan;
394
- const s = [...o.diagnostics, ...G(e, "canvas", t)], a = n === "jpeg" ? "image/jpeg" : "image/png", l = [], c = Math.min(e.pages.length - 1, t.end ?? e.pages.length - 1);
395
- for (let d = Math.max(0, t.start ?? 0); d <= c; d++) {
396
- R(t.signal);
397
- const m = await ze(e.pages[d], d, i, s);
398
+ const s = [...o.diagnostics, ...q(e, "canvas", t)], a = n === "jpeg" ? "image/jpeg" : "image/png", l = [], c = Math.min(e.pages.length - 1, t.end ?? e.pages.length - 1);
399
+ for (let m = Math.max(0, t.start ?? 0); m <= c; m++) {
400
+ $(t.signal);
401
+ const d = await _e(e.pages[m], m, i, s);
398
402
  try {
399
- l.push(await Mt(m, a, r, t.signal));
403
+ l.push(await Pt(d, a, r, t.signal));
400
404
  } finally {
401
- m.width = 0, m.height = 0;
405
+ d.width = 0, d.height = 0;
402
406
  }
403
- await Xe(t, l.length, c - Math.max(0, t.start ?? 0) + 1);
407
+ await it(t, l.length, c - Math.max(0, t.start ?? 0) + 1);
404
408
  }
405
- return R(t.signal), { blobs: l, diagnostics: s };
409
+ return $(t.signal), { blobs: l, diagnostics: s };
406
410
  }
407
- function Mt(e, t, n, r) {
408
- return R(r), new Promise((i, o) => {
411
+ function Pt(e, t, n, r) {
412
+ return $(r), new Promise((i, o) => {
409
413
  const s = () => o(r?.reason ?? new DOMException("The operation was aborted.", "AbortError"));
410
414
  r?.addEventListener("abort", s, { once: !0 });
411
415
  try {
@@ -417,24 +421,24 @@ function Mt(e, t, n, r) {
417
421
  }
418
422
  });
419
423
  }
420
- function yn(e, t = {}) {
421
- if (R(t.signal), typeof document > "u")
424
+ function kn(e, t = {}) {
425
+ if ($(t.signal), typeof document > "u")
422
426
  throw new Error("renderPlanToCanvas 需要浏览器环境(SSR 请在客户端钩子中调用)");
423
- const n = t.dpr ?? (typeof devicePixelRatio == "number" ? devicePixelRatio : 1), r = t.dpi ?? 96, i = r / 96 * le, o = t.fontFamily ?? Z, s = t.measurer ?? oe, a = Math.max(0, t.start ?? 0), l = Math.min(e.pages.length - 1, t.end ?? e.pages.length - 1), c = [], d = G(e, "canvas", t), m = xt(e, a, l);
424
- for (const h of m)
425
- ke(h, t), d.push(h);
426
- if (t.fidelity === "strict" && m.length) throw new Ke(d);
427
+ const n = t.dpr ?? (typeof devicePixelRatio == "number" ? devicePixelRatio : 1), r = t.dpi ?? 96, i = r / 96 * de, o = t.fontFamily ?? te, s = t.measurer ?? le, a = Math.max(0, t.start ?? 0), l = Math.min(e.pages.length - 1, t.end ?? e.pages.length - 1), c = [], m = q(e, "canvas", t), d = At(e, a, l);
428
+ for (const h of d)
429
+ Le(h, t), m.push(h);
430
+ if (t.fidelity === "strict" && d.length) throw new rt(m);
427
431
  for (let h = a; h <= l; h++) {
428
- R(t.signal);
429
- const g = e.pages[h], { canvas: f, ctx: v } = Fe(g, n, r, t.maxCanvasPixels);
430
- for (const N of g.components)
431
- de(v, N, i, r, o, s);
432
+ $(t.signal);
433
+ const g = e.pages[h], { canvas: f, ctx: w } = Be(g, n, r, t.maxCanvasPixels);
434
+ for (const C of g.components)
435
+ ge(w, C, i, r, o, s);
432
436
  c.push(f);
433
437
  }
434
- return { canvases: c, diagnostics: d };
438
+ return { canvases: c, diagnostics: m };
435
439
  }
436
- function xt(e, t, n) {
437
- return n < t ? [] : e.pages.slice(t, n + 1).flatMap((r, i) => r.components.flatMap((o, s) => ee(o) ? [{
440
+ function At(e, t, n) {
441
+ return n < t ? [] : e.pages.slice(t, n + 1).flatMap((r, i) => r.components.flatMap((o, s) => re(o) ? [{
438
442
  code: "async-image-required",
439
443
  severity: "warning",
440
444
  format: "canvas",
@@ -445,140 +449,140 @@ function xt(e, t, n) {
445
449
  message: "Use renderPlanToCanvasAsync or renderPlanToImages to decode and include images."
446
450
  }] : []));
447
451
  }
448
- async function Mn(e, t = {}) {
452
+ async function In(e, t = {}) {
449
453
  if (typeof document > "u") throw new Error("renderPlanToCanvasAsync 需要浏览器环境(Node 请使用 PDF 或 XLSX 输出)");
450
- R(t.signal);
451
- const n = await ae(e, { ...t, format: "canvas" });
454
+ $(t.signal);
455
+ const n = await ce(e, { ...t, format: "canvas" });
452
456
  e = n.plan;
453
- const r = [...n.diagnostics, ...G(e, "canvas", t)], i = [], o = Math.min(e.pages.length - 1, t.end ?? e.pages.length - 1);
457
+ const r = [...n.diagnostics, ...q(e, "canvas", t)], i = [], o = Math.min(e.pages.length - 1, t.end ?? e.pages.length - 1);
454
458
  for (let s = Math.max(0, t.start ?? 0); s <= o; s++)
455
- i.push(await ze(e.pages[s], s, t, r));
459
+ i.push(await _e(e.pages[s], s, t, r));
456
460
  return { canvases: i, diagnostics: r };
457
461
  }
458
- async function ze(e, t, n, r) {
459
- const i = n.dpr ?? (typeof devicePixelRatio == "number" ? devicePixelRatio : 1), o = n.dpi ?? 96, s = n.fontFamily ?? Z, a = await He(e, t, n, r);
460
- R(n.signal);
461
- const { canvas: l, ctx: c } = Fe(e, i, o, n.maxCanvasPixels);
462
- for (const d of e.components) de(c, d, o / 25.4, o, s, n.measurer ?? oe, a);
462
+ async function _e(e, t, n, r) {
463
+ const i = n.dpr ?? (typeof devicePixelRatio == "number" ? devicePixelRatio : 1), o = n.dpi ?? 96, s = n.fontFamily ?? te, a = await je(e, t, n, r);
464
+ $(n.signal);
465
+ const { canvas: l, ctx: c } = Be(e, i, o, n.maxCanvasPixels);
466
+ for (const m of e.components) ge(c, m, o / 25.4, o, s, n.measurer ?? le, a);
463
467
  return l;
464
468
  }
465
- async function He(e, t, n, r) {
466
- const i = n.imageLoader ?? mt;
467
- return gt(e, async (o, s) => {
469
+ async function je(e, t, n, r) {
470
+ const i = n.imageLoader ?? bt;
471
+ return vt(e, async (o, s) => {
468
472
  try {
469
473
  return await i(o, s);
470
474
  } catch (a) {
471
475
  if (s?.aborted) throw a;
472
- const l = e.components.findIndex((m) => m.imageData === o), c = e.components[l], d = { code: "image-decode-failed", severity: "warning", format: "canvas", pageIndex: t, componentIndex: l, kind: c.kind, nid: c.nid, message: "Image decoding failed; raster output was cancelled instead of omitting the image." };
473
- throw r.push(d), ke(d, n), a;
476
+ const l = e.components.findIndex((d) => d.imageData === o), c = e.components[l], m = { code: "image-decode-failed", severity: "warning", format: "canvas", pageIndex: t, componentIndex: l, kind: c.kind, nid: c.nid, message: "Image decoding failed; raster output was cancelled instead of omitting the image." };
477
+ throw r.push(m), Le(m, n), a;
474
478
  }
475
479
  }, n.signal);
476
480
  }
477
- function xn(e, t = {}) {
478
- const n = t.dpr ?? (typeof devicePixelRatio == "number" ? devicePixelRatio : 1), r = t.dpi ?? 96, i = r / 96 * le, o = t.fontFamily ?? Z, s = t.measurer ?? oe, a = t.overscan ?? 1, l = t.gapPx ?? 18, c = t.pagesPerFrame ?? 1, d = e.pages.map((u) => u.pageHeightMm * i), m = Math.max(1, ...e.pages.map((u) => u.pageWidthMm * i)), h = { start: 0, end: -1 };
479
- let g = null, f = null, v = null, N = null, C = [], T = 0, A = [], U = 0, B = new AbortController();
480
- const he = [];
481
- function je() {
481
+ function Nn(e, t = {}) {
482
+ const n = t.dpr ?? (typeof devicePixelRatio == "number" ? devicePixelRatio : 1), r = t.dpi ?? 96, i = r / 96 * de, o = t.fontFamily ?? te, s = t.measurer ?? le, a = t.overscan ?? 1, l = t.gapPx ?? 18, c = t.pagesPerFrame ?? 1, m = e.pages.map((u) => u.pageHeightMm * i), d = Math.max(1, ...e.pages.map((u) => u.pageWidthMm * i)), h = { start: 0, end: -1 };
483
+ let g = null, f = null, w = null, C = null, x = [], M = 0, R = [], z = 0, L = new AbortController();
484
+ const ue = [];
485
+ function qe() {
482
486
  const u = g;
483
- u.innerHTML = "", f = document.createElement("div"), f.style.cssText = `width:${m}px;margin:0 auto;`, v = document.createElement("div"), N = document.createElement("div"), f.appendChild(v), C = [];
484
- const M = Math.min(e.pages.length, 3 + a * 2);
485
- for (let D = 0; D < M; D++) {
486
- const b = document.createElement("div");
487
- b.style.cssText = `margin:0 auto ${l}px;box-shadow:0 2px 8px rgba(0,0,0,.35);background:#fff;`, f.appendChild(b), C.push(b);
487
+ u.innerHTML = "", f = document.createElement("div"), f.style.cssText = `width:${d}px;margin:0 auto;`, w = document.createElement("div"), C = document.createElement("div"), f.appendChild(w), x = [];
488
+ const E = Math.min(e.pages.length, 3 + a * 2);
489
+ for (let O = 0; O < E; O++) {
490
+ const y = document.createElement("div");
491
+ y.style.cssText = `margin:0 auto ${l}px;box-shadow:0 2px 8px rgba(0,0,0,.35);background:#fff;`, f.appendChild(y), x.push(y);
488
492
  }
489
- f.appendChild(N), u.appendChild(f);
493
+ f.appendChild(C), u.appendChild(f);
490
494
  }
491
- async function We(u, M) {
492
- const D = U, b = await ae(e, { ...t, signal: B.signal, format: "canvas", start: M, end: M });
493
- he.push(...b.diagnostics);
494
- const S = b.plan.pages[M], Y = await He(S, M, { ...t, signal: B.signal }, he);
495
- if (D !== U || !g) return;
496
- const { widthPx: ne, heightPx: re } = ce(S, r);
497
- let $ = u.firstElementChild;
498
- (!$ || $.tagName !== "CANVAS") && ($ = document.createElement("canvas"), u.innerHTML = "", u.appendChild($));
499
- const ue = De(S, n, r, t.maxCanvasPixels);
500
- $.width = ue.width, $.height = ue.height, $.style.width = `${ne}px`, $.style.height = `${re}px`;
501
- const F = $.getContext("2d");
502
- if (F) {
503
- F.setTransform(1, 0, 0, 1, 0, 0), F.scale(n, n), F.fillStyle = "#ffffff", F.fillRect(0, 0, ne, re);
504
- for (const Ue of S.components)
505
- de(F, Ue, i, r, o, s, Y);
506
- $.dataset.canvasPage = String(M), u.style.height = `${re}px`, u.style.width = `${ne}px`;
495
+ async function Je(u, E) {
496
+ const O = z, y = await ce(e, { ...t, signal: L.signal, format: "canvas", start: E, end: E });
497
+ ue.push(...y.diagnostics);
498
+ const P = y.plan.pages[E], K = await je(P, E, { ...t, signal: L.signal }, ue);
499
+ if (O !== z || !g) return;
500
+ const { widthPx: ae, heightPx: oe } = he(P, r);
501
+ let D = u.firstElementChild;
502
+ (!D || D.tagName !== "CANVAS") && (D = document.createElement("canvas"), u.innerHTML = "", u.appendChild(D));
503
+ const we = ze(P, n, r, t.maxCanvasPixels);
504
+ D.width = we.width, D.height = we.height, D.style.width = `${ae}px`, D.style.height = `${oe}px`;
505
+ const B = D.getContext("2d");
506
+ if (B) {
507
+ B.setTransform(1, 0, 0, 1, 0, 0), B.scale(n, n), B.fillStyle = "#ffffff", B.fillRect(0, 0, ae, oe);
508
+ for (const Ke of P.components)
509
+ ge(B, Ke, i, r, o, s, K);
510
+ D.dataset.canvasPage = String(E), u.style.height = `${oe}px`, u.style.width = `${ae}px`;
507
511
  }
508
512
  }
509
- function Ge(u) {
510
- U++, h.start = u.start, h.end = u.end, v.style.height = `${u.start * l + d.slice(0, u.start).reduce((b, S) => b + S, 0)}px`;
511
- const M = e.pages.length - 1 - u.end;
512
- N.style.height = `${M * l + d.slice(u.end + 1).reduce((b, S) => b + S, 0)}px`;
513
- const D = u.end - u.start + 1;
514
- C.forEach((b, S) => {
515
- if (S < D) {
516
- b.style.display = "";
517
- const Y = u.start + S;
518
- b.style.height = `${d[Y] ?? 0}px`;
513
+ function Ye(u) {
514
+ z++, h.start = u.start, h.end = u.end, w.style.height = `${u.start * l + m.slice(0, u.start).reduce((y, P) => y + P, 0)}px`;
515
+ const E = e.pages.length - 1 - u.end;
516
+ C.style.height = `${E * l + m.slice(u.end + 1).reduce((y, P) => y + P, 0)}px`;
517
+ const O = u.end - u.start + 1;
518
+ x.forEach((y, P) => {
519
+ if (P < O) {
520
+ y.style.display = "";
521
+ const K = u.start + P;
522
+ y.style.height = `${m[K] ?? 0}px`;
519
523
  } else
520
- b.style.display = "none";
521
- }), A = [];
522
- for (let b = u.start; b <= u.end; b++) {
523
- const S = C[b - u.start];
524
- if (!S) continue;
525
- S.firstElementChild?.dataset?.canvasPage !== String(b) && A.push(b);
524
+ y.style.display = "none";
525
+ }), R = [];
526
+ for (let y = u.start; y <= u.end; y++) {
527
+ const P = x[y - u.start];
528
+ if (!P) continue;
529
+ P.firstElementChild?.dataset?.canvasPage !== String(y) && R.push(y);
526
530
  }
527
- te();
531
+ ie();
528
532
  }
529
- function te() {
530
- T || A.length === 0 || (T = requestAnimationFrame(() => {
531
- T = 0;
533
+ function ie() {
534
+ M || R.length === 0 || (M = requestAnimationFrame(() => {
535
+ M = 0;
532
536
  let u = Math.max(1, c);
533
- for (; A.length > 0 && u-- > 0; ) {
534
- const M = A.shift(), D = C[M - h.start];
535
- D && We(D, M).catch(() => {
537
+ for (; R.length > 0 && u-- > 0; ) {
538
+ const E = R.shift(), O = x[E - h.start];
539
+ O && Je(O, E).catch(() => {
536
540
  });
537
541
  }
538
- A.length > 0 && te();
542
+ R.length > 0 && ie();
539
543
  }));
540
544
  }
541
- function V() {
542
- T || (T = requestAnimationFrame(() => {
543
- T = 0;
544
- const u = g, M = ft({
545
- pageHeightsPx: d,
545
+ function J() {
546
+ M || (M = requestAnimationFrame(() => {
547
+ M = 0;
548
+ const u = g, E = xt({
549
+ pageHeightsPx: m,
546
550
  viewportHeightPx: u.clientHeight,
547
551
  scrollTopPx: u.scrollTop,
548
552
  overscan: a,
549
553
  gapPx: l
550
554
  });
551
- M.start !== h.start || M.end !== h.end ? Ge(M) : te();
555
+ E.start !== h.start || E.end !== h.end ? Ye(E) : ie();
552
556
  }));
553
557
  }
554
- let q = null;
558
+ let Y = null;
555
559
  return {
556
560
  attach(u) {
557
561
  if (typeof document > "u")
558
562
  throw new Error("createCanvasPager 需要浏览器环境(SSR 请在客户端钩子中调用 attach)");
559
- R(t.signal), B = new AbortController(), t.signal?.addEventListener("abort", ge, { once: !0 }), G(e, "canvas", t), g = u, je(), u.addEventListener("scroll", V, { passive: !0 }), typeof ResizeObserver < "u" && (q = new ResizeObserver(() => V()), q.observe(u)), V();
563
+ $(t.signal), L = new AbortController(), t.signal?.addEventListener("abort", pe, { once: !0 }), q(e, "canvas", t), g = u, qe(), u.addEventListener("scroll", J, { passive: !0 }), typeof ResizeObserver < "u" && (Y = new ResizeObserver(() => J()), Y.observe(u)), J();
560
564
  },
561
565
  destroy() {
562
- U++, B.abort(), t.signal?.removeEventListener("abort", ge), T && cancelAnimationFrame(T), T = 0, q?.disconnect(), q = null, g?.removeEventListener("scroll", V), A = [], f?.remove(), g = null;
566
+ z++, L.abort(), t.signal?.removeEventListener("abort", pe), M && cancelAnimationFrame(M), M = 0, Y?.disconnect(), Y = null, g?.removeEventListener("scroll", J), R = [], f?.remove(), g = null;
563
567
  },
564
568
  window() {
565
569
  return { ...h };
566
570
  }
567
571
  };
568
- function ge() {
569
- B.abort(t.signal?.reason);
572
+ function pe() {
573
+ L.abort(t.signal?.reason);
570
574
  }
571
575
  }
572
- function _e(e, t, n) {
576
+ function Ue(e, t, n) {
573
577
  let r, i;
574
578
  if (typeof e == "string") {
575
- const o = J[e];
576
- if (!o) throw new Error(`未知纸张预设 "${e}"(可用:${Object.keys(J).join("/")})`);
579
+ const o = Z[e];
580
+ if (!o) throw new Error(`未知纸张预设 "${e}"(可用:${Object.keys(Z).join("/")})`);
577
581
  r = o.widthMm, i = o.heightMm;
578
582
  } else typeof e == "number" ? (r = e, i = t ?? 297) : (r = e.widthMm, i = e.heightMm);
579
583
  return n ? { widthMm: i, heightMm: r } : { widthMm: r, heightMm: i };
580
584
  }
581
- class Et {
585
+ class $t {
582
586
  constructor() {
583
587
  this.pages = [], this.pending = null, this.templateParams = void 0;
584
588
  }
@@ -611,12 +615,12 @@ class Et {
611
615
  */
612
616
  page(t = "a4", n = {}, r) {
613
617
  this.collect();
614
- const o = r != null && !("margins" in r) && !("landscape" in r) && ("marginTopMm" in r || "marginBottomMm" in r || "marginLeftMm" in r || "marginRightMm" in r) ? { margins: r } : typeof n == "number" ? r ?? {} : n, { widthMm: s, heightMm: a } = _e(
618
+ const o = r != null && !("margins" in r) && !("landscape" in r) && ("marginTopMm" in r || "marginBottomMm" in r || "marginLeftMm" in r || "marginRightMm" in r) ? { margins: r } : typeof n == "number" ? r ?? {} : n, { widthMm: s, heightMm: a } = Ue(
615
619
  t,
616
620
  typeof n == "number" ? n : void 0,
617
621
  o.landscape
618
622
  ), l = o.margins ?? {};
619
- return this.pending = new Tt(this, {
623
+ return this.pending = new kt(this, {
620
624
  widthMm: s,
621
625
  heightMm: a,
622
626
  marginTopMm: l.marginTopMm ?? 10,
@@ -638,7 +642,7 @@ class Et {
638
642
  };
639
643
  }
640
644
  }
641
- class Tt {
645
+ class kt {
642
646
  constructor(t, n) {
643
647
  this.parent = t, this.page = n, this.components = [];
644
648
  }
@@ -707,26 +711,26 @@ class Tt {
707
711
  return this.done().build();
708
712
  }
709
713
  }
710
- function En() {
711
- return new Et();
714
+ function Ln() {
715
+ return new $t();
712
716
  }
713
- function Tn(e, t = {}) {
714
- return Ve([], e), e.fields.map((n) => ({
717
+ function Dn(e, t = {}) {
718
+ return Ze([], e), e.fields.map((n) => ({
715
719
  field: n.field,
716
720
  header: `${n.label ?? n.field}${n.unit ? ` (${n.unit})` : ""}`,
717
721
  semanticRole: n.semanticRole ?? (n.type === "number" || n.type === "decimal" ? "measure" : n.type === "date" ? "date" : n.enum ? "dimension" : "text"),
718
722
  ...t[n.field]
719
723
  }));
720
724
  }
721
- function P(e, t, n = !1) {
725
+ function k(e, t, n = !1) {
722
726
  if (!Number.isFinite(e) || (n ? e < 0 : e <= 0))
723
727
  throw new Error(`${t} 必须是有限${n ? "非负" : "正"}数`);
724
728
  }
725
- function K(e, t, n) {
729
+ function Q(e, t, n) {
726
730
  if (e !== void 0 && !["left", "center", "right", "justify", ...n ? ["auto"] : []].includes(e))
727
731
  throw new Error(`${t} 必须是 left/center/right/justify${n ? "/auto" : ""}`);
728
732
  }
729
- function St(e) {
733
+ function It(e) {
730
734
  const t = e.layout ?? "page";
731
735
  if (t !== "page" && t !== "wide")
732
736
  throw new Error("layout 必须是 page 或 wide");
@@ -735,18 +739,18 @@ function St(e) {
735
739
  if (t !== "wide" && e.columnWidthMm !== void 0)
736
740
  throw new Error('columnWidthMm 仅适用于 layout: "wide"');
737
741
  const n = e.columnWidthMm ?? 30;
738
- return P(n, "columnWidthMm"), { layout: t, columnWidthMm: n };
742
+ return k(n, "columnWidthMm"), { layout: t, columnWidthMm: n };
739
743
  }
740
- function Ct(e) {
744
+ function Nt(e) {
741
745
  const t = e.paper === void 0 ? "a4" : e.paper;
742
746
  if (typeof t != "string" && (typeof t != "object" || t === null) || e.landscape !== void 0 && typeof e.landscape != "boolean")
743
747
  throw new Error("paper 必须是纸张预设名或 { widthMm, heightMm } 对象,landscape 必须是布尔值");
744
- if (typeof t == "string" && !Object.prototype.hasOwnProperty.call(J, t))
745
- throw new Error(`未知纸张预设 "${t}"(可用:${Object.keys(J).join("/")})`);
746
- const n = _e(t, void 0, e.landscape), r = n.widthMm, i = n.heightMm;
747
- return P(r, "纸张 widthMm"), P(i, "纸张 heightMm"), { widthMm: r, heightMm: i };
748
+ if (typeof t == "string" && !Object.prototype.hasOwnProperty.call(Z, t))
749
+ throw new Error(`未知纸张预设 "${t}"(可用:${Object.keys(Z).join("/")})`);
750
+ const n = Ue(t, void 0, e.landscape), r = n.widthMm, i = n.heightMm;
751
+ return k(r, "纸张 widthMm"), k(i, "纸张 heightMm"), { widthMm: r, heightMm: i };
748
752
  }
749
- function Rt(e) {
753
+ function Lt(e) {
750
754
  if (e.margins !== void 0 && (!e.margins || typeof e.margins != "object" || Array.isArray(e.margins)))
751
755
  throw new Error("margins 必须是页边距对象");
752
756
  const t = e.margins ?? {}, n = {
@@ -755,93 +759,93 @@ function Rt(e) {
755
759
  marginLeftMm: t.marginLeftMm === void 0 ? 10 : t.marginLeftMm,
756
760
  marginRightMm: t.marginRightMm === void 0 ? 10 : t.marginRightMm
757
761
  };
758
- for (const [r, i] of Object.entries(n)) P(i, r, !0);
762
+ for (const [r, i] of Object.entries(n)) k(i, r, !0);
759
763
  return n;
760
764
  }
761
- function Pt(e, t) {
765
+ function Dt(e, t) {
762
766
  const n = e.dataset === void 0 ? "detail" : e.dataset;
763
767
  if (typeof n != "string" || !n.trim())
764
768
  throw new Error("dataset 必须是非空字符串");
765
769
  if (e.title !== void 0 && typeof e.title != "string")
766
770
  throw new Error("title 必须是字符串");
767
771
  const r = e.titleHeightMm === void 0 ? 10 : e.titleHeightMm, i = e.titleGapMm === void 0 ? 4 : e.titleGapMm;
768
- P(r, "titleHeightMm"), P(i, "titleGapMm", !0);
772
+ k(r, "titleHeightMm"), k(i, "titleGapMm", !0);
769
773
  const o = e.title !== void 0 && e.title.length > 0, s = o ? r + i : 0;
770
774
  if (s >= t)
771
775
  throw new Error("标题高度与间距占满页面,必须为表格保留可用高度");
772
776
  return { dataset: n, titleHeightMm: r, hasTitle: o, titleSpaceMm: s };
773
777
  }
774
- function At(e) {
778
+ function Ft(e) {
775
779
  if (e.listOptions !== void 0 && (!e.listOptions || typeof e.listOptions != "object" || Array.isArray(e.listOptions)))
776
780
  throw new Error("listOptions 必须是列表配置对象");
777
781
  const t = e.listOptions ?? {};
778
- K(t.align, "listOptions.align", !0), K(t.headerAlign, "listOptions.headerAlign", !1);
782
+ Q(t.align, "listOptions.align", !0), Q(t.headerAlign, "listOptions.headerAlign", !1);
779
783
  for (const n of ["fontSizePt", "rowHeightMm", "paddingMm"]) {
780
784
  const r = t[n];
781
- r !== void 0 && P(r, `listOptions.${n}`, n === "paddingMm");
785
+ r !== void 0 && k(r, `listOptions.${n}`, n === "paddingMm");
782
786
  }
783
787
  return t;
784
788
  }
785
- function kt(e) {
789
+ function Ot(e) {
786
790
  let t = 0, n = 0;
787
791
  for (const [r, i] of e.entries()) {
788
792
  if (!i || typeof i.header != "string" || typeof i.field != "string" || !i.field.trim())
789
793
  throw new Error(`columns[${r}] 需要字符串 header 与非空 field`);
790
- K(i.align, `columns[${r}].align`, !0), K(i.headerAlign, `columns[${r}].headerAlign`, !1), i.flex !== void 0 && P(i.flex, `columns[${r}].flex`), i.widthMm !== void 0 ? (P(i.widthMm, `columns[${r}].widthMm`), t += i.widthMm) : n = Math.max(n, i.flex ?? 1);
794
+ Q(i.align, `columns[${r}].align`, !0), Q(i.headerAlign, `columns[${r}].headerAlign`, !1), i.flex !== void 0 && k(i.flex, `columns[${r}].flex`), i.widthMm !== void 0 ? (k(i.widthMm, `columns[${r}].widthMm`), t += i.widthMm) : n = Math.max(n, i.flex ?? 1);
791
795
  }
792
796
  return { fixedWidthMm: t, maxFlex: n };
793
797
  }
794
- function It(e, t, n, r) {
795
- const { fixedWidthMm: i, maxFlex: o } = kt(e.columns);
798
+ function Ht(e, t, n, r) {
799
+ const { fixedWidthMm: i, maxFlex: o } = Ot(e.columns);
796
800
  if (t === "page" && i > r)
797
801
  throw new Error(`固定列宽 ${i}mm 超出页面可用宽度 ${r}mm`);
798
802
  const s = r - i;
799
803
  if (t === "page" && o > 0 && s <= 0)
800
804
  throw new Error("固定列占满页面可用宽度,自动列需要正的剩余宽度");
801
- const a = o > 0 ? e.columns.reduce((c, d) => c + (d.widthMm === void 0 ? (d.flex ?? 1) / o : 0), 0) : 0;
802
- return { columns: e.columns.map(({ widthMm: c, flex: d, ...m }, h) => {
803
- const g = c ?? (t === "wide" ? n * (d ?? 1) : s * ((d ?? 1) / o) / a);
804
- return P(g, `columns[${h}] 分配后的 widthMm`), { ...m, widthMm: g };
805
+ const a = o > 0 ? e.columns.reduce((c, m) => c + (m.widthMm === void 0 ? (m.flex ?? 1) / o : 0), 0) : 0;
806
+ return { columns: e.columns.map(({ widthMm: c, flex: m, ...d }, h) => {
807
+ const g = c ?? (t === "wide" ? n * (m ?? 1) : s * ((m ?? 1) / o) / a);
808
+ return k(g, `columns[${h}] 分配后的 widthMm`), { ...d, widthMm: g };
805
809
  }), fixedWidthMm: i, maxFlex: o };
806
810
  }
807
- function Sn(e) {
811
+ function Fn(e) {
808
812
  if (!e || typeof e != "object")
809
813
  throw new Error("标准明细模板需要 options 对象");
810
814
  if (!Array.isArray(e.columns) || e.columns.length === 0)
811
815
  throw new Error("columns 至少需要一列");
812
- const { layout: t, columnWidthMm: n } = St(e), r = Ct(e);
816
+ const { layout: t, columnWidthMm: n } = It(e), r = Nt(e);
813
817
  let i = r.widthMm;
814
- const o = r.heightMm, s = Rt(e);
818
+ const o = r.heightMm, s = Lt(e);
815
819
  let a = i - s.marginLeftMm - s.marginRightMm;
816
820
  const l = o - s.marginTopMm - s.marginBottomMm;
817
821
  if (t === "page" && a <= 0 || l <= 0)
818
822
  throw new Error("页边距占满纸张,必须保留正的可用宽度和高度");
819
- const { dataset: c, titleHeightMm: d, hasTitle: m, titleSpaceMm: h } = Pt(e, l), g = At(e), { columns: f, fixedWidthMm: v, maxFlex: N } = It(e, t, n, a);
820
- t === "wide" && (a = f.reduce((T, A) => T + A.widthMm, 0), P(a, "宽表总列宽"), i = a + s.marginLeftMm + s.marginRightMm, P(i, "宽表总宽度"));
821
- const C = { widthMm: i, heightMm: o, ...s, components: [], ...t === "wide" ? { layout: t } : {} };
822
- return m && C.components.push({
823
+ const { dataset: c, titleHeightMm: m, hasTitle: d, titleSpaceMm: h } = Dt(e, l), g = Ft(e), { columns: f, fixedWidthMm: w, maxFlex: C } = Ht(e, t, n, a);
824
+ t === "wide" && (a = f.reduce((M, R) => M + R.widthMm, 0), k(a, "宽表总列宽"), i = a + s.marginLeftMm + s.marginRightMm, k(i, "宽表总宽度"));
825
+ const x = { widthMm: i, heightMm: o, ...s, components: [], ...t === "wide" ? { layout: t } : {} };
826
+ return d && x.components.push({
823
827
  kind: "text",
824
828
  text: e.title,
825
829
  leftMm: s.marginLeftMm,
826
830
  topMm: s.marginTopMm,
827
831
  widthMm: a,
828
- heightMm: d,
832
+ heightMm: m,
829
833
  style: { fontSize: 16, bold: !0, align: "center", verticalAlign: "middle", ...e.titleStyle }
830
- }), C.components.push({
834
+ }), x.components.push({
831
835
  align: "auto",
832
836
  headerAlign: "center",
833
837
  ...g,
834
838
  kind: "list",
835
839
  ...t === "wide" ? { layout: t } : {},
836
- ...m ? { title: e.title } : {},
840
+ ...d ? { title: e.title } : {},
837
841
  dataset: c,
838
842
  columns: f,
839
843
  leftMm: s.marginLeftMm,
840
844
  topMm: s.marginTopMm + h,
841
- widthMm: t === "wide" || N > 0 ? a : v
842
- }), e.params === void 0 ? { pages: [C] } : { params: e.params, pages: [C] };
845
+ widthMm: t === "wide" || C > 0 ? a : w
846
+ }), e.params === void 0 ? { pages: [x] } : { params: e.params, pages: [x] };
843
847
  }
844
- function Cn(e) {
848
+ function On(e) {
845
849
  if (e.components !== void 0 && e.pages !== void 0) throw new TypeError("标签 components 与 pages 只能选择一种");
846
850
  const { dataset: t, rowKey: n, copies: r, params: i } = e, o = e.pages ?? [{ components: e.components ?? [] }], s = {
847
851
  repeat: { dataset: t, ...n === void 0 ? {} : { rowKey: n }, ...r === void 0 ? {} : { copies: r } },
@@ -856,143 +860,143 @@ function Cn(e) {
856
860
  components: l.components,
857
861
  ...l.meta === void 0 ? {} : { meta: l.meta }
858
862
  }))
859
- }, a = Ie(s);
860
- if (!a.ok) throw new Ne(a.errors);
863
+ }, a = De(s);
864
+ if (!a.ok) throw new Fe(a.errors);
861
865
  return JSON.parse(JSON.stringify(s));
862
866
  }
863
- function Nt(e) {
867
+ function zt(e) {
864
868
  if (!e || typeof e != "object" || !e.repeat)
865
- throw new se("config", "defineLabelReport 需要带 repeat 的固定标签模板");
866
- const t = Ie(e);
867
- if (!t.ok) throw new Ne(t.errors);
869
+ throw new me("config", "defineLabelReport 需要带 repeat 的固定标签模板");
870
+ const t = De(e);
871
+ if (!t.ok) throw new Fe(t.errors);
868
872
  return e.repeat.dataset;
869
873
  }
870
- function we(e, t) {
871
- if (!Array.isArray(e)) throw new se("validate", "标签数据应为对象数组;请从业务响应中提取行数组");
874
+ function ve(e, t) {
875
+ if (!Array.isArray(e)) throw new me("validate", "标签数据应为对象数组;请从业务响应中提取行数组");
872
876
  return { [t]: e };
873
877
  }
874
- function Rn(e) {
875
- const { template: t, rows: n, load: r, dataSchema: i, params: o, pagination: s, dataValidation: a } = e, l = Nt(t);
878
+ function Hn(e) {
879
+ const { template: t, rows: n, load: r, dataSchema: i, params: o, pagination: s, dataValidation: a } = e, l = zt(t);
876
880
  if (n !== void 0 == (r !== void 0) || r !== void 0 && typeof r != "function")
877
- throw new se("config", "标签报表应且只能配置 rows 或 load 其中一种数据来源");
881
+ throw new me("config", "标签报表应且只能配置 rows 或 load 其中一种数据来源");
878
882
  const c = { template: t, params: o, pagination: s, dataValidation: a, ...i === void 0 ? {} : { dataSchema: { [l]: i } } };
879
- return r ? qe({ ...c, load: r, mapData: (d) => we(d, l) }) : { ...c, datasets: we(n, l) };
883
+ return r ? Qe({ ...c, load: r, mapData: (m) => ve(m, l) }) : { ...c, datasets: ve(n, l) };
880
884
  }
881
- function Pn(e) {
885
+ function zn(e) {
882
886
  return e;
883
887
  }
884
- class L extends Error {
888
+ class F extends Error {
885
889
  constructor(t, n) {
886
890
  super(n), this.code = t, this.name = "ReportTemplateStoreError";
887
891
  }
888
892
  }
889
- function k(e) {
893
+ function I(e) {
890
894
  return JSON.parse(JSON.stringify(e));
891
895
  }
892
- function x(e) {
896
+ function S(e) {
893
897
  if (!e?.aborted) return;
894
898
  const t = new Error("模板操作已取消");
895
899
  throw t.name = "AbortError", t;
896
900
  }
897
- function ve(e) {
901
+ function Me(e) {
898
902
  const t = e ? Number(e.revision) : 0;
899
- if (!Number.isSafeInteger(t) || t < 0 || t >= Number.MAX_SAFE_INTEGER) throw new L("history", "修订号无效或已达上限");
903
+ if (!Number.isSafeInteger(t) || t < 0 || t >= Number.MAX_SAFE_INTEGER) throw new F("history", "修订号无效或已达上限");
900
904
  return String(t + 1);
901
905
  }
902
- function An(e, t = {}) {
906
+ function Bn(e, t = {}) {
903
907
  const n = async (s, a) => {
904
- x(a);
908
+ S(a);
905
909
  const l = await e.read(s, a);
906
- return x(a), l ? k(l) : void 0;
910
+ return S(a), l ? I(l) : void 0;
907
911
  }, r = async (s, a) => {
908
912
  const l = await n(s, a.signal);
909
- if ((l?.revision ?? null) !== a.expectedRevision) throw new L("conflict", "模板已变化,请重新读取后提交");
913
+ if ((l?.revision ?? null) !== a.expectedRevision) throw new F("conflict", "模板已变化,请重新读取后提交");
910
914
  return l;
911
915
  }, i = async (s, a, l) => {
912
- if (x(a.signal), !await e.compareAndSwap(s.id, a.expectedRevision, k(s), { signal: a.signal, ...l ? { publication: k(l) } : {} })) throw new L("conflict", "模板已被其他请求更新");
913
- return k(s);
916
+ if (S(a.signal), !await e.compareAndSwap(s.id, a.expectedRevision, I(s), { signal: a.signal, ...l ? { publication: I(l) } : {} })) throw new F("conflict", "模板已被其他请求更新");
917
+ return I(s);
914
918
  }, o = async (s, a, l, c) => {
915
919
  if (t.beforePublish) {
916
- x(l.signal);
917
- const g = await t.beforePublish({ document: I(a), previous: s.published ? I(s.published) : void 0, signal: l.signal });
918
- if (!g || g.ok !== !0) throw new L("review", g?.issues?.find((f) => f.severity === "error")?.message ?? "模板发布检查未通过");
919
- x(l.signal);
920
+ S(l.signal);
921
+ const g = await t.beforePublish({ document: N(a), previous: s.published ? N(s.published) : void 0, signal: l.signal });
922
+ if (!g || g.ok !== !0) throw new F("review", g?.issues?.find((f) => f.severity === "error")?.message ?? "模板发布检查未通过");
923
+ S(l.signal);
920
924
  }
921
- const d = ve(s), m = I({ ...a, revision: d }), h = { revision: d, document: m, publishedAt: (t.now?.() ?? /* @__PURE__ */ new Date()).toISOString() };
922
- return c !== void 0 && (h.restoredFrom = c), i({ id: s.id, revision: d, publishedRevision: d, published: m }, l, h);
925
+ const m = Me(s), d = N({ ...a, revision: m }), h = { revision: m, document: d, publishedAt: (t.now?.() ?? /* @__PURE__ */ new Date()).toISOString() };
926
+ return c !== void 0 && (h.restoredFrom = c), i({ id: s.id, revision: m, publishedRevision: m, published: d }, l, h);
923
927
  };
924
928
  return {
925
929
  list: async (s) => {
926
- x(s);
930
+ S(s);
927
931
  const a = await e.list(s);
928
- return x(s), k(a);
932
+ return S(s), I(a);
929
933
  },
930
934
  get: async (s, a = {}) => {
931
935
  const l = await n(s, a.signal), c = a.draft ? l?.draft : l?.published;
932
- return c ? I(c) : void 0;
936
+ return c ? N(c) : void 0;
933
937
  },
934
938
  history: async (s, a) => {
935
- x(a);
939
+ S(a);
936
940
  const l = await e.history(s, a);
937
- return x(a), k(l);
941
+ return S(a), I(l);
938
942
  },
939
943
  saveDraft: async (s, a) => {
940
- a = { ...a }, x(a.signal);
941
- const l = I(t.migrate ? await t.migrate(s) : s), c = await r(l.id, a), d = ve(c);
944
+ a = { ...a }, S(a.signal);
945
+ const l = N(t.migrate ? await t.migrate(s) : s), c = await r(l.id, a), m = Me(c);
942
946
  return i({
943
947
  id: l.id,
944
- revision: d,
945
- draft: { ...l, revision: d },
948
+ revision: m,
949
+ draft: { ...l, revision: m },
946
950
  ...c?.publishedRevision ? { publishedRevision: c.publishedRevision, published: c.published } : {}
947
951
  }, a);
948
952
  },
949
953
  publish: async (s, a) => {
950
954
  a = { ...a };
951
955
  const l = await r(s, a);
952
- if (!l) throw new L("missing", "模板不存在");
953
- if (!l.draft) throw new L("draft", "没有可发布的草稿");
956
+ if (!l) throw new F("missing", "模板不存在");
957
+ if (!l.draft) throw new F("draft", "没有可发布的草稿");
954
958
  return o(l, l.draft, a);
955
959
  },
956
960
  rollback: async (s, a, l) => {
957
961
  l = { ...l };
958
962
  const c = await r(s, l);
959
- if (!c) throw new L("missing", "模板不存在");
960
- x(l.signal);
961
- const d = await e.getVersion(s, a, l.signal);
962
- if (!d) throw new L("history", "历史修订不存在");
963
- return o(c, d.document, l, a);
963
+ if (!c) throw new F("missing", "模板不存在");
964
+ S(l.signal);
965
+ const m = await e.getVersion(s, a, l.signal);
966
+ if (!m) throw new F("history", "历史修订不存在");
967
+ return o(c, m.document, l, a);
964
968
  }
965
969
  };
966
970
  }
967
- function kn() {
971
+ function Wn() {
968
972
  const e = /* @__PURE__ */ new Map(), t = /* @__PURE__ */ new Map();
969
973
  return {
970
974
  read: async (n, r) => {
971
- x(r);
975
+ S(r);
972
976
  const i = e.get(n);
973
- return i ? k(i) : void 0;
977
+ return i ? I(i) : void 0;
974
978
  },
975
- list: async (n) => (x(n), Array.from(e.values(), ({ id: r, revision: i, publishedRevision: o }) => ({ id: r, revision: i, ...o ? { publishedRevision: o } : {} }))),
976
- history: async (n, r) => (x(r), Array.from(t.get(n)?.values() ?? [], (i) => k(i))),
979
+ list: async (n) => (S(n), Array.from(e.values(), ({ id: r, revision: i, publishedRevision: o }) => ({ id: r, revision: i, ...o ? { publishedRevision: o } : {} }))),
980
+ history: async (n, r) => (S(r), Array.from(t.get(n)?.values() ?? [], (i) => I(i))),
977
981
  getVersion: async (n, r, i) => {
978
- x(i);
982
+ S(i);
979
983
  const o = t.get(n)?.get(r);
980
- return o ? k(o) : void 0;
984
+ return o ? I(o) : void 0;
981
985
  },
982
986
  compareAndSwap: async (n, r, i, o) => {
983
- if (x(o.signal), (e.get(n)?.revision ?? null) !== r) return !1;
984
- if (i.id !== n) throw new L("history", "状态 ID 与存储 ID 不一致");
985
- const s = k(i), a = o.publication;
987
+ if (S(o.signal), (e.get(n)?.revision ?? null) !== r) return !1;
988
+ if (i.id !== n) throw new F("history", "状态 ID 与存储 ID 不一致");
989
+ const s = I(i), a = o.publication;
986
990
  if (a) {
987
991
  const l = t.get(n) ?? /* @__PURE__ */ new Map();
988
- if (l.has(a.revision) || a.revision !== i.revision || a.document.id !== n) throw new L("history", "发布修订不可覆盖,且必须与状态修订和模板 ID 一致");
989
- l.set(a.revision, k(a)), t.set(n, l);
992
+ if (l.has(a.revision) || a.revision !== i.revision || a.document.id !== n) throw new F("history", "发布修订不可覆盖,且必须与状态修订和模板 ID 一致");
993
+ l.set(a.revision, I(a)), t.set(n, l);
990
994
  }
991
995
  return e.set(n, s), !0;
992
996
  }
993
997
  };
994
998
  }
995
- function $t(e, t) {
999
+ function Bt(e, t) {
996
1000
  const n = e.publishedRevision ?? e.published?.revision;
997
1001
  for (const r of [e.draftRevision, n]) if (r !== void 0 && (typeof r != "string" || !r.trim())) throw new TypeError("模板生命周期修订应为非空字符串");
998
1002
  if (e.draftRevision !== void 0 && e.draftRevision !== t.revision) throw new TypeError("可编辑文档应与草稿修订一致");
@@ -1000,52 +1004,52 @@ function $t(e, t) {
1000
1004
  if (!e.published && n !== void 0 && n !== t.revision) throw new TypeError("发布修订需要对应的独立文档");
1001
1005
  return { ...e.draftRevision === void 0 ? {} : { draftRevision: e.draftRevision }, ...n === void 0 ? {} : { publishedRevision: n } };
1002
1006
  }
1003
- function In(e, t) {
1004
- const n = I(e);
1007
+ function _n(e, t) {
1008
+ const n = N(e);
1005
1009
  if (t.id === n.id) throw new Error("复制模板应使用新的 ID");
1006
1010
  const { revision: r, ...i } = n;
1007
- return I({ ...i, id: t.id, name: t.name });
1011
+ return N({ ...i, id: t.id, name: t.name });
1008
1012
  }
1009
- function Nn(e) {
1013
+ function jn(e) {
1010
1014
  if (!Array.isArray(e) || e.length > 1e3) throw new RangeError("本地模板目录最多 1000 项");
1011
1015
  const t = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Map(), r = [];
1012
1016
  for (const i of e) {
1013
- const o = I(i.document);
1017
+ const o = N(i.document);
1014
1018
  if (t.has(o.id)) throw new Error(`模板 ID 重复:${o.id}`);
1015
1019
  if (i.category !== void 0 && (typeof i.category != "string" || i.category.length > 128) || i.tags !== void 0 && (!Array.isArray(i.tags) || i.tags.length > 20 || i.tags.some((c) => typeof c != "string" || c.length > 128))) throw new TypeError("模板分类和标签无效");
1016
- const s = $t(i, o), { template: a, ...l } = o;
1017
- t.set(o.id, o), i.published ? n.set(o.id, I(i.published)) : s.publishedRevision && n.set(o.id, I(o)), r.push({ ...l, ...s, ...i.category ? { category: i.category } : {}, ...i.tags ? { tags: [...i.tags] } : {} });
1020
+ const s = Bt(i, o), { template: a, ...l } = o;
1021
+ t.set(o.id, o), i.published ? n.set(o.id, N(i.published)) : s.publishedRevision && n.set(o.id, N(o)), r.push({ ...l, ...s, ...i.category ? { category: i.category } : {}, ...i.tags ? { tags: [...i.tags] } : {} });
1018
1022
  }
1019
1023
  return r.sort((i, o) => i.id < o.id ? -1 : 1), {
1020
1024
  search: async (i) => {
1021
- be(i.signal);
1025
+ xe(i.signal);
1022
1026
  const o = i.limit ?? 30;
1023
1027
  if (!Number.isSafeInteger(o) || o < 1 || o > 100) throw new RangeError("模板每页数量应为 1–100");
1024
- const s = i.query?.trim().toLocaleLowerCase() ?? "", a = r.filter((c) => (!i.category || c.category === i.category) && (!i.cursor || c.id > i.cursor) && (!s || [c.id, c.name, c.description, ...c.tags ?? []].some((d) => d?.toLocaleLowerCase().includes(s)))), l = /* @__PURE__ */ new Map();
1028
+ const s = i.query?.trim().toLocaleLowerCase() ?? "", a = r.filter((c) => (!i.category || c.category === i.category) && (!i.cursor || c.id > i.cursor) && (!s || [c.id, c.name, c.description, ...c.tags ?? []].some((m) => m?.toLocaleLowerCase().includes(s)))), l = /* @__PURE__ */ new Map();
1025
1029
  for (const c of r) c.category && l.set(c.category, (l.get(c.category) ?? 0) + 1);
1026
- return JSON.parse(JSON.stringify({ items: a.slice(0, o), ...a.length > o ? { next: a[o - 1].id } : {}, categories: Array.from(l, ([c, d]) => ({ id: c, label: c, count: d })) }));
1030
+ return JSON.parse(JSON.stringify({ items: a.slice(0, o), ...a.length > o ? { next: a[o - 1].id } : {}, categories: Array.from(l, ([c, m]) => ({ id: c, label: c, count: m })) }));
1027
1031
  },
1028
1032
  get: async (i, o) => {
1029
- be(o.signal);
1033
+ xe(o.signal);
1030
1034
  const s = o.mode === "published" ? n.get(i) : t.get(i);
1031
- return s ? I(s) : void 0;
1035
+ return s ? N(s) : void 0;
1032
1036
  }
1033
1037
  };
1034
1038
  }
1035
- function be(e) {
1039
+ function xe(e) {
1036
1040
  if (!e?.aborted) return;
1037
1041
  const t = new Error("模板目录操作已取消");
1038
1042
  throw t.name = "AbortError", t;
1039
1043
  }
1040
- function $n(e) {
1044
+ function Un(e) {
1041
1045
  return e.map((t) => t.map((n) => /[\t\r\n"]/.test(n) ? `"${n.replace(/"/g, '""')}"` : n).join(" ")).join(`\r
1042
1046
  `);
1043
1047
  }
1044
- function Lt(e, t) {
1048
+ function Wt(e, t) {
1045
1049
  const n = e[e.length - 1];
1046
1050
  e.length > 1 && n?.length === 1 && n[0] === "" && /[\r\n]$/.test(t) && e.pop();
1047
1051
  }
1048
- function Ln(e, t = 1e4) {
1052
+ function Gn(e, t = 1e4) {
1049
1053
  if (e.length > 4 * 1024 * 1024) throw new Error("Clipboard text limit exceeded");
1050
1054
  const n = [[]];
1051
1055
  let r = "", i = !1, o = !1, s = 0;
@@ -1085,9 +1089,9 @@ function Ln(e, t = 1e4) {
1085
1089
  r += c;
1086
1090
  }
1087
1091
  if (i) throw new Error("Unclosed clipboard quote");
1088
- return a(), Lt(n, e), n;
1092
+ return a(), Wt(n, e), n;
1089
1093
  }
1090
- class Dt extends Error {
1094
+ class _t extends Error {
1091
1095
  constructor(t, n, r) {
1092
1096
  const i = typeof n.label == "string" ? n.label : "单元格", o = {
1093
1097
  definition: `${i}的编辑器配置无效`,
@@ -1104,373 +1108,450 @@ class Dt extends Error {
1104
1108
  }
1105
1109
  }
1106
1110
  function p(e, t, n) {
1107
- throw new Dt(t, e, n);
1111
+ throw new _t(t, e, n);
1108
1112
  }
1109
- function Be(e) {
1113
+ function Ge(e) {
1110
1114
  if (typeof e != "string" || !/^\d{4}-\d{2}-\d{2}$/.test(e) || e.startsWith("0000-")) return !1;
1111
1115
  const t = /* @__PURE__ */ new Date(`${e}T00:00:00.000Z`);
1112
1116
  return Number.isFinite(t.getTime()) && t.toISOString().slice(0, 10) === e;
1113
1117
  }
1114
- function Ft(e) {
1118
+ function jt(e) {
1115
1119
  const [t = "", n = "0"] = String(e).toLowerCase().split("e");
1116
1120
  return Math.max(0, (t.split(".")[1]?.length ?? 0) - Number(n));
1117
1121
  }
1118
- function Ot(e, t) {
1119
- e.min !== void 0 && t < e.min && p(e, "min", e.min), e.max !== void 0 && t > e.max && p(e, "max", e.max), e.precision !== void 0 && Ft(t) > e.precision && p(e, "precision", e.precision);
1122
+ function Ut(e, t) {
1123
+ e.min !== void 0 && t < e.min && p(e, "min", e.min), e.max !== void 0 && t > e.max && p(e, "max", e.max), e.precision !== void 0 && jt(t) > e.precision && p(e, "precision", e.precision);
1120
1124
  }
1121
- function zt(e, t) {
1122
- Be(t) || p(e, "date"), e.min !== void 0 && t < e.min && p(e, "min", e.min), e.max !== void 0 && t > e.max && p(e, "max", e.max);
1125
+ function Gt(e, t) {
1126
+ Ge(t) || p(e, "date"), e.min !== void 0 && t < e.min && p(e, "min", e.min), e.max !== void 0 && t > e.max && p(e, "max", e.max);
1123
1127
  }
1124
- function Ht(e) {
1128
+ function Vt(e) {
1125
1129
  [e.min, e.max].some((t) => t !== void 0 && !Number.isFinite(t)) && p(e, "definition"), e.min !== void 0 && e.max !== void 0 && e.min > e.max && p(e, "definition"), e.precision !== void 0 && (!Number.isInteger(e.precision) || e.precision < 0 || e.precision > 15) && p(e, "definition");
1126
1130
  }
1127
- function _t(e) {
1128
- [e.min, e.max].some((t) => t !== void 0 && !Be(t)) && p(e, "definition"), e.min !== void 0 && e.max !== void 0 && e.min > e.max && p(e, "definition");
1131
+ function qt(e) {
1132
+ [e.min, e.max].some((t) => t !== void 0 && !Ge(t)) && p(e, "definition"), e.min !== void 0 && e.max !== void 0 && e.min > e.max && p(e, "definition");
1129
1133
  }
1130
- function Bt(e, t) {
1134
+ function Jt(e, t) {
1131
1135
  (!Array.isArray(t.options) || !t.options.length) && p(t, "definition");
1132
1136
  const n = e.valueType === "text" ? "string" : e.valueType, r = /* @__PURE__ */ new Set();
1133
1137
  for (const i of t.options)
1134
1138
  (!i || typeof i.value !== n || typeof i.value == "number" && !Number.isFinite(i.value)) && p(t, "definition"), i.label !== void 0 && typeof i.label != "string" && p(t, "definition"), r.has(i.value) && p(t, "definition"), r.add(i.value);
1135
1139
  }
1136
- function jt(e) {
1140
+ function Yt(e) {
1137
1141
  e.required !== void 0 && typeof e.required != "boolean" && p(e, "definition"), [e.label, e.hint, e.unit].some((t) => t !== void 0 && typeof t != "string") && p(e, "definition"), e.type === "boolean" && [e.trueLabel, e.falseLabel].some((t) => t !== void 0 && typeof t != "string") && p(e, "definition");
1138
1142
  }
1139
- function Wt(e, t) {
1140
- (!t || typeof t != "object" || Array.isArray(t) || !["text", "number", "boolean", "enum", "date"].includes(t.type)) && p(t ?? { type: "text" }, "definition"), jt(t), (t.type === "number" || t.type === "boolean") && e.valueType !== t.type && p(t, "type"), (t.type === "text" || t.type === "date") && e.valueType !== "text" && p(t, "type"), t.type === "number" && Ht(t), t.type === "text" && t.maxLength !== void 0 && (!Number.isInteger(t.maxLength) || t.maxLength < 0) && p(t, "definition"), t.type === "date" && _t(t), t.type === "enum" && Bt(e, t);
1143
+ function Kt(e, t) {
1144
+ (!t || typeof t != "object" || Array.isArray(t) || !["text", "number", "boolean", "enum", "date"].includes(t.type)) && p(t ?? { type: "text" }, "definition"), Yt(t), (t.type === "number" || t.type === "boolean") && e.valueType !== t.type && p(t, "type"), (t.type === "text" || t.type === "date") && e.valueType !== "text" && p(t, "type"), t.type === "number" && Vt(t), t.type === "text" && t.maxLength !== void 0 && (!Number.isInteger(t.maxLength) || t.maxLength < 0) && p(t, "definition"), t.type === "date" && qt(t), t.type === "enum" && Jt(e, t);
1141
1145
  }
1142
- function Dn(e, t, n) {
1143
- if (!e.editable) throw new Ye("readonly");
1144
- n && Wt(e, n);
1145
- const r = Je(e, t);
1146
- return n ? (n.required && typeof r == "string" && !r.trim() && p(n, "required"), r === null || r === "" ? (n.required && p(n, "required"), r) : (n.type === "number" && Ot(n, r), n.type === "date" && zt(n, r), n.type === "text" && n.maxLength !== void 0 && [...String(r)].length > n.maxLength && p(n, "length", n.maxLength), n.type === "enum" && !n.options.some((i) => Object.is(i.value, r)) && p(n, "choice"), r)) : r;
1146
+ function Vn(e, t, n) {
1147
+ if (!e.editable) throw new et("readonly");
1148
+ n && Kt(e, n);
1149
+ const r = tt(e, t);
1150
+ return n ? (n.required && typeof r == "string" && !r.trim() && p(n, "required"), r === null || r === "" ? (n.required && p(n, "required"), r) : (n.type === "number" && Ut(n, r), n.type === "date" && Gt(n, r), n.type === "text" && n.maxLength !== void 0 && [...String(r)].length > n.maxLength && p(n, "length", n.maxLength), n.type === "enum" && !n.options.some((i) => Object.is(i.value, r)) && p(n, "choice"), r)) : r;
1147
1151
  }
1148
- class w extends Error {
1152
+ class b extends Error {
1149
1153
  constructor(t) {
1150
1154
  super(`Report calculation: ${t}`), this.code = t, this.name = "ReportCalculationError";
1151
1155
  }
1152
1156
  }
1153
- function z(e) {
1157
+ function _(e) {
1154
1158
  if (!e?.aborted) return;
1155
1159
  const t = new Error("Calculation cancelled");
1156
1160
  throw t.name = "AbortError", t;
1157
1161
  }
1158
- async function X(e, t = 1) {
1162
+ async function ee(e, t = 1) {
1159
1163
  const n = Math.floor(e.scanned / 2048);
1160
- if (e.scanned += t, e.scanned > e.maxScanned) throw new w("limit");
1161
- z(e.signal), Math.floor(e.scanned / 2048) > n && (await e.yieldToHost(), z(e.signal));
1164
+ if (e.scanned += t, e.scanned > e.maxScanned) throw new b("limit");
1165
+ _(e.signal), Math.floor(e.scanned / 2048) > n && (await e.yieldToHost(), _(e.signal));
1162
1166
  }
1163
- function me(e) {
1167
+ function fe(e) {
1164
1168
  return e.table?.role === "header" ? -Math.max(1, e.grid?.cells.length ?? 1) : e.table?.rowIndex ?? 0;
1165
1169
  }
1166
- function ye(e, t, n) {
1167
- if (![t.pageIndex, t.componentIndex, t.rowIndex, t.columnIndex].every((a) => Number.isSafeInteger(a) && a >= 0)) throw new w("selection");
1170
+ function Ee(e, t, n) {
1171
+ if (![t.pageIndex, t.componentIndex, t.rowIndex, t.columnIndex].every((a) => Number.isSafeInteger(a) && a >= 0)) throw new b("selection");
1168
1172
  const r = e.pages[t.pageIndex]?.components[t.componentIndex];
1169
- if (!r?.grid || t.rowIndex >= r.grid.cells.length) throw new w("selection");
1173
+ if (!r?.grid || t.rowIndex >= r.grid.cells.length) throw new b("selection");
1170
1174
  const i = r.grid.colWidthsMm?.length ?? r.grid.cells.reduce((a, l) => Math.max(a, l.length), 1);
1171
- if (t.columnIndex >= i) throw new w("selection");
1175
+ if (t.columnIndex >= i) throw new b("selection");
1172
1176
  const o = r.table, s = e.pages[n.pageIndex]?.components[n.componentIndex]?.table;
1173
1177
  if (o && s && o.id === s.id) {
1174
1178
  const a = s.columnKeys.indexOf(o.columnKeys[t.columnIndex] ?? "");
1175
- if (a < 0) throw new w("selection");
1176
- return { grid: o.id, row: me(r) + t.rowIndex, column: a };
1179
+ if (a < 0) throw new b("selection");
1180
+ return { grid: o.id, row: fe(r) + t.rowIndex, column: a };
1177
1181
  }
1178
1182
  return { grid: `${t.pageIndex}:${t.componentIndex}`, row: t.rowIndex, column: t.columnIndex };
1179
1183
  }
1180
- function Gt(e, t, n) {
1181
- const r = ye(e, t.anchor, t.anchor), i = ye(e, t.focus, t.anchor);
1182
- if (r.grid !== i.grid) throw new w("selection");
1184
+ function Xt(e, t, n) {
1185
+ const r = Ee(e, t.anchor, t.anchor), i = Ee(e, t.focus, t.anchor);
1186
+ if (r.grid !== i.grid) throw new b("selection");
1183
1187
  const o = (Math.abs(r.row - i.row) + 1) * (Math.abs(r.column - i.column) + 1);
1184
- if (!Number.isSafeInteger(o) || o > n) throw new w("limit");
1188
+ if (!Number.isSafeInteger(o) || o > n) throw new b("limit");
1185
1189
  return { grid: r.grid, rowStart: Math.min(r.row, i.row), rowEnd: Math.max(r.row, i.row), columnStart: Math.min(r.column, i.column), columnEnd: Math.max(r.column, i.column), origin: e.pages[t.anchor.pageIndex].components[t.anchor.componentIndex].table };
1186
1190
  }
1187
- function Ut(e) {
1191
+ function Zt(e) {
1188
1192
  if (!e) return !1;
1189
1193
  const t = e.replace(/"[^"]*"|\\.|\[(?![hms]+\])[^\]]*\]/gi, "");
1190
1194
  return /[ymdhs]/i.test(t);
1191
1195
  }
1192
- function Vt(e) {
1193
- if (e.valueType === "text" || e.valueType === "boolean" || Ut(e.numberFormat)) return null;
1196
+ function Qt(e) {
1197
+ if (e.valueType === "text" || e.valueType === "boolean" || Zt(e.numberFormat)) return null;
1194
1198
  const t = e.value;
1195
1199
  if (typeof t != "number" || !Number.isFinite(t)) return null;
1196
- if (Number.isInteger(t) && !Number.isSafeInteger(t)) throw new w("precision");
1200
+ if (Number.isInteger(t) && !Number.isSafeInteger(t)) throw new b("precision");
1197
1201
  return t;
1198
1202
  }
1199
- function qt(e, t, n) {
1203
+ function en(e, t, n) {
1200
1204
  if (e.seen.has(n)) return;
1201
1205
  e.seen.add(n), e.selected++;
1202
- const r = t ? Vt(t) : null;
1206
+ const r = t ? Qt(t) : null;
1203
1207
  r === null ? e.excluded++ : e.values.push(r);
1204
1208
  }
1205
- function Yt(e, t, n, r) {
1209
+ function tn(e, t, n, r) {
1206
1210
  return r.origin ? e.table?.id === r.origin.id : `${t}:${n}` === r.grid;
1207
1211
  }
1208
- function Jt(e, t, n) {
1212
+ function nn(e, t, n) {
1209
1213
  return n.origin ? n.origin.columnKeys.indexOf(e.table.columnKeys[t] ?? "") : t;
1210
1214
  }
1211
- function Kt(e, t, n, r) {
1212
- const i = r.origin ? me(e) + t : t, o = Jt(e, n, r);
1215
+ function rn(e, t, n, r) {
1216
+ const i = r.origin ? fe(e) + t : t, o = nn(e, n, r);
1213
1217
  return i < r.rowStart || i > r.rowEnd || o < r.columnStart || o > r.columnEnd ? null : `${r.grid}:${i}:${o}`;
1214
1218
  }
1215
- function Xt(e, t) {
1216
- const n = t.origin ? me(e) : 0, r = Math.max(0, t.rowStart - n), i = Math.min(e.grid.cells.length, t.rowEnd - n + 1);
1219
+ function an(e, t) {
1220
+ const n = t.origin ? fe(e) : 0, r = Math.max(0, t.rowStart - n), i = Math.min(e.grid.cells.length, t.rowEnd - n + 1);
1217
1221
  return i > r ? i : 0;
1218
1222
  }
1219
- async function Zt(e, t, n, r, i) {
1223
+ async function on(e, t, n, r, i) {
1220
1224
  const o = e.grid;
1221
- if (t > r.maxScanned) throw new w("limit");
1225
+ if (t > r.maxScanned) throw new b("limit");
1222
1226
  const s = o.colWidthsMm?.length ?? o.cells.reduce((l, c) => Math.max(l, c.length), 1);
1223
- if (s > r.maxScanned) throw new w("limit");
1227
+ if (s > r.maxScanned) throw new b("limit");
1224
1228
  const a = /* @__PURE__ */ new Map();
1225
1229
  for (let l = 0; l < t; l++) {
1226
- l > 0 && l % 2048 === 0 && (await r.yieldToHost(), z(r.signal));
1230
+ l > 0 && l % 2048 === 0 && (await r.yieldToHost(), _(r.signal));
1227
1231
  let c = 0;
1228
- for (const d of o.cells[l]) {
1229
- for (await X(r); c < s && (a.get(c) ?? 0) > l; ) c++;
1232
+ for (const m of o.cells[l]) {
1233
+ for (await ee(r); c < s && (a.get(c) ?? 0) > l; ) c++;
1230
1234
  if (c >= s) break;
1231
- const m = Math.max(1, Math.min(d?.colSpan ?? 1, s - c)), h = Math.min(o.cells.length, l + Math.max(1, d?.rowSpan ?? 1));
1232
- m > 1 && await X(r, m - 1);
1233
- for (let f = c; f < c + m; f++) a.set(f, h);
1234
- const g = Kt(e, l, c, n);
1235
- g && qt(i, d, g), c += m;
1235
+ const d = Math.max(1, Math.min(m?.colSpan ?? 1, s - c)), h = Math.min(o.cells.length, l + Math.max(1, m?.rowSpan ?? 1));
1236
+ d > 1 && await ee(r, d - 1);
1237
+ for (let f = c; f < c + d; f++) a.set(f, h);
1238
+ const g = rn(e, l, c, n);
1239
+ g && en(i, m, g), c += d;
1236
1240
  }
1237
1241
  }
1238
1242
  }
1239
- async function Qt(e, t, n) {
1243
+ async function sn(e, t, n) {
1240
1244
  const r = { values: [], seen: /* @__PURE__ */ new Set(), excluded: 0, selected: 0 };
1241
1245
  for (let i = 0; i < e.pages.length; i++) {
1242
- await X(n);
1246
+ await ee(n);
1243
1247
  const o = e.pages[i];
1244
1248
  for (let s = 0; s < o.components.length; s++) {
1245
- await X(n);
1249
+ await ee(n);
1246
1250
  const a = o.components[s];
1247
- if (!a.grid || !Yt(a, i, s, t) || a.table && a.table.role !== "body") continue;
1248
- const l = Xt(a, t);
1249
- l && await Zt(a, l, t, n, r);
1251
+ if (!a.grid || !tn(a, i, s, t) || a.table && a.table.role !== "body") continue;
1252
+ const l = an(a, t);
1253
+ l && await on(a, l, t, n, r);
1250
1254
  }
1251
1255
  }
1252
1256
  return r;
1253
1257
  }
1254
- function W(e) {
1255
- if (!Number.isFinite(e)) throw new w("overflow");
1258
+ function V(e) {
1259
+ if (!Number.isFinite(e)) throw new b("overflow");
1256
1260
  return e;
1257
1261
  }
1258
- function en(e) {
1262
+ function ln(e) {
1259
1263
  let t = 0, n = 0;
1260
1264
  for (const r of e) {
1261
- const i = r - n, o = W(t + i);
1265
+ const i = r - n, o = V(t + i);
1262
1266
  n = o - t - i, t = o;
1263
1267
  }
1264
1268
  return t;
1265
1269
  }
1266
- async function Me(e, t) {
1270
+ async function Se(e, t) {
1267
1271
  let n = [...e], r = new Array(e.length);
1268
1272
  for (let o = 1; o < e.length; o *= 2) {
1269
1273
  for (let s = 0; s < e.length; s += o * 2) {
1270
1274
  const a = Math.min(s + o, e.length), l = Math.min(s + o * 2, e.length);
1271
- let c = s, d = a;
1272
- for (let m = s; m < l; m++)
1273
- r[m] = d >= l || c < a && n[c] <= n[d] ? n[c++] : n[d++], m % 2048 === 0 && (await t.yieldToHost(), z(t.signal));
1275
+ let c = s, m = a;
1276
+ for (let d = s; d < l; d++)
1277
+ r[d] = m >= l || c < a && n[c] <= n[m] ? n[c++] : n[m++], d % 2048 === 0 && (await t.yieldToHost(), _(t.signal));
1274
1278
  }
1275
1279
  [n, r] = [r, n];
1276
1280
  }
1277
1281
  const i = Math.floor(n.length / 2);
1278
- return n.length % 2 ? n[i] : W(n[i - 1] / 2 + n[i] / 2);
1282
+ return n.length % 2 ? n[i] : V(n[i - 1] / 2 + n[i] / 2);
1279
1283
  }
1280
- function tn(e) {
1281
- const t = en(e);
1284
+ function cn(e) {
1285
+ const t = ln(e);
1282
1286
  let n = 1 / 0, r = -1 / 0;
1283
1287
  for (const i of e)
1284
1288
  n = Math.min(n, i), r = Math.max(r, i);
1285
1289
  return { SUM: t, AVERAGE: t / e.length, AVG: t / e.length, MIN: n, MAX: r, COUNT: e.length };
1286
1290
  }
1287
- function nn(e, t) {
1288
- if (typeof e != "string" || e.length > 256) throw new w("expression");
1291
+ function mn(e, t) {
1292
+ if (typeof e != "string" || e.length > 256) throw new b("expression");
1289
1293
  const n = e.toUpperCase().match(/(?:\d+(?:\.\d*)?|\.\d+)(?:E[+-]?\d+)?|[A-Z_]+|[()+\-*/]|\S/g) ?? [];
1290
- if (!n.length || n.length > 64) throw new w("expression");
1294
+ if (!n.length || n.length > 64) throw new b("expression");
1291
1295
  let r = 0;
1292
1296
  function i(a) {
1293
- if (a > 16) throw new w("expression");
1297
+ if (a > 16) throw new b("expression");
1294
1298
  const l = n[r++];
1295
1299
  if (l === "+" || l === "-") return (l === "-" ? -1 : 1) * i(a + 1);
1296
1300
  if (l === "(") {
1297
1301
  const c = o(0, a + 1);
1298
- if (n[r++] !== ")") throw new w("expression");
1302
+ if (n[r++] !== ")") throw new b("expression");
1299
1303
  return c;
1300
1304
  }
1301
- if (l && /^(?:SUM|AVERAGE|AVG|MIN|MAX|COUNT|MEDIAN)$/.test(l) && Object.prototype.hasOwnProperty.call(t, l)) return W(t[l]);
1302
- if (l && /^(?:\d+(?:\.\d*)?|\.\d+)(?:E[+-]?\d+)?$/.test(l)) return W(Number(l));
1303
- throw new w("expression");
1305
+ if (l && /^(?:SUM|AVERAGE|AVG|MIN|MAX|COUNT|MEDIAN)$/.test(l) && Object.prototype.hasOwnProperty.call(t, l)) return V(t[l]);
1306
+ if (l && /^(?:\d+(?:\.\d*)?|\.\d+)(?:E[+-]?\d+)?$/.test(l)) return V(Number(l));
1307
+ throw new b("expression");
1304
1308
  }
1305
1309
  function o(a, l) {
1306
1310
  let c = i(l);
1307
1311
  for (; r < n.length; ) {
1308
- const d = n[r], m = d === "+" || d === "-" ? 1 : d === "*" || d === "/" ? 2 : 0;
1309
- if (!m || m < a) break;
1312
+ const m = n[r], d = m === "+" || m === "-" ? 1 : m === "*" || m === "/" ? 2 : 0;
1313
+ if (!d || d < a) break;
1310
1314
  r++;
1311
- const h = o(m + 1, l + 1);
1312
- if (d === "/" && h === 0) throw new w("division");
1313
- c = W(d === "+" ? c + h : d === "-" ? c - h : d === "*" ? c * h : c / h);
1315
+ const h = o(d + 1, l + 1);
1316
+ if (m === "/" && h === 0) throw new b("division");
1317
+ c = V(m === "+" ? c + h : m === "-" ? c - h : m === "*" ? c * h : c / h);
1314
1318
  }
1315
1319
  return c;
1316
1320
  }
1317
1321
  const s = o(1, 0);
1318
- if (r !== n.length) throw new w("expression");
1322
+ if (r !== n.length) throw new b("expression");
1319
1323
  return s;
1320
1324
  }
1321
- function rn(e) {
1325
+ function dn(e) {
1322
1326
  const t = e.maxCells ?? 1e5, n = e.maxScannedCells ?? 2e5, r = e.precision ?? 2;
1323
- if (![t, n].every((i) => Number.isSafeInteger(i) && i >= 1 && i <= 2e6)) throw new w("limit");
1324
- if (!Number.isInteger(r) || r < 0 || r > 12) throw new w("precision");
1327
+ if (![t, n].every((i) => Number.isSafeInteger(i) && i >= 1 && i <= 2e6)) throw new b("limit");
1328
+ if (!Number.isInteger(r) || r < 0 || r > 12) throw new b("precision");
1325
1329
  return { maxCells: t, maxScanned: n, precision: r };
1326
1330
  }
1327
- async function Fn(e, t, n = {}) {
1328
- const r = rn(n), i = { scanned: 0, maxScanned: r.maxScanned, signal: n.signal, yieldToHost: n.yieldToHost ?? (() => new Promise((l) => setTimeout(l, 0))) };
1329
- z(i.signal);
1330
- const o = await Qt(e, Gt(e, t, r.maxCells), i), s = n.operation ?? "sum";
1331
- if (!["sum", "average", "min", "max", "count", "median", "expression"].includes(s)) throw new w("expression");
1331
+ async function qn(e, t, n = {}) {
1332
+ const r = dn(n), i = { scanned: 0, maxScanned: r.maxScanned, signal: n.signal, yieldToHost: n.yieldToHost ?? (() => new Promise((l) => setTimeout(l, 0))) };
1333
+ _(i.signal);
1334
+ const o = await sn(e, Xt(e, t, r.maxCells), i), s = n.operation ?? "sum";
1335
+ if (!["sum", "average", "min", "max", "count", "median", "expression"].includes(s)) throw new b("expression");
1332
1336
  let a = null;
1333
1337
  if (s === "count") a = o.values.length;
1334
1338
  else if (o.values.length)
1335
- if (s === "median") a = await Me(o.values, i);
1339
+ if (s === "median") a = await Se(o.values, i);
1336
1340
  else {
1337
- const l = tn(o.values);
1338
- s === "expression" ? (/\bMEDIAN\b/i.test(n.expression ?? "") && (l.MEDIAN = await Me(o.values, i)), a = nn(n.expression ?? "", l)) : a = l[s.toUpperCase()];
1341
+ const l = cn(o.values);
1342
+ s === "expression" ? (/\bMEDIAN\b/i.test(n.expression ?? "") && (l.MEDIAN = await Se(o.values, i)), a = mn(n.expression ?? "", l)) : a = l[s.toUpperCase()];
1339
1343
  }
1340
- if (z(i.signal), a !== null && Number.isInteger(a) && !Number.isSafeInteger(a)) throw new w("precision");
1344
+ if (_(i.signal), a !== null && Number.isInteger(a) && !Number.isSafeInteger(a)) throw new b("precision");
1341
1345
  return { value: a, formatted: a === null ? "—" : a.toFixed(r.precision), numericCells: o.values.length, excludedCells: o.excluded, selectedCells: o.selected, precision: r.precision };
1342
1346
  }
1347
+ class A extends Error {
1348
+ constructor(t, n) {
1349
+ super(t), this.path = n, this.code = "label-sheet", this.name = "LabelSheetError";
1350
+ }
1351
+ }
1352
+ function X(e) {
1353
+ if (e?.aborted) {
1354
+ const t = new Error("标签拼版已取消");
1355
+ throw t.name = "AbortError", t;
1356
+ }
1357
+ }
1358
+ function H(e, t, n = !1) {
1359
+ if (!Number.isFinite(e) || e <= 0 || n && !Number.isSafeInteger(e)) throw new A("应为正有限数字,数量应为安全整数", t);
1360
+ return e;
1361
+ }
1362
+ function Te(e, t) {
1363
+ if (!Number.isFinite(e) || e < 0) throw new A("应为非负有限数字", t);
1364
+ return e;
1365
+ }
1366
+ function hn(e) {
1367
+ const t = typeof e.marginMm == "object" ? e.marginMm : { top: e.marginMm ?? 0, left: e.marginMm ?? 0, bottom: e.marginMm ?? 0, right: e.marginMm ?? 0 }, n = typeof e.gapMm == "object" ? e.gapMm : { horizontal: e.gapMm ?? 0, vertical: e.gapMm ?? 0 };
1368
+ for (const r of ["top", "left", "bottom", "right"]) Te(t?.[r], `$.marginMm.${r}`);
1369
+ for (const r of ["horizontal", "vertical"]) Te(n?.[r], `$.gapMm.${r}`);
1370
+ return { margin: t, gap: n };
1371
+ }
1372
+ function gn(e) {
1373
+ const t = e.paper === void 0 || e.paper === "a4" ? { widthMm: 210, heightMm: 297 } : e.paper;
1374
+ H(t.widthMm, "$.paper.widthMm"), H(t.heightMm, "$.paper.heightMm");
1375
+ const n = H(e.columns, "$.columns", !0), r = H(e.rows, "$.rows", !0), i = n * r;
1376
+ if (i > 1e3) throw new A("每张纸不能超过 1000 个位置", "$.columns");
1377
+ const { margin: o, gap: s } = hn(e), a = e.startSlot ?? 0, l = e.offsetMm ?? { x: 0, y: 0 };
1378
+ if (!Number.isSafeInteger(a) || a < 0 || a >= i) throw new A("起始位置应在首张纸的有效位置内", "$.startSlot");
1379
+ if (!Number.isFinite(l.x) || !Number.isFinite(l.y)) throw new A("校准偏移应为有限毫米值", "$.offsetMm");
1380
+ return { paper: t, columns: n, rows: r, capacity: i, margin: o, gap: s, startSlot: a, offset: l };
1381
+ }
1382
+ function Ve(e) {
1383
+ return 1 + (e.grid?.cells.reduce((t, n) => t + n.length + 1 + n.reduce((r, i) => r + (i?.children?.reduce((o, s) => o + Ve(s), 0) ?? 0), 0), 0) ?? 0);
1384
+ }
1385
+ function fn(e, t, n) {
1386
+ if (!Xe(e).ok) throw new A("标签计划无效", "$.plan");
1387
+ const r = e.pages[0];
1388
+ if (!r) return;
1389
+ const { paper: i, columns: o, rows: s, margin: a, gap: l, offset: c } = n;
1390
+ if (a.left + c.x < 0 || a.top + c.y < 0 || a.left + c.x + o * r.pageWidthMm + (o - 1) * l.horizontal + a.right > i.widthMm + 1e-6 || a.top + c.y + s * r.pageHeightMm + (s - 1) * l.vertical + a.bottom > i.heightMm + 1e-6) throw new A("标签、间距、边距及校准偏移超过纸张尺寸;不会自动缩小标签", "$.paper");
1391
+ let m = 0;
1392
+ for (const [d, h] of e.pages.entries()) {
1393
+ if (X(t.signal), h.layout === "wide" || h.pageWidthMm !== r.pageWidthMm || h.pageHeightMm !== r.pageHeightMm) throw new A("拼版需要尺寸相同的固定标签页面", `$.pages.${d}`);
1394
+ if (m += h.components.reduce((g, f) => g + Ve(f), 0), m > H(t.maxComponents ?? 25e4, "$.maxComponents", !0)) throw new A("拼版组件总量超过预算", "$.maxComponents");
1395
+ for (const g of h.components) if (g.leftMm < 0 || g.topMm < 0 || g.leftMm + g.widthMm > h.pageWidthMm + 1e-6 || g.topMm + g.heightMm > h.pageHeightMm + 1e-6) throw new A("标签内容超出标签边界", `$.pages.${d}.components`);
1396
+ }
1397
+ }
1398
+ function Jn(e, t) {
1399
+ X(t.signal);
1400
+ const n = gn(t), { paper: r, columns: i, capacity: o, margin: s, gap: a, startSlot: l, offset: c } = n, m = e.pages.length ? Math.ceil((l + e.pages.length) / o) : 0;
1401
+ if (m > H(t.maxSheets ?? 1e4, "$.maxSheets", !0)) throw new A("拼版纸张数量超过预算", "$.maxSheets");
1402
+ H(t.maxComponents ?? 25e4, "$.maxComponents", !0), fn(e, t, n);
1403
+ const d = nt(e, { maxBytes: H(t.maxSnapshotBytes ?? 64e6, "$.maxSnapshotBytes", !0), check: () => X(t.signal), error: (g, f) => new A(f, "$.maxSnapshotBytes") }), h = Array.from({ length: m }, () => ({ pageWidthMm: r.widthMm, pageHeightMm: r.heightMm, components: [], meta: { labelSheet: { columns: i, rows: n.rows, slots: [] } } }));
1404
+ for (const [g, f] of d.pages.entries()) {
1405
+ X(t.signal);
1406
+ const w = l + g, C = w % o, x = h[Math.floor(w / o)], M = s.left + c.x + C % i * (f.pageWidthMm + a.horizontal), R = s.top + c.y + Math.floor(C / i) * (f.pageHeightMm + a.vertical), z = { sourcePageIndex: g, slotIndex: C, xMm: M, yMm: R, widthMm: f.pageWidthMm, heightMm: f.pageHeightMm, ...f.meta ? { sourceMeta: f.meta } : {} };
1407
+ x.meta.labelSheet.slots.push(z), x.components.push(...f.components.map((L) => ({ ...L, leftMm: L.leftMm + M, topMm: L.topMm + R, meta: { ...L.meta, labelSheet: z } })));
1408
+ }
1409
+ return { ...d, pages: h };
1410
+ }
1343
1411
  export {
1344
- Qn as CSS_DPI,
1345
- Hn as DEFAULT_BORDER_PT,
1346
- Z as DEFAULT_FONT_FAMILY,
1347
- _n as DEFAULT_FONT_PT,
1348
- br as DEFAULT_LABEL_PAGE_LIMIT,
1349
- Bn as DEFAULT_STROKE_COLOR,
1350
- xe as DEFAULT_TEXT_COLOR,
1351
- jn as LINE_HEIGHT,
1352
- er as MM_PER_INCH,
1353
- gr as OutputAssetError,
1354
- Ke as OutputFidelityError,
1355
- J as PAPER_SIZES,
1356
- Tt as PageBuilder,
1357
- yr as PaginateCellLimitError,
1358
- Mr as PaginatePageLimitError,
1359
- ir as RENDER_PLAN_SCHEMA_VERSION,
1360
- qr as REPORT_TEMPLATE_DOCUMENT_VERSION,
1361
- Un as ReportBindingError,
1362
- w as ReportCalculationError,
1363
- Ye as ReportCellEditError,
1364
- Dt as ReportCellFieldError,
1365
- Qr as ReportParamValidationError,
1366
- se as ReportSourceError,
1367
- Ne as ReportTemplateError,
1368
- L as ReportTemplateStoreError,
1369
- Wn as SCHEMA_VERSION_MACH,
1370
- Et as TemplateBuilder,
1371
- di as TreeRowLimitError,
1372
- xr as applyReportCellEdit,
1373
- Er as applyReportCellEditBatch,
1374
- Tr as applyReportEditResult,
1375
- ar as assertRenderPlan,
1376
- ei as assertReportParams,
1377
- Fn as calculateReportSelection,
1378
- ur as charWidthEm,
1379
- E as classOf,
1380
- In as cloneReportTemplate,
1381
- Tn as columnsFromContract,
1382
- ft as computePageWindow,
1383
- Sr as countTemplatePages,
1384
- fr as createCanvasMeasurer,
1385
- xn as createCanvasPager,
1386
- pr as createHeuristicMeasurer,
1387
- Cn as createLabelTemplate,
1388
- Nn as createLocalTemplateCatalog,
1389
- kn as createMemoryTemplateStore,
1390
- Pn as createProviderReport,
1391
- Cr as createReportCellEdit,
1392
- Rr as createReportCellEditBatch,
1393
- Pr as createReportCellResolver,
1394
- Ar as createReportEditSession,
1395
- kr as createReportSource,
1396
- Sn as createTableTemplate,
1397
- En as createTemplate,
1398
- An as createTemplateManager,
1399
- Yr as createTemplateRegistry,
1400
- mi as createTreeTable,
1401
- mr as datasetJsonSchema,
1402
- Rn as defineLabelReport,
1403
- qe as defineReport,
1404
- Jr as defineReportTemplate,
1405
- Ir as diffReportTemplates,
1406
- Nr as estimateListLayoutCells,
1407
- Vn as evalStyleRule,
1408
- nn as evaluateReportAggregateExpression,
1409
- $r as formatReportCellEdit,
1410
- $n as formatReportClipboard,
1411
- ti as formatReportDateRange,
1412
- qn as formatValue,
1413
- Lr as getReportCellContext,
1414
- Dr as getReportEditSession,
1415
- oe as heuristicMeasurer,
1416
- Ur as inspectOutputCapabilities,
1417
- ee as isImageBackedComponent,
1418
- ni as isReportDate,
1419
- ri as isReportMonth,
1420
- ii as isReportYear,
1421
- Ce as isRichText,
1422
- ce as measurePageSizePx,
1423
- wr as measureTextMm,
1424
- Te as mergeComponentStyles,
1425
- ie as mmToPx,
1426
- tr as mmToPxFactor,
1427
- Fr as paginateTemplate,
1428
- Or as paginateTemplatePages,
1429
- Yn as parseDateLocal,
1430
- Dn as parseReportCellFieldInput,
1431
- Je as parseReportCellInput,
1432
- Ln as parseReportClipboard,
1433
- oi as parseReportDateRange,
1434
- I as parseReportTemplate,
1435
- vn as planFontSizePx,
1436
- zr as projectListColumns,
1437
- O as ptToPx,
1438
- nr as pxToMm,
1439
- Hr as registerReportEditSession,
1440
- _r as relocateReportCellEdits,
1441
- Le as renderComponent,
1442
- dt as renderPage,
1443
- wn as renderPlan,
1444
- yn as renderPlanToCanvas,
1445
- Mn as renderPlanToCanvasAsync,
1446
- bn as renderPlanToImages,
1447
- Br as reportCellEditKey,
1448
- G as reportOutputDiagnostics,
1449
- ai as reportParamsJsonSchema,
1450
- Ee as resolveBoxBorders,
1451
- Jn as resolveComponentBinding,
1452
- _ as resolveFontSize,
1453
- Pe as resolveGridLayout,
1454
- Q as resolveLineHeight,
1455
- _e as resolvePaper,
1456
- ae as resolvePlanAssets,
1457
- j as resolveStroke,
1458
- Se as resolveTextColor,
1459
- jr as reviewReportTemplate,
1460
- H as round,
1461
- Kr as serializeReportTemplate,
1462
- Wr as summarizeReportCellEdits,
1463
- Kn as toExcelNumberFormat,
1464
- Xn as toNumber,
1465
- sr as validateComponent,
1466
- Ve as validateDatasetRows,
1467
- lr as validatePage,
1468
- cr as validateRenderPlan,
1469
- Wt as validateReportCellFieldDefinition,
1470
- si as validateReportParamDefinitions,
1471
- li as validateReportParams,
1472
- Ie as validateReportTemplate,
1473
- Xr as validateReportTemplateDocument,
1474
- hi as validateTreeOptions,
1475
- Re as wrapText
1412
+ dr as CSS_DPI,
1413
+ Xn as DEFAULT_BORDER_PT,
1414
+ te as DEFAULT_FONT_FAMILY,
1415
+ Zn as DEFAULT_FONT_PT,
1416
+ $r as DEFAULT_LABEL_PAGE_LIMIT,
1417
+ Qn as DEFAULT_STROKE_COLOR,
1418
+ Ce as DEFAULT_TEXT_COLOR,
1419
+ er as LINE_HEIGHT,
1420
+ A as LabelSheetError,
1421
+ hr as MM_PER_INCH,
1422
+ Sr as OutputAssetError,
1423
+ rt as OutputFidelityError,
1424
+ Z as PAPER_SIZES,
1425
+ kt as PageBuilder,
1426
+ kr as PaginateCellLimitError,
1427
+ Ir as PaginatePageLimitError,
1428
+ pr as RENDER_PLAN_SCHEMA_VERSION,
1429
+ ai as REPORT_TEMPLATE_DOCUMENT_VERSION,
1430
+ rr as ReportBindingError,
1431
+ b as ReportCalculationError,
1432
+ et as ReportCellEditError,
1433
+ _t as ReportCellFieldError,
1434
+ di as ReportParamValidationError,
1435
+ me as ReportSourceError,
1436
+ Fe as ReportTemplateError,
1437
+ F as ReportTemplateStoreError,
1438
+ tr as SCHEMA_VERSION_MACH,
1439
+ $t as TemplateBuilder,
1440
+ Di as TreeRowLimitError,
1441
+ Nr as applyReportCellEdit,
1442
+ Lr as applyReportCellEditBatch,
1443
+ $i as applyReportDocumentStyle,
1444
+ Dr as applyReportEditResult,
1445
+ br as assertRenderPlan,
1446
+ hi as assertReportParams,
1447
+ qn as calculateReportSelection,
1448
+ ki as captureTemplateFragment,
1449
+ Tr as charWidthEm,
1450
+ T as classOf,
1451
+ _n as cloneReportTemplate,
1452
+ Ci as collectTemplateOutline,
1453
+ Dn as columnsFromContract,
1454
+ xt as computePageWindow,
1455
+ Fr as countTemplatePages,
1456
+ Cr as createCanvasMeasurer,
1457
+ Nn as createCanvasPager,
1458
+ Rr as createHeuristicMeasurer,
1459
+ On as createLabelTemplate,
1460
+ jn as createLocalTemplateCatalog,
1461
+ Wn as createMemoryTemplateStore,
1462
+ zn as createProviderReport,
1463
+ Or as createReportCellEdit,
1464
+ Hr as createReportCellEditBatch,
1465
+ zr as createReportCellResolver,
1466
+ Br as createReportEditSession,
1467
+ Wr as createReportSource,
1468
+ Fn as createTableTemplate,
1469
+ Ln as createTemplate,
1470
+ Bn as createTemplateManager,
1471
+ oi as createTemplateRegistry,
1472
+ Fi as createTreeTable,
1473
+ xr as datasetJsonSchema,
1474
+ Hn as defineLabelReport,
1475
+ Qe as defineReport,
1476
+ si as defineReportTemplate,
1477
+ _r as diffReportTemplates,
1478
+ jr as estimateListLayoutCells,
1479
+ ir as evalStyleRule,
1480
+ mn as evaluateReportAggregateExpression,
1481
+ Ur as formatReportCellEdit,
1482
+ Un as formatReportClipboard,
1483
+ gi as formatReportDateRange,
1484
+ ar as formatValue,
1485
+ Gr as getReportCellContext,
1486
+ Vr as getReportEditSession,
1487
+ xi as hasValidDataExplanation,
1488
+ le as heuristicMeasurer,
1489
+ Jn as imposeLabelSheets,
1490
+ Ii as insertTemplateFragment,
1491
+ ri as inspectOutputCapabilities,
1492
+ Ri as inspectTemplateFieldUsage,
1493
+ Ni as inspectTemplateFragmentBindings,
1494
+ re as isImageBackedComponent,
1495
+ Ei as isReportDataTarget,
1496
+ fi as isReportDate,
1497
+ ui as isReportMonth,
1498
+ Si as isReportValueState,
1499
+ pi as isReportYear,
1500
+ $e as isRichText,
1501
+ he as measurePageSizePx,
1502
+ Pr as measureTextMm,
1503
+ Pe as mergeComponentStyles,
1504
+ se as mmToPx,
1505
+ gr as mmToPxFactor,
1506
+ qr as paginateTemplate,
1507
+ Jr as paginateTemplatePages,
1508
+ or as parseDateLocal,
1509
+ Vn as parseReportCellFieldInput,
1510
+ tt as parseReportCellInput,
1511
+ Gn as parseReportClipboard,
1512
+ wi as parseReportDateRange,
1513
+ N as parseReportTemplate,
1514
+ An as planFontSizePx,
1515
+ Yr as projectListColumns,
1516
+ W as ptToPx,
1517
+ fr as pxToMm,
1518
+ Kr as registerReportEditSession,
1519
+ Xr as relocateReportCellEdits,
1520
+ He as renderComponent,
1521
+ wt as renderPage,
1522
+ Pn as renderPlan,
1523
+ kn as renderPlanToCanvas,
1524
+ In as renderPlanToCanvasAsync,
1525
+ $n as renderPlanToImages,
1526
+ Zr as reportCellEditKey,
1527
+ q as reportOutputDiagnostics,
1528
+ bi as reportParamsJsonSchema,
1529
+ Re as resolveBoxBorders,
1530
+ sr as resolveComponentBinding,
1531
+ U as resolveFontSize,
1532
+ Ie as resolveGridLayout,
1533
+ ne as resolveLineHeight,
1534
+ Ue as resolvePaper,
1535
+ ce as resolvePlanAssets,
1536
+ G as resolveStroke,
1537
+ Ae as resolveTextColor,
1538
+ Qr as reviewReportTemplate,
1539
+ ei as reviewReportTemplateAsync,
1540
+ j as round,
1541
+ li as serializeReportTemplate,
1542
+ ti as summarizeReportCellEdits,
1543
+ Pi as templatePathLocation,
1544
+ lr as toExcelNumberFormat,
1545
+ cr as toNumber,
1546
+ yr as validateComponent,
1547
+ Ze as validateDatasetRows,
1548
+ vr as validatePage,
1549
+ Xe as validateRenderPlan,
1550
+ Kt as validateReportCellFieldDefinition,
1551
+ yi as validateReportParamDefinitions,
1552
+ vi as validateReportParams,
1553
+ De as validateReportTemplate,
1554
+ ci as validateReportTemplateDocument,
1555
+ Oi as validateTreeOptions,
1556
+ ke as wrapText
1476
1557
  };