kordoc 4.24.41 → 4.24.43
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/{-5XLO3RHD.js → -IRTEUGHT.js} +22 -22
- package/dist/{chunk-EPZVMBAQ.js → chunk-33ULZVQN.js} +2 -2
- package/dist/{chunk-2IK2Z6PO.js → chunk-5ZQSDJC3.js} +2 -2
- package/dist/{chunk-JBQ5R4VV.js → chunk-6BAC5WKC.js} +2 -2
- package/dist/{chunk-SGBD6MTI.js → chunk-76KKAGSR.js} +2 -2
- package/dist/{chunk-HR72SA4M.cjs → chunk-7IH2L2WW.cjs} +58 -58
- package/dist/chunk-7IH2L2WW.cjs.map +1 -0
- package/dist/{chunk-TVMNTRPZ.cjs → chunk-7NTFM2LI.cjs} +210 -109
- package/dist/chunk-7NTFM2LI.cjs.map +1 -0
- package/dist/{chunk-5QMMROCA.cjs → chunk-7OKHYNFV.cjs} +3 -3
- package/dist/chunk-7OKHYNFV.cjs.map +1 -0
- package/dist/{chunk-WYJWJ7X4.js → chunk-7QC674TF.js} +2 -2
- package/dist/{chunk-GYMAGQNQ.js → chunk-7V4BBIXX.js} +6 -6
- package/dist/{chunk-KTWCSSNS.js → chunk-AAC4TTOA.js} +10 -10
- package/dist/chunk-ARVHYL3V.cjs.map +1 -1
- package/dist/{chunk-TWFL7T4K.js → chunk-BAGUU5RD.js} +2 -2
- package/dist/{chunk-FVYTDR6E.js → chunk-BEME7VXP.js} +127 -26
- package/dist/chunk-BEME7VXP.js.map +1 -0
- package/dist/{chunk-2CHSOHDE.js → chunk-BMCX5UMC.js} +2 -2
- package/dist/{chunk-ZOCDODX3.js → chunk-C2EXMJOO.js} +2 -2
- package/dist/{chunk-IXFRVO7E.js → chunk-C5JLH7GR.js} +3 -3
- package/dist/chunk-DEVQZTE7.cjs.map +1 -1
- package/dist/{chunk-XPYC55DA.js → chunk-FE5IIPCV.js} +5 -5
- package/dist/{chunk-TJARBWAJ.cjs → chunk-FEHNN7XX.cjs} +98 -98
- package/dist/chunk-FEHNN7XX.cjs.map +1 -0
- package/dist/{chunk-OPE2XDGY.js → chunk-G6HFTS4C.js} +5 -5
- package/dist/chunk-GS7T56RP.cjs.map +1 -1
- package/dist/{chunk-5QHQ56AK.js → chunk-GVPNAYLT.js} +114 -22
- package/dist/chunk-GVPNAYLT.js.map +1 -0
- package/dist/{chunk-UI3SZQXC.js → chunk-HDSIUJ32.js} +6 -6
- package/dist/{chunk-C2YUJXHB.js → chunk-IGHNUSHZ.js} +13 -6
- package/dist/chunk-IGHNUSHZ.js.map +1 -0
- package/dist/{chunk-JIMG76FW.js → chunk-IIOBUTXH.js} +3 -3
- package/dist/chunk-IIOBUTXH.js.map +1 -0
- package/dist/chunk-J55UQC5H.cjs.map +1 -1
- package/dist/{chunk-WNOSEEBH.cjs → chunk-JIBNIVOO.cjs} +51 -44
- package/dist/chunk-JIBNIVOO.cjs.map +1 -0
- package/dist/{chunk-ZUFIMOGS.js → chunk-KEQPJMTT.js} +16 -16
- package/dist/chunk-LAYKIZOX.cjs.map +1 -1
- package/dist/{chunk-QNXWOUWQ.js → chunk-LWOXK3IX.js} +2 -2
- package/dist/{chunk-IHMDGE7Z.cjs → chunk-M5TNYNFH.cjs} +3 -3
- package/dist/chunk-M5TNYNFH.cjs.map +1 -0
- package/dist/{chunk-EPR3TQS3.js → chunk-MK4AAGEC.js} +2 -2
- package/dist/{chunk-ZTN3T3GH.cjs → chunk-MMK32GPD.cjs} +3 -3
- package/dist/chunk-MMK32GPD.cjs.map +1 -0
- package/dist/{chunk-K2AVB6ZW.js → chunk-N3SXIWQU.js} +3 -3
- package/dist/{chunk-MZ7AGKAN.js → chunk-N4OJTOFQ.js} +3 -3
- package/dist/chunk-N4OJTOFQ.js.map +1 -0
- package/dist/{chunk-ZDTP5IJU.js → chunk-NXDKVHHA.js} +2 -2
- package/dist/{chunk-KF6MJIPV.js → chunk-NYFEI3EQ.js} +11 -11
- package/dist/{chunk-SV462GOK.js → chunk-OPVQA7LF.js} +2 -2
- package/dist/{chunk-3GJ3CMYS.js → chunk-PILZTDAP.js} +2 -2
- package/dist/{chunk-C5XJDCXW.js → chunk-QSCYLSRQ.js} +2 -2
- package/dist/{chunk-C5XJDCXW.js.map → chunk-QSCYLSRQ.js.map} +1 -1
- package/dist/{chunk-TGKYTBQ2.js → chunk-S4ATZL42.js} +3 -3
- package/dist/{chunk-IFWGHRCQ.js → chunk-TBGGAR7W.js} +3 -3
- package/dist/chunk-TBGGAR7W.js.map +1 -0
- package/dist/chunk-TK3FDAEE.cjs.map +1 -1
- package/dist/{chunk-57LVGVIS.js → chunk-TM5FVUIO.js} +2 -2
- package/dist/{chunk-NHDOSQZ6.js → chunk-UCKNBTHB.js} +5 -5
- package/dist/{chunk-HJGKVI7D.cjs → chunk-VALBVWMT.cjs} +267 -175
- package/dist/chunk-VALBVWMT.cjs.map +1 -0
- package/dist/chunk-X7RBVVDC.cjs.map +1 -1
- package/dist/{chunk-CCGGLBHD.js → chunk-XSV4LNHT.js} +7 -7
- package/dist/{chunk-S7TKYRJB.js → chunk-XWDOEEZ4.js} +2 -2
- package/dist/{chunk-JZEMASGR.cjs → chunk-XXBO2VOS.cjs} +2 -2
- package/dist/chunk-XXBO2VOS.cjs.map +1 -0
- package/dist/{chunk-XBWP6REN.js → chunk-YGYTO25K.js} +13 -6
- package/dist/chunk-YGYTO25K.js.map +1 -0
- package/dist/{chunk-KQDO246G.js → chunk-YNZLXX6K.js} +126 -25
- package/dist/chunk-YNZLXX6K.js.map +1 -0
- package/dist/{chunk-UHN5TULI.js → chunk-ZN2NJJ2O.js} +116 -24
- package/dist/chunk-ZN2NJJ2O.js.map +1 -0
- package/dist/chunks-RIY64UXL.js +11 -0
- package/dist/cli.js +46 -46
- package/dist/cli.js.map +1 -1
- package/dist/detect-V75ERMYL.cjs.map +1 -1
- package/dist/{formula-3X2Y6F6V.js → formula-64GAGC5P.js} +3 -3
- package/dist/{formula-IBE4CZ5R.js → formula-FXF2LEG5.js} +4 -4
- package/dist/{formula-4WGDQBOM.cjs → formula-NBGGSBED.cjs} +9 -9
- package/dist/formula-NBGGSBED.cjs.map +1 -0
- package/dist/generator-4C4FJT5F.js +17 -0
- package/dist/generator-V4DLZW4V.js +10 -0
- package/dist/generator-YELVMNZ5.cjs +11 -0
- package/dist/generator-YELVMNZ5.cjs.map +1 -0
- package/dist/{hancom-CBYVMPCO.js → hancom-55JUQI42.js} +2 -2
- package/dist/{hancom-YR2BB373.cjs → hancom-JGMDQQRF.cjs} +5 -5
- package/dist/hancom-JGMDQQRF.cjs.map +1 -0
- package/dist/{hancom-UACA2WTF.js → hancom-WUWPCXXC.js} +2 -2
- package/dist/{image-ocr-2CUGPHIK.js → image-ocr-C2IOYE4F.js} +12 -12
- package/dist/image-ocr-C2IOYE4F.js.map +1 -0
- package/dist/{image-ocr-JEHNWQVE.js → image-ocr-NRMLGRWH.js} +9 -9
- package/dist/image-ocr-NRMLGRWH.js.map +1 -0
- package/dist/{image-ocr-RNAJ66EN.cjs → image-ocr-VVQWPQJR.cjs} +29 -29
- package/dist/image-ocr-VVQWPQJR.cjs.map +1 -0
- package/dist/index.cjs +1107 -1107
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -5
- package/dist/index.d.ts +6 -5
- package/dist/index.js +10 -10
- package/dist/mcp.js +38 -38
- package/dist/mcp.js.map +1 -1
- package/dist/memo-RGYHUBXN.js +17 -0
- package/dist/{model-bundle-HLPWOTCS.js → model-bundle-7F7HKKNW.js} +5 -5
- package/dist/{models-AMOW56WP.js → models-XNTWLTIS.js} +5 -5
- package/dist/page-range-QHHFTL7X.cjs.map +1 -1
- package/dist/{parse-worker-v2-Z4BCWVRX.js → parse-worker-v2-2646BGLS.js} +24 -24
- package/dist/parse-worker-v2-2646BGLS.js.map +1 -0
- package/dist/{parser-Y4GUP7PZ.js → parser-6RBMOISN.js} +13 -13
- package/dist/{parser-YMNUQBLB.js → parser-LKFBXGDV.js} +10 -10
- package/dist/{parser-D2DQIUP3.cjs → parser-ZGJQD5ZA.cjs} +161 -161
- package/dist/parser-ZGJQD5ZA.cjs.map +1 -0
- package/dist/{pdf-ocr-EPIM3YWE.js → pdf-ocr-FAA3Q5BD.js} +7 -7
- package/dist/{pdf-ocr-3K266ENT.js → pdf-ocr-J34PHJMP.js} +10 -10
- package/dist/pdf-ocr-WIBDU5H4.cjs +40 -0
- package/dist/pdf-ocr-WIBDU5H4.cjs.map +1 -0
- package/dist/{profile-io-AW4GEYDQ.js → profile-io-J3H52L4Y.js} +3 -3
- package/dist/{rasterize-75AWRNSO.js → rasterize-3FG4H7WX.js} +3 -3
- package/dist/{redact-doc-3UUPTXFI.js → redact-doc-CCLWNWAN.js} +22 -22
- package/dist/{render-JGMRAI2P.js → render-VQA2XY6S.js} +12 -12
- package/dist/{rewrite-fallback-UDQAKQN2.js → rewrite-fallback-R52RR5NL.js} +13 -13
- package/dist/seal-3P5RJIID.js +16 -0
- package/dist/{setup-JTHBR676.js → setup-75BEQHOQ.js} +3 -3
- package/dist/{to-hwpx-GJP66LQS.js → to-hwpx-HQTEFNV5.js} +7 -7
- package/dist/{to-hwpx-ZD7IGU7G.js → to-hwpx-HR33KFDQ.js} +4 -4
- package/dist/to-hwpx-NHRRWZGB.cjs +16 -0
- package/dist/to-hwpx-NHRRWZGB.cjs.map +1 -0
- package/dist/visual-OZTTV577.js +37 -0
- package/dist/{watch-QL4YAMRV.js → watch-AZ7OMTXR.js} +23 -23
- package/package.json +1 -1
- package/dist/chunk-5QHQ56AK.js.map +0 -1
- package/dist/chunk-5QMMROCA.cjs.map +0 -1
- package/dist/chunk-C2YUJXHB.js.map +0 -1
- package/dist/chunk-FVYTDR6E.js.map +0 -1
- package/dist/chunk-HJGKVI7D.cjs.map +0 -1
- package/dist/chunk-HR72SA4M.cjs.map +0 -1
- package/dist/chunk-IFWGHRCQ.js.map +0 -1
- package/dist/chunk-IHMDGE7Z.cjs.map +0 -1
- package/dist/chunk-JIMG76FW.js.map +0 -1
- package/dist/chunk-JZEMASGR.cjs.map +0 -1
- package/dist/chunk-KQDO246G.js.map +0 -1
- package/dist/chunk-MZ7AGKAN.js.map +0 -1
- package/dist/chunk-TJARBWAJ.cjs.map +0 -1
- package/dist/chunk-TVMNTRPZ.cjs.map +0 -1
- package/dist/chunk-UHN5TULI.js.map +0 -1
- package/dist/chunk-WNOSEEBH.cjs.map +0 -1
- package/dist/chunk-XBWP6REN.js.map +0 -1
- package/dist/chunk-ZTN3T3GH.cjs.map +0 -1
- package/dist/chunks-23JEOBIH.js +0 -11
- package/dist/formula-4WGDQBOM.cjs.map +0 -1
- package/dist/generator-JYJLWH7T.js +0 -17
- package/dist/generator-PGOJNK7D.js +0 -10
- package/dist/generator-ZRVKK7UG.cjs +0 -11
- package/dist/generator-ZRVKK7UG.cjs.map +0 -1
- package/dist/hancom-YR2BB373.cjs.map +0 -1
- package/dist/image-ocr-2CUGPHIK.js.map +0 -1
- package/dist/image-ocr-JEHNWQVE.js.map +0 -1
- package/dist/image-ocr-RNAJ66EN.cjs.map +0 -1
- package/dist/memo-V24MEWBZ.js +0 -17
- package/dist/parse-worker-v2-Z4BCWVRX.js.map +0 -1
- package/dist/parser-D2DQIUP3.cjs.map +0 -1
- package/dist/pdf-ocr-OX7H7NOU.cjs +0 -40
- package/dist/pdf-ocr-OX7H7NOU.cjs.map +0 -1
- package/dist/seal-WFNKTHBW.js +0 -16
- package/dist/to-hwpx-LKPXAHSQ.cjs +0 -16
- package/dist/to-hwpx-LKPXAHSQ.cjs.map +0 -1
- package/dist/visual-666SNQ3Y.js +0 -37
- /package/dist/{-5XLO3RHD.js.map → -IRTEUGHT.js.map} +0 -0
- /package/dist/{chunk-EPZVMBAQ.js.map → chunk-33ULZVQN.js.map} +0 -0
- /package/dist/{chunk-2IK2Z6PO.js.map → chunk-5ZQSDJC3.js.map} +0 -0
- /package/dist/{chunk-JBQ5R4VV.js.map → chunk-6BAC5WKC.js.map} +0 -0
- /package/dist/{chunk-SGBD6MTI.js.map → chunk-76KKAGSR.js.map} +0 -0
- /package/dist/{chunk-WYJWJ7X4.js.map → chunk-7QC674TF.js.map} +0 -0
- /package/dist/{chunk-GYMAGQNQ.js.map → chunk-7V4BBIXX.js.map} +0 -0
- /package/dist/{chunk-KTWCSSNS.js.map → chunk-AAC4TTOA.js.map} +0 -0
- /package/dist/{chunk-TWFL7T4K.js.map → chunk-BAGUU5RD.js.map} +0 -0
- /package/dist/{chunk-2CHSOHDE.js.map → chunk-BMCX5UMC.js.map} +0 -0
- /package/dist/{chunk-ZOCDODX3.js.map → chunk-C2EXMJOO.js.map} +0 -0
- /package/dist/{chunk-IXFRVO7E.js.map → chunk-C5JLH7GR.js.map} +0 -0
- /package/dist/{chunk-XPYC55DA.js.map → chunk-FE5IIPCV.js.map} +0 -0
- /package/dist/{chunk-OPE2XDGY.js.map → chunk-G6HFTS4C.js.map} +0 -0
- /package/dist/{chunk-UI3SZQXC.js.map → chunk-HDSIUJ32.js.map} +0 -0
- /package/dist/{chunk-ZUFIMOGS.js.map → chunk-KEQPJMTT.js.map} +0 -0
- /package/dist/{chunk-QNXWOUWQ.js.map → chunk-LWOXK3IX.js.map} +0 -0
- /package/dist/{chunk-EPR3TQS3.js.map → chunk-MK4AAGEC.js.map} +0 -0
- /package/dist/{chunk-K2AVB6ZW.js.map → chunk-N3SXIWQU.js.map} +0 -0
- /package/dist/{chunk-ZDTP5IJU.js.map → chunk-NXDKVHHA.js.map} +0 -0
- /package/dist/{chunk-KF6MJIPV.js.map → chunk-NYFEI3EQ.js.map} +0 -0
- /package/dist/{chunk-SV462GOK.js.map → chunk-OPVQA7LF.js.map} +0 -0
- /package/dist/{chunk-3GJ3CMYS.js.map → chunk-PILZTDAP.js.map} +0 -0
- /package/dist/{chunk-TGKYTBQ2.js.map → chunk-S4ATZL42.js.map} +0 -0
- /package/dist/{chunk-57LVGVIS.js.map → chunk-TM5FVUIO.js.map} +0 -0
- /package/dist/{chunk-NHDOSQZ6.js.map → chunk-UCKNBTHB.js.map} +0 -0
- /package/dist/{chunk-CCGGLBHD.js.map → chunk-XSV4LNHT.js.map} +0 -0
- /package/dist/{chunk-S7TKYRJB.js.map → chunk-XWDOEEZ4.js.map} +0 -0
- /package/dist/{chunks-23JEOBIH.js.map → chunks-RIY64UXL.js.map} +0 -0
- /package/dist/{formula-3X2Y6F6V.js.map → formula-64GAGC5P.js.map} +0 -0
- /package/dist/{formula-IBE4CZ5R.js.map → formula-FXF2LEG5.js.map} +0 -0
- /package/dist/{generator-JYJLWH7T.js.map → generator-4C4FJT5F.js.map} +0 -0
- /package/dist/{generator-PGOJNK7D.js.map → generator-V4DLZW4V.js.map} +0 -0
- /package/dist/{hancom-CBYVMPCO.js.map → hancom-55JUQI42.js.map} +0 -0
- /package/dist/{hancom-UACA2WTF.js.map → hancom-WUWPCXXC.js.map} +0 -0
- /package/dist/{memo-V24MEWBZ.js.map → memo-RGYHUBXN.js.map} +0 -0
- /package/dist/{model-bundle-HLPWOTCS.js.map → model-bundle-7F7HKKNW.js.map} +0 -0
- /package/dist/{models-AMOW56WP.js.map → models-XNTWLTIS.js.map} +0 -0
- /package/dist/{parser-Y4GUP7PZ.js.map → parser-6RBMOISN.js.map} +0 -0
- /package/dist/{parser-YMNUQBLB.js.map → parser-LKFBXGDV.js.map} +0 -0
- /package/dist/{pdf-ocr-3K266ENT.js.map → pdf-ocr-FAA3Q5BD.js.map} +0 -0
- /package/dist/{pdf-ocr-EPIM3YWE.js.map → pdf-ocr-J34PHJMP.js.map} +0 -0
- /package/dist/{profile-io-AW4GEYDQ.js.map → profile-io-J3H52L4Y.js.map} +0 -0
- /package/dist/{rasterize-75AWRNSO.js.map → rasterize-3FG4H7WX.js.map} +0 -0
- /package/dist/{redact-doc-3UUPTXFI.js.map → redact-doc-CCLWNWAN.js.map} +0 -0
- /package/dist/{render-JGMRAI2P.js.map → render-VQA2XY6S.js.map} +0 -0
- /package/dist/{rewrite-fallback-UDQAKQN2.js.map → rewrite-fallback-R52RR5NL.js.map} +0 -0
- /package/dist/{seal-WFNKTHBW.js.map → seal-3P5RJIID.js.map} +0 -0
- /package/dist/{setup-JTHBR676.js.map → setup-75BEQHOQ.js.map} +0 -0
- /package/dist/{to-hwpx-GJP66LQS.js.map → to-hwpx-HQTEFNV5.js.map} +0 -0
- /package/dist/{to-hwpx-ZD7IGU7G.js.map → to-hwpx-HR33KFDQ.js.map} +0 -0
- /package/dist/{visual-666SNQ3Y.js.map → visual-OZTTV577.js.map} +0 -0
- /package/dist/{watch-QL4YAMRV.js.map → watch-AZ7OMTXR.js.map} +0 -0
|
@@ -34,20 +34,22 @@
|
|
|
34
34
|
|
|
35
35
|
|
|
36
36
|
|
|
37
|
-
var _chunkHJGKVI7Dcjs = require('./chunk-HJGKVI7D.cjs');
|
|
38
37
|
|
|
39
38
|
|
|
40
|
-
var
|
|
39
|
+
var _chunkVALBVWMTcjs = require('./chunk-VALBVWMT.cjs');
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
var _chunkMMK32GPDcjs = require('./chunk-MMK32GPD.cjs');
|
|
41
43
|
|
|
42
44
|
|
|
43
45
|
var _chunkTK3FDAEEcjs = require('./chunk-TK3FDAEE.cjs');
|
|
44
46
|
|
|
45
47
|
|
|
46
48
|
|
|
47
|
-
var
|
|
49
|
+
var _chunkXXBO2VOScjs = require('./chunk-XXBO2VOS.cjs');
|
|
48
50
|
|
|
49
51
|
// src/ocr/ocr-stacked-rows.ts
|
|
50
|
-
var NUMERIC = /^[-+−△▲▽▼]?[\d.,]+[%p]?$|^[-–—·∼~]$|^\([-+−△▲▽▼]?[\d.,]
|
|
52
|
+
var NUMERIC = /^[-+−△▲▽▼]?[\d.,]+[%p]?$|^[-–—·∼~]$|^\([-+−△▲▽▼]?[\d.,]+%?\)$/;
|
|
51
53
|
var blank = () => ({ text: "", colSpan: 1, rowSpan: 1 });
|
|
52
54
|
function rowAnchors(t, r, coveredFromAbove) {
|
|
53
55
|
const out = [];
|
|
@@ -85,7 +87,8 @@ function splitTable(t) {
|
|
|
85
87
|
const flat = stacked.flat();
|
|
86
88
|
const numericShare = flat.length ? flat.filter((s) => NUMERIC.test(s.replace(/\s+/g, ""))).length / flat.length : 0;
|
|
87
89
|
const spanOk = anchors.every((a, i) => (_nullishCoalesce(a.cell.rowSpan, () => ( 1))) === 1 || lines[i].length <= 1);
|
|
88
|
-
const
|
|
90
|
+
const shares = k === 2 && stacked.length >= 2 && stacked.every((ls) => NUMERIC.test(ls[0].replace(/\s+/g, "")) && /^\(.*\)$/.test(ls[1]));
|
|
91
|
+
const ok = spanOk && k >= 2 && n >= 2 && (stacked.length * 2 >= nonEmpty || shares) && lines.every((ls) => ls.length <= 1 || near(ls)) && numericShare >= 0.6;
|
|
89
92
|
if (!ok) {
|
|
90
93
|
newRows.push(row);
|
|
91
94
|
continue;
|
|
@@ -511,15 +514,56 @@ var _path = require('path');
|
|
|
511
514
|
|
|
512
515
|
// src/ocr/glyph-restore.ts
|
|
513
516
|
var INKLESS_DELTA = 32;
|
|
514
|
-
function
|
|
517
|
+
function ringAsks(rgba, pageW, box, text, steps, stepPx) {
|
|
518
|
+
const chars = [...text];
|
|
519
|
+
if (chars.length !== steps.length || !/[가-힣]/.test(text)) return [];
|
|
520
|
+
const gray = _chunkVALBVWMTcjs.grayCrop.call(void 0, rgba, pageW, box);
|
|
521
|
+
const rings = _chunkVALBVWMTcjs.ringBoxes.call(void 0, gray, box.w, box.h, _chunkVALBVWMTcjs.inkStats.call(void 0, gray));
|
|
522
|
+
const owner = ringOwners(chars, (i) => (steps[i] + 0.5) * stepPx, rings);
|
|
523
|
+
return rings.flatMap((r, k) => {
|
|
524
|
+
const at = owner.indexOf(k);
|
|
525
|
+
if (at >= 0 && !/^[\u2460-\u2468]$/.test(chars[at])) return [];
|
|
526
|
+
const { inner } = r;
|
|
527
|
+
return [{ x0: r.x0, x1: r.x1, jamo: r.jamo, box: { x: box.x + inner.x0 - 1, y: box.y + inner.y0 - 1, w: inner.x1 - inner.x0 + 2, h: inner.y1 - inner.y0 + 2 } }];
|
|
528
|
+
});
|
|
529
|
+
}
|
|
530
|
+
function ringOwners(chars, cx, rings) {
|
|
531
|
+
return chars.map((c, i) => {
|
|
532
|
+
if (!c.trim()) return -1;
|
|
533
|
+
let best = -1, d = Infinity;
|
|
534
|
+
rings.forEach((r, k) => {
|
|
535
|
+
const e = Math.abs(cx(i) - (r.x0 + r.x1) / 2);
|
|
536
|
+
if (cx(i) >= r.x0 && cx(i) <= r.x1 && e < d) {
|
|
537
|
+
d = e;
|
|
538
|
+
best = k;
|
|
539
|
+
}
|
|
540
|
+
});
|
|
541
|
+
return best;
|
|
542
|
+
});
|
|
543
|
+
}
|
|
544
|
+
var RING_JAMO = "\u3131\u3134\u3137\u3139\u3141\u3142\u3145\u3147\u3148\u314A\u314B\u314C\u314D\u314E";
|
|
545
|
+
var RING_SYLLABLE = "\uAC00\uB098\uB2E4\uB77C\uB9C8\uBC14\uC0AC\uC544\uC790\uCC28\uCE74\uD0C0\uD30C\uD558";
|
|
546
|
+
function ringGlyph(read, jamo = null, confidence = 1) {
|
|
547
|
+
const t = read.trim();
|
|
548
|
+
if (jamo && /^[가-힣□口ㄱ-ㅎ]$/.test(t) && !RING_SYLLABLE.includes(t)) return String.fromCharCode(12896 + RING_JAMO.indexOf(jamo));
|
|
549
|
+
if (confidence < 0.5 || [...t].length !== 1 || /^[oO0ㅇ]$/.test(t)) return null;
|
|
550
|
+
if (/^[1-9]$/.test(t)) return String.fromCharCode(9311 + Number(t));
|
|
551
|
+
if (RING_JAMO.includes(t)) return String.fromCharCode(12896 + RING_JAMO.indexOf(t));
|
|
552
|
+
if (RING_SYLLABLE.includes(t)) return String.fromCharCode(12910 + RING_SYLLABLE.indexOf(t));
|
|
553
|
+
const l = /^[CSUVWXZ]$/.test(t) ? t.toLowerCase() : t;
|
|
554
|
+
if (/^[a-z]$/.test(l)) return String.fromCharCode(9424 + l.charCodeAt(0) - 97);
|
|
555
|
+
if (/^[A-Z]$/.test(l)) return String.fromCharCode(9398 + l.charCodeAt(0) - 65);
|
|
556
|
+
return null;
|
|
557
|
+
}
|
|
558
|
+
function restoreGlyphs(rgba, pageW, box, text, steps, stepPx, note = {}, rings = []) {
|
|
515
559
|
const chars = [...text];
|
|
516
560
|
if (chars.length !== steps.length) return text;
|
|
517
|
-
const gray =
|
|
518
|
-
const c = { chars, cx: (i) => (steps[i] + 0.5) * stepPx, gray, w: box.w, h: box.h, ink:
|
|
561
|
+
const gray = _chunkVALBVWMTcjs.grayCrop.call(void 0, rgba, pageW, box);
|
|
562
|
+
const c = { chars, cx: (i) => (steps[i] + 0.5) * stepPx, gray, w: box.w, h: box.h, ink: _chunkVALBVWMTcjs.inkStats.call(void 0, gray) };
|
|
519
563
|
if (/[[\]]/.test(text)) brackets(c);
|
|
520
564
|
if (text.includes("'")) cornerQuotes(c);
|
|
521
565
|
if (/['"]/.test(text)) quotes(c);
|
|
522
|
-
if (/(^|\D)[1-9](\D|$)/.test(text)) circled(c);
|
|
566
|
+
if (/(^|\D)[1-9](\D|$)|[ㄱ-ㅎa-zCSUVWXZ]/.test(text)) circled(c);
|
|
523
567
|
if (text.includes("*")) stars(c);
|
|
524
568
|
if (/[\u00b7\u2022]/.test(text)) discs(c);
|
|
525
569
|
if (/[-\u2013\u2014]/.test(text)) dashes(c);
|
|
@@ -528,12 +572,24 @@ function restoreGlyphs(rgba, pageW, box, text, steps, stepPx, note = {}) {
|
|
|
528
572
|
note.ringLead = ring(c);
|
|
529
573
|
if (/[I|]/.test(text)) parallels(c);
|
|
530
574
|
if (/[I1Ⅰ-Ⅲ|]|^\s*\./.test(text)) roman(c);
|
|
575
|
+
const owner = ringOwners(chars, c.cx, rings);
|
|
576
|
+
rings.forEach((r, k) => {
|
|
577
|
+
const live = chars.map((_, i) => i).filter((i) => chars[i].trim());
|
|
578
|
+
const at = owner.indexOf(k);
|
|
579
|
+
if (at >= 0) {
|
|
580
|
+
chars[at] = r.glyph + [...chars[at]].slice(1).join("");
|
|
581
|
+
return;
|
|
582
|
+
}
|
|
583
|
+
const prev = live.filter((i) => c.cx(i) < r.x0).pop();
|
|
584
|
+
if (prev !== void 0) chars[prev] += r.glyph;
|
|
585
|
+
else if (live.length) chars[live[0]] = r.glyph + chars[live[0]];
|
|
586
|
+
});
|
|
531
587
|
return chars.join("");
|
|
532
588
|
}
|
|
533
589
|
function trimInklessEnds(rgba, pageW, box, text, steps, stepPx) {
|
|
534
590
|
const chars = [...text], { w, h } = box;
|
|
535
591
|
if (chars.length !== steps.length || steps.some((s) => (s + 0.5) * stepPx > w + stepPx)) return { text, steps };
|
|
536
|
-
const gray =
|
|
592
|
+
const gray = _chunkVALBVWMTcjs.grayCrop.call(void 0, rgba, pageW, box);
|
|
537
593
|
const hist = new Uint32Array(256);
|
|
538
594
|
for (const v of gray) hist[v]++;
|
|
539
595
|
let bg = 0;
|
|
@@ -564,8 +620,8 @@ function cornerCommas({ chars, cx, gray, w, h, ink }) {
|
|
|
564
620
|
continue;
|
|
565
621
|
}
|
|
566
622
|
if (open > 0) {
|
|
567
|
-
const f =
|
|
568
|
-
if (f &&
|
|
623
|
+
const f = _chunkVALBVWMTcjs.bracketFeatures.call(void 0, gray, w, h, ink, cx(i));
|
|
624
|
+
if (f && _chunkVALBVWMTcjs.bracketShape.call(void 0, f, true) === "\u300D") {
|
|
569
625
|
chars[i] = "\u300D";
|
|
570
626
|
open--;
|
|
571
627
|
}
|
|
@@ -575,12 +631,12 @@ function cornerCommas({ chars, cx, gray, w, h, ink }) {
|
|
|
575
631
|
function cornerQuotes({ chars, cx, gray, w, h, ink }) {
|
|
576
632
|
for (let i = 0; i < chars.length; i++) {
|
|
577
633
|
if (chars[i] !== "'" || !/^[가-힣]/.test(_nullishCoalesce(chars[i + 1], () => ( "")))) continue;
|
|
578
|
-
const f =
|
|
579
|
-
if (!f || f.ch < f.charH * 0.45 ||
|
|
634
|
+
const f = _chunkVALBVWMTcjs.bracketFeatures.call(void 0, gray, w, h, ink, cx(i));
|
|
635
|
+
if (!f || f.ch < f.charH * 0.45 || _chunkVALBVWMTcjs.bracketShape.call(void 0, f, false) !== "\u300C") continue;
|
|
580
636
|
const rest = chars.slice(i + 1), end = rest.findIndex((c) => c === "'" || c === "\u300D" || c === ",");
|
|
581
637
|
const pair = end >= 0 && rest[end] !== "'" && (rest[end] === "\u300D" || (() => {
|
|
582
|
-
const g =
|
|
583
|
-
return !!g &&
|
|
638
|
+
const g = _chunkVALBVWMTcjs.bracketFeatures.call(void 0, gray, w, h, ink, cx(i + 1 + end));
|
|
639
|
+
return !!g && _chunkVALBVWMTcjs.bracketShape.call(void 0, g, true) === "\u300D";
|
|
584
640
|
})());
|
|
585
641
|
if (pair) chars[i] = "\u300C";
|
|
586
642
|
}
|
|
@@ -588,8 +644,8 @@ function cornerQuotes({ chars, cx, gray, w, h, ink }) {
|
|
|
588
644
|
function brackets({ chars, cx, gray, w, h, ink }) {
|
|
589
645
|
const shape = chars.map((c, i) => {
|
|
590
646
|
if (c !== "[" && c !== "]") return null;
|
|
591
|
-
const f =
|
|
592
|
-
return f &&
|
|
647
|
+
const f = _chunkVALBVWMTcjs.bracketFeatures.call(void 0, gray, w, h, ink, cx(i));
|
|
648
|
+
return f && _chunkVALBVWMTcjs.bracketShape.call(void 0, f, c === "]");
|
|
593
649
|
});
|
|
594
650
|
for (let i = 0; i < chars.length; i++) {
|
|
595
651
|
if (chars[i] !== "[") continue;
|
|
@@ -621,7 +677,7 @@ function quotes({ chars, cx, gray, w, h, ink }) {
|
|
|
621
677
|
continue;
|
|
622
678
|
}
|
|
623
679
|
if (!year(i) && !single[kind]) continue;
|
|
624
|
-
const r =
|
|
680
|
+
const r = _chunkVALBVWMTcjs.quoteHead.call(void 0, gray, w, h, ink, cx(i));
|
|
625
681
|
if (r !== null && r >= 0.47) {
|
|
626
682
|
chars[i] = kind === "'" ? "\u2018" : "\u201C";
|
|
627
683
|
open[kind] = true;
|
|
@@ -632,18 +688,22 @@ function dashes({ chars, cx, gray, w, h, ink }) {
|
|
|
632
688
|
const head = chars.findIndex((c) => c.trim()), letters = chars.some((c) => /[가-힣A-Za-z]/.test(c));
|
|
633
689
|
for (let i = 0; i < chars.length; i++) {
|
|
634
690
|
if (!/^[-\u2013\u2014]$/.test(chars[i])) continue;
|
|
635
|
-
const r =
|
|
691
|
+
const r = _chunkVALBVWMTcjs.dashRatio.call(void 0, gray, w, h, ink, cx(i));
|
|
636
692
|
if (r === null) continue;
|
|
637
693
|
if (r < 0.65) chars[i] = "-";
|
|
638
694
|
else if (r > 0.75 && i === head && letters) chars[i] = "\u2014";
|
|
639
695
|
}
|
|
640
696
|
}
|
|
641
697
|
function circled({ chars, cx, gray, w, h, ink }) {
|
|
642
|
-
const
|
|
698
|
+
const alone = (re, i) => re.test(chars[i]) && !re.test(_nullishCoalesce(chars[i - 1], () => ( ""))) && !re.test(_nullishCoalesce(chars[i + 1], () => ( "")));
|
|
699
|
+
const at = chars.flatMap((_, i) => alone(/^\d$/, i) && chars[i] !== "0" || alone(/^[ㄱ-ㅎ]$/, i) || alone(/^[A-Za-z]$/, i) && /[a-zCSUVWXZ]/.test(chars[i]) ? [i] : []);
|
|
643
700
|
if (!at.length) return;
|
|
644
|
-
const hit =
|
|
701
|
+
const hit = _chunkVALBVWMTcjs.circledAt.call(void 0, gray, w, h, ink, at.map(cx));
|
|
702
|
+
const JAMO = "\u3131\u3134\u3137\u3139\u3141\u3142\u3145\u3147\u3148\u314A\u314B\u314C\u314D\u314E";
|
|
645
703
|
at.forEach((i, k) => {
|
|
646
|
-
if (hit[k])
|
|
704
|
+
if (!hit[k]) return;
|
|
705
|
+
const ch = chars[i];
|
|
706
|
+
chars[i] = /\d/.test(ch) ? String.fromCharCode(9311 + Number(ch)) : /[a-zA-Z]/.test(ch) ? String.fromCharCode(9424 + ch.toLowerCase().charCodeAt(0) - 97) : JAMO.includes(ch) ? String.fromCharCode(12896 + JAMO.indexOf(ch)) : ch;
|
|
647
707
|
});
|
|
648
708
|
}
|
|
649
709
|
function stars({ chars, cx, gray, w, h, ink }) {
|
|
@@ -651,16 +711,16 @@ function stars({ chars, cx, gray, w, h, ink }) {
|
|
|
651
711
|
if (chars[i] !== "*" || chars[i - 1] === "*") continue;
|
|
652
712
|
let e = i;
|
|
653
713
|
while (chars[e + 1] === "*") e++;
|
|
654
|
-
const n =
|
|
714
|
+
const n = _chunkVALBVWMTcjs.starRun.call(void 0, gray, w, h, ink, cx(i));
|
|
655
715
|
if (n > e - i + 1 && n <= 4) chars[e] += "*".repeat(n - (e - i + 1));
|
|
656
716
|
i = e;
|
|
657
717
|
}
|
|
658
718
|
}
|
|
659
719
|
function discs({ chars, cx, gray, w, h, ink }) {
|
|
660
|
-
for (let i = 0; i < chars.length; i++) if (/^[\u00b7\u2022]$/.test(chars[i]) &&
|
|
720
|
+
for (let i = 0; i < chars.length; i++) if (/^[\u00b7\u2022]$/.test(chars[i]) && _chunkVALBVWMTcjs.discAt.call(void 0, gray, w, h, ink, cx(i))) chars[i] = "\u25CF";
|
|
661
721
|
}
|
|
662
722
|
function gaps({ chars, cx, gray, w, h, ink }) {
|
|
663
|
-
const { glyphs, bandH } =
|
|
723
|
+
const { glyphs, bandH } = _chunkVALBVWMTcjs.gapGlyphs.call(void 0, gray, w, h, ink);
|
|
664
724
|
if (!glyphs.length) return;
|
|
665
725
|
const live = chars.map((c, i) => i).filter((i) => chars[i].trim());
|
|
666
726
|
if (!live.length) return;
|
|
@@ -731,18 +791,18 @@ function ring({ chars, cx, gray, w, h, ink }) {
|
|
|
731
791
|
const rest = chars.slice(k + 1).join("").trimStart();
|
|
732
792
|
const live = chars.map((c, i) => i).filter((i) => chars[i].trim());
|
|
733
793
|
if (live.length <= 3 && live.every((i) => /^[Oo]$/.test(chars[i]))) {
|
|
734
|
-
if (_optionalChain([
|
|
735
|
-
if (!live.every((i) =>
|
|
794
|
+
if (_optionalChain([_chunkVALBVWMTcjs.leadingBullet.call(void 0, gray, w, h, ink, cx(live[0])), 'optionalAccess', _7 => _7.mark]) === "\u25CE") return false;
|
|
795
|
+
if (!live.every((i) => _chunkVALBVWMTcjs.ringBullet.call(void 0, gray, w, h, ink, cx(i)) === "\u25CB")) return false;
|
|
736
796
|
for (const i of live) chars[i] = "\u25CB";
|
|
737
797
|
return true;
|
|
738
798
|
}
|
|
739
799
|
if (/^[A-Z]{2,}/.test(rest) && /^[Oo0]$/.test(chars[k])) {
|
|
740
|
-
if (
|
|
800
|
+
if (_chunkVALBVWMTcjs.ringBullet.call(void 0, gray, w, h, ink, cx(k)) !== "\u25CB") return false;
|
|
741
801
|
chars[k] = chars[k + 1] === " " ? "\u25CB" : "\u25CB ";
|
|
742
802
|
return true;
|
|
743
803
|
}
|
|
744
804
|
if (!/^[(\[「【<]?\d*[가-힣]/.test(rest)) return false;
|
|
745
|
-
const r =
|
|
805
|
+
const r = _chunkVALBVWMTcjs.ringBullet.call(void 0, gray, w, h, ink, cx(k));
|
|
746
806
|
if (/^[Cc]$/.test(chars[k]) && r !== "\u25CB") return false;
|
|
747
807
|
if (r) chars[k] = r;
|
|
748
808
|
return r !== null;
|
|
@@ -759,7 +819,7 @@ function parallels({ chars, cx, gray, w, h, ink }) {
|
|
|
759
819
|
let p = s - 1, q = e + 1;
|
|
760
820
|
while (p >= 0 && !chars[p].trim()) p--;
|
|
761
821
|
while (q < chars.length && !chars[q].trim()) q++;
|
|
762
|
-
if (
|
|
822
|
+
if (_chunkVALBVWMTcjs.slantedPair.call(void 0, gray, w, h, ink, p >= 0 ? cx(p) : -Infinity, q < chars.length ? cx(q) : Infinity)) {
|
|
763
823
|
chars[s] = "\u2225";
|
|
764
824
|
for (let k = s + 1; k <= e; k++) chars[k] = "";
|
|
765
825
|
}
|
|
@@ -771,7 +831,7 @@ function roman({ chars, cx, gray, w, h, ink }) {
|
|
|
771
831
|
const ROMAN = /^[IⅠ-Ⅲ]$/, LATIN = /[A-Za-z]$/;
|
|
772
832
|
for (let i = 0; i < chars.length; i++) {
|
|
773
833
|
if (chars[i] !== "1" || /[\dA-Za-z]$/.test(_nullishCoalesce(chars[i - 1], () => ( ""))) || /^[\dA-Za-z,]/.test(_nullishCoalesce(chars[i + 1], () => ( "")))) continue;
|
|
774
|
-
if (
|
|
834
|
+
if (_chunkVALBVWMTcjs.serifOne.call(void 0, gray, w, h, ink, cx(i))) chars[i] = "\u2160";
|
|
775
835
|
}
|
|
776
836
|
for (let i = 0; i < chars.length; i++) {
|
|
777
837
|
const hangul = /^[파피]$/.test(chars[i]);
|
|
@@ -781,13 +841,13 @@ function roman({ chars, cx, gray, w, h, ink }) {
|
|
|
781
841
|
while (q < chars.length && !chars[q].trim()) q++;
|
|
782
842
|
const glued = hangul ? chars[p] === "(" && chars[q] === "-" : /[가-힣]$/.test(_nullishCoalesce(chars[i - 1], () => ( ""))) || (_nullishCoalesce(chars[i + 1], () => ( ""))) === "." || chars[p] === "-" && chars[q] === "-";
|
|
783
843
|
if (!glued) continue;
|
|
784
|
-
const n =
|
|
844
|
+
const n = _chunkVALBVWMTcjs.romanStems.call(void 0, gray, w, h, ink, p >= 0 ? cx(p) : -Infinity, q < chars.length ? cx(q) : Infinity, /[가-힣]$/.test(_nullishCoalesce(chars[p], () => ( ""))));
|
|
785
845
|
if (n) chars[i] = String.fromCharCode(8543 + n);
|
|
786
846
|
}
|
|
787
847
|
const inRoman = (i) => ROMAN.test(chars[i]) || chars[i] === "1" && (ROMAN.test(_nullishCoalesce(chars[i - 1], () => ( ""))) || ROMAN.test(_nullishCoalesce(chars[i + 1], () => ( ""))));
|
|
788
848
|
const k = chars.findIndex((c) => c.trim());
|
|
789
849
|
if (chars[k] === "." && chars.slice(k + 1).some((c) => /[가-힣A-Za-z0-9]/.test(c))) {
|
|
790
|
-
const n =
|
|
850
|
+
const n = _chunkVALBVWMTcjs.romanStems.call(void 0, gray, w, h, ink, -Infinity, cx(k));
|
|
791
851
|
if (n) chars[k] = String.fromCharCode(8543 + n) + chars[k];
|
|
792
852
|
}
|
|
793
853
|
for (let s = 0; s < chars.length; ) {
|
|
@@ -805,7 +865,7 @@ function roman({ chars, cx, gray, w, h, ink }) {
|
|
|
805
865
|
let p = s - 1, q = e;
|
|
806
866
|
while (p >= 0 && !chars[p].trim()) p--;
|
|
807
867
|
while (q < chars.length && !chars[q].trim()) q++;
|
|
808
|
-
const n =
|
|
868
|
+
const n = _chunkVALBVWMTcjs.romanStems.call(void 0, gray, w, h, ink, p >= 0 ? cx(p) : -Infinity, q < chars.length ? cx(q) : Infinity, /[가-힣]$/.test(_nullishCoalesce(chars[p], () => ( ""))));
|
|
809
869
|
const canon = n ? [["\u2160", "I"], ["\u2161", "II"], ["\u2162", "III"]][n - 1] : null;
|
|
810
870
|
if (canon && !canon.includes(tok)) {
|
|
811
871
|
chars[s] = canon[0];
|
|
@@ -1015,14 +1075,16 @@ function lineCrop(rgba, pageW, box, rot, keep, stretch = 1) {
|
|
|
1015
1075
|
}
|
|
1016
1076
|
return { rgb, w: rw };
|
|
1017
1077
|
}
|
|
1078
|
+
var CELL_RULE_MARGIN = 0.7;
|
|
1018
1079
|
function splitBoxAtCellRules(b, rules) {
|
|
1019
|
-
const
|
|
1080
|
+
const m = b.h * CELL_RULE_MARGIN;
|
|
1081
|
+
const cuts = rules.filter((r) => r.x1 > b.x + m && r.x1 < b.x + b.w - m && r.y1 <= b.y + b.h * 0.25 && r.y2 >= b.y + b.h * 0.75).sort((a, c) => a.x1 - c.x1);
|
|
1020
1082
|
if (!cuts.length) return [b];
|
|
1021
1083
|
const out = [];
|
|
1022
1084
|
let left = b.x;
|
|
1023
1085
|
for (const r of cuts) {
|
|
1024
1086
|
const edge = Math.floor(r.x1 - r.thicknessPx / 2 - 1);
|
|
1025
|
-
if (edge - left <
|
|
1087
|
+
if (edge - left < m) continue;
|
|
1026
1088
|
out.push({ ...b, x: left, w: edge - left });
|
|
1027
1089
|
left = Math.ceil(r.x1 + r.thicknessPx / 2 + 1);
|
|
1028
1090
|
}
|
|
@@ -1084,6 +1146,13 @@ var KEEP_MARGIN = 0.06;
|
|
|
1084
1146
|
var RETRY_SCORE = 0.9;
|
|
1085
1147
|
var LEADER_MIN_DOTS = 4;
|
|
1086
1148
|
var LEADER_CONTEXT = 0.5;
|
|
1149
|
+
var DET_MIN_SHORT_SIDE = 80;
|
|
1150
|
+
var DET_MAX_LONG_SIDE = 4096;
|
|
1151
|
+
function detInputSize(width, height, longSide) {
|
|
1152
|
+
let ratio = longSide / Math.max(width, height);
|
|
1153
|
+
if (Math.min(width, height) * ratio < DET_MIN_SHORT_SIDE) ratio = Math.min(DET_MIN_SHORT_SIDE / Math.min(width, height), DET_MAX_LONG_SIDE / Math.max(width, height));
|
|
1154
|
+
return { dw: Math.max(32, Math.round(width * ratio / 32) * 32), dh: Math.max(32, Math.round(height * ratio / 32) * 32) };
|
|
1155
|
+
}
|
|
1087
1156
|
var MIN_INK_RATIO = 0.01;
|
|
1088
1157
|
var MAX_LOCAL_MODEL_BYTES = 1024 * 1024 * 1024;
|
|
1089
1158
|
var DET_MEAN = [0.485, 0.456, 0.406];
|
|
@@ -1194,8 +1263,8 @@ function joinGapLeaders(rgba, width, items) {
|
|
|
1194
1263
|
if (g1 - g0 < h * 3) continue;
|
|
1195
1264
|
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));
|
|
1196
1265
|
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 };
|
|
1197
|
-
const gray =
|
|
1198
|
-
const runs =
|
|
1266
|
+
const gray = _chunkVALBVWMTcjs.grayCrop.call(void 0, rgba, width, box);
|
|
1267
|
+
const runs = _chunkVALBVWMTcjs.leaderRuns.call(void 0, gray, box.w, box.h, _chunkVALBVWMTcjs.inkStats.call(void 0, gray), LEADER_MIN_DOTS);
|
|
1199
1268
|
const cover = runs.reduce((k, [a, b]) => k + Math.max(0, Math.min(b, g1 - box.x) - Math.max(a, g0 - box.x)), 0);
|
|
1200
1269
|
if (cover < (g1 - g0) * 0.6) continue;
|
|
1201
1270
|
for (const o of items) if (junk(o) && sameLine(o, num) && o.x >= g0 - 2 && o.x + o.w <= g1 + 2) gone.add(o);
|
|
@@ -1462,7 +1531,7 @@ var OcrEngine = class _OcrEngine {
|
|
|
1462
1531
|
this.ort = parts.ort;
|
|
1463
1532
|
this.sharp = parts.sharp;
|
|
1464
1533
|
}
|
|
1465
|
-
static async create(models =
|
|
1534
|
+
static async create(models = _chunkVALBVWMTcjs.DEFAULT_OCR_MODELS) {
|
|
1466
1535
|
_chunkTK3FDAEEcjs.disableOrtTelemetry.call(void 0, );
|
|
1467
1536
|
const [ortMod, sharpModRaw] = await Promise.all([
|
|
1468
1537
|
tryImport("onnxruntime-node", () => Promise.resolve().then(() => _interopRequireWildcard(require("onnxruntime-node")))),
|
|
@@ -1482,16 +1551,16 @@ var OcrEngine = class _OcrEngine {
|
|
|
1482
1551
|
const local = (s) => "spec" in s ? Promise.resolve(null) : verifiedBytes(s);
|
|
1483
1552
|
const [detBytes, recBytes, dictBytes] = await Promise.all([local(models.det), local(models.rec), local(models.dict)]);
|
|
1484
1553
|
const session = (s, bytes) => bytes ? ortMod.InferenceSession.create(bytes, sessionOpts).catch(() => {
|
|
1485
|
-
throw new (0,
|
|
1486
|
-
}) : ortMod.InferenceSession.create(
|
|
1554
|
+
throw new (0, _chunkXXBO2VOScjs.KordocError)(`OCR \uBAA8\uB378\uC744 \uC5F4\uC9C0 \uBABB\uD588\uC2B5\uB2C8\uB2E4: ${_path.basename.call(void 0, _chunkVALBVWMTcjs.ocrSourcePath.call(void 0, s))} \u2014 ONNX \uBAA8\uB378\uC774 \uC544\uB2C8\uAC70\uB098 \uC190\uC0C1\uB410\uC2B5\uB2C8\uB2E4`);
|
|
1555
|
+
}) : ortMod.InferenceSession.create(_chunkVALBVWMTcjs.ocrSourcePath.call(void 0, s), sessionOpts);
|
|
1487
1556
|
const [det, rec, dictYml] = await Promise.all([
|
|
1488
1557
|
session(models.det, detBytes),
|
|
1489
1558
|
session(models.rec, recBytes),
|
|
1490
|
-
dictBytes ? new TextDecoder().decode(dictBytes) : _promises.readFile.call(void 0,
|
|
1559
|
+
dictBytes ? new TextDecoder().decode(dictBytes) : _promises.readFile.call(void 0, _chunkVALBVWMTcjs.ocrSourcePath.call(void 0, models.dict), "utf-8")
|
|
1491
1560
|
]);
|
|
1492
|
-
const dict =
|
|
1561
|
+
const dict = _chunkVALBVWMTcjs.parseCharacterDict.call(void 0, dictYml);
|
|
1493
1562
|
if (dict.length === 0) {
|
|
1494
|
-
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,
|
|
1563
|
+
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, _chunkXXBO2VOScjs.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`);
|
|
1495
1564
|
}
|
|
1496
1565
|
return new _OcrEngine({ det, rec, dict, ort: ortMod, sharp: sharpMod });
|
|
1497
1566
|
}
|
|
@@ -1523,10 +1592,10 @@ var OcrEngine = class _OcrEngine {
|
|
|
1523
1592
|
if (it.x - x < it.h * 0.8) return;
|
|
1524
1593
|
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;
|
|
1525
1594
|
const box = { x, y: it.y, w: it.x + it.w - x, h: it.h };
|
|
1526
|
-
const g =
|
|
1527
|
-
const b =
|
|
1595
|
+
const g = _chunkVALBVWMTcjs.grayCrop.call(void 0, rgba, width, box);
|
|
1596
|
+
const b = _chunkVALBVWMTcjs.leadingBullet.call(void 0, g, box.w, box.h, _chunkVALBVWMTcjs.inkStats.call(void 0, g), it.x - x, 1.05);
|
|
1528
1597
|
if (_optionalChain([b, 'optionalAccess', _32 => _32.mark]) !== "\u25A1" || b.covers) return;
|
|
1529
|
-
const ink =
|
|
1598
|
+
const ink = _chunkVALBVWMTcjs.inkStats.call(void 0, g), on = (v) => ink.darkInk ? v <= ink.threshold : v > ink.threshold;
|
|
1530
1599
|
let left = 0;
|
|
1531
1600
|
while (left < it.x - x && !Array.from({ length: box.h }, (_, y) => g[y * box.w + left]).some(on)) left++;
|
|
1532
1601
|
it.text = "\u25A1 " + it.text;
|
|
@@ -1558,12 +1627,12 @@ var OcrEngine = class _OcrEngine {
|
|
|
1558
1627
|
const joins = [];
|
|
1559
1628
|
let group = 0;
|
|
1560
1629
|
for (const b of boxes) {
|
|
1561
|
-
const gray =
|
|
1562
|
-
const ink =
|
|
1630
|
+
const gray = _chunkVALBVWMTcjs.grayCrop.call(void 0, rgba, width, b);
|
|
1631
|
+
const ink = _chunkVALBVWMTcjs.inkStats.call(void 0, gray);
|
|
1563
1632
|
if (tuning.minInkContrast > 0 && ink.contrast < tuning.minInkContrast) continue;
|
|
1564
1633
|
if (tuning.minInkContrast > 0 && ink.inkRatio < MIN_INK_RATIO) continue;
|
|
1565
1634
|
if (tuning.splitTall && b.h >= b.w * TALL_RATIO) {
|
|
1566
|
-
const bands =
|
|
1635
|
+
const bands = _chunkVALBVWMTcjs.splitRowBands.call(void 0, gray, b.w, b.h, ink, 0.45);
|
|
1567
1636
|
if (bands.length >= 2) {
|
|
1568
1637
|
for (const sub of bandBoxes(b, bands, height)) jobs.push({ box: sub, rot: 0, group: group++ });
|
|
1569
1638
|
continue;
|
|
@@ -1574,9 +1643,9 @@ var OcrEngine = class _OcrEngine {
|
|
|
1574
1643
|
continue;
|
|
1575
1644
|
}
|
|
1576
1645
|
}
|
|
1577
|
-
const trim = tuning.trimEdges ?
|
|
1646
|
+
const trim = tuning.trimEdges ? _chunkVALBVWMTcjs.edgeTrim.call(void 0, gray, b.w, b.h, ink) : null;
|
|
1578
1647
|
const keep = trim ? { ...trim, bg: median(gray) } : void 0;
|
|
1579
|
-
const leaders = tuning.splitLeaders ?
|
|
1648
|
+
const leaders = tuning.splitLeaders ? _chunkVALBVWMTcjs.leaderRuns.call(void 0, gray, b.w, b.h, ink, LEADER_MIN_DOTS) : [];
|
|
1580
1649
|
if (leaders.length) {
|
|
1581
1650
|
const join = joins.length;
|
|
1582
1651
|
joins.push({ box: b, parts: [], trailDots: false });
|
|
@@ -1585,7 +1654,7 @@ var OcrEngine = class _OcrEngine {
|
|
|
1585
1654
|
const bare = { x: b.x + x0, y: b.y, w: a - x0, h: b.h };
|
|
1586
1655
|
const end = c > a ? Math.min(c, a + Math.round(b.h * LEADER_CONTEXT)) : a;
|
|
1587
1656
|
x0 = c;
|
|
1588
|
-
if (bare.w >= DET_MIN_SIZE &&
|
|
1657
|
+
if (bare.w >= DET_MIN_SIZE && _chunkVALBVWMTcjs.inkStats.call(void 0, _chunkVALBVWMTcjs.grayCrop.call(void 0, rgba, width, bare)).contrast >= Math.max(1, tuning.minInkContrast)) {
|
|
1589
1658
|
jobs.push({ box: { ...bare, w: end - (bare.x - b.x) }, rot: 0, group: group++, join, dotsBefore: dots, trimDots: end > a });
|
|
1590
1659
|
dots = false;
|
|
1591
1660
|
}
|
|
@@ -1616,23 +1685,32 @@ var OcrEngine = class _OcrEngine {
|
|
|
1616
1685
|
let items = [];
|
|
1617
1686
|
const boxOf = /* @__PURE__ */ new Map();
|
|
1618
1687
|
const retry = [];
|
|
1688
|
+
const ringReads = /* @__PURE__ */ new Map();
|
|
1689
|
+
if (tuning.postprocess) {
|
|
1690
|
+
const asks = [...best.values()].flatMap((r) => r.job.rot === 0 ? ringAsks(rgba, width, r.job.box, r.text, r.steps, r.stepPx).map((a) => ({ ...a, job: r.job })) : []);
|
|
1691
|
+
const res = asks.length ? await this.recognizeJobs(rgba, width, asks.map((a, k) => ({ box: a.box, rot: 0, group: k })), tuning.recBatch) : [];
|
|
1692
|
+
asks.forEach((a, k) => {
|
|
1693
|
+
const glyph = res[k] ? ringGlyph(res[k].text, a.jamo, res[k].confidence) : null;
|
|
1694
|
+
if (glyph) ringReads.set(a.job, [..._nullishCoalesce(ringReads.get(a.job), () => ( [])), { x0: a.x0, x1: a.x1, glyph }]);
|
|
1695
|
+
});
|
|
1696
|
+
}
|
|
1619
1697
|
for (const r of best.values()) {
|
|
1620
1698
|
const { job, confidence, stepPx } = r;
|
|
1621
1699
|
const { text: read, steps } = tuning.postprocess && job.rot === 0 ? trimInklessEnds(rgba, width, job.box, r.text, r.steps, stepPx) : r;
|
|
1622
1700
|
const note = {};
|
|
1623
|
-
const raw = tuning.postprocess && job.rot === 0 ? restoreGlyphs(rgba, width, job.box, read, steps, stepPx, note) : read;
|
|
1701
|
+
const raw = tuning.postprocess && job.rot === 0 ? restoreGlyphs(rgba, width, job.box, read, steps, stepPx, note, ringReads.get(job)) : read;
|
|
1624
1702
|
let text = tuning.postprocess ? restoreSymbols(raw.trim(), note.ringLead) : raw;
|
|
1625
1703
|
if (!text.trim()) continue;
|
|
1626
1704
|
if (tuning.postprocess && job.rot === 0 && text !== "/" && /^[(:;/)]+$/.test(text) && text.includes("/")) {
|
|
1627
|
-
const g =
|
|
1628
|
-
if (
|
|
1705
|
+
const g = _chunkVALBVWMTcjs.grayCrop.call(void 0, rgba, width, job.box);
|
|
1706
|
+
if (_chunkVALBVWMTcjs.tallInkCount.call(void 0, g, job.box.w, job.box.h, _chunkVALBVWMTcjs.inkStats.call(void 0, g)) === 1) text = "/";
|
|
1629
1707
|
}
|
|
1630
1708
|
let ringByShape = false;
|
|
1631
1709
|
if (tuning.postprocess && job.rot === 0 && !/^[◎●▪□■▣❐❏○ㅇ◆◇◈]/.test(text)) {
|
|
1632
1710
|
const chars = [...read], k = chars.findIndex((c) => c.trim());
|
|
1633
1711
|
if (k >= 0 && steps.length === chars.length) {
|
|
1634
|
-
const g =
|
|
1635
|
-
const b =
|
|
1712
|
+
const g = _chunkVALBVWMTcjs.grayCrop.call(void 0, rgba, width, job.box);
|
|
1713
|
+
const b = _chunkVALBVWMTcjs.leadingBullet.call(void 0, g, job.box.w, job.box.h, _chunkVALBVWMTcjs.inkStats.call(void 0, g), (steps[k] + 0.5) * stepPx);
|
|
1636
1714
|
const body = (_nullishCoalesce(text.match(/[가-힣]/g), () => ( []))).length >= 4;
|
|
1637
1715
|
const miss = /^[Oo0•·ㆍ∙‧○]/.test(text);
|
|
1638
1716
|
if (_optionalChain([b, 'optionalAccess', _35 => _35.mark]) === "\u25CE" && b.covers && /^[Oo0○©]/.test(text)) {
|
|
@@ -1647,17 +1725,17 @@ var OcrEngine = class _OcrEngine {
|
|
|
1647
1725
|
} else if (_optionalChain([b, 'optionalAccess', _42 => _42.mark]) === "\u2750" || _optionalChain([b, 'optionalAccess', _43 => _43.mark]) === "\u274F") {
|
|
1648
1726
|
if (b.covers ? /^[ㅁ口]/.test(text) : body) text = b.covers ? b.mark + text.slice(1) : b.mark + " " + text;
|
|
1649
1727
|
} else if (b && b.mark !== "\u25CE" && body) text = b.covers ? miss ? b.mark + " " + text.slice(1).trimStart() : text : b.mark + " " + text;
|
|
1650
|
-
else if (!b && body && /^[가-힣]/.test(chars[k]) &&
|
|
1728
|
+
else if (!b && body && /^[가-힣]/.test(chars[k]) && _chunkVALBVWMTcjs.leadingRing.call(void 0, g, job.box.w, job.box.h, _chunkVALBVWMTcjs.inkStats.call(void 0, g), (steps[k] + 0.5) * stepPx)) text = "\u25CB " + text;
|
|
1651
1729
|
}
|
|
1652
1730
|
}
|
|
1653
1731
|
if (tuning.postprocess && /^\d/.test(text) && job.rot === 0) {
|
|
1654
|
-
const g =
|
|
1655
|
-
const tri =
|
|
1732
|
+
const g = _chunkVALBVWMTcjs.grayCrop.call(void 0, rgba, width, job.box);
|
|
1733
|
+
const tri = _chunkVALBVWMTcjs.leadingTriangle.call(void 0, g, job.box.w, job.box.h, _chunkVALBVWMTcjs.inkStats.call(void 0, g));
|
|
1656
1734
|
if (tri) text = tri + text;
|
|
1657
1735
|
}
|
|
1658
1736
|
if (tuning.postprocess && text === "\u2192" && job.rot === 0 && job.join === void 0) {
|
|
1659
|
-
const g =
|
|
1660
|
-
text = _nullishCoalesce(
|
|
1737
|
+
const g = _chunkVALBVWMTcjs.grayCrop.call(void 0, rgba, width, job.box);
|
|
1738
|
+
text = _nullishCoalesce(_chunkVALBVWMTcjs.arrowGlyph.call(void 0, g, job.box.w, job.box.h, _chunkVALBVWMTcjs.inkStats.call(void 0, g)), () => ( text));
|
|
1661
1739
|
}
|
|
1662
1740
|
if (job.footer) {
|
|
1663
1741
|
if (!/^[-\u2013\u2014]?\s*(?:\d{1,4}|[ivxIVXⅰ-ⅹⅠ-Ⅹ]{1,4})\s*[-\u2013\u2014]?$/.test(text.trim())) continue;
|
|
@@ -1678,7 +1756,7 @@ var OcrEngine = class _OcrEngine {
|
|
|
1678
1756
|
continue;
|
|
1679
1757
|
}
|
|
1680
1758
|
const item = { text, ...this.itemBox(rgba, width, job.box, tuning), confidence };
|
|
1681
|
-
if (job.rot === 0)
|
|
1759
|
+
if (job.rot === 0) _chunkVALBVWMTcjs.rememberOcrTextGaps.call(void 0, item, _chunkVALBVWMTcjs.findOcrTextGaps.call(void 0, rgba, width, job.box, read, text, steps, stepPx));
|
|
1682
1760
|
if (job.rot === 0 && job.keep === void 0) boxOf.set(item, job.box);
|
|
1683
1761
|
items.push(item);
|
|
1684
1762
|
}
|
|
@@ -1691,14 +1769,14 @@ var OcrEngine = class _OcrEngine {
|
|
|
1691
1769
|
const r = res[k];
|
|
1692
1770
|
if (!r || /\s/.test(r.text.trim()) || badThousands(r.text) || r.confidence < it.confidence - 0.05 || skeleton(r.text) !== skeleton(it.text)) return;
|
|
1693
1771
|
it.text = restoreSymbols(r.text.trim());
|
|
1694
|
-
|
|
1772
|
+
_chunkVALBVWMTcjs.rememberOcrTextGaps.call(void 0, it, _chunkVALBVWMTcjs.findOcrTextGaps.call(void 0, rgba, width, boxOf.get(it), r.text, it.text, r.steps, r.stepPx));
|
|
1695
1773
|
});
|
|
1696
1774
|
}
|
|
1697
1775
|
if (retry.length) {
|
|
1698
1776
|
const subs = [];
|
|
1699
1777
|
for (const b of retry) {
|
|
1700
|
-
const gray =
|
|
1701
|
-
const cut = midBlankRow(gray, b.w, b.h,
|
|
1778
|
+
const gray = _chunkVALBVWMTcjs.grayCrop.call(void 0, rgba, width, b);
|
|
1779
|
+
const cut = midBlankRow(gray, b.w, b.h, _chunkVALBVWMTcjs.inkStats.call(void 0, gray));
|
|
1702
1780
|
if (cut && b.w >= 3 * Math.max(cut[0], b.h - cut[1])) subs.push({ ...b, h: cut[0] }, { ...b, y: b.y + cut[1], h: b.h - cut[1] });
|
|
1703
1781
|
}
|
|
1704
1782
|
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));
|
|
@@ -1761,15 +1839,13 @@ var OcrEngine = class _OcrEngine {
|
|
|
1761
1839
|
/** 결과 좌표 — det 박스 그대로 또는 박스 안 잉크 외곽 (tightBoxes) */
|
|
1762
1840
|
itemBox(rgba, width, b, tuning) {
|
|
1763
1841
|
if (!tuning.tightBoxes) return b;
|
|
1764
|
-
const gray =
|
|
1765
|
-
const t =
|
|
1842
|
+
const gray = _chunkVALBVWMTcjs.grayCrop.call(void 0, rgba, width, b);
|
|
1843
|
+
const t = _chunkVALBVWMTcjs.inkBounds.call(void 0, gray, b.w, b.h, _chunkVALBVWMTcjs.inkStats.call(void 0, gray));
|
|
1766
1844
|
return { x: b.x + t.x0, y: b.y + t.y0, w: t.x1 - t.x0, h: t.y1 - t.y0 };
|
|
1767
1845
|
}
|
|
1768
1846
|
// ─── det ─────────────────────────────────────────────
|
|
1769
1847
|
async detect(rgba, width, height, tuning, stats) {
|
|
1770
|
-
const
|
|
1771
|
-
const dw = Math.max(32, Math.round(width * ratio / 32) * 32);
|
|
1772
|
-
const dh = Math.max(32, Math.round(height * ratio / 32) * 32);
|
|
1848
|
+
const { dw, dh } = detInputSize(width, height, tuning.detLongSide);
|
|
1773
1849
|
const rgb = await this.sharp(rgba, { raw: { width, height, channels: 4 } }).resize(dw, dh, { fit: "fill" }).removeAlpha().raw().toBuffer();
|
|
1774
1850
|
const plane = dw * dh;
|
|
1775
1851
|
const input = new Float32Array(3 * plane);
|
|
@@ -1835,7 +1911,7 @@ var OcrEngine = class _OcrEngine {
|
|
|
1835
1911
|
const out = await this.rec.run({ [this.rec.inputNames[0]]: tensor });
|
|
1836
1912
|
const logits = out[this.rec.outputNames[0]];
|
|
1837
1913
|
const [, T, C] = logits.dims;
|
|
1838
|
-
if (C !== this.dict.length + 2) throw new (0,
|
|
1914
|
+
if (C !== this.dict.length + 2) throw new (0, _chunkXXBO2VOScjs.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`);
|
|
1839
1915
|
const data = logits.data;
|
|
1840
1916
|
idx.forEach((ci, k) => {
|
|
1841
1917
|
const r = ctcDecode(data.subarray(k * T * C, (k + 1) * T * C), T, C, this.dict);
|
|
@@ -1845,9 +1921,9 @@ var OcrEngine = class _OcrEngine {
|
|
|
1845
1921
|
const chars = r ? [...r.text] : [];
|
|
1846
1922
|
if (r && job.rot === 0 && chars.length === r.steps.length && r.steps.some((t) => t > last) && !r.text.includes("(cid:")) {
|
|
1847
1923
|
const tallCh = (c) => !/[\s.,:;\u00b7\u2026'"\u2018-\u201d`\-_~]/.test(c);
|
|
1848
|
-
const g =
|
|
1924
|
+
const g = _chunkVALBVWMTcjs.grayCrop.call(void 0, rgba, pageW, job.box);
|
|
1849
1925
|
const inside = chars.filter((c, i) => r.steps[i] <= last && tallCh(c)).length;
|
|
1850
|
-
let budget = inside <= 2 ?
|
|
1926
|
+
let budget = inside <= 2 ? _chunkVALBVWMTcjs.tallInkCount.call(void 0, g, job.box.w, job.box.h, _chunkVALBVWMTcjs.inkStats.call(void 0, g)) - inside : Infinity;
|
|
1851
1927
|
const keep = chars.map((c, i) => r.steps[i] <= last || !tallCh(c) || budget-- > 0);
|
|
1852
1928
|
if (!keep.every(Boolean)) kept = { ...r, text: chars.filter((_, i) => keep[i]).join(""), steps: r.steps.filter((_, i) => keep[i]) };
|
|
1853
1929
|
}
|
|
@@ -1958,13 +2034,13 @@ async function tryImport(name, loader) {
|
|
|
1958
2034
|
return await loader();
|
|
1959
2035
|
} catch (e) {
|
|
1960
2036
|
throw new Error(
|
|
1961
|
-
`\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.${
|
|
2037
|
+
`\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.${_chunkXXBO2VOScjs.OPTIONAL_DEP_INSTALL_HINT} \uC6D0\uC778: ${e.message}`
|
|
1962
2038
|
);
|
|
1963
2039
|
}
|
|
1964
2040
|
}
|
|
1965
2041
|
async function verifiedBytes(s) {
|
|
1966
2042
|
const name = _path.basename.call(void 0, s.file.path);
|
|
1967
|
-
const fail = (why2) => new (0,
|
|
2043
|
+
const fail = (why2) => new (0, _chunkXXBO2VOScjs.KordocError)(`OCR \uBAA8\uB378 \uD30C\uC77C\uC744 \uC77D\uC9C0 \uBABB\uD588\uC2B5\uB2C8\uB2E4: ${name} (${why2})`);
|
|
1968
2044
|
const why = (e) => {
|
|
1969
2045
|
const code = e.code;
|
|
1970
2046
|
return code === "ENOENT" ? "\uD30C\uC77C\uC774 \uC5C6\uC74C" : code === "EACCES" || code === "EPERM" ? "\uAD8C\uD55C \uC5C6\uC74C" : "\uC77D\uAE30 \uC2E4\uD328";
|
|
@@ -1985,13 +2061,13 @@ async function verifiedBytes(s) {
|
|
|
1985
2061
|
}
|
|
1986
2062
|
const actual = _crypto.createHash.call(void 0, "sha256").update(bytes).digest("hex");
|
|
1987
2063
|
if (actual !== s.file.sha256) {
|
|
1988
|
-
throw new (0,
|
|
2064
|
+
throw new (0, _chunkXXBO2VOScjs.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)`);
|
|
1989
2065
|
}
|
|
1990
2066
|
return bytes;
|
|
1991
2067
|
}
|
|
1992
2068
|
var engines = /* @__PURE__ */ new Map();
|
|
1993
|
-
function getOcrEngine(models =
|
|
1994
|
-
const key =
|
|
2069
|
+
function getOcrEngine(models = _chunkVALBVWMTcjs.DEFAULT_OCR_MODELS) {
|
|
2070
|
+
const key = _chunkVALBVWMTcjs.ocrSelectionKey.call(void 0, models);
|
|
1995
2071
|
let p = engines.get(key);
|
|
1996
2072
|
if (!p) {
|
|
1997
2073
|
p = OcrEngine.create(models).catch((err) => {
|
|
@@ -2108,29 +2184,44 @@ function rotateRgba(rgba, width, height, deg) {
|
|
|
2108
2184
|
var OCR_RENDER_SCALE = 3;
|
|
2109
2185
|
var MAX_OCR_PIXELS = 24e6;
|
|
2110
2186
|
var PAGE_TIMEOUT_MS = 12e4;
|
|
2111
|
-
var
|
|
2187
|
+
var AUTO_REC = { pageConf: 0.9, gain: 0.06 };
|
|
2188
|
+
var DEFAULT_AUTO_REC = { pageConf: 0.85, gain: 0.1, lazy: true };
|
|
2189
|
+
var DEFAULT_BUILTIN_OCR = Object.freeze({
|
|
2190
|
+
models: _chunkVALBVWMTcjs.DEFAULT_OCR_MODELS,
|
|
2191
|
+
tuning: DEFAULT_OCR_TUNING,
|
|
2192
|
+
handwriting: _chunkVALBVWMTcjs.handwritingFallbackModels.call(void 0, _chunkVALBVWMTcjs.DEFAULT_OCR_MODELS),
|
|
2193
|
+
autoRec: DEFAULT_AUTO_REC
|
|
2194
|
+
});
|
|
2195
|
+
var DEFAULT_BUILTIN_OCR_FETCH = Object.freeze({ ...DEFAULT_BUILTIN_OCR, autoRec: { ...DEFAULT_AUTO_REC, fetch: true } });
|
|
2112
2196
|
function builtinOcrConfig(o) {
|
|
2113
|
-
if (!o || o.ocrDet === void 0 && o.ocrDetLongSide === void 0 && o.ocrRec === void 0 && o.ocrRecDict === void 0 && !o.ocrLines) return DEFAULT_BUILTIN_OCR;
|
|
2114
|
-
const bad =
|
|
2115
|
-
if (bad) throw new (0,
|
|
2116
|
-
const models =
|
|
2197
|
+
if (!o || o.ocrDet === void 0 && o.ocrDetLongSide === void 0 && o.ocrRec === void 0 && o.ocrRecDict === void 0 && !o.ocrLines) return _optionalChain([o, 'optionalAccess', _59 => _59.ocr]) ? DEFAULT_BUILTIN_OCR_FETCH : DEFAULT_BUILTIN_OCR;
|
|
2198
|
+
const bad = _chunkMMK32GPDcjs.validateOcrOptions.call(void 0, o);
|
|
2199
|
+
if (bad) throw new (0, _chunkXXBO2VOScjs.KordocError)(bad);
|
|
2200
|
+
const models = _chunkVALBVWMTcjs.resolveOcrModels.call(void 0, o);
|
|
2117
2201
|
return {
|
|
2118
2202
|
models,
|
|
2119
|
-
...o.ocrRec === "auto" ? { handwriting:
|
|
2203
|
+
...o.ocrRec === "auto" ? { handwriting: _chunkVALBVWMTcjs.handwritingFallbackModels.call(void 0, models), autoRec: AUTO_REC } : o.ocrRec === void 0 ? { handwriting: _chunkVALBVWMTcjs.handwritingFallbackModels.call(void 0, models), autoRec: o.ocr ? { ...DEFAULT_AUTO_REC, fetch: true } : DEFAULT_AUTO_REC } : {},
|
|
2120
2204
|
tuning: o.ocrDetLongSide === void 0 ? DEFAULT_OCR_TUNING : { ...DEFAULT_OCR_TUNING, detLongSide: o.ocrDetLongSide },
|
|
2121
2205
|
lines: o.ocrLines === "all" ? "all" : o.ocrLines ? "kept" : void 0
|
|
2122
2206
|
};
|
|
2123
2207
|
}
|
|
2124
|
-
var AUTO_REC_PAGE_CONF = 0.9;
|
|
2125
|
-
var AUTO_REC_GAIN = 0.06;
|
|
2126
2208
|
async function recognizeOcrPage(engine, config, tuning, rgba, width, height, stats, cellRules, rowRules) {
|
|
2127
2209
|
const items = await engine.recognizePage(rgba, width, height, stats, tuning, cellRules, rowRules);
|
|
2128
2210
|
if (!config.handwriting || stats.pageRotation) return items;
|
|
2211
|
+
const auto = _nullishCoalesce(config.autoRec, () => ( AUTO_REC));
|
|
2129
2212
|
const base = meanConfidence(items);
|
|
2130
|
-
if (base >=
|
|
2213
|
+
if (base >= auto.pageConf) return items;
|
|
2131
2214
|
const altStats = { droppedLowConf: 0, ...stats.dropped ? { dropped: [] } : {} };
|
|
2132
|
-
|
|
2133
|
-
|
|
2215
|
+
let alt;
|
|
2216
|
+
try {
|
|
2217
|
+
if (auto.lazy && !auto.fetch && !await _chunkVALBVWMTcjs.ocrModelsCached.call(void 0, config.handwriting)) return items;
|
|
2218
|
+
if (auto.lazy) await _chunkVALBVWMTcjs.ensureOcrModelsFor.call(void 0, config.handwriting, reportModelDownload);
|
|
2219
|
+
alt = await (await getOcrEngine(config.handwriting)).recognizePage(rgba, width, height, altStats, tuning, cellRules, rowRules);
|
|
2220
|
+
} catch (e) {
|
|
2221
|
+
if (!auto.lazy) throw e;
|
|
2222
|
+
return items;
|
|
2223
|
+
}
|
|
2224
|
+
if (meanConfidence(alt) - base < auto.gain) return items;
|
|
2134
2225
|
Object.assign(stats, altStats);
|
|
2135
2226
|
return alt;
|
|
2136
2227
|
}
|
|
@@ -2163,8 +2254,8 @@ async function runPdfOcr(buffer, targets, mode, warnings, onProgress, detectTabl
|
|
|
2163
2254
|
"@hyzyla/pdfium",
|
|
2164
2255
|
() => Promise.resolve().then(() => _interopRequireWildcard(require("@hyzyla/pdfium")))
|
|
2165
2256
|
);
|
|
2166
|
-
if (mode === "builtin") await
|
|
2167
|
-
if (mode === "builtin" && config.handwriting) await
|
|
2257
|
+
if (mode === "builtin") await _chunkVALBVWMTcjs.ensureOcrModelsFor.call(void 0, config.models, reportModelDownload);
|
|
2258
|
+
if (mode === "builtin" && config.handwriting && !_optionalChain([config, 'access', _60 => _60.autoRec, 'optionalAccess', _61 => _61.lazy])) await _chunkVALBVWMTcjs.ensureOcrModelsFor.call(void 0, config.handwriting, reportModelDownload);
|
|
2168
2259
|
const engine = mode === "builtin" ? await getOcrEngine(config.models) : null;
|
|
2169
2260
|
const pdfium = await pdfiumMod.PDFiumLibrary.init();
|
|
2170
2261
|
const doc = await pdfium.loadDocument(new Uint8Array(buffer));
|
|
@@ -2173,15 +2264,15 @@ async function runPdfOcr(buffer, targets, mode, warnings, onProgress, detectTabl
|
|
|
2173
2264
|
const count = doc.getPageCount();
|
|
2174
2265
|
for (const pageNo of [...targets].filter((p) => p >= 1 && p <= count).sort((a, b) => a - b)) {
|
|
2175
2266
|
const page = doc.getPage(pageNo - 1);
|
|
2176
|
-
_optionalChain([onProgress, 'optionalCall',
|
|
2267
|
+
_optionalChain([onProgress, 'optionalCall', _62 => _62(++done, targets.size)]);
|
|
2177
2268
|
try {
|
|
2178
2269
|
const { blocks, lines } = await withTimeout(
|
|
2179
|
-
ocrOnePage(page, pageNo, mode, engine, warnings, detectTables, _optionalChain([vectorOps, 'optionalAccess',
|
|
2270
|
+
ocrOnePage(page, pageNo, mode, engine, warnings, detectTables, _optionalChain([vectorOps, 'optionalAccess', _63 => _63.get, 'call', _64 => _64(pageNo)]), _optionalChain([imageRegions, 'optionalAccess', _65 => _65.get, 'call', _66 => _66(pageNo)]), config),
|
|
2180
2271
|
PAGE_TIMEOUT_MS,
|
|
2181
2272
|
`OCR \uD398\uC774\uC9C0 ${pageNo} \uD0C0\uC784\uC544\uC6C3 (${PAGE_TIMEOUT_MS / 1e3}\uCD08)`
|
|
2182
2273
|
);
|
|
2183
2274
|
result.set(pageNo, blocks);
|
|
2184
|
-
if (lines) _optionalChain([linesOut, 'optionalAccess',
|
|
2275
|
+
if (lines) _optionalChain([linesOut, 'optionalAccess', _67 => _67.set, 'call', _68 => _68(pageNo, lines)]);
|
|
2185
2276
|
} catch (e) {
|
|
2186
2277
|
warnings.push({
|
|
2187
2278
|
page: pageNo,
|
|
@@ -2265,7 +2356,7 @@ async function ocrOnePage(page, pageNo, mode, engine, warnings, detectTables, ve
|
|
|
2265
2356
|
const regionBlocks = regions.flatMap((r, k) => {
|
|
2266
2357
|
let own = items.filter((it) => inside(it, r));
|
|
2267
2358
|
const near = reads[k];
|
|
2268
|
-
if (_optionalChain([near, 'optionalAccess',
|
|
2359
|
+
if (_optionalChain([near, 'optionalAccess', _69 => _69.length]) && meanConfidence(near) > meanConfidence(own)) {
|
|
2269
2360
|
own = near;
|
|
2270
2361
|
reread.add(k);
|
|
2271
2362
|
}
|
|
@@ -2273,9 +2364,9 @@ async function ocrOnePage(page, pageNo, mode, engine, warnings, detectTables, ve
|
|
|
2273
2364
|
for (const it of own) used.add(it);
|
|
2274
2365
|
const blocks = ocrItemsToBlocks(own, pageNo, pdfW, pdfH, scale, ruling && rulingToPdfLines(ruling, scale, pdfH), detectTables, void 0, true);
|
|
2275
2366
|
const x1 = r.x1 * scale - 2, x2 = r.x2 * scale + 2, y1 = (pdfH - r.y2) * scale - 2, y2 = (pdfH - r.y1) * scale + 2;
|
|
2276
|
-
const columnRules = _nullishCoalesce(_optionalChain([ruling, 'optionalAccess',
|
|
2367
|
+
const columnRules = _nullishCoalesce(_optionalChain([ruling, 'optionalAccess', _70 => _70.verticals, 'access', _71 => _71.filter, 'call', _72 => _72((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', _73 => _73.length]), () => ( 0));
|
|
2277
2368
|
if (columnRules < 2) {
|
|
2278
|
-
for (const b of blocks) if (b.type === "table")
|
|
2369
|
+
for (const b of blocks) if (b.type === "table") _chunkVALBVWMTcjs.UNRULED_REGION_TABLES.add(b);
|
|
2279
2370
|
}
|
|
2280
2371
|
return blocks;
|
|
2281
2372
|
});
|
|
@@ -2334,7 +2425,7 @@ async function closerReads(rgba, rw, rh, pdfH, hi, regions, engine, tuning = REG
|
|
|
2334
2425
|
const items = await engine.recognizePage(crop, cw, ch, void 0, tuning);
|
|
2335
2426
|
out.push(items.map((it) => {
|
|
2336
2427
|
const placed = { ...it, x: (it.x + x0) / 2, y: (it.y + y0) / 2, w: it.w / 2, h: it.h / 2 };
|
|
2337
|
-
|
|
2428
|
+
_chunkVALBVWMTcjs.copyOcrTextGaps.call(void 0, it, placed, 0.5, x0 / 2);
|
|
2338
2429
|
return placed;
|
|
2339
2430
|
}));
|
|
2340
2431
|
}
|
|
@@ -2342,7 +2433,7 @@ async function closerReads(rgba, rw, rh, pdfH, hi, regions, engine, tuning = REG
|
|
|
2342
2433
|
}
|
|
2343
2434
|
var proseBox = (b) => {
|
|
2344
2435
|
const t = b.text.replace(/\s/g, "");
|
|
2345
|
-
return b.w >= b.h * 7 && (_nullishCoalesce(_optionalChain([t, 'access',
|
|
2436
|
+
return b.w >= b.h * 7 && (_nullishCoalesce(_optionalChain([t, 'access', _74 => _74.match, 'call', _75 => _75(/\d/g), 'optionalAccess', _76 => _76.length]), () => ( 0))) < t.length * 0.3;
|
|
2346
2437
|
};
|
|
2347
2438
|
function groupOcrLines(items, figureRegion = false) {
|
|
2348
2439
|
const order = items.map((_, i) => i).sort((a, b) => items[a].y + items[a].h / 2 - (items[b].y + items[b].h / 2));
|
|
@@ -2422,15 +2513,15 @@ function ocrItemsToBlocks(items, pageNumber, pdfW, pdfH, scale, extraLines, dete
|
|
|
2422
2513
|
isHidden: false,
|
|
2423
2514
|
...xs[i].space ? { hasSpaceBefore: true } : {}
|
|
2424
2515
|
};
|
|
2425
|
-
|
|
2516
|
+
_chunkVALBVWMTcjs.copyOcrTextGaps.call(void 0, it, normalized, 1 / scale);
|
|
2426
2517
|
return normalized;
|
|
2427
2518
|
}).filter((it) => it.text);
|
|
2428
|
-
const blocks = unframeOcrLayoutTables(splitStackedOcrRows(
|
|
2519
|
+
const blocks = unframeOcrLayoutTables(splitStackedOcrRows(_chunkVALBVWMTcjs.extractPageBlocksWithLines.call(void 0, norm, pageNumber, opList, pdfW, pdfH, extraLines, detectTables)), pdfH);
|
|
2429
2520
|
if (!figureRegion) markOcrHeadings(blocks);
|
|
2430
2521
|
return blocks;
|
|
2431
2522
|
}
|
|
2432
2523
|
function markOcrHeadings(blocks) {
|
|
2433
|
-
const sized = blocks.filter((b) => b.type === "paragraph" && b.text && _optionalChain([b, 'access',
|
|
2524
|
+
const sized = blocks.filter((b) => b.type === "paragraph" && b.text && _optionalChain([b, 'access', _77 => _77.style, 'optionalAccess', _78 => _78.fontSize]));
|
|
2434
2525
|
const weights = sized.map((b) => [b.style.fontSize, b.text.length]);
|
|
2435
2526
|
const total = weights.reduce((n, [, w]) => n + w, 0);
|
|
2436
2527
|
if (total < 100) return;
|
|
@@ -2447,6 +2538,16 @@ function markOcrHeadings(blocks) {
|
|
|
2447
2538
|
for (const b of sized) {
|
|
2448
2539
|
const text = b.text.trim(), size = b.style.fontSize;
|
|
2449
2540
|
const ratio = size / body;
|
|
2541
|
+
if (ratio >= 1 && ratio < 1.3 && /^제\s*\d+\s*[장절편부]\s*(?![에의은는을를이가와과로도만\s])\S/.test(text) && text.length <= 30 && !/[.!?。,]$|다\.?$/.test(text) && (!b.bbox || b.bbox.height <= size * 1.6)) {
|
|
2542
|
+
b.type = "heading";
|
|
2543
|
+
b.level = /^제\s*\d+\s*절/.test(text) ? 2 : 1;
|
|
2544
|
+
continue;
|
|
2545
|
+
}
|
|
2546
|
+
if (text.length <= 60 && /^[A-Z0-9][A-Z0-9 '’&:!,-]*$/.test(text) && (_nullishCoalesce(text.match(/[A-Z]/g), () => ( []))).length >= 12 && /[A-Z]{2,}[,:]?\s+[A-Z]{2,}/.test(text) && !/[.,]$/.test(text) && (!b.bbox || b.bbox.height <= size * 3.2)) {
|
|
2547
|
+
b.type = "heading";
|
|
2548
|
+
b.level = ratio >= 1.5 ? 1 : 2;
|
|
2549
|
+
continue;
|
|
2550
|
+
}
|
|
2450
2551
|
if (ratio < 1.3) continue;
|
|
2451
2552
|
if (text.length < 2 || text.length > (ratio >= 1.5 ? 60 : 40) || /[.!?。]$|다\.?$/.test(text) || /^[\d\s.,%·-]+$/.test(text)) continue;
|
|
2452
2553
|
if (b.bbox && b.bbox.height > size * (ratio >= 1.5 ? 3.2 : 1.6)) continue;
|
|
@@ -2457,9 +2558,9 @@ function markOcrHeadings(blocks) {
|
|
|
2457
2558
|
const a = blocks[i - 1], b = blocks[i];
|
|
2458
2559
|
if (a.type !== "heading" || b.type !== "heading" || !a.bbox || !b.bbox) continue;
|
|
2459
2560
|
const marker = /^(?:제\s*\d+\s*[장절편부]|chapter\s*\d+|part\s*\d+)$/i.test(a.text.trim());
|
|
2460
|
-
const sa = _nullishCoalesce(_optionalChain([a, 'access',
|
|
2561
|
+
const sa = _nullishCoalesce(_optionalChain([a, 'access', _79 => _79.style, 'optionalAccess', _80 => _80.fontSize]), () => ( 0)), sb = _nullishCoalesce(_optionalChain([b, 'access', _81 => _81.style, 'optionalAccess', _82 => _82.fontSize]), () => ( 0));
|
|
2461
2562
|
if (!marker && (a.level !== b.level || Math.max(sa, sb) > Math.min(sa, sb) * 1.3)) continue;
|
|
2462
|
-
const gap = a.bbox.y - (b.bbox.y + b.bbox.height), size = Math.max(_nullishCoalesce(_optionalChain([a, 'access',
|
|
2563
|
+
const gap = a.bbox.y - (b.bbox.y + b.bbox.height), size = Math.max(_nullishCoalesce(_optionalChain([a, 'access', _83 => _83.style, 'optionalAccess', _84 => _84.fontSize]), () => ( 0)), _nullishCoalesce(_optionalChain([b, 'access', _85 => _85.style, 'optionalAccess', _86 => _86.fontSize]), () => ( 0)));
|
|
2463
2564
|
const across = Math.min(a.bbox.x + a.bbox.width, b.bbox.x + b.bbox.width) - Math.max(a.bbox.x, b.bbox.x);
|
|
2464
2565
|
if (gap < 0 || gap > size * (marker ? 3 : 1.2) || across <= 0) continue;
|
|
2465
2566
|
a.level = Math.min(_nullishCoalesce(a.level, () => ( 2)), _nullishCoalesce(b.level, () => ( 2)));
|
|
@@ -2474,7 +2575,7 @@ async function tryImport2(name, loader) {
|
|
|
2474
2575
|
return await loader();
|
|
2475
2576
|
} catch (e) {
|
|
2476
2577
|
throw new Error(
|
|
2477
|
-
`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.${
|
|
2578
|
+
`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.${_chunkXXBO2VOScjs.OPTIONAL_DEP_INSTALL_HINT} \uC6D0\uC778: ${e.message}`
|
|
2478
2579
|
);
|
|
2479
2580
|
}
|
|
2480
2581
|
}
|
|
@@ -2525,4 +2626,4 @@ function bgraToRgba(bgra) {
|
|
|
2525
2626
|
|
|
2526
2627
|
|
|
2527
2628
|
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.groupOcrLines = groupOcrLines; exports.ocrItemsToBlocks = ocrItemsToBlocks; exports.markOcrHeadings = markOcrHeadings;
|
|
2528
|
-
//# sourceMappingURL=chunk-
|
|
2629
|
+
//# sourceMappingURL=chunk-7NTFM2LI.cjs.map
|