function R(o){const t=o.toUpperCase(),a={coreKeywords:["居民身份证","中华人民共和国居民身份证","公民身份号码","IDENTITY CARD","RESIDENT IDENTITY CARD","ID CARD"],fieldKeywords:["姓名","性别","民族","出生","住址","公民身份号码","签发机关","有效期限","年","月","日"],countryKeywords:["中华人民共和国","PEOPLE'S REPUBLIC OF CHINA","CHINA","PRC","中国"],singleCharKeywords:["姓","名","性","别","民","族","出","生","住","址","号","码"]},r={bankNames:["中国工商银行","中国农业银行","中国银行","中国建设银行","交通银行","招商银行","中信银行","浦发银行","兴业银行","民生银行","光大银行","华夏银行","平安银行","广发银行","浙商银行","渤海银行","邮政储蓄银行","INDUSTRIAL AND COMMERCIAL BANK","AGRICULTURAL BANK","BANK OF CHINA","CONSTRUCTION BANK","COMMUNICATIONS BANK","MERCHANTS BANK","CHINA MERCHANTS BANK","CITIC","PING AN BANK","BANK OF BEIJING","BANK OF SHANGHAI","CHINA EVERBRIGHT BANK","HUAXIA BANK"],cardTypes:["CREDIT CARD","DEBIT CARD","信用卡","借记卡","储蓄卡","贷记卡","金卡","白金卡"],paymentNetworks:["银联","UNIONPAY","VISA","MASTERCARD","AMEX","AMERICAN EXPRESS","JCB","DINERS CLUB"],functionKeywords:["VALID THRU","VALID FROM","EXPIRES","EXPIRY","CVV","CVV2","CVC","SECURITY CODE"]},s={coreKeywords:["PASSPORT","护照","TRAVEL DOCUMENT"],countryKeywords:["PEOPLE'S REPUBLIC OF CHINA","CHINA","CHINESE","中华人民共和国","中国"],typeKeywords:["P","TYPE","PASSPORT NO","护照号码"],fieldKeywords:["SURNAME","GIVEN NAME","NATIONALITY","DATE OF BIRTH","PLACE OF BIRTH","DATE OF ISSUE","DATE OF EXPIRY","AUTHORITY","SEX","姓","名","国籍","出生日期"]},f={provinces:["京","津","沪","渝","冀","豫","云","辽","黑","湘","皖","鲁","新","苏","浙","赣","鄂","桂","甘","晋","蒙","陕","吉","闽","贵","粤","青","藏","川","宁","琼"],typeKeywords:["警","军","WJ","使","领","港","澳","学","挂","超"]};let n=0,c=0,i=0,d=0;for(const e of a.coreKeywords)t.includes(e.toUpperCase())&&(n+=10);for(const e of a.fieldKeywords)t.includes(e.toUpperCase())&&(n+=3);for(const e of a.countryKeywords)t.includes(e.toUpperCase())&&(n+=2);let C=0;for(const e of a.singleCharKeywords)t.includes(e)&&C++;n+=Math.min(C,5),/\b\d{6}(19|20)\d{2}(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])\d{3}[\dXx]\b/.test(t)&&(n+=15),/\d{17}[\dXx]/.test(t)&&(n+=8);for(const e of r.bankNames)t.includes(e.toUpperCase())&&(c+=5);for(const e of r.cardTypes)t.includes(e.toUpperCase())&&(c+=4);for(const e of r.paymentNetworks)t.includes(e.toUpperCase())&&(c+=3);for(const e of r.functionKeywords)t.includes(e.toUpperCase())&&(c+=2);/\b\d{4}[\s\-]?\d{4}[\s\-]?\d{4}[\s\-]?\d{4,7}\b/.test(t)&&(c+=10);for(const e of s.coreKeywords)t.includes(e.toUpperCase())&&(i+=10);for(const e of s.countryKeywords)t.includes(e.toUpperCase())&&(i+=3);for(const e of s.typeKeywords)t.includes(e.toUpperCase())&&(i+=2);for(const e of s.fieldKeywords)t.includes(e.toUpperCase())&&(i+=2);/\b[EePpGgSs]\d{8}\b/.test(t)&&(i+=8);for(const e of f.provinces)t.includes(e)&&(d+=3);for(const e of f.typeKeywords)t.includes(e.toUpperCase())&&(d+=2);/[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼][A-Z][A-HJ-NP-Z0-9]{4,5}[A-HJ-NP-Z0-9挂学警港澳]?/.test(t)&&(d+=15);const A=[{type:"ID_CARD",score:n},{type:"BANK_CARD",score:c},{type:"PASSPORT",score:i},{type:"LICENSE_PLATE",score:d}];A.sort((e,m)=>m.score-e.score);const l=A[0],E=5,u=12;if(l.score>=E){const e=l.score>=u?.9:.5+l.score/u*.4;return{isDocument:!0,documentType:l.type,confidence:e}}return{isDocument:!1,confidence:0}}function T(o,t,a,r=6){return o.filter(s=>s.confidence>20&&s.text.trim().length>0).map(s=>{const f=Math.max(0,s.x0-r),n=Math.max(0,s.y0-r),c=Math.min(t-f,Math.max(1,s.x1-s.x0+2*r)),i=Math.min(a-n,Math.max(1,s.y1-s.y0+2*r));return{x:f,y:n,width:c,height:i}})}function M(o,t,a,r=.26){if(o.length===0)return null;const s=o.filter(A=>A.y0>=a*r),f=s.length>=2?s:o;let n=1/0,c=1/0,i=0,d=0;for(const A of f)n=Math.min(n,A.x0),c=Math.min(c,A.y0),i=Math.max(i,A.x1),d=Math.max(d,A.y1);if(!Number.isFinite(n)||i<=n||d<=c)return null;const C=16,h=Math.max(0,n-C),y=Math.max(0,c-C),p=Math.min(t-h,i-n+2*C),I=Math.min(a-y,d-c+2*C),N=p*I/(t*a);return N<.004||N>.98?null:{x:Math.round(h),y:Math.round(y),width:Math.round(p),height:Math.round(I)}}function P(o,t){const a=o.x+o.width/2,r=o.y+o.height/2;return a>=t.x&&a<=t.x+t.width&&r>=t.y&&r<=t.y+t.height}function w(o,t){const a=Math.max(o.x,t.x),r=Math.max(o.y,t.y),s=Math.min(o.x+o.width,t.x+t.width),f=Math.min(o.y+o.height,t.y+t.height),n=Math.max(0,s-a),c=Math.max(0,f-r),i=n*c,d=o.width*o.height,C=t.width*t.height,h=Math.min(d,C)||1;return i/h}export{R as a,M as c,T as m,w as o,P as r};
