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,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
blocksToPages,
|
|
3
3
|
encodePng
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-DQHDI567.js";
|
|
5
5
|
import {
|
|
6
6
|
hasRequestedPagesAfter,
|
|
7
7
|
parsePageRange
|
|
@@ -58,22 +58,24 @@ import {
|
|
|
58
58
|
startsNewItem,
|
|
59
59
|
trimTrailingEmptyTableCols,
|
|
60
60
|
wrapJoiner
|
|
61
|
-
} from "./chunk-
|
|
61
|
+
} from "./chunk-FEGRQA3Q.js";
|
|
62
62
|
import {
|
|
63
63
|
CELL_EDGES,
|
|
64
|
+
CELL_PAGES,
|
|
64
65
|
CONTENT_CELLS,
|
|
65
66
|
WINGDINGS,
|
|
67
|
+
assignTableIds,
|
|
66
68
|
blocksToMarkdown,
|
|
67
69
|
escapeLiteralDollar,
|
|
68
70
|
escapeLiteralTags,
|
|
69
71
|
stripScriptTags,
|
|
70
72
|
unframeLayoutTables
|
|
71
|
-
} from "./chunk-
|
|
72
|
-
import "./chunk-
|
|
73
|
+
} from "./chunk-YLST4S4P.js";
|
|
74
|
+
import "./chunk-7XRI4FL4.js";
|
|
73
75
|
import {
|
|
74
76
|
KordocError,
|
|
75
77
|
sanitizeHref
|
|
76
|
-
} from "./chunk-
|
|
78
|
+
} from "./chunk-Z2WI3E4N.js";
|
|
77
79
|
|
|
78
80
|
// src/pdf/ocr-region-merge.ts
|
|
79
81
|
function mergeOcrImageRegions(blocks, page, regions, ocrBlocks) {
|
|
@@ -754,6 +756,167 @@ function splitContactTables(blocks) {
|
|
|
754
756
|
}
|
|
755
757
|
}
|
|
756
758
|
|
|
759
|
+
// src/pdf/table-pages.ts
|
|
760
|
+
var CELL_SPLITS = /* @__PURE__ */ new WeakMap();
|
|
761
|
+
function relocate(src, dst, from = 0) {
|
|
762
|
+
const out = [];
|
|
763
|
+
for (const s of CELL_SPLITS.get(src) ?? []) {
|
|
764
|
+
const at = dst.text.indexOf(src.text.slice(s.at, s.at + 20).trimEnd(), Math.max(from, out.at(-1)?.at ?? 0));
|
|
765
|
+
if (at >= 0) out.push({ at, page: s.page });
|
|
766
|
+
}
|
|
767
|
+
return out;
|
|
768
|
+
}
|
|
769
|
+
var setSplits = (cell, splits) => {
|
|
770
|
+
if (splits.length) CELL_SPLITS.set(cell, splits.sort((a, b) => a.at - b.at));
|
|
771
|
+
};
|
|
772
|
+
function markContinuedText(cell, add, page) {
|
|
773
|
+
if (!add.text.trim()) return;
|
|
774
|
+
const base = cell.text.trim() ? cell.text.length + 1 : 0;
|
|
775
|
+
setSplits(cell, [
|
|
776
|
+
...CELL_SPLITS.get(cell) ?? [],
|
|
777
|
+
{ at: base, page },
|
|
778
|
+
...(CELL_SPLITS.get(add) ?? []).map((s) => ({ at: base + s.at, page: s.page }))
|
|
779
|
+
]);
|
|
780
|
+
}
|
|
781
|
+
function rowStarts(t) {
|
|
782
|
+
const covered = /* @__PURE__ */ new Set();
|
|
783
|
+
const rows = [];
|
|
784
|
+
for (let r = 0; r < t.rows; r++) {
|
|
785
|
+
const starts = [];
|
|
786
|
+
for (let c = 0; c < t.cols; c++) {
|
|
787
|
+
if (covered.has(r * 1e5 + c)) continue;
|
|
788
|
+
const cell = t.cells[r]?.[c];
|
|
789
|
+
if (!cell) continue;
|
|
790
|
+
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);
|
|
791
|
+
starts.push({ cell, c });
|
|
792
|
+
}
|
|
793
|
+
rows.push(starts);
|
|
794
|
+
}
|
|
795
|
+
return rows;
|
|
796
|
+
}
|
|
797
|
+
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));
|
|
798
|
+
function cellPage(cell) {
|
|
799
|
+
const p = CELL_PAGES.get(cell);
|
|
800
|
+
if (p !== void 0 || !cell.blocks?.length || cell.blocks.some((b) => b.pageNumber === void 0)) return p;
|
|
801
|
+
return Math.min(...cell.blocks.map((b) => b.pageNumber));
|
|
802
|
+
}
|
|
803
|
+
function tableRowPages(t, pageNumber) {
|
|
804
|
+
const pages = [];
|
|
805
|
+
let prev = pageNumber;
|
|
806
|
+
for (const starts of rowStarts(t)) {
|
|
807
|
+
let mark, text = false;
|
|
808
|
+
for (const { cell } of starts) {
|
|
809
|
+
const p = cellPage(cell);
|
|
810
|
+
if (p !== void 0) mark = Math.max(mark ?? p, p);
|
|
811
|
+
else if (cell.text.trim() || cell.blocks?.length) text = true;
|
|
812
|
+
}
|
|
813
|
+
const page = mark ?? (text ? pageNumber : prev);
|
|
814
|
+
prev = page !== void 0 && prev !== void 0 ? Math.max(prev, page) : page ?? prev;
|
|
815
|
+
pages.push(prev);
|
|
816
|
+
}
|
|
817
|
+
return pages;
|
|
818
|
+
}
|
|
819
|
+
function markJoinedPages(table, prev, curr) {
|
|
820
|
+
const pt = prev.table, ct = curr.table;
|
|
821
|
+
if (!curr.pageNumber || table.rows < pt.rows) return;
|
|
822
|
+
const pp = tableRowPages(pt, prev.pageNumber), cp = tableRowPages(ct, curr.pageNumber);
|
|
823
|
+
const off = table.rows - ct.rows;
|
|
824
|
+
const rows = rowStarts(table), ptRows = rowStarts(pt), ctRows = rowStarts(ct);
|
|
825
|
+
rows.forEach((starts, r) => {
|
|
826
|
+
const page2 = r < pt.rows ? pp[r] : cp[r - off];
|
|
827
|
+
for (const { cell } of starts) {
|
|
828
|
+
if (page2 !== void 0 && page2 !== prev.pageNumber) CELL_PAGES.set(cell, page2);
|
|
829
|
+
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));
|
|
830
|
+
if (src) setSplits(cell, relocate(src.cell, cell));
|
|
831
|
+
}
|
|
832
|
+
});
|
|
833
|
+
const cr = pt.rows - 1 - off, page = cp[cr];
|
|
834
|
+
if (cr < 0 || page === void 0 || page === prev.pageNumber) return;
|
|
835
|
+
const tails = ctRows[cr].filter((s) => s.cell.text.trim());
|
|
836
|
+
for (const { cell } of ctRows[cr]) for (const b of cell.blocks ?? []) b.pageNumber ??= page;
|
|
837
|
+
const heads = covering(pt, pt.rows - 1);
|
|
838
|
+
for (const cell of covering(table, pt.rows - 1)) {
|
|
839
|
+
if (cell.blocks?.length) continue;
|
|
840
|
+
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];
|
|
841
|
+
if (!head) continue;
|
|
842
|
+
const from = head.text.trimEnd().length;
|
|
843
|
+
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];
|
|
844
|
+
if (!hit) continue;
|
|
845
|
+
setSplits(cell, [...relocate(head, cell), { at: hit.at, page }, ...relocate(hit.t, cell, hit.at)]);
|
|
846
|
+
}
|
|
847
|
+
}
|
|
848
|
+
function splitCell(cell, page) {
|
|
849
|
+
if (page === void 0) return null;
|
|
850
|
+
if (cell.blocks?.length) {
|
|
851
|
+
const k2 = cell.blocks.findIndex((b) => (b.pageNumber ?? page) > page);
|
|
852
|
+
if (k2 <= 0) return null;
|
|
853
|
+
const head = cell.blocks.slice(0, k2), tail = cell.blocks.slice(k2);
|
|
854
|
+
const text = (bs) => bs.map((b) => b.text ?? "").filter(Boolean).join("\n");
|
|
855
|
+
return { head: { text: text(head), blocks: head }, tail: { text: text(tail), blocks: tail }, page: tail[0].pageNumber, rest: [] };
|
|
856
|
+
}
|
|
857
|
+
const splits = CELL_SPLITS.get(cell) ?? [];
|
|
858
|
+
const k = splits.findIndex((s2) => s2.page > page && s2.at < cell.text.length);
|
|
859
|
+
if (k < 0) return null;
|
|
860
|
+
const s = splits[k];
|
|
861
|
+
const rest = cell.text.slice(s.at), lead = rest.length - rest.trimStart().length;
|
|
862
|
+
return {
|
|
863
|
+
head: { text: cell.text.slice(0, s.at).trimEnd() },
|
|
864
|
+
tail: { text: rest.trim() },
|
|
865
|
+
page: s.page,
|
|
866
|
+
rest: splits.slice(k + 1).map((x) => ({ at: x.at - s.at - lead, page: x.page })).filter((x) => x.at > 0)
|
|
867
|
+
};
|
|
868
|
+
}
|
|
869
|
+
function splitCrossPageRows(t, pageNumber) {
|
|
870
|
+
const pages = tableRowPages(t, pageNumber);
|
|
871
|
+
const rows = rowStarts(t);
|
|
872
|
+
for (let r = 0; r < t.rows; r++) {
|
|
873
|
+
const splits = rows[r].map((s) => ({ ...s, split: splitCell(s.cell, pages[r]) })).filter((s) => s.split);
|
|
874
|
+
if (!splits.length) continue;
|
|
875
|
+
const clone = (cell, patch) => {
|
|
876
|
+
const out = { ...cell, ...patch };
|
|
877
|
+
const p = CELL_PAGES.get(cell);
|
|
878
|
+
if (p !== void 0) CELL_PAGES.set(out, p);
|
|
879
|
+
if (!("text" in patch) && CELL_SPLITS.has(cell)) CELL_SPLITS.set(out, CELL_SPLITS.get(cell));
|
|
880
|
+
return out;
|
|
881
|
+
};
|
|
882
|
+
const e = Math.max(...splits.map((s) => r + s.cell.rowSpan - 1));
|
|
883
|
+
const cells = t.cells.map((row2) => row2.slice());
|
|
884
|
+
const row = Array.from({ length: t.cols }, () => ({ text: "", colSpan: 1, rowSpan: 1 }));
|
|
885
|
+
for (const { cell, c, split } of splits) {
|
|
886
|
+
cells[r][c] = clone(cell, split.head);
|
|
887
|
+
const tail = { ...cell, ...split.tail, rowSpan: 1 };
|
|
888
|
+
CELL_PAGES.set(tail, split.page);
|
|
889
|
+
setSplits(tail, split.rest);
|
|
890
|
+
row[c] = tail;
|
|
891
|
+
}
|
|
892
|
+
rows.forEach((starts, rr) => {
|
|
893
|
+
for (const { cell, c } of starts) {
|
|
894
|
+
if (splits.some((s) => s.cell === cell) || rr > e || rr + cell.rowSpan - 1 <= e) continue;
|
|
895
|
+
cells[rr][c] = clone(cells[rr][c], { rowSpan: cell.rowSpan + 1 });
|
|
896
|
+
}
|
|
897
|
+
});
|
|
898
|
+
cells.splice(e + 1, 0, row);
|
|
899
|
+
return splitCrossPageRows({ ...t, rows: t.rows + 1, cells }, pageNumber);
|
|
900
|
+
}
|
|
901
|
+
return t;
|
|
902
|
+
}
|
|
903
|
+
function splitPageTables(blocks) {
|
|
904
|
+
return blocks.flatMap((b) => {
|
|
905
|
+
if (b.type !== "table" || !b.table) return [b];
|
|
906
|
+
const t = splitCrossPageRows(b.table, b.pageNumber);
|
|
907
|
+
const pages = tableRowPages(t, b.pageNumber);
|
|
908
|
+
const cuts = [0];
|
|
909
|
+
for (let r = 1; r < t.rows; r++) if (pages[r] !== pages[r - 1]) cuts.push(r);
|
|
910
|
+
if (cuts.length === 1) return t === b.table ? [b] : [{ ...b, table: t }];
|
|
911
|
+
return cuts.map((from, k) => {
|
|
912
|
+
const end = cuts[k + 1] ?? t.rows;
|
|
913
|
+
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));
|
|
914
|
+
const table = { ...t, rows: end - from, cells, ...k ? { caption: void 0, captionBlocks: void 0 } : {} };
|
|
915
|
+
return { ...b, table, pageNumber: pages[from] };
|
|
916
|
+
});
|
|
917
|
+
});
|
|
918
|
+
}
|
|
919
|
+
|
|
757
920
|
// src/pdf/table-parts.ts
|
|
758
921
|
var flowText = (text) => text.replace(/<\/?u>|~~/g, "");
|
|
759
922
|
var PART_COL_TOL = 1;
|
|
@@ -1173,6 +1336,7 @@ function leftColumnOf(b, t) {
|
|
|
1173
1336
|
}
|
|
1174
1337
|
function placeJoined(blocks, i, j, table) {
|
|
1175
1338
|
const prev = blocks[i];
|
|
1339
|
+
markJoinedPages(table, prev, blocks[j]);
|
|
1176
1340
|
blocks[i] = { ...prev, table };
|
|
1177
1341
|
blocks.splice(j, 1);
|
|
1178
1342
|
let k = j - 1;
|
|
@@ -1526,6 +1690,7 @@ function mergeContinuedCells(blocks, pageHeights) {
|
|
|
1526
1690
|
if (!cell || !add) continue;
|
|
1527
1691
|
const at = cell.blocks || add.blocks ? cellBlocks(cell, prev.pageNumber).length : -1;
|
|
1528
1692
|
if (cell.blocks || add.blocks) cell.blocks = [...cellBlocks(cell, prev.pageNumber), ...cellBlocks(add, part.pageNumber)];
|
|
1693
|
+
else if (part.pageNumber) markContinuedText(cell, add, part.pageNumber);
|
|
1529
1694
|
cell.text = [cell.text, add.text].filter((s) => s.trim()).join("\n");
|
|
1530
1695
|
joinCellEdges(cell, add);
|
|
1531
1696
|
const lines = CELL_LINES.get(add);
|
|
@@ -2874,7 +3039,7 @@ function mergeLinkRuns(markdown) {
|
|
|
2874
3039
|
|
|
2875
3040
|
// src/pdf/formula-ocr.ts
|
|
2876
3041
|
async function applyFormulaOcr(buffer, blocks, pageFilter, effectivePageCount, warnings, _onProgress) {
|
|
2877
|
-
const formulaMod = await import("./formula-
|
|
3042
|
+
const formulaMod = await import("./formula-G4YA7SNQ.js");
|
|
2878
3043
|
const { FormulaPipeline, ensureFormulaModels } = formulaMod;
|
|
2879
3044
|
await ensureFormulaModels((p) => {
|
|
2880
3045
|
if (p.phase === "download" && p.total) {
|
|
@@ -3295,7 +3460,7 @@ async function parsePdfDocument(buffer, options) {
|
|
|
3295
3460
|
}
|
|
3296
3461
|
if (targets.size > 0) {
|
|
3297
3462
|
try {
|
|
3298
|
-
const { runPdfOcr } = await import("./pdf-ocr-
|
|
3463
|
+
const { runPdfOcr } = await import("./pdf-ocr-YSRBRIPR.js");
|
|
3299
3464
|
const mode = typeof options?.ocr === "function" ? options.ocr : "builtin";
|
|
3300
3465
|
const regionPages = new Map([...ocrRegions].filter(([p]) => options?.ocr !== "force" && !isImageBased && !pageQuality.find((q) => q.page === p)?.needsOcr));
|
|
3301
3466
|
const ocrPageBlocks = await runPdfOcr(ocrBuffer, targets, mode, warnings, options?.onProgress, options?.tables !== false, vectorPageOps, regionPages);
|
|
@@ -3448,11 +3613,12 @@ async function parsePdfDocument(buffer, options) {
|
|
|
3448
3613
|
blocks.length = 0;
|
|
3449
3614
|
for (const b of kept) blocks.push(b);
|
|
3450
3615
|
}
|
|
3451
|
-
const finishMarkdown = (bs) => mergeLinkRuns(cleanPdfText(blocksToMarkdown(bs), { keepLoneNumbers: true }));
|
|
3616
|
+
const finishMarkdown = (bs) => mergeLinkRuns(cleanPdfText(blocksToMarkdown(bs, { tableFormat: options?.tableFormat }), { keepLoneNumbers: true }));
|
|
3617
|
+
if (options?.tableFormat === "gfm") assignTableIds(blocks);
|
|
3452
3618
|
let markdown = finishMarkdown(outBlocks);
|
|
3453
3619
|
return {
|
|
3454
3620
|
markdown,
|
|
3455
|
-
pages: blocksToPages(splitPageBreakWraps(outBlocks), finishMarkdown),
|
|
3621
|
+
pages: blocksToPages(splitPageTables(splitPageBreakWraps(outBlocks)), finishMarkdown),
|
|
3456
3622
|
blocks,
|
|
3457
3623
|
metadata,
|
|
3458
3624
|
outline: outline.length > 0 ? outline : void 0,
|
|
@@ -3532,4 +3698,4 @@ export {
|
|
|
3532
3698
|
parsePdfDocument,
|
|
3533
3699
|
removeHeaderFooterBlocks
|
|
3534
3700
|
};
|
|
3535
|
-
//# sourceMappingURL=parser-
|
|
3701
|
+
//# sourceMappingURL=parser-YX4LGKIK.js.map
|