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
@@ -3,15 +3,16 @@
3
3
 
4
4
 
5
5
 
6
- var _chunk62W7QCEXcjs = require('./chunk-62W7QCEX.cjs');
7
6
 
7
+ var _chunkAKB72TEHcjs = require('./chunk-AKB72TEH.cjs');
8
8
 
9
9
 
10
- var _chunkCEIATRDWcjs = require('./chunk-CEIATRDW.cjs');
11
10
 
11
+ var _chunkWYON5ANUcjs = require('./chunk-WYON5ANU.cjs');
12
12
 
13
13
 
14
- var _chunkSTM3ORY7cjs = require('./chunk-STM3ORY7.cjs');
14
+
15
+ var _chunkQNJLLF4Jcjs = require('./chunk-QNJLLF4J.cjs');
15
16
 
16
17
  // src/ocr/models.ts
17
18
  var _path = require('path');
@@ -39,10 +40,10 @@ var OCR_REC_DICT = {
39
40
  };
40
41
  var ALL_OCR_MODELS = [OCR_DET_MODEL, OCR_REC_MODEL, OCR_REC_DICT];
41
42
  function getOcrModelsDir() {
42
- return _chunkCEIATRDWcjs.getModelsDir.call(void 0, "ppocr");
43
+ return _chunkWYON5ANUcjs.getModelsDir.call(void 0, "ppocr");
43
44
  }
44
45
  async function ensureOcrModels(onProgress) {
45
- return _chunkCEIATRDWcjs.ensureModelsIn.call(void 0, getOcrModelsDir(), ALL_OCR_MODELS, onProgress);
46
+ return _chunkWYON5ANUcjs.ensureModelsIn.call(void 0, getOcrModelsDir(), ALL_OCR_MODELS, onProgress);
46
47
  }
