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