kordoc 4.16.0 → 4.16.1
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 +345 -1135
- package/dist/{-VQNLLLPE.js → -3DURLXSO.js} +11 -11
- package/dist/{chunk-3JWMDL3S.js → chunk-24N4IJ5I.js} +2 -2
- package/dist/{chunk-H6KMTYYZ.cjs → chunk-2BZFKIRB.cjs} +3 -3
- package/dist/{chunk-H6KMTYYZ.cjs.map → chunk-2BZFKIRB.cjs.map} +1 -1
- package/dist/{chunk-RC4C7Q33.js → chunk-3VLVNKJV.js} +2 -2
- package/dist/{chunk-XHOZB2WP.js → chunk-3WIQSM3Z.js} +681 -22
- package/dist/chunk-3WIQSM3Z.js.map +1 -0
- package/dist/{chunk-DYENR3PX.js → chunk-63YGGAQW.js} +2 -2
- package/dist/{chunk-43FKGDDO.js → chunk-7FKPPIDZ.js} +50 -19
- package/dist/chunk-7FKPPIDZ.js.map +1 -0
- package/dist/{chunk-MH6MAL64.cjs → chunk-7IRHSRPU.cjs} +136 -105
- package/dist/chunk-7IRHSRPU.cjs.map +1 -0
- package/dist/{chunk-A3QDRMVD.js → chunk-7XAGIPOX.js} +2 -2
- package/dist/{chunk-NNYF2AGC.js → chunk-ANZTLTKU.js} +2 -2
- package/dist/{chunk-N6TPODYL.js → chunk-BIHS4VWR.js} +2 -2
- package/dist/{chunk-476OYHGZ.js → chunk-BTO7ZEE4.js} +6 -6
- package/dist/{chunk-46DZF3RK.js → chunk-CXWWX6BQ.js} +2 -2
- package/dist/{chunk-DRY3L5KQ.cjs → chunk-D2QCXK2X.cjs} +6 -6
- package/dist/{chunk-DRY3L5KQ.cjs.map → chunk-D2QCXK2X.cjs.map} +1 -1
- package/dist/{chunk-JB5X5NNL.js → chunk-DJ2BBQ5P.js} +680 -21
- package/dist/chunk-DJ2BBQ5P.js.map +1 -0
- package/dist/{chunk-ZY5K3LPM.cjs → chunk-DO74GYSM.cjs} +1 -1
- package/dist/chunk-DO74GYSM.cjs.map +1 -0
- package/dist/{chunk-6LMKQM7I.js → chunk-EEVAPRPD.js} +3 -3
- package/dist/{chunk-XWA625AN.js → chunk-FSDJLAOW.js} +3 -1
- package/dist/chunk-FSDJLAOW.js.map +1 -0
- package/dist/{chunk-QJERJZJ6.js → chunk-KBAQLAEL.js} +1 -1
- package/dist/chunk-KBAQLAEL.js.map +1 -0
- package/dist/{chunk-PQRP4NSF.js → chunk-N65ZXWNQ.js} +2 -2
- package/dist/{chunk-UDX7TSOC.js → chunk-NCXRSQNE.js} +2 -2
- package/dist/{chunk-GOQBON77.js → chunk-NUPXPKIQ.js} +2 -2
- package/dist/{chunk-B5NEGP65.cjs → chunk-NV37CQFN.cjs} +692 -33
- package/dist/chunk-NV37CQFN.cjs.map +1 -0
- package/dist/{chunk-CB5XDCSL.js → chunk-OBRPYCIS.js} +1377 -947
- package/dist/chunk-OBRPYCIS.js.map +1 -0
- package/dist/{chunk-HIVK5V27.js → chunk-PVMROO3A.js} +51 -20
- package/dist/chunk-PVMROO3A.js.map +1 -0
- package/dist/{chunk-UQ6TZDW6.js → chunk-T77M2QP7.js} +1 -1
- package/dist/chunk-T77M2QP7.js.map +1 -0
- package/dist/{chunk-TGD7UFHD.js → chunk-UZHT3LBF.js} +2 -2
- package/dist/{chunk-PIMB2YNO.js → chunk-VCRBR72A.js} +2 -2
- package/dist/{chunk-C75WE52C.js → chunk-VNOQTDTE.js} +2 -2
- package/dist/{chunk-NWODPYBD.cjs → chunk-YRRBA4HW.cjs} +2 -2
- package/dist/{chunk-NWODPYBD.cjs.map → chunk-YRRBA4HW.cjs.map} +1 -1
- package/dist/chunks-PYYQURNO.js +10 -0
- package/dist/cli.js +31 -29
- package/dist/cli.js.map +1 -1
- package/dist/{formula-FNQYHMIY.js → formula-IPLFHEBD.js} +3 -3
- package/dist/{formula-VEFKYXPB.cjs → formula-TRTONZMA.cjs} +9 -9
- package/dist/{formula-VEFKYXPB.cjs.map → formula-TRTONZMA.cjs.map} +1 -1
- package/dist/{formula-5775PTP2.js → formula-U4BTEZ6I.js} +4 -4
- package/dist/{image-ocr-PYZU4TO7.js → image-ocr-3IJ25PS4.js} +8 -8
- package/dist/{image-ocr-YA2MQBRP.js → image-ocr-GTDG4SAJ.js} +6 -6
- package/dist/{image-ocr-6JZR734G.cjs → image-ocr-THFLQ3DC.cjs} +15 -15
- package/dist/{image-ocr-6JZR734G.cjs.map → image-ocr-THFLQ3DC.cjs.map} +1 -1
- package/dist/index.cjs +1555 -1125
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +17 -5
- package/dist/index.d.ts +17 -5
- package/dist/index.js +1105 -675
- package/dist/index.js.map +1 -1
- package/dist/mcp.js +31 -27
- package/dist/mcp.js.map +1 -1
- package/dist/{model-bundle-O6J7ORVC.js → model-bundle-PVWIAVEX.js} +5 -5
- package/dist/{models-YMOKZGCI.js → models-VCRF3JMT.js} +5 -5
- package/dist/{parser-YAQV7FBO.cjs → parser-2CN2DIPV.cjs} +356 -218
- package/dist/parser-2CN2DIPV.cjs.map +1 -0
- package/dist/{parser-3B6I2XL7.js → parser-T4RITZDP.js} +221 -83
- package/dist/parser-T4RITZDP.js.map +1 -0
- package/dist/{parser-PXATL5DM.js → parser-UEROAPYZ.js} +218 -80
- package/dist/parser-UEROAPYZ.js.map +1 -0
- package/dist/pdf-ocr-NARV2AQI.cjs +16 -0
- package/dist/{pdf-ocr-T2JXQATA.cjs.map → pdf-ocr-NARV2AQI.cjs.map} +1 -1
- package/dist/pdf-ocr-SYLMM727.js +18 -0
- package/dist/pdf-ocr-YMQZDJBO.js +15 -0
- package/dist/{profile-io-ZTV2MKRT.js → profile-io-YD54CDXY.js} +3 -3
- package/dist/{rasterize-MMUZ537K.js → rasterize-3THYOOUN.js} +3 -3
- package/dist/{redact-doc-S42XGV5D.js → redact-doc-65L2YJN6.js} +11 -11
- package/dist/{render-WCWPZKJ7.js → render-YU7QJVZ7.js} +7 -7
- package/dist/seal-6CQGFTML.js +10 -0
- package/dist/{setup-D35LKZCH.js → setup-CFHKXDY4.js} +3 -3
- package/dist/visual-ED2H75Q5.js +20 -0
- package/dist/{watch-AX64CIMN.js → watch-D6FCAYKJ.js} +12 -12
- package/package.json +1 -1
- package/dist/chunk-43FKGDDO.js.map +0 -1
- package/dist/chunk-B5NEGP65.cjs.map +0 -1
- package/dist/chunk-CB5XDCSL.js.map +0 -1
- package/dist/chunk-HIVK5V27.js.map +0 -1
- package/dist/chunk-JB5X5NNL.js.map +0 -1
- package/dist/chunk-MH6MAL64.cjs.map +0 -1
- package/dist/chunk-QJERJZJ6.js.map +0 -1
- package/dist/chunk-UQ6TZDW6.js.map +0 -1
- package/dist/chunk-XHOZB2WP.js.map +0 -1
- package/dist/chunk-XWA625AN.js.map +0 -1
- package/dist/chunk-ZY5K3LPM.cjs.map +0 -1
- package/dist/chunks-JD25E5PM.js +0 -10
- package/dist/parser-3B6I2XL7.js.map +0 -1
- package/dist/parser-PXATL5DM.js.map +0 -1
- package/dist/parser-YAQV7FBO.cjs.map +0 -1
- package/dist/pdf-ocr-2TTO5PX2.js +0 -15
- package/dist/pdf-ocr-T2JXQATA.cjs +0 -16
- package/dist/pdf-ocr-WF2NQA6X.js +0 -18
- package/dist/seal-WHK4GOHR.js +0 -10
- package/dist/visual-WL4TDE5B.js +0 -20
- /package/dist/{-VQNLLLPE.js.map → -3DURLXSO.js.map} +0 -0
- /package/dist/{chunk-3JWMDL3S.js.map → chunk-24N4IJ5I.js.map} +0 -0
- /package/dist/{chunk-RC4C7Q33.js.map → chunk-3VLVNKJV.js.map} +0 -0
- /package/dist/{chunk-DYENR3PX.js.map → chunk-63YGGAQW.js.map} +0 -0
- /package/dist/{chunk-A3QDRMVD.js.map → chunk-7XAGIPOX.js.map} +0 -0
- /package/dist/{chunk-NNYF2AGC.js.map → chunk-ANZTLTKU.js.map} +0 -0
- /package/dist/{chunk-N6TPODYL.js.map → chunk-BIHS4VWR.js.map} +0 -0
- /package/dist/{chunk-476OYHGZ.js.map → chunk-BTO7ZEE4.js.map} +0 -0
- /package/dist/{chunk-46DZF3RK.js.map → chunk-CXWWX6BQ.js.map} +0 -0
- /package/dist/{chunk-6LMKQM7I.js.map → chunk-EEVAPRPD.js.map} +0 -0
- /package/dist/{chunk-PQRP4NSF.js.map → chunk-N65ZXWNQ.js.map} +0 -0
- /package/dist/{chunk-UDX7TSOC.js.map → chunk-NCXRSQNE.js.map} +0 -0
- /package/dist/{chunk-GOQBON77.js.map → chunk-NUPXPKIQ.js.map} +0 -0
- /package/dist/{chunk-TGD7UFHD.js.map → chunk-UZHT3LBF.js.map} +0 -0
- /package/dist/{chunk-PIMB2YNO.js.map → chunk-VCRBR72A.js.map} +0 -0
- /package/dist/{chunk-C75WE52C.js.map → chunk-VNOQTDTE.js.map} +0 -0
- /package/dist/{chunks-JD25E5PM.js.map → chunks-PYYQURNO.js.map} +0 -0
- /package/dist/{formula-FNQYHMIY.js.map → formula-IPLFHEBD.js.map} +0 -0
- /package/dist/{formula-5775PTP2.js.map → formula-U4BTEZ6I.js.map} +0 -0
- /package/dist/{image-ocr-PYZU4TO7.js.map → image-ocr-3IJ25PS4.js.map} +0 -0
- /package/dist/{image-ocr-YA2MQBRP.js.map → image-ocr-GTDG4SAJ.js.map} +0 -0
- /package/dist/{model-bundle-O6J7ORVC.js.map → model-bundle-PVWIAVEX.js.map} +0 -0
- /package/dist/{models-YMOKZGCI.js.map → models-VCRF3JMT.js.map} +0 -0
- /package/dist/{pdf-ocr-2TTO5PX2.js.map → pdf-ocr-SYLMM727.js.map} +0 -0
- /package/dist/{pdf-ocr-WF2NQA6X.js.map → pdf-ocr-YMQZDJBO.js.map} +0 -0
- /package/dist/{profile-io-ZTV2MKRT.js.map → profile-io-YD54CDXY.js.map} +0 -0
- /package/dist/{rasterize-MMUZ537K.js.map → rasterize-3THYOOUN.js.map} +0 -0
- /package/dist/{redact-doc-S42XGV5D.js.map → redact-doc-65L2YJN6.js.map} +0 -0
- /package/dist/{render-WCWPZKJ7.js.map → render-YU7QJVZ7.js.map} +0 -0
- /package/dist/{seal-WHK4GOHR.js.map → seal-6CQGFTML.js.map} +0 -0
- /package/dist/{setup-D35LKZCH.js.map → setup-CFHKXDY4.js.map} +0 -0
- /package/dist/{visual-WL4TDE5B.js.map → visual-ED2H75Q5.js.map} +0 -0
- /package/dist/{watch-AX64CIMN.js.map → watch-D6FCAYKJ.js.map} +0 -0
|
@@ -2,15 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var _chunkDO74GYSMcjs = require('./chunk-DO74GYSM.cjs');
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
var
|
|
9
|
+
var _chunk2BZFKIRBcjs = require('./chunk-2BZFKIRB.cjs');
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
|
|
13
|
-
var
|
|
13
|
+
var _chunkYRRBA4HWcjs = require('./chunk-YRRBA4HW.cjs');
|
|
14
14
|
|
|
15
15
|
// src/ocr/models.ts
|
|
16
16
|
var _path = require('path');
|
|
@@ -38,10 +38,10 @@ var OCR_REC_DICT = {
|
|
|
38
38
|
};
|
|
39
39
|
var ALL_OCR_MODELS = [OCR_DET_MODEL, OCR_REC_MODEL, OCR_REC_DICT];
|
|
40
40
|
function getOcrModelsDir() {
|
|
41
|
-
return
|
|
41
|
+
return _chunk2BZFKIRBcjs.getModelsDir.call(void 0, "ppocr");
|
|
42
42
|
}
|
|
43
43
|
async function ensureOcrModels(onProgress) {
|
|
44
|
-
return
|
|
44
|
+
return _chunk2BZFKIRBcjs.ensureModelsIn.call(void 0, getOcrModelsDir(), ALL_OCR_MODELS, onProgress);
|
|
45
45
|
}
|
|
46
46
|
async function ocrModelsCached() {
|
|
47
47
|
const dir = getOcrModelsDir();
|
|
@@ -1085,6 +1085,12 @@ function dropInsetClipGrids(clipGrids, lineGrids) {
|
|
|
1085
1085
|
const near = (a, b) => Math.abs(a - b) <= SHADE_CLIP_TOL;
|
|
1086
1086
|
return clipGrids.filter((c) => c.clipParent || c.rowYs.length !== 2 || !lineGrids.some((l) => l.rowYs.length >= 3 && near(c.bbox.x1, l.bbox.x1) && near(c.bbox.x2, l.bbox.x2) && l.rowYs.some((top, r) => r + 1 < l.rowYs.length && top - c.bbox.y2 >= INSET_CLIP_MIN && c.bbox.y1 - l.rowYs[r + 1] >= INSET_CLIP_MIN)));
|
|
1087
1087
|
}
|
|
1088
|
+
function dropHeadBandClipGrids(clipGrids, lineGrids) {
|
|
1089
|
+
if (clipGrids.length === 0 || lineGrids.length === 0) return clipGrids;
|
|
1090
|
+
const near = (a, b) => Math.abs(a - b) <= SHADE_CLIP_TOL;
|
|
1091
|
+
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);
|
|
1092
|
+
return clipGrids.filter((c) => c.clipParent || !_optionalChain([c, 'access', _15 => _15.cells, 'optionalAccess', _16 => _16.length]) || !lineGrids.some((l) => l.rowYs.length > c.rowYs.length && l.colXs.length === c.colXs.length && c.colXs.every((x, k) => near(x, l.colXs[k])) && c.rowYs.every((y, k) => near(y, l.rowYs[k])) && !clipGrids.some((o) => o !== c && overlaps(o.bbox, l.bbox))));
|
|
1093
|
+
}
|
|
1088
1094
|
function enforceMinWidth(colXs, minWidth) {
|
|
1089
1095
|
if (colXs.length <= 2) return colXs;
|
|
1090
1096
|
const result = [colXs[0]];
|
|
@@ -1427,7 +1433,7 @@ function buildClipCellGrids(rects, strokedH, strokedV, pageWidth, pageHeight, te
|
|
|
1427
1433
|
for (let dx = -1; dx <= 1 && !duplicate; dx++) {
|
|
1428
1434
|
const ys2 = buckets.get(bx + dx);
|
|
1429
1435
|
for (let dy = -1; dy <= 1 && !duplicate; dy++) {
|
|
1430
|
-
duplicate = _nullishCoalesce(_optionalChain([ys2, 'optionalAccess',
|
|
1436
|
+
duplicate = _nullishCoalesce(_optionalChain([ys2, 'optionalAccess', _17 => _17.get, 'call', _18 => _18(by + dy), 'optionalAccess', _19 => _19.some, 'call', _20 => _20((c) => sameRect(c, r))]), () => ( false));
|
|
1431
1437
|
}
|
|
1432
1438
|
}
|
|
1433
1439
|
if (duplicate) continue;
|
|
@@ -1544,7 +1550,7 @@ function buildClipCellGrids(rects, strokedH, strokedV, pageWidth, pageHeight, te
|
|
|
1544
1550
|
else groups.set(r, [i]);
|
|
1545
1551
|
}
|
|
1546
1552
|
const containers = cells.filter((_, i) => isContainer[i]);
|
|
1547
|
-
const groupSize = (i) => _nullishCoalesce(_optionalChain([groups, 'access',
|
|
1553
|
+
const groupSize = (i) => _nullishCoalesce(_optionalChain([groups, 'access', _21 => _21.get, 'call', _22 => _22(find(i)), 'optionalAccess', _23 => _23.length]), () => ( 0));
|
|
1548
1554
|
const isGridMember = (i) => groupSize(i) >= CLIP_MIN_GROUP;
|
|
1549
1555
|
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);
|
|
1550
1556
|
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);
|
|
@@ -1970,12 +1976,19 @@ var WrapLexicon = (_class = class {constructor() { _class.prototype.__init.call(
|
|
|
1970
1976
|
joinedWord(left, right) {
|
|
1971
1977
|
return this.isWord(left + right) && !this.pairs.has(left + " " + right);
|
|
1972
1978
|
}
|
|
1979
|
+
/** 두 글자+두 글자 증거만 — 한 글자 쌍으로 물러서지 않는다 (표 칸 조각처럼 줄 꺾임이 아닌 자리에 쓸 때) */
|
|
1980
|
+
evidence2(left, right) {
|
|
1981
|
+
const n = left.length;
|
|
1982
|
+
if (n < 2 || right.length < 2) return null;
|
|
1983
|
+
const k1 = pairKey(left.charCodeAt(n - 2), left.charCodeAt(n - 1)), k2 = pairKey(right.charCodeAt(0), right.charCodeAt(1));
|
|
1984
|
+
return decideCounts(_nullishCoalesce(_optionalChain([this, 'access', _24 => _24.joined2, 'access', _25 => _25.get, 'call', _26 => _26(k1), 'optionalAccess', _27 => _27.get, 'call', _28 => _28(k2)]), () => ( 0)), _nullishCoalesce(_optionalChain([this, 'access', _29 => _29.spaced2, 'access', _30 => _30.get, 'call', _31 => _31(k1), 'optionalAccess', _32 => _32.get, 'call', _33 => _33(k2)]), () => ( 0)));
|
|
1985
|
+
}
|
|
1973
1986
|
/** 꺾인 자리 증거: "" 붙음 · " " 띄움 · null 모름 (두 글자 증거가 갈리거나 없으면 한 글자) */
|
|
1974
1987
|
evidence(left, right) {
|
|
1975
1988
|
const n = left.length;
|
|
1976
1989
|
if (n >= 2 && right.length >= 2) {
|
|
1977
1990
|
const k1 = pairKey(left.charCodeAt(n - 2), left.charCodeAt(n - 1)), k2 = pairKey(right.charCodeAt(0), right.charCodeAt(1));
|
|
1978
|
-
const v = decideCounts(_nullishCoalesce(_optionalChain([this, 'access',
|
|
1991
|
+
const v = decideCounts(_nullishCoalesce(_optionalChain([this, 'access', _34 => _34.joined2, 'access', _35 => _35.get, 'call', _36 => _36(k1), 'optionalAccess', _37 => _37.get, 'call', _38 => _38(k2)]), () => ( 0)), _nullishCoalesce(_optionalChain([this, 'access', _39 => _39.spaced2, 'access', _40 => _40.get, 'call', _41 => _41(k1), 'optionalAccess', _42 => _42.get, 'call', _43 => _43(k2)]), () => ( 0)));
|
|
1979
1992
|
if (v !== null) return v;
|
|
1980
1993
|
}
|
|
1981
1994
|
if (n && right.length) {
|
|
@@ -2047,11 +2060,11 @@ function wrapJoiner(prevText, nextText, lex) {
|
|
|
2047
2060
|
if (particleContinues(left, right)) return "";
|
|
2048
2061
|
if (endsAsWord(left)) return " ";
|
|
2049
2062
|
if (/[A-Za-z]-$/.test(left) && /^[A-Za-z]/.test(right) && !/[가-힣]/.test(prev + next)) {
|
|
2050
|
-
return _optionalChain([lex, 'optionalAccess',
|
|
2063
|
+
return _optionalChain([lex, 'optionalAccess', _44 => _44.joinedWord, 'call', _45 => _45(left, right.replace(/[.,;:!?)]*$/, ""))]) ? "" : " ";
|
|
2051
2064
|
}
|
|
2052
2065
|
if (/[·ㆍ‧-]/.test(a) && !/[·ㆍ‧…]{2}$/.test(prev) && /[가-힣A-Za-z0-9]/.test(b)) return "";
|
|
2053
2066
|
if (/[A-Za-z]/.test(a) && /[A-Za-z]/.test(b) || /\d/.test(a) && /\d/.test(b)) return " ";
|
|
2054
|
-
const ev = _optionalChain([lex, 'optionalAccess',
|
|
2067
|
+
const ev = _optionalChain([lex, 'optionalAccess', _46 => _46.evidence, 'call', _47 => _47(left, right)]);
|
|
2055
2068
|
if (ev != null) return ev;
|
|
2056
2069
|
if (lex && /[가-힣A-Za-z0-9]$/.test(left) && /^[가-힣A-Za-z0-9]/.test(right) && lex.joinedWord(left, right.replace(/[.,)」』’”;:]+$/, ""))) return "";
|
|
2057
2070
|
if (/\d$/.test(left) && COUNTER.test(right)) return "";
|
|
@@ -2073,7 +2086,7 @@ function joinPageBreakWraps(blocks, lex) {
|
|
|
2073
2086
|
if (a.type !== "paragraph" && a.type !== "list" || b.type !== "paragraph") continue;
|
|
2074
2087
|
const last = a.bbox && PARA_LAST_LINE.get(a.bbox), fs = last ? last.fontSize : 0;
|
|
2075
2088
|
if (!last || fs <= 0 || (_nullishCoalesce(pageRight.get(a.pageNumber), () => ( Infinity))) - last.right >= BODY_FULL_TOL * fs) continue;
|
|
2076
|
-
if (last.width < BODY_MIN_WIDTH_EM * fs || Math.abs((_nullishCoalesce(_optionalChain([b, 'access',
|
|
2089
|
+
if (last.width < BODY_MIN_WIDTH_EM * fs || Math.abs((_nullishCoalesce(_optionalChain([b, 'access', _48 => _48.style, 'optionalAccess', _49 => _49.fontSize]), () => ( 0))) - fs) > 0.15 * fs) continue;
|
|
2077
2090
|
if (startsNewItem(a.text, b.text)) continue;
|
|
2078
2091
|
a.text += wrapJoiner(a.text, b.text, lex) + b.text;
|
|
2079
2092
|
const bl = b.bbox && PARA_LAST_LINE.get(b.bbox);
|
|
@@ -2128,6 +2141,7 @@ function cellLineFills(box, contentLeft, cellRight, lineRight, fontSize) {
|
|
|
2128
2141
|
}
|
|
2129
2142
|
|
|
2130
2143
|
// src/pdf/cell-text.ts
|
|
2144
|
+
var REGION_LABELS = /* @__PURE__ */ new Set(["\uC11C\uC6B8", "\uBD80\uC0B0", "\uB300\uAD6C", "\uC778\uCC9C", "\uAD11\uC8FC", "\uB300\uC804", "\uC6B8\uC0B0", "\uC138\uC885", "\uACBD\uAE30", "\uAC15\uC6D0", "\uCDA9\uBD81", "\uCDA9\uB0A8", "\uC804\uBD81", "\uC804\uB0A8", "\uACBD\uBD81", "\uACBD\uB0A8", "\uC81C\uC8FC", "\uC804\uAD6D"]);
|
|
2131
2145
|
var CELL_PADDING = 2;
|
|
2132
2146
|
var SPACE_GAP_RATIO = 0.17;
|
|
2133
2147
|
function spaceGapThreshold(fontSize) {
|
|
@@ -2222,8 +2236,8 @@ function cellTextToString(items, wrap) {
|
|
|
2222
2236
|
const textLines = merged.map((line) => {
|
|
2223
2237
|
const s = sortLineByX(line);
|
|
2224
2238
|
if (s.length === 1) return s[0].text;
|
|
2225
|
-
if (s.length === 2 && /^[가-힣]$/.test(s[0].text) && /^[가-힣]$/.test(s[1].text) && !!_optionalChain([wrap, 'optionalAccess',
|
|
2226
|
-
const evenSpaced = detectEvenSpacedItems(s);
|
|
2239
|
+
if (s.length === 2 && /^[가-힣]$/.test(s[0].text) && /^[가-힣]$/.test(s[1].text) && !!_optionalChain([wrap, 'optionalAccess', _50 => _50.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;
|
|
2240
|
+
const evenSpaced = detectEvenSpacedItems(s, true);
|
|
2227
2241
|
let result = s[0].text;
|
|
2228
2242
|
for (let j = 1; j < s.length; j++) {
|
|
2229
2243
|
if (evenSpaced[j]) {
|
|
@@ -2293,9 +2307,13 @@ function mergeSuperscriptRows(lines) {
|
|
|
2293
2307
|
}
|
|
2294
2308
|
return result;
|
|
2295
2309
|
}
|
|
2296
|
-
function detectEvenSpacedItems(items) {
|
|
2310
|
+
function detectEvenSpacedItems(items, cellLine = false) {
|
|
2297
2311
|
const result = new Array(items.length).fill(false);
|
|
2298
2312
|
if (items.length < 3) return result;
|
|
2313
|
+
if (cellLine && items.every((it) => /^[가-힣]$/.test(it.text)) && items.slice(1).every((it) => !it.hasSpaceBefore || it.syntheticSpace) && items.slice(1).every((it, k) => it.x - (items[k].x + items[k].w) >= it.fontSize * 0.1)) {
|
|
2314
|
+
markEvenRun(items, result, 0, items.length);
|
|
2315
|
+
if (result.some(Boolean)) return result;
|
|
2316
|
+
}
|
|
2299
2317
|
let runStart = -1;
|
|
2300
2318
|
for (let i = 0; i < items.length; i++) {
|
|
2301
2319
|
const isShortKorean = /^[가-힣]{1}$/.test(items[i].text) || /^[\d]{1}$/.test(items[i].text);
|
|
@@ -2364,7 +2382,7 @@ function mergeCellTextLines(textLines, wrap) {
|
|
|
2364
2382
|
merged[merged.length - 1] = prev + curr.trim();
|
|
2365
2383
|
} else if (!wrap && /[,(]$/.test(prev.trim()) && curr.trim().length <= 15) {
|
|
2366
2384
|
merged[merged.length - 1] = prev + curr.trim();
|
|
2367
|
-
} else if (/[\d,]$/.test(prev) && /^[\d,]+[)\]]?$/.test(curr.trim()) && curr.trim().length <= 10 && !(/\d,\d{3}$/.test(prev) && /^\d/.test(curr.trim())) && !(/(?:^|[^\d,])\d{1,3}$/.test(prev) && /^(\d{1,3}(,\d{3})+|\d{1,3})$/.test(curr.trim()) && !_optionalChain([wrap, 'optionalAccess',
|
|
2385
|
+
} else if (/[\d,]$/.test(prev) && /^[\d,]+[)\]]?$/.test(curr.trim()) && curr.trim().length <= 10 && !(/\d,\d{3}$/.test(prev) && /^\d/.test(curr.trim())) && !(/(?:^|[^\d,])\d{1,3}$/.test(prev) && /^(\d{1,3}(,\d{3})+|\d{1,3})$/.test(curr.trim()) && !_optionalChain([wrap, 'optionalAccess', _51 => _51.wraps, 'access', _52 => _52[i - 1]])) && !(/(?:^|\s)\d{1,7}$/.test(prev) && /^\d{1,7}$/.test(curr.trim()) && !_optionalChain([wrap, 'optionalAccess', _53 => _53.wraps, 'access', _54 => _54[i - 1]]))) {
|
|
2368
2386
|
merged[merged.length - 1] = prev + curr.trim();
|
|
2369
2387
|
} else {
|
|
2370
2388
|
merged.push(curr);
|
|
@@ -2434,7 +2452,7 @@ function normalizeUndersegmentedTable(originalCells, colXs, items, rowYs) {
|
|
|
2434
2452
|
if (numRows > MAX_UNDERSEGMENTED_ROWS || numCols < MIN_UNDERSEGMENTED_COLUMNS) return null;
|
|
2435
2453
|
if (items.length === 0) return null;
|
|
2436
2454
|
if (numRows >= 3) {
|
|
2437
|
-
if (_optionalChain([rowYs, 'optionalAccess',
|
|
2455
|
+
if (_optionalChain([rowYs, 'optionalAccess', _55 => _55.length]) !== numRows + 1) return null;
|
|
2438
2456
|
const rebuilt2 = [];
|
|
2439
2457
|
let expanded = 0;
|
|
2440
2458
|
for (let r = 0; r < numRows; r++) {
|
|
@@ -2581,7 +2599,7 @@ function dominantStyle(items) {
|
|
|
2581
2599
|
let maxCount = 0, dominantSize = 0;
|
|
2582
2600
|
for (const i of items) {
|
|
2583
2601
|
if (i.fontSize <= 0) continue;
|
|
2584
|
-
const count = (freq.get(i.fontSize) || 0) + Math.max(1, _nullishCoalesce(_optionalChain([i, 'access',
|
|
2602
|
+
const count = (freq.get(i.fontSize) || 0) + Math.max(1, _nullishCoalesce(_optionalChain([i, 'access', _56 => _56.text, 'access', _57 => _57.match, 'call', _58 => _58(/[\p{L}\p{N}]/gu), 'optionalAccess', _59 => _59.length]), () => ( 0)));
|
|
2585
2603
|
freq.set(i.fontSize, count);
|
|
2586
2604
|
if (count > maxCount) {
|
|
2587
2605
|
maxCount = count;
|
|
@@ -2589,7 +2607,7 @@ function dominantStyle(items) {
|
|
|
2589
2607
|
}
|
|
2590
2608
|
}
|
|
2591
2609
|
if (dominantSize === 0) return void 0;
|
|
2592
|
-
const fontName = _optionalChain([items, 'access',
|
|
2610
|
+
const fontName = _optionalChain([items, 'access', _60 => _60.find, 'call', _61 => _61((i) => i.fontSize === dominantSize), 'optionalAccess', _62 => _62.fontName]) || void 0;
|
|
2593
2611
|
return fontName ? { fontSize: dominantSize, fontName } : { fontSize: dominantSize };
|
|
2594
2612
|
}
|
|
2595
2613
|
function normalizeItems(rawItems) {
|
|
@@ -2602,7 +2620,7 @@ function normalizeItems(rawItems) {
|
|
|
2602
2620
|
const x = Math.round(i.transform[4]);
|
|
2603
2621
|
const y = Math.round(i.transform[5]);
|
|
2604
2622
|
if (!i.str.trim()) {
|
|
2605
|
-
spacePositions.push({ x, y });
|
|
2623
|
+
spacePositions.push({ x, y, synthetic: i.synthetic });
|
|
2606
2624
|
continue;
|
|
2607
2625
|
}
|
|
2608
2626
|
const scaleX = Math.hypot(i.transform[0], i.transform[1]);
|
|
@@ -2658,7 +2676,10 @@ function normalizeItems(rawItems) {
|
|
|
2658
2676
|
nearest = item;
|
|
2659
2677
|
}
|
|
2660
2678
|
}
|
|
2661
|
-
if (nearest)
|
|
2679
|
+
if (nearest) {
|
|
2680
|
+
nearest.syntheticSpace = (nearest.hasSpaceBefore ? nearest.syntheticSpace === true : true) && sp.synthetic === true;
|
|
2681
|
+
nearest.hasSpaceBefore = true;
|
|
2682
|
+
}
|
|
2662
2683
|
}
|
|
2663
2684
|
}
|
|
2664
2685
|
return deduped;
|
|
@@ -2706,7 +2727,7 @@ function splitAroundOverlays(c, overlays) {
|
|
|
2706
2727
|
const ov = overlays.filter((o) => {
|
|
2707
2728
|
for (let at = c.text.indexOf(o.text); at >= 0; at = c.text.indexOf(o.text, at + 1)) {
|
|
2708
2729
|
const prefix = c.text.slice(0, at);
|
|
2709
|
-
const est = c.x + glyphUnits(prefix.replace(/\s+/g, "")) * a0 + (_nullishCoalesce(_optionalChain([prefix, 'access',
|
|
2730
|
+
const est = c.x + glyphUnits(prefix.replace(/\s+/g, "")) * a0 + (_nullishCoalesce(_optionalChain([prefix, 'access', _63 => _63.match, 'call', _64 => _64(/\s+/g), 'optionalAccess', _65 => _65.length]), () => ( 0))) * ws;
|
|
2710
2731
|
if (Math.abs(est - o.x) <= OVERLAY_DUP_EM * fs) return false;
|
|
2711
2732
|
}
|
|
2712
2733
|
return true;
|
|
@@ -2819,7 +2840,7 @@ function mergeSuperscriptLines(lines) {
|
|
|
2819
2840
|
return result;
|
|
2820
2841
|
}
|
|
2821
2842
|
function mergeLineSimple(items) {
|
|
2822
|
-
if (items.length <= 1) return _optionalChain([items, 'access',
|
|
2843
|
+
if (items.length <= 1) return _optionalChain([items, 'access', _66 => _66[0], 'optionalAccess', _67 => _67.text]) || "";
|
|
2823
2844
|
const sorted = sortLineByX([...items]);
|
|
2824
2845
|
const isEvenSpaced = detectEvenSpacedItems(sorted);
|
|
2825
2846
|
let result = sorted[0].text;
|
|
@@ -2964,7 +2985,7 @@ function splitTrailingColumnRegion(items) {
|
|
|
2964
2985
|
}
|
|
2965
2986
|
function panelBlocks(items, panel, pageNum) {
|
|
2966
2987
|
const lines = groupByY([...items].sort((a, b) => b.y - a.y || a.x - b.x));
|
|
2967
|
-
const faceOf = (line) => _nullishCoalesce(_optionalChain([dominantStyle, 'call',
|
|
2988
|
+
const faceOf = (line) => _nullishCoalesce(_optionalChain([dominantStyle, 'call', _68 => _68(line), 'optionalAccess', _69 => _69.fontName]), () => ( ""));
|
|
2968
2989
|
const runs = [];
|
|
2969
2990
|
for (const line of lines) {
|
|
2970
2991
|
const last = runs[runs.length - 1];
|
|
@@ -2994,7 +3015,7 @@ function pushLineParagraphs(out, yLines, pageNum, lex) {
|
|
|
2994
3015
|
const lines = attachDropCaps(yLines).map((items) => ({ items, text: mergeLineSimple(items) })).filter((l) => l.text.trim());
|
|
2995
3016
|
const geo = lines.map((l) => {
|
|
2996
3017
|
const b = computeBBox(l.items, pageNum);
|
|
2997
|
-
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',
|
|
3018
|
+
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', _70 => _70(l.items), 'optionalAccess', _71 => _71.fontSize]), () => ( 0)) };
|
|
2998
3019
|
});
|
|
2999
3020
|
const joins = bodyLineJoins(geo, lex);
|
|
3000
3021
|
for (let i = 0; i + 1 < geo.length; i++) {
|
|
@@ -3038,15 +3059,15 @@ function computeMedianFontSizeFromFreq(freq) {
|
|
|
3038
3059
|
function detectHeadings(blocks, medianFontSize) {
|
|
3039
3060
|
for (let bi = 0; bi < blocks.length; bi++) {
|
|
3040
3061
|
const block = blocks[bi];
|
|
3041
|
-
if (block.type !== "paragraph" || !block.text || !_optionalChain([block, 'access',
|
|
3062
|
+
if (block.type !== "paragraph" || !block.text || !_optionalChain([block, 'access', _72 => _72.style, 'optionalAccess', _73 => _73.fontSize])) continue;
|
|
3042
3063
|
const text = block.text.trim();
|
|
3043
3064
|
if (text.length === 0 || text.length > 200) continue;
|
|
3044
3065
|
if (/^\d+$/.test(text) && !isChapterNumber(block, blocks[bi + 1], medianFontSize)) continue;
|
|
3045
3066
|
const ratio = block.style.fontSize / medianFontSize;
|
|
3046
3067
|
let level = 0;
|
|
3047
|
-
if (ratio >=
|
|
3048
|
-
else if (ratio >=
|
|
3049
|
-
else if (ratio >=
|
|
3068
|
+
if (ratio >= _chunkDO74GYSMcjs.HEADING_RATIO_H1) level = 1;
|
|
3069
|
+
else if (ratio >= _chunkDO74GYSMcjs.HEADING_RATIO_H2) level = 2;
|
|
3070
|
+
else if (ratio >= _chunkDO74GYSMcjs.HEADING_RATIO_H3) level = 3;
|
|
3050
3071
|
if (level > 0) {
|
|
3051
3072
|
block.type = "heading";
|
|
3052
3073
|
block.level = level;
|
|
@@ -3055,21 +3076,21 @@ function detectHeadings(blocks, medianFontSize) {
|
|
|
3055
3076
|
}
|
|
3056
3077
|
}
|
|
3057
3078
|
function isChapterNumber(block, next, medianFontSize) {
|
|
3058
|
-
const size = _nullishCoalesce(_optionalChain([block, 'access',
|
|
3059
|
-
const nextSize = _nullishCoalesce(_optionalChain([next, 'optionalAccess',
|
|
3060
|
-
const text = _nullishCoalesce(_optionalChain([next, 'optionalAccess',
|
|
3061
|
-
const a = block.bbox, b = _optionalChain([next, 'optionalAccess',
|
|
3062
|
-
return /^\d{1,2}$/.test(_nullishCoalesce(_optionalChain([block, 'access',
|
|
3079
|
+
const size = _nullishCoalesce(_optionalChain([block, 'access', _74 => _74.style, 'optionalAccess', _75 => _75.fontSize]), () => ( 0));
|
|
3080
|
+
const nextSize = _nullishCoalesce(_optionalChain([next, 'optionalAccess', _76 => _76.style, 'optionalAccess', _77 => _77.fontSize]), () => ( 0));
|
|
3081
|
+
const text = _nullishCoalesce(_optionalChain([next, 'optionalAccess', _78 => _78.text, 'optionalAccess', _79 => _79.trim, 'call', _80 => _80()]), () => ( ""));
|
|
3082
|
+
const a = block.bbox, b = _optionalChain([next, 'optionalAccess', _81 => _81.bbox]);
|
|
3083
|
+
return /^\d{1,2}$/.test(_nullishCoalesce(_optionalChain([block, 'access', _82 => _82.text, 'optionalAccess', _83 => _83.trim, 'call', _84 => _84()]), () => ( ""))) && size >= medianFontSize * 2.5 && !!next && (next.type === "paragraph" || next.type === "heading") && next.pageNumber === block.pageNumber && nextSize >= medianFontSize * _chunkDO74GYSMcjs.HEADING_RATIO_H1 && text.length > 0 && text.length <= 80 && !/^[\d\s.]+$/.test(text) && !!a && !!b && a.y > b.y && a.y - (b.y + b.height) <= size * 2;
|
|
3063
3084
|
}
|
|
3064
3085
|
function mergeStackedHeadingLines(blocks, medianFontSize) {
|
|
3065
3086
|
for (let i = 0; i < blocks.length - 1; ) {
|
|
3066
3087
|
const a = blocks[i], b = blocks[i + 1];
|
|
3067
3088
|
const ab = a.bbox, bb = b.bbox;
|
|
3068
|
-
const af = _nullishCoalesce(_optionalChain([a, 'access',
|
|
3089
|
+
const af = _nullishCoalesce(_optionalChain([a, 'access', _85 => _85.style, 'optionalAccess', _86 => _86.fontSize]), () => ( 0)), bf = _nullishCoalesce(_optionalChain([b, 'access', _87 => _87.style, 'optionalAccess', _88 => _88.fontSize]), () => ( 0));
|
|
3069
3090
|
const gap = ab && bb ? ab.y - (bb.y + bb.height) : Infinity;
|
|
3070
|
-
const centered = ab && bb && _optionalChain([a, 'access',
|
|
3091
|
+
const centered = ab && bb && _optionalChain([a, 'access', _89 => _89.style, 'optionalAccess', _90 => _90.fontName]) === _optionalChain([b, 'access', _91 => _91.style, 'optionalAccess', _92 => _92.fontName]) && Math.abs(ab.x + ab.width / 2 - (bb.x + bb.width / 2)) <= Math.max(5, af * 0.5);
|
|
3071
3092
|
const sameAnchor = ab && bb && Math.abs(ab.x - bb.x) <= 5;
|
|
3072
|
-
const wrapped = sameAnchor && _optionalChain([a, 'access',
|
|
3093
|
+
const wrapped = sameAnchor && _optionalChain([a, 'access', _93 => _93.style, 'optionalAccess', _94 => _94.fontName]) === _optionalChain([b, 'access', _95 => _95.style, 'optionalAccess', _96 => _96.fontName]) && af === bf && ab.width >= bb.width * 0.95 && (_nullishCoalesce(_optionalChain([a, 'access', _97 => _97.text, 'optionalAccess', _98 => _98.trim, 'call', _99 => _99(), 'access', _100 => _100.split, 'call', _101 => _101(/\s+/), 'access', _102 => _102.length]), () => ( 0))) >= 3;
|
|
3073
3094
|
const displayStack = centered && gap <= Math.min(af, bf) * 0.3 && Math.max(af, bf) <= Math.min(af, bf) * 1.45;
|
|
3074
3095
|
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)) {
|
|
3075
3096
|
i++;
|
|
@@ -3098,22 +3119,22 @@ function detectTypographyHeadings(blocks) {
|
|
|
3098
3119
|
if (page.some((block) => block.type === "heading")) continue;
|
|
3099
3120
|
const faceWeight = /* @__PURE__ */ new Map();
|
|
3100
3121
|
for (const block of page) {
|
|
3101
|
-
if (block.type !== "paragraph" || !block.text || !_optionalChain([block, 'access',
|
|
3122
|
+
if (block.type !== "paragraph" || !block.text || !_optionalChain([block, 'access', _103 => _103.style, 'optionalAccess', _104 => _104.fontName])) continue;
|
|
3102
3123
|
const face = block.style.fontName;
|
|
3103
3124
|
faceWeight.set(face, (_nullishCoalesce(faceWeight.get(face), () => ( 0))) + block.text.length);
|
|
3104
3125
|
}
|
|
3105
|
-
const bodyFace = _optionalChain([[...faceWeight], 'access',
|
|
3126
|
+
const bodyFace = _optionalChain([[...faceWeight], 'access', _105 => _105.sort, 'call', _106 => _106((a, b) => b[1] - a[1]), 'access', _107 => _107[0], 'optionalAccess', _108 => _108[0]]);
|
|
3106
3127
|
if (!bodyFace || (_nullishCoalesce(faceWeight.get(bodyFace), () => ( 0))) < 250) continue;
|
|
3107
3128
|
const sizeWeight = /* @__PURE__ */ new Map();
|
|
3108
3129
|
for (const block of page) {
|
|
3109
|
-
if (block.type !== "paragraph" || _optionalChain([block, 'access',
|
|
3130
|
+
if (block.type !== "paragraph" || _optionalChain([block, 'access', _109 => _109.style, 'optionalAccess', _110 => _110.fontName]) !== bodyFace || !block.style.fontSize) continue;
|
|
3110
3131
|
sizeWeight.set(block.style.fontSize, (_nullishCoalesce(sizeWeight.get(block.style.fontSize), () => ( 0))) + block.text.length);
|
|
3111
3132
|
}
|
|
3112
|
-
const bodySize = _nullishCoalesce(_optionalChain([[...sizeWeight], 'access',
|
|
3133
|
+
const bodySize = _nullishCoalesce(_optionalChain([[...sizeWeight], 'access', _111 => _111.sort, 'call', _112 => _112((a, b) => b[1] - a[1]), 'access', _113 => _113[0], 'optionalAccess', _114 => _114[0]]), () => ( 0));
|
|
3113
3134
|
for (let i = 0; i < page.length; i++) {
|
|
3114
3135
|
const block = page[i];
|
|
3115
3136
|
const { text, bbox, style } = block;
|
|
3116
|
-
if (block.type !== "paragraph" || !text || !bbox || !_optionalChain([style, 'optionalAccess',
|
|
3137
|
+
if (block.type !== "paragraph" || !text || !bbox || !_optionalChain([style, 'optionalAccess', _115 => _115.fontName]) || !style.fontSize) continue;
|
|
3117
3138
|
const title = text.trim();
|
|
3118
3139
|
const numbered = /^\d+(?:\.\d+)*\.?\s+[A-Z가-힣]/.test(title);
|
|
3119
3140
|
const faces = FACE_CHARS.get(block);
|
|
@@ -3143,16 +3164,16 @@ function detectDocumentStyleHeadings(blocks) {
|
|
|
3143
3164
|
for (const page of byPage.values()) {
|
|
3144
3165
|
const faceChars = /* @__PURE__ */ new Map();
|
|
3145
3166
|
for (const block of page) {
|
|
3146
|
-
if (block.type !== "paragraph" || !block.text || !_optionalChain([block, 'access',
|
|
3167
|
+
if (block.type !== "paragraph" || !block.text || !_optionalChain([block, 'access', _116 => _116.style, 'optionalAccess', _117 => _117.fontName])) continue;
|
|
3147
3168
|
faceChars.set(block.style.fontName, (_nullishCoalesce(faceChars.get(block.style.fontName), () => ( 0))) + block.text.length);
|
|
3148
3169
|
}
|
|
3149
|
-
const bodyFace = _optionalChain([[...faceChars], 'access',
|
|
3170
|
+
const bodyFace = _optionalChain([[...faceChars], 'access', _118 => _118.sort, 'call', _119 => _119((a, b) => b[1] - a[1]), 'access', _120 => _120[0], 'optionalAccess', _121 => _121[0]]);
|
|
3150
3171
|
if (!bodyFace || (_nullishCoalesce(faceChars.get(bodyFace), () => ( 0))) < 100) continue;
|
|
3151
|
-
const labels = page.filter((b) => b.type === "paragraph" && b.text && b.bbox && _optionalChain([b, 'access',
|
|
3172
|
+
const labels = page.filter((b) => b.type === "paragraph" && b.text && b.bbox && _optionalChain([b, 'access', _122 => _122.style, 'optionalAccess', _123 => _123.fontName]) && b.style.fontName !== bodyFace && b.text.trim().length >= 3 && b.text.trim().length <= 40);
|
|
3152
3173
|
for (const label of labels) {
|
|
3153
|
-
const peers = labels.filter((b) => _optionalChain([b, 'access',
|
|
3174
|
+
const peers = labels.filter((b) => _optionalChain([b, 'access', _124 => _124.style, 'optionalAccess', _125 => _125.fontName]) === _optionalChain([label, 'access', _126 => _126.style, 'optionalAccess', _127 => _127.fontName]) && Math.abs(b.bbox.y - label.bbox.y) <= 3 && Math.abs(b.bbox.x - label.bbox.x) >= 60);
|
|
3154
3175
|
if (peers.length < 2) continue;
|
|
3155
|
-
const value = page.find((b) => b.type === "paragraph" && b.bbox && _optionalChain([b, 'access',
|
|
3176
|
+
const value = page.find((b) => b.type === "paragraph" && b.bbox && _optionalChain([b, 'access', _128 => _128.style, 'optionalAccess', _129 => _129.fontName]) !== _optionalChain([label, 'access', _130 => _130.style, 'optionalAccess', _131 => _131.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);
|
|
3156
3177
|
if (value) {
|
|
3157
3178
|
label.type = "heading";
|
|
3158
3179
|
label.level = 2;
|
|
@@ -3161,7 +3182,7 @@ function detectDocumentStyleHeadings(blocks) {
|
|
|
3161
3182
|
const first = page.find((b) => b.type !== "image" && b.type !== "separator");
|
|
3162
3183
|
const second = page[page.indexOf(first) + 1];
|
|
3163
3184
|
const third = page[page.indexOf(first) + 2];
|
|
3164
|
-
if (!first || !second || !third || first.type !== "list" && first.type !== "paragraph" || second.type !== "paragraph" || !first.text || !second.text || !first.bbox || !second.bbox || !_optionalChain([first, 'access',
|
|
3185
|
+
if (!first || !second || !third || first.type !== "list" && first.type !== "paragraph" || second.type !== "paragraph" || !first.text || !second.text || !first.bbox || !second.bbox || !_optionalChain([first, 'access', _132 => _132.style, 'optionalAccess', _133 => _133.fontName]) || !_optionalChain([second, 'access', _134 => _134.style, 'optionalAccess', _135 => _135.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', _136 => _136.style, 'optionalAccess', _137 => _137.fontName]) !== bodyFace) continue;
|
|
3165
3186
|
first.type = "heading";
|
|
3166
3187
|
first.level = 1;
|
|
3167
3188
|
first.text = `${first.text.trim()} ${second.text.trim()}`;
|
|
@@ -3185,18 +3206,18 @@ function detectSiblingStyleHeadings(blocks) {
|
|
|
3185
3206
|
for (const page of byPage.values()) {
|
|
3186
3207
|
const bodyChars = /* @__PURE__ */ new Map();
|
|
3187
3208
|
for (const block of page) {
|
|
3188
|
-
if (block.type !== "paragraph" || !block.text || !_optionalChain([block, 'access',
|
|
3209
|
+
if (block.type !== "paragraph" || !block.text || !_optionalChain([block, 'access', _138 => _138.style, 'optionalAccess', _139 => _139.fontName])) continue;
|
|
3189
3210
|
const face = block.style.fontName;
|
|
3190
3211
|
bodyChars.set(face, (_nullishCoalesce(bodyChars.get(face), () => ( 0))) + block.text.length);
|
|
3191
3212
|
}
|
|
3192
|
-
const bodyFace = _optionalChain([[...bodyChars], 'access',
|
|
3193
|
-
const anchors = page.filter((b) => b.type === "heading" && b.text && _optionalChain([b, 'access',
|
|
3213
|
+
const bodyFace = _optionalChain([[...bodyChars], 'access', _140 => _140.sort, 'call', _141 => _141((a, b) => b[1] - a[1]), 'access', _142 => _142[0], 'optionalAccess', _143 => _143[0]]);
|
|
3214
|
+
const anchors = page.filter((b) => b.type === "heading" && b.text && _optionalChain([b, 'access', _144 => _144.style, 'optionalAccess', _145 => _145.fontName]) && b.style.fontName !== bodyFace);
|
|
3194
3215
|
for (const anchor of anchors) {
|
|
3195
3216
|
const numbered = /^([A-Z])\.\d+\s+/.exec(anchor.text.trim());
|
|
3196
3217
|
const lettered = /^([A-Z])\s+/.exec(anchor.text.trim());
|
|
3197
|
-
const peers = anchors.filter((b) => _optionalChain([b, 'access',
|
|
3218
|
+
const peers = anchors.filter((b) => _optionalChain([b, 'access', _146 => _146.style, 'optionalAccess', _147 => _147.fontName]) === _optionalChain([anchor, 'access', _148 => _148.style, 'optionalAccess', _149 => _149.fontName]) && Math.abs((_nullishCoalesce(_optionalChain([b, 'access', _150 => _150.style, 'optionalAccess', _151 => _151.fontSize]), () => ( 0))) - (_nullishCoalesce(_optionalChain([anchor, 'access', _152 => _152.style, 'optionalAccess', _153 => _153.fontSize]), () => ( 0)))) < 0.5);
|
|
3198
3219
|
if (peers.length < 2 && !numbered && !lettered) continue;
|
|
3199
|
-
const candidates = page.filter((b) => b.type === "paragraph" && b.text && b.bbox && _optionalChain([b, 'access',
|
|
3220
|
+
const candidates = page.filter((b) => b.type === "paragraph" && b.text && b.bbox && _optionalChain([b, 'access', _154 => _154.style, 'optionalAccess', _155 => _155.fontName]) === _optionalChain([anchor, 'access', _156 => _156.style, 'optionalAccess', _157 => _157.fontName]) && Math.abs((_nullishCoalesce(_optionalChain([b, 'access', _158 => _158.style, 'optionalAccess', _159 => _159.fontSize]), () => ( 0))) - (_nullishCoalesce(_optionalChain([anchor, 'access', _160 => _160.style, 'optionalAccess', _161 => _161.fontSize]), () => ( 0)))) < 0.5 && b.text.trim().length >= 3 && b.text.trim().length <= 80 && b.bbox.height <= (_nullishCoalesce(_optionalChain([b, 'access', _162 => _162.style, 'optionalAccess', _163 => _163.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()));
|
|
3200
3221
|
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));
|
|
3201
3222
|
if (siblings.length < (numbered || lettered ? 1 : 2)) continue;
|
|
3202
3223
|
for (const sibling of siblings) {
|
|
@@ -3215,11 +3236,11 @@ function detectRepeatedPageLabels(blocks) {
|
|
|
3215
3236
|
}
|
|
3216
3237
|
for (const page of byPage.values()) {
|
|
3217
3238
|
const bodyChars = /* @__PURE__ */ new Map();
|
|
3218
|
-
for (const b of page) if (b.type === "paragraph" && b.text && _optionalChain([b, 'access',
|
|
3239
|
+
for (const b of page) if (b.type === "paragraph" && b.text && _optionalChain([b, 'access', _164 => _164.style, 'optionalAccess', _165 => _165.fontName])) {
|
|
3219
3240
|
bodyChars.set(b.style.fontName, (_nullishCoalesce(bodyChars.get(b.style.fontName), () => ( 0))) + b.text.length);
|
|
3220
3241
|
}
|
|
3221
|
-
const bodyFace = _optionalChain([[...bodyChars], 'access',
|
|
3222
|
-
const candidates = page.filter((b) => b.type === "paragraph" && b.text && b.bbox && _optionalChain([b, 'access',
|
|
3242
|
+
const bodyFace = _optionalChain([[...bodyChars], 'access', _166 => _166.sort, 'call', _167 => _167((a, b) => b[1] - a[1]), 'access', _168 => _168[0], 'optionalAccess', _169 => _169[0]]);
|
|
3243
|
+
const candidates = page.filter((b) => b.type === "paragraph" && b.text && b.bbox && _optionalChain([b, 'access', _170 => _170.style, 'optionalAccess', _171 => _171.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);
|
|
3223
3244
|
const groups = /* @__PURE__ */ new Map();
|
|
3224
3245
|
for (const b of candidates) {
|
|
3225
3246
|
const key = `${b.style.fontName}:${b.style.fontSize}`;
|
|
@@ -3255,19 +3276,19 @@ function detectPageLeadHeadings(blocks) {
|
|
|
3255
3276
|
for (const page of byPage.values()) {
|
|
3256
3277
|
const content = page.filter((b) => b.type !== "image" && b.type !== "separator" && !(b.type === "paragraph" && !b.style));
|
|
3257
3278
|
const [first, second, third] = content;
|
|
3258
|
-
if (!_optionalChain([first, 'optionalAccess',
|
|
3279
|
+
if (!_optionalChain([first, 'optionalAccess', _172 => _172.bbox]) || !first.text || !_optionalChain([first, 'access', _173 => _173.style, 'optionalAccess', _174 => _174.fontSize]) || !second) continue;
|
|
3259
3280
|
const firstText = first.text.trim();
|
|
3260
3281
|
const captionLike = /^(?:Figure|Fig\.?|Table|표|그림)\s*\d/i;
|
|
3261
3282
|
const hasImage = page.some((b) => b.type === "image");
|
|
3262
|
-
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',
|
|
3283
|
+
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', _175 => _175.text, 'optionalAccess', _176 => _176.trim, 'call', _177 => _177()]), () => ( ""))) && (_nullishCoalesce(_optionalChain([second, 'access', _178 => _178.text, 'optionalAccess', _179 => _179.length]), () => ( 0))) >= 100 && second.bbox && first.bbox.y - (second.bbox.y + second.bbox.height) >= first.style.fontSize);
|
|
3263
3284
|
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);
|
|
3264
|
-
const firstIsSection = first.type === "list" && /^\d+\.\s+[A-Z][A-Z\s]{12,}$/.test(firstText) && second.type === "paragraph" && (_nullishCoalesce(_optionalChain([second, 'access',
|
|
3285
|
+
const firstIsSection = first.type === "list" && /^\d+\.\s+[A-Z][A-Z\s]{12,}$/.test(firstText) && second.type === "paragraph" && (_nullishCoalesce(_optionalChain([second, 'access', _180 => _180.text, 'optionalAccess', _181 => _181.length]), () => ( 0))) >= 100;
|
|
3265
3286
|
if (firstIsTitle || firstAboveProse || firstIsSection) {
|
|
3266
3287
|
first.type = "heading";
|
|
3267
3288
|
first.level = 1;
|
|
3268
3289
|
}
|
|
3269
|
-
if (first.type !== "heading" || captionLike.test(firstText) || second.type !== "paragraph" || !second.text || !second.bbox || !_optionalChain([second, 'access',
|
|
3270
|
-
const distinctFace = _optionalChain([third, 'access',
|
|
3290
|
+
if (first.type !== "heading" || captionLike.test(firstText) || second.type !== "paragraph" || !second.text || !second.bbox || !_optionalChain([second, 'access', _182 => _182.style, 'optionalAccess', _183 => _183.fontName]) || !second.style.fontSize || !_optionalChain([third, 'optionalAccess', _184 => _184.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;
|
|
3291
|
+
const distinctFace = _optionalChain([third, 'access', _185 => _185.style, 'optionalAccess', _186 => _186.fontName]) !== second.style.fontName;
|
|
3271
3292
|
const namedContents = /^Table of Contents$/i.test(second.text.trim());
|
|
3272
3293
|
if (distinctFace && third.text.length >= 60 || namedContents) {
|
|
3273
3294
|
second.type = "heading";
|
|
@@ -3278,24 +3299,24 @@ function detectPageLeadHeadings(blocks) {
|
|
|
3278
3299
|
function refineDocumentStyleHeadings(blocks) {
|
|
3279
3300
|
const faceChars = /* @__PURE__ */ new Map();
|
|
3280
3301
|
for (const block of blocks) {
|
|
3281
|
-
if (block.type !== "paragraph" || !block.text || !_optionalChain([block, 'access',
|
|
3302
|
+
if (block.type !== "paragraph" || !block.text || !_optionalChain([block, 'access', _187 => _187.style, 'optionalAccess', _188 => _188.fontName])) continue;
|
|
3282
3303
|
faceChars.set(block.style.fontName, (_nullishCoalesce(faceChars.get(block.style.fontName), () => ( 0))) + block.text.length);
|
|
3283
3304
|
}
|
|
3284
3305
|
const [bodyFace, bodyChars] = _nullishCoalesce([...faceChars].sort((a, b) => b[1] - a[1])[0], () => ( []));
|
|
3285
3306
|
if (!bodyFace || !bodyChars || bodyChars < 300) return;
|
|
3286
3307
|
for (let i = 0; i < blocks.length; i++) {
|
|
3287
3308
|
const block = blocks[i];
|
|
3288
|
-
const text = _nullishCoalesce(_optionalChain([block, 'access',
|
|
3309
|
+
const text = _nullishCoalesce(_optionalChain([block, 'access', _189 => _189.text, 'optionalAccess', _190 => _190.trim, 'call', _191 => _191()]), () => ( ""));
|
|
3289
3310
|
if (block.type === "heading" && /(?:https?:\/\/|www\.|^arxiv:|^doi:)/i.test(text)) {
|
|
3290
3311
|
block.type = "paragraph";
|
|
3291
3312
|
block.level = void 0;
|
|
3292
3313
|
continue;
|
|
3293
3314
|
}
|
|
3294
3315
|
const box = block.bbox, style = block.style;
|
|
3295
|
-
if (block.type !== "paragraph" || !box || !_optionalChain([style, 'optionalAccess',
|
|
3316
|
+
if (block.type !== "paragraph" || !box || !_optionalChain([style, 'optionalAccess', _192 => _192.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;
|
|
3296
3317
|
const previous = blocks[i - 1], next = blocks[i + 1];
|
|
3297
|
-
const pb = _optionalChain([previous, 'optionalAccess',
|
|
3298
|
-
if (!pb || !nb || previous.pageNumber !== block.pageNumber || next.pageNumber !== block.pageNumber || previous.type !== "paragraph" && previous.type !== "heading" || next.type !== "paragraph" || _optionalChain([next, 'access',
|
|
3318
|
+
const pb = _optionalChain([previous, 'optionalAccess', _193 => _193.bbox]), nb = _optionalChain([next, 'optionalAccess', _194 => _194.bbox]);
|
|
3319
|
+
if (!pb || !nb || previous.pageNumber !== block.pageNumber || next.pageNumber !== block.pageNumber || previous.type !== "paragraph" && previous.type !== "heading" || next.type !== "paragraph" || _optionalChain([next, 'access', _195 => _195.style, 'optionalAccess', _196 => _196.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;
|
|
3299
3320
|
block.type = "heading";
|
|
3300
3321
|
block.level = 2;
|
|
3301
3322
|
}
|
|
@@ -3345,7 +3366,7 @@ function detectMarkerHeadings(blocks) {
|
|
|
3345
3366
|
block.level = 4;
|
|
3346
3367
|
continue;
|
|
3347
3368
|
}
|
|
3348
|
-
if (/^[가-힣]{2,6}$/.test(text) && _optionalChain([block, 'access',
|
|
3369
|
+
if (/^[가-힣]{2,6}$/.test(text) && _optionalChain([block, 'access', _197 => _197.style, 'optionalAccess', _198 => _198.fontSize])) {
|
|
3349
3370
|
const prev = blocks[i - 1];
|
|
3350
3371
|
const next = blocks[i + 1];
|
|
3351
3372
|
const prevIsStructural = !prev || prev.type === "table" || prev.type === "heading" || prev.type === "separator";
|
|
@@ -3386,7 +3407,7 @@ function detectTableCaptions(blocks) {
|
|
|
3386
3407
|
block.table.caption = blocks[i - 1].text.trim();
|
|
3387
3408
|
blocks.splice(i - 1, 1);
|
|
3388
3409
|
i--;
|
|
3389
|
-
} else if (isCaptionCandidate(blocks[i + 1], block) && _optionalChain([blocks, 'access',
|
|
3410
|
+
} else if (isCaptionCandidate(blocks[i + 1], block) && _optionalChain([blocks, 'access', _199 => _199[i + 2], 'optionalAccess', _200 => _200.type]) !== "table") {
|
|
3390
3411
|
block.table.caption = blocks[i + 1].text.trim();
|
|
3391
3412
|
blocks.splice(i + 1, 1);
|
|
3392
3413
|
}
|
|
@@ -3593,21 +3614,23 @@ function detectSpecialKoreanTables(blocks) {
|
|
|
3593
3614
|
flushKvTable();
|
|
3594
3615
|
return result;
|
|
3595
3616
|
}
|
|
3596
|
-
function removeHeaderFooterBlocks(blocks, pageHeights, warnings) {
|
|
3617
|
+
function removeHeaderFooterBlocks(blocks, pageHeights, warnings, notes, tables = false) {
|
|
3597
3618
|
const ZONE_RATIO = 0.12;
|
|
3598
3619
|
const MIN_REPEAT = 3;
|
|
3599
3620
|
const topEntries = [];
|
|
3600
3621
|
const bottomEntries = [];
|
|
3601
3622
|
for (let bi = 0; bi < blocks.length; bi++) {
|
|
3602
3623
|
const b = blocks[bi];
|
|
3603
|
-
|
|
3624
|
+
const text = !tables ? _optionalChain([b, 'access', _201 => _201.text, 'optionalAccess', _202 => _202.trim, 'call', _203 => _203()]) : b.type === "table" && b.table ? b.table.cells.flat().map((c) => c.text.trim()).filter(Boolean).join(" | ") : void 0;
|
|
3625
|
+
if (!b.bbox || !b.pageNumber || !text) continue;
|
|
3604
3626
|
const ph = pageHeights.get(b.bbox.page) || pageHeights.get(b.pageNumber);
|
|
3605
3627
|
if (!ph) continue;
|
|
3606
3628
|
const blockTop = ph - (b.bbox.y + b.bbox.height);
|
|
3607
3629
|
const blockBottom = ph - b.bbox.y;
|
|
3608
|
-
const entry = { blockIdx: bi, page: b.pageNumber, text
|
|
3609
|
-
|
|
3610
|
-
|
|
3630
|
+
const entry = { blockIdx: bi, page: b.pageNumber, text };
|
|
3631
|
+
const boxMid = b.type === "table" && b.bbox.height <= ph * 0.05 ? (blockTop + blockBottom) / 2 : void 0;
|
|
3632
|
+
if ((_nullishCoalesce(boxMid, () => ( blockBottom))) <= ph * ZONE_RATIO) topEntries.push(entry);
|
|
3633
|
+
else if ((_nullishCoalesce(boxMid, () => ( blockTop))) >= ph * (1 - ZONE_RATIO)) bottomEntries.push(entry);
|
|
3611
3634
|
}
|
|
3612
3635
|
const removeSet = /* @__PURE__ */ new Set();
|
|
3613
3636
|
for (const entries of [topEntries, bottomEntries]) {
|
|
@@ -3629,7 +3652,7 @@ function removeHeaderFooterBlocks(blocks, pageHeights, warnings) {
|
|
|
3629
3652
|
for (const [p, count] of patternCount) {
|
|
3630
3653
|
const pages = [..._nullishCoalesce(patternPages.get(p), () => ( []))];
|
|
3631
3654
|
const span = pages.length ? Math.max(...pages) - Math.min(...pages) + 1 : 0;
|
|
3632
|
-
const pageNumbered = (_nullishCoalesce(_optionalChain([patternNumbers, 'access',
|
|
3655
|
+
const pageNumbered = !tables && (_nullishCoalesce(_optionalChain([patternNumbers, 'access', _204 => _204.get, 'call', _205 => _205(p), 'optionalAccess', _206 => _206.size]), () => ( 0))) > 1;
|
|
3633
3656
|
if (count >= MIN_REPEAT && pages.length >= MIN_REPEAT && (pages.length >= span * 0.4 || pageNumbered)) {
|
|
3634
3657
|
repeatedPatterns.add(p);
|
|
3635
3658
|
}
|
|
@@ -3637,9 +3660,11 @@ function removeHeaderFooterBlocks(blocks, pageHeights, warnings) {
|
|
|
3637
3660
|
for (const e of entries) {
|
|
3638
3661
|
const norm = e.text.replace(/\d+/g, "#");
|
|
3639
3662
|
if (!repeatedPatterns.has(norm)) continue;
|
|
3663
|
+
const noteMark = _optionalChain([e, 'access', _207 => _207.text, 'access', _208 => _208.match, 'call', _209 => _209(/^\d{1,3}\)/), 'optionalAccess', _210 => _210[0]]);
|
|
3664
|
+
if (noteMark && _optionalChain([notes, 'optionalAccess', _211 => _211.get, 'call', _212 => _212(e.page), 'optionalAccess', _213 => _213.marks, 'access', _214 => _214.some, 'call', _215 => _215((m) => m.mark === noteMark)])) continue;
|
|
3640
3665
|
const cand = blocks[e.blockIdx];
|
|
3641
3666
|
const cb = cand.bbox;
|
|
3642
|
-
const tableNote = /^(?:주\s*(?:\d+\s*[).:]|[::])|(?:자료|출처)\s*[::])/.test(e.text) && blocks.some((o) => {
|
|
3667
|
+
const tableNote = /^(?:주\s*(?:\d+\s*[).:]|[::])|(?:자료|출처)\s*[::])/.test(e.text.replace(/ \| /g, " ")) && blocks.some((o) => {
|
|
3643
3668
|
if (o.type !== "table" || !o.bbox || o.bbox.page !== cb.page) return false;
|
|
3644
3669
|
const gap = o.bbox.y - (cb.y + cb.height);
|
|
3645
3670
|
return gap >= 0 && gap <= cb.height && cb.x >= o.bbox.x && cb.x + cb.width <= o.bbox.x + o.bbox.width;
|
|
@@ -3650,7 +3675,7 @@ function removeHeaderFooterBlocks(blocks, pageHeights, warnings) {
|
|
|
3650
3675
|
if (bi === e.blockIdx) continue;
|
|
3651
3676
|
const o = blocks[bi];
|
|
3652
3677
|
if (!o.bbox || o.bbox.page !== cb.page) continue;
|
|
3653
|
-
const oNorm = _optionalChain([o, 'access',
|
|
3678
|
+
const oNorm = _optionalChain([o, 'access', _216 => _216.text, 'optionalAccess', _217 => _217.trim, 'call', _218 => _218(), 'access', _219 => _219.replace, 'call', _220 => _220(/\d+/g, "#")]);
|
|
3654
3679
|
if (oNorm && repeatedPatterns.has(oNorm)) continue;
|
|
3655
3680
|
const overlap2 = Math.min(cb.y + cb.height, o.bbox.y + o.bbox.height) - Math.max(cb.y, o.bbox.y);
|
|
3656
3681
|
if (overlap2 >= cb.height * 0.5) {
|
|
@@ -3693,7 +3718,7 @@ function recordCellLines(cell, items) {
|
|
|
3693
3718
|
function markImageCell(cell) {
|
|
3694
3719
|
IMAGE_CELLS.add(cell);
|
|
3695
3720
|
}
|
|
3696
|
-
var emptyCell = (cell) => !cell || !_optionalChain([cell, 'access',
|
|
3721
|
+
var emptyCell = (cell) => !cell || !_optionalChain([cell, 'access', _221 => _221.text, 'optionalAccess', _222 => _222.trim, 'call', _223 => _223()]) && !_optionalChain([cell, 'access', _224 => _224.blocks, 'optionalAccess', _225 => _225.length]) && !IMAGE_CELLS.has(cell);
|
|
3697
3722
|
function trimTable(table) {
|
|
3698
3723
|
let cols = table.cols;
|
|
3699
3724
|
while (cols > 0 && table.cells.every((row) => emptyCell(row[cols - 1]))) cols--;
|
|
@@ -3709,7 +3734,7 @@ function trimTable(table) {
|
|
|
3709
3734
|
function trimTrailingEmptyTableCols(blocks) {
|
|
3710
3735
|
for (const b of blocks) {
|
|
3711
3736
|
if (b.type !== "table" || !b.table) continue;
|
|
3712
|
-
for (const row of b.table.cells) for (const cell of row) if (_optionalChain([cell, 'access',
|
|
3737
|
+
for (const row of b.table.cells) for (const cell of row) if (_optionalChain([cell, 'access', _226 => _226.blocks, 'optionalAccess', _227 => _227.length])) trimTrailingEmptyTableCols(cell.blocks);
|
|
3713
3738
|
trimTable(b.table);
|
|
3714
3739
|
}
|
|
3715
3740
|
}
|
|
@@ -3729,7 +3754,7 @@ function mergeSliverColumns(grid, colXs, maxWidth) {
|
|
|
3729
3754
|
}
|
|
3730
3755
|
const ok = owner.every((row) => {
|
|
3731
3756
|
const o = row[c];
|
|
3732
|
-
return !!o && (o.colSpan > 1 || !o.text.trim() && !_optionalChain([o, 'access',
|
|
3757
|
+
return !!o && (o.colSpan > 1 || !o.text.trim() && !_optionalChain([o, 'access', _228 => _228.blocks, 'optionalAccess', _229 => _229.length]));
|
|
3733
3758
|
});
|
|
3734
3759
|
if (!ok) continue;
|
|
3735
3760
|
const spanning = /* @__PURE__ */ new Set();
|
|
@@ -3795,7 +3820,7 @@ function isProseTable(table) {
|
|
|
3795
3820
|
if (!(long > 0 && long >= total * 0.5 && longRows >= rows * 0.4)) return false;
|
|
3796
3821
|
for (let c = 0; c < table.cols; c++) {
|
|
3797
3822
|
const filled = table.cells.map((row) => row[c]).filter((cell) => cell && cell.colSpan < table.cols && cell.text.trim()).map((cell) => cell.text.trim());
|
|
3798
|
-
if (filled.length >= 3 && filled.length >= rows * 0.6 && filled.every((text) => text.length <= 30 && (_nullishCoalesce(_optionalChain([text, 'access',
|
|
3823
|
+
if (filled.length >= 3 && filled.length >= rows * 0.6 && filled.every((text) => text.length <= 30 && (_nullishCoalesce(_optionalChain([text, 'access', _230 => _230.match, 'call', _231 => _231(/\p{L}/gu), 'optionalAccess', _232 => _232.length]), () => ( 0))) >= 2)) return false;
|
|
3799
3824
|
}
|
|
3800
3825
|
return true;
|
|
3801
3826
|
}
|
|
@@ -3822,7 +3847,7 @@ function isChartTable(table) {
|
|
|
3822
3847
|
const numeric = texts.filter((text) => NUMERIC_CELL.test(text)).length;
|
|
3823
3848
|
if (numeric < texts.length * 0.5) return false;
|
|
3824
3849
|
for (let c = 0; c < table.cols; c++) {
|
|
3825
|
-
const ticks = table.cells.flatMap((row) => (_nullishCoalesce(_optionalChain([row, 'access',
|
|
3850
|
+
const ticks = table.cells.flatMap((row) => (_nullishCoalesce(_optionalChain([row, 'access', _233 => _233[c], 'optionalAccess', _234 => _234.text]), () => ( ""))).split(/\s+/)).filter((token) => /^-?[\d,]+(?:\.\d+)?%?$/.test(token)).map((token) => Number(token.replace(/[,%]/g, "")));
|
|
3826
3851
|
if (hasValueAxis(ticks)) return true;
|
|
3827
3852
|
}
|
|
3828
3853
|
const values = texts.filter((text) => text.split(/\s+/).every((token) => /^[-−–]?[\d,]*\.?\d+%?$/.test(token))).length;
|
|
@@ -3976,7 +4001,7 @@ function detectAlignedTwoColumnTables(rows, pageNum) {
|
|
|
3976
4001
|
continue;
|
|
3977
4002
|
}
|
|
3978
4003
|
const top = rows[i - 1];
|
|
3979
|
-
const title = _optionalChain([top, 'optionalAccess',
|
|
4004
|
+
const title = _optionalChain([top, 'optionalAccess', _235 => _235.items, 'access', _236 => _236.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;
|
|
3980
4005
|
const tableRows = title ? [title, ...body] : body;
|
|
3981
4006
|
const cells = tableRows.map((row, idx) => {
|
|
3982
4007
|
if (title && idx === 0) return [{ text: row.items[0].text, colSpan: 2, rowSpan: 1 }, { text: "", colSpan: 1, rowSpan: 1 }];
|
|
@@ -4032,12 +4057,12 @@ function isTwoColumnProse(r) {
|
|
|
4032
4057
|
if (t.rows < 8) return false;
|
|
4033
4058
|
const dense = [];
|
|
4034
4059
|
for (let c = 0; c < t.cols; c++) {
|
|
4035
|
-
const filled = t.cells.filter((row) => _optionalChain([row, 'access',
|
|
4060
|
+
const filled = t.cells.filter((row) => _optionalChain([row, 'access', _237 => _237[c], 'optionalAccess', _238 => _238.text, 'access', _239 => _239.trim, 'call', _240 => _240()])).length;
|
|
4036
4061
|
if (filled / t.rows >= 0.3) dense.push(c);
|
|
4037
4062
|
}
|
|
4038
4063
|
if (dense.length !== 2) return false;
|
|
4039
4064
|
for (const c of dense) {
|
|
4040
|
-
const lens = t.cells.map((row) => _nullishCoalesce(_optionalChain([row, 'access',
|
|
4065
|
+
const lens = t.cells.map((row) => _nullishCoalesce(_optionalChain([row, 'access', _241 => _241[c], 'optionalAccess', _242 => _242.text, 'access', _243 => _243.replace, 'call', _244 => _244(/\s+/g, ""), 'access', _245 => _245.length]), () => ( 0))).filter((n) => n > 0);
|
|
4041
4066
|
const avg = lens.reduce((s, v) => s + v, 0) / (lens.length || 1);
|
|
4042
4067
|
if (avg < 12) return false;
|
|
4043
4068
|
}
|
|
@@ -4433,7 +4458,7 @@ function assignRowItems(items, columns, numCols, headerFace) {
|
|
|
4433
4458
|
const runs = [];
|
|
4434
4459
|
for (const it of sorted) {
|
|
4435
4460
|
const last = runs[runs.length - 1];
|
|
4436
|
-
const prev = _optionalChain([last, 'optionalAccess',
|
|
4461
|
+
const prev = _optionalChain([last, 'optionalAccess', _246 => _246[last.length - 1]]);
|
|
4437
4462
|
if (prev && it.x - (prev.x + prev.w) <= Math.max(0.5, it.fontSize * 0.05) && !it.hasSpaceBefore) last.push(it);
|
|
4438
4463
|
else runs.push([it]);
|
|
4439
4464
|
}
|
|
@@ -4507,7 +4532,7 @@ function buildClusterTable(rows, columns, pageNum) {
|
|
|
4507
4532
|
() => Array.from({ length: numCols }, () => ({ text: "", colSpan: 1, rowSpan: 1 }))
|
|
4508
4533
|
);
|
|
4509
4534
|
const usedItems = /* @__PURE__ */ new Set();
|
|
4510
|
-
const headFaces = new Set(_optionalChain([rows, 'access',
|
|
4535
|
+
const headFaces = new Set(_optionalChain([rows, 'access', _247 => _247[0], 'optionalAccess', _248 => _248.items, 'access', _249 => _249.map, 'call', _250 => _250((i) => i.fontName)]));
|
|
4511
4536
|
const headerFace = headFaces.size === 1 && rows.slice(1).every((row) => row.items.every((i) => !headFaces.has(i.fontName))) ? [...headFaces][0] : void 0;
|
|
4512
4537
|
for (let r = 0; r < numRows; r++) {
|
|
4513
4538
|
const row = rows[r];
|
|
@@ -4537,7 +4562,7 @@ function buildClusterTable(rows, columns, pageNum) {
|
|
|
4537
4562
|
const nonEmptyCols = cells[r].filter((c) => c.text.trim()).length;
|
|
4538
4563
|
if (nonEmptyCols !== 1) continue;
|
|
4539
4564
|
if (cells[r][0].text.trim() !== "") continue;
|
|
4540
|
-
const contentText = _optionalChain([cells, 'access',
|
|
4565
|
+
const contentText = _optionalChain([cells, 'access', _251 => _251[r], 'access', _252 => _252.find, 'call', _253 => _253((c) => c.text.trim()), 'optionalAccess', _254 => _254.text, 'access', _255 => _255.trim, 'call', _256 => _256()]) || "";
|
|
4541
4566
|
if (/^[○●▶\-·]/.test(contentText)) continue;
|
|
4542
4567
|
for (let pr = r - 1; pr >= 0; pr--) {
|
|
4543
4568
|
if (cells[pr].some((c) => c.text.trim())) {
|
|
@@ -5136,16 +5161,16 @@ function isProseSpread(items) {
|
|
|
5136
5161
|
for (let i = 1; i < sorted.length; i++) {
|
|
5137
5162
|
gaps.push(sorted[i].x - (sorted[i - 1].x + sorted[i - 1].w));
|
|
5138
5163
|
}
|
|
5139
|
-
const maxGap =
|
|
5164
|
+
const maxGap = _chunkYRRBA4HWcjs.safeMax.call(void 0, gaps);
|
|
5140
5165
|
const avgLen = items.reduce((s, i) => s + i.text.length, 0) / items.length;
|
|
5141
5166
|
if (items.length >= 4 && maxGap < 40 && avgLen < 5) return true;
|
|
5142
|
-
const minGap =
|
|
5167
|
+
const minGap = _chunkYRRBA4HWcjs.safeMin.call(void 0, gaps);
|
|
5143
5168
|
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;
|
|
5144
5169
|
}
|
|
5145
5170
|
function detectColumns(yLines) {
|
|
5146
5171
|
const allItems = yLines.flat();
|
|
5147
5172
|
if (allItems.length === 0) return null;
|
|
5148
|
-
const pageWidth =
|
|
5173
|
+
const pageWidth = _chunkYRRBA4HWcjs.safeMax.call(void 0, allItems.map((i) => i.x + i.w)) - _chunkYRRBA4HWcjs.safeMin.call(void 0, allItems.map((i) => i.x));
|
|
5149
5174
|
if (pageWidth < 100) return null;
|
|
5150
5175
|
let bigoLineIdx = -1;
|
|
5151
5176
|
for (let i = 0; i < yLines.length; i++) {
|
|
@@ -5965,7 +5990,8 @@ function topTableBand(items) {
|
|
|
5965
5990
|
h: i.h,
|
|
5966
5991
|
fontSize: i.fontSize,
|
|
5967
5992
|
fontName: i.fontName,
|
|
5968
|
-
hasSpaceBefore: i.hasSpaceBefore
|
|
5993
|
+
hasSpaceBefore: i.hasSpaceBefore,
|
|
5994
|
+
syntheticSpace: i.syntheticSpace
|
|
5969
5995
|
})), 1);
|
|
5970
5996
|
if (!candidate.some((t) => t.table.cols >= 3 && t.table.rows >= 3 && t.usedItems.size >= top.length * 0.75)) continue;
|
|
5971
5997
|
return { top, rest: lines.slice(n).flat() };
|
|
@@ -6019,7 +6045,7 @@ function stackedTableBands(items) {
|
|
|
6019
6045
|
const caption = (start, end) => lines.slice(start, end).some((line) => /^Table\s+\d+\s*[:.]/i.test(mergeLineSimple(line).trim()));
|
|
6020
6046
|
while (runs.length > 0 && !caption(runs[runs.length - 1].end, lines.length)) runs.pop();
|
|
6021
6047
|
if (runs.length < 2) return null;
|
|
6022
|
-
if (runs.some((run, i) => !caption(run.end, _nullishCoalesce(_optionalChain([runs, 'access',
|
|
6048
|
+
if (runs.some((run, i) => !caption(run.end, _nullishCoalesce(_optionalChain([runs, 'access', _257 => _257[i + 1], 'optionalAccess', _258 => _258.start]), () => ( lines.length))))) return null;
|
|
6023
6049
|
const tables = runs.map((run) => lines.slice(run.start, run.end).flat());
|
|
6024
6050
|
const between = runs.slice(0, -1).map((run, i) => lines.slice(run.end, runs[i + 1].start).flat());
|
|
6025
6051
|
const tail = lines.slice(runs[runs.length - 1].end);
|
|
@@ -6182,7 +6208,7 @@ function extractPageBlocksWithLines(items, pageNum, opList, pageWidth, pageHeigh
|
|
|
6182
6208
|
const filled = fillBlanks(items, horizontals, verticals);
|
|
6183
6209
|
items = filled.items;
|
|
6184
6210
|
horizontals = filled.horizontals;
|
|
6185
|
-
const prevPage = _optionalChain([carry, 'optionalAccess',
|
|
6211
|
+
const prevPage = _optionalChain([carry, 'optionalAccess', _259 => _259.page]) === pageNum - 1 ? carry.clip : void 0;
|
|
6186
6212
|
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 };
|
|
6187
6213
|
if (carry) {
|
|
6188
6214
|
carry.page = pageNum;
|
|
@@ -6211,7 +6237,7 @@ function extractPageBlocksWithLines(items, pageNum, opList, pageWidth, pageHeigh
|
|
|
6211
6237
|
if (underlines.size) horizontals = horizontals.filter((l) => !underlines.has(l));
|
|
6212
6238
|
wrapUnderlineRuns(items);
|
|
6213
6239
|
const lineGrids = detectTables ? buildTableGrids(horizontals, verticals) : [];
|
|
6214
|
-
const tableClipGrids = dropInsetClipGrids(dropShadingClipGrids(clipGrids, lineGrids, extracted.fillRects, verticals), lineGrids);
|
|
6240
|
+
const tableClipGrids = dropHeadBandClipGrids(dropInsetClipGrids(dropShadingClipGrids(clipGrids, lineGrids, extracted.fillRects, verticals), lineGrids), lineGrids);
|
|
6215
6241
|
const grids = [...tableClipGrids, ...dropGridsInside(lineGrids, tableClipGrids, clipResult.containers)];
|
|
6216
6242
|
if (grids.length === 1 && grids[0].rowYs.length === 2 && grids[0].colXs.length === 2 && grids[0].bbox.x2 - grids[0].bbox.x1 > pageWidth * 1.2 && grids[0].bbox.y2 - grids[0].bbox.y1 > pageHeight * 1.2) {
|
|
6217
6243
|
return extractPageBlocksFallback(items, pageNum, true, detectTables, lex);
|
|
@@ -6415,6 +6441,7 @@ function extractBlocksWithGrids(items, pageNum, pageWidth, pageHeight, grids, ho
|
|
|
6415
6441
|
fontSize: i.fontSize,
|
|
6416
6442
|
fontName: i.fontName,
|
|
6417
6443
|
hasSpaceBefore: i.hasSpaceBefore,
|
|
6444
|
+
syntheticSpace: i.syntheticSpace,
|
|
6418
6445
|
seq: i.seq
|
|
6419
6446
|
}));
|
|
6420
6447
|
const cellTextMap = mapTextToCells(textItems, cells);
|
|
@@ -6482,13 +6509,13 @@ function extractBlocksWithGrids(items, pageNum, pageWidth, pageHeight, grids, ho
|
|
|
6482
6509
|
if (!assignedItems.has(textItems[ti])) usedItems.delete(tableItems[ti]);
|
|
6483
6510
|
}
|
|
6484
6511
|
}
|
|
6485
|
-
if (unitLine.length > 0 && rebuiltUsed && !/^\s*\(\s*단위\s*[::]/.test(_nullishCoalesce(_optionalChain([finalGrid, 'access',
|
|
6512
|
+
if (unitLine.length > 0 && rebuiltUsed && !/^\s*\(\s*단위\s*[::]/.test(_nullishCoalesce(_optionalChain([finalGrid, 'access', _260 => _260[0], 'optionalAccess', _261 => _261[0], 'optionalAccess', _262 => _262.text]), () => ( "")))) {
|
|
6486
6513
|
finalGrid.unshift(Array.from({ length: numCols }, (_, c) => ({ text: c === 0 ? cleanCellText(unitText) : "", colSpan: c === 0 ? numCols : 1, rowSpan: 1 })));
|
|
6487
6514
|
finalRows++;
|
|
6488
6515
|
for (const item of unitLine) usedItems.add(item);
|
|
6489
6516
|
}
|
|
6490
6517
|
const filledCells = finalGrid.flat().filter((c) => c.text.trim()).length;
|
|
6491
|
-
if (!rebuiltUsed && filledCells * 2 >= finalGrid.flat().length && !/^\s*\(\s*단위\s*[::]/.test(_nullishCoalesce(_optionalChain([finalGrid, 'access',
|
|
6518
|
+
if (!rebuiltUsed && filledCells * 2 >= finalGrid.flat().length && !/^\s*\(\s*단위\s*[::]/.test(_nullishCoalesce(_optionalChain([finalGrid, 'access', _263 => _263[0], 'optionalAccess', _264 => _264[0], 'optionalAccess', _265 => _265.text]), () => ( "")))) {
|
|
6492
6519
|
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);
|
|
6493
6520
|
const line = above.filter((it) => Math.abs(it.y - Math.min(...above.map((a) => a.y))) <= 1).sort((a, b) => a.x - b.x);
|
|
6494
6521
|
const text = line.map((it) => it.text).join("");
|
|
@@ -6501,7 +6528,7 @@ function extractBlocksWithGrids(items, pageNum, pageWidth, pageHeight, grids, ho
|
|
|
6501
6528
|
}
|
|
6502
6529
|
let semanticOneColumn = false;
|
|
6503
6530
|
if (!grid.cells && numCols === 1 && numGridRows >= 2) {
|
|
6504
|
-
const populatedRows = finalGrid.filter((row) => _optionalChain([row, 'access',
|
|
6531
|
+
const populatedRows = finalGrid.filter((row) => _optionalChain([row, 'access', _266 => _266[0], 'optionalAccess', _267 => _267.text, 'access', _268 => _268.trim, 'call', _269 => _269()]));
|
|
6505
6532
|
if (populatedRows.length >= 4) {
|
|
6506
6533
|
const fontSizes = tableItems.map((item) => item.fontSize).filter((size) => size > 0).sort((a, b) => a - b);
|
|
6507
6534
|
const medianFont = _nullishCoalesce(fontSizes[Math.floor(fontSizes.length / 2)], () => ( 0));
|
|
@@ -6527,6 +6554,7 @@ function extractBlocksWithGrids(items, pageNum, pageWidth, pageHeight, grids, ho
|
|
|
6527
6554
|
fontSize: i.fontSize,
|
|
6528
6555
|
fontName: i.fontName,
|
|
6529
6556
|
hasSpaceBefore: i.hasSpaceBefore,
|
|
6557
|
+
syntheticSpace: i.syntheticSpace,
|
|
6530
6558
|
seq: i.seq
|
|
6531
6559
|
})))), colSpan: 1, rowSpan: 1 })));
|
|
6532
6560
|
finalRows++;
|
|
@@ -6575,7 +6603,7 @@ function extractBlocksWithGrids(items, pageNum, pageWidth, pageHeight, grids, ho
|
|
|
6575
6603
|
height: grid.bbox.y2 - grid.bbox.y1
|
|
6576
6604
|
};
|
|
6577
6605
|
if (numRows === 1 && numCols === 1 && gridW < pageWidth * 0.35) {
|
|
6578
|
-
const prose = _nullishCoalesce(_optionalChain([finalGrid, 'access',
|
|
6606
|
+
const prose = _nullishCoalesce(_optionalChain([finalGrid, 'access', _270 => _270[0], 'optionalAccess', _271 => _271[0], 'optionalAccess', _272 => _272.text]), () => ( ""));
|
|
6579
6607
|
const besideLines = (side) => new Set(side.map((it) => Math.round(it.y / 3))).size;
|
|
6580
6608
|
const rightLines = items.filter((it) => it.x >= grid.bbox.x2 + 3 && it.y >= grid.bbox.y1 && it.y <= grid.bbox.y2);
|
|
6581
6609
|
const leftLines = items.filter((it) => it.x + it.w <= grid.bbox.x1 - 3 && it.y >= grid.bbox.y1 && it.y <= grid.bbox.y2);
|
|
@@ -6623,12 +6651,13 @@ function extractBlocksWithGrids(items, pageNum, pageWidth, pageHeight, grids, ho
|
|
|
6623
6651
|
h: i.h,
|
|
6624
6652
|
fontSize: i.fontSize,
|
|
6625
6653
|
fontName: i.fontName,
|
|
6626
|
-
hasSpaceBefore: i.hasSpaceBefore
|
|
6654
|
+
hasSpaceBefore: i.hasSpaceBefore,
|
|
6655
|
+
syntheticSpace: i.syntheticSpace
|
|
6627
6656
|
}));
|
|
6628
6657
|
const proseColumns = findTwoColumnProseCutX(clusterItems) !== null || detectPersistentColumnGutter(remaining.map((i) => ({ x: i.x, y: i.y, w: i.w, h: i.h > 0 ? i.h : i.fontSize }))) !== null;
|
|
6629
6658
|
const clusterResults = (proseColumns ? [] : detectClusterTables(clusterItems, pageNum)).filter((cr) => {
|
|
6630
6659
|
const b = cr.bbox;
|
|
6631
|
-
return !blocks.some((x) => x.type === "paragraph" && x.bbox && (_nullishCoalesce(_optionalChain([x, 'access',
|
|
6660
|
+
return !blocks.some((x) => x.type === "paragraph" && x.bbox && (_nullishCoalesce(_optionalChain([x, 'access', _273 => _273.text, 'optionalAccess', _274 => _274.match, 'call', _275 => _275(/\p{L}/gu), 'optionalAccess', _276 => _276.length]), () => ( 0))) >= 10 && Math.min(x.bbox.x + x.bbox.width, b.x + b.width) - Math.max(x.bbox.x, b.x) >= 0.8 * b.width && x.bbox.y >= b.y - 2 && x.bbox.y + x.bbox.height <= b.y + b.height + 2);
|
|
6632
6661
|
});
|
|
6633
6662
|
if (clusterResults.length > 0) {
|
|
6634
6663
|
const ciToIdx = /* @__PURE__ */ new Map();
|
|
@@ -6662,7 +6691,7 @@ function extractBlocksWithGrids(items, pageNum, pageWidth, pageHeight, grids, ho
|
|
|
6662
6691
|
if (gutterX !== null) {
|
|
6663
6692
|
const gx = gutterX;
|
|
6664
6693
|
const allY = remaining.map((i) => i.y);
|
|
6665
|
-
const pageH =
|
|
6694
|
+
const pageH = _chunkYRRBA4HWcjs.safeMax.call(void 0, allY) - _chunkYRRBA4HWcjs.safeMin.call(void 0, allY);
|
|
6666
6695
|
const gapThreshold = Math.max(15, pageH * 0.03);
|
|
6667
6696
|
const sides = [
|
|
6668
6697
|
remaining.filter((i) => i.x + i.w <= gx),
|
|
@@ -6682,7 +6711,7 @@ function extractBlocksWithGrids(items, pageNum, pageWidth, pageHeight, grids, ho
|
|
|
6682
6711
|
finalTextBlocks = detectListBlocks(textBlocks);
|
|
6683
6712
|
} else {
|
|
6684
6713
|
const allY = remaining.map((i) => i.y);
|
|
6685
|
-
const pageH =
|
|
6714
|
+
const pageH = _chunkYRRBA4HWcjs.safeMax.call(void 0, allY) - _chunkYRRBA4HWcjs.safeMin.call(void 0, allY);
|
|
6686
6715
|
const groups = xyCutOrder(remaining, Math.max(15, pageH * 0.03));
|
|
6687
6716
|
const textBlocks = [];
|
|
6688
6717
|
for (const group of groups) {
|
|
@@ -6937,7 +6966,8 @@ function extractPageBlocksFallback(items, pageNum, fullPage = false, detectTable
|
|
|
6937
6966
|
h: i.h,
|
|
6938
6967
|
fontSize: i.fontSize,
|
|
6939
6968
|
fontName: i.fontName,
|
|
6940
|
-
hasSpaceBefore: i.hasSpaceBefore
|
|
6969
|
+
hasSpaceBefore: i.hasSpaceBefore,
|
|
6970
|
+
syntheticSpace: i.syntheticSpace
|
|
6941
6971
|
}));
|
|
6942
6972
|
const textRects = items.map((i) => ({ x: i.x, y: i.y, w: i.w, h: i.h > 0 ? i.h : i.fontSize }));
|
|
6943
6973
|
const earlyProseCut = fullPage && detectTables ? _nullishCoalesce(_nullishCoalesce(findTwoColumnProseCutX(clusterItems), () => ( persistentGutter(textRects))), () => ( (figures.length > 0 ? detectColumnGutter([...textRects, ...figures]) : null))) : null;
|
|
@@ -6995,7 +7025,7 @@ function extractPageBlocksFallback(items, pageNum, fullPage = false, detectTable
|
|
|
6995
7025
|
blocks.push(...columnTextToBlocks(tableText, pageNum, bbox, dominantStyle(items)));
|
|
6996
7026
|
} else {
|
|
6997
7027
|
const allY = items.map((i) => i.y);
|
|
6998
|
-
const pageHeight =
|
|
7028
|
+
const pageHeight = _chunkYRRBA4HWcjs.safeMax.call(void 0, allY) - _chunkYRRBA4HWcjs.safeMin.call(void 0, allY);
|
|
6999
7029
|
const gapThreshold = Math.max(15, pageHeight * 0.03);
|
|
7000
7030
|
const orderedGroups = proseCutX !== null ? splitTwoColumnProse(items, proseCutX) : xyCutOrder(items, gapThreshold);
|
|
7001
7031
|
for (const group of orderedGroups) {
|
|
@@ -7055,5 +7085,6 @@ function extractPageBlocksFallback(items, pageNum, fullPage = false, detectTable
|
|
|
7055
7085
|
|
|
7056
7086
|
|
|
7057
7087
|
|
|
7058
|
-
|
|
7059
|
-
|
|
7088
|
+
|
|
7089
|
+
exports.OCR_DET_MODEL = OCR_DET_MODEL; exports.OCR_REC_MODEL = OCR_REC_MODEL; exports.OCR_REC_DICT = OCR_REC_DICT; exports.getOcrModelsDir = getOcrModelsDir; exports.ensureOcrModels = ensureOcrModels; exports.ocrModelsCached = ocrModelsCached; exports.parseCharacterDict = parseCharacterDict; exports.extractLines = extractLines; exports.extractImageRegions = extractImageRegions; exports.filterHiddenText = filterHiddenText; exports.collapseEvenSpacing = collapseEvenSpacing; exports.normalizeItems = normalizeItems; exports.WrapLexicon = WrapLexicon; exports.startsNewItem = startsNewItem; exports.wrapJoiner = wrapJoiner; exports.joinPageBreakWraps = joinPageBreakWraps; exports.latinSoftWrap = latinSoftWrap; exports.TOC_BLOCKS = TOC_BLOCKS; exports.computeMedianFontSizeFromFreq = computeMedianFontSizeFromFreq; exports.detectHeadings = detectHeadings; exports.mergeStackedHeadingLines = mergeStackedHeadingLines; exports.detectTypographyHeadings = detectTypographyHeadings; exports.detectDocumentStyleHeadings = detectDocumentStyleHeadings; exports.detectSiblingStyleHeadings = detectSiblingStyleHeadings; exports.detectRepeatedPageLabels = detectRepeatedPageLabels; exports.detectPageLeadHeadings = detectPageLeadHeadings; exports.refineDocumentStyleHeadings = refineDocumentStyleHeadings; exports.detectMarkerHeadings = detectMarkerHeadings; exports.detectTableCaptions = detectTableCaptions; exports.detectKoreanListBlocks = detectKoreanListBlocks; exports.removeHeaderFooterBlocks = removeHeaderFooterBlocks; exports.CLIP_TABLES = CLIP_TABLES; exports.TABLE_COLXS = TABLE_COLXS; exports.EMPTY_PARTS = EMPTY_PARTS; exports.IMAGE_CELLS = IMAGE_CELLS; exports.FILLER_CELLS = FILLER_CELLS; exports.CONT_PARTS = CONT_PARTS; exports.CELL_LINES = CELL_LINES; exports.trimTrailingEmptyTableCols = trimTrailingEmptyTableCols; exports.extractPageBlocksWithLines = extractPageBlocksWithLines;
|
|
7090
|
+
//# sourceMappingURL=chunk-7IRHSRPU.cjs.map
|