@guodun/antdv 1.4.8 → 1.5.1
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 +315 -286
- package/dist/es/components/contract-signing-location/src/ContractSigningLocationCanvas.vue.mjs +316 -285
- package/dist/es/components/contract-signing-location/src/ContractSigningTemplatePage.vue.mjs +62 -54
- package/dist/es/components/contract-signing-location/style/index.css +1 -1
- package/dist/es/components/index.mjs +1 -0
- package/dist/es/components/pro-contract-template-designer/index.mjs +1 -0
- package/dist/es/components/pro-contract-template-designer/src/ContractPrintIframe.mjs +7 -0
- package/dist/es/components/pro-contract-template-designer/src/ContractPrintIframe.vue.mjs +129 -0
- package/dist/es/components/pro-contract-template-designer/src/ContractPrintIframe.vue_vue_type_style_index_0_scoped_a9912ff0_lang.css +1 -0
- package/dist/es/components/pro-contract-template-designer/src/ContractTemplatePreviewModal.vue.mjs +10 -5
- package/dist/es/components/pro-contract-template-designer/src/ContractTemplatePreviewPage.vue.mjs +64 -43
- package/dist/es/components/pro-contract-template-designer/src/ContractTemplateRendererPage.vue.mjs +82 -53
- package/dist/es/components/pro-contract-template-designer/src/DesignerPage.vue.mjs +271 -265
- package/dist/es/components/pro-contract-template-designer/src/ProContractTemplateDesigner.vue.mjs +762 -751
- package/dist/es/components/pro-contract-template-designer/src/ProContractTemplateRenderer.vue.mjs +217 -197
- package/dist/es/components/pro-contract-template-designer/src/constants.mjs +29 -51
- package/dist/es/components/pro-contract-template-designer/src/extensions/template-variable.mjs +103 -103
- package/dist/es/components/pro-contract-template-designer/src/extensions/word-paste.mjs +24 -21
- package/dist/es/components/pro-contract-template-designer/src/utils/contract-print-document.mjs +314 -0
- package/dist/es/components/pro-contract-template-designer/src/utils/page-decorations.mjs +1 -1
- package/dist/es/components/pro-contract-template-designer/src/utils/template-variable-render.mjs +47 -47
- package/dist/es/components/pro-contract-template-designer/src/utils/word-paste.mjs +216 -148
- package/dist/es/components/pro-contract-template-designer/style/index.css +1 -1
- package/dist/es/index.mjs +27 -26
- package/dist/lib/components/contract-signing-location/src/ContractSigningLocation.vue.cjs +1 -1
- package/dist/lib/components/contract-signing-location/src/ContractSigningLocationCanvas.vue.cjs +1 -1
- package/dist/lib/components/contract-signing-location/src/ContractSigningTemplatePage.vue.cjs +1 -1
- package/dist/lib/components/contract-signing-location/style/index.css +1 -1
- package/dist/lib/components/index.cjs +1 -1
- package/dist/lib/components/pro-contract-template-designer/index.cjs +1 -1
- package/dist/lib/components/pro-contract-template-designer/src/ContractPrintIframe.cjs +1 -0
- package/dist/lib/components/pro-contract-template-designer/src/ContractPrintIframe.vue.cjs +1 -0
- package/dist/lib/components/pro-contract-template-designer/src/ContractPrintIframe.vue_vue_type_style_index_0_scoped_a9912ff0_lang.css +1 -0
- package/dist/lib/components/pro-contract-template-designer/src/ContractTemplatePreviewModal.vue.cjs +1 -1
- package/dist/lib/components/pro-contract-template-designer/src/ContractTemplatePreviewPage.vue.cjs +1 -1
- package/dist/lib/components/pro-contract-template-designer/src/ContractTemplateRendererPage.vue.cjs +1 -1
- package/dist/lib/components/pro-contract-template-designer/src/DesignerPage.vue.cjs +2 -2
- package/dist/lib/components/pro-contract-template-designer/src/ProContractTemplateDesigner.vue.cjs +1 -1
- package/dist/lib/components/pro-contract-template-designer/src/ProContractTemplateRenderer.vue.cjs +1 -1
- package/dist/lib/components/pro-contract-template-designer/src/constants.cjs +1 -1
- package/dist/lib/components/pro-contract-template-designer/src/extensions/template-variable.cjs +1 -1
- package/dist/lib/components/pro-contract-template-designer/src/extensions/word-paste.cjs +1 -1
- package/dist/lib/components/pro-contract-template-designer/src/utils/contract-print-document.cjs +211 -0
- package/dist/lib/components/pro-contract-template-designer/src/utils/page-decorations.cjs +1 -1
- package/dist/lib/components/pro-contract-template-designer/src/utils/template-variable-render.cjs +1 -1
- package/dist/lib/components/pro-contract-template-designer/src/utils/word-paste.cjs +2 -2
- package/dist/lib/components/pro-contract-template-designer/style/index.css +1 -1
- package/dist/lib/index.cjs +1 -1
- package/dist/theme/contract-signing-location.css +1 -1
- package/dist/theme/icon.css +1 -1
- package/dist/theme/index.css +1 -1
- package/dist/types/components/contract-signing-location/src/ContractSigningLocation.vue.d.ts +7 -0
- package/dist/types/components/contract-signing-location/src/ContractSigningLocationCanvas.vue.d.ts +4 -0
- package/dist/types/components/contract-signing-location/src/ContractSigningTemplatePage.vue.d.ts +9 -3
- package/dist/types/components/contract-signing-location/src/types.d.ts +5 -0
- package/dist/types/components/pro-contract-template-designer/index.d.ts +1 -0
- package/dist/types/components/pro-contract-template-designer/src/ContractPrintIframe.vue.d.ts +35 -0
- package/dist/types/components/pro-contract-template-designer/src/ContractTemplateDesignerToolbar.vue.d.ts +2 -2
- package/dist/types/components/pro-contract-template-designer/src/ContractTemplatePreviewModal.vue.d.ts +1 -0
- package/dist/types/components/pro-contract-template-designer/src/ContractTemplatePreviewPage.vue.d.ts +1 -0
- package/dist/types/components/pro-contract-template-designer/src/ContractTemplateRendererPage.vue.d.ts +13 -1
- package/dist/types/components/pro-contract-template-designer/src/DesignerPage.vue.d.ts +6 -0
- package/dist/types/components/pro-contract-template-designer/src/ProContractTemplateDesigner.vue.d.ts +1 -0
- package/dist/types/components/pro-contract-template-designer/src/ProContractTemplateRenderer.vue.d.ts +1 -0
- package/dist/types/components/pro-contract-template-designer/src/constants.d.ts +4 -4
- package/dist/types/components/pro-contract-template-designer/src/extensions/word-paste.d.ts +8 -0
- package/dist/types/components/pro-contract-template-designer/src/types.d.ts +10 -0
- package/dist/types/components/pro-contract-template-designer/src/utils/contract-print-document.d.ts +119 -0
- package/dist/types/components/pro-contract-template-designer/src/utils/word-paste.d.ts +2 -0
- package/package.json +4 -3
package/dist/es/components/pro-contract-template-designer/src/utils/contract-print-document.mjs
ADDED
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
import { shallowRef as e } from "vue";
|
|
2
|
+
import { CONTRACT_PRINT_FONT_FAMILY as t, CONTRACT_PRINT_FONT_TIMEOUT_MS as n, CONTRACT_PRINT_METRIC_NORMALIZE_CSS as r, CONTRACT_PRINT_SANS_FONT_FAMILY as i, buildContractPrintCss as a } from "@guodun/contract-print-css";
|
|
3
|
+
//#region src/components/pro-contract-template-designer/src/utils/contract-print-document.ts
|
|
4
|
+
var o = "gd-contract-print", s = .5, c = "合同签署位置:甲方(Company A)编号 2026-08-31。", l = n + 1e3, u = /* @__PURE__ */ new Set();
|
|
5
|
+
function d(e) {
|
|
6
|
+
u.forEach((t) => t(e));
|
|
7
|
+
}
|
|
8
|
+
function f(e) {
|
|
9
|
+
u.size || window.addEventListener("message", d), u.add(e);
|
|
10
|
+
}
|
|
11
|
+
function p(e) {
|
|
12
|
+
u.delete(e), u.size || window.removeEventListener("message", d);
|
|
13
|
+
}
|
|
14
|
+
var m = "合同签署位置甲乙双方", h = ":,()。;", g = "20260831", _ = {
|
|
15
|
+
textWidth: 379.546875,
|
|
16
|
+
sansTextWidth: 393,
|
|
17
|
+
variableRowHeight: 28
|
|
18
|
+
}, v = "合同排版度量校验失败,禁止生成签署坐标", y = e("");
|
|
19
|
+
function b(e) {
|
|
20
|
+
y.value = (e?.baseUrl?.trim() ?? "").replace(/\/+$/, "");
|
|
21
|
+
}
|
|
22
|
+
function x(e) {
|
|
23
|
+
let t = e?.trim();
|
|
24
|
+
return t ? t.replace(/\/+$/, "") : y.value.trim().replace(/\/+$/, "");
|
|
25
|
+
}
|
|
26
|
+
function S(e, t = typeof window > "u" ? "" : window.location.origin) {
|
|
27
|
+
let n = e.trim().replace(/\/+$/, "");
|
|
28
|
+
return n ? /^https?:\/\//i.test(n) ? n : t ? new URL(n.startsWith("/") ? n : `/${n}`, `${t.replace(/\/+$/, "")}/`).href.replace(/\/+$/, "") : n.startsWith("/") ? n : `/${n}` : "";
|
|
29
|
+
}
|
|
30
|
+
function C(e) {
|
|
31
|
+
let l = `gd-contract-print-${e.messageId}`, u = a({
|
|
32
|
+
width: e.width,
|
|
33
|
+
height: e.height,
|
|
34
|
+
pages: [{
|
|
35
|
+
id: e.pageId,
|
|
36
|
+
pageSize: {
|
|
37
|
+
width: e.width,
|
|
38
|
+
height: e.height
|
|
39
|
+
}
|
|
40
|
+
}]
|
|
41
|
+
}), d = JSON.stringify({
|
|
42
|
+
messageId: e.messageId,
|
|
43
|
+
parentOrigin: e.parentOrigin,
|
|
44
|
+
pageId: e.pageId,
|
|
45
|
+
pageHeight: e.height,
|
|
46
|
+
timeoutMs: n,
|
|
47
|
+
fontFamily: t,
|
|
48
|
+
sansFontFamily: i,
|
|
49
|
+
latinFontFamily: "\"GD Contract Latin\", serif",
|
|
50
|
+
metricNormalizeCss: r.replace(/\s+/g, " ").trim(),
|
|
51
|
+
sample: c,
|
|
52
|
+
hanziSample: m,
|
|
53
|
+
punctSample: h,
|
|
54
|
+
digitSample: g,
|
|
55
|
+
hanziAdvance: 16,
|
|
56
|
+
punctAdvance: 16,
|
|
57
|
+
digitAdvance: 8,
|
|
58
|
+
baseline: _,
|
|
59
|
+
tolerance: s
|
|
60
|
+
}).replace(/</g, "\\u003c"), f = `width:${e.width}px;min-height:${e.height}px;padding-top:${e.paddingTop}px;padding-bottom:${e.paddingBottom}px`;
|
|
61
|
+
return `<!doctype html>
|
|
62
|
+
<html lang="zh-CN">
|
|
63
|
+
<head>
|
|
64
|
+
<meta charset="utf-8">
|
|
65
|
+
<meta name="color-scheme" content="light">
|
|
66
|
+
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; base-uri 'none'; object-src 'none'; form-action 'none'; connect-src 'none'; frame-src 'none'; worker-src 'none'; img-src data: blob: http: https:; font-src data: blob: http: https:; style-src 'unsafe-inline'; script-src 'nonce-${T(l)}'">
|
|
67
|
+
<style data-contract-render-style="true">
|
|
68
|
+
${w(u)}
|
|
69
|
+
</style>
|
|
70
|
+
</head>
|
|
71
|
+
<body>
|
|
72
|
+
<section class="${T(e.classNames)}" data-page-id="${T(e.pageId)}" data-page-format="${T(e.pageFormat ?? "Custom")}" data-page-width="${e.width}" data-page-height="${e.height}" style="${f}">
|
|
73
|
+
${e.decorationsHtml}
|
|
74
|
+
<div class="gd-contract-template-page__content">${e.contentHtml}</div>
|
|
75
|
+
</section>
|
|
76
|
+
<script nonce="${T(l)}">
|
|
77
|
+
(() => {
|
|
78
|
+
'use strict'
|
|
79
|
+
const config = ${d}
|
|
80
|
+
const namespace = ${JSON.stringify(o)}
|
|
81
|
+
const page = document.querySelector('.gd-contract-template-page')
|
|
82
|
+
let ready = false
|
|
83
|
+
let observer
|
|
84
|
+
|
|
85
|
+
const post = (type, payload = {}) => {
|
|
86
|
+
if (!config.parentOrigin)
|
|
87
|
+
return
|
|
88
|
+
parent.postMessage({ namespace, messageId: config.messageId, type, ...payload }, config.parentOrigin)
|
|
89
|
+
}
|
|
90
|
+
const getControl = (target) => target instanceof Element
|
|
91
|
+
? target.closest('[data-contract-render-wrapper], [data-contract-render-control]')
|
|
92
|
+
: null
|
|
93
|
+
const postSelection = (target) => {
|
|
94
|
+
const control = getControl(target)
|
|
95
|
+
const key = control?.getAttribute('data-key') || ''
|
|
96
|
+
if (key)
|
|
97
|
+
post('interaction', { interaction: { kind: 'select', key, pageId: config.pageId } })
|
|
98
|
+
}
|
|
99
|
+
addEventListener('click', event => postSelection(event.target))
|
|
100
|
+
addEventListener('focusin', event => postSelection(event.target))
|
|
101
|
+
addEventListener('keydown', (event) => {
|
|
102
|
+
if (event.key !== 'Enter' && event.key !== ' ')
|
|
103
|
+
return
|
|
104
|
+
if (event.target instanceof HTMLInputElement || event.target instanceof HTMLTextAreaElement)
|
|
105
|
+
return
|
|
106
|
+
const key = event.target instanceof HTMLElement ? event.target.getAttribute('data-key') || '' : ''
|
|
107
|
+
if (!key)
|
|
108
|
+
return
|
|
109
|
+
event.preventDefault()
|
|
110
|
+
post('interaction', { interaction: { kind: 'select', key, pageId: config.pageId } })
|
|
111
|
+
})
|
|
112
|
+
const postInput = (event) => {
|
|
113
|
+
const target = event.target
|
|
114
|
+
if (!(target instanceof HTMLInputElement) && !(target instanceof HTMLTextAreaElement))
|
|
115
|
+
return
|
|
116
|
+
const key = target.getAttribute('data-key') || ''
|
|
117
|
+
if (!key)
|
|
118
|
+
return
|
|
119
|
+
let value = target.value
|
|
120
|
+
if (target instanceof HTMLInputElement && target.type === 'checkbox')
|
|
121
|
+
value = target.checked
|
|
122
|
+
else if (target instanceof HTMLInputElement && target.type === 'number')
|
|
123
|
+
value = target.value === '' ? undefined : target.valueAsNumber
|
|
124
|
+
post('interaction', { interaction: { kind: 'input', key, pageId: config.pageId, value } })
|
|
125
|
+
}
|
|
126
|
+
addEventListener('input', postInput)
|
|
127
|
+
addEventListener('change', postInput)
|
|
128
|
+
addEventListener('message', (event) => {
|
|
129
|
+
const message = event.data
|
|
130
|
+
if (event.source !== parent
|
|
131
|
+
|| event.origin !== config.parentOrigin
|
|
132
|
+
|| !message
|
|
133
|
+
|| message.namespace !== namespace
|
|
134
|
+
|| message.messageId !== config.messageId
|
|
135
|
+
|| message.type !== 'command'
|
|
136
|
+
|| message.command?.kind !== 'highlight'
|
|
137
|
+
|| typeof message.command.key !== 'string'
|
|
138
|
+
|| typeof message.command.scroll !== 'boolean')
|
|
139
|
+
return
|
|
140
|
+
const key = message.command.key
|
|
141
|
+
const controls = document.querySelectorAll('[data-contract-render-wrapper], [data-contract-render-control]')
|
|
142
|
+
let firstMatch
|
|
143
|
+
controls.forEach((control) => {
|
|
144
|
+
const active = Boolean(key) && control.getAttribute('data-key') === key
|
|
145
|
+
control.classList.toggle('is-active', active)
|
|
146
|
+
if (active && !firstMatch)
|
|
147
|
+
firstMatch = control
|
|
148
|
+
})
|
|
149
|
+
if (message.command.scroll)
|
|
150
|
+
firstMatch?.scrollIntoView({ behavior: 'smooth', block: 'center', inline: 'center' })
|
|
151
|
+
})
|
|
152
|
+
const measure = () => {
|
|
153
|
+
if (!page)
|
|
154
|
+
throw new Error('合同打印页节点不存在')
|
|
155
|
+
const probeStyle = 'position:absolute;visibility:hidden;white-space:nowrap;' + config.metricNormalizeCss + ';'
|
|
156
|
+
const fontProbe = document.createElement('span')
|
|
157
|
+
fontProbe.textContent = config.sample
|
|
158
|
+
fontProbe.style.cssText = probeStyle + 'font:400 16px/28px ' + config.fontFamily
|
|
159
|
+
const sansFontProbe = document.createElement('span')
|
|
160
|
+
sansFontProbe.textContent = config.sample
|
|
161
|
+
sansFontProbe.style.cssText = probeStyle + 'font:400 16px/28px ' + config.sansFontFamily
|
|
162
|
+
const hanziProbe = document.createElement('span')
|
|
163
|
+
hanziProbe.textContent = config.hanziSample
|
|
164
|
+
hanziProbe.style.cssText = probeStyle + 'font:400 16px/28px ' + config.fontFamily
|
|
165
|
+
const punctProbe = document.createElement('span')
|
|
166
|
+
punctProbe.textContent = config.punctSample
|
|
167
|
+
punctProbe.style.cssText = probeStyle + 'font:400 16px/28px ' + config.fontFamily
|
|
168
|
+
const digitProbe = document.createElement('span')
|
|
169
|
+
digitProbe.textContent = config.digitSample
|
|
170
|
+
digitProbe.style.cssText = probeStyle + 'font:400 16px/28px ' + config.latinFontFamily
|
|
171
|
+
const rowProbe = document.createElement('p')
|
|
172
|
+
rowProbe.style.cssText = 'position:absolute;visibility:hidden;width:320px;margin:0;' + config.metricNormalizeCss + ';font:400 16px/28px ' + config.fontFamily
|
|
173
|
+
rowProbe.innerHTML = '甲方:<span class="gd-contract-template-variable" style="--gd-contract-variable-width:96px">变量ABC123</span>,合同编号 2026。'
|
|
174
|
+
document.body.append(fontProbe, sansFontProbe, hanziProbe, punctProbe, digitProbe, rowProbe)
|
|
175
|
+
const pageStyle = getComputedStyle(page)
|
|
176
|
+
const pageTop = page.getBoundingClientRect().top
|
|
177
|
+
const probeOffsets = {}
|
|
178
|
+
page.querySelectorAll('[data-probe]').forEach((probe) => {
|
|
179
|
+
const key = probe.getAttribute('data-probe')
|
|
180
|
+
if (key)
|
|
181
|
+
probeOffsets[key] = probe.getBoundingClientRect().top - pageTop
|
|
182
|
+
})
|
|
183
|
+
const content = page.querySelector('.gd-contract-template-page__content')
|
|
184
|
+
const blocks = content
|
|
185
|
+
? Array.from(content.children).map((block) => {
|
|
186
|
+
const rect = block.getBoundingClientRect()
|
|
187
|
+
const lineHeight = Number.parseFloat(getComputedStyle(block).lineHeight) || 28
|
|
188
|
+
return {
|
|
189
|
+
text: (block.textContent || '').replace(/\\s+/gu, ' ').trim().slice(0, 14),
|
|
190
|
+
top: Math.round((rect.top - pageTop) * 100) / 100,
|
|
191
|
+
lineCount: Math.round(rect.height / lineHeight),
|
|
192
|
+
}
|
|
193
|
+
})
|
|
194
|
+
: []
|
|
195
|
+
const metrics = {
|
|
196
|
+
pageWidth: page.offsetWidth,
|
|
197
|
+
pageHeight: page.offsetHeight,
|
|
198
|
+
contentHeight: page.scrollHeight,
|
|
199
|
+
overflowHeight: Math.max(0, page.scrollHeight - config.pageHeight),
|
|
200
|
+
paddingTop: Number.parseFloat(pageStyle.paddingTop),
|
|
201
|
+
paddingBottom: Number.parseFloat(pageStyle.paddingBottom),
|
|
202
|
+
paddingLeft: Number.parseFloat(pageStyle.paddingLeft),
|
|
203
|
+
paddingRight: Number.parseFloat(pageStyle.paddingRight),
|
|
204
|
+
fontSize: Number.parseFloat(pageStyle.fontSize),
|
|
205
|
+
lineHeight: Number.parseFloat(pageStyle.lineHeight),
|
|
206
|
+
fontFamily: pageStyle.fontFamily,
|
|
207
|
+
textWidth: fontProbe.getBoundingClientRect().width,
|
|
208
|
+
sansTextWidth: sansFontProbe.getBoundingClientRect().width,
|
|
209
|
+
hanziWidth: hanziProbe.getBoundingClientRect().width,
|
|
210
|
+
punctWidth: punctProbe.getBoundingClientRect().width,
|
|
211
|
+
digitWidth: digitProbe.getBoundingClientRect().width,
|
|
212
|
+
variableRowHeight: rowProbe.getBoundingClientRect().height,
|
|
213
|
+
probeOffsets,
|
|
214
|
+
blocks,
|
|
215
|
+
}
|
|
216
|
+
fontProbe.remove()
|
|
217
|
+
sansFontProbe.remove()
|
|
218
|
+
hanziProbe.remove()
|
|
219
|
+
punctProbe.remove()
|
|
220
|
+
digitProbe.remove()
|
|
221
|
+
rowProbe.remove()
|
|
222
|
+
return metrics
|
|
223
|
+
}
|
|
224
|
+
const assertAdvance = (label, actual, expected) => {
|
|
225
|
+
if (!Number.isFinite(actual) || Math.abs(actual - expected) > config.tolerance)
|
|
226
|
+
throw new Error('合同排版度量不一致:' + label + ' expected=' + expected + ' actual=' + actual + ' tolerance=' + config.tolerance)
|
|
227
|
+
}
|
|
228
|
+
const assertMetrics = (metrics) => {
|
|
229
|
+
assertAdvance('hanziWidth', metrics.hanziWidth, config.hanziSample.length * config.hanziAdvance)
|
|
230
|
+
assertAdvance('punctWidth', metrics.punctWidth, config.punctSample.length * config.punctAdvance)
|
|
231
|
+
assertAdvance('digitWidth', metrics.digitWidth, config.digitSample.length * config.digitAdvance)
|
|
232
|
+
for (const key of ['textWidth', 'sansTextWidth', 'variableRowHeight']) {
|
|
233
|
+
const expected = Number(config.baseline[key])
|
|
234
|
+
const actual = Number(metrics[key])
|
|
235
|
+
if (!(expected > 0) || !Number.isFinite(actual) || Math.abs(actual - expected) > config.tolerance)
|
|
236
|
+
throw new Error('合同排版度量不一致:' + key + ' expected=' + expected + ' actual=' + actual + ' tolerance=' + config.tolerance)
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
const withTimeout = (promise) => Promise.race([
|
|
240
|
+
promise,
|
|
241
|
+
new Promise((_, reject) => setTimeout(() => reject(new Error('合同排版度量校验超时(' + config.timeoutMs + 'ms)')), config.timeoutMs)),
|
|
242
|
+
])
|
|
243
|
+
const start = async () => {
|
|
244
|
+
if (document.fonts)
|
|
245
|
+
await withTimeout(document.fonts.ready)
|
|
246
|
+
const metrics = measure()
|
|
247
|
+
assertMetrics(metrics)
|
|
248
|
+
ready = true
|
|
249
|
+
post('ready', { metrics })
|
|
250
|
+
observer = new ResizeObserver(() => {
|
|
251
|
+
if (!ready)
|
|
252
|
+
return
|
|
253
|
+
try {
|
|
254
|
+
post('metrics', { metrics: measure() })
|
|
255
|
+
}
|
|
256
|
+
catch (error) {
|
|
257
|
+
ready = false
|
|
258
|
+
observer?.disconnect()
|
|
259
|
+
post('error', { error: error instanceof Error ? error.message : String(error) })
|
|
260
|
+
}
|
|
261
|
+
})
|
|
262
|
+
observer.observe(page)
|
|
263
|
+
}
|
|
264
|
+
start().catch((error) => {
|
|
265
|
+
post('error', { error: error instanceof Error ? error.message : String(error) })
|
|
266
|
+
})
|
|
267
|
+
addEventListener('pagehide', () => observer?.disconnect(), { once: true })
|
|
268
|
+
})()
|
|
269
|
+
<\/script>
|
|
270
|
+
</body>
|
|
271
|
+
</html>`;
|
|
272
|
+
}
|
|
273
|
+
function w(e) {
|
|
274
|
+
return e.replace(/<\/style/gi, "<\\/style");
|
|
275
|
+
}
|
|
276
|
+
function T(e) {
|
|
277
|
+
return String(e).replace(/&/g, "&").replace(/"/g, """).replace(/</g, "<").replace(/>/g, ">");
|
|
278
|
+
}
|
|
279
|
+
function E(e) {
|
|
280
|
+
if (!e || typeof e != "object") return !1;
|
|
281
|
+
let t = e;
|
|
282
|
+
return t.namespace === "gd-contract-print" && typeof t.messageId == "string" && /^gd-contract-print-[A-Za-z0-9-]{8,160}$/.test(t.messageId) && (t.type === "ready" || t.type === "metrics" || t.type === "error" || t.type === "interaction") ? t.type === "error" ? typeof t.error == "string" && t.error.length <= 2e3 : t.type === "interaction" ? D(t.interaction) : O(t.metrics) : !1;
|
|
283
|
+
}
|
|
284
|
+
function D(e) {
|
|
285
|
+
if (!e || typeof e != "object") return !1;
|
|
286
|
+
let t = e;
|
|
287
|
+
return typeof t.key != "string" || !/^[A-Za-z][A-Za-z0-9_]{1,63}$/.test(t.key) || typeof t.pageId != "string" || !t.pageId || t.pageId.length > 256 ? !1 : t.kind === "select" ? !0 : t.kind === "input" && (t.value === void 0 || typeof t.value == "string" && t.value.length <= 1e6 || typeof t.value == "number" && Number.isFinite(t.value) || typeof t.value == "boolean");
|
|
288
|
+
}
|
|
289
|
+
function O(e) {
|
|
290
|
+
if (!e || typeof e != "object") return !1;
|
|
291
|
+
let t = e;
|
|
292
|
+
if (![
|
|
293
|
+
"pageWidth",
|
|
294
|
+
"pageHeight",
|
|
295
|
+
"contentHeight",
|
|
296
|
+
"overflowHeight",
|
|
297
|
+
"paddingTop",
|
|
298
|
+
"paddingBottom",
|
|
299
|
+
"paddingLeft",
|
|
300
|
+
"paddingRight",
|
|
301
|
+
"fontSize",
|
|
302
|
+
"lineHeight",
|
|
303
|
+
"textWidth",
|
|
304
|
+
"sansTextWidth",
|
|
305
|
+
"variableRowHeight"
|
|
306
|
+
].every((e) => {
|
|
307
|
+
let n = t[e];
|
|
308
|
+
return typeof n == "number" && Number.isFinite(n) && n >= 0 && n <= 1e7;
|
|
309
|
+
}) || !(t.pageWidth > 0) || !(t.pageHeight > 0) || !(t.fontSize > 0) || !(t.lineHeight > 0) || typeof t.fontFamily != "string" || t.fontFamily.length > 1e3 || !t.probeOffsets || typeof t.probeOffsets != "object") return !1;
|
|
310
|
+
let n = Object.values(t.probeOffsets);
|
|
311
|
+
return n.length > 1e3 || !n.every((e) => Number.isFinite(e) && e >= -1e7 && e <= 1e7) || !Array.isArray(t.blocks) || t.blocks.length > 1e4 ? !1 : t.blocks.every((e) => !!e && typeof e.text == "string" && e.text.length <= 1e3 && Number.isFinite(e.top) && Math.abs(e.top) <= 1e7 && Number.isFinite(e.lineCount) && e.lineCount >= 0 && e.lineCount <= 1e6);
|
|
312
|
+
}
|
|
313
|
+
//#endregion
|
|
314
|
+
export { v as CONTRACT_PRINT_FONT_UNCONFIGURED_MESSAGE, l as CONTRACT_PRINT_FRAME_TIMEOUT_MS, o as CONTRACT_PRINT_MESSAGE_NAMESPACE, C as buildContractPrintDocument, b as configureContractPrintFonts, E as isContractPrintFrameMessage, x as resolveContractFontBaseUrl, f as subscribeContractPrintFrameMessages, S as toAbsoluteContractFontBaseUrl, p as unsubscribeContractPrintFrameMessages };
|
|
@@ -388,7 +388,7 @@ function H(e, t) {
|
|
|
388
388
|
return typeof e == "string" && s.test(e) ? e : t;
|
|
389
389
|
}
|
|
390
390
|
function U(e, t) {
|
|
391
|
-
return typeof e == "string" && e.replace(/[
|
|
391
|
+
return typeof e == "string" && e.replace(/[;{}<>]/g, "").trim().slice(0, 120) || t;
|
|
392
392
|
}
|
|
393
393
|
function W(e, t, n, r) {
|
|
394
394
|
let i = Number(e);
|
package/dist/es/components/pro-contract-template-designer/src/utils/template-variable-render.mjs
CHANGED
|
@@ -1,64 +1,64 @@
|
|
|
1
|
-
import "../constants.mjs";
|
|
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
|
-
function
|
|
4
|
-
let
|
|
5
|
-
type:
|
|
6
|
-
defaultValue:
|
|
7
|
-
placeholder:
|
|
8
|
-
format:
|
|
9
|
-
precision:
|
|
10
|
-
useGrouping:
|
|
11
|
-
checkedText:
|
|
12
|
-
uncheckedText:
|
|
13
|
-
}),
|
|
3
|
+
function t(t) {
|
|
4
|
+
let r = t.type === void 0 ? "text" : String(t.type), i = Math.max(24, o(t.width, 160)), s = Math.max(24, o(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, o(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, o(t.rows, 3)), x = Math.max(18, o(t.lineHeight, 28)), S = b * x, C = v === "fill" ? "100% 100%" : v, w = g === "right" ? "flex-end" : g === "center" ? "center" : "flex-start", T = String(t.defaultValue || ""), E = n({
|
|
5
|
+
type: r,
|
|
6
|
+
defaultValue: T,
|
|
7
|
+
placeholder: t.placeholder || "",
|
|
8
|
+
format: t.format || "",
|
|
9
|
+
precision: t.precision,
|
|
10
|
+
useGrouping: t.useGrouping,
|
|
11
|
+
checkedText: t.checkedText || "",
|
|
12
|
+
uncheckedText: t.uncheckedText || ""
|
|
13
|
+
}), D = T.trim().length > 0, O = !D && E.trim().length > 0, k = r === "checkbox" && a(T), A = r === "image" && D ? `;--gd-contract-variable-image:url('${T.replaceAll("'", "%27")}')` : "";
|
|
14
14
|
return {
|
|
15
|
-
type:
|
|
16
|
-
width:
|
|
17
|
-
height:
|
|
18
|
-
border:
|
|
19
|
-
underline:
|
|
20
|
-
color:
|
|
21
|
-
background:
|
|
22
|
-
fontSize:
|
|
23
|
-
fontFamily:
|
|
24
|
-
placeholderColor:
|
|
25
|
-
lineColor:
|
|
26
|
-
textAlign:
|
|
27
|
-
borderStyle:
|
|
28
|
-
objectFit:
|
|
29
|
-
displayText:
|
|
30
|
-
hasDefaultValue:
|
|
31
|
-
isPlaceholder:
|
|
32
|
-
isChecked:
|
|
15
|
+
type: r,
|
|
16
|
+
width: i,
|
|
17
|
+
height: s,
|
|
18
|
+
border: c,
|
|
19
|
+
underline: l,
|
|
20
|
+
color: u,
|
|
21
|
+
background: d,
|
|
22
|
+
fontSize: f,
|
|
23
|
+
fontFamily: p,
|
|
24
|
+
placeholderColor: m,
|
|
25
|
+
lineColor: h,
|
|
26
|
+
textAlign: g,
|
|
27
|
+
borderStyle: _,
|
|
28
|
+
objectFit: v,
|
|
29
|
+
displayText: E,
|
|
30
|
+
hasDefaultValue: D,
|
|
31
|
+
isPlaceholder: O,
|
|
32
|
+
isChecked: k,
|
|
33
33
|
classes: [
|
|
34
34
|
"gd-contract-template-variable",
|
|
35
|
-
`is-${
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
35
|
+
`is-${r}`,
|
|
36
|
+
c ? "has-border" : "",
|
|
37
|
+
l ? "has-underline" : "",
|
|
38
|
+
y ? "is-multiline" : "",
|
|
39
|
+
O ? "is-placeholder" : "",
|
|
40
|
+
D ? "has-value" : "",
|
|
41
|
+
k ? "is-checked" : ""
|
|
42
42
|
].filter(Boolean),
|
|
43
|
-
styleText: `--gd-contract-variable-width:${
|
|
43
|
+
styleText: `--gd-contract-variable-width:${i}px;--gd-contract-variable-height:${s}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}`
|
|
44
44
|
};
|
|
45
45
|
}
|
|
46
|
-
function
|
|
47
|
-
let t = e.type || "text",
|
|
48
|
-
return t === "checkbox" ?
|
|
46
|
+
function n(e) {
|
|
47
|
+
let t = e.type || "text", n = e.defaultValue || "", o = e.placeholder || "";
|
|
48
|
+
return t === "checkbox" ? n ? a(n) ? e.checkedText || o : e.uncheckedText || o : o : n ? t === "date" ? r(n, e.format || "") : t === "number" ? i(n, {
|
|
49
49
|
format: e.format || "",
|
|
50
50
|
precision: e.precision,
|
|
51
51
|
useGrouping: e.useGrouping
|
|
52
|
-
}) : t === "image" ? o :
|
|
52
|
+
}) : t === "image" ? o : n : o;
|
|
53
53
|
}
|
|
54
|
-
function
|
|
54
|
+
function r(e, t) {
|
|
55
55
|
if (!t) return e;
|
|
56
56
|
let n = /^(\d{4})[-/年](\d{1,2})[-/月](\d{1,2})/.exec(e);
|
|
57
57
|
if (!n) return e;
|
|
58
58
|
let [, r, i, a] = n;
|
|
59
59
|
return t.replace("YYYY", r).replace("MM", i.padStart(2, "0")).replace("DD", a.padStart(2, "0"));
|
|
60
60
|
}
|
|
61
|
-
function
|
|
61
|
+
function i(e, t) {
|
|
62
62
|
let n = Number(e);
|
|
63
63
|
if (!Number.isFinite(n)) return e;
|
|
64
64
|
let r = n.toLocaleString("zh-CN", {
|
|
@@ -68,7 +68,7 @@ function r(e, t) {
|
|
|
68
68
|
});
|
|
69
69
|
return t.format === "currency" ? `¥${r}` : r;
|
|
70
70
|
}
|
|
71
|
-
function
|
|
71
|
+
function a(e) {
|
|
72
72
|
return [
|
|
73
73
|
"1",
|
|
74
74
|
"true",
|
|
@@ -78,10 +78,10 @@ function i(e) {
|
|
|
78
78
|
"已选"
|
|
79
79
|
].includes(e.trim().toLowerCase());
|
|
80
80
|
}
|
|
81
|
-
function
|
|
81
|
+
function o(e, t) {
|
|
82
82
|
if (e == null || e === "") return t;
|
|
83
83
|
let n = Number(e);
|
|
84
84
|
return Number.isFinite(n) ? n : t;
|
|
85
85
|
}
|
|
86
86
|
//#endregion
|
|
87
|
-
export {
|
|
87
|
+
export { t as resolveTemplateVariablePresentation };
|