@agile-team/mach-report 2.12.0 → 2.14.0

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