kordoc 3.8.1 → 3.8.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 +5 -0
- package/dist/{-LD4BZDDJ.js → -FEHSMPVO.js} +3 -3
- package/dist/{chunk-PELBIL4K.js → chunk-553VTUVP.js} +2 -2
- package/dist/{chunk-KT2BCHXI.js → chunk-DP37KF2X.js} +834 -822
- package/dist/chunk-DP37KF2X.js.map +1 -0
- package/dist/{chunk-IFYJFWD2.js → chunk-JHZUFBUV.js} +2 -2
- package/dist/{chunk-LFCS3UVG.cjs → chunk-YBPNKFJW.cjs} +2 -2
- package/dist/{chunk-LFCS3UVG.cjs.map → chunk-YBPNKFJW.cjs.map} +1 -1
- package/dist/cli.js +4 -4
- package/dist/index.cjs +946 -934
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +17 -8
- package/dist/index.d.ts +17 -8
- package/dist/index.js +833 -821
- package/dist/index.js.map +1 -1
- package/dist/mcp.js +3 -3
- package/dist/{parser-FFEBMLSH.js → parser-KNQDRLZQ.js} +60 -20
- package/dist/parser-KNQDRLZQ.js.map +1 -0
- package/dist/{parser-XEDROIM7.js → parser-NR2TYGO3.js} +60 -20
- package/dist/parser-NR2TYGO3.js.map +1 -0
- package/dist/{parser-IXK5V7YG.cjs → parser-NS4ZPD7B.cjs} +77 -35
- package/dist/parser-NS4ZPD7B.cjs.map +1 -0
- package/dist/{watch-MAWCDNFI.js → watch-XCWADLPU.js} +3 -3
- package/package.json +1 -1
- package/dist/chunk-KT2BCHXI.js.map +0 -1
- package/dist/parser-FFEBMLSH.js.map +0 -1
- package/dist/parser-IXK5V7YG.cjs.map +0 -1
- package/dist/parser-XEDROIM7.js.map +0 -1
- /package/dist/{-LD4BZDDJ.js.map → -FEHSMPVO.js.map} +0 -0
- /package/dist/{chunk-PELBIL4K.js.map → chunk-553VTUVP.js.map} +0 -0
- /package/dist/{chunk-IFYJFWD2.js.map → chunk-JHZUFBUV.js.map} +0 -0
- /package/dist/{watch-MAWCDNFI.js.map → watch-XCWADLPU.js.map} +0 -0
|
@@ -6,11 +6,13 @@
|
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
var
|
|
9
|
+
var _chunkYBPNKFJWcjs = require('./chunk-YBPNKFJW.cjs');
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
var _chunkDCZVOIEOcjs = require('./chunk-DCZVOIEO.cjs');
|
|
13
|
-
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
var _chunkGS7T56RPcjs = require('./chunk-GS7T56RP.cjs');
|
|
14
16
|
|
|
15
17
|
// src/pdf/line-extract.ts
|
|
16
18
|
var _pdfmjs = require('pdfjs-dist/legacy/build/pdf.mjs');
|
|
@@ -21,21 +23,30 @@ function extractLines(fnArray, argsArray) {
|
|
|
21
23
|
const horizontals = [];
|
|
22
24
|
const verticals = [];
|
|
23
25
|
let lineWidth = 1;
|
|
26
|
+
let ctm = [1, 0, 0, 1, 0, 0];
|
|
27
|
+
const ctmStack = [];
|
|
28
|
+
const applyCtm = (x, y) => [ctm[0] * x + ctm[2] * y + ctm[4], ctm[1] * x + ctm[3] * y + ctm[5]];
|
|
29
|
+
const ctmScale = () => (Math.hypot(ctm[0], ctm[1]) + Math.hypot(ctm[2], ctm[3])) / 2;
|
|
24
30
|
let currentPath = [];
|
|
25
31
|
let pathStartX = 0, pathStartY = 0;
|
|
26
32
|
let curX = 0, curY = 0;
|
|
27
|
-
function
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
33
|
+
function pushSeg(x1, y1, x2, y2) {
|
|
34
|
+
const [tx1, ty1] = applyCtm(x1, y1);
|
|
35
|
+
const [tx2, ty2] = applyCtm(x2, y2);
|
|
36
|
+
currentPath.push({ x1: tx1, y1: ty1, x2: tx2, y2: ty2 });
|
|
37
|
+
}
|
|
38
|
+
function pushRectangle(rx, ry, rw, rh) {
|
|
39
|
+
const effH = Math.abs(rh) * Math.hypot(ctm[2], ctm[3]);
|
|
40
|
+
const effW = Math.abs(rw) * Math.hypot(ctm[0], ctm[1]);
|
|
41
|
+
if (effH < ORIENTATION_TOL * 2) {
|
|
42
|
+
pushSeg(rx, ry + rh / 2, rx + rw, ry + rh / 2);
|
|
43
|
+
} else if (effW < ORIENTATION_TOL * 2) {
|
|
44
|
+
pushSeg(rx + rw / 2, ry, rx + rw / 2, ry + rh);
|
|
32
45
|
} else {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
{ x1: rx, y1: ry + rh, x2: rx, y2: ry }
|
|
38
|
-
);
|
|
46
|
+
pushSeg(rx, ry, rx + rw, ry);
|
|
47
|
+
pushSeg(rx + rw, ry, rx + rw, ry + rh);
|
|
48
|
+
pushSeg(rx + rw, ry + rh, rx, ry + rh);
|
|
49
|
+
pushSeg(rx, ry + rh, rx, ry);
|
|
39
50
|
}
|
|
40
51
|
}
|
|
41
52
|
function flushPath(isStroke) {
|
|
@@ -43,8 +54,9 @@ function extractLines(fnArray, argsArray) {
|
|
|
43
54
|
currentPath = [];
|
|
44
55
|
return;
|
|
45
56
|
}
|
|
57
|
+
const effWidth = lineWidth * ctmScale();
|
|
46
58
|
for (const seg of currentPath) {
|
|
47
|
-
classifyAndAdd(seg,
|
|
59
|
+
classifyAndAdd(seg, effWidth, horizontals, verticals);
|
|
48
60
|
}
|
|
49
61
|
currentPath = [];
|
|
50
62
|
}
|
|
@@ -55,6 +67,24 @@ function extractLines(fnArray, argsArray) {
|
|
|
55
67
|
case _pdfmjs.OPS.setLineWidth:
|
|
56
68
|
lineWidth = args[0] || 1;
|
|
57
69
|
break;
|
|
70
|
+
case _pdfmjs.OPS.save:
|
|
71
|
+
ctmStack.push(ctm.slice());
|
|
72
|
+
break;
|
|
73
|
+
case _pdfmjs.OPS.restore:
|
|
74
|
+
ctm = _nullishCoalesce(ctmStack.pop(), () => ( [1, 0, 0, 1, 0, 0]));
|
|
75
|
+
break;
|
|
76
|
+
case _pdfmjs.OPS.transform: {
|
|
77
|
+
const t = args;
|
|
78
|
+
ctm = [
|
|
79
|
+
ctm[0] * t[0] + ctm[2] * t[1],
|
|
80
|
+
ctm[1] * t[0] + ctm[3] * t[1],
|
|
81
|
+
ctm[0] * t[2] + ctm[2] * t[3],
|
|
82
|
+
ctm[1] * t[2] + ctm[3] * t[3],
|
|
83
|
+
ctm[0] * t[4] + ctm[2] * t[5] + ctm[4],
|
|
84
|
+
ctm[1] * t[4] + ctm[3] * t[5] + ctm[5]
|
|
85
|
+
];
|
|
86
|
+
break;
|
|
87
|
+
}
|
|
58
88
|
case _pdfmjs.OPS.constructPath: {
|
|
59
89
|
const arg0 = args[0];
|
|
60
90
|
if (Array.isArray(arg0)) {
|
|
@@ -69,16 +99,16 @@ function extractLines(fnArray, argsArray) {
|
|
|
69
99
|
pathStartY = curY;
|
|
70
100
|
} else if (subOp === _pdfmjs.OPS.lineTo) {
|
|
71
101
|
const x2 = coords[ci++], y2 = coords[ci++];
|
|
72
|
-
|
|
102
|
+
pushSeg(curX, curY, x2, y2);
|
|
73
103
|
curX = x2;
|
|
74
104
|
curY = y2;
|
|
75
105
|
} else if (subOp === _pdfmjs.OPS.rectangle) {
|
|
76
106
|
const rx = coords[ci++], ry = coords[ci++];
|
|
77
107
|
const rw = coords[ci++], rh = coords[ci++];
|
|
78
|
-
pushRectangle(
|
|
108
|
+
pushRectangle(rx, ry, rw, rh);
|
|
79
109
|
} else if (subOp === _pdfmjs.OPS.closePath) {
|
|
80
110
|
if (curX !== pathStartX || curY !== pathStartY) {
|
|
81
|
-
|
|
111
|
+
pushSeg(curX, curY, pathStartX, pathStartY);
|
|
82
112
|
}
|
|
83
113
|
curX = pathStartX;
|
|
84
114
|
curY = pathStartY;
|
|
@@ -104,7 +134,7 @@ function extractLines(fnArray, argsArray) {
|
|
|
104
134
|
pathStartY = curY;
|
|
105
135
|
} else if (drawOp === 1 /* lineTo */) {
|
|
106
136
|
const x2 = pathData[di++], y2 = pathData[di++];
|
|
107
|
-
|
|
137
|
+
pushSeg(curX, curY, x2, y2);
|
|
108
138
|
curX = x2;
|
|
109
139
|
curY = y2;
|
|
110
140
|
} else if (drawOp === 2 /* curveTo */) {
|
|
@@ -113,7 +143,7 @@ function extractLines(fnArray, argsArray) {
|
|
|
113
143
|
di += 4;
|
|
114
144
|
} else if (drawOp === 4 /* closePath */) {
|
|
115
145
|
if (curX !== pathStartX || curY !== pathStartY) {
|
|
116
|
-
|
|
146
|
+
pushSeg(curX, curY, pathStartX, pathStartY);
|
|
117
147
|
}
|
|
118
148
|
curX = pathStartX;
|
|
119
149
|
curY = pathStartY;
|
|
@@ -1847,14 +1877,14 @@ function isProseSpread(items) {
|
|
|
1847
1877
|
for (let i = 1; i < sorted.length; i++) {
|
|
1848
1878
|
gaps.push(sorted[i].x - (sorted[i - 1].x + sorted[i - 1].w));
|
|
1849
1879
|
}
|
|
1850
|
-
const maxGap =
|
|
1880
|
+
const maxGap = _chunkYBPNKFJWcjs.safeMax.call(void 0, gaps);
|
|
1851
1881
|
const avgLen = items.reduce((s, i) => s + i.text.length, 0) / items.length;
|
|
1852
1882
|
return maxGap < 40 && avgLen < 5;
|
|
1853
1883
|
}
|
|
1854
1884
|
function detectColumns(yLines) {
|
|
1855
1885
|
const allItems = yLines.flat();
|
|
1856
1886
|
if (allItems.length === 0) return null;
|
|
1857
|
-
const pageWidth =
|
|
1887
|
+
const pageWidth = _chunkYBPNKFJWcjs.safeMax.call(void 0, allItems.map((i) => i.x + i.w)) - _chunkYBPNKFJWcjs.safeMin.call(void 0, allItems.map((i) => i.x));
|
|
1858
1888
|
if (pageWidth < 100) return null;
|
|
1859
1889
|
let bigoLineIdx = -1;
|
|
1860
1890
|
for (let i = 0; i < yLines.length; i++) {
|
|
@@ -2076,9 +2106,9 @@ function detectHeadings(blocks, medianFontSize) {
|
|
|
2076
2106
|
if (/^\d+$/.test(text)) continue;
|
|
2077
2107
|
const ratio = block.style.fontSize / medianFontSize;
|
|
2078
2108
|
let level = 0;
|
|
2079
|
-
if (ratio >=
|
|
2080
|
-
else if (ratio >=
|
|
2081
|
-
else if (ratio >=
|
|
2109
|
+
if (ratio >= _chunkYBPNKFJWcjs.HEADING_RATIO_H1) level = 1;
|
|
2110
|
+
else if (ratio >= _chunkYBPNKFJWcjs.HEADING_RATIO_H2) level = 2;
|
|
2111
|
+
else if (ratio >= _chunkYBPNKFJWcjs.HEADING_RATIO_H3) level = 3;
|
|
2082
2112
|
if (level > 0) {
|
|
2083
2113
|
block.type = "heading";
|
|
2084
2114
|
block.level = level;
|
|
@@ -2597,7 +2627,7 @@ function extractBlocksWithGrids(items, pageNum, grids, horizontals, verticals) {
|
|
|
2597
2627
|
}
|
|
2598
2628
|
if (remaining.length > 0) {
|
|
2599
2629
|
const allY = remaining.map((i) => i.y);
|
|
2600
|
-
const pageH =
|
|
2630
|
+
const pageH = _chunkYBPNKFJWcjs.safeMax.call(void 0, allY) - _chunkYBPNKFJWcjs.safeMin.call(void 0, allY);
|
|
2601
2631
|
const groups = xyCutOrder(remaining, Math.max(15, pageH * 0.03));
|
|
2602
2632
|
const textBlocks = [];
|
|
2603
2633
|
for (const group of groups) {
|
|
@@ -2726,7 +2756,7 @@ function extractPageBlocksFallback(items, pageNum) {
|
|
|
2726
2756
|
blocks.push({ type: "paragraph", text: tableText, pageNumber: pageNum, bbox, style: dominantStyle(items) });
|
|
2727
2757
|
} else {
|
|
2728
2758
|
const allY = items.map((i) => i.y);
|
|
2729
|
-
const pageHeight =
|
|
2759
|
+
const pageHeight = _chunkYBPNKFJWcjs.safeMax.call(void 0, allY) - _chunkYBPNKFJWcjs.safeMin.call(void 0, allY);
|
|
2730
2760
|
const gapThreshold = Math.max(15, pageHeight * 0.03);
|
|
2731
2761
|
const orderedGroups = xyCutOrder(items, gapThreshold);
|
|
2732
2762
|
for (const group of orderedGroups) {
|
|
@@ -2949,16 +2979,28 @@ g.pdfjsWorker = pdfjsWorker;
|
|
|
2949
2979
|
|
|
2950
2980
|
// src/pdf/parser.ts
|
|
2951
2981
|
|
|
2982
|
+
var _module = require('module');
|
|
2983
|
+
var _path = require('path');
|
|
2952
2984
|
_pdfmjs.GlobalWorkerOptions.workerSrc = "";
|
|
2953
2985
|
var MAX_PAGES = 5e3;
|
|
2954
2986
|
var MAX_TOTAL_TEXT = 100 * 1024 * 1024;
|
|
2955
2987
|
var PDF_LOAD_TIMEOUT_MS = 3e4;
|
|
2988
|
+
var pdfjsAssets = {};
|
|
2989
|
+
try {
|
|
2990
|
+
const _require = _module.createRequire.call(void 0, _chunkGS7T56RPcjs.importMetaUrl);
|
|
2991
|
+
const pkgDir = _path.dirname.call(void 0, _require.resolve("pdfjs-dist/package.json"));
|
|
2992
|
+
pdfjsAssets.cMapUrl = _path.join.call(void 0, pkgDir, "cmaps") + "/";
|
|
2993
|
+
pdfjsAssets.cMapPacked = true;
|
|
2994
|
+
pdfjsAssets.standardFontDataUrl = _path.join.call(void 0, pkgDir, "standard_fonts") + "/";
|
|
2995
|
+
} catch (e2) {
|
|
2996
|
+
}
|
|
2956
2997
|
async function loadPdfWithTimeout(buffer) {
|
|
2957
2998
|
const loadingTask = _pdfmjs.getDocument.call(void 0, {
|
|
2958
2999
|
data: new Uint8Array(buffer),
|
|
2959
3000
|
useSystemFonts: true,
|
|
2960
3001
|
disableFontFace: true,
|
|
2961
|
-
isEvalSupported: false
|
|
3002
|
+
isEvalSupported: false,
|
|
3003
|
+
...pdfjsAssets
|
|
2962
3004
|
});
|
|
2963
3005
|
let timer;
|
|
2964
3006
|
try {
|
|
@@ -2967,7 +3009,7 @@ async function loadPdfWithTimeout(buffer) {
|
|
|
2967
3009
|
new Promise((_, reject) => {
|
|
2968
3010
|
timer = setTimeout(() => {
|
|
2969
3011
|
loadingTask.destroy();
|
|
2970
|
-
reject(new (0,
|
|
3012
|
+
reject(new (0, _chunkYBPNKFJWcjs.KordocError)("PDF \uB85C\uB529 \uD0C0\uC784\uC544\uC6C3 (30\uCD08 \uCD08\uACFC)"));
|
|
2971
3013
|
}, PDF_LOAD_TIMEOUT_MS);
|
|
2972
3014
|
})
|
|
2973
3015
|
]);
|
|
@@ -2980,7 +3022,7 @@ async function parsePdfDocument(buffer, options) {
|
|
|
2980
3022
|
const doc = await loadPdfWithTimeout(buffer);
|
|
2981
3023
|
try {
|
|
2982
3024
|
const pageCount = doc.numPages;
|
|
2983
|
-
if (pageCount === 0) throw new (0,
|
|
3025
|
+
if (pageCount === 0) throw new (0, _chunkYBPNKFJWcjs.KordocError)("PDF\uC5D0 \uD398\uC774\uC9C0\uAC00 \uC5C6\uC2B5\uB2C8\uB2E4.");
|
|
2984
3026
|
const metadata = { pageCount };
|
|
2985
3027
|
await extractPdfMetadata(doc, metadata);
|
|
2986
3028
|
const blocks = [];
|
|
@@ -3040,11 +3082,11 @@ async function parsePdfDocument(buffer, options) {
|
|
|
3040
3082
|
pageText += pageText ? "\n" + t : t;
|
|
3041
3083
|
}
|
|
3042
3084
|
pageQuality.push(computePageQuality(i, pageText));
|
|
3043
|
-
if (totalTextBytes > MAX_TOTAL_TEXT) throw new (0,
|
|
3085
|
+
if (totalTextBytes > MAX_TOTAL_TEXT) throw new (0, _chunkYBPNKFJWcjs.KordocError)("\uD14D\uC2A4\uD2B8 \uCD94\uCD9C \uD06C\uAE30 \uCD08\uACFC");
|
|
3044
3086
|
parsedPages++;
|
|
3045
3087
|
_optionalChain([options, 'optionalAccess', _27 => _27.onProgress, 'optionalCall', _28 => _28(parsedPages, totalTarget)]);
|
|
3046
3088
|
} catch (pageErr) {
|
|
3047
|
-
if (pageErr instanceof
|
|
3089
|
+
if (pageErr instanceof _chunkYBPNKFJWcjs.KordocError) throw pageErr;
|
|
3048
3090
|
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" });
|
|
3049
3091
|
}
|
|
3050
3092
|
}
|
|
@@ -3059,7 +3101,7 @@ async function parsePdfDocument(buffer, options) {
|
|
|
3059
3101
|
const ocrMarkdown = ocrBlocks.map((b) => b.text || "").filter(Boolean).join("\n\n");
|
|
3060
3102
|
return { markdown: ocrMarkdown, blocks: ocrBlocks, metadata, warnings, isImageBased: true, pageQuality, qualitySummary: summarizeDocumentQuality(pageQuality) };
|
|
3061
3103
|
}
|
|
3062
|
-
} catch (
|
|
3104
|
+
} catch (e3) {
|
|
3063
3105
|
}
|
|
3064
3106
|
}
|
|
3065
3107
|
isImageBased = true;
|
|
@@ -3112,7 +3154,7 @@ async function parsePdfDocument(buffer, options) {
|
|
|
3112
3154
|
detectKoreanListBlocks(blocks);
|
|
3113
3155
|
const outline = blocks.filter((b) => b.type === "heading" && b.level && b.text).map((b) => ({ level: b.level, text: b.text, pageNumber: b.pageNumber }));
|
|
3114
3156
|
sanitizeBlockControlChars(blocks);
|
|
3115
|
-
let markdown = cleanPdfText(
|
|
3157
|
+
let markdown = cleanPdfText(_chunkYBPNKFJWcjs.blocksToMarkdown.call(void 0, blocks));
|
|
3116
3158
|
return {
|
|
3117
3159
|
markdown,
|
|
3118
3160
|
blocks,
|
|
@@ -3142,7 +3184,7 @@ async function extractPdfMetadata(doc, metadata) {
|
|
|
3142
3184
|
}
|
|
3143
3185
|
if (typeof info.CreationDate === "string") metadata.createdAt = parsePdfDate(info.CreationDate);
|
|
3144
3186
|
if (typeof info.ModDate === "string") metadata.modifiedAt = parsePdfDate(info.ModDate);
|
|
3145
|
-
} catch (
|
|
3187
|
+
} catch (e4) {
|
|
3146
3188
|
}
|
|
3147
3189
|
}
|
|
3148
3190
|
function parsePdfDate(dateStr) {
|
|
@@ -3171,4 +3213,4 @@ async function extractPdfMetadataOnly(buffer) {
|
|
|
3171
3213
|
|
|
3172
3214
|
|
|
3173
3215
|
exports.cleanPdfText = cleanPdfText; exports.detectKoreanListBlocks = detectKoreanListBlocks; exports.detectTableCaptions = detectTableCaptions; exports.extractPdfMetadataOnly = extractPdfMetadataOnly; exports.mergeCrossPageTables = mergeCrossPageTables; exports.parsePdfDocument = parsePdfDocument; exports.removeHeaderFooterBlocks = removeHeaderFooterBlocks;
|
|
3174
|
-
//# sourceMappingURL=parser-
|
|
3216
|
+
//# sourceMappingURL=parser-NS4ZPD7B.cjs.map
|