kordoc 4.16.2 → 4.17.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 (150) hide show
  1. package/README.md +14 -13
  2. package/dist/{-4G6MA4X6.js → -PRAKO6M4.js} +11 -11
  3. package/dist/{chunk-AUWGDP4G.js → chunk-2KF5WZCR.js} +2 -2
  4. package/dist/{chunk-UTP2WCHS.js → chunk-4GSF2R7T.js} +4 -4
  5. package/dist/{chunk-TXUKTOG2.js → chunk-4XVNQAK5.js} +219 -23
  6. package/dist/chunk-4XVNQAK5.js.map +1 -0
  7. package/dist/chunk-5CDUL6PH.js +250 -0
  8. package/dist/chunk-5CDUL6PH.js.map +1 -0
  9. package/dist/{chunk-4VODJKFL.js → chunk-6RGGYQQC.js} +3 -3
  10. package/dist/{chunk-DES2LGFZ.js → chunk-A55JGNKD.js} +2 -2
  11. package/dist/chunk-AKB72TEH.cjs +248 -0
  12. package/dist/chunk-AKB72TEH.cjs.map +1 -0
  13. package/dist/{chunk-LEIAEWZ7.js → chunk-BFT5IM2R.js} +2 -2
  14. package/dist/{chunk-KIOQ4N37.js → chunk-BLPR4HRF.js} +2 -2
  15. package/dist/{chunk-JELRWAZC.js → chunk-BZG7K44Z.js} +2 -2
  16. package/dist/{chunk-F4NRLLY4.js → chunk-EFO6JZY6.js} +2 -2
  17. package/dist/chunk-GS7T56RP.cjs.map +1 -1
  18. package/dist/{chunk-JFLAM3MM.js → chunk-I5DJOP62.js} +2 -2
  19. package/dist/chunk-I5DJOP62.js.map +1 -0
  20. package/dist/chunk-J55UQC5H.cjs.map +1 -1
  21. package/dist/{chunk-QOCS7W7R.js → chunk-K2VYABZ3.js} +86 -43
  22. package/dist/chunk-K2VYABZ3.js.map +1 -0
  23. package/dist/chunk-MJBCXW5R.js +248 -0
  24. package/dist/chunk-MJBCXW5R.js.map +1 -0
  25. package/dist/{chunk-MLIS253L.js → chunk-ML4NHUR7.js} +2 -2
  26. package/dist/{chunk-GO5IFOUF.js → chunk-N6V7LQBL.js} +2 -2
  27. package/dist/{chunk-FKUDAIJI.cjs → chunk-O7OUX6NU.cjs} +12 -12
  28. package/dist/chunk-O7OUX6NU.cjs.map +1 -0
  29. package/dist/{chunk-S2PL227Q.js → chunk-PHID6WNG.js} +2 -2
  30. package/dist/{chunk-IQGIT2VX.js → chunk-QJWVMPB6.js} +34 -17
  31. package/dist/chunk-QJWVMPB6.js.map +1 -0
  32. package/dist/{chunk-STM3ORY7.cjs → chunk-QNJLLF4J.cjs} +2 -2
  33. package/dist/chunk-QNJLLF4J.cjs.map +1 -0
  34. package/dist/{chunk-FSDJLAOW.js → chunk-QPJXYJIK.js} +55 -1
  35. package/dist/chunk-QPJXYJIK.js.map +1 -0
  36. package/dist/{chunk-XTFN5WKS.cjs → chunk-R2BUANHQ.cjs} +6 -6
  37. package/dist/chunk-R2BUANHQ.cjs.map +1 -0
  38. package/dist/{chunk-OXLPVQYK.js → chunk-TDQ6XDB3.js} +3 -3
  39. package/dist/{chunk-SFEQYKYJ.js → chunk-WN6OD2CQ.js} +218 -22
  40. package/dist/chunk-WN6OD2CQ.js.map +1 -0
  41. package/dist/{chunk-5KS5PWJR.js → chunk-WY5JAR4O.js} +2 -2
  42. package/dist/{chunk-CEIATRDW.cjs → chunk-WYON5ANU.cjs} +3 -3
  43. package/dist/chunk-WYON5ANU.cjs.map +1 -0
  44. package/dist/{chunk-WDQTFAXY.cjs → chunk-XEPKOC2O.cjs} +240 -44
  45. package/dist/chunk-XEPKOC2O.cjs.map +1 -0
  46. package/dist/{chunk-7KNGSQU7.js → chunk-YZ5HHS6A.js} +2 -2
  47. package/dist/{chunk-P6ZDXTV6.js → chunk-ZF6KHPB7.js} +2 -2
  48. package/dist/chunks-YBFBLJ4G.js +10 -0
  49. package/dist/cli.js +36 -54
  50. package/dist/cli.js.map +1 -1
  51. package/dist/{formula-NARUOXRX.js → formula-7MMFBRGJ.js} +4 -4
  52. package/dist/{formula-WIMV5TUX.cjs → formula-ECNOZT36.cjs} +9 -9
  53. package/dist/formula-ECNOZT36.cjs.map +1 -0
  54. package/dist/{formula-EPKLPDU7.js → formula-SHBXRXOJ.js} +3 -3
  55. package/dist/{image-ocr-3WJ4QH3T.js → image-ocr-P6ECJCT2.js} +8 -8
  56. package/dist/{image-ocr-5BUJQ4TK.js → image-ocr-QCT3A7X5.js} +6 -6
  57. package/dist/{image-ocr-AXWXR6JV.cjs → image-ocr-VUDSP2B4.cjs} +15 -15
  58. package/dist/image-ocr-VUDSP2B4.cjs.map +1 -0
  59. package/dist/index.cjs +768 -710
  60. package/dist/index.cjs.map +1 -1
  61. package/dist/index.d.cts +4 -0
  62. package/dist/index.d.ts +4 -0
  63. package/dist/index.js +106 -48
  64. package/dist/index.js.map +1 -1
  65. package/dist/mcp.js +38 -43
  66. package/dist/mcp.js.map +1 -1
  67. package/dist/{model-bundle-IMBW7D2Z.js → model-bundle-OUHGCEZY.js} +5 -5
  68. package/dist/{models-SY75IBOE.js → models-6D6LMOTH.js} +5 -5
  69. package/dist/page-range-QHHFTL7X.cjs.map +1 -1
  70. package/dist/{parser-ZQM3664Z.js → parser-CTRB7PKD.js} +257 -46
  71. package/dist/parser-CTRB7PKD.js.map +1 -0
  72. package/dist/{parser-2LU4EVU3.cjs → parser-RQ4PJRTJ.cjs} +411 -200
  73. package/dist/parser-RQ4PJRTJ.cjs.map +1 -0
  74. package/dist/{parser-N6476XAC.js → parser-ZPRQ3SSU.js} +260 -49
  75. package/dist/parser-ZPRQ3SSU.js.map +1 -0
  76. package/dist/pdf-ocr-462ZFSHX.js +15 -0
  77. package/dist/pdf-ocr-L35FQYGP.js +18 -0
  78. package/dist/pdf-ocr-STK5EQFF.cjs +16 -0
  79. package/dist/pdf-ocr-STK5EQFF.cjs.map +1 -0
  80. package/dist/{profile-io-GJPKCYPT.js → profile-io-YZUW6MAN.js} +3 -3
  81. package/dist/{rasterize-UOALJQDS.js → rasterize-OUR2QJXX.js} +3 -3
  82. package/dist/{redact-doc-22SYW3KH.js → redact-doc-4OQKG4SM.js} +11 -11
  83. package/dist/{render-MJ4H3R23.js → render-XNO6PZJO.js} +7 -7
  84. package/dist/seal-CJ7C44JN.js +10 -0
  85. package/dist/{setup-2URYVUEO.js → setup-UU3EIHNI.js} +3 -3
  86. package/dist/visual-QRMRFPUK.js +20 -0
  87. package/dist/{watch-ALXZGTOB.js → watch-SR6Q5SQN.js} +12 -12
  88. package/package.json +2 -2
  89. package/dist/chunk-3IB7LBHC.js +0 -57
  90. package/dist/chunk-3IB7LBHC.js.map +0 -1
  91. package/dist/chunk-62W7QCEX.cjs +0 -57
  92. package/dist/chunk-62W7QCEX.cjs.map +0 -1
  93. package/dist/chunk-CEIATRDW.cjs.map +0 -1
  94. package/dist/chunk-FKUDAIJI.cjs.map +0 -1
  95. package/dist/chunk-FSDJLAOW.js.map +0 -1
  96. package/dist/chunk-IQGIT2VX.js.map +0 -1
  97. package/dist/chunk-J3IF6KGW.js +0 -59
  98. package/dist/chunk-J3IF6KGW.js.map +0 -1
  99. package/dist/chunk-JFLAM3MM.js.map +0 -1
  100. package/dist/chunk-QOCS7W7R.js.map +0 -1
  101. package/dist/chunk-SFEQYKYJ.js.map +0 -1
  102. package/dist/chunk-STM3ORY7.cjs.map +0 -1
  103. package/dist/chunk-TXUKTOG2.js.map +0 -1
  104. package/dist/chunk-WDQTFAXY.cjs.map +0 -1
  105. package/dist/chunk-XTFN5WKS.cjs.map +0 -1
  106. package/dist/chunks-NUNIKS2J.js +0 -10
  107. package/dist/formula-WIMV5TUX.cjs.map +0 -1
  108. package/dist/image-ocr-AXWXR6JV.cjs.map +0 -1
  109. package/dist/parser-2LU4EVU3.cjs.map +0 -1
  110. package/dist/parser-N6476XAC.js.map +0 -1
  111. package/dist/parser-ZQM3664Z.js.map +0 -1
  112. package/dist/pdf-ocr-6DEE23IP.js +0 -15
  113. package/dist/pdf-ocr-GHEJVPX2.cjs +0 -16
  114. package/dist/pdf-ocr-GHEJVPX2.cjs.map +0 -1
  115. package/dist/pdf-ocr-MQTWODVU.js +0 -18
  116. package/dist/seal-XWMRUTI4.js +0 -10
  117. package/dist/visual-USPS4QRC.js +0 -20
  118. /package/dist/{-4G6MA4X6.js.map → -PRAKO6M4.js.map} +0 -0
  119. /package/dist/{chunk-AUWGDP4G.js.map → chunk-2KF5WZCR.js.map} +0 -0
  120. /package/dist/{chunk-UTP2WCHS.js.map → chunk-4GSF2R7T.js.map} +0 -0
  121. /package/dist/{chunk-4VODJKFL.js.map → chunk-6RGGYQQC.js.map} +0 -0
  122. /package/dist/{chunk-DES2LGFZ.js.map → chunk-A55JGNKD.js.map} +0 -0
  123. /package/dist/{chunk-LEIAEWZ7.js.map → chunk-BFT5IM2R.js.map} +0 -0
  124. /package/dist/{chunk-KIOQ4N37.js.map → chunk-BLPR4HRF.js.map} +0 -0
  125. /package/dist/{chunk-JELRWAZC.js.map → chunk-BZG7K44Z.js.map} +0 -0
  126. /package/dist/{chunk-F4NRLLY4.js.map → chunk-EFO6JZY6.js.map} +0 -0
  127. /package/dist/{chunk-MLIS253L.js.map → chunk-ML4NHUR7.js.map} +0 -0
  128. /package/dist/{chunk-GO5IFOUF.js.map → chunk-N6V7LQBL.js.map} +0 -0
  129. /package/dist/{chunk-S2PL227Q.js.map → chunk-PHID6WNG.js.map} +0 -0
  130. /package/dist/{chunk-OXLPVQYK.js.map → chunk-TDQ6XDB3.js.map} +0 -0
  131. /package/dist/{chunk-5KS5PWJR.js.map → chunk-WY5JAR4O.js.map} +0 -0
  132. /package/dist/{chunk-7KNGSQU7.js.map → chunk-YZ5HHS6A.js.map} +0 -0
  133. /package/dist/{chunk-P6ZDXTV6.js.map → chunk-ZF6KHPB7.js.map} +0 -0
  134. /package/dist/{chunks-NUNIKS2J.js.map → chunks-YBFBLJ4G.js.map} +0 -0
  135. /package/dist/{formula-NARUOXRX.js.map → formula-7MMFBRGJ.js.map} +0 -0
  136. /package/dist/{formula-EPKLPDU7.js.map → formula-SHBXRXOJ.js.map} +0 -0
  137. /package/dist/{image-ocr-3WJ4QH3T.js.map → image-ocr-P6ECJCT2.js.map} +0 -0
  138. /package/dist/{image-ocr-5BUJQ4TK.js.map → image-ocr-QCT3A7X5.js.map} +0 -0
  139. /package/dist/{model-bundle-IMBW7D2Z.js.map → model-bundle-OUHGCEZY.js.map} +0 -0
  140. /package/dist/{models-SY75IBOE.js.map → models-6D6LMOTH.js.map} +0 -0
  141. /package/dist/{pdf-ocr-6DEE23IP.js.map → pdf-ocr-462ZFSHX.js.map} +0 -0
  142. /package/dist/{pdf-ocr-MQTWODVU.js.map → pdf-ocr-L35FQYGP.js.map} +0 -0
  143. /package/dist/{profile-io-GJPKCYPT.js.map → profile-io-YZUW6MAN.js.map} +0 -0
  144. /package/dist/{rasterize-UOALJQDS.js.map → rasterize-OUR2QJXX.js.map} +0 -0
  145. /package/dist/{redact-doc-22SYW3KH.js.map → redact-doc-4OQKG4SM.js.map} +0 -0
  146. /package/dist/{render-MJ4H3R23.js.map → render-XNO6PZJO.js.map} +0 -0
  147. /package/dist/{seal-XWMRUTI4.js.map → seal-CJ7C44JN.js.map} +0 -0
  148. /package/dist/{setup-2URYVUEO.js.map → setup-UU3EIHNI.js.map} +0 -0
  149. /package/dist/{visual-USPS4QRC.js.map → visual-QRMRFPUK.js.map} +0 -0
  150. /package/dist/{watch-ALXZGTOB.js.map → watch-SR6Q5SQN.js.map} +0 -0
