kordoc 4.0.7 → 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.
Files changed (123) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +837 -806
  3. package/dist/{-6HWEFXVV.js → -AS4IABL2.js} +24 -11
  4. package/dist/{chunk-BKWHX3RC.js → chunk-37HJHCPA.js} +24 -15
  5. package/dist/chunk-37HJHCPA.js.map +1 -0
  6. package/dist/{chunk-U25XGCNH.cjs → chunk-37VKMUST.cjs} +174 -25
  7. package/dist/chunk-37VKMUST.cjs.map +1 -0
  8. package/dist/{chunk-5OKHAJ62.js → chunk-4KI23VHA.js} +162 -13
  9. package/dist/chunk-4KI23VHA.js.map +1 -0
  10. package/dist/{chunk-6GBLFQMA.js → chunk-5RPYBC2Q.js} +1 -1
  11. package/dist/chunk-5RPYBC2Q.js.map +1 -0
  12. package/dist/{chunk-NGSHDBQR.js → chunk-AX2R5Q2N.js} +7 -4
  13. package/dist/chunk-AX2R5Q2N.js.map +1 -0
  14. package/dist/{chunk-X34YWRL5.cjs → chunk-DCZVOIEO.cjs} +1 -1
  15. package/dist/chunk-DCZVOIEO.cjs.map +1 -0
  16. package/dist/chunk-DZIXKL7E.js +145 -0
  17. package/dist/chunk-DZIXKL7E.js.map +1 -0
  18. package/dist/chunk-F2ZU3IZG.js +82 -0
  19. package/dist/chunk-F2ZU3IZG.js.map +1 -0
  20. package/dist/{chunk-AIQ3ISQU.js → chunk-GE43BE46.js} +1 -1
  21. package/dist/chunk-GE43BE46.js.map +1 -0
  22. package/dist/{chunk-Q7EN4EUJ.js → chunk-GQVSHGG4.js} +12 -4
  23. package/dist/chunk-GQVSHGG4.js.map +1 -0
  24. package/dist/chunk-GS7T56RP.cjs.map +1 -1
  25. package/dist/{chunk-TJJTLM76.js → chunk-L2XQQTOY.js} +1422 -1121
  26. package/dist/chunk-L2XQQTOY.js.map +1 -0
  27. package/dist/{chunk-3TBUDJDE.js → chunk-MOL7MDBG.js} +1 -1
  28. package/dist/chunk-MOL7MDBG.js.map +1 -0
  29. package/dist/{chunk-CNM75ZSX.js → chunk-O5VS7RIR.js} +2 -2
  30. package/dist/chunk-O5VS7RIR.js.map +1 -0
  31. package/dist/{chunk-2SN3CKME.js → chunk-SSTK6IKK.js} +18 -21
  32. package/dist/chunk-SSTK6IKK.js.map +1 -0
  33. package/dist/chunk-UOO7LSDG.js +152 -0
  34. package/dist/chunk-UOO7LSDG.js.map +1 -0
  35. package/dist/{chunk-ONXVBURQ.js → chunk-WO52HVQJ.js} +2 -2
  36. package/dist/chunk-WO52HVQJ.js.map +1 -0
  37. package/dist/{chunk-CFQLK3LM.js → chunk-YOO6ET6M.js} +7 -3
  38. package/dist/chunk-YOO6ET6M.js.map +1 -0
  39. package/dist/chunks-WVMGF7JL.js +10 -0
  40. package/dist/cli.js +173 -38
  41. package/dist/cli.js.map +1 -1
  42. package/dist/{detect-NTR2FUEG.js → detect-YEZX2XCF.js} +2 -2
  43. package/dist/{formula-ZYUDQHD3.cjs → formula-5NKVS2LR.cjs} +1 -1
  44. package/dist/formula-5NKVS2LR.cjs.map +1 -0
  45. package/dist/{formula-KOQV353G.js → formula-JCNF43NE.js} +1 -1
  46. package/dist/formula-JCNF43NE.js.map +1 -0
  47. package/dist/{formula-MEDGYQXS.js → formula-RXVSQPXI.js} +1 -1
  48. package/dist/formula-RXVSQPXI.js.map +1 -0
  49. package/dist/index.cjs +1932 -1397
  50. package/dist/index.cjs.map +1 -1
  51. package/dist/index.d.cts +106 -2
  52. package/dist/index.d.ts +106 -2
  53. package/dist/index.js +1626 -1091
  54. package/dist/index.js.map +1 -1
  55. package/dist/mcp.js +275 -67
  56. package/dist/mcp.js.map +1 -1
  57. package/dist/page-range-737B4EZW.js +8 -0
  58. package/dist/page-range-LNMXJU6W.js +7 -0
  59. package/dist/page-range-P7SDW6LR.cjs +8 -0
  60. package/dist/page-range-P7SDW6LR.cjs.map +1 -0
  61. package/dist/{parser-E6U5TNAU.cjs → parser-N4A7UGDK.cjs} +314 -56
  62. package/dist/parser-N4A7UGDK.cjs.map +1 -0
  63. package/dist/{parser-5EHWYJMC.js → parser-PEOYBXBO.js} +287 -27
  64. package/dist/parser-PEOYBXBO.js.map +1 -0
  65. package/dist/{parser-UGB3NIVH.js → parser-XX4QTDFQ.js} +283 -25
  66. package/dist/parser-XX4QTDFQ.js.map +1 -0
  67. package/dist/{profile-io-CAKRPQRD.js → profile-io-PLDQFPJA.js} +3 -3
  68. package/dist/{provider-5K7O3Z2O.cjs → provider-4FAYHJ6N.cjs} +3 -3
  69. package/dist/provider-4FAYHJ6N.cjs.map +1 -0
  70. package/dist/{provider-H4WWSPOV.js → provider-C6IOGIS5.js} +3 -3
  71. package/dist/provider-C6IOGIS5.js.map +1 -0
  72. package/dist/{provider-7H4CPZYS.js → provider-UIBW2MIH.js} +3 -3
  73. package/dist/provider-UIBW2MIH.js.map +1 -0
  74. package/dist/rasterize-WWNQLKYW.js +40 -0
  75. package/dist/rasterize-WWNQLKYW.js.map +1 -0
  76. package/dist/redact-7ILEAUTS.js +12 -0
  77. package/dist/render-T7S6H6AN.js +10 -0
  78. package/dist/render-T7S6H6AN.js.map +1 -0
  79. package/dist/seal-7PTL6MXH.js +10 -0
  80. package/dist/seal-7PTL6MXH.js.map +1 -0
  81. package/dist/{setup-QSJ2INNS.js → setup-Q2PRE7UA.js} +5 -3
  82. package/dist/setup-Q2PRE7UA.js.map +1 -0
  83. package/dist/{watch-RMX427YR.js → watch-SFHXZALC.js} +78 -24
  84. package/dist/watch-SFHXZALC.js.map +1 -0
  85. package/package.json +97 -97
  86. package/dist/chunk-2SN3CKME.js.map +0 -1
  87. package/dist/chunk-3TBUDJDE.js.map +0 -1
  88. package/dist/chunk-5OKHAJ62.js.map +0 -1
  89. package/dist/chunk-6GBLFQMA.js.map +0 -1
  90. package/dist/chunk-AIQ3ISQU.js.map +0 -1
  91. package/dist/chunk-BKWHX3RC.js.map +0 -1
  92. package/dist/chunk-CFQLK3LM.js.map +0 -1
  93. package/dist/chunk-CNM75ZSX.js.map +0 -1
  94. package/dist/chunk-NGSHDBQR.js.map +0 -1
  95. package/dist/chunk-ONXVBURQ.js.map +0 -1
  96. package/dist/chunk-Q7EN4EUJ.js.map +0 -1
  97. package/dist/chunk-TJJTLM76.js.map +0 -1
  98. package/dist/chunk-U25XGCNH.cjs.map +0 -1
  99. package/dist/chunk-X34YWRL5.cjs.map +0 -1
  100. package/dist/formula-KOQV353G.js.map +0 -1
  101. package/dist/formula-MEDGYQXS.js.map +0 -1
  102. package/dist/formula-ZYUDQHD3.cjs.map +0 -1
  103. package/dist/page-range-CIRRJPXJ.js +0 -7
  104. package/dist/page-range-OF5I4PQY.js +0 -8
  105. package/dist/page-range-TPIRSA3J.cjs +0 -8
  106. package/dist/page-range-TPIRSA3J.cjs.map +0 -1
  107. package/dist/parser-5EHWYJMC.js.map +0 -1
  108. package/dist/parser-E6U5TNAU.cjs.map +0 -1
  109. package/dist/parser-UGB3NIVH.js.map +0 -1
  110. package/dist/provider-5K7O3Z2O.cjs.map +0 -1
  111. package/dist/provider-7H4CPZYS.js.map +0 -1
  112. package/dist/provider-H4WWSPOV.js.map +0 -1
  113. package/dist/render-P6663O4I.js +0 -10
  114. package/dist/seal-7PPTXKKV.js +0 -10
  115. package/dist/setup-QSJ2INNS.js.map +0 -1
  116. package/dist/watch-RMX427YR.js.map +0 -1
  117. /package/dist/{-6HWEFXVV.js.map → -AS4IABL2.js.map} +0 -0
  118. /package/dist/{detect-NTR2FUEG.js.map → chunks-WVMGF7JL.js.map} +0 -0
  119. /package/dist/{page-range-CIRRJPXJ.js.map → detect-YEZX2XCF.js.map} +0 -0
  120. /package/dist/{page-range-OF5I4PQY.js.map → page-range-737B4EZW.js.map} +0 -0
  121. /package/dist/{profile-io-CAKRPQRD.js.map → page-range-LNMXJU6W.js.map} +0 -0
  122. /package/dist/{render-P6663O4I.js.map → profile-io-PLDQFPJA.js.map} +0 -0
  123. /package/dist/{seal-7PPTXKKV.js.map → redact-7ILEAUTS.js.map} +0 -0
