@agile-team/mach-report 2.5.0 → 2.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +126 -16
- package/dist/ReportPreview-BdvoqdOd.cjs +6 -0
- package/dist/ReportPreview-COFkbeEM.js +3719 -0
- package/dist/_plugin-vue_export-helper-BHFhmbuH.cjs +1 -0
- package/dist/_plugin-vue_export-helper-CHgC5LLL.js +9 -0
- package/dist/analytics.cjs +1 -0
- package/dist/analytics.d.cts +276 -0
- package/dist/analytics.d.ts +276 -0
- package/dist/analytics.js +223 -0
- package/dist/assets-B9qJku3V.js +160 -0
- package/dist/assets-RZan7EyL.cjs +1 -0
- package/dist/capabilities-joSutDF8.js +63 -0
- package/dist/capabilities-xGTpnPjJ.cjs +1 -0
- package/dist/designer.cjs +1 -0
- package/dist/designer.d.cts +869 -0
- package/dist/designer.d.ts +869 -0
- package/dist/designer.js +628 -0
- package/dist/index.cjs +8 -5
- package/dist/index.d.cts +497 -9
- package/dist/index.d.ts +497 -9
- package/dist/index.js +1088 -1499
- package/dist/param-validation-BWNjLcN0.js +116 -0
- package/dist/param-validation-CiTxFeZ8.cjs +1 -0
- package/dist/pdf.cjs +48 -48
- package/dist/pdf.d.cts +119 -1
- package/dist/pdf.d.ts +119 -1
- package/dist/pdf.js +3932 -3868
- package/dist/{plugin-DMPLDpBY.cjs → plugin-9t_ZFwhz.cjs} +1 -1
- package/dist/{plugin-DDLcFWlk.js → plugin-s8Ay8kKk.js} +2 -2
- package/dist/progress-DD964VAB.js +102 -0
- package/dist/progress-KvhwXZ1Q.cjs +1 -0
- package/dist/render-plan-CckPEQyf.cjs +1 -0
- package/dist/{render-plan-CXBWRog4.js → render-plan-uzZYYSy1.js} +11 -10
- package/dist/report-params-B_VCihAh.js +12 -0
- package/dist/report-params-CjWrjPl6.cjs +1 -0
- package/dist/report-source-BXHNy_AD.js +755 -0
- package/dist/report-source-CCAvFE3t.cjs +1 -0
- package/dist/server/node.d.cts +320 -0
- package/dist/server/node.d.ts +320 -0
- package/dist/server-node.cjs +1 -0
- package/dist/server-node.js +303 -0
- package/dist/server.cjs +1 -0
- package/dist/server.d.cts +668 -0
- package/dist/server.d.ts +668 -0
- package/dist/server.js +245 -0
- package/dist/style-CpwiOPyB.cjs +1 -0
- package/dist/style-Dv5o_x6b.js +67 -0
- package/dist/style.css +1 -1
- package/dist/task-events-DQ276fn2.cjs +1 -0
- package/dist/task-events-Dpsvf_t2.js +47 -0
- package/dist/template-registry-DWExx0gU.cjs +1 -0
- package/dist/template-registry-NpOakidD.js +354 -0
- package/dist/textwrap-CnGsEum6.cjs +4 -0
- package/dist/textwrap-DOl04hCQ.js +110 -0
- package/dist/validate-DfHPD8wX.cjs +1 -0
- package/dist/validate-S6CgIm5d.js +148 -0
- package/dist/vue/async.d.cts +1507 -1538
- package/dist/vue/async.d.ts +1507 -1538
- package/dist/vue/index.d.cts +2376 -2347
- package/dist/vue/index.d.ts +2376 -2347
- package/dist/vue-async.cjs +1 -1
- package/dist/vue-async.js +3 -3
- package/dist/vue.cjs +1 -1
- package/dist/vue.js +184 -75
- package/dist/worker.cjs +1 -0
- package/dist/worker.d.cts +325 -0
- package/dist/worker.d.ts +325 -0
- package/dist/worker.js +158 -0
- package/dist/xlsx/node.d.cts +47 -0
- package/dist/xlsx/node.d.ts +47 -0
- package/dist/xlsx-node.cjs +221 -0
- package/dist/xlsx-node.js +36409 -0
- package/dist/xlsx.cjs +20 -20
- package/dist/xlsx.d.cts +87 -2
- package/dist/xlsx.d.ts +87 -2
- package/dist/xlsx.js +5987 -5840
- package/package.json +63 -3
- package/dist/ReportPreview-CBKLI--k.js +0 -2188
- package/dist/ReportPreview-ClM8h0pM.cjs +0 -6
- package/dist/grid-geometry-BNIvw52m.cjs +0 -1
- package/dist/grid-geometry-C8hGoe9o.js +0 -130
- package/dist/render-plan-CCTL4F9v.cjs +0 -1
- package/dist/report-params-B3Fia6JO.js +0 -10
- package/dist/report-params-D1gZ1DME.cjs +0 -1
- package/dist/textwrap-nH0UYU6D.js +0 -108
- package/dist/textwrap-oD-t4b4B.cjs +0 -4
|
@@ -0,0 +1,354 @@
|
|
|
1
|
+
import { R } from "./render-plan-uzZYYSy1.js";
|
|
2
|
+
import { v, d as L } from "./validate-S6CgIm5d.js";
|
|
3
|
+
import { v as _, i as x } from "./param-validation-BWNjLcN0.js";
|
|
4
|
+
const O = "1.0";
|
|
5
|
+
class p extends Error {
|
|
6
|
+
constructor(t) {
|
|
7
|
+
super(`模板校验失败:${t.slice(0, 3).map((s) => `${s.path}: ${s.message}`).join("; ")}`), this.errors = t, this.name = "ReportTemplateError";
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
const P = /* @__PURE__ */ new Set(["__proto__", "prototype", "constructor"]), T = /* @__PURE__ */ new Set(["schemaVersion", "id", "name", "revision", "description", "template"]), D = /* @__PURE__ */ new Set(["left", "center", "right", "justify"]), M = 2e5, J = 64, N = 1e7;
|
|
11
|
+
function u(e) {
|
|
12
|
+
return !!e && typeof e == "object" && !Array.isArray(e);
|
|
13
|
+
}
|
|
14
|
+
function V(e, t, s) {
|
|
15
|
+
const i = Object.getPrototypeOf(e), f = Array.isArray(e);
|
|
16
|
+
if (f ? i !== Array.prototype : i !== Object.prototype && i !== null)
|
|
17
|
+
return s.push({ path: t, message: "模板对象必须使用普通 JSON 对象原型" }), !1;
|
|
18
|
+
if (f) {
|
|
19
|
+
const n = Object.keys(e);
|
|
20
|
+
if (n.length !== e.length || n.some((a) => !/^(0|[1-9]\d*)$/.test(a) || Number(a) >= e.length))
|
|
21
|
+
return s.push({ path: t, message: "模板数组不能包含空位或额外属性" }), !1;
|
|
22
|
+
}
|
|
23
|
+
return Object.getOwnPropertySymbols(e).length > 0 ? (s.push({ path: t, message: "模板不能包含 Symbol 键" }), !1) : !0;
|
|
24
|
+
}
|
|
25
|
+
function I(e, t, s, i) {
|
|
26
|
+
return P.has(e) ? (i.push({ path: s, message: "模板不能包含可能污染原型的键" }), !1) : t.get || t.set || !t.enumerable ? (i.push({ path: s, message: "模板不能包含访问器或不可枚举字段" }), !1) : !0;
|
|
27
|
+
}
|
|
28
|
+
function F(e) {
|
|
29
|
+
return e === null || typeof e == "boolean" || typeof e == "number" && Number.isFinite(e);
|
|
30
|
+
}
|
|
31
|
+
function k(e, t) {
|
|
32
|
+
const s = /* @__PURE__ */ new Set();
|
|
33
|
+
let i = 0, f = 0, n = !1;
|
|
34
|
+
const a = (o, h, m) => {
|
|
35
|
+
if (!n) {
|
|
36
|
+
if (++i > M) {
|
|
37
|
+
i === M + 1 && t.push({ path: h, message: "模板超过 JSON 节点安全上限" });
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
if (m > J) {
|
|
41
|
+
t.push({ path: h, message: "模板嵌套层级过深" });
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
if (typeof o == "string") {
|
|
45
|
+
f += o.length, f > N && (n = !0, t.push({ path: h, message: "模板文本超过 1000 万字符的安全上限" }));
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
if (!F(o)) {
|
|
49
|
+
if (!o || typeof o != "object") {
|
|
50
|
+
t.push({ path: h, message: "模板只允许 JSON 值,不允许函数、undefined 或非有限数字" });
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
if (s.has(o)) {
|
|
54
|
+
t.push({ path: h, message: "模板不能包含循环引用" });
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
if (V(o, h, t)) {
|
|
58
|
+
s.add(o);
|
|
59
|
+
for (const [r, g] of Object.entries(Object.getOwnPropertyDescriptors(o))) {
|
|
60
|
+
if (Array.isArray(o) && r === "length") continue;
|
|
61
|
+
const y = `${h}.${r}`;
|
|
62
|
+
if (I(r, g, y, t) && a(g.value, y, m + 1), i > M || n) break;
|
|
63
|
+
}
|
|
64
|
+
s.delete(o);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
a(e, "$", 0);
|
|
70
|
+
}
|
|
71
|
+
function l(e, t, s, i, f = !1) {
|
|
72
|
+
const n = e[t];
|
|
73
|
+
n === void 0 && !f || (typeof n != "string" || f && !n.trim()) && i.push({ path: `${s}.${t}`, message: f ? "应为非空字符串" : "应为字符串" });
|
|
74
|
+
}
|
|
75
|
+
function c(e, t, s, i, f = 0, n = !1) {
|
|
76
|
+
const a = e[t];
|
|
77
|
+
a === void 0 && !n || (typeof a != "number" || !Number.isFinite(a) || a < f) && i.push({ path: `${s}.${t}`, message: `应为大于等于 ${f} 的有限数字` });
|
|
78
|
+
}
|
|
79
|
+
function b(e, t, s, i) {
|
|
80
|
+
e[t] !== void 0 && typeof e[t] != "boolean" && i.push({ path: `${s}.${t}`, message: "应为布尔值" });
|
|
81
|
+
}
|
|
82
|
+
function $(e, t, s, i = !1) {
|
|
83
|
+
e !== void 0 && !D.has(e) && !(i && e === "auto") && s.push({ path: t, message: `未知对齐方式${i ? "(支持 auto)" : ""}` });
|
|
84
|
+
}
|
|
85
|
+
function d(e, t, s) {
|
|
86
|
+
if (e !== void 0) {
|
|
87
|
+
if (!u(e)) {
|
|
88
|
+
s.push({ path: t, message: "样式应为对象" });
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
$(e.align, `${t}.align`, s), e.verticalAlign !== void 0 && !["top", "middle", "bottom"].includes(e.verticalAlign) && s.push({ path: `${t}.verticalAlign`, message: "未知垂直对齐方式" });
|
|
92
|
+
for (const i of ["fontSize", "fontSizePx", "lineWidthPt", "lineHeight"]) c(e, i, t, s);
|
|
93
|
+
for (const i of ["letterSpacing", "rotateDeg"]) c(e, i, t, s, -1 / 0);
|
|
94
|
+
c(e, "opacity", t, s), typeof e.opacity == "number" && e.opacity > 1 && s.push({ path: `${t}.opacity`, message: "透明度不能大于 1" });
|
|
95
|
+
for (const i of ["bold", "italic", "underline", "borderTop", "borderRight", "borderBottom", "borderLeft"]) b(e, i, t, s);
|
|
96
|
+
for (const i of ["fontFamily", "color", "backgroundColor", "lineColor", "borderColor"]) l(e, i, t, s);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
function j(e, t, s) {
|
|
100
|
+
if (e === void 0) return;
|
|
101
|
+
if (!Array.isArray(e)) {
|
|
102
|
+
s.push({ path: t, message: "参数定义应为数组" });
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
const i = /* @__PURE__ */ new Set(), f = s.length;
|
|
106
|
+
e.forEach((n, a) => {
|
|
107
|
+
const o = `${t}.${a}`;
|
|
108
|
+
if (!u(n)) {
|
|
109
|
+
s.push({ path: o, message: "参数定义应为对象" });
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
l(n, "field", o, s, !0), typeof n.field == "string" && (i.has(n.field) && s.push({ path: `${o}.field`, message: "参数名重复" }), i.add(n.field)), n.type !== void 0 && !["text", "number", "date", "select"].includes(n.type) && s.push({ path: `${o}.type`, message: "未知参数类型" });
|
|
113
|
+
for (const h of ["label", "defaultValue", "placeholder"]) l(n, h, o, s);
|
|
114
|
+
b(n, "required", o, s);
|
|
115
|
+
for (const h of ["minLength", "maxLength"]) {
|
|
116
|
+
const m = n[h];
|
|
117
|
+
m !== void 0 && (typeof m != "number" || !Number.isSafeInteger(m) || m < 0) && s.push({ path: `${o}.${h}`, message: "长度边界应为非负整数" });
|
|
118
|
+
}
|
|
119
|
+
C(n, o, s), n.options !== void 0 && (Array.isArray(n.options) ? n.options.forEach((h, m) => {
|
|
120
|
+
const r = `${o}.options.${m}`;
|
|
121
|
+
if (!u(h)) s.push({ path: r, message: "选项应为对象" });
|
|
122
|
+
else
|
|
123
|
+
for (const g of ["label", "value"]) typeof h[g] != "string" && s.push({ path: `${r}.${g}`, message: "选项标签与值应为字符串(允许空白选项)" });
|
|
124
|
+
}) : s.push({ path: `${o}.options`, message: "选项应为数组" }));
|
|
125
|
+
}), s.length === f && s.push(..._(e).map((n) => ({ path: n.path.replace("$.paramDefs", t), message: n.message })));
|
|
126
|
+
}
|
|
127
|
+
function C(e, t, s) {
|
|
128
|
+
for (const n of ["min", "max"]) {
|
|
129
|
+
const a = e[n];
|
|
130
|
+
if (a === void 0) continue;
|
|
131
|
+
(e.type === "date" ? typeof a == "string" && x(a) : e.type === "number" && typeof a == "number" && Number.isFinite(a)) || s.push({ path: `${t}.${n}`, message: "number 使用有限数字边界,date 使用有效 YYYY-MM-DD 日期边界" });
|
|
132
|
+
}
|
|
133
|
+
const i = typeof e.min == "number" && typeof e.max == "number" && e.min > e.max, f = typeof e.min == "string" && typeof e.max == "string" && e.min > e.max;
|
|
134
|
+
(i || f) && s.push({ path: t, message: "最小边界不能大于最大边界" }), typeof e.minLength == "number" && typeof e.maxLength == "number" && e.minLength > e.maxLength && s.push({ path: t, message: "最小长度不能大于最大长度" });
|
|
135
|
+
}
|
|
136
|
+
function H(e, t, s) {
|
|
137
|
+
if (!Array.isArray(e) || e.length === 0) {
|
|
138
|
+
s.push({ path: t, message: "列表至少需要一列" });
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
e.forEach((i, f) => {
|
|
142
|
+
const n = `${t}.${f}`;
|
|
143
|
+
if (!u(i)) {
|
|
144
|
+
s.push({ path: n, message: "列应为对象" });
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
if (L(i, n, s), typeof i.header != "string" && s.push({ path: `${n}.header`, message: "表头应为字符串(允许空白表头)" }), l(i, "field", n, s, !0), c(i, "widthMm", n, s, Number.MIN_VALUE, !0), d(i.style, `${n}.style`, s), d(i.headerStyle, `${n}.headerStyle`, s), $(i.align, `${n}.align`, s, !0), $(i.headerAlign, `${n}.headerAlign`, s), i.semanticRole !== void 0 && !["identifier", "dimension", "measure", "date", "text"].includes(i.semanticRole) && s.push({ path: `${n}.semanticRole`, message: "未知列语义" }), i.format !== void 0)
|
|
148
|
+
if (!u(i.format) || !["number", "percent", "date"].includes(i.format.kind))
|
|
149
|
+
s.push({ path: `${n}.format`, message: "未知列格式" });
|
|
150
|
+
else {
|
|
151
|
+
const a = i.format.digits;
|
|
152
|
+
a !== void 0 && (typeof a != "number" || !Number.isInteger(a) || a < 0 || a > 100) && s.push({ path: `${n}.format.digits`, message: "小数位应为 0–100 的整数" }), b(i.format, "thousands", `${n}.format`, s), l(i.format, "pattern", `${n}.format`, s);
|
|
153
|
+
}
|
|
154
|
+
i.rules !== void 0 && (Array.isArray(i.rules) ? i.rules.forEach((a, o) => {
|
|
155
|
+
const h = `${n}.rules.${o}`;
|
|
156
|
+
if (!u(a) || !u(a.when)) {
|
|
157
|
+
s.push({ path: h, message: "条件格式缺少 when 对象" });
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
l(a.when, "field", `${h}.when`, s, !0), [">", ">=", "<", "<=", "==", "!="].includes(a.when.op) || s.push({ path: `${h}.when.op`, message: "未知条件运算符" }), typeof a.when.value != "number" && typeof a.when.value != "string" && s.push({ path: `${h}.when.value`, message: "条件值应为数字或字符串" }), d(a.style, `${h}.style`, s);
|
|
161
|
+
}) : s.push({ path: `${n}.rules`, message: "条件格式应为数组" }));
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
function U(e, t, s) {
|
|
165
|
+
if (e !== void 0) {
|
|
166
|
+
if (!u(e)) {
|
|
167
|
+
s.push({ path: t, message: "分组应为对象" });
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
l(e, "field", t, s, !0);
|
|
171
|
+
for (const i of ["headerTemplate", "subtotalLabel"]) l(e, i, t, s);
|
|
172
|
+
for (const i of ["headerStyle", "subtotalStyle"]) d(e[i], `${t}.${i}`, s);
|
|
173
|
+
b(e, "keepWithNext", t, s), e.subtotal !== void 0 && (!Array.isArray(e.subtotal) || e.subtotal.some((i) => typeof i != "string")) && s.push({ path: `${t}.subtotal`, message: "小计字段应为字符串数组" });
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
function G(e, t, s) {
|
|
177
|
+
if (!(e === void 0 || typeof e == "boolean")) {
|
|
178
|
+
if (!u(e)) {
|
|
179
|
+
s.push({ path: t, message: "合计应为布尔值或对象" });
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
l(e, "label", t, s), d(e.style, `${t}.style`, s), e.fields !== void 0 && (!Array.isArray(e.fields) || e.fields.some((i) => typeof i != "string")) && s.push({ path: `${t}.fields`, message: "合计字段应为字符串数组" });
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
function W(e, t, s, i) {
|
|
186
|
+
const f = { kind: "rect", leftMm: 0, topMm: 0, widthMm: 1, heightMm: 1, grid: e };
|
|
187
|
+
if (v(f, s, i, []), E(f, s, i), !u(e) || !Array.isArray(e.cells)) return;
|
|
188
|
+
const n = e.cells, a = Array.isArray(t) ? t.length : 0;
|
|
189
|
+
if (n.length * a > M) {
|
|
190
|
+
i.push({ path: s, message: "表头逻辑网格超过 20 万格安全上限" });
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
e.cells.length || i.push({ path: `${s}.cells`, message: "表头至少需要一行" }), Array.isArray(e.colWidthsMm) && e.colWidthsMm.length !== a && i.push({ path: `${s}.colWidthsMm`, message: "表头列宽数量应与列表列数一致" }), Array.isArray(e.rowHeightsMm) && e.rowHeightsMm.length !== e.cells.length && i.push({ path: `${s}.rowHeightsMm`, message: "表头行高数量应与行数一致" }), Y(n, a, s, i);
|
|
194
|
+
}
|
|
195
|
+
function Y(e, t, s, i) {
|
|
196
|
+
const f = /* @__PURE__ */ new Set();
|
|
197
|
+
e.forEach((n, a) => {
|
|
198
|
+
if (!Array.isArray(n)) return;
|
|
199
|
+
let o = 0;
|
|
200
|
+
n.forEach((h, m) => {
|
|
201
|
+
for (; f.has(`${a}:${o}`); ) o++;
|
|
202
|
+
const r = u(h) && typeof h.colSpan == "number" ? h.colSpan : 1, g = u(h) && typeof h.rowSpan == "number" ? h.rowSpan : 1;
|
|
203
|
+
(o + r > t || a + g > e.length) && i.push({ path: `${s}.cells.${a}.${m}`, message: "表头合并区域超出表头边界" });
|
|
204
|
+
for (let y = a; y < Math.min(e.length, a + g); y++)
|
|
205
|
+
for (let A = o; A < Math.min(t, o + r); A++)
|
|
206
|
+
f.has(`${y}:${A}`) && i.push({ path: `${s}.cells.${a}.${m}`, message: "表头合并区域重叠" }), f.add(`${y}:${A}`);
|
|
207
|
+
o += r;
|
|
208
|
+
});
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
function z(e, t, s) {
|
|
212
|
+
for (const i of ["leftMm", "topMm"]) c(e, i, t, s, -1 / 0, !0);
|
|
213
|
+
c(e, "widthMm", t, s, Number.MIN_VALUE, !0), l(e, "dataset", t, s, !0), l(e, "title", t, s);
|
|
214
|
+
for (const i of ["rowKey", "revisionField", "sourceTokenField"]) l(e, i, t, s, e[i] !== void 0);
|
|
215
|
+
e.headerGrid !== void 0 && W(e.headerGrid, e.columns, `${t}.headerGrid`, s), e.layout !== void 0 && e.layout !== "page" && e.layout !== "wide" && s.push({ path: `${t}.layout`, message: "布局应为 page 或 wide" }), H(e.columns, `${t}.columns`, s);
|
|
216
|
+
for (const i of ["fontSizePt", "rowHeightMm"]) c(e, i, t, s, Number.MIN_VALUE);
|
|
217
|
+
c(e, "paddingMm", t, s);
|
|
218
|
+
for (const i of ["headerBold", "headerEveryPage", "border"]) b(e, i, t, s);
|
|
219
|
+
l(e, "headerBackgroundColor", t, s), $(e.align, `${t}.align`, s, !0), $(e.headerAlign, `${t}.headerAlign`, s), d(e.headerStyle, `${t}.headerStyle`, s), U(e.groupBy, `${t}.groupBy`, s), G(e.grandTotal, `${t}.grandTotal`, s);
|
|
220
|
+
}
|
|
221
|
+
function E(e, t, s) {
|
|
222
|
+
d(e.style, `${t}.style`, s);
|
|
223
|
+
for (const f of ["text", "rawText", "imageData", "fallbackText", "nid", "rkey"]) l(e, f, t, s);
|
|
224
|
+
if (e.lines !== void 0 && (!Array.isArray(e.lines) || e.lines.some((f) => typeof f != "string")) && s.push({ path: `${t}.lines`, message: "文本行应为字符串数组" }), Array.isArray(e.richParagraphs) && e.richParagraphs.forEach((f, n) => {
|
|
225
|
+
if (!u(f)) return;
|
|
226
|
+
const a = `${t}.richParagraphs.${n}`;
|
|
227
|
+
$(f.align, `${a}.align`, s);
|
|
228
|
+
for (const o of ["lineHeight", "spaceBeforeMm", "spaceAfterMm", "indentMm"]) c(f, o, a, s);
|
|
229
|
+
Array.isArray(f.segments) && f.segments.forEach((o, h) => {
|
|
230
|
+
const m = `${a}.segments.${h}`;
|
|
231
|
+
if (!u(o)) {
|
|
232
|
+
s.push({ path: m, message: "富文本片段应为对象" });
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
o.kind !== void 0 && o.kind !== "text" && o.kind !== "field" && s.push({ path: `${m}.kind`, message: "未知富文本片段类型" });
|
|
236
|
+
for (const r of ["text", "field"]) l(o, r, m, s);
|
|
237
|
+
d(o.style, `${m}.style`, s);
|
|
238
|
+
});
|
|
239
|
+
}), !u(e.grid)) return;
|
|
240
|
+
const i = e.grid;
|
|
241
|
+
c(i, "gapMm", `${t}.grid`, s), c(i, "paddingMm", `${t}.grid`, s);
|
|
242
|
+
for (const f of ["colWidthsMm", "rowHeightsMm"]) {
|
|
243
|
+
const n = i[f];
|
|
244
|
+
n !== void 0 && (!Array.isArray(n) || n.some((a) => typeof a != "number" || !Number.isFinite(a) || a < 0)) && s.push({ path: `${t}.grid.${f}`, message: "网格尺寸应为有限非负数字数组" });
|
|
245
|
+
}
|
|
246
|
+
Array.isArray(i.cells) && i.cells.forEach((f, n) => {
|
|
247
|
+
Array.isArray(f) && f.forEach((a, o) => {
|
|
248
|
+
const h = `${t}.grid.cells.${n}.${o}`;
|
|
249
|
+
if (a !== null) {
|
|
250
|
+
if (!u(a)) {
|
|
251
|
+
s.push({ path: h, message: "网格单元格应为对象或 null" });
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
for (const m of ["text", "rawText", "numberFormat"]) l(a, m, h, s);
|
|
255
|
+
for (const m of ["colSpan", "rowSpan"]) {
|
|
256
|
+
const r = a[m];
|
|
257
|
+
r !== void 0 && (typeof r != "number" || !Number.isInteger(r) || r <= 0) && s.push({ path: `${h}.${m}`, message: "跨度应为正整数" });
|
|
258
|
+
}
|
|
259
|
+
a.value !== void 0 && a.value !== null && !["string", "number", "boolean"].includes(typeof a.value) && s.push({ path: `${h}.value`, message: "Excel 原始值应为字符串、数字、布尔值或 null" }), d(a.style, `${h}.style`, s), a.children !== void 0 && (Array.isArray(a.children) ? a.children.forEach((m, r) => {
|
|
260
|
+
u(m) && E(m, `${h}.children.${r}`, s);
|
|
261
|
+
}) : s.push({ path: `${h}.children`, message: "嵌套组件应为数组" }));
|
|
262
|
+
}
|
|
263
|
+
});
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
function K(e) {
|
|
267
|
+
const t = [], s = [];
|
|
268
|
+
return k(e, t), t.length ? { ok: !1, errors: t, warnings: s } : (u(e) ? (e.schemaVersion !== void 0 && e.schemaVersion !== R && t.push({ path: "$.schemaVersion", message: "不支持的模板 schemaVersion" }), j(e.params, "$.params", t), !Array.isArray(e.pages) || e.pages.length === 0 ? t.push({ path: "$.pages", message: "模板至少需要一页" }) : e.pages.forEach((i, f) => {
|
|
269
|
+
const n = `$.pages.${f}`;
|
|
270
|
+
if (!u(i)) {
|
|
271
|
+
t.push({ path: n, message: "页应为对象" });
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
c(i, "widthMm", n, t, Number.MIN_VALUE, !0), c(i, "heightMm", n, t, Number.MIN_VALUE, !0), i.layout !== void 0 && i.layout !== "page" && i.layout !== "wide" && t.push({ path: `${n}.layout`, message: "布局应为 page 或 wide" }), typeof i.heightMm == "number" && i.heightMm >= 5e3 && t.push({ path: `${n}.heightMm`, message: "页高应小于 5000mm" });
|
|
275
|
+
for (const a of ["marginTopMm", "marginBottomMm", "marginLeftMm", "marginRightMm"]) c(i, a, n, t);
|
|
276
|
+
typeof i.widthMm == "number" && Number(i.marginLeftMm ?? 0) + Number(i.marginRightMm ?? 0) >= i.widthMm && t.push({ path: n, message: "横向页边距占满页面" }), typeof i.heightMm == "number" && Number(i.marginTopMm ?? 0) + Number(i.marginBottomMm ?? 0) >= i.heightMm && t.push({ path: n, message: "纵向页边距占满页面" }), Array.isArray(i.components) ? i.components.forEach((a, o) => {
|
|
277
|
+
const h = `${n}.components.${o}`;
|
|
278
|
+
u(a) && a.kind === "list" ? z(a, h, t) : (v(a, h, t, s), u(a) && E(a, h, t));
|
|
279
|
+
}) : t.push({ path: `${n}.components`, message: "组件应为数组" });
|
|
280
|
+
})) : t.push({ path: "$", message: "模板应为对象" }), { ok: t.length === 0, errors: t, warnings: s });
|
|
281
|
+
}
|
|
282
|
+
function X(e) {
|
|
283
|
+
const t = [], s = [];
|
|
284
|
+
if (k(e, t), t.length) return { ok: !1, errors: t, warnings: s };
|
|
285
|
+
if (!u(e)) t.push({ path: "$", message: "模板文档应为对象" });
|
|
286
|
+
else {
|
|
287
|
+
for (const f of Object.keys(e))
|
|
288
|
+
T.has(f) || t.push({ path: `$.${f}`, message: "模板文档存在未知字段;只保存模板与描述,不保存取数或业务数据" });
|
|
289
|
+
e.schemaVersion !== O && t.push({ path: "$.schemaVersion", message: "不支持的模板文档版本" });
|
|
290
|
+
for (const f of ["id", "name"]) l(e, f, "$", t, !0);
|
|
291
|
+
for (const f of ["revision", "description"]) l(e, f, "$", t);
|
|
292
|
+
const i = K(e.template);
|
|
293
|
+
t.push(...i.errors.map((f) => ({ ...f, path: `$.template${f.path.slice(1)}` }))), s.push(...i.warnings.map((f) => ({ ...f, path: `$.template${f.path.slice(1)}` })));
|
|
294
|
+
}
|
|
295
|
+
return { ok: t.length === 0, errors: t, warnings: s };
|
|
296
|
+
}
|
|
297
|
+
function S(e) {
|
|
298
|
+
const t = X(e);
|
|
299
|
+
if (!t.ok) throw new p(t.errors);
|
|
300
|
+
}
|
|
301
|
+
function q(e) {
|
|
302
|
+
const t = [];
|
|
303
|
+
if (k(e, t), t.length) throw new p(t);
|
|
304
|
+
const s = { ...e, schemaVersion: e.schemaVersion ?? O };
|
|
305
|
+
return S(s), w(s);
|
|
306
|
+
}
|
|
307
|
+
function ee(e) {
|
|
308
|
+
let t = e;
|
|
309
|
+
if (typeof e == "string") {
|
|
310
|
+
if (e.length > N)
|
|
311
|
+
throw new p([{ path: "$", message: "模板 JSON 超过 1000 万字符的导出/导入上限" }]);
|
|
312
|
+
try {
|
|
313
|
+
t = JSON.parse(e);
|
|
314
|
+
} catch {
|
|
315
|
+
throw new p([{ path: "$", message: "模板 JSON 语法无效" }]);
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
return S(t), w(t);
|
|
319
|
+
}
|
|
320
|
+
function te(e) {
|
|
321
|
+
S(e);
|
|
322
|
+
const t = JSON.stringify(e, null, 2);
|
|
323
|
+
if (t.length > N) throw new p([{ path: "$", message: "模板 JSON 超过 1000 万字符的导出/导入上限" }]);
|
|
324
|
+
return t;
|
|
325
|
+
}
|
|
326
|
+
function w(e) {
|
|
327
|
+
return JSON.parse(JSON.stringify(e));
|
|
328
|
+
}
|
|
329
|
+
function se(e = []) {
|
|
330
|
+
const t = /* @__PURE__ */ new Map(), s = {
|
|
331
|
+
get: (i) => {
|
|
332
|
+
const f = t.get(i);
|
|
333
|
+
return f ? w(f) : void 0;
|
|
334
|
+
},
|
|
335
|
+
list: () => Array.from(t.values(), ({ template: i, ...f }) => ({ ...f })),
|
|
336
|
+
register: (i, f = {}) => {
|
|
337
|
+
if (S(i), t.has(i.id) && !f.replace) throw new p([{ path: "$.id", message: `模板 ID ${i.id} 已注册;更新需显式 replace:true` }]);
|
|
338
|
+
t.set(i.id, w(i));
|
|
339
|
+
},
|
|
340
|
+
remove: (i) => t.delete(i)
|
|
341
|
+
};
|
|
342
|
+
for (const i of e) s.register(i);
|
|
343
|
+
return s;
|
|
344
|
+
}
|
|
345
|
+
export {
|
|
346
|
+
O as R,
|
|
347
|
+
p as a,
|
|
348
|
+
X as b,
|
|
349
|
+
se as c,
|
|
350
|
+
q as d,
|
|
351
|
+
ee as p,
|
|
352
|
+
te as s,
|
|
353
|
+
K as v
|
|
354
|
+
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
"use strict";const w=require("./render-plan-CckPEQyf.cjs"),M=/[\u3000-\u9fff\uff00-\uffef]/,s=new Uint8Array(128);{for(const t of"iljtf.,:;'`|!()[]")s[t.charCodeAt(0)]=1;for(const t of"mwMW@")s[t.charCodeAt(0)]=2;for(let t=48;t<=57;t++)s[t]=3;for(let t=65;t<=90;t++)s[t]=4;s[32]=5}const g=[.54,.26,.95,.59,.67,.3];function d(t){const e=t.charCodeAt(0);return e<128?g[s[e]]:M.test(t)?1:/[A-Z]/.test(t)?.67:.54}const o={measureMm(t,e){const{fontSizePt:i,bold:c=!1,letterSpacingPt:u=0}=e,r=25.4/72;let n=0;for(const h of t)n+=d(h);return c&&(n*=1.04),(n*i+u*Math.max(0,Array.from(t).length-1))*r}};function p(){return o}function A(t,e){return o.measureMm(t,e)}function x(t){let e;return{measureMm(i,c){if(e===void 0&&(e=t()),!e)return o.measureMm(i,c);const u=c.fontSizePt*96/72;e.font=`${c.italic?"italic ":""}${c.bold?"bold ":""}${u}px ${c.fontFamily??w.DEFAULT_FONT_FAMILY}`,"letterSpacing"in e&&(e.letterSpacing="0px");const r=(c.letterSpacingPt??0)*Math.max(0,Array.from(i).length-1);return e.measureText(i).width*25.4/96+r*25.4/72}}}function T(t,e,i){const c=[];let u="";const r=()=>{u&&(c.push({text:u,widthMm:i.measureMm(u,e),cjk:!1}),u="")};for(const n of t){if(n===`
|
|
2
|
+
`){r(),c.push({text:`
|
|
3
|
+
`,widthMm:0,cjk:!1,br:!0});continue}if(n===" "){r(),c.push({text:n,widthMm:i.measureMm(n,e),cjk:!1,space:!0});continue}if(M.test(n)){r(),c.push({text:n,widthMm:i.measureMm(n,e),cjk:!0});continue}u+=n}return r(),c}function S(t,e,i,c=o){if(!t)return[""];t=t.replace(/\r\n?/g,`
|
|
4
|
+
`);const u=[];let r="",n=0;const h=(i.letterSpacingPt??0)*25.4/72,f=()=>{u.push(r),r="",n=0};for(const a of T(t,i,c)){if(a.br){f();continue}const m=r.length>0?h:0;if(n+m+a.widthMm<=e){r+=a.text,n+=m+a.widthMm;continue}if(a.space){f();continue}if(a.cjk){r.length>0&&f(),r=a.text,n=a.widthMm;continue}if(r.length>0&&f(),a.widthMm<=e){r=a.text,n=a.widthMm;continue}for(const l of a.text)c.measureMm(r+l,i)>e&&r.length>0&&f(),r+=l,n=c.measureMm(r,i)}return f(),u}exports.charWidthEm=d;exports.createCanvasMeasurer=x;exports.createHeuristicMeasurer=p;exports.heuristicMeasurer=o;exports.measureTextMm=A;exports.wrapText=S;
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { D as M } from "./render-plan-uzZYYSy1.js";
|
|
2
|
+
const d = /[\u3000-\u9fff\uff00-\uffef]/, s = new Uint8Array(128);
|
|
3
|
+
{
|
|
4
|
+
for (const t of "iljtf.,:;'`|!()[]") s[t.charCodeAt(0)] = 1;
|
|
5
|
+
for (const t of "mwMW@") s[t.charCodeAt(0)] = 2;
|
|
6
|
+
for (let t = 48; t <= 57; t++) s[t] = 3;
|
|
7
|
+
for (let t = 65; t <= 90; t++) s[t] = 4;
|
|
8
|
+
s[32] = 5;
|
|
9
|
+
}
|
|
10
|
+
const w = [0.54, 0.26, 0.95, 0.59, 0.67, 0.3];
|
|
11
|
+
function g(t) {
|
|
12
|
+
const e = t.charCodeAt(0);
|
|
13
|
+
return e < 128 ? w[s[e]] : d.test(t) ? 1 : /[A-Z]/.test(t) ? 0.67 : 0.54;
|
|
14
|
+
}
|
|
15
|
+
const o = {
|
|
16
|
+
measureMm(t, e) {
|
|
17
|
+
const { fontSizePt: i, bold: c = !1, letterSpacingPt: f = 0 } = e, n = 25.4 / 72;
|
|
18
|
+
let r = 0;
|
|
19
|
+
for (const h of t)
|
|
20
|
+
r += g(h);
|
|
21
|
+
return c && (r *= 1.04), (r * i + f * Math.max(0, Array.from(t).length - 1)) * n;
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
function S() {
|
|
25
|
+
return o;
|
|
26
|
+
}
|
|
27
|
+
function T(t, e) {
|
|
28
|
+
return o.measureMm(t, e);
|
|
29
|
+
}
|
|
30
|
+
function b(t) {
|
|
31
|
+
let e;
|
|
32
|
+
return {
|
|
33
|
+
measureMm(i, c) {
|
|
34
|
+
if (e === void 0 && (e = t()), !e) return o.measureMm(i, c);
|
|
35
|
+
const f = c.fontSizePt * 96 / 72;
|
|
36
|
+
e.font = `${c.italic ? "italic " : ""}${c.bold ? "bold " : ""}${f}px ${c.fontFamily ?? M}`, "letterSpacing" in e && (e.letterSpacing = "0px");
|
|
37
|
+
const n = (c.letterSpacingPt ?? 0) * Math.max(0, Array.from(i).length - 1);
|
|
38
|
+
return e.measureText(i).width * 25.4 / 96 + n * 25.4 / 72;
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
function p(t, e, i) {
|
|
43
|
+
const c = [];
|
|
44
|
+
let f = "";
|
|
45
|
+
const n = () => {
|
|
46
|
+
f && (c.push({ text: f, widthMm: i.measureMm(f, e), cjk: !1 }), f = "");
|
|
47
|
+
};
|
|
48
|
+
for (const r of t) {
|
|
49
|
+
if (r === `
|
|
50
|
+
`) {
|
|
51
|
+
n(), c.push({ text: `
|
|
52
|
+
`, widthMm: 0, cjk: !1, br: !0 });
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
if (r === " ") {
|
|
56
|
+
n(), c.push({ text: r, widthMm: i.measureMm(r, e), cjk: !1, space: !0 });
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
if (d.test(r)) {
|
|
60
|
+
n(), c.push({ text: r, widthMm: i.measureMm(r, e), cjk: !0 });
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
f += r;
|
|
64
|
+
}
|
|
65
|
+
return n(), c;
|
|
66
|
+
}
|
|
67
|
+
function j(t, e, i, c = o) {
|
|
68
|
+
if (!t) return [""];
|
|
69
|
+
t = t.replace(/\r\n?/g, `
|
|
70
|
+
`);
|
|
71
|
+
const f = [];
|
|
72
|
+
let n = "", r = 0;
|
|
73
|
+
const h = (i.letterSpacingPt ?? 0) * 25.4 / 72, u = () => {
|
|
74
|
+
f.push(n), n = "", r = 0;
|
|
75
|
+
};
|
|
76
|
+
for (const a of p(t, i, c)) {
|
|
77
|
+
if (a.br) {
|
|
78
|
+
u();
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
const m = n.length > 0 ? h : 0;
|
|
82
|
+
if (r + m + a.widthMm <= e) {
|
|
83
|
+
n += a.text, r += m + a.widthMm;
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
if (a.space) {
|
|
87
|
+
u();
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
if (a.cjk) {
|
|
91
|
+
n.length > 0 && u(), n = a.text, r = a.widthMm;
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
if (n.length > 0 && u(), a.widthMm <= e) {
|
|
95
|
+
n = a.text, r = a.widthMm;
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
for (const l of a.text)
|
|
99
|
+
c.measureMm(n + l, i) > e && n.length > 0 && u(), n += l, r = c.measureMm(n, i);
|
|
100
|
+
}
|
|
101
|
+
return u(), f;
|
|
102
|
+
}
|
|
103
|
+
export {
|
|
104
|
+
b as a,
|
|
105
|
+
S as b,
|
|
106
|
+
g as c,
|
|
107
|
+
o as h,
|
|
108
|
+
T as m,
|
|
109
|
+
j as w
|
|
110
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";function r(e,i,s){e.editable!==void 0&&typeof e.editable!="boolean"&&s.push({path:`${i}.editable`,message:"编辑控制应为布尔值"}),e.valueType!==void 0&&!["text","number","boolean"].includes(e.valueType)&&s.push({path:`${i}.valueType`,message:"编辑类型应为 text、number 或 boolean"})}function $(e,i,s){r(e,i,s),m(e.source,`${i}.source`,s,!0),e.formula!==void 0&&typeof e.formula!="string"&&s.push({path:`${i}.formula`,message:"单元格公式应为字符串"})}function m(e,i,s,t=!1){if(e===void 0)return;if(!e||typeof e!="object"||Array.isArray(e)){s.push({path:i,message:"业务来源应为对象"});return}const a=e;for(const n of["datasetId",...t?["field"]:[]])(typeof a[n]!="string"||!a[n].trim())&&s.push({path:`${i}.${n}`,message:"业务标识应为非空字符串"});for(const n of["rowKey","revision"]){const o=a[n];o===void 0&&!(t&&n==="rowKey")||typeof o!="string"&&!(typeof o=="number"&&Number.isFinite(o))&&s.push({path:`${i}.${n}`,message:"业务键及修订号应为字符串或有限数字"})}a.sourceToken!==void 0&&typeof a.sourceToken!="string"&&s.push({path:`${i}.sourceToken`,message:"来源令牌应为字符串"})}const v=new Set(["text","image","barcode","qrcode","chart","line","rect","ellipse"]);function f(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function A(e,i,s,t){const a=e[i];(typeof a!="number"||!Number.isFinite(a))&&t.push({path:`${s}.${i}`,message:`应为有限数字,实际 ${JSON.stringify(a)}`})}function b(e,i,s){if(e!==void 0){const t=`${i}.table`;if(!f(e))s.push({path:t,message:"逻辑表来源应为对象"});else{m(e.source,`${t}.source`,s),(typeof e.id!="string"||!e.id.trim())&&s.push({path:`${t}.id`,message:"逻辑表 ID 应为非空字符串"});const a=e.role;["header","body","group-header","subtotal","grand-total"].includes(a)||s.push({path:`${t}.role`,message:"未知逻辑表行角色"});const n=e.rowIndex;(typeof n!="number"||!Number.isInteger(n)||(a==="header"?n!==-1:n<0))&&s.push({path:`${t}.rowIndex`,message:"表头索引应为 -1,内容行索引应为非负整数"}),(!Array.isArray(e.columnKeys)||e.columnKeys.some(o=>typeof o!="string"))&&s.push({path:`${t}.columnKeys`,message:"逻辑列字段应为字符串数组"}),e.layout!==void 0&&e.layout!=="page"&&e.layout!=="wide"&&s.push({path:`${t}.layout`,message:"布局应为 page 或 wide"}),e.title!==void 0&&typeof e.title!="string"&&s.push({path:`${t}.title`,message:"逻辑表名称应为字符串"})}}}function M(e,i,s,t){if(e!==void 0)if(!f(e)||!Array.isArray(e.cells))s.push({path:`${i}.grid.cells`,message:"grid.cells 应为二维数组"});else{const a=e.paddingMm;a!==void 0&&(typeof a!="number"||!Number.isFinite(a)||a<0)&&s.push({path:`${i}.grid.paddingMm`,message:"单元格内距应为有限非负数"}),e.cells.forEach((n,o)=>{if(!Array.isArray(n)){s.push({path:`${i}.grid.cells.${o}`,message:"行应为数组"});return}n.forEach((u,d)=>{if(u==null)return;const h=`${i}.grid.cells.${o}.${d}`;if(!f(u)){s.push({path:h,message:"网格单元格应为对象或 null"});return}$(u,h,s),Array.isArray(u.children)&&u.children.forEach((c,y)=>{g(c,`${i}.grid.cells.${o}.${d}.children.${y}`,s,t)})})})}}function w(e,i,s){e!==void 0&&(Array.isArray(e)?e.forEach((t,a)=>{(!f(t)||!Array.isArray(t.segments))&&s.push({path:`${i}.richParagraphs.${a}`,message:"段落缺少 segments 数组"})}):s.push({path:`${i}.richParagraphs`,message:"richParagraphs 应为数组"}))}function g(e,i,s,t=[]){if(!f(e)){s.push({path:i,message:"组件应为对象"});return}const a=e.kind;typeof a!="string"?s.push({path:`${i}.kind`,message:"组件缺少 kind 字符串"}):v.has(a)||t.push({path:`${i}.kind`,message:`未知组件类型 ${JSON.stringify(a)},将以兜底方式渲染`});for(const n of["leftMm","topMm","widthMm","heightMm"])A(e,n,i,s);typeof e.leftMm=="number"&&e.leftMm<-100&&s.push({path:`${i}.leftMm`,message:"几何数值异常(leftMm<-100)"});for(const n of["widthMm","heightMm"])typeof e[n]=="number"&&e[n]<0&&s.push({path:`${i}.${n}`,message:"组件尺寸不能为负数"});b(e.table,i,s),e.lineDirection!==void 0&&!["down","up"].includes(e.lineDirection)&&s.push({path:`${i}.lineDirection`,message:"线段方向应为 down 或 up"}),M(e.grid,i,s,t),w(e.richParagraphs,i,s)}function p(e,i,s,t=[]){if(!f(e)){s.push({path:i,message:"页应为对象"});return}const a=e.pageWidthMm,n=e.pageHeightMm;(typeof a!="number"||!Number.isFinite(a)||a<=0)&&s.push({path:`${i}.pageWidthMm`,message:`页宽非法: ${JSON.stringify(a)}`}),(typeof n!="number"||!(n>0&&n<5e3))&&s.push({path:`${i}.pageHeightMm`,message:`页高非法: ${JSON.stringify(n)}`}),e.layout!==void 0&&e.layout!=="page"&&e.layout!=="wide"&&s.push({path:`${i}.layout`,message:"布局应为 page 或 wide"});const o=e.components;Array.isArray(o)?Array.isArray(o)&&o.forEach((u,d)=>g(u,`${i}.components.${d}`,s,t)):s.push({path:`${i}.components`,message:"components 应为数组"})}function l(e){const i=[],s=[],t=f(e)?e.pages:void 0;if(!Array.isArray(t))i.push({path:"$.pages",message:e==null?"渲染计划为空":"渲染计划缺少 pages 数组"});else{t.forEach((n,o)=>p(n,`$.pages.${o}`,i,s)),t.length>2e3&&s.push({path:"$.pages",message:`页数异常大(${t.length} 页),渲染与打印耗时可能显著增加`});const a=t.reduce((n,o)=>n+(f(o)&&Array.isArray(o.components)?o.components.length:0),0);a>5e4&&s.push({path:"$.pages",message:`组件总数异常大(${a} 个),可能触发浏览器性能限制`})}return{ok:i.length===0,errors:i,warnings:s}}function k(e){const i=l(e);if(!i.ok){const s=i.errors.slice(0,3).map(t=>`${t.path}: ${t.message}`).join("; ");throw new Error(`渲染计划校验失败(${i.errors.length} 处): ${s}`)}return e.pages}exports.assertRenderPlan=k;exports.validateComponent=g;exports.validateEditableMetadata=r;exports.validatePage=p;exports.validateRenderPlan=l;
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
function c(e, i, s) {
|
|
2
|
+
e.editable !== void 0 && typeof e.editable != "boolean" && s.push({ path: `${i}.editable`, message: "编辑控制应为布尔值" }), e.valueType !== void 0 && !["text", "number", "boolean"].includes(e.valueType) && s.push({ path: `${i}.valueType`, message: "编辑类型应为 text、number 或 boolean" });
|
|
3
|
+
}
|
|
4
|
+
function y(e, i, s) {
|
|
5
|
+
c(e, i, s), h(e.source, `${i}.source`, s, !0), e.formula !== void 0 && typeof e.formula != "string" && s.push({ path: `${i}.formula`, message: "单元格公式应为字符串" });
|
|
6
|
+
}
|
|
7
|
+
function h(e, i, s, t = !1) {
|
|
8
|
+
if (e === void 0) return;
|
|
9
|
+
if (!e || typeof e != "object" || Array.isArray(e)) {
|
|
10
|
+
s.push({ path: i, message: "业务来源应为对象" });
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
const n = e;
|
|
14
|
+
for (const a of ["datasetId", ...t ? ["field"] : []])
|
|
15
|
+
(typeof n[a] != "string" || !n[a].trim()) && s.push({ path: `${i}.${a}`, message: "业务标识应为非空字符串" });
|
|
16
|
+
for (const a of ["rowKey", "revision"]) {
|
|
17
|
+
const o = n[a];
|
|
18
|
+
o === void 0 && !(t && a === "rowKey") || typeof o != "string" && !(typeof o == "number" && Number.isFinite(o)) && s.push({ path: `${i}.${a}`, message: "业务键及修订号应为字符串或有限数字" });
|
|
19
|
+
}
|
|
20
|
+
n.sourceToken !== void 0 && typeof n.sourceToken != "string" && s.push({ path: `${i}.sourceToken`, message: "来源令牌应为字符串" });
|
|
21
|
+
}
|
|
22
|
+
const l = /* @__PURE__ */ new Set([
|
|
23
|
+
"text",
|
|
24
|
+
"image",
|
|
25
|
+
"barcode",
|
|
26
|
+
"qrcode",
|
|
27
|
+
"chart",
|
|
28
|
+
"line",
|
|
29
|
+
"rect",
|
|
30
|
+
"ellipse"
|
|
31
|
+
]);
|
|
32
|
+
function f(e) {
|
|
33
|
+
return typeof e == "object" && e !== null && !Array.isArray(e);
|
|
34
|
+
}
|
|
35
|
+
function $(e, i, s, t) {
|
|
36
|
+
const n = e[i];
|
|
37
|
+
(typeof n != "number" || !Number.isFinite(n)) && t.push({ path: `${s}.${i}`, message: `应为有限数字,实际 ${JSON.stringify(n)}` });
|
|
38
|
+
}
|
|
39
|
+
function A(e, i, s) {
|
|
40
|
+
if (e !== void 0) {
|
|
41
|
+
const t = `${i}.table`;
|
|
42
|
+
if (!f(e)) s.push({ path: t, message: "逻辑表来源应为对象" });
|
|
43
|
+
else {
|
|
44
|
+
h(e.source, `${t}.source`, s), (typeof e.id != "string" || !e.id.trim()) && s.push({ path: `${t}.id`, message: "逻辑表 ID 应为非空字符串" });
|
|
45
|
+
const n = e.role;
|
|
46
|
+
["header", "body", "group-header", "subtotal", "grand-total"].includes(n) || s.push({ path: `${t}.role`, message: "未知逻辑表行角色" });
|
|
47
|
+
const a = e.rowIndex;
|
|
48
|
+
(typeof a != "number" || !Number.isInteger(a) || (n === "header" ? a !== -1 : a < 0)) && s.push({ path: `${t}.rowIndex`, message: "表头索引应为 -1,内容行索引应为非负整数" }), (!Array.isArray(e.columnKeys) || e.columnKeys.some((o) => typeof o != "string")) && s.push({ path: `${t}.columnKeys`, message: "逻辑列字段应为字符串数组" }), e.layout !== void 0 && e.layout !== "page" && e.layout !== "wide" && s.push({ path: `${t}.layout`, message: "布局应为 page 或 wide" }), e.title !== void 0 && typeof e.title != "string" && s.push({ path: `${t}.title`, message: "逻辑表名称应为字符串" });
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
function v(e, i, s, t) {
|
|
53
|
+
if (e !== void 0)
|
|
54
|
+
if (!f(e) || !Array.isArray(e.cells))
|
|
55
|
+
s.push({ path: `${i}.grid.cells`, message: "grid.cells 应为二维数组" });
|
|
56
|
+
else {
|
|
57
|
+
const n = e.paddingMm;
|
|
58
|
+
n !== void 0 && (typeof n != "number" || !Number.isFinite(n) || n < 0) && s.push({ path: `${i}.grid.paddingMm`, message: "单元格内距应为有限非负数" }), e.cells.forEach((a, o) => {
|
|
59
|
+
if (!Array.isArray(a)) {
|
|
60
|
+
s.push({ path: `${i}.grid.cells.${o}`, message: "行应为数组" });
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
a.forEach((u, d) => {
|
|
64
|
+
if (u == null) return;
|
|
65
|
+
const g = `${i}.grid.cells.${o}.${d}`;
|
|
66
|
+
if (!f(u)) {
|
|
67
|
+
s.push({ path: g, message: "网格单元格应为对象或 null" });
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
y(u, g, s), Array.isArray(u.children) && u.children.forEach((p, m) => {
|
|
71
|
+
r(p, `${i}.grid.cells.${o}.${d}.children.${m}`, s, t);
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
function b(e, i, s) {
|
|
78
|
+
e !== void 0 && (Array.isArray(e) ? e.forEach((t, n) => {
|
|
79
|
+
(!f(t) || !Array.isArray(t.segments)) && s.push({ path: `${i}.richParagraphs.${n}`, message: "段落缺少 segments 数组" });
|
|
80
|
+
}) : s.push({ path: `${i}.richParagraphs`, message: "richParagraphs 应为数组" }));
|
|
81
|
+
}
|
|
82
|
+
function r(e, i, s, t = []) {
|
|
83
|
+
if (!f(e)) {
|
|
84
|
+
s.push({ path: i, message: "组件应为对象" });
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
const n = e.kind;
|
|
88
|
+
typeof n != "string" ? s.push({ path: `${i}.kind`, message: "组件缺少 kind 字符串" }) : l.has(n) || t.push({
|
|
89
|
+
path: `${i}.kind`,
|
|
90
|
+
message: `未知组件类型 ${JSON.stringify(n)},将以兜底方式渲染`
|
|
91
|
+
});
|
|
92
|
+
for (const a of ["leftMm", "topMm", "widthMm", "heightMm"])
|
|
93
|
+
$(e, a, i, s);
|
|
94
|
+
typeof e.leftMm == "number" && e.leftMm < -100 && s.push({ path: `${i}.leftMm`, message: "几何数值异常(leftMm<-100)" });
|
|
95
|
+
for (const a of ["widthMm", "heightMm"])
|
|
96
|
+
typeof e[a] == "number" && e[a] < 0 && s.push({ path: `${i}.${a}`, message: "组件尺寸不能为负数" });
|
|
97
|
+
A(e.table, i, s), e.lineDirection !== void 0 && !["down", "up"].includes(e.lineDirection) && s.push({ path: `${i}.lineDirection`, message: "线段方向应为 down 或 up" }), v(e.grid, i, s, t), b(e.richParagraphs, i, s);
|
|
98
|
+
}
|
|
99
|
+
function M(e, i, s, t = []) {
|
|
100
|
+
if (!f(e)) {
|
|
101
|
+
s.push({ path: i, message: "页应为对象" });
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
const n = e.pageWidthMm, a = e.pageHeightMm;
|
|
105
|
+
(typeof n != "number" || !Number.isFinite(n) || n <= 0) && s.push({ path: `${i}.pageWidthMm`, message: `页宽非法: ${JSON.stringify(n)}` }), (typeof a != "number" || !(a > 0 && a < 5e3)) && s.push({ path: `${i}.pageHeightMm`, message: `页高非法: ${JSON.stringify(a)}` }), e.layout !== void 0 && e.layout !== "page" && e.layout !== "wide" && s.push({ path: `${i}.layout`, message: "布局应为 page 或 wide" });
|
|
106
|
+
const o = e.components;
|
|
107
|
+
Array.isArray(o) ? Array.isArray(o) && o.forEach(
|
|
108
|
+
(u, d) => r(u, `${i}.components.${d}`, s, t)
|
|
109
|
+
) : s.push({ path: `${i}.components`, message: "components 应为数组" });
|
|
110
|
+
}
|
|
111
|
+
function w(e) {
|
|
112
|
+
const i = [], s = [], t = f(e) ? e.pages : void 0;
|
|
113
|
+
if (!Array.isArray(t))
|
|
114
|
+
i.push({
|
|
115
|
+
path: "$.pages",
|
|
116
|
+
message: e == null ? "渲染计划为空" : "渲染计划缺少 pages 数组"
|
|
117
|
+
});
|
|
118
|
+
else {
|
|
119
|
+
t.forEach((a, o) => M(a, `$.pages.${o}`, i, s)), t.length > 2e3 && s.push({
|
|
120
|
+
path: "$.pages",
|
|
121
|
+
message: `页数异常大(${t.length} 页),渲染与打印耗时可能显著增加`
|
|
122
|
+
});
|
|
123
|
+
const n = t.reduce(
|
|
124
|
+
(a, o) => a + (f(o) && Array.isArray(o.components) ? o.components.length : 0),
|
|
125
|
+
0
|
|
126
|
+
);
|
|
127
|
+
n > 5e4 && s.push({
|
|
128
|
+
path: "$.pages",
|
|
129
|
+
message: `组件总数异常大(${n} 个),可能触发浏览器性能限制`
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
return { ok: i.length === 0, errors: i, warnings: s };
|
|
133
|
+
}
|
|
134
|
+
function k(e) {
|
|
135
|
+
const i = w(e);
|
|
136
|
+
if (!i.ok) {
|
|
137
|
+
const s = i.errors.slice(0, 3).map((t) => `${t.path}: ${t.message}`).join("; ");
|
|
138
|
+
throw new Error(`渲染计划校验失败(${i.errors.length} 处): ${s}`);
|
|
139
|
+
}
|
|
140
|
+
return e.pages;
|
|
141
|
+
}
|
|
142
|
+
export {
|
|
143
|
+
k as a,
|
|
144
|
+
M as b,
|
|
145
|
+
w as c,
|
|
146
|
+
c as d,
|
|
147
|
+
r as v
|
|
148
|
+
};
|