kordoc 4.16.0 → 4.16.2
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 +344 -1135
- package/dist/{-VQNLLLPE.js → -4G6MA4X6.js} +11 -11
- package/dist/chunk-3IB7LBHC.js +57 -0
- package/dist/chunk-3IB7LBHC.js.map +1 -0
- package/dist/{chunk-6LMKQM7I.js → chunk-4VODJKFL.js} +3 -3
- package/dist/{chunk-UDX7TSOC.js → chunk-5KS5PWJR.js} +2 -2
- package/dist/chunk-62W7QCEX.cjs +57 -0
- package/dist/chunk-62W7QCEX.cjs.map +1 -0
- package/dist/{chunk-NNYF2AGC.js → chunk-7KNGSQU7.js} +4 -4
- package/dist/chunk-7KNGSQU7.js.map +1 -0
- package/dist/{chunk-DYENR3PX.js → chunk-AUWGDP4G.js} +2 -2
- package/dist/{chunk-H6KMTYYZ.cjs → chunk-CEIATRDW.cjs} +3 -3
- package/dist/{chunk-H6KMTYYZ.cjs.map → chunk-CEIATRDW.cjs.map} +1 -1
- package/dist/{chunk-N6TPODYL.js → chunk-DES2LGFZ.js} +2 -2
- package/dist/{chunk-PQRP4NSF.js → chunk-F4NRLLY4.js} +2 -2
- package/dist/{chunk-B5NEGP65.cjs → chunk-FKUDAIJI.cjs} +692 -33
- package/dist/chunk-FKUDAIJI.cjs.map +1 -0
- package/dist/{chunk-XWA625AN.js → chunk-FSDJLAOW.js} +3 -1
- package/dist/chunk-FSDJLAOW.js.map +1 -0
- package/dist/{chunk-PIMB2YNO.js → chunk-GO5IFOUF.js} +2 -2
- package/dist/{chunk-476OYHGZ.js → chunk-IQGIT2VX.js} +37 -7
- package/dist/chunk-IQGIT2VX.js.map +1 -0
- package/dist/chunk-J3IF6KGW.js +59 -0
- package/dist/chunk-J3IF6KGW.js.map +1 -0
- package/dist/{chunk-C75WE52C.js → chunk-JELRWAZC.js} +2 -2
- package/dist/{chunk-46DZF3RK.js → chunk-JFLAM3MM.js} +2 -2
- package/dist/{chunk-A3QDRMVD.js → chunk-KIOQ4N37.js} +2 -2
- package/dist/{chunk-TGD7UFHD.js → chunk-LEIAEWZ7.js} +4 -4
- package/dist/chunk-LEIAEWZ7.js.map +1 -0
- package/dist/{chunk-GOQBON77.js → chunk-MLIS253L.js} +2 -2
- package/dist/{chunk-JB5X5NNL.js → chunk-OXLPVQYK.js} +680 -21
- package/dist/chunk-OXLPVQYK.js.map +1 -0
- package/dist/{chunk-RC4C7Q33.js → chunk-P6ZDXTV6.js} +2 -2
- package/dist/{chunk-CB5XDCSL.js → chunk-QOCS7W7R.js} +5034 -4569
- package/dist/chunk-QOCS7W7R.js.map +1 -0
- package/dist/{chunk-3JWMDL3S.js → chunk-S2PL227Q.js} +2 -2
- package/dist/{chunk-HIVK5V27.js → chunk-SFEQYKYJ.js} +133 -110
- package/dist/chunk-SFEQYKYJ.js.map +1 -0
- package/dist/{chunk-NWODPYBD.cjs → chunk-STM3ORY7.cjs} +2 -2
- package/dist/{chunk-NWODPYBD.cjs.map → chunk-STM3ORY7.cjs.map} +1 -1
- package/dist/{chunk-43FKGDDO.js → chunk-TXUKTOG2.js} +213 -30
- package/dist/chunk-TXUKTOG2.js.map +1 -0
- package/dist/{chunk-XHOZB2WP.js → chunk-UTP2WCHS.js} +681 -22
- package/dist/chunk-UTP2WCHS.js.map +1 -0
- package/dist/{chunk-MH6MAL64.cjs → chunk-WDQTFAXY.cjs} +217 -114
- package/dist/chunk-WDQTFAXY.cjs.map +1 -0
- package/dist/{chunk-DRY3L5KQ.cjs → chunk-XTFN5WKS.cjs} +7 -7
- package/dist/chunk-XTFN5WKS.cjs.map +1 -0
- package/dist/chunks-NUNIKS2J.js +10 -0
- package/dist/cli.js +33 -30
- package/dist/cli.js.map +1 -1
- package/dist/{formula-FNQYHMIY.js → formula-EPKLPDU7.js} +3 -3
- package/dist/{formula-5775PTP2.js → formula-NARUOXRX.js} +4 -4
- package/dist/{formula-VEFKYXPB.cjs → formula-WIMV5TUX.cjs} +9 -9
- package/dist/{formula-VEFKYXPB.cjs.map → formula-WIMV5TUX.cjs.map} +1 -1
- package/dist/{image-ocr-PYZU4TO7.js → image-ocr-3WJ4QH3T.js} +8 -8
- package/dist/{image-ocr-YA2MQBRP.js → image-ocr-5BUJQ4TK.js} +6 -6
- package/dist/{image-ocr-6JZR734G.cjs → image-ocr-AXWXR6JV.cjs} +15 -15
- package/dist/{image-ocr-6JZR734G.cjs.map → image-ocr-AXWXR6JV.cjs.map} +1 -1
- package/dist/index.cjs +1900 -1406
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +24 -6
- package/dist/index.d.ts +24 -6
- package/dist/index.js +1282 -788
- package/dist/index.js.map +1 -1
- package/dist/mcp.js +34 -28
- package/dist/mcp.js.map +1 -1
- package/dist/{model-bundle-O6J7ORVC.js → model-bundle-IMBW7D2Z.js} +5 -5
- package/dist/{models-YMOKZGCI.js → models-SY75IBOE.js} +5 -5
- package/dist/{parser-YAQV7FBO.cjs → parser-2LU4EVU3.cjs} +360 -219
- package/dist/parser-2LU4EVU3.cjs.map +1 -0
- package/dist/{parser-3B6I2XL7.js → parser-N6476XAC.js} +225 -84
- package/dist/parser-N6476XAC.js.map +1 -0
- package/dist/{parser-PXATL5DM.js → parser-ZQM3664Z.js} +222 -81
- package/dist/parser-ZQM3664Z.js.map +1 -0
- package/dist/pdf-ocr-6DEE23IP.js +15 -0
- package/dist/pdf-ocr-GHEJVPX2.cjs +16 -0
- package/dist/{pdf-ocr-T2JXQATA.cjs.map → pdf-ocr-GHEJVPX2.cjs.map} +1 -1
- package/dist/pdf-ocr-MQTWODVU.js +18 -0
- package/dist/{profile-io-ZTV2MKRT.js → profile-io-GJPKCYPT.js} +3 -3
- package/dist/{rasterize-MMUZ537K.js → rasterize-UOALJQDS.js} +3 -3
- package/dist/{redact-doc-S42XGV5D.js → redact-doc-22SYW3KH.js} +11 -11
- package/dist/{render-WCWPZKJ7.js → render-MJ4H3R23.js} +7 -7
- package/dist/seal-XWMRUTI4.js +10 -0
- package/dist/{setup-D35LKZCH.js → setup-2URYVUEO.js} +3 -3
- package/dist/visual-USPS4QRC.js +20 -0
- package/dist/{watch-AX64CIMN.js → watch-ALXZGTOB.js} +12 -12
- package/package.json +1 -1
- package/dist/chunk-43FKGDDO.js.map +0 -1
- package/dist/chunk-476OYHGZ.js.map +0 -1
- package/dist/chunk-B5NEGP65.cjs.map +0 -1
- package/dist/chunk-CB5XDCSL.js.map +0 -1
- package/dist/chunk-DRY3L5KQ.cjs.map +0 -1
- package/dist/chunk-HIVK5V27.js.map +0 -1
- package/dist/chunk-JB5X5NNL.js.map +0 -1
- package/dist/chunk-MH6MAL64.cjs.map +0 -1
- package/dist/chunk-NNYF2AGC.js.map +0 -1
- package/dist/chunk-QJERJZJ6.js +0 -11
- package/dist/chunk-QJERJZJ6.js.map +0 -1
- package/dist/chunk-TGD7UFHD.js.map +0 -1
- package/dist/chunk-UQ6TZDW6.js +0 -13
- package/dist/chunk-UQ6TZDW6.js.map +0 -1
- package/dist/chunk-XHOZB2WP.js.map +0 -1
- package/dist/chunk-XWA625AN.js.map +0 -1
- package/dist/chunk-ZY5K3LPM.cjs +0 -11
- package/dist/chunk-ZY5K3LPM.cjs.map +0 -1
- package/dist/chunks-JD25E5PM.js +0 -10
- package/dist/parser-3B6I2XL7.js.map +0 -1
- package/dist/parser-PXATL5DM.js.map +0 -1
- package/dist/parser-YAQV7FBO.cjs.map +0 -1
- package/dist/pdf-ocr-2TTO5PX2.js +0 -15
- package/dist/pdf-ocr-T2JXQATA.cjs +0 -16
- package/dist/pdf-ocr-WF2NQA6X.js +0 -18
- package/dist/seal-WHK4GOHR.js +0 -10
- package/dist/visual-WL4TDE5B.js +0 -20
- /package/dist/{-VQNLLLPE.js.map → -4G6MA4X6.js.map} +0 -0
- /package/dist/{chunk-6LMKQM7I.js.map → chunk-4VODJKFL.js.map} +0 -0
- /package/dist/{chunk-UDX7TSOC.js.map → chunk-5KS5PWJR.js.map} +0 -0
- /package/dist/{chunk-DYENR3PX.js.map → chunk-AUWGDP4G.js.map} +0 -0
- /package/dist/{chunk-N6TPODYL.js.map → chunk-DES2LGFZ.js.map} +0 -0
- /package/dist/{chunk-PQRP4NSF.js.map → chunk-F4NRLLY4.js.map} +0 -0
- /package/dist/{chunk-PIMB2YNO.js.map → chunk-GO5IFOUF.js.map} +0 -0
- /package/dist/{chunk-C75WE52C.js.map → chunk-JELRWAZC.js.map} +0 -0
- /package/dist/{chunk-46DZF3RK.js.map → chunk-JFLAM3MM.js.map} +0 -0
- /package/dist/{chunk-A3QDRMVD.js.map → chunk-KIOQ4N37.js.map} +0 -0
- /package/dist/{chunk-GOQBON77.js.map → chunk-MLIS253L.js.map} +0 -0
- /package/dist/{chunk-RC4C7Q33.js.map → chunk-P6ZDXTV6.js.map} +0 -0
- /package/dist/{chunk-3JWMDL3S.js.map → chunk-S2PL227Q.js.map} +0 -0
- /package/dist/{chunks-JD25E5PM.js.map → chunks-NUNIKS2J.js.map} +0 -0
- /package/dist/{formula-FNQYHMIY.js.map → formula-EPKLPDU7.js.map} +0 -0
- /package/dist/{formula-5775PTP2.js.map → formula-NARUOXRX.js.map} +0 -0
- /package/dist/{image-ocr-PYZU4TO7.js.map → image-ocr-3WJ4QH3T.js.map} +0 -0
- /package/dist/{image-ocr-YA2MQBRP.js.map → image-ocr-5BUJQ4TK.js.map} +0 -0
- /package/dist/{model-bundle-O6J7ORVC.js.map → model-bundle-IMBW7D2Z.js.map} +0 -0
- /package/dist/{models-YMOKZGCI.js.map → models-SY75IBOE.js.map} +0 -0
- /package/dist/{pdf-ocr-2TTO5PX2.js.map → pdf-ocr-6DEE23IP.js.map} +0 -0
- /package/dist/{pdf-ocr-WF2NQA6X.js.map → pdf-ocr-MQTWODVU.js.map} +0 -0
- /package/dist/{profile-io-ZTV2MKRT.js.map → profile-io-GJPKCYPT.js.map} +0 -0
- /package/dist/{rasterize-MMUZ537K.js.map → rasterize-UOALJQDS.js.map} +0 -0
- /package/dist/{redact-doc-S42XGV5D.js.map → redact-doc-22SYW3KH.js.map} +0 -0
- /package/dist/{render-WCWPZKJ7.js.map → render-MJ4H3R23.js.map} +0 -0
- /package/dist/{seal-WHK4GOHR.js.map → seal-XWMRUTI4.js.map} +0 -0
- /package/dist/{setup-D35LKZCH.js.map → setup-2URYVUEO.js.map} +0 -0
- /package/dist/{visual-WL4TDE5B.js.map → visual-USPS4QRC.js.map} +0 -0
- /package/dist/{watch-AX64CIMN.js.map → watch-ALXZGTOB.js.map} +0 -0
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
var
|
|
7
|
+
var _chunkXTFN5WKScjs = require('./chunk-XTFN5WKS.cjs');
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
|
|
@@ -43,13 +43,16 @@ var _chunkJ55UQC5Hcjs = require('./chunk-J55UQC5H.cjs');
|
|
|
43
43
|
|
|
44
44
|
|
|
45
45
|
|
|
46
|
-
var _chunkMH6MAL64cjs = require('./chunk-MH6MAL64.cjs');
|
|
47
|
-
require('./chunk-ZY5K3LPM.cjs');
|
|
48
|
-
require('./chunk-H6KMTYYZ.cjs');
|
|
49
46
|
|
|
47
|
+
var _chunkWDQTFAXYcjs = require('./chunk-WDQTFAXY.cjs');
|
|
50
48
|
|
|
51
49
|
|
|
52
|
-
var
|
|
50
|
+
var _chunk62W7QCEXcjs = require('./chunk-62W7QCEX.cjs');
|
|
51
|
+
require('./chunk-CEIATRDW.cjs');
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
var _chunkSTM3ORY7cjs = require('./chunk-STM3ORY7.cjs');
|
|
53
56
|
|
|
54
57
|
|
|
55
58
|
var _chunkGS7T56RPcjs = require('./chunk-GS7T56RP.cjs');
|
|
@@ -243,7 +246,7 @@ async function extractPageImages(page, fnArray, argsArray, pageNumber, state, wa
|
|
|
243
246
|
const filename = `image_${String(state.imageIndex).padStart(3, "0")}.png`;
|
|
244
247
|
state.seen.set(hash, filename);
|
|
245
248
|
if (withBytes) {
|
|
246
|
-
const png =
|
|
249
|
+
const png = _chunkXTFN5WKScjs.encodePng.call(void 0, w, h, rgba);
|
|
247
250
|
state.totalBytes += png.length;
|
|
248
251
|
images.push({ filename, data: png, mimeType: "image/png" });
|
|
249
252
|
}
|
|
@@ -637,6 +640,40 @@ function ocrVectorOps(opList, paths) {
|
|
|
637
640
|
return { fnArray, argsArray };
|
|
638
641
|
}
|
|
639
642
|
|
|
643
|
+
// src/pdf/contact-table.ts
|
|
644
|
+
var CONTACT_HEAD = /^(?:담당\s*부서|<[^<>]+>)$/;
|
|
645
|
+
var CONTACT_ROLE = /^(?:책임자|담당자)$/;
|
|
646
|
+
var PERSON = /^(.+?)\s+([가-힣]{2,4})\s+(\([^()]*\d[^()]*\)|\S+@\S+)$/;
|
|
647
|
+
function splitContactTables(blocks) {
|
|
648
|
+
for (const b of blocks) {
|
|
649
|
+
const t = b.type === "table" ? b.table : void 0;
|
|
650
|
+
if (!t || t.cols !== 4 || t.rows < 2) continue;
|
|
651
|
+
const rows = t.cells;
|
|
652
|
+
if (!CONTACT_HEAD.test(rows[0][0].text.replace(/\s+/g, " ").trim())) continue;
|
|
653
|
+
const people = rows.map((r) => PERSON.exec(r[3].text.replace(/\s+/g, " ").trim()));
|
|
654
|
+
if (people.some((p) => !p) || rows.some((r) => !CONTACT_ROLE.test(r[2].text.replace(/\s+/g, "")) || r[2].rowSpan !== 1 || r[3].rowSpan !== 1)) continue;
|
|
655
|
+
const lead = [];
|
|
656
|
+
let ok = true;
|
|
657
|
+
for (const c of [0, 1]) {
|
|
658
|
+
const top = rows[0][c];
|
|
659
|
+
if (top.rowSpan === 1) {
|
|
660
|
+
lead.push(rows.map((r) => r[c].text));
|
|
661
|
+
continue;
|
|
662
|
+
}
|
|
663
|
+
const lines = top.text.split("\n").map((s) => s.trim()).filter(Boolean);
|
|
664
|
+
if (top.rowSpan !== t.rows || lines.length > t.rows) {
|
|
665
|
+
ok = false;
|
|
666
|
+
break;
|
|
667
|
+
}
|
|
668
|
+
lead.push(rows.map((_, r) => _nullishCoalesce(lines[r], () => ( ""))));
|
|
669
|
+
}
|
|
670
|
+
if (!ok) continue;
|
|
671
|
+
const one = (text) => ({ text, colSpan: 1, rowSpan: 1 });
|
|
672
|
+
t.cells = rows.map((r, i) => [one(lead[0][i]), one(lead[1][i]), one(r[2].text), one(people[i][1]), one(people[i][2]), one(people[i][3])]);
|
|
673
|
+
t.cols = 6;
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
|
|
640
677
|
// src/pdf/table-parts.ts
|
|
641
678
|
var PART_COL_TOL = 1;
|
|
642
679
|
function anchorsOf(table) {
|
|
@@ -673,7 +710,7 @@ var indexOf = (coords, x) => {
|
|
|
673
710
|
};
|
|
674
711
|
var rowText = (anchors, r) => anchors.filter((a) => a.r === r).map((a) => a.cell.text.replace(/\s+/g, "")).join("|");
|
|
675
712
|
var hasText = (t) => t.replace(/\|/g, "") !== "";
|
|
676
|
-
function joinSplitParts(prev, pcx, curr, ccx, dx = 0, prevBottom) {
|
|
713
|
+
function joinSplitParts(prev, pcx, curr, ccx, dx = 0, prevBottom, lex) {
|
|
677
714
|
if (pcx.length !== prev.cols + 1 || ccx.length !== curr.cols + 1) return null;
|
|
678
715
|
const U = unionCoords(pcx, ccx);
|
|
679
716
|
const cols = U.length - 1;
|
|
@@ -696,14 +733,14 @@ function joinSplitParts(prev, pcx, curr, ccx, dx = 0, prevBottom) {
|
|
|
696
733
|
if (r + dr < rows) owner[r + dr][dc] = placed;
|
|
697
734
|
}
|
|
698
735
|
grid[r][c1] = { ...a.cell, colSpan: c2 - c1, rowSpan: a.rs };
|
|
699
|
-
const lines =
|
|
700
|
-
if (lines)
|
|
701
|
-
if (
|
|
736
|
+
const lines = _chunkWDQTFAXYcjs.CELL_LINES.get(a.cell);
|
|
737
|
+
if (lines) _chunkWDQTFAXYcjs.CELL_LINES.set(grid[r][c1], shift ? lines.map((l) => ({ ...l, l: l.l + shift, r: l.r + shift })) : lines);
|
|
738
|
+
if (_chunkWDQTFAXYcjs.IMAGE_CELLS.has(a.cell)) _chunkWDQTFAXYcjs.IMAGE_CELLS.add(grid[r][c1]);
|
|
702
739
|
return true;
|
|
703
740
|
};
|
|
704
|
-
for (const a of pa) if (!
|
|
741
|
+
for (const a of pa) if (!_chunkWDQTFAXYcjs.FILLER_CELLS.has(a.cell) && !place(a, pcx, 0)) return null;
|
|
705
742
|
for (const a of ca) {
|
|
706
|
-
if (a.r < skip ||
|
|
743
|
+
if (a.r < skip || _chunkWDQTFAXYcjs.FILLER_CELLS.has(a.cell)) continue;
|
|
707
744
|
if (!place(a, ccx, prev.rows - skip, dx)) return null;
|
|
708
745
|
}
|
|
709
746
|
const first = prev.rows;
|
|
@@ -727,15 +764,37 @@ function joinSplitParts(prev, pcx, curr, ccx, dx = 0, prevBottom) {
|
|
|
727
764
|
const grown = { ...above, rs: newRs };
|
|
728
765
|
for (let rr = above.r; rr < above.r + newRs; rr++) for (let dc = above.c; dc < above.c + above.cs; dc++) owner[rr][dc] = grown;
|
|
729
766
|
}
|
|
730
|
-
for (let r = 0; r < rows; r++) for (let c = 0; c < cols; c++) if (owner[r][c] === null)
|
|
767
|
+
for (let r = 0; r < rows; r++) for (let c = 0; c < cols; c++) if (owner[r][c] === null) _chunkWDQTFAXYcjs.FILLER_CELLS.add(grid[r][c]);
|
|
731
768
|
const table = { rows, cols, cells: grid, hasHeader: prev.hasHeader, ...prev.caption ? { caption: prev.caption } : {} };
|
|
732
|
-
|
|
733
|
-
if (rows > prev.rows && !split && prevBottom !== void 0
|
|
769
|
+
let split = rows > prev.rows && mergeSplitRow(table, owner, prev.rows, U);
|
|
770
|
+
if (rows > prev.rows && !split && prevBottom !== void 0 && mergeStraddlingCells(table, owner, prev.rows, prevBottom, lex)) split = mergeSplitRow(table, owner, prev.rows, U, true);
|
|
734
771
|
return { table, colXs: U, split, header: ca.filter((a) => a.r < skip && a.cell.text.trim()).length >= 2 };
|
|
735
772
|
}
|
|
736
|
-
function mergeStraddlingCells(table, owner, first, prevBottom) {
|
|
773
|
+
function mergeStraddlingCells(table, owner, first, prevBottom, lex) {
|
|
737
774
|
const last = first - 1;
|
|
738
|
-
|
|
775
|
+
const straddles = owner[first].some((o, c) => o !== null && o === owner[last][c]);
|
|
776
|
+
let firstNew = table.cols;
|
|
777
|
+
for (let c = 0; c < table.cols; c++) {
|
|
778
|
+
const d = owner[first][c];
|
|
779
|
+
if (d && d.r === first && d !== owner[last][c] && hasContent(table.cells[d.r][d.c])) {
|
|
780
|
+
firstNew = c;
|
|
781
|
+
break;
|
|
782
|
+
}
|
|
783
|
+
}
|
|
784
|
+
let midWord = false;
|
|
785
|
+
if (lex) for (let c = 0; c < table.cols && !midWord; ) {
|
|
786
|
+
const u = owner[last][c], d = owner[first][c];
|
|
787
|
+
if (!u) {
|
|
788
|
+
c++;
|
|
789
|
+
continue;
|
|
790
|
+
}
|
|
791
|
+
c = u.c + u.cs;
|
|
792
|
+
if (!d || d === u || u.r + u.rs - 1 !== last || d.r !== first || d.c !== u.c || d.cs !== u.cs) continue;
|
|
793
|
+
if (u.r !== last || d.rs < 2) continue;
|
|
794
|
+
const tail = _nullishCoalesce(table.cells[u.r][u.c].text.trim().split(/\s+/).pop(), () => ( "")), head = _nullishCoalesce(table.cells[first][d.c].text.trim().split(/\s+/)[0], () => ( ""));
|
|
795
|
+
if (/^[가-힣]{2,}$/.test(tail) && /^[가-힣]{2,}/.test(head) && lex.evidence2(tail, head) === "") midWord = true;
|
|
796
|
+
}
|
|
797
|
+
let merged = false;
|
|
739
798
|
for (let c = 0; c < table.cols; ) {
|
|
740
799
|
const u = owner[last][c], d = owner[first][c];
|
|
741
800
|
if (!u) {
|
|
@@ -743,18 +802,24 @@ function mergeStraddlingCells(table, owner, first, prevBottom) {
|
|
|
743
802
|
continue;
|
|
744
803
|
}
|
|
745
804
|
c = u.c + u.cs;
|
|
746
|
-
if (!d || d === u || u.r
|
|
805
|
+
if (!d || d === u || u.r + u.rs - 1 !== last || d.r !== first || d.c !== u.c || d.cs !== u.cs) continue;
|
|
747
806
|
const a = table.cells[u.r][u.c], b = table.cells[first][d.c];
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
807
|
+
if (!(u.rs >= 2 && u.c + u.cs <= firstNew && hasContent(a) && !hasContent(b))) {
|
|
808
|
+
if (!straddles && !midWord) continue;
|
|
809
|
+
if (u.r >= last && d.rs < 2) continue;
|
|
810
|
+
const U = _chunkWDQTFAXYcjs.CELL_LINES.get(a);
|
|
811
|
+
if (!_optionalChain([U, 'optionalAccess', _33 => _33.length]) || U.length > STRADDLE_MAX_LINES || !hasContent(b)) continue;
|
|
812
|
+
const lu = U[U.length - 1];
|
|
813
|
+
if (!midWord && lu.y - prevBottom > (u.r >= last ? STRADDLE_BOTTOM_ONE_ROW : STRADDLE_BOTTOM) * (lu.h || 10)) continue;
|
|
814
|
+
}
|
|
752
815
|
appendCell(a, b);
|
|
753
816
|
a.rowSpan = first + d.rs - u.r;
|
|
754
817
|
table.cells[first][d.c] = { text: "", colSpan: 1, rowSpan: 1 };
|
|
755
818
|
const grown = { ...u, rs: a.rowSpan };
|
|
756
819
|
for (let rr = u.r; rr < u.r + grown.rs; rr++) for (let dc = u.c; dc < u.c + u.cs; dc++) owner[rr][dc] = grown;
|
|
820
|
+
merged = true;
|
|
757
821
|
}
|
|
822
|
+
return merged;
|
|
758
823
|
}
|
|
759
824
|
var FULL_LINE_TOL = 1;
|
|
760
825
|
var FULL_LINE_MIN_FRAC = 0.5;
|
|
@@ -769,7 +834,7 @@ var LABEL_ROOM = 1.5;
|
|
|
769
834
|
var HANGING_MIN = 0.5;
|
|
770
835
|
var HANGING_TOL = 1;
|
|
771
836
|
function continuesAcross(u, d, x1, x2) {
|
|
772
|
-
const U =
|
|
837
|
+
const U = _chunkWDQTFAXYcjs.CELL_LINES.get(u), D = _chunkWDQTFAXYcjs.CELL_LINES.get(d);
|
|
773
838
|
if (!_optionalChain([U, 'optionalAccess', _34 => _34.length]) || !_optionalChain([D, 'optionalAccess', _35 => _35.length])) return false;
|
|
774
839
|
const last = U[U.length - 1];
|
|
775
840
|
const fs = last.h || 10;
|
|
@@ -790,11 +855,21 @@ function continuesAcross(u, d, x1, x2) {
|
|
|
790
855
|
const hanging = U.length >= 2 && U.every((l) => maxR - l.r <= FULL_LINE_TOL * fs) && last.l - minL >= HANGING_MIN * fs && Math.abs(D[0].l - last.l) <= HANGING_TOL;
|
|
791
856
|
return U.some(leftAligned) || D.some(leftAligned) || hanging;
|
|
792
857
|
}
|
|
793
|
-
|
|
794
|
-
|
|
858
|
+
var OUTLINE_HEAD = /^[□■]\s*\S/;
|
|
859
|
+
var OUTLINE_ITEM = /^[ㅇ○◦\-‐–·․‧※*]\s*\S/;
|
|
860
|
+
function outlineContinues(u, d) {
|
|
861
|
+
const U = u.text.split("\n").map((l) => l.trim()).filter(Boolean);
|
|
862
|
+
const D = d.text.split("\n").map((l) => l.trim()).filter(Boolean);
|
|
863
|
+
return U.length >= 2 && D.length >= 1 && U.some((l) => OUTLINE_HEAD.test(l)) && OUTLINE_ITEM.test(D[0]);
|
|
864
|
+
}
|
|
865
|
+
function lineEnded(c, x1, x2, next = "") {
|
|
866
|
+
const L = _chunkWDQTFAXYcjs.CELL_LINES.get(c);
|
|
795
867
|
if (!L || L.length !== 1) return false;
|
|
796
|
-
const l = L[0];
|
|
797
|
-
|
|
868
|
+
const l = L[0], h = l.h || 10;
|
|
869
|
+
const word = _nullishCoalesce(next.trim().split(/\s+/)[0], () => ( ""));
|
|
870
|
+
let units = 0;
|
|
871
|
+
for (const ch of word) units += /[가-힣\u3400-\u9fff]/.test(ch) ? 1 : 0.55;
|
|
872
|
+
return x2 - l.r - (l.l - x1) >= Math.max(LABEL_ROOM, units) * h;
|
|
798
873
|
}
|
|
799
874
|
function appendCell(a, b) {
|
|
800
875
|
if (_optionalChain([a, 'access', _36 => _36.blocks, 'optionalAccess', _37 => _37.length]) || _optionalChain([b, 'access', _38 => _38.blocks, 'optionalAccess', _39 => _39.length])) {
|
|
@@ -803,8 +878,23 @@ function appendCell(a, b) {
|
|
|
803
878
|
}
|
|
804
879
|
if (b.text.trim()) a.text = a.text.trim() ? a.text + "\n" + b.text : b.text;
|
|
805
880
|
}
|
|
806
|
-
var hasContent = (cell) => !!cell.text.trim() || !!_optionalChain([cell, 'access', _42 => _42.blocks, 'optionalAccess', _43 => _43.length]) ||
|
|
807
|
-
|
|
881
|
+
var hasContent = (cell) => !!cell.text.trim() || !!_optionalChain([cell, 'access', _42 => _42.blocks, 'optionalAccess', _43 => _43.length]) || _chunkWDQTFAXYcjs.IMAGE_CELLS.has(cell);
|
|
882
|
+
var CLAUSE_OPEN_ENDING = /(?:하는|되는|하고|하며|하여|되어|되고|되며|이며|으며|어야|아야|여야)$/;
|
|
883
|
+
var batchim = (ch) => {
|
|
884
|
+
const k = ch.charCodeAt(0) - 44032;
|
|
885
|
+
return k >= 0 && k < 11172 && k % 28 !== 0;
|
|
886
|
+
};
|
|
887
|
+
function clauseContinues(u, d) {
|
|
888
|
+
const tail = _nullishCoalesce(u.text.trim().split(/\s+/).pop(), () => ( "")), head = d.text.trim();
|
|
889
|
+
if (!/^[가-힣]{2,}$/.test(tail) || !/^[가-힣]/.test(head) || _chunkWDQTFAXYcjs.startsNewItem.call(void 0, u.text, head)) return false;
|
|
890
|
+
const last = tail[tail.length - 1], before = tail[tail.length - 2];
|
|
891
|
+
return last === "\uC744" && batchim(before) || last === "\uB97C" && !batchim(before) || CLAUSE_OPEN_ENDING.test(tail);
|
|
892
|
+
}
|
|
893
|
+
function outlineOnly(pairs, cell) {
|
|
894
|
+
const filled = pairs.filter(([, d]) => hasContent(d.cell));
|
|
895
|
+
return filled.length === 1 && outlineContinues(cell(filled[0][0]), cell(filled[0][1]));
|
|
896
|
+
}
|
|
897
|
+
function mergeSplitRow(table, owner, first, colXs, textOnly = false) {
|
|
808
898
|
const last = first - 1;
|
|
809
899
|
const pairs = [];
|
|
810
900
|
let carried = false;
|
|
@@ -822,12 +912,12 @@ function mergeSplitRow(table, owner, first, colXs) {
|
|
|
822
912
|
} else if (a.r === last && a.rs === 2) carried = true;
|
|
823
913
|
c = a.c + a.cs;
|
|
824
914
|
}
|
|
825
|
-
const carriedSplit = carried && pairs.filter(([u, d]) => hasContent(u.cell) && hasContent(d.cell)).length <= 1 && !pairs.some(([u, d]) => !hasContent(u.cell) && hasContent(d.cell));
|
|
915
|
+
const carriedSplit = !textOnly && carried && pairs.filter(([u, d]) => hasContent(u.cell) && hasContent(d.cell)).length <= 1 && !pairs.some(([u, d]) => !hasContent(u.cell) && hasContent(d.cell));
|
|
826
916
|
const cell = (a) => table.cells[a.r][a.c];
|
|
827
917
|
if (!carriedSplit) {
|
|
828
918
|
const norm = (c) => c.text.replace(/\s+/g, "");
|
|
829
|
-
if (pairs.some(([u, d]) => hasContent(d.cell) && norm(cell(d)) !== norm(cell(u)) && lineEnded(cell(u), colXs[u.c], colXs[u.c + u.cs]))) return false;
|
|
830
|
-
if (!pairs.some(([u, d]) => continuesAcross(cell(u), cell(d), colXs[u.c], colXs[u.c + u.cs]))) return false;
|
|
919
|
+
if (pairs.some(([u, d]) => hasContent(d.cell) && norm(cell(d)) !== norm(cell(u)) && lineEnded(cell(u), colXs[u.c], colXs[u.c + u.cs], cell(d).text))) return false;
|
|
920
|
+
if (!outlineOnly(pairs, cell) && !pairs.some(([u, d]) => continuesAcross(cell(u), cell(d), colXs[u.c], colXs[u.c + u.cs])) && !pairs.some(([u, d]) => clauseContinues(cell(u), cell(d)))) return false;
|
|
831
921
|
}
|
|
832
922
|
for (const [u, d] of pairs) appendCell(table.cells[u.r][u.c], table.cells[d.r][d.c]);
|
|
833
923
|
for (let r = 0; r < first; r++) for (let c = 0; c < table.cols; c++) {
|
|
@@ -874,8 +964,8 @@ function sameHeadShape(a, b) {
|
|
|
874
964
|
}
|
|
875
965
|
return tall;
|
|
876
966
|
}
|
|
877
|
-
function mergeCrossPageTables(blocks, pageHeights) {
|
|
878
|
-
mergeColumnFlow(blocks, pageHeights);
|
|
967
|
+
function mergeCrossPageTables(blocks, pageHeights, lex) {
|
|
968
|
+
mergeColumnFlow(blocks, pageHeights, lex);
|
|
879
969
|
for (let i = blocks.length - 2; i >= 0; i--) {
|
|
880
970
|
const prev = blocks[i];
|
|
881
971
|
if (prev.type !== "table" || !prev.table || !prev.bbox || !prev.pageNumber) continue;
|
|
@@ -884,24 +974,24 @@ function mergeCrossPageTables(blocks, pageHeights) {
|
|
|
884
974
|
const curr = blocks[j];
|
|
885
975
|
if (!curr || curr.type !== "table" || !curr.table || !curr.bbox || curr.pageNumber !== prev.pageNumber + 1) continue;
|
|
886
976
|
if (startsWithUnitRow(prev.table) && startsWithUnitRow(curr.table)) continue;
|
|
887
|
-
const joined = j === i + 1 || blocks.slice(i + 1, j).every((b) => besideOwn(b, prev, curr) || insideTable(b, prev)) ? looksContinued(prev, curr, pageHeights) && !restartsTable(blocks, i, curr.table, pageHeights) ? _nullishCoalesce(joinClipParts(prev, curr, pageHeights), () => ( false)) : null : null;
|
|
977
|
+
const joined = j === i + 1 || blocks.slice(i + 1, j).every((b) => besideOwn(b, prev, curr) || insideTable(b, prev)) ? looksContinued(prev, curr, pageHeights) && !restartsTable(blocks, i, curr.table, pageHeights) ? _nullishCoalesce(joinClipParts(prev, curr, pageHeights, lex), () => ( false)) : null : null;
|
|
888
978
|
if (joined) {
|
|
889
979
|
placeJoined(blocks, i, j, joined);
|
|
890
980
|
continue;
|
|
891
981
|
}
|
|
892
|
-
if (
|
|
982
|
+
if (_chunkWDQTFAXYcjs.EMPTY_PARTS.has(curr.table)) {
|
|
893
983
|
blocks.splice(j, 1);
|
|
894
984
|
i++;
|
|
895
985
|
continue;
|
|
896
986
|
}
|
|
897
987
|
if (joined === null) continue;
|
|
898
|
-
if (prev.table.cols !== curr.table.cols || prev.table.renderAsTable !== curr.table.renderAsTable ||
|
|
988
|
+
if (prev.table.cols !== curr.table.cols || prev.table.renderAsTable !== curr.table.renderAsTable || _chunkWDQTFAXYcjs.EMPTY_PARTS.has(prev.table)) continue;
|
|
899
989
|
const width = Math.max(prev.bbox.width, curr.bbox.width, 1);
|
|
900
990
|
const leftDiff = Math.abs(prev.bbox.x - curr.bbox.x);
|
|
901
991
|
const rightDiff = Math.abs(prev.bbox.x + prev.bbox.width - (curr.bbox.x + curr.bbox.width));
|
|
902
992
|
if (leftDiff > width * NEIGHBOR_TABLE_EPSILON || rightDiff > width * NEIGHBOR_TABLE_EPSILON) continue;
|
|
903
|
-
const px =
|
|
904
|
-
if (px && cx && !shiftedSame(px, cx, !
|
|
993
|
+
const px = _chunkWDQTFAXYcjs.TABLE_COLXS.get(prev.table), cx = _chunkWDQTFAXYcjs.TABLE_COLXS.get(curr.table);
|
|
994
|
+
if (px && cx && !shiftedSame(px, cx, !_chunkWDQTFAXYcjs.CLIP_TABLES.has(prev.table) && !_chunkWDQTFAXYcjs.CLIP_TABLES.has(curr.table))) continue;
|
|
905
995
|
if (!rowTextsEqual(prev.table.cells[0], curr.table.cells[0]) && sameHeadShape(prev.table.cells[0], curr.table.cells[0])) continue;
|
|
906
996
|
let currCells = curr.table.cells;
|
|
907
997
|
if (currCells.length > 1 && prev.table.cells.length > 0 && rowTextsEqual(prev.table.cells[0], currCells[0])) {
|
|
@@ -919,20 +1009,20 @@ function mergeCrossPageTables(blocks, pageHeights) {
|
|
|
919
1009
|
caption: prev.table.caption,
|
|
920
1010
|
...prev.table.renderAsTable ? { renderAsTable: true } : {}
|
|
921
1011
|
};
|
|
922
|
-
if (_nullishCoalesce(px, () => ( cx)))
|
|
923
|
-
if (
|
|
1012
|
+
if (_nullishCoalesce(px, () => ( cx))) _chunkWDQTFAXYcjs.TABLE_COLXS.set(merged, _nullishCoalesce(px, () => ( cx)));
|
|
1013
|
+
if (_chunkWDQTFAXYcjs.CLIP_TABLES.has(prev.table) || _chunkWDQTFAXYcjs.CLIP_TABLES.has(curr.table)) _chunkWDQTFAXYcjs.CLIP_TABLES.add(merged);
|
|
924
1014
|
placeJoined(blocks, i, j, merged);
|
|
925
1015
|
}
|
|
926
1016
|
for (let i = blocks.length - 1; i >= 0; i--) {
|
|
927
1017
|
const t = blocks[i].table;
|
|
928
|
-
if (blocks[i].type === "table" && t &&
|
|
1018
|
+
if (blocks[i].type === "table" && t && _chunkWDQTFAXYcjs.EMPTY_PARTS.has(t)) blocks.splice(i, 1);
|
|
929
1019
|
}
|
|
930
1020
|
}
|
|
931
|
-
function mergeColumnFlow(blocks, pageHeights) {
|
|
1021
|
+
function mergeColumnFlow(blocks, pageHeights, lex) {
|
|
932
1022
|
if (!pageHeights) return;
|
|
933
1023
|
for (let i = 0; i < blocks.length; i++) {
|
|
934
1024
|
const L = blocks[i];
|
|
935
|
-
if (L.type !== "table" || !L.table || !L.bbox || !L.pageNumber || !
|
|
1025
|
+
if (L.type !== "table" || !L.table || !L.bbox || !L.pageNumber || !_chunkWDQTFAXYcjs.CLIP_TABLES.has(L.table) || _chunkWDQTFAXYcjs.EMPTY_PARTS.has(L.table)) continue;
|
|
936
1026
|
const ph = pageHeights.get(L.pageNumber);
|
|
937
1027
|
if (!ph || L.bbox.y > ph * PAGE_EDGE_BAND) continue;
|
|
938
1028
|
let s0 = i, s1 = i;
|
|
@@ -950,7 +1040,7 @@ function mergeColumnFlow(blocks, pageHeights) {
|
|
|
950
1040
|
const R = blocks[k];
|
|
951
1041
|
if (Math.abs(R.bbox.width - L.bbox.width) > Math.max(R.bbox.width, L.bbox.width) * NEIGHBOR_TABLE_EPSILON) continue;
|
|
952
1042
|
if (!looksContinued(L, R) || restartsTable(blocks, i, R.table, pageHeights)) continue;
|
|
953
|
-
const joined = joinClipParts(L, R, pageHeights);
|
|
1043
|
+
const joined = joinClipParts(L, R, pageHeights, lex);
|
|
954
1044
|
if (!joined) continue;
|
|
955
1045
|
const top = L.bbox.y + L.bbox.height;
|
|
956
1046
|
const at = Math.min(i, k);
|
|
@@ -959,12 +1049,12 @@ function mergeColumnFlow(blocks, pageHeights) {
|
|
|
959
1049
|
i = at - 1;
|
|
960
1050
|
}
|
|
961
1051
|
}
|
|
962
|
-
function joinClipParts(prev, curr, pageHeights) {
|
|
1052
|
+
function joinClipParts(prev, curr, pageHeights, lex) {
|
|
963
1053
|
const pt = prev.table, ct = curr.table;
|
|
964
|
-
if (!
|
|
965
|
-
const px =
|
|
1054
|
+
if (!_chunkWDQTFAXYcjs.CLIP_TABLES.has(pt) || !_chunkWDQTFAXYcjs.CLIP_TABLES.has(ct)) return null;
|
|
1055
|
+
const px = _chunkWDQTFAXYcjs.TABLE_COLXS.get(pt), cx = _chunkWDQTFAXYcjs.TABLE_COLXS.get(ct);
|
|
966
1056
|
if (!px || !cx) return null;
|
|
967
|
-
let xs = cx, shifted = false, dx = 0;
|
|
1057
|
+
let xs = cx, shifted = false, dx = 0, foreign = false;
|
|
968
1058
|
if (!shiftedSame(px, cx, false)) {
|
|
969
1059
|
if (!_optionalChain([pageHeights, 'optionalAccess', _54 => _54.get, 'call', _55 => _55(prev.pageNumber)]) || !_optionalChain([pageHeights, 'optionalAccess', _56 => _56.get, 'call', _57 => _57(curr.pageNumber)])) return null;
|
|
970
1060
|
dx = px[px.length - 1] - cx[cx.length - 1];
|
|
@@ -973,22 +1063,32 @@ function joinClipParts(prev, curr, pageHeights) {
|
|
|
973
1063
|
shifted = true;
|
|
974
1064
|
} else dx = 0;
|
|
975
1065
|
if (!px.some((x) => Math.abs(x - xs[0]) <= CONTINUATION_COL_TOL)) return null;
|
|
1066
|
+
const inner = xs.slice(1, -1);
|
|
1067
|
+
foreign = inner.length > 0 && !inner.some((x) => px.some((p) => Math.abs(p - x) <= CONTINUATION_COL_TOL)) && headingRow(_nullishCoalesce(ct.cells[0], () => ( [])));
|
|
976
1068
|
}
|
|
977
|
-
const res = joinSplitParts(pt, px, ct, xs, dx, _optionalChain([prev, 'access', _58 => _58.bbox, 'optionalAccess', _59 => _59.y]));
|
|
978
|
-
if (!res || shifted && !res.split && !res.header) return null;
|
|
979
|
-
|
|
980
|
-
|
|
1069
|
+
const res = joinSplitParts(pt, px, ct, xs, dx, _optionalChain([prev, 'access', _58 => _58.bbox, 'optionalAccess', _59 => _59.y]), lex);
|
|
1070
|
+
if (!res || (shifted || foreign) && !res.split && !res.header) return null;
|
|
1071
|
+
_chunkWDQTFAXYcjs.TABLE_COLXS.set(res.table, res.colXs);
|
|
1072
|
+
_chunkWDQTFAXYcjs.CLIP_TABLES.add(res.table);
|
|
981
1073
|
return res.table;
|
|
982
1074
|
}
|
|
1075
|
+
function headingRow(row) {
|
|
1076
|
+
const heads = row.map((c) => c.text.replace(/\s+/g, "")).filter(Boolean);
|
|
1077
|
+
if (heads.length === 1) return heads[0].length <= 8 || /^[①-⑳❶-❿]/.test(heads[0]);
|
|
1078
|
+
return heads.length === 2 && /^(?:\d{1,2}|[ⅠⅡⅢⅣⅤⅥⅦⅧⅨⅩ]+|[①-⑳❶-❿])$/.test(heads[0]);
|
|
1079
|
+
}
|
|
983
1080
|
var ANNEX_HEAD_RE = /^\s*[<\[(【]?\s*(?:붙\s*임|참\s*고|별\s*첨|별\s*지|별\s*표|첨\s*부|부\s*록)(?:\s*\d|\s*$|\s*[>\])】])|^\s*■/;
|
|
984
1081
|
function looksContinued(prev, curr, pageHeights) {
|
|
985
1082
|
const ph = _optionalChain([pageHeights, 'optionalAccess', _60 => _60.get, 'call', _61 => _61(prev.pageNumber)]), ch = _optionalChain([pageHeights, 'optionalAccess', _62 => _62.get, 'call', _63 => _63(curr.pageNumber)]);
|
|
986
1083
|
if (ph && ch && (prev.bbox.y > ph * PAGE_EDGE_BAND || curr.bbox.y + curr.bbox.height < ch * (1 - PAGE_EDGE_BAND))) return false;
|
|
987
|
-
const
|
|
988
|
-
|
|
1084
|
+
const firstRow = _nullishCoalesce(curr.table.cells[0], () => ( []));
|
|
1085
|
+
const firstText = _nullishCoalesce(_optionalChain([firstRow, 'access', _64 => _64.find, 'call', _65 => _65((c) => c.text.trim()), 'optionalAccess', _66 => _66.text]), () => ( ""));
|
|
1086
|
+
if (!ANNEX_HEAD_RE.test(firstText)) return true;
|
|
1087
|
+
const filled = firstRow.map((c) => c.text.replace(/\s+/g, "")).filter(Boolean);
|
|
1088
|
+
return filled.length >= 2 && filled.every((t) => t === filled[0]);
|
|
989
1089
|
}
|
|
990
1090
|
function firstRowSig(t) {
|
|
991
|
-
const x =
|
|
1091
|
+
const x = _chunkWDQTFAXYcjs.TABLE_COLXS.get(t);
|
|
992
1092
|
if (!x || x.length !== t.cols + 1) return null;
|
|
993
1093
|
return anchorsOf(t).filter((a) => a.r === 0).map((a) => ({ x1: x[a.c], x2: x[a.c + a.cs], t: a.cell.text.replace(/\s+/g, "") }));
|
|
994
1094
|
}
|
|
@@ -998,6 +1098,7 @@ function restartsTable(blocks, i, curr, pageHeights) {
|
|
|
998
1098
|
const head = blocks[chainHead(blocks, i, pageHeights)].table;
|
|
999
1099
|
if (cs.length === 1 && restartsTitledForm(head, curr)) return true;
|
|
1000
1100
|
if (cs.length < RESTART_MIN_ANCHORS) return false;
|
|
1101
|
+
if (CONTACT_HEAD.test(cs[0].t) && cs.some((c) => CONTACT_ROLE.test(c.t))) return false;
|
|
1001
1102
|
const hs = firstRowSig(head);
|
|
1002
1103
|
if (!hs || hs.length !== cs.length) return false;
|
|
1003
1104
|
const dx = hs[hs.length - 1].x2 - cs[cs.length - 1].x2;
|
|
@@ -1012,9 +1113,9 @@ function restartsTable(blocks, i, curr, pageHeights) {
|
|
|
1012
1113
|
}
|
|
1013
1114
|
function restartsTitledForm(head, curr) {
|
|
1014
1115
|
if (head.rows < 2 || curr.rows < 2 || head.cols !== curr.cols) return false;
|
|
1015
|
-
const full = (t) => _optionalChain([t, 'access',
|
|
1116
|
+
const full = (t) => _optionalChain([t, 'access', _67 => _67.cells, 'access', _68 => _68[0], 'access', _69 => _69[0], 'optionalAccess', _70 => _70.colSpan]) === t.cols;
|
|
1016
1117
|
if (!full(head) || !full(curr)) return false;
|
|
1017
|
-
const norm = (c) => (_nullishCoalesce(_optionalChain([c, 'optionalAccess',
|
|
1118
|
+
const norm = (c) => (_nullishCoalesce(_optionalChain([c, 'optionalAccess', _71 => _71.text]), () => ( ""))).replace(/\s+/g, "");
|
|
1018
1119
|
const ht = norm(head.cells[0][0]), ct = norm(curr.cells[0][0]);
|
|
1019
1120
|
if (!ht || !ct || ht === ct) return false;
|
|
1020
1121
|
const titleLike = (t) => t.length <= TITLE_ROW_MAX_CHARS && !/^[ㅇ○◦•·\-–※*□■▪☞]/.test(t);
|
|
@@ -1040,7 +1141,7 @@ function chainHead(blocks, i, pageHeights) {
|
|
|
1040
1141
|
if (pb.pageNumber !== (_nullishCoalesce(cur.pageNumber, () => ( 0))) - 1) break;
|
|
1041
1142
|
if (!blocks.slice(p + 1, k).every((b) => besideOwn(b, pb, cur) || insideTable(b, pb))) break;
|
|
1042
1143
|
if (!looksContinued(pb, cur, pageHeights)) break;
|
|
1043
|
-
const px =
|
|
1144
|
+
const px = _chunkWDQTFAXYcjs.TABLE_COLXS.get(pb.table), cx = _chunkWDQTFAXYcjs.TABLE_COLXS.get(cur.table);
|
|
1044
1145
|
if (!px || !cx) break;
|
|
1045
1146
|
const dx = px[px.length - 1] - cx[cx.length - 1];
|
|
1046
1147
|
if (!shiftedSame(px, cx) && !px.some((x) => Math.abs(x - (cx[0] + dx)) <= CONTINUATION_COL_TOL)) break;
|
|
@@ -1071,12 +1172,12 @@ var RESTART_LOOKBACK_PAGES = 5;
|
|
|
1071
1172
|
var COL_MATCH_TOL = 0.5;
|
|
1072
1173
|
var CONTINUED_TABLE_PAGE_BAND = 0.16;
|
|
1073
1174
|
function lastRowCell(t, x1, x2) {
|
|
1074
|
-
const xs =
|
|
1175
|
+
const xs = _chunkWDQTFAXYcjs.TABLE_COLXS.get(t);
|
|
1075
1176
|
const covered = /* @__PURE__ */ new Set();
|
|
1076
1177
|
for (let r = 0; r < t.rows; r++) {
|
|
1077
1178
|
for (let c = 0; c < t.cols; c++) {
|
|
1078
1179
|
if (covered.has(r * 1e5 + c)) continue;
|
|
1079
|
-
const cell = _optionalChain([t, 'access',
|
|
1180
|
+
const cell = _optionalChain([t, 'access', _72 => _72.cells, 'access', _73 => _73[r], 'optionalAccess', _74 => _74[c]]);
|
|
1080
1181
|
if (!cell) continue;
|
|
1081
1182
|
for (let dr = 0; dr < cell.rowSpan; dr++) for (let dc = 0; dc < cell.colSpan; dc++) covered.add((r + dr) * 1e5 + c + dc);
|
|
1082
1183
|
if (r + cell.rowSpan !== t.rows) continue;
|
|
@@ -1089,19 +1190,19 @@ var cellBlocks = (cell, pageNumber) => _nullishCoalesce(cell.blocks, () => ( cel
|
|
|
1089
1190
|
function mergeContinuedCells(blocks, pageHeights) {
|
|
1090
1191
|
for (let j = blocks.length - 1; j > 0; j--) {
|
|
1091
1192
|
const part = blocks[j];
|
|
1092
|
-
const from = part.table ?
|
|
1193
|
+
const from = part.table ? _chunkWDQTFAXYcjs.CONT_PARTS.get(part.table) : void 0;
|
|
1093
1194
|
if (!from || !part.table) continue;
|
|
1094
1195
|
let i = j - 1;
|
|
1095
1196
|
while (i >= 0 && blocks[i].type !== "table") i--;
|
|
1096
1197
|
const prev = blocks[i];
|
|
1097
1198
|
if (i < 0 || !prev.table || prev.pageNumber !== (_nullishCoalesce(part.pageNumber, () => ( 0))) - 1) continue;
|
|
1098
1199
|
const cell = lastRowCell(prev.table, from.x1, from.x2);
|
|
1099
|
-
const add = _optionalChain([part, 'access',
|
|
1200
|
+
const add = _optionalChain([part, 'access', _75 => _75.table, 'access', _76 => _76.cells, 'access', _77 => _77[0], 'optionalAccess', _78 => _78[0]]);
|
|
1100
1201
|
if (!cell || !add) continue;
|
|
1101
1202
|
const at = cell.blocks || add.blocks ? cellBlocks(cell, prev.pageNumber).length : -1;
|
|
1102
1203
|
if (cell.blocks || add.blocks) cell.blocks = [...cellBlocks(cell, prev.pageNumber), ...cellBlocks(add, part.pageNumber)];
|
|
1103
1204
|
cell.text = [cell.text, add.text].filter((s) => s.trim()).join("\n");
|
|
1104
|
-
if (cell.text.trim() || _optionalChain([cell, 'access',
|
|
1205
|
+
if (cell.text.trim() || _optionalChain([cell, 'access', _79 => _79.blocks, 'optionalAccess', _80 => _80.length])) _chunkWDQTFAXYcjs.EMPTY_PARTS.delete(prev.table);
|
|
1105
1206
|
blocks.splice(j, 1);
|
|
1106
1207
|
if (cell.blocks && at > 0) {
|
|
1107
1208
|
const nextAt = cell.blocks[at];
|
|
@@ -1113,24 +1214,24 @@ function mergeContinuedCells(blocks, pageHeights) {
|
|
|
1113
1214
|
}
|
|
1114
1215
|
function unwrapContinuedTable(blocks, at, pageHeights) {
|
|
1115
1216
|
const prev = blocks[at - 1], frame = blocks[at];
|
|
1116
|
-
if (!_optionalChain([prev, 'optionalAccess',
|
|
1117
|
-
const inner = _optionalChain([frame, 'access',
|
|
1118
|
-
const next = _optionalChain([inner, 'optionalAccess',
|
|
1119
|
-
if (!inner || !_optionalChain([next, 'optionalAccess',
|
|
1120
|
-
const px =
|
|
1217
|
+
if (!_optionalChain([prev, 'optionalAccess', _81 => _81.table]) || !_optionalChain([frame, 'optionalAccess', _82 => _82.table]) || frame.table.rows !== 1 || frame.table.cols !== 1 || !_chunkWDQTFAXYcjs.CLIP_TABLES.has(frame.table)) return;
|
|
1218
|
+
const inner = _optionalChain([frame, 'access', _83 => _83.table, 'access', _84 => _84.cells, 'access', _85 => _85[0], 'optionalAccess', _86 => _86[0], 'optionalAccess', _87 => _87.blocks]);
|
|
1219
|
+
const next = _optionalChain([inner, 'optionalAccess', _88 => _88[0]]);
|
|
1220
|
+
if (!inner || !_optionalChain([next, 'optionalAccess', _89 => _89.table]) || !prev.bbox || !next.bbox || !prev.pageNumber || next.pageNumber !== prev.pageNumber + 1 || !_chunkWDQTFAXYcjs.CLIP_TABLES.has(prev.table) || !_chunkWDQTFAXYcjs.CLIP_TABLES.has(next.table) || prev.table.cols !== next.table.cols) return;
|
|
1221
|
+
const px = _chunkWDQTFAXYcjs.TABLE_COLXS.get(prev.table), nx = _chunkWDQTFAXYcjs.TABLE_COLXS.get(next.table);
|
|
1121
1222
|
if (!px || !nx || px.length !== nx.length || px.some((x, i) => Math.abs(x - nx[i]) > COL_MATCH_TOL)) return;
|
|
1122
|
-
const ph = _optionalChain([pageHeights, 'optionalAccess',
|
|
1223
|
+
const ph = _optionalChain([pageHeights, 'optionalAccess', _90 => _90.get, 'call', _91 => _91(prev.pageNumber)]), nh = _optionalChain([pageHeights, 'optionalAccess', _92 => _92.get, 'call', _93 => _93(next.pageNumber)]);
|
|
1123
1224
|
if (!ph || !nh || prev.bbox.y > ph * CONTINUED_TABLE_PAGE_BAND || next.bbox.y + next.bbox.height < nh * (1 - CONTINUED_TABLE_PAGE_BAND)) return;
|
|
1124
1225
|
blocks.splice(at, 1, ...inner);
|
|
1125
1226
|
}
|
|
1126
1227
|
function fillNestedContinuation(blocks, at) {
|
|
1127
1228
|
const prev = blocks[at - 1], next = blocks[at];
|
|
1128
|
-
const t = _optionalChain([prev, 'optionalAccess',
|
|
1129
|
-
if (!t || !u || u.rows !== 1 || u.cols !== 1 || !
|
|
1130
|
-
const xs =
|
|
1229
|
+
const t = _optionalChain([prev, 'optionalAccess', _94 => _94.table]), u = _optionalChain([next, 'optionalAccess', _95 => _95.table]);
|
|
1230
|
+
if (!t || !u || u.rows !== 1 || u.cols !== 1 || !_chunkWDQTFAXYcjs.CLIP_TABLES.has(t) || !_chunkWDQTFAXYcjs.CLIP_TABLES.has(u) || next.pageNumber !== (_nullishCoalesce(prev.pageNumber, () => ( 0))) + 1) return;
|
|
1231
|
+
const xs = _chunkWDQTFAXYcjs.TABLE_COLXS.get(u);
|
|
1131
1232
|
const cell = xs ? lastRowCell(t, xs[0], xs[xs.length - 1]) : void 0;
|
|
1132
|
-
const add = _optionalChain([u, 'access',
|
|
1133
|
-
if (!cell || !add || cell.text.trim() || _optionalChain([cell, 'access',
|
|
1233
|
+
const add = _optionalChain([u, 'access', _96 => _96.cells, 'access', _97 => _97[0], 'optionalAccess', _98 => _98[0]]);
|
|
1234
|
+
if (!cell || !add || cell.text.trim() || _optionalChain([cell, 'access', _99 => _99.blocks, 'optionalAccess', _100 => _100.length])) return;
|
|
1134
1235
|
cell.text = add.text;
|
|
1135
1236
|
if (add.blocks) cell.blocks = add.blocks;
|
|
1136
1237
|
blocks.splice(at, 1);
|
|
@@ -1168,7 +1269,7 @@ var WINANSI_REVERSE = {
|
|
|
1168
1269
|
};
|
|
1169
1270
|
function symbolFontTable(fontName) {
|
|
1170
1271
|
if (!fontName) return void 0;
|
|
1171
|
-
if (/wingdings(?![\s-]*[23])/i.test(fontName)) return
|
|
1272
|
+
if (/wingdings(?![\s-]*[23])/i.test(fontName)) return _chunkXTFN5WKScjs.WINGDINGS;
|
|
1172
1273
|
return void 0;
|
|
1173
1274
|
}
|
|
1174
1275
|
function remapSymbolText(text, table) {
|
|
@@ -1296,7 +1397,7 @@ function layout(toks) {
|
|
|
1296
1397
|
const bar = rest.find((t) => t.bar && t.x >= rt.x && t.x <= rt.x + rt.w + 2 && Math.abs(t.y - rt.y) <= size * 1.5);
|
|
1297
1398
|
if (!bar) continue;
|
|
1298
1399
|
const inner = rest.filter((t) => !t.bar && t !== rt && t.x + t.w / 2 > bar.x && t.x + t.w / 2 < bar.x + bar.w && bar.y - t.y > 0 && bar.y - t.y <= size * 1.4);
|
|
1299
|
-
const tok = { text: `\\sqrt{${linear(inner)}}`, x: rt.x, w: bar.x + bar.w - rt.x, y: _nullishCoalesce(_optionalChain([inner, 'access',
|
|
1400
|
+
const tok = { text: `\\sqrt{${linear(inner)}}`, x: rt.x, w: bar.x + bar.w - rt.x, y: _nullishCoalesce(_optionalChain([inner, 'access', _101 => _101[0], 'optionalAccess', _102 => _102.y]), () => ( rt.y)), size: Math.max(rt.size, ...inner.map((t) => t.size)), bar: false };
|
|
1300
1401
|
rest = [...rest.filter((t) => t !== rt && t !== bar && !inner.includes(t)), tok];
|
|
1301
1402
|
}
|
|
1302
1403
|
const bars = rest.filter((t) => t.bar).sort((a, b) => a.w - b.w);
|
|
@@ -1398,7 +1499,7 @@ function wrapEquationRuns(items, faceName) {
|
|
|
1398
1499
|
for (const i of mains) ys.set(i.y, (_nullishCoalesce(ys.get(i.y), () => ( 0))) + 1);
|
|
1399
1500
|
const top = [...ys].sort((p, q) => q[1] - p[1]);
|
|
1400
1501
|
const bar = cur.find(isBarItem);
|
|
1401
|
-
const lineY = bar && top.length > 1 && top[0][1] === top[1][1] ? Math.round(bar.y + size * 0.3) : _nullishCoalesce(_optionalChain([top, 'access',
|
|
1502
|
+
const lineY = bar && top.length > 1 && top[0][1] === top[1][1] ? Math.round(bar.y + size * 0.3) : _nullishCoalesce(_optionalChain([top, 'access', _103 => _103[0], 'optionalAccess', _104 => _104[0]]), () => ( cur[0].y));
|
|
1402
1503
|
const base = { ..._nullishCoalesce(mains[0], () => ( cur[0])), y: lineY, fontSize: size || cur[0].fontSize };
|
|
1403
1504
|
const x1 = Math.min(...cur.map((i) => i.x)), x2 = Math.max(...cur.map((i) => i.x + i.w));
|
|
1404
1505
|
added.push({ ...base, text: `$${tex}$`, x: x1, w: x2 - x1, hasSpaceBefore: true });
|
|
@@ -1744,7 +1845,7 @@ function joinVerticalColumns(items) {
|
|
|
1744
1845
|
const groups = [];
|
|
1745
1846
|
for (const col of columns) {
|
|
1746
1847
|
const g2 = groups[groups.length - 1];
|
|
1747
|
-
const last = _optionalChain([g2, 'optionalAccess',
|
|
1848
|
+
const last = _optionalChain([g2, 'optionalAccess', _105 => _105[g2.length - 1]]);
|
|
1748
1849
|
const fs = col.items[0].fontSize;
|
|
1749
1850
|
if (last && last.x - col.x >= fs * 1.2 && last.x - col.x <= fs * 4 && Math.abs(last.items[0].y - col.items[0].y) <= fs * 1.2) g2.push(col);
|
|
1750
1851
|
else groups.push([col]);
|
|
@@ -1844,6 +1945,52 @@ function restoreTrackedSpacing(items, fnArray, argsArray) {
|
|
|
1844
1945
|
}
|
|
1845
1946
|
return changed;
|
|
1846
1947
|
}
|
|
1948
|
+
function markSyntheticSpaces(items, fnArray, argsArray) {
|
|
1949
|
+
if (!items.some((it) => typeof it.str === "string" && it.str.length > 0 && !it.str.trim())) return;
|
|
1950
|
+
const streams = /* @__PURE__ */ new Map();
|
|
1951
|
+
const saved = [];
|
|
1952
|
+
let font = "";
|
|
1953
|
+
for (let i = 0; i < fnArray.length; i++) {
|
|
1954
|
+
const fn = fnArray[i];
|
|
1955
|
+
const args = argsArray[i];
|
|
1956
|
+
if (fn === _pdfmjs.OPS.setFont) font = String(args[0]);
|
|
1957
|
+
else if (fn === _pdfmjs.OPS.save || fn === _pdfmjs.OPS.paintFormXObjectBegin) saved.push(font);
|
|
1958
|
+
else if (fn === _pdfmjs.OPS.restore || fn === _pdfmjs.OPS.paintFormXObjectEnd) font = _nullishCoalesce(saved.pop(), () => ( font));
|
|
1959
|
+
else if (fn === _pdfmjs.OPS.showText) {
|
|
1960
|
+
let list = streams.get(font);
|
|
1961
|
+
if (!list) streams.set(font, list = []);
|
|
1962
|
+
for (const g2 of args[0]) {
|
|
1963
|
+
if (g2 && typeof g2 === "object" && typeof g2.unicode === "string") list.push(_pdfmjs.normalizeUnicode.call(void 0, g2.unicode));
|
|
1964
|
+
}
|
|
1965
|
+
}
|
|
1966
|
+
}
|
|
1967
|
+
const cursor = /* @__PURE__ */ new Map();
|
|
1968
|
+
const failed = /* @__PURE__ */ new Set();
|
|
1969
|
+
const marks = [];
|
|
1970
|
+
for (const it of items) {
|
|
1971
|
+
const f = _nullishCoalesce(it.fontName, () => ( ""));
|
|
1972
|
+
const glyphs = streams.get(f);
|
|
1973
|
+
if (!glyphs || failed.has(f) || typeof it.str !== "string" || !it.str) continue;
|
|
1974
|
+
let gi = _nullishCoalesce(cursor.get(f), () => ( 0));
|
|
1975
|
+
if (!it.str.trim()) {
|
|
1976
|
+
if (gi < glyphs.length && /^\s+$/.test(glyphs[gi])) {
|
|
1977
|
+
while (gi < glyphs.length && /^\s+$/.test(glyphs[gi])) gi++;
|
|
1978
|
+
cursor.set(f, gi);
|
|
1979
|
+
} else marks.push(it);
|
|
1980
|
+
continue;
|
|
1981
|
+
}
|
|
1982
|
+
const want = it.str.replace(/\s+/g, "");
|
|
1983
|
+
while (gi < glyphs.length && /^\s*$/.test(glyphs[gi])) gi++;
|
|
1984
|
+
let got = "";
|
|
1985
|
+
while (gi < glyphs.length && got.length < want.length) got += glyphs[gi++].replace(/\s+/g, "");
|
|
1986
|
+
if (got !== want) {
|
|
1987
|
+
failed.add(f);
|
|
1988
|
+
continue;
|
|
1989
|
+
}
|
|
1990
|
+
cursor.set(f, gi);
|
|
1991
|
+
}
|
|
1992
|
+
for (const it of marks) if (!failed.has(_nullishCoalesce(it.fontName, () => ( "")))) it.synthetic = true;
|
|
1993
|
+
}
|
|
1847
1994
|
|
|
1848
1995
|
// src/pdf/endnotes.ts
|
|
1849
1996
|
var NOTE_MARK = /^\s*(문\d{1,5}[))]|\d{1,5}\)|\(\d{1,5}\))/;
|
|
@@ -1884,7 +2031,7 @@ function relocateEndnotes(blocks) {
|
|
|
1884
2031
|
}
|
|
1885
2032
|
const shapes = /* @__PURE__ */ new Map();
|
|
1886
2033
|
for (const h of heads) shapes.set(h.shape, (_nullishCoalesce(shapes.get(h.shape), () => ( 0))) + 1);
|
|
1887
|
-
const main = _optionalChain([[...shapes], 'access',
|
|
2034
|
+
const main = _optionalChain([[...shapes], 'access', _106 => _106.sort, 'call', _107 => _107((a, b) => b[1] - a[1]), 'access', _108 => _108[0], 'optionalAccess', _109 => _109[0]]);
|
|
1888
2035
|
if (!main || !/#/.test(main)) return blocks;
|
|
1889
2036
|
const lastRun = (hs) => {
|
|
1890
2037
|
let run2 = [];
|
|
@@ -1981,10 +2128,11 @@ function orderTwoUpPage(blocks, pageWidth, pageHeight) {
|
|
|
1981
2128
|
var BAND = 0.12;
|
|
1982
2129
|
var MAX_CHARS = 10;
|
|
1983
2130
|
var MIN_REPEAT = 3;
|
|
2131
|
+
var RUN_GAP = 5;
|
|
1984
2132
|
function removeSideTabs(blocks, pageWidths) {
|
|
1985
2133
|
const edges = /* @__PURE__ */ new Map();
|
|
1986
2134
|
for (const b of blocks) {
|
|
1987
|
-
if (!b.bbox || b.pageNumber === void 0 || [..._nullishCoalesce(_optionalChain([b, 'access',
|
|
2135
|
+
if (!b.bbox || b.pageNumber === void 0 || [..._nullishCoalesce(_optionalChain([b, 'access', _110 => _110.text, 'optionalAccess', _111 => _111.trim, 'call', _112 => _112()]), () => ( ""))].length <= MAX_CHARS) continue;
|
|
1988
2136
|
const e = _nullishCoalesce(edges.get(b.pageNumber), () => ( { lefts: [], rights: [] }));
|
|
1989
2137
|
e.lefts.push(b.bbox.x);
|
|
1990
2138
|
e.rights.push(b.bbox.x + b.bbox.width);
|
|
@@ -2000,7 +2148,7 @@ function removeSideTabs(blocks, pageWidths) {
|
|
|
2000
2148
|
const fallback = all.length ? { left: q(all.map((e) => e.left), 0.5), right: q(all.map((e) => e.right), 0.5) } : void 0;
|
|
2001
2149
|
const key = (b) => {
|
|
2002
2150
|
const w = b.pageNumber !== void 0 ? pageWidths.get(b.pageNumber) : void 0;
|
|
2003
|
-
const text = _optionalChain([b, 'access',
|
|
2151
|
+
const text = _optionalChain([b, 'access', _113 => _113.text, 'optionalAccess', _114 => _114.trim, 'call', _115 => _115()]);
|
|
2004
2152
|
const area = _nullishCoalesce((b.pageNumber !== void 0 ? body.get(b.pageNumber) : void 0), () => ( fallback));
|
|
2005
2153
|
if (!w || !area || !b.bbox || !text || b.type === "table" || [...text].length > MAX_CHARS) return null;
|
|
2006
2154
|
const side = b.bbox.x + b.bbox.width <= Math.min(w * BAND, area.left - 1) ? "L" : b.bbox.x >= Math.max(w * (1 - BAND), area.right + 1) ? "R" : null;
|
|
@@ -2013,13 +2161,21 @@ function removeSideTabs(blocks, pageWidths) {
|
|
|
2013
2161
|
}
|
|
2014
2162
|
const running = /* @__PURE__ */ new Set();
|
|
2015
2163
|
for (const [k, ps] of pages) {
|
|
2016
|
-
const list = [...ps];
|
|
2017
|
-
|
|
2018
|
-
|
|
2164
|
+
const list = [...ps].sort((a, b) => a - b);
|
|
2165
|
+
let run = [];
|
|
2166
|
+
const flush = () => {
|
|
2167
|
+
if (run.length >= MIN_REPEAT && run.length >= (run[run.length - 1] - run[0] + 1) * 0.4) for (const p of run) running.add(`${p}\0${k}`);
|
|
2168
|
+
run = [];
|
|
2169
|
+
};
|
|
2170
|
+
for (const p of list) {
|
|
2171
|
+
if (run.length && p - run[run.length - 1] > RUN_GAP) flush();
|
|
2172
|
+
run.push(p);
|
|
2173
|
+
}
|
|
2174
|
+
flush();
|
|
2019
2175
|
}
|
|
2020
2176
|
return running.size ? blocks.filter((b) => {
|
|
2021
2177
|
const k = key(b);
|
|
2022
|
-
return !k || !running.has(k);
|
|
2178
|
+
return !k || !running.has(`${b.pageNumber}\0${k}`);
|
|
2023
2179
|
}) : blocks;
|
|
2024
2180
|
}
|
|
2025
2181
|
|
|
@@ -2068,7 +2224,7 @@ function inlineFootnotes(blocks, pages) {
|
|
|
2068
2224
|
open = true;
|
|
2069
2225
|
continue;
|
|
2070
2226
|
}
|
|
2071
|
-
const prev = pb[j - 1], line = (_nullishCoalesce(_nullishCoalesce(_optionalChain([b, 'access',
|
|
2227
|
+
const prev = pb[j - 1], line = (_nullishCoalesce(_nullishCoalesce(_optionalChain([b, 'access', _116 => _116.style, 'optionalAccess', _117 => _117.fontSize]), () => ( _optionalChain([b, 'access', _118 => _118.bbox, 'optionalAccess', _119 => _119.height]))), () => ( 10))) * 1.5;
|
|
2072
2228
|
if (open && b.bbox && prev.bbox && prev.bbox.y - top(b) <= line && !/^[-–—\s\d]+$/.test(b.text)) {
|
|
2073
2229
|
notes[notes.length - 1].text += " " + b.text.trim();
|
|
2074
2230
|
notes[notes.length - 1].blocks.push(b);
|
|
@@ -2091,7 +2247,7 @@ var CAPTION = /^(?:Table|Figure|Fig\.?)\s*\d+(?:\.\d+)*\s*[.:]/i;
|
|
|
2091
2247
|
var EQUATION_NUMBER = /\t\(\d{1,3}[a-z]?\)\s*$/;
|
|
2092
2248
|
var DISPLAY_MATH = /=|[√∑∏∫∂∇≤≥≈≠∈∀∃]/;
|
|
2093
2249
|
function isRunningHead(block, page, pageHeight) {
|
|
2094
|
-
const box = block.bbox, text = _optionalChain([block, 'access',
|
|
2250
|
+
const box = block.bbox, text = _optionalChain([block, 'access', _120 => _120.text, 'optionalAccess', _121 => _121.trim, 'call', _122 => _122()]);
|
|
2095
2251
|
if (!box || !text || !pageHeight) return false;
|
|
2096
2252
|
const top = box.y + box.height >= pageHeight * 0.9;
|
|
2097
2253
|
const bottom = box.y <= pageHeight * 0.1;
|
|
@@ -2099,7 +2255,7 @@ function isRunningHead(block, page, pageHeight) {
|
|
|
2099
2255
|
const others = page.filter((o) => o !== block && o.bbox && o.type !== "image" && o.type !== "separator");
|
|
2100
2256
|
if (top && others.some((o) => o.bbox.y + o.bbox.height > box.y + box.height)) return false;
|
|
2101
2257
|
if (bottom && others.some((o) => o.bbox.y < box.y)) return false;
|
|
2102
|
-
if (bottom && box.height <= (_nullishCoalesce(_optionalChain([block, 'access',
|
|
2258
|
+
if (bottom && box.height <= (_nullishCoalesce(_optionalChain([block, 'access', _123 => _123.style, 'optionalAccess', _124 => _124.fontSize]), () => ( 0))) * 1.6) return true;
|
|
2103
2259
|
if (!text.includes(" ")) return false;
|
|
2104
2260
|
const parts = text.split(/\t+/).map((part) => part.trim()).filter(Boolean);
|
|
2105
2261
|
if (parts.length >= 2 && (PAGE_NUMBER.test(parts[0]) || PAGE_NUMBER.test(parts[parts.length - 1]))) return true;
|
|
@@ -2108,7 +2264,7 @@ function isRunningHead(block, page, pageHeight) {
|
|
|
2108
2264
|
return right > left && box.width >= (right - left) * 0.6;
|
|
2109
2265
|
}
|
|
2110
2266
|
function unbalancedClose(text) {
|
|
2111
|
-
return (_nullishCoalesce(_optionalChain([text, 'access',
|
|
2267
|
+
return (_nullishCoalesce(_optionalChain([text, 'access', _125 => _125.match, 'call', _126 => _126(/\)/g), 'optionalAccess', _127 => _127.length]), () => ( 0))) > (_nullishCoalesce(_optionalChain([text, 'access', _128 => _128.match, 'call', _129 => _129(/\(/g), 'optionalAccess', _130 => _130.length]), () => ( 0)));
|
|
2112
2268
|
}
|
|
2113
2269
|
function demoteNonHeadingRoles(blocks, pageHeights, faceNames) {
|
|
2114
2270
|
const byPage = /* @__PURE__ */ new Map();
|
|
@@ -2121,7 +2277,7 @@ function demoteNonHeadingRoles(blocks, pageHeights, faceNames) {
|
|
|
2121
2277
|
for (const [pageNumber, page] of byPage) {
|
|
2122
2278
|
const chars = /* @__PURE__ */ new Map();
|
|
2123
2279
|
for (const b of page) {
|
|
2124
|
-
if (b.type !== "paragraph" && b.type !== "heading" || !b.text || !_optionalChain([b, 'access',
|
|
2280
|
+
if (b.type !== "paragraph" && b.type !== "heading" || !b.text || !_optionalChain([b, 'access', _131 => _131.style, 'optionalAccess', _132 => _132.fontName]) || !b.style.fontSize) continue;
|
|
2125
2281
|
const key2 = `${b.style.fontName}:${b.style.fontSize}`;
|
|
2126
2282
|
chars.set(key2, (_nullishCoalesce(chars.get(key2), () => ( 0))) + b.text.length);
|
|
2127
2283
|
}
|
|
@@ -2132,48 +2288,48 @@ function demoteNonHeadingRoles(blocks, pageHeights, faceNames) {
|
|
|
2132
2288
|
const block = blocks[i];
|
|
2133
2289
|
if (block.type !== "heading" || !block.text) continue;
|
|
2134
2290
|
const text = block.text.replace(/<[^>]+>/g, "").trim();
|
|
2135
|
-
const fsz = _nullishCoalesce(_optionalChain([block, 'access',
|
|
2136
|
-
const tocEntry = i > 0 &&
|
|
2291
|
+
const fsz = _nullishCoalesce(_optionalChain([block, 'access', _133 => _133.style, 'optionalAccess', _134 => _134.fontSize]), () => ( 0));
|
|
2292
|
+
const tocEntry = i > 0 && _chunkWDQTFAXYcjs.TOC_BLOCKS.has(blocks[i - 1]) && _chunkWDQTFAXYcjs.TOC_BLOCKS.has(blocks[i + 1]);
|
|
2137
2293
|
const page = _nullishCoalesce(byPage.get(_nullishCoalesce(block.pageNumber, () => ( 0))), () => ( []));
|
|
2138
|
-
const proseStyle = _optionalChain([block, 'access',
|
|
2294
|
+
const proseStyle = _optionalChain([block, 'access', _135 => _135.style, 'optionalAccess', _136 => _136.fontName]) && bodyStyle.get(_nullishCoalesce(block.pageNumber, () => ( 0))) === `${block.style.fontName}:${block.style.fontSize}` && text.length > 60;
|
|
2139
2295
|
const next = blocks[i + 1];
|
|
2140
|
-
const nb = _optionalChain([next, 'optionalAccess',
|
|
2141
|
-
const chapterNumber = !!nb && !!bb && fsz >= (_nullishCoalesce(_optionalChain([next, 'optionalAccess',
|
|
2142
|
-
if (/^\d+(?:\.\d+)*\.?$/.test(text) && _optionalChain([next, 'optionalAccess',
|
|
2296
|
+
const nb = _optionalChain([next, 'optionalAccess', _137 => _137.bbox]), bb = block.bbox;
|
|
2297
|
+
const chapterNumber = !!nb && !!bb && fsz >= (_nullishCoalesce(_optionalChain([next, 'optionalAccess', _138 => _138.style, 'optionalAccess', _139 => _139.fontSize]), () => ( 0))) * 1.2 && Math.abs(bb.x - nb.x) > fsz && Math.abs(bb.x + bb.width / 2 - (nb.x + nb.width / 2)) < nb.width * 0.1;
|
|
2298
|
+
if (/^\d+(?:\.\d+)*\.?$/.test(text) && _optionalChain([next, 'optionalAccess', _140 => _140.type]) === "heading" && next.text && next.pageNumber === block.pageNumber && !chapterNumber) {
|
|
2143
2299
|
next.text = `${block.text.trim()} ${next.text.trim()}`;
|
|
2144
2300
|
blocks.splice(i--, 1);
|
|
2145
2301
|
continue;
|
|
2146
2302
|
}
|
|
2147
|
-
if ((_optionalChain([next, 'optionalAccess',
|
|
2303
|
+
if ((_optionalChain([next, 'optionalAccess', _141 => _141.type]) === "paragraph" || _optionalChain([next, 'optionalAccess', _142 => _142.type]) === "heading" && !CAPTION.test(text)) && next.pageNumber === block.pageNumber && next.text && next.bbox && block.bbox && _optionalChain([next, 'access', _143 => _143.style, 'optionalAccess', _144 => _144.fontName]) === _optionalChain([block, 'access', _145 => _145.style, 'optionalAccess', _146 => _146.fontName]) && _optionalChain([next, 'access', _147 => _147.style, 'optionalAccess', _148 => _148.fontSize]) === _optionalChain([block, 'access', _149 => _149.style, 'optionalAccess', _150 => _150.fontSize]) && fsz > 0 && /^[a-z]/.test(next.text.trim()) && next.text.trim().length <= 40 && !/[.:;!?]$/.test(next.text.trim()) && block.bbox.y - (next.bbox.y + next.bbox.height) < fsz * 1.2 && Math.abs(next.bbox.x - block.bbox.x) < fsz) {
|
|
2148
2304
|
block.text = `${block.text.trim()} ${next.text.trim()}`;
|
|
2149
2305
|
block.bbox = { ...block.bbox, y: next.bbox.y, height: block.bbox.y + block.bbox.height - next.bbox.y };
|
|
2150
2306
|
blocks.splice(i + 1, 1);
|
|
2151
2307
|
}
|
|
2152
2308
|
const after = blocks[i + 2];
|
|
2153
|
-
if ((_optionalChain([next, 'optionalAccess',
|
|
2309
|
+
if ((_optionalChain([next, 'optionalAccess', _151 => _151.type]) === "paragraph" || _optionalChain([next, 'optionalAccess', _152 => _152.type]) === "heading") && /^(?:&|\+|and|or)$/i.test(_nullishCoalesce(_optionalChain([next, 'access', _153 => _153.text, 'optionalAccess', _154 => _154.trim, 'call', _155 => _155()]), () => ( ""))) && _optionalChain([after, 'optionalAccess', _156 => _156.type]) === "heading" && after.text && after.pageNumber === block.pageNumber && next.pageNumber === block.pageNumber && _optionalChain([after, 'access', _157 => _157.style, 'optionalAccess', _158 => _158.fontSize]) === _optionalChain([block, 'access', _159 => _159.style, 'optionalAccess', _160 => _160.fontSize])) {
|
|
2154
2310
|
block.text = `${block.text.trim()} ${next.text.trim()} ${after.text.trim()}`;
|
|
2155
2311
|
blocks.splice(i + 1, 2);
|
|
2156
2312
|
}
|
|
2157
2313
|
const tiny = fsz > 0 && fsz < 7.5;
|
|
2158
2314
|
const prev = blocks[i - 1];
|
|
2159
|
-
if (_optionalChain([prev, 'optionalAccess',
|
|
2315
|
+
if (_optionalChain([prev, 'optionalAccess', _161 => _161.type]) === "paragraph" && prev.pageNumber === block.pageNumber && /^[a-z]{1,3}[.)]$/.test(_nullishCoalesce(_optionalChain([prev, 'access', _162 => _162.text, 'optionalAccess', _163 => _163.trim, 'call', _164 => _164()]), () => ( ""))) && prev.bbox && block.bbox && Math.abs(prev.bbox.y - block.bbox.y) < 2 && prev.bbox.x + prev.bbox.width <= block.bbox.x) {
|
|
2160
2316
|
prev.text = `${prev.text.trim()} ${block.text.trim()}`;
|
|
2161
2317
|
prev.bbox = { ...prev.bbox, width: block.bbox.x + block.bbox.width - prev.bbox.x };
|
|
2162
2318
|
blocks.splice(i--, 1);
|
|
2163
2319
|
continue;
|
|
2164
2320
|
}
|
|
2165
|
-
if (_optionalChain([prev, 'optionalAccess',
|
|
2321
|
+
if (_optionalChain([prev, 'optionalAccess', _165 => _165.type]) === "paragraph" && prev.pageNumber === block.pageNumber && /^\d{1,2}(?:\.\d{1,2})*\.?$/.test(_nullishCoalesce(_optionalChain([prev, 'access', _166 => _166.text, 'optionalAccess', _167 => _167.trim, 'call', _168 => _168()]), () => ( ""))) && prev.bbox && block.bbox && fsz > 0 && (Math.abs(prev.bbox.y - block.bbox.y) < 2 && prev.bbox.x + prev.bbox.width <= block.bbox.x && block.bbox.x - (prev.bbox.x + prev.bbox.width) < fsz * 3 || Math.abs(prev.bbox.x - block.bbox.x) < 2 && (_nullishCoalesce(_optionalChain([prev, 'access', _169 => _169.style, 'optionalAccess', _170 => _170.fontSize]), () => ( 0))) >= fsz && prev.bbox.y - (block.bbox.y + block.bbox.height) < fsz * 1.5)) {
|
|
2166
2322
|
block.text = `${prev.text.trim()} ${block.text.trim()}`;
|
|
2167
2323
|
blocks.splice(i - 1, 1);
|
|
2168
2324
|
i -= 2;
|
|
2169
2325
|
continue;
|
|
2170
2326
|
}
|
|
2171
|
-
const box = block.bbox, size = _nullishCoalesce(_optionalChain([block, 'access',
|
|
2172
|
-
const kicker = !!box && size > 0 && _optionalChain([next, 'optionalAccess',
|
|
2173
|
-
const face = _nullishCoalesce(_optionalChain([faceNames, 'optionalAccess',
|
|
2327
|
+
const box = block.bbox, size = _nullishCoalesce(_optionalChain([block, 'access', _171 => _171.style, 'optionalAccess', _172 => _172.fontSize]), () => ( 0));
|
|
2328
|
+
const kicker = !!box && size > 0 && _optionalChain([next, 'optionalAccess', _173 => _173.type]) === "heading" && next.pageNumber === block.pageNumber && !!next.bbox && (_nullishCoalesce(_optionalChain([next, 'access', _174 => _174.style, 'optionalAccess', _175 => _175.fontSize]), () => ( 0))) >= size * 1.3 && box.y - (next.bbox.y + next.bbox.height) <= size * 3 && Math.min(box.x + box.width, next.bbox.x + next.bbox.width) - Math.max(box.x, next.bbox.x) >= Math.min(box.width, next.bbox.width) * 0.5 && !page.some((o) => o !== block && o.bbox && o.bbox.y > box.y + box.height && o.type !== "image");
|
|
2329
|
+
const face = _nullishCoalesce(_optionalChain([faceNames, 'optionalAccess', _176 => _176.get, 'call', _177 => _177(_nullishCoalesce(_optionalChain([block, 'access', _178 => _178.style, 'optionalAccess', _179 => _179.fontName]), () => ( "")))]), () => ( ""));
|
|
2174
2330
|
const [bodyFace, bodySize] = (_nullishCoalesce(bodyStyle.get(_nullishCoalesce(block.pageNumber, () => ( 0))), () => ( ""))).split(":");
|
|
2175
|
-
const byline = /Italic|Oblique/i.test(face) && !/Bold|Black|Heavy|Semibold/i.test(face) && !!bodyFace && size <= Number(bodySize) + 0.5 && _optionalChain([blocks, 'access',
|
|
2176
|
-
const ocrFragment = _optionalChain([block, 'access',
|
|
2331
|
+
const byline = /Italic|Oblique/i.test(face) && !/Bold|Black|Heavy|Semibold/i.test(face) && !!bodyFace && size <= Number(bodySize) + 0.5 && _optionalChain([blocks, 'access', _180 => _180[i - 1], 'optionalAccess', _181 => _181.type]) === "heading" && blocks[i - 1].pageNumber === block.pageNumber;
|
|
2332
|
+
const ocrFragment = _optionalChain([block, 'access', _182 => _182.style, 'optionalAccess', _183 => _183.fontName]) === "ocr" && (/^[.,;:…·•-]/.test(text) || text.includes("\u2026") || (_nullishCoalesce(_optionalChain([text, 'access', _184 => _184.match, 'call', _185 => _185(/\p{L}/gu), 'optionalAccess', _186 => _186.length]), () => ( 0))) < 2 || text.split(/\s+/).length > 7);
|
|
2177
2333
|
if (ocrFragment || tocEntry || proseStyle || kicker || byline || tiny || !/\p{L}/u.test(text) && !chapterNumber || /^[a-z]/.test(text) || CAPTION.test(text) || EQUATION_NUMBER.test(block.text) || DISPLAY_MATH.test(text) || // 닫는 괄호가 여는 괄호보다 많으면 앞 줄에서 이어진 문장 조각이다 ("Fact-checking) and is used …") — "1)"·"가)" 앞머리 번호는 빼고 센다
|
|
2178
2334
|
unbalancedClose(text.replace(/^\s*[\dA-Za-z가-힣ⅰ-ⅹ]{1,3}\)\s*/, "")) || isRunningHead(block, page, pageHeights.get(_nullishCoalesce(block.pageNumber, () => ( 0))))) {
|
|
2179
2335
|
block.type = "paragraph";
|
|
@@ -2187,7 +2343,9 @@ function normalizeAraea(text) {
|
|
|
2187
2343
|
return text.replace(/(?<![\u1100-\u115F])\u119E/g, "\u318D");
|
|
2188
2344
|
}
|
|
2189
2345
|
var stripNoUnicodeGlyph = (text) => text.includes("\uF000") ? text.replace(/\uF000/g, "") : text;
|
|
2190
|
-
var
|
|
2346
|
+
var CHOSEONG_COMPAT = "\u3131\u3132\u3134\u3137\u3138\u3139\u3141\u3142\u3143\u3145\u3146\u3147\u3148\u3149\u314A\u314B\u314C\u314D\u314E";
|
|
2347
|
+
var normalizeLoneChoseong = (text) => /[\u1100-\u1112]/.test(text) ? text.replace(/[\u1100-\u1112](?![\u1160-\u11A7\uD7B0-\uD7C6])/g, (c) => CHOSEONG_COMPAT[c.charCodeAt(0) - 4352]) : text;
|
|
2348
|
+
var cleanChars = (text) => normalizeLoneChoseong(normalizeAraea(stripNoUnicodeGlyph(stripControlChars(text))));
|
|
2191
2349
|
function sanitizeBlockControlChars(blocks) {
|
|
2192
2350
|
for (const b of blocks) {
|
|
2193
2351
|
if (b.text) b.text = cleanChars(b.text);
|
|
@@ -2206,28 +2364,28 @@ var CAPTION_LABEL = /^(?:figure|fig\.|diagram|table|chart|graph|exhibit|box)\s*[
|
|
|
2206
2364
|
function captionTableText(t) {
|
|
2207
2365
|
if (!t || t.rows !== 1 || t.cols !== 2) return null;
|
|
2208
2366
|
const [label, body] = t.cells[0];
|
|
2209
|
-
if (!label || !body || _optionalChain([label, 'access',
|
|
2367
|
+
if (!label || !body || _optionalChain([label, 'access', _187 => _187.blocks, 'optionalAccess', _188 => _188.length]) || _optionalChain([body, 'access', _189 => _189.blocks, 'optionalAccess', _190 => _190.length]) || !CAPTION_LABEL.test(label.text.trim()) || !body.text.trim()) return null;
|
|
2210
2368
|
return `${label.text.trim()} ${body.text.replace(/\s*\n\s*/g, " ").trim()}`;
|
|
2211
2369
|
}
|
|
2212
2370
|
function splitSingleCellTables(blocks) {
|
|
2213
2371
|
const out = [];
|
|
2214
2372
|
for (const b of blocks) {
|
|
2215
2373
|
const t = b.type === "table" ? b.table : void 0;
|
|
2216
|
-
const only = t && t.rows === 1 && t.cols === 1 && _optionalChain([t, 'access',
|
|
2374
|
+
const only = t && t.rows === 1 && t.cols === 1 && _optionalChain([t, 'access', _191 => _191.cells, 'access', _192 => _192[0], 'optionalAccess', _193 => _193[0], 'optionalAccess', _194 => _194.blocks, 'optionalAccess', _195 => _195.length]) === 1 ? t.cells[0][0].blocks[0] : void 0;
|
|
2217
2375
|
const squash = (s) => s.replace(/\s/g, "");
|
|
2218
2376
|
const inner = only && (!squash(t.cells[0][0].text) || only.type === "table" && squash(t.cells[0][0].text) === squash(only.table.cells.flat().map((c) => c.text).join(""))) ? only : void 0;
|
|
2219
|
-
const caption = _nullishCoalesce(captionTableText(t), () => ( (_optionalChain([inner, 'optionalAccess',
|
|
2377
|
+
const caption = _nullishCoalesce(captionTableText(t), () => ( (_optionalChain([inner, 'optionalAccess', _196 => _196.type]) === "table" ? captionTableText(inner.table) : null)));
|
|
2220
2378
|
if (caption) {
|
|
2221
2379
|
out.push({ type: "paragraph", text: caption, pageNumber: b.pageNumber, bbox: b.bbox });
|
|
2222
2380
|
continue;
|
|
2223
2381
|
}
|
|
2224
|
-
const cell = t && t.rows === 1 && t.cols === 1 ? _optionalChain([t, 'access',
|
|
2225
|
-
if (!cell || _optionalChain([cell, 'access',
|
|
2382
|
+
const cell = t && t.rows === 1 && t.cols === 1 ? _optionalChain([t, 'access', _197 => _197.cells, 'access', _198 => _198[0], 'optionalAccess', _199 => _199[0]]) : void 0;
|
|
2383
|
+
if (!cell || _optionalChain([cell, 'access', _200 => _200.blocks, 'optionalAccess', _201 => _201.some, 'call', _202 => _202((x) => x.type === "table")])) {
|
|
2226
2384
|
out.push(b);
|
|
2227
2385
|
continue;
|
|
2228
2386
|
}
|
|
2229
2387
|
const lines = (_nullishCoalesce(cell.text, () => ( ""))).split(/\n/).map((l) => l.trim()).filter(Boolean);
|
|
2230
|
-
if (_optionalChain([t, 'optionalAccess',
|
|
2388
|
+
if (_optionalChain([t, 'optionalAccess', _203 => _203.caption, 'optionalAccess', _204 => _204.trim, 'call', _205 => _205()])) out.push({ type: "paragraph", text: t.caption.trim(), pageNumber: b.pageNumber, bbox: b.bbox });
|
|
2231
2389
|
for (const text of lines) out.push({ type: "paragraph", text, pageNumber: b.pageNumber, bbox: b.bbox });
|
|
2232
2390
|
}
|
|
2233
2391
|
return out;
|
|
@@ -2240,7 +2398,7 @@ function joinLatinCellWraps(blocks) {
|
|
|
2240
2398
|
const lines = cell.text.split("\n");
|
|
2241
2399
|
const out = [lines[0]];
|
|
2242
2400
|
for (const line of lines.slice(1)) {
|
|
2243
|
-
if (
|
|
2401
|
+
if (_chunkWDQTFAXYcjs.latinSoftWrap.call(void 0, out[out.length - 1], line)) out[out.length - 1] = out[out.length - 1].trimEnd() + " " + line.trim();
|
|
2244
2402
|
else out.push(line);
|
|
2245
2403
|
}
|
|
2246
2404
|
cell.text = out.join("\n");
|
|
@@ -2251,20 +2409,20 @@ function joinLatinCellWraps(blocks) {
|
|
|
2251
2409
|
}
|
|
2252
2410
|
function cleanPdfText(text, opts) {
|
|
2253
2411
|
let clean = normalizeAraea(stripControlChars(text));
|
|
2254
|
-
if (!_optionalChain([opts, 'optionalAccess',
|
|
2412
|
+
if (!_optionalChain([opts, 'optionalAccess', _206 => _206.keepLoneNumbers])) {
|
|
2255
2413
|
clean = clean.replace(/^\d{1,4}\n/, "").replace(/\n\d{1,4}\n/g, "\n").replace(/\n\d{1,4}$/, "");
|
|
2256
2414
|
}
|
|
2257
|
-
if (!_optionalChain([opts, 'optionalAccess',
|
|
2415
|
+
if (!_optionalChain([opts, 'optionalAccess', _207 => _207.keepLoneNumbers])) clean = clean.replace(/^#{1,6}\s*\d{1,4}\s*$/gm, "");
|
|
2258
2416
|
return mergeKoreanLines(
|
|
2259
2417
|
clean.replace(/^[\s]*[-–—]\s*[-–—]?\d+[-–—]?[\s]*[-–—]?[\s]*$/gm, "").replace(/^\s*\d+\s*\/\s*\d+\s*$/gm, "").replace(/\.(?: \.){3,}/g, (m) => ".".repeat(m.length + 1 >> 1))
|
|
2260
2418
|
).replace(/^(?!\| ---).*$/gm, (line) => {
|
|
2261
2419
|
if (/^\s*\${1,2}.+\${1,2}\s*$/.test(line)) return line;
|
|
2262
2420
|
if (line.startsWith("|")) {
|
|
2263
|
-
return line.replace(/(?:\\.|[^|\\])+/g, (cell) => cell.split("<br>").map((seg) => seg.replace(/\S(?:.*\S)?/, (t) =>
|
|
2421
|
+
return line.replace(/(?:\\.|[^|\\])+/g, (cell) => cell.split("<br>").map((seg) => seg.replace(/\S(?:.*\S)?/, (t) => _chunkWDQTFAXYcjs.collapseEvenSpacing.call(void 0, t, false))).join("<br>"));
|
|
2264
2422
|
}
|
|
2265
|
-
const mark = _nullishCoalesce(_optionalChain([/^(?:#{1,6}|-) /, 'access',
|
|
2266
|
-
return mark +
|
|
2267
|
-
}).replace(/\\~\\~/g, "~~").replace(/~~~~/g, "").replace(/<u>\s*<\/u>/g, "").replace(/\n{3,}/g, "\n\n").trim();
|
|
2423
|
+
const mark = _nullishCoalesce(_optionalChain([/^(?:#{1,6}|-) /, 'access', _208 => _208.exec, 'call', _209 => _209(line), 'optionalAccess', _210 => _210[0]]), () => ( ""));
|
|
2424
|
+
return mark + _chunkWDQTFAXYcjs.collapseEvenSpacing.call(void 0, line.slice(mark.length), false);
|
|
2425
|
+
}).replace(/\\~\\~/g, "~~").replace(/~~~~/g, "").replace(/<u>\s*<\/u>/g, "").replace(/<(sup|sub)>\s*<\/\1>/g, "").replace(/\n{3,}/g, "\n\n").trim();
|
|
2268
2426
|
}
|
|
2269
2427
|
function startsWithMarker(line) {
|
|
2270
2428
|
const t = line.trimStart();
|
|
@@ -2295,7 +2453,7 @@ function mergeKoreanLines(text) {
|
|
|
2295
2453
|
continue;
|
|
2296
2454
|
}
|
|
2297
2455
|
if (/[가-힣·,\-]$/.test(prev) && /^[가-힣(]/.test(curr) && !startsWithMarker(curr) && !isStandaloneHeader(prev) && !startsWithMarker(prev)) {
|
|
2298
|
-
result[result.length - 1] = prev +
|
|
2456
|
+
result[result.length - 1] = prev + _chunkWDQTFAXYcjs.wrapJoiner.call(void 0, prev, curr) + curr;
|
|
2299
2457
|
} else {
|
|
2300
2458
|
result.push(curr);
|
|
2301
2459
|
}
|
|
@@ -2311,7 +2469,7 @@ function applyLinkAnnotations(items, annots) {
|
|
|
2311
2469
|
const wrapped = /* @__PURE__ */ new Set();
|
|
2312
2470
|
for (const a of annots) {
|
|
2313
2471
|
if (a.subtype !== "Link" || !a.url || !a.rect || a.rect.length < 4) continue;
|
|
2314
|
-
const url =
|
|
2472
|
+
const url = _chunkSTM3ORY7cjs.sanitizeHref.call(void 0, a.url);
|
|
2315
2473
|
if (!url) continue;
|
|
2316
2474
|
const x1 = Math.min(a.rect[0], a.rect[2]), x2 = Math.max(a.rect[0], a.rect[2]);
|
|
2317
2475
|
const y1 = Math.min(a.rect[1], a.rect[3]), y2 = Math.max(a.rect[1], a.rect[3]);
|
|
@@ -2352,7 +2510,7 @@ function mergeLinkRuns(markdown) {
|
|
|
2352
2510
|
|
|
2353
2511
|
// src/pdf/formula-ocr.ts
|
|
2354
2512
|
async function applyFormulaOcr(buffer, blocks, pageFilter, effectivePageCount, warnings, _onProgress) {
|
|
2355
|
-
const formulaMod = await Promise.resolve().then(() => _interopRequireWildcard(require("./formula-
|
|
2513
|
+
const formulaMod = await Promise.resolve().then(() => _interopRequireWildcard(require("./formula-WIMV5TUX.cjs")));
|
|
2356
2514
|
const { FormulaPipeline, ensureFormulaModels } = formulaMod;
|
|
2357
2515
|
await ensureFormulaModels((p) => {
|
|
2358
2516
|
if (p.phase === "download" && p.total) {
|
|
@@ -2492,42 +2650,15 @@ g.pdfjsWorker = pdfjsWorker;
|
|
|
2492
2650
|
|
|
2493
2651
|
var _module = require('module');
|
|
2494
2652
|
var _path = require('path');
|
|
2495
|
-
|
|
2496
|
-
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
|
|
2501
|
-
for (const b of blocks) {
|
|
2502
|
-
const t = b.type === "table" ? b.table : void 0;
|
|
2503
|
-
if (!t || t.cols !== 4 || t.rows < 2) continue;
|
|
2504
|
-
const rows = t.cells;
|
|
2505
|
-
if (!HEAD.test(rows[0][0].text.replace(/\s+/g, " ").trim())) continue;
|
|
2506
|
-
const people = rows.map((r) => PERSON.exec(r[3].text.replace(/\s+/g, " ").trim()));
|
|
2507
|
-
if (people.some((p) => !p) || rows.some((r) => !ROLE.test(r[2].text.replace(/\s+/g, "")) || r[2].rowSpan !== 1 || r[3].rowSpan !== 1)) continue;
|
|
2508
|
-
const lead = [];
|
|
2509
|
-
let ok = true;
|
|
2510
|
-
for (const c of [0, 1]) {
|
|
2511
|
-
const top = rows[0][c];
|
|
2512
|
-
if (top.rowSpan === 1) {
|
|
2513
|
-
lead.push(rows.map((r) => r[c].text));
|
|
2514
|
-
continue;
|
|
2515
|
-
}
|
|
2516
|
-
const lines = top.text.split("\n").map((s) => s.trim()).filter(Boolean);
|
|
2517
|
-
if (top.rowSpan !== t.rows || lines.length > t.rows) {
|
|
2518
|
-
ok = false;
|
|
2519
|
-
break;
|
|
2520
|
-
}
|
|
2521
|
-
lead.push(rows.map((_, r) => _nullishCoalesce(lines[r], () => ( ""))));
|
|
2522
|
-
}
|
|
2523
|
-
if (!ok) continue;
|
|
2524
|
-
const one = (text) => ({ text, colSpan: 1, rowSpan: 1 });
|
|
2525
|
-
t.cells = rows.map((r, i) => [one(lead[0][i]), one(lead[1][i]), one(r[2].text), one(people[i][1]), one(people[i][2]), one(people[i][3])]);
|
|
2526
|
-
t.cols = 6;
|
|
2653
|
+
function ocrImageRegions(regions, large, all) {
|
|
2654
|
+
if (all) return regions;
|
|
2655
|
+
const out = /* @__PURE__ */ new Map();
|
|
2656
|
+
for (const [p, rs] of regions) {
|
|
2657
|
+
const big = rs.filter((r) => large.has(r));
|
|
2658
|
+
if (big.length) out.set(p, big);
|
|
2527
2659
|
}
|
|
2660
|
+
return out;
|
|
2528
2661
|
}
|
|
2529
|
-
|
|
2530
|
-
// src/pdf/parser.ts
|
|
2531
2662
|
_pdfmjs.GlobalWorkerOptions.workerSrc = "";
|
|
2532
2663
|
var MAX_PAGES = 5e3;
|
|
2533
2664
|
var MAX_TOTAL_TEXT = 100 * 1024 * 1024;
|
|
@@ -2558,13 +2689,13 @@ async function loadPdfWithTimeout(buffer) {
|
|
|
2558
2689
|
try {
|
|
2559
2690
|
return await Promise.race([
|
|
2560
2691
|
loadingTask.promise.catch((e) => {
|
|
2561
|
-
if (e instanceof Error && e.name === "PasswordException") throw new (0,
|
|
2692
|
+
if (e instanceof Error && e.name === "PasswordException") throw new (0, _chunkSTM3ORY7cjs.KordocError)("\uC554\uD638\uB85C \uBCF4\uD638\uB41C PDF \uD30C\uC77C\uC785\uB2C8\uB2E4 (PDF \uC5F4\uAE30 \uC554\uD638\uB294 \uC9C0\uC6D0\uD558\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4)");
|
|
2562
2693
|
throw e;
|
|
2563
2694
|
}),
|
|
2564
2695
|
new Promise((_, reject) => {
|
|
2565
2696
|
timer = setTimeout(() => {
|
|
2566
2697
|
loadingTask.destroy();
|
|
2567
|
-
reject(new (0,
|
|
2698
|
+
reject(new (0, _chunkSTM3ORY7cjs.KordocError)("PDF \uB85C\uB529 \uD0C0\uC784\uC544\uC6C3 (30\uCD08 \uCD08\uACFC)"));
|
|
2568
2699
|
}, PDF_LOAD_TIMEOUT_MS);
|
|
2569
2700
|
})
|
|
2570
2701
|
]);
|
|
@@ -2573,13 +2704,13 @@ async function loadPdfWithTimeout(buffer) {
|
|
|
2573
2704
|
}
|
|
2574
2705
|
}
|
|
2575
2706
|
async function parsePdfDocument(buffer, options) {
|
|
2576
|
-
const formulaBuffer = _optionalChain([options, 'optionalAccess',
|
|
2577
|
-
const autoOcr = _optionalChain([options, 'optionalAccess',
|
|
2578
|
-
const ocrBuffer = _optionalChain([options, 'optionalAccess',
|
|
2707
|
+
const formulaBuffer = _optionalChain([options, 'optionalAccess', _211 => _211.formulaOcr]) ? buffer : null;
|
|
2708
|
+
const autoOcr = _optionalChain([options, 'optionalAccess', _212 => _212.ocr]) === void 0 && await _chunkWDQTFAXYcjs.ocrModelsCached.call(void 0, );
|
|
2709
|
+
const ocrBuffer = _optionalChain([options, 'optionalAccess', _213 => _213.ocr]) || autoOcr ? buffer : null;
|
|
2579
2710
|
const doc = await loadPdfWithTimeout(buffer);
|
|
2580
2711
|
try {
|
|
2581
2712
|
const pageCount = doc.numPages;
|
|
2582
|
-
if (pageCount === 0) throw new (0,
|
|
2713
|
+
if (pageCount === 0) throw new (0, _chunkSTM3ORY7cjs.KordocError)("PDF\uC5D0 \uD398\uC774\uC9C0\uAC00 \uC5C6\uC2B5\uB2C8\uB2E4.");
|
|
2583
2714
|
const metadata = { pageCount, pageMode: "layout" };
|
|
2584
2715
|
await extractPdfMetadata(doc, metadata);
|
|
2585
2716
|
const blocks = [];
|
|
@@ -2588,8 +2719,8 @@ async function parsePdfDocument(buffer, options) {
|
|
|
2588
2719
|
let totalChars = 0;
|
|
2589
2720
|
let totalTextBytes = 0;
|
|
2590
2721
|
const effectivePageCount = Math.min(pageCount, MAX_PAGES);
|
|
2591
|
-
const pageFilter = _optionalChain([options, 'optionalAccess',
|
|
2592
|
-
if (pageCount > MAX_PAGES && (!_optionalChain([options, 'optionalAccess',
|
|
2722
|
+
const pageFilter = _optionalChain([options, 'optionalAccess', _214 => _214.pages]) ? _chunkJ55UQC5Hcjs.parsePageRange.call(void 0, options.pages, effectivePageCount) : null;
|
|
2723
|
+
if (pageCount > MAX_PAGES && (!_optionalChain([options, 'optionalAccess', _215 => _215.pages]) || _chunkJ55UQC5Hcjs.hasRequestedPagesAfter.call(void 0, options.pages, MAX_PAGES, pageCount))) {
|
|
2593
2724
|
warnings.push({ message: `${pageCount}\uCABD \uC911 \uC55E ${MAX_PAGES}\uCABD\uB9CC \uD30C\uC2F1\uD588\uC2B5\uB2C8\uB2E4 (\uCABD \uC218 \uC0C1\uD55C)`, code: "PARTIAL_PARSE" });
|
|
2594
2725
|
}
|
|
2595
2726
|
const totalTarget = pageFilter ? pageFilter.size : effectivePageCount;
|
|
@@ -2600,12 +2731,13 @@ async function parsePdfDocument(buffer, options) {
|
|
|
2600
2731
|
const pagesWithLargeImage = /* @__PURE__ */ new Set();
|
|
2601
2732
|
const skippedImagePages = /* @__PURE__ */ new Map();
|
|
2602
2733
|
const uncoveredImageRegions = /* @__PURE__ */ new Map();
|
|
2734
|
+
const largeImageRegions = /* @__PURE__ */ new Set();
|
|
2603
2735
|
const imageState = createPdfImageState();
|
|
2604
2736
|
const extractedImages = [];
|
|
2605
2737
|
const pageImageBlocks = /* @__PURE__ */ new Map();
|
|
2606
2738
|
const carry = {};
|
|
2607
2739
|
const vectorPageOps = /* @__PURE__ */ new Map();
|
|
2608
|
-
const wrapLexicon = new (0,
|
|
2740
|
+
const wrapLexicon = new (0, _chunkWDQTFAXYcjs.WrapLexicon)();
|
|
2609
2741
|
const noteMarks = /* @__PURE__ */ new Map();
|
|
2610
2742
|
let parsedPages = 0;
|
|
2611
2743
|
for (let i = 1; i <= effectivePageCount; i++) {
|
|
@@ -2628,12 +2760,13 @@ async function parsePdfDocument(buffer, options) {
|
|
|
2628
2760
|
return void 0;
|
|
2629
2761
|
}
|
|
2630
2762
|
};
|
|
2631
|
-
const differencesOf = (loadedName) => _optionalChain([fontObj, 'call',
|
|
2632
|
-
restoreNamedGlyphs(rawItems, rawOps.fnArray, rawOps.argsArray, differencesOf, (n) => _optionalChain([fontObj, 'call',
|
|
2763
|
+
const differencesOf = (loadedName) => _optionalChain([fontObj, 'call', _216 => _216(loadedName), 'optionalAccess', _217 => _217.differences]);
|
|
2764
|
+
restoreNamedGlyphs(rawItems, rawOps.fnArray, rawOps.argsArray, differencesOf, (n) => _optionalChain([fontObj, 'call', _218 => _218(n), 'optionalAccess', _219 => _219.name]));
|
|
2633
2765
|
restoreTrackedSpacing(rawItems, rawOps.fnArray, rawOps.argsArray);
|
|
2766
|
+
markSyntheticSpaces(rawItems, rawOps.fnArray, rawOps.argsArray);
|
|
2634
2767
|
const occluded = occludedTextItems(rawItems, rawOps.fnArray, rawOps.argsArray);
|
|
2635
|
-
const items =
|
|
2636
|
-
const filtered =
|
|
2768
|
+
const items = _chunkWDQTFAXYcjs.normalizeItems.call(void 0, occluded.size ? rawItems.filter((it) => !occluded.has(it)) : rawItems);
|
|
2769
|
+
const filtered = _chunkWDQTFAXYcjs.filterHiddenText.call(void 0, items, pageW, pageH, viewX1, viewY1);
|
|
2637
2770
|
const joined = joinVerticalColumns(filtered.visible);
|
|
2638
2771
|
const visible = dropTabLeaderDots(joined);
|
|
2639
2772
|
const hiddenCount = filtered.hiddenCount + occluded.size;
|
|
@@ -2657,7 +2790,7 @@ async function parsePdfDocument(buffer, options) {
|
|
|
2657
2790
|
fnArray: [_pdfmjs.OPS.transform, ...rawOps.fnArray],
|
|
2658
2791
|
argsArray: [[1, 0, 0, 1, -viewX1, -viewY1], ...rawOps.argsArray]
|
|
2659
2792
|
} : rawOps;
|
|
2660
|
-
remapSymbolFontItems(visible, (loadedName) => _optionalChain([fontObj, 'call',
|
|
2793
|
+
remapSymbolFontItems(visible, (loadedName) => _optionalChain([fontObj, 'call', _220 => _220(loadedName), 'optionalAccess', _221 => _221.name]));
|
|
2661
2794
|
remapControlGlyphs(visible, differencesOf);
|
|
2662
2795
|
const faces = /* @__PURE__ */ new Map();
|
|
2663
2796
|
for (const it of visible) {
|
|
@@ -2665,17 +2798,17 @@ async function parsePdfDocument(buffer, options) {
|
|
|
2665
2798
|
let face = faces.get(it.fontName);
|
|
2666
2799
|
if (face === void 0) {
|
|
2667
2800
|
const obj = fontObj(it.fontName);
|
|
2668
|
-
face = _optionalChain([obj, 'optionalAccess',
|
|
2801
|
+
face = _optionalChain([obj, 'optionalAccess', _222 => _222.isType3Font]) && /^[A-Z]{6}\+./.test(_nullishCoalesce(obj.name, () => ( ""))) && obj.name.slice(7) || it.fontName;
|
|
2669
2802
|
faces.set(it.fontName, face);
|
|
2670
2803
|
}
|
|
2671
2804
|
it.fontName = face;
|
|
2672
|
-
if (!faceNames.has(face)) faceNames.set(face, (_nullishCoalesce(_optionalChain([fontObj, 'call',
|
|
2805
|
+
if (!faceNames.has(face)) faceNames.set(face, (_nullishCoalesce(_optionalChain([fontObj, 'call', _223 => _223(face), 'optionalAccess', _224 => _224.name]), () => ( ""))).replace(/^[A-Z]{6}\+/, ""));
|
|
2673
2806
|
}
|
|
2674
|
-
for (const it of visible) if (it.text.includes("$")) it.text =
|
|
2807
|
+
for (const it of visible) if (it.text.includes("$")) it.text = _chunkXTFN5WKScjs.escapeLiteralDollar.call(void 0, it.text);
|
|
2675
2808
|
wrapEquationRuns(visible, (face) => faceNames.get(face));
|
|
2676
2809
|
const pageArea = pageW * pageH;
|
|
2677
2810
|
if (pageArea > 0) {
|
|
2678
|
-
const imageRegions =
|
|
2811
|
+
const imageRegions = _chunkWDQTFAXYcjs.extractImageRegions.call(void 0, opList.fnArray, opList.argsArray);
|
|
2679
2812
|
let uncovered = 0;
|
|
2680
2813
|
for (const r of imageRegions) {
|
|
2681
2814
|
const area = (r.x2 - r.x1) * (r.y2 - r.y1);
|
|
@@ -2694,20 +2827,21 @@ async function parsePdfDocument(buffer, options) {
|
|
|
2694
2827
|
const regions = _nullishCoalesce(uncoveredImageRegions.get(i), () => ( []));
|
|
2695
2828
|
regions.push(r);
|
|
2696
2829
|
uncoveredImageRegions.set(i, regions);
|
|
2830
|
+
if (large) largeImageRegions.add(r);
|
|
2697
2831
|
}
|
|
2698
2832
|
}
|
|
2699
2833
|
}
|
|
2700
2834
|
if (uncovered > 0) skippedImagePages.set(i, uncovered);
|
|
2701
2835
|
}
|
|
2702
2836
|
const marks = superscriptNoteMarks(visible);
|
|
2703
|
-
if (marks.length) noteMarks.set(i, { marks, seps: footnoteSeparators(
|
|
2837
|
+
if (marks.length) noteMarks.set(i, { marks, seps: footnoteSeparators(_chunkWDQTFAXYcjs.extractLines.call(void 0, opList.fnArray, opList.argsArray).horizontals, pageW, pageH) });
|
|
2704
2838
|
const stamp = marginStamp(visible);
|
|
2705
2839
|
const flow = stamp.length ? visible.filter((it) => !stamp.includes(it)) : visible;
|
|
2706
|
-
const pageBlocks = orderTwoUpPage(
|
|
2840
|
+
const pageBlocks = orderTwoUpPage(_chunkWDQTFAXYcjs.extractPageBlocksWithLines.call(void 0, flow, i, opList, pageW, pageH, void 0, _optionalChain([options, 'optionalAccess', _225 => _225.tables]) !== false, carry, wrapLexicon), pageW, pageH);
|
|
2707
2841
|
if (stamp.length) pageBlocks.unshift({ type: "paragraph", text: [...stamp].sort((a, b) => a.y - b.y).map((it) => it.text).join(" "), pageNumber: i });
|
|
2708
2842
|
for (const b of pageBlocks) blocks.push(b);
|
|
2709
2843
|
try {
|
|
2710
|
-
const { blocks: imgBlocks, images: pageImages } = await extractPageImages(page, opList.fnArray, opList.argsArray, i, imageState, warnings, _optionalChain([options, 'optionalAccess',
|
|
2844
|
+
const { blocks: imgBlocks, images: pageImages } = await extractPageImages(page, opList.fnArray, opList.argsArray, i, imageState, warnings, _optionalChain([options, 'optionalAccess', _226 => _226.images]) !== false);
|
|
2711
2845
|
if (imgBlocks.length > 0) pageImageBlocks.set(i, imgBlocks);
|
|
2712
2846
|
extractedImages.push(...pageImages);
|
|
2713
2847
|
} catch (e6) {
|
|
@@ -2726,26 +2860,27 @@ async function parsePdfDocument(buffer, options) {
|
|
|
2726
2860
|
const vector = scanVectorGlyphs(opList.fnArray, opList.argsArray, visible);
|
|
2727
2861
|
const quality = computePageQuality(i, pageText, vector.glyphs);
|
|
2728
2862
|
pageQuality.push(quality);
|
|
2729
|
-
if (_optionalChain([options, 'optionalAccess',
|
|
2863
|
+
if (_optionalChain([options, 'optionalAccess', _227 => _227.ocr]) && quality.ocrReason === "vector_text" && page.rotate % 360 === 0 && page.view[0] === 0 && page.view[1] === 0) {
|
|
2730
2864
|
vectorPageOps.set(i, ocrVectorOps(opList, vector.paths));
|
|
2731
2865
|
}
|
|
2732
|
-
if (totalTextBytes > MAX_TOTAL_TEXT) throw new (0,
|
|
2866
|
+
if (totalTextBytes > MAX_TOTAL_TEXT) throw new (0, _chunkSTM3ORY7cjs.KordocError)("\uD14D\uC2A4\uD2B8 \uCD94\uCD9C \uD06C\uAE30 \uCD08\uACFC");
|
|
2733
2867
|
parsedPages++;
|
|
2734
|
-
_optionalChain([options, 'optionalAccess',
|
|
2868
|
+
_optionalChain([options, 'optionalAccess', _228 => _228.onProgress, 'optionalCall', _229 => _229(parsedPages, totalTarget)]);
|
|
2735
2869
|
} catch (pageErr) {
|
|
2736
|
-
if (pageErr instanceof
|
|
2870
|
+
if (pageErr instanceof _chunkSTM3ORY7cjs.KordocError) throw pageErr;
|
|
2737
2871
|
warnings.push({ page: i, message: `\uD398\uC774\uC9C0 ${i} \uD30C\uC2F1 \uC2E4\uD328: ${pageErr instanceof Error ? pageErr.message : "\uC54C \uC218 \uC5C6\uB294 \uC624\uB958"}`, code: "PARTIAL_PARSE" });
|
|
2738
2872
|
} finally {
|
|
2739
|
-
_optionalChain([loadedPage, 'optionalAccess',
|
|
2873
|
+
_optionalChain([loadedPage, 'optionalAccess', _230 => _230.cleanup, 'call', _231 => _231()]);
|
|
2740
2874
|
}
|
|
2741
2875
|
}
|
|
2742
2876
|
const parsedPageCount = parsedPages || (pageFilter ? pageFilter.size : effectivePageCount);
|
|
2743
|
-
const isImageBased = _optionalChain([pageFilter, 'optionalAccess',
|
|
2877
|
+
const isImageBased = _optionalChain([pageFilter, 'optionalAccess', _232 => _232.size]) !== 0 && totalChars / Math.max(parsedPageCount, 1) < 10;
|
|
2744
2878
|
const ocrDone = /* @__PURE__ */ new Set();
|
|
2879
|
+
const ocrRegions = _optionalChain([options, 'optionalAccess', _233 => _233.ocr]) === true || autoOcr ? ocrImageRegions(uncoveredImageRegions, largeImageRegions, _optionalChain([options, 'optionalAccess', _234 => _234.ocr]) === true) : /* @__PURE__ */ new Map();
|
|
2745
2880
|
if (ocrBuffer) {
|
|
2746
2881
|
const inScope = (p) => !pageFilter || pageFilter.has(p);
|
|
2747
2882
|
const targets = /* @__PURE__ */ new Set();
|
|
2748
|
-
if (_optionalChain([options, 'optionalAccess',
|
|
2883
|
+
if (_optionalChain([options, 'optionalAccess', _235 => _235.ocr]) === "force" || isImageBased) {
|
|
2749
2884
|
for (let i = 1; i <= effectivePageCount; i++) if (inScope(i)) targets.add(i);
|
|
2750
2885
|
} else {
|
|
2751
2886
|
for (const pq of pageQuality) {
|
|
@@ -2754,27 +2889,28 @@ async function parsePdfDocument(buffer, options) {
|
|
|
2754
2889
|
if (autoOcr && pq.ocrReason !== "low_text" && pq.ocrReason !== "vector_text") continue;
|
|
2755
2890
|
targets.add(pq.page);
|
|
2756
2891
|
}
|
|
2757
|
-
|
|
2892
|
+
for (const p of ocrRegions.keys()) targets.add(p);
|
|
2758
2893
|
}
|
|
2759
2894
|
if (targets.size > 0) {
|
|
2760
2895
|
try {
|
|
2761
|
-
const { runPdfOcr } = await Promise.resolve().then(() => _interopRequireWildcard(require("./pdf-ocr-
|
|
2762
|
-
const mode = typeof _optionalChain([options, 'optionalAccess',
|
|
2763
|
-
const regionPages = new Map([...
|
|
2764
|
-
const ocrPageBlocks = await runPdfOcr(ocrBuffer, targets, mode, warnings, _optionalChain([options, 'optionalAccess',
|
|
2896
|
+
const { runPdfOcr } = await Promise.resolve().then(() => _interopRequireWildcard(require("./pdf-ocr-GHEJVPX2.cjs")));
|
|
2897
|
+
const mode = typeof _optionalChain([options, 'optionalAccess', _236 => _236.ocr]) === "function" ? options.ocr : "builtin";
|
|
2898
|
+
const regionPages = new Map([...ocrRegions].filter(([p]) => _optionalChain([options, 'optionalAccess', _237 => _237.ocr]) !== "force" && !isImageBased && !_optionalChain([pageQuality, 'access', _238 => _238.find, 'call', _239 => _239((q) => q.page === p), 'optionalAccess', _240 => _240.needsOcr])));
|
|
2899
|
+
const ocrPageBlocks = await runPdfOcr(ocrBuffer, targets, mode, warnings, _optionalChain([options, 'optionalAccess', _241 => _241.onProgress]), _optionalChain([options, 'optionalAccess', _242 => _242.tables]) !== false, vectorPageOps, regionPages);
|
|
2900
|
+
for (const obs of ocrPageBlocks.values()) _chunk62W7QCEXcjs.stripScriptTags.call(void 0, { blocks: obs });
|
|
2765
2901
|
if (ocrPageBlocks.size > 0) {
|
|
2766
2902
|
const replacePages = /* @__PURE__ */ new Set();
|
|
2767
2903
|
for (const [p, obs] of ocrPageBlocks) {
|
|
2768
|
-
const needsOcr = _optionalChain([pageQuality, 'access',
|
|
2769
|
-
if (_optionalChain([options, 'optionalAccess',
|
|
2904
|
+
const needsOcr = _optionalChain([pageQuality, 'access', _243 => _243.find, 'call', _244 => _244((q) => q.page === p), 'optionalAccess', _245 => _245.needsOcr]);
|
|
2905
|
+
if (_optionalChain([options, 'optionalAccess', _246 => _246.ocr]) === "force" || isImageBased || needsOcr) {
|
|
2770
2906
|
replacePages.add(p);
|
|
2771
2907
|
ocrDone.add(p);
|
|
2772
2908
|
continue;
|
|
2773
2909
|
}
|
|
2774
|
-
const regions =
|
|
2910
|
+
const regions = ocrRegions.get(p);
|
|
2775
2911
|
if (!regions || mergeOcrImageRegions(blocks, p, regions, obs) === 0) continue;
|
|
2776
2912
|
ocrDone.add(p);
|
|
2777
|
-
if (_optionalChain([pageImageBlocks, 'access',
|
|
2913
|
+
if (_optionalChain([pageImageBlocks, 'access', _247 => _247.get, 'call', _248 => _248(p), 'optionalAccess', _249 => _249.length]) === 1) pageImageBlocks.delete(p);
|
|
2778
2914
|
}
|
|
2779
2915
|
if (replacePages.size) {
|
|
2780
2916
|
const merged = blocks.filter((b) => !(b.pageNumber && replacePages.has(b.pageNumber)));
|
|
@@ -2824,8 +2960,8 @@ async function parsePdfDocument(buffer, options) {
|
|
|
2824
2960
|
warnings.push({ page, message: `${count}\uAC1C \uC774\uBBF8\uC9C0 \uC601\uC5ED\uC5D0 \uCD94\uCD9C \uAC00\uB2A5\uD55C \uD14D\uC2A4\uD2B8 \uC5C6\uC74C (\uADF8\uB9BC/\uCC28\uD2B8/\uB3C4\uC7A5 \uB0B4\uC6A9 \uB204\uB77D \uAC00\uB2A5 \u2014 \uADF8\uB9BC \uC18D \uAE00\uC740 ocr: true / CLI --ocr \uB85C \uC77D\uC2B5\uB2C8\uB2E4)`, code: "SKIPPED_IMAGE" });
|
|
2825
2961
|
}
|
|
2826
2962
|
}
|
|
2827
|
-
if (_optionalChain([options, 'optionalAccess',
|
|
2828
|
-
const removed =
|
|
2963
|
+
if (_optionalChain([options, 'optionalAccess', _250 => _250.removeHeaderFooter]) !== false && parsedPageCount >= 3) {
|
|
2964
|
+
const removed = _chunkWDQTFAXYcjs.removeHeaderFooterBlocks.call(void 0, blocks, pageHeights, warnings, noteMarks);
|
|
2829
2965
|
for (let ri = removed.length - 1; ri >= 0; ri--) {
|
|
2830
2966
|
blocks.splice(removed[ri], 1);
|
|
2831
2967
|
}
|
|
@@ -2836,12 +2972,16 @@ async function parsePdfDocument(buffer, options) {
|
|
|
2836
2972
|
}
|
|
2837
2973
|
}
|
|
2838
2974
|
mergeContinuedCells(blocks, pageHeights);
|
|
2839
|
-
mergeCrossPageTables(blocks, pageHeights);
|
|
2975
|
+
mergeCrossPageTables(blocks, pageHeights, wrapLexicon);
|
|
2976
|
+
if (_optionalChain([options, 'optionalAccess', _251 => _251.removeHeaderFooter]) !== false && parsedPageCount >= 3) {
|
|
2977
|
+
const boxes = _chunkWDQTFAXYcjs.removeHeaderFooterBlocks.call(void 0, blocks, pageHeights, warnings, noteMarks, true);
|
|
2978
|
+
for (let ri = boxes.length - 1; ri >= 0; ri--) blocks.splice(boxes[ri], 1);
|
|
2979
|
+
}
|
|
2840
2980
|
splitContactTables(blocks);
|
|
2841
|
-
if (!_optionalChain([options, 'optionalAccess',
|
|
2842
|
-
|
|
2981
|
+
if (!_optionalChain([options, 'optionalAccess', _252 => _252.keepTrailingEmptyCols])) _chunkWDQTFAXYcjs.trimTrailingEmptyTableCols.call(void 0, blocks);
|
|
2982
|
+
_chunkWDQTFAXYcjs.joinPageBreakWraps.call(void 0, blocks, wrapLexicon);
|
|
2843
2983
|
injectPageImageBlocks(blocks, pageImageBlocks);
|
|
2844
|
-
if (_optionalChain([options, 'optionalAccess',
|
|
2984
|
+
if (_optionalChain([options, 'optionalAccess', _253 => _253.formulaOcr]) && formulaBuffer) {
|
|
2845
2985
|
try {
|
|
2846
2986
|
await applyFormulaOcr(formulaBuffer, blocks, pageFilter, effectivePageCount, warnings, options.onProgress);
|
|
2847
2987
|
} catch (e) {
|
|
@@ -2851,38 +2991,38 @@ async function parsePdfDocument(buffer, options) {
|
|
|
2851
2991
|
});
|
|
2852
2992
|
}
|
|
2853
2993
|
}
|
|
2854
|
-
const medianFontSize =
|
|
2994
|
+
const medianFontSize = _chunkWDQTFAXYcjs.computeMedianFontSizeFromFreq.call(void 0, fontSizeFreq);
|
|
2855
2995
|
if (medianFontSize > 0) {
|
|
2856
|
-
|
|
2857
|
-
}
|
|
2858
|
-
|
|
2859
|
-
|
|
2860
|
-
|
|
2861
|
-
|
|
2862
|
-
|
|
2863
|
-
|
|
2864
|
-
|
|
2865
|
-
|
|
2996
|
+
_chunkWDQTFAXYcjs.detectHeadings.call(void 0, blocks, medianFontSize);
|
|
2997
|
+
}
|
|
2998
|
+
_chunkWDQTFAXYcjs.detectDocumentStyleHeadings.call(void 0, blocks);
|
|
2999
|
+
_chunkWDQTFAXYcjs.detectTypographyHeadings.call(void 0, blocks);
|
|
3000
|
+
_chunkWDQTFAXYcjs.detectSiblingStyleHeadings.call(void 0, blocks);
|
|
3001
|
+
_chunkWDQTFAXYcjs.detectRepeatedPageLabels.call(void 0, blocks);
|
|
3002
|
+
_chunkWDQTFAXYcjs.detectPageLeadHeadings.call(void 0, blocks);
|
|
3003
|
+
_chunkWDQTFAXYcjs.mergeStackedHeadingLines.call(void 0, blocks, medianFontSize);
|
|
3004
|
+
_chunkWDQTFAXYcjs.refineDocumentStyleHeadings.call(void 0, blocks);
|
|
3005
|
+
_chunkWDQTFAXYcjs.detectMarkerHeadings.call(void 0, blocks);
|
|
2866
3006
|
demoteNonHeadingRoles(blocks, pageHeights, faceNames);
|
|
2867
|
-
|
|
2868
|
-
|
|
3007
|
+
_chunkWDQTFAXYcjs.detectTableCaptions.call(void 0, blocks);
|
|
3008
|
+
_chunkWDQTFAXYcjs.detectKoreanListBlocks.call(void 0, blocks);
|
|
2869
3009
|
const outline = blocks.filter((b) => b.type === "heading" && b.level && b.text).map((b) => ({ level: b.level, text: b.text, pageNumber: b.pageNumber }));
|
|
2870
3010
|
sanitizeBlockControlChars(blocks);
|
|
2871
3011
|
let outBlocks = splitSingleCellTables(blocks);
|
|
2872
3012
|
outBlocks = inlineFootnotes(outBlocks, noteMarks);
|
|
2873
3013
|
outBlocks = relocateEndnotes(outBlocks);
|
|
2874
|
-
if (_optionalChain([options, 'optionalAccess',
|
|
3014
|
+
if (_optionalChain([options, 'optionalAccess', _254 => _254.removeHeaderFooter]) !== false) outBlocks = outBlocks.filter((b) => {
|
|
2875
3015
|
if (b.type !== "paragraph" || !/^\s*\d{1,4}\s*$/.test(_nullishCoalesce(b.text, () => ( "")))) return true;
|
|
2876
3016
|
const h = pageHeights.get(_nullishCoalesce(b.pageNumber, () => ( 0)));
|
|
2877
3017
|
if (!b.bbox || !h) return false;
|
|
2878
3018
|
return b.bbox.y > h * 0.1 && b.bbox.y + b.bbox.height < h * 0.9;
|
|
2879
3019
|
});
|
|
2880
3020
|
joinLatinCellWraps(outBlocks);
|
|
2881
|
-
const finishMarkdown = (bs) => mergeLinkRuns(cleanPdfText(
|
|
3021
|
+
const finishMarkdown = (bs) => mergeLinkRuns(cleanPdfText(_chunkXTFN5WKScjs.blocksToMarkdown.call(void 0, bs), { keepLoneNumbers: true }));
|
|
2882
3022
|
let markdown = finishMarkdown(outBlocks);
|
|
2883
3023
|
return {
|
|
2884
3024
|
markdown,
|
|
2885
|
-
pages:
|
|
3025
|
+
pages: _chunkXTFN5WKScjs.blocksToPages.call(void 0, outBlocks, finishMarkdown),
|
|
2886
3026
|
blocks,
|
|
2887
3027
|
metadata,
|
|
2888
3028
|
outline: outline.length > 0 ? outline : void 0,
|
|
@@ -2900,7 +3040,7 @@ async function parsePdfDocument(buffer, options) {
|
|
|
2900
3040
|
async function extractPdfMetadata(doc, metadata) {
|
|
2901
3041
|
try {
|
|
2902
3042
|
const result = await doc.getMetadata();
|
|
2903
|
-
if (!_optionalChain([result, 'optionalAccess',
|
|
3043
|
+
if (!_optionalChain([result, 'optionalAccess', _255 => _255.info])) return;
|
|
2904
3044
|
const info = result.info;
|
|
2905
3045
|
if (typeof info.Title === "string" && info.Title.trim()) metadata.title = info.Title.trim();
|
|
2906
3046
|
if (typeof info.Author === "string" && info.Author.trim()) metadata.author = info.Author.trim();
|
|
@@ -2951,5 +3091,6 @@ function marginStamp(items) {
|
|
|
2951
3091
|
|
|
2952
3092
|
|
|
2953
3093
|
|
|
2954
|
-
|
|
2955
|
-
|
|
3094
|
+
|
|
3095
|
+
exports.cleanPdfText = cleanPdfText; exports.detectKoreanListBlocks = _chunkWDQTFAXYcjs.detectKoreanListBlocks; exports.detectTableCaptions = _chunkWDQTFAXYcjs.detectTableCaptions; exports.extractPdfMetadataOnly = extractPdfMetadataOnly; exports.mergeCrossPageTables = mergeCrossPageTables; exports.ocrImageRegions = ocrImageRegions; exports.parsePdfDocument = parsePdfDocument; exports.removeHeaderFooterBlocks = _chunkWDQTFAXYcjs.removeHeaderFooterBlocks;
|
|
3096
|
+
//# sourceMappingURL=parser-2LU4EVU3.cjs.map
|