@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.
Files changed (33) hide show
  1. package/README.md +20 -1
  2. package/dist/index.esm.js +2748 -1038
  3. package/dist/index.umd.cjs +28 -19
  4. package/dist/src/adapters/element.d.ts +2 -2
  5. package/dist/src/adapters/element.d.ts.map +1 -1
  6. package/dist/src/adapters/ui-framework.d.ts +5 -0
  7. package/dist/src/adapters/ui-framework.d.ts.map +1 -0
  8. package/dist/src/client/gateway-client.d.ts.map +1 -1
  9. package/dist/src/config/defaults.d.ts +1 -1
  10. package/dist/src/config/defaults.d.ts.map +1 -1
  11. package/dist/src/core/smart-fill-instance.d.ts +25 -1
  12. package/dist/src/core/smart-fill-instance.d.ts.map +1 -1
  13. package/dist/src/core/smart-fill.d.ts.map +1 -1
  14. package/dist/src/filler/dom-filler.d.ts.map +1 -1
  15. package/dist/src/index.d.ts +6 -6
  16. package/dist/src/index.d.ts.map +1 -1
  17. package/dist/src/rules/local-rules.d.ts.map +1 -1
  18. package/dist/src/scanner/dom-scanner.d.ts +7 -1
  19. package/dist/src/scanner/dom-scanner.d.ts.map +1 -1
  20. package/dist/src/scanner/ui-frameworks.d.ts +38 -0
  21. package/dist/src/scanner/ui-frameworks.d.ts.map +1 -0
  22. package/dist/src/select/address-cascader.d.ts +13 -0
  23. package/dist/src/select/address-cascader.d.ts.map +1 -0
  24. package/dist/src/select/custom-select.d.ts +19 -0
  25. package/dist/src/select/custom-select.d.ts.map +1 -0
  26. package/dist/src/select/option-match.d.ts +14 -0
  27. package/dist/src/select/option-match.d.ts.map +1 -0
  28. package/dist/src/select/select-fill.d.ts +4 -0
  29. package/dist/src/select/select-fill.d.ts.map +1 -0
  30. package/dist/src/types/index.d.ts +33 -5
  31. package/dist/src/types/index.d.ts.map +1 -1
  32. package/dist/style.css +1 -1
  33. package/package.json +5 -2
