kordoc 4.14.2 → 4.14.3
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 +38 -5
- package/dist/{-AQKXLFIM.js → -7XBPXCXN.js} +13 -11
- package/dist/{chunk-FOJZNMMK.js → chunk-2LQGSDZ6.js} +1 -1
- package/dist/chunk-2LQGSDZ6.js.map +1 -0
- package/dist/chunk-4R67INKT.js +1002 -0
- package/dist/chunk-4R67INKT.js.map +1 -0
- package/dist/{chunk-ILU76UF3.js → chunk-4RJ5D7MT.js} +2 -2
- package/dist/chunk-4RJ5D7MT.js.map +1 -0
- package/dist/{chunk-EQZI77PP.cjs → chunk-5VVS2QIJ.cjs} +3 -3
- package/dist/{chunk-EQZI77PP.cjs.map → chunk-5VVS2QIJ.cjs.map} +1 -1
- package/dist/{chunk-3DUADAY2.js → chunk-A275ZQLX.js} +209 -87
- package/dist/chunk-A275ZQLX.js.map +1 -0
- package/dist/{chunk-EISO3POT.js → chunk-CVEERPMP.js} +788 -194
- package/dist/chunk-CVEERPMP.js.map +1 -0
- package/dist/{chunk-ZWD734EY.js → chunk-D6KQKMU3.js} +2 -2
- package/dist/{chunk-QOMNEWCQ.cjs → chunk-EBZUZC6F.cjs} +305 -31
- package/dist/chunk-EBZUZC6F.cjs.map +1 -0
- package/dist/{chunk-HR2XNERB.cjs → chunk-EMGF6EEV.cjs} +2 -2
- package/dist/{chunk-HR2XNERB.cjs.map → chunk-EMGF6EEV.cjs.map} +1 -1
- package/dist/{chunk-GDW4YP7K.js → chunk-FAZR34CA.js} +2 -2
- package/dist/{chunk-TNCKOL2O.js → chunk-GTINVM5K.js} +2 -2
- package/dist/{chunk-L7DMSMAG.cjs → chunk-HX4UUF7Y.cjs} +1 -1
- package/dist/chunk-HX4UUF7Y.cjs.map +1 -0
- package/dist/{chunk-UET462HB.js → chunk-I4NNYWIR.js} +2 -2
- package/dist/chunk-IH56ZISC.js +620 -0
- package/dist/chunk-IH56ZISC.js.map +1 -0
- package/dist/{chunk-EDNJLUSE.js → chunk-IHZEFW4L.js} +2 -2
- package/dist/chunk-IW2CB755.cjs +1002 -0
- package/dist/chunk-IW2CB755.cjs.map +1 -0
- package/dist/{chunk-ZWOFQRIB.js → chunk-JCVIOLBF.js} +3 -3
- package/dist/{chunk-JQEFP45L.js → chunk-L5EH2NVO.js} +2 -2
- package/dist/{chunk-247ANM72.cjs → chunk-NOAQRCV6.cjs} +219 -97
- package/dist/chunk-NOAQRCV6.cjs.map +1 -0
- package/dist/{chunk-7IAQ4HOK.js → chunk-NQCUAGLR.js} +1 -1
- package/dist/chunk-NQCUAGLR.js.map +1 -0
- package/dist/{chunk-NS55SM7A.js → chunk-O2PGQNYE.js} +2 -2
- package/dist/{chunk-QC5T6D4J.js → chunk-QGW7NMTX.js} +299 -25
- package/dist/chunk-QGW7NMTX.js.map +1 -0
- package/dist/{chunk-A7QC2ZVP.js → chunk-UVVEBI22.js} +209 -87
- package/dist/chunk-UVVEBI22.js.map +1 -0
- package/dist/chunk-VJHAUMCF.js +949 -0
- package/dist/chunk-VJHAUMCF.js.map +1 -0
- package/dist/{chunk-C7FQBSON.js → chunk-VNFJPTU4.js} +2 -2
- package/dist/{chunk-VQ5W4MYO.js → chunk-VYOGXNQ3.js} +298 -24
- package/dist/chunk-VYOGXNQ3.js.map +1 -0
- package/dist/{chunk-DOGPOY4B.js → chunk-WB5LW52Z.js} +2 -2
- package/dist/{chunk-TSFS5VKD.js → chunk-YGBZABI4.js} +332 -141
- package/dist/chunk-YGBZABI4.js.map +1 -0
- package/dist/chunks-I7TEMJXH.js +10 -0
- package/dist/cli.js +228 -97
- package/dist/cli.js.map +1 -1
- package/dist/{formula-PJJ6S3Z2.cjs → formula-CPO2TZGB.cjs} +9 -9
- package/dist/{formula-PJJ6S3Z2.cjs.map → formula-CPO2TZGB.cjs.map} +1 -1
- package/dist/{formula-5S7WWXGH.js → formula-NOIDZEBA.js} +4 -4
- package/dist/{formula-JGFTXWYT.js → formula-X44GV7TN.js} +3 -3
- package/dist/{image-ocr-WCAYXLOA.js → image-ocr-72RAR4WR.js} +34 -16
- package/dist/image-ocr-72RAR4WR.js.map +1 -0
- package/dist/{image-ocr-FLIL7MGN.js → image-ocr-R6W6A75P.js} +32 -14
- package/dist/image-ocr-R6W6A75P.js.map +1 -0
- package/dist/{image-ocr-ZTYAGV3W.cjs → image-ocr-SUGT64ZM.cjs} +36 -18
- package/dist/image-ocr-SUGT64ZM.cjs.map +1 -0
- package/dist/index.cjs +2416 -1184
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +62 -25
- package/dist/index.d.ts +62 -25
- package/dist/index.js +1853 -621
- package/dist/index.js.map +1 -1
- package/dist/mcp.js +74 -53
- package/dist/mcp.js.map +1 -1
- package/dist/{model-bundle-FSPZZ2EM.js → model-bundle-57CLEBCO.js} +5 -5
- package/dist/{models-CJPAQK5R.js → models-7ELIFTD7.js} +5 -5
- package/dist/{parser-SCUTZAIJ.js → parser-4NKAYWAX.js} +261 -241
- package/dist/parser-4NKAYWAX.js.map +1 -0
- package/dist/{parser-A4TMPJAM.js → parser-HWFQRSUQ.js} +261 -241
- package/dist/parser-HWFQRSUQ.js.map +1 -0
- package/dist/{parser-VCXE4I5A.cjs → parser-RANGXGBD.cjs} +289 -269
- package/dist/parser-RANGXGBD.cjs.map +1 -0
- package/dist/pdf-ocr-BNC34MNU.js +13 -0
- package/dist/pdf-ocr-QX2GB33Q.js +16 -0
- package/dist/pdf-ocr-VHSFACH7.cjs +14 -0
- package/dist/{pdf-ocr-MBZZ57LD.cjs.map → pdf-ocr-VHSFACH7.cjs.map} +1 -1
- package/dist/{profile-io-LBM263K7.js → profile-io-V52PL5ZO.js} +3 -3
- package/dist/{rasterize-46RG4ZF6.js → rasterize-ZIGLJDOG.js} +3 -3
- package/dist/redact-TIQEQI3M.js +18 -0
- package/dist/redact-doc-KXZ3TZAG.js +1216 -0
- package/dist/redact-doc-KXZ3TZAG.js.map +1 -0
- package/dist/{render-NGP5T24S.js → render-U5PE6V2E.js} +7 -7
- package/dist/seal-DNXJBILR.js +10 -0
- package/dist/{setup-AU4OCHNH.js → setup-YRDM4ODP.js} +3 -3
- package/dist/visual-5XWMA4EV.js +19 -0
- package/dist/{watch-MKPUCPXM.js → watch-5IOLBATT.js} +12 -12
- package/package.json +2 -2
- package/dist/chunk-247ANM72.cjs.map +0 -1
- package/dist/chunk-3DUADAY2.js.map +0 -1
- package/dist/chunk-422427XJ.cjs +0 -571
- package/dist/chunk-422427XJ.cjs.map +0 -1
- package/dist/chunk-7IAQ4HOK.js.map +0 -1
- package/dist/chunk-A7QC2ZVP.js.map +0 -1
- package/dist/chunk-DZIXKL7E.js +0 -145
- package/dist/chunk-DZIXKL7E.js.map +0 -1
- package/dist/chunk-EISO3POT.js.map +0 -1
- package/dist/chunk-EP7KOI2V.js +0 -571
- package/dist/chunk-EP7KOI2V.js.map +0 -1
- package/dist/chunk-FOJZNMMK.js.map +0 -1
- package/dist/chunk-ILU76UF3.js.map +0 -1
- package/dist/chunk-KVWV4ULP.js +0 -516
- package/dist/chunk-KVWV4ULP.js.map +0 -1
- package/dist/chunk-L7DMSMAG.cjs.map +0 -1
- package/dist/chunk-QC5T6D4J.js.map +0 -1
- package/dist/chunk-QOMNEWCQ.cjs.map +0 -1
- package/dist/chunk-TSFS5VKD.js.map +0 -1
- package/dist/chunk-VQ5W4MYO.js.map +0 -1
- package/dist/chunks-SX77P5CV.js +0 -10
- package/dist/image-ocr-FLIL7MGN.js.map +0 -1
- package/dist/image-ocr-WCAYXLOA.js.map +0 -1
- package/dist/image-ocr-ZTYAGV3W.cjs.map +0 -1
- package/dist/parser-A4TMPJAM.js.map +0 -1
- package/dist/parser-SCUTZAIJ.js.map +0 -1
- package/dist/parser-VCXE4I5A.cjs.map +0 -1
- package/dist/pdf-ocr-76SAUXMZ.js +0 -13
- package/dist/pdf-ocr-CPU55CVF.js +0 -16
- package/dist/pdf-ocr-MBZZ57LD.cjs +0 -14
- package/dist/redact-7ILEAUTS.js +0 -12
- package/dist/seal-RGUPOLXD.js +0 -10
- package/dist/visual-NZLYIYEM.js +0 -19
- /package/dist/{-AQKXLFIM.js.map → -7XBPXCXN.js.map} +0 -0
- /package/dist/{chunk-ZWD734EY.js.map → chunk-D6KQKMU3.js.map} +0 -0
- /package/dist/{chunk-GDW4YP7K.js.map → chunk-FAZR34CA.js.map} +0 -0
- /package/dist/{chunk-TNCKOL2O.js.map → chunk-GTINVM5K.js.map} +0 -0
- /package/dist/{chunk-UET462HB.js.map → chunk-I4NNYWIR.js.map} +0 -0
- /package/dist/{chunk-EDNJLUSE.js.map → chunk-IHZEFW4L.js.map} +0 -0
- /package/dist/{chunk-ZWOFQRIB.js.map → chunk-JCVIOLBF.js.map} +0 -0
- /package/dist/{chunk-JQEFP45L.js.map → chunk-L5EH2NVO.js.map} +0 -0
- /package/dist/{chunk-NS55SM7A.js.map → chunk-O2PGQNYE.js.map} +0 -0
- /package/dist/{chunk-C7FQBSON.js.map → chunk-VNFJPTU4.js.map} +0 -0
- /package/dist/{chunk-DOGPOY4B.js.map → chunk-WB5LW52Z.js.map} +0 -0
- /package/dist/{chunks-SX77P5CV.js.map → chunks-I7TEMJXH.js.map} +0 -0
- /package/dist/{formula-5S7WWXGH.js.map → formula-NOIDZEBA.js.map} +0 -0
- /package/dist/{formula-JGFTXWYT.js.map → formula-X44GV7TN.js.map} +0 -0
- /package/dist/{model-bundle-FSPZZ2EM.js.map → model-bundle-57CLEBCO.js.map} +0 -0
- /package/dist/{models-CJPAQK5R.js.map → models-7ELIFTD7.js.map} +0 -0
- /package/dist/{pdf-ocr-76SAUXMZ.js.map → pdf-ocr-BNC34MNU.js.map} +0 -0
- /package/dist/{pdf-ocr-CPU55CVF.js.map → pdf-ocr-QX2GB33Q.js.map} +0 -0
- /package/dist/{profile-io-LBM263K7.js.map → profile-io-V52PL5ZO.js.map} +0 -0
- /package/dist/{rasterize-46RG4ZF6.js.map → rasterize-ZIGLJDOG.js.map} +0 -0
- /package/dist/{redact-7ILEAUTS.js.map → redact-TIQEQI3M.js.map} +0 -0
- /package/dist/{render-NGP5T24S.js.map → render-U5PE6V2E.js.map} +0 -0
- /package/dist/{seal-RGUPOLXD.js.map → seal-DNXJBILR.js.map} +0 -0
- /package/dist/{setup-AU4OCHNH.js.map → setup-YRDM4ODP.js.map} +0 -0
- /package/dist/{visual-NZLYIYEM.js.map → visual-5XWMA4EV.js.map} +0 -0
- /package/dist/{watch-MKPUCPXM.js.map → watch-5IOLBATT.js.map} +0 -0
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class;
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
|
|
5
|
+
var _chunkEBZUZC6Fcjs = require('./chunk-EBZUZC6F.cjs');
|
|
5
6
|
|
|
6
7
|
|
|
7
8
|
var _chunkDCZVOIEOcjs = require('./chunk-DCZVOIEO.cjs');
|
|
@@ -18,12 +19,18 @@ var _chunkDCZVOIEOcjs = require('./chunk-DCZVOIEO.cjs');
|
|
|
18
19
|
|
|
19
20
|
|
|
20
21
|
|
|
21
|
-
var _chunk247ANM72cjs = require('./chunk-247ANM72.cjs');
|
|
22
|
-
require('./chunk-L7DMSMAG.cjs');
|
|
23
22
|
|
|
24
23
|
|
|
25
24
|
|
|
26
|
-
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
var _chunkNOAQRCV6cjs = require('./chunk-NOAQRCV6.cjs');
|
|
29
|
+
require('./chunk-HX4UUF7Y.cjs');
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
var _chunkEMGF6EEVcjs = require('./chunk-EMGF6EEV.cjs');
|
|
27
34
|
|
|
28
35
|
|
|
29
36
|
var _chunkGS7T56RPcjs = require('./chunk-GS7T56RP.cjs');
|
|
@@ -110,7 +117,7 @@ function toRgba(img) {
|
|
|
110
117
|
}
|
|
111
118
|
return null;
|
|
112
119
|
}
|
|
113
|
-
async function extractPageImages(page, fnArray, argsArray, pageNumber, state, warnings) {
|
|
120
|
+
async function extractPageImages(page, fnArray, argsArray, pageNumber, state, warnings, withBytes = true) {
|
|
114
121
|
const blocks = [];
|
|
115
122
|
const images = [];
|
|
116
123
|
const pageSeenIds = /* @__PURE__ */ new Set();
|
|
@@ -149,12 +156,14 @@ async function extractPageImages(page, fnArray, argsArray, pageNumber, state, wa
|
|
|
149
156
|
if (state.seen.has(hash)) continue;
|
|
150
157
|
const rgba = toRgba(imgData);
|
|
151
158
|
if (!rgba) continue;
|
|
152
|
-
const png = _chunkQOMNEWCQcjs.encodePng.call(void 0, w, h, rgba);
|
|
153
159
|
state.imageIndex++;
|
|
154
|
-
state.totalBytes += png.length;
|
|
155
160
|
const filename = `image_${String(state.imageIndex).padStart(3, "0")}.png`;
|
|
156
161
|
state.seen.set(hash, filename);
|
|
157
|
-
|
|
162
|
+
if (withBytes) {
|
|
163
|
+
const png = _chunkEBZUZC6Fcjs.encodePng.call(void 0, w, h, rgba);
|
|
164
|
+
state.totalBytes += png.length;
|
|
165
|
+
images.push({ filename, data: png, mimeType: "image/png" });
|
|
166
|
+
}
|
|
158
167
|
blocks.push({ type: "image", text: filename, pageNumber });
|
|
159
168
|
}
|
|
160
169
|
return { blocks, images };
|
|
@@ -325,232 +334,241 @@ function summarizeDocumentQuality(pages) {
|
|
|
325
334
|
};
|
|
326
335
|
}
|
|
327
336
|
|
|
337
|
+
// src/pdf/table-parts.ts
|
|
338
|
+
var PART_COL_TOL = 1;
|
|
339
|
+
function anchorsOf(table) {
|
|
340
|
+
const out = [];
|
|
341
|
+
const covered = /* @__PURE__ */ new Set();
|
|
342
|
+
for (let r = 0; r < table.rows; r++) {
|
|
343
|
+
for (let c = 0; c < table.cols; c++) {
|
|
344
|
+
if (covered.has(r * 1e5 + c)) continue;
|
|
345
|
+
const cell = _optionalChain([table, 'access', _7 => _7.cells, 'access', _8 => _8[r], 'optionalAccess', _9 => _9[c]]);
|
|
346
|
+
if (!cell) continue;
|
|
347
|
+
out.push({ r, c, rs: cell.rowSpan, cs: cell.colSpan, cell });
|
|
348
|
+
for (let dr = 0; dr < cell.rowSpan; dr++) {
|
|
349
|
+
for (let dc = 0; dc < cell.colSpan; dc++) if (dr || dc) covered.add((r + dr) * 1e5 + (c + dc));
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
return out;
|
|
354
|
+
}
|
|
355
|
+
function unionCoords(a, b) {
|
|
356
|
+
const out = [...a];
|
|
357
|
+
for (const v of b) if (!a.some((x) => Math.abs(x - v) <= PART_COL_TOL)) out.push(v);
|
|
358
|
+
return out.sort((x, y) => x - y);
|
|
359
|
+
}
|
|
360
|
+
var indexOf = (coords, x) => {
|
|
361
|
+
let best = -1, bestD = Infinity;
|
|
362
|
+
for (let i = 0; i < coords.length; i++) {
|
|
363
|
+
const d = Math.abs(coords[i] - x);
|
|
364
|
+
if (d < bestD) {
|
|
365
|
+
bestD = d;
|
|
366
|
+
best = i;
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
return bestD <= PART_COL_TOL ? best : -1;
|
|
370
|
+
};
|
|
371
|
+
var rowText = (anchors, r) => anchors.filter((a) => a.r === r).map((a) => a.cell.text.replace(/\s+/g, "")).join("|");
|
|
372
|
+
function joinSplitParts(prev, pcx, curr, ccx) {
|
|
373
|
+
if (pcx.length !== prev.cols + 1 || ccx.length !== curr.cols + 1) return null;
|
|
374
|
+
const U = unionCoords(pcx, ccx);
|
|
375
|
+
const cols = U.length - 1;
|
|
376
|
+
if (cols < 1) return null;
|
|
377
|
+
const pa = anchorsOf(prev), ca = anchorsOf(curr);
|
|
378
|
+
let skip = 0;
|
|
379
|
+
while (skip < Math.min(3, curr.rows - 1, prev.rows) && rowText(ca, skip) !== "" && rowText(ca, skip) === rowText(pa, skip)) skip++;
|
|
380
|
+
const rows = prev.rows + curr.rows - skip;
|
|
381
|
+
const grid = Array.from({ length: rows }, () => Array.from({ length: cols }, () => ({ text: "", colSpan: 1, rowSpan: 1 })));
|
|
382
|
+
const owner = Array.from({ length: rows }, () => new Array(cols).fill(null));
|
|
383
|
+
const place = (a, x, rowOff) => {
|
|
384
|
+
const c1 = indexOf(U, x[a.c]), c2 = indexOf(U, x[a.c + a.cs]);
|
|
385
|
+
if (c1 < 0 || c2 <= c1) return false;
|
|
386
|
+
const r = a.r + rowOff;
|
|
387
|
+
const placed = { r, c: c1, rs: a.rs, cs: c2 - c1, cell: a.cell };
|
|
388
|
+
for (let dr = 0; dr < a.rs; dr++) for (let dc = c1; dc < c2; dc++) {
|
|
389
|
+
if (r + dr < rows) owner[r + dr][dc] = placed;
|
|
390
|
+
}
|
|
391
|
+
grid[r][c1] = { ...a.cell, colSpan: c2 - c1, rowSpan: a.rs };
|
|
392
|
+
const lines = _chunkNOAQRCV6cjs.CELL_LINES.get(a.cell);
|
|
393
|
+
if (lines) _chunkNOAQRCV6cjs.CELL_LINES.set(grid[r][c1], lines);
|
|
394
|
+
if (_chunkNOAQRCV6cjs.IMAGE_CELLS.has(a.cell)) _chunkNOAQRCV6cjs.IMAGE_CELLS.add(grid[r][c1]);
|
|
395
|
+
return true;
|
|
396
|
+
};
|
|
397
|
+
for (const a of pa) if (!_chunkNOAQRCV6cjs.FILLER_CELLS.has(a.cell) && !place(a, pcx, 0)) return null;
|
|
398
|
+
for (const a of ca) {
|
|
399
|
+
if (a.r < skip || _chunkNOAQRCV6cjs.FILLER_CELLS.has(a.cell)) continue;
|
|
400
|
+
if (!place(a, ccx, prev.rows - skip)) return null;
|
|
401
|
+
}
|
|
402
|
+
const first = prev.rows;
|
|
403
|
+
for (let c = 0; c < cols; c++) {
|
|
404
|
+
const above = _optionalChain([owner, 'access', _10 => _10[first - 1], 'optionalAccess', _11 => _11[c]]);
|
|
405
|
+
if (!above) continue;
|
|
406
|
+
let r = first;
|
|
407
|
+
while (r < rows && owner[r][c] === null) r++;
|
|
408
|
+
if (r === first) continue;
|
|
409
|
+
const span = r - first;
|
|
410
|
+
let ok = true;
|
|
411
|
+
for (let dc = above.c; dc < above.c + above.cs && ok; dc++) {
|
|
412
|
+
for (let rr = first; rr < first + span; rr++) if (owner[rr][dc] !== null) {
|
|
413
|
+
ok = false;
|
|
414
|
+
break;
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
if (!ok) continue;
|
|
418
|
+
const newRs = above.rs + span;
|
|
419
|
+
grid[above.r][above.c].rowSpan = newRs;
|
|
420
|
+
const grown = { ...above, rs: newRs };
|
|
421
|
+
for (let rr = above.r; rr < above.r + newRs; rr++) for (let dc = above.c; dc < above.c + above.cs; dc++) owner[rr][dc] = grown;
|
|
422
|
+
}
|
|
423
|
+
for (let r = 0; r < rows; r++) for (let c = 0; c < cols; c++) if (owner[r][c] === null) _chunkNOAQRCV6cjs.FILLER_CELLS.add(grid[r][c]);
|
|
424
|
+
const table = { rows, cols, cells: grid, hasHeader: prev.hasHeader, ...prev.caption ? { caption: prev.caption } : {} };
|
|
425
|
+
if (rows > prev.rows) mergeSplitRow(table, owner, prev.rows, U);
|
|
426
|
+
return { table, colXs: U };
|
|
427
|
+
}
|
|
428
|
+
var FULL_LINE_TOL = 1;
|
|
429
|
+
var FULL_LINE_MIN_FRAC = 0.5;
|
|
430
|
+
var FULL_LINE_EDGE_MIN = 12;
|
|
431
|
+
var SINGLE_LINE_WORD_GAP = 3.5;
|
|
432
|
+
var SHORT_LINE_GAP = 1.5;
|
|
433
|
+
function continuesAcross(u, d, x1, x2) {
|
|
434
|
+
const U = _chunkNOAQRCV6cjs.CELL_LINES.get(u), D = _chunkNOAQRCV6cjs.CELL_LINES.get(d);
|
|
435
|
+
if (!_optionalChain([U, 'optionalAccess', _12 => _12.length]) || !_optionalChain([D, 'optionalAccess', _13 => _13.length])) return false;
|
|
436
|
+
const last = U[U.length - 1];
|
|
437
|
+
const fs = last.h || 10;
|
|
438
|
+
let minL = Infinity, maxR = -Infinity;
|
|
439
|
+
for (const l of U) {
|
|
440
|
+
minL = Math.min(minL, l.l);
|
|
441
|
+
maxR = Math.max(maxR, l.r);
|
|
442
|
+
}
|
|
443
|
+
for (const l of D) {
|
|
444
|
+
minL = Math.min(minL, l.l);
|
|
445
|
+
maxR = Math.max(maxR, l.r);
|
|
446
|
+
}
|
|
447
|
+
if (maxR - last.r > FULL_LINE_TOL * fs) return false;
|
|
448
|
+
if (U.length === 1 && x2 - last.r > Math.max(FULL_LINE_EDGE_MIN, SINGLE_LINE_WORD_GAP * fs)) return false;
|
|
449
|
+
if (last.r - last.l < FULL_LINE_MIN_FRAC * (x2 - x1)) return false;
|
|
450
|
+
const leftAligned = (l) => l.l - minL <= fs && maxR - l.r > SHORT_LINE_GAP * fs;
|
|
451
|
+
return U.some(leftAligned) || D.some(leftAligned);
|
|
452
|
+
}
|
|
453
|
+
function mergeSplitRow(table, owner, first, colXs) {
|
|
454
|
+
const last = first - 1;
|
|
455
|
+
const pairs = [];
|
|
456
|
+
for (let c = 0; c < table.cols; ) {
|
|
457
|
+
const a = owner[last][c], b = owner[first][c];
|
|
458
|
+
if (!a || !b) return;
|
|
459
|
+
if (a !== b) {
|
|
460
|
+
if (a.c !== b.c || a.cs !== b.cs || a.r + a.rs - 1 !== last || b.r !== first || b.rs !== 1) return;
|
|
461
|
+
pairs.push([a, b]);
|
|
462
|
+
}
|
|
463
|
+
c = a.c + a.cs;
|
|
464
|
+
}
|
|
465
|
+
if (!pairs.some(([u, d]) => continuesAcross(u.cell, d.cell, colXs[u.c], colXs[u.c + u.cs]))) return;
|
|
466
|
+
for (const [u, d] of pairs) {
|
|
467
|
+
const a = table.cells[u.r][u.c], b = table.cells[d.r][d.c];
|
|
468
|
+
if (b.text.trim()) a.text = a.text.trim() ? a.text + "\n" + b.text : b.text;
|
|
469
|
+
if (_optionalChain([b, 'access', _14 => _14.blocks, 'optionalAccess', _15 => _15.length])) a.blocks = [..._nullishCoalesce(a.blocks, () => ( [])), ...b.blocks];
|
|
470
|
+
}
|
|
471
|
+
for (let r = 0; r < first; r++) for (let c = 0; c < table.cols; c++) {
|
|
472
|
+
const o = owner[r][c];
|
|
473
|
+
if (o && o.r === r && o.c === c && r + table.cells[r][c].rowSpan > first) table.cells[r][c].rowSpan--;
|
|
474
|
+
}
|
|
475
|
+
table.cells.splice(first, 1);
|
|
476
|
+
table.rows--;
|
|
477
|
+
}
|
|
478
|
+
var NEIGHBOR_TABLE_EPSILON = 0.2;
|
|
479
|
+
function besideBoth(b, p, c) {
|
|
480
|
+
if (b.type === "table" || !b.bbox) return false;
|
|
481
|
+
const bx1 = b.bbox.x, bx2 = b.bbox.x + b.bbox.width;
|
|
482
|
+
return [p.bbox, c.bbox].every((t) => bx2 <= t.x + 1 || bx1 >= t.x + t.width - 1);
|
|
483
|
+
}
|
|
484
|
+
function mergeCrossPageTables(blocks, pageHeights) {
|
|
485
|
+
for (let i = blocks.length - 2; i >= 0; i--) {
|
|
486
|
+
const prev = blocks[i];
|
|
487
|
+
if (prev.type !== "table" || !prev.table || !prev.bbox || !prev.pageNumber) continue;
|
|
488
|
+
let j = i + 1;
|
|
489
|
+
while (j < blocks.length && blocks[j].type !== "table" && (_nullishCoalesce(blocks[j].pageNumber, () => ( 0))) <= prev.pageNumber + 1) j++;
|
|
490
|
+
const curr = blocks[j];
|
|
491
|
+
if (!curr || curr.type !== "table" || !curr.table || !curr.bbox || curr.pageNumber !== prev.pageNumber + 1) continue;
|
|
492
|
+
const joined = j === i + 1 || blocks.slice(i + 1, j).every((b) => besideBoth(b, prev, curr)) ? looksContinued(prev, curr, pageHeights) ? _nullishCoalesce(joinClipParts(prev, curr, pageHeights), () => ( false)) : null : null;
|
|
493
|
+
if (joined) {
|
|
494
|
+
blocks[i] = { ...prev, table: joined };
|
|
495
|
+
blocks.splice(j, 1);
|
|
496
|
+
continue;
|
|
497
|
+
}
|
|
498
|
+
if (_chunkNOAQRCV6cjs.EMPTY_PARTS.has(curr.table)) {
|
|
499
|
+
blocks.splice(j, 1);
|
|
500
|
+
i++;
|
|
501
|
+
continue;
|
|
502
|
+
}
|
|
503
|
+
if (joined === null) continue;
|
|
504
|
+
if (prev.table.cols !== curr.table.cols || _chunkNOAQRCV6cjs.EMPTY_PARTS.has(prev.table)) continue;
|
|
505
|
+
const width = Math.max(prev.bbox.width, curr.bbox.width, 1);
|
|
506
|
+
const leftDiff = Math.abs(prev.bbox.x - curr.bbox.x);
|
|
507
|
+
const rightDiff = Math.abs(prev.bbox.x + prev.bbox.width - (curr.bbox.x + curr.bbox.width));
|
|
508
|
+
if (leftDiff > width * NEIGHBOR_TABLE_EPSILON || rightDiff > width * NEIGHBOR_TABLE_EPSILON) continue;
|
|
509
|
+
const px = _chunkNOAQRCV6cjs.TABLE_COLXS.get(prev.table), cx = _chunkNOAQRCV6cjs.TABLE_COLXS.get(curr.table);
|
|
510
|
+
if (px && cx && (px.length !== cx.length || px.some((x, k) => Math.abs(x - cx[k]) > CONTINUATION_COL_TOL))) continue;
|
|
511
|
+
let currCells = curr.table.cells;
|
|
512
|
+
if (currCells.length > 1 && prev.table.cells.length > 0 && rowTextsEqual(prev.table.cells[0], currCells[0])) {
|
|
513
|
+
currCells = currCells.slice(1);
|
|
514
|
+
}
|
|
515
|
+
if (currCells.length === 0) {
|
|
516
|
+
blocks.splice(j, 1);
|
|
517
|
+
continue;
|
|
518
|
+
}
|
|
519
|
+
const merged = {
|
|
520
|
+
rows: prev.table.rows + currCells.length,
|
|
521
|
+
cols: prev.table.cols,
|
|
522
|
+
cells: [...prev.table.cells, ...currCells],
|
|
523
|
+
hasHeader: prev.table.hasHeader,
|
|
524
|
+
caption: prev.table.caption
|
|
525
|
+
};
|
|
526
|
+
if (_nullishCoalesce(px, () => ( cx))) _chunkNOAQRCV6cjs.TABLE_COLXS.set(merged, _nullishCoalesce(px, () => ( cx)));
|
|
527
|
+
if (_chunkNOAQRCV6cjs.CLIP_TABLES.has(prev.table) || _chunkNOAQRCV6cjs.CLIP_TABLES.has(curr.table)) _chunkNOAQRCV6cjs.CLIP_TABLES.add(merged);
|
|
528
|
+
blocks[i] = { ...prev, table: merged };
|
|
529
|
+
blocks.splice(j, 1);
|
|
530
|
+
}
|
|
531
|
+
for (let i = blocks.length - 1; i >= 0; i--) {
|
|
532
|
+
const t = blocks[i].table;
|
|
533
|
+
if (blocks[i].type === "table" && t && _chunkNOAQRCV6cjs.EMPTY_PARTS.has(t)) blocks.splice(i, 1);
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
function joinClipParts(prev, curr, pageHeights) {
|
|
537
|
+
const pt = prev.table, ct = curr.table;
|
|
538
|
+
if (!_chunkNOAQRCV6cjs.CLIP_TABLES.has(pt) || !_chunkNOAQRCV6cjs.CLIP_TABLES.has(ct)) return null;
|
|
539
|
+
const px = _chunkNOAQRCV6cjs.TABLE_COLXS.get(pt), cx = _chunkNOAQRCV6cjs.TABLE_COLXS.get(ct);
|
|
540
|
+
if (!px || !cx) return null;
|
|
541
|
+
const sameCols = px.length === cx.length && px.every((x, k) => Math.abs(x - cx[k]) <= CONTINUATION_COL_TOL);
|
|
542
|
+
if (!sameCols) {
|
|
543
|
+
if (!_optionalChain([pageHeights, 'optionalAccess', _16 => _16.get, 'call', _17 => _17(prev.pageNumber)]) || !_optionalChain([pageHeights, 'optionalAccess', _18 => _18.get, 'call', _19 => _19(curr.pageNumber)])) return null;
|
|
544
|
+
if (Math.abs(px[px.length - 1] - cx[cx.length - 1]) > CONTINUATION_COL_TOL) return null;
|
|
545
|
+
if (!px.some((x) => Math.abs(x - cx[0]) <= CONTINUATION_COL_TOL)) return null;
|
|
546
|
+
}
|
|
547
|
+
const res = joinSplitParts(pt, px, ct, cx);
|
|
548
|
+
if (!res) return null;
|
|
549
|
+
_chunkNOAQRCV6cjs.TABLE_COLXS.set(res.table, res.colXs);
|
|
550
|
+
_chunkNOAQRCV6cjs.CLIP_TABLES.add(res.table);
|
|
551
|
+
return res.table;
|
|
552
|
+
}
|
|
553
|
+
var ANNEX_HEAD_RE = /^\s*[<\[(【]?\s*(?:붙\s*임|참\s*고|별\s*첨|별\s*지|별\s*표|첨\s*부|부\s*록)(?:\s*\d|\s*$|\s*[>\])】])|^\s*■/;
|
|
554
|
+
function looksContinued(prev, curr, pageHeights) {
|
|
555
|
+
const ph = _optionalChain([pageHeights, 'optionalAccess', _20 => _20.get, 'call', _21 => _21(prev.pageNumber)]), ch = _optionalChain([pageHeights, 'optionalAccess', _22 => _22.get, 'call', _23 => _23(curr.pageNumber)]);
|
|
556
|
+
if (ph && ch && (prev.bbox.y > ph * PAGE_EDGE_BAND || curr.bbox.y + curr.bbox.height < ch * (1 - PAGE_EDGE_BAND))) return false;
|
|
557
|
+
const firstText = _nullishCoalesce(_optionalChain([curr, 'access', _24 => _24.table, 'access', _25 => _25.cells, 'access', _26 => _26[0], 'optionalAccess', _27 => _27.find, 'call', _28 => _28((c) => c.text.trim()), 'optionalAccess', _29 => _29.text]), () => ( ""));
|
|
558
|
+
return !ANNEX_HEAD_RE.test(firstText);
|
|
559
|
+
}
|
|
560
|
+
function rowTextsEqual(a, b) {
|
|
561
|
+
if (a.length !== b.length) return false;
|
|
562
|
+
const norm = (t) => t.replace(/\s+/g, "");
|
|
563
|
+
for (let i = 0; i < a.length; i++) {
|
|
564
|
+
if (norm(a[i].text) !== norm(b[i].text)) return false;
|
|
565
|
+
}
|
|
566
|
+
return a.some((c) => c.text.trim() !== "");
|
|
567
|
+
}
|
|
568
|
+
var CONTINUATION_COL_TOL = 2;
|
|
569
|
+
var PAGE_EDGE_BAND = 0.16;
|
|
570
|
+
|
|
328
571
|
// src/pdf/symbol-fonts.ts
|
|
329
|
-
var WINGDINGS = [
|
|
330
|
-
"\u{1F589}",
|
|
331
|
-
"\u2702",
|
|
332
|
-
"\u2701",
|
|
333
|
-
"\u{1F453}",
|
|
334
|
-
"\u{1F56D}",
|
|
335
|
-
"\u{1F56E}",
|
|
336
|
-
"\u{1F56F}",
|
|
337
|
-
"\u{1F57F}",
|
|
338
|
-
"\u2706",
|
|
339
|
-
"\u{1F582}",
|
|
340
|
-
"\u{1F583}",
|
|
341
|
-
"\u{1F4EA}",
|
|
342
|
-
"\u{1F4EB}",
|
|
343
|
-
"\u{1F4EC}",
|
|
344
|
-
"\u{1F4ED}",
|
|
345
|
-
"\u{1F4C1}",
|
|
346
|
-
"\u{1F4C2}",
|
|
347
|
-
"\u{1F4C4}",
|
|
348
|
-
"\u{1F5CF}",
|
|
349
|
-
"\u{1F5D0}",
|
|
350
|
-
"\u{1F5C4}",
|
|
351
|
-
"\u231B",
|
|
352
|
-
"\u{1F5AE}",
|
|
353
|
-
"\u{1F5B0}",
|
|
354
|
-
"\u{1F5B2}",
|
|
355
|
-
"\u{1F5B3}",
|
|
356
|
-
"\u{1F5B4}",
|
|
357
|
-
"\u{1F5AB}",
|
|
358
|
-
"\u{1F5AC}",
|
|
359
|
-
"\u2707",
|
|
360
|
-
"\u270D",
|
|
361
|
-
"\u{1F58E}",
|
|
362
|
-
"\u270C",
|
|
363
|
-
"\u{1F44C}",
|
|
364
|
-
"\u{1F44D}",
|
|
365
|
-
"\u{1F44E}",
|
|
366
|
-
"\u261C",
|
|
367
|
-
"\u261E",
|
|
368
|
-
"\u261D",
|
|
369
|
-
"\u261F",
|
|
370
|
-
"\u{1F590}",
|
|
371
|
-
"\u263A",
|
|
372
|
-
"\u{1F610}",
|
|
373
|
-
"\u2639",
|
|
374
|
-
"\u{1F4A3}",
|
|
375
|
-
"\u2620",
|
|
376
|
-
"\u{1F3F3}",
|
|
377
|
-
"\u{1F3F1}",
|
|
378
|
-
"\u2708",
|
|
379
|
-
"\u263C",
|
|
380
|
-
"\u{1F4A7}",
|
|
381
|
-
"\u2744",
|
|
382
|
-
"\u{1F546}",
|
|
383
|
-
"\u271E",
|
|
384
|
-
"\u{1F548}",
|
|
385
|
-
"\u2720",
|
|
386
|
-
"\u2721",
|
|
387
|
-
"\u262A",
|
|
388
|
-
"\u262F",
|
|
389
|
-
"\u0950",
|
|
390
|
-
"\u2638",
|
|
391
|
-
"\u2648",
|
|
392
|
-
"\u2649",
|
|
393
|
-
"\u264A",
|
|
394
|
-
"\u264B",
|
|
395
|
-
"\u264C",
|
|
396
|
-
"\u264D",
|
|
397
|
-
"\u264E",
|
|
398
|
-
"\u264F",
|
|
399
|
-
"\u2650",
|
|
400
|
-
"\u2651",
|
|
401
|
-
"\u2652",
|
|
402
|
-
"\u2653",
|
|
403
|
-
"\u{1F670}",
|
|
404
|
-
"\u{1F675}",
|
|
405
|
-
"\u25CF",
|
|
406
|
-
"\u25CB",
|
|
407
|
-
"\u25A0",
|
|
408
|
-
"\u25A1",
|
|
409
|
-
"\u25A1",
|
|
410
|
-
"\u2751",
|
|
411
|
-
"\u2752",
|
|
412
|
-
"\u2B27",
|
|
413
|
-
"\u29EB",
|
|
414
|
-
"\u25C6",
|
|
415
|
-
"\u2756",
|
|
416
|
-
"\u2B25",
|
|
417
|
-
"\u2327",
|
|
418
|
-
"\u2BB9",
|
|
419
|
-
"\u2318",
|
|
420
|
-
"\u{1F3F5}",
|
|
421
|
-
"\u{1F3F6}",
|
|
422
|
-
"\u{1F676}",
|
|
423
|
-
"\u{1F677}",
|
|
424
|
-
"",
|
|
425
|
-
"\u24EA",
|
|
426
|
-
"\u2460",
|
|
427
|
-
"\u2461",
|
|
428
|
-
"\u2462",
|
|
429
|
-
"\u2463",
|
|
430
|
-
"\u2464",
|
|
431
|
-
"\u2465",
|
|
432
|
-
"\u2466",
|
|
433
|
-
"\u2467",
|
|
434
|
-
"\u2468",
|
|
435
|
-
"\u2469",
|
|
436
|
-
"\u24FF",
|
|
437
|
-
"\u2776",
|
|
438
|
-
"\u2777",
|
|
439
|
-
"\u2778",
|
|
440
|
-
"\u2779",
|
|
441
|
-
"\u277A",
|
|
442
|
-
"\u277B",
|
|
443
|
-
"\u277C",
|
|
444
|
-
"\u277D",
|
|
445
|
-
"\u277E",
|
|
446
|
-
"\u277F",
|
|
447
|
-
"\u{1F662}",
|
|
448
|
-
"\u{1F660}",
|
|
449
|
-
"\u{1F661}",
|
|
450
|
-
"\u{1F663}",
|
|
451
|
-
"\u{1F65E}",
|
|
452
|
-
"\u{1F65C}",
|
|
453
|
-
"\u{1F65D}",
|
|
454
|
-
"\u{1F65F}",
|
|
455
|
-
"\xB7",
|
|
456
|
-
"\u2022",
|
|
457
|
-
"\u25AA",
|
|
458
|
-
"\u26AA",
|
|
459
|
-
"\u25CB",
|
|
460
|
-
"\u25EF",
|
|
461
|
-
"\u25C9",
|
|
462
|
-
"\u25CE",
|
|
463
|
-
"\u{1F53F}",
|
|
464
|
-
"\u25AA",
|
|
465
|
-
"\u25FB",
|
|
466
|
-
"\u{1F7C2}",
|
|
467
|
-
"\u2726",
|
|
468
|
-
"\u2605",
|
|
469
|
-
"\u2736",
|
|
470
|
-
"\u2734",
|
|
471
|
-
"\u2739",
|
|
472
|
-
"\u2735",
|
|
473
|
-
"\u2BD0",
|
|
474
|
-
"\u2316",
|
|
475
|
-
"\u27E1",
|
|
476
|
-
"\u2311",
|
|
477
|
-
"\u2BD1",
|
|
478
|
-
"\u272A",
|
|
479
|
-
"\u2730",
|
|
480
|
-
"\u{1F550}",
|
|
481
|
-
"\u{1F551}",
|
|
482
|
-
"\u{1F552}",
|
|
483
|
-
"\u{1F553}",
|
|
484
|
-
"\u{1F554}",
|
|
485
|
-
"\u{1F555}",
|
|
486
|
-
"\u{1F556}",
|
|
487
|
-
"\u{1F557}",
|
|
488
|
-
"\u{1F558}",
|
|
489
|
-
"\u{1F559}",
|
|
490
|
-
"\u{1F55A}",
|
|
491
|
-
"\u{1F55B}",
|
|
492
|
-
"\u2BB0",
|
|
493
|
-
"\u2BB1",
|
|
494
|
-
"\u2BB2",
|
|
495
|
-
"\u2BB3",
|
|
496
|
-
"\u2BB4",
|
|
497
|
-
"\u2BB5",
|
|
498
|
-
"\u2BB6",
|
|
499
|
-
"\u2BB7",
|
|
500
|
-
"\u{1F66A}",
|
|
501
|
-
"\u{1F66B}",
|
|
502
|
-
"\u{1F655}",
|
|
503
|
-
"\u{1F654}",
|
|
504
|
-
"\u{1F657}",
|
|
505
|
-
"\u{1F656}",
|
|
506
|
-
"\u{1F650}",
|
|
507
|
-
"\u{1F651}",
|
|
508
|
-
"\u{1F652}",
|
|
509
|
-
"\u{1F653}",
|
|
510
|
-
"\u232B",
|
|
511
|
-
"\u2326",
|
|
512
|
-
"\u2B98",
|
|
513
|
-
"\u2B9A",
|
|
514
|
-
"\u2B99",
|
|
515
|
-
"\u2B9B",
|
|
516
|
-
"\u2B88",
|
|
517
|
-
"\u2B8A",
|
|
518
|
-
"\u2B89",
|
|
519
|
-
"\u2B8B",
|
|
520
|
-
"\u2190",
|
|
521
|
-
"\u2192",
|
|
522
|
-
"\u2191",
|
|
523
|
-
"\u2193",
|
|
524
|
-
"\u2196",
|
|
525
|
-
"\u2197",
|
|
526
|
-
"\u2199",
|
|
527
|
-
"\u2198",
|
|
528
|
-
"\u2B05",
|
|
529
|
-
"\u2794",
|
|
530
|
-
"\u2B06",
|
|
531
|
-
"\u2B07",
|
|
532
|
-
"\u2B09",
|
|
533
|
-
"\u2B08",
|
|
534
|
-
"\u2B0B",
|
|
535
|
-
"\u2B0A",
|
|
536
|
-
"\u21E6",
|
|
537
|
-
"\u21E8",
|
|
538
|
-
"\u21E7",
|
|
539
|
-
"\u21E9",
|
|
540
|
-
"\u2B04",
|
|
541
|
-
"\u21F3",
|
|
542
|
-
"\u2B00",
|
|
543
|
-
"\u2B01",
|
|
544
|
-
"\u2B03",
|
|
545
|
-
"\u2B02",
|
|
546
|
-
"\u{1F8AC}",
|
|
547
|
-
"\u{1F8AD}",
|
|
548
|
-
"\u2717",
|
|
549
|
-
"\u2714",
|
|
550
|
-
"\u2612",
|
|
551
|
-
"\u2611",
|
|
552
|
-
""
|
|
553
|
-
];
|
|
554
572
|
var WINANSI_REVERSE = {
|
|
555
573
|
8364: 128,
|
|
556
574
|
8218: 130,
|
|
@@ -582,7 +600,7 @@ var WINANSI_REVERSE = {
|
|
|
582
600
|
};
|
|
583
601
|
function symbolFontTable(fontName) {
|
|
584
602
|
if (!fontName) return void 0;
|
|
585
|
-
if (/wingdings(?![\s-]*[23])/i.test(fontName)) return WINGDINGS;
|
|
603
|
+
if (/wingdings(?![\s-]*[23])/i.test(fontName)) return _chunkEBZUZC6Fcjs.WINGDINGS;
|
|
586
604
|
return void 0;
|
|
587
605
|
}
|
|
588
606
|
function remapSymbolText(text, table) {
|
|
@@ -623,7 +641,8 @@ function remapSymbolFontItems(items, resolveFontName) {
|
|
|
623
641
|
function normalizeAraea(text) {
|
|
624
642
|
return text.replace(/(?<![\u1100-\u115F])\u119E/g, "\u318D");
|
|
625
643
|
}
|
|
626
|
-
var
|
|
644
|
+
var stripNoUnicodeGlyph = (text) => text.includes("\uF000") ? text.replace(/\uF000/g, "") : text;
|
|
645
|
+
var cleanChars = (text) => normalizeAraea(stripNoUnicodeGlyph(stripControlChars(text)));
|
|
627
646
|
function sanitizeBlockControlChars(blocks) {
|
|
628
647
|
for (const b of blocks) {
|
|
629
648
|
if (b.text) b.text = cleanChars(b.text);
|
|
@@ -642,8 +661,8 @@ function splitSingleCellTables(blocks) {
|
|
|
642
661
|
const out = [];
|
|
643
662
|
for (const b of blocks) {
|
|
644
663
|
const t = b.type === "table" ? b.table : void 0;
|
|
645
|
-
const cell = t && t.rows === 1 && t.cols === 1 ? _optionalChain([t, 'access',
|
|
646
|
-
if (!cell || _optionalChain([cell, 'access',
|
|
664
|
+
const cell = t && t.rows === 1 && t.cols === 1 ? _optionalChain([t, 'access', _30 => _30.cells, 'access', _31 => _31[0], 'optionalAccess', _32 => _32[0]]) : void 0;
|
|
665
|
+
if (!cell || _optionalChain([cell, 'access', _33 => _33.blocks, 'optionalAccess', _34 => _34.some, 'call', _35 => _35((x) => x.type === "table")])) {
|
|
647
666
|
out.push(b);
|
|
648
667
|
continue;
|
|
649
668
|
}
|
|
@@ -658,7 +677,7 @@ function cleanPdfText(text) {
|
|
|
658
677
|
normalizeAraea(stripControlChars(text)).replace(/^\d{1,4}\n/, "").replace(/^[\s]*[-–—]\s*[-–—]?\d+[-–—]?[\s]*[-–—]?[\s]*$/gm, "").replace(/^\s*\d+\s*\/\s*\d+\s*$/gm, "").replace(/\n\d{1,4}\n/g, "\n").replace(/\n\d{1,4}$/, "").replace(/^#{1,6}\s*\d{1,4}\s*$/gm, "")
|
|
659
678
|
).replace(/^(?!\| ---).*$/gm, (line) => {
|
|
660
679
|
if (/^\s*\${1,2}.+\${1,2}\s*$/.test(line)) return line;
|
|
661
|
-
return
|
|
680
|
+
return _chunkNOAQRCV6cjs.collapseEvenSpacing.call(void 0, line);
|
|
662
681
|
}).replace(/([□■◆○●▶ㅇ])\s+([가-힣])\s+([가-힣])/g, "$1 $2$3").replace(/\\~\\~/g, "~~").replace(/~~~~/g, "").replace(/<u>\s*<\/u>/g, "").replace(/\n{3,}/g, "\n\n").trim();
|
|
663
682
|
}
|
|
664
683
|
function startsWithMarker(line) {
|
|
@@ -706,7 +725,7 @@ function applyLinkAnnotations(items, annots) {
|
|
|
706
725
|
const wrapped = /* @__PURE__ */ new Set();
|
|
707
726
|
for (const a of annots) {
|
|
708
727
|
if (a.subtype !== "Link" || !a.url || !a.rect || a.rect.length < 4) continue;
|
|
709
|
-
const url =
|
|
728
|
+
const url = _chunkEMGF6EEVcjs.sanitizeHref.call(void 0, a.url);
|
|
710
729
|
if (!url) continue;
|
|
711
730
|
const x1 = Math.min(a.rect[0], a.rect[2]), x2 = Math.max(a.rect[0], a.rect[2]);
|
|
712
731
|
const y1 = Math.min(a.rect[1], a.rect[3]), y2 = Math.max(a.rect[1], a.rect[3]);
|
|
@@ -737,7 +756,7 @@ function applyLinkAnnotations(items, annots) {
|
|
|
737
756
|
|
|
738
757
|
// src/pdf/formula-ocr.ts
|
|
739
758
|
async function applyFormulaOcr(buffer, blocks, pageFilter, effectivePageCount, warnings, _onProgress) {
|
|
740
|
-
const formulaMod = await Promise.resolve().then(() => _interopRequireWildcard(require("./formula-
|
|
759
|
+
const formulaMod = await Promise.resolve().then(() => _interopRequireWildcard(require("./formula-CPO2TZGB.cjs")));
|
|
741
760
|
const { FormulaPipeline, ensureFormulaModels } = formulaMod;
|
|
742
761
|
await ensureFormulaModels((p) => {
|
|
743
762
|
if (p.phase === "download" && p.total) {
|
|
@@ -905,7 +924,7 @@ async function loadPdfWithTimeout(buffer) {
|
|
|
905
924
|
new Promise((_, reject) => {
|
|
906
925
|
timer = setTimeout(() => {
|
|
907
926
|
loadingTask.destroy();
|
|
908
|
-
reject(new (0,
|
|
927
|
+
reject(new (0, _chunkEMGF6EEVcjs.KordocError)("PDF \uB85C\uB529 \uD0C0\uC784\uC544\uC6C3 (30\uCD08 \uCD08\uACFC)"));
|
|
909
928
|
}, PDF_LOAD_TIMEOUT_MS);
|
|
910
929
|
})
|
|
911
930
|
]);
|
|
@@ -914,12 +933,12 @@ async function loadPdfWithTimeout(buffer) {
|
|
|
914
933
|
}
|
|
915
934
|
}
|
|
916
935
|
async function parsePdfDocument(buffer, options) {
|
|
917
|
-
const formulaBuffer = _optionalChain([options, 'optionalAccess',
|
|
918
|
-
const ocrBuffer = _optionalChain([options, 'optionalAccess',
|
|
936
|
+
const formulaBuffer = _optionalChain([options, 'optionalAccess', _36 => _36.formulaOcr]) ? buffer.slice(0) : null;
|
|
937
|
+
const ocrBuffer = _optionalChain([options, 'optionalAccess', _37 => _37.ocr]) ? buffer.slice(0) : null;
|
|
919
938
|
const doc = await loadPdfWithTimeout(buffer);
|
|
920
939
|
try {
|
|
921
940
|
const pageCount = doc.numPages;
|
|
922
|
-
if (pageCount === 0) throw new (0,
|
|
941
|
+
if (pageCount === 0) throw new (0, _chunkEMGF6EEVcjs.KordocError)("PDF\uC5D0 \uD398\uC774\uC9C0\uAC00 \uC5C6\uC2B5\uB2C8\uB2E4.");
|
|
923
942
|
const metadata = { pageCount, pageMode: "layout" };
|
|
924
943
|
await extractPdfMetadata(doc, metadata);
|
|
925
944
|
const blocks = [];
|
|
@@ -928,7 +947,7 @@ async function parsePdfDocument(buffer, options) {
|
|
|
928
947
|
let totalChars = 0;
|
|
929
948
|
let totalTextBytes = 0;
|
|
930
949
|
const effectivePageCount = Math.min(pageCount, MAX_PAGES);
|
|
931
|
-
const pageFilter = _optionalChain([options, 'optionalAccess',
|
|
950
|
+
const pageFilter = _optionalChain([options, 'optionalAccess', _38 => _38.pages]) ? _chunkDCZVOIEOcjs.parsePageRange.call(void 0, options.pages, effectivePageCount) : null;
|
|
932
951
|
const totalTarget = pageFilter ? pageFilter.size : effectivePageCount;
|
|
933
952
|
const fontSizeFreq = /* @__PURE__ */ new Map();
|
|
934
953
|
const pageHeights = /* @__PURE__ */ new Map();
|
|
@@ -946,8 +965,8 @@ async function parsePdfDocument(buffer, options) {
|
|
|
946
965
|
const viewport = page.getViewport({ scale: 1 });
|
|
947
966
|
pageHeights.set(i, viewport.height);
|
|
948
967
|
const rawItems = tc.items;
|
|
949
|
-
const items =
|
|
950
|
-
const { visible, hiddenCount } =
|
|
968
|
+
const items = _chunkNOAQRCV6cjs.normalizeItems.call(void 0, rawItems);
|
|
969
|
+
const { visible, hiddenCount } = _chunkNOAQRCV6cjs.filterHiddenText.call(void 0, items, viewport.width, viewport.height);
|
|
951
970
|
if (hiddenCount > 0) {
|
|
952
971
|
warnings.push({ page: i, message: `${hiddenCount}\uAC1C \uC228\uACA8\uC9C4 \uD14D\uC2A4\uD2B8 \uC694\uC18C \uD544\uD130\uB9C1\uB428`, code: "HIDDEN_TEXT_FILTERED" });
|
|
953
972
|
}
|
|
@@ -962,14 +981,14 @@ async function parsePdfDocument(buffer, options) {
|
|
|
962
981
|
const opList = await page.getOperatorList();
|
|
963
982
|
remapSymbolFontItems(visible, (loadedName) => {
|
|
964
983
|
try {
|
|
965
|
-
return page.commonObjs.has(loadedName) ? _optionalChain([page, 'access',
|
|
984
|
+
return page.commonObjs.has(loadedName) ? _optionalChain([page, 'access', _39 => _39.commonObjs, 'access', _40 => _40.get, 'call', _41 => _41(loadedName), 'optionalAccess', _42 => _42.name]) : void 0;
|
|
966
985
|
} catch (e5) {
|
|
967
986
|
return void 0;
|
|
968
987
|
}
|
|
969
988
|
});
|
|
970
989
|
const pageArea = viewport.width * viewport.height;
|
|
971
990
|
if (pageArea > 0) {
|
|
972
|
-
const imageRegions =
|
|
991
|
+
const imageRegions = _chunkNOAQRCV6cjs.extractImageRegions.call(void 0, opList.fnArray, opList.argsArray);
|
|
973
992
|
let uncovered = 0;
|
|
974
993
|
for (const r of imageRegions) {
|
|
975
994
|
const area = (r.x2 - r.x1) * (r.y2 - r.y1);
|
|
@@ -984,10 +1003,10 @@ async function parsePdfDocument(buffer, options) {
|
|
|
984
1003
|
}
|
|
985
1004
|
if (uncovered > 0) skippedImagePages.set(i, uncovered);
|
|
986
1005
|
}
|
|
987
|
-
const pageBlocks =
|
|
1006
|
+
const pageBlocks = _chunkNOAQRCV6cjs.extractPageBlocksWithLines.call(void 0, visible, i, opList, viewport.width, viewport.height, void 0, _optionalChain([options, 'optionalAccess', _43 => _43.tables]) !== false);
|
|
988
1007
|
for (const b of pageBlocks) blocks.push(b);
|
|
989
1008
|
try {
|
|
990
|
-
const { blocks: imgBlocks, images: pageImages } = await extractPageImages(page, opList.fnArray, opList.argsArray, i, imageState, warnings);
|
|
1009
|
+
const { blocks: imgBlocks, images: pageImages } = await extractPageImages(page, opList.fnArray, opList.argsArray, i, imageState, warnings, _optionalChain([options, 'optionalAccess', _44 => _44.images]) !== false);
|
|
991
1010
|
if (imgBlocks.length > 0) pageImageBlocks.set(i, imgBlocks);
|
|
992
1011
|
extractedImages.push(...pageImages);
|
|
993
1012
|
} catch (e6) {
|
|
@@ -1004,18 +1023,18 @@ async function parsePdfDocument(buffer, options) {
|
|
|
1004
1023
|
pageText += pageText ? "\n" + t : t;
|
|
1005
1024
|
}
|
|
1006
1025
|
pageQuality.push(computePageQuality(i, pageText));
|
|
1007
|
-
if (totalTextBytes > MAX_TOTAL_TEXT) throw new (0,
|
|
1026
|
+
if (totalTextBytes > MAX_TOTAL_TEXT) throw new (0, _chunkEMGF6EEVcjs.KordocError)("\uD14D\uC2A4\uD2B8 \uCD94\uCD9C \uD06C\uAE30 \uCD08\uACFC");
|
|
1008
1027
|
parsedPages++;
|
|
1009
|
-
_optionalChain([options, 'optionalAccess',
|
|
1028
|
+
_optionalChain([options, 'optionalAccess', _45 => _45.onProgress, 'optionalCall', _46 => _46(parsedPages, totalTarget)]);
|
|
1010
1029
|
} catch (pageErr) {
|
|
1011
|
-
if (pageErr instanceof
|
|
1030
|
+
if (pageErr instanceof _chunkEMGF6EEVcjs.KordocError) throw pageErr;
|
|
1012
1031
|
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" });
|
|
1013
1032
|
}
|
|
1014
1033
|
}
|
|
1015
1034
|
const parsedPageCount = parsedPages || (pageFilter ? pageFilter.size : effectivePageCount);
|
|
1016
1035
|
const isImageBased = totalChars / Math.max(parsedPageCount, 1) < 10;
|
|
1017
1036
|
const ocrDone = /* @__PURE__ */ new Set();
|
|
1018
|
-
if (_optionalChain([options, 'optionalAccess',
|
|
1037
|
+
if (_optionalChain([options, 'optionalAccess', _47 => _47.ocr]) && ocrBuffer) {
|
|
1019
1038
|
const inScope = (p) => !pageFilter || pageFilter.has(p);
|
|
1020
1039
|
const targets = /* @__PURE__ */ new Set();
|
|
1021
1040
|
if (options.ocr === "force" || isImageBased) {
|
|
@@ -1029,7 +1048,7 @@ async function parsePdfDocument(buffer, options) {
|
|
|
1029
1048
|
}
|
|
1030
1049
|
if (targets.size > 0) {
|
|
1031
1050
|
try {
|
|
1032
|
-
const { runPdfOcr } = await Promise.resolve().then(() => _interopRequireWildcard(require("./pdf-ocr-
|
|
1051
|
+
const { runPdfOcr } = await Promise.resolve().then(() => _interopRequireWildcard(require("./pdf-ocr-VHSFACH7.cjs")));
|
|
1033
1052
|
const mode = typeof options.ocr === "function" ? options.ocr : "builtin";
|
|
1034
1053
|
const ocrPageBlocks = await runPdfOcr(ocrBuffer, targets, mode, warnings, options.onProgress, options.tables !== false);
|
|
1035
1054
|
if (ocrPageBlocks.size > 0) {
|
|
@@ -1078,15 +1097,16 @@ async function parsePdfDocument(buffer, options) {
|
|
|
1078
1097
|
warnings.push({ page, message: `${count}\uAC1C \uC774\uBBF8\uC9C0 \uC601\uC5ED\uC5D0 \uCD94\uCD9C \uAC00\uB2A5\uD55C \uD14D\uC2A4\uD2B8 \uC5C6\uC74C (\uADF8\uB9BC/\uCC28\uD2B8/\uB3C4\uC7A5 \uB0B4\uC6A9 \uB204\uB77D \uAC00\uB2A5)`, code: "SKIPPED_IMAGE" });
|
|
1079
1098
|
}
|
|
1080
1099
|
}
|
|
1081
|
-
if (_optionalChain([options, 'optionalAccess',
|
|
1082
|
-
const removed =
|
|
1100
|
+
if (_optionalChain([options, 'optionalAccess', _48 => _48.removeHeaderFooter]) !== false && parsedPageCount >= 3) {
|
|
1101
|
+
const removed = _chunkNOAQRCV6cjs.removeHeaderFooterBlocks.call(void 0, blocks, pageHeights, warnings);
|
|
1083
1102
|
for (let ri = removed.length - 1; ri >= 0; ri--) {
|
|
1084
1103
|
blocks.splice(removed[ri], 1);
|
|
1085
1104
|
}
|
|
1086
1105
|
}
|
|
1087
|
-
|
|
1106
|
+
mergeCrossPageTables(blocks, pageHeights);
|
|
1107
|
+
if (!_optionalChain([options, 'optionalAccess', _49 => _49.keepTrailingEmptyCols])) _chunkNOAQRCV6cjs.trimTrailingEmptyTableCols.call(void 0, blocks);
|
|
1088
1108
|
injectPageImageBlocks(blocks, pageImageBlocks);
|
|
1089
|
-
if (_optionalChain([options, 'optionalAccess',
|
|
1109
|
+
if (_optionalChain([options, 'optionalAccess', _50 => _50.formulaOcr]) && formulaBuffer) {
|
|
1090
1110
|
try {
|
|
1091
1111
|
await applyFormulaOcr(formulaBuffer, blocks, pageFilter, effectivePageCount, warnings, options.onProgress);
|
|
1092
1112
|
} catch (e) {
|
|
@@ -1096,17 +1116,17 @@ async function parsePdfDocument(buffer, options) {
|
|
|
1096
1116
|
});
|
|
1097
1117
|
}
|
|
1098
1118
|
}
|
|
1099
|
-
const medianFontSize =
|
|
1119
|
+
const medianFontSize = _chunkNOAQRCV6cjs.computeMedianFontSizeFromFreq.call(void 0, fontSizeFreq);
|
|
1100
1120
|
if (medianFontSize > 0) {
|
|
1101
|
-
|
|
1121
|
+
_chunkNOAQRCV6cjs.detectHeadings.call(void 0, blocks, medianFontSize);
|
|
1102
1122
|
}
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1123
|
+
_chunkNOAQRCV6cjs.detectMarkerHeadings.call(void 0, blocks);
|
|
1124
|
+
_chunkNOAQRCV6cjs.detectTableCaptions.call(void 0, blocks);
|
|
1125
|
+
_chunkNOAQRCV6cjs.detectKoreanListBlocks.call(void 0, blocks);
|
|
1106
1126
|
const outline = blocks.filter((b) => b.type === "heading" && b.level && b.text).map((b) => ({ level: b.level, text: b.text, pageNumber: b.pageNumber }));
|
|
1107
1127
|
sanitizeBlockControlChars(blocks);
|
|
1108
1128
|
const outBlocks = splitSingleCellTables(blocks);
|
|
1109
|
-
let markdown = cleanPdfText(
|
|
1129
|
+
let markdown = cleanPdfText(_chunkEBZUZC6Fcjs.blocksToMarkdown.call(void 0, outBlocks));
|
|
1110
1130
|
return {
|
|
1111
1131
|
markdown,
|
|
1112
1132
|
blocks,
|
|
@@ -1126,7 +1146,7 @@ async function parsePdfDocument(buffer, options) {
|
|
|
1126
1146
|
async function extractPdfMetadata(doc, metadata) {
|
|
1127
1147
|
try {
|
|
1128
1148
|
const result = await doc.getMetadata();
|
|
1129
|
-
if (!_optionalChain([result, 'optionalAccess',
|
|
1149
|
+
if (!_optionalChain([result, 'optionalAccess', _51 => _51.info])) return;
|
|
1130
1150
|
const info = result.info;
|
|
1131
1151
|
if (typeof info.Title === "string" && info.Title.trim()) metadata.title = info.Title.trim();
|
|
1132
1152
|
if (typeof info.Author === "string" && info.Author.trim()) metadata.author = info.Author.trim();
|
|
@@ -1165,5 +1185,5 @@ async function extractPdfMetadataOnly(buffer) {
|
|
|
1165
1185
|
|
|
1166
1186
|
|
|
1167
1187
|
|
|
1168
|
-
exports.cleanPdfText = cleanPdfText; exports.detectKoreanListBlocks =
|
|
1169
|
-
//# sourceMappingURL=parser-
|
|
1188
|
+
exports.cleanPdfText = cleanPdfText; exports.detectKoreanListBlocks = _chunkNOAQRCV6cjs.detectKoreanListBlocks; exports.detectTableCaptions = _chunkNOAQRCV6cjs.detectTableCaptions; exports.extractPdfMetadataOnly = extractPdfMetadataOnly; exports.mergeCrossPageTables = mergeCrossPageTables; exports.parsePdfDocument = parsePdfDocument; exports.removeHeaderFooterBlocks = _chunkNOAQRCV6cjs.removeHeaderFooterBlocks;
|
|
1189
|
+
//# sourceMappingURL=parser-RANGXGBD.cjs.map
|