kordoc 4.24.44 → 4.24.46
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/{-H334XSXO.js → -N45T7D3V.js} +21 -21
- package/dist/{chunk-JI3WWHN2.js → chunk-4IIMCEUZ.js} +6 -6
- package/dist/{chunk-PSB3XI2U.js → chunk-5O5BKPET.js} +2 -2
- package/dist/{chunk-WLBPDYAT.js → chunk-5WR335MB.js} +11 -11
- package/dist/{chunk-OQCRVBB7.cjs → chunk-6A36TKBX.cjs} +6 -6
- package/dist/{chunk-OQCRVBB7.cjs.map → chunk-6A36TKBX.cjs.map} +1 -1
- package/dist/{chunk-ZGYKWZJS.cjs → chunk-7GM5ZLTC.cjs} +2 -2
- package/dist/{chunk-ZGYKWZJS.cjs.map → chunk-7GM5ZLTC.cjs.map} +1 -1
- package/dist/{chunk-NYQ6HNLA.js → chunk-7L7VO2L2.js} +2 -2
- package/dist/{chunk-XCRE5EMS.js → chunk-B2VBXPXH.js} +2 -2
- package/dist/{chunk-IV6GW3K7.js → chunk-BOQQO7X7.js} +2 -2
- package/dist/{chunk-IV6GW3K7.js.map → chunk-BOQQO7X7.js.map} +1 -1
- package/dist/{chunk-UZTGIVEH.js → chunk-BVLUNWRF.js} +5 -5
- package/dist/{chunk-QR5EL3EF.js → chunk-BY25KD5A.js} +2 -2
- package/dist/{chunk-HB3KLT7N.cjs → chunk-CUYBCAYZ.cjs} +58 -58
- package/dist/{chunk-HB3KLT7N.cjs.map → chunk-CUYBCAYZ.cjs.map} +1 -1
- package/dist/{chunk-O7EDZT7I.cjs → chunk-D46JZLFC.cjs} +98 -98
- package/dist/{chunk-O7EDZT7I.cjs.map → chunk-D46JZLFC.cjs.map} +1 -1
- package/dist/{chunk-HD6RQDGW.js → chunk-FQP6MKZY.js} +2 -2
- package/dist/{chunk-AS6INVO3.js → chunk-FRVE5JWE.js} +29 -9
- package/dist/chunk-FRVE5JWE.js.map +1 -0
- package/dist/{chunk-6M2Z6QDD.js → chunk-G2T6PBYW.js} +2 -2
- package/dist/{chunk-C2TMQUP4.js → chunk-GKD7J45E.js} +5 -5
- package/dist/{chunk-3EBWTFBT.js → chunk-HEH5WH2Q.js} +2 -2
- package/dist/{chunk-FQMLFAEN.js → chunk-JISE24L4.js} +10 -10
- package/dist/{chunk-7W6G4EC7.js → chunk-JRYQERD5.js} +2 -2
- package/dist/chunk-JRYQERD5.js.map +1 -0
- package/dist/{chunk-WF2GLWPA.js → chunk-KVRW3522.js} +20 -16
- package/dist/chunk-KVRW3522.js.map +1 -0
- package/dist/{chunk-GRY6ITVN.js → chunk-MIJ7EO56.js} +2 -2
- package/dist/{chunk-ABJ5DR2C.js → chunk-MVFUAMCR.js} +2 -2
- package/dist/{chunk-SXULSPB6.cjs → chunk-MYLKNYSY.cjs} +50 -30
- package/dist/chunk-MYLKNYSY.cjs.map +1 -0
- package/dist/{chunk-NJ2BJDHJ.js → chunk-MZX36SAT.js} +2 -2
- package/dist/{chunk-WXTEM53O.js → chunk-NJBY4HME.js} +2 -2
- package/dist/{chunk-6ZYOH3TZ.js → chunk-NJEMXMHP.js} +2 -2
- package/dist/{chunk-UETXNBIQ.js → chunk-NWABYDS5.js} +7 -7
- package/dist/{chunk-TRVRIIER.js → chunk-QDBOIQQI.js} +2 -2
- package/dist/{chunk-2TJ4E6MT.js → chunk-QF7UXLA2.js} +2 -2
- package/dist/{chunk-RUCMKRDE.js → chunk-QIRUP2IN.js} +2 -2
- package/dist/{chunk-YSRLHL2J.js → chunk-RNWOGZWU.js} +116 -7
- package/dist/chunk-RNWOGZWU.js.map +1 -0
- package/dist/{chunk-YEKQTHWN.js → chunk-SHYDVLFD.js} +5 -5
- package/dist/{chunk-HDP2NFYZ.js → chunk-TXEWEFWH.js} +28 -8
- package/dist/chunk-TXEWEFWH.js.map +1 -0
- package/dist/{chunk-RFSKHVLF.js → chunk-UHCEBHIY.js} +2 -2
- package/dist/{chunk-B3GHP32M.js → chunk-V5EDKEW3.js} +6 -6
- package/dist/{chunk-2KHZVNCS.js → chunk-VL7UACGR.js} +3 -3
- package/dist/{chunk-7VVBR5WX.js → chunk-WBBTXX7T.js} +115 -6
- package/dist/chunk-WBBTXX7T.js.map +1 -0
- package/dist/{chunk-IT34DGXJ.cjs → chunk-X2UNKZT4.cjs} +3 -3
- package/dist/{chunk-IT34DGXJ.cjs.map → chunk-X2UNKZT4.cjs.map} +1 -1
- package/dist/{chunk-AMLNYJWV.js → chunk-X5APVAKP.js} +3 -3
- package/dist/{chunk-YN3C6T5M.cjs → chunk-XEMHC53A.cjs} +225 -116
- package/dist/chunk-XEMHC53A.cjs.map +1 -0
- package/dist/{chunk-4Y5KRSHV.js → chunk-YV6BBJXJ.js} +3 -3
- package/dist/{chunk-HW6KA2HI.cjs → chunk-ZRKB6EVS.cjs} +3 -3
- package/dist/{chunk-HW6KA2HI.cjs.map → chunk-ZRKB6EVS.cjs.map} +1 -1
- package/dist/{chunk-2FDWBF47.js → chunk-ZWOUNYCK.js} +2 -2
- package/dist/chunks-4ERKEYKW.js +11 -0
- package/dist/cli.js +43 -43
- package/dist/{formula-XAUTHBU5.cjs → formula-C6ODQNSO.cjs} +9 -9
- package/dist/{formula-XAUTHBU5.cjs.map → formula-C6ODQNSO.cjs.map} +1 -1
- package/dist/{formula-DLJ44T7B.js → formula-K6TX7MPD.js} +4 -4
- package/dist/{formula-2FOYPHV2.js → formula-NSUMSGTH.js} +3 -3
- package/dist/generator-OHDWVKTZ.js +10 -0
- package/dist/generator-QQ43CWBH.cjs +11 -0
- package/dist/{generator-BIEVUOPW.cjs.map → generator-QQ43CWBH.cjs.map} +1 -1
- package/dist/generator-SEH6W2LS.js +17 -0
- package/dist/{hancom-B5LZPM5Y.js → hancom-24ZZS7G6.js} +2 -2
- package/dist/{hancom-W6XQOGQY.js → hancom-HXONTKAF.js} +2 -2
- package/dist/{hancom-TFYG5RGJ.cjs → hancom-MFD3WGNU.cjs} +5 -5
- package/dist/{hancom-TFYG5RGJ.cjs.map → hancom-MFD3WGNU.cjs.map} +1 -1
- package/dist/{image-ocr-6NMWKDT6.cjs → image-ocr-44UBGI4O.cjs} +27 -27
- package/dist/{image-ocr-6NMWKDT6.cjs.map → image-ocr-44UBGI4O.cjs.map} +1 -1
- package/dist/{image-ocr-BKFZMHFE.js → image-ocr-C4PANEFS.js} +7 -7
- package/dist/{image-ocr-XRXLPEBP.js → image-ocr-UWM2JO4F.js} +10 -10
- package/dist/index.cjs +1110 -1106
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +14 -10
- package/dist/index.js.map +1 -1
- package/dist/mcp.js +36 -36
- package/dist/memo-WOHINE33.js +17 -0
- package/dist/{model-bundle-R3AIXPVX.js → model-bundle-WAPNK77M.js} +5 -5
- package/dist/{models-BLHI4JAU.js → models-RVSU27QC.js} +5 -5
- package/dist/{parse-worker-v2-IB3KIORL.js → parse-worker-v2-SV4YBNJU.js} +22 -22
- package/dist/{parser-QR2TG3WE.js → parser-N7XYSGJF.js} +12 -12
- package/dist/{parser-7VLNB7T6.cjs → parser-QOBNISNN.cjs} +159 -159
- package/dist/{parser-7VLNB7T6.cjs.map → parser-QOBNISNN.cjs.map} +1 -1
- package/dist/{parser-QCPSCSGJ.js → parser-YYGB5XWO.js} +9 -9
- package/dist/pdf-ocr-EEMKTX5R.cjs +42 -0
- package/dist/{pdf-ocr-TUCEX4AY.cjs.map → pdf-ocr-EEMKTX5R.cjs.map} +1 -1
- package/dist/{pdf-ocr-TGXEFZB5.js → pdf-ocr-GFQNIMQG.js} +6 -6
- package/dist/{pdf-ocr-6PZ66I7G.js → pdf-ocr-WXNQMLU2.js} +9 -9
- package/dist/{profile-io-QL4XZ34F.js → profile-io-EKLAEN7W.js} +3 -3
- package/dist/{rasterize-PUG2V436.js → rasterize-IXUL6Y5W.js} +3 -3
- package/dist/{redact-doc-XDMXMF3A.js → redact-doc-JUTJ3SOJ.js} +21 -21
- package/dist/{render-IHE7XBO6.js → render-YPFJPUNC.js} +12 -12
- package/dist/{rewrite-fallback-J2KE4JIC.js → rewrite-fallback-H6ORRXXB.js} +13 -13
- package/dist/seal-J3JWCKI6.js +16 -0
- package/dist/{setup-FAU3G7N3.js → setup-R2HZNN6F.js} +3 -3
- package/dist/{to-hwpx-B5CXJLNS.js → to-hwpx-LRYNPYMS.js} +4 -4
- package/dist/to-hwpx-WHCXM2SA.cjs +16 -0
- package/dist/{to-hwpx-KFQVO5YC.cjs.map → to-hwpx-WHCXM2SA.cjs.map} +1 -1
- package/dist/{to-hwpx-YLJE3AZW.js → to-hwpx-WWWZ7USZ.js} +7 -7
- package/dist/visual-3XBGXVFX.js +37 -0
- package/dist/{watch-VKZVO6GV.js → watch-ETBDIPSJ.js} +22 -22
- package/package.json +1 -1
- package/dist/chunk-7VVBR5WX.js.map +0 -1
- package/dist/chunk-7W6G4EC7.js.map +0 -1
- package/dist/chunk-AS6INVO3.js.map +0 -1
- package/dist/chunk-HDP2NFYZ.js.map +0 -1
- package/dist/chunk-SXULSPB6.cjs.map +0 -1
- package/dist/chunk-WF2GLWPA.js.map +0 -1
- package/dist/chunk-YN3C6T5M.cjs.map +0 -1
- package/dist/chunk-YSRLHL2J.js.map +0 -1
- package/dist/chunks-IBZZKRII.js +0 -11
- package/dist/generator-5QCCBJM6.js +0 -10
- package/dist/generator-BIEVUOPW.cjs +0 -11
- package/dist/generator-S373GIY7.js +0 -17
- package/dist/memo-NMEJZR24.js +0 -17
- package/dist/pdf-ocr-TUCEX4AY.cjs +0 -42
- package/dist/seal-OXEZMJL4.js +0 -16
- package/dist/to-hwpx-KFQVO5YC.cjs +0 -16
- package/dist/visual-GJLFH23Q.js +0 -37
- /package/dist/{-H334XSXO.js.map → -N45T7D3V.js.map} +0 -0
- /package/dist/{chunk-JI3WWHN2.js.map → chunk-4IIMCEUZ.js.map} +0 -0
- /package/dist/{chunk-PSB3XI2U.js.map → chunk-5O5BKPET.js.map} +0 -0
- /package/dist/{chunk-WLBPDYAT.js.map → chunk-5WR335MB.js.map} +0 -0
- /package/dist/{chunk-NYQ6HNLA.js.map → chunk-7L7VO2L2.js.map} +0 -0
- /package/dist/{chunk-XCRE5EMS.js.map → chunk-B2VBXPXH.js.map} +0 -0
- /package/dist/{chunk-UZTGIVEH.js.map → chunk-BVLUNWRF.js.map} +0 -0
- /package/dist/{chunk-QR5EL3EF.js.map → chunk-BY25KD5A.js.map} +0 -0
- /package/dist/{chunk-HD6RQDGW.js.map → chunk-FQP6MKZY.js.map} +0 -0
- /package/dist/{chunk-6M2Z6QDD.js.map → chunk-G2T6PBYW.js.map} +0 -0
- /package/dist/{chunk-C2TMQUP4.js.map → chunk-GKD7J45E.js.map} +0 -0
- /package/dist/{chunk-3EBWTFBT.js.map → chunk-HEH5WH2Q.js.map} +0 -0
- /package/dist/{chunk-FQMLFAEN.js.map → chunk-JISE24L4.js.map} +0 -0
- /package/dist/{chunk-GRY6ITVN.js.map → chunk-MIJ7EO56.js.map} +0 -0
- /package/dist/{chunk-ABJ5DR2C.js.map → chunk-MVFUAMCR.js.map} +0 -0
- /package/dist/{chunk-NJ2BJDHJ.js.map → chunk-MZX36SAT.js.map} +0 -0
- /package/dist/{chunk-WXTEM53O.js.map → chunk-NJBY4HME.js.map} +0 -0
- /package/dist/{chunk-6ZYOH3TZ.js.map → chunk-NJEMXMHP.js.map} +0 -0
- /package/dist/{chunk-UETXNBIQ.js.map → chunk-NWABYDS5.js.map} +0 -0
- /package/dist/{chunk-TRVRIIER.js.map → chunk-QDBOIQQI.js.map} +0 -0
- /package/dist/{chunk-2TJ4E6MT.js.map → chunk-QF7UXLA2.js.map} +0 -0
- /package/dist/{chunk-RUCMKRDE.js.map → chunk-QIRUP2IN.js.map} +0 -0
- /package/dist/{chunk-YEKQTHWN.js.map → chunk-SHYDVLFD.js.map} +0 -0
- /package/dist/{chunk-RFSKHVLF.js.map → chunk-UHCEBHIY.js.map} +0 -0
- /package/dist/{chunk-B3GHP32M.js.map → chunk-V5EDKEW3.js.map} +0 -0
- /package/dist/{chunk-2KHZVNCS.js.map → chunk-VL7UACGR.js.map} +0 -0
- /package/dist/{chunk-AMLNYJWV.js.map → chunk-X5APVAKP.js.map} +0 -0
- /package/dist/{chunk-4Y5KRSHV.js.map → chunk-YV6BBJXJ.js.map} +0 -0
- /package/dist/{chunk-2FDWBF47.js.map → chunk-ZWOUNYCK.js.map} +0 -0
- /package/dist/{chunks-IBZZKRII.js.map → chunks-4ERKEYKW.js.map} +0 -0
- /package/dist/{formula-DLJ44T7B.js.map → formula-K6TX7MPD.js.map} +0 -0
- /package/dist/{formula-2FOYPHV2.js.map → formula-NSUMSGTH.js.map} +0 -0
- /package/dist/{generator-5QCCBJM6.js.map → generator-OHDWVKTZ.js.map} +0 -0
- /package/dist/{generator-S373GIY7.js.map → generator-SEH6W2LS.js.map} +0 -0
- /package/dist/{hancom-B5LZPM5Y.js.map → hancom-24ZZS7G6.js.map} +0 -0
- /package/dist/{hancom-W6XQOGQY.js.map → hancom-HXONTKAF.js.map} +0 -0
- /package/dist/{image-ocr-BKFZMHFE.js.map → image-ocr-C4PANEFS.js.map} +0 -0
- /package/dist/{image-ocr-XRXLPEBP.js.map → image-ocr-UWM2JO4F.js.map} +0 -0
- /package/dist/{memo-NMEJZR24.js.map → memo-WOHINE33.js.map} +0 -0
- /package/dist/{model-bundle-R3AIXPVX.js.map → model-bundle-WAPNK77M.js.map} +0 -0
- /package/dist/{models-BLHI4JAU.js.map → models-RVSU27QC.js.map} +0 -0
- /package/dist/{parse-worker-v2-IB3KIORL.js.map → parse-worker-v2-SV4YBNJU.js.map} +0 -0
- /package/dist/{parser-QR2TG3WE.js.map → parser-N7XYSGJF.js.map} +0 -0
- /package/dist/{parser-QCPSCSGJ.js.map → parser-YYGB5XWO.js.map} +0 -0
- /package/dist/{pdf-ocr-6PZ66I7G.js.map → pdf-ocr-GFQNIMQG.js.map} +0 -0
- /package/dist/{pdf-ocr-TGXEFZB5.js.map → pdf-ocr-WXNQMLU2.js.map} +0 -0
- /package/dist/{profile-io-QL4XZ34F.js.map → profile-io-EKLAEN7W.js.map} +0 -0
- /package/dist/{rasterize-PUG2V436.js.map → rasterize-IXUL6Y5W.js.map} +0 -0
- /package/dist/{redact-doc-XDMXMF3A.js.map → redact-doc-JUTJ3SOJ.js.map} +0 -0
- /package/dist/{render-IHE7XBO6.js.map → render-YPFJPUNC.js.map} +0 -0
- /package/dist/{rewrite-fallback-J2KE4JIC.js.map → rewrite-fallback-H6ORRXXB.js.map} +0 -0
- /package/dist/{seal-OXEZMJL4.js.map → seal-J3JWCKI6.js.map} +0 -0
- /package/dist/{setup-FAU3G7N3.js.map → setup-R2HZNN6F.js.map} +0 -0
- /package/dist/{to-hwpx-B5CXJLNS.js.map → to-hwpx-LRYNPYMS.js.map} +0 -0
- /package/dist/{to-hwpx-YLJE3AZW.js.map → to-hwpx-WWWZ7USZ.js.map} +0 -0
- /package/dist/{visual-GJLFH23Q.js.map → visual-3XBGXVFX.js.map} +0 -0
- /package/dist/{watch-VKZVO6GV.js.map → watch-ETBDIPSJ.js.map} +0 -0
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
|
|
37
37
|
|
|
38
38
|
|
|
39
|
-
var
|
|
39
|
+
var _chunkMYLKNYSYcjs = require('./chunk-MYLKNYSY.cjs');
|
|
40
40
|
|
|
41
41
|
|
|
42
42
|
var _chunkMMK32GPDcjs = require('./chunk-MMK32GPD.cjs');
|
|
@@ -46,7 +46,7 @@ var _chunkTK3FDAEEcjs = require('./chunk-TK3FDAEE.cjs');
|
|
|
46
46
|
|
|
47
47
|
|
|
48
48
|
|
|
49
|
-
var
|
|
49
|
+
var _chunk7GM5ZLTCcjs = require('./chunk-7GM5ZLTC.cjs');
|
|
50
50
|
|
|
51
51
|
// src/ocr/ocr-stacked-rows.ts
|
|
52
52
|
var NUMERIC = /^[-+−△▲▽▼]?[\d.,]+[%p]?$|^[-–—·∼~]$|^\([-+−△▲▽▼]?[\d.,]+%?\)$/;
|
|
@@ -77,7 +77,10 @@ function splitTable(t) {
|
|
|
77
77
|
for (let r = 0; r < t.rows; r++) {
|
|
78
78
|
const row = _nullishCoalesce(t.cells[r], () => ( []));
|
|
79
79
|
const anchors = rowAnchors(t, r, cover[r]);
|
|
80
|
-
const lines = anchors.map((a) =>
|
|
80
|
+
const lines = anchors.map((a) => {
|
|
81
|
+
const ls = a.cell.text.split("\n").map((s) => s.trim()).filter(Boolean);
|
|
82
|
+
return (_nullishCoalesce(a.cell.rowSpan, () => ( 1))) > 1 && ls.length > 1 && ls.every((l) => !NUMERIC.test(l.replace(/\s+/g, ""))) ? [ls.join("\n")] : ls;
|
|
83
|
+
});
|
|
81
84
|
const counts = /* @__PURE__ */ new Map();
|
|
82
85
|
for (const ls of lines) if (ls.length >= 2) counts.set(ls.length, (_nullishCoalesce(counts.get(ls.length), () => ( 0))) + 1);
|
|
83
86
|
const [k, n] = _nullishCoalesce([...counts].sort((a, b) => b[1] - a[1])[0], () => ( [0, 0]));
|
|
@@ -157,6 +160,109 @@ function unframeOcrLayoutTables(blocks, pageHeight) {
|
|
|
157
160
|
return out;
|
|
158
161
|
}
|
|
159
162
|
|
|
163
|
+
// src/ocr/ocr-name-value-columns.ts
|
|
164
|
+
var NAME_VALUE = /^([^\d]*?)\s*(\d[\d,.]*\d|\d)([^\d\n]{0,2})(?:\n([^\d]*))?$/;
|
|
165
|
+
function nameValue(text) {
|
|
166
|
+
const m = NAME_VALUE.exec(text.trim());
|
|
167
|
+
if (!m) return null;
|
|
168
|
+
const name = [m[1], _nullishCoalesce(m[4], () => ( ""))].map((s) => s.replace(/\s+/g, " ").trim()).filter(Boolean).join(" ");
|
|
169
|
+
if ((_nullishCoalesce(name.match(/[가-힣A-Za-z]/g), () => ( []))).length < 2) return null;
|
|
170
|
+
return { name, value: (m[2] + m[3]).trim() };
|
|
171
|
+
}
|
|
172
|
+
function owners(t) {
|
|
173
|
+
const own = Array.from({ length: t.rows }, () => Array(t.cols));
|
|
174
|
+
for (let r = 0; r < t.rows; r++) for (let c = 0; c < t.cols; c++) {
|
|
175
|
+
if (own[r][c]) continue;
|
|
176
|
+
const cell = t.cells[r][c];
|
|
177
|
+
for (let i = r; i < Math.min(t.rows, r + Math.max(1, _nullishCoalesce(cell.rowSpan, () => ( 1)))); i++)
|
|
178
|
+
for (let j = c; j < Math.min(t.cols, c + Math.max(1, _nullishCoalesce(cell.colSpan, () => ( 1)))); j++) own[i][j] ??= cell;
|
|
179
|
+
}
|
|
180
|
+
return own;
|
|
181
|
+
}
|
|
182
|
+
function headerCuts(text) {
|
|
183
|
+
const out = [];
|
|
184
|
+
for (const m of text.matchAll(/\s+/g)) {
|
|
185
|
+
const l = text.slice(0, m.index).replace(/\s+/g, ""), r = text.slice(m.index + m[0].length).replace(/\s+/g, "");
|
|
186
|
+
if (l.length >= 2 && r.length >= 2) out.push([l, r]);
|
|
187
|
+
}
|
|
188
|
+
return out;
|
|
189
|
+
}
|
|
190
|
+
function cutAt(text, left) {
|
|
191
|
+
let n = 0;
|
|
192
|
+
for (let i = 0; i < text.length; i++) {
|
|
193
|
+
if (!/\s/.test(text[i])) n++;
|
|
194
|
+
if (n === left.length) return [text.slice(0, i + 1).trim(), text.slice(i + 1).trim()];
|
|
195
|
+
}
|
|
196
|
+
return null;
|
|
197
|
+
}
|
|
198
|
+
function splitTable2(t) {
|
|
199
|
+
if (t.cells.length !== t.rows || t.cells.some((row) => row.length !== t.cols)) return false;
|
|
200
|
+
const own = owners(t);
|
|
201
|
+
const anchor = (r, c) => own[r][c] === t.cells[r][c] ? t.cells[r][c] : null;
|
|
202
|
+
const targets = [];
|
|
203
|
+
for (let c = 0; c < t.cols; c++) {
|
|
204
|
+
let filled = 0, hits = 0, grouped = 0, first = -1;
|
|
205
|
+
for (let r = 0; r < t.rows; r++) {
|
|
206
|
+
const cell = anchor(r, c);
|
|
207
|
+
if (!cell || (_nullishCoalesce(cell.colSpan, () => ( 1))) !== 1 || _optionalChain([cell, 'access', _4 => _4.blocks, 'optionalAccess', _5 => _5.length]) || !cell.text.trim()) continue;
|
|
208
|
+
const nv = nameValue(cell.text);
|
|
209
|
+
if (nv) {
|
|
210
|
+
hits++;
|
|
211
|
+
if (first < 0) first = r;
|
|
212
|
+
if (/,\d{2}|\.\d/.test(nv.value)) grouped++;
|
|
213
|
+
}
|
|
214
|
+
if (first >= 0) filled++;
|
|
215
|
+
}
|
|
216
|
+
if (hits >= 5 && hits >= filled * 0.8 && grouped >= 2) targets.push({ c, first });
|
|
217
|
+
}
|
|
218
|
+
if (!targets.length) return false;
|
|
219
|
+
const starts = /* @__PURE__ */ new Map();
|
|
220
|
+
for (const { first } of targets) starts.set(first, (_nullishCoalesce(starts.get(first), () => ( 0))) + 1);
|
|
221
|
+
const start = [...starts].sort((a, b) => b[1] - a[1] || a[0] - b[0])[0][0];
|
|
222
|
+
for (const tg of targets) if (tg.first > start) tg.first = start;
|
|
223
|
+
const heads = targets.map(({ c, first }) => {
|
|
224
|
+
const cell = first > 0 ? anchor(first - 1, c) : null;
|
|
225
|
+
return cell && (_nullishCoalesce(cell.colSpan, () => ( 1))) === 1 && (_nullishCoalesce(cell.rowSpan, () => ( 1))) === 1 && cell.text.trim() ? cell : null;
|
|
226
|
+
});
|
|
227
|
+
const votes = /* @__PURE__ */ new Map();
|
|
228
|
+
for (const h of heads) if (h) for (const [l, r] of headerCuts(h.text.trim())) votes.set(`${l}\0${r}`, (_nullishCoalesce(votes.get(`${l}\0${r}`), () => ( 0))) + 1);
|
|
229
|
+
const [best, second] = [...votes].sort((a, b) => b[1] - a[1]);
|
|
230
|
+
const cut = best && (!second || best[1] > second[1]) ? best[0].split("\0") : null;
|
|
231
|
+
for (const [k, { c, first }] of [...targets.entries()].reverse()) {
|
|
232
|
+
const grown = /* @__PURE__ */ new Set();
|
|
233
|
+
for (let r = 0; r < t.rows; r++) {
|
|
234
|
+
const cell = anchor(r, c);
|
|
235
|
+
let right = { text: "", colSpan: 1, rowSpan: 1 };
|
|
236
|
+
if (cell && (_nullishCoalesce(cell.colSpan, () => ( 1))) === 1 && !_optionalChain([cell, 'access', _6 => _6.blocks, 'optionalAccess', _7 => _7.length])) {
|
|
237
|
+
const text = cell.text.trim();
|
|
238
|
+
const nv = r >= first ? nameValue(text) : null;
|
|
239
|
+
const head = r === first - 1 && heads[k] === cell && cut && text.replace(/\s+/g, "") === cut.join("") ? cutAt(text, cut[0]) : null;
|
|
240
|
+
if (nv) {
|
|
241
|
+
cell.text = nv.name;
|
|
242
|
+
right = { ...cell, text: nv.value };
|
|
243
|
+
} else if (head) {
|
|
244
|
+
cell.text = head[0];
|
|
245
|
+
right = { ...cell, text: head[1] };
|
|
246
|
+
} else if (r >= first && text && /^[\d,.\s%()+-]+$/.test(text)) {
|
|
247
|
+
right = { ...cell, text };
|
|
248
|
+
cell.text = "";
|
|
249
|
+
} else cell.colSpan = 2;
|
|
250
|
+
grown.add(cell);
|
|
251
|
+
} else if (!grown.has(own[r][c])) {
|
|
252
|
+
own[r][c].colSpan = Math.max(1, _nullishCoalesce(own[r][c].colSpan, () => ( 1))) + 1;
|
|
253
|
+
grown.add(own[r][c]);
|
|
254
|
+
}
|
|
255
|
+
t.cells[r].splice(c + 1, 0, right);
|
|
256
|
+
}
|
|
257
|
+
t.cols++;
|
|
258
|
+
}
|
|
259
|
+
return true;
|
|
260
|
+
}
|
|
261
|
+
function splitOcrNameValueColumns(blocks) {
|
|
262
|
+
for (const b of blocks) if (b.type === "table" && b.table) splitTable2(b.table);
|
|
263
|
+
return blocks;
|
|
264
|
+
}
|
|
265
|
+
|
|
160
266
|
// src/ocr/ruling-lines.ts
|
|
161
267
|
var INK_LUMA_MAX = 205;
|
|
162
268
|
var MIN_LINE_LENGTH_PT = 20;
|
|
@@ -171,6 +277,7 @@ var DOT_MAX_DASH_PT = 4;
|
|
|
171
277
|
var DOT_MAX_PERIOD_PT = 2.2;
|
|
172
278
|
var DOT_MIN_COUNT = 8;
|
|
173
279
|
var DOT_TOUCH_PT = 1.5;
|
|
280
|
+
var DOT_ONE_SIDE_MIN_PT = 60;
|
|
174
281
|
var FILL_DELTA = 10;
|
|
175
282
|
var FILL_MIN_LENGTH_PT = 10;
|
|
176
283
|
var FILL_MIN_DEPTH_PT = 4;
|
|
@@ -216,7 +323,9 @@ function detectRulingLines(rgba, width, height, scale) {
|
|
|
216
323
|
const allH = [...horizontals, ...dotH], allV = [...verticals, ...dotV];
|
|
217
324
|
const touchesV = (a) => allV.some((p) => p.x1 >= a.x1 - tol && p.x1 <= a.x2 + tol && a.y1 >= p.y1 - tol && a.y1 <= p.y2 + tol);
|
|
218
325
|
const touchesH = (a) => allH.some((p) => p.y1 >= a.y1 - tol && p.y1 <= a.y2 + tol && a.x1 >= p.x1 - tol && a.x1 <= p.x2 + tol);
|
|
219
|
-
|
|
326
|
+
const crossesV = (a) => new Set(allV.filter((p) => p.x1 >= a.x1 - tol && p.x1 <= a.x2 + tol && a.y1 >= p.y1 - tol && a.y1 <= p.y2 + tol).map((p) => Math.round(p.x1 / tol))).size >= 2;
|
|
327
|
+
const oneSideMin = DOT_ONE_SIDE_MIN_PT * scale;
|
|
328
|
+
horizontals.push(...dotH.filter((a) => crossesV(a) || a.x2 - a.x1 >= oneSideMin && touchesV(a)));
|
|
220
329
|
verticals.push(...dotV.filter(touchesH));
|
|
221
330
|
const inkV = [...verticals];
|
|
222
331
|
const ruleH = horizontals.filter((p) => inkV.some((v) => v.x1 >= p.x1 - tol && v.x1 <= p.x2 + tol && p.y1 >= v.y1 - tol && p.y1 <= v.y2 + tol));
|
|
@@ -517,8 +626,8 @@ var INKLESS_DELTA = 32;
|
|
|
517
626
|
function ringAsks(rgba, pageW, box, text, steps, stepPx) {
|
|
518
627
|
const chars = [...text];
|
|
519
628
|
if (chars.length !== steps.length || !/[가-힣]/.test(text)) return [];
|
|
520
|
-
const gray =
|
|
521
|
-
const rings =
|
|
629
|
+
const gray = _chunkMYLKNYSYcjs.grayCrop.call(void 0, rgba, pageW, box);
|
|
630
|
+
const rings = _chunkMYLKNYSYcjs.ringBoxes.call(void 0, gray, box.w, box.h, _chunkMYLKNYSYcjs.inkStats.call(void 0, gray));
|
|
522
631
|
const owner = ringOwners(chars, (i) => (steps[i] + 0.5) * stepPx, rings);
|
|
523
632
|
return rings.flatMap((r, k) => {
|
|
524
633
|
const at = owner.indexOf(k);
|
|
@@ -558,8 +667,8 @@ function ringGlyph(read, jamo = null, confidence = 1) {
|
|
|
558
667
|
function restoreGlyphs(rgba, pageW, box, text, steps, stepPx, note = {}, rings = []) {
|
|
559
668
|
const chars = [...text];
|
|
560
669
|
if (chars.length !== steps.length) return text;
|
|
561
|
-
const gray =
|
|
562
|
-
const c = { chars, cx: (i) => (steps[i] + 0.5) * stepPx, gray, w: box.w, h: box.h, ink:
|
|
670
|
+
const gray = _chunkMYLKNYSYcjs.grayCrop.call(void 0, rgba, pageW, box);
|
|
671
|
+
const c = { chars, cx: (i) => (steps[i] + 0.5) * stepPx, gray, w: box.w, h: box.h, ink: _chunkMYLKNYSYcjs.inkStats.call(void 0, gray) };
|
|
563
672
|
if (/[[\]]/.test(text)) brackets(c);
|
|
564
673
|
if (text.includes("'")) cornerQuotes(c);
|
|
565
674
|
if (/['"]/.test(text)) quotes(c);
|
|
@@ -589,7 +698,7 @@ function restoreGlyphs(rgba, pageW, box, text, steps, stepPx, note = {}, rings =
|
|
|
589
698
|
function trimInklessEnds(rgba, pageW, box, text, steps, stepPx) {
|
|
590
699
|
const chars = [...text], { w, h } = box;
|
|
591
700
|
if (chars.length !== steps.length || steps.some((s) => (s + 0.5) * stepPx > w + stepPx)) return { text, steps };
|
|
592
|
-
const gray =
|
|
701
|
+
const gray = _chunkMYLKNYSYcjs.grayCrop.call(void 0, rgba, pageW, box);
|
|
593
702
|
const hist = new Uint32Array(256);
|
|
594
703
|
for (const v of gray) hist[v]++;
|
|
595
704
|
let bg = 0;
|
|
@@ -620,8 +729,8 @@ function cornerCommas({ chars, cx, gray, w, h, ink }) {
|
|
|
620
729
|
continue;
|
|
621
730
|
}
|
|
622
731
|
if (open > 0) {
|
|
623
|
-
const f =
|
|
624
|
-
if (f &&
|
|
732
|
+
const f = _chunkMYLKNYSYcjs.bracketFeatures.call(void 0, gray, w, h, ink, cx(i));
|
|
733
|
+
if (f && _chunkMYLKNYSYcjs.bracketShape.call(void 0, f, true) === "\u300D") {
|
|
625
734
|
chars[i] = "\u300D";
|
|
626
735
|
open--;
|
|
627
736
|
}
|
|
@@ -631,12 +740,12 @@ function cornerCommas({ chars, cx, gray, w, h, ink }) {
|
|
|
631
740
|
function cornerQuotes({ chars, cx, gray, w, h, ink }) {
|
|
632
741
|
for (let i = 0; i < chars.length; i++) {
|
|
633
742
|
if (chars[i] !== "'" || !/^[가-힣]/.test(_nullishCoalesce(chars[i + 1], () => ( "")))) continue;
|
|
634
|
-
const f =
|
|
635
|
-
if (!f || f.ch < f.charH * 0.45 ||
|
|
743
|
+
const f = _chunkMYLKNYSYcjs.bracketFeatures.call(void 0, gray, w, h, ink, cx(i));
|
|
744
|
+
if (!f || f.ch < f.charH * 0.45 || _chunkMYLKNYSYcjs.bracketShape.call(void 0, f, false) !== "\u300C") continue;
|
|
636
745
|
const rest = chars.slice(i + 1), end = rest.findIndex((c) => c === "'" || c === "\u300D" || c === ",");
|
|
637
746
|
const pair = end >= 0 && rest[end] !== "'" && (rest[end] === "\u300D" || (() => {
|
|
638
|
-
const g =
|
|
639
|
-
return !!g &&
|
|
747
|
+
const g = _chunkMYLKNYSYcjs.bracketFeatures.call(void 0, gray, w, h, ink, cx(i + 1 + end));
|
|
748
|
+
return !!g && _chunkMYLKNYSYcjs.bracketShape.call(void 0, g, true) === "\u300D";
|
|
640
749
|
})());
|
|
641
750
|
if (pair) chars[i] = "\u300C";
|
|
642
751
|
}
|
|
@@ -644,8 +753,8 @@ function cornerQuotes({ chars, cx, gray, w, h, ink }) {
|
|
|
644
753
|
function brackets({ chars, cx, gray, w, h, ink }) {
|
|
645
754
|
const shape = chars.map((c, i) => {
|
|
646
755
|
if (c !== "[" && c !== "]") return null;
|
|
647
|
-
const f =
|
|
648
|
-
return f &&
|
|
756
|
+
const f = _chunkMYLKNYSYcjs.bracketFeatures.call(void 0, gray, w, h, ink, cx(i));
|
|
757
|
+
return f && _chunkMYLKNYSYcjs.bracketShape.call(void 0, f, c === "]");
|
|
649
758
|
});
|
|
650
759
|
for (let i = 0; i < chars.length; i++) {
|
|
651
760
|
if (chars[i] !== "[") continue;
|
|
@@ -677,7 +786,7 @@ function quotes({ chars, cx, gray, w, h, ink }) {
|
|
|
677
786
|
continue;
|
|
678
787
|
}
|
|
679
788
|
if (!year(i) && !single[kind]) continue;
|
|
680
|
-
const r =
|
|
789
|
+
const r = _chunkMYLKNYSYcjs.quoteHead.call(void 0, gray, w, h, ink, cx(i));
|
|
681
790
|
if (r !== null && r >= 0.47) {
|
|
682
791
|
chars[i] = kind === "'" ? "\u2018" : "\u201C";
|
|
683
792
|
open[kind] = true;
|
|
@@ -688,7 +797,7 @@ function dashes({ chars, cx, gray, w, h, ink }) {
|
|
|
688
797
|
const head = chars.findIndex((c) => c.trim()), letters = chars.some((c) => /[가-힣A-Za-z]/.test(c));
|
|
689
798
|
for (let i = 0; i < chars.length; i++) {
|
|
690
799
|
if (!/^[-\u2013\u2014]$/.test(chars[i])) continue;
|
|
691
|
-
const r =
|
|
800
|
+
const r = _chunkMYLKNYSYcjs.dashRatio.call(void 0, gray, w, h, ink, cx(i));
|
|
692
801
|
if (r === null) continue;
|
|
693
802
|
if (r < 0.65) chars[i] = "-";
|
|
694
803
|
else if (r > 0.75 && i === head && letters) chars[i] = "\u2014";
|
|
@@ -698,7 +807,7 @@ function circled({ chars, cx, gray, w, h, ink }) {
|
|
|
698
807
|
const alone = (re, i) => re.test(chars[i]) && !re.test(_nullishCoalesce(chars[i - 1], () => ( ""))) && !re.test(_nullishCoalesce(chars[i + 1], () => ( "")));
|
|
699
808
|
const at = chars.flatMap((_, i) => alone(/^\d$/, i) && chars[i] !== "0" || alone(/^[ㄱ-ㅎ]$/, i) || alone(/^[A-Za-z]$/, i) && /[a-zCSUVWXZ]/.test(chars[i]) ? [i] : []);
|
|
700
809
|
if (!at.length) return;
|
|
701
|
-
const hit =
|
|
810
|
+
const hit = _chunkMYLKNYSYcjs.circledAt.call(void 0, gray, w, h, ink, at.map(cx));
|
|
702
811
|
const JAMO = "\u3131\u3134\u3137\u3139\u3141\u3142\u3145\u3147\u3148\u314A\u314B\u314C\u314D\u314E";
|
|
703
812
|
at.forEach((i, k) => {
|
|
704
813
|
if (!hit[k]) return;
|
|
@@ -711,16 +820,16 @@ function stars({ chars, cx, gray, w, h, ink }) {
|
|
|
711
820
|
if (chars[i] !== "*" || chars[i - 1] === "*") continue;
|
|
712
821
|
let e = i;
|
|
713
822
|
while (chars[e + 1] === "*") e++;
|
|
714
|
-
const n =
|
|
823
|
+
const n = _chunkMYLKNYSYcjs.starRun.call(void 0, gray, w, h, ink, cx(i));
|
|
715
824
|
if (n > e - i + 1 && n <= 4) chars[e] += "*".repeat(n - (e - i + 1));
|
|
716
825
|
i = e;
|
|
717
826
|
}
|
|
718
827
|
}
|
|
719
828
|
function discs({ chars, cx, gray, w, h, ink }) {
|
|
720
|
-
for (let i = 0; i < chars.length; i++) if (/^[\u00b7\u2022]$/.test(chars[i]) &&
|
|
829
|
+
for (let i = 0; i < chars.length; i++) if (/^[\u00b7\u2022]$/.test(chars[i]) && _chunkMYLKNYSYcjs.discAt.call(void 0, gray, w, h, ink, cx(i))) chars[i] = "\u25CF";
|
|
721
830
|
}
|
|
722
831
|
function gaps({ chars, cx, gray, w, h, ink }) {
|
|
723
|
-
const { glyphs, bandH } =
|
|
832
|
+
const { glyphs, bandH } = _chunkMYLKNYSYcjs.gapGlyphs.call(void 0, gray, w, h, ink);
|
|
724
833
|
if (!glyphs.length) return;
|
|
725
834
|
const live = chars.map((c, i) => i).filter((i) => chars[i].trim());
|
|
726
835
|
if (!live.length) return;
|
|
@@ -733,7 +842,7 @@ function gaps({ chars, cx, gray, w, h, ink }) {
|
|
|
733
842
|
if (tail >= 1 && tail <= 3 && tail < live.length) {
|
|
734
843
|
const prev = live[live.length - 1 - tail], num = live[live.length - tail];
|
|
735
844
|
const run = loose.filter((g) => (g.x0 + g.x1) / 2 > cx(prev) && (g.x0 + g.x1) / 2 < cx(num));
|
|
736
|
-
const mark = _optionalChain([run, 'access',
|
|
845
|
+
const mark = _optionalChain([run, 'access', _8 => _8[0], 'optionalAccess', _9 => _9.mark, 'access', _10 => _10[0]]);
|
|
737
846
|
if (run.length >= 2 && run.length <= 3 && run.every((g) => g.mark[0] === mark) && /^[가-힣?)]$/.test(chars[prev]) && !glyphs.some((g) => !run.includes(g) && (g.x0 + g.x1) / 2 > cx(prev) && (g.x0 + g.x1) / 2 < cx(num)))
|
|
738
847
|
chars[prev] += " " + mark.repeat(run.length) + " ";
|
|
739
848
|
}
|
|
@@ -791,18 +900,18 @@ function ring({ chars, cx, gray, w, h, ink }) {
|
|
|
791
900
|
const rest = chars.slice(k + 1).join("").trimStart();
|
|
792
901
|
const live = chars.map((c, i) => i).filter((i) => chars[i].trim());
|
|
793
902
|
if (live.length <= 3 && live.every((i) => /^[Oo]$/.test(chars[i]))) {
|
|
794
|
-
if (_optionalChain([
|
|
795
|
-
if (!live.every((i) =>
|
|
903
|
+
if (_optionalChain([_chunkMYLKNYSYcjs.leadingBullet.call(void 0, gray, w, h, ink, cx(live[0])), 'optionalAccess', _11 => _11.mark]) === "\u25CE") return false;
|
|
904
|
+
if (!live.every((i) => _chunkMYLKNYSYcjs.ringBullet.call(void 0, gray, w, h, ink, cx(i)) === "\u25CB")) return false;
|
|
796
905
|
for (const i of live) chars[i] = "\u25CB";
|
|
797
906
|
return true;
|
|
798
907
|
}
|
|
799
908
|
if (/^[A-Z]{2,}/.test(rest) && /^[Oo0]$/.test(chars[k])) {
|
|
800
|
-
if (
|
|
909
|
+
if (_chunkMYLKNYSYcjs.ringBullet.call(void 0, gray, w, h, ink, cx(k)) !== "\u25CB") return false;
|
|
801
910
|
chars[k] = chars[k + 1] === " " ? "\u25CB" : "\u25CB ";
|
|
802
911
|
return true;
|
|
803
912
|
}
|
|
804
913
|
if (!/^[(\[「【<]?\d*[가-힣]/.test(rest)) return false;
|
|
805
|
-
const r =
|
|
914
|
+
const r = _chunkMYLKNYSYcjs.ringBullet.call(void 0, gray, w, h, ink, cx(k));
|
|
806
915
|
if (/^[Cc]$/.test(chars[k]) && r !== "\u25CB") return false;
|
|
807
916
|
if (r) chars[k] = r;
|
|
808
917
|
return r !== null;
|
|
@@ -819,7 +928,7 @@ function parallels({ chars, cx, gray, w, h, ink }) {
|
|
|
819
928
|
let p = s - 1, q = e + 1;
|
|
820
929
|
while (p >= 0 && !chars[p].trim()) p--;
|
|
821
930
|
while (q < chars.length && !chars[q].trim()) q++;
|
|
822
|
-
if (
|
|
931
|
+
if (_chunkMYLKNYSYcjs.slantedPair.call(void 0, gray, w, h, ink, p >= 0 ? cx(p) : -Infinity, q < chars.length ? cx(q) : Infinity)) {
|
|
823
932
|
chars[s] = "\u2225";
|
|
824
933
|
for (let k = s + 1; k <= e; k++) chars[k] = "";
|
|
825
934
|
}
|
|
@@ -831,7 +940,7 @@ function roman({ chars, cx, gray, w, h, ink }) {
|
|
|
831
940
|
const ROMAN = /^[IⅠ-Ⅲ]$/, LATIN = /[A-Za-z]$/;
|
|
832
941
|
for (let i = 0; i < chars.length; i++) {
|
|
833
942
|
if (chars[i] !== "1" || /[\dA-Za-z]$/.test(_nullishCoalesce(chars[i - 1], () => ( ""))) || /^[\dA-Za-z,]/.test(_nullishCoalesce(chars[i + 1], () => ( "")))) continue;
|
|
834
|
-
if (
|
|
943
|
+
if (_chunkMYLKNYSYcjs.serifOne.call(void 0, gray, w, h, ink, cx(i))) chars[i] = "\u2160";
|
|
835
944
|
}
|
|
836
945
|
for (let i = 0; i < chars.length; i++) {
|
|
837
946
|
const hangul = /^[파피]$/.test(chars[i]);
|
|
@@ -841,13 +950,13 @@ function roman({ chars, cx, gray, w, h, ink }) {
|
|
|
841
950
|
while (q < chars.length && !chars[q].trim()) q++;
|
|
842
951
|
const glued = hangul ? chars[p] === "(" && chars[q] === "-" : /[가-힣]$/.test(_nullishCoalesce(chars[i - 1], () => ( ""))) || (_nullishCoalesce(chars[i + 1], () => ( ""))) === "." || chars[p] === "-" && chars[q] === "-";
|
|
843
952
|
if (!glued) continue;
|
|
844
|
-
const n =
|
|
953
|
+
const n = _chunkMYLKNYSYcjs.romanStems.call(void 0, gray, w, h, ink, p >= 0 ? cx(p) : -Infinity, q < chars.length ? cx(q) : Infinity, /[가-힣]$/.test(_nullishCoalesce(chars[p], () => ( ""))));
|
|
845
954
|
if (n) chars[i] = String.fromCharCode(8543 + n);
|
|
846
955
|
}
|
|
847
956
|
const inRoman = (i) => ROMAN.test(chars[i]) || chars[i] === "1" && (ROMAN.test(_nullishCoalesce(chars[i - 1], () => ( ""))) || ROMAN.test(_nullishCoalesce(chars[i + 1], () => ( ""))));
|
|
848
957
|
const k = chars.findIndex((c) => c.trim());
|
|
849
958
|
if (chars[k] === "." && chars.slice(k + 1).some((c) => /[가-힣A-Za-z0-9]/.test(c))) {
|
|
850
|
-
const n =
|
|
959
|
+
const n = _chunkMYLKNYSYcjs.romanStems.call(void 0, gray, w, h, ink, -Infinity, cx(k));
|
|
851
960
|
if (n) chars[k] = String.fromCharCode(8543 + n) + chars[k];
|
|
852
961
|
}
|
|
853
962
|
for (let s = 0; s < chars.length; ) {
|
|
@@ -865,7 +974,7 @@ function roman({ chars, cx, gray, w, h, ink }) {
|
|
|
865
974
|
let p = s - 1, q = e;
|
|
866
975
|
while (p >= 0 && !chars[p].trim()) p--;
|
|
867
976
|
while (q < chars.length && !chars[q].trim()) q++;
|
|
868
|
-
const n =
|
|
977
|
+
const n = _chunkMYLKNYSYcjs.romanStems.call(void 0, gray, w, h, ink, p >= 0 ? cx(p) : -Infinity, q < chars.length ? cx(q) : Infinity, /[가-힣]$/.test(_nullishCoalesce(chars[p], () => ( ""))));
|
|
869
978
|
const canon = n ? [["\u2160", "I"], ["\u2161", "II"], ["\u2162", "III"]][n - 1] : null;
|
|
870
979
|
if (canon && !canon.includes(tok)) {
|
|
871
980
|
chars[s] = canon[0];
|
|
@@ -960,7 +1069,7 @@ function joinLeaderItems(items, ends) {
|
|
|
960
1069
|
for (const o of items) if (!gone.has(o) && junk(o) && sameLine(o, left) && o.x + o.w / 2 >= left.x + left.w - left.h && o.x + o.w / 2 <= right.x + right.h) gone.add(o);
|
|
961
1070
|
};
|
|
962
1071
|
for (const it of [...items].sort((a, b) => b.x - a.x)) {
|
|
963
|
-
if (gone.has(it) || !_optionalChain([ends, 'access',
|
|
1072
|
+
if (gone.has(it) || !_optionalChain([ends, 'access', _12 => _12.get, 'call', _13 => _13(it), 'optionalAccess', _14 => _14.lead])) continue;
|
|
964
1073
|
const left = neighbor(it, true);
|
|
965
1074
|
if (left) {
|
|
966
1075
|
dropJunkBetween(left, it);
|
|
@@ -968,7 +1077,7 @@ function joinLeaderItems(items, ends) {
|
|
|
968
1077
|
}
|
|
969
1078
|
}
|
|
970
1079
|
for (const it of [...items].sort((a, b) => a.x - b.x)) {
|
|
971
|
-
if (gone.has(it) || !_optionalChain([ends, 'access',
|
|
1080
|
+
if (gone.has(it) || !_optionalChain([ends, 'access', _15 => _15.get, 'call', _16 => _16(it), 'optionalAccess', _17 => _17.trail])) continue;
|
|
972
1081
|
const right = neighbor(it, false);
|
|
973
1082
|
if (right) {
|
|
974
1083
|
dropJunkBetween(it, right);
|
|
@@ -1169,7 +1278,7 @@ function rowHeadDashes(rgba, width, items) {
|
|
|
1169
1278
|
if (done.has(it) || it.h < 12) continue;
|
|
1170
1279
|
const row = items.filter((o) => Math.min(o.y + o.h, it.y + it.h) - Math.max(o.y, it.y) >= Math.min(o.h, it.h) * 0.6);
|
|
1171
1280
|
for (const o of row) done.add(o);
|
|
1172
|
-
if (row.reduce((k, o) => k + (_nullishCoalesce(_optionalChain([o, 'access',
|
|
1281
|
+
if (row.reduce((k, o) => k + (_nullishCoalesce(_optionalChain([o, 'access', _18 => _18.text, 'access', _19 => _19.match, 'call', _20 => _20(/[가-힣]/g), 'optionalAccess', _21 => _21.length]), () => ( 0))), 0) < 2) continue;
|
|
1173
1282
|
const first = row.reduce((m, o) => o.x < m.x ? o : m);
|
|
1174
1283
|
if (!/^[가-힣]/.test(first.text)) continue;
|
|
1175
1284
|
if (row.filter((o) => /\d/.test(o.text)).length >= 2) continue;
|
|
@@ -1214,7 +1323,7 @@ function rowTailBoxes(rgba, width, items) {
|
|
|
1214
1323
|
if (done.has(it) || it.h < 12) continue;
|
|
1215
1324
|
const row = items.filter((o) => Math.min(o.y + o.h, it.y + it.h) - Math.max(o.y, it.y) >= Math.min(o.h, it.h) * 0.6);
|
|
1216
1325
|
for (const o of row) done.add(o);
|
|
1217
|
-
if (row.reduce((k, o) => k + (_nullishCoalesce(_optionalChain([o, 'access',
|
|
1326
|
+
if (row.reduce((k, o) => k + (_nullishCoalesce(_optionalChain([o, 'access', _22 => _22.text, 'access', _23 => _23.match, 'call', _24 => _24(/[가-힣]/g), 'optionalAccess', _25 => _25.length]), () => ( 0))), 0) < 2) continue;
|
|
1218
1327
|
const last = row.reduce((m, o) => o.x + o.w > m.x + m.w ? o : m);
|
|
1219
1328
|
if (/\d$/.test(last.text.trim())) continue;
|
|
1220
1329
|
const y0 = Math.min(...row.map((o) => o.y)), y1 = Math.max(...row.map((o) => o.y + o.h)), h = y1 - y0;
|
|
@@ -1263,8 +1372,8 @@ function joinGapLeaders(rgba, width, items) {
|
|
|
1263
1372
|
if (g1 - g0 < h * 3) continue;
|
|
1264
1373
|
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));
|
|
1265
1374
|
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 };
|
|
1266
|
-
const gray =
|
|
1267
|
-
const runs =
|
|
1375
|
+
const gray = _chunkMYLKNYSYcjs.grayCrop.call(void 0, rgba, width, box);
|
|
1376
|
+
const runs = _chunkMYLKNYSYcjs.leaderRuns.call(void 0, gray, box.w, box.h, _chunkMYLKNYSYcjs.inkStats.call(void 0, gray), LEADER_MIN_DOTS);
|
|
1268
1377
|
const cover = runs.reduce((k, [a, b]) => k + Math.max(0, Math.min(b, g1 - box.x) - Math.max(a, g0 - box.x)), 0);
|
|
1269
1378
|
if (cover < (g1 - g0) * 0.6) continue;
|
|
1270
1379
|
for (const o of items) if (junk(o) && sameLine(o, num) && o.x >= g0 - 2 && o.x + o.w <= g1 + 2) gone.add(o);
|
|
@@ -1291,7 +1400,7 @@ function rowHeadBoxes(rgba, width, items) {
|
|
|
1291
1400
|
if (done.has(it) || it.h < 12) continue;
|
|
1292
1401
|
const row = items.filter((o) => Math.min(o.y + o.h, it.y + it.h) - Math.max(o.y, it.y) >= Math.min(o.h, it.h) * 0.6);
|
|
1293
1402
|
for (const o of row) done.add(o);
|
|
1294
|
-
if (row.reduce((k, o) => k + (_nullishCoalesce(_optionalChain([o, 'access',
|
|
1403
|
+
if (row.reduce((k, o) => k + (_nullishCoalesce(_optionalChain([o, 'access', _26 => _26.text, 'access', _27 => _27.match, 'call', _28 => _28(/[가-힣]/g), 'optionalAccess', _29 => _29.length]), () => ( 0))), 0) < 2) continue;
|
|
1295
1404
|
const first = row.reduce((m, o) => o.x < m.x ? o : m);
|
|
1296
1405
|
if (!/^[가-힣\d]/.test(first.text)) continue;
|
|
1297
1406
|
const hs = row.map((o) => o.h).sort((a, b) => a - b), h = hs[hs.length >> 1];
|
|
@@ -1457,7 +1566,7 @@ function closingParens(rgba, width, items) {
|
|
|
1457
1566
|
};
|
|
1458
1567
|
for (const it of items) {
|
|
1459
1568
|
const t = it.text.replace(/\s+$/, "");
|
|
1460
|
-
if ((_nullishCoalesce(_optionalChain([t, 'access',
|
|
1569
|
+
if ((_nullishCoalesce(_optionalChain([t, 'access', _30 => _30.match, 'call', _31 => _31(/\(/g), 'optionalAccess', _32 => _32.length]), () => ( 0))) <= (_nullishCoalesce(_optionalChain([t, 'access', _33 => _33.match, 'call', _34 => _34(/\)/g), 'optionalAccess', _35 => _35.length]), () => ( 0))) || !/\([^()]*$/.test(t)) continue;
|
|
1461
1570
|
const x0 = it.x + it.w + 2;
|
|
1462
1571
|
const next = items.filter((o) => o !== it && o.x >= x0 && o.y < it.y + it.h && o.y + o.h > it.y).reduce((m, o) => Math.min(m, o.x), Infinity);
|
|
1463
1572
|
let x1 = Math.min(width, next, x0 + it.h * 16);
|
|
@@ -1531,7 +1640,7 @@ var OcrEngine = class _OcrEngine {
|
|
|
1531
1640
|
this.ort = parts.ort;
|
|
1532
1641
|
this.sharp = parts.sharp;
|
|
1533
1642
|
}
|
|
1534
|
-
static async create(models =
|
|
1643
|
+
static async create(models = _chunkMYLKNYSYcjs.DEFAULT_OCR_MODELS) {
|
|
1535
1644
|
_chunkTK3FDAEEcjs.disableOrtTelemetry.call(void 0, );
|
|
1536
1645
|
const [ortMod, sharpModRaw] = await Promise.all([
|
|
1537
1646
|
tryImport("onnxruntime-node", () => Promise.resolve().then(() => _interopRequireWildcard(require("onnxruntime-node")))),
|
|
@@ -1551,16 +1660,16 @@ var OcrEngine = class _OcrEngine {
|
|
|
1551
1660
|
const local = (s) => "spec" in s ? Promise.resolve(null) : verifiedBytes(s);
|
|
1552
1661
|
const [detBytes, recBytes, dictBytes] = await Promise.all([local(models.det), local(models.rec), local(models.dict)]);
|
|
1553
1662
|
const session = (s, bytes) => bytes ? ortMod.InferenceSession.create(bytes, sessionOpts).catch(() => {
|
|
1554
|
-
throw new (0,
|
|
1555
|
-
}) : ortMod.InferenceSession.create(
|
|
1663
|
+
throw new (0, _chunk7GM5ZLTCcjs.KordocError)(`OCR \uBAA8\uB378\uC744 \uC5F4\uC9C0 \uBABB\uD588\uC2B5\uB2C8\uB2E4: ${_path.basename.call(void 0, _chunkMYLKNYSYcjs.ocrSourcePath.call(void 0, s))} \u2014 ONNX \uBAA8\uB378\uC774 \uC544\uB2C8\uAC70\uB098 \uC190\uC0C1\uB410\uC2B5\uB2C8\uB2E4`);
|
|
1664
|
+
}) : ortMod.InferenceSession.create(_chunkMYLKNYSYcjs.ocrSourcePath.call(void 0, s), sessionOpts);
|
|
1556
1665
|
const [det, rec, dictYml] = await Promise.all([
|
|
1557
1666
|
session(models.det, detBytes),
|
|
1558
1667
|
session(models.rec, recBytes),
|
|
1559
|
-
dictBytes ? new TextDecoder().decode(dictBytes) : _promises.readFile.call(void 0,
|
|
1668
|
+
dictBytes ? new TextDecoder().decode(dictBytes) : _promises.readFile.call(void 0, _chunkMYLKNYSYcjs.ocrSourcePath.call(void 0, models.dict), "utf-8")
|
|
1560
1669
|
]);
|
|
1561
|
-
const dict =
|
|
1670
|
+
const dict = _chunkMYLKNYSYcjs.parseCharacterDict.call(void 0, dictYml);
|
|
1562
1671
|
if (dict.length === 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,
|
|
1672
|
+
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, _chunk7GM5ZLTCcjs.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`);
|
|
1564
1673
|
}
|
|
1565
1674
|
return new _OcrEngine({ det, rec, dict, ort: ortMod, sharp: sharpMod });
|
|
1566
1675
|
}
|
|
@@ -1592,10 +1701,10 @@ var OcrEngine = class _OcrEngine {
|
|
|
1592
1701
|
if (it.x - x < it.h * 0.8) return;
|
|
1593
1702
|
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;
|
|
1594
1703
|
const box = { x, y: it.y, w: it.x + it.w - x, h: it.h };
|
|
1595
|
-
const g =
|
|
1596
|
-
const b =
|
|
1597
|
-
if (_optionalChain([b, 'optionalAccess',
|
|
1598
|
-
const ink =
|
|
1704
|
+
const g = _chunkMYLKNYSYcjs.grayCrop.call(void 0, rgba, width, box);
|
|
1705
|
+
const b = _chunkMYLKNYSYcjs.leadingBullet.call(void 0, g, box.w, box.h, _chunkMYLKNYSYcjs.inkStats.call(void 0, g), it.x - x, 1.05);
|
|
1706
|
+
if (_optionalChain([b, 'optionalAccess', _36 => _36.mark]) !== "\u25A1" || b.covers) return;
|
|
1707
|
+
const ink = _chunkMYLKNYSYcjs.inkStats.call(void 0, g), on = (v) => ink.darkInk ? v <= ink.threshold : v > ink.threshold;
|
|
1599
1708
|
let left = 0;
|
|
1600
1709
|
while (left < it.x - x && !Array.from({ length: box.h }, (_, y) => g[y * box.w + left]).some(on)) left++;
|
|
1601
1710
|
it.text = "\u25A1 " + it.text;
|
|
@@ -1611,7 +1720,7 @@ var OcrEngine = class _OcrEngine {
|
|
|
1611
1720
|
const sample = [...tall].sort((a, b) => b.h - a.h).slice(0, ORIENT_SAMPLE);
|
|
1612
1721
|
const rots = [0, 90, 270];
|
|
1613
1722
|
const probe = await this.recognizeJobs(rgba, width, sample.flatMap((box, group2) => rots.map((rot) => ({ box, rot, group: group2 }))), tuning.recBatch);
|
|
1614
|
-
const mean = (k) => sample.reduce((sum, _, i) => sum + (_nullishCoalesce(_optionalChain([probe, 'access',
|
|
1723
|
+
const mean = (k) => sample.reduce((sum, _, i) => sum + (_nullishCoalesce(_optionalChain([probe, 'access', _37 => _37[i * rots.length + k], 'optionalAccess', _38 => _38.confidence]), () => ( 0))), 0) / sample.length;
|
|
1615
1724
|
const [m0, m90, m270] = rots.map((_, k) => mean(k));
|
|
1616
1725
|
const best2 = Math.max(m90, m270);
|
|
1617
1726
|
if (best2 >= ORIENT_MIN_CONF && best2 >= m0 + ORIENT_GAIN) {
|
|
@@ -1627,12 +1736,12 @@ var OcrEngine = class _OcrEngine {
|
|
|
1627
1736
|
const joins = [];
|
|
1628
1737
|
let group = 0;
|
|
1629
1738
|
for (const b of boxes) {
|
|
1630
|
-
const gray =
|
|
1631
|
-
const ink =
|
|
1739
|
+
const gray = _chunkMYLKNYSYcjs.grayCrop.call(void 0, rgba, width, b);
|
|
1740
|
+
const ink = _chunkMYLKNYSYcjs.inkStats.call(void 0, gray);
|
|
1632
1741
|
if (tuning.minInkContrast > 0 && ink.contrast < tuning.minInkContrast) continue;
|
|
1633
1742
|
if (tuning.minInkContrast > 0 && ink.inkRatio < MIN_INK_RATIO) continue;
|
|
1634
1743
|
if (tuning.splitTall && b.h >= b.w * TALL_RATIO) {
|
|
1635
|
-
const bands =
|
|
1744
|
+
const bands = _chunkMYLKNYSYcjs.splitRowBands.call(void 0, gray, b.w, b.h, ink, 0.45);
|
|
1636
1745
|
if (bands.length >= 2) {
|
|
1637
1746
|
for (const sub of bandBoxes(b, bands, height)) jobs.push({ box: sub, rot: 0, group: group++ });
|
|
1638
1747
|
continue;
|
|
@@ -1643,9 +1752,9 @@ var OcrEngine = class _OcrEngine {
|
|
|
1643
1752
|
continue;
|
|
1644
1753
|
}
|
|
1645
1754
|
}
|
|
1646
|
-
const trim = tuning.trimEdges ?
|
|
1755
|
+
const trim = tuning.trimEdges ? _chunkMYLKNYSYcjs.edgeTrim.call(void 0, gray, b.w, b.h, ink) : null;
|
|
1647
1756
|
const keep = trim ? { ...trim, bg: median(gray) } : void 0;
|
|
1648
|
-
const leaders = tuning.splitLeaders ?
|
|
1757
|
+
const leaders = tuning.splitLeaders ? _chunkMYLKNYSYcjs.leaderRuns.call(void 0, gray, b.w, b.h, ink, LEADER_MIN_DOTS) : [];
|
|
1649
1758
|
if (leaders.length) {
|
|
1650
1759
|
const join = joins.length;
|
|
1651
1760
|
joins.push({ box: b, parts: [], trailDots: false });
|
|
@@ -1654,7 +1763,7 @@ var OcrEngine = class _OcrEngine {
|
|
|
1654
1763
|
const bare = { x: b.x + x0, y: b.y, w: a - x0, h: b.h };
|
|
1655
1764
|
const end = c > a ? Math.min(c, a + Math.round(b.h * LEADER_CONTEXT)) : a;
|
|
1656
1765
|
x0 = c;
|
|
1657
|
-
if (bare.w >= DET_MIN_SIZE &&
|
|
1766
|
+
if (bare.w >= DET_MIN_SIZE && _chunkMYLKNYSYcjs.inkStats.call(void 0, _chunkMYLKNYSYcjs.grayCrop.call(void 0, rgba, width, bare)).contrast >= Math.max(1, tuning.minInkContrast)) {
|
|
1658
1767
|
jobs.push({ box: { ...bare, w: end - (bare.x - b.x) }, rot: 0, group: group++, join, dotsBefore: dots, trimDots: end > a });
|
|
1659
1768
|
dots = false;
|
|
1660
1769
|
}
|
|
@@ -1702,40 +1811,40 @@ var OcrEngine = class _OcrEngine {
|
|
|
1702
1811
|
let text = tuning.postprocess ? restoreSymbols(raw.trim(), note.ringLead) : raw;
|
|
1703
1812
|
if (!text.trim()) continue;
|
|
1704
1813
|
if (tuning.postprocess && job.rot === 0 && text !== "/" && /^[(:;/)]+$/.test(text) && text.includes("/")) {
|
|
1705
|
-
const g =
|
|
1706
|
-
if (
|
|
1814
|
+
const g = _chunkMYLKNYSYcjs.grayCrop.call(void 0, rgba, width, job.box);
|
|
1815
|
+
if (_chunkMYLKNYSYcjs.tallInkCount.call(void 0, g, job.box.w, job.box.h, _chunkMYLKNYSYcjs.inkStats.call(void 0, g)) === 1) text = "/";
|
|
1707
1816
|
}
|
|
1708
1817
|
let ringByShape = false;
|
|
1709
1818
|
if (tuning.postprocess && job.rot === 0 && !/^[◎●▪□■▣❐❏○ㅇ◆◇◈]/.test(text)) {
|
|
1710
1819
|
const chars = [...read], k = chars.findIndex((c) => c.trim());
|
|
1711
1820
|
if (k >= 0 && steps.length === chars.length) {
|
|
1712
|
-
const g =
|
|
1713
|
-
const b =
|
|
1821
|
+
const g = _chunkMYLKNYSYcjs.grayCrop.call(void 0, rgba, width, job.box);
|
|
1822
|
+
const b = _chunkMYLKNYSYcjs.leadingBullet.call(void 0, g, job.box.w, job.box.h, _chunkMYLKNYSYcjs.inkStats.call(void 0, g), (steps[k] + 0.5) * stepPx);
|
|
1714
1823
|
const body = (_nullishCoalesce(text.match(/[가-힣]/g), () => ( []))).length >= 4;
|
|
1715
1824
|
const miss = /^[Oo0•·ㆍ∙‧○]/.test(text);
|
|
1716
|
-
if (_optionalChain([b, 'optionalAccess',
|
|
1825
|
+
if (_optionalChain([b, 'optionalAccess', _39 => _39.mark]) === "\u25CE" && b.covers && /^[Oo0○©]/.test(text)) {
|
|
1717
1826
|
text = b.mark + " " + text.slice(1).trimStart();
|
|
1718
1827
|
ringByShape = true;
|
|
1719
|
-
} else if (_optionalChain([b, 'optionalAccess',
|
|
1828
|
+
} else if (_optionalChain([b, 'optionalAccess', _40 => _40.mark]) === "\u25A1" || _optionalChain([b, 'optionalAccess', _41 => _41.mark]) === "\u25A3") {
|
|
1720
1829
|
if (!b.covers && body) text = b.mark + " " + text;
|
|
1721
|
-
} else if (_optionalChain([b, 'optionalAccess',
|
|
1830
|
+
} else if (_optionalChain([b, 'optionalAccess', _42 => _42.mark]) === "\u25C6" || _optionalChain([b, 'optionalAccess', _43 => _43.mark]) === "\u25C7" || _optionalChain([b, 'optionalAccess', _44 => _44.mark]) === "\u25C8") {
|
|
1722
1831
|
if (b.covers ? /^[\p{S}\p{P}]/u.test(text) : body) text = b.covers ? b.mark + " " + text.slice(1).trimStart() : b.mark + " " + text;
|
|
1723
|
-
} else if (_optionalChain([b, 'optionalAccess',
|
|
1832
|
+
} else if (_optionalChain([b, 'optionalAccess', _45 => _45.mark]) === "\u2023") {
|
|
1724
1833
|
if (b.covers ? text.startsWith("\u2192") : body) text = b.covers ? b.mark + " " + text.slice(1).trimStart() : b.mark + " " + text;
|
|
1725
|
-
} else if (_optionalChain([b, 'optionalAccess',
|
|
1834
|
+
} else if (_optionalChain([b, 'optionalAccess', _46 => _46.mark]) === "\u2750" || _optionalChain([b, 'optionalAccess', _47 => _47.mark]) === "\u274F") {
|
|
1726
1835
|
if (b.covers ? /^[ㅁ口]/.test(text) : body) text = b.covers ? b.mark + text.slice(1) : b.mark + " " + text;
|
|
1727
1836
|
} else if (b && b.mark !== "\u25CE" && body) text = b.covers ? miss ? b.mark + " " + text.slice(1).trimStart() : text : b.mark + " " + text;
|
|
1728
|
-
else if (!b && body && /^[가-힣]/.test(chars[k]) &&
|
|
1837
|
+
else if (!b && body && /^[가-힣]/.test(chars[k]) && _chunkMYLKNYSYcjs.leadingRing.call(void 0, g, job.box.w, job.box.h, _chunkMYLKNYSYcjs.inkStats.call(void 0, g), (steps[k] + 0.5) * stepPx)) text = "\u25CB " + text;
|
|
1729
1838
|
}
|
|
1730
1839
|
}
|
|
1731
1840
|
if (tuning.postprocess && /^\d/.test(text) && job.rot === 0) {
|
|
1732
|
-
const g =
|
|
1733
|
-
const tri =
|
|
1841
|
+
const g = _chunkMYLKNYSYcjs.grayCrop.call(void 0, rgba, width, job.box);
|
|
1842
|
+
const tri = _chunkMYLKNYSYcjs.leadingTriangle.call(void 0, g, job.box.w, job.box.h, _chunkMYLKNYSYcjs.inkStats.call(void 0, g));
|
|
1734
1843
|
if (tri) text = tri + text;
|
|
1735
1844
|
}
|
|
1736
1845
|
if (tuning.postprocess && text === "\u2192" && job.rot === 0 && job.join === void 0) {
|
|
1737
|
-
const g =
|
|
1738
|
-
text = _nullishCoalesce(
|
|
1846
|
+
const g = _chunkMYLKNYSYcjs.grayCrop.call(void 0, rgba, width, job.box);
|
|
1847
|
+
text = _nullishCoalesce(_chunkMYLKNYSYcjs.arrowGlyph.call(void 0, g, job.box.w, job.box.h, _chunkMYLKNYSYcjs.inkStats.call(void 0, g)), () => ( text));
|
|
1739
1848
|
}
|
|
1740
1849
|
if (job.footer) {
|
|
1741
1850
|
if (!/^[-\u2013\u2014]?\s*(?:\d{1,4}|[ivxIVXⅰ-ⅹⅠ-Ⅹ]{1,4})\s*[-\u2013\u2014]?$/.test(text.trim())) continue;
|
|
@@ -1746,7 +1855,7 @@ var OcrEngine = class _OcrEngine {
|
|
|
1746
1855
|
if (tuning.postprocess && job.rot === 0 && job.join === void 0 && !job.footer) retry.push(job.box);
|
|
1747
1856
|
if (stats) {
|
|
1748
1857
|
stats.droppedLowConf++;
|
|
1749
|
-
_optionalChain([stats, 'access',
|
|
1858
|
+
_optionalChain([stats, 'access', _48 => _48.dropped, 'optionalAccess', _49 => _49.push, 'call', _50 => _50({ text, ...this.itemBox(rgba, width, job.box, tuning), confidence })]);
|
|
1750
1859
|
}
|
|
1751
1860
|
continue;
|
|
1752
1861
|
}
|
|
@@ -1756,7 +1865,7 @@ var OcrEngine = class _OcrEngine {
|
|
|
1756
1865
|
continue;
|
|
1757
1866
|
}
|
|
1758
1867
|
const item = { text, ...this.itemBox(rgba, width, job.box, tuning), confidence };
|
|
1759
|
-
if (job.rot === 0)
|
|
1868
|
+
if (job.rot === 0) _chunkMYLKNYSYcjs.rememberOcrTextGaps.call(void 0, item, _chunkMYLKNYSYcjs.findOcrTextGaps.call(void 0, rgba, width, job.box, read, text, steps, stepPx));
|
|
1760
1869
|
if (job.rot === 0 && job.keep === void 0) boxOf.set(item, job.box);
|
|
1761
1870
|
items.push(item);
|
|
1762
1871
|
}
|
|
@@ -1769,14 +1878,14 @@ var OcrEngine = class _OcrEngine {
|
|
|
1769
1878
|
const r = res[k];
|
|
1770
1879
|
if (!r || /\s/.test(r.text.trim()) || badThousands(r.text) || r.confidence < it.confidence - 0.05 || skeleton(r.text) !== skeleton(it.text)) return;
|
|
1771
1880
|
it.text = restoreSymbols(r.text.trim());
|
|
1772
|
-
|
|
1881
|
+
_chunkMYLKNYSYcjs.rememberOcrTextGaps.call(void 0, it, _chunkMYLKNYSYcjs.findOcrTextGaps.call(void 0, rgba, width, boxOf.get(it), r.text, it.text, r.steps, r.stepPx));
|
|
1773
1882
|
});
|
|
1774
1883
|
}
|
|
1775
1884
|
if (retry.length) {
|
|
1776
1885
|
const subs = [];
|
|
1777
1886
|
for (const b of retry) {
|
|
1778
|
-
const gray =
|
|
1779
|
-
const cut = midBlankRow(gray, b.w, b.h,
|
|
1887
|
+
const gray = _chunkMYLKNYSYcjs.grayCrop.call(void 0, rgba, width, b);
|
|
1888
|
+
const cut = midBlankRow(gray, b.w, b.h, _chunkMYLKNYSYcjs.inkStats.call(void 0, gray));
|
|
1780
1889
|
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] });
|
|
1781
1890
|
}
|
|
1782
1891
|
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));
|
|
@@ -1818,16 +1927,16 @@ var OcrEngine = class _OcrEngine {
|
|
|
1818
1927
|
if (tails.length) {
|
|
1819
1928
|
const res = await this.recognizeJobs(rgba, width, tails.map((box, k) => ({ box, rot: 0, group: k })), tuning.recBatch);
|
|
1820
1929
|
tails.forEach((box, k) => {
|
|
1821
|
-
const t = _nullishCoalesce(_optionalChain([res, 'access',
|
|
1822
|
-
if (/^\d{1,4}$/.test(t) && (_nullishCoalesce(_optionalChain([res, 'access',
|
|
1930
|
+
const t = _nullishCoalesce(_optionalChain([res, 'access', _51 => _51[k], 'optionalAccess', _52 => _52.text, 'access', _53 => _53.trim, 'call', _54 => _54()]), () => ( ""));
|
|
1931
|
+
if (/^\d{1,4}$/.test(t) && (_nullishCoalesce(_optionalChain([res, 'access', _55 => _55[k], 'optionalAccess', _56 => _56.confidence]), () => ( 0))) >= tuning.textScore) items.push({ text: t, ...this.itemBox(rgba, width, box, tuning), confidence: res[k].confidence });
|
|
1823
1932
|
});
|
|
1824
1933
|
}
|
|
1825
1934
|
const heads = rowHeadBoxes(rgba, width, items);
|
|
1826
1935
|
if (heads.length) {
|
|
1827
1936
|
const res = await this.recognizeJobs(rgba, width, heads.map((box, k) => ({ box, rot: 0, group: k })), tuning.recBatch);
|
|
1828
1937
|
heads.forEach((box, k) => {
|
|
1829
|
-
const t = _nullishCoalesce(_optionalChain([res, 'access',
|
|
1830
|
-
if (/^(?:[IVXⅠ-Ⅻ]{1,4}|\d{1,2})\s?\.$/.test(t) && (_nullishCoalesce(_optionalChain([res, 'access',
|
|
1938
|
+
const t = _nullishCoalesce(_optionalChain([res, 'access', _57 => _57[k], 'optionalAccess', _58 => _58.text, 'access', _59 => _59.trim, 'call', _60 => _60()]), () => ( ""));
|
|
1939
|
+
if (/^(?:[IVXⅠ-Ⅻ]{1,4}|\d{1,2})\s?\.$/.test(t) && (_nullishCoalesce(_optionalChain([res, 'access', _61 => _61[k], 'optionalAccess', _62 => _62.confidence]), () => ( 0))) >= tuning.textScore) items.push({ text: t, ...this.itemBox(rgba, width, box, tuning), confidence: res[k].confidence });
|
|
1831
1940
|
});
|
|
1832
1941
|
}
|
|
1833
1942
|
}
|
|
@@ -1839,8 +1948,8 @@ var OcrEngine = class _OcrEngine {
|
|
|
1839
1948
|
/** 결과 좌표 — det 박스 그대로 또는 박스 안 잉크 외곽 (tightBoxes) */
|
|
1840
1949
|
itemBox(rgba, width, b, tuning) {
|
|
1841
1950
|
if (!tuning.tightBoxes) return b;
|
|
1842
|
-
const gray =
|
|
1843
|
-
const t =
|
|
1951
|
+
const gray = _chunkMYLKNYSYcjs.grayCrop.call(void 0, rgba, width, b);
|
|
1952
|
+
const t = _chunkMYLKNYSYcjs.inkBounds.call(void 0, gray, b.w, b.h, _chunkMYLKNYSYcjs.inkStats.call(void 0, gray));
|
|
1844
1953
|
return { x: b.x + t.x0, y: b.y + t.y0, w: t.x1 - t.x0, h: t.y1 - t.y0 };
|
|
1845
1954
|
}
|
|
1846
1955
|
// ─── det ─────────────────────────────────────────────
|
|
@@ -1911,7 +2020,7 @@ var OcrEngine = class _OcrEngine {
|
|
|
1911
2020
|
const out = await this.rec.run({ [this.rec.inputNames[0]]: tensor });
|
|
1912
2021
|
const logits = out[this.rec.outputNames[0]];
|
|
1913
2022
|
const [, T, C] = logits.dims;
|
|
1914
|
-
if (C !== this.dict.length + 2) throw new (0,
|
|
2023
|
+
if (C !== this.dict.length + 2) throw new (0, _chunk7GM5ZLTCcjs.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`);
|
|
1915
2024
|
const data = logits.data;
|
|
1916
2025
|
idx.forEach((ci, k) => {
|
|
1917
2026
|
const r = ctcDecode(data.subarray(k * T * C, (k + 1) * T * C), T, C, this.dict);
|
|
@@ -1921,9 +2030,9 @@ var OcrEngine = class _OcrEngine {
|
|
|
1921
2030
|
const chars = r ? [...r.text] : [];
|
|
1922
2031
|
if (r && job.rot === 0 && chars.length === r.steps.length && r.steps.some((t) => t > last) && !r.text.includes("(cid:")) {
|
|
1923
2032
|
const tallCh = (c) => !/[\s.,:;\u00b7\u2026'"\u2018-\u201d`\-_~]/.test(c);
|
|
1924
|
-
const g =
|
|
2033
|
+
const g = _chunkMYLKNYSYcjs.grayCrop.call(void 0, rgba, pageW, job.box);
|
|
1925
2034
|
const inside = chars.filter((c, i) => r.steps[i] <= last && tallCh(c)).length;
|
|
1926
|
-
let budget = inside <= 2 ?
|
|
2035
|
+
let budget = inside <= 2 ? _chunkMYLKNYSYcjs.tallInkCount.call(void 0, g, job.box.w, job.box.h, _chunkMYLKNYSYcjs.inkStats.call(void 0, g)) - inside : Infinity;
|
|
1927
2036
|
const keep = chars.map((c, i) => r.steps[i] <= last || !tallCh(c) || budget-- > 0);
|
|
1928
2037
|
if (!keep.every(Boolean)) kept = { ...r, text: chars.filter((_, i) => keep[i]).join(""), steps: r.steps.filter((_, i) => keep[i]) };
|
|
1929
2038
|
}
|
|
@@ -2034,13 +2143,13 @@ async function tryImport(name, loader) {
|
|
|
2034
2143
|
return await loader();
|
|
2035
2144
|
} catch (e) {
|
|
2036
2145
|
throw new Error(
|
|
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.${
|
|
2146
|
+
`\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.${_chunk7GM5ZLTCcjs.OPTIONAL_DEP_INSTALL_HINT} \uC6D0\uC778: ${e.message}`
|
|
2038
2147
|
);
|
|
2039
2148
|
}
|
|
2040
2149
|
}
|
|
2041
2150
|
async function verifiedBytes(s) {
|
|
2042
2151
|
const name = _path.basename.call(void 0, s.file.path);
|
|
2043
|
-
const fail = (why2) => new (0,
|
|
2152
|
+
const fail = (why2) => new (0, _chunk7GM5ZLTCcjs.KordocError)(`OCR \uBAA8\uB378 \uD30C\uC77C\uC744 \uC77D\uC9C0 \uBABB\uD588\uC2B5\uB2C8\uB2E4: ${name} (${why2})`);
|
|
2044
2153
|
const why = (e) => {
|
|
2045
2154
|
const code = e.code;
|
|
2046
2155
|
return code === "ENOENT" ? "\uD30C\uC77C\uC774 \uC5C6\uC74C" : code === "EACCES" || code === "EPERM" ? "\uAD8C\uD55C \uC5C6\uC74C" : "\uC77D\uAE30 \uC2E4\uD328";
|
|
@@ -2061,13 +2170,13 @@ async function verifiedBytes(s) {
|
|
|
2061
2170
|
}
|
|
2062
2171
|
const actual = _crypto.createHash.call(void 0, "sha256").update(bytes).digest("hex");
|
|
2063
2172
|
if (actual !== s.file.sha256) {
|
|
2064
|
-
throw new (0,
|
|
2173
|
+
throw new (0, _chunk7GM5ZLTCcjs.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)`);
|
|
2065
2174
|
}
|
|
2066
2175
|
return bytes;
|
|
2067
2176
|
}
|
|
2068
2177
|
var engines = /* @__PURE__ */ new Map();
|
|
2069
|
-
function getOcrEngine(models =
|
|
2070
|
-
const key =
|
|
2178
|
+
function getOcrEngine(models = _chunkMYLKNYSYcjs.DEFAULT_OCR_MODELS) {
|
|
2179
|
+
const key = _chunkMYLKNYSYcjs.ocrSelectionKey.call(void 0, models);
|
|
2071
2180
|
let p = engines.get(key);
|
|
2072
2181
|
if (!p) {
|
|
2073
2182
|
p = OcrEngine.create(models).catch((err) => {
|
|
@@ -2187,20 +2296,20 @@ var PAGE_TIMEOUT_MS = 12e4;
|
|
|
2187
2296
|
var AUTO_REC = { pageConf: 0.9, gain: 0.06 };
|
|
2188
2297
|
var DEFAULT_AUTO_REC = { pageConf: 0.85, gain: 0.1, lazy: true };
|
|
2189
2298
|
var DEFAULT_BUILTIN_OCR = Object.freeze({
|
|
2190
|
-
models:
|
|
2299
|
+
models: _chunkMYLKNYSYcjs.DEFAULT_OCR_MODELS,
|
|
2191
2300
|
tuning: DEFAULT_OCR_TUNING,
|
|
2192
|
-
handwriting:
|
|
2301
|
+
handwriting: _chunkMYLKNYSYcjs.handwritingFallbackModels.call(void 0, _chunkMYLKNYSYcjs.DEFAULT_OCR_MODELS),
|
|
2193
2302
|
autoRec: DEFAULT_AUTO_REC
|
|
2194
2303
|
});
|
|
2195
2304
|
var DEFAULT_BUILTIN_OCR_FETCH = Object.freeze({ ...DEFAULT_BUILTIN_OCR, autoRec: { ...DEFAULT_AUTO_REC, fetch: true } });
|
|
2196
2305
|
function builtinOcrConfig(o) {
|
|
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',
|
|
2306
|
+
if (!o || o.ocrDet === void 0 && o.ocrDetLongSide === void 0 && o.ocrRec === void 0 && o.ocrRecDict === void 0 && !o.ocrLines) return _optionalChain([o, 'optionalAccess', _63 => _63.ocr]) ? DEFAULT_BUILTIN_OCR_FETCH : DEFAULT_BUILTIN_OCR;
|
|
2198
2307
|
const bad = _chunkMMK32GPDcjs.validateOcrOptions.call(void 0, o);
|
|
2199
|
-
if (bad) throw new (0,
|
|
2200
|
-
const models =
|
|
2308
|
+
if (bad) throw new (0, _chunk7GM5ZLTCcjs.KordocError)(bad);
|
|
2309
|
+
const models = _chunkMYLKNYSYcjs.resolveOcrModels.call(void 0, o);
|
|
2201
2310
|
return {
|
|
2202
2311
|
models,
|
|
2203
|
-
...o.ocrRec === "auto" ? { handwriting:
|
|
2312
|
+
...o.ocrRec === "auto" ? { handwriting: _chunkMYLKNYSYcjs.handwritingFallbackModels.call(void 0, models), autoRec: AUTO_REC } : o.ocrRec === void 0 ? { handwriting: _chunkMYLKNYSYcjs.handwritingFallbackModels.call(void 0, models), autoRec: o.ocr ? { ...DEFAULT_AUTO_REC, fetch: true } : DEFAULT_AUTO_REC } : {},
|
|
2204
2313
|
tuning: o.ocrDetLongSide === void 0 ? DEFAULT_OCR_TUNING : { ...DEFAULT_OCR_TUNING, detLongSide: o.ocrDetLongSide },
|
|
2205
2314
|
lines: o.ocrLines === "all" ? "all" : o.ocrLines ? "kept" : void 0
|
|
2206
2315
|
};
|
|
@@ -2214,8 +2323,8 @@ async function recognizeOcrPage(engine, config, tuning, rgba, width, height, sta
|
|
|
2214
2323
|
const altStats = { droppedLowConf: 0, ...stats.dropped ? { dropped: [] } : {} };
|
|
2215
2324
|
let alt;
|
|
2216
2325
|
try {
|
|
2217
|
-
if (auto.lazy && !auto.fetch && !await
|
|
2218
|
-
if (auto.lazy) await
|
|
2326
|
+
if (auto.lazy && !auto.fetch && !await _chunkMYLKNYSYcjs.ocrModelsCached.call(void 0, config.handwriting)) return items;
|
|
2327
|
+
if (auto.lazy) await _chunkMYLKNYSYcjs.ensureOcrModelsFor.call(void 0, config.handwriting, reportModelDownload);
|
|
2219
2328
|
alt = await (await getOcrEngine(config.handwriting)).recognizePage(rgba, width, height, altStats, tuning, cellRules, rowRules);
|
|
2220
2329
|
} catch (e) {
|
|
2221
2330
|
if (!auto.lazy) throw e;
|
|
@@ -2254,8 +2363,8 @@ async function runPdfOcr(buffer, targets, mode, warnings, onProgress, detectTabl
|
|
|
2254
2363
|
"@hyzyla/pdfium",
|
|
2255
2364
|
() => Promise.resolve().then(() => _interopRequireWildcard(require("@hyzyla/pdfium")))
|
|
2256
2365
|
);
|
|
2257
|
-
if (mode === "builtin") await
|
|
2258
|
-
if (mode === "builtin" && config.handwriting && !_optionalChain([config, 'access',
|
|
2366
|
+
if (mode === "builtin") await _chunkMYLKNYSYcjs.ensureOcrModelsFor.call(void 0, config.models, reportModelDownload);
|
|
2367
|
+
if (mode === "builtin" && config.handwriting && !_optionalChain([config, 'access', _64 => _64.autoRec, 'optionalAccess', _65 => _65.lazy])) await _chunkMYLKNYSYcjs.ensureOcrModelsFor.call(void 0, config.handwriting, reportModelDownload);
|
|
2259
2368
|
const engine = mode === "builtin" ? await getOcrEngine(config.models) : null;
|
|
2260
2369
|
const pdfium = await pdfiumMod.PDFiumLibrary.init();
|
|
2261
2370
|
const doc = await pdfium.loadDocument(new Uint8Array(buffer));
|
|
@@ -2264,15 +2373,15 @@ async function runPdfOcr(buffer, targets, mode, warnings, onProgress, detectTabl
|
|
|
2264
2373
|
const count = doc.getPageCount();
|
|
2265
2374
|
for (const pageNo of [...targets].filter((p) => p >= 1 && p <= count).sort((a, b) => a - b)) {
|
|
2266
2375
|
const page = doc.getPage(pageNo - 1);
|
|
2267
|
-
_optionalChain([onProgress, 'optionalCall',
|
|
2376
|
+
_optionalChain([onProgress, 'optionalCall', _66 => _66(++done, targets.size)]);
|
|
2268
2377
|
try {
|
|
2269
2378
|
const { blocks, lines } = await withTimeout(
|
|
2270
|
-
ocrOnePage(page, pageNo, mode, engine, warnings, detectTables, _optionalChain([vectorOps, 'optionalAccess',
|
|
2379
|
+
ocrOnePage(page, pageNo, mode, engine, warnings, detectTables, _optionalChain([vectorOps, 'optionalAccess', _67 => _67.get, 'call', _68 => _68(pageNo)]), _optionalChain([imageRegions, 'optionalAccess', _69 => _69.get, 'call', _70 => _70(pageNo)]), config),
|
|
2271
2380
|
PAGE_TIMEOUT_MS,
|
|
2272
2381
|
`OCR \uD398\uC774\uC9C0 ${pageNo} \uD0C0\uC784\uC544\uC6C3 (${PAGE_TIMEOUT_MS / 1e3}\uCD08)`
|
|
2273
2382
|
);
|
|
2274
2383
|
result.set(pageNo, blocks);
|
|
2275
|
-
if (lines) _optionalChain([linesOut, 'optionalAccess',
|
|
2384
|
+
if (lines) _optionalChain([linesOut, 'optionalAccess', _71 => _71.set, 'call', _72 => _72(pageNo, lines)]);
|
|
2276
2385
|
} catch (e) {
|
|
2277
2386
|
warnings.push({
|
|
2278
2387
|
page: pageNo,
|
|
@@ -2356,7 +2465,7 @@ async function ocrOnePage(page, pageNo, mode, engine, warnings, detectTables, ve
|
|
|
2356
2465
|
const regionBlocks = regions.flatMap((r, k) => {
|
|
2357
2466
|
let own = items.filter((it) => inside(it, r));
|
|
2358
2467
|
const near = reads[k];
|
|
2359
|
-
if (_optionalChain([near, 'optionalAccess',
|
|
2468
|
+
if (_optionalChain([near, 'optionalAccess', _73 => _73.length]) && meanConfidence(near) > meanConfidence(own)) {
|
|
2360
2469
|
own = near;
|
|
2361
2470
|
reread.add(k);
|
|
2362
2471
|
}
|
|
@@ -2364,9 +2473,9 @@ async function ocrOnePage(page, pageNo, mode, engine, warnings, detectTables, ve
|
|
|
2364
2473
|
for (const it of own) used.add(it);
|
|
2365
2474
|
const blocks = ocrItemsToBlocks(own, pageNo, pdfW, pdfH, scale, ruling && rulingToPdfLines(ruling, scale, pdfH), detectTables, void 0, true);
|
|
2366
2475
|
const x1 = r.x1 * scale - 2, x2 = r.x2 * scale + 2, y1 = (pdfH - r.y2) * scale - 2, y2 = (pdfH - r.y1) * scale + 2;
|
|
2367
|
-
const columnRules = _nullishCoalesce(_optionalChain([ruling, 'optionalAccess',
|
|
2476
|
+
const columnRules = _nullishCoalesce(_optionalChain([ruling, 'optionalAccess', _74 => _74.verticals, 'access', _75 => _75.filter, 'call', _76 => _76((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', _77 => _77.length]), () => ( 0));
|
|
2368
2477
|
if (columnRules < 2) {
|
|
2369
|
-
for (const b of blocks) if (b.type === "table")
|
|
2478
|
+
for (const b of blocks) if (b.type === "table") _chunkMYLKNYSYcjs.UNRULED_REGION_TABLES.add(b);
|
|
2370
2479
|
}
|
|
2371
2480
|
return blocks;
|
|
2372
2481
|
});
|
|
@@ -2438,7 +2547,7 @@ async function closerReads(rgba, rw, rh, pdfH, hi, regions, engine, tuning = REG
|
|
|
2438
2547
|
const items = await engine.recognizePage(crop, cw, ch, void 0, tuning);
|
|
2439
2548
|
out.push(items.map((it) => {
|
|
2440
2549
|
const placed = { ...it, x: (it.x + x0) / 2, y: (it.y + y0) / 2, w: it.w / 2, h: it.h / 2 };
|
|
2441
|
-
|
|
2550
|
+
_chunkMYLKNYSYcjs.copyOcrTextGaps.call(void 0, it, placed, 0.5, x0 / 2);
|
|
2442
2551
|
return placed;
|
|
2443
2552
|
}));
|
|
2444
2553
|
}
|
|
@@ -2446,7 +2555,7 @@ async function closerReads(rgba, rw, rh, pdfH, hi, regions, engine, tuning = REG
|
|
|
2446
2555
|
}
|
|
2447
2556
|
var proseBox = (b) => {
|
|
2448
2557
|
const t = b.text.replace(/\s/g, "");
|
|
2449
|
-
return b.w >= b.h * 7 && (_nullishCoalesce(_optionalChain([t, 'access',
|
|
2558
|
+
return b.w >= b.h * 7 && (_nullishCoalesce(_optionalChain([t, 'access', _78 => _78.match, 'call', _79 => _79(/\d/g), 'optionalAccess', _80 => _80.length]), () => ( 0))) < t.length * 0.3;
|
|
2450
2559
|
};
|
|
2451
2560
|
function groupOcrLines(items, figureRegion = false) {
|
|
2452
2561
|
const order = items.map((_, i) => i).sort((a, b) => items[a].y + items[a].h / 2 - (items[b].y + items[b].h / 2));
|
|
@@ -2526,15 +2635,15 @@ function ocrItemsToBlocks(items, pageNumber, pdfW, pdfH, scale, extraLines, dete
|
|
|
2526
2635
|
isHidden: false,
|
|
2527
2636
|
...xs[i].space ? { hasSpaceBefore: true } : {}
|
|
2528
2637
|
};
|
|
2529
|
-
|
|
2638
|
+
_chunkMYLKNYSYcjs.copyOcrTextGaps.call(void 0, it, normalized, 1 / scale);
|
|
2530
2639
|
return normalized;
|
|
2531
2640
|
}).filter((it) => it.text);
|
|
2532
|
-
const blocks = unframeOcrLayoutTables(splitStackedOcrRows(
|
|
2641
|
+
const blocks = unframeOcrLayoutTables(splitOcrNameValueColumns(splitStackedOcrRows(_chunkMYLKNYSYcjs.extractPageBlocksWithLines.call(void 0, norm, pageNumber, opList, pdfW, pdfH, extraLines, detectTables))), pdfH);
|
|
2533
2642
|
if (!figureRegion) markOcrHeadings(blocks);
|
|
2534
2643
|
return blocks;
|
|
2535
2644
|
}
|
|
2536
2645
|
function markOcrHeadings(blocks) {
|
|
2537
|
-
const sized = blocks.filter((b) => b.type === "paragraph" && b.text && _optionalChain([b, 'access',
|
|
2646
|
+
const sized = blocks.filter((b) => b.type === "paragraph" && b.text && _optionalChain([b, 'access', _81 => _81.style, 'optionalAccess', _82 => _82.fontSize]));
|
|
2538
2647
|
const weights = sized.map((b) => [b.style.fontSize, b.text.length]);
|
|
2539
2648
|
const total = weights.reduce((n, [, w]) => n + w, 0);
|
|
2540
2649
|
if (total < 100) return;
|
|
@@ -2571,9 +2680,9 @@ function markOcrHeadings(blocks) {
|
|
|
2571
2680
|
const a = blocks[i - 1], b = blocks[i];
|
|
2572
2681
|
if (a.type !== "heading" || b.type !== "heading" || !a.bbox || !b.bbox) continue;
|
|
2573
2682
|
const marker = /^(?:제\s*\d+\s*[장절편부]|chapter\s*\d+|part\s*\d+)$/i.test(a.text.trim());
|
|
2574
|
-
const sa = _nullishCoalesce(_optionalChain([a, 'access',
|
|
2683
|
+
const sa = _nullishCoalesce(_optionalChain([a, 'access', _83 => _83.style, 'optionalAccess', _84 => _84.fontSize]), () => ( 0)), sb = _nullishCoalesce(_optionalChain([b, 'access', _85 => _85.style, 'optionalAccess', _86 => _86.fontSize]), () => ( 0));
|
|
2575
2684
|
if (!marker && (a.level !== b.level || Math.max(sa, sb) > Math.min(sa, sb) * 1.3)) continue;
|
|
2576
|
-
const gap = a.bbox.y - (b.bbox.y + b.bbox.height), size = Math.max(_nullishCoalesce(_optionalChain([a, 'access',
|
|
2685
|
+
const gap = a.bbox.y - (b.bbox.y + b.bbox.height), size = Math.max(_nullishCoalesce(_optionalChain([a, 'access', _87 => _87.style, 'optionalAccess', _88 => _88.fontSize]), () => ( 0)), _nullishCoalesce(_optionalChain([b, 'access', _89 => _89.style, 'optionalAccess', _90 => _90.fontSize]), () => ( 0)));
|
|
2577
2686
|
const across = Math.min(a.bbox.x + a.bbox.width, b.bbox.x + b.bbox.width) - Math.max(a.bbox.x, b.bbox.x);
|
|
2578
2687
|
if (gap < 0 || gap > size * (marker ? 3 : 1.2) || across <= 0) continue;
|
|
2579
2688
|
a.level = Math.min(_nullishCoalesce(a.level, () => ( 2)), _nullishCoalesce(b.level, () => ( 2)));
|
|
@@ -2588,7 +2697,7 @@ async function tryImport2(name, loader) {
|
|
|
2588
2697
|
return await loader();
|
|
2589
2698
|
} catch (e) {
|
|
2590
2699
|
throw new Error(
|
|
2591
|
-
`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.${
|
|
2700
|
+
`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.${_chunk7GM5ZLTCcjs.OPTIONAL_DEP_INSTALL_HINT} \uC6D0\uC778: ${e.message}`
|
|
2592
2701
|
);
|
|
2593
2702
|
}
|
|
2594
2703
|
}
|
|
@@ -2640,4 +2749,4 @@ function bgraToRgba(bgra) {
|
|
|
2640
2749
|
|
|
2641
2750
|
|
|
2642
2751
|
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;
|
|
2643
|
-
//# sourceMappingURL=chunk-
|
|
2752
|
+
//# sourceMappingURL=chunk-XEMHC53A.cjs.map
|