kordoc 4.22.1 → 4.22.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.
- package/README.md +4 -1
- package/dist/{-FYKHW5G6.js → -C437ZARA.js} +11 -11
- package/dist/{chunk-5SVJU22Z.js → chunk-2X64TI7I.js} +2 -2
- package/dist/{chunk-JHHXTNZQ.js → chunk-3LJ6QO53.js} +28 -6
- package/dist/chunk-3LJ6QO53.js.map +1 -0
- package/dist/{chunk-TSZQ4LMV.js → chunk-4BJZGXNM.js} +2 -2
- package/dist/{chunk-3H5QG6I2.js → chunk-4GCS7WJJ.js} +2 -2
- package/dist/{chunk-7FASIFQP.js → chunk-56GBOIOE.js} +2 -2
- package/dist/{chunk-M2CBEXHN.cjs → chunk-AUWO57ED.cjs} +2 -2
- package/dist/{chunk-M2CBEXHN.cjs.map → chunk-AUWO57ED.cjs.map} +1 -1
- package/dist/{chunk-5FD3LAKC.js → chunk-AXR7OKQY.js} +2 -2
- package/dist/{chunk-IB5TO2CO.js → chunk-CNMUT5YW.js} +2 -2
- package/dist/{chunk-ATODI25J.js → chunk-DQXP3ELP.js} +2 -2
- package/dist/{chunk-OSFB5SQS.cjs → chunk-EKKZNKJD.cjs} +3 -3
- package/dist/{chunk-OSFB5SQS.cjs.map → chunk-EKKZNKJD.cjs.map} +1 -1
- package/dist/{chunk-EXVTF6XE.cjs → chunk-ENV25MPM.cjs} +24 -24
- package/dist/{chunk-EXVTF6XE.cjs.map → chunk-ENV25MPM.cjs.map} +1 -1
- package/dist/{chunk-YE4IN3D7.js → chunk-FPUBEM3F.js} +11 -11
- package/dist/{chunk-5VBAHUGC.js → chunk-GFQIKYBV.js} +3 -3
- package/dist/{chunk-MDS3GH43.js → chunk-GVBQVXXB.js} +2 -2
- package/dist/{chunk-ZECSXHYP.cjs → chunk-I4BS4BXE.cjs} +188 -166
- package/dist/{chunk-ZECSXHYP.cjs.map → chunk-I4BS4BXE.cjs.map} +1 -1
- package/dist/{chunk-7RND4SNB.js → chunk-IRP6QS3K.js} +3 -3
- package/dist/{chunk-R37TFXMP.js → chunk-L6N4OMKR.js} +60 -28
- package/dist/chunk-L6N4OMKR.js.map +1 -0
- package/dist/{chunk-IK4W2M4P.js → chunk-L6PFPBTK.js} +2 -2
- package/dist/{chunk-RO7AORMO.cjs → chunk-MED2MR6O.cjs} +6 -6
- package/dist/{chunk-RO7AORMO.cjs.map → chunk-MED2MR6O.cjs.map} +1 -1
- package/dist/{chunk-MGJYVNDX.js → chunk-NGDMJICC.js} +29 -7
- package/dist/{chunk-JHHXTNZQ.js.map → chunk-NGDMJICC.js.map} +1 -1
- package/dist/{chunk-SMPK5TUQ.js → chunk-QFJCEHY7.js} +2 -2
- package/dist/{chunk-M4JC7TXG.js → chunk-S4KQUVBV.js} +4 -4
- package/dist/{chunk-AIAIBNIB.js → chunk-U3TZVR7A.js} +2 -2
- package/dist/{chunk-QH4B3PL7.js → chunk-UMNKY2EZ.js} +4 -4
- package/dist/{chunk-DOBJ7BW5.js → chunk-UV2G6XFA.js} +2 -2
- package/dist/{chunk-LHO7E3RW.js → chunk-VUC4JJUM.js} +2 -2
- package/dist/{chunk-3SPOIAST.js → chunk-YOFKJ7IM.js} +2 -2
- package/dist/{chunk-ME4NQSLE.js → chunk-YTEMFVZB.js} +2 -2
- package/dist/{chunk-B35C5HJK.cjs → chunk-ZLFUZM7H.cjs} +3 -3
- package/dist/{chunk-B35C5HJK.cjs.map → chunk-ZLFUZM7H.cjs.map} +1 -1
- package/dist/chunks-MPOOHZVO.js +10 -0
- package/dist/cli.js +30 -30
- package/dist/{formula-PYDSQGLS.cjs → formula-3TVRNJ66.cjs} +9 -9
- package/dist/{formula-PYDSQGLS.cjs.map → formula-3TVRNJ66.cjs.map} +1 -1
- package/dist/{formula-JBTYYSKB.js → formula-43QBPAL5.js} +4 -4
- package/dist/{formula-RUS4SF3O.js → formula-HUENRCPJ.js} +3 -3
- package/dist/{image-ocr-VA6WV6E4.js → image-ocr-BAHDLDV5.js} +6 -6
- package/dist/{image-ocr-QJT4EIQU.js → image-ocr-HYAKWJGE.js} +9 -9
- package/dist/{image-ocr-PLNNCEOR.cjs → image-ocr-OC3TCXMV.cjs} +17 -17
- package/dist/{image-ocr-PLNNCEOR.cjs.map → image-ocr-OC3TCXMV.cjs.map} +1 -1
- package/dist/index.cjs +356 -324
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +60 -28
- package/dist/index.js.map +1 -1
- package/dist/mcp.js +22 -22
- package/dist/{model-bundle-U2YY7ATC.js → model-bundle-23WBSECG.js} +5 -5
- package/dist/{models-BOJ2SFCR.js → models-NRZQY45P.js} +5 -5
- package/dist/{parse-worker-v2-ZHMFK3U3.js → parse-worker-v2-DPNXGJ73.js} +12 -12
- package/dist/{parser-HM6N7J4R.js → parser-FNUQW2F3.js} +73 -27
- package/dist/parser-FNUQW2F3.js.map +1 -0
- package/dist/{parser-6337Z4U2.cjs → parser-OKAQRZKM.cjs} +318 -272
- package/dist/parser-OKAQRZKM.cjs.map +1 -0
- package/dist/{parser-A2EWLK2J.js → parser-XNOLC3MZ.js} +70 -24
- package/dist/parser-XNOLC3MZ.js.map +1 -0
- package/dist/pdf-ocr-6UXBIQE6.cjs +31 -0
- package/dist/{pdf-ocr-PGXNUFU7.cjs.map → pdf-ocr-6UXBIQE6.cjs.map} +1 -1
- package/dist/{pdf-ocr-JDER5BHI.js → pdf-ocr-FAGA3O6B.js} +6 -6
- package/dist/{pdf-ocr-MEVC6HXG.js → pdf-ocr-N5LYC5LA.js} +9 -9
- package/dist/{profile-io-OJ23SPYO.js → profile-io-HC6FMYX4.js} +3 -3
- package/dist/{rasterize-76CWCLSU.js → rasterize-QLTROEV2.js} +3 -3
- package/dist/{redact-doc-EZQIHRVT.js → redact-doc-V4KMM2QV.js} +11 -11
- package/dist/{render-JZFJPFWK.js → render-V4S3QLTR.js} +7 -7
- package/dist/seal-MQ5TB5YZ.js +10 -0
- package/dist/{setup-RIVS74JN.js → setup-HU7ZOQNM.js} +3 -3
- package/dist/visual-RLIFC4XC.js +21 -0
- package/dist/{watch-WMH222E5.js → watch-NPIZ6DSJ.js} +12 -12
- package/package.json +1 -1
- package/dist/chunk-MGJYVNDX.js.map +0 -1
- package/dist/chunk-R37TFXMP.js.map +0 -1
- package/dist/chunks-4XIAEJEX.js +0 -10
- package/dist/parser-6337Z4U2.cjs.map +0 -1
- package/dist/parser-A2EWLK2J.js.map +0 -1
- package/dist/parser-HM6N7J4R.js.map +0 -1
- package/dist/pdf-ocr-PGXNUFU7.cjs +0 -31
- package/dist/seal-P2NOP4LC.js +0 -10
- package/dist/visual-R5GGZBTU.js +0 -21
- /package/dist/{-FYKHW5G6.js.map → -C437ZARA.js.map} +0 -0
- /package/dist/{chunk-5SVJU22Z.js.map → chunk-2X64TI7I.js.map} +0 -0
- /package/dist/{chunk-TSZQ4LMV.js.map → chunk-4BJZGXNM.js.map} +0 -0
- /package/dist/{chunk-3H5QG6I2.js.map → chunk-4GCS7WJJ.js.map} +0 -0
- /package/dist/{chunk-7FASIFQP.js.map → chunk-56GBOIOE.js.map} +0 -0
- /package/dist/{chunk-5FD3LAKC.js.map → chunk-AXR7OKQY.js.map} +0 -0
- /package/dist/{chunk-IB5TO2CO.js.map → chunk-CNMUT5YW.js.map} +0 -0
- /package/dist/{chunk-ATODI25J.js.map → chunk-DQXP3ELP.js.map} +0 -0
- /package/dist/{chunk-YE4IN3D7.js.map → chunk-FPUBEM3F.js.map} +0 -0
- /package/dist/{chunk-5VBAHUGC.js.map → chunk-GFQIKYBV.js.map} +0 -0
- /package/dist/{chunk-MDS3GH43.js.map → chunk-GVBQVXXB.js.map} +0 -0
- /package/dist/{chunk-7RND4SNB.js.map → chunk-IRP6QS3K.js.map} +0 -0
- /package/dist/{chunk-IK4W2M4P.js.map → chunk-L6PFPBTK.js.map} +0 -0
- /package/dist/{chunk-SMPK5TUQ.js.map → chunk-QFJCEHY7.js.map} +0 -0
- /package/dist/{chunk-M4JC7TXG.js.map → chunk-S4KQUVBV.js.map} +0 -0
- /package/dist/{chunk-AIAIBNIB.js.map → chunk-U3TZVR7A.js.map} +0 -0
- /package/dist/{chunk-QH4B3PL7.js.map → chunk-UMNKY2EZ.js.map} +0 -0
- /package/dist/{chunk-DOBJ7BW5.js.map → chunk-UV2G6XFA.js.map} +0 -0
- /package/dist/{chunk-LHO7E3RW.js.map → chunk-VUC4JJUM.js.map} +0 -0
- /package/dist/{chunk-3SPOIAST.js.map → chunk-YOFKJ7IM.js.map} +0 -0
- /package/dist/{chunk-ME4NQSLE.js.map → chunk-YTEMFVZB.js.map} +0 -0
- /package/dist/{chunks-4XIAEJEX.js.map → chunks-MPOOHZVO.js.map} +0 -0
- /package/dist/{formula-JBTYYSKB.js.map → formula-43QBPAL5.js.map} +0 -0
- /package/dist/{formula-RUS4SF3O.js.map → formula-HUENRCPJ.js.map} +0 -0
- /package/dist/{image-ocr-VA6WV6E4.js.map → image-ocr-BAHDLDV5.js.map} +0 -0
- /package/dist/{image-ocr-QJT4EIQU.js.map → image-ocr-HYAKWJGE.js.map} +0 -0
- /package/dist/{model-bundle-U2YY7ATC.js.map → model-bundle-23WBSECG.js.map} +0 -0
- /package/dist/{models-BOJ2SFCR.js.map → models-NRZQY45P.js.map} +0 -0
- /package/dist/{parse-worker-v2-ZHMFK3U3.js.map → parse-worker-v2-DPNXGJ73.js.map} +0 -0
- /package/dist/{pdf-ocr-JDER5BHI.js.map → pdf-ocr-FAGA3O6B.js.map} +0 -0
- /package/dist/{pdf-ocr-MEVC6HXG.js.map → pdf-ocr-N5LYC5LA.js.map} +0 -0
- /package/dist/{profile-io-OJ23SPYO.js.map → profile-io-HC6FMYX4.js.map} +0 -0
- /package/dist/{rasterize-76CWCLSU.js.map → rasterize-QLTROEV2.js.map} +0 -0
- /package/dist/{redact-doc-EZQIHRVT.js.map → redact-doc-V4KMM2QV.js.map} +0 -0
- /package/dist/{render-JZFJPFWK.js.map → render-V4S3QLTR.js.map} +0 -0
- /package/dist/{seal-P2NOP4LC.js.map → seal-MQ5TB5YZ.js.map} +0 -0
- /package/dist/{setup-RIVS74JN.js.map → setup-HU7ZOQNM.js.map} +0 -0
- /package/dist/{visual-R5GGZBTU.js.map → visual-RLIFC4XC.js.map} +0 -0
- /package/dist/{watch-WMH222E5.js.map → watch-NPIZ6DSJ.js.map} +0 -0
|
@@ -4,15 +4,15 @@
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
var
|
|
7
|
+
var _chunkMED2MR6Ocjs = require('./chunk-MED2MR6O.cjs');
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
|
|
11
|
-
var
|
|
11
|
+
var _chunkZLFUZM7Hcjs = require('./chunk-ZLFUZM7H.cjs');
|
|
12
12
|
|
|
13
13
|
|
|
14
14
|
|
|
15
|
-
var
|
|
15
|
+
var _chunkAUWO57EDcjs = require('./chunk-AUWO57ED.cjs');
|
|
16
16
|
|
|
17
17
|
// src/ocr/models.ts
|
|
18
18
|
var _path = require('path');
|
|
@@ -48,7 +48,7 @@ var OCR_REC_DICT = {
|
|
|
48
48
|
sizeMb: 1
|
|
49
49
|
};
|
|
50
50
|
function getOcrModelsDir() {
|
|
51
|
-
return
|
|
51
|
+
return _chunkZLFUZM7Hcjs.getModelsDir.call(void 0, "ppocr");
|
|
52
52
|
}
|
|
53
53
|
var DEFAULT_OCR_MODELS = Object.freeze({
|
|
54
54
|
det: { spec: OCR_DET_MODEL },
|
|
@@ -90,7 +90,7 @@ async function ensureOcrModelsFor(sel, onProgress) {
|
|
|
90
90
|
if (!stamp || verifiedInProcess.get(path) !== stamp) todo.push(s.spec);
|
|
91
91
|
}
|
|
92
92
|
if (!todo.length) return;
|
|
93
|
-
await
|
|
93
|
+
await _chunkZLFUZM7Hcjs.ensureModelsIn.call(void 0, dir, todo, onProgress);
|
|
94
94
|
for (const spec of todo) {
|
|
95
95
|
const path = _path.join.call(void 0, dir, spec.filename), stamp = await fileStamp(path);
|
|
96
96
|
if (stamp) verifiedInProcess.set(path, stamp);
|
|
@@ -969,6 +969,28 @@ function bridgeSkippedRowVerticals(horizontals, verticals, items) {
|
|
|
969
969
|
// src/pdf/line-types.ts
|
|
970
970
|
var VERTEX_MERGE_FACTOR = 4;
|
|
971
971
|
|
|
972
|
+
// src/pdf/shaded-row-bands.ts
|
|
973
|
+
function hasShadedRowBands(host, clips, fills, verticals, horizontals) {
|
|
974
|
+
const tol = 1.5;
|
|
975
|
+
const near2 = (a, b) => Math.abs(a - b) <= tol;
|
|
976
|
+
const bands = clips.filter((c) => Math.min(c.bbox.x2, host.bbox.x2) > Math.max(c.bbox.x1, host.bbox.x1) && Math.min(c.bbox.y2, host.bbox.y2) > Math.max(c.bbox.y1, host.bbox.y1));
|
|
977
|
+
if (bands.length < 2 || host.colXs.length < 3) return false;
|
|
978
|
+
if (!host.colXs.slice(1, -1).every((x) => verticals.some((v) => !v.fromFill && near2(v.x1, x) && v.y1 <= host.bbox.y1 + tol && v.y2 >= host.bbox.y2 - tol))) return false;
|
|
979
|
+
const covered = /* @__PURE__ */ new Set();
|
|
980
|
+
for (const band of bands) {
|
|
981
|
+
if (band.clipParent || !_optionalChain([band, 'access', _17 => _17.cells, 'optionalAccess', _18 => _18.length]) || band.colXs.length !== host.colXs.length || !band.colXs.every((x, i) => near2(x, host.colXs[i]))) return false;
|
|
982
|
+
const start = host.rowYs.findIndex((y) => near2(y, band.rowYs[0]));
|
|
983
|
+
if (start < 0 || !band.rowYs.every((y, i) => near2(y, host.rowYs[start + i]))) return false;
|
|
984
|
+
if (!band.rowYs.every((y) => horizontals.some((h) => !h.fromFill && near2(h.y1, y) && h.x1 <= host.bbox.x1 + tol && h.x2 >= host.bbox.x2 - tol))) return false;
|
|
985
|
+
if (band.cells.length !== (band.rowYs.length - 1) * (band.colXs.length - 1) || !band.cells.every((cell) => !cell.filler && cell.rowSpan === 1 && cell.colSpan === 1 && near2(cell.bbox.x1, band.colXs[cell.col]) && near2(cell.bbox.x2, band.colXs[cell.col + 1]) && near2(cell.bbox.y2, band.rowYs[cell.row]) && near2(cell.bbox.y1, band.rowYs[cell.row + 1]) && fills.some((f) => near2(f.x1, cell.bbox.x1) && near2(f.x2, cell.bbox.x2) && near2(f.y1, cell.bbox.y1) && near2(f.y2, cell.bbox.y2)))) return false;
|
|
986
|
+
for (let i = 0; i < band.rowYs.length - 1; i++) {
|
|
987
|
+
if (covered.has(start + i)) return false;
|
|
988
|
+
covered.add(start + i);
|
|
989
|
+
}
|
|
990
|
+
}
|
|
991
|
+
return covered.size < host.rowYs.length - 1;
|
|
992
|
+
}
|
|
993
|
+
|
|
972
994
|
// src/pdf/table-grid.ts
|
|
973
995
|
var CONNECT_TOL = 5;
|
|
974
996
|
var MIN_COL_WIDTH = 15;
|
|
@@ -1058,7 +1080,7 @@ function mergeVertices(vertices) {
|
|
|
1058
1080
|
const candidates = [];
|
|
1059
1081
|
for (let dx = -1; dx <= 1; dx++) {
|
|
1060
1082
|
for (let dy = -1; dy <= 1; dy++) {
|
|
1061
|
-
const arr = _optionalChain([buckets, 'access',
|
|
1083
|
+
const arr = _optionalChain([buckets, 'access', _19 => _19.get, 'call', _20 => _20(cx + dx), 'optionalAccess', _21 => _21.get, 'call', _22 => _22(cy + dy)]);
|
|
1062
1084
|
if (!arr) continue;
|
|
1063
1085
|
for (const j of arr) {
|
|
1064
1086
|
if (j > i && !used[j]) candidates.push(j);
|
|
@@ -1179,13 +1201,13 @@ function buildTableGrids(horizontals, verticals, narrowRuns = true) {
|
|
|
1179
1201
|
}
|
|
1180
1202
|
var SHADE_CLIP_TOL = 1.5;
|
|
1181
1203
|
var SHADE_CLIP_MAX_AREA = 0.5;
|
|
1182
|
-
function dropShadingClipGrids(clipGrids, lineGrids, fillRects, verticals = []) {
|
|
1204
|
+
function dropShadingClipGrids(clipGrids, lineGrids, fillRects, verticals = [], horizontals = []) {
|
|
1183
1205
|
if (clipGrids.length === 0 || lineGrids.length === 0 || fillRects.length === 0) return clipGrids;
|
|
1184
1206
|
const near2 = (a, b) => Math.abs(a - b) <= SHADE_CLIP_TOL;
|
|
1185
1207
|
const area = (b) => Math.max(0, b.x2 - b.x1) * Math.max(0, b.y2 - b.y1);
|
|
1186
1208
|
const inter = (a, b) => area({ x1: Math.max(a.x1, b.x1), y1: Math.max(a.y1, b.y1), x2: Math.min(a.x2, b.x2), y2: Math.min(a.y2, b.y2) });
|
|
1187
1209
|
return clipGrids.filter((c) => {
|
|
1188
|
-
if (!_optionalChain([c, 'access',
|
|
1210
|
+
if (!_optionalChain([c, 'access', _23 => _23.cells, 'optionalAccess', _24 => _24.length]) || c.clipParent) return true;
|
|
1189
1211
|
const sourceCells = c.cells.filter((cell) => !cell.filler);
|
|
1190
1212
|
if (sourceCells.length === 0) return true;
|
|
1191
1213
|
const shaded = sourceCells.every((cell) => fillRects.some((f) => near2(f.x1, cell.bbox.x1) && near2(f.x2, cell.bbox.x2) && near2(f.y1, cell.bbox.y1) && near2(f.y2, cell.bbox.y2)));
|
|
@@ -1195,7 +1217,7 @@ function dropShadingClipGrids(clipGrids, lineGrids, fillRects, verticals = []) {
|
|
|
1195
1217
|
const host = lineGrids.find((l) => (
|
|
1196
1218
|
// Inferred filler cells carry no boundary evidence. Replace their frame only
|
|
1197
1219
|
// with a finer ruled grid of the same extent, never a larger surrounding form.
|
|
1198
|
-
(!c.cells.some((cell) => cell.filler) || near2(c.bbox.x1, l.bbox.x1) && near2(c.bbox.x2, l.bbox.x2) && near2(c.bbox.y1, l.bbox.y1) && near2(c.bbox.y2, l.bbox.y2) && l.rowYs.length > c.rowYs.length && sourceCells.every((cell) => [cell.bbox.y1, cell.bbox.y2].every((y) => l.rowYs.some((ly) => near2(y, ly))))) && c.bbox.x1 >= l.bbox.x1 - SHADE_CLIP_TOL && c.bbox.x2 <= l.bbox.x2 + SHADE_CLIP_TOL && c.bbox.y1 >= l.bbox.y1 - SHADE_CLIP_TOL && c.bbox.y2 <= l.bbox.y2 + SHADE_CLIP_TOL && c.colXs.every((x) => l.colXs.some((lx) => near2(lx, x))) && (clipGrids.reduce((s, o) => s + (_optionalChain([o, 'access',
|
|
1220
|
+
(!c.cells.some((cell) => cell.filler) || near2(c.bbox.x1, l.bbox.x1) && near2(c.bbox.x2, l.bbox.x2) && near2(c.bbox.y1, l.bbox.y1) && near2(c.bbox.y2, l.bbox.y2) && l.rowYs.length > c.rowYs.length && sourceCells.every((cell) => [cell.bbox.y1, cell.bbox.y2].every((y) => l.rowYs.some((ly) => near2(y, ly))))) && c.bbox.x1 >= l.bbox.x1 - SHADE_CLIP_TOL && c.bbox.x2 <= l.bbox.x2 + SHADE_CLIP_TOL && c.bbox.y1 >= l.bbox.y1 - SHADE_CLIP_TOL && c.bbox.y2 <= l.bbox.y2 + SHADE_CLIP_TOL && c.colXs.every((x) => l.colXs.some((lx) => near2(lx, x))) && (clipGrids.reduce((s, o) => s + (_optionalChain([o, 'access', _25 => _25.cells, 'optionalAccess', _26 => _26.some, 'call', _27 => _27((cell) => cell.filler)]) ? o.cells.filter((cell) => !cell.filler).reduce((a, cell) => a + inter(cell.bbox, l.bbox), 0) : inter(o.bbox, l.bbox)), 0) <= area(l.bbox) * SHADE_CLIP_MAX_AREA || l.rowYs.length === c.rowYs.length + 1 && c.rowYs.every((y, i) => near2(y, l.rowYs[i])) && l.colXs.length === c.colXs.length && c.colXs.every((x, i) => near2(x, l.colXs[i])) && !clipGrids.some((o) => o !== c && inter(o.bbox, l.bbox) > 0) || hasShadedRowBands(l, clipGrids, fillRects, verticals, horizontals))
|
|
1199
1221
|
));
|
|
1200
1222
|
return !host;
|
|
1201
1223
|
});
|
|
@@ -1210,7 +1232,7 @@ function dropHeadBandClipGrids(clipGrids, lineGrids) {
|
|
|
1210
1232
|
if (clipGrids.length === 0 || lineGrids.length === 0) return clipGrids;
|
|
1211
1233
|
const near2 = (a, b) => Math.abs(a - b) <= SHADE_CLIP_TOL;
|
|
1212
1234
|
const overlaps = (a, b) => Math.min(a.x2, b.x2) > Math.max(a.x1, b.x1) && Math.min(a.y2, b.y2) > Math.max(a.y1, b.y1);
|
|
1213
|
-
return clipGrids.filter((c) => c.clipParent || !_optionalChain([c, 'access',
|
|
1235
|
+
return clipGrids.filter((c) => c.clipParent || !_optionalChain([c, 'access', _28 => _28.cells, 'optionalAccess', _29 => _29.length]) || !lineGrids.some((l) => l.rowYs.length > c.rowYs.length && l.colXs.length === c.colXs.length && c.colXs.every((x, k) => near2(x, l.colXs[k])) && c.rowYs.every((y, k) => near2(y, l.rowYs[k])) && !clipGrids.some((o) => o !== c && overlaps(o.bbox, l.bbox))));
|
|
1214
1236
|
}
|
|
1215
1237
|
function enforceMinWidth(colXs, minWidth, narrowRuns = true) {
|
|
1216
1238
|
if (colXs.length <= 2) return colXs;
|
|
@@ -1561,7 +1583,7 @@ function buildClipCellGrids(rects, strokedH, strokedV, pageWidth, pageHeight, te
|
|
|
1561
1583
|
for (let dx = -1; dx <= 1 && !duplicate; dx++) {
|
|
1562
1584
|
const ys2 = buckets.get(bx + dx);
|
|
1563
1585
|
for (let dy = -1; dy <= 1 && !duplicate; dy++) {
|
|
1564
|
-
duplicate = _nullishCoalesce(_optionalChain([ys2, 'optionalAccess',
|
|
1586
|
+
duplicate = _nullishCoalesce(_optionalChain([ys2, 'optionalAccess', _30 => _30.get, 'call', _31 => _31(by + dy), 'optionalAccess', _32 => _32.some, 'call', _33 => _33((c) => sameRect(c, r))]), () => ( false));
|
|
1565
1587
|
}
|
|
1566
1588
|
}
|
|
1567
1589
|
if (duplicate) continue;
|
|
@@ -1709,7 +1731,7 @@ function buildClipCellGrids(rects, strokedH, strokedV, pageWidth, pageHeight, te
|
|
|
1709
1731
|
else groups.set(r, [i]);
|
|
1710
1732
|
}
|
|
1711
1733
|
const containers = cells.filter((_, i) => isContainer[i]);
|
|
1712
|
-
const groupSize = (i) => _nullishCoalesce(_optionalChain([groups, 'access',
|
|
1734
|
+
const groupSize = (i) => _nullishCoalesce(_optionalChain([groups, 'access', _34 => _34.get, 'call', _35 => _35(find(i)), 'optionalAccess', _36 => _36.length]), () => ( 0));
|
|
1713
1735
|
const isGridMember = (i) => groupSize(i) >= CLIP_MIN_GROUP;
|
|
1714
1736
|
const framed = (r) => edgeStroked(strokedH, "h", r.y1, r.x1, r.x2) && edgeStroked(strokedH, "h", r.y2, r.x1, r.x2) && edgeStroked(strokedV, "v", r.x1, r.y1, r.y2) && edgeStroked(strokedV, "v", r.x2, r.y1, r.y2);
|
|
1715
1737
|
const titledFrame = (r) => r.y1 >= pageHeight * TITLED_FRAME_MIN_TOP && r.x2 - r.x1 >= pageWidth * TITLED_FRAME_MIN_WIDTH && textPoints.some((p) => p.y < r.y1 && p.y > pageHeight * HEADER_BAND && p.x >= r.x1 - CLIP_EDGE_TOL && p.x <= r.x2 + CLIP_EDGE_TOL) && textPoints.some((p) => p.x > r.x1 && p.x < r.x2 && p.y > r.y1 && p.y < r.y2);
|
|
@@ -2087,8 +2109,8 @@ function childRules(r, grid) {
|
|
|
2087
2109
|
}
|
|
2088
2110
|
function recordClipCellEdges(grids, horizontals, verticals, nonRules) {
|
|
2089
2111
|
if (!grids.some((g) => g.cells)) return;
|
|
2090
|
-
const h = rules(_optionalChain([nonRules, 'optionalAccess',
|
|
2091
|
-
const v = rules(_optionalChain([nonRules, 'optionalAccess',
|
|
2112
|
+
const h = rules(_optionalChain([nonRules, 'optionalAccess', _37 => _37.size]) ? horizontals.filter((l) => !nonRules.has(l)) : horizontals, "h");
|
|
2113
|
+
const v = rules(_optionalChain([nonRules, 'optionalAccess', _38 => _38.size]) ? verticals.filter((l) => !nonRules.has(l)) : verticals, "v");
|
|
2092
2114
|
for (const g of grids) {
|
|
2093
2115
|
if (!g.cells) continue;
|
|
2094
2116
|
const ownH = childRules(h, g), ownV = childRules(v, g);
|
|
@@ -2104,9 +2126,9 @@ function recordOpenEndCellEdges(grid, cells, horizontals) {
|
|
|
2104
2126
|
const end = horizontals.find((l) => OPEN_END_RULES.has(l) && Math.abs(l.y1 - b.y1) <= EDGE_NEAR2 && Math.abs(l.x1 - b.x1) <= EDGE_NEAR2 && Math.abs(l.x2 - b.x2) <= EDGE_NEAR2);
|
|
2105
2127
|
const raw = end && OPEN_END_RULES.get(end);
|
|
2106
2128
|
if (!raw) return;
|
|
2107
|
-
const hs = raw.horizontals.filter((l) => !_optionalChain([raw, 'access',
|
|
2129
|
+
const hs = raw.horizontals.filter((l) => !_optionalChain([raw, 'access', _39 => _39.nonRules, 'optionalAccess', _40 => _40.has, 'call', _41 => _41(l)]));
|
|
2108
2130
|
if (hs.some((l) => Math.abs(l.y1 - b.y1) <= EDGE_NEAR2 && Math.min(l.x2, b.x2) - Math.max(l.x1, b.x1) > TIP_MAX)) return;
|
|
2109
|
-
const h = rules(hs, "h"), v = rules(raw.verticals.filter((l) => !_optionalChain([raw, 'access',
|
|
2131
|
+
const h = rules(hs, "h"), v = rules(raw.verticals.filter((l) => !_optionalChain([raw, 'access', _42 => _42.nonRules, 'optionalAccess', _43 => _43.has, 'call', _44 => _44(l)])), "v");
|
|
2110
2132
|
const edges = cells.map((c) => edgesOf(c.bbox, h, v));
|
|
2111
2133
|
const last = grid.rowYs.length - 2;
|
|
2112
2134
|
if (!cells.every((c, i) => {
|
|
@@ -2117,16 +2139,16 @@ function recordOpenEndCellEdges(grid, cells, horizontals) {
|
|
|
2117
2139
|
}
|
|
2118
2140
|
function takeClipCellEdges(from, to) {
|
|
2119
2141
|
const e = CLIP_CELL_EDGES.get(from);
|
|
2120
|
-
if (e)
|
|
2142
|
+
if (e) _chunkMED2MR6Ocjs.CELL_EDGES.set(to, e);
|
|
2121
2143
|
}
|
|
2122
2144
|
function hasOpenCellSeam(a, b) {
|
|
2123
|
-
const u =
|
|
2145
|
+
const u = _chunkMED2MR6Ocjs.CELL_EDGES.get(a), d = _chunkMED2MR6Ocjs.CELL_EDGES.get(b);
|
|
2124
2146
|
return !!u && !!d && u.t && !u.b && !d.t && d.b && u.l && u.r && d.l && d.r;
|
|
2125
2147
|
}
|
|
2126
2148
|
function joinCellEdges(a, b) {
|
|
2127
|
-
const u =
|
|
2149
|
+
const u = _chunkMED2MR6Ocjs.CELL_EDGES.get(a), d = _chunkMED2MR6Ocjs.CELL_EDGES.get(b);
|
|
2128
2150
|
if (!u || !d) return;
|
|
2129
|
-
|
|
2151
|
+
_chunkMED2MR6Ocjs.CELL_EDGES.set(a, { t: u.t, b: d.b, l: u.l || d.l, r: u.r || d.r });
|
|
2130
2152
|
}
|
|
2131
2153
|
|
|
2132
2154
|
// src/pdf/cell-extract.ts
|
|
@@ -2302,7 +2324,7 @@ function tagScripts(text, lines) {
|
|
|
2302
2324
|
const [s, e, kind] = marks[m];
|
|
2303
2325
|
out = out.slice(0, s) + `<${kind}>` + out.slice(s, e) + `</${kind}>` + out.slice(e);
|
|
2304
2326
|
}
|
|
2305
|
-
return
|
|
2327
|
+
return _chunkMED2MR6Ocjs.tidyScriptTags.call(void 0, out);
|
|
2306
2328
|
}
|
|
2307
2329
|
|
|
2308
2330
|
// src/pdf/line-wrap.ts
|
|
@@ -2338,12 +2360,12 @@ var WrapLexicon = (_class = class {constructor() { _class.prototype.__init.call(
|
|
|
2338
2360
|
const t = toks[i], n = t.length;
|
|
2339
2361
|
if (i > 0 && i < toks.length - 1) {
|
|
2340
2362
|
bump(this.words, t);
|
|
2341
|
-
const run = _nullishCoalesce(_optionalChain([t, 'access',
|
|
2363
|
+
const run = _nullishCoalesce(_optionalChain([t, 'access', _45 => _45.match, 'call', _46 => _46(/^[가-힣]+/), 'optionalAccess', _47 => _47[0]]), () => ( ""));
|
|
2342
2364
|
for (let j = 2; j <= Math.min(run.length, 6); j++) this.heads.add(run.slice(0, j));
|
|
2343
2365
|
}
|
|
2344
2366
|
if (i + 1 < toks.length) {
|
|
2345
2367
|
this.pairs.add(t + " " + toks[i + 1]);
|
|
2346
|
-
const tail = _optionalChain([t, 'access',
|
|
2368
|
+
const tail = _optionalChain([t, 'access', _48 => _48.match, 'call', _49 => _49(/[가-힣]+$/), 'optionalAccess', _50 => _50[0]]);
|
|
2347
2369
|
if (tail) this.spacedHeads.add(tail + " " + toks[i + 1].charAt(0));
|
|
2348
2370
|
}
|
|
2349
2371
|
for (let a = 0; a + 1 < n; a++) {
|
|
@@ -2380,14 +2402,14 @@ var WrapLexicon = (_class = class {constructor() { _class.prototype.__init.call(
|
|
|
2380
2402
|
const n = left.length;
|
|
2381
2403
|
if (n < 2 || right.length < 2) return null;
|
|
2382
2404
|
const k1 = pairKey(left.charCodeAt(n - 2), left.charCodeAt(n - 1)), k2 = pairKey(right.charCodeAt(0), right.charCodeAt(1));
|
|
2383
|
-
return decideCounts(_nullishCoalesce(_optionalChain([this, 'access',
|
|
2405
|
+
return decideCounts(_nullishCoalesce(_optionalChain([this, 'access', _51 => _51.joined2, 'access', _52 => _52.get, 'call', _53 => _53(k1), 'optionalAccess', _54 => _54.get, 'call', _55 => _55(k2)]), () => ( 0)), _nullishCoalesce(_optionalChain([this, 'access', _56 => _56.spaced2, 'access', _57 => _57.get, 'call', _58 => _58(k1), 'optionalAccess', _59 => _59.get, 'call', _60 => _60(k2)]), () => ( 0)));
|
|
2384
2406
|
}
|
|
2385
2407
|
/** 꺾인 자리 증거: "" 붙음 · " " 띄움 · null 모름 (두 글자 증거가 갈리거나 없으면 한 글자) */
|
|
2386
2408
|
evidence(left, right) {
|
|
2387
2409
|
const n = left.length;
|
|
2388
2410
|
if (n >= 2 && right.length >= 2) {
|
|
2389
2411
|
const k1 = pairKey(left.charCodeAt(n - 2), left.charCodeAt(n - 1)), k2 = pairKey(right.charCodeAt(0), right.charCodeAt(1));
|
|
2390
|
-
const v = decideCounts(_nullishCoalesce(_optionalChain([this, 'access',
|
|
2412
|
+
const v = decideCounts(_nullishCoalesce(_optionalChain([this, 'access', _61 => _61.joined2, 'access', _62 => _62.get, 'call', _63 => _63(k1), 'optionalAccess', _64 => _64.get, 'call', _65 => _65(k2)]), () => ( 0)), _nullishCoalesce(_optionalChain([this, 'access', _66 => _66.spaced2, 'access', _67 => _67.get, 'call', _68 => _68(k1), 'optionalAccess', _69 => _69.get, 'call', _70 => _70(k2)]), () => ( 0)));
|
|
2391
2413
|
if (v !== null) return v;
|
|
2392
2414
|
}
|
|
2393
2415
|
if (n && right.length) {
|
|
@@ -2462,11 +2484,11 @@ function wrapJoiner(prevText, nextText, lex, heads = true) {
|
|
|
2462
2484
|
if (particleContinues(left, right)) return "";
|
|
2463
2485
|
if (endsAsWord(left)) return " ";
|
|
2464
2486
|
if (/[A-Za-z]-$/.test(left) && /^[A-Za-z]/.test(right) && !/[가-힣]/.test(prev + next)) {
|
|
2465
|
-
return _optionalChain([lex, 'optionalAccess',
|
|
2487
|
+
return _optionalChain([lex, 'optionalAccess', _71 => _71.joinedWord, 'call', _72 => _72(left, right.replace(/[.,;:!?)]*$/, ""))]) ? "" : " ";
|
|
2466
2488
|
}
|
|
2467
2489
|
if (/[·ㆍ‧-]/.test(a) && !/[·ㆍ‧…]{2}$/.test(prev) && /[가-힣A-Za-z0-9]/.test(b)) return "";
|
|
2468
2490
|
if (/[A-Za-z]/.test(a) && /[A-Za-z]/.test(b) || /\d/.test(a) && /\d/.test(b)) return " ";
|
|
2469
|
-
const ev = _optionalChain([lex, 'optionalAccess',
|
|
2491
|
+
const ev = _optionalChain([lex, 'optionalAccess', _73 => _73.evidence, 'call', _74 => _74(left, right)]);
|
|
2470
2492
|
if (ev != null) return ev;
|
|
2471
2493
|
if (lex && /[가-힣A-Za-z0-9]$/.test(left) && /^[가-힣A-Za-z0-9]/.test(right) && lex.joinedWord(left, right.replace(/[.,)」』’”;:]+$/, ""))) return "";
|
|
2472
2494
|
if (/\d$/.test(left) && COUNTER.test(right)) return "";
|
|
@@ -2474,7 +2496,7 @@ function wrapJoiner(prevText, nextText, lex, heads = true) {
|
|
|
2474
2496
|
const r1 = right.replace(/[.,)」』’”]+$/, "");
|
|
2475
2497
|
if (lex && /[가-힣]$/.test(left) && /^[가-힣]$/.test(r1) && !STANDALONE_SYLLABLE.test(r1) && !lex.isWord(r1) && !lex.isWord(right)) return "";
|
|
2476
2498
|
if (lex && heads) {
|
|
2477
|
-
const tail = _optionalChain([left, 'access',
|
|
2499
|
+
const tail = _optionalChain([left, 'access', _75 => _75.match, 'call', _76 => _76(/[가-힣]+$/), 'optionalAccess', _77 => _77[0]]), run = _optionalChain([right, 'access', _78 => _78.match, 'call', _79 => _79(/^[가-힣]+/), 'optionalAccess', _80 => _80[0]]);
|
|
2478
2500
|
if (tail && run && !STANDALONE_SYLLABLE.test(tail) && lex.startsWord(tail + run.slice(0, 2)) && !lex.spacedHead(tail, run[0])) return "";
|
|
2479
2501
|
if (/[가-힣]{2}$/.test(left) && /^\([^()\s]*\)/.test(right) && !endsAsWord(left) && !/(?:함|음|됨|임|다)$/.test(left) && !BARE_UNIT_PAREN.test(right) && !/^\(\d/.test(right)) return "";
|
|
2480
2502
|
}
|
|
@@ -2509,14 +2531,14 @@ function joinPageBreakWraps(blocks, lex) {
|
|
|
2509
2531
|
if (a.type !== "paragraph" && a.type !== "list" || b.type !== "paragraph") continue;
|
|
2510
2532
|
const last = a.bbox && PARA_LAST_LINE.get(a.bbox), fs = last ? last.fontSize : 0;
|
|
2511
2533
|
if (!last || fs <= 0 || (_nullishCoalesce(pageRight.get(a.pageNumber), () => ( Infinity))) - last.right >= BODY_FULL_TOL * fs) continue;
|
|
2512
|
-
if (last.width < BODY_MIN_WIDTH_EM * fs || Math.abs((_nullishCoalesce(_optionalChain([b, 'access',
|
|
2534
|
+
if (last.width < BODY_MIN_WIDTH_EM * fs || Math.abs((_nullishCoalesce(_optionalChain([b, 'access', _81 => _81.style, 'optionalAccess', _82 => _82.fontSize]), () => ( 0))) - fs) > 0.15 * fs) continue;
|
|
2513
2535
|
const bt = b.text.replace(MARKUP, "");
|
|
2514
2536
|
if (startsNewItem(a.text, b.text) || PAGE_REF_TAIL.test(a.text) || PAGE_ITEM_HEAD.test(bt)) continue;
|
|
2515
2537
|
if (PAGE_HEAD_MARK.test(bt) && !(/^[\u25a0-\u25ff]/.test(bt) && a.text.includes(bt[0]))) continue;
|
|
2516
2538
|
const firstLeft = b.bbox && PARA_FIRST_LEFT.get(b.bbox);
|
|
2517
2539
|
const indented = firstLeft === void 0 || firstLeft - (_nullishCoalesce(pageLeft.get(b.pageNumber), () => ( firstLeft))) >= 0.3 * fs;
|
|
2518
2540
|
if (indented && SENTENCE_END.test(a.text.replace(MARKUP, "").trimEnd())) continue;
|
|
2519
|
-
if (Math.round(_nullishCoalesce(_optionalChain([b, 'access',
|
|
2541
|
+
if (Math.round(_nullishCoalesce(_optionalChain([b, 'access', _83 => _83.style, 'optionalAccess', _84 => _84.fontSize]), () => ( 0))) !== Math.round(fs) && titleLike(b.text)) continue;
|
|
2520
2542
|
if (/\t/.test(a.text.slice(a.text.lastIndexOf("\n") + 1).replace(/^\S{1,8}\t/, "")) && titleLike(bt.trim().split("\n")[0])) continue;
|
|
2521
2543
|
const joined = wrapJoiner(a.text, b.text, lex);
|
|
2522
2544
|
const head = a.text, joiner = joined === "" && last.spaceAfter ? " " : joined;
|
|
@@ -2565,7 +2587,7 @@ function bodyLineJoins(lines, lex) {
|
|
|
2565
2587
|
for (const l of lines) if (!HANGING.test(l.text) && l.right > inner) inner = l.right;
|
|
2566
2588
|
const full = (l) => right - l.right < BODY_FULL_TOL * l.fontSize || right - inner <= 1.2 * l.fontSize && inner - l.right < BODY_FULL_TOL * l.fontSize;
|
|
2567
2589
|
const nextWordNoRoom = (a, b) => {
|
|
2568
|
-
const w = _optionalChain([b, 'access',
|
|
2590
|
+
const w = _optionalChain([b, 'access', _85 => _85.text, 'access', _86 => _86.trim, 'call', _87 => _87(), 'access', _88 => _88.match, 'call', _89 => _89(/^\S+/), 'optionalAccess', _90 => _90[0]]);
|
|
2569
2591
|
const n = [...b.text.trim()].length;
|
|
2570
2592
|
if (!w || n === 0) return false;
|
|
2571
2593
|
const em = (b.right - b.left) / n;
|
|
@@ -2755,7 +2777,7 @@ function cellTextToString(items, wrap) {
|
|
|
2755
2777
|
const merged = mergeSuperscriptRows(lines).map((line) => sortLineByX(line));
|
|
2756
2778
|
const textLines = merged.map((s) => {
|
|
2757
2779
|
if (s.length === 1) return s[0].text;
|
|
2758
|
-
if (s.length === 2 && /^[가-힣]$/.test(s[0].text) && /^[가-힣]$/.test(s[1].text) && !!_optionalChain([wrap, 'optionalAccess',
|
|
2780
|
+
if (s.length === 2 && /^[가-힣]$/.test(s[0].text) && /^[가-힣]$/.test(s[1].text) && !!_optionalChain([wrap, 'optionalAccess', _91 => _91.lex]) && (wrap.lex.isWord(s[0].text + s[1].text) || wrap.lex.evidence(s[0].text, s[1].text) === "" || REGION_LABELS.has(s[0].text + s[1].text)) && s[1].x - (s[0].x + s[0].w) >= Math.max(s[0].fontSize, s[1].fontSize) * 1.5 && s[1].x + s[1].w - s[0].x >= wrap.box.x2 - wrap.box.x1 - Math.max(s[0].fontSize, s[1].fontSize) * 2) return s[0].text + s[1].text;
|
|
2759
2781
|
const evenSpaced = detectEvenSpacedItems(s, true);
|
|
2760
2782
|
let result = s[0].text;
|
|
2761
2783
|
for (let j = 1; j < s.length; j++) {
|
|
@@ -2900,12 +2922,12 @@ function markEvenRun(items, visible, result, start, end) {
|
|
|
2900
2922
|
}
|
|
2901
2923
|
function mergeCellTextLines(textLines, wrap) {
|
|
2902
2924
|
if (textLines.length <= 1) return textLines[0] || "";
|
|
2903
|
-
const numberWrapped = (k) => !!_optionalChain([wrap, 'optionalAccess',
|
|
2925
|
+
const numberWrapped = (k) => !!_optionalChain([wrap, 'optionalAccess', _92 => _92.wraps, 'access', _93 => _93[k]]) && (_nullishCoalesce(_optionalChain([wrap, 'access', _94 => _94.wide, 'optionalAccess', _95 => _95[k]]), () => ( true)));
|
|
2904
2926
|
const merged = [textLines[0]];
|
|
2905
2927
|
for (let i = 1; i < textLines.length; i++) {
|
|
2906
2928
|
const prev = merged[merged.length - 1];
|
|
2907
2929
|
const curr = textLines[i];
|
|
2908
|
-
if (wrap ? wrap.wraps[i - 1] && !_optionalChain([wrap, 'access',
|
|
2930
|
+
if (wrap ? wrap.wraps[i - 1] && !_optionalChain([wrap, 'access', _96 => _96.spaced, 'optionalAccess', _97 => _97[i - 1]]) && !startsNewItem(prev, curr) && wrapJoiner(prev, curr, wrap.lex, false) === "" : /[가-힣]$/.test(prev) && /^[가-힣]+$/.test(curr) && curr.length <= 8 && !curr.includes(" ")) {
|
|
2909
2931
|
merged[merged.length - 1] = prev + curr;
|
|
2910
2932
|
} else if (curr.trim().length <= 3 && /^[)\]%}]/.test(curr.trim())) {
|
|
2911
2933
|
merged[merged.length - 1] = prev + curr.trim();
|
|
@@ -2983,7 +3005,7 @@ function normalizeUndersegmentedTable(originalCells, colXs, items, rowYs) {
|
|
|
2983
3005
|
if (numRows > MAX_UNDERSEGMENTED_ROWS || numCols < MIN_UNDERSEGMENTED_COLUMNS) return null;
|
|
2984
3006
|
if (items.length === 0) return null;
|
|
2985
3007
|
if (numRows >= 3) {
|
|
2986
|
-
if (_optionalChain([rowYs, 'optionalAccess',
|
|
3008
|
+
if (_optionalChain([rowYs, 'optionalAccess', _98 => _98.length]) !== numRows + 1) return null;
|
|
2987
3009
|
const rebuilt2 = [];
|
|
2988
3010
|
let expanded = 0;
|
|
2989
3011
|
for (let r = 0; r < numRows; r++) {
|
|
@@ -3136,7 +3158,7 @@ function dominantStyle(items) {
|
|
|
3136
3158
|
let maxCount = 0, dominantSize = 0;
|
|
3137
3159
|
for (const i of items) {
|
|
3138
3160
|
if (i.fontSize <= 0) continue;
|
|
3139
|
-
const count = (freq.get(i.fontSize) || 0) + Math.max(1, _nullishCoalesce(_optionalChain([i, 'access',
|
|
3161
|
+
const count = (freq.get(i.fontSize) || 0) + Math.max(1, _nullishCoalesce(_optionalChain([i, 'access', _99 => _99.text, 'access', _100 => _100.match, 'call', _101 => _101(/[\p{L}\p{N}]/gu), 'optionalAccess', _102 => _102.length]), () => ( 0)));
|
|
3140
3162
|
freq.set(i.fontSize, count);
|
|
3141
3163
|
if (count > maxCount) {
|
|
3142
3164
|
maxCount = count;
|
|
@@ -3144,7 +3166,7 @@ function dominantStyle(items) {
|
|
|
3144
3166
|
}
|
|
3145
3167
|
}
|
|
3146
3168
|
if (dominantSize === 0) return void 0;
|
|
3147
|
-
const fontName = _optionalChain([items, 'access',
|
|
3169
|
+
const fontName = _optionalChain([items, 'access', _103 => _103.find, 'call', _104 => _104((i) => i.fontSize === dominantSize), 'optionalAccess', _105 => _105.fontName]) || void 0;
|
|
3148
3170
|
return fontName ? { fontSize: dominantSize, fontName } : { fontSize: dominantSize };
|
|
3149
3171
|
}
|
|
3150
3172
|
function normalizeItems(rawItems) {
|
|
@@ -3289,7 +3311,7 @@ function splitAroundOverlays(c, overlays) {
|
|
|
3289
3311
|
const ov = overlays.filter((o) => {
|
|
3290
3312
|
for (let at = c.text.indexOf(o.text); at >= 0; at = c.text.indexOf(o.text, at + 1)) {
|
|
3291
3313
|
const prefix = c.text.slice(0, at);
|
|
3292
|
-
const est = c.x + glyphUnits(prefix.replace(/\s+/g, "")) * a0 + (_nullishCoalesce(_optionalChain([prefix, 'access',
|
|
3314
|
+
const est = c.x + glyphUnits(prefix.replace(/\s+/g, "")) * a0 + (_nullishCoalesce(_optionalChain([prefix, 'access', _106 => _106.match, 'call', _107 => _107(/\s+/g), 'optionalAccess', _108 => _108.length]), () => ( 0))) * ws;
|
|
3293
3315
|
if (Math.abs(est - o.x) <= OVERLAY_DUP_EM * fs) return false;
|
|
3294
3316
|
}
|
|
3295
3317
|
return true;
|
|
@@ -3414,7 +3436,7 @@ function mergeSuperscriptLines(lines) {
|
|
|
3414
3436
|
return result;
|
|
3415
3437
|
}
|
|
3416
3438
|
function mergeLineSimple(items) {
|
|
3417
|
-
if (items.length <= 1) return _optionalChain([items, 'access',
|
|
3439
|
+
if (items.length <= 1) return _optionalChain([items, 'access', _109 => _109[0], 'optionalAccess', _110 => _110.text]) || "";
|
|
3418
3440
|
const sorted = sortLineByX([...items]);
|
|
3419
3441
|
const isEvenSpaced = detectEvenSpacedItems(sorted);
|
|
3420
3442
|
let result = sorted[0].text;
|
|
@@ -3502,7 +3524,7 @@ function isProseTable(table) {
|
|
|
3502
3524
|
if (!(long > 0 && long >= total * 0.5 && longRows >= rows * 0.4)) return false;
|
|
3503
3525
|
for (let c = 0; c < table.cols; c++) {
|
|
3504
3526
|
const filled = table.cells.map((row) => row[c]).filter((cell) => cell && cell.colSpan < table.cols && cell.text.trim()).map((cell) => cell.text.trim());
|
|
3505
|
-
if (filled.length >= 3 && filled.length >= rows * 0.6 && filled.every((text) => text.length <= 30 && (_nullishCoalesce(_optionalChain([text, 'access',
|
|
3527
|
+
if (filled.length >= 3 && filled.length >= rows * 0.6 && filled.every((text) => text.length <= 30 && (_nullishCoalesce(_optionalChain([text, 'access', _111 => _111.match, 'call', _112 => _112(/\p{L}/gu), 'optionalAccess', _113 => _113.length]), () => ( 0))) >= 2)) return false;
|
|
3506
3528
|
}
|
|
3507
3529
|
return true;
|
|
3508
3530
|
}
|
|
@@ -3531,7 +3553,7 @@ var TICK = /^-?[\d,]+(?:\.\d+)?%?$/;
|
|
|
3531
3553
|
var QUANTITY = /^[-−–]?[\d,]*\.?\d+%?$/;
|
|
3532
3554
|
var quantity = (token) => Number(token.replace(/^[−–]/, "-").replace(/[,%]/g, ""));
|
|
3533
3555
|
function isValueAxisColumn(table, c) {
|
|
3534
|
-
const lines = table.cells.flatMap((row) => (_nullishCoalesce(_optionalChain([row, 'access',
|
|
3556
|
+
const lines = table.cells.flatMap((row) => (_nullishCoalesce(_optionalChain([row, 'access', _114 => _114[c], 'optionalAccess', _115 => _115.text]), () => ( ""))).split("\n").map((line) => line.trim().split(/\s+/)));
|
|
3535
3557
|
const others = table.cells.flatMap((row) => row.filter((_, k) => k !== c).map((cell) => cell.text.trim().split(/\s+/))).filter((tokens) => tokens.every((token) => QUANTITY.test(token))).flat().map(quantity).filter((v) => !(Number.isInteger(v) && v >= 1900 && v <= 2100));
|
|
3536
3558
|
for (const ticks of [lines.flat().filter((t) => TICK.test(t)).map(quantity), lines.map((tokens) => tokens[0]).filter((t) => TICK.test(t)).map(quantity)]) {
|
|
3537
3559
|
const run = fallingRun(ticks);
|
|
@@ -3563,7 +3585,7 @@ function isChartTable(table, ocr = false) {
|
|
|
3563
3585
|
const numeric = texts.filter((text) => NUMERIC_CELL.test(text)).length;
|
|
3564
3586
|
if (numeric < texts.length * 0.5) return false;
|
|
3565
3587
|
for (let c = 0; c < table.cols; c++) {
|
|
3566
|
-
if (!ocr ? isValueAxisColumn(table, c) : hasValueAxis(table.cells.flatMap((row) => (_nullishCoalesce(_optionalChain([row, 'access',
|
|
3588
|
+
if (!ocr ? isValueAxisColumn(table, c) : hasValueAxis(table.cells.flatMap((row) => (_nullishCoalesce(_optionalChain([row, 'access', _116 => _116[c], 'optionalAccess', _117 => _117.text]), () => ( ""))).split(/\s+/)).filter((t) => TICK.test(t)).map((t) => Number(t.replace(/[,%]/g, ""))))) return true;
|
|
3567
3589
|
}
|
|
3568
3590
|
const values = texts.filter((text) => text.split(/\s+/).every((token) => QUANTITY.test(token))).length;
|
|
3569
3591
|
const cells = table.rows * table.cols;
|
|
@@ -3616,7 +3638,7 @@ function clusterCellLines(items) {
|
|
|
3616
3638
|
}
|
|
3617
3639
|
var WRAP_INDENT_MAX = 3;
|
|
3618
3640
|
function joinClusterCellLines(lines, box, lex) {
|
|
3619
|
-
let out = _nullishCoalesce(_optionalChain([lines, 'access',
|
|
3641
|
+
let out = _nullishCoalesce(_optionalChain([lines, 'access', _118 => _118[0], 'optionalAccess', _119 => _119.text]), () => ( ""));
|
|
3620
3642
|
for (let i = 1; i < lines.length; i++) {
|
|
3621
3643
|
const a = lines[i - 1], b = lines[i];
|
|
3622
3644
|
const join2 = !a.spaceAfter && cellLineWraps(box, box.x1, a.right, a.fontSize, b.firstCharW) && a.left - box.x1 <= WRAP_INDENT_MAX * a.fontSize && b.left - box.x1 <= WRAP_INDENT_MAX * b.fontSize && /<\/u>$/.test(a.text) === /^<u>/.test(b.text) && !startsNewItem(out, b.text) && wrapJoiner(out, b.text, lex, false) === "";
|
|
@@ -3827,7 +3849,7 @@ function detectAlignedTwoColumnTables(rows, pageNum) {
|
|
|
3827
3849
|
continue;
|
|
3828
3850
|
}
|
|
3829
3851
|
const top = rows[i - 1];
|
|
3830
|
-
const title = _optionalChain([top, 'optionalAccess',
|
|
3852
|
+
const title = _optionalChain([top, 'optionalAccess', _120 => _120.items, 'access', _121 => _121.length]) === 1 && Math.abs(top.items[0].x - first[0].x) <= 5 && top.items[0].text.length <= 65 && top.y - first[0].y <= Math.max(24, first[0].fontSize * 2.8) ? top : void 0;
|
|
3831
3853
|
const tableRows = title ? [title, ...body] : body;
|
|
3832
3854
|
const cells = tableRows.map((row, idx) => {
|
|
3833
3855
|
if (title && idx === 0) return [{ text: row.items[0].text, colSpan: 2, rowSpan: 1 }, { text: "", colSpan: 1, rowSpan: 1 }];
|
|
@@ -3883,12 +3905,12 @@ function isTwoColumnProse(r) {
|
|
|
3883
3905
|
if (t.rows < 8) return false;
|
|
3884
3906
|
const dense = [];
|
|
3885
3907
|
for (let c = 0; c < t.cols; c++) {
|
|
3886
|
-
const filled = t.cells.filter((row) => _optionalChain([row, 'access',
|
|
3908
|
+
const filled = t.cells.filter((row) => _optionalChain([row, 'access', _122 => _122[c], 'optionalAccess', _123 => _123.text, 'access', _124 => _124.trim, 'call', _125 => _125()])).length;
|
|
3887
3909
|
if (filled / t.rows >= 0.3) dense.push(c);
|
|
3888
3910
|
}
|
|
3889
3911
|
if (dense.length !== 2) return false;
|
|
3890
3912
|
for (const c of dense) {
|
|
3891
|
-
const lens = t.cells.map((row) => _nullishCoalesce(_optionalChain([row, 'access',
|
|
3913
|
+
const lens = t.cells.map((row) => _nullishCoalesce(_optionalChain([row, 'access', _126 => _126[c], 'optionalAccess', _127 => _127.text, 'access', _128 => _128.replace, 'call', _129 => _129(/\s+/g, ""), 'access', _130 => _130.length]), () => ( 0))).filter((n) => n > 0);
|
|
3892
3914
|
const avg = lens.reduce((s, v) => s + v, 0) / (lens.length || 1);
|
|
3893
3915
|
if (avg < 12) return false;
|
|
3894
3916
|
}
|
|
@@ -4302,7 +4324,7 @@ function assignRowItems(items, columns, numCols, headerFace) {
|
|
|
4302
4324
|
const runs = [];
|
|
4303
4325
|
for (const it of sorted) {
|
|
4304
4326
|
const last = runs[runs.length - 1];
|
|
4305
|
-
const prev = _optionalChain([last, 'optionalAccess',
|
|
4327
|
+
const prev = _optionalChain([last, 'optionalAccess', _131 => _131[last.length - 1]]);
|
|
4306
4328
|
if (prev && it.x - (prev.x + prev.w) <= Math.max(0.5, it.fontSize * 0.05) && !it.hasSpaceBefore) last.push(it);
|
|
4307
4329
|
else runs.push([it]);
|
|
4308
4330
|
}
|
|
@@ -4377,7 +4399,7 @@ function buildClusterTable(rows, columns, pageNum, lex) {
|
|
|
4377
4399
|
);
|
|
4378
4400
|
const usedItems = /* @__PURE__ */ new Set();
|
|
4379
4401
|
const lines = cells.map((row) => row.map(() => []));
|
|
4380
|
-
const headFaces = new Set(_optionalChain([rows, 'access',
|
|
4402
|
+
const headFaces = new Set(_optionalChain([rows, 'access', _132 => _132[0], 'optionalAccess', _133 => _133.items, 'access', _134 => _134.map, 'call', _135 => _135((i) => i.fontName)]));
|
|
4381
4403
|
const headerFace = headFaces.size === 1 && rows.slice(1).every((row) => row.items.every((i) => !headFaces.has(i.fontName))) ? [...headFaces][0] : void 0;
|
|
4382
4404
|
for (let r = 0; r < numRows; r++) {
|
|
4383
4405
|
const row = rows[r];
|
|
@@ -4413,7 +4435,7 @@ function buildClusterTable(rows, columns, pageNum, lex) {
|
|
|
4413
4435
|
const nonEmptyCols = cells[r].filter((c) => c.text.trim()).length;
|
|
4414
4436
|
if (nonEmptyCols !== 1) continue;
|
|
4415
4437
|
if (cells[r][0].text.trim() !== "") continue;
|
|
4416
|
-
const contentText = _optionalChain([cells, 'access',
|
|
4438
|
+
const contentText = _optionalChain([cells, 'access', _136 => _136[r], 'access', _137 => _137.find, 'call', _138 => _138((c) => c.text.trim()), 'optionalAccess', _139 => _139.text, 'access', _140 => _140.trim, 'call', _141 => _141()]) || "";
|
|
4417
4439
|
if (/^[○●▶\-·]/.test(contentText)) continue;
|
|
4418
4440
|
for (let pr = r - 1; pr >= 0; pr--) {
|
|
4419
4441
|
if (cells[pr].some((c) => c.text.trim())) {
|
|
@@ -4646,7 +4668,7 @@ function stackedTableBands(items) {
|
|
|
4646
4668
|
const caption = (start, end) => lines.slice(start, end).some((line) => /^Table\s+\d+\s*[:.]/i.test(mergeLineSimple(line).trim()));
|
|
4647
4669
|
while (runs.length > 0 && !caption(runs[runs.length - 1].end, lines.length)) runs.pop();
|
|
4648
4670
|
if (runs.length < 2) return null;
|
|
4649
|
-
if (runs.some((run, i) => !caption(run.end, _nullishCoalesce(_optionalChain([runs, 'access',
|
|
4671
|
+
if (runs.some((run, i) => !caption(run.end, _nullishCoalesce(_optionalChain([runs, 'access', _142 => _142[i + 1], 'optionalAccess', _143 => _143.start]), () => ( lines.length))))) return null;
|
|
4650
4672
|
const tables = runs.map((run) => lines.slice(run.start, run.end).flat());
|
|
4651
4673
|
const between = runs.slice(0, -1).map((run, i) => lines.slice(run.end, runs[i + 1].start).flat());
|
|
4652
4674
|
const tail = lines.slice(runs[runs.length - 1].end);
|
|
@@ -4914,7 +4936,7 @@ function splitTrailingColumnRegion(items) {
|
|
|
4914
4936
|
}
|
|
4915
4937
|
function panelBlocks(items, panel, pageNum) {
|
|
4916
4938
|
const lines = groupByY([...items].sort((a, b) => b.y - a.y || a.x - b.x));
|
|
4917
|
-
const faceOf = (line) => _nullishCoalesce(_optionalChain([dominantStyle, 'call',
|
|
4939
|
+
const faceOf = (line) => _nullishCoalesce(_optionalChain([dominantStyle, 'call', _144 => _144(line), 'optionalAccess', _145 => _145.fontName]), () => ( ""));
|
|
4918
4940
|
const runs = [];
|
|
4919
4941
|
for (const line of lines) {
|
|
4920
4942
|
const last = runs[runs.length - 1];
|
|
@@ -5096,7 +5118,7 @@ function validWrapBands(items, bands) {
|
|
|
5096
5118
|
}
|
|
5097
5119
|
function inheritedWrapBands(items) {
|
|
5098
5120
|
const source = XY_WRAP_ITEMS.get(items[0]);
|
|
5099
|
-
const present = _optionalChain([source, 'optionalAccess',
|
|
5121
|
+
const present = _optionalChain([source, 'optionalAccess', _146 => _146.length]) === items.length ? new Set(items) : null;
|
|
5100
5122
|
const sameLeaf = present && source.every((item) => present.has(item));
|
|
5101
5123
|
return sameLeaf ? validWrapBands(items, _nullishCoalesce(XY_WRAP_BANDS.get(items[0]), () => ( []))) : [];
|
|
5102
5124
|
}
|
|
@@ -5135,7 +5157,7 @@ function wrappedLineBands(items, inherited) {
|
|
|
5135
5157
|
left: box.x,
|
|
5136
5158
|
right: box.x + box.width,
|
|
5137
5159
|
y: row.reduce((n, i) => n + i.y, 0) / row.length,
|
|
5138
|
-
fontSize: _nullishCoalesce(_optionalChain([dominantStyle, 'call',
|
|
5160
|
+
fontSize: _nullishCoalesce(_optionalChain([dominantStyle, 'call', _147 => _147(row), 'optionalAccess', _148 => _148.fontSize]), () => ( 0)),
|
|
5139
5161
|
sources: row.map((item) => ({ item, state: { ...item } }))
|
|
5140
5162
|
};
|
|
5141
5163
|
});
|
|
@@ -5271,10 +5293,10 @@ function pushLineParagraphs(out, yLines, pageNum, lex) {
|
|
|
5271
5293
|
const lines = attachDropCaps(yLines).map((items) => ({ items, text: mergeLineSimple(items) })).filter((l) => l.text.trim());
|
|
5272
5294
|
const geo = lines.map((l) => {
|
|
5273
5295
|
const b = computeBBox(l.items, pageNum);
|
|
5274
|
-
return { text: l.text, left: b.x, right: b.x + b.width, y: l.items.reduce((s, i) => s + i.y, 0) / l.items.length, fontSize: _nullishCoalesce(_optionalChain([dominantStyle, 'call',
|
|
5296
|
+
return { text: l.text, left: b.x, right: b.x + b.width, y: l.items.reduce((s, i) => s + i.y, 0) / l.items.length, fontSize: _nullishCoalesce(_optionalChain([dominantStyle, 'call', _149 => _149(l.items), 'optionalAccess', _150 => _150.fontSize]), () => ( 0)) };
|
|
5275
5297
|
});
|
|
5276
5298
|
const joins = bodyLineJoins(geo, lex);
|
|
5277
|
-
const first = _optionalChain([lines, 'access',
|
|
5299
|
+
const first = _optionalChain([lines, 'access', _151 => _151[0], 'optionalAccess', _152 => _152.items, 'access', _153 => _153[0]]);
|
|
5278
5300
|
const bands = first ? _nullishCoalesce(XY_WRAP_BANDS.get(first), () => ( [])) : [];
|
|
5279
5301
|
const hasBand = (top, bottom) => {
|
|
5280
5302
|
let lo = 0, hi = bands.length;
|
|
@@ -5351,15 +5373,15 @@ function computeMedianFontSizeFromFreq(freq) {
|
|
|
5351
5373
|
function detectHeadings(blocks, medianFontSize) {
|
|
5352
5374
|
for (let bi = 0; bi < blocks.length; bi++) {
|
|
5353
5375
|
const block = blocks[bi];
|
|
5354
|
-
if (block.type !== "paragraph" || !block.text || !_optionalChain([block, 'access',
|
|
5376
|
+
if (block.type !== "paragraph" || !block.text || !_optionalChain([block, 'access', _154 => _154.style, 'optionalAccess', _155 => _155.fontSize])) continue;
|
|
5355
5377
|
const text = block.text.trim();
|
|
5356
5378
|
if (text.length === 0 || text.length > 200) continue;
|
|
5357
5379
|
if (/^\d+$/.test(text) && !isChapterNumber(block, blocks[bi + 1], medianFontSize)) continue;
|
|
5358
5380
|
const ratio = block.style.fontSize / medianFontSize;
|
|
5359
5381
|
let level = 0;
|
|
5360
|
-
if (ratio >=
|
|
5361
|
-
else if (ratio >=
|
|
5362
|
-
else if (ratio >=
|
|
5382
|
+
if (ratio >= _chunkMED2MR6Ocjs.HEADING_RATIO_H1) level = 1;
|
|
5383
|
+
else if (ratio >= _chunkMED2MR6Ocjs.HEADING_RATIO_H2) level = 2;
|
|
5384
|
+
else if (ratio >= _chunkMED2MR6Ocjs.HEADING_RATIO_H3) level = 3;
|
|
5363
5385
|
if (level > 0) {
|
|
5364
5386
|
block.type = "heading";
|
|
5365
5387
|
block.level = level;
|
|
@@ -5368,21 +5390,21 @@ function detectHeadings(blocks, medianFontSize) {
|
|
|
5368
5390
|
}
|
|
5369
5391
|
}
|
|
5370
5392
|
function isChapterNumber(block, next, medianFontSize) {
|
|
5371
|
-
const size = _nullishCoalesce(_optionalChain([block, 'access',
|
|
5372
|
-
const nextSize = _nullishCoalesce(_optionalChain([next, 'optionalAccess',
|
|
5373
|
-
const text = _nullishCoalesce(_optionalChain([next, 'optionalAccess',
|
|
5374
|
-
const a = block.bbox, b = _optionalChain([next, 'optionalAccess',
|
|
5375
|
-
return /^\d{1,2}$/.test(_nullishCoalesce(_optionalChain([block, 'access',
|
|
5393
|
+
const size = _nullishCoalesce(_optionalChain([block, 'access', _156 => _156.style, 'optionalAccess', _157 => _157.fontSize]), () => ( 0));
|
|
5394
|
+
const nextSize = _nullishCoalesce(_optionalChain([next, 'optionalAccess', _158 => _158.style, 'optionalAccess', _159 => _159.fontSize]), () => ( 0));
|
|
5395
|
+
const text = _nullishCoalesce(_optionalChain([next, 'optionalAccess', _160 => _160.text, 'optionalAccess', _161 => _161.trim, 'call', _162 => _162()]), () => ( ""));
|
|
5396
|
+
const a = block.bbox, b = _optionalChain([next, 'optionalAccess', _163 => _163.bbox]);
|
|
5397
|
+
return /^\d{1,2}$/.test(_nullishCoalesce(_optionalChain([block, 'access', _164 => _164.text, 'optionalAccess', _165 => _165.trim, 'call', _166 => _166()]), () => ( ""))) && size >= medianFontSize * 2.5 && !!next && (next.type === "paragraph" || next.type === "heading") && next.pageNumber === block.pageNumber && nextSize >= medianFontSize * _chunkMED2MR6Ocjs.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;
|
|
5376
5398
|
}
|
|
5377
5399
|
function mergeStackedHeadingLines(blocks, medianFontSize) {
|
|
5378
5400
|
for (let i = 0; i < blocks.length - 1; ) {
|
|
5379
5401
|
const a = blocks[i], b = blocks[i + 1];
|
|
5380
5402
|
const ab = a.bbox, bb = b.bbox;
|
|
5381
|
-
const af = _nullishCoalesce(_optionalChain([a, 'access',
|
|
5403
|
+
const af = _nullishCoalesce(_optionalChain([a, 'access', _167 => _167.style, 'optionalAccess', _168 => _168.fontSize]), () => ( 0)), bf = _nullishCoalesce(_optionalChain([b, 'access', _169 => _169.style, 'optionalAccess', _170 => _170.fontSize]), () => ( 0));
|
|
5382
5404
|
const gap = ab && bb ? ab.y - (bb.y + bb.height) : Infinity;
|
|
5383
|
-
const centered = ab && bb && _optionalChain([a, 'access',
|
|
5405
|
+
const centered = ab && bb && _optionalChain([a, 'access', _171 => _171.style, 'optionalAccess', _172 => _172.fontName]) === _optionalChain([b, 'access', _173 => _173.style, 'optionalAccess', _174 => _174.fontName]) && Math.abs(ab.x + ab.width / 2 - (bb.x + bb.width / 2)) <= Math.max(5, af * 0.5);
|
|
5384
5406
|
const sameAnchor = ab && bb && Math.abs(ab.x - bb.x) <= 5;
|
|
5385
|
-
const wrapped = sameAnchor && _optionalChain([a, 'access',
|
|
5407
|
+
const wrapped = sameAnchor && _optionalChain([a, 'access', _175 => _175.style, 'optionalAccess', _176 => _176.fontName]) === _optionalChain([b, 'access', _177 => _177.style, 'optionalAccess', _178 => _178.fontName]) && af === bf && ab.width >= bb.width * 0.95 && (_nullishCoalesce(_optionalChain([a, 'access', _179 => _179.text, 'optionalAccess', _180 => _180.trim, 'call', _181 => _181(), 'access', _182 => _182.split, 'call', _183 => _183(/\s+/), 'access', _184 => _184.length]), () => ( 0))) >= 3;
|
|
5386
5408
|
const displayStack = centered && gap <= Math.min(af, bf) * 0.3 && Math.max(af, bf) <= Math.min(af, bf) * 1.45;
|
|
5387
5409
|
if (a.type !== "heading" || b.type !== "heading" || !a.text || !b.text || /^\d+$/.test(a.text.trim()) || !ab || !bb || ab.page !== bb.page || !(sameAnchor && af >= medianFontSize * 2 && bf >= medianFontSize * 2) && !wrapped && !(centered && af >= medianFontSize * 1.25 && bf >= medianFontSize * 1.25) || Math.abs(af - bf) > Math.max(af, bf) * 0.15 && !displayStack || gap < -2 || gap > Math.max(af, bf) * 0.45 || a.text.length > (centered ? 120 : 50) || b.text.length > (centered ? 120 : 50)) {
|
|
5388
5410
|
i++;
|
|
@@ -5411,25 +5433,25 @@ function detectTypographyHeadings(blocks) {
|
|
|
5411
5433
|
if (page.some((block) => block.type === "heading")) continue;
|
|
5412
5434
|
const faceWeight = /* @__PURE__ */ new Map();
|
|
5413
5435
|
for (const block of page) {
|
|
5414
|
-
if (block.type !== "paragraph" || !block.text || !_optionalChain([block, 'access',
|
|
5436
|
+
if (block.type !== "paragraph" || !block.text || !_optionalChain([block, 'access', _185 => _185.style, 'optionalAccess', _186 => _186.fontName])) continue;
|
|
5415
5437
|
const faces = FACE_CHARS.get(block);
|
|
5416
5438
|
if (faces) for (const [face, n] of faces) faceWeight.set(face, (_nullishCoalesce(faceWeight.get(face), () => ( 0))) + n);
|
|
5417
5439
|
else faceWeight.set(block.style.fontName, (_nullishCoalesce(faceWeight.get(block.style.fontName), () => ( 0))) + block.text.length);
|
|
5418
5440
|
}
|
|
5419
|
-
const bodyFace = _optionalChain([[...faceWeight], 'access',
|
|
5441
|
+
const bodyFace = _optionalChain([[...faceWeight], 'access', _187 => _187.sort, 'call', _188 => _188((a, b) => b[1] - a[1]), 'access', _189 => _189[0], 'optionalAccess', _190 => _190[0]]);
|
|
5420
5442
|
if (!bodyFace || (_nullishCoalesce(faceWeight.get(bodyFace), () => ( 0))) < 250) continue;
|
|
5421
5443
|
const sizeWeight = /* @__PURE__ */ new Map();
|
|
5422
5444
|
for (const block of page) {
|
|
5423
|
-
if (block.type !== "paragraph" || !_optionalChain([block, 'access',
|
|
5445
|
+
if (block.type !== "paragraph" || !_optionalChain([block, 'access', _191 => _191.style, 'optionalAccess', _192 => _192.fontSize])) continue;
|
|
5424
5446
|
const faces = FACE_CHARS.get(block);
|
|
5425
|
-
const chars = faces ? _nullishCoalesce(faces.get(bodyFace), () => ( 0)) : block.style.fontName === bodyFace ? _nullishCoalesce(_optionalChain([block, 'access',
|
|
5447
|
+
const chars = faces ? _nullishCoalesce(faces.get(bodyFace), () => ( 0)) : block.style.fontName === bodyFace ? _nullishCoalesce(_optionalChain([block, 'access', _193 => _193.text, 'optionalAccess', _194 => _194.length]), () => ( 0)) : 0;
|
|
5426
5448
|
if (chars) sizeWeight.set(block.style.fontSize, (_nullishCoalesce(sizeWeight.get(block.style.fontSize), () => ( 0))) + chars);
|
|
5427
5449
|
}
|
|
5428
|
-
const bodySize = _nullishCoalesce(_optionalChain([[...sizeWeight], 'access',
|
|
5450
|
+
const bodySize = _nullishCoalesce(_optionalChain([[...sizeWeight], 'access', _195 => _195.sort, 'call', _196 => _196((a, b) => b[1] - a[1]), 'access', _197 => _197[0], 'optionalAccess', _198 => _198[0]]), () => ( 0));
|
|
5429
5451
|
for (let i = 0; i < page.length; i++) {
|
|
5430
5452
|
const block = page[i];
|
|
5431
5453
|
const { text, bbox, style } = block;
|
|
5432
|
-
if (block.type !== "paragraph" || !text || !bbox || !_optionalChain([style, 'optionalAccess',
|
|
5454
|
+
if (block.type !== "paragraph" || !text || !bbox || !_optionalChain([style, 'optionalAccess', _199 => _199.fontName]) || !style.fontSize) continue;
|
|
5433
5455
|
const title = text.trim();
|
|
5434
5456
|
const numbered = /^\d+(?:\.\d+)*\.?\s+[A-Z가-힣]/.test(title);
|
|
5435
5457
|
const faces = FACE_CHARS.get(block);
|
|
@@ -5459,16 +5481,16 @@ function detectDocumentStyleHeadings(blocks) {
|
|
|
5459
5481
|
for (const page of byPage.values()) {
|
|
5460
5482
|
const faceChars = /* @__PURE__ */ new Map();
|
|
5461
5483
|
for (const block of page) {
|
|
5462
|
-
if (block.type !== "paragraph" || !block.text || !_optionalChain([block, 'access',
|
|
5484
|
+
if (block.type !== "paragraph" || !block.text || !_optionalChain([block, 'access', _200 => _200.style, 'optionalAccess', _201 => _201.fontName])) continue;
|
|
5463
5485
|
faceChars.set(block.style.fontName, (_nullishCoalesce(faceChars.get(block.style.fontName), () => ( 0))) + block.text.length);
|
|
5464
5486
|
}
|
|
5465
|
-
const bodyFace = _optionalChain([[...faceChars], 'access',
|
|
5487
|
+
const bodyFace = _optionalChain([[...faceChars], 'access', _202 => _202.sort, 'call', _203 => _203((a, b) => b[1] - a[1]), 'access', _204 => _204[0], 'optionalAccess', _205 => _205[0]]);
|
|
5466
5488
|
if (!bodyFace || (_nullishCoalesce(faceChars.get(bodyFace), () => ( 0))) < 100) continue;
|
|
5467
|
-
const labels = page.filter((b) => b.type === "paragraph" && b.text && b.bbox && _optionalChain([b, 'access',
|
|
5489
|
+
const labels = page.filter((b) => b.type === "paragraph" && b.text && b.bbox && _optionalChain([b, 'access', _206 => _206.style, 'optionalAccess', _207 => _207.fontName]) && b.style.fontName !== bodyFace && b.text.trim().length >= 3 && b.text.trim().length <= 40);
|
|
5468
5490
|
for (const label of labels) {
|
|
5469
|
-
const peers = labels.filter((b) => _optionalChain([b, 'access',
|
|
5491
|
+
const peers = labels.filter((b) => _optionalChain([b, 'access', _208 => _208.style, 'optionalAccess', _209 => _209.fontName]) === _optionalChain([label, 'access', _210 => _210.style, 'optionalAccess', _211 => _211.fontName]) && Math.abs(b.bbox.y - label.bbox.y) <= 3 && Math.abs(b.bbox.x - label.bbox.x) >= 60);
|
|
5470
5492
|
if (peers.length < 2) continue;
|
|
5471
|
-
const value = page.find((b) => b.type === "paragraph" && b.bbox && _optionalChain([b, 'access',
|
|
5493
|
+
const value = page.find((b) => b.type === "paragraph" && b.bbox && _optionalChain([b, 'access', _212 => _212.style, 'optionalAccess', _213 => _213.fontName]) !== _optionalChain([label, 'access', _214 => _214.style, 'optionalAccess', _215 => _215.fontName]) && b.bbox.x >= label.bbox.x - 5 && b.bbox.x <= label.bbox.x + 20 && b.bbox.y < label.bbox.y && label.bbox.y - (b.bbox.y + b.bbox.height) <= 60);
|
|
5472
5494
|
if (value) {
|
|
5473
5495
|
label.type = "heading";
|
|
5474
5496
|
label.level = 2;
|
|
@@ -5477,7 +5499,7 @@ function detectDocumentStyleHeadings(blocks) {
|
|
|
5477
5499
|
const first = page.find((b) => b.type !== "image" && b.type !== "separator");
|
|
5478
5500
|
const second = page[page.indexOf(first) + 1];
|
|
5479
5501
|
const third = page[page.indexOf(first) + 2];
|
|
5480
|
-
if (!first || !second || !third || first.type !== "list" && first.type !== "paragraph" || second.type !== "paragraph" || !first.text || !second.text || !first.bbox || !second.bbox || !_optionalChain([first, 'access',
|
|
5502
|
+
if (!first || !second || !third || first.type !== "list" && first.type !== "paragraph" || second.type !== "paragraph" || !first.text || !second.text || !first.bbox || !second.bbox || !_optionalChain([first, 'access', _216 => _216.style, 'optionalAccess', _217 => _217.fontName]) || !_optionalChain([second, 'access', _218 => _218.style, 'optionalAccess', _219 => _219.fontName]) || !/^\d+(?:\.\d+)*\.\s+/.test(first.text.trim()) || first.style.fontName === bodyFace || second.style.fontName === bodyFace || first.text.length + second.text.length > 140 || Math.abs(first.bbox.x - second.bbox.x) > 30 || first.bbox.y - (second.bbox.y + second.bbox.height) > (_nullishCoalesce(first.style.fontSize, () => ( 0))) * 1.5 || _optionalChain([third, 'access', _220 => _220.style, 'optionalAccess', _221 => _221.fontName]) !== bodyFace) continue;
|
|
5481
5503
|
first.type = "heading";
|
|
5482
5504
|
first.level = 1;
|
|
5483
5505
|
first.text = `${first.text.trim()} ${second.text.trim()}`;
|
|
@@ -5501,18 +5523,18 @@ function detectSiblingStyleHeadings(blocks) {
|
|
|
5501
5523
|
for (const page of byPage.values()) {
|
|
5502
5524
|
const bodyChars = /* @__PURE__ */ new Map();
|
|
5503
5525
|
for (const block of page) {
|
|
5504
|
-
if (block.type !== "paragraph" || !block.text || !_optionalChain([block, 'access',
|
|
5526
|
+
if (block.type !== "paragraph" || !block.text || !_optionalChain([block, 'access', _222 => _222.style, 'optionalAccess', _223 => _223.fontName])) continue;
|
|
5505
5527
|
const face = block.style.fontName;
|
|
5506
5528
|
bodyChars.set(face, (_nullishCoalesce(bodyChars.get(face), () => ( 0))) + block.text.length);
|
|
5507
5529
|
}
|
|
5508
|
-
const bodyFace = _optionalChain([[...bodyChars], 'access',
|
|
5509
|
-
const anchors = page.filter((b) => b.type === "heading" && b.text && _optionalChain([b, 'access',
|
|
5530
|
+
const bodyFace = _optionalChain([[...bodyChars], 'access', _224 => _224.sort, 'call', _225 => _225((a, b) => b[1] - a[1]), 'access', _226 => _226[0], 'optionalAccess', _227 => _227[0]]);
|
|
5531
|
+
const anchors = page.filter((b) => b.type === "heading" && b.text && _optionalChain([b, 'access', _228 => _228.style, 'optionalAccess', _229 => _229.fontName]) && b.style.fontName !== bodyFace);
|
|
5510
5532
|
for (const anchor of anchors) {
|
|
5511
5533
|
const numbered = /^([A-Z])\.\d+\s+/.exec(anchor.text.trim());
|
|
5512
5534
|
const lettered = /^([A-Z])\s+/.exec(anchor.text.trim());
|
|
5513
|
-
const peers = anchors.filter((b) => _optionalChain([b, 'access',
|
|
5535
|
+
const peers = anchors.filter((b) => _optionalChain([b, 'access', _230 => _230.style, 'optionalAccess', _231 => _231.fontName]) === _optionalChain([anchor, 'access', _232 => _232.style, 'optionalAccess', _233 => _233.fontName]) && Math.abs((_nullishCoalesce(_optionalChain([b, 'access', _234 => _234.style, 'optionalAccess', _235 => _235.fontSize]), () => ( 0))) - (_nullishCoalesce(_optionalChain([anchor, 'access', _236 => _236.style, 'optionalAccess', _237 => _237.fontSize]), () => ( 0)))) < 0.5);
|
|
5514
5536
|
if (peers.length < 2 && !numbered && !lettered) continue;
|
|
5515
|
-
const candidates = page.filter((b) => b.type === "paragraph" && b.text && b.bbox && _optionalChain([b, 'access',
|
|
5537
|
+
const candidates = page.filter((b) => b.type === "paragraph" && b.text && b.bbox && _optionalChain([b, 'access', _238 => _238.style, 'optionalAccess', _239 => _239.fontName]) === _optionalChain([anchor, 'access', _240 => _240.style, 'optionalAccess', _241 => _241.fontName]) && Math.abs((_nullishCoalesce(_optionalChain([b, 'access', _242 => _242.style, 'optionalAccess', _243 => _243.fontSize]), () => ( 0))) - (_nullishCoalesce(_optionalChain([anchor, 'access', _244 => _244.style, 'optionalAccess', _245 => _245.fontSize]), () => ( 0)))) < 0.5 && b.text.trim().length >= 3 && b.text.trim().length <= 80 && b.bbox.height <= (_nullishCoalesce(_optionalChain([b, 'access', _246 => _246.style, 'optionalAccess', _247 => _247.fontSize]), () => ( 0))) * 1.6 && /^[A-Z]/.test(b.text.trim()) && !/[.!?:;,]$/.test(b.text.trim()) && !/^(?:Table|Figure|Fig\.?|Appendix)\s+\d/i.test(b.text.trim()));
|
|
5516
5538
|
const siblings = candidates.filter((b) => numbered ? new RegExp(`^${numbered[1]}\\.\\d+\\s+`).test(b.text.trim()) : lettered ? /^[A-Z]\s+/.test(b.text.trim()) && Math.abs(anchor.bbox.x - b.bbox.x) < 8 : peers.some((h) => h.bbox && Math.abs(h.bbox.x - b.bbox.x) < 8));
|
|
5517
5539
|
if (siblings.length < (numbered || lettered ? 1 : 2)) continue;
|
|
5518
5540
|
for (const sibling of siblings) {
|
|
@@ -5531,13 +5553,13 @@ function detectRepeatedPageLabels(blocks) {
|
|
|
5531
5553
|
}
|
|
5532
5554
|
for (const page of byPage.values()) {
|
|
5533
5555
|
const bodyChars = /* @__PURE__ */ new Map();
|
|
5534
|
-
for (const b of page) if (b.type === "paragraph" && b.text && _optionalChain([b, 'access',
|
|
5556
|
+
for (const b of page) if (b.type === "paragraph" && b.text && _optionalChain([b, 'access', _248 => _248.style, 'optionalAccess', _249 => _249.fontName])) {
|
|
5535
5557
|
const faces = FACE_CHARS.get(b);
|
|
5536
5558
|
if (faces) for (const [face, n] of faces) bodyChars.set(face, (_nullishCoalesce(bodyChars.get(face), () => ( 0))) + n);
|
|
5537
5559
|
else bodyChars.set(b.style.fontName, (_nullishCoalesce(bodyChars.get(b.style.fontName), () => ( 0))) + b.text.length);
|
|
5538
5560
|
}
|
|
5539
|
-
const bodyFace = _optionalChain([[...bodyChars], 'access',
|
|
5540
|
-
const candidates = page.filter((b) => b.type === "paragraph" && b.text && b.bbox && _optionalChain([b, 'access',
|
|
5561
|
+
const bodyFace = _optionalChain([[...bodyChars], 'access', _250 => _250.sort, 'call', _251 => _251((a, b) => b[1] - a[1]), 'access', _252 => _252[0], 'optionalAccess', _253 => _253[0]]);
|
|
5562
|
+
const candidates = page.filter((b) => b.type === "paragraph" && b.text && b.bbox && _optionalChain([b, 'access', _254 => _254.style, 'optionalAccess', _255 => _255.fontName]) && b.style.fontName !== bodyFace && b.bbox.height <= (_nullishCoalesce(b.style.fontSize, () => ( 0))) * 1.6 && b.text.trim().length >= 5 && b.text.trim().length <= 80);
|
|
5541
5563
|
const groups = /* @__PURE__ */ new Map();
|
|
5542
5564
|
for (const b of candidates) {
|
|
5543
5565
|
const key = `${b.style.fontName}:${b.style.fontSize}`;
|
|
@@ -5573,19 +5595,19 @@ function detectPageLeadHeadings(blocks) {
|
|
|
5573
5595
|
for (const page of byPage.values()) {
|
|
5574
5596
|
const content = page.filter((b) => b.type !== "image" && b.type !== "separator" && !(b.type === "paragraph" && !b.style));
|
|
5575
5597
|
const [first, second, third] = content;
|
|
5576
|
-
if (!_optionalChain([first, 'optionalAccess',
|
|
5598
|
+
if (!_optionalChain([first, 'optionalAccess', _256 => _256.bbox]) || !first.text || !_optionalChain([first, 'access', _257 => _257.style, 'optionalAccess', _258 => _258.fontSize]) || !second) continue;
|
|
5577
5599
|
const firstText = first.text.trim();
|
|
5578
5600
|
const captionLike = /^(?:Figure|Fig\.?|Table|표|그림)\s*\d/i;
|
|
5579
5601
|
const hasImage = page.some((b) => b.type === "image");
|
|
5580
|
-
const firstIsTitle = first.type === "paragraph" && firstText.length >= 5 && firstText.length <= 80 && first.bbox.height <= first.style.fontSize * 1.6 && (/^(?:CONTENTS|Table of Contents)$/i.test(firstText) || hasImage && /^[A-Z]/.test(firstText) && !captionLike.test(firstText) && second.type === "paragraph" && /^[A-Z]/.test(_nullishCoalesce(_optionalChain([second, 'access',
|
|
5602
|
+
const firstIsTitle = first.type === "paragraph" && firstText.length >= 5 && firstText.length <= 80 && first.bbox.height <= first.style.fontSize * 1.6 && (/^(?:CONTENTS|Table of Contents)$/i.test(firstText) || hasImage && /^[A-Z]/.test(firstText) && !captionLike.test(firstText) && second.type === "paragraph" && /^[A-Z]/.test(_nullishCoalesce(_optionalChain([second, 'access', _259 => _259.text, 'optionalAccess', _260 => _260.trim, 'call', _261 => _261()]), () => ( ""))) && (_nullishCoalesce(_optionalChain([second, 'access', _262 => _262.text, 'optionalAccess', _263 => _263.length]), () => ( 0))) >= 100 && second.bbox && first.bbox.y - (second.bbox.y + second.bbox.height) >= first.style.fontSize);
|
|
5581
5603
|
const firstAboveProse = first.type === "paragraph" && firstText.length >= 5 && firstText.length <= 80 && first.bbox.height <= first.style.fontSize * 2 && second.type === "paragraph" && second.bbox && second.bbox.height >= first.style.fontSize * 4 && Math.abs(first.bbox.x - second.bbox.x) <= first.style.fontSize * 2 && first.bbox.y - (second.bbox.y + second.bbox.height) >= first.style.fontSize * 2 && !captionLike.test(firstText) && !/^(?:doi:|https?:|www\.)/i.test(firstText);
|
|
5582
|
-
const firstIsSection = first.type === "list" && /^\d+\.\s+[A-Z][A-Z\s]{12,}$/.test(firstText) && second.type === "paragraph" && (_nullishCoalesce(_optionalChain([second, 'access',
|
|
5604
|
+
const firstIsSection = first.type === "list" && /^\d+\.\s+[A-Z][A-Z\s]{12,}$/.test(firstText) && second.type === "paragraph" && (_nullishCoalesce(_optionalChain([second, 'access', _264 => _264.text, 'optionalAccess', _265 => _265.length]), () => ( 0))) >= 100;
|
|
5583
5605
|
if (firstIsTitle || firstAboveProse || firstIsSection) {
|
|
5584
5606
|
first.type = "heading";
|
|
5585
5607
|
first.level = 1;
|
|
5586
5608
|
}
|
|
5587
|
-
if (first.type !== "heading" || captionLike.test(firstText) || second.type !== "paragraph" || !second.text || !second.bbox || !_optionalChain([second, 'access',
|
|
5588
|
-
const distinctFace = _optionalChain([third, 'access',
|
|
5609
|
+
if (first.type !== "heading" || captionLike.test(firstText) || second.type !== "paragraph" || !second.text || !second.bbox || !_optionalChain([second, 'access', _266 => _266.style, 'optionalAccess', _267 => _267.fontName]) || !second.style.fontSize || !_optionalChain([third, 'optionalAccess', _268 => _268.text]) || !third.bbox || second.text.trim().length < 5 || second.text.trim().length > 80 || captionLike.test(second.text.trim()) || /^(?:doi:|https?:)/i.test(second.text.trim()) || second.bbox.height > second.style.fontSize * 1.6 || Math.abs(second.bbox.x - third.bbox.x) > 30) continue;
|
|
5610
|
+
const distinctFace = _optionalChain([third, 'access', _269 => _269.style, 'optionalAccess', _270 => _270.fontName]) !== second.style.fontName;
|
|
5589
5611
|
const namedContents = /^Table of Contents$/i.test(second.text.trim());
|
|
5590
5612
|
if (distinctFace && third.text.length >= 60 || namedContents) {
|
|
5591
5613
|
second.type = "heading";
|
|
@@ -5596,24 +5618,24 @@ function detectPageLeadHeadings(blocks) {
|
|
|
5596
5618
|
function refineDocumentStyleHeadings(blocks) {
|
|
5597
5619
|
const faceChars = /* @__PURE__ */ new Map();
|
|
5598
5620
|
for (const block of blocks) {
|
|
5599
|
-
if (block.type !== "paragraph" || !block.text || !_optionalChain([block, 'access',
|
|
5621
|
+
if (block.type !== "paragraph" || !block.text || !_optionalChain([block, 'access', _271 => _271.style, 'optionalAccess', _272 => _272.fontName])) continue;
|
|
5600
5622
|
faceChars.set(block.style.fontName, (_nullishCoalesce(faceChars.get(block.style.fontName), () => ( 0))) + block.text.length);
|
|
5601
5623
|
}
|
|
5602
5624
|
const [bodyFace, bodyChars] = _nullishCoalesce([...faceChars].sort((a, b) => b[1] - a[1])[0], () => ( []));
|
|
5603
5625
|
if (!bodyFace || !bodyChars || bodyChars < 300) return;
|
|
5604
5626
|
for (let i = 0; i < blocks.length; i++) {
|
|
5605
5627
|
const block = blocks[i];
|
|
5606
|
-
const text = _nullishCoalesce(_optionalChain([block, 'access',
|
|
5628
|
+
const text = _nullishCoalesce(_optionalChain([block, 'access', _273 => _273.text, 'optionalAccess', _274 => _274.trim, 'call', _275 => _275()]), () => ( ""));
|
|
5607
5629
|
if (block.type === "heading" && /(?:https?:\/\/|www\.|^arxiv:|^doi:)/i.test(text)) {
|
|
5608
5630
|
block.type = "paragraph";
|
|
5609
5631
|
block.level = void 0;
|
|
5610
5632
|
continue;
|
|
5611
5633
|
}
|
|
5612
5634
|
const box = block.bbox, style = block.style;
|
|
5613
|
-
if (block.type !== "paragraph" || !box || !_optionalChain([style, 'optionalAccess',
|
|
5635
|
+
if (block.type !== "paragraph" || !box || !_optionalChain([style, 'optionalAccess', _276 => _276.fontName]) || !style.fontSize || style.fontName === bodyFace || (_nullishCoalesce(faceChars.get(style.fontName), () => ( 0))) > bodyChars * 0.25 || text.length < 3 || text.length > 70 || text.includes("\n") || box.height > style.fontSize * 1.6 || /^(?:table|figure|fig\.?|source|doi:|arxiv:|https?:|www\.|[•●○▪▫⮚*∗†])/i.test(text) || /(?:https?:\/\/|www\.|@|[=¼≪þ])/i.test(text) || /^definition\s+\d+[.:]?\s+.*\b(?:is|are|means)\b/i.test(text) || /^[\d\s.,:%+\-–]+$/.test(text)) continue;
|
|
5614
5636
|
const previous = blocks[i - 1], next = blocks[i + 1];
|
|
5615
|
-
const pb = _optionalChain([previous, 'optionalAccess',
|
|
5616
|
-
if (!pb || !nb || previous.pageNumber !== block.pageNumber || next.pageNumber !== block.pageNumber || previous.type !== "paragraph" && previous.type !== "heading" || next.type !== "paragraph" || _optionalChain([next, 'access',
|
|
5637
|
+
const pb = _optionalChain([previous, 'optionalAccess', _277 => _277.bbox]), nb = _optionalChain([next, 'optionalAccess', _278 => _278.bbox]);
|
|
5638
|
+
if (!pb || !nb || previous.pageNumber !== block.pageNumber || next.pageNumber !== block.pageNumber || previous.type !== "paragraph" && previous.type !== "heading" || next.type !== "paragraph" || _optionalChain([next, 'access', _279 => _279.style, 'optionalAccess', _280 => _280.fontName]) !== bodyFace || !next.text || next.text.length < 40 || style.fontSize < (_nullishCoalesce(next.style.fontSize, () => ( 0))) * 0.95 || pb.y - (box.y + box.height) < style.fontSize * 0.5 || box.y - (nb.y + nb.height) < 0 || box.y - (nb.y + nb.height) > style.fontSize * 2 || box.x + box.width / 2 < nb.x - 10 || box.x + box.width / 2 > nb.x + nb.width + 10) continue;
|
|
5617
5639
|
block.type = "heading";
|
|
5618
5640
|
block.level = 2;
|
|
5619
5641
|
}
|
|
@@ -5663,7 +5685,7 @@ function detectMarkerHeadings(blocks) {
|
|
|
5663
5685
|
block.level = 4;
|
|
5664
5686
|
continue;
|
|
5665
5687
|
}
|
|
5666
|
-
if (/^[가-힣]{2,6}$/.test(text) && _optionalChain([block, 'access',
|
|
5688
|
+
if (/^[가-힣]{2,6}$/.test(text) && _optionalChain([block, 'access', _281 => _281.style, 'optionalAccess', _282 => _282.fontSize])) {
|
|
5667
5689
|
const prev = blocks[i - 1];
|
|
5668
5690
|
const next = blocks[i + 1];
|
|
5669
5691
|
const prevIsStructural = !prev || prev.type === "table" || prev.type === "heading" || prev.type === "separator";
|
|
@@ -5704,7 +5726,7 @@ function detectTableCaptions(blocks) {
|
|
|
5704
5726
|
block.table.caption = blocks[i - 1].text.trim();
|
|
5705
5727
|
blocks.splice(i - 1, 1);
|
|
5706
5728
|
i--;
|
|
5707
|
-
} else if (isCaptionCandidate(blocks[i + 1], block) && _optionalChain([blocks, 'access',
|
|
5729
|
+
} else if (isCaptionCandidate(blocks[i + 1], block) && _optionalChain([blocks, 'access', _283 => _283[i + 2], 'optionalAccess', _284 => _284.type]) !== "table") {
|
|
5708
5730
|
block.table.caption = blocks[i + 1].text.trim();
|
|
5709
5731
|
blocks.splice(i + 1, 1);
|
|
5710
5732
|
}
|
|
@@ -5937,7 +5959,7 @@ function removeHeaderFooterBlocks(blocks, pageHeights, warnings, notes, tables =
|
|
|
5937
5959
|
const bottomEntries = [];
|
|
5938
5960
|
for (let bi = 0; bi < blocks.length; bi++) {
|
|
5939
5961
|
const b = blocks[bi];
|
|
5940
|
-
const text = !tables ? _optionalChain([b, 'access',
|
|
5962
|
+
const text = !tables ? _optionalChain([b, 'access', _285 => _285.text, 'optionalAccess', _286 => _286.trim, 'call', _287 => _287()]) : b.type === "table" && b.table ? b.table.cells.flat().map((c) => c.text.trim()).filter(Boolean).join(" | ") : void 0;
|
|
5941
5963
|
if (!b.bbox || !b.pageNumber || !text) continue;
|
|
5942
5964
|
const ph = pageHeights.get(b.bbox.page) || pageHeights.get(b.pageNumber);
|
|
5943
5965
|
if (!ph) continue;
|
|
@@ -5970,7 +5992,7 @@ function removeHeaderFooterBlocks(blocks, pageHeights, warnings, notes, tables =
|
|
|
5970
5992
|
for (const [p, count] of patternCount) {
|
|
5971
5993
|
const pages = [..._nullishCoalesce(patternPages.get(p), () => ( []))];
|
|
5972
5994
|
const span2 = pages.length ? Math.max(...pages) - Math.min(...pages) + 1 : 0;
|
|
5973
|
-
const varying = !tables && (_nullishCoalesce(_optionalChain([patternNumbers, 'access',
|
|
5995
|
+
const varying = !tables && (_nullishCoalesce(_optionalChain([patternNumbers, 'access', _288 => _288.get, 'call', _289 => _289(p), 'optionalAccess', _290 => _290.size]), () => ( 0))) > 1;
|
|
5974
5996
|
const occ = _nullishCoalesce(patternOcc.get(p), () => ( []));
|
|
5975
5997
|
const dense = pages.length >= span2 * 0.4;
|
|
5976
5998
|
const loose = looseVaryingNumber(occ) && (entries === bottomEntries || dense || tracksPages(occ));
|
|
@@ -5982,8 +6004,8 @@ function removeHeaderFooterBlocks(blocks, pageHeights, warnings, notes, tables =
|
|
|
5982
6004
|
for (const e of entries) {
|
|
5983
6005
|
const norm = e.text.replace(/\d+/g, "#");
|
|
5984
6006
|
if (!repeatedPatterns.has(norm)) continue;
|
|
5985
|
-
const noteMark = _optionalChain([e, 'access',
|
|
5986
|
-
if (noteMark && _optionalChain([notes, 'optionalAccess',
|
|
6007
|
+
const noteMark = _optionalChain([e, 'access', _291 => _291.text, 'access', _292 => _292.match, 'call', _293 => _293(/^\d{1,3}\)/), 'optionalAccess', _294 => _294[0]]);
|
|
6008
|
+
if (noteMark && _optionalChain([notes, 'optionalAccess', _295 => _295.get, 'call', _296 => _296(e.page), 'optionalAccess', _297 => _297.marks, 'access', _298 => _298.some, 'call', _299 => _299((m) => m.mark === noteMark)])) continue;
|
|
5987
6009
|
const cand = blocks[e.blockIdx];
|
|
5988
6010
|
const cb = cand.bbox;
|
|
5989
6011
|
const tableNote = /^(?:주\s*(?:\d+\s*[).:]|[::])|(?:자료|출처)\s*[::])/.test(e.text.replace(/ \| /g, " ")) && blocks.some((o) => {
|
|
@@ -5997,7 +6019,7 @@ function removeHeaderFooterBlocks(blocks, pageHeights, warnings, notes, tables =
|
|
|
5997
6019
|
if (bi === e.blockIdx) continue;
|
|
5998
6020
|
const o = blocks[bi];
|
|
5999
6021
|
if (!o.bbox || o.bbox.page !== cb.page) continue;
|
|
6000
|
-
const oNorm = _optionalChain([o, 'access',
|
|
6022
|
+
const oNorm = _optionalChain([o, 'access', _300 => _300.text, 'optionalAccess', _301 => _301.trim, 'call', _302 => _302(), 'access', _303 => _303.replace, 'call', _304 => _304(/\d+/g, "#")]);
|
|
6001
6023
|
if (oNorm && repeatedPatterns.has(oNorm)) continue;
|
|
6002
6024
|
const overlap2 = Math.min(cb.y + cb.height, o.bbox.y + o.bbox.height) - Math.max(cb.y, o.bbox.y);
|
|
6003
6025
|
if (overlap2 >= cb.height * 0.5) {
|
|
@@ -6125,7 +6147,7 @@ function recordRowRules(table, cells, bbox, hs) {
|
|
|
6125
6147
|
function markImageCell(cell) {
|
|
6126
6148
|
IMAGE_CELLS.add(cell);
|
|
6127
6149
|
}
|
|
6128
|
-
var emptyCell = (cell) => !cell || !_optionalChain([cell, 'access',
|
|
6150
|
+
var emptyCell = (cell) => !cell || !_optionalChain([cell, 'access', _305 => _305.text, 'optionalAccess', _306 => _306.trim, 'call', _307 => _307()]) && !_optionalChain([cell, 'access', _308 => _308.blocks, 'optionalAccess', _309 => _309.length]) && !IMAGE_CELLS.has(cell);
|
|
6129
6151
|
function trimTable(table) {
|
|
6130
6152
|
let cols = table.cols;
|
|
6131
6153
|
while (cols > 0 && table.cells.every((row) => emptyCell(row[cols - 1]))) cols--;
|
|
@@ -6141,7 +6163,7 @@ function trimTable(table) {
|
|
|
6141
6163
|
function trimTrailingEmptyTableCols(blocks) {
|
|
6142
6164
|
for (const b of blocks) {
|
|
6143
6165
|
if (b.type !== "table" || !b.table) continue;
|
|
6144
|
-
for (const row of b.table.cells) for (const cell of row) if (_optionalChain([cell, 'access',
|
|
6166
|
+
for (const row of b.table.cells) for (const cell of row) if (_optionalChain([cell, 'access', _310 => _310.blocks, 'optionalAccess', _311 => _311.length])) trimTrailingEmptyTableCols(cell.blocks);
|
|
6145
6167
|
trimTable(b.table);
|
|
6146
6168
|
}
|
|
6147
6169
|
}
|
|
@@ -6161,7 +6183,7 @@ function mergeSliverColumns(grid, colXs, maxWidth) {
|
|
|
6161
6183
|
}
|
|
6162
6184
|
const ok = owner.every((row) => {
|
|
6163
6185
|
const o = row[c];
|
|
6164
|
-
return !!o && (o.colSpan > 1 || !o.text.trim() && !_optionalChain([o, 'access',
|
|
6186
|
+
return !!o && (o.colSpan > 1 || !o.text.trim() && !_optionalChain([o, 'access', _312 => _312.blocks, 'optionalAccess', _313 => _313.length]));
|
|
6165
6187
|
});
|
|
6166
6188
|
if (!ok) continue;
|
|
6167
6189
|
const spanning = /* @__PURE__ */ new Set();
|
|
@@ -6188,7 +6210,7 @@ var multiply = (m, t) => [
|
|
|
6188
6210
|
m[1] * t[4] + m[3] * t[5] + m[5]
|
|
6189
6211
|
];
|
|
6190
6212
|
function hollowCircle(image) {
|
|
6191
|
-
if (!_optionalChain([image, 'optionalAccess',
|
|
6213
|
+
if (!_optionalChain([image, 'optionalAccess', _314 => _314.data]) || image.width < 16 || image.width > 128 || image.height < 16 || image.height > 128 || Math.abs(image.width - image.height) > Math.min(image.width, image.height) * 0.1) return false;
|
|
6192
6214
|
const stride = image.kind === _pdfmjs.ImageKind.RGB_24BPP ? 3 : image.kind === _pdfmjs.ImageKind.RGBA_32BPP ? 4 : 0;
|
|
6193
6215
|
const { width, height, data } = image;
|
|
6194
6216
|
if (!stride || data.length < width * height * stride) return false;
|
|
@@ -6253,9 +6275,9 @@ function smallVisibleImagePaints(fnArray, argsArray) {
|
|
|
6253
6275
|
const op = fnArray[i], args = argsArray[i];
|
|
6254
6276
|
if (op === _pdfmjs.OPS.save || op === _pdfmjs.OPS.paintFormXObjectBegin) {
|
|
6255
6277
|
stack.push({ ctm, alpha, clip, unknownClip });
|
|
6256
|
-
const matrix = op === _pdfmjs.OPS.paintFormXObjectBegin ? _optionalChain([args, 'optionalAccess',
|
|
6278
|
+
const matrix = op === _pdfmjs.OPS.paintFormXObjectBegin ? _optionalChain([args, 'optionalAccess', _315 => _315[0]]) : void 0;
|
|
6257
6279
|
if (Array.isArray(matrix) && matrix.length >= 6) ctm = multiply(ctm, matrix);
|
|
6258
|
-
const bounds = op === _pdfmjs.OPS.paintFormXObjectBegin ? _optionalChain([args, 'optionalAccess',
|
|
6280
|
+
const bounds = op === _pdfmjs.OPS.paintFormXObjectBegin ? _optionalChain([args, 'optionalAccess', _316 => _316[1]]) : void 0;
|
|
6259
6281
|
if (Array.isArray(bounds) && bounds.length === 4) {
|
|
6260
6282
|
const box = rectangle(bounds[0], bounds[1], bounds[2] - bounds[0], bounds[3] - bounds[1]);
|
|
6261
6283
|
if (box && ctm[1] === 0 && ctm[2] === 0) intersectClip(box);
|
|
@@ -6263,17 +6285,17 @@ function smallVisibleImagePaints(fnArray, argsArray) {
|
|
|
6263
6285
|
}
|
|
6264
6286
|
} else if (op === _pdfmjs.OPS.restore || op === _pdfmjs.OPS.paintFormXObjectEnd) {
|
|
6265
6287
|
const state = stack.pop();
|
|
6266
|
-
ctm = _nullishCoalesce(_optionalChain([state, 'optionalAccess',
|
|
6267
|
-
alpha = _nullishCoalesce(_optionalChain([state, 'optionalAccess',
|
|
6268
|
-
clip = _nullishCoalesce(_optionalChain([state, 'optionalAccess',
|
|
6269
|
-
unknownClip = _nullishCoalesce(_optionalChain([state, 'optionalAccess',
|
|
6288
|
+
ctm = _nullishCoalesce(_optionalChain([state, 'optionalAccess', _317 => _317.ctm]), () => ( [1, 0, 0, 1, 0, 0]));
|
|
6289
|
+
alpha = _nullishCoalesce(_optionalChain([state, 'optionalAccess', _318 => _318.alpha]), () => ( 1));
|
|
6290
|
+
clip = _nullishCoalesce(_optionalChain([state, 'optionalAccess', _319 => _319.clip]), () => ( null));
|
|
6291
|
+
unknownClip = _nullishCoalesce(_optionalChain([state, 'optionalAccess', _320 => _320.unknownClip]), () => ( false));
|
|
6270
6292
|
} else if (op === _pdfmjs.OPS.setGState) {
|
|
6271
|
-
for (const [key, value] of _nullishCoalesce(_optionalChain([args, 'optionalAccess',
|
|
6293
|
+
for (const [key, value] of _nullishCoalesce(_optionalChain([args, 'optionalAccess', _321 => _321[0]]), () => ( []))) {
|
|
6272
6294
|
if (key === "ca") alpha = typeof value === "number" ? value : 0;
|
|
6273
6295
|
}
|
|
6274
6296
|
} else if (op === _pdfmjs.OPS.constructPath) {
|
|
6275
6297
|
const [operations, coordinates] = args;
|
|
6276
|
-
pathRect = pathRect === void 0 && _optionalChain([operations, 'optionalAccess',
|
|
6298
|
+
pathRect = pathRect === void 0 && _optionalChain([operations, 'optionalAccess', _322 => _322.length]) === 1 && operations[0] === _pdfmjs.OPS.rectangle && _optionalChain([coordinates, 'optionalAccess', _323 => _323.length]) >= 4 && ctm[1] === 0 && ctm[2] === 0 ? rectangle(coordinates[0], coordinates[1], coordinates[2], coordinates[3]) : null;
|
|
6277
6299
|
} else if (op === _pdfmjs.OPS.clip || op === _pdfmjs.OPS.eoClip) pendingClip = true;
|
|
6278
6300
|
else if ([
|
|
6279
6301
|
_pdfmjs.OPS.endPath,
|
|
@@ -6293,7 +6315,7 @@ function smallVisibleImagePaints(fnArray, argsArray) {
|
|
|
6293
6315
|
pendingClip = false;
|
|
6294
6316
|
pathRect = void 0;
|
|
6295
6317
|
} else if (op === _pdfmjs.OPS.transform && Array.isArray(args) && args.length >= 6) ctm = multiply(ctm, args);
|
|
6296
|
-
else if (op === _pdfmjs.OPS.paintImageXObject && typeof _optionalChain([args, 'optionalAccess',
|
|
6318
|
+
else if (op === _pdfmjs.OPS.paintImageXObject && typeof _optionalChain([args, 'optionalAccess', _324 => _324[0]]) === "string") {
|
|
6297
6319
|
if (typeof args[1] !== "number" || typeof args[2] !== "number" || args[1] < 16 || args[1] > 128 || args[2] < 16 || args[2] > 128) continue;
|
|
6298
6320
|
const box = extractImageRegions([_pdfmjs.OPS.transform, _pdfmjs.OPS.paintImageXObject], [ctm, args])[0];
|
|
6299
6321
|
if (!box || ctm[1] !== 0 || ctm[2] !== 0 || alpha < 0.99 || unknownClip || clip && (box.x1 + (box.x2 - box.x1) * 0.03 < clip.x1 || box.y1 + (box.y2 - box.y1) * 0.03 < clip.y1 || box.x2 - (box.x2 - box.x1) * 0.03 > clip.x2 || box.y2 - (box.y2 - box.y1) * 0.03 > clip.y2)) continue;
|
|
@@ -6312,14 +6334,14 @@ async function restoreImageBullets(items, page, fnArray, argsArray, shapes = /*
|
|
|
6312
6334
|
const line = items.filter((item) => !item.isHidden && item.fontSize > 0 && item.x >= box.x2 && item.x - box.x2 <= item.fontSize * 0.7 && Math.abs(item.y + item.h / 2 - (box.y1 + box.y2) / 2) <= item.fontSize * 0.4 && height >= item.fontSize * 0.5 && height <= item.fontSize * 1.2).sort((a, b) => a.x - b.x)[0];
|
|
6313
6335
|
if (!line || /^[○●•◦□■∙]/.test(line.text.trim()) || !/\p{L}/u.test(line.text)) continue;
|
|
6314
6336
|
const row = items.filter((item) => Math.abs(item.y - line.y) <= 2 && item.x >= line.x);
|
|
6315
|
-
if (row.reduce((n, item) => n + (_nullishCoalesce(_optionalChain([item, 'access',
|
|
6337
|
+
if (row.reduce((n, item) => n + (_nullishCoalesce(_optionalChain([item, 'access', _325 => _325.text, 'access', _326 => _326.match, 'call', _327 => _327(/\p{L}/gu), 'optionalAccess', _328 => _328.length]), () => ( 0))), 0) < 12 || items.some((item) => item !== line && Math.abs(item.y - line.y) <= 2 && item.x < line.x)) continue;
|
|
6316
6338
|
candidates.push({ id, x: box.x1, width, line });
|
|
6317
6339
|
}
|
|
6318
6340
|
let restored = 0;
|
|
6319
6341
|
const used = /* @__PURE__ */ new Set();
|
|
6320
6342
|
for (const candidate of candidates) {
|
|
6321
6343
|
const same = candidates.filter((other) => other.id === candidate.id && other.line !== candidate.line && Math.abs(other.line.x - candidate.line.x) <= 1 && Math.abs(other.x - candidate.x) <= 1 && Math.abs(other.width - candidate.width) <= 1 && other.line.fontSize === candidate.line.fontSize && Math.abs(other.line.y - candidate.line.y) >= candidate.line.fontSize * 2);
|
|
6322
|
-
const numbered = items.filter((item) => !item.isHidden && /^[①-⑮]\s*/.test(item.text.trim()) && item.fontName === candidate.line.fontName && item.fontSize === candidate.line.fontSize && Math.abs(item.x - candidate.x) <= 1 && (_nullishCoalesce(_optionalChain([item, 'access',
|
|
6344
|
+
const numbered = items.filter((item) => !item.isHidden && /^[①-⑮]\s*/.test(item.text.trim()) && item.fontName === candidate.line.fontName && item.fontSize === candidate.line.fontSize && Math.abs(item.x - candidate.x) <= 1 && (_nullishCoalesce(_optionalChain([item, 'access', _329 => _329.text, 'access', _330 => _330.match, 'call', _331 => _331(/\p{L}/gu), 'optionalAccess', _332 => _332.length]), () => ( 0))) >= 12).sort((a, b) => b.y - a.y);
|
|
6323
6345
|
const numberedList = numbered.some((item, index) => index > 0 && item.text.trim().charCodeAt(0) === numbered[index - 1].text.trim().charCodeAt(0) + 1);
|
|
6324
6346
|
if (!same.length && !numberedList || used.has(candidate.line)) continue;
|
|
6325
6347
|
if (!shapes.has(candidate.id)) shapes.set(candidate.id, hollowCircle(await resolveImagePixels(page, candidate.id)));
|
|
@@ -6385,7 +6407,7 @@ function groupFlowBoxUnits(blocks, grids, hs, vs, images) {
|
|
|
6385
6407
|
return units;
|
|
6386
6408
|
}
|
|
6387
6409
|
function arrowDirection(image) {
|
|
6388
|
-
if (!_optionalChain([image, 'optionalAccess',
|
|
6410
|
+
if (!_optionalChain([image, 'optionalAccess', _333 => _333.data]) || image.width < 16 || image.width > 128 || image.height < 16 || image.height > 128) return 0;
|
|
6389
6411
|
const { width, height, data } = image;
|
|
6390
6412
|
const stride = image.kind === _pdfmjs.ImageKind.RGB_24BPP ? 3 : image.kind === _pdfmjs.ImageKind.RGBA_32BPP ? 4 : 0;
|
|
6391
6413
|
if (!stride || data.length < width * height * stride) return 0;
|
|
@@ -6453,7 +6475,7 @@ function isSideTabTable(box, table, others, pageWidth, pageHeight) {
|
|
|
6453
6475
|
function removeSideTabs(blocks, pageWidths) {
|
|
6454
6476
|
const edges = /* @__PURE__ */ new Map();
|
|
6455
6477
|
for (const b of blocks) {
|
|
6456
|
-
if (!b.bbox || b.pageNumber === void 0 || [..._nullishCoalesce(_optionalChain([b, 'access',
|
|
6478
|
+
if (!b.bbox || b.pageNumber === void 0 || [..._nullishCoalesce(_optionalChain([b, 'access', _334 => _334.text, 'optionalAccess', _335 => _335.trim, 'call', _336 => _336()]), () => ( ""))].length <= MAX_CHARS) continue;
|
|
6457
6479
|
const e = _nullishCoalesce(edges.get(b.pageNumber), () => ( { lefts: [], rights: [] }));
|
|
6458
6480
|
e.lefts.push(b.bbox.x);
|
|
6459
6481
|
e.rights.push(b.bbox.x + b.bbox.width);
|
|
@@ -6469,7 +6491,7 @@ function removeSideTabs(blocks, pageWidths) {
|
|
|
6469
6491
|
const fallback = all.length ? { left: q(all.map((e) => e.left), 0.5), right: q(all.map((e) => e.right), 0.5) } : void 0;
|
|
6470
6492
|
const key = (b) => {
|
|
6471
6493
|
const w = b.pageNumber !== void 0 ? pageWidths.get(b.pageNumber) : void 0;
|
|
6472
|
-
const text = _optionalChain([b, 'access',
|
|
6494
|
+
const text = _optionalChain([b, 'access', _337 => _337.text, 'optionalAccess', _338 => _338.trim, 'call', _339 => _339()]);
|
|
6473
6495
|
const area = _nullishCoalesce((b.pageNumber !== void 0 ? body.get(b.pageNumber) : void 0), () => ( fallback));
|
|
6474
6496
|
if (b.type === "table") {
|
|
6475
6497
|
if (!w || !b.bbox || !b.table || !SIDE_TAB_TABLES.has(b.table)) return null;
|
|
@@ -6902,16 +6924,16 @@ function isProseSpread(items) {
|
|
|
6902
6924
|
for (let i = 1; i < sorted.length; i++) {
|
|
6903
6925
|
gaps.push(sorted[i].x - (sorted[i - 1].x + sorted[i - 1].w));
|
|
6904
6926
|
}
|
|
6905
|
-
const maxGap =
|
|
6927
|
+
const maxGap = _chunkAUWO57EDcjs.safeMax.call(void 0, gaps);
|
|
6906
6928
|
const avgLen = items.reduce((s, i) => s + i.text.length, 0) / items.length;
|
|
6907
6929
|
if (items.length >= 4 && maxGap < 40 && avgLen < 5) return true;
|
|
6908
|
-
const minGap =
|
|
6930
|
+
const minGap = _chunkAUWO57EDcjs.safeMin.call(void 0, gaps);
|
|
6909
6931
|
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 || items.some((i) => /\p{L}[,.;:]["”’)]?$/u.test(i.text)));
|
|
6910
6932
|
}
|
|
6911
6933
|
function detectColumns(yLines) {
|
|
6912
6934
|
const allItems = yLines.flat();
|
|
6913
6935
|
if (allItems.length === 0) return null;
|
|
6914
|
-
const pageWidth =
|
|
6936
|
+
const pageWidth = _chunkAUWO57EDcjs.safeMax.call(void 0, allItems.map((i) => i.x + i.w)) - _chunkAUWO57EDcjs.safeMin.call(void 0, allItems.map((i) => i.x));
|
|
6915
6937
|
if (pageWidth < 100) return null;
|
|
6916
6938
|
let bigoLineIdx = -1;
|
|
6917
6939
|
for (let i = 0; i < yLines.length; i++) {
|
|
@@ -7136,7 +7158,7 @@ var UNDER_BOX_PAIR_MAX_EM = 2.2;
|
|
|
7136
7158
|
var UNDER_BOX_PAIR_OVERLAP = 0.8;
|
|
7137
7159
|
function markUnderlineItems(items, horizontals, verticals, nonRules) {
|
|
7138
7160
|
const underlines = [];
|
|
7139
|
-
if (_optionalChain([nonRules, 'optionalAccess',
|
|
7161
|
+
if (_optionalChain([nonRules, 'optionalAccess', _340 => _340.size])) horizontals = horizontals.filter((line) => !nonRules.has(line));
|
|
7140
7162
|
if (items.length === 0 || horizontals.length === 0) return underlines;
|
|
7141
7163
|
const tightOwners = /* @__PURE__ */ new Map();
|
|
7142
7164
|
const tightlyOwned = (line) => {
|
|
@@ -7242,7 +7264,7 @@ function hasBoxTopPair(line, maxH, horizontals, cellItems) {
|
|
|
7242
7264
|
if (ow <= 0) continue;
|
|
7243
7265
|
const overlap2 = Math.min(line.x2, o.x2) - Math.max(line.x1, o.x1);
|
|
7244
7266
|
if (overlap2 / Math.max(w, ow) < UNDER_BOX_PAIR_OVERLAP) continue;
|
|
7245
|
-
const covered = _nullishCoalesce(_optionalChain([cellItems, 'optionalAccess',
|
|
7267
|
+
const covered = _nullishCoalesce(_optionalChain([cellItems, 'optionalAccess', _341 => _341.reduce, 'call', _342 => _342((sum, item) => {
|
|
7246
7268
|
const below = item.y - o.y1;
|
|
7247
7269
|
if (below < 0.5 || below > 3 || !item.text.trim()) return sum;
|
|
7248
7270
|
return sum + Math.max(0, Math.min(o.x2, item.x + item.w) - Math.max(o.x1, item.x));
|
|
@@ -7403,12 +7425,12 @@ function rebuildUnitLine(items, grid) {
|
|
|
7403
7425
|
function prependUnitRow(cells, cols, line, usedItems) {
|
|
7404
7426
|
const text = cleanCellText(line.map((item) => item.text).join(""));
|
|
7405
7427
|
cells.unshift(Array.from({ length: cols }, (_, c) => ({ text: c === 0 ? text : "", colSpan: c === 0 ? cols : 1, rowSpan: 1 })));
|
|
7406
|
-
for (const cell of cells[0])
|
|
7428
|
+
for (const cell of cells[0]) _chunkMED2MR6Ocjs.CELL_EDGES.set(cell, NO_EDGES);
|
|
7407
7429
|
for (const item of line) usedItems.add(item);
|
|
7408
7430
|
}
|
|
7409
7431
|
function attachUnitRow(items, grid, cells, cols, usedItems) {
|
|
7410
7432
|
const all = cells.flat();
|
|
7411
|
-
if (all.filter((c) => c.text.trim()).length * 2 < all.length || UNIT.test(_nullishCoalesce(_optionalChain([cells, 'access',
|
|
7433
|
+
if (all.filter((c) => c.text.trim()).length * 2 < all.length || UNIT.test(_nullishCoalesce(_optionalChain([cells, 'access', _343 => _343[0], 'optionalAccess', _344 => _344[0], 'optionalAccess', _345 => _345.text]), () => ( "")))) return false;
|
|
7412
7434
|
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);
|
|
7413
7435
|
let nearest = Infinity;
|
|
7414
7436
|
for (const it of above) nearest = Math.min(nearest, it.y);
|
|
@@ -7443,7 +7465,7 @@ function closeShadedTableEdges(clipGrids, horizontals, verticals, fillRects) {
|
|
|
7443
7465
|
let hs = horizontals, vs = verticals;
|
|
7444
7466
|
const restored = [];
|
|
7445
7467
|
for (const grid of clipGrids) {
|
|
7446
|
-
if (grid.clipParent || grid.rowYs.length !== 2 || grid.colXs.length < 3 || !_optionalChain([grid, 'access',
|
|
7468
|
+
if (grid.clipParent || grid.rowYs.length !== 2 || grid.colXs.length < 3 || !_optionalChain([grid, 'access', _346 => _346.cells, 'optionalAccess', _347 => _347.length]) || grid.cells.some((c) => c.filler || c.rowSpan !== 1 || c.colSpan !== 1)) continue;
|
|
7447
7469
|
const { x1, x2, y1: mid, y2: top } = grid.bbox;
|
|
7448
7470
|
if (!grid.cells.every((c) => fillRects.some((f) => near2(f.x1, c.bbox.x1) && near2(f.x2, c.bbox.x2) && near2(f.y1, c.bbox.y1) && near2(f.y2, c.bbox.y2)))) continue;
|
|
7449
7471
|
const topRule = hs.find((h) => near2(h.y1, top) && near2(h.x1, x1) && near2(h.x2, x2));
|
|
@@ -7857,7 +7879,7 @@ function takeFrameSpanningText(items, cutX, pageNum, lex) {
|
|
|
7857
7879
|
const rows = groupByY([...items].sort((a, b) => b.y - a.y || a.x - b.x)).map((line) => {
|
|
7858
7880
|
const runs = [];
|
|
7859
7881
|
for (const item of [...line].sort((a, b) => a.x - b.x)) {
|
|
7860
|
-
const run = runs[runs.length - 1], prev = _optionalChain([run, 'optionalAccess',
|
|
7882
|
+
const run = runs[runs.length - 1], prev = _optionalChain([run, 'optionalAccess', _348 => _348[run.length - 1]]);
|
|
7861
7883
|
if (prev && item.x - (prev.x + prev.w) <= Math.max(prev.fontSize, item.fontSize) * 0.6) run.push(item);
|
|
7862
7884
|
else runs.push([item]);
|
|
7863
7885
|
}
|
|
@@ -7901,7 +7923,7 @@ function groupFrameParagraphUnits(units, frames) {
|
|
|
7901
7923
|
for (const unit of units) for (const block of unit) source.set(block, unit);
|
|
7902
7924
|
const members = /* @__PURE__ */ new Map(), emitted = /* @__PURE__ */ new Set();
|
|
7903
7925
|
for (const frame of frames) {
|
|
7904
|
-
if (frame.length < 2 || frame.some((block) => block.type !== "paragraph" || _optionalChain([source, 'access',
|
|
7926
|
+
if (frame.length < 2 || frame.some((block) => block.type !== "paragraph" || _optionalChain([source, 'access', _349 => _349.get, 'call', _350 => _350(block), 'optionalAccess', _351 => _351.length]) !== 1)) continue;
|
|
7905
7927
|
for (const block of frame) members.set(block, frame);
|
|
7906
7928
|
}
|
|
7907
7929
|
const out = [];
|
|
@@ -7914,7 +7936,7 @@ function groupFrameParagraphUnits(units, frames) {
|
|
|
7914
7936
|
}
|
|
7915
7937
|
}
|
|
7916
7938
|
for (const unit of out) {
|
|
7917
|
-
if (unit.length < 2 || _optionalChain([FRAME_READING_UNITS, 'access',
|
|
7939
|
+
if (unit.length < 2 || _optionalChain([FRAME_READING_UNITS, 'access', _352 => _352.get, 'call', _353 => _353(unit[0]), 'optionalAccess', _354 => _354.blocks]) === unit) continue;
|
|
7918
7940
|
const bs = unit.map((b) => b.bbox).filter((b) => !!b);
|
|
7919
7941
|
if (bs.length !== unit.length) continue;
|
|
7920
7942
|
const x = Math.min(...bs.map((b) => b.x)), y = Math.min(...bs.map((b) => b.y));
|
|
@@ -7931,14 +7953,14 @@ function groupFrameParagraphUnits(units, frames) {
|
|
|
7931
7953
|
function recordFrameTitle(table, source, pageNum) {
|
|
7932
7954
|
if (!CLIP_TABLES.has(table) || table.rows !== 1 || table.cols !== 3 || source.length < 2) return;
|
|
7933
7955
|
const cells = table.cells[0];
|
|
7934
|
-
if (cells.length !== 3 || cells.some((c) => c.colSpan !== 1 || c.rowSpan !== 1 || _optionalChain([c, 'access',
|
|
7956
|
+
if (cells.length !== 3 || cells.some((c) => c.colSpan !== 1 || c.rowSpan !== 1 || _optionalChain([c, 'access', _355 => _355.blocks, 'optionalAccess', _356 => _356.length]) || c.text.includes("\n"))) return;
|
|
7935
7957
|
const [label, spacer, title] = cells;
|
|
7936
7958
|
if (!/^(?:붙임|별첨|첨부|부록)\s*\d{1,3}$/.test(label.text.trim()) || spacer.text.trim() || !title.text.trim()) return;
|
|
7937
7959
|
if (cells.some((c) => {
|
|
7938
|
-
const e =
|
|
7960
|
+
const e = _chunkMED2MR6Ocjs.CELL_EDGES.get(c);
|
|
7939
7961
|
return !e || e.t || e.b || e.l || e.r;
|
|
7940
7962
|
})) return;
|
|
7941
|
-
const xs = TABLE_COLXS.get(table), style = dominantStyle(source), fs = _nullishCoalesce(_optionalChain([style, 'optionalAccess',
|
|
7963
|
+
const xs = TABLE_COLXS.get(table), style = dominantStyle(source), fs = _nullishCoalesce(_optionalChain([style, 'optionalAccess', _357 => _357.fontSize]), () => ( 0));
|
|
7942
7964
|
if (!xs || xs.length !== 4 || fs <= 0) return;
|
|
7943
7965
|
const width = xs[3] - xs[0], gap = xs[2] - xs[1];
|
|
7944
7966
|
if (width < fs * 12 || gap <= 0 || gap > fs * 1.5 || xs[1] - xs[0] > width * 0.25 || xs[3] - xs[2] < width * 0.6) return;
|
|
@@ -7996,7 +8018,7 @@ function extendNestedShadedHeaders(clipGrids, lineGrids, horizontals, verticals,
|
|
|
7996
8018
|
const extended = [];
|
|
7997
8019
|
for (let i = 0; i < clipGrids.length; i++) {
|
|
7998
8020
|
const c = clipGrids[i], parent = c.clipParent;
|
|
7999
|
-
if (!parent || c.rowYs.length !== 2 || c.colXs.length < 3 || !_optionalChain([c, 'access',
|
|
8021
|
+
if (!parent || c.rowYs.length !== 2 || c.colXs.length < 3 || !_optionalChain([c, 'access', _358 => _358.cells, 'optionalAccess', _359 => _359.length]) || c.cells.some((cell) => cell.filler || cell.rowSpan !== 1 || cell.colSpan !== 1)) continue;
|
|
8000
8022
|
if (!clipGrids.some((g) => g.rowYs.length === 2 && g.colXs.length === 2 && near2(g.bbox.x1, parent.x1) && near2(g.bbox.x2, parent.x2) && near2(g.bbox.y1, parent.y1) && near2(g.bbox.y2, parent.y2))) continue;
|
|
8001
8023
|
if (!c.cells.every((cell) => fills.some((f) => near2(f.x1, cell.bbox.x1) && near2(f.x2, cell.bbox.x2) && near2(f.y1, cell.bbox.y1) && near2(f.y2, cell.bbox.y2)))) continue;
|
|
8002
8024
|
const host = lineGrids.find((l) => l.rowYs.length > 2 && l.colXs.length === c.colXs.length && c.colXs.every((x, k) => near2(x, l.colXs[k])) && c.rowYs.every((y, k) => near2(y, l.rowYs[k])) && contains4(parent, l.bbox) && l.rowYs.every((y) => horizontals.some((h) => near2(h.y1, y) && near2(h.x1, l.bbox.x1) && near2(h.x2, l.bbox.x2))) && l.colXs.every((x) => verticals.some((v) => near2(v.x1, x) && v.y1 <= l.bbox.y1 + 1.5 && v.y2 >= l.bbox.y2 - 1.5)) && !clipGrids.some((o) => o !== c && !contains4(o.bbox, l.bbox) && Math.min(o.bbox.x2, l.bbox.x2) > Math.max(o.bbox.x1, l.bbox.x1) && Math.min(o.bbox.y2, l.bbox.y2) > Math.max(o.bbox.y1, l.bbox.y1)));
|
|
@@ -8019,7 +8041,7 @@ function attachSideTabBlocks(tab, body, pageNum) {
|
|
|
8019
8041
|
bbox: computeBBox(items, pageNum),
|
|
8020
8042
|
style: dominantStyle(items)
|
|
8021
8043
|
});
|
|
8022
|
-
const prefix = ordered.filter((g) => !_optionalChain([caps, 'optionalAccess',
|
|
8044
|
+
const prefix = ordered.filter((g) => !_optionalChain([caps, 'optionalAccess', _360 => _360.has, 'call', _361 => _361(g)])).map((g) => ({
|
|
8023
8045
|
type: "paragraph",
|
|
8024
8046
|
text: g.text.trim(),
|
|
8025
8047
|
pageNumber: pageNum,
|
|
@@ -8028,7 +8050,7 @@ function attachSideTabBlocks(tab, body, pageNum) {
|
|
|
8028
8050
|
}));
|
|
8029
8051
|
const groups = /* @__PURE__ */ new Map();
|
|
8030
8052
|
for (const g of ordered) {
|
|
8031
|
-
const cap = _optionalChain([caps, 'optionalAccess',
|
|
8053
|
+
const cap = _optionalChain([caps, 'optionalAccess', _362 => _362.get, 'call', _363 => _363(g)]);
|
|
8032
8054
|
if (cap) groups.set(cap, [..._nullishCoalesce(groups.get(cap), () => ( [])), g]);
|
|
8033
8055
|
}
|
|
8034
8056
|
for (const [cap, glyphs] of groups) {
|
|
@@ -8062,7 +8084,7 @@ function extractPageBlocksWithLines(items, pageNum, opList, pageWidth, pageHeigh
|
|
|
8062
8084
|
const filled = fillBlanks(items, horizontals, verticals);
|
|
8063
8085
|
items = filled.items;
|
|
8064
8086
|
horizontals = filled.horizontals;
|
|
8065
|
-
const prevPage = _optionalChain([carry, 'optionalAccess',
|
|
8087
|
+
const prevPage = _optionalChain([carry, 'optionalAccess', _364 => _364.page]) === pageNum - 1 ? carry.clip : void 0;
|
|
8066
8088
|
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 };
|
|
8067
8089
|
if (carry) {
|
|
8068
8090
|
carry.page = pageNum;
|
|
@@ -8099,7 +8121,7 @@ function extractPageBlocksWithLines(items, pageNum, opList, pageWidth, pageHeigh
|
|
|
8099
8121
|
if (shadedEdges) ({ horizontals, verticals } = shadedEdges);
|
|
8100
8122
|
const lineGrids = detectTables ? buildTableGrids(horizontals, verticals, !(items.length > 0 && items.every((it) => it.fontName === "ocr"))) : [];
|
|
8101
8123
|
if (shadedEdges) nestRestoredShadedGrids(lineGrids, shadedEdges.restored, horizontals, verticals);
|
|
8102
|
-
const tableClipGrids = dropHeadBandClipGrids(dropInsetClipGrids(dropShadingClipGrids(clipGrids, lineGrids, extracted.fillRects, verticals), lineGrids), lineGrids);
|
|
8124
|
+
const tableClipGrids = dropHeadBandClipGrids(dropInsetClipGrids(dropShadingClipGrids(clipGrids, lineGrids, extracted.fillRects, verticals, horizontals), lineGrids), lineGrids);
|
|
8103
8125
|
recordClipCellEdges(
|
|
8104
8126
|
extendNestedShadedHeaders(tableClipGrids, lineGrids, horizontals, verticals, extracted.fillRects),
|
|
8105
8127
|
extracted.horizontals.concat(extracted.shortH),
|
|
@@ -8313,14 +8335,14 @@ function extractBlocksWithGrids(items, pageNum, pageWidth, pageHeight, grids, ho
|
|
|
8313
8335
|
if (!assignedItems.has(textItems[ti])) usedItems.delete(owners[ti]);
|
|
8314
8336
|
}
|
|
8315
8337
|
}
|
|
8316
|
-
if (unitLine.length > 0 && rebuiltUsed && !/^\s*\(\s*단위\s*[::]/.test(_nullishCoalesce(_optionalChain([finalGrid, 'access',
|
|
8338
|
+
if (unitLine.length > 0 && rebuiltUsed && !/^\s*\(\s*단위\s*[::]/.test(_nullishCoalesce(_optionalChain([finalGrid, 'access', _365 => _365[0], 'optionalAccess', _366 => _366[0], 'optionalAccess', _367 => _367.text]), () => ( "")))) {
|
|
8317
8339
|
prependUnitRow(finalGrid, numCols, unitLine, usedItems);
|
|
8318
8340
|
finalRows++;
|
|
8319
8341
|
}
|
|
8320
8342
|
if (!rebuiltUsed && attachUnitRow(items, grid, finalGrid, numCols, usedItems)) finalRows++;
|
|
8321
8343
|
let semanticOneColumn = false;
|
|
8322
8344
|
if (!grid.cells && !nestedAttached && numCols === 1 && numGridRows >= 2) {
|
|
8323
|
-
const populatedRows = finalGrid.filter((row) => _optionalChain([row, 'access',
|
|
8345
|
+
const populatedRows = finalGrid.filter((row) => _optionalChain([row, 'access', _368 => _368[0], 'optionalAccess', _369 => _369.text, 'access', _370 => _370.trim, 'call', _371 => _371()]));
|
|
8324
8346
|
if (populatedRows.length >= 4) {
|
|
8325
8347
|
const fontSizes = tableItems.map((item) => item.fontSize).filter((size) => size > 0).sort((a, b) => a - b);
|
|
8326
8348
|
const medianFont = _nullishCoalesce(fontSizes[Math.floor(fontSizes.length / 2)], () => ( 0));
|
|
@@ -8416,7 +8438,7 @@ function extractBlocksWithGrids(items, pageNum, pageWidth, pageHeight, grids, ho
|
|
|
8416
8438
|
height: grid.bbox.y2 - grid.bbox.y1
|
|
8417
8439
|
};
|
|
8418
8440
|
if (numRows === 1 && numCols === 1 && gridW < pageWidth * 0.35) {
|
|
8419
|
-
const prose = _nullishCoalesce(_optionalChain([finalGrid, 'access',
|
|
8441
|
+
const prose = _nullishCoalesce(_optionalChain([finalGrid, 'access', _372 => _372[0], 'optionalAccess', _373 => _373[0], 'optionalAccess', _374 => _374.text]), () => ( ""));
|
|
8420
8442
|
const besideLines = (side) => new Set(side.map((it) => Math.round(it.y / 3))).size;
|
|
8421
8443
|
const rightLines = items.filter((it) => it.x >= grid.bbox.x2 + 3 && it.y >= grid.bbox.y1 && it.y <= grid.bbox.y2);
|
|
8422
8444
|
const leftLines = items.filter((it) => it.x + it.w <= grid.bbox.x1 - 3 && it.y >= grid.bbox.y1 && it.y <= grid.bbox.y2);
|
|
@@ -8435,8 +8457,8 @@ function extractBlocksWithGrids(items, pageNum, pageWidth, pageHeight, grids, ho
|
|
|
8435
8457
|
}
|
|
8436
8458
|
}
|
|
8437
8459
|
if (!grid.cells && !nestedAttached && shouldDemoteTable(irTable)) {
|
|
8438
|
-
const paragraphs = numRows === 1 && numCols === 1 ? _optionalChain([irTable, 'access',
|
|
8439
|
-
if (_optionalChain([paragraphs, 'optionalAccess',
|
|
8460
|
+
const paragraphs = numRows === 1 && numCols === 1 ? _optionalChain([irTable, 'access', _375 => _375.cells, 'access', _376 => _376[0], 'optionalAccess', _377 => _377[0], 'optionalAccess', _378 => _378.blocks]) : void 0;
|
|
8461
|
+
if (_optionalChain([paragraphs, 'optionalAccess', _379 => _379.length])) {
|
|
8440
8462
|
blocks.push(...paragraphs);
|
|
8441
8463
|
frameParagraphUnits.push(paragraphs);
|
|
8442
8464
|
recordFrameReadingUnit(paragraphs, tableBbox);
|
|
@@ -8479,7 +8501,7 @@ function extractBlocksWithGrids(items, pageNum, pageWidth, pageHeight, grids, ho
|
|
|
8479
8501
|
const clusterResults = (proseColumns ? [] : detectClusterTables(clusterItems, pageNum, void 0, lex)).filter((cr) => {
|
|
8480
8502
|
const b = cr.bbox;
|
|
8481
8503
|
const overlapX = (x) => Math.min(x.x + x.width, b.x + b.width) - Math.max(x.x, b.x);
|
|
8482
|
-
return !blocks.some((x) => x.bbox && x.bbox.y >= b.y - 2 && x.bbox.y + x.bbox.height <= b.y + b.height + 2 && (x.type === "paragraph" ? (_nullishCoalesce(_optionalChain([x, 'access',
|
|
8504
|
+
return !blocks.some((x) => x.bbox && x.bbox.y >= b.y - 2 && x.bbox.y + x.bbox.height <= b.y + b.height + 2 && (x.type === "paragraph" ? (_nullishCoalesce(_optionalChain([x, 'access', _380 => _380.text, 'optionalAccess', _381 => _381.match, 'call', _382 => _382(/\p{L}/gu), 'optionalAccess', _383 => _383.length]), () => ( 0))) >= 10 && overlapX(x.bbox) >= 0.8 * b.width : x.type === "table" && !ocrPage && _optionalChain([x, 'access', _384 => _384.table, 'optionalAccess', _385 => _385.cols]) === cr.table.cols && overlapX(x.bbox) >= 0.5 * Math.min(x.bbox.width, b.width)));
|
|
8483
8505
|
});
|
|
8484
8506
|
if (clusterResults.length > 0) {
|
|
8485
8507
|
const ciToIdx = /* @__PURE__ */ new Map();
|
|
@@ -8516,7 +8538,7 @@ function extractBlocksWithGrids(items, pageNum, pageWidth, pageHeight, grids, ho
|
|
|
8516
8538
|
groupSizes.push(1);
|
|
8517
8539
|
}
|
|
8518
8540
|
const allY = remaining.map((i) => i.y);
|
|
8519
|
-
const pageH =
|
|
8541
|
+
const pageH = _chunkAUWO57EDcjs.safeMax.call(void 0, allY) - _chunkAUWO57EDcjs.safeMin.call(void 0, allY);
|
|
8520
8542
|
const gapThreshold = Math.max(15, pageH * 0.03);
|
|
8521
8543
|
const sides = frameColumnTextBands(remaining, spanning, gx);
|
|
8522
8544
|
const textBlocks = [];
|
|
@@ -8532,7 +8554,7 @@ function extractBlocksWithGrids(items, pageNum, pageWidth, pageHeight, grids, ho
|
|
|
8532
8554
|
finalTextBlocks.push(...detectListBlocks(textBlocks));
|
|
8533
8555
|
} else {
|
|
8534
8556
|
const allY = remaining.map((i) => i.y);
|
|
8535
|
-
const pageH =
|
|
8557
|
+
const pageH = _chunkAUWO57EDcjs.safeMax.call(void 0, allY) - _chunkAUWO57EDcjs.safeMin.call(void 0, allY);
|
|
8536
8558
|
const gapThreshold = Math.max(15, pageH * 0.03);
|
|
8537
8559
|
const groups = xyCutOrder(remaining, gapThreshold);
|
|
8538
8560
|
const textBlocks = [];
|
|
@@ -8860,7 +8882,7 @@ function extractPageBlocksFallback(items, pageNum, fullPage = false, detectTable
|
|
|
8860
8882
|
blocks.push(...columnTextToBlocks(tableText, pageNum, bbox, dominantStyle(items)));
|
|
8861
8883
|
} else {
|
|
8862
8884
|
const allY = items.map((i) => i.y);
|
|
8863
|
-
const pageHeight =
|
|
8885
|
+
const pageHeight = _chunkAUWO57EDcjs.safeMax.call(void 0, allY) - _chunkAUWO57EDcjs.safeMin.call(void 0, allY);
|
|
8864
8886
|
const gapThreshold = Math.max(15, pageHeight * 0.03);
|
|
8865
8887
|
const orderedGroups = proseCutX !== null ? splitTwoColumnProse(items, proseCutX) : xyCutOrder(items, gapThreshold, 0, void 0, minGap);
|
|
8866
8888
|
for (const group of orderedGroups) {
|
|
@@ -8892,17 +8914,17 @@ function mergeOcrImageRegions(blocks, page, regions, ocrBlocks) {
|
|
|
8892
8914
|
const overlapH = Math.max(0, Math.min(b.y + b.height, region.y2) - Math.max(b.y, region.y1));
|
|
8893
8915
|
return overlapW * overlapH >= b.width * b.height * 0.8;
|
|
8894
8916
|
});
|
|
8895
|
-
const labels = candidates.filter((b) => b.type === "paragraph" && b.bbox.height <= 24 && (_nullishCoalesce(_optionalChain([b, 'access',
|
|
8917
|
+
const labels = candidates.filter((b) => b.type === "paragraph" && b.bbox.height <= 24 && (_nullishCoalesce(_optionalChain([b, 'access', _386 => _386.text, 'optionalAccess', _387 => _387.match, 'call', _388 => _388(/[\p{L}\p{N}]/gu), 'optionalAccess', _389 => _389.length]), () => ( 0))) >= 2);
|
|
8896
8918
|
const axisFragments = rotatedAxisFragments(candidates);
|
|
8897
8919
|
const accepted = candidates.filter((b) => {
|
|
8898
|
-
if (b.type === "paragraph") return (_nullishCoalesce(_optionalChain([b, 'access',
|
|
8920
|
+
if (b.type === "paragraph") return (_nullishCoalesce(_optionalChain([b, 'access', _390 => _390.text, 'optionalAccess', _391 => _391.match, 'call', _392 => _392(/[\p{L}\p{N}]/gu), 'optionalAccess', _393 => _393.length]), () => ( 0))) >= 2 || !axisFragments.has(b) && (supportedDiagramLabel(b, labels, region) || axisTick(b, candidates));
|
|
8899
8921
|
const t = b.table;
|
|
8900
8922
|
if (b.type !== "table" || !t || UNRULED_REGION_TABLES.has(b)) return false;
|
|
8901
8923
|
if (t.rows === 1 && t.cols === 1) {
|
|
8902
|
-
const text = _nullishCoalesce(_optionalChain([t, 'access',
|
|
8903
|
-
return (_nullishCoalesce(_optionalChain([text, 'access',
|
|
8924
|
+
const text = _nullishCoalesce(_optionalChain([t, 'access', _394 => _394.cells, 'access', _395 => _395[0], 'optionalAccess', _396 => _396[0], 'optionalAccess', _397 => _397.text]), () => ( ""));
|
|
8925
|
+
return (_nullishCoalesce(_optionalChain([text, 'access', _398 => _398.match, 'call', _399 => _399(/\n/g), 'optionalAccess', _400 => _400.length]), () => ( 0))) >= 5 && (_nullishCoalesce(_optionalChain([text, 'access', _401 => _401.match, 'call', _402 => _402(/\d/g), 'optionalAccess', _403 => _403.length]), () => ( 0))) >= text.length * 0.25;
|
|
8904
8926
|
}
|
|
8905
|
-
const headerLabels = _nullishCoalesce(_optionalChain([t, 'access',
|
|
8927
|
+
const headerLabels = _nullishCoalesce(_optionalChain([t, 'access', _404 => _404.cells, 'access', _405 => _405[0], 'optionalAccess', _406 => _406.filter, 'call', _407 => _407((c) => c.text.replace(/[^A-Za-z가-힣]/g, "").length >= 2), 'access', _408 => _408.length]), () => ( 0));
|
|
8906
8928
|
return t.rows >= 2 && t.cols >= 2 && headerLabels >= t.cols * 0.75 && t.cells.slice(1).some((row) => row.filter((c) => c.text.trim()).length >= 2);
|
|
8907
8929
|
});
|
|
8908
8930
|
const selected = candidates.flatMap((b) => accepted.includes(b) ? [b] : b.type === "table" && b.table ? rowParagraphs(b).filter((p) => /[\p{L}\p{N}]{2}/u.test(_nullishCoalesce(p.text, () => ( "")))) : []);
|
|
@@ -8919,14 +8941,14 @@ function mergeOcrImageRegions(blocks, page, regions, ocrBlocks) {
|
|
|
8919
8941
|
for (const block of selected) {
|
|
8920
8942
|
if (seen2.has(block)) continue;
|
|
8921
8943
|
const frame = FRAME_READING_UNITS.get(block);
|
|
8922
|
-
const source = _optionalChain([frame, 'optionalAccess',
|
|
8944
|
+
const source = _optionalChain([frame, 'optionalAccess', _409 => _409.blocks, 'access', _410 => _410.every, 'call', _411 => _411((member) => selectedSet.has(member))]) ? frame.blocks : [block];
|
|
8923
8945
|
source.forEach((member) => seen2.add(member));
|
|
8924
8946
|
const available = source.filter((member) => !hasOriginal(member));
|
|
8925
8947
|
const units = frame && available.length === source.length && source === frame.blocks ? [{ blocks: available, bbox: frame.bbox, atomic: true }] : available.map((member) => ({ blocks: [member], bbox: member.bbox, atomic: false }));
|
|
8926
8948
|
for (const unit of units) {
|
|
8927
8949
|
const b = unit.bbox;
|
|
8928
8950
|
const index = blocks.findIndex((existing) => {
|
|
8929
|
-
const e = _nullishCoalesce(_optionalChain([FRAME_READING_UNITS, 'access',
|
|
8951
|
+
const e = _nullishCoalesce(_optionalChain([FRAME_READING_UNITS, 'access', _412 => _412.get, 'call', _413 => _413(existing), 'optionalAccess', _414 => _414.bbox]), () => ( existing.bbox));
|
|
8930
8952
|
if (existing.pageNumber !== page || !e) return false;
|
|
8931
8953
|
const beside = e.y < region.y2 && e.y + e.height > region.y1 && e.x >= region.x2 - 1;
|
|
8932
8954
|
if (placedHere.has(existing) && Math.abs(e.y + e.height / 2 - b.y - b.height / 2) <= Math.min(e.height, b.height) * 0.25) return e.x > b.x;
|
|
@@ -8944,16 +8966,16 @@ function mergeOcrImageRegions(blocks, page, regions, ocrBlocks) {
|
|
|
8944
8966
|
}
|
|
8945
8967
|
function axisTick(block, candidates) {
|
|
8946
8968
|
const b = block.bbox;
|
|
8947
|
-
if (!/^\d$/u.test(_nullishCoalesce(_optionalChain([block, 'access',
|
|
8948
|
-
const numeric = candidates.filter((o) => o !== block && o.type === "paragraph" && o.bbox && /^[\d\s.,%+−-]+$/u.test(_nullishCoalesce(_optionalChain([o, 'access',
|
|
8969
|
+
if (!/^\d$/u.test(_nullishCoalesce(_optionalChain([block, 'access', _415 => _415.text, 'optionalAccess', _416 => _416.trim, 'call', _417 => _417()]), () => ( "")))) return false;
|
|
8970
|
+
const numeric = candidates.filter((o) => o !== block && o.type === "paragraph" && o.bbox && /^[\d\s.,%+−-]+$/u.test(_nullishCoalesce(_optionalChain([o, 'access', _418 => _418.text, 'optionalAccess', _419 => _419.trim, 'call', _420 => _420()]), () => ( ""))) && /\d/u.test(_nullishCoalesce(o.text, () => ( ""))) && Math.max(o.bbox.height, b.height) <= Math.min(o.bbox.height, b.height) * 2);
|
|
8949
8971
|
const cy = b.y + b.height / 2, right = b.x + b.width;
|
|
8950
8972
|
const row = numeric.filter((o) => Math.abs(o.bbox.y + o.bbox.height / 2 - cy) <= Math.min(o.bbox.height, b.height) * 0.35);
|
|
8951
8973
|
const column = numeric.filter((o) => Math.abs(o.bbox.x + o.bbox.width - right) <= Math.max(o.bbox.height, b.height) * 0.5);
|
|
8952
8974
|
return row.length >= 2 || column.length >= 2;
|
|
8953
8975
|
}
|
|
8954
8976
|
function supportedDiagramLabel(block, labels, region) {
|
|
8955
|
-
const b = block.bbox, text = _nullishCoalesce(_optionalChain([block, 'access',
|
|
8956
|
-
if (!b || !/^[\p{L}\p{N}]$/u.test(text) || b.height < 4 || b.width < 1 || b.width > b.height * 2 || b.x < region.x1 || b.y < region.y1 || b.x + b.width > region.x2 || b.y + b.height > region.y2 || b.width * b.height > (region.x2 - region.x1) * (region.y2 - region.y1) * 5e-3 || labels.length < 3 || !labels.some((l) => /\p{L}{3}/u.test(_nullishCoalesce(l.text, () => ( "")))) || labels.filter((l) => !/\p{L}/u.test(_nullishCoalesce(l.text, () => ( ""))) && (_nullishCoalesce(_optionalChain([l, 'access',
|
|
8977
|
+
const b = block.bbox, text = _nullishCoalesce(_optionalChain([block, 'access', _421 => _421.text, 'optionalAccess', _422 => _422.trim, 'call', _423 => _423()]), () => ( ""));
|
|
8978
|
+
if (!b || !/^[\p{L}\p{N}]$/u.test(text) || b.height < 4 || b.width < 1 || b.width > b.height * 2 || b.x < region.x1 || b.y < region.y1 || b.x + b.width > region.x2 || b.y + b.height > region.y2 || b.width * b.height > (region.x2 - region.x1) * (region.y2 - region.y1) * 5e-3 || labels.length < 3 || !labels.some((l) => /\p{L}{3}/u.test(_nullishCoalesce(l.text, () => ( "")))) || labels.filter((l) => !/\p{L}/u.test(_nullishCoalesce(l.text, () => ( ""))) && (_nullishCoalesce(_optionalChain([l, 'access', _424 => _424.text, 'optionalAccess', _425 => _425.match, 'call', _426 => _426(/\p{N}/gu), 'optionalAccess', _427 => _427.length]), () => ( 0))) >= 2).length < 2) return false;
|
|
8957
8979
|
let above = false, below = false;
|
|
8958
8980
|
for (const label of labels) {
|
|
8959
8981
|
const a = label.bbox, em = Math.max(b.height, a.height);
|
|
@@ -8968,7 +8990,7 @@ function rotatedAxisFragments(candidates) {
|
|
|
8968
8990
|
const paragraphs = candidates.filter((b) => b.type === "paragraph" && b.bbox.height <= 24);
|
|
8969
8991
|
const axes = [];
|
|
8970
8992
|
for (const block of paragraphs) {
|
|
8971
|
-
const b = block.bbox, text = _nullishCoalesce(_optionalChain([block, 'access',
|
|
8993
|
+
const b = block.bbox, text = _nullishCoalesce(_optionalChain([block, 'access', _428 => _428.text, 'optionalAccess', _429 => _429.trim, 'call', _430 => _430()]), () => ( ""));
|
|
8972
8994
|
if (!/^[\d\s.,%+−-]+$/u.test(text) || !/\d/u.test(text) || b.width > b.height * 6) continue;
|
|
8973
8995
|
const axis = axes.find((a) => Math.abs(a[0].bbox.x + a[0].bbox.width - b.x - b.width) <= Math.max(a[0].bbox.height, b.height) * 0.5);
|
|
8974
8996
|
if (axis) axis.push(block);
|
|
@@ -8985,8 +9007,8 @@ function rotatedAxisFragments(candidates) {
|
|
|
8985
9007
|
const em = Math.max(...axis.map((a) => a.bbox.height)), right = axis[0].bbox.x + axis[0].bbox.width;
|
|
8986
9008
|
if (top - bottom < em * 6) continue;
|
|
8987
9009
|
const left = paragraphs.filter((block) => {
|
|
8988
|
-
const b = block.bbox, text = _nullishCoalesce(_optionalChain([block, 'access',
|
|
8989
|
-
return /\p{Script=Latin}/u.test(text) && (_nullishCoalesce(_optionalChain([text, 'access',
|
|
9010
|
+
const b = block.bbox, text = _nullishCoalesce(_optionalChain([block, 'access', _431 => _431.text, 'optionalAccess', _432 => _432.trim, 'call', _433 => _433()]), () => ( ""));
|
|
9011
|
+
return /\p{Script=Latin}/u.test(text) && (_nullishCoalesce(_optionalChain([text, 'access', _434 => _434.match, 'call', _435 => _435(/[\p{L}\p{N}]/gu), 'optionalAccess', _436 => _436.length]), () => ( 0))) <= 3 && b.width <= b.height * 3 && b.x + b.width >= right - em * 6 && b.x + b.width <= right - Math.max(em, b.height) && b.y >= bottom && b.y + b.height <= top;
|
|
8990
9012
|
});
|
|
8991
9013
|
const stack = left.filter((a) => left.some((b) => {
|
|
8992
9014
|
if (a === b || !aligned(a, b)) return false;
|
|
@@ -8996,7 +9018,7 @@ function rotatedAxisFragments(candidates) {
|
|
|
8996
9018
|
if (stack.length < 2) continue;
|
|
8997
9019
|
for (const block of paragraphs) {
|
|
8998
9020
|
const b = block.bbox;
|
|
8999
|
-
if (b.y >= bottom && b.y + b.height <= top && b.x + b.width >= right - em * 6 && b.x + b.width <= right - Math.max(em, b.height) && /^[\p{L}\p{N}]$/u.test(_nullishCoalesce(_optionalChain([block, 'access',
|
|
9021
|
+
if (b.y >= bottom && b.y + b.height <= top && b.x + b.width >= right - em * 6 && b.x + b.width <= right - Math.max(em, b.height) && /^[\p{L}\p{N}]$/u.test(_nullishCoalesce(_optionalChain([block, 'access', _437 => _437.text, 'optionalAccess', _438 => _438.trim, 'call', _439 => _439()]), () => ( ""))) && stack.some((s) => aligned(s, block))) fragments.add(block);
|
|
9000
9022
|
}
|
|
9001
9023
|
}
|
|
9002
9024
|
return fragments;
|
|
@@ -9074,4 +9096,4 @@ function rowParagraphs(block) {
|
|
|
9074
9096
|
|
|
9075
9097
|
|
|
9076
9098
|
exports.DEFAULT_OCR_MODELS = DEFAULT_OCR_MODELS; exports.resolveOcrModels = resolveOcrModels; exports.ocrSelectionKey = ocrSelectionKey; exports.ocrSourcePath = ocrSourcePath; exports.ensureOcrModelsFor = ensureOcrModelsFor; exports.ocrModelsCached = ocrModelsCached; exports.parseCharacterDict = parseCharacterDict; exports.extractLines = extractLines; exports.extractImageRegions = extractImageRegions; exports.NO_EDGES = NO_EDGES; exports.hasOpenCellSeam = hasOpenCellSeam; exports.joinCellEdges = joinCellEdges; exports.filterHiddenText = filterHiddenText; exports.collapseEvenSpacing = collapseEvenSpacing; exports.computeBBox = computeBBox; exports.dominantStyle = dominantStyle; exports.normalizeItems = normalizeItems; exports.groupByY = groupByY; exports.mergeLineSimple = mergeLineSimple; exports.WrapLexicon = WrapLexicon; exports.startsNewItem = startsNewItem; exports.wrapJoiner = wrapJoiner; exports.joinPageBreakWraps = joinPageBreakWraps; exports.splitPageBreakWraps = splitPageBreakWraps; 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.runningLinePatterns = runningLinePatterns; exports.stripAbsorbedRunningLines = stripAbsorbedRunningLines; exports.CLIP_TABLES = CLIP_TABLES; exports.FRAME_TITLE_BLOCKS = FRAME_TITLE_BLOCKS; 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.restoreImageBullets = restoreImageBullets; exports.detectRightArrowRegions = detectRightArrowRegions; exports.removeSideTabs = removeSideTabs; exports.extractPageBlocksWithLines = extractPageBlocksWithLines; exports.UNRULED_REGION_TABLES = UNRULED_REGION_TABLES; exports.mergeOcrImageRegions = mergeOcrImageRegions;
|
|
9077
|
-
//# sourceMappingURL=chunk-
|
|
9099
|
+
//# sourceMappingURL=chunk-I4BS4BXE.cjs.map
|