kordoc 4.6.1 → 4.7.0

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 (47) hide show
  1. package/dist/{-6XJ6MCQG.js → -MK2223RL.js} +2 -2
  2. package/dist/{chunk-AC3K3FZJ.cjs → chunk-5QTHHQQE.cjs} +3 -3
  3. package/dist/{chunk-AC3K3FZJ.cjs.map → chunk-5QTHHQQE.cjs.map} +1 -1
  4. package/dist/{chunk-VO24F4BJ.js → chunk-6PIR74EA.js} +3 -3
  5. package/dist/{chunk-EACTUWYE.js → chunk-AEYNY6FG.js} +2 -2
  6. package/dist/{chunk-SHYF2BB2.cjs → chunk-C27PPXRZ.cjs} +120 -1
  7. package/dist/chunk-C27PPXRZ.cjs.map +1 -0
  8. package/dist/{chunk-B2OQOTRT.js → chunk-GIWKBPII.js} +120 -1
  9. package/dist/chunk-GIWKBPII.js.map +1 -0
  10. package/dist/{chunk-VCA4SZ2D.js → chunk-P2NWNJMR.js} +2 -2
  11. package/dist/{chunk-BGSGUONP.js → chunk-PEVPKD6Z.js} +120 -1
  12. package/dist/chunk-PEVPKD6Z.js.map +1 -0
  13. package/dist/cli.js +6 -6
  14. package/dist/{image-ocr-7VYYQH5F.js → image-ocr-3A3HZX6O.js} +3 -3
  15. package/dist/{image-ocr-Y3WDYG4I.js → image-ocr-4MHEX4MN.js} +3 -3
  16. package/dist/{image-ocr-MLUPV4FM.cjs → image-ocr-OB5PCQUU.cjs} +8 -8
  17. package/dist/{image-ocr-MLUPV4FM.cjs.map → image-ocr-OB5PCQUU.cjs.map} +1 -1
  18. package/dist/index.cjs +2 -2
  19. package/dist/index.js +2 -2
  20. package/dist/mcp.js +3 -3
  21. package/dist/{parser-FMYUF4DT.js → parser-EIVCD4NS.js} +4 -4
  22. package/dist/parser-EIVCD4NS.js.map +1 -0
  23. package/dist/{parser-ZDJ7QTLL.js → parser-EQN4YKU4.js} +4 -4
  24. package/dist/parser-EQN4YKU4.js.map +1 -0
  25. package/dist/{parser-QOFG3K3Y.cjs → parser-VACM3DFR.cjs} +17 -17
  26. package/dist/{parser-QOFG3K3Y.cjs.map → parser-VACM3DFR.cjs.map} +1 -1
  27. package/dist/{pdf-ocr-CBJAL5DC.js → pdf-ocr-N62EWEX4.js} +3 -3
  28. package/dist/{pdf-ocr-BFWPYON4.js → pdf-ocr-NPYDUIC5.js} +3 -3
  29. package/dist/pdf-ocr-OBPQ4F4D.cjs +13 -0
  30. package/dist/{pdf-ocr-MYZNSEK4.cjs.map → pdf-ocr-OBPQ4F4D.cjs.map} +1 -1
  31. package/dist/{watch-ZPKLNQTD.js → watch-MONT6CGI.js} +2 -2
  32. package/package.json +1 -1
  33. package/dist/chunk-B2OQOTRT.js.map +0 -1
  34. package/dist/chunk-BGSGUONP.js.map +0 -1
  35. package/dist/chunk-SHYF2BB2.cjs.map +0 -1
  36. package/dist/parser-FMYUF4DT.js.map +0 -1
  37. package/dist/parser-ZDJ7QTLL.js.map +0 -1
  38. package/dist/pdf-ocr-MYZNSEK4.cjs +0 -13
  39. /package/dist/{-6XJ6MCQG.js.map → -MK2223RL.js.map} +0 -0
  40. /package/dist/{chunk-VO24F4BJ.js.map → chunk-6PIR74EA.js.map} +0 -0
  41. /package/dist/{chunk-EACTUWYE.js.map → chunk-AEYNY6FG.js.map} +0 -0
  42. /package/dist/{chunk-VCA4SZ2D.js.map → chunk-P2NWNJMR.js.map} +0 -0
  43. /package/dist/{image-ocr-7VYYQH5F.js.map → image-ocr-3A3HZX6O.js.map} +0 -0
  44. /package/dist/{image-ocr-Y3WDYG4I.js.map → image-ocr-4MHEX4MN.js.map} +0 -0
  45. /package/dist/{pdf-ocr-BFWPYON4.js.map → pdf-ocr-N62EWEX4.js.map} +0 -0
  46. /package/dist/{pdf-ocr-CBJAL5DC.js.map → pdf-ocr-NPYDUIC5.js.map} +0 -0
  47. /package/dist/{watch-ZPKLNQTD.js.map → watch-MONT6CGI.js.map} +0 -0
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  extractPageBlocksWithLines
4
- } from "./chunk-BGSGUONP.js";
4
+ } from "./chunk-PEVPKD6Z.js";
5
5
  import {
6
6
  OCR_DET_MODEL,
7
7
  OCR_REC_DICT,
@@ -513,4 +513,4 @@ export {
513
513
  runPdfOcr,
514
514
  ocrItemsToBlocks
515
515
  };
516
- //# sourceMappingURL=chunk-VCA4SZ2D.js.map
516
+ //# sourceMappingURL=chunk-P2NWNJMR.js.map
@@ -3043,6 +3043,123 @@ function buildGridTable(lines, columns) {
3043
3043
  return md.join("\n");
3044
3044
  }
3045
3045
 
3046
+ // src/pdf/underline.ts
3047
+ var UNDER_MAX_THICKNESS = 2;
3048
+ var UNDER_BELOW_EM = 0.72;
3049
+ var UNDER_BELOW_MIN_PT = 3;
3050
+ var UNDER_ABOVE_PT = 1;
3051
+ var UNDER_MIN_OVERLAP_RATIO = 0.6;
3052
+ var UNDER_OWNER_PAD_EM = 0.75;
3053
+ var UNDER_OWNER_PAD_MIN_PT = 4;
3054
+ var UNDER_MIN_COVERAGE = 0.6;
3055
+ var UNDER_GRID_EPS = 2;
3056
+ var UNDER_COLUMN_GAP_EM = 2;
3057
+ var UNDER_REPEATED_SPAN_LEVELS = 3;
3058
+ var UNDER_SPAN_OVERLAP_RATIO = 0.8;
3059
+ var UNDER_BOX_PAIR_MIN_EM = 0.5;
3060
+ var UNDER_BOX_PAIR_MAX_EM = 2.2;
3061
+ var UNDER_BOX_PAIR_OVERLAP = 0.8;
3062
+ function markUnderlineItems(items, horizontals, verticals) {
3063
+ if (items.length === 0 || horizontals.length === 0) return;
3064
+ for (const line of horizontals) {
3065
+ if (line.lineWidth > UNDER_MAX_THICKNESS) continue;
3066
+ if (touchesVertical(line, verticals)) continue;
3067
+ if (isRepeatedSpanRule(line, horizontals)) continue;
3068
+ const matches = [];
3069
+ for (const item of items) {
3070
+ const h = item.h > 0 ? item.h : item.fontSize;
3071
+ if (h <= 0 || item.w <= 0 || !item.text.trim()) continue;
3072
+ const below = Math.max(h * UNDER_BELOW_EM, UNDER_BELOW_MIN_PT);
3073
+ if (line.y1 < item.y - below || line.y1 > item.y + UNDER_ABOVE_PT) continue;
3074
+ const overlap = Math.min(line.x2, item.x + item.w) - Math.max(line.x1, item.x);
3075
+ if (overlap / item.w < UNDER_MIN_OVERLAP_RATIO) continue;
3076
+ matches.push(item);
3077
+ }
3078
+ if (matches.length === 0) continue;
3079
+ let x1 = Infinity, x2 = -Infinity, maxH = 0, covered = 0;
3080
+ for (const m of matches) {
3081
+ x1 = Math.min(x1, m.x);
3082
+ x2 = Math.max(x2, m.x + m.w);
3083
+ maxH = Math.max(maxH, m.h > 0 ? m.h : m.fontSize);
3084
+ covered += m.w;
3085
+ }
3086
+ const pad = Math.max(maxH * UNDER_OWNER_PAD_EM, UNDER_OWNER_PAD_MIN_PT);
3087
+ if (line.x1 < x1 - pad || line.x2 > x2 + pad) continue;
3088
+ if (covered < (line.x2 - line.x1) * UNDER_MIN_COVERAGE) continue;
3089
+ if (hasBoxTopPair(line, maxH, horizontals)) continue;
3090
+ matches.sort((a, b) => a.x - b.x);
3091
+ let hole = false;
3092
+ for (let i = 1; i < matches.length; i++) {
3093
+ if (matches[i].x - (matches[i - 1].x + matches[i - 1].w) > maxH * UNDER_COLUMN_GAP_EM) {
3094
+ hole = true;
3095
+ break;
3096
+ }
3097
+ }
3098
+ if (hole) continue;
3099
+ for (const m of matches) m.underline = true;
3100
+ }
3101
+ }
3102
+ function touchesVertical(line, verticals) {
3103
+ for (const v of verticals) {
3104
+ if (v.x1 < line.x1 - UNDER_GRID_EPS || v.x1 > line.x2 + UNDER_GRID_EPS) continue;
3105
+ const lo = Math.min(v.y1, v.y2), hi = Math.max(v.y1, v.y2);
3106
+ if (lo <= line.y1 + UNDER_GRID_EPS && hi >= line.y1 - UNDER_GRID_EPS) return true;
3107
+ }
3108
+ return false;
3109
+ }
3110
+ function hasBoxTopPair(line, maxH, horizontals) {
3111
+ const w = line.x2 - line.x1;
3112
+ if (w <= 0) return false;
3113
+ for (const o of horizontals) {
3114
+ if (o === line) continue;
3115
+ const dy = o.y1 - line.y1;
3116
+ if (dy < maxH * UNDER_BOX_PAIR_MIN_EM || dy > maxH * UNDER_BOX_PAIR_MAX_EM) continue;
3117
+ const ow = o.x2 - o.x1;
3118
+ if (ow <= 0) continue;
3119
+ const overlap = Math.min(line.x2, o.x2) - Math.max(line.x1, o.x1);
3120
+ if (overlap / Math.max(w, ow) >= UNDER_BOX_PAIR_OVERLAP) return true;
3121
+ }
3122
+ return false;
3123
+ }
3124
+ function isRepeatedSpanRule(line, horizontals) {
3125
+ const w = line.x2 - line.x1;
3126
+ if (w <= 0) return false;
3127
+ const ys = [];
3128
+ for (const o of horizontals) {
3129
+ const ow = o.x2 - o.x1;
3130
+ if (ow <= 0) continue;
3131
+ const overlap = Math.min(line.x2, o.x2) - Math.max(line.x1, o.x1);
3132
+ if (overlap / Math.max(w, ow) < UNDER_SPAN_OVERLAP_RATIO) continue;
3133
+ if (!ys.some((y) => Math.abs(y - o.y1) < 2)) ys.push(o.y1);
3134
+ }
3135
+ return ys.length >= UNDER_REPEATED_SPAN_LEVELS;
3136
+ }
3137
+ function wrapUnderlineRuns(items) {
3138
+ const marked = items.filter((i) => i.underline);
3139
+ if (marked.length === 0) return;
3140
+ const lines = /* @__PURE__ */ new Map();
3141
+ for (const item of marked) {
3142
+ const key = Math.round(item.y / 3);
3143
+ const arr = lines.get(key) || [];
3144
+ arr.push(item);
3145
+ lines.set(key, arr);
3146
+ }
3147
+ for (const arr of lines.values()) {
3148
+ arr.sort((a, b) => a.x - b.x);
3149
+ let runStart = 0;
3150
+ for (let i = 1; i <= arr.length; i++) {
3151
+ const prev = arr[i - 1];
3152
+ const em = Math.max(prev.h > 0 ? prev.h : prev.fontSize, 1);
3153
+ const gap = i < arr.length ? arr[i].x - (prev.x + prev.w) : Infinity;
3154
+ if (gap > em) {
3155
+ arr[runStart].text = "<u>" + arr[runStart].text;
3156
+ prev.text = prev.text + "</u>";
3157
+ runStart = i;
3158
+ }
3159
+ }
3160
+ }
3161
+ }
3162
+
3046
3163
  // src/pdf/page-blocks.ts
3047
3164
  function extractPageBlocksWithLines(items, pageNum, opList, pageWidth, pageHeight, extraLines, detectTables = true) {
3048
3165
  if (items.length === 0) return [];
@@ -3058,6 +3175,8 @@ function extractPageBlocksWithLines(items, pageNum, opList, pageWidth, pageHeigh
3058
3175
  verticals = bridgeSplitColumnVerticals(horizontals, verticals);
3059
3176
  markStrikethroughItems(items, horizontals);
3060
3177
  wrapStrikethroughRuns(items);
3178
+ markUnderlineItems(items, horizontals, verticals);
3179
+ wrapUnderlineRuns(items);
3061
3180
  const grids = detectTables ? buildTableGrids(horizontals, verticals) : [];
3062
3181
  if (grids.length > 0) {
3063
3182
  return extractBlocksWithGrids(items, pageNum, grids, horizontals, verticals);
@@ -3568,4 +3687,4 @@ export {
3568
3687
  extractPageBlocksWithLines,
3569
3688
  mergeCrossPageTables
3570
3689
  };
3571
- //# sourceMappingURL=chunk-BGSGUONP.js.map
3690
+ //# sourceMappingURL=chunk-PEVPKD6Z.js.map