@@ -1,10 +1,10 @@
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;
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; } async function _asyncOptionalChain(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 = await fn(value); } else if (op === 'call' || op === 'optionalCall') { value = await fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class;
2
2
 
3
3
 
4
4
 
5
5
 
6
6
 
7
- var _chunkXTFN5WKScjs = require('./chunk-XTFN5WKS.cjs');
7
+ var _chunkR2BUANHQcjs = require('./chunk-R2BUANHQ.cjs');
8
8
 
9
9
 
10
10
 
@@ -44,15 +44,24 @@ var _chunkJ55UQC5Hcjs = require('./chunk-J55UQC5H.cjs');
44
44
 
45
45
 
46
46
 
47
- var _chunkWDQTFAXYcjs = require('./chunk-WDQTFAXY.cjs');
48
47
 
49
48
 
50
- var _chunk62W7QCEXcjs = require('./chunk-62W7QCEX.cjs');
51
- require('./chunk-CEIATRDW.cjs');
52
49
 
53
50
 
54
51
 
55
- var _chunkSTM3ORY7cjs = require('./chunk-STM3ORY7.cjs');
52
+
53
+ var _chunkXEPKOC2Ocjs = require('./chunk-XEPKOC2O.cjs');
54
+
55
+
56
+
57
+
58
+
59
+ var _chunkAKB72TEHcjs = require('./chunk-AKB72TEH.cjs');
60
+ require('./chunk-WYON5ANU.cjs');
61
+
62
+
63
+
64
+ var _chunkQNJLLF4Jcjs = require('./chunk-QNJLLF4J.cjs');
56
65
 
57
66
 
58
67
  var _chunkGS7T56RPcjs = require('./chunk-GS7T56RP.cjs');
@@ -246,7 +255,7 @@ async function extractPageImages(page, fnArray, argsArray, pageNumber, state, wa
246
255
  const filename = `image_${String(state.imageIndex).padStart(3, "0")}.png`;
247
256
  state.seen.set(hash, filename);
248
257
  if (withBytes) {
249
- const png = _chunkXTFN5WKScjs.encodePng.call(void 0, w, h, rgba);
258
+ const png = _chunkR2BUANHQcjs.encodePng.call(void 0, w, h, rgba);
250
259
  state.totalBytes += png.length;
251
260
  images.push({ filename, data: png, mimeType: "image/png" });
252
261
  }
@@ -676,6 +685,7 @@ function splitContactTables(blocks) {
676
685
 
677
686
  // src/pdf/table-parts.ts
678
687
  var PART_COL_TOL = 1;
688
+ var PART_COL_SNAP = 0.3;
679
689
  function anchorsOf(table) {
680
690
  const out = [];
681
691
  const covered = /* @__PURE__ */ new Set();
@@ -693,9 +703,22 @@ function anchorsOf(table) {
693
703
  return out;
694
704
  }
695
705
  function unionCoords(a, b) {
706
+ const drift = a.length === b.length && a.every((x, i) => Math.abs(x - b[i]) <= PART_COL_TOL);
707
+ const tol = drift ? PART_COL_TOL : PART_COL_SNAP;
708
+ const pairs = [];
709
+ for (const v of b) for (const x of a) if (Math.abs(x - v) <= tol) pairs.push([Math.abs(x - v), v, x]);
710
+ pairs.sort((p, q) => p[0] - q[0]);
711
+ const map = /* @__PURE__ */ new Map(), taken = /* @__PURE__ */ new Set();
712
+ for (const [, v, x] of pairs) if (!map.has(v) && !taken.has(x)) {
713
+ map.set(v, x);
714
+ taken.add(x);
715
+ }
696
716
  const out = [...a];
697
- for (const v of b) if (!a.some((x) => Math.abs(x - v) <= PART_COL_TOL)) out.push(v);
698
- return out.sort((x, y) => x - y);
717
+ for (const v of b) if (!map.has(v)) {
718
+ map.set(v, v);
719
+ out.push(v);
720
+ }
721
+ return { U: out.sort((x, y) => x - y), map };
699
722
  }
700
723
  var indexOf = (coords, x) => {
701
724
  let best = -1, bestD = Infinity;
@@ -712,18 +735,31 @@ var rowText = (anchors, r) => anchors.filter((a) => a.r === r).map((a) => a.cell
712
735
  var hasText = (t) => t.replace(/\|/g, "") !== "";
713
736
  function joinSplitParts(prev, pcx, curr, ccx, dx = 0, prevBottom, lex) {
714
737
  if (pcx.length !== prev.cols + 1 || ccx.length !== curr.cols + 1) return null;
715
- const U = unionCoords(pcx, ccx);
738
+ const { U, map } = unionCoords(pcx, ccx);
739
+ const cxU = ccx.map((v) => _nullishCoalesce(map.get(v), () => ( v)));
716
740
  const cols = U.length - 1;
717
741
  if (cols < 1) return null;
718
742
  const pa = anchorsOf(prev), ca = anchorsOf(curr);
719
- let skip = 0;
743
+ let skip = 0, head = 0;
720
744
  while (skip < Math.min(3, curr.rows - 1, prev.rows) && rowText(ca, skip) !== "" && rowText(ca, skip) === rowText(pa, skip)) skip++;
721
745
  for (let h = 1; h <= 2 && !skip; h++) {
746
+ head = h;
722
747
  while (skip < Math.min(3, curr.rows - 1, prev.rows - h) && hasText(rowText(ca, skip)) && rowText(ca, skip) === rowText(pa, h + skip)) skip++;
723
748
  }
749
+ const sameSpans = (u, d) => {
750
+ if (u.length !== d.length || !u.length) return false;
751
+ const shift = pcx[u[u.length - 1].c + u[u.length - 1].cs] - ccx[d[d.length - 1].c + d[d.length - 1].cs];
752
+ return u.every((a, n) => Math.abs(pcx[a.c] - ccx[d[n].c] - shift) <= CONTINUATION_COL_TOL && Math.abs(pcx[a.c + a.cs] - ccx[d[n].c + d[n].cs] - shift) <= CONTINUATION_COL_TOL);
753
+ };
754
+ for (let k = 0; k < skip; k++) {
755
+ if (sameSpans(pa.filter((a) => a.r === head + k), ca.filter((a) => a.r === k))) continue;
756
+ if (hasText(rowText(ca, k))) return null;
757
+ skip = k;
758
+ }
724
759
  const rows = prev.rows + curr.rows - skip;
725
760
  const grid = Array.from({ length: rows }, () => Array.from({ length: cols }, () => ({ text: "", colSpan: 1, rowSpan: 1 })));
726
761
  const owner = Array.from({ length: rows }, () => new Array(cols).fill(null));
762
+ let edged = false;
727
763
  const place = (a, x, rowOff, shift = 0) => {
728
764
  const c1 = indexOf(U, x[a.c]), c2 = indexOf(U, x[a.c + a.cs]);
729
765
  if (c1 < 0 || c2 <= c1) return false;
@@ -733,15 +769,20 @@ function joinSplitParts(prev, pcx, curr, ccx, dx = 0, prevBottom, lex) {
733
769
  if (r + dr < rows) owner[r + dr][dc] = placed;
734
770
  }
735
771
  grid[r][c1] = { ...a.cell, colSpan: c2 - c1, rowSpan: a.rs };
736
- const lines = _chunkWDQTFAXYcjs.CELL_LINES.get(a.cell);
737
- if (lines) _chunkWDQTFAXYcjs.CELL_LINES.set(grid[r][c1], shift ? lines.map((l) => ({ ...l, l: l.l + shift, r: l.r + shift })) : lines);
738
- if (_chunkWDQTFAXYcjs.IMAGE_CELLS.has(a.cell)) _chunkWDQTFAXYcjs.IMAGE_CELLS.add(grid[r][c1]);
772
+ const lines = _chunkXEPKOC2Ocjs.CELL_LINES.get(a.cell);
773
+ if (lines) _chunkXEPKOC2Ocjs.CELL_LINES.set(grid[r][c1], shift ? lines.map((l) => ({ ...l, l: l.l + shift, r: l.r + shift })) : lines);
774
+ if (_chunkXEPKOC2Ocjs.IMAGE_CELLS.has(a.cell)) _chunkXEPKOC2Ocjs.IMAGE_CELLS.add(grid[r][c1]);
775
+ const edges = _chunkAKB72TEHcjs.CELL_EDGES.get(a.cell);
776
+ if (edges) {
777
+ _chunkAKB72TEHcjs.CELL_EDGES.set(grid[r][c1], edges);
778
+ edged = true;
779
+ }
739
780
  return true;
740
781
  };
741
- for (const a of pa) if (!_chunkWDQTFAXYcjs.FILLER_CELLS.has(a.cell) && !place(a, pcx, 0)) return null;
782
+ for (const a of pa) if (!_chunkXEPKOC2Ocjs.FILLER_CELLS.has(a.cell) && !place(a, pcx, 0)) return null;
742
783
  for (const a of ca) {
743
- if (a.r < skip || _chunkWDQTFAXYcjs.FILLER_CELLS.has(a.cell)) continue;
744
- if (!place(a, ccx, prev.rows - skip, dx)) return null;
784
+ if (a.r < skip || _chunkXEPKOC2Ocjs.FILLER_CELLS.has(a.cell)) continue;
785
+ if (!place(a, cxU, prev.rows - skip, dx)) return null;
745
786
  }
746
787
  const first = prev.rows;
747
788
  for (let c = 0; c < cols; c++) {
@@ -764,13 +805,33 @@ function joinSplitParts(prev, pcx, curr, ccx, dx = 0, prevBottom, lex) {
764
805
  const grown = { ...above, rs: newRs };
765
806
  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;
766
807
  }
767
- for (let r = 0; r < rows; r++) for (let c = 0; c < cols; c++) if (owner[r][c] === null) _chunkWDQTFAXYcjs.FILLER_CELLS.add(grid[r][c]);
808
+ for (let r = 0; r < rows; r++) for (let c = 0; c < cols; c++) if (owner[r][c] === null) _chunkXEPKOC2Ocjs.FILLER_CELLS.add(grid[r][c]);
809
+ if (edged) {
810
+ for (let r = 0; r < rows; r++) for (let c = 0; c < cols; c++) if (owner[r][c] === null) _chunkAKB72TEHcjs.CELL_EDGES.set(grid[r][c], _chunkXEPKOC2Ocjs.NO_EDGES);
811
+ }
812
+ for (let c = 0; c < cols && U[c + 1] <= pcx[0] + PART_COL_TOL; c++) {
813
+ let r = prev.rows;
814
+ while (r < rows && owner[r][c] === null) r++;
815
+ const through = { r: 0, c, rs: r, cs: 1, cell: grid[0][c] };
816
+ for (let rr = 0; rr < r; rr++) owner[rr][c] = through;
817
+ }
768
818
  const table = { rows, cols, cells: grid, hasHeader: prev.hasHeader, ...prev.caption ? { caption: prev.caption } : {} };
769
- let split = rows > prev.rows && mergeSplitRow(table, owner, prev.rows, U);
770
- if (rows > prev.rows && !split && prevBottom !== void 0 && mergeStraddlingCells(table, owner, prev.rows, prevBottom, lex)) split = mergeSplitRow(table, owner, prev.rows, U, true);
819
+ const pr = _chunkXEPKOC2Ocjs.ROW_RULES.get(prev), cr = _chunkXEPKOC2Ocjs.ROW_RULES.get(curr);
820
+ const shifted = dx !== 0;
821
+ const cut = {
822
+ open: !!pr && !!cr && !pr.bottom && !cr.top && pr.innerOpen + cr.innerOpen === 0 && pr.innerRuled + cr.innerRuled > 0,
823
+ ruled: !!pr && !!cr && pr.bottom && cr.top,
824
+ list: !shifted ? "any" : skip > 0 && ca.filter((a) => a.r < skip && a.cell.text.trim()).length < 2 ? "none" : "multi"
825
+ };
826
+ let split = rows > prev.rows && mergeSplitRow(table, owner, prev.rows, U, false, cut);
827
+ if (rows > prev.rows && !split && prevBottom !== void 0 && mergeStraddlingCells(table, owner, prev.rows, prevBottom, lex, U)) split = mergeSplitRow(table, owner, prev.rows, U, true, { ...cut, open: false });
828
+ if (pr && cr) {
829
+ const cutRuled = pr.bottom || cr.top;
830
+ _chunkXEPKOC2Ocjs.ROW_RULES.set(table, { top: pr.top, bottom: cr.bottom, innerRuled: pr.innerRuled + cr.innerRuled + (!split && cutRuled ? 1 : 0), innerOpen: pr.innerOpen + cr.innerOpen + (!split && !cutRuled ? 1 : 0) });
831
+ }
771
832
  return { table, colXs: U, split, header: ca.filter((a) => a.r < skip && a.cell.text.trim()).length >= 2 };
772
833
  }
773
- function mergeStraddlingCells(table, owner, first, prevBottom, lex) {
834
+ function mergeStraddlingCells(table, owner, first, prevBottom, lex, colXs) {
774
835
  const last = first - 1;
775
836
  const straddles = owner[first].some((o, c) => o !== null && o === owner[last][c]);
776
837
  let firstNew = table.cols;
@@ -794,6 +855,19 @@ function mergeStraddlingCells(table, owner, first, prevBottom, lex) {
794
855
  const tail = _nullishCoalesce(table.cells[u.r][u.c].text.trim().split(/\s+/).pop(), () => ( "")), head = _nullishCoalesce(table.cells[first][d.c].text.trim().split(/\s+/)[0], () => ( ""));
795
856
  if (/^[가-힣]{2,}$/.test(tail) && /^[가-힣]{2,}/.test(head) && lex.evidence2(tail, head) === "") midWord = true;
796
857
  }
858
+ const crossed = /* @__PURE__ */ new Set();
859
+ const shape = (u, d) => `${u.r}:${u.rs}:${d.rs}`;
860
+ if (straddles && colXs) for (let c = 0; c < table.cols; ) {
861
+ const u = owner[last][c], d = owner[first][c];
862
+ if (!u) {
863
+ c++;
864
+ continue;
865
+ }
866
+ c = u.c + u.cs;
867
+ if (!d || d === u || u.r + u.rs - 1 !== last || d.r !== first || d.c !== u.c || d.cs !== u.cs || u.rs < 2) continue;
868
+ const a = table.cells[u.r][u.c], b = table.cells[first][d.c];
869
+ if (hasContent(a) && hasContent(b) && continuesAcross(a, b, colXs[u.c], colXs[u.c + u.cs])) crossed.add(shape(u, d));
870
+ }
797
871
  let merged = false;
798
872
  for (let c = 0; c < table.cols; ) {
799
873
  const u = owner[last][c], d = owner[first][c];
@@ -804,13 +878,16 @@ function mergeStraddlingCells(table, owner, first, prevBottom, lex) {
804
878
  c = u.c + u.cs;
805
879
  if (!d || d === u || u.r + u.rs - 1 !== last || d.r !== first || d.c !== u.c || d.cs !== u.cs) continue;
806
880
  const a = table.cells[u.r][u.c], b = table.cells[first][d.c];
807
- if (!(u.rs >= 2 && u.c + u.cs <= firstNew && hasContent(a) && !hasContent(b))) {
881
+ if (!crossed.has(shape(u, d)) && !(u.rs >= 2 && u.c + u.cs <= firstNew && hasContent(a) && !hasContent(b))) {
808
882
  if (!straddles && !midWord) continue;
809
883
  if (u.r >= last && d.rs < 2) continue;
810
- const U = _chunkWDQTFAXYcjs.CELL_LINES.get(a);
811
- if (!_optionalChain([U, 'optionalAccess', _33 => _33.length]) || U.length > STRADDLE_MAX_LINES || !hasContent(b)) continue;
812
- const lu = U[U.length - 1];
813
- if (!midWord && lu.y - prevBottom > (u.r >= last ? STRADDLE_BOTTOM_ONE_ROW : STRADDLE_BOTTOM) * (lu.h || 10)) continue;
884
+ const U = _chunkXEPKOC2Ocjs.CELL_LINES.get(a);
885
+ if (!_optionalChain([U, 'optionalAccess', _33 => _33.length]) || !hasContent(b)) continue;
886
+ if (!(straddles && filledToBottom(U, prevBottom) && clauseContinues(a, b))) {
887
+ if (U.length > STRADDLE_MAX_LINES) continue;
888
+ const lu = U[U.length - 1];
889
+ if (!midWord && lu.y - prevBottom > (u.r >= last ? STRADDLE_BOTTOM_ONE_ROW : STRADDLE_BOTTOM) * (lu.h || 10)) continue;
890
+ }
814
891
  }
815
892
  appendCell(a, b);
816
893
  a.rowSpan = first + d.rs - u.r;
@@ -821,6 +898,11 @@ function mergeStraddlingCells(table, owner, first, prevBottom, lex) {
821
898
  }
822
899
  return merged;
823
900
  }
901
+ function filledToBottom(U, bottom) {
902
+ if (U.length < 2) return false;
903
+ const lu = U[U.length - 1];
904
+ return lu.y - bottom < (U[0].y - lu.y) / (U.length - 1) + FILL_SLACK * (lu.h || 10);
905
+ }
824
906
  var FULL_LINE_TOL = 1;
825
907
  var FULL_LINE_MIN_FRAC = 0.5;
826
908
  var FULL_LINE_EDGE_MIN = 12;
@@ -829,12 +911,13 @@ var SHORT_LINE_GAP = 1.5;
829
911
  var STRADDLE_MAX_LINES = 3;
830
912
  var STRADDLE_BOTTOM = 1.2;
831
913
  var STRADDLE_BOTTOM_ONE_ROW = 0.55;
914
+ var FILL_SLACK = 0.5;
832
915
  var CARRIED_MIN_COL_W = 4;
833
916
  var LABEL_ROOM = 1.5;
834
917
  var HANGING_MIN = 0.5;
835
918
  var HANGING_TOL = 1;
836
919
  function continuesAcross(u, d, x1, x2) {
837
- const U = _chunkWDQTFAXYcjs.CELL_LINES.get(u), D = _chunkWDQTFAXYcjs.CELL_LINES.get(d);
920
+ const U = _chunkXEPKOC2Ocjs.CELL_LINES.get(u), D = _chunkXEPKOC2Ocjs.CELL_LINES.get(d);
838
921
  if (!_optionalChain([U, 'optionalAccess', _34 => _34.length]) || !_optionalChain([D, 'optionalAccess', _35 => _35.length])) return false;
839
922
  const last = U[U.length - 1];
840
923
  const fs = last.h || 10;
@@ -850,10 +933,16 @@ function continuesAcross(u, d, x1, x2) {
850
933
  maxR = Math.max(maxR, x2 - (minL - x1));
851
934
  if (maxR - last.r > FULL_LINE_TOL * fs) return false;
852
935
  if (U.length === 1 && x2 - last.r > Math.max(FULL_LINE_EDGE_MIN, SINGLE_LINE_WORD_GAP * fs)) return false;
853
- if (last.r - last.l < FULL_LINE_MIN_FRAC * (x2 - x1)) return false;
854
- const leftAligned = (l) => l.l - minL <= fs && maxR - l.r > SHORT_LINE_GAP * fs;
855
- const hanging = U.length >= 2 && U.every((l) => maxR - l.r <= FULL_LINE_TOL * fs) && last.l - minL >= HANGING_MIN * fs && Math.abs(D[0].l - last.l) <= HANGING_TOL;
856
- return U.some(leftAligned) || D.some(leftAligned) || hanging;
936
+ const indented = last.l - minL >= HANGING_MIN * fs;
937
+ if (last.r - last.l < FULL_LINE_MIN_FRAC * (indented ? x2 - last.l : x2 - x1)) return false;
938
+ const newItem = _chunkXEPKOC2Ocjs.startsNewItem.call(void 0, u.text, d.text);
939
+ const all = D.length ? U.concat(D) : U;
940
+ const leftAligned = (l) => maxR - l.r > SHORT_LINE_GAP * fs && (l.l - minL <= fs || !newItem && all.some((o) => o !== l && Math.abs(o.l - l.l) <= HANGING_TOL && Math.abs(o.r - l.r) >= HANGING_MIN * fs));
941
+ const hanging = U.length >= 2 && U.every((l) => maxR - l.r <= FULL_LINE_TOL * fs) && indented && Math.abs(D[0].l - last.l) <= HANGING_TOL;
942
+ const hangingHead = !indented && D.length >= 2 && D[0].l - last.l >= HANGING_MIN * fs && maxR - D[0].r <= FULL_LINE_TOL * fs && D.every((l) => Math.abs(l.l - D[0].l) <= HANGING_TOL);
943
+ const d0 = D[0];
944
+ const hangStart = U.length === 1 && !newItem && d0.l - last.l >= HANGING_MIN * fs && D.every((l) => l.l >= d0.l - HANGING_TOL) && (Math.abs(d0.r - last.r) <= HANGING_TOL && d0.r - d0.l >= FULL_LINE_MIN_FRAC * (x2 - x1) || last.r - d0.r > SHORT_LINE_GAP * fs && Math.abs(d0.l + d0.r - last.l - last.r) / 2 >= HANGING_MIN * fs);
945
+ return U.some(leftAligned) || D.some(leftAligned) || hanging || hangingHead || hangStart;
857
946
  }
858
947
  var OUTLINE_HEAD = /^[□■]\s*\S/;
859
948
  var OUTLINE_ITEM = /^[ㅇ○◦\-‐–·․‧※*]\s*\S/;
@@ -862,23 +951,29 @@ function outlineContinues(u, d) {
862
951
  const D = d.text.split("\n").map((l) => l.trim()).filter(Boolean);
863
952
  return U.length >= 2 && D.length >= 1 && U.some((l) => OUTLINE_HEAD.test(l)) && OUTLINE_ITEM.test(D[0]);
864
953
  }
865
- function lineEnded(c, x1, x2, next = "") {
866
- const L = _chunkWDQTFAXYcjs.CELL_LINES.get(c);
954
+ function lineEnded(c, x1, x2, next) {
955
+ const L = _chunkXEPKOC2Ocjs.CELL_LINES.get(c);
867
956
  if (!L || L.length !== 1) return false;
868
957
  const l = L[0], h = l.h || 10;
869
- const word = _nullishCoalesce(next.trim().split(/\s+/)[0], () => ( ""));
958
+ const d0 = next ? _optionalChain([_chunkXEPKOC2Ocjs.CELL_LINES, 'access', _36 => _36.get, 'call', _37 => _37(next), 'optionalAccess', _38 => _38[0]]) : void 0;
959
+ if (d0 && d0.l - l.l >= HANGING_MIN * h) return false;
960
+ return x2 - l.r - (l.l - x1) >= Math.max(LABEL_ROOM, firstWordUnits(_nullishCoalesce(_optionalChain([next, 'optionalAccess', _39 => _39.text]), () => ( "")))) * h;
961
+ }
962
+ function firstWordUnits(text) {
963
+ const word = _nullishCoalesce(text.trim().replace(/^([(\[「『<〈])\s+/, "$1").split(/\s+/)[0], () => ( ""));
870
964
  let units = 0;
871
965
  for (const ch of word) units += /[가-힣\u3400-\u9fff]/.test(ch) ? 1 : 0.55;
872
- return x2 - l.r - (l.l - x1) >= Math.max(LABEL_ROOM, units) * h;
966
+ return units;
873
967
  }
874
968
  function appendCell(a, b) {
875
- if (_optionalChain([a, 'access', _36 => _36.blocks, 'optionalAccess', _37 => _37.length]) || _optionalChain([b, 'access', _38 => _38.blocks, 'optionalAccess', _39 => _39.length])) {
876
- const asBlocks = (c) => _optionalChain([c, 'access', _40 => _40.blocks, 'optionalAccess', _41 => _41.length]) ? c.blocks : c.text.split("\n").map((l) => l.trim()).filter(Boolean).map((text) => ({ type: "paragraph", text }));
969
+ if (_optionalChain([a, 'access', _40 => _40.blocks, 'optionalAccess', _41 => _41.length]) || _optionalChain([b, 'access', _42 => _42.blocks, 'optionalAccess', _43 => _43.length])) {
970
+ const asBlocks = (c) => _optionalChain([c, 'access', _44 => _44.blocks, 'optionalAccess', _45 => _45.length]) ? c.blocks : c.text.split("\n").map((l) => l.trim()).filter(Boolean).map((text) => ({ type: "paragraph", text }));
877
971
  a.blocks = [...asBlocks(a), ...asBlocks(b)];
878
972
  }
879
973
  if (b.text.trim()) a.text = a.text.trim() ? a.text + "\n" + b.text : b.text;
974
+ _chunkXEPKOC2Ocjs.joinCellEdges.call(void 0, a, b);
880
975
  }
881
- var hasContent = (cell) => !!cell.text.trim() || !!_optionalChain([cell, 'access', _42 => _42.blocks, 'optionalAccess', _43 => _43.length]) || _chunkWDQTFAXYcjs.IMAGE_CELLS.has(cell);
976
+ var hasContent = (cell) => !!cell.text.trim() || !!_optionalChain([cell, 'access', _46 => _46.blocks, 'optionalAccess', _47 => _47.length]) || _chunkXEPKOC2Ocjs.IMAGE_CELLS.has(cell);
882
977
  var CLAUSE_OPEN_ENDING = /(?:하는|되는|하고|하며|하여|되어|되고|되며|이며|으며|어야|아야|여야)$/;
883
978
  var batchim = (ch) => {
884
979
  const k = ch.charCodeAt(0) - 44032;
@@ -886,15 +981,46 @@ var batchim = (ch) => {
886
981
  };
887
982
  function clauseContinues(u, d) {
888
983
  const tail = _nullishCoalesce(u.text.trim().split(/\s+/).pop(), () => ( "")), head = d.text.trim();
889
- if (!/^[가-힣]{2,}$/.test(tail) || !/^[가-힣]/.test(head) || _chunkWDQTFAXYcjs.startsNewItem.call(void 0, u.text, head)) return false;
984
+ if (!/^[가-힣]{2,}$/.test(tail) || !/^[가-힣]/.test(head) || _chunkXEPKOC2Ocjs.startsNewItem.call(void 0, u.text, head)) return false;
890
985
  const last = tail[tail.length - 1], before = tail[tail.length - 2];
891
986
  return last === "\uC744" && batchim(before) || last === "\uB97C" && !batchim(before) || CLAUSE_OPEN_ENDING.test(tail);
892
987
  }
988
+ function wordOverflows(u, d, x1, x2) {
989
+ const U = _chunkXEPKOC2Ocjs.CELL_LINES.get(u);
990
+ if (!_optionalChain([U, 'optionalAccess', _48 => _48.length]) || _chunkXEPKOC2Ocjs.startsNewItem.call(void 0, u.text, d.text)) return false;
991
+ const last = U[U.length - 1], units = firstWordUnits(d.text);
992
+ return units > 0 && last.r - last.l + units * (last.h || 10) > x2 - x1;
993
+ }
994
+ var KO_ORDER = "\uAC00\uB098\uB2E4\uB77C\uB9C8\uBC14\uC0AC\uC544\uC790\uCC28\uCE74\uD0C0\uD30C\uD558";
995
+ function itemMark(line) {
996
+ let m = /^(\d{1,2})([.)])(?!\d)/.exec(line);
997
+ if (m) return { style: "1" + m[2], n: +m[1] };
998
+ if (m = /^\((\d{1,2})\)/.exec(line)) return { style: "(1)", n: +m[1] };
999
+ if ((m = /^([가-하])([.)])/.exec(line)) && KO_ORDER.includes(m[1])) return { style: "\uAC00" + m[2], n: KO_ORDER.indexOf(m[1]) };
1000
+ if ((m = /^\(([가-하])\)/.exec(line)) && KO_ORDER.includes(m[1])) return { style: "(\uAC00)", n: KO_ORDER.indexOf(m[1]) };
1001
+ if (m = /^[①-⑳]/.exec(line)) return { style: "\u2460", n: m[0].charCodeAt(0) };
1002
+ if (m = /^([A-Z])\.\s/.exec(line)) return { style: "A.", n: m[1].charCodeAt(0) };
1003
+ return null;
1004
+ }
1005
+ function listContinues(u, d, multi = false) {
1006
+ const head = itemMark(d.text.trim());
1007
+ if (!head) return false;
1008
+ const marks = u.text.split("\n").map((l) => itemMark(l.trim()));
1009
+ let last = -1, count = 0;
1010
+ marks.forEach((m, i) => {
1011
+ if (_optionalChain([m, 'optionalAccess', _49 => _49.style]) === head.style) {
1012
+ last = i;
1013
+ count++;
1014
+ }
1015
+ });
1016
+ return last >= 0 && marks[last].n + 1 === head.n && (count >= 2 || !multi && last > 0);
1017
+ }
893
1018
  function outlineOnly(pairs, cell) {
894
1019
  const filled = pairs.filter(([, d]) => hasContent(d.cell));
895
1020
  return filled.length === 1 && outlineContinues(cell(filled[0][0]), cell(filled[0][1]));
896
1021
  }
897
- function mergeSplitRow(table, owner, first, colXs, textOnly = false) {
1022
+ var NO_CUT = { open: false, ruled: false, list: "any" };
1023
+ function mergeSplitRow(table, owner, first, colXs, textOnly = false, cut = NO_CUT) {
898
1024
  const last = first - 1;
899
1025
  const pairs = [];
900
1026
  let carried = false;
@@ -907,19 +1033,30 @@ function mergeSplitRow(table, owner, first, colXs, textOnly = false) {
907
1033
  }
908
1034
  if (!a || !b) return false;
909
1035
  if (a !== b) {
910
- if (a.c !== b.c || a.cs !== b.cs || a.r + a.rs - 1 !== last || b.r !== first || b.rs !== 1) return false;
1036
+ if (a.c !== b.c || a.cs !== b.cs || a.r + a.rs - 1 !== last || b.r !== first) return false;
1037
+ if (b.rs > 1 && (a.rs > 1 || !hasContent(a.cell))) return false;
911
1038
  pairs.push([a, b]);
912
1039
  } else if (a.r === last && a.rs === 2) carried = true;
913
1040
  c = a.c + a.cs;
914
1041
  }
915
- const carriedSplit = !textOnly && carried && pairs.filter(([u, d]) => hasContent(u.cell) && hasContent(d.cell)).length <= 1 && !pairs.some(([u, d]) => !hasContent(u.cell) && hasContent(d.cell));
1042
+ const newCell = pairs.some(([u, d]) => !hasContent(u.cell) && hasContent(d.cell));
916
1043
  const cell = (a) => table.cells[a.r][a.c];
1044
+ const contentPairs = pairs.filter(([u, d]) => hasContent(u.cell) && hasContent(d.cell));
1045
+ const carriedSplit = !textOnly && carried && !newCell && (contentPairs.length <= 1 || contentPairs.every(([, d]) => d.rs > 1) || !cut.ruled && contentPairs.some(([u, d]) => wordOverflows(cell(u), cell(d), colXs[u.c], colXs[u.c + u.cs])));
917
1046
  if (!carriedSplit) {
918
1047
  const norm = (c) => c.text.replace(/\s+/g, "");
919
- if (pairs.some(([u, d]) => hasContent(d.cell) && norm(cell(d)) !== norm(cell(u)) && lineEnded(cell(u), colXs[u.c], colXs[u.c + u.cs], cell(d).text))) return false;
920
- if (!outlineOnly(pairs, cell) && !pairs.some(([u, d]) => continuesAcross(cell(u), cell(d), colXs[u.c], colXs[u.c + u.cs])) && !pairs.some(([u, d]) => clauseContinues(cell(u), cell(d)))) return false;
1048
+ if (pairs.some(([u, d]) => hasContent(d.cell) && norm(cell(d)) !== norm(cell(u)) && lineEnded(cell(u), colXs[u.c], colXs[u.c + u.cs], cell(d)))) return false;
1049
+ const flows = ([u, d]) => continuesAcross(cell(u), cell(d), colXs[u.c], colXs[u.c + u.cs]) || clauseContinues(cell(u), cell(d));
1050
+ if (!(cut.open && !newCell)) {
1051
+ if (pairs.some((p) => p[1].rs > 1 && !flows(p))) return false;
1052
+ const one = pairs.filter(([, d]) => d.rs === 1);
1053
+ if (!outlineOnly(pairs, cell) && !one.some(flows) && (cut.list === "none" || !one.some(([u, d]) => listContinues(cell(u), cell(d), cut.list === "multi")))) return false;
1054
+ }
1055
+ }
1056
+ for (const [u, d] of pairs) {
1057
+ appendCell(table.cells[u.r][u.c], table.cells[d.r][d.c]);
1058
+ if (d.rs > 1) table.cells[u.r][u.c].rowSpan = u.rs + d.rs;
921
1059
  }
922
- for (const [u, d] of pairs) appendCell(table.cells[u.r][u.c], table.cells[d.r][d.c]);
923
1060
  for (let r = 0; r < first; r++) for (let c = 0; c < table.cols; c++) {
924
1061
  const o = owner[r][c];
925
1062
  if (o && o.r === r && o.c === c && r + table.cells[r][c].rowSpan > first) table.cells[r][c].rowSpan--;
@@ -953,7 +1090,7 @@ function insideTable(b, t) {
953
1090
  return b.bbox.x >= o.x - 1 && b.bbox.x + b.bbox.width <= o.x + o.width + 1 && b.bbox.y >= o.y - 1 && b.bbox.y + b.bbox.height <= o.y + o.height + 1;
954
1091
  }
955
1092
  function startsWithUnitRow(table) {
956
- return /^\s*\(\s*단위\s*[::]/.test(_nullishCoalesce(_optionalChain([table, 'access', _44 => _44.cells, 'access', _45 => _45[0], 'optionalAccess', _46 => _46[0], 'optionalAccess', _47 => _47.text]), () => ( ""))) && _optionalChain([table, 'access', _48 => _48.cells, 'access', _49 => _49[0], 'optionalAccess', _50 => _50.slice, 'call', _51 => _51(1), 'access', _52 => _52.every, 'call', _53 => _53((c) => !c.text.trim())]);
1093
+ return /^\s*\(\s*단위\s*[::]/.test(_nullishCoalesce(_optionalChain([table, 'access', _50 => _50.cells, 'access', _51 => _51[0], 'optionalAccess', _52 => _52[0], 'optionalAccess', _53 => _53.text]), () => ( ""))) && _optionalChain([table, 'access', _54 => _54.cells, 'access', _55 => _55[0], 'optionalAccess', _56 => _56.slice, 'call', _57 => _57(1), 'access', _58 => _58.every, 'call', _59 => _59((c) => !c.text.trim())]);
957
1094
  }
958
1095
  function sameHeadShape(a, b) {
959
1096
  if (!a || !b || a.length !== b.length) return false;
@@ -967,11 +1104,14 @@ function sameHeadShape(a, b) {
967
1104
  function mergeCrossPageTables(blocks, pageHeights, lex) {
968
1105
  mergeColumnFlow(blocks, pageHeights, lex);
969
1106
  for (let i = blocks.length - 2; i >= 0; i--) {
970
- const prev = blocks[i];
971
- if (prev.type !== "table" || !prev.table || !prev.bbox || !prev.pageNumber) continue;
1107
+ const tail = tailOf(blocks[i]);
1108
+ if (tail.type !== "table" || !tail.table || !tail.bbox || !tail.pageNumber) continue;
972
1109
  let j = i + 1;
973
- while (j < blocks.length && (blocks[j].type !== "table" || insideTable(blocks[j], prev) || leftColumnOf(blocks[j], prev)) && (_nullishCoalesce(blocks[j].pageNumber, () => ( 0))) <= prev.pageNumber + 1) j++;
1110
+ const skip = (b) => b.type !== "table" || [blocks[i], tail].some((t) => insideTable(b, t) || leftColumnOf(b, t));
1111
+ while (j < blocks.length && skip(blocks[j]) && (_nullishCoalesce(blocks[j].pageNumber, () => ( 0))) <= tail.pageNumber + 1) j++;
974
1112
  const curr = blocks[j];
1113
+ const prev = tail !== blocks[i] && _optionalChain([curr, 'optionalAccess', _60 => _60.pageNumber]) === tail.pageNumber ? blocks[i] : tail;
1114
+ if (!prev.table || !prev.bbox || !prev.pageNumber) continue;
975
1115
  if (!curr || curr.type !== "table" || !curr.table || !curr.bbox || curr.pageNumber !== prev.pageNumber + 1) continue;
976
1116
  if (startsWithUnitRow(prev.table) && startsWithUnitRow(curr.table)) continue;
977
1117
  const joined = j === i + 1 || blocks.slice(i + 1, j).every((b) => besideOwn(b, prev, curr) || insideTable(b, prev)) ? looksContinued(prev, curr, pageHeights) && !restartsTable(blocks, i, curr.table, pageHeights) ? _nullishCoalesce(joinClipParts(prev, curr, pageHeights, lex), () => ( false)) : null : null;
@@ -979,19 +1119,19 @@ function mergeCrossPageTables(blocks, pageHeights, lex) {
979
1119
  placeJoined(blocks, i, j, joined);
980
1120
  continue;
981
1121
  }
982
- if (_chunkWDQTFAXYcjs.EMPTY_PARTS.has(curr.table)) {
1122
+ if (_chunkXEPKOC2Ocjs.EMPTY_PARTS.has(curr.table)) {
983
1123
  blocks.splice(j, 1);
984
1124
  i++;
985
1125
  continue;
986
1126
  }
987
1127
  if (joined === null) continue;
988
- if (prev.table.cols !== curr.table.cols || prev.table.renderAsTable !== curr.table.renderAsTable || _chunkWDQTFAXYcjs.EMPTY_PARTS.has(prev.table)) continue;
1128
+ if (prev.table.cols !== curr.table.cols || prev.table.renderAsTable !== curr.table.renderAsTable || _chunkXEPKOC2Ocjs.EMPTY_PARTS.has(prev.table)) continue;
989
1129
  const width = Math.max(prev.bbox.width, curr.bbox.width, 1);
990
1130
  const leftDiff = Math.abs(prev.bbox.x - curr.bbox.x);
991
1131
  const rightDiff = Math.abs(prev.bbox.x + prev.bbox.width - (curr.bbox.x + curr.bbox.width));
992
1132
  if (leftDiff > width * NEIGHBOR_TABLE_EPSILON || rightDiff > width * NEIGHBOR_TABLE_EPSILON) continue;
993
- const px = _chunkWDQTFAXYcjs.TABLE_COLXS.get(prev.table), cx = _chunkWDQTFAXYcjs.TABLE_COLXS.get(curr.table);
994
- if (px && cx && !shiftedSame(px, cx, !_chunkWDQTFAXYcjs.CLIP_TABLES.has(prev.table) && !_chunkWDQTFAXYcjs.CLIP_TABLES.has(curr.table))) continue;
1133
+ const px = _chunkXEPKOC2Ocjs.TABLE_COLXS.get(prev.table), cx = _chunkXEPKOC2Ocjs.TABLE_COLXS.get(curr.table);
1134
+ if (px && cx && !shiftedSame(px, cx, !_chunkXEPKOC2Ocjs.CLIP_TABLES.has(prev.table) && !_chunkXEPKOC2Ocjs.CLIP_TABLES.has(curr.table))) continue;
995
1135
  if (!rowTextsEqual(prev.table.cells[0], curr.table.cells[0]) && sameHeadShape(prev.table.cells[0], curr.table.cells[0])) continue;
996
1136
  let currCells = curr.table.cells;
997
1137
  if (currCells.length > 1 && prev.table.cells.length > 0 && rowTextsEqual(prev.table.cells[0], currCells[0])) {
@@ -1009,20 +1149,20 @@ function mergeCrossPageTables(blocks, pageHeights, lex) {
1009
1149
  caption: prev.table.caption,
1010
1150
  ...prev.table.renderAsTable ? { renderAsTable: true } : {}
1011
1151
  };
1012
- if (_nullishCoalesce(px, () => ( cx))) _chunkWDQTFAXYcjs.TABLE_COLXS.set(merged, _nullishCoalesce(px, () => ( cx)));
1013
- if (_chunkWDQTFAXYcjs.CLIP_TABLES.has(prev.table) || _chunkWDQTFAXYcjs.CLIP_TABLES.has(curr.table)) _chunkWDQTFAXYcjs.CLIP_TABLES.add(merged);
1152
+ if (_nullishCoalesce(px, () => ( cx))) _chunkXEPKOC2Ocjs.TABLE_COLXS.set(merged, _nullishCoalesce(px, () => ( cx)));
1153
+ if (_chunkXEPKOC2Ocjs.CLIP_TABLES.has(prev.table) || _chunkXEPKOC2Ocjs.CLIP_TABLES.has(curr.table)) _chunkXEPKOC2Ocjs.CLIP_TABLES.add(merged);
1014
1154
  placeJoined(blocks, i, j, merged);
1015
1155
  }
1016
1156
  for (let i = blocks.length - 1; i >= 0; i--) {
1017
1157
  const t = blocks[i].table;
1018
- if (blocks[i].type === "table" && t && _chunkWDQTFAXYcjs.EMPTY_PARTS.has(t)) blocks.splice(i, 1);
1158
+ if (blocks[i].type === "table" && t && _chunkXEPKOC2Ocjs.EMPTY_PARTS.has(t)) blocks.splice(i, 1);
1019
1159
  }
1020
1160
  }
1021
1161
  function mergeColumnFlow(blocks, pageHeights, lex) {
1022
1162
  if (!pageHeights) return;
1023
1163
  for (let i = 0; i < blocks.length; i++) {
1024
1164
  const L = blocks[i];
1025
- if (L.type !== "table" || !L.table || !L.bbox || !L.pageNumber || !_chunkWDQTFAXYcjs.CLIP_TABLES.has(L.table) || _chunkWDQTFAXYcjs.EMPTY_PARTS.has(L.table)) continue;
1165
+ if (L.type !== "table" || !L.table || !L.bbox || !L.pageNumber || !_chunkXEPKOC2Ocjs.CLIP_TABLES.has(L.table) || _chunkXEPKOC2Ocjs.EMPTY_PARTS.has(L.table)) continue;
1026
1166
  const ph = pageHeights.get(L.pageNumber);
1027
1167
  if (!ph || L.bbox.y > ph * PAGE_EDGE_BAND) continue;
1028
1168
  let s0 = i, s1 = i;
@@ -1051,27 +1191,39 @@ function mergeColumnFlow(blocks, pageHeights, lex) {
1051
1191
  }
1052
1192
  function joinClipParts(prev, curr, pageHeights, lex) {
1053
1193
  const pt = prev.table, ct = curr.table;
1054
- if (!_chunkWDQTFAXYcjs.CLIP_TABLES.has(pt) || !_chunkWDQTFAXYcjs.CLIP_TABLES.has(ct)) return null;
1055
- const px = _chunkWDQTFAXYcjs.TABLE_COLXS.get(pt), cx = _chunkWDQTFAXYcjs.TABLE_COLXS.get(ct);
1194
+ if (!_chunkXEPKOC2Ocjs.CLIP_TABLES.has(pt) || !_chunkXEPKOC2Ocjs.CLIP_TABLES.has(ct)) return null;
1195
+ const px = _chunkXEPKOC2Ocjs.TABLE_COLXS.get(pt), cx = _chunkXEPKOC2Ocjs.TABLE_COLXS.get(ct);
1056
1196
  if (!px || !cx) return null;
1057
- let xs = cx, shifted = false, dx = 0, foreign = false;
1197
+ let xs = cx, shifted = false, dx = 0, foreign = false, within = false;
1058
1198
  if (!shiftedSame(px, cx, false)) {
1059
- if (!_optionalChain([pageHeights, 'optionalAccess', _54 => _54.get, 'call', _55 => _55(prev.pageNumber)]) || !_optionalChain([pageHeights, 'optionalAccess', _56 => _56.get, 'call', _57 => _57(curr.pageNumber)])) return null;
1199
+ if (!_optionalChain([pageHeights, 'optionalAccess', _61 => _61.get, 'call', _62 => _62(prev.pageNumber)]) || !_optionalChain([pageHeights, 'optionalAccess', _63 => _63.get, 'call', _64 => _64(curr.pageNumber)])) return null;
1060
1200
  dx = px[px.length - 1] - cx[cx.length - 1];
1061
- if (Math.abs(dx) > CONTINUATION_COL_TOL) {
1201
+ within = Math.abs(dx) > CONTINUATION_COL_TOL && cx.length >= 3 && cx.every((x) => px.some((p) => Math.abs(p - x) <= CONTINUATION_COL_TOL));
1202
+ if (Math.abs(dx) > CONTINUATION_COL_TOL && !within) {
1062
1203
  xs = cx.map((x) => x + dx);
1063
1204
  shifted = true;
1064
1205
  } else dx = 0;
1065
- if (!px.some((x) => Math.abs(x - xs[0]) <= CONTINUATION_COL_TOL)) return null;
1066
- const inner = xs.slice(1, -1);
1067
- foreign = inner.length > 0 && !inner.some((x) => px.some((p) => Math.abs(p - x) <= CONTINUATION_COL_TOL)) && headingRow(_nullishCoalesce(ct.cells[0], () => ( [])));
1068
- }
1069
- const res = joinSplitParts(pt, px, ct, xs, dx, _optionalChain([prev, 'access', _58 => _58.bbox, 'optionalAccess', _59 => _59.y]), lex);
1070
- if (!res || (shifted || foreign) && !res.split && !res.header) return null;
1071
- _chunkWDQTFAXYcjs.TABLE_COLXS.set(res.table, res.colXs);
1072
- _chunkWDQTFAXYcjs.CLIP_TABLES.add(res.table);
1206
+ if (!px.some((x) => Math.abs(x - xs[0]) <= CONTINUATION_COL_TOL) && !prevLacksLeftCols(prev, px, xs, pageHeights)) return null;
1207
+ const unrelated = (b) => {
1208
+ const inner = b.slice(1, -1).map((x) => x + dx);
1209
+ return inner.length > 0 && !inner.some((x) => px.some((p) => Math.abs(p - x) <= CONTINUATION_COL_TOL));
1210
+ };
1211
+ foreign = unrelated(cx) && unrelated(_nullishCoalesce(_chunkXEPKOC2Ocjs.PART_COLXS.get(ct), () => ( cx))) && (headingRow(_nullishCoalesce(ct.cells[0], () => ( []))) || px.length > FOREIGN_FIRST_ROW_CELLS && anchorsOf(ct).filter((a) => a.r === 0).length >= FOREIGN_FIRST_ROW_CELLS);
1212
+ }
1213
+ const res = joinSplitParts(pt, px, ct, xs, dx, _optionalChain([prev, 'access', _65 => _65.bbox, 'optionalAccess', _66 => _66.y]), lex);
1214
+ if (!res || (shifted || foreign || within) && !res.split && !res.header) return null;
1215
+ _chunkXEPKOC2Ocjs.TABLE_COLXS.set(res.table, res.colXs);
1216
+ const ys = _chunkXEPKOC2Ocjs.TABLE_ROWYS.get(pt);
1217
+ if (ys) _chunkXEPKOC2Ocjs.TABLE_ROWYS.set(res.table, ys);
1218
+ _chunkXEPKOC2Ocjs.PART_COLXS.set(res.table, _nullishCoalesce(_chunkXEPKOC2Ocjs.PART_COLXS.get(pt), () => ( px)));
1219
+ _chunkXEPKOC2Ocjs.CLIP_TABLES.add(res.table);
1073
1220
  return res.table;
1074
1221
  }
1222
+ function prevLacksLeftCols(prev, px, xs, pageHeights) {
1223
+ const ph = _optionalChain([pageHeights, 'optionalAccess', _67 => _67.get, 'call', _68 => _68(prev.pageNumber)]);
1224
+ if (!ph || prev.bbox.y + prev.bbox.height < ph * (1 - PAGE_EDGE_BAND)) return false;
1225
+ return xs[0] < px[0] && xs.slice(1, -1).some((x) => Math.abs(x - px[0]) <= CONTINUATION_COL_TOL);
1226
+ }
1075
1227
  function headingRow(row) {
1076
1228
  const heads = row.map((c) => c.text.replace(/\s+/g, "")).filter(Boolean);
1077
1229
  if (heads.length === 1) return heads[0].length <= 8 || /^[①-⑳❶-❿]/.test(heads[0]);
@@ -1079,16 +1231,39 @@ function headingRow(row) {
1079
1231
  }
1080
1232
  var ANNEX_HEAD_RE = /^\s*[<\[(【]?\s*(?:붙\s*임|참\s*고|별\s*첨|별\s*지|별\s*표|첨\s*부|부\s*록)(?:\s*\d|\s*$|\s*[>\])】])|^\s*■/;
1081
1233
  function looksContinued(prev, curr, pageHeights) {
1082
- const ph = _optionalChain([pageHeights, 'optionalAccess', _60 => _60.get, 'call', _61 => _61(prev.pageNumber)]), ch = _optionalChain([pageHeights, 'optionalAccess', _62 => _62.get, 'call', _63 => _63(curr.pageNumber)]);
1083
- if (ph && ch && (prev.bbox.y > ph * PAGE_EDGE_BAND || curr.bbox.y + curr.bbox.height < ch * (1 - PAGE_EDGE_BAND))) return false;
1234
+ const ph = _optionalChain([pageHeights, 'optionalAccess', _69 => _69.get, 'call', _70 => _70(prev.pageNumber)]), ch = _optionalChain([pageHeights, 'optionalAccess', _71 => _71.get, 'call', _72 => _72(curr.pageNumber)]);
1235
+ if (ph && ch && (prev.bbox.y > ph * PAGE_EDGE_BAND && !pushedLead(prev, curr) || curr.bbox.y + curr.bbox.height < ch * (1 - PAGE_EDGE_BAND))) return false;
1084
1236
  const firstRow = _nullishCoalesce(curr.table.cells[0], () => ( []));
1085
- const firstText = _nullishCoalesce(_optionalChain([firstRow, 'access', _64 => _64.find, 'call', _65 => _65((c) => c.text.trim()), 'optionalAccess', _66 => _66.text]), () => ( ""));
1237
+ const firstText = _nullishCoalesce(_optionalChain([firstRow, 'access', _73 => _73.find, 'call', _74 => _74((c) => c.text.trim()), 'optionalAccess', _75 => _75.text]), () => ( ""));
1086
1238
  if (!ANNEX_HEAD_RE.test(firstText)) return true;
1087
1239
  const filled = firstRow.map((c) => c.text.replace(/\s+/g, "")).filter(Boolean);
1088
1240
  return filled.length >= 2 && filled.every((t) => t === filled[0]);
1089
1241
  }
1242
+ function pushedLead(prev, curr) {
1243
+ if (!_chunkXEPKOC2Ocjs.CLIP_TABLES.has(prev.table) || !_chunkXEPKOC2Ocjs.CLIP_TABLES.has(curr.table)) return false;
1244
+ const lead = leadRows(curr.table);
1245
+ return lead.image && lead.height > prev.bbox.y;
1246
+ }
1247
+ function leadRows(t) {
1248
+ const ys = _chunkXEPKOC2Ocjs.TABLE_ROWYS.get(t);
1249
+ if (!ys || ys.length < 2) return { height: 0, image: false };
1250
+ const anchors = anchorsOf(t);
1251
+ let end = 1, image = false;
1252
+ for (let r = 0; r < end; r++) {
1253
+ for (const a of anchors) {
1254
+ if (a.r !== r) continue;
1255
+ end = Math.max(end, r + a.rs);
1256
+ if (_chunkXEPKOC2Ocjs.IMAGE_CELLS.has(a.cell)) image = true;
1257
+ }
1258
+ }
1259
+ return { height: ys[0] - ys[Math.min(end, ys.length - 1)], image };
1260
+ }
1261
+ function tailOf(b) {
1262
+ const t = b.table && _chunkXEPKOC2Ocjs.TABLE_TAIL.get(b.table);
1263
+ return t && b.bbox ? { ...b, pageNumber: t.page, bbox: { ...b.bbox, page: t.page, y: t.y, height: t.height } } : b;
1264
+ }
1090
1265
  function firstRowSig(t) {
1091
- const x = _chunkWDQTFAXYcjs.TABLE_COLXS.get(t);
1266
+ const x = _chunkXEPKOC2Ocjs.TABLE_COLXS.get(t);
1092
1267
  if (!x || x.length !== t.cols + 1) return null;
1093
1268
  return anchorsOf(t).filter((a) => a.r === 0).map((a) => ({ x1: x[a.c], x2: x[a.c + a.cs], t: a.cell.text.replace(/\s+/g, "") }));
1094
1269
  }
@@ -1113,9 +1288,9 @@ function restartsTable(blocks, i, curr, pageHeights) {
1113
1288
  }
1114
1289
  function restartsTitledForm(head, curr) {
1115
1290
  if (head.rows < 2 || curr.rows < 2 || head.cols !== curr.cols) return false;
1116
- const full = (t) => _optionalChain([t, 'access', _67 => _67.cells, 'access', _68 => _68[0], 'access', _69 => _69[0], 'optionalAccess', _70 => _70.colSpan]) === t.cols;
1291
+ const full = (t) => _optionalChain([t, 'access', _76 => _76.cells, 'access', _77 => _77[0], 'access', _78 => _78[0], 'optionalAccess', _79 => _79.colSpan]) === t.cols;
1117
1292
  if (!full(head) || !full(curr)) return false;
1118
- const norm = (c) => (_nullishCoalesce(_optionalChain([c, 'optionalAccess', _71 => _71.text]), () => ( ""))).replace(/\s+/g, "");
1293
+ const norm = (c) => (_nullishCoalesce(_optionalChain([c, 'optionalAccess', _80 => _80.text]), () => ( ""))).replace(/\s+/g, "");
1119
1294
  const ht = norm(head.cells[0][0]), ct = norm(curr.cells[0][0]);
1120
1295
  if (!ht || !ct || ht === ct) return false;
1121
1296
  const titleLike = (t) => t.length <= TITLE_ROW_MAX_CHARS && !/^[ㅇ○◦•·\-–※*□■▪☞]/.test(t);
@@ -1137,14 +1312,14 @@ function chainHead(blocks, i, pageHeights) {
1137
1312
  break;
1138
1313
  }
1139
1314
  }
1140
- const pb = blocks[p];
1315
+ const pb = tailOf(blocks[p]);
1141
1316
  if (pb.pageNumber !== (_nullishCoalesce(cur.pageNumber, () => ( 0))) - 1) break;
1142
1317
  if (!blocks.slice(p + 1, k).every((b) => besideOwn(b, pb, cur) || insideTable(b, pb))) break;
1143
1318
  if (!looksContinued(pb, cur, pageHeights)) break;
1144
- const px = _chunkWDQTFAXYcjs.TABLE_COLXS.get(pb.table), cx = _chunkWDQTFAXYcjs.TABLE_COLXS.get(cur.table);
1319
+ const px = _chunkXEPKOC2Ocjs.TABLE_COLXS.get(pb.table), cx = _chunkXEPKOC2Ocjs.TABLE_COLXS.get(cur.table);
1145
1320
  if (!px || !cx) break;
1146
1321
  const dx = px[px.length - 1] - cx[cx.length - 1];
1147
- if (!shiftedSame(px, cx) && !px.some((x) => Math.abs(x - (cx[0] + dx)) <= CONTINUATION_COL_TOL)) break;
1322
+ if (!shiftedSame(px, cx) && !px.some((x) => Math.abs(x - (cx[0] + dx)) <= CONTINUATION_COL_TOL) && !prevLacksLeftCols(pb, px, cx, pageHeights)) break;
1148
1323
  k = p;
1149
1324
  }
1150
1325
  return k;
@@ -1158,6 +1333,7 @@ function rowTextsEqual(a, b) {
1158
1333
  return a.some((c) => c.text.trim() !== "");
1159
1334
  }
1160
1335
  var CONTINUATION_COL_TOL = 2;
1336
+ var FOREIGN_FIRST_ROW_CELLS = 3;
1161
1337
  function shiftedSame(px, cx, allowShift = true) {
1162
1338
  if (px.length !== cx.length) return false;
1163
1339
  const dx = allowShift ? px[px.length - 1] - cx[cx.length - 1] : 0;
@@ -1172,12 +1348,12 @@ var RESTART_LOOKBACK_PAGES = 5;
1172
1348
  var COL_MATCH_TOL = 0.5;
1173
1349
  var CONTINUED_TABLE_PAGE_BAND = 0.16;
1174
1350
  function lastRowCell(t, x1, x2) {
1175
- const xs = _chunkWDQTFAXYcjs.TABLE_COLXS.get(t);
1351
+ const xs = _chunkXEPKOC2Ocjs.TABLE_COLXS.get(t);
1176
1352
  const covered = /* @__PURE__ */ new Set();
1177
1353
  for (let r = 0; r < t.rows; r++) {
1178
1354
  for (let c = 0; c < t.cols; c++) {
1179
1355
  if (covered.has(r * 1e5 + c)) continue;
1180
- const cell = _optionalChain([t, 'access', _72 => _72.cells, 'access', _73 => _73[r], 'optionalAccess', _74 => _74[c]]);
1356
+ const cell = _optionalChain([t, 'access', _81 => _81.cells, 'access', _82 => _82[r], 'optionalAccess', _83 => _83[c]]);
1181
1357
  if (!cell) continue;
1182
1358
  for (let dr = 0; dr < cell.rowSpan; dr++) for (let dc = 0; dc < cell.colSpan; dc++) covered.add((r + dr) * 1e5 + c + dc);
1183
1359
  if (r + cell.rowSpan !== t.rows) continue;
@@ -1190,19 +1366,23 @@ var cellBlocks = (cell, pageNumber) => _nullishCoalesce(cell.blocks, () => ( cel
1190
1366
  function mergeContinuedCells(blocks, pageHeights) {
1191
1367
  for (let j = blocks.length - 1; j > 0; j--) {
1192
1368
  const part = blocks[j];
1193
- const from = part.table ? _chunkWDQTFAXYcjs.CONT_PARTS.get(part.table) : void 0;
1369
+ const from = part.table ? _chunkXEPKOC2Ocjs.CONT_PARTS.get(part.table) : void 0;
1194
1370
  if (!from || !part.table) continue;
1195
1371
  let i = j - 1;
1196
1372
  while (i >= 0 && blocks[i].type !== "table") i--;
1197
1373
  const prev = blocks[i];
1198
1374
  if (i < 0 || !prev.table || prev.pageNumber !== (_nullishCoalesce(part.pageNumber, () => ( 0))) - 1) continue;
1199
1375
  const cell = lastRowCell(prev.table, from.x1, from.x2);
1200
- const add = _optionalChain([part, 'access', _75 => _75.table, 'access', _76 => _76.cells, 'access', _77 => _77[0], 'optionalAccess', _78 => _78[0]]);
1376
+ const add = _optionalChain([part, 'access', _84 => _84.table, 'access', _85 => _85.cells, 'access', _86 => _86[0], 'optionalAccess', _87 => _87[0]]);
1201
1377
  if (!cell || !add) continue;
1202
1378
  const at = cell.blocks || add.blocks ? cellBlocks(cell, prev.pageNumber).length : -1;
1203
1379
  if (cell.blocks || add.blocks) cell.blocks = [...cellBlocks(cell, prev.pageNumber), ...cellBlocks(add, part.pageNumber)];
1204
1380
  cell.text = [cell.text, add.text].filter((s) => s.trim()).join("\n");
1205
- if (cell.text.trim() || _optionalChain([cell, 'access', _79 => _79.blocks, 'optionalAccess', _80 => _80.length])) _chunkWDQTFAXYcjs.EMPTY_PARTS.delete(prev.table);
1381
+ _chunkXEPKOC2Ocjs.joinCellEdges.call(void 0, cell, add);
1382
+ const lines = _chunkXEPKOC2Ocjs.CELL_LINES.get(add);
1383
+ if (_optionalChain([lines, 'optionalAccess', _88 => _88.length])) _chunkXEPKOC2Ocjs.CELL_LINES.set(cell, [..._nullishCoalesce(_chunkXEPKOC2Ocjs.CELL_LINES.get(cell), () => ( [])), ...lines]);
1384
+ if (part.pageNumber && part.bbox) _chunkXEPKOC2Ocjs.TABLE_TAIL.set(prev.table, _nullishCoalesce(_chunkXEPKOC2Ocjs.TABLE_TAIL.get(part.table), () => ( { page: part.pageNumber, y: part.bbox.y, height: part.bbox.height })));
1385
+ if (cell.text.trim() || _optionalChain([cell, 'access', _89 => _89.blocks, 'optionalAccess', _90 => _90.length])) _chunkXEPKOC2Ocjs.EMPTY_PARTS.delete(prev.table);
1206
1386
  blocks.splice(j, 1);
1207
1387
  if (cell.blocks && at > 0) {
1208
1388
  const nextAt = cell.blocks[at];
@@ -1214,26 +1394,27 @@ function mergeContinuedCells(blocks, pageHeights) {
1214
1394
  }
1215
1395
  function unwrapContinuedTable(blocks, at, pageHeights) {
1216
1396
  const prev = blocks[at - 1], frame = blocks[at];
1217
- if (!_optionalChain([prev, 'optionalAccess', _81 => _81.table]) || !_optionalChain([frame, 'optionalAccess', _82 => _82.table]) || frame.table.rows !== 1 || frame.table.cols !== 1 || !_chunkWDQTFAXYcjs.CLIP_TABLES.has(frame.table)) return;
1218
- const inner = _optionalChain([frame, 'access', _83 => _83.table, 'access', _84 => _84.cells, 'access', _85 => _85[0], 'optionalAccess', _86 => _86[0], 'optionalAccess', _87 => _87.blocks]);
1219
- const next = _optionalChain([inner, 'optionalAccess', _88 => _88[0]]);
1220
- if (!inner || !_optionalChain([next, 'optionalAccess', _89 => _89.table]) || !prev.bbox || !next.bbox || !prev.pageNumber || next.pageNumber !== prev.pageNumber + 1 || !_chunkWDQTFAXYcjs.CLIP_TABLES.has(prev.table) || !_chunkWDQTFAXYcjs.CLIP_TABLES.has(next.table) || prev.table.cols !== next.table.cols) return;
1221
- const px = _chunkWDQTFAXYcjs.TABLE_COLXS.get(prev.table), nx = _chunkWDQTFAXYcjs.TABLE_COLXS.get(next.table);
1397
+ if (!_optionalChain([prev, 'optionalAccess', _91 => _91.table]) || !_optionalChain([frame, 'optionalAccess', _92 => _92.table]) || frame.table.rows !== 1 || frame.table.cols !== 1 || !_chunkXEPKOC2Ocjs.CLIP_TABLES.has(frame.table)) return;
1398
+ const inner = _optionalChain([frame, 'access', _93 => _93.table, 'access', _94 => _94.cells, 'access', _95 => _95[0], 'optionalAccess', _96 => _96[0], 'optionalAccess', _97 => _97.blocks]);
1399
+ const next = _optionalChain([inner, 'optionalAccess', _98 => _98[0]]);
1400
+ if (!inner || !_optionalChain([next, 'optionalAccess', _99 => _99.table]) || !prev.bbox || !next.bbox || !prev.pageNumber || next.pageNumber !== prev.pageNumber + 1 || !_chunkXEPKOC2Ocjs.CLIP_TABLES.has(prev.table) || !_chunkXEPKOC2Ocjs.CLIP_TABLES.has(next.table) || prev.table.cols !== next.table.cols) return;
1401
+ const px = _chunkXEPKOC2Ocjs.TABLE_COLXS.get(prev.table), nx = _chunkXEPKOC2Ocjs.TABLE_COLXS.get(next.table);
1222
1402
  if (!px || !nx || px.length !== nx.length || px.some((x, i) => Math.abs(x - nx[i]) > COL_MATCH_TOL)) return;
1223
- const ph = _optionalChain([pageHeights, 'optionalAccess', _90 => _90.get, 'call', _91 => _91(prev.pageNumber)]), nh = _optionalChain([pageHeights, 'optionalAccess', _92 => _92.get, 'call', _93 => _93(next.pageNumber)]);
1403
+ const ph = _optionalChain([pageHeights, 'optionalAccess', _100 => _100.get, 'call', _101 => _101(prev.pageNumber)]), nh = _optionalChain([pageHeights, 'optionalAccess', _102 => _102.get, 'call', _103 => _103(next.pageNumber)]);
1224
1404
  if (!ph || !nh || prev.bbox.y > ph * CONTINUED_TABLE_PAGE_BAND || next.bbox.y + next.bbox.height < nh * (1 - CONTINUED_TABLE_PAGE_BAND)) return;
1225
1405
  blocks.splice(at, 1, ...inner);
1226
1406
  }
1227
1407
  function fillNestedContinuation(blocks, at) {
1228
1408
  const prev = blocks[at - 1], next = blocks[at];
1229
- const t = _optionalChain([prev, 'optionalAccess', _94 => _94.table]), u = _optionalChain([next, 'optionalAccess', _95 => _95.table]);
1230
- if (!t || !u || u.rows !== 1 || u.cols !== 1 || !_chunkWDQTFAXYcjs.CLIP_TABLES.has(t) || !_chunkWDQTFAXYcjs.CLIP_TABLES.has(u) || next.pageNumber !== (_nullishCoalesce(prev.pageNumber, () => ( 0))) + 1) return;
1231
- const xs = _chunkWDQTFAXYcjs.TABLE_COLXS.get(u);
1409
+ const t = _optionalChain([prev, 'optionalAccess', _104 => _104.table]), u = _optionalChain([next, 'optionalAccess', _105 => _105.table]);
1410
+ if (!t || !u || u.rows !== 1 || u.cols !== 1 || !_chunkXEPKOC2Ocjs.CLIP_TABLES.has(t) || !_chunkXEPKOC2Ocjs.CLIP_TABLES.has(u) || next.pageNumber !== (_nullishCoalesce(prev.pageNumber, () => ( 0))) + 1) return;
1411
+ const xs = _chunkXEPKOC2Ocjs.TABLE_COLXS.get(u);
1232
1412
  const cell = xs ? lastRowCell(t, xs[0], xs[xs.length - 1]) : void 0;
1233
- const add = _optionalChain([u, 'access', _96 => _96.cells, 'access', _97 => _97[0], 'optionalAccess', _98 => _98[0]]);
1234
- if (!cell || !add || cell.text.trim() || _optionalChain([cell, 'access', _99 => _99.blocks, 'optionalAccess', _100 => _100.length])) return;
1413
+ const add = _optionalChain([u, 'access', _106 => _106.cells, 'access', _107 => _107[0], 'optionalAccess', _108 => _108[0]]);
1414
+ if (!cell || !add || cell.text.trim() || _optionalChain([cell, 'access', _109 => _109.blocks, 'optionalAccess', _110 => _110.length])) return;
1235
1415
  cell.text = add.text;
1236
1416
  if (add.blocks) cell.blocks = add.blocks;
1417
+ _chunkXEPKOC2Ocjs.joinCellEdges.call(void 0, cell, add);
1237
1418
  blocks.splice(at, 1);
1238
1419
  }
1239
1420
 
@@ -1269,7 +1450,7 @@ var WINANSI_REVERSE = {
1269
1450
  };
1270
1451
  function symbolFontTable(fontName) {
1271
1452
  if (!fontName) return void 0;
1272
- if (/wingdings(?![\s-]*[23])/i.test(fontName)) return _chunkXTFN5WKScjs.WINGDINGS;
1453
+ if (/wingdings(?![\s-]*[23])/i.test(fontName)) return _chunkR2BUANHQcjs.WINGDINGS;
1273
1454
  return void 0;
1274
1455
  }
1275
1456
  function remapSymbolText(text, table) {
@@ -1397,7 +1578,7 @@ function layout(toks) {
1397
1578
  const bar = rest.find((t) => t.bar && t.x >= rt.x && t.x <= rt.x + rt.w + 2 && Math.abs(t.y - rt.y) <= size * 1.5);
1398
1579
  if (!bar) continue;
1399
1580
  const inner = rest.filter((t) => !t.bar && t !== rt && t.x + t.w / 2 > bar.x && t.x + t.w / 2 < bar.x + bar.w && bar.y - t.y > 0 && bar.y - t.y <= size * 1.4);
1400
- const tok = { text: `\\sqrt{${linear(inner)}}`, x: rt.x, w: bar.x + bar.w - rt.x, y: _nullishCoalesce(_optionalChain([inner, 'access', _101 => _101[0], 'optionalAccess', _102 => _102.y]), () => ( rt.y)), size: Math.max(rt.size, ...inner.map((t) => t.size)), bar: false };
1581
+ const tok = { text: `\\sqrt{${linear(inner)}}`, x: rt.x, w: bar.x + bar.w - rt.x, y: _nullishCoalesce(_optionalChain([inner, 'access', _111 => _111[0], 'optionalAccess', _112 => _112.y]), () => ( rt.y)), size: Math.max(rt.size, ...inner.map((t) => t.size)), bar: false };
1401
1582
  rest = [...rest.filter((t) => t !== rt && t !== bar && !inner.includes(t)), tok];
1402
1583
  }
1403
1584
  const bars = rest.filter((t) => t.bar).sort((a, b) => a.w - b.w);
@@ -1499,7 +1680,7 @@ function wrapEquationRuns(items, faceName) {
1499
1680
  for (const i of mains) ys.set(i.y, (_nullishCoalesce(ys.get(i.y), () => ( 0))) + 1);
1500
1681
  const top = [...ys].sort((p, q) => q[1] - p[1]);
1501
1682
  const bar = cur.find(isBarItem);
1502
- const lineY = bar && top.length > 1 && top[0][1] === top[1][1] ? Math.round(bar.y + size * 0.3) : _nullishCoalesce(_optionalChain([top, 'access', _103 => _103[0], 'optionalAccess', _104 => _104[0]]), () => ( cur[0].y));
1683
+ const lineY = bar && top.length > 1 && top[0][1] === top[1][1] ? Math.round(bar.y + size * 0.3) : _nullishCoalesce(_optionalChain([top, 'access', _113 => _113[0], 'optionalAccess', _114 => _114[0]]), () => ( cur[0].y));
1503
1684
  const base = { ..._nullishCoalesce(mains[0], () => ( cur[0])), y: lineY, fontSize: size || cur[0].fontSize };
1504
1685
  const x1 = Math.min(...cur.map((i) => i.x)), x2 = Math.max(...cur.map((i) => i.x + i.w));
1505
1686
  added.push({ ...base, text: `$${tex}$`, x: x1, w: x2 - x1, hasSpaceBefore: true });
@@ -1845,7 +2026,7 @@ function joinVerticalColumns(items) {
1845
2026
  const groups = [];
1846
2027
  for (const col of columns) {
1847
2028
  const g2 = groups[groups.length - 1];
1848
- const last = _optionalChain([g2, 'optionalAccess', _105 => _105[g2.length - 1]]);
2029
+ const last = _optionalChain([g2, 'optionalAccess', _115 => _115[g2.length - 1]]);
1849
2030
  const fs = col.items[0].fontSize;
1850
2031
  if (last && last.x - col.x >= fs * 1.2 && last.x - col.x <= fs * 4 && Math.abs(last.items[0].y - col.items[0].y) <= fs * 1.2) g2.push(col);
1851
2032
  else groups.push([col]);
@@ -2031,7 +2212,7 @@ function relocateEndnotes(blocks) {
2031
2212
  }
2032
2213
  const shapes = /* @__PURE__ */ new Map();
2033
2214
  for (const h of heads) shapes.set(h.shape, (_nullishCoalesce(shapes.get(h.shape), () => ( 0))) + 1);
2034
- const main = _optionalChain([[...shapes], 'access', _106 => _106.sort, 'call', _107 => _107((a, b) => b[1] - a[1]), 'access', _108 => _108[0], 'optionalAccess', _109 => _109[0]]);
2215
+ const main = _optionalChain([[...shapes], 'access', _116 => _116.sort, 'call', _117 => _117((a, b) => b[1] - a[1]), 'access', _118 => _118[0], 'optionalAccess', _119 => _119[0]]);
2035
2216
  if (!main || !/#/.test(main)) return blocks;
2036
2217
  const lastRun = (hs) => {
2037
2218
  let run2 = [];
@@ -2132,7 +2313,7 @@ var RUN_GAP = 5;
2132
2313
  function removeSideTabs(blocks, pageWidths) {
2133
2314
  const edges = /* @__PURE__ */ new Map();
2134
2315
  for (const b of blocks) {
2135
- if (!b.bbox || b.pageNumber === void 0 || [..._nullishCoalesce(_optionalChain([b, 'access', _110 => _110.text, 'optionalAccess', _111 => _111.trim, 'call', _112 => _112()]), () => ( ""))].length <= MAX_CHARS) continue;
2316
+ if (!b.bbox || b.pageNumber === void 0 || [..._nullishCoalesce(_optionalChain([b, 'access', _120 => _120.text, 'optionalAccess', _121 => _121.trim, 'call', _122 => _122()]), () => ( ""))].length <= MAX_CHARS) continue;
2136
2317
  const e = _nullishCoalesce(edges.get(b.pageNumber), () => ( { lefts: [], rights: [] }));
2137
2318
  e.lefts.push(b.bbox.x);
2138
2319
  e.rights.push(b.bbox.x + b.bbox.width);
@@ -2148,7 +2329,7 @@ function removeSideTabs(blocks, pageWidths) {
2148
2329
  const fallback = all.length ? { left: q(all.map((e) => e.left), 0.5), right: q(all.map((e) => e.right), 0.5) } : void 0;
2149
2330
  const key = (b) => {
2150
2331
  const w = b.pageNumber !== void 0 ? pageWidths.get(b.pageNumber) : void 0;
2151
- const text = _optionalChain([b, 'access', _113 => _113.text, 'optionalAccess', _114 => _114.trim, 'call', _115 => _115()]);
2332
+ const text = _optionalChain([b, 'access', _123 => _123.text, 'optionalAccess', _124 => _124.trim, 'call', _125 => _125()]);
2152
2333
  const area = _nullishCoalesce((b.pageNumber !== void 0 ? body.get(b.pageNumber) : void 0), () => ( fallback));
2153
2334
  if (!w || !area || !b.bbox || !text || b.type === "table" || [...text].length > MAX_CHARS) return null;
2154
2335
  const side = b.bbox.x + b.bbox.width <= Math.min(w * BAND, area.left - 1) ? "L" : b.bbox.x >= Math.max(w * (1 - BAND), area.right + 1) ? "R" : null;
@@ -2224,7 +2405,7 @@ function inlineFootnotes(blocks, pages) {
2224
2405
  open = true;
2225
2406
  continue;
2226
2407
  }
2227
- const prev = pb[j - 1], line = (_nullishCoalesce(_nullishCoalesce(_optionalChain([b, 'access', _116 => _116.style, 'optionalAccess', _117 => _117.fontSize]), () => ( _optionalChain([b, 'access', _118 => _118.bbox, 'optionalAccess', _119 => _119.height]))), () => ( 10))) * 1.5;
2408
+ const prev = pb[j - 1], line = (_nullishCoalesce(_nullishCoalesce(_optionalChain([b, 'access', _126 => _126.style, 'optionalAccess', _127 => _127.fontSize]), () => ( _optionalChain([b, 'access', _128 => _128.bbox, 'optionalAccess', _129 => _129.height]))), () => ( 10))) * 1.5;
2228
2409
  if (open && b.bbox && prev.bbox && prev.bbox.y - top(b) <= line && !/^[-–—\s\d]+$/.test(b.text)) {
2229
2410
  notes[notes.length - 1].text += " " + b.text.trim();
2230
2411
  notes[notes.length - 1].blocks.push(b);
@@ -2247,7 +2428,7 @@ var CAPTION = /^(?:Table|Figure|Fig\.?)\s*\d+(?:\.\d+)*\s*[.:]/i;
2247
2428
  var EQUATION_NUMBER = /\t\(\d{1,3}[a-z]?\)\s*$/;
2248
2429
  var DISPLAY_MATH = /=|[√∑∏∫∂∇≤≥≈≠∈∀∃]/;
2249
2430
  function isRunningHead(block, page, pageHeight) {
2250
- const box = block.bbox, text = _optionalChain([block, 'access', _120 => _120.text, 'optionalAccess', _121 => _121.trim, 'call', _122 => _122()]);
2431
+ const box = block.bbox, text = _optionalChain([block, 'access', _130 => _130.text, 'optionalAccess', _131 => _131.trim, 'call', _132 => _132()]);
2251
2432
  if (!box || !text || !pageHeight) return false;
2252
2433
  const top = box.y + box.height >= pageHeight * 0.9;
2253
2434
  const bottom = box.y <= pageHeight * 0.1;
@@ -2255,7 +2436,7 @@ function isRunningHead(block, page, pageHeight) {
2255
2436
  const others = page.filter((o) => o !== block && o.bbox && o.type !== "image" && o.type !== "separator");
2256
2437
  if (top && others.some((o) => o.bbox.y + o.bbox.height > box.y + box.height)) return false;
2257
2438
  if (bottom && others.some((o) => o.bbox.y < box.y)) return false;
2258
- if (bottom && box.height <= (_nullishCoalesce(_optionalChain([block, 'access', _123 => _123.style, 'optionalAccess', _124 => _124.fontSize]), () => ( 0))) * 1.6) return true;
2439
+ if (bottom && box.height <= (_nullishCoalesce(_optionalChain([block, 'access', _133 => _133.style, 'optionalAccess', _134 => _134.fontSize]), () => ( 0))) * 1.6) return true;
2259
2440
  if (!text.includes(" ")) return false;
2260
2441
  const parts = text.split(/\t+/).map((part) => part.trim()).filter(Boolean);
2261
2442
  if (parts.length >= 2 && (PAGE_NUMBER.test(parts[0]) || PAGE_NUMBER.test(parts[parts.length - 1]))) return true;
@@ -2264,7 +2445,7 @@ function isRunningHead(block, page, pageHeight) {
2264
2445
  return right > left && box.width >= (right - left) * 0.6;
2265
2446
  }
2266
2447
  function unbalancedClose(text) {
2267
- return (_nullishCoalesce(_optionalChain([text, 'access', _125 => _125.match, 'call', _126 => _126(/\)/g), 'optionalAccess', _127 => _127.length]), () => ( 0))) > (_nullishCoalesce(_optionalChain([text, 'access', _128 => _128.match, 'call', _129 => _129(/\(/g), 'optionalAccess', _130 => _130.length]), () => ( 0)));
2448
+ return (_nullishCoalesce(_optionalChain([text, 'access', _135 => _135.match, 'call', _136 => _136(/\)/g), 'optionalAccess', _137 => _137.length]), () => ( 0))) > (_nullishCoalesce(_optionalChain([text, 'access', _138 => _138.match, 'call', _139 => _139(/\(/g), 'optionalAccess', _140 => _140.length]), () => ( 0)));
2268
2449
  }
2269
2450
  function demoteNonHeadingRoles(blocks, pageHeights, faceNames) {
2270
2451
  const byPage = /* @__PURE__ */ new Map();
@@ -2277,7 +2458,7 @@ function demoteNonHeadingRoles(blocks, pageHeights, faceNames) {
2277
2458
  for (const [pageNumber, page] of byPage) {
2278
2459
  const chars = /* @__PURE__ */ new Map();
2279
2460
  for (const b of page) {
2280
- if (b.type !== "paragraph" && b.type !== "heading" || !b.text || !_optionalChain([b, 'access', _131 => _131.style, 'optionalAccess', _132 => _132.fontName]) || !b.style.fontSize) continue;
2461
+ if (b.type !== "paragraph" && b.type !== "heading" || !b.text || !_optionalChain([b, 'access', _141 => _141.style, 'optionalAccess', _142 => _142.fontName]) || !b.style.fontSize) continue;
2281
2462
  const key2 = `${b.style.fontName}:${b.style.fontSize}`;
2282
2463
  chars.set(key2, (_nullishCoalesce(chars.get(key2), () => ( 0))) + b.text.length);
2283
2464
  }
@@ -2288,48 +2469,48 @@ function demoteNonHeadingRoles(blocks, pageHeights, faceNames) {
2288
2469
  const block = blocks[i];
2289
2470
  if (block.type !== "heading" || !block.text) continue;
2290
2471
  const text = block.text.replace(/<[^>]+>/g, "").trim();
2291
- const fsz = _nullishCoalesce(_optionalChain([block, 'access', _133 => _133.style, 'optionalAccess', _134 => _134.fontSize]), () => ( 0));
2292
- const tocEntry = i > 0 && _chunkWDQTFAXYcjs.TOC_BLOCKS.has(blocks[i - 1]) && _chunkWDQTFAXYcjs.TOC_BLOCKS.has(blocks[i + 1]);
2472
+ const fsz = _nullishCoalesce(_optionalChain([block, 'access', _143 => _143.style, 'optionalAccess', _144 => _144.fontSize]), () => ( 0));
2473
+ const tocEntry = i > 0 && _chunkXEPKOC2Ocjs.TOC_BLOCKS.has(blocks[i - 1]) && _chunkXEPKOC2Ocjs.TOC_BLOCKS.has(blocks[i + 1]);
2293
2474
  const page = _nullishCoalesce(byPage.get(_nullishCoalesce(block.pageNumber, () => ( 0))), () => ( []));
2294
- const proseStyle = _optionalChain([block, 'access', _135 => _135.style, 'optionalAccess', _136 => _136.fontName]) && bodyStyle.get(_nullishCoalesce(block.pageNumber, () => ( 0))) === `${block.style.fontName}:${block.style.fontSize}` && text.length > 60;
2475
+ const proseStyle = _optionalChain([block, 'access', _145 => _145.style, 'optionalAccess', _146 => _146.fontName]) && bodyStyle.get(_nullishCoalesce(block.pageNumber, () => ( 0))) === `${block.style.fontName}:${block.style.fontSize}` && text.length > 60;
2295
2476
  const next = blocks[i + 1];
2296
- const nb = _optionalChain([next, 'optionalAccess', _137 => _137.bbox]), bb = block.bbox;
2297
- const chapterNumber = !!nb && !!bb && fsz >= (_nullishCoalesce(_optionalChain([next, 'optionalAccess', _138 => _138.style, 'optionalAccess', _139 => _139.fontSize]), () => ( 0))) * 1.2 && Math.abs(bb.x - nb.x) > fsz && Math.abs(bb.x + bb.width / 2 - (nb.x + nb.width / 2)) < nb.width * 0.1;
2298
- if (/^\d+(?:\.\d+)*\.?$/.test(text) && _optionalChain([next, 'optionalAccess', _140 => _140.type]) === "heading" && next.text && next.pageNumber === block.pageNumber && !chapterNumber) {
2477
+ const nb = _optionalChain([next, 'optionalAccess', _147 => _147.bbox]), bb = block.bbox;
2478
+ const chapterNumber = !!nb && !!bb && fsz >= (_nullishCoalesce(_optionalChain([next, 'optionalAccess', _148 => _148.style, 'optionalAccess', _149 => _149.fontSize]), () => ( 0))) * 1.2 && Math.abs(bb.x - nb.x) > fsz && Math.abs(bb.x + bb.width / 2 - (nb.x + nb.width / 2)) < nb.width * 0.1;
2479
+ if (/^\d+(?:\.\d+)*\.?$/.test(text) && _optionalChain([next, 'optionalAccess', _150 => _150.type]) === "heading" && next.text && next.pageNumber === block.pageNumber && !chapterNumber) {
2299
2480
  next.text = `${block.text.trim()} ${next.text.trim()}`;
2300
2481
  blocks.splice(i--, 1);
2301
2482
  continue;
2302
2483
  }
2303
- if ((_optionalChain([next, 'optionalAccess', _141 => _141.type]) === "paragraph" || _optionalChain([next, 'optionalAccess', _142 => _142.type]) === "heading" && !CAPTION.test(text)) && next.pageNumber === block.pageNumber && next.text && next.bbox && block.bbox && _optionalChain([next, 'access', _143 => _143.style, 'optionalAccess', _144 => _144.fontName]) === _optionalChain([block, 'access', _145 => _145.style, 'optionalAccess', _146 => _146.fontName]) && _optionalChain([next, 'access', _147 => _147.style, 'optionalAccess', _148 => _148.fontSize]) === _optionalChain([block, 'access', _149 => _149.style, 'optionalAccess', _150 => _150.fontSize]) && fsz > 0 && /^[a-z]/.test(next.text.trim()) && next.text.trim().length <= 40 && !/[.:;!?]$/.test(next.text.trim()) && block.bbox.y - (next.bbox.y + next.bbox.height) < fsz * 1.2 && Math.abs(next.bbox.x - block.bbox.x) < fsz) {
2484
+ if ((_optionalChain([next, 'optionalAccess', _151 => _151.type]) === "paragraph" || _optionalChain([next, 'optionalAccess', _152 => _152.type]) === "heading" && !CAPTION.test(text)) && next.pageNumber === block.pageNumber && next.text && next.bbox && block.bbox && _optionalChain([next, 'access', _153 => _153.style, 'optionalAccess', _154 => _154.fontName]) === _optionalChain([block, 'access', _155 => _155.style, 'optionalAccess', _156 => _156.fontName]) && _optionalChain([next, 'access', _157 => _157.style, 'optionalAccess', _158 => _158.fontSize]) === _optionalChain([block, 'access', _159 => _159.style, 'optionalAccess', _160 => _160.fontSize]) && fsz > 0 && /^[a-z]/.test(next.text.trim()) && next.text.trim().length <= 40 && !/[.:;!?]$/.test(next.text.trim()) && block.bbox.y - (next.bbox.y + next.bbox.height) < fsz * 1.2 && Math.abs(next.bbox.x - block.bbox.x) < fsz) {
2304
2485
  block.text = `${block.text.trim()} ${next.text.trim()}`;
2305
2486
  block.bbox = { ...block.bbox, y: next.bbox.y, height: block.bbox.y + block.bbox.height - next.bbox.y };
2306
2487
  blocks.splice(i + 1, 1);
2307
2488
  }
2308
2489
  const after = blocks[i + 2];
2309
- if ((_optionalChain([next, 'optionalAccess', _151 => _151.type]) === "paragraph" || _optionalChain([next, 'optionalAccess', _152 => _152.type]) === "heading") && /^(?:&|\+|and|or)$/i.test(_nullishCoalesce(_optionalChain([next, 'access', _153 => _153.text, 'optionalAccess', _154 => _154.trim, 'call', _155 => _155()]), () => ( ""))) && _optionalChain([after, 'optionalAccess', _156 => _156.type]) === "heading" && after.text && after.pageNumber === block.pageNumber && next.pageNumber === block.pageNumber && _optionalChain([after, 'access', _157 => _157.style, 'optionalAccess', _158 => _158.fontSize]) === _optionalChain([block, 'access', _159 => _159.style, 'optionalAccess', _160 => _160.fontSize])) {
2490
+ if ((_optionalChain([next, 'optionalAccess', _161 => _161.type]) === "paragraph" || _optionalChain([next, 'optionalAccess', _162 => _162.type]) === "heading") && /^(?:&|\+|and|or)$/i.test(_nullishCoalesce(_optionalChain([next, 'access', _163 => _163.text, 'optionalAccess', _164 => _164.trim, 'call', _165 => _165()]), () => ( ""))) && _optionalChain([after, 'optionalAccess', _166 => _166.type]) === "heading" && after.text && after.pageNumber === block.pageNumber && next.pageNumber === block.pageNumber && _optionalChain([after, 'access', _167 => _167.style, 'optionalAccess', _168 => _168.fontSize]) === _optionalChain([block, 'access', _169 => _169.style, 'optionalAccess', _170 => _170.fontSize])) {
2310
2491
  block.text = `${block.text.trim()} ${next.text.trim()} ${after.text.trim()}`;
2311
2492
  blocks.splice(i + 1, 2);
2312
2493
  }
2313
2494
  const tiny = fsz > 0 && fsz < 7.5;
2314
2495
  const prev = blocks[i - 1];
2315
- if (_optionalChain([prev, 'optionalAccess', _161 => _161.type]) === "paragraph" && prev.pageNumber === block.pageNumber && /^[a-z]{1,3}[.)]$/.test(_nullishCoalesce(_optionalChain([prev, 'access', _162 => _162.text, 'optionalAccess', _163 => _163.trim, 'call', _164 => _164()]), () => ( ""))) && prev.bbox && block.bbox && Math.abs(prev.bbox.y - block.bbox.y) < 2 && prev.bbox.x + prev.bbox.width <= block.bbox.x) {
2496
+ if (_optionalChain([prev, 'optionalAccess', _171 => _171.type]) === "paragraph" && prev.pageNumber === block.pageNumber && /^[a-z]{1,3}[.)]$/.test(_nullishCoalesce(_optionalChain([prev, 'access', _172 => _172.text, 'optionalAccess', _173 => _173.trim, 'call', _174 => _174()]), () => ( ""))) && prev.bbox && block.bbox && Math.abs(prev.bbox.y - block.bbox.y) < 2 && prev.bbox.x + prev.bbox.width <= block.bbox.x) {
2316
2497
  prev.text = `${prev.text.trim()} ${block.text.trim()}`;
2317
2498
  prev.bbox = { ...prev.bbox, width: block.bbox.x + block.bbox.width - prev.bbox.x };
2318
2499
  blocks.splice(i--, 1);
2319
2500
  continue;
2320
2501
  }
2321
- if (_optionalChain([prev, 'optionalAccess', _165 => _165.type]) === "paragraph" && prev.pageNumber === block.pageNumber && /^\d{1,2}(?:\.\d{1,2})*\.?$/.test(_nullishCoalesce(_optionalChain([prev, 'access', _166 => _166.text, 'optionalAccess', _167 => _167.trim, 'call', _168 => _168()]), () => ( ""))) && prev.bbox && block.bbox && fsz > 0 && (Math.abs(prev.bbox.y - block.bbox.y) < 2 && prev.bbox.x + prev.bbox.width <= block.bbox.x && block.bbox.x - (prev.bbox.x + prev.bbox.width) < fsz * 3 || Math.abs(prev.bbox.x - block.bbox.x) < 2 && (_nullishCoalesce(_optionalChain([prev, 'access', _169 => _169.style, 'optionalAccess', _170 => _170.fontSize]), () => ( 0))) >= fsz && prev.bbox.y - (block.bbox.y + block.bbox.height) < fsz * 1.5)) {
2502
+ if (_optionalChain([prev, 'optionalAccess', _175 => _175.type]) === "paragraph" && prev.pageNumber === block.pageNumber && /^\d{1,2}(?:\.\d{1,2})*\.?$/.test(_nullishCoalesce(_optionalChain([prev, 'access', _176 => _176.text, 'optionalAccess', _177 => _177.trim, 'call', _178 => _178()]), () => ( ""))) && prev.bbox && block.bbox && fsz > 0 && (Math.abs(prev.bbox.y - block.bbox.y) < 2 && prev.bbox.x + prev.bbox.width <= block.bbox.x && block.bbox.x - (prev.bbox.x + prev.bbox.width) < fsz * 3 || Math.abs(prev.bbox.x - block.bbox.x) < 2 && (_nullishCoalesce(_optionalChain([prev, 'access', _179 => _179.style, 'optionalAccess', _180 => _180.fontSize]), () => ( 0))) >= fsz && prev.bbox.y - (block.bbox.y + block.bbox.height) < fsz * 1.5)) {
2322
2503
  block.text = `${prev.text.trim()} ${block.text.trim()}`;
2323
2504
  blocks.splice(i - 1, 1);
2324
2505
  i -= 2;
2325
2506
  continue;
2326
2507
  }
2327
- const box = block.bbox, size = _nullishCoalesce(_optionalChain([block, 'access', _171 => _171.style, 'optionalAccess', _172 => _172.fontSize]), () => ( 0));
2328
- const kicker = !!box && size > 0 && _optionalChain([next, 'optionalAccess', _173 => _173.type]) === "heading" && next.pageNumber === block.pageNumber && !!next.bbox && (_nullishCoalesce(_optionalChain([next, 'access', _174 => _174.style, 'optionalAccess', _175 => _175.fontSize]), () => ( 0))) >= size * 1.3 && box.y - (next.bbox.y + next.bbox.height) <= size * 3 && Math.min(box.x + box.width, next.bbox.x + next.bbox.width) - Math.max(box.x, next.bbox.x) >= Math.min(box.width, next.bbox.width) * 0.5 && !page.some((o) => o !== block && o.bbox && o.bbox.y > box.y + box.height && o.type !== "image");
2329
- const face = _nullishCoalesce(_optionalChain([faceNames, 'optionalAccess', _176 => _176.get, 'call', _177 => _177(_nullishCoalesce(_optionalChain([block, 'access', _178 => _178.style, 'optionalAccess', _179 => _179.fontName]), () => ( "")))]), () => ( ""));
2508
+ const box = block.bbox, size = _nullishCoalesce(_optionalChain([block, 'access', _181 => _181.style, 'optionalAccess', _182 => _182.fontSize]), () => ( 0));
2509
+ const kicker = !!box && size > 0 && _optionalChain([next, 'optionalAccess', _183 => _183.type]) === "heading" && next.pageNumber === block.pageNumber && !!next.bbox && (_nullishCoalesce(_optionalChain([next, 'access', _184 => _184.style, 'optionalAccess', _185 => _185.fontSize]), () => ( 0))) >= size * 1.3 && box.y - (next.bbox.y + next.bbox.height) <= size * 3 && Math.min(box.x + box.width, next.bbox.x + next.bbox.width) - Math.max(box.x, next.bbox.x) >= Math.min(box.width, next.bbox.width) * 0.5 && !page.some((o) => o !== block && o.bbox && o.bbox.y > box.y + box.height && o.type !== "image");
2510
+ const face = _nullishCoalesce(_optionalChain([faceNames, 'optionalAccess', _186 => _186.get, 'call', _187 => _187(_nullishCoalesce(_optionalChain([block, 'access', _188 => _188.style, 'optionalAccess', _189 => _189.fontName]), () => ( "")))]), () => ( ""));
2330
2511
  const [bodyFace, bodySize] = (_nullishCoalesce(bodyStyle.get(_nullishCoalesce(block.pageNumber, () => ( 0))), () => ( ""))).split(":");
2331
- const byline = /Italic|Oblique/i.test(face) && !/Bold|Black|Heavy|Semibold/i.test(face) && !!bodyFace && size <= Number(bodySize) + 0.5 && _optionalChain([blocks, 'access', _180 => _180[i - 1], 'optionalAccess', _181 => _181.type]) === "heading" && blocks[i - 1].pageNumber === block.pageNumber;
2332
- const ocrFragment = _optionalChain([block, 'access', _182 => _182.style, 'optionalAccess', _183 => _183.fontName]) === "ocr" && (/^[.,;:…·•-]/.test(text) || text.includes("\u2026") || (_nullishCoalesce(_optionalChain([text, 'access', _184 => _184.match, 'call', _185 => _185(/\p{L}/gu), 'optionalAccess', _186 => _186.length]), () => ( 0))) < 2 || text.split(/\s+/).length > 7);
2512
+ const byline = /Italic|Oblique/i.test(face) && !/Bold|Black|Heavy|Semibold/i.test(face) && !!bodyFace && size <= Number(bodySize) + 0.5 && _optionalChain([blocks, 'access', _190 => _190[i - 1], 'optionalAccess', _191 => _191.type]) === "heading" && blocks[i - 1].pageNumber === block.pageNumber;
2513
+ const ocrFragment = _optionalChain([block, 'access', _192 => _192.style, 'optionalAccess', _193 => _193.fontName]) === "ocr" && (/^[.,;:…·•-]/.test(text) || text.includes("\u2026") || (_nullishCoalesce(_optionalChain([text, 'access', _194 => _194.match, 'call', _195 => _195(/\p{L}/gu), 'optionalAccess', _196 => _196.length]), () => ( 0))) < 2 || text.split(/\s+/).length > 7);
2333
2514
  if (ocrFragment || tocEntry || proseStyle || kicker || byline || tiny || !/\p{L}/u.test(text) && !chapterNumber || /^[a-z]/.test(text) || CAPTION.test(text) || EQUATION_NUMBER.test(block.text) || DISPLAY_MATH.test(text) || // 닫는 괄호가 여는 괄호보다 많으면 앞 줄에서 이어진 문장 조각이다 ("Fact-checking) and is used …") — "1)"·"가)" 앞머리 번호는 빼고 센다
2334
2515
  unbalancedClose(text.replace(/^\s*[\dA-Za-z가-힣ⅰ-ⅹ]{1,3}\)\s*/, "")) || isRunningHead(block, page, pageHeights.get(_nullishCoalesce(block.pageNumber, () => ( 0))))) {
2335
2516
  block.type = "paragraph";
@@ -2364,28 +2545,28 @@ var CAPTION_LABEL = /^(?:figure|fig\.|diagram|table|chart|graph|exhibit|box)\s*[
2364
2545
  function captionTableText(t) {
2365
2546
  if (!t || t.rows !== 1 || t.cols !== 2) return null;
2366
2547
  const [label, body] = t.cells[0];
2367
- if (!label || !body || _optionalChain([label, 'access', _187 => _187.blocks, 'optionalAccess', _188 => _188.length]) || _optionalChain([body, 'access', _189 => _189.blocks, 'optionalAccess', _190 => _190.length]) || !CAPTION_LABEL.test(label.text.trim()) || !body.text.trim()) return null;
2548
+ if (!label || !body || _optionalChain([label, 'access', _197 => _197.blocks, 'optionalAccess', _198 => _198.length]) || _optionalChain([body, 'access', _199 => _199.blocks, 'optionalAccess', _200 => _200.length]) || !CAPTION_LABEL.test(label.text.trim()) || !body.text.trim()) return null;
2368
2549
  return `${label.text.trim()} ${body.text.replace(/\s*\n\s*/g, " ").trim()}`;
2369
2550
  }
2370
2551
  function splitSingleCellTables(blocks) {
2371
2552
  const out = [];
2372
2553
  for (const b of blocks) {
2373
2554
  const t = b.type === "table" ? b.table : void 0;
2374
- const only = t && t.rows === 1 && t.cols === 1 && _optionalChain([t, 'access', _191 => _191.cells, 'access', _192 => _192[0], 'optionalAccess', _193 => _193[0], 'optionalAccess', _194 => _194.blocks, 'optionalAccess', _195 => _195.length]) === 1 ? t.cells[0][0].blocks[0] : void 0;
2555
+ const only = t && t.rows === 1 && t.cols === 1 && _optionalChain([t, 'access', _201 => _201.cells, 'access', _202 => _202[0], 'optionalAccess', _203 => _203[0], 'optionalAccess', _204 => _204.blocks, 'optionalAccess', _205 => _205.length]) === 1 ? t.cells[0][0].blocks[0] : void 0;
2375
2556
  const squash = (s) => s.replace(/\s/g, "");
2376
2557
  const inner = only && (!squash(t.cells[0][0].text) || only.type === "table" && squash(t.cells[0][0].text) === squash(only.table.cells.flat().map((c) => c.text).join(""))) ? only : void 0;
2377
- const caption = _nullishCoalesce(captionTableText(t), () => ( (_optionalChain([inner, 'optionalAccess', _196 => _196.type]) === "table" ? captionTableText(inner.table) : null)));
2558
+ const caption = _nullishCoalesce(captionTableText(t), () => ( (_optionalChain([inner, 'optionalAccess', _206 => _206.type]) === "table" ? captionTableText(inner.table) : null)));
2378
2559
  if (caption) {
2379
2560
  out.push({ type: "paragraph", text: caption, pageNumber: b.pageNumber, bbox: b.bbox });
2380
2561
  continue;
2381
2562
  }
2382
- const cell = t && t.rows === 1 && t.cols === 1 ? _optionalChain([t, 'access', _197 => _197.cells, 'access', _198 => _198[0], 'optionalAccess', _199 => _199[0]]) : void 0;
2383
- if (!cell || _optionalChain([cell, 'access', _200 => _200.blocks, 'optionalAccess', _201 => _201.some, 'call', _202 => _202((x) => x.type === "table")])) {
2563
+ const cell = t && t.rows === 1 && t.cols === 1 ? _optionalChain([t, 'access', _207 => _207.cells, 'access', _208 => _208[0], 'optionalAccess', _209 => _209[0]]) : void 0;
2564
+ if (!cell || _optionalChain([cell, 'access', _210 => _210.blocks, 'optionalAccess', _211 => _211.some, 'call', _212 => _212((x) => x.type === "table")])) {
2384
2565
  out.push(b);
2385
2566
  continue;
2386
2567
  }
2387
2568
  const lines = (_nullishCoalesce(cell.text, () => ( ""))).split(/\n/).map((l) => l.trim()).filter(Boolean);
2388
- if (_optionalChain([t, 'optionalAccess', _203 => _203.caption, 'optionalAccess', _204 => _204.trim, 'call', _205 => _205()])) out.push({ type: "paragraph", text: t.caption.trim(), pageNumber: b.pageNumber, bbox: b.bbox });
2569
+ if (_optionalChain([t, 'optionalAccess', _213 => _213.caption, 'optionalAccess', _214 => _214.trim, 'call', _215 => _215()])) out.push({ type: "paragraph", text: t.caption.trim(), pageNumber: b.pageNumber, bbox: b.bbox });
2389
2570
  for (const text of lines) out.push({ type: "paragraph", text, pageNumber: b.pageNumber, bbox: b.bbox });
2390
2571
  }
2391
2572
  return out;
@@ -2398,7 +2579,7 @@ function joinLatinCellWraps(blocks) {
2398
2579
  const lines = cell.text.split("\n");
2399
2580
  const out = [lines[0]];
2400
2581
  for (const line of lines.slice(1)) {
2401
- if (_chunkWDQTFAXYcjs.latinSoftWrap.call(void 0, out[out.length - 1], line)) out[out.length - 1] = out[out.length - 1].trimEnd() + " " + line.trim();
2582
+ if (_chunkXEPKOC2Ocjs.latinSoftWrap.call(void 0, out[out.length - 1], line)) out[out.length - 1] = out[out.length - 1].trimEnd() + " " + line.trim();
2402
2583
  else out.push(line);
2403
2584
  }
2404
2585
  cell.text = out.join("\n");
@@ -2409,19 +2590,19 @@ function joinLatinCellWraps(blocks) {
2409
2590
  }
2410
2591
  function cleanPdfText(text, opts) {
2411
2592
  let clean = normalizeAraea(stripControlChars(text));
2412
- if (!_optionalChain([opts, 'optionalAccess', _206 => _206.keepLoneNumbers])) {
2593
+ if (!_optionalChain([opts, 'optionalAccess', _216 => _216.keepLoneNumbers])) {
2413
2594
  clean = clean.replace(/^\d{1,4}\n/, "").replace(/\n\d{1,4}\n/g, "\n").replace(/\n\d{1,4}$/, "");
2414
2595
  }
2415
- if (!_optionalChain([opts, 'optionalAccess', _207 => _207.keepLoneNumbers])) clean = clean.replace(/^#{1,6}\s*\d{1,4}\s*$/gm, "");
2596
+ if (!_optionalChain([opts, 'optionalAccess', _217 => _217.keepLoneNumbers])) clean = clean.replace(/^#{1,6}\s*\d{1,4}\s*$/gm, "");
2416
2597
  return mergeKoreanLines(
2417
2598
  clean.replace(/^[\s]*[-–—]\s*[-–—]?\d+[-–—]?[\s]*[-–—]?[\s]*$/gm, "").replace(/^\s*\d+\s*\/\s*\d+\s*$/gm, "").replace(/\.(?: \.){3,}/g, (m) => ".".repeat(m.length + 1 >> 1))
2418
2599
  ).replace(/^(?!\| ---).*$/gm, (line) => {
2419
2600
  if (/^\s*\${1,2}.+\${1,2}\s*$/.test(line)) return line;
2420
2601
  if (line.startsWith("|")) {
2421
- return line.replace(/(?:\\.|[^|\\])+/g, (cell) => cell.split("<br>").map((seg) => seg.replace(/\S(?:.*\S)?/, (t) => _chunkWDQTFAXYcjs.collapseEvenSpacing.call(void 0, t, false))).join("<br>"));
2602
+ return line.replace(/(?:\\.|[^|\\])+/g, (cell) => cell.split("<br>").map((seg) => seg.replace(/\S(?:.*\S)?/, (t) => _chunkXEPKOC2Ocjs.collapseEvenSpacing.call(void 0, t, false))).join("<br>"));
2422
2603
  }
2423
- const mark = _nullishCoalesce(_optionalChain([/^(?:#{1,6}|-) /, 'access', _208 => _208.exec, 'call', _209 => _209(line), 'optionalAccess', _210 => _210[0]]), () => ( ""));
2424
- return mark + _chunkWDQTFAXYcjs.collapseEvenSpacing.call(void 0, line.slice(mark.length), false);
2604
+ const mark = _nullishCoalesce(_optionalChain([/^(?:#{1,6}|-) /, 'access', _218 => _218.exec, 'call', _219 => _219(line), 'optionalAccess', _220 => _220[0]]), () => ( ""));
2605
+ return mark + _chunkXEPKOC2Ocjs.collapseEvenSpacing.call(void 0, line.slice(mark.length), false);
2425
2606
  }).replace(/\\~\\~/g, "~~").replace(/~~~~/g, "").replace(/<u>\s*<\/u>/g, "").replace(/<(sup|sub)>\s*<\/\1>/g, "").replace(/\n{3,}/g, "\n\n").trim();
2426
2607
  }
2427
2608
  function startsWithMarker(line) {
@@ -2453,7 +2634,7 @@ function mergeKoreanLines(text) {
2453
2634
  continue;
2454
2635
  }
2455
2636
  if (/[가-힣·,\-]$/.test(prev) && /^[가-힣(]/.test(curr) && !startsWithMarker(curr) && !isStandaloneHeader(prev) && !startsWithMarker(prev)) {
2456
- result[result.length - 1] = prev + _chunkWDQTFAXYcjs.wrapJoiner.call(void 0, prev, curr) + curr;
2637
+ result[result.length - 1] = prev + _chunkXEPKOC2Ocjs.wrapJoiner.call(void 0, prev, curr) + curr;
2457
2638
  } else {
2458
2639
  result.push(curr);
2459
2640
  }
@@ -2469,7 +2650,7 @@ function applyLinkAnnotations(items, annots) {
2469
2650
  const wrapped = /* @__PURE__ */ new Set();
2470
2651
  for (const a of annots) {
2471
2652
  if (a.subtype !== "Link" || !a.url || !a.rect || a.rect.length < 4) continue;
2472
- const url = _chunkSTM3ORY7cjs.sanitizeHref.call(void 0, a.url);
2653
+ const url = _chunkQNJLLF4Jcjs.sanitizeHref.call(void 0, a.url);
2473
2654
  if (!url) continue;
2474
2655
  const x1 = Math.min(a.rect[0], a.rect[2]), x2 = Math.max(a.rect[0], a.rect[2]);
2475
2656
  const y1 = Math.min(a.rect[1], a.rect[3]), y2 = Math.max(a.rect[1], a.rect[3]);
@@ -2510,7 +2691,7 @@ function mergeLinkRuns(markdown) {
2510
2691
 
2511
2692
  // src/pdf/formula-ocr.ts
2512
2693
  async function applyFormulaOcr(buffer, blocks, pageFilter, effectivePageCount, warnings, _onProgress) {
2513
- const formulaMod = await Promise.resolve().then(() => _interopRequireWildcard(require("./formula-WIMV5TUX.cjs")));
2694
+ const formulaMod = await Promise.resolve().then(() => _interopRequireWildcard(require("./formula-ECNOZT36.cjs")));
2514
2695
  const { FormulaPipeline, ensureFormulaModels } = formulaMod;
2515
2696
  await ensureFormulaModels((p) => {
2516
2697
  if (p.phase === "download" && p.total) {
@@ -2689,13 +2870,13 @@ async function loadPdfWithTimeout(buffer) {
2689
2870
  try {
2690
2871
  return await Promise.race([
2691
2872
  loadingTask.promise.catch((e) => {
2692
- if (e instanceof Error && e.name === "PasswordException") throw new (0, _chunkSTM3ORY7cjs.KordocError)("\uC554\uD638\uB85C \uBCF4\uD638\uB41C PDF \uD30C\uC77C\uC785\uB2C8\uB2E4 (PDF \uC5F4\uAE30 \uC554\uD638\uB294 \uC9C0\uC6D0\uD558\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4)");
2873
+ if (e instanceof Error && e.name === "PasswordException") throw new (0, _chunkQNJLLF4Jcjs.KordocError)("\uC554\uD638\uB85C \uBCF4\uD638\uB41C PDF \uD30C\uC77C\uC785\uB2C8\uB2E4 (PDF \uC5F4\uAE30 \uC554\uD638\uB294 \uC9C0\uC6D0\uD558\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4)");
2693
2874
  throw e;
2694
2875
  }),
2695
2876
  new Promise((_, reject) => {
2696
2877
  timer = setTimeout(() => {
2697
2878
  loadingTask.destroy();
2698
- reject(new (0, _chunkSTM3ORY7cjs.KordocError)("PDF \uB85C\uB529 \uD0C0\uC784\uC544\uC6C3 (30\uCD08 \uCD08\uACFC)"));
2879
+ reject(new (0, _chunkQNJLLF4Jcjs.KordocError)("PDF \uB85C\uB529 \uD0C0\uC784\uC544\uC6C3 (30\uCD08 \uCD08\uACFC)"));
2699
2880
  }, PDF_LOAD_TIMEOUT_MS);
2700
2881
  })
2701
2882
  ]);
@@ -2704,13 +2885,13 @@ async function loadPdfWithTimeout(buffer) {
2704
2885
  }
2705
2886
  }
2706
2887
  async function parsePdfDocument(buffer, options) {
2707
- const formulaBuffer = _optionalChain([options, 'optionalAccess', _211 => _211.formulaOcr]) ? buffer : null;
2708
- const autoOcr = _optionalChain([options, 'optionalAccess', _212 => _212.ocr]) === void 0 && await _chunkWDQTFAXYcjs.ocrModelsCached.call(void 0, );
2709
- const ocrBuffer = _optionalChain([options, 'optionalAccess', _213 => _213.ocr]) || autoOcr ? buffer : null;
2888
+ const formulaBuffer = _optionalChain([options, 'optionalAccess', _221 => _221.formulaOcr]) ? buffer : null;
2889
+ const autoOcr = _optionalChain([options, 'optionalAccess', _222 => _222.ocr]) === void 0 && await _chunkXEPKOC2Ocjs.ocrModelsCached.call(void 0, );
2890
+ const ocrBuffer = _optionalChain([options, 'optionalAccess', _223 => _223.ocr]) || autoOcr ? buffer : null;
2710
2891
  const doc = await loadPdfWithTimeout(buffer);
2711
2892
  try {
2712
2893
  const pageCount = doc.numPages;
2713
- if (pageCount === 0) throw new (0, _chunkSTM3ORY7cjs.KordocError)("PDF\uC5D0 \uD398\uC774\uC9C0\uAC00 \uC5C6\uC2B5\uB2C8\uB2E4.");
2894
+ if (pageCount === 0) throw new (0, _chunkQNJLLF4Jcjs.KordocError)("PDF\uC5D0 \uD398\uC774\uC9C0\uAC00 \uC5C6\uC2B5\uB2C8\uB2E4.");
2714
2895
  const metadata = { pageCount, pageMode: "layout" };
2715
2896
  await extractPdfMetadata(doc, metadata);
2716
2897
  const blocks = [];
@@ -2719,8 +2900,8 @@ async function parsePdfDocument(buffer, options) {
2719
2900
  let totalChars = 0;
2720
2901
  let totalTextBytes = 0;
2721
2902
  const effectivePageCount = Math.min(pageCount, MAX_PAGES);
2722
- const pageFilter = _optionalChain([options, 'optionalAccess', _214 => _214.pages]) ? _chunkJ55UQC5Hcjs.parsePageRange.call(void 0, options.pages, effectivePageCount) : null;
2723
- if (pageCount > MAX_PAGES && (!_optionalChain([options, 'optionalAccess', _215 => _215.pages]) || _chunkJ55UQC5Hcjs.hasRequestedPagesAfter.call(void 0, options.pages, MAX_PAGES, pageCount))) {
2903
+ const pageFilter = _optionalChain([options, 'optionalAccess', _224 => _224.pages]) ? _chunkJ55UQC5Hcjs.parsePageRange.call(void 0, options.pages, effectivePageCount) : null;
2904
+ if (pageCount > MAX_PAGES && (!_optionalChain([options, 'optionalAccess', _225 => _225.pages]) || _chunkJ55UQC5Hcjs.hasRequestedPagesAfter.call(void 0, options.pages, MAX_PAGES, pageCount))) {
2724
2905
  warnings.push({ message: `${pageCount}\uCABD \uC911 \uC55E ${MAX_PAGES}\uCABD\uB9CC \uD30C\uC2F1\uD588\uC2B5\uB2C8\uB2E4 (\uCABD \uC218 \uC0C1\uD55C)`, code: "PARTIAL_PARSE" });
2725
2906
  }
2726
2907
  const totalTarget = pageFilter ? pageFilter.size : effectivePageCount;
@@ -2737,7 +2918,7 @@ async function parsePdfDocument(buffer, options) {
2737
2918
  const pageImageBlocks = /* @__PURE__ */ new Map();
2738
2919
  const carry = {};
2739
2920
  const vectorPageOps = /* @__PURE__ */ new Map();
2740
- const wrapLexicon = new (0, _chunkWDQTFAXYcjs.WrapLexicon)();
2921
+ const wrapLexicon = new (0, _chunkXEPKOC2Ocjs.WrapLexicon)();
2741
2922
  const noteMarks = /* @__PURE__ */ new Map();
2742
2923
  let parsedPages = 0;
2743
2924
  for (let i = 1; i <= effectivePageCount; i++) {
@@ -2760,13 +2941,13 @@ async function parsePdfDocument(buffer, options) {
2760
2941
  return void 0;
2761
2942
  }
2762
2943
  };
2763
- const differencesOf = (loadedName) => _optionalChain([fontObj, 'call', _216 => _216(loadedName), 'optionalAccess', _217 => _217.differences]);
2764
- restoreNamedGlyphs(rawItems, rawOps.fnArray, rawOps.argsArray, differencesOf, (n) => _optionalChain([fontObj, 'call', _218 => _218(n), 'optionalAccess', _219 => _219.name]));
2944
+ const differencesOf = (loadedName) => _optionalChain([fontObj, 'call', _226 => _226(loadedName), 'optionalAccess', _227 => _227.differences]);
2945
+ restoreNamedGlyphs(rawItems, rawOps.fnArray, rawOps.argsArray, differencesOf, (n) => _optionalChain([fontObj, 'call', _228 => _228(n), 'optionalAccess', _229 => _229.name]));
2765
2946
  restoreTrackedSpacing(rawItems, rawOps.fnArray, rawOps.argsArray);
2766
2947
  markSyntheticSpaces(rawItems, rawOps.fnArray, rawOps.argsArray);
2767
2948
  const occluded = occludedTextItems(rawItems, rawOps.fnArray, rawOps.argsArray);
2768
- const items = _chunkWDQTFAXYcjs.normalizeItems.call(void 0, occluded.size ? rawItems.filter((it) => !occluded.has(it)) : rawItems);
2769
- const filtered = _chunkWDQTFAXYcjs.filterHiddenText.call(void 0, items, pageW, pageH, viewX1, viewY1);
2949
+ const items = _chunkXEPKOC2Ocjs.normalizeItems.call(void 0, occluded.size ? rawItems.filter((it) => !occluded.has(it)) : rawItems);
2950
+ const filtered = _chunkXEPKOC2Ocjs.filterHiddenText.call(void 0, items, pageW, pageH, viewX1, viewY1);
2770
2951
  const joined = joinVerticalColumns(filtered.visible);
2771
2952
  const visible = dropTabLeaderDots(joined);
2772
2953
  const hiddenCount = filtered.hiddenCount + occluded.size;
@@ -2790,7 +2971,7 @@ async function parsePdfDocument(buffer, options) {
2790
2971
  fnArray: [_pdfmjs.OPS.transform, ...rawOps.fnArray],
2791
2972
  argsArray: [[1, 0, 0, 1, -viewX1, -viewY1], ...rawOps.argsArray]
2792
2973
  } : rawOps;
2793
- remapSymbolFontItems(visible, (loadedName) => _optionalChain([fontObj, 'call', _220 => _220(loadedName), 'optionalAccess', _221 => _221.name]));
2974
+ remapSymbolFontItems(visible, (loadedName) => _optionalChain([fontObj, 'call', _230 => _230(loadedName), 'optionalAccess', _231 => _231.name]));
2794
2975
  remapControlGlyphs(visible, differencesOf);
2795
2976
  const faces = /* @__PURE__ */ new Map();
2796
2977
  for (const it of visible) {
@@ -2798,17 +2979,17 @@ async function parsePdfDocument(buffer, options) {
2798
2979
  let face = faces.get(it.fontName);
2799
2980
  if (face === void 0) {
2800
2981
  const obj = fontObj(it.fontName);
2801
- face = _optionalChain([obj, 'optionalAccess', _222 => _222.isType3Font]) && /^[A-Z]{6}\+./.test(_nullishCoalesce(obj.name, () => ( ""))) && obj.name.slice(7) || it.fontName;
2982
+ face = _optionalChain([obj, 'optionalAccess', _232 => _232.isType3Font]) && /^[A-Z]{6}\+./.test(_nullishCoalesce(obj.name, () => ( ""))) && obj.name.slice(7) || it.fontName;
2802
2983
  faces.set(it.fontName, face);
2803
2984
  }
2804
2985
  it.fontName = face;
2805
- if (!faceNames.has(face)) faceNames.set(face, (_nullishCoalesce(_optionalChain([fontObj, 'call', _223 => _223(face), 'optionalAccess', _224 => _224.name]), () => ( ""))).replace(/^[A-Z]{6}\+/, ""));
2986
+ if (!faceNames.has(face)) faceNames.set(face, (_nullishCoalesce(_optionalChain([fontObj, 'call', _233 => _233(face), 'optionalAccess', _234 => _234.name]), () => ( ""))).replace(/^[A-Z]{6}\+/, ""));
2806
2987
  }
2807
- for (const it of visible) if (it.text.includes("$")) it.text = _chunkXTFN5WKScjs.escapeLiteralDollar.call(void 0, it.text);
2988
+ for (const it of visible) if (it.text.includes("$")) it.text = _chunkR2BUANHQcjs.escapeLiteralDollar.call(void 0, it.text);
2808
2989
  wrapEquationRuns(visible, (face) => faceNames.get(face));
2809
2990
  const pageArea = pageW * pageH;
2810
2991
  if (pageArea > 0) {
2811
- const imageRegions = _chunkWDQTFAXYcjs.extractImageRegions.call(void 0, opList.fnArray, opList.argsArray);
2992
+ const imageRegions = _chunkXEPKOC2Ocjs.extractImageRegions.call(void 0, opList.fnArray, opList.argsArray);
2812
2993
  let uncovered = 0;
2813
2994
  for (const r of imageRegions) {
2814
2995
  const area = (r.x2 - r.x1) * (r.y2 - r.y1);
@@ -2834,14 +3015,14 @@ async function parsePdfDocument(buffer, options) {
2834
3015
  if (uncovered > 0) skippedImagePages.set(i, uncovered);
2835
3016
  }
2836
3017
  const marks = superscriptNoteMarks(visible);
2837
- if (marks.length) noteMarks.set(i, { marks, seps: footnoteSeparators(_chunkWDQTFAXYcjs.extractLines.call(void 0, opList.fnArray, opList.argsArray).horizontals, pageW, pageH) });
3018
+ if (marks.length) noteMarks.set(i, { marks, seps: footnoteSeparators(_chunkXEPKOC2Ocjs.extractLines.call(void 0, opList.fnArray, opList.argsArray).horizontals, pageW, pageH) });
2838
3019
  const stamp = marginStamp(visible);
2839
3020
  const flow = stamp.length ? visible.filter((it) => !stamp.includes(it)) : visible;
2840
- const pageBlocks = orderTwoUpPage(_chunkWDQTFAXYcjs.extractPageBlocksWithLines.call(void 0, flow, i, opList, pageW, pageH, void 0, _optionalChain([options, 'optionalAccess', _225 => _225.tables]) !== false, carry, wrapLexicon), pageW, pageH);
3021
+ const pageBlocks = orderTwoUpPage(_chunkXEPKOC2Ocjs.extractPageBlocksWithLines.call(void 0, flow, i, opList, pageW, pageH, void 0, _optionalChain([options, 'optionalAccess', _235 => _235.tables]) !== false, carry, wrapLexicon), pageW, pageH);
2841
3022
  if (stamp.length) pageBlocks.unshift({ type: "paragraph", text: [...stamp].sort((a, b) => a.y - b.y).map((it) => it.text).join(" "), pageNumber: i });
2842
3023
  for (const b of pageBlocks) blocks.push(b);
2843
3024
  try {
2844
- const { blocks: imgBlocks, images: pageImages } = await extractPageImages(page, opList.fnArray, opList.argsArray, i, imageState, warnings, _optionalChain([options, 'optionalAccess', _226 => _226.images]) !== false);
3025
+ const { blocks: imgBlocks, images: pageImages } = await extractPageImages(page, opList.fnArray, opList.argsArray, i, imageState, warnings, _optionalChain([options, 'optionalAccess', _236 => _236.images]) !== false);
2845
3026
  if (imgBlocks.length > 0) pageImageBlocks.set(i, imgBlocks);
2846
3027
  extractedImages.push(...pageImages);
2847
3028
  } catch (e6) {
@@ -2860,27 +3041,27 @@ async function parsePdfDocument(buffer, options) {
2860
3041
  const vector = scanVectorGlyphs(opList.fnArray, opList.argsArray, visible);
2861
3042
  const quality = computePageQuality(i, pageText, vector.glyphs);
2862
3043
  pageQuality.push(quality);
2863
- if (_optionalChain([options, 'optionalAccess', _227 => _227.ocr]) && quality.ocrReason === "vector_text" && page.rotate % 360 === 0 && page.view[0] === 0 && page.view[1] === 0) {
3044
+ if (_optionalChain([options, 'optionalAccess', _237 => _237.ocr]) && quality.ocrReason === "vector_text" && page.rotate % 360 === 0 && page.view[0] === 0 && page.view[1] === 0) {
2864
3045
  vectorPageOps.set(i, ocrVectorOps(opList, vector.paths));
2865
3046
  }
2866
- if (totalTextBytes > MAX_TOTAL_TEXT) throw new (0, _chunkSTM3ORY7cjs.KordocError)("\uD14D\uC2A4\uD2B8 \uCD94\uCD9C \uD06C\uAE30 \uCD08\uACFC");
3047
+ if (totalTextBytes > MAX_TOTAL_TEXT) throw new (0, _chunkQNJLLF4Jcjs.KordocError)("\uD14D\uC2A4\uD2B8 \uCD94\uCD9C \uD06C\uAE30 \uCD08\uACFC");
2867
3048
  parsedPages++;
2868
- _optionalChain([options, 'optionalAccess', _228 => _228.onProgress, 'optionalCall', _229 => _229(parsedPages, totalTarget)]);
3049
+ _optionalChain([options, 'optionalAccess', _238 => _238.onProgress, 'optionalCall', _239 => _239(parsedPages, totalTarget)]);
2869
3050
  } catch (pageErr) {
2870
- if (pageErr instanceof _chunkSTM3ORY7cjs.KordocError) throw pageErr;
3051
+ if (pageErr instanceof _chunkQNJLLF4Jcjs.KordocError) throw pageErr;
2871
3052
  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" });
2872
3053
  } finally {
2873
- _optionalChain([loadedPage, 'optionalAccess', _230 => _230.cleanup, 'call', _231 => _231()]);
3054
+ _optionalChain([loadedPage, 'optionalAccess', _240 => _240.cleanup, 'call', _241 => _241()]);
2874
3055
  }
2875
3056
  }
2876
3057
  const parsedPageCount = parsedPages || (pageFilter ? pageFilter.size : effectivePageCount);
2877
- const isImageBased = _optionalChain([pageFilter, 'optionalAccess', _232 => _232.size]) !== 0 && totalChars / Math.max(parsedPageCount, 1) < 10;
3058
+ const isImageBased = _optionalChain([pageFilter, 'optionalAccess', _242 => _242.size]) !== 0 && totalChars / Math.max(parsedPageCount, 1) < 10;
2878
3059
  const ocrDone = /* @__PURE__ */ new Set();
2879
- const ocrRegions = _optionalChain([options, 'optionalAccess', _233 => _233.ocr]) === true || autoOcr ? ocrImageRegions(uncoveredImageRegions, largeImageRegions, _optionalChain([options, 'optionalAccess', _234 => _234.ocr]) === true) : /* @__PURE__ */ new Map();
3060
+ const ocrRegions = _optionalChain([options, 'optionalAccess', _243 => _243.ocr]) === true || autoOcr ? ocrImageRegions(uncoveredImageRegions, largeImageRegions, _optionalChain([options, 'optionalAccess', _244 => _244.ocr]) === true) : /* @__PURE__ */ new Map();
2880
3061
  if (ocrBuffer) {
2881
3062
  const inScope = (p) => !pageFilter || pageFilter.has(p);
2882
3063
  const targets = /* @__PURE__ */ new Set();
2883
- if (_optionalChain([options, 'optionalAccess', _235 => _235.ocr]) === "force" || isImageBased) {
3064
+ if (_optionalChain([options, 'optionalAccess', _245 => _245.ocr]) === "force" || isImageBased) {
2884
3065
  for (let i = 1; i <= effectivePageCount; i++) if (inScope(i)) targets.add(i);
2885
3066
  } else {
2886
3067
  for (const pq of pageQuality) {
@@ -2893,16 +3074,16 @@ async function parsePdfDocument(buffer, options) {
2893
3074
  }
2894
3075
  if (targets.size > 0) {
2895
3076
  try {
2896
- const { runPdfOcr } = await Promise.resolve().then(() => _interopRequireWildcard(require("./pdf-ocr-GHEJVPX2.cjs")));
2897
- const mode = typeof _optionalChain([options, 'optionalAccess', _236 => _236.ocr]) === "function" ? options.ocr : "builtin";
2898
- const regionPages = new Map([...ocrRegions].filter(([p]) => _optionalChain([options, 'optionalAccess', _237 => _237.ocr]) !== "force" && !isImageBased && !_optionalChain([pageQuality, 'access', _238 => _238.find, 'call', _239 => _239((q) => q.page === p), 'optionalAccess', _240 => _240.needsOcr])));
2899
- const ocrPageBlocks = await runPdfOcr(ocrBuffer, targets, mode, warnings, _optionalChain([options, 'optionalAccess', _241 => _241.onProgress]), _optionalChain([options, 'optionalAccess', _242 => _242.tables]) !== false, vectorPageOps, regionPages);
2900
- for (const obs of ocrPageBlocks.values()) _chunk62W7QCEXcjs.stripScriptTags.call(void 0, { blocks: obs });
3077
+ const { runPdfOcr } = await Promise.resolve().then(() => _interopRequireWildcard(require("./pdf-ocr-STK5EQFF.cjs")));
3078
+ const mode = typeof _optionalChain([options, 'optionalAccess', _246 => _246.ocr]) === "function" ? options.ocr : "builtin";
3079
+ const regionPages = new Map([...ocrRegions].filter(([p]) => _optionalChain([options, 'optionalAccess', _247 => _247.ocr]) !== "force" && !isImageBased && !_optionalChain([pageQuality, 'access', _248 => _248.find, 'call', _249 => _249((q) => q.page === p), 'optionalAccess', _250 => _250.needsOcr])));
3080
+ const ocrPageBlocks = await runPdfOcr(ocrBuffer, targets, mode, warnings, _optionalChain([options, 'optionalAccess', _251 => _251.onProgress]), _optionalChain([options, 'optionalAccess', _252 => _252.tables]) !== false, vectorPageOps, regionPages);
3081
+ for (const obs of ocrPageBlocks.values()) _chunkAKB72TEHcjs.stripScriptTags.call(void 0, { blocks: obs });
2901
3082
  if (ocrPageBlocks.size > 0) {
2902
3083
  const replacePages = /* @__PURE__ */ new Set();
2903
3084
  for (const [p, obs] of ocrPageBlocks) {
2904
- const needsOcr = _optionalChain([pageQuality, 'access', _243 => _243.find, 'call', _244 => _244((q) => q.page === p), 'optionalAccess', _245 => _245.needsOcr]);
2905
- if (_optionalChain([options, 'optionalAccess', _246 => _246.ocr]) === "force" || isImageBased || needsOcr) {
3085
+ const needsOcr = _optionalChain([pageQuality, 'access', _253 => _253.find, 'call', _254 => _254((q) => q.page === p), 'optionalAccess', _255 => _255.needsOcr]);
3086
+ if (_optionalChain([options, 'optionalAccess', _256 => _256.ocr]) === "force" || isImageBased || needsOcr) {
2906
3087
  replacePages.add(p);
2907
3088
  ocrDone.add(p);
2908
3089
  continue;
@@ -2910,7 +3091,7 @@ async function parsePdfDocument(buffer, options) {
2910
3091
  const regions = ocrRegions.get(p);
2911
3092
  if (!regions || mergeOcrImageRegions(blocks, p, regions, obs) === 0) continue;
2912
3093
  ocrDone.add(p);
2913
- if (_optionalChain([pageImageBlocks, 'access', _247 => _247.get, 'call', _248 => _248(p), 'optionalAccess', _249 => _249.length]) === 1) pageImageBlocks.delete(p);
3094
+ if (_optionalChain([pageImageBlocks, 'access', _257 => _257.get, 'call', _258 => _258(p), 'optionalAccess', _259 => _259.length]) === 1) pageImageBlocks.delete(p);
2914
3095
  }
2915
3096
  if (replacePages.size) {
2916
3097
  const merged = blocks.filter((b) => !(b.pageNumber && replacePages.has(b.pageNumber)));
@@ -2960,8 +3141,8 @@ async function parsePdfDocument(buffer, options) {
2960
3141
  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 \u2014 \uADF8\uB9BC \uC18D \uAE00\uC740 ocr: true / CLI --ocr \uB85C \uC77D\uC2B5\uB2C8\uB2E4)`, code: "SKIPPED_IMAGE" });
2961
3142
  }
2962
3143
  }
2963
- if (_optionalChain([options, 'optionalAccess', _250 => _250.removeHeaderFooter]) !== false && parsedPageCount >= 3) {
2964
- const removed = _chunkWDQTFAXYcjs.removeHeaderFooterBlocks.call(void 0, blocks, pageHeights, warnings, noteMarks);
3144
+ if (_optionalChain([options, 'optionalAccess', _260 => _260.removeHeaderFooter]) !== false && parsedPageCount >= 3) {
3145
+ const removed = _chunkXEPKOC2Ocjs.removeHeaderFooterBlocks.call(void 0, blocks, pageHeights, warnings, noteMarks);
2965
3146
  for (let ri = removed.length - 1; ri >= 0; ri--) {
2966
3147
  blocks.splice(removed[ri], 1);
2967
3148
  }
@@ -2973,15 +3154,15 @@ async function parsePdfDocument(buffer, options) {
2973
3154
  }
2974
3155
  mergeContinuedCells(blocks, pageHeights);
2975
3156
  mergeCrossPageTables(blocks, pageHeights, wrapLexicon);
2976
- if (_optionalChain([options, 'optionalAccess', _251 => _251.removeHeaderFooter]) !== false && parsedPageCount >= 3) {
2977
- const boxes = _chunkWDQTFAXYcjs.removeHeaderFooterBlocks.call(void 0, blocks, pageHeights, warnings, noteMarks, true);
3157
+ if (_optionalChain([options, 'optionalAccess', _261 => _261.removeHeaderFooter]) !== false && parsedPageCount >= 3) {
3158
+ const boxes = _chunkXEPKOC2Ocjs.removeHeaderFooterBlocks.call(void 0, blocks, pageHeights, warnings, noteMarks, true);
2978
3159
  for (let ri = boxes.length - 1; ri >= 0; ri--) blocks.splice(boxes[ri], 1);
2979
3160
  }
2980
3161
  splitContactTables(blocks);
2981
- if (!_optionalChain([options, 'optionalAccess', _252 => _252.keepTrailingEmptyCols])) _chunkWDQTFAXYcjs.trimTrailingEmptyTableCols.call(void 0, blocks);
2982
- _chunkWDQTFAXYcjs.joinPageBreakWraps.call(void 0, blocks, wrapLexicon);
3162
+ if (!_optionalChain([options, 'optionalAccess', _262 => _262.keepTrailingEmptyCols])) _chunkXEPKOC2Ocjs.trimTrailingEmptyTableCols.call(void 0, blocks);
3163
+ _chunkXEPKOC2Ocjs.joinPageBreakWraps.call(void 0, blocks, wrapLexicon);
2983
3164
  injectPageImageBlocks(blocks, pageImageBlocks);
2984
- if (_optionalChain([options, 'optionalAccess', _253 => _253.formulaOcr]) && formulaBuffer) {
3165
+ if (_optionalChain([options, 'optionalAccess', _263 => _263.formulaOcr]) && formulaBuffer) {
2985
3166
  try {
2986
3167
  await applyFormulaOcr(formulaBuffer, blocks, pageFilter, effectivePageCount, warnings, options.onProgress);
2987
3168
  } catch (e) {
@@ -2991,38 +3172,60 @@ async function parsePdfDocument(buffer, options) {
2991
3172
  });
2992
3173
  }
2993
3174
  }
2994
- const medianFontSize = _chunkWDQTFAXYcjs.computeMedianFontSizeFromFreq.call(void 0, fontSizeFreq);
3175
+ const medianFontSize = _chunkXEPKOC2Ocjs.computeMedianFontSizeFromFreq.call(void 0, fontSizeFreq);
2995
3176
  if (medianFontSize > 0) {
2996
- _chunkWDQTFAXYcjs.detectHeadings.call(void 0, blocks, medianFontSize);
2997
- }
2998
- _chunkWDQTFAXYcjs.detectDocumentStyleHeadings.call(void 0, blocks);
2999
- _chunkWDQTFAXYcjs.detectTypographyHeadings.call(void 0, blocks);
3000
- _chunkWDQTFAXYcjs.detectSiblingStyleHeadings.call(void 0, blocks);
3001
- _chunkWDQTFAXYcjs.detectRepeatedPageLabels.call(void 0, blocks);
3002
- _chunkWDQTFAXYcjs.detectPageLeadHeadings.call(void 0, blocks);
3003
- _chunkWDQTFAXYcjs.mergeStackedHeadingLines.call(void 0, blocks, medianFontSize);
3004
- _chunkWDQTFAXYcjs.refineDocumentStyleHeadings.call(void 0, blocks);
3005
- _chunkWDQTFAXYcjs.detectMarkerHeadings.call(void 0, blocks);
3177
+ _chunkXEPKOC2Ocjs.detectHeadings.call(void 0, blocks, medianFontSize);
3178
+ }
3179
+ _chunkXEPKOC2Ocjs.detectDocumentStyleHeadings.call(void 0, blocks);
3180
+ _chunkXEPKOC2Ocjs.detectTypographyHeadings.call(void 0, blocks);
3181
+ _chunkXEPKOC2Ocjs.detectSiblingStyleHeadings.call(void 0, blocks);
3182
+ _chunkXEPKOC2Ocjs.detectRepeatedPageLabels.call(void 0, blocks);
3183
+ _chunkXEPKOC2Ocjs.detectPageLeadHeadings.call(void 0, blocks);
3184
+ _chunkXEPKOC2Ocjs.mergeStackedHeadingLines.call(void 0, blocks, medianFontSize);
3185
+ _chunkXEPKOC2Ocjs.refineDocumentStyleHeadings.call(void 0, blocks);
3186
+ _chunkXEPKOC2Ocjs.detectMarkerHeadings.call(void 0, blocks);
3006
3187
  demoteNonHeadingRoles(blocks, pageHeights, faceNames);
3007
- _chunkWDQTFAXYcjs.detectTableCaptions.call(void 0, blocks);
3008
- _chunkWDQTFAXYcjs.detectKoreanListBlocks.call(void 0, blocks);
3188
+ _chunkXEPKOC2Ocjs.detectTableCaptions.call(void 0, blocks);
3189
+ _chunkXEPKOC2Ocjs.detectKoreanListBlocks.call(void 0, blocks);
3009
3190
  const outline = blocks.filter((b) => b.type === "heading" && b.level && b.text).map((b) => ({ level: b.level, text: b.text, pageNumber: b.pageNumber }));
3010
3191
  sanitizeBlockControlChars(blocks);
3011
3192
  let outBlocks = splitSingleCellTables(blocks);
3012
3193
  outBlocks = inlineFootnotes(outBlocks, noteMarks);
3013
3194
  outBlocks = relocateEndnotes(outBlocks);
3014
- if (_optionalChain([options, 'optionalAccess', _254 => _254.removeHeaderFooter]) !== false) outBlocks = outBlocks.filter((b) => {
3195
+ if (_optionalChain([options, 'optionalAccess', _264 => _264.removeHeaderFooter]) !== false) outBlocks = outBlocks.filter((b) => {
3015
3196
  if (b.type !== "paragraph" || !/^\s*\d{1,4}\s*$/.test(_nullishCoalesce(b.text, () => ( "")))) return true;
3016
3197
  const h = pageHeights.get(_nullishCoalesce(b.pageNumber, () => ( 0)));
3017
3198
  if (!b.bbox || !h) return false;
3018
3199
  return b.bbox.y > h * 0.1 && b.bbox.y + b.bbox.height < h * 0.9;
3019
3200
  });
3020
3201
  joinLatinCellWraps(outBlocks);
3021
- const finishMarkdown = (bs) => mergeLinkRuns(cleanPdfText(_chunkXTFN5WKScjs.blocksToMarkdown.call(void 0, bs), { keepLoneNumbers: true }));
3202
+ if (_optionalChain([options, 'optionalAccess', _265 => _265.layoutTables]) !== "keep" && await isHancomPdf(doc)) {
3203
+ const shown = /* @__PURE__ */ new Map();
3204
+ const markContent = (bs) => {
3205
+ for (const b of _nullishCoalesce(bs, () => ( []))) if (b.table) for (const row of b.table.cells) for (const c of row) {
3206
+ if (_chunkXEPKOC2Ocjs.IMAGE_CELLS.has(c)) _chunkAKB72TEHcjs.CONTENT_CELLS.add(c);
3207
+ markContent(c.blocks);
3208
+ }
3209
+ };
3210
+ const visual = (bs) => bs.flatMap((b) => {
3211
+ if (b.type !== "table") return [b];
3212
+ let v = shown.get(b);
3213
+ if (!v) {
3214
+ markContent([b]);
3215
+ shown.set(b, v = _chunkAKB72TEHcjs.unframeLayoutTables.call(void 0, [b], !!_optionalChain([options, 'optionalAccess', _266 => _266.keepTrailingEmptyCols])));
3216
+ }
3217
+ return v;
3218
+ });
3219
+ outBlocks = visual(outBlocks);
3220
+ const kept = visual(blocks);
3221
+ blocks.length = 0;
3222
+ for (const b of kept) blocks.push(b);
3223
+ }
3224
+ const finishMarkdown = (bs) => mergeLinkRuns(cleanPdfText(_chunkR2BUANHQcjs.blocksToMarkdown.call(void 0, bs), { keepLoneNumbers: true }));
3022
3225
  let markdown = finishMarkdown(outBlocks);
3023
3226
  return {
3024
3227
  markdown,
3025
- pages: _chunkXTFN5WKScjs.blocksToPages.call(void 0, outBlocks, finishMarkdown),
3228
+ pages: _chunkR2BUANHQcjs.blocksToPages.call(void 0, outBlocks, finishMarkdown),
3026
3229
  blocks,
3027
3230
  metadata,
3028
3231
  outline: outline.length > 0 ? outline : void 0,
@@ -3040,7 +3243,7 @@ async function parsePdfDocument(buffer, options) {
3040
3243
  async function extractPdfMetadata(doc, metadata) {
3041
3244
  try {
3042
3245
  const result = await doc.getMetadata();
3043
- if (!_optionalChain([result, 'optionalAccess', _255 => _255.info])) return;
3246
+ if (!_optionalChain([result, 'optionalAccess', _267 => _267.info])) return;
3044
3247
  const info = result.info;
3045
3248
  if (typeof info.Title === "string" && info.Title.trim()) metadata.title = info.Title.trim();
3046
3249
  if (typeof info.Author === "string" && info.Author.trim()) metadata.author = info.Author.trim();
@@ -3054,6 +3257,14 @@ async function extractPdfMetadata(doc, metadata) {
3054
3257
  } catch (e7) {
3055
3258
  }
3056
3259
  }
3260
+ async function isHancomPdf(doc) {
3261
+ try {
3262
+ const info = await _asyncOptionalChain([(await doc.getMetadata()), 'optionalAccess', async _268 => _268.info]);
3263
+ return [_optionalChain([info, 'optionalAccess', _269 => _269.Producer]), _optionalChain([info, 'optionalAccess', _270 => _270.Creator])].some((v) => typeof v === "string" && /^\s*(?:hancom\b|hwp\b)/i.test(v));
3264
+ } catch (e8) {
3265
+ return false;
3266
+ }
3267
+ }
3057
3268
  function parsePdfDate(dateStr) {
3058
3269
  const m = dateStr.match(/D:(\d{4})(\d{2})?(\d{2})?(\d{2})?(\d{2})?(\d{2})?/);
3059
3270
  if (!m) return void 0;
@@ -3092,5 +3303,5 @@ function marginStamp(items) {
3092
3303
 
3093
3304
 
3094
3305
 
3095
- exports.cleanPdfText = cleanPdfText; exports.detectKoreanListBlocks = _chunkWDQTFAXYcjs.detectKoreanListBlocks; exports.detectTableCaptions = _chunkWDQTFAXYcjs.detectTableCaptions; exports.extractPdfMetadataOnly = extractPdfMetadataOnly; exports.mergeCrossPageTables = mergeCrossPageTables; exports.ocrImageRegions = ocrImageRegions; exports.parsePdfDocument = parsePdfDocument; exports.removeHeaderFooterBlocks = _chunkWDQTFAXYcjs.removeHeaderFooterBlocks;
3096
- //# sourceMappingURL=parser-2LU4EVU3.cjs.map
3306
+ exports.cleanPdfText = cleanPdfText; exports.detectKoreanListBlocks = _chunkXEPKOC2Ocjs.detectKoreanListBlocks; exports.detectTableCaptions = _chunkXEPKOC2Ocjs.detectTableCaptions; exports.extractPdfMetadataOnly = extractPdfMetadataOnly; exports.mergeCrossPageTables = mergeCrossPageTables; exports.ocrImageRegions = ocrImageRegions; exports.parsePdfDocument = parsePdfDocument; exports.removeHeaderFooterBlocks = _chunkXEPKOC2Ocjs.removeHeaderFooterBlocks;
3307
+ //# sourceMappingURL=parser-RQ4PJRTJ.cjs.map