kordoc 4.16.1 → 4.16.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (137) hide show
  1. package/README.md +6 -7
  2. package/dist/{-3DURLXSO.js → -4G6MA4X6.js} +11 -11
  3. package/dist/chunk-3IB7LBHC.js +57 -0
  4. package/dist/chunk-3IB7LBHC.js.map +1 -0
  5. package/dist/{chunk-EEVAPRPD.js → chunk-4VODJKFL.js} +3 -3
  6. package/dist/{chunk-NCXRSQNE.js → chunk-5KS5PWJR.js} +2 -2
  7. package/dist/chunk-62W7QCEX.cjs +57 -0
  8. package/dist/chunk-62W7QCEX.cjs.map +1 -0
  9. package/dist/{chunk-ANZTLTKU.js → chunk-7KNGSQU7.js} +4 -4
  10. package/dist/chunk-7KNGSQU7.js.map +1 -0
  11. package/dist/{chunk-63YGGAQW.js → chunk-AUWGDP4G.js} +2 -2
  12. package/dist/{chunk-2BZFKIRB.cjs → chunk-CEIATRDW.cjs} +3 -3
  13. package/dist/{chunk-2BZFKIRB.cjs.map → chunk-CEIATRDW.cjs.map} +1 -1
  14. package/dist/{chunk-BIHS4VWR.js → chunk-DES2LGFZ.js} +2 -2
  15. package/dist/{chunk-N65ZXWNQ.js → chunk-F4NRLLY4.js} +2 -2
  16. package/dist/{chunk-NV37CQFN.cjs → chunk-FKUDAIJI.cjs} +12 -12
  17. package/dist/{chunk-NV37CQFN.cjs.map → chunk-FKUDAIJI.cjs.map} +1 -1
  18. package/dist/{chunk-VCRBR72A.js → chunk-GO5IFOUF.js} +2 -2
  19. package/dist/{chunk-BTO7ZEE4.js → chunk-IQGIT2VX.js} +37 -7
  20. package/dist/chunk-IQGIT2VX.js.map +1 -0
  21. package/dist/chunk-J3IF6KGW.js +59 -0
  22. package/dist/chunk-J3IF6KGW.js.map +1 -0
  23. package/dist/{chunk-VNOQTDTE.js → chunk-JELRWAZC.js} +2 -2
  24. package/dist/{chunk-CXWWX6BQ.js → chunk-JFLAM3MM.js} +2 -2
  25. package/dist/{chunk-7XAGIPOX.js → chunk-KIOQ4N37.js} +2 -2
  26. package/dist/{chunk-UZHT3LBF.js → chunk-LEIAEWZ7.js} +4 -4
  27. package/dist/chunk-LEIAEWZ7.js.map +1 -0
  28. package/dist/{chunk-NUPXPKIQ.js → chunk-MLIS253L.js} +2 -2
  29. package/dist/{chunk-DJ2BBQ5P.js → chunk-OXLPVQYK.js} +3 -3
  30. package/dist/{chunk-3VLVNKJV.js → chunk-P6ZDXTV6.js} +2 -2
  31. package/dist/{chunk-OBRPYCIS.js → chunk-QOCS7W7R.js} +58 -23
  32. package/dist/chunk-QOCS7W7R.js.map +1 -0
  33. package/dist/{chunk-24N4IJ5I.js → chunk-S2PL227Q.js} +2 -2
  34. package/dist/{chunk-PVMROO3A.js → chunk-SFEQYKYJ.js} +86 -94
  35. package/dist/chunk-SFEQYKYJ.js.map +1 -0
  36. package/dist/{chunk-YRRBA4HW.cjs → chunk-STM3ORY7.cjs} +2 -2
  37. package/dist/{chunk-YRRBA4HW.cjs.map → chunk-STM3ORY7.cjs.map} +1 -1
  38. package/dist/{chunk-7FKPPIDZ.js → chunk-TXUKTOG2.js} +166 -14
  39. package/dist/chunk-TXUKTOG2.js.map +1 -0
  40. package/dist/{chunk-3WIQSM3Z.js → chunk-UTP2WCHS.js} +4 -4
  41. package/dist/{chunk-7IRHSRPU.cjs → chunk-WDQTFAXY.cjs} +97 -25
  42. package/dist/chunk-WDQTFAXY.cjs.map +1 -0
  43. package/dist/{chunk-D2QCXK2X.cjs → chunk-XTFN5WKS.cjs} +7 -7
  44. package/dist/chunk-XTFN5WKS.cjs.map +1 -0
  45. package/dist/chunks-NUNIKS2J.js +10 -0
  46. package/dist/cli.js +28 -27
  47. package/dist/cli.js.map +1 -1
  48. package/dist/{formula-IPLFHEBD.js → formula-EPKLPDU7.js} +3 -3
  49. package/dist/{formula-U4BTEZ6I.js → formula-NARUOXRX.js} +4 -4
  50. package/dist/{formula-TRTONZMA.cjs → formula-WIMV5TUX.cjs} +9 -9
  51. package/dist/{formula-TRTONZMA.cjs.map → formula-WIMV5TUX.cjs.map} +1 -1
  52. package/dist/{image-ocr-3IJ25PS4.js → image-ocr-3WJ4QH3T.js} +8 -8
  53. package/dist/{image-ocr-GTDG4SAJ.js → image-ocr-5BUJQ4TK.js} +6 -6
  54. package/dist/{image-ocr-THFLQ3DC.cjs → image-ocr-AXWXR6JV.cjs} +15 -15
  55. package/dist/{image-ocr-THFLQ3DC.cjs.map → image-ocr-AXWXR6JV.cjs.map} +1 -1
  56. package/dist/index.cjs +723 -659
  57. package/dist/index.cjs.map +1 -1
  58. package/dist/index.d.cts +7 -1
  59. package/dist/index.d.ts +7 -1
  60. package/dist/index.js +82 -18
  61. package/dist/index.js.map +1 -1
  62. package/dist/mcp.js +25 -23
  63. package/dist/mcp.js.map +1 -1
  64. package/dist/{model-bundle-PVWIAVEX.js → model-bundle-IMBW7D2Z.js} +5 -5
  65. package/dist/{models-VCRF3JMT.js → models-SY75IBOE.js} +5 -5
  66. package/dist/{parser-2CN2DIPV.cjs → parser-2LU4EVU3.cjs} +86 -83
  67. package/dist/parser-2LU4EVU3.cjs.map +1 -0
  68. package/dist/{parser-T4RITZDP.js → parser-N6476XAC.js} +15 -12
  69. package/dist/{parser-UEROAPYZ.js.map → parser-N6476XAC.js.map} +1 -1
  70. package/dist/{parser-UEROAPYZ.js → parser-ZQM3664Z.js} +12 -9
  71. package/dist/{parser-T4RITZDP.js.map → parser-ZQM3664Z.js.map} +1 -1
  72. package/dist/pdf-ocr-6DEE23IP.js +15 -0
  73. package/dist/pdf-ocr-GHEJVPX2.cjs +16 -0
  74. package/dist/{pdf-ocr-NARV2AQI.cjs.map → pdf-ocr-GHEJVPX2.cjs.map} +1 -1
  75. package/dist/pdf-ocr-MQTWODVU.js +18 -0
  76. package/dist/{profile-io-YD54CDXY.js → profile-io-GJPKCYPT.js} +3 -3
  77. package/dist/{rasterize-3THYOOUN.js → rasterize-UOALJQDS.js} +3 -3
  78. package/dist/{redact-doc-65L2YJN6.js → redact-doc-22SYW3KH.js} +11 -11
  79. package/dist/{render-YU7QJVZ7.js → render-MJ4H3R23.js} +7 -7
  80. package/dist/seal-XWMRUTI4.js +10 -0
  81. package/dist/{setup-CFHKXDY4.js → setup-2URYVUEO.js} +3 -3
  82. package/dist/visual-USPS4QRC.js +20 -0
  83. package/dist/{watch-D6FCAYKJ.js → watch-ALXZGTOB.js} +12 -12
  84. package/package.json +1 -1
  85. package/dist/chunk-7FKPPIDZ.js.map +0 -1
  86. package/dist/chunk-7IRHSRPU.cjs.map +0 -1
  87. package/dist/chunk-ANZTLTKU.js.map +0 -1
  88. package/dist/chunk-BTO7ZEE4.js.map +0 -1
  89. package/dist/chunk-D2QCXK2X.cjs.map +0 -1
  90. package/dist/chunk-DO74GYSM.cjs +0 -11
  91. package/dist/chunk-DO74GYSM.cjs.map +0 -1
  92. package/dist/chunk-KBAQLAEL.js +0 -11
  93. package/dist/chunk-KBAQLAEL.js.map +0 -1
  94. package/dist/chunk-OBRPYCIS.js.map +0 -1
  95. package/dist/chunk-PVMROO3A.js.map +0 -1
  96. package/dist/chunk-T77M2QP7.js +0 -13
  97. package/dist/chunk-T77M2QP7.js.map +0 -1
  98. package/dist/chunk-UZHT3LBF.js.map +0 -1
  99. package/dist/chunks-PYYQURNO.js +0 -10
  100. package/dist/parser-2CN2DIPV.cjs.map +0 -1
  101. package/dist/pdf-ocr-NARV2AQI.cjs +0 -16
  102. package/dist/pdf-ocr-SYLMM727.js +0 -18
  103. package/dist/pdf-ocr-YMQZDJBO.js +0 -15
  104. package/dist/seal-6CQGFTML.js +0 -10
  105. package/dist/visual-ED2H75Q5.js +0 -20
  106. /package/dist/{-3DURLXSO.js.map → -4G6MA4X6.js.map} +0 -0
  107. /package/dist/{chunk-EEVAPRPD.js.map → chunk-4VODJKFL.js.map} +0 -0
  108. /package/dist/{chunk-NCXRSQNE.js.map → chunk-5KS5PWJR.js.map} +0 -0
  109. /package/dist/{chunk-63YGGAQW.js.map → chunk-AUWGDP4G.js.map} +0 -0
  110. /package/dist/{chunk-BIHS4VWR.js.map → chunk-DES2LGFZ.js.map} +0 -0
  111. /package/dist/{chunk-N65ZXWNQ.js.map → chunk-F4NRLLY4.js.map} +0 -0
  112. /package/dist/{chunk-VCRBR72A.js.map → chunk-GO5IFOUF.js.map} +0 -0
  113. /package/dist/{chunk-VNOQTDTE.js.map → chunk-JELRWAZC.js.map} +0 -0
  114. /package/dist/{chunk-CXWWX6BQ.js.map → chunk-JFLAM3MM.js.map} +0 -0
  115. /package/dist/{chunk-7XAGIPOX.js.map → chunk-KIOQ4N37.js.map} +0 -0
  116. /package/dist/{chunk-NUPXPKIQ.js.map → chunk-MLIS253L.js.map} +0 -0
  117. /package/dist/{chunk-DJ2BBQ5P.js.map → chunk-OXLPVQYK.js.map} +0 -0
  118. /package/dist/{chunk-3VLVNKJV.js.map → chunk-P6ZDXTV6.js.map} +0 -0
  119. /package/dist/{chunk-24N4IJ5I.js.map → chunk-S2PL227Q.js.map} +0 -0
  120. /package/dist/{chunk-3WIQSM3Z.js.map → chunk-UTP2WCHS.js.map} +0 -0
  121. /package/dist/{chunks-PYYQURNO.js.map → chunks-NUNIKS2J.js.map} +0 -0
  122. /package/dist/{formula-IPLFHEBD.js.map → formula-EPKLPDU7.js.map} +0 -0
  123. /package/dist/{formula-U4BTEZ6I.js.map → formula-NARUOXRX.js.map} +0 -0
  124. /package/dist/{image-ocr-3IJ25PS4.js.map → image-ocr-3WJ4QH3T.js.map} +0 -0
  125. /package/dist/{image-ocr-GTDG4SAJ.js.map → image-ocr-5BUJQ4TK.js.map} +0 -0
  126. /package/dist/{model-bundle-PVWIAVEX.js.map → model-bundle-IMBW7D2Z.js.map} +0 -0
  127. /package/dist/{models-VCRF3JMT.js.map → models-SY75IBOE.js.map} +0 -0
  128. /package/dist/{pdf-ocr-SYLMM727.js.map → pdf-ocr-6DEE23IP.js.map} +0 -0
  129. /package/dist/{pdf-ocr-YMQZDJBO.js.map → pdf-ocr-MQTWODVU.js.map} +0 -0
  130. /package/dist/{profile-io-YD54CDXY.js.map → profile-io-GJPKCYPT.js.map} +0 -0
  131. /package/dist/{rasterize-3THYOOUN.js.map → rasterize-UOALJQDS.js.map} +0 -0
  132. /package/dist/{redact-doc-65L2YJN6.js.map → redact-doc-22SYW3KH.js.map} +0 -0
  133. /package/dist/{render-YU7QJVZ7.js.map → render-MJ4H3R23.js.map} +0 -0
  134. /package/dist/{seal-6CQGFTML.js.map → seal-XWMRUTI4.js.map} +0 -0
  135. /package/dist/{setup-CFHKXDY4.js.map → setup-2URYVUEO.js.map} +0 -0
  136. /package/dist/{visual-ED2H75Q5.js.map → visual-USPS4QRC.js.map} +0 -0
  137. /package/dist/{watch-D6FCAYKJ.js.map → watch-ALXZGTOB.js.map} +0 -0
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  extractPageBlocksWithLines
4
- } from "./chunk-7FKPPIDZ.js";
4
+ } from "./chunk-SFEQYKYJ.js";
5
5
  import {
6
6
  OCR_DET_MODEL,
7
7
  OCR_REC_DICT,
@@ -9,10 +9,10 @@ import {
9
9
  ensureOcrModels,
10
10
  getOcrModelsDir,
11
11
  parseCharacterDict
12
- } from "./chunk-BIHS4VWR.js";
12
+ } from "./chunk-DES2LGFZ.js";
13
13
  import {
14
14
  OPTIONAL_DEP_INSTALL_HINT
15
- } from "./chunk-3VLVNKJV.js";
15
+ } from "./chunk-P6ZDXTV6.js";
16
16
 
