@kc-one/smart-fill-sdk 0.0.10 → 0.0.11

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.
@@ -1,5 +1,5 @@
1
- (function(g,w){typeof exports=="object"&&typeof module<"u"?w(exports):typeof define=="function"&&define.amd?define(["exports"],w):(g=typeof globalThis<"u"?globalThis:g||self,w(g.SmartFillSDK={}))})(this,function(g){"use strict";var Zo=Object.defineProperty;var Jo=(g,w,R)=>w in g?Zo(g,w,{enumerable:!0,configurable:!0,writable:!0,value:R}):g[w]=R;var f=(g,w,R)=>Jo(g,typeof w!="symbol"?w+"":w,R);const w={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}))}},R=[{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"}],gn=["is-disabled","ant-select-disabled","n-select--disabled","arco-select-disabled","van-field--disabled","van-switch--disabled","van-stepper--disabled","van-dropdown-menu--disabled"],tt=R.map(e=>e.selectors).join(", "),yn=[".form-item",".ant-form-item",".el-form-item",".n-form-item",".arco-form-item",".van-cell",".van-field",".field",".form-row"].join(", "),mn=["label",".ant-form-item-label",".el-form-item__label",".n-form-item-label",".arco-form-item-label",".van-field__label",".label"].join(", "),nt=["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(", "),bn=["is-checked","ant-switch-checked","n-switch--active","arco-switch-checked","van-switch--on","van-radio--checked","van-checkbox--checked"];function P(e){return R.find(t=>e.matches(t.selectors))||null}function rt(e){return!!P(e)}function Le(e){for(let t=e;t;t=t.parentElement)if(rt(t))return t;return null}function oe(e){var n;const t=P(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=d(((n=e.querySelector(".van-field__control"))==null?void 0:n.textContent)||"");if(!e.querySelector("textarea")&&(o==="请选择"||o===""))return"select"}}return t.type}function ot(e){const t=P(e);if(t!=null&&t.optionSelector)return Array.from(e.querySelectorAll(t.optionSelector)).map(n=>vn(n)).filter(n=>!!(n.label||n.value))}function vn(e){const t=e instanceof HTMLInputElement?e:e.querySelector('input[type="radio"],input[type="checkbox"]'),n=d(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 V(e){return bn.some(t=>e.classList.contains(t))||e.getAttribute("aria-checked")==="true"||!!e.querySelector("input:checked")}function H(e){return e.querySelector('input:not([type="hidden"]), textarea')}function it(e){var t,n,r;return e.getAttribute("name")||((t=H(e))==null?void 0:t.getAttribute("name"))||e.getAttribute("data-smart-fill-key")||((n=H(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 d(e){return e.replace(/[*::]/g,"").replace(/\s+/g," ").trim()}const Ie="data-smart-fill-hide-dropdown-mode",st="smart-fill-hide-dropdown-style",at=["[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(", "),wn=[".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(", "),Me=["[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(", "),ie=[Me,".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(", "),Re=[".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(", "),ct=[".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(", "),lt=[".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(", "),Sn=/(?:省|市|自治区|特别行政区|自治州|地区|盟|县|区)$/,En=/地址|省|市|区|县|地区|籍贯|户籍|居住地|所在地|区域/,xn=new Set(["select","cascader","date"]);function C(e){return!wt(e)||ft(e)?!1:!!e.closest(".el-cascader, .ant-cascader, .van-cascader, .n-cascader, .arco-cascader")}function x(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=d(((n=e.querySelector(".van-field__control"))==null?void 0:n.textContent)||"");if(!e.querySelector("textarea")&&(r==="请选择"||r===""))return!0}return!1}function B(e){return!wt(e)||ft(e)||e instanceof HTMLSelectElement||e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement?!1:e.matches(at)||e.getAttribute("role")==="combobox"||e.getAttribute("aria-haspopup")==="listbox"||e.classList.contains("el-select__wrapper")||e.classList.contains("el-select-v2__wrapper")||x(e)}function U(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")&&!x(n)?null:n:B(e)?e:null}function Fe(e){if(e instanceof HTMLSelectElement)return e;if(C(e))return e.closest(".el-cascader, .ant-cascader, .van-cascader, .n-cascader, .arco-cascader")||e;const t=U(e);return t||(e.matches(".van-field")&&x(e)?e:null)}function ut(e){if(C(e))return"cascader";if(B(e)||x(e))return"select";const t=oe(e);return t||(e instanceof HTMLSelectElement?"select":null)}function Oe(e,t){const n=t||ut(e);return n!=null&&xn.has(n)}function kn(e){const t=e.matches(".van-field")?e:e.closest(".van-field");if(t instanceof HTMLElement&&x(t)){const i=t.querySelector(".van-field__control");if(i instanceof HTMLInputElement)return d(i.value);const s=d((i==null?void 0:i.textContent)||"");return s&&s!=="请选择"?s:""}const n=e.querySelector(wn);if(n instanceof HTMLInputElement)return d(n.value);const r=d((n==null?void 0:n.textContent)||"");if(r&&r!=="请选择")return r;const o=e.querySelector('input:not([type="hidden"])');return o!=null&&o.value?d(o.value):r}function dt(e){const t=Mn(e);if(!t.length)return;const n=Rn(t);return n.length?n:void 0}function se(e){var t;return!((t=e.options)!=null&&t.length)||e.type==="cascader"||En.test(e.label||"")?!1:Hn(e.options)}async function _n(e){if(e instanceof HTMLSelectElement)return Array.from(e.options).map(s=>({value:s.value,label:d(s.textContent||s.label)})).filter(s=>s.label||s.value);const t=dt(e);if(t!=null&&t.length)return t;const n=U(e)||e;if(!B(n)&&!C(n)&&!x(n))return;const r=Kn(),o=Nn(),i=new Set(o.getTrackedDropdowns());try{if(!(C(n)?await Cn(n,o,i):await An(n,o,i)))return;const a=await Ln(o,i,n);if(!a.length)return;const c=Tn(a);return c.length?c:void 0}finally{await zn(n,o),await F(60),o.restore(),r()}}function ft(e){return e.hasAttribute("disabled")||e.getAttribute("aria-disabled")==="true"}async function An(e,t,n){const r=j(e);if(!r.length)return!1;for(const o of r)if(bt(o),mt(o),await F(160),pt(e,t,n)||(vt(o),await F(180),pt(e,t,n)))return!0;return!1}async function Cn(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(bt(o),mt(o),await F(180),ae(t,n,e).length||(vt(o),await F(180),ae(t,n,e).length))return!0;return!1}function Tn(e){var r;const t=new Set,n=[];for(const o of e){const i=o.matches(ie)?[o]:Array.from(o.querySelectorAll(ie));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=d(((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 Ln(e,t,n){for(let r=0;r<8;r+=1){const o=ae(e,t,n);if(o.length)return o;await F(r===0?120:80)}return[]}function pt(e,t,n){return ae(t,n,e).length>0?!0:j(e).some(r=>r.getAttribute("aria-expanded")==="true"||r.classList.contains("is-focus")||r.classList.contains("is-focused"))}function In(e,t,n){const r=t.filter(c=>De(e,c)),o=r.filter(c=>Fn(e,c)),i=o.filter(c=>!n.has(c));if(i.length)return i.sort((c,l)=>N(l,e)-N(c,e));const s=ht(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)=>N(l,e)-N(c,e)).slice(0,1);const a=r.filter(c=>Pn(c)&&gt(e)).sort((c,l)=>N(l,e)-N(c,e)).slice(0,1);return a.length?a:[]}function ae(e,t,n){return In(n,e.getTrackedDropdowns(),t)}function N(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+=yt(t,e)),o}function Mn(e){const t=C(e)?lt:ct,n=new Set;e.matches(t)&&n.add(e);for(const r of e.querySelectorAll(t))De(e,r)&&n.add(r);for(const r of e.querySelectorAll("[role='listbox']"))e.contains(r)&&De(e,r)&&n.add(r);return[...n]}function Rn(e){const t=new Set,n=[];for(const r of e){const o=r.matches(Me)?[r]:Array.from(r.querySelectorAll(Me));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=d(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 ht(e){return new Set(j(e).flatMap(t=>[t.getAttribute("aria-controls"),t.getAttribute("aria-owns")]).filter(t=>!!t))}function Fn(e,t){const n=ht(e);return n.size&&t.id&&n.has(t.id)||e.contains(t)?!0:qn(t)?gt(e):n.size>0||j(e).some(o=>o.getAttribute("aria-controls")||o.getAttribute("aria-owns"))?!1:yt(e,t)>0}function De(e,t){const n=C(e),r=On(t);return n?r:r?!1:Dn(t)}function On(e){return e.matches(lt)||!!e.querySelector(".el-cascader-node, .ant-cascader-menu-item, .van-cascader__option, .n-cascader-node, .arco-cascader-option")}function Dn(e){return e.matches(ct)||!!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 qn(e){return e.matches(".van-popup, .van-action-sheet, .van-picker, .van-dropdown-item__content, .van-dropdown-item")}function gt(e){return j(e).some(t=>t.getAttribute("aria-expanded")==="true"||t.classList.contains("is-focus")||t.classList.contains("is-focused")||e.contains(document.activeElement))}function Pn(e){return e.matches(ie)||!!e.querySelector(ie)}function yt(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 Hn(e){const t=e.slice(0,8).map(r=>d(String(r.label||r.value||""))).filter(Boolean);return t.length<4?!1:t.filter(r=>Sn.test(r)).length/t.length>=.75}function j(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 Nn(){const e=new Map;$n(),document.documentElement.setAttribute(Ie,"true");const t=()=>{for(const r of document.querySelectorAll(Re))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(Re)),restore:()=>{n.disconnect(),document.documentElement.removeAttribute(Ie);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 $n(){if(document.getElementById(st))return;const e=document.createElement("style");e.id=st,e.textContent=`
2
- ${Re.split(",").map(t=>`html[${Ie}="true"] ${t.trim()}`).join(`,
1
+ (function(y,S){typeof exports=="object"&&typeof module<"u"?S(exports):typeof define=="function"&&define.amd?define(["exports"],S):(y=typeof globalThis<"u"?globalThis:y||self,S(y.SmartFillSDK={}))})(this,function(y){"use strict";var eo=Object.defineProperty;var to=(y,S,q)=>S in y?eo(y,S,{enumerable:!0,configurable:!0,writable:!0,value:q}):y[S]=q;var f=(y,S,q)=>to(y,typeof S!="symbol"?S+"":S,q);const S={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}))}},q=[{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"}],wn=["is-disabled","ant-select-disabled","n-select--disabled","arco-select-disabled","van-field--disabled","van-switch--disabled","van-stepper--disabled","van-dropdown-menu--disabled"],nt=q.map(e=>e.selectors).join(", "),Sn=[".form-item",".ant-form-item",".el-form-item",".n-form-item",".arco-form-item",".van-cell",".van-field",".field",".form-row"].join(", "),En=["label",".ant-form-item-label",".el-form-item__label",".n-form-item-label",".arco-form-item-label",".van-field__label",".label"].join(", "),rt=["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(", "),xn=["is-checked","ant-switch-checked","n-switch--active","arco-switch-checked","van-switch--on","van-radio--checked","van-checkbox--checked"];function K(e){return q.find(t=>e.matches(t.selectors))||null}function it(e){return!!K(e)}function Ie(e){for(let t=e;t;t=t.parentElement)if(it(t))return t;return null}function ce(e){var n;const t=K(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 i=(r.getAttribute("placeholder")||"").trim();if(!i||/选择|select/i.test(i))return"select"}if(e.classList.contains("van-field--clickable")){const i=d(((n=e.querySelector(".van-field__control"))==null?void 0:n.textContent)||"");if(!e.querySelector("textarea")&&(i==="请选择"||i===""))return"select"}}return t.type}function ot(e){const t=K(e);if(t!=null&&t.optionSelector)return Array.from(e.querySelectorAll(t.optionSelector)).map(n=>kn(n)).filter(n=>!!(n.label||n.value))}function kn(e){const t=e instanceof HTMLInputElement?e:e.querySelector('input[type="radio"],input[type="checkbox"]'),n=d(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 Y(e){return xn.some(t=>e.classList.contains(t))||e.getAttribute("aria-checked")==="true"||!!e.querySelector("input:checked")}function V(e){return e.querySelector('input:not([type="hidden"]), textarea')}function st(e){var t,n,r;return e.getAttribute("name")||((t=V(e))==null?void 0:t.getAttribute("name"))||e.getAttribute("data-smart-fill-key")||((n=V(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 d(e){return e.replace(/[*::]/g,"").replace(/\s+/g," ").trim()}const Me="data-smart-fill-hide-dropdown-mode",at="smart-fill-hide-dropdown-style",ct=["[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(", "),_n=[".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(", "),Re=["[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(", "),le=[Re,".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(", "),Fe=[".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(", "),lt=[".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(", "),ut=[".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(", "),An=/(?:省|市|自治区|特别行政区|自治州|地区|盟|县|区)$/,Cn=/地址|省|市|区|县|地区|籍贯|户籍|居住地|所在地|区域/,Tn=new Set(["select","cascader","date"]);function L(e){return!St(e)||pt(e)?!1:!!e.closest(".el-cascader, .ant-cascader, .van-cascader, .n-cascader, .arco-cascader")}function _(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=d(((n=e.querySelector(".van-field__control"))==null?void 0:n.textContent)||"");if(!e.querySelector("textarea")&&(r==="请选择"||r===""))return!0}return!1}function W(e){return!St(e)||pt(e)||e instanceof HTMLSelectElement||e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement?!1:e.matches(ct)||e.getAttribute("role")==="combobox"||e.getAttribute("aria-haspopup")==="listbox"||e.classList.contains("el-select__wrapper")||e.classList.contains("el-select-v2__wrapper")||_(e)}function X(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")&&!_(n)?null:n:W(e)?e:null}function Oe(e){if(e instanceof HTMLSelectElement)return e;if(L(e))return e.closest(".el-cascader, .ant-cascader, .van-cascader, .n-cascader, .arco-cascader")||e;const t=X(e);return t||(e.matches(".van-field")&&_(e)?e:null)}function dt(e){if(L(e))return"cascader";if(W(e)||_(e))return"select";const t=ce(e);return t||(e instanceof HTMLSelectElement?"select":null)}function qe(e,t){const n=t||dt(e);return n!=null&&Tn.has(n)}function Ln(e){const t=e.matches(".van-field")?e:e.closest(".van-field");if(t instanceof HTMLElement&&_(t)){const o=t.querySelector(".van-field__control");if(o instanceof HTMLInputElement)return d(o.value);const s=d((o==null?void 0:o.textContent)||"");return s&&s!=="请选择"?s:""}const n=e.querySelector(_n);if(n instanceof HTMLInputElement)return d(n.value);const r=d((n==null?void 0:n.textContent)||"");if(r&&r!=="请选择")return r;const i=e.querySelector('input:not([type="hidden"])');return i!=null&&i.value?d(i.value):r}function ft(e){const t=Dn(e);if(!t.length)return;const n=Pn(t);return n.length?n:void 0}function ue(e){var t;return!((t=e.options)!=null&&t.length)||e.type==="cascader"||Cn.test(e.label||"")?!1:Vn(e.options)}async function In(e){if(e instanceof HTMLSelectElement)return Array.from(e.options).map(s=>({value:s.value,label:d(s.textContent||s.label)})).filter(s=>s.label||s.value);const t=ft(e);if(t!=null&&t.length)return t;const n=X(e)||e;if(!W(n)&&!L(n)&&!_(n))return;const r=Gn(),i=Bn(),o=new Set(i.getTrackedDropdowns());try{if(!(L(n)?await Rn(n,i,o):await Mn(n,i,o)))return;const a=await On(i,o,n);if(!a.length)return;const c=Fn(a);return c.length?c:void 0}finally{await jn(n,i),await D(60),i.restore(),r()}}function pt(e){return e.hasAttribute("disabled")||e.getAttribute("aria-disabled")==="true"}async function Mn(e,t,n){const r=Z(e);if(!r.length)return!1;for(const i of r)if(vt(i),mt(i),await D(160),ht(e,t,n)||(wt(i),await D(180),ht(e,t,n)))return!0;return!1}async function Rn(e,t,n){const r=[e,e.querySelector(".el-input__wrapper"),e.querySelector(".el-input"),e.querySelector(".van-field__control"),e.querySelector("input")].filter(i=>i instanceof HTMLElement);for(const i of r)if(vt(i),mt(i),await D(180),de(t,n,e).length||(wt(i),await D(180),de(t,n,e).length))return!0;return!1}function Fn(e){var r;const t=new Set,n=[];for(const i of e){const o=i.matches(le)?[i]:Array.from(i.querySelectorAll(le));for(const s of o){if(s.classList.contains("is-disabled")||s.classList.contains("ant-select-item-option-disabled")||s.getAttribute("aria-disabled")==="true")continue;const a=d(((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 On(e,t,n){for(let r=0;r<8;r+=1){const i=de(e,t,n);if(i.length)return i;await D(r===0?120:80)}return[]}function ht(e,t,n){return de(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 qn(e,t,n){const r=t.filter(c=>De(e,c)),i=r.filter(c=>Nn(e,c)),o=i.filter(c=>!n.has(c));if(o.length)return o.sort((c,l)=>B(l,e)-B(c,e));const s=gt(e);if(s.size){const c=i.filter(l=>l.id&&s.has(l.id));if(c.length)return c}if(i.length)return i.sort((c,l)=>B(l,e)-B(c,e)).slice(0,1);const a=r.filter(c=>Kn(c)&&yt(e)).sort((c,l)=>B(l,e)-B(c,e)).slice(0,1);return a.length?a:[]}function de(e,t,n){return qn(n,e.getTrackedDropdowns(),t)}function B(e,t){const n=e.getBoundingClientRect(),r=Number.parseInt(window.getComputedStyle(e).zIndex||"0",10);let i=(Number.isNaN(r)?0:r)*10+n.width*n.height;return t&&(i+=bt(t,e)),i}function Dn(e){const t=L(e)?ut:lt,n=new Set;e.matches(t)&&n.add(e);for(const r of e.querySelectorAll(t))De(e,r)&&n.add(r);for(const r of e.querySelectorAll("[role='listbox']"))e.contains(r)&&De(e,r)&&n.add(r);return[...n]}function Pn(e){const t=new Set,n=[];for(const r of e){const i=r.matches(Re)?[r]:Array.from(r.querySelectorAll(Re));for(const o of i){if(o.classList.contains("is-disabled")||o.classList.contains("ant-select-item-option-disabled")||o.getAttribute("aria-disabled")==="true")continue;const s=d(o.textContent||""),a=o.getAttribute("data-value")||o.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 gt(e){return new Set(Z(e).flatMap(t=>[t.getAttribute("aria-controls"),t.getAttribute("aria-owns")]).filter(t=>!!t))}function Nn(e,t){const n=gt(e);return n.size&&t.id&&n.has(t.id)||e.contains(t)?!0:zn(t)?yt(e):n.size>0||Z(e).some(i=>i.getAttribute("aria-controls")||i.getAttribute("aria-owns"))?!1:bt(e,t)>0}function De(e,t){const n=L(e),r=Hn(t);return n?r:r?!1:$n(t)}function Hn(e){return e.matches(ut)||!!e.querySelector(".el-cascader-node, .ant-cascader-menu-item, .van-cascader__option, .n-cascader-node, .arco-cascader-option")}function $n(e){return e.matches(lt)||!!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 zn(e){return e.matches(".van-popup, .van-action-sheet, .van-picker, .van-dropdown-item__content, .van-dropdown-item")}function yt(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(le)||!!e.querySelector(le)}function bt(e,t){const n=e.getBoundingClientRect(),r=t.getBoundingClientRect();if(!n.width||!n.height||!r.width||!r.height)return 0;const i=Math.min(n.right,r.right)-Math.max(n.left,r.left);if(i<=0)return 0;const o=r.top>=n.bottom?r.top-n.bottom:n.top-r.bottom;return o>320?0:Math.max(0,400-o)+i}function Vn(e){const t=e.slice(0,8).map(r=>d(String(r.label||r.value||""))).filter(Boolean);return t.length<4?!1:t.filter(r=>An.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,i)=>i.indexOf(n)===r)}function Bn(){const e=new Map;Un(),document.documentElement.setAttribute(Me,"true");const t=()=>{for(const r of document.querySelectorAll(Fe))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(Fe)),restore:()=>{n.disconnect(),document.documentElement.removeAttribute(Me);for(const[r,i]of e)r.style.display=i.display,r.style.opacity=i.opacity,r.style.visibility=i.visibility,r.style.pointerEvents=i.pointerEvents}}}function Un(){if(document.getElementById(at))return;const e=document.createElement("style");e.id=at,e.textContent=`
2
+ ${Fe.split(",").map(t=>`html[${Me}="true"] ${t.trim()}`).join(`,
3
3
  `)} {
4
4
  opacity: 0 !important;
5
5
  visibility: hidden !important;
@@ -7,7 +7,7 @@
7
7
  transition: none !important;
8
8
  animation: none !important;
9
9
  }
10
- `,document.head.appendChild(e)}async function zn(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 F(120);for(const n of t.getTrackedDropdowns())n.isConnected&&(n.style.display="none",n.setAttribute("aria-hidden","true"))}function mt(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 bt(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 F(e){return new Promise(t=>window.setTimeout(t,e))}function Kn(){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 wt(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}const Vn=/(维吾尔自治区|壮族自治区|回族自治区|特别行政区|自治区直辖县级行政区划|自治区|自治州|地区|盟|林区|街道|苏木|社区|省|市|区|县|旗|镇|乡)$/g,Bn=new Set(["市辖区","县","自治区直辖县级行政区划"]);let ce=null;function v(e){return String(e??"").replace(/\s+/g,"").replace(/[,,。.、/\\\-]/g,"").trim().toLowerCase()}function T(e){return v(e).replace(Vn,"")}function qe(e){if(e==null)return"";if(typeof e=="string"||typeof e=="number")return String(e).trim();if(Array.isArray(e))return e.map(t=>qe(t)).filter(Boolean).join("");if(typeof e=="object"){const t=[],n=new Set,r=o=>{const i=d(String(o??""));!i||n.has(i)||(n.add(i),t.push(i))};for(const o of["province","provinceName","prov","city","cityName","district","districtName","area","areaName","county","countyName","region","regionName","address","detail","detailAddress","fullAddress","label","text","value","name","answer"])r(e[o]);return t.join("")}return d(String(e))}function le(e){const t=[],n=[],r=s=>{const a=d(String(s??""));a&&t.push(a)},o=s=>{const a=v(s);a&&(n.push(a),r(s))};if(Array.isArray(e))for(const s of e)o(s);else if(typeof e=="object"&&e){for(const s of["province","provinceName","prov","city","cityName","district","districtName","area","areaName","county","countyName","region","regionName"])o(e[s]);for(const s of["address","detail","detailAddress","fullAddress","label","value","text","name","answer"])r(e[s])}else r(e);const i=v(t.join(""));return{fullText:i,looseFullText:T(i),structuredParts:n}}function ue(e,t){const n=v(e),r=v(t);if(!n||!r)return!1;if(n===r||n.includes(r)||r.includes(n))return!0;const o=T(n),i=T(r);return!o||!i?!1:o===i||o.includes(i)||i.includes(o)}function Pe(e,t=le(e)){const n=Zn();if(!n.length)return[];let r=null,o=0;for(const i of n){const s=Yn(i,t);s>o&&(o=s,r=i)}return o>=120?(r==null?void 0:r.labels)||[]:[]}function Un(e,t,n,r){let o=null,i=0;const s=jn(t,n,r);for(const a of e){const c=a.querySelector(".el-cascader-node__label, .ant-cascader-menu-item-content, .n-cascader-node__label, .arco-cascader-option-label"),l=d((c==null?void 0:c.textContent)||a.textContent||""),u=v(l);if(!u)continue;const p=T(u);let m=Gn(u,p,s);!m&&t.fullText&&(t.fullText.includes(u)?m=100+u.length:u.includes(t.fullText)?m=70+t.fullText.length:t.looseFullText.includes(p)&&(m=80+p.length)),m>i&&(i=m,o=a)}return i>=75?o:null}function jn(e,t,n){const r=[],o=new Set,i=(s,a)=>{const c=v(s);!c||o.has(c)||(o.add(c),r.push({normalized:c,stripped:T(c),score:a}))};if(t.length){t[n]&&i(t[n],260);for(let s=n+1;s<t.length;s+=1)i(t[s],215-(s-n)*15)}e.structuredParts[n]&&i(e.structuredParts[n],235);for(let s=0;s<e.structuredParts.length;s+=1)s!==n&&i(e.structuredParts[s],180-Math.abs(s-n)*20);return e.fullText&&i(e.fullText,130),r}function Gn(e,t,n){let r=0;for(const o of n){let i=0;o.normalized===e?i=o.score+80:o.stripped&&o.stripped===t?i=o.score+68:o.normalized.includes(e)?i=o.score+40+e.length:e.includes(o.normalized)?i=o.score+28+o.normalized.length:o.stripped&&t&&o.stripped.includes(t)?i=o.score+24+t.length:o.stripped&&t&&t.includes(o.stripped)&&(i=o.score+20+o.stripped.length),i>r&&(r=i)}return r}function Yn(e,t){let n=0,r=0;for(let o=0;o<e.aliasesByLevel.length;o+=1){const i=Wn(e.aliasesByLevel[o],t.structuredParts[o]||"",t.fullText,t.looseFullText,o);i>0?(r+=1,n+=i):t.structuredParts[o]&&(n-=30)}return n+=r*18+e.labels.length*4,t.structuredParts.length>e.labels.length&&(n-=(t.structuredParts.length-e.labels.length)*10),n}function Wn(e,t,n,r,o){const i=[60,95,135,160][o]||160;let s=0;for(const a of e){let c=0;const l=T(a);t&&(t===a?c=Math.max(c,i+130+a.length):t.includes(a)||a.includes(t)?c=Math.max(c,i+95+Math.min(a.length,t.length)):l&&T(t)===l&&(c=Math.max(c,i+80+l.length))),n&&(n.includes(a)?c=Math.max(c,i+50+a.length):l&&r.includes(l)&&(c=Math.max(c,i+35+l.length))),c>s&&(s=c)}return s}function Xn(e){const t=d(e),n=v(t);if(!n)return[];const r=new Set([n]),o=T(n);o&&!Bn.has(t)&&r.add(o);const i={内蒙古自治区:"内蒙古",广西壮族自治区:"广西",西藏自治区:"西藏",宁夏回族自治区:"宁夏",新疆维吾尔自治区:"新疆",香港特别行政区:"香港",澳门特别行政区:"澳门"};return i[t]&&r.add(i[t]),Array.from(r).filter(Boolean)}function Zn(){if(ce)return ce;const e=globalThis.__SMART_FILL_ADDRESS_MAP__,t=e==null?void 0:e.data,n=Array.isArray(t)?t:Array.isArray(t==null?void 0:t.data)?t.data:[];return ce=Jn(n),ce}function Jn(e){const t=[],n=new Set,r=o=>{const i=o.map(a=>d(a)).filter(Boolean);if(!i.length)return;const s=i.join(">");n.has(s)||(n.add(s),t.push({labels:i,aliasesByLevel:i.map(a=>Xn(a))}))};for(const o of e)if(o!=null&&o.label&&(r([o.label]),!(!Array.isArray(o.children)||!o.children.length))){for(const i of o.children)if(i!=null&&i.label&&(r([o.label,i.label]),!(!Array.isArray(i.children)||!i.children.length)))for(const s of i.children)s!=null&&s.label&&r([o.label,i.label,s.label])}return t}function de(e,t){const n=fe(t);if(!n.length)return null;let r=null,o=0;for(const i of e){const s=L(i.value),a=L(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&&pe(s)===pe(c)||a&&pe(a)===pe(c))&&(l=80),l>o&&(o=l,r=i)}}return o>=80?r:null}function fe(e){if(Array.isArray(e))return e.flatMap(n=>fe(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=>L(r)).filter(Boolean)}const t=L(e);return t?[t]:[]}function L(e){return String(e??"").replace(/\s+/g,"").replace(/[::,,。.、()()\-_/]/g,"").trim().toLowerCase()}function pe(e){return L(e).replace(/(请选择|选择|状态|情况|类型|方式|所属|是否)$/g,"")}const he=[".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(", "),Qn=[".el-cascader-panel .el-cascader-menu",".ant-cascader-menu",".van-cascader__options",".n-cascader-menu",".arco-cascader-list"].join(", "),er=[".el-cascader-node",".ant-cascader-menu-item",".van-cascader__option",".n-cascader-node",".arco-cascader-option"].join(", "),tr=".van-picker__confirm, .van-picker__toolbar .van-picker__confirm";async function nr(e,t,n,r){const o=xt(t,r);return e instanceof HTMLSelectElement?rr(e,o):C(e)||n==="cascader"?or(e,o):(B(e)||x(e)||n==="select"||n==="date",Et(e,o))}function St(e){if(e instanceof HTMLSelectElement){const n=e.options[e.selectedIndex];return d((n==null?void 0:n.textContent)||e.value)}if(C(e)){const n=e.querySelector("input");if(n!=null&&n.value)return d(n.value);const r=e.querySelector(".el-cascader__tags-text, .el-cascader__label");return d((r==null?void 0:r.textContent)||"")}if(B(e)||x(e))return kn(e);const t=e.querySelector("input, textarea");return d((t==null?void 0:t.value)||e.textContent||"")}async function rr(e,t){const n=Array.from(e.options).map(o=>({source:o,value:o.value,label:o.textContent})),r=de(n,t.searchValue);if((r==null?void 0:r.source)instanceof HTMLOptionElement){X(e,r.source.value),k(e);return}if(!ge(e,t))throw new Error("原生下拉框中没有匹配到对应选项")}async function Et(e,t){const n=U(e)||e;if(Ne(n,t.searchValue))return;const r=new Set(W());try{if(!await ir(n)){if(ge(n,t))return;throw new Error("自定义下拉框未能成功展开")}const i=await gr(n,r),s=await ar(t.searchValue,i,!0);if(!(s!=null&&s.source)){if(await me(n),ge(n,t))return;throw new Error("自定义下拉框展开后未找到匹配选项")}if(O(s.source),await y(120),mr(),k(n),await y(120),Ne(n,t.searchValue)||ge(n,t)&&Ne(n,t.searchValue))return;throw new Error("自定义下拉框点击选项后未成功回填")}finally{await me(n),await y(80)}}async function or(e,t){const n=e.closest(".el-cascader, .ant-cascader, .van-cascader, .n-cascader, .arco-cascader")||e;if(!Lt(n,t.searchValue)){ye(n)&&(await At(n),await y(120));try{if(await sr(n)){const o=await ur(t.searchValue);if(await y(180),await me(n),await y(120),o&&Lt(n,t.searchValue)){k(n);return}}}finally{await me(n),await y(80)}throw await At(n),new Error("级联选择框匹配失败")}}function xt(e,t){var s;const n=(s=t==null?void 0:t.options)!=null&&s.length?de(t.options.map(a=>({value:String(a.value),label:a.label})),e):null,r=$(e),o=d(String((n==null?void 0:n.label)??r??"")),i=d(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 ir(e){const t=He(e);for(const n of t)if(Mt(n),O(n),await y(160),Tt(e)||(Rt(n),await y(180),Tt(e)))return!0;return!1}async function sr(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(n.scrollIntoView({block:"nearest",inline:"nearest"}),Mt(n),O(n),await y(180),Y().length||(Rt(n),await y(180),Y().length))return!0;return!1}async function ar(e,t,n=!1){for(let r=0;r<12;r+=1){const o=de(Ct(t,n).map(i=>({source:i,value:cr(i),label:lr(i)})),e);if(o)return o;await y(100)}return null}function cr(e){return e.getAttribute("data-value")||e.getAttribute("data-name")||e.getAttribute("value")||e.getAttribute("name")||e.textContent||""}function lr(e){var t;return d(((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 ur(e){const t=le(e),n=Pe(e,t),r=It(e),o=Math.max(n.length,r.length,1);if(!t.fullText&&!t.structuredParts.length&&!r.length)return!1;for(let i=0;i<o;i+=1){const s=Y();if(!s.length)return i>0;const a=s[Math.min(i,s.length-1)],c=Array.from(a.querySelectorAll(er)).filter(u=>!u.classList.contains("is-disabled")&&u.getAttribute("aria-disabled")!=="true");if(!c.length)return!1;let l=null;if((n.length||t.structuredParts.length)&&(l=Un(c,t,n,i)),!l&&r[i]){const u=de(c.map(p=>{var m;return{source:p,value:p.getAttribute("data-value")||p.textContent,label:((m=p.querySelector(".el-cascader-node__label"))==null?void 0:m.textContent)||p.textContent}}),r[i]);l=(u==null?void 0:u.source)instanceof HTMLElement?u.source:null}if(!l)return!1;if(O(l),await y(220),!Y().length)return!0}return!Y().length||!0}function ge(e,t){const n=hr(t)?t:xt(t),r=n.displayValue||$(t),o=n.fillValue||r;if(!r&&!o)return!1;const i=U(e)||e;if(x(i))return fr(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,X(e,o),k(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(),X(s,r),s.dispatchEvent(new InputEvent("input",{bubbles:!0,composed:!0,data:r,inputType:"insertReplacementText"})),s.dispatchEvent(new Event("change",{bubbles:!0,composed:!0})),k(s),k(e),s.blur(),!0}catch{return!1}finally{a&&(s.readOnly=!0,c&&s.setAttribute("readonly",""))}}function dr(e){const t=le(e),n=Pe(e,t);if(n.length)return n.join(" / ");const r=It(e);return r.length?r.join(" / "):qe(e)}function kt(e){const t=e.querySelector("input");return t instanceof HTMLInputElement?t:null}function _t(e){const t=kt(e);if(t!=null&&t.value)return d(t.value);const n=e.querySelector(".el-cascader__tags-text, .el-cascader__label");return d((n==null?void 0:n.textContent)||"")}function ye(e){return!!v(_t(e))}async function At(e){if(!ye(e))return;const t=e.querySelector(".el-input__wrapper, .el-input, .ant-select-selector");t&&(t.dispatchEvent(new MouseEvent("mouseenter",{bubbles:!0})),t.dispatchEvent(new MouseEvent("mouseover",{bubbles:!0})),await y(80));const n=e.querySelector(".el-input__clear, .el-icon-circle-close, .ant-select-clear, .ant-cascader-picker-clear, .van-icon-clear");if(n&&(O(n),await y(180),!ye(e)))return;const r=kt(e);if(r&&!r.disabled){const i=r.readOnly,s=r.hasAttribute("readonly");try{i&&(r.readOnly=!1,r.removeAttribute("readonly")),X(r,""),r.dispatchEvent(new InputEvent("input",{bubbles:!0,composed:!0,inputType:"deleteContentBackward"})),r.dispatchEvent(new Event("change",{bubbles:!0,composed:!0})),k(r)}finally{i&&(r.readOnly=!0,s&&r.setAttribute("readonly",""))}await y(120)}const o=e.querySelector(".el-tag__close, .el-cascader__tags .el-icon-close");o&&ye(e)&&(O(o),await y(120))}function fr(e,t,n){pr(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?G(r,t||n):r instanceof HTMLElement&&(r.textContent=t||n);for(const s of o)G(s,n);for(const s of i)r!==s&&G(s,t||n);return k(e),!0}function pr(e){const t=e.querySelector(".van-field__control");t instanceof HTMLInputElement?G(t,""):t instanceof HTMLElement&&(t.textContent="");for(const n of e.querySelectorAll("input"))G(n,"")}function G(e,t){if(e.disabled)return;const n=e.readOnly,r=e.hasAttribute("readonly");try{n&&(e.readOnly=!1,e.removeAttribute("readonly")),X(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})),k(e)}finally{n&&(e.readOnly=!0,r&&e.setAttribute("readonly",""))}}function hr(e){return typeof e=="object"&&e!=null&&"searchValue"in e&&"fillValue"in e&&"displayValue"in e}function He(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 Ct(e,t){return(e.length?e:W()).flatMap(o=>o.matches(he)?[o]:Array.from(o.querySelectorAll(he))).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":z(o)&&!o.classList.contains("is-disabled")&&!o.classList.contains("ant-select-item-option-disabled")&&o.getAttribute("aria-disabled")!=="true")}function Y(){return Array.from(document.querySelectorAll(Qn)).filter(z)}async function gr(e,t){for(let n=0;n<10;n+=1){const r=yr(e,t);if(r.length)return r;await y(80)}return W().filter(z)}function yr(e,t){const n=W(),r=n.filter(i=>!t.has(i));if(r.length)return r.sort((i,s)=>be(s)-be(i));const o=new Set(He(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=>z(i)&&(i.querySelector(he)||i.matches(he))).sort((i,s)=>be(s)-be(i)).slice(0,1)}function Tt(e){return Ct(W().filter(z),!1).length>0?!0:He(e).some(t=>t.getAttribute("aria-expanded")==="true"||t.classList.contains("is-focus")||t.classList.contains("is-focused"))}function Lt(e,t){const n=_t(e),r=v(n);if(!r)return!1;const o=qe(t),i=v(o);if(ue(r,i))return!0;const s=le(t),a=Pe(t,s),c=v(a.join(""));if(ue(r,c))return!0;const l=v(dr(t));if(ue(r,l))return!0;const u=v(s.structuredParts.join(""));return ue(r,u)}function Ne(e,t){const n=L(St(e));if(!n)return!1;const r=fe(t);if(!r.length){const o=L($(t));return o?n===o||n.includes(o)||o.includes(n):!1}return r.some(o=>{const i=L(o);return!!i&&(n===i||n.includes(i)||i.includes(n))})}function mr(){const e=document.querySelector(tr);e&&z(e)&&O(e)}async function me(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 y(120)}function W(){return Array.from(document.querySelectorAll(br()))}function be(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 br(){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 $(e){if(e==null)return"";if(typeof e=="string"||typeof e=="number"||typeof e=="boolean")return d(String(e));if(Array.isArray(e))return e.map(t=>$(t)).filter(Boolean).join(" ");if(typeof e=="object"){const t=e;for(const n of["label","text","value","answer","name"]){const r=$(t[n]);if(r)return r}}return d(String(e))}function It(e){const t=$(e);if(!t)return[];if(t.includes("/")||t.includes("、"))return t.split(/[//、]/).map(r=>r.trim()).filter(Boolean);const n=fe(e);return n.length?[d(n[0])]:[t]}function X(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 k(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 O(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 Mt(e){e.focus({preventScroll:!0});const t=e instanceof HTMLInputElement?e:e.querySelector("input");t instanceof HTMLElement&&t.focus({preventScroll:!0})}function Rt(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 z(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 y(e){return new Promise(t=>window.setTimeout(t,e))}const Ft=new Set(["select","cascader","date"]),$e={name:"ui-framework",match:e=>e.matches(tt)||rt(e)||!wr(e)&&Oe(e),getValue:e=>{var o,i;const t=e.element;if(!t)return;const n=P(t);if((n==null?void 0:n.kind)==="switch")return V(t);if((n==null?void 0:n.kind)==="radioGroup")return kr(t);if((n==null?void 0:n.kind)==="checkboxGroup")return _r(t);const r=e.type||oe(t)||(n==null?void 0:n.type);return r&&Ft.has(r)?St(t):n?((i=H(t))==null?void 0:i.value)||t.textContent||void 0:(o=H(t))==null?void 0:o.value},setValue:async(e,t)=>{const n=e.element;if(!n)return;const r=P(n);if((r==null?void 0:r.kind)==="switch"){Sr(n,t);return}if((r==null?void 0:r.kind)==="radioGroup"){xr(n,t);return}if((r==null?void 0:r.kind)==="checkboxGroup"){Er(n,t);return}const o=e.type||oe(n)||(r==null?void 0:r.type);if(o&&Ft.has(o)||Oe(n,o||void 0)){await nr(n,t,o||"select",e);return}const i=H(n);if(i){Ar(i,t);return}n.dispatchEvent(new Event("change",{bubbles:!0}))}},vr=$e;function wr(e){return e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement||e instanceof HTMLSelectElement}function Sr(e,t){V(e)!==Cr(t)&&ve(e)}function Er(e,t){var o;const n=new Set(Tr(t).map(I)),r=ot(e)||[];for(const i of Z(e)){const s=J(i.textContent||""),a=i.getAttribute("value")||((o=i.querySelector("input"))==null?void 0:o.value)||s,c=V(i),l=n.has(I(String(a)))||n.has(I(s));c!==l&&ve(i)}if(!Z(e).length&&r.length)for(const i of r)(n.has(I(String(i.value)))||n.has(I(i.label)))&&ve(e)}function xr(e,t){const n=I(String(t??"")),r=Z(e).find(o=>{var a;const i=J(o.textContent||""),s=o.getAttribute("value")||((a=o.querySelector("input"))==null?void 0:a.value)||i;return I(String(s))===n||I(i)===n});r&&ve(r)}function kr(e){var n;const t=Z(e).find(r=>V(r));if(t)return t.getAttribute("value")||((n=t.querySelector("input"))==null?void 0:n.value)||J(t.textContent||"")}function _r(e){return Z(e).filter(t=>V(t)).map(t=>{var n;return t.getAttribute("value")||((n=t.querySelector("input"))==null?void 0:n.value)||J(t.textContent||"")})}function Z(e){const t=P(e);return t!=null&&t.optionSelector?Array.from(e.querySelectorAll(t.optionSelector)):[]}function Ar(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 ve(e){e.dispatchEvent(new MouseEvent("click",{bubbles:!0,cancelable:!0,view:window}))}function Cr(e){return typeof e=="boolean"?e:["true","1","是","开启","启用","yes","y"].includes(String(e??"").trim().toLowerCase())}function Tr(e){return Array.isArray(e)?e.map(String):String(e??"").split(/[,,;;、]/).map(t=>t.trim()).filter(Boolean)}function I(e){return J(e).toLowerCase()}function J(e){return e.replace(/\s+/g," ").trim()}const Ot="https://uat.kingdeefin.com";class Dt extends Error{constructor(n){super(n.message);f(this,"smartFillError");this.name="SmartFillException",this.smartFillError=n}}function S(e,t,n,r={}){return new Dt({code:e,message:t,stage:n,...r})}function qt(e,t,n="RECOGNIZE_FAILED"){return e instanceof Dt?e.smartFillError:{code:n,message:e instanceof Error?e.message:String(e||"智能录入异常"),stage:t,retryable:t==="recognize"}}function we(e="sf"){return`${e}_${Date.now().toString(36)}_${Math.random().toString(36).slice(2,10)}`}class Lr{constructor(t){f(this,"seToken","");f(this,"baseURL",Ot);this.config=t}setAccessToken(t){this.seToken=t}async createSession(){if(!/^seKey-[A-Za-z0-9_-]{6,}$/.test(this.config.apiKey))throw S("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:p,source:m,...re})=>re),userInputMsg:r||""})}),i=Mr(o,t.fields,t.scanToken);return console.log("suggestions",i),{scanToken:t.scanToken,suggestions:i,trace:o.trace||{traceId:we("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=Fr(r);if(!o)throw S("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",we("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 S(Or(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"?S("RECOGNIZE_TIMEOUT","识别请求超时,请稍后重试。","recognize",{retryable:!0}):s}finally{window.clearTimeout(o)}}}const Ir=.95;function Mr(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:Rr(s.confidence),source:s.source||"ai",warnings:s.warnings}})}function Rr(e){return typeof e!="number"||Number.isNaN(e)?Ir:e<0?0:e>1?1:e}function Fr(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 Or(e){return e===401?"TOKEN_EXPIRED":e===403?"API_KEY_FORBIDDEN":e===404?"FORM_CONFIG_NOT_FOUND":"RECOGNIZE_FAILED"}class ze{constructor(){f(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 Dr{constructor(){f(this,"instances",new Set);f(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 qr=[/^(el|rc|ant|radix|headlessui|mui|chakra)-/i,/[0-9a-f]{8,}/i,/\d{6,}/];function _(e){const t=String(e||"").trim();return!t||qr.some(n=>n.test(t))?"":t}function Q(e){const t=(e.options||[]).slice(0,20).map(n=>`${n.label}:${String(n.value)}`).join("|");return K([e.fieldId,e.tagName,e.type,_(e.name),_(e.id),e.label,e.placeholder,e.section,t].join("::"))}function K(e){return String(e??"").replace(/\s+/g," ").trim().toLowerCase()}const Pt="smart-fill-highlight-style",Pr=`
10
+ `,document.head.appendChild(e)}async function jn(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 D(120);for(const n of t.getTrackedDropdowns())n.isConnected&&(n.style.display="none",n.setAttribute("aria-hidden","true"))}function mt(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 vt(e){e.focus({preventScroll:!0});const t=e instanceof HTMLInputElement?e:e.querySelector("input");t instanceof HTMLElement&&t.focus({preventScroll:!0})}function wt(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 D(e){return new Promise(t=>window.setTimeout(t,e))}function Gn(){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 St(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}const Yn=/(维吾尔自治区|壮族自治区|回族自治区|特别行政区|自治区直辖县级行政区划|自治区|自治州|地区|盟|林区|街道|苏木|社区|省|市|区|县|旗|镇|乡)$/g,Wn=new Set(["市辖区","县","自治区直辖县级行政区划"]);let fe=null;function w(e){return String(e??"").replace(/\s+/g,"").replace(/[,,。.、/\\\-]/g,"").trim().toLowerCase()}function I(e){return w(e).replace(Yn,"")}function Pe(e){if(e==null)return"";if(typeof e=="string"||typeof e=="number")return String(e).trim();if(Array.isArray(e))return e.map(t=>Pe(t)).filter(Boolean).join("");if(typeof e=="object"){const t=[],n=new Set,r=i=>{const o=d(String(i??""));!o||n.has(o)||(n.add(o),t.push(o))};for(const i of["province","provinceName","prov","city","cityName","district","districtName","area","areaName","county","countyName","region","regionName","address","detail","detailAddress","fullAddress","label","text","value","name","answer"])r(e[i]);return t.join("")}return d(String(e))}function pe(e){const t=[],n=[],r=s=>{const a=d(String(s??""));a&&t.push(a)},i=s=>{const a=w(s);a&&(n.push(a),r(s))};if(Array.isArray(e))for(const s of e)i(s);else if(typeof e=="object"&&e){for(const s of["province","provinceName","prov","city","cityName","district","districtName","area","areaName","county","countyName","region","regionName"])i(e[s]);for(const s of["address","detail","detailAddress","fullAddress","label","value","text","name","answer"])r(e[s])}else r(e);const o=w(t.join(""));return{fullText:o,looseFullText:I(o),structuredParts:n}}function he(e,t){const n=w(e),r=w(t);if(!n||!r)return!1;if(n===r||n.includes(r)||r.includes(n))return!0;const i=I(n),o=I(r);return!i||!o?!1:i===o||i.includes(o)||o.includes(i)}function Ne(e,t=pe(e)){const n=tr();if(!n.length)return[];let r=null,i=0;for(const o of n){const s=Jn(o,t);s>i&&(i=s,r=o)}return i>=120?(r==null?void 0:r.labels)||[]:[]}function Et(e,t,n,r){let i=null,o=0;const s=Xn(t,n,r);for(const a of e){const c=a.querySelector(".el-cascader-node__label, .ant-cascader-menu-item-content, .n-cascader-node__label, .arco-cascader-option-label"),l=d((c==null?void 0:c.textContent)||a.textContent||""),u=w(l);if(!u)continue;const p=I(u);let h=Zn(u,p,s);!h&&t.fullText&&(t.fullText.includes(u)?h=100+u.length:u.includes(t.fullText)?h=70+t.fullText.length:t.looseFullText.includes(p)&&(h=80+p.length)),h>o&&(o=h,i=a)}return o>=75?i:null}function Xn(e,t,n){const r=[],i=new Set,o=(s,a)=>{const c=w(s);!c||i.has(c)||(i.add(c),r.push({normalized:c,stripped:I(c),score:a}))};if(t.length){t[n]&&o(t[n],260);for(let s=n+1;s<t.length;s+=1)o(t[s],215-(s-n)*15)}e.structuredParts[n]&&o(e.structuredParts[n],235);for(let s=0;s<e.structuredParts.length;s+=1)s!==n&&o(e.structuredParts[s],180-Math.abs(s-n)*20);return e.fullText&&o(e.fullText,130),r}function Zn(e,t,n){let r=0;for(const i of n){let o=0;i.normalized===e?o=i.score+80:i.stripped&&i.stripped===t?o=i.score+68:i.normalized.includes(e)?o=i.score+40+e.length:e.includes(i.normalized)?o=i.score+28+i.normalized.length:i.stripped&&t&&i.stripped.includes(t)?o=i.score+24+t.length:i.stripped&&t&&t.includes(i.stripped)&&(o=i.score+20+i.stripped.length),o>r&&(r=o)}return r}function Jn(e,t){let n=0,r=0;for(let i=0;i<e.aliasesByLevel.length;i+=1){const o=Qn(e.aliasesByLevel[i],t.structuredParts[i]||"",t.fullText,t.looseFullText,i);o>0?(r+=1,n+=o):t.structuredParts[i]&&(n-=30)}return n+=r*18+e.labels.length*4,t.structuredParts.length>e.labels.length&&(n-=(t.structuredParts.length-e.labels.length)*10),n}function Qn(e,t,n,r,i){const o=[60,95,135,160][i]||160;let s=0;for(const a of e){let c=0;const l=I(a);t&&(t===a?c=Math.max(c,o+130+a.length):t.includes(a)||a.includes(t)?c=Math.max(c,o+95+Math.min(a.length,t.length)):l&&I(t)===l&&(c=Math.max(c,o+80+l.length))),n&&(n.includes(a)?c=Math.max(c,o+50+a.length):l&&r.includes(l)&&(c=Math.max(c,o+35+l.length))),c>s&&(s=c)}return s}function er(e){const t=d(e),n=w(t);if(!n)return[];const r=new Set([n]),i=I(n);i&&!Wn.has(t)&&r.add(i);const o={内蒙古自治区:"内蒙古",广西壮族自治区:"广西",西藏自治区:"西藏",宁夏回族自治区:"宁夏",新疆维吾尔自治区:"新疆",香港特别行政区:"香港",澳门特别行政区:"澳门"};return o[t]&&r.add(o[t]),Array.from(r).filter(Boolean)}function tr(){if(fe)return fe;const e=globalThis.__SMART_FILL_ADDRESS_MAP__,t=e==null?void 0:e.data,n=Array.isArray(t)?t:Array.isArray(t==null?void 0:t.data)?t.data:[];return fe=nr(n),fe}function nr(e){const t=[],n=new Set,r=i=>{const o=i.map(a=>d(a)).filter(Boolean);if(!o.length)return;const s=o.join(">");n.has(s)||(n.add(s),t.push({labels:o,aliasesByLevel:o.map(a=>er(a))}))};for(const i of e)if(i!=null&&i.label&&(r([i.label]),!(!Array.isArray(i.children)||!i.children.length))){for(const o of i.children)if(o!=null&&o.label&&(r([i.label,o.label]),!(!Array.isArray(o.children)||!o.children.length)))for(const s of o.children)s!=null&&s.label&&r([i.label,o.label,s.label])}return t}function J(e,t){const n=ge(t);if(!n.length)return null;let r=null,i=0;for(const o of e){const s=M(o.value),a=M(o.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&&ye(s)===ye(c)||a&&ye(a)===ye(c))&&(l=80),l>i&&(i=l,r=o)}}return i>=80?r:null}function ge(e){if(Array.isArray(e))return e.flatMap(n=>ge(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=>M(r)).filter(Boolean)}const t=M(e);return t?[t]:[]}function M(e){return String(e??"").replace(/\s+/g,"").replace(/[::,,。.、()()\-_/]/g,"").trim().toLowerCase()}function ye(e){return M(e).replace(/(请选择|选择|状态|情况|类型|方式|所属|是否)$/g,"")}const be=[".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(", "),rr=[".el-cascader-panel .el-cascader-menu",".ant-cascader-menu",".van-cascader__options",".n-cascader-menu",".arco-cascader-list"].join(", "),ir=[".el-cascader-node",".ant-cascader-menu-item",".van-cascader__option",".n-cascader-node",".arco-cascader-option"].join(", "),or=".van-picker__confirm, .van-picker__toolbar .van-picker__confirm";async function sr(e,t,n,r){const i=_t(t,r);return e instanceof HTMLSelectElement?ar(e,i):L(e)||n==="cascader"?cr(e,i):(W(e)||_(e)||n==="select"||n==="date",kt(e,i))}function xt(e){if(e instanceof HTMLSelectElement){const n=e.options[e.selectedIndex];return d((n==null?void 0:n.textContent)||e.value)}if(L(e)){const n=e.querySelector("input");if(n!=null&&n.value)return d(n.value);const r=e.querySelector(".el-cascader__tags-text, .el-cascader__label");return d((r==null?void 0:r.textContent)||"")}if(W(e)||_(e))return Ln(e);const t=e.querySelector("input, textarea");return d((t==null?void 0:t.value)||e.textContent||"")}async function ar(e,t){const n=Array.from(e.options).map(i=>({source:i,value:i.value,label:i.textContent})),r=J(n,t.searchValue);if((r==null?void 0:r.source)instanceof HTMLOptionElement){if(r.source.disabled)throw It(e),new Error("下拉目标选项已禁用");N(e,r.source.value),E(e);return}if(!me(e,t))throw new Error("原生下拉框中没有匹配到对应选项")}async function kt(e,t){const n=X(e)||e;if($e(n,t.searchValue))return;const r=new Set(te());try{if(!await lr(n)){if(me(n,t))return;throw new Error("自定义下拉框未能成功展开")}const o=await vr(n,r),s=await At(t.searchValue,o,!0,!0);if(s!=null&&s.source&&U(s.source))throw await ee(n),await yr(n),new Error("下拉目标选项已禁用");const a=await dr(t.searchValue,o,!0);if(!(a!=null&&a.source)){if(await ee(n),me(n,t))return;throw new Error("自定义下拉框展开后未找到匹配选项")}if(R(a.source),await b(120),Sr(),E(n),await b(120),$e(n,t.searchValue)||me(n,t)&&$e(n,t.searchValue))return;throw new Error("自定义下拉框点击选项后未成功回填")}finally{await ee(n),await b(80)}}async function cr(e,t){const n=e.closest(".el-cascader, .ant-cascader, .van-cascader, .n-cascader, .arco-cascader")||e;if(Ot(n,t.searchValue))return;ve(n)&&(await Lt(n),await b(120));let r="级联选择框匹配失败";try{if(await ur(n)){const o=await hr(t.searchValue);if(await b(180),await ee(n),await b(120),o&&Ot(n,t.searchValue)){E(n);return}}}catch(i){i instanceof Error&&i.message&&(r=i.message)}finally{await ee(n),await b(80)}throw await Lt(n),new Error(r)}function _t(e,t){var s;const n=(s=t==null?void 0:t.options)!=null&&s.length?J(t.options.map(a=>({value:String(a.value),label:a.label})),e):null,r=j(e),i=d(String((n==null?void 0:n.label)??r??"")),o=d(String((n==null?void 0:n.value)??(n==null?void 0:n.label)??r??""));return{searchValue:n?[e,n.label,n.value]:e,fillValue:o,displayValue:i}}async function lr(e){const t=He(e);for(const n of t)if(Dt(n),R(n),await b(160),Ft(e)||(Pt(n),await b(180),Ft(e)))return!0;return!1}async function ur(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(n.scrollIntoView({block:"nearest",inline:"nearest"}),Dt(n),R(n),await b(180),Q().length||(Pt(n),await b(180),Q().length))return!0;return!1}async function dr(e,t,n=!1){return At(e,t,n,!1)}async function At(e,t,n=!1,r=!1){for(let i=0;i<12;i+=1){const o=J(Rt(t,n,r).map(s=>({source:s,value:fr(s),label:pr(s)})),e);if(o)return o;await b(100)}return null}function fr(e){return e.getAttribute("data-value")||e.getAttribute("data-name")||e.getAttribute("value")||e.getAttribute("name")||e.textContent||""}function pr(e){var t;return d(((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 hr(e){const t=pe(e),n=Ne(e,t),r=qt(e),i=Math.max(n.length,r.length,1);if(!t.fullText&&!t.structuredParts.length&&!r.length)return!1;for(let o=0;o<i;o+=1){const s=Q();if(!s.length)return o>0;const a=s[Math.min(o,s.length-1)],c=Array.from(a.querySelectorAll(ir)),l=c.filter(h=>!U(h));let u=null;if(n.length||t.structuredParts.length){const h=c.filter(m=>U(m));h.length&&(u=Et(h,t,n,o))}if(!l.length){if(u)throw new Error("级联目标选项已禁用");return!1}let p=null;if((n.length||t.structuredParts.length)&&(p=Et(l,t,n,o)),!p&&!u&&r[o]){const h=J(c.filter(m=>U(m)).map(m=>{var A;return{source:m,value:m.getAttribute("data-value")||m.textContent,label:((A=m.querySelector(".el-cascader-node__label"))==null?void 0:A.textContent)||m.textContent}}),r[o]);u=(h==null?void 0:h.source)instanceof HTMLElement?h.source:null}if(!p&&u)throw new Error("级联目标选项已禁用");if(!p&&r[o]){const h=J(l.map(m=>{var A;return{source:m,value:m.getAttribute("data-value")||m.textContent,label:((A=m.querySelector(".el-cascader-node__label"))==null?void 0:A.textContent)||m.textContent}}),r[o]);p=(h==null?void 0:h.source)instanceof HTMLElement?h.source:null}if(!p)return!1;if(R(p),await b(220),!Q().length)return!0}return!Q().length||!0}function me(e,t){const n=mr(t)?t:_t(t),r=n.displayValue||j(t),i=n.fillValue||r;if(!r&&!i)return!1;const o=X(e)||e;if(_(o))return br(o,r,i);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=i,l.textContent=r||i,l.selected=!0,N(e,i),E(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(),N(s,r),s.dispatchEvent(new InputEvent("input",{bubbles:!0,composed:!0,data:r,inputType:"insertReplacementText"})),s.dispatchEvent(new Event("change",{bubbles:!0,composed:!0})),E(s),E(e),s.blur(),!0}catch{return!1}finally{a&&(s.readOnly=!0,c&&s.setAttribute("readonly",""))}}function gr(e){const t=pe(e),n=Ne(e,t);if(n.length)return n.join(" / ");const r=qt(e);return r.length?r.join(" / "):Pe(e)}function Ct(e){const t=e.querySelector("input");return t instanceof HTMLInputElement?t:null}function Tt(e){const t=Ct(e);if(t!=null&&t.value)return d(t.value);const n=e.querySelector(".el-cascader__tags-text, .el-cascader__label");return d((n==null?void 0:n.textContent)||"")}function ve(e){return!!w(Tt(e))}async function Lt(e){if(!ve(e))return;const t=e.querySelector(".el-input__wrapper, .el-input, .ant-select-selector");t&&(t.dispatchEvent(new MouseEvent("mouseenter",{bubbles:!0})),t.dispatchEvent(new MouseEvent("mouseover",{bubbles:!0})),await b(80));const n=e.querySelector(".el-input__clear, .el-icon-circle-close, .ant-select-clear, .ant-cascader-picker-clear, .van-icon-clear");if(n&&(R(n),await b(180),!ve(e)))return;const r=Ct(e);if(r&&!r.disabled){const o=r.readOnly,s=r.hasAttribute("readonly");try{o&&(r.readOnly=!1,r.removeAttribute("readonly")),N(r,""),r.dispatchEvent(new InputEvent("input",{bubbles:!0,composed:!0,inputType:"deleteContentBackward"})),r.dispatchEvent(new Event("change",{bubbles:!0,composed:!0})),E(r)}finally{o&&(r.readOnly=!0,s&&r.setAttribute("readonly",""))}await b(120)}const i=e.querySelector(".el-tag__close, .el-cascader__tags .el-icon-close");i&&ve(e)&&(R(i),await b(120))}async function yr(e){if(e instanceof HTMLSelectElement){It(e);return}if(_(e)){Mt(e);return}const t=e.querySelector(".el-input__wrapper, .el-input, .ant-select-selector, .ant-picker, .n-base-selection, .arco-select-view, .semi-select-selection");t&&(t.dispatchEvent(new MouseEvent("mouseenter",{bubbles:!0})),t.dispatchEvent(new MouseEvent("mouseover",{bubbles:!0})),await b(80));const n=e.querySelector(".el-input__clear, .el-icon-circle-close, .ant-select-clear, .ant-picker-clear, .ant-cascader-picker-clear, .n-base-clear, .van-icon-clear");n&&(R(n),await b(180));const r=e.querySelector('input:not([type="hidden"])');r&&!r.disabled&&P(r,"");for(const i of e.querySelectorAll('input[type="hidden"]'))P(i,"");E(e)}function It(e){const t=Array.from(e.options).find(n=>n.value==="");t?N(e,t.value):(e.selectedIndex=-1,N(e,"")),E(e)}function br(e,t,n){Mt(e);const r=e.querySelector(".van-field__control"),i=Array.from(e.querySelectorAll('input[type="hidden"]')),o=Array.from(e.querySelectorAll('input:not([type="hidden"])'));r instanceof HTMLInputElement?P(r,t||n):r instanceof HTMLElement&&(r.textContent=t||n);for(const s of i)P(s,n);for(const s of o)r!==s&&P(s,t||n);return E(e),!0}function Mt(e){const t=e.querySelector(".van-field__control");t instanceof HTMLInputElement?P(t,""):t instanceof HTMLElement&&(t.textContent="");for(const n of e.querySelectorAll("input"))P(n,"")}function P(e,t){if(e.disabled)return;const n=e.readOnly,r=e.hasAttribute("readonly");try{n&&(e.readOnly=!1,e.removeAttribute("readonly")),N(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})),E(e)}finally{n&&(e.readOnly=!0,r&&e.setAttribute("readonly",""))}}function mr(e){return typeof e=="object"&&e!=null&&"searchValue"in e&&"fillValue"in e&&"displayValue"in e}function He(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,i)=>i.indexOf(n)===r)}function Rt(e,t,n=!1){return(e.length?e:te()).flatMap(o=>o.matches(be)?[o]:Array.from(o.querySelectorAll(be))).filter((o,s,a)=>a.indexOf(o)===s).filter(o=>n?t?!0:H(o):(t||H(o))&&!U(o))}function Q(){return Array.from(document.querySelectorAll(rr)).filter(H)}async function vr(e,t){for(let n=0;n<10;n+=1){const r=wr(e,t);if(r.length)return r;await b(80)}return te().filter(H)}function wr(e,t){const n=te(),r=n.filter(o=>!t.has(o));if(r.length)return r.sort((o,s)=>we(s)-we(o));const i=new Set(He(e).flatMap(o=>[o.getAttribute("aria-controls"),o.getAttribute("aria-owns")]).filter(o=>!!o));if(i.size){const o=n.filter(s=>i.has(s.id));if(o.length)return o}return n.filter(o=>H(o)&&(o.querySelector(be)||o.matches(be))).sort((o,s)=>we(s)-we(o)).slice(0,1)}function Ft(e){return Rt(te().filter(H),!1).length>0?!0:He(e).some(t=>t.getAttribute("aria-expanded")==="true"||t.classList.contains("is-focus")||t.classList.contains("is-focused"))}function Ot(e,t){const n=Tt(e),r=w(n);if(!r)return!1;const i=Pe(t),o=w(i);if(he(r,o))return!0;const s=pe(t),a=Ne(t,s),c=w(a.join(""));if(he(r,c))return!0;const l=w(gr(t));if(he(r,l))return!0;const u=w(s.structuredParts.join(""));return he(r,u)}function $e(e,t){const n=M(xt(e));if(!n)return!1;const r=ge(t);if(!r.length){const i=M(j(t));return i?n===i||n.includes(i)||i.includes(n):!1}return r.some(i=>{const o=M(i);return!!o&&(n===o||n.includes(o)||o.includes(n))})}function U(e){return e instanceof HTMLOptionElement?e.disabled:e.classList.contains("is-disabled")||e.classList.contains("ant-select-item-option-disabled")||e.classList.contains("van-cascader__option--disabled")||e.classList.contains("n-cascader-node--disabled")||e.classList.contains("arco-cascader-option-disabled")||e.classList.contains("arco-select-option-disabled")||e.getAttribute("aria-disabled")==="true"}function Sr(){const e=document.querySelector(or);e&&H(e)&&R(e)}async function ee(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 te(){return Array.from(document.querySelectorAll(Er()))}function we(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 Er(){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 j(e){if(e==null)return"";if(typeof e=="string"||typeof e=="number"||typeof e=="boolean")return d(String(e));if(Array.isArray(e))return e.map(t=>j(t)).filter(Boolean).join(" ");if(typeof e=="object"){const t=e;for(const n of["label","text","value","answer","name"]){const r=j(t[n]);if(r)return r}}return d(String(e))}function qt(e){const t=j(e);if(!t)return[];if(t.includes("/")||t.includes("、"))return t.split(/[//、]/).map(r=>r.trim()).filter(Boolean);const n=ge(e);return n.length?[d(n[0])]:[t]}function N(e,t){var i;const n=Object.getPrototypeOf(e),r=Object.getOwnPropertyDescriptor(n,"value");(i=r==null?void 0:r.set)==null||i.call(e,t)}function E(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 R(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 Dt(e){e.focus({preventScroll:!0});const t=e instanceof HTMLInputElement?e:e.querySelector("input");t instanceof HTMLElement&&t.focus({preventScroll:!0})}function Pt(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 Nt=new Set(["select","cascader","date"]),ze={name:"ui-framework",match:e=>e.matches(nt)||it(e)||!kr(e)&&qe(e),getValue:e=>{var i,o;const t=e.element;if(!t)return;const n=K(t);if((n==null?void 0:n.kind)==="switch")return Y(t);if((n==null?void 0:n.kind)==="radioGroup")return Tr(t);if((n==null?void 0:n.kind)==="checkboxGroup")return Lr(t);const r=e.type||ce(t)||(n==null?void 0:n.type);return r&&Nt.has(r)?xt(t):n?((o=V(t))==null?void 0:o.value)||t.textContent||void 0:(i=V(t))==null?void 0:i.value},setValue:async(e,t)=>{const n=e.element;if(!n)return;const r=K(n);if((r==null?void 0:r.kind)==="switch"){_r(n,t);return}if((r==null?void 0:r.kind)==="radioGroup"){Cr(n,t);return}if((r==null?void 0:r.kind)==="checkboxGroup"){Ar(n,t);return}const i=e.type||ce(n)||(r==null?void 0:r.type);if(i&&Nt.has(i)||qe(n,i||void 0)){await sr(n,t,i||"select",e);return}const o=V(n);if(o){Ir(o,t);return}n.dispatchEvent(new Event("change",{bubbles:!0}))}},xr=ze;function kr(e){return e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement||e instanceof HTMLSelectElement}function _r(e,t){Y(e)!==Mr(t)&&Se(e)}function Ar(e,t){var i;const n=new Set(Rr(t).map(F)),r=ot(e)||[];for(const o of ne(e)){const s=re(o.textContent||""),a=o.getAttribute("value")||((i=o.querySelector("input"))==null?void 0:i.value)||s,c=Y(o),l=n.has(F(String(a)))||n.has(F(s));c!==l&&Se(o)}if(!ne(e).length&&r.length)for(const o of r)(n.has(F(String(o.value)))||n.has(F(o.label)))&&Se(e)}function Cr(e,t){const n=F(String(t??"")),r=ne(e).find(i=>{var a;const o=re(i.textContent||""),s=i.getAttribute("value")||((a=i.querySelector("input"))==null?void 0:a.value)||o;return F(String(s))===n||F(o)===n});r&&Se(r)}function Tr(e){var n;const t=ne(e).find(r=>Y(r));if(t)return t.getAttribute("value")||((n=t.querySelector("input"))==null?void 0:n.value)||re(t.textContent||"")}function Lr(e){return ne(e).filter(t=>Y(t)).map(t=>{var n;return t.getAttribute("value")||((n=t.querySelector("input"))==null?void 0:n.value)||re(t.textContent||"")})}function ne(e){const t=K(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 Se(e){e.dispatchEvent(new MouseEvent("click",{bubbles:!0,cancelable:!0,view:window}))}function Mr(e){return typeof e=="boolean"?e:["true","1","是","开启","启用","yes","y"].includes(String(e??"").trim().toLowerCase())}function Rr(e){return Array.isArray(e)?e.map(String):String(e??"").split(/[,,;;、]/).map(t=>t.trim()).filter(Boolean)}function F(e){return re(e).toLowerCase()}function re(e){return e.replace(/\s+/g," ").trim()}const Ht="https://uat.kingdeefin.com";class $t extends Error{constructor(n){super(n.message);f(this,"smartFillError");this.name="SmartFillException",this.smartFillError=n}}function x(e,t,n,r={}){return new $t({code:e,message:t,stage:n,...r})}function zt(e,t,n="RECOGNIZE_FAILED"){return e instanceof $t?e.smartFillError:{code:n,message:e instanceof Error?e.message:String(e||"智能录入异常"),stage:t,retryable:t==="recognize"}}function Ee(e="sf"){return`${e}_${Date.now().toString(36)}_${Math.random().toString(36).slice(2,10)}`}class Fr{constructor(t){f(this,"seToken","");f(this,"baseURL",Ht);this.config=t}setAccessToken(t){this.seToken=t}async createSession(){if(!/^seKey-[A-Za-z0-9_-]{6,}$/.test(this.config.apiKey))throw x("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 o,s,a,c;const n=(o=t.images)!=null&&o.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 i=await this.recognizeImages(n);return(c=t.onStatusChange)==null||c.call(t,"image_recognizing"),{text:i,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 i=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:p,source:h,...m})=>m),userInputMsg:r||""})}),o=qr(i,t.fields,t.scanToken);return console.log("suggestions",o),{scanToken:t.scanToken,suggestions:o,trace:i.trace||{traceId:Ee("trace"),usedOcr:!!t.usedOcr,usedAi:!0,durationMs:Math.round(performance.now()-n)}}}async recognizeImages(t){const n=new FormData;t.forEach(o=>{n.append("image",o,o.name)});const r=await this.request("/fcloud/flow-product/agentChat/smartEntry/ocr",{method:"POST",body:n}),i=Pr(r);if(!i)throw x("RECOGNIZE_FAILED","图片识别未提取到文本内容。","recognize");return i}async request(t,n){const r=new AbortController,i=window.setTimeout(()=>r.abort(),this.config.requestTimeoutMs??3e4),o=new Headers(n.headers);n.body&&!(n.body instanceof FormData)&&!o.has("Content-Type")&&o.set("Content-Type","application/json"),o.set("x-trace-id",Ee("trace")),this.seToken&&o.set("seToken",`${this.seToken}`);try{const s=await fetch(`${this.baseURL}${t}`,{...n,headers:o,signal:r.signal});if(!s.ok)throw x(Nr(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"?x("RECOGNIZE_TIMEOUT","识别请求超时,请稍后重试。","recognize",{retryable:!0}):s}finally{window.clearTimeout(i)}}}const Or=.95;function qr(e,t,n){var o;const r=new Map(t.map(s=>[s.fieldId,s]));return(((o=e.data)==null?void 0:o.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)?Or: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 Nr(e){return e===401?"TOKEN_EXPIRED":e===403?"API_KEY_FORBIDDEN":e===404?"FORM_CONFIG_NOT_FOUND":"RECOGNIZE_FAILED"}class Ke{constructor(){f(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(i=>i(n))}clear(){this.handlers.clear()}}class Hr{constructor(){f(this,"instances",new Set);f(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 $r=[/^(el|rc|ant|radix|headlessui|mui|chakra)-/i,/[0-9a-f]{8,}/i,/\d{6,}/];function C(e){const t=String(e||"").trim();return!t||$r.some(n=>n.test(t))?"":t}function ie(e){const t=(e.options||[]).slice(0,20).map(n=>`${n.label}:${String(n.value)}`).join("|");return G([e.fieldId,e.tagName,e.type,C(e.name),C(e.id),e.label,e.placeholder,e.section,t].join("::"))}function G(e){return String(e??"").replace(/\s+/g," ").trim().toLowerCase()}const Kt="smart-fill-highlight-style",zr=`
11
11
  [data-smart-fill-highlighted="true"] {
12
12
  background: #eaf3ff !important;
13
13
  box-shadow: 0 0 0 1px #91caff inset !important;
@@ -34,8 +34,8 @@
34
34
  background: #eaf3ff !important;
35
35
  box-shadow: 0 0 0 1px #91caff inset !important;
36
36
  }
37
- `.trim();function Hr(){if(typeof document>"u"||document.getElementById(Pt))return;const e=document.createElement("style");e.id=Pt,e.textContent=Pr,document.head.appendChild(e)}const Ke=new WeakMap,Nr=['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 Ve{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(Ee(o.fieldId,"",o.value,"字段不在当前扫描结果中","FIELD_NOT_FOUND"));continue}if(i.scanToken!==t.scanToken){r.push(Ee(i.fieldId,i.label,o.value,"页面扫描已过期,请重新扫描","SCAN_TOKEN_EXPIRED"));continue}const s=Ur(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(Ee(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(Ee(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=Se(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=Se(t,r);s&&Be(s,t);return}const o=Se(t,r);if(!o)throw new Error("页面中未找到对应字段");if(t.fingerprint&&t.fingerprint!==Q({...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),Be(o,t);return}zr(o,n),Be(o,t)}matchAdapter(t,n){const r=Se(t,n);return r?this.adapters.find(o=>o.match(r,t)):void 0}}function Se(e,t){var r;if((r=e.element)!=null&&r.isConnected)return e.element;const n=$r(t==null?void 0:t.element);return n||document.querySelector(`[data-smart-fill-id="${Ue(e.fieldId)}"]`)}function $r(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 zr(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="${Ue(e.name)}"][value="${Ue(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 Be(e,t){Hr();const n=Kr(e,t),r=()=>{for(const o of n)o.isConnected&&Vr(o)};typeof requestAnimationFrame=="function"?requestAnimationFrame(()=>requestAnimationFrame(r)):r()}function Kr(e,t){if(e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement||e instanceof HTMLSelectElement)return[e];const n=Oe(e,t==null?void 0:t.type)&&U(e)||e,r=Br(Array.from(n.querySelectorAll(Nr)).filter(Ht));if(r.length)return r;const o=H(n);return o&&Ht(o)?[o]:[n]}function Vr(e){var r;e.setAttribute("data-smart-fill-highlighted","true"),(r=Ke.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(),Ke.delete(e))};Ke.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 Br(e){return e.filter(t=>!e.some(n=>n!==t&&n.contains(t)))}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 Ee(e,t,n,r,o){return{fieldId:e,label:t,attemptedValue:n,reason:r,reasonCode:o}}function Ue(e){return typeof CSS<"u"&&CSS.escape?CSS.escape(e):e.replace(/["\\]/g,"\\$&")}function Ur(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 jr=[{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:"日期格式命中"}],D={mobile:["手机","手机号","电话","联系电话","mobile","phone","法人手机号","法人电话","法定代表人手机号","法人手机","紧急联系人手机号","紧急联系人电话","紧急联系电话","联系人手机号","联系人电话","联系手机","配偶手机号","配偶电话","爱人手机号"],idCard:["身份证","证件号","身份证号","idcard","id card","法人身份证","法人身份证号","法定代表人身份证号","配偶身份证","配偶身份证号","爱人身份证号"],email:["邮箱","邮件","email","mail","联系人邮箱","联系邮箱","contact email"],bankCard:["银行卡","卡号","bank","bank card"],amount:["金额","费用","价格","合计","总计","amount","price","申请金额","贷款金额","借款金额","授信金额","申请额度"],date:["日期","时间","有效期","date","申请日期","申请时间","受理日期","进件日期"]},Nt={mobile:"mobile",idCard:"idCard",email:"email",bankCard:"bankCard",amount:"amount",date:"date"};class $t{recognize(t,n,r){const o=to([...Gr(t),...Yr(t)]),i=new Set,s=[];for(const a of o.sort((c,l)=>l.confidence-c.confidence)){const c=Xr(a,n,i);c&&(s.push({fieldId:c.fieldId,scanToken:r,label:c.label,value:Jr(a.value,c),displayValue:a.value,confidence:a.confidence,source:"local_rule",reason:a.reason}),i.add(c.fieldId))}return s}}function Gr(e){const t=[];for(const n of jr)for(const r of e.matchAll(n.pattern)){const o=zt(r[1]||r[0]);t.push({key:n.key,value:o,confidence:n.confidence,reason:n.reason,baseKey:Nt[n.key]})}return t}function Yr(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=eo(o[1]),s=zt(o[2]);if(!(!i||!s))for(const a of Wr(i,s))t.push(a)}return t}function Wr(e,t){const n=K(e),r=Qr(t),o=[];return(M(n,D.mobile)||r==="mobile")&&o.push("mobile"),(M(n,D.idCard)||r==="idCard")&&o.push("idCard"),(M(n,D.email)||r==="email")&&o.push("email"),(M(n,D.bankCard)||r==="bankCard")&&o.push("bankCard"),(M(n,D.amount)||r==="amount")&&o.push("amount"),(M(n,D.date)||r==="date")&&o.push("date"),no(o).map((i,s)=>({key:i,value:t,confidence:Math.max(.84,.96-s*.04),reason:`键值对文本命中(${e})`,baseKey:Nt[i]}))}function Xr(e,t,n){let r=null;for(const o of t){if(n.has(o.fieldId))continue;const i=Zr(e,o);i>((r==null?void 0:r.score)??0)&&(r={field:o,score:i})}return r&&r.score>=.45?r.field:null}function Zr(e,t){const n=K([t.fieldId,t.label,t.placeholder,t.name,t.id,t.section].join(" ")),r=D[e.key]||[e.key];let o=0;return M(n,r)?o+=.95:M(n,[e.key])&&(o+=.82),n.includes(K(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 Jr(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 Qr(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 eo(e){return e.replace(/[“”"'`]/g,"").replace(/\s+/g," ").trim()}function zt(e){return e.replace(/[,。;;]+$/g,"").replace(/^[“”"'`\s]+|[“”"'`\s]+$/g,"").trim()}function M(e,t){const n=K(e);return t.some(r=>n.includes(K(r)))}function to(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 no(e){return[...new Set(e)]}const Kt=["input","textarea","select","[contenteditable]:not([contenteditable='false'])"].join(", "),ro=new Set(["hidden","submit","button","image","reset","file","password"]);class Vt{constructor(t=document){this.root=t}scan(t={}){var l;const n=we("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,p)=>this.fromElement(u,p,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)&&!se(s);if(!s.element||a||s.type!=="select"&&s.type!=="cascader"){r.push(s);continue}const c=await _n(s.element),l=c!=null&&c.length&&!se({...s,options:c})?c:void 0;if(!(l!=null&&l.length)){r.push({...s,options:se(s)?void 0:s.options});continue}const u={...s,options:l};u.fingerprint=Q({...u,tagName:s.element.tagName.toLowerCase()}),r.push(u)}return{...n,fields:r}}fromSchema(t,n){const r=ho(t.element,this.root),o=r?Fe(r)||Le(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=Q({...i,tagName:o==null?void 0:o.tagName.toLowerCase()}),i}fromElement(t,n,r,o=this.root){const i=oo(t,n),s=ao(t,o),a={fieldId:i,fingerprint:"",scanToken:r,type:io(t),localRuleMode:"inherit",label:Bt(t),placeholder:jt(t),name:_(it(t))||void 0,id:_(t.id)||void 0,section:so(t),options:s,required:uo(t),readonly:lo(t),disabled:Ge(t),source:"form_scan",element:t};return se(a)&&(a.options=void 0),a.fingerprint=Q({...a,tagName:t.tagName.toLowerCase()}),a}resolveRoot(t){if(t){const n=Gt(this.root,t);if(n)return n}return this.root}collectVisibleFields(t){const n=new Set,r=[Kt,at,tt,".van-field"].join(", ");for(const s of t.querySelectorAll(r)){if(!(s instanceof HTMLElement))continue;const a=Fe(s)||Le(s);!a||!je(a)||Ge(a)||n.add(a)}const o=[...n],i=Array.from(t.querySelectorAll(Kt)).filter(s=>!(s instanceof HTMLElement)||!je(s)||fo(s)||s instanceof HTMLInputElement&&ro.has((s.type||"").toLowerCase())?!1:!Ge(s)&&!s.hasAttribute("readonly"));return po([...i,...o])}detectTopLayerContainer(t){const n=document.activeElement instanceof HTMLElement?document.activeElement:null,r=n==null?void 0:n.closest(nt);if(r instanceof HTMLElement&&t.some(i=>r.contains(i)))return r;const o=t.map(i=>i.closest(nt)).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 oo(e,t){const n=e.getAttribute("data-smart-fill-id");if(n)return n;const o=_(e.getAttribute("name"))||_(e.getAttribute("data-smart-fill-key"))||_(it(e))||_(e.id)||_(Bt(e))||`smart-fill-${Date.now()}-${t}`;return e.setAttribute("data-smart-fill-id",o),o}function io(e){const t=ut(e);if(t)return t;const n=oe(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 Bt(e){const t=e.getAttribute("aria-label");if(t)return t.trim();if(e.id){const i=document.querySelector(`label[for="${Ye(e.id)}"]`);if(i!=null&&i.textContent)return d(i.textContent)}const n=e.closest(yn),r=n==null?void 0:n.querySelector(mn);if(r!=null&&r.textContent)return d(r.textContent);const o=e.closest("label");if(o){const i=Ut(o,e);if(i)return i}return jt(e)||e.getAttribute("name")||e.id||"未命名字段"}function Ut(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=d(n.textContent||"");if(r)return t instanceof HTMLInputElement&&t.value&&r.includes(t.value)?d(r.replace(t.value,""))||void 0:r}function jt(e){var t;return e.getAttribute("placeholder")||e.getAttribute("aria-placeholder")||((t=e.querySelector("[placeholder]"))==null?void 0:t.getAttribute("placeholder"))||void 0}function so(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?d(n.textContent):void 0}function ao(e,t=document){const n=dt(e);if(n!=null&&n.length)return n;const r=ot(e);if(r!=null&&r.length)return r;if(e instanceof HTMLSelectElement)return Array.from(e.options).map(o=>({label:d(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="${Ye(e.name)}"]`)).filter(o=>o.type===e.type&&je(o)).map(o=>({label:co(o),value:o.value||!0}))}function co(e){if(e.id){const n=document.querySelector(`label[for="${Ye(e.id)}"]`);if(n!=null&&n.textContent)return d(n.textContent)}const t=e.closest("label");if(t){const n=Ut(t,e);if(n)return n}return d(e.getAttribute("aria-label")||e.value||"")}function je(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 Ge(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"||gn.some(t=>e.classList.contains(t))}function lo(e){return e.hasAttribute("readonly")||!!e.querySelector("[readonly]")}function uo(e){return e.hasAttribute("required")||e.getAttribute("aria-required")==="true"||!!e.querySelector('[required], [aria-required="true"]')}function fo(e){return Fe(e)!=null||Le(e)!=null}function po(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 ho(e,t){return e instanceof HTMLElement?e:typeof e=="string"?Gt(t,e):null}function Gt(e,t){try{const n=e.querySelector(t);return n instanceof HTMLElement?n:null}catch{return null}}function Ye(e){return typeof CSS<"u"&&CSS.escape?CSS.escape(e):e.replace(/["\\]/g,"\\$&")}const We=5,go=10*1024*1024,yo=50*1024*1024;class mo{constructor(t){f(this,"host",null);f(this,"root",null);f(this,"autoApplyState",null);f(this,"selectedFiles",[]);f(this,"inputText","");f(this,"localPriorityEnabled");f(this,"isOpen",!1);f(this,"dragState",null);f(this,"suppressOpenClick",!1);f(this,"isUploadHovering",!1);f(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=xe(this.dragState.startLeft+n,8,i),c=xe(this.dragState.startTop+r,8,s);this.host.style.left=`${a}px`,this.host.style.top=`${c}px`});f(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))});f(this,"handleDocumentPaste",t=>{const n=vo(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>${wo}</style>
37
+ `.trim();function Kr(){if(typeof document>"u"||document.getElementById(Kt))return;const e=document.createElement("style");e.id=Kt,e.textContent=zr,document.head.appendChild(e)}const Ve=new WeakMap,Vr=['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 Be{constructor(t,n,r=[]){this.fields=t,this.schemas=n,this.adapters=r}async apply(t){const n=[],r=[];for(const i of t.values){const o=this.fields.find(l=>l.fieldId===i.fieldId);if(!o){r.push(ke(i.fieldId,"",i.value,"字段不在当前扫描结果中","FIELD_NOT_FOUND"));continue}if(o.scanToken!==t.scanToken){r.push(ke(o.fieldId,o.label,i.value,"页面扫描已过期,请重新扫描","SCAN_TOKEN_EXPIRED"));continue}const s=Wr(this.schemas,i.fieldId),a=s!=null&&s.transform?s.transform(i.value):i.value,c=await this.getValue(o,s);try{const l=s!=null&&s.validate?await s.validate(a):!0;if(l!==!0){r.push(ke(o.fieldId,o.label,a,typeof l=="string"?l:"字段校验未通过","VALIDATE_FAILED"));continue}await this.setValue(o,a,s),n.push({fieldId:o.fieldId,label:o.label,value:a,previousValue:c})}catch(l){r.push(ke(o.fieldId,o.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 i=xe(t,n);if(i)return i instanceof HTMLInputElement&&i.type==="checkbox"?i.checked:i instanceof HTMLInputElement&&i.type==="radio"?i.checked?i.value:void 0:i instanceof HTMLInputElement||i instanceof HTMLTextAreaElement||i instanceof HTMLSelectElement?i.value:i.textContent}async setValue(t,n,r){if(r!=null&&r.setValue){await r.setValue(n);const s=xe(t,r);s&&Ue(s,t);return}const i=xe(t,r);if(!i)throw new Error("页面中未找到对应字段");if(t.fingerprint&&t.fingerprint!==ie({...t,tagName:i.tagName.toLowerCase()}))throw new Error("字段结构已变化,请重新扫描");const o=this.matchAdapter(t,r);if(t.disabled||i.hasAttribute("disabled")||i.getAttribute("aria-disabled")==="true")throw new Error("字段不可编辑");if(t.readonly||i.hasAttribute("readonly"))throw new Error("字段不可编辑");if(o){await o.setValue(t,n),Ue(i,t);return}Ur(i,n),Ue(i,t)}matchAdapter(t,n){const r=xe(t,n);return r?this.adapters.find(i=>i.match(r,t)):void 0}}function xe(e,t){var r;if((r=e.element)!=null&&r.isConnected)return e.element;const n=Br(t==null?void 0:t.element);return n||document.querySelector(`[data-smart-fill-id="${je(e.fieldId)}"]`)}function Br(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 Ur(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="${je(e.name)}"][value="${je(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 Ue(e,t){Kr();const n=jr(e,t),r=()=>{for(const i of n)i.isConnected&&Gr(i)};typeof requestAnimationFrame=="function"?requestAnimationFrame(()=>requestAnimationFrame(r)):r()}function jr(e,t){if(e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement||e instanceof HTMLSelectElement)return[e];const n=qe(e,t==null?void 0:t.type)&&X(e)||e,r=Yr(Array.from(n.querySelectorAll(Vr)).filter(Vt));if(r.length)return r;const i=V(n);return i&&Vt(i)?[i]:[n]}function Gr(e){var r;e.setAttribute("data-smart-fill-highlighted","true"),(r=Ve.get(e))==null||r.abort();const t=new AbortController,n=i=>{i&&"isTrusted"in i&&!i.isTrusted||(e.removeAttribute("data-smart-fill-highlighted"),t.abort(),Ve.delete(e))};Ve.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 Yr(e){return e.filter(t=>!e.some(n=>n!==t&&n.contains(t)))}function Vt(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 ke(e,t,n,r,i){return{fieldId:e,label:t,attemptedValue:n,reason:r,reasonCode:i}}function je(e){return typeof CSS<"u"&&CSS.escape?CSS.escape(e):e.replace(/["\\]/g,"\\$&")}function Wr(e,t){const n=e.find(i=>i.fieldId===t);if(n)return n;const r=t.includes(":")?t.slice(t.lastIndexOf(":")+1):"";if(r)return e.find(i=>i.rowKey!=null&&String(i.rowKey)===r&&`${i.fieldId}:${i.rowKey}`===t)}const Xr=[{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:"日期格式命中"}],$={mobile:["手机","手机号","电话","联系电话","mobile","phone","法人手机号","法人电话","法定代表人手机号","法人手机","紧急联系人手机号","紧急联系人电话","紧急联系电话","联系人手机号","联系人电话","联系手机","配偶手机号","配偶电话","爱人手机号"],idCard:["身份证","证件号","身份证号","idcard","id card","法人身份证","法人身份证号","法定代表人身份证号","配偶身份证","配偶身份证号","爱人身份证号"],email:["邮箱","邮件","email","mail","联系人邮箱","联系邮箱","contact email"],bankCard:["银行卡","卡号","bank","bank card"],amount:["金额","费用","价格","合计","总计","amount","price","申请金额","贷款金额","借款金额","授信金额","申请额度"],date:["日期","时间","有效期","date","申请日期","申请时间","受理日期","进件日期"]},Bt={mobile:"mobile",idCard:"idCard",email:"email",bankCard:"bankCard",amount:"amount",date:"date"};class Ut{recognize(t,n,r){const i=oi([...Zr(t),...Jr(t)]),o=new Set,s=[];for(const a of i.sort((c,l)=>l.confidence-c.confidence)){const c=ei(a,n,o);c&&(s.push({fieldId:c.fieldId,scanToken:r,label:c.label,value:ni(a.value,c),displayValue:a.value,confidence:a.confidence,source:"local_rule",reason:a.reason}),o.add(c.fieldId))}return s}}function Zr(e){const t=[];for(const n of Xr)for(const r of e.matchAll(n.pattern)){const i=jt(r[1]||r[0]);t.push({key:n.key,value:i,confidence:n.confidence,reason:n.reason,baseKey:Bt[n.key]})}return t}function Jr(e){const t=[],n=e.split(/\r?\n|[;,;]/).map(r=>r.trim()).filter(Boolean);for(const r of n){const i=r.match(/^[“"'`]?([^::=]{2,30})[”"'`]?[::=]\s*(.+)$/);if(!i)continue;const o=ii(i[1]),s=jt(i[2]);if(!(!o||!s))for(const a of Qr(o,s))t.push(a)}return t}function Qr(e,t){const n=G(e),r=ri(t),i=[];return(O(n,$.mobile)||r==="mobile")&&i.push("mobile"),(O(n,$.idCard)||r==="idCard")&&i.push("idCard"),(O(n,$.email)||r==="email")&&i.push("email"),(O(n,$.bankCard)||r==="bankCard")&&i.push("bankCard"),(O(n,$.amount)||r==="amount")&&i.push("amount"),(O(n,$.date)||r==="date")&&i.push("date"),si(i).map((o,s)=>({key:o,value:t,confidence:Math.max(.84,.96-s*.04),reason:`键值对文本命中(${e})`,baseKey:Bt[o]}))}function ei(e,t,n){let r=null;for(const i of t){if(n.has(i.fieldId))continue;const o=ti(e,i);o>((r==null?void 0:r.score)??0)&&(r={field:i,score:o})}return r&&r.score>=.45?r.field:null}function ti(e,t){const n=G([t.fieldId,t.label,t.placeholder,t.name,t.id,t.section].join(" ")),r=$[e.key]||[e.key];let i=0;return O(n,r)?i+=.95:O(n,[e.key])&&(i+=.82),n.includes(G(e.key))&&(i+=.22),t.required&&(i+=.05),e.baseKey==="amount"&&(t.type==="amount"||t.type==="number")&&(i+=.18),e.baseKey==="date"&&t.type==="date"&&(i+=.18),["email","mobile","idCard","bankCard"].includes(e.baseKey)&&t.type==="text"&&(i+=.08),Math.min(i,1)}function ni(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 ri(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 ii(e){return e.replace(/[“”"'`]/g,"").replace(/\s+/g," ").trim()}function jt(e){return e.replace(/[,。;;]+$/g,"").replace(/^[“”"'`\s]+|[“”"'`\s]+$/g,"").trim()}function O(e,t){const n=G(e);return t.some(r=>n.includes(G(r)))}function oi(e){const t=new Map;for(const n of e){const r=`${n.key}::${n.value}`,i=t.get(r);(!i||i.confidence<n.confidence)&&t.set(r,n)}return[...t.values()]}function si(e){return[...new Set(e)]}const Gt=["input","textarea","select","[contenteditable]:not([contenteditable='false'])"].join(", "),ai=new Set(["hidden","submit","button","image","reset","file","password"]);class Yt{constructor(t=document){this.root=t}scan(t={}){var l;const n=Ee("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),i=this.collectVisibleFields(r),o=this.detectTopLayerContainer(i),s=i.filter(u=>o.contains(u)),a=(s.length?s:i).slice(0,t.maxFields??200),c=s.length?o:r;return{scanToken:n,fields:a.map((u,p)=>this.fromElement(u,p,n,c))}}async scanWithDynamicOptions(t={}){var i,o;const n=this.scan(t);if(!n.fields.length||(i=t.registered)!=null&&i.length)return n;const r=[];for(const s of n.fields){const a=!!((o=s.options)!=null&&o.length)&&!ue(s);if(!s.element||a||s.type!=="select"&&s.type!=="cascader"){r.push(s);continue}const c=await In(s.element),l=c!=null&&c.length&&!ue({...s,options:c})?c:void 0;if(!(l!=null&&l.length)){r.push({...s,options:ue(s)?void 0:s.options});continue}const u={...s,options:l};u.fingerprint=ie({...u,tagName:s.element.tagName.toLowerCase()}),r.push(u)}return{...n,fields:r}}fromSchema(t,n){const r=bi(t.element,this.root),i=r?Oe(r)||Ie(r)||r:null,o={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:i||void 0,fingerprint:""};return o.fingerprint=ie({...o,tagName:i==null?void 0:i.tagName.toLowerCase()}),o}fromElement(t,n,r,i=this.root){const o=ci(t,n),s=di(t,i),a={fieldId:o,fingerprint:"",scanToken:r,type:li(t),localRuleMode:"inherit",label:Wt(t),placeholder:Zt(t),name:C(st(t))||void 0,id:C(t.id)||void 0,section:ui(t),options:s,required:hi(t),readonly:pi(t),disabled:Ye(t),source:"form_scan",element:t};return ue(a)&&(a.options=void 0),a.fingerprint=ie({...a,tagName:t.tagName.toLowerCase()}),a}resolveRoot(t){if(t){const n=Jt(this.root,t);if(n)return n}return this.root}collectVisibleFields(t){const n=new Set,r=[Gt,ct,nt,".van-field"].join(", ");for(const s of t.querySelectorAll(r)){if(!(s instanceof HTMLElement))continue;const a=Oe(s)||Ie(s);!a||!Ge(a)||Ye(a)||n.add(a)}const i=[...n],o=Array.from(t.querySelectorAll(Gt)).filter(s=>!(s instanceof HTMLElement)||!Ge(s)||gi(s)||s instanceof HTMLInputElement&&ai.has((s.type||"").toLowerCase())?!1:!Ye(s)&&!s.hasAttribute("readonly"));return yi([...o,...i])}detectTopLayerContainer(t){const n=document.activeElement instanceof HTMLElement?document.activeElement:null,r=n==null?void 0:n.closest(rt);if(r instanceof HTMLElement&&t.some(o=>r.contains(o)))return r;const i=t.map(o=>o.closest(rt)).filter(o=>o instanceof HTMLElement);return i.length?i.sort((o,s)=>t.filter(a=>s.contains(a)).length-t.filter(a=>o.contains(a)).length)[0]:document.body}}function ci(e,t){const n=e.getAttribute("data-smart-fill-id");if(n)return n;const i=C(e.getAttribute("name"))||C(e.getAttribute("data-smart-fill-key"))||C(st(e))||C(e.id)||C(Wt(e))||`smart-fill-${Date.now()}-${t}`;return e.setAttribute("data-smart-fill-id",i),i}function li(e){const t=dt(e);if(t)return t;const n=ce(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 Wt(e){const t=e.getAttribute("aria-label");if(t)return t.trim();if(e.id){const o=document.querySelector(`label[for="${We(e.id)}"]`);if(o!=null&&o.textContent)return d(o.textContent)}const n=e.closest(Sn),r=n==null?void 0:n.querySelector(En);if(r!=null&&r.textContent)return d(r.textContent);const i=e.closest("label");if(i){const o=Xt(i,e);if(o)return o}return Zt(e)||e.getAttribute("name")||e.id||"未命名字段"}function Xt(e,t){const n=e.cloneNode(!0);for(const i of n.querySelectorAll('input, textarea, select, button, [role="combobox"], [role="listbox"]'))i.remove();const r=d(n.textContent||"");if(r)return t instanceof HTMLInputElement&&t.value&&r.includes(t.value)?d(r.replace(t.value,""))||void 0:r}function Zt(e){var t;return e.getAttribute("placeholder")||e.getAttribute("aria-placeholder")||((t=e.querySelector("[placeholder]"))==null?void 0:t.getAttribute("placeholder"))||void 0}function ui(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?d(n.textContent):void 0}function di(e,t=document){const n=ft(e);if(n!=null&&n.length)return n;const r=ot(e);if(r!=null&&r.length)return r;if(e instanceof HTMLSelectElement)return Array.from(e.options).map(i=>({label:d(i.textContent||i.label),value:i.value}));if(e instanceof HTMLInputElement&&(e.type==="radio"||e.type==="checkbox")&&e.name)return Array.from(t.querySelectorAll(`input[name="${We(e.name)}"]`)).filter(i=>i.type===e.type&&Ge(i)).map(i=>({label:fi(i),value:i.value||!0}))}function fi(e){if(e.id){const n=document.querySelector(`label[for="${We(e.id)}"]`);if(n!=null&&n.textContent)return d(n.textContent)}const t=e.closest("label");if(t){const n=Xt(t,e);if(n)return n}return d(e.getAttribute("aria-label")||e.value||"")}function Ge(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 Ye(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"||wn.some(t=>e.classList.contains(t))}function pi(e){return e.hasAttribute("readonly")||!!e.querySelector("[readonly]")}function hi(e){return e.hasAttribute("required")||e.getAttribute("aria-required")==="true"||!!e.querySelector('[required], [aria-required="true"]')}function gi(e){return Oe(e)!=null||Ie(e)!=null}function yi(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 bi(e,t){return e instanceof HTMLElement?e:typeof e=="string"?Jt(t,e):null}function Jt(e,t){try{const n=e.querySelector(t);return n instanceof HTMLElement?n:null}catch{return null}}function We(e){return typeof CSS<"u"&&CSS.escape?CSS.escape(e):e.replace(/["\\]/g,"\\$&")}const Xe=5,mi=10*1024*1024,vi=50*1024*1024;class wi{constructor(t){f(this,"host",null);f(this,"root",null);f(this,"autoApplyState",null);f(this,"selectedFiles",[]);f(this,"inputText","");f(this,"localPriorityEnabled");f(this,"isOpen",!1);f(this,"dragState",null);f(this,"suppressOpenClick",!1);f(this,"isUploadHovering",!1);f(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 i=this.host.getBoundingClientRect(),o=Math.max(8,window.innerWidth-i.width-8),s=Math.max(8,window.innerHeight-i.height-8),a=_e(this.dragState.startLeft+n,8,o),c=_e(this.dragState.startTop+r,8,s);this.host.style.left=`${a}px`,this.host.style.top=`${c}px`});f(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))});f(this,"handleDocumentPaste",t=>{const n=Ei(t);if(!n.length||!this.isOpen||!this.host)return;const r=document.activeElement,i=this.root instanceof ShadowRoot?this.root.activeElement:null;!(r===this.host||this.host.contains(r)||i)&&!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>${xi}</style>
39
39
  ${this.options.mode==="floating"?`<button class="sf-float" type="button" data-role="open">${this.t("entry","智能录入")}</button>`:""}
40
40
  <section class="sf-panel ${t?"is-open":""} ${this.options.mode==="inline"?"is-inline":"is-floating"}" aria-label="智能录入面板">
41
41
  <header class="sf-header" data-role="close" >
@@ -45,7 +45,7 @@
45
45
  <div class="sf-body ${t?"is-open":""}">
46
46
  <div class="sf-entry-grid">
47
47
  <div class="sf-textarea-wrap">
48
- <textarea class="sf-textarea" data-role="text" placeholder="${this.t("placeholder","粘贴文本,如:姓名:张三 手机号:13800000000")}">${bo(this.inputText)}</textarea>
48
+ <textarea class="sf-textarea" data-role="text" placeholder="${this.t("placeholder","粘贴文本,如:姓名:张三 手机号:13800000000")}">${Si(this.inputText)}</textarea>
49
49
  <div class="sf-textarea-actions">
50
50
  <button class="sf-btn sf-btn-secondary" type="button" data-role="clear">${this.t("clear","清空")}</button>
51
51
  <button class="sf-btn sf-btn-primary" type="button" data-role="recognize">${this.t("recognize","智能识别")}</button>
@@ -62,7 +62,7 @@
62
62
  <circle cx="10" cy="10.5" r="1" fill="currentColor"/>
63
63
  </svg>
64
64
  </span>
65
- <span class="sf-upload-hint">${this.t("uploadHint",`点击、拖拽、Ctrl + V 粘贴图片至此(最多 ${We} 张)`)}</span>
65
+ <span class="sf-upload-hint">${this.t("uploadHint",`点击、拖拽、Ctrl + V 粘贴图片至此(最多 ${Xe} 张)`)}</span>
66
66
  </span>
67
67
  <span class="sf-upload-btn" data-role="file-label">图片识别</span>
68
68
  </label>
@@ -72,7 +72,7 @@
72
72
  </div>
73
73
  </div>
74
74
  </section>
75
- `,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 p=u.target;this.handleImages(Array.from(p.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 p;u.preventDefault(),this.isUploadHovering=!1,n.removeAttribute("data-dragover"),this.handleImages(Array.from(((p=u.dataTransfer)==null?void 0:p.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 p,m;this.localPriorityEnabled=u.target.checked,(m=(p=this.options).onLocalPriorityChange)==null||m.call(p,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"]'),p=u==null?void 0:u.value.trim();if(this.inputText=(u==null?void 0:u.value)||this.inputText,!p){this.setError(this.t("emptyInput","请输入文本内容。"));return}this.options.onRecognize({text:p})})}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>We){this.resetSelectedFiles(),this.setError(this.t("maxFilesError",`最多上传 ${We} 张图片。`));return}if(n.find(i=>i.size>go)){this.resetSelectedFiles(),this.setError(this.t("maxSingleFileSizeError","单张图片不能超过 10MB。"));return}if(n.reduce((i,s)=>i+s.size,0)>yo){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=xe(t.left,8,Math.max(8,window.innerWidth-t.width-8)),r=xe(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 bo(e){return e.replace(/[&<>"']/g,t=>({"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"})[t]||t)}function xe(e,t,n){return Math.min(Math.max(e,t),n)}function vo(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 wo=`
75
+ `,this.bindEvents())}bindEvents(){var r,i,o,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)),(i=this.query('[data-role="close"]'))==null||i.addEventListener("click",()=>{if(this.options.mode==="inline"){this.isOpen?this.options.onClose():this.options.onOpen();return}this.options.onClose()}),(o=this.query('[data-role="file"]'))==null||o.addEventListener("change",u=>{const p=u.target;this.handleImages(Array.from(p.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 p;u.preventDefault(),this.isUploadHovering=!1,n.removeAttribute("data-dragover"),this.handleImages(Array.from(((p=u.dataTransfer)==null?void 0:p.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 p,h;this.localPriorityEnabled=u.target.checked,(h=(p=this.options).onLocalPriorityChange)==null||h.call(p,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"]'),p=u==null?void 0:u.value.trim();if(this.inputText=(u==null?void 0:u.value)||this.inputText,!p){this.setError(this.t("emptyInput","请输入文本内容。"));return}this.options.onRecognize({text:p})})}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(o=>o.type.startsWith("image/"));if(!n.length){this.resetSelectedFiles(),this.setError(this.t("invalidImageError","请选择图片文件。"));return}if(n.length>Xe){this.resetSelectedFiles(),this.setError(this.t("maxFilesError",`最多上传 ${Xe} 张图片。`));return}if(n.find(o=>o.size>mi)){this.resetSelectedFiles(),this.setError(this.t("maxSingleFileSizeError","单张图片不能超过 10MB。"));return}if(n.reduce((o,s)=>o+s.size,0)>vi){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=_e(t.left,8,Math.max(8,window.innerWidth-t.width-8)),r=_e(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 Si(e){return e.replace(/[&<>"']/g,t=>({"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"})[t]||t)}function _e(e,t,n){return Math.min(Math.max(e,t),n)}function Ei(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 xi=`
76
76
  :host, .sf-panel { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
77
77
  :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; }
78
78
  .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; }
@@ -143,4 +143,4 @@
143
143
  width: min(450px, calc(100vw - 32px))
144
144
  }
145
145
  }
146
- `,So=.75,Eo=1800,ee=new Map;let te=0;const Xe="smart-fill:routechange",Yt="smart-fill:session-scan:";let Wt=!1;const Xt=new WeakMap;let xo=0;function Zt(){ee.clear(),cn(),te+=1}class Jt{constructor(t,n){f(this,"events",new ze);f(this,"scanner");f(this,"ruleEngine",new $t);f(this,"panel",null);f(this,"panels",[]);f(this,"panelStorageKeys",new Map);f(this,"registeredFields",[]);f(this,"adapters",[$e]);f(this,"scanResult",null);f(this,"autoApplyState",null);f(this,"formConfigVersion");f(this,"localPriorityEnabled",!1);f(this,"destroyed",!1);f(this,"scanCacheVersion",te);f(this,"floatingRouteSnapshot",null);f(this,"floatingLifecycleCleanup",null);f(this,"preScanTimer",null);this.config=t,this.context=n,this.scanner=new Vt(t.root||document),this.localPriorityEnabled=Go(),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 S("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 S("UNSUPPORTED_PAGE","未找到智能录入挂载点。","ui");const r=ln("inline",jo(t,n)),o=un(r,!0);return this.createPanel("inline",r,o).mount(n),this.schedulePreScan(),this}mountFloatingButton(){this.assertAlive();const t=qo(this.config),n=ln("floating"),r=un(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 mo({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,Yo(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),dn(this.panelStorageKeys.get(t),!0),this.scanResult||await this.rescan())}close(t=this.panel){t&&(this.panel=t,t.setOpen(!1),dn(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 S("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=we("trace"),o=performance.now();this.events.emit("recognizing",{scanToken:n.scanToken,traceId:r}),(a=this.panel)==null||a.setBusy(!0,"识别中...");try{const p=n.fields.filter(b=>To(b.localRuleMode,this.localPriorityEnabled)),m=n.fields.filter(b=>b.localRuleMode!=="only"),{text:re,usedOcr:_e}=await this.context.client.resolveInputText({text:t.text,images:t.images,onStatusChange:b=>{var Ce,q,Te;if(b==="image_uploading"){(Ce=this.panel)==null||Ce.setStatus("图片上传中...");return}if(b==="image_recognizing"){(q=this.panel)==null||q.setStatus("图片识别中...");return}(Te=this.panel)==null||Te.setStatus("识别中...")}}),Ae=re?this.ruleEngine.recognize(re,p,n.scanToken):[];let A;if(!m.length)A=en(n.scanToken,r,Ae,o,void 0,_e);else try{const b=await this.context.client.recognize({scanToken:n.scanToken,formCode:this.config.formCode,configVersion:this.formConfigVersion,text:re,usedOcr:_e,fields:m,onStatusChange:()=>{var q;(q=this.panel)==null||q.setStatus("识别中...")}});b.trace.durationMs=b.trace.durationMs||Math.round(performance.now()-o);const Ce=Co(Ae,b.suggestions.filter(q=>m.some(Te=>Te.fieldId===q.fieldId)));A={...b,suggestions:Ce}}catch(b){if(!Ae.length)throw b;A=en(n.scanToken,r,Ae,o,[_e?"后端识别失败,已使用 OCR 文本触发本地识别继续回填。":"后端识别失败,已启用本地识别继续回填。"],_e)}if(this.autoApplyState=_o(A.scanToken,A.trace.traceId,A.suggestions,n,this.registeredFields),this.events.emit("recognized",A),(c=this.panel)==null||c.setAutoApplyState(this.autoApplyState),this.config.apiEnable){const b=ko(A,this.autoApplyState,n);this.config.apiCallback&&await Promise.resolve(this.config.apiCallback(b)),(l=this.panel)==null||l.setStatus(`识别完成,已返回 ${b.fields.length} 个字段。`)}else await this.applyAutoItems(this.autoApplyState);return A}catch(p){throw this.clearScanStateOnTokenExpired(p),this.emitError(p,"recognize"),p}finally{(u=this.panel)==null||u.setBusy(!1)}}async apply(t){var o;if(this.assertAlive(),this.syncScanCacheVersion(),!this.scanResult)throw S("SCAN_TOKEN_EXPIRED","请先扫描字段后再回填。","apply");this.events.emit("applying",{scanToken:t.scanToken,count:t.values.length});const r=await new Ve(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 S("SCAN_TOKEN_EXPIRED","请先扫描字段后再回填。","apply");const n=Ao(t),r=t.items.filter(l=>Qt(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 Ve(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 S("INSTANCE_DESTROYED","实例已销毁。","ui")}emitError(t,n){var o;const r=qt(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=ee.get(n);if(r&&(!t||r.dynamicOptionsReady)){const i=Io(r.scanResult);if(!i)ee.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=ee.get(r);o!=null&&o.dynamicOptionsReady&&!n||(ee.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:Fo(this.config)}getSessionPageScanCacheKey(){return this.registeredFields.length||!this.config.formCode?null:Oo(this.config)}clearScanStateOnTokenExpired(t){qt(t,"recognize").code==="TOKEN_EXPIRED"&&(Zt(),this.scanCacheVersion=te,this.scanResult=null,this.autoApplyState=null)}syncScanCacheVersion(){this.scanCacheVersion!==te&&(this.scanCacheVersion=te,this.scanResult=null,this.autoApplyState=null)}getPersistedPageScanResult(t){const n=this.getSessionPageScanCacheKey();if(!n)return null;const r=Bo(n);if(!r||t&&!r.dynamicOptionsReady)return null;const o=this.scanner.scan({maxFields:this.config.maxFields}),i=Mo(r,o);return i?{scanResult:i,dynamicOptionsReady:r.dynamicOptionsReady}:(cn(n),null)}persistPageScanResult(t,n){const r=this.getSessionPageScanCacheKey();!r||!t.fields.length||Uo(r,{version:1,dynamicOptionsReady:n,fields:t.fields.map(({element:o,scanToken:i,...s})=>s)})}bindFloatingLifecycle(t){this.clearFloatingLifecycle(),this.floatingRouteSnapshot=rn(),Do();const n=()=>{this.destroyed||rn()!==this.floatingRouteSnapshot&&this.destroy()};window.addEventListener(Xe,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(Xe,n),r.disconnect(),this.floatingRouteSnapshot=null,this.floatingLifecycleCleanup=null}}clearFloatingLifecycle(){var t;(t=this.floatingLifecycleCleanup)==null||t.call(this)}}function ko(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 _o(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():Lo(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 Qt(e){var t;return e.confidence>=So&&!((t=e.warnings)!=null&&t.length)}function Ao(e){return e.items.filter(t=>!Qt(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 Co(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 To(e,t){return e==="only"?!0:e==="off"?!1:t}function en(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 Lo(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=Ro(n);return r?{...n,element:r}:null});return t.some(n=>!n)?null:{...e,fields:t}}function Mo(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=Q({...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 Ro(e){var t;if((t=e.element)!=null&&t.isConnected)return e.element;try{return document.querySelector(`[data-smart-fill-id="${Wo(e.fieldId)}"]`)}catch{return null}}function Fo(e){const t=typeof location<"u"?`${location.origin}${location.pathname}${location.search}`:"unknown-page",n=tn(e.root||document);return`smart-fill:${t}:${e.formCode||"default-form"}:${n}:${e.maxFields??200}:scan`}function Oo(e){const t=tn(e.root||document);return`${Yt}${e.formCode||"default-form"}:${t}:${e.maxFields??200}`}function tn(e){if(e===document)return"document";const t=Xt.get(e);if(t)return t;const n=e instanceof HTMLElement&&e.id?`el:${e.id}`:`root:${++xo}`;return Xt.set(e,n),n}function Do(){if(Wt||typeof window>"u")return;Wt=!0;const e=()=>{window.dispatchEvent(new Event(Xe))};window.addEventListener("popstate",e),window.addEventListener("hashchange",e),nn("pushState",e),nn("replaceState",e)}function nn(e,t){const n=window.history[e];window.history[e]=function(...o){const i=n.apply(this,o);return t(),i}}function rn(){return typeof location>"u"?"unknown-route":`${location.pathname}${location.search}${location.hash}`}function qo(e){const t=Po(e.floatingContainer);if(t)return t;const n=Ho(e.routeContainerSelector);return n||No()||document.body}function Po(e){return e?e instanceof HTMLElement?e:Ze(e):null}function Ho(e){if(!e)return null;const t=on(),n=t?Ze(e,t):null;return n||Ze(e)}function No(){const e=on();if(!e)return null;const t=$o(e);if(t)return t;const n=zo(e);if(n)return n;const r=Ko(e);return r!==e?r:null}function on(){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&&ke(n))return n}return null}function $o(e){const t=E(e),n=sn(e).filter(o=>!Je(o)).filter(o=>E(o)>=Math.max(t*.2,48e3)),r=n.filter(o=>Vo(o));return r.length?r.sort((o,i)=>E(i)-E(o))[0]:n.length===1?n[0]:null}function zo(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=an(e),r=E(e);return t.flatMap(i=>Array.from(e.querySelectorAll(i))).filter(i=>ke(i)&&!Je(i)).filter(i=>Qe(i,n)<=3).filter(i=>E(i)>=Math.max(r*.2,48e3)).sort((i,s)=>Qe(i,n)-Qe(s,n)||E(s)-E(i))[0]||null}function Ko(e){let t=e;for(;;){const n=sn(t).filter(o=>!Je(o));if(n.length!==1)return t;const[r]=n;if(E(r)<Math.max(E(t)*.25,48e3))return t;t=r}}function sn(e){return Array.from(e.children).filter(t=>t instanceof HTMLElement).filter(t=>ke(t))}function Ze(e,t=document){try{const n=t.querySelector(e);return n&&ke(n)?n:null}catch{return null}}function ke(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:E(e)<24e3}function Vo(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 E(e){const t=e.getBoundingClientRect();return Math.max(0,t.width)*Math.max(0,t.height)}function an(e){let t=0,n=e;for(;n&&n!==document.body;)t+=1,n=n.parentElement;return t}function Qe(e,t){return Math.max(0,an(e)-t)}function Bo(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 Uo(e,t){try{window.sessionStorage.setItem(e,JSON.stringify(t))}catch{}}function cn(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(Yt)&&t.push(r)}for(const n of t)window.sessionStorage.removeItem(n)}catch{}}function ln(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 jo(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 un(e,t){try{const n=window.localStorage.getItem(e);return n==null?t:n==="1"}catch{return t}}function dn(e,t){if(e)try{window.localStorage.setItem(e,t?"1":"0")}catch{}}function fn(){return`smart-fill:${typeof location<"u"?location.pathname:"unknown-page"}:local-priority`}function Go(){try{return window.localStorage.getItem(fn())==="1"}catch{return!1}}function Yo(e){try{window.localStorage.setItem(fn(),e?"1":"0")}catch{}}function Wo(e){return typeof CSS<"u"&&CSS.escape?CSS.escape(e):e.replace(/["\\]/g,"\\$&")}const h={status:"idle"},et=new ze,pn=new Dr;class hn{static async setup(t){if(typeof window>"u")return h.status="ready",Xo();if(h.status==="ready"&&h.apiKey===t.apiKey&&h.session)return h.session;if(h.status==="loading"&&h.apiKey===t.apiKey&&h.promise)return h.promise;h.apiKey&&h.apiKey!==t.apiKey&&(Zt(),pn.destroyAll());const n=new Lr(t);return h.status="loading",h.apiKey=t.apiKey,h.client=n,h.promise=n.createSession().then(r=>(console.log("SmartFill session created:",r),n.setAccessToken(r.apiKey),h.status="ready",h.session=r,et.emit("ready",{apiKey:t.apiKey}),r)).catch(r=>{throw h.status="error",r}),h.promise}static create(t={}){if(typeof window>"u")return ne();if(h.status!=="ready"||!h.client)throw S("SDK_NOT_READY","请先 await SmartFill.setup({ apiKey })。","setup");return new Jt(t,{client:h.client,manager:pn})}}f(hn,"on",et.on.bind(et));function Xo(){return{apiKey:"server-mock",accessToken:"server-mock",expiresIn:0,refreshBefore:0,features:{text:!1,image:!1,ai:!1,localRuleOnly:!0},rulesVersion:"server"}}function ne(e){const t=()=>{};return{on:t,useAdapter:()=>ne(),registerFields:()=>ne(),unregisterFields:t,mount:()=>ne(),mountFloatingButton:()=>ne(),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}}g.DEFAULT_BASE_URL=Ot,g.DomFiller=Ve,g.DomScanner=Vt,g.ElementAdapter=vr,g.EventBus=ze,g.LocalRuleEngine=$t,g.NativeAdapter=w,g.SmartFill=hn,g.SmartFillInstance=Jt,g.UiFrameworkAdapter=$e,Object.defineProperty(g,Symbol.toStringTag,{value:"Module"})});
146
+ `,ki=.75,_i=1800,oe=new Map;let se=0;const Ze="smart-fill:routechange",Qt="smart-fill:session-scan:";let en=!1;const tn=new WeakMap;let Ai=0;function nn(){oe.clear(),pn(),se+=1}class rn{constructor(t,n){f(this,"events",new Ke);f(this,"scanner");f(this,"ruleEngine",new Ut);f(this,"panel",null);f(this,"panels",[]);f(this,"panelStorageKeys",new Map);f(this,"registeredFields",[]);f(this,"adapters",[ze]);f(this,"scanResult",null);f(this,"autoApplyState",null);f(this,"formConfigVersion");f(this,"localPriorityEnabled",!1);f(this,"destroyed",!1);f(this,"scanCacheVersion",se);f(this,"floatingRouteSnapshot",null);f(this,"floatingLifecycleCleanup",null);f(this,"preScanTimer",null);this.config=t,this.context=n,this.scanner=new Yt(t.root||document),this.localPriorityEnabled=Xi(),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 i=r.rowKey==null?r.fieldId:`${r.fieldId}:${r.rowKey}`;if(n.has(i))throw x("UNSUPPORTED_PAGE",`字段 ${i} 重复注册。`,"scan");n.add(i)}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 x("UNSUPPORTED_PAGE","未找到智能录入挂载点。","ui");const r=hn("inline",Wi(t,n)),i=gn(r,!0);return this.createPanel("inline",r,i).mount(n),this.schedulePreScan(),this}mountFloatingButton(){this.assertAlive();const t=Hi(this.config),n=hn("floating"),r=gn(n,!0);return this.createPanel("floating",n,r).mount(t),this.bindFloatingLifecycle(t),this.schedulePreScan(),this}createPanel(t,n,r){let i;return i=new wi({mode:t,initialOpen:r,messages:this.config.messages,localPriorityEnabled:this.localPriorityEnabled,onOpen:()=>this.open(i),onClose:()=>this.close(i),onRecognize:o=>(this.panel=i,this.recognize(o)),onLocalPriorityChange:o=>this.handleLocalPriorityChange(o,i)}),this.panels.push(i),this.panelStorageKeys.set(i,n),this.panel=i,i}handleLocalPriorityChange(t,n){this.localPriorityEnabled=t,Zi(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),yn(this.panelStorageKeys.get(t),!0),this.scanResult||await this.rescan())}close(t=this.panel){t&&(this.panel=t,t.setOpen(!1),yn(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),i=this.registeredFields.length?this.registeredFields:void 0,o=i?this.scanner.scan({registered:i,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=o,this.cachePageScanResult(o,t.dynamicOptions),!this.scanResult.fields.length)throw x("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(()=>{})},_i))}cancelPreScan(){this.preScanTimer!=null&&(window.clearTimeout(this.preScanTimer),this.preScanTimer=null)}async recognize(t){var o,s,a,c,l,u;this.assertAlive(),this.syncScanCacheVersion(),(o=this.panel)==null||o.setBusy(!0,"扫描中..."),(s=this.panel)==null||s.setStatus("扫描中...");const n=await this.rescan(),r=Ee("trace"),i=performance.now();this.events.emit("recognizing",{scanToken:n.scanToken,traceId:r}),(a=this.panel)==null||a.setBusy(!0,"识别中...");try{const p=n.fields.filter(v=>Mi(v.localRuleMode,this.localPriorityEnabled)),h=n.fields.filter(v=>v.localRuleMode!=="only"),{text:m,usedOcr:A}=await this.context.client.resolveInputText({text:t.text,images:t.images,onStatusChange:v=>{var Te,z,Le;if(v==="image_uploading"){(Te=this.panel)==null||Te.setStatus("图片上传中...");return}if(v==="image_recognizing"){(z=this.panel)==null||z.setStatus("图片识别中...");return}(Le=this.panel)==null||Le.setStatus("识别中...")}}),Ce=m?this.ruleEngine.recognize(m,p,n.scanToken):[];let T;if(!h.length)T=sn(n.scanToken,r,Ce,i,void 0,A);else try{const v=await this.context.client.recognize({scanToken:n.scanToken,formCode:this.config.formCode,configVersion:this.formConfigVersion,text:m,usedOcr:A,fields:h,onStatusChange:()=>{var z;(z=this.panel)==null||z.setStatus("识别中...")}});v.trace.durationMs=v.trace.durationMs||Math.round(performance.now()-i);const Te=Ii(Ce,v.suggestions.filter(z=>h.some(Le=>Le.fieldId===z.fieldId)));T={...v,suggestions:Te}}catch(v){if(!Ce.length)throw v;T=sn(n.scanToken,r,Ce,i,[A?"后端识别失败,已使用 OCR 文本触发本地识别继续回填。":"后端识别失败,已启用本地识别继续回填。"],A)}if(this.autoApplyState=Ti(T.scanToken,T.trace.traceId,T.suggestions,n,this.registeredFields),this.events.emit("recognized",T),(c=this.panel)==null||c.setAutoApplyState(this.autoApplyState),this.config.apiEnable){const v=Ci(T,this.autoApplyState,n);this.config.apiCallback&&await Promise.resolve(this.config.apiCallback(v)),(l=this.panel)==null||l.setStatus(`识别完成,已返回 ${v.fields.length} 个字段。`)}else await this.applyAutoItems(this.autoApplyState);return T}catch(p){throw this.clearScanStateOnTokenExpired(p),this.emitError(p,"recognize"),p}finally{(u=this.panel)==null||u.setBusy(!1)}}async apply(t){var i;if(this.assertAlive(),this.syncScanCacheVersion(),!this.scanResult)throw x("SCAN_TOKEN_EXPIRED","请先扫描字段后再回填。","apply");this.events.emit("applying",{scanToken:t.scanToken,count:t.values.length});const r=await new Be(this.scanResult.fields,this.registeredFields,this.adapters).apply(t);return this.events.emit("applied",r),(i=this.panel)==null||i.setApplyResult(r),r}async applyAutoItems(t){var a,c;if(!this.scanResult)throw x("SCAN_TOKEN_EXPIRED","请先扫描字段后再回填。","apply");const n=Li(t),r=t.items.filter(l=>on(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 o=await new Be(this.scanResult.fields,this.registeredFields,this.adapters).apply({scanToken:t.scanToken,values:r}),s={...o,skipped:[...n,...o.skipped],warnings:[...o.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 x("INSTANCE_DESTROYED","实例已销毁。","ui")}emitError(t,n){var i;const r=zt(t,n);this.events.emit("error",r),(i=this.panel)==null||i.setError(r.message)}getCachedPageScanResult(t){const n=this.getPageScanCacheKey();if(!n)return null;const r=oe.get(n);if(r&&(!t||r.dynamicOptionsReady)){const o=Fi(r.scanResult);if(!o)oe.delete(n);else return o}const i=this.getPersistedPageScanResult(t);return i?(this.cachePageScanResult(i.scanResult,i.dynamicOptionsReady),i.scanResult):null}cachePageScanResult(t,n){const r=this.getPageScanCacheKey();if(!r||!t.fields.length)return;const i=oe.get(r);i!=null&&i.dynamicOptionsReady&&!n||(oe.set(r,{scanResult:t,dynamicOptionsReady:(i==null?void 0:i.dynamicOptionsReady)||n}),this.persistPageScanResult(t,(i==null?void 0:i.dynamicOptionsReady)||n))}getPageScanCacheKey(){return this.registeredFields.length?null:Di(this.config)}getSessionPageScanCacheKey(){return this.registeredFields.length||!this.config.formCode?null:Pi(this.config)}clearScanStateOnTokenExpired(t){zt(t,"recognize").code==="TOKEN_EXPIRED"&&(nn(),this.scanCacheVersion=se,this.scanResult=null,this.autoApplyState=null)}syncScanCacheVersion(){this.scanCacheVersion!==se&&(this.scanCacheVersion=se,this.scanResult=null,this.autoApplyState=null)}getPersistedPageScanResult(t){const n=this.getSessionPageScanCacheKey();if(!n)return null;const r=Gi(n);if(!r||t&&!r.dynamicOptionsReady)return null;const i=this.scanner.scan({maxFields:this.config.maxFields}),o=Oi(r,i);return o?{scanResult:o,dynamicOptionsReady:r.dynamicOptionsReady}:(pn(n),null)}persistPageScanResult(t,n){const r=this.getSessionPageScanCacheKey();!r||!t.fields.length||Yi(r,{version:1,dynamicOptionsReady:n,fields:t.fields.map(({element:i,scanToken:o,...s})=>s)})}bindFloatingLifecycle(t){this.clearFloatingLifecycle(),this.floatingRouteSnapshot=ln(),Ni();const n=()=>{this.destroyed||ln()!==this.floatingRouteSnapshot&&this.destroy()};window.addEventListener(Ze,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(Ze,n),r.disconnect(),this.floatingRouteSnapshot=null,this.floatingLifecycleCleanup=null}}clearFloatingLifecycle(){var t;(t=this.floatingLifecycleCleanup)==null||t.call(this)}}function Ci(e,t,n){return{scanToken:e.scanToken,trace:e.trace,warnings:e.warnings,fields:t.items.map(r=>{const i=n.fields.find(o=>o.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:i==null?void 0:i.type,currentValue:r.currentValue,warnings:r.warnings}})}}function Ti(e,t,n,r,i){return{scanToken:e,traceId:t,items:n.map(o=>{const s=r.fields.find(l=>l.fieldId===o.fieldId),a=i.find(l=>l.fieldId===o.fieldId),c=a!=null&&a.getValue?a.getValue():Ri(s==null?void 0:s.element);return{applyItemId:`${o.fieldId}_${Math.random().toString(36).slice(2,8)}`,fieldId:o.fieldId,scanToken:e,groupId:o.groupId,label:o.label,value:o.value,currentValue:c,displayValue:o.displayValue||String(o.value??""),confidence:o.confidence,source:o.source,warnings:o.warnings,previousValue:c}})}}function on(e){var t;return e.confidence>=ki&&!((t=e.warnings)!=null&&t.length)}function Li(e){return e.items.filter(t=>!on(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 Ii(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 Mi(e,t){return e==="only"?!0:e==="off"?!1:t}function sn(e,t,n,r,i,o=!1){return{scanToken:e,suggestions:n,warnings:i,trace:{traceId:t,usedOcr:o,usedAi:!1,durationMs:Math.round(performance.now()-r)}}}function Ri(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 Fi(e){const t=e.fields.map(n=>{if(n.source==="registered")return n;const r=qi(n);return r?{...n,element:r}:null});return t.some(n=>!n)?null:{...e,fields:t}}function Oi(e,t){var s,a;const n=new Map(t.fields.map(c=>[c.fieldId,c])),r=[],i=new Set;for(const c of e.fields){const l=n.get(c.fieldId);if(!l)continue;i.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=ie({...u,tagName:(a=u.element)==null?void 0:a.tagName.toLowerCase()}),r.push(u)}if(!r.length)return null;const o=t.fields.filter(c=>!i.has(c.fieldId));return{...t,fields:[...r,...o]}}function qi(e){var t;if((t=e.element)!=null&&t.isConnected)return e.element;try{return document.querySelector(`[data-smart-fill-id="${Ji(e.fieldId)}"]`)}catch{return null}}function Di(e){const t=typeof location<"u"?`${location.origin}${location.pathname}${location.search}`:"unknown-page",n=an(e.root||document);return`smart-fill:${t}:${e.formCode||"default-form"}:${n}:${e.maxFields??200}:scan`}function Pi(e){const t=an(e.root||document);return`${Qt}${e.formCode||"default-form"}:${t}:${e.maxFields??200}`}function an(e){if(e===document)return"document";const t=tn.get(e);if(t)return t;const n=e instanceof HTMLElement&&e.id?`el:${e.id}`:`root:${++Ai}`;return tn.set(e,n),n}function Ni(){if(en||typeof window>"u")return;en=!0;const e=()=>{window.dispatchEvent(new Event(Ze))};window.addEventListener("popstate",e),window.addEventListener("hashchange",e),cn("pushState",e),cn("replaceState",e)}function cn(e,t){const n=window.history[e];window.history[e]=function(...i){const o=n.apply(this,i);return t(),o}}function ln(){return typeof location>"u"?"unknown-route":`${location.pathname}${location.search}${location.hash}`}function Hi(e){const t=$i(e.floatingContainer);if(t)return t;const n=zi(e.routeContainerSelector);return n||Ki()||document.body}function $i(e){return e?e instanceof HTMLElement?e:Je(e):null}function zi(e){if(!e)return null;const t=un(),n=t?Je(e,t):null;return n||Je(e)}function Ki(){const e=un();if(!e)return null;const t=Vi(e);if(t)return t;const n=Bi(e);if(n)return n;const r=Ui(e);return r!==e?r:null}function un(){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&&Ae(n))return n}return null}function Vi(e){const t=k(e),n=dn(e).filter(i=>!Qe(i)).filter(i=>k(i)>=Math.max(t*.2,48e3)),r=n.filter(i=>ji(i));return r.length?r.sort((i,o)=>k(o)-k(i))[0]:n.length===1?n[0]:null}function Bi(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=fn(e),r=k(e);return t.flatMap(o=>Array.from(e.querySelectorAll(o))).filter(o=>Ae(o)&&!Qe(o)).filter(o=>et(o,n)<=3).filter(o=>k(o)>=Math.max(r*.2,48e3)).sort((o,s)=>et(o,n)-et(s,n)||k(s)-k(o))[0]||null}function Ui(e){let t=e;for(;;){const n=dn(t).filter(i=>!Qe(i));if(n.length!==1)return t;const[r]=n;if(k(r)<Math.max(k(t)*.25,48e3))return t;t=r}}function dn(e){return Array.from(e.children).filter(t=>t instanceof HTMLElement).filter(t=>Ae(t))}function Je(e,t=document){try{const n=t.querySelector(e);return n&&Ae(n)?n:null}catch{return null}}function Ae(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 Qe(e){const t=window.getComputedStyle(e);return t.position==="fixed"||t.position==="sticky"?!0:k(e)<24e3}function ji(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 k(e){const t=e.getBoundingClientRect();return Math.max(0,t.width)*Math.max(0,t.height)}function fn(e){let t=0,n=e;for(;n&&n!==document.body;)t+=1,n=n.parentElement;return t}function et(e,t){return Math.max(0,fn(e)-t)}function Gi(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 Yi(e,t){try{window.sessionStorage.setItem(e,JSON.stringify(t))}catch{}}function pn(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(Qt)&&t.push(r)}for(const n of t)window.sessionStorage.removeItem(n)}catch{}}function hn(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 Wi(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 gn(e,t){try{const n=window.localStorage.getItem(e);return n==null?t:n==="1"}catch{return t}}function yn(e,t){if(e)try{window.localStorage.setItem(e,t?"1":"0")}catch{}}function bn(){return`smart-fill:${typeof location<"u"?location.pathname:"unknown-page"}:local-priority`}function Xi(){try{return window.localStorage.getItem(bn())==="1"}catch{return!1}}function Zi(e){try{window.localStorage.setItem(bn(),e?"1":"0")}catch{}}function Ji(e){return typeof CSS<"u"&&CSS.escape?CSS.escape(e):e.replace(/["\\]/g,"\\$&")}const g={status:"idle"},tt=new Ke,mn=new Hr;class vn{static async setup(t){if(typeof window>"u")return g.status="ready",Qi();if(g.status==="ready"&&g.apiKey===t.apiKey&&g.session)return g.session;if(g.status==="loading"&&g.apiKey===t.apiKey&&g.promise)return g.promise;g.apiKey&&g.apiKey!==t.apiKey&&(nn(),mn.destroyAll());const n=new Fr(t);return g.status="loading",g.apiKey=t.apiKey,g.client=n,g.promise=n.createSession().then(r=>(console.log("SmartFill session created:",r),n.setAccessToken(r.apiKey),g.status="ready",g.session=r,tt.emit("ready",{apiKey:t.apiKey}),r)).catch(r=>{throw g.status="error",r}),g.promise}static create(t={}){if(typeof window>"u")return ae();if(g.status!=="ready"||!g.client)throw x("SDK_NOT_READY","请先 await SmartFill.setup({ apiKey })。","setup");return new rn(t,{client:g.client,manager:mn})}}f(vn,"on",tt.on.bind(tt));function Qi(){return{apiKey:"server-mock",accessToken:"server-mock",expiresIn:0,refreshBefore:0,features:{text:!1,image:!1,ai:!1,localRuleOnly:!0},rulesVersion:"server"}}function ae(e){const t=()=>{};return{on:t,useAdapter:()=>ae(),registerFields:()=>ae(),unregisterFields:t,mount:()=>ae(),mountFloatingButton:()=>ae(),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}}y.DEFAULT_BASE_URL=Ht,y.DomFiller=Be,y.DomScanner=Yt,y.ElementAdapter=xr,y.EventBus=Ke,y.LocalRuleEngine=Ut,y.NativeAdapter=S,y.SmartFill=vn,y.SmartFillInstance=rn,y.UiFrameworkAdapter=ze,Object.defineProperty(y,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kc-one/smart-fill-sdk",
3
- "version": "0.0.10",
3
+ "version": "0.0.11",
4
4
  "description": "Page-embedded smart form filling SDK.",
5
5
  "publishConfig": {
6
6
  "access": "public",