kordoc 4.18.13 → 4.19.1
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/{-DC2OO5KO.js → -LYUUVVQF.js} +11 -11
- package/dist/{chunk-ISC2TH24.js → chunk-4WTJS6ES.js} +2 -2
- package/dist/{chunk-SVIOP7PE.js → chunk-5AZQEMMG.js} +7 -7
- package/dist/{chunk-SVIOP7PE.js.map → chunk-5AZQEMMG.js.map} +1 -1
- package/dist/{chunk-GUH6HYSZ.js → chunk-6KOQPPLX.js} +25 -22
- package/dist/chunk-6KOQPPLX.js.map +1 -0
- package/dist/{chunk-PN5WWW56.js → chunk-7L5GY54Q.js} +2 -2
- package/dist/{chunk-PN5WWW56.js.map → chunk-7L5GY54Q.js.map} +1 -1
- package/dist/{chunk-PHMWSWHJ.js → chunk-7XRI4FL4.js} +2 -2
- package/dist/{chunk-32ZUIHSY.js → chunk-ADBES5QJ.js} +3 -3
- package/dist/{chunk-JWTZ3OVZ.js → chunk-BDTWXJNM.js} +2 -2
- package/dist/{chunk-INESPVEV.js → chunk-CL3CJ7X5.js} +3 -3
- package/dist/{chunk-VDEENOPW.js → chunk-DQHDI567.js} +2 -2
- package/dist/{chunk-ZNY5BRV6.js → chunk-FEGRQA3Q.js} +4 -4
- package/dist/{chunk-3FGHQWJP.cjs → chunk-FNX3ZAYB.cjs} +22 -22
- package/dist/{chunk-3FGHQWJP.cjs.map → chunk-FNX3ZAYB.cjs.map} +1 -1
- package/dist/{chunk-GGMIPTM5.cjs → chunk-GPNPYBXJ.cjs} +12 -12
- package/dist/{chunk-GGMIPTM5.cjs.map → chunk-GPNPYBXJ.cjs.map} +1 -1
- package/dist/{chunk-6CQZMVXW.cjs → chunk-HMJXB7ZE.cjs} +3 -3
- package/dist/{chunk-6CQZMVXW.cjs.map → chunk-HMJXB7ZE.cjs.map} +1 -1
- package/dist/{chunk-IRN5SDY2.js → chunk-JA5B4NPF.js} +2 -2
- package/dist/{chunk-GSW7W7AL.js → chunk-JNIJPP4B.js} +7 -4
- package/dist/chunk-JNIJPP4B.js.map +1 -0
- package/dist/{chunk-EZSWBHHI.js → chunk-KYFP5LDC.js} +2 -2
- package/dist/{chunk-XVB3PUPJ.js → chunk-L5N5UQBP.js} +10 -4
- package/dist/chunk-L5N5UQBP.js.map +1 -0
- package/dist/{chunk-6AYTYTFY.js → chunk-MSUGYK6A.js} +3 -3
- package/dist/{chunk-K6WSMTVU.cjs → chunk-RHMIEEAZ.cjs} +2 -2
- package/dist/{chunk-K6WSMTVU.cjs.map → chunk-RHMIEEAZ.cjs.map} +1 -1
- package/dist/{chunk-JKHU7HID.js → chunk-TRUR4RUJ.js} +95 -11
- package/dist/chunk-TRUR4RUJ.js.map +1 -0
- package/dist/{chunk-DHEUQXXR.js → chunk-UAAYIEIK.js} +2 -2
- package/dist/{chunk-RQEDNI4P.cjs → chunk-UOXOYZU4.cjs} +3 -3
- package/dist/{chunk-RQEDNI4P.cjs.map → chunk-UOXOYZU4.cjs.map} +1 -1
- package/dist/{chunk-6FW3AZWN.cjs → chunk-W5NXOMCD.cjs} +125 -35
- package/dist/chunk-W5NXOMCD.cjs.map +1 -0
- package/dist/{chunk-V7LKQNC4.js → chunk-X6ME7YYS.js} +2 -2
- package/dist/{chunk-LKA7Z2NH.js → chunk-XFZMRCGJ.js} +2 -2
- package/dist/{chunk-JPSLMPFI.js → chunk-YLST4S4P.js} +103 -13
- package/dist/chunk-YLST4S4P.js.map +1 -0
- package/dist/{chunk-EBXJ45VZ.js → chunk-Z2WI3E4N.js} +2 -2
- package/dist/{chunk-EBXJ45VZ.js.map → chunk-Z2WI3E4N.js.map} +1 -1
- package/dist/{chunk-7LOD4IGO.js → chunk-ZTGTFO52.js} +4 -4
- package/dist/chunks-T67OQGPJ.js +10 -0
- package/dist/cli.js +39 -28
- package/dist/cli.js.map +1 -1
- package/dist/{formula-DAMFHLQO.js → formula-G4YA7SNQ.js} +3 -3
- package/dist/{formula-HJNQGPRC.cjs → formula-J3UUIPCX.cjs} +9 -9
- package/dist/{formula-HJNQGPRC.cjs.map → formula-J3UUIPCX.cjs.map} +1 -1
- package/dist/{formula-YCAO5IVW.js → formula-QSZRYZ44.js} +4 -4
- package/dist/{image-ocr-AZ25IOC7.cjs → image-ocr-467KLV3F.cjs} +15 -15
- package/dist/{image-ocr-AZ25IOC7.cjs.map → image-ocr-467KLV3F.cjs.map} +1 -1
- package/dist/{image-ocr-VH54SDZ7.js → image-ocr-I52GBXRE.js} +6 -6
- package/dist/{image-ocr-PAF76DAW.js → image-ocr-ZP3F4MUY.js} +9 -9
- package/dist/index.cjs +669 -663
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +15 -2
- package/dist/index.d.ts +15 -2
- package/dist/index.js +26 -20
- package/dist/index.js.map +1 -1
- package/dist/mcp.js +25 -23
- package/dist/mcp.js.map +1 -1
- package/dist/{model-bundle-53CHDYCG.js → model-bundle-FEUM7XXS.js} +5 -5
- package/dist/{models-UVLAKK3M.js → models-6QCNX5YR.js} +5 -5
- package/dist/{parser-I4D3TRGU.js → parser-6EIBURDE.js} +179 -13
- package/dist/parser-6EIBURDE.js.map +1 -0
- package/dist/{parser-HWAOPQYK.cjs → parser-BIJBX2D5.cjs} +393 -227
- package/dist/parser-BIJBX2D5.cjs.map +1 -0
- package/dist/{parser-Z6PHB54O.js → parser-YX4LGKIK.js} +176 -10
- package/dist/parser-YX4LGKIK.js.map +1 -0
- package/dist/pdf-ocr-DXQIMO77.cjs +17 -0
- package/dist/{pdf-ocr-HR6CXGTX.cjs.map → pdf-ocr-DXQIMO77.cjs.map} +1 -1
- package/dist/pdf-ocr-MESGGING.js +20 -0
- package/dist/pdf-ocr-YSRBRIPR.js +16 -0
- package/dist/{profile-io-WHCWCOPW.js → profile-io-ATHFEUAP.js} +3 -3
- package/dist/{rasterize-5DZ3DHGH.js → rasterize-SG3CLXMQ.js} +3 -3
- package/dist/{redact-doc-RNJVMFGQ.js → redact-doc-K3S4HFHU.js} +11 -11
- package/dist/{render-NZ6RA6SW.js → render-6CQJM7VE.js} +7 -7
- package/dist/seal-SMO4544N.js +10 -0
- package/dist/{setup-U3EQNK4Z.js → setup-CZ5KHGPI.js} +3 -3
- package/dist/visual-UWYGQLOU.js +20 -0
- package/dist/{watch-GB2M7XU6.js → watch-RQRIGLFF.js} +12 -12
- package/package.json +3 -2
- package/dist/chunk-6FW3AZWN.cjs.map +0 -1
- package/dist/chunk-GSW7W7AL.js.map +0 -1
- package/dist/chunk-GUH6HYSZ.js.map +0 -1
- package/dist/chunk-JKHU7HID.js.map +0 -1
- package/dist/chunk-JPSLMPFI.js.map +0 -1
- package/dist/chunk-XVB3PUPJ.js.map +0 -1
- package/dist/chunks-JZW2TXIZ.js +0 -10
- package/dist/parser-HWAOPQYK.cjs.map +0 -1
- package/dist/parser-I4D3TRGU.js.map +0 -1
- package/dist/parser-Z6PHB54O.js.map +0 -1
- package/dist/pdf-ocr-F4ICXO7W.js +0 -20
- package/dist/pdf-ocr-HR6CXGTX.cjs +0 -17
- package/dist/pdf-ocr-JI3K7JIN.js +0 -16
- package/dist/seal-WHJ6O5HT.js +0 -10
- package/dist/visual-JDAS4R43.js +0 -20
- /package/dist/{-DC2OO5KO.js.map → -LYUUVVQF.js.map} +0 -0
- /package/dist/{chunk-ISC2TH24.js.map → chunk-4WTJS6ES.js.map} +0 -0
- /package/dist/{chunk-PHMWSWHJ.js.map → chunk-7XRI4FL4.js.map} +0 -0
- /package/dist/{chunk-32ZUIHSY.js.map → chunk-ADBES5QJ.js.map} +0 -0
- /package/dist/{chunk-JWTZ3OVZ.js.map → chunk-BDTWXJNM.js.map} +0 -0
- /package/dist/{chunk-INESPVEV.js.map → chunk-CL3CJ7X5.js.map} +0 -0
- /package/dist/{chunk-VDEENOPW.js.map → chunk-DQHDI567.js.map} +0 -0
- /package/dist/{chunk-ZNY5BRV6.js.map → chunk-FEGRQA3Q.js.map} +0 -0
- /package/dist/{chunk-IRN5SDY2.js.map → chunk-JA5B4NPF.js.map} +0 -0
- /package/dist/{chunk-EZSWBHHI.js.map → chunk-KYFP5LDC.js.map} +0 -0
- /package/dist/{chunk-6AYTYTFY.js.map → chunk-MSUGYK6A.js.map} +0 -0
- /package/dist/{chunk-DHEUQXXR.js.map → chunk-UAAYIEIK.js.map} +0 -0
- /package/dist/{chunk-V7LKQNC4.js.map → chunk-X6ME7YYS.js.map} +0 -0
- /package/dist/{chunk-LKA7Z2NH.js.map → chunk-XFZMRCGJ.js.map} +0 -0
- /package/dist/{chunk-7LOD4IGO.js.map → chunk-ZTGTFO52.js.map} +0 -0
- /package/dist/{chunks-JZW2TXIZ.js.map → chunks-T67OQGPJ.js.map} +0 -0
- /package/dist/{formula-DAMFHLQO.js.map → formula-G4YA7SNQ.js.map} +0 -0
- /package/dist/{formula-YCAO5IVW.js.map → formula-QSZRYZ44.js.map} +0 -0
- /package/dist/{image-ocr-VH54SDZ7.js.map → image-ocr-I52GBXRE.js.map} +0 -0
- /package/dist/{image-ocr-PAF76DAW.js.map → image-ocr-ZP3F4MUY.js.map} +0 -0
- /package/dist/{model-bundle-53CHDYCG.js.map → model-bundle-FEUM7XXS.js.map} +0 -0
- /package/dist/{models-UVLAKK3M.js.map → models-6QCNX5YR.js.map} +0 -0
- /package/dist/{pdf-ocr-F4ICXO7W.js.map → pdf-ocr-MESGGING.js.map} +0 -0
- /package/dist/{pdf-ocr-JI3K7JIN.js.map → pdf-ocr-YSRBRIPR.js.map} +0 -0
- /package/dist/{profile-io-WHCWCOPW.js.map → profile-io-ATHFEUAP.js.map} +0 -0
- /package/dist/{rasterize-5DZ3DHGH.js.map → rasterize-SG3CLXMQ.js.map} +0 -0
- /package/dist/{redact-doc-RNJVMFGQ.js.map → redact-doc-K3S4HFHU.js.map} +0 -0
- /package/dist/{render-NZ6RA6SW.js.map → render-6CQJM7VE.js.map} +0 -0
- /package/dist/{seal-WHJ6O5HT.js.map → seal-SMO4544N.js.map} +0 -0
- /package/dist/{setup-U3EQNK4Z.js.map → setup-CZ5KHGPI.js.map} +0 -0
- /package/dist/{visual-JDAS4R43.js.map → visual-UWYGQLOU.js.map} +0 -0
- /package/dist/{watch-GB2M7XU6.js.map → watch-RQRIGLFF.js.map} +0 -0
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
3
|
ALL_OCR_MODELS
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-XFZMRCGJ.js";
|
|
5
5
|
import {
|
|
6
6
|
ALL_FORMULA_MODELS,
|
|
7
7
|
getModelStatusIn,
|
|
8
8
|
getModelsDir
|
|
9
|
-
} from "./chunk-
|
|
10
|
-
import "./chunk-
|
|
11
|
-
import "./chunk-
|
|
9
|
+
} from "./chunk-BDTWXJNM.js";
|
|
10
|
+
import "./chunk-4WTJS6ES.js";
|
|
11
|
+
import "./chunk-7L5GY54Q.js";
|
|
12
12
|
|
|
13
13
|
// src/shared/model-bundle.ts
|
|
14
14
|
import { copyFile, mkdir } from "fs/promises";
|
|
@@ -101,4 +101,4 @@ export {
|
|
|
101
101
|
importModels,
|
|
102
102
|
modelCacheStatus
|
|
103
103
|
};
|
|
104
|
-
//# sourceMappingURL=model-bundle-
|
|
104
|
+
//# sourceMappingURL=model-bundle-FEUM7XXS.js.map
|
|
@@ -10,10 +10,10 @@ import {
|
|
|
10
10
|
ocrModelPath,
|
|
11
11
|
ocrModelsCached,
|
|
12
12
|
parseCharacterDict
|
|
13
|
-
} from "./chunk-
|
|
14
|
-
import "./chunk-
|
|
15
|
-
import "./chunk-
|
|
16
|
-
import "./chunk-
|
|
13
|
+
} from "./chunk-XFZMRCGJ.js";
|
|
14
|
+
import "./chunk-BDTWXJNM.js";
|
|
15
|
+
import "./chunk-4WTJS6ES.js";
|
|
16
|
+
import "./chunk-7L5GY54Q.js";
|
|
17
17
|
export {
|
|
18
18
|
ALL_OCR_MODELS,
|
|
19
19
|
OCR_DET_MODEL,
|
|
@@ -26,4 +26,4 @@ export {
|
|
|
26
26
|
ocrModelsCached,
|
|
27
27
|
parseCharacterDict
|
|
28
28
|
};
|
|
29
|
-
//# sourceMappingURL=models-
|
|
29
|
+
//# sourceMappingURL=models-6QCNX5YR.js.map
|
|
@@ -50,38 +50,40 @@ import {
|
|
|
50
50
|
startsNewItem,
|
|
51
51
|
trimTrailingEmptyTableCols,
|
|
52
52
|
wrapJoiner
|
|
53
|
-
} from "./chunk-
|
|
53
|
+
} from "./chunk-CL3CJ7X5.js";
|
|
54
54
|
import {
|
|
55
55
|
ocrModelsCached
|
|
56
|
-
} from "./chunk-
|
|
57
|
-
import "./chunk-
|
|
58
|
-
import "./chunk-
|
|
56
|
+
} from "./chunk-XFZMRCGJ.js";
|
|
57
|
+
import "./chunk-BDTWXJNM.js";
|
|
58
|
+
import "./chunk-4WTJS6ES.js";
|
|
59
59
|
import {
|
|
60
60
|
blocksToPages
|
|
61
|
-
} from "./chunk-
|
|
61
|
+
} from "./chunk-X6ME7YYS.js";
|
|
62
62
|
import {
|
|
63
63
|
encodePng
|
|
64
64
|
} from "./chunk-7FCNOKOR.js";
|
|
65
65
|
import {
|
|
66
66
|
CELL_EDGES,
|
|
67
|
+
CELL_PAGES,
|
|
67
68
|
CONTENT_CELLS,
|
|
68
69
|
escapeLiteralTags,
|
|
69
70
|
stripScriptTags,
|
|
70
71
|
unframeLayoutTables
|
|
71
|
-
} from "./chunk-
|
|
72
|
+
} from "./chunk-L5N5UQBP.js";
|
|
72
73
|
import {
|
|
73
74
|
hasRequestedPagesAfter,
|
|
74
75
|
parsePageRange
|
|
75
76
|
} from "./chunk-VQFA55IC.js";
|
|
76
77
|
import {
|
|
77
78
|
WINGDINGS,
|
|
79
|
+
assignTableIds,
|
|
78
80
|
blocksToMarkdown,
|
|
79
81
|
escapeLiteralDollar
|
|
80
|
-
} from "./chunk-
|
|
82
|
+
} from "./chunk-TRUR4RUJ.js";
|
|
81
83
|
import {
|
|
82
84
|
KordocError,
|
|
83
85
|
sanitizeHref
|
|
84
|
-
} from "./chunk-
|
|
86
|
+
} from "./chunk-7L5GY54Q.js";
|
|
85
87
|
|
|
86
88
|
// src/pdf/ocr-region-merge.ts
|
|
87
89
|
function mergeOcrImageRegions(blocks, page, regions, ocrBlocks) {
|
|
@@ -762,6 +764,167 @@ function splitContactTables(blocks) {
|
|
|
762
764
|
}
|
|
763
765
|
}
|
|
764
766
|
|
|
767
|
+
// src/pdf/table-pages.ts
|
|
768
|
+
var CELL_SPLITS = /* @__PURE__ */ new WeakMap();
|
|
769
|
+
function relocate(src, dst, from = 0) {
|
|
770
|
+
const out = [];
|
|
771
|
+
for (const s of CELL_SPLITS.get(src) ?? []) {
|
|
772
|
+
const at = dst.text.indexOf(src.text.slice(s.at, s.at + 20).trimEnd(), Math.max(from, out.at(-1)?.at ?? 0));
|
|
773
|
+
if (at >= 0) out.push({ at, page: s.page });
|
|
774
|
+
}
|
|
775
|
+
return out;
|
|
776
|
+
}
|
|
777
|
+
var setSplits = (cell, splits) => {
|
|
778
|
+
if (splits.length) CELL_SPLITS.set(cell, splits.sort((a, b) => a.at - b.at));
|
|
779
|
+
};
|
|
780
|
+
function markContinuedText(cell, add, page) {
|
|
781
|
+
if (!add.text.trim()) return;
|
|
782
|
+
const base = cell.text.trim() ? cell.text.length + 1 : 0;
|
|
783
|
+
setSplits(cell, [
|
|
784
|
+
...CELL_SPLITS.get(cell) ?? [],
|
|
785
|
+
{ at: base, page },
|
|
786
|
+
...(CELL_SPLITS.get(add) ?? []).map((s) => ({ at: base + s.at, page: s.page }))
|
|
787
|
+
]);
|
|
788
|
+
}
|
|
789
|
+
function rowStarts(t) {
|
|
790
|
+
const covered = /* @__PURE__ */ new Set();
|
|
791
|
+
const rows = [];
|
|
792
|
+
for (let r = 0; r < t.rows; r++) {
|
|
793
|
+
const starts = [];
|
|
794
|
+
for (let c = 0; c < t.cols; c++) {
|
|
795
|
+
if (covered.has(r * 1e5 + c)) continue;
|
|
796
|
+
const cell = t.cells[r]?.[c];
|
|
797
|
+
if (!cell) continue;
|
|
798
|
+
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);
|
|
799
|
+
starts.push({ cell, c });
|
|
800
|
+
}
|
|
801
|
+
rows.push(starts);
|
|
802
|
+
}
|
|
803
|
+
return rows;
|
|
804
|
+
}
|
|
805
|
+
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));
|
|
806
|
+
function cellPage(cell) {
|
|
807
|
+
const p = CELL_PAGES.get(cell);
|
|
808
|
+
if (p !== void 0 || !cell.blocks?.length || cell.blocks.some((b) => b.pageNumber === void 0)) return p;
|
|
809
|
+
return Math.min(...cell.blocks.map((b) => b.pageNumber));
|
|
810
|
+
}
|
|
811
|
+
function tableRowPages(t, pageNumber) {
|
|
812
|
+
const pages = [];
|
|
813
|
+
let prev = pageNumber;
|
|
814
|
+
for (const starts of rowStarts(t)) {
|
|
815
|
+
let mark, text = false;
|
|
816
|
+
for (const { cell } of starts) {
|
|
817
|
+
const p = cellPage(cell);
|
|
818
|
+
if (p !== void 0) mark = Math.max(mark ?? p, p);
|
|
819
|
+
else if (cell.text.trim() || cell.blocks?.length) text = true;
|
|
820
|
+
}
|
|
821
|
+
const page = mark ?? (text ? pageNumber : prev);
|
|
822
|
+
prev = page !== void 0 && prev !== void 0 ? Math.max(prev, page) : page ?? prev;
|
|
823
|
+
pages.push(prev);
|
|
824
|
+
}
|
|
825
|
+
return pages;
|
|
826
|
+
}
|
|
827
|
+
function markJoinedPages(table, prev, curr) {
|
|
828
|
+
const pt = prev.table, ct = curr.table;
|
|
829
|
+
if (!curr.pageNumber || table.rows < pt.rows) return;
|
|
830
|
+
const pp = tableRowPages(pt, prev.pageNumber), cp = tableRowPages(ct, curr.pageNumber);
|
|
831
|
+
const off = table.rows - ct.rows;
|
|
832
|
+
const rows = rowStarts(table), ptRows = rowStarts(pt), ctRows = rowStarts(ct);
|
|
833
|
+
rows.forEach((starts, r) => {
|
|
834
|
+
const page2 = r < pt.rows ? pp[r] : cp[r - off];
|
|
835
|
+
for (const { cell } of starts) {
|
|
836
|
+
if (page2 !== void 0 && page2 !== prev.pageNumber) CELL_PAGES.set(cell, page2);
|
|
837
|
+
const src = (r < pt.rows ? ptRows[r] : ctRows[r - off])?.find((s) => s.cell !== cell && s.cell.text === cell.text && CELL_SPLITS.has(s.cell));
|
|
838
|
+
if (src) setSplits(cell, relocate(src.cell, cell));
|
|
839
|
+
}
|
|
840
|
+
});
|
|
841
|
+
const cr = pt.rows - 1 - off, page = cp[cr];
|
|
842
|
+
if (cr < 0 || page === void 0 || page === prev.pageNumber) return;
|
|
843
|
+
const tails = ctRows[cr].filter((s) => s.cell.text.trim());
|
|
844
|
+
for (const { cell } of ctRows[cr]) for (const b of cell.blocks ?? []) b.pageNumber ??= page;
|
|
845
|
+
const heads = covering(pt, pt.rows - 1);
|
|
846
|
+
for (const cell of covering(table, pt.rows - 1)) {
|
|
847
|
+
if (cell.blocks?.length) continue;
|
|
848
|
+
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];
|
|
849
|
+
if (!head) continue;
|
|
850
|
+
const from = head.text.trimEnd().length;
|
|
851
|
+
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];
|
|
852
|
+
if (!hit) continue;
|
|
853
|
+
setSplits(cell, [...relocate(head, cell), { at: hit.at, page }, ...relocate(hit.t, cell, hit.at)]);
|
|
854
|
+
}
|
|
855
|
+
}
|
|
856
|
+
function splitCell(cell, page) {
|
|
857
|
+
if (page === void 0) return null;
|
|
858
|
+
if (cell.blocks?.length) {
|
|
859
|
+
const k2 = cell.blocks.findIndex((b) => (b.pageNumber ?? page) > page);
|
|
860
|
+
if (k2 <= 0) return null;
|
|
861
|
+
const head = cell.blocks.slice(0, k2), tail = cell.blocks.slice(k2);
|
|
862
|
+
const text = (bs) => bs.map((b) => b.text ?? "").filter(Boolean).join("\n");
|
|
863
|
+
return { head: { text: text(head), blocks: head }, tail: { text: text(tail), blocks: tail }, page: tail[0].pageNumber, rest: [] };
|
|
864
|
+
}
|
|
865
|
+
const splits = CELL_SPLITS.get(cell) ?? [];
|
|
866
|
+
const k = splits.findIndex((s2) => s2.page > page && s2.at < cell.text.length);
|
|
867
|
+
if (k < 0) return null;
|
|
868
|
+
const s = splits[k];
|
|
869
|
+
const rest = cell.text.slice(s.at), lead = rest.length - rest.trimStart().length;
|
|
870
|
+
return {
|
|
871
|
+
head: { text: cell.text.slice(0, s.at).trimEnd() },
|
|
872
|
+
tail: { text: rest.trim() },
|
|
873
|
+
page: s.page,
|
|
874
|
+
rest: splits.slice(k + 1).map((x) => ({ at: x.at - s.at - lead, page: x.page })).filter((x) => x.at > 0)
|
|
875
|
+
};
|
|
876
|
+
}
|
|
877
|
+
function splitCrossPageRows(t, pageNumber) {
|
|
878
|
+
const pages = tableRowPages(t, pageNumber);
|
|
879
|
+
const rows = rowStarts(t);
|
|
880
|
+
for (let r = 0; r < t.rows; r++) {
|
|
881
|
+
const splits = rows[r].map((s) => ({ ...s, split: splitCell(s.cell, pages[r]) })).filter((s) => s.split);
|
|
882
|
+
if (!splits.length) continue;
|
|
883
|
+
const clone = (cell, patch) => {
|
|
884
|
+
const out = { ...cell, ...patch };
|
|
885
|
+
const p = CELL_PAGES.get(cell);
|
|
886
|
+
if (p !== void 0) CELL_PAGES.set(out, p);
|
|
887
|
+
if (!("text" in patch) && CELL_SPLITS.has(cell)) CELL_SPLITS.set(out, CELL_SPLITS.get(cell));
|
|
888
|
+
return out;
|
|
889
|
+
};
|
|
890
|
+
const e = Math.max(...splits.map((s) => r + s.cell.rowSpan - 1));
|
|
891
|
+
const cells = t.cells.map((row2) => row2.slice());
|
|
892
|
+
const row = Array.from({ length: t.cols }, () => ({ text: "", colSpan: 1, rowSpan: 1 }));
|
|
893
|
+
for (const { cell, c, split } of splits) {
|
|
894
|
+
cells[r][c] = clone(cell, split.head);
|
|
895
|
+
const tail = { ...cell, ...split.tail, rowSpan: 1 };
|
|
896
|
+
CELL_PAGES.set(tail, split.page);
|
|
897
|
+
setSplits(tail, split.rest);
|
|
898
|
+
row[c] = tail;
|
|
899
|
+
}
|
|
900
|
+
rows.forEach((starts, rr) => {
|
|
901
|
+
for (const { cell, c } of starts) {
|
|
902
|
+
if (splits.some((s) => s.cell === cell) || rr > e || rr + cell.rowSpan - 1 <= e) continue;
|
|
903
|
+
cells[rr][c] = clone(cells[rr][c], { rowSpan: cell.rowSpan + 1 });
|
|
904
|
+
}
|
|
905
|
+
});
|
|
906
|
+
cells.splice(e + 1, 0, row);
|
|
907
|
+
return splitCrossPageRows({ ...t, rows: t.rows + 1, cells }, pageNumber);
|
|
908
|
+
}
|
|
909
|
+
return t;
|
|
910
|
+
}
|
|
911
|
+
function splitPageTables(blocks) {
|
|
912
|
+
return blocks.flatMap((b) => {
|
|
913
|
+
if (b.type !== "table" || !b.table) return [b];
|
|
914
|
+
const t = splitCrossPageRows(b.table, b.pageNumber);
|
|
915
|
+
const pages = tableRowPages(t, b.pageNumber);
|
|
916
|
+
const cuts = [0];
|
|
917
|
+
for (let r = 1; r < t.rows; r++) if (pages[r] !== pages[r - 1]) cuts.push(r);
|
|
918
|
+
if (cuts.length === 1) return t === b.table ? [b] : [{ ...b, table: t }];
|
|
919
|
+
return cuts.map((from, k) => {
|
|
920
|
+
const end = cuts[k + 1] ?? t.rows;
|
|
921
|
+
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));
|
|
922
|
+
const table = { ...t, rows: end - from, cells, ...k ? { caption: void 0, captionBlocks: void 0 } : {} };
|
|
923
|
+
return { ...b, table, pageNumber: pages[from] };
|
|
924
|
+
});
|
|
925
|
+
});
|
|
926
|
+
}
|
|
927
|
+
|
|
765
928
|
// src/pdf/table-parts.ts
|
|
766
929
|
var flowText = (text) => text.replace(/<\/?u>|~~/g, "");
|
|
767
930
|
var PART_COL_TOL = 1;
|
|
@@ -1181,6 +1344,7 @@ function leftColumnOf(b, t) {
|
|
|
1181
1344
|
}
|
|
1182
1345
|
function placeJoined(blocks, i, j, table) {
|
|
1183
1346
|
const prev = blocks[i];
|
|
1347
|
+
markJoinedPages(table, prev, blocks[j]);
|
|
1184
1348
|
blocks[i] = { ...prev, table };
|
|
1185
1349
|
blocks.splice(j, 1);
|
|
1186
1350
|
let k = j - 1;
|
|
@@ -1534,6 +1698,7 @@ function mergeContinuedCells(blocks, pageHeights) {
|
|
|
1534
1698
|
if (!cell || !add) continue;
|
|
1535
1699
|
const at = cell.blocks || add.blocks ? cellBlocks(cell, prev.pageNumber).length : -1;
|
|
1536
1700
|
if (cell.blocks || add.blocks) cell.blocks = [...cellBlocks(cell, prev.pageNumber), ...cellBlocks(add, part.pageNumber)];
|
|
1701
|
+
else if (part.pageNumber) markContinuedText(cell, add, part.pageNumber);
|
|
1537
1702
|
cell.text = [cell.text, add.text].filter((s) => s.trim()).join("\n");
|
|
1538
1703
|
joinCellEdges(cell, add);
|
|
1539
1704
|
const lines = CELL_LINES.get(add);
|
|
@@ -2882,7 +3047,7 @@ function mergeLinkRuns(markdown) {
|
|
|
2882
3047
|
|
|
2883
3048
|
// src/pdf/formula-ocr.ts
|
|
2884
3049
|
async function applyFormulaOcr(buffer, blocks, pageFilter, effectivePageCount, warnings, _onProgress) {
|
|
2885
|
-
const formulaMod = await import("./formula-
|
|
3050
|
+
const formulaMod = await import("./formula-QSZRYZ44.js");
|
|
2886
3051
|
const { FormulaPipeline, ensureFormulaModels } = formulaMod;
|
|
2887
3052
|
await ensureFormulaModels((p) => {
|
|
2888
3053
|
if (p.phase === "download" && p.total) {
|
|
@@ -3303,7 +3468,7 @@ async function parsePdfDocument(buffer, options) {
|
|
|
3303
3468
|
}
|
|
3304
3469
|
if (targets.size > 0) {
|
|
3305
3470
|
try {
|
|
3306
|
-
const { runPdfOcr } = await import("./pdf-ocr-
|
|
3471
|
+
const { runPdfOcr } = await import("./pdf-ocr-MESGGING.js");
|
|
3307
3472
|
const mode = typeof options?.ocr === "function" ? options.ocr : "builtin";
|
|
3308
3473
|
const regionPages = new Map([...ocrRegions].filter(([p]) => options?.ocr !== "force" && !isImageBased && !pageQuality.find((q) => q.page === p)?.needsOcr));
|
|
3309
3474
|
const ocrPageBlocks = await runPdfOcr(ocrBuffer, targets, mode, warnings, options?.onProgress, options?.tables !== false, vectorPageOps, regionPages);
|
|
@@ -3456,11 +3621,12 @@ async function parsePdfDocument(buffer, options) {
|
|
|
3456
3621
|
blocks.length = 0;
|
|
3457
3622
|
for (const b of kept) blocks.push(b);
|
|
3458
3623
|
}
|
|
3459
|
-
const finishMarkdown = (bs) => mergeLinkRuns(cleanPdfText(blocksToMarkdown(bs), { keepLoneNumbers: true }));
|
|
3624
|
+
const finishMarkdown = (bs) => mergeLinkRuns(cleanPdfText(blocksToMarkdown(bs, { tableFormat: options?.tableFormat }), { keepLoneNumbers: true }));
|
|
3625
|
+
if (options?.tableFormat === "gfm") assignTableIds(blocks);
|
|
3460
3626
|
let markdown = finishMarkdown(outBlocks);
|
|
3461
3627
|
return {
|
|
3462
3628
|
markdown,
|
|
3463
|
-
pages: blocksToPages(splitPageBreakWraps(outBlocks), finishMarkdown),
|
|
3629
|
+
pages: blocksToPages(splitPageTables(splitPageBreakWraps(outBlocks)), finishMarkdown),
|
|
3464
3630
|
blocks,
|
|
3465
3631
|
metadata,
|
|
3466
3632
|
outline: outline.length > 0 ? outline : void 0,
|
|
@@ -3540,4 +3706,4 @@ export {
|
|
|
3540
3706
|
parsePdfDocument,
|
|
3541
3707
|
removeHeaderFooterBlocks
|
|
3542
3708
|
};
|
|
3543
|
-
//# sourceMappingURL=parser-
|
|
3709
|
+
//# sourceMappingURL=parser-6EIBURDE.js.map
|