17
17
  // src/ocr/ruling-lines.ts
18
18
  var INK_LUMA_MAX = 205;
@@ -2061,4 +2061,4 @@ export {
2061
2061
  runPdfOcr,
2062
2062
  ocrItemsToBlocks
2063
2063
  };
2064
- //# sourceMappingURL=chunk-3WIQSM3Z.js.map
2064
+ //# sourceMappingURL=chunk-UTP2WCHS.js.map
@@ -2,15 +2,16 @@
2
2
 
3
3
 
4
4
 
5
- var _chunkDO74GYSMcjs = require('./chunk-DO74GYSM.cjs');
6
5
 
6
+ var _chunk62W7QCEXcjs = require('./chunk-62W7QCEX.cjs');
7
7
 
8
8
 
9
- var _chunk2BZFKIRBcjs = require('./chunk-2BZFKIRB.cjs');
10
9
 
10
+ var _chunkCEIATRDWcjs = require('./chunk-CEIATRDW.cjs');
11
11
 
12
12
 
13
- var _chunkYRRBA4HWcjs = require('./chunk-YRRBA4HW.cjs');
13
+
14
+ var _chunkSTM3ORY7cjs = require('./chunk-STM3ORY7.cjs');
14
15
 
15
16
  // src/ocr/models.ts
