kordoc 4.0.3 → 4.0.5
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 +8 -0
- package/dist/{-QSF64HNK.js → -QVHGOOCR.js} +9 -7
- package/dist/chunk-5RPYBC2Q.js +88 -0
- package/dist/chunk-5RPYBC2Q.js.map +1 -0
- package/dist/{chunk-6JSZBSOD.js → chunk-6BABRVOJ.js} +2 -2
- package/dist/{chunk-PNQDQ3SM.js → chunk-6PED5OOG.js} +34 -4
- package/dist/chunk-6PED5OOG.js.map +1 -0
- package/dist/{chunk-OVESZY5R.cjs → chunk-6R5FY47W.cjs} +38 -8
- package/dist/chunk-6R5FY47W.cjs.map +1 -0
- package/dist/{chunk-RO2GVZ3I.js → chunk-6WDPB4SN.js} +3 -3
- package/dist/{chunk-TQYX5E32.js → chunk-FKK4K53F.js} +34 -4
- package/dist/chunk-FKK4K53F.js.map +1 -0
- package/dist/{chunk-MQLKSRIK.js → chunk-OMERK4AW.js} +76 -25
- package/dist/chunk-OMERK4AW.js.map +1 -0
- package/dist/{chunk-AUJICYJG.js → chunk-QK2G34WE.js} +4 -3
- package/dist/chunk-QK2G34WE.js.map +1 -0
- package/dist/{chunk-K2SETHJ6.js → chunk-Z6Q3YG22.js} +1632 -765
- package/dist/chunk-Z6Q3YG22.js.map +1 -0
- package/dist/chunk-ZGMMLYAL.js +92 -0
- package/dist/chunk-ZGMMLYAL.js.map +1 -0
- package/dist/cli.js +119 -72
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +21162 -20243
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +53 -1
- package/dist/index.d.ts +53 -1
- package/dist/index.js +20987 -20068
- package/dist/index.js.map +1 -1
- package/dist/mcp.js +106 -83
- package/dist/mcp.js.map +1 -1
- package/dist/{parser-FMONFTAN.cjs → parser-2V5SPTU7.cjs} +106 -17
- package/dist/parser-2V5SPTU7.cjs.map +1 -0
- package/dist/{parser-AODAQQLQ.js → parser-3MAYZUJX.js} +95 -6
- package/dist/parser-3MAYZUJX.js.map +1 -0
- package/dist/{parser-J7YREDNS.js → parser-YSHZC5FQ.js} +94 -5
- package/dist/parser-YSHZC5FQ.js.map +1 -0
- package/dist/profile-io-3EECPDHG.js +11 -0
- package/dist/render-MJSQ4TG2.js +10 -0
- package/dist/seal-R3POFNOU.js +10 -0
- package/dist/seal-R3POFNOU.js.map +1 -0
- package/dist/{watch-P65Z24AL.js → watch-7MHSCKEQ.js} +7 -7
- package/package.json +1 -1
- package/dist/chunk-AUJICYJG.js.map +0 -1
- package/dist/chunk-K2SETHJ6.js.map +0 -1
- package/dist/chunk-MQLKSRIK.js.map +0 -1
- package/dist/chunk-OVESZY5R.cjs.map +0 -1
- package/dist/chunk-PNQDQ3SM.js.map +0 -1
- package/dist/chunk-TQYX5E32.js.map +0 -1
- package/dist/parser-AODAQQLQ.js.map +0 -1
- package/dist/parser-FMONFTAN.cjs.map +0 -1
- package/dist/parser-J7YREDNS.js.map +0 -1
- package/dist/render-JPP7YTV3.js +0 -10
- package/dist/seal-MDE4DXZQ.js +0 -10
- /package/dist/{-QSF64HNK.js.map → -QVHGOOCR.js.map} +0 -0
- /package/dist/{chunk-6JSZBSOD.js.map → chunk-6BABRVOJ.js.map} +0 -0
- /package/dist/{chunk-RO2GVZ3I.js.map → chunk-6WDPB4SN.js.map} +0 -0
- /package/dist/{render-JPP7YTV3.js.map → profile-io-3EECPDHG.js.map} +0 -0
- /package/dist/{seal-MDE4DXZQ.js.map → render-MJSQ4TG2.js.map} +0 -0
- /package/dist/{watch-P65Z24AL.js.map → watch-7MHSCKEQ.js.map} +0 -0
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
blocksToMarkdown,
|
|
7
7
|
safeMax,
|
|
8
8
|
safeMin
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-FKK4K53F.js";
|
|
10
10
|
import {
|
|
11
11
|
parsePageRange
|
|
12
12
|
} from "./chunk-GE43BE46.js";
|
|
@@ -487,6 +487,14 @@ var CONNECT_TOL = 5;
|
|
|
487
487
|
var MIN_COL_WIDTH = 15;
|
|
488
488
|
var MIN_ROW_HEIGHT = 6;
|
|
489
489
|
var MIN_COORD_MERGE_TOL = 8;
|
|
490
|
+
var CUT_FULLWIDTH_RATIO = 0.9;
|
|
491
|
+
var CUT_CROSS_EPS = 2;
|
|
492
|
+
var CUT_MIN_SIDE_VERTICALS = 2;
|
|
493
|
+
var CUT_EDGE_MARGIN = 12;
|
|
494
|
+
var CUT_INTERIOR_MATCH_TOL = 8;
|
|
495
|
+
var CUT_MAX_INTERIOR_OVERLAP = 0.5;
|
|
496
|
+
var CUT_VCHAIN_X_TOL = 1.5;
|
|
497
|
+
var CUT_VCHAIN_GAP = 1;
|
|
490
498
|
function buildVertices(horizontals, verticals) {
|
|
491
499
|
const vertices = [];
|
|
492
500
|
const tol = CONNECT_TOL;
|
|
@@ -534,9 +542,13 @@ function buildTableGrids(horizontals, verticals) {
|
|
|
534
542
|
...horizontals.map((l, i) => ({ ...l, type: "h", id: i })),
|
|
535
543
|
...verticals.map((l, i) => ({ ...l, type: "v", id: i + horizontals.length }))
|
|
536
544
|
];
|
|
537
|
-
const groups =
|
|
545
|
+
const groups = [];
|
|
546
|
+
for (const g2 of groupConnectedLines(allLines)) {
|
|
547
|
+
const bands = splitStackedGroup(g2);
|
|
548
|
+
for (const b of bands) groups.push({ lines: b, fromSplit: bands.length > 1 });
|
|
549
|
+
}
|
|
538
550
|
const grids = [];
|
|
539
|
-
for (const group of groups) {
|
|
551
|
+
for (const { lines: group, fromSplit } of groups) {
|
|
540
552
|
const hLines = group.filter((l) => l.type === "h");
|
|
541
553
|
const vLines = group.filter((l) => l.type === "v");
|
|
542
554
|
if (hLines.length < 2 || vLines.length < 2) continue;
|
|
@@ -555,7 +567,7 @@ function buildTableGrids(horizontals, verticals) {
|
|
|
555
567
|
x2: gx2 + CONNECT_TOL,
|
|
556
568
|
y2: gy2 + CONNECT_TOL
|
|
557
569
|
};
|
|
558
|
-
const groupVertices = vertices.filter(
|
|
570
|
+
const groupVertices = fromSplit ? mergeVertices(buildVertices(hLines, vLines)) : vertices.filter(
|
|
559
571
|
(v) => v.x >= groupBbox.x1 && v.x <= groupBbox.x2 && v.y >= groupBbox.y1 && v.y <= groupBbox.y2
|
|
560
572
|
);
|
|
561
573
|
const groupRadius = groupVertices.length > 0 ? groupVertices.reduce((max, v) => Math.max(max, v.radius), 1) : globalRadius;
|
|
@@ -655,6 +667,83 @@ function clusterCoordinates(values, tolerance) {
|
|
|
655
667
|
}
|
|
656
668
|
return clusters.map((c) => c.sum / c.count);
|
|
657
669
|
}
|
|
670
|
+
function chainVerticals(vs) {
|
|
671
|
+
if (vs.length <= 1) return vs.map((v) => ({ y1: v.y1, y2: v.y2 }));
|
|
672
|
+
const sorted = [...vs].sort((a, b) => a.x1 - b.x1 || a.y1 - b.y1);
|
|
673
|
+
const rules = [];
|
|
674
|
+
let bandStart = 0;
|
|
675
|
+
const flushBand = (end) => {
|
|
676
|
+
const band = sorted.slice(bandStart, end).sort((a, b) => a.y1 - b.y1);
|
|
677
|
+
let cur = { y1: band[0].y1, y2: band[0].y2 };
|
|
678
|
+
for (let i = 1; i < band.length; i++) {
|
|
679
|
+
const seg = band[i];
|
|
680
|
+
if (seg.y1 - cur.y2 <= CUT_VCHAIN_GAP) {
|
|
681
|
+
if (seg.y2 > cur.y2) cur.y2 = seg.y2;
|
|
682
|
+
} else {
|
|
683
|
+
rules.push(cur);
|
|
684
|
+
cur = { y1: seg.y1, y2: seg.y2 };
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
rules.push(cur);
|
|
688
|
+
};
|
|
689
|
+
for (let i = 1; i <= sorted.length; i++) {
|
|
690
|
+
if (i === sorted.length || sorted[i].x1 - sorted[bandStart].x1 > CUT_VCHAIN_X_TOL) {
|
|
691
|
+
flushBand(i);
|
|
692
|
+
bandStart = i;
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
return rules;
|
|
696
|
+
}
|
|
697
|
+
function splitStackedGroup(group) {
|
|
698
|
+
const hs = group.filter((l) => l.type === "h");
|
|
699
|
+
const vs = group.filter((l) => l.type === "v");
|
|
700
|
+
if (hs.length < 3 || vs.length < 4) return [group];
|
|
701
|
+
let gx1 = Infinity, gx2 = -Infinity;
|
|
702
|
+
for (const l of group) {
|
|
703
|
+
if (l.x1 < gx1) gx1 = l.x1;
|
|
704
|
+
if (l.x2 > gx2) gx2 = l.x2;
|
|
705
|
+
}
|
|
706
|
+
const groupW = gx2 - gx1;
|
|
707
|
+
if (groupW <= 0) return [group];
|
|
708
|
+
const isInterior = (v) => v.x1 > gx1 + CUT_EDGE_MARGIN && v.x1 < gx2 - CUT_EDGE_MARGIN;
|
|
709
|
+
const chained = chainVerticals(vs);
|
|
710
|
+
const cuts = [];
|
|
711
|
+
for (const h of hs) {
|
|
712
|
+
const y = h.y1;
|
|
713
|
+
if (h.x2 - h.x1 < groupW * CUT_FULLWIDTH_RATIO) continue;
|
|
714
|
+
if (cuts.some((c) => Math.abs(c - y) <= CUT_CROSS_EPS)) continue;
|
|
715
|
+
if (chained.some((v) => v.y1 < y - CUT_CROSS_EPS && v.y2 > y + CUT_CROSS_EPS)) continue;
|
|
716
|
+
const above = vs.filter((v) => v.y1 >= y - CUT_CROSS_EPS);
|
|
717
|
+
const below = vs.filter((v) => v.y2 <= y + CUT_CROSS_EPS);
|
|
718
|
+
if (above.length < CUT_MIN_SIDE_VERTICALS || below.length < CUT_MIN_SIDE_VERTICALS) continue;
|
|
719
|
+
const ia = above.filter(isInterior);
|
|
720
|
+
const ib = below.filter(isInterior);
|
|
721
|
+
if (ia.length === 0 || ib.length === 0) continue;
|
|
722
|
+
let matched = 0;
|
|
723
|
+
for (const a of ia) if (ib.some((b) => Math.abs(a.x1 - b.x1) <= CUT_INTERIOR_MATCH_TOL)) matched++;
|
|
724
|
+
if (matched / Math.min(ia.length, ib.length) > CUT_MAX_INTERIOR_OVERLAP) continue;
|
|
725
|
+
cuts.push(y);
|
|
726
|
+
}
|
|
727
|
+
if (cuts.length === 0) return [group];
|
|
728
|
+
cuts.sort((a, b) => b - a);
|
|
729
|
+
const bandOf = (y) => {
|
|
730
|
+
let k = 0;
|
|
731
|
+
while (k < cuts.length && y < cuts[k]) k++;
|
|
732
|
+
return k;
|
|
733
|
+
};
|
|
734
|
+
const bands = Array.from({ length: cuts.length + 1 }, () => []);
|
|
735
|
+
for (const v of vs) bands[bandOf((v.y1 + v.y2) / 2)].push(v);
|
|
736
|
+
for (const h of hs) {
|
|
737
|
+
const atCut = cuts.findIndex((c) => Math.abs(h.y1 - c) <= CUT_CROSS_EPS);
|
|
738
|
+
if (atCut >= 0) {
|
|
739
|
+
bands[atCut].push(h);
|
|
740
|
+
bands[atCut + 1].push(h);
|
|
741
|
+
} else {
|
|
742
|
+
bands[bandOf(h.y1)].push(h);
|
|
743
|
+
}
|
|
744
|
+
}
|
|
745
|
+
return bands.filter((b) => b.length > 0);
|
|
746
|
+
}
|
|
658
747
|
function groupConnectedLines(lines) {
|
|
659
748
|
const parent = lines.map((_, i) => i);
|
|
660
749
|
function find(x) {
|
|
@@ -3584,4 +3673,4 @@ export {
|
|
|
3584
3673
|
parsePdfDocument,
|
|
3585
3674
|
removeHeaderFooterBlocks
|
|
3586
3675
|
};
|
|
3587
|
-
//# sourceMappingURL=parser-
|
|
3676
|
+
//# sourceMappingURL=parser-YSHZC5FQ.js.map
|