kordoc 3.13.0 → 3.16.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 (54) hide show
  1. package/README.md +34 -1
  2. package/dist/{-MRPDPE2X.js → -H7N62NZU.js} +24 -13
  3. package/dist/{chunk-33CIKNL4.js → chunk-5RHRQ7HK.js} +479 -258
  4. package/dist/chunk-5RHRQ7HK.js.map +1 -0
  5. package/dist/{chunk-MEXUFQVC.cjs → chunk-BIP4JAVG.cjs} +5 -5
  6. package/dist/chunk-BIP4JAVG.cjs.map +1 -0
  7. package/dist/chunk-DCZVOIEO.cjs.map +1 -1
  8. package/dist/chunk-FGL7BH4P.js +1019 -0
  9. package/dist/chunk-FGL7BH4P.js.map +1 -0
  10. package/dist/chunk-GS7T56RP.cjs.map +1 -1
  11. package/dist/{chunk-Q6UXVJXI.js → chunk-IC56KHBL.js} +2 -2
  12. package/dist/chunk-JFNWJFKP.js +185 -0
  13. package/dist/chunk-JFNWJFKP.js.map +1 -0
  14. package/dist/{chunk-YXOT7P5B.js → chunk-LYL4IL3E.js} +5 -5
  15. package/dist/{chunk-YXOT7P5B.js.map → chunk-LYL4IL3E.js.map} +1 -1
  16. package/dist/{chunk-O4WFPOFN.js → chunk-Q7EGGW3H.js} +5 -5
  17. package/dist/{chunk-O4WFPOFN.js.map → chunk-Q7EGGW3H.js.map} +1 -1
  18. package/dist/{chunk-TWACKS3K.js → chunk-WD5NUUU6.js} +571 -729
  19. package/dist/chunk-WD5NUUU6.js.map +1 -0
  20. package/dist/cli.js +125 -12
  21. package/dist/cli.js.map +1 -1
  22. package/dist/formula-5NKVS2LR.cjs.map +1 -1
  23. package/dist/index.cjs +1668 -449
  24. package/dist/index.cjs.map +1 -1
  25. package/dist/index.d.cts +144 -6
  26. package/dist/index.d.ts +144 -6
  27. package/dist/index.js +1502 -283
  28. package/dist/index.js.map +1 -1
  29. package/dist/mcp.js +93 -12
  30. package/dist/mcp.js.map +1 -1
  31. package/dist/page-range-P7SDW6LR.cjs.map +1 -1
  32. package/dist/{parser-Z3IL2ESY.js → parser-5G247XYD.js} +54 -6
  33. package/dist/parser-5G247XYD.js.map +1 -0
  34. package/dist/{parser-DZBI3EA2.cjs → parser-6V7F3GET.cjs} +66 -18
  35. package/dist/parser-6V7F3GET.cjs.map +1 -0
  36. package/dist/{parser-XUNGOH76.js → parser-HBHCD7TE.js} +55 -7
  37. package/dist/parser-HBHCD7TE.js.map +1 -0
  38. package/dist/provider-G4C2V2PD.cjs.map +1 -1
  39. package/dist/render-VA4NHROW.js +10 -0
  40. package/dist/seal-UVDRGHEF.js +10 -0
  41. package/dist/seal-UVDRGHEF.js.map +1 -0
  42. package/dist/{watch-G5NFIT5L.js → watch-HIYNOSFD.js} +7 -5
  43. package/dist/{watch-G5NFIT5L.js.map → watch-HIYNOSFD.js.map} +1 -1
  44. package/package.json +4 -3
  45. package/dist/chunk-33CIKNL4.js.map +0 -1
  46. package/dist/chunk-MEXUFQVC.cjs.map +0 -1
  47. package/dist/chunk-TWACKS3K.js.map +0 -1
  48. package/dist/parser-DZBI3EA2.cjs.map +0 -1
  49. package/dist/parser-XUNGOH76.js.map +0 -1
  50. package/dist/parser-Z3IL2ESY.js.map +0 -1
  51. package/dist/render-VZ4OGHZU.js +0 -9
  52. /package/dist/{-MRPDPE2X.js.map → -H7N62NZU.js.map} +0 -0
  53. /package/dist/{chunk-Q6UXVJXI.js.map → chunk-IC56KHBL.js.map} +0 -0
  54. /package/dist/{render-VZ4OGHZU.js.map → render-VA4NHROW.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-YXOT7P5B.js";
7
+ } from "./chunk-LYL4IL3E.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-Q6UXVJXI.js";
15
+ } from "./chunk-IC56KHBL.js";
16
16
 
17
17
  // src/pdf/line-extract.ts
18
18
  import { OPS } from "pdfjs-dist/legacy/build/pdf.mjs";
@@ -219,15 +219,45 @@ function dropShadingStacks(lines, dir) {
219
219
  else groups.set(key, [l]);
220
220
  }
221
221
  const dropped = /* @__PURE__ */ new Set();