16
17
  var _path = require('path');
@@ -38,10 +39,10 @@ var OCR_REC_DICT = {
38
39
  };
39
40
  var ALL_OCR_MODELS = [OCR_DET_MODEL, OCR_REC_MODEL, OCR_REC_DICT];
40
41
  function getOcrModelsDir() {
41
- return _chunk2BZFKIRBcjs.getModelsDir.call(void 0, "ppocr");
42
+ return _chunkCEIATRDWcjs.getModelsDir.call(void 0, "ppocr");
42
43
  }
43
44
  async function ensureOcrModels(onProgress) {
44
- return _chunk2BZFKIRBcjs.ensureModelsIn.call(void 0, getOcrModelsDir(), ALL_OCR_MODELS, onProgress);
45
+ return _chunkCEIATRDWcjs.ensureModelsIn.call(void 0, getOcrModelsDir(), ALL_OCR_MODELS, onProgress);
45
46
  }
46
47
  async function ocrModelsCached() {
47
48
  const dir = getOcrModelsDir();
@@ -1927,6 +1928,60 @@ function hasHorizontalLine(horizontals, y, leftX, rightX, vertexRadius) {
1927
1928
  return false;
1928
1929
  }
1929
1930
 
1931
+ // src/pdf/script-items.ts
1932
+ function scriptKindsOfLine(sorted) {
1933
+ const kinds = sorted.map(() => null);
1934
+ if (sorted.length < 2) return kinds;
1935
+ const weight = /* @__PURE__ */ new Map();
1936
+ for (const it of sorted) {
1937
+ const k = Math.round(it.fontSize * 2) / 2;
1938
+ weight.set(k, (_nullishCoalesce(weight.get(k), () => ( 0))) + it.text.trim().length);
1939
+ }
1940
+ let bodyFs = 0, best = -1;
1941
+ for (const [fs, n] of weight) if (n > best || n === best && fs > bodyFs) {
1942
+ best = n;
1943
+ bodyFs = fs;
1944
+ }
1945
+ if (bodyFs <= 0) return kinds;
1946
+ const ys = sorted.filter((it) => Math.abs(it.fontSize - bodyFs) <= bodyFs * 0.12).map((it) => it.y).sort((a, b) => a - b);
1947
+ const bodyY = ys[ys.length >> 1];
1948
+ const isBody = (it) => it.fontSize > bodyFs * 0.85;
1949
+ for (let i = 1; i < sorted.length; i++) {
1950
+ const it = sorted[i], prev = sorted[i - 1];
1951
+ const t = it.text.trim();
1952
+ if (!t || t.length > 16 || isBody(it)) continue;
1953
+ if (!isBody(prev) && !kinds[i - 1]) continue;
1954
+ const gap = it.x - (prev.x + prev.w);
1955
+ if (gap > bodyFs * 0.35 || gap < -bodyFs * 0.5) continue;
1956
+ const dy = it.y - bodyY;
1957
+ if (dy >= bodyFs * 0.15) kinds[i] = "sup";
1958
+ else if (dy <= -bodyFs * 0.08) kinds[i] = "sub";
1959
+ }
1960
+ return kinds;
1961
+ }
1962
+ function tagScripts(text, lines) {
1963
+ const marks = [];
1964
+ let cursor = 0;
1965
+ for (const line of lines) {
1966
+ const kinds = scriptKindsOfLine(line);
1967
+ for (let k = 0; k < line.length; k++) {
1968
+ const t = line[k].text;
1969
+ if (!t) continue;
1970
+ const at = text.indexOf(t, cursor);
1971
+ if (at < 0 || /\S/.test(text.slice(cursor, at))) return text;
1972
+ if (kinds[k]) marks.push([at, at + t.length, kinds[k]]);
1973
+ cursor = at + t.length;
1974
+ }
1975
+ }
1976
+ if (!marks.length) return text;
1977
+ let out = text;
1978
+ for (let m = marks.length - 1; m >= 0; m--) {
1979
+ const [s, e, kind] = marks[m];
1980
+ out = out.slice(0, s) + `<${kind}>` + out.slice(s, e) + `</${kind}>` + out.slice(e);
1981
+ }
1982
+ return _chunk62W7QCEXcjs.tidyScriptTags.call(void 0, out);
1983
+ }
1984
+
1930
1985
  // src/pdf/line-wrap.ts
1931
1986
  var MARKUP = /<\/?u>|~~/g;
1932
1987
  var bump = (m, k) => {
@@ -2258,7 +2313,8 @@ function cellTextToString(items, wrap) {
2258
2313
  }
2259
2314
  return result;
2260
2315
  });
