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
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var _chunk37VKMUSTcjs = require('./chunk-37VKMUST.cjs');
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
var _chunkDCZVOIEOcjs = require('./chunk-DCZVOIEO.cjs');
|
|
@@ -581,6 +581,18 @@ function buildVertices(horizontals, verticals) {
|
|
|
581
581
|
}
|
|
582
582
|
function mergeVertices(vertices) {
|
|
583
583
|
if (vertices.length <= 1) return vertices;
|
|
584
|
+
let maxRadiusAll = 1;
|
|
585
|
+
for (const v of vertices) {
|
|
586
|
+
if (v.radius > maxRadiusAll) maxRadiusAll = v.radius;
|
|
587
|
+
}
|
|
588
|
+
const cell = Math.max(VERTEX_MERGE_FACTOR * maxRadiusAll, 1);
|
|
589
|
+
const buckets = /* @__PURE__ */ new Map();
|
|
590
|
+
for (let i = 0; i < vertices.length; i++) {
|
|
591
|
+
const key = Math.floor(vertices[i].x / cell) + "," + Math.floor(vertices[i].y / cell);
|
|
592
|
+
const arr = buckets.get(key);
|
|
593
|
+
if (arr) arr.push(i);
|
|
594
|
+
else buckets.set(key, [i]);
|
|
595
|
+
}
|
|
584
596
|
const merged = [];
|
|
585
597
|
const used = new Array(vertices.length).fill(false);
|
|
586
598
|
for (let i = 0; i < vertices.length; i++) {
|
|
@@ -588,7 +600,20 @@ function mergeVertices(vertices) {
|
|
|
588
600
|
let sumX = vertices[i].x, sumY = vertices[i].y;
|
|
589
601
|
let maxRadius = vertices[i].radius;
|
|
590
602
|
let count = 1;
|
|
591
|
-
|
|
603
|
+
const cx = Math.floor(vertices[i].x / cell);
|
|
604
|
+
const cy = Math.floor(vertices[i].y / cell);
|
|
605
|
+
const candidates = [];
|
|
606
|
+
for (let dx = -1; dx <= 1; dx++) {
|
|
607
|
+
for (let dy = -1; dy <= 1; dy++) {
|
|
608
|
+
const arr = buckets.get(cx + dx + "," + (cy + dy));
|
|
609
|
+
if (!arr) continue;
|
|
610
|
+
for (const j of arr) {
|
|
611
|
+
if (j > i && !used[j]) candidates.push(j);
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
candidates.sort((a, b) => a - b);
|
|
616
|
+
for (const j of candidates) {
|
|
592
617
|
if (used[j]) continue;
|
|
593
618
|
const mergeTol = VERTEX_MERGE_FACTOR * Math.max(maxRadius, vertices[j].radius);
|
|
594
619
|
if (Math.abs(vertices[i].x - vertices[j].x) <= mergeTol && Math.abs(vertices[i].y - vertices[j].y) <= mergeTol) {
|
|
@@ -815,6 +840,7 @@ function splitStackedGroup(group) {
|
|
|
815
840
|
}
|
|
816
841
|
return bands.filter((b) => b.length > 0);
|
|
817
842
|
}
|
|
843
|
+
var GROUP_BUCKET_CELL = 100;
|
|
818
844
|
function groupConnectedLines(lines) {
|
|
819
845
|
const parent = lines.map((_, i) => i);
|
|
820
846
|
function find(x) {
|
|
@@ -828,10 +854,34 @@ function groupConnectedLines(lines) {
|
|
|
828
854
|
const ra = find(a), rb = find(b);
|
|
829
855
|
if (ra !== rb) parent[ra] = rb;
|
|
830
856
|
}
|
|
857
|
+
const cellMap = /* @__PURE__ */ new Map();
|
|
831
858
|
for (let i = 0; i < lines.length; i++) {
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
859
|
+
const l = lines[i];
|
|
860
|
+
const cx1 = Math.floor((Math.min(l.x1, l.x2) - CONNECT_TOL) / GROUP_BUCKET_CELL);
|
|
861
|
+
const cx2 = Math.floor((Math.max(l.x1, l.x2) + CONNECT_TOL) / GROUP_BUCKET_CELL);
|
|
862
|
+
const cy1 = Math.floor((Math.min(l.y1, l.y2) - CONNECT_TOL) / GROUP_BUCKET_CELL);
|
|
863
|
+
const cy2 = Math.floor((Math.max(l.y1, l.y2) + CONNECT_TOL) / GROUP_BUCKET_CELL);
|
|
864
|
+
for (let cx = cx1; cx <= cx2; cx++) {
|
|
865
|
+
for (let cy = cy1; cy <= cy2; cy++) {
|
|
866
|
+
const key = cx + "," + cy;
|
|
867
|
+
const arr = cellMap.get(key);
|
|
868
|
+
if (arr) arr.push(i);
|
|
869
|
+
else cellMap.set(key, [i]);
|
|
870
|
+
}
|
|
871
|
+
}
|
|
872
|
+
}
|
|
873
|
+
const tested = /* @__PURE__ */ new Set();
|
|
874
|
+
for (const arr of cellMap.values()) {
|
|
875
|
+
for (let a = 0; a < arr.length; a++) {
|
|
876
|
+
for (let b = a + 1; b < arr.length; b++) {
|
|
877
|
+
const i = Math.min(arr[a], arr[b]);
|
|
878
|
+
const j = Math.max(arr[a], arr[b]);
|
|
879
|
+
const key = i * lines.length + j;
|
|
880
|
+
if (tested.has(key)) continue;
|
|
881
|
+
tested.add(key);
|
|
882
|
+
if (linesIntersect(lines[i], lines[j])) {
|
|
883
|
+
union(i, j);
|
|
884
|
+
}
|
|
835
885
|
}
|
|
836
886
|
}
|
|
837
887
|
}
|
|
@@ -1319,12 +1369,21 @@ async function extractPageImages(page, fnArray, argsArray, pageNumber, state, wa
|
|
|
1319
1369
|
if (typeof objId !== "string" || pageSeenIds.has(objId)) continue;
|
|
1320
1370
|
pageSeenIds.add(objId);
|
|
1321
1371
|
dedupeId = objId;
|
|
1322
|
-
|
|
1323
|
-
} else if (op === _pdfmjs.OPS.paintInlineImageXObject) {
|
|
1324
|
-
imgData = _optionalChain([argsArray, 'access', _6 => _6[i], 'optionalAccess', _7 => _7[0]]);
|
|
1325
|
-
} else {
|
|
1372
|
+
} else if (op !== _pdfmjs.OPS.paintInlineImageXObject) {
|
|
1326
1373
|
continue;
|
|
1327
1374
|
}
|
|
1375
|
+
if (state.imageIndex >= MAX_IMAGES_PER_DOC || state.totalBytes >= MAX_TOTAL_IMAGE_BYTES) {
|
|
1376
|
+
if (!state.capWarned) {
|
|
1377
|
+
state.capWarned = true;
|
|
1378
|
+
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" });
|
|
1379
|
+
}
|
|
1380
|
+
continue;
|
|
1381
|
+
}
|
|
1382
|
+
if (dedupeId) {
|
|
1383
|
+
imgData = await resolveImgData(page, dedupeId);
|
|
1384
|
+
} else {
|
|
1385
|
+
imgData = _optionalChain([argsArray, 'access', _6 => _6[i], 'optionalAccess', _7 => _7[0]]);
|
|
1386
|
+
}
|
|
1328
1387
|
if (!_optionalChain([imgData, 'optionalAccess', _8 => _8.data]) || !imgData.width || !imgData.height) continue;
|
|
1329
1388
|
const { width: w, height: h } = imgData;
|
|
1330
1389
|
if (w < MIN_DIM || h < MIN_DIM) continue;
|
|
@@ -1334,16 +1393,9 @@ async function extractPageImages(page, fnArray, argsArray, pageNumber, state, wa
|
|
|
1334
1393
|
}
|
|
1335
1394
|
const hash = `${w}x${h}k${_nullishCoalesce(imgData.kind, () => ( "?"))}h${fnv1a(imgData.data)}${dedupeId ? "" : "inline"}`;
|
|
1336
1395
|
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
1396
|
const rgba = toRgba(imgData);
|
|
1345
1397
|
if (!rgba) continue;
|
|
1346
|
-
const png =
|
|
1398
|
+
const png = _chunk37VKMUSTcjs.encodePng.call(void 0, w, h, rgba);
|
|
1347
1399
|
state.imageIndex++;
|
|
1348
1400
|
state.totalBytes += png.length;
|
|
1349
1401
|
const filename = `image_${String(state.imageIndex).padStart(3, "0")}.png`;
|
|
@@ -2485,14 +2537,14 @@ function isProseSpread(items) {
|
|
|
2485
2537
|
for (let i = 1; i < sorted.length; i++) {
|
|
2486
2538
|
gaps.push(sorted[i].x - (sorted[i - 1].x + sorted[i - 1].w));
|
|
2487
2539
|
}
|
|
2488
|
-
const maxGap =
|
|
2540
|
+
const maxGap = _chunk37VKMUSTcjs.safeMax.call(void 0, gaps);
|
|
2489
2541
|
const avgLen = items.reduce((s, i) => s + i.text.length, 0) / items.length;
|
|
2490
2542
|
return maxGap < 40 && avgLen < 5;
|
|
2491
2543
|
}
|
|
2492
2544
|
function detectColumns(yLines) {
|
|
2493
2545
|
const allItems = yLines.flat();
|
|
2494
2546
|
if (allItems.length === 0) return null;
|
|
2495
|
-
const pageWidth =
|
|
2547
|
+
const pageWidth = _chunk37VKMUSTcjs.safeMax.call(void 0, allItems.map((i) => i.x + i.w)) - _chunk37VKMUSTcjs.safeMin.call(void 0, allItems.map((i) => i.x));
|
|
2496
2548
|
if (pageWidth < 100) return null;
|
|
2497
2549
|
let bigoLineIdx = -1;
|
|
2498
2550
|
for (let i = 0; i < yLines.length; i++) {
|
|
@@ -2683,11 +2735,12 @@ function buildGridTable(lines, columns) {
|
|
|
2683
2735
|
if (filledCells < totalCells * 0.35 || merged.length < 2 || merged.length <= 3 && numCols >= 7) {
|
|
2684
2736
|
return merged.map((r) => r.filter((c) => c).join(" ")).join("\n");
|
|
2685
2737
|
}
|
|
2738
|
+
const escCell = (c) => c.replace(/\t/g, " ").replace(/\|/g, "\\|");
|
|
2686
2739
|
const md = [];
|
|
2687
|
-
md.push("| " + merged[0].join(" | ") + " |");
|
|
2740
|
+
md.push("| " + merged[0].map(escCell).join(" | ") + " |");
|
|
2688
2741
|
md.push("| " + merged[0].map(() => "---").join(" | ") + " |");
|
|
2689
2742
|
for (let r = 1; r < merged.length; r++) {
|
|
2690
|
-
md.push("| " + merged[r].join(" | ") + " |");
|
|
2743
|
+
md.push("| " + merged[r].map(escCell).join(" | ") + " |");
|
|
2691
2744
|
}
|
|
2692
2745
|
return md.join("\n");
|
|
2693
2746
|
}
|
|
@@ -2714,9 +2767,9 @@ function detectHeadings(blocks, medianFontSize) {
|
|
|
2714
2767
|
if (/^\d+$/.test(text)) continue;
|
|
2715
2768
|
const ratio = block.style.fontSize / medianFontSize;
|
|
2716
2769
|
let level = 0;
|
|
2717
|
-
if (ratio >=
|
|
2718
|
-
else if (ratio >=
|
|
2719
|
-
else if (ratio >=
|
|
2770
|
+
if (ratio >= _chunk37VKMUSTcjs.HEADING_RATIO_H1) level = 1;
|
|
2771
|
+
else if (ratio >= _chunk37VKMUSTcjs.HEADING_RATIO_H2) level = 2;
|
|
2772
|
+
else if (ratio >= _chunk37VKMUSTcjs.HEADING_RATIO_H3) level = 3;
|
|
2720
2773
|
if (level > 0) {
|
|
2721
2774
|
block.type = "heading";
|
|
2722
2775
|
block.level = level;
|
|
@@ -2867,6 +2920,7 @@ function detectKoreanListBlocks(blocks) {
|
|
|
2867
2920
|
}
|
|
2868
2921
|
let familyStack = [];
|
|
2869
2922
|
let lastTopLevelList = null;
|
|
2923
|
+
let prevListIdx = -2;
|
|
2870
2924
|
const toRemove = /* @__PURE__ */ new Set();
|
|
2871
2925
|
for (let i = 0; i < blocks.length; i++) {
|
|
2872
2926
|
const b = blocks[i];
|
|
@@ -2895,7 +2949,7 @@ function detectKoreanListBlocks(blocks) {
|
|
|
2895
2949
|
if (depth === 0) {
|
|
2896
2950
|
blocks[i] = listBlock;
|
|
2897
2951
|
lastTopLevelList = listBlock;
|
|
2898
|
-
} else if (lastTopLevelList) {
|
|
2952
|
+
} else if (lastTopLevelList && i === prevListIdx + 1) {
|
|
2899
2953
|
if (!lastTopLevelList.children) lastTopLevelList.children = [];
|
|
2900
2954
|
lastTopLevelList.children.push(listBlock);
|
|
2901
2955
|
toRemove.add(i);
|
|
@@ -2903,6 +2957,7 @@ function detectKoreanListBlocks(blocks) {
|
|
|
2903
2957
|
blocks[i] = listBlock;
|
|
2904
2958
|
lastTopLevelList = listBlock;
|
|
2905
2959
|
}
|
|
2960
|
+
prevListIdx = i;
|
|
2906
2961
|
}
|
|
2907
2962
|
if (toRemove.size > 0) {
|
|
2908
2963
|
const sorted = [...toRemove].sort((a, b) => b - a);
|
|
@@ -3028,8 +3083,8 @@ function removeHeaderFooterBlocks(blocks, pageHeights, warnings) {
|
|
|
3028
3083
|
const blockTop = ph - (b.bbox.y + b.bbox.height);
|
|
3029
3084
|
const blockBottom = ph - b.bbox.y;
|
|
3030
3085
|
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))
|
|
3086
|
+
if (blockBottom <= ph * ZONE_RATIO) topEntries.push(entry);
|
|
3087
|
+
else if (blockTop >= ph * (1 - ZONE_RATIO)) bottomEntries.push(entry);
|
|
3033
3088
|
}
|
|
3034
3089
|
const removeSet = /* @__PURE__ */ new Set();
|
|
3035
3090
|
for (const entries of [topEntries, bottomEntries]) {
|
|
@@ -3202,6 +3257,8 @@ function extractBlocksWithGrids(items, pageNum, grids, horizontals, verticals) {
|
|
|
3202
3257
|
hasSpaceBefore: i.hasSpaceBefore
|
|
3203
3258
|
}));
|
|
3204
3259
|
const cellTextMap = mapTextToCells(textItems, cells);
|
|
3260
|
+
const assignedItems = /* @__PURE__ */ new Set();
|
|
3261
|
+
for (const arr of cellTextMap.values()) for (const it of arr) assignedItems.add(it);
|
|
3205
3262
|
const numRows = grid.rowYs.length - 1;
|
|
3206
3263
|
const numCols = grid.colXs.length - 1;
|
|
3207
3264
|
const irGrid = Array.from(
|
|
@@ -3221,9 +3278,11 @@ function extractBlocksWithGrids(items, pageNum, grids, horizontals, verticals) {
|
|
|
3221
3278
|
}
|
|
3222
3279
|
let finalGrid = irGrid;
|
|
3223
3280
|
let finalRows = numRows;
|
|
3281
|
+
let rebuiltUsed = false;
|
|
3224
3282
|
if (numRows <= 2 && numCols >= 3) {
|
|
3225
3283
|
const rebuilt = normalizeUndersegmentedTable(irGrid, grid.colXs, textItems);
|
|
3226
3284
|
if (rebuilt) {
|
|
3285
|
+
rebuiltUsed = true;
|
|
3227
3286
|
finalGrid = rebuilt.map((row) => row.map((rawText) => {
|
|
3228
3287
|
const cleaned = rawText.replace(/^[\s]*[-–—]\s*\d+\s*[-–—][\s]*$/gm, "").trim();
|
|
3229
3288
|
return {
|
|
@@ -3235,6 +3294,11 @@ function extractBlocksWithGrids(items, pageNum, grids, horizontals, verticals) {
|
|
|
3235
3294
|
finalRows = finalGrid.length;
|
|
3236
3295
|
}
|
|
3237
3296
|
}
|
|
3297
|
+
if (!rebuiltUsed) {
|
|
3298
|
+
for (let ti = 0; ti < textItems.length; ti++) {
|
|
3299
|
+
if (!assignedItems.has(textItems[ti])) usedItems.delete(tableItems[ti]);
|
|
3300
|
+
}
|
|
3301
|
+
}
|
|
3238
3302
|
const irTable = {
|
|
3239
3303
|
rows: finalRows,
|
|
3240
3304
|
cols: numCols,
|
|
@@ -3291,25 +3355,39 @@ function extractBlocksWithGrids(items, pageNum, grids, horizontals, verticals) {
|
|
|
3291
3355
|
}
|
|
3292
3356
|
remaining = remaining.filter((_, idx) => !usedClusterIndices.has(idx));
|
|
3293
3357
|
}
|
|
3358
|
+
const groupSizes = [];
|
|
3359
|
+
let finalTextBlocks = [];
|
|
3294
3360
|
if (remaining.length > 0) {
|
|
3295
3361
|
const allY = remaining.map((i) => i.y);
|
|
3296
|
-
const pageH =
|
|
3362
|
+
const pageH = _chunk37VKMUSTcjs.safeMax.call(void 0, allY) - _chunk37VKMUSTcjs.safeMin.call(void 0, allY);
|
|
3297
3363
|
const groups = xyCutOrder(remaining, Math.max(15, pageH * 0.03));
|
|
3298
3364
|
const textBlocks = [];
|
|
3299
3365
|
for (const group of groups) {
|
|
3300
3366
|
if (group.length === 0) continue;
|
|
3301
3367
|
const groupBlocks = extractPageBlocksFallback(group, pageNum);
|
|
3302
3368
|
for (const b of groupBlocks) textBlocks.push(b);
|
|
3369
|
+
groupSizes.push(groupBlocks.length);
|
|
3303
3370
|
}
|
|
3304
|
-
|
|
3305
|
-
for (const b of finalTextBlocks) blocks.push(b);
|
|
3371
|
+
finalTextBlocks = detectListBlocks(textBlocks);
|
|
3306
3372
|
}
|
|
3307
|
-
blocks.
|
|
3308
|
-
|
|
3309
|
-
|
|
3310
|
-
|
|
3311
|
-
|
|
3312
|
-
|
|
3373
|
+
const units = blocks.map((b) => [b]);
|
|
3374
|
+
let off = 0;
|
|
3375
|
+
for (const size of groupSizes) {
|
|
3376
|
+
const unit = finalTextBlocks.slice(off, off + size);
|
|
3377
|
+
off += size;
|
|
3378
|
+
if (unit.length > 0) units.push(unit);
|
|
3379
|
+
}
|
|
3380
|
+
const unitTopY = (u) => {
|
|
3381
|
+
let top = 0;
|
|
3382
|
+
for (const b of u) {
|
|
3383
|
+
if (b.bbox && b.bbox.y + b.bbox.height > top) top = b.bbox.y + b.bbox.height;
|
|
3384
|
+
}
|
|
3385
|
+
return top;
|
|
3386
|
+
};
|
|
3387
|
+
units.sort((a, b) => unitTopY(b) - unitTopY(a));
|
|
3388
|
+
const ordered = [];
|
|
3389
|
+
for (const u of units) for (const b of u) ordered.push(b);
|
|
3390
|
+
return mergeAdjacentTableBlocks(ordered);
|
|
3313
3391
|
}
|
|
3314
3392
|
return mergeAdjacentTableBlocks(blocks);
|
|
3315
3393
|
}
|
|
@@ -3469,7 +3547,7 @@ function extractPageBlocksFallback(items, pageNum, fullPage = false) {
|
|
|
3469
3547
|
blocks.push({ type: "paragraph", text: tableText, pageNumber: pageNum, bbox, style: dominantStyle(items) });
|
|
3470
3548
|
} else {
|
|
3471
3549
|
const allY = items.map((i) => i.y);
|
|
3472
|
-
const pageHeight =
|
|
3550
|
+
const pageHeight = _chunk37VKMUSTcjs.safeMax.call(void 0, allY) - _chunk37VKMUSTcjs.safeMin.call(void 0, allY);
|
|
3473
3551
|
const gapThreshold = Math.max(15, pageHeight * 0.03);
|
|
3474
3552
|
const orderedGroups = proseCutX !== null ? splitTwoColumnProse(items, proseCutX) : xyCutOrder(items, gapThreshold);
|
|
3475
3553
|
for (const group of orderedGroups) {
|
|
@@ -3722,7 +3800,7 @@ async function loadPdfWithTimeout(buffer) {
|
|
|
3722
3800
|
new Promise((_, reject) => {
|
|
3723
3801
|
timer = setTimeout(() => {
|
|
3724
3802
|
loadingTask.destroy();
|
|
3725
|
-
reject(new (0,
|
|
3803
|
+
reject(new (0, _chunk37VKMUSTcjs.KordocError)("PDF \uB85C\uB529 \uD0C0\uC784\uC544\uC6C3 (30\uCD08 \uCD08\uACFC)"));
|
|
3726
3804
|
}, PDF_LOAD_TIMEOUT_MS);
|
|
3727
3805
|
})
|
|
3728
3806
|
]);
|
|
@@ -3735,7 +3813,7 @@ async function parsePdfDocument(buffer, options) {
|
|
|
3735
3813
|
const doc = await loadPdfWithTimeout(buffer);
|
|
3736
3814
|
try {
|
|
3737
3815
|
const pageCount = doc.numPages;
|
|
3738
|
-
if (pageCount === 0) throw new (0,
|
|
3816
|
+
if (pageCount === 0) throw new (0, _chunk37VKMUSTcjs.KordocError)("PDF\uC5D0 \uD398\uC774\uC9C0\uAC00 \uC5C6\uC2B5\uB2C8\uB2E4.");
|
|
3739
3817
|
const metadata = { pageCount };
|
|
3740
3818
|
await extractPdfMetadata(doc, metadata);
|
|
3741
3819
|
const blocks = [];
|
|
@@ -3798,17 +3876,21 @@ async function parsePdfDocument(buffer, options) {
|
|
|
3798
3876
|
}
|
|
3799
3877
|
let pageText = "";
|
|
3800
3878
|
for (const b of pageBlocks) {
|
|
3801
|
-
|
|
3879
|
+
let t = b.text || "";
|
|
3880
|
+
if (b.type === "table" && b.table) {
|
|
3881
|
+
const cellText = b.table.cells.map((row) => row.map((c) => c.text).join(" ")).join("\n");
|
|
3882
|
+
t = t ? t + "\n" + cellText : cellText;
|
|
3883
|
+
}
|
|
3802
3884
|
totalChars += t.replace(/\s/g, "").length;
|
|
3803
3885
|
totalTextBytes += t.length * 2;
|
|
3804
3886
|
pageText += pageText ? "\n" + t : t;
|
|
3805
3887
|
}
|
|
3806
3888
|
pageQuality.push(computePageQuality(i, pageText));
|
|
3807
|
-
if (totalTextBytes > MAX_TOTAL_TEXT) throw new (0,
|
|
3889
|
+
if (totalTextBytes > MAX_TOTAL_TEXT) throw new (0, _chunk37VKMUSTcjs.KordocError)("\uD14D\uC2A4\uD2B8 \uCD94\uCD9C \uD06C\uAE30 \uCD08\uACFC");
|
|
3808
3890
|
parsedPages++;
|
|
3809
3891
|
_optionalChain([options, 'optionalAccess', _41 => _41.onProgress, 'optionalCall', _42 => _42(parsedPages, totalTarget)]);
|
|
3810
3892
|
} catch (pageErr) {
|
|
3811
|
-
if (pageErr instanceof
|
|
3893
|
+
if (pageErr instanceof _chunk37VKMUSTcjs.KordocError) throw pageErr;
|
|
3812
3894
|
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" });
|
|
3813
3895
|
}
|
|
3814
3896
|
}
|
|
@@ -3817,7 +3899,7 @@ async function parsePdfDocument(buffer, options) {
|
|
|
3817
3899
|
if (totalChars / Math.max(parsedPageCount, 1) < 10) {
|
|
3818
3900
|
if (_optionalChain([options, 'optionalAccess', _43 => _43.ocr])) {
|
|
3819
3901
|
try {
|
|
3820
|
-
const { ocrPages } = await Promise.resolve().then(() => _interopRequireWildcard(require("./provider-
|
|
3902
|
+
const { ocrPages } = await Promise.resolve().then(() => _interopRequireWildcard(require("./provider-4FAYHJ6N.cjs")));
|
|
3821
3903
|
const ocrBlocks = await ocrPages(doc, options.ocr, pageFilter, effectivePageCount);
|
|
3822
3904
|
if (ocrBlocks.length > 0) {
|
|
3823
3905
|
const ocrMarkdown = ocrBlocks.map((b) => b.text || "").filter(Boolean).join("\n\n");
|
|
@@ -3878,7 +3960,7 @@ async function parsePdfDocument(buffer, options) {
|
|
|
3878
3960
|
detectKoreanListBlocks(blocks);
|
|
3879
3961
|
const outline = blocks.filter((b) => b.type === "heading" && b.level && b.text).map((b) => ({ level: b.level, text: b.text, pageNumber: b.pageNumber }));
|
|
3880
3962
|
sanitizeBlockControlChars(blocks);
|
|
3881
|
-
let markdown = cleanPdfText(
|
|
3963
|
+
let markdown = cleanPdfText(_chunk37VKMUSTcjs.blocksToMarkdown.call(void 0, blocks));
|
|
3882
3964
|
return {
|
|
3883
3965
|
markdown,
|
|
3884
3966
|
blocks,
|
|
@@ -3938,4 +4020,4 @@ async function extractPdfMetadataOnly(buffer) {
|
|
|
3938
4020
|
|
|
3939
4021
|
|
|
3940
4022
|
exports.cleanPdfText = cleanPdfText; exports.detectKoreanListBlocks = detectKoreanListBlocks; exports.detectTableCaptions = detectTableCaptions; exports.extractPdfMetadataOnly = extractPdfMetadataOnly; exports.mergeCrossPageTables = mergeCrossPageTables; exports.parsePdfDocument = parsePdfDocument; exports.removeHeaderFooterBlocks = removeHeaderFooterBlocks;
|
|
3941
|
-
//# sourceMappingURL=parser-
|
|
4023
|
+
//# sourceMappingURL=parser-N4A7UGDK.cjs.map
|