47
48
  async function ocrModelsCached() {
48
49
  const dir = getOcrModelsDir();
@@ -103,6 +104,9 @@ function extractLines(fnArray, argsArray) {
103
104
  const colorStack = [];
104
105
  let fillAlpha = 1, strokeAlpha = 1;
105
106
  const alphaStack = [];
107
+ let strokeColor = 0;
108
+ const strokeColorStack = [];
109
+ const nonRules = /* @__PURE__ */ new Set();
106
110
  const hiddenBoxes = [];
107
111
  const paintedFills = /* @__PURE__ */ new Map();
108
112
  const thinFill = /* @__PURE__ */ new Set();
@@ -170,6 +174,7 @@ function extractLines(fnArray, argsArray) {
170
174
  for (const r of pathRects) painted.push(r);
171
175
  paintedFills.set(fillColor, painted);
172
176
  }
177
+ const areaFill = fromFill && (pathRects.length > 0 || thickPath(currentPath));
173
178
  pathRects = [];
174
179
  pathRectSegs = [];
175
180
  if (!isStroke) {
@@ -180,6 +185,9 @@ function extractLines(fnArray, argsArray) {
180
185
  }
181
186
  pendingClip = false;
182
187
  const effWidth = lineWidth * ctmScale();
188
+ const outs = [horizontals, verticals, shortH, shortV, thinShortH, thinShortV];
189
+ const white = (fromFill ? fillColor : strokeColor) === 16777215;
190
+ const from = white || areaFill ? outs.map((o) => o.length) : void 0;
183
191
  currentPath.forEach((seg, k) => {
184
192
  const role = segRole[k];
185
193
  if (role === "hidden") return;
@@ -191,6 +199,9 @@ function extractLines(fnArray, argsArray) {
191
199
  }
192
200
  classifyAndAdd(seg, effWidth, horizontals, verticals, fromFill, fromFill ? void 0 : { h: shortH, v: shortV });
193
201
  });
202
+ if (from) outs.forEach((o, k) => {
203
+ for (let n = from[k]; n < o.length; n++) if (white || k < 2 && !thinFill.has(o[n])) nonRules.add(o[n]);
204
+ });
194
205
  currentPath = [];
195
206
  }
196
207
  for (let i = 0; i < fnArray.length; i++) {
@@ -203,11 +214,13 @@ function extractLines(fnArray, argsArray) {
203
214
  case _pdfmjs.OPS.save:
204
215
  ctmStack.push(ctm.slice());
205
216
  colorStack.push(fillColor);
217
+ strokeColorStack.push(strokeColor);
206
218
  alphaStack.push([fillAlpha, strokeAlpha]);
207
219
  break;
208
220
  case _pdfmjs.OPS.restore:
209
221
  ctm = _nullishCoalesce(ctmStack.pop(), () => ( [1, 0, 0, 1, 0, 0]));
210
222
  fillColor = _nullishCoalesce(colorStack.pop(), () => ( 0));
223
+ strokeColor = _nullishCoalesce(strokeColorStack.pop(), () => ( 0));
211
224
  [fillAlpha, strokeAlpha] = _nullishCoalesce(alphaStack.pop(), () => ( [1, 1]));
212
225
  break;
213
226
  case _pdfmjs.OPS.setGState: {
@@ -225,12 +238,18 @@ function extractLines(fnArray, argsArray) {
225
238
  fillColor = c[0] << 16 | c[1] << 8 | c[2];
226
239
  break;
227
240
  }
241
+ case _pdfmjs.OPS.setStrokeRGBColor: {
242
+ const c = args;
243
+ strokeColor = c[0] << 16 | c[1] << 8 | c[2];
244
+ break;
245
+ }
228
246
  case _pdfmjs.OPS.transform:
229
247
  case _pdfmjs.OPS.paintFormXObjectBegin: {
230
248
  let t = args;
231
249
  if (op === _pdfmjs.OPS.paintFormXObjectBegin) {
232
250
  ctmStack.push(ctm.slice());
233
251
  colorStack.push(fillColor);
252
+ strokeColorStack.push(strokeColor);
234
253
  alphaStack.push([fillAlpha, strokeAlpha]);
235
254
  const m = args[0];
236
255
  if (!Array.isArray(m) || m.length < 6) break;
@@ -249,6 +268,7 @@ function extractLines(fnArray, argsArray) {
249
268
  case _pdfmjs.OPS.paintFormXObjectEnd:
250
269
  ctm = _nullishCoalesce(ctmStack.pop(), () => ( [1, 0, 0, 1, 0, 0]));
251
270
  fillColor = _nullishCoalesce(colorStack.pop(), () => ( 0));
271
+ strokeColor = _nullishCoalesce(strokeColorStack.pop(), () => ( 0));
252
272
  [fillAlpha, strokeAlpha] = _nullishCoalesce(alphaStack.pop(), () => ( [1, 1]));
253
273
  break;
254
274
  case _pdfmjs.OPS.constructPath: {
@@ -360,7 +380,8 @@ function extractLines(fnArray, argsArray) {
360
380
  fillRects,
361
381
  hiddenBoxes,
362
382
  shortH,
363
- shortV
383
+ shortV,
384
+ nonRules
364
385
  };
365
386
  }
366
387
  var SHORT_CHAIN_POS_TOL = 0.5;
@@ -415,6 +436,17 @@ function chainShortSegments(longs, shorts, dir, chainable = (l) => !l.fromFill)
415
436
  }
416
437
  var CLIP_MIN_W = 4;
417
438
  var CLIP_MIN_H = 2;
439
+ function thickPath(path) {
440
+ if (!path.length) return false;
441
+ let x1 = Infinity, y1 = Infinity, x2 = -Infinity, y2 = -Infinity;
442
+ for (const s of path) {
443
+ x1 = Math.min(x1, s.x1, s.x2);
444
+ x2 = Math.max(x2, s.x1, s.x2);
445
+ y1 = Math.min(y1, s.y1, s.y2);
446
+ y2 = Math.max(y2, s.y1, s.y2);
447
+ }
448
+ return Math.min(x2 - x1, y2 - y1) > THIN_FILL_MAX;
449
+ }
418
450
  function captureClipRect(path, out, minW = CLIP_MIN_W, minH = CLIP_MIN_H) {
419
451
  if (path.length < 3 || path.length > 5) return;
420
452
  let x1 = Infinity, y1 = Infinity, x2 = -Infinity, y2 = -Infinity;
@@ -538,7 +570,7 @@ var CHAIN_GAP = 3;
538
570
  function chainCollinearRules(horizontals) {
539
571
  if (horizontals.length <= 1) return horizontals;
540
572
  const sorted = [...horizontals].sort((a, b) => a.y1 - b.y1 || a.x1 - b.x1);
541
- const rules = [];
573
+ const rules2 = [];
542
574
  let bandStart = 0;
543
575
  const flushBand = (end) => {
544
576
  const band = sorted.slice(bandStart, end).sort((a, b) => a.x1 - b.x1);
@@ -549,11 +581,11 @@ function chainCollinearRules(horizontals) {
549
581
  if (seg.x2 > cur.x2) cur.x2 = seg.x2;
550
582
  if (seg.lineWidth > cur.lineWidth) cur.lineWidth = seg.lineWidth;
551
583
  } else {
552
- rules.push(cur);
584
+ rules2.push(cur);
553
585
  cur = { ...seg };
554
586
  }
555
587
  }
556
- rules.push(cur);
588
+ rules2.push(cur);
557
589
  };
558
590
  for (let i = 1; i <= sorted.length; i++) {
559
591
  if (i === sorted.length || sorted[i].y1 - sorted[bandStart].y1 > CHAIN_Y_TOL) {
@@ -561,7 +593,7 @@ function chainCollinearRules(horizontals) {
561
593
  bandStart = i;
562
594
  }
563
595
  }
564
- return rules;
596
+ return rules2;
565
597
  }
566
598
  function closeOpenTableEdges(horizontals, verticals) {
567
599
  if (horizontals.length < EDGE_MIN_RULES) return verticals;
@@ -827,7 +859,7 @@ function bridgeSkippedRowVerticals(horizontals, verticals, items) {
827
859
  if (hi - lo > BRIDGE_MIN_GAP && hi - lo <= 40) gaps.push({ x, lo, hi, spanLo: s[i - 1].y1, spanHi: s[i].y2 });
828
860
  }
829
861
  }
830
- const rules = chainCollinearRules(horizontals);
862
+ const rules2 = chainCollinearRules(horizontals);
831
863
  const added = [];
832
864
  const done = /* @__PURE__ */ new Set();
833
865
  for (const g of gaps) {
@@ -837,7 +869,7 @@ function bridgeSkippedRowVerticals(horizontals, verticals, items) {
837
869
  if (band.length < BRIDGE_MIN_COLUMNS) continue;
838
870
  const xs = band.map((o) => o.x);
839
871
  const x1 = Math.min(...xs), x2 = Math.max(...xs);
840
- const ruled = (y) => rules.some((h) => Math.abs(h.y1 - y) <= BRIDGE_ENDPOINT_TOL && h.x1 <= x1 + BRIDGE_ENDPOINT_TOL && h.x2 >= x2 - BRIDGE_ENDPOINT_TOL);
872
+ const ruled = (y) => rules2.some((h) => Math.abs(h.y1 - y) <= BRIDGE_ENDPOINT_TOL && h.x1 <= x1 + BRIDGE_ENDPOINT_TOL && h.x2 >= x2 - BRIDGE_ENDPOINT_TOL);
841
873
  if (!ruled(g.lo) || !ruled(g.hi)) continue;
842
874
  const rowItems = items.filter((it) => {
843
875
  const cy = it.y + (it.h || it.fontSize) / 2;
@@ -1166,7 +1198,7 @@ function clusterCoordinates(values, tolerance) {
1166
1198
  function chainVerticals(vs) {
1167
1199
  if (vs.length <= 1) return vs.map((v) => ({ y1: v.y1, y2: v.y2 }));
1168
1200
  const sorted = [...vs].sort((a, b) => a.x1 - b.x1 || a.y1 - b.y1);
1169
- const rules = [];
1201
+ const rules2 = [];
1170
1202
  let bandStart = 0;
1171
1203
  const flushBand = (end) => {
1172
1204
  const band = sorted.slice(bandStart, end).sort((a, b) => a.y1 - b.y1);
@@ -1176,11 +1208,11 @@ function chainVerticals(vs) {
1176
1208
  if (seg.y1 - cur.y2 <= CUT_VCHAIN_GAP) {
1177
1209
  if (seg.y2 > cur.y2) cur.y2 = seg.y2;
1178
1210
  } else {
1179
- rules.push(cur);
1211
+ rules2.push(cur);
1180
1212
  cur = { y1: seg.y1, y2: seg.y2 };
1181
1213
  }
1182
1214
  }
1183
- rules.push(cur);
1215
+ rules2.push(cur);
1184
1216
  };
1185
1217
  for (let i = 1; i <= sorted.length; i++) {
1186
1218
  if (i === sorted.length || sorted[i].x1 - sorted[bandStart].x1 > CUT_VCHAIN_X_TOL) {
@@ -1188,7 +1220,7 @@ function chainVerticals(vs) {
1188
1220
  bandStart = i;
1189
1221
  }
1190
1222
  }
1191
- return rules;
1223
+ return rules2;
1192
1224
  }
1193
1225
  function splitStackedGroup(group) {
1194
1226
  const hs = group.filter((l) => l.type === "h");
@@ -1538,11 +1570,42 @@ function buildClipCellGrids(rects, strokedH, strokedV, pageWidth, pageHeight, te
1538
1570
  }
1539
1571
  }
1540
1572
  }
1573
+ const stacked = /* @__PURE__ */ new Set();
1574
+ if (ruledGaps.some((g) => g.axis === "y" && g.both && g.hi - g.lo > STACKED_TABLE_GAP)) {
1575
+ for (let i = 0; i < cells.length; i++) {
1576
+ if (tableClip[i]) continue;
1577
+ const k = edgeBin(cells[i].y2);
1578
+ for (let d = -1; d <= 1; d++) {
1579
+ if ((_nullishCoalesce(startsY.get(k + d), () => ( []))).some((j) => j !== i && !tableClip[j] && parent[j] === parent[i] && adjacent(cells[i], cells[j]))) stacked.add(find(i));
1580
+ }
1581
+ }
1582
+ }
1583
+ const comp = cells.map((_, i) => find(i));
1541
1584
  for (const g of ruledGaps) {
1542
1585
  if (tableClip[g.i] || tableClip[g.j]) continue;
1586
+ if (g.axis === "y" && g.both && g.hi - g.lo > STACKED_TABLE_GAP && comp[g.i] !== comp[g.j] && stacked.has(comp[g.i]) && stacked.has(comp[g.j])) continue;
1543
1587
  const ra = find(g.i), rb = find(g.j);
1544
1588
  if (ra !== rb) root[ra] = rb;
1545
1589
  }
1590
+ if (prev.lastCells.length) {
1591
+ const headTop = pageHeight * (1 - HEADER_BAND);
1592
+ let top = -Infinity;
1593
+ for (let i = 0; i < cells.length; i++) if (parent[i] < 0 && !tableClip[i]) top = Math.max(top, cells[i].y2);
1594
+ const band = cells.flatMap((c, i) => parent[i] < 0 && !tableClip[i] && Math.abs(c.y2 - top) <= CLIP_COORD_TOL ? [i] : []);
1595
+ const y1 = band.length ? cells[band[0]].y1 : 0;
1596
+ if (band.length >= 2 && band.every((i) => Math.abs(cells[i].y1 - y1) <= CLIP_COORD_TOL) && !textPoints.some((p) => p.y > top + CLIP_EDGE_TOL && p.y < headTop)) {
1597
+ for (let f = 0; f < cells.length; f++) {
1598
+ const b = cells[f];
1599
+ if (parent[f] >= 0 || tableClip[f] || Math.abs(b.y2 - y1) > CLIP_ADJ_GAP) continue;
1600
+ const on = band.filter((i) => cells[i].x1 >= b.x1 - CLIP_COORD_TOL && cells[i].x2 <= b.x2 + CLIP_COORD_TOL);
1601
+ if (on.length < 2 || !on.some((i) => adjacent(cells[i], b))) continue;
1602
+ for (const i of on) {
1603
+ const ra = find(i), rb = find(f);
1604
+ if (ra !== rb) root[ra] = rb;
1605
+ }
1606
+ }
1607
+ }
1608
+ }
1546
1609
  const groups = /* @__PURE__ */ new Map();
1547
1610
  for (let i = 0; i < cells.length; i++) {
1548
1611
  const r = find(i);
@@ -1602,6 +1665,8 @@ function buildClipCellGrids(rects, strokedH, strokedV, pageWidth, pageHeight, te
1602
1665
  if (invisible / edges < CLIP_MIN_INVISIBLE) continue;
1603
1666
  const colXs = dropSliverGaps(clusterCoords(members.flatMap((r) => [r.x1, r.x2])));
1604
1667
  const rowYs = clusterCoords(members.flatMap((r) => [r.y1, r.y2])).reverse();
1668
+ const band = parentRect ? void 0 : carriedBandTop(colXs, rowYs[0], strokedH, strokedV, textPoints, cells, prev.lastCells, headY);
1669
+ if (band !== void 0) rowYs.unshift(band);
1605
1670
  const numRows = rowYs.length - 1, numCols = colXs.length - 1;
1606
1671
  if (numRows < 1 || numCols < 1) continue;
1607
1672
  const occupied = Array.from({ length: numRows }, () => new Array(numCols).fill(false));
@@ -1648,6 +1713,7 @@ function buildClipCellGrids(rects, strokedH, strokedV, pageWidth, pageHeight, te
1648
1713
  return { grids, containers, page: { lastCells, clips: cells } };
1649
1714
  }
1650
1715
  var CLIP_SPACING_MAX = 3;
1716
+ var STACKED_TABLE_GAP = 2.6;
1651
1717
  function findRuledGaps(cells, parent, strokedH, strokedV) {
1652
1718
  const al = (u, v) => Math.abs(u - v) <= CLIP_COORD_TOL;
1653
1719
  const occupied = (i, j, x1, y1, x2, y2) => cells.some((k, n) => n !== i && n !== j && parent[n] === parent[i] && overlap(k.x1, k.x2, x1, x2) > CLIP_ADJ_GAP && overlap(k.y1, k.y2, y1, y2) > CLIP_ADJ_GAP);
@@ -1777,6 +1843,20 @@ function closeGaps(members, gaps) {
1777
1843
  }
1778
1844
  return out;
1779
1845
  }
1846
+ function carriedBandTop(colXs, top, strokedH, strokedV, textPoints, cells, prevLast, headY) {
1847
+ const x1 = colXs[0], x2 = colXs[colXs.length - 1];
1848
+ if (!prevLast.some((b) => overlap(b.x1, b.x2, x1, x2) > CLIP_EDGE_TOL)) return void 0;
1849
+ let y;
1850
+ for (const l of strokedH) {
1851
+ if (l.y1 > top + CLIP_MIN_H2 && l.x1 <= x1 + STROKE_NEAR && l.x2 >= x2 - STROKE_NEAR && (y === void 0 || l.y1 < y)) y = l.y1;
1852
+ }
1853
+ if (y === void 0 || !edgeStroked(strokedV, "v", x1, top, y) || !edgeStroked(strokedV, "v", x2, top, y)) return void 0;
1854
+ const above = Math.max(y, headY);
1855
+ const inX = (x) => x > x1 && x < x2;
1856
+ if (textPoints.some((p) => inX(p.x) && p.y > top && p.y < above)) return void 0;
1857
+ if (cells.some((c) => overlap(c.x1, c.x2, x1, x2) > CLIP_EDGE_TOL && c.y1 >= top - CLIP_EDGE_TOL && c.y1 < above)) return void 0;
1858
+ return y;
1859
+ }
1780
1860
  function addNarrowEdgeCols(colXs, rowYs, out, fills) {
1781
1861
  if (!fills.length) return;
1782
1862
  const rowIdx = (y) => {
@@ -1979,7 +2059,7 @@ function tagScripts(text, lines) {
1979
2059
  const [s, e, kind] = marks[m];
1980
2060
  out = out.slice(0, s) + `<${kind}>` + out.slice(s, e) + `</${kind}>` + out.slice(e);
1981
2061
  }
1982
- return _chunk62W7QCEXcjs.tidyScriptTags.call(void 0, out);
2062
+ return _chunkAKB72TEHcjs.tidyScriptTags.call(void 0, out);
1983
2063
  }
1984
2064
 
1985
2065
  // src/pdf/line-wrap.ts
@@ -3131,9 +3211,9 @@ function detectHeadings(blocks, medianFontSize) {
3131
3211
  if (/^\d+$/.test(text) && !isChapterNumber(block, blocks[bi + 1], medianFontSize)) continue;
3132
3212
  const ratio = block.style.fontSize / medianFontSize;
3133
3213
  let level = 0;
3134
- if (ratio >= _chunk62W7QCEXcjs.HEADING_RATIO_H1) level = 1;
3135
- else if (ratio >= _chunk62W7QCEXcjs.HEADING_RATIO_H2) level = 2;
3136
- else if (ratio >= _chunk62W7QCEXcjs.HEADING_RATIO_H3) level = 3;
3214
+ if (ratio >= _chunkAKB72TEHcjs.HEADING_RATIO_H1) level = 1;
3215
+ else if (ratio >= _chunkAKB72TEHcjs.HEADING_RATIO_H2) level = 2;
3216
+ else if (ratio >= _chunkAKB72TEHcjs.HEADING_RATIO_H3) level = 3;
3137
3217
  if (level > 0) {
3138
3218
  block.type = "heading";
3139
3219
  block.level = level;
@@ -3146,7 +3226,7 @@ function isChapterNumber(block, next, medianFontSize) {
3146
3226
  const nextSize = _nullishCoalesce(_optionalChain([next, 'optionalAccess', _76 => _76.style, 'optionalAccess', _77 => _77.fontSize]), () => ( 0));
3147
3227
  const text = _nullishCoalesce(_optionalChain([next, 'optionalAccess', _78 => _78.text, 'optionalAccess', _79 => _79.trim, 'call', _80 => _80()]), () => ( ""));
3148
3228
  const a = block.bbox, b = _optionalChain([next, 'optionalAccess', _81 => _81.bbox]);
3149
- return /^\d{1,2}$/.test(_nullishCoalesce(_optionalChain([block, 'access', _82 => _82.text, 'optionalAccess', _83 => _83.trim, 'call', _84 => _84()]), () => ( ""))) && size >= medianFontSize * 2.5 && !!next && (next.type === "paragraph" || next.type === "heading") && next.pageNumber === block.pageNumber && nextSize >= medianFontSize * _chunk62W7QCEXcjs.HEADING_RATIO_H1 && text.length > 0 && text.length <= 80 && !/^[\d\s.]+$/.test(text) && !!a && !!b && a.y > b.y && a.y - (b.y + b.height) <= size * 2;
3229
+ return /^\d{1,2}$/.test(_nullishCoalesce(_optionalChain([block, 'access', _82 => _82.text, 'optionalAccess', _83 => _83.trim, 'call', _84 => _84()]), () => ( ""))) && size >= medianFontSize * 2.5 && !!next && (next.type === "paragraph" || next.type === "heading") && next.pageNumber === block.pageNumber && nextSize >= medianFontSize * _chunkAKB72TEHcjs.HEADING_RATIO_H1 && text.length > 0 && text.length <= 80 && !/^[\d\s.]+$/.test(text) && !!a && !!b && a.y > b.y && a.y - (b.y + b.height) <= size * 2;
3150
3230
  }
3151
3231
  function mergeStackedHeadingLines(blocks, medianFontSize) {
3152
3232
  for (let i = 0; i < blocks.length - 1; ) {
@@ -3761,6 +3841,9 @@ function removeHeaderFooterBlocks(blocks, pageHeights, warnings, notes, tables =
3761
3841
  // src/pdf/table-meta.ts
3762
3842
  var CLIP_TABLES = /* @__PURE__ */ new WeakSet();
3763
3843
  var TABLE_COLXS = /* @__PURE__ */ new WeakMap();
3844
+ var TABLE_ROWYS = /* @__PURE__ */ new WeakMap();
3845
+ var TABLE_TAIL = /* @__PURE__ */ new WeakMap();
3846
+ var PART_COLXS = /* @__PURE__ */ new WeakMap();
3764
3847
  var EMPTY_PARTS = /* @__PURE__ */ new WeakSet();
3765
3848
  var IMAGE_CELLS = /* @__PURE__ */ new WeakSet();
3766
3849
  var FILLER_CELLS = /* @__PURE__ */ new WeakSet();
@@ -3779,6 +3862,34 @@ function recordCellLines(cell, items) {
3779
3862
  }
3780
3863
  CELL_LINES.set(cell, lines);
3781
3864
  }
3865
+ var ROW_RULES = /* @__PURE__ */ new WeakMap();
3866
+ function ruleCover(hs, y, x1, x2) {
3867
+ const segs = hs.filter((l) => Math.abs(l.y1 - y) <= 1.5 && l.x2 > x1 && l.x1 < x2).map((l) => [Math.max(l.x1, x1), Math.min(l.x2, x2)]).sort((a, b) => a[0] - b[0]);
3868
+ let len = 0, end = x1;
3869
+ for (const [a, b] of segs) if (b > end) {
3870
+ len += b - Math.max(a, end);
3871
+ end = b;
3872
+ }
3873
+ return x2 > x1 ? len / (x2 - x1) : 0;
3874
+ }
3875
+ function recordRowRules(table, cells, bbox, hs) {
3876
+ const real = cells.filter((c) => !c.filler);
3877
+ const edge = (y, pick) => {
3878
+ let w = 0, covered = 0;
3879
+ for (const c of real) if (Math.abs(pick(c) - y) <= 1) {
3880
+ w += c.bbox.x2 - c.bbox.x1;
3881
+ covered += ruleCover(hs, y, c.bbox.x1, c.bbox.x2) * (c.bbox.x2 - c.bbox.x1);
3882
+ }
3883
+ return w > 0 && covered >= 0.9 * w;
3884
+ };
3885
+ let innerRuled = 0, innerOpen = 0;
3886
+ for (const c of real) {
3887
+ if (Math.abs(c.bbox.y1 - bbox.y1) <= 1) continue;
3888
+ if (ruleCover(hs, c.bbox.y1, c.bbox.x1 + 0.5, c.bbox.x2 - 0.5) >= 0.9) innerRuled++;
3889
+ else innerOpen++;
3890
+ }
3891
+ ROW_RULES.set(table, { top: edge(bbox.y2, (c) => c.bbox.y2), bottom: edge(bbox.y1, (c) => c.bbox.y1), innerRuled, innerOpen });
3892
+ }
3782
3893
 
3783
3894
  // src/pdf/table-trim.ts
3784
3895
  function markImageCell(cell) {
@@ -5227,16 +5338,16 @@ function isProseSpread(items) {
5227
5338
  for (let i = 1; i < sorted.length; i++) {
5228
5339
  gaps.push(sorted[i].x - (sorted[i - 1].x + sorted[i - 1].w));
5229
5340
  }
5230
- const maxGap = _chunkSTM3ORY7cjs.safeMax.call(void 0, gaps);
5341
+ const maxGap = _chunkQNJLLF4Jcjs.safeMax.call(void 0, gaps);
5231
5342
  const avgLen = items.reduce((s, i) => s + i.text.length, 0) / items.length;
5232
5343
  if (items.length >= 4 && maxGap < 40 && avgLen < 5) return true;
5233
- const minGap = _chunkSTM3ORY7cjs.safeMin.call(void 0, gaps);
5344
+ const minGap = _chunkQNJLLF4Jcjs.safeMin.call(void 0, gaps);
5234
5345
  return minGap > 0 && maxGap - minGap <= Math.max(2, maxGap * 0.15) && items.filter((i) => /^\P{L}*\p{Ll}/u.test(i.text)).length * 2 >= items.length;
5235
5346
  }
5236
5347
  function detectColumns(yLines) {
5237
5348
  const allItems = yLines.flat();
5238
5349
  if (allItems.length === 0) return null;
5239
- const pageWidth = _chunkSTM3ORY7cjs.safeMax.call(void 0, allItems.map((i) => i.x + i.w)) - _chunkSTM3ORY7cjs.safeMin.call(void 0, allItems.map((i) => i.x));
5350
+ const pageWidth = _chunkQNJLLF4Jcjs.safeMax.call(void 0, allItems.map((i) => i.x + i.w)) - _chunkQNJLLF4Jcjs.safeMin.call(void 0, allItems.map((i) => i.x));
5240
5351
  if (pageWidth < 100) return null;
5241
5352
  let bigoLineIdx = -1;
5242
5353
  for (let i = 0; i < yLines.length; i++) {
@@ -5589,6 +5700,76 @@ function headerLineAbove(free, colXs, top) {
5589
5700
  return cols;
5590
5701
  }
5591
5702
 
5703
+ // src/pdf/cell-edges.ts
5704
+ var CLIP_CELL_EDGES = /* @__PURE__ */ new WeakMap();
5705
+ var NO_EDGES = Object.freeze({ t: false, b: false, l: false, r: false });
5706
+ var EDGE_NEAR2 = 1.6;
5707
+ var EDGE_COVER = 0.6;
5708
+ var EDGE_SLACK = 3;
5709
+ var DASH_GAP = 3;
5710
+ var TIP_MAX = 1.5;
5711
+ function rules(lines, dir) {
5712
+ const sorted = [...lines].sort((a, b) => dir === "h" ? a.y1 - b.y1 : a.x1 - b.x1);
5713
+ return { dir, pos: sorted.map((l) => dir === "h" ? l.y1 : l.x1), lines: sorted };
5714
+ }
5715
+ function seen(r, at, a1, a2) {
5716
+ const len = a2 - a1;
5717
+ if (len <= 0) return false;
5718
+ const covered = coverage(r, at, a1, a2);
5719
+ return covered >= len * EDGE_COVER && len - covered <= EDGE_SLACK;
5720
+ }
5721
+ function coverage(r, at, a1, a2) {
5722
+ let i = 0, j = r.pos.length;
5723
+ while (i < j) {
5724
+ const m = i + j >> 1;
5725
+ if (r.pos[m] < at - EDGE_NEAR2) i = m + 1;
5726
+ else j = m;
5727
+ }
5728
+ const spans = [];
5729
+ for (; i < r.pos.length && r.pos[i] <= at + EDGE_NEAR2; i++) {
5730
+ const l = r.lines[i];
5731
+ const l1 = r.dir === "h" ? Math.min(l.x1, l.x2) : Math.min(l.y1, l.y2), l2 = r.dir === "h" ? Math.max(l.x1, l.x2) : Math.max(l.y1, l.y2);
5732
+ const lo = Math.max(a1, l1), hi = Math.min(a2, l2);
5733
+ if (hi <= lo || l1 < a1 !== l2 > a2 && hi - lo < TIP_MAX) continue;
5734
+ spans.push([lo, hi]);
5735
+ }
5736
+ if (!spans.length) return 0;
5737
+ spans.sort((p, q) => p[0] - q[0]);
5738
+ let covered = 0, s = spans[0][0], e = spans[0][1];
5739
+ for (const [lo, hi] of spans.slice(1)) {
5740
+ if (lo <= e + DASH_GAP) e = Math.max(e, hi);
5741
+ else {
5742
+ covered += e - s;
5743
+ s = lo;
5744
+ e = hi;
5745
+ }
5746
+ }
5747
+ return covered + e - s;
5748
+ }
5749
+ function edgesOf(box, h, v) {
5750
+ return {
5751
+ t: seen(h, box.y2, box.x1, box.x2),
5752
+ b: seen(h, box.y1, box.x1, box.x2),
5753
+ l: seen(v, box.x1, box.y1, box.y2),
5754
+ r: seen(v, box.x2, box.y1, box.y2)
5755
+ };
5756
+ }
5757
+ function recordClipCellEdges(grids, horizontals, verticals, nonRules) {
5758
+ if (!grids.some((g) => g.cells)) return;
5759
+ const h = rules(_optionalChain([nonRules, 'optionalAccess', _257 => _257.size]) ? horizontals.filter((l) => !nonRules.has(l)) : horizontals, "h");
5760
+ const v = rules(_optionalChain([nonRules, 'optionalAccess', _258 => _258.size]) ? verticals.filter((l) => !nonRules.has(l)) : verticals, "v");
5761
+ for (const g of grids) for (const c of _nullishCoalesce(g.cells, () => ( []))) CLIP_CELL_EDGES.set(c, edgesOf(c.bbox, h, v));
5762
+ }
5763
+ function takeClipCellEdges(from, to) {
5764
+ const e = CLIP_CELL_EDGES.get(from);
5765
+ if (e) _chunkAKB72TEHcjs.CELL_EDGES.set(to, e);
5766
+ }
5767
+ function joinCellEdges(a, b) {
5768
+ const u = _chunkAKB72TEHcjs.CELL_EDGES.get(a), d = _chunkAKB72TEHcjs.CELL_EDGES.get(b);
5769
+ if (!u || !d) return;
5770
+ _chunkAKB72TEHcjs.CELL_EDGES.set(a, { t: u.t, b: d.b, l: u.l || d.l, r: u.r || d.r });
5771
+ }
5772
+
5592
5773
  // src/pdf/page-frame.ts
5593
5774
  function isPageFrameGrid(grid, cells, pageWidth, pageHeight, items = []) {
5594
5775
  const b = grid.bbox;
@@ -5843,8 +6024,8 @@ function detectRuledBandTables(horizontals, verticals, items, pageNum) {
5843
6024
  };
5844
6025
  for (const g of groups) {
5845
6026
  if (g.length < 2) continue;
5846
- const rules = [...g].sort((a, b) => b.y1 - a.y1);
5847
- const x1 = Math.min(...rules.map((r) => r.x1)), x2 = Math.max(...rules.map((r) => r.x2));
6027
+ const rules2 = [...g].sort((a, b) => b.y1 - a.y1);
6028
+ const x1 = Math.min(...rules2.map((r) => r.x1)), x2 = Math.max(...rules2.map((r) => r.x2));
5848
6029
  let run = [];
5849
6030
  const flush = () => {
5850
6031
  if (run.length >= 2) emit(run, x1, x2);
@@ -5858,8 +6039,8 @@ function detectRuledBandTables(horizontals, verticals, items, pageNum) {
5858
6039
  run = [];
5859
6040
  };
5860
6041
  let title = null;
5861
- for (let i = 0; i + 1 < rules.length; i++) {
5862
- const top = rules[i].y1, bottom = rules[i + 1].y1;
6042
+ for (let i = 0; i + 1 < rules2.length; i++) {
6043
+ const top = rules2[i].y1, bottom = rules2[i + 1].y1;
5863
6044
  const band = lines.filter((l) => l[0].y < top && l[0].y > bottom);
5864
6045
  const inside = !band.some((l) => l.some((it) => it.x < x1 - EDGE_TOL3 || it.x + it.w > x2 + EDGE_TOL3));
5865
6046
  const fs = median(band.flat().map((it) => it.fontSize).filter((s) => s > 0)) || 10;
@@ -6117,7 +6298,7 @@ function stackedTableBands(items) {
6117
6298
  const caption = (start, end) => lines.slice(start, end).some((line) => /^Table\s+\d+\s*[:.]/i.test(mergeLineSimple(line).trim()));
6118
6299
  while (runs.length > 0 && !caption(runs[runs.length - 1].end, lines.length)) runs.pop();
6119
6300
  if (runs.length < 2) return null;
6120
- if (runs.some((run, i) => !caption(run.end, _nullishCoalesce(_optionalChain([runs, 'access', _257 => _257[i + 1], 'optionalAccess', _258 => _258.start]), () => ( lines.length))))) return null;
6301
+ if (runs.some((run, i) => !caption(run.end, _nullishCoalesce(_optionalChain([runs, 'access', _259 => _259[i + 1], 'optionalAccess', _260 => _260.start]), () => ( lines.length))))) return null;
6121
6302
  const tables = runs.map((run) => lines.slice(run.start, run.end).flat());
6122
6303
  const between = runs.slice(0, -1).map((run, i) => lines.slice(run.end, runs[i + 1].start).flat());
6123
6304
  const tail = lines.slice(runs[runs.length - 1].end);
@@ -6277,16 +6458,18 @@ function extractPageBlocksWithLines(items, pageNum, opList, pageWidth, pageHeigh
6277
6458
  for (const line of streamLines(items)) lex.addLine(mergeLineSimple(line));
6278
6459
  const extracted = extractLines(opList.fnArray, opList.argsArray);
6279
6460
  let { horizontals, verticals } = extracted;
6461
+ const rawRules = extracted.horizontals.concat(extracted.shortH);
6280
6462
  const filled = fillBlanks(items, horizontals, verticals);
6281
6463
  items = filled.items;
6282
6464
  horizontals = filled.horizontals;
6283
- const prevPage = _optionalChain([carry, 'optionalAccess', _259 => _259.page]) === pageNum - 1 ? carry.clip : void 0;
6465
+ const prevPage = _optionalChain([carry, 'optionalAccess', _261 => _261.page]) === pageNum - 1 ? carry.clip : void 0;
6284
6466
  const clipResult = detectTables ? buildClipCellGrids(extracted.clipRects, horizontals, verticals, pageWidth, pageHeight, items.map((it) => ({ x: it.x + it.w / 2, y: it.y + it.h / 2 })), extracted.fillRects, prevPage) : { grids: [], containers: [], page: void 0 };
6285
6467
  if (carry) {
6286
6468
  carry.page = pageNum;
6287
6469
  carry.clip = clipResult.page;
6288
6470
  }
6289
6471
  const clipGrids = clipResult.grids;
6472
+ recordClipCellEdges(clipGrids, horizontals.concat(extracted.shortH), verticals.concat(extracted.shortV), extracted.nonRules);
6290
6473
  if (clipGrids.length === 0) {
6291
6474
  horizontals = chainShortSegments(horizontals, extracted.shortH, "h");
6292
6475
  verticals = chainShortSegments(verticals, extracted.shortV, "v");
@@ -6318,7 +6501,7 @@ function extractPageBlocksWithLines(items, pageNum, opList, pageWidth, pageHeigh
6318
6501
  if (detectTables && clipGrids.length === 0 && ruled.length === 0 && lineGrids.length === 0) ruled.push(...detectTextBoxTables(extracted.hiddenBoxes, items, pageNum));
6319
6502
  if (ruled.length > 0) {
6320
6503
  const imageRegions = extractImageRegions(opList.fnArray, opList.argsArray).filter((r) => r.x2 - r.x1 >= 8 && r.y2 - r.y1 >= 8);
6321
- return extractBlocksWithGrids(items, pageNum, pageWidth, pageHeight, grids, horizontals, verticals, imageRegions, lex, ruled);
6504
+ return extractBlocksWithGrids(items, pageNum, pageWidth, pageHeight, grids, horizontals, verticals, imageRegions, lex, ruled, rawRules);
6322
6505
  }
6323
6506
  if (detectTables && stackedTableBands(items)) {
6324
6507
  return extractPageBlocksFallback(items, pageNum, true, detectTables, lex);
@@ -6329,7 +6512,7 @@ function extractPageBlocksWithLines(items, pageNum, opList, pageWidth, pageHeigh
6329
6512
  }
6330
6513
  if (grids.length > 0) {
6331
6514
  const imageRegions = extractImageRegions(opList.fnArray, opList.argsArray).filter((r) => r.x2 - r.x1 >= 8 && r.y2 - r.y1 >= 8);
6332
- return extractBlocksWithGrids(items, pageNum, pageWidth, pageHeight, grids, horizontals, verticals, imageRegions, lex);
6515
+ return extractBlocksWithGrids(items, pageNum, pageWidth, pageHeight, grids, horizontals, verticals, imageRegions, lex, [], rawRules);
6333
6516
  }
6334
6517
  const figures = extractImageRegions(opList.fnArray, opList.argsArray).filter((r) => r.x2 - r.x1 >= 40 && r.y2 - r.y1 >= 40).map((r) => ({ x: r.x1, y: r.y1, w: r.x2 - r.x1, h: r.y2 - r.y1 }));
6335
6518
  return extractPageBlocksFallback(items, pageNum, true, detectTables, lex, figures);
@@ -6472,7 +6655,7 @@ function buildFrameCellBlocks(cellItems, nested, pageNum, wrap) {
6472
6655
  const text = blocks.map((b) => b.type === "table" && b.table ? b.table.cells.flat().map((c) => c.text).filter(Boolean).join("\n") : _nullishCoalesce(b.text, () => ( ""))).filter(Boolean).join("\n");
6473
6656
  return { blocks, text };
6474
6657
  }
6475
- function extractBlocksWithGrids(items, pageNum, pageWidth, pageHeight, grids, horizontals, verticals, imageRegions = [], lex, ruled = []) {
6658
+ function extractBlocksWithGrids(items, pageNum, pageWidth, pageHeight, grids, horizontals, verticals, imageRegions = [], lex, ruled = [], rawRules = horizontals) {
6476
6659
  const ocrPage = items.length > 0 && items.every((i) => i.fontName === "ocr");
6477
6660
  const blocks = [];
6478
6661
  const usedItems = /* @__PURE__ */ new Set();
@@ -6534,6 +6717,7 @@ function extractBlocksWithGrids(items, pageNum, pageWidth, pageHeight, grids, ho
6534
6717
  const built = buildFrameCellBlocks(cellItems, nested, pageNum, { box: cell.bbox, lex });
6535
6718
  irGrid[cell.row][cell.col] = { text: built.text, colSpan: cell.colSpan, rowSpan: cell.rowSpan, blocks: built.blocks };
6536
6719
  if (cellItems.length) recordCellLines(irGrid[cell.row][cell.col], cellItems);
6720
+ takeClipCellEdges(cell, irGrid[cell.row][cell.col]);
6537
6721
  continue;
6538
6722
  }
6539
6723
  irGrid[cell.row][cell.col] = {
@@ -6551,6 +6735,7 @@ function extractBlocksWithGrids(items, pageNum, pageWidth, pageHeight, grids, ho
6551
6735
  }
6552
6736
  if (cell.filler && !cellItems.length) FILLER_CELLS.add(irGrid[cell.row][cell.col]);
6553
6737
  if (grid.cells && cellItems.length) recordCellLines(irGrid[cell.row][cell.col], cellItems);
6738
+ takeClipCellEdges(cell, irGrid[cell.row][cell.col]);
6554
6739
  }
6555
6740
  let finalGrid = irGrid;
6556
6741
  let finalRows = numRows;
@@ -6581,26 +6766,27 @@ function extractBlocksWithGrids(items, pageNum, pageWidth, pageHeight, grids, ho
6581
6766
  if (!assignedItems.has(textItems[ti])) usedItems.delete(tableItems[ti]);
6582
6767
  }
6583
6768
  }
6584
- if (unitLine.length > 0 && rebuiltUsed && !/^\s*\(\s*단위\s*[::]/.test(_nullishCoalesce(_optionalChain([finalGrid, 'access', _260 => _260[0], 'optionalAccess', _261 => _261[0], 'optionalAccess', _262 => _262.text]), () => ( "")))) {
6769
+ if (unitLine.length > 0 && rebuiltUsed && !/^\s*\(\s*단위\s*[::]/.test(_nullishCoalesce(_optionalChain([finalGrid, 'access', _262 => _262[0], 'optionalAccess', _263 => _263[0], 'optionalAccess', _264 => _264.text]), () => ( "")))) {
6585
6770
  finalGrid.unshift(Array.from({ length: numCols }, (_, c) => ({ text: c === 0 ? cleanCellText(unitText) : "", colSpan: c === 0 ? numCols : 1, rowSpan: 1 })));
6586
6771
  finalRows++;
6587
6772
  for (const item of unitLine) usedItems.add(item);
6588
6773
  }
6589
6774
  const filledCells = finalGrid.flat().filter((c) => c.text.trim()).length;
6590
- if (!rebuiltUsed && filledCells * 2 >= finalGrid.flat().length && !/^\s*\(\s*단위\s*[::]/.test(_nullishCoalesce(_optionalChain([finalGrid, 'access', _263 => _263[0], 'optionalAccess', _264 => _264[0], 'optionalAccess', _265 => _265.text]), () => ( "")))) {
6775
+ if (!rebuiltUsed && filledCells * 2 >= finalGrid.flat().length && !/^\s*\(\s*단위\s*[::]/.test(_nullishCoalesce(_optionalChain([finalGrid, 'access', _265 => _265[0], 'optionalAccess', _266 => _266[0], 'optionalAccess', _267 => _267.text]), () => ( "")))) {
6591
6776
  const above = items.filter((it) => !usedItems.has(it) && it.y >= grid.bbox.y2 && it.y - grid.bbox.y2 <= 8 && it.x >= grid.bbox.x1 - 3 && it.x + it.w <= grid.bbox.x2 + 3);
6592
6777
  const line = above.filter((it) => Math.abs(it.y - Math.min(...above.map((a) => a.y))) <= 1).sort((a, b) => a.x - b.x);
6593
6778
  const text = line.map((it) => it.text).join("");
6594
6779
  const inset = line.length ? grid.bbox.x2 - (line[line.length - 1].x + line[line.length - 1].w) : 0;
6595
6780
  if (line.length && /^\s*\(\s*단위\s*[::]/.test(text) && inset >= 4.6 && inset <= 5.6) {
6596
6781
  finalGrid.unshift(Array.from({ length: numCols }, (_, c) => ({ text: c === 0 ? cleanCellText(text) : "", colSpan: c === 0 ? numCols : 1, rowSpan: 1 })));
6782
+ if (grid.cells) for (const u of finalGrid[0]) _chunkAKB72TEHcjs.CELL_EDGES.set(u, NO_EDGES);
6597
6783
  finalRows++;
6598
6784
  for (const item of line) usedItems.add(item);
6599
6785
  }
6600
6786
  }
6601
6787
  let semanticOneColumn = false;
6602
6788
  if (!grid.cells && numCols === 1 && numGridRows >= 2) {
6603
- const populatedRows = finalGrid.filter((row) => _optionalChain([row, 'access', _266 => _266[0], 'optionalAccess', _267 => _267.text, 'access', _268 => _268.trim, 'call', _269 => _269()]));
6789
+ const populatedRows = finalGrid.filter((row) => _optionalChain([row, 'access', _268 => _268[0], 'optionalAccess', _269 => _269.text, 'access', _270 => _270.trim, 'call', _271 => _271()]));
6604
6790
  if (populatedRows.length >= 4) {
6605
6791
  const fontSizes = tableItems.map((item) => item.fontSize).filter((size) => size > 0).sort((a, b) => a - b);
6606
6792
  const medianFont = _nullishCoalesce(fontSizes[Math.floor(fontSizes.length / 2)], () => ( 0));
@@ -6647,8 +6833,12 @@ function extractBlocksWithGrids(items, pageNum, pageWidth, pageHeight, grids, ho
6647
6833
  hasHeader: finalRows > 1,
6648
6834
  ...semanticOneColumn ? { renderAsTable: true } : {}
6649
6835
  };
6650
- if (grid.cells) CLIP_TABLES.add(irTable);
6836
+ if (grid.cells) {
6837
+ CLIP_TABLES.add(irTable);
6838
+ recordRowRules(irTable, grid.cells, grid.bbox, rawRules);
6839
+ }
6651
6840
  TABLE_COLXS.set(irTable, grid.colXs);
6841
+ if (grid.cells && finalRows === numRows) TABLE_ROWYS.set(irTable, grid.rowYs);
6652
6842
  if (grid.continues) CONT_PARTS.set(irTable, grid.continues);
6653
6843
  const hasContent = finalGrid.some((row) => row.some((cell) => cell.text.trim() !== ""));
6654
6844
  const emptyPart = !hasContent && !!grid.cells && !grid.clipParent && !nestedAttached;
@@ -6675,7 +6865,7 @@ function extractBlocksWithGrids(items, pageNum, pageWidth, pageHeight, grids, ho
6675
6865
  height: grid.bbox.y2 - grid.bbox.y1
6676
6866
  };
6677
6867
  if (numRows === 1 && numCols === 1 && gridW < pageWidth * 0.35) {
6678
- const prose = _nullishCoalesce(_optionalChain([finalGrid, 'access', _270 => _270[0], 'optionalAccess', _271 => _271[0], 'optionalAccess', _272 => _272.text]), () => ( ""));
6868
+ const prose = _nullishCoalesce(_optionalChain([finalGrid, 'access', _272 => _272[0], 'optionalAccess', _273 => _273[0], 'optionalAccess', _274 => _274.text]), () => ( ""));
6679
6869
  const besideLines = (side) => new Set(side.map((it) => Math.round(it.y / 3))).size;
6680
6870
  const rightLines = items.filter((it) => it.x >= grid.bbox.x2 + 3 && it.y >= grid.bbox.y1 && it.y <= grid.bbox.y2);
6681
6871
  const leftLines = items.filter((it) => it.x + it.w <= grid.bbox.x1 - 3 && it.y >= grid.bbox.y1 && it.y <= grid.bbox.y2);
@@ -6729,7 +6919,7 @@ function extractBlocksWithGrids(items, pageNum, pageWidth, pageHeight, grids, ho
6729
6919
  const proseColumns = findTwoColumnProseCutX(clusterItems) !== null || detectPersistentColumnGutter(remaining.map((i) => ({ x: i.x, y: i.y, w: i.w, h: i.h > 0 ? i.h : i.fontSize }))) !== null;
6730
6920
  const clusterResults = (proseColumns ? [] : detectClusterTables(clusterItems, pageNum)).filter((cr) => {
6731
6921
  const b = cr.bbox;
6732
- return !blocks.some((x) => x.type === "paragraph" && x.bbox && (_nullishCoalesce(_optionalChain([x, 'access', _273 => _273.text, 'optionalAccess', _274 => _274.match, 'call', _275 => _275(/\p{L}/gu), 'optionalAccess', _276 => _276.length]), () => ( 0))) >= 10 && Math.min(x.bbox.x + x.bbox.width, b.x + b.width) - Math.max(x.bbox.x, b.x) >= 0.8 * b.width && x.bbox.y >= b.y - 2 && x.bbox.y + x.bbox.height <= b.y + b.height + 2);
6922
+ return !blocks.some((x) => x.type === "paragraph" && x.bbox && (_nullishCoalesce(_optionalChain([x, 'access', _275 => _275.text, 'optionalAccess', _276 => _276.match, 'call', _277 => _277(/\p{L}/gu), 'optionalAccess', _278 => _278.length]), () => ( 0))) >= 10 && Math.min(x.bbox.x + x.bbox.width, b.x + b.width) - Math.max(x.bbox.x, b.x) >= 0.8 * b.width && x.bbox.y >= b.y - 2 && x.bbox.y + x.bbox.height <= b.y + b.height + 2);
6733
6923
  });
6734
6924
  if (clusterResults.length > 0) {
6735
6925
  const ciToIdx = /* @__PURE__ */ new Map();
@@ -6763,7 +6953,7 @@ function extractBlocksWithGrids(items, pageNum, pageWidth, pageHeight, grids, ho
6763
6953
  if (gutterX !== null) {
6764
6954
  const gx = gutterX;
6765
6955
  const allY = remaining.map((i) => i.y);
6766
- const pageH = _chunkSTM3ORY7cjs.safeMax.call(void 0, allY) - _chunkSTM3ORY7cjs.safeMin.call(void 0, allY);
6956
+ const pageH = _chunkQNJLLF4Jcjs.safeMax.call(void 0, allY) - _chunkQNJLLF4Jcjs.safeMin.call(void 0, allY);
6767
6957
  const gapThreshold = Math.max(15, pageH * 0.03);
6768
6958
  const sides = [
6769
6959
  remaining.filter((i) => i.x + i.w <= gx),
@@ -6783,7 +6973,7 @@ function extractBlocksWithGrids(items, pageNum, pageWidth, pageHeight, grids, ho
6783
6973
  finalTextBlocks = detectListBlocks(textBlocks);
6784
6974
  } else {
6785
6975
  const allY = remaining.map((i) => i.y);
6786
- const pageH = _chunkSTM3ORY7cjs.safeMax.call(void 0, allY) - _chunkSTM3ORY7cjs.safeMin.call(void 0, allY);
6976
+ const pageH = _chunkQNJLLF4Jcjs.safeMax.call(void 0, allY) - _chunkQNJLLF4Jcjs.safeMin.call(void 0, allY);
6787
6977
  const groups = xyCutOrder(remaining, Math.max(15, pageH * 0.03));
6788
6978
  const textBlocks = [];
6789
6979
  for (const group of groups) {
@@ -7097,7 +7287,7 @@ function extractPageBlocksFallback(items, pageNum, fullPage = false, detectTable
7097
7287
  blocks.push(...columnTextToBlocks(tableText, pageNum, bbox, dominantStyle(items)));
7098
7288
  } else {
7099
7289
  const allY = items.map((i) => i.y);
7100
- const pageHeight = _chunkSTM3ORY7cjs.safeMax.call(void 0, allY) - _chunkSTM3ORY7cjs.safeMin.call(void 0, allY);
7290
+ const pageHeight = _chunkQNJLLF4Jcjs.safeMax.call(void 0, allY) - _chunkQNJLLF4Jcjs.safeMin.call(void 0, allY);
7101
7291
  const gapThreshold = Math.max(15, pageHeight * 0.03);
7102
7292
  const orderedGroups = proseCutX !== null ? splitTwoColumnProse(items, proseCutX) : xyCutOrder(items, gapThreshold);
7103
7293
  for (const group of orderedGroups) {
@@ -7158,5 +7348,11 @@ function extractPageBlocksFallback(items, pageNum, fullPage = false, detectTable
7158
7348
 
7159
7349
 
7160
7350
 
7161
- exports.OCR_DET_MODEL = OCR_DET_MODEL; exports.OCR_REC_MODEL = OCR_REC_MODEL; exports.OCR_REC_DICT = OCR_REC_DICT; exports.getOcrModelsDir = getOcrModelsDir; exports.ensureOcrModels = ensureOcrModels; exports.ocrModelsCached = ocrModelsCached; exports.parseCharacterDict = parseCharacterDict; exports.extractLines = extractLines; exports.extractImageRegions = extractImageRegions; exports.filterHiddenText = filterHiddenText; exports.collapseEvenSpacing = collapseEvenSpacing; exports.normalizeItems = normalizeItems; exports.WrapLexicon = WrapLexicon; exports.startsNewItem = startsNewItem; exports.wrapJoiner = wrapJoiner; exports.joinPageBreakWraps = joinPageBreakWraps; exports.latinSoftWrap = latinSoftWrap; exports.TOC_BLOCKS = TOC_BLOCKS; exports.computeMedianFontSizeFromFreq = computeMedianFontSizeFromFreq; exports.detectHeadings = detectHeadings; exports.mergeStackedHeadingLines = mergeStackedHeadingLines; exports.detectTypographyHeadings = detectTypographyHeadings; exports.detectDocumentStyleHeadings = detectDocumentStyleHeadings; exports.detectSiblingStyleHeadings = detectSiblingStyleHeadings; exports.detectRepeatedPageLabels = detectRepeatedPageLabels; exports.detectPageLeadHeadings = detectPageLeadHeadings; exports.refineDocumentStyleHeadings = refineDocumentStyleHeadings; exports.detectMarkerHeadings = detectMarkerHeadings; exports.detectTableCaptions = detectTableCaptions; exports.detectKoreanListBlocks = detectKoreanListBlocks; exports.removeHeaderFooterBlocks = removeHeaderFooterBlocks; exports.CLIP_TABLES = CLIP_TABLES; exports.TABLE_COLXS = TABLE_COLXS; exports.EMPTY_PARTS = EMPTY_PARTS; exports.IMAGE_CELLS = IMAGE_CELLS; exports.FILLER_CELLS = FILLER_CELLS; exports.CONT_PARTS = CONT_PARTS; exports.CELL_LINES = CELL_LINES; exports.trimTrailingEmptyTableCols = trimTrailingEmptyTableCols; exports.extractPageBlocksWithLines = extractPageBlocksWithLines;
7162
- //# sourceMappingURL=chunk-WDQTFAXY.cjs.map
7351
+
7352
+
7353
+
7354
+
7355
+
7356
+
7357
+ exports.OCR_DET_MODEL = OCR_DET_MODEL; exports.OCR_REC_MODEL = OCR_REC_MODEL; exports.OCR_REC_DICT = OCR_REC_DICT; exports.getOcrModelsDir = getOcrModelsDir; exports.ensureOcrModels = ensureOcrModels; exports.ocrModelsCached = ocrModelsCached; exports.parseCharacterDict = parseCharacterDict; exports.extractLines = extractLines; exports.extractImageRegions = extractImageRegions; exports.filterHiddenText = filterHiddenText; exports.collapseEvenSpacing = collapseEvenSpacing; exports.normalizeItems = normalizeItems; exports.WrapLexicon = WrapLexicon; exports.startsNewItem = startsNewItem; exports.wrapJoiner = wrapJoiner; exports.joinPageBreakWraps = joinPageBreakWraps; exports.latinSoftWrap = latinSoftWrap; exports.TOC_BLOCKS = TOC_BLOCKS; exports.computeMedianFontSizeFromFreq = computeMedianFontSizeFromFreq; exports.detectHeadings = detectHeadings; exports.mergeStackedHeadingLines = mergeStackedHeadingLines; exports.detectTypographyHeadings = detectTypographyHeadings; exports.detectDocumentStyleHeadings = detectDocumentStyleHeadings; exports.detectSiblingStyleHeadings = detectSiblingStyleHeadings; exports.detectRepeatedPageLabels = detectRepeatedPageLabels; exports.detectPageLeadHeadings = detectPageLeadHeadings; exports.refineDocumentStyleHeadings = refineDocumentStyleHeadings; exports.detectMarkerHeadings = detectMarkerHeadings; exports.detectTableCaptions = detectTableCaptions; exports.detectKoreanListBlocks = detectKoreanListBlocks; exports.removeHeaderFooterBlocks = removeHeaderFooterBlocks; exports.CLIP_TABLES = CLIP_TABLES; exports.TABLE_COLXS = TABLE_COLXS; exports.TABLE_ROWYS = TABLE_ROWYS; exports.TABLE_TAIL = TABLE_TAIL; exports.PART_COLXS = PART_COLXS; exports.EMPTY_PARTS = EMPTY_PARTS; exports.IMAGE_CELLS = IMAGE_CELLS; exports.FILLER_CELLS = FILLER_CELLS; exports.CONT_PARTS = CONT_PARTS; exports.CELL_LINES = CELL_LINES; exports.ROW_RULES = ROW_RULES; exports.trimTrailingEmptyTableCols = trimTrailingEmptyTableCols; exports.NO_EDGES = NO_EDGES; exports.joinCellEdges = joinCellEdges; exports.extractPageBlocksWithLines = extractPageBlocksWithLines;
7358
+ //# sourceMappingURL=chunk-XEPKOC2O.cjs.map