kordoc 3.12.0 → 3.13.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 (34) hide show
  1. package/README.md +7 -0
  2. package/dist/{-OPZIF3QT.js → -MRPDPE2X.js} +5 -5
  3. package/dist/{chunk-ILR7GF3W.js → chunk-33CIKNL4.js} +2 -2
  4. package/dist/{chunk-2C5GCXPJ.cjs → chunk-MEXUFQVC.cjs} +2 -2
  5. package/dist/{chunk-2C5GCXPJ.cjs.map → chunk-MEXUFQVC.cjs.map} +1 -1
  6. package/dist/{chunk-NGKIAZ6G.js → chunk-O4WFPOFN.js} +2 -2
  7. package/dist/{chunk-7Z43WEML.js → chunk-Q6UXVJXI.js} +2 -2
  8. package/dist/{chunk-RUYSNNYZ.js → chunk-TWACKS3K.js} +21 -5
  9. package/dist/{chunk-RUYSNNYZ.js.map → chunk-TWACKS3K.js.map} +1 -1
  10. package/dist/{chunk-BUDM6ULT.js → chunk-YXOT7P5B.js} +2 -2
  11. package/dist/cli.js +7 -7
  12. package/dist/index.cjs +134 -118
  13. package/dist/index.cjs.map +1 -1
  14. package/dist/index.js +18 -2
  15. package/dist/index.js.map +1 -1
  16. package/dist/mcp.js +5 -5
  17. package/dist/{parser-PCTX7LGN.cjs → parser-DZBI3EA2.cjs} +66 -14
  18. package/dist/parser-DZBI3EA2.cjs.map +1 -0
  19. package/dist/{parser-5FSEFR3R.js → parser-XUNGOH76.js} +55 -3
  20. package/dist/{parser-AWEGMHHV.js.map → parser-XUNGOH76.js.map} +1 -1
  21. package/dist/{parser-AWEGMHHV.js → parser-Z3IL2ESY.js} +54 -2
  22. package/dist/{parser-5FSEFR3R.js.map → parser-Z3IL2ESY.js.map} +1 -1
  23. package/dist/render-VZ4OGHZU.js +9 -0
  24. package/dist/{watch-Y7BAYXJE.js → watch-G5NFIT5L.js} +5 -5
  25. package/package.json +1 -1
  26. package/dist/parser-PCTX7LGN.cjs.map +0 -1
  27. package/dist/render-ATQNKOT2.js +0 -9
  28. /package/dist/{-OPZIF3QT.js.map → -MRPDPE2X.js.map} +0 -0
  29. /package/dist/{chunk-ILR7GF3W.js.map → chunk-33CIKNL4.js.map} +0 -0
  30. /package/dist/{chunk-NGKIAZ6G.js.map → chunk-O4WFPOFN.js.map} +0 -0
  31. /package/dist/{chunk-7Z43WEML.js.map → chunk-Q6UXVJXI.js.map} +0 -0
  32. /package/dist/{chunk-BUDM6ULT.js.map → chunk-YXOT7P5B.js.map} +0 -0
  33. /package/dist/{render-ATQNKOT2.js.map → render-VZ4OGHZU.js.map} +0 -0
  34. /package/dist/{watch-Y7BAYXJE.js.map → watch-G5NFIT5L.js.map} +0 -0
package/dist/mcp.js CHANGED
@@ -10,22 +10,22 @@ import {
10
10
  parse,
11
11
  patchHwp,
12
12
  patchHwpx
13
- } from "./chunk-RUYSNNYZ.js";
13
+ } from "./chunk-TWACKS3K.js";
14
14
  import {
15
15
  detectFormat,
16
16
  detectZipFormat
17
17
  } from "./chunk-MEPHGCPQ.js";
18
- import "./chunk-ILR7GF3W.js";
18
+ import "./chunk-33CIKNL4.js";
19
19
  import {
20
20
  blocksToMarkdown
21
- } from "./chunk-BUDM6ULT.js";
21
+ } from "./chunk-YXOT7P5B.js";
22
22
  import "./chunk-MOL7MDBG.js";
23
23
  import {
24
24
  KordocError,
25
25
  VERSION,
26
26
  sanitizeError,
27
27
  toArrayBuffer
28
- } from "./chunk-7Z43WEML.js";
28
+ } from "./chunk-Q6UXVJXI.js";
29
29
 
30
30
  // src/mcp.ts
