kordoc 4.24.37 → 4.24.39
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/{-HX3RWDQF.js → -7VE547IT.js} +60 -60
- package/dist/{chunk-4MWGWS3B.js → chunk-2XXTL4S4.js} +2 -2
- package/dist/{chunk-J26TNCL7.js → chunk-346W5O2J.js} +2 -2
- package/dist/{chunk-LM7LYH54.js → chunk-3MHRL3OO.js} +2 -2
- package/dist/{chunk-TQBNSAAS.js → chunk-4FWLCWNU.js} +2 -2
- package/dist/{chunk-6QK6ZQTF.js → chunk-7AYP2XO6.js} +3 -3
- package/dist/{chunk-YNIZLSM4.js → chunk-7BQWFZJO.js} +8 -8
- package/dist/{chunk-OTB6UOIB.js → chunk-7ZRUR4TZ.js} +2 -2
- package/dist/{chunk-IWCWO3GP.js → chunk-BWBR5GWQ.js} +2 -2
- package/dist/{chunk-P3SZJJRK.js → chunk-COH7WXBK.js} +7 -7
- package/dist/{chunk-524MGRNW.js → chunk-CS76UPUC.js} +125 -21
- package/dist/chunk-CS76UPUC.js.map +1 -0
- package/dist/{chunk-LWSMZJLR.js → chunk-F2JYJ2SP.js} +2 -2
- package/dist/{chunk-MTSWWXSB.js → chunk-FRMJTW3C.js} +2 -2
- package/dist/{chunk-JRVZBYQ2.js → chunk-FZMZUX7B.js} +130 -21
- package/dist/chunk-FZMZUX7B.js.map +1 -0
- package/dist/{chunk-J42O5KBX.js → chunk-GXED6LJX.js} +2 -2
- package/dist/{chunk-E527FG6I.cjs → chunk-IM5SIGUN.cjs} +3 -3
- package/dist/{chunk-E527FG6I.cjs.map → chunk-IM5SIGUN.cjs.map} +1 -1
- package/dist/{chunk-RR2FKPFN.js → chunk-IZWZ3RQC.js} +2 -2
- package/dist/{chunk-RR2FKPFN.js.map → chunk-IZWZ3RQC.js.map} +1 -1
- package/dist/{chunk-BT5RPLV4.js → chunk-L23XOAKF.js} +19 -19
- package/dist/{chunk-WZUTLJP2.cjs → chunk-LE3733C2.cjs} +212 -108
- package/dist/chunk-LE3733C2.cjs.map +1 -0
- package/dist/{chunk-2LDFUVVF.js → chunk-LOJYJISM.js} +16 -7
- package/dist/chunk-LOJYJISM.js.map +1 -0
- package/dist/{chunk-KGX4TLBX.cjs → chunk-LU7X6LLW.cjs} +3 -3
- package/dist/{chunk-KGX4TLBX.cjs.map → chunk-LU7X6LLW.cjs.map} +1 -1
- package/dist/{chunk-DRDW5ULI.js → chunk-M2ZRTYQ5.js} +14 -14
- package/dist/{chunk-QWYIYVIZ.cjs → chunk-MANE7HAZ.cjs} +2 -2
- package/dist/{chunk-QWYIYVIZ.cjs.map → chunk-MANE7HAZ.cjs.map} +1 -1
- package/dist/{chunk-XCMDIXWE.js → chunk-NL5OTD2E.js} +32 -32
- package/dist/{chunk-ONCXLQV4.js → chunk-NQJL3664.js} +3 -3
- package/dist/{chunk-KFJKRST5.js → chunk-PFHMNNW7.js} +126 -17
- package/dist/chunk-PFHMNNW7.js.map +1 -0
- package/dist/{chunk-OHLJEWS6.js → chunk-PHVAJBHM.js} +2 -2
- package/dist/{chunk-7GN7O3K2.js → chunk-PQIIYKNL.js} +51 -51
- package/dist/{chunk-T7K3CLXM.js → chunk-QDPYTJ4Y.js} +2 -2
- package/dist/{chunk-7MGZWDO4.js → chunk-QDQPAC4L.js} +2 -2
- package/dist/{chunk-7MGZWDO4.js.map → chunk-QDQPAC4L.js.map} +1 -1
- package/dist/{chunk-LG4SU2D4.cjs → chunk-RJNHXCMP.cjs} +69 -60
- package/dist/chunk-RJNHXCMP.cjs.map +1 -0
- package/dist/{chunk-33BKUIIC.js → chunk-RPAEXGWZ.js} +2 -2
- package/dist/{chunk-VRCXXZHT.js → chunk-SFLHCRO6.js} +2 -2
- package/dist/{chunk-GCFG67SF.js → chunk-U5OV6D66.js} +50 -50
- package/dist/{chunk-RBCDHT55.cjs → chunk-UKTRLJII.cjs} +98 -98
- package/dist/{chunk-RBCDHT55.cjs.map → chunk-UKTRLJII.cjs.map} +1 -1
- package/dist/{chunk-BYOAA442.js → chunk-V2RIY72D.js} +2 -2
- package/dist/{chunk-EJKCEP3Q.cjs → chunk-V3IMDOZE.cjs} +6 -6
- package/dist/{chunk-EJKCEP3Q.cjs.map → chunk-V3IMDOZE.cjs.map} +1 -1
- package/dist/{chunk-4OWD6WRS.js → chunk-WPIG3KUV.js} +121 -17
- package/dist/chunk-WPIG3KUV.js.map +1 -0
- package/dist/{chunk-6XOJ6CEK.js → chunk-WVER4OWF.js} +3 -3
- package/dist/{chunk-IOABX3GR.cjs → chunk-XYVTCXAG.cjs} +265 -156
- package/dist/chunk-XYVTCXAG.cjs.map +1 -0
- package/dist/{chunk-6SVVVZLV.js → chunk-Y5O4DS56.js} +2 -2
- package/dist/{chunk-UMQADPM5.js → chunk-YXKU6UJD.js} +2 -2
- package/dist/{chunk-B2VRTOQZ.js → chunk-ZDMLZRS4.js} +18 -9
- package/dist/chunk-ZDMLZRS4.js.map +1 -0
- package/dist/{chunk-64MVXWS5.js → chunk-ZVAX6E63.js} +2 -2
- package/dist/chunks-WTYZ4KG2.js +11 -0
- package/dist/cli.js +61 -60
- package/dist/cli.js.map +1 -1
- package/dist/{formula-DLZUYM6F.js → formula-MMLDES2Z.js} +20 -17
- package/dist/{formula-DLZUYM6F.js.map → formula-MMLDES2Z.js.map} +1 -1
- package/dist/{formula-2MQWKUKR.js → formula-PFSZZNPP.js} +19 -16
- package/dist/{formula-2MQWKUKR.js.map → formula-PFSZZNPP.js.map} +1 -1
- package/dist/{formula-T2YY77JT.cjs → formula-UI2UR74M.cjs} +25 -22
- package/dist/formula-UI2UR74M.cjs.map +1 -0
- package/dist/generator-C3SCP3ZG.js +10 -0
- package/dist/generator-CHBOCLYX.cjs +11 -0
- package/dist/{generator-YBWCA6B5.cjs.map → generator-CHBOCLYX.cjs.map} +1 -1
- package/dist/generator-RTSNDZJB.js +17 -0
- package/dist/hancom-3V3USCW5.js +84 -0
- package/dist/hancom-3V3USCW5.js.map +1 -0
- package/dist/hancom-GV5TTF5H.cjs +85 -0
- package/dist/hancom-GV5TTF5H.cjs.map +1 -0
- package/dist/hancom-XO52GNC3.js +85 -0
- package/dist/hancom-XO52GNC3.js.map +1 -0
- package/dist/image-ocr-2WKCFABH.cjs +211 -0
- package/dist/image-ocr-2WKCFABH.cjs.map +1 -0
- package/dist/{image-ocr-3NF3QJM7.js → image-ocr-R2ASFKHX.js} +99 -15
- package/dist/image-ocr-R2ASFKHX.js.map +1 -0
- package/dist/{image-ocr-XRKFK7AA.js → image-ocr-SU4RPHBF.js} +94 -10
- package/dist/image-ocr-SU4RPHBF.js.map +1 -0
- package/dist/index.cjs +1110 -1110
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -1
- package/dist/index.d.ts +7 -1
- package/dist/index.js +70 -70
- package/dist/mcp.js +57 -56
- package/dist/mcp.js.map +1 -1
- package/dist/memo-U4RZJRU2.js +17 -0
- package/dist/{model-bundle-MO5I26AO.js → model-bundle-JMSH2F4A.js} +5 -5
- package/dist/{models-IIP4GZ57.js → models-D5SATVOZ.js} +5 -5
- package/dist/{parse-worker-v2-GWOL3TTO.js → parse-worker-v2-WIIZQFRX.js} +28 -28
- package/dist/{parser-UCLUVQPA.js → parser-KCY43TBS.js} +16 -16
- package/dist/{parser-R6UJQ6CV.cjs → parser-MFBTEGJA.cjs} +162 -162
- package/dist/{parser-R6UJQ6CV.cjs.map → parser-MFBTEGJA.cjs.map} +1 -1
- package/dist/{parser-DJQFM6VE.js → parser-SBJKV5GS.js} +16 -16
- package/dist/{pdf-ocr-EWXGN4JB.js → pdf-ocr-I6GNQEFS.js} +8 -6
- package/dist/pdf-ocr-L2O4SQUK.cjs +40 -0
- package/dist/pdf-ocr-L2O4SQUK.cjs.map +1 -0
- package/dist/{pdf-ocr-7PSNKQOI.js → pdf-ocr-UU5PSZ7Z.js} +12 -10
- package/dist/{profile-io-NUU3VKNW.js → profile-io-HZK4ZZ2O.js} +3 -3
- package/dist/{rasterize-RARCMBJ3.js → rasterize-VNP4ULXM.js} +3 -3
- package/dist/{redact-doc-JKGDXGNJ.js → redact-doc-SPHSBCPN.js} +37 -37
- package/dist/{render-SGLKO3PG.js → render-CKTTIDU2.js} +14 -14
- package/dist/{rewrite-fallback-7YZXSR5K.js → rewrite-fallback-H2KMJV6G.js} +21 -21
- package/dist/seal-MSY5G3UR.js +16 -0
- package/dist/{setup-5IYW4FZ7.js → setup-GJVOXJN7.js} +3 -3
- package/dist/{to-hwpx-QMANIAWY.js → to-hwpx-5UIBNW3D.js} +9 -9
- package/dist/to-hwpx-6BQNMA6P.cjs +16 -0
- package/dist/{to-hwpx-DEBHREDM.cjs.map → to-hwpx-6BQNMA6P.cjs.map} +1 -1
- package/dist/{to-hwpx-4PM6XV2L.js → to-hwpx-JJHDCYER.js} +4 -4
- package/dist/visual-Q6PIMKSA.js +37 -0
- package/dist/{watch-YZS76EOS.js → watch-YZZES36Q.js} +27 -27
- package/package.json +1 -1
- package/dist/chunk-2LDFUVVF.js.map +0 -1
- package/dist/chunk-4OWD6WRS.js.map +0 -1
- package/dist/chunk-524MGRNW.js.map +0 -1
- package/dist/chunk-B2VRTOQZ.js.map +0 -1
- package/dist/chunk-IOABX3GR.cjs.map +0 -1
- package/dist/chunk-JRVZBYQ2.js.map +0 -1
- package/dist/chunk-KFJKRST5.js.map +0 -1
- package/dist/chunk-LG4SU2D4.cjs.map +0 -1
- package/dist/chunk-WZUTLJP2.cjs.map +0 -1
- package/dist/chunks-NRA4GFK2.js +0 -11
- package/dist/formula-T2YY77JT.cjs.map +0 -1
- package/dist/generator-2WFWLJFG.js +0 -10
- package/dist/generator-5NWKWLOO.js +0 -17
- package/dist/generator-YBWCA6B5.cjs +0 -11
- package/dist/image-ocr-3NF3QJM7.js.map +0 -1
- package/dist/image-ocr-N7UKGSRY.cjs +0 -127
- package/dist/image-ocr-N7UKGSRY.cjs.map +0 -1
- package/dist/image-ocr-XRKFK7AA.js.map +0 -1
- package/dist/memo-XJ4NBV4J.js +0 -17
- package/dist/pdf-ocr-HECUBUMU.cjs +0 -38
- package/dist/pdf-ocr-HECUBUMU.cjs.map +0 -1
- package/dist/seal-LSS7WY6Z.js +0 -16
- package/dist/to-hwpx-DEBHREDM.cjs +0 -16
- package/dist/visual-QXYBJJ5D.js +0 -37
- /package/dist/{-HX3RWDQF.js.map → -7VE547IT.js.map} +0 -0
- /package/dist/{chunk-4MWGWS3B.js.map → chunk-2XXTL4S4.js.map} +0 -0
- /package/dist/{chunk-J26TNCL7.js.map → chunk-346W5O2J.js.map} +0 -0
- /package/dist/{chunk-LM7LYH54.js.map → chunk-3MHRL3OO.js.map} +0 -0
- /package/dist/{chunk-TQBNSAAS.js.map → chunk-4FWLCWNU.js.map} +0 -0
- /package/dist/{chunk-6QK6ZQTF.js.map → chunk-7AYP2XO6.js.map} +0 -0
- /package/dist/{chunk-YNIZLSM4.js.map → chunk-7BQWFZJO.js.map} +0 -0
- /package/dist/{chunk-OTB6UOIB.js.map → chunk-7ZRUR4TZ.js.map} +0 -0
- /package/dist/{chunk-IWCWO3GP.js.map → chunk-BWBR5GWQ.js.map} +0 -0
- /package/dist/{chunk-P3SZJJRK.js.map → chunk-COH7WXBK.js.map} +0 -0
- /package/dist/{chunk-LWSMZJLR.js.map → chunk-F2JYJ2SP.js.map} +0 -0
- /package/dist/{chunk-MTSWWXSB.js.map → chunk-FRMJTW3C.js.map} +0 -0
- /package/dist/{chunk-J42O5KBX.js.map → chunk-GXED6LJX.js.map} +0 -0
- /package/dist/{chunk-BT5RPLV4.js.map → chunk-L23XOAKF.js.map} +0 -0
- /package/dist/{chunk-DRDW5ULI.js.map → chunk-M2ZRTYQ5.js.map} +0 -0
- /package/dist/{chunk-XCMDIXWE.js.map → chunk-NL5OTD2E.js.map} +0 -0
- /package/dist/{chunk-ONCXLQV4.js.map → chunk-NQJL3664.js.map} +0 -0
- /package/dist/{chunk-OHLJEWS6.js.map → chunk-PHVAJBHM.js.map} +0 -0
- /package/dist/{chunk-7GN7O3K2.js.map → chunk-PQIIYKNL.js.map} +0 -0
- /package/dist/{chunk-T7K3CLXM.js.map → chunk-QDPYTJ4Y.js.map} +0 -0
- /package/dist/{chunk-33BKUIIC.js.map → chunk-RPAEXGWZ.js.map} +0 -0
- /package/dist/{chunk-VRCXXZHT.js.map → chunk-SFLHCRO6.js.map} +0 -0
- /package/dist/{chunk-GCFG67SF.js.map → chunk-U5OV6D66.js.map} +0 -0
- /package/dist/{chunk-BYOAA442.js.map → chunk-V2RIY72D.js.map} +0 -0
- /package/dist/{chunk-6XOJ6CEK.js.map → chunk-WVER4OWF.js.map} +0 -0
- /package/dist/{chunk-6SVVVZLV.js.map → chunk-Y5O4DS56.js.map} +0 -0
- /package/dist/{chunk-UMQADPM5.js.map → chunk-YXKU6UJD.js.map} +0 -0
- /package/dist/{chunk-64MVXWS5.js.map → chunk-ZVAX6E63.js.map} +0 -0
- /package/dist/{chunks-NRA4GFK2.js.map → chunks-WTYZ4KG2.js.map} +0 -0
- /package/dist/{generator-2WFWLJFG.js.map → generator-C3SCP3ZG.js.map} +0 -0
- /package/dist/{generator-5NWKWLOO.js.map → generator-RTSNDZJB.js.map} +0 -0
- /package/dist/{memo-XJ4NBV4J.js.map → memo-U4RZJRU2.js.map} +0 -0
- /package/dist/{model-bundle-MO5I26AO.js.map → model-bundle-JMSH2F4A.js.map} +0 -0
- /package/dist/{models-IIP4GZ57.js.map → models-D5SATVOZ.js.map} +0 -0
- /package/dist/{parse-worker-v2-GWOL3TTO.js.map → parse-worker-v2-WIIZQFRX.js.map} +0 -0
- /package/dist/{parser-UCLUVQPA.js.map → parser-KCY43TBS.js.map} +0 -0
- /package/dist/{parser-DJQFM6VE.js.map → parser-SBJKV5GS.js.map} +0 -0
- /package/dist/{pdf-ocr-7PSNKQOI.js.map → pdf-ocr-I6GNQEFS.js.map} +0 -0
- /package/dist/{pdf-ocr-EWXGN4JB.js.map → pdf-ocr-UU5PSZ7Z.js.map} +0 -0
- /package/dist/{profile-io-NUU3VKNW.js.map → profile-io-HZK4ZZ2O.js.map} +0 -0
- /package/dist/{rasterize-RARCMBJ3.js.map → rasterize-VNP4ULXM.js.map} +0 -0
- /package/dist/{redact-doc-JKGDXGNJ.js.map → redact-doc-SPHSBCPN.js.map} +0 -0
- /package/dist/{render-SGLKO3PG.js.map → render-CKTTIDU2.js.map} +0 -0
- /package/dist/{rewrite-fallback-7YZXSR5K.js.map → rewrite-fallback-H2KMJV6G.js.map} +0 -0
- /package/dist/{seal-LSS7WY6Z.js.map → seal-MSY5G3UR.js.map} +0 -0
- /package/dist/{setup-5IYW4FZ7.js.map → setup-GJVOXJN7.js.map} +0 -0
- /package/dist/{to-hwpx-4PM6XV2L.js.map → to-hwpx-5UIBNW3D.js.map} +0 -0
- /package/dist/{to-hwpx-QMANIAWY.js.map → to-hwpx-JJHDCYER.js.map} +0 -0
- /package/dist/{visual-QXYBJJ5D.js.map → visual-Q6PIMKSA.js.map} +0 -0
- /package/dist/{watch-YZS76EOS.js.map → watch-YZZES36Q.js.map} +0 -0
|
@@ -34,7 +34,7 @@ import {
|
|
|
34
34
|
splitRowBands,
|
|
35
35
|
starRun,
|
|
36
36
|
tallInkCount
|
|
37
|
-
} from "./chunk-
|
|
37
|
+
} from "./chunk-FZMZUX7B.js";
|
|
38
38
|
import {
|
|
39
39
|
validateOcrOptions
|
|
40
40
|
} from "./chunk-IFWGHRCQ.js";
|
|
@@ -44,7 +44,7 @@ import {
|
|
|
44
44
|
import {
|
|
45
45
|
KordocError,
|
|
46
46
|
OPTIONAL_DEP_INSTALL_HINT
|
|
47
|
-
} from "./chunk-
|
|
47
|
+
} from "./chunk-ZVAX6E63.js";
|
|
48
48
|
|
|
49
49
|
// src/ocr/ocr-stacked-rows.ts
|
|
50
50
|
var NUMERIC = /^[-+−△▲▽▼]?[\d.,]+[%p]?$|^[-–—·∼~]$|^\([-+−△▲▽▼]?[\d.,]+\)$/;
|
|
@@ -1058,7 +1058,8 @@ var DEFAULT_OCR_TUNING = Object.freeze({
|
|
|
1058
1058
|
minInkContrast: 35,
|
|
1059
1059
|
postprocess: true,
|
|
1060
1060
|
tightBoxes: true,
|
|
1061
|
-
splitLeaders: true
|
|
1061
|
+
splitLeaders: true,
|
|
1062
|
+
orientPage: true
|
|
1062
1063
|
});
|
|
1063
1064
|
var DET_MIN_SIZE = 3;
|
|
1064
1065
|
var DET_MAX_BOXES = 3e3;
|
|
@@ -1066,6 +1067,11 @@ var REC_MIN_WIDTH = 320;
|
|
|
1066
1067
|
var REC_BATCH_MAX_PIXELS = 48 * 16e3;
|
|
1067
1068
|
var TALL_RATIO = 1.5;
|
|
1068
1069
|
var ROTATE_RATIO = 3;
|
|
1070
|
+
var ORIENT_MIN_BOXES = 20;
|
|
1071
|
+
var ORIENT_TALL_SHARE = 0.6;
|
|
1072
|
+
var ORIENT_SAMPLE = 12;
|
|
1073
|
+
var ORIENT_MIN_CONF = 0.7;
|
|
1074
|
+
var ORIENT_GAIN = 0.1;
|
|
1069
1075
|
var KEEP_MARGIN = 0.06;
|
|
1070
1076
|
var RETRY_SCORE = 0.9;
|
|
1071
1077
|
var LEADER_MIN_DOTS = 4;
|
|
@@ -1522,6 +1528,21 @@ var OcrEngine = class _OcrEngine {
|
|
|
1522
1528
|
async recognizePage(rgba, width, height, stats, tuning = DEFAULT_OCR_TUNING, cellRules = [], rowRules = []) {
|
|
1523
1529
|
if (width < DET_MIN_SIZE || height < DET_MIN_SIZE) return [];
|
|
1524
1530
|
const detected = await this.detect(rgba, width, height, tuning, stats);
|
|
1531
|
+
if (tuning.orientPage && stats && detected.length >= ORIENT_MIN_BOXES) {
|
|
1532
|
+
const tall = detected.filter((b) => b.h >= b.w * TALL_RATIO);
|
|
1533
|
+
if (tall.length >= detected.length * ORIENT_TALL_SHARE) {
|
|
1534
|
+
const sample = [...tall].sort((a, b) => b.h - a.h).slice(0, ORIENT_SAMPLE);
|
|
1535
|
+
const rots = [0, 90, 270];
|
|
1536
|
+
const probe = await this.recognizeJobs(rgba, width, sample.flatMap((box, group2) => rots.map((rot) => ({ box, rot, group: group2 }))), tuning.recBatch);
|
|
1537
|
+
const mean = (k) => sample.reduce((sum, _, i) => sum + (probe[i * rots.length + k]?.confidence ?? 0), 0) / sample.length;
|
|
1538
|
+
const [m0, m90, m270] = rots.map((_, k) => mean(k));
|
|
1539
|
+
const best2 = Math.max(m90, m270);
|
|
1540
|
+
if (best2 >= ORIENT_MIN_CONF && best2 >= m0 + ORIENT_GAIN) {
|
|
1541
|
+
stats.pageRotation = m90 >= m270 ? 90 : 270;
|
|
1542
|
+
return [];
|
|
1543
|
+
}
|
|
1544
|
+
}
|
|
1545
|
+
}
|
|
1525
1546
|
const rows = rowRules.length ? detected.flatMap((b) => splitBoxAtRowRules(b, rowRules)) : detected;
|
|
1526
1547
|
const boxes = cellRules.length ? rows.flatMap((b) => splitBoxAtCellRules(b, cellRules)) : rows;
|
|
1527
1548
|
const footer = tuning.postprocess ? footerInkBox(rgba, width, height, boxes) : null;
|
|
@@ -2015,6 +2036,20 @@ function deskewPage(rgba, width, height) {
|
|
|
2015
2036
|
if (Math.abs(est.angle) < MIN_APPLY_DEG || est.gain < MIN_GAIN) return { rgba, angle: 0 };
|
|
2016
2037
|
return { rgba: rotateRgba(rgba, width, height, est.angle), angle: est.angle };
|
|
2017
2038
|
}
|
|
2039
|
+
function rotateQuarter(rgba, width, height, rot) {
|
|
2040
|
+
const out = new Uint8Array(rgba.length);
|
|
2041
|
+
for (let v = 0; v < width; v++) {
|
|
2042
|
+
for (let u = 0; u < height; u++) {
|
|
2043
|
+
const px = rot === 90 ? width - 1 - v : v, py = rot === 90 ? u : height - 1 - u;
|
|
2044
|
+
const o = (v * height + u) * 4, i = (py * width + px) * 4;
|
|
2045
|
+
out[o] = rgba[i];
|
|
2046
|
+
out[o + 1] = rgba[i + 1];
|
|
2047
|
+
out[o + 2] = rgba[i + 2];
|
|
2048
|
+
out[o + 3] = rgba[i + 3];
|
|
2049
|
+
}
|
|
2050
|
+
}
|
|
2051
|
+
return { rgba: out, width: height, height: width };
|
|
2052
|
+
}
|
|
2018
2053
|
function rotateRgba(rgba, width, height, deg) {
|
|
2019
2054
|
const out = new Uint8Array(rgba.length);
|
|
2020
2055
|
const t = deg * Math.PI / 180;
|
|
@@ -2068,7 +2103,7 @@ var AUTO_REC_PAGE_CONF = 0.9;
|
|
|
2068
2103
|
var AUTO_REC_GAIN = 0.06;
|
|
2069
2104
|
async function recognizeOcrPage(engine, config, tuning, rgba, width, height, stats, cellRules, rowRules) {
|
|
2070
2105
|
const items = await engine.recognizePage(rgba, width, height, stats, tuning, cellRules, rowRules);
|
|
2071
|
-
if (!config.handwriting) return items;
|
|
2106
|
+
if (!config.handwriting || stats.pageRotation) return items;
|
|
2072
2107
|
const base = meanConfidence(items);
|
|
2073
2108
|
if (base >= AUTO_REC_PAGE_CONF) return items;
|
|
2074
2109
|
const altStats = { droppedLowConf: 0, ...stats.dropped ? { dropped: [] } : {} };
|
|
@@ -2140,7 +2175,7 @@ async function runPdfOcr(buffer, targets, mode, warnings, onProgress, detectTabl
|
|
|
2140
2175
|
return result;
|
|
2141
2176
|
}
|
|
2142
2177
|
async function ocrOnePage(page, pageNo, mode, engine, warnings, detectTables, vectorOps, regions, config = DEFAULT_BUILTIN_OCR) {
|
|
2143
|
-
|
|
2178
|
+
let { originalWidth: pdfW, originalHeight: pdfH } = page.getOriginalSize();
|
|
2144
2179
|
const renderScale = Math.min(OCR_RENDER_SCALE, Math.sqrt(MAX_OCR_PIXELS / Math.max(1, pdfW * pdfH)));
|
|
2145
2180
|
if (renderScale < OCR_RENDER_SCALE) {
|
|
2146
2181
|
warnings.push({ page: pageNo, code: "PARTIAL_PARSE", message: `OCR \uB798\uC2A4\uD130 \uD53D\uC140 \uC0C1\uD55C\uC73C\uB85C \uB80C\uB354 \uD574\uC0C1\uB3C4\uB97C \uCD95\uC18C\uD588\uC2B5\uB2C8\uB2E4 (\uC791\uC740 \uAE00\uC790 \uC778\uC2DD \uACB0\uC190 \uAC00\uB2A5)` });
|
|
@@ -2151,13 +2186,13 @@ async function ocrOnePage(page, pageNo, mode, engine, warnings, detectTables, ve
|
|
|
2151
2186
|
render: async ({ data }) => data
|
|
2152
2187
|
});
|
|
2153
2188
|
const hiRgba = closer ? bgraToRgba(rendered.data) : null;
|
|
2154
|
-
|
|
2189
|
+
let { rgba, width: rw, height: rh } = hiRgba ? halve(hiRgba, rendered.width, rendered.height) : { rgba: bgraToRgba(rendered.data), width: rendered.width, height: rendered.height };
|
|
2155
2190
|
if (mode === "builtin") {
|
|
2156
|
-
|
|
2191
|
+
let { rgba: upright, angle } = vectorOps || regions ? { rgba, angle: 0 } : deskewPage(rgba, rw, rh);
|
|
2157
2192
|
const stats = { droppedLowConf: 0, ...config.lines === "all" ? { dropped: [] } : {} };
|
|
2158
|
-
|
|
2159
|
-
const tuning = regions ? regionTuning(config.tuning) : config.tuning;
|
|
2160
|
-
|
|
2193
|
+
let ruling = vectorOps ? void 0 : detectRulingLines(upright, rw, rh, rh / pdfH);
|
|
2194
|
+
const tuning = regions ? regionTuning(config.tuning) : vectorOps ? { ...config.tuning, orientPage: false } : config.tuning;
|
|
2195
|
+
let items = await recognizeOcrPage(
|
|
2161
2196
|
engine,
|
|
2162
2197
|
config,
|
|
2163
2198
|
tuning,
|
|
@@ -2168,6 +2203,23 @@ async function ocrOnePage(page, pageNo, mode, engine, warnings, detectTables, ve
|
|
|
2168
2203
|
ruling ? [...ruling.cellDividers ?? [], ...cellEdgeVerticals(ruling)] : void 0,
|
|
2169
2204
|
ruling ? cellEdgeHorizontals(ruling) : void 0
|
|
2170
2205
|
);
|
|
2206
|
+
if (stats.pageRotation) {
|
|
2207
|
+
({ rgba: upright, width: rw, height: rh } = rotateQuarter(upright, rw, rh, stats.pageRotation));
|
|
2208
|
+
[pdfW, pdfH] = [pdfH, pdfW];
|
|
2209
|
+
delete stats.pageRotation;
|
|
2210
|
+
ruling = detectRulingLines(upright, rw, rh, rh / pdfH);
|
|
2211
|
+
items = await recognizeOcrPage(
|
|
2212
|
+
engine,
|
|
2213
|
+
config,
|
|
2214
|
+
{ ...tuning, orientPage: false },
|
|
2215
|
+
upright,
|
|
2216
|
+
rw,
|
|
2217
|
+
rh,
|
|
2218
|
+
stats,
|
|
2219
|
+
[...ruling.cellDividers ?? [], ...cellEdgeVerticals(ruling)],
|
|
2220
|
+
cellEdgeHorizontals(ruling)
|
|
2221
|
+
);
|
|
2222
|
+
}
|
|
2171
2223
|
if (stats.droppedLowConf > 0) {
|
|
2172
2224
|
warnings.push({
|
|
2173
2225
|
page: pageNo,
|
|
@@ -2235,8 +2287,8 @@ function halve(src, w, h) {
|
|
|
2235
2287
|
}
|
|
2236
2288
|
return { rgba: out, width: W, height: H };
|
|
2237
2289
|
}
|
|
2238
|
-
var REGION_TUNING = Object.freeze({ ...DEFAULT_OCR_TUNING, trimEdges: false });
|
|
2239
|
-
var regionTuning = (t) => t === DEFAULT_OCR_TUNING ? REGION_TUNING : { ...t, trimEdges: false };
|
|
2290
|
+
var REGION_TUNING = Object.freeze({ ...DEFAULT_OCR_TUNING, trimEdges: false, orientPage: false });
|
|
2291
|
+
var regionTuning = (t) => t === DEFAULT_OCR_TUNING ? REGION_TUNING : { ...t, trimEdges: false, orientPage: false };
|
|
2240
2292
|
function meanConfidence(items) {
|
|
2241
2293
|
let n = 0, sum = 0;
|
|
2242
2294
|
for (const it of items) {
|
|
@@ -2311,6 +2363,7 @@ function groupOcrLines(items, figureRegion = false) {
|
|
|
2311
2363
|
function ocrItemsToBlocks(items, pageNumber, pdfW, pdfH, scale, extraLines, detectTables = true, opList = { fnArray: [], argsArray: [] }, figureRegion = false) {
|
|
2312
2364
|
const bottoms = items.map((it) => it.y + it.h);
|
|
2313
2365
|
const xs = items.map((it) => ({ x: it.x, r: it.x + it.w, space: false }));
|
|
2366
|
+
const texts = items.map((it) => it.text);
|
|
2314
2367
|
for (const line of groupOcrLines(items, figureRegion)) {
|
|
2315
2368
|
if (line.length < 2) continue;
|
|
2316
2369
|
const sorted = line.map((j) => items[j].y + items[j].h).sort((a, b) => a - b);
|
|
@@ -2319,6 +2372,13 @@ function ocrItemsToBlocks(items, pageNumber, pdfW, pdfH, scale, extraLines, dete
|
|
|
2319
2372
|
for (let k = 1; k < byX.length; k++) {
|
|
2320
2373
|
const L = xs[byX[k - 1]], R = xs[byX[k]];
|
|
2321
2374
|
if (R.x >= L.r) continue;
|
|
2375
|
+
const lt = [...texts[byX[k - 1]]], rt = [...texts[byX[k]]], per = items[byX[k]].w / Math.max(1, rt.length);
|
|
2376
|
+
for (let n = Math.min(3, rt.length, lt.length); n >= 1; n--) {
|
|
2377
|
+
if (lt.slice(-n).join("") === rt.slice(0, n).join("") && /[가-힣]/.test(rt[0]) && L.r - R.x >= per * n * 0.5) {
|
|
2378
|
+
texts[byX[k]] = rt.slice(n).join("");
|
|
2379
|
+
break;
|
|
2380
|
+
}
|
|
2381
|
+
}
|
|
2322
2382
|
const mid = (R.x + L.r) / 2, half = Math.min(items[byX[k - 1]].h, items[byX[k]].h) * 0.15;
|
|
2323
2383
|
L.r = Math.max(L.x + 1, mid - half);
|
|
2324
2384
|
R.x = Math.min(R.r - 1, mid + half);
|
|
@@ -2328,7 +2388,7 @@ function ocrItemsToBlocks(items, pageNumber, pdfW, pdfH, scale, extraLines, dete
|
|
|
2328
2388
|
const norm = items.map((it, i) => {
|
|
2329
2389
|
const h = (figureRegion ? Math.max(1, bottoms[i] - it.y) : it.h) / scale;
|
|
2330
2390
|
const normalized = {
|
|
2331
|
-
text:
|
|
2391
|
+
text: texts[i],
|
|
2332
2392
|
x: Math.round(xs[i].x / scale),
|
|
2333
2393
|
// NormItem.y 는 pdfjs transform[5] = 베이스라인 (bottom-up) — 잉크 하단으로 근사
|
|
2334
2394
|
y: Math.round(pdfH - bottoms[i] / scale),
|
|
@@ -2342,8 +2402,50 @@ function ocrItemsToBlocks(items, pageNumber, pdfW, pdfH, scale, extraLines, dete
|
|
|
2342
2402
|
};
|
|
2343
2403
|
copyOcrTextGaps(it, normalized, 1 / scale);
|
|
2344
2404
|
return normalized;
|
|
2345
|
-
});
|
|
2346
|
-
|
|
2405
|
+
}).filter((it) => it.text);
|
|
2406
|
+
const blocks = unframeOcrLayoutTables(splitStackedOcrRows(extractPageBlocksWithLines(norm, pageNumber, opList, pdfW, pdfH, extraLines, detectTables)), pdfH);
|
|
2407
|
+
if (!figureRegion) markOcrHeadings(blocks);
|
|
2408
|
+
return blocks;
|
|
2409
|
+
}
|
|
2410
|
+
function markOcrHeadings(blocks) {
|
|
2411
|
+
const sized = blocks.filter((b) => b.type === "paragraph" && b.text && b.style?.fontSize);
|
|
2412
|
+
const weights = sized.map((b) => [b.style.fontSize, b.text.length]);
|
|
2413
|
+
const total = weights.reduce((n, [, w]) => n + w, 0);
|
|
2414
|
+
if (total < 100) return;
|
|
2415
|
+
weights.sort((a, b) => a[0] - b[0]);
|
|
2416
|
+
let acc = 0, body = 0;
|
|
2417
|
+
for (const [size, w] of weights) {
|
|
2418
|
+
acc += w;
|
|
2419
|
+
if (acc >= total / 2) {
|
|
2420
|
+
body = size;
|
|
2421
|
+
break;
|
|
2422
|
+
}
|
|
2423
|
+
}
|
|
2424
|
+
if (!body) return;
|
|
2425
|
+
for (const b of sized) {
|
|
2426
|
+
const text = b.text.trim(), size = b.style.fontSize;
|
|
2427
|
+
const ratio = size / body;
|
|
2428
|
+
if (ratio < 1.3) continue;
|
|
2429
|
+
if (text.length < 2 || text.length > (ratio >= 1.5 ? 60 : 40) || /[.!?。]$|다\.?$/.test(text) || /^[\d\s.,%·-]+$/.test(text)) continue;
|
|
2430
|
+
if (b.bbox && b.bbox.height > size * (ratio >= 1.5 ? 3.2 : 1.6)) continue;
|
|
2431
|
+
b.type = "heading";
|
|
2432
|
+
b.level = ratio >= 1.5 ? 1 : 2;
|
|
2433
|
+
}
|
|
2434
|
+
for (let i = blocks.length - 1; i > 0; i--) {
|
|
2435
|
+
const a = blocks[i - 1], b = blocks[i];
|
|
2436
|
+
if (a.type !== "heading" || b.type !== "heading" || !a.bbox || !b.bbox) continue;
|
|
2437
|
+
const marker = /^(?:제\s*\d+\s*[장절편부]|chapter\s*\d+|part\s*\d+)$/i.test(a.text.trim());
|
|
2438
|
+
const sa = a.style?.fontSize ?? 0, sb = b.style?.fontSize ?? 0;
|
|
2439
|
+
if (!marker && (a.level !== b.level || Math.max(sa, sb) > Math.min(sa, sb) * 1.3)) continue;
|
|
2440
|
+
const gap = a.bbox.y - (b.bbox.y + b.bbox.height), size = Math.max(a.style?.fontSize ?? 0, b.style?.fontSize ?? 0);
|
|
2441
|
+
const across = Math.min(a.bbox.x + a.bbox.width, b.bbox.x + b.bbox.width) - Math.max(a.bbox.x, b.bbox.x);
|
|
2442
|
+
if (gap < 0 || gap > size * (marker ? 3 : 1.2) || across <= 0) continue;
|
|
2443
|
+
a.level = Math.min(a.level ?? 2, b.level ?? 2);
|
|
2444
|
+
a.text = `${a.text.trim()} ${b.text.trim()}`;
|
|
2445
|
+
const x = Math.min(a.bbox.x, b.bbox.x);
|
|
2446
|
+
a.bbox = { ...a.bbox, x, y: b.bbox.y, width: Math.max(a.bbox.x + a.bbox.width, b.bbox.x + b.bbox.width) - x, height: a.bbox.y + a.bbox.height - b.bbox.y };
|
|
2447
|
+
blocks.splice(i, 1);
|
|
2448
|
+
}
|
|
2347
2449
|
}
|
|
2348
2450
|
async function tryImport2(name, loader) {
|
|
2349
2451
|
try {
|
|
@@ -2385,6 +2487,7 @@ export {
|
|
|
2385
2487
|
detectRulingLines,
|
|
2386
2488
|
rulingToPdfLines,
|
|
2387
2489
|
deskewPage,
|
|
2490
|
+
rotateQuarter,
|
|
2388
2491
|
MAX_OCR_PIXELS,
|
|
2389
2492
|
DEFAULT_BUILTIN_OCR,
|
|
2390
2493
|
builtinOcrConfig,
|
|
@@ -2397,6 +2500,7 @@ export {
|
|
|
2397
2500
|
runPdfOcr,
|
|
2398
2501
|
ocrOnePage,
|
|
2399
2502
|
groupOcrLines,
|
|
2400
|
-
ocrItemsToBlocks
|
|
2503
|
+
ocrItemsToBlocks,
|
|
2504
|
+
markOcrHeadings
|
|
2401
2505
|
};
|
|
2402
|
-
//# sourceMappingURL=chunk-
|
|
2506
|
+
//# sourceMappingURL=chunk-WPIG3KUV.js.map
|