@sekyro/web 0.1.0-rc.4 → 0.1.0-rc.40
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/CHANGELOG.md +491 -0
- package/LICENSE +25 -16
- package/README.md +158 -62
- package/THIRD-PARTY-NOTICES.txt +154 -0
- package/dist/assets.generated-DpkbvoII.d.cts +249 -0
- package/dist/assets.generated-DpkbvoII.d.ts +249 -0
- package/dist/background-monitor-A7FKJOAG.js +1 -0
- package/dist/barcode-detect-C5IOXMKI.js +1 -0
- package/dist/camera-trait-DELAK3YN.js +1 -0
- package/dist/capture-constraints-CVqpMNGA.d.cts +48 -0
- package/dist/capture-constraints-CVqpMNGA.d.ts +48 -0
- package/dist/capture-session-doc-DFLSX6BB.js +1 -0
- package/dist/{capture-session-v3-uXJr1Wlm.d.ts → capture-session-v3-C-9FB_vX.d.cts} +232 -13
- package/dist/{capture-session-v3-DEInCOUg.d.cts → capture-session-v3-DEpGJ_fI.d.ts} +232 -13
- package/dist/challenge-frame-YBTLAQ5G.js +1 -0
- package/dist/chunk-22AW4NJD.js +1 -0
- package/dist/chunk-33KKMPJ5.js +1 -0
- package/dist/chunk-3WQJI7UL.js +1 -0
- package/dist/chunk-4NO6MQPH.js +1 -0
- package/dist/chunk-53POX7U4.js +1 -0
- package/dist/chunk-7QZWBDI5.js +1 -0
- package/dist/chunk-BD4KIQQD.js +1 -0
- package/dist/chunk-BPAGOPYL.js +1 -0
- package/dist/chunk-BRLQIJYF.js +1 -0
- package/dist/chunk-CJHMFPL6.js +1 -0
- package/dist/chunk-CPUECYAJ.js +1 -0
- package/dist/chunk-FPXL63KZ.js +1 -0
- package/dist/chunk-FSSMUAKC.js +1 -0
- package/dist/chunk-FYU7J2DC.js +1 -0
- package/dist/chunk-GFJATPUR.js +1 -0
- package/dist/chunk-GI3UFGRQ.js +1 -0
- package/dist/chunk-JLVZ35QK.js +2 -0
- package/dist/chunk-L3TNFMQK.js +1 -0
- package/dist/chunk-M3637QGB.js +1 -0
- package/dist/chunk-MQHTFHSN.js +1 -0
- package/dist/chunk-POIQGEZM.js +1 -0
- package/dist/chunk-QB62OPX5.js +1 -0
- package/dist/chunk-QZUFICG3.js +1 -0
- package/dist/chunk-RI3E7GBN.js +1 -0
- package/dist/chunk-SJ5OJ677.js +1 -0
- package/dist/chunk-SMKCBUJL.js +1 -0
- package/dist/chunk-SX7TUC3V.js +1 -0
- package/dist/chunk-TSA6GHUG.js +1 -0
- package/dist/chunk-U5TL63CG.js +1 -0
- package/dist/chunk-VSLJZ7GH.js +1 -0
- package/dist/chunk-VWGKUQ3C.js +1 -0
- package/dist/chunk-W357WDNU.js +1 -0
- package/dist/chunk-WNBEOK5Q.js +1 -0
- package/dist/chunk-Y5GRT27C.js +3 -0
- package/dist/chunk-ZVD6VHM2.js +1 -0
- package/dist/client/index.cjs +1 -357
- package/dist/client/index.d.cts +6 -37
- package/dist/client/index.d.ts +6 -37
- package/dist/client/index.js +1 -15
- package/dist/clip-inspect-DLJXVKV6.js +1 -0
- package/dist/core/index.cjs +1 -1634
- package/dist/core/index.d.cts +5 -4
- package/dist/core/index.d.ts +5 -4
- package/dist/core/index.js +1 -139
- package/dist/core/ocr/worker.bundle.js +41 -0
- package/dist/core/ocr/worker.cjs +41 -0
- package/dist/core/ocr/worker.d.cts +97 -0
- package/dist/core/ocr/worker.d.ts +97 -0
- package/dist/core/ocr/worker.js +40 -0
- package/dist/core/v3/detect-worker.cjs +1 -392
- package/dist/core/v3/detect-worker.d.cts +1 -1
- package/dist/core/v3/detect-worker.d.ts +1 -1
- package/dist/core/v3/detect-worker.js +1 -13
- package/dist/create-document-capture-4ZOSBL3Y.js +1 -0
- package/dist/create-portrait-capture-5VGYZUOK.js +1 -0
- package/dist/create-verification-B8c9xBnz.d.ts +3871 -0
- package/dist/create-verification-BadlGBh3.d.cts +3871 -0
- package/dist/{detect-worker-CKXHlXx9.d.ts → detect-worker-CHqsPJoM.d.cts} +25 -2
- package/dist/{detect-worker-CKXHlXx9.d.cts → detect-worker-CHqsPJoM.d.ts} +25 -2
- package/dist/detector-scanic-P2RTEQUV.js +1 -0
- package/dist/icao-gate-BqXxEAq6.d.cts +610 -0
- package/dist/icao-gate-C7D7Lce7.d.ts +610 -0
- package/dist/icao-gate-T3BTOKFJ.js +1 -0
- package/dist/icao-policy-Bo7TQyTd.d.ts +80 -0
- package/dist/icao-policy-CgSI4oFo.d.cts +80 -0
- package/dist/icao-tuning-4ETMF53W.js +1 -0
- package/dist/index.cjs +3 -2698
- package/dist/index.d.cts +138 -5
- package/dist/index.d.ts +138 -5
- package/dist/index.js +1 -28
- package/dist/internal/index.cjs +3 -4228
- package/dist/internal/index.d.cts +306 -371
- package/dist/internal/index.d.ts +306 -371
- package/dist/internal/index.js +1 -647
- package/dist/keyframe-rank-YAJLYJYF.js +1 -0
- package/dist/landmarker-KB7LVXAU.js +1 -0
- package/dist/mrz-band-VYHOTDHY.js +1 -0
- package/dist/plan-runner-3BLEJWHF.js +1 -0
- package/dist/popup/index.cjs +1 -76
- package/dist/popup/index.d.cts +9 -3
- package/dist/popup/index.d.ts +9 -3
- package/dist/popup/index.js +1 -11
- package/dist/print-DCYX3CZD.js +1 -0
- package/dist/scanic-ml-stub-KW7IZHUT.js +1 -0
- package/dist/segmenter-USLNBX65.js +1 -0
- package/dist/types-BAAj6TOZ.d.cts +2230 -0
- package/dist/types-BAAj6TOZ.d.ts +2230 -0
- package/dist/upload-file-EGXXM6TQ.js +1 -0
- package/package.json +30 -11
- package/sbom.cdx.json +349 -0
- package/dist/capture-constraints-BujkZcfb.d.cts +0 -21
- package/dist/capture-constraints-BujkZcfb.d.ts +0 -21
- package/dist/chunk-EWRNPKTR.js +0 -1123
- package/dist/chunk-EWRNPKTR.js.map +0 -1
- package/dist/chunk-MWNFSNMP.js +0 -52
- package/dist/chunk-MWNFSNMP.js.map +0 -1
- package/dist/chunk-NILNKLK6.js +0 -50
- package/dist/chunk-NILNKLK6.js.map +0 -1
- package/dist/chunk-NWF46H7K.js +0 -359
- package/dist/chunk-NWF46H7K.js.map +0 -1
- package/dist/chunk-TBANUT3X.js +0 -885
- package/dist/chunk-TBANUT3X.js.map +0 -1
- package/dist/chunk-WY6U7AIK.js +0 -193
- package/dist/chunk-WY6U7AIK.js.map +0 -1
- package/dist/chunk-YVFF4Q4G.js +0 -327
- package/dist/chunk-YVFF4Q4G.js.map +0 -1
- package/dist/client/index.cjs.map +0 -1
- package/dist/client/index.js.map +0 -1
- package/dist/core/index.cjs.map +0 -1
- package/dist/core/index.js.map +0 -1
- package/dist/core/v3/detect-worker.cjs.map +0 -1
- package/dist/core/v3/detect-worker.js.map +0 -1
- package/dist/create-verification-Ce1y5kJR.d.ts +0 -371
- package/dist/create-verification-Dkb2tXuY.d.cts +0 -371
- package/dist/detector-scanic-4C6IEW2K.js +0 -787
- package/dist/detector-scanic-4C6IEW2K.js.map +0 -1
- package/dist/hosted-client-DWzCRYJK.d.cts +0 -421
- package/dist/hosted-client-DWzCRYJK.d.ts +0 -421
- package/dist/index.cjs.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/internal/index.cjs.map +0 -1
- package/dist/internal/index.js.map +0 -1
- package/dist/popup/index.cjs.map +0 -1
- package/dist/popup/index.js.map +0 -1
- package/dist/scanic-ml-stub-S2OZ6HEF.js +0 -10
- package/dist/scanic-ml-stub-S2OZ6HEF.js.map +0 -1
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { O as OCR_ASSET_SET } from '../../assets.generated-DpkbvoII.js';
|
|
2
|
+
|
|
3
|
+
interface OcrDecoded {
|
|
4
|
+
readonly text: string;
|
|
5
|
+
readonly score: number;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
type PrintedScript = keyof typeof OCR_ASSET_SET.scripts;
|
|
9
|
+
|
|
10
|
+
/** The Emscripten module surface the binding exports (bindings/exports.json). */
|
|
11
|
+
interface SekyroOcrModule {
|
|
12
|
+
HEAPU8: Uint8Array;
|
|
13
|
+
_malloc(n: number): number;
|
|
14
|
+
_free(p: number): void;
|
|
15
|
+
_skw_engine_id(): number;
|
|
16
|
+
_skw_load(model: number, param: number, paramBytes: number, weights: number, weightBytes: number, classes: number): number;
|
|
17
|
+
_skw_unload(model: number): void;
|
|
18
|
+
_skw_set_detector_limit(limit: number): void;
|
|
19
|
+
_skw_read(px: number, w: number, h: number, x: number, y: number, rw: number, rh: number, scale: number, op: number, scripts: number): number;
|
|
20
|
+
_skw_line_count(): number;
|
|
21
|
+
_skw_lines(): number;
|
|
22
|
+
_skw_best(): number;
|
|
23
|
+
_skw_values(): number;
|
|
24
|
+
_skw_sharpness(px: number, w: number, h: number): number;
|
|
25
|
+
}
|
|
26
|
+
/** One detected line: its source box (x1,y1 … x4,y4, source pixels) and each requested script's decode. */
|
|
27
|
+
interface EngineLine {
|
|
28
|
+
readonly box: readonly number[];
|
|
29
|
+
readonly latin?: OcrDecoded;
|
|
30
|
+
readonly arabic?: OcrDecoded;
|
|
31
|
+
}
|
|
32
|
+
declare class WasmEngine {
|
|
33
|
+
private readonly m;
|
|
34
|
+
private px;
|
|
35
|
+
private pxBytes;
|
|
36
|
+
private dicts;
|
|
37
|
+
private classes;
|
|
38
|
+
private held;
|
|
39
|
+
private latinKind;
|
|
40
|
+
/** The v5 script each recognizer slot holds (slot 1: latin; slot 2: the document's non-Latin script). */
|
|
41
|
+
private scripts;
|
|
42
|
+
constructor(m: SekyroOcrModule);
|
|
43
|
+
engineId(): string;
|
|
44
|
+
private put;
|
|
45
|
+
/**
|
|
46
|
+
* Loads a net; `dict` (UTF-8 text) for a recognizer. The heap copies live until [unload] (ncnn keeps pointers).
|
|
47
|
+
* `mrz`: the MRZ-only recognizer (spec D10; sekyro-mobile/ocr-models/mrz) in the LATIN slot instead of PP-OCR Latin:
|
|
48
|
+
* the same engine read and `recognize` callback, its own 37-symbol dictionary (39 classes with blank + space).
|
|
49
|
+
* Otherwise a PP-OCRv5 printed-text recognizer (spec 2026-11-15 D4, v5-models.ts): `script` `latin` in the LATIN slot
|
|
50
|
+
* (the default there), any other v5 script in slot 2 (the binding's ARABIC slot; `arabic` the default there). Its
|
|
51
|
+
* class count is the script's (838 Latin, 749 Arabic, …) and its dictionary must have exactly classes − 1 entries
|
|
52
|
+
* with no trailing newline; any other shape is the wrong file (OCR_ASSET_INVALID), as on Android.
|
|
53
|
+
*/
|
|
54
|
+
load(model: 0 | 1 | 2, param: ArrayBuffer | Uint8Array, weights: ArrayBuffer | Uint8Array, dict?: string, o?: {
|
|
55
|
+
mrz?: boolean;
|
|
56
|
+
script?: PrintedScript;
|
|
57
|
+
}): void;
|
|
58
|
+
/** Which recognizer the LATIN slot holds (null when none). */
|
|
59
|
+
recognizer(): "latin" | "mrz" | null;
|
|
60
|
+
/** The v5 script slot 2 holds (the document's non-Latin script), null when empty. */
|
|
61
|
+
secondScript(): PrintedScript | null;
|
|
62
|
+
unload(model: 0 | 1 | 2): void;
|
|
63
|
+
loaded(model: 0 | 1 | 2): boolean;
|
|
64
|
+
private pixels;
|
|
65
|
+
/** Blur-gate measure of an RGBA image; null when not measurable (Kotlin `N.s(...).takeIf { it >= 0 }`). */
|
|
66
|
+
sharpness(rgba: Uint8Array | Uint8ClampedArray, w: number, h: number): number | null;
|
|
67
|
+
/**
|
|
68
|
+
* One engine read: `region` normalized [x, y, w, h], `op` the detector operation (3 cover … 9 inkLines), `scripts`
|
|
69
|
+
* SCRIPTS.LATIN | ARABIC | BOTH (or NONE: the detected line boxes only, no recognizer), `limit` the detector input
|
|
70
|
+
* long side.
|
|
71
|
+
*/
|
|
72
|
+
read(rgba: Uint8Array | Uint8ClampedArray, w: number, h: number, region: readonly number[], scale: number, op: number, scripts: number, limit: number): EngineLine[];
|
|
73
|
+
/** Current wasm heap size (it only grows): the memory telemetry of a read profile. */
|
|
74
|
+
heapBytes(): number;
|
|
75
|
+
dispose(): void;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
interface OcrWorkerScope {
|
|
79
|
+
onmessage: ((event: {
|
|
80
|
+
data: unknown;
|
|
81
|
+
}) => void) | null;
|
|
82
|
+
postMessage(data: unknown): void;
|
|
83
|
+
close(): void;
|
|
84
|
+
}
|
|
85
|
+
interface OcrWorkerDeps {
|
|
86
|
+
fetch: typeof fetch;
|
|
87
|
+
now: () => number;
|
|
88
|
+
/** The 2D canvas the worker draws bitmaps on (null = unsupported: OffscreenCanvas 2D missing in this worker). */
|
|
89
|
+
canvas: (w: number, h: number) => {
|
|
90
|
+
draw(bitmap: ImageBitmap): Uint8ClampedArray;
|
|
91
|
+
} | null;
|
|
92
|
+
instantiate: (module: WebAssembly.Module) => Promise<WasmEngine>;
|
|
93
|
+
}
|
|
94
|
+
declare function defaultDeps(): OcrWorkerDeps;
|
|
95
|
+
declare function installOcrWorkerHost(scope: OcrWorkerScope, deps?: OcrWorkerDeps): void;
|
|
96
|
+
|
|
97
|
+
export { type OcrWorkerDeps, type OcrWorkerScope, defaultDeps, installOcrWorkerHost };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import{a as Oe,b as Te,c as Le}from"../../chunk-BD4KIQQD.js";import{b as _e}from"../../chunk-JLVZ35QK.js";import{a as ue}from"../../chunk-QB62OPX5.js";import{c as Ne,h as Ce}from"../../chunk-WNBEOK5Q.js";var S=class extends Error{constructor(n){super(n),this.name="OcrFailure",this.code=n}};function le(e){return[...e.split(`
|
|
2
|
+
`)," "]}function we(e,n,t,r,s){if(t<2||e.length===0||e.length!==n.length||r.length<t-1)throw new S("OCR_INFERENCE_FAILED");let i="",o=-1,u=0,a=0;for(let f=0;f<e.length;f++){let g=e[f];if(!Number.isInteger(g)||g<0||g>=t)throw new S("OCR_INFERENCE_FAILED");g!==0&&g!==o&&(i+=r[g-1],u+=Math.fround(n[f]),a++),o=g}return{text:s?Array.from(i).reverse().join(""):i,score:a===0?0:u/a}}var ge="latin",st=Object.keys(ue.scripts);function De(e){return Object.prototype.hasOwnProperty.call(ue.scripts,e)}function Be(e){let n=ue.scripts[e];return{script:e,classes:n.classes,rtl:n.rtl,param:n.param,bin:n.bin,dict:n.dict}}function Pe(e,n){let t=le(e);if(e.endsWith(`
|
|
3
|
+
`)||t.length!==n-1)throw new S("OCR_ASSET_INVALID");return t}var ve=e=>e.reduce((n,t)=>n+t,0)/e.length;function ke(e){let n=e.filter(s=>s.score>=.5);if(n.length===0)return[];if(n.some(s=>s.box.length!==4||!Number.isFinite(s.score)||s.box.some(i=>!Number.isFinite(i.x)||!Number.isFinite(i.y))))throw new S("OCR_INFERENCE_FAILED");let t=ve(n.map(s=>s.box[2].y-s.box[0].y)),r=[];for(let s of n){let i=(s.box[0].y+s.box[2].y)/2,o=r.find(u=>Math.abs((u[0].box[0].y+u[0].box[2].y)/2-i)<t/2);o===void 0?r.push([s]):o.push(s)}for(let s of r)s.sort((i,o)=>i.box[0].x-o.box[0].x);return r.sort((s,i)=>s[0].box[0].y-i[0].box[0].y),r.map(s=>{let i=s[0].box,o=s[s.length-1].box,u=[i[0],o[1],o[2],i[3]];return{text:s.map(a=>a.text).join(" "),x:Math.min(...u.map(a=>a.x)),y:Math.min(...u.map(a=>a.y)),x2:Math.max(...u.map(a=>a.x)),y2:Math.max(...u.map(a=>a.y)),score:ve(s.map(a=>a.score))}})}var $={of(e,n,t){return!Number.isInteger(e)||!Number.isInteger(n)||!Number.isInteger(t)||n<1||n>12||t<1||t>new Date(Date.UTC(e,n,0)).getUTCDate()?null:{year:e,month:n,day:t}},iso(e){return`${String(e.year).padStart(4,"0")}-${String(e.month).padStart(2,"0")}-${String(e.day).padStart(2,"0")}`},parse(e){let[n,t,r]=e.split("-").map(Number);return{year:n,month:t,day:r}},today(){let e=new Date;return{year:e.getFullYear(),month:e.getMonth()+1,day:e.getDate()}}},Fe=30,Ke=36,He=44,pe="MRT",pn=[7,3,1],bn=/^[0-9]{6}$/,ye=/^[0-9]{10}$/,We=e=>e!==void 0&&e.length===1&&e>="0"&&e<="9";function yn(e){return e>="0"&&e<="9"?e.charCodeAt(0)-48:e>="A"&&e<="Z"?e.charCodeAt(0)-55:0}function de(e){let n=0;for(let t=0;t<e.length;t++)n+=yn(e[t])*pn[t%3];return String(n%10)}function B(e,n){return n==="<"?null:We(n)?de(e)===n:!1}function ce(e){return e.trim().toUpperCase().replaceAll(" ","")}function An(e,n){return(ce(e)+"<".repeat(n)).slice(0,n)}function P(e){return e.replace(/^<+|<+$/g,"")}var hn=new Set(`ABW AFG AGO AIA ALA ALB AND ARE ARG ARM ASM ATA ATF ATG AUS AUT AZE BDI BEL BEN BES BFA BGD BGR BHR
|
|
4
|
+
BHS BIH BLM BLR BLZ BMU BOL BRA BRB BRN BTN BVT BWA CAF CAN CCK CHE CHL CHN CIV CMR COD COG COK COL
|
|
5
|
+
COM CPV CRI CUB CUW CXR CYM CYP CZE DEU DJI DMA DNK DOM DZA ECU EGY ERI ESH ESP EST ETH FIN FJI FLK
|
|
6
|
+
FRA FRO FSM GAB GBR GEO GGY GHA GIB GIN GLP GMB GNB GNQ GRC GRD GRL GTM GUF GUM GUY HKG HMD HND HRV
|
|
7
|
+
HTI HUN IDN IMN IND IOT IRL IRN IRQ ISL ISR ITA JAM JEY JOR JPN KAZ KEN KGZ KHM KIR KNA KOR KWT LAO
|
|
8
|
+
LBN LBR LBY LCA LIE LKA LSO LTU LUX LVA MAC MAF MAR MCO MDA MDG MDV MEX MHL MKD MLI MLT MMR MNE MNG
|
|
9
|
+
MNP MOZ MRT MSR MTQ MUS MWI MYS MYT NAM NCL NER NFK NGA NIC NIU NLD NOR NPL NRU NZL OMN PAK PAN PCN
|
|
10
|
+
PER PHL PLW PNG POL PRI PRK PRT PRY PSE PYF QAT REU ROU RUS RWA SAU SDN SEN SGP SGS SHN SJM SLB SLE
|
|
11
|
+
SLV SMR SOM SPM SRB SSD STP SUR SVK SVN SWE SWZ SXM SYC SYR TCA TCD TGO THA TJK TKL TKM TLS TON TTO
|
|
12
|
+
TUN TUR TUV TWN TZA UGA UKR UMI URY USA UZB VAT VCT VEN VGB VIR VNM VUT WLF WSM XKK YEM ZAF ZMB ZWE`.trim().split(/\s+/)),xn=new Set(`D GBD GBN GBO GBP GBS RKS UNK UNO UNA EUE XBA XIM XCC XCE XCO XDC XEC XES XMP XOM XPO XXA XXB XXC
|
|
13
|
+
XXX ANT NTZ UTO`.trim().split(/\s+/));function Mn(e){return hn.has(e)||xn.has(e)}var Rn="012568",In="OIZSGB",Sn="OQDILZSGB",En="000112568";function be(e){let n=Rn.indexOf(e);return e.length!==1||n<0?e:In[n]}function Nn(e){let n=Sn.indexOf(e);return e.length!==1||n<0?e:En[n]}var Cn=[["\xAB","<<"],["\u2039","<"],["\uFF1C","<"],["\u3008","<"],["\xD7","X"]],ze=[`aaccc${"x".repeat(9)}n${"x".repeat(15)}`,`${"n".repeat(7)}x${"n".repeat(7)}ccc${"x".repeat(11)}n`,"a".repeat(30)],Ve=[`aaccc${"a".repeat(31)}`,`${"x".repeat(9)}nccc${"n".repeat(7)}x${"n".repeat(7)}${"x".repeat(7)}n`],Ze=[`aaccc${"a".repeat(39)}`,`${"x".repeat(9)}nccc${"n".repeat(7)}x${"n".repeat(7)}${"x".repeat(14)}nn`];function _n(e,n){let t="",r=0;for(;r<n.length;){let s=n[r];if(s==="c"){let o=e.substring(r,r+3),u=Array.from(o,be).join("");t+=u!==o&&Mn(u.replaceAll("<",""))?u:o,r+=3;continue}let i=e[r];t+=s==="a"?be(i):s==="n"?Nn(i):i,r++}return t}function j(e,n,t){return t.slice(0,e.length).map((r,s)=>{let i=Cn.reduce((o,[u,a])=>o.replaceAll(u,a),ce(e[s]));return _n(An(i,n),r)})}function Ye(e,n){let t=e.filter(r=>r.trim().length>0);return n==="TD1"?j(t.slice(0,3),Fe,ze):n==="TD2"?j(t.slice(0,2),Ke,Ve):j(t.slice(0,2),He,Ze)}function Ae(e){let n=`${e.toUpperCase()}<<`.slice(0,2);return n==="AC"?"unknown":n==="IR"||n==="AR"||"ACRT".includes(n[0])?"residence_permit":n[0]==="P"?"passport":n[0]==="I"?"carte_identite":"unknown"}function On(e){return ye.test(e)&&Number(e)%97===1}function Tn(e,n,t){if(!bn.test(e))return null;let r=Number(e.slice(0,2)),s=n?2e3+r:r>t.year%100?1900+r:2e3+r;return $.of(s,Number(e.slice(2,4)),Number(e.slice(4,6)))}function q(e,n,t){let r=Tn(e,n,t);return r?$.iso(r):""}function he(e){let n=e.split("<<").filter(t=>P(t).length>0);return[(n[0]??"").replaceAll("<"," ").trim(),(n[1]??"").replaceAll("<"," ").trim()]}var xe=e=>e==="M"||e==="F"?e:"",Ln=e=>e.substring(0,2).replaceAll("<",""),re=e=>e.substring(2,5).replaceAll("<","");function Xe(e,n,t){if(n==="<"&&P(t).length>0){let r=t.indexOf("<"),s=r<0?t:t.slice(0,r);if(s.length>=2){let i=e+s.slice(0,-1);if(B(i,s[s.length-1])===!0)return{value:P(i),ok:!0,warn:null}}return{value:P(e),ok:!1,warn:"docnum_cd_mismatch"}}return{value:P(e),ok:B(e,n),warn:null}}var F=(e,n)=>({success:!1,error:e,fields:{},checkDigits:{},hardCdFail:!1,warns:[],...n===void 0?{}:{linesCount:n}});function Me(e,n,t,r,s,i,o){return{success:!0,documentType:e,format:n,documentCode:Ln(t),fields:r,checkDigits:s,hardCdFail:i,warns:o}}function wn(e,n){if(e.length<3)return F("mrz_incomplete");let[t,r,s]=j(e.slice(0,3),Fe,ze),i=re(t)===pe||r.substring(15,18)===pe||On(t.substring(15,25)),o=[],u={},a,m,f=!1;if(i){a=P(t.substring(5,14));let h=t[14];We(h)?(m=de(t.substring(5,14))===h,m||o.push("td1_docnum_cd_mismatch")):m=null}else{let h=Xe(t.substring(5,14),t[14],t.substring(15,30));if(h.ok===null)return F("mrz_incomplete");a=h.value,m=h.ok,f=h.ok===!1&&h.warn===null,h.warn!==null&&o.push(h.warn)}u.document_number=m;let g=B(r.substring(0,6),r[6]),y=B(r.substring(8,14),r[14]);if(u.birth_date=g,u.expiry_date=y,g===null||y===null)return F("mrz_incomplete");let b=B(t.substring(5,30)+r.substring(0,7)+r.substring(8,15)+r.substring(18,29),r[29]);u.composite=b,b===!1&&o.push("composite_cd_mismatch");let d=i?t.substring(15,25):"",[l,R]=he(s),I=g===!1||y===!1||f;return Me(Ae(t.substring(0,2)),"TD1",t,{issuing_state:re(t),document_number:a,nni:ye.test(d)?d:"",birth_date:q(r.substring(0,6),!1,n),expiry_date:q(r.substring(8,14),!0,n),sex:xe(r[7]),nationality:P(r.substring(15,18)),surname:l,given_names:R},u,I,o)}function Dn(e,n){if(e.length<2)return F("mrz_incomplete");let[t,r]=j(e.slice(0,2),Ke,Ve),s=[],i=Xe(r.substring(0,9),r[9],r.substring(28,35));i.warn!==null&&s.push(i.warn);let o=B(r.substring(13,19),r[19]),u=B(r.substring(21,27),r[27]),a={document_number:i.ok,birth_date:o,expiry_date:u};if(i.ok===null||o===null||u===null)return F("mrz_incomplete");let m=B(r.substring(0,10)+r.substring(13,20)+r.substring(21,35),r[35]);a.composite=m,m===!1&&s.push("composite_cd_mismatch");let[f,g]=he(t.substring(5,36)),y=i.ok===!1&&i.warn===null||o===!1||u===!1;return Me(Ae(t.substring(0,2)),"TD2",t,{issuing_state:re(t),document_number:i.value,nni:"",birth_date:q(r.substring(13,19),!1,n),expiry_date:q(r.substring(21,27),!0,n),sex:xe(r[20]),nationality:P(r.substring(10,13)),surname:f,given_names:g},a,y,s)}function Ue(e,n){if(e.length<2)return F("mrz_incomplete");let[t,r]=j(e.slice(0,2),He,Ze),s=re(t)===pe,i=[],o={},u=r.substring(0,9),a=B(u,r[9]),m=B(r.substring(13,19),r[19]),f=B(r.substring(21,27),r[27]);if(o.document_number=a,o.birth_date=m,o.expiry_date=f,a===null||m===null||f===null)return F("mrz_incomplete");let g=r.substring(28,42),y="";if(P(g).length>0){let I=B(g,r[42]);o.personal_number=I;let h=P(g);s&&I!==!1&&ye.test(h)&&(y=h)}let b=B(r.substring(0,10)+r.substring(13,20)+r.substring(21,43),r[43]);o.composite=b,b===!1&&i.push("composite_cd_mismatch");let[d,l]=he(t.substring(5,44)),R=a===!1||m===!1||f===!1;return Me(Ae(t.substring(0,2)),"TD3",t,{issuing_state:re(t),document_number:P(u),nni_candidate:y,birth_date:q(r.substring(13,19),!1,n),expiry_date:q(r.substring(21,27),!0,n),sex:xe(r[20]),nationality:P(r.substring(10,13)),surname:d,given_names:l},o,R,i)}var Ge=new Set(["A","C","I"]),Bn=new Set(["R","T"]);function $e(e,n=$.today()){let t=e.filter(s=>s.trim().length>0);if(t.length===0)return F("mrz_unrecognized",0);let r=Array.from(ce(t[0]).slice(0,1),be).join("");return t.length===3&&(Ge.has(r)||Bn.has(r))?wn(t,n):t.length===2&&r==="P"?Ue(t,n):t.length===2&&Ge.has(r)?Math.max(...t.map(s=>ce(s).length))>40?Ue(t,n):Dn(t,n):F("mrz_unrecognized",t.length)}var Pn=new Map([...(`ABWAW AFGAF AGOAO AIAAI ALAAX ALBAL ANDAD AREAE ARGAR ARMAM ASMAS ATAAQ
|
|
14
|
+
ATFTF ATGAG AUSAU AUTAT AZEAZ BDIBI BELBE BENBJ BESBQ BFABF BGDBD BGRBG
|
|
15
|
+
BHRBH BHSBS BIHBA BLMBL BLRBY BLZBZ BMUBM BOLBO BRABR BRBBB BRNBN BTNBT
|
|
16
|
+
BVTBV BWABW CAFCF CANCA CCKCC CHECH CHLCL CHNCN CIVCI CMRCM CODCD COGCG
|
|
17
|
+
COKCK COLCO COMKM CPVCV CRICR CUBCU CUWCW CXRCX CYMKY CYPCY CZECZ DEUDE
|
|
18
|
+
DJIDJ DMADM DNKDK DOMDO DZADZ ECUEC EGYEG ERIER ESHEH ESPES ESTEE ETHET
|
|
19
|
+
FINFI FJIFJ FLKFK FRAFR FROFO FSMFM GABGA GBRGB GEOGE GGYGG GHAGH GIBGI
|
|
20
|
+
GINGN GLPGP GMBGM GNBGW GNQGQ GRCGR GRDGD GRLGL GTMGT GUFGF GUMGU GUYGY
|
|
21
|
+
HKGHK HMDHM HNDHN HRVHR HTIHT HUNHU IDNID IMNIM INDIN IOTIO IRLIE IRNIR
|
|
22
|
+
IRQIQ ISLIS ISRIL ITAIT JAMJM JEYJE JORJO JPNJP KAZKZ KENKE KGZKG KHMKH
|
|
23
|
+
KIRKI KNAKN KORKR KWTKW LAOLA LBNLB LBRLR LBYLY LCALC LIELI LKALK LSOLS
|
|
24
|
+
LTULT LUXLU LVALV MACMO MAFMF MARMA MCOMC MDAMD MDGMG MDVMV MEXMX MHLMH
|
|
25
|
+
MKDMK MLIML MLTMT MMRMM MNEME MNGMN MNPMP MOZMZ MRTMR MSRMS MTQMQ MUSMU
|
|
26
|
+
MWIMW MYSMY MYTYT NAMNA NCLNC NERNE NFKNF NGANG NICNI NIUNU NLDNL NORNO
|
|
27
|
+
NPLNP NRUNR NZLNZ OMNOM PAKPK PANPA PCNPN PERPE PHLPH PLWPW PNGPG POLPL
|
|
28
|
+
PRIPR PRKKP PRTPT PRYPY PSEPS PYFPF QATQA REURE ROURO RUSRU RWARW SAUSA
|
|
29
|
+
SDNSD SENSN SGPSG SGSGS SHNSH SJMSJ SLBSB SLESL SLVSV SMRSM SOMSO SPMPM
|
|
30
|
+
SRBRS SSDSS STPST SURSR SVKSK SVNSI SWESE SWZSZ SXMSX SYCSC SYRSY TCATC
|
|
31
|
+
TCDTD TGOTG THATH TJKTJ TKLTK TKMTM TLSTL TONTO TTOTT TUNTN TURTR TUVTV
|
|
32
|
+
TWNTW TZATZ UGAUG UKRUA UMIUM URYUY USAUS UZBUZ VATVA VCTVC VENVE VGBVG
|
|
33
|
+
VIRVI VNMVN VUTVU WLFWF WSMWS YEMYE ZAFZA ZMBZM ZWEZW`.match(/[A-Z]{5}/g)??[]).map(e=>[e.slice(0,3),e.slice(3)]),["D","DE"]]),Je={of(e){return Pn.get(e.replaceAll("<",""))??null}};var Ie=e=>de(e);function tn(e){return e.slice(0,5e4).split(/\r?\n/).slice(0,200).map(n=>n.toUpperCase().replace(/[«‹〈]/g,"<").replace(/[^A-Z0-9<]/g,"")).filter(n=>n.length>0)}var Qe=e=>e.replace(/[OQ]/g,"0").replace(/[IL]/g,"1").replaceAll("Z","2").replaceAll("S","5").replaceAll("B","8");function je(e,n){let t=Qe(e),r=Qe(n);if(!/^\d{6}$/.test(t)||Ie(t)!==r)return null;let s=2e3+Number(t.slice(0,2)),i=Number(t.slice(2,4)),o=Number(t.slice(4,6));return i>=1&&i<=12&&o>=1&&o<=new Date(Date.UTC(s,i,0)).getUTCDate()?t:null}function Re(e,n){let t=e.replace(/<+$/,"");return/^[A-Z0-9]+$/.test(t)&&Ie(e)===n?t:null}function vn(e){if(e.length<15)return null;if(e[14]!=="<")return Re(e.substring(5,14),e[14]);let n=/^([A-Z0-9]+)</.exec(e.substring(15,Math.min(30,e.length)))?.[1];return n===void 0||n.length<2?null:Re(e.substring(5,14)+n.slice(0,-1),n[n.length-1])}var x=(e,n,t)=>n>=e.length?"":e.substring(n,Math.min(t,e.length)),V=(e,n)=>n<e.length?e[n]:"",qe=/^[IAC][A-Z<][A-Z<]{3}/,kn=/^P[A-Z<][A-Z<]{3}/,rn=/^[PIAC][A-Z<][A-Z<]{3}/;function Un(e){let n=tn(e),t=[],r=[];for(let i=0;i<n.length;i++){let o="",u=0;for(;u<6&&i+u<n.length&&(o+=n[i+u],!(o.length>300));)r.push(o),u++}let s=(i,o,u)=>{if(o.length<(u?15:28))return;let a=new Map,m=u?vn(i):Re(x(o,0,9),V(o,9)),f=je(u?x(o,0,6):x(o,13,19),u?V(o,6):V(o,19)),g=je(u?x(o,8,14):x(o,21,27),u?V(o,14):V(o,27));m!==null&&a.set("docNumber",m),f!==null&&a.set("dob6",f),g!==null&&a.set("expiry6",g),a.size>0&&t.push({fields:a,country:Je.of(x(i,2,5))})};for(let i of r)qe.test(i)&&(i.length>=45&&s(i.substring(0,30),i.substring(30),!0),i.length>=64&&s(i.substring(0,36),i.substring(36),!1)),kn.test(i)&&i.length>=72&&s(i.substring(0,44),i.substring(44),!1);for(let i=0;i<n.length-1;i++){let o=n[i],u=n[i+1];qe.test(o)&&o.length>=15&&o.length<=30&&s(o,u,!0),rn.test(o)&&o.length>=5&&o.length<=44&&s(o,u,!1)}return t}function Gn(e){let n=Un(e);if(n.length===0)return{};let t=Math.max(...n.map(i=>i.fields.size)),r=n.filter(i=>i.fields.size===t),s={};for(let i of["docNumber","dob6","expiry6"]){let o=new Set(r.map(u=>u.fields.get(i)).filter(u=>u!==void 0));o.size===1&&r.every(u=>u.fields.has(i))&&(s[i]=[...o][0])}return s}function Fn(e){let n=Gn(e),t=n.docNumber,r=n.dob6,s=n.expiry6;return t!==void 0&&r!==void 0&&s!==void 0?{docNumber:t,dob6:r,expiry6:s}:null}function sn(e){let n=Hn(e);return n.length===1?n[0]:null}var Kn=e=>JSON.stringify([e.documentNumber,e.nationality,e.dob,e.sex,e.expiry,e.primaryIdentifier,e.secondaryIdentifier,e.optional]);function Hn(e){let n=tn(e),t=[];for(let s=0;s<n.length;s++){let i=n[s];if(!rn.test(i))continue;let o=i.startsWith("P")?[44]:[30,36];for(let u of o){let a=u===30?3:2,m=n.slice(s,Math.min(n.length,s+a));m.length===a&&m.every(y=>y.length<=u)&&t.push(m.map(y=>y.padEnd(u,"<")).join(`
|
|
34
|
+
`));let f="",g=0;for(;g<6&&s+g<n.length&&(f+=n[s+g],f.length===u*a&&t.push(f),!(f.length>=u*a));)g++}}let r=new Map;for(let s of t){let i=Fn(s);if(i===null)continue;let o=s.includes(`
|
|
35
|
+
`)?s.split(`
|
|
36
|
+
`):s.match(s.length===90?/.{30}/g:s.length===88?/.{44}/g:/.{36}/g)??[],u=o[0]??"",a=o[1]??"",m=o.length===3,f=m?x(u,5,30)+x(a,0,7)+x(a,8,15)+x(a,18,29):x(a,0,10)+x(a,13,20)+x(a,21,a.length-1),g=m?V(a,29):V(a,a.length-1);if(!/^[0-9]$/.test(g)||Ie(f)!==g)continue;let y=Wn(s);if(y===null||y.primaryIdentifier.length===0&&y.secondaryIdentifier.length===0||!/^[MFX]?$/.test(y.sex))continue;let b={...y,documentNumber:i.docNumber,dob:i.dob6,expiry:i.expiry6};r.set(Kn(b),{fields:b,mrzLines:o})}return[...r.values()]}var U=e=>e.replaceAll("<"," ").replace(/\s+/g," ").trim();function en(e){let n=e.split("<<");return[U(n[0]??""),U(n.slice(1).join("<<"))]}var nn=e=>e.length===0?null:e;function Wn(e){let n=e.split(/\r?\n/).map(r=>r.replace(/\s+$/,"")).filter(r=>r.length>0),t=e.replace(/[\r\n]/g,"");if(n.length===1&&(t.length===90?n=[t.substring(0,30),t.substring(30,60),t.substring(60,90)]:t.length===72?n=[t.substring(0,36),t.substring(36,72)]:t.length===88&&(n=[t.substring(0,44),t.substring(44,88)])),n.length===3){let[r,s,i]=n,o=V(r,14)==="<"?/^([A-Z0-9]+)</.exec(x(r,15,30))?.[1]:void 0,u=U(x(r,5,14)+(o!==void 0&&o.length>1?o.slice(0,-1):"")),[a,m]=en(i),f=U(`${x(r,15,30)}<${x(s,18,29)}`);return{documentNumber:u,nationality:U(x(s,15,18)),dob:x(s,0,6),sex:U(x(s,7,8)),expiry:x(s,8,14),primaryIdentifier:a,secondaryIdentifier:m,optional:nn(f)}}if(n.length===2){let[r,s]=n,i=r.length>=44,[o,u]=en(x(r,5,i?44:36));return{documentNumber:U(x(s,0,9)),nationality:U(x(s,10,13)),dob:x(s,13,19),sex:U(x(s,20,21)),expiry:x(s,21,27),primaryIdentifier:o,secondaryIdentifier:u,optional:nn(U(i?x(s,28,42):x(s,28,35)))}}return null}function on(e,n=$.today()){let t=$e(e,n),r=t.format??null,s=r==="TD1"||r==="TD2"||r==="TD3"?Ye(e,r):[...e];return{format:r,documentCode:t.documentCode??null,lines:s,valid:t.success&&!t.hardCdFail}}var zn=/^[A-Z0-9<]{25,}$/;function Vn(e){return e.toUpperCase().replaceAll(" ","").replaceAll("\xAB","<").replaceAll("\u2039","<")}var Se=(e,n,t)=>e.length>=n&&e.length<=t;function an(e){let n=e.map(Vn).filter(t=>zn.test(t));for(let t=0;t+3<=n.length;t++){let r=n.slice(t,t+3);if(r.every(s=>Se(s,28,32))&&"IAC".includes(r[0][0]))return r}for(let t=0;t+2<=n.length;t++){let r=n.slice(t,t+2);if(r.every(s=>Se(s,40,46))&&r[0].startsWith("P")||r.every(s=>Se(s,34,38))&&"IACPV".includes(r[0][0]))return r}return[]}var ee={SIZE:80,SCRIPT:64,OFFSET:68,STEPS:72},_={DETECTOR:0,LATIN:1,ARABIC:2},k={NONE:0,LATIN:1,ARABIC:2,BOTH:3},se=3;var Z=e=>Math.round(Math.min(1,Math.max(0,e))*1e4)/1e4;async function ln(e,n,t,r,s){let i=s.now??(()=>performance.now()),o=i(),a=e.read(n,t,r,s.region??[0,0,1,1],1,se,k.LATIN,s.detectorLimit).map(l=>({text:l.latin.text,score:l.latin.score,box:[0,1,2,3].map(R=>({x:l.box[2*R],y:l.box[2*R+1]}))})),m=ke([...a].reverse()),f=m.map(l=>l.text),g=[...sn(f.join(`
|
|
37
|
+
`))?.mrzLines??an(f)],y=m.map(l=>[Z(l.x/t),Z(l.y/r),Z((l.x2-l.x)/t),Z((l.y2-l.y)/r)]),b={kind:"band",ms:0,lineBoxes:y,lineCount:g.length,valid:!1},d=Yn(m.map(l=>l.text),y,g);if(d!==null&&(b.mrzBox=d),g.length>0){let l=on(g,s.today??$.today());l.format&&(b.format=l.format),l.documentCode&&/^[A-Z<]{1,2}$/.test(l.documentCode)&&(b.documentCode=l.documentCode),l.valid&&(b.valid=!0,b.digest=await _e(s.salt,l.lines))}return b.ms=Math.round(i()-o),b}var un=e=>e.toUpperCase().replace(/\s+/g,"");function Zn(e,n){let t=Math.max(e.length,n.length);if(t===0)return 0;let r=0;for(let s=0;s<Math.min(e.length,n.length);s++)e[s]===n[s]&&r++;return r/t}function Yn(e,n,t){if(t.length===0||e.length===0)return null;let r=new Set,s=[];for(let m of t){let f=-1,g=.5;if(e.forEach((y,b)=>{let d=r.has(b)?0:Zn(un(y),un(m));d>g&&(g=d,f=b)}),f<0)return null;r.add(f),s.push(n[f])}let i=Math.min(...s.map(m=>m[0])),o=Math.min(...s.map(m=>m[1])),u=Math.max(...s.map(m=>m[0]+m[2])),a=Math.max(...s.map(m=>m[1]+m[3]));return[Z(i),Z(o),Z(u-i),Z(a-o)]}async function Xn(e={}){var n,t=e,r=import.meta.url,s="",i,o;try{s=new URL(".",r).href}catch{}o=c=>{var A=new XMLHttpRequest;return A.open("GET",c,!1),A.responseType="arraybuffer",A.send(null),new Uint8Array(A.response)},i=async c=>{if(c=await fetch(c,{credentials:"same-origin"}),c.ok)return c.arrayBuffer();throw Error(c.status+" : "+c.url)};var u=console.log.bind(console),a=console.error.bind(console),m=!1,f,g,y,b,d,l=!1;function R(){var c=oe.buffer;new Int8Array(c),new Int16Array(c),t.HEAPU8=y=new Uint8Array(c),new Uint16Array(c),new Int32Array(c),b=new Uint32Array(c),new Float32Array(c),new Float64Array(c),d=new BigInt64Array(c),new BigUint64Array(c)}function I(c){throw c="Aborted("+c+")",a(c),m=!0,c+=". Build with -sASSERTIONS for more info.",l&&J(),c=new WebAssembly.RuntimeError(c),g?.(c),c}var h;async function L(c){try{var A=await i(c);return new Uint8Array(A)}catch{}if(o)c=o(c);else throw"both async and sync fetching of the wasm failed";return c}async function w(c,A){try{var p=await L(c);return await WebAssembly.instantiate(p,A)}catch(E){a(`failed to asynchronously prepare wasm: ${E}`),I(E)}}async function K(c){var A=h;try{var p=fetch(A,{credentials:"same-origin"});return await WebAssembly.instantiateStreaming(p,c)}catch(E){a(`wasm streaming compile failed: ${E}`),a("falling back to ArrayBuffer instantiation")}return w(A,c)}var H={},W=()=>{if(!Y){var c={USER:"web_user",LOGNAME:"web_user",PATH:"/",PWD:"/",HOME:"/home/web_user",LANG:(globalThis.navigator?.language??"C").replace("-","_")+".UTF-8",_:"./this.program"},A;for(A in H)H[A]===void 0?delete c[A]:c[A]=H[A];var p=[];for(A in c)p.push(`${A}=${c[A]}`);Y=p}return Y},Y,X=[null,[],[]],ie=globalThis.TextDecoder&&new TextDecoder,J,oe,gn={i:()=>I(""),b:function(c,A,p){return 0<=c&&3>=c?(d[p>>3]=BigInt(Math.round(1e6*(c===0?Date.now():performance.now()))),0):28},d:()=>1073741824,c:c=>{var A=y.length;if(c>>>=0,1073741824<c)return!1;for(var p=1;4>=p;p*=2){var E=A*(1+.2/p);E=Math.min(E,c+100663296);e:{E=(Math.min(1073741824,65536*Math.ceil(Math.max(c,E)/65536))-oe.buffer.byteLength+65535)/65536|0;try{oe.grow(E),R();var O=1;break e}catch{}O=void 0}if(O)return!0}return!1},f:(c,A)=>{var p=0,E=0,O;for(O of W()){var M=A+p;b[c+E>>2]=M;for(var Q=O,D=y,ne=M,G=M+1/0-1,N=0;N<Q.length;++N){var C=Q.codePointAt(N);if(127>=C){if(M>=G)break;D[M++]=C}else if(2047>=C){if(M+1>=G)break;D[M++]=192|C>>6,D[M++]=128|C&63}else if(65535>=C){if(M+2>=G)break;D[M++]=224|C>>12,D[M++]=128|C>>6&63,D[M++]=128|C&63}else{if(M+3>=G)break;D[M++]=240|C>>18,D[M++]=128|C>>12&63,D[M++]=128|C>>6&63,D[M++]=128|C&63,N++}}D[M]=0,Q=M-ne,p+=Q+1,E+=4}return 0},g:(c,A)=>{var p=W();b[c>>2]=p.length,c=0;for(var E of p){for(var O=p=0;O<E.length;++O){var M=E.charCodeAt(O);127>=M?p++:2047>=M?p+=2:55296<=M&&57343>=M?(p+=4,++O):p+=3}c+=p+1}return b[A>>2]=c,0},j:()=>52,h:()=>52,e:function(){return 70},a:(c,A,p,E)=>{for(var O=0,M=0;M<p;M++){var Q=b[A>>2],D=b[A+4>>2];A+=8;for(var ne=0;ne<D;ne++){var G=c,N=y[Q+ne],C=X[G];if(N===0||N===10){G=G===1?u:a,N=C;for(var z=0,te=N,v=z,T=v+void 0;te[v]&&!(v>=T);)++v;if(te=v,16<te-z&&N.buffer&&ie)N=ie.decode(N.subarray(z,te));else{for(v="";z<te;)if(T=N[z++],T&128){var fe=N[z++]&63;if((T&224)==192)v+=String.fromCharCode((T&31)<<6|fe);else{var Ee=N[z++]&63;T=(T&240)==224?(T&15)<<12|fe<<6|Ee:(T&7)<<18|fe<<12|Ee<<6|N[z++]&63,65536>T?v+=String.fromCharCode(T):(T-=65536,v+=String.fromCharCode(55296|T>>10,56320|T&1023))}}else v+=String.fromCharCode(T);N=v}G(N),C.length=0}else C.push(N)}O+=D}return b[E>>2]=O,0}},ae;return ae=await(async function(){function c(p){return p=ae=p.exports,t._skw_engine_id=p.m,t._skw_load=p.n,t._skw_unload=p.o,t._skw_set_detector_limit=p.p,t._skw_read=p.q,t._skw_line_count=p.r,t._skw_lines=p.s,t._skw_best=p.t,t._skw_values=p.u,t._skw_sharpness=p.v,t._free=p.w,t._malloc=p.x,J=p.y,oe=p.k,R(),ae}var A={a:gn};return t.instantiateWasm?new Promise(p=>{t.instantiateWasm(A,(E,O)=>{p(c(E,O))})}):(h??(h=t.locateFile?t.locateFile?t.locateFile("sekyro-ocr.wasm",s):s+"sekyro-ocr.wasm":new URL("sekyro-ocr.wasm",import.meta.url).href),c((await K(A)).instance))})(),t.calledRun=!0,m||(l=!0,ae.l(),f?.(t)),l?n=t:n=new Promise((c,A)=>{f=c,g=A}),n}var cn=Xn;function dn(e){return e===1||e===5?new S("OCR_IMAGE_INVALID"):e===2?new S("OCR_ASSET_INVALID"):e===4?new S("OCR_CANCELLED"):e===6?new S("OCR_BUSY"):e===7?new S("OCR_UNAVAILABLE"):new S("OCR_INFERENCE_FAILED")}var me=class{constructor(n){this.m=n;this.px=0;this.pxBytes=0;this.dicts=[null,null,null];this.classes=[0,0,0];this.held=[[],[],[]];this.latinKind="latin";this.scripts=[null,null,null]}engineId(){let n=this.m._skw_engine_id(),t="";for(let r=n;this.m.HEAPU8[r]!==0&&r<n+64;r++)t+=String.fromCharCode(this.m.HEAPU8[r]);return t}put(n){let t=this.m._malloc(n.length);if(!t)throw new S("OCR_UNAVAILABLE");return this.m.HEAPU8.set(n,t),t}load(n,t,r,s,i={}){this.unload(n);let o=new Uint8Array(t),u=new Uint8Array(o.byteLength+1);u.set(o);let a=null,m=0,f=null;if(i.mrz===!0){if(n!==_.LATIN||s===void 0||!Qn(s)||i.script!==void 0)throw new S("OCR_ASSET_INVALID");a=le(s),m=mn(s)}else if(n!==_.DETECTOR){if(f=i.script??(n===_.LATIN?ge:"arabic"),s===void 0||!De(f)||n===_.LATIN!=(f===ge))throw new S("OCR_ASSET_INVALID");m=Be(f).classes,a=Pe(s,m)}else if(s!==void 0||i.script!==void 0)throw new S("OCR_ASSET_INVALID");let g=new Uint8Array(r),y=this.put(u),b=this.put(g);this.held[n]=[y,b];let d=this.m._skw_load(n,y,u.length,b,g.byteLength,m);if(d!==0)throw this.unload(n),dn(d);this.dicts[n]=a,this.classes[n]=m,this.scripts[n]=f,n===_.LATIN&&(this.latinKind=i.mrz===!0?"mrz":"latin")}recognizer(){return this.loaded(_.LATIN)?this.latinKind:null}secondScript(){return this.loaded(_.ARABIC)?this.scripts[_.ARABIC]:null}unload(n){this.held[n].length&&this.m._skw_unload(n);for(let t of this.held[n])this.m._free(t);this.held[n]=[],this.dicts[n]=null,this.scripts[n]=null}loaded(n){return this.held[n].length>0}pixels(n){if(n.length>this.pxBytes){if(this.px&&this.m._free(this.px),this.px=this.m._malloc(n.length),!this.px)throw new S("OCR_UNAVAILABLE");this.pxBytes=n.length}return this.m.HEAPU8.set(n,this.px),this.px}sharpness(n,t,r){let s=this.m._skw_sharpness(this.pixels(n),t,r);return s>=0&&Number.isFinite(s)?s:null}read(n,t,r,s,i,o,u,a){if(!$n(u))throw new S("OCR_IMAGE_INVALID");if(u&k.LATIN&&!this.dicts[_.LATIN]||u&k.ARABIC&&!this.dicts[_.ARABIC]||!this.loaded(0))throw new S("OCR_UNAVAILABLE");let m=this.pixels(n);this.m._skw_set_detector_limit(a);let f=this.m._skw_read(m,t,r,s[0],s[1],s[2],s[3],i,o,u);if(f!==0)throw dn(f);let g=this.m._skw_line_count(),y=this.m.HEAPU8.buffer,b=new DataView(y,this.m._skw_lines(),g*ee.SIZE),d=new Int32Array(y,this.m._skw_best()),l=new Float32Array(y,this.m._skw_values()),R=[];for(let I=0;I<g;I++){let h=I*ee.SIZE,L=b.getInt32(h+ee.SCRIPT,!0),w=b.getInt32(h+ee.OFFSET,!0),K=b.getInt32(h+ee.STEPS,!0);if(u===k.NONE){R.push({box:Array.from({length:8},(ie,J)=>b.getFloat64(h+8*J,!0))});continue}let H=this.dicts[L];if(!H)throw new S("OCR_INFERENCE_FAILED");let W=we(d.subarray(w,w+K),l.subarray(w,w+K),this.classes[L],H,!1),Y=Array.from({length:8},(ie,J)=>b.getFloat64(h+8*J,!0)),X=R[R.length-1];L===_.ARABIC&&X&&X.arabic===void 0&&X.latin!==void 0&&Jn(X.box,Y)?X.arabic=W:R.push(L===_.ARABIC?{box:Y,arabic:W}:{box:Y,latin:W})}return R}heapBytes(){return this.m.HEAPU8.length}dispose(){for(let n of[0,1,2])this.unload(n);this.px&&this.m._free(this.px),this.px=0,this.pxBytes=0}};function mn(e){return(e.endsWith(`
|
|
38
|
+
`)?e.slice(0,-1):e).split(`
|
|
39
|
+
`).length+2}var $n=e=>Number.isInteger(e)&&e>=k.NONE&&e<=k.BOTH,Jn=(e,n)=>e.every((t,r)=>t===n[r]);function Qn(e){let n=e.split(`
|
|
40
|
+
`);return n.length===37&&new Set(n).size===37&&n.every(t=>/^[0-9A-Z<]$/.test(t))&&mn(e)===39}async function fn(e){let n=await cn({instantiateWasm:(t,r)=>(WebAssembly.instantiate(e,t).then(s=>r(s,e)),{})});return new me(n)}function jn(){let e=null,n=null;return(t,r)=>{if(typeof OffscreenCanvas!="function"||(e||(e=new OffscreenCanvas(t,r),n=e.getContext("2d",{willReadFrequently:!0})),!n))return null;(e.width!==t||e.height!==r)&&(e.width=t,e.height=r);let s=n;return{draw(i){return s.clearRect(0,0,t,r),s.drawImage(i,0,0),s.getImageData(0,0,t,r).data}}}}function qn(){return{fetch:(...e)=>fetch(...e),now:()=>performance.now(),canvas:jn(),instantiate:fn}}function et(e,n=qn()){let t=null,r="",s=960,i=0,o=!1,u=Promise.resolve(),a=d=>e.postMessage(d);async function m(d){if(n.canvas(1,1)===null)return a({id:d.id,kind:"failed",reason:"unsupported"});r=d.salt,s=d.detectorLimit;try{let l=await Le(d.baseUrl,Te,d.maxDownloadMs,n.fetch,n.now);i=l.downloadMs,o=l.cached;let R=await WebAssembly.compile(l.files.get("sekyro-ocr.wasm")),I=await n.instantiate(R),h=new TextDecoder("utf-8",{fatal:!0}).decode(l.files.get("mrz_dict.txt"));I.load(_.DETECTOR,l.files.get("det.param"),l.files.get("det.bin")),I.load(_.LATIN,l.files.get("mrz-rec.param"),l.files.get("mrz-rec.bin"),h,{mrz:!0}),l.files.clear(),t=I,a({id:d.id,kind:"ready",warmupMs:0,downloadMs:i,cached:o})}catch(l){a({id:d.id,kind:"failed",reason:l instanceof Oe?l.reason:"error"})}}async function f(d,l,R,I){if(!t)return l.close(),a({id:d,kind:"error",code:"not_ready"});let h=l.width,L=l.height,w=n.canvas(h,L);if(!w)return l.close(),a({id:d,kind:"failed",reason:"unsupported"});let K=w.draw(l);l.close();try{a({id:d,...await ln(t,K,h,L,{detectorLimit:I,salt:r,region:R,now:n.now})})}catch{a({id:d,kind:"error",code:"OCR_INFERENCE_FAILED"})}}async function g(d,l,R){if(!t)return l.close(),a({id:d,kind:"error",code:"not_ready"});let I=l.width,h=l.height,L=n.canvas(I,h);if(!L)return l.close(),a({id:d,kind:"failed",reason:"unsupported"});let w=L.draw(l);l.close();try{let K=n.now(),H=t.read(w,I,h,[0,0,1,1],1,se,k.NONE,R);a({id:d,kind:"layout",ms:Math.round(n.now()-K),lineBoxes:Ne(H.map(W=>W.box),I,h)})}catch{a({id:d,kind:"error",code:"OCR_INFERENCE_FAILED"})}}async function y(d){if(!t)return a({id:d,kind:"error",code:"not_ready"});let l=Ce(),R=()=>t.read(l.rgba,l.width,l.height,[0,0,1,1],1,se,k.LATIN,960),I,h;try{let L=n.now();R();let w=n.now();R(),I=Math.round(w-L),h=Math.round(n.now()-w)}catch{return a({id:d,kind:"error",code:"OCR_INFERENCE_FAILED"})}a({id:d,kind:"ready",warmupMs:I,benchMs:h,downloadMs:i,cached:o})}async function b(d){switch(d.kind){case"init":return m(d);case"warmup":return y(d.id);case"band":return f(d.id,d.bitmap,void 0,d.detectorLimit);case"still":return f(d.id,d.bitmap,d.region,d.detectorLimit);case"layout":return g(d.id,d.bitmap,d.detectorLimit);case"dispose":t?.dispose(),t=null,e.close();return}}e.onmessage=d=>{let l=d.data;u=u.then(()=>b(l)).catch(()=>a({id:l.id,kind:"error",code:"OCR_INFERENCE_FAILED"}))}}typeof WorkerGlobalScope<"u"&&typeof self<"u"&&self instanceof WorkerGlobalScope&&et(self);export{qn as defaultDeps,et as installOcrWorkerHost};
|
|
@@ -1,392 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
|
|
30
|
-
// src/core/v3/detect-worker.ts
|
|
31
|
-
var detect_worker_exports = {};
|
|
32
|
-
__export(detect_worker_exports, {
|
|
33
|
-
WORKER_PROTOCOL_VERSION: () => WORKER_PROTOCOL_VERSION,
|
|
34
|
-
WorkerDetectorProxy: () => WorkerDetectorProxy,
|
|
35
|
-
installWorkerDetectorHost: () => installWorkerDetectorHost,
|
|
36
|
-
workerOffloadSupported: () => workerOffloadSupported
|
|
37
|
-
});
|
|
38
|
-
module.exports = __toCommonJS(detect_worker_exports);
|
|
39
|
-
|
|
40
|
-
// src/core/v3/detector-blaze.ts
|
|
41
|
-
var BLAZE_INIT_TIMEOUT_MS = 1e4;
|
|
42
|
-
var BlazeDetector = class _BlazeDetector {
|
|
43
|
-
constructor(inner, fallbackReason) {
|
|
44
|
-
this.tier = "blaze";
|
|
45
|
-
this.inner = inner;
|
|
46
|
-
if (fallbackReason !== void 0) this.fallbackReason = fallbackReason;
|
|
47
|
-
}
|
|
48
|
-
static async create(assetBaseUrl, fallbackReason) {
|
|
49
|
-
const vision = await import("@mediapipe/tasks-vision");
|
|
50
|
-
const fileset = await vision.FilesetResolver.forVisionTasks(assetBaseUrl);
|
|
51
|
-
const inner = await vision.FaceDetector.createFromOptions(fileset, {
|
|
52
|
-
baseOptions: {
|
|
53
|
-
modelAssetPath: `${assetBaseUrl}/blaze_face_short_range.tflite`,
|
|
54
|
-
// CPU delegate — the iOS-Safari-safe path (see header). NEVER 'GPU'.
|
|
55
|
-
delegate: "CPU"
|
|
56
|
-
},
|
|
57
|
-
runningMode: "IMAGE"
|
|
58
|
-
});
|
|
59
|
-
return new _BlazeDetector(inner, fallbackReason);
|
|
60
|
-
}
|
|
61
|
-
async detect(source, sourceWidth, sourceHeight) {
|
|
62
|
-
let detections;
|
|
63
|
-
try {
|
|
64
|
-
detections = this.inner.detect(source).detections;
|
|
65
|
-
} catch {
|
|
66
|
-
return null;
|
|
67
|
-
}
|
|
68
|
-
const best = pickMostConfident(detections);
|
|
69
|
-
if (best?.boundingBox === void 0) return null;
|
|
70
|
-
const size = intrinsicSize(source);
|
|
71
|
-
const eyes = extractEyes(best.keypoints, size);
|
|
72
|
-
const observation = {
|
|
73
|
-
box: {
|
|
74
|
-
x: best.boundingBox.originX,
|
|
75
|
-
y: best.boundingBox.originY,
|
|
76
|
-
width: best.boundingBox.width,
|
|
77
|
-
height: best.boundingBox.height
|
|
78
|
-
},
|
|
79
|
-
...eyes !== void 0 ? { eyes } : {},
|
|
80
|
-
score: best.categories[0]?.score ?? 0
|
|
81
|
-
};
|
|
82
|
-
return toStreamPixels(observation, source, sourceWidth, sourceHeight);
|
|
83
|
-
}
|
|
84
|
-
destroy() {
|
|
85
|
-
try {
|
|
86
|
-
this.inner.close();
|
|
87
|
-
} catch {
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
};
|
|
91
|
-
function pickMostConfident(detections) {
|
|
92
|
-
let best;
|
|
93
|
-
let bestScore = -1;
|
|
94
|
-
for (const detection of detections) {
|
|
95
|
-
const score = detection.categories[0]?.score ?? 0;
|
|
96
|
-
if (score > bestScore) {
|
|
97
|
-
best = detection;
|
|
98
|
-
bestScore = score;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
return best;
|
|
102
|
-
}
|
|
103
|
-
function extractEyes(keypoints, size) {
|
|
104
|
-
const a = keypoints?.[0];
|
|
105
|
-
const b = keypoints?.[1];
|
|
106
|
-
if (a === void 0 || b === void 0) return void 0;
|
|
107
|
-
const toSource = (p) => ({ x: p.x * size.width, y: p.y * size.height });
|
|
108
|
-
const [pa, pb] = [toSource(a), toSource(b)];
|
|
109
|
-
return pa.x <= pb.x ? { left: pa, right: pb } : { left: pb, right: pa };
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
// src/core/v3/detector-native.ts
|
|
113
|
-
function smokeSource() {
|
|
114
|
-
if (typeof OffscreenCanvas === "function") return new OffscreenCanvas(2, 2);
|
|
115
|
-
const canvas = document.createElement("canvas");
|
|
116
|
-
canvas.width = 2;
|
|
117
|
-
canvas.height = 2;
|
|
118
|
-
return canvas;
|
|
119
|
-
}
|
|
120
|
-
async function probeNativeDetector() {
|
|
121
|
-
const ctor = globalThis.FaceDetector;
|
|
122
|
-
if (typeof ctor !== "function") return { ok: false, reason: "unsupported" };
|
|
123
|
-
try {
|
|
124
|
-
const instance = new ctor({ fastMode: true, maxDetectedFaces: 1 });
|
|
125
|
-
await instance.detect(smokeSource());
|
|
126
|
-
return { ok: true, instance };
|
|
127
|
-
} catch (err) {
|
|
128
|
-
return { ok: false, reason: `smoke_failed:${err instanceof Error ? err.message : String(err)}` };
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
var NativeDetector = class {
|
|
132
|
-
constructor(inner, fallbackReason) {
|
|
133
|
-
this.tier = "native";
|
|
134
|
-
this.inner = inner;
|
|
135
|
-
if (fallbackReason !== void 0) this.fallbackReason = fallbackReason;
|
|
136
|
-
}
|
|
137
|
-
async detect(source, sourceWidth, sourceHeight) {
|
|
138
|
-
let faces;
|
|
139
|
-
try {
|
|
140
|
-
faces = await this.inner.detect(source);
|
|
141
|
-
} catch {
|
|
142
|
-
return null;
|
|
143
|
-
}
|
|
144
|
-
const face = faces[0];
|
|
145
|
-
if (face === void 0) return null;
|
|
146
|
-
const eyes = extractEyes2(face.landmarks);
|
|
147
|
-
const observation = {
|
|
148
|
-
box: {
|
|
149
|
-
x: face.boundingBox.x,
|
|
150
|
-
y: face.boundingBox.y,
|
|
151
|
-
width: face.boundingBox.width,
|
|
152
|
-
height: face.boundingBox.height
|
|
153
|
-
},
|
|
154
|
-
...eyes !== void 0 ? { eyes } : {},
|
|
155
|
-
// The Shape Detection API exposes no confidence — the smoke-tested
|
|
156
|
-
// native tier treats any detection as confident.
|
|
157
|
-
score: 1
|
|
158
|
-
};
|
|
159
|
-
return toStreamPixels(observation, source, sourceWidth, sourceHeight);
|
|
160
|
-
}
|
|
161
|
-
destroy() {
|
|
162
|
-
}
|
|
163
|
-
};
|
|
164
|
-
function extractEyes2(landmarks) {
|
|
165
|
-
if (landmarks === void 0) return void 0;
|
|
166
|
-
const eyePoints = landmarks.filter((landmark) => landmark.type === "eye").map((landmark) => landmark.locations[0]).filter((point) => point !== void 0);
|
|
167
|
-
const [a, b] = eyePoints;
|
|
168
|
-
if (a === void 0 || b === void 0) return void 0;
|
|
169
|
-
return a.x <= b.x ? { left: a, right: b } : { left: b, right: a };
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
// src/core/v3/detector.ts
|
|
173
|
-
var DEFAULT_V3_ASSET_BASE_URL = "/models-v3";
|
|
174
|
-
var DEFAULT_TIER_ORDER = ["native", "blaze"];
|
|
175
|
-
var DetectorLadderError = class extends Error {
|
|
176
|
-
constructor(fallbackReason) {
|
|
177
|
-
super(`no detector tier available (${fallbackReason})`);
|
|
178
|
-
this.name = "DetectorLadderError";
|
|
179
|
-
this.fallbackReason = fallbackReason;
|
|
180
|
-
}
|
|
181
|
-
};
|
|
182
|
-
function intrinsicSize(source) {
|
|
183
|
-
const candidate = source;
|
|
184
|
-
if (typeof candidate.videoWidth === "number" && candidate.videoWidth > 0) {
|
|
185
|
-
return { width: candidate.videoWidth, height: candidate.videoHeight ?? 0 };
|
|
186
|
-
}
|
|
187
|
-
if (typeof candidate.naturalWidth === "number" && candidate.naturalWidth > 0) {
|
|
188
|
-
return { width: candidate.naturalWidth, height: candidate.naturalHeight ?? 0 };
|
|
189
|
-
}
|
|
190
|
-
const width = typeof candidate.width === "number" ? candidate.width : 0;
|
|
191
|
-
const height = typeof candidate.height === "number" ? candidate.height : 0;
|
|
192
|
-
return { width, height };
|
|
193
|
-
}
|
|
194
|
-
function toStreamPixels(observation, source, streamWidth, streamHeight) {
|
|
195
|
-
const size = intrinsicSize(source);
|
|
196
|
-
const scaleX = size.width > 0 ? streamWidth / size.width : 1;
|
|
197
|
-
const scaleY = size.height > 0 ? streamHeight / size.height : 1;
|
|
198
|
-
const scalePoint = (p) => ({ x: p.x * scaleX, y: p.y * scaleY });
|
|
199
|
-
return {
|
|
200
|
-
box: {
|
|
201
|
-
x: observation.box.x * scaleX,
|
|
202
|
-
y: observation.box.y * scaleY,
|
|
203
|
-
width: observation.box.width * scaleX,
|
|
204
|
-
height: observation.box.height * scaleY
|
|
205
|
-
},
|
|
206
|
-
...observation.eyes !== void 0 ? { eyes: { left: scalePoint(observation.eyes.left), right: scalePoint(observation.eyes.right) } } : {},
|
|
207
|
-
score: observation.score
|
|
208
|
-
};
|
|
209
|
-
}
|
|
210
|
-
function describeError(err) {
|
|
211
|
-
return err instanceof Error ? err.message : String(err);
|
|
212
|
-
}
|
|
213
|
-
async function createDetector(options) {
|
|
214
|
-
const order = options.preferred ?? DEFAULT_TIER_ORDER;
|
|
215
|
-
const reasons = [];
|
|
216
|
-
for (const tier of order) {
|
|
217
|
-
if (tier === "native") {
|
|
218
|
-
const probed = await probeNativeDetector();
|
|
219
|
-
if (probed.ok) {
|
|
220
|
-
return new NativeDetector(probed.instance, reasonOf(reasons));
|
|
221
|
-
}
|
|
222
|
-
reasons.push(`native:${probed.reason}`);
|
|
223
|
-
continue;
|
|
224
|
-
}
|
|
225
|
-
try {
|
|
226
|
-
return await withTimeout(
|
|
227
|
-
BlazeDetector.create(
|
|
228
|
-
options.v3AssetBaseUrl ?? DEFAULT_V3_ASSET_BASE_URL,
|
|
229
|
-
reasonOf(reasons)
|
|
230
|
-
),
|
|
231
|
-
options.blazeInitTimeoutMs ?? BLAZE_INIT_TIMEOUT_MS
|
|
232
|
-
);
|
|
233
|
-
} catch (err) {
|
|
234
|
-
reasons.push(
|
|
235
|
-
err instanceof InitTimeoutError ? "blaze:blaze_init_timeout" : `blaze:${describeError(err)}`
|
|
236
|
-
);
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
throw new DetectorLadderError(reasonOf(reasons) ?? "no_tier_available");
|
|
240
|
-
}
|
|
241
|
-
function reasonOf(reasons) {
|
|
242
|
-
return reasons.length > 0 ? reasons.join("; ") : void 0;
|
|
243
|
-
}
|
|
244
|
-
var InitTimeoutError = class extends Error {
|
|
245
|
-
};
|
|
246
|
-
function withTimeout(promise, deadlineMs) {
|
|
247
|
-
return new Promise((resolvePromise, rejectPromise) => {
|
|
248
|
-
const timer = setTimeout(() => {
|
|
249
|
-
rejectPromise(new InitTimeoutError(`init exceeded ${deadlineMs}ms`));
|
|
250
|
-
promise.then(
|
|
251
|
-
(value) => value.destroy(),
|
|
252
|
-
() => void 0
|
|
253
|
-
);
|
|
254
|
-
}, deadlineMs);
|
|
255
|
-
promise.then(
|
|
256
|
-
(value) => {
|
|
257
|
-
clearTimeout(timer);
|
|
258
|
-
resolvePromise(value);
|
|
259
|
-
},
|
|
260
|
-
(err) => {
|
|
261
|
-
clearTimeout(timer);
|
|
262
|
-
rejectPromise(err);
|
|
263
|
-
}
|
|
264
|
-
);
|
|
265
|
-
});
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
// src/core/v3/detect-worker.ts
|
|
269
|
-
var WORKER_PROTOCOL_VERSION = 1;
|
|
270
|
-
function workerOffloadSupported() {
|
|
271
|
-
return typeof OffscreenCanvas === "function" && typeof createImageBitmap === "function" && typeof Worker === "function";
|
|
272
|
-
}
|
|
273
|
-
function installWorkerDetectorHost(scope, deps = {}) {
|
|
274
|
-
const create = deps.createDetector ?? createDetector;
|
|
275
|
-
let detector = null;
|
|
276
|
-
scope.onmessage = (event) => {
|
|
277
|
-
const message = event.data;
|
|
278
|
-
if (message.v !== WORKER_PROTOCOL_VERSION) {
|
|
279
|
-
message.bitmap?.close?.();
|
|
280
|
-
return;
|
|
281
|
-
}
|
|
282
|
-
if (message.type === "init") {
|
|
283
|
-
void create(message.options).then((created) => {
|
|
284
|
-
detector = created;
|
|
285
|
-
const ready = {
|
|
286
|
-
v: WORKER_PROTOCOL_VERSION,
|
|
287
|
-
type: "ready",
|
|
288
|
-
tier: created.tier,
|
|
289
|
-
...created.fallbackReason !== void 0 ? { fallbackReason: created.fallbackReason } : {}
|
|
290
|
-
};
|
|
291
|
-
scope.postMessage(ready);
|
|
292
|
-
});
|
|
293
|
-
return;
|
|
294
|
-
}
|
|
295
|
-
if (message.type === "detect") {
|
|
296
|
-
const respond = (observation) => {
|
|
297
|
-
const result = {
|
|
298
|
-
v: WORKER_PROTOCOL_VERSION,
|
|
299
|
-
type: "result",
|
|
300
|
-
id: message.id,
|
|
301
|
-
observation
|
|
302
|
-
};
|
|
303
|
-
scope.postMessage(result);
|
|
304
|
-
message.bitmap.close?.();
|
|
305
|
-
};
|
|
306
|
-
if (detector === null) {
|
|
307
|
-
respond(null);
|
|
308
|
-
return;
|
|
309
|
-
}
|
|
310
|
-
void detector.detect(message.bitmap, message.streamWidth, message.streamHeight).then(respond, () => respond(null));
|
|
311
|
-
}
|
|
312
|
-
};
|
|
313
|
-
}
|
|
314
|
-
if (typeof self !== "undefined" && typeof self.importScripts === "function") {
|
|
315
|
-
installWorkerDetectorHost(self);
|
|
316
|
-
}
|
|
317
|
-
var WorkerDetectorProxy = class _WorkerDetectorProxy {
|
|
318
|
-
constructor(worker, ready) {
|
|
319
|
-
this.pending = /* @__PURE__ */ new Map();
|
|
320
|
-
this.nextId = 1;
|
|
321
|
-
this.worker = worker;
|
|
322
|
-
this.tier = ready.tier;
|
|
323
|
-
if (ready.fallbackReason !== void 0) this.fallbackReason = ready.fallbackReason;
|
|
324
|
-
worker.addEventListener("message", (event) => {
|
|
325
|
-
const message = event.data;
|
|
326
|
-
if (message.v !== WORKER_PROTOCOL_VERSION || message.type !== "result") return;
|
|
327
|
-
const resolve = this.pending.get(message.id);
|
|
328
|
-
this.pending.delete(message.id);
|
|
329
|
-
resolve?.(message.observation);
|
|
330
|
-
});
|
|
331
|
-
}
|
|
332
|
-
static create(worker, options, readyTimeoutMs = 1e4) {
|
|
333
|
-
return new Promise((resolve, reject) => {
|
|
334
|
-
const timer = setTimeout(() => {
|
|
335
|
-
worker.removeEventListener("message", onReady);
|
|
336
|
-
worker.terminate();
|
|
337
|
-
reject(new Error(`worker detector not ready within ${readyTimeoutMs}ms`));
|
|
338
|
-
}, readyTimeoutMs);
|
|
339
|
-
const onReady = (event) => {
|
|
340
|
-
const message = event.data;
|
|
341
|
-
if (message.v !== WORKER_PROTOCOL_VERSION || message.type !== "ready") return;
|
|
342
|
-
clearTimeout(timer);
|
|
343
|
-
worker.removeEventListener("message", onReady);
|
|
344
|
-
resolve(new _WorkerDetectorProxy(worker, message));
|
|
345
|
-
};
|
|
346
|
-
worker.addEventListener("message", onReady);
|
|
347
|
-
const init = { v: WORKER_PROTOCOL_VERSION, type: "init", options };
|
|
348
|
-
worker.postMessage(init);
|
|
349
|
-
});
|
|
350
|
-
}
|
|
351
|
-
async detect(source, sourceWidth, sourceHeight) {
|
|
352
|
-
let bitmap;
|
|
353
|
-
try {
|
|
354
|
-
if (typeof ImageBitmap !== "undefined" && source instanceof ImageBitmap) {
|
|
355
|
-
bitmap = source;
|
|
356
|
-
} else if (typeof createImageBitmap === "function") {
|
|
357
|
-
bitmap = await createImageBitmap(source);
|
|
358
|
-
} else {
|
|
359
|
-
bitmap = source;
|
|
360
|
-
}
|
|
361
|
-
} catch {
|
|
362
|
-
return null;
|
|
363
|
-
}
|
|
364
|
-
const id = this.nextId;
|
|
365
|
-
this.nextId += 1;
|
|
366
|
-
return new Promise((resolve) => {
|
|
367
|
-
this.pending.set(id, resolve);
|
|
368
|
-
const message = {
|
|
369
|
-
v: WORKER_PROTOCOL_VERSION,
|
|
370
|
-
type: "detect",
|
|
371
|
-
id,
|
|
372
|
-
bitmap,
|
|
373
|
-
streamWidth: sourceWidth,
|
|
374
|
-
streamHeight: sourceHeight
|
|
375
|
-
};
|
|
376
|
-
this.worker.postMessage(message, [bitmap]);
|
|
377
|
-
});
|
|
378
|
-
}
|
|
379
|
-
destroy() {
|
|
380
|
-
for (const resolve of this.pending.values()) resolve(null);
|
|
381
|
-
this.pending.clear();
|
|
382
|
-
this.worker.terminate();
|
|
383
|
-
}
|
|
384
|
-
};
|
|
385
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
386
|
-
0 && (module.exports = {
|
|
387
|
-
WORKER_PROTOCOL_VERSION,
|
|
388
|
-
WorkerDetectorProxy,
|
|
389
|
-
installWorkerDetectorHost,
|
|
390
|
-
workerOffloadSupported
|
|
391
|
-
});
|
|
392
|
-
//# sourceMappingURL=detect-worker.cjs.map
|
|
1
|
+
"use strict";var I=Object.create;var l=Object.defineProperty;var S=Object.getOwnPropertyDescriptor;var _=Object.getOwnPropertyNames;var M=Object.getPrototypeOf,L=Object.prototype.hasOwnProperty;var C=(t,e)=>{for(var r in e)l(t,r,{get:e[r],enumerable:!0})},O=(t,e,r,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of _(e))!L.call(t,n)&&n!==r&&l(t,n,{get:()=>e[n],enumerable:!(o=S(e,n))||o.enumerable});return t};var W=(t,e,r)=>(r=t!=null?I(M(t)):{},O(e||!t||!t.__esModule?l(r,"default",{value:t,enumerable:!0}):r,t)),B=t=>O(l({},"__esModule",{value:!0}),t);var Y={};C(Y,{WORKER_PROTOCOL_VERSION:()=>d,WorkerDetectorProxy:()=>w,installWorkerDetectorHost:()=>T,workerOffloadSupported:()=>G});module.exports=B(Y);var D=1e4,f=class t{constructor(e,r){this.tier="blaze";this.inner=e,r!==void 0&&(this.fallbackReason=r)}static async create(e,r){let o=await import("@mediapipe/tasks-vision"),n=await o.FilesetResolver.forVisionTasks(e),i=await o.FaceDetector.createFromOptions(n,{baseOptions:{modelAssetPath:`${e}/blaze_face_short_range.tflite`,delegate:"CPU"},runningMode:"IMAGE"});return new t(i,r)}async detect(e,r,o){let n;try{n=this.inner.detect(e).detections}catch{return null}let i=P(n);if(i?.boundingBox===void 0)return null;let a=v(e),s=N(i.keypoints,a),c=i.keypoints?.[2],m={box:{x:i.boundingBox.originX,y:i.boundingBox.originY,width:i.boundingBox.width,height:i.boundingBox.height},...s!==void 0?{eyes:s}:{},...c!==void 0?{nose:{x:c.x*a.width,y:c.y*a.height}}:{},score:i.categories[0]?.score??0,extraFaces:h(n.map(u=>u.boundingBox??{width:0,height:0}),n.indexOf(i))};return b(m,e,r,o)}destroy(){try{this.inner.close()}catch{}}};function P(t){let e,r=-1;for(let o of t){let n=o.categories[0]?.score??0;n>r&&(e=o,r=n)}return e}function N(t,e){let r=t?.[0],o=t?.[1];if(r===void 0||o===void 0)return;let n=s=>({x:s.x*e.width,y:s.y*e.height}),[i,a]=[n(r),n(o)];return i.x<=a.x?{left:i,right:a}:{left:a,right:i}}function A(){if(typeof OffscreenCanvas=="function")return new OffscreenCanvas(2,2);let t=document.createElement("canvas");return t.width=2,t.height=2,t}var V=4;async function F(){let t=globalThis.FaceDetector;if(typeof t!="function")return{ok:!1,reason:"unsupported"};try{let e=new t({fastMode:!0,maxDetectedFaces:V});return await e.detect(A()),{ok:!0,instance:e}}catch(e){return{ok:!1,reason:`smoke_failed:${e instanceof Error?e.message:String(e)}`}}}var g=class{constructor(e,r){this.tier="native";this.inner=e,r!==void 0&&(this.fallbackReason=r)}async detect(e,r,o){let n;try{n=await this.inner.detect(e)}catch{return null}let i=n.map(u=>u.boundingBox),a=-1;i.forEach((u,E)=>{let y=i[a];(y===void 0||u.width*u.height>y.width*y.height)&&(a=E)});let s=n[a];if(s===void 0)return null;let c=z(s.landmarks),m={box:{x:s.boundingBox.x,y:s.boundingBox.y,width:s.boundingBox.width,height:s.boundingBox.height},...c!==void 0?{eyes:c}:{},score:1,extraFaces:h(i,a)};return b(m,e,r,o)}destroy(){}};function z(t){if(t===void 0)return;let e=t.filter(n=>n.type==="eye").map(n=>n.locations[0]).filter(n=>n!==void 0),[r,o]=e;if(!(r===void 0||o===void 0))return r.x<=o.x?{left:r,right:o}:{left:o,right:r}}var H=.25;function h(t,e){let r=t[e],o=r===void 0?0:r.width*r.height;if(!(o>0))return 0;let n=0;return t.forEach((i,a)=>{a!==e&&i.width*i.height>=H*o&&(n+=1)}),n}var U="/models-v3",$=["native","blaze"],k=class extends Error{constructor(e){super(`no detector tier available (${e})`),this.name="DetectorLadderError",this.fallbackReason=e}};function v(t){let e=t;if(typeof e.videoWidth=="number"&&e.videoWidth>0)return{width:e.videoWidth,height:e.videoHeight??0};if(typeof e.naturalWidth=="number"&&e.naturalWidth>0)return{width:e.naturalWidth,height:e.naturalHeight??0};let r=typeof e.width=="number"?e.width:0,o=typeof e.height=="number"?e.height:0;return{width:r,height:o}}function b(t,e,r,o){let n=v(e),i=n.width>0?r/n.width:1,a=n.height>0?o/n.height:1,s=c=>({x:c.x*i,y:c.y*a});return{box:{x:t.box.x*i,y:t.box.y*a,width:t.box.width*i,height:t.box.height*a},...t.eyes!==void 0?{eyes:{left:s(t.eyes.left),right:s(t.eyes.right)}}:{},...t.nose!==void 0?{nose:s(t.nose)}:{},score:t.score,...t.extraFaces!==void 0?{extraFaces:t.extraFaces}:{}}}function K(t){return t instanceof Error?t.message:String(t)}async function R(t){let e=t.preferred??$,r=[];for(let o of e){if(o==="native"){let n=await F();if(n.ok)return new g(n.instance,x(r));r.push(`native:${n.reason}`);continue}try{return await X(f.create(t.v3AssetBaseUrl??U,x(r)),t.blazeInitTimeoutMs??D)}catch(n){r.push(n instanceof p?"blaze:blaze_init_timeout":`blaze:${K(n)}`)}}throw new k(x(r)??"no_tier_available")}function x(t){return t.length>0?t.join("; "):void 0}var p=class extends Error{};function X(t,e){return new Promise((r,o)=>{let n=setTimeout(()=>{o(new p(`init exceeded ${e}ms`)),t.then(i=>i.destroy(),()=>{})},e);t.then(i=>{clearTimeout(n),r(i)},i=>{clearTimeout(n),o(i)})})}var d=1;function G(){return typeof OffscreenCanvas=="function"&&typeof createImageBitmap=="function"&&typeof Worker=="function"}function T(t,e={}){let r=e.createDetector??R,o=null;t.onmessage=n=>{let i=n.data;if(i.v!==d){i.bitmap?.close?.();return}if(i.type==="init"){r(i.options).then(a=>{o=a;let s={v:d,type:"ready",tier:a.tier,...a.fallbackReason!==void 0?{fallbackReason:a.fallbackReason}:{}};t.postMessage(s)});return}if(i.type==="detect"){let a=s=>{let c={v:d,type:"result",id:i.id,observation:s};t.postMessage(c),i.bitmap.close?.()};if(o===null){a(null);return}o.detect(i.bitmap,i.streamWidth,i.streamHeight).then(a,()=>a(null))}}}typeof self<"u"&&typeof self.importScripts=="function"&&T(self);var w=class t{constructor(e,r){this.pending=new Map;this.nextId=1;this.worker=e,this.tier=r.tier,r.fallbackReason!==void 0&&(this.fallbackReason=r.fallbackReason),e.addEventListener("message",o=>{let n=o.data;if(n.v!==d||n.type!=="result")return;let i=this.pending.get(n.id);this.pending.delete(n.id),i?.(n.observation)})}static create(e,r,o=1e4){return new Promise((n,i)=>{let a=setTimeout(()=>{e.removeEventListener("message",s),e.terminate(),i(new Error(`worker detector not ready within ${o}ms`))},o),s=m=>{let u=m.data;u.v!==d||u.type!=="ready"||(clearTimeout(a),e.removeEventListener("message",s),n(new t(e,u)))};e.addEventListener("message",s);let c={v:d,type:"init",options:r};e.postMessage(c)})}async detect(e,r,o){let n;try{typeof ImageBitmap<"u"&&e instanceof ImageBitmap?n=e:typeof createImageBitmap=="function"?n=await createImageBitmap(e):n=e}catch{return null}let i=this.nextId;return this.nextId+=1,new Promise(a=>{this.pending.set(i,a);let s={v:d,type:"detect",id:i,bitmap:n,streamWidth:r,streamHeight:o};this.worker.postMessage(s,[n])})}destroy(){for(let e of this.pending.values())e(null);this.pending.clear(),this.worker.terminate()}};0&&(module.exports={WORKER_PROTOCOL_VERSION,WorkerDetectorProxy,installWorkerDetectorHost,workerOffloadSupported});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { f as WORKER_PROTOCOL_VERSION, g as WorkerDetectorProxy, W as WorkerLike, h as WorkerScopeLike, j as installWorkerDetectorHost, w as workerOffloadSupported } from '../../detect-worker-CHqsPJoM.cjs';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { f as WORKER_PROTOCOL_VERSION, g as WorkerDetectorProxy, W as WorkerLike, h as WorkerScopeLike, j as installWorkerDetectorHost, w as workerOffloadSupported } from '../../detect-worker-CHqsPJoM.js';
|
|
@@ -1,13 +1 @@
|
|
|
1
|
-
import {
|
|
2
|
-
WORKER_PROTOCOL_VERSION,
|
|
3
|
-
WorkerDetectorProxy,
|
|
4
|
-
installWorkerDetectorHost,
|
|
5
|
-
workerOffloadSupported
|
|
6
|
-
} from "../../chunk-NWF46H7K.js";
|
|
7
|
-
export {
|
|
8
|
-
WORKER_PROTOCOL_VERSION,
|
|
9
|
-
WorkerDetectorProxy,
|
|
10
|
-
installWorkerDetectorHost,
|
|
11
|
-
workerOffloadSupported
|
|
12
|
-
};
|
|
13
|
-
//# sourceMappingURL=detect-worker.js.map
|
|
1
|
+
import{i as a,j as b,k as c,l as d}from"../../chunk-FSSMUAKC.js";export{a as WORKER_PROTOCOL_VERSION,d as WorkerDetectorProxy,c as installWorkerDetectorHost,b as workerOffloadSupported};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{u as a,v as b,w as c,x as d,y as e}from"./chunk-4NO6MQPH.js";import"./chunk-MQHTFHSN.js";import"./chunk-BRLQIJYF.js";import"./chunk-BPAGOPYL.js";import"./chunk-7QZWBDI5.js";import"./chunk-FYU7J2DC.js";import"./chunk-SX7TUC3V.js";import"./chunk-W357WDNU.js";import"./chunk-POIQGEZM.js";import"./chunk-CPUECYAJ.js";import"./chunk-FPXL63KZ.js";import"./chunk-U5TL63CG.js";import"./chunk-TSA6GHUG.js";import"./chunk-22AW4NJD.js";import"./chunk-FSSMUAKC.js";import"./chunk-WNBEOK5Q.js";export{b as BARCODE_BUDGET_MS,a as SAME_FACE_MAX_DROPS,d as createDocumentCapture,e as createDocumentCaptureInternal,c as warmDocumentCapture};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{j as a,k as b,l as c,m as d,n as e,o as f}from"./chunk-VWGKUQ3C.js";import"./chunk-53POX7U4.js";import"./chunk-33KKMPJ5.js";import"./chunk-CJHMFPL6.js";import"./chunk-RI3E7GBN.js";import"./chunk-GI3UFGRQ.js";import"./chunk-7QZWBDI5.js";import"./chunk-SX7TUC3V.js";import"./chunk-CPUECYAJ.js";import"./chunk-TSA6GHUG.js";export{a as ANALYSIS_LONG_EDGE,b as PORTRAIT_JPEG_QUALITY,e as createPortraitCaptureInternal,c as defaultGrabber,d as observe,f as warmPortraitCapture};
|