kordoc 4.24.65 → 4.24.66
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/README.md +4 -4
- package/dist/{-3Q26OZHW.js → -F525UPLU.js} +21 -21
- package/dist/{chunk-VQZIP2UW.js → chunk-2XL56JBH.js} +10 -10
- package/dist/{chunk-7DQI7BU6.js → chunk-3UBJILCL.js} +2 -2
- package/dist/{chunk-NBBT2EYG.js → chunk-4AQEYIQ3.js} +2 -2
- package/dist/{chunk-Y6UT3AYV.js → chunk-4UU2SHSY.js} +35 -8
- package/dist/chunk-4UU2SHSY.js.map +1 -0
- package/dist/{chunk-S5XPBZQ6.cjs → chunk-64EE67KV.cjs} +3 -3
- package/dist/{chunk-S5XPBZQ6.cjs.map → chunk-64EE67KV.cjs.map} +1 -1
- package/dist/{chunk-3Z7WJCP2.js → chunk-6I5IGEH5.js} +2 -2
- package/dist/{chunk-UYEZER77.js → chunk-727NQOEV.js} +2 -2
- package/dist/{chunk-PWSUGKMS.js → chunk-7VOBRIAX.js} +2 -2
- package/dist/{chunk-FTMDZ4Y5.js → chunk-ADVM2BSC.js} +3 -3
- package/dist/{chunk-JW6PNIXI.js → chunk-AKHGU46M.js} +7 -7
- package/dist/{chunk-VMR3QMB5.js → chunk-AQ2MNHLW.js} +58 -13
- package/dist/chunk-AQ2MNHLW.js.map +1 -0
- package/dist/{chunk-RH6E2YVG.js → chunk-CFQG5H5S.js} +2 -2
- package/dist/{chunk-6R4M2LVY.js → chunk-CNM5LSE2.js} +2 -2
- package/dist/{chunk-BYTIJ226.js → chunk-DQAHD7AV.js} +2 -2
- package/dist/{chunk-AX34AL6K.js → chunk-E3MKUDIV.js} +2 -2
- package/dist/{chunk-LXRBEPYC.js → chunk-EKLKGFW3.js} +2 -2
- package/dist/{chunk-AKYUE4JE.js → chunk-JDLRNVPW.js} +2 -2
- package/dist/{chunk-B4AKPVWA.cjs → chunk-JMCNY622.cjs} +142 -97
- package/dist/chunk-JMCNY622.cjs.map +1 -0
- package/dist/{chunk-NTMN5UKQ.js → chunk-JTBGDI7W.js} +34 -7
- package/dist/chunk-JTBGDI7W.js.map +1 -0
- package/dist/{chunk-GITPHKYL.cjs → chunk-JWPSOXBE.cjs} +8 -8
- package/dist/{chunk-GITPHKYL.cjs.map → chunk-JWPSOXBE.cjs.map} +1 -1
- package/dist/{chunk-UJI2ZP6M.cjs → chunk-MJBGYWZE.cjs} +104 -104
- package/dist/{chunk-UJI2ZP6M.cjs.map → chunk-MJBGYWZE.cjs.map} +1 -1
- package/dist/{chunk-TN2C7M6Q.js → chunk-NHTQRDJ6.js} +11 -11
- package/dist/{chunk-EG47QXJE.js → chunk-O62APXCV.js} +5 -5
- package/dist/{chunk-3JHKWOVZ.js → chunk-PHWKC6UC.js} +57 -12
- package/dist/chunk-PHWKC6UC.js.map +1 -0
- package/dist/{chunk-ZMJVWAH2.cjs → chunk-QN6WSJVU.cjs} +58 -58
- package/dist/{chunk-ZMJVWAH2.cjs.map → chunk-QN6WSJVU.cjs.map} +1 -1
- package/dist/{chunk-BRDRZHVC.js → chunk-QPEOOQV5.js} +2 -2
- package/dist/{chunk-U2TSYPPM.js → chunk-R4JIQ5TC.js} +2 -2
- package/dist/{chunk-27ZUZMQY.js → chunk-RDNYND2I.js} +5 -5
- package/dist/{chunk-MTUGM4ZK.js → chunk-RN46L3AU.js} +6 -6
- package/dist/{chunk-ABA2Z4LT.js → chunk-RXE7BWTU.js} +2 -2
- package/dist/{chunk-DQQ6C7WA.js → chunk-S2KMYEFM.js} +2 -2
- package/dist/{chunk-DKSSS4ED.js → chunk-S532VXZW.js} +2 -2
- package/dist/{chunk-TYJFA5S7.js → chunk-SMPW433I.js} +2 -2
- package/dist/{chunk-CLI5IIY3.js → chunk-THKLA33K.js} +2 -2
- package/dist/{chunk-GZC4XIKW.js → chunk-TLN3QVS3.js} +5 -5
- package/dist/{chunk-I2HHHJF5.js → chunk-TW7LJ4CT.js} +2 -2
- package/dist/{chunk-XS254L5R.js → chunk-U5BSGXWG.js} +3 -3
- package/dist/{chunk-BPNJBWKQ.js → chunk-V5AGFLMV.js} +15 -15
- package/dist/{chunk-7PTPUYYJ.js → chunk-VUVENRQF.js} +3 -3
- package/dist/{chunk-B4ZNG3G7.cjs → chunk-WD5KO2FI.cjs} +203 -176
- package/dist/chunk-WD5KO2FI.cjs.map +1 -0
- package/dist/{chunk-4T4Y2WRR.cjs → chunk-WL6FHOXS.cjs} +2 -2
- package/dist/{chunk-4T4Y2WRR.cjs.map → chunk-WL6FHOXS.cjs.map} +1 -1
- package/dist/{chunk-KUAPGGQE.js → chunk-X2JWEVBD.js} +6 -6
- package/dist/{chunk-6J5RTSBG.cjs → chunk-ZLZ3XYNR.cjs} +3 -3
- package/dist/{chunk-6J5RTSBG.cjs.map → chunk-ZLZ3XYNR.cjs.map} +1 -1
- package/dist/chunks-4IEOCUKM.js +11 -0
- package/dist/cli.js +45 -45
- package/dist/{formula-WDYM2TBT.js → formula-DNEIS4K3.js} +3 -3
- package/dist/{formula-HNVGC323.cjs → formula-HKMKULZI.cjs} +9 -9
- package/dist/{formula-HNVGC323.cjs.map → formula-HKMKULZI.cjs.map} +1 -1
- package/dist/{formula-N6HZBMYV.js → formula-Z6MQKJK4.js} +4 -4
- package/dist/generator-54YDTC4H.js +11 -0
- package/dist/generator-LGPN5WJF.cjs +12 -0
- package/dist/{generator-GJID5Q4V.cjs.map → generator-LGPN5WJF.cjs.map} +1 -1
- package/dist/generator-ZECPB7JM.js +18 -0
- package/dist/{hancom-Y4QJMNTG.cjs → hancom-DYJIMXYD.cjs} +5 -5
- package/dist/{hancom-Y4QJMNTG.cjs.map → hancom-DYJIMXYD.cjs.map} +1 -1
- package/dist/{hancom-TJ2T5WD7.js → hancom-EKGYO3DR.js} +2 -2
- package/dist/{hancom-XNW5F3S5.js → hancom-UA3FAKPN.js} +2 -2
- package/dist/{image-ocr-HXQV325C.js → image-ocr-AEJC2HYX.js} +7 -7
- package/dist/{image-ocr-2P6OUO7R.cjs → image-ocr-PZ2U43B5.cjs} +28 -28
- package/dist/{image-ocr-2P6OUO7R.cjs.map → image-ocr-PZ2U43B5.cjs.map} +1 -1
- package/dist/{image-ocr-EEI3UA36.js → image-ocr-V5ULS7PL.js} +10 -10
- package/dist/index.cjs +1115 -1115
- package/dist/index.js +9 -9
- package/dist/mcp.js +36 -36
- package/dist/memo-WGP7QJ7M.js +17 -0
- package/dist/{model-bundle-QMXOK6ML.js → model-bundle-OYH3ZTJK.js} +5 -5
- package/dist/{models-VRTWSRWY.js → models-52726NXY.js} +5 -5
- package/dist/{parse-worker-v2-4YEQVFDN.js → parse-worker-v2-5C3VXRFT.js} +22 -22
- package/dist/{parser-4FZWTV4P.js → parser-4EIBYZUS.js} +12 -12
- package/dist/{parser-6ZIQHTU7.js → parser-L55CW5GW.js} +9 -9
- package/dist/{parser-5X3O5FMI.cjs → parser-Y3F7ULSO.cjs} +166 -166
- package/dist/{parser-5X3O5FMI.cjs.map → parser-Y3F7ULSO.cjs.map} +1 -1
- package/dist/{pdf-ocr-HHWYGVYA.js → pdf-ocr-4XG2GDWK.js} +9 -9
- package/dist/pdf-ocr-6DDEOYWS.cjs +43 -0
- package/dist/{pdf-ocr-47CN4L3H.cjs.map → pdf-ocr-6DDEOYWS.cjs.map} +1 -1
- package/dist/{pdf-ocr-TIYXB6UN.js → pdf-ocr-DO3GQSVO.js} +6 -6
- package/dist/{profile-io-6FHN5UEA.js → profile-io-J4BGPXD6.js} +3 -3
- package/dist/{rasterize-JFBYSQSV.js → rasterize-2BD3ST5L.js} +3 -3
- package/dist/{redact-doc-PYL7KZBW.js → redact-doc-T5ZO5BUF.js} +21 -21
- package/dist/{render-6V2YIVO3.js → render-XHAEGFDS.js} +12 -12
- package/dist/{rewrite-fallback-53SOLUTC.js → rewrite-fallback-GDC6ISST.js} +13 -13
- package/dist/seal-DDP5FWKY.js +16 -0
- package/dist/{setup-LFIDDDUO.js → setup-JAH3DJMB.js} +3 -3
- package/dist/to-hwpx-CBFKBA26.cjs +16 -0
- package/dist/{to-hwpx-SNIR5XQE.cjs.map → to-hwpx-CBFKBA26.cjs.map} +1 -1
- package/dist/{to-hwpx-PVXV4MP3.js → to-hwpx-FU5MRESY.js} +7 -7
- package/dist/{to-hwpx-VPIDINZP.js → to-hwpx-HQLTHIOW.js} +4 -4
- package/dist/visual-TYA7MDHZ.js +38 -0
- package/dist/{watch-RDE5VTIX.js → watch-52TBPFGB.js} +22 -22
- package/package.json +1 -1
- package/dist/chunk-3JHKWOVZ.js.map +0 -1
- package/dist/chunk-B4AKPVWA.cjs.map +0 -1
- package/dist/chunk-B4ZNG3G7.cjs.map +0 -1
- package/dist/chunk-NTMN5UKQ.js.map +0 -1
- package/dist/chunk-VMR3QMB5.js.map +0 -1
- package/dist/chunk-Y6UT3AYV.js.map +0 -1
- package/dist/chunks-LAMEBTHT.js +0 -11
- package/dist/generator-GJID5Q4V.cjs +0 -12
- package/dist/generator-LGSVRPVO.js +0 -11
- package/dist/generator-QQTCTEMZ.js +0 -18
- package/dist/memo-JYBL4KYT.js +0 -17
- package/dist/pdf-ocr-47CN4L3H.cjs +0 -43
- package/dist/seal-KRIMAC4M.js +0 -16
- package/dist/to-hwpx-SNIR5XQE.cjs +0 -16
- package/dist/visual-HKD7SS2K.js +0 -38
- /package/dist/{-3Q26OZHW.js.map → -F525UPLU.js.map} +0 -0
- /package/dist/{chunk-VQZIP2UW.js.map → chunk-2XL56JBH.js.map} +0 -0
- /package/dist/{chunk-7DQI7BU6.js.map → chunk-3UBJILCL.js.map} +0 -0
- /package/dist/{chunk-NBBT2EYG.js.map → chunk-4AQEYIQ3.js.map} +0 -0
- /package/dist/{chunk-3Z7WJCP2.js.map → chunk-6I5IGEH5.js.map} +0 -0
- /package/dist/{chunk-UYEZER77.js.map → chunk-727NQOEV.js.map} +0 -0
- /package/dist/{chunk-PWSUGKMS.js.map → chunk-7VOBRIAX.js.map} +0 -0
- /package/dist/{chunk-FTMDZ4Y5.js.map → chunk-ADVM2BSC.js.map} +0 -0
- /package/dist/{chunk-JW6PNIXI.js.map → chunk-AKHGU46M.js.map} +0 -0
- /package/dist/{chunk-RH6E2YVG.js.map → chunk-CFQG5H5S.js.map} +0 -0
- /package/dist/{chunk-6R4M2LVY.js.map → chunk-CNM5LSE2.js.map} +0 -0
- /package/dist/{chunk-BYTIJ226.js.map → chunk-DQAHD7AV.js.map} +0 -0
- /package/dist/{chunk-AX34AL6K.js.map → chunk-E3MKUDIV.js.map} +0 -0
- /package/dist/{chunk-LXRBEPYC.js.map → chunk-EKLKGFW3.js.map} +0 -0
- /package/dist/{chunk-AKYUE4JE.js.map → chunk-JDLRNVPW.js.map} +0 -0
- /package/dist/{chunk-TN2C7M6Q.js.map → chunk-NHTQRDJ6.js.map} +0 -0
- /package/dist/{chunk-EG47QXJE.js.map → chunk-O62APXCV.js.map} +0 -0
- /package/dist/{chunk-BRDRZHVC.js.map → chunk-QPEOOQV5.js.map} +0 -0
- /package/dist/{chunk-U2TSYPPM.js.map → chunk-R4JIQ5TC.js.map} +0 -0
- /package/dist/{chunk-27ZUZMQY.js.map → chunk-RDNYND2I.js.map} +0 -0
- /package/dist/{chunk-MTUGM4ZK.js.map → chunk-RN46L3AU.js.map} +0 -0
- /package/dist/{chunk-ABA2Z4LT.js.map → chunk-RXE7BWTU.js.map} +0 -0
- /package/dist/{chunk-DQQ6C7WA.js.map → chunk-S2KMYEFM.js.map} +0 -0
- /package/dist/{chunk-DKSSS4ED.js.map → chunk-S532VXZW.js.map} +0 -0
- /package/dist/{chunk-TYJFA5S7.js.map → chunk-SMPW433I.js.map} +0 -0
- /package/dist/{chunk-CLI5IIY3.js.map → chunk-THKLA33K.js.map} +0 -0
- /package/dist/{chunk-GZC4XIKW.js.map → chunk-TLN3QVS3.js.map} +0 -0
- /package/dist/{chunk-I2HHHJF5.js.map → chunk-TW7LJ4CT.js.map} +0 -0
- /package/dist/{chunk-XS254L5R.js.map → chunk-U5BSGXWG.js.map} +0 -0
- /package/dist/{chunk-BPNJBWKQ.js.map → chunk-V5AGFLMV.js.map} +0 -0
- /package/dist/{chunk-7PTPUYYJ.js.map → chunk-VUVENRQF.js.map} +0 -0
- /package/dist/{chunk-KUAPGGQE.js.map → chunk-X2JWEVBD.js.map} +0 -0
- /package/dist/{chunks-LAMEBTHT.js.map → chunks-4IEOCUKM.js.map} +0 -0
- /package/dist/{formula-WDYM2TBT.js.map → formula-DNEIS4K3.js.map} +0 -0
- /package/dist/{formula-N6HZBMYV.js.map → formula-Z6MQKJK4.js.map} +0 -0
- /package/dist/{generator-LGSVRPVO.js.map → generator-54YDTC4H.js.map} +0 -0
- /package/dist/{generator-QQTCTEMZ.js.map → generator-ZECPB7JM.js.map} +0 -0
- /package/dist/{hancom-TJ2T5WD7.js.map → hancom-EKGYO3DR.js.map} +0 -0
- /package/dist/{hancom-XNW5F3S5.js.map → hancom-UA3FAKPN.js.map} +0 -0
- /package/dist/{image-ocr-HXQV325C.js.map → image-ocr-AEJC2HYX.js.map} +0 -0
- /package/dist/{image-ocr-EEI3UA36.js.map → image-ocr-V5ULS7PL.js.map} +0 -0
- /package/dist/{memo-JYBL4KYT.js.map → memo-WGP7QJ7M.js.map} +0 -0
- /package/dist/{model-bundle-QMXOK6ML.js.map → model-bundle-OYH3ZTJK.js.map} +0 -0
- /package/dist/{models-VRTWSRWY.js.map → models-52726NXY.js.map} +0 -0
- /package/dist/{parse-worker-v2-4YEQVFDN.js.map → parse-worker-v2-5C3VXRFT.js.map} +0 -0
- /package/dist/{parser-4FZWTV4P.js.map → parser-4EIBYZUS.js.map} +0 -0
- /package/dist/{parser-6ZIQHTU7.js.map → parser-L55CW5GW.js.map} +0 -0
- /package/dist/{pdf-ocr-HHWYGVYA.js.map → pdf-ocr-4XG2GDWK.js.map} +0 -0
- /package/dist/{pdf-ocr-TIYXB6UN.js.map → pdf-ocr-DO3GQSVO.js.map} +0 -0
- /package/dist/{profile-io-6FHN5UEA.js.map → profile-io-J4BGPXD6.js.map} +0 -0
- /package/dist/{rasterize-JFBYSQSV.js.map → rasterize-2BD3ST5L.js.map} +0 -0
- /package/dist/{redact-doc-PYL7KZBW.js.map → redact-doc-T5ZO5BUF.js.map} +0 -0
- /package/dist/{render-6V2YIVO3.js.map → render-XHAEGFDS.js.map} +0 -0
- /package/dist/{rewrite-fallback-53SOLUTC.js.map → rewrite-fallback-GDC6ISST.js.map} +0 -0
- /package/dist/{seal-KRIMAC4M.js.map → seal-DDP5FWKY.js.map} +0 -0
- /package/dist/{setup-LFIDDDUO.js.map → setup-JAH3DJMB.js.map} +0 -0
- /package/dist/{to-hwpx-PVXV4MP3.js.map → to-hwpx-FU5MRESY.js.map} +0 -0
- /package/dist/{to-hwpx-VPIDINZP.js.map → to-hwpx-HQLTHIOW.js.map} +0 -0
- /package/dist/{visual-HKD7SS2K.js.map → visual-TYA7MDHZ.js.map} +0 -0
- /package/dist/{watch-RDE5VTIX.js.map → watch-52TBPFGB.js.map} +0 -0
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
|
|
38
38
|
|
|
39
39
|
|
|
40
|
-
var
|
|
40
|
+
var _chunkWD5KO2FIcjs = require('./chunk-WD5KO2FI.cjs');
|
|
41
41
|
|
|
42
42
|
|
|
43
43
|
var _chunkMMK32GPDcjs = require('./chunk-MMK32GPD.cjs');
|
|
@@ -50,7 +50,7 @@ var _chunk64H2FCYFcjs = require('./chunk-64H2FCYF.cjs');
|
|
|
50
50
|
|
|
51
51
|
|
|
52
52
|
|
|
53
|
-
var
|
|
53
|
+
var _chunkWL6FHOXScjs = require('./chunk-WL6FHOXS.cjs');
|
|
54
54
|
|
|
55
55
|
// src/ocr/ocr-stacked-rows.ts
|
|
56
56
|
var NUMERIC = /^[-+−△▲▽▼]?[\d.,]+[%p원]?$|^[-–—·∼~]원?$|^\([-+−△▲▽▼]?[\d.,]+%?\)$/;
|
|
@@ -428,7 +428,46 @@ function detectRulingLines(rgba, width, height, scale) {
|
|
|
428
428
|
};
|
|
429
429
|
const dotted = (m, base, step, span) => dottedRuns(m, base, step, span, minLenPx, dot.maxGap, dot.maxDash, dot.maxPeriod);
|
|
430
430
|
const horizontals = detectBands(ink, width, height, maxThickPx, false, solid);
|
|
431
|
+
const filledAt = (x, h) => {
|
|
432
|
+
const yt = Math.round(h.y1 - h.thicknessPx / 2) - 2, yb = Math.round(h.y1 + h.thicknessPx / 2) + 2;
|
|
433
|
+
return yt >= 0 && yb < height && ink[yt * width + x] === 1 && ink[yb * width + x] === 1;
|
|
434
|
+
};
|
|
435
|
+
const trimFilled = (h) => {
|
|
436
|
+
let x1 = Math.round(h.x1), x2 = Math.round(h.x2);
|
|
437
|
+
while (x1 < x2 && filledAt(x1, h)) x1++;
|
|
438
|
+
while (x2 > x1 && filledAt(x2, h)) x2--;
|
|
439
|
+
return x2 - x1 + 1 >= minLenPx ? { ...h, x1, x2, isolated: true } : null;
|
|
440
|
+
};
|
|
441
|
+
const hAdd = detectBands(ink, width, height, maxThickPx, false, solid, true).map(trimFilled).filter((h) => h !== null).filter((h) => !horizontals.some((p) => Math.abs(p.y1 - h.y1) <= maxThickPx && Math.min(p.x2, h.x2) - Math.max(p.x1, h.x1) > (h.x2 - h.x1) * 0.5));
|
|
442
|
+
const baseH = horizontals.length;
|
|
443
|
+
horizontals.push(...hAdd);
|
|
431
444
|
const verticals = detectBands(ink, width, height, maxThickPx, true, solid);
|
|
445
|
+
const faint = (x, y) => {
|
|
446
|
+
const l = luma[y * width + x];
|
|
447
|
+
return l > INK_LUMA_MAX && l <= 230 && x >= 3 && x + 3 < width && l + 20 <= Math.min(luma[y * width + x - 3], luma[y * width + x + 3]);
|
|
448
|
+
};
|
|
449
|
+
for (const v of verticals) {
|
|
450
|
+
const xs = [Math.round(v.x1) - 1, Math.round(v.x1), Math.round(v.x1) + 1];
|
|
451
|
+
const cross = (y) => xs.some((x) => x >= 3 && x + 3 < width && luma[y * width + x] <= INK_LUMA_MAX && luma[y * width + x - 3] <= INK_LUMA_MAX && luma[y * width + x + 3] <= INK_LUMA_MAX);
|
|
452
|
+
const at = (y) => xs.some((x) => faint(x, y));
|
|
453
|
+
for (const dir of [1, -1]) {
|
|
454
|
+
let y = dir > 0 ? Math.round(v.y2) + 1 : Math.round(v.y1) - 1, end = y - dir, gap2 = 0;
|
|
455
|
+
while (y >= 0 && y < height && gap2 <= GAP_TOL_PX) {
|
|
456
|
+
if (at(y)) {
|
|
457
|
+
end = y;
|
|
458
|
+
gap2 = 0;
|
|
459
|
+
} else if (!cross(y)) gap2++;
|
|
460
|
+
y += dir;
|
|
461
|
+
}
|
|
462
|
+
if (Math.abs(end - (dir > 0 ? v.y2 : v.y1)) < minLenPx) continue;
|
|
463
|
+
if (!horizontals.some((h) => Math.abs(h.y1 - end) <= maxThickPx * 2 && h.x1 <= v.x1 + maxThickPx && h.x2 >= v.x1 - maxThickPx)) continue;
|
|
464
|
+
if (!verticals.some((o) => o !== v && Math.abs((dir > 0 ? o.y2 : o.y1) - end) <= maxThickPx * 2)) continue;
|
|
465
|
+
if (dir > 0) v.y2 = end;
|
|
466
|
+
else v.y1 = end;
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
const meets = (h) => new Set(verticals.filter((v) => v.x1 >= h.x1 - maxThickPx && v.x1 <= h.x2 + maxThickPx && h.y1 >= v.y1 - maxThickPx && h.y1 <= v.y2 + maxThickPx).map((v) => Math.round(v.x1 / 4))).size >= 2;
|
|
470
|
+
horizontals.splice(baseH, hAdd.length, ...hAdd.filter((h) => h.thicknessPx <= 3 && meets(h)));
|
|
432
471
|
const dotH = detectBands(ink, width, height, maxThickPx, false, dotted);
|
|
433
472
|
const dotV = detectBands(ink, width, height, maxThickPx, true, dotted);
|
|
434
473
|
const tol = Math.max(2, Math.round(DOT_TOUCH_PT * scale));
|
|
@@ -559,10 +598,10 @@ function detectRulingLines(rgba, width, height, scale) {
|
|
|
559
598
|
}
|
|
560
599
|
}
|
|
561
600
|
if (frames.length) {
|
|
562
|
-
const
|
|
563
|
-
for (let p = 0; p <
|
|
564
|
-
const hs = detectBands(
|
|
565
|
-
const vs = detectBands(
|
|
601
|
+
const faint2 = new Uint8Array(ink.length);
|
|
602
|
+
for (let p = 0; p < faint2.length; p++) if (luma[p] <= 240 && rgba[p * 4 + 3] >= 128) faint2[p] = 1;
|
|
603
|
+
const hs = detectBands(faint2, width, height, maxThickPx, false, solid);
|
|
604
|
+
const vs = detectBands(faint2, width, height, maxThickPx, true, solid);
|
|
566
605
|
for (const f of frames) {
|
|
567
606
|
const innerH = hs.filter((h) => h.y1 > f.y1 + tol && h.y1 < f.y2 - tol && Math.abs(h.x1 - f.x1) <= tol && Math.abs(h.x2 - f.x2) <= tol);
|
|
568
607
|
const innerV = vs.filter((v) => v.x1 > f.x1 + tol && v.x1 < f.x2 - tol && Math.abs(v.y1 - f.y1) <= tol && Math.abs(v.y2 - f.y2) <= tol);
|
|
@@ -714,7 +753,7 @@ function dottedRuns(mask, base, step, span, minLenPx, maxGap, maxDash, maxPeriod
|
|
|
714
753
|
flush();
|
|
715
754
|
return runs;
|
|
716
755
|
}
|
|
717
|
-
function detectBands(ink, width, height, maxThickPx, transpose, readRuns) {
|
|
756
|
+
function detectBands(ink, width, height, maxThickPx, transpose, readRuns, prevRun = false) {
|
|
718
757
|
const lines = transpose ? width : height;
|
|
719
758
|
const span = transpose ? height : width;
|
|
720
759
|
const step = transpose ? width : 1;
|
|
@@ -734,6 +773,7 @@ function detectBands(ink, width, height, maxThickPx, transpose, readRuns) {
|
|
|
734
773
|
const emit = (b) => {
|
|
735
774
|
const thick = b.last - b.first + 1;
|
|
736
775
|
if (thick > maxThickPx) return;
|
|
776
|
+
if (prevRun && (surroundInkRatio(b, b.first - 2) >= SURROUND_INK_RATIO || surroundInkRatio(b, b.last + 2) >= SURROUND_INK_RATIO)) return;
|
|
737
777
|
if (surroundInkRatio(b, b.first - 2) >= SURROUND_INK_RATIO && surroundInkRatio(b, b.last + 2) >= SURROUND_INK_RATIO) return;
|
|
738
778
|
const center = (b.first + b.last) / 2;
|
|
739
779
|
out.push(
|
|
@@ -753,11 +793,15 @@ function detectBands(ink, width, height, maxThickPx, transpose, readRuns) {
|
|
|
753
793
|
for (let r = 0; r < runs.length; r++) {
|
|
754
794
|
if (used.has(r)) continue;
|
|
755
795
|
const run = runs[r];
|
|
756
|
-
const
|
|
757
|
-
const
|
|
758
|
-
|
|
796
|
+
const lo = prevRun ? band.plo : band.lo, hi = prevRun ? band.phi : band.hi;
|
|
797
|
+
const overlap = Math.min(hi, run.hi) - Math.max(lo, run.lo) + 1;
|
|
798
|
+
const prevLen = hi - lo + 1, runLen = run.hi - run.lo + 1;
|
|
799
|
+
const shorter = Math.min(prevLen, runLen);
|
|
800
|
+
if (overlap >= shorter * BAND_OVERLAP_RATIO && (!prevRun || shorter * 2 >= Math.max(prevLen, runLen))) {
|
|
759
801
|
band.lo = Math.min(band.lo, run.lo);
|
|
760
802
|
band.hi = Math.max(band.hi, run.hi);
|
|
803
|
+
band.plo = run.lo;
|
|
804
|
+
band.phi = run.hi;
|
|
761
805
|
band.last = line;
|
|
762
806
|
next.push(band);
|
|
763
807
|
used.add(r);
|
|
@@ -768,7 +812,7 @@ function detectBands(ink, width, height, maxThickPx, transpose, readRuns) {
|
|
|
768
812
|
if (!merged) emit(band);
|
|
769
813
|
}
|
|
770
814
|
for (let r = 0; r < runs.length; r++) {
|
|
771
|
-
if (!used.has(r)) next.push({ lo: runs[r].lo, hi: runs[r].hi, first: line, last: line });
|
|
815
|
+
if (!used.has(r)) next.push({ lo: runs[r].lo, hi: runs[r].hi, first: line, last: line, plo: runs[r].lo, phi: runs[r].hi });
|
|
772
816
|
}
|
|
773
817
|
open = next;
|
|
774
818
|
}
|
|
@@ -805,8 +849,8 @@ var INKLESS_DELTA = 32;
|
|
|
805
849
|
function ringAsks(rgba, pageW, box, text, steps, stepPx) {
|
|
806
850
|
const chars = [...text];
|
|
807
851
|
if (chars.length !== steps.length || !/[가-힣]/.test(text)) return [];
|
|
808
|
-
const gray =
|
|
809
|
-
const rings =
|
|
852
|
+
const gray = _chunkWD5KO2FIcjs.grayCrop.call(void 0, rgba, pageW, box);
|
|
853
|
+
const rings = _chunkWD5KO2FIcjs.ringBoxes.call(void 0, gray, box.w, box.h, _chunkWD5KO2FIcjs.inkStats.call(void 0, gray));
|
|
810
854
|
const owner = ringOwners(chars, (i) => (steps[i] + 0.5) * stepPx, rings);
|
|
811
855
|
return rings.flatMap((r, k) => {
|
|
812
856
|
const at = owner.indexOf(k);
|
|
@@ -846,8 +890,8 @@ function ringGlyph(read, jamo = null, confidence = 1) {
|
|
|
846
890
|
function restoreGlyphs(rgba, pageW, box, text, steps, stepPx, note = {}, rings = []) {
|
|
847
891
|
const chars = [...text];
|
|
848
892
|
if (chars.length !== steps.length) return text;
|
|
849
|
-
const gray =
|
|
850
|
-
const c = { chars, cx: (i) => (steps[i] + 0.5) * stepPx, gray, w: box.w, h: box.h, ink:
|
|
893
|
+
const gray = _chunkWD5KO2FIcjs.grayCrop.call(void 0, rgba, pageW, box);
|
|
894
|
+
const c = { chars, cx: (i) => (steps[i] + 0.5) * stepPx, gray, w: box.w, h: box.h, ink: _chunkWD5KO2FIcjs.inkStats.call(void 0, gray) };
|
|
851
895
|
if (/[[\]]/.test(text)) brackets(c);
|
|
852
896
|
if (text.includes("'")) cornerQuotes(c);
|
|
853
897
|
if (/['"]/.test(text)) quotes(c);
|
|
@@ -877,7 +921,7 @@ function restoreGlyphs(rgba, pageW, box, text, steps, stepPx, note = {}, rings =
|
|
|
877
921
|
function trimInklessEnds(rgba, pageW, box, text, steps, stepPx) {
|
|
878
922
|
const chars = [...text], { w, h } = box;
|
|
879
923
|
if (chars.length !== steps.length || steps.some((s) => (s + 0.5) * stepPx > w + stepPx)) return { text, steps };
|
|
880
|
-
const gray =
|
|
924
|
+
const gray = _chunkWD5KO2FIcjs.grayCrop.call(void 0, rgba, pageW, box);
|
|
881
925
|
const hist = new Uint32Array(256);
|
|
882
926
|
for (const v of gray) hist[v]++;
|
|
883
927
|
let bg = 0;
|
|
@@ -908,8 +952,8 @@ function cornerCommas({ chars, cx, gray, w, h, ink }) {
|
|
|
908
952
|
continue;
|
|
909
953
|
}
|
|
910
954
|
if (open > 0) {
|
|
911
|
-
const f =
|
|
912
|
-
if (f &&
|
|
955
|
+
const f = _chunkWD5KO2FIcjs.bracketFeatures.call(void 0, gray, w, h, ink, cx(i));
|
|
956
|
+
if (f && _chunkWD5KO2FIcjs.bracketShape.call(void 0, f, true) === "\u300D") {
|
|
913
957
|
chars[i] = "\u300D";
|
|
914
958
|
open--;
|
|
915
959
|
}
|
|
@@ -919,12 +963,12 @@ function cornerCommas({ chars, cx, gray, w, h, ink }) {
|
|
|
919
963
|
function cornerQuotes({ chars, cx, gray, w, h, ink }) {
|
|
920
964
|
for (let i = 0; i < chars.length; i++) {
|
|
921
965
|
if (chars[i] !== "'" || !/^[가-힣]/.test(_nullishCoalesce(chars[i + 1], () => ( "")))) continue;
|
|
922
|
-
const f =
|
|
923
|
-
if (!f || f.ch < f.charH * 0.45 ||
|
|
966
|
+
const f = _chunkWD5KO2FIcjs.bracketFeatures.call(void 0, gray, w, h, ink, cx(i));
|
|
967
|
+
if (!f || f.ch < f.charH * 0.45 || _chunkWD5KO2FIcjs.bracketShape.call(void 0, f, false) !== "\u300C") continue;
|
|
924
968
|
const rest = chars.slice(i + 1), end = rest.findIndex((c) => c === "'" || c === "\u300D" || c === ",");
|
|
925
969
|
const pair = end >= 0 && rest[end] !== "'" && (rest[end] === "\u300D" || (() => {
|
|
926
|
-
const g =
|
|
927
|
-
return !!g &&
|
|
970
|
+
const g = _chunkWD5KO2FIcjs.bracketFeatures.call(void 0, gray, w, h, ink, cx(i + 1 + end));
|
|
971
|
+
return !!g && _chunkWD5KO2FIcjs.bracketShape.call(void 0, g, true) === "\u300D";
|
|
928
972
|
})());
|
|
929
973
|
if (pair) chars[i] = "\u300C";
|
|
930
974
|
}
|
|
@@ -932,8 +976,8 @@ function cornerQuotes({ chars, cx, gray, w, h, ink }) {
|
|
|
932
976
|
function brackets({ chars, cx, gray, w, h, ink }) {
|
|
933
977
|
const shape = chars.map((c, i) => {
|
|
934
978
|
if (c !== "[" && c !== "]") return null;
|
|
935
|
-
const f =
|
|
936
|
-
return f &&
|
|
979
|
+
const f = _chunkWD5KO2FIcjs.bracketFeatures.call(void 0, gray, w, h, ink, cx(i));
|
|
980
|
+
return f && _chunkWD5KO2FIcjs.bracketShape.call(void 0, f, c === "]");
|
|
937
981
|
});
|
|
938
982
|
for (let i = 0; i < chars.length; i++) {
|
|
939
983
|
if (chars[i] !== "[") continue;
|
|
@@ -965,7 +1009,7 @@ function quotes({ chars, cx, gray, w, h, ink }) {
|
|
|
965
1009
|
continue;
|
|
966
1010
|
}
|
|
967
1011
|
if (!year(i) && !single[kind]) continue;
|
|
968
|
-
const r =
|
|
1012
|
+
const r = _chunkWD5KO2FIcjs.quoteHead.call(void 0, gray, w, h, ink, cx(i));
|
|
969
1013
|
if (r !== null && r >= 0.47) {
|
|
970
1014
|
chars[i] = kind === "'" ? "\u2018" : "\u201C";
|
|
971
1015
|
open[kind] = true;
|
|
@@ -976,7 +1020,7 @@ function dashes({ chars, cx, gray, w, h, ink }) {
|
|
|
976
1020
|
const head = chars.findIndex((c) => c.trim()), letters = chars.some((c) => /[가-힣A-Za-z]/.test(c));
|
|
977
1021
|
for (let i = 0; i < chars.length; i++) {
|
|
978
1022
|
if (!/^[-\u2013\u2014]$/.test(chars[i])) continue;
|
|
979
|
-
const r =
|
|
1023
|
+
const r = _chunkWD5KO2FIcjs.dashRatio.call(void 0, gray, w, h, ink, cx(i));
|
|
980
1024
|
if (r === null) continue;
|
|
981
1025
|
if (r < 0.65) chars[i] = "-";
|
|
982
1026
|
else if (r > 0.75 && i === head && letters) chars[i] = "\u2014";
|
|
@@ -986,7 +1030,7 @@ function circled({ chars, cx, gray, w, h, ink }) {
|
|
|
986
1030
|
const alone = (re, i) => re.test(chars[i]) && !re.test(_nullishCoalesce(chars[i - 1], () => ( ""))) && !re.test(_nullishCoalesce(chars[i + 1], () => ( "")));
|
|
987
1031
|
const at = chars.flatMap((_, i) => alone(/^\d$/, i) && chars[i] !== "0" || alone(/^[ㄱ-ㅎ]$/, i) || alone(/^[A-Za-z]$/, i) && /[a-zCSUVWXZ]/.test(chars[i]) ? [i] : []);
|
|
988
1032
|
if (!at.length) return;
|
|
989
|
-
const hit =
|
|
1033
|
+
const hit = _chunkWD5KO2FIcjs.circledAt.call(void 0, gray, w, h, ink, at.map(cx));
|
|
990
1034
|
const JAMO = "\u3131\u3134\u3137\u3139\u3141\u3142\u3145\u3147\u3148\u314A\u314B\u314C\u314D\u314E";
|
|
991
1035
|
at.forEach((i, k) => {
|
|
992
1036
|
if (!hit[k]) return;
|
|
@@ -999,16 +1043,16 @@ function stars({ chars, cx, gray, w, h, ink }) {
|
|
|
999
1043
|
if (chars[i] !== "*" || chars[i - 1] === "*") continue;
|
|
1000
1044
|
let e = i;
|
|
1001
1045
|
while (chars[e + 1] === "*") e++;
|
|
1002
|
-
const n =
|
|
1046
|
+
const n = _chunkWD5KO2FIcjs.starRun.call(void 0, gray, w, h, ink, cx(i));
|
|
1003
1047
|
if (n > e - i + 1 && n <= 4) chars[e] += "*".repeat(n - (e - i + 1));
|
|
1004
1048
|
i = e;
|
|
1005
1049
|
}
|
|
1006
1050
|
}
|
|
1007
1051
|
function discs({ chars, cx, gray, w, h, ink }) {
|
|
1008
|
-
for (let i = 0; i < chars.length; i++) if (/^[\u00b7\u2022]$/.test(chars[i]) &&
|
|
1052
|
+
for (let i = 0; i < chars.length; i++) if (/^[\u00b7\u2022]$/.test(chars[i]) && _chunkWD5KO2FIcjs.discAt.call(void 0, gray, w, h, ink, cx(i))) chars[i] = "\u25CF";
|
|
1009
1053
|
}
|
|
1010
1054
|
function gaps({ chars, cx, gray, w, h, ink }) {
|
|
1011
|
-
const { glyphs, bandH } =
|
|
1055
|
+
const { glyphs, bandH } = _chunkWD5KO2FIcjs.gapGlyphs.call(void 0, gray, w, h, ink);
|
|
1012
1056
|
if (!glyphs.length) return;
|
|
1013
1057
|
const live = chars.map((c, i) => i).filter((i) => chars[i].trim());
|
|
1014
1058
|
if (!live.length) return;
|
|
@@ -1079,18 +1123,18 @@ function ring({ chars, cx, gray, w, h, ink }) {
|
|
|
1079
1123
|
const rest = chars.slice(k + 1).join("").trimStart();
|
|
1080
1124
|
const live = chars.map((c, i) => i).filter((i) => chars[i].trim());
|
|
1081
1125
|
if (live.length <= 3 && live.every((i) => /^[Oo]$/.test(chars[i]))) {
|
|
1082
|
-
if (_optionalChain([
|
|
1083
|
-
if (!live.every((i) =>
|
|
1126
|
+
if (_optionalChain([_chunkWD5KO2FIcjs.leadingBullet.call(void 0, gray, w, h, ink, cx(live[0])), 'optionalAccess', _11 => _11.mark]) === "\u25CE") return false;
|
|
1127
|
+
if (!live.every((i) => _chunkWD5KO2FIcjs.ringBullet.call(void 0, gray, w, h, ink, cx(i)) === "\u25CB")) return false;
|
|
1084
1128
|
for (const i of live) chars[i] = "\u25CB";
|
|
1085
1129
|
return true;
|
|
1086
1130
|
}
|
|
1087
1131
|
if (/^[A-Z]{2,}/.test(rest) && /^[Oo0]$/.test(chars[k])) {
|
|
1088
|
-
if (
|
|
1132
|
+
if (_chunkWD5KO2FIcjs.ringBullet.call(void 0, gray, w, h, ink, cx(k)) !== "\u25CB") return false;
|
|
1089
1133
|
chars[k] = chars[k + 1] === " " ? "\u25CB" : "\u25CB ";
|
|
1090
1134
|
return true;
|
|
1091
1135
|
}
|
|
1092
1136
|
if (!/^[(\[「【<]?\d*[가-힣]/.test(rest)) return false;
|
|
1093
|
-
const r =
|
|
1137
|
+
const r = _chunkWD5KO2FIcjs.ringBullet.call(void 0, gray, w, h, ink, cx(k));
|
|
1094
1138
|
if (/^[Cc]$/.test(chars[k]) && r !== "\u25CB") return false;
|
|
1095
1139
|
if (r) chars[k] = r;
|
|
1096
1140
|
return r !== null;
|
|
@@ -1107,7 +1151,7 @@ function parallels({ chars, cx, gray, w, h, ink }) {
|
|
|
1107
1151
|
let p = s - 1, q = e + 1;
|
|
1108
1152
|
while (p >= 0 && !chars[p].trim()) p--;
|
|
1109
1153
|
while (q < chars.length && !chars[q].trim()) q++;
|
|
1110
|
-
if (
|
|
1154
|
+
if (_chunkWD5KO2FIcjs.slantedPair.call(void 0, gray, w, h, ink, p >= 0 ? cx(p) : -Infinity, q < chars.length ? cx(q) : Infinity)) {
|
|
1111
1155
|
chars[s] = "\u2225";
|
|
1112
1156
|
for (let k = s + 1; k <= e; k++) chars[k] = "";
|
|
1113
1157
|
}
|
|
@@ -1119,7 +1163,7 @@ function roman({ chars, cx, gray, w, h, ink }) {
|
|
|
1119
1163
|
const ROMAN = /^[IⅠ-Ⅲ]$/, LATIN = /[A-Za-z]$/;
|
|
1120
1164
|
for (let i = 0; i < chars.length; i++) {
|
|
1121
1165
|
if (chars[i] !== "1" || /[\dA-Za-z]$/.test(_nullishCoalesce(chars[i - 1], () => ( ""))) || /^[\dA-Za-z,]/.test(_nullishCoalesce(chars[i + 1], () => ( "")))) continue;
|
|
1122
|
-
if (
|
|
1166
|
+
if (_chunkWD5KO2FIcjs.serifOne.call(void 0, gray, w, h, ink, cx(i))) chars[i] = "\u2160";
|
|
1123
1167
|
}
|
|
1124
1168
|
for (let i = 0; i < chars.length; i++) {
|
|
1125
1169
|
const hangul = /^[파피]$/.test(chars[i]);
|
|
@@ -1129,13 +1173,13 @@ function roman({ chars, cx, gray, w, h, ink }) {
|
|
|
1129
1173
|
while (q < chars.length && !chars[q].trim()) q++;
|
|
1130
1174
|
const glued = hangul ? chars[p] === "(" && chars[q] === "-" : /[가-힣]$/.test(_nullishCoalesce(chars[i - 1], () => ( ""))) || (_nullishCoalesce(chars[i + 1], () => ( ""))) === "." || chars[p] === "-" && chars[q] === "-";
|
|
1131
1175
|
if (!glued) continue;
|
|
1132
|
-
const n =
|
|
1176
|
+
const n = _chunkWD5KO2FIcjs.romanStems.call(void 0, gray, w, h, ink, p >= 0 ? cx(p) : -Infinity, q < chars.length ? cx(q) : Infinity, /[가-힣]$/.test(_nullishCoalesce(chars[p], () => ( ""))));
|
|
1133
1177
|
if (n) chars[i] = String.fromCharCode(8543 + n);
|
|
1134
1178
|
}
|
|
1135
1179
|
const inRoman = (i) => ROMAN.test(chars[i]) || chars[i] === "1" && (ROMAN.test(_nullishCoalesce(chars[i - 1], () => ( ""))) || ROMAN.test(_nullishCoalesce(chars[i + 1], () => ( ""))));
|
|
1136
1180
|
const k = chars.findIndex((c) => c.trim());
|
|
1137
1181
|
if (chars[k] === "." && chars.slice(k + 1).some((c) => /[가-힣A-Za-z0-9]/.test(c))) {
|
|
1138
|
-
const n =
|
|
1182
|
+
const n = _chunkWD5KO2FIcjs.romanStems.call(void 0, gray, w, h, ink, -Infinity, cx(k));
|
|
1139
1183
|
if (n) chars[k] = String.fromCharCode(8543 + n) + chars[k];
|
|
1140
1184
|
}
|
|
1141
1185
|
for (let s = 0; s < chars.length; ) {
|
|
@@ -1153,7 +1197,7 @@ function roman({ chars, cx, gray, w, h, ink }) {
|
|
|
1153
1197
|
let p = s - 1, q = e;
|
|
1154
1198
|
while (p >= 0 && !chars[p].trim()) p--;
|
|
1155
1199
|
while (q < chars.length && !chars[q].trim()) q++;
|
|
1156
|
-
const n =
|
|
1200
|
+
const n = _chunkWD5KO2FIcjs.romanStems.call(void 0, gray, w, h, ink, p >= 0 ? cx(p) : -Infinity, q < chars.length ? cx(q) : Infinity, /[가-힣]$/.test(_nullishCoalesce(chars[p], () => ( ""))));
|
|
1157
1201
|
const canon = n ? [["\u2160", "I"], ["\u2161", "II"], ["\u2162", "III"]][n - 1] : null;
|
|
1158
1202
|
if (canon && !canon.includes(tok)) {
|
|
1159
1203
|
chars[s] = canon[0];
|
|
@@ -1582,8 +1626,8 @@ function joinGapLeaders(rgba, width, items) {
|
|
|
1582
1626
|
if (g1 - g0 < h * 3) continue;
|
|
1583
1627
|
const pad = Math.round(h * 0.25), y = Math.max(0, Math.min(left.y, num.y) - pad), x = Math.max(0, Math.round(g0 - h));
|
|
1584
1628
|
const box = { x, y, w: Math.min(width, Math.round(g1 + h)) - x, h: Math.min(Math.floor(rgba.length / 4 / width), Math.max(left.y + left.h, num.y + num.h) + pad) - y };
|
|
1585
|
-
const gray =
|
|
1586
|
-
const runs =
|
|
1629
|
+
const gray = _chunkWD5KO2FIcjs.grayCrop.call(void 0, rgba, width, box);
|
|
1630
|
+
const runs = _chunkWD5KO2FIcjs.leaderRuns.call(void 0, gray, box.w, box.h, _chunkWD5KO2FIcjs.inkStats.call(void 0, gray), LEADER_MIN_DOTS);
|
|
1587
1631
|
const cover = runs.reduce((k, [a, b]) => k + Math.max(0, Math.min(b, g1 - box.x) - Math.max(a, g0 - box.x)), 0);
|
|
1588
1632
|
if (cover < (g1 - g0) * 0.6) continue;
|
|
1589
1633
|
for (const o of items) if (junk(o) && sameLine(o, num) && o.x >= g0 - 2 && o.x + o.w <= g1 + 2) gone.add(o);
|
|
@@ -1866,7 +1910,7 @@ var OcrEngine = class _OcrEngine {
|
|
|
1866
1910
|
this.ort = parts.ort;
|
|
1867
1911
|
this.sharp = parts.sharp;
|
|
1868
1912
|
}
|
|
1869
|
-
static async create(models =
|
|
1913
|
+
static async create(models = _chunkWD5KO2FIcjs.DEFAULT_OCR_MODELS) {
|
|
1870
1914
|
_chunkTK3FDAEEcjs.disableOrtTelemetry.call(void 0, );
|
|
1871
1915
|
const [ortMod, sharpModRaw] = await Promise.all([
|
|
1872
1916
|
tryImport("onnxruntime-node", () => Promise.resolve().then(() => _interopRequireWildcard(require("onnxruntime-node")))),
|
|
@@ -1886,16 +1930,16 @@ var OcrEngine = class _OcrEngine {
|
|
|
1886
1930
|
const local = (s) => "spec" in s ? Promise.resolve(null) : verifiedBytes(s);
|
|
1887
1931
|
const [detBytes, recBytes, dictBytes] = await Promise.all([local(models.det), local(models.rec), local(models.dict)]);
|
|
1888
1932
|
const session = (s, bytes) => bytes ? ortMod.InferenceSession.create(bytes, sessionOpts).catch(() => {
|
|
1889
|
-
throw new (0,
|
|
1890
|
-
}) : ortMod.InferenceSession.create(
|
|
1933
|
+
throw new (0, _chunkWL6FHOXScjs.KordocError)(`OCR \uBAA8\uB378\uC744 \uC5F4\uC9C0 \uBABB\uD588\uC2B5\uB2C8\uB2E4: ${_path.basename.call(void 0, _chunkWD5KO2FIcjs.ocrSourcePath.call(void 0, s))} \u2014 ONNX \uBAA8\uB378\uC774 \uC544\uB2C8\uAC70\uB098 \uC190\uC0C1\uB410\uC2B5\uB2C8\uB2E4`);
|
|
1934
|
+
}) : ortMod.InferenceSession.create(_chunkWD5KO2FIcjs.ocrSourcePath.call(void 0, s), sessionOpts);
|
|
1891
1935
|
const [det, rec, dictYml] = await Promise.all([
|
|
1892
1936
|
session(models.det, detBytes),
|
|
1893
1937
|
session(models.rec, recBytes),
|
|
1894
|
-
dictBytes ? new TextDecoder().decode(dictBytes) : _promises.readFile.call(void 0,
|
|
1938
|
+
dictBytes ? new TextDecoder().decode(dictBytes) : _promises.readFile.call(void 0, _chunkWD5KO2FIcjs.ocrSourcePath.call(void 0, models.dict), "utf-8")
|
|
1895
1939
|
]);
|
|
1896
|
-
const dict =
|
|
1940
|
+
const dict = _chunkWD5KO2FIcjs.parseCharacterDict.call(void 0, dictYml);
|
|
1897
1941
|
if (dict.length === 0) {
|
|
1898
|
-
throw "spec" in models.dict ? new Error("OCR \uC0AC\uC804 \uD30C\uC2F1 \uC2E4\uD328 \u2014 \uBAA8\uB378 \uCE90\uC2DC\uB97C \uC0AD\uC81C \uD6C4 \uC7AC\uB2E4\uC6B4\uB85C\uB4DC\uD558\uC138\uC694") : new (0,
|
|
1942
|
+
throw "spec" in models.dict ? new Error("OCR \uC0AC\uC804 \uD30C\uC2F1 \uC2E4\uD328 \u2014 \uBAA8\uB378 \uCE90\uC2DC\uB97C \uC0AD\uC81C \uD6C4 \uC7AC\uB2E4\uC6B4\uB85C\uB4DC\uD558\uC138\uC694") : new (0, _chunkWL6FHOXScjs.KordocError)(`OCR \uC0AC\uC804 \uD30C\uC2F1 \uC2E4\uD328 \u2014 ${_path.basename.call(void 0, models.dict.file.path)} \uC5D0 PostProcess.character_dict \uBAA9\uB85D\uC774 \uC5C6\uC2B5\uB2C8\uB2E4`);
|
|
1899
1943
|
}
|
|
1900
1944
|
return new _OcrEngine({ det, rec, dict, ort: ortMod, sharp: sharpMod });
|
|
1901
1945
|
}
|
|
@@ -1927,10 +1971,10 @@ var OcrEngine = class _OcrEngine {
|
|
|
1927
1971
|
if (it.x - x < it.h * 0.8) return;
|
|
1928
1972
|
if (items.some((o) => o !== it && o.x < it.x && o.x + o.w > x && o.y < it.y + it.h && o.y + o.h > it.y)) return;
|
|
1929
1973
|
const box = { x, y: it.y, w: it.x + it.w - x, h: it.h };
|
|
1930
|
-
const g =
|
|
1931
|
-
const b =
|
|
1974
|
+
const g = _chunkWD5KO2FIcjs.grayCrop.call(void 0, rgba, width, box);
|
|
1975
|
+
const b = _chunkWD5KO2FIcjs.leadingBullet.call(void 0, g, box.w, box.h, _chunkWD5KO2FIcjs.inkStats.call(void 0, g), it.x - x, 1.05);
|
|
1932
1976
|
if (_optionalChain([b, 'optionalAccess', _36 => _36.mark]) !== "\u25A1" || b.covers) return;
|
|
1933
|
-
const ink =
|
|
1977
|
+
const ink = _chunkWD5KO2FIcjs.inkStats.call(void 0, g), on = (v) => ink.darkInk ? v <= ink.threshold : v > ink.threshold;
|
|
1934
1978
|
let left = 0;
|
|
1935
1979
|
while (left < it.x - x && !Array.from({ length: box.h }, (_, y) => g[y * box.w + left]).some(on)) left++;
|
|
1936
1980
|
it.text = "\u25A1 " + it.text;
|
|
@@ -1962,12 +2006,12 @@ var OcrEngine = class _OcrEngine {
|
|
|
1962
2006
|
const joins = [];
|
|
1963
2007
|
let group = 0;
|
|
1964
2008
|
for (const b of boxes) {
|
|
1965
|
-
const gray =
|
|
1966
|
-
const ink =
|
|
2009
|
+
const gray = _chunkWD5KO2FIcjs.grayCrop.call(void 0, rgba, width, b);
|
|
2010
|
+
const ink = _chunkWD5KO2FIcjs.inkStats.call(void 0, gray);
|
|
1967
2011
|
if (tuning.minInkContrast > 0 && ink.contrast < tuning.minInkContrast) continue;
|
|
1968
2012
|
if (tuning.minInkContrast > 0 && ink.inkRatio < MIN_INK_RATIO) continue;
|
|
1969
2013
|
if (tuning.splitTall && b.h >= b.w * TALL_RATIO) {
|
|
1970
|
-
const bands =
|
|
2014
|
+
const bands = _chunkWD5KO2FIcjs.splitRowBands.call(void 0, gray, b.w, b.h, ink, 0.45);
|
|
1971
2015
|
if (bands.length >= 2) {
|
|
1972
2016
|
for (const sub of bandBoxes(b, bands, height)) jobs.push({ box: sub, rot: 0, group: group++ });
|
|
1973
2017
|
continue;
|
|
@@ -1991,9 +2035,9 @@ var OcrEngine = class _OcrEngine {
|
|
|
1991
2035
|
continue;
|
|
1992
2036
|
}
|
|
1993
2037
|
}
|
|
1994
|
-
const trim = tuning.trimEdges ?
|
|
2038
|
+
const trim = tuning.trimEdges ? _chunkWD5KO2FIcjs.edgeTrim.call(void 0, gray, b.w, b.h, ink) : null;
|
|
1995
2039
|
const keep = trim ? { ...trim, bg: median(gray) } : void 0;
|
|
1996
|
-
const leaders = tuning.splitLeaders ?
|
|
2040
|
+
const leaders = tuning.splitLeaders ? _chunkWD5KO2FIcjs.leaderRuns.call(void 0, gray, b.w, b.h, ink, LEADER_MIN_DOTS) : [];
|
|
1997
2041
|
if (leaders.length) {
|
|
1998
2042
|
const join = joins.length;
|
|
1999
2043
|
joins.push({ box: b, parts: [], trailDots: false });
|
|
@@ -2002,7 +2046,7 @@ var OcrEngine = class _OcrEngine {
|
|
|
2002
2046
|
const bare = { x: b.x + x0, y: b.y, w: a - x0, h: b.h };
|
|
2003
2047
|
const end = c > a ? Math.min(c, a + Math.round(b.h * LEADER_CONTEXT)) : a;
|
|
2004
2048
|
x0 = c;
|
|
2005
|
-
if (bare.w >= DET_MIN_SIZE &&
|
|
2049
|
+
if (bare.w >= DET_MIN_SIZE && _chunkWD5KO2FIcjs.inkStats.call(void 0, _chunkWD5KO2FIcjs.grayCrop.call(void 0, rgba, width, bare)).contrast >= Math.max(1, tuning.minInkContrast)) {
|
|
2006
2050
|
jobs.push({ box: { ...bare, w: end - (bare.x - b.x) }, rot: 0, group: group++, join, dotsBefore: dots, trimDots: end > a });
|
|
2007
2051
|
dots = false;
|
|
2008
2052
|
}
|
|
@@ -2051,15 +2095,15 @@ var OcrEngine = class _OcrEngine {
|
|
|
2051
2095
|
let text = tuning.postprocess ? restoreSymbols(raw.trim(), note.ringLead) : raw;
|
|
2052
2096
|
if (!text.trim()) continue;
|
|
2053
2097
|
if (tuning.postprocess && job.rot === 0 && text !== "/" && /^[(:;/)]+$/.test(text) && text.includes("/")) {
|
|
2054
|
-
const g =
|
|
2055
|
-
if (
|
|
2098
|
+
const g = _chunkWD5KO2FIcjs.grayCrop.call(void 0, rgba, width, job.box);
|
|
2099
|
+
if (_chunkWD5KO2FIcjs.tallInkCount.call(void 0, g, job.box.w, job.box.h, _chunkWD5KO2FIcjs.inkStats.call(void 0, g)) === 1) text = "/";
|
|
2056
2100
|
}
|
|
2057
2101
|
let ringByShape = false;
|
|
2058
2102
|
if (tuning.postprocess && job.rot === 0 && !/^[◎●▪□■▣❐❏○ㅇ◆◇◈]/.test(text)) {
|
|
2059
2103
|
const chars = [...read], k = chars.findIndex((c) => c.trim());
|
|
2060
2104
|
if (k >= 0 && steps.length === chars.length) {
|
|
2061
|
-
const g =
|
|
2062
|
-
const b =
|
|
2105
|
+
const g = _chunkWD5KO2FIcjs.grayCrop.call(void 0, rgba, width, job.box);
|
|
2106
|
+
const b = _chunkWD5KO2FIcjs.leadingBullet.call(void 0, g, job.box.w, job.box.h, _chunkWD5KO2FIcjs.inkStats.call(void 0, g), (steps[k] + 0.5) * stepPx);
|
|
2063
2107
|
const body = (_nullishCoalesce(text.match(/[가-힣]/g), () => ( []))).length >= 4;
|
|
2064
2108
|
const miss = /^[Oo0•·ㆍ∙‧○]/.test(text);
|
|
2065
2109
|
if (_optionalChain([b, 'optionalAccess', _39 => _39.mark]) === "\u25CE" && b.covers && /^[Oo0○©]/.test(text)) {
|
|
@@ -2074,17 +2118,17 @@ var OcrEngine = class _OcrEngine {
|
|
|
2074
2118
|
} else if (_optionalChain([b, 'optionalAccess', _46 => _46.mark]) === "\u2750" || _optionalChain([b, 'optionalAccess', _47 => _47.mark]) === "\u274F") {
|
|
2075
2119
|
if (b.covers ? /^[ㅁ口]/.test(text) : body) text = b.covers ? b.mark + text.slice(1) : b.mark + " " + text;
|
|
2076
2120
|
} else if (b && b.mark !== "\u25CE" && body) text = b.covers ? miss ? b.mark + " " + text.slice(1).trimStart() : text : b.mark + " " + text;
|
|
2077
|
-
else if (!b && body && /^[가-힣]/.test(chars[k]) &&
|
|
2121
|
+
else if (!b && body && /^[가-힣]/.test(chars[k]) && _chunkWD5KO2FIcjs.leadingRing.call(void 0, g, job.box.w, job.box.h, _chunkWD5KO2FIcjs.inkStats.call(void 0, g), (steps[k] + 0.5) * stepPx)) text = "\u25CB " + text;
|
|
2078
2122
|
}
|
|
2079
2123
|
}
|
|
2080
2124
|
if (tuning.postprocess && /^\d/.test(text) && job.rot === 0) {
|
|
2081
|
-
const g =
|
|
2082
|
-
const tri =
|
|
2125
|
+
const g = _chunkWD5KO2FIcjs.grayCrop.call(void 0, rgba, width, job.box);
|
|
2126
|
+
const tri = _chunkWD5KO2FIcjs.leadingTriangle.call(void 0, g, job.box.w, job.box.h, _chunkWD5KO2FIcjs.inkStats.call(void 0, g));
|
|
2083
2127
|
if (tri) text = tri + text;
|
|
2084
2128
|
}
|
|
2085
2129
|
if (tuning.postprocess && text === "\u2192" && job.rot === 0 && job.join === void 0) {
|
|
2086
|
-
const g =
|
|
2087
|
-
text = _nullishCoalesce(
|
|
2130
|
+
const g = _chunkWD5KO2FIcjs.grayCrop.call(void 0, rgba, width, job.box);
|
|
2131
|
+
text = _nullishCoalesce(_chunkWD5KO2FIcjs.arrowGlyph.call(void 0, g, job.box.w, job.box.h, _chunkWD5KO2FIcjs.inkStats.call(void 0, g)), () => ( text));
|
|
2088
2132
|
}
|
|
2089
2133
|
if (job.footer) {
|
|
2090
2134
|
if (!/^[-\u2013\u2014]?\s*(?:\d{1,4}|[ivxIVXⅰ-ⅹⅠ-Ⅹ]{1,4})\s*[-\u2013\u2014]?$/.test(text.trim())) continue;
|
|
@@ -2108,7 +2152,7 @@ var OcrEngine = class _OcrEngine {
|
|
|
2108
2152
|
continue;
|
|
2109
2153
|
}
|
|
2110
2154
|
const item = { text, ...this.itemBox(rgba, width, job.box, tuning), confidence };
|
|
2111
|
-
if (job.rot === 0)
|
|
2155
|
+
if (job.rot === 0) _chunkWD5KO2FIcjs.rememberOcrTextGaps.call(void 0, item, _chunkWD5KO2FIcjs.findOcrTextGaps.call(void 0, rgba, width, job.box, read, text, steps, stepPx));
|
|
2112
2156
|
if (job.rot === 0 && job.keep === void 0) boxOf.set(item, job.box);
|
|
2113
2157
|
items.push(item);
|
|
2114
2158
|
}
|
|
@@ -2122,7 +2166,7 @@ var OcrEngine = class _OcrEngine {
|
|
|
2122
2166
|
const merged = rereadNumberText(it.text, r.text);
|
|
2123
2167
|
if (merged === null) return;
|
|
2124
2168
|
it.text = merged;
|
|
2125
|
-
|
|
2169
|
+
_chunkWD5KO2FIcjs.rememberOcrTextGaps.call(void 0, it, _chunkWD5KO2FIcjs.findOcrTextGaps.call(void 0, rgba, width, boxOf.get(it), r.text, it.text, r.steps, r.stepPx));
|
|
2126
2170
|
});
|
|
2127
2171
|
}
|
|
2128
2172
|
const pairs = tuning.postprocess ? items.filter((it) => boxOf.has(it) && NUMBER_PAIR.test(it.text.trim())) : [];
|
|
@@ -2150,8 +2194,8 @@ var OcrEngine = class _OcrEngine {
|
|
|
2150
2194
|
const halves = [];
|
|
2151
2195
|
for (const it of tall) {
|
|
2152
2196
|
const b = boxOf.get(it);
|
|
2153
|
-
const gray =
|
|
2154
|
-
const cut = _nullishCoalesce(midBlankRow(gray, b.w, b.h,
|
|
2197
|
+
const gray = _chunkWD5KO2FIcjs.grayCrop.call(void 0, rgba, width, b);
|
|
2198
|
+
const cut = _nullishCoalesce(midBlankRow(gray, b.w, b.h, _chunkWD5KO2FIcjs.inkStats.call(void 0, gray)), () => ( valleyRow(gray, b.w, b.h, _chunkWD5KO2FIcjs.inkStats.call(void 0, gray))));
|
|
2155
2199
|
if (cut) halves.push({ it, top: { ...b, h: cut[0] }, bottom: { ...b, y: b.y + cut[1], h: b.h - cut[1] } });
|
|
2156
2200
|
}
|
|
2157
2201
|
const res = halves.length ? await this.recognizeJobs(rgba, width, halves.flatMap((hv, k) => [{ box: hv.top, rot: 0, group: 2 * k }, { box: hv.bottom, rot: 0, group: 2 * k + 1 }]), tuning.recBatch) : [];
|
|
@@ -2172,14 +2216,14 @@ var OcrEngine = class _OcrEngine {
|
|
|
2172
2216
|
const subs = [];
|
|
2173
2217
|
const stacks = [];
|
|
2174
2218
|
for (const b of [...retry, ...blank2]) {
|
|
2175
|
-
const gray =
|
|
2176
|
-
const ink =
|
|
2219
|
+
const gray = _chunkWD5KO2FIcjs.grayCrop.call(void 0, rgba, width, b);
|
|
2220
|
+
const ink = _chunkWD5KO2FIcjs.inkStats.call(void 0, gray);
|
|
2177
2221
|
const cut = retry.includes(b) ? midBlankRow(gray, b.w, b.h, ink) : null;
|
|
2178
2222
|
if (cut && b.w >= 3 * Math.max(cut[0], b.h - cut[1])) {
|
|
2179
2223
|
subs.push({ ...b, h: cut[0] }, { ...b, y: b.y + cut[1], h: b.h - cut[1] });
|
|
2180
2224
|
continue;
|
|
2181
2225
|
}
|
|
2182
|
-
const bands =
|
|
2226
|
+
const bands = _chunkWD5KO2FIcjs.stackedGlyphBands.call(void 0, gray, b.w, b.h, ink);
|
|
2183
2227
|
if (bands) stacks.push({ box: b, parts: bandBoxes(b, bands, height), word: bands.every((x, i) => i === 0 || x.y0 - bands[i - 1].y1 <= STACK_WORD_GAP * Math.max(x.y1 - x.y0, bands[i - 1].y1 - bands[i - 1].y0)) });
|
|
2184
2228
|
}
|
|
2185
2229
|
const overlap = (a, o) => Math.max(0, Math.min(a.x + a.w, o.x + o.w) - Math.max(a.x, o.x)) * Math.max(0, Math.min(a.y + a.h, o.y + o.h) - Math.max(a.y, o.y));
|
|
@@ -2258,8 +2302,8 @@ var OcrEngine = class _OcrEngine {
|
|
|
2258
2302
|
/** 결과 좌표 — det 박스 그대로 또는 박스 안 잉크 외곽 (tightBoxes) */
|
|
2259
2303
|
itemBox(rgba, width, b, tuning) {
|
|
2260
2304
|
if (!tuning.tightBoxes) return b;
|
|
2261
|
-
const gray =
|
|
2262
|
-
const t =
|
|
2305
|
+
const gray = _chunkWD5KO2FIcjs.grayCrop.call(void 0, rgba, width, b);
|
|
2306
|
+
const t = _chunkWD5KO2FIcjs.inkBounds.call(void 0, gray, b.w, b.h, _chunkWD5KO2FIcjs.inkStats.call(void 0, gray));
|
|
2263
2307
|
return { x: b.x + t.x0, y: b.y + t.y0, w: t.x1 - t.x0, h: t.y1 - t.y0 };
|
|
2264
2308
|
}
|
|
2265
2309
|
// ─── det ─────────────────────────────────────────────
|
|
@@ -2330,7 +2374,7 @@ var OcrEngine = class _OcrEngine {
|
|
|
2330
2374
|
const out = await this.rec.run({ [this.rec.inputNames[0]]: tensor });
|
|
2331
2375
|
const logits = out[this.rec.outputNames[0]];
|
|
2332
2376
|
const [, T, C] = logits.dims;
|
|
2333
|
-
if (C !== this.dict.length + 2) throw new (0,
|
|
2377
|
+
if (C !== this.dict.length + 2) throw new (0, _chunkWL6FHOXScjs.KordocError)(`OCR rec \uCD9C\uB825 \uD074\uB798\uC2A4 ${C}\uAC1C\uAC00 \uC0AC\uC804 ${this.dict.length}\uC790 + 2 \uC640 \uB2E4\uB985\uB2C8\uB2E4 \u2014 \uBAA8\uB378\uC5D0 \uB9DE\uB294 \uC0AC\uC804(ocrRecDict)\uC744 \uC9C0\uC815\uD558\uC138\uC694`);
|
|
2334
2378
|
const data = logits.data;
|
|
2335
2379
|
idx.forEach((ci, k) => {
|
|
2336
2380
|
const r = ctcDecode(data.subarray(k * T * C, (k + 1) * T * C), T, C, this.dict);
|
|
@@ -2340,9 +2384,9 @@ var OcrEngine = class _OcrEngine {
|
|
|
2340
2384
|
const chars = r ? [...r.text] : [];
|
|
2341
2385
|
if (r && job.rot === 0 && chars.length === r.steps.length && r.steps.some((t) => t > last) && !r.text.includes("(cid:")) {
|
|
2342
2386
|
const tallCh = (c) => !/[\s.,:;\u00b7\u2026'"\u2018-\u201d`\-_~]/.test(c);
|
|
2343
|
-
const g =
|
|
2387
|
+
const g = _chunkWD5KO2FIcjs.grayCrop.call(void 0, rgba, pageW, job.box);
|
|
2344
2388
|
const inside = chars.filter((c, i) => r.steps[i] <= last && tallCh(c)).length;
|
|
2345
|
-
let budget = inside <= 2 ?
|
|
2389
|
+
let budget = inside <= 2 ? _chunkWD5KO2FIcjs.tallInkCount.call(void 0, g, job.box.w, job.box.h, _chunkWD5KO2FIcjs.inkStats.call(void 0, g)) - inside : Infinity;
|
|
2346
2390
|
const keep = chars.map((c, i) => r.steps[i] <= last || !tallCh(c) || budget-- > 0);
|
|
2347
2391
|
if (!keep.every(Boolean)) kept = { ...r, text: chars.filter((_, i) => keep[i]).join(""), steps: r.steps.filter((_, i) => keep[i]) };
|
|
2348
2392
|
}
|
|
@@ -2453,13 +2497,13 @@ async function tryImport(name, loader) {
|
|
|
2453
2497
|
return await loader();
|
|
2454
2498
|
} catch (e) {
|
|
2455
2499
|
throw new Error(
|
|
2456
|
-
`\uB0B4\uC7A5 OCR \uC744 \uC0AC\uC6A9\uD558\uB824\uBA74 optional dependency '${name}' \uC774 \uD544\uC694\uD569\uB2C8\uB2E4. \`npm install ${name}\` \uD6C4 \uB2E4\uC2DC \uC2E4\uD589\uD558\uC138\uC694.${
|
|
2500
|
+
`\uB0B4\uC7A5 OCR \uC744 \uC0AC\uC6A9\uD558\uB824\uBA74 optional dependency '${name}' \uC774 \uD544\uC694\uD569\uB2C8\uB2E4. \`npm install ${name}\` \uD6C4 \uB2E4\uC2DC \uC2E4\uD589\uD558\uC138\uC694.${_chunkWL6FHOXScjs.OPTIONAL_DEP_INSTALL_HINT} \uC6D0\uC778: ${e.message}`
|
|
2457
2501
|
);
|
|
2458
2502
|
}
|
|
2459
2503
|
}
|
|
2460
2504
|
async function verifiedBytes(s) {
|
|
2461
2505
|
const name = _path.basename.call(void 0, s.file.path);
|
|
2462
|
-
const fail = (why2) => new (0,
|
|
2506
|
+
const fail = (why2) => new (0, _chunkWL6FHOXScjs.KordocError)(`OCR \uBAA8\uB378 \uD30C\uC77C\uC744 \uC77D\uC9C0 \uBABB\uD588\uC2B5\uB2C8\uB2E4: ${name} (${why2})`);
|
|
2463
2507
|
const why = (e) => {
|
|
2464
2508
|
const code = e.code;
|
|
2465
2509
|
return code === "ENOENT" ? "\uD30C\uC77C\uC774 \uC5C6\uC74C" : code === "EACCES" || code === "EPERM" ? "\uAD8C\uD55C \uC5C6\uC74C" : "\uC77D\uAE30 \uC2E4\uD328";
|
|
@@ -2480,13 +2524,13 @@ async function verifiedBytes(s) {
|
|
|
2480
2524
|
}
|
|
2481
2525
|
const actual = _crypto.createHash.call(void 0, "sha256").update(bytes).digest("hex");
|
|
2482
2526
|
if (actual !== s.file.sha256) {
|
|
2483
|
-
throw new (0,
|
|
2527
|
+
throw new (0, _chunkWL6FHOXScjs.KordocError)(`OCR \uBAA8\uB378 SHA256 mismatch: ${_path.basename.call(void 0, s.file.path)} \u2014 expected ${s.file.sha256}, got ${actual} (\uB85C\uB4DC \uAC70\uBD80)`);
|
|
2484
2528
|
}
|
|
2485
2529
|
return bytes;
|
|
2486
2530
|
}
|
|
2487
2531
|
var engines = /* @__PURE__ */ new Map();
|
|
2488
|
-
function getOcrEngine(models =
|
|
2489
|
-
const key =
|
|
2532
|
+
function getOcrEngine(models = _chunkWD5KO2FIcjs.DEFAULT_OCR_MODELS) {
|
|
2533
|
+
const key = _chunkWD5KO2FIcjs.ocrSelectionKey.call(void 0, models);
|
|
2490
2534
|
let p = engines.get(key);
|
|
2491
2535
|
if (!p) {
|
|
2492
2536
|
p = OcrEngine.create(models).catch((err) => {
|
|
@@ -2962,20 +3006,20 @@ var REDETECT = { minDropped: 15, minShare: 0.15, scale: 5 / 3 };
|
|
|
2962
3006
|
var AUTO_REC = { pageConf: 0.9, gain: 0.06 };
|
|
2963
3007
|
var DEFAULT_AUTO_REC = { pageConf: 0.9, gain: 0.08, altConf: 0.95, sureGain: 0.1, minDiff: 0.08, minChars: 80, lazy: true };
|
|
2964
3008
|
var DEFAULT_BUILTIN_OCR = Object.freeze({
|
|
2965
|
-
models:
|
|
3009
|
+
models: _chunkWD5KO2FIcjs.DEFAULT_OCR_MODELS,
|
|
2966
3010
|
tuning: DEFAULT_OCR_TUNING,
|
|
2967
|
-
handwriting:
|
|
3011
|
+
handwriting: _chunkWD5KO2FIcjs.handwritingFallbackModels.call(void 0, _chunkWD5KO2FIcjs.DEFAULT_OCR_MODELS),
|
|
2968
3012
|
autoRec: DEFAULT_AUTO_REC
|
|
2969
3013
|
});
|
|
2970
3014
|
var DEFAULT_BUILTIN_OCR_FETCH = Object.freeze({ ...DEFAULT_BUILTIN_OCR, autoRec: { ...DEFAULT_AUTO_REC, fetch: true } });
|
|
2971
3015
|
function builtinOcrConfig(o) {
|
|
2972
3016
|
if (!o || o.ocrDet === void 0 && o.ocrDetLongSide === void 0 && o.ocrRec === void 0 && o.ocrRecDict === void 0 && !o.ocrLines) return _optionalChain([o, 'optionalAccess', _78 => _78.ocr]) ? DEFAULT_BUILTIN_OCR_FETCH : DEFAULT_BUILTIN_OCR;
|
|
2973
3017
|
const bad = _chunkMMK32GPDcjs.validateOcrOptions.call(void 0, o);
|
|
2974
|
-
if (bad) throw new (0,
|
|
2975
|
-
const models =
|
|
3018
|
+
if (bad) throw new (0, _chunkWL6FHOXScjs.KordocError)(bad);
|
|
3019
|
+
const models = _chunkWD5KO2FIcjs.resolveOcrModels.call(void 0, o);
|
|
2976
3020
|
return {
|
|
2977
3021
|
models,
|
|
2978
|
-
...o.ocrRec === "auto" ? { handwriting:
|
|
3022
|
+
...o.ocrRec === "auto" ? { handwriting: _chunkWD5KO2FIcjs.handwritingFallbackModels.call(void 0, models), autoRec: AUTO_REC } : o.ocrRec === void 0 ? { handwriting: _chunkWD5KO2FIcjs.handwritingFallbackModels.call(void 0, models), autoRec: o.ocr ? { ...DEFAULT_AUTO_REC, fetch: true } : DEFAULT_AUTO_REC } : {},
|
|
2979
3023
|
tuning: o.ocrDetLongSide === void 0 ? DEFAULT_OCR_TUNING : { ...DEFAULT_OCR_TUNING, detLongSide: o.ocrDetLongSide },
|
|
2980
3024
|
lines: o.ocrLines === "all" ? "all" : o.ocrLines ? "kept" : void 0
|
|
2981
3025
|
};
|
|
@@ -3001,8 +3045,8 @@ async function withHandwritingRec(items, config, tuning, rgba, width, height, st
|
|
|
3001
3045
|
const altStats = { droppedLowConf: 0, ...stats.dropped ? { dropped: [] } : {} };
|
|
3002
3046
|
let alt;
|
|
3003
3047
|
try {
|
|
3004
|
-
if (auto.lazy && !auto.fetch && !await
|
|
3005
|
-
if (auto.lazy) await
|
|
3048
|
+
if (auto.lazy && !auto.fetch && !await _chunkWD5KO2FIcjs.ocrModelsCached.call(void 0, config.handwriting)) return items;
|
|
3049
|
+
if (auto.lazy) await _chunkWD5KO2FIcjs.ensureOcrModelsFor.call(void 0, config.handwriting, reportModelDownload);
|
|
3006
3050
|
alt = await (await getOcrEngine(config.handwriting)).recognizePage(rgba, width, height, altStats, tuning, cellRules, rowRules);
|
|
3007
3051
|
} catch (e) {
|
|
3008
3052
|
if (!auto.lazy) throw e;
|
|
@@ -3048,8 +3092,8 @@ async function runPdfOcr(buffer, targets, mode, warnings, onProgress, detectTabl
|
|
|
3048
3092
|
"@hyzyla/pdfium",
|
|
3049
3093
|
() => Promise.resolve().then(() => _interopRequireWildcard(require("@hyzyla/pdfium")))
|
|
3050
3094
|
);
|
|
3051
|
-
if (mode === "builtin") await
|
|
3052
|
-
if (mode === "builtin" && config.handwriting && !_optionalChain([config, 'access', _79 => _79.autoRec, 'optionalAccess', _80 => _80.lazy])) await
|
|
3095
|
+
if (mode === "builtin") await _chunkWD5KO2FIcjs.ensureOcrModelsFor.call(void 0, config.models, reportModelDownload);
|
|
3096
|
+
if (mode === "builtin" && config.handwriting && !_optionalChain([config, 'access', _79 => _79.autoRec, 'optionalAccess', _80 => _80.lazy])) await _chunkWD5KO2FIcjs.ensureOcrModelsFor.call(void 0, config.handwriting, reportModelDownload);
|
|
3053
3097
|
const engine = mode === "builtin" ? await getOcrEngine(config.models) : null;
|
|
3054
3098
|
const pdfium = await pdfiumMod.PDFiumLibrary.init();
|
|
3055
3099
|
const doc = await pdfium.loadDocument(new Uint8Array(buffer));
|
|
@@ -3098,6 +3142,7 @@ async function ocrOnePage(page, pageNo, mode, engine, warnings, detectTables, ve
|
|
|
3098
3142
|
let { rgba: upright, angle } = vectorOps || regions ? { rgba, angle: 0 } : deskewPage(rgba, rw, rh);
|
|
3099
3143
|
const stats = { droppedLowConf: 0, ...config.lines === "all" ? { dropped: [] } : {} };
|
|
3100
3144
|
let ruling = vectorOps ? void 0 : detectRulingLines(upright, rw, rh, rh / pdfH);
|
|
3145
|
+
if (ruling && regions) ruling = { ...ruling, horizontals: ruling.horizontals.filter((h) => !h.isolated) };
|
|
3101
3146
|
const tuning = regions ? regionTuning(config.tuning) : vectorOps ? { ...config.tuning, orientPage: false } : config.tuning;
|
|
3102
3147
|
let items = await recognizeOcrPage(
|
|
3103
3148
|
engine,
|
|
@@ -3161,7 +3206,7 @@ async function ocrOnePage(page, pageNo, mode, engine, warnings, detectTables, ve
|
|
|
3161
3206
|
const x1 = r.x1 * scale - 2, x2 = r.x2 * scale + 2, y1 = (pdfH - r.y2) * scale - 2, y2 = (pdfH - r.y1) * scale + 2;
|
|
3162
3207
|
const columnRules = _nullishCoalesce(_optionalChain([ruling, 'optionalAccess', _89 => _89.verticals, 'access', _90 => _90.filter, 'call', _91 => _91((s) => Math.min(s.x1, s.x2) >= x1 && Math.max(s.x1, s.x2) <= x2 && Math.min(s.y1, s.y2) >= y1 && Math.max(s.y1, s.y2) <= y2), 'access', _92 => _92.length]), () => ( 0));
|
|
3163
3208
|
if (columnRules < 2) {
|
|
3164
|
-
for (const b of blocks) if (b.type === "table")
|
|
3209
|
+
for (const b of blocks) if (b.type === "table") _chunkWD5KO2FIcjs.UNRULED_REGION_TABLES.add(b);
|
|
3165
3210
|
}
|
|
3166
3211
|
return blocks;
|
|
3167
3212
|
});
|
|
@@ -3233,7 +3278,7 @@ async function closerReads(rgba, rw, rh, pdfH, hi, regions, engine, tuning = REG
|
|
|
3233
3278
|
const items = await engine.recognizePage(crop, cw, ch, void 0, tuning);
|
|
3234
3279
|
out.push(items.map((it) => {
|
|
3235
3280
|
const placed = { ...it, x: (it.x + x0) / 2, y: (it.y + y0) / 2, w: it.w / 2, h: it.h / 2 };
|
|
3236
|
-
|
|
3281
|
+
_chunkWD5KO2FIcjs.copyOcrTextGaps.call(void 0, it, placed, 0.5, x0 / 2);
|
|
3237
3282
|
return placed;
|
|
3238
3283
|
}));
|
|
3239
3284
|
}
|
|
@@ -3325,7 +3370,7 @@ function ocrItemsToBlocks(items, pageNumber, pdfW, pdfH, scale, extraLines, dete
|
|
|
3325
3370
|
isHidden: false,
|
|
3326
3371
|
...xs[i].space ? { hasSpaceBefore: true } : {}
|
|
3327
3372
|
};
|
|
3328
|
-
|
|
3373
|
+
_chunkWD5KO2FIcjs.copyOcrTextGaps.call(void 0, it, normalized, 1 / scale);
|
|
3329
3374
|
return normalized;
|
|
3330
3375
|
}).filter((it) => it.text);
|
|
3331
3376
|
if (_optionalChain([extraLines, 'optionalAccess', _96 => _96.verticals, 'access', _97 => _97.length]) && items.length) {
|
|
@@ -3341,7 +3386,7 @@ function ocrItemsToBlocks(items, pageNumber, pdfW, pdfH, scale, extraLines, dete
|
|
|
3341
3386
|
})
|
|
3342
3387
|
};
|
|
3343
3388
|
}
|
|
3344
|
-
const laid = unframeOcrLayoutTables(splitOcrJoinedHeaders(splitOcrContactColumns(splitOcrNameValueColumns(splitStackedOcrRows(
|
|
3389
|
+
const laid = unframeOcrLayoutTables(splitOcrJoinedHeaders(splitOcrContactColumns(splitOcrNameValueColumns(splitStackedOcrRows(_chunkWD5KO2FIcjs.extractPageBlocksWithLines.call(void 0, norm, pageNumber, opList, pdfW, pdfH, extraLines, detectTables))))), pdfH);
|
|
3345
3390
|
const blocks = figureRegion ? laid : splitOcrProseRows(laid);
|
|
3346
3391
|
if (!figureRegion) markOcrHeadings(blocks);
|
|
3347
3392
|
return blocks;
|
|
@@ -3402,7 +3447,7 @@ async function tryImport2(name, loader) {
|
|
|
3402
3447
|
return await loader();
|
|
3403
3448
|
} catch (e) {
|
|
3404
3449
|
throw new Error(
|
|
3405
|
-
`OCR \uC744 \uC0AC\uC6A9\uD558\uB824\uBA74 optional dependency '${name}' \uC774 \uD544\uC694\uD569\uB2C8\uB2E4. \`npm install ${name}\` \uD6C4 \uB2E4\uC2DC \uC2E4\uD589\uD558\uC138\uC694.${
|
|
3450
|
+
`OCR \uC744 \uC0AC\uC6A9\uD558\uB824\uBA74 optional dependency '${name}' \uC774 \uD544\uC694\uD569\uB2C8\uB2E4. \`npm install ${name}\` \uD6C4 \uB2E4\uC2DC \uC2E4\uD589\uD558\uC138\uC694.${_chunkWL6FHOXScjs.OPTIONAL_DEP_INSTALL_HINT} \uC6D0\uC778: ${e.message}`
|
|
3406
3451
|
);
|
|
3407
3452
|
}
|
|
3408
3453
|
}
|
|
@@ -3455,4 +3500,4 @@ function bgraToRgba(bgra) {
|
|
|
3455
3500
|
|
|
3456
3501
|
|
|
3457
3502
|
exports.rescueEmptyCells = rescueEmptyCells; exports.getOcrEngine = getOcrEngine; exports.detectRulingLines = detectRulingLines; exports.rulingToPdfLines = rulingToPdfLines; exports.deskewPage = deskewPage; exports.rotateQuarter = rotateQuarter; exports.MAX_OCR_PIXELS = MAX_OCR_PIXELS; exports.DEFAULT_BUILTIN_OCR = DEFAULT_BUILTIN_OCR; exports.builtinOcrConfig = builtinOcrConfig; exports.recognizeOcrPage = recognizeOcrPage; exports.reportModelDownload = reportModelDownload; exports.toOcrLine = toOcrLine; exports.pageLines = pageLines; exports.cellEdgeVerticals = cellEdgeVerticals; exports.cellEdgeHorizontals = cellEdgeHorizontals; exports.runPdfOcr = runPdfOcr; exports.ocrOnePage = ocrOnePage; exports.stretchFaintCrop = stretchFaintCrop; exports.groupOcrLines = groupOcrLines; exports.ocrItemsToBlocks = ocrItemsToBlocks; exports.markOcrHeadings = markOcrHeadings;
|
|
3458
|
-
//# sourceMappingURL=chunk-
|
|
3503
|
+
//# sourceMappingURL=chunk-JMCNY622.cjs.map
|