2261
- if (!wrap) return mergeCellTextLines(textLines);
2316
+ const scripted = (s) => tagScripts(s, merged.map((l) => sortLineByX([...l])));
2317
+ if (!wrap) return scripted(mergeCellTextLines(textLines));
2262
2318
  let contentLeft = Infinity;
2263
2319
  for (const it of items) if (it.x < contentLeft) contentLeft = it.x;
2264
2320
  const lineEnds = merged.map((line) => {
@@ -2271,7 +2327,7 @@ function cellTextToString(items, wrap) {
2271
2327
  let cellRight = -Infinity;
2272
2328
  for (const e of lineEnds) if (e.right > cellRight) cellRight = e.right;
2273
2329
  const wraps = lineEnds.slice(0, -1).map((a, i) => cellLineWraps(wrap.box, contentLeft, a.right, a.fontSize, lineEnds[i + 1].firstCharW) || lineEnds.length >= 3 && !textLines[i + 1].startsWith("(") && cellLineFills(wrap.box, contentLeft, cellRight, a.right, a.fontSize));
2274
- return mergeCellTextLines(textLines, { wraps, lex: wrap.lex });
2330
+ return scripted(mergeCellTextLines(textLines, { wraps, lex: wrap.lex }));
2275
2331
  }
2276
2332
  function mergeSuperscriptRows(lines) {
2277
2333
  if (lines.length <= 1) return lines;
@@ -2822,6 +2878,13 @@ function mergeSuperscriptLines(lines) {
2822
2878
  for (const i of line) total += i.text.trim().length;
2823
2879
  return total > 0 && total <= 10;
2824
2880
  };
2881
+ const isMarkers = (line, host) => line.length > 1 && line.length <= 16 && line.every((i) => {
2882
+ if (i.text.trim().length > 3 || !i.text.trim()) return false;
2883
+ return host.some((h) => {
2884
+ const g = i.x - (h.x + h.w);
2885
+ return g <= h.fontSize * 0.35 && g >= -h.fontSize * 0.1;
2886
+ });
2887
+ });
2825
2888
  const result = [lines[0]];
2826
2889
  for (let i = 1; i < lines.length; i++) {
2827
2890
  const prev = result[result.length - 1];
@@ -2829,8 +2892,8 @@ function mergeSuperscriptLines(lines) {
2829
2892
  const a = band(prev);
2830
2893
  const b = band(curr);
2831
2894
  const overlap2 = Math.min(a.top, b.top) - Math.max(a.bottom, b.bottom);
2832
- const prevIsFrag = isFrag(prev) && a.height <= b.height * 0.8 && overlap2 >= a.height * 0.5;
2833
- const currIsFrag = isFrag(curr) && b.height <= a.height * 0.8 && overlap2 >= b.height * 0.5;
2895
+ const prevIsFrag = (isFrag(prev) || isMarkers(prev, curr)) && a.height <= b.height * 0.8 && overlap2 >= a.height * 0.5;
2896
+ const currIsFrag = (isFrag(curr) || isMarkers(curr, prev)) && b.height <= a.height * 0.8 && overlap2 >= b.height * 0.5;
2834
2897
  if (prevIsFrag || currIsFrag) {
2835
2898
  result[result.length - 1] = [...prev, ...curr];
2836
2899
  } else {
@@ -3028,10 +3091,13 @@ function pushLineParagraphs(out, yLines, pageNum, lex) {
3028
3091
  for (let i = 0; i < lines.length; ) {
3029
3092
  let text = lines[i].text;
3030
3093
  const items = [...lines[i].items];
3094
+ const srcLines = [lines[i].items];
3031
3095
  for (; i + 1 < lines.length && joins[i] !== "\n"; i++) {
3032
3096
  text += joins[i] + lines[i + 1].text;
3033
3097
  items.push(...lines[i + 1].items);
3098
+ srcLines.push(lines[i + 1].items);
3034
3099
  }
3100
+ text = tagScripts(text, srcLines.map((l) => sortLineByX([...l])));
3035
3101
  const block = { type: "paragraph", text, pageNumber: pageNum, bbox: computeBBox(items, pageNum), style: dominantStyle(items) };
3036
3102
  const faces = /* @__PURE__ */ new Map();
3037
3103
  for (const it of items) faces.set(it.fontName, (_nullishCoalesce(faces.get(it.fontName), () => ( 0))) + it.text.length);
@@ -3065,9 +3131,9 @@ function detectHeadings(blocks, medianFontSize) {
3065
3131
  if (/^\d+$/.test(text) && !isChapterNumber(block, blocks[bi + 1], medianFontSize)) continue;
3066
3132
  const ratio = block.style.fontSize / medianFontSize;
3067
3133
  let level = 0;
3068
- if (ratio >= _chunkDO74GYSMcjs.HEADING_RATIO_H1) level = 1;
3069
- else if (ratio >= _chunkDO74GYSMcjs.HEADING_RATIO_H2) level = 2;
3070
- else if (ratio >= _chunkDO74GYSMcjs.HEADING_RATIO_H3) level = 3;
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;
3071
3137
  if (level > 0) {
3072
3138
  block.type = "heading";
3073
3139
  block.level = level;
@@ -3080,7 +3146,7 @@ function isChapterNumber(block, next, medianFontSize) {
3080
3146
  const nextSize = _nullishCoalesce(_optionalChain([next, 'optionalAccess', _76 => _76.style, 'optionalAccess', _77 => _77.fontSize]), () => ( 0));
3081
3147
  const text = _nullishCoalesce(_optionalChain([next, 'optionalAccess', _78 => _78.text, 'optionalAccess', _79 => _79.trim, 'call', _80 => _80()]), () => ( ""));
3082
3148
  const a = block.bbox, b = _optionalChain([next, 'optionalAccess', _81 => _81.bbox]);
3083
- 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 * _chunkDO74GYSMcjs.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;
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;
3084
3150
  }
3085
3151
  function mergeStackedHeadingLines(blocks, medianFontSize) {
3086
3152
  for (let i = 0; i < blocks.length - 1; ) {
@@ -5161,16 +5227,16 @@ function isProseSpread(items) {
5161
5227
  for (let i = 1; i < sorted.length; i++) {
5162
5228
  gaps.push(sorted[i].x - (sorted[i - 1].x + sorted[i - 1].w));
5163
5229
  }
5164
- const maxGap = _chunkYRRBA4HWcjs.safeMax.call(void 0, gaps);
5230
+ const maxGap = _chunkSTM3ORY7cjs.safeMax.call(void 0, gaps);
5165
5231
  const avgLen = items.reduce((s, i) => s + i.text.length, 0) / items.length;
5166
5232
  if (items.length >= 4 && maxGap < 40 && avgLen < 5) return true;
5167
- const minGap = _chunkYRRBA4HWcjs.safeMin.call(void 0, gaps);
5233
+ const minGap = _chunkSTM3ORY7cjs.safeMin.call(void 0, gaps);
5168
5234
  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;
5169
5235
  }
5170
5236
  function detectColumns(yLines) {
5171
5237
  const allItems = yLines.flat();
5172
5238
  if (allItems.length === 0) return null;
5173
- const pageWidth = _chunkYRRBA4HWcjs.safeMax.call(void 0, allItems.map((i) => i.x + i.w)) - _chunkYRRBA4HWcjs.safeMin.call(void 0, allItems.map((i) => i.x));
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));
5174
5240
  if (pageWidth < 100) return null;
5175
5241
  let bigoLineIdx = -1;
5176
5242
  for (let i = 0; i < yLines.length; i++) {
@@ -5893,17 +5959,23 @@ function splitTwoColumnProse(items, cutX) {
5893
5959
  if (last && Math.abs(last[0].y - c.y) <= 3) last.push(c);
5894
5960
  else crossLines.push([c]);
5895
5961
  }
5896
- const bandItem = (arr) => arr.filter((i) => {
5962
+ const scriptOf = (i, cl) => {
5963
+ const fs = cl[0].fontSize, dy = i.y - cl[0].y;
5964
+ if (i.fontSize > fs * 0.85 || dy > fs * 0.6 || dy < -fs * 0.35) return false;
5965
+ return cl.some((c) => c !== i && c.fontSize > fs * 0.85 && i.x - (c.x + c.w) <= fs * 0.35 && i.x - (c.x + c.w) >= -fs * 0.1);
5966
+ };
5967
+ const bandItem = (arr, fits) => arr.filter((i) => {
5897
5968
  for (const cl of crossLines) {
5898
- if (Math.abs(cl[0].y - i.y) <= 3) {
5969
+ if (fits(i, cl)) {
5899
5970
  cl.push(i);
5900
5971
  return false;
5901
5972
  }
5902
5973
  }
5903
5974
  return true;
5904
5975
  });
5905
- const leftRest = bandItem(left);
5906
- const rightRest = bandItem(right);
5976
+ const sameY = (i, cl) => Math.abs(cl[0].y - i.y) <= 3;
5977
+ const leftRest = bandItem(bandItem(left, sameY), scriptOf);
5978
+ const rightRest = bandItem(bandItem(right, sameY), scriptOf);
5907
5979
  const boundYs = crossLines.map((cl) => cl[0].y);
5908
5980
  const bandOf = (y) => {
5909
5981
  let k = 0;
@@ -5915,7 +5987,7 @@ function splitTwoColumnProse(items, cutX) {
5915
5987
  const L = leftRest.filter((i) => bandOf(i.y) === k);
5916
5988
  const R = rightRest.filter((i) => bandOf(i.y) === k);
5917
5989
  groups.push(...columnPair(L, R));
5918
- if (k < crossLines.length) groups.push(crossLines[k]);
5990
+ if (k < crossLines.length) groups.push(crossLines[k].sort((a, b) => b.y - a.y || a.x - b.x));
5919
5991
  }
5920
5992
  return groups;
5921
5993
  }
@@ -6691,7 +6763,7 @@ function extractBlocksWithGrids(items, pageNum, pageWidth, pageHeight, grids, ho
6691
6763
  if (gutterX !== null) {
6692
6764
  const gx = gutterX;
6693
6765
  const allY = remaining.map((i) => i.y);
6694
- const pageH = _chunkYRRBA4HWcjs.safeMax.call(void 0, allY) - _chunkYRRBA4HWcjs.safeMin.call(void 0, allY);
6766
+ const pageH = _chunkSTM3ORY7cjs.safeMax.call(void 0, allY) - _chunkSTM3ORY7cjs.safeMin.call(void 0, allY);
6695
6767
  const gapThreshold = Math.max(15, pageH * 0.03);
6696
6768
  const sides = [
6697
6769
  remaining.filter((i) => i.x + i.w <= gx),
@@ -6711,7 +6783,7 @@ function extractBlocksWithGrids(items, pageNum, pageWidth, pageHeight, grids, ho
6711
6783
  finalTextBlocks = detectListBlocks(textBlocks);
6712
6784
  } else {
6713
6785
  const allY = remaining.map((i) => i.y);
6714
- const pageH = _chunkYRRBA4HWcjs.safeMax.call(void 0, allY) - _chunkYRRBA4HWcjs.safeMin.call(void 0, allY);
6786
+ const pageH = _chunkSTM3ORY7cjs.safeMax.call(void 0, allY) - _chunkSTM3ORY7cjs.safeMin.call(void 0, allY);
6715
6787
  const groups = xyCutOrder(remaining, Math.max(15, pageH * 0.03));
6716
6788
  const textBlocks = [];
6717
6789
  for (const group of groups) {
@@ -7025,7 +7097,7 @@ function extractPageBlocksFallback(items, pageNum, fullPage = false, detectTable
7025
7097
  blocks.push(...columnTextToBlocks(tableText, pageNum, bbox, dominantStyle(items)));
7026
7098
  } else {
7027
7099
  const allY = items.map((i) => i.y);
7028
- const pageHeight = _chunkYRRBA4HWcjs.safeMax.call(void 0, allY) - _chunkYRRBA4HWcjs.safeMin.call(void 0, allY);
7100
+ const pageHeight = _chunkSTM3ORY7cjs.safeMax.call(void 0, allY) - _chunkSTM3ORY7cjs.safeMin.call(void 0, allY);
7029
7101
  const gapThreshold = Math.max(15, pageHeight * 0.03);
7030
7102
  const orderedGroups = proseCutX !== null ? splitTwoColumnProse(items, proseCutX) : xyCutOrder(items, gapThreshold);
7031
7103
  for (const group of orderedGroups) {
@@ -7087,4 +7159,4 @@ function extractPageBlocksFallback(items, pageNum, fullPage = false, detectTable
7087
7159
 
7088
7160
 
7089
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;
7090
- //# sourceMappingURL=chunk-7IRHSRPU.cjs.map
7162
+ //# sourceMappingURL=chunk-WDQTFAXY.cjs.map