@agile-team/mach-report 2.15.0 → 2.17.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 (171) hide show
  1. package/README.md +21 -12
  2. package/dist/{ExcelBindingWizard-Bs43BGNp.cjs → ExcelBindingWizard-Bq6FYME6.cjs} +1 -1
  3. package/dist/{ExcelBindingWizard-BKH1nGNS.js → ExcelBindingWizard-Co1svTsw.js} +3 -3
  4. package/dist/{ParamEditor-Da4akw6V.cjs → ParamEditor-B5UZRgxv.cjs} +1 -1
  5. package/dist/{ParamEditor-DoAhzJsm.js → ParamEditor-DNNARyeB.js} +1 -1
  6. package/dist/{ReportBatchPanel-wP9m9Pj1.cjs → ReportBatchPanel-Ctvs2t_9.cjs} +1 -1
  7. package/dist/{ReportBatchPanel-BMf6boMA.js → ReportBatchPanel-uQh06usx.js} +3 -3
  8. package/dist/ReportPreview-BdQawRh0.js +4879 -0
  9. package/dist/ReportPreview-CJC_-j2I.cjs +6 -0
  10. package/dist/{ReportTemplateLibrary-Sxr3eD0J.cjs → ReportTemplateLibrary-CnP7_1pH.cjs} +1 -1
  11. package/dist/{ReportTemplateLibrary-C9wutIiT.js → ReportTemplateLibrary-TIL_Oj2l.js} +1 -1
  12. package/dist/RuleEditor-DkRjOLlr.js +2141 -0
  13. package/dist/RuleEditor-h5anGsDB.cjs +1 -0
  14. package/dist/{TemplateOutlinePanel-JTSR53vJ.cjs → TemplateOutlinePanel-BlLxRrfu.cjs} +1 -1
  15. package/dist/{TemplateOutlinePanel-D6Bkny59.js → TemplateOutlinePanel-BouxsuqQ.js} +1 -1
  16. package/dist/{TemplateReusePanel-rVuK1kTz.js → TemplateReusePanel-BEACLPaN.js} +2 -2
  17. package/dist/{TemplateReusePanel-Kx35S0Ql.cjs → TemplateReusePanel-yxsHSO40.cjs} +1 -1
  18. package/dist/{TemplateReviewPanel-B0ar9_zf.js → TemplateReviewPanel-B1OGRY2i.js} +1 -1
  19. package/dist/{TemplateReviewPanel-Dn6X9UmY.cjs → TemplateReviewPanel-D9Cx0m2N.cjs} +1 -1
  20. package/dist/analytics.cjs +1 -1
  21. package/dist/analytics.d.cts +65 -1
  22. package/dist/analytics.d.ts +65 -1
  23. package/dist/analytics.js +4 -4
  24. package/dist/artifact-integrity.json +105 -101
  25. package/dist/assets-BIMVwjQe.js +231 -0
  26. package/dist/assets-Dfs2ElxI.cjs +1 -0
  27. package/dist/auto-BIOmtVhk.js +240 -0
  28. package/dist/auto-DDHflI9v.cjs +1 -0
  29. package/dist/{batch-BfZHN1do.js → batch-WzDIXJAt.js} +1 -1
  30. package/dist/{batch-CLpELXBl.cjs → batch-z6Aw5GEY.cjs} +1 -1
  31. package/dist/codes.d.cts +2 -0
  32. package/dist/codes.d.ts +2 -0
  33. package/dist/component-tree-Ca6YYfHq.js +61 -0
  34. package/dist/component-tree-DkGLEfZC.cjs +1 -0
  35. package/dist/computed-BW5a8QFk.js +612 -0
  36. package/dist/computed-C2GD3XcE.cjs +1 -0
  37. package/dist/config-Dg_o8e7m.cjs +1 -0
  38. package/dist/{config-BVsJXSqS.js → config-XQ4qrQ7Q.js} +66 -64
  39. package/dist/dataset-DL83majE.js +161 -0
  40. package/dist/dataset-IrlXbUvh.cjs +1 -0
  41. package/dist/designer-D9XAxqSc.js +5178 -0
  42. package/dist/designer-uCDo5XSK.cjs +2 -0
  43. package/dist/designer.cjs +1 -1
  44. package/dist/designer.d.cts +178 -3
  45. package/dist/designer.d.ts +178 -3
  46. package/dist/designer.js +1 -1
  47. package/dist/drill-ByN8COs_.cjs +1 -0
  48. package/dist/{drill-ByJviLXS.js → drill-CKW3Xtfa.js} +5 -5
  49. package/dist/encoding-BFMFIc4r.cjs +1 -0
  50. package/dist/encoding-DP_Eaf0A.js +21 -0
  51. package/dist/{font-loader-B_UkxpzC.cjs → font-loader-7FWVlykp.cjs} +1 -1
  52. package/dist/{font-loader-Q3bQjmrI.js → font-loader-CQZowp0I.js} +1 -1
  53. package/dist/index.cjs +8 -9
  54. package/dist/index.d.cts +175 -1
  55. package/dist/index.d.ts +175 -1
  56. package/dist/index.js +1343 -915
  57. package/dist/json-snapshot-D7PE1NsU.cjs +2 -0
  58. package/dist/json-snapshot-DYmEe3sO.js +1779 -0
  59. package/dist/matrix-JLAXlux-.js +302 -0
  60. package/dist/matrix-gTHpDTGm.cjs +1 -0
  61. package/dist/{pdf-CvvrjPQg.cjs → pdf-B8JouyYv.cjs} +48 -50
  62. package/dist/{pdf-BwNyeGpt.js → pdf-l3ea86di.js} +2734 -2748
  63. package/dist/pdf.cjs +1 -1
  64. package/dist/pdf.d.cts +14 -0
  65. package/dist/pdf.d.ts +14 -0
  66. package/dist/pdf.js +2 -2
  67. package/dist/{plugin-Ca_XZG3l.js → plugin-BBp74CQZ.js} +1 -1
  68. package/dist/{plugin-DHO7X8z2.cjs → plugin-CtFX9PFG.cjs} +1 -1
  69. package/dist/prepared-CARicKYh.js +87 -0
  70. package/dist/prepared-Ch1x_Gog.cjs +1 -0
  71. package/dist/progress-BXzlVbIp.js +29 -0
  72. package/dist/progress-DJBd9Rb9.cjs +1 -0
  73. package/dist/{progress-D-OTpEav.js → progress-Hc2vxoCs.js} +2 -2
  74. package/dist/protocol-B5A2uom4.cjs +1 -0
  75. package/dist/protocol-BaiWjq5w.js +90 -0
  76. package/dist/record-bindings-B86Sur_y.cjs +1 -0
  77. package/dist/{record-bindings-Do_b3h4V.js → record-bindings-D4TuMzHs.js} +10 -11
  78. package/dist/{region-binding-workflow-BMhK_TjP.js → region-binding-workflow-BNasF5kz.js} +2 -2
  79. package/dist/{region-binding-workflow-DIYJdCUr.cjs → region-binding-workflow-O2Cni3mF.cjs} +1 -1
  80. package/dist/report-encoding-worker.cjs +1 -0
  81. package/dist/report-encoding-worker.d.ts +1 -0
  82. package/dist/report-encoding-worker.js +2 -0
  83. package/dist/rich-text-layout-ALlMoYOG.cjs +3 -0
  84. package/dist/rich-text-layout-Ct5WrY1g.js +102 -0
  85. package/dist/runtime-DakRXui3.js +170 -0
  86. package/dist/runtime-dL5ygIfa.cjs +1 -0
  87. package/dist/sbom.cdx.json +2 -2
  88. package/dist/server/node.d.cts +132 -1
  89. package/dist/server/node.d.ts +132 -1
  90. package/dist/server-node.cjs +5 -1
  91. package/dist/server-node.js +5177 -463
  92. package/dist/server.cjs +1 -1
  93. package/dist/server.d.cts +182 -2
  94. package/dist/server.d.ts +182 -2
  95. package/dist/server.js +918 -833
  96. package/dist/sha256-BshdOkCC.cjs +1 -0
  97. package/dist/sha256-DTG-Gq8i.js +157 -0
  98. package/dist/style-67OqfNed.js +73 -0
  99. package/dist/style-C22Pbv3T.cjs +1 -0
  100. package/dist/style.css +1 -1
  101. package/dist/template-catalog-Dua8h9ZA.cjs +1 -0
  102. package/dist/{template-catalog-j2B1MJlL.js → template-catalog-wT1fNeAP.js} +10 -10
  103. package/dist/{template-fragments-DcKeiylI.cjs → template-fragments-BajTajb4.cjs} +1 -1
  104. package/dist/{template-fragments-BGbQLGlV.js → template-fragments-DmX5XK4N.js} +2 -2
  105. package/dist/template-registry-CpysHAxy.cjs +1 -0
  106. package/dist/{template-registry-BtaKPELV.js → template-registry-u11fPd8D.js} +389 -321
  107. package/dist/{textwrap-DE1kgcJB.js → textwrap-BEIg2w8y.js} +1 -1
  108. package/dist/textwrap-BI-yJ6Wt.cjs +4 -0
  109. package/dist/{tree-BX380Rr7.cjs → tree-CLpxYbKa.cjs} +1 -1
  110. package/dist/{tree-CjVZLRw7.js → tree-DNJorJUf.js} +1 -1
  111. package/dist/vue/async.d.cts +174 -2
  112. package/dist/vue/async.d.ts +174 -2
  113. package/dist/vue/index.d.cts +218 -3
  114. package/dist/vue/index.d.ts +218 -3
  115. package/dist/vue-async.cjs +1 -1
  116. package/dist/vue-async.js +3 -3
  117. package/dist/vue.cjs +1 -1
  118. package/dist/vue.js +7 -7
  119. package/dist/{workbook-session-BvToI-Fd.js → workbook-session-B8pNW24X.js} +153 -140
  120. package/dist/{workbook-session-Bjv1YCRK.cjs → workbook-session-DN5LSA5C.cjs} +12 -12
  121. package/dist/worker.cjs +1 -1
  122. package/dist/worker.d.cts +84 -1
  123. package/dist/worker.d.ts +84 -1
  124. package/dist/worker.js +12 -157
  125. package/dist/xlsx-node.cjs +33 -33
  126. package/dist/xlsx-node.js +1282 -1289
  127. package/dist/xlsx.cjs +4 -3
  128. package/dist/xlsx.d.cts +90 -2
  129. package/dist/xlsx.d.ts +90 -2
  130. package/dist/xlsx.js +279 -259
  131. package/package.json +6 -3
  132. package/dist/ReportPreview-ChV19HBp.js +0 -4619
  133. package/dist/ReportPreview-DbLvvOUT.cjs +0 -6
  134. package/dist/RuleEditor-C_Clasvd.js +0 -2037
  135. package/dist/RuleEditor-XhGHK8DE.cjs +0 -1
  136. package/dist/assets-B9ImAi6_.cjs +0 -1
  137. package/dist/assets-DEaz4qsp.js +0 -124
  138. package/dist/batch-BaP6pWDE.cjs +0 -1
  139. package/dist/batch-CGyt-b2W.js +0 -273
  140. package/dist/capabilities-CAh2Nrue.cjs +0 -1
  141. package/dist/capabilities-DskCHs3V.js +0 -69
  142. package/dist/computed-C-4C2S5h.js +0 -521
  143. package/dist/computed-CGV2a809.cjs +0 -1
  144. package/dist/config-D10us76d.cjs +0 -1
  145. package/dist/data-explanation-B8MZRYVS.js +0 -16
  146. package/dist/data-explanation-DE55G30w.cjs +0 -1
  147. package/dist/dataset-BkRmwgeJ.cjs +0 -1
  148. package/dist/dataset-H5pFuQGU.js +0 -121
  149. package/dist/defaults-DXhiM1ZD.js +0 -10
  150. package/dist/defaults-xhmcLLrf.cjs +0 -1
  151. package/dist/designer-2bDlcNXQ.js +0 -5136
  152. package/dist/designer-BT7XCdbW.cjs +0 -2
  153. package/dist/drill-DYTxuL3A.cjs +0 -1
  154. package/dist/grid-strokes-Cr7DwUux.cjs +0 -1
  155. package/dist/grid-strokes-DyyG1q_o.js +0 -53
  156. package/dist/json-snapshot-DFb2eWkf.js +0 -1416
  157. package/dist/json-snapshot-WWSGlaHG.cjs +0 -2
  158. package/dist/matrix-CGRGkn5s.js +0 -112
  159. package/dist/matrix-gEO7ZM_u.cjs +0 -1
  160. package/dist/prepared-CFy9B75C.cjs +0 -1
  161. package/dist/prepared-ajM-H-9B.js +0 -69
  162. package/dist/record-bindings-By_UKZ2g.cjs +0 -1
  163. package/dist/render-plan-7xpGrCEl.cjs +0 -1
  164. package/dist/render-plan-Ck6koX9L.js +0 -13
  165. package/dist/sha256-ArEYjaTI.cjs +0 -1
  166. package/dist/sha256-DPEuJ3nh.js +0 -155
  167. package/dist/style-CQ1PK8ZB.js +0 -67
  168. package/dist/style-UgIJSA1F.cjs +0 -1
  169. package/dist/template-catalog-FJE_c9Qe.cjs +0 -1
  170. package/dist/template-registry-Co1zPq5e.cjs +0 -1
  171. package/dist/textwrap-CWHyzkBH.cjs +0 -4
