@kc-one/smart-fill-sdk 0.0.1-beta.1 → 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 +24 -5
  2. package/dist/index.esm.js +2754 -890
  3. package/dist/index.umd.cjs +28 -19
  4. package/dist/src/adapters/element.d.ts +3 -0
  5. package/dist/src/adapters/element.d.ts.map +1 -0
  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 -5
  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 te = Object.defineProperty;
2
- var ne = (n, e, t) => e in n ? te(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t;
3
- var c = (n, e, t) => ne(n, typeof e != "symbol" ? e + "" : e, t);
4
- const se = "https://loan.kdbank.cn";
5
- class B 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 y(n, e, t, s = {}) {
14
- return new B({ 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 ie(n, e, t = "RECOGNIZE_FAILED") {
17
- return n instanceof B ? 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 L(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 re {
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", se);
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 re {
42
1426
  */
43
1427
  async createSession() {
44
1428
  if (!/^seKey-[A-Za-z0-9_-]{6,}$/.test(this.config.apiKey))
45
- throw y("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 re {
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,767 +1459,880 @@ class re {
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 = oe(i, e.fields, e.scanToken);
95
- return {
96
- scanToken: e.scanToken,
97
- suggestions: r,
98
- trace: i.trace || {
99
- traceId: L("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 = ce(s);
119
- if (!i)
120
- throw y("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", L("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 y(de(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" ? y("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 ae = 0.95;
146
- function oe(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: le(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 le(n) {
164
- return typeof n != "number" || Number.isNaN(n) ? ae : 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 ce(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 de(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 Y {
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 ue {
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 pe = [
1604
+ const _r = [
220
1605
  /^(el|rc|ant|radix|headlessui|mui|chakra)-/i,
221
1606
  /[0-9a-f]{8,}/i,
222
1607
  /\d{6,}/
223
1608
  ];
224
- function v(n) {
225
- const e = String(n || "").trim();
226
- return !e || pe.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;
227
1612
  }
228
- function $(n) {
229
- const e = (n.options || []).slice(0, 20).map((t) => `${t.label}:${String(t.value)}`).join("|");
230
- return w(
1613
+ function G(e) {
1614
+ const t = (e.options || []).slice(0, 20).map((n) => `${n.label}:${String(n.value)}`).join("|");
1615
+ return $(
231
1616
  [
232
- n.fieldId,
233
- n.tagName,
234
- n.type,
235
- v(n.name),
236
- v(n.id),
237
- n.label,
238
- n.placeholder,
239
- n.section,
240
- 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
241
1626
  ].join("::")
242
1627
  );
243
1628
  }
244
- function w(n) {
245
- return String(n ?? "").replace(/\s+/g, " ").trim().toLowerCase();
1629
+ function $(e) {
1630
+ return String(e ?? "").replace(/\s+/g, " ").trim().toLowerCase();
246
1631
  }
247
- const F = /* @__PURE__ */ new WeakMap();
248
- class D {
249
- constructor(e, t, s = []) {
250
- 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;
251
1656
  }
252
1657
  /**
253
1658
  * 批量回填字段值。
254
1659
  * 每条 value 依次校验:字段存在 → scanToken 有效 → validate → setValue。
255
1660
  * 失败项记入 skipped,不中断后续字段。
256
1661
  */
257
- async apply(e) {
258
- const t = [], s = [];
259
- for (const i of e.values) {
260
- const r = this.fields.find((l) => l.fieldId === i.fieldId);
261
- if (!r) {
262
- 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"));
263
1668
  continue;
264
1669
  }
265
- if (r.scanToken !== e.scanToken) {
266
- 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"));
267
1672
  continue;
268
1673
  }
269
- 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);
270
1675
  try {
271
- const l = a != null && a.validate ? await a.validate(o) : !0;
1676
+ const l = s != null && s.validate ? await s.validate(a) : !0;
272
1677
  if (l !== !0) {
273
- 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"));
274
1679
  continue;
275
1680
  }
276
- 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 });
277
1682
  } catch (l) {
278
- 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"));
279
1684
  }
280
1685
  }
281
1686
  return {
282
- applied: t,
283
- skipped: s,
284
- warnings: s.length ? ["部分字段未回填,请查看跳过原因。"] : void 0
1687
+ applied: n,
1688
+ skipped: r,
1689
+ warnings: r.length ? ["部分字段未回填,请查看跳过原因。"] : void 0
285
1690
  };
286
1691
  }
287
1692
  /** 读取字段当前值,优先级:schema.getValue > adapter > DOM */
288
- async getValue(e, t) {
289
- if (t != null && t.getValue) return t.getValue();
290
- const s = this.matchAdapter(e);
291
- if (s != null && s.getValue) return s.getValue(e);
292
- const i = M(e);
293
- if (i)
294
- 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;
295
1700
  }
296
1701
  /**
297
1702
  * 写入字段值,优先级:schema.setValue > adapter > 原生 DOM。
298
1703
  * 写入前校验 fingerprint 防 DOM 变化误填,写入后触发高亮。
299
1704
  */
300
- async setValue(e, t, s) {
301
- if (s != null && s.setValue) {
302
- 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);
303
1710
  return;
304
1711
  }
305
- const i = M(e);
306
- if (!i) throw new Error("页面中未找到对应字段");
307
- if (e.fingerprint && e.fingerprint !== $({ ...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() }))
308
1715
  throw new Error("字段结构已变化,请重新扫描");
309
- 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")
1718
+ throw new Error("字段不可编辑");
1719
+ if (!s && !i && (t.readonly || o.hasAttribute("readonly")))
310
1720
  throw new Error("字段不可编辑");
311
- const r = this.matchAdapter(e);
312
- if (r) {
313
- await r.setValue(e, t);
1721
+ if (i) {
1722
+ await i.setValue(t, n), Ce(o, t);
314
1723
  return;
315
1724
  }
316
- fe(i, t), he(i);
1725
+ Tr(o, n), Ce(o, t);
317
1726
  }
318
1727
  /** 匹配第一个适用的组件库适配器 */
319
- matchAdapter(e) {
320
- const t = M(e);
321
- return t ? this.adapters.find((s) => s.match(t, e)) : void 0;
322
- }
323
- }
324
- function M(n) {
325
- var e;
326
- return (e = n.element) != null && e.isConnected ? n.element : document.querySelector(`[data-smart-fill-id="${R(n.fieldId)}"]`);
327
- }
328
- function fe(n, e) {
329
- if (n instanceof HTMLInputElement && n.type === "checkbox")
330
- n.checked = !!e;
331
- else if (n instanceof HTMLInputElement && n.type === "radio") {
332
- const t = document.querySelector(`input[type="radio"][name="${R(n.name)}"][value="${R(String(e))}"]`);
333
- (t || n).checked = !0;
334
- } else n instanceof HTMLInputElement || n instanceof HTMLTextAreaElement || n instanceof HTMLSelectElement ? n.value = String(e ?? "") : n.isContentEditable && (n.textContent = String(e ?? ""));
335
- n.dispatchEvent(new Event("input", { bubbles: !0 })), n.dispatchEvent(new Event("change", { bubbles: !0 }));
336
- }
337
- function he(n) {
338
- var s;
339
- n.setAttribute("data-smart-fill-highlighted", "true"), (s = F.get(n)) == null || s.abort();
340
- const e = new AbortController(), t = (i) => {
341
- i && "isTrusted" in i && !i.isTrusted || (n.removeAttribute("data-smart-fill-highlighted"), e.abort(), F.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));
342
1780
  };
343
- F.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 });
1782
+ }
1783
+ function Mr(e) {
1784
+ return e.filter((t) => !e.some((n) => n !== t && n.contains(t)));
1785
+ }
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;
344
1792
  }
345
- function T(n, e, t, s, i) {
346
- return { fieldId: n, label: e, attemptedValue: t, reason: s, reasonCode: i };
1793
+ function fe(e, t, n, r, o) {
1794
+ return { fieldId: e, label: t, attemptedValue: n, reason: r, reasonCode: o };
347
1795
  }
348
- function R(n) {
349
- return typeof CSS < "u" && CSS.escape ? CSS.escape(n) : n.replace(/["\\]/g, "\\$&");
1796
+ function Ne(e) {
1797
+ return typeof CSS < "u" && CSS.escape ? CSS.escape(e) : e.replace(/["\\]/g, "\\$&");
350
1798
  }
351
- const ge = [
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 = [
352
1807
  { key: "mobile", pattern: new RegExp("(?<!\\d)1[3-9]\\d{9}(?!\\d)", "g"), confidence: 0.98, reason: "手机号正则命中" },
353
1808
  { key: "idCard", pattern: new RegExp("(?<!\\d)\\d{17}[\\dXx](?!\\d)", "g"), confidence: 0.96, reason: "身份证号正则命中" },
354
1809
  { key: "email", pattern: /[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}/g, confidence: 0.95, reason: "邮箱正则命中" },
355
1810
  { key: "bankCard", pattern: new RegExp("(?<!\\d)\\d{16,19}(?!\\d)", "g"), confidence: 0.9, reason: "银行卡号正则命中" },
356
1811
  { key: "amount", pattern: /(?:金额|价格|费用|合计|总计)[::\s]*([0-9]+(?:\.[0-9]{1,2})?)/g, confidence: 0.88, reason: "金额关键词命中" },
357
1812
  { key: "date", pattern: /\d{4}[-/.年]\d{1,2}[-/.月]\d{1,2}日?/g, confidence: 0.86, reason: "日期格式命中" }
358
- ], P = {
359
- legalPerson: ["法人", "法定代表人", "法定代表", "企业法人", "legal person", "legal representative"],
360
- emergencyContact: ["紧急联系人", "紧急联络人", "emergency contact"],
361
- contact: ["联系人", "联络人", "联系人员", "contact"],
362
- spouse: ["配偶", "爱人", "夫妻", "spouse"]
363
- }, h = {
364
- mobile: ["手机", "手机号", "电话", "联系电话", "mobile", "phone"],
365
- legalPersonMobile: ["法人手机号", "法人电话", "法定代表人手机号", "法人手机", "legal person mobile"],
366
- emergencyContactMobile: ["紧急联系人手机号", "紧急联系人电话", "紧急联系电话", "emergency contact mobile"],
367
- contactMobile: ["联系人手机号", "联系人电话", "联系手机", "contact mobile"],
368
- spouseMobile: ["配偶手机号", "配偶电话", "爱人手机号", "spouse mobile"],
369
- idCard: ["身份证", "证件号", "身份证号", "idcard", "id card"],
370
- legalPersonIdCard: ["法人身份证", "法人身份证号", "法定代表人身份证号"],
371
- spouseIdCard: ["配偶身份证", "配偶身份证号", "爱人身份证号"],
372
- email: ["邮箱", "邮件", "email", "mail"],
373
- contactEmail: ["联系人邮箱", "联系邮箱", "contact email"],
374
- name: ["姓名", "名字", "称呼", "name"],
375
- customerName: ["客户姓名", "申请人姓名", "用户姓名", "借款人姓名", "客户名称"],
376
- legalPersonName: ["法人姓名", "法定代表人姓名", "企业法人姓名"],
377
- emergencyContactName: ["紧急联系人姓名", "紧急联系人名称"],
378
- contactName: ["联系人姓名", "联系人名称"],
379
- spouseName: ["配偶姓名", "爱人姓名"],
380
- companyName: ["公司名称", "企业名称", "单位名称", "商户名称", "公司", "企业"],
381
- address: ["地址", "住址", "通讯地址", "联系地址", "现住址", "办公地址"],
382
- detailAddress: ["详细地址", "街道地址", "门牌地址", "详细住址"],
383
- amount: ["金额", "费用", "价格", "合计", "总计", "amount", "price"],
384
- applyAmount: ["申请金额", "贷款金额", "借款金额", "授信金额", "申请额度"],
385
- date: ["日期", "时间", "有效期", "date"],
386
- applyDate: ["申请日期", "申请时间", "受理日期", "进件日期"],
387
- bankCard: ["银行卡", "卡号", "bank", "bank card"]
388
- }, j = {
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 = {
389
1866
  mobile: "mobile",
390
- legalPersonMobile: "mobile",
391
- emergencyContactMobile: "mobile",
392
- contactMobile: "mobile",
393
- spouseMobile: "mobile",
394
1867
  idCard: "idCard",
395
- legalPersonIdCard: "idCard",
396
- spouseIdCard: "idCard",
397
1868
  email: "email",
398
- contactEmail: "email",
399
- name: "name",
400
- customerName: "name",
401
- legalPersonName: "name",
402
- emergencyContactName: "name",
403
- contactName: "name",
404
- spouseName: "name",
405
- companyName: "companyName",
406
- address: "address",
407
- detailAddress: "address",
1869
+ bankCard: "bankCard",
408
1870
  amount: "amount",
409
- applyAmount: "amount",
410
- date: "date",
411
- applyDate: "date",
412
- bankCard: "bankCard"
1871
+ date: "date"
413
1872
  };
414
- class me {
1873
+ class Or {
415
1874
  /**
416
1875
  * 从文本中提取事实并匹配到 scan 字段。
417
1876
  * 按 confidence 降序分配,每个 fieldId 仅匹配一次(usedFieldIds 去重)。
418
1877
  */
419
- recognize(e, t, s) {
420
- const i = Te([...ye(e), ...be(e)]), r = /* @__PURE__ */ new Set(), a = [];
421
- for (const o of i.sort((d, l) => l.confidence - d.confidence)) {
422
- const d = Ee(o, t, r);
423
- d && (a.push({
424
- fieldId: d.fieldId,
425
- scanToken: s,
426
- label: d.label,
427
- value: we(o.value, d),
428
- displayValue: o.value,
429
- 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,
430
1889
  source: "local_rule",
431
- reason: o.reason
432
- }), r.add(d.fieldId));
1890
+ reason: a.reason
1891
+ }), i.add(c.fieldId));
433
1892
  }
434
- return a;
435
- }
436
- }
437
- function ye(n) {
438
- const e = [];
439
- for (const t of ge)
440
- for (const s of n.matchAll(t.pattern)) {
441
- const i = Z(s[1] || s[0]);
442
- e.push({
443
- key: t.key,
444
- value: i,
445
- confidence: t.confidence,
446
- reason: t.reason,
447
- baseKey: j[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]
448
1907
  });
449
1908
  }
450
- return e;
451
- }
452
- function be(n) {
453
- const e = [], t = n.split(/\r?\n|[;,;]/).map((s) => s.trim()).filter(Boolean);
454
- for (const s of t) {
455
- const i = s.match(/^[“"'`]?([^::=]{2,30})[”"'`]?[::=]\s*(.+)$/);
456
- if (!i) continue;
457
- const r = Ae(i[1]), a = Z(i[2]);
458
- if (!(!r || !a))
459
- for (const o of xe(r, a))
460
- e.push(o);
461
- }
462
- return e;
463
- }
464
- function xe(n, e) {
465
- const t = w(n), s = Ie(e), i = [], r = Se(t);
466
- return f(t, h.applyDate) && i.push("applyDate"), f(t, h.applyAmount) && i.push("applyAmount"), f(t, h.companyName) && i.push("companyName"), f(t, h.detailAddress) && i.push("detailAddress"), f(t, h.address) && i.push("address"), (f(t, h.mobile) || s === "mobile") && r && N(i, r, "mobile"), (f(t, h.idCard) || s === "idCard") && r && N(i, r, "idCard"), (f(t, h.email) || s === "email") && r && N(i, r, "email"), (f(t, h.mobile) || s === "mobile") && i.push("mobile"), (f(t, h.idCard) || s === "idCard") && i.push("idCard"), (f(t, h.email) || s === "email") && i.push("email"), (f(t, h.bankCard) || s === "bankCard") && i.push("bankCard"), (f(t, h.amount) || s === "amount") && i.push("amount"), (f(t, h.date) || s === "date") && i.push("date"), Ce(i).map((a, o) => ({
467
- key: a,
468
- value: e,
469
- confidence: Math.max(0.84, 0.96 - o * 0.04),
470
- reason: r ? `键值对文本命中(${n},角色增强)` : `键值对文本命中(${n})`,
471
- baseKey: j[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]
472
1931
  }));
473
1932
  }
474
- function Ee(n, e, t) {
475
- let s = null;
476
- for (const i of e) {
477
- if (t.has(i.fieldId)) continue;
478
- const r = ve(n, i);
479
- 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 });
480
1939
  }
481
- return s && s.score >= 0.45 ? s.field : null;
1940
+ return r && r.score >= 0.45 ? r.field : null;
482
1941
  }
483
- function ve(n, e) {
484
- const t = w([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];
485
- let r = 0;
486
- return f(t, s) ? r += 0.95 : n.key !== n.baseKey && f(t, i) ? r += 0.68 : f(t, i) && (r += 0.82), t.includes(w(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);
487
- }
488
- function we(n, e) {
489
- var t;
490
- 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);
491
1946
  }
492
- function Se(n) {
493
- const e = Object.keys(P).filter((t) => f(n, P[t]));
494
- 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;
495
1950
  }
496
- function Ie(n) {
497
- const e = n.replace(/\s+/g, "");
498
- 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";
499
1954
  }
500
- function N(n, e, t) {
501
- var i;
502
- const s = (i = ke[e]) == null ? void 0 : i[t];
503
- s && n.push(s);
504
- }
505
- const ke = {
506
- legalPerson: {
507
- mobile: "legalPersonMobile",
508
- idCard: "legalPersonIdCard",
509
- name: "legalPersonName"
510
- },
511
- emergencyContact: {
512
- mobile: "emergencyContactMobile",
513
- name: "emergencyContactName"
514
- },
515
- contact: {
516
- mobile: "contactMobile",
517
- email: "contactEmail",
518
- name: "contactName"
519
- },
520
- spouse: {
521
- mobile: "spouseMobile",
522
- idCard: "spouseIdCard",
523
- name: "spouseName"
524
- }
525
- };
526
- function Ae(n) {
527
- return n.replace(/[“”"'`]/g, "").replace(/\s+/g, " ").trim();
1955
+ function Kr(e) {
1956
+ return e.replace(/[“”"'`]/g, "").replace(/\s+/g, " ").trim();
528
1957
  }
529
- function Z(n) {
530
- return n.replace(/[,。;;]+$/g, "").replace(/^[“”"'`\s]+|[“”"'`\s]+$/g, "").trim();
1958
+ function Kt(e) {
1959
+ return e.replace(/[,。;;]+$/g, "").replace(/^[“”"'`\s]+|[“”"'`\s]+$/g, "").trim();
531
1960
  }
532
- function f(n, e) {
533
- const t = w(n);
534
- return e.some((s) => t.includes(w(s)));
1961
+ function k(e, t) {
1962
+ const n = $(e);
1963
+ return t.some((r) => n.includes($(r)));
535
1964
  }
536
- function Te(n) {
537
- const e = /* @__PURE__ */ new Map();
538
- for (const t of n) {
539
- const s = `${t.key}::${t.value}`, i = e.get(s);
540
- (!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);
541
1970
  }
542
- return [...e.values()];
1971
+ return [...t.values()];
543
1972
  }
544
- function Ce(n) {
545
- return [...new Set(n)];
1973
+ function Br(e) {
1974
+ return [...new Set(e)];
546
1975
  }
547
- const Le = [
1976
+ const st = [
548
1977
  "input",
549
1978
  "textarea",
550
1979
  "select",
551
1980
  "[contenteditable]:not([contenteditable='false'])"
552
- ].join(", "), z = [
553
- "dialog[open]",
554
- "[role='dialog']",
555
- "[aria-modal='true']",
556
- ".modal",
557
- ".modal-dialog",
558
- ".ant-modal",
559
- ".ant-drawer",
560
- ".el-dialog",
561
- ".el-drawer",
562
- ".n-dialog",
563
- ".n-modal",
564
- ".popup",
565
- ".drawer"
566
- ].join(", "), Fe = /* @__PURE__ */ new Set(["hidden", "submit", "button", "image", "reset", "file", "password"]);
567
- class Me {
568
- constructor(e = document) {
569
- 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;
570
1985
  }
571
1986
  /**
572
1987
  * 扫描可回填字段。
573
1988
  * - registered 非空:仅解析注册 Schema,不扫 DOM
574
- * - 否则:自动扫描可见 input/textarea/select,优先弹窗内控件
1989
+ * - 否则:自动扫描可见原生控件与 UI 框架组件,优先弹窗内控件
575
1990
  */
576
- scan(e = {}) {
577
- var d;
578
- const t = L("scan");
579
- 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)
580
1995
  return {
581
- scanToken: t,
582
- fields: e.registered.map((l) => this.fromSchema(l, t))
1996
+ scanToken: n,
1997
+ fields: t.registered.map((u) => this.fromSchema(u, n))
583
1998
  };
584
- 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;
585
2000
  return {
586
- scanToken: t,
587
- 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))
588
2003
  };
589
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
+ }
590
2031
  /** FieldSchema → FieldDescriptor,解析 element 并生成 fingerprint */
591
- fromSchema(e, t) {
592
- const s = De(e.element, this.root), i = {
593
- fieldId: e.rowKey == null ? e.fieldId : `${e.fieldId}:${e.rowKey}`,
594
- label: e.label,
595
- type: e.type,
596
- localRuleMode: e.localRuleMode ?? "inherit",
597
- required: e.required,
598
- section: e.section,
599
- 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,
600
2042
  source: "registered",
601
- scanToken: t,
602
- element: s || void 0,
2043
+ scanToken: n,
2044
+ element: o || void 0,
603
2045
  fingerprint: ""
604
2046
  };
605
- return i.fingerprint = $({
2047
+ return i.fingerprint = G({
606
2048
  ...i,
607
- tagName: s == null ? void 0 : s.tagName.toLowerCase()
2049
+ tagName: o == null ? void 0 : o.tagName.toLowerCase()
608
2050
  }), i;
609
2051
  }
610
2052
  /** DOM 元素 → FieldDescriptor,自动推断 label/type 并写入 data-smart-fill-id */
611
- fromElement(e, t, s) {
612
- const i = Ne(e, t), r = $e(e), a = {
2053
+ fromElement(t, n, r, o = this.root) {
2054
+ const i = Gr(t, n), s = Xr(t, o), a = {
613
2055
  fieldId: i,
614
2056
  fingerprint: "",
615
- scanToken: s,
616
- type: Oe(e),
2057
+ scanToken: r,
2058
+ type: Yr(t),
617
2059
  localRuleMode: "inherit",
618
- label: G(e),
619
- placeholder: X(e),
620
- name: v(e.getAttribute("name")) || void 0,
621
- id: v(e.id) || void 0,
622
- section: _e(e),
623
- options: r,
624
- required: e.hasAttribute("required") || e.getAttribute("aria-required") === "true",
625
- readonly: e.hasAttribute("readonly"),
626
- disabled: e.hasAttribute("disabled"),
2060
+ label: Vt(t),
2061
+ placeholder: Ut(t),
2062
+ name: E(wt(t)) || void 0,
2063
+ id: E(t.id) || void 0,
2064
+ section: Wr(t),
2065
+ options: s,
2066
+ required: Qr(t),
2067
+ readonly: Jr(t) && !hn(t),
2068
+ disabled: Te(t),
627
2069
  source: "form_scan",
628
- element: e
2070
+ element: t
629
2071
  };
630
- return a.fingerprint = $({
2072
+ return se(a) && (a.options = void 0), a.fingerprint = G({
631
2073
  ...a,
632
- tagName: e.tagName.toLowerCase()
2074
+ tagName: t.tagName.toLowerCase()
633
2075
  }), a;
634
2076
  }
635
2077
  /** 解析扫描根节点,scanContainer 为 CSS 选择器 */
636
- resolveRoot(e) {
637
- if (e) {
638
- const t = W(this.root, e);
639
- if (t)
640
- return t;
2078
+ resolveRoot(t) {
2079
+ if (t) {
2080
+ const n = jt(this.root, t);
2081
+ if (n)
2082
+ return n;
641
2083
  }
642
2084
  return this.root;
643
2085
  }
644
2086
  /** 收集 root 下可见且可编辑的表单控件 */
645
- collectVisibleFields(e) {
646
- return Array.from(e.querySelectorAll(Le)).filter((t) => !(t instanceof HTMLElement) || !Re(t) || t instanceof HTMLInputElement && Fe.has((t.type || "").toLowerCase()) ? !1 : !t.hasAttribute("disabled") && !t.hasAttribute("readonly"));
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]);
647
2096
  }
648
2097
  /**
649
2098
  * 检测最应优先扫描的容器。
650
2099
  * 优先 activeElement 所在弹窗,否则取包含最多字段的弹窗容器。
651
2100
  */
652
- detectTopLayerContainer(e) {
653
- const t = document.activeElement instanceof HTMLElement ? document.activeElement : null, s = t == null ? void 0 : t.closest(z);
654
- if (s instanceof HTMLElement && e.some((r) => s.contains(r)))
655
- return s;
656
- const i = e.map((r) => r.closest(z)).filter((r) => r instanceof HTMLElement);
657
- 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;
658
2107
  }
659
2108
  }
660
- function Ne(n, e) {
661
- const t = n.getAttribute("data-smart-fill-id");
662
- if (t)
663
- return t;
664
- const i = v(n.getAttribute("data-smart-fill-key")) || v(n.getAttribute("name")) || v(n.id) || `smart-fill-${Date.now()}-${e}`;
665
- return n.setAttribute("data-smart-fill-id", i), i;
666
- }
667
- function Oe(n) {
668
- if (n instanceof HTMLTextAreaElement) return "textarea";
669
- if (n instanceof HTMLSelectElement) return "select";
670
- if (n instanceof HTMLInputElement) {
671
- const e = (n.type || "text").toLowerCase();
672
- if (e === "radio") return "radio";
673
- if (e === "checkbox") return "checkbox";
674
- if (e === "date" || e === "month") return "date";
675
- if (e === "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";
676
2129
  }
677
2130
  return "text";
678
2131
  }
679
- function G(n) {
680
- const e = n.getAttribute("aria-label");
681
- if (e) return e.trim();
682
- if (n.id) {
683
- const r = document.querySelector(`label[for="${J(n.id)}"]`);
684
- if (r != null && r.textContent) return I(r.textContent);
685
- }
686
- const t = n.closest("label");
687
- if (t != null && t.textContent) return I(t.textContent);
688
- 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");
689
- return i != null && i.textContent ? I(i.textContent) : X(n) || n.getAttribute("name") || n.id || "未命名字段";
690
- }
691
- function X(n) {
692
- return n.getAttribute("placeholder") || n.getAttribute("aria-placeholder") || void 0;
693
- }
694
- function _e(n) {
695
- const e = n.closest("fieldset, section, .panel, .card, .form-section"), t = e == null ? void 0 : e.querySelector("legend, h1, h2, h3, .title, .section-title");
696
- return t != null && t.textContent ? I(t.textContent) : void 0;
697
- }
698
- function $e(n) {
699
- if (n instanceof HTMLSelectElement)
700
- return Array.from(n.options).map((e) => ({
701
- label: I(e.textContent || e.label),
702
- 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
703
2173
  }));
704
- if (n instanceof HTMLInputElement && (n.type === "radio" || n.type === "checkbox") && n.name)
705
- return Array.from(document.querySelectorAll(`input[name="${J(n.name)}"]`)).map((e) => ({
706
- label: G(e),
707
- 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
708
2178
  }));
709
2179
  }
710
- function Re(n) {
711
- const e = window.getComputedStyle(n);
712
- return e.display === "none" || e.visibility === "hidden" || Number(e.opacity) === 0 ? !1 : !!(n.offsetWidth || n.offsetHeight || n.getClientRects().length);
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 || "");
2191
+ }
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);
2195
+ }
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));
713
2198
  }
714
- function De(n, e) {
715
- return n instanceof HTMLElement ? n : typeof n == "string" ? W(e, n) : null;
2199
+ function Jr(e) {
2200
+ return e.hasAttribute("readonly") || !!e.querySelector("[readonly]");
716
2201
  }
717
- function W(n, e) {
2202
+ function Qr(e) {
2203
+ return e.hasAttribute("required") || e.getAttribute("aria-required") === "true" || !!e.querySelector('[required], [aria-required="true"]');
2204
+ }
2205
+ function eo(e) {
2206
+ return Pe(e) != null || Re(e) != null;
2207
+ }
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;
2213
+ }
2214
+ function no(e, t) {
2215
+ return e instanceof HTMLElement ? e : typeof e == "string" ? jt(t, e) : null;
2216
+ }
2217
+ function jt(e, t) {
718
2218
  try {
719
- const t = n.querySelector(e);
720
- return t instanceof HTMLElement ? t : null;
2219
+ const n = e.querySelector(t);
2220
+ return n instanceof HTMLElement ? n : null;
721
2221
  } catch {
722
2222
  return null;
723
2223
  }
724
2224
  }
725
- function I(n) {
726
- return n.replace(/[*::]/g, "").replace(/\s+/g, " ").trim();
727
- }
728
- function J(n) {
729
- return typeof CSS < "u" && CSS.escape ? CSS.escape(n) : n.replace(/["\\]/g, "\\$&");
2225
+ function Ye(e) {
2226
+ return typeof CSS < "u" && CSS.escape ? CSS.escape(e) : e.replace(/["\\]/g, "\\$&");
730
2227
  }
731
- const O = 5, Pe = 10 * 1024 * 1024, ze = 50 * 1024 * 1024;
732
- class Ke {
733
- constructor(e) {
2228
+ const Le = 5, ro = 10 * 1024 * 1024, oo = 50 * 1024 * 1024;
2229
+ class io {
2230
+ constructor(t) {
734
2231
  /** 面板宿主元素,挂载到 container 下 */
735
- c(this, "host", null);
2232
+ d(this, "host", null);
736
2233
  /** Shadow DOM 根或 fallback 到 host */
737
- c(this, "root", null);
2234
+ d(this, "root", null);
738
2235
  /** 识别结果候选项,供 review 区域展示 */
739
- c(this, "autoApplyState", null);
2236
+ d(this, "autoApplyState", null);
740
2237
  /** 用户选择的图片文件列表 */
741
- c(this, "selectedFiles", []);
2238
+ d(this, "selectedFiles", []);
742
2239
  /** 文本输入框内容缓存,render 重绘时保留 */
743
- c(this, "inputText", "");
2240
+ d(this, "inputText", "");
744
2241
  /** 本地优先识别开关状态 */
745
- c(this, "localPriorityEnabled");
2242
+ d(this, "localPriorityEnabled");
746
2243
  /** 面板展开状态:inline 默认展开,floating 默认收起 */
747
- c(this, "isOpen", !1);
2244
+ d(this, "isOpen", !1);
748
2245
  /** floating 模式拖拽状态 */
749
- c(this, "dragState", null);
2246
+ d(this, "dragState", null);
750
2247
  /** 拖拽结束后抑制 click 触发 open,避免误开面板 */
751
- c(this, "suppressOpenClick", !1);
2248
+ d(this, "suppressOpenClick", !1);
752
2249
  /** 鼠标是否正悬浮在图片区,供 Ctrl+V 粘贴图片触发判断 */
753
- c(this, "isUploadHovering", !1);
754
- c(this, "handleDragMove", (e) => {
755
- if (!this.dragState || !this.host || e.pointerId !== this.dragState.pointerId) return;
756
- const t = e.clientX - this.dragState.startX, s = e.clientY - this.dragState.startY;
757
- (Math.abs(t) > 3 || Math.abs(s) > 3) && (this.dragState.moved = !0);
758
- const i = this.host.getBoundingClientRect(), r = Math.max(8, window.innerWidth - i.width - 8), a = Math.max(8, window.innerHeight - i.height - 8), o = C(this.dragState.startLeft + t, 8, r), d = C(this.dragState.startTop + s, 8, a);
759
- 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`;
760
2257
  });
761
- c(this, "handleDragEnd", (e) => {
762
- !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(() => {
763
2260
  this.suppressOpenClick = !1;
764
2261
  }, 0));
765
2262
  });
766
2263
  /** 面板聚焦或鼠标悬浮在图片区时接管全局粘贴图片 */
767
- c(this, "handleDocumentPaste", (e) => {
768
- const t = Ve(e);
769
- 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)
770
2267
  return;
771
- const s = document.activeElement, i = this.root instanceof ShadowRoot ? this.root.activeElement : null;
772
- !(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));
773
2270
  });
774
- this.options = e, this.localPriorityEnabled = e.localPriorityEnabled ?? !1;
2271
+ this.options = t, this.localPriorityEnabled = t.localPriorityEnabled ?? !1;
775
2272
  }
776
2273
  /** 挂载面板到指定容器,创建 Shadow DOM 并首次渲染 */
777
- mount(e) {
778
- 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);
779
2276
  }
780
2277
  /** 控制面板展开/收起 */
781
- setOpen(e) {
782
- this.isOpen = e, this.render(this.isOpen), this.keepHostInViewport();
2278
+ setOpen(t) {
2279
+ this.isOpen = t, this.render(this.isOpen), this.keepHostInViewport();
783
2280
  }
784
2281
  /** 同步本地优先开关状态(来自其他面板/外部持久化),不触发 onLocalPriorityChange */
785
- setLocalPriorityEnabled(e) {
786
- this.localPriorityEnabled = e;
787
- const t = this.query('[data-role="local-priority-toggle"]');
788
- 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);
789
2286
  }
790
2287
  /** 识别按钮 loading 状态 */
791
- setBusy(e, t = "") {
792
- const s = this.query('[data-role="recognize"]');
793
- 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", "智能识别"));
794
2291
  }
795
2292
  /** 更新底部状态文案 */
796
- setStatus(e) {
797
- const t = this.query('[data-role="status"]');
798
- 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"));
799
2296
  }
800
2297
  /** 展示错误状态(红色文案) */
801
- setError(e) {
802
- const t = this.query('[data-role="status"]');
803
- 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"));
804
2301
  }
805
2302
  /** 更新识别结果列表并刷新 review 区域 */
806
- setAutoApplyState(e) {
807
- 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", "识别完成,正在自动回填..."));
808
2305
  }
809
2306
  /** 展示回填结果统计(成功/跳过数量) */
810
- setApplyResult(e) {
811
- const t = this.query('[data-role="status"]');
812
- 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"));
813
2310
  }
814
2311
  /** 移除 DOM 节点并解绑拖拽监听 */
815
2312
  destroy() {
816
- var e;
817
- 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;
818
2315
  }
819
- render(e) {
2316
+ render(t) {
820
2317
  this.root && (this.root.innerHTML = `
821
- <style>${qe}</style>
2318
+ <style>${co}</style>
822
2319
  ${this.options.mode === "floating" ? `<button class="sf-float" type="button" data-role="open">${this.t("entry", "智能录入")}</button>` : ""}
823
- <section class="sf-panel ${e ? "is-open" : ""} ${this.options.mode === "inline" ? "is-inline" : "is-floating"}" aria-label="智能录入面板">
824
- <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" >
825
2322
  <strong>${this.t("title", "智能录入")}</strong>
826
- <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>
827
2324
  </header>
828
- <div class="sf-body ${e ? "is-open" : ""}">
2325
+ <div class="sf-body ${t ? "is-open" : ""}">
829
2326
  <label class="sf-toggle">
830
2327
  <span class="sf-toggle-main">
831
2328
  <input type="checkbox" data-role="local-priority-toggle" ${this.localPriorityEnabled ? "checked" : ""} />
832
- <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>
833
2331
  </span>
834
- <span class="sf-toggle-desc">${this.t("localPriorityDesc", "开启后优先使用前端本地规则提取手机号、证件号等;关闭后直接走后端识别流程。")}</span>
835
2332
  </label>
836
2333
  <div class="sf-entry-grid">
837
2334
  <div class="sf-textarea-wrap">
838
- <textarea class="sf-textarea" data-role="text" placeholder="${this.t("placeholder", "粘贴文本,如:姓名:张三 手机号:13800000000")}">${He(this.inputText)}</textarea>
2335
+ <textarea class="sf-textarea" data-role="text" placeholder="${this.t("placeholder", "粘贴文本,如:姓名:张三 手机号:13800000000")}">${so(this.inputText)}</textarea>
839
2336
  <div class="sf-textarea-actions">
840
2337
  <button class="sf-btn sf-btn-secondary" type="button" data-role="clear">${this.t("clear", "清空")}</button>
841
2338
  <button class="sf-btn sf-btn-primary" type="button" data-role="recognize">${this.t("recognize", "智能识别")}</button>
@@ -852,7 +2349,7 @@ class Ke {
852
2349
  <circle cx="10" cy="10.5" r="1" fill="currentColor"/>
853
2350
  </svg>
854
2351
  </span>
855
- <span class="sf-upload-hint">${this.t("uploadHint", `点击、拖拽、Ctrl + V 粘贴图片至此(最多 ${O} 张)`)}</span>
2352
+ <span class="sf-upload-hint">${this.t("uploadHint", `点击、拖拽、Ctrl + V 粘贴图片至此(最多 ${Le} 张)`)}</span>
856
2353
  </span>
857
2354
  <span class="sf-upload-btn" data-role="file-label">图片识别</span>
858
2355
  </label>
@@ -865,48 +2362,48 @@ class Ke {
865
2362
  `, this.bindEvents());
866
2363
  }
867
2364
  bindEvents() {
868
- var s, i, r, a, o, d, l;
869
- const e = this.query('[data-role="open"]');
870
- 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", () => {
871
2368
  this.suppressOpenClick || this.options.onOpen();
872
- }), (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", () => {
873
2370
  if (this.options.mode === "inline") {
874
2371
  this.isOpen ? this.options.onClose() : this.options.onOpen();
875
2372
  return;
876
2373
  }
877
2374
  this.options.onClose();
878
- }), (r = this.query('[data-role="file"]')) == null || r.addEventListener("change", (u) => {
879
- const g = u.target;
880
- 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 || []));
881
2378
  });
882
- const t = this.query('[data-role="upload"]');
883
- t == null || t.addEventListener("pointerenter", () => {
2379
+ const n = this.query('[data-role="upload"]');
2380
+ n == null || n.addEventListener("pointerenter", () => {
884
2381
  this.isUploadHovering = !0;
885
- }), t == null || t.addEventListener("pointerleave", () => {
886
- this.isUploadHovering = !1, t.removeAttribute("data-dragover");
887
- }), t == null || t.addEventListener("dragenter", (u) => {
888
- u.preventDefault(), this.isUploadHovering = !0, t.setAttribute("data-dragover", "true");
889
- }), t == null || t.addEventListener("dragover", (u) => {
890
- u.preventDefault(), t.setAttribute("data-dragover", "true");
891
- }), t == null || t.addEventListener("dragleave", (u) => {
892
- u.currentTarget.contains(u.relatedTarget) || (this.isUploadHovering = !1, t.removeAttribute("data-dragover"));
893
- }), t == null || t.addEventListener("drop", (u) => {
894
- var g;
895
- u.preventDefault(), this.isUploadHovering = !1, t.removeAttribute("data-dragover"), this.handleImages(Array.from(((g = u.dataTransfer) == null ? void 0 : g.files) || []));
896
- }), (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) => {
897
2394
  this.inputText = u.target.value;
898
- }), (o = this.query('[data-role="local-priority-toggle"]')) == null || o.addEventListener("change", (u) => {
899
- var g, x;
900
- this.localPriorityEnabled = u.target.checked, (x = (g = this.options).onLocalPriorityChange) == null || x.call(g, this.localPriorityEnabled);
901
- }), (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", () => {
902
2399
  this.clearFormState();
903
2400
  }), (l = this.query('[data-role="recognize"]')) == null || l.addEventListener("click", () => {
904
- const u = this.query('[data-role="text"]'), g = u == null ? void 0 : u.value.trim();
905
- 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) {
906
2403
  this.setError(this.t("emptyInput", "请输入文本内容。"));
907
2404
  return;
908
2405
  }
909
- this.options.onRecognize({ text: g });
2406
+ this.options.onRecognize({ text: p });
910
2407
  });
911
2408
  }
912
2409
  clearFormState() {
@@ -914,98 +2411,98 @@ class Ke {
914
2411
  }
915
2412
  /** 清空当前已选图片与上传文案,供 clear 和图片识别成功后复用 */
916
2413
  resetSelectedFiles() {
917
- var t;
2414
+ var n;
918
2415
  this.selectedFiles = [];
919
- const e = this.query('[data-role="file"]');
920
- 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");
921
2418
  }
922
2419
  /** 校验并触发图片识别,支持点击选择 / 拖拽 / 粘贴三种入口 */
923
- async handleImages(e) {
924
- const t = e.filter((r) => r.type.startsWith("image/"));
925
- if (!t.length) {
2420
+ async handleImages(t) {
2421
+ const n = t.filter((i) => i.type.startsWith("image/"));
2422
+ if (!n.length) {
926
2423
  this.resetSelectedFiles(), this.setError(this.t("invalidImageError", "请选择图片文件。"));
927
2424
  return;
928
2425
  }
929
- if (t.length > O) {
930
- this.resetSelectedFiles(), this.setError(this.t("maxFilesError", `最多上传 ${O} 张图片。`));
2426
+ if (n.length > Le) {
2427
+ this.resetSelectedFiles(), this.setError(this.t("maxFilesError", `最多上传 ${Le} 张图片。`));
931
2428
  return;
932
2429
  }
933
- if (t.find((r) => r.size > Pe)) {
2430
+ if (n.find((i) => i.size > ro)) {
934
2431
  this.resetSelectedFiles(), this.setError(this.t("maxSingleFileSizeError", "单张图片不能超过 10MB。"));
935
2432
  return;
936
2433
  }
937
- if (t.reduce((r, a) => r + a.size, 0) > ze) {
2434
+ if (n.reduce((i, s) => i + s.size, 0) > oo) {
938
2435
  this.resetSelectedFiles(), this.setError(this.t("maxTotalFileSizeError", "上传图片总大小不能超过 50MB。"));
939
2436
  return;
940
2437
  }
941
- this.selectedFiles = t, this.setStatus(this.t("imageReady", `已选择 ${this.selectedFiles.length} 张图片,开始识别...`));
2438
+ this.selectedFiles = n, this.setStatus(this.t("imageReady", `已选择 ${this.selectedFiles.length} 张图片,开始识别...`));
942
2439
  try {
943
2440
  await this.options.onRecognize({ images: [...this.selectedFiles] }), this.resetSelectedFiles();
944
2441
  } catch {
945
2442
  }
946
2443
  }
947
- startDrag(e) {
948
- var s;
949
- if (this.options.mode !== "floating" || !this.host || e.button !== 0 || (s = e.target) != null && s.closest('[data-role="close"]')) return;
950
- const t = this.host.getBoundingClientRect();
951
- 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 = {
952
- pointerId: e.pointerId,
953
- startX: e.clientX,
954
- startY: e.clientY,
955
- startLeft: t.left,
956
- 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,
957
2454
  moved: !1
958
- }, 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);
959
2456
  }
960
2457
  keepHostInViewport() {
961
2458
  this.options.mode !== "floating" || !this.host || !this.host.style.left || !this.host.style.top || window.requestAnimationFrame(() => {
962
2459
  if (!this.host) return;
963
- const e = this.host.getBoundingClientRect(), t = C(e.left, 8, Math.max(8, window.innerWidth - e.width - 8)), s = C(e.top, 8, Math.max(8, window.innerHeight - e.height - 8));
964
- 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`;
965
2462
  });
966
2463
  }
967
- query(e) {
968
- var t;
969
- 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;
970
2467
  }
971
- t(e, t) {
972
- var s;
973
- 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;
974
2471
  }
975
2472
  }
976
- function He(n) {
977
- return n.replace(/[&<>"']/g, (e) => ({
2473
+ function so(e) {
2474
+ return e.replace(/[&<>"']/g, (t) => ({
978
2475
  "&": "&amp;",
979
2476
  "<": "&lt;",
980
2477
  ">": "&gt;",
981
2478
  '"': "&quot;",
982
2479
  "'": "&#39;"
983
- })[e] || e);
2480
+ })[t] || t);
984
2481
  }
985
- function C(n, e, t) {
986
- return Math.min(Math.max(n, e), t);
2482
+ function pe(e, t, n) {
2483
+ return Math.min(Math.max(e, t), n);
987
2484
  }
988
- function Ve(n) {
989
- var t;
990
- 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);
991
2488
  }
992
- const qe = `
2489
+ const co = `
993
2490
  :host, .sf-panel { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
994
- :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; }
995
- .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; }
996
- .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; }
997
2494
  .sf-panel.is-open { display: block; }
998
2495
  .sf-panel.is-inline { display: block; }
999
2496
  .sf-body { display: none; }
1000
2497
  .sf-body.is-open { display: block; }
1001
2498
  .sf-header, .sf-actions { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
1002
2499
  .sf-header { cursor: move; user-select: none; touch-action: none; }
1003
- .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; }
1004
2501
  .sf-tip, .sf-status, .sf-empty, small { color: #64748b; font-size: 12px; }
1005
2502
  .sf-toggle { display: grid; gap: 4px; margin: 10px 0 12px; padding: 10px 12px; border: 1px solid #dbe3ef; border-radius: 10px; background: #f8fbff; }
1006
2503
  .sf-toggle-main { display: flex; align-items: center; gap: 8px; color: #172033; font-size: 13px; font-weight: 600; }
1007
2504
  .sf-toggle-main input { margin: 0; }
1008
- .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; }
1009
2506
  .sf-entry-grid { display: grid; grid-template-columns: minmax(0, 1fr) 200px; gap: 12px; align-items: stretch; margin: 10px 0 14px; }
1010
2507
  .sf-textarea-wrap { position: relative; }
1011
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; }
@@ -1023,10 +2520,10 @@ const qe = `
1023
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; }
1024
2521
  .sf-btn:hover { transform: translateY(-1px); box-shadow: 0 8px 20px rgba(15, 23, 42, .08); }
1025
2522
  .sf-btn-secondary { background: #fff; color: #6b7280; border-color: #e5e7eb; }
1026
- .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); }
1027
2524
  .sf-btn:disabled { opacity: .55; cursor: not-allowed; }
1028
2525
  .sf-panel.is-floating .sf-entry-grid { grid-template-columns: 1fr; gap: 10px; }
1029
- .sf-panel.is-floating .sf-textarea { min-height: 140px; }
2526
+ .sf-panel.is-floating .sf-textarea { min-height: 180px; }
1030
2527
  .sf-panel.is-floating .sf-upload { height: 96px; padding-top: 10px; padding-bottom: 10px; }
1031
2528
  .sf-panel.is-floating .sf-upload-illustration { gap: 6px; }
1032
2529
  .sf-panel.is-floating .sf-upload-icon { width: 22px; height: 22px; }
@@ -1035,110 +2532,126 @@ const qe = `
1035
2532
  [data-status="error"] { color: #dc2626; }
1036
2533
  [data-status="warning"] { color: #d97706; }
1037
2534
  [data-status="success"] { color: #16a34a; }
1038
- `, Ue = 0.75;
1039
- class Be {
1040
- 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) {
1041
2546
  /** 实例级事件总线,对应 instance.on(...) */
1042
- c(this, "events", new Y());
2547
+ d(this, "events", new Ht());
1043
2548
  /** 页面字段扫描器,root 来自 SmartFill.create({ root }) */
1044
- c(this, "scanner");
2549
+ d(this, "scanner");
1045
2550
  /** 浏览器端本地规则引擎,用于文本正则/键值对提取 */
1046
- c(this, "ruleEngine", new me());
2551
+ d(this, "ruleEngine", new Or());
1047
2552
  /** Shadow DOM 面板,mount / mountFloatingButton 后可用(指向最后挂载的面板,用于状态展示) */
1048
- c(this, "panel", null);
2553
+ d(this, "panel", null);
1049
2554
  /** 已挂载的全部面板(inline / floating 可同时存在),用于本地优先开关广播与销毁 */
1050
- c(this, "panels", []);
2555
+ d(this, "panels", []);
1051
2556
  /** 面板展开状态持久化 key */
1052
- c(this, "panelStorageKeys", /* @__PURE__ */ new Map());
2557
+ d(this, "panelStorageKeys", /* @__PURE__ */ new Map());
1053
2558
  /** 业务方 registerFields 注册的字段;非空时 rescan 仅扫描这些字段 */
1054
- c(this, "registeredFields", []);
2559
+ d(this, "registeredFields", []);
1055
2560
  /** 组件库回填适配器链,如 AntD / Element 自定义控件 */
1056
- c(this, "adapters", []);
2561
+ d(this, "adapters", [Nt]);
1057
2562
  /** 最近一次 rescan 结果;scanToken 用于识别/回填防过期校验 */
1058
- c(this, "scanResult", null);
2563
+ d(this, "scanResult", null);
1059
2564
  /** recognize 完成后生成的自动回填候选,供面板展示与 applyAutoItems 使用 */
1060
- c(this, "autoApplyState", null);
2565
+ d(this, "autoApplyState", null);
1061
2566
  /** 预留:表单配置版本号,识别请求可携带给后端 */
1062
- c(this, "formConfigVersion");
2567
+ d(this, "formConfigVersion");
1063
2568
  /** 面板「启用本地优先识别」开关状态,默认关闭(走后端识别) */
1064
- c(this, "localPriorityEnabled", !1);
2569
+ d(this, "localPriorityEnabled", !1);
1065
2570
  /** 实例是否已 destroy,销毁后所有公开方法抛 INSTANCE_DESTROYED */
1066
- c(this, "destroyed", !1);
1067
- this.config = e, this.context = t, this.scanner = new Me(e.root || document), this.localPriorityEnabled = Je(), 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);
1068
2581
  }
1069
2582
  /** 订阅实例事件,返回取消订阅函数 */
1070
- on(e, t) {
1071
- return this.events.on(e, t);
2583
+ on(t, n) {
2584
+ return this.events.on(t, n);
1072
2585
  }
1073
2586
  /** 注册组件库回填适配器,支持链式调用 */
1074
- useAdapter(e) {
1075
- return this.assertAlive(), this.adapters.push(e), this;
2587
+ useAdapter(t) {
2588
+ return this.assertAlive(), this.adapters.push(t), this;
1076
2589
  }
1077
2590
  /**
1078
2591
  * 显式注册字段映射(L3 模式)。
1079
2592
  * 注册后 rescan 不再自动扫 DOM,仅解析 element 选择器定位控件。
1080
2593
  * rowKey 用于明细行等同 fieldId 多行场景,不可重复。
1081
2594
  */
1082
- registerFields(e) {
2595
+ registerFields(t) {
1083
2596
  this.assertAlive();
1084
- const t = /* @__PURE__ */ new Set();
1085
- for (const s of e) {
1086
- const i = s.rowKey == null ? s.fieldId : `${s.fieldId}:${s.rowKey}`;
1087
- if (t.has(i))
1088
- throw y("UNSUPPORTED_PAGE", `字段 ${i} 重复注册。`, "scan");
1089
- 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);
1090
2603
  }
1091
- return this.registeredFields = e, this;
2604
+ return this.registeredFields = t, this.scanResult = null, this.schedulePreScan(), this;
1092
2605
  }
1093
2606
  /** 取消注册字段;不传 fieldIds 时清空全部注册 */
1094
- unregisterFields(e) {
1095
- 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();
1096
2609
  }
1097
2610
  /** 将面板嵌入指定容器(inline 模式) */
1098
- mount(e) {
2611
+ mount(t) {
1099
2612
  this.assertAlive();
1100
- const t = typeof e == "string" ? document.querySelector(e) : e;
1101
- if (!t)
1102
- throw y("UNSUPPORTED_PAGE", "未找到智能录入挂载点。", "ui");
1103
- const s = H("inline", We(e, t)), i = V(s, !0);
1104
- 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;
1105
2618
  }
1106
- /** 挂载右下角悬浮按钮 + 弹框(floating 模式) */
2619
+ /** 挂载右下角悬浮按钮 + 弹框(floating 模式),优先挂到当前子路由页面顶层容器 */
1107
2620
  mountFloatingButton() {
1108
2621
  this.assertAlive();
1109
- const e = H("floating"), t = V(e, !1);
1110
- 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;
1111
2624
  }
1112
2625
  /**
1113
2626
  * 创建面板并登记到 panels。
1114
2627
  * inline / floating 共用同一份 localPriorityEnabled,开关变更经 handleLocalPriorityChange 持久化并广播。
1115
2628
  */
1116
- createPanel(e, t, s) {
1117
- let i;
1118
- return i = new Ke({
1119
- mode: e,
1120
- initialOpen: s,
2629
+ createPanel(t, n, r) {
2630
+ let o;
2631
+ return o = new io({
2632
+ mode: t,
2633
+ initialOpen: r,
1121
2634
  messages: this.config.messages,
1122
2635
  localPriorityEnabled: this.localPriorityEnabled,
1123
- onOpen: () => this.open(i),
1124
- onClose: () => this.close(i),
1125
- onRecognize: (r) => (this.panel = i, this.recognize(r)),
1126
- onLocalPriorityChange: (r) => this.handleLocalPriorityChange(r, i)
1127
- }), 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;
1128
2641
  }
1129
2642
  /** 同步本地优先开关:更新内存态、写入 localStorage,并广播到其他已挂载面板 */
1130
- handleLocalPriorityChange(e, t) {
1131
- this.localPriorityEnabled = e, Qe(e);
1132
- for (const s of this.panels)
1133
- 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);
1134
2647
  }
1135
2648
  /** 打开面板并触发 rescan,同时激活当前实例(关闭其他实例面板) */
1136
- async open(e = this.panel) {
1137
- this.assertAlive(), e && (this.context.manager.activate(this), this.panel = e, e.setOpen(!0), q(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());
1138
2651
  }
1139
2652
  /** 关闭面板(不销毁实例) */
1140
- close(e = this.panel) {
1141
- e && (this.panel = e, e.setOpen(!1), q(this.panelStorageKeys.get(e), !1));
2653
+ close(t = this.panel) {
2654
+ t && (this.panel = t, t.setOpen(!1), ht(this.panelStorageKeys.get(t), !1));
1142
2655
  }
1143
2656
  /**
1144
2657
  * 扫描页面可回填字段。
@@ -1146,24 +2659,43 @@ class Be {
1146
2659
  * 扫描成功 emit scanCompleted,失败 emit error。
1147
2660
  */
1148
2661
  async rescan() {
1149
- var e;
1150
- 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;
1151
2669
  try {
1152
2670
  this.formConfigVersion = void 0;
1153
- const t = this.registeredFields.length ? this.registeredFields : void 0;
1154
- if (this.scanResult = this.scanner.scan({
1155
- 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({
1156
2675
  maxFields: this.config.maxFields
1157
- }), !this.scanResult.fields.length)
1158
- throw y("NO_FIELDS_FOUND", "当前页面未找到可回填字段。", "scan");
1159
- return this.events.emit("scanCompleted", {
2676
+ }) : this.scanner.scan({
2677
+ maxFields: this.config.maxFields
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", {
1160
2682
  scanToken: this.scanResult.scanToken,
1161
2683
  fieldCount: this.scanResult.fields.length
1162
- }), (e = this.panel) == null || e.setStatus(`已扫描 ${this.scanResult.fields.length} 个字段。`), this.scanResult;
1163
- } catch (t) {
1164
- 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;
1165
2687
  }
1166
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
+ }
1167
2699
  /**
1168
2700
  * 识别入口:文本/图片 → 本地规则 + 后端网关 → 合并 → 自动回填。
1169
2701
  *
@@ -1174,74 +2706,79 @@ class Be {
1174
2706
  *
1175
2707
  * 后端失败时,仅在当前已启用本地规则时,降级使用本地结果继续回填。
1176
2708
  */
1177
- async recognize(e) {
1178
- var r, a, o;
1179
- this.assertAlive();
1180
- const t = this.scanResult || await this.rescan(), s = L("trace"), i = performance.now();
1181
- 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, "识别中...");
1182
2714
  try {
1183
- const d = t.fields.filter((m) => Ge(m.localRuleMode, this.localPriorityEnabled)), l = t.fields.filter((m) => m.localRuleMode !== "only"), { text: u, usedOcr: g } = await this.context.client.resolveInputText({
1184
- text: e.text,
1185
- images: e.images,
1186
- onStatusChange: (m) => {
1187
- var k, E, A;
1188
- if (m === "image_uploading") {
1189
- (k = this.panel) == null || k.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("图片上传中...");
1190
2722
  return;
1191
2723
  }
1192
- if (m === "image_recognizing") {
1193
- (E = this.panel) == null || E.setStatus("图片识别中...");
2724
+ if (b === "image_recognizing") {
2725
+ (I = this.panel) == null || I.setStatus("图片识别中...");
1194
2726
  return;
1195
2727
  }
1196
- (A = this.panel) == null || A.setStatus("识别中...");
2728
+ (ie = this.panel) == null || ie.setStatus("识别中...");
1197
2729
  }
1198
- }), x = u ? this.ruleEngine.recognize(u, d, t.scanToken) : [];
1199
- let b;
1200
- if (!l.length)
1201
- b = K(t.scanToken, s, x, 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);
1202
2734
  else
1203
2735
  try {
1204
- const m = await this.context.client.recognize({
1205
- scanToken: t.scanToken,
2736
+ const b = await this.context.client.recognize({
2737
+ scanToken: n.scanToken,
1206
2738
  formCode: this.config.formCode,
1207
2739
  configVersion: this.formConfigVersion,
1208
- text: u,
1209
- usedOcr: g,
1210
- fields: l,
2740
+ text: x,
2741
+ usedOcr: ne,
2742
+ fields: g,
1211
2743
  onStatusChange: () => {
1212
- var E;
1213
- (E = this.panel) == null || E.setStatus("识别中...");
2744
+ var I;
2745
+ (I = this.panel) == null || I.setStatus("识别中...");
1214
2746
  }
1215
2747
  });
1216
- m.trace.durationMs = m.trace.durationMs || Math.round(performance.now() - i);
1217
- const k = Ze(
1218
- x,
1219
- m.suggestions.filter((E) => l.some((A) => A.fieldId === E.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))
1220
2752
  );
1221
- b = { ...m, suggestions: k };
1222
- } catch (m) {
1223
- if (!x.length)
1224
- throw m;
1225
- b = K(
1226
- t.scanToken,
1227
- s,
1228
- x,
1229
- i,
1230
- [g ? "后端识别失败,已使用 OCR 文本触发本地识别继续回填。" : "后端识别失败,已启用本地识别继续回填。"],
1231
- 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
1232
2764
  );
1233
2765
  }
1234
- return this.autoApplyState = Ye(
1235
- b.scanToken,
1236
- b.trace.traceId,
1237
- b.suggestions,
1238
- t,
2766
+ if (this.autoApplyState = go(
2767
+ S.scanToken,
2768
+ S.trace.traceId,
2769
+ S.suggestions,
2770
+ n,
1239
2771
  this.registeredFields
1240
- ), this.events.emit("recognized", b), (a = this.panel) == null || a.setAutoApplyState(this.autoApplyState), await this.applyAutoItems(this.autoApplyState), b;
1241
- } catch (d) {
1242
- 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;
1243
2780
  } finally {
1244
- (o = this.panel) == null || o.setBusy(!1);
2781
+ (u = this.panel) == null || u.setBusy(!1);
1245
2782
  }
1246
2783
  }
1247
2784
  /**
@@ -1249,191 +2786,527 @@ class Be {
1249
2786
  * 通常由业务方调用;recognize 流程内的自动回填走 applyAutoItems。
1250
2787
  * 需传入与当前 scanResult 一致的 scanToken。
1251
2788
  */
1252
- async apply(e) {
1253
- var i;
1254
- if (this.assertAlive(), !this.scanResult)
1255
- throw y("SCAN_TOKEN_EXPIRED", "请先扫描字段后再回填。", "apply");
1256
- this.events.emit("applying", { scanToken: e.scanToken, count: e.values.length });
1257
- const s = await new D(this.scanResult.fields, this.registeredFields, this.adapters).apply(e);
1258
- 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;
1259
2796
  }
1260
2797
  /**
1261
2798
  * 自动回填:过滤 confidence ≥ 阈值且无 warnings 的候选项,写入 DOM。
1262
2799
  * 被策略跳过的字段记录在 skipped 中,reasonCode 为 LOW_CONFIDENCE / AUTO_APPLY_WARNING。
1263
2800
  */
1264
- async applyAutoItems(e) {
1265
- var o, d;
2801
+ async applyAutoItems(t) {
2802
+ var a, c;
1266
2803
  if (!this.scanResult)
1267
- throw y("SCAN_TOKEN_EXPIRED", "请先扫描字段后再回填。", "apply");
1268
- const t = je(e), s = e.items.filter((l) => Q(l)).map((l) => ({ fieldId: l.fieldId, value: l.value, source: l.source }));
1269
- this.events.emit("applying", { scanToken: e.scanToken, count: s.length }), (o = this.panel) == null || o.setStatus("识别完成,正在自动回填...");
1270
- const r = await new D(this.scanResult.fields, this.registeredFields, this.adapters).apply({ scanToken: e.scanToken, values: s }), a = {
1271
- ...r,
1272
- 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],
1273
2810
  warnings: [
1274
- ...r.warnings || [],
1275
- ...t.length ? ["部分字段因置信度或风险策略被跳过。"] : []
2811
+ ...i.warnings || [],
2812
+ ...n.length ? ["部分字段因置信度或风险策略被跳过。"] : []
1276
2813
  ]
1277
2814
  };
1278
- 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;
1279
2816
  }
1280
2817
  /** 销毁实例:移除面板、清空事件、从 InstanceManager 注销 */
1281
2818
  destroy() {
1282
2819
  if (!this.destroyed) {
1283
- this.destroyed = !0;
1284
- 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();
1285
2822
  this.panels.length = 0, this.panelStorageKeys.clear(), this.panel = null, this.events.clear(), this.context.manager.remove(this);
1286
2823
  }
1287
2824
  }
1288
2825
  assertAlive() {
1289
2826
  if (this.destroyed)
1290
- throw y("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
+ });
1291
2887
  }
1292
- emitError(e, t) {
1293
- var i;
1294
- const s = ie(e, t);
1295
- this.events.emit("error", s), (i = this.panel) == null || i.setError(s.message);
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
+ };
2900
+ }
2901
+ clearFloatingLifecycle() {
2902
+ var t;
2903
+ (t = this.floatingLifecycleCleanup) == null || t.call(this);
1296
2904
  }
1297
2905
  }
1298
- function Ye(n, e, t, s, i) {
2906
+ function ho(e, t, n) {
1299
2907
  return {
1300
- scanToken: n,
1301
- traceId: e,
1302
- items: t.map((r) => {
1303
- 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() : Xe(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);
1304
2913
  return {
1305
- applyItemId: `${r.fieldId}_${Math.random().toString(36).slice(2, 8)}`,
1306
2914
  fieldId: r.fieldId,
1307
- scanToken: n,
1308
- groupId: r.groupId,
1309
2915
  label: r.label,
1310
2916
  value: r.value,
1311
- currentValue: d,
1312
2917
  displayValue: r.displayValue || String(r.value ?? ""),
1313
2918
  confidence: r.confidence,
1314
2919
  source: r.source,
1315
- warnings: r.warnings,
1316
- previousValue: d
2920
+ type: o == null ? void 0 : o.type,
2921
+ currentValue: r.currentValue,
2922
+ warnings: r.warnings
1317
2923
  };
1318
2924
  })
1319
2925
  };
1320
2926
  }
1321
- function Q(n) {
1322
- var e;
1323
- return n.confidence >= Ue && !((e = n.warnings) != null && e.length);
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
2946
+ };
2947
+ })
2948
+ };
2949
+ }
2950
+ function Wt(e) {
2951
+ var t;
2952
+ return e.confidence >= lo && !((t = e.warnings) != null && t.length);
1324
2953
  }
1325
- function je(n) {
1326
- return n.items.filter((e) => !Q(e)).map((e) => {
1327
- var t, s;
2954
+ function yo(e) {
2955
+ return e.items.filter((t) => !Wt(t)).map((t) => {
2956
+ var n, r;
1328
2957
  return {
1329
- fieldId: e.fieldId,
1330
- label: e.label,
1331
- attemptedValue: e.value,
1332
- reason: ((t = e.warnings) == null ? void 0 : t.join(";")) || `置信度 ${Math.round(e.confidence * 100)}% 低于自动回填阈值`,
1333
- 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"
1334
2963
  };
1335
2964
  });
1336
2965
  }
1337
- function Ze(n, e) {
1338
- const t = /* @__PURE__ */ new Map();
1339
- for (const s of e)
1340
- t.set(s.fieldId, s);
1341
- for (const s of n)
1342
- t.has(s.fieldId) || t.set(s.fieldId, s);
1343
- 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()];
1344
2973
  }
1345
- function Ge(n, e) {
1346
- return n === "only" ? !0 : n === "off" ? !1 : e;
2974
+ function mo(e, t) {
2975
+ return e === "only" ? !0 : e === "off" ? !1 : t;
1347
2976
  }
1348
- function K(n, e, t, s, i, r = !1) {
2977
+ function lt(e, t, n, r, o, i = !1) {
1349
2978
  return {
1350
- scanToken: n,
1351
- suggestions: t,
1352
- warnings: i,
2979
+ scanToken: e,
2980
+ suggestions: n,
2981
+ warnings: o,
1353
2982
  trace: {
1354
- traceId: e,
1355
- usedOcr: r,
2983
+ traceId: t,
2984
+ usedOcr: i,
1356
2985
  usedAi: !1,
1357
- durationMs: Math.round(performance.now() - s)
2986
+ durationMs: Math.round(performance.now() - r)
1358
2987
  }
1359
2988
  };
1360
2989
  }
1361
- function Xe(n) {
1362
- if (n)
1363
- 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;
1364
2993
  }
1365
- function H(n, e = "default") {
1366
- const t = typeof location < "u" ? location.pathname : "unknown-page", s = e.replace(/[^\w-]/g, "_") || "default";
1367
- 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
+ };
1368
3005
  }
1369
- function We(n, e) {
1370
- if (typeof n == "string") return n;
1371
- if (e.id) return `#${e.id}`;
1372
- const t = typeof e.className == "string" ? e.className.trim().split(/\s+/).filter(Boolean)[0] : "";
1373
- 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
+ };
1374
3037
  }
1375
- function V(n, e) {
3038
+ function Eo(e) {
3039
+ var t;
3040
+ if ((t = e.element) != null && t.isConnected) return e.element;
1376
3041
  try {
1377
- const t = window.localStorage.getItem(n);
1378
- return t == null ? e : t === "1";
3042
+ return document.querySelector(`[data-smart-fill-id="${$o(e.fieldId)}"]`);
1379
3043
  } catch {
1380
- return e;
3044
+ return null;
1381
3045
  }
1382
3046
  }
1383
- function q(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);
1384
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)
1385
3255
  try {
1386
- window.localStorage.setItem(n, e ? "1" : "0");
3256
+ window.localStorage.setItem(e, t ? "1" : "0");
1387
3257
  } catch {
1388
3258
  }
1389
3259
  }
1390
- function ee() {
3260
+ function tn() {
1391
3261
  return `smart-fill:${typeof location < "u" ? location.pathname : "unknown-page"}:local-priority`;
1392
3262
  }
1393
- function Je() {
3263
+ function qo() {
1394
3264
  try {
1395
- return window.localStorage.getItem(ee()) === "1";
3265
+ return window.localStorage.getItem(tn()) === "1";
1396
3266
  } catch {
1397
3267
  return !1;
1398
3268
  }
1399
3269
  }
1400
- function Qe(n) {
3270
+ function No(e) {
1401
3271
  try {
1402
- window.localStorage.setItem(ee(), n ? "1" : "0");
3272
+ window.localStorage.setItem(tn(), e ? "1" : "0");
1403
3273
  } catch {
1404
3274
  }
1405
3275
  }
1406
- const p = { status: "idle" }, _ = new Y(), U = new ue();
1407
- class et {
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 {
1408
3281
  /** 初始化 SDK:校验 apiKey、创建会话、获取 accessToken */
1409
- static async setup(e) {
3282
+ static async setup(t) {
1410
3283
  if (typeof window > "u")
1411
- return p.status = "ready", tt();
1412
- if (p.status === "ready" && p.apiKey === e.apiKey && p.session)
1413
- return p.session;
1414
- if (p.status === "loading" && p.apiKey === e.apiKey && p.promise)
1415
- return p.promise;
1416
- p.apiKey && p.apiKey !== e.apiKey && U.destroyAll();
1417
- const t = new re(e);
1418
- return p.status = "loading", p.apiKey = e.apiKey, p.client = t, p.promise = t.createSession().then((s) => (console.log("SmartFill session created:", s), t.setAccessToken(s.apiKey), p.status = "ready", p.session = s, _.emit("ready", { apiKey: e.apiKey }), s)).catch((s) => {
1419
- throw p.status = "error", s;
1420
- }), p.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;
1421
3294
  }
1422
3295
  /** 创建页面实例,必须在 setup ready 后调用 */
1423
- static create(e = {}) {
3296
+ static create(t = {}) {
1424
3297
  if (typeof window > "u")
1425
- return S();
1426
- if (p.status !== "ready" || !p.client)
1427
- throw y("SDK_NOT_READY", "请先 await SmartFill.setup({ apiKey })。", "setup");
1428
- return new Be(e, {
1429
- client: p.client,
1430
- manager: U
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
1431
3304
  });
1432
3305
  }
1433
3306
  }
1434
3307
  /** 订阅全局事件(目前仅 ready) */
1435
- c(et, "on", _.on.bind(_));
1436
- function tt() {
3308
+ d(Ho, "on", Me.on.bind(Me));
3309
+ function zo() {
1437
3310
  return {
1438
3311
  apiKey: "server-mock",
1439
3312
  accessToken: "server-mock",
@@ -1443,50 +3316,41 @@ function tt() {
1443
3316
  rulesVersion: "server"
1444
3317
  };
1445
3318
  }
1446
- function S(n) {
1447
- const e = () => {
3319
+ function B(e) {
3320
+ const t = () => {
1448
3321
  };
1449
3322
  return {
1450
- on: e,
1451
- useAdapter: () => S(),
1452
- registerFields: () => S(),
1453
- unregisterFields: e,
1454
- mount: () => S(),
1455
- mountFloatingButton: () => S(),
3323
+ on: t,
3324
+ useAdapter: () => B(),
3325
+ registerFields: () => B(),
3326
+ unregisterFields: t,
3327
+ mount: () => B(),
3328
+ mountFloatingButton: () => B(),
1456
3329
  open: async () => {
1457
3330
  },
1458
- close: e,
3331
+ close: t,
1459
3332
  rescan: async () => ({ scanToken: "server", fields: [] }),
1460
3333
  recognize: async () => ({
1461
3334
  scanToken: "server",
1462
3335
  suggestions: [],
1463
3336
  trace: { traceId: "server", usedOcr: !1, usedAi: !1, durationMs: 0 }
1464
3337
  }),
3338
+ // 识别结果
1465
3339
  apply: async () => ({ applied: [], skipped: [] }),
1466
- destroy: e
3340
+ // 回填结果
3341
+ destroy: t
3342
+ // 销毁实例
1467
3343
  };
1468
3344
  }
1469
- const st = {
1470
- name: "native",
1471
- /** 匹配 input / textarea / select 原生控件 */
1472
- match: (n) => n instanceof HTMLInputElement || n instanceof HTMLTextAreaElement || n instanceof HTMLSelectElement,
1473
- getValue: (n) => {
1474
- const e = n.element;
1475
- if (e instanceof HTMLInputElement && e.type === "checkbox") return e.checked;
1476
- if (e instanceof HTMLInputElement || e instanceof HTMLTextAreaElement || e instanceof HTMLSelectElement) return e.value;
1477
- },
1478
- setValue: (n, e) => {
1479
- const t = n.element;
1480
- 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 }));
1481
- }
1482
- };
1483
3345
  export {
1484
- se as DEFAULT_BASE_URL,
1485
- D as DomFiller,
1486
- Me as DomScanner,
1487
- Y as EventBus,
1488
- me as LocalRuleEngine,
1489
- st as NativeAdapter,
1490
- et as SmartFill,
1491
- Be 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
1492
3356
  };