kordoc 4.0.2 → 4.0.4
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 +800 -768
- package/dist/{-XMKVL3NX.js → -Q4ZCVQFI.js} +10 -8
- package/dist/chunk-2RIOXYGA.js +92 -0
- package/dist/chunk-2RIOXYGA.js.map +1 -0
- package/dist/chunk-5RPYBC2Q.js +88 -0
- package/dist/chunk-5RPYBC2Q.js.map +1 -0
- package/dist/chunk-DCZVOIEO.cjs.map +1 -1
- package/dist/{chunk-IKBIIEVJ.js → chunk-DKMKJMR6.js} +5 -4
- package/dist/chunk-DKMKJMR6.js.map +1 -0
- package/dist/chunk-GS7T56RP.cjs.map +1 -1
- package/dist/{chunk-STMLZDKR.js → chunk-KA5AN73R.js} +2 -2
- package/dist/chunk-KA5AN73R.js.map +1 -0
- package/dist/{chunk-3IYQYBUF.js → chunk-KSVLQ5BC.js} +33 -4
- package/dist/chunk-KSVLQ5BC.js.map +1 -0
- package/dist/{chunk-5CJGKKMZ.js → chunk-MEPHGCPQ.js} +1 -1
- package/dist/chunk-MEPHGCPQ.js.map +1 -0
- package/dist/{chunk-AHWRAGXN.js → chunk-MLNHZN32.js} +1876 -965
- package/dist/chunk-MLNHZN32.js.map +1 -0
- package/dist/chunk-MOL7MDBG.js +0 -0
- package/dist/{chunk-WN7LZHII.cjs → chunk-NIW7CZYX.cjs} +37 -8
- package/dist/chunk-NIW7CZYX.cjs.map +1 -0
- package/dist/{chunk-6SD4X5PT.js → chunk-S3KGEEBQ.js} +76 -25
- package/dist/chunk-S3KGEEBQ.js.map +1 -0
- package/dist/{chunk-67RANGFQ.js → chunk-TXNRIVWA.js} +3 -3
- package/dist/chunk-TXNRIVWA.js.map +1 -0
- package/dist/{chunk-6YIYFWO2.js → chunk-ZJXR4PWY.js} +33 -4
- package/dist/chunk-ZJXR4PWY.js.map +1 -0
- package/dist/cli.js +120 -73
- package/dist/cli.js.map +1 -1
- package/dist/{detect-PJZMUL2Z.js → detect-RI2MQ33K.js} +2 -2
- package/dist/formula-5NKVS2LR.cjs.map +1 -1
- package/dist/formula-JCNF43NE.js +0 -0
- package/dist/index.cjs +21139 -20176
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +52 -5
- package/dist/index.d.ts +52 -5
- package/dist/index.js +20969 -20006
- package/dist/index.js.map +1 -1
- package/dist/mcp.js +113 -90
- package/dist/mcp.js.map +1 -1
- package/dist/page-range-737B4EZW.js +0 -0
- package/dist/page-range-P7SDW6LR.cjs.map +1 -1
- package/dist/{parser-6AYYGX6J.cjs → parser-2ZUTCU2G.cjs} +108 -19
- package/dist/parser-2ZUTCU2G.cjs.map +1 -0
- package/dist/{parser-3HM2VYKK.js → parser-46JGSTPR.js} +97 -8
- package/dist/parser-46JGSTPR.js.map +1 -0
- package/dist/{parser-2Q2YKEJG.js → parser-TLCC67W6.js} +96 -7
- package/dist/parser-TLCC67W6.js.map +1 -0
- package/dist/profile-io-MRVIJ5T4.js +11 -0
- package/dist/{provider-H4WWSPOV.js → provider-4ZJKV3DC.js} +1 -1
- package/dist/provider-4ZJKV3DC.js.map +1 -0
- package/dist/{provider-7H4CPZYS.js → provider-AKROB7WQ.js} +1 -1
- package/dist/provider-AKROB7WQ.js.map +1 -0
- package/dist/{provider-5K7O3Z2O.cjs → provider-G4C2V2PD.cjs} +1 -1
- package/dist/provider-G4C2V2PD.cjs.map +1 -0
- package/dist/render-TTOG6CHW.js +10 -0
- package/dist/seal-NMLZ3M3K.js +10 -0
- package/dist/seal-NMLZ3M3K.js.map +1 -0
- package/dist/setup-57FB3LSP.js +0 -0
- package/dist/{watch-6OHF727O.js → watch-NZNVJ4YD.js} +8 -8
- package/dist/watch-NZNVJ4YD.js.map +1 -0
- package/package.json +4 -4
- package/dist/chunk-3IYQYBUF.js.map +0 -1
- package/dist/chunk-5CJGKKMZ.js.map +0 -1
- package/dist/chunk-67RANGFQ.js.map +0 -1
- package/dist/chunk-6SD4X5PT.js.map +0 -1
- package/dist/chunk-6YIYFWO2.js.map +0 -1
- package/dist/chunk-AHWRAGXN.js.map +0 -1
- package/dist/chunk-IKBIIEVJ.js.map +0 -1
- package/dist/chunk-STMLZDKR.js.map +0 -1
- package/dist/chunk-WN7LZHII.cjs.map +0 -1
- package/dist/parser-2Q2YKEJG.js.map +0 -1
- package/dist/parser-3HM2VYKK.js.map +0 -1
- package/dist/parser-6AYYGX6J.cjs.map +0 -1
- package/dist/provider-5K7O3Z2O.cjs.map +0 -1
- package/dist/provider-7H4CPZYS.js.map +0 -1
- package/dist/provider-H4WWSPOV.js.map +0 -1
- package/dist/render-W4VCJE6N.js +0 -10
- package/dist/seal-DRPTNHOP.js +0 -10
- package/dist/watch-6OHF727O.js.map +0 -1
- /package/dist/{-XMKVL3NX.js.map → -Q4ZCVQFI.js.map} +0 -0
- /package/dist/{detect-PJZMUL2Z.js.map → detect-RI2MQ33K.js.map} +0 -0
- /package/dist/{render-W4VCJE6N.js.map → profile-io-MRVIJ5T4.js.map} +0 -0
- /package/dist/{seal-DRPTNHOP.js.map → render-TTOG6CHW.js.map} +0 -0
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
HEADING_RATIO_H2,
|
|
5
5
|
HEADING_RATIO_H3,
|
|
6
6
|
blocksToMarkdown
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-ZJXR4PWY.js";
|
|
8
8
|
import {
|
|
9
9
|
parsePageRange
|
|
10
10
|
} from "./chunk-MOL7MDBG.js";
|
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
KordocError,
|
|
13
13
|
safeMax,
|
|
14
14
|
safeMin
|
|
15
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-KA5AN73R.js";
|
|
16
16
|
|
|
17
17
|
// src/pdf/line-extract.ts
|
|
18
18
|
import { OPS } from "pdfjs-dist/legacy/build/pdf.mjs";
|
|
@@ -490,6 +490,14 @@ var CONNECT_TOL = 5;
|
|
|
490
490
|
var MIN_COL_WIDTH = 15;
|
|
491
491
|
var MIN_ROW_HEIGHT = 6;
|
|
492
492
|
var MIN_COORD_MERGE_TOL = 8;
|
|
493
|
+
var CUT_FULLWIDTH_RATIO = 0.9;
|
|
494
|
+
var CUT_CROSS_EPS = 2;
|
|
495
|
+
var CUT_MIN_SIDE_VERTICALS = 2;
|
|
496
|
+
var CUT_EDGE_MARGIN = 12;
|
|
497
|
+
var CUT_INTERIOR_MATCH_TOL = 8;
|
|
498
|
+
var CUT_MAX_INTERIOR_OVERLAP = 0.5;
|
|
499
|
+
var CUT_VCHAIN_X_TOL = 1.5;
|
|
500
|
+
var CUT_VCHAIN_GAP = 1;
|
|
493
501
|
function buildVertices(horizontals, verticals) {
|
|
494
502
|
const vertices = [];
|
|
495
503
|
const tol = CONNECT_TOL;
|
|
@@ -537,9 +545,13 @@ function buildTableGrids(horizontals, verticals) {
|
|
|
537
545
|
...horizontals.map((l, i) => ({ ...l, type: "h", id: i })),
|
|
538
546
|
...verticals.map((l, i) => ({ ...l, type: "v", id: i + horizontals.length }))
|
|
539
547
|
];
|
|
540
|
-
const groups =
|
|
548
|
+
const groups = [];
|
|
549
|
+
for (const g2 of groupConnectedLines(allLines)) {
|
|
550
|
+
const bands = splitStackedGroup(g2);
|
|
551
|
+
for (const b of bands) groups.push({ lines: b, fromSplit: bands.length > 1 });
|
|
552
|
+
}
|
|
541
553
|
const grids = [];
|
|
542
|
-
for (const group of groups) {
|
|
554
|
+
for (const { lines: group, fromSplit } of groups) {
|
|
543
555
|
const hLines = group.filter((l) => l.type === "h");
|
|
544
556
|
const vLines = group.filter((l) => l.type === "v");
|
|
545
557
|
if (hLines.length < 2 || vLines.length < 2) continue;
|
|
@@ -558,7 +570,7 @@ function buildTableGrids(horizontals, verticals) {
|
|
|
558
570
|
x2: gx2 + CONNECT_TOL,
|
|
559
571
|
y2: gy2 + CONNECT_TOL
|
|
560
572
|
};
|
|
561
|
-
const groupVertices = vertices.filter(
|
|
573
|
+
const groupVertices = fromSplit ? mergeVertices(buildVertices(hLines, vLines)) : vertices.filter(
|
|
562
574
|
(v) => v.x >= groupBbox.x1 && v.x <= groupBbox.x2 && v.y >= groupBbox.y1 && v.y <= groupBbox.y2
|
|
563
575
|
);
|
|
564
576
|
const groupRadius = groupVertices.length > 0 ? groupVertices.reduce((max, v) => Math.max(max, v.radius), 1) : globalRadius;
|
|
@@ -658,6 +670,83 @@ function clusterCoordinates(values, tolerance) {
|
|
|
658
670
|
}
|
|
659
671
|
return clusters.map((c) => c.sum / c.count);
|
|
660
672
|
}
|
|
673
|
+
function chainVerticals(vs) {
|
|
674
|
+
if (vs.length <= 1) return vs.map((v) => ({ y1: v.y1, y2: v.y2 }));
|
|
675
|
+
const sorted = [...vs].sort((a, b) => a.x1 - b.x1 || a.y1 - b.y1);
|
|
676
|
+
const rules = [];
|
|
677
|
+
let bandStart = 0;
|
|
678
|
+
const flushBand = (end) => {
|
|
679
|
+
const band = sorted.slice(bandStart, end).sort((a, b) => a.y1 - b.y1);
|
|
680
|
+
let cur = { y1: band[0].y1, y2: band[0].y2 };
|
|
681
|
+
for (let i = 1; i < band.length; i++) {
|
|
682
|
+
const seg = band[i];
|
|
683
|
+
if (seg.y1 - cur.y2 <= CUT_VCHAIN_GAP) {
|
|
684
|
+
if (seg.y2 > cur.y2) cur.y2 = seg.y2;
|
|
685
|
+
} else {
|
|
686
|
+
rules.push(cur);
|
|
687
|
+
cur = { y1: seg.y1, y2: seg.y2 };
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
rules.push(cur);
|
|
691
|
+
};
|
|
692
|
+
for (let i = 1; i <= sorted.length; i++) {
|
|
693
|
+
if (i === sorted.length || sorted[i].x1 - sorted[bandStart].x1 > CUT_VCHAIN_X_TOL) {
|
|
694
|
+
flushBand(i);
|
|
695
|
+
bandStart = i;
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
return rules;
|
|
699
|
+
}
|
|
700
|
+
function splitStackedGroup(group) {
|
|
701
|
+
const hs = group.filter((l) => l.type === "h");
|
|
702
|
+
const vs = group.filter((l) => l.type === "v");
|
|
703
|
+
if (hs.length < 3 || vs.length < 4) return [group];
|
|
704
|
+
let gx1 = Infinity, gx2 = -Infinity;
|
|
705
|
+
for (const l of group) {
|
|
706
|
+
if (l.x1 < gx1) gx1 = l.x1;
|
|
707
|
+
if (l.x2 > gx2) gx2 = l.x2;
|
|
708
|
+
}
|
|
709
|
+
const groupW = gx2 - gx1;
|
|
710
|
+
if (groupW <= 0) return [group];
|
|
711
|
+
const isInterior = (v) => v.x1 > gx1 + CUT_EDGE_MARGIN && v.x1 < gx2 - CUT_EDGE_MARGIN;
|
|
712
|
+
const chained = chainVerticals(vs);
|
|
713
|
+
const cuts = [];
|
|
714
|
+
for (const h of hs) {
|
|
715
|
+
const y = h.y1;
|
|
716
|
+
if (h.x2 - h.x1 < groupW * CUT_FULLWIDTH_RATIO) continue;
|
|
717
|
+
if (cuts.some((c) => Math.abs(c - y) <= CUT_CROSS_EPS)) continue;
|
|
718
|
+
if (chained.some((v) => v.y1 < y - CUT_CROSS_EPS && v.y2 > y + CUT_CROSS_EPS)) continue;
|
|
719
|
+
const above = vs.filter((v) => v.y1 >= y - CUT_CROSS_EPS);
|
|
720
|
+
const below = vs.filter((v) => v.y2 <= y + CUT_CROSS_EPS);
|
|
721
|
+
if (above.length < CUT_MIN_SIDE_VERTICALS || below.length < CUT_MIN_SIDE_VERTICALS) continue;
|
|
722
|
+
const ia = above.filter(isInterior);
|
|
723
|
+
const ib = below.filter(isInterior);
|
|
724
|
+
if (ia.length === 0 || ib.length === 0) continue;
|
|
725
|
+
let matched = 0;
|
|
726
|
+
for (const a of ia) if (ib.some((b) => Math.abs(a.x1 - b.x1) <= CUT_INTERIOR_MATCH_TOL)) matched++;
|
|
727
|
+
if (matched / Math.min(ia.length, ib.length) > CUT_MAX_INTERIOR_OVERLAP) continue;
|
|
728
|
+
cuts.push(y);
|
|
729
|
+
}
|
|
730
|
+
if (cuts.length === 0) return [group];
|
|
731
|
+
cuts.sort((a, b) => b - a);
|
|
732
|
+
const bandOf = (y) => {
|
|
733
|
+
let k = 0;
|
|
734
|
+
while (k < cuts.length && y < cuts[k]) k++;
|
|
735
|
+
return k;
|
|
736
|
+
};
|
|
737
|
+
const bands = Array.from({ length: cuts.length + 1 }, () => []);
|
|
738
|
+
for (const v of vs) bands[bandOf((v.y1 + v.y2) / 2)].push(v);
|
|
739
|
+
for (const h of hs) {
|
|
740
|
+
const atCut = cuts.findIndex((c) => Math.abs(h.y1 - c) <= CUT_CROSS_EPS);
|
|
741
|
+
if (atCut >= 0) {
|
|
742
|
+
bands[atCut].push(h);
|
|
743
|
+
bands[atCut + 1].push(h);
|
|
744
|
+
} else {
|
|
745
|
+
bands[bandOf(h.y1)].push(h);
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
return bands.filter((b) => b.length > 0);
|
|
749
|
+
}
|
|
661
750
|
function groupConnectedLines(lines) {
|
|
662
751
|
const parent = lines.map((_, i) => i);
|
|
663
752
|
function find(x) {
|
|
@@ -1236,7 +1325,7 @@ function dominantStyle(items) {
|
|
|
1236
1325
|
}
|
|
1237
1326
|
if (dominantSize === 0) return void 0;
|
|
1238
1327
|
const fontName = items.find((i) => i.fontSize === dominantSize)?.fontName || void 0;
|
|
1239
|
-
return { fontSize: dominantSize, fontName };
|
|
1328
|
+
return fontName ? { fontSize: dominantSize, fontName } : { fontSize: dominantSize };
|
|
1240
1329
|
}
|
|
1241
1330
|
function normalizeItems(rawItems) {
|
|
1242
1331
|
const items = [];
|
|
@@ -3469,7 +3558,7 @@ async function parsePdfDocument(buffer, options) {
|
|
|
3469
3558
|
if (totalChars / Math.max(parsedPageCount, 1) < 10) {
|
|
3470
3559
|
if (options?.ocr) {
|
|
3471
3560
|
try {
|
|
3472
|
-
const { ocrPages } = await import("./provider-
|
|
3561
|
+
const { ocrPages } = await import("./provider-AKROB7WQ.js");
|
|
3473
3562
|
const ocrBlocks = await ocrPages(doc, options.ocr, pageFilter, effectivePageCount);
|
|
3474
3563
|
if (ocrBlocks.length > 0) {
|
|
3475
3564
|
const ocrMarkdown = ocrBlocks.map((b) => b.text || "").filter(Boolean).join("\n\n");
|
|
@@ -3587,4 +3676,4 @@ export {
|
|
|
3587
3676
|
parsePdfDocument,
|
|
3588
3677
|
removeHeaderFooterBlocks
|
|
3589
3678
|
};
|
|
3590
|
-
//# sourceMappingURL=parser-
|
|
3679
|
+
//# sourceMappingURL=parser-46JGSTPR.js.map
|