@kc-one/smart-fill-sdk 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.esm.js +20 -1
- package/dist/index.umd.cjs +20 -1
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -2490,7 +2490,7 @@ const co = `
|
|
|
2490
2490
|
:host, .sf-panel { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
|
|
2491
2491
|
:host(.sf-sdk-host-floating), .sf-sdk-host-floating { position: fixed; top: 30px; right: 30px; z-index: 2147483647; display: flex; flex-direction: column; align-items: flex-end; gap: 12px; width: min(450px, calc(100vw - 32px)); pointer-events: none; }
|
|
2492
2492
|
.sf-float { font-size: 15px; align-self: flex-end; border: 0; border-radius: 999px; padding: 10px 30px; color: #fff; background: linear-gradient(to right, #FF7E49, #FFA34E); box-shadow: 0 10px 24px rgba(37,99,235,.3); cursor: move; user-select: none; touch-action: none; pointer-events: auto; }
|
|
2493
|
-
.sf-panel { display: none; width: 100%; box-sizing: border-box; border: 1px solid #dbe3ef; border-radius:
|
|
2493
|
+
.sf-panel { display: none; width: 100%; box-sizing: border-box; border: 1px solid #dbe3ef; border-radius: 8px; background: #fff; color: #FF7E49; padding: 12px 16px; pointer-events: auto; }
|
|
2494
2494
|
.sf-panel.is-open { display: block; }
|
|
2495
2495
|
.sf-panel.is-inline { display: block; }
|
|
2496
2496
|
.sf-body { display: none; }
|
|
@@ -2532,6 +2532,25 @@ const co = `
|
|
|
2532
2532
|
[data-status="error"] { color: #dc2626; }
|
|
2533
2533
|
[data-status="warning"] { color: #d97706; }
|
|
2534
2534
|
[data-status="success"] { color: #16a34a; }
|
|
2535
|
+
|
|
2536
|
+
@media (max-width: 768px) {
|
|
2537
|
+
.sf-entry-grid { grid-template-columns: minmax(0, 1fr) 35%;}
|
|
2538
|
+
.sf-btn{
|
|
2539
|
+
padding: 8px 10px;
|
|
2540
|
+
font-size: 12px;
|
|
2541
|
+
line-height: 1;
|
|
2542
|
+
}
|
|
2543
|
+
.sf-upload-btn {
|
|
2544
|
+
padding: 8px 6px;
|
|
2545
|
+
font-size: 12px;
|
|
2546
|
+
}
|
|
2547
|
+
.sf-upload-hint {
|
|
2548
|
+
font-size: 11px;
|
|
2549
|
+
}
|
|
2550
|
+
.sf-toggle-title{
|
|
2551
|
+
min-width: 60px;
|
|
2552
|
+
}
|
|
2553
|
+
}
|
|
2535
2554
|
`, lo = 0.75, uo = 1800, K = /* @__PURE__ */ new Map();
|
|
2536
2555
|
let V = 0;
|
|
2537
2556
|
const He = "smart-fill:routechange", Gt = "smart-fill:session-scan:";
|
package/dist/index.umd.cjs
CHANGED
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
:host, .sf-panel { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
|
|
57
57
|
:host(.sf-sdk-host-floating), .sf-sdk-host-floating { position: fixed; top: 30px; right: 30px; z-index: 2147483647; display: flex; flex-direction: column; align-items: flex-end; gap: 12px; width: min(450px, calc(100vw - 32px)); pointer-events: none; }
|
|
58
58
|
.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; }
|
|
59
|
-
.sf-panel { display: none; width: 100%; box-sizing: border-box; border: 1px solid #dbe3ef; border-radius:
|
|
59
|
+
.sf-panel { display: none; width: 100%; box-sizing: border-box; border: 1px solid #dbe3ef; border-radius: 8px; background: #fff; color: #FF7E49; padding: 12px 16px; pointer-events: auto; }
|
|
60
60
|
.sf-panel.is-open { display: block; }
|
|
61
61
|
.sf-panel.is-inline { display: block; }
|
|
62
62
|
.sf-body { display: none; }
|
|
@@ -98,4 +98,23 @@
|
|
|
98
98
|
[data-status="error"] { color: #dc2626; }
|
|
99
99
|
[data-status="warning"] { color: #d97706; }
|
|
100
100
|
[data-status="success"] { color: #16a34a; }
|
|
101
|
+
|
|
102
|
+
@media (max-width: 768px) {
|
|
103
|
+
.sf-entry-grid { grid-template-columns: minmax(0, 1fr) 35%;}
|
|
104
|
+
.sf-btn{
|
|
105
|
+
padding: 8px 10px;
|
|
106
|
+
font-size: 12px;
|
|
107
|
+
line-height: 1;
|
|
108
|
+
}
|
|
109
|
+
.sf-upload-btn {
|
|
110
|
+
padding: 8px 6px;
|
|
111
|
+
font-size: 12px;
|
|
112
|
+
}
|
|
113
|
+
.sf-upload-hint {
|
|
114
|
+
font-size: 11px;
|
|
115
|
+
}
|
|
116
|
+
.sf-toggle-title{
|
|
117
|
+
min-width: 60px;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
101
120
|
`,po=.75,ho=1800,ne=new Map;let re=0;const Ze="smart-fill:routechange",Vt="smart-fill:session-scan:";let Bt=!1;const Ut=new WeakMap;let go=0;function jt(){ne.clear(),nn(),re+=1}class Gt{constructor(t,n){d(this,"events",new Ke);d(this,"scanner");d(this,"ruleEngine",new Dt);d(this,"panel",null);d(this,"panels",[]);d(this,"panelStorageKeys",new Map);d(this,"registeredFields",[]);d(this,"adapters",[ze]);d(this,"scanResult",null);d(this,"autoApplyState",null);d(this,"formConfigVersion");d(this,"localPriorityEnabled",!1);d(this,"destroyed",!1);d(this,"scanCacheVersion",re);d(this,"floatingRouteSnapshot",null);d(this,"floatingLifecycleCleanup",null);d(this,"preScanTimer",null);this.config=t,this.context=n,this.scanner=new Nt(t.root||document),this.localPriorityEnabled=$o(),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=rn("inline",No(t,n)),o=on(r,!0);return this.createPanel("inline",r,o).mount(n),this.schedulePreScan(),this}mountFloatingButton(){this.assertAlive();const t=To(this.config),n=rn("floating"),r=on(n,!1);return this.createPanel("floating",n,r).mount(t),this.bindFloatingLifecycle(t),this.schedulePreScan(),this}createPanel(t,n,r){let o;return o=new co({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,Ho(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),sn(this.panelStorageKeys.get(t),!0),this.scanResult||await this.rescan())}close(t=this.panel){t&&(this.panel=t,t.setOpen(!1),sn(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(()=>{})},ho))}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=ve("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(m=>wo(m.localRuleMode,this.localPriorityEnabled)),y=n.fields.filter(m=>m.localRuleMode!=="only"),{text:M,usedOcr:ke}=await this.context.client.resolveInputText({text:t.text,images:t.images,onStatusChange:m=>{var Ae,N,Ce;if(m==="image_uploading"){(Ae=this.panel)==null||Ae.setStatus("图片上传中...");return}if(m==="image_recognizing"){(N=this.panel)==null||N.setStatus("图片识别中...");return}(Ce=this.panel)==null||Ce.setStatus("识别中...")}}),_e=M?this.ruleEngine.recognize(M,p,n.scanToken):[];let k;if(!y.length)k=Wt(n.scanToken,r,_e,o,void 0,ke);else try{const m=await this.context.client.recognize({scanToken:n.scanToken,formCode:this.config.formCode,configVersion:this.formConfigVersion,text:M,usedOcr:ke,fields:y,onStatusChange:()=>{var N;(N=this.panel)==null||N.setStatus("识别中...")}});m.trace.durationMs=m.trace.durationMs||Math.round(performance.now()-o);const Ae=vo(_e,m.suggestions.filter(N=>y.some(Ce=>Ce.fieldId===N.fieldId)));k={...m,suggestions:Ae}}catch(m){if(!_e.length)throw m;k=Wt(n.scanToken,r,_e,o,[ke?"后端识别失败,已使用 OCR 文本触发本地识别继续回填。":"后端识别失败,已启用本地识别继续回填。"],ke)}if(this.autoApplyState=bo(k.scanToken,k.trace.traceId,k.suggestions,n,this.registeredFields),this.events.emit("recognized",k),(c=this.panel)==null||c.setAutoApplyState(this.autoApplyState),this.config.apiEnable){const m=yo(k,this.autoApplyState,n);this.config.apiCallback&&await Promise.resolve(this.config.apiCallback(m)),(l=this.panel)==null||l.setStatus(`识别完成,已返回 ${m.fields.length} 个字段。`)}else await this.applyAutoItems(this.autoApplyState);return k}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 Be(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=mo(t),r=t.items.filter(l=>Yt(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 Be(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=Rt(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=ne.get(n);if(r&&(!t||r.dynamicOptionsReady)){const i=Eo(r.scanResult);if(!i)ne.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=ne.get(r);o!=null&&o.dynamicOptionsReady&&!n||(ne.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:_o(this.config)}getSessionPageScanCacheKey(){return this.registeredFields.length||!this.config.formCode?null:Ao(this.config)}clearScanStateOnTokenExpired(t){Rt(t,"recognize").code==="TOKEN_EXPIRED"&&(jt(),this.scanCacheVersion=re,this.scanResult=null,this.autoApplyState=null)}syncScanCacheVersion(){this.scanCacheVersion!==re&&(this.scanCacheVersion=re,this.scanResult=null,this.autoApplyState=null)}getPersistedPageScanResult(t){const n=this.getSessionPageScanCacheKey();if(!n)return null;const r=Po(n);if(!r||t&&!r.dynamicOptionsReady)return null;const o=this.scanner.scan({maxFields:this.config.maxFields}),i=xo(r,o);return i?{scanResult:i,dynamicOptionsReady:r.dynamicOptionsReady}:(nn(n),null)}persistPageScanResult(t,n){const r=this.getSessionPageScanCacheKey();!r||!t.fields.length||qo(r,{version:1,dynamicOptionsReady:n,fields:t.fields.map(({element:o,scanToken:i,...s})=>s)})}bindFloatingLifecycle(t){this.clearFloatingLifecycle(),this.floatingRouteSnapshot=Jt(),Co();const n=()=>{this.destroyed||Jt()!==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 yo(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 bo(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():So(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 Yt(e){var t;return e.confidence>=po&&!((t=e.warnings)!=null&&t.length)}function mo(e){return e.items.filter(t=>!Yt(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 vo(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 wo(e,t){return e==="only"?!0:e==="off"?!1:t}function Wt(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 So(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 Eo(e){const t=e.fields.map(n=>{if(n.source==="registered")return n;const r=ko(n);return r?{...n,element:r}:null});return t.some(n=>!n)?null:{...e,fields:t}}function xo(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=te({...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 ko(e){var t;if((t=e.element)!=null&&t.isConnected)return e.element;try{return document.querySelector(`[data-smart-fill-id="${zo(e.fieldId)}"]`)}catch{return null}}function _o(e){const t=typeof location<"u"?`${location.origin}${location.pathname}${location.search}`:"unknown-page",n=Xt(e.root||document);return`smart-fill:${t}:${e.formCode||"default-form"}:${n}:${e.maxFields??200}:scan`}function Ao(e){const t=Xt(e.root||document);return`${Vt}${e.formCode||"default-form"}:${t}:${e.maxFields??200}`}function Xt(e){if(e===document)return"document";const t=Ut.get(e);if(t)return t;const n=e instanceof HTMLElement&&e.id?`el:${e.id}`:`root:${++go}`;return Ut.set(e,n),n}function Co(){if(Bt||typeof window>"u")return;Bt=!0;const e=()=>{window.dispatchEvent(new Event(Ze))};window.addEventListener("popstate",e),window.addEventListener("hashchange",e),Zt("pushState",e),Zt("replaceState",e)}function Zt(e,t){const n=window.history[e];window.history[e]=function(...o){const i=n.apply(this,o);return t(),i}}function Jt(){return typeof location>"u"?"unknown-route":`${location.pathname}${location.search}${location.hash}`}function To(e){const t=Lo(e.floatingContainer);if(t)return t;const n=Io(e.routeContainerSelector);return n||Mo()||document.body}function Lo(e){return e?e instanceof HTMLElement?e:Je(e):null}function Io(e){if(!e)return null;const t=Qt(),n=t?Je(e,t):null;return n||Je(e)}function Mo(){const e=Qt();if(!e)return null;const t=Ro(e);if(t)return t;const n=Fo(e);if(n)return n;const r=Oo(e);return r!==e?r:null}function Qt(){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&&xe(n))return n}return null}function Ro(e){const t=E(e),n=en(e).filter(o=>!Qe(o)).filter(o=>E(o)>=Math.max(t*.2,48e3)),r=n.filter(o=>Do(o));return r.length?r.sort((o,i)=>E(i)-E(o))[0]:n.length===1?n[0]:null}function Fo(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=tn(e),r=E(e);return t.flatMap(i=>Array.from(e.querySelectorAll(i))).filter(i=>xe(i)&&!Qe(i)).filter(i=>et(i,n)<=3).filter(i=>E(i)>=Math.max(r*.2,48e3)).sort((i,s)=>et(i,n)-et(s,n)||E(s)-E(i))[0]||null}function Oo(e){let t=e;for(;;){const n=en(t).filter(o=>!Qe(o));if(n.length!==1)return t;const[r]=n;if(E(r)<Math.max(E(t)*.25,48e3))return t;t=r}}function en(e){return Array.from(e.children).filter(t=>t instanceof HTMLElement).filter(t=>xe(t))}function Je(e,t=document){try{const n=t.querySelector(e);return n&&xe(n)?n:null}catch{return null}}function xe(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:E(e)<24e3}function Do(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 tn(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,tn(e)-t)}function Po(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 qo(e,t){try{window.sessionStorage.setItem(e,JSON.stringify(t))}catch{}}function nn(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(Vt)&&t.push(r)}for(const n of t)window.sessionStorage.removeItem(n)}catch{}}function rn(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 No(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 on(e,t){try{const n=window.localStorage.getItem(e);return n==null?t:n==="1"}catch{return t}}function sn(e,t){if(e)try{window.localStorage.setItem(e,t?"1":"0")}catch{}}function an(){return`smart-fill:${typeof location<"u"?location.pathname:"unknown-page"}:local-priority`}function $o(){try{return window.localStorage.getItem(an())==="1"}catch{return!1}}function Ho(e){try{window.localStorage.setItem(an(),e?"1":"0")}catch{}}function zo(e){return typeof CSS<"u"&&CSS.escape?CSS.escape(e):e.replace(/["\\]/g,"\\$&")}const h={status:"idle"},tt=new Ke,cn=new Lr;class ln{static async setup(t){if(typeof window>"u")return h.status="ready",Ko();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&&(jt(),cn.destroyAll());const n=new xr(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,tt.emit("ready",{apiKey:t.apiKey}),r)).catch(r=>{throw h.status="error",r}),h.promise}static create(t={}){if(typeof window>"u")return oe();if(h.status!=="ready"||!h.client)throw S("SDK_NOT_READY","请先 await SmartFill.setup({ apiKey })。","setup");return new Gt(t,{client:h.client,manager:cn})}}d(ln,"on",tt.on.bind(tt));function Ko(){return{apiKey:"server-mock",accessToken:"server-mock",expiresIn:0,refreshBefore:0,features:{text:!1,image:!1,ai:!1,localRuleOnly:!0},rulesVersion:"server"}}function oe(e){const t=()=>{};return{on:t,useAdapter:()=>oe(),registerFields:()=>oe(),unregisterFields:t,mount:()=>oe(),mountFloatingButton:()=>oe(),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=It,g.DomFiller=Be,g.DomScanner=Nt,g.ElementAdapter=pr,g.EventBus=Ke,g.LocalRuleEngine=Dt,g.NativeAdapter=v,g.SmartFill=ln,g.SmartFillInstance=Gt,g.UiFrameworkAdapter=ze,Object.defineProperty(g,Symbol.toStringTag,{value:"Module"})});
|