@guodun/antdv 1.7.9 → 1.7.11
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/dist/es/components/contract-signing-location/src/ContractSigningLocation.vue.mjs +295 -296
- package/dist/es/components/pro-contract-template-designer/src/ContractTemplateDesignerInspector.vue.mjs +247 -220
- package/dist/es/components/pro-contract-template-designer/src/ContractTemplateRendererField.vue.mjs +1 -1
- package/dist/es/components/pro-contract-template-designer/src/ContractTemplateSingleRenderer.vue.mjs +297 -294
- package/dist/es/components/pro-contract-template-designer/src/ProContractTemplateDesigner.vue.mjs +1 -2
- package/dist/es/components/pro-contract-template-designer/src/composables/use-template-designer.mjs +1 -1
- package/dist/es/components/pro-contract-template-designer/src/utils/contract-print-document.mjs +7 -1
- package/dist/es/components/pro-contract-template-designer/src/utils/template-renderer.mjs +113 -102
- package/dist/es/components/pro-contract-template-designer/src/utils/template-variable-render.mjs +35 -20
- package/dist/es/components/pro-contract-template-designer/style/index.css +1 -1
- package/dist/es/index.mjs +19 -19
- package/dist/lib/components/contract-signing-location/src/ContractSigningLocation.vue.cjs +1 -1
- package/dist/lib/components/pro-contract-template-designer/src/ContractTemplateDesignerInspector.vue.cjs +1 -1
- package/dist/lib/components/pro-contract-template-designer/src/ContractTemplateRendererField.vue.cjs +1 -1
- package/dist/lib/components/pro-contract-template-designer/src/ContractTemplateSingleRenderer.vue.cjs +1 -1
- package/dist/lib/components/pro-contract-template-designer/src/ProContractTemplateDesigner.vue.cjs +1 -1
- package/dist/lib/components/pro-contract-template-designer/src/composables/use-template-designer.cjs +1 -1
- package/dist/lib/components/pro-contract-template-designer/src/utils/contract-print-document.cjs +7 -1
- package/dist/lib/components/pro-contract-template-designer/src/utils/template-renderer.cjs +5 -3
- package/dist/lib/components/pro-contract-template-designer/src/utils/template-variable-render.cjs +1 -1
- package/dist/lib/components/pro-contract-template-designer/style/index.css +1 -1
- package/dist/lib/index.cjs +1 -1
- package/dist/theme/icon.css +1 -1
- package/dist/theme/index.css +1 -1
- package/dist/types/components/pro-contract-template-designer/src/types.d.ts +3 -0
- package/dist/types/components/pro-contract-template-designer/src/utils/contract-print-document.d.ts +1 -1
- package/dist/types/components/pro-contract-template-designer/src/utils/template-renderer.d.ts +2 -0
- package/dist/types/components/pro-contract-template-designer/src/utils/template-variable-render.d.ts +8 -2
- package/package.json +3 -2
package/dist/es/components/pro-contract-template-designer/src/utils/contract-print-document.mjs
CHANGED
|
@@ -244,7 +244,13 @@ ${e.decorationsHtml}
|
|
|
244
244
|
if (document.fonts)
|
|
245
245
|
await withTimeout(document.fonts.ready)
|
|
246
246
|
const metrics = measure()
|
|
247
|
-
|
|
247
|
+
try {
|
|
248
|
+
assertMetrics(metrics)
|
|
249
|
+
}
|
|
250
|
+
catch (error) {
|
|
251
|
+
// 样本宽度跟系统字体、浏览器缩放走,业务用户无法消除。偏差只记日志,底图和签署继续。
|
|
252
|
+
console.warn('[GD-SIGN-COORD]', error instanceof Error ? error.message : String(error))
|
|
253
|
+
}
|
|
248
254
|
ready = true
|
|
249
255
|
post('ready', { metrics })
|
|
250
256
|
observer = new ResizeObserver(() => {
|
|
@@ -3,11 +3,11 @@ import { resolveTemplateVariablePresentation as c } from "./template-variable-re
|
|
|
3
3
|
import { buildPageDecorationClassNames as l, buildPageDecorationsHtml as u, collectPageDecorationVariableKeys as d, normalizePageDecorations as f, validatePageDecorations as p } from "./page-decorations.mjs";
|
|
4
4
|
import { isContractTemplateFieldType as m } from "../types.mjs";
|
|
5
5
|
import { buildRadioOptionsHtml as h, formatContractTemplateRenderValue as g, isContractTemplateSelectionValue as _ } from "./advanced-controls.mjs";
|
|
6
|
-
import { CONTRACT_TEMPLATE_RESERVED_VARIABLE_KEYS as v, CONTRACT_TEMPLATE_VARIABLE_KEY_PATTERN as
|
|
7
|
-
import { isSafeContractImageUrl as
|
|
6
|
+
import { CONTRACT_TEMPLATE_RESERVED_VARIABLE_KEYS as v, CONTRACT_TEMPLATE_VARIABLE_KEY_PATTERN as y, DEFAULT_PAGE_SIZE as ee, resolvePageSize as te, validateContractTemplateVariableKey as ne } from "../composables/use-template-designer.mjs";
|
|
7
|
+
import { isSafeContractImageUrl as re } from "./image-url.mjs";
|
|
8
8
|
//#region src/components/pro-contract-template-designer/src/utils/template-renderer.ts
|
|
9
|
-
function
|
|
10
|
-
let t = Array.isArray(e?.variables) ? e.variables : [], n = t.map((e) =>
|
|
9
|
+
function ie(e) {
|
|
10
|
+
let t = Array.isArray(e?.variables) ? e.variables : [], n = t.map((e) => b(e)), r = {};
|
|
11
11
|
return t.forEach((e) => {
|
|
12
12
|
let t = typeof e?.key == "string" ? e.key : "";
|
|
13
13
|
if (t) {
|
|
@@ -27,30 +27,30 @@ function te(e) {
|
|
|
27
27
|
variables: n
|
|
28
28
|
};
|
|
29
29
|
}
|
|
30
|
-
function
|
|
30
|
+
function b(e) {
|
|
31
31
|
return JSON.parse(JSON.stringify(e));
|
|
32
32
|
}
|
|
33
|
-
var
|
|
33
|
+
var x = new Set([
|
|
34
34
|
"action",
|
|
35
35
|
"formaction",
|
|
36
36
|
"href",
|
|
37
37
|
"src",
|
|
38
38
|
"xlink:href"
|
|
39
|
-
]),
|
|
40
|
-
function
|
|
39
|
+
]), S = /<[^>]+data-template-variable=["']true["'][^>]*>/gi, C = 100, w = 6e3, T = 6, E = /^data:image\/(?:png|jpe?g|webp|gif);base64,[A-Za-z0-9+/=]+$/i;
|
|
40
|
+
function D(e) {
|
|
41
41
|
let t = {};
|
|
42
42
|
return (Array.isArray(e?.variables) ? e.variables : []).forEach((e) => {
|
|
43
|
-
e?.key && (t[e.key] =
|
|
43
|
+
e?.key && (t[e.key] = B(e));
|
|
44
44
|
}), t;
|
|
45
45
|
}
|
|
46
|
-
function
|
|
46
|
+
function ae(e, t) {
|
|
47
47
|
return {
|
|
48
|
-
...
|
|
48
|
+
...D(e),
|
|
49
49
|
...t ?? {}
|
|
50
50
|
};
|
|
51
51
|
}
|
|
52
|
-
function
|
|
53
|
-
let n =
|
|
52
|
+
function O(e, t) {
|
|
53
|
+
let n = A(e);
|
|
54
54
|
if (!e) return n;
|
|
55
55
|
let r = Array.isArray(e.variables) ? e.variables : [], i = new Set(r.map((e) => e?.key).filter(Boolean));
|
|
56
56
|
return Object.keys(t).forEach((e) => {
|
|
@@ -63,8 +63,8 @@ function M(e, t) {
|
|
|
63
63
|
});
|
|
64
64
|
}), r.forEach((e) => {
|
|
65
65
|
if (!e?.key) return;
|
|
66
|
-
let r =
|
|
67
|
-
if (e.required &&
|
|
66
|
+
let r = Z(e, t[e.key]), i = e.label || e.key;
|
|
67
|
+
if (e.required && N(r)) {
|
|
68
68
|
n.push({
|
|
69
69
|
type: "variable",
|
|
70
70
|
id: e.id,
|
|
@@ -74,39 +74,33 @@ function M(e, t) {
|
|
|
74
74
|
});
|
|
75
75
|
return;
|
|
76
76
|
}
|
|
77
|
-
if (
|
|
77
|
+
if (N(r)) return;
|
|
78
78
|
let a = e.type ?? "text";
|
|
79
|
-
a === "number" && !
|
|
79
|
+
a === "number" && !ue(r, e.precision, e.format) && n.push({
|
|
80
80
|
type: "variable",
|
|
81
81
|
id: e.id,
|
|
82
82
|
variableKey: e.key,
|
|
83
83
|
message: `${i} 不是合法数字或超出精度`,
|
|
84
84
|
code: "VARIABLE_TYPE_INVALID"
|
|
85
|
-
}), a === "checkbox" && !
|
|
85
|
+
}), a === "checkbox" && !de(r) && n.push({
|
|
86
86
|
type: "variable",
|
|
87
87
|
id: e.id,
|
|
88
88
|
variableKey: e.key,
|
|
89
89
|
message: `${i} 不是合法勾选值`,
|
|
90
90
|
code: "VARIABLE_TYPE_INVALID"
|
|
91
|
-
}), a === "date" && !
|
|
91
|
+
}), a === "date" && !Q(r) && n.push({
|
|
92
92
|
type: "variable",
|
|
93
93
|
id: e.id,
|
|
94
94
|
variableKey: e.key,
|
|
95
95
|
message: `${i} 不是合法日期`,
|
|
96
96
|
code: "VARIABLE_TYPE_INVALID"
|
|
97
|
-
}), a === "image" && !
|
|
97
|
+
}), a === "image" && !fe(String(r).trim()) && n.push({
|
|
98
98
|
type: "security",
|
|
99
99
|
id: e.id,
|
|
100
100
|
variableKey: e.key,
|
|
101
101
|
message: `${i} 必须使用安全的图片 data URL`,
|
|
102
102
|
code: "UNSAFE_IMAGE_URL"
|
|
103
|
-
}), a
|
|
104
|
-
type: "variable",
|
|
105
|
-
id: e.id,
|
|
106
|
-
variableKey: e.key,
|
|
107
|
-
message: `${i} 内容超出变量范围`,
|
|
108
|
-
code: "VARIABLE_OVERFLOW"
|
|
109
|
-
}), fe(a) && (pe(r, a !== "radio" && !!e.multiple) ? K(e) && !q(e, r) && n.push({
|
|
103
|
+
}), n.push(...k(e, r)), pe(a) && (me(r, a !== "radio" && !!e.multiple) ? U(e) && !W(e, r) && n.push({
|
|
110
104
|
type: "variable",
|
|
111
105
|
id: e.id,
|
|
112
106
|
variableKey: e.key,
|
|
@@ -121,10 +115,23 @@ function M(e, t) {
|
|
|
121
115
|
}));
|
|
122
116
|
}), n;
|
|
123
117
|
}
|
|
124
|
-
function
|
|
125
|
-
|
|
118
|
+
function k(e, t) {
|
|
119
|
+
if ((e.type ?? "text") !== "text") return [];
|
|
120
|
+
let n = Z(e, t);
|
|
121
|
+
if (N(n) || !he(e, String(n))) return [];
|
|
122
|
+
let r = e.label || e.key;
|
|
123
|
+
return [{
|
|
124
|
+
type: "variable",
|
|
125
|
+
id: e.id,
|
|
126
|
+
variableKey: e.key,
|
|
127
|
+
message: e.multiline ? `${r} 内容超出正文预留的${e.rows ?? 3}行,请缩短内容或调整模板行数` : `${r} 内容超出变量范围`,
|
|
128
|
+
code: "VARIABLE_OVERFLOW"
|
|
129
|
+
}];
|
|
126
130
|
}
|
|
127
|
-
function
|
|
131
|
+
function oe(e, t, n) {
|
|
132
|
+
return O(e, t);
|
|
133
|
+
}
|
|
134
|
+
function A(e) {
|
|
128
135
|
if (!e) return [{
|
|
129
136
|
type: "page",
|
|
130
137
|
id: "template",
|
|
@@ -145,7 +152,7 @@ function N(e) {
|
|
|
145
152
|
}), $(e.pageSize) || t.push({
|
|
146
153
|
type: "page",
|
|
147
154
|
id: "template-page-size",
|
|
148
|
-
message: `模板默认页面尺寸必须在 ${
|
|
155
|
+
message: `模板默认页面尺寸必须在 ${C} ~ ${w} CSS px 之间`,
|
|
149
156
|
code: "TEMPLATE_PAGE_SIZE_INVALID"
|
|
150
157
|
});
|
|
151
158
|
let i = /* @__PURE__ */ new Map();
|
|
@@ -159,7 +166,7 @@ function N(e) {
|
|
|
159
166
|
});
|
|
160
167
|
return;
|
|
161
168
|
}
|
|
162
|
-
let a = e.key.trim(), o = r.some((t) => t?.id !== e.id && typeof t?.key == "string" && t.key.trim() === a), s =
|
|
169
|
+
let a = e.key.trim(), o = r.some((t) => t?.id !== e.id && typeof t?.key == "string" && t.key.trim() === a), s = ne(e.key, r, e.id), c = !y.test(a) || v.has(a);
|
|
163
170
|
s && (c || !o || e.key !== a) && t.push({
|
|
164
171
|
type: "variable",
|
|
165
172
|
id: e.id || `variable-${n}`,
|
|
@@ -198,9 +205,9 @@ function N(e) {
|
|
|
198
205
|
type: "page",
|
|
199
206
|
id: `${e.id}-page-size`,
|
|
200
207
|
pageId: e.id,
|
|
201
|
-
message: `${e.title || `第 ${n + 1} 页`}:页面尺寸必须在 ${
|
|
208
|
+
message: `${e.title || `第 ${n + 1} 页`}:页面尺寸必须在 ${C} ~ ${w} CSS px 之间`,
|
|
202
209
|
code: "PAGE_SIZE_INVALID"
|
|
203
|
-
}),
|
|
210
|
+
}), se(e.contentHtml).forEach((e) => a.add(e)), ce(e.contentHtml).forEach((r, i) => {
|
|
204
211
|
t.push({
|
|
205
212
|
type: "security",
|
|
206
213
|
id: `${e.id}-security-${i}`,
|
|
@@ -229,59 +236,59 @@ function N(e) {
|
|
|
229
236
|
});
|
|
230
237
|
}), t.push(...p(e.pageDecorations, r)), t;
|
|
231
238
|
}
|
|
232
|
-
function
|
|
239
|
+
function j(e, t, n = {}) {
|
|
233
240
|
if (!e || !Array.isArray(e.pages)) return [];
|
|
234
|
-
let r = Array.isArray(e.variables) ? e.variables : [], i = new Map(r.filter((e) => e?.key).map((e) => [e.key, e])), a = o(e.pageSize) ? e.pageSize :
|
|
241
|
+
let r = Array.isArray(e.variables) ? e.variables : [], i = new Map(r.filter((e) => e?.key).map((e) => [e.key, e])), a = o(e.pageSize) ? e.pageSize : ee;
|
|
235
242
|
return e.pages.flatMap((o) => {
|
|
236
243
|
if (!o || typeof o.id != "string" || !o.id.trim() || typeof o.contentHtml != "string") return [];
|
|
237
|
-
let s =
|
|
244
|
+
let s = te(o.pageSize, a);
|
|
238
245
|
return [{
|
|
239
246
|
id: o.id,
|
|
240
247
|
title: o.title || "未命名页面",
|
|
241
248
|
format: s.format ?? "Custom",
|
|
242
249
|
width: s.width,
|
|
243
250
|
height: s.height,
|
|
244
|
-
contentHtml:
|
|
251
|
+
contentHtml: P(o.contentHtml, i, t, n),
|
|
245
252
|
...e.pageDecorations ? { pageDecorations: f(e.pageDecorations) } : {},
|
|
246
253
|
decorationVariables: r,
|
|
247
254
|
decorationValues: t
|
|
248
255
|
}];
|
|
249
256
|
});
|
|
250
257
|
}
|
|
251
|
-
function
|
|
252
|
-
return
|
|
258
|
+
function M(e, t, n = {}) {
|
|
259
|
+
return j(e, t, n).map((e, t, n) => {
|
|
253
260
|
let i = u(e.pageDecorations, t + 1, n.length, e.decorationVariables, e.decorationValues);
|
|
254
261
|
return `<section class="${l(e.pageDecorations, t + 1)}" data-page-id="${r(e.id)}" data-page-format="${r(e.format)}" data-page-width="${e.width}" data-page-height="${e.height}" style="width:${e.width}px;min-height:${e.height}px">${i}<div class="gd-contract-template-page__content">${e.contentHtml}</div></section>`;
|
|
255
262
|
}).join("\n");
|
|
256
263
|
}
|
|
257
|
-
function
|
|
264
|
+
function N(e) {
|
|
258
265
|
return e == null || e === "" || Array.isArray(e) && e.length === 0;
|
|
259
266
|
}
|
|
260
|
-
function
|
|
267
|
+
function P(e, n, r, i) {
|
|
261
268
|
if (!e) return e;
|
|
262
|
-
let o =
|
|
269
|
+
let o = J(e);
|
|
263
270
|
if (t()) {
|
|
264
271
|
let e = new DOMParser().parseFromString(o, "text/html");
|
|
265
272
|
return e.querySelectorAll("[data-template-variable]").forEach((e) => {
|
|
266
|
-
|
|
267
|
-
}), e.body.innerHTML;
|
|
273
|
+
F(e, n, r, i);
|
|
274
|
+
}), e.body.innerHTML.replace(/(<textarea\b[^>]*data-contract-render-control="true"[^>]*>)(?=[\r\n])/gi, "$1\n");
|
|
268
275
|
}
|
|
269
276
|
return s(o, (e, t) => {
|
|
270
277
|
let o = a(t, "data-key");
|
|
271
|
-
return o ?
|
|
278
|
+
return o ? I(n.get(o), o, r[o], i) : e;
|
|
272
279
|
});
|
|
273
280
|
}
|
|
274
|
-
function
|
|
281
|
+
function F(e, t, n, r) {
|
|
275
282
|
let i = e.dataset.key || "", a = t.get(i);
|
|
276
283
|
if (!i || !a) return;
|
|
277
|
-
let o = new DOMParser().parseFromString(
|
|
278
|
-
o && e.replaceWith(o);
|
|
284
|
+
let o = new DOMParser().parseFromString(I(a, i, n[i], r), "text/html").body.firstElementChild;
|
|
285
|
+
o && (o.tagName === "TEXTAREA" && (o.textContent = G(z(a, n[i]))), e.replaceWith(o));
|
|
279
286
|
}
|
|
280
|
-
function
|
|
281
|
-
return r.mode === "display" ?
|
|
287
|
+
function I(e, t, n, r) {
|
|
288
|
+
return r.mode === "display" ? L(e, t, n, r) : R(e, t, n, r);
|
|
282
289
|
}
|
|
283
|
-
function
|
|
284
|
-
let o = e?.type ?? "text", s =
|
|
290
|
+
function L(e, t, n, a) {
|
|
291
|
+
let o = e?.type ?? "text", s = z(e, n), l = o === "image" && !N(s) && !re(String(s)) ? "" : s, u = K(l), d = c({
|
|
285
292
|
type: o,
|
|
286
293
|
width: e?.width,
|
|
287
294
|
height: e?.height,
|
|
@@ -302,7 +309,7 @@ function B(e, t, n, a) {
|
|
|
302
309
|
"gd-contract-template-renderer__preview-control",
|
|
303
310
|
...d.classes,
|
|
304
311
|
a.activeKey === t ? "is-active" : "",
|
|
305
|
-
|
|
312
|
+
N(l) ? "is-empty" : ""
|
|
306
313
|
].filter(Boolean).join(" "))}"`,
|
|
307
314
|
`style="${r(d.styleText)}"`,
|
|
308
315
|
"data-contract-render-wrapper=\"true\"",
|
|
@@ -313,10 +320,10 @@ function B(e, t, n, a) {
|
|
|
313
320
|
a.disabled ? "" : "role=\"button\"",
|
|
314
321
|
a.disabled ? "" : "tabindex=\"0\""
|
|
315
322
|
].filter(Boolean).join(" ");
|
|
316
|
-
return o === "checkbox" ? `<span ${p}><span class="gd-contract-template-renderer__checkbox-mark" aria-hidden="true">${
|
|
323
|
+
return o === "checkbox" ? `<span ${p}><span class="gd-contract-template-renderer__checkbox-mark" aria-hidden="true">${q(l) ? "✓" : ""}</span>${i(f)}</span>` : o === "radio" ? `<span ${p}>${h(e?.options, V(l)) || i(e?.placeholder || f)}</span>` : o === "select" ? `<span ${p}>${i(H(e, l) || f)}</span>` : o === "image" && !N(l) ? `<span ${p}></span>` : `<span ${p}>${i(f)}</span>`;
|
|
317
324
|
}
|
|
318
|
-
function
|
|
319
|
-
let o = e?.type ?? "text", s = !!a.readonly, l =
|
|
325
|
+
function R(e, t, n, a) {
|
|
326
|
+
let o = e?.type ?? "text", s = !!a.readonly, l = G(z(e, n)), u = c({
|
|
320
327
|
type: o,
|
|
321
328
|
width: e?.width,
|
|
322
329
|
height: e?.height,
|
|
@@ -339,26 +346,30 @@ function V(e, t, n, a) {
|
|
|
339
346
|
d ? "disabled" : "",
|
|
340
347
|
s ? "readonly" : ""
|
|
341
348
|
].filter(Boolean).join(" "), p = `style="${r(u.styleText)}"`, m = r(["gd-contract-template-renderer__control", ...u.classes].join(" "));
|
|
342
|
-
if (o === "checkbox") return `<label class="${m}" ${p} data-contract-render-wrapper="true" data-key="${r(t)}"><input type="checkbox" ${f} ${
|
|
349
|
+
if (o === "checkbox") return `<label class="${m}" ${p} data-contract-render-wrapper="true" data-key="${r(t)}"><input type="checkbox" ${f} ${q(l) ? "checked" : ""}>${i(e?.checkedText || e?.label || t)}</label>`;
|
|
343
350
|
if (o === "radio") {
|
|
344
|
-
let a =
|
|
351
|
+
let a = z(e, n), o = h(e?.options, V(a)) || i(u.displayText || e?.placeholder || "");
|
|
345
352
|
return `<span class="${m}" ${p} data-contract-render-wrapper="true" data-key="${r(t)}">${o}</span>`;
|
|
346
353
|
}
|
|
347
354
|
if (s) return `<span class="${m}" ${p} data-contract-render-wrapper="true" data-key="${r(t)}">${i(u.displayText || l)}</span>`;
|
|
348
355
|
if (o === "number") return `<input class="${m}" ${p} type="number" ${f} value="${r(l)}" placeholder="${r(e?.placeholder || "")}">`;
|
|
349
356
|
if (o === "date") return `<input class="${m}" ${p} type="date" ${f} value="${r(l)}" placeholder="${r(e?.placeholder || "")}">`;
|
|
350
357
|
if (o === "select" || o.endsWith("-selector") || o === "custom") {
|
|
351
|
-
let a =
|
|
358
|
+
let a = z(e, n), s = o === "select" ? H(e, a) : g(a);
|
|
352
359
|
return `<span class="${m}" ${p} data-contract-render-wrapper="true" data-key="${r(t)}">${i(s)}</span>`;
|
|
353
360
|
}
|
|
354
|
-
|
|
361
|
+
if (e?.multiline) {
|
|
362
|
+
let t = /^[\r\n]/.test(l) ? "\n" : "";
|
|
363
|
+
return `<textarea class="${m}" ${p} ${f} placeholder="${r(e.placeholder || "")}">${t}${i(l)}</textarea>`;
|
|
364
|
+
}
|
|
365
|
+
return `<input class="${m}" ${p} type="text" ${f} value="${r(l)}" placeholder="${r(e?.placeholder || "")}">`;
|
|
355
366
|
}
|
|
356
|
-
function
|
|
357
|
-
if (!(e?.type === "select" && e.multiple &&
|
|
367
|
+
function z(e, t) {
|
|
368
|
+
if (!(e?.type === "select" && e.multiple && N(t))) return t ?? B(e);
|
|
358
369
|
}
|
|
359
|
-
function
|
|
370
|
+
function B(e) {
|
|
360
371
|
if (!e) return "";
|
|
361
|
-
if (e.type === "checkbox") return
|
|
372
|
+
if (e.type === "checkbox") return q(e.defaultValue);
|
|
362
373
|
if (e.type === "number" && e.defaultValue !== void 0) {
|
|
363
374
|
let t = Number(e.defaultValue);
|
|
364
375
|
return Number.isFinite(t) ? t : e.defaultValue;
|
|
@@ -374,13 +385,13 @@ function U(e) {
|
|
|
374
385
|
}
|
|
375
386
|
if (!e.type?.endsWith("-selector")) return e.defaultValue ?? "";
|
|
376
387
|
}
|
|
377
|
-
function
|
|
388
|
+
function V(e) {
|
|
378
389
|
if (!Array.isArray(e)) {
|
|
379
390
|
if (_(e)) return e.value;
|
|
380
391
|
if (typeof e == "string" || typeof e == "number") return e;
|
|
381
392
|
}
|
|
382
393
|
}
|
|
383
|
-
function
|
|
394
|
+
function H(e, t) {
|
|
384
395
|
let n = Array.isArray(t) ? t : [t];
|
|
385
396
|
if (n.length && n.every((e) => _(e))) return g(t);
|
|
386
397
|
let r = n.flatMap((t) => {
|
|
@@ -391,45 +402,45 @@ function G(e, t) {
|
|
|
391
402
|
});
|
|
392
403
|
return r.length ? r.join("、") : g(t);
|
|
393
404
|
}
|
|
394
|
-
function
|
|
405
|
+
function U(e) {
|
|
395
406
|
return (e.type === "select" || e.type === "radio") && !e.dataSource && Array.isArray(e.options) && e.options.length > 0;
|
|
396
407
|
}
|
|
397
|
-
function
|
|
408
|
+
function W(e, t) {
|
|
398
409
|
let n = Array.isArray(t) ? t : [t];
|
|
399
410
|
return n.length > 0 && n.every((t) => _(t) && (e.options ?? []).some((e) => String(e.value) === String(t.value)));
|
|
400
411
|
}
|
|
401
|
-
function
|
|
412
|
+
function G(e) {
|
|
402
413
|
return typeof e == "boolean" ? e ? "true" : "" : e == null ? "" : g(e);
|
|
403
414
|
}
|
|
404
|
-
function
|
|
415
|
+
function K(e) {
|
|
405
416
|
return typeof e == "boolean" ? e ? "true" : "false" : e == null ? "" : g(e);
|
|
406
417
|
}
|
|
407
|
-
function
|
|
418
|
+
function q(e) {
|
|
408
419
|
return e === !0 || e === "true" || e === "1" || e === "yes" || e === "是" || e === "已选";
|
|
409
420
|
}
|
|
410
|
-
function
|
|
421
|
+
function J(t) {
|
|
411
422
|
if (e()) {
|
|
412
423
|
let e = new DOMParser().parseFromString(t, "text/html");
|
|
413
424
|
return e.querySelectorAll("script,style,meta,link,iframe,object,embed").forEach((e) => e.remove()), e.querySelectorAll("*").forEach((e) => {
|
|
414
425
|
Array.from(e.attributes).forEach((t) => {
|
|
415
426
|
let n = t.name.toLowerCase();
|
|
416
|
-
(n.startsWith("on") || n === "srcdoc" ||
|
|
427
|
+
(n.startsWith("on") || n === "srcdoc" || x.has(n) && Y(t.value) || n === "style" && X(t.value)) && e.removeAttribute(t.name);
|
|
417
428
|
});
|
|
418
429
|
}), e.body.innerHTML;
|
|
419
430
|
}
|
|
420
431
|
return t.replace(/<\s*(script|style|iframe|object|embed)\b[^>]*>[\s\S]*?<\s*\/\s*\1\s*>/gi, "").replace(/<\s*\/?\s*(?:script|style|meta|link|iframe|object|embed)\b[^>]*>/gi, "").replace(/\s+on[a-z]+\s*=\s*(?:"[^"]*"|'[^']*'|[^\s>]+)/gi, "").replace(/\s+srcdoc\s*=\s*(?:"[^"]*"|'[^']*'|[^\s>]+)/gi, "").replace(/\s+(action|formaction|href|src|xlink:href)\s*=\s*(?:(["'])(.*?)\2|([^\s>]+))/gi, (e, t, n, r, i) => {
|
|
421
432
|
let a = r ?? i ?? "";
|
|
422
|
-
return
|
|
423
|
-
}).replace(/\s+style\s*=\s*(["'])(.*?)\1/gi, (e, t, n) =>
|
|
433
|
+
return Y(a) ? "" : n ? ` ${t}=${n}${a}${n}` : ` ${t}=${a}`;
|
|
434
|
+
}).replace(/\s+style\s*=\s*(["'])(.*?)\1/gi, (e, t, n) => X(n) ? "" : ` style=${t}${n}${t}`);
|
|
424
435
|
}
|
|
425
|
-
function
|
|
426
|
-
return n(e,
|
|
436
|
+
function se(e) {
|
|
437
|
+
return n(e, S, (e) => a(e, "data-key"));
|
|
427
438
|
}
|
|
428
|
-
function
|
|
439
|
+
function ce(e) {
|
|
429
440
|
let t = [];
|
|
430
|
-
return /<\s*(script|style|meta|link|iframe|object|embed)\b/i.test(e) && t.push("正文包含已移除的危险标签"), /\s(?:on[a-z]+|srcdoc)\s*=/i.test(e) && t.push("正文包含已移除的事件或嵌入属性"), (
|
|
441
|
+
return /<\s*(script|style|meta|link|iframe|object|embed)\b/i.test(e) && t.push("正文包含已移除的危险标签"), /\s(?:on[a-z]+|srcdoc)\s*=/i.test(e) && t.push("正文包含已移除的事件或嵌入属性"), (le(e) || /style\s*=\s*["'][^"']*(?:expression\s*\(|url\s*\(\s*["']?\s*(?:javascript|vbscript|data:text\/html))/i.test(e)) && t.push("正文包含已移除的危险 URL 或样式"), t;
|
|
431
442
|
}
|
|
432
|
-
function
|
|
443
|
+
function Y(e) {
|
|
433
444
|
let t = e.replace(/&#(?:x([\da-f]+)|(\d+));?/gi, (e, t, n) => {
|
|
434
445
|
let r = Number.parseInt(t ?? n ?? "", t ? 16 : 10);
|
|
435
446
|
try {
|
|
@@ -444,40 +455,40 @@ function Z(e) {
|
|
|
444
455
|
})[t.toLowerCase()] ?? "").trim().replace(/[\u0000-\u0020\u007F]+/g, "");
|
|
445
456
|
return /^(?:javascript|vbscript|data:text\/html)/i.test(t);
|
|
446
457
|
}
|
|
447
|
-
function
|
|
458
|
+
function le(e) {
|
|
448
459
|
let t = /\s+(?:action|formaction|href|src|xlink:href)\s*=\s*(?:(["'])(.*?)\1|([^\s>]+))/gi, n = t.exec(e);
|
|
449
460
|
for (; n;) {
|
|
450
|
-
if (
|
|
461
|
+
if (Y(n[2] ?? n[3] ?? "")) return !0;
|
|
451
462
|
n = t.exec(e);
|
|
452
463
|
}
|
|
453
464
|
return !1;
|
|
454
465
|
}
|
|
455
|
-
function
|
|
466
|
+
function X(e) {
|
|
456
467
|
return /expression\s*\(|url\s*\(\s*["']?\s*(?:javascript|vbscript|data:text\/html)/i.test(e);
|
|
457
468
|
}
|
|
458
|
-
function
|
|
459
|
-
return
|
|
469
|
+
function Z(e, t) {
|
|
470
|
+
return N(t) ? e.type === "select" || e.type === "radio" ? B(e) : N(e.defaultValue) ? t : e.defaultValue : t;
|
|
460
471
|
}
|
|
461
|
-
function
|
|
472
|
+
function ue(e, t, n) {
|
|
462
473
|
if (typeof e == "boolean" || typeof e != "number" && typeof e != "string") return !1;
|
|
463
|
-
let
|
|
464
|
-
if (!/^-?(?:\d+)(?:\.\d+)?$/.test(
|
|
465
|
-
let
|
|
466
|
-
if (!Number.isFinite(
|
|
474
|
+
let r = String(e).trim();
|
|
475
|
+
if (!/^-?(?:\d+)(?:\.\d+)?$/.test(r)) return !1;
|
|
476
|
+
let i = Number(r);
|
|
477
|
+
if (!Number.isFinite(i)) return !1;
|
|
467
478
|
if (t !== void 0) {
|
|
468
|
-
let e =
|
|
469
|
-
if (!Number.isInteger(t) || t < 0 || t >
|
|
479
|
+
let e = r.split(".")[1]?.length ?? 0, i = t + (n === "percent" ? 2 : 0);
|
|
480
|
+
if (!Number.isInteger(t) || t < 0 || t > T || e > i) return !1;
|
|
470
481
|
}
|
|
471
482
|
return !0;
|
|
472
483
|
}
|
|
473
|
-
function
|
|
484
|
+
function Q(e) {
|
|
474
485
|
if (typeof e != "string" && typeof e != "number") return !1;
|
|
475
486
|
let t = String(e).trim(), n = /^(\d{4})[-/年](\d{1,2})[-/月](\d{1,2})(?:日)?(?:[T\s].*)?$/.exec(t);
|
|
476
487
|
if (!n) return !1;
|
|
477
488
|
let r = Number(n[1]), i = Number(n[2]), a = Number(n[3]), o = new Date(Date.UTC(r, i - 1, a));
|
|
478
489
|
return o.getUTCFullYear() === r && o.getUTCMonth() === i - 1 && o.getUTCDate() === a;
|
|
479
490
|
}
|
|
480
|
-
function
|
|
491
|
+
function de(e) {
|
|
481
492
|
return typeof e == "boolean" ? !0 : [
|
|
482
493
|
"1",
|
|
483
494
|
"true",
|
|
@@ -493,16 +504,16 @@ function ue(e) {
|
|
|
493
504
|
"未选"
|
|
494
505
|
].includes(String(e).trim().toLowerCase());
|
|
495
506
|
}
|
|
496
|
-
function de(e) {
|
|
497
|
-
return k.test(e);
|
|
498
|
-
}
|
|
499
507
|
function fe(e) {
|
|
508
|
+
return E.test(e);
|
|
509
|
+
}
|
|
510
|
+
function pe(e) {
|
|
500
511
|
return e === "select" || e === "radio" || e === "user-selector" || e === "dept-selector" || e === "role-selector" || e === "org-selector";
|
|
501
512
|
}
|
|
502
|
-
function
|
|
513
|
+
function me(e, t) {
|
|
503
514
|
return t ? Array.isArray(e) && e.every(_) : _(e);
|
|
504
515
|
}
|
|
505
|
-
function
|
|
516
|
+
function he(e, t) {
|
|
506
517
|
let n = e.width;
|
|
507
518
|
if (!Number.isFinite(n) || n <= 0) return !1;
|
|
508
519
|
let r = Math.max(10, Number.isFinite(e.style?.fontSize) && (e.style?.fontSize ?? 0) > 0 ? e.style.fontSize : 14), i = Math.max(1, n - 12) / r, a = (e) => Array.from(e).reduce((e, t) => e + (/[^\x00-\x7f]/.test(t) ? 1 : .55), 0);
|
|
@@ -511,7 +522,7 @@ function me(e, t) {
|
|
|
511
522
|
function $(e) {
|
|
512
523
|
if (!e || typeof e != "object") return !1;
|
|
513
524
|
let { width: t, height: n } = e;
|
|
514
|
-
return typeof t == "number" && typeof n == "number" && Number.isFinite(t) && Number.isFinite(n) && t >=
|
|
525
|
+
return typeof t == "number" && typeof n == "number" && Number.isFinite(t) && Number.isFinite(n) && t >= C && n >= C && t <= w && n <= w;
|
|
515
526
|
}
|
|
516
527
|
//#endregion
|
|
517
|
-
export {
|
|
528
|
+
export { D as buildInitialRenderValues, M as buildTemplateRenderHtml, j as buildTemplateRenderPages, ie as buildTemplateVariableData, N as isEmptyRenderValue, ae as normalizeRenderValues, oe as resolveTemplateRenderSubmitErrors, J as sanitizeContractRendererHtml, A as validateTemplateRenderStructure, O as validateTemplateRenderValues, k as validateTemplateTextOverflow };
|
package/dist/es/components/pro-contract-template-designer/src/utils/template-variable-render.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { DEFAULT_CONTRACT_FONT_FAMILY as e } from "../constants.mjs";
|
|
2
2
|
//#region src/components/pro-contract-template-designer/src/utils/template-variable-render.ts
|
|
3
3
|
function t(t) {
|
|
4
|
-
let r = t.type === void 0 ? "text" : String(t.type), i = Math.max(24,
|
|
4
|
+
let r = t.type === void 0 ? "text" : String(t.type), i = Math.max(24, s(t.width, 160)), a = Math.max(24, s(t.height, 32)), c = t.style?.border ?? t.border ?? r === "image", l = t.style?.underline ?? t.underline ?? (r !== "image" && r !== "checkbox"), u = t.style?.color || t.color || "#1f2937", d = t.style?.background || t.background || "transparent", f = Math.max(10, s(t.style?.fontSize ?? t.fontSize, 14)), p = t.style?.fontFamily || t.fontFamily || e, m = t.style?.placeholderColor || t.placeholderColor || "#7a818b", h = t.style?.lineColor || t.lineColor || "#565b66", g = t.style?.textAlign || t.textAlign || "left", _ = t.style?.borderStyle || t.borderStyle || "solid", v = t.style?.objectFit || t.objectFit || "contain", y = !!t.multiline, b = Math.max(1, s(t.rows, 3)), x = Math.max(18, s(t.lineHeight, 28)), S = b * x, C = v === "fill" ? "100% 100%" : v, w = g === "right" ? "flex-end" : g === "center" ? "center" : "flex-start", T = r === "select" && t.multiple ? "" : String(t.defaultValue || ""), E = n({
|
|
5
5
|
type: r,
|
|
6
6
|
defaultValue: T,
|
|
7
7
|
placeholder: t.placeholder || "",
|
|
@@ -12,11 +12,11 @@ function t(t) {
|
|
|
12
12
|
uncheckedText: t.uncheckedText || "",
|
|
13
13
|
options: t.options,
|
|
14
14
|
multiple: t.multiple
|
|
15
|
-
}), D = T.trim().length > 0, O = !D && E.trim().length > 0, k = r === "checkbox" &&
|
|
15
|
+
}), D = T.trim().length > 0, O = !D && E.trim().length > 0, k = r === "checkbox" && o(T), A = r === "image" && D ? `;--gd-contract-variable-image:url('${T.replaceAll("'", "%27")}')` : "";
|
|
16
16
|
return {
|
|
17
17
|
type: r,
|
|
18
18
|
width: i,
|
|
19
|
-
height:
|
|
19
|
+
height: a,
|
|
20
20
|
border: c,
|
|
21
21
|
underline: l,
|
|
22
22
|
color: u,
|
|
@@ -42,24 +42,24 @@ function t(t) {
|
|
|
42
42
|
D ? "has-value" : "",
|
|
43
43
|
k ? "is-checked" : ""
|
|
44
44
|
].filter(Boolean),
|
|
45
|
-
styleText: `--gd-contract-variable-width:${i}px;--gd-contract-variable-height:${
|
|
45
|
+
styleText: `--gd-contract-variable-width:${i}px;--gd-contract-variable-height:${a}px;--gd-contract-variable-rows:${b};--gd-contract-variable-line-height:${x}px;--gd-contract-variable-multiline-height:${S}px;--gd-contract-variable-color:${u};--gd-contract-variable-background:${d};--gd-contract-variable-font-size:${f}px;--gd-contract-variable-font-family:${p};--gd-contract-variable-placeholder-color:${m};--gd-contract-variable-line-color:${h};--gd-contract-variable-text-align:${g};--gd-contract-variable-justify-content:${w};--gd-contract-variable-border-style:${_};--gd-contract-variable-object-fit:${C}${A}`
|
|
46
46
|
};
|
|
47
47
|
}
|
|
48
48
|
function n(e) {
|
|
49
|
-
let t = e.type || "text", n = t === "select" && e.multiple ? "" : e.defaultValue || "",
|
|
50
|
-
if (t === "checkbox") return n ?
|
|
51
|
-
if (!n) return
|
|
49
|
+
let t = e.type || "text", n = t === "select" && e.multiple ? "" : e.defaultValue || "", i = e.placeholder || "";
|
|
50
|
+
if (t === "checkbox") return n ? o(n) ? e.checkedText || i : e.uncheckedText || i : i;
|
|
51
|
+
if (!n) return i;
|
|
52
52
|
if (t === "date") return r(n, e.format || "");
|
|
53
|
-
if (t === "number") return
|
|
53
|
+
if (t === "number") return a(n, {
|
|
54
54
|
format: e.format || "",
|
|
55
55
|
precision: e.precision,
|
|
56
56
|
useGrouping: e.useGrouping
|
|
57
57
|
});
|
|
58
|
-
if (t === "image") return
|
|
58
|
+
if (t === "image") return i;
|
|
59
59
|
if (t === "select") {
|
|
60
60
|
let t = e.options?.find((e) => String(e.value ?? "") === n);
|
|
61
61
|
if (t?.label) return t.label;
|
|
62
|
-
if (e.options?.length) return
|
|
62
|
+
if (e.options?.length) return i;
|
|
63
63
|
}
|
|
64
64
|
return n;
|
|
65
65
|
}
|
|
@@ -70,17 +70,32 @@ function r(e, t) {
|
|
|
70
70
|
let [, r, i, a] = n;
|
|
71
71
|
return t.replace("YYYY", r).replace("MM", i.padStart(2, "0")).replace("DD", a.padStart(2, "0"));
|
|
72
72
|
}
|
|
73
|
-
|
|
73
|
+
var i = [
|
|
74
|
+
{
|
|
75
|
+
value: "decimal",
|
|
76
|
+
label: "常规数字"
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
value: "percent",
|
|
80
|
+
label: "百分比"
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
value: "currency",
|
|
84
|
+
label: "人民币金额"
|
|
85
|
+
}
|
|
86
|
+
];
|
|
87
|
+
function a(e, t) {
|
|
74
88
|
let n = Number(e);
|
|
75
|
-
if (!Number.isFinite(n)) return e;
|
|
76
|
-
let r = n.toLocaleString("zh-CN", {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
89
|
+
if (!e.trim() || !Number.isFinite(n)) return e;
|
|
90
|
+
let r = typeof t.precision == "number" && Number.isInteger(t.precision) && t.precision >= 0 && t.precision <= 20 ? t.precision : void 0, i = n.toLocaleString("zh-CN", {
|
|
91
|
+
style: t.format === "percent" ? "percent" : "decimal",
|
|
92
|
+
useGrouping: t.useGrouping === !0,
|
|
93
|
+
minimumFractionDigits: r ?? 0,
|
|
94
|
+
maximumFractionDigits: r ?? 20
|
|
80
95
|
});
|
|
81
|
-
return t.format === "currency" ? `¥${
|
|
96
|
+
return t.format === "currency" ? `¥${i}` : i;
|
|
82
97
|
}
|
|
83
|
-
function
|
|
98
|
+
function o(e) {
|
|
84
99
|
return [
|
|
85
100
|
"1",
|
|
86
101
|
"true",
|
|
@@ -90,10 +105,10 @@ function a(e) {
|
|
|
90
105
|
"已选"
|
|
91
106
|
].includes(e.trim().toLowerCase());
|
|
92
107
|
}
|
|
93
|
-
function
|
|
108
|
+
function s(e, t) {
|
|
94
109
|
if (e == null || e === "") return t;
|
|
95
110
|
let n = Number(e);
|
|
96
111
|
return Number.isFinite(n) ? n : t;
|
|
97
112
|
}
|
|
98
113
|
//#endregion
|
|
99
|
-
export { t as resolveTemplateVariablePresentation };
|
|
114
|
+
export { i as TEMPLATE_NUMBER_FORMAT_OPTIONS, t as resolveTemplateVariablePresentation };
|