222
+ const coord = (l) => dir === "h" ? l.y1 : l.x1;
222
223
  for (const group of groups.values()) {
223
224
  if (group.length < STACK_MIN_LINES) continue;
224
- group.sort((a, b) => dir === "h" ? a.y1 - b.y1 : a.x1 - b.x1);
225
+ group.sort((a, b) => coord(a) - coord(b));
225
226
  let runStart = 0;
226
227
  for (let i = 1; i <= group.length; i++) {
227
- const gap = i < group.length ? dir === "h" ? group[i].y1 - group[i - 1].y1 : group[i].x1 - group[i - 1].x1 : Infinity;
228
+ const gap = i < group.length ? coord(group[i]) - coord(group[i - 1]) : Infinity;
228
229
  if (gap < STACK_GAP) continue;
229
230
  if (i - runStart >= STACK_MIN_LINES) {
230
- for (let j = runStart; j < i; j++) dropped.add(group[j]);
231
+ let s = runStart;
232
+ let e = i - 1;
233
+ const wKey = (l) => Math.round(l.lineWidth * 100);
234
+ const wCount = /* @__PURE__ */ new Map();
235
+ for (let j = s; j <= e; j++) wCount.set(wKey(group[j]), (wCount.get(wKey(group[j])) ?? 0) + 1);
236
+ let domW = 0;
237
+ let domN = 0;
238
+ for (const [w, n] of wCount) if (n > domN) {
239
+ domW = w;
240
+ domN = n;
241
+ }
242
+ const pitches = [];
243
+ for (let j = s + 1; j <= e; j++) pitches.push(coord(group[j]) - coord(group[j - 1]));
244
+ pitches.sort((a, b) => a - b);
245
+ const medPitch = pitches[Math.floor(pitches.length / 2)] ?? 0;
246
+ const edgeAlien = (j, inwardGap) => wKey(group[j]) !== domW || medPitch > 0 && inwardGap > medPitch * 1.8;
247
+ while (e - s + 1 >= STACK_MIN_LINES) {
248
+ if (edgeAlien(s, coord(group[s + 1]) - coord(group[s]))) {
249
+ s++;
250
+ continue;
251
+ }
252
+ if (edgeAlien(e, coord(group[e]) - coord(group[e - 1]))) {
253
+ e--;
254
+ continue;
255
+ }
256
+ break;
257
+ }
258
+ if (e - s + 1 >= STACK_MIN_LINES) {
259
+ for (let j = s; j <= e; j++) dropped.add(group[j]);
260
+ }
231
261
  }
232
262
  runStart = i;
233
263
  }
@@ -240,6 +270,7 @@ var EDGE_MIN_SPAN = 12;
240
270
  var EDGE_INSET = 15;
241
271
  var EDGE_NEAR = 10;
242
272
  var EDGE_CONNECT_TOL = 5;
273
+ var EDGE_YGAP_SPLIT_K = 2.5;
243
274
  var CHAIN_Y_TOL = 1.5;
244
275
  var CHAIN_GAP = 3;
245
276
  function chainCollinearRules(horizontals) {
@@ -284,8 +315,25 @@ function closeOpenTableEdges(horizontals, verticals) {
284
315
  }
285
316
  if (!placed) groups.push([hl]);
286
317
  }
287
- const synthesized = [];
318
+ const splitGroups = [];
288
319
  for (const g2 of groups) {
320
+ const sorted = [...g2].sort((a, b) => a.y1 - b.y1);
321
+ const gaps = [];
322
+ for (let i = 1; i < sorted.length; i++) gaps.push(sorted[i].y1 - sorted[i - 1].y1);
323
+ const median = gaps.length ? [...gaps].sort((a, b) => a - b)[gaps.length >> 1] : 0;
324
+ const threshold = median * EDGE_YGAP_SPLIT_K;
325
+ let cur = sorted.length ? [sorted[0]] : [];
326
+ for (let i = 1; i < sorted.length; i++) {
327
+ if (median > 0 && sorted[i].y1 - sorted[i - 1].y1 > threshold && cur.length >= EDGE_MIN_RULES && sorted.length - i >= EDGE_MIN_RULES) {
328
+ splitGroups.push(cur);
329
+ cur = [];
330
+ }
331
+ cur.push(sorted[i]);
332
+ }
333
+ if (cur.length) splitGroups.push(cur);
334
+ }
335
+ const synthesized = [];
336
+ for (const g2 of splitGroups) {
289
337
  if (g2.length < EDGE_MIN_RULES) continue;
290
338
  let yMin = Infinity, yMax = -Infinity, x1 = 0, x2 = 0;
291
339
  for (const hl of g2) {
@@ -3526,4 +3574,4 @@ export {
3526
3574
  parsePdfDocument,
3527
3575
  removeHeaderFooterBlocks
3528
3576
  };
3529
- //# sourceMappingURL=parser-XUNGOH76.js.map
3577
+ //# sourceMappingURL=parser-HBHCD7TE.js.map