kordoc 3.11.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.
- package/README.md +13 -0
- package/dist/{-QMW2GDWP.js → -MRPDPE2X.js} +5 -5
- package/dist/{chunk-GETZFABK.js → chunk-33CIKNL4.js} +2 -2
- package/dist/{chunk-RCSDSN5Y.cjs → chunk-MEXUFQVC.cjs} +2 -2
- package/dist/{chunk-RCSDSN5Y.cjs.map → chunk-MEXUFQVC.cjs.map} +1 -1
- package/dist/{chunk-D4JKKSSI.js → chunk-O4WFPOFN.js} +2 -2
- package/dist/{chunk-SNSAZ7FA.js → chunk-Q6UXVJXI.js} +2 -2
- package/dist/{chunk-TUBD3EEF.js → chunk-TWACKS3K.js} +21 -5
- package/dist/{chunk-TUBD3EEF.js.map → chunk-TWACKS3K.js.map} +1 -1
- package/dist/{chunk-O27B5IRL.js → chunk-YXOT7P5B.js} +2 -2
- package/dist/cli.js +7 -7
- package/dist/index.cjs +134 -118
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +18 -2
- package/dist/index.js.map +1 -1
- package/dist/mcp.js +5 -5
- package/dist/{parser-X34HD2KQ.cjs → parser-DZBI3EA2.cjs} +101 -15
- package/dist/parser-DZBI3EA2.cjs.map +1 -0
- package/dist/{parser-3EARWV2H.js → parser-XUNGOH76.js} +90 -4
- package/dist/parser-XUNGOH76.js.map +1 -0
- package/dist/{parser-STGI5I5K.js → parser-Z3IL2ESY.js} +89 -3
- package/dist/parser-Z3IL2ESY.js.map +1 -0
- package/dist/render-VZ4OGHZU.js +9 -0
- package/dist/{watch-KVYJ46S6.js → watch-G5NFIT5L.js} +5 -5
- package/package.json +1 -1
- package/dist/parser-3EARWV2H.js.map +0 -1
- package/dist/parser-STGI5I5K.js.map +0 -1
- package/dist/parser-X34HD2KQ.cjs.map +0 -1
- package/dist/render-FPWZ6YNZ.js +0 -9
- /package/dist/{-QMW2GDWP.js.map → -MRPDPE2X.js.map} +0 -0
- /package/dist/{chunk-GETZFABK.js.map → chunk-33CIKNL4.js.map} +0 -0
- /package/dist/{chunk-D4JKKSSI.js.map → chunk-O4WFPOFN.js.map} +0 -0
- /package/dist/{chunk-SNSAZ7FA.js.map → chunk-Q6UXVJXI.js.map} +0 -0
- /package/dist/{chunk-O27B5IRL.js.map → chunk-YXOT7P5B.js.map} +0 -0
- /package/dist/{render-FPWZ6YNZ.js.map → render-VZ4OGHZU.js.map} +0 -0
- /package/dist/{watch-KVYJ46S6.js.map → watch-G5NFIT5L.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-
|
|
7
|
+
} from "./chunk-YXOT7P5B.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-
|
|
15
|
+
} from "./chunk-Q6UXVJXI.js";
|
|
16
16
|
|
|
17
17
|
// src/pdf/line-extract.ts
|
|
18
18
|
import { OPS } from "pdfjs-dist/legacy/build/pdf.mjs";
|
|
@@ -240,10 +240,40 @@ var EDGE_MIN_SPAN = 12;
|
|
|
240
240
|
var EDGE_INSET = 15;
|
|
241
241
|
var EDGE_NEAR = 10;
|
|
242
242
|
var EDGE_CONNECT_TOL = 5;
|
|
243
|
+
var CHAIN_Y_TOL = 1.5;
|
|
244
|
+
var CHAIN_GAP = 3;
|
|
245
|
+
function chainCollinearRules(horizontals) {
|
|
246
|
+
if (horizontals.length <= 1) return horizontals;
|
|
247
|
+
const sorted = [...horizontals].sort((a, b) => a.y1 - b.y1 || a.x1 - b.x1);
|
|
248
|
+
const rules = [];
|
|
249
|
+
let bandStart = 0;
|
|
250
|
+
const flushBand = (end) => {
|
|
251
|
+
const band = sorted.slice(bandStart, end).sort((a, b) => a.x1 - b.x1);
|
|
252
|
+
let cur = { ...band[0] };
|
|
253
|
+
for (let i = 1; i < band.length; i++) {
|
|
254
|
+
const seg = band[i];
|
|
255
|
+
if (seg.x1 - cur.x2 <= CHAIN_GAP) {
|
|
256
|
+
if (seg.x2 > cur.x2) cur.x2 = seg.x2;
|
|
257
|
+
if (seg.lineWidth > cur.lineWidth) cur.lineWidth = seg.lineWidth;
|
|
258
|
+
} else {
|
|
259
|
+
rules.push(cur);
|
|
260
|
+
cur = { ...seg };
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
rules.push(cur);
|
|
264
|
+
};
|
|
265
|
+
for (let i = 1; i <= sorted.length; i++) {
|
|
266
|
+
if (i === sorted.length || sorted[i].y1 - sorted[bandStart].y1 > CHAIN_Y_TOL) {
|
|
267
|
+
flushBand(i);
|
|
268
|
+
bandStart = i;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
return rules;
|
|
272
|
+
}
|
|
243
273
|
function closeOpenTableEdges(horizontals, verticals) {
|
|
244
274
|
if (horizontals.length < EDGE_MIN_RULES) return verticals;
|
|
245
275
|
const groups = [];
|
|
246
|
-
for (const hl of horizontals) {
|
|
276
|
+
for (const hl of chainCollinearRules(horizontals)) {
|
|
247
277
|
let placed = false;
|
|
248
278
|
for (const g2 of groups) {
|
|
249
279
|
if (Math.abs(g2[0].x1 - hl.x1) <= EDGE_ALIGN_TOL && Math.abs(g2[0].x2 - hl.x2) <= EDGE_ALIGN_TOL) {
|
|
@@ -2298,6 +2328,10 @@ function detectHeadings(blocks, medianFontSize) {
|
|
|
2298
2328
|
function shouldDemoteTable(table) {
|
|
2299
2329
|
const allCells = table.cells.flatMap((row) => row.map((c) => c.text.trim())).filter(Boolean);
|
|
2300
2330
|
const allText = allCells.join(" ");
|
|
2331
|
+
if (table.rows >= 2 && table.cols >= 2 && table.cells[0].every((c) => {
|
|
2332
|
+
const t = c.text.trim();
|
|
2333
|
+
return t.length > 0 && t.length <= 12 && !/[□■◆○●▶ㅇ<>]/.test(t);
|
|
2334
|
+
}) && table.cells.slice(1).some((row) => row.some((c) => c.text.trim() !== ""))) return false;
|
|
2301
2335
|
if (table.rows <= 3 && table.cols <= 3) {
|
|
2302
2336
|
const totalCells2 = table.rows * table.cols;
|
|
2303
2337
|
const emptyCells2 = totalCells2 - allCells.length;
|
|
@@ -2687,6 +2721,54 @@ function wrapStrikethroughRuns(items) {
|
|
|
2687
2721
|
arr[arr.length - 1].text = arr[arr.length - 1].text + "~~";
|
|
2688
2722
|
}
|
|
2689
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
|
+
}
|
|
2690
2772
|
function extractBlocksWithGrids(items, pageNum, grids, horizontals, verticals) {
|
|
2691
2773
|
const blocks = [];
|
|
2692
2774
|
const usedItems = /* @__PURE__ */ new Set();
|
|
@@ -2761,6 +2843,10 @@ function extractBlocksWithGrids(items, pageNum, grids, horizontals, verticals) {
|
|
|
2761
2843
|
};
|
|
2762
2844
|
const hasContent = finalGrid.some((row) => row.some((cell) => cell.text.trim() !== ""));
|
|
2763
2845
|
if (!hasContent) continue;
|
|
2846
|
+
if (isProseBoxGrid(grid, verticals, irTable)) {
|
|
2847
|
+
for (const it of tableItems) usedItems.delete(it);
|
|
2848
|
+
continue;
|
|
2849
|
+
}
|
|
2764
2850
|
const tableBbox = {
|
|
2765
2851
|
page: pageNum,
|
|
2766
2852
|
x: grid.bbox.x1,
|
|
@@ -3440,4 +3526,4 @@ export {
|
|
|
3440
3526
|
parsePdfDocument,
|
|
3441
3527
|
removeHeaderFooterBlocks
|
|
3442
3528
|
};
|
|
3443
|
-
//# sourceMappingURL=parser-
|
|
3529
|
+
//# sourceMappingURL=parser-XUNGOH76.js.map
|