@kc-one/smart-fill-sdk 0.0.12 → 0.0.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +542 -223
- package/dist/index.esm.js +198 -190
- package/dist/index.umd.cjs +8 -8
- package/dist/src/config/defaults.d.ts +1 -6
- package/dist/src/config/defaults.d.ts.map +1 -1
- package/dist/src/index.d.ts +3 -1
- package/dist/src/index.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
var pn = Object.defineProperty;
|
|
2
2
|
var hn = (e, t, n) => t in e ? pn(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
|
|
3
3
|
var d = (e, t, n) => hn(e, typeof t != "symbol" ? t + "" : t, n);
|
|
4
|
-
const
|
|
4
|
+
const oi = {
|
|
5
5
|
name: "native",
|
|
6
6
|
/** 匹配 input / textarea / select 原生控件 */
|
|
7
7
|
match: (e) => e instanceof HTMLInputElement || e instanceof HTMLTextAreaElement || e instanceof HTMLSelectElement,
|
|
@@ -335,7 +335,7 @@ function te(e) {
|
|
|
335
335
|
].join(", "));
|
|
336
336
|
return n instanceof HTMLElement ? n.matches(".van-field") && !k(n) ? null : n : ee(e) ? e : null;
|
|
337
337
|
}
|
|
338
|
-
function
|
|
338
|
+
function Ne(e) {
|
|
339
339
|
if (e instanceof HTMLSelectElement) return e;
|
|
340
340
|
if (I(e))
|
|
341
341
|
return e.closest(".el-cascader, .ant-cascader, .van-cascader, .n-cascader, .arco-cascader") || e;
|
|
@@ -348,7 +348,7 @@ function Ct(e) {
|
|
|
348
348
|
const t = me(e);
|
|
349
349
|
return t || (e instanceof HTMLSelectElement ? "select" : null);
|
|
350
350
|
}
|
|
351
|
-
function
|
|
351
|
+
function He(e, t) {
|
|
352
352
|
const n = t || Ct(e);
|
|
353
353
|
return n != null && xn.has(n);
|
|
354
354
|
}
|
|
@@ -377,7 +377,7 @@ function Tt(e) {
|
|
|
377
377
|
}
|
|
378
378
|
function ce(e) {
|
|
379
379
|
var t;
|
|
380
|
-
return !((t = e.options) != null && t.length) || e.type === "cascader" || En.test(e.label || "") ? !1 :
|
|
380
|
+
return !((t = e.options) != null && t.length) || e.type === "cascader" || En.test(e.label || "") ? !1 : Nn(e.options);
|
|
381
381
|
}
|
|
382
382
|
async function _n(e) {
|
|
383
383
|
if (e instanceof HTMLSelectElement)
|
|
@@ -387,7 +387,7 @@ async function _n(e) {
|
|
|
387
387
|
const n = te(e) || e;
|
|
388
388
|
if (!ee(n) && !I(n) && !k(n))
|
|
389
389
|
return;
|
|
390
|
-
const r = Kn(), o =
|
|
390
|
+
const r = Kn(), o = Hn(), i = new Set(o.getTrackedDropdowns());
|
|
391
391
|
try {
|
|
392
392
|
if (!(I(n) ? await Cn(n, o, i) : await An(n, o, i))) return;
|
|
393
393
|
const a = await Ln(o, i, n);
|
|
@@ -452,21 +452,21 @@ function Je(e, t, n) {
|
|
|
452
452
|
function In(e, t, n) {
|
|
453
453
|
const r = t.filter((c) => $e(e, c)), o = r.filter((c) => On(e, c)), i = o.filter((c) => !n.has(c));
|
|
454
454
|
if (i.length)
|
|
455
|
-
return i.sort((c, l) =>
|
|
455
|
+
return i.sort((c, l) => H(l, e) - H(c, e));
|
|
456
456
|
const s = It(e);
|
|
457
457
|
if (s.size) {
|
|
458
458
|
const c = o.filter((l) => l.id && s.has(l.id));
|
|
459
459
|
if (c.length) return c;
|
|
460
460
|
}
|
|
461
461
|
if (o.length)
|
|
462
|
-
return o.sort((c, l) =>
|
|
463
|
-
const a = r.filter((c) => Pn(c) && Mt(e)).sort((c, l) =>
|
|
462
|
+
return o.sort((c, l) => H(l, e) - H(c, e)).slice(0, 1);
|
|
463
|
+
const a = r.filter((c) => Pn(c) && Mt(e)).sort((c, l) => H(l, e) - H(c, e)).slice(0, 1);
|
|
464
464
|
return a.length ? a : [];
|
|
465
465
|
}
|
|
466
466
|
function ve(e, t, n) {
|
|
467
467
|
return In(n, e.getTrackedDropdowns(), t);
|
|
468
468
|
}
|
|
469
|
-
function
|
|
469
|
+
function H(e, t) {
|
|
470
470
|
const n = e.getBoundingClientRect(), r = Number.parseInt(window.getComputedStyle(e).zIndex || "0", 10);
|
|
471
471
|
let o = (Number.isNaN(r) ? 0 : r) * 10 + n.width * n.height;
|
|
472
472
|
return t && (o += Rt(t, e)), o;
|
|
@@ -532,7 +532,7 @@ function Rt(e, t) {
|
|
|
532
532
|
const i = r.top >= n.bottom ? r.top - n.bottom : n.top - r.bottom;
|
|
533
533
|
return i > 320 ? 0 : Math.max(0, 400 - i) + o;
|
|
534
534
|
}
|
|
535
|
-
function
|
|
535
|
+
function Nn(e) {
|
|
536
536
|
const t = e.slice(0, 8).map((r) => f(String(r.label || r.value || ""))).filter(Boolean);
|
|
537
537
|
return t.length < 4 ? !1 : t.filter((r) => Sn.test(r)).length / t.length >= 0.75;
|
|
538
538
|
}
|
|
@@ -561,7 +561,7 @@ function ne(e) {
|
|
|
561
561
|
e.querySelector(".select__wrapper")
|
|
562
562
|
].filter((n) => n instanceof HTMLElement).filter((n, r, o) => o.indexOf(n) === r);
|
|
563
563
|
}
|
|
564
|
-
function
|
|
564
|
+
function Hn() {
|
|
565
565
|
const e = /* @__PURE__ */ new Map();
|
|
566
566
|
$n(), document.documentElement.setAttribute(qe, "true");
|
|
567
567
|
const t = () => {
|
|
@@ -907,7 +907,7 @@ const Se = [
|
|
|
907
907
|
".arco-cascader-option"
|
|
908
908
|
].join(", "), er = ".van-picker__confirm, .van-picker__toolbar .van-picker__confirm";
|
|
909
909
|
async function tr(e, t, n, r) {
|
|
910
|
-
const o =
|
|
910
|
+
const o = Nt(t, r);
|
|
911
911
|
return e instanceof HTMLSelectElement ? nr(e, o) : I(e) || n === "cascader" ? rr(e, o) : (ee(e) || k(e) || n === "select" || n === "date", et(e, o));
|
|
912
912
|
}
|
|
913
913
|
function Pt(e) {
|
|
@@ -950,7 +950,7 @@ async function et(e, t) {
|
|
|
950
950
|
if (ye(n, t)) return;
|
|
951
951
|
throw new Error("自定义下拉框未能成功展开");
|
|
952
952
|
}
|
|
953
|
-
const i = await hr(n, r), s = await
|
|
953
|
+
const i = await hr(n, r), s = await Ht(t.searchValue, i, !0, !0);
|
|
954
954
|
if (s != null && s.source && z(s.source))
|
|
955
955
|
throw await W(n), await dr(n), new Error("下拉目标选项已禁用");
|
|
956
956
|
const a = await sr(t.searchValue, i, !0);
|
|
@@ -985,7 +985,7 @@ async function rr(e, t) {
|
|
|
985
985
|
}
|
|
986
986
|
throw await tt(n), new Error(r);
|
|
987
987
|
}
|
|
988
|
-
function
|
|
988
|
+
function Nt(e, t) {
|
|
989
989
|
var s;
|
|
990
990
|
const n = (s = t == null ? void 0 : t.options) != null && s.length ? Z(
|
|
991
991
|
t.options.map((a) => ({
|
|
@@ -1019,9 +1019,9 @@ async function ir(e) {
|
|
|
1019
1019
|
return !1;
|
|
1020
1020
|
}
|
|
1021
1021
|
async function sr(e, t, n = !1) {
|
|
1022
|
-
return
|
|
1022
|
+
return Ht(e, t, n, !1);
|
|
1023
1023
|
}
|
|
1024
|
-
async function
|
|
1024
|
+
async function Ht(e, t, n = !1, r = !1) {
|
|
1025
1025
|
for (let o = 0; o < 12; o += 1) {
|
|
1026
1026
|
const i = Z(
|
|
1027
1027
|
Bt(t, n, r).map((s) => ({
|
|
@@ -1099,7 +1099,7 @@ async function lr(e) {
|
|
|
1099
1099
|
return !Y().length || !0;
|
|
1100
1100
|
}
|
|
1101
1101
|
function ye(e, t) {
|
|
1102
|
-
const n = pr(t) ? t :
|
|
1102
|
+
const n = pr(t) ? t : Nt(t), r = n.displayValue || V(t), o = n.fillValue || r;
|
|
1103
1103
|
if (!r && !o) return !1;
|
|
1104
1104
|
const i = te(e) || e;
|
|
1105
1105
|
if (k(i))
|
|
@@ -1248,10 +1248,10 @@ function Ge(e) {
|
|
|
1248
1248
|
].filter((n) => n instanceof HTMLElement).filter((n, r, o) => o.indexOf(n) === r);
|
|
1249
1249
|
}
|
|
1250
1250
|
function Bt(e, t, n = !1) {
|
|
1251
|
-
return (e.length ? e : re()).flatMap((i) => i.matches(Se) ? [i] : Array.from(i.querySelectorAll(Se))).filter((i, s, a) => a.indexOf(i) === s).filter((i) => n ? t ? !0 :
|
|
1251
|
+
return (e.length ? e : re()).flatMap((i) => i.matches(Se) ? [i] : Array.from(i.querySelectorAll(Se))).filter((i, s, a) => a.indexOf(i) === s).filter((i) => n ? t ? !0 : N(i) : (t || N(i)) && !z(i));
|
|
1252
1252
|
}
|
|
1253
1253
|
function Y() {
|
|
1254
|
-
return Array.from(document.querySelectorAll(Jn)).filter(
|
|
1254
|
+
return Array.from(document.querySelectorAll(Jn)).filter(N);
|
|
1255
1255
|
}
|
|
1256
1256
|
async function hr(e, t) {
|
|
1257
1257
|
for (let n = 0; n < 10; n += 1) {
|
|
@@ -1259,7 +1259,7 @@ async function hr(e, t) {
|
|
|
1259
1259
|
if (r.length) return r;
|
|
1260
1260
|
await b(80);
|
|
1261
1261
|
}
|
|
1262
|
-
return re().filter(
|
|
1262
|
+
return re().filter(N);
|
|
1263
1263
|
}
|
|
1264
1264
|
function gr(e, t) {
|
|
1265
1265
|
const n = re(), r = n.filter((i) => !t.has(i));
|
|
@@ -1272,10 +1272,10 @@ function gr(e, t) {
|
|
|
1272
1272
|
const i = n.filter((s) => o.has(s.id));
|
|
1273
1273
|
if (i.length) return i;
|
|
1274
1274
|
}
|
|
1275
|
-
return n.filter((i) =>
|
|
1275
|
+
return n.filter((i) => N(i) && (i.querySelector(Se) || i.matches(Se))).sort((i, s) => fe(s) - fe(i)).slice(0, 1);
|
|
1276
1276
|
}
|
|
1277
1277
|
function nt(e) {
|
|
1278
|
-
return Bt(re().filter(
|
|
1278
|
+
return Bt(re().filter(N), !1).length > 0 ? !0 : Ge(e).some((t) => t.getAttribute("aria-expanded") === "true" || t.classList.contains("is-focus") || t.classList.contains("is-focused"));
|
|
1279
1279
|
}
|
|
1280
1280
|
function rt(e, t) {
|
|
1281
1281
|
const n = zt(e), r = w(n);
|
|
@@ -1307,7 +1307,7 @@ function z(e) {
|
|
|
1307
1307
|
}
|
|
1308
1308
|
function yr() {
|
|
1309
1309
|
const e = document.querySelector(er);
|
|
1310
|
-
e &&
|
|
1310
|
+
e && N(e) && R(e);
|
|
1311
1311
|
}
|
|
1312
1312
|
async function W(e) {
|
|
1313
1313
|
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 b(120);
|
|
@@ -1388,7 +1388,7 @@ function Gt(e) {
|
|
|
1388
1388
|
for (const t of [{ key: "ArrowDown", code: "ArrowDown" }, { key: "Enter", code: "Enter" }, { key: " ", code: "Space" }])
|
|
1389
1389
|
e.dispatchEvent(new KeyboardEvent("keydown", { ...t, bubbles: !0, composed: !0 })), e.dispatchEvent(new KeyboardEvent("keyup", { ...t, bubbles: !0, composed: !0 }));
|
|
1390
1390
|
}
|
|
1391
|
-
function
|
|
1391
|
+
function N(e) {
|
|
1392
1392
|
const t = window.getComputedStyle(e);
|
|
1393
1393
|
if (t.display === "none" || t.visibility === "hidden" || Number(t.opacity) === 0) return !1;
|
|
1394
1394
|
const n = e.getBoundingClientRect();
|
|
@@ -1399,7 +1399,7 @@ function b(e) {
|
|
|
1399
1399
|
}
|
|
1400
1400
|
const ot = /* @__PURE__ */ new Set(["select", "cascader", "date"]), Yt = {
|
|
1401
1401
|
name: "ui-framework",
|
|
1402
|
-
match: (e) => e.matches(vt) || St(e) || !mr(e) &&
|
|
1402
|
+
match: (e) => e.matches(vt) || St(e) || !mr(e) && He(e),
|
|
1403
1403
|
getValue: (e) => {
|
|
1404
1404
|
var o, i;
|
|
1405
1405
|
const t = e.element;
|
|
@@ -1428,7 +1428,7 @@ const ot = /* @__PURE__ */ new Set(["select", "cascader", "date"]), Yt = {
|
|
|
1428
1428
|
return;
|
|
1429
1429
|
}
|
|
1430
1430
|
const o = e.type || me(n) || (r == null ? void 0 : r.type);
|
|
1431
|
-
if (o && ot.has(o) ||
|
|
1431
|
+
if (o && ot.has(o) || He(n, o || void 0)) {
|
|
1432
1432
|
await tr(n, t, o || "select", e);
|
|
1433
1433
|
return;
|
|
1434
1434
|
}
|
|
@@ -1439,7 +1439,7 @@ const ot = /* @__PURE__ */ new Set(["select", "cascader", "date"]), Yt = {
|
|
|
1439
1439
|
}
|
|
1440
1440
|
n.dispatchEvent(new Event("change", { bubbles: !0 }));
|
|
1441
1441
|
}
|
|
1442
|
-
},
|
|
1442
|
+
}, ii = Yt;
|
|
1443
1443
|
function mr(e) {
|
|
1444
1444
|
return e instanceof HTMLInputElement || e instanceof HTMLTextAreaElement || e instanceof HTMLSelectElement;
|
|
1445
1445
|
}
|
|
@@ -1499,7 +1499,11 @@ function T(e) {
|
|
|
1499
1499
|
function oe(e) {
|
|
1500
1500
|
return e.replace(/\s+/g, " ").trim();
|
|
1501
1501
|
}
|
|
1502
|
-
const Cr = "https://
|
|
1502
|
+
const Cr = "https://loan.kdbank.cn", Tr = "https://8.kingdeefin.com";
|
|
1503
|
+
function Lr() {
|
|
1504
|
+
return typeof window < "u" && window.location.hostname.includes("8.kingdeefin") ? Tr : Cr;
|
|
1505
|
+
}
|
|
1506
|
+
const Ir = Lr();
|
|
1503
1507
|
class Wt extends Error {
|
|
1504
1508
|
constructor(n) {
|
|
1505
1509
|
super(n.message);
|
|
@@ -1522,12 +1526,12 @@ function it(e, t, n = "RECOGNIZE_FAILED") {
|
|
|
1522
1526
|
function xe(e = "sf") {
|
|
1523
1527
|
return `${e}_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 10)}`;
|
|
1524
1528
|
}
|
|
1525
|
-
class
|
|
1529
|
+
class Mr {
|
|
1526
1530
|
constructor(t) {
|
|
1527
1531
|
/** 会话 accessToken,写入请求头 seToken */
|
|
1528
1532
|
d(this, "seToken", "");
|
|
1529
1533
|
/** 网关根地址,见 config/defaults.ts */
|
|
1530
|
-
d(this, "baseURL",
|
|
1534
|
+
d(this, "baseURL", Ir);
|
|
1531
1535
|
this.config = t;
|
|
1532
1536
|
}
|
|
1533
1537
|
/** 设置会话 token,后续 request 自动携带 seToken 请求头 */
|
|
@@ -1590,7 +1594,7 @@ class Tr {
|
|
|
1590
1594
|
userInputMsg: r || ""
|
|
1591
1595
|
})
|
|
1592
1596
|
}
|
|
1593
|
-
), i =
|
|
1597
|
+
), i = Or(o, t.fields, t.scanToken);
|
|
1594
1598
|
return console.log("suggestions", i), {
|
|
1595
1599
|
scanToken: t.scanToken,
|
|
1596
1600
|
suggestions: i,
|
|
@@ -1614,7 +1618,7 @@ class Tr {
|
|
|
1614
1618
|
method: "POST",
|
|
1615
1619
|
body: n
|
|
1616
1620
|
}
|
|
1617
|
-
), o =
|
|
1621
|
+
), o = qr(r);
|
|
1618
1622
|
if (!o)
|
|
1619
1623
|
throw v("RECOGNIZE_FAILED", "图片识别未提取到文本内容。", "recognize");
|
|
1620
1624
|
return o;
|
|
@@ -1630,7 +1634,7 @@ class Tr {
|
|
|
1630
1634
|
signal: r.signal
|
|
1631
1635
|
});
|
|
1632
1636
|
if (!s.ok)
|
|
1633
|
-
throw v(
|
|
1637
|
+
throw v(Dr(s.status), await s.text(), t.includes("session") ? "setup" : "recognize", {
|
|
1634
1638
|
retryable: s.status >= 500 || s.status === 429
|
|
1635
1639
|
});
|
|
1636
1640
|
return s.json();
|
|
@@ -1641,8 +1645,8 @@ class Tr {
|
|
|
1641
1645
|
}
|
|
1642
1646
|
}
|
|
1643
1647
|
}
|
|
1644
|
-
const
|
|
1645
|
-
function
|
|
1648
|
+
const Rr = 0.95;
|
|
1649
|
+
function Or(e, t, n) {
|
|
1646
1650
|
var i;
|
|
1647
1651
|
const r = new Map(t.map((s) => [s.fieldId, s]));
|
|
1648
1652
|
return (((i = e.data) == null ? void 0 : i.fieldValues) || []).filter((s) => !!(s != null && s.fieldId)).map((s) => {
|
|
@@ -1653,21 +1657,21 @@ function Ir(e, t, n) {
|
|
|
1653
1657
|
label: s.label || (a == null ? void 0 : a.label) || s.fieldId,
|
|
1654
1658
|
value: s.value,
|
|
1655
1659
|
displayValue: s.value == null ? "" : String(s.value),
|
|
1656
|
-
confidence:
|
|
1660
|
+
confidence: Fr(s.confidence),
|
|
1657
1661
|
source: s.source || "ai",
|
|
1658
1662
|
warnings: s.warnings
|
|
1659
1663
|
};
|
|
1660
1664
|
});
|
|
1661
1665
|
}
|
|
1662
|
-
function
|
|
1663
|
-
return typeof e != "number" || Number.isNaN(e) ?
|
|
1666
|
+
function Fr(e) {
|
|
1667
|
+
return typeof e != "number" || Number.isNaN(e) ? Rr : e < 0 ? 0 : e > 1 ? 1 : e;
|
|
1664
1668
|
}
|
|
1665
|
-
function
|
|
1669
|
+
function qr(e) {
|
|
1666
1670
|
var n;
|
|
1667
1671
|
const t = typeof e.data == "string" ? e.data : ((n = e.data) == null ? void 0 : n.text) || e.text || "";
|
|
1668
1672
|
return String(t || "").trim();
|
|
1669
1673
|
}
|
|
1670
|
-
function
|
|
1674
|
+
function Dr(e) {
|
|
1671
1675
|
return e === 401 ? "TOKEN_EXPIRED" : e === 403 ? "API_KEY_FORBIDDEN" : e === 404 ? "FORM_CONFIG_NOT_FOUND" : "RECOGNIZE_FAILED";
|
|
1672
1676
|
}
|
|
1673
1677
|
class Xt {
|
|
@@ -1691,7 +1695,7 @@ class Xt {
|
|
|
1691
1695
|
this.handlers.clear();
|
|
1692
1696
|
}
|
|
1693
1697
|
}
|
|
1694
|
-
class
|
|
1698
|
+
class Pr {
|
|
1695
1699
|
constructor() {
|
|
1696
1700
|
/** 当前页面所有存活实例 */
|
|
1697
1701
|
d(this, "instances", /* @__PURE__ */ new Set());
|
|
@@ -1715,14 +1719,14 @@ class Fr {
|
|
|
1715
1719
|
this.instances.forEach((t) => t.destroy()), this.instances.clear(), this.active = null;
|
|
1716
1720
|
}
|
|
1717
1721
|
}
|
|
1718
|
-
const
|
|
1722
|
+
const Nr = [
|
|
1719
1723
|
/^(el|rc|ant|radix|headlessui|mui|chakra)-/i,
|
|
1720
1724
|
/[0-9a-f]{8,}/i,
|
|
1721
1725
|
/\d{6,}/
|
|
1722
1726
|
];
|
|
1723
1727
|
function A(e) {
|
|
1724
1728
|
const t = String(e || "").trim();
|
|
1725
|
-
return !t ||
|
|
1729
|
+
return !t || Nr.some((n) => n.test(t)) ? "" : t;
|
|
1726
1730
|
}
|
|
1727
1731
|
function X(e) {
|
|
1728
1732
|
const t = (e.options || []).slice(0, 20).map((n) => `${n.label}:${String(n.value)}`).join("|");
|
|
@@ -1743,7 +1747,7 @@ function X(e) {
|
|
|
1743
1747
|
function B(e) {
|
|
1744
1748
|
return String(e ?? "").replace(/\s+/g, " ").trim().toLowerCase();
|
|
1745
1749
|
}
|
|
1746
|
-
const st = "smart-fill-highlight-style",
|
|
1750
|
+
const st = "smart-fill-highlight-style", Hr = `
|
|
1747
1751
|
[data-smart-fill-highlighted="true"] {
|
|
1748
1752
|
background: #eaf3ff !important;
|
|
1749
1753
|
box-shadow: 0 0 0 1px #91caff inset !important;
|
|
@@ -1771,13 +1775,13 @@ const st = "smart-fill-highlight-style", Dr = `
|
|
|
1771
1775
|
box-shadow: 0 0 0 1px #91caff inset !important;
|
|
1772
1776
|
}
|
|
1773
1777
|
`.trim();
|
|
1774
|
-
function
|
|
1778
|
+
function $r() {
|
|
1775
1779
|
if (typeof document > "u" || document.getElementById(st))
|
|
1776
1780
|
return;
|
|
1777
1781
|
const e = document.createElement("style");
|
|
1778
|
-
e.id = st, e.textContent =
|
|
1782
|
+
e.id = st, e.textContent = Hr, document.head.appendChild(e);
|
|
1779
1783
|
}
|
|
1780
|
-
const Te = /* @__PURE__ */ new WeakMap(),
|
|
1784
|
+
const Te = /* @__PURE__ */ new WeakMap(), zr = [
|
|
1781
1785
|
'input:not([type="hidden"])',
|
|
1782
1786
|
"textarea",
|
|
1783
1787
|
"select",
|
|
@@ -1819,7 +1823,7 @@ class at {
|
|
|
1819
1823
|
r.push(he(i.fieldId, i.label, o.value, "页面扫描已过期,请重新扫描", "SCAN_TOKEN_EXPIRED"));
|
|
1820
1824
|
continue;
|
|
1821
1825
|
}
|
|
1822
|
-
const s =
|
|
1826
|
+
const s = Gr(this.schemas, o.fieldId), a = s != null && s.transform ? s.transform(o.value) : o.value, c = await this.getValue(i, s);
|
|
1823
1827
|
try {
|
|
1824
1828
|
const l = s != null && s.validate ? await s.validate(a) : !0;
|
|
1825
1829
|
if (l !== !0) {
|
|
@@ -1870,7 +1874,7 @@ class at {
|
|
|
1870
1874
|
await i.setValue(t, n), Le(o, t);
|
|
1871
1875
|
return;
|
|
1872
1876
|
}
|
|
1873
|
-
|
|
1877
|
+
Vr(o, n), Le(o, t);
|
|
1874
1878
|
}
|
|
1875
1879
|
/** 匹配第一个适用的组件库适配器 */
|
|
1876
1880
|
matchAdapter(t, n) {
|
|
@@ -1881,10 +1885,10 @@ class at {
|
|
|
1881
1885
|
function pe(e, t) {
|
|
1882
1886
|
var r;
|
|
1883
1887
|
if ((r = e.element) != null && r.isConnected) return e.element;
|
|
1884
|
-
const n =
|
|
1888
|
+
const n = Kr(t == null ? void 0 : t.element);
|
|
1885
1889
|
return n || document.querySelector(`[data-smart-fill-id="${ze(e.fieldId)}"]`);
|
|
1886
1890
|
}
|
|
1887
|
-
function
|
|
1891
|
+
function Kr(e) {
|
|
1888
1892
|
if (e instanceof HTMLElement)
|
|
1889
1893
|
return e.isConnected ? e : null;
|
|
1890
1894
|
if (typeof e == "string")
|
|
@@ -1896,7 +1900,7 @@ function Nr(e) {
|
|
|
1896
1900
|
}
|
|
1897
1901
|
return null;
|
|
1898
1902
|
}
|
|
1899
|
-
function
|
|
1903
|
+
function Vr(e, t) {
|
|
1900
1904
|
if (e instanceof HTMLInputElement && e.type === "checkbox")
|
|
1901
1905
|
e.checked = !!t;
|
|
1902
1906
|
else if (e instanceof HTMLInputElement && e.type === "radio") {
|
|
@@ -1906,25 +1910,25 @@ function $r(e, t) {
|
|
|
1906
1910
|
e.dispatchEvent(new Event("input", { bubbles: !0 })), e.dispatchEvent(new Event("change", { bubbles: !0 }));
|
|
1907
1911
|
}
|
|
1908
1912
|
function Le(e, t) {
|
|
1909
|
-
|
|
1910
|
-
const n =
|
|
1913
|
+
$r();
|
|
1914
|
+
const n = Br(e, t), r = () => {
|
|
1911
1915
|
for (const o of n)
|
|
1912
|
-
o.isConnected &&
|
|
1916
|
+
o.isConnected && Ur(o);
|
|
1913
1917
|
};
|
|
1914
1918
|
typeof requestAnimationFrame == "function" ? requestAnimationFrame(() => requestAnimationFrame(r)) : r();
|
|
1915
1919
|
}
|
|
1916
|
-
function
|
|
1920
|
+
function Br(e, t) {
|
|
1917
1921
|
if (e instanceof HTMLInputElement || e instanceof HTMLTextAreaElement || e instanceof HTMLSelectElement)
|
|
1918
1922
|
return [e];
|
|
1919
|
-
const n =
|
|
1920
|
-
Array.from(n.querySelectorAll(
|
|
1923
|
+
const n = He(e, t == null ? void 0 : t.type) && te(e) || e, r = jr(
|
|
1924
|
+
Array.from(n.querySelectorAll(zr)).filter(ct)
|
|
1921
1925
|
);
|
|
1922
1926
|
if (r.length)
|
|
1923
1927
|
return r;
|
|
1924
1928
|
const o = $(n);
|
|
1925
1929
|
return o && ct(o) ? [o] : [n];
|
|
1926
1930
|
}
|
|
1927
|
-
function
|
|
1931
|
+
function Ur(e) {
|
|
1928
1932
|
var r;
|
|
1929
1933
|
e.setAttribute("data-smart-fill-highlighted", "true"), (r = Te.get(e)) == null || r.abort();
|
|
1930
1934
|
const t = new AbortController(), n = (o) => {
|
|
@@ -1932,7 +1936,7 @@ function Kr(e) {
|
|
|
1932
1936
|
};
|
|
1933
1937
|
Te.set(e, t), e.addEventListener("pointerdown", n, { signal: t.signal }), e.addEventListener("mousedown", 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 });
|
|
1934
1938
|
}
|
|
1935
|
-
function
|
|
1939
|
+
function jr(e) {
|
|
1936
1940
|
return e.filter((t) => !e.some((n) => n !== t && n.contains(t)));
|
|
1937
1941
|
}
|
|
1938
1942
|
function ct(e) {
|
|
@@ -1948,14 +1952,14 @@ function he(e, t, n, r, o) {
|
|
|
1948
1952
|
function ze(e) {
|
|
1949
1953
|
return typeof CSS < "u" && CSS.escape ? CSS.escape(e) : e.replace(/["\\]/g, "\\$&");
|
|
1950
1954
|
}
|
|
1951
|
-
function
|
|
1955
|
+
function Gr(e, t) {
|
|
1952
1956
|
const n = e.find((o) => o.fieldId === t);
|
|
1953
1957
|
if (n) return n;
|
|
1954
1958
|
const r = t.includes(":") ? t.slice(t.lastIndexOf(":") + 1) : "";
|
|
1955
1959
|
if (r)
|
|
1956
1960
|
return e.find((o) => o.rowKey != null && String(o.rowKey) === r && `${o.fieldId}:${o.rowKey}` === t);
|
|
1957
1961
|
}
|
|
1958
|
-
const
|
|
1962
|
+
const Yr = [
|
|
1959
1963
|
{ key: "mobile", pattern: new RegExp("(?<!\\d)1[3-9]\\d{9}(?!\\d)", "g"), confidence: 0.98, reason: "手机号正则命中" },
|
|
1960
1964
|
{ key: "idCard", pattern: new RegExp("(?<!\\d)\\d{17}[\\dXx](?!\\d)", "g"), confidence: 0.96, reason: "身份证号正则命中" },
|
|
1961
1965
|
{ key: "email", pattern: /[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}/g, confidence: 0.95, reason: "邮箱正则命中" },
|
|
@@ -2022,20 +2026,20 @@ const Ur = [
|
|
|
2022
2026
|
amount: "amount",
|
|
2023
2027
|
date: "date"
|
|
2024
2028
|
};
|
|
2025
|
-
class
|
|
2029
|
+
class Wr {
|
|
2026
2030
|
/**
|
|
2027
2031
|
* 从文本中提取事实并匹配到 scan 字段。
|
|
2028
2032
|
* 按 confidence 降序分配,每个 fieldId 仅匹配一次(usedFieldIds 去重)。
|
|
2029
2033
|
*/
|
|
2030
2034
|
recognize(t, n, r) {
|
|
2031
|
-
const o =
|
|
2035
|
+
const o = oo([...Xr(t), ...Zr(t)]), i = /* @__PURE__ */ new Set(), s = [];
|
|
2032
2036
|
for (const a of o.sort((c, l) => l.confidence - c.confidence)) {
|
|
2033
|
-
const c =
|
|
2037
|
+
const c = Qr(a, n, i);
|
|
2034
2038
|
c && (s.push({
|
|
2035
2039
|
fieldId: c.fieldId,
|
|
2036
2040
|
scanToken: r,
|
|
2037
2041
|
label: c.label,
|
|
2038
|
-
value:
|
|
2042
|
+
value: to(a.value, c),
|
|
2039
2043
|
displayValue: a.value,
|
|
2040
2044
|
confidence: a.confidence,
|
|
2041
2045
|
source: "local_rule",
|
|
@@ -2045,9 +2049,9 @@ class jr {
|
|
|
2045
2049
|
return s;
|
|
2046
2050
|
}
|
|
2047
2051
|
}
|
|
2048
|
-
function
|
|
2052
|
+
function Xr(e) {
|
|
2049
2053
|
const t = [];
|
|
2050
|
-
for (const n of
|
|
2054
|
+
for (const n of Yr)
|
|
2051
2055
|
for (const r of e.matchAll(n.pattern)) {
|
|
2052
2056
|
const o = Jt(r[1] || r[0]);
|
|
2053
2057
|
t.push({
|
|
@@ -2060,21 +2064,21 @@ function Gr(e) {
|
|
|
2060
2064
|
}
|
|
2061
2065
|
return t;
|
|
2062
2066
|
}
|
|
2063
|
-
function
|
|
2067
|
+
function Zr(e) {
|
|
2064
2068
|
const t = [], n = e.split(/\r?\n|[;,;]/).map((r) => r.trim()).filter(Boolean);
|
|
2065
2069
|
for (const r of n) {
|
|
2066
2070
|
const o = r.match(/^[“"'`]?([^::=]{2,30})[”"'`]?[::=]\s*(.+)$/);
|
|
2067
2071
|
if (!o) continue;
|
|
2068
|
-
const i =
|
|
2072
|
+
const i = ro(o[1]), s = Jt(o[2]);
|
|
2069
2073
|
if (!(!i || !s))
|
|
2070
|
-
for (const a of
|
|
2074
|
+
for (const a of Jr(i, s))
|
|
2071
2075
|
t.push(a);
|
|
2072
2076
|
}
|
|
2073
2077
|
return t;
|
|
2074
2078
|
}
|
|
2075
|
-
function
|
|
2076
|
-
const n = B(e), r =
|
|
2077
|
-
return (C(n, F.mobile) || r === "mobile") && o.push("mobile"), (C(n, F.idCard) || r === "idCard") && o.push("idCard"), (C(n, F.email) || r === "email") && o.push("email"), (C(n, F.bankCard) || r === "bankCard") && o.push("bankCard"), (C(n, F.amount) || r === "amount") && o.push("amount"), (C(n, F.date) || r === "date") && o.push("date"),
|
|
2079
|
+
function Jr(e, t) {
|
|
2080
|
+
const n = B(e), r = no(t), o = [];
|
|
2081
|
+
return (C(n, F.mobile) || r === "mobile") && o.push("mobile"), (C(n, F.idCard) || r === "idCard") && o.push("idCard"), (C(n, F.email) || r === "email") && o.push("email"), (C(n, F.bankCard) || r === "bankCard") && o.push("bankCard"), (C(n, F.amount) || r === "amount") && o.push("amount"), (C(n, F.date) || r === "date") && o.push("date"), io(o).map((i, s) => ({
|
|
2078
2082
|
key: i,
|
|
2079
2083
|
value: t,
|
|
2080
2084
|
confidence: Math.max(0.84, 0.96 - s * 0.04),
|
|
@@ -2082,29 +2086,29 @@ function Wr(e, t) {
|
|
|
2082
2086
|
baseKey: Zt[i]
|
|
2083
2087
|
}));
|
|
2084
2088
|
}
|
|
2085
|
-
function
|
|
2089
|
+
function Qr(e, t, n) {
|
|
2086
2090
|
let r = null;
|
|
2087
2091
|
for (const o of t) {
|
|
2088
2092
|
if (n.has(o.fieldId)) continue;
|
|
2089
|
-
const i =
|
|
2093
|
+
const i = eo(e, o);
|
|
2090
2094
|
i > ((r == null ? void 0 : r.score) ?? 0) && (r = { field: o, score: i });
|
|
2091
2095
|
}
|
|
2092
2096
|
return r && r.score >= 0.45 ? r.field : null;
|
|
2093
2097
|
}
|
|
2094
|
-
function
|
|
2098
|
+
function eo(e, t) {
|
|
2095
2099
|
const n = B([t.fieldId, t.label, t.placeholder, t.name, t.id, t.section].join(" ")), r = F[e.key] || [e.key];
|
|
2096
2100
|
let o = 0;
|
|
2097
2101
|
return C(n, r) ? o += 0.95 : C(n, [e.key]) && (o += 0.82), n.includes(B(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);
|
|
2098
2102
|
}
|
|
2099
|
-
function
|
|
2103
|
+
function to(e, t) {
|
|
2100
2104
|
var n;
|
|
2101
2105
|
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;
|
|
2102
2106
|
}
|
|
2103
|
-
function
|
|
2107
|
+
function no(e) {
|
|
2104
2108
|
const t = e.replace(/\s+/g, "");
|
|
2105
2109
|
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";
|
|
2106
2110
|
}
|
|
2107
|
-
function
|
|
2111
|
+
function ro(e) {
|
|
2108
2112
|
return e.replace(/[“”"'`]/g, "").replace(/\s+/g, " ").trim();
|
|
2109
2113
|
}
|
|
2110
2114
|
function Jt(e) {
|
|
@@ -2114,7 +2118,7 @@ function C(e, t) {
|
|
|
2114
2118
|
const n = B(e);
|
|
2115
2119
|
return t.some((r) => n.includes(B(r)));
|
|
2116
2120
|
}
|
|
2117
|
-
function
|
|
2121
|
+
function oo(e) {
|
|
2118
2122
|
const t = /* @__PURE__ */ new Map();
|
|
2119
2123
|
for (const n of e) {
|
|
2120
2124
|
const r = `${n.key}::${n.value}`, o = t.get(r);
|
|
@@ -2122,7 +2126,7 @@ function to(e) {
|
|
|
2122
2126
|
}
|
|
2123
2127
|
return [...t.values()];
|
|
2124
2128
|
}
|
|
2125
|
-
function
|
|
2129
|
+
function io(e) {
|
|
2126
2130
|
return [...new Set(e)];
|
|
2127
2131
|
}
|
|
2128
2132
|
const lt = [
|
|
@@ -2130,8 +2134,8 @@ const lt = [
|
|
|
2130
2134
|
"textarea",
|
|
2131
2135
|
"select",
|
|
2132
2136
|
"[contenteditable]:not([contenteditable='false'])"
|
|
2133
|
-
].join(", "),
|
|
2134
|
-
class
|
|
2137
|
+
].join(", "), so = /* @__PURE__ */ new Set(["hidden", "submit", "button", "image", "reset", "file", "password"]);
|
|
2138
|
+
class ao {
|
|
2135
2139
|
constructor(t = document) {
|
|
2136
2140
|
this.root = t;
|
|
2137
2141
|
}
|
|
@@ -2182,7 +2186,7 @@ class oo {
|
|
|
2182
2186
|
}
|
|
2183
2187
|
/** FieldSchema → FieldDescriptor,解析 element 并生成 fingerprint */
|
|
2184
2188
|
fromSchema(t, n) {
|
|
2185
|
-
const r =
|
|
2189
|
+
const r = mo(t.element, this.root), o = r ? Ne(r) || Fe(r) || r : null, i = {
|
|
2186
2190
|
fieldId: t.rowKey == null ? t.fieldId : `${t.fieldId}:${t.rowKey}`,
|
|
2187
2191
|
label: t.label,
|
|
2188
2192
|
type: t.type,
|
|
@@ -2203,20 +2207,20 @@ class oo {
|
|
|
2203
2207
|
}
|
|
2204
2208
|
/** DOM 元素 → FieldDescriptor,自动推断 label/type 并写入 data-smart-fill-id */
|
|
2205
2209
|
fromElement(t, n, r, o = this.root) {
|
|
2206
|
-
const i =
|
|
2210
|
+
const i = co(t, n), s = fo(t, o), a = {
|
|
2207
2211
|
fieldId: i,
|
|
2208
2212
|
fingerprint: "",
|
|
2209
2213
|
scanToken: r,
|
|
2210
|
-
type:
|
|
2214
|
+
type: lo(t),
|
|
2211
2215
|
localRuleMode: "inherit",
|
|
2212
2216
|
label: Qt(t),
|
|
2213
2217
|
placeholder: tn(t),
|
|
2214
2218
|
name: A(xt(t)) || void 0,
|
|
2215
2219
|
id: A(t.id) || void 0,
|
|
2216
|
-
section:
|
|
2220
|
+
section: uo(t),
|
|
2217
2221
|
options: s,
|
|
2218
|
-
required:
|
|
2219
|
-
readonly:
|
|
2222
|
+
required: go(t),
|
|
2223
|
+
readonly: ho(t),
|
|
2220
2224
|
disabled: Ie(t),
|
|
2221
2225
|
source: "form_scan",
|
|
2222
2226
|
element: t
|
|
@@ -2240,11 +2244,11 @@ class oo {
|
|
|
2240
2244
|
const n = /* @__PURE__ */ new Set(), r = [lt, kt, vt, ".van-field"].join(", ");
|
|
2241
2245
|
for (const s of t.querySelectorAll(r)) {
|
|
2242
2246
|
if (!(s instanceof HTMLElement)) continue;
|
|
2243
|
-
const a =
|
|
2247
|
+
const a = Ne(s) || Fe(s);
|
|
2244
2248
|
!a || !Ke(a) || Ie(a) || n.add(a);
|
|
2245
2249
|
}
|
|
2246
|
-
const o = [...n], i = Array.from(t.querySelectorAll(lt)).filter((s) => !(s instanceof HTMLElement) || !Ke(s) ||
|
|
2247
|
-
return
|
|
2250
|
+
const o = [...n], i = Array.from(t.querySelectorAll(lt)).filter((s) => !(s instanceof HTMLElement) || !Ke(s) || yo(s) || s instanceof HTMLInputElement && so.has((s.type || "").toLowerCase()) ? !1 : !Ie(s) && !s.hasAttribute("readonly"));
|
|
2251
|
+
return bo([...i, ...o]);
|
|
2248
2252
|
}
|
|
2249
2253
|
/**
|
|
2250
2254
|
* 检测最应优先扫描的容器。
|
|
@@ -2258,14 +2262,14 @@ class oo {
|
|
|
2258
2262
|
return o.length ? o.sort((i, s) => t.filter((a) => s.contains(a)).length - t.filter((a) => i.contains(a)).length)[0] : document.body;
|
|
2259
2263
|
}
|
|
2260
2264
|
}
|
|
2261
|
-
function
|
|
2265
|
+
function co(e, t) {
|
|
2262
2266
|
const n = e.getAttribute("data-smart-fill-id");
|
|
2263
2267
|
if (n)
|
|
2264
2268
|
return n;
|
|
2265
2269
|
const o = A(e.getAttribute("name")) || A(e.getAttribute("data-smart-fill-key")) || A(xt(e)) || A(e.id) || A(Qt(e)) || `smart-fill-${Date.now()}-${t}`;
|
|
2266
2270
|
return e.setAttribute("data-smart-fill-id", o), o;
|
|
2267
2271
|
}
|
|
2268
|
-
function
|
|
2272
|
+
function lo(e) {
|
|
2269
2273
|
const t = Ct(e);
|
|
2270
2274
|
if (t) return t;
|
|
2271
2275
|
const n = me(e);
|
|
@@ -2309,11 +2313,11 @@ function tn(e) {
|
|
|
2309
2313
|
var t;
|
|
2310
2314
|
return e.getAttribute("placeholder") || e.getAttribute("aria-placeholder") || ((t = e.querySelector("[placeholder]")) == null ? void 0 : t.getAttribute("placeholder")) || void 0;
|
|
2311
2315
|
}
|
|
2312
|
-
function
|
|
2316
|
+
function uo(e) {
|
|
2313
2317
|
const t = e.closest("fieldset, section, .panel, .card, .form-section"), n = t == null ? void 0 : t.querySelector("legend, h1, h2, h3, .title, .section-title");
|
|
2314
2318
|
return n != null && n.textContent ? f(n.textContent) : void 0;
|
|
2315
2319
|
}
|
|
2316
|
-
function
|
|
2320
|
+
function fo(e, t = document) {
|
|
2317
2321
|
const n = Tt(e);
|
|
2318
2322
|
if (n != null && n.length) return n;
|
|
2319
2323
|
const r = Et(e);
|
|
@@ -2325,11 +2329,11 @@ function co(e, t = document) {
|
|
|
2325
2329
|
}));
|
|
2326
2330
|
if (e instanceof HTMLInputElement && (e.type === "radio" || e.type === "checkbox") && e.name)
|
|
2327
2331
|
return Array.from(t.querySelectorAll(`input[name="${Ye(e.name)}"]`)).filter((o) => o.type === e.type && Ke(o)).map((o) => ({
|
|
2328
|
-
label:
|
|
2332
|
+
label: po(o),
|
|
2329
2333
|
value: o.value || !0
|
|
2330
2334
|
}));
|
|
2331
2335
|
}
|
|
2332
|
-
function
|
|
2336
|
+
function po(e) {
|
|
2333
2337
|
if (e.id) {
|
|
2334
2338
|
const n = document.querySelector(`label[for="${Ye(e.id)}"]`);
|
|
2335
2339
|
if (n != null && n.textContent) return f(n.textContent);
|
|
@@ -2348,22 +2352,22 @@ function Ke(e) {
|
|
|
2348
2352
|
function Ie(e) {
|
|
2349
2353
|
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" || gn.some((t) => e.classList.contains(t));
|
|
2350
2354
|
}
|
|
2351
|
-
function
|
|
2355
|
+
function ho(e) {
|
|
2352
2356
|
return e.hasAttribute("readonly") || !!e.querySelector("[readonly]");
|
|
2353
2357
|
}
|
|
2354
|
-
function
|
|
2358
|
+
function go(e) {
|
|
2355
2359
|
return e.hasAttribute("required") || e.getAttribute("aria-required") === "true" || !!e.querySelector('[required], [aria-required="true"]');
|
|
2356
2360
|
}
|
|
2357
|
-
function
|
|
2358
|
-
return
|
|
2361
|
+
function yo(e) {
|
|
2362
|
+
return Ne(e) != null || Fe(e) != null;
|
|
2359
2363
|
}
|
|
2360
|
-
function
|
|
2364
|
+
function bo(e) {
|
|
2361
2365
|
const t = [];
|
|
2362
2366
|
for (const n of e)
|
|
2363
2367
|
t.some((r) => r === n || r.contains(n) || n.contains(r)) || t.push(n);
|
|
2364
2368
|
return t;
|
|
2365
2369
|
}
|
|
2366
|
-
function
|
|
2370
|
+
function mo(e, t) {
|
|
2367
2371
|
return e instanceof HTMLElement ? e : typeof e == "string" ? nn(t, e) : null;
|
|
2368
2372
|
}
|
|
2369
2373
|
function nn(e, t) {
|
|
@@ -2377,8 +2381,8 @@ function nn(e, t) {
|
|
|
2377
2381
|
function Ye(e) {
|
|
2378
2382
|
return typeof CSS < "u" && CSS.escape ? CSS.escape(e) : e.replace(/["\\]/g, "\\$&");
|
|
2379
2383
|
}
|
|
2380
|
-
const Me = 5,
|
|
2381
|
-
class
|
|
2384
|
+
const Me = 5, wo = 10 * 1024 * 1024, vo = 50 * 1024 * 1024;
|
|
2385
|
+
class So {
|
|
2382
2386
|
constructor(t) {
|
|
2383
2387
|
/** 面板宿主元素,挂载到 container 下 */
|
|
2384
2388
|
d(this, "host", null);
|
|
@@ -2414,7 +2418,7 @@ class mo {
|
|
|
2414
2418
|
});
|
|
2415
2419
|
/** 面板聚焦或鼠标悬浮在图片区时接管全局粘贴图片 */
|
|
2416
2420
|
d(this, "handleDocumentPaste", (t) => {
|
|
2417
|
-
const n =
|
|
2421
|
+
const n = xo(t);
|
|
2418
2422
|
if (!n.length || !this.isOpen || !this.host)
|
|
2419
2423
|
return;
|
|
2420
2424
|
const r = document.activeElement, o = this.root instanceof ShadowRoot ? this.root.activeElement : null;
|
|
@@ -2467,7 +2471,7 @@ class mo {
|
|
|
2467
2471
|
}
|
|
2468
2472
|
render(t) {
|
|
2469
2473
|
this.root && (this.root.innerHTML = `
|
|
2470
|
-
<style>${
|
|
2474
|
+
<style>${ko}</style>
|
|
2471
2475
|
${this.options.mode === "floating" ? `<button class="sf-float" type="button" data-role="open">${this.t("entry", "智能录入")}</button>` : ""}
|
|
2472
2476
|
<section class="sf-panel ${t ? "is-open" : ""} ${this.options.mode === "inline" ? "is-inline" : "is-floating"}" aria-label="智能录入面板">
|
|
2473
2477
|
<header class="sf-header" data-role="close" >
|
|
@@ -2477,7 +2481,7 @@ class mo {
|
|
|
2477
2481
|
<div class="sf-body ${t ? "is-open" : ""}">
|
|
2478
2482
|
<div class="sf-entry-grid">
|
|
2479
2483
|
<div class="sf-textarea-wrap">
|
|
2480
|
-
<textarea class="sf-textarea" data-role="text" placeholder="${this.t("placeholder", "粘贴文本,如:姓名:张三 手机号:13800000000")}">${
|
|
2484
|
+
<textarea class="sf-textarea" data-role="text" placeholder="${this.t("placeholder", "粘贴文本,如:姓名:张三 手机号:13800000000")}">${Eo(this.inputText)}</textarea>
|
|
2481
2485
|
<div class="sf-textarea-actions">
|
|
2482
2486
|
<button class="sf-btn sf-btn-secondary" type="button" data-role="clear">${this.t("clear", "清空")}</button>
|
|
2483
2487
|
<button class="sf-btn sf-btn-primary" type="button" data-role="recognize">${this.t("recognize", "智能识别")}</button>
|
|
@@ -2572,11 +2576,11 @@ class mo {
|
|
|
2572
2576
|
this.resetSelectedFiles(), this.setError(this.t("maxFilesError", `最多上传 ${Me} 张图片。`));
|
|
2573
2577
|
return;
|
|
2574
2578
|
}
|
|
2575
|
-
if (n.find((i) => i.size >
|
|
2579
|
+
if (n.find((i) => i.size > wo)) {
|
|
2576
2580
|
this.resetSelectedFiles(), this.setError(this.t("maxSingleFileSizeError", "单张图片不能超过 10MB。"));
|
|
2577
2581
|
return;
|
|
2578
2582
|
}
|
|
2579
|
-
if (n.reduce((i, s) => i + s.size, 0) >
|
|
2583
|
+
if (n.reduce((i, s) => i + s.size, 0) > vo) {
|
|
2580
2584
|
this.resetSelectedFiles(), this.setError(this.t("maxTotalFileSizeError", "上传图片总大小不能超过 50MB。"));
|
|
2581
2585
|
return;
|
|
2582
2586
|
}
|
|
@@ -2615,7 +2619,7 @@ class mo {
|
|
|
2615
2619
|
return ((r = this.options.messages) == null ? void 0 : r[t]) || n;
|
|
2616
2620
|
}
|
|
2617
2621
|
}
|
|
2618
|
-
function
|
|
2622
|
+
function Eo(e) {
|
|
2619
2623
|
return e.replace(/[&<>"']/g, (t) => ({
|
|
2620
2624
|
"&": "&",
|
|
2621
2625
|
"<": "<",
|
|
@@ -2627,11 +2631,11 @@ function wo(e) {
|
|
|
2627
2631
|
function ge(e, t, n) {
|
|
2628
2632
|
return Math.min(Math.max(e, t), n);
|
|
2629
2633
|
}
|
|
2630
|
-
function
|
|
2634
|
+
function xo(e) {
|
|
2631
2635
|
var n;
|
|
2632
2636
|
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);
|
|
2633
2637
|
}
|
|
2634
|
-
const
|
|
2638
|
+
const ko = `
|
|
2635
2639
|
:host, .sf-panel { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
|
|
2636
2640
|
: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; }
|
|
2637
2641
|
.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; }
|
|
@@ -2702,23 +2706,23 @@ const So = `
|
|
|
2702
2706
|
width: min(450px, calc(100vw - 32px))
|
|
2703
2707
|
}
|
|
2704
2708
|
}
|
|
2705
|
-
`,
|
|
2709
|
+
`, _o = 0.75, Ao = 1800, U = /* @__PURE__ */ new Map();
|
|
2706
2710
|
let j = 0;
|
|
2707
2711
|
const Ve = "smart-fill:routechange", rn = "smart-fill:session-scan:";
|
|
2708
2712
|
let ut = !1;
|
|
2709
2713
|
const dt = /* @__PURE__ */ new WeakMap();
|
|
2710
|
-
let
|
|
2714
|
+
let Co = 0;
|
|
2711
2715
|
function on() {
|
|
2712
2716
|
U.clear(), dn(), j += 1;
|
|
2713
2717
|
}
|
|
2714
|
-
class
|
|
2718
|
+
class To {
|
|
2715
2719
|
constructor(t, n) {
|
|
2716
2720
|
/** 实例级事件总线,对应 instance.on(...) */
|
|
2717
2721
|
d(this, "events", new Xt());
|
|
2718
2722
|
/** 页面字段扫描器,root 来自 SmartFill.create({ root }) */
|
|
2719
2723
|
d(this, "scanner");
|
|
2720
2724
|
/** 浏览器端本地规则引擎,用于文本正则/键值对提取 */
|
|
2721
|
-
d(this, "ruleEngine", new
|
|
2725
|
+
d(this, "ruleEngine", new Wr());
|
|
2722
2726
|
/** Shadow DOM 面板,mount / mountFloatingButton 后可用(指向最后挂载的面板,用于状态展示) */
|
|
2723
2727
|
d(this, "panel", null);
|
|
2724
2728
|
/** 已挂载的全部面板(inline / floating 可同时存在),用于本地优先开关广播与销毁 */
|
|
@@ -2747,7 +2751,7 @@ class _o {
|
|
|
2747
2751
|
d(this, "floatingLifecycleCleanup", null);
|
|
2748
2752
|
/** mount 后预扫描定时器 */
|
|
2749
2753
|
d(this, "preScanTimer", null);
|
|
2750
|
-
this.config = t, this.context = n, this.scanner = new
|
|
2754
|
+
this.config = t, this.context = n, this.scanner = new ao(t.root || document), this.localPriorityEnabled = Jo(), this.context.manager.add(this);
|
|
2751
2755
|
}
|
|
2752
2756
|
/** 订阅实例事件,返回取消订阅函数 */
|
|
2753
2757
|
on(t, n) {
|
|
@@ -2783,13 +2787,13 @@ class _o {
|
|
|
2783
2787
|
const n = typeof t == "string" ? document.querySelector(t) : t;
|
|
2784
2788
|
if (!n)
|
|
2785
2789
|
throw v("UNSUPPORTED_PAGE", "未找到智能录入挂载点。", "ui");
|
|
2786
|
-
const r = gt("inline",
|
|
2790
|
+
const r = gt("inline", Zo(t, n)), o = yt(r, !0);
|
|
2787
2791
|
return this.createPanel("inline", r, o).mount(n), this.schedulePreScan(), this;
|
|
2788
2792
|
}
|
|
2789
2793
|
/** 挂载右下角悬浮按钮 + 弹框(floating 模式),优先挂到当前子路由页面顶层容器 */
|
|
2790
2794
|
mountFloatingButton() {
|
|
2791
2795
|
this.assertAlive();
|
|
2792
|
-
const t =
|
|
2796
|
+
const t = zo(this.config), n = gt("floating"), r = yt(n, !0);
|
|
2793
2797
|
return this.createPanel("floating", n, r).mount(t), this.bindFloatingLifecycle(t), this.schedulePreScan(), this;
|
|
2794
2798
|
}
|
|
2795
2799
|
/**
|
|
@@ -2798,7 +2802,7 @@ class _o {
|
|
|
2798
2802
|
*/
|
|
2799
2803
|
createPanel(t, n, r) {
|
|
2800
2804
|
let o;
|
|
2801
|
-
return o = new
|
|
2805
|
+
return o = new So({
|
|
2802
2806
|
mode: t,
|
|
2803
2807
|
initialOpen: r,
|
|
2804
2808
|
messages: this.config.messages,
|
|
@@ -2811,7 +2815,7 @@ class _o {
|
|
|
2811
2815
|
}
|
|
2812
2816
|
/** 同步本地优先开关:更新内存态、写入 localStorage,并广播到其他已挂载面板 */
|
|
2813
2817
|
handleLocalPriorityChange(t, n) {
|
|
2814
|
-
this.localPriorityEnabled = t,
|
|
2818
|
+
this.localPriorityEnabled = t, Qo(t);
|
|
2815
2819
|
for (const r of this.panels)
|
|
2816
2820
|
r !== n && r.setLocalPriorityEnabled(t);
|
|
2817
2821
|
}
|
|
@@ -2861,7 +2865,7 @@ class _o {
|
|
|
2861
2865
|
this.destroyed || !this.panels.length || (this.preScanTimer != null && window.clearTimeout(this.preScanTimer), this.preScanTimer = window.setTimeout(() => {
|
|
2862
2866
|
this.preScanTimer = null, !(this.destroyed || this.scanResult) && this.preScan().catch(() => {
|
|
2863
2867
|
});
|
|
2864
|
-
},
|
|
2868
|
+
}, Ao));
|
|
2865
2869
|
}
|
|
2866
2870
|
cancelPreScan() {
|
|
2867
2871
|
this.preScanTimer != null && (window.clearTimeout(this.preScanTimer), this.preScanTimer = null);
|
|
@@ -2882,7 +2886,7 @@ class _o {
|
|
|
2882
2886
|
const n = await this.rescan(), r = xe("trace"), o = performance.now();
|
|
2883
2887
|
this.events.emit("recognizing", { scanToken: n.scanToken, traceId: r }), (a = this.panel) == null || a.setBusy(!0, "识别中...");
|
|
2884
2888
|
try {
|
|
2885
|
-
const p = n.fields.filter((m) =>
|
|
2889
|
+
const p = n.fields.filter((m) => Oo(m.localRuleMode, this.localPriorityEnabled)), h = n.fields.filter((m) => m.localRuleMode !== "only"), { text: y, usedOcr: x } = await this.context.client.resolveInputText({
|
|
2886
2890
|
text: t.text,
|
|
2887
2891
|
images: t.images,
|
|
2888
2892
|
onStatusChange: (m) => {
|
|
@@ -2916,7 +2920,7 @@ class _o {
|
|
|
2916
2920
|
}
|
|
2917
2921
|
});
|
|
2918
2922
|
m.trace.durationMs = m.trace.durationMs || Math.round(performance.now() - o);
|
|
2919
|
-
const se =
|
|
2923
|
+
const se = Ro(
|
|
2920
2924
|
ie,
|
|
2921
2925
|
m.suggestions.filter((O) => h.some((ae) => ae.fieldId === O.fieldId))
|
|
2922
2926
|
);
|
|
@@ -2933,14 +2937,14 @@ class _o {
|
|
|
2933
2937
|
x
|
|
2934
2938
|
);
|
|
2935
2939
|
}
|
|
2936
|
-
if (this.autoApplyState =
|
|
2940
|
+
if (this.autoApplyState = Io(
|
|
2937
2941
|
_.scanToken,
|
|
2938
2942
|
_.trace.traceId,
|
|
2939
2943
|
_.suggestions,
|
|
2940
2944
|
n,
|
|
2941
2945
|
this.registeredFields
|
|
2942
2946
|
), this.events.emit("recognized", _), (c = this.panel) == null || c.setAutoApplyState(this.autoApplyState), this.config.apiEnable) {
|
|
2943
|
-
const m =
|
|
2947
|
+
const m = Lo(_, this.autoApplyState, n);
|
|
2944
2948
|
this.config.apiCallback && await Promise.resolve(this.config.apiCallback(m)), (l = this.panel) == null || l.setStatus(`识别完成,已返回 ${m.fields.length} 个字段。`);
|
|
2945
2949
|
} else
|
|
2946
2950
|
await this.applyAutoItems(this.autoApplyState);
|
|
@@ -2972,7 +2976,7 @@ class _o {
|
|
|
2972
2976
|
var a, c;
|
|
2973
2977
|
if (!this.scanResult)
|
|
2974
2978
|
throw v("SCAN_TOKEN_EXPIRED", "请先扫描字段后再回填。", "apply");
|
|
2975
|
-
const n =
|
|
2979
|
+
const n = Mo(t), r = t.items.filter((l) => sn(l)).map((l) => ({ fieldId: l.fieldId, value: l.value, source: l.source }));
|
|
2976
2980
|
this.events.emit("applying", { scanToken: t.scanToken, count: r.length }), (a = this.panel) == null || a.setStatus("识别完成,正在自动回填...");
|
|
2977
2981
|
const i = await new at(this.scanResult.fields, this.registeredFields, this.adapters).apply({ scanToken: t.scanToken, values: r }), s = {
|
|
2978
2982
|
...i,
|
|
@@ -3006,7 +3010,7 @@ class _o {
|
|
|
3006
3010
|
if (!n) return null;
|
|
3007
3011
|
const r = U.get(n);
|
|
3008
3012
|
if (r && (!t || r.dynamicOptionsReady)) {
|
|
3009
|
-
const i =
|
|
3013
|
+
const i = qo(r.scanResult);
|
|
3010
3014
|
if (!i)
|
|
3011
3015
|
U.delete(n);
|
|
3012
3016
|
else
|
|
@@ -3025,10 +3029,10 @@ class _o {
|
|
|
3025
3029
|
}), this.persistPageScanResult(t, (o == null ? void 0 : o.dynamicOptionsReady) || n));
|
|
3026
3030
|
}
|
|
3027
3031
|
getPageScanCacheKey() {
|
|
3028
|
-
return this.registeredFields.length ? null :
|
|
3032
|
+
return this.registeredFields.length ? null : No(this.config);
|
|
3029
3033
|
}
|
|
3030
3034
|
getSessionPageScanCacheKey() {
|
|
3031
|
-
return this.registeredFields.length || !this.config.formCode ? null :
|
|
3035
|
+
return this.registeredFields.length || !this.config.formCode ? null : Ho(this.config);
|
|
3032
3036
|
}
|
|
3033
3037
|
clearScanStateOnTokenExpired(t) {
|
|
3034
3038
|
it(t, "recognize").code === "TOKEN_EXPIRED" && (on(), this.scanCacheVersion = j, this.scanResult = null, this.autoApplyState = null);
|
|
@@ -3039,9 +3043,9 @@ class _o {
|
|
|
3039
3043
|
getPersistedPageScanResult(t) {
|
|
3040
3044
|
const n = this.getSessionPageScanCacheKey();
|
|
3041
3045
|
if (!n) return null;
|
|
3042
|
-
const r =
|
|
3046
|
+
const r = Wo(n);
|
|
3043
3047
|
if (!r || t && !r.dynamicOptionsReady) return null;
|
|
3044
|
-
const o = this.scanner.scan({ maxFields: this.config.maxFields }), i =
|
|
3048
|
+
const o = this.scanner.scan({ maxFields: this.config.maxFields }), i = Do(r, o);
|
|
3045
3049
|
return i ? {
|
|
3046
3050
|
scanResult: i,
|
|
3047
3051
|
dynamicOptionsReady: r.dynamicOptionsReady
|
|
@@ -3049,14 +3053,14 @@ class _o {
|
|
|
3049
3053
|
}
|
|
3050
3054
|
persistPageScanResult(t, n) {
|
|
3051
3055
|
const r = this.getSessionPageScanCacheKey();
|
|
3052
|
-
!r || !t.fields.length ||
|
|
3056
|
+
!r || !t.fields.length || Xo(r, {
|
|
3053
3057
|
version: 1,
|
|
3054
3058
|
dynamicOptionsReady: n,
|
|
3055
3059
|
fields: t.fields.map(({ element: o, scanToken: i, ...s }) => s)
|
|
3056
3060
|
});
|
|
3057
3061
|
}
|
|
3058
3062
|
bindFloatingLifecycle(t) {
|
|
3059
|
-
this.clearFloatingLifecycle(), this.floatingRouteSnapshot = ht(),
|
|
3063
|
+
this.clearFloatingLifecycle(), this.floatingRouteSnapshot = ht(), $o();
|
|
3060
3064
|
const n = () => {
|
|
3061
3065
|
this.destroyed || ht() !== this.floatingRouteSnapshot && this.destroy();
|
|
3062
3066
|
};
|
|
@@ -3073,7 +3077,7 @@ class _o {
|
|
|
3073
3077
|
(t = this.floatingLifecycleCleanup) == null || t.call(this);
|
|
3074
3078
|
}
|
|
3075
3079
|
}
|
|
3076
|
-
function
|
|
3080
|
+
function Lo(e, t, n) {
|
|
3077
3081
|
return {
|
|
3078
3082
|
scanToken: e.scanToken,
|
|
3079
3083
|
trace: e.trace,
|
|
@@ -3094,12 +3098,12 @@ function Ao(e, t, n) {
|
|
|
3094
3098
|
})
|
|
3095
3099
|
};
|
|
3096
3100
|
}
|
|
3097
|
-
function
|
|
3101
|
+
function Io(e, t, n, r, o) {
|
|
3098
3102
|
return {
|
|
3099
3103
|
scanToken: e,
|
|
3100
3104
|
traceId: t,
|
|
3101
3105
|
items: n.map((i) => {
|
|
3102
|
-
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() :
|
|
3106
|
+
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() : Fo(s == null ? void 0 : s.element);
|
|
3103
3107
|
return {
|
|
3104
3108
|
applyItemId: `${i.fieldId}_${Math.random().toString(36).slice(2, 8)}`,
|
|
3105
3109
|
fieldId: i.fieldId,
|
|
@@ -3119,9 +3123,9 @@ function Co(e, t, n, r, o) {
|
|
|
3119
3123
|
}
|
|
3120
3124
|
function sn(e) {
|
|
3121
3125
|
var t;
|
|
3122
|
-
return e.confidence >=
|
|
3126
|
+
return e.confidence >= _o && !((t = e.warnings) != null && t.length);
|
|
3123
3127
|
}
|
|
3124
|
-
function
|
|
3128
|
+
function Mo(e) {
|
|
3125
3129
|
return e.items.filter((t) => !sn(t)).map((t) => {
|
|
3126
3130
|
var n, r;
|
|
3127
3131
|
return {
|
|
@@ -3133,7 +3137,7 @@ function To(e) {
|
|
|
3133
3137
|
};
|
|
3134
3138
|
});
|
|
3135
3139
|
}
|
|
3136
|
-
function
|
|
3140
|
+
function Ro(e, t) {
|
|
3137
3141
|
const n = /* @__PURE__ */ new Map();
|
|
3138
3142
|
for (const r of t)
|
|
3139
3143
|
n.set(r.fieldId, r);
|
|
@@ -3141,7 +3145,7 @@ function Lo(e, t) {
|
|
|
3141
3145
|
n.has(r.fieldId) || n.set(r.fieldId, r);
|
|
3142
3146
|
return [...n.values()];
|
|
3143
3147
|
}
|
|
3144
|
-
function
|
|
3148
|
+
function Oo(e, t) {
|
|
3145
3149
|
return e === "only" ? !0 : e === "off" ? !1 : t;
|
|
3146
3150
|
}
|
|
3147
3151
|
function ft(e, t, n, r, o, i = !1) {
|
|
@@ -3157,15 +3161,15 @@ function ft(e, t, n, r, o, i = !1) {
|
|
|
3157
3161
|
}
|
|
3158
3162
|
};
|
|
3159
3163
|
}
|
|
3160
|
-
function
|
|
3164
|
+
function Fo(e) {
|
|
3161
3165
|
if (e)
|
|
3162
3166
|
return e instanceof HTMLInputElement && e.type === "checkbox" ? e.checked : e instanceof HTMLInputElement || e instanceof HTMLTextAreaElement || e instanceof HTMLSelectElement ? e.value : e.textContent;
|
|
3163
3167
|
}
|
|
3164
|
-
function
|
|
3168
|
+
function qo(e) {
|
|
3165
3169
|
const t = e.fields.map((n) => {
|
|
3166
3170
|
if (n.source === "registered")
|
|
3167
3171
|
return n;
|
|
3168
|
-
const r =
|
|
3172
|
+
const r = Po(n);
|
|
3169
3173
|
return r ? { ...n, element: r } : null;
|
|
3170
3174
|
});
|
|
3171
3175
|
return t.some((n) => !n) ? null : {
|
|
@@ -3173,7 +3177,7 @@ function Ro(e) {
|
|
|
3173
3177
|
fields: t
|
|
3174
3178
|
};
|
|
3175
3179
|
}
|
|
3176
|
-
function
|
|
3180
|
+
function Do(e, t) {
|
|
3177
3181
|
var s, a;
|
|
3178
3182
|
const n = new Map(t.fields.map((c) => [c.fieldId, c])), r = [], o = /* @__PURE__ */ new Set();
|
|
3179
3183
|
for (const c of e.fields) {
|
|
@@ -3205,20 +3209,20 @@ function Oo(e, t) {
|
|
|
3205
3209
|
fields: [...r, ...i]
|
|
3206
3210
|
};
|
|
3207
3211
|
}
|
|
3208
|
-
function
|
|
3212
|
+
function Po(e) {
|
|
3209
3213
|
var t;
|
|
3210
3214
|
if ((t = e.element) != null && t.isConnected) return e.element;
|
|
3211
3215
|
try {
|
|
3212
|
-
return document.querySelector(`[data-smart-fill-id="${
|
|
3216
|
+
return document.querySelector(`[data-smart-fill-id="${ei(e.fieldId)}"]`);
|
|
3213
3217
|
} catch {
|
|
3214
3218
|
return null;
|
|
3215
3219
|
}
|
|
3216
3220
|
}
|
|
3217
|
-
function
|
|
3221
|
+
function No(e) {
|
|
3218
3222
|
const t = typeof location < "u" ? `${location.origin}${location.pathname}${location.search}` : "unknown-page", n = an(e.root || document);
|
|
3219
3223
|
return `smart-fill:${t}:${e.formCode || "default-form"}:${n}:${e.maxFields ?? 200}:scan`;
|
|
3220
3224
|
}
|
|
3221
|
-
function
|
|
3225
|
+
function Ho(e) {
|
|
3222
3226
|
const t = an(e.root || document);
|
|
3223
3227
|
return `${rn}${e.formCode || "default-form"}:${t}:${e.maxFields ?? 200}`;
|
|
3224
3228
|
}
|
|
@@ -3226,10 +3230,10 @@ function an(e) {
|
|
|
3226
3230
|
if (e === document) return "document";
|
|
3227
3231
|
const t = dt.get(e);
|
|
3228
3232
|
if (t) return t;
|
|
3229
|
-
const n = e instanceof HTMLElement && e.id ? `el:${e.id}` : `root:${++
|
|
3233
|
+
const n = e instanceof HTMLElement && e.id ? `el:${e.id}` : `root:${++Co}`;
|
|
3230
3234
|
return dt.set(e, n), n;
|
|
3231
3235
|
}
|
|
3232
|
-
function
|
|
3236
|
+
function $o() {
|
|
3233
3237
|
if (ut || typeof window > "u") return;
|
|
3234
3238
|
ut = !0;
|
|
3235
3239
|
const e = () => {
|
|
@@ -3247,32 +3251,32 @@ function pt(e, t) {
|
|
|
3247
3251
|
function ht() {
|
|
3248
3252
|
return typeof location > "u" ? "unknown-route" : `${location.pathname}${location.search}${location.hash}`;
|
|
3249
3253
|
}
|
|
3250
|
-
function
|
|
3251
|
-
const t =
|
|
3254
|
+
function zo(e) {
|
|
3255
|
+
const t = Ko(e.floatingContainer);
|
|
3252
3256
|
if (t)
|
|
3253
3257
|
return t;
|
|
3254
|
-
const n =
|
|
3255
|
-
return n ||
|
|
3258
|
+
const n = Vo(e.routeContainerSelector);
|
|
3259
|
+
return n || Bo() || document.body;
|
|
3256
3260
|
}
|
|
3257
|
-
function
|
|
3261
|
+
function Ko(e) {
|
|
3258
3262
|
return e ? e instanceof HTMLElement ? e : Be(e) : null;
|
|
3259
3263
|
}
|
|
3260
|
-
function
|
|
3264
|
+
function Vo(e) {
|
|
3261
3265
|
if (!e) return null;
|
|
3262
3266
|
const t = cn(), n = t ? Be(e, t) : null;
|
|
3263
3267
|
return n || Be(e);
|
|
3264
3268
|
}
|
|
3265
|
-
function
|
|
3269
|
+
function Bo() {
|
|
3266
3270
|
const e = cn();
|
|
3267
3271
|
if (!e)
|
|
3268
3272
|
return null;
|
|
3269
|
-
const t =
|
|
3273
|
+
const t = Uo(e);
|
|
3270
3274
|
if (t)
|
|
3271
3275
|
return t;
|
|
3272
|
-
const n =
|
|
3276
|
+
const n = jo(e);
|
|
3273
3277
|
if (n)
|
|
3274
3278
|
return n;
|
|
3275
|
-
const r =
|
|
3279
|
+
const r = Go(e);
|
|
3276
3280
|
return r !== e ? r : null;
|
|
3277
3281
|
}
|
|
3278
3282
|
function cn() {
|
|
@@ -3294,11 +3298,11 @@ function cn() {
|
|
|
3294
3298
|
}
|
|
3295
3299
|
return null;
|
|
3296
3300
|
}
|
|
3297
|
-
function
|
|
3298
|
-
const t = S(e), n = ln(e).filter((o) => !We(o)).filter((o) => S(o) >= Math.max(t * 0.2, 48e3)), r = n.filter((o) =>
|
|
3301
|
+
function Uo(e) {
|
|
3302
|
+
const t = S(e), n = ln(e).filter((o) => !We(o)).filter((o) => S(o) >= Math.max(t * 0.2, 48e3)), r = n.filter((o) => Yo(o));
|
|
3299
3303
|
return r.length ? r.sort((o, i) => S(i) - S(o))[0] : n.length === 1 ? n[0] : null;
|
|
3300
3304
|
}
|
|
3301
|
-
function
|
|
3305
|
+
function jo(e) {
|
|
3302
3306
|
const t = [
|
|
3303
3307
|
"[data-route-root]",
|
|
3304
3308
|
"[data-router-view]",
|
|
@@ -3317,7 +3321,7 @@ function Vo(e) {
|
|
|
3317
3321
|
], n = un(e), r = S(e);
|
|
3318
3322
|
return t.flatMap((i) => Array.from(e.querySelectorAll(i))).filter((i) => Ae(i) && !We(i)).filter((i) => Re(i, n) <= 3).filter((i) => S(i) >= Math.max(r * 0.2, 48e3)).sort((i, s) => Re(i, n) - Re(s, n) || S(s) - S(i))[0] || null;
|
|
3319
3323
|
}
|
|
3320
|
-
function
|
|
3324
|
+
function Go(e) {
|
|
3321
3325
|
let t = e;
|
|
3322
3326
|
for (; ; ) {
|
|
3323
3327
|
const n = ln(t).filter((o) => !We(o));
|
|
@@ -3351,7 +3355,7 @@ function We(e) {
|
|
|
3351
3355
|
const t = window.getComputedStyle(e);
|
|
3352
3356
|
return t.position === "fixed" || t.position === "sticky" ? !0 : S(e) < 24e3;
|
|
3353
3357
|
}
|
|
3354
|
-
function
|
|
3358
|
+
function Yo(e) {
|
|
3355
3359
|
if (e.tagName.toLowerCase() === "main" || e.getAttribute("role") === "main")
|
|
3356
3360
|
return !0;
|
|
3357
3361
|
const t = e.id || "", n = typeof e.className == "string" ? e.className : "", r = `${t} ${n}`.toLowerCase();
|
|
@@ -3370,7 +3374,7 @@ function un(e) {
|
|
|
3370
3374
|
function Re(e, t) {
|
|
3371
3375
|
return Math.max(0, un(e) - t);
|
|
3372
3376
|
}
|
|
3373
|
-
function
|
|
3377
|
+
function Wo(e) {
|
|
3374
3378
|
try {
|
|
3375
3379
|
const t = window.sessionStorage.getItem(e);
|
|
3376
3380
|
if (!t) return null;
|
|
@@ -3380,7 +3384,7 @@ function jo(e) {
|
|
|
3380
3384
|
return null;
|
|
3381
3385
|
}
|
|
3382
3386
|
}
|
|
3383
|
-
function
|
|
3387
|
+
function Xo(e, t) {
|
|
3384
3388
|
try {
|
|
3385
3389
|
window.sessionStorage.setItem(e, JSON.stringify(t));
|
|
3386
3390
|
} catch {
|
|
@@ -3406,7 +3410,7 @@ function gt(e, t = "default") {
|
|
|
3406
3410
|
const n = typeof location < "u" ? location.pathname : "unknown-page", r = t.replace(/[^\w-]/g, "_") || "default";
|
|
3407
3411
|
return `smart-fill:${e}:${n}:${r}:open`;
|
|
3408
3412
|
}
|
|
3409
|
-
function
|
|
3413
|
+
function Zo(e, t) {
|
|
3410
3414
|
if (typeof e == "string") return e;
|
|
3411
3415
|
if (t.id) return `#${t.id}`;
|
|
3412
3416
|
const n = typeof t.className == "string" ? t.className.trim().split(/\s+/).filter(Boolean)[0] : "";
|
|
@@ -3430,34 +3434,34 @@ function bt(e, t) {
|
|
|
3430
3434
|
function fn() {
|
|
3431
3435
|
return `smart-fill:${typeof location < "u" ? location.pathname : "unknown-page"}:local-priority`;
|
|
3432
3436
|
}
|
|
3433
|
-
function
|
|
3437
|
+
function Jo() {
|
|
3434
3438
|
try {
|
|
3435
3439
|
return window.localStorage.getItem(fn()) === "1";
|
|
3436
3440
|
} catch {
|
|
3437
3441
|
return !1;
|
|
3438
3442
|
}
|
|
3439
3443
|
}
|
|
3440
|
-
function
|
|
3444
|
+
function Qo(e) {
|
|
3441
3445
|
try {
|
|
3442
3446
|
window.localStorage.setItem(fn(), e ? "1" : "0");
|
|
3443
3447
|
} catch {
|
|
3444
3448
|
}
|
|
3445
3449
|
}
|
|
3446
|
-
function
|
|
3450
|
+
function ei(e) {
|
|
3447
3451
|
return typeof CSS < "u" && CSS.escape ? CSS.escape(e) : e.replace(/["\\]/g, "\\$&");
|
|
3448
3452
|
}
|
|
3449
|
-
const g = { status: "idle" }, Oe = new Xt(), mt = new
|
|
3450
|
-
class
|
|
3453
|
+
const g = { status: "idle" }, Oe = new Xt(), mt = new Pr();
|
|
3454
|
+
class ti {
|
|
3451
3455
|
/** 初始化 SDK:校验 apiKey、创建会话、获取 accessToken */
|
|
3452
3456
|
static async setup(t) {
|
|
3453
3457
|
if (typeof window > "u")
|
|
3454
|
-
return g.status = "ready",
|
|
3458
|
+
return g.status = "ready", ni();
|
|
3455
3459
|
if (g.status === "ready" && g.apiKey === t.apiKey && g.session)
|
|
3456
3460
|
return g.session;
|
|
3457
3461
|
if (g.status === "loading" && g.apiKey === t.apiKey && g.promise)
|
|
3458
3462
|
return g.promise;
|
|
3459
3463
|
g.apiKey && g.apiKey !== t.apiKey && (on(), mt.destroyAll());
|
|
3460
|
-
const n = new
|
|
3464
|
+
const n = new Mr(t);
|
|
3461
3465
|
return g.status = "loading", g.apiKey = t.apiKey, g.client = n, g.promise = n.createSession().then((r) => (console.log("SmartFill session created:", r), n.setAccessToken(r.apiKey), g.status = "ready", g.session = r, Oe.emit("ready", { apiKey: t.apiKey }), r)).catch((r) => {
|
|
3462
3466
|
throw g.status = "error", r;
|
|
3463
3467
|
}), g.promise;
|
|
@@ -3468,15 +3472,15 @@ class Jo {
|
|
|
3468
3472
|
return G();
|
|
3469
3473
|
if (g.status !== "ready" || !g.client)
|
|
3470
3474
|
throw v("SDK_NOT_READY", "请先 await SmartFill.setup({ apiKey })。", "setup");
|
|
3471
|
-
return new
|
|
3475
|
+
return new To(t, {
|
|
3472
3476
|
client: g.client,
|
|
3473
3477
|
manager: mt
|
|
3474
3478
|
});
|
|
3475
3479
|
}
|
|
3476
3480
|
}
|
|
3477
3481
|
/** 订阅全局事件(目前仅 ready) */
|
|
3478
|
-
d(
|
|
3479
|
-
function
|
|
3482
|
+
d(ti, "on", Oe.on.bind(Oe));
|
|
3483
|
+
function ni() {
|
|
3480
3484
|
return {
|
|
3481
3485
|
apiKey: "server-mock",
|
|
3482
3486
|
accessToken: "server-mock",
|
|
@@ -3513,14 +3517,18 @@ function G(e) {
|
|
|
3513
3517
|
};
|
|
3514
3518
|
}
|
|
3515
3519
|
export {
|
|
3516
|
-
|
|
3520
|
+
Ir as DEFAULT_BASE_URL,
|
|
3517
3521
|
at as DomFiller,
|
|
3518
|
-
|
|
3519
|
-
|
|
3522
|
+
ao as DomScanner,
|
|
3523
|
+
ii as ElementAdapter,
|
|
3520
3524
|
Xt as EventBus,
|
|
3521
|
-
|
|
3522
|
-
|
|
3523
|
-
|
|
3524
|
-
|
|
3525
|
-
|
|
3525
|
+
Wr as LocalRuleEngine,
|
|
3526
|
+
oi as NativeAdapter,
|
|
3527
|
+
ti as SmartFill,
|
|
3528
|
+
Wt as SmartFillException,
|
|
3529
|
+
To as SmartFillInstance,
|
|
3530
|
+
Yt as UiFrameworkAdapter,
|
|
3531
|
+
v as createError,
|
|
3532
|
+
xe as createTraceId,
|
|
3533
|
+
it as toSmartFillError
|
|
3526
3534
|
};
|