kordoc 4.19.0 → 4.19.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 +3 -1
- package/dist/{-I3DEUQUC.js → -3JIHF2AL.js} +11 -11
- package/dist/{chunk-CR4RXHXO.js → chunk-4CS7XE2Q.js} +2 -2
- package/dist/{chunk-UCTD3BXH.js → chunk-56ZWAREM.js} +2 -2
- package/dist/{chunk-YV4PWWRW.cjs → chunk-5PGOZBEQ.cjs} +22 -22
- package/dist/{chunk-YV4PWWRW.cjs.map → chunk-5PGOZBEQ.cjs.map} +1 -1
- package/dist/{chunk-OMJWAJBD.js → chunk-6ZBORHFB.js} +2 -2
- package/dist/{chunk-DH75ZUYF.js → chunk-AKSCTGKG.js} +10 -4
- package/dist/chunk-AKSCTGKG.js.map +1 -0
- package/dist/{chunk-L5KNWOGR.js → chunk-AOVMOCTK.js} +10 -4
- package/dist/chunk-AOVMOCTK.js.map +1 -0
- package/dist/{chunk-XXUXQHUC.js → chunk-B4R443MV.js} +2 -2
- package/dist/{chunk-RYKNAYKC.js → chunk-EUCBMW6C.js} +3 -3
- package/dist/{chunk-XIWGPC3V.js → chunk-GNUGD4RO.js} +2 -2
- package/dist/{chunk-AMDDV4CI.js → chunk-I2TBI7PN.js} +2 -2
- package/dist/{chunk-5B55S4JU.js → chunk-J75TVRJB.js} +2 -2
- package/dist/{chunk-VZSOPECZ.js → chunk-JK7N4R4K.js} +2 -2
- package/dist/{chunk-DEYCTP2S.js → chunk-JXJDXDOU.js} +3 -3
- package/dist/{chunk-34RIECIF.cjs → chunk-MZ6XNFZL.cjs} +2 -2
- package/dist/{chunk-34RIECIF.cjs.map → chunk-MZ6XNFZL.cjs.map} +1 -1
- package/dist/{chunk-C4JHZNRL.js → chunk-NV46IWKF.js} +27 -21
- package/dist/chunk-NV46IWKF.js.map +1 -0
- package/dist/{chunk-UTVNSCEI.js → chunk-OKHKEYTL.js} +2 -2
- package/dist/{chunk-LNU54ZKV.cjs → chunk-ORGWGR4K.cjs} +15 -9
- package/dist/chunk-ORGWGR4K.cjs.map +1 -0
- package/dist/{chunk-AAE765MK.js → chunk-PWQ2BVAT.js} +3 -3
- package/dist/{chunk-FJE3TMZ7.js → chunk-QYJPU4FZ.js} +30 -2
- package/dist/chunk-QYJPU4FZ.js.map +1 -0
- package/dist/{chunk-DGXGVC4Z.js → chunk-QZ63HXEG.js} +51 -20
- package/dist/chunk-QZ63HXEG.js.map +1 -0
- package/dist/{chunk-GCYLNOTJ.js → chunk-R2JM2HOJ.js} +4 -4
- package/dist/{chunk-LLVF6X5W.cjs → chunk-RVBQT2PD.cjs} +3 -3
- package/dist/{chunk-LLVF6X5W.cjs.map → chunk-RVBQT2PD.cjs.map} +1 -1
- package/dist/{chunk-7TVRQJXI.cjs → chunk-T2DZTOGG.cjs} +12 -12
- package/dist/{chunk-7TVRQJXI.cjs.map → chunk-T2DZTOGG.cjs.map} +1 -1
- package/dist/{chunk-GYQVQF2J.js → chunk-TM4T4NYJ.js} +2 -2
- package/dist/{chunk-W5XX2GKO.js → chunk-U6AJU2VD.js} +2 -2
- package/dist/{chunk-QHN7N2QA.js → chunk-VO22VAR3.js} +2 -2
- package/dist/{chunk-5ZSQ2ZIH.cjs → chunk-WQAGDJIP.cjs} +3 -3
- package/dist/{chunk-5ZSQ2ZIH.cjs.map → chunk-WQAGDJIP.cjs.map} +1 -1
- package/dist/{chunk-HFMIAMEO.js → chunk-XPM7WC54.js} +4 -4
- package/dist/chunks-2EC2R7PY.js +10 -0
- package/dist/cli.js +26 -26
- package/dist/{formula-L2BKGA4J.cjs → formula-RNATQ3FQ.cjs} +9 -9
- package/dist/{formula-L2BKGA4J.cjs.map → formula-RNATQ3FQ.cjs.map} +1 -1
- package/dist/{formula-DUEAYGIG.js → formula-RSTTP626.js} +4 -4
- package/dist/{formula-I4MAHCTZ.js → formula-STIFIS57.js} +3 -3
- package/dist/{image-ocr-ZWRJZKYR.cjs → image-ocr-7L5TBBPA.cjs} +15 -15
- package/dist/{image-ocr-ZWRJZKYR.cjs.map → image-ocr-7L5TBBPA.cjs.map} +1 -1
- package/dist/{image-ocr-B32G24XW.js → image-ocr-R6ZDFBAN.js} +6 -6
- package/dist/{image-ocr-NUL3JKXM.js → image-ocr-XKSAEEXP.js} +9 -9
- package/dist/index.cjs +824 -761
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +94 -31
- package/dist/index.js.map +1 -1
- package/dist/mcp.js +22 -22
- package/dist/{model-bundle-OBIKG4K5.js → model-bundle-NGTKULP7.js} +5 -5
- package/dist/{models-2OZHOPPM.js → models-QOSU5SYL.js} +5 -5
- package/dist/{parser-FDE6GQST.js → parser-3G4G6SST.js} +176 -12
- package/dist/parser-3G4G6SST.js.map +1 -0
- package/dist/{parser-YW3NMSJE.js → parser-5GUEP6EK.js} +173 -9
- package/dist/parser-5GUEP6EK.js.map +1 -0
- package/dist/{parser-DMWCXX7A.cjs → parser-AIQBU7FS.cjs} +392 -228
- package/dist/parser-AIQBU7FS.cjs.map +1 -0
- package/dist/pdf-ocr-7OAFUDM4.cjs +17 -0
- package/dist/{pdf-ocr-K2OK7FNQ.cjs.map → pdf-ocr-7OAFUDM4.cjs.map} +1 -1
- package/dist/pdf-ocr-DAXS5RX4.js +16 -0
- package/dist/pdf-ocr-R3VGX6F2.js +20 -0
- package/dist/{profile-io-6WCU4KHY.js → profile-io-ZVNMDLLS.js} +3 -3
- package/dist/{rasterize-X3I7SWXF.js → rasterize-Y2RLMVCL.js} +3 -3
- package/dist/{redact-doc-6H7WPUQD.js → redact-doc-PNRDDBI3.js} +11 -11
- package/dist/{render-PBQJGZT3.js → render-S3ALARVO.js} +7 -7
- package/dist/seal-EJWPS5VK.js +10 -0
- package/dist/{setup-UORJSR3M.js → setup-JH66VSFZ.js} +3 -3
- package/dist/visual-GDXMKDVY.js +20 -0
- package/dist/{watch-S2ZMDDZU.js → watch-KMB2FTOD.js} +12 -12
- package/package.json +1 -1
- package/dist/chunk-C4JHZNRL.js.map +0 -1
- package/dist/chunk-DGXGVC4Z.js.map +0 -1
- package/dist/chunk-DH75ZUYF.js.map +0 -1
- package/dist/chunk-FJE3TMZ7.js.map +0 -1
- package/dist/chunk-L5KNWOGR.js.map +0 -1
- package/dist/chunk-LNU54ZKV.cjs.map +0 -1
- package/dist/chunks-JPNLQOVD.js +0 -10
- package/dist/parser-DMWCXX7A.cjs.map +0 -1
- package/dist/parser-FDE6GQST.js.map +0 -1
- package/dist/parser-YW3NMSJE.js.map +0 -1
- package/dist/pdf-ocr-7MR56U4P.js +0 -16
- package/dist/pdf-ocr-K2OK7FNQ.cjs +0 -17
- package/dist/pdf-ocr-YHC4X67W.js +0 -20
- package/dist/seal-E2E7CFZJ.js +0 -10
- package/dist/visual-4GDT5BRH.js +0 -20
- /package/dist/{-I3DEUQUC.js.map → -3JIHF2AL.js.map} +0 -0
- /package/dist/{chunk-CR4RXHXO.js.map → chunk-4CS7XE2Q.js.map} +0 -0
- /package/dist/{chunk-UCTD3BXH.js.map → chunk-56ZWAREM.js.map} +0 -0
- /package/dist/{chunk-OMJWAJBD.js.map → chunk-6ZBORHFB.js.map} +0 -0
- /package/dist/{chunk-XXUXQHUC.js.map → chunk-B4R443MV.js.map} +0 -0
- /package/dist/{chunk-RYKNAYKC.js.map → chunk-EUCBMW6C.js.map} +0 -0
- /package/dist/{chunk-XIWGPC3V.js.map → chunk-GNUGD4RO.js.map} +0 -0
- /package/dist/{chunk-AMDDV4CI.js.map → chunk-I2TBI7PN.js.map} +0 -0
- /package/dist/{chunk-5B55S4JU.js.map → chunk-J75TVRJB.js.map} +0 -0
- /package/dist/{chunk-VZSOPECZ.js.map → chunk-JK7N4R4K.js.map} +0 -0
- /package/dist/{chunk-DEYCTP2S.js.map → chunk-JXJDXDOU.js.map} +0 -0
- /package/dist/{chunk-UTVNSCEI.js.map → chunk-OKHKEYTL.js.map} +0 -0
- /package/dist/{chunk-AAE765MK.js.map → chunk-PWQ2BVAT.js.map} +0 -0
- /package/dist/{chunk-GCYLNOTJ.js.map → chunk-R2JM2HOJ.js.map} +0 -0
- /package/dist/{chunk-GYQVQF2J.js.map → chunk-TM4T4NYJ.js.map} +0 -0
- /package/dist/{chunk-W5XX2GKO.js.map → chunk-U6AJU2VD.js.map} +0 -0
- /package/dist/{chunk-QHN7N2QA.js.map → chunk-VO22VAR3.js.map} +0 -0
- /package/dist/{chunk-HFMIAMEO.js.map → chunk-XPM7WC54.js.map} +0 -0
- /package/dist/{chunks-JPNLQOVD.js.map → chunks-2EC2R7PY.js.map} +0 -0
- /package/dist/{formula-DUEAYGIG.js.map → formula-RSTTP626.js.map} +0 -0
- /package/dist/{formula-I4MAHCTZ.js.map → formula-STIFIS57.js.map} +0 -0
- /package/dist/{image-ocr-B32G24XW.js.map → image-ocr-R6ZDFBAN.js.map} +0 -0
- /package/dist/{image-ocr-NUL3JKXM.js.map → image-ocr-XKSAEEXP.js.map} +0 -0
- /package/dist/{model-bundle-OBIKG4K5.js.map → model-bundle-NGTKULP7.js.map} +0 -0
- /package/dist/{models-2OZHOPPM.js.map → models-QOSU5SYL.js.map} +0 -0
- /package/dist/{pdf-ocr-7MR56U4P.js.map → pdf-ocr-DAXS5RX4.js.map} +0 -0
- /package/dist/{pdf-ocr-YHC4X67W.js.map → pdf-ocr-R3VGX6F2.js.map} +0 -0
- /package/dist/{profile-io-6WCU4KHY.js.map → profile-io-ZVNMDLLS.js.map} +0 -0
- /package/dist/{rasterize-X3I7SWXF.js.map → rasterize-Y2RLMVCL.js.map} +0 -0
- /package/dist/{redact-doc-6H7WPUQD.js.map → redact-doc-PNRDDBI3.js.map} +0 -0
- /package/dist/{render-PBQJGZT3.js.map → render-S3ALARVO.js.map} +0 -0
- /package/dist/{seal-E2E7CFZJ.js.map → seal-EJWPS5VK.js.map} +0 -0
- /package/dist/{setup-UORJSR3M.js.map → setup-JH66VSFZ.js.map} +0 -0
- /package/dist/{visual-4GDT5BRH.js.map → visual-GDXMKDVY.js.map} +0 -0
- /package/dist/{watch-S2ZMDDZU.js.map → watch-KMB2FTOD.js.map} +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } async function _asyncOptionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = await fn(value); } else if (op === 'call' || op === 'optionalCall') { value = await fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class;
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
var
|
|
4
|
+
var _chunkRVBQT2PDcjs = require('./chunk-RVBQT2PD.cjs');
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
|
|
@@ -58,7 +58,7 @@ var _chunkJ55UQC5Hcjs = require('./chunk-J55UQC5H.cjs');
|
|
|
58
58
|
|
|
59
59
|
|
|
60
60
|
|
|
61
|
-
var
|
|
61
|
+
var _chunk5PGOZBEQcjs = require('./chunk-5PGOZBEQ.cjs');
|
|
62
62
|
|
|
63
63
|
|
|
64
64
|
|
|
@@ -69,12 +69,13 @@ var _chunkYV4PWWRWcjs = require('./chunk-YV4PWWRW.cjs');
|
|
|
69
69
|
|
|
70
70
|
|
|
71
71
|
|
|
72
|
-
var _chunkLNU54ZKVcjs = require('./chunk-LNU54ZKV.cjs');
|
|
73
|
-
require('./chunk-5ZSQ2ZIH.cjs');
|
|
74
72
|
|
|
73
|
+
var _chunkORGWGR4Kcjs = require('./chunk-ORGWGR4K.cjs');
|
|
74
|
+
require('./chunk-WQAGDJIP.cjs');
|
|
75
75
|
|
|
76
76
|
|
|
77
|
-
|
|
77
|
+
|
|
78
|
+
var _chunkMZ6XNFZLcjs = require('./chunk-MZ6XNFZL.cjs');
|
|
78
79
|
|
|
79
80
|
|
|
80
81
|
var _chunkGS7T56RPcjs = require('./chunk-GS7T56RP.cjs');
|
|
@@ -115,7 +116,7 @@ function mergeOcrImageRegions(blocks, page, regions, ocrBlocks) {
|
|
|
115
116
|
const selectedSet = new Set(selected), seen = /* @__PURE__ */ new Set();
|
|
116
117
|
for (const block of selected) {
|
|
117
118
|
if (seen.has(block)) continue;
|
|
118
|
-
const frame =
|
|
119
|
+
const frame = _chunk5PGOZBEQcjs.FRAME_READING_UNITS.get(block);
|
|
119
120
|
const source = _optionalChain([frame, 'optionalAccess', _25 => _25.blocks, 'access', _26 => _26.every, 'call', _27 => _27((member) => selectedSet.has(member))]) ? frame.blocks : [block];
|
|
120
121
|
source.forEach((member) => seen.add(member));
|
|
121
122
|
const available = source.filter((member) => !hasOriginal(member));
|
|
@@ -123,13 +124,13 @@ function mergeOcrImageRegions(blocks, page, regions, ocrBlocks) {
|
|
|
123
124
|
for (const unit of units) {
|
|
124
125
|
const b = unit.bbox;
|
|
125
126
|
const index = blocks.findIndex((existing) => {
|
|
126
|
-
const e = _nullishCoalesce(_optionalChain([
|
|
127
|
+
const e = _nullishCoalesce(_optionalChain([_chunk5PGOZBEQcjs.FRAME_READING_UNITS, 'access', _28 => _28.get, 'call', _29 => _29(existing), 'optionalAccess', _30 => _30.bbox]), () => ( existing.bbox));
|
|
127
128
|
if (existing.pageNumber !== page || !e) return false;
|
|
128
129
|
const beside = e.y < region.y2 && e.y + e.height > region.y1 && e.x >= region.x2 - 1;
|
|
129
130
|
return e.y < b.y || beside;
|
|
130
131
|
});
|
|
131
132
|
const placed = unit.blocks.map((member) => member.type === "paragraph" ? { ...member, style: void 0 } : member);
|
|
132
|
-
if (unit.atomic)
|
|
133
|
+
if (unit.atomic) _chunk5PGOZBEQcjs.recordFrameReadingUnit.call(void 0, placed, unit.bbox);
|
|
133
134
|
blocks.splice(index < 0 ? blocks.length : index, 0, ...placed);
|
|
134
135
|
added += placed.length;
|
|
135
136
|
}
|
|
@@ -330,7 +331,7 @@ async function extractPageImages(page, fnArray, argsArray, pageNumber, state, wa
|
|
|
330
331
|
const filename = `image_${String(state.imageIndex).padStart(3, "0")}.png`;
|
|
331
332
|
state.seen.set(hash, filename);
|
|
332
333
|
if (withBytes) {
|
|
333
|
-
const png =
|
|
334
|
+
const png = _chunkRVBQT2PDcjs.encodePng.call(void 0, w, h, rgba);
|
|
334
335
|
state.totalBytes += png.length;
|
|
335
336
|
images.push({ filename, data: png, mimeType: "image/png" });
|
|
336
337
|
}
|
|
@@ -758,6 +759,167 @@ function splitContactTables(blocks) {
|
|
|
758
759
|
}
|
|
759
760
|
}
|
|
760
761
|
|
|
762
|
+
// src/pdf/table-pages.ts
|
|
763
|
+
var CELL_SPLITS = /* @__PURE__ */ new WeakMap();
|
|
764
|
+
function relocate(src, dst, from = 0) {
|
|
765
|
+
const out = [];
|
|
766
|
+
for (const s of _nullishCoalesce(CELL_SPLITS.get(src), () => ( []))) {
|
|
767
|
+
const at = dst.text.indexOf(src.text.slice(s.at, s.at + 20).trimEnd(), Math.max(from, _nullishCoalesce(_optionalChain([out, 'access', _57 => _57.at, 'call', _58 => _58(-1), 'optionalAccess', _59 => _59.at]), () => ( 0))));
|
|
768
|
+
if (at >= 0) out.push({ at, page: s.page });
|
|
769
|
+
}
|
|
770
|
+
return out;
|
|
771
|
+
}
|
|
772
|
+
var setSplits = (cell, splits) => {
|
|
773
|
+
if (splits.length) CELL_SPLITS.set(cell, splits.sort((a, b) => a.at - b.at));
|
|
774
|
+
};
|
|
775
|
+
function markContinuedText(cell, add, page) {
|
|
776
|
+
if (!add.text.trim()) return;
|
|
777
|
+
const base = cell.text.trim() ? cell.text.length + 1 : 0;
|
|
778
|
+
setSplits(cell, [
|
|
779
|
+
..._nullishCoalesce(CELL_SPLITS.get(cell), () => ( [])),
|
|
780
|
+
{ at: base, page },
|
|
781
|
+
...(_nullishCoalesce(CELL_SPLITS.get(add), () => ( []))).map((s) => ({ at: base + s.at, page: s.page }))
|
|
782
|
+
]);
|
|
783
|
+
}
|
|
784
|
+
function rowStarts(t) {
|
|
785
|
+
const covered = /* @__PURE__ */ new Set();
|
|
786
|
+
const rows = [];
|
|
787
|
+
for (let r = 0; r < t.rows; r++) {
|
|
788
|
+
const starts = [];
|
|
789
|
+
for (let c = 0; c < t.cols; c++) {
|
|
790
|
+
if (covered.has(r * 1e5 + c)) continue;
|
|
791
|
+
const cell = _optionalChain([t, 'access', _60 => _60.cells, 'access', _61 => _61[r], 'optionalAccess', _62 => _62[c]]);
|
|
792
|
+
if (!cell) continue;
|
|
793
|
+
for (let dr = 0; dr < cell.rowSpan; dr++) for (let dc = 0; dc < cell.colSpan; dc++) if (dr || dc) covered.add((r + dr) * 1e5 + c + dc);
|
|
794
|
+
starts.push({ cell, c });
|
|
795
|
+
}
|
|
796
|
+
rows.push(starts);
|
|
797
|
+
}
|
|
798
|
+
return rows;
|
|
799
|
+
}
|
|
800
|
+
var covering = (t, r) => rowStarts(t).slice(0, r + 1).flatMap((starts, rr) => starts.filter((s) => rr + s.cell.rowSpan > r).map((s) => s.cell));
|
|
801
|
+
function cellPage(cell) {
|
|
802
|
+
const p = _chunkORGWGR4Kcjs.CELL_PAGES.get(cell);
|
|
803
|
+
if (p !== void 0 || !_optionalChain([cell, 'access', _63 => _63.blocks, 'optionalAccess', _64 => _64.length]) || cell.blocks.some((b) => b.pageNumber === void 0)) return p;
|
|
804
|
+
return Math.min(...cell.blocks.map((b) => b.pageNumber));
|
|
805
|
+
}
|
|
806
|
+
function tableRowPages(t, pageNumber) {
|
|
807
|
+
const pages = [];
|
|
808
|
+
let prev = pageNumber;
|
|
809
|
+
for (const starts of rowStarts(t)) {
|
|
810
|
+
let mark, text = false;
|
|
811
|
+
for (const { cell } of starts) {
|
|
812
|
+
const p = cellPage(cell);
|
|
813
|
+
if (p !== void 0) mark = Math.max(_nullishCoalesce(mark, () => ( p)), p);
|
|
814
|
+
else if (cell.text.trim() || _optionalChain([cell, 'access', _65 => _65.blocks, 'optionalAccess', _66 => _66.length])) text = true;
|
|
815
|
+
}
|
|
816
|
+
const page = _nullishCoalesce(mark, () => ( (text ? pageNumber : prev)));
|
|
817
|
+
prev = page !== void 0 && prev !== void 0 ? Math.max(prev, page) : _nullishCoalesce(page, () => ( prev));
|
|
818
|
+
pages.push(prev);
|
|
819
|
+
}
|
|
820
|
+
return pages;
|
|
821
|
+
}
|
|
822
|
+
function markJoinedPages(table, prev, curr) {
|
|
823
|
+
const pt = prev.table, ct = curr.table;
|
|
824
|
+
if (!curr.pageNumber || table.rows < pt.rows) return;
|
|
825
|
+
const pp = tableRowPages(pt, prev.pageNumber), cp = tableRowPages(ct, curr.pageNumber);
|
|
826
|
+
const off = table.rows - ct.rows;
|
|
827
|
+
const rows = rowStarts(table), ptRows = rowStarts(pt), ctRows = rowStarts(ct);
|
|
828
|
+
rows.forEach((starts, r) => {
|
|
829
|
+
const page2 = r < pt.rows ? pp[r] : cp[r - off];
|
|
830
|
+
for (const { cell } of starts) {
|
|
831
|
+
if (page2 !== void 0 && page2 !== prev.pageNumber) _chunkORGWGR4Kcjs.CELL_PAGES.set(cell, page2);
|
|
832
|
+
const src = _optionalChain([(r < pt.rows ? ptRows[r] : ctRows[r - off]), 'optionalAccess', _67 => _67.find, 'call', _68 => _68((s) => s.cell !== cell && s.cell.text === cell.text && CELL_SPLITS.has(s.cell))]);
|
|
833
|
+
if (src) setSplits(cell, relocate(src.cell, cell));
|
|
834
|
+
}
|
|
835
|
+
});
|
|
836
|
+
const cr = pt.rows - 1 - off, page = cp[cr];
|
|
837
|
+
if (cr < 0 || page === void 0 || page === prev.pageNumber) return;
|
|
838
|
+
const tails = ctRows[cr].filter((s) => s.cell.text.trim());
|
|
839
|
+
for (const { cell } of ctRows[cr]) for (const b of _nullishCoalesce(cell.blocks, () => ( []))) b.pageNumber ??= page;
|
|
840
|
+
const heads = covering(pt, pt.rows - 1);
|
|
841
|
+
for (const cell of covering(table, pt.rows - 1)) {
|
|
842
|
+
if (_optionalChain([cell, 'access', _69 => _69.blocks, 'optionalAccess', _70 => _70.length])) continue;
|
|
843
|
+
const head = heads.filter((h) => h.text.trim() && cell.text.startsWith(h.text.trimEnd()) && cell.text.trim().length > h.text.trim().length).sort((a, b) => b.text.length - a.text.length)[0];
|
|
844
|
+
if (!head) continue;
|
|
845
|
+
const from = head.text.trimEnd().length;
|
|
846
|
+
const hit = tails.map((t) => ({ t: t.cell, at: cell.text.indexOf(t.cell.text.trim().slice(0, 20), from) })).filter((h) => h.at >= from).sort((a, b) => a.at - b.at)[0];
|
|
847
|
+
if (!hit) continue;
|
|
848
|
+
setSplits(cell, [...relocate(head, cell), { at: hit.at, page }, ...relocate(hit.t, cell, hit.at)]);
|
|
849
|
+
}
|
|
850
|
+
}
|
|
851
|
+
function splitCell(cell, page) {
|
|
852
|
+
if (page === void 0) return null;
|
|
853
|
+
if (_optionalChain([cell, 'access', _71 => _71.blocks, 'optionalAccess', _72 => _72.length])) {
|
|
854
|
+
const k2 = cell.blocks.findIndex((b) => (_nullishCoalesce(b.pageNumber, () => ( page))) > page);
|
|
855
|
+
if (k2 <= 0) return null;
|
|
856
|
+
const head = cell.blocks.slice(0, k2), tail = cell.blocks.slice(k2);
|
|
857
|
+
const text = (bs) => bs.map((b) => _nullishCoalesce(b.text, () => ( ""))).filter(Boolean).join("\n");
|
|
858
|
+
return { head: { text: text(head), blocks: head }, tail: { text: text(tail), blocks: tail }, page: tail[0].pageNumber, rest: [] };
|
|
859
|
+
}
|
|
860
|
+
const splits = _nullishCoalesce(CELL_SPLITS.get(cell), () => ( []));
|
|
861
|
+
const k = splits.findIndex((s2) => s2.page > page && s2.at < cell.text.length);
|
|
862
|
+
if (k < 0) return null;
|
|
863
|
+
const s = splits[k];
|
|
864
|
+
const rest = cell.text.slice(s.at), lead = rest.length - rest.trimStart().length;
|
|
865
|
+
return {
|
|
866
|
+
head: { text: cell.text.slice(0, s.at).trimEnd() },
|
|
867
|
+
tail: { text: rest.trim() },
|
|
868
|
+
page: s.page,
|
|
869
|
+
rest: splits.slice(k + 1).map((x) => ({ at: x.at - s.at - lead, page: x.page })).filter((x) => x.at > 0)
|
|
870
|
+
};
|
|
871
|
+
}
|
|
872
|
+
function splitCrossPageRows(t, pageNumber) {
|
|
873
|
+
const pages = tableRowPages(t, pageNumber);
|
|
874
|
+
const rows = rowStarts(t);
|
|
875
|
+
for (let r = 0; r < t.rows; r++) {
|
|
876
|
+
const splits = rows[r].map((s) => ({ ...s, split: splitCell(s.cell, pages[r]) })).filter((s) => s.split);
|
|
877
|
+
if (!splits.length) continue;
|
|
878
|
+
const clone = (cell, patch) => {
|
|
879
|
+
const out = { ...cell, ...patch };
|
|
880
|
+
const p = _chunkORGWGR4Kcjs.CELL_PAGES.get(cell);
|
|
881
|
+
if (p !== void 0) _chunkORGWGR4Kcjs.CELL_PAGES.set(out, p);
|
|
882
|
+
if (!("text" in patch) && CELL_SPLITS.has(cell)) CELL_SPLITS.set(out, CELL_SPLITS.get(cell));
|
|
883
|
+
return out;
|
|
884
|
+
};
|
|
885
|
+
const e = Math.max(...splits.map((s) => r + s.cell.rowSpan - 1));
|
|
886
|
+
const cells = t.cells.map((row2) => row2.slice());
|
|
887
|
+
const row = Array.from({ length: t.cols }, () => ({ text: "", colSpan: 1, rowSpan: 1 }));
|
|
888
|
+
for (const { cell, c, split } of splits) {
|
|
889
|
+
cells[r][c] = clone(cell, split.head);
|
|
890
|
+
const tail = { ...cell, ...split.tail, rowSpan: 1 };
|
|
891
|
+
_chunkORGWGR4Kcjs.CELL_PAGES.set(tail, split.page);
|
|
892
|
+
setSplits(tail, split.rest);
|
|
893
|
+
row[c] = tail;
|
|
894
|
+
}
|
|
895
|
+
rows.forEach((starts, rr) => {
|
|
896
|
+
for (const { cell, c } of starts) {
|
|
897
|
+
if (splits.some((s) => s.cell === cell) || rr > e || rr + cell.rowSpan - 1 <= e) continue;
|
|
898
|
+
cells[rr][c] = clone(cells[rr][c], { rowSpan: cell.rowSpan + 1 });
|
|
899
|
+
}
|
|
900
|
+
});
|
|
901
|
+
cells.splice(e + 1, 0, row);
|
|
902
|
+
return splitCrossPageRows({ ...t, rows: t.rows + 1, cells }, pageNumber);
|
|
903
|
+
}
|
|
904
|
+
return t;
|
|
905
|
+
}
|
|
906
|
+
function splitPageTables(blocks) {
|
|
907
|
+
return blocks.flatMap((b) => {
|
|
908
|
+
if (b.type !== "table" || !b.table) return [b];
|
|
909
|
+
const t = splitCrossPageRows(b.table, b.pageNumber);
|
|
910
|
+
const pages = tableRowPages(t, b.pageNumber);
|
|
911
|
+
const cuts = [0];
|
|
912
|
+
for (let r = 1; r < t.rows; r++) if (pages[r] !== pages[r - 1]) cuts.push(r);
|
|
913
|
+
if (cuts.length === 1) return t === b.table ? [b] : [{ ...b, table: t }];
|
|
914
|
+
return cuts.map((from, k) => {
|
|
915
|
+
const end = _nullishCoalesce(cuts[k + 1], () => ( t.rows));
|
|
916
|
+
const cells = t.cells.slice(from, end).map((row, dr) => row.map((cell) => cell && from + dr + cell.rowSpan > end ? { ...cell, rowSpan: end - from - dr } : cell));
|
|
917
|
+
const table = { ...t, rows: end - from, cells, ...k ? { caption: void 0, captionBlocks: void 0 } : {} };
|
|
918
|
+
return { ...b, table, pageNumber: pages[from] };
|
|
919
|
+
});
|
|
920
|
+
});
|
|
921
|
+
}
|
|
922
|
+
|
|
761
923
|
// src/pdf/table-parts.ts
|
|
762
924
|
var flowText = (text) => text.replace(/<\/?u>|~~/g, "");
|
|
763
925
|
var PART_COL_TOL = 1;
|
|
@@ -768,7 +930,7 @@ function anchorsOf(table) {
|
|
|
768
930
|
for (let r = 0; r < table.rows; r++) {
|
|
769
931
|
for (let c = 0; c < table.cols; c++) {
|
|
770
932
|
if (covered.has(r * 1e5 + c)) continue;
|
|
771
|
-
const cell = _optionalChain([table, 'access',
|
|
933
|
+
const cell = _optionalChain([table, 'access', _73 => _73.cells, 'access', _74 => _74[r], 'optionalAccess', _75 => _75[c]]);
|
|
772
934
|
if (!cell) continue;
|
|
773
935
|
out.push({ r, c, rs: cell.rowSpan, cs: cell.colSpan, cell });
|
|
774
936
|
for (let dr = 0; dr < cell.rowSpan; dr++) {
|
|
@@ -845,24 +1007,24 @@ function joinSplitParts(prev, pcx, curr, ccx, dx = 0, prevBottom, lex) {
|
|
|
845
1007
|
if (r + dr < rows) owner[r + dr][dc] = placed;
|
|
846
1008
|
}
|
|
847
1009
|
grid[r][c1] = { ...a.cell, colSpan: c2 - c1, rowSpan: a.rs };
|
|
848
|
-
const lines =
|
|
849
|
-
if (lines)
|
|
850
|
-
if (
|
|
851
|
-
const edges =
|
|
1010
|
+
const lines = _chunk5PGOZBEQcjs.CELL_LINES.get(a.cell);
|
|
1011
|
+
if (lines) _chunk5PGOZBEQcjs.CELL_LINES.set(grid[r][c1], shift ? lines.map((l) => ({ ...l, l: l.l + shift, r: l.r + shift })) : lines);
|
|
1012
|
+
if (_chunk5PGOZBEQcjs.IMAGE_CELLS.has(a.cell)) _chunk5PGOZBEQcjs.IMAGE_CELLS.add(grid[r][c1]);
|
|
1013
|
+
const edges = _chunkORGWGR4Kcjs.CELL_EDGES.get(a.cell);
|
|
852
1014
|
if (edges) {
|
|
853
|
-
|
|
1015
|
+
_chunkORGWGR4Kcjs.CELL_EDGES.set(grid[r][c1], edges);
|
|
854
1016
|
edged = true;
|
|
855
1017
|
}
|
|
856
1018
|
return true;
|
|
857
1019
|
};
|
|
858
|
-
for (const a of pa) if (!
|
|
1020
|
+
for (const a of pa) if (!_chunk5PGOZBEQcjs.FILLER_CELLS.has(a.cell) && !place(a, pcx, 0)) return null;
|
|
859
1021
|
for (const a of ca) {
|
|
860
|
-
if (a.r < skip ||
|
|
1022
|
+
if (a.r < skip || _chunk5PGOZBEQcjs.FILLER_CELLS.has(a.cell)) continue;
|
|
861
1023
|
if (!place(a, cxU, prev.rows - skip, dx)) return null;
|
|
862
1024
|
}
|
|
863
1025
|
const first = prev.rows;
|
|
864
1026
|
for (let c = 0; c < cols; c++) {
|
|
865
|
-
const above = _optionalChain([owner, 'access',
|
|
1027
|
+
const above = _optionalChain([owner, 'access', _76 => _76[first - 1], 'optionalAccess', _77 => _77[c]]);
|
|
866
1028
|
if (!above) continue;
|
|
867
1029
|
let r = first;
|
|
868
1030
|
while (r < rows && owner[r][c] === null) r++;
|
|
@@ -881,9 +1043,9 @@ function joinSplitParts(prev, pcx, curr, ccx, dx = 0, prevBottom, lex) {
|
|
|
881
1043
|
const grown = { ...above, rs: newRs };
|
|
882
1044
|
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;
|
|
883
1045
|
}
|
|
884
|
-
for (let r = 0; r < rows; r++) for (let c = 0; c < cols; c++) if (owner[r][c] === null)
|
|
1046
|
+
for (let r = 0; r < rows; r++) for (let c = 0; c < cols; c++) if (owner[r][c] === null) _chunk5PGOZBEQcjs.FILLER_CELLS.add(grid[r][c]);
|
|
885
1047
|
if (edged) {
|
|
886
|
-
for (let r = 0; r < rows; r++) for (let c = 0; c < cols; c++) if (owner[r][c] === null)
|
|
1048
|
+
for (let r = 0; r < rows; r++) for (let c = 0; c < cols; c++) if (owner[r][c] === null) _chunkORGWGR4Kcjs.CELL_EDGES.set(grid[r][c], _chunk5PGOZBEQcjs.NO_EDGES);
|
|
887
1049
|
}
|
|
888
1050
|
for (let c = 0; c < cols && U[c + 1] <= pcx[0] + PART_COL_TOL; c++) {
|
|
889
1051
|
let r = prev.rows;
|
|
@@ -892,7 +1054,7 @@ function joinSplitParts(prev, pcx, curr, ccx, dx = 0, prevBottom, lex) {
|
|
|
892
1054
|
for (let rr = 0; rr < r; rr++) owner[rr][c] = through;
|
|
893
1055
|
}
|
|
894
1056
|
const table = { rows, cols, cells: grid, hasHeader: prev.hasHeader, ...prev.caption ? { caption: prev.caption } : {} };
|
|
895
|
-
const pr =
|
|
1057
|
+
const pr = _chunk5PGOZBEQcjs.ROW_RULES.get(prev), cr = _chunk5PGOZBEQcjs.ROW_RULES.get(curr);
|
|
896
1058
|
const shifted = dx !== 0;
|
|
897
1059
|
const cut = {
|
|
898
1060
|
open: !!pr && !!cr && !pr.bottom && !cr.top && pr.innerOpen + cr.innerOpen === 0 && pr.innerRuled + cr.innerRuled > 0,
|
|
@@ -903,7 +1065,7 @@ function joinSplitParts(prev, pcx, curr, ccx, dx = 0, prevBottom, lex) {
|
|
|
903
1065
|
if (rows > prev.rows && !split && prevBottom !== void 0 && mergeStraddlingCells(table, owner, prev.rows, prevBottom, lex, U)) split = mergeSplitRow(table, owner, prev.rows, U, true, { ...cut, open: false });
|
|
904
1066
|
if (pr && cr) {
|
|
905
1067
|
const cutRuled = pr.bottom || cr.top;
|
|
906
|
-
|
|
1068
|
+
_chunk5PGOZBEQcjs.ROW_RULES.set(table, { top: pr.top, bottom: cr.bottom, innerRuled: pr.innerRuled + cr.innerRuled + (!split && cutRuled ? 1 : 0), innerOpen: pr.innerOpen + cr.innerOpen + (!split && !cutRuled ? 1 : 0) });
|
|
907
1069
|
}
|
|
908
1070
|
return { table, colXs: U, split, header: ca.filter((a) => a.r < skip && a.cell.text.trim()).length >= 2 };
|
|
909
1071
|
}
|
|
@@ -957,8 +1119,8 @@ function mergeStraddlingCells(table, owner, first, prevBottom, lex, colXs) {
|
|
|
957
1119
|
if (!crossed.has(shape(u, d)) && !(u.rs >= 2 && u.c + u.cs <= firstNew && hasContent(a) && !hasContent(b))) {
|
|
958
1120
|
if (!straddles && !midWord) continue;
|
|
959
1121
|
if (u.r >= last && d.rs < 2) continue;
|
|
960
|
-
const U =
|
|
961
|
-
if (!_optionalChain([U, 'optionalAccess',
|
|
1122
|
+
const U = _chunk5PGOZBEQcjs.CELL_LINES.get(a);
|
|
1123
|
+
if (!_optionalChain([U, 'optionalAccess', _78 => _78.length]) || !hasContent(b)) continue;
|
|
962
1124
|
if (!(straddles && filledToBottom(U, prevBottom) && clauseContinues(a, b))) {
|
|
963
1125
|
if (U.length > STRADDLE_MAX_LINES) continue;
|
|
964
1126
|
const lu = U[U.length - 1];
|
|
@@ -1004,8 +1166,8 @@ function nextItemHead(prev, next) {
|
|
|
1004
1166
|
return false;
|
|
1005
1167
|
}
|
|
1006
1168
|
function continuesAcross(u, d, x1, x2) {
|
|
1007
|
-
const U =
|
|
1008
|
-
if (!_optionalChain([U, 'optionalAccess',
|
|
1169
|
+
const U = _chunk5PGOZBEQcjs.CELL_LINES.get(u), D = _chunk5PGOZBEQcjs.CELL_LINES.get(d);
|
|
1170
|
+
if (!_optionalChain([U, 'optionalAccess', _79 => _79.length]) || !_optionalChain([D, 'optionalAccess', _80 => _80.length])) return false;
|
|
1009
1171
|
const last = U[U.length - 1];
|
|
1010
1172
|
const fs = last.h || 10;
|
|
1011
1173
|
let minL = Infinity, maxR = -Infinity;
|
|
@@ -1022,7 +1184,7 @@ function continuesAcross(u, d, x1, x2) {
|
|
|
1022
1184
|
if (U.length === 1 && x2 - last.r > Math.max(FULL_LINE_EDGE_MIN, SINGLE_LINE_WORD_GAP * fs)) return false;
|
|
1023
1185
|
const indented = last.l - minL >= HANGING_MIN * fs;
|
|
1024
1186
|
if (last.r - last.l < FULL_LINE_MIN_FRAC * (indented ? x2 - last.l : x2 - x1)) return false;
|
|
1025
|
-
const newItem =
|
|
1187
|
+
const newItem = _chunk5PGOZBEQcjs.startsNewItem.call(void 0, u.text, d.text);
|
|
1026
1188
|
const all = D.length ? U.concat(D) : U;
|
|
1027
1189
|
const leftAligned = (l) => maxR - l.r > SHORT_LINE_GAP * fs && (l.l - minL <= fs || !newItem && all.some((o) => o !== l && Math.abs(o.l - l.l) <= HANGING_TOL && Math.abs(o.r - l.r) >= HANGING_MIN * fs));
|
|
1028
1190
|
const hanging = U.length >= 2 && U.every((l) => maxR - l.r <= FULL_LINE_TOL * fs) && indented && Math.abs(D[0].l - last.l) <= HANGING_TOL;
|
|
@@ -1039,12 +1201,12 @@ function outlineContinues(u, d) {
|
|
|
1039
1201
|
return U.length >= 2 && D.length >= 1 && U.some((l) => OUTLINE_HEAD.test(l)) && OUTLINE_ITEM.test(D[0]);
|
|
1040
1202
|
}
|
|
1041
1203
|
function lineEnded(c, x1, x2, next) {
|
|
1042
|
-
const L =
|
|
1204
|
+
const L = _chunk5PGOZBEQcjs.CELL_LINES.get(c);
|
|
1043
1205
|
if (!L || L.length !== 1) return false;
|
|
1044
1206
|
const l = L[0], h = l.h || 10;
|
|
1045
|
-
const d0 = next ? _optionalChain([
|
|
1207
|
+
const d0 = next ? _optionalChain([_chunk5PGOZBEQcjs.CELL_LINES, 'access', _81 => _81.get, 'call', _82 => _82(next), 'optionalAccess', _83 => _83[0]]) : void 0;
|
|
1046
1208
|
if (d0 && d0.l - l.l >= HANGING_MIN * h) return false;
|
|
1047
|
-
return x2 - l.r - (l.l - x1) >= Math.max(LABEL_ROOM, firstWordUnits(_nullishCoalesce(_optionalChain([next, 'optionalAccess',
|
|
1209
|
+
return x2 - l.r - (l.l - x1) >= Math.max(LABEL_ROOM, firstWordUnits(_nullishCoalesce(_optionalChain([next, 'optionalAccess', _84 => _84.text]), () => ( "")))) * h;
|
|
1048
1210
|
}
|
|
1049
1211
|
function firstWordUnits(text) {
|
|
1050
1212
|
const word = _nullishCoalesce(flowText(text).trim().replace(/^([(\[「『<〈])\s+/, "$1").split(/\s+/)[0], () => ( ""));
|
|
@@ -1053,14 +1215,14 @@ function firstWordUnits(text) {
|
|
|
1053
1215
|
return units;
|
|
1054
1216
|
}
|
|
1055
1217
|
function appendCell(a, b) {
|
|
1056
|
-
if (_optionalChain([a, 'access',
|
|
1057
|
-
const asBlocks = (c) => _optionalChain([c, 'access',
|
|
1218
|
+
if (_optionalChain([a, 'access', _85 => _85.blocks, 'optionalAccess', _86 => _86.length]) || _optionalChain([b, 'access', _87 => _87.blocks, 'optionalAccess', _88 => _88.length])) {
|
|
1219
|
+
const asBlocks = (c) => _optionalChain([c, 'access', _89 => _89.blocks, 'optionalAccess', _90 => _90.length]) ? c.blocks : c.text.split("\n").map((l) => l.trim()).filter(Boolean).map((text) => ({ type: "paragraph", text }));
|
|
1058
1220
|
a.blocks = [...asBlocks(a), ...asBlocks(b)];
|
|
1059
1221
|
}
|
|
1060
1222
|
if (b.text.trim()) a.text = a.text.trim() ? a.text + "\n" + b.text : b.text;
|
|
1061
|
-
|
|
1223
|
+
_chunk5PGOZBEQcjs.joinCellEdges.call(void 0, a, b);
|
|
1062
1224
|
}
|
|
1063
|
-
var hasContent = (cell) => !!cell.text.trim() || !!_optionalChain([cell, 'access',
|
|
1225
|
+
var hasContent = (cell) => !!cell.text.trim() || !!_optionalChain([cell, 'access', _91 => _91.blocks, 'optionalAccess', _92 => _92.length]) || _chunk5PGOZBEQcjs.IMAGE_CELLS.has(cell);
|
|
1064
1226
|
var CLAUSE_OPEN_ENDING = /(?:하는|되는|하고|하며|하여|되어|되고|되며|이며|으며|어야|아야|여야)$/;
|
|
1065
1227
|
var batchim = (ch) => {
|
|
1066
1228
|
const k = ch.charCodeAt(0) - 44032;
|
|
@@ -1068,13 +1230,13 @@ var batchim = (ch) => {
|
|
|
1068
1230
|
};
|
|
1069
1231
|
function clauseContinues(u, d) {
|
|
1070
1232
|
const tail = _nullishCoalesce(flowText(u.text).trim().split(/\s+/).pop(), () => ( "")), head = flowText(d.text).trim();
|
|
1071
|
-
if (!/^[가-힣]{2,}$/.test(tail) || !/^[가-힣]/.test(head) ||
|
|
1233
|
+
if (!/^[가-힣]{2,}$/.test(tail) || !/^[가-힣]/.test(head) || _chunk5PGOZBEQcjs.startsNewItem.call(void 0, u.text, head)) return false;
|
|
1072
1234
|
const last = tail[tail.length - 1], before = tail[tail.length - 2];
|
|
1073
1235
|
return last === "\uC744" && batchim(before) || last === "\uB97C" && !batchim(before) || CLAUSE_OPEN_ENDING.test(tail);
|
|
1074
1236
|
}
|
|
1075
1237
|
function wordOverflows(u, d, x1, x2) {
|
|
1076
|
-
const U =
|
|
1077
|
-
if (!_optionalChain([U, 'optionalAccess',
|
|
1238
|
+
const U = _chunk5PGOZBEQcjs.CELL_LINES.get(u);
|
|
1239
|
+
if (!_optionalChain([U, 'optionalAccess', _93 => _93.length]) || _chunk5PGOZBEQcjs.startsNewItem.call(void 0, u.text, d.text)) return false;
|
|
1078
1240
|
const last = U[U.length - 1], units = firstWordUnits(d.text);
|
|
1079
1241
|
return units > 0 && last.r - last.l + units * (last.h || 10) > x2 - x1;
|
|
1080
1242
|
}
|
|
@@ -1096,7 +1258,7 @@ function listContinues(u, d, multi = false) {
|
|
|
1096
1258
|
const marks = u.text.split("\n").map((l) => itemMark(l.trim()));
|
|
1097
1259
|
let last = -1, count = 0;
|
|
1098
1260
|
marks.forEach((m, i) => {
|
|
1099
|
-
if (_optionalChain([m, 'optionalAccess',
|
|
1261
|
+
if (_optionalChain([m, 'optionalAccess', _94 => _94.style]) === head.style) {
|
|
1100
1262
|
last = i;
|
|
1101
1263
|
count++;
|
|
1102
1264
|
}
|
|
@@ -1134,7 +1296,7 @@ function mergeSplitRow(table, owner, first, colXs, textOnly = false, cut = NO_CU
|
|
|
1134
1296
|
if (!carriedSplit) {
|
|
1135
1297
|
const norm = (c) => flowText(c.text).replace(/\s+/g, "");
|
|
1136
1298
|
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)))) return false;
|
|
1137
|
-
const oneLine = (c) => _optionalChain([
|
|
1299
|
+
const oneLine = (c) => _optionalChain([_chunk5PGOZBEQcjs.CELL_LINES, 'access', _95 => _95.get, 'call', _96 => _96(c), 'optionalAccess', _97 => _97.length]) === 1;
|
|
1138
1300
|
if (pairs.some(([u, d]) => nextItemHead(cell(u).text, cell(d).text)) && pairs.some(([u, d]) => hasContent(u.cell) && hasContent(d.cell) && oneLine(cell(u)) && oneLine(cell(d)) && norm(cell(u)) !== norm(cell(d)))) return false;
|
|
1139
1301
|
const flows = ([u, d]) => continuesAcross(cell(u), cell(d), colXs[u.c], colXs[u.c + u.cs]) || clauseContinues(cell(u), cell(d));
|
|
1140
1302
|
if (!(cut.open && !newCell)) {
|
|
@@ -1165,8 +1327,8 @@ function besideOwn(b, p, c) {
|
|
|
1165
1327
|
}
|
|
1166
1328
|
var PAGE_NUMBER_TEXT = /^[-–—]?\s*\d{1,4}\s*[-–—]?$/;
|
|
1167
1329
|
function pageNumberBetween(b, p, c, pageHeights) {
|
|
1168
|
-
if (b.type !== "paragraph" || !b.bbox || !PAGE_NUMBER_TEXT.test(_nullishCoalesce(_optionalChain([b, 'access',
|
|
1169
|
-
const h = b.pageNumber ? _optionalChain([pageHeights, 'optionalAccess',
|
|
1330
|
+
if (b.type !== "paragraph" || !b.bbox || !PAGE_NUMBER_TEXT.test(_nullishCoalesce(_optionalChain([b, 'access', _98 => _98.text, 'optionalAccess', _99 => _99.trim, 'call', _100 => _100()]), () => ( "")))) return false;
|
|
1331
|
+
const h = b.pageNumber ? _optionalChain([pageHeights, 'optionalAccess', _101 => _101.get, 'call', _102 => _102(b.pageNumber)]) : void 0;
|
|
1170
1332
|
if (!h) return false;
|
|
1171
1333
|
if (b.pageNumber === p.pageNumber) return b.bbox.y + b.bbox.height <= Math.min(p.bbox.y, h * PAGE_EDGE_BAND) + 1;
|
|
1172
1334
|
if (b.pageNumber === c.pageNumber) return b.bbox.y >= Math.max(c.bbox.y + c.bbox.height, h * (1 - PAGE_EDGE_BAND)) - 1;
|
|
@@ -1177,6 +1339,7 @@ function leftColumnOf(b, t) {
|
|
|
1177
1339
|
}
|
|
1178
1340
|
function placeJoined(blocks, i, j, table) {
|
|
1179
1341
|
const prev = blocks[i];
|
|
1342
|
+
markJoinedPages(table, prev, blocks[j]);
|
|
1180
1343
|
blocks[i] = { ...prev, table };
|
|
1181
1344
|
blocks.splice(j, 1);
|
|
1182
1345
|
let k = j - 1;
|
|
@@ -1189,7 +1352,7 @@ function insideTable(b, t) {
|
|
|
1189
1352
|
return b.bbox.x >= o.x - 1 && b.bbox.x + b.bbox.width <= o.x + o.width + 1 && b.bbox.y >= o.y - 1 && b.bbox.y + b.bbox.height <= o.y + o.height + 1;
|
|
1190
1353
|
}
|
|
1191
1354
|
function startsWithUnitRow(table) {
|
|
1192
|
-
return /^\s*\(\s*단위\s*[::]/.test(_nullishCoalesce(_optionalChain([table, 'access',
|
|
1355
|
+
return /^\s*\(\s*단위\s*[::]/.test(_nullishCoalesce(_optionalChain([table, 'access', _103 => _103.cells, 'access', _104 => _104[0], 'optionalAccess', _105 => _105[0], 'optionalAccess', _106 => _106.text]), () => ( ""))) && _optionalChain([table, 'access', _107 => _107.cells, 'access', _108 => _108[0], 'optionalAccess', _109 => _109.slice, 'call', _110 => _110(1), 'access', _111 => _111.every, 'call', _112 => _112((c) => !c.text.trim())]);
|
|
1193
1356
|
}
|
|
1194
1357
|
function sameHeadShape(a, b) {
|
|
1195
1358
|
if (!a || !b || a.length !== b.length) return false;
|
|
@@ -1209,7 +1372,7 @@ function mergeCrossPageTables(blocks, pageHeights, lex) {
|
|
|
1209
1372
|
const skip = (b) => b.type !== "table" || [blocks[i], tail].some((t) => insideTable(b, t) || leftColumnOf(b, t));
|
|
1210
1373
|
while (j < blocks.length && skip(blocks[j]) && (_nullishCoalesce(blocks[j].pageNumber, () => ( 0))) <= tail.pageNumber + 1) j++;
|
|
1211
1374
|
const curr = blocks[j];
|
|
1212
|
-
const prev = tail !== blocks[i] && _optionalChain([curr, 'optionalAccess',
|
|
1375
|
+
const prev = tail !== blocks[i] && _optionalChain([curr, 'optionalAccess', _113 => _113.pageNumber]) === tail.pageNumber ? blocks[i] : tail;
|
|
1213
1376
|
if (!prev.table || !prev.bbox || !prev.pageNumber) continue;
|
|
1214
1377
|
if (!curr || curr.type !== "table" || !curr.table || !curr.bbox || curr.pageNumber !== prev.pageNumber + 1) continue;
|
|
1215
1378
|
if (startsWithUnitRow(prev.table) && startsWithUnitRow(curr.table)) continue;
|
|
@@ -1218,19 +1381,19 @@ function mergeCrossPageTables(blocks, pageHeights, lex) {
|
|
|
1218
1381
|
placeJoined(blocks, i, j, joined);
|
|
1219
1382
|
continue;
|
|
1220
1383
|
}
|
|
1221
|
-
if (
|
|
1384
|
+
if (_chunk5PGOZBEQcjs.EMPTY_PARTS.has(curr.table)) {
|
|
1222
1385
|
blocks.splice(j, 1);
|
|
1223
1386
|
i++;
|
|
1224
1387
|
continue;
|
|
1225
1388
|
}
|
|
1226
1389
|
if (joined === null) continue;
|
|
1227
|
-
if (prev.table.cols !== curr.table.cols || prev.table.renderAsTable !== curr.table.renderAsTable ||
|
|
1390
|
+
if (prev.table.cols !== curr.table.cols || prev.table.renderAsTable !== curr.table.renderAsTable || _chunk5PGOZBEQcjs.EMPTY_PARTS.has(prev.table)) continue;
|
|
1228
1391
|
const width = Math.max(prev.bbox.width, curr.bbox.width, 1);
|
|
1229
1392
|
const leftDiff = Math.abs(prev.bbox.x - curr.bbox.x);
|
|
1230
1393
|
const rightDiff = Math.abs(prev.bbox.x + prev.bbox.width - (curr.bbox.x + curr.bbox.width));
|
|
1231
1394
|
if (leftDiff > width * NEIGHBOR_TABLE_EPSILON || rightDiff > width * NEIGHBOR_TABLE_EPSILON) continue;
|
|
1232
|
-
const px =
|
|
1233
|
-
if (px && cx && !shiftedSame(px, cx, !
|
|
1395
|
+
const px = _chunk5PGOZBEQcjs.TABLE_COLXS.get(prev.table), cx = _chunk5PGOZBEQcjs.TABLE_COLXS.get(curr.table);
|
|
1396
|
+
if (px && cx && !shiftedSame(px, cx, !_chunk5PGOZBEQcjs.CLIP_TABLES.has(prev.table) && !_chunk5PGOZBEQcjs.CLIP_TABLES.has(curr.table))) continue;
|
|
1234
1397
|
if (!rowTextsEqual(prev.table.cells[0], curr.table.cells[0]) && sameHeadShape(prev.table.cells[0], curr.table.cells[0])) continue;
|
|
1235
1398
|
let currCells = curr.table.cells;
|
|
1236
1399
|
const headRows = repeatedHeaderRows(prev.table, curr.table);
|
|
@@ -1241,16 +1404,16 @@ function mergeCrossPageTables(blocks, pageHeights, lex) {
|
|
|
1241
1404
|
blocks.splice(j, 1);
|
|
1242
1405
|
continue;
|
|
1243
1406
|
}
|
|
1244
|
-
if (px && cx && !
|
|
1407
|
+
if (px && cx && !_chunk5PGOZBEQcjs.CLIP_TABLES.has(prev.table) && !_chunk5PGOZBEQcjs.CLIP_TABLES.has(curr.table) && currCells.length < curr.table.cells.length && curr.table.cells[0].filter((c) => c.text.trim()).length >= 2 && prev.table.cells.at(-1).concat(currCells[0]).every((c) => c.rowSpan === 1 && c.colSpan === 1 && _chunk5PGOZBEQcjs.CELL_LINES.has(c))) {
|
|
1245
1408
|
const dx = px[0] - cx[0];
|
|
1246
1409
|
const part = joinSplitParts(prev.table, px, curr.table, cx.map((x) => x + dx), dx, void 0, lex);
|
|
1247
|
-
if (_optionalChain([part, 'optionalAccess',
|
|
1410
|
+
if (_optionalChain([part, 'optionalAccess', _114 => _114.split]) && part.table.rows === prev.table.rows + currCells.length - 1) {
|
|
1248
1411
|
const last = prev.table.rows - 1;
|
|
1249
1412
|
for (let c = 0; c < part.table.cols; c++) {
|
|
1250
|
-
const U =
|
|
1251
|
-
|
|
1413
|
+
const U = _chunk5PGOZBEQcjs.CELL_LINES.get(prev.table.cells[last][c]), D = _chunk5PGOZBEQcjs.CELL_LINES.get(currCells[0][c]);
|
|
1414
|
+
_chunk5PGOZBEQcjs.CELL_LINES.set(part.table.cells[last][c], U.concat(D.map((l) => ({ ...l, l: l.l + dx, r: l.r + dx }))));
|
|
1252
1415
|
}
|
|
1253
|
-
|
|
1416
|
+
_chunk5PGOZBEQcjs.TABLE_COLXS.set(part.table, part.colXs);
|
|
1254
1417
|
placeJoined(blocks, i, j, part.table);
|
|
1255
1418
|
continue;
|
|
1256
1419
|
}
|
|
@@ -1263,20 +1426,20 @@ function mergeCrossPageTables(blocks, pageHeights, lex) {
|
|
|
1263
1426
|
caption: prev.table.caption,
|
|
1264
1427
|
...prev.table.renderAsTable ? { renderAsTable: true } : {}
|
|
1265
1428
|
};
|
|
1266
|
-
if (_nullishCoalesce(px, () => ( cx)))
|
|
1267
|
-
if (
|
|
1429
|
+
if (_nullishCoalesce(px, () => ( cx))) _chunk5PGOZBEQcjs.TABLE_COLXS.set(merged, _nullishCoalesce(px, () => ( cx)));
|
|
1430
|
+
if (_chunk5PGOZBEQcjs.CLIP_TABLES.has(prev.table) || _chunk5PGOZBEQcjs.CLIP_TABLES.has(curr.table)) _chunk5PGOZBEQcjs.CLIP_TABLES.add(merged);
|
|
1268
1431
|
placeJoined(blocks, i, j, merged);
|
|
1269
1432
|
}
|
|
1270
1433
|
for (let i = blocks.length - 1; i >= 0; i--) {
|
|
1271
1434
|
const t = blocks[i].table;
|
|
1272
|
-
if (blocks[i].type === "table" && t &&
|
|
1435
|
+
if (blocks[i].type === "table" && t && _chunk5PGOZBEQcjs.EMPTY_PARTS.has(t)) blocks.splice(i, 1);
|
|
1273
1436
|
}
|
|
1274
1437
|
}
|
|
1275
1438
|
function mergeColumnFlow(blocks, pageHeights, lex) {
|
|
1276
1439
|
if (!pageHeights) return;
|
|
1277
1440
|
for (let i = 0; i < blocks.length; i++) {
|
|
1278
1441
|
const L = blocks[i];
|
|
1279
|
-
if (L.type !== "table" || !L.table || !L.bbox || !L.pageNumber || !
|
|
1442
|
+
if (L.type !== "table" || !L.table || !L.bbox || !L.pageNumber || !_chunk5PGOZBEQcjs.CLIP_TABLES.has(L.table) || _chunk5PGOZBEQcjs.EMPTY_PARTS.has(L.table)) continue;
|
|
1280
1443
|
const ph = pageHeights.get(L.pageNumber);
|
|
1281
1444
|
if (!ph || L.bbox.y > ph * PAGE_EDGE_BAND) continue;
|
|
1282
1445
|
let s0 = i, s1 = i;
|
|
@@ -1305,12 +1468,12 @@ function mergeColumnFlow(blocks, pageHeights, lex) {
|
|
|
1305
1468
|
}
|
|
1306
1469
|
function joinClipParts(prev, curr, pageHeights, lex) {
|
|
1307
1470
|
const pt = prev.table, ct = curr.table;
|
|
1308
|
-
if (!
|
|
1309
|
-
const px =
|
|
1471
|
+
if (!_chunk5PGOZBEQcjs.CLIP_TABLES.has(pt) || !_chunk5PGOZBEQcjs.CLIP_TABLES.has(ct)) return null;
|
|
1472
|
+
const px = _chunk5PGOZBEQcjs.TABLE_COLXS.get(pt), cx = _chunk5PGOZBEQcjs.TABLE_COLXS.get(ct);
|
|
1310
1473
|
if (!px || !cx) return null;
|
|
1311
1474
|
let xs = cx, shifted = false, dx = 0, foreign = false, within = false;
|
|
1312
1475
|
if (!shiftedSame(px, cx, false)) {
|
|
1313
|
-
if (!_optionalChain([pageHeights, 'optionalAccess',
|
|
1476
|
+
if (!_optionalChain([pageHeights, 'optionalAccess', _115 => _115.get, 'call', _116 => _116(prev.pageNumber)]) || !_optionalChain([pageHeights, 'optionalAccess', _117 => _117.get, 'call', _118 => _118(curr.pageNumber)])) return null;
|
|
1314
1477
|
dx = px[px.length - 1] - cx[cx.length - 1];
|
|
1315
1478
|
within = Math.abs(dx) > CONTINUATION_COL_TOL && cx.length >= 3 && cx.every((x) => px.some((p) => Math.abs(p - x) <= CONTINUATION_COL_TOL));
|
|
1316
1479
|
if (Math.abs(dx) > CONTINUATION_COL_TOL && !within) {
|
|
@@ -1322,19 +1485,19 @@ function joinClipParts(prev, curr, pageHeights, lex) {
|
|
|
1322
1485
|
const inner = b.slice(1, -1).map((x) => x + dx);
|
|
1323
1486
|
return inner.length > 0 && !inner.some((x) => px.some((p) => Math.abs(p - x) <= CONTINUATION_COL_TOL));
|
|
1324
1487
|
};
|
|
1325
|
-
foreign = unrelated(cx) && unrelated(_nullishCoalesce(
|
|
1488
|
+
foreign = unrelated(cx) && unrelated(_nullishCoalesce(_chunk5PGOZBEQcjs.PART_COLXS.get(ct), () => ( cx))) && (headingRow(_nullishCoalesce(ct.cells[0], () => ( []))) || px.length > FOREIGN_FIRST_ROW_CELLS && anchorsOf(ct).filter((a) => a.r === 0).length >= FOREIGN_FIRST_ROW_CELLS);
|
|
1326
1489
|
}
|
|
1327
|
-
const res = joinSplitParts(pt, px, ct, xs, dx, _optionalChain([prev, 'access',
|
|
1490
|
+
const res = joinSplitParts(pt, px, ct, xs, dx, _optionalChain([prev, 'access', _119 => _119.bbox, 'optionalAccess', _120 => _120.y]), lex);
|
|
1328
1491
|
if (!res || (shifted || foreign || within) && !res.split && !res.header) return null;
|
|
1329
|
-
|
|
1330
|
-
const ys =
|
|
1331
|
-
if (ys)
|
|
1332
|
-
|
|
1333
|
-
|
|
1492
|
+
_chunk5PGOZBEQcjs.TABLE_COLXS.set(res.table, res.colXs);
|
|
1493
|
+
const ys = _chunk5PGOZBEQcjs.TABLE_ROWYS.get(pt);
|
|
1494
|
+
if (ys) _chunk5PGOZBEQcjs.TABLE_ROWYS.set(res.table, ys);
|
|
1495
|
+
_chunk5PGOZBEQcjs.PART_COLXS.set(res.table, _nullishCoalesce(_chunk5PGOZBEQcjs.PART_COLXS.get(pt), () => ( px)));
|
|
1496
|
+
_chunk5PGOZBEQcjs.CLIP_TABLES.add(res.table);
|
|
1334
1497
|
return res.table;
|
|
1335
1498
|
}
|
|
1336
1499
|
function prevLacksLeftCols(prev, px, xs, pageHeights) {
|
|
1337
|
-
const ph = _optionalChain([pageHeights, 'optionalAccess',
|
|
1500
|
+
const ph = _optionalChain([pageHeights, 'optionalAccess', _121 => _121.get, 'call', _122 => _122(prev.pageNumber)]);
|
|
1338
1501
|
if (!ph || prev.bbox.y + prev.bbox.height < ph * (1 - PAGE_EDGE_BAND)) return false;
|
|
1339
1502
|
return xs[0] < px[0] && xs.slice(1, -1).some((x) => Math.abs(x - px[0]) <= CONTINUATION_COL_TOL);
|
|
1340
1503
|
}
|
|
@@ -1345,21 +1508,21 @@ function headingRow(row) {
|
|
|
1345
1508
|
}
|
|
1346
1509
|
var ANNEX_HEAD_RE = /^\s*[<\[(【]?\s*(?:붙\s*임|참\s*고|별\s*첨|별\s*지|별\s*표|첨\s*부|부\s*록)(?:\s*\d|\s*$|\s*[>\])】])|^\s*■/;
|
|
1347
1510
|
function looksContinued(prev, curr, pageHeights) {
|
|
1348
|
-
const ph = _optionalChain([pageHeights, 'optionalAccess',
|
|
1511
|
+
const ph = _optionalChain([pageHeights, 'optionalAccess', _123 => _123.get, 'call', _124 => _124(prev.pageNumber)]), ch = _optionalChain([pageHeights, 'optionalAccess', _125 => _125.get, 'call', _126 => _126(curr.pageNumber)]);
|
|
1349
1512
|
if (ph && ch && (prev.bbox.y > ph * PAGE_EDGE_BAND && !pushedLead(prev, curr) || curr.bbox.y + curr.bbox.height < ch * (1 - PAGE_EDGE_BAND))) return false;
|
|
1350
1513
|
const firstRow = _nullishCoalesce(curr.table.cells[0], () => ( []));
|
|
1351
|
-
const firstText = _nullishCoalesce(_optionalChain([firstRow, 'access',
|
|
1514
|
+
const firstText = _nullishCoalesce(_optionalChain([firstRow, 'access', _127 => _127.find, 'call', _128 => _128((c) => c.text.trim()), 'optionalAccess', _129 => _129.text]), () => ( ""));
|
|
1352
1515
|
if (!ANNEX_HEAD_RE.test(firstText)) return true;
|
|
1353
1516
|
const filled = firstRow.map((c) => flowText(c.text).replace(/\s+/g, "")).filter(Boolean);
|
|
1354
1517
|
return filled.length >= 2 && filled.every((t) => t === filled[0]);
|
|
1355
1518
|
}
|
|
1356
1519
|
function pushedLead(prev, curr) {
|
|
1357
|
-
if (!
|
|
1520
|
+
if (!_chunk5PGOZBEQcjs.CLIP_TABLES.has(prev.table) || !_chunk5PGOZBEQcjs.CLIP_TABLES.has(curr.table)) return false;
|
|
1358
1521
|
const lead = leadRows(curr.table);
|
|
1359
1522
|
return lead.image && lead.height > prev.bbox.y;
|
|
1360
1523
|
}
|
|
1361
1524
|
function leadRows(t) {
|
|
1362
|
-
const ys =
|
|
1525
|
+
const ys = _chunk5PGOZBEQcjs.TABLE_ROWYS.get(t);
|
|
1363
1526
|
if (!ys || ys.length < 2) return { height: 0, image: false };
|
|
1364
1527
|
const anchors = anchorsOf(t);
|
|
1365
1528
|
let end = 1, image = false;
|
|
@@ -1367,17 +1530,17 @@ function leadRows(t) {
|
|
|
1367
1530
|
for (const a of anchors) {
|
|
1368
1531
|
if (a.r !== r) continue;
|
|
1369
1532
|
end = Math.max(end, r + a.rs);
|
|
1370
|
-
if (
|
|
1533
|
+
if (_chunk5PGOZBEQcjs.IMAGE_CELLS.has(a.cell)) image = true;
|
|
1371
1534
|
}
|
|
1372
1535
|
}
|
|
1373
1536
|
return { height: ys[0] - ys[Math.min(end, ys.length - 1)], image };
|
|
1374
1537
|
}
|
|
1375
1538
|
function tailOf(b) {
|
|
1376
|
-
const t = b.table &&
|
|
1539
|
+
const t = b.table && _chunk5PGOZBEQcjs.TABLE_TAIL.get(b.table);
|
|
1377
1540
|
return t && b.bbox ? { ...b, pageNumber: t.page, bbox: { ...b.bbox, page: t.page, y: t.y, height: t.height } } : b;
|
|
1378
1541
|
}
|
|
1379
1542
|
function firstRowSig(t) {
|
|
1380
|
-
const x =
|
|
1543
|
+
const x = _chunk5PGOZBEQcjs.TABLE_COLXS.get(t);
|
|
1381
1544
|
if (!x || x.length !== t.cols + 1) return null;
|
|
1382
1545
|
return anchorsOf(t).filter((a) => a.r === 0).map((a) => ({ x1: x[a.c], x2: x[a.c + a.cs], t: flowText(a.cell.text).replace(/\s+/g, "") }));
|
|
1383
1546
|
}
|
|
@@ -1402,9 +1565,9 @@ function restartsTable(blocks, i, curr, pageHeights) {
|
|
|
1402
1565
|
}
|
|
1403
1566
|
function restartsTitledForm(head, curr) {
|
|
1404
1567
|
if (head.rows < 2 || curr.rows < 2 || head.cols !== curr.cols) return false;
|
|
1405
|
-
const full = (t) => _optionalChain([t, 'access',
|
|
1568
|
+
const full = (t) => _optionalChain([t, 'access', _130 => _130.cells, 'access', _131 => _131[0], 'access', _132 => _132[0], 'optionalAccess', _133 => _133.colSpan]) === t.cols;
|
|
1406
1569
|
if (!full(head) || !full(curr)) return false;
|
|
1407
|
-
const norm = (c) => flowText(_nullishCoalesce(_optionalChain([c, 'optionalAccess',
|
|
1570
|
+
const norm = (c) => flowText(_nullishCoalesce(_optionalChain([c, 'optionalAccess', _134 => _134.text]), () => ( ""))).replace(/\s+/g, "");
|
|
1408
1571
|
const ht = norm(head.cells[0][0]), ct = norm(curr.cells[0][0]);
|
|
1409
1572
|
if (!ht || !ct || ht === ct) return false;
|
|
1410
1573
|
const titleLike = (t) => t.length <= TITLE_ROW_MAX_CHARS && !/^[ㅇ○◦•·\-–※*□■▪☞]/.test(t);
|
|
@@ -1430,7 +1593,7 @@ function chainHead(blocks, i, pageHeights) {
|
|
|
1430
1593
|
if (pb.pageNumber !== (_nullishCoalesce(cur.pageNumber, () => ( 0))) - 1) break;
|
|
1431
1594
|
if (!blocks.slice(p + 1, k).every((b) => besideOwn(b, pb, cur) || insideTable(b, pb) || pageNumberBetween(b, pb, cur, pageHeights))) break;
|
|
1432
1595
|
if (!looksContinued(pb, cur, pageHeights)) break;
|
|
1433
|
-
const px =
|
|
1596
|
+
const px = _chunk5PGOZBEQcjs.TABLE_COLXS.get(pb.table), cx = _chunk5PGOZBEQcjs.TABLE_COLXS.get(cur.table);
|
|
1434
1597
|
if (!px || !cx) break;
|
|
1435
1598
|
const dx = px[px.length - 1] - cx[cx.length - 1];
|
|
1436
1599
|
if (!shiftedSame(px, cx) && !px.some((x) => Math.abs(x - (cx[0] + dx)) <= CONTINUATION_COL_TOL) && !prevLacksLeftCols(pb, px, cx, pageHeights)) break;
|
|
@@ -1447,7 +1610,7 @@ function continueRowSpans(prevCells, currCells) {
|
|
|
1447
1610
|
if (hasContent(cell) || (cell.rowSpan || 1) < 2) continue;
|
|
1448
1611
|
let anchor;
|
|
1449
1612
|
for (let r = last - 1; r >= 0 && !anchor; r--) {
|
|
1450
|
-
const a = _optionalChain([prevCells, 'access',
|
|
1613
|
+
const a = _optionalChain([prevCells, 'access', _135 => _135[r], 'optionalAccess', _136 => _136[c]]);
|
|
1451
1614
|
if (a && r + (a.rowSpan || 1) === last && (a.colSpan || 1) === (cell.colSpan || 1) && (hasContent(a) || a.rowSpan >= 2)) anchor = a;
|
|
1452
1615
|
}
|
|
1453
1616
|
if (!anchor) continue;
|
|
@@ -1501,12 +1664,12 @@ var RESTART_LOOKBACK_PAGES = 5;
|
|
|
1501
1664
|
var COL_MATCH_TOL = 0.5;
|
|
1502
1665
|
var CONTINUED_TABLE_PAGE_BAND = 0.16;
|
|
1503
1666
|
function lastRowCell(t, x1, x2) {
|
|
1504
|
-
const xs =
|
|
1667
|
+
const xs = _chunk5PGOZBEQcjs.TABLE_COLXS.get(t);
|
|
1505
1668
|
const covered = /* @__PURE__ */ new Set();
|
|
1506
1669
|
for (let r = 0; r < t.rows; r++) {
|
|
1507
1670
|
for (let c = 0; c < t.cols; c++) {
|
|
1508
1671
|
if (covered.has(r * 1e5 + c)) continue;
|
|
1509
|
-
const cell = _optionalChain([t, 'access',
|
|
1672
|
+
const cell = _optionalChain([t, 'access', _137 => _137.cells, 'access', _138 => _138[r], 'optionalAccess', _139 => _139[c]]);
|
|
1510
1673
|
if (!cell) continue;
|
|
1511
1674
|
for (let dr = 0; dr < cell.rowSpan; dr++) for (let dc = 0; dc < cell.colSpan; dc++) covered.add((r + dr) * 1e5 + c + dc);
|
|
1512
1675
|
if (r + cell.rowSpan !== t.rows) continue;
|
|
@@ -1519,23 +1682,24 @@ var cellBlocks = (cell, pageNumber) => _nullishCoalesce(cell.blocks, () => ( cel
|
|
|
1519
1682
|
function mergeContinuedCells(blocks, pageHeights) {
|
|
1520
1683
|
for (let j = blocks.length - 1; j > 0; j--) {
|
|
1521
1684
|
const part = blocks[j];
|
|
1522
|
-
const from = part.table ?
|
|
1685
|
+
const from = part.table ? _chunk5PGOZBEQcjs.CONT_PARTS.get(part.table) : void 0;
|
|
1523
1686
|
if (!from || !part.table) continue;
|
|
1524
1687
|
let i = j - 1;
|
|
1525
1688
|
while (i >= 0 && blocks[i].type !== "table") i--;
|
|
1526
1689
|
const prev = blocks[i];
|
|
1527
1690
|
if (i < 0 || !prev.table || prev.pageNumber !== (_nullishCoalesce(part.pageNumber, () => ( 0))) - 1) continue;
|
|
1528
1691
|
const cell = lastRowCell(prev.table, from.x1, from.x2);
|
|
1529
|
-
const add = _optionalChain([part, 'access',
|
|
1692
|
+
const add = _optionalChain([part, 'access', _140 => _140.table, 'access', _141 => _141.cells, 'access', _142 => _142[0], 'optionalAccess', _143 => _143[0]]);
|
|
1530
1693
|
if (!cell || !add) continue;
|
|
1531
1694
|
const at = cell.blocks || add.blocks ? cellBlocks(cell, prev.pageNumber).length : -1;
|
|
1532
1695
|
if (cell.blocks || add.blocks) cell.blocks = [...cellBlocks(cell, prev.pageNumber), ...cellBlocks(add, part.pageNumber)];
|
|
1696
|
+
else if (part.pageNumber) markContinuedText(cell, add, part.pageNumber);
|
|
1533
1697
|
cell.text = [cell.text, add.text].filter((s) => s.trim()).join("\n");
|
|
1534
|
-
|
|
1535
|
-
const lines =
|
|
1536
|
-
if (_optionalChain([lines, 'optionalAccess',
|
|
1537
|
-
if (part.pageNumber && part.bbox)
|
|
1538
|
-
if (cell.text.trim() || _optionalChain([cell, 'access',
|
|
1698
|
+
_chunk5PGOZBEQcjs.joinCellEdges.call(void 0, cell, add);
|
|
1699
|
+
const lines = _chunk5PGOZBEQcjs.CELL_LINES.get(add);
|
|
1700
|
+
if (_optionalChain([lines, 'optionalAccess', _144 => _144.length])) _chunk5PGOZBEQcjs.CELL_LINES.set(cell, [..._nullishCoalesce(_chunk5PGOZBEQcjs.CELL_LINES.get(cell), () => ( [])), ...lines]);
|
|
1701
|
+
if (part.pageNumber && part.bbox) _chunk5PGOZBEQcjs.TABLE_TAIL.set(prev.table, _nullishCoalesce(_chunk5PGOZBEQcjs.TABLE_TAIL.get(part.table), () => ( { page: part.pageNumber, y: part.bbox.y, height: part.bbox.height })));
|
|
1702
|
+
if (cell.text.trim() || _optionalChain([cell, 'access', _145 => _145.blocks, 'optionalAccess', _146 => _146.length])) _chunk5PGOZBEQcjs.EMPTY_PARTS.delete(prev.table);
|
|
1539
1703
|
blocks.splice(j, 1);
|
|
1540
1704
|
if (cell.blocks && at > 0) {
|
|
1541
1705
|
const nextAt = cell.blocks[at];
|
|
@@ -1547,27 +1711,27 @@ function mergeContinuedCells(blocks, pageHeights) {
|
|
|
1547
1711
|
}
|
|
1548
1712
|
function unwrapContinuedTable(blocks, at, pageHeights) {
|
|
1549
1713
|
const prev = blocks[at - 1], frame = blocks[at];
|
|
1550
|
-
if (!_optionalChain([prev, 'optionalAccess',
|
|
1551
|
-
const inner = _optionalChain([frame, 'access',
|
|
1552
|
-
const next = _optionalChain([inner, 'optionalAccess',
|
|
1553
|
-
if (!inner || !_optionalChain([next, 'optionalAccess',
|
|
1554
|
-
const px =
|
|
1714
|
+
if (!_optionalChain([prev, 'optionalAccess', _147 => _147.table]) || !_optionalChain([frame, 'optionalAccess', _148 => _148.table]) || frame.table.rows !== 1 || frame.table.cols !== 1 || !_chunk5PGOZBEQcjs.CLIP_TABLES.has(frame.table)) return;
|
|
1715
|
+
const inner = _optionalChain([frame, 'access', _149 => _149.table, 'access', _150 => _150.cells, 'access', _151 => _151[0], 'optionalAccess', _152 => _152[0], 'optionalAccess', _153 => _153.blocks]);
|
|
1716
|
+
const next = _optionalChain([inner, 'optionalAccess', _154 => _154[0]]);
|
|
1717
|
+
if (!inner || !_optionalChain([next, 'optionalAccess', _155 => _155.table]) || !prev.bbox || !next.bbox || !prev.pageNumber || next.pageNumber !== prev.pageNumber + 1 || !_chunk5PGOZBEQcjs.CLIP_TABLES.has(prev.table) || !_chunk5PGOZBEQcjs.CLIP_TABLES.has(next.table) || prev.table.cols !== next.table.cols) return;
|
|
1718
|
+
const px = _chunk5PGOZBEQcjs.TABLE_COLXS.get(prev.table), nx = _chunk5PGOZBEQcjs.TABLE_COLXS.get(next.table);
|
|
1555
1719
|
if (!px || !nx || px.length !== nx.length || px.some((x, i) => Math.abs(x - nx[i]) > COL_MATCH_TOL)) return;
|
|
1556
|
-
const ph = _optionalChain([pageHeights, 'optionalAccess',
|
|
1720
|
+
const ph = _optionalChain([pageHeights, 'optionalAccess', _156 => _156.get, 'call', _157 => _157(prev.pageNumber)]), nh = _optionalChain([pageHeights, 'optionalAccess', _158 => _158.get, 'call', _159 => _159(next.pageNumber)]);
|
|
1557
1721
|
if (!ph || !nh || prev.bbox.y > ph * CONTINUED_TABLE_PAGE_BAND || next.bbox.y + next.bbox.height < nh * (1 - CONTINUED_TABLE_PAGE_BAND)) return;
|
|
1558
1722
|
blocks.splice(at, 1, ...inner);
|
|
1559
1723
|
}
|
|
1560
1724
|
function fillNestedContinuation(blocks, at) {
|
|
1561
1725
|
const prev = blocks[at - 1], next = blocks[at];
|
|
1562
|
-
const t = _optionalChain([prev, 'optionalAccess',
|
|
1563
|
-
if (!t || !u || u.rows !== 1 || u.cols !== 1 || !
|
|
1564
|
-
const xs =
|
|
1726
|
+
const t = _optionalChain([prev, 'optionalAccess', _160 => _160.table]), u = _optionalChain([next, 'optionalAccess', _161 => _161.table]);
|
|
1727
|
+
if (!t || !u || u.rows !== 1 || u.cols !== 1 || !_chunk5PGOZBEQcjs.CLIP_TABLES.has(t) || !_chunk5PGOZBEQcjs.CLIP_TABLES.has(u) || next.pageNumber !== (_nullishCoalesce(prev.pageNumber, () => ( 0))) + 1) return;
|
|
1728
|
+
const xs = _chunk5PGOZBEQcjs.TABLE_COLXS.get(u);
|
|
1565
1729
|
const cell = xs ? lastRowCell(t, xs[0], xs[xs.length - 1]) : void 0;
|
|
1566
|
-
const add = _optionalChain([u, 'access',
|
|
1567
|
-
if (!cell || !add || cell.text.trim() || _optionalChain([cell, 'access',
|
|
1730
|
+
const add = _optionalChain([u, 'access', _162 => _162.cells, 'access', _163 => _163[0], 'optionalAccess', _164 => _164[0]]);
|
|
1731
|
+
if (!cell || !add || cell.text.trim() || _optionalChain([cell, 'access', _165 => _165.blocks, 'optionalAccess', _166 => _166.length])) return;
|
|
1568
1732
|
cell.text = add.text;
|
|
1569
1733
|
if (add.blocks) cell.blocks = add.blocks;
|
|
1570
|
-
|
|
1734
|
+
_chunk5PGOZBEQcjs.joinCellEdges.call(void 0, cell, add);
|
|
1571
1735
|
blocks.splice(at, 1);
|
|
1572
1736
|
}
|
|
1573
1737
|
|
|
@@ -1587,15 +1751,15 @@ function selectionContextPages(selected, pageCount) {
|
|
|
1587
1751
|
function marginContextBlocks(raw, page, view) {
|
|
1588
1752
|
const [x1, y1, x2, y2] = view;
|
|
1589
1753
|
const width = x2 - x1, height = y2 - y1;
|
|
1590
|
-
const items =
|
|
1754
|
+
const items = _chunk5PGOZBEQcjs.filterHiddenText.call(void 0, _chunk5PGOZBEQcjs.normalizeItems.call(void 0, raw), width, height, x1, y1).visible;
|
|
1591
1755
|
for (const item of items) {
|
|
1592
1756
|
item.x -= x1;
|
|
1593
1757
|
item.y -= y1;
|
|
1594
1758
|
}
|
|
1595
|
-
return
|
|
1596
|
-
const bbox =
|
|
1759
|
+
return _chunk5PGOZBEQcjs.groupByY.call(void 0, items).flatMap((line) => {
|
|
1760
|
+
const bbox = _chunk5PGOZBEQcjs.computeBBox.call(void 0, line, page);
|
|
1597
1761
|
if (bbox.y + bbox.height < height * 0.88 && bbox.y > height * 0.12) return [];
|
|
1598
|
-
return [{ type: "paragraph", text:
|
|
1762
|
+
return [{ type: "paragraph", text: _chunk5PGOZBEQcjs.mergeLineSimple.call(void 0, line), pageNumber: page, bbox, style: _chunk5PGOZBEQcjs.dominantStyle.call(void 0, line) }];
|
|
1599
1763
|
});
|
|
1600
1764
|
}
|
|
1601
1765
|
|
|
@@ -1631,7 +1795,7 @@ var WINANSI_REVERSE = {
|
|
|
1631
1795
|
};
|
|
1632
1796
|
function symbolFontTable(fontName) {
|
|
1633
1797
|
if (!fontName) return void 0;
|
|
1634
|
-
if (/wingdings(?![\s-]*[23])/i.test(fontName)) return
|
|
1798
|
+
if (/wingdings(?![\s-]*[23])/i.test(fontName)) return _chunkORGWGR4Kcjs.WINGDINGS;
|
|
1635
1799
|
return void 0;
|
|
1636
1800
|
}
|
|
1637
1801
|
function remapSymbolText(text, table) {
|
|
@@ -1759,7 +1923,7 @@ function layout(toks) {
|
|
|
1759
1923
|
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);
|
|
1760
1924
|
if (!bar) continue;
|
|
1761
1925
|
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);
|
|
1762
|
-
const tok = { text: `\\sqrt{${linear(inner)}}`, x: rt.x, w: bar.x + bar.w - rt.x, y: _nullishCoalesce(_optionalChain([inner, 'access',
|
|
1926
|
+
const tok = { text: `\\sqrt{${linear(inner)}}`, x: rt.x, w: bar.x + bar.w - rt.x, y: _nullishCoalesce(_optionalChain([inner, 'access', _167 => _167[0], 'optionalAccess', _168 => _168.y]), () => ( rt.y)), size: Math.max(rt.size, ...inner.map((t) => t.size)), bar: false };
|
|
1763
1927
|
rest = [...rest.filter((t) => t !== rt && t !== bar && !inner.includes(t)), tok];
|
|
1764
1928
|
}
|
|
1765
1929
|
const bars = rest.filter((t) => t.bar).sort((a, b) => a.w - b.w);
|
|
@@ -1861,7 +2025,7 @@ function wrapEquationRuns(items, faceName) {
|
|
|
1861
2025
|
for (const i of mains) ys.set(i.y, (_nullishCoalesce(ys.get(i.y), () => ( 0))) + 1);
|
|
1862
2026
|
const top = [...ys].sort((p, q) => q[1] - p[1]);
|
|
1863
2027
|
const bar = cur.find(isBarItem);
|
|
1864
|
-
const lineY = bar && top.length > 1 && top[0][1] === top[1][1] ? Math.round(bar.y + size * 0.3) : _nullishCoalesce(_optionalChain([top, 'access',
|
|
2028
|
+
const lineY = bar && top.length > 1 && top[0][1] === top[1][1] ? Math.round(bar.y + size * 0.3) : _nullishCoalesce(_optionalChain([top, 'access', _169 => _169[0], 'optionalAccess', _170 => _170[0]]), () => ( cur[0].y));
|
|
1865
2029
|
const base = { ..._nullishCoalesce(mains[0], () => ( cur[0])), y: lineY, fontSize: size || cur[0].fontSize };
|
|
1866
2030
|
const x1 = Math.min(...cur.map((i) => i.x)), x2 = Math.max(...cur.map((i) => i.x + i.w));
|
|
1867
2031
|
added.push({ ...base, text: `$${tex}$`, x: x1, w: x2 - x1, hasSpaceBefore: true });
|
|
@@ -2212,7 +2376,7 @@ function joinVerticalColumns(items) {
|
|
|
2212
2376
|
const groups = [];
|
|
2213
2377
|
for (const col of columns) {
|
|
2214
2378
|
const g2 = groups[groups.length - 1];
|
|
2215
|
-
const last = _optionalChain([g2, 'optionalAccess',
|
|
2379
|
+
const last = _optionalChain([g2, 'optionalAccess', _171 => _171[g2.length - 1]]);
|
|
2216
2380
|
const fs = col.items[0].fontSize;
|
|
2217
2381
|
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);
|
|
2218
2382
|
else groups.push([col]);
|
|
@@ -2398,7 +2562,7 @@ function relocateEndnotes(blocks) {
|
|
|
2398
2562
|
}
|
|
2399
2563
|
const shapes = /* @__PURE__ */ new Map();
|
|
2400
2564
|
for (const h of heads) shapes.set(h.shape, (_nullishCoalesce(shapes.get(h.shape), () => ( 0))) + 1);
|
|
2401
|
-
const main = _optionalChain([[...shapes], 'access',
|
|
2565
|
+
const main = _optionalChain([[...shapes], 'access', _172 => _172.sort, 'call', _173 => _173((a, b) => b[1] - a[1]), 'access', _174 => _174[0], 'optionalAccess', _175 => _175[0]]);
|
|
2402
2566
|
if (!main || !/#/.test(main)) return blocks;
|
|
2403
2567
|
const lastRun = (hs) => {
|
|
2404
2568
|
let run2 = [];
|
|
@@ -2536,7 +2700,7 @@ function inlineFootnotes(blocks, pages) {
|
|
|
2536
2700
|
open = true;
|
|
2537
2701
|
continue;
|
|
2538
2702
|
}
|
|
2539
|
-
const prev = pb[j - 1], line = (_nullishCoalesce(_nullishCoalesce(_optionalChain([b, 'access',
|
|
2703
|
+
const prev = pb[j - 1], line = (_nullishCoalesce(_nullishCoalesce(_optionalChain([b, 'access', _176 => _176.style, 'optionalAccess', _177 => _177.fontSize]), () => ( _optionalChain([b, 'access', _178 => _178.bbox, 'optionalAccess', _179 => _179.height]))), () => ( 10))) * 1.5;
|
|
2540
2704
|
if (open && b.bbox && prev.bbox && prev.bbox.y - top(b) <= line && !/^[-–—\s\d]+$/.test(b.text)) {
|
|
2541
2705
|
notes[notes.length - 1].text += " " + b.text.trim();
|
|
2542
2706
|
notes[notes.length - 1].blocks.push(b);
|
|
@@ -2559,7 +2723,7 @@ var CAPTION = /^(?:Table|Figure|Fig\.?)\s*\d+(?:\.\d+)*\s*[.:]/i;
|
|
|
2559
2723
|
var EQUATION_NUMBER = /\t\(\d{1,3}[a-z]?\)\s*$/;
|
|
2560
2724
|
var DISPLAY_MATH = /=|[√∑∏∫∂∇≤≥≈≠∈∀∃]/;
|
|
2561
2725
|
function isRunningHead(block, page, pageHeight) {
|
|
2562
|
-
const box = block.bbox, text = _optionalChain([block, 'access',
|
|
2726
|
+
const box = block.bbox, text = _optionalChain([block, 'access', _180 => _180.text, 'optionalAccess', _181 => _181.trim, 'call', _182 => _182()]);
|
|
2563
2727
|
if (!box || !text || !pageHeight) return false;
|
|
2564
2728
|
const top = box.y + box.height >= pageHeight * 0.9;
|
|
2565
2729
|
const bottom = box.y <= pageHeight * 0.1;
|
|
@@ -2567,7 +2731,7 @@ function isRunningHead(block, page, pageHeight) {
|
|
|
2567
2731
|
const others = page.filter((o) => o !== block && o.bbox && o.type !== "image" && o.type !== "separator");
|
|
2568
2732
|
if (top && others.some((o) => o.bbox.y + o.bbox.height > box.y + box.height)) return false;
|
|
2569
2733
|
if (bottom && others.some((o) => o.bbox.y < box.y)) return false;
|
|
2570
|
-
if (bottom && box.height <= (_nullishCoalesce(_optionalChain([block, 'access',
|
|
2734
|
+
if (bottom && box.height <= (_nullishCoalesce(_optionalChain([block, 'access', _183 => _183.style, 'optionalAccess', _184 => _184.fontSize]), () => ( 0))) * 1.6) return true;
|
|
2571
2735
|
if (!text.includes(" ")) return false;
|
|
2572
2736
|
const parts = text.split(/\t+/).map((part) => part.trim()).filter(Boolean);
|
|
2573
2737
|
if (parts.length >= 2 && (PAGE_NUMBER.test(parts[0]) || PAGE_NUMBER.test(parts[parts.length - 1]))) return true;
|
|
@@ -2576,7 +2740,7 @@ function isRunningHead(block, page, pageHeight) {
|
|
|
2576
2740
|
return right > left && box.width >= (right - left) * 0.6;
|
|
2577
2741
|
}
|
|
2578
2742
|
function unbalancedClose(text) {
|
|
2579
|
-
return (_nullishCoalesce(_optionalChain([text, 'access',
|
|
2743
|
+
return (_nullishCoalesce(_optionalChain([text, 'access', _185 => _185.match, 'call', _186 => _186(/\)/g), 'optionalAccess', _187 => _187.length]), () => ( 0))) > (_nullishCoalesce(_optionalChain([text, 'access', _188 => _188.match, 'call', _189 => _189(/\(/g), 'optionalAccess', _190 => _190.length]), () => ( 0)));
|
|
2580
2744
|
}
|
|
2581
2745
|
function demoteNonHeadingRoles(blocks, pageHeights, faceNames) {
|
|
2582
2746
|
const byPage = /* @__PURE__ */ new Map();
|
|
@@ -2592,7 +2756,7 @@ function demoteNonHeadingRoles(blocks, pageHeights, faceNames) {
|
|
|
2592
2756
|
const sizes = /* @__PURE__ */ new Map();
|
|
2593
2757
|
let proseChars = 0;
|
|
2594
2758
|
for (const b of page) {
|
|
2595
|
-
if (b.type !== "paragraph" && b.type !== "heading" || !b.text || !_optionalChain([b, 'access',
|
|
2759
|
+
if (b.type !== "paragraph" && b.type !== "heading" || !b.text || !_optionalChain([b, 'access', _191 => _191.style, 'optionalAccess', _192 => _192.fontName]) || !b.style.fontSize) continue;
|
|
2596
2760
|
const key2 = `${b.style.fontName}:${b.style.fontSize}`;
|
|
2597
2761
|
chars.set(key2, (_nullishCoalesce(chars.get(key2), () => ( 0))) + b.text.length);
|
|
2598
2762
|
if (b.type === "paragraph" && b.style.fontName === "ocr") {
|
|
@@ -2616,13 +2780,13 @@ function demoteNonHeadingRoles(blocks, pageHeights, faceNames) {
|
|
|
2616
2780
|
const citedProse = /* @__PURE__ */ new Set();
|
|
2617
2781
|
const numberedProse = /* @__PURE__ */ new Set();
|
|
2618
2782
|
for (const page of byPage.values()) {
|
|
2619
|
-
const numbered = page.filter((b) => (b.type === "heading" || b.type === "paragraph") && /^[①-⑮]\s*/.test(_nullishCoalesce(_optionalChain([b, 'access',
|
|
2783
|
+
const numbered = page.filter((b) => (b.type === "heading" || b.type === "paragraph") && /^[①-⑮]\s*/.test(_nullishCoalesce(_optionalChain([b, 'access', _193 => _193.text, 'optionalAccess', _194 => _194.trim, 'call', _195 => _195()]), () => ( ""))) && b.bbox && _optionalChain([b, 'access', _196 => _196.style, 'optionalAccess', _197 => _197.fontName]) && b.style.fontSize && !/Bold|Black|Heavy|Semibold/i.test(_nullishCoalesce(_optionalChain([faceNames, 'optionalAccess', _198 => _198.get, 'call', _199 => _199(b.style.fontName)]), () => ( ""))));
|
|
2620
2784
|
let chain = [];
|
|
2621
2785
|
const finish = () => {
|
|
2622
|
-
if (chain.length < 3 || !chain.some((b) => (_nullishCoalesce(_optionalChain([b, 'access',
|
|
2786
|
+
if (chain.length < 3 || !chain.some((b) => (_nullishCoalesce(_optionalChain([b, 'access', _200 => _200.text, 'optionalAccess', _201 => _201.length]), () => ( 0))) >= 40 && b.bbox.height >= b.style.fontSize * 2.4)) return;
|
|
2623
2787
|
for (const b of chain) numberedProse.add(b);
|
|
2624
2788
|
const first = chain[0], size = first.style.fontSize;
|
|
2625
|
-
for (const b of page) if (/^[○●•◦]\s/.test(_nullishCoalesce(_optionalChain([b, 'access',
|
|
2789
|
+
for (const b of page) if (/^[○●•◦]\s/.test(_nullishCoalesce(_optionalChain([b, 'access', _202 => _202.text, 'optionalAccess', _203 => _203.trim, 'call', _204 => _204()]), () => ( ""))) && _optionalChain([b, 'access', _205 => _205.style, 'optionalAccess', _206 => _206.fontName]) === _optionalChain([first, 'access', _207 => _207.style, 'optionalAccess', _208 => _208.fontName]) && _optionalChain([b, 'access', _209 => _209.style, 'optionalAccess', _210 => _210.fontSize]) === size && b.bbox && Math.abs(b.bbox.x - first.bbox.x) <= size * 0.5 && (_nullishCoalesce(_optionalChain([b, 'access', _211 => _211.text, 'optionalAccess', _212 => _212.length]), () => ( 0))) >= 15) numberedProse.add(b);
|
|
2626
2790
|
};
|
|
2627
2791
|
for (const b of numbered) {
|
|
2628
2792
|
const prev = chain.at(-1), size = b.style.fontSize;
|
|
@@ -2636,9 +2800,9 @@ function demoteNonHeadingRoles(blocks, pageHeights, faceNames) {
|
|
|
2636
2800
|
}
|
|
2637
2801
|
for (let i = 0; i + 1 < blocks.length; i++) {
|
|
2638
2802
|
const prose = blocks[i], reference = blocks[i + 1];
|
|
2639
|
-
const a = prose.bbox, b = reference.bbox, size = _nullishCoalesce(_optionalChain([prose, 'access',
|
|
2640
|
-
const source = _nullishCoalesce(_optionalChain([reference, 'access',
|
|
2641
|
-
if (prose.type !== "heading" && prose.type !== "paragraph" && prose.type !== "list" || reference.type !== "heading" && reference.type !== "paragraph" || (_nullishCoalesce(_optionalChain([prose, 'access',
|
|
2803
|
+
const a = prose.bbox, b = reference.bbox, size = _nullishCoalesce(_optionalChain([prose, 'access', _213 => _213.style, 'optionalAccess', _214 => _214.fontSize]), () => ( 0));
|
|
2804
|
+
const source = _nullishCoalesce(_optionalChain([reference, 'access', _215 => _215.text, 'optionalAccess', _216 => _216.replace, 'call', _217 => _217(/<[^>]+>/g, ""), 'access', _218 => _218.trim, 'call', _219 => _219()]), () => ( ""));
|
|
2805
|
+
if (prose.type !== "heading" && prose.type !== "paragraph" && prose.type !== "list" || reference.type !== "heading" && reference.type !== "paragraph" || (_nullishCoalesce(_optionalChain([prose, 'access', _220 => _220.text, 'optionalAccess', _221 => _221.length]), () => ( 0))) < 40 || !a || !b || size <= 0 || a.height < size * 2.4 || prose.pageNumber !== reference.pageNumber || _optionalChain([prose, 'access', _222 => _222.style, 'optionalAccess', _223 => _223.fontName]) !== _optionalChain([reference, 'access', _224 => _224.style, 'optionalAccess', _225 => _225.fontName]) || _optionalChain([prose, 'access', _226 => _226.style, 'optionalAccess', _227 => _227.fontSize]) !== _optionalChain([reference, 'access', _228 => _228.style, 'optionalAccess', _229 => _229.fontSize]) || Math.abs(a.x - b.x) > size && !(/^[○●•◦]\s/.test(_nullishCoalesce(prose.text, () => ( ""))) && b.x >= a.x && b.x - a.x <= size * 2) || a.y - (b.y + b.height) < 0 || a.y - (b.y + b.height) > size || !/^[((].*(?:제\s*\d+\s*조|(?:Article|Section)\s+\d+).*[))]$/i.test(source)) continue;
|
|
2642
2806
|
citedProse.add(prose);
|
|
2643
2807
|
citedProse.add(reference);
|
|
2644
2808
|
}
|
|
@@ -2646,49 +2810,49 @@ function demoteNonHeadingRoles(blocks, pageHeights, faceNames) {
|
|
|
2646
2810
|
const block = blocks[i];
|
|
2647
2811
|
if (block.type !== "heading" || !block.text) continue;
|
|
2648
2812
|
const text = block.text.replace(/<[^>]+>/g, "").trim();
|
|
2649
|
-
const fsz = _nullishCoalesce(_optionalChain([block, 'access',
|
|
2650
|
-
const tocEntry = i > 0 &&
|
|
2813
|
+
const fsz = _nullishCoalesce(_optionalChain([block, 'access', _230 => _230.style, 'optionalAccess', _231 => _231.fontSize]), () => ( 0));
|
|
2814
|
+
const tocEntry = i > 0 && _chunk5PGOZBEQcjs.TOC_BLOCKS.has(blocks[i - 1]) && _chunk5PGOZBEQcjs.TOC_BLOCKS.has(blocks[i + 1]);
|
|
2651
2815
|
const page = _nullishCoalesce(byPage.get(_nullishCoalesce(block.pageNumber, () => ( 0))), () => ( []));
|
|
2652
|
-
const proseStyle = _optionalChain([block, 'access',
|
|
2816
|
+
const proseStyle = _optionalChain([block, 'access', _232 => _232.style, 'optionalAccess', _233 => _233.fontName]) && bodyStyle.get(_nullishCoalesce(block.pageNumber, () => ( 0))) === `${block.style.fontName}:${block.style.fontSize}` && text.length > 60;
|
|
2653
2817
|
const next = blocks[i + 1];
|
|
2654
|
-
const nb = _optionalChain([next, 'optionalAccess',
|
|
2655
|
-
const chapterNumber = !!nb && !!bb && fsz >= (_nullishCoalesce(_optionalChain([next, 'optionalAccess',
|
|
2656
|
-
if (/^\d+(?:\.\d+)*\.?$/.test(text) && _optionalChain([next, 'optionalAccess',
|
|
2818
|
+
const nb = _optionalChain([next, 'optionalAccess', _234 => _234.bbox]), bb = block.bbox;
|
|
2819
|
+
const chapterNumber = !!nb && !!bb && fsz >= (_nullishCoalesce(_optionalChain([next, 'optionalAccess', _235 => _235.style, 'optionalAccess', _236 => _236.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;
|
|
2820
|
+
if (/^\d+(?:\.\d+)*\.?$/.test(text) && _optionalChain([next, 'optionalAccess', _237 => _237.type]) === "heading" && next.text && next.pageNumber === block.pageNumber && !chapterNumber) {
|
|
2657
2821
|
next.text = `${block.text.trim()} ${next.text.trim()}`;
|
|
2658
2822
|
blocks.splice(i--, 1);
|
|
2659
2823
|
continue;
|
|
2660
2824
|
}
|
|
2661
|
-
if ((_optionalChain([next, 'optionalAccess',
|
|
2825
|
+
if ((_optionalChain([next, 'optionalAccess', _238 => _238.type]) === "paragraph" || _optionalChain([next, 'optionalAccess', _239 => _239.type]) === "heading" && !CAPTION.test(text)) && next.pageNumber === block.pageNumber && next.text && next.bbox && block.bbox && _optionalChain([next, 'access', _240 => _240.style, 'optionalAccess', _241 => _241.fontName]) === _optionalChain([block, 'access', _242 => _242.style, 'optionalAccess', _243 => _243.fontName]) && _optionalChain([next, 'access', _244 => _244.style, 'optionalAccess', _245 => _245.fontSize]) === _optionalChain([block, 'access', _246 => _246.style, 'optionalAccess', _247 => _247.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) {
|
|
2662
2826
|
block.text = `${block.text.trim()} ${next.text.trim()}`;
|
|
2663
2827
|
block.bbox = { ...block.bbox, y: next.bbox.y, height: block.bbox.y + block.bbox.height - next.bbox.y };
|
|
2664
2828
|
blocks.splice(i + 1, 1);
|
|
2665
2829
|
}
|
|
2666
2830
|
const after = blocks[i + 2];
|
|
2667
|
-
if ((_optionalChain([next, 'optionalAccess',
|
|
2831
|
+
if ((_optionalChain([next, 'optionalAccess', _248 => _248.type]) === "paragraph" || _optionalChain([next, 'optionalAccess', _249 => _249.type]) === "heading") && /^(?:&|\+|and|or)$/i.test(_nullishCoalesce(_optionalChain([next, 'access', _250 => _250.text, 'optionalAccess', _251 => _251.trim, 'call', _252 => _252()]), () => ( ""))) && _optionalChain([after, 'optionalAccess', _253 => _253.type]) === "heading" && after.text && after.pageNumber === block.pageNumber && next.pageNumber === block.pageNumber && _optionalChain([after, 'access', _254 => _254.style, 'optionalAccess', _255 => _255.fontSize]) === _optionalChain([block, 'access', _256 => _256.style, 'optionalAccess', _257 => _257.fontSize])) {
|
|
2668
2832
|
block.text = `${block.text.trim()} ${next.text.trim()} ${after.text.trim()}`;
|
|
2669
2833
|
blocks.splice(i + 1, 2);
|
|
2670
2834
|
}
|
|
2671
2835
|
const tiny = fsz > 0 && fsz < 7.5;
|
|
2672
2836
|
const prev = blocks[i - 1];
|
|
2673
|
-
if (_optionalChain([prev, 'optionalAccess',
|
|
2837
|
+
if (_optionalChain([prev, 'optionalAccess', _258 => _258.type]) === "paragraph" && prev.pageNumber === block.pageNumber && /^[a-z]{1,3}[.)]$/.test(_nullishCoalesce(_optionalChain([prev, 'access', _259 => _259.text, 'optionalAccess', _260 => _260.trim, 'call', _261 => _261()]), () => ( ""))) && prev.bbox && block.bbox && Math.abs(prev.bbox.y - block.bbox.y) < 2 && prev.bbox.x + prev.bbox.width <= block.bbox.x) {
|
|
2674
2838
|
prev.text = `${prev.text.trim()} ${block.text.trim()}`;
|
|
2675
2839
|
prev.bbox = { ...prev.bbox, width: block.bbox.x + block.bbox.width - prev.bbox.x };
|
|
2676
2840
|
blocks.splice(i--, 1);
|
|
2677
2841
|
continue;
|
|
2678
2842
|
}
|
|
2679
|
-
if (_optionalChain([prev, 'optionalAccess',
|
|
2843
|
+
if (_optionalChain([prev, 'optionalAccess', _262 => _262.type]) === "paragraph" && prev.pageNumber === block.pageNumber && /^\d{1,2}(?:\.\d{1,2})*\.?$/.test(_nullishCoalesce(_optionalChain([prev, 'access', _263 => _263.text, 'optionalAccess', _264 => _264.trim, 'call', _265 => _265()]), () => ( ""))) && 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', _266 => _266.style, 'optionalAccess', _267 => _267.fontSize]), () => ( 0))) >= fsz && prev.bbox.y - (block.bbox.y + block.bbox.height) < fsz * 1.5)) {
|
|
2680
2844
|
block.text = `${prev.text.trim()} ${block.text.trim()}`;
|
|
2681
2845
|
blocks.splice(i - 1, 1);
|
|
2682
2846
|
i -= 2;
|
|
2683
2847
|
continue;
|
|
2684
2848
|
}
|
|
2685
|
-
const box = block.bbox, size = _nullishCoalesce(_optionalChain([block, 'access',
|
|
2686
|
-
const kicker = !!box && size > 0 && _optionalChain([next, 'optionalAccess',
|
|
2687
|
-
const face = _nullishCoalesce(_optionalChain([faceNames, 'optionalAccess',
|
|
2849
|
+
const box = block.bbox, size = _nullishCoalesce(_optionalChain([block, 'access', _268 => _268.style, 'optionalAccess', _269 => _269.fontSize]), () => ( 0));
|
|
2850
|
+
const kicker = !!box && size > 0 && _optionalChain([next, 'optionalAccess', _270 => _270.type]) === "heading" && next.pageNumber === block.pageNumber && !!next.bbox && (_optionalChain([block, 'access', _271 => _271.style, 'optionalAccess', _272 => _272.fontName]) !== "ocr" || size < (_nullishCoalesce(bodySizes.get(_nullishCoalesce(block.pageNumber, () => ( 0))), () => ( Infinity))) * 2) && (_nullishCoalesce(_optionalChain([next, 'access', _273 => _273.style, 'optionalAccess', _274 => _274.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");
|
|
2851
|
+
const face = _nullishCoalesce(_optionalChain([faceNames, 'optionalAccess', _275 => _275.get, 'call', _276 => _276(_nullishCoalesce(_optionalChain([block, 'access', _277 => _277.style, 'optionalAccess', _278 => _278.fontName]), () => ( "")))]), () => ( ""));
|
|
2688
2852
|
const [bodyFace, bodySize] = (_nullishCoalesce(bodyStyle.get(_nullishCoalesce(block.pageNumber, () => ( 0))), () => ( ""))).split(":");
|
|
2689
|
-
const byline = /Italic|Oblique/i.test(face) && !/Bold|Black|Heavy|Semibold/i.test(face) && !!bodyFace && size <= Number(bodySize) + 0.5 && _optionalChain([blocks, 'access',
|
|
2690
|
-
const ocrFragment = _optionalChain([block, 'access',
|
|
2691
|
-
const crowdedOcr = _optionalChain([block, 'access',
|
|
2853
|
+
const byline = /Italic|Oblique/i.test(face) && !/Bold|Black|Heavy|Semibold/i.test(face) && !!bodyFace && size <= Number(bodySize) + 0.5 && _optionalChain([blocks, 'access', _279 => _279[i - 1], 'optionalAccess', _280 => _280.type]) === "heading" && blocks[i - 1].pageNumber === block.pageNumber;
|
|
2854
|
+
const ocrFragment = _optionalChain([block, 'access', _281 => _281.style, 'optionalAccess', _282 => _282.fontName]) === "ocr" && (/^[.,;:…·•-]/.test(text) || text.includes("\u2026") || (_nullishCoalesce(_optionalChain([text, 'access', _283 => _283.match, 'call', _284 => _284(/\p{L}/gu), 'optionalAccess', _285 => _285.length]), () => ( 0))) < 2 || text.split(/\s+/).length > 7);
|
|
2855
|
+
const crowdedOcr = _optionalChain([block, 'access', _286 => _286.style, 'optionalAccess', _287 => _287.fontName]) === "ocr" && !!box && [prev, next].every((o) => _optionalChain([o, 'optionalAccess', _288 => _288.type]) === "paragraph" && o.pageNumber === block.pageNumber && _optionalChain([o, 'access', _289 => _289.style, 'optionalAccess', _290 => _290.fontName]) === "ocr" && !!o.bbox && (_nullishCoalesce(_optionalChain([o, 'access', _291 => _291.text, 'optionalAccess', _292 => _292.length]), () => ( 0))) >= 15 && Math.abs(o.bbox.x - box.x) <= size * 0.25 && Math.min(o.bbox.y + o.bbox.height, box.y + box.height) - Math.max(o.bbox.y, box.y) >= o.bbox.height * 0.2) && prev.bbox.y > box.y && next.bbox.y < box.y;
|
|
2692
2856
|
if (numberedProse.has(block) || citedProse.has(block) || ocrFragment || crowdedOcr || 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)"·"가)" 앞머리 번호는 빼고 센다
|
|
2693
2857
|
unbalancedClose(text.replace(/^\s*[\dA-Za-z가-힣ⅰ-ⅹ]{1,3}\)\s*/, "")) || isRunningHead(block, page, pageHeights.get(_nullishCoalesce(block.pageNumber, () => ( 0))))) {
|
|
2694
2858
|
block.type = "paragraph";
|
|
@@ -2723,34 +2887,34 @@ var CAPTION_LABEL = /^(?:figure|fig\.|diagram|table|chart|graph|exhibit|box)\s*[
|
|
|
2723
2887
|
function captionTableText(t) {
|
|
2724
2888
|
if (!t || t.rows !== 1 || t.cols !== 2) return null;
|
|
2725
2889
|
const [label, body] = t.cells[0];
|
|
2726
|
-
if (!label || !body || _optionalChain([label, 'access',
|
|
2890
|
+
if (!label || !body || _optionalChain([label, 'access', _293 => _293.blocks, 'optionalAccess', _294 => _294.length]) || _optionalChain([body, 'access', _295 => _295.blocks, 'optionalAccess', _296 => _296.length]) || !CAPTION_LABEL.test(label.text.trim()) || !body.text.trim()) return null;
|
|
2727
2891
|
return `${label.text.trim()} ${body.text.replace(/\s*\n\s*/g, " ").trim()}`;
|
|
2728
2892
|
}
|
|
2729
2893
|
function splitSingleCellTables(blocks) {
|
|
2730
2894
|
const out = [];
|
|
2731
2895
|
for (const b of blocks) {
|
|
2732
2896
|
const t = b.type === "table" ? b.table : void 0;
|
|
2733
|
-
const title = t &&
|
|
2897
|
+
const title = t && _chunk5PGOZBEQcjs.FRAME_TITLE_BLOCKS.get(t);
|
|
2734
2898
|
if (title) {
|
|
2735
2899
|
out.push({ ...title, text: `${t.cells[0][0].text.trim()} ${t.cells[0][2].text.trim()}` });
|
|
2736
2900
|
continue;
|
|
2737
2901
|
}
|
|
2738
|
-
const only = t && t.rows === 1 && t.cols === 1 && _optionalChain([t, 'access',
|
|
2902
|
+
const only = t && t.rows === 1 && t.cols === 1 && _optionalChain([t, 'access', _297 => _297.cells, 'access', _298 => _298[0], 'optionalAccess', _299 => _299[0], 'optionalAccess', _300 => _300.blocks, 'optionalAccess', _301 => _301.length]) === 1 ? t.cells[0][0].blocks[0] : void 0;
|
|
2739
2903
|
const squash = (s) => s.replace(/\s/g, "");
|
|
2740
2904
|
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;
|
|
2741
|
-
const caption = _nullishCoalesce(captionTableText(t), () => ( (_optionalChain([inner, 'optionalAccess',
|
|
2905
|
+
const caption = _nullishCoalesce(captionTableText(t), () => ( (_optionalChain([inner, 'optionalAccess', _302 => _302.type]) === "table" ? captionTableText(inner.table) : null)));
|
|
2742
2906
|
if (caption) {
|
|
2743
2907
|
out.push({ type: "paragraph", text: caption, pageNumber: b.pageNumber, bbox: b.bbox });
|
|
2744
2908
|
continue;
|
|
2745
2909
|
}
|
|
2746
|
-
const cell = t && t.rows === 1 && t.cols === 1 ? _optionalChain([t, 'access',
|
|
2910
|
+
const cell = t && t.rows === 1 && t.cols === 1 ? _optionalChain([t, 'access', _303 => _303.cells, 'access', _304 => _304[0], 'optionalAccess', _305 => _305[0]]) : void 0;
|
|
2747
2911
|
if (!cell) {
|
|
2748
2912
|
out.push(b);
|
|
2749
2913
|
continue;
|
|
2750
2914
|
}
|
|
2751
2915
|
const lines = (_nullishCoalesce(cell.text, () => ( ""))).split(/\n/).map((l) => l.trim()).filter(Boolean);
|
|
2752
|
-
if (_optionalChain([t, 'optionalAccess',
|
|
2753
|
-
if (_optionalChain([cell, 'access',
|
|
2916
|
+
if (_optionalChain([t, 'optionalAccess', _306 => _306.caption, 'optionalAccess', _307 => _307.trim, 'call', _308 => _308()])) out.push({ type: "paragraph", text: t.caption.trim(), pageNumber: b.pageNumber, bbox: b.bbox });
|
|
2917
|
+
if (_optionalChain([cell, 'access', _309 => _309.blocks, 'optionalAccess', _310 => _310.length])) {
|
|
2754
2918
|
out.push(...splitSingleCellTables(cell.blocks));
|
|
2755
2919
|
continue;
|
|
2756
2920
|
}
|
|
@@ -2766,7 +2930,7 @@ function joinLatinCellWraps(blocks) {
|
|
|
2766
2930
|
const lines = cell.text.split("\n");
|
|
2767
2931
|
const out = [lines[0]];
|
|
2768
2932
|
for (const line of lines.slice(1)) {
|
|
2769
|
-
if (
|
|
2933
|
+
if (_chunk5PGOZBEQcjs.latinSoftWrap.call(void 0, out[out.length - 1], line)) out[out.length - 1] = out[out.length - 1].trimEnd() + " " + line.trim();
|
|
2770
2934
|
else out.push(line);
|
|
2771
2935
|
}
|
|
2772
2936
|
cell.text = out.join("\n");
|
|
@@ -2777,19 +2941,19 @@ function joinLatinCellWraps(blocks) {
|
|
|
2777
2941
|
}
|
|
2778
2942
|
function cleanPdfText(text, opts) {
|
|
2779
2943
|
let clean = normalizeAraea(stripControlChars(text));
|
|
2780
|
-
if (!_optionalChain([opts, 'optionalAccess',
|
|
2944
|
+
if (!_optionalChain([opts, 'optionalAccess', _311 => _311.keepLoneNumbers])) {
|
|
2781
2945
|
clean = clean.replace(/^\d{1,4}\n/, "").replace(/\n\d{1,4}\n/g, "\n").replace(/\n\d{1,4}$/, "");
|
|
2782
2946
|
}
|
|
2783
|
-
if (!_optionalChain([opts, 'optionalAccess',
|
|
2947
|
+
if (!_optionalChain([opts, 'optionalAccess', _312 => _312.keepLoneNumbers])) clean = clean.replace(/^#{1,6}\s*\d{1,4}\s*$/gm, "");
|
|
2784
2948
|
return mergeKoreanLines(
|
|
2785
2949
|
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))
|
|
2786
2950
|
).replace(/^(?!\| ---).*$/gm, (line) => {
|
|
2787
2951
|
if (/^\s*\${1,2}.+\${1,2}\s*$/.test(line)) return line;
|
|
2788
2952
|
if (line.startsWith("|")) {
|
|
2789
|
-
return line.replace(/(?:\\.|[^|\\])+/g, (cell) => cell.split("<br>").map((seg) => seg.replace(/\S(?:.*\S)?/, (t) =>
|
|
2953
|
+
return line.replace(/(?:\\.|[^|\\])+/g, (cell) => cell.split("<br>").map((seg) => seg.replace(/\S(?:.*\S)?/, (t) => _chunk5PGOZBEQcjs.collapseEvenSpacing.call(void 0, t, false))).join("<br>"));
|
|
2790
2954
|
}
|
|
2791
|
-
const mark = _nullishCoalesce(_optionalChain([/^(?:#{1,6}|-) /, 'access',
|
|
2792
|
-
return mark +
|
|
2955
|
+
const mark = _nullishCoalesce(_optionalChain([/^(?:#{1,6}|-) /, 'access', _313 => _313.exec, 'call', _314 => _314(line), 'optionalAccess', _315 => _315[0]]), () => ( ""));
|
|
2956
|
+
return mark + _chunk5PGOZBEQcjs.collapseEvenSpacing.call(void 0, line.slice(mark.length), false);
|
|
2793
2957
|
}).replace(/\\~\\~/g, "~~").replace(/~~~~/g, "").replace(/<u>\s*<\/u>/g, "").replace(/<(sup|sub)>\s*<\/\1>/g, "").replace(/\n{3,}/g, "\n\n").trim();
|
|
2794
2958
|
}
|
|
2795
2959
|
function startsWithMarker(line) {
|
|
@@ -2821,7 +2985,7 @@ function mergeKoreanLines(text) {
|
|
|
2821
2985
|
continue;
|
|
2822
2986
|
}
|
|
2823
2987
|
if (/[가-힣·,\-]$/.test(prev) && /^[가-힣(]/.test(curr) && !startsWithMarker(curr) && !isStandaloneHeader(prev) && !startsWithMarker(prev)) {
|
|
2824
|
-
result[result.length - 1] = prev +
|
|
2988
|
+
result[result.length - 1] = prev + _chunk5PGOZBEQcjs.wrapJoiner.call(void 0, prev, curr) + curr;
|
|
2825
2989
|
} else {
|
|
2826
2990
|
result.push(curr);
|
|
2827
2991
|
}
|
|
@@ -2837,7 +3001,7 @@ function applyLinkAnnotations(items, annots) {
|
|
|
2837
3001
|
const wrapped = /* @__PURE__ */ new Set();
|
|
2838
3002
|
for (const a of annots) {
|
|
2839
3003
|
if (a.subtype !== "Link" || !a.url || !a.rect || a.rect.length < 4) continue;
|
|
2840
|
-
const url =
|
|
3004
|
+
const url = _chunkMZ6XNFZLcjs.sanitizeHref.call(void 0, a.url);
|
|
2841
3005
|
if (!url) continue;
|
|
2842
3006
|
const x1 = Math.min(a.rect[0], a.rect[2]), x2 = Math.max(a.rect[0], a.rect[2]);
|
|
2843
3007
|
const y1 = Math.min(a.rect[1], a.rect[3]), y2 = Math.max(a.rect[1], a.rect[3]);
|
|
@@ -2878,7 +3042,7 @@ function mergeLinkRuns(markdown) {
|
|
|
2878
3042
|
|
|
2879
3043
|
// src/pdf/formula-ocr.ts
|
|
2880
3044
|
async function applyFormulaOcr(buffer, blocks, pageFilter, effectivePageCount, warnings, _onProgress) {
|
|
2881
|
-
const formulaMod = await Promise.resolve().then(() => _interopRequireWildcard(require("./formula-
|
|
3045
|
+
const formulaMod = await Promise.resolve().then(() => _interopRequireWildcard(require("./formula-RNATQ3FQ.cjs")));
|
|
2882
3046
|
const { FormulaPipeline, ensureFormulaModels } = formulaMod;
|
|
2883
3047
|
await ensureFormulaModels((p) => {
|
|
2884
3048
|
if (p.phase === "download" && p.total) {
|
|
@@ -3069,13 +3233,13 @@ async function loadPdfWithTimeout(buffer) {
|
|
|
3069
3233
|
try {
|
|
3070
3234
|
return await Promise.race([
|
|
3071
3235
|
loadingTask.promise.catch((e) => {
|
|
3072
|
-
if (e instanceof Error && e.name === "PasswordException") throw new (0,
|
|
3236
|
+
if (e instanceof Error && e.name === "PasswordException") throw new (0, _chunkMZ6XNFZLcjs.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)");
|
|
3073
3237
|
throw e;
|
|
3074
3238
|
}),
|
|
3075
3239
|
new Promise((_, reject) => {
|
|
3076
3240
|
timer = setTimeout(() => {
|
|
3077
3241
|
loadingTask.destroy();
|
|
3078
|
-
reject(new (0,
|
|
3242
|
+
reject(new (0, _chunkMZ6XNFZLcjs.KordocError)("PDF \uB85C\uB529 \uD0C0\uC784\uC544\uC6C3 (30\uCD08 \uCD08\uACFC)"));
|
|
3079
3243
|
}, PDF_LOAD_TIMEOUT_MS);
|
|
3080
3244
|
})
|
|
3081
3245
|
]);
|
|
@@ -3084,13 +3248,13 @@ async function loadPdfWithTimeout(buffer) {
|
|
|
3084
3248
|
}
|
|
3085
3249
|
}
|
|
3086
3250
|
async function parsePdfDocument(buffer, options) {
|
|
3087
|
-
const formulaBuffer = _optionalChain([options, 'optionalAccess',
|
|
3088
|
-
const autoOcr = _optionalChain([options, 'optionalAccess',
|
|
3089
|
-
const ocrBuffer = _optionalChain([options, 'optionalAccess',
|
|
3251
|
+
const formulaBuffer = _optionalChain([options, 'optionalAccess', _316 => _316.formulaOcr]) ? buffer : null;
|
|
3252
|
+
const autoOcr = _optionalChain([options, 'optionalAccess', _317 => _317.ocr]) === void 0 && await _chunk5PGOZBEQcjs.ocrModelsCached.call(void 0, );
|
|
3253
|
+
const ocrBuffer = _optionalChain([options, 'optionalAccess', _318 => _318.ocr]) || autoOcr ? buffer : null;
|
|
3090
3254
|
const doc = await loadPdfWithTimeout(buffer);
|
|
3091
3255
|
try {
|
|
3092
3256
|
const pageCount = doc.numPages;
|
|
3093
|
-
if (pageCount === 0) throw new (0,
|
|
3257
|
+
if (pageCount === 0) throw new (0, _chunkMZ6XNFZLcjs.KordocError)("PDF\uC5D0 \uD398\uC774\uC9C0\uAC00 \uC5C6\uC2B5\uB2C8\uB2E4.");
|
|
3094
3258
|
const metadata = { pageCount, pageMode: "layout" };
|
|
3095
3259
|
await extractPdfMetadata(doc, metadata);
|
|
3096
3260
|
const blocks = [];
|
|
@@ -3099,8 +3263,8 @@ async function parsePdfDocument(buffer, options) {
|
|
|
3099
3263
|
let totalChars = 0;
|
|
3100
3264
|
let totalTextBytes = 0;
|
|
3101
3265
|
const effectivePageCount = Math.min(pageCount, MAX_PAGES);
|
|
3102
|
-
const pageFilter = _optionalChain([options, 'optionalAccess',
|
|
3103
|
-
if (pageCount > MAX_PAGES && (!_optionalChain([options, 'optionalAccess',
|
|
3266
|
+
const pageFilter = _optionalChain([options, 'optionalAccess', _319 => _319.pages]) ? _chunkJ55UQC5Hcjs.parsePageRange.call(void 0, options.pages, effectivePageCount) : null;
|
|
3267
|
+
if (pageCount > MAX_PAGES && (!_optionalChain([options, 'optionalAccess', _320 => _320.pages]) || _chunkJ55UQC5Hcjs.hasRequestedPagesAfter.call(void 0, options.pages, MAX_PAGES, pageCount))) {
|
|
3104
3268
|
warnings.push({ message: `${pageCount}\uCABD \uC911 \uC55E ${MAX_PAGES}\uCABD\uB9CC \uD30C\uC2F1\uD588\uC2B5\uB2C8\uB2E4 (\uCABD \uC218 \uC0C1\uD55C)`, code: "PARTIAL_PARSE" });
|
|
3105
3269
|
}
|
|
3106
3270
|
const totalTarget = pageFilter ? pageFilter.size : effectivePageCount;
|
|
@@ -3119,10 +3283,10 @@ async function parsePdfDocument(buffer, options) {
|
|
|
3119
3283
|
const pageImageBlocks = /* @__PURE__ */ new Map();
|
|
3120
3284
|
const carry = {};
|
|
3121
3285
|
const vectorPageOps = /* @__PURE__ */ new Map();
|
|
3122
|
-
const wrapLexicon = new (0,
|
|
3286
|
+
const wrapLexicon = new (0, _chunk5PGOZBEQcjs.WrapLexicon)();
|
|
3123
3287
|
const noteMarks = /* @__PURE__ */ new Map();
|
|
3124
3288
|
const headerContext = [];
|
|
3125
|
-
if (pageFilter && _optionalChain([options, 'optionalAccess',
|
|
3289
|
+
if (pageFilter && _optionalChain([options, 'optionalAccess', _321 => _321.removeHeaderFooter]) !== false && pageFilter.size < effectivePageCount) {
|
|
3126
3290
|
for (const number of selectionContextPages(pageFilter, effectivePageCount)) {
|
|
3127
3291
|
let contextPage;
|
|
3128
3292
|
try {
|
|
@@ -3132,7 +3296,7 @@ async function parsePdfDocument(buffer, options) {
|
|
|
3132
3296
|
headerContext.push(...marginContextBlocks(content.items, number, contextPage.view));
|
|
3133
3297
|
} catch (e4) {
|
|
3134
3298
|
} finally {
|
|
3135
|
-
_optionalChain([contextPage, 'optionalAccess',
|
|
3299
|
+
_optionalChain([contextPage, 'optionalAccess', _322 => _322.cleanup, 'call', _323 => _323()]);
|
|
3136
3300
|
}
|
|
3137
3301
|
}
|
|
3138
3302
|
}
|
|
@@ -3159,13 +3323,13 @@ async function parsePdfDocument(buffer, options) {
|
|
|
3159
3323
|
return void 0;
|
|
3160
3324
|
}
|
|
3161
3325
|
};
|
|
3162
|
-
const differencesOf = (loadedName) => _optionalChain([fontObj, 'call',
|
|
3163
|
-
restoreNamedGlyphs(rawItems, rawOps.fnArray, rawOps.argsArray, differencesOf, (n) => _optionalChain([fontObj, 'call',
|
|
3326
|
+
const differencesOf = (loadedName) => _optionalChain([fontObj, 'call', _324 => _324(loadedName), 'optionalAccess', _325 => _325.differences]);
|
|
3327
|
+
restoreNamedGlyphs(rawItems, rawOps.fnArray, rawOps.argsArray, differencesOf, (n) => _optionalChain([fontObj, 'call', _326 => _326(n), 'optionalAccess', _327 => _327.name]));
|
|
3164
3328
|
restoreTrackedSpacing(rawItems, rawOps.fnArray, rawOps.argsArray);
|
|
3165
3329
|
markSyntheticSpaces(rawItems, rawOps.fnArray, rawOps.argsArray);
|
|
3166
3330
|
const occluded = occludedTextItems(rawItems, rawOps.fnArray, rawOps.argsArray);
|
|
3167
|
-
const items =
|
|
3168
|
-
const filtered =
|
|
3331
|
+
const items = _chunk5PGOZBEQcjs.normalizeItems.call(void 0, occluded.size ? rawItems.filter((it) => !occluded.has(it)) : rawItems);
|
|
3332
|
+
const filtered = _chunk5PGOZBEQcjs.filterHiddenText.call(void 0, items, pageW, pageH, viewX1, viewY1);
|
|
3169
3333
|
const joined = joinVerticalColumns(filtered.visible);
|
|
3170
3334
|
const visible = dropTabLeaderDots(joined);
|
|
3171
3335
|
const hiddenCount = filtered.hiddenCount + occluded.size;
|
|
@@ -3189,27 +3353,27 @@ async function parsePdfDocument(buffer, options) {
|
|
|
3189
3353
|
fnArray: [_pdfmjs.OPS.transform, ...rawOps.fnArray],
|
|
3190
3354
|
argsArray: [[1, 0, 0, 1, -viewX1, -viewY1], ...rawOps.argsArray]
|
|
3191
3355
|
} : rawOps;
|
|
3192
|
-
remapSymbolFontItems(visible, (loadedName) => _optionalChain([fontObj, 'call',
|
|
3356
|
+
remapSymbolFontItems(visible, (loadedName) => _optionalChain([fontObj, 'call', _328 => _328(loadedName), 'optionalAccess', _329 => _329.name]));
|
|
3193
3357
|
remapControlGlyphs(visible, differencesOf);
|
|
3194
|
-
await
|
|
3358
|
+
await _chunk5PGOZBEQcjs.restoreImageBullets.call(void 0, visible, page, opList.fnArray, opList.argsArray, imageBulletShapes);
|
|
3195
3359
|
const faces = /* @__PURE__ */ new Map();
|
|
3196
3360
|
for (const it of visible) {
|
|
3197
3361
|
if (!it.fontName) continue;
|
|
3198
3362
|
let face = faces.get(it.fontName);
|
|
3199
3363
|
if (face === void 0) {
|
|
3200
3364
|
const obj = fontObj(it.fontName);
|
|
3201
|
-
face = _optionalChain([obj, 'optionalAccess',
|
|
3365
|
+
face = _optionalChain([obj, 'optionalAccess', _330 => _330.isType3Font]) && /^[A-Z]{6}\+./.test(_nullishCoalesce(obj.name, () => ( ""))) && obj.name.slice(7) || it.fontName;
|
|
3202
3366
|
faces.set(it.fontName, face);
|
|
3203
3367
|
}
|
|
3204
3368
|
it.fontName = face;
|
|
3205
|
-
if (!faceNames.has(face)) faceNames.set(face, (_nullishCoalesce(_optionalChain([fontObj, 'call',
|
|
3369
|
+
if (!faceNames.has(face)) faceNames.set(face, (_nullishCoalesce(_optionalChain([fontObj, 'call', _331 => _331(face), 'optionalAccess', _332 => _332.name]), () => ( ""))).replace(/^[A-Z]{6}\+/, ""));
|
|
3206
3370
|
}
|
|
3207
|
-
for (const it of visible) if (it.text.includes("$")) it.text =
|
|
3208
|
-
for (const it of visible) if (it.text.includes("<")) it.text =
|
|
3371
|
+
for (const it of visible) if (it.text.includes("$")) it.text = _chunkORGWGR4Kcjs.escapeLiteralDollar.call(void 0, it.text);
|
|
3372
|
+
for (const it of visible) if (it.text.includes("<")) it.text = _chunkORGWGR4Kcjs.escapeLiteralTags.call(void 0, it.text);
|
|
3209
3373
|
wrapEquationRuns(visible, (face) => faceNames.get(face));
|
|
3210
3374
|
const pageArea = pageW * pageH;
|
|
3211
3375
|
if (pageArea > 0) {
|
|
3212
|
-
const imageRegions =
|
|
3376
|
+
const imageRegions = _chunk5PGOZBEQcjs.extractImageRegions.call(void 0, opList.fnArray, opList.argsArray);
|
|
3213
3377
|
let uncovered = 0;
|
|
3214
3378
|
for (const r of imageRegions) {
|
|
3215
3379
|
const area = (r.x2 - r.x1) * (r.y2 - r.y1);
|
|
@@ -3235,15 +3399,15 @@ async function parsePdfDocument(buffer, options) {
|
|
|
3235
3399
|
if (uncovered > 0) skippedImagePages.set(i, uncovered);
|
|
3236
3400
|
}
|
|
3237
3401
|
const marks = superscriptNoteMarks(visible);
|
|
3238
|
-
if (marks.length) noteMarks.set(i, { marks, seps: footnoteSeparators(
|
|
3402
|
+
if (marks.length) noteMarks.set(i, { marks, seps: footnoteSeparators(_chunk5PGOZBEQcjs.extractLines.call(void 0, opList.fnArray, opList.argsArray).horizontals, pageW, pageH) });
|
|
3239
3403
|
const stamp = marginStamp(visible);
|
|
3240
3404
|
const flow = stamp.length ? visible.filter((it) => !stamp.includes(it)) : visible;
|
|
3241
|
-
const rightArrows = _optionalChain([options, 'optionalAccess',
|
|
3242
|
-
const pageBlocks = orderTwoUpPage(
|
|
3405
|
+
const rightArrows = _optionalChain([options, 'optionalAccess', _333 => _333.tables]) !== false ? await _chunk5PGOZBEQcjs.detectRightArrowRegions.call(void 0, page, opList.fnArray, opList.argsArray, imageArrowDirections) : [];
|
|
3406
|
+
const pageBlocks = orderTwoUpPage(_chunk5PGOZBEQcjs.extractPageBlocksWithLines.call(void 0, flow, i, opList, pageW, pageH, void 0, _optionalChain([options, 'optionalAccess', _334 => _334.tables]) !== false, carry, wrapLexicon, rightArrows), pageW, pageH);
|
|
3243
3407
|
if (stamp.length) pageBlocks.unshift({ type: "paragraph", text: [...stamp].sort((a, b) => a.y - b.y).map((it) => it.text).join(" "), pageNumber: i });
|
|
3244
3408
|
for (const b of pageBlocks) blocks.push(b);
|
|
3245
3409
|
try {
|
|
3246
|
-
const { blocks: imgBlocks, images: pageImages } = await extractPageImages(page, opList.fnArray, opList.argsArray, i, imageState, warnings, _optionalChain([options, 'optionalAccess',
|
|
3410
|
+
const { blocks: imgBlocks, images: pageImages } = await extractPageImages(page, opList.fnArray, opList.argsArray, i, imageState, warnings, _optionalChain([options, 'optionalAccess', _335 => _335.images]) !== false);
|
|
3247
3411
|
if (imgBlocks.length > 0) pageImageBlocks.set(i, imgBlocks);
|
|
3248
3412
|
extractedImages.push(...pageImages);
|
|
3249
3413
|
} catch (e7) {
|
|
@@ -3262,17 +3426,17 @@ async function parsePdfDocument(buffer, options) {
|
|
|
3262
3426
|
const vector = scanVectorGlyphs(opList.fnArray, opList.argsArray, visible);
|
|
3263
3427
|
const quality = computePageQuality(i, pageText, vector.glyphs);
|
|
3264
3428
|
pageQuality.push(quality);
|
|
3265
|
-
if (_optionalChain([options, 'optionalAccess',
|
|
3429
|
+
if (_optionalChain([options, 'optionalAccess', _336 => _336.ocr]) && quality.ocrReason === "vector_text" && page.rotate % 360 === 0 && page.view[0] === 0 && page.view[1] === 0) {
|
|
3266
3430
|
vectorPageOps.set(i, ocrVectorOps(opList, vector.paths));
|
|
3267
3431
|
}
|
|
3268
|
-
if (totalTextBytes > MAX_TOTAL_TEXT) throw new (0,
|
|
3432
|
+
if (totalTextBytes > MAX_TOTAL_TEXT) throw new (0, _chunkMZ6XNFZLcjs.KordocError)("\uD14D\uC2A4\uD2B8 \uCD94\uCD9C \uD06C\uAE30 \uCD08\uACFC");
|
|
3269
3433
|
parsedPages++;
|
|
3270
|
-
_optionalChain([options, 'optionalAccess',
|
|
3434
|
+
_optionalChain([options, 'optionalAccess', _337 => _337.onProgress, 'optionalCall', _338 => _338(parsedPages, totalTarget)]);
|
|
3271
3435
|
} catch (pageErr) {
|
|
3272
|
-
if (pageErr instanceof
|
|
3436
|
+
if (pageErr instanceof _chunkMZ6XNFZLcjs.KordocError) throw pageErr;
|
|
3273
3437
|
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" });
|
|
3274
3438
|
} finally {
|
|
3275
|
-
_optionalChain([loadedPage, 'optionalAccess',
|
|
3439
|
+
_optionalChain([loadedPage, 'optionalAccess', _339 => _339.cleanup, 'call', _340 => _340()]);
|
|
3276
3440
|
}
|
|
3277
3441
|
if (loadedFonts.size > FONT_CACHE_LIMIT) {
|
|
3278
3442
|
await doc.cleanup();
|
|
@@ -3280,13 +3444,13 @@ async function parsePdfDocument(buffer, options) {
|
|
|
3280
3444
|
}
|
|
3281
3445
|
}
|
|
3282
3446
|
const parsedPageCount = parsedPages || (pageFilter ? pageFilter.size : effectivePageCount);
|
|
3283
|
-
const isImageBased = _optionalChain([pageFilter, 'optionalAccess',
|
|
3447
|
+
const isImageBased = _optionalChain([pageFilter, 'optionalAccess', _341 => _341.size]) !== 0 && totalChars / Math.max(parsedPageCount, 1) < 10;
|
|
3284
3448
|
const ocrDone = /* @__PURE__ */ new Set();
|
|
3285
|
-
const ocrRegions = _optionalChain([options, 'optionalAccess',
|
|
3449
|
+
const ocrRegions = _optionalChain([options, 'optionalAccess', _342 => _342.ocr]) === true || autoOcr ? ocrImageRegions(uncoveredImageRegions, largeImageRegions, _optionalChain([options, 'optionalAccess', _343 => _343.ocr]) === true) : /* @__PURE__ */ new Map();
|
|
3286
3450
|
if (ocrBuffer) {
|
|
3287
3451
|
const inScope = (p) => !pageFilter || pageFilter.has(p);
|
|
3288
3452
|
const targets = /* @__PURE__ */ new Set();
|
|
3289
|
-
if (_optionalChain([options, 'optionalAccess',
|
|
3453
|
+
if (_optionalChain([options, 'optionalAccess', _344 => _344.ocr]) === "force" || isImageBased) {
|
|
3290
3454
|
for (let i = 1; i <= effectivePageCount; i++) if (inScope(i)) targets.add(i);
|
|
3291
3455
|
} else {
|
|
3292
3456
|
for (const pq of pageQuality) {
|
|
@@ -3299,16 +3463,16 @@ async function parsePdfDocument(buffer, options) {
|
|
|
3299
3463
|
}
|
|
3300
3464
|
if (targets.size > 0) {
|
|
3301
3465
|
try {
|
|
3302
|
-
const { runPdfOcr } = await Promise.resolve().then(() => _interopRequireWildcard(require("./pdf-ocr-
|
|
3303
|
-
const mode = typeof _optionalChain([options, 'optionalAccess',
|
|
3304
|
-
const regionPages = new Map([...ocrRegions].filter(([p]) => _optionalChain([options, 'optionalAccess',
|
|
3305
|
-
const ocrPageBlocks = await runPdfOcr(ocrBuffer, targets, mode, warnings, _optionalChain([options, 'optionalAccess',
|
|
3306
|
-
for (const obs of ocrPageBlocks.values())
|
|
3466
|
+
const { runPdfOcr } = await Promise.resolve().then(() => _interopRequireWildcard(require("./pdf-ocr-7OAFUDM4.cjs")));
|
|
3467
|
+
const mode = typeof _optionalChain([options, 'optionalAccess', _345 => _345.ocr]) === "function" ? options.ocr : "builtin";
|
|
3468
|
+
const regionPages = new Map([...ocrRegions].filter(([p]) => _optionalChain([options, 'optionalAccess', _346 => _346.ocr]) !== "force" && !isImageBased && !_optionalChain([pageQuality, 'access', _347 => _347.find, 'call', _348 => _348((q) => q.page === p), 'optionalAccess', _349 => _349.needsOcr])));
|
|
3469
|
+
const ocrPageBlocks = await runPdfOcr(ocrBuffer, targets, mode, warnings, _optionalChain([options, 'optionalAccess', _350 => _350.onProgress]), _optionalChain([options, 'optionalAccess', _351 => _351.tables]) !== false, vectorPageOps, regionPages);
|
|
3470
|
+
for (const obs of ocrPageBlocks.values()) _chunkORGWGR4Kcjs.stripScriptTags.call(void 0, { blocks: obs });
|
|
3307
3471
|
if (ocrPageBlocks.size > 0) {
|
|
3308
3472
|
const replacePages = /* @__PURE__ */ new Set();
|
|
3309
3473
|
for (const [p, obs] of ocrPageBlocks) {
|
|
3310
|
-
const needsOcr = _optionalChain([pageQuality, 'access',
|
|
3311
|
-
if (_optionalChain([options, 'optionalAccess',
|
|
3474
|
+
const needsOcr = _optionalChain([pageQuality, 'access', _352 => _352.find, 'call', _353 => _353((q) => q.page === p), 'optionalAccess', _354 => _354.needsOcr]);
|
|
3475
|
+
if (_optionalChain([options, 'optionalAccess', _355 => _355.ocr]) === "force" || isImageBased || needsOcr) {
|
|
3312
3476
|
replacePages.add(p);
|
|
3313
3477
|
ocrDone.add(p);
|
|
3314
3478
|
continue;
|
|
@@ -3316,7 +3480,7 @@ async function parsePdfDocument(buffer, options) {
|
|
|
3316
3480
|
const regions = ocrRegions.get(p);
|
|
3317
3481
|
if (!regions || mergeOcrImageRegions(blocks, p, regions, obs) === 0) continue;
|
|
3318
3482
|
ocrDone.add(p);
|
|
3319
|
-
if (_optionalChain([pageImageBlocks, 'access',
|
|
3483
|
+
if (_optionalChain([pageImageBlocks, 'access', _356 => _356.get, 'call', _357 => _357(p), 'optionalAccess', _358 => _358.length]) === 1) pageImageBlocks.delete(p);
|
|
3320
3484
|
}
|
|
3321
3485
|
if (replacePages.size) {
|
|
3322
3486
|
const merged = blocks.filter((b) => !(b.pageNumber && replacePages.has(b.pageNumber)));
|
|
@@ -3366,12 +3530,12 @@ async function parsePdfDocument(buffer, options) {
|
|
|
3366
3530
|
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" });
|
|
3367
3531
|
}
|
|
3368
3532
|
}
|
|
3369
|
-
if (_optionalChain([options, 'optionalAccess',
|
|
3370
|
-
const removed =
|
|
3533
|
+
if (_optionalChain([options, 'optionalAccess', _359 => _359.removeHeaderFooter]) !== false && (parsedPageCount >= 3 || headerContext.length)) {
|
|
3534
|
+
const removed = _chunk5PGOZBEQcjs.removeHeaderFooterBlocks.call(void 0, blocks, pageHeights, warnings, noteMarks, false, headerContext);
|
|
3371
3535
|
for (let ri = removed.length - 1; ri >= 0; ri--) {
|
|
3372
3536
|
blocks.splice(removed[ri], 1);
|
|
3373
3537
|
}
|
|
3374
|
-
const kept =
|
|
3538
|
+
const kept = _chunk5PGOZBEQcjs.removeSideTabs.call(void 0, blocks, pageWidths);
|
|
3375
3539
|
if (kept !== blocks) {
|
|
3376
3540
|
blocks.length = 0;
|
|
3377
3541
|
blocks.push(...kept);
|
|
@@ -3379,15 +3543,15 @@ async function parsePdfDocument(buffer, options) {
|
|
|
3379
3543
|
}
|
|
3380
3544
|
mergeContinuedCells(blocks, pageHeights);
|
|
3381
3545
|
mergeCrossPageTables(blocks, pageHeights, wrapLexicon);
|
|
3382
|
-
if (_optionalChain([options, 'optionalAccess',
|
|
3383
|
-
const boxes =
|
|
3546
|
+
if (_optionalChain([options, 'optionalAccess', _360 => _360.removeHeaderFooter]) !== false && parsedPageCount >= 3) {
|
|
3547
|
+
const boxes = _chunk5PGOZBEQcjs.removeHeaderFooterBlocks.call(void 0, blocks, pageHeights, warnings, noteMarks, true);
|
|
3384
3548
|
for (let ri = boxes.length - 1; ri >= 0; ri--) blocks.splice(boxes[ri], 1);
|
|
3385
3549
|
}
|
|
3386
3550
|
splitContactTables(blocks);
|
|
3387
|
-
if (!_optionalChain([options, 'optionalAccess',
|
|
3388
|
-
|
|
3551
|
+
if (!_optionalChain([options, 'optionalAccess', _361 => _361.keepTrailingEmptyCols])) _chunk5PGOZBEQcjs.trimTrailingEmptyTableCols.call(void 0, blocks);
|
|
3552
|
+
_chunk5PGOZBEQcjs.joinPageBreakWraps.call(void 0, blocks, wrapLexicon);
|
|
3389
3553
|
injectPageImageBlocks(blocks, pageImageBlocks);
|
|
3390
|
-
if (_optionalChain([options, 'optionalAccess',
|
|
3554
|
+
if (_optionalChain([options, 'optionalAccess', _362 => _362.formulaOcr]) && formulaBuffer) {
|
|
3391
3555
|
try {
|
|
3392
3556
|
await applyFormulaOcr(formulaBuffer, blocks, pageFilter, effectivePageCount, warnings, options.onProgress);
|
|
3393
3557
|
} catch (e) {
|
|
@@ -3397,53 +3561,53 @@ async function parsePdfDocument(buffer, options) {
|
|
|
3397
3561
|
});
|
|
3398
3562
|
}
|
|
3399
3563
|
}
|
|
3400
|
-
const medianFontSize =
|
|
3564
|
+
const medianFontSize = _chunk5PGOZBEQcjs.computeMedianFontSizeFromFreq.call(void 0, fontSizeFreq);
|
|
3401
3565
|
if (medianFontSize > 0) {
|
|
3402
|
-
|
|
3403
|
-
}
|
|
3404
|
-
|
|
3405
|
-
|
|
3406
|
-
|
|
3407
|
-
|
|
3408
|
-
|
|
3409
|
-
|
|
3410
|
-
|
|
3411
|
-
|
|
3566
|
+
_chunk5PGOZBEQcjs.detectHeadings.call(void 0, blocks, medianFontSize);
|
|
3567
|
+
}
|
|
3568
|
+
_chunk5PGOZBEQcjs.detectDocumentStyleHeadings.call(void 0, blocks);
|
|
3569
|
+
_chunk5PGOZBEQcjs.detectTypographyHeadings.call(void 0, blocks);
|
|
3570
|
+
_chunk5PGOZBEQcjs.detectSiblingStyleHeadings.call(void 0, blocks);
|
|
3571
|
+
_chunk5PGOZBEQcjs.detectRepeatedPageLabels.call(void 0, blocks);
|
|
3572
|
+
_chunk5PGOZBEQcjs.detectPageLeadHeadings.call(void 0, blocks);
|
|
3573
|
+
_chunk5PGOZBEQcjs.mergeStackedHeadingLines.call(void 0, blocks, medianFontSize);
|
|
3574
|
+
_chunk5PGOZBEQcjs.refineDocumentStyleHeadings.call(void 0, blocks);
|
|
3575
|
+
_chunk5PGOZBEQcjs.detectMarkerHeadings.call(void 0, blocks);
|
|
3412
3576
|
demoteNonHeadingRoles(blocks, pageHeights, faceNames);
|
|
3413
|
-
|
|
3414
|
-
|
|
3577
|
+
_chunk5PGOZBEQcjs.detectTableCaptions.call(void 0, blocks);
|
|
3578
|
+
_chunk5PGOZBEQcjs.detectKoreanListBlocks.call(void 0, blocks);
|
|
3415
3579
|
const outline = blocks.filter((b) => b.type === "heading" && b.level && b.text).map((b) => ({ level: b.level, text: b.text, pageNumber: b.pageNumber }));
|
|
3416
3580
|
sanitizeBlockControlChars(blocks);
|
|
3417
3581
|
let outBlocks = splitSingleCellTables(blocks);
|
|
3418
|
-
if (_optionalChain([options, 'optionalAccess',
|
|
3582
|
+
if (_optionalChain([options, 'optionalAccess', _363 => _363.layoutTables]) !== "keep") {
|
|
3419
3583
|
blocks.length = 0;
|
|
3420
3584
|
for (const block of outBlocks) blocks.push(block);
|
|
3421
3585
|
}
|
|
3422
3586
|
outBlocks = inlineFootnotes(outBlocks, noteMarks);
|
|
3423
3587
|
outBlocks = relocateEndnotes(outBlocks);
|
|
3424
|
-
if (_optionalChain([options, 'optionalAccess',
|
|
3588
|
+
if (_optionalChain([options, 'optionalAccess', _364 => _364.removeHeaderFooter]) !== false) outBlocks = outBlocks.filter((b) => {
|
|
3425
3589
|
if (b.type !== "paragraph" || !/^\s*\d{1,4}\s*$/.test(_nullishCoalesce(b.text, () => ( "")))) return true;
|
|
3426
3590
|
const h = pageHeights.get(_nullishCoalesce(b.pageNumber, () => ( 0)));
|
|
3427
3591
|
if (!b.bbox || !h) return false;
|
|
3428
3592
|
return b.bbox.y > h * 0.1 && b.bbox.y + b.bbox.height < h * 0.9;
|
|
3429
3593
|
});
|
|
3430
3594
|
joinLatinCellWraps(outBlocks);
|
|
3431
|
-
if (_optionalChain([options, 'optionalAccess',
|
|
3595
|
+
if (_optionalChain([options, 'optionalAccess', _365 => _365.layoutTables]) !== "keep") {
|
|
3432
3596
|
const hancom = await isHancomPdf(doc);
|
|
3433
3597
|
const shown = /* @__PURE__ */ new Map();
|
|
3434
3598
|
const markContent = (bs) => {
|
|
3435
3599
|
for (const b of _nullishCoalesce(bs, () => ( []))) if (b.table) for (const row of b.table.cells) for (const c of row) {
|
|
3436
|
-
if (
|
|
3600
|
+
if (_chunk5PGOZBEQcjs.IMAGE_CELLS.has(c)) _chunkORGWGR4Kcjs.CONTENT_CELLS.add(c);
|
|
3437
3601
|
markContent(c.blocks);
|
|
3438
3602
|
}
|
|
3439
3603
|
};
|
|
3440
3604
|
const visual = (bs) => bs.flatMap((b) => {
|
|
3441
3605
|
if (b.type !== "table") return [b];
|
|
3442
|
-
if (!hancom && b.table &&
|
|
3606
|
+
if (!hancom && b.table && _chunk5PGOZBEQcjs.CLIP_TABLES.has(b.table)) return [b];
|
|
3443
3607
|
let v = shown.get(b);
|
|
3444
3608
|
if (!v) {
|
|
3445
3609
|
markContent([b]);
|
|
3446
|
-
shown.set(b, v =
|
|
3610
|
+
shown.set(b, v = _chunkORGWGR4Kcjs.unframeLayoutTables.call(void 0, [b], !!_optionalChain([options, 'optionalAccess', _366 => _366.keepTrailingEmptyCols])));
|
|
3447
3611
|
}
|
|
3448
3612
|
return v;
|
|
3449
3613
|
});
|
|
@@ -3452,12 +3616,12 @@ async function parsePdfDocument(buffer, options) {
|
|
|
3452
3616
|
blocks.length = 0;
|
|
3453
3617
|
for (const b of kept) blocks.push(b);
|
|
3454
3618
|
}
|
|
3455
|
-
const finishMarkdown = (bs) => mergeLinkRuns(cleanPdfText(
|
|
3456
|
-
if (_optionalChain([options, 'optionalAccess',
|
|
3619
|
+
const finishMarkdown = (bs) => mergeLinkRuns(cleanPdfText(_chunkORGWGR4Kcjs.blocksToMarkdown.call(void 0, bs, { tableFormat: _optionalChain([options, 'optionalAccess', _367 => _367.tableFormat]) }), { keepLoneNumbers: true }));
|
|
3620
|
+
if (_optionalChain([options, 'optionalAccess', _368 => _368.tableFormat]) === "gfm") _chunkORGWGR4Kcjs.assignTableIds.call(void 0, blocks);
|
|
3457
3621
|
let markdown = finishMarkdown(outBlocks);
|
|
3458
3622
|
return {
|
|
3459
3623
|
markdown,
|
|
3460
|
-
pages:
|
|
3624
|
+
pages: _chunkRVBQT2PDcjs.blocksToPages.call(void 0, splitPageTables(_chunk5PGOZBEQcjs.splitPageBreakWraps.call(void 0, outBlocks)), finishMarkdown),
|
|
3461
3625
|
blocks,
|
|
3462
3626
|
metadata,
|
|
3463
3627
|
outline: outline.length > 0 ? outline : void 0,
|
|
@@ -3475,7 +3639,7 @@ async function parsePdfDocument(buffer, options) {
|
|
|
3475
3639
|
async function extractPdfMetadata(doc, metadata) {
|
|
3476
3640
|
try {
|
|
3477
3641
|
const result = await doc.getMetadata();
|
|
3478
|
-
if (!_optionalChain([result, 'optionalAccess',
|
|
3642
|
+
if (!_optionalChain([result, 'optionalAccess', _369 => _369.info])) return;
|
|
3479
3643
|
const info = result.info;
|
|
3480
3644
|
if (typeof info.Title === "string" && info.Title.trim()) metadata.title = info.Title.trim();
|
|
3481
3645
|
if (typeof info.Author === "string" && info.Author.trim()) metadata.author = info.Author.trim();
|
|
@@ -3491,8 +3655,8 @@ async function extractPdfMetadata(doc, metadata) {
|
|
|
3491
3655
|
}
|
|
3492
3656
|
async function isHancomPdf(doc) {
|
|
3493
3657
|
try {
|
|
3494
|
-
const info = await _asyncOptionalChain([(await doc.getMetadata()), 'optionalAccess', async
|
|
3495
|
-
return [_optionalChain([info, 'optionalAccess',
|
|
3658
|
+
const info = await _asyncOptionalChain([(await doc.getMetadata()), 'optionalAccess', async _370 => _370.info]);
|
|
3659
|
+
return [_optionalChain([info, 'optionalAccess', _371 => _371.Producer]), _optionalChain([info, 'optionalAccess', _372 => _372.Creator])].some((v) => typeof v === "string" && /^\s*(?:hancom\b|hwp\b)/i.test(v));
|
|
3496
3660
|
} catch (e9) {
|
|
3497
3661
|
return false;
|
|
3498
3662
|
}
|
|
@@ -3536,5 +3700,5 @@ function marginStamp(items) {
|
|
|
3536
3700
|
|
|
3537
3701
|
|
|
3538
3702
|
|
|
3539
|
-
exports.PDFJS_DOCUMENT_OPTIONS = PDFJS_DOCUMENT_OPTIONS; exports.cleanPdfText = cleanPdfText; exports.detectKoreanListBlocks =
|
|
3540
|
-
//# sourceMappingURL=parser-
|
|
3703
|
+
exports.PDFJS_DOCUMENT_OPTIONS = PDFJS_DOCUMENT_OPTIONS; exports.cleanPdfText = cleanPdfText; exports.detectKoreanListBlocks = _chunk5PGOZBEQcjs.detectKoreanListBlocks; exports.detectTableCaptions = _chunk5PGOZBEQcjs.detectTableCaptions; exports.extractPdfMetadataOnly = extractPdfMetadataOnly; exports.mergeCrossPageTables = mergeCrossPageTables; exports.ocrImageRegions = ocrImageRegions; exports.parsePdfDocument = parsePdfDocument; exports.removeHeaderFooterBlocks = _chunk5PGOZBEQcjs.removeHeaderFooterBlocks;
|
|
3704
|
+
//# sourceMappingURL=parser-AIQBU7FS.cjs.map
|