@@ -1,69 +0,0 @@
1
- import { a as h, b as D } from "./progress-D-OTpEav.js";
2
- import { a as x, i as O } from "./render-plan-Ck6koX9L.js";
3
- function b(s, e) {
4
- h(e.signal), D(() => e.onDiagnostic?.(s)), h(e.signal);
5
- }
6
- class E extends Error {
7
- constructor(e) {
8
- super(`Output contains ${e.length} known fidelity issue(s): ${e[0]?.code}`), this.diagnostics = e, this.code = "output-fidelity", this.name = "OutputFidelityError";
9
- }
10
- }
11
- const $ = /* @__PURE__ */ new Set(["text", "rect", "line", "ellipse"]), M = /* @__PURE__ */ new Set(["image", "chart", "barcode", "qrcode"]);
12
- function C(s, e) {
13
- if (!s.grid) {
14
- if (O(s))
15
- return (e === "pdf" || e === "xlsx") && !/^data:image\/(png|jpe?g);base64,/i.test(s.imageData) ? { code: "unsupported-image-format", message: `${e.toUpperCase()} accepts PNG or JPEG data URLs; convert this image before exporting.` } : void 0;
16
- if (M.has(s.kind)) return { code: "missing-image", message: `${s.kind} requires imageData or a renderer adapter before output.` };
17
- if (!$.has(s.kind)) return { code: "unsupported-component", message: `Unsupported component kind: ${s.kind}.` };
18
- if (e === "xlsx" && s.kind !== "text") return { code: "unsupported-component", message: `XLSX data export omits ${s.kind} geometry.` };
19
- }
20
- }
21
- function u(s, e, t, i, r) {
22
- return { ...r, severity: "warning", format: e, pageIndex: t, componentIndex: i, kind: s.kind, nid: s.nid };
23
- }
24
- function l(s, e) {
25
- if (!s || e === "dom") return;
26
- const t = [];
27
- return s.rotateDeg && t.push("rotateDeg"), s.opacity !== void 0 && s.opacity !== 1 && t.push("opacity"), e !== "xlsx" && s.align === "justify" && t.push("justify"), e === "canvas" && s.underline && t.push("underline"), e === "xlsx" && s.letterSpacing && t.push("letterSpacing"), t.length ? `${e} does not preserve these styles: ${t.join(", ")}.` : void 0;
28
- }
29
- function R(s, e, t, i, r) {
30
- for (const n of s.richParagraphs ?? []) {
31
- e === "xlsx" && (n.spaceBeforeMm || n.spaceAfterMm || n.indentMm || n.align || n.lineHeight) && r.push(u(s, e, t, i, { code: "unsupported-style", message: "XLSX rich text preserves fonts and paragraph newlines; paragraph spacing, indentation and alignment are not retained." }));
32
- const a = l({ align: n.align }, e);
33
- a && r.push(u(s, e, t, i, { code: "unsupported-style", message: a }));
34
- for (const d of n.segments) {
35
- const o = l(d.style, e) ?? (e !== "dom" && d.style?.backgroundColor ? "Inline background colors are not preserved in this output." : void 0);
36
- o && r.push(u(s, e, t, i, { code: "unsupported-style", message: o }));
37
- }
38
- }
39
- }
40
- function v(s, e, t, i, r, n, a) {
41
- if (a.has(s)) return;
42
- const d = new Set(a).add(s), o = C(s, e);
43
- o && n.push({ ...u(s, e, t, i, o), componentPath: r });
44
- const f = l(s.style, e);
45
- f && n.push({ ...u(s, e, t, i, { code: "unsupported-style", message: f }), componentPath: r }), x(s) && e === "canvas" && n.push(u(s, e, t, i, { code: "rich-text-flattened", message: "Rich text is exported as plain text; inline styles are not preserved." })), R(s, e, t, i, n);
46
- for (const [c, k] of (s.grid?.cells ?? []).entries()) for (const [p, g] of k.entries()) {
47
- const y = l(g?.style, e);
48
- if (y && n.push({ ...u(s, e, t, i, { code: "unsupported-style", message: y }), componentPath: [...r, c, p] }), g?.children?.length && e !== "dom")
49
- n.push({ ...u(s, e, t, i, { code: "nested-components-omitted", message: "Nested grid components are omitted; cell text is preserved." }), componentPath: [...r, c, p] });
50
- else if (e === "dom")
51
- for (const [S, w] of (g?.children ?? []).entries()) v(w, e, t, i, [...r, c, p, S], n, d);
52
- }
53
- }
54
- function j(s, e) {
55
- const t = [];
56
- return s.pages.forEach((i, r) => i.components.forEach((n, a) => v(n, e, r, a, [], t, /* @__PURE__ */ new Set()))), t;
57
- }
58
- function A(s, e, t) {
59
- h(t.signal);
60
- const i = j(s, e);
61
- if (i.forEach((r) => b(r, t)), t.fidelity === "strict" && i.length) throw new E(i);
62
- return i;
63
- }
64
- export {
65
- E as O,
66
- j as i,
67
- b as n,
68
- A as r
69
- };
@@ -1,521 +0,0 @@
1
- function g(r) {
2
- if (!Number.isSafeInteger(r) || r < 0 || r > 1e3 * 2)
3
- throw new Error("十进制精度超出预算");
4
- return 10n ** BigInt(r);
5
- }
6
- function h(r) {
7
- if (r.coefficient.toString().length > 1e3 * 2 || r.scale > 1e3 * 2)
8
- throw new Error("十进制结果超出精度预算");
9
- return r;
10
- }
11
- function s(r) {
12
- if (typeof r != "string" && !(typeof r == "number" && Number.isFinite(r)))
13
- throw new Error("十进制参数必须是有限数字或十进制文本");
14
- const e = String(r);
15
- if (e.length > 1e3) throw new Error("十进制文本超出精度预算");
16
- const n = /^([+-]?)(\d+)(?:\.(\d*))?(?:[eE]([+-]?\d{1,4}))?$/.exec(
17
- e
18
- );
19
- if (!n) throw new Error("无效十进制文本");
20
- const t = n[3] ?? "", o = Number(n[4] ?? 0), i = t.length - o, c = BigInt(
21
- `${n[1] === "-" ? "-" : ""}${n[2]}${t}`
22
- );
23
- return h(
24
- i < 0 ? { coefficient: c * g(-i), scale: 0 } : { coefficient: c, scale: i }
25
- );
26
- }
27
- function B(r, e) {
28
- const n = Math.max(r.scale, e.scale);
29
- return [
30
- r.coefficient * g(n - r.scale),
31
- e.coefficient * g(n - e.scale),
32
- n
33
- ];
34
- }
35
- function O(r, e) {
36
- const [n, t] = B(r, e);
37
- return n < t ? -1 : n > t ? 1 : 0;
38
- }
39
- function m(r, e) {
40
- const [n, t, o] = B(r, e);
41
- return h({ coefficient: n + t, scale: o });
42
- }
43
- function A(r, e) {
44
- return h({
45
- coefficient: r.coefficient * e.coefficient,
46
- scale: r.scale + e.scale
47
- });
48
- }
49
- function D(r, e) {
50
- const n = r / e, t = r % e, o = (i) => i < 0n ? -i : i;
51
- return o(t) * 2n < o(e) ? n : n + (r < 0n == e < 0n ? 1n : -1n);
52
- }
53
- function p(r) {
54
- if (!Number.isInteger(r) || r < 0 || r > 100)
55
- throw new Error("十进制小数位应为 0–100 的整数");
56
- }
57
- function E(r, e, n = 20) {
58
- if (p(n), e.coefficient === 0n) throw new Error("不能除以零");
59
- const t = e.scale - r.scale + n, o = r.coefficient * g(Math.max(0, t)), i = e.coefficient * g(Math.max(0, -t));
60
- return h({
61
- coefficient: D(o, i),
62
- scale: n
63
- });
64
- }
65
- function v(r, e) {
66
- let n = r.coefficient, t = r.scale;
67
- e !== void 0 && (p(e), n = e >= t ? n * g(e - t) : D(n, g(t - e)), t = e);
68
- const o = n < 0n, i = (o ? -n : n).toString().padStart(t + 1, "0");
69
- let c = t ? i.slice(-t) : "";
70
- return e === void 0 && (c = c.replace(/0+$/, "")), `${o ? "-" : ""}${t ? i.slice(0, -t) : i}${c ? `.${c}` : ""}`;
71
- }
72
- function q(r, e, n = !1, t = !1) {
73
- let o = s(r);
74
- t && (o = A(o, { coefficient: 100n, scale: 0 }));
75
- const [i, c] = v(o, e).split(".");
76
- return `${n ? i.replace(/\B(?=(\d{3})+(?!\d))/g, ",") : i}${c === void 0 ? "" : `.${c}`}${t ? "%" : ""}`;
77
- }
78
- const j = [
79
- "sum",
80
- "count",
81
- "avg",
82
- "min",
83
- "max",
84
- "weightedAvg"
85
- ];
86
- function N(r) {
87
- if (typeof r != "number" || !Number.isFinite(r))
88
- throw new Error(
89
- "聚合度量必须是有限数字,不能隐式转换;小数文本请显式选择 decimal"
90
- );
91
- return r;
92
- }
93
- function w(r, e) {
94
- return e && Object.prototype.hasOwnProperty.call(r, e) ? r[e] : void 0;
95
- }
96
- function _(r) {
97
- let e = 0, n = 0, t = 0, o = 0, i = 1 / 0, c = -1 / 0;
98
- const u = (a) => {
99
- const f = a - t, l = n + f;
100
- t = l - n - f, n = l;
101
- };
102
- return {
103
- add(a) {
104
- const f = w(a, r.field);
105
- if (r.op === "count") {
106
- (!r.field || f != null) && e++;
107
- return;
108
- }
109
- if (f == null) return;
110
- const l = N(f), F = r.op === "weightedAvg" ? w(a, r.weightField) : 1;
111
- if (F == null) return;
112
- const y = N(F);
113
- if (r.op === "weightedAvg" && y < 0)
114
- throw new Error("加权平均的权重不能为负数");
115
- ["sum", "avg", "weightedAvg"].includes(r.op) && u(l * y), o += y, i = Math.min(i, l), c = Math.max(c, l), e++;
116
- },
117
- value() {
118
- if (r.op === "count") return e;
119
- if (!e) return null;
120
- const a = r.op === "min" ? i : r.op === "max" ? c : r.op === "avg" ? n / e : r.op === "weightedAvg" ? o === 0 ? null : n / o : n;
121
- if (a !== null && !Number.isFinite(a))
122
- throw new Error("聚合计算溢出");
123
- return a;
124
- }
125
- };
126
- }
127
- function R(r) {
128
- let e = 0, n = s("0"), t = s("0"), o, i;
129
- return {
130
- add(c) {
131
- const u = w(c, r.field);
132
- if (r.op === "count") {
133
- (!r.field || u != null) && e++;
134
- return;
135
- }
136
- if (u == null) return;
137
- const a = r.op === "weightedAvg" ? w(c, r.weightField) : "1";
138
- if (a == null) return;
139
- const f = s(u), l = s(a);
140
- if (r.op === "weightedAvg" && l.coefficient < 0n)
141
- throw new Error("加权平均的权重不能为负数");
142
- ["sum", "avg", "weightedAvg"].includes(r.op) && (n = m(n, A(f, l))), r.op === "weightedAvg" && (t = m(t, l)), (!o || O(f, o) < 0) && (o = f), (!i || O(f, i) > 0) && (i = f), e++;
143
- },
144
- value() {
145
- if (r.op === "count") return e;
146
- if (!e || r.op === "weightedAvg" && t.coefficient === 0n)
147
- return null;
148
- let c = r.op === "min" ? o : r.op === "max" ? i : n;
149
- return r.op === "avg" && (c = E(n, s(e), r.digits)), r.op === "weightedAvg" && (c = E(n, t, r.digits)), v(c, r.digits);
150
- }
151
- };
152
- }
153
- function T(r) {
154
- if (r.digits !== void 0 && p(r.digits), r.numeric !== void 0 && r.numeric !== "number" && r.numeric !== "decimal")
155
- throw new Error("未知聚合数值模式");
156
- if (!j.includes(r.op)) throw new Error("未知聚合操作");
157
- if (r.op !== "count" && !r.field)
158
- throw new Error("聚合需要度量字段");
159
- if (r.op === "weightedAvg" && !r.weightField)
160
- throw new Error("加权平均需要权重字段");
161
- return r.numeric === "decimal" ? R(r) : _(r);
162
- }
163
- function $(r, e) {
164
- const n = T(e);
165
- for (const t of r) n.add(t);
166
- return n.value();
167
- }
168
- const C = /* @__PURE__ */ new Set(["__proto__", "prototype", "constructor"]);
169
- function d(r) {
170
- if (typeof r != "string" || !r.trim() || C.has(r))
171
- throw new Error("计算字段应为安全的非空字段名");
172
- }
173
- function b(r) {
174
- return r === null || ["string", "boolean"].includes(typeof r) || typeof r == "number" && Number.isFinite(r);
175
- }
176
- function G(r) {
177
- if (r.some((e) => typeof e != "number" || !Number.isFinite(e)))
178
- throw new Error("算术参数必须是有限数字;空值和小数文本不会隐式转换");
179
- return r;
180
- }
181
- function X(r, e) {
182
- const n = G(e);
183
- let t;
184
- if (r === "add") t = n.reduce((o, i) => o + i, 0);
185
- else if (r === "multiply") t = n.reduce((o, i) => o * i, 1);
186
- else if (r === "subtract") t = n[0] - n[1];
187
- else {
188
- if (n[1] === 0) throw new Error("不能除以零");
189
- t = n[0] / n[1];
190
- }
191
- if (!Number.isFinite(t)) throw new Error("计算结果不是有限数字");
192
- return t;
193
- }
194
- function Z(r, e, n) {
195
- const t = e.map(s);
196
- let o;
197
- return r === "add" ? o = t.reduce(m) : r === "multiply" ? o = t.reduce(A) : r === "subtract" ? o = m(t[0], {
198
- ...t[1],
199
- coefficient: -t[1].coefficient
200
- }) : o = E(t[0], t[1], n), v(o, n);
201
- }
202
- function J(r, e, n) {
203
- return n.nulls !== "error" && e.some((t) => t == null) || r === "divide" && n.divisionByZero === "null" && (n.numeric === "decimal" ? s(e[1]).coefficient === 0n : e[1] === 0) ? null : n.numeric === "decimal" ? Z(r, e, n.digits) : X(r, e);
204
- }
205
- function P(r, e) {
206
- r.field !== void 0 && d(r.field), r.weightField !== void 0 && d(r.weightField);
207
- const n = {
208
- op: r.aggregate,
209
- field: r.field,
210
- weightField: r.weightField,
211
- numeric: e.numeric,
212
- digits: e.digits
213
- };
214
- $([], n);
215
- const t = /* @__PURE__ */ new WeakMap();
216
- return (o) => {
217
- let i = t.get(o.rows);
218
- if (!i) {
219
- try {
220
- i = { value: $(o.rows, n) };
221
- } catch (c) {
222
- i = {
223
- error: c instanceof Error ? c : new Error(String(c))
224
- };
225
- }
226
- t.set(o.rows, i);
227
- }
228
- if (i.error) throw i.error;
229
- return i.value;
230
- };
231
- }
232
- function z(r, e) {
233
- for (const n of r) {
234
- const t = n(e);
235
- if (t != null) return t;
236
- }
237
- return null;
238
- }
239
- function S(r, e = {}, n = { nodes: 0 }, t = 0) {
240
- if (++n.nodes > 256 || t > 16)
241
- throw new Error("计算表达式超出深度或节点预算");
242
- if (!r || typeof r != "object" || Array.isArray(r))
243
- throw new Error("计算表达式应为声明式对象");
244
- if ("aggregate" in r) return P(r, e);
245
- if ("field" in r) {
246
- d(r.field);
247
- const o = r.field;
248
- return ({ row: i }) => Object.prototype.hasOwnProperty.call(i, o) ? i[o] : void 0;
249
- }
250
- if ("value" in r) {
251
- if (!b(r.value))
252
- throw new Error("常量应为有限 JSON 标量");
253
- return () => r.value;
254
- }
255
- return W(r, e, n, t);
256
- }
257
- function W(r, e, n, t) {
258
- if (!["add", "subtract", "multiply", "divide", "coalesce"].includes(
259
- r.op
260
- ) || !Array.isArray(r.args))
261
- throw new Error("未知计算操作");
262
- if (r.args.length > 256 || Object.keys(r.args).length !== r.args.length)
263
- throw new Error("计算参数超出预算或包含空位");
264
- if (r.args.length < 2 || ["subtract", "divide"].includes(r.op) && r.args.length !== 2)
265
- throw new Error("运算参数数量不正确");
266
- const o = r.args.map(
267
- (i) => S(i, e, n, t + 1)
268
- );
269
- return r.op === "coalesce" ? (i) => z(o, i) : (i) => J(
270
- r.op,
271
- o.map((c) => c(i)),
272
- e
273
- );
274
- }
275
- function K(r) {
276
- S(r);
277
- const e = /* @__PURE__ */ new Set(), n = (t) => {
278
- "field" in t && t.field && e.add(t.field), "aggregate" in t && t.weightField && e.add(t.weightField), "args" in t && t.args.forEach(n);
279
- };
280
- return n(r), [...e];
281
- }
282
- function Q(r) {
283
- if (d(r.field), r.scope !== void 0 && !["row", "group", "dataset"].includes(r.scope))
284
- throw new Error("未知计算范围");
285
- if (r.numeric !== void 0 && r.numeric !== "number" && r.numeric !== "decimal")
286
- throw new Error("未知数值模式");
287
- if (r.digits !== void 0 && p(r.digits), r.nulls !== void 0 && r.nulls !== "propagate" && r.nulls !== "error")
288
- throw new Error("未知空值规则");
289
- if (r.divisionByZero !== void 0 && r.divisionByZero !== "null" && r.divisionByZero !== "error")
290
- throw new Error("未知除零规则");
291
- if (r.scope === "group" && (!Array.isArray(r.groupBy) || !r.groupBy.length))
292
- throw new Error("分组计算需要 groupBy 字段");
293
- U(r);
294
- }
295
- function U(r) {
296
- if (r.groupBy !== void 0) {
297
- if (!Array.isArray(r.groupBy) || r.groupBy.length > 16)
298
- throw new Error("计算分组最多 16 级");
299
- r.groupBy.forEach(d);
300
- }
301
- if (r.dependsOn !== void 0) {
302
- if (!Array.isArray(r.dependsOn) || r.dependsOn.length > 2048)
303
- throw new Error("计算依赖超出预算");
304
- r.dependsOn.forEach(d);
305
- }
306
- }
307
- function M(r) {
308
- return [
309
- .../* @__PURE__ */ new Set([
310
- ...typeof r.expression == "string" ? r.dependsOn ?? [] : K(r.expression),
311
- ...r.groupBy ?? []
312
- ])
313
- ];
314
- }
315
- function k(r) {
316
- if (!Array.isArray(r) || r.length > 2048)
317
- throw new Error("计算字段应为数组且最多2048项");
318
- const e = /* @__PURE__ */ new Map();
319
- for (const c of r) {
320
- if (Q(c), e.has(c.field)) throw new Error(`计算字段重复:${c.field}`);
321
- e.set(c.field, c);
322
- }
323
- const n = /* @__PURE__ */ new Set(), t = /* @__PURE__ */ new Set(), o = [];
324
- function i(c) {
325
- if (!t.has(c.field)) {
326
- if (n.has(c.field))
327
- throw new Error(
328
- `计算字段存在循环依赖:${[...n, c.field].join(" → ")}`
329
- );
330
- n.add(c.field);
331
- for (const u of M(c)) {
332
- const a = e.get(u);
333
- a && i(a);
334
- }
335
- n.delete(c.field), t.add(c.field), o.push(c);
336
- }
337
- }
338
- return r.forEach(i), o;
339
- }
340
- function rr(r) {
341
- try {
342
- const e = k(r);
343
- return {
344
- valid: !0,
345
- errors: [],
346
- order: e.map((n) => n.field),
347
- fields: r.map((n) => ({
348
- field: n.field,
349
- dependencies: M(n),
350
- scope: n.scope ?? "row"
351
- }))
352
- };
353
- } catch (e) {
354
- return {
355
- valid: !1,
356
- errors: [e instanceof Error ? e.message : String(e)],
357
- fields: [],
358
- order: []
359
- };
360
- }
361
- }
362
- function er(r = []) {
363
- return {
364
- fields: r.map((e) => ({ ...e })),
365
- functions: [
366
- {
367
- name: "add",
368
- minArgs: 2,
369
- maxArgs: 256,
370
- input: "numeric",
371
- output: "numeric"
372
- },
373
- {
374
- name: "subtract",
375
- minArgs: 2,
376
- maxArgs: 2,
377
- input: "numeric",
378
- output: "numeric"
379
- },
380
- {
381
- name: "multiply",
382
- minArgs: 2,
383
- maxArgs: 256,
384
- input: "numeric",
385
- output: "numeric"
386
- },
387
- {
388
- name: "divide",
389
- minArgs: 2,
390
- maxArgs: 2,
391
- input: "numeric",
392
- output: "numeric"
393
- },
394
- {
395
- name: "coalesce",
396
- minArgs: 2,
397
- maxArgs: 256,
398
- input: "scalar",
399
- output: "scalar"
400
- }
401
- ],
402
- operations: ["add", "subtract", "multiply", "divide", "coalesce"],
403
- aggregates: ["sum", "count", "avg", "min", "max", "weightedAvg"],
404
- scopes: ["row", "group", "dataset"],
405
- numericModes: ["number", "decimal"],
406
- rules: {
407
- nulls: "propagate",
408
- aggregateNulls: "skip",
409
- emptyAggregate: null,
410
- countEmpty: 0,
411
- divisionByZero: "error",
412
- decimalOutput: "string",
413
- rounding: "half-away-from-zero"
414
- }
415
- };
416
- }
417
- function V(r) {
418
- return k(r.fields).map((e) => {
419
- if (typeof e.expression != "string")
420
- return {
421
- definition: e,
422
- read: S(e.expression, e)
423
- };
424
- if (!r.formula)
425
- throw new Error("字符串公式需要显式配置 formula adapter");
426
- const n = e.expression;
427
- return {
428
- definition: e,
429
- read: (t) => r.formula.evaluate(n, t)
430
- };
431
- });
432
- }
433
- function H(r, e) {
434
- return JSON.stringify(
435
- e.map((n) => {
436
- const t = Object.prototype.hasOwnProperty.call(r, n) ? r[n] : null;
437
- if (t != null && !b(t))
438
- throw new Error("分组字段应为有限 JSON 标量");
439
- return [typeof t, t ?? null];
440
- })
441
- );
442
- }
443
- function L(r, e) {
444
- if (e.scope === "dataset") return () => r;
445
- if (e.scope !== "group") {
446
- const o = /* @__PURE__ */ new WeakMap();
447
- return (i) => {
448
- let c = o.get(i);
449
- return c || (c = [i], o.set(i, c)), c;
450
- };
451
- }
452
- const n = /* @__PURE__ */ new Map(), t = /* @__PURE__ */ new WeakMap();
453
- for (const o of r) {
454
- const i = H(o, e.groupBy);
455
- t.set(o, i);
456
- const c = n.get(i);
457
- c ? c.push(o) : n.set(i, [o]);
458
- }
459
- return (o) => n.get(t.get(o));
460
- }
461
- function Y(r, e) {
462
- const n = e.maxRows ?? 1e5, t = e.maxCells ?? 2e6;
463
- if (!Array.isArray(r) || !Number.isSafeInteger(n) || n < 1 || r.length > n)
464
- throw new Error("计算数据行数超出预算或输入不是数组");
465
- if (!Array.isArray(e.fields) || e.fields.length > 2048)
466
- throw new Error("计算字段应为数组且最多2048项");
467
- if (!Number.isSafeInteger(t) || t < 1 || r.length * e.fields.length > t)
468
- throw new Error("计算单元格超出 maxCells 预算");
469
- }
470
- function I(r) {
471
- if (r?.aborted) {
472
- const e = new Error("数据计算已取消");
473
- throw e.name = "AbortError", e;
474
- }
475
- }
476
- function x(r, e, n, t, o, i) {
477
- try {
478
- const c = r.read({ row: e, rowIndex: n, rows: t });
479
- if (c !== void 0 && !b(c))
480
- throw new Error("计算结果应为有限 JSON 标量,异步公式请先在数据源中求值");
481
- e[r.definition.field] = c ?? null;
482
- } catch (c) {
483
- const u = c instanceof Error ? c.message : String(c);
484
- if (o.onError !== "null")
485
- throw Object.assign(
486
- new Error(`第 ${n + 1} 行 ${r.definition.field}:${u}`),
487
- { cause: c }
488
- );
489
- e[r.definition.field] = null, i.push({ rowIndex: n, field: r.definition.field, message: u });
490
- }
491
- }
492
- function nr(r, e) {
493
- Y(r, e), I(e.signal);
494
- const n = V(e), t = [], o = r.map((i, c) => {
495
- if (!i || typeof i != "object" || Array.isArray(i))
496
- throw new Error(`第 ${c + 1} 行应为对象`);
497
- return { ...i };
498
- });
499
- for (const i of n) {
500
- const c = L(o, i.definition);
501
- o.forEach((u, a) => {
502
- I(e.signal), x(i, u, a, c(u), e, t);
503
- });
504
- }
505
- return { rows: o, issues: t };
506
- }
507
- export {
508
- m as a,
509
- $ as b,
510
- T as c,
511
- O as d,
512
- nr as e,
513
- p as f,
514
- E as g,
515
- q as h,
516
- er as i,
517
- v as j,
518
- A as m,
519
- s as p,
520
- rr as v
521
- };
@@ -1 +0,0 @@
1
- "use strict";function g(r){if(!Number.isSafeInteger(r)||r<0||r>1e3*2)throw new Error("十进制精度超出预算");return 10n**BigInt(r)}function y(r){if(r.coefficient.toString().length>1e3*2||r.scale>1e3*2)throw new Error("十进制结果超出精度预算");return r}function s(r){if(typeof r!="string"&&!(typeof r=="number"&&Number.isFinite(r)))throw new Error("十进制参数必须是有限数字或十进制文本");const e=String(r);if(e.length>1e3)throw new Error("十进制文本超出精度预算");const t=/^([+-]?)(\d+)(?:\.(\d*))?(?:[eE]([+-]?\d{1,4}))?$/.exec(e);if(!t)throw new Error("无效十进制文本");const n=t[3]??"",o=Number(t[4]??0),i=n.length-o,c=BigInt(`${t[1]==="-"?"-":""}${t[2]}${n}`);return y(i<0?{coefficient:c*g(-i),scale:0}:{coefficient:c,scale:i})}function I(r,e){const t=Math.max(r.scale,e.scale);return[r.coefficient*g(t-r.scale),e.coefficient*g(t-e.scale),t]}function b(r,e){const[t,n]=I(r,e);return t<n?-1:t>n?1:0}function m(r,e){const[t,n,o]=I(r,e);return y({coefficient:t+n,scale:o})}function E(r,e){return y({coefficient:r.coefficient*e.coefficient,scale:r.scale+e.scale})}function M(r,e){const t=r/e,n=r%e,o=i=>i<0n?-i:i;return o(n)*2n<o(e)?t:t+(r<0n==e<0n?1n:-1n)}function w(r){if(!Number.isInteger(r)||r<0||r>100)throw new Error("十进制小数位应为 0–100 的整数")}function h(r,e,t=20){if(w(t),e.coefficient===0n)throw new Error("不能除以零");const n=e.scale-r.scale+t,o=r.coefficient*g(Math.max(0,n)),i=e.coefficient*g(Math.max(0,-n));return y({coefficient:M(o,i),scale:t})}function A(r,e){let t=r.coefficient,n=r.scale;e!==void 0&&(w(e),t=e>=n?t*g(e-n):M(t,g(n-e)),n=e);const o=t<0n,i=(o?-t:t).toString().padStart(n+1,"0");let c=n?i.slice(-n):"";return e===void 0&&(c=c.replace(/0+$/,"")),`${o?"-":""}${n?i.slice(0,-n):i}${c?`.${c}`:""}`}function _(r,e,t=!1,n=!1){let o=s(r);n&&(o=E(o,{coefficient:100n,scale:0}));const[i,c]=A(o,e).split(".");return`${t?i.replace(/\B(?=(\d{3})+(?!\d))/g,","):i}${c===void 0?"":`.${c}`}${n?"%":""}`}const R=["sum","count","avg","min","max","weightedAvg"];function N(r){if(typeof r!="number"||!Number.isFinite(r))throw new Error("聚合度量必须是有限数字,不能隐式转换;小数文本请显式选择 decimal");return r}function p(r,e){return e&&Object.prototype.hasOwnProperty.call(r,e)?r[e]:void 0}function C(r){let e=0,t=0,n=0,o=0,i=1/0,c=-1/0;const u=a=>{const l=a-n,f=t+l;n=f-t-l,t=f};return{add(a){const l=p(a,r.field);if(r.op==="count"){(!r.field||l!=null)&&e++;return}if(l==null)return;const f=N(l),O=r.op==="weightedAvg"?p(a,r.weightField):1;if(O==null)return;const v=N(O);if(r.op==="weightedAvg"&&v<0)throw new Error("加权平均的权重不能为负数");["sum","avg","weightedAvg"].includes(r.op)&&u(f*v),o+=v,i=Math.min(i,f),c=Math.max(c,f),e++},value(){if(r.op==="count")return e;if(!e)return null;const a=r.op==="min"?i:r.op==="max"?c:r.op==="avg"?t/e:r.op==="weightedAvg"?o===0?null:t/o:t;if(a!==null&&!Number.isFinite(a))throw new Error("聚合计算溢出");return a}}}function T(r){let e=0,t=s("0"),n=s("0"),o,i;return{add(c){const u=p(c,r.field);if(r.op==="count"){(!r.field||u!=null)&&e++;return}if(u==null)return;const a=r.op==="weightedAvg"?p(c,r.weightField):"1";if(a==null)return;const l=s(u),f=s(a);if(r.op==="weightedAvg"&&f.coefficient<0n)throw new Error("加权平均的权重不能为负数");["sum","avg","weightedAvg"].includes(r.op)&&(t=m(t,E(l,f))),r.op==="weightedAvg"&&(n=m(n,f)),(!o||b(l,o)<0)&&(o=l),(!i||b(l,i)>0)&&(i=l),e++},value(){if(r.op==="count")return e;if(!e||r.op==="weightedAvg"&&n.coefficient===0n)return null;let c=r.op==="min"?o:r.op==="max"?i:t;return r.op==="avg"&&(c=h(t,s(e),r.digits)),r.op==="weightedAvg"&&(c=h(t,n,r.digits)),A(c,r.digits)}}}function B(r){if(r.digits!==void 0&&w(r.digits),r.numeric!==void 0&&r.numeric!=="number"&&r.numeric!=="decimal")throw new Error("未知聚合数值模式");if(!R.includes(r.op))throw new Error("未知聚合操作");if(r.op!=="count"&&!r.field)throw new Error("聚合需要度量字段");if(r.op==="weightedAvg"&&!r.weightField)throw new Error("加权平均需要权重字段");return r.numeric==="decimal"?T(r):C(r)}function S(r,e){const t=B(e);for(const n of r)t.add(n);return t.value()}const G=new Set(["__proto__","prototype","constructor"]);function d(r){if(typeof r!="string"||!r.trim()||G.has(r))throw new Error("计算字段应为安全的非空字段名")}function D(r){return r===null||["string","boolean"].includes(typeof r)||typeof r=="number"&&Number.isFinite(r)}function X(r){if(r.some(e=>typeof e!="number"||!Number.isFinite(e)))throw new Error("算术参数必须是有限数字;空值和小数文本不会隐式转换");return r}function Z(r,e){const t=X(e);let n;if(r==="add")n=t.reduce((o,i)=>o+i,0);else if(r==="multiply")n=t.reduce((o,i)=>o*i,1);else if(r==="subtract")n=t[0]-t[1];else{if(t[1]===0)throw new Error("不能除以零");n=t[0]/t[1]}if(!Number.isFinite(n))throw new Error("计算结果不是有限数字");return n}function J(r,e,t){const n=e.map(s);let o;return r==="add"?o=n.reduce(m):r==="multiply"?o=n.reduce(E):r==="subtract"?o=m(n[0],{...n[1],coefficient:-n[1].coefficient}):o=h(n[0],n[1],t),A(o,t)}function P(r,e,t){return t.nulls!=="error"&&e.some(n=>n==null)||r==="divide"&&t.divisionByZero==="null"&&(t.numeric==="decimal"?s(e[1]).coefficient===0n:e[1]===0)?null:t.numeric==="decimal"?J(r,e,t.digits):Z(r,e)}function z(r,e){r.field!==void 0&&d(r.field),r.weightField!==void 0&&d(r.weightField);const t={op:r.aggregate,field:r.field,weightField:r.weightField,numeric:e.numeric,digits:e.digits};S([],t);const n=new WeakMap;return o=>{let i=n.get(o.rows);if(!i){try{i={value:S(o.rows,t)}}catch(c){i={error:c instanceof Error?c:new Error(String(c))}}n.set(o.rows,i)}if(i.error)throw i.error;return i.value}}function W(r,e){for(const t of r){const n=t(e);if(n!=null)return n}return null}function F(r,e={},t={nodes:0},n=0){if(++t.nodes>256||n>16)throw new Error("计算表达式超出深度或节点预算");if(!r||typeof r!="object"||Array.isArray(r))throw new Error("计算表达式应为声明式对象");if("aggregate"in r)return z(r,e);if("field"in r){d(r.field);const o=r.field;return({row:i})=>Object.prototype.hasOwnProperty.call(i,o)?i[o]:void 0}if("value"in r){if(!D(r.value))throw new Error("常量应为有限 JSON 标量");return()=>r.value}return K(r,e,t,n)}function K(r,e,t,n){if(!["add","subtract","multiply","divide","coalesce"].includes(r.op)||!Array.isArray(r.args))throw new Error("未知计算操作");if(r.args.length>256||Object.keys(r.args).length!==r.args.length)throw new Error("计算参数超出预算或包含空位");if(r.args.length<2||["subtract","divide"].includes(r.op)&&r.args.length!==2)throw new Error("运算参数数量不正确");const o=r.args.map(i=>F(i,e,t,n+1));return r.op==="coalesce"?i=>W(o,i):i=>P(r.op,o.map(c=>c(i)),e)}function Q(r){F(r);const e=new Set,t=n=>{"field"in n&&n.field&&e.add(n.field),"aggregate"in n&&n.weightField&&e.add(n.weightField),"args"in n&&n.args.forEach(t)};return t(r),[...e]}function U(r){if(d(r.field),r.scope!==void 0&&!["row","group","dataset"].includes(r.scope))throw new Error("未知计算范围");if(r.numeric!==void 0&&r.numeric!=="number"&&r.numeric!=="decimal")throw new Error("未知数值模式");if(r.digits!==void 0&&w(r.digits),r.nulls!==void 0&&r.nulls!=="propagate"&&r.nulls!=="error")throw new Error("未知空值规则");if(r.divisionByZero!==void 0&&r.divisionByZero!=="null"&&r.divisionByZero!=="error")throw new Error("未知除零规则");if(r.scope==="group"&&(!Array.isArray(r.groupBy)||!r.groupBy.length))throw new Error("分组计算需要 groupBy 字段");V(r)}function V(r){if(r.groupBy!==void 0){if(!Array.isArray(r.groupBy)||r.groupBy.length>16)throw new Error("计算分组最多 16 级");r.groupBy.forEach(d)}if(r.dependsOn!==void 0){if(!Array.isArray(r.dependsOn)||r.dependsOn.length>2048)throw new Error("计算依赖超出预算");r.dependsOn.forEach(d)}}function k(r){return[...new Set([...typeof r.expression=="string"?r.dependsOn??[]:Q(r.expression),...r.groupBy??[]])]}function j(r){if(!Array.isArray(r)||r.length>2048)throw new Error("计算字段应为数组且最多2048项");const e=new Map;for(const c of r){if(U(c),e.has(c.field))throw new Error(`计算字段重复:${c.field}`);e.set(c.field,c)}const t=new Set,n=new Set,o=[];function i(c){if(!n.has(c.field)){if(t.has(c.field))throw new Error(`计算字段存在循环依赖:${[...t,c.field].join(" → ")}`);t.add(c.field);for(const u of k(c)){const a=e.get(u);a&&i(a)}t.delete(c.field),n.add(c.field),o.push(c)}}return r.forEach(i),o}function H(r){try{const e=j(r);return{valid:!0,errors:[],order:e.map(t=>t.field),fields:r.map(t=>({field:t.field,dependencies:k(t),scope:t.scope??"row"}))}}catch(e){return{valid:!1,errors:[e instanceof Error?e.message:String(e)],fields:[],order:[]}}}function L(r=[]){return{fields:r.map(e=>({...e})),functions:[{name:"add",minArgs:2,maxArgs:256,input:"numeric",output:"numeric"},{name:"subtract",minArgs:2,maxArgs:2,input:"numeric",output:"numeric"},{name:"multiply",minArgs:2,maxArgs:256,input:"numeric",output:"numeric"},{name:"divide",minArgs:2,maxArgs:2,input:"numeric",output:"numeric"},{name:"coalesce",minArgs:2,maxArgs:256,input:"scalar",output:"scalar"}],operations:["add","subtract","multiply","divide","coalesce"],aggregates:["sum","count","avg","min","max","weightedAvg"],scopes:["row","group","dataset"],numericModes:["number","decimal"],rules:{nulls:"propagate",aggregateNulls:"skip",emptyAggregate:null,countEmpty:0,divisionByZero:"error",decimalOutput:"string",rounding:"half-away-from-zero"}}}function Y(r){return j(r.fields).map(e=>{if(typeof e.expression!="string")return{definition:e,read:F(e.expression,e)};if(!r.formula)throw new Error("字符串公式需要显式配置 formula adapter");const t=e.expression;return{definition:e,read:n=>r.formula.evaluate(t,n)}})}function x(r,e){return JSON.stringify(e.map(t=>{const n=Object.prototype.hasOwnProperty.call(r,t)?r[t]:null;if(n!=null&&!D(n))throw new Error("分组字段应为有限 JSON 标量");return[typeof n,n??null]}))}function q(r,e){if(e.scope==="dataset")return()=>r;if(e.scope!=="group"){const o=new WeakMap;return i=>{let c=o.get(i);return c||(c=[i],o.set(i,c)),c}}const t=new Map,n=new WeakMap;for(const o of r){const i=x(o,e.groupBy);n.set(o,i);const c=t.get(i);c?c.push(o):t.set(i,[o])}return o=>t.get(n.get(o))}function rr(r,e){const t=e.maxRows??1e5,n=e.maxCells??2e6;if(!Array.isArray(r)||!Number.isSafeInteger(t)||t<1||r.length>t)throw new Error("计算数据行数超出预算或输入不是数组");if(!Array.isArray(e.fields)||e.fields.length>2048)throw new Error("计算字段应为数组且最多2048项");if(!Number.isSafeInteger(n)||n<1||r.length*e.fields.length>n)throw new Error("计算单元格超出 maxCells 预算")}function $(r){if(r?.aborted){const e=new Error("数据计算已取消");throw e.name="AbortError",e}}function er(r,e,t,n,o,i){try{const c=r.read({row:e,rowIndex:t,rows:n});if(c!==void 0&&!D(c))throw new Error("计算结果应为有限 JSON 标量,异步公式请先在数据源中求值");e[r.definition.field]=c??null}catch(c){const u=c instanceof Error?c.message:String(c);if(o.onError!=="null")throw Object.assign(new Error(`第 ${t+1} 行 ${r.definition.field}:${u}`),{cause:c});e[r.definition.field]=null,i.push({rowIndex:t,field:r.definition.field,message:u})}}function tr(r,e){rr(r,e),$(e.signal);const t=Y(e),n=[],o=r.map((i,c)=>{if(!i||typeof i!="object"||Array.isArray(i))throw new Error(`第 ${c+1} 行应为对象`);return{...i}});for(const i of t){const c=q(o,i.definition);o.forEach((u,a)=>{$(e.signal),er(i,u,a,c(u),e,n)})}return{rows:o,issues:n}}exports.addDecimal=m;exports.aggregateRows=S;exports.compareDecimal=b;exports.computeDataset=tr;exports.createAggregateAccumulator=B;exports.decimalDigits=w;exports.divideDecimal=h;exports.formatDecimal=_;exports.getComputationMetadata=L;exports.multiplyDecimal=E;exports.parseDecimal=s;exports.printDecimal=A;exports.validateComputedFields=H;