kordoc 4.0.8 → 4.1.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 +25 -11
- package/dist/{-LE4RLXVA.js → -AS4IABL2.js} +23 -10
- package/dist/{chunk-2DZQF6YJ.js → chunk-37HJHCPA.js} +24 -15
- package/dist/chunk-37HJHCPA.js.map +1 -0
- package/dist/{chunk-6XAAYAWL.cjs → chunk-37VKMUST.cjs} +47 -37
- package/dist/chunk-37VKMUST.cjs.map +1 -0
- package/dist/{chunk-OQPILS7B.js → chunk-4KI23VHA.js} +33 -23
- package/dist/chunk-4KI23VHA.js.map +1 -0
- package/dist/{chunk-D35VBACN.js → chunk-AX2R5Q2N.js} +7 -4
- package/dist/chunk-AX2R5Q2N.js.map +1 -0
- package/dist/chunk-DZIXKL7E.js +145 -0
- package/dist/chunk-DZIXKL7E.js.map +1 -0
- package/dist/chunk-F2ZU3IZG.js +82 -0
- package/dist/chunk-F2ZU3IZG.js.map +1 -0
- package/dist/{chunk-BNU5QGIZ.js → chunk-GQVSHGG4.js} +12 -4
- package/dist/chunk-GQVSHGG4.js.map +1 -0
- package/dist/{chunk-7S3M4N4E.js → chunk-L2XQQTOY.js} +566 -189
- package/dist/chunk-L2XQQTOY.js.map +1 -0
- package/dist/{chunk-HMUEU7D7.js → chunk-O5VS7RIR.js} +2 -2
- package/dist/{chunk-UEIYETCQ.js → chunk-SSTK6IKK.js} +18 -160
- package/dist/chunk-SSTK6IKK.js.map +1 -0
- package/dist/chunk-UOO7LSDG.js +152 -0
- package/dist/chunk-UOO7LSDG.js.map +1 -0
- package/dist/{chunk-RROH5WHO.js → chunk-WO52HVQJ.js} +2 -2
- package/dist/{chunk-MEPHGCPQ.js → chunk-YOO6ET6M.js} +7 -3
- package/dist/chunk-YOO6ET6M.js.map +1 -0
- package/dist/chunks-WVMGF7JL.js +10 -0
- package/dist/cli.js +170 -35
- package/dist/cli.js.map +1 -1
- package/dist/{detect-RI2MQ33K.js → detect-YEZX2XCF.js} +2 -2
- package/dist/index.cjs +1142 -531
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +105 -1
- package/dist/index.d.ts +105 -1
- package/dist/index.js +802 -191
- package/dist/index.js.map +1 -1
- package/dist/mcp.js +273 -65
- package/dist/mcp.js.map +1 -1
- package/dist/{parser-ITMU2WN5.cjs → parser-N4A7UGDK.cjs} +127 -45
- package/dist/parser-N4A7UGDK.cjs.map +1 -0
- package/dist/{parser-TCTCSBYZ.js → parser-PEOYBXBO.js} +118 -34
- package/dist/parser-PEOYBXBO.js.map +1 -0
- package/dist/{parser-KMMUS73Q.js → parser-XX4QTDFQ.js} +114 -32
- package/dist/parser-XX4QTDFQ.js.map +1 -0
- package/dist/{profile-io-SLN4P76T.js → profile-io-PLDQFPJA.js} +3 -3
- package/dist/{provider-G4C2V2PD.cjs → provider-4FAYHJ6N.cjs} +3 -3
- package/dist/provider-4FAYHJ6N.cjs.map +1 -0
- package/dist/{provider-4ZJKV3DC.js → provider-C6IOGIS5.js} +3 -3
- package/dist/provider-C6IOGIS5.js.map +1 -0
- package/dist/{provider-AKROB7WQ.js → provider-UIBW2MIH.js} +3 -3
- package/dist/provider-UIBW2MIH.js.map +1 -0
- package/dist/rasterize-WWNQLKYW.js +40 -0
- package/dist/rasterize-WWNQLKYW.js.map +1 -0
- package/dist/redact-7ILEAUTS.js +12 -0
- package/dist/render-T7S6H6AN.js +10 -0
- package/dist/render-T7S6H6AN.js.map +1 -0
- package/dist/seal-7PTL6MXH.js +10 -0
- package/dist/seal-7PTL6MXH.js.map +1 -0
- package/dist/{setup-57FB3LSP.js → setup-Q2PRE7UA.js} +5 -3
- package/dist/setup-Q2PRE7UA.js.map +1 -0
- package/dist/{watch-OHQWSVPE.js → watch-SFHXZALC.js} +77 -23
- package/dist/watch-SFHXZALC.js.map +1 -0
- package/package.json +1 -1
- package/dist/chunk-2DZQF6YJ.js.map +0 -1
- package/dist/chunk-6XAAYAWL.cjs.map +0 -1
- package/dist/chunk-7S3M4N4E.js.map +0 -1
- package/dist/chunk-BNU5QGIZ.js.map +0 -1
- package/dist/chunk-D35VBACN.js.map +0 -1
- package/dist/chunk-MEPHGCPQ.js.map +0 -1
- package/dist/chunk-OQPILS7B.js.map +0 -1
- package/dist/chunk-UEIYETCQ.js.map +0 -1
- package/dist/parser-ITMU2WN5.cjs.map +0 -1
- package/dist/parser-KMMUS73Q.js.map +0 -1
- package/dist/parser-TCTCSBYZ.js.map +0 -1
- package/dist/provider-4ZJKV3DC.js.map +0 -1
- package/dist/provider-AKROB7WQ.js.map +0 -1
- package/dist/provider-G4C2V2PD.cjs.map +0 -1
- package/dist/render-25BT623I.js +0 -10
- package/dist/seal-R4TETA4C.js +0 -10
- package/dist/setup-57FB3LSP.js.map +0 -1
- package/dist/watch-OHQWSVPE.js.map +0 -1
- /package/dist/{-LE4RLXVA.js.map → -AS4IABL2.js.map} +0 -0
- /package/dist/{chunk-HMUEU7D7.js.map → chunk-O5VS7RIR.js.map} +0 -0
- /package/dist/{chunk-RROH5WHO.js.map → chunk-WO52HVQJ.js.map} +0 -0
- /package/dist/{detect-RI2MQ33K.js.map → chunks-WVMGF7JL.js.map} +0 -0
- /package/dist/{profile-io-SLN4P76T.js.map → detect-YEZX2XCF.js.map} +0 -0
- /package/dist/{render-25BT623I.js.map → profile-io-PLDQFPJA.js.map} +0 -0
- /package/dist/{seal-R4TETA4C.js.map → redact-7ILEAUTS.js.map} +0 -0
|
@@ -3,17 +3,19 @@ import {
|
|
|
3
3
|
HEADING_RATIO_H1,
|
|
4
4
|
HEADING_RATIO_H2,
|
|
5
5
|
HEADING_RATIO_H3,
|
|
6
|
-
blocksToMarkdown,
|
|
7
6
|
encodePng
|
|
8
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-UOO7LSDG.js";
|
|
9
8
|
import {
|
|
10
9
|
parsePageRange
|
|
11
10
|
} from "./chunk-MOL7MDBG.js";
|
|
11
|
+
import {
|
|
12
|
+
blocksToMarkdown
|
|
13
|
+
} from "./chunk-SSTK6IKK.js";
|
|
12
14
|
import {
|
|
13
15
|
KordocError,
|
|
14
16
|
safeMax,
|
|
15
17
|
safeMin
|
|
16
|
-
} from "./chunk-
|
|
18
|
+
} from "./chunk-O5VS7RIR.js";
|
|
17
19
|
|
|
18
20
|
// src/pdf/line-extract.ts
|
|
19
21
|
import { OPS } from "pdfjs-dist/legacy/build/pdf.mjs";
|
|
@@ -581,6 +583,18 @@ function buildVertices(horizontals, verticals) {
|
|
|
581
583
|
}
|
|
582
584
|
function mergeVertices(vertices) {
|
|
583
585
|
if (vertices.length <= 1) return vertices;
|
|
586
|
+
let maxRadiusAll = 1;
|
|
587
|
+
for (const v of vertices) {
|
|
588
|
+
if (v.radius > maxRadiusAll) maxRadiusAll = v.radius;
|
|
589
|
+
}
|
|
590
|
+
const cell = Math.max(VERTEX_MERGE_FACTOR * maxRadiusAll, 1);
|
|
591
|
+
const buckets = /* @__PURE__ */ new Map();
|
|
592
|
+
for (let i = 0; i < vertices.length; i++) {
|
|
593
|
+
const key = Math.floor(vertices[i].x / cell) + "," + Math.floor(vertices[i].y / cell);
|
|
594
|
+
const arr = buckets.get(key);
|
|
595
|
+
if (arr) arr.push(i);
|
|
596
|
+
else buckets.set(key, [i]);
|
|
597
|
+
}
|
|
584
598
|
const merged = [];
|
|
585
599
|
const used = new Array(vertices.length).fill(false);
|
|
586
600
|
for (let i = 0; i < vertices.length; i++) {
|
|
@@ -588,7 +602,20 @@ function mergeVertices(vertices) {
|
|
|
588
602
|
let sumX = vertices[i].x, sumY = vertices[i].y;
|
|
589
603
|
let maxRadius = vertices[i].radius;
|
|
590
604
|
let count = 1;
|
|
591
|
-
|
|
605
|
+
const cx = Math.floor(vertices[i].x / cell);
|
|
606
|
+
const cy = Math.floor(vertices[i].y / cell);
|
|
607
|
+
const candidates = [];
|
|
608
|
+
for (let dx = -1; dx <= 1; dx++) {
|
|
609
|
+
for (let dy = -1; dy <= 1; dy++) {
|
|
610
|
+
const arr = buckets.get(cx + dx + "," + (cy + dy));
|
|
611
|
+
if (!arr) continue;
|
|
612
|
+
for (const j of arr) {
|
|
613
|
+
if (j > i && !used[j]) candidates.push(j);
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
candidates.sort((a, b) => a - b);
|
|
618
|
+
for (const j of candidates) {
|
|
592
619
|
if (used[j]) continue;
|
|
593
620
|
const mergeTol = VERTEX_MERGE_FACTOR * Math.max(maxRadius, vertices[j].radius);
|
|
594
621
|
if (Math.abs(vertices[i].x - vertices[j].x) <= mergeTol && Math.abs(vertices[i].y - vertices[j].y) <= mergeTol) {
|
|
@@ -815,6 +842,7 @@ function splitStackedGroup(group) {
|
|
|
815
842
|
}
|
|
816
843
|
return bands.filter((b) => b.length > 0);
|
|
817
844
|
}
|
|
845
|
+
var GROUP_BUCKET_CELL = 100;
|
|
818
846
|
function groupConnectedLines(lines) {
|
|
819
847
|
const parent = lines.map((_, i) => i);
|
|
820
848
|
function find(x) {
|
|
@@ -828,10 +856,34 @@ function groupConnectedLines(lines) {
|
|
|
828
856
|
const ra = find(a), rb = find(b);
|
|
829
857
|
if (ra !== rb) parent[ra] = rb;
|
|
830
858
|
}
|
|
859
|
+
const cellMap = /* @__PURE__ */ new Map();
|
|
831
860
|
for (let i = 0; i < lines.length; i++) {
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
861
|
+
const l = lines[i];
|
|
862
|
+
const cx1 = Math.floor((Math.min(l.x1, l.x2) - CONNECT_TOL) / GROUP_BUCKET_CELL);
|
|
863
|
+
const cx2 = Math.floor((Math.max(l.x1, l.x2) + CONNECT_TOL) / GROUP_BUCKET_CELL);
|
|
864
|
+
const cy1 = Math.floor((Math.min(l.y1, l.y2) - CONNECT_TOL) / GROUP_BUCKET_CELL);
|
|
865
|
+
const cy2 = Math.floor((Math.max(l.y1, l.y2) + CONNECT_TOL) / GROUP_BUCKET_CELL);
|
|
866
|
+
for (let cx = cx1; cx <= cx2; cx++) {
|
|
867
|
+
for (let cy = cy1; cy <= cy2; cy++) {
|
|
868
|
+
const key = cx + "," + cy;
|
|
869
|
+
const arr = cellMap.get(key);
|
|
870
|
+
if (arr) arr.push(i);
|
|
871
|
+
else cellMap.set(key, [i]);
|
|
872
|
+
}
|
|
873
|
+
}
|
|
874
|
+
}
|
|
875
|
+
const tested = /* @__PURE__ */ new Set();
|
|
876
|
+
for (const arr of cellMap.values()) {
|
|
877
|
+
for (let a = 0; a < arr.length; a++) {
|
|
878
|
+
for (let b = a + 1; b < arr.length; b++) {
|
|
879
|
+
const i = Math.min(arr[a], arr[b]);
|
|
880
|
+
const j = Math.max(arr[a], arr[b]);
|
|
881
|
+
const key = i * lines.length + j;
|
|
882
|
+
if (tested.has(key)) continue;
|
|
883
|
+
tested.add(key);
|
|
884
|
+
if (linesIntersect(lines[i], lines[j])) {
|
|
885
|
+
union(i, j);
|
|
886
|
+
}
|
|
835
887
|
}
|
|
836
888
|
}
|
|
837
889
|
}
|
|
@@ -1319,12 +1371,21 @@ async function extractPageImages(page, fnArray, argsArray, pageNumber, state, wa
|
|
|
1319
1371
|
if (typeof objId !== "string" || pageSeenIds.has(objId)) continue;
|
|
1320
1372
|
pageSeenIds.add(objId);
|
|
1321
1373
|
dedupeId = objId;
|
|
1322
|
-
|
|
1323
|
-
} else if (op === OPS3.paintInlineImageXObject) {
|
|
1324
|
-
imgData = argsArray[i]?.[0];
|
|
1325
|
-
} else {
|
|
1374
|
+
} else if (op !== OPS3.paintInlineImageXObject) {
|
|
1326
1375
|
continue;
|
|
1327
1376
|
}
|
|
1377
|
+
if (state.imageIndex >= MAX_IMAGES_PER_DOC || state.totalBytes >= MAX_TOTAL_IMAGE_BYTES) {
|
|
1378
|
+
if (!state.capWarned) {
|
|
1379
|
+
state.capWarned = true;
|
|
1380
|
+
warnings.push({ page: pageNumber, message: `\uC774\uBBF8\uC9C0 \uCD94\uCD9C \uC0C1\uD55C \uB3C4\uB2EC (${MAX_IMAGES_PER_DOC}\uAC1C/128MB) \u2014 \uC774\uD6C4 \uC774\uBBF8\uC9C0 \uC0DD\uB7B5`, code: "SKIPPED_IMAGE" });
|
|
1381
|
+
}
|
|
1382
|
+
continue;
|
|
1383
|
+
}
|
|
1384
|
+
if (dedupeId) {
|
|
1385
|
+
imgData = await resolveImgData(page, dedupeId);
|
|
1386
|
+
} else {
|
|
1387
|
+
imgData = argsArray[i]?.[0];
|
|
1388
|
+
}
|
|
1328
1389
|
if (!imgData?.data || !imgData.width || !imgData.height) continue;
|
|
1329
1390
|
const { width: w, height: h } = imgData;
|
|
1330
1391
|
if (w < MIN_DIM || h < MIN_DIM) continue;
|
|
@@ -1334,13 +1395,6 @@ async function extractPageImages(page, fnArray, argsArray, pageNumber, state, wa
|
|
|
1334
1395
|
}
|
|
1335
1396
|
const hash = `${w}x${h}k${imgData.kind ?? "?"}h${fnv1a(imgData.data)}${dedupeId ? "" : "inline"}`;
|
|
1336
1397
|
if (state.seen.has(hash)) continue;
|
|
1337
|
-
if (state.imageIndex >= MAX_IMAGES_PER_DOC || state.totalBytes >= MAX_TOTAL_IMAGE_BYTES) {
|
|
1338
|
-
if (!state.capWarned) {
|
|
1339
|
-
state.capWarned = true;
|
|
1340
|
-
warnings.push({ page: pageNumber, message: `\uC774\uBBF8\uC9C0 \uCD94\uCD9C \uC0C1\uD55C \uB3C4\uB2EC (${MAX_IMAGES_PER_DOC}\uAC1C/128MB) \u2014 \uC774\uD6C4 \uC774\uBBF8\uC9C0 \uC0DD\uB7B5`, code: "SKIPPED_IMAGE" });
|
|
1341
|
-
}
|
|
1342
|
-
continue;
|
|
1343
|
-
}
|
|
1344
1398
|
const rgba = toRgba(imgData);
|
|
1345
1399
|
if (!rgba) continue;
|
|
1346
1400
|
const png = encodePng(w, h, rgba);
|
|
@@ -2683,11 +2737,12 @@ function buildGridTable(lines, columns) {
|
|
|
2683
2737
|
if (filledCells < totalCells * 0.35 || merged.length < 2 || merged.length <= 3 && numCols >= 7) {
|
|
2684
2738
|
return merged.map((r) => r.filter((c) => c).join(" ")).join("\n");
|
|
2685
2739
|
}
|
|
2740
|
+
const escCell = (c) => c.replace(/\t/g, " ").replace(/\|/g, "\\|");
|
|
2686
2741
|
const md = [];
|
|
2687
|
-
md.push("| " + merged[0].join(" | ") + " |");
|
|
2742
|
+
md.push("| " + merged[0].map(escCell).join(" | ") + " |");
|
|
2688
2743
|
md.push("| " + merged[0].map(() => "---").join(" | ") + " |");
|
|
2689
2744
|
for (let r = 1; r < merged.length; r++) {
|
|
2690
|
-
md.push("| " + merged[r].join(" | ") + " |");
|
|
2745
|
+
md.push("| " + merged[r].map(escCell).join(" | ") + " |");
|
|
2691
2746
|
}
|
|
2692
2747
|
return md.join("\n");
|
|
2693
2748
|
}
|
|
@@ -2867,6 +2922,7 @@ function detectKoreanListBlocks(blocks) {
|
|
|
2867
2922
|
}
|
|
2868
2923
|
let familyStack = [];
|
|
2869
2924
|
let lastTopLevelList = null;
|
|
2925
|
+
let prevListIdx = -2;
|
|
2870
2926
|
const toRemove = /* @__PURE__ */ new Set();
|
|
2871
2927
|
for (let i = 0; i < blocks.length; i++) {
|
|
2872
2928
|
const b = blocks[i];
|
|
@@ -2895,7 +2951,7 @@ function detectKoreanListBlocks(blocks) {
|
|
|
2895
2951
|
if (depth === 0) {
|
|
2896
2952
|
blocks[i] = listBlock;
|
|
2897
2953
|
lastTopLevelList = listBlock;
|
|
2898
|
-
} else if (lastTopLevelList) {
|
|
2954
|
+
} else if (lastTopLevelList && i === prevListIdx + 1) {
|
|
2899
2955
|
if (!lastTopLevelList.children) lastTopLevelList.children = [];
|
|
2900
2956
|
lastTopLevelList.children.push(listBlock);
|
|
2901
2957
|
toRemove.add(i);
|
|
@@ -2903,6 +2959,7 @@ function detectKoreanListBlocks(blocks) {
|
|
|
2903
2959
|
blocks[i] = listBlock;
|
|
2904
2960
|
lastTopLevelList = listBlock;
|
|
2905
2961
|
}
|
|
2962
|
+
prevListIdx = i;
|
|
2906
2963
|
}
|
|
2907
2964
|
if (toRemove.size > 0) {
|
|
2908
2965
|
const sorted = [...toRemove].sort((a, b) => b - a);
|
|
@@ -3028,8 +3085,8 @@ function removeHeaderFooterBlocks(blocks, pageHeights, warnings) {
|
|
|
3028
3085
|
const blockTop = ph - (b.bbox.y + b.bbox.height);
|
|
3029
3086
|
const blockBottom = ph - b.bbox.y;
|
|
3030
3087
|
const entry = { blockIdx: bi, page: b.pageNumber, text: b.text.trim() };
|
|
3031
|
-
if (blockBottom <= ph * ZONE_RATIO)
|
|
3032
|
-
else if (blockTop >= ph * (1 - ZONE_RATIO))
|
|
3088
|
+
if (blockBottom <= ph * ZONE_RATIO) topEntries.push(entry);
|
|
3089
|
+
else if (blockTop >= ph * (1 - ZONE_RATIO)) bottomEntries.push(entry);
|
|
3033
3090
|
}
|
|
3034
3091
|
const removeSet = /* @__PURE__ */ new Set();
|
|
3035
3092
|
for (const entries of [topEntries, bottomEntries]) {
|
|
@@ -3202,6 +3259,8 @@ function extractBlocksWithGrids(items, pageNum, grids, horizontals, verticals) {
|
|
|
3202
3259
|
hasSpaceBefore: i.hasSpaceBefore
|
|
3203
3260
|
}));
|
|
3204
3261
|
const cellTextMap = mapTextToCells(textItems, cells);
|
|
3262
|
+
const assignedItems = /* @__PURE__ */ new Set();
|
|
3263
|
+
for (const arr of cellTextMap.values()) for (const it of arr) assignedItems.add(it);
|
|
3205
3264
|
const numRows = grid.rowYs.length - 1;
|
|
3206
3265
|
const numCols = grid.colXs.length - 1;
|
|
3207
3266
|
const irGrid = Array.from(
|
|
@@ -3221,9 +3280,11 @@ function extractBlocksWithGrids(items, pageNum, grids, horizontals, verticals) {
|
|
|
3221
3280
|
}
|
|
3222
3281
|
let finalGrid = irGrid;
|
|
3223
3282
|
let finalRows = numRows;
|
|
3283
|
+
let rebuiltUsed = false;
|
|
3224
3284
|
if (numRows <= 2 && numCols >= 3) {
|
|
3225
3285
|
const rebuilt = normalizeUndersegmentedTable(irGrid, grid.colXs, textItems);
|
|
3226
3286
|
if (rebuilt) {
|
|
3287
|
+
rebuiltUsed = true;
|
|
3227
3288
|
finalGrid = rebuilt.map((row) => row.map((rawText) => {
|
|
3228
3289
|
const cleaned = rawText.replace(/^[\s]*[-–—]\s*\d+\s*[-–—][\s]*$/gm, "").trim();
|
|
3229
3290
|
return {
|
|
@@ -3235,6 +3296,11 @@ function extractBlocksWithGrids(items, pageNum, grids, horizontals, verticals) {
|
|
|
3235
3296
|
finalRows = finalGrid.length;
|
|
3236
3297
|
}
|
|
3237
3298
|
}
|
|
3299
|
+
if (!rebuiltUsed) {
|
|
3300
|
+
for (let ti = 0; ti < textItems.length; ti++) {
|
|
3301
|
+
if (!assignedItems.has(textItems[ti])) usedItems.delete(tableItems[ti]);
|
|
3302
|
+
}
|
|
3303
|
+
}
|
|
3238
3304
|
const irTable = {
|
|
3239
3305
|
rows: finalRows,
|
|
3240
3306
|
cols: numCols,
|
|
@@ -3291,6 +3357,8 @@ function extractBlocksWithGrids(items, pageNum, grids, horizontals, verticals) {
|
|
|
3291
3357
|
}
|
|
3292
3358
|
remaining = remaining.filter((_, idx) => !usedClusterIndices.has(idx));
|
|
3293
3359
|
}
|
|
3360
|
+
const groupSizes = [];
|
|
3361
|
+
let finalTextBlocks = [];
|
|
3294
3362
|
if (remaining.length > 0) {
|
|
3295
3363
|
const allY = remaining.map((i) => i.y);
|
|
3296
3364
|
const pageH = safeMax(allY) - safeMin(allY);
|
|
@@ -3300,16 +3368,28 @@ function extractBlocksWithGrids(items, pageNum, grids, horizontals, verticals) {
|
|
|
3300
3368
|
if (group.length === 0) continue;
|
|
3301
3369
|
const groupBlocks = extractPageBlocksFallback(group, pageNum);
|
|
3302
3370
|
for (const b of groupBlocks) textBlocks.push(b);
|
|
3371
|
+
groupSizes.push(groupBlocks.length);
|
|
3303
3372
|
}
|
|
3304
|
-
|
|
3305
|
-
for (const b of finalTextBlocks) blocks.push(b);
|
|
3373
|
+
finalTextBlocks = detectListBlocks(textBlocks);
|
|
3306
3374
|
}
|
|
3307
|
-
blocks.
|
|
3308
|
-
|
|
3309
|
-
|
|
3310
|
-
|
|
3311
|
-
|
|
3312
|
-
|
|
3375
|
+
const units = blocks.map((b) => [b]);
|
|
3376
|
+
let off = 0;
|
|
3377
|
+
for (const size of groupSizes) {
|
|
3378
|
+
const unit = finalTextBlocks.slice(off, off + size);
|
|
3379
|
+
off += size;
|
|
3380
|
+
if (unit.length > 0) units.push(unit);
|
|
3381
|
+
}
|
|
3382
|
+
const unitTopY = (u) => {
|
|
3383
|
+
let top = 0;
|
|
3384
|
+
for (const b of u) {
|
|
3385
|
+
if (b.bbox && b.bbox.y + b.bbox.height > top) top = b.bbox.y + b.bbox.height;
|
|
3386
|
+
}
|
|
3387
|
+
return top;
|
|
3388
|
+
};
|
|
3389
|
+
units.sort((a, b) => unitTopY(b) - unitTopY(a));
|
|
3390
|
+
const ordered = [];
|
|
3391
|
+
for (const u of units) for (const b of u) ordered.push(b);
|
|
3392
|
+
return mergeAdjacentTableBlocks(ordered);
|
|
3313
3393
|
}
|
|
3314
3394
|
return mergeAdjacentTableBlocks(blocks);
|
|
3315
3395
|
}
|
|
@@ -3798,7 +3878,11 @@ async function parsePdfDocument(buffer, options) {
|
|
|
3798
3878
|
}
|
|
3799
3879
|
let pageText = "";
|
|
3800
3880
|
for (const b of pageBlocks) {
|
|
3801
|
-
|
|
3881
|
+
let t = b.text || "";
|
|
3882
|
+
if (b.type === "table" && b.table) {
|
|
3883
|
+
const cellText = b.table.cells.map((row) => row.map((c) => c.text).join(" ")).join("\n");
|
|
3884
|
+
t = t ? t + "\n" + cellText : cellText;
|
|
3885
|
+
}
|
|
3802
3886
|
totalChars += t.replace(/\s/g, "").length;
|
|
3803
3887
|
totalTextBytes += t.length * 2;
|
|
3804
3888
|
pageText += pageText ? "\n" + t : t;
|
|
@@ -3817,7 +3901,7 @@ async function parsePdfDocument(buffer, options) {
|
|
|
3817
3901
|
if (totalChars / Math.max(parsedPageCount, 1) < 10) {
|
|
3818
3902
|
if (options?.ocr) {
|
|
3819
3903
|
try {
|
|
3820
|
-
const { ocrPages } = await import("./provider-
|
|
3904
|
+
const { ocrPages } = await import("./provider-UIBW2MIH.js");
|
|
3821
3905
|
const ocrBlocks = await ocrPages(doc, options.ocr, pageFilter, effectivePageCount);
|
|
3822
3906
|
if (ocrBlocks.length > 0) {
|
|
3823
3907
|
const ocrMarkdown = ocrBlocks.map((b) => b.text || "").filter(Boolean).join("\n\n");
|
|
@@ -3938,4 +4022,4 @@ export {
|
|
|
3938
4022
|
parsePdfDocument,
|
|
3939
4023
|
removeHeaderFooterBlocks
|
|
3940
4024
|
};
|
|
3941
|
-
//# sourceMappingURL=parser-
|
|
4025
|
+
//# sourceMappingURL=parser-PEOYBXBO.js.map
|