@kc-one/smart-fill-sdk 0.0.1-beta.2 → 0.0.1-beta.3
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 +20 -1
- package/dist/index.esm.js +2748 -1038
- package/dist/index.umd.cjs +28 -19
- package/dist/src/adapters/element.d.ts +2 -2
- package/dist/src/adapters/element.d.ts.map +1 -1
- package/dist/src/adapters/ui-framework.d.ts +5 -0
- package/dist/src/adapters/ui-framework.d.ts.map +1 -0
- package/dist/src/client/gateway-client.d.ts.map +1 -1
- package/dist/src/config/defaults.d.ts +1 -1
- package/dist/src/config/defaults.d.ts.map +1 -1
- package/dist/src/core/smart-fill-instance.d.ts +25 -1
- package/dist/src/core/smart-fill-instance.d.ts.map +1 -1
- package/dist/src/core/smart-fill.d.ts.map +1 -1
- package/dist/src/filler/dom-filler.d.ts.map +1 -1
- package/dist/src/index.d.ts +6 -6
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/rules/local-rules.d.ts.map +1 -1
- package/dist/src/scanner/dom-scanner.d.ts +7 -1
- package/dist/src/scanner/dom-scanner.d.ts.map +1 -1
- package/dist/src/scanner/ui-frameworks.d.ts +38 -0
- package/dist/src/scanner/ui-frameworks.d.ts.map +1 -0
- package/dist/src/select/address-cascader.d.ts +13 -0
- package/dist/src/select/address-cascader.d.ts.map +1 -0
- package/dist/src/select/custom-select.d.ts +19 -0
- package/dist/src/select/custom-select.d.ts.map +1 -0
- package/dist/src/select/option-match.d.ts +14 -0
- package/dist/src/select/option-match.d.ts.map +1 -0
- package/dist/src/select/select-fill.d.ts +4 -0
- package/dist/src/select/select-fill.d.ts.map +1 -0
- package/dist/src/types/index.d.ts +33 -5
- package/dist/src/types/index.d.ts.map +1 -1
- package/dist/style.css +1 -1
- package/package.json +5 -2
package/dist/index.esm.js
CHANGED
|
@@ -1,40 +1,1424 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
var nn = Object.defineProperty;
|
|
2
|
+
var rn = (e, t, n) => t in e ? nn(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
|
|
3
|
+
var d = (e, t, n) => rn(e, typeof t != "symbol" ? t + "" : t, n);
|
|
4
|
+
const Vo = {
|
|
5
|
+
name: "native",
|
|
6
|
+
/** 匹配 input / textarea / select 原生控件 */
|
|
7
|
+
match: (e) => e instanceof HTMLInputElement || e instanceof HTMLTextAreaElement || e instanceof HTMLSelectElement,
|
|
8
|
+
getValue: (e) => {
|
|
9
|
+
const t = e.element;
|
|
10
|
+
if (t instanceof HTMLInputElement && t.type === "checkbox") return t.checked;
|
|
11
|
+
if (t instanceof HTMLInputElement || t instanceof HTMLTextAreaElement || t instanceof HTMLSelectElement) return t.value;
|
|
12
|
+
},
|
|
13
|
+
setValue: (e, t) => {
|
|
14
|
+
const n = e.element;
|
|
15
|
+
n instanceof HTMLInputElement && n.type === "checkbox" ? n.checked = !!t : (n instanceof HTMLInputElement || n instanceof HTMLTextAreaElement || n instanceof HTMLSelectElement) && (n.value = String(t ?? "")), n == null || n.dispatchEvent(new Event("input", { bubbles: !0 })), n == null || n.dispatchEvent(new Event("change", { bubbles: !0 }));
|
|
16
|
+
}
|
|
17
|
+
}, yt = [
|
|
18
|
+
// Element Plus / Element UI
|
|
19
|
+
{ framework: "element", selectors: ".el-select,.el-select-v2", type: "select", kind: "input" },
|
|
20
|
+
{ framework: "element", selectors: ".el-cascader", type: "cascader", kind: "input" },
|
|
21
|
+
{ framework: "element", selectors: ".el-date-editor,.el-time-picker", type: "date", kind: "input" },
|
|
22
|
+
{ framework: "element", selectors: ".el-input-number", type: "number", kind: "input" },
|
|
23
|
+
{ framework: "element", selectors: ".el-switch", type: "checkbox", kind: "switch" },
|
|
24
|
+
{ framework: "element", selectors: ".el-radio-group", type: "radio", kind: "radioGroup", optionSelector: '.el-radio,[role="radio"],input[type="radio"]' },
|
|
25
|
+
{ framework: "element", selectors: ".el-checkbox-group", type: "checkbox", kind: "checkboxGroup", optionSelector: '.el-checkbox,[role="checkbox"],input[type="checkbox"]' },
|
|
26
|
+
// Ant Design Vue
|
|
27
|
+
{ framework: "antd", selectors: ".ant-select", type: "select", kind: "input" },
|
|
28
|
+
{ framework: "antd", selectors: ".ant-cascader", type: "cascader", kind: "input" },
|
|
29
|
+
{ framework: "antd", selectors: ".ant-picker", type: "date", kind: "input" },
|
|
30
|
+
{ framework: "antd", selectors: ".ant-input-number", type: "number", kind: "input" },
|
|
31
|
+
{ framework: "antd", selectors: ".ant-switch", type: "checkbox", kind: "switch" },
|
|
32
|
+
{ framework: "antd", selectors: ".ant-radio-group", type: "radio", kind: "radioGroup", optionSelector: '.ant-radio-button,.ant-radio-wrapper,.ant-radio,[role="radio"],input[type="radio"]' },
|
|
33
|
+
{ framework: "antd", selectors: ".ant-checkbox-group", type: "checkbox", kind: "checkboxGroup", optionSelector: '.ant-checkbox-wrapper,.ant-checkbox,[role="checkbox"],input[type="checkbox"]' },
|
|
34
|
+
// Naive UI
|
|
35
|
+
{ framework: "naive", selectors: ".n-select", type: "select", kind: "input" },
|
|
36
|
+
{ framework: "naive", selectors: ".n-cascader", type: "cascader", kind: "input" },
|
|
37
|
+
{ framework: "naive", selectors: ".n-date-picker,.n-time-picker", type: "date", kind: "input" },
|
|
38
|
+
{ framework: "naive", selectors: ".n-input-number", type: "number", kind: "input" },
|
|
39
|
+
{ framework: "naive", selectors: ".n-switch", type: "checkbox", kind: "switch" },
|
|
40
|
+
{ framework: "naive", selectors: ".n-radio-group", type: "radio", kind: "radioGroup", optionSelector: '.n-radio,[role="radio"],input[type="radio"]' },
|
|
41
|
+
{ framework: "naive", selectors: ".n-checkbox-group", type: "checkbox", kind: "checkboxGroup", optionSelector: '.n-checkbox,[role="checkbox"],input[type="checkbox"]' },
|
|
42
|
+
// Arco Design
|
|
43
|
+
{ framework: "arco", selectors: ".arco-select", type: "select", kind: "input" },
|
|
44
|
+
{ framework: "arco", selectors: ".arco-cascader", type: "cascader", kind: "input" },
|
|
45
|
+
{ framework: "arco", selectors: ".arco-picker", type: "date", kind: "input" },
|
|
46
|
+
{ framework: "arco", selectors: ".arco-input-number", type: "number", kind: "input" },
|
|
47
|
+
{ framework: "arco", selectors: ".arco-switch", type: "checkbox", kind: "switch" },
|
|
48
|
+
{ framework: "arco", selectors: ".arco-radio-group", type: "radio", kind: "radioGroup", optionSelector: '.arco-radio,[role="radio"],input[type="radio"]' },
|
|
49
|
+
{ framework: "arco", selectors: ".arco-checkbox-group", type: "checkbox", kind: "checkboxGroup", optionSelector: '.arco-checkbox,[role="checkbox"],input[type="checkbox"]' },
|
|
50
|
+
// Vant(移动端 Vue 组件库)
|
|
51
|
+
{ framework: "vant", selectors: ".van-dropdown-menu", type: "select", kind: "input" },
|
|
52
|
+
{ framework: "vant", selectors: ".van-cascader", type: "cascader", kind: "input" },
|
|
53
|
+
{ framework: "vant", selectors: ".van-stepper", type: "number", kind: "input" },
|
|
54
|
+
{ framework: "vant", selectors: ".van-field--picker", type: "date", kind: "input" },
|
|
55
|
+
{ framework: "vant", selectors: ".van-search", type: "text", kind: "input" },
|
|
56
|
+
{ framework: "vant", selectors: ".van-field", type: "text", kind: "input" },
|
|
57
|
+
{ framework: "vant", selectors: ".van-switch", type: "checkbox", kind: "switch" },
|
|
58
|
+
{ framework: "vant", selectors: ".van-radio-group", type: "radio", kind: "radioGroup", optionSelector: '.van-radio,[role="radio"],input[type="radio"]' },
|
|
59
|
+
{ framework: "vant", selectors: ".van-checkbox-group", type: "checkbox", kind: "checkboxGroup", optionSelector: '.van-checkbox,[role="checkbox"],input[type="checkbox"]' },
|
|
60
|
+
// 通用 ARIA 下拉(无框架 class 或作为内层触发器)
|
|
61
|
+
{ framework: "generic", selectors: '[role="combobox"]', type: "select", kind: "input" }
|
|
62
|
+
], on = [
|
|
63
|
+
"is-disabled",
|
|
64
|
+
"ant-select-disabled",
|
|
65
|
+
"n-select--disabled",
|
|
66
|
+
"arco-select-disabled",
|
|
67
|
+
"van-field--disabled",
|
|
68
|
+
"van-switch--disabled",
|
|
69
|
+
"van-stepper--disabled",
|
|
70
|
+
"van-dropdown-menu--disabled"
|
|
71
|
+
], bt = yt.map((e) => e.selectors).join(", "), sn = [
|
|
72
|
+
".form-item",
|
|
73
|
+
".ant-form-item",
|
|
74
|
+
".el-form-item",
|
|
75
|
+
".n-form-item",
|
|
76
|
+
".arco-form-item",
|
|
77
|
+
".van-cell",
|
|
78
|
+
".van-field",
|
|
79
|
+
".field",
|
|
80
|
+
".form-row"
|
|
81
|
+
].join(", "), an = [
|
|
82
|
+
"label",
|
|
83
|
+
".ant-form-item-label",
|
|
84
|
+
".el-form-item__label",
|
|
85
|
+
".n-form-item-label",
|
|
86
|
+
".arco-form-item-label",
|
|
87
|
+
".van-field__label",
|
|
88
|
+
".label"
|
|
89
|
+
].join(", "), Xe = [
|
|
90
|
+
"dialog[open]",
|
|
91
|
+
"[role='dialog']",
|
|
92
|
+
"[aria-modal='true']",
|
|
93
|
+
".modal",
|
|
94
|
+
".modal-dialog",
|
|
95
|
+
".ant-modal",
|
|
96
|
+
".ant-drawer",
|
|
97
|
+
".el-dialog",
|
|
98
|
+
".el-drawer",
|
|
99
|
+
".n-modal",
|
|
100
|
+
".n-dialog",
|
|
101
|
+
".arco-modal",
|
|
102
|
+
".arco-drawer",
|
|
103
|
+
".van-popup",
|
|
104
|
+
".van-dialog",
|
|
105
|
+
".van-action-sheet",
|
|
106
|
+
".popup",
|
|
107
|
+
".drawer"
|
|
108
|
+
].join(", "), cn = [
|
|
109
|
+
"is-checked",
|
|
110
|
+
"ant-switch-checked",
|
|
111
|
+
"n-switch--active",
|
|
112
|
+
"arco-switch-checked",
|
|
113
|
+
"van-switch--on",
|
|
114
|
+
"van-radio--checked",
|
|
115
|
+
"van-checkbox--checked"
|
|
116
|
+
];
|
|
117
|
+
function N(e) {
|
|
118
|
+
return yt.find((t) => e.matches(t.selectors)) || null;
|
|
119
|
+
}
|
|
120
|
+
function mt(e) {
|
|
121
|
+
return !!N(e);
|
|
122
|
+
}
|
|
123
|
+
function Re(e) {
|
|
124
|
+
for (let t = e; t; t = t.parentElement)
|
|
125
|
+
if (mt(t)) return t;
|
|
126
|
+
return null;
|
|
127
|
+
}
|
|
128
|
+
function he(e) {
|
|
129
|
+
var n;
|
|
130
|
+
const t = N(e);
|
|
131
|
+
if (!t) return null;
|
|
132
|
+
if (e.matches(".van-field")) {
|
|
133
|
+
if (e.querySelector("textarea")) return "textarea";
|
|
134
|
+
if (e.classList.contains("van-field--picker")) return "date";
|
|
135
|
+
if (e.querySelector(".van-dropdown-menu")) return "select";
|
|
136
|
+
const r = e.querySelector("input");
|
|
137
|
+
if (r && (r.readOnly || r.hasAttribute("readonly"))) {
|
|
138
|
+
const o = (r.getAttribute("placeholder") || "").trim();
|
|
139
|
+
if (!o || /选择|select/i.test(o)) return "select";
|
|
140
|
+
}
|
|
141
|
+
if (e.classList.contains("van-field--clickable")) {
|
|
142
|
+
const o = f(((n = e.querySelector(".van-field__control")) == null ? void 0 : n.textContent) || "");
|
|
143
|
+
if (!e.querySelector("textarea") && (o === "请选择" || o === ""))
|
|
144
|
+
return "select";
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
return t.type;
|
|
148
|
+
}
|
|
149
|
+
function vt(e) {
|
|
150
|
+
const t = N(e);
|
|
151
|
+
if (t != null && t.optionSelector)
|
|
152
|
+
return Array.from(e.querySelectorAll(t.optionSelector)).map((n) => ln(n)).filter((n) => !!(n.label || n.value));
|
|
153
|
+
}
|
|
154
|
+
function ln(e) {
|
|
155
|
+
const t = e instanceof HTMLInputElement ? e : e.querySelector('input[type="radio"],input[type="checkbox"]'), n = f(e.textContent || e.getAttribute("aria-label") || e.getAttribute("title") || ""), r = e.getAttribute("value") || (t == null ? void 0 : t.value) || n;
|
|
156
|
+
return { label: n, value: r };
|
|
157
|
+
}
|
|
158
|
+
function X(e) {
|
|
159
|
+
return cn.some((t) => e.classList.contains(t)) || e.getAttribute("aria-checked") === "true" || !!e.querySelector("input:checked");
|
|
160
|
+
}
|
|
161
|
+
function q(e) {
|
|
162
|
+
return e.querySelector('input:not([type="hidden"]), textarea');
|
|
163
|
+
}
|
|
164
|
+
function wt(e) {
|
|
165
|
+
var t, n, r;
|
|
166
|
+
return e.getAttribute("name") || ((t = q(e)) == null ? void 0 : t.getAttribute("name")) || e.getAttribute("data-smart-fill-key") || ((n = q(e)) == null ? void 0 : n.getAttribute("data-smart-fill-key")) || ((r = e.querySelector("[data-smart-fill-key]")) == null ? void 0 : r.getAttribute("data-smart-fill-key"));
|
|
167
|
+
}
|
|
168
|
+
function f(e) {
|
|
169
|
+
return e.replace(/[*::]/g, "").replace(/\s+/g, " ").trim();
|
|
170
|
+
}
|
|
171
|
+
const Fe = "data-smart-fill-hide-dropdown-mode", Ze = "smart-fill-hide-dropdown-style", St = [
|
|
172
|
+
"[role='combobox']",
|
|
173
|
+
"[aria-haspopup='listbox']",
|
|
174
|
+
".el-cascader",
|
|
175
|
+
".ant-cascader",
|
|
176
|
+
".arco-cascader",
|
|
177
|
+
".ant-select",
|
|
178
|
+
".el-select",
|
|
179
|
+
".el-select-v2",
|
|
180
|
+
".el-select__wrapper",
|
|
181
|
+
".el-select-v2__wrapper",
|
|
182
|
+
".n-select",
|
|
183
|
+
".n-base-selection",
|
|
184
|
+
".ivu-select",
|
|
185
|
+
".arco-select",
|
|
186
|
+
".semi-select",
|
|
187
|
+
".t-select",
|
|
188
|
+
".select-trigger",
|
|
189
|
+
".select__wrapper",
|
|
190
|
+
".van-dropdown-menu",
|
|
191
|
+
".van-dropdown-menu__bar",
|
|
192
|
+
".van-field--picker",
|
|
193
|
+
".van-field--clickable"
|
|
194
|
+
].join(", "), un = [
|
|
195
|
+
".ant-select-selection-item",
|
|
196
|
+
".el-select__selected-item",
|
|
197
|
+
".el-select-v2__selected-item",
|
|
198
|
+
".el-select-v2-selected-item",
|
|
199
|
+
".el-select__placeholder",
|
|
200
|
+
".el-select-v2__placeholder",
|
|
201
|
+
".el-select-selected-value",
|
|
202
|
+
".n-base-selection-label",
|
|
203
|
+
".ivu-select-selected-value",
|
|
204
|
+
".arco-select-view-value",
|
|
205
|
+
".semi-select-selection-text",
|
|
206
|
+
".t-input__inner",
|
|
207
|
+
".select-value",
|
|
208
|
+
".selection-item",
|
|
209
|
+
".van-field__control"
|
|
210
|
+
].join(", "), Oe = [
|
|
211
|
+
"[role='option']",
|
|
212
|
+
".ant-select-item-option",
|
|
213
|
+
".el-select-dropdown__item",
|
|
214
|
+
".el-select-v2__option",
|
|
215
|
+
".n-base-select-option",
|
|
216
|
+
".ivu-select-item",
|
|
217
|
+
".arco-select-option",
|
|
218
|
+
".semi-select-option",
|
|
219
|
+
".t-select-option",
|
|
220
|
+
".van-picker-column__item",
|
|
221
|
+
".van-action-sheet__item"
|
|
222
|
+
].join(", "), ge = [
|
|
223
|
+
Oe,
|
|
224
|
+
".van-action-sheet__name",
|
|
225
|
+
".van-cascader__option",
|
|
226
|
+
".van-dropdown-item__option",
|
|
227
|
+
".van-picker-column__item--selected",
|
|
228
|
+
".el-cascader-node",
|
|
229
|
+
".ant-cascader-menu-item",
|
|
230
|
+
".n-cascader-node",
|
|
231
|
+
".arco-cascader-option"
|
|
232
|
+
].join(", "), De = [
|
|
233
|
+
".el-select-dropdown",
|
|
234
|
+
".el-cascader__dropdown",
|
|
235
|
+
".el-cascader-panel",
|
|
236
|
+
".el-select__popper",
|
|
237
|
+
".el-select-v2__popper",
|
|
238
|
+
".el-popper.el-cascader__dropdown",
|
|
239
|
+
".el-popper.el-select__popper",
|
|
240
|
+
".el-popper.el-select-v2__popper",
|
|
241
|
+
".el-popper",
|
|
242
|
+
".ant-select-dropdown",
|
|
243
|
+
".ant-cascader-menus",
|
|
244
|
+
".n-base-select-menu",
|
|
245
|
+
".n-cascader-menu",
|
|
246
|
+
".arco-select-dropdown",
|
|
247
|
+
".arco-cascader-panel",
|
|
248
|
+
".semi-select-dropdown",
|
|
249
|
+
".t-select__dropdown",
|
|
250
|
+
".van-popup",
|
|
251
|
+
".van-action-sheet",
|
|
252
|
+
".van-dropdown-item__content",
|
|
253
|
+
".van-dropdown-item",
|
|
254
|
+
".van-picker",
|
|
255
|
+
"[role='listbox']"
|
|
256
|
+
].join(", "), Et = [
|
|
257
|
+
".el-select-dropdown",
|
|
258
|
+
".el-select__popper",
|
|
259
|
+
".el-select-v2__popper",
|
|
260
|
+
".el-popper.el-select__popper",
|
|
261
|
+
".el-popper.el-select-v2__popper",
|
|
262
|
+
".ant-select-dropdown",
|
|
263
|
+
".n-base-select-menu",
|
|
264
|
+
".arco-select-dropdown",
|
|
265
|
+
".semi-select-dropdown",
|
|
266
|
+
".t-select__dropdown",
|
|
267
|
+
".van-popup",
|
|
268
|
+
".van-action-sheet",
|
|
269
|
+
".van-dropdown-item__content",
|
|
270
|
+
".van-dropdown-item",
|
|
271
|
+
".van-picker",
|
|
272
|
+
"[role='listbox']"
|
|
273
|
+
].join(", "), xt = [
|
|
274
|
+
".el-cascader__dropdown",
|
|
275
|
+
".el-cascader-panel",
|
|
276
|
+
".el-popper.el-cascader__dropdown",
|
|
277
|
+
".ant-cascader-menus",
|
|
278
|
+
".n-cascader-menu",
|
|
279
|
+
".arco-cascader-panel",
|
|
280
|
+
".van-cascader",
|
|
281
|
+
".van-cascader__options"
|
|
282
|
+
].join(", "), dn = /(?:省|市|自治区|特别行政区|自治州|地区|盟|县|区)$/, fn = /地址|省|市|区|县|地区|籍贯|户籍|居住地|所在地|区域/, pn = /* @__PURE__ */ new Set(["select", "cascader", "date"]);
|
|
283
|
+
function C(e) {
|
|
284
|
+
return !Ft(e) || At(e) ? !1 : !!e.closest(".el-cascader, .ant-cascader, .van-cascader, .n-cascader, .arco-cascader");
|
|
285
|
+
}
|
|
286
|
+
function O(e) {
|
|
287
|
+
var n;
|
|
288
|
+
if (!e.matches(".van-field")) return !1;
|
|
289
|
+
if (e.classList.contains("van-field--picker") || e.querySelector(".van-dropdown-menu"))
|
|
290
|
+
return !0;
|
|
291
|
+
const t = e.querySelector("input");
|
|
292
|
+
if (t && (t.readOnly || t.hasAttribute("readonly"))) {
|
|
293
|
+
const r = (t.getAttribute("placeholder") || "").trim();
|
|
294
|
+
if (!r || /选择|select/i.test(r)) return !0;
|
|
295
|
+
}
|
|
296
|
+
if (e.classList.contains("van-field--clickable")) {
|
|
297
|
+
const r = f(((n = e.querySelector(".van-field__control")) == null ? void 0 : n.textContent) || "");
|
|
298
|
+
if (!e.querySelector("textarea") && (r === "请选择" || r === ""))
|
|
299
|
+
return !0;
|
|
300
|
+
}
|
|
301
|
+
return !1;
|
|
302
|
+
}
|
|
303
|
+
function Z(e) {
|
|
304
|
+
return !Ft(e) || At(e) || e instanceof HTMLSelectElement || e instanceof HTMLInputElement || e instanceof HTMLTextAreaElement ? !1 : e.matches(St) || e.getAttribute("role") === "combobox" || e.getAttribute("aria-haspopup") === "listbox" || e.classList.contains("el-select__wrapper") || e.classList.contains("el-select-v2__wrapper") || O(e);
|
|
305
|
+
}
|
|
306
|
+
function Ee(e) {
|
|
307
|
+
const t = e.closest(".el-cascader, .ant-cascader, .van-cascader, .n-cascader, .arco-cascader");
|
|
308
|
+
if (t instanceof HTMLElement) return t;
|
|
309
|
+
const n = e.closest([
|
|
310
|
+
".el-date-editor",
|
|
311
|
+
".el-time-picker",
|
|
312
|
+
".el-date-picker",
|
|
313
|
+
".el-date-picker-panel",
|
|
314
|
+
".el-select",
|
|
315
|
+
".el-select-v2",
|
|
316
|
+
".ant-picker",
|
|
317
|
+
".ant-select",
|
|
318
|
+
".n-date-picker",
|
|
319
|
+
".n-time-picker",
|
|
320
|
+
".n-select",
|
|
321
|
+
".ivu-select",
|
|
322
|
+
".arco-picker",
|
|
323
|
+
".arco-select",
|
|
324
|
+
".semi-select",
|
|
325
|
+
".t-select",
|
|
326
|
+
".van-field",
|
|
327
|
+
".van-dropdown-menu",
|
|
328
|
+
".van-dropdown-menu__bar",
|
|
329
|
+
"[role='combobox']",
|
|
330
|
+
"[aria-haspopup='listbox']",
|
|
331
|
+
".select-trigger",
|
|
332
|
+
".select__wrapper",
|
|
333
|
+
".el-select__wrapper",
|
|
334
|
+
".el-select-v2__wrapper"
|
|
335
|
+
].join(", "));
|
|
336
|
+
return n instanceof HTMLElement ? n.matches(".van-field") && !O(n) ? null : n : Z(e) ? e : null;
|
|
337
|
+
}
|
|
338
|
+
function Pe(e) {
|
|
339
|
+
if (e instanceof HTMLSelectElement) return e;
|
|
340
|
+
if (C(e))
|
|
341
|
+
return e.closest(".el-cascader, .ant-cascader, .van-cascader, .n-cascader, .arco-cascader") || e;
|
|
342
|
+
const t = Ee(e);
|
|
343
|
+
return t || (e.matches(".van-field") && O(e) ? e : null);
|
|
344
|
+
}
|
|
345
|
+
function Ke(e) {
|
|
346
|
+
if (C(e)) return "cascader";
|
|
347
|
+
if (Z(e) || O(e)) return "select";
|
|
348
|
+
const t = he(e);
|
|
349
|
+
return t || (e instanceof HTMLSelectElement ? "select" : null);
|
|
350
|
+
}
|
|
351
|
+
function Y(e, t) {
|
|
352
|
+
const n = t || Ke(e);
|
|
353
|
+
return n != null && pn.has(n);
|
|
354
|
+
}
|
|
355
|
+
function hn(e) {
|
|
356
|
+
return Y(e, Ke(e) || void 0);
|
|
357
|
+
}
|
|
358
|
+
function kt(e) {
|
|
359
|
+
const t = e.querySelector(un);
|
|
360
|
+
if (t instanceof HTMLInputElement)
|
|
361
|
+
return f(t.value);
|
|
362
|
+
const n = f((t == null ? void 0 : t.textContent) || "");
|
|
363
|
+
if (n && n !== "请选择") return n;
|
|
364
|
+
const r = e.querySelector('input:not([type="hidden"])');
|
|
365
|
+
return r != null && r.value ? f(r.value) : n;
|
|
366
|
+
}
|
|
367
|
+
function _t(e) {
|
|
368
|
+
const t = Sn(e);
|
|
369
|
+
if (!t.length) return;
|
|
370
|
+
const n = En(t);
|
|
371
|
+
return n.length ? n : void 0;
|
|
372
|
+
}
|
|
373
|
+
function se(e) {
|
|
374
|
+
var t;
|
|
375
|
+
return !((t = e.options) != null && t.length) || e.type === "cascader" || fn.test(e.label || "") ? !1 : Tn(e.options);
|
|
376
|
+
}
|
|
377
|
+
async function gn(e) {
|
|
378
|
+
if (e instanceof HTMLSelectElement)
|
|
379
|
+
return Array.from(e.options).map((s) => ({ value: s.value, label: f(s.textContent || s.label) })).filter((s) => s.label || s.value);
|
|
380
|
+
const t = _t(e);
|
|
381
|
+
if (t != null && t.length) return t;
|
|
382
|
+
const n = Ee(e) || e;
|
|
383
|
+
if (!Z(n) && !C(n) && !O(n))
|
|
384
|
+
return;
|
|
385
|
+
const r = Rn(), o = Ln(), i = new Set(o.getTrackedDropdowns());
|
|
386
|
+
try {
|
|
387
|
+
if (!(C(n) ? await bn(n, o, i) : await yn(n, o, i))) return;
|
|
388
|
+
const a = await vn(o, i, n);
|
|
389
|
+
if (!a.length) return;
|
|
390
|
+
const c = mn(a);
|
|
391
|
+
return c.length ? c : void 0;
|
|
392
|
+
} finally {
|
|
393
|
+
await Mn(n, o), await R(60), o.restore(), r();
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
function At(e) {
|
|
397
|
+
return e.hasAttribute("disabled") || e.getAttribute("aria-disabled") === "true";
|
|
398
|
+
}
|
|
399
|
+
async function yn(e, t, n) {
|
|
400
|
+
const r = J(e);
|
|
401
|
+
if (!r.length) return !1;
|
|
402
|
+
for (const o of r)
|
|
403
|
+
if (Mt(o), It(o), await R(160), Je(e, t, n) || (Rt(o), await R(180), Je(e, t, n))) return !0;
|
|
404
|
+
return !1;
|
|
405
|
+
}
|
|
406
|
+
async function bn(e, t, n) {
|
|
407
|
+
const r = [
|
|
408
|
+
e,
|
|
409
|
+
e.querySelector(".el-input__wrapper"),
|
|
410
|
+
e.querySelector(".el-input"),
|
|
411
|
+
e.querySelector(".van-field__control"),
|
|
412
|
+
e.querySelector("input")
|
|
413
|
+
].filter((o) => o instanceof HTMLElement);
|
|
414
|
+
for (const o of r)
|
|
415
|
+
if (Mt(o), It(o), await R(180), ye(t, n, e).length || (Rt(o), await R(180), ye(t, n, e).length)) return !0;
|
|
416
|
+
return !1;
|
|
417
|
+
}
|
|
418
|
+
function mn(e) {
|
|
419
|
+
var r;
|
|
420
|
+
const t = /* @__PURE__ */ new Set(), n = [];
|
|
421
|
+
for (const o of e) {
|
|
422
|
+
const i = o.matches(ge) ? [o] : Array.from(o.querySelectorAll(ge));
|
|
423
|
+
for (const s of i) {
|
|
424
|
+
if (s.classList.contains("is-disabled") || s.classList.contains("ant-select-item-option-disabled") || s.getAttribute("aria-disabled") === "true")
|
|
425
|
+
continue;
|
|
426
|
+
const a = f(
|
|
427
|
+
((r = s.querySelector(".el-cascader-node__label, .ant-cascader-menu-item-content")) == null ? void 0 : r.textContent) || s.textContent || ""
|
|
428
|
+
), c = s.getAttribute("data-value") || s.getAttribute("value") || a;
|
|
429
|
+
if (!a && !c) continue;
|
|
430
|
+
const l = `${a}::${String(c)}`;
|
|
431
|
+
t.has(l) || (t.add(l), n.push({ label: a, value: c }));
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
return n;
|
|
435
|
+
}
|
|
436
|
+
async function vn(e, t, n) {
|
|
437
|
+
for (let r = 0; r < 8; r += 1) {
|
|
438
|
+
const o = ye(e, t, n);
|
|
439
|
+
if (o.length) return o;
|
|
440
|
+
await R(r === 0 ? 120 : 80);
|
|
441
|
+
}
|
|
442
|
+
return [];
|
|
443
|
+
}
|
|
444
|
+
function Je(e, t, n) {
|
|
445
|
+
return ye(t, n, e).length > 0 ? !0 : J(e).some((r) => r.getAttribute("aria-expanded") === "true" || r.classList.contains("is-focus") || r.classList.contains("is-focused"));
|
|
446
|
+
}
|
|
447
|
+
function wn(e, t, n) {
|
|
448
|
+
const r = t.filter((c) => qe(e, c)), o = r.filter((c) => xn(e, c)), i = o.filter((c) => !n.has(c));
|
|
449
|
+
if (i.length)
|
|
450
|
+
return i.sort((c, l) => P(l, e) - P(c, e));
|
|
451
|
+
const s = Ct(e);
|
|
452
|
+
if (s.size) {
|
|
453
|
+
const c = o.filter((l) => l.id && s.has(l.id));
|
|
454
|
+
if (c.length) return c;
|
|
455
|
+
}
|
|
456
|
+
if (o.length)
|
|
457
|
+
return o.sort((c, l) => P(l, e) - P(c, e)).slice(0, 1);
|
|
458
|
+
const a = r.filter((c) => Cn(c) && Tt(e)).sort((c, l) => P(l, e) - P(c, e)).slice(0, 1);
|
|
459
|
+
return a.length ? a : [];
|
|
460
|
+
}
|
|
461
|
+
function ye(e, t, n) {
|
|
462
|
+
return wn(n, e.getTrackedDropdowns(), t);
|
|
463
|
+
}
|
|
464
|
+
function P(e, t) {
|
|
465
|
+
const n = e.getBoundingClientRect(), r = Number.parseInt(window.getComputedStyle(e).zIndex || "0", 10);
|
|
466
|
+
let o = (Number.isNaN(r) ? 0 : r) * 10 + n.width * n.height;
|
|
467
|
+
return t && (o += Lt(t, e)), o;
|
|
468
|
+
}
|
|
469
|
+
function Sn(e) {
|
|
470
|
+
const t = C(e) ? xt : Et, n = /* @__PURE__ */ new Set();
|
|
471
|
+
e.matches(t) && n.add(e);
|
|
472
|
+
for (const r of e.querySelectorAll(t))
|
|
473
|
+
qe(e, r) && n.add(r);
|
|
474
|
+
for (const r of e.querySelectorAll("[role='listbox']"))
|
|
475
|
+
e.contains(r) && qe(e, r) && n.add(r);
|
|
476
|
+
return [...n];
|
|
477
|
+
}
|
|
478
|
+
function En(e) {
|
|
479
|
+
const t = /* @__PURE__ */ new Set(), n = [];
|
|
480
|
+
for (const r of e) {
|
|
481
|
+
const o = r.matches(Oe) ? [r] : Array.from(r.querySelectorAll(Oe));
|
|
482
|
+
for (const i of o) {
|
|
483
|
+
if (i.classList.contains("is-disabled") || i.classList.contains("ant-select-item-option-disabled") || i.getAttribute("aria-disabled") === "true")
|
|
484
|
+
continue;
|
|
485
|
+
const s = f(i.textContent || ""), a = i.getAttribute("data-value") || i.getAttribute("value") || s;
|
|
486
|
+
if (!s && !a) continue;
|
|
487
|
+
const c = `${s}::${String(a)}`;
|
|
488
|
+
t.has(c) || (t.add(c), n.push({ label: s, value: a }));
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
return n;
|
|
492
|
+
}
|
|
493
|
+
function Ct(e) {
|
|
494
|
+
return new Set(
|
|
495
|
+
J(e).flatMap((t) => [t.getAttribute("aria-controls"), t.getAttribute("aria-owns")]).filter((t) => !!t)
|
|
496
|
+
);
|
|
497
|
+
}
|
|
498
|
+
function xn(e, t) {
|
|
499
|
+
const n = Ct(e);
|
|
500
|
+
return n.size && t.id && n.has(t.id) || e.contains(t) ? !0 : An(t) ? Tt(e) : n.size > 0 || J(e).some((o) => o.getAttribute("aria-controls") || o.getAttribute("aria-owns")) ? !1 : Lt(e, t) > 0;
|
|
501
|
+
}
|
|
502
|
+
function qe(e, t) {
|
|
503
|
+
const n = C(e), r = kn(t);
|
|
504
|
+
return n ? r : r ? !1 : _n(t);
|
|
505
|
+
}
|
|
506
|
+
function kn(e) {
|
|
507
|
+
return e.matches(xt) || !!e.querySelector(".el-cascader-node, .ant-cascader-menu-item, .van-cascader__option, .n-cascader-node, .arco-cascader-option");
|
|
508
|
+
}
|
|
509
|
+
function _n(e) {
|
|
510
|
+
return e.matches(Et) || !!e.querySelector('.el-select-dropdown__item, .ant-select-item-option, .van-picker-column__item, .van-action-sheet__item, .van-dropdown-item__option, [role="option"]');
|
|
511
|
+
}
|
|
512
|
+
function An(e) {
|
|
513
|
+
return e.matches(".van-popup, .van-action-sheet, .van-picker, .van-dropdown-item__content, .van-dropdown-item");
|
|
514
|
+
}
|
|
515
|
+
function Tt(e) {
|
|
516
|
+
return J(e).some((t) => t.getAttribute("aria-expanded") === "true" || t.classList.contains("is-focus") || t.classList.contains("is-focused") || e.contains(document.activeElement));
|
|
517
|
+
}
|
|
518
|
+
function Cn(e) {
|
|
519
|
+
return e.matches(ge) || !!e.querySelector(ge);
|
|
520
|
+
}
|
|
521
|
+
function Lt(e, t) {
|
|
522
|
+
const n = e.getBoundingClientRect(), r = t.getBoundingClientRect();
|
|
523
|
+
if (!n.width || !n.height || !r.width || !r.height)
|
|
524
|
+
return 0;
|
|
525
|
+
const o = Math.min(n.right, r.right) - Math.max(n.left, r.left);
|
|
526
|
+
if (o <= 0) return 0;
|
|
527
|
+
const i = r.top >= n.bottom ? r.top - n.bottom : n.top - r.bottom;
|
|
528
|
+
return i > 320 ? 0 : Math.max(0, 400 - i) + o;
|
|
529
|
+
}
|
|
530
|
+
function Tn(e) {
|
|
531
|
+
const t = e.slice(0, 8).map((r) => f(String(r.label || r.value || ""))).filter(Boolean);
|
|
532
|
+
return t.length < 4 ? !1 : t.filter((r) => dn.test(r)).length / t.length >= 0.75;
|
|
533
|
+
}
|
|
534
|
+
function J(e) {
|
|
535
|
+
return [
|
|
536
|
+
e,
|
|
537
|
+
e.querySelector(".van-field__control"),
|
|
538
|
+
e.querySelector(".van-field__body"),
|
|
539
|
+
e.querySelector(".van-dropdown-menu__bar"),
|
|
540
|
+
e.querySelector(".el-select__wrapper"),
|
|
541
|
+
e.querySelector(".el-select-v2__wrapper"),
|
|
542
|
+
e.querySelector(".el-select__selection"),
|
|
543
|
+
e.querySelector(".el-input__wrapper"),
|
|
544
|
+
e.querySelector(".el-input"),
|
|
545
|
+
e.querySelector("input"),
|
|
546
|
+
e.querySelector("[role='combobox']"),
|
|
547
|
+
e.querySelector("[aria-haspopup='listbox']"),
|
|
548
|
+
e.querySelector(".ant-select-selector"),
|
|
549
|
+
e.querySelector(".n-base-selection"),
|
|
550
|
+
e.querySelector(".n-base-selection-label"),
|
|
551
|
+
e.querySelector(".arco-select-view"),
|
|
552
|
+
e.querySelector(".arco-cascader"),
|
|
553
|
+
e.querySelector(".semi-select"),
|
|
554
|
+
e.querySelector(".t-input"),
|
|
555
|
+
e.querySelector(".select-trigger"),
|
|
556
|
+
e.querySelector(".select__wrapper")
|
|
557
|
+
].filter((n) => n instanceof HTMLElement).filter((n, r, o) => o.indexOf(n) === r);
|
|
558
|
+
}
|
|
559
|
+
function Ln() {
|
|
560
|
+
const e = /* @__PURE__ */ new Map();
|
|
561
|
+
In(), document.documentElement.setAttribute(Fe, "true");
|
|
562
|
+
const t = () => {
|
|
563
|
+
for (const r of document.querySelectorAll(De))
|
|
564
|
+
e.has(r) || e.set(r, {
|
|
565
|
+
display: r.style.display,
|
|
566
|
+
opacity: r.style.opacity,
|
|
567
|
+
visibility: r.style.visibility,
|
|
568
|
+
pointerEvents: r.style.pointerEvents
|
|
569
|
+
}), r.style.opacity = "0", r.style.visibility = "hidden", r.style.pointerEvents = "none";
|
|
570
|
+
};
|
|
571
|
+
t();
|
|
572
|
+
const n = new MutationObserver(() => t());
|
|
573
|
+
return n.observe(document.body, {
|
|
574
|
+
childList: !0,
|
|
575
|
+
subtree: !0,
|
|
576
|
+
attributes: !0,
|
|
577
|
+
attributeFilter: ["class", "style", "aria-hidden"]
|
|
578
|
+
}), {
|
|
579
|
+
getTrackedDropdowns: () => Array.from(document.querySelectorAll(De)),
|
|
580
|
+
restore: () => {
|
|
581
|
+
n.disconnect(), document.documentElement.removeAttribute(Fe);
|
|
582
|
+
for (const [r, o] of e)
|
|
583
|
+
r.style.display = o.display, r.style.opacity = o.opacity, r.style.visibility = o.visibility, r.style.pointerEvents = o.pointerEvents;
|
|
584
|
+
}
|
|
585
|
+
};
|
|
586
|
+
}
|
|
587
|
+
function In() {
|
|
588
|
+
if (document.getElementById(Ze)) return;
|
|
589
|
+
const e = document.createElement("style");
|
|
590
|
+
e.id = Ze, e.textContent = `
|
|
591
|
+
${De.split(",").map((t) => `html[${Fe}="true"] ${t.trim()}`).join(`,
|
|
592
|
+
`)} {
|
|
593
|
+
opacity: 0 !important;
|
|
594
|
+
visibility: hidden !important;
|
|
595
|
+
pointer-events: none !important;
|
|
596
|
+
transition: none !important;
|
|
597
|
+
animation: none !important;
|
|
598
|
+
}
|
|
599
|
+
`, document.head.appendChild(e);
|
|
600
|
+
}
|
|
601
|
+
async function Mn(e, t) {
|
|
602
|
+
e.dispatchEvent(new KeyboardEvent("keydown", { key: "Escape", code: "Escape", bubbles: !0 })), document.dispatchEvent(new KeyboardEvent("keydown", { key: "Escape", code: "Escape", bubbles: !0 })), document.activeElement instanceof HTMLElement && document.activeElement.blur(), document.body.dispatchEvent(new MouseEvent("mousedown", { bubbles: !0, cancelable: !0, view: window })), document.body.dispatchEvent(new MouseEvent("mouseup", { bubbles: !0, cancelable: !0, view: window })), document.body.dispatchEvent(new MouseEvent("click", { bubbles: !0, cancelable: !0, view: window })), await R(120);
|
|
603
|
+
for (const n of t.getTrackedDropdowns())
|
|
604
|
+
n.isConnected && (n.style.display = "none", n.setAttribute("aria-hidden", "true"));
|
|
605
|
+
}
|
|
606
|
+
function It(e) {
|
|
607
|
+
window.PointerEvent && (e.dispatchEvent(new PointerEvent("pointerdown", { bubbles: !0, composed: !0, button: 0 })), e.dispatchEvent(new PointerEvent("pointerup", { bubbles: !0, composed: !0, button: 0 }))), e.dispatchEvent(new MouseEvent("mousedown", { bubbles: !0, composed: !0, button: 0 })), e.dispatchEvent(new MouseEvent("mouseup", { bubbles: !0, composed: !0, button: 0 })), e.click();
|
|
608
|
+
}
|
|
609
|
+
function Mt(e) {
|
|
610
|
+
e.focus({ preventScroll: !0 });
|
|
611
|
+
const t = e instanceof HTMLInputElement ? e : e.querySelector("input");
|
|
612
|
+
t instanceof HTMLElement && t.focus({ preventScroll: !0 });
|
|
613
|
+
}
|
|
614
|
+
function Rt(e) {
|
|
615
|
+
for (const t of [{ key: "ArrowDown", code: "ArrowDown" }, { key: "Enter", code: "Enter" }, { key: " ", code: "Space" }])
|
|
616
|
+
e.dispatchEvent(new KeyboardEvent("keydown", { ...t, bubbles: !0, composed: !0 })), e.dispatchEvent(new KeyboardEvent("keyup", { ...t, bubbles: !0, composed: !0 }));
|
|
617
|
+
}
|
|
618
|
+
function R(e) {
|
|
619
|
+
return new Promise((t) => window.setTimeout(t, e));
|
|
620
|
+
}
|
|
621
|
+
function Rn() {
|
|
622
|
+
const e = /* @__PURE__ */ new Map();
|
|
623
|
+
e.set(window, { left: window.scrollX, top: window.scrollY });
|
|
624
|
+
for (const t of document.querySelectorAll("*"))
|
|
625
|
+
(t.scrollTop || t.scrollLeft) && e.set(t, { left: t.scrollLeft, top: t.scrollTop });
|
|
626
|
+
return () => {
|
|
627
|
+
for (const [t, n] of e)
|
|
628
|
+
t === window ? window.scrollTo(n.left, n.top) : t instanceof HTMLElement && (t.scrollLeft = n.left, t.scrollTop = n.top);
|
|
629
|
+
};
|
|
630
|
+
}
|
|
631
|
+
function Ft(e) {
|
|
632
|
+
const t = window.getComputedStyle(e);
|
|
633
|
+
if (t.display === "none" || t.visibility === "hidden" || Number(t.opacity) === 0)
|
|
634
|
+
return !1;
|
|
635
|
+
const n = e.getBoundingClientRect();
|
|
636
|
+
return n.width > 0 && n.height > 0;
|
|
637
|
+
}
|
|
638
|
+
const Fn = /(维吾尔自治区|壮族自治区|回族自治区|特别行政区|自治区直辖县级行政区划|自治区|自治州|地区|盟|林区|街道|苏木|社区|省|市|区|县|旗|镇|乡)$/g, On = /* @__PURE__ */ new Set(["市辖区", "县", "自治区直辖县级行政区划"]);
|
|
639
|
+
let ae = null;
|
|
640
|
+
function m(e) {
|
|
641
|
+
return String(e ?? "").replace(/\s+/g, "").replace(/[,,。.、/\\\-]/g, "").trim().toLowerCase();
|
|
642
|
+
}
|
|
643
|
+
function T(e) {
|
|
644
|
+
return m(e).replace(Fn, "");
|
|
645
|
+
}
|
|
646
|
+
function Ve(e) {
|
|
647
|
+
if (e == null) return "";
|
|
648
|
+
if (typeof e == "string" || typeof e == "number")
|
|
649
|
+
return String(e).trim();
|
|
650
|
+
if (Array.isArray(e))
|
|
651
|
+
return e.map((t) => Ve(t)).filter(Boolean).join("");
|
|
652
|
+
if (typeof e == "object") {
|
|
653
|
+
const t = [], n = /* @__PURE__ */ new Set(), r = (o) => {
|
|
654
|
+
const i = f(String(o ?? ""));
|
|
655
|
+
!i || n.has(i) || (n.add(i), t.push(i));
|
|
656
|
+
};
|
|
657
|
+
for (const o of [
|
|
658
|
+
"province",
|
|
659
|
+
"provinceName",
|
|
660
|
+
"prov",
|
|
661
|
+
"city",
|
|
662
|
+
"cityName",
|
|
663
|
+
"district",
|
|
664
|
+
"districtName",
|
|
665
|
+
"area",
|
|
666
|
+
"areaName",
|
|
667
|
+
"county",
|
|
668
|
+
"countyName",
|
|
669
|
+
"region",
|
|
670
|
+
"regionName",
|
|
671
|
+
"address",
|
|
672
|
+
"detail",
|
|
673
|
+
"detailAddress",
|
|
674
|
+
"fullAddress",
|
|
675
|
+
"label",
|
|
676
|
+
"text",
|
|
677
|
+
"value",
|
|
678
|
+
"name",
|
|
679
|
+
"answer"
|
|
680
|
+
])
|
|
681
|
+
r(e[o]);
|
|
682
|
+
return t.join("");
|
|
683
|
+
}
|
|
684
|
+
return f(String(e));
|
|
685
|
+
}
|
|
686
|
+
function xe(e) {
|
|
687
|
+
const t = [], n = [], r = (s) => {
|
|
688
|
+
const a = f(String(s ?? ""));
|
|
689
|
+
a && t.push(a);
|
|
690
|
+
}, o = (s) => {
|
|
691
|
+
const a = m(s);
|
|
692
|
+
a && (n.push(a), r(s));
|
|
693
|
+
};
|
|
694
|
+
if (Array.isArray(e))
|
|
695
|
+
for (const s of e) o(s);
|
|
696
|
+
else if (typeof e == "object" && e) {
|
|
697
|
+
for (const s of [
|
|
698
|
+
"province",
|
|
699
|
+
"provinceName",
|
|
700
|
+
"prov",
|
|
701
|
+
"city",
|
|
702
|
+
"cityName",
|
|
703
|
+
"district",
|
|
704
|
+
"districtName",
|
|
705
|
+
"area",
|
|
706
|
+
"areaName",
|
|
707
|
+
"county",
|
|
708
|
+
"countyName",
|
|
709
|
+
"region",
|
|
710
|
+
"regionName"
|
|
711
|
+
])
|
|
712
|
+
o(e[s]);
|
|
713
|
+
for (const s of ["address", "detail", "detailAddress", "fullAddress", "label", "value", "text", "name", "answer"])
|
|
714
|
+
r(e[s]);
|
|
715
|
+
} else
|
|
716
|
+
r(e);
|
|
717
|
+
const i = m(t.join(""));
|
|
718
|
+
return {
|
|
719
|
+
fullText: i,
|
|
720
|
+
looseFullText: T(i),
|
|
721
|
+
structuredParts: n
|
|
722
|
+
};
|
|
723
|
+
}
|
|
724
|
+
function _e(e, t) {
|
|
725
|
+
const n = m(e), r = m(t);
|
|
726
|
+
if (!n || !r) return !1;
|
|
727
|
+
if (n === r || n.includes(r) || r.includes(n))
|
|
728
|
+
return !0;
|
|
729
|
+
const o = T(n), i = T(r);
|
|
730
|
+
return !o || !i ? !1 : o === i || o.includes(i) || i.includes(o);
|
|
731
|
+
}
|
|
732
|
+
function Be(e, t = xe(e)) {
|
|
733
|
+
const n = zn();
|
|
734
|
+
if (!n.length) return [];
|
|
735
|
+
let r = null, o = 0;
|
|
736
|
+
for (const i of n) {
|
|
737
|
+
const s = Nn(i, t);
|
|
738
|
+
s > o && (o = s, r = i);
|
|
739
|
+
}
|
|
740
|
+
return o >= 120 ? (r == null ? void 0 : r.labels) || [] : [];
|
|
741
|
+
}
|
|
742
|
+
function Dn(e, t, n, r) {
|
|
743
|
+
let o = null, i = 0;
|
|
744
|
+
const s = Pn(t, n, r);
|
|
745
|
+
for (const a of e) {
|
|
746
|
+
const c = a.querySelector(".el-cascader-node__label, .ant-cascader-menu-item-content, .n-cascader-node__label, .arco-cascader-option-label"), l = f((c == null ? void 0 : c.textContent) || a.textContent || ""), u = m(l);
|
|
747
|
+
if (!u) continue;
|
|
748
|
+
const p = T(u);
|
|
749
|
+
let g = qn(u, p, s);
|
|
750
|
+
!g && t.fullText && (t.fullText.includes(u) ? g = 100 + u.length : u.includes(t.fullText) ? g = 70 + t.fullText.length : t.looseFullText.includes(p) && (g = 80 + p.length)), g > i && (i = g, o = a);
|
|
751
|
+
}
|
|
752
|
+
return i >= 75 ? o : null;
|
|
753
|
+
}
|
|
754
|
+
function Pn(e, t, n) {
|
|
755
|
+
const r = [], o = /* @__PURE__ */ new Set(), i = (s, a) => {
|
|
756
|
+
const c = m(s);
|
|
757
|
+
!c || o.has(c) || (o.add(c), r.push({
|
|
758
|
+
normalized: c,
|
|
759
|
+
stripped: T(c),
|
|
760
|
+
score: a
|
|
761
|
+
}));
|
|
762
|
+
};
|
|
763
|
+
if (t.length) {
|
|
764
|
+
t[n] && i(t[n], 260);
|
|
765
|
+
for (let s = n + 1; s < t.length; s += 1)
|
|
766
|
+
i(t[s], 215 - (s - n) * 15);
|
|
767
|
+
}
|
|
768
|
+
e.structuredParts[n] && i(e.structuredParts[n], 235);
|
|
769
|
+
for (let s = 0; s < e.structuredParts.length; s += 1)
|
|
770
|
+
s !== n && i(e.structuredParts[s], 180 - Math.abs(s - n) * 20);
|
|
771
|
+
return e.fullText && i(e.fullText, 130), r;
|
|
772
|
+
}
|
|
773
|
+
function qn(e, t, n) {
|
|
774
|
+
let r = 0;
|
|
775
|
+
for (const o of n) {
|
|
776
|
+
let i = 0;
|
|
777
|
+
o.normalized === e ? i = o.score + 80 : o.stripped && o.stripped === t ? i = o.score + 68 : o.normalized.includes(e) ? i = o.score + 40 + e.length : e.includes(o.normalized) ? i = o.score + 28 + o.normalized.length : o.stripped && t && o.stripped.includes(t) ? i = o.score + 24 + t.length : o.stripped && t && t.includes(o.stripped) && (i = o.score + 20 + o.stripped.length), i > r && (r = i);
|
|
778
|
+
}
|
|
779
|
+
return r;
|
|
780
|
+
}
|
|
781
|
+
function Nn(e, t) {
|
|
782
|
+
let n = 0, r = 0;
|
|
783
|
+
for (let o = 0; o < e.aliasesByLevel.length; o += 1) {
|
|
784
|
+
const i = $n(
|
|
785
|
+
e.aliasesByLevel[o],
|
|
786
|
+
t.structuredParts[o] || "",
|
|
787
|
+
t.fullText,
|
|
788
|
+
t.looseFullText,
|
|
789
|
+
o
|
|
790
|
+
);
|
|
791
|
+
i > 0 ? (r += 1, n += i) : t.structuredParts[o] && (n -= 30);
|
|
792
|
+
}
|
|
793
|
+
return n += r * 18 + e.labels.length * 4, t.structuredParts.length > e.labels.length && (n -= (t.structuredParts.length - e.labels.length) * 10), n;
|
|
794
|
+
}
|
|
795
|
+
function $n(e, t, n, r, o) {
|
|
796
|
+
const i = [60, 95, 135, 160][o] || 160;
|
|
797
|
+
let s = 0;
|
|
798
|
+
for (const a of e) {
|
|
799
|
+
let c = 0;
|
|
800
|
+
const l = T(a);
|
|
801
|
+
t && (t === a ? c = Math.max(c, i + 130 + a.length) : t.includes(a) || a.includes(t) ? c = Math.max(c, i + 95 + Math.min(a.length, t.length)) : l && T(t) === l && (c = Math.max(c, i + 80 + l.length))), n && (n.includes(a) ? c = Math.max(c, i + 50 + a.length) : l && r.includes(l) && (c = Math.max(c, i + 35 + l.length))), c > s && (s = c);
|
|
802
|
+
}
|
|
803
|
+
return s;
|
|
804
|
+
}
|
|
805
|
+
function Hn(e) {
|
|
806
|
+
const t = f(e), n = m(t);
|
|
807
|
+
if (!n) return [];
|
|
808
|
+
const r = /* @__PURE__ */ new Set([n]), o = T(n);
|
|
809
|
+
o && !On.has(t) && r.add(o);
|
|
810
|
+
const i = {
|
|
811
|
+
内蒙古自治区: "内蒙古",
|
|
812
|
+
广西壮族自治区: "广西",
|
|
813
|
+
西藏自治区: "西藏",
|
|
814
|
+
宁夏回族自治区: "宁夏",
|
|
815
|
+
新疆维吾尔自治区: "新疆",
|
|
816
|
+
香港特别行政区: "香港",
|
|
817
|
+
澳门特别行政区: "澳门"
|
|
818
|
+
};
|
|
819
|
+
return i[t] && r.add(i[t]), Array.from(r).filter(Boolean);
|
|
820
|
+
}
|
|
821
|
+
function zn() {
|
|
822
|
+
if (ae) return ae;
|
|
823
|
+
const e = globalThis.__SMART_FILL_ADDRESS_MAP__, t = e == null ? void 0 : e.data, n = Array.isArray(t) ? t : Array.isArray(t == null ? void 0 : t.data) ? t.data : [];
|
|
824
|
+
return ae = Kn(n), ae;
|
|
825
|
+
}
|
|
826
|
+
function Kn(e) {
|
|
827
|
+
const t = [], n = /* @__PURE__ */ new Set(), r = (o) => {
|
|
828
|
+
const i = o.map((a) => f(a)).filter(Boolean);
|
|
829
|
+
if (!i.length) return;
|
|
830
|
+
const s = i.join(">");
|
|
831
|
+
n.has(s) || (n.add(s), t.push({
|
|
832
|
+
labels: i,
|
|
833
|
+
aliasesByLevel: i.map((a) => Hn(a))
|
|
834
|
+
}));
|
|
835
|
+
};
|
|
836
|
+
for (const o of e)
|
|
837
|
+
if (o != null && o.label && (r([o.label]), !(!Array.isArray(o.children) || !o.children.length))) {
|
|
838
|
+
for (const i of o.children)
|
|
839
|
+
if (i != null && i.label && (r([o.label, i.label]), !(!Array.isArray(i.children) || !i.children.length)))
|
|
840
|
+
for (const s of i.children)
|
|
841
|
+
s != null && s.label && r([o.label, i.label, s.label]);
|
|
842
|
+
}
|
|
843
|
+
return t;
|
|
844
|
+
}
|
|
845
|
+
function Q(e, t) {
|
|
846
|
+
const n = Ue(t);
|
|
847
|
+
if (!n.length) return null;
|
|
848
|
+
let r = null, o = 0;
|
|
849
|
+
for (const i of e) {
|
|
850
|
+
const s = L(i.value), a = L(i.label);
|
|
851
|
+
for (const c of n) {
|
|
852
|
+
let l = 0;
|
|
853
|
+
c === s || c === a ? l = 120 : s && c.includes(s) || a && c.includes(a) ? l = 100 : s && s.includes(c) || a && a.includes(c) ? l = 90 : (s && ce(s) === ce(c) || a && ce(a) === ce(c)) && (l = 80), l > o && (o = l, r = i);
|
|
854
|
+
}
|
|
855
|
+
}
|
|
856
|
+
return o >= 80 ? r : null;
|
|
857
|
+
}
|
|
858
|
+
function Ue(e) {
|
|
859
|
+
if (Array.isArray(e))
|
|
860
|
+
return e.flatMap((n) => Ue(n));
|
|
861
|
+
if (typeof e == "object" && e) {
|
|
862
|
+
const n = e;
|
|
863
|
+
return [n.label, n.value, n.text, n.answer, n.name].filter((r) => r != null).map((r) => L(r)).filter(Boolean);
|
|
864
|
+
}
|
|
865
|
+
const t = L(e);
|
|
866
|
+
return t ? [t] : [];
|
|
867
|
+
}
|
|
868
|
+
function L(e) {
|
|
869
|
+
return String(e ?? "").replace(/\s+/g, "").replace(/[::,,。.、()()\-_/]/g, "").trim().toLowerCase();
|
|
870
|
+
}
|
|
871
|
+
function ce(e) {
|
|
872
|
+
return L(e).replace(/(请选择|选择|状态|情况|类型|方式|所属|是否)$/g, "");
|
|
873
|
+
}
|
|
874
|
+
const be = [
|
|
875
|
+
".ant-select-item-option",
|
|
876
|
+
".el-select-dropdown__item",
|
|
877
|
+
".el-select-v2__option",
|
|
878
|
+
".el-select-v2__option-item",
|
|
879
|
+
".n-base-select-option",
|
|
880
|
+
".ivu-select-item",
|
|
881
|
+
".arco-select-option",
|
|
882
|
+
".semi-select-option",
|
|
883
|
+
".t-select-option",
|
|
884
|
+
".van-picker-column__item",
|
|
885
|
+
".van-action-sheet__item",
|
|
886
|
+
".van-action-sheet__name",
|
|
887
|
+
".van-cascader__option",
|
|
888
|
+
".van-dropdown-item__option",
|
|
889
|
+
".van-radio",
|
|
890
|
+
"[role='option']"
|
|
891
|
+
].join(", "), Vn = [
|
|
892
|
+
".el-cascader-panel .el-cascader-menu",
|
|
893
|
+
".ant-cascader-menu",
|
|
894
|
+
".van-cascader__options",
|
|
895
|
+
".n-cascader-menu",
|
|
896
|
+
".arco-cascader-list"
|
|
897
|
+
].join(", "), Bn = [
|
|
898
|
+
".el-cascader-node",
|
|
899
|
+
".ant-cascader-menu-item",
|
|
900
|
+
".van-cascader__option",
|
|
901
|
+
".n-cascader-node",
|
|
902
|
+
".arco-cascader-option"
|
|
903
|
+
].join(", "), Un = ".van-picker__confirm, .van-picker__toolbar .van-picker__confirm", jn = [
|
|
904
|
+
".el-input__clear",
|
|
905
|
+
".el-cascader__tags .el-tag__close",
|
|
906
|
+
".el-tag__close",
|
|
907
|
+
".ant-select-clear",
|
|
908
|
+
".ant-cascader-picker-clear",
|
|
909
|
+
".n-base-clear",
|
|
910
|
+
".n-base-close",
|
|
911
|
+
".arco-icon-close",
|
|
912
|
+
".van-icon-clear",
|
|
913
|
+
".van-field__clear"
|
|
914
|
+
].join(", ");
|
|
915
|
+
async function Gn(e, t, n, r) {
|
|
916
|
+
const o = Xn(t, r);
|
|
917
|
+
return e instanceof HTMLSelectElement ? Yn(e, o) : C(e) || n === "cascader" ? Wn(e, o) : (Z(e) || O(e) || n === "select" || n === "date", Qe(e, o));
|
|
918
|
+
}
|
|
919
|
+
function Ot(e) {
|
|
920
|
+
if (e instanceof HTMLSelectElement) {
|
|
921
|
+
const n = e.options[e.selectedIndex];
|
|
922
|
+
return f((n == null ? void 0 : n.textContent) || e.value);
|
|
923
|
+
}
|
|
924
|
+
if (C(e))
|
|
925
|
+
return je(e);
|
|
926
|
+
if (Z(e) || O(e))
|
|
927
|
+
return kt(e);
|
|
928
|
+
const t = e.querySelector("input, textarea");
|
|
929
|
+
return f((t == null ? void 0 : t.value) || e.textContent || "");
|
|
930
|
+
}
|
|
931
|
+
async function Yn(e, t) {
|
|
932
|
+
const n = Array.from(e.options).map((o) => ({
|
|
933
|
+
source: o,
|
|
934
|
+
value: o.value,
|
|
935
|
+
label: o.textContent
|
|
936
|
+
})), r = Q(n, t.searchValue);
|
|
937
|
+
if ((r == null ? void 0 : r.source) instanceof HTMLOptionElement) {
|
|
938
|
+
ve(e, r.source.value), A(e);
|
|
939
|
+
return;
|
|
940
|
+
}
|
|
941
|
+
if (!U(e, t.fillValue))
|
|
942
|
+
throw new Error("原生下拉框中没有匹配到对应选项");
|
|
943
|
+
}
|
|
944
|
+
async function Qe(e, t) {
|
|
945
|
+
const n = Ee(e) || e, r = kt(n);
|
|
946
|
+
if (r && Q([{ value: r, label: r }], t.searchValue))
|
|
947
|
+
return;
|
|
948
|
+
const o = new Set(ee());
|
|
949
|
+
try {
|
|
950
|
+
if (!await Zn(n)) {
|
|
951
|
+
if (U(n, t.fillValue)) return;
|
|
952
|
+
throw new Error("自定义下拉框未能成功展开");
|
|
953
|
+
}
|
|
954
|
+
const s = await rr(n, o), a = await Qn(t.searchValue, s, !0);
|
|
955
|
+
if (!(a != null && a.source)) {
|
|
956
|
+
if (await me(n), U(n, t.fillValue)) return;
|
|
957
|
+
throw new Error("自定义下拉框展开后未找到匹配选项");
|
|
958
|
+
}
|
|
959
|
+
if (H(a.source), await y(120), ir(), A(n), await y(120), tt(n, t.searchValue) || U(n, t.fillValue) && tt(n, t.searchValue))
|
|
960
|
+
return;
|
|
961
|
+
throw new Error("自定义下拉框点击选项后未成功回填");
|
|
962
|
+
} finally {
|
|
963
|
+
await me(n), await y(80);
|
|
964
|
+
}
|
|
965
|
+
}
|
|
966
|
+
async function Wn(e, t) {
|
|
967
|
+
const n = e.closest(".el-cascader, .ant-cascader, .van-cascader, .n-cascader, .arco-cascader") || e;
|
|
968
|
+
if (!le(n, t.searchValue) && !(z(n) && (await nr(n), await y(120), le(n, t.searchValue)))) {
|
|
969
|
+
try {
|
|
970
|
+
if (await Jn(n)) {
|
|
971
|
+
const o = await er(t.searchValue);
|
|
972
|
+
if (await y(180), await me(n), await y(120), o && le(n, t.searchValue)) {
|
|
973
|
+
A(n);
|
|
974
|
+
return;
|
|
975
|
+
}
|
|
976
|
+
}
|
|
977
|
+
if (tr(n, t.fillValue) && le(n, t.searchValue))
|
|
978
|
+
return;
|
|
979
|
+
} finally {
|
|
980
|
+
await me(n), await y(80);
|
|
981
|
+
}
|
|
982
|
+
throw new Error("级联选择框匹配失败");
|
|
983
|
+
}
|
|
984
|
+
}
|
|
985
|
+
function Xn(e, t) {
|
|
986
|
+
var o;
|
|
987
|
+
const n = (o = t == null ? void 0 : t.options) != null && o.length ? Q(
|
|
988
|
+
t.options.map((i) => ({
|
|
989
|
+
value: String(i.value),
|
|
990
|
+
label: i.label
|
|
991
|
+
})),
|
|
992
|
+
e
|
|
993
|
+
) : null, r = (n == null ? void 0 : n.value) ?? (n == null ? void 0 : n.label) ?? e;
|
|
994
|
+
return {
|
|
995
|
+
searchValue: n ? [e, n.label, n.value] : e,
|
|
996
|
+
fillValue: r
|
|
997
|
+
};
|
|
998
|
+
}
|
|
999
|
+
async function Zn(e) {
|
|
1000
|
+
const t = Ge(e);
|
|
1001
|
+
for (const n of t)
|
|
1002
|
+
if (Pt(n), H(n), await y(160), et(e) || (qt(n), await y(180), et(e))) return !0;
|
|
1003
|
+
return !1;
|
|
1004
|
+
}
|
|
1005
|
+
async function Jn(e) {
|
|
1006
|
+
const t = [
|
|
1007
|
+
e,
|
|
1008
|
+
e.querySelector(".el-input__wrapper"),
|
|
1009
|
+
e.querySelector(".el-input"),
|
|
1010
|
+
e.querySelector(".van-field__control"),
|
|
1011
|
+
e.querySelector("input")
|
|
1012
|
+
].filter((n) => n instanceof HTMLElement);
|
|
1013
|
+
for (const n of t)
|
|
1014
|
+
if (Pt(n), H(n), await y(180), j().length || (qt(n), await y(180), j().length)) return !0;
|
|
1015
|
+
return !1;
|
|
1016
|
+
}
|
|
1017
|
+
async function Qn(e, t, n = !1) {
|
|
1018
|
+
for (let r = 0; r < 12; r += 1) {
|
|
1019
|
+
const o = Q(
|
|
1020
|
+
Dt(t, n).map((i) => ({
|
|
1021
|
+
source: i,
|
|
1022
|
+
value: i.getAttribute("data-value") || i.getAttribute("value") || i.textContent || "",
|
|
1023
|
+
label: i.textContent || ""
|
|
1024
|
+
})),
|
|
1025
|
+
e
|
|
1026
|
+
);
|
|
1027
|
+
if (o) return o;
|
|
1028
|
+
await y(100);
|
|
1029
|
+
}
|
|
1030
|
+
return null;
|
|
1031
|
+
}
|
|
1032
|
+
async function er(e) {
|
|
1033
|
+
const t = xe(e), n = ar(e, t);
|
|
1034
|
+
if (!t.fullText && !t.structuredParts.length && !n.length) return !1;
|
|
1035
|
+
const r = Be(e, t), o = Math.max(r.length, n.length, t.structuredParts.length, 1);
|
|
1036
|
+
for (let i = 0; i < o; i += 1) {
|
|
1037
|
+
const s = j();
|
|
1038
|
+
if (!s.length) return i > 0;
|
|
1039
|
+
const a = s[Math.min(i, s.length - 1)], c = Array.from(a.querySelectorAll(Bn)).filter((u) => !u.classList.contains("is-disabled") && u.getAttribute("aria-disabled") !== "true");
|
|
1040
|
+
if (!c.length) return !1;
|
|
1041
|
+
let l = null;
|
|
1042
|
+
if ((t.fullText || t.structuredParts.length) && (l = Dn(c, t, r, i)), !l) {
|
|
1043
|
+
const u = r[i] ?? n[i];
|
|
1044
|
+
if (!u) return !1;
|
|
1045
|
+
const p = Q(
|
|
1046
|
+
c.map((g) => {
|
|
1047
|
+
var x;
|
|
1048
|
+
return {
|
|
1049
|
+
source: g,
|
|
1050
|
+
value: g.getAttribute("data-value") || g.textContent,
|
|
1051
|
+
label: ((x = g.querySelector(".el-cascader-node__label, .ant-cascader-menu-item-content, .n-cascader-node__label, .arco-cascader-option-label")) == null ? void 0 : x.textContent) || g.textContent
|
|
1052
|
+
};
|
|
1053
|
+
}),
|
|
1054
|
+
u
|
|
1055
|
+
);
|
|
1056
|
+
l = (p == null ? void 0 : p.source) ?? null;
|
|
1057
|
+
}
|
|
1058
|
+
if (!l) return !1;
|
|
1059
|
+
if (H(l), await y(220), !j().length) return !0;
|
|
1060
|
+
}
|
|
1061
|
+
return !j().length;
|
|
1062
|
+
}
|
|
1063
|
+
function U(e, t) {
|
|
1064
|
+
const n = F(t);
|
|
1065
|
+
if (!n) return !1;
|
|
1066
|
+
if (e instanceof HTMLSelectElement) {
|
|
1067
|
+
let s = Array.from(e.options).find((a) => a.dataset.smartFillFallbackOption === "true");
|
|
1068
|
+
return s || (s = document.createElement("option"), s.dataset.smartFillFallbackOption = "true", e.appendChild(s)), s.value = n, s.textContent = n, s.selected = !0, ve(e, n), A(e), !0;
|
|
1069
|
+
}
|
|
1070
|
+
const r = e.querySelector('input:not([type="hidden"])');
|
|
1071
|
+
if (!(r instanceof HTMLInputElement) || r.disabled) return !1;
|
|
1072
|
+
const o = r.readOnly, i = r.hasAttribute("readonly");
|
|
1073
|
+
try {
|
|
1074
|
+
return o && (r.readOnly = !1, r.removeAttribute("readonly")), r.focus(), ve(r, n), r.dispatchEvent(new InputEvent("input", {
|
|
1075
|
+
bubbles: !0,
|
|
1076
|
+
composed: !0,
|
|
1077
|
+
data: n,
|
|
1078
|
+
inputType: "insertReplacementText"
|
|
1079
|
+
})), r.dispatchEvent(new Event("change", { bubbles: !0, composed: !0 })), A(r), A(e), r.blur(), !0;
|
|
1080
|
+
} catch {
|
|
1081
|
+
return !1;
|
|
1082
|
+
} finally {
|
|
1083
|
+
o && (r.readOnly = !0, i && r.setAttribute("readonly", ""));
|
|
1084
|
+
}
|
|
1085
|
+
}
|
|
1086
|
+
function tr(e, t) {
|
|
1087
|
+
const n = e.querySelector("input"), r = Ve(t) || F(t);
|
|
1088
|
+
return !(n instanceof HTMLInputElement) || !r || n.disabled ? !1 : U(e, r);
|
|
1089
|
+
}
|
|
1090
|
+
function je(e) {
|
|
1091
|
+
const t = e.querySelector("input");
|
|
1092
|
+
if (t instanceof HTMLInputElement && t.value)
|
|
1093
|
+
return f(t.value);
|
|
1094
|
+
const n = e.querySelector(
|
|
1095
|
+
".el-cascader__tags-text, .el-cascader__label, .ant-cascader-picker-label, .n-base-selection-label, .arco-cascader-view-value"
|
|
1096
|
+
);
|
|
1097
|
+
return f((n == null ? void 0 : n.textContent) || "");
|
|
1098
|
+
}
|
|
1099
|
+
function z(e) {
|
|
1100
|
+
const t = je(e);
|
|
1101
|
+
return !!(m(t) || L(t));
|
|
1102
|
+
}
|
|
1103
|
+
async function nr(e) {
|
|
1104
|
+
if (!z(e)) return !0;
|
|
1105
|
+
const t = e.querySelector(".el-input__wrapper, .el-input, .ant-select-selector, .ant-cascader-picker") ?? e;
|
|
1106
|
+
t instanceof HTMLElement && (t.dispatchEvent(new MouseEvent("mouseenter", { bubbles: !0 })), await y(80));
|
|
1107
|
+
const n = e.querySelector(jn);
|
|
1108
|
+
if (n && D(n) && (H(n), await y(120), !z(e)))
|
|
1109
|
+
return !0;
|
|
1110
|
+
const r = e.querySelector('input:not([type="hidden"])');
|
|
1111
|
+
if (r instanceof HTMLInputElement && !r.disabled) {
|
|
1112
|
+
const o = r.readOnly, i = r.hasAttribute("readonly");
|
|
1113
|
+
try {
|
|
1114
|
+
if (o && (r.readOnly = !1, r.removeAttribute("readonly")), r.focus(), ve(r, ""), r.dispatchEvent(new InputEvent("input", {
|
|
1115
|
+
bubbles: !0,
|
|
1116
|
+
composed: !0,
|
|
1117
|
+
data: "",
|
|
1118
|
+
inputType: "deleteContentBackward"
|
|
1119
|
+
})), r.dispatchEvent(new Event("change", { bubbles: !0, composed: !0 })), A(r), A(e), r.blur(), await y(80), !z(e)) return !0;
|
|
1120
|
+
} finally {
|
|
1121
|
+
o && (r.readOnly = !0, i && r.setAttribute("readonly", ""));
|
|
1122
|
+
}
|
|
1123
|
+
}
|
|
1124
|
+
return !z(e);
|
|
1125
|
+
}
|
|
1126
|
+
function Ge(e) {
|
|
1127
|
+
return [
|
|
1128
|
+
e,
|
|
1129
|
+
e.querySelector(".van-field__control"),
|
|
1130
|
+
e.querySelector(".van-field__body"),
|
|
1131
|
+
e.querySelector(".el-select__wrapper"),
|
|
1132
|
+
e.querySelector(".el-select-v2__wrapper"),
|
|
1133
|
+
e.querySelector(".el-select__selection"),
|
|
1134
|
+
e.querySelector(".el-input__wrapper"),
|
|
1135
|
+
e.querySelector(".el-input"),
|
|
1136
|
+
e.querySelector("input"),
|
|
1137
|
+
e.querySelector("[role='combobox']"),
|
|
1138
|
+
e.querySelector("[aria-haspopup='listbox']"),
|
|
1139
|
+
e.querySelector(".ant-select-selector"),
|
|
1140
|
+
e.querySelector(".n-base-selection"),
|
|
1141
|
+
e.querySelector(".arco-select-view"),
|
|
1142
|
+
e.querySelector(".select-trigger"),
|
|
1143
|
+
e.querySelector(".select__wrapper")
|
|
1144
|
+
].filter((n) => n instanceof HTMLElement).filter((n, r, o) => o.indexOf(n) === r);
|
|
1145
|
+
}
|
|
1146
|
+
function Dt(e, t) {
|
|
1147
|
+
return (e.length ? e : ee()).flatMap((o) => o.matches(be) ? [o] : Array.from(o.querySelectorAll(be))).filter((o, i, s) => s.indexOf(o) === i).filter((o) => t ? !o.classList.contains("is-disabled") && !o.classList.contains("ant-select-item-option-disabled") && o.getAttribute("aria-disabled") !== "true" : D(o) && !o.classList.contains("is-disabled") && !o.classList.contains("ant-select-item-option-disabled") && o.getAttribute("aria-disabled") !== "true");
|
|
1148
|
+
}
|
|
1149
|
+
function j() {
|
|
1150
|
+
return Array.from(document.querySelectorAll(Vn)).filter(D);
|
|
1151
|
+
}
|
|
1152
|
+
async function rr(e, t) {
|
|
1153
|
+
for (let n = 0; n < 10; n += 1) {
|
|
1154
|
+
const r = or(e, t);
|
|
1155
|
+
if (r.length) return r;
|
|
1156
|
+
await y(80);
|
|
1157
|
+
}
|
|
1158
|
+
return ee().filter(D);
|
|
1159
|
+
}
|
|
1160
|
+
function or(e, t) {
|
|
1161
|
+
const n = ee(), r = n.filter((i) => !t.has(i));
|
|
1162
|
+
if (r.length)
|
|
1163
|
+
return r.sort((i, s) => ue(s) - ue(i));
|
|
1164
|
+
const o = new Set(
|
|
1165
|
+
Ge(e).flatMap((i) => [i.getAttribute("aria-controls"), i.getAttribute("aria-owns")]).filter((i) => !!i)
|
|
1166
|
+
);
|
|
1167
|
+
if (o.size) {
|
|
1168
|
+
const i = n.filter((s) => o.has(s.id));
|
|
1169
|
+
if (i.length) return i;
|
|
1170
|
+
}
|
|
1171
|
+
return n.filter((i) => D(i) && (i.querySelector(be) || i.matches(be))).sort((i, s) => ue(s) - ue(i)).slice(0, 1);
|
|
1172
|
+
}
|
|
1173
|
+
function et(e) {
|
|
1174
|
+
return Dt(ee().filter(D), !1).length > 0 ? !0 : Ge(e).some((t) => t.getAttribute("aria-expanded") === "true" || t.classList.contains("is-focus") || t.classList.contains("is-focused"));
|
|
1175
|
+
}
|
|
1176
|
+
function le(e, t) {
|
|
1177
|
+
const n = je(e), r = m(n);
|
|
1178
|
+
if (!r) return !1;
|
|
1179
|
+
const o = Ve(t) || F(t), i = m(o);
|
|
1180
|
+
if (_e(r, i)) return !0;
|
|
1181
|
+
const s = xe(t), a = Be(t, s);
|
|
1182
|
+
if (_e(r, m(a.join("")))) return !0;
|
|
1183
|
+
const c = m(s.structuredParts.join(""));
|
|
1184
|
+
return _e(r, c);
|
|
1185
|
+
}
|
|
1186
|
+
function tt(e, t) {
|
|
1187
|
+
const n = L(Ot(e)), r = L(F(t));
|
|
1188
|
+
return !n || !r ? !1 : n === r || n.includes(r) || r.includes(n);
|
|
1189
|
+
}
|
|
1190
|
+
function ir() {
|
|
1191
|
+
const e = document.querySelector(Un);
|
|
1192
|
+
e && D(e) && H(e);
|
|
1193
|
+
}
|
|
1194
|
+
async function me(e) {
|
|
1195
|
+
e == null || e.dispatchEvent(new KeyboardEvent("keydown", { key: "Escape", code: "Escape", bubbles: !0 })), document.dispatchEvent(new KeyboardEvent("keydown", { key: "Escape", code: "Escape", bubbles: !0 })), document.activeElement instanceof HTMLElement && document.activeElement.blur(), document.body.dispatchEvent(new MouseEvent("mousedown", { bubbles: !0, cancelable: !0, view: window })), document.body.dispatchEvent(new MouseEvent("mouseup", { bubbles: !0, cancelable: !0, view: window })), document.body.dispatchEvent(new MouseEvent("click", { bubbles: !0, cancelable: !0, view: window })), await y(120);
|
|
1196
|
+
}
|
|
1197
|
+
function ee() {
|
|
1198
|
+
return Array.from(document.querySelectorAll(sr()));
|
|
1199
|
+
}
|
|
1200
|
+
function ue(e) {
|
|
1201
|
+
const t = e.getBoundingClientRect(), n = Number.parseInt(window.getComputedStyle(e).zIndex || "0", 10);
|
|
1202
|
+
return (Number.isNaN(n) ? 0 : n) * 10 + t.width * t.height;
|
|
1203
|
+
}
|
|
1204
|
+
function sr() {
|
|
1205
|
+
return [
|
|
1206
|
+
".el-select-dropdown",
|
|
1207
|
+
".el-cascader__dropdown",
|
|
1208
|
+
".el-cascader-panel",
|
|
1209
|
+
".el-select__popper",
|
|
1210
|
+
".el-select-v2__popper",
|
|
1211
|
+
".el-popper.el-cascader__dropdown",
|
|
1212
|
+
".el-popper.el-select__popper",
|
|
1213
|
+
".el-popper.el-select-v2__popper",
|
|
1214
|
+
".el-popper",
|
|
1215
|
+
".ant-select-dropdown",
|
|
1216
|
+
".ant-cascader-menus",
|
|
1217
|
+
".n-base-select-menu",
|
|
1218
|
+
".n-cascader-menu",
|
|
1219
|
+
".arco-select-dropdown",
|
|
1220
|
+
".arco-cascader-panel",
|
|
1221
|
+
".semi-select-dropdown",
|
|
1222
|
+
".t-select__dropdown",
|
|
1223
|
+
".van-popup",
|
|
1224
|
+
".van-action-sheet",
|
|
1225
|
+
".van-dropdown-item__content",
|
|
1226
|
+
".van-picker",
|
|
1227
|
+
"[role='listbox']"
|
|
1228
|
+
].join(", ");
|
|
1229
|
+
}
|
|
1230
|
+
function F(e) {
|
|
1231
|
+
if (e == null) return "";
|
|
1232
|
+
if (typeof e == "string" || typeof e == "number" || typeof e == "boolean")
|
|
1233
|
+
return f(String(e));
|
|
1234
|
+
if (Array.isArray(e))
|
|
1235
|
+
return e.map((t) => F(t)).filter(Boolean).join(" ");
|
|
1236
|
+
if (typeof e == "object") {
|
|
1237
|
+
const t = e;
|
|
1238
|
+
for (const n of ["label", "text", "value", "answer", "name"]) {
|
|
1239
|
+
const r = F(t[n]);
|
|
1240
|
+
if (r) return r;
|
|
1241
|
+
}
|
|
1242
|
+
}
|
|
1243
|
+
return f(String(e));
|
|
1244
|
+
}
|
|
1245
|
+
function ar(e, t = xe(e)) {
|
|
1246
|
+
if (t.structuredParts.length)
|
|
1247
|
+
return t.structuredParts.map((i) => f(i));
|
|
1248
|
+
const n = Be(e, t);
|
|
1249
|
+
if (n.length) return n;
|
|
1250
|
+
const r = F(e);
|
|
1251
|
+
if (!r) return [];
|
|
1252
|
+
if (r.includes("/") || r.includes("、"))
|
|
1253
|
+
return r.split(/[//、]/).map((i) => i.trim()).filter(Boolean);
|
|
1254
|
+
const o = Ue(e);
|
|
1255
|
+
return o.length ? [f(o[0])] : [r];
|
|
1256
|
+
}
|
|
1257
|
+
function ve(e, t) {
|
|
1258
|
+
var o;
|
|
1259
|
+
const n = Object.getPrototypeOf(e), r = Object.getOwnPropertyDescriptor(n, "value");
|
|
1260
|
+
(o = r == null ? void 0 : r.set) == null || o.call(e, t);
|
|
1261
|
+
}
|
|
1262
|
+
function A(e) {
|
|
1263
|
+
e.dispatchEvent(new Event("focus", { bubbles: !0 })), e.dispatchEvent(new InputEvent("input", { bubbles: !0, composed: !0, data: null, inputType: "insertText" })), e.dispatchEvent(new Event("change", { bubbles: !0, composed: !0 })), e.dispatchEvent(new Event("blur", { bubbles: !0 }));
|
|
1264
|
+
}
|
|
1265
|
+
function H(e) {
|
|
1266
|
+
window.PointerEvent && (e.dispatchEvent(new PointerEvent("pointerdown", { bubbles: !0, composed: !0, button: 0 })), e.dispatchEvent(new PointerEvent("pointerup", { bubbles: !0, composed: !0, button: 0 }))), e.dispatchEvent(new MouseEvent("mousedown", { bubbles: !0, composed: !0, button: 0 })), e.dispatchEvent(new MouseEvent("mouseup", { bubbles: !0, composed: !0, button: 0 })), e.click();
|
|
1267
|
+
}
|
|
1268
|
+
function Pt(e) {
|
|
1269
|
+
e.focus({ preventScroll: !0 });
|
|
1270
|
+
const t = e instanceof HTMLInputElement ? e : e.querySelector("input");
|
|
1271
|
+
t instanceof HTMLElement && t.focus({ preventScroll: !0 });
|
|
1272
|
+
}
|
|
1273
|
+
function qt(e) {
|
|
1274
|
+
for (const t of [{ key: "ArrowDown", code: "ArrowDown" }, { key: "Enter", code: "Enter" }, { key: " ", code: "Space" }])
|
|
1275
|
+
e.dispatchEvent(new KeyboardEvent("keydown", { ...t, bubbles: !0, composed: !0 })), e.dispatchEvent(new KeyboardEvent("keyup", { ...t, bubbles: !0, composed: !0 }));
|
|
1276
|
+
}
|
|
1277
|
+
function D(e) {
|
|
1278
|
+
const t = window.getComputedStyle(e);
|
|
1279
|
+
if (t.display === "none" || t.visibility === "hidden" || Number(t.opacity) === 0) return !1;
|
|
1280
|
+
const n = e.getBoundingClientRect();
|
|
1281
|
+
return n.width > 0 && n.height > 0;
|
|
1282
|
+
}
|
|
1283
|
+
function y(e) {
|
|
1284
|
+
return new Promise((t) => window.setTimeout(t, e));
|
|
1285
|
+
}
|
|
1286
|
+
const nt = /* @__PURE__ */ new Set(["select", "cascader", "date"]), Nt = {
|
|
1287
|
+
name: "ui-framework",
|
|
1288
|
+
match: (e) => e.matches(bt) || mt(e) || !cr(e) && Y(e),
|
|
1289
|
+
getValue: (e) => {
|
|
1290
|
+
var o, i;
|
|
1291
|
+
const t = e.element;
|
|
1292
|
+
if (!t) return;
|
|
1293
|
+
const n = N(t);
|
|
1294
|
+
if ((n == null ? void 0 : n.kind) === "switch") return X(t);
|
|
1295
|
+
if ((n == null ? void 0 : n.kind) === "radioGroup") return fr(t);
|
|
1296
|
+
if ((n == null ? void 0 : n.kind) === "checkboxGroup") return pr(t);
|
|
1297
|
+
const r = e.type || he(t) || (n == null ? void 0 : n.type);
|
|
1298
|
+
return r && nt.has(r) ? Ot(t) : n ? ((i = q(t)) == null ? void 0 : i.value) || t.textContent || void 0 : (o = q(t)) == null ? void 0 : o.value;
|
|
1299
|
+
},
|
|
1300
|
+
setValue: async (e, t) => {
|
|
1301
|
+
const n = e.element;
|
|
1302
|
+
if (!n) return;
|
|
1303
|
+
const r = N(n);
|
|
1304
|
+
if ((r == null ? void 0 : r.kind) === "switch") {
|
|
1305
|
+
lr(n, t);
|
|
1306
|
+
return;
|
|
1307
|
+
}
|
|
1308
|
+
if ((r == null ? void 0 : r.kind) === "radioGroup") {
|
|
1309
|
+
dr(n, t);
|
|
1310
|
+
return;
|
|
1311
|
+
}
|
|
1312
|
+
if ((r == null ? void 0 : r.kind) === "checkboxGroup") {
|
|
1313
|
+
ur(n, t);
|
|
1314
|
+
return;
|
|
1315
|
+
}
|
|
1316
|
+
const o = e.type || he(n) || (r == null ? void 0 : r.type);
|
|
1317
|
+
if (o && nt.has(o) || Y(n, o || void 0)) {
|
|
1318
|
+
await Gn(n, t, o || "select", e);
|
|
1319
|
+
return;
|
|
1320
|
+
}
|
|
1321
|
+
const i = q(n);
|
|
1322
|
+
if (i) {
|
|
1323
|
+
hr(i, t);
|
|
1324
|
+
return;
|
|
1325
|
+
}
|
|
1326
|
+
n.dispatchEvent(new Event("change", { bubbles: !0 }));
|
|
1327
|
+
}
|
|
1328
|
+
}, Bo = Nt;
|
|
1329
|
+
function cr(e) {
|
|
1330
|
+
return e instanceof HTMLInputElement || e instanceof HTMLTextAreaElement || e instanceof HTMLSelectElement;
|
|
1331
|
+
}
|
|
1332
|
+
function lr(e, t) {
|
|
1333
|
+
X(e) !== gr(t) && we(e);
|
|
1334
|
+
}
|
|
1335
|
+
function ur(e, t) {
|
|
1336
|
+
var o;
|
|
1337
|
+
const n = new Set(yr(t).map(_)), r = vt(e) || [];
|
|
1338
|
+
for (const i of W(e)) {
|
|
1339
|
+
const s = te(i.textContent || ""), a = i.getAttribute("value") || ((o = i.querySelector("input")) == null ? void 0 : o.value) || s, c = X(i), l = n.has(_(String(a))) || n.has(_(s));
|
|
1340
|
+
c !== l && we(i);
|
|
1341
|
+
}
|
|
1342
|
+
if (!W(e).length && r.length)
|
|
1343
|
+
for (const i of r)
|
|
1344
|
+
(n.has(_(String(i.value))) || n.has(_(i.label))) && we(e);
|
|
1345
|
+
}
|
|
1346
|
+
function dr(e, t) {
|
|
1347
|
+
const n = _(String(t ?? "")), r = W(e).find((o) => {
|
|
1348
|
+
var a;
|
|
1349
|
+
const i = te(o.textContent || ""), s = o.getAttribute("value") || ((a = o.querySelector("input")) == null ? void 0 : a.value) || i;
|
|
1350
|
+
return _(String(s)) === n || _(i) === n;
|
|
1351
|
+
});
|
|
1352
|
+
r && we(r);
|
|
1353
|
+
}
|
|
1354
|
+
function fr(e) {
|
|
1355
|
+
var n;
|
|
1356
|
+
const t = W(e).find((r) => X(r));
|
|
1357
|
+
if (t)
|
|
1358
|
+
return t.getAttribute("value") || ((n = t.querySelector("input")) == null ? void 0 : n.value) || te(t.textContent || "");
|
|
1359
|
+
}
|
|
1360
|
+
function pr(e) {
|
|
1361
|
+
return W(e).filter((t) => X(t)).map((t) => {
|
|
1362
|
+
var n;
|
|
1363
|
+
return t.getAttribute("value") || ((n = t.querySelector("input")) == null ? void 0 : n.value) || te(t.textContent || "");
|
|
1364
|
+
});
|
|
1365
|
+
}
|
|
1366
|
+
function W(e) {
|
|
1367
|
+
const t = N(e);
|
|
1368
|
+
return t != null && t.optionSelector ? Array.from(e.querySelectorAll(t.optionSelector)) : [];
|
|
1369
|
+
}
|
|
1370
|
+
function hr(e, t) {
|
|
1371
|
+
e.value = String(t ?? ""), e.dispatchEvent(new Event("input", { bubbles: !0 })), e.dispatchEvent(new Event("change", { bubbles: !0 })), e.dispatchEvent(new Event("blur", { bubbles: !0 }));
|
|
1372
|
+
}
|
|
1373
|
+
function we(e) {
|
|
1374
|
+
e.dispatchEvent(new MouseEvent("click", { bubbles: !0, cancelable: !0, view: window }));
|
|
1375
|
+
}
|
|
1376
|
+
function gr(e) {
|
|
1377
|
+
return typeof e == "boolean" ? e : ["true", "1", "是", "开启", "启用", "yes", "y"].includes(String(e ?? "").trim().toLowerCase());
|
|
1378
|
+
}
|
|
1379
|
+
function yr(e) {
|
|
1380
|
+
return Array.isArray(e) ? e.map(String) : String(e ?? "").split(/[,,;;、]/).map((t) => t.trim()).filter(Boolean);
|
|
1381
|
+
}
|
|
1382
|
+
function _(e) {
|
|
1383
|
+
return te(e).toLowerCase();
|
|
1384
|
+
}
|
|
1385
|
+
function te(e) {
|
|
1386
|
+
return e.replace(/\s+/g, " ").trim();
|
|
1387
|
+
}
|
|
1388
|
+
const br = "https://uat.kingdeefin.com";
|
|
1389
|
+
class $t extends Error {
|
|
1390
|
+
constructor(n) {
|
|
1391
|
+
super(n.message);
|
|
8
1392
|
/** 结构化错误信息,含 code / stage / retryable */
|
|
9
|
-
|
|
10
|
-
this.name = "SmartFillException", this.smartFillError =
|
|
1393
|
+
d(this, "smartFillError");
|
|
1394
|
+
this.name = "SmartFillException", this.smartFillError = n;
|
|
11
1395
|
}
|
|
12
1396
|
}
|
|
13
|
-
function
|
|
14
|
-
return new
|
|
1397
|
+
function v(e, t, n, r = {}) {
|
|
1398
|
+
return new $t({ code: e, message: t, stage: n, ...r });
|
|
15
1399
|
}
|
|
16
|
-
function
|
|
17
|
-
return
|
|
18
|
-
code:
|
|
19
|
-
message:
|
|
20
|
-
stage:
|
|
21
|
-
retryable:
|
|
1400
|
+
function rt(e, t, n = "RECOGNIZE_FAILED") {
|
|
1401
|
+
return e instanceof $t ? e.smartFillError : {
|
|
1402
|
+
code: n,
|
|
1403
|
+
message: e instanceof Error ? e.message : String(e || "智能录入异常"),
|
|
1404
|
+
stage: t,
|
|
1405
|
+
retryable: t === "recognize"
|
|
22
1406
|
};
|
|
23
1407
|
}
|
|
24
|
-
function
|
|
25
|
-
return `${
|
|
1408
|
+
function Se(e = "sf") {
|
|
1409
|
+
return `${e}_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 10)}`;
|
|
26
1410
|
}
|
|
27
|
-
class
|
|
28
|
-
constructor(
|
|
1411
|
+
class mr {
|
|
1412
|
+
constructor(t) {
|
|
29
1413
|
/** 会话 accessToken,写入请求头 seToken */
|
|
30
|
-
|
|
1414
|
+
d(this, "seToken", "");
|
|
31
1415
|
/** 网关根地址,见 config/defaults.ts */
|
|
32
|
-
|
|
33
|
-
this.config =
|
|
1416
|
+
d(this, "baseURL", br);
|
|
1417
|
+
this.config = t;
|
|
34
1418
|
}
|
|
35
1419
|
/** 设置会话 token,后续 request 自动携带 seToken 请求头 */
|
|
36
|
-
setAccessToken(
|
|
37
|
-
this.seToken =
|
|
1420
|
+
setAccessToken(t) {
|
|
1421
|
+
this.seToken = t;
|
|
38
1422
|
}
|
|
39
1423
|
/**
|
|
40
1424
|
* 创建 SDK 会话。
|
|
@@ -42,15 +1426,15 @@ class me {
|
|
|
42
1426
|
*/
|
|
43
1427
|
async createSession() {
|
|
44
1428
|
if (!/^seKey-[A-Za-z0-9_-]{6,}$/.test(this.config.apiKey))
|
|
45
|
-
throw
|
|
1429
|
+
throw v("API_KEY_INVALID", "apiKey 格式不正确,应以 seKey- 开头。", "setup");
|
|
46
1430
|
return {
|
|
47
1431
|
apiKey: this.config.apiKey,
|
|
48
1432
|
rulesVersion: "0.0.1"
|
|
49
1433
|
};
|
|
50
1434
|
}
|
|
51
1435
|
/** 按 formCode 拉取远端表单配置(当前扫描流程已不再依赖) */
|
|
52
|
-
async getFormConfig(
|
|
53
|
-
return
|
|
1436
|
+
async getFormConfig(t) {
|
|
1437
|
+
return t ? this.request(`/sdk/forms/${encodeURIComponent(t)}`, {
|
|
54
1438
|
method: "GET"
|
|
55
1439
|
}) : null;
|
|
56
1440
|
}
|
|
@@ -59,14 +1443,14 @@ class me {
|
|
|
59
1443
|
* - 图片:先走 OCR 提取文本,供本地规则和后端识别共用
|
|
60
1444
|
* - 纯文本:直接返回 trim 后的输入
|
|
61
1445
|
*/
|
|
62
|
-
async resolveInputText(
|
|
63
|
-
var
|
|
64
|
-
const
|
|
65
|
-
if (!
|
|
66
|
-
return { text:
|
|
67
|
-
(
|
|
68
|
-
const
|
|
69
|
-
return (
|
|
1446
|
+
async resolveInputText(t) {
|
|
1447
|
+
var i, s, a, c;
|
|
1448
|
+
const n = (i = t.images) != null && i.length ? t.images : [], r = ((s = t.text) == null ? void 0 : s.trim()) || "";
|
|
1449
|
+
if (!n.length)
|
|
1450
|
+
return { text: r, usedOcr: !1 };
|
|
1451
|
+
(a = t.onStatusChange) == null || a.call(t, "image_uploading");
|
|
1452
|
+
const o = await this.recognizeImages(n);
|
|
1453
|
+
return (c = t.onStatusChange) == null || c.call(t, "image_recognizing"), { text: o, usedOcr: !0 };
|
|
70
1454
|
}
|
|
71
1455
|
/**
|
|
72
1456
|
* 调用后端智能识别接口。
|
|
@@ -75,920 +1459,880 @@ class me {
|
|
|
75
1459
|
* - confidence:DEFAULT_REMOTE_CONFIDENCE
|
|
76
1460
|
* - source:'ai'
|
|
77
1461
|
*/
|
|
78
|
-
async recognize(
|
|
79
|
-
var
|
|
80
|
-
const
|
|
81
|
-
(
|
|
82
|
-
const
|
|
1462
|
+
async recognize(t) {
|
|
1463
|
+
var s, a;
|
|
1464
|
+
const n = performance.now(), r = (s = t.text) == null ? void 0 : s.trim();
|
|
1465
|
+
(a = t.onStatusChange) == null || a.call(t, "recognizing");
|
|
1466
|
+
const o = await this.request(
|
|
83
1467
|
"/fcloud/flow-product/agentChat/smartEntry",
|
|
84
1468
|
{
|
|
85
1469
|
method: "POST",
|
|
86
1470
|
body: JSON.stringify({
|
|
87
1471
|
// scanToken: payload.scanToken,
|
|
88
|
-
formCode:
|
|
89
|
-
configVersion:
|
|
90
|
-
formMsg:
|
|
91
|
-
|
|
1472
|
+
formCode: t.formCode || "",
|
|
1473
|
+
configVersion: t.configVersion || "",
|
|
1474
|
+
formMsg: t.fields.map(({ fingerprint: c, element: l, localRuleMode: u, scanToken: p, source: g, ...x }) => x),
|
|
1475
|
+
// 将字段描述符转换为后端需要的格式
|
|
1476
|
+
userInputMsg: r || ""
|
|
92
1477
|
})
|
|
93
1478
|
}
|
|
94
|
-
),
|
|
95
|
-
return {
|
|
96
|
-
scanToken:
|
|
97
|
-
suggestions:
|
|
98
|
-
trace:
|
|
99
|
-
traceId:
|
|
100
|
-
usedOcr: !!
|
|
1479
|
+
), i = wr(o, t.fields, t.scanToken);
|
|
1480
|
+
return console.log("suggestions", i), {
|
|
1481
|
+
scanToken: t.scanToken,
|
|
1482
|
+
suggestions: i,
|
|
1483
|
+
trace: o.trace || {
|
|
1484
|
+
traceId: Se("trace"),
|
|
1485
|
+
usedOcr: !!t.usedOcr,
|
|
101
1486
|
usedAi: !0,
|
|
102
|
-
durationMs: Math.round(performance.now() -
|
|
1487
|
+
durationMs: Math.round(performance.now() - n)
|
|
103
1488
|
}
|
|
104
1489
|
};
|
|
105
1490
|
}
|
|
106
1491
|
/** 图片 OCR:以 multipart/form-data 上传 files,返回提取出的 text 文本 */
|
|
107
|
-
async recognizeImages(
|
|
108
|
-
const
|
|
109
|
-
|
|
110
|
-
|
|
1492
|
+
async recognizeImages(t) {
|
|
1493
|
+
const n = new FormData();
|
|
1494
|
+
t.forEach((i) => {
|
|
1495
|
+
n.append("image", i, i.name);
|
|
111
1496
|
});
|
|
112
|
-
const
|
|
1497
|
+
const r = await this.request(
|
|
113
1498
|
"/fcloud/flow-product/agentChat/smartEntry/ocr",
|
|
114
1499
|
{
|
|
115
1500
|
method: "POST",
|
|
116
|
-
body:
|
|
1501
|
+
body: n
|
|
117
1502
|
}
|
|
118
|
-
),
|
|
119
|
-
if (!
|
|
120
|
-
throw
|
|
121
|
-
return
|
|
1503
|
+
), o = Er(r);
|
|
1504
|
+
if (!o)
|
|
1505
|
+
throw v("RECOGNIZE_FAILED", "图片识别未提取到文本内容。", "recognize");
|
|
1506
|
+
return o;
|
|
122
1507
|
}
|
|
123
1508
|
/** 通用 fetch 封装:超时控制、trace 头、HTTP 错误映射为 SmartFillException */
|
|
124
|
-
async request(
|
|
125
|
-
const
|
|
126
|
-
|
|
1509
|
+
async request(t, n) {
|
|
1510
|
+
const r = new AbortController(), o = window.setTimeout(() => r.abort(), this.config.requestTimeoutMs ?? 3e4), i = new Headers(n.headers);
|
|
1511
|
+
n.body && !(n.body instanceof FormData) && !i.has("Content-Type") && i.set("Content-Type", "application/json"), i.set("x-trace-id", Se("trace")), this.seToken && i.set("seToken", `${this.seToken}`);
|
|
127
1512
|
try {
|
|
128
|
-
const
|
|
129
|
-
...
|
|
130
|
-
headers:
|
|
131
|
-
signal:
|
|
1513
|
+
const s = await fetch(`${this.baseURL}${t}`, {
|
|
1514
|
+
...n,
|
|
1515
|
+
headers: i,
|
|
1516
|
+
signal: r.signal
|
|
132
1517
|
});
|
|
133
|
-
if (!
|
|
134
|
-
throw
|
|
135
|
-
retryable:
|
|
1518
|
+
if (!s.ok)
|
|
1519
|
+
throw v(xr(s.status), await s.text(), t.includes("session") ? "setup" : "recognize", {
|
|
1520
|
+
retryable: s.status >= 500 || s.status === 429
|
|
136
1521
|
});
|
|
137
|
-
return
|
|
138
|
-
} catch (
|
|
139
|
-
throw
|
|
1522
|
+
return s.json();
|
|
1523
|
+
} catch (s) {
|
|
1524
|
+
throw s instanceof DOMException && s.name === "AbortError" ? v("RECOGNIZE_TIMEOUT", "识别请求超时,请稍后重试。", "recognize", { retryable: !0 }) : s;
|
|
140
1525
|
} finally {
|
|
141
|
-
window.clearTimeout(
|
|
1526
|
+
window.clearTimeout(o);
|
|
142
1527
|
}
|
|
143
1528
|
}
|
|
144
1529
|
}
|
|
145
|
-
const
|
|
146
|
-
function
|
|
147
|
-
var
|
|
148
|
-
const
|
|
149
|
-
return (((
|
|
150
|
-
const
|
|
1530
|
+
const vr = 0.95;
|
|
1531
|
+
function wr(e, t, n) {
|
|
1532
|
+
var i;
|
|
1533
|
+
const r = new Map(t.map((s) => [s.fieldId, s]));
|
|
1534
|
+
return (((i = e.data) == null ? void 0 : i.fieldValues) || []).filter((s) => !!(s != null && s.fieldId)).map((s) => {
|
|
1535
|
+
const a = r.get(s.fieldId);
|
|
151
1536
|
return {
|
|
152
|
-
fieldId:
|
|
153
|
-
scanToken:
|
|
154
|
-
label:
|
|
155
|
-
value:
|
|
156
|
-
displayValue:
|
|
157
|
-
confidence:
|
|
158
|
-
source:
|
|
159
|
-
warnings:
|
|
1537
|
+
fieldId: s.fieldId,
|
|
1538
|
+
scanToken: n,
|
|
1539
|
+
label: s.label || (a == null ? void 0 : a.label) || s.fieldId,
|
|
1540
|
+
value: s.value,
|
|
1541
|
+
displayValue: s.value == null ? "" : String(s.value),
|
|
1542
|
+
confidence: Sr(s.confidence),
|
|
1543
|
+
source: s.source || "ai",
|
|
1544
|
+
warnings: s.warnings
|
|
160
1545
|
};
|
|
161
1546
|
});
|
|
162
1547
|
}
|
|
163
|
-
function
|
|
164
|
-
return typeof
|
|
1548
|
+
function Sr(e) {
|
|
1549
|
+
return typeof e != "number" || Number.isNaN(e) ? vr : e < 0 ? 0 : e > 1 ? 1 : e;
|
|
165
1550
|
}
|
|
166
|
-
function
|
|
167
|
-
var
|
|
168
|
-
const
|
|
169
|
-
return String(
|
|
1551
|
+
function Er(e) {
|
|
1552
|
+
var n;
|
|
1553
|
+
const t = typeof e.data == "string" ? e.data : ((n = e.data) == null ? void 0 : n.text) || e.text || "";
|
|
1554
|
+
return String(t || "").trim();
|
|
170
1555
|
}
|
|
171
|
-
function
|
|
172
|
-
return
|
|
1556
|
+
function xr(e) {
|
|
1557
|
+
return e === 401 ? "TOKEN_EXPIRED" : e === 403 ? "API_KEY_FORBIDDEN" : e === 404 ? "FORM_CONFIG_NOT_FOUND" : "RECOGNIZE_FAILED";
|
|
173
1558
|
}
|
|
174
|
-
class
|
|
1559
|
+
class Ht {
|
|
175
1560
|
constructor() {
|
|
176
|
-
|
|
1561
|
+
d(this, "handlers", /* @__PURE__ */ new Map());
|
|
177
1562
|
}
|
|
178
1563
|
/** 订阅事件,返回 unsubscribe 函数 */
|
|
179
|
-
on(
|
|
180
|
-
const
|
|
181
|
-
return
|
|
1564
|
+
on(t, n) {
|
|
1565
|
+
const r = this.handlers.get(t) ?? /* @__PURE__ */ new Set();
|
|
1566
|
+
return r.add(n), this.handlers.set(t, r), () => this.off(t, n);
|
|
182
1567
|
}
|
|
183
|
-
off(
|
|
184
|
-
var
|
|
185
|
-
(
|
|
1568
|
+
off(t, n) {
|
|
1569
|
+
var r;
|
|
1570
|
+
(r = this.handlers.get(t)) == null || r.delete(n);
|
|
186
1571
|
}
|
|
187
|
-
emit(
|
|
188
|
-
var
|
|
189
|
-
(
|
|
1572
|
+
emit(t, n) {
|
|
1573
|
+
var r;
|
|
1574
|
+
(r = this.handlers.get(t)) == null || r.forEach((o) => o(n));
|
|
190
1575
|
}
|
|
191
1576
|
clear() {
|
|
192
1577
|
this.handlers.clear();
|
|
193
1578
|
}
|
|
194
1579
|
}
|
|
195
|
-
class
|
|
1580
|
+
class kr {
|
|
196
1581
|
constructor() {
|
|
197
1582
|
/** 当前页面所有存活实例 */
|
|
198
|
-
|
|
1583
|
+
d(this, "instances", /* @__PURE__ */ new Set());
|
|
199
1584
|
/** 当前激活(面板打开)的实例 */
|
|
200
|
-
|
|
1585
|
+
d(this, "active", null);
|
|
201
1586
|
}
|
|
202
1587
|
/** 注册新实例 */
|
|
203
|
-
add(
|
|
204
|
-
this.instances.add(
|
|
1588
|
+
add(t) {
|
|
1589
|
+
this.instances.add(t);
|
|
205
1590
|
}
|
|
206
1591
|
/** 激活实例,自动关闭上一个实例的面板 */
|
|
207
|
-
activate(
|
|
208
|
-
this.active && this.active !==
|
|
1592
|
+
activate(t) {
|
|
1593
|
+
this.active && this.active !== t && this.active.close(), this.active = t;
|
|
209
1594
|
}
|
|
210
1595
|
/** 实例销毁时从管理器移除 */
|
|
211
|
-
remove(
|
|
212
|
-
this.instances.delete(
|
|
1596
|
+
remove(t) {
|
|
1597
|
+
this.instances.delete(t), this.active === t && (this.active = null);
|
|
213
1598
|
}
|
|
214
1599
|
/** 销毁所有实例(apiKey 变更时调用) */
|
|
215
1600
|
destroyAll() {
|
|
216
|
-
this.instances.forEach((
|
|
1601
|
+
this.instances.forEach((t) => t.destroy()), this.instances.clear(), this.active = null;
|
|
217
1602
|
}
|
|
218
1603
|
}
|
|
219
|
-
const
|
|
220
|
-
".el-select",
|
|
221
|
-
".el-date-editor",
|
|
222
|
-
".el-time-picker",
|
|
223
|
-
".el-switch",
|
|
224
|
-
".el-checkbox-group",
|
|
225
|
-
".el-radio-group",
|
|
226
|
-
".el-cascader",
|
|
227
|
-
".el-input-number"
|
|
228
|
-
].join(", "), ke = {
|
|
229
|
-
name: "element",
|
|
230
|
-
match: (n) => n.matches(Se),
|
|
231
|
-
getValue: (n) => {
|
|
232
|
-
var t;
|
|
233
|
-
const e = n.element;
|
|
234
|
-
if (e)
|
|
235
|
-
return e.matches(".el-switch") ? e.classList.contains("is-checked") || e.getAttribute("aria-checked") === "true" : e.matches(".el-radio-group") ? Te(e, "radio") : e.matches(".el-checkbox-group") ? Le(e) : ((t = V(e)) == null ? void 0 : t.value) || e.textContent || void 0;
|
|
236
|
-
},
|
|
237
|
-
setValue: (n, e) => {
|
|
238
|
-
const t = n.element;
|
|
239
|
-
if (!t) return;
|
|
240
|
-
if (t.matches(".el-switch")) {
|
|
241
|
-
Ae(t, e);
|
|
242
|
-
return;
|
|
243
|
-
}
|
|
244
|
-
if (t.matches(".el-radio-group")) {
|
|
245
|
-
Ce(t, "radio", e);
|
|
246
|
-
return;
|
|
247
|
-
}
|
|
248
|
-
if (t.matches(".el-checkbox-group")) {
|
|
249
|
-
Ie(t, e);
|
|
250
|
-
return;
|
|
251
|
-
}
|
|
252
|
-
const s = V(t);
|
|
253
|
-
if (s) {
|
|
254
|
-
Me(s, e);
|
|
255
|
-
return;
|
|
256
|
-
}
|
|
257
|
-
t.dispatchEvent(new Event("change", { bubbles: !0 }));
|
|
258
|
-
}
|
|
259
|
-
};
|
|
260
|
-
function Ae(n, e) {
|
|
261
|
-
(n.classList.contains("is-checked") || n.getAttribute("aria-checked") === "true") !== Fe(e) && H(n);
|
|
262
|
-
}
|
|
263
|
-
function Ie(n, e) {
|
|
264
|
-
var i;
|
|
265
|
-
const t = new Set(Oe(e).map(S)), s = F(n, "checkbox");
|
|
266
|
-
for (const r of s) {
|
|
267
|
-
const a = ((i = r.input) == null ? void 0 : i.checked) || r.root.classList.contains("is-checked") || r.root.getAttribute("aria-checked") === "true", o = t.has(S(r.value)) || t.has(S(r.label));
|
|
268
|
-
a !== o && H(r.root);
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
function Ce(n, e, t) {
|
|
272
|
-
const s = S(String(t ?? "")), i = F(n, e).find((r) => S(r.value) === s || S(r.label) === s);
|
|
273
|
-
i && H(i.root);
|
|
274
|
-
}
|
|
275
|
-
function Te(n, e) {
|
|
276
|
-
var t;
|
|
277
|
-
return (t = F(n, e).find((s) => {
|
|
278
|
-
var i;
|
|
279
|
-
return ((i = s.input) == null ? void 0 : i.checked) || s.root.classList.contains("is-checked");
|
|
280
|
-
})) == null ? void 0 : t.value;
|
|
281
|
-
}
|
|
282
|
-
function Le(n) {
|
|
283
|
-
return F(n, "checkbox").filter((e) => {
|
|
284
|
-
var t;
|
|
285
|
-
return ((t = e.input) == null ? void 0 : t.checked) || e.root.classList.contains("is-checked");
|
|
286
|
-
}).map((e) => e.value);
|
|
287
|
-
}
|
|
288
|
-
function F(n, e) {
|
|
289
|
-
return Array.from(n.querySelectorAll(`.el-${e}, [role="${e}"], input[type="${e}"]`)).map((t) => {
|
|
290
|
-
const s = t instanceof HTMLInputElement ? t : t.querySelector(`input[type="${e}"]`), i = t instanceof HTMLInputElement && t.closest(`.el-${e}, [role="${e}"]`) || t, r = ee(i.textContent || i.getAttribute("aria-label") || (s == null ? void 0 : s.value) || "");
|
|
291
|
-
return {
|
|
292
|
-
root: i,
|
|
293
|
-
input: s,
|
|
294
|
-
label: r,
|
|
295
|
-
value: i.getAttribute("value") || (s == null ? void 0 : s.value) || r
|
|
296
|
-
};
|
|
297
|
-
});
|
|
298
|
-
}
|
|
299
|
-
function V(n) {
|
|
300
|
-
return n.querySelector('input:not([type="hidden"]), textarea');
|
|
301
|
-
}
|
|
302
|
-
function Me(n, e) {
|
|
303
|
-
n.value = String(e ?? ""), n.dispatchEvent(new Event("input", { bubbles: !0 })), n.dispatchEvent(new Event("change", { bubbles: !0 })), n.dispatchEvent(new Event("blur", { bubbles: !0 }));
|
|
304
|
-
}
|
|
305
|
-
function H(n) {
|
|
306
|
-
n.dispatchEvent(new MouseEvent("click", { bubbles: !0, cancelable: !0, view: window }));
|
|
307
|
-
}
|
|
308
|
-
function Fe(n) {
|
|
309
|
-
return typeof n == "boolean" ? n : ["true", "1", "是", "开启", "启用", "yes", "y"].includes(String(n ?? "").trim().toLowerCase());
|
|
310
|
-
}
|
|
311
|
-
function Oe(n) {
|
|
312
|
-
return Array.isArray(n) ? n.map(String) : String(n ?? "").split(/[,,;;、]/).map((e) => e.trim()).filter(Boolean);
|
|
313
|
-
}
|
|
314
|
-
function S(n) {
|
|
315
|
-
return ee(n).toLowerCase();
|
|
316
|
-
}
|
|
317
|
-
function ee(n) {
|
|
318
|
-
return n.replace(/\s+/g, " ").trim();
|
|
319
|
-
}
|
|
320
|
-
const $e = [
|
|
1604
|
+
const _r = [
|
|
321
1605
|
/^(el|rc|ant|radix|headlessui|mui|chakra)-/i,
|
|
322
1606
|
/[0-9a-f]{8,}/i,
|
|
323
1607
|
/\d{6,}/
|
|
324
1608
|
];
|
|
325
|
-
function
|
|
326
|
-
const
|
|
327
|
-
return !
|
|
1609
|
+
function E(e) {
|
|
1610
|
+
const t = String(e || "").trim();
|
|
1611
|
+
return !t || _r.some((n) => n.test(t)) ? "" : t;
|
|
328
1612
|
}
|
|
329
|
-
function
|
|
330
|
-
const
|
|
331
|
-
return
|
|
1613
|
+
function G(e) {
|
|
1614
|
+
const t = (e.options || []).slice(0, 20).map((n) => `${n.label}:${String(n.value)}`).join("|");
|
|
1615
|
+
return $(
|
|
332
1616
|
[
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
1617
|
+
e.fieldId,
|
|
1618
|
+
e.tagName,
|
|
1619
|
+
e.type,
|
|
1620
|
+
E(e.name),
|
|
1621
|
+
E(e.id),
|
|
1622
|
+
e.label,
|
|
1623
|
+
e.placeholder,
|
|
1624
|
+
e.section,
|
|
1625
|
+
t
|
|
342
1626
|
].join("::")
|
|
343
1627
|
);
|
|
344
1628
|
}
|
|
345
|
-
function
|
|
346
|
-
return String(
|
|
1629
|
+
function $(e) {
|
|
1630
|
+
return String(e ?? "").replace(/\s+/g, " ").trim().toLowerCase();
|
|
347
1631
|
}
|
|
348
|
-
const
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
1632
|
+
const Ae = /* @__PURE__ */ new WeakMap(), Ar = [
|
|
1633
|
+
'input:not([type="hidden"])',
|
|
1634
|
+
"textarea",
|
|
1635
|
+
"select",
|
|
1636
|
+
".el-input__wrapper",
|
|
1637
|
+
".el-select__wrapper",
|
|
1638
|
+
".el-select-v2__wrapper",
|
|
1639
|
+
".el-date-editor",
|
|
1640
|
+
".ant-select-selector",
|
|
1641
|
+
".ant-picker",
|
|
1642
|
+
".n-base-selection",
|
|
1643
|
+
".n-input__input-el",
|
|
1644
|
+
".arco-select-view",
|
|
1645
|
+
".arco-picker",
|
|
1646
|
+
".ivu-select-selection",
|
|
1647
|
+
".semi-select-selection",
|
|
1648
|
+
".t-input__wrap",
|
|
1649
|
+
".van-field__control",
|
|
1650
|
+
".van-field__body",
|
|
1651
|
+
"[role='combobox']"
|
|
1652
|
+
].join(", ");
|
|
1653
|
+
class ot {
|
|
1654
|
+
constructor(t, n, r = []) {
|
|
1655
|
+
this.fields = t, this.schemas = n, this.adapters = r;
|
|
352
1656
|
}
|
|
353
1657
|
/**
|
|
354
1658
|
* 批量回填字段值。
|
|
355
1659
|
* 每条 value 依次校验:字段存在 → scanToken 有效 → validate → setValue。
|
|
356
1660
|
* 失败项记入 skipped,不中断后续字段。
|
|
357
1661
|
*/
|
|
358
|
-
async apply(
|
|
359
|
-
const
|
|
360
|
-
for (const
|
|
361
|
-
const
|
|
362
|
-
if (!
|
|
363
|
-
|
|
1662
|
+
async apply(t) {
|
|
1663
|
+
const n = [], r = [];
|
|
1664
|
+
for (const o of t.values) {
|
|
1665
|
+
const i = this.fields.find((l) => l.fieldId === o.fieldId);
|
|
1666
|
+
if (!i) {
|
|
1667
|
+
r.push(fe(o.fieldId, "", o.value, "字段不在当前扫描结果中", "FIELD_NOT_FOUND"));
|
|
364
1668
|
continue;
|
|
365
1669
|
}
|
|
366
|
-
if (
|
|
367
|
-
|
|
1670
|
+
if (i.scanToken !== t.scanToken) {
|
|
1671
|
+
r.push(fe(i.fieldId, i.label, o.value, "页面扫描已过期,请重新扫描", "SCAN_TOKEN_EXPIRED"));
|
|
368
1672
|
continue;
|
|
369
1673
|
}
|
|
370
|
-
const
|
|
1674
|
+
const s = Rr(this.schemas, o.fieldId), a = s != null && s.transform ? s.transform(o.value) : o.value, c = await this.getValue(i, s);
|
|
371
1675
|
try {
|
|
372
|
-
const l =
|
|
1676
|
+
const l = s != null && s.validate ? await s.validate(a) : !0;
|
|
373
1677
|
if (l !== !0) {
|
|
374
|
-
|
|
1678
|
+
r.push(fe(i.fieldId, i.label, a, typeof l == "string" ? l : "字段校验未通过", "VALIDATE_FAILED"));
|
|
375
1679
|
continue;
|
|
376
1680
|
}
|
|
377
|
-
await this.setValue(
|
|
1681
|
+
await this.setValue(i, a, s), n.push({ fieldId: i.fieldId, label: i.label, value: a, previousValue: c });
|
|
378
1682
|
} catch (l) {
|
|
379
|
-
|
|
1683
|
+
r.push(fe(i.fieldId, i.label, a, l instanceof Error ? l.message : "字段回填失败", "SET_VALUE_FAILED"));
|
|
380
1684
|
}
|
|
381
1685
|
}
|
|
382
1686
|
return {
|
|
383
|
-
applied:
|
|
384
|
-
skipped:
|
|
385
|
-
warnings:
|
|
1687
|
+
applied: n,
|
|
1688
|
+
skipped: r,
|
|
1689
|
+
warnings: r.length ? ["部分字段未回填,请查看跳过原因。"] : void 0
|
|
386
1690
|
};
|
|
387
1691
|
}
|
|
388
1692
|
/** 读取字段当前值,优先级:schema.getValue > adapter > DOM */
|
|
389
|
-
async getValue(
|
|
390
|
-
if (
|
|
391
|
-
const
|
|
392
|
-
if (
|
|
393
|
-
const
|
|
394
|
-
if (
|
|
395
|
-
return
|
|
1693
|
+
async getValue(t, n) {
|
|
1694
|
+
if (n != null && n.getValue) return n.getValue();
|
|
1695
|
+
const r = this.matchAdapter(t, n);
|
|
1696
|
+
if (r != null && r.getValue) return r.getValue(t);
|
|
1697
|
+
const o = de(t, n);
|
|
1698
|
+
if (o)
|
|
1699
|
+
return o instanceof HTMLInputElement && o.type === "checkbox" ? o.checked : o instanceof HTMLInputElement && o.type === "radio" ? o.checked ? o.value : void 0 : o instanceof HTMLInputElement || o instanceof HTMLTextAreaElement || o instanceof HTMLSelectElement ? o.value : o.textContent;
|
|
396
1700
|
}
|
|
397
1701
|
/**
|
|
398
1702
|
* 写入字段值,优先级:schema.setValue > adapter > 原生 DOM。
|
|
399
1703
|
* 写入前校验 fingerprint 防 DOM 变化误填,写入后触发高亮。
|
|
400
1704
|
*/
|
|
401
|
-
async setValue(
|
|
402
|
-
if (
|
|
403
|
-
await
|
|
1705
|
+
async setValue(t, n, r) {
|
|
1706
|
+
if (r != null && r.setValue) {
|
|
1707
|
+
await r.setValue(n);
|
|
1708
|
+
const a = de(t, r);
|
|
1709
|
+
a && Ce(a, t);
|
|
404
1710
|
return;
|
|
405
1711
|
}
|
|
406
|
-
const
|
|
407
|
-
if (!
|
|
408
|
-
if (
|
|
1712
|
+
const o = de(t, r);
|
|
1713
|
+
if (!o) throw new Error("页面中未找到对应字段");
|
|
1714
|
+
if (t.fingerprint && t.fingerprint !== G({ ...t, tagName: o.tagName.toLowerCase() }))
|
|
409
1715
|
throw new Error("字段结构已变化,请重新扫描");
|
|
410
|
-
|
|
1716
|
+
const i = this.matchAdapter(t, r), s = Y(o, t.type);
|
|
1717
|
+
if (t.disabled || o.hasAttribute("disabled") || o.getAttribute("aria-disabled") === "true")
|
|
411
1718
|
throw new Error("字段不可编辑");
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
1719
|
+
if (!s && !i && (t.readonly || o.hasAttribute("readonly")))
|
|
1720
|
+
throw new Error("字段不可编辑");
|
|
1721
|
+
if (i) {
|
|
1722
|
+
await i.setValue(t, n), Ce(o, t);
|
|
415
1723
|
return;
|
|
416
1724
|
}
|
|
417
|
-
|
|
1725
|
+
Tr(o, n), Ce(o, t);
|
|
418
1726
|
}
|
|
419
1727
|
/** 匹配第一个适用的组件库适配器 */
|
|
420
|
-
matchAdapter(
|
|
421
|
-
const
|
|
422
|
-
return
|
|
423
|
-
}
|
|
424
|
-
}
|
|
425
|
-
function
|
|
426
|
-
var
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
1728
|
+
matchAdapter(t, n) {
|
|
1729
|
+
const r = de(t, n);
|
|
1730
|
+
return r ? this.adapters.find((o) => o.match(r, t)) : void 0;
|
|
1731
|
+
}
|
|
1732
|
+
}
|
|
1733
|
+
function de(e, t) {
|
|
1734
|
+
var r;
|
|
1735
|
+
if ((r = e.element) != null && r.isConnected) return e.element;
|
|
1736
|
+
const n = Cr(t == null ? void 0 : t.element);
|
|
1737
|
+
return n || document.querySelector(`[data-smart-fill-id="${Ne(e.fieldId)}"]`);
|
|
1738
|
+
}
|
|
1739
|
+
function Cr(e) {
|
|
1740
|
+
if (e instanceof HTMLElement)
|
|
1741
|
+
return e.isConnected ? e : null;
|
|
1742
|
+
if (typeof e == "string")
|
|
1743
|
+
try {
|
|
1744
|
+
const t = document.querySelector(e);
|
|
1745
|
+
return t instanceof HTMLElement ? t : null;
|
|
1746
|
+
} catch {
|
|
1747
|
+
return null;
|
|
1748
|
+
}
|
|
1749
|
+
return null;
|
|
1750
|
+
}
|
|
1751
|
+
function Tr(e, t) {
|
|
1752
|
+
if (e instanceof HTMLInputElement && e.type === "checkbox")
|
|
1753
|
+
e.checked = !!t;
|
|
1754
|
+
else if (e instanceof HTMLInputElement && e.type === "radio") {
|
|
1755
|
+
const n = document.querySelector(`input[type="radio"][name="${Ne(e.name)}"][value="${Ne(String(t))}"]`);
|
|
1756
|
+
(n || e).checked = !0;
|
|
1757
|
+
} else e instanceof HTMLInputElement || e instanceof HTMLTextAreaElement || e instanceof HTMLSelectElement ? e.value = String(t ?? "") : e.isContentEditable && (e.textContent = String(t ?? ""));
|
|
1758
|
+
e.dispatchEvent(new Event("input", { bubbles: !0 })), e.dispatchEvent(new Event("change", { bubbles: !0 }));
|
|
1759
|
+
}
|
|
1760
|
+
function Ce(e, t) {
|
|
1761
|
+
for (const n of Lr(e, t))
|
|
1762
|
+
Ir(n);
|
|
1763
|
+
}
|
|
1764
|
+
function Lr(e, t) {
|
|
1765
|
+
if (e instanceof HTMLInputElement || e instanceof HTMLTextAreaElement || e instanceof HTMLSelectElement)
|
|
1766
|
+
return [e];
|
|
1767
|
+
const n = Y(e, t == null ? void 0 : t.type) && Ee(e) || e, r = Mr(
|
|
1768
|
+
Array.from(n.querySelectorAll(Ar)).filter(it)
|
|
1769
|
+
);
|
|
1770
|
+
if (r.length)
|
|
1771
|
+
return r;
|
|
1772
|
+
const o = q(n);
|
|
1773
|
+
return o && it(o) ? [o] : [n];
|
|
1774
|
+
}
|
|
1775
|
+
function Ir(e) {
|
|
1776
|
+
var r;
|
|
1777
|
+
e.setAttribute("data-smart-fill-highlighted", "true"), (r = Ae.get(e)) == null || r.abort();
|
|
1778
|
+
const t = new AbortController(), n = (o) => {
|
|
1779
|
+
o && "isTrusted" in o && !o.isTrusted || (e.removeAttribute("data-smart-fill-highlighted"), t.abort(), Ae.delete(e));
|
|
443
1780
|
};
|
|
444
|
-
|
|
1781
|
+
Ae.set(e, t), e.addEventListener("focus", n, { signal: t.signal }), e.addEventListener("pointerdown", n, { signal: t.signal }), e.addEventListener("keydown", n, { signal: t.signal }), e.addEventListener("input", n, { signal: t.signal }), e.addEventListener("change", n, { signal: t.signal });
|
|
445
1782
|
}
|
|
446
|
-
function
|
|
447
|
-
return
|
|
1783
|
+
function Mr(e) {
|
|
1784
|
+
return e.filter((t) => !e.some((n) => n !== t && n.contains(t)));
|
|
448
1785
|
}
|
|
449
|
-
function
|
|
450
|
-
|
|
1786
|
+
function it(e) {
|
|
1787
|
+
const t = window.getComputedStyle(e);
|
|
1788
|
+
if (t.display === "none" || t.visibility === "hidden" || Number(t.opacity) === 0)
|
|
1789
|
+
return !1;
|
|
1790
|
+
const n = e.getBoundingClientRect();
|
|
1791
|
+
return n.width > 0 && n.height > 0;
|
|
451
1792
|
}
|
|
452
|
-
|
|
1793
|
+
function fe(e, t, n, r, o) {
|
|
1794
|
+
return { fieldId: e, label: t, attemptedValue: n, reason: r, reasonCode: o };
|
|
1795
|
+
}
|
|
1796
|
+
function Ne(e) {
|
|
1797
|
+
return typeof CSS < "u" && CSS.escape ? CSS.escape(e) : e.replace(/["\\]/g, "\\$&");
|
|
1798
|
+
}
|
|
1799
|
+
function Rr(e, t) {
|
|
1800
|
+
const n = e.find((o) => o.fieldId === t);
|
|
1801
|
+
if (n) return n;
|
|
1802
|
+
const r = t.includes(":") ? t.slice(t.lastIndexOf(":") + 1) : "";
|
|
1803
|
+
if (r)
|
|
1804
|
+
return e.find((o) => o.rowKey != null && String(o.rowKey) === r && `${o.fieldId}:${o.rowKey}` === t);
|
|
1805
|
+
}
|
|
1806
|
+
const Fr = [
|
|
453
1807
|
{ key: "mobile", pattern: new RegExp("(?<!\\d)1[3-9]\\d{9}(?!\\d)", "g"), confidence: 0.98, reason: "手机号正则命中" },
|
|
454
1808
|
{ key: "idCard", pattern: new RegExp("(?<!\\d)\\d{17}[\\dXx](?!\\d)", "g"), confidence: 0.96, reason: "身份证号正则命中" },
|
|
455
1809
|
{ key: "email", pattern: /[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}/g, confidence: 0.95, reason: "邮箱正则命中" },
|
|
456
1810
|
{ key: "bankCard", pattern: new RegExp("(?<!\\d)\\d{16,19}(?!\\d)", "g"), confidence: 0.9, reason: "银行卡号正则命中" },
|
|
457
1811
|
{ key: "amount", pattern: /(?:金额|价格|费用|合计|总计)[::\s]*([0-9]+(?:\.[0-9]{1,2})?)/g, confidence: 0.88, reason: "金额关键词命中" },
|
|
458
1812
|
{ key: "date", pattern: /\d{4}[-/.年]\d{1,2}[-/.月]\d{1,2}日?/g, confidence: 0.86, reason: "日期格式命中" }
|
|
459
|
-
],
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
1813
|
+
], M = {
|
|
1814
|
+
mobile: [
|
|
1815
|
+
"手机",
|
|
1816
|
+
"手机号",
|
|
1817
|
+
"电话",
|
|
1818
|
+
"联系电话",
|
|
1819
|
+
"mobile",
|
|
1820
|
+
"phone",
|
|
1821
|
+
"法人手机号",
|
|
1822
|
+
"法人电话",
|
|
1823
|
+
"法定代表人手机号",
|
|
1824
|
+
"法人手机",
|
|
1825
|
+
"紧急联系人手机号",
|
|
1826
|
+
"紧急联系人电话",
|
|
1827
|
+
"紧急联系电话",
|
|
1828
|
+
"联系人手机号",
|
|
1829
|
+
"联系人电话",
|
|
1830
|
+
"联系手机",
|
|
1831
|
+
"配偶手机号",
|
|
1832
|
+
"配偶电话",
|
|
1833
|
+
"爱人手机号"
|
|
1834
|
+
],
|
|
1835
|
+
idCard: [
|
|
1836
|
+
"身份证",
|
|
1837
|
+
"证件号",
|
|
1838
|
+
"身份证号",
|
|
1839
|
+
"idcard",
|
|
1840
|
+
"id card",
|
|
1841
|
+
"法人身份证",
|
|
1842
|
+
"法人身份证号",
|
|
1843
|
+
"法定代表人身份证号",
|
|
1844
|
+
"配偶身份证",
|
|
1845
|
+
"配偶身份证号",
|
|
1846
|
+
"爱人身份证号"
|
|
1847
|
+
],
|
|
1848
|
+
email: ["邮箱", "邮件", "email", "mail", "联系人邮箱", "联系邮箱", "contact email"],
|
|
1849
|
+
bankCard: ["银行卡", "卡号", "bank", "bank card"],
|
|
1850
|
+
amount: [
|
|
1851
|
+
"金额",
|
|
1852
|
+
"费用",
|
|
1853
|
+
"价格",
|
|
1854
|
+
"合计",
|
|
1855
|
+
"总计",
|
|
1856
|
+
"amount",
|
|
1857
|
+
"price",
|
|
1858
|
+
"申请金额",
|
|
1859
|
+
"贷款金额",
|
|
1860
|
+
"借款金额",
|
|
1861
|
+
"授信金额",
|
|
1862
|
+
"申请额度"
|
|
1863
|
+
],
|
|
1864
|
+
date: ["日期", "时间", "有效期", "date", "申请日期", "申请时间", "受理日期", "进件日期"]
|
|
1865
|
+
}, zt = {
|
|
490
1866
|
mobile: "mobile",
|
|
491
|
-
legalPersonMobile: "mobile",
|
|
492
|
-
emergencyContactMobile: "mobile",
|
|
493
|
-
contactMobile: "mobile",
|
|
494
|
-
spouseMobile: "mobile",
|
|
495
1867
|
idCard: "idCard",
|
|
496
|
-
legalPersonIdCard: "idCard",
|
|
497
|
-
spouseIdCard: "idCard",
|
|
498
1868
|
email: "email",
|
|
499
|
-
|
|
500
|
-
name: "name",
|
|
501
|
-
customerName: "name",
|
|
502
|
-
legalPersonName: "name",
|
|
503
|
-
emergencyContactName: "name",
|
|
504
|
-
contactName: "name",
|
|
505
|
-
spouseName: "name",
|
|
506
|
-
companyName: "companyName",
|
|
507
|
-
address: "address",
|
|
508
|
-
detailAddress: "address",
|
|
1869
|
+
bankCard: "bankCard",
|
|
509
1870
|
amount: "amount",
|
|
510
|
-
|
|
511
|
-
date: "date",
|
|
512
|
-
applyDate: "date",
|
|
513
|
-
bankCard: "bankCard"
|
|
1871
|
+
date: "date"
|
|
514
1872
|
};
|
|
515
|
-
class
|
|
1873
|
+
class Or {
|
|
516
1874
|
/**
|
|
517
1875
|
* 从文本中提取事实并匹配到 scan 字段。
|
|
518
1876
|
* 按 confidence 降序分配,每个 fieldId 仅匹配一次(usedFieldIds 去重)。
|
|
519
1877
|
*/
|
|
520
|
-
recognize(
|
|
521
|
-
const
|
|
522
|
-
for (const
|
|
523
|
-
const
|
|
524
|
-
|
|
525
|
-
fieldId:
|
|
526
|
-
scanToken:
|
|
527
|
-
label:
|
|
528
|
-
value:
|
|
529
|
-
displayValue:
|
|
530
|
-
confidence:
|
|
1878
|
+
recognize(t, n, r) {
|
|
1879
|
+
const o = Vr([...Dr(t), ...Pr(t)]), i = /* @__PURE__ */ new Set(), s = [];
|
|
1880
|
+
for (const a of o.sort((c, l) => l.confidence - c.confidence)) {
|
|
1881
|
+
const c = Nr(a, n, i);
|
|
1882
|
+
c && (s.push({
|
|
1883
|
+
fieldId: c.fieldId,
|
|
1884
|
+
scanToken: r,
|
|
1885
|
+
label: c.label,
|
|
1886
|
+
value: Hr(a.value, c),
|
|
1887
|
+
displayValue: a.value,
|
|
1888
|
+
confidence: a.confidence,
|
|
531
1889
|
source: "local_rule",
|
|
532
|
-
reason:
|
|
533
|
-
}),
|
|
1890
|
+
reason: a.reason
|
|
1891
|
+
}), i.add(c.fieldId));
|
|
534
1892
|
}
|
|
535
|
-
return
|
|
536
|
-
}
|
|
537
|
-
}
|
|
538
|
-
function
|
|
539
|
-
const
|
|
540
|
-
for (const
|
|
541
|
-
for (const
|
|
542
|
-
const
|
|
543
|
-
|
|
544
|
-
key:
|
|
545
|
-
value:
|
|
546
|
-
confidence:
|
|
547
|
-
reason:
|
|
548
|
-
baseKey:
|
|
1893
|
+
return s;
|
|
1894
|
+
}
|
|
1895
|
+
}
|
|
1896
|
+
function Dr(e) {
|
|
1897
|
+
const t = [];
|
|
1898
|
+
for (const n of Fr)
|
|
1899
|
+
for (const r of e.matchAll(n.pattern)) {
|
|
1900
|
+
const o = Kt(r[1] || r[0]);
|
|
1901
|
+
t.push({
|
|
1902
|
+
key: n.key,
|
|
1903
|
+
value: o,
|
|
1904
|
+
confidence: n.confidence,
|
|
1905
|
+
reason: n.reason,
|
|
1906
|
+
baseKey: zt[n.key]
|
|
549
1907
|
});
|
|
550
1908
|
}
|
|
551
|
-
return
|
|
552
|
-
}
|
|
553
|
-
function
|
|
554
|
-
const
|
|
555
|
-
for (const
|
|
556
|
-
const
|
|
557
|
-
if (!
|
|
558
|
-
const
|
|
559
|
-
if (!(!
|
|
560
|
-
for (const
|
|
561
|
-
|
|
562
|
-
}
|
|
563
|
-
return
|
|
564
|
-
}
|
|
565
|
-
function
|
|
566
|
-
const
|
|
567
|
-
return
|
|
568
|
-
key:
|
|
569
|
-
value:
|
|
570
|
-
confidence: Math.max(0.84, 0.96 -
|
|
571
|
-
reason:
|
|
572
|
-
baseKey:
|
|
1909
|
+
return t;
|
|
1910
|
+
}
|
|
1911
|
+
function Pr(e) {
|
|
1912
|
+
const t = [], n = e.split(/\r?\n|[;,;]/).map((r) => r.trim()).filter(Boolean);
|
|
1913
|
+
for (const r of n) {
|
|
1914
|
+
const o = r.match(/^[“"'`]?([^::=]{2,30})[”"'`]?[::=]\s*(.+)$/);
|
|
1915
|
+
if (!o) continue;
|
|
1916
|
+
const i = Kr(o[1]), s = Kt(o[2]);
|
|
1917
|
+
if (!(!i || !s))
|
|
1918
|
+
for (const a of qr(i, s))
|
|
1919
|
+
t.push(a);
|
|
1920
|
+
}
|
|
1921
|
+
return t;
|
|
1922
|
+
}
|
|
1923
|
+
function qr(e, t) {
|
|
1924
|
+
const n = $(e), r = zr(t), o = [];
|
|
1925
|
+
return (k(n, M.mobile) || r === "mobile") && o.push("mobile"), (k(n, M.idCard) || r === "idCard") && o.push("idCard"), (k(n, M.email) || r === "email") && o.push("email"), (k(n, M.bankCard) || r === "bankCard") && o.push("bankCard"), (k(n, M.amount) || r === "amount") && o.push("amount"), (k(n, M.date) || r === "date") && o.push("date"), Br(o).map((i, s) => ({
|
|
1926
|
+
key: i,
|
|
1927
|
+
value: t,
|
|
1928
|
+
confidence: Math.max(0.84, 0.96 - s * 0.04),
|
|
1929
|
+
reason: `键值对文本命中(${e})`,
|
|
1930
|
+
baseKey: zt[i]
|
|
573
1931
|
}));
|
|
574
1932
|
}
|
|
575
|
-
function
|
|
576
|
-
let
|
|
577
|
-
for (const
|
|
578
|
-
if (
|
|
579
|
-
const
|
|
580
|
-
|
|
1933
|
+
function Nr(e, t, n) {
|
|
1934
|
+
let r = null;
|
|
1935
|
+
for (const o of t) {
|
|
1936
|
+
if (n.has(o.fieldId)) continue;
|
|
1937
|
+
const i = $r(e, o);
|
|
1938
|
+
i > ((r == null ? void 0 : r.score) ?? 0) && (r = { field: o, score: i });
|
|
581
1939
|
}
|
|
582
|
-
return
|
|
583
|
-
}
|
|
584
|
-
function Ve(n, e) {
|
|
585
|
-
const t = k([e.fieldId, e.label, e.placeholder, e.name, e.id, e.section].join(" ")), s = h[n.key] || [n.key], i = h[n.baseKey] || [n.baseKey];
|
|
586
|
-
let r = 0;
|
|
587
|
-
return p(t, s) ? r += 0.95 : n.key !== n.baseKey && p(t, i) ? r += 0.68 : p(t, i) && (r += 0.82), t.includes(k(n.key)) && (r += 0.22), e.required && (r += 0.05), n.baseKey === "amount" && (e.type === "amount" || e.type === "number") && (r += 0.18), n.baseKey === "date" && e.type === "date" && (r += 0.18), n.baseKey === "address" && (e.type === "textarea" || e.type === "text") && (r += 0.12), ["name", "companyName", "email", "mobile", "idCard", "bankCard"].includes(n.baseKey) && e.type === "text" && (r += 0.08), Math.min(r, 1);
|
|
1940
|
+
return r && r.score >= 0.45 ? r.field : null;
|
|
588
1941
|
}
|
|
589
|
-
function
|
|
590
|
-
|
|
591
|
-
|
|
1942
|
+
function $r(e, t) {
|
|
1943
|
+
const n = $([t.fieldId, t.label, t.placeholder, t.name, t.id, t.section].join(" ")), r = M[e.key] || [e.key];
|
|
1944
|
+
let o = 0;
|
|
1945
|
+
return k(n, r) ? o += 0.95 : k(n, [e.key]) && (o += 0.82), n.includes($(e.key)) && (o += 0.22), t.required && (o += 0.05), e.baseKey === "amount" && (t.type === "amount" || t.type === "number") && (o += 0.18), e.baseKey === "date" && t.type === "date" && (o += 0.18), ["email", "mobile", "idCard", "bankCard"].includes(e.baseKey) && t.type === "text" && (o += 0.08), Math.min(o, 1);
|
|
592
1946
|
}
|
|
593
|
-
function
|
|
594
|
-
|
|
595
|
-
return
|
|
1947
|
+
function Hr(e, t) {
|
|
1948
|
+
var n;
|
|
1949
|
+
return t.type === "date" ? e.replace(/[年月/.]/g, "-").replace(/日/g, "").replace(/--/g, "-") : t.type === "number" || t.type === "amount" ? ((n = e.match(/[0-9]+(?:\.[0-9]+)?/)) == null ? void 0 : n[0]) ?? e : t.name && /mobile|phone|idcard|bankcard/i.test(t.name) || t.id && /mobile|phone|idcard|bankcard/i.test(t.id) || /mobile|phone|idcard|bankcard/i.test(t.fieldId) ? e.replace(/\s+/g, "") : e;
|
|
596
1950
|
}
|
|
597
|
-
function
|
|
598
|
-
const
|
|
599
|
-
return /^1[3-9]\d{9}$/.test(
|
|
1951
|
+
function zr(e) {
|
|
1952
|
+
const t = e.replace(/\s+/g, "");
|
|
1953
|
+
return /^1[3-9]\d{9}$/.test(t) ? "mobile" : /^\d{17}[\dXx]$/.test(t) ? "idCard" : /^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$/.test(e) ? "email" : /^\d{16,19}$/.test(t) ? "bankCard" : /^\d{4}[-/.年]\d{1,2}[-/.月]\d{1,2}日?$/.test(e) ? "date" : /^[0-9]+(?:\.[0-9]{1,2})?$/.test(t) ? "amount" : "unknown";
|
|
600
1954
|
}
|
|
601
|
-
function
|
|
602
|
-
|
|
603
|
-
const s = (i = je[e]) == null ? void 0 : i[t];
|
|
604
|
-
s && n.push(s);
|
|
605
|
-
}
|
|
606
|
-
const je = {
|
|
607
|
-
legalPerson: {
|
|
608
|
-
mobile: "legalPersonMobile",
|
|
609
|
-
idCard: "legalPersonIdCard",
|
|
610
|
-
name: "legalPersonName"
|
|
611
|
-
},
|
|
612
|
-
emergencyContact: {
|
|
613
|
-
mobile: "emergencyContactMobile",
|
|
614
|
-
name: "emergencyContactName"
|
|
615
|
-
},
|
|
616
|
-
contact: {
|
|
617
|
-
mobile: "contactMobile",
|
|
618
|
-
email: "contactEmail",
|
|
619
|
-
name: "contactName"
|
|
620
|
-
},
|
|
621
|
-
spouse: {
|
|
622
|
-
mobile: "spouseMobile",
|
|
623
|
-
idCard: "spouseIdCard",
|
|
624
|
-
name: "spouseName"
|
|
625
|
-
}
|
|
626
|
-
};
|
|
627
|
-
function Ye(n) {
|
|
628
|
-
return n.replace(/[“”"'`]/g, "").replace(/\s+/g, " ").trim();
|
|
1955
|
+
function Kr(e) {
|
|
1956
|
+
return e.replace(/[“”"'`]/g, "").replace(/\s+/g, " ").trim();
|
|
629
1957
|
}
|
|
630
|
-
function
|
|
631
|
-
return
|
|
1958
|
+
function Kt(e) {
|
|
1959
|
+
return e.replace(/[,。;;]+$/g, "").replace(/^[“”"'`\s]+|[“”"'`\s]+$/g, "").trim();
|
|
632
1960
|
}
|
|
633
|
-
function
|
|
634
|
-
const
|
|
635
|
-
return
|
|
1961
|
+
function k(e, t) {
|
|
1962
|
+
const n = $(e);
|
|
1963
|
+
return t.some((r) => n.includes($(r)));
|
|
636
1964
|
}
|
|
637
|
-
function
|
|
638
|
-
const
|
|
639
|
-
for (const
|
|
640
|
-
const
|
|
641
|
-
(!
|
|
1965
|
+
function Vr(e) {
|
|
1966
|
+
const t = /* @__PURE__ */ new Map();
|
|
1967
|
+
for (const n of e) {
|
|
1968
|
+
const r = `${n.key}::${n.value}`, o = t.get(r);
|
|
1969
|
+
(!o || o.confidence < n.confidence) && t.set(r, n);
|
|
642
1970
|
}
|
|
643
|
-
return [...
|
|
1971
|
+
return [...t.values()];
|
|
644
1972
|
}
|
|
645
|
-
function
|
|
646
|
-
return [...new Set(
|
|
1973
|
+
function Br(e) {
|
|
1974
|
+
return [...new Set(e)];
|
|
647
1975
|
}
|
|
648
|
-
const
|
|
1976
|
+
const st = [
|
|
649
1977
|
"input",
|
|
650
1978
|
"textarea",
|
|
651
1979
|
"select",
|
|
652
1980
|
"[contenteditable]:not([contenteditable='false'])"
|
|
653
|
-
].join(", "),
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
".el-switch",
|
|
658
|
-
".el-checkbox-group",
|
|
659
|
-
".el-radio-group",
|
|
660
|
-
".el-cascader",
|
|
661
|
-
".el-input-number"
|
|
662
|
-
].join(", "), B = [
|
|
663
|
-
"dialog[open]",
|
|
664
|
-
"[role='dialog']",
|
|
665
|
-
"[aria-modal='true']",
|
|
666
|
-
".modal",
|
|
667
|
-
".modal-dialog",
|
|
668
|
-
".ant-modal",
|
|
669
|
-
".ant-drawer",
|
|
670
|
-
".el-dialog",
|
|
671
|
-
".el-drawer",
|
|
672
|
-
".n-dialog",
|
|
673
|
-
".n-modal",
|
|
674
|
-
".popup",
|
|
675
|
-
".drawer"
|
|
676
|
-
].join(", "), We = /* @__PURE__ */ new Set(["hidden", "submit", "button", "image", "reset", "file", "password"]);
|
|
677
|
-
class Je {
|
|
678
|
-
constructor(e = document) {
|
|
679
|
-
this.root = e;
|
|
1981
|
+
].join(", "), Ur = /* @__PURE__ */ new Set(["hidden", "submit", "button", "image", "reset", "file", "password"]);
|
|
1982
|
+
class jr {
|
|
1983
|
+
constructor(t = document) {
|
|
1984
|
+
this.root = t;
|
|
680
1985
|
}
|
|
681
1986
|
/**
|
|
682
1987
|
* 扫描可回填字段。
|
|
683
1988
|
* - registered 非空:仅解析注册 Schema,不扫 DOM
|
|
684
|
-
* -
|
|
1989
|
+
* - 否则:自动扫描可见原生控件与 UI 框架组件,优先弹窗内控件
|
|
685
1990
|
*/
|
|
686
|
-
scan(
|
|
687
|
-
var
|
|
688
|
-
const
|
|
689
|
-
if ((
|
|
1991
|
+
scan(t = {}) {
|
|
1992
|
+
var l;
|
|
1993
|
+
const n = Se("scan");
|
|
1994
|
+
if ((l = t.registered) != null && l.length)
|
|
690
1995
|
return {
|
|
691
|
-
scanToken:
|
|
692
|
-
fields:
|
|
1996
|
+
scanToken: n,
|
|
1997
|
+
fields: t.registered.map((u) => this.fromSchema(u, n))
|
|
693
1998
|
};
|
|
694
|
-
const
|
|
1999
|
+
const r = this.resolveRoot(t.scanContainer), o = this.collectVisibleFields(r), i = this.detectTopLayerContainer(o), s = o.filter((u) => i.contains(u)), a = (s.length ? s : o).slice(0, t.maxFields ?? 200), c = s.length ? i : r;
|
|
695
2000
|
return {
|
|
696
|
-
scanToken:
|
|
697
|
-
fields:
|
|
2001
|
+
scanToken: n,
|
|
2002
|
+
fields: a.map((u, p) => this.fromElement(u, p, n, c))
|
|
698
2003
|
};
|
|
699
2004
|
}
|
|
2005
|
+
/** 在基础扫描后,按需展开下拉并补充动态选项 */
|
|
2006
|
+
async scanWithDynamicOptions(t = {}) {
|
|
2007
|
+
var o, i;
|
|
2008
|
+
const n = this.scan(t);
|
|
2009
|
+
if (!n.fields.length || (o = t.registered) != null && o.length)
|
|
2010
|
+
return n;
|
|
2011
|
+
const r = [];
|
|
2012
|
+
for (const s of n.fields) {
|
|
2013
|
+
const a = !!((i = s.options) != null && i.length) && !se(s);
|
|
2014
|
+
if (!s.element || a || s.type !== "select" && s.type !== "cascader") {
|
|
2015
|
+
r.push(s);
|
|
2016
|
+
continue;
|
|
2017
|
+
}
|
|
2018
|
+
const c = await gn(s.element), l = c != null && c.length && !se({ ...s, options: c }) ? c : void 0;
|
|
2019
|
+
if (!(l != null && l.length)) {
|
|
2020
|
+
r.push({ ...s, options: se(s) ? void 0 : s.options });
|
|
2021
|
+
continue;
|
|
2022
|
+
}
|
|
2023
|
+
const u = { ...s, options: l };
|
|
2024
|
+
u.fingerprint = G({
|
|
2025
|
+
...u,
|
|
2026
|
+
tagName: s.element.tagName.toLowerCase()
|
|
2027
|
+
}), r.push(u);
|
|
2028
|
+
}
|
|
2029
|
+
return { ...n, fields: r };
|
|
2030
|
+
}
|
|
700
2031
|
/** FieldSchema → FieldDescriptor,解析 element 并生成 fingerprint */
|
|
701
|
-
fromSchema(
|
|
702
|
-
const
|
|
703
|
-
fieldId:
|
|
704
|
-
label:
|
|
705
|
-
type:
|
|
706
|
-
localRuleMode:
|
|
707
|
-
required:
|
|
708
|
-
section:
|
|
709
|
-
options:
|
|
2032
|
+
fromSchema(t, n) {
|
|
2033
|
+
const r = no(t.element, this.root), o = r ? Pe(r) || Re(r) || r : null, i = {
|
|
2034
|
+
fieldId: t.rowKey == null ? t.fieldId : `${t.fieldId}:${t.rowKey}`,
|
|
2035
|
+
label: t.label,
|
|
2036
|
+
type: t.type,
|
|
2037
|
+
localRuleMode: t.localRuleMode ?? "inherit",
|
|
2038
|
+
required: t.required,
|
|
2039
|
+
section: t.section,
|
|
2040
|
+
options: t.options,
|
|
2041
|
+
demoValue: t.demoValue,
|
|
710
2042
|
source: "registered",
|
|
711
|
-
scanToken:
|
|
712
|
-
element:
|
|
2043
|
+
scanToken: n,
|
|
2044
|
+
element: o || void 0,
|
|
713
2045
|
fingerprint: ""
|
|
714
2046
|
};
|
|
715
|
-
return i.fingerprint =
|
|
2047
|
+
return i.fingerprint = G({
|
|
716
2048
|
...i,
|
|
717
|
-
tagName:
|
|
2049
|
+
tagName: o == null ? void 0 : o.tagName.toLowerCase()
|
|
718
2050
|
}), i;
|
|
719
2051
|
}
|
|
720
2052
|
/** DOM 元素 → FieldDescriptor,自动推断 label/type 并写入 data-smart-fill-id */
|
|
721
|
-
fromElement(
|
|
722
|
-
const i =
|
|
2053
|
+
fromElement(t, n, r, o = this.root) {
|
|
2054
|
+
const i = Gr(t, n), s = Xr(t, o), a = {
|
|
723
2055
|
fieldId: i,
|
|
724
2056
|
fingerprint: "",
|
|
725
|
-
scanToken:
|
|
726
|
-
type:
|
|
2057
|
+
scanToken: r,
|
|
2058
|
+
type: Yr(t),
|
|
727
2059
|
localRuleMode: "inherit",
|
|
728
|
-
label:
|
|
729
|
-
placeholder:
|
|
730
|
-
name:
|
|
731
|
-
id:
|
|
732
|
-
section:
|
|
733
|
-
options:
|
|
734
|
-
required:
|
|
735
|
-
readonly:
|
|
736
|
-
disabled:
|
|
2060
|
+
label: Vt(t),
|
|
2061
|
+
placeholder: Ut(t),
|
|
2062
|
+
name: E(wt(t)) || void 0,
|
|
2063
|
+
id: E(t.id) || void 0,
|
|
2064
|
+
section: Wr(t),
|
|
2065
|
+
options: s,
|
|
2066
|
+
required: Qr(t),
|
|
2067
|
+
readonly: Jr(t) && !hn(t),
|
|
2068
|
+
disabled: Te(t),
|
|
737
2069
|
source: "form_scan",
|
|
738
|
-
element:
|
|
2070
|
+
element: t
|
|
739
2071
|
};
|
|
740
|
-
return a.fingerprint =
|
|
2072
|
+
return se(a) && (a.options = void 0), a.fingerprint = G({
|
|
741
2073
|
...a,
|
|
742
|
-
tagName:
|
|
2074
|
+
tagName: t.tagName.toLowerCase()
|
|
743
2075
|
}), a;
|
|
744
2076
|
}
|
|
745
2077
|
/** 解析扫描根节点,scanContainer 为 CSS 选择器 */
|
|
746
|
-
resolveRoot(
|
|
747
|
-
if (
|
|
748
|
-
const
|
|
749
|
-
if (
|
|
750
|
-
return
|
|
2078
|
+
resolveRoot(t) {
|
|
2079
|
+
if (t) {
|
|
2080
|
+
const n = jt(this.root, t);
|
|
2081
|
+
if (n)
|
|
2082
|
+
return n;
|
|
751
2083
|
}
|
|
752
2084
|
return this.root;
|
|
753
2085
|
}
|
|
754
2086
|
/** 收集 root 下可见且可编辑的表单控件 */
|
|
755
|
-
collectVisibleFields(
|
|
756
|
-
const
|
|
757
|
-
|
|
2087
|
+
collectVisibleFields(t) {
|
|
2088
|
+
const n = /* @__PURE__ */ new Set(), r = [st, St, bt, ".van-field"].join(", ");
|
|
2089
|
+
for (const s of t.querySelectorAll(r)) {
|
|
2090
|
+
if (!(s instanceof HTMLElement)) continue;
|
|
2091
|
+
const a = Pe(s) || Re(s);
|
|
2092
|
+
!a || !$e(a) || Te(a) || n.add(a);
|
|
2093
|
+
}
|
|
2094
|
+
const o = [...n], i = Array.from(t.querySelectorAll(st)).filter((s) => !(s instanceof HTMLElement) || !$e(s) || eo(s) || s instanceof HTMLInputElement && Ur.has((s.type || "").toLowerCase()) ? !1 : !Te(s) && !s.hasAttribute("readonly"));
|
|
2095
|
+
return to([...i, ...o]);
|
|
758
2096
|
}
|
|
759
2097
|
/**
|
|
760
2098
|
* 检测最应优先扫描的容器。
|
|
761
2099
|
* 优先 activeElement 所在弹窗,否则取包含最多字段的弹窗容器。
|
|
762
2100
|
*/
|
|
763
|
-
detectTopLayerContainer(
|
|
764
|
-
const
|
|
765
|
-
if (
|
|
766
|
-
return
|
|
767
|
-
const
|
|
768
|
-
return
|
|
2101
|
+
detectTopLayerContainer(t) {
|
|
2102
|
+
const n = document.activeElement instanceof HTMLElement ? document.activeElement : null, r = n == null ? void 0 : n.closest(Xe);
|
|
2103
|
+
if (r instanceof HTMLElement && t.some((i) => r.contains(i)))
|
|
2104
|
+
return r;
|
|
2105
|
+
const o = t.map((i) => i.closest(Xe)).filter((i) => i instanceof HTMLElement);
|
|
2106
|
+
return o.length ? o.sort((i, s) => t.filter((a) => s.contains(a)).length - t.filter((a) => i.contains(a)).length)[0] : document.body;
|
|
769
2107
|
}
|
|
770
2108
|
}
|
|
771
|
-
function
|
|
772
|
-
const
|
|
773
|
-
if (
|
|
774
|
-
return
|
|
775
|
-
const
|
|
776
|
-
return
|
|
777
|
-
}
|
|
778
|
-
function
|
|
779
|
-
const
|
|
780
|
-
if (
|
|
781
|
-
|
|
782
|
-
if (n
|
|
783
|
-
if (
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
if (
|
|
788
|
-
if (
|
|
2109
|
+
function Gr(e, t) {
|
|
2110
|
+
const n = e.getAttribute("data-smart-fill-id");
|
|
2111
|
+
if (n)
|
|
2112
|
+
return n;
|
|
2113
|
+
const o = E(e.getAttribute("name")) || E(e.getAttribute("data-smart-fill-key")) || E(wt(e)) || E(e.id) || E(Vt(e)) || `smart-fill-${Date.now()}-${t}`;
|
|
2114
|
+
return e.setAttribute("data-smart-fill-id", o), o;
|
|
2115
|
+
}
|
|
2116
|
+
function Yr(e) {
|
|
2117
|
+
const t = Ke(e);
|
|
2118
|
+
if (t) return t;
|
|
2119
|
+
const n = he(e);
|
|
2120
|
+
if (n) return n;
|
|
2121
|
+
if (e instanceof HTMLTextAreaElement) return "textarea";
|
|
2122
|
+
if (e instanceof HTMLSelectElement) return "select";
|
|
2123
|
+
if (e instanceof HTMLInputElement) {
|
|
2124
|
+
const r = (e.type || "text").toLowerCase();
|
|
2125
|
+
if (r === "radio") return "radio";
|
|
2126
|
+
if (r === "checkbox") return "checkbox";
|
|
2127
|
+
if (r === "date" || r === "month") return "date";
|
|
2128
|
+
if (r === "number") return "number";
|
|
789
2129
|
}
|
|
790
2130
|
return "text";
|
|
791
2131
|
}
|
|
792
|
-
function
|
|
793
|
-
const
|
|
794
|
-
if (
|
|
795
|
-
if (
|
|
796
|
-
const
|
|
797
|
-
if (
|
|
798
|
-
}
|
|
799
|
-
const
|
|
800
|
-
if (
|
|
801
|
-
const
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
return
|
|
807
|
-
}
|
|
808
|
-
function
|
|
809
|
-
const
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
if (
|
|
814
|
-
return
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
if (
|
|
830
|
-
return Array.from(
|
|
831
|
-
label:
|
|
832
|
-
value:
|
|
2132
|
+
function Vt(e) {
|
|
2133
|
+
const t = e.getAttribute("aria-label");
|
|
2134
|
+
if (t) return t.trim();
|
|
2135
|
+
if (e.id) {
|
|
2136
|
+
const i = document.querySelector(`label[for="${Ye(e.id)}"]`);
|
|
2137
|
+
if (i != null && i.textContent) return f(i.textContent);
|
|
2138
|
+
}
|
|
2139
|
+
const n = e.closest(sn), r = n == null ? void 0 : n.querySelector(an);
|
|
2140
|
+
if (r != null && r.textContent) return f(r.textContent);
|
|
2141
|
+
const o = e.closest("label");
|
|
2142
|
+
if (o) {
|
|
2143
|
+
const i = Bt(o, e);
|
|
2144
|
+
if (i) return i;
|
|
2145
|
+
}
|
|
2146
|
+
return Ut(e) || e.getAttribute("name") || e.id || "未命名字段";
|
|
2147
|
+
}
|
|
2148
|
+
function Bt(e, t) {
|
|
2149
|
+
const n = e.cloneNode(!0);
|
|
2150
|
+
for (const o of n.querySelectorAll('input, textarea, select, button, [role="combobox"], [role="listbox"]'))
|
|
2151
|
+
o.remove();
|
|
2152
|
+
const r = f(n.textContent || "");
|
|
2153
|
+
if (r)
|
|
2154
|
+
return t instanceof HTMLInputElement && t.value && r.includes(t.value) ? f(r.replace(t.value, "")) || void 0 : r;
|
|
2155
|
+
}
|
|
2156
|
+
function Ut(e) {
|
|
2157
|
+
var t;
|
|
2158
|
+
return e.getAttribute("placeholder") || e.getAttribute("aria-placeholder") || ((t = e.querySelector("[placeholder]")) == null ? void 0 : t.getAttribute("placeholder")) || void 0;
|
|
2159
|
+
}
|
|
2160
|
+
function Wr(e) {
|
|
2161
|
+
const t = e.closest("fieldset, section, .panel, .card, .form-section"), n = t == null ? void 0 : t.querySelector("legend, h1, h2, h3, .title, .section-title");
|
|
2162
|
+
return n != null && n.textContent ? f(n.textContent) : void 0;
|
|
2163
|
+
}
|
|
2164
|
+
function Xr(e, t = document) {
|
|
2165
|
+
const n = _t(e);
|
|
2166
|
+
if (n != null && n.length) return n;
|
|
2167
|
+
const r = vt(e);
|
|
2168
|
+
if (r != null && r.length) return r;
|
|
2169
|
+
if (e instanceof HTMLSelectElement)
|
|
2170
|
+
return Array.from(e.options).map((o) => ({
|
|
2171
|
+
label: f(o.textContent || o.label),
|
|
2172
|
+
value: o.value
|
|
833
2173
|
}));
|
|
834
|
-
if (
|
|
835
|
-
return Array.from(
|
|
836
|
-
label:
|
|
837
|
-
value:
|
|
2174
|
+
if (e instanceof HTMLInputElement && (e.type === "radio" || e.type === "checkbox") && e.name)
|
|
2175
|
+
return Array.from(t.querySelectorAll(`input[name="${Ye(e.name)}"]`)).filter((o) => o.type === e.type && $e(o)).map((o) => ({
|
|
2176
|
+
label: Zr(o),
|
|
2177
|
+
value: o.value || !0
|
|
838
2178
|
}));
|
|
839
2179
|
}
|
|
840
|
-
function
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
2180
|
+
function Zr(e) {
|
|
2181
|
+
if (e.id) {
|
|
2182
|
+
const n = document.querySelector(`label[for="${Ye(e.id)}"]`);
|
|
2183
|
+
if (n != null && n.textContent) return f(n.textContent);
|
|
2184
|
+
}
|
|
2185
|
+
const t = e.closest("label");
|
|
2186
|
+
if (t) {
|
|
2187
|
+
const n = Bt(t, e);
|
|
2188
|
+
if (n) return n;
|
|
2189
|
+
}
|
|
2190
|
+
return f(e.getAttribute("aria-label") || e.value || "");
|
|
846
2191
|
}
|
|
847
|
-
function
|
|
848
|
-
|
|
2192
|
+
function $e(e) {
|
|
2193
|
+
const t = window.getComputedStyle(e);
|
|
2194
|
+
return t.display === "none" || t.visibility === "hidden" || Number(t.opacity) === 0 ? !1 : !!(e.offsetWidth || e.offsetHeight || e.getClientRects().length);
|
|
849
2195
|
}
|
|
850
|
-
function
|
|
851
|
-
return
|
|
2196
|
+
function Te(e) {
|
|
2197
|
+
return e instanceof HTMLInputElement || e instanceof HTMLSelectElement || e instanceof HTMLTextAreaElement || e instanceof HTMLButtonElement ? e.disabled || e.getAttribute("aria-disabled") === "true" : e.hasAttribute("disabled") || e.getAttribute("aria-disabled") === "true" || on.some((t) => e.classList.contains(t));
|
|
852
2198
|
}
|
|
853
|
-
function
|
|
854
|
-
|
|
855
|
-
return e instanceof HTMLElement ? re(e) : !1;
|
|
2199
|
+
function Jr(e) {
|
|
2200
|
+
return e.hasAttribute("readonly") || !!e.querySelector("[readonly]");
|
|
856
2201
|
}
|
|
857
|
-
function
|
|
858
|
-
return !!
|
|
2202
|
+
function Qr(e) {
|
|
2203
|
+
return e.hasAttribute("required") || e.getAttribute("aria-required") === "true" || !!e.querySelector('[required], [aria-required="true"]');
|
|
859
2204
|
}
|
|
860
|
-
function
|
|
861
|
-
return
|
|
2205
|
+
function eo(e) {
|
|
2206
|
+
return Pe(e) != null || Re(e) != null;
|
|
862
2207
|
}
|
|
863
|
-
function
|
|
864
|
-
|
|
865
|
-
|
|
2208
|
+
function to(e) {
|
|
2209
|
+
const t = [];
|
|
2210
|
+
for (const n of e)
|
|
2211
|
+
t.some((r) => r === n || r.contains(n) || n.contains(r)) || t.push(n);
|
|
2212
|
+
return t;
|
|
866
2213
|
}
|
|
867
|
-
function
|
|
868
|
-
return
|
|
2214
|
+
function no(e, t) {
|
|
2215
|
+
return e instanceof HTMLElement ? e : typeof e == "string" ? jt(t, e) : null;
|
|
869
2216
|
}
|
|
870
|
-
function
|
|
2217
|
+
function jt(e, t) {
|
|
871
2218
|
try {
|
|
872
|
-
const
|
|
873
|
-
return
|
|
2219
|
+
const n = e.querySelector(t);
|
|
2220
|
+
return n instanceof HTMLElement ? n : null;
|
|
874
2221
|
} catch {
|
|
875
2222
|
return null;
|
|
876
2223
|
}
|
|
877
2224
|
}
|
|
878
|
-
function
|
|
879
|
-
return
|
|
2225
|
+
function Ye(e) {
|
|
2226
|
+
return typeof CSS < "u" && CSS.escape ? CSS.escape(e) : e.replace(/["\\]/g, "\\$&");
|
|
880
2227
|
}
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
const R = 5, ot = 10 * 1024 * 1024, lt = 50 * 1024 * 1024;
|
|
885
|
-
class ct {
|
|
886
|
-
constructor(e) {
|
|
2228
|
+
const Le = 5, ro = 10 * 1024 * 1024, oo = 50 * 1024 * 1024;
|
|
2229
|
+
class io {
|
|
2230
|
+
constructor(t) {
|
|
887
2231
|
/** 面板宿主元素,挂载到 container 下 */
|
|
888
|
-
|
|
2232
|
+
d(this, "host", null);
|
|
889
2233
|
/** Shadow DOM 根或 fallback 到 host */
|
|
890
|
-
|
|
2234
|
+
d(this, "root", null);
|
|
891
2235
|
/** 识别结果候选项,供 review 区域展示 */
|
|
892
|
-
|
|
2236
|
+
d(this, "autoApplyState", null);
|
|
893
2237
|
/** 用户选择的图片文件列表 */
|
|
894
|
-
|
|
2238
|
+
d(this, "selectedFiles", []);
|
|
895
2239
|
/** 文本输入框内容缓存,render 重绘时保留 */
|
|
896
|
-
|
|
2240
|
+
d(this, "inputText", "");
|
|
897
2241
|
/** 本地优先识别开关状态 */
|
|
898
|
-
|
|
2242
|
+
d(this, "localPriorityEnabled");
|
|
899
2243
|
/** 面板展开状态:inline 默认展开,floating 默认收起 */
|
|
900
|
-
|
|
2244
|
+
d(this, "isOpen", !1);
|
|
901
2245
|
/** floating 模式拖拽状态 */
|
|
902
|
-
|
|
2246
|
+
d(this, "dragState", null);
|
|
903
2247
|
/** 拖拽结束后抑制 click 触发 open,避免误开面板 */
|
|
904
|
-
|
|
2248
|
+
d(this, "suppressOpenClick", !1);
|
|
905
2249
|
/** 鼠标是否正悬浮在图片区,供 Ctrl+V 粘贴图片触发判断 */
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
if (!this.dragState || !this.host ||
|
|
909
|
-
const
|
|
910
|
-
(Math.abs(
|
|
911
|
-
const
|
|
912
|
-
this.host.style.left = `${
|
|
2250
|
+
d(this, "isUploadHovering", !1);
|
|
2251
|
+
d(this, "handleDragMove", (t) => {
|
|
2252
|
+
if (!this.dragState || !this.host || t.pointerId !== this.dragState.pointerId) return;
|
|
2253
|
+
const n = t.clientX - this.dragState.startX, r = t.clientY - this.dragState.startY;
|
|
2254
|
+
(Math.abs(n) > 3 || Math.abs(r) > 3) && (this.dragState.moved = !0);
|
|
2255
|
+
const o = this.host.getBoundingClientRect(), i = Math.max(8, window.innerWidth - o.width - 8), s = Math.max(8, window.innerHeight - o.height - 8), a = pe(this.dragState.startLeft + n, 8, i), c = pe(this.dragState.startTop + r, 8, s);
|
|
2256
|
+
this.host.style.left = `${a}px`, this.host.style.top = `${c}px`;
|
|
913
2257
|
});
|
|
914
|
-
|
|
915
|
-
!this.dragState ||
|
|
2258
|
+
d(this, "handleDragEnd", (t) => {
|
|
2259
|
+
!this.dragState || t.pointerId !== this.dragState.pointerId || (this.suppressOpenClick = this.dragState.moved, this.dragState = null, document.removeEventListener("pointermove", this.handleDragMove), document.removeEventListener("pointerup", this.handleDragEnd), document.removeEventListener("pointercancel", this.handleDragEnd), this.suppressOpenClick && window.setTimeout(() => {
|
|
916
2260
|
this.suppressOpenClick = !1;
|
|
917
2261
|
}, 0));
|
|
918
2262
|
});
|
|
919
2263
|
/** 面板聚焦或鼠标悬浮在图片区时接管全局粘贴图片 */
|
|
920
|
-
|
|
921
|
-
const
|
|
922
|
-
if (!
|
|
2264
|
+
d(this, "handleDocumentPaste", (t) => {
|
|
2265
|
+
const n = ao(t);
|
|
2266
|
+
if (!n.length || !this.isOpen || !this.host)
|
|
923
2267
|
return;
|
|
924
|
-
const
|
|
925
|
-
!(
|
|
2268
|
+
const r = document.activeElement, o = this.root instanceof ShadowRoot ? this.root.activeElement : null;
|
|
2269
|
+
!(r === this.host || this.host.contains(r) || o) && !this.isUploadHovering || (t.preventDefault(), this.handleImages(n));
|
|
926
2270
|
});
|
|
927
|
-
this.options =
|
|
2271
|
+
this.options = t, this.localPriorityEnabled = t.localPriorityEnabled ?? !1;
|
|
928
2272
|
}
|
|
929
2273
|
/** 挂载面板到指定容器,创建 Shadow DOM 并首次渲染 */
|
|
930
|
-
mount(
|
|
931
|
-
this.host = document.createElement("div"), this.host.className = `sf-sdk-host sf-sdk-host-${this.options.mode}`,
|
|
2274
|
+
mount(t) {
|
|
2275
|
+
this.host = document.createElement("div"), this.host.className = `sf-sdk-host sf-sdk-host-${this.options.mode}`, t.appendChild(this.host), this.root = this.host.attachShadow ? this.host.attachShadow({ mode: "open" }) : this.host, this.isOpen = this.options.initialOpen ?? this.options.mode === "inline", document.addEventListener("paste", this.handleDocumentPaste), this.render(this.isOpen);
|
|
932
2276
|
}
|
|
933
2277
|
/** 控制面板展开/收起 */
|
|
934
|
-
setOpen(
|
|
935
|
-
this.isOpen =
|
|
2278
|
+
setOpen(t) {
|
|
2279
|
+
this.isOpen = t, this.render(this.isOpen), this.keepHostInViewport();
|
|
936
2280
|
}
|
|
937
2281
|
/** 同步本地优先开关状态(来自其他面板/外部持久化),不触发 onLocalPriorityChange */
|
|
938
|
-
setLocalPriorityEnabled(
|
|
939
|
-
this.localPriorityEnabled =
|
|
940
|
-
const
|
|
941
|
-
|
|
2282
|
+
setLocalPriorityEnabled(t) {
|
|
2283
|
+
this.localPriorityEnabled = t;
|
|
2284
|
+
const n = this.query('[data-role="local-priority-toggle"]');
|
|
2285
|
+
n && (n.checked = t);
|
|
942
2286
|
}
|
|
943
2287
|
/** 识别按钮 loading 状态 */
|
|
944
|
-
setBusy(
|
|
945
|
-
const
|
|
946
|
-
|
|
2288
|
+
setBusy(t, n = "") {
|
|
2289
|
+
const r = this.query('[data-role="recognize"]');
|
|
2290
|
+
r && (r.disabled = t, r.textContent = t ? n : this.t("recognize", "智能识别"));
|
|
947
2291
|
}
|
|
948
2292
|
/** 更新底部状态文案 */
|
|
949
|
-
setStatus(
|
|
950
|
-
const
|
|
951
|
-
|
|
2293
|
+
setStatus(t) {
|
|
2294
|
+
const n = this.query('[data-role="status"]');
|
|
2295
|
+
n && (n.textContent = t, n.removeAttribute("data-status"));
|
|
952
2296
|
}
|
|
953
2297
|
/** 展示错误状态(红色文案) */
|
|
954
|
-
setError(
|
|
955
|
-
const
|
|
956
|
-
|
|
2298
|
+
setError(t) {
|
|
2299
|
+
const n = this.query('[data-role="status"]');
|
|
2300
|
+
n && (n.textContent = t, n.setAttribute("data-status", "error"));
|
|
957
2301
|
}
|
|
958
2302
|
/** 更新识别结果列表并刷新 review 区域 */
|
|
959
|
-
setAutoApplyState(
|
|
960
|
-
this.autoApplyState =
|
|
2303
|
+
setAutoApplyState(t) {
|
|
2304
|
+
this.autoApplyState = t, this.render(!0), this.keepHostInViewport(), this.setStatus(this.t("recognized", "识别完成,正在自动回填..."));
|
|
961
2305
|
}
|
|
962
2306
|
/** 展示回填结果统计(成功/跳过数量) */
|
|
963
|
-
setApplyResult(
|
|
964
|
-
const
|
|
965
|
-
|
|
2307
|
+
setApplyResult(t) {
|
|
2308
|
+
const n = this.query('[data-role="status"]');
|
|
2309
|
+
n && (n.textContent = `已回填 ${t.applied.length} 项,跳过 ${t.skipped.length} 项。`, n.setAttribute("data-status", t.skipped.length ? "warning" : "success"));
|
|
966
2310
|
}
|
|
967
2311
|
/** 移除 DOM 节点并解绑拖拽监听 */
|
|
968
2312
|
destroy() {
|
|
969
|
-
var
|
|
970
|
-
document.removeEventListener("pointermove", this.handleDragMove), document.removeEventListener("pointerup", this.handleDragEnd), document.removeEventListener("pointercancel", this.handleDragEnd), document.removeEventListener("paste", this.handleDocumentPaste), (
|
|
2313
|
+
var t;
|
|
2314
|
+
document.removeEventListener("pointermove", this.handleDragMove), document.removeEventListener("pointerup", this.handleDragEnd), document.removeEventListener("pointercancel", this.handleDragEnd), document.removeEventListener("paste", this.handleDocumentPaste), (t = this.host) == null || t.remove(), this.host = null, this.root = null, this.dragState = null, this.isUploadHovering = !1;
|
|
971
2315
|
}
|
|
972
|
-
render(
|
|
2316
|
+
render(t) {
|
|
973
2317
|
this.root && (this.root.innerHTML = `
|
|
974
|
-
<style>${
|
|
2318
|
+
<style>${co}</style>
|
|
975
2319
|
${this.options.mode === "floating" ? `<button class="sf-float" type="button" data-role="open">${this.t("entry", "智能录入")}</button>` : ""}
|
|
976
|
-
<section class="sf-panel ${
|
|
977
|
-
<header class="sf-header">
|
|
2320
|
+
<section class="sf-panel ${t ? "is-open" : ""} ${this.options.mode === "inline" ? "is-inline" : "is-floating"}" aria-label="智能录入面板">
|
|
2321
|
+
<header class="sf-header" data-role="close" >
|
|
978
2322
|
<strong>${this.t("title", "智能录入")}</strong>
|
|
979
|
-
<button class="sf-icon-btn" type="button"
|
|
2323
|
+
<button class="sf-icon-btn" type="button" aria-label="${this.options.mode === "inline" ? t ? this.t("collapse", "收起") : this.t("expand", "展开") : this.t("close", "关闭")}">${this.options.mode === "inline" ? t ? "∧" : "∨" : "x"}</button>
|
|
980
2324
|
</header>
|
|
981
|
-
<div class="sf-body ${
|
|
2325
|
+
<div class="sf-body ${t ? "is-open" : ""}">
|
|
982
2326
|
<label class="sf-toggle">
|
|
983
2327
|
<span class="sf-toggle-main">
|
|
984
2328
|
<input type="checkbox" data-role="local-priority-toggle" ${this.localPriorityEnabled ? "checked" : ""} />
|
|
985
|
-
<span class="sf-toggle-title">${this.t("localPriorityTitle", "
|
|
2329
|
+
<span class="sf-toggle-title">${this.t("localPriorityTitle", "本地优先")}</span>
|
|
2330
|
+
<span class="sf-toggle-desc">${this.t("localPriorityDesc", "开启后优先使用本地规则提取手机号、证件号等敏感信息")}</span>
|
|
986
2331
|
</span>
|
|
987
|
-
<span class="sf-toggle-desc">${this.t("localPriorityDesc", "开启后优先使用前端本地规则提取手机号、证件号等;关闭后直接走后端识别流程。")}</span>
|
|
988
2332
|
</label>
|
|
989
2333
|
<div class="sf-entry-grid">
|
|
990
2334
|
<div class="sf-textarea-wrap">
|
|
991
|
-
<textarea class="sf-textarea" data-role="text" placeholder="${this.t("placeholder", "粘贴文本,如:姓名:张三 手机号:13800000000")}">${
|
|
2335
|
+
<textarea class="sf-textarea" data-role="text" placeholder="${this.t("placeholder", "粘贴文本,如:姓名:张三 手机号:13800000000")}">${so(this.inputText)}</textarea>
|
|
992
2336
|
<div class="sf-textarea-actions">
|
|
993
2337
|
<button class="sf-btn sf-btn-secondary" type="button" data-role="clear">${this.t("clear", "清空")}</button>
|
|
994
2338
|
<button class="sf-btn sf-btn-primary" type="button" data-role="recognize">${this.t("recognize", "智能识别")}</button>
|
|
@@ -1005,7 +2349,7 @@ class ct {
|
|
|
1005
2349
|
<circle cx="10" cy="10.5" r="1" fill="currentColor"/>
|
|
1006
2350
|
</svg>
|
|
1007
2351
|
</span>
|
|
1008
|
-
<span class="sf-upload-hint">${this.t("uploadHint", `点击、拖拽、Ctrl + V 粘贴图片至此(最多 ${
|
|
2352
|
+
<span class="sf-upload-hint">${this.t("uploadHint", `点击、拖拽、Ctrl + V 粘贴图片至此(最多 ${Le} 张)`)}</span>
|
|
1009
2353
|
</span>
|
|
1010
2354
|
<span class="sf-upload-btn" data-role="file-label">图片识别</span>
|
|
1011
2355
|
</label>
|
|
@@ -1018,48 +2362,48 @@ class ct {
|
|
|
1018
2362
|
`, this.bindEvents());
|
|
1019
2363
|
}
|
|
1020
2364
|
bindEvents() {
|
|
1021
|
-
var
|
|
1022
|
-
const
|
|
1023
|
-
|
|
2365
|
+
var r, o, i, s, a, c, l;
|
|
2366
|
+
const t = this.query('[data-role="open"]');
|
|
2367
|
+
t == null || t.addEventListener("pointerdown", (u) => this.startDrag(u)), t == null || t.addEventListener("click", () => {
|
|
1024
2368
|
this.suppressOpenClick || this.options.onOpen();
|
|
1025
|
-
}), (
|
|
2369
|
+
}), (r = this.query(".sf-header")) == null || r.addEventListener("pointerdown", (u) => this.startDrag(u)), (o = this.query('[data-role="close"]')) == null || o.addEventListener("click", () => {
|
|
1026
2370
|
if (this.options.mode === "inline") {
|
|
1027
2371
|
this.isOpen ? this.options.onClose() : this.options.onOpen();
|
|
1028
2372
|
return;
|
|
1029
2373
|
}
|
|
1030
2374
|
this.options.onClose();
|
|
1031
|
-
}), (
|
|
1032
|
-
const
|
|
1033
|
-
this.handleImages(Array.from(
|
|
2375
|
+
}), (i = this.query('[data-role="file"]')) == null || i.addEventListener("change", (u) => {
|
|
2376
|
+
const p = u.target;
|
|
2377
|
+
this.handleImages(Array.from(p.files || []));
|
|
1034
2378
|
});
|
|
1035
|
-
const
|
|
1036
|
-
|
|
2379
|
+
const n = this.query('[data-role="upload"]');
|
|
2380
|
+
n == null || n.addEventListener("pointerenter", () => {
|
|
1037
2381
|
this.isUploadHovering = !0;
|
|
1038
|
-
}),
|
|
1039
|
-
this.isUploadHovering = !1,
|
|
1040
|
-
}),
|
|
1041
|
-
u.preventDefault(), this.isUploadHovering = !0,
|
|
1042
|
-
}),
|
|
1043
|
-
u.preventDefault(),
|
|
1044
|
-
}),
|
|
1045
|
-
u.currentTarget.contains(u.relatedTarget) || (this.isUploadHovering = !1,
|
|
1046
|
-
}),
|
|
1047
|
-
var
|
|
1048
|
-
u.preventDefault(), this.isUploadHovering = !1,
|
|
1049
|
-
}), (
|
|
2382
|
+
}), n == null || n.addEventListener("pointerleave", () => {
|
|
2383
|
+
this.isUploadHovering = !1, n.removeAttribute("data-dragover");
|
|
2384
|
+
}), n == null || n.addEventListener("dragenter", (u) => {
|
|
2385
|
+
u.preventDefault(), this.isUploadHovering = !0, n.setAttribute("data-dragover", "true");
|
|
2386
|
+
}), n == null || n.addEventListener("dragover", (u) => {
|
|
2387
|
+
u.preventDefault(), n.setAttribute("data-dragover", "true");
|
|
2388
|
+
}), n == null || n.addEventListener("dragleave", (u) => {
|
|
2389
|
+
u.currentTarget.contains(u.relatedTarget) || (this.isUploadHovering = !1, n.removeAttribute("data-dragover"));
|
|
2390
|
+
}), n == null || n.addEventListener("drop", (u) => {
|
|
2391
|
+
var p;
|
|
2392
|
+
u.preventDefault(), this.isUploadHovering = !1, n.removeAttribute("data-dragover"), this.handleImages(Array.from(((p = u.dataTransfer) == null ? void 0 : p.files) || []));
|
|
2393
|
+
}), (s = this.query('[data-role="text"]')) == null || s.addEventListener("input", (u) => {
|
|
1050
2394
|
this.inputText = u.target.value;
|
|
1051
|
-
}), (
|
|
1052
|
-
var
|
|
1053
|
-
this.localPriorityEnabled = u.target.checked, (
|
|
1054
|
-
}), (
|
|
2395
|
+
}), (a = this.query('[data-role="local-priority-toggle"]')) == null || a.addEventListener("change", (u) => {
|
|
2396
|
+
var p, g;
|
|
2397
|
+
this.localPriorityEnabled = u.target.checked, (g = (p = this.options).onLocalPriorityChange) == null || g.call(p, this.localPriorityEnabled);
|
|
2398
|
+
}), (c = this.query('[data-role="clear"]')) == null || c.addEventListener("click", () => {
|
|
1055
2399
|
this.clearFormState();
|
|
1056
2400
|
}), (l = this.query('[data-role="recognize"]')) == null || l.addEventListener("click", () => {
|
|
1057
|
-
const u = this.query('[data-role="text"]'),
|
|
1058
|
-
if (this.inputText = (u == null ? void 0 : u.value) || this.inputText, !
|
|
2401
|
+
const u = this.query('[data-role="text"]'), p = u == null ? void 0 : u.value.trim();
|
|
2402
|
+
if (this.inputText = (u == null ? void 0 : u.value) || this.inputText, !p) {
|
|
1059
2403
|
this.setError(this.t("emptyInput", "请输入文本内容。"));
|
|
1060
2404
|
return;
|
|
1061
2405
|
}
|
|
1062
|
-
this.options.onRecognize({ text:
|
|
2406
|
+
this.options.onRecognize({ text: p });
|
|
1063
2407
|
});
|
|
1064
2408
|
}
|
|
1065
2409
|
clearFormState() {
|
|
@@ -1067,98 +2411,98 @@ class ct {
|
|
|
1067
2411
|
}
|
|
1068
2412
|
/** 清空当前已选图片与上传文案,供 clear 和图片识别成功后复用 */
|
|
1069
2413
|
resetSelectedFiles() {
|
|
1070
|
-
var
|
|
2414
|
+
var n;
|
|
1071
2415
|
this.selectedFiles = [];
|
|
1072
|
-
const
|
|
1073
|
-
|
|
2416
|
+
const t = this.query('[data-role="file"]');
|
|
2417
|
+
t && (t.value = ""), this.isUploadHovering = !1, (n = this.query('[data-role="upload"]')) == null || n.removeAttribute("data-dragover");
|
|
1074
2418
|
}
|
|
1075
2419
|
/** 校验并触发图片识别,支持点击选择 / 拖拽 / 粘贴三种入口 */
|
|
1076
|
-
async handleImages(
|
|
1077
|
-
const
|
|
1078
|
-
if (!
|
|
2420
|
+
async handleImages(t) {
|
|
2421
|
+
const n = t.filter((i) => i.type.startsWith("image/"));
|
|
2422
|
+
if (!n.length) {
|
|
1079
2423
|
this.resetSelectedFiles(), this.setError(this.t("invalidImageError", "请选择图片文件。"));
|
|
1080
2424
|
return;
|
|
1081
2425
|
}
|
|
1082
|
-
if (
|
|
1083
|
-
this.resetSelectedFiles(), this.setError(this.t("maxFilesError", `最多上传 ${
|
|
2426
|
+
if (n.length > Le) {
|
|
2427
|
+
this.resetSelectedFiles(), this.setError(this.t("maxFilesError", `最多上传 ${Le} 张图片。`));
|
|
1084
2428
|
return;
|
|
1085
2429
|
}
|
|
1086
|
-
if (
|
|
2430
|
+
if (n.find((i) => i.size > ro)) {
|
|
1087
2431
|
this.resetSelectedFiles(), this.setError(this.t("maxSingleFileSizeError", "单张图片不能超过 10MB。"));
|
|
1088
2432
|
return;
|
|
1089
2433
|
}
|
|
1090
|
-
if (
|
|
2434
|
+
if (n.reduce((i, s) => i + s.size, 0) > oo) {
|
|
1091
2435
|
this.resetSelectedFiles(), this.setError(this.t("maxTotalFileSizeError", "上传图片总大小不能超过 50MB。"));
|
|
1092
2436
|
return;
|
|
1093
2437
|
}
|
|
1094
|
-
this.selectedFiles =
|
|
2438
|
+
this.selectedFiles = n, this.setStatus(this.t("imageReady", `已选择 ${this.selectedFiles.length} 张图片,开始识别...`));
|
|
1095
2439
|
try {
|
|
1096
2440
|
await this.options.onRecognize({ images: [...this.selectedFiles] }), this.resetSelectedFiles();
|
|
1097
2441
|
} catch {
|
|
1098
2442
|
}
|
|
1099
2443
|
}
|
|
1100
|
-
startDrag(
|
|
1101
|
-
var
|
|
1102
|
-
if (this.options.mode !== "floating" || !this.host ||
|
|
1103
|
-
const
|
|
1104
|
-
this.host.style.left = `${
|
|
1105
|
-
pointerId:
|
|
1106
|
-
startX:
|
|
1107
|
-
startY:
|
|
1108
|
-
startLeft:
|
|
1109
|
-
startTop:
|
|
2444
|
+
startDrag(t) {
|
|
2445
|
+
var r;
|
|
2446
|
+
if (this.options.mode !== "floating" || !this.host || t.button !== 0 || (r = t.target) != null && r.closest('[data-role="close"]')) return;
|
|
2447
|
+
const n = this.host.getBoundingClientRect();
|
|
2448
|
+
this.host.style.left = `${n.left}px`, this.host.style.top = `${n.top}px`, this.host.style.right = "auto", this.host.style.bottom = "auto", this.dragState = {
|
|
2449
|
+
pointerId: t.pointerId,
|
|
2450
|
+
startX: t.clientX,
|
|
2451
|
+
startY: t.clientY,
|
|
2452
|
+
startLeft: n.left,
|
|
2453
|
+
startTop: n.top,
|
|
1110
2454
|
moved: !1
|
|
1111
|
-
},
|
|
2455
|
+
}, t.preventDefault(), document.addEventListener("pointermove", this.handleDragMove), document.addEventListener("pointerup", this.handleDragEnd), document.addEventListener("pointercancel", this.handleDragEnd);
|
|
1112
2456
|
}
|
|
1113
2457
|
keepHostInViewport() {
|
|
1114
2458
|
this.options.mode !== "floating" || !this.host || !this.host.style.left || !this.host.style.top || window.requestAnimationFrame(() => {
|
|
1115
2459
|
if (!this.host) return;
|
|
1116
|
-
const
|
|
1117
|
-
this.host.style.left = `${
|
|
2460
|
+
const t = this.host.getBoundingClientRect(), n = pe(t.left, 8, Math.max(8, window.innerWidth - t.width - 8)), r = pe(t.top, 8, Math.max(8, window.innerHeight - t.height - 8));
|
|
2461
|
+
this.host.style.left = `${n}px`, this.host.style.top = `${r}px`;
|
|
1118
2462
|
});
|
|
1119
2463
|
}
|
|
1120
|
-
query(
|
|
1121
|
-
var
|
|
1122
|
-
return ((
|
|
2464
|
+
query(t) {
|
|
2465
|
+
var n;
|
|
2466
|
+
return ((n = this.root) == null ? void 0 : n.querySelector(t)) || null;
|
|
1123
2467
|
}
|
|
1124
|
-
t(
|
|
1125
|
-
var
|
|
1126
|
-
return ((
|
|
2468
|
+
t(t, n) {
|
|
2469
|
+
var r;
|
|
2470
|
+
return ((r = this.options.messages) == null ? void 0 : r[t]) || n;
|
|
1127
2471
|
}
|
|
1128
2472
|
}
|
|
1129
|
-
function
|
|
1130
|
-
return
|
|
2473
|
+
function so(e) {
|
|
2474
|
+
return e.replace(/[&<>"']/g, (t) => ({
|
|
1131
2475
|
"&": "&",
|
|
1132
2476
|
"<": "<",
|
|
1133
2477
|
">": ">",
|
|
1134
2478
|
'"': """,
|
|
1135
2479
|
"'": "'"
|
|
1136
|
-
})[
|
|
2480
|
+
})[t] || t);
|
|
1137
2481
|
}
|
|
1138
|
-
function
|
|
1139
|
-
return Math.min(Math.max(
|
|
2482
|
+
function pe(e, t, n) {
|
|
2483
|
+
return Math.min(Math.max(e, t), n);
|
|
1140
2484
|
}
|
|
1141
|
-
function
|
|
1142
|
-
var
|
|
1143
|
-
return Array.from(((
|
|
2485
|
+
function ao(e) {
|
|
2486
|
+
var n;
|
|
2487
|
+
return Array.from(((n = e.clipboardData) == null ? void 0 : n.items) || []).filter((r) => r.kind === "file" && r.type.startsWith("image/")).map((r) => r.getAsFile()).filter((r) => !!r);
|
|
1144
2488
|
}
|
|
1145
|
-
const
|
|
2489
|
+
const co = `
|
|
1146
2490
|
:host, .sf-panel { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
|
|
1147
|
-
:host(.sf-sdk-host-floating), .sf-sdk-host-floating { position: fixed; top:
|
|
1148
|
-
.sf-float { align-self: flex-end; border: 0; border-radius: 999px; padding:
|
|
1149
|
-
.sf-panel { display: none; width: 100%; box-sizing: border-box; border: 1px solid #dbe3ef; border-radius: 16px; background: #fff; color: #
|
|
2491
|
+
:host(.sf-sdk-host-floating), .sf-sdk-host-floating { position: fixed; top: 30px; right: 30px; z-index: 2147483647; display: flex; flex-direction: column; align-items: flex-end; gap: 12px; width: min(450px, calc(100vw - 32px)); pointer-events: none; }
|
|
2492
|
+
.sf-float { font-size: 15px; align-self: flex-end; border: 0; border-radius: 999px; padding: 10px 30px; color: #fff; background: linear-gradient(to right, #FF7E49, #FFA34E); box-shadow: 0 10px 24px rgba(37,99,235,.3); cursor: move; user-select: none; touch-action: none; pointer-events: auto; }
|
|
2493
|
+
.sf-panel { display: none; width: 100%; box-sizing: border-box; border: 1px solid #dbe3ef; border-radius: 16px; background: #fff; color: #FF7E49; box-shadow: 0 18px 48px rgba(15,23,42,.18); padding: 12px 16px; pointer-events: auto; }
|
|
1150
2494
|
.sf-panel.is-open { display: block; }
|
|
1151
2495
|
.sf-panel.is-inline { display: block; }
|
|
1152
2496
|
.sf-body { display: none; }
|
|
1153
2497
|
.sf-body.is-open { display: block; }
|
|
1154
2498
|
.sf-header, .sf-actions { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
|
|
1155
2499
|
.sf-header { cursor: move; user-select: none; touch-action: none; }
|
|
1156
|
-
.sf-icon-btn {font-size: 16px; border: 0; background: transparent; cursor: pointer; color: #
|
|
2500
|
+
.sf-icon-btn {font-size: 16px; border: 0; background: transparent; cursor: pointer; color: #FF7E49; font-weight: 900; }
|
|
1157
2501
|
.sf-tip, .sf-status, .sf-empty, small { color: #64748b; font-size: 12px; }
|
|
1158
2502
|
.sf-toggle { display: grid; gap: 4px; margin: 10px 0 12px; padding: 10px 12px; border: 1px solid #dbe3ef; border-radius: 10px; background: #f8fbff; }
|
|
1159
2503
|
.sf-toggle-main { display: flex; align-items: center; gap: 8px; color: #172033; font-size: 13px; font-weight: 600; }
|
|
1160
2504
|
.sf-toggle-main input { margin: 0; }
|
|
1161
|
-
.sf-toggle-desc { color:
|
|
2505
|
+
.sf-toggle-desc { color:rgb(119, 128, 141); font-size: 12px; line-height: 1.4; font-weight: 400; }
|
|
1162
2506
|
.sf-entry-grid { display: grid; grid-template-columns: minmax(0, 1fr) 200px; gap: 12px; align-items: stretch; margin: 10px 0 14px; }
|
|
1163
2507
|
.sf-textarea-wrap { position: relative; }
|
|
1164
2508
|
.sf-textarea { width: 100%; min-height: 140px; resize: vertical; border: 1px solid #cbd5e1; border-radius: 10px; padding: 10px 10px 56px; box-sizing: border-box; }
|
|
@@ -1176,10 +2520,10 @@ const ft = `
|
|
|
1176
2520
|
.sf-btn { border: 1px solid #d7e3f5; border-radius: 999px; background: #fff; color: #4b5563; padding: 8px 20px; cursor: pointer; font-size: 13px; font-weight: 600; transition: all .18s ease; }
|
|
1177
2521
|
.sf-btn:hover { transform: translateY(-1px); box-shadow: 0 8px 20px rgba(15, 23, 42, .08); }
|
|
1178
2522
|
.sf-btn-secondary { background: #fff; color: #6b7280; border-color: #e5e7eb; }
|
|
1179
|
-
.sf-btn-primary { min-width: 100px; border-color: transparent; background: linear-gradient(
|
|
2523
|
+
.sf-btn-primary { min-width: 100px; border-color: transparent; background: linear-gradient(to right, #FF7E49, #FFA34E); color: #fff; box-shadow: 0 12px 26px rgba(59, 114, 246, .32); }
|
|
1180
2524
|
.sf-btn:disabled { opacity: .55; cursor: not-allowed; }
|
|
1181
2525
|
.sf-panel.is-floating .sf-entry-grid { grid-template-columns: 1fr; gap: 10px; }
|
|
1182
|
-
.sf-panel.is-floating .sf-textarea { min-height:
|
|
2526
|
+
.sf-panel.is-floating .sf-textarea { min-height: 180px; }
|
|
1183
2527
|
.sf-panel.is-floating .sf-upload { height: 96px; padding-top: 10px; padding-bottom: 10px; }
|
|
1184
2528
|
.sf-panel.is-floating .sf-upload-illustration { gap: 6px; }
|
|
1185
2529
|
.sf-panel.is-floating .sf-upload-icon { width: 22px; height: 22px; }
|
|
@@ -1188,110 +2532,126 @@ const ft = `
|
|
|
1188
2532
|
[data-status="error"] { color: #dc2626; }
|
|
1189
2533
|
[data-status="warning"] { color: #d97706; }
|
|
1190
2534
|
[data-status="success"] { color: #16a34a; }
|
|
1191
|
-
`,
|
|
1192
|
-
|
|
1193
|
-
|
|
2535
|
+
`, lo = 0.75, uo = 1800, K = /* @__PURE__ */ new Map();
|
|
2536
|
+
let V = 0;
|
|
2537
|
+
const He = "smart-fill:routechange", Gt = "smart-fill:session-scan:";
|
|
2538
|
+
let at = !1;
|
|
2539
|
+
const ct = /* @__PURE__ */ new WeakMap();
|
|
2540
|
+
let fo = 0;
|
|
2541
|
+
function Yt() {
|
|
2542
|
+
K.clear(), en(), V += 1;
|
|
2543
|
+
}
|
|
2544
|
+
class po {
|
|
2545
|
+
constructor(t, n) {
|
|
1194
2546
|
/** 实例级事件总线,对应 instance.on(...) */
|
|
1195
|
-
|
|
2547
|
+
d(this, "events", new Ht());
|
|
1196
2548
|
/** 页面字段扫描器,root 来自 SmartFill.create({ root }) */
|
|
1197
|
-
|
|
2549
|
+
d(this, "scanner");
|
|
1198
2550
|
/** 浏览器端本地规则引擎,用于文本正则/键值对提取 */
|
|
1199
|
-
|
|
2551
|
+
d(this, "ruleEngine", new Or());
|
|
1200
2552
|
/** Shadow DOM 面板,mount / mountFloatingButton 后可用(指向最后挂载的面板,用于状态展示) */
|
|
1201
|
-
|
|
2553
|
+
d(this, "panel", null);
|
|
1202
2554
|
/** 已挂载的全部面板(inline / floating 可同时存在),用于本地优先开关广播与销毁 */
|
|
1203
|
-
|
|
2555
|
+
d(this, "panels", []);
|
|
1204
2556
|
/** 面板展开状态持久化 key */
|
|
1205
|
-
|
|
2557
|
+
d(this, "panelStorageKeys", /* @__PURE__ */ new Map());
|
|
1206
2558
|
/** 业务方 registerFields 注册的字段;非空时 rescan 仅扫描这些字段 */
|
|
1207
|
-
|
|
2559
|
+
d(this, "registeredFields", []);
|
|
1208
2560
|
/** 组件库回填适配器链,如 AntD / Element 自定义控件 */
|
|
1209
|
-
|
|
2561
|
+
d(this, "adapters", [Nt]);
|
|
1210
2562
|
/** 最近一次 rescan 结果;scanToken 用于识别/回填防过期校验 */
|
|
1211
|
-
|
|
2563
|
+
d(this, "scanResult", null);
|
|
1212
2564
|
/** recognize 完成后生成的自动回填候选,供面板展示与 applyAutoItems 使用 */
|
|
1213
|
-
|
|
2565
|
+
d(this, "autoApplyState", null);
|
|
1214
2566
|
/** 预留:表单配置版本号,识别请求可携带给后端 */
|
|
1215
|
-
|
|
2567
|
+
d(this, "formConfigVersion");
|
|
1216
2568
|
/** 面板「启用本地优先识别」开关状态,默认关闭(走后端识别) */
|
|
1217
|
-
|
|
2569
|
+
d(this, "localPriorityEnabled", !1);
|
|
1218
2570
|
/** 实例是否已 destroy,销毁后所有公开方法抛 INSTANCE_DESTROYED */
|
|
1219
|
-
|
|
1220
|
-
|
|
2571
|
+
d(this, "destroyed", !1);
|
|
2572
|
+
/** 页面扫描缓存代际快照;变化时说明缓存已被全局清空 */
|
|
2573
|
+
d(this, "scanCacheVersion", V);
|
|
2574
|
+
/** 悬浮挂载时记录当前路由快照,路由切换后自动销毁实例 */
|
|
2575
|
+
d(this, "floatingRouteSnapshot", null);
|
|
2576
|
+
/** 悬浮挂载生命周期清理函数:移除路由监听和容器 observer */
|
|
2577
|
+
d(this, "floatingLifecycleCleanup", null);
|
|
2578
|
+
/** mount 后预扫描定时器 */
|
|
2579
|
+
d(this, "preScanTimer", null);
|
|
2580
|
+
this.config = t, this.context = n, this.scanner = new jr(t.root || document), this.localPriorityEnabled = qo(), this.context.manager.add(this);
|
|
1221
2581
|
}
|
|
1222
2582
|
/** 订阅实例事件,返回取消订阅函数 */
|
|
1223
|
-
on(
|
|
1224
|
-
return this.events.on(
|
|
2583
|
+
on(t, n) {
|
|
2584
|
+
return this.events.on(t, n);
|
|
1225
2585
|
}
|
|
1226
2586
|
/** 注册组件库回填适配器,支持链式调用 */
|
|
1227
|
-
useAdapter(
|
|
1228
|
-
return this.assertAlive(), this.adapters.push(
|
|
2587
|
+
useAdapter(t) {
|
|
2588
|
+
return this.assertAlive(), this.adapters.push(t), this;
|
|
1229
2589
|
}
|
|
1230
2590
|
/**
|
|
1231
2591
|
* 显式注册字段映射(L3 模式)。
|
|
1232
2592
|
* 注册后 rescan 不再自动扫 DOM,仅解析 element 选择器定位控件。
|
|
1233
2593
|
* rowKey 用于明细行等同 fieldId 多行场景,不可重复。
|
|
1234
2594
|
*/
|
|
1235
|
-
registerFields(
|
|
2595
|
+
registerFields(t) {
|
|
1236
2596
|
this.assertAlive();
|
|
1237
|
-
const
|
|
1238
|
-
for (const
|
|
1239
|
-
const
|
|
1240
|
-
if (
|
|
1241
|
-
throw
|
|
1242
|
-
|
|
2597
|
+
const n = /* @__PURE__ */ new Set();
|
|
2598
|
+
for (const r of t) {
|
|
2599
|
+
const o = r.rowKey == null ? r.fieldId : `${r.fieldId}:${r.rowKey}`;
|
|
2600
|
+
if (n.has(o))
|
|
2601
|
+
throw v("UNSUPPORTED_PAGE", `字段 ${o} 重复注册。`, "scan");
|
|
2602
|
+
n.add(o);
|
|
1243
2603
|
}
|
|
1244
|
-
return this.registeredFields =
|
|
2604
|
+
return this.registeredFields = t, this.scanResult = null, this.schedulePreScan(), this;
|
|
1245
2605
|
}
|
|
1246
2606
|
/** 取消注册字段;不传 fieldIds 时清空全部注册 */
|
|
1247
|
-
unregisterFields(
|
|
1248
|
-
this.assertAlive(), this.registeredFields =
|
|
2607
|
+
unregisterFields(t) {
|
|
2608
|
+
this.assertAlive(), this.registeredFields = t != null && t.length ? this.registeredFields.filter((n) => !t.includes(n.fieldId)) : [], this.scanResult = null, this.schedulePreScan();
|
|
1249
2609
|
}
|
|
1250
2610
|
/** 将面板嵌入指定容器(inline 模式) */
|
|
1251
|
-
mount(
|
|
2611
|
+
mount(t) {
|
|
1252
2612
|
this.assertAlive();
|
|
1253
|
-
const
|
|
1254
|
-
if (!
|
|
1255
|
-
throw
|
|
1256
|
-
const
|
|
1257
|
-
return this.createPanel("inline",
|
|
2613
|
+
const n = typeof t == "string" ? document.querySelector(t) : t;
|
|
2614
|
+
if (!n)
|
|
2615
|
+
throw v("UNSUPPORTED_PAGE", "未找到智能录入挂载点。", "ui");
|
|
2616
|
+
const r = ft("inline", Po(t, n)), o = pt(r, !0);
|
|
2617
|
+
return this.createPanel("inline", r, o).mount(n), this.schedulePreScan(), this;
|
|
1258
2618
|
}
|
|
1259
|
-
/** 挂载右下角悬浮按钮 + 弹框(floating
|
|
2619
|
+
/** 挂载右下角悬浮按钮 + 弹框(floating 模式),优先挂到当前子路由页面顶层容器 */
|
|
1260
2620
|
mountFloatingButton() {
|
|
1261
2621
|
this.assertAlive();
|
|
1262
|
-
const
|
|
1263
|
-
return this.createPanel("floating",
|
|
2622
|
+
const t = Ao(this.config), n = ft("floating"), r = pt(n, !1);
|
|
2623
|
+
return this.createPanel("floating", n, r).mount(t), this.bindFloatingLifecycle(t), this.schedulePreScan(), this;
|
|
1264
2624
|
}
|
|
1265
2625
|
/**
|
|
1266
2626
|
* 创建面板并登记到 panels。
|
|
1267
2627
|
* inline / floating 共用同一份 localPriorityEnabled,开关变更经 handleLocalPriorityChange 持久化并广播。
|
|
1268
2628
|
*/
|
|
1269
|
-
createPanel(
|
|
1270
|
-
let
|
|
1271
|
-
return
|
|
1272
|
-
mode:
|
|
1273
|
-
initialOpen:
|
|
2629
|
+
createPanel(t, n, r) {
|
|
2630
|
+
let o;
|
|
2631
|
+
return o = new io({
|
|
2632
|
+
mode: t,
|
|
2633
|
+
initialOpen: r,
|
|
1274
2634
|
messages: this.config.messages,
|
|
1275
2635
|
localPriorityEnabled: this.localPriorityEnabled,
|
|
1276
|
-
onOpen: () => this.open(
|
|
1277
|
-
onClose: () => this.close(
|
|
1278
|
-
onRecognize: (
|
|
1279
|
-
onLocalPriorityChange: (
|
|
1280
|
-
}), this.panels.push(
|
|
2636
|
+
onOpen: () => this.open(o),
|
|
2637
|
+
onClose: () => this.close(o),
|
|
2638
|
+
onRecognize: (i) => (this.panel = o, this.recognize(i)),
|
|
2639
|
+
onLocalPriorityChange: (i) => this.handleLocalPriorityChange(i, o)
|
|
2640
|
+
}), this.panels.push(o), this.panelStorageKeys.set(o, n), this.panel = o, o;
|
|
1281
2641
|
}
|
|
1282
2642
|
/** 同步本地优先开关:更新内存态、写入 localStorage,并广播到其他已挂载面板 */
|
|
1283
|
-
handleLocalPriorityChange(
|
|
1284
|
-
this.localPriorityEnabled =
|
|
1285
|
-
for (const
|
|
1286
|
-
|
|
2643
|
+
handleLocalPriorityChange(t, n) {
|
|
2644
|
+
this.localPriorityEnabled = t, No(t);
|
|
2645
|
+
for (const r of this.panels)
|
|
2646
|
+
r !== n && r.setLocalPriorityEnabled(t);
|
|
1287
2647
|
}
|
|
1288
2648
|
/** 打开面板并触发 rescan,同时激活当前实例(关闭其他实例面板) */
|
|
1289
|
-
async open(
|
|
1290
|
-
this.assertAlive(),
|
|
2649
|
+
async open(t = this.panel) {
|
|
2650
|
+
this.assertAlive(), this.syncScanCacheVersion(), t && (this.context.manager.activate(this), this.panel = t, t.setOpen(!0), ht(this.panelStorageKeys.get(t), !0), this.scanResult || await this.rescan());
|
|
1291
2651
|
}
|
|
1292
2652
|
/** 关闭面板(不销毁实例) */
|
|
1293
|
-
close(
|
|
1294
|
-
|
|
2653
|
+
close(t = this.panel) {
|
|
2654
|
+
t && (this.panel = t, t.setOpen(!1), ht(this.panelStorageKeys.get(t), !1));
|
|
1295
2655
|
}
|
|
1296
2656
|
/**
|
|
1297
2657
|
* 扫描页面可回填字段。
|
|
@@ -1299,24 +2659,43 @@ class ht {
|
|
|
1299
2659
|
* 扫描成功 emit scanCompleted,失败 emit error。
|
|
1300
2660
|
*/
|
|
1301
2661
|
async rescan() {
|
|
1302
|
-
|
|
1303
|
-
|
|
2662
|
+
return this.assertAlive(), this.syncScanCacheVersion(), this.cancelPreScan(), this.runScan({ dynamicOptions: !0, emitStatus: !0 });
|
|
2663
|
+
}
|
|
2664
|
+
async preScan() {
|
|
2665
|
+
return this.assertAlive(), this.syncScanCacheVersion(), this.runScan({ dynamicOptions: !1, emitStatus: !1 });
|
|
2666
|
+
}
|
|
2667
|
+
async runScan(t) {
|
|
2668
|
+
var n;
|
|
1304
2669
|
try {
|
|
1305
2670
|
this.formConfigVersion = void 0;
|
|
1306
|
-
const t = this.registeredFields.length ? this.registeredFields : void 0
|
|
1307
|
-
|
|
1308
|
-
|
|
2671
|
+
const r = this.getCachedPageScanResult(t.dynamicOptions), o = this.registeredFields.length ? this.registeredFields : void 0, i = o ? this.scanner.scan({
|
|
2672
|
+
registered: o,
|
|
2673
|
+
maxFields: this.config.maxFields
|
|
2674
|
+
}) : r ?? (t.dynamicOptions ? await this.scanner.scanWithDynamicOptions({
|
|
2675
|
+
maxFields: this.config.maxFields
|
|
2676
|
+
}) : this.scanner.scan({
|
|
1309
2677
|
maxFields: this.config.maxFields
|
|
1310
|
-
})
|
|
1311
|
-
|
|
1312
|
-
|
|
2678
|
+
}));
|
|
2679
|
+
if (this.scanResult = i, this.cachePageScanResult(i, t.dynamicOptions), !this.scanResult.fields.length)
|
|
2680
|
+
throw v("NO_FIELDS_FOUND", "当前页面未找到可回填字段。", "scan");
|
|
2681
|
+
return t.emitStatus && (this.events.emit("scanCompleted", {
|
|
1313
2682
|
scanToken: this.scanResult.scanToken,
|
|
1314
2683
|
fieldCount: this.scanResult.fields.length
|
|
1315
|
-
}), (
|
|
1316
|
-
} catch (
|
|
1317
|
-
throw this.emitError(
|
|
2684
|
+
}), (n = this.panel) == null || n.setStatus(`已扫描 ${this.scanResult.fields.length} 个字段。`)), this.scanResult;
|
|
2685
|
+
} catch (r) {
|
|
2686
|
+
throw t.emitStatus && this.emitError(r, "scan"), r;
|
|
1318
2687
|
}
|
|
1319
2688
|
}
|
|
2689
|
+
/** mount 成功后先静默扫描保存;registerFields 存在时仍只扫注册字段 */
|
|
2690
|
+
schedulePreScan() {
|
|
2691
|
+
this.destroyed || !this.panels.length || (this.preScanTimer != null && window.clearTimeout(this.preScanTimer), this.preScanTimer = window.setTimeout(() => {
|
|
2692
|
+
this.preScanTimer = null, !(this.destroyed || this.scanResult) && this.preScan().catch(() => {
|
|
2693
|
+
});
|
|
2694
|
+
}, uo));
|
|
2695
|
+
}
|
|
2696
|
+
cancelPreScan() {
|
|
2697
|
+
this.preScanTimer != null && (window.clearTimeout(this.preScanTimer), this.preScanTimer = null);
|
|
2698
|
+
}
|
|
1320
2699
|
/**
|
|
1321
2700
|
* 识别入口:文本/图片 → 本地规则 + 后端网关 → 合并 → 自动回填。
|
|
1322
2701
|
*
|
|
@@ -1327,74 +2706,79 @@ class ht {
|
|
|
1327
2706
|
*
|
|
1328
2707
|
* 后端失败时,仅在当前已启用本地规则时,降级使用本地结果继续回填。
|
|
1329
2708
|
*/
|
|
1330
|
-
async recognize(
|
|
1331
|
-
var
|
|
1332
|
-
this.assertAlive();
|
|
1333
|
-
const
|
|
1334
|
-
this.events.emit("recognizing", { scanToken:
|
|
2709
|
+
async recognize(t) {
|
|
2710
|
+
var i, s, a, c, l, u;
|
|
2711
|
+
this.assertAlive(), this.syncScanCacheVersion(), (i = this.panel) == null || i.setBusy(!0, "扫描中..."), (s = this.panel) == null || s.setStatus("扫描中...");
|
|
2712
|
+
const n = await this.rescan(), r = Se("trace"), o = performance.now();
|
|
2713
|
+
this.events.emit("recognizing", { scanToken: n.scanToken, traceId: r }), (a = this.panel) == null || a.setBusy(!0, "识别中...");
|
|
1335
2714
|
try {
|
|
1336
|
-
const
|
|
1337
|
-
text:
|
|
1338
|
-
images:
|
|
1339
|
-
onStatusChange: (
|
|
1340
|
-
var
|
|
1341
|
-
if (
|
|
1342
|
-
(
|
|
2715
|
+
const p = n.fields.filter((b) => mo(b.localRuleMode, this.localPriorityEnabled)), g = n.fields.filter((b) => b.localRuleMode !== "only"), { text: x, usedOcr: ne } = await this.context.client.resolveInputText({
|
|
2716
|
+
text: t.text,
|
|
2717
|
+
images: t.images,
|
|
2718
|
+
onStatusChange: (b) => {
|
|
2719
|
+
var oe, I, ie;
|
|
2720
|
+
if (b === "image_uploading") {
|
|
2721
|
+
(oe = this.panel) == null || oe.setStatus("图片上传中...");
|
|
1343
2722
|
return;
|
|
1344
2723
|
}
|
|
1345
|
-
if (
|
|
1346
|
-
(
|
|
2724
|
+
if (b === "image_recognizing") {
|
|
2725
|
+
(I = this.panel) == null || I.setStatus("图片识别中...");
|
|
1347
2726
|
return;
|
|
1348
2727
|
}
|
|
1349
|
-
(
|
|
2728
|
+
(ie = this.panel) == null || ie.setStatus("识别中...");
|
|
1350
2729
|
}
|
|
1351
|
-
}),
|
|
1352
|
-
let
|
|
1353
|
-
if (!
|
|
1354
|
-
|
|
2730
|
+
}), re = x ? this.ruleEngine.recognize(x, p, n.scanToken) : [];
|
|
2731
|
+
let S;
|
|
2732
|
+
if (!g.length)
|
|
2733
|
+
S = lt(n.scanToken, r, re, o, void 0, ne);
|
|
1355
2734
|
else
|
|
1356
2735
|
try {
|
|
1357
|
-
const
|
|
1358
|
-
scanToken:
|
|
2736
|
+
const b = await this.context.client.recognize({
|
|
2737
|
+
scanToken: n.scanToken,
|
|
1359
2738
|
formCode: this.config.formCode,
|
|
1360
2739
|
configVersion: this.formConfigVersion,
|
|
1361
|
-
text:
|
|
1362
|
-
usedOcr:
|
|
1363
|
-
fields:
|
|
2740
|
+
text: x,
|
|
2741
|
+
usedOcr: ne,
|
|
2742
|
+
fields: g,
|
|
1364
2743
|
onStatusChange: () => {
|
|
1365
|
-
var
|
|
1366
|
-
(
|
|
2744
|
+
var I;
|
|
2745
|
+
(I = this.panel) == null || I.setStatus("识别中...");
|
|
1367
2746
|
}
|
|
1368
2747
|
});
|
|
1369
|
-
|
|
1370
|
-
const
|
|
1371
|
-
|
|
1372
|
-
|
|
2748
|
+
b.trace.durationMs = b.trace.durationMs || Math.round(performance.now() - o);
|
|
2749
|
+
const oe = bo(
|
|
2750
|
+
re,
|
|
2751
|
+
b.suggestions.filter((I) => g.some((ie) => ie.fieldId === I.fieldId))
|
|
1373
2752
|
);
|
|
1374
|
-
|
|
1375
|
-
} catch (
|
|
1376
|
-
if (!
|
|
1377
|
-
throw
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
[
|
|
1384
|
-
|
|
2753
|
+
S = { ...b, suggestions: oe };
|
|
2754
|
+
} catch (b) {
|
|
2755
|
+
if (!re.length)
|
|
2756
|
+
throw b;
|
|
2757
|
+
S = lt(
|
|
2758
|
+
n.scanToken,
|
|
2759
|
+
r,
|
|
2760
|
+
re,
|
|
2761
|
+
o,
|
|
2762
|
+
[ne ? "后端识别失败,已使用 OCR 文本触发本地识别继续回填。" : "后端识别失败,已启用本地识别继续回填。"],
|
|
2763
|
+
ne
|
|
1385
2764
|
);
|
|
1386
2765
|
}
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
2766
|
+
if (this.autoApplyState = go(
|
|
2767
|
+
S.scanToken,
|
|
2768
|
+
S.trace.traceId,
|
|
2769
|
+
S.suggestions,
|
|
2770
|
+
n,
|
|
1392
2771
|
this.registeredFields
|
|
1393
|
-
), this.events.emit("recognized",
|
|
1394
|
-
|
|
1395
|
-
|
|
2772
|
+
), this.events.emit("recognized", S), (c = this.panel) == null || c.setAutoApplyState(this.autoApplyState), this.config.apiEnable) {
|
|
2773
|
+
const b = ho(S, this.autoApplyState, n);
|
|
2774
|
+
this.config.apiCallback && await Promise.resolve(this.config.apiCallback(b)), (l = this.panel) == null || l.setStatus(`识别完成,已返回 ${b.fields.length} 个字段。`);
|
|
2775
|
+
} else
|
|
2776
|
+
await this.applyAutoItems(this.autoApplyState);
|
|
2777
|
+
return S;
|
|
2778
|
+
} catch (p) {
|
|
2779
|
+
throw this.clearScanStateOnTokenExpired(p), this.emitError(p, "recognize"), p;
|
|
1396
2780
|
} finally {
|
|
1397
|
-
(
|
|
2781
|
+
(u = this.panel) == null || u.setBusy(!1);
|
|
1398
2782
|
}
|
|
1399
2783
|
}
|
|
1400
2784
|
/**
|
|
@@ -1402,191 +2786,527 @@ class ht {
|
|
|
1402
2786
|
* 通常由业务方调用;recognize 流程内的自动回填走 applyAutoItems。
|
|
1403
2787
|
* 需传入与当前 scanResult 一致的 scanToken。
|
|
1404
2788
|
*/
|
|
1405
|
-
async apply(
|
|
1406
|
-
var
|
|
1407
|
-
if (this.assertAlive(), !this.scanResult)
|
|
1408
|
-
throw
|
|
1409
|
-
this.events.emit("applying", { scanToken:
|
|
1410
|
-
const
|
|
1411
|
-
return this.events.emit("applied",
|
|
2789
|
+
async apply(t) {
|
|
2790
|
+
var o;
|
|
2791
|
+
if (this.assertAlive(), this.syncScanCacheVersion(), !this.scanResult)
|
|
2792
|
+
throw v("SCAN_TOKEN_EXPIRED", "请先扫描字段后再回填。", "apply");
|
|
2793
|
+
this.events.emit("applying", { scanToken: t.scanToken, count: t.values.length });
|
|
2794
|
+
const r = await new ot(this.scanResult.fields, this.registeredFields, this.adapters).apply(t);
|
|
2795
|
+
return this.events.emit("applied", r), (o = this.panel) == null || o.setApplyResult(r), r;
|
|
1412
2796
|
}
|
|
1413
2797
|
/**
|
|
1414
2798
|
* 自动回填:过滤 confidence ≥ 阈值且无 warnings 的候选项,写入 DOM。
|
|
1415
2799
|
* 被策略跳过的字段记录在 skipped 中,reasonCode 为 LOW_CONFIDENCE / AUTO_APPLY_WARNING。
|
|
1416
2800
|
*/
|
|
1417
|
-
async applyAutoItems(
|
|
1418
|
-
var
|
|
2801
|
+
async applyAutoItems(t) {
|
|
2802
|
+
var a, c;
|
|
1419
2803
|
if (!this.scanResult)
|
|
1420
|
-
throw
|
|
1421
|
-
const
|
|
1422
|
-
this.events.emit("applying", { scanToken:
|
|
1423
|
-
const
|
|
1424
|
-
...
|
|
1425
|
-
skipped: [...
|
|
2804
|
+
throw v("SCAN_TOKEN_EXPIRED", "请先扫描字段后再回填。", "apply");
|
|
2805
|
+
const n = yo(t), r = t.items.filter((l) => Wt(l)).map((l) => ({ fieldId: l.fieldId, value: l.value, source: l.source }));
|
|
2806
|
+
this.events.emit("applying", { scanToken: t.scanToken, count: r.length }), (a = this.panel) == null || a.setStatus("识别完成,正在自动回填...");
|
|
2807
|
+
const i = await new ot(this.scanResult.fields, this.registeredFields, this.adapters).apply({ scanToken: t.scanToken, values: r }), s = {
|
|
2808
|
+
...i,
|
|
2809
|
+
skipped: [...n, ...i.skipped],
|
|
1426
2810
|
warnings: [
|
|
1427
|
-
...
|
|
1428
|
-
...
|
|
2811
|
+
...i.warnings || [],
|
|
2812
|
+
...n.length ? ["部分字段因置信度或风险策略被跳过。"] : []
|
|
1429
2813
|
]
|
|
1430
2814
|
};
|
|
1431
|
-
return this.events.emit("applied",
|
|
2815
|
+
return this.events.emit("applied", s), (c = this.panel) == null || c.setApplyResult(s), s;
|
|
1432
2816
|
}
|
|
1433
2817
|
/** 销毁实例:移除面板、清空事件、从 InstanceManager 注销 */
|
|
1434
2818
|
destroy() {
|
|
1435
2819
|
if (!this.destroyed) {
|
|
1436
|
-
this.destroyed = !0;
|
|
1437
|
-
for (const
|
|
2820
|
+
this.destroyed = !0, this.cancelPreScan(), this.clearFloatingLifecycle();
|
|
2821
|
+
for (const t of this.panels) t.destroy();
|
|
1438
2822
|
this.panels.length = 0, this.panelStorageKeys.clear(), this.panel = null, this.events.clear(), this.context.manager.remove(this);
|
|
1439
2823
|
}
|
|
1440
2824
|
}
|
|
1441
2825
|
assertAlive() {
|
|
1442
2826
|
if (this.destroyed)
|
|
1443
|
-
throw
|
|
2827
|
+
throw v("INSTANCE_DESTROYED", "实例已销毁。", "ui");
|
|
2828
|
+
}
|
|
2829
|
+
emitError(t, n) {
|
|
2830
|
+
var o;
|
|
2831
|
+
const r = rt(t, n);
|
|
2832
|
+
this.events.emit("error", r), (o = this.panel) == null || o.setError(r.message);
|
|
2833
|
+
}
|
|
2834
|
+
getCachedPageScanResult(t) {
|
|
2835
|
+
const n = this.getPageScanCacheKey();
|
|
2836
|
+
if (!n) return null;
|
|
2837
|
+
const r = K.get(n);
|
|
2838
|
+
if (r && (!t || r.dynamicOptionsReady)) {
|
|
2839
|
+
const i = wo(r.scanResult);
|
|
2840
|
+
if (!i)
|
|
2841
|
+
K.delete(n);
|
|
2842
|
+
else
|
|
2843
|
+
return i;
|
|
2844
|
+
}
|
|
2845
|
+
const o = this.getPersistedPageScanResult(t);
|
|
2846
|
+
return o ? (this.cachePageScanResult(o.scanResult, o.dynamicOptionsReady), o.scanResult) : null;
|
|
2847
|
+
}
|
|
2848
|
+
cachePageScanResult(t, n) {
|
|
2849
|
+
const r = this.getPageScanCacheKey();
|
|
2850
|
+
if (!r || !t.fields.length) return;
|
|
2851
|
+
const o = K.get(r);
|
|
2852
|
+
o != null && o.dynamicOptionsReady && !n || (K.set(r, {
|
|
2853
|
+
scanResult: t,
|
|
2854
|
+
dynamicOptionsReady: (o == null ? void 0 : o.dynamicOptionsReady) || n
|
|
2855
|
+
}), this.persistPageScanResult(t, (o == null ? void 0 : o.dynamicOptionsReady) || n));
|
|
2856
|
+
}
|
|
2857
|
+
getPageScanCacheKey() {
|
|
2858
|
+
return this.registeredFields.length ? null : xo(this.config);
|
|
2859
|
+
}
|
|
2860
|
+
getSessionPageScanCacheKey() {
|
|
2861
|
+
return this.registeredFields.length || !this.config.formCode ? null : ko(this.config);
|
|
2862
|
+
}
|
|
2863
|
+
clearScanStateOnTokenExpired(t) {
|
|
2864
|
+
rt(t, "recognize").code === "TOKEN_EXPIRED" && (Yt(), this.scanCacheVersion = V, this.scanResult = null, this.autoApplyState = null);
|
|
2865
|
+
}
|
|
2866
|
+
syncScanCacheVersion() {
|
|
2867
|
+
this.scanCacheVersion !== V && (this.scanCacheVersion = V, this.scanResult = null, this.autoApplyState = null);
|
|
2868
|
+
}
|
|
2869
|
+
getPersistedPageScanResult(t) {
|
|
2870
|
+
const n = this.getSessionPageScanCacheKey();
|
|
2871
|
+
if (!n) return null;
|
|
2872
|
+
const r = Oo(n);
|
|
2873
|
+
if (!r || t && !r.dynamicOptionsReady) return null;
|
|
2874
|
+
const o = this.scanner.scan({ maxFields: this.config.maxFields }), i = So(r, o);
|
|
2875
|
+
return i ? {
|
|
2876
|
+
scanResult: i,
|
|
2877
|
+
dynamicOptionsReady: r.dynamicOptionsReady
|
|
2878
|
+
} : (en(n), null);
|
|
2879
|
+
}
|
|
2880
|
+
persistPageScanResult(t, n) {
|
|
2881
|
+
const r = this.getSessionPageScanCacheKey();
|
|
2882
|
+
!r || !t.fields.length || Do(r, {
|
|
2883
|
+
version: 1,
|
|
2884
|
+
dynamicOptionsReady: n,
|
|
2885
|
+
fields: t.fields.map(({ element: o, scanToken: i, ...s }) => s)
|
|
2886
|
+
});
|
|
2887
|
+
}
|
|
2888
|
+
bindFloatingLifecycle(t) {
|
|
2889
|
+
this.clearFloatingLifecycle(), this.floatingRouteSnapshot = dt(), _o();
|
|
2890
|
+
const n = () => {
|
|
2891
|
+
this.destroyed || dt() !== this.floatingRouteSnapshot && this.destroy();
|
|
2892
|
+
};
|
|
2893
|
+
window.addEventListener(He, n);
|
|
2894
|
+
const r = new MutationObserver(() => {
|
|
2895
|
+
this.destroyed || t !== document.body && !t.isConnected && this.destroy();
|
|
2896
|
+
});
|
|
2897
|
+
r.observe(document.body, { childList: !0, subtree: !0 }), this.floatingLifecycleCleanup = () => {
|
|
2898
|
+
window.removeEventListener(He, n), r.disconnect(), this.floatingRouteSnapshot = null, this.floatingLifecycleCleanup = null;
|
|
2899
|
+
};
|
|
1444
2900
|
}
|
|
1445
|
-
|
|
1446
|
-
var
|
|
1447
|
-
|
|
1448
|
-
this.events.emit("error", s), (i = this.panel) == null || i.setError(s.message);
|
|
2901
|
+
clearFloatingLifecycle() {
|
|
2902
|
+
var t;
|
|
2903
|
+
(t = this.floatingLifecycleCleanup) == null || t.call(this);
|
|
1449
2904
|
}
|
|
1450
2905
|
}
|
|
1451
|
-
function
|
|
2906
|
+
function ho(e, t, n) {
|
|
1452
2907
|
return {
|
|
1453
|
-
scanToken:
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
2908
|
+
scanToken: e.scanToken,
|
|
2909
|
+
trace: e.trace,
|
|
2910
|
+
warnings: e.warnings,
|
|
2911
|
+
fields: t.items.map((r) => {
|
|
2912
|
+
const o = n.fields.find((i) => i.fieldId === r.fieldId);
|
|
1457
2913
|
return {
|
|
1458
|
-
applyItemId: `${r.fieldId}_${Math.random().toString(36).slice(2, 8)}`,
|
|
1459
2914
|
fieldId: r.fieldId,
|
|
1460
|
-
scanToken: n,
|
|
1461
|
-
groupId: r.groupId,
|
|
1462
2915
|
label: r.label,
|
|
1463
2916
|
value: r.value,
|
|
1464
|
-
currentValue: d,
|
|
1465
2917
|
displayValue: r.displayValue || String(r.value ?? ""),
|
|
1466
2918
|
confidence: r.confidence,
|
|
1467
2919
|
source: r.source,
|
|
1468
|
-
|
|
1469
|
-
|
|
2920
|
+
type: o == null ? void 0 : o.type,
|
|
2921
|
+
currentValue: r.currentValue,
|
|
2922
|
+
warnings: r.warnings
|
|
2923
|
+
};
|
|
2924
|
+
})
|
|
2925
|
+
};
|
|
2926
|
+
}
|
|
2927
|
+
function go(e, t, n, r, o) {
|
|
2928
|
+
return {
|
|
2929
|
+
scanToken: e,
|
|
2930
|
+
traceId: t,
|
|
2931
|
+
items: n.map((i) => {
|
|
2932
|
+
const s = r.fields.find((l) => l.fieldId === i.fieldId), a = o.find((l) => l.fieldId === i.fieldId), c = a != null && a.getValue ? a.getValue() : vo(s == null ? void 0 : s.element);
|
|
2933
|
+
return {
|
|
2934
|
+
applyItemId: `${i.fieldId}_${Math.random().toString(36).slice(2, 8)}`,
|
|
2935
|
+
fieldId: i.fieldId,
|
|
2936
|
+
scanToken: e,
|
|
2937
|
+
groupId: i.groupId,
|
|
2938
|
+
label: i.label,
|
|
2939
|
+
value: i.value,
|
|
2940
|
+
currentValue: c,
|
|
2941
|
+
displayValue: i.displayValue || String(i.value ?? ""),
|
|
2942
|
+
confidence: i.confidence,
|
|
2943
|
+
source: i.source,
|
|
2944
|
+
warnings: i.warnings,
|
|
2945
|
+
previousValue: c
|
|
1470
2946
|
};
|
|
1471
2947
|
})
|
|
1472
2948
|
};
|
|
1473
2949
|
}
|
|
1474
|
-
function
|
|
1475
|
-
var
|
|
1476
|
-
return
|
|
2950
|
+
function Wt(e) {
|
|
2951
|
+
var t;
|
|
2952
|
+
return e.confidence >= lo && !((t = e.warnings) != null && t.length);
|
|
1477
2953
|
}
|
|
1478
|
-
function
|
|
1479
|
-
return
|
|
1480
|
-
var
|
|
2954
|
+
function yo(e) {
|
|
2955
|
+
return e.items.filter((t) => !Wt(t)).map((t) => {
|
|
2956
|
+
var n, r;
|
|
1481
2957
|
return {
|
|
1482
|
-
fieldId:
|
|
1483
|
-
label:
|
|
1484
|
-
attemptedValue:
|
|
1485
|
-
reason: ((
|
|
1486
|
-
reasonCode: (
|
|
2958
|
+
fieldId: t.fieldId,
|
|
2959
|
+
label: t.label,
|
|
2960
|
+
attemptedValue: t.value,
|
|
2961
|
+
reason: ((n = t.warnings) == null ? void 0 : n.join(";")) || `置信度 ${Math.round(t.confidence * 100)}% 低于自动回填阈值`,
|
|
2962
|
+
reasonCode: (r = t.warnings) != null && r.length ? "AUTO_APPLY_WARNING" : "LOW_CONFIDENCE"
|
|
1487
2963
|
};
|
|
1488
2964
|
});
|
|
1489
2965
|
}
|
|
1490
|
-
function
|
|
1491
|
-
const
|
|
1492
|
-
for (const
|
|
1493
|
-
|
|
1494
|
-
for (const
|
|
1495
|
-
|
|
1496
|
-
return [...
|
|
2966
|
+
function bo(e, t) {
|
|
2967
|
+
const n = /* @__PURE__ */ new Map();
|
|
2968
|
+
for (const r of t)
|
|
2969
|
+
n.set(r.fieldId, r);
|
|
2970
|
+
for (const r of e)
|
|
2971
|
+
n.has(r.fieldId) || n.set(r.fieldId, r);
|
|
2972
|
+
return [...n.values()];
|
|
1497
2973
|
}
|
|
1498
|
-
function
|
|
1499
|
-
return
|
|
2974
|
+
function mo(e, t) {
|
|
2975
|
+
return e === "only" ? !0 : e === "off" ? !1 : t;
|
|
1500
2976
|
}
|
|
1501
|
-
function
|
|
2977
|
+
function lt(e, t, n, r, o, i = !1) {
|
|
1502
2978
|
return {
|
|
1503
|
-
scanToken:
|
|
1504
|
-
suggestions:
|
|
1505
|
-
warnings:
|
|
2979
|
+
scanToken: e,
|
|
2980
|
+
suggestions: n,
|
|
2981
|
+
warnings: o,
|
|
1506
2982
|
trace: {
|
|
1507
|
-
traceId:
|
|
1508
|
-
usedOcr:
|
|
2983
|
+
traceId: t,
|
|
2984
|
+
usedOcr: i,
|
|
1509
2985
|
usedAi: !1,
|
|
1510
|
-
durationMs: Math.round(performance.now() -
|
|
2986
|
+
durationMs: Math.round(performance.now() - r)
|
|
1511
2987
|
}
|
|
1512
2988
|
};
|
|
1513
2989
|
}
|
|
1514
|
-
function
|
|
1515
|
-
if (
|
|
1516
|
-
return
|
|
2990
|
+
function vo(e) {
|
|
2991
|
+
if (e)
|
|
2992
|
+
return e instanceof HTMLInputElement && e.type === "checkbox" ? e.checked : e instanceof HTMLInputElement || e instanceof HTMLTextAreaElement || e instanceof HTMLSelectElement ? e.value : e.textContent;
|
|
1517
2993
|
}
|
|
1518
|
-
function
|
|
1519
|
-
const t =
|
|
1520
|
-
|
|
2994
|
+
function wo(e) {
|
|
2995
|
+
const t = e.fields.map((n) => {
|
|
2996
|
+
if (n.source === "registered")
|
|
2997
|
+
return n;
|
|
2998
|
+
const r = Eo(n);
|
|
2999
|
+
return r ? { ...n, element: r } : null;
|
|
3000
|
+
});
|
|
3001
|
+
return t.some((n) => !n) ? null : {
|
|
3002
|
+
...e,
|
|
3003
|
+
fields: t
|
|
3004
|
+
};
|
|
1521
3005
|
}
|
|
1522
|
-
function
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
const
|
|
1526
|
-
|
|
3006
|
+
function So(e, t) {
|
|
3007
|
+
var s, a;
|
|
3008
|
+
const n = new Map(t.fields.map((c) => [c.fieldId, c])), r = [], o = /* @__PURE__ */ new Set();
|
|
3009
|
+
for (const c of e.fields) {
|
|
3010
|
+
const l = n.get(c.fieldId);
|
|
3011
|
+
if (!l) continue;
|
|
3012
|
+
o.add(c.fieldId);
|
|
3013
|
+
const u = {
|
|
3014
|
+
...l,
|
|
3015
|
+
label: c.label || l.label,
|
|
3016
|
+
placeholder: c.placeholder ?? l.placeholder,
|
|
3017
|
+
name: c.name ?? l.name,
|
|
3018
|
+
id: c.id ?? l.id,
|
|
3019
|
+
section: c.section ?? l.section,
|
|
3020
|
+
options: (s = c.options) != null && s.length ? c.options : l.options,
|
|
3021
|
+
required: c.required ?? l.required,
|
|
3022
|
+
readonly: c.readonly ?? l.readonly,
|
|
3023
|
+
disabled: c.disabled ?? l.disabled
|
|
3024
|
+
};
|
|
3025
|
+
u.fingerprint = G({
|
|
3026
|
+
...u,
|
|
3027
|
+
tagName: (a = u.element) == null ? void 0 : a.tagName.toLowerCase()
|
|
3028
|
+
}), r.push(u);
|
|
3029
|
+
}
|
|
3030
|
+
if (!r.length)
|
|
3031
|
+
return null;
|
|
3032
|
+
const i = t.fields.filter((c) => !o.has(c.fieldId));
|
|
3033
|
+
return {
|
|
3034
|
+
...t,
|
|
3035
|
+
fields: [...r, ...i]
|
|
3036
|
+
};
|
|
1527
3037
|
}
|
|
1528
|
-
function
|
|
3038
|
+
function Eo(e) {
|
|
3039
|
+
var t;
|
|
3040
|
+
if ((t = e.element) != null && t.isConnected) return e.element;
|
|
1529
3041
|
try {
|
|
1530
|
-
|
|
1531
|
-
return t == null ? e : t === "1";
|
|
3042
|
+
return document.querySelector(`[data-smart-fill-id="${$o(e.fieldId)}"]`);
|
|
1532
3043
|
} catch {
|
|
1533
|
-
return
|
|
3044
|
+
return null;
|
|
1534
3045
|
}
|
|
1535
3046
|
}
|
|
1536
|
-
function
|
|
3047
|
+
function xo(e) {
|
|
3048
|
+
const t = typeof location < "u" ? `${location.origin}${location.pathname}${location.search}` : "unknown-page", n = Xt(e.root || document);
|
|
3049
|
+
return `smart-fill:${t}:${e.formCode || "default-form"}:${n}:${e.maxFields ?? 200}:scan`;
|
|
3050
|
+
}
|
|
3051
|
+
function ko(e) {
|
|
3052
|
+
const t = Xt(e.root || document);
|
|
3053
|
+
return `${Gt}${e.formCode || "default-form"}:${t}:${e.maxFields ?? 200}`;
|
|
3054
|
+
}
|
|
3055
|
+
function Xt(e) {
|
|
3056
|
+
if (e === document) return "document";
|
|
3057
|
+
const t = ct.get(e);
|
|
3058
|
+
if (t) return t;
|
|
3059
|
+
const n = e instanceof HTMLElement && e.id ? `el:${e.id}` : `root:${++fo}`;
|
|
3060
|
+
return ct.set(e, n), n;
|
|
3061
|
+
}
|
|
3062
|
+
function _o() {
|
|
3063
|
+
if (at || typeof window > "u") return;
|
|
3064
|
+
at = !0;
|
|
3065
|
+
const e = () => {
|
|
3066
|
+
window.dispatchEvent(new Event(He));
|
|
3067
|
+
};
|
|
3068
|
+
window.addEventListener("popstate", e), window.addEventListener("hashchange", e), ut("pushState", e), ut("replaceState", e);
|
|
3069
|
+
}
|
|
3070
|
+
function ut(e, t) {
|
|
3071
|
+
const n = window.history[e];
|
|
3072
|
+
window.history[e] = function(...o) {
|
|
3073
|
+
const i = n.apply(this, o);
|
|
3074
|
+
return t(), i;
|
|
3075
|
+
};
|
|
3076
|
+
}
|
|
3077
|
+
function dt() {
|
|
3078
|
+
return typeof location > "u" ? "unknown-route" : `${location.pathname}${location.search}${location.hash}`;
|
|
3079
|
+
}
|
|
3080
|
+
function Ao(e) {
|
|
3081
|
+
const t = Co(e.floatingContainer);
|
|
3082
|
+
if (t)
|
|
3083
|
+
return t;
|
|
3084
|
+
const n = To(e.routeContainerSelector);
|
|
3085
|
+
return n || Lo() || document.body;
|
|
3086
|
+
}
|
|
3087
|
+
function Co(e) {
|
|
3088
|
+
return e ? e instanceof HTMLElement ? e : ze(e) : null;
|
|
3089
|
+
}
|
|
3090
|
+
function To(e) {
|
|
3091
|
+
if (!e) return null;
|
|
3092
|
+
const t = Zt(), n = t ? ze(e, t) : null;
|
|
3093
|
+
return n || ze(e);
|
|
3094
|
+
}
|
|
3095
|
+
function Lo() {
|
|
3096
|
+
const e = Zt();
|
|
3097
|
+
if (!e)
|
|
3098
|
+
return null;
|
|
3099
|
+
const t = Io(e);
|
|
3100
|
+
if (t)
|
|
3101
|
+
return t;
|
|
3102
|
+
const n = Mo(e);
|
|
1537
3103
|
if (n)
|
|
3104
|
+
return n;
|
|
3105
|
+
const r = Ro(e);
|
|
3106
|
+
return r !== e ? r : null;
|
|
3107
|
+
}
|
|
3108
|
+
function Zt() {
|
|
3109
|
+
const e = [
|
|
3110
|
+
"#app",
|
|
3111
|
+
"#root",
|
|
3112
|
+
"#__next",
|
|
3113
|
+
"#nuxt",
|
|
3114
|
+
"[data-reactroot]",
|
|
3115
|
+
"[data-v-app]",
|
|
3116
|
+
"[data-vue-app]",
|
|
3117
|
+
"[data-app-root]",
|
|
3118
|
+
"[data-router-root]"
|
|
3119
|
+
];
|
|
3120
|
+
for (const t of e) {
|
|
3121
|
+
const n = document.querySelector(t);
|
|
3122
|
+
if (n && ke(n))
|
|
3123
|
+
return n;
|
|
3124
|
+
}
|
|
3125
|
+
return null;
|
|
3126
|
+
}
|
|
3127
|
+
function Io(e) {
|
|
3128
|
+
const t = w(e), n = Jt(e).filter((o) => !We(o)).filter((o) => w(o) >= Math.max(t * 0.2, 48e3)), r = n.filter((o) => Fo(o));
|
|
3129
|
+
return r.length ? r.sort((o, i) => w(i) - w(o))[0] : n.length === 1 ? n[0] : null;
|
|
3130
|
+
}
|
|
3131
|
+
function Mo(e) {
|
|
3132
|
+
const t = [
|
|
3133
|
+
"[data-route-root]",
|
|
3134
|
+
"[data-router-view]",
|
|
3135
|
+
"[data-page-root]",
|
|
3136
|
+
"[data-page-container]",
|
|
3137
|
+
".router-view",
|
|
3138
|
+
".route-view",
|
|
3139
|
+
".page-root",
|
|
3140
|
+
".page-container",
|
|
3141
|
+
".page",
|
|
3142
|
+
".layout-content",
|
|
3143
|
+
".app-main",
|
|
3144
|
+
".app-content",
|
|
3145
|
+
"main",
|
|
3146
|
+
'[role="main"]'
|
|
3147
|
+
], n = Qt(e), r = w(e);
|
|
3148
|
+
return t.flatMap((i) => Array.from(e.querySelectorAll(i))).filter((i) => ke(i) && !We(i)).filter((i) => Ie(i, n) <= 3).filter((i) => w(i) >= Math.max(r * 0.2, 48e3)).sort((i, s) => Ie(i, n) - Ie(s, n) || w(s) - w(i))[0] || null;
|
|
3149
|
+
}
|
|
3150
|
+
function Ro(e) {
|
|
3151
|
+
let t = e;
|
|
3152
|
+
for (; ; ) {
|
|
3153
|
+
const n = Jt(t).filter((o) => !We(o));
|
|
3154
|
+
if (n.length !== 1)
|
|
3155
|
+
return t;
|
|
3156
|
+
const [r] = n;
|
|
3157
|
+
if (w(r) < Math.max(w(t) * 0.25, 48e3))
|
|
3158
|
+
return t;
|
|
3159
|
+
t = r;
|
|
3160
|
+
}
|
|
3161
|
+
}
|
|
3162
|
+
function Jt(e) {
|
|
3163
|
+
return Array.from(e.children).filter((t) => t instanceof HTMLElement).filter((t) => ke(t));
|
|
3164
|
+
}
|
|
3165
|
+
function ze(e, t = document) {
|
|
3166
|
+
try {
|
|
3167
|
+
const n = t.querySelector(e);
|
|
3168
|
+
return n && ke(n) ? n : null;
|
|
3169
|
+
} catch {
|
|
3170
|
+
return null;
|
|
3171
|
+
}
|
|
3172
|
+
}
|
|
3173
|
+
function ke(e) {
|
|
3174
|
+
const t = window.getComputedStyle(e);
|
|
3175
|
+
if (t.display === "none" || t.visibility === "hidden" || Number(t.opacity) === 0)
|
|
3176
|
+
return !1;
|
|
3177
|
+
const n = e.getBoundingClientRect();
|
|
3178
|
+
return n.width > 0 && n.height > 0;
|
|
3179
|
+
}
|
|
3180
|
+
function We(e) {
|
|
3181
|
+
const t = window.getComputedStyle(e);
|
|
3182
|
+
return t.position === "fixed" || t.position === "sticky" ? !0 : w(e) < 24e3;
|
|
3183
|
+
}
|
|
3184
|
+
function Fo(e) {
|
|
3185
|
+
if (e.tagName.toLowerCase() === "main" || e.getAttribute("role") === "main")
|
|
3186
|
+
return !0;
|
|
3187
|
+
const t = e.id || "", n = typeof e.className == "string" ? e.className : "", r = `${t} ${n}`.toLowerCase();
|
|
3188
|
+
return /(page|layout|content|container|main|router|route|view)/.test(r);
|
|
3189
|
+
}
|
|
3190
|
+
function w(e) {
|
|
3191
|
+
const t = e.getBoundingClientRect();
|
|
3192
|
+
return Math.max(0, t.width) * Math.max(0, t.height);
|
|
3193
|
+
}
|
|
3194
|
+
function Qt(e) {
|
|
3195
|
+
let t = 0, n = e;
|
|
3196
|
+
for (; n && n !== document.body; )
|
|
3197
|
+
t += 1, n = n.parentElement;
|
|
3198
|
+
return t;
|
|
3199
|
+
}
|
|
3200
|
+
function Ie(e, t) {
|
|
3201
|
+
return Math.max(0, Qt(e) - t);
|
|
3202
|
+
}
|
|
3203
|
+
function Oo(e) {
|
|
3204
|
+
try {
|
|
3205
|
+
const t = window.sessionStorage.getItem(e);
|
|
3206
|
+
if (!t) return null;
|
|
3207
|
+
const n = JSON.parse(t);
|
|
3208
|
+
return (n == null ? void 0 : n.version) !== 1 || !Array.isArray(n.fields) ? null : n;
|
|
3209
|
+
} catch {
|
|
3210
|
+
return null;
|
|
3211
|
+
}
|
|
3212
|
+
}
|
|
3213
|
+
function Do(e, t) {
|
|
3214
|
+
try {
|
|
3215
|
+
window.sessionStorage.setItem(e, JSON.stringify(t));
|
|
3216
|
+
} catch {
|
|
3217
|
+
}
|
|
3218
|
+
}
|
|
3219
|
+
function en(e) {
|
|
3220
|
+
try {
|
|
3221
|
+
if (e) {
|
|
3222
|
+
window.sessionStorage.removeItem(e);
|
|
3223
|
+
return;
|
|
3224
|
+
}
|
|
3225
|
+
const t = [];
|
|
3226
|
+
for (let n = 0; n < window.sessionStorage.length; n += 1) {
|
|
3227
|
+
const r = window.sessionStorage.key(n);
|
|
3228
|
+
r != null && r.startsWith(Gt) && t.push(r);
|
|
3229
|
+
}
|
|
3230
|
+
for (const n of t)
|
|
3231
|
+
window.sessionStorage.removeItem(n);
|
|
3232
|
+
} catch {
|
|
3233
|
+
}
|
|
3234
|
+
}
|
|
3235
|
+
function ft(e, t = "default") {
|
|
3236
|
+
const n = typeof location < "u" ? location.pathname : "unknown-page", r = t.replace(/[^\w-]/g, "_") || "default";
|
|
3237
|
+
return `smart-fill:${e}:${n}:${r}:open`;
|
|
3238
|
+
}
|
|
3239
|
+
function Po(e, t) {
|
|
3240
|
+
if (typeof e == "string") return e;
|
|
3241
|
+
if (t.id) return `#${t.id}`;
|
|
3242
|
+
const n = typeof t.className == "string" ? t.className.trim().split(/\s+/).filter(Boolean)[0] : "";
|
|
3243
|
+
return n ? `.${n}` : t.tagName.toLowerCase();
|
|
3244
|
+
}
|
|
3245
|
+
function pt(e, t) {
|
|
3246
|
+
try {
|
|
3247
|
+
const n = window.localStorage.getItem(e);
|
|
3248
|
+
return n == null ? t : n === "1";
|
|
3249
|
+
} catch {
|
|
3250
|
+
return t;
|
|
3251
|
+
}
|
|
3252
|
+
}
|
|
3253
|
+
function ht(e, t) {
|
|
3254
|
+
if (e)
|
|
1538
3255
|
try {
|
|
1539
|
-
window.localStorage.setItem(
|
|
3256
|
+
window.localStorage.setItem(e, t ? "1" : "0");
|
|
1540
3257
|
} catch {
|
|
1541
3258
|
}
|
|
1542
3259
|
}
|
|
1543
|
-
function
|
|
3260
|
+
function tn() {
|
|
1544
3261
|
return `smart-fill:${typeof location < "u" ? location.pathname : "unknown-page"}:local-priority`;
|
|
1545
3262
|
}
|
|
1546
|
-
function
|
|
3263
|
+
function qo() {
|
|
1547
3264
|
try {
|
|
1548
|
-
return window.localStorage.getItem(
|
|
3265
|
+
return window.localStorage.getItem(tn()) === "1";
|
|
1549
3266
|
} catch {
|
|
1550
3267
|
return !1;
|
|
1551
3268
|
}
|
|
1552
3269
|
}
|
|
1553
|
-
function
|
|
3270
|
+
function No(e) {
|
|
1554
3271
|
try {
|
|
1555
|
-
window.localStorage.setItem(
|
|
3272
|
+
window.localStorage.setItem(tn(), e ? "1" : "0");
|
|
1556
3273
|
} catch {
|
|
1557
3274
|
}
|
|
1558
3275
|
}
|
|
1559
|
-
|
|
1560
|
-
|
|
3276
|
+
function $o(e) {
|
|
3277
|
+
return typeof CSS < "u" && CSS.escape ? CSS.escape(e) : e.replace(/["\\]/g, "\\$&");
|
|
3278
|
+
}
|
|
3279
|
+
const h = { status: "idle" }, Me = new Ht(), gt = new kr();
|
|
3280
|
+
class Ho {
|
|
1561
3281
|
/** 初始化 SDK:校验 apiKey、创建会话、获取 accessToken */
|
|
1562
|
-
static async setup(
|
|
3282
|
+
static async setup(t) {
|
|
1563
3283
|
if (typeof window > "u")
|
|
1564
|
-
return
|
|
1565
|
-
if (
|
|
1566
|
-
return
|
|
1567
|
-
if (
|
|
1568
|
-
return
|
|
1569
|
-
|
|
1570
|
-
const
|
|
1571
|
-
return
|
|
1572
|
-
throw
|
|
1573
|
-
}),
|
|
3284
|
+
return h.status = "ready", zo();
|
|
3285
|
+
if (h.status === "ready" && h.apiKey === t.apiKey && h.session)
|
|
3286
|
+
return h.session;
|
|
3287
|
+
if (h.status === "loading" && h.apiKey === t.apiKey && h.promise)
|
|
3288
|
+
return h.promise;
|
|
3289
|
+
h.apiKey && h.apiKey !== t.apiKey && (Yt(), gt.destroyAll());
|
|
3290
|
+
const n = new mr(t);
|
|
3291
|
+
return h.status = "loading", h.apiKey = t.apiKey, h.client = n, h.promise = n.createSession().then((r) => (console.log("SmartFill session created:", r), n.setAccessToken(r.apiKey), h.status = "ready", h.session = r, Me.emit("ready", { apiKey: t.apiKey }), r)).catch((r) => {
|
|
3292
|
+
throw h.status = "error", r;
|
|
3293
|
+
}), h.promise;
|
|
1574
3294
|
}
|
|
1575
3295
|
/** 创建页面实例,必须在 setup ready 后调用 */
|
|
1576
|
-
static create(
|
|
3296
|
+
static create(t = {}) {
|
|
1577
3297
|
if (typeof window > "u")
|
|
1578
|
-
return
|
|
1579
|
-
if (
|
|
1580
|
-
throw
|
|
1581
|
-
return new
|
|
1582
|
-
client:
|
|
1583
|
-
manager:
|
|
3298
|
+
return B();
|
|
3299
|
+
if (h.status !== "ready" || !h.client)
|
|
3300
|
+
throw v("SDK_NOT_READY", "请先 await SmartFill.setup({ apiKey })。", "setup");
|
|
3301
|
+
return new po(t, {
|
|
3302
|
+
client: h.client,
|
|
3303
|
+
manager: gt
|
|
1584
3304
|
});
|
|
1585
3305
|
}
|
|
1586
3306
|
}
|
|
1587
3307
|
/** 订阅全局事件(目前仅 ready) */
|
|
1588
|
-
|
|
1589
|
-
function
|
|
3308
|
+
d(Ho, "on", Me.on.bind(Me));
|
|
3309
|
+
function zo() {
|
|
1590
3310
|
return {
|
|
1591
3311
|
apiKey: "server-mock",
|
|
1592
3312
|
accessToken: "server-mock",
|
|
@@ -1596,51 +3316,41 @@ function kt() {
|
|
|
1596
3316
|
rulesVersion: "server"
|
|
1597
3317
|
};
|
|
1598
3318
|
}
|
|
1599
|
-
function
|
|
1600
|
-
const
|
|
3319
|
+
function B(e) {
|
|
3320
|
+
const t = () => {
|
|
1601
3321
|
};
|
|
1602
3322
|
return {
|
|
1603
|
-
on:
|
|
1604
|
-
useAdapter: () =>
|
|
1605
|
-
registerFields: () =>
|
|
1606
|
-
unregisterFields:
|
|
1607
|
-
mount: () =>
|
|
1608
|
-
mountFloatingButton: () =>
|
|
3323
|
+
on: t,
|
|
3324
|
+
useAdapter: () => B(),
|
|
3325
|
+
registerFields: () => B(),
|
|
3326
|
+
unregisterFields: t,
|
|
3327
|
+
mount: () => B(),
|
|
3328
|
+
mountFloatingButton: () => B(),
|
|
1609
3329
|
open: async () => {
|
|
1610
3330
|
},
|
|
1611
|
-
close:
|
|
3331
|
+
close: t,
|
|
1612
3332
|
rescan: async () => ({ scanToken: "server", fields: [] }),
|
|
1613
3333
|
recognize: async () => ({
|
|
1614
3334
|
scanToken: "server",
|
|
1615
3335
|
suggestions: [],
|
|
1616
3336
|
trace: { traceId: "server", usedOcr: !1, usedAi: !1, durationMs: 0 }
|
|
1617
3337
|
}),
|
|
3338
|
+
// 识别结果
|
|
1618
3339
|
apply: async () => ({ applied: [], skipped: [] }),
|
|
1619
|
-
|
|
3340
|
+
// 回填结果
|
|
3341
|
+
destroy: t
|
|
3342
|
+
// 销毁实例
|
|
1620
3343
|
};
|
|
1621
3344
|
}
|
|
1622
|
-
const It = {
|
|
1623
|
-
name: "native",
|
|
1624
|
-
/** 匹配 input / textarea / select 原生控件 */
|
|
1625
|
-
match: (n) => n instanceof HTMLInputElement || n instanceof HTMLTextAreaElement || n instanceof HTMLSelectElement,
|
|
1626
|
-
getValue: (n) => {
|
|
1627
|
-
const e = n.element;
|
|
1628
|
-
if (e instanceof HTMLInputElement && e.type === "checkbox") return e.checked;
|
|
1629
|
-
if (e instanceof HTMLInputElement || e instanceof HTMLTextAreaElement || e instanceof HTMLSelectElement) return e.value;
|
|
1630
|
-
},
|
|
1631
|
-
setValue: (n, e) => {
|
|
1632
|
-
const t = n.element;
|
|
1633
|
-
t instanceof HTMLInputElement && t.type === "checkbox" ? t.checked = !!e : (t instanceof HTMLInputElement || t instanceof HTMLTextAreaElement || t instanceof HTMLSelectElement) && (t.value = String(e ?? "")), t == null || t.dispatchEvent(new Event("input", { bubbles: !0 })), t == null || t.dispatchEvent(new Event("change", { bubbles: !0 }));
|
|
1634
|
-
}
|
|
1635
|
-
};
|
|
1636
3345
|
export {
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
3346
|
+
br as DEFAULT_BASE_URL,
|
|
3347
|
+
ot as DomFiller,
|
|
3348
|
+
jr as DomScanner,
|
|
3349
|
+
Bo as ElementAdapter,
|
|
3350
|
+
Ht as EventBus,
|
|
3351
|
+
Or as LocalRuleEngine,
|
|
3352
|
+
Vo as NativeAdapter,
|
|
3353
|
+
Ho as SmartFill,
|
|
3354
|
+
po as SmartFillInstance,
|
|
3355
|
+
Nt as UiFrameworkAdapter
|
|
1646
3356
|
};
|