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
@@ -2,7 +2,7 @@
2
2
  import {
3
3
  KordocError,
4
4
  OPTIONAL_DEP_INSTALL_HINT
5
- } from "./chunk-3VLVNKJV.js";
5
+ } from "./chunk-P6ZDXTV6.js";
6
6
 
7
7
  // src/render/rasterize.ts
8
8
  var densityExponent = null;
@@ -88,4 +88,4 @@ export {
88
88
  rasterizeSvg,
89
89
  rasterizePageSvg
90
90
  };
91
- //# sourceMappingURL=chunk-24N4IJ5I.js.map
91
+ //# sourceMappingURL=chunk-S2PL227Q.js.map
@@ -1,86 +1,14 @@
1
+ #!/usr/bin/env node
1
2
  import {
2
3
  HEADING_RATIO_H1,
3
4
  HEADING_RATIO_H2,
4
- HEADING_RATIO_H3
5
- } from "./chunk-KBAQLAEL.js";
6
- import {
7
- ensureModelsIn,
8
- getModelsDir
9
- } from "./chunk-N65ZXWNQ.js";
5
+ HEADING_RATIO_H3,
6
+ tidyScriptTags
7
+ } from "./chunk-J3IF6KGW.js";
10
8
  import {
11
9
  safeMax,
12
10
  safeMin
13
- } from "./chunk-NUPXPKIQ.js";
14
-
15
- // src/ocr/models.ts
16
- import { join } from "path";
17
- import { stat } from "fs/promises";
18
- var OCR_DET_MODEL = {
19
- name: "PP-OCRv5 mobile det",
20
- filename: "det.onnx",
21
- url: "https://huggingface.co/PaddlePaddle/PP-OCRv5_mobile_det_onnx/resolve/main/inference.onnx",
22
- sha256: "a431985659dc921974177a95adcfbb90fd9e51989a5e04d70d0b75f597b6e61d",
23
- sizeMb: 5
24
- };
25
- var OCR_REC_MODEL = {
26
- name: "PP-OCRv5 korean rec",
27
- filename: "rec_korean.onnx",
28
- url: "https://huggingface.co/PaddlePaddle/korean_PP-OCRv5_mobile_rec_onnx/resolve/main/inference.onnx",
29
- sha256: "92f0b7785e64fc9090106a241cf4c1eb97472824558272751b88a2a4476d3a08",
30
- sizeMb: 13
31
- };
32
- var OCR_REC_DICT = {
33
- name: "PP-OCRv5 korean dict",
34
- filename: "rec_korean.yml",
35
- url: "https://huggingface.co/PaddlePaddle/korean_PP-OCRv5_mobile_rec_onnx/resolve/main/inference.yml",
36
- sha256: "f757fa1c40e99edcf27e9cce879b93eb2a51fa46f5ef39095689b8c37dd75998",
37
- sizeMb: 1
38
- };
39
- var ALL_OCR_MODELS = [OCR_DET_MODEL, OCR_REC_MODEL, OCR_REC_DICT];
40
- function getOcrModelsDir() {
41
- return getModelsDir("ppocr");
42
- }
43
- async function ensureOcrModels(onProgress) {
44
- return ensureModelsIn(getOcrModelsDir(), ALL_OCR_MODELS, onProgress);
45
- }
46
- async function ocrModelsCached() {
47
- const dir = getOcrModelsDir();
48
- for (const spec of ALL_OCR_MODELS) {
49
- try {
50
- if (!(await stat(join(dir, spec.filename))).size) return false;
51
- } catch {
52
- return false;
53
- }
54
- }
55
- return true;
56
- }
57
- function parseCharacterDict(yml) {
58
- const lines = yml.split("\n");
59
- const chars = [];
60
- let inDict = false;
61
- let dictIndent = -1;
62
- for (const line of lines) {
63
- if (!inDict) {
64
- const m2 = /^(\s*)character_dict:\s*$/.exec(line);
65
- if (m2) {
66
- inDict = true;
67
- dictIndent = m2[1].length;
68
- }
69
- continue;
70
- }
71
- const m = /^(\s*)- (.*)$/.exec(line);
72
- if (m && m[1].length >= dictIndent) {
73
- let v = m[2];
74
- if (v.length >= 2 && (v.startsWith("'") && v.endsWith("'") || v.startsWith('"') && v.endsWith('"'))) {
75
- v = v.slice(1, -1).replace(/''/g, "'");
76
- }
77
- chars.push(v);
78
- continue;
79
- }
80
- if (line.trim() !== "") break;
81
- }
82
- return chars;
83
- }
11
+ } from "./chunk-P6ZDXTV6.js";
84
12
 
85
13
  // src/pdf/line-extract.ts
86
14
  import { OPS } from "pdfjs-dist/legacy/build/pdf.mjs";
@@ -1927,6 +1855,60 @@ function hasHorizontalLine(horizontals, y, leftX, rightX, vertexRadius) {
1927
1855
  return false;
1928
1856
  }