@@ -6,10 +6,11 @@
6
6
 
7
7
 
8
8
 
9
- var _chunkU25XGCNHcjs = require('./chunk-U25XGCNH.cjs');
10
9
 
10
+ var _chunk37VKMUSTcjs = require('./chunk-37VKMUST.cjs');
11
11
 
12
- var _chunkX34YWRL5cjs = require('./chunk-X34YWRL5.cjs');
12
+
13
+ var _chunkDCZVOIEOcjs = require('./chunk-DCZVOIEO.cjs');
13
14
 
14
15
 
15
16
  var _chunkGS7T56RPcjs = require('./chunk-GS7T56RP.cjs');
@@ -580,6 +581,18 @@ function buildVertices(horizontals, verticals) {
580
581
  }
581
582
  function mergeVertices(vertices) {
582
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
+ }
583
596
  const merged = [];
584
597
  const used = new Array(vertices.length).fill(false);
585
598
  for (let i = 0; i < vertices.length; i++) {
@@ -587,7 +600,20 @@ function mergeVertices(vertices) {
587
600
  let sumX = vertices[i].x, sumY = vertices[i].y;
588
601
  let maxRadius = vertices[i].radius;
589
602
  let count = 1;
590
- for (let j = i + 1; j < vertices.length; j++) {
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) {
591
617
  if (used[j]) continue;
592
618
  const mergeTol = VERTEX_MERGE_FACTOR * Math.max(maxRadius, vertices[j].radius);
593
619
  if (Math.abs(vertices[i].x - vertices[j].x) <= mergeTol && Math.abs(vertices[i].y - vertices[j].y) <= mergeTol) {
@@ -814,6 +840,7 @@ function splitStackedGroup(group) {
814
840
  }
815
841
  return bands.filter((b) => b.length > 0);
816
842
  }
843
+ var GROUP_BUCKET_CELL = 100;
817
844
  function groupConnectedLines(lines) {
818
845
  const parent = lines.map((_, i) => i);
819
846
  function find(x) {
@@ -827,10 +854,34 @@ function groupConnectedLines(lines) {
827
854
  const ra = find(a), rb = find(b);
828
855
  if (ra !== rb) parent[ra] = rb;
829
856
  }
857
+ const cellMap = /* @__PURE__ */ new Map();
830
858
  for (let i = 0; i < lines.length; i++) {
831
- for (let j = i + 1; j < lines.length; j++) {
832
- if (linesIntersect(lines[i], lines[j])) {
833
- union(i, j);
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
+ }
834
885
  }
835
886
  }
836
887
  }
@@ -1223,6 +1274,172 @@ function normalizeUndersegmentedTable(originalCells, colXs, items) {
1223
1274
  return rebuilt;
1224
1275
  }
1225
1276
 
1277
+ // src/pdf/image-extract.ts
1278
+
1279
+ var IMAGE_RESOLVE_TIMEOUT_MS = 5e3;
1280
+ function resolveImgData(page, objId) {
1281
+ const store = objId.startsWith("g_") ? page.commonObjs : page.objs;
1282
+ return new Promise((resolve) => {
1283
+ let done = false;
1284
+ const timer = setTimeout(() => {
1285
+ if (!done) {
1286
+ done = true;
1287
+ resolve(null);
1288
+ }
1289
+ }, IMAGE_RESOLVE_TIMEOUT_MS);
1290
+ try {
1291
+ store.get(objId, (data) => {
1292
+ if (!done) {
1293
+ done = true;
1294
+ clearTimeout(timer);
1295
+ resolve(_nullishCoalesce(data, () => ( null)));
1296
+ }
1297
+ });
1298
+ } catch (e2) {
1299
+ if (!done) {
1300
+ done = true;
1301
+ clearTimeout(timer);
1302
+ resolve(null);
1303
+ }
1304
+ }
1305
+ });
1306
+ }
1307
+ var MIN_DIM = 8;
1308
+ var MAX_PIXELS = 36e6;
1309
+ var MAX_IMAGES_PER_DOC = 200;
1310
+ var MAX_TOTAL_IMAGE_BYTES = 128 * 1024 * 1024;
1311
+ function createPdfImageState() {
1312
+ return { imageIndex: 0, totalBytes: 0, seen: /* @__PURE__ */ new Map(), capWarned: false };
1313
+ }
1314
+ function fnv1a(data) {
1315
+ let h = 2166136261;
1316
+ for (let i = 0; i < data.length; i++) {
1317
+ h ^= data[i];
1318
+ h = Math.imul(h, 16777619);
1319
+ }
1320
+ return h >>> 0;
1321
+ }
1322
+ function toRgba(img) {
1323
+ const { width: w, height: h, kind, data } = img;
1324
+ if (!data || !w || !h) return null;
1325
+ const rgba = new Uint8Array(w * h * 4);
1326
+ if (kind === _pdfmjs.ImageKind.RGBA_32BPP) {
1327
+ if (data.length < w * h * 4) return null;
1328
+ rgba.set(data.subarray(0, w * h * 4));
1329
+ return rgba;
1330
+ }
1331
+ if (kind === _pdfmjs.ImageKind.RGB_24BPP) {
1332
+ if (data.length < w * h * 3) return null;
1333
+ for (let i = 0, s = 0, d = 0; i < w * h; i++, s += 3, d += 4) {
1334
+ rgba[d] = data[s];
1335
+ rgba[d + 1] = data[s + 1];
1336
+ rgba[d + 2] = data[s + 2];
1337
+ rgba[d + 3] = 255;
1338
+ }
1339
+ return rgba;
1340
+ }
1341
+ if (kind === _pdfmjs.ImageKind.GRAYSCALE_1BPP) {
1342
+ const stride = w + 7 >> 3;
1343
+ if (data.length < stride * h) return null;
1344
+ for (let y = 0; y < h; y++) {
1345
+ for (let x = 0; x < w; x++) {
1346
+ const bit = data[y * stride + (x >> 3)] >> 7 - (x & 7) & 1;
1347
+ const v = bit ? 255 : 0;
1348
+ const d = (y * w + x) * 4;
1349
+ rgba[d] = v;
1350
+ rgba[d + 1] = v;
1351
+ rgba[d + 2] = v;
1352
+ rgba[d + 3] = 255;
1353
+ }
1354
+ }
1355
+ return rgba;
1356
+ }
1357
+ return null;
1358
+ }
1359
+ async function extractPageImages(page, fnArray, argsArray, pageNumber, state, warnings) {
1360
+ const blocks = [];
1361
+ const images = [];
1362
+ const pageSeenIds = /* @__PURE__ */ new Set();
1363
+ for (let i = 0; i < fnArray.length; i++) {
1364
+ const op = fnArray[i];
1365
+ let imgData = null;
1366
+ let dedupeId = null;
1367
+ if (op === _pdfmjs.OPS.paintImageXObject || op === _pdfmjs.OPS.paintImageXObjectRepeat) {
1368
+ const objId = _optionalChain([argsArray, 'access', _4 => _4[i], 'optionalAccess', _5 => _5[0]]);
1369
+ if (typeof objId !== "string" || pageSeenIds.has(objId)) continue;
1370
+ pageSeenIds.add(objId);
1371
+ dedupeId = objId;
1372
+ } else if (op !== _pdfmjs.OPS.paintInlineImageXObject) {
1373
+ continue;
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
+ }
1387
+ if (!_optionalChain([imgData, 'optionalAccess', _8 => _8.data]) || !imgData.width || !imgData.height) continue;
1388
+ const { width: w, height: h } = imgData;
1389
+ if (w < MIN_DIM || h < MIN_DIM) continue;
1390
+ if (w * h > MAX_PIXELS) {
1391
+ warnings.push({ page: pageNumber, message: `\uC774\uBBF8\uC9C0 \uD06C\uAE30 \uCD08\uACFC\uB85C \uCD94\uCD9C \uC0DD\uB7B5 (${w}\xD7${h})`, code: "SKIPPED_IMAGE" });
1392
+ continue;
1393
+ }
1394
+ const hash = `${w}x${h}k${_nullishCoalesce(imgData.kind, () => ( "?"))}h${fnv1a(imgData.data)}${dedupeId ? "" : "inline"}`;
1395
+ if (state.seen.has(hash)) continue;
1396
+ const rgba = toRgba(imgData);
1397
+ if (!rgba) continue;
1398
+ const png = _chunk37VKMUSTcjs.encodePng.call(void 0, w, h, rgba);
1399
+ state.imageIndex++;
1400
+ state.totalBytes += png.length;
1401
+ const filename = `image_${String(state.imageIndex).padStart(3, "0")}.png`;
1402
+ state.seen.set(hash, filename);
1403
+ images.push({ filename, data: png, mimeType: "image/png" });
1404
+ blocks.push({ type: "image", text: filename, pageNumber });
1405
+ }
1406
+ return { blocks, images };
1407
+ }
1408
+ function injectPageImageBlocks(blocks, pageImages) {
1409
+ if (pageImages.size === 0) return;
1410
+ const lastIndexForPage = /* @__PURE__ */ new Map();
1411
+ for (let i = 0; i < blocks.length; i++) {
1412
+ const p = blocks[i].pageNumber;
1413
+ if (p !== void 0) lastIndexForPage.set(p, i);
1414
+ }
1415
+ const pageAtIndex = /* @__PURE__ */ new Map();
1416
+ for (const [p, last] of lastIndexForPage) pageAtIndex.set(last, p);
1417
+ const result = [];
1418
+ const injected = /* @__PURE__ */ new Set();
1419
+ for (let i = 0; i < blocks.length; i++) {
1420
+ result.push(blocks[i]);
1421
+ const p = pageAtIndex.get(i);
1422
+ if (p !== void 0 && pageImages.has(p)) {
1423
+ result.push(...pageImages.get(p));
1424
+ injected.add(p);
1425
+ }
1426
+ }
1427
+ for (const p of [...pageImages.keys()].sort((a, b) => a - b)) {
1428
+ if (injected.has(p)) continue;
1429
+ let at = result.length;
1430
+ for (let i = 0; i < result.length; i++) {
1431
+ const bp = result[i].pageNumber;
1432
+ if (bp !== void 0 && bp > p) {
1433
+ at = i;
1434
+ break;
1435
+ }
1436
+ }
1437
+ result.splice(at, 0, ...pageImages.get(p));
1438
+ }
1439
+ blocks.length = 0;
1440
+ blocks.push(...result);
1441
+ }
1442
+
1226
1443
  // src/pdf/quality.ts
1227
1444
  var RARE_JONG = /* @__PURE__ */ new Set([3, 5, 6, 9, 10, 11, 12, 13, 14, 15, 18, 24, 25, 26]);
1228
1445
  var MOJIBAKE_MIN_HANGUL = 30;
@@ -1408,7 +1625,7 @@ function dominantStyle(items) {
1408
1625
  }
1409
1626
  }
1410
1627
  if (dominantSize === 0) return void 0;
1411
- const fontName = _optionalChain([items, 'access', _4 => _4.find, 'call', _5 => _5((i) => i.fontSize === dominantSize), 'optionalAccess', _6 => _6.fontName]) || void 0;
1628
+ const fontName = _optionalChain([items, 'access', _9 => _9.find, 'call', _10 => _10((i) => i.fontSize === dominantSize), 'optionalAccess', _11 => _11.fontName]) || void 0;
1412
1629
  return fontName ? { fontSize: dominantSize, fontName } : { fontSize: dominantSize };
1413
1630
  }
1414
1631
  function normalizeItems(rawItems) {
@@ -1529,7 +1746,7 @@ function mergeSuperscriptLines(lines) {
1529
1746
  return result;
1530
1747
  }
1531
1748
  function mergeLineSimple(items) {
1532
- if (items.length <= 1) return _optionalChain([items, 'access', _7 => _7[0], 'optionalAccess', _8 => _8.text]) || "";
1749
+ if (items.length <= 1) return _optionalChain([items, 'access', _12 => _12[0], 'optionalAccess', _13 => _13.text]) || "";
1533
1750
  const sorted = [...items].sort((a, b) => a.x - b.x);
1534
1751
  const isEvenSpaced = detectEvenSpacedItems(sorted);
1535
1752
  let result = sorted[0].text;
@@ -1616,12 +1833,12 @@ function isTwoColumnProse(r) {
1616
1833
  if (t.rows < 8) return false;
1617
1834
  const dense = [];
1618
1835
  for (let c = 0; c < t.cols; c++) {
1619
- const filled = t.cells.filter((row) => _optionalChain([row, 'access', _9 => _9[c], 'optionalAccess', _10 => _10.text, 'access', _11 => _11.trim, 'call', _12 => _12()])).length;
1836
+ const filled = t.cells.filter((row) => _optionalChain([row, 'access', _14 => _14[c], 'optionalAccess', _15 => _15.text, 'access', _16 => _16.trim, 'call', _17 => _17()])).length;
1620
1837
  if (filled / t.rows >= 0.3) dense.push(c);
1621
1838
  }
1622
1839
  if (dense.length !== 2) return false;
1623
1840
  for (const c of dense) {
1624
- const lens = t.cells.map((row) => _nullishCoalesce(_optionalChain([row, 'access', _13 => _13[c], 'optionalAccess', _14 => _14.text, 'access', _15 => _15.replace, 'call', _16 => _16(/\s+/g, ""), 'access', _17 => _17.length]), () => ( 0))).filter((n) => n > 0);
1841
+ const lens = t.cells.map((row) => _nullishCoalesce(_optionalChain([row, 'access', _18 => _18[c], 'optionalAccess', _19 => _19.text, 'access', _20 => _20.replace, 'call', _21 => _21(/\s+/g, ""), 'access', _22 => _22.length]), () => ( 0))).filter((n) => n > 0);
1625
1842
  const avg = lens.reduce((s, v) => s + v, 0) / (lens.length || 1);
1626
1843
  if (avg < 12) return false;
1627
1844
  }
@@ -2098,7 +2315,7 @@ function buildClusterTable(rows, columns, pageNum) {
2098
2315
  const nonEmptyCols = cells[r].filter((c) => c.text.trim()).length;
2099
2316
  if (nonEmptyCols !== 1) continue;
2100
2317
  if (cells[r][0].text.trim() !== "") continue;
2101
- const contentText = _optionalChain([cells, 'access', _18 => _18[r], 'access', _19 => _19.find, 'call', _20 => _20((c) => c.text.trim()), 'optionalAccess', _21 => _21.text, 'access', _22 => _22.trim, 'call', _23 => _23()]) || "";
2318
+ const contentText = _optionalChain([cells, 'access', _23 => _23[r], 'access', _24 => _24.find, 'call', _25 => _25((c) => c.text.trim()), 'optionalAccess', _26 => _26.text, 'access', _27 => _27.trim, 'call', _28 => _28()]) || "";
2102
2319
  if (/^[○●▶\-·]/.test(contentText)) continue;
2103
2320
  for (let pr = r - 1; pr >= 0; pr--) {
2104
2321
  if (cells[pr].some((c) => c.text.trim())) {
@@ -2320,14 +2537,14 @@ function isProseSpread(items) {
2320
2537
  for (let i = 1; i < sorted.length; i++) {
2321
2538
  gaps.push(sorted[i].x - (sorted[i - 1].x + sorted[i - 1].w));
2322
2539
  }
2323
- const maxGap = _chunkU25XGCNHcjs.safeMax.call(void 0, gaps);
2540
+ const maxGap = _chunk37VKMUSTcjs.safeMax.call(void 0, gaps);
2324
2541
  const avgLen = items.reduce((s, i) => s + i.text.length, 0) / items.length;
2325
2542
  return maxGap < 40 && avgLen < 5;
2326
2543
  }
2327
2544
  function detectColumns(yLines) {
2328
2545
  const allItems = yLines.flat();
2329
2546
  if (allItems.length === 0) return null;
2330
- const pageWidth = _chunkU25XGCNHcjs.safeMax.call(void 0, allItems.map((i) => i.x + i.w)) - _chunkU25XGCNHcjs.safeMin.call(void 0, allItems.map((i) => i.x));
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));
2331
2548
  if (pageWidth < 100) return null;
2332
2549
  let bigoLineIdx = -1;
2333
2550
  for (let i = 0; i < yLines.length; i++) {
@@ -2518,11 +2735,12 @@ function buildGridTable(lines, columns) {
2518
2735
  if (filledCells < totalCells * 0.35 || merged.length < 2 || merged.length <= 3 && numCols >= 7) {
2519
2736
  return merged.map((r) => r.filter((c) => c).join(" ")).join("\n");
2520
2737
  }
2738
+ const escCell = (c) => c.replace(/\t/g, " ").replace(/\|/g, "\\|");
2521
2739
  const md = [];
2522
- md.push("| " + merged[0].join(" | ") + " |");
2740
+ md.push("| " + merged[0].map(escCell).join(" | ") + " |");
2523
2741
  md.push("| " + merged[0].map(() => "---").join(" | ") + " |");
2524
2742
  for (let r = 1; r < merged.length; r++) {
2525
- md.push("| " + merged[r].join(" | ") + " |");
2743
+ md.push("| " + merged[r].map(escCell).join(" | ") + " |");
2526
2744
  }
2527
2745
  return md.join("\n");
2528
2746
  }
@@ -2543,15 +2761,15 @@ function computeMedianFontSizeFromFreq(freq) {
2543
2761
  }
2544
2762
  function detectHeadings(blocks, medianFontSize) {
2545
2763
  for (const block of blocks) {
2546
- if (block.type !== "paragraph" || !block.text || !_optionalChain([block, 'access', _24 => _24.style, 'optionalAccess', _25 => _25.fontSize])) continue;
2764
+ if (block.type !== "paragraph" || !block.text || !_optionalChain([block, 'access', _29 => _29.style, 'optionalAccess', _30 => _30.fontSize])) continue;
2547
2765
  const text = block.text.trim();
2548
2766
  if (text.length === 0 || text.length > 200) continue;
2549
2767
  if (/^\d+$/.test(text)) continue;
2550
2768
  const ratio = block.style.fontSize / medianFontSize;
2551
2769
  let level = 0;
2552
- if (ratio >= _chunkU25XGCNHcjs.HEADING_RATIO_H1) level = 1;
2553
- else if (ratio >= _chunkU25XGCNHcjs.HEADING_RATIO_H2) level = 2;
2554
- else if (ratio >= _chunkU25XGCNHcjs.HEADING_RATIO_H3) level = 3;
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;
2555
2773
  if (level > 0) {
2556
2774
  block.type = "heading";
2557
2775
  block.level = level;
@@ -2604,7 +2822,7 @@ function detectMarkerHeadings(blocks) {
2604
2822
  block.level = 4;
2605
2823
  continue;
2606
2824
  }
2607
- if (/^[가-힣]{2,6}$/.test(text) && _optionalChain([block, 'access', _26 => _26.style, 'optionalAccess', _27 => _27.fontSize])) {
2825
+ if (/^[가-힣]{2,6}$/.test(text) && _optionalChain([block, 'access', _31 => _31.style, 'optionalAccess', _32 => _32.fontSize])) {
2608
2826
  const prev = blocks[i - 1];
2609
2827
  const next = blocks[i + 1];
2610
2828
  const prevIsStructural = !prev || prev.type === "table" || prev.type === "heading" || prev.type === "separator";
@@ -2702,6 +2920,7 @@ function detectKoreanListBlocks(blocks) {
2702
2920
  }
2703
2921
  let familyStack = [];
2704
2922
  let lastTopLevelList = null;
2923
+ let prevListIdx = -2;
2705
2924
  const toRemove = /* @__PURE__ */ new Set();
2706
2925
  for (let i = 0; i < blocks.length; i++) {
2707
2926
  const b = blocks[i];
@@ -2730,7 +2949,7 @@ function detectKoreanListBlocks(blocks) {
2730
2949
  if (depth === 0) {
2731
2950
  blocks[i] = listBlock;
2732
2951
  lastTopLevelList = listBlock;
2733
- } else if (lastTopLevelList) {
2952
+ } else if (lastTopLevelList && i === prevListIdx + 1) {
2734
2953
  if (!lastTopLevelList.children) lastTopLevelList.children = [];
2735
2954
  lastTopLevelList.children.push(listBlock);
2736
2955
  toRemove.add(i);
@@ -2738,6 +2957,7 @@ function detectKoreanListBlocks(blocks) {
2738
2957
  blocks[i] = listBlock;
2739
2958
  lastTopLevelList = listBlock;
2740
2959
  }
2960
+ prevListIdx = i;
2741
2961
  }
2742
2962
  if (toRemove.size > 0) {
2743
2963
  const sorted = [...toRemove].sort((a, b) => b - a);
@@ -2857,14 +3077,14 @@ function removeHeaderFooterBlocks(blocks, pageHeights, warnings) {
2857
3077
  const bottomEntries = [];
2858
3078
  for (let bi = 0; bi < blocks.length; bi++) {
2859
3079
  const b = blocks[bi];
2860
- if (!b.bbox || !b.pageNumber || !_optionalChain([b, 'access', _28 => _28.text, 'optionalAccess', _29 => _29.trim, 'call', _30 => _30()])) continue;
3080
+ if (!b.bbox || !b.pageNumber || !_optionalChain([b, 'access', _33 => _33.text, 'optionalAccess', _34 => _34.trim, 'call', _35 => _35()])) continue;
2861
3081
  const ph = pageHeights.get(b.bbox.page) || pageHeights.get(b.pageNumber);
2862
3082
  if (!ph) continue;
2863
3083
  const blockTop = ph - (b.bbox.y + b.bbox.height);
2864
3084
  const blockBottom = ph - b.bbox.y;
2865
3085
  const entry = { blockIdx: bi, page: b.pageNumber, text: b.text.trim() };
2866
- if (blockBottom <= ph * ZONE_RATIO) bottomEntries.push(entry);
2867
- else if (blockTop >= ph * (1 - ZONE_RATIO)) topEntries.push(entry);
3086
+ if (blockBottom <= ph * ZONE_RATIO) topEntries.push(entry);
3087
+ else if (blockTop >= ph * (1 - ZONE_RATIO)) bottomEntries.push(entry);
2868
3088
  }
2869
3089
  const removeSet = /* @__PURE__ */ new Set();
2870
3090
  for (const entries of [topEntries, bottomEntries]) {
@@ -2880,7 +3100,7 @@ function removeHeaderFooterBlocks(blocks, pageHeights, warnings) {
2880
3100
  }
2881
3101
  const repeatedPatterns = /* @__PURE__ */ new Set();
2882
3102
  for (const [p, count] of patternCount) {
2883
- if (count >= MIN_REPEAT && (_nullishCoalesce(_optionalChain([patternPages, 'access', _31 => _31.get, 'call', _32 => _32(p), 'optionalAccess', _33 => _33.size]), () => ( 0))) >= MIN_REPEAT) {
3103
+ if (count >= MIN_REPEAT && (_nullishCoalesce(_optionalChain([patternPages, 'access', _36 => _36.get, 'call', _37 => _37(p), 'optionalAccess', _38 => _38.size]), () => ( 0))) >= MIN_REPEAT) {
2884
3104
  repeatedPatterns.add(p);
2885
3105
  }
2886
3106
  }
@@ -3037,6 +3257,8 @@ function extractBlocksWithGrids(items, pageNum, grids, horizontals, verticals) {
3037
3257
  hasSpaceBefore: i.hasSpaceBefore
3038
3258
  }));
3039
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);
3040
3262
  const numRows = grid.rowYs.length - 1;
3041
3263
  const numCols = grid.colXs.length - 1;
3042
3264
  const irGrid = Array.from(
@@ -3056,9 +3278,11 @@ function extractBlocksWithGrids(items, pageNum, grids, horizontals, verticals) {
3056
3278
  }
3057
3279
  let finalGrid = irGrid;
3058
3280
  let finalRows = numRows;
3281
+ let rebuiltUsed = false;
3059
3282
  if (numRows <= 2 && numCols >= 3) {
3060
3283
  const rebuilt = normalizeUndersegmentedTable(irGrid, grid.colXs, textItems);
3061
3284
  if (rebuilt) {
3285
+ rebuiltUsed = true;
3062
3286
  finalGrid = rebuilt.map((row) => row.map((rawText) => {
3063
3287
  const cleaned = rawText.replace(/^[\s]*[-–—]\s*\d+\s*[-–—][\s]*$/gm, "").trim();
3064
3288
  return {
@@ -3070,6 +3294,11 @@ function extractBlocksWithGrids(items, pageNum, grids, horizontals, verticals) {
3070
3294
  finalRows = finalGrid.length;
3071
3295
  }
3072
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
+ }
3073
3302
  const irTable = {
3074
3303
  rows: finalRows,
3075
3304
  cols: numCols,
@@ -3126,25 +3355,39 @@ function extractBlocksWithGrids(items, pageNum, grids, horizontals, verticals) {
3126
3355
  }
3127
3356
  remaining = remaining.filter((_, idx) => !usedClusterIndices.has(idx));
3128
3357
  }
3358
+ const groupSizes = [];
3359
+ let finalTextBlocks = [];
3129
3360
  if (remaining.length > 0) {
3130
3361
  const allY = remaining.map((i) => i.y);
3131
- const pageH = _chunkU25XGCNHcjs.safeMax.call(void 0, allY) - _chunkU25XGCNHcjs.safeMin.call(void 0, allY);
3362
+ const pageH = _chunk37VKMUSTcjs.safeMax.call(void 0, allY) - _chunk37VKMUSTcjs.safeMin.call(void 0, allY);
3132
3363
  const groups = xyCutOrder(remaining, Math.max(15, pageH * 0.03));
3133
3364
  const textBlocks = [];
3134
3365
  for (const group of groups) {
3135
3366
  if (group.length === 0) continue;
3136
3367
  const groupBlocks = extractPageBlocksFallback(group, pageNum);
3137
3368
  for (const b of groupBlocks) textBlocks.push(b);
3369
+ groupSizes.push(groupBlocks.length);
3138
3370
  }
3139
- const finalTextBlocks = detectListBlocks(textBlocks);
3140
- for (const b of finalTextBlocks) blocks.push(b);
3371
+ finalTextBlocks = detectListBlocks(textBlocks);
3141
3372
  }
3142
- blocks.sort((a, b) => {
3143
- const ay = a.bbox ? a.bbox.y + a.bbox.height : 0;
3144
- const by = b.bbox ? b.bbox.y + b.bbox.height : 0;
3145
- return by - ay;
3146
- });
3147
- return mergeAdjacentTableBlocks(blocks);
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);
3148
3391
  }
3149
3392
  return mergeAdjacentTableBlocks(blocks);
3150
3393
  }
@@ -3304,7 +3547,7 @@ function extractPageBlocksFallback(items, pageNum, fullPage = false) {
3304
3547
  blocks.push({ type: "paragraph", text: tableText, pageNumber: pageNum, bbox, style: dominantStyle(items) });
3305
3548
  } else {
3306
3549
  const allY = items.map((i) => i.y);
3307
- const pageHeight = _chunkU25XGCNHcjs.safeMax.call(void 0, allY) - _chunkU25XGCNHcjs.safeMin.call(void 0, allY);
3550
+ const pageHeight = _chunk37VKMUSTcjs.safeMax.call(void 0, allY) - _chunk37VKMUSTcjs.safeMin.call(void 0, allY);
3308
3551
  const gapThreshold = Math.max(15, pageHeight * 0.03);
3309
3552
  const orderedGroups = proseCutX !== null ? splitTwoColumnProse(items, proseCutX) : xyCutOrder(items, gapThreshold);
3310
3553
  for (const group of orderedGroups) {
@@ -3390,7 +3633,7 @@ function mergeKoreanLines(text) {
3390
3633
 
3391
3634
  // src/pdf/formula-ocr.ts
3392
3635
  async function applyFormulaOcr(buffer, blocks, pageFilter, effectivePageCount, warnings, _onProgress) {
3393
- const formulaMod = await Promise.resolve().then(() => _interopRequireWildcard(require("./formula-ZYUDQHD3.cjs")));
3636
+ const formulaMod = await Promise.resolve().then(() => _interopRequireWildcard(require("./formula-5NKVS2LR.cjs")));
3394
3637
  const { FormulaPipeline, ensureFormulaModels } = formulaMod;
3395
3638
  await ensureFormulaModels((p) => {
3396
3639
  if (p.phase === "download" && p.total) {
@@ -3540,7 +3783,7 @@ try {
3540
3783
  pdfjsAssets.cMapUrl = _path.join.call(void 0, pkgDir, "cmaps") + "/";
3541
3784
  pdfjsAssets.cMapPacked = true;
3542
3785
  pdfjsAssets.standardFontDataUrl = _path.join.call(void 0, pkgDir, "standard_fonts") + "/";
3543
- } catch (e2) {
3786
+ } catch (e3) {
3544
3787
  }
3545
3788
  async function loadPdfWithTimeout(buffer) {
3546
3789
  const loadingTask = _pdfmjs.getDocument.call(void 0, {
@@ -3557,7 +3800,7 @@ async function loadPdfWithTimeout(buffer) {
3557
3800
  new Promise((_, reject) => {
3558
3801
  timer = setTimeout(() => {
3559
3802
  loadingTask.destroy();
3560
- reject(new (0, _chunkU25XGCNHcjs.KordocError)("PDF \uB85C\uB529 \uD0C0\uC784\uC544\uC6C3 (30\uCD08 \uCD08\uACFC)"));
3803
+ reject(new (0, _chunk37VKMUSTcjs.KordocError)("PDF \uB85C\uB529 \uD0C0\uC784\uC544\uC6C3 (30\uCD08 \uCD08\uACFC)"));
3561
3804
  }, PDF_LOAD_TIMEOUT_MS);
3562
3805
  })
3563
3806
  ]);
@@ -3566,11 +3809,11 @@ async function loadPdfWithTimeout(buffer) {
3566
3809
  }
3567
3810
  }
3568
3811
  async function parsePdfDocument(buffer, options) {
3569
- const formulaBuffer = _optionalChain([options, 'optionalAccess', _34 => _34.formulaOcr]) ? buffer.slice(0) : null;
3812
+ const formulaBuffer = _optionalChain([options, 'optionalAccess', _39 => _39.formulaOcr]) ? buffer.slice(0) : null;
3570
3813
  const doc = await loadPdfWithTimeout(buffer);
3571
3814
  try {
3572
3815
  const pageCount = doc.numPages;
3573
- if (pageCount === 0) throw new (0, _chunkU25XGCNHcjs.KordocError)("PDF\uC5D0 \uD398\uC774\uC9C0\uAC00 \uC5C6\uC2B5\uB2C8\uB2E4.");
3816
+ if (pageCount === 0) throw new (0, _chunk37VKMUSTcjs.KordocError)("PDF\uC5D0 \uD398\uC774\uC9C0\uAC00 \uC5C6\uC2B5\uB2C8\uB2E4.");
3574
3817
  const metadata = { pageCount };
3575
3818
  await extractPdfMetadata(doc, metadata);
3576
3819
  const blocks = [];
@@ -3579,12 +3822,15 @@ async function parsePdfDocument(buffer, options) {
3579
3822
  let totalChars = 0;
3580
3823
  let totalTextBytes = 0;
3581
3824
  const effectivePageCount = Math.min(pageCount, MAX_PAGES);
3582
- const pageFilter = _optionalChain([options, 'optionalAccess', _35 => _35.pages]) ? _chunkX34YWRL5cjs.parsePageRange.call(void 0, options.pages, effectivePageCount) : null;
3825
+ const pageFilter = _optionalChain([options, 'optionalAccess', _40 => _40.pages]) ? _chunkDCZVOIEOcjs.parsePageRange.call(void 0, options.pages, effectivePageCount) : null;
3583
3826
  const totalTarget = pageFilter ? pageFilter.size : effectivePageCount;
3584
3827
  const fontSizeFreq = /* @__PURE__ */ new Map();
3585
3828
  const pageHeights = /* @__PURE__ */ new Map();
3586
3829
  const pagesWithLargeImage = /* @__PURE__ */ new Set();
3587
3830
  const skippedImagePages = /* @__PURE__ */ new Map();
3831
+ const imageState = createPdfImageState();
3832
+ const extractedImages = [];
3833
+ const pageImageBlocks = /* @__PURE__ */ new Map();
3588
3834
  let parsedPages = 0;
3589
3835
  for (let i = 1; i <= effectivePageCount; i++) {
3590
3836
  if (pageFilter && !pageFilter.has(i)) continue;
@@ -3622,34 +3868,44 @@ async function parsePdfDocument(buffer, options) {
3622
3868
  }
3623
3869
  const pageBlocks = extractPageBlocksWithLines(visible, i, opList, viewport.width, viewport.height);
3624
3870
  for (const b of pageBlocks) blocks.push(b);
3871
+ try {
3872
+ const { blocks: imgBlocks, images: pageImages } = await extractPageImages(page, opList.fnArray, opList.argsArray, i, imageState, warnings);
3873
+ if (imgBlocks.length > 0) pageImageBlocks.set(i, imgBlocks);
3874
+ extractedImages.push(...pageImages);
3875
+ } catch (e4) {
3876
+ }
3625
3877
  let pageText = "";
3626
3878
  for (const b of pageBlocks) {
3627
- const t = b.text || "";
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
+ }
3628
3884
  totalChars += t.replace(/\s/g, "").length;
3629
3885
  totalTextBytes += t.length * 2;
3630
3886
  pageText += pageText ? "\n" + t : t;
3631
3887
  }
3632
3888
  pageQuality.push(computePageQuality(i, pageText));
3633
- if (totalTextBytes > MAX_TOTAL_TEXT) throw new (0, _chunkU25XGCNHcjs.KordocError)("\uD14D\uC2A4\uD2B8 \uCD94\uCD9C \uD06C\uAE30 \uCD08\uACFC");
3889
+ if (totalTextBytes > MAX_TOTAL_TEXT) throw new (0, _chunk37VKMUSTcjs.KordocError)("\uD14D\uC2A4\uD2B8 \uCD94\uCD9C \uD06C\uAE30 \uCD08\uACFC");
3634
3890
  parsedPages++;
3635
- _optionalChain([options, 'optionalAccess', _36 => _36.onProgress, 'optionalCall', _37 => _37(parsedPages, totalTarget)]);
3891
+ _optionalChain([options, 'optionalAccess', _41 => _41.onProgress, 'optionalCall', _42 => _42(parsedPages, totalTarget)]);
3636
3892
  } catch (pageErr) {
3637
- if (pageErr instanceof _chunkU25XGCNHcjs.KordocError) throw pageErr;
3893
+ if (pageErr instanceof _chunk37VKMUSTcjs.KordocError) throw pageErr;
3638
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" });
3639
3895
  }
3640
3896
  }
3641
3897
  const parsedPageCount = parsedPages || (pageFilter ? pageFilter.size : effectivePageCount);
3642
3898
  let isImageBased = false;
3643
3899
  if (totalChars / Math.max(parsedPageCount, 1) < 10) {
3644
- if (_optionalChain([options, 'optionalAccess', _38 => _38.ocr])) {
3900
+ if (_optionalChain([options, 'optionalAccess', _43 => _43.ocr])) {
3645
3901
  try {
3646
- const { ocrPages } = await Promise.resolve().then(() => _interopRequireWildcard(require("./provider-5K7O3Z2O.cjs")));
3902
+ const { ocrPages } = await Promise.resolve().then(() => _interopRequireWildcard(require("./provider-4FAYHJ6N.cjs")));
3647
3903
  const ocrBlocks = await ocrPages(doc, options.ocr, pageFilter, effectivePageCount);
3648
3904
  if (ocrBlocks.length > 0) {
3649
3905
  const ocrMarkdown = ocrBlocks.map((b) => b.text || "").filter(Boolean).join("\n\n");
3650
- return { markdown: ocrMarkdown, blocks: ocrBlocks, metadata, warnings, isImageBased: true, pageQuality, qualitySummary: summarizeDocumentQuality(pageQuality) };
3906
+ return { markdown: ocrMarkdown, blocks: ocrBlocks, metadata, warnings, isImageBased: true, pageQuality, qualitySummary: summarizeDocumentQuality(pageQuality), images: extractedImages.length > 0 ? extractedImages : void 0 };
3651
3907
  }
3652
- } catch (e3) {
3908
+ } catch (e5) {
3653
3909
  }
3654
3910
  }
3655
3911
  isImageBased = true;
@@ -3677,14 +3933,15 @@ async function parsePdfDocument(buffer, options) {
3677
3933
  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" });
3678
3934
  }
3679
3935
  }
3680
- if (_optionalChain([options, 'optionalAccess', _39 => _39.removeHeaderFooter]) !== false && parsedPageCount >= 3) {
3936
+ if (_optionalChain([options, 'optionalAccess', _44 => _44.removeHeaderFooter]) !== false && parsedPageCount >= 3) {
3681
3937
  const removed = removeHeaderFooterBlocks(blocks, pageHeights, warnings);
3682
3938
  for (let ri = removed.length - 1; ri >= 0; ri--) {
3683
3939
  blocks.splice(removed[ri], 1);
3684
3940
  }
3685
3941
  }
3686
3942
  mergeCrossPageTables(blocks);
3687
- if (_optionalChain([options, 'optionalAccess', _40 => _40.formulaOcr]) && formulaBuffer) {
3943
+ injectPageImageBlocks(blocks, pageImageBlocks);
3944
+ if (_optionalChain([options, 'optionalAccess', _45 => _45.formulaOcr]) && formulaBuffer) {
3688
3945
  try {
3689
3946
  await applyFormulaOcr(formulaBuffer, blocks, pageFilter, effectivePageCount, warnings, options.onProgress);
3690
3947
  } catch (e) {
@@ -3703,7 +3960,7 @@ async function parsePdfDocument(buffer, options) {
3703
3960
  detectKoreanListBlocks(blocks);
3704
3961
  const outline = blocks.filter((b) => b.type === "heading" && b.level && b.text).map((b) => ({ level: b.level, text: b.text, pageNumber: b.pageNumber }));
3705
3962
  sanitizeBlockControlChars(blocks);
3706
- let markdown = cleanPdfText(_chunkU25XGCNHcjs.blocksToMarkdown.call(void 0, blocks));
3963
+ let markdown = cleanPdfText(_chunk37VKMUSTcjs.blocksToMarkdown.call(void 0, blocks));
3707
3964
  return {
3708
3965
  markdown,
3709
3966
  blocks,
@@ -3712,7 +3969,8 @@ async function parsePdfDocument(buffer, options) {
3712
3969
  warnings: warnings.length > 0 ? warnings : void 0,
3713
3970
  isImageBased: isImageBased || void 0,
3714
3971
  pageQuality,
3715
- qualitySummary: summarizeDocumentQuality(pageQuality)
3972
+ qualitySummary: summarizeDocumentQuality(pageQuality),
3973
+ images: extractedImages.length > 0 ? extractedImages : void 0
3716
3974
  };
3717
3975
  } finally {
3718
3976
  await doc.destroy().catch(() => {
@@ -3722,7 +3980,7 @@ async function parsePdfDocument(buffer, options) {
3722
3980
  async function extractPdfMetadata(doc, metadata) {
3723
3981
  try {
3724
3982
  const result = await doc.getMetadata();
3725
- if (!_optionalChain([result, 'optionalAccess', _41 => _41.info])) return;
3983
+ if (!_optionalChain([result, 'optionalAccess', _46 => _46.info])) return;
3726
3984
  const info = result.info;
3727
3985
  if (typeof info.Title === "string" && info.Title.trim()) metadata.title = info.Title.trim();
3728
3986
  if (typeof info.Author === "string" && info.Author.trim()) metadata.author = info.Author.trim();
@@ -3733,7 +3991,7 @@ async function extractPdfMetadata(doc, metadata) {
3733
3991
  }
3734
3992
  if (typeof info.CreationDate === "string") metadata.createdAt = parsePdfDate(info.CreationDate);
3735
3993
  if (typeof info.ModDate === "string") metadata.modifiedAt = parsePdfDate(info.ModDate);
3736
- } catch (e4) {
3994
+ } catch (e6) {
3737
3995
  }
3738
3996
  }
3739
3997
  function parsePdfDate(dateStr) {
@@ -3762,4 +4020,4 @@ async function extractPdfMetadataOnly(buffer) {
3762
4020
 
3763
4021
 
3764
4022
  exports.cleanPdfText = cleanPdfText; exports.detectKoreanListBlocks = detectKoreanListBlocks; exports.detectTableCaptions = detectTableCaptions; exports.extractPdfMetadataOnly = extractPdfMetadataOnly; exports.mergeCrossPageTables = mergeCrossPageTables; exports.parsePdfDocument = parsePdfDocument; exports.removeHeaderFooterBlocks = removeHeaderFooterBlocks;
3765
- //# sourceMappingURL=parser-E6U5TNAU.cjs.map
4023
+ //# sourceMappingURL=parser-N4A7UGDK.cjs.map