kordoc 4.0.3 → 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.
Files changed (59) hide show
  1. package/README.md +8 -0
  2. package/dist/{-QSF64HNK.js → -Q4ZCVQFI.js} +9 -7
  3. package/dist/chunk-2RIOXYGA.js +92 -0
  4. package/dist/chunk-2RIOXYGA.js.map +1 -0
  5. package/dist/chunk-5RPYBC2Q.js +88 -0
  6. package/dist/chunk-5RPYBC2Q.js.map +1 -0
  7. package/dist/{chunk-AUJICYJG.js → chunk-DKMKJMR6.js} +4 -3
  8. package/dist/chunk-DKMKJMR6.js.map +1 -0
  9. package/dist/{chunk-6JSZBSOD.js → chunk-KA5AN73R.js} +2 -2
  10. package/dist/{chunk-TQYX5E32.js → chunk-KSVLQ5BC.js} +33 -4
  11. package/dist/chunk-KSVLQ5BC.js.map +1 -0
  12. package/dist/{chunk-K2SETHJ6.js → chunk-MLNHZN32.js} +1589 -765
  13. package/dist/chunk-MLNHZN32.js.map +1 -0
  14. package/dist/{chunk-OVESZY5R.cjs → chunk-NIW7CZYX.cjs} +37 -8
  15. package/dist/chunk-NIW7CZYX.cjs.map +1 -0
  16. package/dist/{chunk-MQLKSRIK.js → chunk-S3KGEEBQ.js} +76 -25
  17. package/dist/chunk-S3KGEEBQ.js.map +1 -0
  18. package/dist/{chunk-RO2GVZ3I.js → chunk-TXNRIVWA.js} +3 -3
  19. package/dist/{chunk-PNQDQ3SM.js → chunk-ZJXR4PWY.js} +33 -4
  20. package/dist/chunk-ZJXR4PWY.js.map +1 -0
  21. package/dist/cli.js +119 -72
  22. package/dist/cli.js.map +1 -1
  23. package/dist/index.cjs +21122 -20246
  24. package/dist/index.cjs.map +1 -1
  25. package/dist/index.d.cts +47 -1
  26. package/dist/index.d.ts +47 -1
  27. package/dist/index.js +20944 -20068
  28. package/dist/index.js.map +1 -1
  29. package/dist/mcp.js +106 -83
  30. package/dist/mcp.js.map +1 -1
  31. package/dist/{parser-FMONFTAN.cjs → parser-2ZUTCU2G.cjs} +106 -17
  32. package/dist/parser-2ZUTCU2G.cjs.map +1 -0
  33. package/dist/{parser-AODAQQLQ.js → parser-46JGSTPR.js} +95 -6
  34. package/dist/parser-46JGSTPR.js.map +1 -0
  35. package/dist/{parser-J7YREDNS.js → parser-TLCC67W6.js} +94 -5
  36. package/dist/parser-TLCC67W6.js.map +1 -0
  37. package/dist/profile-io-MRVIJ5T4.js +11 -0
  38. package/dist/render-TTOG6CHW.js +10 -0
  39. package/dist/seal-NMLZ3M3K.js +10 -0
  40. package/dist/seal-NMLZ3M3K.js.map +1 -0
  41. package/dist/{watch-P65Z24AL.js → watch-NZNVJ4YD.js} +7 -7
  42. package/package.json +1 -1
  43. package/dist/chunk-AUJICYJG.js.map +0 -1
  44. package/dist/chunk-K2SETHJ6.js.map +0 -1
  45. package/dist/chunk-MQLKSRIK.js.map +0 -1
  46. package/dist/chunk-OVESZY5R.cjs.map +0 -1
  47. package/dist/chunk-PNQDQ3SM.js.map +0 -1
  48. package/dist/chunk-TQYX5E32.js.map +0 -1
  49. package/dist/parser-AODAQQLQ.js.map +0 -1
  50. package/dist/parser-FMONFTAN.cjs.map +0 -1
  51. package/dist/parser-J7YREDNS.js.map +0 -1
  52. package/dist/render-JPP7YTV3.js +0 -10
  53. package/dist/seal-MDE4DXZQ.js +0 -10
  54. /package/dist/{-QSF64HNK.js.map → -Q4ZCVQFI.js.map} +0 -0
  55. /package/dist/{chunk-6JSZBSOD.js.map → chunk-KA5AN73R.js.map} +0 -0
  56. /package/dist/{chunk-RO2GVZ3I.js.map → chunk-TXNRIVWA.js.map} +0 -0
  57. /package/dist/{render-JPP7YTV3.js.map → profile-io-MRVIJ5T4.js.map} +0 -0
  58. /package/dist/{seal-MDE4DXZQ.js.map → render-TTOG6CHW.js.map} +0 -0
  59. /package/dist/{watch-P65Z24AL.js.map → watch-NZNVJ4YD.js.map} +0 -0
@@ -6,7 +6,7 @@ import {
6
6
  blocksToMarkdown,
7
7
  safeMax,
8
8
  safeMin
9
- } from "./chunk-TQYX5E32.js";
9
+ } from "./chunk-KSVLQ5BC.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 = groupConnectedLines(allLines);
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-J7YREDNS.js.map
3676
+ //# sourceMappingURL=parser-TLCC67W6.js.map