1929
1857
 
1858
+ // src/pdf/script-items.ts
1859
+ function scriptKindsOfLine(sorted) {
1860
+ const kinds = sorted.map(() => null);
1861
+ if (sorted.length < 2) return kinds;
1862
+ const weight = /* @__PURE__ */ new Map();
1863
+ for (const it of sorted) {
1864
+ const k = Math.round(it.fontSize * 2) / 2;
1865
+ weight.set(k, (weight.get(k) ?? 0) + it.text.trim().length);
1866
+ }
1867
+ let bodyFs = 0, best = -1;
1868
+ for (const [fs, n] of weight) if (n > best || n === best && fs > bodyFs) {
1869
+ best = n;
1870
+ bodyFs = fs;
1871
+ }
1872
+ if (bodyFs <= 0) return kinds;
1873
+ const ys = sorted.filter((it) => Math.abs(it.fontSize - bodyFs) <= bodyFs * 0.12).map((it) => it.y).sort((a, b) => a - b);
1874
+ const bodyY = ys[ys.length >> 1];
1875
+ const isBody = (it) => it.fontSize > bodyFs * 0.85;
1876
+ for (let i = 1; i < sorted.length; i++) {
1877
+ const it = sorted[i], prev = sorted[i - 1];
1878
+ const t = it.text.trim();
1879
+ if (!t || t.length > 16 || isBody(it)) continue;
1880
+ if (!isBody(prev) && !kinds[i - 1]) continue;
1881
+ const gap = it.x - (prev.x + prev.w);
1882
+ if (gap > bodyFs * 0.35 || gap < -bodyFs * 0.5) continue;
1883
+ const dy = it.y - bodyY;
1884
+ if (dy >= bodyFs * 0.15) kinds[i] = "sup";
1885
+ else if (dy <= -bodyFs * 0.08) kinds[i] = "sub";
1886
+ }
1887
+ return kinds;
1888
+ }
1889
+ function tagScripts(text, lines) {
1890
+ const marks = [];
1891
+ let cursor = 0;
1892
+ for (const line of lines) {
1893
+ const kinds = scriptKindsOfLine(line);
1894
+ for (let k = 0; k < line.length; k++) {
1895
+ const t = line[k].text;
1896
+ if (!t) continue;
1897
+ const at = text.indexOf(t, cursor);
1898
+ if (at < 0 || /\S/.test(text.slice(cursor, at))) return text;
1899
+ if (kinds[k]) marks.push([at, at + t.length, kinds[k]]);
1900
+ cursor = at + t.length;
1901
+ }
1902
+ }
1903
+ if (!marks.length) return text;
1904
+ let out = text;
1905
+ for (let m = marks.length - 1; m >= 0; m--) {
1906
+ const [s, e, kind] = marks[m];
1907
+ out = out.slice(0, s) + `<${kind}>` + out.slice(s, e) + `</${kind}>` + out.slice(e);
1908
+ }
1909
+ return tidyScriptTags(out);
1910
+ }
1911
+
1930
1912
  // src/pdf/line-wrap.ts
1931
1913
  var MARKUP = /<\/?u>|~~/g;
1932
1914
  var bump = (m, k) => {
@@ -2258,7 +2240,8 @@ function cellTextToString(items, wrap) {
2258
2240
  }
2259
2241
  return result;
2260
2242
  });
2261
- if (!wrap) return mergeCellTextLines(textLines);
2243
+ const scripted = (s) => tagScripts(s, merged.map((l) => sortLineByX([...l])));
2244
+ if (!wrap) return scripted(mergeCellTextLines(textLines));
2262
2245
  let contentLeft = Infinity;
2263
2246
  for (const it of items) if (it.x < contentLeft) contentLeft = it.x;
2264
2247
  const lineEnds = merged.map((line) => {
@@ -2271,7 +2254,7 @@ function cellTextToString(items, wrap) {
2271
2254
  let cellRight = -Infinity;
2272
2255
  for (const e of lineEnds) if (e.right > cellRight) cellRight = e.right;
2273
2256
  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 });
2257
+ return scripted(mergeCellTextLines(textLines, { wraps, lex: wrap.lex }));
2275
2258
  }
