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.
- package/README.md +34 -1
- package/dist/{-MRPDPE2X.js → -H7N62NZU.js} +24 -13
- package/dist/{chunk-33CIKNL4.js → chunk-5RHRQ7HK.js} +479 -258
- package/dist/chunk-5RHRQ7HK.js.map +1 -0
- package/dist/{chunk-MEXUFQVC.cjs → chunk-BIP4JAVG.cjs} +5 -5
- package/dist/chunk-BIP4JAVG.cjs.map +1 -0
- package/dist/chunk-DCZVOIEO.cjs.map +1 -1
- package/dist/chunk-FGL7BH4P.js +1019 -0
- package/dist/chunk-FGL7BH4P.js.map +1 -0
- package/dist/chunk-GS7T56RP.cjs.map +1 -1
- package/dist/{chunk-Q6UXVJXI.js → chunk-IC56KHBL.js} +2 -2
- package/dist/chunk-JFNWJFKP.js +185 -0
- package/dist/chunk-JFNWJFKP.js.map +1 -0
- package/dist/{chunk-YXOT7P5B.js → chunk-LYL4IL3E.js} +5 -5
- package/dist/{chunk-YXOT7P5B.js.map → chunk-LYL4IL3E.js.map} +1 -1
- package/dist/{chunk-O4WFPOFN.js → chunk-Q7EGGW3H.js} +5 -5
- package/dist/{chunk-O4WFPOFN.js.map → chunk-Q7EGGW3H.js.map} +1 -1
- package/dist/{chunk-TWACKS3K.js → chunk-WD5NUUU6.js} +571 -729
- package/dist/chunk-WD5NUUU6.js.map +1 -0
- package/dist/cli.js +125 -12
- package/dist/cli.js.map +1 -1
- package/dist/formula-5NKVS2LR.cjs.map +1 -1
- package/dist/index.cjs +1668 -449
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +144 -6
- package/dist/index.d.ts +144 -6
- package/dist/index.js +1502 -283
- package/dist/index.js.map +1 -1
- package/dist/mcp.js +93 -12
- package/dist/mcp.js.map +1 -1
- package/dist/page-range-P7SDW6LR.cjs.map +1 -1
- package/dist/{parser-Z3IL2ESY.js → parser-5G247XYD.js} +54 -6
- package/dist/parser-5G247XYD.js.map +1 -0
- package/dist/{parser-DZBI3EA2.cjs → parser-6V7F3GET.cjs} +66 -18
- package/dist/parser-6V7F3GET.cjs.map +1 -0
- package/dist/{parser-XUNGOH76.js → parser-HBHCD7TE.js} +55 -7
- package/dist/parser-HBHCD7TE.js.map +1 -0
- package/dist/provider-G4C2V2PD.cjs.map +1 -1
- package/dist/render-VA4NHROW.js +10 -0
- package/dist/seal-UVDRGHEF.js +10 -0
- package/dist/seal-UVDRGHEF.js.map +1 -0
- package/dist/{watch-G5NFIT5L.js → watch-HIYNOSFD.js} +7 -5
- package/dist/{watch-G5NFIT5L.js.map → watch-HIYNOSFD.js.map} +1 -1
- package/package.json +4 -3
- package/dist/chunk-33CIKNL4.js.map +0 -1
- package/dist/chunk-MEXUFQVC.cjs.map +0 -1
- package/dist/chunk-TWACKS3K.js.map +0 -1
- package/dist/parser-DZBI3EA2.cjs.map +0 -1
- package/dist/parser-XUNGOH76.js.map +0 -1
- package/dist/parser-Z3IL2ESY.js.map +0 -1
- package/dist/render-VZ4OGHZU.js +0 -9
- /package/dist/{-MRPDPE2X.js.map → -H7N62NZU.js.map} +0 -0
- /package/dist/{chunk-Q6UXVJXI.js.map → chunk-IC56KHBL.js.map} +0 -0
- /package/dist/{render-VZ4OGHZU.js.map → render-VA4NHROW.js.map} +0 -0
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
var
|
|
9
|
+
var _chunkBIP4JAVGcjs = require('./chunk-BIP4JAVG.cjs');
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
var _chunkDCZVOIEOcjs = require('./chunk-DCZVOIEO.cjs');
|
|
@@ -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) =>
|
|
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 ?
|
|
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
|
-
|
|
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]), (_nullishCoalesce(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 = _nullishCoalesce(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
|
|
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) {
|
|
@@ -2086,14 +2134,14 @@ function isProseSpread(items) {
|
|
|
2086
2134
|
for (let i = 1; i < sorted.length; i++) {
|
|
2087
2135
|
gaps.push(sorted[i].x - (sorted[i - 1].x + sorted[i - 1].w));
|
|
2088
2136
|
}
|
|
2089
|
-
const maxGap =
|
|
2137
|
+
const maxGap = _chunkBIP4JAVGcjs.safeMax.call(void 0, gaps);
|
|
2090
2138
|
const avgLen = items.reduce((s, i) => s + i.text.length, 0) / items.length;
|
|
2091
2139
|
return maxGap < 40 && avgLen < 5;
|
|
2092
2140
|
}
|
|
2093
2141
|
function detectColumns(yLines) {
|
|
2094
2142
|
const allItems = yLines.flat();
|
|
2095
2143
|
if (allItems.length === 0) return null;
|
|
2096
|
-
const pageWidth =
|
|
2144
|
+
const pageWidth = _chunkBIP4JAVGcjs.safeMax.call(void 0, allItems.map((i) => i.x + i.w)) - _chunkBIP4JAVGcjs.safeMin.call(void 0, allItems.map((i) => i.x));
|
|
2097
2145
|
if (pageWidth < 100) return null;
|
|
2098
2146
|
let bigoLineIdx = -1;
|
|
2099
2147
|
for (let i = 0; i < yLines.length; i++) {
|
|
@@ -2315,9 +2363,9 @@ function detectHeadings(blocks, medianFontSize) {
|
|
|
2315
2363
|
if (/^\d+$/.test(text)) continue;
|
|
2316
2364
|
const ratio = block.style.fontSize / medianFontSize;
|
|
2317
2365
|
let level = 0;
|
|
2318
|
-
if (ratio >=
|
|
2319
|
-
else if (ratio >=
|
|
2320
|
-
else if (ratio >=
|
|
2366
|
+
if (ratio >= _chunkBIP4JAVGcjs.HEADING_RATIO_H1) level = 1;
|
|
2367
|
+
else if (ratio >= _chunkBIP4JAVGcjs.HEADING_RATIO_H2) level = 2;
|
|
2368
|
+
else if (ratio >= _chunkBIP4JAVGcjs.HEADING_RATIO_H3) level = 3;
|
|
2321
2369
|
if (level > 0) {
|
|
2322
2370
|
block.type = "heading";
|
|
2323
2371
|
block.level = level;
|
|
@@ -2893,7 +2941,7 @@ function extractBlocksWithGrids(items, pageNum, grids, horizontals, verticals) {
|
|
|
2893
2941
|
}
|
|
2894
2942
|
if (remaining.length > 0) {
|
|
2895
2943
|
const allY = remaining.map((i) => i.y);
|
|
2896
|
-
const pageH =
|
|
2944
|
+
const pageH = _chunkBIP4JAVGcjs.safeMax.call(void 0, allY) - _chunkBIP4JAVGcjs.safeMin.call(void 0, allY);
|
|
2897
2945
|
const groups = xyCutOrder(remaining, Math.max(15, pageH * 0.03));
|
|
2898
2946
|
const textBlocks = [];
|
|
2899
2947
|
for (const group of groups) {
|
|
@@ -3069,7 +3117,7 @@ function extractPageBlocksFallback(items, pageNum, fullPage = false) {
|
|
|
3069
3117
|
blocks.push({ type: "paragraph", text: tableText, pageNumber: pageNum, bbox, style: dominantStyle(items) });
|
|
3070
3118
|
} else {
|
|
3071
3119
|
const allY = items.map((i) => i.y);
|
|
3072
|
-
const pageHeight =
|
|
3120
|
+
const pageHeight = _chunkBIP4JAVGcjs.safeMax.call(void 0, allY) - _chunkBIP4JAVGcjs.safeMin.call(void 0, allY);
|
|
3073
3121
|
const gapThreshold = Math.max(15, pageHeight * 0.03);
|
|
3074
3122
|
const orderedGroups = proseCutX !== null ? splitTwoColumnProse(items, proseCutX) : xyCutOrder(items, gapThreshold);
|
|
3075
3123
|
for (const group of orderedGroups) {
|
|
@@ -3322,7 +3370,7 @@ async function loadPdfWithTimeout(buffer) {
|
|
|
3322
3370
|
new Promise((_, reject) => {
|
|
3323
3371
|
timer = setTimeout(() => {
|
|
3324
3372
|
loadingTask.destroy();
|
|
3325
|
-
reject(new (0,
|
|
3373
|
+
reject(new (0, _chunkBIP4JAVGcjs.KordocError)("PDF \uB85C\uB529 \uD0C0\uC784\uC544\uC6C3 (30\uCD08 \uCD08\uACFC)"));
|
|
3326
3374
|
}, PDF_LOAD_TIMEOUT_MS);
|
|
3327
3375
|
})
|
|
3328
3376
|
]);
|
|
@@ -3335,7 +3383,7 @@ async function parsePdfDocument(buffer, options) {
|
|
|
3335
3383
|
const doc = await loadPdfWithTimeout(buffer);
|
|
3336
3384
|
try {
|
|
3337
3385
|
const pageCount = doc.numPages;
|
|
3338
|
-
if (pageCount === 0) throw new (0,
|
|
3386
|
+
if (pageCount === 0) throw new (0, _chunkBIP4JAVGcjs.KordocError)("PDF\uC5D0 \uD398\uC774\uC9C0\uAC00 \uC5C6\uC2B5\uB2C8\uB2E4.");
|
|
3339
3387
|
const metadata = { pageCount };
|
|
3340
3388
|
await extractPdfMetadata(doc, metadata);
|
|
3341
3389
|
const blocks = [];
|
|
@@ -3395,11 +3443,11 @@ async function parsePdfDocument(buffer, options) {
|
|
|
3395
3443
|
pageText += pageText ? "\n" + t : t;
|
|
3396
3444
|
}
|
|
3397
3445
|
pageQuality.push(computePageQuality(i, pageText));
|
|
3398
|
-
if (totalTextBytes > MAX_TOTAL_TEXT) throw new (0,
|
|
3446
|
+
if (totalTextBytes > MAX_TOTAL_TEXT) throw new (0, _chunkBIP4JAVGcjs.KordocError)("\uD14D\uC2A4\uD2B8 \uCD94\uCD9C \uD06C\uAE30 \uCD08\uACFC");
|
|
3399
3447
|
parsedPages++;
|
|
3400
3448
|
_optionalChain([options, 'optionalAccess', _36 => _36.onProgress, 'optionalCall', _37 => _37(parsedPages, totalTarget)]);
|
|
3401
3449
|
} catch (pageErr) {
|
|
3402
|
-
if (pageErr instanceof
|
|
3450
|
+
if (pageErr instanceof _chunkBIP4JAVGcjs.KordocError) throw pageErr;
|
|
3403
3451
|
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" });
|
|
3404
3452
|
}
|
|
3405
3453
|
}
|
|
@@ -3467,7 +3515,7 @@ async function parsePdfDocument(buffer, options) {
|
|
|
3467
3515
|
detectKoreanListBlocks(blocks);
|
|
3468
3516
|
const outline = blocks.filter((b) => b.type === "heading" && b.level && b.text).map((b) => ({ level: b.level, text: b.text, pageNumber: b.pageNumber }));
|
|
3469
3517
|
sanitizeBlockControlChars(blocks);
|
|
3470
|
-
let markdown = cleanPdfText(
|
|
3518
|
+
let markdown = cleanPdfText(_chunkBIP4JAVGcjs.blocksToMarkdown.call(void 0, blocks));
|
|
3471
3519
|
return {
|
|
3472
3520
|
markdown,
|
|
3473
3521
|
blocks,
|
|
@@ -3526,4 +3574,4 @@ async function extractPdfMetadataOnly(buffer) {
|
|
|
3526
3574
|
|
|
3527
3575
|
|
|
3528
3576
|
exports.cleanPdfText = cleanPdfText; exports.detectKoreanListBlocks = detectKoreanListBlocks; exports.detectTableCaptions = detectTableCaptions; exports.extractPdfMetadataOnly = extractPdfMetadataOnly; exports.mergeCrossPageTables = mergeCrossPageTables; exports.parsePdfDocument = parsePdfDocument; exports.removeHeaderFooterBlocks = removeHeaderFooterBlocks;
|
|
3529
|
-
//# sourceMappingURL=parser-
|
|
3577
|
+
//# sourceMappingURL=parser-6V7F3GET.cjs.map
|