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
@@ -4,7 +4,7 @@ import {
4
4
  HEADING_RATIO_H2,
5
5
  HEADING_RATIO_H3,
6
6
  blocksToMarkdown
7
- } from "./chunk-PNQDQ3SM.js";
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-6JSZBSOD.js";
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 = groupConnectedLines(allLines);
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) {
@@ -3587,4 +3676,4 @@ export {
3587
3676
  parsePdfDocument,
3588
3677
  removeHeaderFooterBlocks
3589
3678
  };
3590
- //# sourceMappingURL=parser-AODAQQLQ.js.map
3679
+ //# sourceMappingURL=parser-46JGSTPR.js.map