2276
2259
  function mergeSuperscriptRows(lines) {
2277
2260
  if (lines.length <= 1) return lines;
@@ -2822,6 +2805,13 @@ function mergeSuperscriptLines(lines) {
2822
2805
  for (const i of line) total += i.text.trim().length;
2823
2806
  return total > 0 && total <= 10;
2824
2807
  };
2808
+ const isMarkers = (line, host) => line.length > 1 && line.length <= 16 && line.every((i) => {
2809
+ if (i.text.trim().length > 3 || !i.text.trim()) return false;
2810
+ return host.some((h) => {
2811
+ const g = i.x - (h.x + h.w);
2812
+ return g <= h.fontSize * 0.35 && g >= -h.fontSize * 0.1;
2813
+ });
2814
+ });
2825
2815
  const result = [lines[0]];
2826
2816
  for (let i = 1; i < lines.length; i++) {
2827
2817
  const prev = result[result.length - 1];
@@ -2829,8 +2819,8 @@ function mergeSuperscriptLines(lines) {
2829
2819
  const a = band(prev);
2830
2820
  const b = band(curr);
2831
2821
  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;
2822
+ const prevIsFrag = (isFrag(prev) || isMarkers(prev, curr)) && a.height <= b.height * 0.8 && overlap2 >= a.height * 0.5;
2823
+ const currIsFrag = (isFrag(curr) || isMarkers(curr, prev)) && b.height <= a.height * 0.8 && overlap2 >= b.height * 0.5;
2834
2824
  if (prevIsFrag || currIsFrag) {
2835
2825
  result[result.length - 1] = [...prev, ...curr];
2836
2826
  } else {
@@ -3028,10 +3018,13 @@ function pushLineParagraphs(out, yLines, pageNum, lex) {
3028
3018
  for (let i = 0; i < lines.length; ) {
3029
3019
  let text = lines[i].text;
3030
3020
  const items = [...lines[i].items];
3021
+ const srcLines = [lines[i].items];
3031
3022
  for (; i + 1 < lines.length && joins[i] !== "\n"; i++) {
3032
3023
  text += joins[i] + lines[i + 1].text;
3033
3024
  items.push(...lines[i + 1].items);
3025
+ srcLines.push(lines[i + 1].items);
3034
3026
  }
3027
+ text = tagScripts(text, srcLines.map((l) => sortLineByX([...l])));
3035
3028
  const block = { type: "paragraph", text, pageNumber: pageNum, bbox: computeBBox(items, pageNum), style: dominantStyle(items) };
3036
3029
  const faces = /* @__PURE__ */ new Map();
3037
3030
  for (const it of items) faces.set(it.fontName, (faces.get(it.fontName) ?? 0) + it.text.length);
@@ -5893,17 +5886,23 @@ function splitTwoColumnProse(items, cutX) {
5893
5886
  if (last && Math.abs(last[0].y - c.y) <= 3) last.push(c);
5894
5887
  else crossLines.push([c]);
5895
5888
  }
5896
- const bandItem = (arr) => arr.filter((i) => {
5889
+ const scriptOf = (i, cl) => {
5890
+ const fs = cl[0].fontSize, dy = i.y - cl[0].y;
5891
+ if (i.fontSize > fs * 0.85 || dy > fs * 0.6 || dy < -fs * 0.35) return false;
5892
+ 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);
5893
+ };
5894
+ const bandItem = (arr, fits) => arr.filter((i) => {
5897
5895
  for (const cl of crossLines) {
5898
- if (Math.abs(cl[0].y - i.y) <= 3) {
5896
+ if (fits(i, cl)) {
5899
5897
  cl.push(i);
5900
5898
  return false;
5901
5899
  }
5902
5900
  }
5903
5901
  return true;
5904
5902
  });
5905
- const leftRest = bandItem(left);
5906
- const rightRest = bandItem(right);
5903
+ const sameY = (i, cl) => Math.abs(cl[0].y - i.y) <= 3;
5904
+ const leftRest = bandItem(bandItem(left, sameY), scriptOf);
5905
+ const rightRest = bandItem(bandItem(right, sameY), scriptOf);
5907
5906
  const boundYs = crossLines.map((cl) => cl[0].y);
5908
5907
  const bandOf = (y) => {
5909
5908
  let k = 0;
@@ -5915,7 +5914,7 @@ function splitTwoColumnProse(items, cutX) {
5915
5914
  const L = leftRest.filter((i) => bandOf(i.y) === k);
5916
5915
  const R = rightRest.filter((i) => bandOf(i.y) === k);
5917
5916
  groups.push(...columnPair(L, R));
5918
- if (k < crossLines.length) groups.push(crossLines[k]);
5917
+ if (k < crossLines.length) groups.push(crossLines[k].sort((a, b) => b.y - a.y || a.x - b.x));
5919
5918
  }
5920
5919
  return groups;
5921
5920
  }
@@ -7046,13 +7045,6 @@ function extractPageBlocksFallback(items, pageNum, fullPage = false, detectTable
7046
7045
  }
7047
7046
 
7048
7047
  export {
7049
- OCR_DET_MODEL,
7050
- OCR_REC_MODEL,
7051
- OCR_REC_DICT,
7052
- getOcrModelsDir,
7053
- ensureOcrModels,
7054
- ocrModelsCached,
7055
- parseCharacterDict,
7056
7048
  extractLines,
7057
7049
  extractImageRegions,
7058
7050
  filterHiddenText,
@@ -7087,4 +7079,4 @@ export {
7087
7079
  trimTrailingEmptyTableCols,
7088
7080
  extractPageBlocksWithLines
7089
7081
  };
7090
- //# sourceMappingURL=chunk-PVMROO3A.js.map
7082
+ //# sourceMappingURL=chunk-SFEQYKYJ.js.map