@kc-one/smart-fill-sdk 0.0.5 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.umd.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(h,m){typeof exports=="object"&&typeof module<"u"?m(exports):typeof define=="function"&&define.amd?define(["exports"],m):(h=typeof globalThis<"u"?globalThis:h||self,m(h.SmartFillSDK={}))})(this,function(h){"use strict";var Ao=Object.defineProperty;var To=(h,m,I)=>m in h?Ao(h,m,{enumerable:!0,configurable:!0,writable:!0,value:I}):h[m]=I;var d=(h,m,I)=>To(h,typeof m!="symbol"?m+"":m,I);const m={name:"native",match:e=>e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement||e instanceof HTMLSelectElement,getValue:e=>{const t=e.element;if(t instanceof HTMLInputElement&&t.type==="checkbox")return t.checked;if(t instanceof HTMLInputElement||t instanceof HTMLTextAreaElement||t instanceof HTMLSelectElement)return t.value},setValue:(e,t)=>{const n=e.element;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}))}},I=[{framework:"element",selectors:".el-select,.el-select-v2",type:"select",kind:"input"},{framework:"element",selectors:".el-cascader",type:"cascader",kind:"input"},{framework:"element",selectors:".el-date-editor,.el-time-picker",type:"date",kind:"input"},{framework:"element",selectors:".el-input-number",type:"number",kind:"input"},{framework:"element",selectors:".el-switch",type:"checkbox",kind:"switch"},{framework:"element",selectors:".el-radio-group",type:"radio",kind:"radioGroup",optionSelector:'.el-radio,[role="radio"],input[type="radio"]'},{framework:"element",selectors:".el-checkbox-group",type:"checkbox",kind:"checkboxGroup",optionSelector:'.el-checkbox,[role="checkbox"],input[type="checkbox"]'},{framework:"antd",selectors:".ant-select",type:"select",kind:"input"},{framework:"antd",selectors:".ant-cascader",type:"cascader",kind:"input"},{framework:"antd",selectors:".ant-picker",type:"date",kind:"input"},{framework:"antd",selectors:".ant-input-number",type:"number",kind:"input"},{framework:"antd",selectors:".ant-switch",type:"checkbox",kind:"switch"},{framework:"antd",selectors:".ant-radio-group",type:"radio",kind:"radioGroup",optionSelector:'.ant-radio-button,.ant-radio-wrapper,.ant-radio,[role="radio"],input[type="radio"]'},{framework:"antd",selectors:".ant-checkbox-group",type:"checkbox",kind:"checkboxGroup",optionSelector:'.ant-checkbox-wrapper,.ant-checkbox,[role="checkbox"],input[type="checkbox"]'},{framework:"naive",selectors:".n-select",type:"select",kind:"input"},{framework:"naive",selectors:".n-cascader",type:"cascader",kind:"input"},{framework:"naive",selectors:".n-date-picker,.n-time-picker",type:"date",kind:"input"},{framework:"naive",selectors:".n-input-number",type:"number",kind:"input"},{framework:"naive",selectors:".n-switch",type:"checkbox",kind:"switch"},{framework:"naive",selectors:".n-radio-group",type:"radio",kind:"radioGroup",optionSelector:'.n-radio,[role="radio"],input[type="radio"]'},{framework:"naive",selectors:".n-checkbox-group",type:"checkbox",kind:"checkboxGroup",optionSelector:'.n-checkbox,[role="checkbox"],input[type="checkbox"]'},{framework:"arco",selectors:".arco-select",type:"select",kind:"input"},{framework:"arco",selectors:".arco-cascader",type:"cascader",kind:"input"},{framework:"arco",selectors:".arco-picker",type:"date",kind:"input"},{framework:"arco",selectors:".arco-input-number",type:"number",kind:"input"},{framework:"arco",selectors:".arco-switch",type:"checkbox",kind:"switch"},{framework:"arco",selectors:".arco-radio-group",type:"radio",kind:"radioGroup",optionSelector:'.arco-radio,[role="radio"],input[type="radio"]'},{framework:"arco",selectors:".arco-checkbox-group",type:"checkbox",kind:"checkboxGroup",optionSelector:'.arco-checkbox,[role="checkbox"],input[type="checkbox"]'},{framework:"vant",selectors:".van-dropdown-menu",type:"select",kind:"input"},{framework:"vant",selectors:".van-cascader",type:"cascader",kind:"input"},{framework:"vant",selectors:".van-stepper",type:"number",kind:"input"},{framework:"vant",selectors:".van-field--picker",type:"date",kind:"input"},{framework:"vant",selectors:".van-search",type:"text",kind:"input"},{framework:"vant",selectors:".van-field",type:"text",kind:"input"},{framework:"vant",selectors:".van-switch",type:"checkbox",kind:"switch"},{framework:"vant",selectors:".van-radio-group",type:"radio",kind:"radioGroup",optionSelector:'.van-radio,[role="radio"],input[type="radio"]'},{framework:"vant",selectors:".van-checkbox-group",type:"checkbox",kind:"checkboxGroup",optionSelector:'.van-checkbox,[role="checkbox"],input[type="checkbox"]'},{framework:"generic",selectors:'[role="combobox"]',type:"select",kind:"input"}],tn=["is-disabled","ant-select-disabled","n-select--disabled","arco-select-disabled","van-field--disabled","van-switch--disabled","van-stepper--disabled","van-dropdown-menu--disabled"],We=I.map(e=>e.selectors).join(", "),nn=[".form-item",".ant-form-item",".el-form-item",".n-form-item",".arco-form-item",".van-cell",".van-field",".field",".form-row"].join(", "),rn=["label",".ant-form-item-label",".el-form-item__label",".n-form-item-label",".arco-form-item-label",".van-field__label",".label"].join(", "),Xe=["dialog[open]","[role='dialog']","[aria-modal='true']",".modal",".modal-dialog",".ant-modal",".ant-drawer",".el-dialog",".el-drawer",".n-modal",".n-dialog",".arco-modal",".arco-drawer",".van-popup",".van-dialog",".van-action-sheet",".popup",".drawer"].join(", "),on=["is-checked","ant-switch-checked","n-switch--active","arco-switch-checked","van-switch--on","van-radio--checked","van-checkbox--checked"];function D(e){return I.find(t=>e.matches(t.selectors))||null}function Ze(e){return!!D(e)}function xe(e){for(let t=e;t;t=t.parentElement)if(Ze(t))return t;return null}function te(e){var n;const t=D(e);if(!t)return null;if(e.matches(".van-field")){if(e.querySelector("textarea"))return"textarea";if(e.classList.contains("van-field--picker"))return"date";if(e.querySelector(".van-dropdown-menu"))return"select";const r=e.querySelector("input");if(r&&(r.readOnly||r.hasAttribute("readonly"))){const o=(r.getAttribute("placeholder")||"").trim();if(!o||/选择|select/i.test(o))return"select"}if(e.classList.contains("van-field--clickable")){const o=p(((n=e.querySelector(".van-field__control"))==null?void 0:n.textContent)||"");if(!e.querySelector("textarea")&&(o==="请选择"||o===""))return"select"}}return t.type}function Je(e){const t=D(e);if(t!=null&&t.optionSelector)return Array.from(e.querySelectorAll(t.optionSelector)).map(n=>sn(n)).filter(n=>!!(n.label||n.value))}function sn(e){const t=e instanceof HTMLInputElement?e:e.querySelector('input[type="radio"],input[type="checkbox"]'),n=p(e.textContent||e.getAttribute("aria-label")||e.getAttribute("title")||""),r=e.getAttribute("value")||(t==null?void 0:t.value)||n;return{label:n,value:r}}function N(e){return on.some(t=>e.classList.contains(t))||e.getAttribute("aria-checked")==="true"||!!e.querySelector("input:checked")}function q(e){return e.querySelector('input:not([type="hidden"]), textarea')}function Qe(e){var t,n,r;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"))}function p(e){return e.replace(/[*::]/g,"").replace(/\s+/g," ").trim()}const ke="data-smart-fill-hide-dropdown-mode",et="smart-fill-hide-dropdown-style",tt=["[role='combobox']","[aria-haspopup='listbox']",".el-cascader",".ant-cascader",".arco-cascader",".ant-select",".el-select",".el-select-v2",".el-select__wrapper",".el-select-v2__wrapper",".n-select",".n-base-selection",".ivu-select",".arco-select",".semi-select",".t-select",".select-trigger",".select__wrapper",".van-dropdown-menu",".van-dropdown-menu__bar",".van-field--picker",".van-field--clickable"].join(", "),an=[".ant-select-selection-item",".el-select__selected-item",".el-select-v2__selected-item",".el-select-v2-selected-item",".el-select__placeholder",".el-select-v2__placeholder",".el-select-selected-value",".n-base-selection-label",".ivu-select-selected-value",".arco-select-view-value",".semi-select-selection-text",".t-input__inner",".select-value",".selection-item",".van-field__control"].join(", "),_e=["[role='option']",".ant-select-item-option",".el-select-dropdown__item",".el-select-v2__option",".n-base-select-option",".ivu-select-item",".arco-select-option",".semi-select-option",".t-select-option",".van-picker-column__item",".van-action-sheet__item"].join(", "),ne=[_e,".van-action-sheet__name",".van-cascader__option",".van-dropdown-item__option",".van-picker-column__item--selected",".el-cascader-node",".ant-cascader-menu-item",".n-cascader-node",".arco-cascader-option"].join(", "),Ce=[".el-select-dropdown",".el-cascader__dropdown",".el-cascader-panel",".el-select__popper",".el-select-v2__popper",".el-popper.el-cascader__dropdown",".el-popper.el-select__popper",".el-popper.el-select-v2__popper",".el-popper",".ant-select-dropdown",".ant-cascader-menus",".n-base-select-menu",".n-cascader-menu",".arco-select-dropdown",".arco-cascader-panel",".semi-select-dropdown",".t-select__dropdown",".van-popup",".van-action-sheet",".van-dropdown-item__content",".van-dropdown-item",".van-picker","[role='listbox']"].join(", "),nt=[".el-select-dropdown",".el-select__popper",".el-select-v2__popper",".el-popper.el-select__popper",".el-popper.el-select-v2__popper",".ant-select-dropdown",".n-base-select-menu",".arco-select-dropdown",".semi-select-dropdown",".t-select__dropdown",".van-popup",".van-action-sheet",".van-dropdown-item__content",".van-dropdown-item",".van-picker","[role='listbox']"].join(", "),rt=[".el-cascader__dropdown",".el-cascader-panel",".el-popper.el-cascader__dropdown",".ant-cascader-menus",".n-cascader-menu",".arco-cascader-panel",".van-cascader",".van-cascader__options"].join(", "),cn=/(?:省|市|自治区|特别行政区|自治州|地区|盟|县|区)$/,ln=/地址|省|市|区|县|地区|籍贯|户籍|居住地|所在地|区域/,un=new Set(["select","cascader","date"]);function _(e){return!ht(e)||st(e)?!1:!!e.closest(".el-cascader, .ant-cascader, .van-cascader, .n-cascader, .arco-cascader")}function E(e){var n;if(!e.matches(".van-field"))return!1;if(e.classList.contains("van-field--picker")||e.querySelector(".van-dropdown-menu"))return!0;const t=e.querySelector("input");if(t&&(t.readOnly||t.hasAttribute("readonly"))){const r=(t.getAttribute("placeholder")||"").trim();if(!r||/选择|select/i.test(r))return!0}if(e.classList.contains("van-field--clickable")){const r=p(((n=e.querySelector(".van-field__control"))==null?void 0:n.textContent)||"");if(!e.querySelector("textarea")&&(r==="请选择"||r===""))return!0}return!1}function V(e){return!ht(e)||st(e)||e instanceof HTMLSelectElement||e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement?!1:e.matches(tt)||e.getAttribute("role")==="combobox"||e.getAttribute("aria-haspopup")==="listbox"||e.classList.contains("el-select__wrapper")||e.classList.contains("el-select-v2__wrapper")||E(e)}function K(e){const t=e.closest(".el-cascader, .ant-cascader, .van-cascader, .n-cascader, .arco-cascader");if(t instanceof HTMLElement)return t;const n=e.closest([".el-date-editor",".el-time-picker",".el-date-picker",".el-date-picker-panel",".el-select",".el-select-v2",".ant-picker",".ant-select",".n-date-picker",".n-time-picker",".n-select",".ivu-select",".arco-picker",".arco-select",".semi-select",".t-select",".van-field",".van-dropdown-menu",".van-dropdown-menu__bar","[role='combobox']","[aria-haspopup='listbox']",".select-trigger",".select__wrapper",".el-select__wrapper",".el-select-v2__wrapper"].join(", "));return n instanceof HTMLElement?n.matches(".van-field")&&!E(n)?null:n:V(e)?e:null}function Ae(e){if(e instanceof HTMLSelectElement)return e;if(_(e))return e.closest(".el-cascader, .ant-cascader, .van-cascader, .n-cascader, .arco-cascader")||e;const t=K(e);return t||(e.matches(".van-field")&&E(e)?e:null)}function ot(e){if(_(e))return"cascader";if(V(e)||E(e))return"select";const t=te(e);return t||(e instanceof HTMLSelectElement?"select":null)}function Te(e,t){const n=t||ot(e);return n!=null&&un.has(n)}function dn(e){const t=e.matches(".van-field")?e:e.closest(".van-field");if(t instanceof HTMLElement&&E(t)){const i=t.querySelector(".van-field__control");if(i instanceof HTMLInputElement)return p(i.value);const s=p((i==null?void 0:i.textContent)||"");return s&&s!=="请选择"?s:""}const n=e.querySelector(an);if(n instanceof HTMLInputElement)return p(n.value);const r=p((n==null?void 0:n.textContent)||"");if(r&&r!=="请选择")return r;const o=e.querySelector('input:not([type="hidden"])');return o!=null&&o.value?p(o.value):r}function it(e){const t=mn(e);if(!t.length)return;const n=wn(t);return n.length?n:void 0}function re(e){var t;return!((t=e.options)!=null&&t.length)||e.type==="cascader"||ln.test(e.label||"")?!1:_n(e.options)}async function pn(e){if(e instanceof HTMLSelectElement)return Array.from(e.options).map(s=>({value:s.value,label:p(s.textContent||s.label)})).filter(s=>s.label||s.value);const t=it(e);if(t!=null&&t.length)return t;const n=K(e)||e;if(!V(n)&&!_(n)&&!E(n))return;const r=Ln(),o=Cn(),i=new Set(o.getTrackedDropdowns());try{if(!(_(n)?await hn(n,o,i):await fn(n,o,i)))return;const a=await yn(o,i,n);if(!a.length)return;const c=gn(a);return c.length?c:void 0}finally{await Tn(n,o),await M(60),o.restore(),r()}}function st(e){return e.hasAttribute("disabled")||e.getAttribute("aria-disabled")==="true"}async function fn(e,t,n){const r=z(e);if(!r.length)return!1;for(const o of r)if(pt(o),dt(o),await M(160),at(e,t,n)||(ft(o),await M(180),at(e,t,n)))return!0;return!1}async function hn(e,t,n){const r=[e,e.querySelector(".el-input__wrapper"),e.querySelector(".el-input"),e.querySelector(".van-field__control"),e.querySelector("input")].filter(o=>o instanceof HTMLElement);for(const o of r)if(pt(o),dt(o),await M(180),oe(t,n,e).length||(ft(o),await M(180),oe(t,n,e).length))return!0;return!1}function gn(e){var r;const t=new Set,n=[];for(const o of e){const i=o.matches(ne)?[o]:Array.from(o.querySelectorAll(ne));for(const s of i){if(s.classList.contains("is-disabled")||s.classList.contains("ant-select-item-option-disabled")||s.getAttribute("aria-disabled")==="true")continue;const a=p(((r=s.querySelector(".el-cascader-node__label, .ant-cascader-menu-item-content"))==null?void 0:r.textContent)||s.textContent||""),c=s.getAttribute("data-value")||s.getAttribute("value")||a;if(!a&&!c)continue;const l=`${a}::${String(c)}`;t.has(l)||(t.add(l),n.push({label:a,value:c}))}}return n}async function yn(e,t,n){for(let r=0;r<8;r+=1){const o=oe(e,t,n);if(o.length)return o;await M(r===0?120:80)}return[]}function at(e,t,n){return oe(t,n,e).length>0?!0:z(e).some(r=>r.getAttribute("aria-expanded")==="true"||r.classList.contains("is-focus")||r.classList.contains("is-focused"))}function bn(e,t,n){const r=t.filter(c=>Le(e,c)),o=r.filter(c=>vn(e,c)),i=o.filter(c=>!n.has(c));if(i.length)return i.sort((c,l)=>P(l,e)-P(c,e));const s=ct(e);if(s.size){const c=o.filter(l=>l.id&&s.has(l.id));if(c.length)return c}if(o.length)return o.sort((c,l)=>P(l,e)-P(c,e)).slice(0,1);const a=r.filter(c=>kn(c)&<(e)).sort((c,l)=>P(l,e)-P(c,e)).slice(0,1);return a.length?a:[]}function oe(e,t,n){return bn(n,e.getTrackedDropdowns(),t)}function P(e,t){const n=e.getBoundingClientRect(),r=Number.parseInt(window.getComputedStyle(e).zIndex||"0",10);let o=(Number.isNaN(r)?0:r)*10+n.width*n.height;return t&&(o+=ut(t,e)),o}function mn(e){const t=_(e)?rt:nt,n=new Set;e.matches(t)&&n.add(e);for(const r of e.querySelectorAll(t))Le(e,r)&&n.add(r);for(const r of e.querySelectorAll("[role='listbox']"))e.contains(r)&&Le(e,r)&&n.add(r);return[...n]}function wn(e){const t=new Set,n=[];for(const r of e){const o=r.matches(_e)?[r]:Array.from(r.querySelectorAll(_e));for(const i of o){if(i.classList.contains("is-disabled")||i.classList.contains("ant-select-item-option-disabled")||i.getAttribute("aria-disabled")==="true")continue;const s=p(i.textContent||""),a=i.getAttribute("data-value")||i.getAttribute("value")||s;if(!s&&!a)continue;const c=`${s}::${String(a)}`;t.has(c)||(t.add(c),n.push({label:s,value:a}))}}return n}function ct(e){return new Set(z(e).flatMap(t=>[t.getAttribute("aria-controls"),t.getAttribute("aria-owns")]).filter(t=>!!t))}function vn(e,t){const n=ct(e);return n.size&&t.id&&n.has(t.id)||e.contains(t)?!0:xn(t)?lt(e):n.size>0||z(e).some(o=>o.getAttribute("aria-controls")||o.getAttribute("aria-owns"))?!1:ut(e,t)>0}function Le(e,t){const n=_(e),r=Sn(t);return n?r:r?!1:En(t)}function Sn(e){return e.matches(rt)||!!e.querySelector(".el-cascader-node, .ant-cascader-menu-item, .van-cascader__option, .n-cascader-node, .arco-cascader-option")}function En(e){return e.matches(nt)||!!e.querySelector('.el-select-dropdown__item, .ant-select-item-option, .van-picker-column__item, .van-action-sheet__item, .van-dropdown-item__option, [role="option"]')}function xn(e){return e.matches(".van-popup, .van-action-sheet, .van-picker, .van-dropdown-item__content, .van-dropdown-item")}function lt(e){return z(e).some(t=>t.getAttribute("aria-expanded")==="true"||t.classList.contains("is-focus")||t.classList.contains("is-focused")||e.contains(document.activeElement))}function kn(e){return e.matches(ne)||!!e.querySelector(ne)}function ut(e,t){const n=e.getBoundingClientRect(),r=t.getBoundingClientRect();if(!n.width||!n.height||!r.width||!r.height)return 0;const o=Math.min(n.right,r.right)-Math.max(n.left,r.left);if(o<=0)return 0;const i=r.top>=n.bottom?r.top-n.bottom:n.top-r.bottom;return i>320?0:Math.max(0,400-i)+o}function _n(e){const t=e.slice(0,8).map(r=>p(String(r.label||r.value||""))).filter(Boolean);return t.length<4?!1:t.filter(r=>cn.test(r)).length/t.length>=.75}function z(e){return[e,e.querySelector(".van-field__control"),e.querySelector(".van-field__body"),e.querySelector(".van-dropdown-menu__bar"),e.querySelector(".el-select__wrapper"),e.querySelector(".el-select-v2__wrapper"),e.querySelector(".el-select__selection"),e.querySelector(".el-input__wrapper"),e.querySelector(".el-input"),e.querySelector("input"),e.querySelector("[role='combobox']"),e.querySelector("[aria-haspopup='listbox']"),e.querySelector(".ant-select-selector"),e.querySelector(".n-base-selection"),e.querySelector(".n-base-selection-label"),e.querySelector(".arco-select-view"),e.querySelector(".arco-cascader"),e.querySelector(".semi-select"),e.querySelector(".t-input"),e.querySelector(".select-trigger"),e.querySelector(".select__wrapper")].filter(n=>n instanceof HTMLElement).filter((n,r,o)=>o.indexOf(n)===r)}function Cn(){const e=new Map;An(),document.documentElement.setAttribute(ke,"true");const t=()=>{for(const r of document.querySelectorAll(Ce))e.has(r)||e.set(r,{display:r.style.display,opacity:r.style.opacity,visibility:r.style.visibility,pointerEvents:r.style.pointerEvents}),r.style.opacity="0",r.style.visibility="hidden",r.style.pointerEvents="none"};t();const n=new MutationObserver(()=>t());return n.observe(document.body,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["class","style","aria-hidden"]}),{getTrackedDropdowns:()=>Array.from(document.querySelectorAll(Ce)),restore:()=>{n.disconnect(),document.documentElement.removeAttribute(ke);for(const[r,o]of e)r.style.display=o.display,r.style.opacity=o.opacity,r.style.visibility=o.visibility,r.style.pointerEvents=o.pointerEvents}}}function An(){if(document.getElementById(et))return;const e=document.createElement("style");e.id=et,e.textContent=`
|
|
1
|
+
(function(h,m){typeof exports=="object"&&typeof module<"u"?m(exports):typeof define=="function"&&define.amd?define(["exports"],m):(h=typeof globalThis<"u"?globalThis:h||self,m(h.SmartFillSDK={}))})(this,function(h){"use strict";var Io=Object.defineProperty;var Mo=(h,m,I)=>m in h?Io(h,m,{enumerable:!0,configurable:!0,writable:!0,value:I}):h[m]=I;var d=(h,m,I)=>Mo(h,typeof m!="symbol"?m+"":m,I);const m={name:"native",match:e=>e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement||e instanceof HTMLSelectElement,getValue:e=>{const t=e.element;if(t instanceof HTMLInputElement&&t.type==="checkbox")return t.checked;if(t instanceof HTMLInputElement||t instanceof HTMLTextAreaElement||t instanceof HTMLSelectElement)return t.value},setValue:(e,t)=>{const n=e.element;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}))}},I=[{framework:"element",selectors:".el-select,.el-select-v2",type:"select",kind:"input"},{framework:"element",selectors:".el-cascader",type:"cascader",kind:"input"},{framework:"element",selectors:".el-date-editor,.el-time-picker",type:"date",kind:"input"},{framework:"element",selectors:".el-input-number",type:"number",kind:"input"},{framework:"element",selectors:".el-switch",type:"checkbox",kind:"switch"},{framework:"element",selectors:".el-radio-group",type:"radio",kind:"radioGroup",optionSelector:'.el-radio,[role="radio"],input[type="radio"]'},{framework:"element",selectors:".el-checkbox-group",type:"checkbox",kind:"checkboxGroup",optionSelector:'.el-checkbox,[role="checkbox"],input[type="checkbox"]'},{framework:"antd",selectors:".ant-select",type:"select",kind:"input"},{framework:"antd",selectors:".ant-cascader",type:"cascader",kind:"input"},{framework:"antd",selectors:".ant-picker",type:"date",kind:"input"},{framework:"antd",selectors:".ant-input-number",type:"number",kind:"input"},{framework:"antd",selectors:".ant-switch",type:"checkbox",kind:"switch"},{framework:"antd",selectors:".ant-radio-group",type:"radio",kind:"radioGroup",optionSelector:'.ant-radio-button,.ant-radio-wrapper,.ant-radio,[role="radio"],input[type="radio"]'},{framework:"antd",selectors:".ant-checkbox-group",type:"checkbox",kind:"checkboxGroup",optionSelector:'.ant-checkbox-wrapper,.ant-checkbox,[role="checkbox"],input[type="checkbox"]'},{framework:"naive",selectors:".n-select",type:"select",kind:"input"},{framework:"naive",selectors:".n-cascader",type:"cascader",kind:"input"},{framework:"naive",selectors:".n-date-picker,.n-time-picker",type:"date",kind:"input"},{framework:"naive",selectors:".n-input-number",type:"number",kind:"input"},{framework:"naive",selectors:".n-switch",type:"checkbox",kind:"switch"},{framework:"naive",selectors:".n-radio-group",type:"radio",kind:"radioGroup",optionSelector:'.n-radio,[role="radio"],input[type="radio"]'},{framework:"naive",selectors:".n-checkbox-group",type:"checkbox",kind:"checkboxGroup",optionSelector:'.n-checkbox,[role="checkbox"],input[type="checkbox"]'},{framework:"arco",selectors:".arco-select",type:"select",kind:"input"},{framework:"arco",selectors:".arco-cascader",type:"cascader",kind:"input"},{framework:"arco",selectors:".arco-picker",type:"date",kind:"input"},{framework:"arco",selectors:".arco-input-number",type:"number",kind:"input"},{framework:"arco",selectors:".arco-switch",type:"checkbox",kind:"switch"},{framework:"arco",selectors:".arco-radio-group",type:"radio",kind:"radioGroup",optionSelector:'.arco-radio,[role="radio"],input[type="radio"]'},{framework:"arco",selectors:".arco-checkbox-group",type:"checkbox",kind:"checkboxGroup",optionSelector:'.arco-checkbox,[role="checkbox"],input[type="checkbox"]'},{framework:"vant",selectors:".van-dropdown-menu",type:"select",kind:"input"},{framework:"vant",selectors:".van-cascader",type:"cascader",kind:"input"},{framework:"vant",selectors:".van-stepper",type:"number",kind:"input"},{framework:"vant",selectors:".van-field--picker",type:"date",kind:"input"},{framework:"vant",selectors:".van-search",type:"text",kind:"input"},{framework:"vant",selectors:".van-field",type:"text",kind:"input"},{framework:"vant",selectors:".van-switch",type:"checkbox",kind:"switch"},{framework:"vant",selectors:".van-radio-group",type:"radio",kind:"radioGroup",optionSelector:'.van-radio,[role="radio"],input[type="radio"]'},{framework:"vant",selectors:".van-checkbox-group",type:"checkbox",kind:"checkboxGroup",optionSelector:'.van-checkbox,[role="checkbox"],input[type="checkbox"]'},{framework:"generic",selectors:'[role="combobox"]',type:"select",kind:"input"}],nn=["is-disabled","ant-select-disabled","n-select--disabled","arco-select-disabled","van-field--disabled","van-switch--disabled","van-stepper--disabled","van-dropdown-menu--disabled"],We=I.map(e=>e.selectors).join(", "),rn=[".form-item",".ant-form-item",".el-form-item",".n-form-item",".arco-form-item",".van-cell",".van-field",".field",".form-row"].join(", "),on=["label",".ant-form-item-label",".el-form-item__label",".n-form-item-label",".arco-form-item-label",".van-field__label",".label"].join(", "),Xe=["dialog[open]","[role='dialog']","[aria-modal='true']",".modal",".modal-dialog",".ant-modal",".ant-drawer",".el-dialog",".el-drawer",".n-modal",".n-dialog",".arco-modal",".arco-drawer",".van-popup",".van-dialog",".van-action-sheet",".popup",".drawer"].join(", "),sn=["is-checked","ant-switch-checked","n-switch--active","arco-switch-checked","van-switch--on","van-radio--checked","van-checkbox--checked"];function q(e){return I.find(t=>e.matches(t.selectors))||null}function Ze(e){return!!q(e)}function xe(e){for(let t=e;t;t=t.parentElement)if(Ze(t))return t;return null}function te(e){var n;const t=q(e);if(!t)return null;if(e.matches(".van-field")){if(e.querySelector("textarea"))return"textarea";if(e.classList.contains("van-field--picker"))return"date";if(e.querySelector(".van-dropdown-menu"))return"select";const r=e.querySelector("input");if(r&&(r.readOnly||r.hasAttribute("readonly"))){const o=(r.getAttribute("placeholder")||"").trim();if(!o||/选择|select/i.test(o))return"select"}if(e.classList.contains("van-field--clickable")){const o=p(((n=e.querySelector(".van-field__control"))==null?void 0:n.textContent)||"");if(!e.querySelector("textarea")&&(o==="请选择"||o===""))return"select"}}return t.type}function Je(e){const t=q(e);if(t!=null&&t.optionSelector)return Array.from(e.querySelectorAll(t.optionSelector)).map(n=>an(n)).filter(n=>!!(n.label||n.value))}function an(e){const t=e instanceof HTMLInputElement?e:e.querySelector('input[type="radio"],input[type="checkbox"]'),n=p(e.textContent||e.getAttribute("aria-label")||e.getAttribute("title")||""),r=e.getAttribute("value")||(t==null?void 0:t.value)||n;return{label:n,value:r}}function N(e){return sn.some(t=>e.classList.contains(t))||e.getAttribute("aria-checked")==="true"||!!e.querySelector("input:checked")}function D(e){return e.querySelector('input:not([type="hidden"]), textarea')}function Qe(e){var t,n,r;return e.getAttribute("name")||((t=D(e))==null?void 0:t.getAttribute("name"))||e.getAttribute("data-smart-fill-key")||((n=D(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"))}function p(e){return e.replace(/[*::]/g,"").replace(/\s+/g," ").trim()}const ke="data-smart-fill-hide-dropdown-mode",et="smart-fill-hide-dropdown-style",tt=["[role='combobox']","[aria-haspopup='listbox']",".el-cascader",".ant-cascader",".arco-cascader",".ant-select",".el-select",".el-select-v2",".el-select__wrapper",".el-select-v2__wrapper",".n-select",".n-base-selection",".ivu-select",".arco-select",".semi-select",".t-select",".select-trigger",".select__wrapper",".van-dropdown-menu",".van-dropdown-menu__bar",".van-field--picker",".van-field--clickable"].join(", "),cn=[".ant-select-selection-item",".el-select__selected-item",".el-select-v2__selected-item",".el-select-v2-selected-item",".el-select__placeholder",".el-select-v2__placeholder",".el-select-selected-value",".n-base-selection-label",".ivu-select-selected-value",".arco-select-view-value",".semi-select-selection-text",".t-input__inner",".select-value",".selection-item",".van-field__control"].join(", "),_e=["[role='option']",".ant-select-item-option",".el-select-dropdown__item",".el-select-v2__option",".n-base-select-option",".ivu-select-item",".arco-select-option",".semi-select-option",".t-select-option",".van-picker-column__item",".van-action-sheet__item"].join(", "),ne=[_e,".van-action-sheet__name",".van-cascader__option",".van-dropdown-item__option",".van-picker-column__item--selected",".el-cascader-node",".ant-cascader-menu-item",".n-cascader-node",".arco-cascader-option"].join(", "),Ce=[".el-select-dropdown",".el-cascader__dropdown",".el-cascader-panel",".el-select__popper",".el-select-v2__popper",".el-popper.el-cascader__dropdown",".el-popper.el-select__popper",".el-popper.el-select-v2__popper",".el-popper",".ant-select-dropdown",".ant-cascader-menus",".n-base-select-menu",".n-cascader-menu",".arco-select-dropdown",".arco-cascader-panel",".semi-select-dropdown",".t-select__dropdown",".van-popup",".van-action-sheet",".van-dropdown-item__content",".van-dropdown-item",".van-picker","[role='listbox']"].join(", "),nt=[".el-select-dropdown",".el-select__popper",".el-select-v2__popper",".el-popper.el-select__popper",".el-popper.el-select-v2__popper",".ant-select-dropdown",".n-base-select-menu",".arco-select-dropdown",".semi-select-dropdown",".t-select__dropdown",".van-popup",".van-action-sheet",".van-dropdown-item__content",".van-dropdown-item",".van-picker","[role='listbox']"].join(", "),rt=[".el-cascader__dropdown",".el-cascader-panel",".el-popper.el-cascader__dropdown",".ant-cascader-menus",".n-cascader-menu",".arco-cascader-panel",".van-cascader",".van-cascader__options"].join(", "),ln=/(?:省|市|自治区|特别行政区|自治州|地区|盟|县|区)$/,un=/地址|省|市|区|县|地区|籍贯|户籍|居住地|所在地|区域/,dn=new Set(["select","cascader","date"]);function _(e){return!ht(e)||st(e)?!1:!!e.closest(".el-cascader, .ant-cascader, .van-cascader, .n-cascader, .arco-cascader")}function E(e){var n;if(!e.matches(".van-field"))return!1;if(e.classList.contains("van-field--picker")||e.querySelector(".van-dropdown-menu"))return!0;const t=e.querySelector("input");if(t&&(t.readOnly||t.hasAttribute("readonly"))){const r=(t.getAttribute("placeholder")||"").trim();if(!r||/选择|select/i.test(r))return!0}if(e.classList.contains("van-field--clickable")){const r=p(((n=e.querySelector(".van-field__control"))==null?void 0:n.textContent)||"");if(!e.querySelector("textarea")&&(r==="请选择"||r===""))return!0}return!1}function V(e){return!ht(e)||st(e)||e instanceof HTMLSelectElement||e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement?!1:e.matches(tt)||e.getAttribute("role")==="combobox"||e.getAttribute("aria-haspopup")==="listbox"||e.classList.contains("el-select__wrapper")||e.classList.contains("el-select-v2__wrapper")||E(e)}function K(e){const t=e.closest(".el-cascader, .ant-cascader, .van-cascader, .n-cascader, .arco-cascader");if(t instanceof HTMLElement)return t;const n=e.closest([".el-date-editor",".el-time-picker",".el-date-picker",".el-date-picker-panel",".el-select",".el-select-v2",".ant-picker",".ant-select",".n-date-picker",".n-time-picker",".n-select",".ivu-select",".arco-picker",".arco-select",".semi-select",".t-select",".van-field",".van-dropdown-menu",".van-dropdown-menu__bar","[role='combobox']","[aria-haspopup='listbox']",".select-trigger",".select__wrapper",".el-select__wrapper",".el-select-v2__wrapper"].join(", "));return n instanceof HTMLElement?n.matches(".van-field")&&!E(n)?null:n:V(e)?e:null}function Ae(e){if(e instanceof HTMLSelectElement)return e;if(_(e))return e.closest(".el-cascader, .ant-cascader, .van-cascader, .n-cascader, .arco-cascader")||e;const t=K(e);return t||(e.matches(".van-field")&&E(e)?e:null)}function ot(e){if(_(e))return"cascader";if(V(e)||E(e))return"select";const t=te(e);return t||(e instanceof HTMLSelectElement?"select":null)}function Te(e,t){const n=t||ot(e);return n!=null&&dn.has(n)}function pn(e){const t=e.matches(".van-field")?e:e.closest(".van-field");if(t instanceof HTMLElement&&E(t)){const i=t.querySelector(".van-field__control");if(i instanceof HTMLInputElement)return p(i.value);const s=p((i==null?void 0:i.textContent)||"");return s&&s!=="请选择"?s:""}const n=e.querySelector(cn);if(n instanceof HTMLInputElement)return p(n.value);const r=p((n==null?void 0:n.textContent)||"");if(r&&r!=="请选择")return r;const o=e.querySelector('input:not([type="hidden"])');return o!=null&&o.value?p(o.value):r}function it(e){const t=wn(e);if(!t.length)return;const n=vn(t);return n.length?n:void 0}function re(e){var t;return!((t=e.options)!=null&&t.length)||e.type==="cascader"||un.test(e.label||"")?!1:Cn(e.options)}async function fn(e){if(e instanceof HTMLSelectElement)return Array.from(e.options).map(s=>({value:s.value,label:p(s.textContent||s.label)})).filter(s=>s.label||s.value);const t=it(e);if(t!=null&&t.length)return t;const n=K(e)||e;if(!V(n)&&!_(n)&&!E(n))return;const r=In(),o=An(),i=new Set(o.getTrackedDropdowns());try{if(!(_(n)?await gn(n,o,i):await hn(n,o,i)))return;const a=await bn(o,i,n);if(!a.length)return;const c=yn(a);return c.length?c:void 0}finally{await Ln(n,o),await M(60),o.restore(),r()}}function st(e){return e.hasAttribute("disabled")||e.getAttribute("aria-disabled")==="true"}async function hn(e,t,n){const r=z(e);if(!r.length)return!1;for(const o of r)if(pt(o),dt(o),await M(160),at(e,t,n)||(ft(o),await M(180),at(e,t,n)))return!0;return!1}async function gn(e,t,n){const r=[e,e.querySelector(".el-input__wrapper"),e.querySelector(".el-input"),e.querySelector(".van-field__control"),e.querySelector("input")].filter(o=>o instanceof HTMLElement);for(const o of r)if(pt(o),dt(o),await M(180),oe(t,n,e).length||(ft(o),await M(180),oe(t,n,e).length))return!0;return!1}function yn(e){var r;const t=new Set,n=[];for(const o of e){const i=o.matches(ne)?[o]:Array.from(o.querySelectorAll(ne));for(const s of i){if(s.classList.contains("is-disabled")||s.classList.contains("ant-select-item-option-disabled")||s.getAttribute("aria-disabled")==="true")continue;const a=p(((r=s.querySelector(".el-cascader-node__label, .ant-cascader-menu-item-content"))==null?void 0:r.textContent)||s.textContent||""),c=s.getAttribute("data-value")||s.getAttribute("value")||a;if(!a&&!c)continue;const l=`${a}::${String(c)}`;t.has(l)||(t.add(l),n.push({label:a,value:c}))}}return n}async function bn(e,t,n){for(let r=0;r<8;r+=1){const o=oe(e,t,n);if(o.length)return o;await M(r===0?120:80)}return[]}function at(e,t,n){return oe(t,n,e).length>0?!0:z(e).some(r=>r.getAttribute("aria-expanded")==="true"||r.classList.contains("is-focus")||r.classList.contains("is-focused"))}function mn(e,t,n){const r=t.filter(c=>Le(e,c)),o=r.filter(c=>Sn(e,c)),i=o.filter(c=>!n.has(c));if(i.length)return i.sort((c,l)=>P(l,e)-P(c,e));const s=ct(e);if(s.size){const c=o.filter(l=>l.id&&s.has(l.id));if(c.length)return c}if(o.length)return o.sort((c,l)=>P(l,e)-P(c,e)).slice(0,1);const a=r.filter(c=>_n(c)&<(e)).sort((c,l)=>P(l,e)-P(c,e)).slice(0,1);return a.length?a:[]}function oe(e,t,n){return mn(n,e.getTrackedDropdowns(),t)}function P(e,t){const n=e.getBoundingClientRect(),r=Number.parseInt(window.getComputedStyle(e).zIndex||"0",10);let o=(Number.isNaN(r)?0:r)*10+n.width*n.height;return t&&(o+=ut(t,e)),o}function wn(e){const t=_(e)?rt:nt,n=new Set;e.matches(t)&&n.add(e);for(const r of e.querySelectorAll(t))Le(e,r)&&n.add(r);for(const r of e.querySelectorAll("[role='listbox']"))e.contains(r)&&Le(e,r)&&n.add(r);return[...n]}function vn(e){const t=new Set,n=[];for(const r of e){const o=r.matches(_e)?[r]:Array.from(r.querySelectorAll(_e));for(const i of o){if(i.classList.contains("is-disabled")||i.classList.contains("ant-select-item-option-disabled")||i.getAttribute("aria-disabled")==="true")continue;const s=p(i.textContent||""),a=i.getAttribute("data-value")||i.getAttribute("value")||s;if(!s&&!a)continue;const c=`${s}::${String(a)}`;t.has(c)||(t.add(c),n.push({label:s,value:a}))}}return n}function ct(e){return new Set(z(e).flatMap(t=>[t.getAttribute("aria-controls"),t.getAttribute("aria-owns")]).filter(t=>!!t))}function Sn(e,t){const n=ct(e);return n.size&&t.id&&n.has(t.id)||e.contains(t)?!0:kn(t)?lt(e):n.size>0||z(e).some(o=>o.getAttribute("aria-controls")||o.getAttribute("aria-owns"))?!1:ut(e,t)>0}function Le(e,t){const n=_(e),r=En(t);return n?r:r?!1:xn(t)}function En(e){return e.matches(rt)||!!e.querySelector(".el-cascader-node, .ant-cascader-menu-item, .van-cascader__option, .n-cascader-node, .arco-cascader-option")}function xn(e){return e.matches(nt)||!!e.querySelector('.el-select-dropdown__item, .ant-select-item-option, .van-picker-column__item, .van-action-sheet__item, .van-dropdown-item__option, [role="option"]')}function kn(e){return e.matches(".van-popup, .van-action-sheet, .van-picker, .van-dropdown-item__content, .van-dropdown-item")}function lt(e){return z(e).some(t=>t.getAttribute("aria-expanded")==="true"||t.classList.contains("is-focus")||t.classList.contains("is-focused")||e.contains(document.activeElement))}function _n(e){return e.matches(ne)||!!e.querySelector(ne)}function ut(e,t){const n=e.getBoundingClientRect(),r=t.getBoundingClientRect();if(!n.width||!n.height||!r.width||!r.height)return 0;const o=Math.min(n.right,r.right)-Math.max(n.left,r.left);if(o<=0)return 0;const i=r.top>=n.bottom?r.top-n.bottom:n.top-r.bottom;return i>320?0:Math.max(0,400-i)+o}function Cn(e){const t=e.slice(0,8).map(r=>p(String(r.label||r.value||""))).filter(Boolean);return t.length<4?!1:t.filter(r=>ln.test(r)).length/t.length>=.75}function z(e){return[e,e.querySelector(".van-field__control"),e.querySelector(".van-field__body"),e.querySelector(".van-dropdown-menu__bar"),e.querySelector(".el-select__wrapper"),e.querySelector(".el-select-v2__wrapper"),e.querySelector(".el-select__selection"),e.querySelector(".el-input__wrapper"),e.querySelector(".el-input"),e.querySelector("input"),e.querySelector("[role='combobox']"),e.querySelector("[aria-haspopup='listbox']"),e.querySelector(".ant-select-selector"),e.querySelector(".n-base-selection"),e.querySelector(".n-base-selection-label"),e.querySelector(".arco-select-view"),e.querySelector(".arco-cascader"),e.querySelector(".semi-select"),e.querySelector(".t-input"),e.querySelector(".select-trigger"),e.querySelector(".select__wrapper")].filter(n=>n instanceof HTMLElement).filter((n,r,o)=>o.indexOf(n)===r)}function An(){const e=new Map;Tn(),document.documentElement.setAttribute(ke,"true");const t=()=>{for(const r of document.querySelectorAll(Ce))e.has(r)||e.set(r,{display:r.style.display,opacity:r.style.opacity,visibility:r.style.visibility,pointerEvents:r.style.pointerEvents}),r.style.opacity="0",r.style.visibility="hidden",r.style.pointerEvents="none"};t();const n=new MutationObserver(()=>t());return n.observe(document.body,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["class","style","aria-hidden"]}),{getTrackedDropdowns:()=>Array.from(document.querySelectorAll(Ce)),restore:()=>{n.disconnect(),document.documentElement.removeAttribute(ke);for(const[r,o]of e)r.style.display=o.display,r.style.opacity=o.opacity,r.style.visibility=o.visibility,r.style.pointerEvents=o.pointerEvents}}}function Tn(){if(document.getElementById(et))return;const e=document.createElement("style");e.id=et,e.textContent=`
|
|
2
2
|
${Ce.split(",").map(t=>`html[${ke}="true"] ${t.trim()}`).join(`,
|
|
3
3
|
`)} {
|
|
4
4
|
opacity: 0 !important;
|
|
@@ -7,8 +7,35 @@
|
|
|
7
7
|
transition: none !important;
|
|
8
8
|
animation: none !important;
|
|
9
9
|
}
|
|
10
|
-
`,document.head.appendChild(e)}async function Tn(e,t){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 M(120);for(const n of t.getTrackedDropdowns())n.isConnected&&(n.style.display="none",n.setAttribute("aria-hidden","true"))}function dt(e){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()}function pt(e){e.focus({preventScroll:!0});const t=e instanceof HTMLInputElement?e:e.querySelector("input");t instanceof HTMLElement&&t.focus({preventScroll:!0})}function ft(e){for(const t of[{key:"ArrowDown",code:"ArrowDown"},{key:"Enter",code:"Enter"},{key:" ",code:"Space"}])e.dispatchEvent(new KeyboardEvent("keydown",{...t,bubbles:!0,composed:!0})),e.dispatchEvent(new KeyboardEvent("keyup",{...t,bubbles:!0,composed:!0}))}function M(e){return new Promise(t=>window.setTimeout(t,e))}function Ln(){const e=new Map;e.set(window,{left:window.scrollX,top:window.scrollY});for(const t of document.querySelectorAll("*"))(t.scrollTop||t.scrollLeft)&&e.set(t,{left:t.scrollLeft,top:t.scrollTop});return()=>{for(const[t,n]of e)t===window?window.scrollTo(n.left,n.top):t instanceof HTMLElement&&(t.scrollLeft=n.left,t.scrollTop=n.top)}}function ht(e){const t=window.getComputedStyle(e);if(t.display==="none"||t.visibility==="hidden"||Number(t.opacity)===0)return!1;const n=e.getBoundingClientRect();return n.width>0&&n.height>0}function ie(e,t){const n=se(t);if(!n.length)return null;let r=null,o=0;for(const i of e){const s=S(i.value),a=S(i.label);for(const c of n){let l=0;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&&ae(s)===ae(c)||a&&ae(a)===ae(c))&&(l=80),l>o&&(o=l,r=i)}}return o>=80?r:null}function se(e){if(Array.isArray(e))return e.flatMap(n=>se(n));if(typeof e=="object"&&e){const n=e;return[n.label,n.value,n.text,n.answer,n.name].filter(r=>r!=null).map(r=>S(r)).filter(Boolean)}const t=S(e);return t?[t]:[]}function S(e){return String(e??"").replace(/\s+/g,"").replace(/[::,,。.、()()\-_/]/g,"").trim().toLowerCase()}function ae(e){return S(e).replace(/(请选择|选择|状态|情况|类型|方式|所属|是否)$/g,"")}const ce=[".ant-select-item-option",".el-select-dropdown__item",".el-select-v2__option",".el-select-v2__option-item",".n-base-select-option",".ivu-select-item",".arco-select-option",".semi-select-option",".t-select-option",".van-picker-column__item",".van-action-sheet__item",".van-action-sheet__name",".van-cascader__option",".van-dropdown-item__option",".van-radio","[role='option']"].join(", "),In=[".el-cascader-panel .el-cascader-menu",".ant-cascader-menu",".van-cascader__options",".n-cascader-menu",".arco-cascader-list"].join(", "),Mn=[".el-cascader-node",".ant-cascader-menu-item",".van-cascader__option",".n-cascader-node",".arco-cascader-option"].join(", "),Fn=".van-picker__confirm, .van-picker__toolbar .van-picker__confirm";async function Rn(e,t,n,r){const o=yt(t,r);return e instanceof HTMLSelectElement?On(e,o):_(e)||n==="cascader"?Dn(e,o):(V(e)||E(e)||n==="select"||n==="date",gt(e,o))}function Ie(e){if(e instanceof HTMLSelectElement){const n=e.options[e.selectedIndex];return p((n==null?void 0:n.textContent)||e.value)}if(_(e)){const n=e.querySelector("input");if(n!=null&&n.value)return p(n.value);const r=e.querySelector(".el-cascader__tags-text, .el-cascader__label");return p((r==null?void 0:r.textContent)||"")}if(V(e)||E(e))return dn(e);const t=e.querySelector("input, textarea");return p((t==null?void 0:t.value)||e.textContent||"")}async function On(e,t){const n=Array.from(e.options).map(o=>({source:o,value:o.value,label:o.textContent})),r=ie(n,t.searchValue);if((r==null?void 0:r.source)instanceof HTMLOptionElement){pe(e,r.source.value),A(e);return}if(!B(e,t))throw new Error("原生下拉框中没有匹配到对应选项")}async function gt(e,t){const n=K(e)||e;if(Re(n,t.searchValue))return;const r=new Set(j());try{if(!await qn(n)){if(B(n,t))return;throw new Error("自定义下拉框未能成功展开")}const i=await jn(n,r),s=await Hn(t.searchValue,i,!0);if(!(s!=null&&s.source)){if(await ue(n),B(n,t))return;throw new Error("自定义下拉框展开后未找到匹配选项")}if(G(s.source),await b(120),Yn(),A(n),await b(120),Re(n,t.searchValue)||B(n,t)&&Re(n,t.searchValue))return;throw new Error("自定义下拉框点击选项后未成功回填")}finally{await ue(n),await b(80)}}async function Dn(e,t){const n=e.closest(".el-cascader, .ant-cascader, .van-cascader, .n-cascader, .arco-cascader")||e;if(!Fe(n,t.searchValue)){try{if(await Pn(n)){const o=await Vn(t.searchValue);if(await b(180),await ue(n),await b(120),o&&Fe(n,t.searchValue)){A(n);return}}if(Kn(n,t.fillValue)&&Fe(n,t.searchValue))return}finally{await ue(n),await b(80)}throw new Error("级联选择框匹配失败")}}function yt(e,t){var s;const n=(s=t==null?void 0:t.options)!=null&&s.length?ie(t.options.map(a=>({value:String(a.value),label:a.label})),e):null,r=C(e),o=p(String((n==null?void 0:n.label)??r??"")),i=p(String((n==null?void 0:n.value)??(n==null?void 0:n.label)??r??""));return{searchValue:n?[e,n.label,n.value]:e,fillValue:i,displayValue:o}}async function qn(e){const t=Me(e);for(const n of t)if(wt(n),G(n),await b(160),mt(e)||(vt(n),await b(180),mt(e)))return!0;return!1}async function Pn(e){const t=[e,e.querySelector(".el-input__wrapper"),e.querySelector(".el-input"),e.querySelector(".van-field__control"),e.querySelector("input")].filter(n=>n instanceof HTMLElement);for(const n of t)if(wt(n),G(n),await b(180),le().length||(vt(n),await b(180),le().length))return!0;return!1}async function Hn(e,t,n=!1){for(let r=0;r<12;r+=1){const o=ie(bt(t,n).map(i=>({source:i,value:$n(i),label:Nn(i)})),e);if(o)return o;await b(100)}return null}function $n(e){return e.getAttribute("data-value")||e.getAttribute("data-name")||e.getAttribute("value")||e.getAttribute("name")||e.textContent||""}function Nn(e){var t;return p(((t=e.querySelector(".van-action-sheet__name, .el-cascader-node__label, .ant-cascader-menu-item-content, .n-cascader-node__label, .arco-cascader-option-label"))==null?void 0:t.textContent)||e.textContent||"")}async function Vn(e){const t=Xn(e);if(!t.length)return!1;for(let n=0;n<t.length;n+=1){const r=le();if(!r.length)return n>0;const o=r[r.length-1],i=Array.from(o.querySelectorAll(Mn)).filter(a=>!a.classList.contains("is-disabled")&&a.getAttribute("aria-disabled")!=="true"),s=ie(i.map(a=>{var c;return{source:a,value:a.getAttribute("data-value")||a.textContent,label:((c=a.querySelector(".el-cascader-node__label"))==null?void 0:c.textContent)||a.textContent}}),t[n]);if(!(s!=null&&s.source))return!1;G(s.source),await b(220)}return!le().length||!0}function B(e,t){const n=Un(t)?t:yt(t),r=n.displayValue||C(t),o=n.fillValue||r;if(!r&&!o)return!1;const i=K(e)||e;if(E(i))return zn(i,r,o);if(e instanceof HTMLSelectElement){let l=Array.from(e.options).find(u=>u.dataset.smartFillFallbackOption==="true");return l||(l=document.createElement("option"),l.dataset.smartFillFallbackOption="true",e.appendChild(l)),l.value=o,l.textContent=r||o,l.selected=!0,pe(e,o),A(e),!0}const s=e.querySelector('input:not([type="hidden"])');if(!(s instanceof HTMLInputElement)||s.disabled)return!1;const a=s.readOnly,c=s.hasAttribute("readonly");try{return a&&(s.readOnly=!1,s.removeAttribute("readonly")),s.focus(),pe(s,r),s.dispatchEvent(new InputEvent("input",{bubbles:!0,composed:!0,data:r,inputType:"insertReplacementText"})),s.dispatchEvent(new Event("change",{bubbles:!0,composed:!0})),A(s),A(e),s.blur(),!0}catch{return!1}finally{a&&(s.readOnly=!0,c&&s.setAttribute("readonly",""))}}function Kn(e,t){const n=e.querySelector("input"),r=C(t);return!(n instanceof HTMLInputElement)||!r||n.disabled?!1:B(e,{searchValue:t,fillValue:r,displayValue:r})}function zn(e,t,n){Bn(e);const r=e.querySelector(".van-field__control"),o=Array.from(e.querySelectorAll('input[type="hidden"]')),i=Array.from(e.querySelectorAll('input:not([type="hidden"])'));r instanceof HTMLInputElement?U(r,t||n):r instanceof HTMLElement&&(r.textContent=t||n);for(const s of o)U(s,n);for(const s of i)r!==s&&U(s,t||n);return A(e),!0}function Bn(e){const t=e.querySelector(".van-field__control");t instanceof HTMLInputElement?U(t,""):t instanceof HTMLElement&&(t.textContent="");for(const n of e.querySelectorAll("input"))U(n,"")}function U(e,t){if(e.disabled)return;const n=e.readOnly,r=e.hasAttribute("readonly");try{n&&(e.readOnly=!1,e.removeAttribute("readonly")),pe(e,t),e.dispatchEvent(new InputEvent("input",{bubbles:!0,composed:!0,data:t,inputType:t?"insertReplacementText":"deleteContentBackward"})),e.dispatchEvent(new Event("change",{bubbles:!0,composed:!0})),A(e)}finally{n&&(e.readOnly=!0,r&&e.setAttribute("readonly",""))}}function Un(e){return typeof e=="object"&&e!=null&&"searchValue"in e&&"fillValue"in e&&"displayValue"in e}function Me(e){return[e,e.querySelector(".van-field__control"),e.querySelector(".van-field__body"),e.querySelector(".el-select__wrapper"),e.querySelector(".el-select-v2__wrapper"),e.querySelector(".el-select__selection"),e.querySelector(".el-input__wrapper"),e.querySelector(".el-input"),e.querySelector("input"),e.querySelector("[role='combobox']"),e.querySelector("[aria-haspopup='listbox']"),e.querySelector(".ant-select-selector"),e.querySelector(".n-base-selection"),e.querySelector(".arco-select-view"),e.querySelector(".select-trigger"),e.querySelector(".select__wrapper")].filter(n=>n instanceof HTMLElement).filter((n,r,o)=>o.indexOf(n)===r)}function bt(e,t){return(e.length?e:j()).flatMap(o=>o.matches(ce)?[o]:Array.from(o.querySelectorAll(ce))).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":H(o)&&!o.classList.contains("is-disabled")&&!o.classList.contains("ant-select-item-option-disabled")&&o.getAttribute("aria-disabled")!=="true")}function le(){return Array.from(document.querySelectorAll(In)).filter(H)}async function jn(e,t){for(let n=0;n<10;n+=1){const r=Gn(e,t);if(r.length)return r;await b(80)}return j().filter(H)}function Gn(e,t){const n=j(),r=n.filter(i=>!t.has(i));if(r.length)return r.sort((i,s)=>de(s)-de(i));const o=new Set(Me(e).flatMap(i=>[i.getAttribute("aria-controls"),i.getAttribute("aria-owns")]).filter(i=>!!i));if(o.size){const i=n.filter(s=>o.has(s.id));if(i.length)return i}return n.filter(i=>H(i)&&(i.querySelector(ce)||i.matches(ce))).sort((i,s)=>de(s)-de(i)).slice(0,1)}function mt(e){return bt(j().filter(H),!1).length>0?!0:Me(e).some(t=>t.getAttribute("aria-expanded")==="true"||t.classList.contains("is-focus")||t.classList.contains("is-focused"))}function Fe(e,t){const n=S(Ie(e)),r=S(C(t));return!n||!r?!1:n===r||n.includes(r)||r.includes(n)}function Re(e,t){const n=S(Ie(e));if(!n)return!1;const r=se(t);if(!r.length){const o=S(C(t));return o?n===o||n.includes(o)||o.includes(n):!1}return r.some(o=>{const i=S(o);return!!i&&(n===i||n.includes(i)||i.includes(n))})}function Yn(){const e=document.querySelector(Fn);e&&H(e)&&G(e)}async function ue(e){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)}function j(){return Array.from(document.querySelectorAll(Wn()))}function de(e){const t=e.getBoundingClientRect(),n=Number.parseInt(window.getComputedStyle(e).zIndex||"0",10);return(Number.isNaN(n)?0:n)*10+t.width*t.height}function Wn(){return[".el-select-dropdown",".el-cascader__dropdown",".el-cascader-panel",".el-select__popper",".el-select-v2__popper",".el-popper.el-cascader__dropdown",".el-popper.el-select__popper",".el-popper.el-select-v2__popper",".el-popper",".ant-select-dropdown",".ant-cascader-menus",".n-base-select-menu",".n-cascader-menu",".arco-select-dropdown",".arco-cascader-panel",".semi-select-dropdown",".t-select__dropdown",".van-popup",".van-action-sheet",".van-dropdown-item__content",".van-picker","[role='listbox']"].join(", ")}function C(e){if(e==null)return"";if(typeof e=="string"||typeof e=="number"||typeof e=="boolean")return p(String(e));if(Array.isArray(e))return e.map(t=>C(t)).filter(Boolean).join(" ");if(typeof e=="object"){const t=e;for(const n of["label","text","value","answer","name"]){const r=C(t[n]);if(r)return r}}return p(String(e))}function Xn(e){const t=C(e);if(!t)return[];if(t.includes("/")||t.includes("、"))return t.split(/[//、]/).map(r=>r.trim()).filter(Boolean);const n=se(e);return n.length?[p(n[0])]:[t]}function pe(e,t){var o;const n=Object.getPrototypeOf(e),r=Object.getOwnPropertyDescriptor(n,"value");(o=r==null?void 0:r.set)==null||o.call(e,t)}function A(e){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}))}function G(e){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()}function wt(e){e.focus({preventScroll:!0});const t=e instanceof HTMLInputElement?e:e.querySelector("input");t instanceof HTMLElement&&t.focus({preventScroll:!0})}function vt(e){for(const t of[{key:"ArrowDown",code:"ArrowDown"},{key:"Enter",code:"Enter"},{key:" ",code:"Space"}])e.dispatchEvent(new KeyboardEvent("keydown",{...t,bubbles:!0,composed:!0})),e.dispatchEvent(new KeyboardEvent("keyup",{...t,bubbles:!0,composed:!0}))}function H(e){const t=window.getComputedStyle(e);if(t.display==="none"||t.visibility==="hidden"||Number(t.opacity)===0)return!1;const n=e.getBoundingClientRect();return n.width>0&&n.height>0}function b(e){return new Promise(t=>window.setTimeout(t,e))}const St=new Set(["select","cascader","date"]),Oe={name:"ui-framework",match:e=>e.matches(We)||Ze(e)||!Jn(e)&&Te(e),getValue:e=>{var o,i;const t=e.element;if(!t)return;const n=D(t);if((n==null?void 0:n.kind)==="switch")return N(t);if((n==null?void 0:n.kind)==="radioGroup")return nr(t);if((n==null?void 0:n.kind)==="checkboxGroup")return rr(t);const r=e.type||te(t)||(n==null?void 0:n.type);return r&&St.has(r)?Ie(t):n?((i=q(t))==null?void 0:i.value)||t.textContent||void 0:(o=q(t))==null?void 0:o.value},setValue:async(e,t)=>{const n=e.element;if(!n)return;const r=D(n);if((r==null?void 0:r.kind)==="switch"){Qn(n,t);return}if((r==null?void 0:r.kind)==="radioGroup"){tr(n,t);return}if((r==null?void 0:r.kind)==="checkboxGroup"){er(n,t);return}const o=e.type||te(n)||(r==null?void 0:r.type);if(o&&St.has(o)||Te(n,o||void 0)){await Rn(n,t,o||"select",e);return}const i=q(n);if(i){or(i,t);return}n.dispatchEvent(new Event("change",{bubbles:!0}))}},Zn=Oe;function Jn(e){return e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement||e instanceof HTMLSelectElement}function Qn(e,t){N(e)!==ir(t)&&fe(e)}function er(e,t){var o;const n=new Set(sr(t).map(T)),r=Je(e)||[];for(const i of Y(e)){const s=W(i.textContent||""),a=i.getAttribute("value")||((o=i.querySelector("input"))==null?void 0:o.value)||s,c=N(i),l=n.has(T(String(a)))||n.has(T(s));c!==l&&fe(i)}if(!Y(e).length&&r.length)for(const i of r)(n.has(T(String(i.value)))||n.has(T(i.label)))&&fe(e)}function tr(e,t){const n=T(String(t??"")),r=Y(e).find(o=>{var a;const i=W(o.textContent||""),s=o.getAttribute("value")||((a=o.querySelector("input"))==null?void 0:a.value)||i;return T(String(s))===n||T(i)===n});r&&fe(r)}function nr(e){var n;const t=Y(e).find(r=>N(r));if(t)return t.getAttribute("value")||((n=t.querySelector("input"))==null?void 0:n.value)||W(t.textContent||"")}function rr(e){return Y(e).filter(t=>N(t)).map(t=>{var n;return t.getAttribute("value")||((n=t.querySelector("input"))==null?void 0:n.value)||W(t.textContent||"")})}function Y(e){const t=D(e);return t!=null&&t.optionSelector?Array.from(e.querySelectorAll(t.optionSelector)):[]}function or(e,t){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}))}function fe(e){e.dispatchEvent(new MouseEvent("click",{bubbles:!0,cancelable:!0,view:window}))}function ir(e){return typeof e=="boolean"?e:["true","1","是","开启","启用","yes","y"].includes(String(e??"").trim().toLowerCase())}function sr(e){return Array.isArray(e)?e.map(String):String(e??"").split(/[,,;;、]/).map(t=>t.trim()).filter(Boolean)}function T(e){return W(e).toLowerCase()}function W(e){return e.replace(/\s+/g," ").trim()}const Et="https://uat.kingdeefin.com";class xt extends Error{constructor(n){super(n.message);d(this,"smartFillError");this.name="SmartFillException",this.smartFillError=n}}function w(e,t,n,r={}){return new xt({code:e,message:t,stage:n,...r})}function kt(e,t,n="RECOGNIZE_FAILED"){return e instanceof xt?e.smartFillError:{code:n,message:e instanceof Error?e.message:String(e||"智能录入异常"),stage:t,retryable:t==="recognize"}}function he(e="sf"){return`${e}_${Date.now().toString(36)}_${Math.random().toString(36).slice(2,10)}`}class ar{constructor(t){d(this,"seToken","");d(this,"baseURL",Et);this.config=t}setAccessToken(t){this.seToken=t}async createSession(){if(!/^seKey-[A-Za-z0-9_-]{6,}$/.test(this.config.apiKey))throw w("API_KEY_INVALID","apiKey 格式不正确,应以 seKey- 开头。","setup");return{apiKey:this.config.apiKey,rulesVersion:"0.0.1"}}async getFormConfig(t){return t?this.request(`/sdk/forms/${encodeURIComponent(t)}`,{method:"GET"}):null}async resolveInputText(t){var i,s,a,c;const n=(i=t.images)!=null&&i.length?t.images:[],r=((s=t.text)==null?void 0:s.trim())||"";if(!n.length)return{text:r,usedOcr:!1};(a=t.onStatusChange)==null||a.call(t,"image_uploading");const o=await this.recognizeImages(n);return(c=t.onStatusChange)==null||c.call(t,"image_recognizing"),{text:o,usedOcr:!0}}async recognize(t){var s,a;const n=performance.now(),r=(s=t.text)==null?void 0:s.trim();(a=t.onStatusChange)==null||a.call(t,"recognizing");const o=await this.request("/fcloud/flow-product/agentChat/smartEntry",{method:"POST",body:JSON.stringify({formCode:t.formCode||"",configVersion:t.configVersion||"",formMsg:t.fields.map(({fingerprint:c,element:l,localRuleMode:u,scanToken:g,source:R,...ee})=>ee),userInputMsg:r||""})}),i=lr(o,t.fields,t.scanToken);return console.log("suggestions",i),{scanToken:t.scanToken,suggestions:i,trace:o.trace||{traceId:he("trace"),usedOcr:!!t.usedOcr,usedAi:!0,durationMs:Math.round(performance.now()-n)}}}async recognizeImages(t){const n=new FormData;t.forEach(i=>{n.append("image",i,i.name)});const r=await this.request("/fcloud/flow-product/agentChat/smartEntry/ocr",{method:"POST",body:n}),o=dr(r);if(!o)throw w("RECOGNIZE_FAILED","图片识别未提取到文本内容。","recognize");return o}async request(t,n){const r=new AbortController,o=window.setTimeout(()=>r.abort(),this.config.requestTimeoutMs??3e4),i=new Headers(n.headers);n.body&&!(n.body instanceof FormData)&&!i.has("Content-Type")&&i.set("Content-Type","application/json"),i.set("x-trace-id",he("trace")),this.seToken&&i.set("seToken",`${this.seToken}`);try{const s=await fetch(`${this.baseURL}${t}`,{...n,headers:i,signal:r.signal});if(!s.ok)throw w(pr(s.status),await s.text(),t.includes("session")?"setup":"recognize",{retryable:s.status>=500||s.status===429});return s.json()}catch(s){throw s instanceof DOMException&&s.name==="AbortError"?w("RECOGNIZE_TIMEOUT","识别请求超时,请稍后重试。","recognize",{retryable:!0}):s}finally{window.clearTimeout(o)}}}const cr=.95;function lr(e,t,n){var i;const r=new Map(t.map(s=>[s.fieldId,s]));return(((i=e.data)==null?void 0:i.fieldValues)||[]).filter(s=>!!(s!=null&&s.fieldId)).map(s=>{const a=r.get(s.fieldId);return{fieldId:s.fieldId,scanToken:n,label:s.label||(a==null?void 0:a.label)||s.fieldId,value:s.value,displayValue:s.value==null?"":String(s.value),confidence:ur(s.confidence),source:s.source||"ai",warnings:s.warnings}})}function ur(e){return typeof e!="number"||Number.isNaN(e)?cr:e<0?0:e>1?1:e}function dr(e){var n;const t=typeof e.data=="string"?e.data:((n=e.data)==null?void 0:n.text)||e.text||"";return String(t||"").trim()}function pr(e){return e===401?"TOKEN_EXPIRED":e===403?"API_KEY_FORBIDDEN":e===404?"FORM_CONFIG_NOT_FOUND":"RECOGNIZE_FAILED"}class De{constructor(){d(this,"handlers",new Map)}on(t,n){const r=this.handlers.get(t)??new Set;return r.add(n),this.handlers.set(t,r),()=>this.off(t,n)}off(t,n){var r;(r=this.handlers.get(t))==null||r.delete(n)}emit(t,n){var r;(r=this.handlers.get(t))==null||r.forEach(o=>o(n))}clear(){this.handlers.clear()}}class fr{constructor(){d(this,"instances",new Set);d(this,"active",null)}add(t){this.instances.add(t)}activate(t){this.active&&this.active!==t&&this.active.close(),this.active=t}remove(t){this.instances.delete(t),this.active===t&&(this.active=null)}destroyAll(){this.instances.forEach(t=>t.destroy()),this.instances.clear(),this.active=null}}const hr=[/^(el|rc|ant|radix|headlessui|mui|chakra)-/i,/[0-9a-f]{8,}/i,/\d{6,}/];function x(e){const t=String(e||"").trim();return!t||hr.some(n=>n.test(t))?"":t}function X(e){const t=(e.options||[]).slice(0,20).map(n=>`${n.label}:${String(n.value)}`).join("|");return $([e.fieldId,e.tagName,e.type,x(e.name),x(e.id),e.label,e.placeholder,e.section,t].join("::"))}function $(e){return String(e??"").replace(/\s+/g," ").trim().toLowerCase()}const qe=new WeakMap,gr=['input:not([type="hidden"])',"textarea","select",".el-input__wrapper",".el-select__wrapper",".el-select-v2__wrapper",".el-date-editor",".ant-select-selector",".ant-picker",".n-base-selection",".n-input__input-el",".arco-select-view",".arco-picker",".ivu-select-selection",".semi-select-selection",".t-input__wrap",".van-field__control",".van-field__body","[role='combobox']"].join(", ");class Pe{constructor(t,n,r=[]){this.fields=t,this.schemas=n,this.adapters=r}async apply(t){const n=[],r=[];for(const o of t.values){const i=this.fields.find(l=>l.fieldId===o.fieldId);if(!i){r.push(ye(o.fieldId,"",o.value,"字段不在当前扫描结果中","FIELD_NOT_FOUND"));continue}if(i.scanToken!==t.scanToken){r.push(ye(i.fieldId,i.label,o.value,"页面扫描已过期,请重新扫描","SCAN_TOKEN_EXPIRED"));continue}const s=Sr(this.schemas,o.fieldId),a=s!=null&&s.transform?s.transform(o.value):o.value,c=await this.getValue(i,s);try{const l=s!=null&&s.validate?await s.validate(a):!0;if(l!==!0){r.push(ye(i.fieldId,i.label,a,typeof l=="string"?l:"字段校验未通过","VALIDATE_FAILED"));continue}await this.setValue(i,a,s),n.push({fieldId:i.fieldId,label:i.label,value:a,previousValue:c})}catch(l){r.push(ye(i.fieldId,i.label,a,l instanceof Error?l.message:"字段回填失败","SET_VALUE_FAILED"))}}return{applied:n,skipped:r,warnings:r.length?["部分字段未回填,请查看跳过原因。"]:void 0}}async getValue(t,n){if(n!=null&&n.getValue)return n.getValue();const r=this.matchAdapter(t,n);if(r!=null&&r.getValue)return r.getValue(t);const o=ge(t,n);if(o)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}async setValue(t,n,r){if(r!=null&&r.setValue){await r.setValue(n);const s=ge(t,r);s&&He(s,t);return}const o=ge(t,r);if(!o)throw new Error("页面中未找到对应字段");if(t.fingerprint&&t.fingerprint!==X({...t,tagName:o.tagName.toLowerCase()}))throw new Error("字段结构已变化,请重新扫描");const i=this.matchAdapter(t,r);if(t.disabled||o.hasAttribute("disabled")||o.getAttribute("aria-disabled")==="true")throw new Error("字段不可编辑");if(t.readonly||o.hasAttribute("readonly"))throw new Error("字段不可编辑");if(i){await i.setValue(t,n),He(o,t);return}br(o,n),He(o,t)}matchAdapter(t,n){const r=ge(t,n);return r?this.adapters.find(o=>o.match(r,t)):void 0}}function ge(e,t){var r;if((r=e.element)!=null&&r.isConnected)return e.element;const n=yr(t==null?void 0:t.element);return n||document.querySelector(`[data-smart-fill-id="${$e(e.fieldId)}"]`)}function yr(e){if(e instanceof HTMLElement)return e.isConnected?e:null;if(typeof e=="string")try{const t=document.querySelector(e);return t instanceof HTMLElement?t:null}catch{return null}return null}function br(e,t){if(e instanceof HTMLInputElement&&e.type==="checkbox")e.checked=!!t;else if(e instanceof HTMLInputElement&&e.type==="radio"){const n=document.querySelector(`input[type="radio"][name="${$e(e.name)}"][value="${$e(String(t))}"]`);(n||e).checked=!0}else e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement||e instanceof HTMLSelectElement?e.value=String(t??""):e.isContentEditable&&(e.textContent=String(t??""));e.dispatchEvent(new Event("input",{bubbles:!0})),e.dispatchEvent(new Event("change",{bubbles:!0}))}function He(e,t){for(const n of mr(e,t))wr(n)}function mr(e,t){if(e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement||e instanceof HTMLSelectElement)return[e];const n=Te(e,t==null?void 0:t.type)&&K(e)||e,r=vr(Array.from(n.querySelectorAll(gr)).filter(_t));if(r.length)return r;const o=q(n);return o&&_t(o)?[o]:[n]}function wr(e){var r;e.setAttribute("data-smart-fill-highlighted","true"),(r=qe.get(e))==null||r.abort();const t=new AbortController,n=o=>{o&&"isTrusted"in o&&!o.isTrusted||(e.removeAttribute("data-smart-fill-highlighted"),t.abort(),qe.delete(e))};qe.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})}function vr(e){return e.filter(t=>!e.some(n=>n!==t&&n.contains(t)))}function _t(e){const t=window.getComputedStyle(e);if(t.display==="none"||t.visibility==="hidden"||Number(t.opacity)===0)return!1;const n=e.getBoundingClientRect();return n.width>0&&n.height>0}function ye(e,t,n,r,o){return{fieldId:e,label:t,attemptedValue:n,reason:r,reasonCode:o}}function $e(e){return typeof CSS<"u"&&CSS.escape?CSS.escape(e):e.replace(/["\\]/g,"\\$&")}function Sr(e,t){const n=e.find(o=>o.fieldId===t);if(n)return n;const r=t.includes(":")?t.slice(t.lastIndexOf(":")+1):"";if(r)return e.find(o=>o.rowKey!=null&&String(o.rowKey)===r&&`${o.fieldId}:${o.rowKey}`===t)}const Er=[{key:"mobile",pattern:new RegExp("(?<!\\d)1[3-9]\\d{9}(?!\\d)","g"),confidence:.98,reason:"手机号正则命中"},{key:"idCard",pattern:new RegExp("(?<!\\d)\\d{17}[\\dXx](?!\\d)","g"),confidence:.96,reason:"身份证号正则命中"},{key:"email",pattern:/[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}/g,confidence:.95,reason:"邮箱正则命中"},{key:"bankCard",pattern:new RegExp("(?<!\\d)\\d{16,19}(?!\\d)","g"),confidence:.9,reason:"银行卡号正则命中"},{key:"amount",pattern:/(?:金额|价格|费用|合计|总计)[::\s]*([0-9]+(?:\.[0-9]{1,2})?)/g,confidence:.88,reason:"金额关键词命中"},{key:"date",pattern:/\d{4}[-/.年]\d{1,2}[-/.月]\d{1,2}日?/g,confidence:.86,reason:"日期格式命中"}],F={mobile:["手机","手机号","电话","联系电话","mobile","phone","法人手机号","法人电话","法定代表人手机号","法人手机","紧急联系人手机号","紧急联系人电话","紧急联系电话","联系人手机号","联系人电话","联系手机","配偶手机号","配偶电话","爱人手机号"],idCard:["身份证","证件号","身份证号","idcard","id card","法人身份证","法人身份证号","法定代表人身份证号","配偶身份证","配偶身份证号","爱人身份证号"],email:["邮箱","邮件","email","mail","联系人邮箱","联系邮箱","contact email"],bankCard:["银行卡","卡号","bank","bank card"],amount:["金额","费用","价格","合计","总计","amount","price","申请金额","贷款金额","借款金额","授信金额","申请额度"],date:["日期","时间","有效期","date","申请日期","申请时间","受理日期","进件日期"]},Ct={mobile:"mobile",idCard:"idCard",email:"email",bankCard:"bankCard",amount:"amount",date:"date"};class At{recognize(t,n,r){const o=Mr([...xr(t),...kr(t)]),i=new Set,s=[];for(const a of o.sort((c,l)=>l.confidence-c.confidence)){const c=Cr(a,n,i);c&&(s.push({fieldId:c.fieldId,scanToken:r,label:c.label,value:Tr(a.value,c),displayValue:a.value,confidence:a.confidence,source:"local_rule",reason:a.reason}),i.add(c.fieldId))}return s}}function xr(e){const t=[];for(const n of Er)for(const r of e.matchAll(n.pattern)){const o=Tt(r[1]||r[0]);t.push({key:n.key,value:o,confidence:n.confidence,reason:n.reason,baseKey:Ct[n.key]})}return t}function kr(e){const t=[],n=e.split(/\r?\n|[;,;]/).map(r=>r.trim()).filter(Boolean);for(const r of n){const o=r.match(/^[“"'`]?([^::=]{2,30})[”"'`]?[::=]\s*(.+)$/);if(!o)continue;const i=Ir(o[1]),s=Tt(o[2]);if(!(!i||!s))for(const a of _r(i,s))t.push(a)}return t}function _r(e,t){const n=$(e),r=Lr(t),o=[];return(L(n,F.mobile)||r==="mobile")&&o.push("mobile"),(L(n,F.idCard)||r==="idCard")&&o.push("idCard"),(L(n,F.email)||r==="email")&&o.push("email"),(L(n,F.bankCard)||r==="bankCard")&&o.push("bankCard"),(L(n,F.amount)||r==="amount")&&o.push("amount"),(L(n,F.date)||r==="date")&&o.push("date"),Fr(o).map((i,s)=>({key:i,value:t,confidence:Math.max(.84,.96-s*.04),reason:`键值对文本命中(${e})`,baseKey:Ct[i]}))}function Cr(e,t,n){let r=null;for(const o of t){if(n.has(o.fieldId))continue;const i=Ar(e,o);i>((r==null?void 0:r.score)??0)&&(r={field:o,score:i})}return r&&r.score>=.45?r.field:null}function Ar(e,t){const n=$([t.fieldId,t.label,t.placeholder,t.name,t.id,t.section].join(" ")),r=F[e.key]||[e.key];let o=0;return L(n,r)?o+=.95:L(n,[e.key])&&(o+=.82),n.includes($(e.key))&&(o+=.22),t.required&&(o+=.05),e.baseKey==="amount"&&(t.type==="amount"||t.type==="number")&&(o+=.18),e.baseKey==="date"&&t.type==="date"&&(o+=.18),["email","mobile","idCard","bankCard"].includes(e.baseKey)&&t.type==="text"&&(o+=.08),Math.min(o,1)}function Tr(e,t){var n;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}function Lr(e){const t=e.replace(/\s+/g,"");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"}function Ir(e){return e.replace(/[“”"'`]/g,"").replace(/\s+/g," ").trim()}function Tt(e){return e.replace(/[,。;;]+$/g,"").replace(/^[“”"'`\s]+|[“”"'`\s]+$/g,"").trim()}function L(e,t){const n=$(e);return t.some(r=>n.includes($(r)))}function Mr(e){const t=new Map;for(const n of e){const r=`${n.key}::${n.value}`,o=t.get(r);(!o||o.confidence<n.confidence)&&t.set(r,n)}return[...t.values()]}function Fr(e){return[...new Set(e)]}const Lt=["input","textarea","select","[contenteditable]:not([contenteditable='false'])"].join(", "),Rr=new Set(["hidden","submit","button","image","reset","file","password"]);class It{constructor(t=document){this.root=t}scan(t={}){var l;const n=he("scan");if((l=t.registered)!=null&&l.length)return{scanToken:n,fields:t.registered.map(u=>this.fromSchema(u,n))};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;return{scanToken:n,fields:a.map((u,g)=>this.fromElement(u,g,n,c))}}async scanWithDynamicOptions(t={}){var o,i;const n=this.scan(t);if(!n.fields.length||(o=t.registered)!=null&&o.length)return n;const r=[];for(const s of n.fields){const a=!!((i=s.options)!=null&&i.length)&&!re(s);if(!s.element||a||s.type!=="select"&&s.type!=="cascader"){r.push(s);continue}const c=await pn(s.element),l=c!=null&&c.length&&!re({...s,options:c})?c:void 0;if(!(l!=null&&l.length)){r.push({...s,options:re(s)?void 0:s.options});continue}const u={...s,options:l};u.fingerprint=X({...u,tagName:s.element.tagName.toLowerCase()}),r.push(u)}return{...n,fields:r}}fromSchema(t,n){const r=zr(t.element,this.root),o=r?Ae(r)||xe(r)||r:null,i={fieldId:t.rowKey==null?t.fieldId:`${t.fieldId}:${t.rowKey}`,label:t.label,type:t.type,localRuleMode:t.localRuleMode??"inherit",required:t.required,section:t.section,options:t.options,demoValue:t.demoValue,source:"registered",scanToken:n,element:o||void 0,fingerprint:""};return i.fingerprint=X({...i,tagName:o==null?void 0:o.tagName.toLowerCase()}),i}fromElement(t,n,r,o=this.root){const i=Or(t,n),s=Pr(t,o),a={fieldId:i,fingerprint:"",scanToken:r,type:Dr(t),localRuleMode:"inherit",label:Mt(t),placeholder:Rt(t),name:x(Qe(t))||void 0,id:x(t.id)||void 0,section:qr(t),options:s,required:Nr(t),readonly:$r(t),disabled:Ve(t),source:"form_scan",element:t};return re(a)&&(a.options=void 0),a.fingerprint=X({...a,tagName:t.tagName.toLowerCase()}),a}resolveRoot(t){if(t){const n=Ot(this.root,t);if(n)return n}return this.root}collectVisibleFields(t){const n=new Set,r=[Lt,tt,We,".van-field"].join(", ");for(const s of t.querySelectorAll(r)){if(!(s instanceof HTMLElement))continue;const a=Ae(s)||xe(s);!a||!Ne(a)||Ve(a)||n.add(a)}const o=[...n],i=Array.from(t.querySelectorAll(Lt)).filter(s=>!(s instanceof HTMLElement)||!Ne(s)||Vr(s)||s instanceof HTMLInputElement&&Rr.has((s.type||"").toLowerCase())?!1:!Ve(s)&&!s.hasAttribute("readonly"));return Kr([...i,...o])}detectTopLayerContainer(t){const n=document.activeElement instanceof HTMLElement?document.activeElement:null,r=n==null?void 0:n.closest(Xe);if(r instanceof HTMLElement&&t.some(i=>r.contains(i)))return r;const o=t.map(i=>i.closest(Xe)).filter(i=>i instanceof HTMLElement);return o.length?o.sort((i,s)=>t.filter(a=>s.contains(a)).length-t.filter(a=>i.contains(a)).length)[0]:document.body}}function Or(e,t){const n=e.getAttribute("data-smart-fill-id");if(n)return n;const o=x(e.getAttribute("name"))||x(e.getAttribute("data-smart-fill-key"))||x(Qe(e))||x(e.id)||x(Mt(e))||`smart-fill-${Date.now()}-${t}`;return e.setAttribute("data-smart-fill-id",o),o}function Dr(e){const t=ot(e);if(t)return t;const n=te(e);if(n)return n;if(e instanceof HTMLTextAreaElement)return"textarea";if(e instanceof HTMLSelectElement)return"select";if(e instanceof HTMLInputElement){const r=(e.type||"text").toLowerCase();if(r==="radio")return"radio";if(r==="checkbox")return"checkbox";if(r==="date"||r==="month")return"date";if(r==="number")return"number"}return"text"}function Mt(e){const t=e.getAttribute("aria-label");if(t)return t.trim();if(e.id){const i=document.querySelector(`label[for="${Ke(e.id)}"]`);if(i!=null&&i.textContent)return p(i.textContent)}const n=e.closest(nn),r=n==null?void 0:n.querySelector(rn);if(r!=null&&r.textContent)return p(r.textContent);const o=e.closest("label");if(o){const i=Ft(o,e);if(i)return i}return Rt(e)||e.getAttribute("name")||e.id||"未命名字段"}function Ft(e,t){const n=e.cloneNode(!0);for(const o of n.querySelectorAll('input, textarea, select, button, [role="combobox"], [role="listbox"]'))o.remove();const r=p(n.textContent||"");if(r)return t instanceof HTMLInputElement&&t.value&&r.includes(t.value)?p(r.replace(t.value,""))||void 0:r}function Rt(e){var t;return e.getAttribute("placeholder")||e.getAttribute("aria-placeholder")||((t=e.querySelector("[placeholder]"))==null?void 0:t.getAttribute("placeholder"))||void 0}function qr(e){const t=e.closest("fieldset, section, .panel, .card, .form-section"),n=t==null?void 0:t.querySelector("legend, h1, h2, h3, .title, .section-title");return n!=null&&n.textContent?p(n.textContent):void 0}function Pr(e,t=document){const n=it(e);if(n!=null&&n.length)return n;const r=Je(e);if(r!=null&&r.length)return r;if(e instanceof HTMLSelectElement)return Array.from(e.options).map(o=>({label:p(o.textContent||o.label),value:o.value}));if(e instanceof HTMLInputElement&&(e.type==="radio"||e.type==="checkbox")&&e.name)return Array.from(t.querySelectorAll(`input[name="${Ke(e.name)}"]`)).filter(o=>o.type===e.type&&Ne(o)).map(o=>({label:Hr(o),value:o.value||!0}))}function Hr(e){if(e.id){const n=document.querySelector(`label[for="${Ke(e.id)}"]`);if(n!=null&&n.textContent)return p(n.textContent)}const t=e.closest("label");if(t){const n=Ft(t,e);if(n)return n}return p(e.getAttribute("aria-label")||e.value||"")}function Ne(e){const t=window.getComputedStyle(e);return t.display==="none"||t.visibility==="hidden"||Number(t.opacity)===0?!1:!!(e.offsetWidth||e.offsetHeight||e.getClientRects().length)}function Ve(e){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"||tn.some(t=>e.classList.contains(t))}function $r(e){return e.hasAttribute("readonly")||!!e.querySelector("[readonly]")}function Nr(e){return e.hasAttribute("required")||e.getAttribute("aria-required")==="true"||!!e.querySelector('[required], [aria-required="true"]')}function Vr(e){return Ae(e)!=null||xe(e)!=null}function Kr(e){const t=[];for(const n of e)t.some(r=>r===n||r.contains(n)||n.contains(r))||t.push(n);return t}function zr(e,t){return e instanceof HTMLElement?e:typeof e=="string"?Ot(t,e):null}function Ot(e,t){try{const n=e.querySelector(t);return n instanceof HTMLElement?n:null}catch{return null}}function Ke(e){return typeof CSS<"u"&&CSS.escape?CSS.escape(e):e.replace(/["\\]/g,"\\$&")}const ze=5,Br=10*1024*1024,Ur=50*1024*1024;class jr{constructor(t){d(this,"host",null);d(this,"root",null);d(this,"autoApplyState",null);d(this,"selectedFiles",[]);d(this,"inputText","");d(this,"localPriorityEnabled");d(this,"isOpen",!1);d(this,"dragState",null);d(this,"suppressOpenClick",!1);d(this,"isUploadHovering",!1);d(this,"handleDragMove",t=>{if(!this.dragState||!this.host||t.pointerId!==this.dragState.pointerId)return;const n=t.clientX-this.dragState.startX,r=t.clientY-this.dragState.startY;(Math.abs(n)>3||Math.abs(r)>3)&&(this.dragState.moved=!0);const o=this.host.getBoundingClientRect(),i=Math.max(8,window.innerWidth-o.width-8),s=Math.max(8,window.innerHeight-o.height-8),a=be(this.dragState.startLeft+n,8,i),c=be(this.dragState.startTop+r,8,s);this.host.style.left=`${a}px`,this.host.style.top=`${c}px`});d(this,"handleDragEnd",t=>{!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(()=>{this.suppressOpenClick=!1},0))});d(this,"handleDocumentPaste",t=>{const n=Yr(t);if(!n.length||!this.isOpen||!this.host)return;const r=document.activeElement,o=this.root instanceof ShadowRoot?this.root.activeElement:null;!(r===this.host||this.host.contains(r)||o)&&!this.isUploadHovering||(t.preventDefault(),this.handleImages(n))});this.options=t,this.localPriorityEnabled=t.localPriorityEnabled??!1}mount(t){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)}setOpen(t){this.isOpen=t,this.render(this.isOpen),this.keepHostInViewport()}setLocalPriorityEnabled(t){this.localPriorityEnabled=t;const n=this.query('[data-role="local-priority-toggle"]');n&&(n.checked=t)}setBusy(t,n=""){const r=this.query('[data-role="recognize"]');r&&(r.disabled=t,r.textContent=t?n:this.t("recognize","智能识别"))}setStatus(t){const n=this.query('[data-role="status"]');n&&(n.textContent=t,n.removeAttribute("data-status"))}setError(t){const n=this.query('[data-role="status"]');n&&(n.textContent=t,n.setAttribute("data-status","error"))}setAutoApplyState(t){this.autoApplyState=t,this.render(!0),this.keepHostInViewport(),this.setStatus(this.t("recognized","识别完成,正在自动回填..."))}setApplyResult(t){const n=this.query('[data-role="status"]');n&&(n.textContent=`已回填 ${t.applied.length} 项,跳过 ${t.skipped.length} 项。`,n.setAttribute("data-status",t.skipped.length?"warning":"success"))}destroy(){var t;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}render(t){this.root&&(this.root.innerHTML=`
|
|
11
|
-
|
|
10
|
+
`,document.head.appendChild(e)}async function Ln(e,t){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 M(120);for(const n of t.getTrackedDropdowns())n.isConnected&&(n.style.display="none",n.setAttribute("aria-hidden","true"))}function dt(e){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()}function pt(e){e.focus({preventScroll:!0});const t=e instanceof HTMLInputElement?e:e.querySelector("input");t instanceof HTMLElement&&t.focus({preventScroll:!0})}function ft(e){for(const t of[{key:"ArrowDown",code:"ArrowDown"},{key:"Enter",code:"Enter"},{key:" ",code:"Space"}])e.dispatchEvent(new KeyboardEvent("keydown",{...t,bubbles:!0,composed:!0})),e.dispatchEvent(new KeyboardEvent("keyup",{...t,bubbles:!0,composed:!0}))}function M(e){return new Promise(t=>window.setTimeout(t,e))}function In(){const e=new Map;e.set(window,{left:window.scrollX,top:window.scrollY});for(const t of document.querySelectorAll("*"))(t.scrollTop||t.scrollLeft)&&e.set(t,{left:t.scrollLeft,top:t.scrollTop});return()=>{for(const[t,n]of e)t===window?window.scrollTo(n.left,n.top):t instanceof HTMLElement&&(t.scrollLeft=n.left,t.scrollTop=n.top)}}function ht(e){const t=window.getComputedStyle(e);if(t.display==="none"||t.visibility==="hidden"||Number(t.opacity)===0)return!1;const n=e.getBoundingClientRect();return n.width>0&&n.height>0}function ie(e,t){const n=se(t);if(!n.length)return null;let r=null,o=0;for(const i of e){const s=S(i.value),a=S(i.label);for(const c of n){let l=0;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&&ae(s)===ae(c)||a&&ae(a)===ae(c))&&(l=80),l>o&&(o=l,r=i)}}return o>=80?r:null}function se(e){if(Array.isArray(e))return e.flatMap(n=>se(n));if(typeof e=="object"&&e){const n=e;return[n.label,n.value,n.text,n.answer,n.name].filter(r=>r!=null).map(r=>S(r)).filter(Boolean)}const t=S(e);return t?[t]:[]}function S(e){return String(e??"").replace(/\s+/g,"").replace(/[::,,。.、()()\-_/]/g,"").trim().toLowerCase()}function ae(e){return S(e).replace(/(请选择|选择|状态|情况|类型|方式|所属|是否)$/g,"")}const ce=[".ant-select-item-option",".el-select-dropdown__item",".el-select-v2__option",".el-select-v2__option-item",".n-base-select-option",".ivu-select-item",".arco-select-option",".semi-select-option",".t-select-option",".van-picker-column__item",".van-action-sheet__item",".van-action-sheet__name",".van-cascader__option",".van-dropdown-item__option",".van-radio","[role='option']"].join(", "),Mn=[".el-cascader-panel .el-cascader-menu",".ant-cascader-menu",".van-cascader__options",".n-cascader-menu",".arco-cascader-list"].join(", "),Fn=[".el-cascader-node",".ant-cascader-menu-item",".van-cascader__option",".n-cascader-node",".arco-cascader-option"].join(", "),Rn=".van-picker__confirm, .van-picker__toolbar .van-picker__confirm";async function On(e,t,n,r){const o=yt(t,r);return e instanceof HTMLSelectElement?qn(e,o):_(e)||n==="cascader"?Dn(e,o):(V(e)||E(e)||n==="select"||n==="date",gt(e,o))}function Ie(e){if(e instanceof HTMLSelectElement){const n=e.options[e.selectedIndex];return p((n==null?void 0:n.textContent)||e.value)}if(_(e)){const n=e.querySelector("input");if(n!=null&&n.value)return p(n.value);const r=e.querySelector(".el-cascader__tags-text, .el-cascader__label");return p((r==null?void 0:r.textContent)||"")}if(V(e)||E(e))return pn(e);const t=e.querySelector("input, textarea");return p((t==null?void 0:t.value)||e.textContent||"")}async function qn(e,t){const n=Array.from(e.options).map(o=>({source:o,value:o.value,label:o.textContent})),r=ie(n,t.searchValue);if((r==null?void 0:r.source)instanceof HTMLOptionElement){pe(e,r.source.value),A(e);return}if(!B(e,t))throw new Error("原生下拉框中没有匹配到对应选项")}async function gt(e,t){const n=K(e)||e;if(Re(n,t.searchValue))return;const r=new Set(j());try{if(!await Pn(n)){if(B(n,t))return;throw new Error("自定义下拉框未能成功展开")}const i=await Gn(n,r),s=await $n(t.searchValue,i,!0);if(!(s!=null&&s.source)){if(await ue(n),B(n,t))return;throw new Error("自定义下拉框展开后未找到匹配选项")}if(G(s.source),await b(120),Wn(),A(n),await b(120),Re(n,t.searchValue)||B(n,t)&&Re(n,t.searchValue))return;throw new Error("自定义下拉框点击选项后未成功回填")}finally{await ue(n),await b(80)}}async function Dn(e,t){const n=e.closest(".el-cascader, .ant-cascader, .van-cascader, .n-cascader, .arco-cascader")||e;if(!Fe(n,t.searchValue)){try{if(await Hn(n)){const o=await Kn(t.searchValue);if(await b(180),await ue(n),await b(120),o&&Fe(n,t.searchValue)){A(n);return}}if(zn(n,t.fillValue)&&Fe(n,t.searchValue))return}finally{await ue(n),await b(80)}throw new Error("级联选择框匹配失败")}}function yt(e,t){var s;const n=(s=t==null?void 0:t.options)!=null&&s.length?ie(t.options.map(a=>({value:String(a.value),label:a.label})),e):null,r=C(e),o=p(String((n==null?void 0:n.label)??r??"")),i=p(String((n==null?void 0:n.value)??(n==null?void 0:n.label)??r??""));return{searchValue:n?[e,n.label,n.value]:e,fillValue:i,displayValue:o}}async function Pn(e){const t=Me(e);for(const n of t)if(wt(n),G(n),await b(160),mt(e)||(vt(n),await b(180),mt(e)))return!0;return!1}async function Hn(e){const t=[e,e.querySelector(".el-input__wrapper"),e.querySelector(".el-input"),e.querySelector(".van-field__control"),e.querySelector("input")].filter(n=>n instanceof HTMLElement);for(const n of t)if(wt(n),G(n),await b(180),le().length||(vt(n),await b(180),le().length))return!0;return!1}async function $n(e,t,n=!1){for(let r=0;r<12;r+=1){const o=ie(bt(t,n).map(i=>({source:i,value:Nn(i),label:Vn(i)})),e);if(o)return o;await b(100)}return null}function Nn(e){return e.getAttribute("data-value")||e.getAttribute("data-name")||e.getAttribute("value")||e.getAttribute("name")||e.textContent||""}function Vn(e){var t;return p(((t=e.querySelector(".van-action-sheet__name, .el-cascader-node__label, .ant-cascader-menu-item-content, .n-cascader-node__label, .arco-cascader-option-label"))==null?void 0:t.textContent)||e.textContent||"")}async function Kn(e){const t=Zn(e);if(!t.length)return!1;for(let n=0;n<t.length;n+=1){const r=le();if(!r.length)return n>0;const o=r[r.length-1],i=Array.from(o.querySelectorAll(Fn)).filter(a=>!a.classList.contains("is-disabled")&&a.getAttribute("aria-disabled")!=="true"),s=ie(i.map(a=>{var c;return{source:a,value:a.getAttribute("data-value")||a.textContent,label:((c=a.querySelector(".el-cascader-node__label"))==null?void 0:c.textContent)||a.textContent}}),t[n]);if(!(s!=null&&s.source))return!1;G(s.source),await b(220)}return!le().length||!0}function B(e,t){const n=jn(t)?t:yt(t),r=n.displayValue||C(t),o=n.fillValue||r;if(!r&&!o)return!1;const i=K(e)||e;if(E(i))return Bn(i,r,o);if(e instanceof HTMLSelectElement){let l=Array.from(e.options).find(u=>u.dataset.smartFillFallbackOption==="true");return l||(l=document.createElement("option"),l.dataset.smartFillFallbackOption="true",e.appendChild(l)),l.value=o,l.textContent=r||o,l.selected=!0,pe(e,o),A(e),!0}const s=e.querySelector('input:not([type="hidden"])');if(!(s instanceof HTMLInputElement)||s.disabled)return!1;const a=s.readOnly,c=s.hasAttribute("readonly");try{return a&&(s.readOnly=!1,s.removeAttribute("readonly")),s.focus(),pe(s,r),s.dispatchEvent(new InputEvent("input",{bubbles:!0,composed:!0,data:r,inputType:"insertReplacementText"})),s.dispatchEvent(new Event("change",{bubbles:!0,composed:!0})),A(s),A(e),s.blur(),!0}catch{return!1}finally{a&&(s.readOnly=!0,c&&s.setAttribute("readonly",""))}}function zn(e,t){const n=e.querySelector("input"),r=C(t);return!(n instanceof HTMLInputElement)||!r||n.disabled?!1:B(e,{searchValue:t,fillValue:r,displayValue:r})}function Bn(e,t,n){Un(e);const r=e.querySelector(".van-field__control"),o=Array.from(e.querySelectorAll('input[type="hidden"]')),i=Array.from(e.querySelectorAll('input:not([type="hidden"])'));r instanceof HTMLInputElement?U(r,t||n):r instanceof HTMLElement&&(r.textContent=t||n);for(const s of o)U(s,n);for(const s of i)r!==s&&U(s,t||n);return A(e),!0}function Un(e){const t=e.querySelector(".van-field__control");t instanceof HTMLInputElement?U(t,""):t instanceof HTMLElement&&(t.textContent="");for(const n of e.querySelectorAll("input"))U(n,"")}function U(e,t){if(e.disabled)return;const n=e.readOnly,r=e.hasAttribute("readonly");try{n&&(e.readOnly=!1,e.removeAttribute("readonly")),pe(e,t),e.dispatchEvent(new InputEvent("input",{bubbles:!0,composed:!0,data:t,inputType:t?"insertReplacementText":"deleteContentBackward"})),e.dispatchEvent(new Event("change",{bubbles:!0,composed:!0})),A(e)}finally{n&&(e.readOnly=!0,r&&e.setAttribute("readonly",""))}}function jn(e){return typeof e=="object"&&e!=null&&"searchValue"in e&&"fillValue"in e&&"displayValue"in e}function Me(e){return[e,e.querySelector(".van-field__control"),e.querySelector(".van-field__body"),e.querySelector(".el-select__wrapper"),e.querySelector(".el-select-v2__wrapper"),e.querySelector(".el-select__selection"),e.querySelector(".el-input__wrapper"),e.querySelector(".el-input"),e.querySelector("input"),e.querySelector("[role='combobox']"),e.querySelector("[aria-haspopup='listbox']"),e.querySelector(".ant-select-selector"),e.querySelector(".n-base-selection"),e.querySelector(".arco-select-view"),e.querySelector(".select-trigger"),e.querySelector(".select__wrapper")].filter(n=>n instanceof HTMLElement).filter((n,r,o)=>o.indexOf(n)===r)}function bt(e,t){return(e.length?e:j()).flatMap(o=>o.matches(ce)?[o]:Array.from(o.querySelectorAll(ce))).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":H(o)&&!o.classList.contains("is-disabled")&&!o.classList.contains("ant-select-item-option-disabled")&&o.getAttribute("aria-disabled")!=="true")}function le(){return Array.from(document.querySelectorAll(Mn)).filter(H)}async function Gn(e,t){for(let n=0;n<10;n+=1){const r=Yn(e,t);if(r.length)return r;await b(80)}return j().filter(H)}function Yn(e,t){const n=j(),r=n.filter(i=>!t.has(i));if(r.length)return r.sort((i,s)=>de(s)-de(i));const o=new Set(Me(e).flatMap(i=>[i.getAttribute("aria-controls"),i.getAttribute("aria-owns")]).filter(i=>!!i));if(o.size){const i=n.filter(s=>o.has(s.id));if(i.length)return i}return n.filter(i=>H(i)&&(i.querySelector(ce)||i.matches(ce))).sort((i,s)=>de(s)-de(i)).slice(0,1)}function mt(e){return bt(j().filter(H),!1).length>0?!0:Me(e).some(t=>t.getAttribute("aria-expanded")==="true"||t.classList.contains("is-focus")||t.classList.contains("is-focused"))}function Fe(e,t){const n=S(Ie(e)),r=S(C(t));return!n||!r?!1:n===r||n.includes(r)||r.includes(n)}function Re(e,t){const n=S(Ie(e));if(!n)return!1;const r=se(t);if(!r.length){const o=S(C(t));return o?n===o||n.includes(o)||o.includes(n):!1}return r.some(o=>{const i=S(o);return!!i&&(n===i||n.includes(i)||i.includes(n))})}function Wn(){const e=document.querySelector(Rn);e&&H(e)&&G(e)}async function ue(e){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)}function j(){return Array.from(document.querySelectorAll(Xn()))}function de(e){const t=e.getBoundingClientRect(),n=Number.parseInt(window.getComputedStyle(e).zIndex||"0",10);return(Number.isNaN(n)?0:n)*10+t.width*t.height}function Xn(){return[".el-select-dropdown",".el-cascader__dropdown",".el-cascader-panel",".el-select__popper",".el-select-v2__popper",".el-popper.el-cascader__dropdown",".el-popper.el-select__popper",".el-popper.el-select-v2__popper",".el-popper",".ant-select-dropdown",".ant-cascader-menus",".n-base-select-menu",".n-cascader-menu",".arco-select-dropdown",".arco-cascader-panel",".semi-select-dropdown",".t-select__dropdown",".van-popup",".van-action-sheet",".van-dropdown-item__content",".van-picker","[role='listbox']"].join(", ")}function C(e){if(e==null)return"";if(typeof e=="string"||typeof e=="number"||typeof e=="boolean")return p(String(e));if(Array.isArray(e))return e.map(t=>C(t)).filter(Boolean).join(" ");if(typeof e=="object"){const t=e;for(const n of["label","text","value","answer","name"]){const r=C(t[n]);if(r)return r}}return p(String(e))}function Zn(e){const t=C(e);if(!t)return[];if(t.includes("/")||t.includes("、"))return t.split(/[//、]/).map(r=>r.trim()).filter(Boolean);const n=se(e);return n.length?[p(n[0])]:[t]}function pe(e,t){var o;const n=Object.getPrototypeOf(e),r=Object.getOwnPropertyDescriptor(n,"value");(o=r==null?void 0:r.set)==null||o.call(e,t)}function A(e){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}))}function G(e){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()}function wt(e){e.focus({preventScroll:!0});const t=e instanceof HTMLInputElement?e:e.querySelector("input");t instanceof HTMLElement&&t.focus({preventScroll:!0})}function vt(e){for(const t of[{key:"ArrowDown",code:"ArrowDown"},{key:"Enter",code:"Enter"},{key:" ",code:"Space"}])e.dispatchEvent(new KeyboardEvent("keydown",{...t,bubbles:!0,composed:!0})),e.dispatchEvent(new KeyboardEvent("keyup",{...t,bubbles:!0,composed:!0}))}function H(e){const t=window.getComputedStyle(e);if(t.display==="none"||t.visibility==="hidden"||Number(t.opacity)===0)return!1;const n=e.getBoundingClientRect();return n.width>0&&n.height>0}function b(e){return new Promise(t=>window.setTimeout(t,e))}const St=new Set(["select","cascader","date"]),Oe={name:"ui-framework",match:e=>e.matches(We)||Ze(e)||!Qn(e)&&Te(e),getValue:e=>{var o,i;const t=e.element;if(!t)return;const n=q(t);if((n==null?void 0:n.kind)==="switch")return N(t);if((n==null?void 0:n.kind)==="radioGroup")return rr(t);if((n==null?void 0:n.kind)==="checkboxGroup")return or(t);const r=e.type||te(t)||(n==null?void 0:n.type);return r&&St.has(r)?Ie(t):n?((i=D(t))==null?void 0:i.value)||t.textContent||void 0:(o=D(t))==null?void 0:o.value},setValue:async(e,t)=>{const n=e.element;if(!n)return;const r=q(n);if((r==null?void 0:r.kind)==="switch"){er(n,t);return}if((r==null?void 0:r.kind)==="radioGroup"){nr(n,t);return}if((r==null?void 0:r.kind)==="checkboxGroup"){tr(n,t);return}const o=e.type||te(n)||(r==null?void 0:r.type);if(o&&St.has(o)||Te(n,o||void 0)){await On(n,t,o||"select",e);return}const i=D(n);if(i){ir(i,t);return}n.dispatchEvent(new Event("change",{bubbles:!0}))}},Jn=Oe;function Qn(e){return e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement||e instanceof HTMLSelectElement}function er(e,t){N(e)!==sr(t)&&fe(e)}function tr(e,t){var o;const n=new Set(ar(t).map(T)),r=Je(e)||[];for(const i of Y(e)){const s=W(i.textContent||""),a=i.getAttribute("value")||((o=i.querySelector("input"))==null?void 0:o.value)||s,c=N(i),l=n.has(T(String(a)))||n.has(T(s));c!==l&&fe(i)}if(!Y(e).length&&r.length)for(const i of r)(n.has(T(String(i.value)))||n.has(T(i.label)))&&fe(e)}function nr(e,t){const n=T(String(t??"")),r=Y(e).find(o=>{var a;const i=W(o.textContent||""),s=o.getAttribute("value")||((a=o.querySelector("input"))==null?void 0:a.value)||i;return T(String(s))===n||T(i)===n});r&&fe(r)}function rr(e){var n;const t=Y(e).find(r=>N(r));if(t)return t.getAttribute("value")||((n=t.querySelector("input"))==null?void 0:n.value)||W(t.textContent||"")}function or(e){return Y(e).filter(t=>N(t)).map(t=>{var n;return t.getAttribute("value")||((n=t.querySelector("input"))==null?void 0:n.value)||W(t.textContent||"")})}function Y(e){const t=q(e);return t!=null&&t.optionSelector?Array.from(e.querySelectorAll(t.optionSelector)):[]}function ir(e,t){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}))}function fe(e){e.dispatchEvent(new MouseEvent("click",{bubbles:!0,cancelable:!0,view:window}))}function sr(e){return typeof e=="boolean"?e:["true","1","是","开启","启用","yes","y"].includes(String(e??"").trim().toLowerCase())}function ar(e){return Array.isArray(e)?e.map(String):String(e??"").split(/[,,;;、]/).map(t=>t.trim()).filter(Boolean)}function T(e){return W(e).toLowerCase()}function W(e){return e.replace(/\s+/g," ").trim()}const Et="https://uat.kingdeefin.com";class xt extends Error{constructor(n){super(n.message);d(this,"smartFillError");this.name="SmartFillException",this.smartFillError=n}}function w(e,t,n,r={}){return new xt({code:e,message:t,stage:n,...r})}function kt(e,t,n="RECOGNIZE_FAILED"){return e instanceof xt?e.smartFillError:{code:n,message:e instanceof Error?e.message:String(e||"智能录入异常"),stage:t,retryable:t==="recognize"}}function he(e="sf"){return`${e}_${Date.now().toString(36)}_${Math.random().toString(36).slice(2,10)}`}class cr{constructor(t){d(this,"seToken","");d(this,"baseURL",Et);this.config=t}setAccessToken(t){this.seToken=t}async createSession(){if(!/^seKey-[A-Za-z0-9_-]{6,}$/.test(this.config.apiKey))throw w("API_KEY_INVALID","apiKey 格式不正确,应以 seKey- 开头。","setup");return{apiKey:this.config.apiKey,rulesVersion:"0.0.1"}}async getFormConfig(t){return t?this.request(`/sdk/forms/${encodeURIComponent(t)}`,{method:"GET"}):null}async resolveInputText(t){var i,s,a,c;const n=(i=t.images)!=null&&i.length?t.images:[],r=((s=t.text)==null?void 0:s.trim())||"";if(!n.length)return{text:r,usedOcr:!1};(a=t.onStatusChange)==null||a.call(t,"image_uploading");const o=await this.recognizeImages(n);return(c=t.onStatusChange)==null||c.call(t,"image_recognizing"),{text:o,usedOcr:!0}}async recognize(t){var s,a;const n=performance.now(),r=(s=t.text)==null?void 0:s.trim();(a=t.onStatusChange)==null||a.call(t,"recognizing");const o=await this.request("/fcloud/flow-product/agentChat/smartEntry",{method:"POST",body:JSON.stringify({formCode:t.formCode||"",configVersion:t.configVersion||"",formMsg:t.fields.map(({fingerprint:c,element:l,localRuleMode:u,scanToken:g,source:R,...ee})=>ee),userInputMsg:r||""})}),i=ur(o,t.fields,t.scanToken);return console.log("suggestions",i),{scanToken:t.scanToken,suggestions:i,trace:o.trace||{traceId:he("trace"),usedOcr:!!t.usedOcr,usedAi:!0,durationMs:Math.round(performance.now()-n)}}}async recognizeImages(t){const n=new FormData;t.forEach(i=>{n.append("image",i,i.name)});const r=await this.request("/fcloud/flow-product/agentChat/smartEntry/ocr",{method:"POST",body:n}),o=pr(r);if(!o)throw w("RECOGNIZE_FAILED","图片识别未提取到文本内容。","recognize");return o}async request(t,n){const r=new AbortController,o=window.setTimeout(()=>r.abort(),this.config.requestTimeoutMs??3e4),i=new Headers(n.headers);n.body&&!(n.body instanceof FormData)&&!i.has("Content-Type")&&i.set("Content-Type","application/json"),i.set("x-trace-id",he("trace")),this.seToken&&i.set("seToken",`${this.seToken}`);try{const s=await fetch(`${this.baseURL}${t}`,{...n,headers:i,signal:r.signal});if(!s.ok)throw w(fr(s.status),await s.text(),t.includes("session")?"setup":"recognize",{retryable:s.status>=500||s.status===429});return s.json()}catch(s){throw s instanceof DOMException&&s.name==="AbortError"?w("RECOGNIZE_TIMEOUT","识别请求超时,请稍后重试。","recognize",{retryable:!0}):s}finally{window.clearTimeout(o)}}}const lr=.95;function ur(e,t,n){var i;const r=new Map(t.map(s=>[s.fieldId,s]));return(((i=e.data)==null?void 0:i.fieldValues)||[]).filter(s=>!!(s!=null&&s.fieldId)).map(s=>{const a=r.get(s.fieldId);return{fieldId:s.fieldId,scanToken:n,label:s.label||(a==null?void 0:a.label)||s.fieldId,value:s.value,displayValue:s.value==null?"":String(s.value),confidence:dr(s.confidence),source:s.source||"ai",warnings:s.warnings}})}function dr(e){return typeof e!="number"||Number.isNaN(e)?lr:e<0?0:e>1?1:e}function pr(e){var n;const t=typeof e.data=="string"?e.data:((n=e.data)==null?void 0:n.text)||e.text||"";return String(t||"").trim()}function fr(e){return e===401?"TOKEN_EXPIRED":e===403?"API_KEY_FORBIDDEN":e===404?"FORM_CONFIG_NOT_FOUND":"RECOGNIZE_FAILED"}class qe{constructor(){d(this,"handlers",new Map)}on(t,n){const r=this.handlers.get(t)??new Set;return r.add(n),this.handlers.set(t,r),()=>this.off(t,n)}off(t,n){var r;(r=this.handlers.get(t))==null||r.delete(n)}emit(t,n){var r;(r=this.handlers.get(t))==null||r.forEach(o=>o(n))}clear(){this.handlers.clear()}}class hr{constructor(){d(this,"instances",new Set);d(this,"active",null)}add(t){this.instances.add(t)}activate(t){this.active&&this.active!==t&&this.active.close(),this.active=t}remove(t){this.instances.delete(t),this.active===t&&(this.active=null)}destroyAll(){this.instances.forEach(t=>t.destroy()),this.instances.clear(),this.active=null}}const gr=[/^(el|rc|ant|radix|headlessui|mui|chakra)-/i,/[0-9a-f]{8,}/i,/\d{6,}/];function x(e){const t=String(e||"").trim();return!t||gr.some(n=>n.test(t))?"":t}function X(e){const t=(e.options||[]).slice(0,20).map(n=>`${n.label}:${String(n.value)}`).join("|");return $([e.fieldId,e.tagName,e.type,x(e.name),x(e.id),e.label,e.placeholder,e.section,t].join("::"))}function $(e){return String(e??"").replace(/\s+/g," ").trim().toLowerCase()}const _t="smart-fill-highlight-style",yr=`
|
|
11
|
+
[data-smart-fill-highlighted="true"] {
|
|
12
|
+
background: #eaf3ff !important;
|
|
13
|
+
box-shadow: 0 0 0 1px #91caff inset !important;
|
|
14
|
+
transition: background-color 0.2s ease, box-shadow 0.2s ease !important;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
[data-smart-fill-highlighted="true"] input:not([type="hidden"]),
|
|
18
|
+
[data-smart-fill-highlighted="true"] textarea {
|
|
19
|
+
background: #eaf3ff !important;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
[data-smart-fill-highlighted="true"].el-select,
|
|
23
|
+
[data-smart-fill-highlighted="true"].el-select-v2,
|
|
24
|
+
[data-smart-fill-highlighted="true"] .el-select__wrapper,
|
|
25
|
+
[data-smart-fill-highlighted="true"] .el-select-v2__wrapper,
|
|
26
|
+
[data-smart-fill-highlighted="true"] .el-input__wrapper,
|
|
27
|
+
[data-smart-fill-highlighted="true"] .el-date-editor,
|
|
28
|
+
[data-smart-fill-highlighted="true"] .ant-select-selector,
|
|
29
|
+
[data-smart-fill-highlighted="true"] .ant-picker,
|
|
30
|
+
[data-smart-fill-highlighted="true"] .n-base-selection,
|
|
31
|
+
[data-smart-fill-highlighted="true"] .arco-select-view,
|
|
32
|
+
[data-smart-fill-highlighted="true"] .van-field__body,
|
|
33
|
+
[data-smart-fill-highlighted="true"] .van-field__control {
|
|
34
|
+
background: #eaf3ff !important;
|
|
35
|
+
box-shadow: 0 0 0 1px #91caff inset !important;
|
|
36
|
+
}
|
|
37
|
+
`.trim();function br(){if(typeof document>"u"||document.getElementById(_t))return;const e=document.createElement("style");e.id=_t,e.textContent=yr,document.head.appendChild(e)}const De=new WeakMap,mr=['input:not([type="hidden"])',"textarea","select",".el-input__wrapper",".el-select__wrapper",".el-select-v2__wrapper",".el-date-editor",".ant-select-selector",".ant-picker",".n-base-selection",".n-input__input-el",".arco-select-view",".arco-picker",".ivu-select-selection",".semi-select-selection",".t-input__wrap",".van-field__control",".van-field__body","[role='combobox']"].join(", ");class Pe{constructor(t,n,r=[]){this.fields=t,this.schemas=n,this.adapters=r}async apply(t){const n=[],r=[];for(const o of t.values){const i=this.fields.find(l=>l.fieldId===o.fieldId);if(!i){r.push(ye(o.fieldId,"",o.value,"字段不在当前扫描结果中","FIELD_NOT_FOUND"));continue}if(i.scanToken!==t.scanToken){r.push(ye(i.fieldId,i.label,o.value,"页面扫描已过期,请重新扫描","SCAN_TOKEN_EXPIRED"));continue}const s=kr(this.schemas,o.fieldId),a=s!=null&&s.transform?s.transform(o.value):o.value,c=await this.getValue(i,s);try{const l=s!=null&&s.validate?await s.validate(a):!0;if(l!==!0){r.push(ye(i.fieldId,i.label,a,typeof l=="string"?l:"字段校验未通过","VALIDATE_FAILED"));continue}await this.setValue(i,a,s),n.push({fieldId:i.fieldId,label:i.label,value:a,previousValue:c})}catch(l){r.push(ye(i.fieldId,i.label,a,l instanceof Error?l.message:"字段回填失败","SET_VALUE_FAILED"))}}return{applied:n,skipped:r,warnings:r.length?["部分字段未回填,请查看跳过原因。"]:void 0}}async getValue(t,n){if(n!=null&&n.getValue)return n.getValue();const r=this.matchAdapter(t,n);if(r!=null&&r.getValue)return r.getValue(t);const o=ge(t,n);if(o)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}async setValue(t,n,r){if(r!=null&&r.setValue){await r.setValue(n);const s=ge(t,r);s&&He(s,t);return}const o=ge(t,r);if(!o)throw new Error("页面中未找到对应字段");if(t.fingerprint&&t.fingerprint!==X({...t,tagName:o.tagName.toLowerCase()}))throw new Error("字段结构已变化,请重新扫描");const i=this.matchAdapter(t,r);if(t.disabled||o.hasAttribute("disabled")||o.getAttribute("aria-disabled")==="true")throw new Error("字段不可编辑");if(t.readonly||o.hasAttribute("readonly"))throw new Error("字段不可编辑");if(i){await i.setValue(t,n),He(o,t);return}vr(o,n),He(o,t)}matchAdapter(t,n){const r=ge(t,n);return r?this.adapters.find(o=>o.match(r,t)):void 0}}function ge(e,t){var r;if((r=e.element)!=null&&r.isConnected)return e.element;const n=wr(t==null?void 0:t.element);return n||document.querySelector(`[data-smart-fill-id="${$e(e.fieldId)}"]`)}function wr(e){if(e instanceof HTMLElement)return e.isConnected?e:null;if(typeof e=="string")try{const t=document.querySelector(e);return t instanceof HTMLElement?t:null}catch{return null}return null}function vr(e,t){if(e instanceof HTMLInputElement&&e.type==="checkbox")e.checked=!!t;else if(e instanceof HTMLInputElement&&e.type==="radio"){const n=document.querySelector(`input[type="radio"][name="${$e(e.name)}"][value="${$e(String(t))}"]`);(n||e).checked=!0}else e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement||e instanceof HTMLSelectElement?e.value=String(t??""):e.isContentEditable&&(e.textContent=String(t??""));e.dispatchEvent(new Event("input",{bubbles:!0})),e.dispatchEvent(new Event("change",{bubbles:!0}))}function He(e,t){br();const n=Sr(e,t),r=()=>{for(const o of n)o.isConnected&&Er(o)};typeof requestAnimationFrame=="function"?requestAnimationFrame(()=>requestAnimationFrame(r)):r()}function Sr(e,t){if(e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement||e instanceof HTMLSelectElement)return[e];const n=Te(e,t==null?void 0:t.type)&&K(e)||e,r=xr(Array.from(n.querySelectorAll(mr)).filter(Ct));if(r.length)return r;const o=D(n);return o&&Ct(o)?[o]:[n]}function Er(e){var r;e.setAttribute("data-smart-fill-highlighted","true"),(r=De.get(e))==null||r.abort();const t=new AbortController,n=o=>{o&&"isTrusted"in o&&!o.isTrusted||(e.removeAttribute("data-smart-fill-highlighted"),t.abort(),De.delete(e))};De.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})}function xr(e){return e.filter(t=>!e.some(n=>n!==t&&n.contains(t)))}function Ct(e){const t=window.getComputedStyle(e);if(t.display==="none"||t.visibility==="hidden"||Number(t.opacity)===0)return!1;const n=e.getBoundingClientRect();return n.width>0&&n.height>0}function ye(e,t,n,r,o){return{fieldId:e,label:t,attemptedValue:n,reason:r,reasonCode:o}}function $e(e){return typeof CSS<"u"&&CSS.escape?CSS.escape(e):e.replace(/["\\]/g,"\\$&")}function kr(e,t){const n=e.find(o=>o.fieldId===t);if(n)return n;const r=t.includes(":")?t.slice(t.lastIndexOf(":")+1):"";if(r)return e.find(o=>o.rowKey!=null&&String(o.rowKey)===r&&`${o.fieldId}:${o.rowKey}`===t)}const _r=[{key:"mobile",pattern:new RegExp("(?<!\\d)1[3-9]\\d{9}(?!\\d)","g"),confidence:.98,reason:"手机号正则命中"},{key:"idCard",pattern:new RegExp("(?<!\\d)\\d{17}[\\dXx](?!\\d)","g"),confidence:.96,reason:"身份证号正则命中"},{key:"email",pattern:/[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}/g,confidence:.95,reason:"邮箱正则命中"},{key:"bankCard",pattern:new RegExp("(?<!\\d)\\d{16,19}(?!\\d)","g"),confidence:.9,reason:"银行卡号正则命中"},{key:"amount",pattern:/(?:金额|价格|费用|合计|总计)[::\s]*([0-9]+(?:\.[0-9]{1,2})?)/g,confidence:.88,reason:"金额关键词命中"},{key:"date",pattern:/\d{4}[-/.年]\d{1,2}[-/.月]\d{1,2}日?/g,confidence:.86,reason:"日期格式命中"}],F={mobile:["手机","手机号","电话","联系电话","mobile","phone","法人手机号","法人电话","法定代表人手机号","法人手机","紧急联系人手机号","紧急联系人电话","紧急联系电话","联系人手机号","联系人电话","联系手机","配偶手机号","配偶电话","爱人手机号"],idCard:["身份证","证件号","身份证号","idcard","id card","法人身份证","法人身份证号","法定代表人身份证号","配偶身份证","配偶身份证号","爱人身份证号"],email:["邮箱","邮件","email","mail","联系人邮箱","联系邮箱","contact email"],bankCard:["银行卡","卡号","bank","bank card"],amount:["金额","费用","价格","合计","总计","amount","price","申请金额","贷款金额","借款金额","授信金额","申请额度"],date:["日期","时间","有效期","date","申请日期","申请时间","受理日期","进件日期"]},At={mobile:"mobile",idCard:"idCard",email:"email",bankCard:"bankCard",amount:"amount",date:"date"};class Tt{recognize(t,n,r){const o=Or([...Cr(t),...Ar(t)]),i=new Set,s=[];for(const a of o.sort((c,l)=>l.confidence-c.confidence)){const c=Lr(a,n,i);c&&(s.push({fieldId:c.fieldId,scanToken:r,label:c.label,value:Mr(a.value,c),displayValue:a.value,confidence:a.confidence,source:"local_rule",reason:a.reason}),i.add(c.fieldId))}return s}}function Cr(e){const t=[];for(const n of _r)for(const r of e.matchAll(n.pattern)){const o=Lt(r[1]||r[0]);t.push({key:n.key,value:o,confidence:n.confidence,reason:n.reason,baseKey:At[n.key]})}return t}function Ar(e){const t=[],n=e.split(/\r?\n|[;,;]/).map(r=>r.trim()).filter(Boolean);for(const r of n){const o=r.match(/^[“"'`]?([^::=]{2,30})[”"'`]?[::=]\s*(.+)$/);if(!o)continue;const i=Rr(o[1]),s=Lt(o[2]);if(!(!i||!s))for(const a of Tr(i,s))t.push(a)}return t}function Tr(e,t){const n=$(e),r=Fr(t),o=[];return(L(n,F.mobile)||r==="mobile")&&o.push("mobile"),(L(n,F.idCard)||r==="idCard")&&o.push("idCard"),(L(n,F.email)||r==="email")&&o.push("email"),(L(n,F.bankCard)||r==="bankCard")&&o.push("bankCard"),(L(n,F.amount)||r==="amount")&&o.push("amount"),(L(n,F.date)||r==="date")&&o.push("date"),qr(o).map((i,s)=>({key:i,value:t,confidence:Math.max(.84,.96-s*.04),reason:`键值对文本命中(${e})`,baseKey:At[i]}))}function Lr(e,t,n){let r=null;for(const o of t){if(n.has(o.fieldId))continue;const i=Ir(e,o);i>((r==null?void 0:r.score)??0)&&(r={field:o,score:i})}return r&&r.score>=.45?r.field:null}function Ir(e,t){const n=$([t.fieldId,t.label,t.placeholder,t.name,t.id,t.section].join(" ")),r=F[e.key]||[e.key];let o=0;return L(n,r)?o+=.95:L(n,[e.key])&&(o+=.82),n.includes($(e.key))&&(o+=.22),t.required&&(o+=.05),e.baseKey==="amount"&&(t.type==="amount"||t.type==="number")&&(o+=.18),e.baseKey==="date"&&t.type==="date"&&(o+=.18),["email","mobile","idCard","bankCard"].includes(e.baseKey)&&t.type==="text"&&(o+=.08),Math.min(o,1)}function Mr(e,t){var n;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}function Fr(e){const t=e.replace(/\s+/g,"");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"}function Rr(e){return e.replace(/[“”"'`]/g,"").replace(/\s+/g," ").trim()}function Lt(e){return e.replace(/[,。;;]+$/g,"").replace(/^[“”"'`\s]+|[“”"'`\s]+$/g,"").trim()}function L(e,t){const n=$(e);return t.some(r=>n.includes($(r)))}function Or(e){const t=new Map;for(const n of e){const r=`${n.key}::${n.value}`,o=t.get(r);(!o||o.confidence<n.confidence)&&t.set(r,n)}return[...t.values()]}function qr(e){return[...new Set(e)]}const It=["input","textarea","select","[contenteditable]:not([contenteditable='false'])"].join(", "),Dr=new Set(["hidden","submit","button","image","reset","file","password"]);class Mt{constructor(t=document){this.root=t}scan(t={}){var l;const n=he("scan");if((l=t.registered)!=null&&l.length)return{scanToken:n,fields:t.registered.map(u=>this.fromSchema(u,n))};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;return{scanToken:n,fields:a.map((u,g)=>this.fromElement(u,g,n,c))}}async scanWithDynamicOptions(t={}){var o,i;const n=this.scan(t);if(!n.fields.length||(o=t.registered)!=null&&o.length)return n;const r=[];for(const s of n.fields){const a=!!((i=s.options)!=null&&i.length)&&!re(s);if(!s.element||a||s.type!=="select"&&s.type!=="cascader"){r.push(s);continue}const c=await fn(s.element),l=c!=null&&c.length&&!re({...s,options:c})?c:void 0;if(!(l!=null&&l.length)){r.push({...s,options:re(s)?void 0:s.options});continue}const u={...s,options:l};u.fingerprint=X({...u,tagName:s.element.tagName.toLowerCase()}),r.push(u)}return{...n,fields:r}}fromSchema(t,n){const r=jr(t.element,this.root),o=r?Ae(r)||xe(r)||r:null,i={fieldId:t.rowKey==null?t.fieldId:`${t.fieldId}:${t.rowKey}`,label:t.label,type:t.type,localRuleMode:t.localRuleMode??"inherit",required:t.required,section:t.section,options:t.options,demoValue:t.demoValue,source:"registered",scanToken:n,element:o||void 0,fingerprint:""};return i.fingerprint=X({...i,tagName:o==null?void 0:o.tagName.toLowerCase()}),i}fromElement(t,n,r,o=this.root){const i=Pr(t,n),s=Nr(t,o),a={fieldId:i,fingerprint:"",scanToken:r,type:Hr(t),localRuleMode:"inherit",label:Ft(t),placeholder:Ot(t),name:x(Qe(t))||void 0,id:x(t.id)||void 0,section:$r(t),options:s,required:zr(t),readonly:Kr(t),disabled:Ve(t),source:"form_scan",element:t};return re(a)&&(a.options=void 0),a.fingerprint=X({...a,tagName:t.tagName.toLowerCase()}),a}resolveRoot(t){if(t){const n=qt(this.root,t);if(n)return n}return this.root}collectVisibleFields(t){const n=new Set,r=[It,tt,We,".van-field"].join(", ");for(const s of t.querySelectorAll(r)){if(!(s instanceof HTMLElement))continue;const a=Ae(s)||xe(s);!a||!Ne(a)||Ve(a)||n.add(a)}const o=[...n],i=Array.from(t.querySelectorAll(It)).filter(s=>!(s instanceof HTMLElement)||!Ne(s)||Br(s)||s instanceof HTMLInputElement&&Dr.has((s.type||"").toLowerCase())?!1:!Ve(s)&&!s.hasAttribute("readonly"));return Ur([...i,...o])}detectTopLayerContainer(t){const n=document.activeElement instanceof HTMLElement?document.activeElement:null,r=n==null?void 0:n.closest(Xe);if(r instanceof HTMLElement&&t.some(i=>r.contains(i)))return r;const o=t.map(i=>i.closest(Xe)).filter(i=>i instanceof HTMLElement);return o.length?o.sort((i,s)=>t.filter(a=>s.contains(a)).length-t.filter(a=>i.contains(a)).length)[0]:document.body}}function Pr(e,t){const n=e.getAttribute("data-smart-fill-id");if(n)return n;const o=x(e.getAttribute("name"))||x(e.getAttribute("data-smart-fill-key"))||x(Qe(e))||x(e.id)||x(Ft(e))||`smart-fill-${Date.now()}-${t}`;return e.setAttribute("data-smart-fill-id",o),o}function Hr(e){const t=ot(e);if(t)return t;const n=te(e);if(n)return n;if(e instanceof HTMLTextAreaElement)return"textarea";if(e instanceof HTMLSelectElement)return"select";if(e instanceof HTMLInputElement){const r=(e.type||"text").toLowerCase();if(r==="radio")return"radio";if(r==="checkbox")return"checkbox";if(r==="date"||r==="month")return"date";if(r==="number")return"number"}return"text"}function Ft(e){const t=e.getAttribute("aria-label");if(t)return t.trim();if(e.id){const i=document.querySelector(`label[for="${Ke(e.id)}"]`);if(i!=null&&i.textContent)return p(i.textContent)}const n=e.closest(rn),r=n==null?void 0:n.querySelector(on);if(r!=null&&r.textContent)return p(r.textContent);const o=e.closest("label");if(o){const i=Rt(o,e);if(i)return i}return Ot(e)||e.getAttribute("name")||e.id||"未命名字段"}function Rt(e,t){const n=e.cloneNode(!0);for(const o of n.querySelectorAll('input, textarea, select, button, [role="combobox"], [role="listbox"]'))o.remove();const r=p(n.textContent||"");if(r)return t instanceof HTMLInputElement&&t.value&&r.includes(t.value)?p(r.replace(t.value,""))||void 0:r}function Ot(e){var t;return e.getAttribute("placeholder")||e.getAttribute("aria-placeholder")||((t=e.querySelector("[placeholder]"))==null?void 0:t.getAttribute("placeholder"))||void 0}function $r(e){const t=e.closest("fieldset, section, .panel, .card, .form-section"),n=t==null?void 0:t.querySelector("legend, h1, h2, h3, .title, .section-title");return n!=null&&n.textContent?p(n.textContent):void 0}function Nr(e,t=document){const n=it(e);if(n!=null&&n.length)return n;const r=Je(e);if(r!=null&&r.length)return r;if(e instanceof HTMLSelectElement)return Array.from(e.options).map(o=>({label:p(o.textContent||o.label),value:o.value}));if(e instanceof HTMLInputElement&&(e.type==="radio"||e.type==="checkbox")&&e.name)return Array.from(t.querySelectorAll(`input[name="${Ke(e.name)}"]`)).filter(o=>o.type===e.type&&Ne(o)).map(o=>({label:Vr(o),value:o.value||!0}))}function Vr(e){if(e.id){const n=document.querySelector(`label[for="${Ke(e.id)}"]`);if(n!=null&&n.textContent)return p(n.textContent)}const t=e.closest("label");if(t){const n=Rt(t,e);if(n)return n}return p(e.getAttribute("aria-label")||e.value||"")}function Ne(e){const t=window.getComputedStyle(e);return t.display==="none"||t.visibility==="hidden"||Number(t.opacity)===0?!1:!!(e.offsetWidth||e.offsetHeight||e.getClientRects().length)}function Ve(e){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"||nn.some(t=>e.classList.contains(t))}function Kr(e){return e.hasAttribute("readonly")||!!e.querySelector("[readonly]")}function zr(e){return e.hasAttribute("required")||e.getAttribute("aria-required")==="true"||!!e.querySelector('[required], [aria-required="true"]')}function Br(e){return Ae(e)!=null||xe(e)!=null}function Ur(e){const t=[];for(const n of e)t.some(r=>r===n||r.contains(n)||n.contains(r))||t.push(n);return t}function jr(e,t){return e instanceof HTMLElement?e:typeof e=="string"?qt(t,e):null}function qt(e,t){try{const n=e.querySelector(t);return n instanceof HTMLElement?n:null}catch{return null}}function Ke(e){return typeof CSS<"u"&&CSS.escape?CSS.escape(e):e.replace(/["\\]/g,"\\$&")}const ze=5,Gr=10*1024*1024,Yr=50*1024*1024;class Wr{constructor(t){d(this,"host",null);d(this,"root",null);d(this,"autoApplyState",null);d(this,"selectedFiles",[]);d(this,"inputText","");d(this,"localPriorityEnabled");d(this,"isOpen",!1);d(this,"dragState",null);d(this,"suppressOpenClick",!1);d(this,"isUploadHovering",!1);d(this,"handleDragMove",t=>{if(!this.dragState||!this.host||t.pointerId!==this.dragState.pointerId)return;const n=t.clientX-this.dragState.startX,r=t.clientY-this.dragState.startY;(Math.abs(n)>3||Math.abs(r)>3)&&(this.dragState.moved=!0);const o=this.host.getBoundingClientRect(),i=Math.max(8,window.innerWidth-o.width-8),s=Math.max(8,window.innerHeight-o.height-8),a=be(this.dragState.startLeft+n,8,i),c=be(this.dragState.startTop+r,8,s);this.host.style.left=`${a}px`,this.host.style.top=`${c}px`});d(this,"handleDragEnd",t=>{!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(()=>{this.suppressOpenClick=!1},0))});d(this,"handleDocumentPaste",t=>{const n=Zr(t);if(!n.length||!this.isOpen||!this.host)return;const r=document.activeElement,o=this.root instanceof ShadowRoot?this.root.activeElement:null;!(r===this.host||this.host.contains(r)||o)&&!this.isUploadHovering||(t.preventDefault(),this.handleImages(n))});this.options=t,this.localPriorityEnabled=t.localPriorityEnabled??!1}mount(t){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)}setOpen(t){this.isOpen=t,this.render(this.isOpen),this.keepHostInViewport()}setLocalPriorityEnabled(t){this.localPriorityEnabled=t;const n=this.query('[data-role="local-priority-toggle"]');n&&(n.checked=t)}setBusy(t,n=""){const r=this.query('[data-role="recognize"]');r&&(r.disabled=t,r.textContent=t?n:this.t("recognize","智能识别"))}setStatus(t){const n=this.query('[data-role="status"]');n&&(n.textContent=t,n.removeAttribute("data-status"))}setError(t){const n=this.query('[data-role="status"]');n&&(n.textContent=t,n.setAttribute("data-status","error"))}setAutoApplyState(t){this.autoApplyState=t,this.render(!0),this.keepHostInViewport(),this.setStatus(this.t("recognized","识别完成,正在自动回填..."))}setApplyResult(t){const n=this.query('[data-role="status"]');n&&(n.textContent=`已回填 ${t.applied.length} 项,跳过 ${t.skipped.length} 项。`,n.setAttribute("data-status",t.skipped.length?"warning":"success"))}destroy(){var t;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}render(t){this.root&&(this.root.innerHTML=`
|
|
38
|
+
<style>${Jr}</style>
|
|
12
39
|
${this.options.mode==="floating"?`<button class="sf-float" type="button" data-role="open">${this.t("entry","智能录入")}</button>`:""}
|
|
13
40
|
<section class="sf-panel ${t?"is-open":""} ${this.options.mode==="inline"?"is-inline":"is-floating"}" aria-label="智能录入面板">
|
|
14
41
|
<header class="sf-header" data-role="close" >
|
|
@@ -25,7 +52,7 @@
|
|
|
25
52
|
</label>
|
|
26
53
|
<div class="sf-entry-grid">
|
|
27
54
|
<div class="sf-textarea-wrap">
|
|
28
|
-
<textarea class="sf-textarea" data-role="text" placeholder="${this.t("placeholder","粘贴文本,如:姓名:张三 手机号:13800000000")}">${
|
|
55
|
+
<textarea class="sf-textarea" data-role="text" placeholder="${this.t("placeholder","粘贴文本,如:姓名:张三 手机号:13800000000")}">${Xr(this.inputText)}</textarea>
|
|
29
56
|
<div class="sf-textarea-actions">
|
|
30
57
|
<button class="sf-btn sf-btn-secondary" type="button" data-role="clear">${this.t("clear","清空")}</button>
|
|
31
58
|
<button class="sf-btn sf-btn-primary" type="button" data-role="recognize">${this.t("recognize","智能识别")}</button>
|
|
@@ -52,7 +79,7 @@
|
|
|
52
79
|
</div>
|
|
53
80
|
</div>
|
|
54
81
|
</section>
|
|
55
|
-
`,this.bindEvents())}bindEvents(){var r,o,i,s,a,c,l;const t=this.query('[data-role="open"]');t==null||t.addEventListener("pointerdown",u=>this.startDrag(u)),t==null||t.addEventListener("click",()=>{this.suppressOpenClick||this.options.onOpen()}),(r=this.query(".sf-header"))==null||r.addEventListener("pointerdown",u=>this.startDrag(u)),(o=this.query('[data-role="close"]'))==null||o.addEventListener("click",()=>{if(this.options.mode==="inline"){this.isOpen?this.options.onClose():this.options.onOpen();return}this.options.onClose()}),(i=this.query('[data-role="file"]'))==null||i.addEventListener("change",u=>{const g=u.target;this.handleImages(Array.from(g.files||[]))});const n=this.query('[data-role="upload"]');n==null||n.addEventListener("pointerenter",()=>{this.isUploadHovering=!0}),n==null||n.addEventListener("pointerleave",()=>{this.isUploadHovering=!1,n.removeAttribute("data-dragover")}),n==null||n.addEventListener("dragenter",u=>{u.preventDefault(),this.isUploadHovering=!0,n.setAttribute("data-dragover","true")}),n==null||n.addEventListener("dragover",u=>{u.preventDefault(),n.setAttribute("data-dragover","true")}),n==null||n.addEventListener("dragleave",u=>{u.currentTarget.contains(u.relatedTarget)||(this.isUploadHovering=!1,n.removeAttribute("data-dragover"))}),n==null||n.addEventListener("drop",u=>{var g;u.preventDefault(),this.isUploadHovering=!1,n.removeAttribute("data-dragover"),this.handleImages(Array.from(((g=u.dataTransfer)==null?void 0:g.files)||[]))}),(s=this.query('[data-role="text"]'))==null||s.addEventListener("input",u=>{this.inputText=u.target.value}),(a=this.query('[data-role="local-priority-toggle"]'))==null||a.addEventListener("change",u=>{var g,R;this.localPriorityEnabled=u.target.checked,(R=(g=this.options).onLocalPriorityChange)==null||R.call(g,this.localPriorityEnabled)}),(c=this.query('[data-role="clear"]'))==null||c.addEventListener("click",()=>{this.clearFormState()}),(l=this.query('[data-role="recognize"]'))==null||l.addEventListener("click",()=>{const u=this.query('[data-role="text"]'),g=u==null?void 0:u.value.trim();if(this.inputText=(u==null?void 0:u.value)||this.inputText,!g){this.setError(this.t("emptyInput","请输入文本内容。"));return}this.options.onRecognize({text:g})})}clearFormState(){this.inputText="",this.resetSelectedFiles(),this.autoApplyState=null,this.render(!0),this.setStatus(this.t("empty","暂无识别结果"))}resetSelectedFiles(){var n;this.selectedFiles=[];const t=this.query('[data-role="file"]');t&&(t.value=""),this.isUploadHovering=!1,(n=this.query('[data-role="upload"]'))==null||n.removeAttribute("data-dragover")}async handleImages(t){const n=t.filter(i=>i.type.startsWith("image/"));if(!n.length){this.resetSelectedFiles(),this.setError(this.t("invalidImageError","请选择图片文件。"));return}if(n.length>ze){this.resetSelectedFiles(),this.setError(this.t("maxFilesError",`最多上传 ${ze} 张图片。`));return}if(n.find(i=>i.size>
|
|
82
|
+
`,this.bindEvents())}bindEvents(){var r,o,i,s,a,c,l;const t=this.query('[data-role="open"]');t==null||t.addEventListener("pointerdown",u=>this.startDrag(u)),t==null||t.addEventListener("click",()=>{this.suppressOpenClick||this.options.onOpen()}),(r=this.query(".sf-header"))==null||r.addEventListener("pointerdown",u=>this.startDrag(u)),(o=this.query('[data-role="close"]'))==null||o.addEventListener("click",()=>{if(this.options.mode==="inline"){this.isOpen?this.options.onClose():this.options.onOpen();return}this.options.onClose()}),(i=this.query('[data-role="file"]'))==null||i.addEventListener("change",u=>{const g=u.target;this.handleImages(Array.from(g.files||[]))});const n=this.query('[data-role="upload"]');n==null||n.addEventListener("pointerenter",()=>{this.isUploadHovering=!0}),n==null||n.addEventListener("pointerleave",()=>{this.isUploadHovering=!1,n.removeAttribute("data-dragover")}),n==null||n.addEventListener("dragenter",u=>{u.preventDefault(),this.isUploadHovering=!0,n.setAttribute("data-dragover","true")}),n==null||n.addEventListener("dragover",u=>{u.preventDefault(),n.setAttribute("data-dragover","true")}),n==null||n.addEventListener("dragleave",u=>{u.currentTarget.contains(u.relatedTarget)||(this.isUploadHovering=!1,n.removeAttribute("data-dragover"))}),n==null||n.addEventListener("drop",u=>{var g;u.preventDefault(),this.isUploadHovering=!1,n.removeAttribute("data-dragover"),this.handleImages(Array.from(((g=u.dataTransfer)==null?void 0:g.files)||[]))}),(s=this.query('[data-role="text"]'))==null||s.addEventListener("input",u=>{this.inputText=u.target.value}),(a=this.query('[data-role="local-priority-toggle"]'))==null||a.addEventListener("change",u=>{var g,R;this.localPriorityEnabled=u.target.checked,(R=(g=this.options).onLocalPriorityChange)==null||R.call(g,this.localPriorityEnabled)}),(c=this.query('[data-role="clear"]'))==null||c.addEventListener("click",()=>{this.clearFormState()}),(l=this.query('[data-role="recognize"]'))==null||l.addEventListener("click",()=>{const u=this.query('[data-role="text"]'),g=u==null?void 0:u.value.trim();if(this.inputText=(u==null?void 0:u.value)||this.inputText,!g){this.setError(this.t("emptyInput","请输入文本内容。"));return}this.options.onRecognize({text:g})})}clearFormState(){this.inputText="",this.resetSelectedFiles(),this.autoApplyState=null,this.render(!0),this.setStatus(this.t("empty","暂无识别结果"))}resetSelectedFiles(){var n;this.selectedFiles=[];const t=this.query('[data-role="file"]');t&&(t.value=""),this.isUploadHovering=!1,(n=this.query('[data-role="upload"]'))==null||n.removeAttribute("data-dragover")}async handleImages(t){const n=t.filter(i=>i.type.startsWith("image/"));if(!n.length){this.resetSelectedFiles(),this.setError(this.t("invalidImageError","请选择图片文件。"));return}if(n.length>ze){this.resetSelectedFiles(),this.setError(this.t("maxFilesError",`最多上传 ${ze} 张图片。`));return}if(n.find(i=>i.size>Gr)){this.resetSelectedFiles(),this.setError(this.t("maxSingleFileSizeError","单张图片不能超过 10MB。"));return}if(n.reduce((i,s)=>i+s.size,0)>Yr){this.resetSelectedFiles(),this.setError(this.t("maxTotalFileSizeError","上传图片总大小不能超过 50MB。"));return}this.selectedFiles=n,this.setStatus(this.t("imageReady",`已选择 ${this.selectedFiles.length} 张图片,开始识别...`));try{await this.options.onRecognize({images:[...this.selectedFiles]}),this.resetSelectedFiles()}catch{}}startDrag(t){var r;if(this.options.mode!=="floating"||!this.host||t.button!==0||(r=t.target)!=null&&r.closest('[data-role="close"]'))return;const n=this.host.getBoundingClientRect();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={pointerId:t.pointerId,startX:t.clientX,startY:t.clientY,startLeft:n.left,startTop:n.top,moved:!1},t.preventDefault(),document.addEventListener("pointermove",this.handleDragMove),document.addEventListener("pointerup",this.handleDragEnd),document.addEventListener("pointercancel",this.handleDragEnd)}keepHostInViewport(){this.options.mode!=="floating"||!this.host||!this.host.style.left||!this.host.style.top||window.requestAnimationFrame(()=>{if(!this.host)return;const t=this.host.getBoundingClientRect(),n=be(t.left,8,Math.max(8,window.innerWidth-t.width-8)),r=be(t.top,8,Math.max(8,window.innerHeight-t.height-8));this.host.style.left=`${n}px`,this.host.style.top=`${r}px`})}query(t){var n;return((n=this.root)==null?void 0:n.querySelector(t))||null}t(t,n){var r;return((r=this.options.messages)==null?void 0:r[t])||n}}function Xr(e){return e.replace(/[&<>"']/g,t=>({"&":"&","<":"<",">":">",'"':""","'":"'"})[t]||t)}function be(e,t,n){return Math.min(Math.max(e,t),n)}function Zr(e){var n;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)}const Jr=`
|
|
56
83
|
:host, .sf-panel { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
|
|
57
84
|
: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; }
|
|
58
85
|
.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; }
|
|
@@ -122,4 +149,4 @@
|
|
|
122
149
|
width: min(450px, calc(100vw - 32px))
|
|
123
150
|
}
|
|
124
151
|
}
|
|
125
|
-
`,Xr=.75,Zr=1800,Z=new Map;let J=0;const Be="smart-fill:routechange",Dt="smart-fill:session-scan:";let qt=!1;const Pt=new WeakMap;let Jr=0;function Ht(){Z.clear(),Yt(),J+=1}class $t{constructor(t,n){d(this,"events",new De);d(this,"scanner");d(this,"ruleEngine",new At);d(this,"panel",null);d(this,"panels",[]);d(this,"panelStorageKeys",new Map);d(this,"registeredFields",[]);d(this,"adapters",[Oe]);d(this,"scanResult",null);d(this,"autoApplyState",null);d(this,"formConfigVersion");d(this,"localPriorityEnabled",!1);d(this,"destroyed",!1);d(this,"scanCacheVersion",J);d(this,"floatingRouteSnapshot",null);d(this,"floatingLifecycleCleanup",null);d(this,"preScanTimer",null);this.config=t,this.context=n,this.scanner=new It(t.root||document),this.localPriorityEnabled=xo(),this.context.manager.add(this)}on(t,n){return this.events.on(t,n)}useAdapter(t){return this.assertAlive(),this.adapters.push(t),this}registerFields(t){this.assertAlive();const n=new Set;for(const r of t){const o=r.rowKey==null?r.fieldId:`${r.fieldId}:${r.rowKey}`;if(n.has(o))throw w("UNSUPPORTED_PAGE",`字段 ${o} 重复注册。`,"scan");n.add(o)}return this.registeredFields=t,this.scanResult=null,this.schedulePreScan(),this}unregisterFields(t){this.assertAlive(),this.registeredFields=t!=null&&t.length?this.registeredFields.filter(n=>!t.includes(n.fieldId)):[],this.scanResult=null,this.schedulePreScan()}mount(t){this.assertAlive();const n=typeof t=="string"?document.querySelector(t):t;if(!n)throw w("UNSUPPORTED_PAGE","未找到智能录入挂载点。","ui");const r=Wt("inline",Eo(t,n)),o=Xt(r,!0);return this.createPanel("inline",r,o).mount(n),this.schedulePreScan(),this}mountFloatingButton(){this.assertAlive();const t=po(this.config),n=Wt("floating"),r=Xt(n,!1);return this.createPanel("floating",n,r).mount(t),this.bindFloatingLifecycle(t),this.schedulePreScan(),this}createPanel(t,n,r){let o;return o=new jr({mode:t,initialOpen:r,messages:this.config.messages,localPriorityEnabled:this.localPriorityEnabled,onOpen:()=>this.open(o),onClose:()=>this.close(o),onRecognize:i=>(this.panel=o,this.recognize(i)),onLocalPriorityChange:i=>this.handleLocalPriorityChange(i,o)}),this.panels.push(o),this.panelStorageKeys.set(o,n),this.panel=o,o}handleLocalPriorityChange(t,n){this.localPriorityEnabled=t,ko(t);for(const r of this.panels)r!==n&&r.setLocalPriorityEnabled(t)}async open(t=this.panel){this.assertAlive(),this.syncScanCacheVersion(),t&&(this.context.manager.activate(this),this.panel=t,t.setOpen(!0),Zt(this.panelStorageKeys.get(t),!0),this.scanResult||await this.rescan())}close(t=this.panel){t&&(this.panel=t,t.setOpen(!1),Zt(this.panelStorageKeys.get(t),!1))}async rescan(){return this.assertAlive(),this.syncScanCacheVersion(),this.cancelPreScan(),this.runScan({dynamicOptions:!0,emitStatus:!0})}async preScan(){return this.assertAlive(),this.syncScanCacheVersion(),this.runScan({dynamicOptions:!1,emitStatus:!1})}async runScan(t){var n;try{this.formConfigVersion=void 0;const r=this.getCachedPageScanResult(t.dynamicOptions),o=this.registeredFields.length?this.registeredFields:void 0,i=o?this.scanner.scan({registered:o,maxFields:this.config.maxFields}):r??(t.dynamicOptions?await this.scanner.scanWithDynamicOptions({maxFields:this.config.maxFields}):this.scanner.scan({maxFields:this.config.maxFields}));if(this.scanResult=i,this.cachePageScanResult(i,t.dynamicOptions),!this.scanResult.fields.length)throw w("NO_FIELDS_FOUND","当前页面未找到可回填字段。","scan");return t.emitStatus&&(this.events.emit("scanCompleted",{scanToken:this.scanResult.scanToken,fieldCount:this.scanResult.fields.length}),(n=this.panel)==null||n.setStatus(`已扫描 ${this.scanResult.fields.length} 个字段。`)),this.scanResult}catch(r){throw t.emitStatus&&this.emitError(r,"scan"),r}}schedulePreScan(){this.destroyed||!this.panels.length||(this.preScanTimer!=null&&window.clearTimeout(this.preScanTimer),this.preScanTimer=window.setTimeout(()=>{this.preScanTimer=null,!(this.destroyed||this.scanResult)&&this.preScan().catch(()=>{})},Zr))}cancelPreScan(){this.preScanTimer!=null&&(window.clearTimeout(this.preScanTimer),this.preScanTimer=null)}async recognize(t){var i,s,a,c,l,u;this.assertAlive(),this.syncScanCacheVersion(),(i=this.panel)==null||i.setBusy(!0,"扫描中..."),(s=this.panel)==null||s.setStatus("扫描中...");const n=await this.rescan(),r=he("trace"),o=performance.now();this.events.emit("recognizing",{scanToken:n.scanToken,traceId:r}),(a=this.panel)==null||a.setBusy(!0,"识别中...");try{const g=n.fields.filter(y=>ro(y.localRuleMode,this.localPriorityEnabled)),R=n.fields.filter(y=>y.localRuleMode!=="only"),{text:ee,usedOcr:we}=await this.context.client.resolveInputText({text:t.text,images:t.images,onStatusChange:y=>{var Se,O,Ee;if(y==="image_uploading"){(Se=this.panel)==null||Se.setStatus("图片上传中...");return}if(y==="image_recognizing"){(O=this.panel)==null||O.setStatus("图片识别中...");return}(Ee=this.panel)==null||Ee.setStatus("识别中...")}}),ve=ee?this.ruleEngine.recognize(ee,g,n.scanToken):[];let k;if(!R.length)k=Vt(n.scanToken,r,ve,o,void 0,we);else try{const y=await this.context.client.recognize({scanToken:n.scanToken,formCode:this.config.formCode,configVersion:this.formConfigVersion,text:ee,usedOcr:we,fields:R,onStatusChange:()=>{var O;(O=this.panel)==null||O.setStatus("识别中...")}});y.trace.durationMs=y.trace.durationMs||Math.round(performance.now()-o);const Se=no(ve,y.suggestions.filter(O=>R.some(Ee=>Ee.fieldId===O.fieldId)));k={...y,suggestions:Se}}catch(y){if(!ve.length)throw y;k=Vt(n.scanToken,r,ve,o,[we?"后端识别失败,已使用 OCR 文本触发本地识别继续回填。":"后端识别失败,已启用本地识别继续回填。"],we)}if(this.autoApplyState=eo(k.scanToken,k.trace.traceId,k.suggestions,n,this.registeredFields),this.events.emit("recognized",k),(c=this.panel)==null||c.setAutoApplyState(this.autoApplyState),this.config.apiEnable){const y=Qr(k,this.autoApplyState,n);this.config.apiCallback&&await Promise.resolve(this.config.apiCallback(y)),(l=this.panel)==null||l.setStatus(`识别完成,已返回 ${y.fields.length} 个字段。`)}else await this.applyAutoItems(this.autoApplyState);return k}catch(g){throw this.clearScanStateOnTokenExpired(g),this.emitError(g,"recognize"),g}finally{(u=this.panel)==null||u.setBusy(!1)}}async apply(t){var o;if(this.assertAlive(),this.syncScanCacheVersion(),!this.scanResult)throw w("SCAN_TOKEN_EXPIRED","请先扫描字段后再回填。","apply");this.events.emit("applying",{scanToken:t.scanToken,count:t.values.length});const r=await new Pe(this.scanResult.fields,this.registeredFields,this.adapters).apply(t);return this.events.emit("applied",r),(o=this.panel)==null||o.setApplyResult(r),r}async applyAutoItems(t){var a,c;if(!this.scanResult)throw w("SCAN_TOKEN_EXPIRED","请先扫描字段后再回填。","apply");const n=to(t),r=t.items.filter(l=>Nt(l)).map(l=>({fieldId:l.fieldId,value:l.value,source:l.source}));this.events.emit("applying",{scanToken:t.scanToken,count:r.length}),(a=this.panel)==null||a.setStatus("识别完成,正在自动回填...");const i=await new Pe(this.scanResult.fields,this.registeredFields,this.adapters).apply({scanToken:t.scanToken,values:r}),s={...i,skipped:[...n,...i.skipped],warnings:[...i.warnings||[],...n.length?["部分字段因置信度或风险策略被跳过。"]:[]]};return this.events.emit("applied",s),(c=this.panel)==null||c.setApplyResult(s),s}destroy(){if(!this.destroyed){this.destroyed=!0,this.cancelPreScan(),this.clearFloatingLifecycle();for(const t of this.panels)t.destroy();this.panels.length=0,this.panelStorageKeys.clear(),this.panel=null,this.events.clear(),this.context.manager.remove(this)}}assertAlive(){if(this.destroyed)throw w("INSTANCE_DESTROYED","实例已销毁。","ui")}emitError(t,n){var o;const r=kt(t,n);this.events.emit("error",r),(o=this.panel)==null||o.setError(r.message)}getCachedPageScanResult(t){const n=this.getPageScanCacheKey();if(!n)return null;const r=Z.get(n);if(r&&(!t||r.dynamicOptionsReady)){const i=io(r.scanResult);if(!i)Z.delete(n);else return i}const o=this.getPersistedPageScanResult(t);return o?(this.cachePageScanResult(o.scanResult,o.dynamicOptionsReady),o.scanResult):null}cachePageScanResult(t,n){const r=this.getPageScanCacheKey();if(!r||!t.fields.length)return;const o=Z.get(r);o!=null&&o.dynamicOptionsReady&&!n||(Z.set(r,{scanResult:t,dynamicOptionsReady:(o==null?void 0:o.dynamicOptionsReady)||n}),this.persistPageScanResult(t,(o==null?void 0:o.dynamicOptionsReady)||n))}getPageScanCacheKey(){return this.registeredFields.length?null:co(this.config)}getSessionPageScanCacheKey(){return this.registeredFields.length||!this.config.formCode?null:lo(this.config)}clearScanStateOnTokenExpired(t){kt(t,"recognize").code==="TOKEN_EXPIRED"&&(Ht(),this.scanCacheVersion=J,this.scanResult=null,this.autoApplyState=null)}syncScanCacheVersion(){this.scanCacheVersion!==J&&(this.scanCacheVersion=J,this.scanResult=null,this.autoApplyState=null)}getPersistedPageScanResult(t){const n=this.getSessionPageScanCacheKey();if(!n)return null;const r=vo(n);if(!r||t&&!r.dynamicOptionsReady)return null;const o=this.scanner.scan({maxFields:this.config.maxFields}),i=so(r,o);return i?{scanResult:i,dynamicOptionsReady:r.dynamicOptionsReady}:(Yt(n),null)}persistPageScanResult(t,n){const r=this.getSessionPageScanCacheKey();!r||!t.fields.length||So(r,{version:1,dynamicOptionsReady:n,fields:t.fields.map(({element:o,scanToken:i,...s})=>s)})}bindFloatingLifecycle(t){this.clearFloatingLifecycle(),this.floatingRouteSnapshot=Bt(),uo();const n=()=>{this.destroyed||Bt()!==this.floatingRouteSnapshot&&this.destroy()};window.addEventListener(Be,n);const r=new MutationObserver(()=>{this.destroyed||t!==document.body&&!t.isConnected&&this.destroy()});r.observe(document.body,{childList:!0,subtree:!0}),this.floatingLifecycleCleanup=()=>{window.removeEventListener(Be,n),r.disconnect(),this.floatingRouteSnapshot=null,this.floatingLifecycleCleanup=null}}clearFloatingLifecycle(){var t;(t=this.floatingLifecycleCleanup)==null||t.call(this)}}function Qr(e,t,n){return{scanToken:e.scanToken,trace:e.trace,warnings:e.warnings,fields:t.items.map(r=>{const o=n.fields.find(i=>i.fieldId===r.fieldId);return{fieldId:r.fieldId,label:r.label,value:r.value,displayValue:r.displayValue||String(r.value??""),confidence:r.confidence,source:r.source,type:o==null?void 0:o.type,currentValue:r.currentValue,warnings:r.warnings}})}}function eo(e,t,n,r,o){return{scanToken:e,traceId:t,items:n.map(i=>{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():oo(s==null?void 0:s.element);return{applyItemId:`${i.fieldId}_${Math.random().toString(36).slice(2,8)}`,fieldId:i.fieldId,scanToken:e,groupId:i.groupId,label:i.label,value:i.value,currentValue:c,displayValue:i.displayValue||String(i.value??""),confidence:i.confidence,source:i.source,warnings:i.warnings,previousValue:c}})}}function Nt(e){var t;return e.confidence>=Xr&&!((t=e.warnings)!=null&&t.length)}function to(e){return e.items.filter(t=>!Nt(t)).map(t=>{var n,r;return{fieldId:t.fieldId,label:t.label,attemptedValue:t.value,reason:((n=t.warnings)==null?void 0:n.join(";"))||`置信度 ${Math.round(t.confidence*100)}% 低于自动回填阈值`,reasonCode:(r=t.warnings)!=null&&r.length?"AUTO_APPLY_WARNING":"LOW_CONFIDENCE"}})}function no(e,t){const n=new Map;for(const r of t)n.set(r.fieldId,r);for(const r of e)n.has(r.fieldId)||n.set(r.fieldId,r);return[...n.values()]}function ro(e,t){return e==="only"?!0:e==="off"?!1:t}function Vt(e,t,n,r,o,i=!1){return{scanToken:e,suggestions:n,warnings:o,trace:{traceId:t,usedOcr:i,usedAi:!1,durationMs:Math.round(performance.now()-r)}}}function oo(e){if(e)return e instanceof HTMLInputElement&&e.type==="checkbox"?e.checked:e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement||e instanceof HTMLSelectElement?e.value:e.textContent}function io(e){const t=e.fields.map(n=>{if(n.source==="registered")return n;const r=ao(n);return r?{...n,element:r}:null});return t.some(n=>!n)?null:{...e,fields:t}}function so(e,t){var s,a;const n=new Map(t.fields.map(c=>[c.fieldId,c])),r=[],o=new Set;for(const c of e.fields){const l=n.get(c.fieldId);if(!l)continue;o.add(c.fieldId);const u={...l,label:c.label||l.label,placeholder:c.placeholder??l.placeholder,name:c.name??l.name,id:c.id??l.id,section:c.section??l.section,options:(s=c.options)!=null&&s.length?c.options:l.options,required:c.required??l.required,readonly:c.readonly??l.readonly,disabled:c.disabled??l.disabled};u.fingerprint=X({...u,tagName:(a=u.element)==null?void 0:a.tagName.toLowerCase()}),r.push(u)}if(!r.length)return null;const i=t.fields.filter(c=>!o.has(c.fieldId));return{...t,fields:[...r,...i]}}function ao(e){var t;if((t=e.element)!=null&&t.isConnected)return e.element;try{return document.querySelector(`[data-smart-fill-id="${_o(e.fieldId)}"]`)}catch{return null}}function co(e){const t=typeof location<"u"?`${location.origin}${location.pathname}${location.search}`:"unknown-page",n=Kt(e.root||document);return`smart-fill:${t}:${e.formCode||"default-form"}:${n}:${e.maxFields??200}:scan`}function lo(e){const t=Kt(e.root||document);return`${Dt}${e.formCode||"default-form"}:${t}:${e.maxFields??200}`}function Kt(e){if(e===document)return"document";const t=Pt.get(e);if(t)return t;const n=e instanceof HTMLElement&&e.id?`el:${e.id}`:`root:${++Jr}`;return Pt.set(e,n),n}function uo(){if(qt||typeof window>"u")return;qt=!0;const e=()=>{window.dispatchEvent(new Event(Be))};window.addEventListener("popstate",e),window.addEventListener("hashchange",e),zt("pushState",e),zt("replaceState",e)}function zt(e,t){const n=window.history[e];window.history[e]=function(...o){const i=n.apply(this,o);return t(),i}}function Bt(){return typeof location>"u"?"unknown-route":`${location.pathname}${location.search}${location.hash}`}function po(e){const t=fo(e.floatingContainer);if(t)return t;const n=ho(e.routeContainerSelector);return n||go()||document.body}function fo(e){return e?e instanceof HTMLElement?e:Ue(e):null}function ho(e){if(!e)return null;const t=Ut(),n=t?Ue(e,t):null;return n||Ue(e)}function go(){const e=Ut();if(!e)return null;const t=yo(e);if(t)return t;const n=bo(e);if(n)return n;const r=mo(e);return r!==e?r:null}function Ut(){const e=["#app","#root","#__next","#nuxt","[data-reactroot]","[data-v-app]","[data-vue-app]","[data-app-root]","[data-router-root]"];for(const t of e){const n=document.querySelector(t);if(n&&me(n))return n}return null}function yo(e){const t=v(e),n=jt(e).filter(o=>!je(o)).filter(o=>v(o)>=Math.max(t*.2,48e3)),r=n.filter(o=>wo(o));return r.length?r.sort((o,i)=>v(i)-v(o))[0]:n.length===1?n[0]:null}function bo(e){const t=["[data-route-root]","[data-router-view]","[data-page-root]","[data-page-container]",".router-view",".route-view",".page-root",".page-container",".page",".layout-content",".app-main",".app-content","main",'[role="main"]'],n=Gt(e),r=v(e);return t.flatMap(i=>Array.from(e.querySelectorAll(i))).filter(i=>me(i)&&!je(i)).filter(i=>Ge(i,n)<=3).filter(i=>v(i)>=Math.max(r*.2,48e3)).sort((i,s)=>Ge(i,n)-Ge(s,n)||v(s)-v(i))[0]||null}function mo(e){let t=e;for(;;){const n=jt(t).filter(o=>!je(o));if(n.length!==1)return t;const[r]=n;if(v(r)<Math.max(v(t)*.25,48e3))return t;t=r}}function jt(e){return Array.from(e.children).filter(t=>t instanceof HTMLElement).filter(t=>me(t))}function Ue(e,t=document){try{const n=t.querySelector(e);return n&&me(n)?n:null}catch{return null}}function me(e){const t=window.getComputedStyle(e);if(t.display==="none"||t.visibility==="hidden"||Number(t.opacity)===0)return!1;const n=e.getBoundingClientRect();return n.width>0&&n.height>0}function je(e){const t=window.getComputedStyle(e);return t.position==="fixed"||t.position==="sticky"?!0:v(e)<24e3}function wo(e){if(e.tagName.toLowerCase()==="main"||e.getAttribute("role")==="main")return!0;const t=e.id||"",n=typeof e.className=="string"?e.className:"",r=`${t} ${n}`.toLowerCase();return/(page|layout|content|container|main|router|route|view)/.test(r)}function v(e){const t=e.getBoundingClientRect();return Math.max(0,t.width)*Math.max(0,t.height)}function Gt(e){let t=0,n=e;for(;n&&n!==document.body;)t+=1,n=n.parentElement;return t}function Ge(e,t){return Math.max(0,Gt(e)-t)}function vo(e){try{const t=window.sessionStorage.getItem(e);if(!t)return null;const n=JSON.parse(t);return(n==null?void 0:n.version)!==1||!Array.isArray(n.fields)?null:n}catch{return null}}function So(e,t){try{window.sessionStorage.setItem(e,JSON.stringify(t))}catch{}}function Yt(e){try{if(e){window.sessionStorage.removeItem(e);return}const t=[];for(let n=0;n<window.sessionStorage.length;n+=1){const r=window.sessionStorage.key(n);r!=null&&r.startsWith(Dt)&&t.push(r)}for(const n of t)window.sessionStorage.removeItem(n)}catch{}}function Wt(e,t="default"){const n=typeof location<"u"?location.pathname:"unknown-page",r=t.replace(/[^\w-]/g,"_")||"default";return`smart-fill:${e}:${n}:${r}:open`}function Eo(e,t){if(typeof e=="string")return e;if(t.id)return`#${t.id}`;const n=typeof t.className=="string"?t.className.trim().split(/\s+/).filter(Boolean)[0]:"";return n?`.${n}`:t.tagName.toLowerCase()}function Xt(e,t){try{const n=window.localStorage.getItem(e);return n==null?t:n==="1"}catch{return t}}function Zt(e,t){if(e)try{window.localStorage.setItem(e,t?"1":"0")}catch{}}function Jt(){return`smart-fill:${typeof location<"u"?location.pathname:"unknown-page"}:local-priority`}function xo(){try{return window.localStorage.getItem(Jt())==="1"}catch{return!1}}function ko(e){try{window.localStorage.setItem(Jt(),e?"1":"0")}catch{}}function _o(e){return typeof CSS<"u"&&CSS.escape?CSS.escape(e):e.replace(/["\\]/g,"\\$&")}const f={status:"idle"},Ye=new De,Qt=new fr;class en{static async setup(t){if(typeof window>"u")return f.status="ready",Co();if(f.status==="ready"&&f.apiKey===t.apiKey&&f.session)return f.session;if(f.status==="loading"&&f.apiKey===t.apiKey&&f.promise)return f.promise;f.apiKey&&f.apiKey!==t.apiKey&&(Ht(),Qt.destroyAll());const n=new ar(t);return f.status="loading",f.apiKey=t.apiKey,f.client=n,f.promise=n.createSession().then(r=>(console.log("SmartFill session created:",r),n.setAccessToken(r.apiKey),f.status="ready",f.session=r,Ye.emit("ready",{apiKey:t.apiKey}),r)).catch(r=>{throw f.status="error",r}),f.promise}static create(t={}){if(typeof window>"u")return Q();if(f.status!=="ready"||!f.client)throw w("SDK_NOT_READY","请先 await SmartFill.setup({ apiKey })。","setup");return new $t(t,{client:f.client,manager:Qt})}}d(en,"on",Ye.on.bind(Ye));function Co(){return{apiKey:"server-mock",accessToken:"server-mock",expiresIn:0,refreshBefore:0,features:{text:!1,image:!1,ai:!1,localRuleOnly:!0},rulesVersion:"server"}}function Q(e){const t=()=>{};return{on:t,useAdapter:()=>Q(),registerFields:()=>Q(),unregisterFields:t,mount:()=>Q(),mountFloatingButton:()=>Q(),open:async()=>{},close:t,rescan:async()=>({scanToken:"server",fields:[]}),recognize:async()=>({scanToken:"server",suggestions:[],trace:{traceId:"server",usedOcr:!1,usedAi:!1,durationMs:0}}),apply:async()=>({applied:[],skipped:[]}),destroy:t}}h.DEFAULT_BASE_URL=Et,h.DomFiller=Pe,h.DomScanner=It,h.ElementAdapter=Zn,h.EventBus=De,h.LocalRuleEngine=At,h.NativeAdapter=m,h.SmartFill=en,h.SmartFillInstance=$t,h.UiFrameworkAdapter=Oe,Object.defineProperty(h,Symbol.toStringTag,{value:"Module"})});
|
|
152
|
+
`,Qr=.75,eo=1800,Z=new Map;let J=0;const Be="smart-fill:routechange",Dt="smart-fill:session-scan:";let Pt=!1;const Ht=new WeakMap;let to=0;function $t(){Z.clear(),Wt(),J+=1}class Nt{constructor(t,n){d(this,"events",new qe);d(this,"scanner");d(this,"ruleEngine",new Tt);d(this,"panel",null);d(this,"panels",[]);d(this,"panelStorageKeys",new Map);d(this,"registeredFields",[]);d(this,"adapters",[Oe]);d(this,"scanResult",null);d(this,"autoApplyState",null);d(this,"formConfigVersion");d(this,"localPriorityEnabled",!1);d(this,"destroyed",!1);d(this,"scanCacheVersion",J);d(this,"floatingRouteSnapshot",null);d(this,"floatingLifecycleCleanup",null);d(this,"preScanTimer",null);this.config=t,this.context=n,this.scanner=new Mt(t.root||document),this.localPriorityEnabled=Co(),this.context.manager.add(this)}on(t,n){return this.events.on(t,n)}useAdapter(t){return this.assertAlive(),this.adapters.push(t),this}registerFields(t){this.assertAlive();const n=new Set;for(const r of t){const o=r.rowKey==null?r.fieldId:`${r.fieldId}:${r.rowKey}`;if(n.has(o))throw w("UNSUPPORTED_PAGE",`字段 ${o} 重复注册。`,"scan");n.add(o)}return this.registeredFields=t,this.scanResult=null,this.schedulePreScan(),this}unregisterFields(t){this.assertAlive(),this.registeredFields=t!=null&&t.length?this.registeredFields.filter(n=>!t.includes(n.fieldId)):[],this.scanResult=null,this.schedulePreScan()}mount(t){this.assertAlive();const n=typeof t=="string"?document.querySelector(t):t;if(!n)throw w("UNSUPPORTED_PAGE","未找到智能录入挂载点。","ui");const r=Xt("inline",_o(t,n)),o=Zt(r,!0);return this.createPanel("inline",r,o).mount(n),this.schedulePreScan(),this}mountFloatingButton(){this.assertAlive();const t=go(this.config),n=Xt("floating"),r=Zt(n,!0);return this.createPanel("floating",n,r).mount(t),this.bindFloatingLifecycle(t),this.schedulePreScan(),this}createPanel(t,n,r){let o;return o=new Wr({mode:t,initialOpen:r,messages:this.config.messages,localPriorityEnabled:this.localPriorityEnabled,onOpen:()=>this.open(o),onClose:()=>this.close(o),onRecognize:i=>(this.panel=o,this.recognize(i)),onLocalPriorityChange:i=>this.handleLocalPriorityChange(i,o)}),this.panels.push(o),this.panelStorageKeys.set(o,n),this.panel=o,o}handleLocalPriorityChange(t,n){this.localPriorityEnabled=t,Ao(t);for(const r of this.panels)r!==n&&r.setLocalPriorityEnabled(t)}async open(t=this.panel){this.assertAlive(),this.syncScanCacheVersion(),t&&(this.context.manager.activate(this),this.panel=t,t.setOpen(!0),Jt(this.panelStorageKeys.get(t),!0),this.scanResult||await this.rescan())}close(t=this.panel){t&&(this.panel=t,t.setOpen(!1),Jt(this.panelStorageKeys.get(t),!1))}async rescan(){return this.assertAlive(),this.syncScanCacheVersion(),this.cancelPreScan(),this.runScan({dynamicOptions:!0,emitStatus:!0})}async preScan(){return this.assertAlive(),this.syncScanCacheVersion(),this.runScan({dynamicOptions:!1,emitStatus:!1})}async runScan(t){var n;try{this.formConfigVersion=void 0;const r=this.getCachedPageScanResult(t.dynamicOptions),o=this.registeredFields.length?this.registeredFields:void 0,i=o?this.scanner.scan({registered:o,maxFields:this.config.maxFields}):r??(t.dynamicOptions?await this.scanner.scanWithDynamicOptions({maxFields:this.config.maxFields}):this.scanner.scan({maxFields:this.config.maxFields}));if(this.scanResult=i,this.cachePageScanResult(i,t.dynamicOptions),!this.scanResult.fields.length)throw w("NO_FIELDS_FOUND","当前页面未找到可回填字段。","scan");return t.emitStatus&&(this.events.emit("scanCompleted",{scanToken:this.scanResult.scanToken,fieldCount:this.scanResult.fields.length}),(n=this.panel)==null||n.setStatus(`已扫描 ${this.scanResult.fields.length} 个字段。`)),this.scanResult}catch(r){throw t.emitStatus&&this.emitError(r,"scan"),r}}schedulePreScan(){this.destroyed||!this.panels.length||(this.preScanTimer!=null&&window.clearTimeout(this.preScanTimer),this.preScanTimer=window.setTimeout(()=>{this.preScanTimer=null,!(this.destroyed||this.scanResult)&&this.preScan().catch(()=>{})},eo))}cancelPreScan(){this.preScanTimer!=null&&(window.clearTimeout(this.preScanTimer),this.preScanTimer=null)}async recognize(t){var i,s,a,c,l,u;this.assertAlive(),this.syncScanCacheVersion(),(i=this.panel)==null||i.setBusy(!0,"扫描中..."),(s=this.panel)==null||s.setStatus("扫描中...");const n=await this.rescan(),r=he("trace"),o=performance.now();this.events.emit("recognizing",{scanToken:n.scanToken,traceId:r}),(a=this.panel)==null||a.setBusy(!0,"识别中...");try{const g=n.fields.filter(y=>so(y.localRuleMode,this.localPriorityEnabled)),R=n.fields.filter(y=>y.localRuleMode!=="only"),{text:ee,usedOcr:we}=await this.context.client.resolveInputText({text:t.text,images:t.images,onStatusChange:y=>{var Se,O,Ee;if(y==="image_uploading"){(Se=this.panel)==null||Se.setStatus("图片上传中...");return}if(y==="image_recognizing"){(O=this.panel)==null||O.setStatus("图片识别中...");return}(Ee=this.panel)==null||Ee.setStatus("识别中...")}}),ve=ee?this.ruleEngine.recognize(ee,g,n.scanToken):[];let k;if(!R.length)k=Kt(n.scanToken,r,ve,o,void 0,we);else try{const y=await this.context.client.recognize({scanToken:n.scanToken,formCode:this.config.formCode,configVersion:this.formConfigVersion,text:ee,usedOcr:we,fields:R,onStatusChange:()=>{var O;(O=this.panel)==null||O.setStatus("识别中...")}});y.trace.durationMs=y.trace.durationMs||Math.round(performance.now()-o);const Se=io(ve,y.suggestions.filter(O=>R.some(Ee=>Ee.fieldId===O.fieldId)));k={...y,suggestions:Se}}catch(y){if(!ve.length)throw y;k=Kt(n.scanToken,r,ve,o,[we?"后端识别失败,已使用 OCR 文本触发本地识别继续回填。":"后端识别失败,已启用本地识别继续回填。"],we)}if(this.autoApplyState=ro(k.scanToken,k.trace.traceId,k.suggestions,n,this.registeredFields),this.events.emit("recognized",k),(c=this.panel)==null||c.setAutoApplyState(this.autoApplyState),this.config.apiEnable){const y=no(k,this.autoApplyState,n);this.config.apiCallback&&await Promise.resolve(this.config.apiCallback(y)),(l=this.panel)==null||l.setStatus(`识别完成,已返回 ${y.fields.length} 个字段。`)}else await this.applyAutoItems(this.autoApplyState);return k}catch(g){throw this.clearScanStateOnTokenExpired(g),this.emitError(g,"recognize"),g}finally{(u=this.panel)==null||u.setBusy(!1)}}async apply(t){var o;if(this.assertAlive(),this.syncScanCacheVersion(),!this.scanResult)throw w("SCAN_TOKEN_EXPIRED","请先扫描字段后再回填。","apply");this.events.emit("applying",{scanToken:t.scanToken,count:t.values.length});const r=await new Pe(this.scanResult.fields,this.registeredFields,this.adapters).apply(t);return this.events.emit("applied",r),(o=this.panel)==null||o.setApplyResult(r),r}async applyAutoItems(t){var a,c;if(!this.scanResult)throw w("SCAN_TOKEN_EXPIRED","请先扫描字段后再回填。","apply");const n=oo(t),r=t.items.filter(l=>Vt(l)).map(l=>({fieldId:l.fieldId,value:l.value,source:l.source}));this.events.emit("applying",{scanToken:t.scanToken,count:r.length}),(a=this.panel)==null||a.setStatus("识别完成,正在自动回填...");const i=await new Pe(this.scanResult.fields,this.registeredFields,this.adapters).apply({scanToken:t.scanToken,values:r}),s={...i,skipped:[...n,...i.skipped],warnings:[...i.warnings||[],...n.length?["部分字段因置信度或风险策略被跳过。"]:[]]};return this.events.emit("applied",s),(c=this.panel)==null||c.setApplyResult(s),s}destroy(){if(!this.destroyed){this.destroyed=!0,this.cancelPreScan(),this.clearFloatingLifecycle();for(const t of this.panels)t.destroy();this.panels.length=0,this.panelStorageKeys.clear(),this.panel=null,this.events.clear(),this.context.manager.remove(this)}}assertAlive(){if(this.destroyed)throw w("INSTANCE_DESTROYED","实例已销毁。","ui")}emitError(t,n){var o;const r=kt(t,n);this.events.emit("error",r),(o=this.panel)==null||o.setError(r.message)}getCachedPageScanResult(t){const n=this.getPageScanCacheKey();if(!n)return null;const r=Z.get(n);if(r&&(!t||r.dynamicOptionsReady)){const i=co(r.scanResult);if(!i)Z.delete(n);else return i}const o=this.getPersistedPageScanResult(t);return o?(this.cachePageScanResult(o.scanResult,o.dynamicOptionsReady),o.scanResult):null}cachePageScanResult(t,n){const r=this.getPageScanCacheKey();if(!r||!t.fields.length)return;const o=Z.get(r);o!=null&&o.dynamicOptionsReady&&!n||(Z.set(r,{scanResult:t,dynamicOptionsReady:(o==null?void 0:o.dynamicOptionsReady)||n}),this.persistPageScanResult(t,(o==null?void 0:o.dynamicOptionsReady)||n))}getPageScanCacheKey(){return this.registeredFields.length?null:po(this.config)}getSessionPageScanCacheKey(){return this.registeredFields.length||!this.config.formCode?null:fo(this.config)}clearScanStateOnTokenExpired(t){kt(t,"recognize").code==="TOKEN_EXPIRED"&&($t(),this.scanCacheVersion=J,this.scanResult=null,this.autoApplyState=null)}syncScanCacheVersion(){this.scanCacheVersion!==J&&(this.scanCacheVersion=J,this.scanResult=null,this.autoApplyState=null)}getPersistedPageScanResult(t){const n=this.getSessionPageScanCacheKey();if(!n)return null;const r=xo(n);if(!r||t&&!r.dynamicOptionsReady)return null;const o=this.scanner.scan({maxFields:this.config.maxFields}),i=lo(r,o);return i?{scanResult:i,dynamicOptionsReady:r.dynamicOptionsReady}:(Wt(n),null)}persistPageScanResult(t,n){const r=this.getSessionPageScanCacheKey();!r||!t.fields.length||ko(r,{version:1,dynamicOptionsReady:n,fields:t.fields.map(({element:o,scanToken:i,...s})=>s)})}bindFloatingLifecycle(t){this.clearFloatingLifecycle(),this.floatingRouteSnapshot=Ut(),ho();const n=()=>{this.destroyed||Ut()!==this.floatingRouteSnapshot&&this.destroy()};window.addEventListener(Be,n);const r=new MutationObserver(()=>{this.destroyed||t!==document.body&&!t.isConnected&&this.destroy()});r.observe(document.body,{childList:!0,subtree:!0}),this.floatingLifecycleCleanup=()=>{window.removeEventListener(Be,n),r.disconnect(),this.floatingRouteSnapshot=null,this.floatingLifecycleCleanup=null}}clearFloatingLifecycle(){var t;(t=this.floatingLifecycleCleanup)==null||t.call(this)}}function no(e,t,n){return{scanToken:e.scanToken,trace:e.trace,warnings:e.warnings,fields:t.items.map(r=>{const o=n.fields.find(i=>i.fieldId===r.fieldId);return{fieldId:r.fieldId,label:r.label,value:r.value,displayValue:r.displayValue||String(r.value??""),confidence:r.confidence,source:r.source,type:o==null?void 0:o.type,currentValue:r.currentValue,warnings:r.warnings}})}}function ro(e,t,n,r,o){return{scanToken:e,traceId:t,items:n.map(i=>{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():ao(s==null?void 0:s.element);return{applyItemId:`${i.fieldId}_${Math.random().toString(36).slice(2,8)}`,fieldId:i.fieldId,scanToken:e,groupId:i.groupId,label:i.label,value:i.value,currentValue:c,displayValue:i.displayValue||String(i.value??""),confidence:i.confidence,source:i.source,warnings:i.warnings,previousValue:c}})}}function Vt(e){var t;return e.confidence>=Qr&&!((t=e.warnings)!=null&&t.length)}function oo(e){return e.items.filter(t=>!Vt(t)).map(t=>{var n,r;return{fieldId:t.fieldId,label:t.label,attemptedValue:t.value,reason:((n=t.warnings)==null?void 0:n.join(";"))||`置信度 ${Math.round(t.confidence*100)}% 低于自动回填阈值`,reasonCode:(r=t.warnings)!=null&&r.length?"AUTO_APPLY_WARNING":"LOW_CONFIDENCE"}})}function io(e,t){const n=new Map;for(const r of t)n.set(r.fieldId,r);for(const r of e)n.has(r.fieldId)||n.set(r.fieldId,r);return[...n.values()]}function so(e,t){return e==="only"?!0:e==="off"?!1:t}function Kt(e,t,n,r,o,i=!1){return{scanToken:e,suggestions:n,warnings:o,trace:{traceId:t,usedOcr:i,usedAi:!1,durationMs:Math.round(performance.now()-r)}}}function ao(e){if(e)return e instanceof HTMLInputElement&&e.type==="checkbox"?e.checked:e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement||e instanceof HTMLSelectElement?e.value:e.textContent}function co(e){const t=e.fields.map(n=>{if(n.source==="registered")return n;const r=uo(n);return r?{...n,element:r}:null});return t.some(n=>!n)?null:{...e,fields:t}}function lo(e,t){var s,a;const n=new Map(t.fields.map(c=>[c.fieldId,c])),r=[],o=new Set;for(const c of e.fields){const l=n.get(c.fieldId);if(!l)continue;o.add(c.fieldId);const u={...l,label:c.label||l.label,placeholder:c.placeholder??l.placeholder,name:c.name??l.name,id:c.id??l.id,section:c.section??l.section,options:(s=c.options)!=null&&s.length?c.options:l.options,required:c.required??l.required,readonly:c.readonly??l.readonly,disabled:c.disabled??l.disabled};u.fingerprint=X({...u,tagName:(a=u.element)==null?void 0:a.tagName.toLowerCase()}),r.push(u)}if(!r.length)return null;const i=t.fields.filter(c=>!o.has(c.fieldId));return{...t,fields:[...r,...i]}}function uo(e){var t;if((t=e.element)!=null&&t.isConnected)return e.element;try{return document.querySelector(`[data-smart-fill-id="${To(e.fieldId)}"]`)}catch{return null}}function po(e){const t=typeof location<"u"?`${location.origin}${location.pathname}${location.search}`:"unknown-page",n=zt(e.root||document);return`smart-fill:${t}:${e.formCode||"default-form"}:${n}:${e.maxFields??200}:scan`}function fo(e){const t=zt(e.root||document);return`${Dt}${e.formCode||"default-form"}:${t}:${e.maxFields??200}`}function zt(e){if(e===document)return"document";const t=Ht.get(e);if(t)return t;const n=e instanceof HTMLElement&&e.id?`el:${e.id}`:`root:${++to}`;return Ht.set(e,n),n}function ho(){if(Pt||typeof window>"u")return;Pt=!0;const e=()=>{window.dispatchEvent(new Event(Be))};window.addEventListener("popstate",e),window.addEventListener("hashchange",e),Bt("pushState",e),Bt("replaceState",e)}function Bt(e,t){const n=window.history[e];window.history[e]=function(...o){const i=n.apply(this,o);return t(),i}}function Ut(){return typeof location>"u"?"unknown-route":`${location.pathname}${location.search}${location.hash}`}function go(e){const t=yo(e.floatingContainer);if(t)return t;const n=bo(e.routeContainerSelector);return n||mo()||document.body}function yo(e){return e?e instanceof HTMLElement?e:Ue(e):null}function bo(e){if(!e)return null;const t=jt(),n=t?Ue(e,t):null;return n||Ue(e)}function mo(){const e=jt();if(!e)return null;const t=wo(e);if(t)return t;const n=vo(e);if(n)return n;const r=So(e);return r!==e?r:null}function jt(){const e=["#app","#root","#__next","#nuxt","[data-reactroot]","[data-v-app]","[data-vue-app]","[data-app-root]","[data-router-root]"];for(const t of e){const n=document.querySelector(t);if(n&&me(n))return n}return null}function wo(e){const t=v(e),n=Gt(e).filter(o=>!je(o)).filter(o=>v(o)>=Math.max(t*.2,48e3)),r=n.filter(o=>Eo(o));return r.length?r.sort((o,i)=>v(i)-v(o))[0]:n.length===1?n[0]:null}function vo(e){const t=["[data-route-root]","[data-router-view]","[data-page-root]","[data-page-container]",".router-view",".route-view",".page-root",".page-container",".page",".layout-content",".app-main",".app-content","main",'[role="main"]'],n=Yt(e),r=v(e);return t.flatMap(i=>Array.from(e.querySelectorAll(i))).filter(i=>me(i)&&!je(i)).filter(i=>Ge(i,n)<=3).filter(i=>v(i)>=Math.max(r*.2,48e3)).sort((i,s)=>Ge(i,n)-Ge(s,n)||v(s)-v(i))[0]||null}function So(e){let t=e;for(;;){const n=Gt(t).filter(o=>!je(o));if(n.length!==1)return t;const[r]=n;if(v(r)<Math.max(v(t)*.25,48e3))return t;t=r}}function Gt(e){return Array.from(e.children).filter(t=>t instanceof HTMLElement).filter(t=>me(t))}function Ue(e,t=document){try{const n=t.querySelector(e);return n&&me(n)?n:null}catch{return null}}function me(e){const t=window.getComputedStyle(e);if(t.display==="none"||t.visibility==="hidden"||Number(t.opacity)===0)return!1;const n=e.getBoundingClientRect();return n.width>0&&n.height>0}function je(e){const t=window.getComputedStyle(e);return t.position==="fixed"||t.position==="sticky"?!0:v(e)<24e3}function Eo(e){if(e.tagName.toLowerCase()==="main"||e.getAttribute("role")==="main")return!0;const t=e.id||"",n=typeof e.className=="string"?e.className:"",r=`${t} ${n}`.toLowerCase();return/(page|layout|content|container|main|router|route|view)/.test(r)}function v(e){const t=e.getBoundingClientRect();return Math.max(0,t.width)*Math.max(0,t.height)}function Yt(e){let t=0,n=e;for(;n&&n!==document.body;)t+=1,n=n.parentElement;return t}function Ge(e,t){return Math.max(0,Yt(e)-t)}function xo(e){try{const t=window.sessionStorage.getItem(e);if(!t)return null;const n=JSON.parse(t);return(n==null?void 0:n.version)!==1||!Array.isArray(n.fields)?null:n}catch{return null}}function ko(e,t){try{window.sessionStorage.setItem(e,JSON.stringify(t))}catch{}}function Wt(e){try{if(e){window.sessionStorage.removeItem(e);return}const t=[];for(let n=0;n<window.sessionStorage.length;n+=1){const r=window.sessionStorage.key(n);r!=null&&r.startsWith(Dt)&&t.push(r)}for(const n of t)window.sessionStorage.removeItem(n)}catch{}}function Xt(e,t="default"){const n=typeof location<"u"?location.pathname:"unknown-page",r=t.replace(/[^\w-]/g,"_")||"default";return`smart-fill:${e}:${n}:${r}:open`}function _o(e,t){if(typeof e=="string")return e;if(t.id)return`#${t.id}`;const n=typeof t.className=="string"?t.className.trim().split(/\s+/).filter(Boolean)[0]:"";return n?`.${n}`:t.tagName.toLowerCase()}function Zt(e,t){try{const n=window.localStorage.getItem(e);return n==null?t:n==="1"}catch{return t}}function Jt(e,t){if(e)try{window.localStorage.setItem(e,t?"1":"0")}catch{}}function Qt(){return`smart-fill:${typeof location<"u"?location.pathname:"unknown-page"}:local-priority`}function Co(){try{return window.localStorage.getItem(Qt())==="1"}catch{return!1}}function Ao(e){try{window.localStorage.setItem(Qt(),e?"1":"0")}catch{}}function To(e){return typeof CSS<"u"&&CSS.escape?CSS.escape(e):e.replace(/["\\]/g,"\\$&")}const f={status:"idle"},Ye=new qe,en=new hr;class tn{static async setup(t){if(typeof window>"u")return f.status="ready",Lo();if(f.status==="ready"&&f.apiKey===t.apiKey&&f.session)return f.session;if(f.status==="loading"&&f.apiKey===t.apiKey&&f.promise)return f.promise;f.apiKey&&f.apiKey!==t.apiKey&&($t(),en.destroyAll());const n=new cr(t);return f.status="loading",f.apiKey=t.apiKey,f.client=n,f.promise=n.createSession().then(r=>(console.log("SmartFill session created:",r),n.setAccessToken(r.apiKey),f.status="ready",f.session=r,Ye.emit("ready",{apiKey:t.apiKey}),r)).catch(r=>{throw f.status="error",r}),f.promise}static create(t={}){if(typeof window>"u")return Q();if(f.status!=="ready"||!f.client)throw w("SDK_NOT_READY","请先 await SmartFill.setup({ apiKey })。","setup");return new Nt(t,{client:f.client,manager:en})}}d(tn,"on",Ye.on.bind(Ye));function Lo(){return{apiKey:"server-mock",accessToken:"server-mock",expiresIn:0,refreshBefore:0,features:{text:!1,image:!1,ai:!1,localRuleOnly:!0},rulesVersion:"server"}}function Q(e){const t=()=>{};return{on:t,useAdapter:()=>Q(),registerFields:()=>Q(),unregisterFields:t,mount:()=>Q(),mountFloatingButton:()=>Q(),open:async()=>{},close:t,rescan:async()=>({scanToken:"server",fields:[]}),recognize:async()=>({scanToken:"server",suggestions:[],trace:{traceId:"server",usedOcr:!1,usedAi:!1,durationMs:0}}),apply:async()=>({applied:[],skipped:[]}),destroy:t}}h.DEFAULT_BASE_URL=Et,h.DomFiller=Pe,h.DomScanner=Mt,h.ElementAdapter=Jn,h.EventBus=qe,h.LocalRuleEngine=Tt,h.NativeAdapter=m,h.SmartFill=tn,h.SmartFillInstance=Nt,h.UiFrameworkAdapter=Oe,Object.defineProperty(h,Symbol.toStringTag,{value:"Module"})});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dom-filler.d.ts","sourceRoot":"","sources":["../../../src/filler/dom-filler.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,eAAe,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"dom-filler.d.ts","sourceRoot":"","sources":["../../../src/filler/dom-filler.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,eAAe,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AA0BxG,qBAAa,SAAS;IAElB,yCAAyC;IACzC,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,oDAAoD;IACpD,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,cAAc;IACd,OAAO,CAAC,QAAQ,CAAC,QAAQ;;IALzB,yCAAyC;IACxB,MAAM,EAAE,eAAe,EAAE;IAC1C,oDAAoD;IACnC,OAAO,EAAE,WAAW,EAAE;IACvC,cAAc;IACG,QAAQ,GAAE,gBAAgB,EAAO;IAGpD;;;;OAIG;IACG,KAAK,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO,CAAC,WAAW,CAAC;IAyCpD,kDAAkD;YACpC,QAAQ;IAYtB;;;OAGG;YACW,QAAQ;IA+BtB,qBAAqB;IACrB,OAAO,CAAC,YAAY;CAIrB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"highlight-style.d.ts","sourceRoot":"","sources":["../../../src/filler/highlight-style.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,kBAAkB,+BAA+B,CAAA;AAE9D,wCAAwC;AACxC,eAAO,MAAM,oBAAoB,QA2BzB,CAAA;AAER,wBAAgB,oBAAoB,SASnC"}
|
package/dist/style.css
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
[data-smart-fill-highlighted=true]{background:#eaf3ff!important;transition:background-color .2s ease}[data-smart-fill-highlighted=true] input:not([type=hidden]),[data-smart-fill-highlighted=true] textarea{background:#eaf3ff!important}
|
|
1
|
+
[data-smart-fill-highlighted=true]{background:#eaf3ff!important;box-shadow:0 0 0 1px #91caff inset!important;transition:background-color .2s ease,box-shadow .2s ease!important}[data-smart-fill-highlighted=true] input:not([type=hidden]),[data-smart-fill-highlighted=true] textarea{background:#eaf3ff!important}[data-smart-fill-highlighted=true].el-select,[data-smart-fill-highlighted=true].el-select-v2,[data-smart-fill-highlighted=true] .el-select__wrapper,[data-smart-fill-highlighted=true] .el-select-v2__wrapper,[data-smart-fill-highlighted=true] .el-input__wrapper,[data-smart-fill-highlighted=true] .el-date-editor,[data-smart-fill-highlighted=true] .ant-select-selector,[data-smart-fill-highlighted=true] .ant-picker,[data-smart-fill-highlighted=true] .n-base-selection,[data-smart-fill-highlighted=true] .arco-select-view,[data-smart-fill-highlighted=true] .van-field__body,[data-smart-fill-highlighted=true] .van-field__control{background:#eaf3ff!important;box-shadow:0 0 0 1px #91caff inset!important}
|