31
31
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
@@ -196,7 +196,7 @@ server.tool(
196
196
  break;
197
197
  case "pdf":
198
198
  try {
199
- const { extractPdfMetadataOnly } = await import("./parser-5FSEFR3R.js");
199
+ const { extractPdfMetadataOnly } = await import("./parser-XUNGOH76.js");
200
200
  metadata = await extractPdfMetadataOnly(buffer);
201
201
  } catch {
202
202
  metadata = void 0;
@@ -6,7 +6,7 @@
6
6
 
7
7
 
8
8
 
9
- var _chunk2C5GCXPJcjs = require('./chunk-2C5GCXPJ.cjs');
9
+ var _chunkMEXUFQVCcjs = require('./chunk-MEXUFQVC.cjs');
10
10
 
11
11
 
12
12
  var _chunkDCZVOIEOcjs = require('./chunk-DCZVOIEO.cjs');
@@ -2086,14 +2086,14 @@ function isProseSpread(items) {
2086
2086
  for (let i = 1; i < sorted.length; i++) {
2087
2087
  gaps.push(sorted[i].x - (sorted[i - 1].x + sorted[i - 1].w));
2088
2088
  }
2089
- const maxGap = _chunk2C5GCXPJcjs.safeMax.call(void 0, gaps);
2089
+ const maxGap = _chunkMEXUFQVCcjs.safeMax.call(void 0, gaps);
2090
2090
  const avgLen = items.reduce((s, i) => s + i.text.length, 0) / items.length;
2091
2091
  return maxGap < 40 && avgLen < 5;
2092
2092
  }
2093
2093
  function detectColumns(yLines) {
2094
2094
  const allItems = yLines.flat();
2095
2095
  if (allItems.length === 0) return null;
2096
- const pageWidth = _chunk2C5GCXPJcjs.safeMax.call(void 0, allItems.map((i) => i.x + i.w)) - _chunk2C5GCXPJcjs.safeMin.call(void 0, allItems.map((i) => i.x));
2096
+ const pageWidth = _chunkMEXUFQVCcjs.safeMax.call(void 0, allItems.map((i) => i.x + i.w)) - _chunkMEXUFQVCcjs.safeMin.call(void 0, allItems.map((i) => i.x));
2097
2097
  if (pageWidth < 100) return null;
2098
2098
  let bigoLineIdx = -1;
2099
2099
  for (let i = 0; i < yLines.length; i++) {
@@ -2315,9 +2315,9 @@ function detectHeadings(blocks, medianFontSize) {
2315
2315
  if (/^\d+$/.test(text)) continue;
2316
2316
  const ratio = block.style.fontSize / medianFontSize;
2317
2317
  let level = 0;
2318
- if (ratio >= _chunk2C5GCXPJcjs.HEADING_RATIO_H1) level = 1;
2319
- else if (ratio >= _chunk2C5GCXPJcjs.HEADING_RATIO_H2) level = 2;
2320
- else if (ratio >= _chunk2C5GCXPJcjs.HEADING_RATIO_H3) level = 3;
2318
+ if (ratio >= _chunkMEXUFQVCcjs.HEADING_RATIO_H1) level = 1;
2319
+ else if (ratio >= _chunkMEXUFQVCcjs.HEADING_RATIO_H2) level = 2;
2320
+ else if (ratio >= _chunkMEXUFQVCcjs.HEADING_RATIO_H3) level = 3;
2321
2321
  if (level > 0) {
2322
2322
  block.type = "heading";
2323
2323
  block.level = level;
@@ -2721,6 +2721,54 @@ function wrapStrikethroughRuns(items) {
2721
2721
  arr[arr.length - 1].text = arr[arr.length - 1].text + "~~";
2722
2722
  }
2723
2723
  }
2724
+ var PROSEBOX_FULLWIDTH_MIN = 0.6;
2725
+ var PROSEBOX_LONG_CELL_CHARS = 80;
2726
+ var PROSEBOX_LONG_CELL_MIN = 3;
2727
+ var PROSEBOX_LONG_CELL_RATIO = 0.4;
2728
+ var PROSEBOX_X_TOL = 8;
2729
+ function verticalCoverageAt(verticals, x, yMin, yMax) {
2730
+ const tol = PROSEBOX_X_TOL;
2731
+ const spans = [];
2732
+ for (const v of verticals) {
2733
+ if (Math.abs(v.x1 - x) > tol) continue;
2734
+ const lo = Math.max(v.y1, yMin), hi = Math.min(v.y2, yMax);
2735
+ if (hi > lo) spans.push([lo, hi]);
2736
+ }
2737
+ if (spans.length === 0) return 0;
2738
+ spans.sort((a, b) => a[0] - b[0]);
2739
+ let total = 0, s = spans[0][0], e = spans[0][1];
2740
+ for (let i = 1; i < spans.length; i++) {
2741
+ if (spans[i][0] <= e) {
2742
+ if (spans[i][1] > e) e = spans[i][1];
2743
+ } else {
2744
+ total += e - s;
2745
+ s = spans[i][0];
2746
+ e = spans[i][1];
2747
+ }
2748
+ }
2749
+ return total + (e - s);
2750
+ }
2751
+ function isProseBoxGrid(grid, verticals, table) {
2752
+ const numCols = grid.colXs.length - 1;
2753
+ if (numCols < 2 || grid.rowYs.length < 3) return false;
2754
+ const gyMax = grid.rowYs[0], gyMin = grid.rowYs[grid.rowYs.length - 1];
2755
+ const span = gyMax - gyMin;
2756
+ if (span <= 0) return false;
2757
+ const interior = grid.colXs.slice(1, -1);
2758
+ let fullWidthHeight = 0;
2759
+ for (let r = 0; r < grid.rowYs.length - 1; r++) {
2760
+ const top = grid.rowYs[r], bot = grid.rowYs[r + 1];
2761
+ const h = top - bot;
2762
+ if (h <= 0) continue;
2763
+ const hasDivider = interior.some((cx) => verticalCoverageAt(verticals, cx, bot, top) >= h * 0.5);
2764
+ if (!hasDivider) fullWidthHeight += h;
2765
+ }
2766
+ if (fullWidthHeight < span * PROSEBOX_FULLWIDTH_MIN) return false;
2767
+ const texts = table.cells.flat().map((c) => c.text.trim()).filter(Boolean);
2768
+ const longCells = texts.filter((s) => s.length > PROSEBOX_LONG_CELL_CHARS).length;
2769
+ if (longCells < PROSEBOX_LONG_CELL_MIN || longCells < texts.length * PROSEBOX_LONG_CELL_RATIO) return false;
2770
+ return true;
2771
+ }
2724
2772
  function extractBlocksWithGrids(items, pageNum, grids, horizontals, verticals) {
2725
2773
  const blocks = [];
2726
2774
  const usedItems = /* @__PURE__ */ new Set();
@@ -2795,6 +2843,10 @@ function extractBlocksWithGrids(items, pageNum, grids, horizontals, verticals) {
2795
2843
  };
2796
2844
  const hasContent = finalGrid.some((row) => row.some((cell) => cell.text.trim() !== ""));
2797
2845
  if (!hasContent) continue;
2846
+ if (isProseBoxGrid(grid, verticals, irTable)) {
2847
+ for (const it of tableItems) usedItems.delete(it);
2848
+ continue;
2849
+ }
2798
2850
  const tableBbox = {
2799
2851
  page: pageNum,
2800
2852
  x: grid.bbox.x1,
@@ -2841,7 +2893,7 @@ function extractBlocksWithGrids(items, pageNum, grids, horizontals, verticals) {
2841
2893
  }
2842
2894
  if (remaining.length > 0) {
2843
2895
  const allY = remaining.map((i) => i.y);
2844
- const pageH = _chunk2C5GCXPJcjs.safeMax.call(void 0, allY) - _chunk2C5GCXPJcjs.safeMin.call(void 0, allY);
2896
+ const pageH = _chunkMEXUFQVCcjs.safeMax.call(void 0, allY) - _chunkMEXUFQVCcjs.safeMin.call(void 0, allY);
2845
2897
  const groups = xyCutOrder(remaining, Math.max(15, pageH * 0.03));
2846
2898
  const textBlocks = [];
2847
2899
  for (const group of groups) {
@@ -3017,7 +3069,7 @@ function extractPageBlocksFallback(items, pageNum, fullPage = false) {
3017
3069
  blocks.push({ type: "paragraph", text: tableText, pageNumber: pageNum, bbox, style: dominantStyle(items) });
3018
3070
  } else {
3019
3071
  const allY = items.map((i) => i.y);
3020
- const pageHeight = _chunk2C5GCXPJcjs.safeMax.call(void 0, allY) - _chunk2C5GCXPJcjs.safeMin.call(void 0, allY);
3072
+ const pageHeight = _chunkMEXUFQVCcjs.safeMax.call(void 0, allY) - _chunkMEXUFQVCcjs.safeMin.call(void 0, allY);
3021
3073
  const gapThreshold = Math.max(15, pageHeight * 0.03);
3022
3074
  const orderedGroups = proseCutX !== null ? splitTwoColumnProse(items, proseCutX) : xyCutOrder(items, gapThreshold);
3023
3075
  for (const group of orderedGroups) {
@@ -3270,7 +3322,7 @@ async function loadPdfWithTimeout(buffer) {
3270
3322
  new Promise((_, reject) => {
3271
3323
  timer = setTimeout(() => {
3272
3324
  loadingTask.destroy();
3273
- reject(new (0, _chunk2C5GCXPJcjs.KordocError)("PDF \uB85C\uB529 \uD0C0\uC784\uC544\uC6C3 (30\uCD08 \uCD08\uACFC)"));
3325
+ reject(new (0, _chunkMEXUFQVCcjs.KordocError)("PDF \uB85C\uB529 \uD0C0\uC784\uC544\uC6C3 (30\uCD08 \uCD08\uACFC)"));
3274
3326
  }, PDF_LOAD_TIMEOUT_MS);
3275
3327
  })
3276
3328
  ]);
@@ -3283,7 +3335,7 @@ async function parsePdfDocument(buffer, options) {
3283
3335
  const doc = await loadPdfWithTimeout(buffer);
3284
3336
  try {
3285
3337
  const pageCount = doc.numPages;
3286
- if (pageCount === 0) throw new (0, _chunk2C5GCXPJcjs.KordocError)("PDF\uC5D0 \uD398\uC774\uC9C0\uAC00 \uC5C6\uC2B5\uB2C8\uB2E4.");
3338
+ if (pageCount === 0) throw new (0, _chunkMEXUFQVCcjs.KordocError)("PDF\uC5D0 \uD398\uC774\uC9C0\uAC00 \uC5C6\uC2B5\uB2C8\uB2E4.");
3287
3339
  const metadata = { pageCount };
3288
3340
  await extractPdfMetadata(doc, metadata);
3289
3341
  const blocks = [];
@@ -3343,11 +3395,11 @@ async function parsePdfDocument(buffer, options) {
3343
3395
  pageText += pageText ? "\n" + t : t;
3344
3396
  }
3345
3397
  pageQuality.push(computePageQuality(i, pageText));
3346
- if (totalTextBytes > MAX_TOTAL_TEXT) throw new (0, _chunk2C5GCXPJcjs.KordocError)("\uD14D\uC2A4\uD2B8 \uCD94\uCD9C \uD06C\uAE30 \uCD08\uACFC");
3398
+ if (totalTextBytes > MAX_TOTAL_TEXT) throw new (0, _chunkMEXUFQVCcjs.KordocError)("\uD14D\uC2A4\uD2B8 \uCD94\uCD9C \uD06C\uAE30 \uCD08\uACFC");
3347
3399
  parsedPages++;
3348
3400
  _optionalChain([options, 'optionalAccess', _36 => _36.onProgress, 'optionalCall', _37 => _37(parsedPages, totalTarget)]);
3349
3401
  } catch (pageErr) {
3350
- if (pageErr instanceof _chunk2C5GCXPJcjs.KordocError) throw pageErr;
3402
+ if (pageErr instanceof _chunkMEXUFQVCcjs.KordocError) throw pageErr;
3351
3403
  warnings.push({ page: i, message: `\uD398\uC774\uC9C0 ${i} \uD30C\uC2F1 \uC2E4\uD328: ${pageErr instanceof Error ? pageErr.message : "\uC54C \uC218 \uC5C6\uB294 \uC624\uB958"}`, code: "PARTIAL_PARSE" });
3352
3404
  }
3353
3405
  }
@@ -3415,7 +3467,7 @@ async function parsePdfDocument(buffer, options) {
3415
3467
  detectKoreanListBlocks(blocks);
3416
3468
  const outline = blocks.filter((b) => b.type === "heading" && b.level && b.text).map((b) => ({ level: b.level, text: b.text, pageNumber: b.pageNumber }));
3417
3469
  sanitizeBlockControlChars(blocks);
3418
- let markdown = cleanPdfText(_chunk2C5GCXPJcjs.blocksToMarkdown.call(void 0, blocks));
3470
+ let markdown = cleanPdfText(_chunkMEXUFQVCcjs.blocksToMarkdown.call(void 0, blocks));
3419
3471
  return {
3420
3472
  markdown,
3421
3473
  blocks,
@@ -3474,4 +3526,4 @@ async function extractPdfMetadataOnly(buffer) {
3474
3526
 
3475
3527
 
3476
3528
  exports.cleanPdfText = cleanPdfText; exports.detectKoreanListBlocks = detectKoreanListBlocks; exports.detectTableCaptions = detectTableCaptions; exports.extractPdfMetadataOnly = extractPdfMetadataOnly; exports.mergeCrossPageTables = mergeCrossPageTables; exports.parsePdfDocument = parsePdfDocument; exports.removeHeaderFooterBlocks = removeHeaderFooterBlocks;
3477
- //# sourceMappingURL=parser-PCTX7LGN.cjs.map
3529
+ //# sourceMappingURL=parser-DZBI3EA2.cjs.map