package/dist/index.esm.js CHANGED
@@ -1,40 +1,1424 @@
1
- var fe = Object.defineProperty;
2
- var pe = (n, e, t) => e in n ? fe(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t;
3
- var c = (n, e, t) => pe(n, typeof e != "symbol" ? e + "" : e, t);
4
- const he = "https://loan.kdbank.cn";
5
- class J extends Error {
6
- constructor(t) {
7
- super(t.message);
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
- c(this, "smartFillError");
10
- this.name = "SmartFillException", this.smartFillError = t;
1393
+ d(this, "smartFillError");
1394
+ this.name = "SmartFillException", this.smartFillError = n;
11
1395
  }
12
1396
  }
13
- function b(n, e, t, s = {}) {
14
- return new J({ code: n, message: e, stage: t, ...s });
1397
+ function v(e, t, n, r = {}) {
1398
+ return new $t({ code: e, message: t, stage: n, ...r });
15
1399
  }
16
- function ge(n, e, t = "RECOGNIZE_FAILED") {
17
- return n instanceof J ? n.smartFillError : {
18
- code: t,
19
- message: n instanceof Error ? n.message : String(n || "智能录入异常"),
20
- stage: e,
21
- retryable: e === "recognize"
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 M(n = "sf") {
25
- return `${n}_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 10)}`;
1408
+ function Se(e = "sf") {
1409
+ return `${e}_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 10)}`;
26
1410
  }
27
- class me {
28
- constructor(e) {
1411
+ class mr {
1412
+ constructor(t) {
29
1413
  /** 会话 accessToken,写入请求头 seToken */
30
- c(this, "seToken", "");
1414
+ d(this, "seToken", "");
31
1415
  /** 网关根地址,见 config/defaults.ts */
32
- c(this, "baseURL", he);
33
- this.config = e;
1416
+ d(this, "baseURL", br);
1417
+ this.config = t;
34
1418
  }
35
1419
  /** 设置会话 token,后续 request 自动携带 seToken 请求头 */
36
- setAccessToken(e) {
37
- this.seToken = e;
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 b("API_KEY_INVALID", "apiKey 格式不正确,应以 seKey- 开头。", "setup");
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(e) {
53
- return e ? this.request(`/sdk/forms/${encodeURIComponent(e)}`, {
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(e) {
63
- var r, a, o, d;
64
- const t = (r = e.images) != null && r.length ? e.images : [], s = ((a = e.text) == null ? void 0 : a.trim()) || "";
65
- if (!t.length)
66
- return { text: s, usedOcr: !1 };
67
- (o = e.onStatusChange) == null || o.call(e, "image_uploading");
68
- const i = await this.recognizeImages(t);
69
- return (d = e.onStatusChange) == null || d.call(e, "image_recognizing"), { text: i, usedOcr: !0 };
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(e) {
79
- var a, o;
80
- const t = performance.now(), s = (a = e.text) == null ? void 0 : a.trim();
81
- (o = e.onStatusChange) == null || o.call(e, "recognizing");
82
- const i = await this.request(
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: e.formCode || "",
89
- configVersion: e.configVersion || "",
90
- formMsg: e.fields.map(({ element: d, ...l }) => l),
91
- userInputMsg: s || ""
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
- ), r = ye(i, e.fields, e.scanToken);
95
- return {
96
- scanToken: e.scanToken,
97
- suggestions: r,
98
- trace: i.trace || {
99
- traceId: M("trace"),
100
- usedOcr: !!e.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() - t)
1487
+ durationMs: Math.round(performance.now() - n)
103
1488
  }
104
1489
  };
105
1490
  }
106
1491
  /** 图片 OCR:以 multipart/form-data 上传 files,返回提取出的 text 文本 */
107
- async recognizeImages(e) {
108
- const t = new FormData();
109
- e.forEach((r) => {
110
- t.append("image", r, r.name);
1492
+ async recognizeImages(t) {
1493
+ const n = new FormData();
1494
+ t.forEach((i) => {
1495
+ n.append("image", i, i.name);
111
1496
  });
112
- const s = await this.request(
1497
+ const r = await this.request(
113
1498
  "/fcloud/flow-product/agentChat/smartEntry/ocr",
114
1499
  {
115
1500
  method: "POST",
116
- body: t
1501
+ body: n
117
1502
  }
118
- ), i = xe(s);
119
- if (!i)
120
- throw b("RECOGNIZE_FAILED", "图片识别未提取到文本内容。", "recognize");
121
- return i;
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(e, t) {
125
- const s = new AbortController(), i = window.setTimeout(() => s.abort(), this.config.requestTimeoutMs ?? 3e4), r = new Headers(t.headers);
126
- t.body && !(t.body instanceof FormData) && !r.has("Content-Type") && r.set("Content-Type", "application/json"), r.set("x-trace-id", M("trace")), this.seToken && r.set("seToken", `${this.seToken}`);
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 a = await fetch(`${this.baseURL}${e}`, {
129
- ...t,
130
- headers: r,
131
- signal: s.signal
1513
+ const s = await fetch(`${this.baseURL}${t}`, {
1514
+ ...n,
1515
+ headers: i,
1516
+ signal: r.signal
132
1517
  });
133
- if (!a.ok)
134
- throw b(ve(a.status), await a.text(), e.includes("session") ? "setup" : "recognize", {
135
- retryable: a.status >= 500 || a.status === 429
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 a.json();
138
- } catch (a) {
139
- throw a instanceof DOMException && a.name === "AbortError" ? b("RECOGNIZE_TIMEOUT", "识别请求超时,请稍后重试。", "recognize", { retryable: !0 }) : a;
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(i);
1526
+ window.clearTimeout(o);
142
1527
  }
143
1528
  }
144
1529
  }
145
- const be = 0.95;
146
- function ye(n, e, t) {
147
- var r;
148
- const s = new Map(e.map((a) => [a.fieldId, a]));
149
- return (((r = n.data) == null ? void 0 : r.fieldValues) || []).filter((a) => !!(a != null && a.fieldId)).map((a) => {
150
- const o = s.get(a.fieldId);
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: a.fieldId,
153
- scanToken: t,
154
- label: a.label || (o == null ? void 0 : o.label) || a.fieldId,
155
- value: a.value,
156
- displayValue: a.value == null ? "" : String(a.value),
157
- confidence: Ee(a.confidence),
158
- source: a.source || "ai",
159
- warnings: a.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 Ee(n) {
164
- return typeof n != "number" || Number.isNaN(n) ? be : n < 0 ? 0 : n > 1 ? 1 : n;
1548
+ function Sr(e) {
1549
+ return typeof e != "number" || Number.isNaN(e) ? vr : e < 0 ? 0 : e > 1 ? 1 : e;
165
1550
  }
166
- function xe(n) {
167
- var t;
168
- const e = typeof n.data == "string" ? n.data : ((t = n.data) == null ? void 0 : t.text) || n.text || "";
169
- return String(e || "").trim();
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 ve(n) {
172
- return n === 401 ? "TOKEN_EXPIRED" : n === 403 ? "API_KEY_FORBIDDEN" : n === 404 ? "FORM_CONFIG_NOT_FOUND" : "RECOGNIZE_FAILED";
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 Q {
1559
+ class Ht {
175
1560
  constructor() {
176
- c(this, "handlers", /* @__PURE__ */ new Map());
1561
+ d(this, "handlers", /* @__PURE__ */ new Map());
177
1562
  }
178
1563
  /** 订阅事件,返回 unsubscribe 函数 */
179
- on(e, t) {
180
- const s = this.handlers.get(e) ?? /* @__PURE__ */ new Set();
181
- return s.add(t), this.handlers.set(e, s), () => this.off(e, t);
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(e, t) {
184
- var s;
185
- (s = this.handlers.get(e)) == null || s.delete(t);
1568
+ off(t, n) {
1569
+ var r;
1570
+ (r = this.handlers.get(t)) == null || r.delete(n);
186
1571
  }
187
- emit(e, t) {
188
- var s;
189
- (s = this.handlers.get(e)) == null || s.forEach((i) => i(t));
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 we {
1580
+ class kr {
196
1581
  constructor() {
197
1582
  /** 当前页面所有存活实例 */
198
- c(this, "instances", /* @__PURE__ */ new Set());
1583
+ d(this, "instances", /* @__PURE__ */ new Set());
199
1584
  /** 当前激活(面板打开)的实例 */
200
- c(this, "active", null);
1585
+ d(this, "active", null);
201
1586
  }
202
1587
  /** 注册新实例 */
203
- add(e) {
204
- this.instances.add(e);
1588
+ add(t) {
1589
+ this.instances.add(t);
205
1590
  }
206
1591
  /** 激活实例,自动关闭上一个实例的面板 */
207
- activate(e) {
208
- this.active && this.active !== e && this.active.close(), this.active = e;
1592
+ activate(t) {
1593
+ this.active && this.active !== t && this.active.close(), this.active = t;
209
1594
  }
210
1595
  /** 实例销毁时从管理器移除 */
211
- remove(e) {
212
- this.instances.delete(e), this.active === e && (this.active = null);
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((e) => e.destroy()), this.instances.clear(), this.active = null;
1601
+ this.instances.forEach((t) => t.destroy()), this.instances.clear(), this.active = null;
217
1602
  }
218
1603
  }
219
- const Se = [
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 x(n) {
326
- const e = String(n || "").trim();
327
- return !e || $e.some((t) => t.test(e)) ? "" : e;
1609
+ function E(e) {
1610
+ const t = String(e || "").trim();
1611
+ return !t || _r.some((n) => n.test(t)) ? "" : t;
328
1612
  }
329
- function P(n) {
330
- const e = (n.options || []).slice(0, 20).map((t) => `${t.label}:${String(t.value)}`).join("|");
331
- return k(
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
- n.fieldId,
334
- n.tagName,
335
- n.type,
336
- x(n.name),
337
- x(n.id),
338
- n.label,
339
- n.placeholder,
340
- n.section,
341
- e
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 k(n) {
346
- return String(n ?? "").replace(/\s+/g, " ").trim().toLowerCase();
1629
+ function $(e) {
1630
+ return String(e ?? "").replace(/\s+/g, " ").trim().toLowerCase();
347
1631
  }
348
- const O = /* @__PURE__ */ new WeakMap();
349
- class q {
350
- constructor(e, t, s = []) {
351
- this.fields = e, this.schemas = t, this.adapters = s;
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(e) {
359
- const t = [], s = [];
360
- for (const i of e.values) {
361
- const r = this.fields.find((l) => l.fieldId === i.fieldId);
362
- if (!r) {
363
- s.push(T(i.fieldId, "", i.value, "字段不在当前扫描结果中", "FIELD_NOT_FOUND"));
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 (r.scanToken !== e.scanToken) {
367
- s.push(T(r.fieldId, r.label, i.value, "页面扫描已过期,请重新扫描", "SCAN_TOKEN_EXPIRED"));
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 a = this.schemas.find((l) => l.fieldId === i.fieldId), o = a != null && a.transform ? a.transform(i.value) : i.value, d = await this.getValue(r, a);
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 = a != null && a.validate ? await a.validate(o) : !0;
1676
+ const l = s != null && s.validate ? await s.validate(a) : !0;
373
1677
  if (l !== !0) {
374
- s.push(T(r.fieldId, r.label, o, typeof l == "string" ? l : "字段校验未通过", "VALIDATE_FAILED"));
1678
+ r.push(fe(i.fieldId, i.label, a, typeof l == "string" ? l : "字段校验未通过", "VALIDATE_FAILED"));
375
1679
  continue;
376
1680
  }
377
- await this.setValue(r, o, a), t.push({ fieldId: r.fieldId, label: r.label, value: o, previousValue: d });
1681
+ await this.setValue(i, a, s), n.push({ fieldId: i.fieldId, label: i.label, value: a, previousValue: c });
378
1682
  } catch (l) {
379
- s.push(T(r.fieldId, r.label, o, l instanceof Error ? l.message : "字段回填失败", "SET_VALUE_FAILED"));
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: t,
384
- skipped: s,
385
- warnings: s.length ? ["部分字段未回填,请查看跳过原因。"] : void 0
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(e, t) {
390
- if (t != null && t.getValue) return t.getValue();
391
- const s = this.matchAdapter(e);
392
- if (s != null && s.getValue) return s.getValue(e);
393
- const i = $(e);
394
- if (i)
395
- return i instanceof HTMLInputElement && i.type === "checkbox" ? i.checked : i instanceof HTMLInputElement && i.type === "radio" ? i.checked ? i.value : void 0 : i instanceof HTMLInputElement || i instanceof HTMLTextAreaElement || i instanceof HTMLSelectElement ? i.value : i.textContent;
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(e, t, s) {
402
- if (s != null && s.setValue) {
403
- await s.setValue(t);
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 i = $(e);
407
- if (!i) throw new Error("页面中未找到对应字段");
408
- if (e.fingerprint && e.fingerprint !== P({ ...e, tagName: i.tagName.toLowerCase() }))
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
- if (e.disabled || e.readonly || i.hasAttribute("disabled") || i.hasAttribute("readonly"))
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
- const r = this.matchAdapter(e);
413
- if (r) {
414
- await r.setValue(e, t);
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
- Ne(i, t), _e(i);
1725
+ Tr(o, n), Ce(o, t);
418
1726
  }
419
1727
  /** 匹配第一个适用的组件库适配器 */
420
- matchAdapter(e) {
421
- const t = $(e);
422
- return t ? this.adapters.find((s) => s.match(t, e)) : void 0;
423
- }
424
- }
425
- function $(n) {
426
- var e;
427
- return (e = n.element) != null && e.isConnected ? n.element : document.querySelector(`[data-smart-fill-id="${z(n.fieldId)}"]`);
428
- }
429
- function Ne(n, e) {
430
- if (n instanceof HTMLInputElement && n.type === "checkbox")
431
- n.checked = !!e;
432
- else if (n instanceof HTMLInputElement && n.type === "radio") {
433
- const t = document.querySelector(`input[type="radio"][name="${z(n.name)}"][value="${z(String(e))}"]`);
434
- (t || n).checked = !0;
435
- } else n instanceof HTMLInputElement || n instanceof HTMLTextAreaElement || n instanceof HTMLSelectElement ? n.value = String(e ?? "") : n.isContentEditable && (n.textContent = String(e ?? ""));
436
- n.dispatchEvent(new Event("input", { bubbles: !0 })), n.dispatchEvent(new Event("change", { bubbles: !0 }));
437
- }
438
- function _e(n) {
439
- var s;
440
- n.setAttribute("data-smart-fill-highlighted", "true"), (s = O.get(n)) == null || s.abort();
441
- const e = new AbortController(), t = (i) => {
442
- i && "isTrusted" in i && !i.isTrusted || (n.removeAttribute("data-smart-fill-highlighted"), e.abort(), O.delete(n));
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
- O.set(n, e), n.addEventListener("focus", t, { signal: e.signal }), n.addEventListener("pointerdown", t, { signal: e.signal }), n.addEventListener("keydown", t, { signal: e.signal }), n.addEventListener("input", t, { signal: e.signal }), n.addEventListener("change", t, { signal: e.signal });
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 T(n, e, t, s, i) {
447
- return { fieldId: n, label: e, attemptedValue: t, reason: s, reasonCode: i };
1783
+ function Mr(e) {
1784
+ return e.filter((t) => !e.some((n) => n !== t && n.contains(t)));
448
1785
  }
449
- function z(n) {
450
- return typeof CSS < "u" && CSS.escape ? CSS.escape(n) : n.replace(/["\\]/g, "\\$&");
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
- const Re = [
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
- ], U = {
460
- legalPerson: ["法人", "法定代表人", "法定代表", "企业法人", "legal person", "legal representative"],
461
- emergencyContact: ["紧急联系人", "紧急联络人", "emergency contact"],
462
- contact: ["联系人", "联络人", "联系人员", "contact"],
463
- spouse: ["配偶", "爱人", "夫妻", "spouse"]
464
- }, h = {
465
- mobile: ["手机", "手机号", "电话", "联系电话", "mobile", "phone"],
466
- legalPersonMobile: ["法人手机号", "法人电话", "法定代表人手机号", "法人手机", "legal person mobile"],
467
- emergencyContactMobile: ["紧急联系人手机号", "紧急联系人电话", "紧急联系电话", "emergency contact mobile"],
468
- contactMobile: ["联系人手机号", "联系人电话", "联系手机", "contact mobile"],
469
- spouseMobile: ["配偶手机号", "配偶电话", "爱人手机号", "spouse mobile"],
470
- idCard: ["身份证", "证件号", "身份证号", "idcard", "id card"],
471
- legalPersonIdCard: ["法人身份证", "法人身份证号", "法定代表人身份证号"],
472
- spouseIdCard: ["配偶身份证", "配偶身份证号", "爱人身份证号"],
473
- email: ["邮箱", "邮件", "email", "mail"],
474
- contactEmail: ["联系人邮箱", "联系邮箱", "contact email"],
475
- name: ["姓名", "名字", "称呼", "name"],
476
- customerName: ["客户姓名", "申请人姓名", "用户姓名", "借款人姓名", "客户名称"],
477
- legalPersonName: ["法人姓名", "法定代表人姓名", "企业法人姓名"],
478
- emergencyContactName: ["紧急联系人姓名", "紧急联系人名称"],
479
- contactName: ["联系人姓名", "联系人名称"],
480
- spouseName: ["配偶姓名", "爱人姓名"],
481
- companyName: ["公司名称", "企业名称", "单位名称", "商户名称", "公司", "企业"],
482
- address: ["地址", "住址", "通讯地址", "联系地址", "现住址", "办公地址"],
483
- detailAddress: ["详细地址", "街道地址", "门牌地址", "详细住址"],
484
- amount: ["金额", "费用", "价格", "合计", "总计", "amount", "price"],
485
- applyAmount: ["申请金额", "贷款金额", "借款金额", "授信金额", "申请额度"],
486
- date: ["日期", "时间", "有效期", "date"],
487
- applyDate: ["申请日期", "申请时间", "受理日期", "进件日期"],
488
- bankCard: ["银行卡", "卡号", "bank", "bank card"]
489
- }, te = {
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
- contactEmail: "email",
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
- applyAmount: "amount",
511
- date: "date",
512
- applyDate: "date",
513
- bankCard: "bankCard"
1871
+ date: "date"
514
1872
  };
515
- class De {
1873
+ class Or {
516
1874
  /**
517
1875
  * 从文本中提取事实并匹配到 scan 字段。
518
1876
  * 按 confidence 降序分配,每个 fieldId 仅匹配一次(usedFieldIds 去重)。
519
1877
  */
520
- recognize(e, t, s) {
521
- const i = Ze([...Pe(e), ...ze(e)]), r = /* @__PURE__ */ new Set(), a = [];
522
- for (const o of i.sort((d, l) => l.confidence - d.confidence)) {
523
- const d = Ke(o, t, r);
524
- d && (a.push({
525
- fieldId: d.fieldId,
526
- scanToken: s,
527
- label: d.label,
528
- value: qe(o.value, d),
529
- displayValue: o.value,
530
- confidence: o.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: o.reason
533
- }), r.add(d.fieldId));
1890
+ reason: a.reason
1891
+ }), i.add(c.fieldId));
534
1892
  }
535
- return a;
536
- }
537
- }
538
- function Pe(n) {
539
- const e = [];
540
- for (const t of Re)
541
- for (const s of n.matchAll(t.pattern)) {
542
- const i = ne(s[1] || s[0]);
543
- e.push({
544
- key: t.key,
545
- value: i,
546
- confidence: t.confidence,
547
- reason: t.reason,
548
- baseKey: te[t.key]
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 e;
552
- }
553
- function ze(n) {
554
- const e = [], t = n.split(/\r?\n|[;,;]/).map((s) => s.trim()).filter(Boolean);
555
- for (const s of t) {
556
- const i = s.match(/^[“"'`]?([^::=]{2,30})[”"'`]?[::=]\s*(.+)$/);
557
- if (!i) continue;
558
- const r = Ye(i[1]), a = ne(i[2]);
559
- if (!(!r || !a))
560
- for (const o of He(r, a))
561
- e.push(o);
562
- }
563
- return e;
564
- }
565
- function He(n, e) {
566
- const t = k(n), s = Be(e), i = [], r = Ue(t);
567
- return p(t, h.applyDate) && i.push("applyDate"), p(t, h.applyAmount) && i.push("applyAmount"), p(t, h.companyName) && i.push("companyName"), p(t, h.detailAddress) && i.push("detailAddress"), p(t, h.address) && i.push("address"), (p(t, h.mobile) || s === "mobile") && r && N(i, r, "mobile"), (p(t, h.idCard) || s === "idCard") && r && N(i, r, "idCard"), (p(t, h.email) || s === "email") && r && N(i, r, "email"), (p(t, h.mobile) || s === "mobile") && i.push("mobile"), (p(t, h.idCard) || s === "idCard") && i.push("idCard"), (p(t, h.email) || s === "email") && i.push("email"), (p(t, h.bankCard) || s === "bankCard") && i.push("bankCard"), (p(t, h.amount) || s === "amount") && i.push("amount"), (p(t, h.date) || s === "date") && i.push("date"), Ge(i).map((a, o) => ({
568
- key: a,
569
- value: e,
570
- confidence: Math.max(0.84, 0.96 - o * 0.04),
571
- reason: r ? `键值对文本命中(${n},角色增强)` : `键值对文本命中(${n})`,
572
- baseKey: te[a]
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 Ke(n, e, t) {
576
- let s = null;
577
- for (const i of e) {
578
- if (t.has(i.fieldId)) continue;
579
- const r = Ve(n, i);
580
- r > ((s == null ? void 0 : s.score) ?? 0) && (s = { field: i, score: r });
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 s && s.score >= 0.45 ? s.field : null;
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 qe(n, e) {
590
- var t;
591
- return e.type === "date" ? n.replace(/[年月/.]/g, "-").replace(/日/g, "").replace(/--/g, "-") : e.type === "number" || e.type === "amount" ? ((t = n.match(/[0-9]+(?:\.[0-9]+)?/)) == null ? void 0 : t[0]) ?? n : e.name && /mobile|phone|idcard|bankcard/i.test(e.name) || e.id && /mobile|phone|idcard|bankcard/i.test(e.id) || /mobile|phone|idcard|bankcard/i.test(e.fieldId) ? n.replace(/\s+/g, "") : n;
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 Ue(n) {
594
- const e = Object.keys(U).filter((t) => p(n, U[t]));
595
- return e.length ? e.includes("emergencyContact") ? "emergencyContact" : e.includes("legalPerson") ? "legalPerson" : e.includes("spouse") ? "spouse" : "contact" : null;
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 Be(n) {
598
- const e = n.replace(/\s+/g, "");
599
- return /^1[3-9]\d{9}$/.test(e) ? "mobile" : /^\d{17}[\dXx]$/.test(e) ? "idCard" : /^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$/.test(n) ? "email" : /^\d{16,19}$/.test(e) ? "bankCard" : /^\d{4}[-/.年]\d{1,2}[-/.月]\d{1,2}日?$/.test(n) ? "date" : /^[0-9]+(?:\.[0-9]{1,2})?$/.test(e) ? "amount" : /[省市区县路街道号栋室乡镇]/.test(n) ? "address" : /^[\u4e00-\u9fa5a-zA-Z·]{2,20}$/.test(n) ? "name" : "unknown";
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 N(n, e, t) {
602
- var i;
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 ne(n) {
631
- return n.replace(/[,。;;]+$/g, "").replace(/^[“”"'`\s]+|[“”"'`\s]+$/g, "").trim();
1958
+ function Kt(e) {
1959
+ return e.replace(/[,。;;]+$/g, "").replace(/^[“”"'`\s]+|[“”"'`\s]+$/g, "").trim();
632
1960
  }
633
- function p(n, e) {
634
- const t = k(n);
635
- return e.some((s) => t.includes(k(s)));
1961
+ function k(e, t) {
1962
+ const n = $(e);
1963
+ return t.some((r) => n.includes($(r)));
636
1964
  }
637
- function Ze(n) {
638
- const e = /* @__PURE__ */ new Map();
639
- for (const t of n) {
640
- const s = `${t.key}::${t.value}`, i = e.get(s);
641
- (!i || i.confidence < t.confidence) && e.set(s, t);
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 [...e.values()];
1971
+ return [...t.values()];
644
1972
  }
645
- function Ge(n) {
646
- return [...new Set(n)];
1973
+ function Br(e) {
1974
+ return [...new Set(e)];
647
1975
  }
648
- const Xe = [
1976
+ const st = [
649
1977
  "input",
650
1978
  "textarea",
651
1979
  "select",
652
1980
  "[contenteditable]:not([contenteditable='false'])"
653
- ].join(", "), se = [
654
- ".el-select",
655
- ".el-date-editor",
656
- ".el-time-picker",
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
- * - 否则:自动扫描可见 input/textarea/select,优先弹窗内控件
1989
+ * - 否则:自动扫描可见原生控件与 UI 框架组件,优先弹窗内控件
685
1990
  */
686
- scan(e = {}) {
687
- var d;
688
- const t = M("scan");
689
- if ((d = e.registered) != null && d.length)
1991
+ scan(t = {}) {
1992
+ var l;
1993
+ const n = Se("scan");
1994
+ if ((l = t.registered) != null && l.length)
690
1995
  return {
691
- scanToken: t,
692
- fields: e.registered.map((l) => this.fromSchema(l, t))
1996
+ scanToken: n,
1997
+ fields: t.registered.map((u) => this.fromSchema(u, n))
693
1998
  };
694
- const s = this.resolveRoot(e.scanContainer), i = this.collectVisibleFields(s), r = this.detectTopLayerContainer(i), a = i.filter((l) => r.contains(l)), o = (a.length ? a : i).slice(0, e.maxFields ?? 200);
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: t,
697
- fields: o.map((l, u) => this.fromElement(l, u, t))
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(e, t) {
702
- const s = at(e.element, this.root), i = {
703
- fieldId: e.rowKey == null ? e.fieldId : `${e.fieldId}:${e.rowKey}`,
704
- label: e.label,
705
- type: e.type,
706
- localRuleMode: e.localRuleMode ?? "inherit",
707
- required: e.required,
708
- section: e.section,
709
- options: e.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: t,
712
- element: s || void 0,
2043
+ scanToken: n,
2044
+ element: o || void 0,
713
2045
  fingerprint: ""
714
2046
  };
715
- return i.fingerprint = P({
2047
+ return i.fingerprint = G({
716
2048
  ...i,
717
- tagName: s == null ? void 0 : s.tagName.toLowerCase()
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(e, t, s) {
722
- const i = Qe(e, t), r = nt(e), a = {
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: s,
726
- type: et(e),
2057
+ scanToken: r,
2058
+ type: Yr(t),
727
2059
  localRuleMode: "inherit",
728
- label: K(e),
729
- placeholder: ie(e),
730
- name: x(oe(e)) || void 0,
731
- id: x(e.id) || void 0,
732
- section: tt(e),
733
- options: r,
734
- required: it(e),
735
- readonly: st(e),
736
- disabled: _(e),
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: e
2070
+ element: t
739
2071
  };
740
- return a.fingerprint = P({
2072
+ return se(a) && (a.options = void 0), a.fingerprint = G({
741
2073
  ...a,
742
- tagName: e.tagName.toLowerCase()
2074
+ tagName: t.tagName.toLowerCase()
743
2075
  }), a;
744
2076
  }
745
2077
  /** 解析扫描根节点,scanContainer 为 CSS 选择器 */
746
- resolveRoot(e) {
747
- if (e) {
748
- const t = le(this.root, e);
749
- if (t)
750
- return t;
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(e) {
756
- const t = Array.from(e.querySelectorAll(se)).filter((i) => !(i instanceof HTMLElement) || !j(i) || _(i) ? !1 : re(i));
757
- return [...Array.from(e.querySelectorAll(Xe)).filter((i) => !(i instanceof HTMLElement) || !j(i) || rt(i) || i instanceof HTMLInputElement && We.has((i.type || "").toLowerCase()) ? !1 : !_(i) && !i.hasAttribute("readonly")), ...t];
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(e) {
764
- const t = document.activeElement instanceof HTMLElement ? document.activeElement : null, s = t == null ? void 0 : t.closest(B);
765
- if (s instanceof HTMLElement && e.some((r) => s.contains(r)))
766
- return s;
767
- const i = e.map((r) => r.closest(B)).filter((r) => r instanceof HTMLElement);
768
- return i.length ? i.sort((r, a) => e.filter((o) => a.contains(o)).length - e.filter((o) => r.contains(o)).length)[0] : document.body;
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 Qe(n, e) {
772
- const t = n.getAttribute("data-smart-fill-id");
773
- if (t)
774
- return t;
775
- const i = x(n.getAttribute("data-smart-fill-key")) || x(oe(n)) || x(n.id) || x(K(n)) || `smart-fill-${Date.now()}-${e}`;
776
- return n.setAttribute("data-smart-fill-id", i), i;
777
- }
778
- function et(n) {
779
- const e = ae(n);
780
- if (e) return e;
781
- if (n instanceof HTMLTextAreaElement) return "textarea";
782
- if (n instanceof HTMLSelectElement) return "select";
783
- if (n instanceof HTMLInputElement) {
784
- const t = (n.type || "text").toLowerCase();
785
- if (t === "radio") return "radio";
786
- if (t === "checkbox") return "checkbox";
787
- if (t === "date" || t === "month") return "date";
788
- if (t === "number") return "number";
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 K(n) {
793
- const e = n.getAttribute("aria-label");
794
- if (e) return e.trim();
795
- if (n.id) {
796
- const r = document.querySelector(`label[for="${ce(n.id)}"]`);
797
- if (r != null && r.textContent) return y(r.textContent);
798
- }
799
- const t = n.closest("label");
800
- if (t != null && t.textContent) return y(t.textContent);
801
- const s = n.closest(".form-item, .ant-form-item, .el-form-item, .field, .form-row"), i = s == null ? void 0 : s.querySelector("label, .ant-form-item-label, .el-form-item__label, .label");
802
- return i != null && i.textContent ? y(i.textContent) : ie(n) || n.getAttribute("name") || n.id || "未命名字段";
803
- }
804
- function ie(n) {
805
- var e;
806
- return n.getAttribute("placeholder") || n.getAttribute("aria-placeholder") || ((e = n.querySelector("[placeholder]")) == null ? void 0 : e.getAttribute("placeholder")) || void 0;
807
- }
808
- function tt(n) {
809
- const e = n.closest("fieldset, section, .panel, .card, .form-section"), t = e == null ? void 0 : e.querySelector("legend, h1, h2, h3, .title, .section-title");
810
- return t != null && t.textContent ? y(t.textContent) : void 0;
811
- }
812
- function nt(n) {
813
- if (n.matches(".el-radio-group"))
814
- return Array.from(n.querySelectorAll('.el-radio, [role="radio"], input[type="radio"]')).map((e) => {
815
- var t;
816
- return {
817
- label: y(e.textContent || e.getAttribute("aria-label") || e.getAttribute("value") || ""),
818
- value: e.getAttribute("value") || ((t = e.querySelector('input[type="radio"]')) == null ? void 0 : t.value) || y(e.textContent || "")
819
- };
820
- }).filter((e) => e.label || e.value);
821
- if (n.matches(".el-checkbox-group"))
822
- return Array.from(n.querySelectorAll('.el-checkbox, [role="checkbox"], input[type="checkbox"]')).map((e) => {
823
- var t;
824
- return {
825
- label: y(e.textContent || e.getAttribute("aria-label") || e.getAttribute("value") || ""),
826
- value: e.getAttribute("value") || ((t = e.querySelector('input[type="checkbox"]')) == null ? void 0 : t.value) || y(e.textContent || "")
827
- };
828
- }).filter((e) => e.label || e.value);
829
- if (n instanceof HTMLSelectElement)
830
- return Array.from(n.options).map((e) => ({
831
- label: y(e.textContent || e.label),
832
- value: e.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 (n instanceof HTMLInputElement && (n.type === "radio" || n.type === "checkbox") && n.name)
835
- return Array.from(document.querySelectorAll(`input[name="${ce(n.name)}"]`)).map((e) => ({
836
- label: K(e),
837
- value: e.value || !0
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 j(n) {
841
- const e = window.getComputedStyle(n);
842
- return e.display === "none" || e.visibility === "hidden" || Number(e.opacity) === 0 ? !1 : !!(n.offsetWidth || n.offsetHeight || n.getClientRects().length);
843
- }
844
- function _(n) {
845
- return n.hasAttribute("disabled") || n.getAttribute("aria-disabled") === "true" || n.classList.contains("is-disabled") || !!n.querySelector('[disabled], [aria-disabled="true"], .is-disabled');
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 st(n) {
848
- return n.hasAttribute("readonly") || !!n.querySelector("[readonly]");
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 it(n) {
851
- return n.hasAttribute("required") || n.getAttribute("aria-required") === "true" || !!n.querySelector('[required], [aria-required="true"]');
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 rt(n) {
854
- const e = n.closest(se);
855
- return e instanceof HTMLElement ? re(e) : !1;
2199
+ function Jr(e) {
2200
+ return e.hasAttribute("readonly") || !!e.querySelector("[readonly]");
856
2201
  }
857
- function re(n) {
858
- return !!ae(n);
2202
+ function Qr(e) {
2203
+ return e.hasAttribute("required") || e.getAttribute("aria-required") === "true" || !!e.querySelector('[required], [aria-required="true"]');
859
2204
  }
860
- function ae(n) {
861
- return n.matches(".el-select, .el-cascader") ? "select" : n.matches(".el-date-editor, .el-time-picker") ? "date" : n.matches(".el-switch") || n.matches(".el-checkbox-group") ? "checkbox" : n.matches(".el-radio-group") ? "radio" : n.matches(".el-input-number") ? "number" : null;
2205
+ function eo(e) {
2206
+ return Pe(e) != null || Re(e) != null;
862
2207
  }
863
- function oe(n) {
864
- var e;
865
- return n.getAttribute("name") || ((e = n.querySelector("[name]")) == null ? void 0 : e.getAttribute("name")) || n.getAttribute("data-smart-fill-key");
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 at(n, e) {
868
- return n instanceof HTMLElement ? n : typeof n == "string" ? le(e, n) : null;
2214
+ function no(e, t) {
2215
+ return e instanceof HTMLElement ? e : typeof e == "string" ? jt(t, e) : null;
869
2216
  }
870
- function le(n, e) {
2217
+ function jt(e, t) {
871
2218
  try {
872
- const t = n.querySelector(e);
873
- return t instanceof HTMLElement ? t : null;
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 y(n) {
879
- return n.replace(/[*::]/g, "").replace(/\s+/g, " ").trim();
2225
+ function Ye(e) {
2226
+ return typeof CSS < "u" && CSS.escape ? CSS.escape(e) : e.replace(/["\\]/g, "\\$&");
880
2227
  }
881
- function ce(n) {
882
- return typeof CSS < "u" && CSS.escape ? CSS.escape(n) : n.replace(/["\\]/g, "\\$&");
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
- c(this, "host", null);
2232
+ d(this, "host", null);
889
2233
  /** Shadow DOM 根或 fallback 到 host */
890
- c(this, "root", null);
2234
+ d(this, "root", null);
891
2235
  /** 识别结果候选项,供 review 区域展示 */
892
- c(this, "autoApplyState", null);
2236
+ d(this, "autoApplyState", null);
893
2237
  /** 用户选择的图片文件列表 */
894
- c(this, "selectedFiles", []);
2238
+ d(this, "selectedFiles", []);
895
2239
  /** 文本输入框内容缓存,render 重绘时保留 */
896
- c(this, "inputText", "");
2240
+ d(this, "inputText", "");
897
2241
  /** 本地优先识别开关状态 */
898
- c(this, "localPriorityEnabled");
2242
+ d(this, "localPriorityEnabled");
899
2243
  /** 面板展开状态:inline 默认展开,floating 默认收起 */
900
- c(this, "isOpen", !1);
2244
+ d(this, "isOpen", !1);
901
2245
  /** floating 模式拖拽状态 */
902
- c(this, "dragState", null);
2246
+ d(this, "dragState", null);
903
2247
  /** 拖拽结束后抑制 click 触发 open,避免误开面板 */
904
- c(this, "suppressOpenClick", !1);
2248
+ d(this, "suppressOpenClick", !1);
905
2249
  /** 鼠标是否正悬浮在图片区,供 Ctrl+V 粘贴图片触发判断 */
906
- c(this, "isUploadHovering", !1);
907
- c(this, "handleDragMove", (e) => {
908
- if (!this.dragState || !this.host || e.pointerId !== this.dragState.pointerId) return;
909
- const t = e.clientX - this.dragState.startX, s = e.clientY - this.dragState.startY;
910
- (Math.abs(t) > 3 || Math.abs(s) > 3) && (this.dragState.moved = !0);
911
- const i = this.host.getBoundingClientRect(), r = Math.max(8, window.innerWidth - i.width - 8), a = Math.max(8, window.innerHeight - i.height - 8), o = L(this.dragState.startLeft + t, 8, r), d = L(this.dragState.startTop + s, 8, a);
912
- this.host.style.left = `${o}px`, this.host.style.top = `${d}px`;
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
- c(this, "handleDragEnd", (e) => {
915
- !this.dragState || e.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(() => {
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
- c(this, "handleDocumentPaste", (e) => {
921
- const t = ut(e);
922
- if (!t.length || !this.isOpen || !this.host)
2264
+ d(this, "handleDocumentPaste", (t) => {
2265
+ const n = ao(t);
2266
+ if (!n.length || !this.isOpen || !this.host)
923
2267
  return;
924
- const s = document.activeElement, i = this.root instanceof ShadowRoot ? this.root.activeElement : null;
925
- !(s === this.host || this.host.contains(s) || i) && !this.isUploadHovering || (e.preventDefault(), this.handleImages(t));
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 = e, this.localPriorityEnabled = e.localPriorityEnabled ?? !1;
2271
+ this.options = t, this.localPriorityEnabled = t.localPriorityEnabled ?? !1;
928
2272
  }
929
2273
  /** 挂载面板到指定容器,创建 Shadow DOM 并首次渲染 */
930
- mount(e) {
931
- this.host = document.createElement("div"), this.host.className = `sf-sdk-host sf-sdk-host-${this.options.mode}`, e.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);
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(e) {
935
- this.isOpen = e, this.render(this.isOpen), this.keepHostInViewport();
2278
+ setOpen(t) {
2279
+ this.isOpen = t, this.render(this.isOpen), this.keepHostInViewport();
936
2280
  }
937
2281
  /** 同步本地优先开关状态(来自其他面板/外部持久化),不触发 onLocalPriorityChange */
938
- setLocalPriorityEnabled(e) {
939
- this.localPriorityEnabled = e;
940
- const t = this.query('[data-role="local-priority-toggle"]');
941
- t && (t.checked = e);
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(e, t = "") {
945
- const s = this.query('[data-role="recognize"]');
946
- s && (s.disabled = e, s.textContent = e ? t : this.t("recognize", "智能识别"));
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(e) {
950
- const t = this.query('[data-role="status"]');
951
- t && (t.textContent = e, t.removeAttribute("data-status"));
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(e) {
955
- const t = this.query('[data-role="status"]');
956
- t && (t.textContent = e, t.setAttribute("data-status", "error"));
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(e) {
960
- this.autoApplyState = e, this.render(!0), this.keepHostInViewport(), this.setStatus(this.t("recognized", "识别完成,正在自动回填..."));
2303
+ setAutoApplyState(t) {
2304
+ this.autoApplyState = t, this.render(!0), this.keepHostInViewport(), this.setStatus(this.t("recognized", "识别完成,正在自动回填..."));
961
2305
  }
962
2306
  /** 展示回填结果统计(成功/跳过数量) */
963
- setApplyResult(e) {
964
- const t = this.query('[data-role="status"]');
965
- t && (t.textContent = `已回填 ${e.applied.length} 项,跳过 ${e.skipped.length} 项。`, t.setAttribute("data-status", e.skipped.length ? "warning" : "success"));
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 e;
970
- document.removeEventListener("pointermove", this.handleDragMove), document.removeEventListener("pointerup", this.handleDragEnd), document.removeEventListener("pointercancel", this.handleDragEnd), document.removeEventListener("paste", this.handleDocumentPaste), (e = this.host) == null || e.remove(), this.host = null, this.root = null, this.dragState = null, this.isUploadHovering = !1;
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(e) {
2316
+ render(t) {
973
2317
  this.root && (this.root.innerHTML = `
974
- <style>${ft}</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 ${e ? "is-open" : ""} ${this.options.mode === "inline" ? "is-inline" : "is-floating"}" aria-label="智能录入面板">
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" data-role="close" aria-label="${this.options.mode === "inline" ? e ? this.t("collapse", "收起") : this.t("expand", "展开") : this.t("close", "关闭")}">${this.options.mode === "inline" ? e ? "∧" : "∨" : "x"}</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 ${e ? "is-open" : ""}">
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", "启用本地优先识别")}</span>
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")}">${dt(this.inputText)}</textarea>
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 粘贴图片至此(最多 ${R} 张)`)}</span>
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 s, i, r, a, o, d, l;
1022
- const e = this.query('[data-role="open"]');
1023
- e == null || e.addEventListener("pointerdown", (u) => this.startDrag(u)), e == null || e.addEventListener("click", () => {
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
- }), (s = this.query(".sf-header")) == null || s.addEventListener("pointerdown", (u) => this.startDrag(u)), (i = this.query('[data-role="close"]')) == null || i.addEventListener("click", () => {
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
- }), (r = this.query('[data-role="file"]')) == null || r.addEventListener("change", (u) => {
1032
- const g = u.target;
1033
- this.handleImages(Array.from(g.files || []));
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 t = this.query('[data-role="upload"]');
1036
- t == null || t.addEventListener("pointerenter", () => {
2379
+ const n = this.query('[data-role="upload"]');
2380
+ n == null || n.addEventListener("pointerenter", () => {
1037
2381
  this.isUploadHovering = !0;
1038
- }), t == null || t.addEventListener("pointerleave", () => {
1039
- this.isUploadHovering = !1, t.removeAttribute("data-dragover");
1040
- }), t == null || t.addEventListener("dragenter", (u) => {
1041
- u.preventDefault(), this.isUploadHovering = !0, t.setAttribute("data-dragover", "true");
1042
- }), t == null || t.addEventListener("dragover", (u) => {
1043
- u.preventDefault(), t.setAttribute("data-dragover", "true");
1044
- }), t == null || t.addEventListener("dragleave", (u) => {
1045
- u.currentTarget.contains(u.relatedTarget) || (this.isUploadHovering = !1, t.removeAttribute("data-dragover"));
1046
- }), t == null || t.addEventListener("drop", (u) => {
1047
- var g;
1048
- u.preventDefault(), this.isUploadHovering = !1, t.removeAttribute("data-dragover"), this.handleImages(Array.from(((g = u.dataTransfer) == null ? void 0 : g.files) || []));
1049
- }), (a = this.query('[data-role="text"]')) == null || a.addEventListener("input", (u) => {
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
- }), (o = this.query('[data-role="local-priority-toggle"]')) == null || o.addEventListener("change", (u) => {
1052
- var g, v;
1053
- this.localPriorityEnabled = u.target.checked, (v = (g = this.options).onLocalPriorityChange) == null || v.call(g, this.localPriorityEnabled);
1054
- }), (d = this.query('[data-role="clear"]')) == null || d.addEventListener("click", () => {
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"]'), g = u == null ? void 0 : u.value.trim();
1058
- if (this.inputText = (u == null ? void 0 : u.value) || this.inputText, !g) {
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: g });
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 t;
2414
+ var n;
1071
2415
  this.selectedFiles = [];
1072
- const e = this.query('[data-role="file"]');
1073
- e && (e.value = ""), this.isUploadHovering = !1, (t = this.query('[data-role="upload"]')) == null || t.removeAttribute("data-dragover");
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(e) {
1077
- const t = e.filter((r) => r.type.startsWith("image/"));
1078
- if (!t.length) {
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 (t.length > R) {
1083
- this.resetSelectedFiles(), this.setError(this.t("maxFilesError", `最多上传 ${R} 张图片。`));
2426
+ if (n.length > Le) {
2427
+ this.resetSelectedFiles(), this.setError(this.t("maxFilesError", `最多上传 ${Le} 张图片。`));
1084
2428
  return;
1085
2429
  }
1086
- if (t.find((r) => r.size > ot)) {
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 (t.reduce((r, a) => r + a.size, 0) > lt) {
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 = t, this.setStatus(this.t("imageReady", `已选择 ${this.selectedFiles.length} 张图片,开始识别...`));
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(e) {
1101
- var s;
1102
- if (this.options.mode !== "floating" || !this.host || e.button !== 0 || (s = e.target) != null && s.closest('[data-role="close"]')) return;
1103
- const t = this.host.getBoundingClientRect();
1104
- this.host.style.left = `${t.left}px`, this.host.style.top = `${t.top}px`, this.host.style.right = "auto", this.host.style.bottom = "auto", this.dragState = {
1105
- pointerId: e.pointerId,
1106
- startX: e.clientX,
1107
- startY: e.clientY,
1108
- startLeft: t.left,
1109
- startTop: t.top,
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
- }, e.preventDefault(), document.addEventListener("pointermove", this.handleDragMove), document.addEventListener("pointerup", this.handleDragEnd), document.addEventListener("pointercancel", this.handleDragEnd);
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 e = this.host.getBoundingClientRect(), t = L(e.left, 8, Math.max(8, window.innerWidth - e.width - 8)), s = L(e.top, 8, Math.max(8, window.innerHeight - e.height - 8));
1117
- this.host.style.left = `${t}px`, this.host.style.top = `${s}px`;
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(e) {
1121
- var t;
1122
- return ((t = this.root) == null ? void 0 : t.querySelector(e)) || null;
2464
+ query(t) {
2465
+ var n;
2466
+ return ((n = this.root) == null ? void 0 : n.querySelector(t)) || null;
1123
2467
  }
1124
- t(e, t) {
1125
- var s;
1126
- return ((s = this.options.messages) == null ? void 0 : s[e]) || t;
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 dt(n) {
1130
- return n.replace(/[&<>"']/g, (e) => ({
2473
+ function so(e) {
2474
+ return e.replace(/[&<>"']/g, (t) => ({
1131
2475
  "&": "&amp;",
1132
2476
  "<": "&lt;",
1133
2477
  ">": "&gt;",
1134
2478
  '"': "&quot;",
1135
2479
  "'": "&#39;"
1136
- })[e] || e);
2480
+ })[t] || t);
1137
2481
  }
1138
- function L(n, e, t) {
1139
- return Math.min(Math.max(n, e), t);
2482
+ function pe(e, t, n) {
2483
+ return Math.min(Math.max(e, t), n);
1140
2484
  }
1141
- function ut(n) {
1142
- var t;
1143
- return Array.from(((t = n.clipboardData) == null ? void 0 : t.items) || []).filter((s) => s.kind === "file" && s.type.startsWith("image/")).map((s) => s.getAsFile()).filter((s) => !!s);
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 ft = `
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: 24px; right: 24px; z-index: 2147483647; display: flex; flex-direction: column; align-items: flex-end; gap: 12px; width: min(420px, calc(100vw - 32px)); pointer-events: none; }
1148
- .sf-float { align-self: flex-end; border: 0; border-radius: 999px; padding: 12px 18px; color: #fff; background: #2563eb; box-shadow: 0 10px 24px rgba(37,99,235,.3); cursor: move; user-select: none; touch-action: none; pointer-events: auto; }
1149
- .sf-panel { display: none; width: 100%; box-sizing: border-box; border: 1px solid #dbe3ef; border-radius: 16px; background: #fff; color: #172033; box-shadow: 0 18px 48px rgba(15,23,42,.18); padding: 16px; pointer-events: auto; }
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: #64748b; font-weight: 700; }
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: #64748b; font-size: 12px; line-height: 1.4; }
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(135deg, #6aa6ff 0%, #4e86ff 45%, #3b72f6 100%); color: #fff; box-shadow: 0 12px 26px rgba(59, 114, 246, .32); }
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: 140px; }
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
- `, pt = 0.75;
1192
- class ht {
1193
- constructor(e, t) {
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
- c(this, "events", new Q());
2547
+ d(this, "events", new Ht());
1196
2548
  /** 页面字段扫描器,root 来自 SmartFill.create({ root }) */
1197
- c(this, "scanner");
2549
+ d(this, "scanner");
1198
2550
  /** 浏览器端本地规则引擎,用于文本正则/键值对提取 */
1199
- c(this, "ruleEngine", new De());
2551
+ d(this, "ruleEngine", new Or());
1200
2552
  /** Shadow DOM 面板,mount / mountFloatingButton 后可用(指向最后挂载的面板,用于状态展示) */
1201
- c(this, "panel", null);
2553
+ d(this, "panel", null);
1202
2554
  /** 已挂载的全部面板(inline / floating 可同时存在),用于本地优先开关广播与销毁 */
1203
- c(this, "panels", []);
2555
+ d(this, "panels", []);
1204
2556
  /** 面板展开状态持久化 key */
1205
- c(this, "panelStorageKeys", /* @__PURE__ */ new Map());
2557
+ d(this, "panelStorageKeys", /* @__PURE__ */ new Map());
1206
2558
  /** 业务方 registerFields 注册的字段;非空时 rescan 仅扫描这些字段 */
1207
- c(this, "registeredFields", []);
2559
+ d(this, "registeredFields", []);
1208
2560
  /** 组件库回填适配器链,如 AntD / Element 自定义控件 */
1209
- c(this, "adapters", [ke]);
2561
+ d(this, "adapters", [Nt]);
1210
2562
  /** 最近一次 rescan 结果;scanToken 用于识别/回填防过期校验 */
1211
- c(this, "scanResult", null);
2563
+ d(this, "scanResult", null);
1212
2564
  /** recognize 完成后生成的自动回填候选,供面板展示与 applyAutoItems 使用 */
1213
- c(this, "autoApplyState", null);
2565
+ d(this, "autoApplyState", null);
1214
2566
  /** 预留:表单配置版本号,识别请求可携带给后端 */
1215
- c(this, "formConfigVersion");
2567
+ d(this, "formConfigVersion");
1216
2568
  /** 面板「启用本地优先识别」开关状态,默认关闭(走后端识别) */
1217
- c(this, "localPriorityEnabled", !1);
2569
+ d(this, "localPriorityEnabled", !1);
1218
2570
  /** 实例是否已 destroy,销毁后所有公开方法抛 INSTANCE_DESTROYED */
1219
- c(this, "destroyed", !1);
1220
- this.config = e, this.context = t, this.scanner = new Je(e.root || document), this.localPriorityEnabled = vt(), this.context.manager.add(this);
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(e, t) {
1224
- return this.events.on(e, t);
2583
+ on(t, n) {
2584
+ return this.events.on(t, n);
1225
2585
  }
1226
2586
  /** 注册组件库回填适配器,支持链式调用 */
1227
- useAdapter(e) {
1228
- return this.assertAlive(), this.adapters.push(e), this;
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(e) {
2595
+ registerFields(t) {
1236
2596
  this.assertAlive();
1237
- const t = /* @__PURE__ */ new Set();
1238
- for (const s of e) {
1239
- const i = s.rowKey == null ? s.fieldId : `${s.fieldId}:${s.rowKey}`;
1240
- if (t.has(i))
1241
- throw b("UNSUPPORTED_PAGE", `字段 ${i} 重复注册。`, "scan");
1242
- t.add(i);
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 = e, this;
2604
+ return this.registeredFields = t, this.scanResult = null, this.schedulePreScan(), this;
1245
2605
  }
1246
2606
  /** 取消注册字段;不传 fieldIds 时清空全部注册 */
1247
- unregisterFields(e) {
1248
- this.assertAlive(), this.registeredFields = e != null && e.length ? this.registeredFields.filter((t) => !e.includes(t.fieldId)) : [];
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(e) {
2611
+ mount(t) {
1252
2612
  this.assertAlive();
1253
- const t = typeof e == "string" ? document.querySelector(e) : e;
1254
- if (!t)
1255
- throw b("UNSUPPORTED_PAGE", "未找到智能录入挂载点。", "ui");
1256
- const s = Z("inline", xt(e, t)), i = G(s, !0);
1257
- return this.createPanel("inline", s, i).mount(t), this;
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 e = Z("floating"), t = G(e, !1);
1263
- return this.createPanel("floating", e, t).mount(document.body), this;
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(e, t, s) {
1270
- let i;
1271
- return i = new ct({
1272
- mode: e,
1273
- initialOpen: s,
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(i),
1277
- onClose: () => this.close(i),
1278
- onRecognize: (r) => (this.panel = i, this.recognize(r)),
1279
- onLocalPriorityChange: (r) => this.handleLocalPriorityChange(r, i)
1280
- }), this.panels.push(i), this.panelStorageKeys.set(i, t), this.panel = i, i;
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(e, t) {
1284
- this.localPriorityEnabled = e, wt(e);
1285
- for (const s of this.panels)
1286
- s !== t && s.setLocalPriorityEnabled(e);
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(e = this.panel) {
1290
- this.assertAlive(), e && (this.context.manager.activate(this), this.panel = e, e.setOpen(!0), X(this.panelStorageKeys.get(e), !0), await this.rescan());
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(e = this.panel) {
1294
- e && (this.panel = e, e.setOpen(!1), X(this.panelStorageKeys.get(e), !1));
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
- var e;
1303
- this.assertAlive();
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
- if (this.scanResult = this.scanner.scan({
1308
- registered: t,
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
- }), !this.scanResult.fields.length)
1311
- throw b("NO_FIELDS_FOUND", "当前页面未找到可回填字段。", "scan");
1312
- return this.events.emit("scanCompleted", {
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
- }), (e = this.panel) == null || e.setStatus(`已扫描 ${this.scanResult.fields.length} 个字段。`), this.scanResult;
1316
- } catch (t) {
1317
- throw this.emitError(t, "scan"), t;
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(e) {
1331
- var r, a, o;
1332
- this.assertAlive();
1333
- const t = this.scanResult || await this.rescan(), s = M("trace"), i = performance.now();
1334
- this.events.emit("recognizing", { scanToken: t.scanToken, traceId: s }), (r = this.panel) == null || r.setBusy(!0, "识别中...");
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 d = t.fields.filter((m) => yt(m.localRuleMode, this.localPriorityEnabled)), l = t.fields.filter((m) => m.localRuleMode !== "only"), { text: u, usedOcr: g } = await this.context.client.resolveInputText({
1337
- text: e.text,
1338
- images: e.images,
1339
- onStatusChange: (m) => {
1340
- var I, w, C;
1341
- if (m === "image_uploading") {
1342
- (I = this.panel) == null || I.setStatus("图片上传中...");
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 (m === "image_recognizing") {
1346
- (w = this.panel) == null || w.setStatus("图片识别中...");
2724
+ if (b === "image_recognizing") {
2725
+ (I = this.panel) == null || I.setStatus("图片识别中...");
1347
2726
  return;
1348
2727
  }
1349
- (C = this.panel) == null || C.setStatus("识别中...");
2728
+ (ie = this.panel) == null || ie.setStatus("识别中...");
1350
2729
  }
1351
- }), v = u ? this.ruleEngine.recognize(u, d, t.scanToken) : [];
1352
- let E;
1353
- if (!l.length)
1354
- E = Y(t.scanToken, s, v, i, void 0, g);
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 m = await this.context.client.recognize({
1358
- scanToken: t.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: u,
1362
- usedOcr: g,
1363
- fields: l,
2740
+ text: x,
2741
+ usedOcr: ne,
2742
+ fields: g,
1364
2743
  onStatusChange: () => {
1365
- var w;
1366
- (w = this.panel) == null || w.setStatus("识别中...");
2744
+ var I;
2745
+ (I = this.panel) == null || I.setStatus("识别中...");
1367
2746
  }
1368
2747
  });
1369
- m.trace.durationMs = m.trace.durationMs || Math.round(performance.now() - i);
1370
- const I = bt(
1371
- v,
1372
- m.suggestions.filter((w) => l.some((C) => C.fieldId === w.fieldId))
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
- E = { ...m, suggestions: I };
1375
- } catch (m) {
1376
- if (!v.length)
1377
- throw m;
1378
- E = Y(
1379
- t.scanToken,
1380
- s,
1381
- v,
1382
- i,
1383
- [g ? "后端识别失败,已使用 OCR 文本触发本地识别继续回填。" : "后端识别失败,已启用本地识别继续回填。"],
1384
- g
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
- return this.autoApplyState = gt(
1388
- E.scanToken,
1389
- E.trace.traceId,
1390
- E.suggestions,
1391
- t,
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", E), (a = this.panel) == null || a.setAutoApplyState(this.autoApplyState), await this.applyAutoItems(this.autoApplyState), E;
1394
- } catch (d) {
1395
- throw this.emitError(d, "recognize"), d;
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
- (o = this.panel) == null || o.setBusy(!1);
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(e) {
1406
- var i;
1407
- if (this.assertAlive(), !this.scanResult)
1408
- throw b("SCAN_TOKEN_EXPIRED", "请先扫描字段后再回填。", "apply");
1409
- this.events.emit("applying", { scanToken: e.scanToken, count: e.values.length });
1410
- const s = await new q(this.scanResult.fields, this.registeredFields, this.adapters).apply(e);
1411
- return this.events.emit("applied", s), (i = this.panel) == null || i.setApplyResult(s), s;
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(e) {
1418
- var o, d;
2801
+ async applyAutoItems(t) {
2802
+ var a, c;
1419
2803
  if (!this.scanResult)
1420
- throw b("SCAN_TOKEN_EXPIRED", "请先扫描字段后再回填。", "apply");
1421
- const t = mt(e), s = e.items.filter((l) => de(l)).map((l) => ({ fieldId: l.fieldId, value: l.value, source: l.source }));
1422
- this.events.emit("applying", { scanToken: e.scanToken, count: s.length }), (o = this.panel) == null || o.setStatus("识别完成,正在自动回填...");
1423
- const r = await new q(this.scanResult.fields, this.registeredFields, this.adapters).apply({ scanToken: e.scanToken, values: s }), a = {
1424
- ...r,
1425
- skipped: [...t, ...r.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
- ...r.warnings || [],
1428
- ...t.length ? ["部分字段因置信度或风险策略被跳过。"] : []
2811
+ ...i.warnings || [],
2812
+ ...n.length ? ["部分字段因置信度或风险策略被跳过。"] : []
1429
2813
  ]
1430
2814
  };
1431
- return this.events.emit("applied", a), (d = this.panel) == null || d.setApplyResult(a), a;
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 e of this.panels) e.destroy();
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 b("INSTANCE_DESTROYED", "实例已销毁。", "ui");
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
- emitError(e, t) {
1446
- var i;
1447
- const s = ge(e, t);
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 gt(n, e, t, s, i) {
2906
+ function ho(e, t, n) {
1452
2907
  return {
1453
- scanToken: n,
1454
- traceId: e,
1455
- items: t.map((r) => {
1456
- const a = s.fields.find((l) => l.fieldId === r.fieldId), o = i.find((l) => l.fieldId === r.fieldId), d = o != null && o.getValue ? o.getValue() : Et(a == null ? void 0 : a.element);
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
- warnings: r.warnings,
1469
- previousValue: d
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 de(n) {
1475
- var e;
1476
- return n.confidence >= pt && !((e = n.warnings) != null && e.length);
2950
+ function Wt(e) {
2951
+ var t;
2952
+ return e.confidence >= lo && !((t = e.warnings) != null && t.length);
1477
2953
  }
1478
- function mt(n) {
1479
- return n.items.filter((e) => !de(e)).map((e) => {
1480
- var t, s;
2954
+ function yo(e) {
2955
+ return e.items.filter((t) => !Wt(t)).map((t) => {
2956
+ var n, r;
1481
2957
  return {
1482
- fieldId: e.fieldId,
1483
- label: e.label,
1484
- attemptedValue: e.value,
1485
- reason: ((t = e.warnings) == null ? void 0 : t.join(";")) || `置信度 ${Math.round(e.confidence * 100)}% 低于自动回填阈值`,
1486
- reasonCode: (s = e.warnings) != null && s.length ? "AUTO_APPLY_WARNING" : "LOW_CONFIDENCE"
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 bt(n, e) {
1491
- const t = /* @__PURE__ */ new Map();
1492
- for (const s of e)
1493
- t.set(s.fieldId, s);
1494
- for (const s of n)
1495
- t.has(s.fieldId) || t.set(s.fieldId, s);
1496
- return [...t.values()];
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 yt(n, e) {
1499
- return n === "only" ? !0 : n === "off" ? !1 : e;
2974
+ function mo(e, t) {
2975
+ return e === "only" ? !0 : e === "off" ? !1 : t;
1500
2976
  }
1501
- function Y(n, e, t, s, i, r = !1) {
2977
+ function lt(e, t, n, r, o, i = !1) {
1502
2978
  return {
1503
- scanToken: n,
1504
- suggestions: t,
1505
- warnings: i,
2979
+ scanToken: e,
2980
+ suggestions: n,
2981
+ warnings: o,
1506
2982
  trace: {
1507
- traceId: e,
1508
- usedOcr: r,
2983
+ traceId: t,
2984
+ usedOcr: i,
1509
2985
  usedAi: !1,
1510
- durationMs: Math.round(performance.now() - s)
2986
+ durationMs: Math.round(performance.now() - r)
1511
2987
  }
1512
2988
  };
1513
2989
  }
1514
- function Et(n) {
1515
- if (n)
1516
- return n instanceof HTMLInputElement && n.type === "checkbox" ? n.checked : n instanceof HTMLInputElement || n instanceof HTMLTextAreaElement || n instanceof HTMLSelectElement ? n.value : n.textContent;
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 Z(n, e = "default") {
1519
- const t = typeof location < "u" ? location.pathname : "unknown-page", s = e.replace(/[^\w-]/g, "_") || "default";
1520
- return `smart-fill:${n}:${t}:${s}:open`;
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 xt(n, e) {
1523
- if (typeof n == "string") return n;
1524
- if (e.id) return `#${e.id}`;
1525
- const t = typeof e.className == "string" ? e.className.trim().split(/\s+/).filter(Boolean)[0] : "";
1526
- return t ? `.${t}` : e.tagName.toLowerCase();
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 G(n, e) {
3038
+ function Eo(e) {
3039
+ var t;
3040
+ if ((t = e.element) != null && t.isConnected) return e.element;
1529
3041
  try {
1530
- const t = window.localStorage.getItem(n);
1531
- return t == null ? e : t === "1";
3042
+ return document.querySelector(`[data-smart-fill-id="${$o(e.fieldId)}"]`);
1532
3043
  } catch {
1533
- return e;
3044
+ return null;
1534
3045
  }
1535
3046
  }
1536
- function X(n, e) {
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(n, e ? "1" : "0");
3256
+ window.localStorage.setItem(e, t ? "1" : "0");
1540
3257
  } catch {
1541
3258
  }
1542
3259
  }
1543
- function ue() {
3260
+ function tn() {
1544
3261
  return `smart-fill:${typeof location < "u" ? location.pathname : "unknown-page"}:local-priority`;
1545
3262
  }
1546
- function vt() {
3263
+ function qo() {
1547
3264
  try {
1548
- return window.localStorage.getItem(ue()) === "1";
3265
+ return window.localStorage.getItem(tn()) === "1";
1549
3266
  } catch {
1550
3267
  return !1;
1551
3268
  }
1552
3269
  }
1553
- function wt(n) {
3270
+ function No(e) {
1554
3271
  try {
1555
- window.localStorage.setItem(ue(), n ? "1" : "0");
3272
+ window.localStorage.setItem(tn(), e ? "1" : "0");
1556
3273
  } catch {
1557
3274
  }
1558
3275
  }
1559
- const f = { status: "idle" }, D = new Q(), W = new we();
1560
- class St {
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(e) {
3282
+ static async setup(t) {
1563
3283
  if (typeof window > "u")
1564
- return f.status = "ready", kt();
1565
- if (f.status === "ready" && f.apiKey === e.apiKey && f.session)
1566
- return f.session;
1567
- if (f.status === "loading" && f.apiKey === e.apiKey && f.promise)
1568
- return f.promise;
1569
- f.apiKey && f.apiKey !== e.apiKey && W.destroyAll();
1570
- const t = new me(e);
1571
- return f.status = "loading", f.apiKey = e.apiKey, f.client = t, f.promise = t.createSession().then((s) => (console.log("SmartFill session created:", s), t.setAccessToken(s.apiKey), f.status = "ready", f.session = s, D.emit("ready", { apiKey: e.apiKey }), s)).catch((s) => {
1572
- throw f.status = "error", s;
1573
- }), f.promise;
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(e = {}) {
3296
+ static create(t = {}) {
1577
3297
  if (typeof window > "u")
1578
- return A();
1579
- if (f.status !== "ready" || !f.client)
1580
- throw b("SDK_NOT_READY", "请先 await SmartFill.setup({ apiKey })。", "setup");
1581
- return new ht(e, {
1582
- client: f.client,
1583
- manager: W
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
- c(St, "on", D.on.bind(D));
1589
- function kt() {
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 A(n) {
1600
- const e = () => {
3319
+ function B(e) {
3320
+ const t = () => {
1601
3321
  };
1602
3322
  return {
1603
- on: e,
1604
- useAdapter: () => A(),
1605
- registerFields: () => A(),
1606
- unregisterFields: e,
1607
- mount: () => A(),
1608
- mountFloatingButton: () => A(),
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: e,
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
- destroy: e
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
- he as DEFAULT_BASE_URL,
1638
- q as DomFiller,
1639
- Je as DomScanner,
1640
- ke as ElementAdapter,
1641
- Q as EventBus,
1642
- De as LocalRuleEngine,
1643
- It as NativeAdapter,
1644
- St as SmartFill,
1645
- ht as SmartFillInstance
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
  };