kordoc 3.16.0 → 3.16.2
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 +1 -1
- package/dist/{-H7N62NZU.js → -C4FVXHIP.js} +7 -7
- package/dist/{chunk-IC56KHBL.js → chunk-4WI7QXEG.js} +2 -2
- package/dist/{chunk-BIP4JAVG.cjs → chunk-72LLOLFX.cjs} +13 -6
- package/dist/chunk-72LLOLFX.cjs.map +1 -0
- package/dist/{chunk-5RHRQ7HK.js → chunk-E4Y73XRH.js} +8 -4
- package/dist/chunk-E4Y73XRH.js.map +1 -0
- package/dist/{chunk-Q7EGGW3H.js → chunk-EJ2ZIYTO.js} +13 -6
- package/dist/chunk-EJ2ZIYTO.js.map +1 -0
- package/dist/{chunk-WD5NUUU6.js → chunk-EUEKDZ7O.js} +315 -262
- package/dist/chunk-EUEKDZ7O.js.map +1 -0
- package/dist/{chunk-JFNWJFKP.js → chunk-HECUYZZK.js} +2 -2
- package/dist/{chunk-LYL4IL3E.js → chunk-IS3IK7UT.js} +13 -6
- package/dist/chunk-IS3IK7UT.js.map +1 -0
- package/dist/{chunk-FGL7BH4P.js → chunk-WR5LHRXO.js} +49 -20
- package/dist/chunk-WR5LHRXO.js.map +1 -0
- package/dist/cli.js +56 -17
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +586 -502
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +11 -3
- package/dist/index.d.ts +11 -3
- package/dist/index.js +358 -274
- package/dist/index.js.map +1 -1
- package/dist/mcp.js +25 -16
- package/dist/mcp.js.map +1 -1
- package/dist/{parser-HBHCD7TE.js → parser-CMPNM6ZL.js} +25 -12
- package/dist/parser-CMPNM6ZL.js.map +1 -0
- package/dist/{parser-5G247XYD.js → parser-GWL72XYS.js} +24 -11
- package/dist/parser-GWL72XYS.js.map +1 -0
- package/dist/{parser-6V7F3GET.cjs → parser-YVRTKGKO.cjs} +36 -23
- package/dist/parser-YVRTKGKO.cjs.map +1 -0
- package/dist/render-A2LFMJCP.js +10 -0
- package/dist/seal-KA4VAV2Z.js +10 -0
- package/dist/{watch-HIYNOSFD.js → watch-WLI6K3IR.js} +7 -7
- package/package.json +2 -5
- package/dist/chunk-5RHRQ7HK.js.map +0 -1
- package/dist/chunk-BIP4JAVG.cjs.map +0 -1
- package/dist/chunk-FGL7BH4P.js.map +0 -1
- package/dist/chunk-LYL4IL3E.js.map +0 -1
- package/dist/chunk-Q7EGGW3H.js.map +0 -1
- package/dist/chunk-WD5NUUU6.js.map +0 -1
- package/dist/parser-5G247XYD.js.map +0 -1
- package/dist/parser-6V7F3GET.cjs.map +0 -1
- package/dist/parser-HBHCD7TE.js.map +0 -1
- package/dist/render-VA4NHROW.js +0 -10
- package/dist/seal-UVDRGHEF.js +0 -10
- /package/dist/{-H7N62NZU.js.map → -C4FVXHIP.js.map} +0 -0
- /package/dist/{chunk-IC56KHBL.js.map → chunk-4WI7QXEG.js.map} +0 -0
- /package/dist/{chunk-JFNWJFKP.js.map → chunk-HECUYZZK.js.map} +0 -0
- /package/dist/{render-VA4NHROW.js.map → render-A2LFMJCP.js.map} +0 -0
- /package/dist/{seal-UVDRGHEF.js.map → seal-KA4VAV2Z.js.map} +0 -0
- /package/dist/{watch-HIYNOSFD.js.map → watch-WLI6K3IR.js.map} +0 -0
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
var
|
|
9
|
+
var _chunk72LLOLFXcjs = require('./chunk-72LLOLFX.cjs');
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
var _chunkDCZVOIEOcjs = require('./chunk-DCZVOIEO.cjs');
|
|
@@ -49,14 +49,14 @@ function extractLines(fnArray, argsArray) {
|
|
|
49
49
|
pushSeg(rx, ry + rh, rx, ry);
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
|
-
function flushPath(isStroke) {
|
|
52
|
+
function flushPath(isStroke, fromFill = false) {
|
|
53
53
|
if (!isStroke) {
|
|
54
54
|
currentPath = [];
|
|
55
55
|
return;
|
|
56
56
|
}
|
|
57
57
|
const effWidth = lineWidth * ctmScale();
|
|
58
58
|
for (const seg of currentPath) {
|
|
59
|
-
classifyAndAdd(seg, effWidth, horizontals, verticals);
|
|
59
|
+
classifyAndAdd(seg, effWidth, horizontals, verticals, fromFill);
|
|
60
60
|
}
|
|
61
61
|
currentPath = [];
|
|
62
62
|
}
|
|
@@ -154,7 +154,9 @@ function extractLines(fnArray, argsArray) {
|
|
|
154
154
|
}
|
|
155
155
|
if (afterOp === _pdfmjs.OPS.stroke || afterOp === _pdfmjs.OPS.closeStroke) {
|
|
156
156
|
flushPath(true);
|
|
157
|
-
} else if (afterOp === _pdfmjs.OPS.fill || afterOp === _pdfmjs.OPS.eoFill
|
|
157
|
+
} else if (afterOp === _pdfmjs.OPS.fill || afterOp === _pdfmjs.OPS.eoFill) {
|
|
158
|
+
flushPath(true, true);
|
|
159
|
+
} else if (afterOp === _pdfmjs.OPS.fillStroke || afterOp === _pdfmjs.OPS.eoFillStroke || afterOp === _pdfmjs.OPS.closeFillStroke || afterOp === _pdfmjs.OPS.closeEOFillStroke) {
|
|
158
160
|
flushPath(true);
|
|
159
161
|
} else if (afterOp === _pdfmjs.OPS.endPath) {
|
|
160
162
|
flushPath(false);
|
|
@@ -168,6 +170,8 @@ function extractLines(fnArray, argsArray) {
|
|
|
168
170
|
break;
|
|
169
171
|
case _pdfmjs.OPS.fill:
|
|
170
172
|
case _pdfmjs.OPS.eoFill:
|
|
173
|
+
flushPath(true, true);
|
|
174
|
+
break;
|
|
171
175
|
case _pdfmjs.OPS.fillStroke:
|
|
172
176
|
case _pdfmjs.OPS.eoFillStroke:
|
|
173
177
|
case _pdfmjs.OPS.closeFillStroke:
|
|
@@ -181,7 +185,7 @@ function extractLines(fnArray, argsArray) {
|
|
|
181
185
|
}
|
|
182
186
|
return { horizontals, verticals };
|
|
183
187
|
}
|
|
184
|
-
function classifyAndAdd(seg, lineWidth, horizontals, verticals) {
|
|
188
|
+
function classifyAndAdd(seg, lineWidth, horizontals, verticals, fromFill = false) {
|
|
185
189
|
const dx = Math.abs(seg.x2 - seg.x1);
|
|
186
190
|
const dy = Math.abs(seg.y2 - seg.y1);
|
|
187
191
|
const length = Math.sqrt(dx * dx + dy * dy);
|
|
@@ -190,12 +194,12 @@ function classifyAndAdd(seg, lineWidth, horizontals, verticals) {
|
|
|
190
194
|
const y = (seg.y1 + seg.y2) / 2;
|
|
191
195
|
const x1 = Math.min(seg.x1, seg.x2);
|
|
192
196
|
const x2 = Math.max(seg.x1, seg.x2);
|
|
193
|
-
horizontals.push({ x1, y1: y, x2, y2: y, lineWidth });
|
|
197
|
+
horizontals.push({ x1, y1: y, x2, y2: y, lineWidth, fromFill });
|
|
194
198
|
} else if (dx <= ORIENTATION_TOL) {
|
|
195
199
|
const x = (seg.x1 + seg.x2) / 2;
|
|
196
200
|
const y1 = Math.min(seg.y1, seg.y2);
|
|
197
201
|
const y2 = Math.max(seg.y1, seg.y2);
|
|
198
|
-
verticals.push({ x1: x, y1, x2: x, y2, lineWidth });
|
|
202
|
+
verticals.push({ x1: x, y1, x2: x, y2, lineWidth, fromFill });
|
|
199
203
|
}
|
|
200
204
|
}
|
|
201
205
|
function preprocessLines(horizontals, verticals) {
|
|
@@ -243,7 +247,10 @@ function dropShadingStacks(lines, dir) {
|
|
|
243
247
|
for (let j = s + 1; j <= e; j++) pitches.push(coord(group[j]) - coord(group[j - 1]));
|
|
244
248
|
pitches.sort((a, b) => a - b);
|
|
245
249
|
const medPitch = _nullishCoalesce(pitches[Math.floor(pitches.length / 2)], () => ( 0));
|
|
246
|
-
|
|
250
|
+
let fillN = 0;
|
|
251
|
+
for (let j = s; j <= e; j++) if (group[j].fromFill) fillN++;
|
|
252
|
+
const stackIsFill = fillN * 2 > e - s + 1;
|
|
253
|
+
const edgeAlien = (j, inwardGap) => stackIsFill && !group[j].fromFill || wKey(group[j]) !== domW || medPitch > 0 && inwardGap > medPitch * 1.8;
|
|
247
254
|
while (e - s + 1 >= STACK_MIN_LINES) {
|
|
248
255
|
if (edgeAlien(s, coord(group[s + 1]) - coord(group[s]))) {
|
|
249
256
|
s++;
|
|
@@ -271,6 +278,7 @@ var EDGE_INSET = 15;
|
|
|
271
278
|
var EDGE_NEAR = 10;
|
|
272
279
|
var EDGE_CONNECT_TOL = 5;
|
|
273
280
|
var EDGE_YGAP_SPLIT_K = 2.5;
|
|
281
|
+
var EDGE_YGAP_ABS_MIN = 30;
|
|
274
282
|
var CHAIN_Y_TOL = 1.5;
|
|
275
283
|
var CHAIN_GAP = 3;
|
|
276
284
|
function chainCollinearRules(horizontals) {
|
|
@@ -324,7 +332,12 @@ function closeOpenTableEdges(horizontals, verticals) {
|
|
|
324
332
|
const threshold = median * EDGE_YGAP_SPLIT_K;
|
|
325
333
|
let cur = sorted.length ? [sorted[0]] : [];
|
|
326
334
|
for (let i = 1; i < sorted.length; i++) {
|
|
327
|
-
|
|
335
|
+
const yLo = sorted[i - 1].y1, yHi = sorted[i].y1;
|
|
336
|
+
const gap = yHi - yLo;
|
|
337
|
+
const gx1 = Math.min(sorted[i - 1].x1, sorted[i].x1);
|
|
338
|
+
const gx2 = Math.max(sorted[i - 1].x2, sorted[i].x2);
|
|
339
|
+
const bridged = verticals.some((vl) => vl.y1 <= yLo + EDGE_NEAR && vl.y2 >= yHi - EDGE_NEAR && vl.x1 >= gx1 - EDGE_CONNECT_TOL && vl.x1 <= gx2 + EDGE_CONNECT_TOL);
|
|
340
|
+
if (median > 0 && gap > threshold && gap > EDGE_YGAP_ABS_MIN && !bridged && cur.length >= EDGE_MIN_RULES && sorted.length - i >= EDGE_MIN_RULES) {
|
|
328
341
|
splitGroups.push(cur);
|
|
329
342
|
cur = [];
|
|
330
343
|
}
|
|
@@ -2134,14 +2147,14 @@ function isProseSpread(items) {
|
|
|
2134
2147
|
for (let i = 1; i < sorted.length; i++) {
|
|
2135
2148
|
gaps.push(sorted[i].x - (sorted[i - 1].x + sorted[i - 1].w));
|
|
2136
2149
|
}
|
|
2137
|
-
const maxGap =
|
|
2150
|
+
const maxGap = _chunk72LLOLFXcjs.safeMax.call(void 0, gaps);
|
|
2138
2151
|
const avgLen = items.reduce((s, i) => s + i.text.length, 0) / items.length;
|
|
2139
2152
|
return maxGap < 40 && avgLen < 5;
|
|
2140
2153
|
}
|
|
2141
2154
|
function detectColumns(yLines) {
|
|
2142
2155
|
const allItems = yLines.flat();
|
|
2143
2156
|
if (allItems.length === 0) return null;
|
|
2144
|
-
const pageWidth =
|
|
2157
|
+
const pageWidth = _chunk72LLOLFXcjs.safeMax.call(void 0, allItems.map((i) => i.x + i.w)) - _chunk72LLOLFXcjs.safeMin.call(void 0, allItems.map((i) => i.x));
|
|
2145
2158
|
if (pageWidth < 100) return null;
|
|
2146
2159
|
let bigoLineIdx = -1;
|
|
2147
2160
|
for (let i = 0; i < yLines.length; i++) {
|
|
@@ -2363,9 +2376,9 @@ function detectHeadings(blocks, medianFontSize) {
|
|
|
2363
2376
|
if (/^\d+$/.test(text)) continue;
|
|
2364
2377
|
const ratio = block.style.fontSize / medianFontSize;
|
|
2365
2378
|
let level = 0;
|
|
2366
|
-
if (ratio >=
|
|
2367
|
-
else if (ratio >=
|
|
2368
|
-
else if (ratio >=
|
|
2379
|
+
if (ratio >= _chunk72LLOLFXcjs.HEADING_RATIO_H1) level = 1;
|
|
2380
|
+
else if (ratio >= _chunk72LLOLFXcjs.HEADING_RATIO_H2) level = 2;
|
|
2381
|
+
else if (ratio >= _chunk72LLOLFXcjs.HEADING_RATIO_H3) level = 3;
|
|
2369
2382
|
if (level > 0) {
|
|
2370
2383
|
block.type = "heading";
|
|
2371
2384
|
block.level = level;
|
|
@@ -2380,7 +2393,7 @@ function shouldDemoteTable(table) {
|
|
|
2380
2393
|
const t = c.text.trim();
|
|
2381
2394
|
return t.length > 0 && t.length <= 12 && !/[□■◆○●▶ㅇ<>]/.test(t);
|
|
2382
2395
|
}) && table.cells.slice(1).some((row) => row.some((c) => c.text.trim() !== ""))) return false;
|
|
2383
|
-
if (table.rows <= 3 && table.cols <= 3) {
|
|
2396
|
+
if (table.rows <= 3 && table.cols <= 3 && allText.length <= 200) {
|
|
2384
2397
|
const totalCells2 = table.rows * table.cols;
|
|
2385
2398
|
const emptyCells2 = totalCells2 - allCells.length;
|
|
2386
2399
|
if (emptyCells2 >= totalCells2 * 0.3) return true;
|
|
@@ -2941,7 +2954,7 @@ function extractBlocksWithGrids(items, pageNum, grids, horizontals, verticals) {
|
|
|
2941
2954
|
}
|
|
2942
2955
|
if (remaining.length > 0) {
|
|
2943
2956
|
const allY = remaining.map((i) => i.y);
|
|
2944
|
-
const pageH =
|
|
2957
|
+
const pageH = _chunk72LLOLFXcjs.safeMax.call(void 0, allY) - _chunk72LLOLFXcjs.safeMin.call(void 0, allY);
|
|
2945
2958
|
const groups = xyCutOrder(remaining, Math.max(15, pageH * 0.03));
|
|
2946
2959
|
const textBlocks = [];
|
|
2947
2960
|
for (const group of groups) {
|
|
@@ -3117,7 +3130,7 @@ function extractPageBlocksFallback(items, pageNum, fullPage = false) {
|
|
|
3117
3130
|
blocks.push({ type: "paragraph", text: tableText, pageNumber: pageNum, bbox, style: dominantStyle(items) });
|
|
3118
3131
|
} else {
|
|
3119
3132
|
const allY = items.map((i) => i.y);
|
|
3120
|
-
const pageHeight =
|
|
3133
|
+
const pageHeight = _chunk72LLOLFXcjs.safeMax.call(void 0, allY) - _chunk72LLOLFXcjs.safeMin.call(void 0, allY);
|
|
3121
3134
|
const gapThreshold = Math.max(15, pageHeight * 0.03);
|
|
3122
3135
|
const orderedGroups = proseCutX !== null ? splitTwoColumnProse(items, proseCutX) : xyCutOrder(items, gapThreshold);
|
|
3123
3136
|
for (const group of orderedGroups) {
|
|
@@ -3370,7 +3383,7 @@ async function loadPdfWithTimeout(buffer) {
|
|
|
3370
3383
|
new Promise((_, reject) => {
|
|
3371
3384
|
timer = setTimeout(() => {
|
|
3372
3385
|
loadingTask.destroy();
|
|
3373
|
-
reject(new (0,
|
|
3386
|
+
reject(new (0, _chunk72LLOLFXcjs.KordocError)("PDF \uB85C\uB529 \uD0C0\uC784\uC544\uC6C3 (30\uCD08 \uCD08\uACFC)"));
|
|
3374
3387
|
}, PDF_LOAD_TIMEOUT_MS);
|
|
3375
3388
|
})
|
|
3376
3389
|
]);
|
|
@@ -3383,7 +3396,7 @@ async function parsePdfDocument(buffer, options) {
|
|
|
3383
3396
|
const doc = await loadPdfWithTimeout(buffer);
|
|
3384
3397
|
try {
|
|
3385
3398
|
const pageCount = doc.numPages;
|
|
3386
|
-
if (pageCount === 0) throw new (0,
|
|
3399
|
+
if (pageCount === 0) throw new (0, _chunk72LLOLFXcjs.KordocError)("PDF\uC5D0 \uD398\uC774\uC9C0\uAC00 \uC5C6\uC2B5\uB2C8\uB2E4.");
|
|
3387
3400
|
const metadata = { pageCount };
|
|
3388
3401
|
await extractPdfMetadata(doc, metadata);
|
|
3389
3402
|
const blocks = [];
|
|
@@ -3443,11 +3456,11 @@ async function parsePdfDocument(buffer, options) {
|
|
|
3443
3456
|
pageText += pageText ? "\n" + t : t;
|
|
3444
3457
|
}
|
|
3445
3458
|
pageQuality.push(computePageQuality(i, pageText));
|
|
3446
|
-
if (totalTextBytes > MAX_TOTAL_TEXT) throw new (0,
|
|
3459
|
+
if (totalTextBytes > MAX_TOTAL_TEXT) throw new (0, _chunk72LLOLFXcjs.KordocError)("\uD14D\uC2A4\uD2B8 \uCD94\uCD9C \uD06C\uAE30 \uCD08\uACFC");
|
|
3447
3460
|
parsedPages++;
|
|
3448
3461
|
_optionalChain([options, 'optionalAccess', _36 => _36.onProgress, 'optionalCall', _37 => _37(parsedPages, totalTarget)]);
|
|
3449
3462
|
} catch (pageErr) {
|
|
3450
|
-
if (pageErr instanceof
|
|
3463
|
+
if (pageErr instanceof _chunk72LLOLFXcjs.KordocError) throw pageErr;
|
|
3451
3464
|
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" });
|
|
3452
3465
|
}
|
|
3453
3466
|
}
|
|
@@ -3515,7 +3528,7 @@ async function parsePdfDocument(buffer, options) {
|
|
|
3515
3528
|
detectKoreanListBlocks(blocks);
|
|
3516
3529
|
const outline = blocks.filter((b) => b.type === "heading" && b.level && b.text).map((b) => ({ level: b.level, text: b.text, pageNumber: b.pageNumber }));
|
|
3517
3530
|
sanitizeBlockControlChars(blocks);
|
|
3518
|
-
let markdown = cleanPdfText(
|
|
3531
|
+
let markdown = cleanPdfText(_chunk72LLOLFXcjs.blocksToMarkdown.call(void 0, blocks));
|
|
3519
3532
|
return {
|
|
3520
3533
|
markdown,
|
|
3521
3534
|
blocks,
|
|
@@ -3574,4 +3587,4 @@ async function extractPdfMetadataOnly(buffer) {
|
|
|
3574
3587
|
|
|
3575
3588
|
|
|
3576
3589
|
exports.cleanPdfText = cleanPdfText; exports.detectKoreanListBlocks = detectKoreanListBlocks; exports.detectTableCaptions = detectTableCaptions; exports.extractPdfMetadataOnly = extractPdfMetadataOnly; exports.mergeCrossPageTables = mergeCrossPageTables; exports.parsePdfDocument = parsePdfDocument; exports.removeHeaderFooterBlocks = removeHeaderFooterBlocks;
|
|
3577
|
-
//# sourceMappingURL=parser-
|
|
3590
|
+
//# sourceMappingURL=parser-YVRTKGKO.cjs.map
|