kordoc 4.24.7 → 4.24.8
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 +6 -7
- package/dist/{-GQDQXRQN.js → -TLCDUU22.js} +11 -11
- package/dist/{chunk-E35YPWOX.js → chunk-5MQG3GJI.js} +2 -2
- package/dist/{chunk-MNG25FK4.cjs → chunk-73MRAQXA.cjs} +192 -176
- package/dist/chunk-73MRAQXA.cjs.map +1 -0
- package/dist/{chunk-VHAOAQZZ.cjs → chunk-7F35EPMM.cjs} +3 -3
- package/dist/chunk-7F35EPMM.cjs.map +1 -0
- package/dist/{chunk-FQVWYJNM.js → chunk-7JUF6G6Z.js} +2 -2
- package/dist/{chunk-OMJPCWKS.js → chunk-7XPTKW76.js} +2 -2
- package/dist/{chunk-MLFPEETP.js → chunk-BJABLQMB.js} +2 -2
- package/dist/{chunk-YQB3LPKQ.cjs → chunk-C3BOYTY5.cjs} +2 -2
- package/dist/chunk-C3BOYTY5.cjs.map +1 -0
- package/dist/{chunk-FIS3WY5Q.js → chunk-CB57N2MG.js} +2 -2
- package/dist/{chunk-BNIXSB6D.js → chunk-D3EHIHYN.js} +2 -2
- package/dist/{chunk-O4RQCDN2.js → chunk-DPB6ZVQ5.js} +33 -17
- package/dist/chunk-DPB6ZVQ5.js.map +1 -0
- package/dist/{chunk-JKZY6FX5.js → chunk-F7UWIMUA.js} +2 -2
- package/dist/{chunk-EIUXBJZP.js → chunk-FSWJC5RR.js} +3 -3
- package/dist/chunk-GS7T56RP.cjs.map +1 -1
- package/dist/{chunk-EIGCAAVM.js → chunk-IT5XO3UG.js} +32 -16
- package/dist/chunk-IT5XO3UG.js.map +1 -0
- package/dist/chunk-J55UQC5H.cjs.map +1 -1
- package/dist/{chunk-UDUEOBS5.js → chunk-J7MFKS73.js} +2 -2
- package/dist/{chunk-AYGMF6H5.cjs → chunk-JM7PZM6E.cjs} +3 -3
- package/dist/chunk-JM7PZM6E.cjs.map +1 -0
- package/dist/{chunk-DEDUWANG.js → chunk-K2FGQ5D5.js} +11 -11
- package/dist/{chunk-GMKFXPEI.js → chunk-KA6JZZIW.js} +5 -5
- package/dist/chunk-KA6JZZIW.js.map +1 -0
- package/dist/{chunk-OPNMXBUR.js → chunk-N2XN6GAQ.js} +2 -2
- package/dist/{chunk-EJPPVB2Y.js → chunk-NE6G6LCP.js} +2 -2
- package/dist/{chunk-7BZBMXWD.cjs → chunk-NW2CKOFL.cjs} +6 -6
- package/dist/chunk-NW2CKOFL.cjs.map +1 -0
- package/dist/{chunk-N2JZGYFK.js → chunk-OUJIV2AM.js} +4 -4
- package/dist/chunk-OUJIV2AM.js.map +1 -0
- package/dist/{chunk-7ICC55XY.js → chunk-RCDRTQ37.js} +2 -2
- package/dist/{chunk-ZQQGV7K2.js → chunk-RCT5MO53.js} +6 -6
- package/dist/{chunk-BLWDQEBY.js → chunk-TDB27K2Z.js} +2 -2
- package/dist/chunk-TK3FDAEE.cjs.map +1 -1
- package/dist/{chunk-WVZXPEHX.js → chunk-TTUAJYTC.js} +5 -5
- package/dist/chunk-TTUAJYTC.js.map +1 -0
- package/dist/{chunk-C4AY47C5.js → chunk-WTSID6AI.js} +2 -2
- package/dist/{chunk-CG2Z6NB3.js → chunk-XOUZC7MX.js} +2 -2
- package/dist/{chunk-DZRXJEOF.js → chunk-Z5DT55TW.js} +3 -3
- package/dist/{chunk-V4PS653P.cjs → chunk-ZJYNTA5R.cjs} +57 -57
- package/dist/chunk-ZJYNTA5R.cjs.map +1 -0
- package/dist/chunks-S2GGFN6W.js +10 -0
- package/dist/cli.js +30 -30
- package/dist/{formula-6XLWGUCB.js → formula-DZMBNPWT.js} +4 -4
- package/dist/{formula-DCC5EOSX.js → formula-PNMQ5JFJ.js} +3 -3
- package/dist/{formula-C55TRBHH.cjs → formula-ZLNSVWS6.cjs} +9 -9
- package/dist/formula-ZLNSVWS6.cjs.map +1 -0
- package/dist/{image-ocr-L736MGYD.js → image-ocr-BPH25SFW.js} +9 -9
- package/dist/{image-ocr-K3ZXDUNU.js → image-ocr-P5Q6YXTO.js} +6 -6
- package/dist/{image-ocr-EV7GVD3W.cjs → image-ocr-YUXCVOOP.cjs} +17 -17
- package/dist/image-ocr-YUXCVOOP.cjs.map +1 -0
- package/dist/index.cjs +340 -340
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +6 -6
- package/dist/mcp.js +23 -23
- package/dist/{model-bundle-OOOJFMGR.js → model-bundle-XAM6JFZV.js} +5 -5
- package/dist/{models-ELFZII4R.js → models-6Q5ULSTP.js} +5 -5
- package/dist/page-range-QHHFTL7X.cjs.map +1 -1
- package/dist/{parse-worker-v2-WS35WZY5.js → parse-worker-v2-ONX5QLJZ.js} +12 -12
- package/dist/{parser-CNRI55MG.js → parser-54R7ENH6.js} +9 -9
- package/dist/{parser-K7Y44QHS.js → parser-JHXN4S6L.js} +12 -12
- package/dist/{parser-X6P3JBT2.cjs → parser-Z352BN56.cjs} +159 -159
- package/dist/parser-Z352BN56.cjs.map +1 -0
- package/dist/{pdf-ocr-QQPZLIHM.js → pdf-ocr-FQ4LAXM6.js} +9 -9
- package/dist/{pdf-ocr-MVNHXGPS.js → pdf-ocr-LFVER7IE.js} +6 -6
- package/dist/pdf-ocr-SMFFJYTD.cjs +31 -0
- package/dist/pdf-ocr-SMFFJYTD.cjs.map +1 -0
- package/dist/{profile-io-GSRLMU4D.js → profile-io-YW5QWKBB.js} +3 -3
- package/dist/{rasterize-3H5QKDH2.js → rasterize-T4S3NMQ7.js} +3 -3
- package/dist/{redact-doc-TLBF7J7W.js → redact-doc-CAVBR5XO.js} +11 -11
- package/dist/{render-FTCOQ6WO.js → render-ZW52ZX6R.js} +7 -7
- package/dist/seal-TQ3RLVVT.js +10 -0
- package/dist/{setup-WVZ47AKV.js → setup-7UGSJPJP.js} +3 -3
- package/dist/visual-6GXHKPCJ.js +21 -0
- package/dist/{watch-CA32Z7XB.js → watch-M4A7B5WS.js} +12 -12
- package/package.json +4 -4
- package/dist/chunk-7BZBMXWD.cjs.map +0 -1
- package/dist/chunk-AYGMF6H5.cjs.map +0 -1
- package/dist/chunk-EIGCAAVM.js.map +0 -1
- package/dist/chunk-GMKFXPEI.js.map +0 -1
- package/dist/chunk-MNG25FK4.cjs.map +0 -1
- package/dist/chunk-N2JZGYFK.js.map +0 -1
- package/dist/chunk-O4RQCDN2.js.map +0 -1
- package/dist/chunk-V4PS653P.cjs.map +0 -1
- package/dist/chunk-VHAOAQZZ.cjs.map +0 -1
- package/dist/chunk-WVZXPEHX.js.map +0 -1
- package/dist/chunk-YQB3LPKQ.cjs.map +0 -1
- package/dist/chunks-XURCANPP.js +0 -10
- package/dist/formula-C55TRBHH.cjs.map +0 -1
- package/dist/image-ocr-EV7GVD3W.cjs.map +0 -1
- package/dist/parser-X6P3JBT2.cjs.map +0 -1
- package/dist/pdf-ocr-S6GSKOPT.cjs +0 -31
- package/dist/pdf-ocr-S6GSKOPT.cjs.map +0 -1
- package/dist/seal-74R7KDRY.js +0 -10
- package/dist/visual-TEW6Y3NH.js +0 -21
- /package/dist/{-GQDQXRQN.js.map → -TLCDUU22.js.map} +0 -0
- /package/dist/{chunk-E35YPWOX.js.map → chunk-5MQG3GJI.js.map} +0 -0
- /package/dist/{chunk-FQVWYJNM.js.map → chunk-7JUF6G6Z.js.map} +0 -0
- /package/dist/{chunk-OMJPCWKS.js.map → chunk-7XPTKW76.js.map} +0 -0
- /package/dist/{chunk-MLFPEETP.js.map → chunk-BJABLQMB.js.map} +0 -0
- /package/dist/{chunk-FIS3WY5Q.js.map → chunk-CB57N2MG.js.map} +0 -0
- /package/dist/{chunk-BNIXSB6D.js.map → chunk-D3EHIHYN.js.map} +0 -0
- /package/dist/{chunk-JKZY6FX5.js.map → chunk-F7UWIMUA.js.map} +0 -0
- /package/dist/{chunk-EIUXBJZP.js.map → chunk-FSWJC5RR.js.map} +0 -0
- /package/dist/{chunk-UDUEOBS5.js.map → chunk-J7MFKS73.js.map} +0 -0
- /package/dist/{chunk-DEDUWANG.js.map → chunk-K2FGQ5D5.js.map} +0 -0
- /package/dist/{chunk-OPNMXBUR.js.map → chunk-N2XN6GAQ.js.map} +0 -0
- /package/dist/{chunk-EJPPVB2Y.js.map → chunk-NE6G6LCP.js.map} +0 -0
- /package/dist/{chunk-7ICC55XY.js.map → chunk-RCDRTQ37.js.map} +0 -0
- /package/dist/{chunk-ZQQGV7K2.js.map → chunk-RCT5MO53.js.map} +0 -0
- /package/dist/{chunk-BLWDQEBY.js.map → chunk-TDB27K2Z.js.map} +0 -0
- /package/dist/{chunk-C4AY47C5.js.map → chunk-WTSID6AI.js.map} +0 -0
- /package/dist/{chunk-CG2Z6NB3.js.map → chunk-XOUZC7MX.js.map} +0 -0
- /package/dist/{chunk-DZRXJEOF.js.map → chunk-Z5DT55TW.js.map} +0 -0
- /package/dist/{chunks-XURCANPP.js.map → chunks-S2GGFN6W.js.map} +0 -0
- /package/dist/{formula-6XLWGUCB.js.map → formula-DZMBNPWT.js.map} +0 -0
- /package/dist/{formula-DCC5EOSX.js.map → formula-PNMQ5JFJ.js.map} +0 -0
- /package/dist/{image-ocr-L736MGYD.js.map → image-ocr-BPH25SFW.js.map} +0 -0
- /package/dist/{image-ocr-K3ZXDUNU.js.map → image-ocr-P5Q6YXTO.js.map} +0 -0
- /package/dist/{model-bundle-OOOJFMGR.js.map → model-bundle-XAM6JFZV.js.map} +0 -0
- /package/dist/{models-ELFZII4R.js.map → models-6Q5ULSTP.js.map} +0 -0
- /package/dist/{parse-worker-v2-WS35WZY5.js.map → parse-worker-v2-ONX5QLJZ.js.map} +0 -0
- /package/dist/{parser-CNRI55MG.js.map → parser-54R7ENH6.js.map} +0 -0
- /package/dist/{parser-K7Y44QHS.js.map → parser-JHXN4S6L.js.map} +0 -0
- /package/dist/{pdf-ocr-MVNHXGPS.js.map → pdf-ocr-FQ4LAXM6.js.map} +0 -0
- /package/dist/{pdf-ocr-QQPZLIHM.js.map → pdf-ocr-LFVER7IE.js.map} +0 -0
- /package/dist/{profile-io-GSRLMU4D.js.map → profile-io-YW5QWKBB.js.map} +0 -0
- /package/dist/{rasterize-3H5QKDH2.js.map → rasterize-T4S3NMQ7.js.map} +0 -0
- /package/dist/{redact-doc-TLBF7J7W.js.map → redact-doc-CAVBR5XO.js.map} +0 -0
- /package/dist/{render-FTCOQ6WO.js.map → render-ZW52ZX6R.js.map} +0 -0
- /package/dist/{seal-74R7KDRY.js.map → seal-TQ3RLVVT.js.map} +0 -0
- /package/dist/{setup-WVZ47AKV.js.map → setup-7UGSJPJP.js.map} +0 -0
- /package/dist/{visual-TEW6Y3NH.js.map → visual-6GXHKPCJ.js.map} +0 -0
- /package/dist/{watch-CA32Z7XB.js.map → watch-M4A7B5WS.js.map} +0 -0
|
@@ -5,15 +5,15 @@
|
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
|
|
8
|
-
var
|
|
8
|
+
var _chunkNW2CKOFLcjs = require('./chunk-NW2CKOFL.cjs');
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
|
|
12
|
-
var
|
|
12
|
+
var _chunkJM7PZM6Ecjs = require('./chunk-JM7PZM6E.cjs');
|
|
13
13
|
|
|
14
14
|
|
|
15
15
|
|
|
16
|
-
var
|
|
16
|
+
var _chunkC3BOYTY5cjs = require('./chunk-C3BOYTY5.cjs');
|
|
17
17
|
|
|
18
18
|
// src/ocr/models.ts
|
|
19
19
|
var _path = require('path');
|
|
@@ -57,7 +57,7 @@ var OCR_REC_DICT = {
|
|
|
57
57
|
sizeMb: 1
|
|
58
58
|
};
|
|
59
59
|
function getOcrModelsDir() {
|
|
60
|
-
return
|
|
60
|
+
return _chunkJM7PZM6Ecjs.getModelsDir.call(void 0, "ppocr");
|
|
61
61
|
}
|
|
62
62
|
var DEFAULT_OCR_MODELS = Object.freeze({
|
|
63
63
|
det: { spec: OCR_DET_MODEL },
|
|
@@ -99,7 +99,7 @@ async function ensureOcrModelsFor(sel, onProgress) {
|
|
|
99
99
|
if (!stamp || verifiedInProcess.get(path) !== stamp) todo.push(s.spec);
|
|
100
100
|
}
|
|
101
101
|
if (!todo.length) return;
|
|
102
|
-
await
|
|
102
|
+
await _chunkJM7PZM6Ecjs.ensureModelsIn.call(void 0, dir, todo, onProgress);
|
|
103
103
|
for (const spec of todo) {
|
|
104
104
|
const path = _path.join.call(void 0, dir, spec.filename), stamp = await fileStamp(path);
|
|
105
105
|
if (stamp) verifiedInProcess.set(path, stamp);
|
|
@@ -616,6 +616,7 @@ function gapGlyphs(gray, w, h, ink) {
|
|
|
616
616
|
if (ch >= bh * 0.9 && cw <= bh * 0.15) continue;
|
|
617
617
|
const others = comps.filter((o) => o !== c && inBand(o) && !(o.x0 >= c.x0 && o.x1 <= c.x1 && o.y0 >= c.y0 && o.y1 <= c.y1));
|
|
618
618
|
const apart = !others.some((o) => o.x0 < c.x1 + 1 && o.x1 > c.x0 - 1);
|
|
619
|
+
const abut = !apart && ch >= bh * 0.3 && ch <= bh * 0.65 && !others.some((o) => o.x0 < c.x1 && o.x1 > c.x0);
|
|
619
620
|
const nearlyApart = !others.some((o) => Math.min(o.x1, c.x1) - Math.max(o.x0, c.x0) > 2);
|
|
620
621
|
const spans = [], runs = [];
|
|
621
622
|
let n = 0;
|
|
@@ -640,18 +641,11 @@ function gapGlyphs(gray, w, h, ink) {
|
|
|
640
641
|
const speck = Math.max(3, bh * 0.08);
|
|
641
642
|
const dot = ch <= bh * 0.25 && cw <= bh * 0.25 && ch >= speck && cw >= speck && cw >= ch * 0.6 && cw <= ch * 1.6;
|
|
642
643
|
const small = ch <= bh * 0.25 && cw <= bh * 0.25 && ch >= 2 && cw >= 2 && cw >= ch * 0.6 && cw <= ch * 1.6 && fill >= 0.6 && cy >= 0.3 && cy <= 0.7;
|
|
643
|
-
if (!apart && !(nearlyApart && ch >= bh * 0.6)) {
|
|
644
|
+
if (!apart && !abut && !(nearlyApart && ch >= bh * 0.6)) {
|
|
644
645
|
if (small) out.push({ x0: c.x0, x1: c.x1, mark: "\xB7" });
|
|
645
646
|
continue;
|
|
646
647
|
}
|
|
647
|
-
|
|
648
|
-
} else if (dot && fill >= 0.6 && cy >= 0.3 && cy <= 0.7) mark = "\xB7";
|
|
649
|
-
else if (small) mark = "\xB7";
|
|
650
|
-
else if (dot && fill >= 0.6 && cy >= 0.75 && cw >= ch * 0.8) mark = ".";
|
|
651
|
-
else if (ch <= bh * 0.4 && ch >= speck && cw >= ch * 0.75 && cw <= ch * 1.3 && fill < 0.6 && runs[ch >> 1] === 2 && cy >= 0.6) mark = "\u3002";
|
|
652
|
-
else if (ch <= bh * 0.15 && cw >= ch * 2 && cw <= bh * 0.8 && fill >= 0.7 && cy >= 0.35 && cy <= 0.75) mark = "-";
|
|
653
|
-
else if (ch >= bh * 0.5 && cw >= ch * 0.9 && cw <= ch * 1.4 && fill >= 0.4 && runs.every((r) => r <= 1) && top <= 0.4 && bottom >= 0.8) mark = "\u25B2";
|
|
654
|
-
else if (ch >= bh * 0.3 && ch <= bh * 0.65 && fill < 0.5) {
|
|
648
|
+
const bracket = () => {
|
|
655
649
|
const stem = (from, to) => {
|
|
656
650
|
let sx = 0, k = 0;
|
|
657
651
|
for (let y = from; y < to; y++) for (let x = c.x0; x < c.x1; x++) if (label[y * w + x] === c.id) {
|
|
@@ -660,9 +654,21 @@ function gapGlyphs(gray, w, h, ink) {
|
|
|
660
654
|
}
|
|
661
655
|
return k ? sx / k / cw : 0.5;
|
|
662
656
|
};
|
|
663
|
-
if (c.y0 <= bandT + bh * 0.15 && top >= 0.7 && bottom <= 0.5 && stem(c.y0 + band, c.y1) <= 0.35)
|
|
664
|
-
|
|
665
|
-
|
|
657
|
+
if (c.y0 <= bandT + bh * 0.15 && top >= 0.7 && bottom <= 0.5 && stem(c.y0 + band, c.y1) <= 0.35) return "\u300C";
|
|
658
|
+
if (c.y1 >= bandB - bh * 0.15 && bottom >= 0.7 && top <= 0.5 && stem(c.y0, c.y1 - band) >= 0.65) return "\u300D";
|
|
659
|
+
return null;
|
|
660
|
+
};
|
|
661
|
+
if (!apart && !abut) {
|
|
662
|
+
} else if (abut) {
|
|
663
|
+
if (fill < 0.5) mark = bracket();
|
|
664
|
+
} else if (dot && fill >= 0.6 && cy >= 0.3 && cy <= 0.7) mark = "\xB7";
|
|
665
|
+
else if (small) mark = "\xB7";
|
|
666
|
+
else if (dot && fill >= 0.6 && cy >= 0.75 && cw >= ch * 0.8) mark = ".";
|
|
667
|
+
else if (ch <= bh * 0.4 && ch >= speck && cw >= ch * 0.75 && cw <= ch * 1.3 && fill < 0.6 && runs[ch >> 1] === 2 && cy >= 0.6) mark = "\u3002";
|
|
668
|
+
else if (ch <= bh * 0.15 && cw >= ch * 2 && cw <= bh * 0.8 && fill >= 0.7 && cy >= 0.35 && cy <= 0.75) mark = "-";
|
|
669
|
+
else if (ch >= bh * 0.5 && cw >= ch * 0.9 && cw <= ch * 1.4 && fill >= 0.4 && runs.every((r) => r <= 1) && top <= 0.4 && bottom >= 0.8) mark = "\u25B2";
|
|
670
|
+
else if (ch >= bh * 0.3 && ch <= bh * 0.65 && fill < 0.5) mark = bracket();
|
|
671
|
+
else if (ch >= charH * 0.6 && cw >= ch * 0.8 && cw <= ch * 1.25 && fill < 0.5 && top >= 0.8 && bottom >= 0.8 && runs[ch >> 1] === 2) mark = ch <= charH * 0.92 ? "\u25A1" : "\u25A1\0";
|
|
666
672
|
if (!mark && ch >= bh * 0.6 && cw >= ch * 0.25 && cw <= ch * 0.7 && fill <= 0.4 && runs.every((r) => r <= 1)) {
|
|
667
673
|
const mx = (y) => {
|
|
668
674
|
let sx = 0, k = 0;
|
|
@@ -2007,7 +2013,17 @@ function dropHeadBandClipGrids(clipGrids, lineGrids) {
|
|
|
2007
2013
|
if (clipGrids.length === 0 || lineGrids.length === 0) return clipGrids;
|
|
2008
2014
|
const near2 = (a, b) => Math.abs(a - b) <= SHADE_CLIP_TOL;
|
|
2009
2015
|
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);
|
|
2010
|
-
|
|
2016
|
+
const kept = clipGrids.filter((c) => c.clipParent || !_optionalChain([c, 'access', _34 => _34.cells, 'optionalAccess', _35 => _35.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))));
|
|
2017
|
+
return kept.filter((c) => !lineGrids.some((l) => headBandTiles(kept, l, near2, overlaps).includes(c)));
|
|
2018
|
+
}
|
|
2019
|
+
function headBandTiles(clips, l, near2, overlaps) {
|
|
2020
|
+
const onRow = (y) => l.rowYs.some((r) => near2(r, y));
|
|
2021
|
+
const band = clips.filter((c) => !c.clipParent && _optionalChain([c, 'access', _36 => _36.cells, 'optionalAccess', _37 => _37.length]) && near2(c.bbox.y2, l.bbox.y2) && c.bbox.y1 > l.bbox.y1 + SHADE_CLIP_TOL && c.bbox.x1 >= l.bbox.x1 - SHADE_CLIP_TOL && c.bbox.x2 <= l.bbox.x2 + SHADE_CLIP_TOL && c.rowYs.every(onRow)).sort((a, b) => a.bbox.x1 - b.bbox.x1);
|
|
2022
|
+
if (band.length < 2 || !near2(band[0].bbox.x1, l.bbox.x1) || !near2(band[band.length - 1].bbox.x2, l.bbox.x2)) return [];
|
|
2023
|
+
if (band.some((c, k) => k > 0 && c.bbox.x1 > band[k - 1].bbox.x2 + SHADE_CLIP_TOL)) return [];
|
|
2024
|
+
const bottom = Math.min(...band.map((c) => c.bbox.y1));
|
|
2025
|
+
const body = { ...l.bbox, y2: bottom };
|
|
2026
|
+
return clips.some((o) => !band.includes(o) && overlaps(o.bbox, body)) ? [] : band;
|
|
2011
2027
|
}
|
|
2012
2028
|
function enforceMinWidth(colXs, minWidth, narrowRuns = true) {
|
|
2013
2029
|
if (colXs.length <= 2) return colXs;
|
|
@@ -2358,7 +2374,7 @@ function buildClipCellGrids(rects, strokedH, strokedV, pageWidth, pageHeight, te
|
|
|
2358
2374
|
for (let dx = -1; dx <= 1 && !duplicate; dx++) {
|
|
2359
2375
|
const ys2 = buckets.get(bx + dx);
|
|
2360
2376
|
for (let dy = -1; dy <= 1 && !duplicate; dy++) {
|
|
2361
|
-
duplicate = _nullishCoalesce(_optionalChain([ys2, 'optionalAccess',
|
|
2377
|
+
duplicate = _nullishCoalesce(_optionalChain([ys2, 'optionalAccess', _38 => _38.get, 'call', _39 => _39(by + dy), 'optionalAccess', _40 => _40.some, 'call', _41 => _41((c) => sameRect(c, r))]), () => ( false));
|
|
2362
2378
|
}
|
|
2363
2379
|
}
|
|
2364
2380
|
if (duplicate) continue;
|
|
@@ -2506,7 +2522,7 @@ function buildClipCellGrids(rects, strokedH, strokedV, pageWidth, pageHeight, te
|
|
|
2506
2522
|
else groups.set(r, [i]);
|
|
2507
2523
|
}
|
|
2508
2524
|
const containers = cells.filter((_, i) => isContainer[i]);
|
|
2509
|
-
const groupSize = (i) => _nullishCoalesce(_optionalChain([groups, 'access',
|
|
2525
|
+
const groupSize = (i) => _nullishCoalesce(_optionalChain([groups, 'access', _42 => _42.get, 'call', _43 => _43(find(i)), 'optionalAccess', _44 => _44.length]), () => ( 0));
|
|
2510
2526
|
const isGridMember = (i) => groupSize(i) >= CLIP_MIN_GROUP;
|
|
2511
2527
|
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);
|
|
2512
2528
|
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);
|
|
@@ -2887,8 +2903,8 @@ function childRules(r, grid) {
|
|
|
2887
2903
|
}
|
|
2888
2904
|
function recordClipCellEdges(grids, horizontals, verticals, nonRules) {
|
|
2889
2905
|
if (!grids.some((g) => g.cells)) return;
|
|
2890
|
-
const h = rules(_optionalChain([nonRules, 'optionalAccess',
|
|
2891
|
-
const v = rules(_optionalChain([nonRules, 'optionalAccess',
|
|
2906
|
+
const h = rules(_optionalChain([nonRules, 'optionalAccess', _45 => _45.size]) ? horizontals.filter((l) => !nonRules.has(l)) : horizontals, "h");
|
|
2907
|
+
const v = rules(_optionalChain([nonRules, 'optionalAccess', _46 => _46.size]) ? verticals.filter((l) => !nonRules.has(l)) : verticals, "v");
|
|
2892
2908
|
for (const g of grids) {
|
|
2893
2909
|
if (!g.cells) continue;
|
|
2894
2910
|
const ownH = childRules(h, g), ownV = childRules(v, g);
|
|
@@ -2904,9 +2920,9 @@ function recordOpenEndCellEdges(grid, cells, horizontals) {
|
|
|
2904
2920
|
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);
|
|
2905
2921
|
const raw = end && OPEN_END_RULES.get(end);
|
|
2906
2922
|
if (!raw) return;
|
|
2907
|
-
const hs = raw.horizontals.filter((l) => !_optionalChain([raw, 'access',
|
|
2923
|
+
const hs = raw.horizontals.filter((l) => !_optionalChain([raw, 'access', _47 => _47.nonRules, 'optionalAccess', _48 => _48.has, 'call', _49 => _49(l)]));
|
|
2908
2924
|
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;
|
|
2909
|
-
const h = rules(hs, "h"), v = rules(raw.verticals.filter((l) => !_optionalChain([raw, 'access',
|
|
2925
|
+
const h = rules(hs, "h"), v = rules(raw.verticals.filter((l) => !_optionalChain([raw, 'access', _50 => _50.nonRules, 'optionalAccess', _51 => _51.has, 'call', _52 => _52(l)])), "v");
|
|
2910
2926
|
const edges = cells.map((c) => edgesOf(c.bbox, h, v));
|
|
2911
2927
|
const last = grid.rowYs.length - 2;
|
|
2912
2928
|
if (!cells.every((c, i) => {
|
|
@@ -2917,16 +2933,16 @@ function recordOpenEndCellEdges(grid, cells, horizontals) {
|
|
|
2917
2933
|
}
|
|
2918
2934
|
function takeClipCellEdges(from, to) {
|
|
2919
2935
|
const e = CLIP_CELL_EDGES.get(from);
|
|
2920
|
-
if (e)
|
|
2936
|
+
if (e) _chunkNW2CKOFLcjs.CELL_EDGES.set(to, e);
|
|
2921
2937
|
}
|
|
2922
2938
|
function hasOpenCellSeam(a, b) {
|
|
2923
|
-
const u =
|
|
2939
|
+
const u = _chunkNW2CKOFLcjs.CELL_EDGES.get(a), d = _chunkNW2CKOFLcjs.CELL_EDGES.get(b);
|
|
2924
2940
|
return !!u && !!d && u.t && !u.b && !d.t && d.b && u.l && u.r && d.l && d.r;
|
|
2925
2941
|
}
|
|
2926
2942
|
function joinCellEdges(a, b) {
|
|
2927
|
-
const u =
|
|
2943
|
+
const u = _chunkNW2CKOFLcjs.CELL_EDGES.get(a), d = _chunkNW2CKOFLcjs.CELL_EDGES.get(b);
|
|
2928
2944
|
if (!u || !d) return;
|
|
2929
|
-
|
|
2945
|
+
_chunkNW2CKOFLcjs.CELL_EDGES.set(a, { t: u.t, b: d.b, l: u.l || d.l, r: u.r || d.r });
|
|
2930
2946
|
}
|
|
2931
2947
|
|
|
2932
2948
|
// src/pdf/cell-extract.ts
|
|
@@ -3102,7 +3118,7 @@ function tagScripts(text, lines) {
|
|
|
3102
3118
|
const [s, e, kind] = marks[m];
|
|
3103
3119
|
out = out.slice(0, s) + `<${kind}>` + out.slice(s, e) + `</${kind}>` + out.slice(e);
|
|
3104
3120
|
}
|
|
3105
|
-
return
|
|
3121
|
+
return _chunkNW2CKOFLcjs.tidyScriptTags.call(void 0, out);
|
|
3106
3122
|
}
|
|
3107
3123
|
|
|
3108
3124
|
// src/pdf/line-wrap.ts
|
|
@@ -3138,12 +3154,12 @@ var WrapLexicon = (_class = class {constructor() { _class.prototype.__init.call(
|
|
|
3138
3154
|
const t = toks[i], n = t.length;
|
|
3139
3155
|
if (i > 0 && i < toks.length - 1) {
|
|
3140
3156
|
bump(this.words, t);
|
|
3141
|
-
const run = _nullishCoalesce(_optionalChain([t, 'access',
|
|
3157
|
+
const run = _nullishCoalesce(_optionalChain([t, 'access', _53 => _53.match, 'call', _54 => _54(/^[가-힣]+/), 'optionalAccess', _55 => _55[0]]), () => ( ""));
|
|
3142
3158
|
for (let j = 2; j <= Math.min(run.length, 6); j++) this.heads.add(run.slice(0, j));
|
|
3143
3159
|
}
|
|
3144
3160
|
if (i + 1 < toks.length) {
|
|
3145
3161
|
this.pairs.add(t + " " + toks[i + 1]);
|
|
3146
|
-
const tail = _optionalChain([t, 'access',
|
|
3162
|
+
const tail = _optionalChain([t, 'access', _56 => _56.match, 'call', _57 => _57(/[가-힣]+$/), 'optionalAccess', _58 => _58[0]]);
|
|
3147
3163
|
if (tail) this.spacedHeads.add(tail + " " + toks[i + 1].charAt(0));
|
|
3148
3164
|
}
|
|
3149
3165
|
for (let a = 0; a + 1 < n; a++) {
|
|
@@ -3180,14 +3196,14 @@ var WrapLexicon = (_class = class {constructor() { _class.prototype.__init.call(
|
|
|
3180
3196
|
const n = left.length;
|
|
3181
3197
|
if (n < 2 || right.length < 2) return null;
|
|
3182
3198
|
const k1 = pairKey(left.charCodeAt(n - 2), left.charCodeAt(n - 1)), k2 = pairKey(right.charCodeAt(0), right.charCodeAt(1));
|
|
3183
|
-
return decideCounts(_nullishCoalesce(_optionalChain([this, 'access',
|
|
3199
|
+
return decideCounts(_nullishCoalesce(_optionalChain([this, 'access', _59 => _59.joined2, 'access', _60 => _60.get, 'call', _61 => _61(k1), 'optionalAccess', _62 => _62.get, 'call', _63 => _63(k2)]), () => ( 0)), _nullishCoalesce(_optionalChain([this, 'access', _64 => _64.spaced2, 'access', _65 => _65.get, 'call', _66 => _66(k1), 'optionalAccess', _67 => _67.get, 'call', _68 => _68(k2)]), () => ( 0)));
|
|
3184
3200
|
}
|
|
3185
3201
|
/** 꺾인 자리 증거: "" 붙음 · " " 띄움 · null 모름 (두 글자 증거가 갈리거나 없으면 한 글자) */
|
|
3186
3202
|
evidence(left, right) {
|
|
3187
3203
|
const n = left.length;
|
|
3188
3204
|
if (n >= 2 && right.length >= 2) {
|
|
3189
3205
|
const k1 = pairKey(left.charCodeAt(n - 2), left.charCodeAt(n - 1)), k2 = pairKey(right.charCodeAt(0), right.charCodeAt(1));
|
|
3190
|
-
const v = decideCounts(_nullishCoalesce(_optionalChain([this, 'access',
|
|
3206
|
+
const v = decideCounts(_nullishCoalesce(_optionalChain([this, 'access', _69 => _69.joined2, 'access', _70 => _70.get, 'call', _71 => _71(k1), 'optionalAccess', _72 => _72.get, 'call', _73 => _73(k2)]), () => ( 0)), _nullishCoalesce(_optionalChain([this, 'access', _74 => _74.spaced2, 'access', _75 => _75.get, 'call', _76 => _76(k1), 'optionalAccess', _77 => _77.get, 'call', _78 => _78(k2)]), () => ( 0)));
|
|
3191
3207
|
if (v !== null) return v;
|
|
3192
3208
|
}
|
|
3193
3209
|
if (n && right.length) {
|
|
@@ -3262,11 +3278,11 @@ function wrapJoiner(prevText, nextText, lex, heads = true) {
|
|
|
3262
3278
|
if (particleContinues(left, right)) return "";
|
|
3263
3279
|
if (endsAsWord(left)) return " ";
|
|
3264
3280
|
if (/[A-Za-z]-$/.test(left) && /^[A-Za-z]/.test(right) && !/[가-힣]/.test(prev + next)) {
|
|
3265
|
-
return _optionalChain([lex, 'optionalAccess',
|
|
3281
|
+
return _optionalChain([lex, 'optionalAccess', _79 => _79.joinedWord, 'call', _80 => _80(left, right.replace(/[.,;:!?)]*$/, ""))]) ? "" : " ";
|
|
3266
3282
|
}
|
|
3267
3283
|
if (/[·ㆍ‧-]/.test(a) && !/[·ㆍ‧…]{2}$/.test(prev) && /[가-힣A-Za-z0-9]/.test(b)) return "";
|
|
3268
3284
|
if (/[A-Za-z]/.test(a) && /[A-Za-z]/.test(b) || /\d/.test(a) && /\d/.test(b)) return " ";
|
|
3269
|
-
const ev = _optionalChain([lex, 'optionalAccess',
|
|
3285
|
+
const ev = _optionalChain([lex, 'optionalAccess', _81 => _81.evidence, 'call', _82 => _82(left, right)]);
|
|
3270
3286
|
if (ev != null) return ev;
|
|
3271
3287
|
if (lex && /[가-힣A-Za-z0-9]$/.test(left) && /^[가-힣A-Za-z0-9]/.test(right) && lex.joinedWord(left, right.replace(/[.,)」』’”;:]+$/, ""))) return "";
|
|
3272
3288
|
if (/\d$/.test(left) && COUNTER.test(right)) return "";
|
|
@@ -3274,7 +3290,7 @@ function wrapJoiner(prevText, nextText, lex, heads = true) {
|
|
|
3274
3290
|
const r1 = right.replace(/[.,)」』’”]+$/, "");
|
|
3275
3291
|
if (lex && /[가-힣]$/.test(left) && /^[가-힣]$/.test(r1) && !STANDALONE_SYLLABLE.test(r1) && !lex.isWord(r1) && !lex.isWord(right)) return "";
|
|
3276
3292
|
if (lex && heads) {
|
|
3277
|
-
const tail = _optionalChain([left, 'access',
|
|
3293
|
+
const tail = _optionalChain([left, 'access', _83 => _83.match, 'call', _84 => _84(/[가-힣]+$/), 'optionalAccess', _85 => _85[0]]), run = _optionalChain([right, 'access', _86 => _86.match, 'call', _87 => _87(/^[가-힣]+/), 'optionalAccess', _88 => _88[0]]);
|
|
3278
3294
|
if (tail && run && !STANDALONE_SYLLABLE.test(tail) && lex.startsWord(tail + run.slice(0, 2)) && !lex.spacedHead(tail, run[0])) return "";
|
|
3279
3295
|
if (/[가-힣]{2}$/.test(left) && /^\([^()\s]*\)/.test(right) && !endsAsWord(left) && !/(?:함|음|됨|임|다)$/.test(left) && !BARE_UNIT_PAREN.test(right) && !/^\(\d/.test(right)) return "";
|
|
3280
3296
|
}
|
|
@@ -3309,14 +3325,14 @@ function joinPageBreakWraps(blocks, lex) {
|
|
|
3309
3325
|
if (a.type !== "paragraph" && a.type !== "list" || b.type !== "paragraph") continue;
|
|
3310
3326
|
const last = a.bbox && PARA_LAST_LINE.get(a.bbox), fs = last ? last.fontSize : 0;
|
|
3311
3327
|
if (!last || fs <= 0 || (_nullishCoalesce(pageRight.get(a.pageNumber), () => ( Infinity))) - last.right >= BODY_FULL_TOL * fs) continue;
|
|
3312
|
-
if (last.width < BODY_MIN_WIDTH_EM * fs || Math.abs((_nullishCoalesce(_optionalChain([b, 'access',
|
|
3328
|
+
if (last.width < BODY_MIN_WIDTH_EM * fs || Math.abs((_nullishCoalesce(_optionalChain([b, 'access', _89 => _89.style, 'optionalAccess', _90 => _90.fontSize]), () => ( 0))) - fs) > 0.15 * fs) continue;
|
|
3313
3329
|
const bt = b.text.replace(MARKUP, "");
|
|
3314
3330
|
if (startsNewItem(a.text, b.text) || PAGE_REF_TAIL.test(a.text) || PAGE_ITEM_HEAD.test(bt)) continue;
|
|
3315
3331
|
if (PAGE_HEAD_MARK.test(bt) && !(/^[\u25a0-\u25ff]/.test(bt) && a.text.includes(bt[0]))) continue;
|
|
3316
3332
|
const firstLeft = b.bbox && PARA_FIRST_LEFT.get(b.bbox);
|
|
3317
3333
|
const indented = firstLeft === void 0 || firstLeft - (_nullishCoalesce(pageLeft.get(b.pageNumber), () => ( firstLeft))) >= 0.3 * fs;
|
|
3318
3334
|
if (indented && SENTENCE_END.test(a.text.replace(MARKUP, "").trimEnd())) continue;
|
|
3319
|
-
if (Math.round(_nullishCoalesce(_optionalChain([b, 'access',
|
|
3335
|
+
if (Math.round(_nullishCoalesce(_optionalChain([b, 'access', _91 => _91.style, 'optionalAccess', _92 => _92.fontSize]), () => ( 0))) !== Math.round(fs) && titleLike(b.text)) continue;
|
|
3320
3336
|
if (/\t/.test(a.text.slice(a.text.lastIndexOf("\n") + 1).replace(/^\S{1,8}\t/, "")) && titleLike(bt.trim().split("\n")[0])) continue;
|
|
3321
3337
|
const joined = wrapJoiner(a.text, b.text, lex);
|
|
3322
3338
|
const head = a.text, joiner = joined === "" && last.spaceAfter ? " " : joined;
|
|
@@ -3365,7 +3381,7 @@ function bodyLineJoins(lines, lex) {
|
|
|
3365
3381
|
for (const l of lines) if (!HANGING.test(l.text) && l.right > inner) inner = l.right;
|
|
3366
3382
|
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;
|
|
3367
3383
|
const nextWordNoRoom = (a, b) => {
|
|
3368
|
-
const w = _optionalChain([b, 'access',
|
|
3384
|
+
const w = _optionalChain([b, 'access', _93 => _93.text, 'access', _94 => _94.trim, 'call', _95 => _95(), 'access', _96 => _96.match, 'call', _97 => _97(/^\S+/), 'optionalAccess', _98 => _98[0]]);
|
|
3369
3385
|
const n = [...b.text.trim()].length;
|
|
3370
3386
|
if (!w || n === 0) return false;
|
|
3371
3387
|
const em = (b.right - b.left) / n;
|
|
@@ -3561,7 +3577,7 @@ function cellTextToString(items, wrap) {
|
|
|
3561
3577
|
const merged = mergeSuperscriptRows(lines).map((line) => sortLineByX(line));
|
|
3562
3578
|
const textLines = merged.map((s) => {
|
|
3563
3579
|
if (s.length === 1) return s[0].text;
|
|
3564
|
-
if (s.length === 2 && /^[가-힣]$/.test(s[0].text) && /^[가-힣]$/.test(s[1].text) && !!_optionalChain([wrap, 'optionalAccess',
|
|
3580
|
+
if (s.length === 2 && /^[가-힣]$/.test(s[0].text) && /^[가-힣]$/.test(s[1].text) && !!_optionalChain([wrap, 'optionalAccess', _99 => _99.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;
|
|
3565
3581
|
const evenSpaced = detectEvenSpacedItems(s, true);
|
|
3566
3582
|
let result = s[0].text;
|
|
3567
3583
|
for (let j = 1; j < s.length; j++) {
|
|
@@ -3707,12 +3723,12 @@ function markEvenRun(items, visible, result, start, end) {
|
|
|
3707
3723
|
}
|
|
3708
3724
|
function mergeCellTextLines(textLines, wrap) {
|
|
3709
3725
|
if (textLines.length <= 1) return textLines[0] || "";
|
|
3710
|
-
const numberWrapped = (k) => !!_optionalChain([wrap, 'optionalAccess',
|
|
3726
|
+
const numberWrapped = (k) => !!_optionalChain([wrap, 'optionalAccess', _100 => _100.wraps, 'access', _101 => _101[k]]) && (_nullishCoalesce(_optionalChain([wrap, 'access', _102 => _102.wide, 'optionalAccess', _103 => _103[k]]), () => ( true)));
|
|
3711
3727
|
const merged = [textLines[0]];
|
|
3712
3728
|
for (let i = 1; i < textLines.length; i++) {
|
|
3713
3729
|
const prev = merged[merged.length - 1];
|
|
3714
3730
|
const curr = textLines[i];
|
|
3715
|
-
if (wrap ? wrap.wraps[i - 1] && !_optionalChain([wrap, 'access',
|
|
3731
|
+
if (wrap ? wrap.wraps[i - 1] && !_optionalChain([wrap, 'access', _104 => _104.spaced, 'optionalAccess', _105 => _105[i - 1]]) && !startsNewItem(prev, curr) && wrapJoiner(prev, curr, wrap.lex, false) === "" : /[가-힣]$/.test(prev) && /^[가-힣]+$/.test(curr) && curr.length <= 8 && !curr.includes(" ")) {
|
|
3716
3732
|
merged[merged.length - 1] = prev + curr;
|
|
3717
3733
|
} else if (curr.trim().length <= 3 && /^[)\]%}]/.test(curr.trim())) {
|
|
3718
3734
|
merged[merged.length - 1] = prev + curr.trim();
|
|
@@ -3807,7 +3823,7 @@ function normalizeUndersegmentedTable(originalCells, colXs, items, rowYs) {
|
|
|
3807
3823
|
if (numRows > MAX_UNDERSEGMENTED_ROWS || numCols < MIN_UNDERSEGMENTED_COLUMNS) return null;
|
|
3808
3824
|
if (items.length === 0) return null;
|
|
3809
3825
|
if (numRows >= 3) {
|
|
3810
|
-
if (_optionalChain([rowYs, 'optionalAccess',
|
|
3826
|
+
if (_optionalChain([rowYs, 'optionalAccess', _106 => _106.length]) !== numRows + 1) return null;
|
|
3811
3827
|
const rebuilt2 = [];
|
|
3812
3828
|
let expanded = 0;
|
|
3813
3829
|
for (let r = 0; r < numRows; r++) {
|
|
@@ -3901,7 +3917,7 @@ function sortLineByX(items) {
|
|
|
3901
3917
|
e++;
|
|
3902
3918
|
}
|
|
3903
3919
|
const run = items.slice(s, e), seqs = run.map((i) => i.seq);
|
|
3904
|
-
const ok = !wide ? !run.some((i) => _optionalChain([i, 'access',
|
|
3920
|
+
const ok = !wide ? !run.some((i) => _optionalChain([i, 'access', _107 => _107.text, 'optionalAccess', _108 => _108.startsWith, 'call', _109 => _109("$")])) : Math.max(...seqs) - Math.min(...seqs) <= 2 * (e - s - 1) && run.every((i) => Math.abs((_nullishCoalesce(i.fontSize, () => ( 0))) - (_nullishCoalesce(run[0].fontSize, () => ( 0)))) <= 0.5);
|
|
3905
3921
|
if (e - s > 1 && seqs.every((q) => q !== void 0) && ok) {
|
|
3906
3922
|
run.sort((a, b) => a.seq - b.seq);
|
|
3907
3923
|
for (let k = 0; k < run.length; k++) items[s + k] = run[k];
|
|
@@ -3970,7 +3986,7 @@ function dominantStyle(items) {
|
|
|
3970
3986
|
let maxCount = 0, dominantSize = 0;
|
|
3971
3987
|
for (const i of items) {
|
|
3972
3988
|
if (i.fontSize <= 0) continue;
|
|
3973
|
-
const count = (freq.get(i.fontSize) || 0) + Math.max(1, _nullishCoalesce(_optionalChain([i, 'access',
|
|
3989
|
+
const count = (freq.get(i.fontSize) || 0) + Math.max(1, _nullishCoalesce(_optionalChain([i, 'access', _110 => _110.text, 'access', _111 => _111.match, 'call', _112 => _112(/[\p{L}\p{N}]/gu), 'optionalAccess', _113 => _113.length]), () => ( 0)));
|
|
3974
3990
|
freq.set(i.fontSize, count);
|
|
3975
3991
|
if (count > maxCount) {
|
|
3976
3992
|
maxCount = count;
|
|
@@ -3978,7 +3994,7 @@ function dominantStyle(items) {
|
|
|
3978
3994
|
}
|
|
3979
3995
|
}
|
|
3980
3996
|
if (dominantSize === 0) return void 0;
|
|
3981
|
-
const fontName = _optionalChain([items, 'access',
|
|
3997
|
+
const fontName = _optionalChain([items, 'access', _114 => _114.find, 'call', _115 => _115((i) => i.fontSize === dominantSize), 'optionalAccess', _116 => _116.fontName]) || void 0;
|
|
3982
3998
|
return fontName ? { fontSize: dominantSize, fontName } : { fontSize: dominantSize };
|
|
3983
3999
|
}
|
|
3984
4000
|
function normalizeItems(rawItems) {
|
|
@@ -4123,7 +4139,7 @@ function splitAroundOverlays(c, overlays) {
|
|
|
4123
4139
|
const ov = overlays.filter((o) => {
|
|
4124
4140
|
for (let at = c.text.indexOf(o.text); at >= 0; at = c.text.indexOf(o.text, at + 1)) {
|
|
4125
4141
|
const prefix = c.text.slice(0, at);
|
|
4126
|
-
const est = c.x + glyphUnits(prefix.replace(/\s+/g, "")) * a0 + (_nullishCoalesce(_optionalChain([prefix, 'access',
|
|
4142
|
+
const est = c.x + glyphUnits(prefix.replace(/\s+/g, "")) * a0 + (_nullishCoalesce(_optionalChain([prefix, 'access', _117 => _117.match, 'call', _118 => _118(/\s+/g), 'optionalAccess', _119 => _119.length]), () => ( 0))) * ws;
|
|
4127
4143
|
if (Math.abs(est - o.x) <= OVERLAY_DUP_EM * fs) return false;
|
|
4128
4144
|
}
|
|
4129
4145
|
return true;
|
|
@@ -4248,7 +4264,7 @@ function mergeSuperscriptLines(lines) {
|
|
|
4248
4264
|
return result;
|
|
4249
4265
|
}
|
|
4250
4266
|
function mergeLineSimple(items) {
|
|
4251
|
-
if (items.length <= 1) return _optionalChain([items, 'access',
|
|
4267
|
+
if (items.length <= 1) return _optionalChain([items, 'access', _120 => _120[0], 'optionalAccess', _121 => _121.text]) || "";
|
|
4252
4268
|
const sorted = sortLineByX([...items]);
|
|
4253
4269
|
const isEvenSpaced = detectEvenSpacedItems(sorted);
|
|
4254
4270
|
let result = sorted[0].text;
|
|
@@ -4336,7 +4352,7 @@ function isProseTable(table) {
|
|
|
4336
4352
|
if (!(long > 0 && long >= total * 0.5 && longRows >= rows * 0.4)) return false;
|
|
4337
4353
|
for (let c = 0; c < table.cols; c++) {
|
|
4338
4354
|
const filled = table.cells.map((row) => row[c]).filter((cell) => cell && cell.colSpan < table.cols && cell.text.trim()).map((cell) => cell.text.trim());
|
|
4339
|
-
if (filled.length >= 3 && filled.length >= rows * 0.6 && filled.every((text) => text.length <= 30 && (_nullishCoalesce(_optionalChain([text, 'access',
|
|
4355
|
+
if (filled.length >= 3 && filled.length >= rows * 0.6 && filled.every((text) => text.length <= 30 && (_nullishCoalesce(_optionalChain([text, 'access', _122 => _122.match, 'call', _123 => _123(/\p{L}/gu), 'optionalAccess', _124 => _124.length]), () => ( 0))) >= 2)) return false;
|
|
4340
4356
|
}
|
|
4341
4357
|
return true;
|
|
4342
4358
|
}
|
|
@@ -4365,7 +4381,7 @@ var TICK = /^-?[\d,]+(?:\.\d+)?%?$/;
|
|
|
4365
4381
|
var QUANTITY = /^[-−–]?[\d,]*\.?\d+%?$/;
|
|
4366
4382
|
var quantity = (token) => Number(token.replace(/^[−–]/, "-").replace(/[,%]/g, ""));
|
|
4367
4383
|
function isValueAxisColumn(table, c) {
|
|
4368
|
-
const lines = table.cells.flatMap((row) => (_nullishCoalesce(_optionalChain([row, 'access',
|
|
4384
|
+
const lines = table.cells.flatMap((row) => (_nullishCoalesce(_optionalChain([row, 'access', _125 => _125[c], 'optionalAccess', _126 => _126.text]), () => ( ""))).split("\n").map((line) => line.trim().split(/\s+/)));
|
|
4369
4385
|
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));
|
|
4370
4386
|
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)]) {
|
|
4371
4387
|
const run = fallingRun(ticks);
|
|
@@ -4397,7 +4413,7 @@ function isChartTable(table, ocr = false) {
|
|
|
4397
4413
|
const numeric = texts.filter((text) => NUMERIC_CELL.test(text)).length;
|
|
4398
4414
|
if (numeric < texts.length * 0.5) return false;
|
|
4399
4415
|
for (let c = 0; c < table.cols; c++) {
|
|
4400
|
-
if (!ocr ? isValueAxisColumn(table, c) : hasValueAxis(table.cells.flatMap((row) => (_nullishCoalesce(_optionalChain([row, 'access',
|
|
4416
|
+
if (!ocr ? isValueAxisColumn(table, c) : hasValueAxis(table.cells.flatMap((row) => (_nullishCoalesce(_optionalChain([row, 'access', _127 => _127[c], 'optionalAccess', _128 => _128.text]), () => ( ""))).split(/\s+/)).filter((t) => TICK.test(t)).map((t) => Number(t.replace(/[,%]/g, ""))))) return true;
|
|
4401
4417
|
}
|
|
4402
4418
|
const values = texts.filter((text) => text.split(/\s+/).every((token) => QUANTITY.test(token))).length;
|
|
4403
4419
|
const cells = table.rows * table.cols;
|
|
@@ -4450,7 +4466,7 @@ function clusterCellLines(items) {
|
|
|
4450
4466
|
}
|
|
4451
4467
|
var WRAP_INDENT_MAX = 3;
|
|
4452
4468
|
function joinClusterCellLines(lines, box, lex) {
|
|
4453
|
-
let out = _nullishCoalesce(_optionalChain([lines, 'access',
|
|
4469
|
+
let out = _nullishCoalesce(_optionalChain([lines, 'access', _129 => _129[0], 'optionalAccess', _130 => _130.text]), () => ( ""));
|
|
4454
4470
|
for (let i = 1; i < lines.length; i++) {
|
|
4455
4471
|
const a = lines[i - 1], b = lines[i];
|
|
4456
4472
|
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) === "";
|
|
@@ -4722,7 +4738,7 @@ function detectAlignedTwoColumnTables(rows, pageNum) {
|
|
|
4722
4738
|
continue;
|
|
4723
4739
|
}
|
|
4724
4740
|
const top = rows[i - 1];
|
|
4725
|
-
const title = _optionalChain([top, 'optionalAccess',
|
|
4741
|
+
const title = _optionalChain([top, 'optionalAccess', _131 => _131.items, 'access', _132 => _132.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;
|
|
4726
4742
|
const tableRows = title ? [title, ...body] : body;
|
|
4727
4743
|
const cells = tableRows.map((row, idx) => {
|
|
4728
4744
|
if (title && idx === 0) return [{ text: row.items[0].text, colSpan: 2, rowSpan: 1 }, { text: "", colSpan: 1, rowSpan: 1 }];
|
|
@@ -4778,12 +4794,12 @@ function isTwoColumnProse(r) {
|
|
|
4778
4794
|
if (t.rows < 8) return false;
|
|
4779
4795
|
const dense = [];
|
|
4780
4796
|
for (let c = 0; c < t.cols; c++) {
|
|
4781
|
-
const filled = t.cells.filter((row) => _optionalChain([row, 'access',
|
|
4797
|
+
const filled = t.cells.filter((row) => _optionalChain([row, 'access', _133 => _133[c], 'optionalAccess', _134 => _134.text, 'access', _135 => _135.trim, 'call', _136 => _136()])).length;
|
|
4782
4798
|
if (filled / t.rows >= 0.3) dense.push(c);
|
|
4783
4799
|
}
|
|
4784
4800
|
if (dense.length !== 2) return false;
|
|
4785
4801
|
for (const c of dense) {
|
|
4786
|
-
const lens = t.cells.map((row) => _nullishCoalesce(_optionalChain([row, 'access',
|
|
4802
|
+
const lens = t.cells.map((row) => _nullishCoalesce(_optionalChain([row, 'access', _137 => _137[c], 'optionalAccess', _138 => _138.text, 'access', _139 => _139.replace, 'call', _140 => _140(/\s+/g, ""), 'access', _141 => _141.length]), () => ( 0))).filter((n) => n > 0);
|
|
4787
4803
|
const avg = lens.reduce((s, v) => s + v, 0) / (lens.length || 1);
|
|
4788
4804
|
if (avg < 12) return false;
|
|
4789
4805
|
}
|
|
@@ -5210,7 +5226,7 @@ function assignRowItems(items, columns, numCols, headerFace) {
|
|
|
5210
5226
|
const runs = [];
|
|
5211
5227
|
for (const it of sorted) {
|
|
5212
5228
|
const last = runs[runs.length - 1];
|
|
5213
|
-
const prev = _optionalChain([last, 'optionalAccess',
|
|
5229
|
+
const prev = _optionalChain([last, 'optionalAccess', _142 => _142[last.length - 1]]);
|
|
5214
5230
|
if (prev && it.x - (prev.x + prev.w) <= Math.max(0.5, it.fontSize * 0.05) && !it.hasSpaceBefore) last.push(it);
|
|
5215
5231
|
else runs.push([it]);
|
|
5216
5232
|
}
|
|
@@ -5278,7 +5294,7 @@ function assignRowItems(items, columns, numCols, headerFace) {
|
|
|
5278
5294
|
function buildClusterTable(rows, columns, pageNum, lex) {
|
|
5279
5295
|
const numRows = rows.length;
|
|
5280
5296
|
if (numRows < MIN_ROWS || columns.length < MIN_COLS) return null;
|
|
5281
|
-
const headFaces = new Set(_optionalChain([rows, 'access',
|
|
5297
|
+
const headFaces = new Set(_optionalChain([rows, 'access', _143 => _143[0], 'optionalAccess', _144 => _144.items, 'access', _145 => _145.map, 'call', _146 => _146((i) => i.fontName)]));
|
|
5282
5298
|
const headerFace = headFaces.size === 1 && rows.slice(1).every((row) => row.items.every((i) => !headFaces.has(i.fontName))) ? [...headFaces][0] : void 0;
|
|
5283
5299
|
const assigned = rows.map((row, r) => assignRowItems(row.items, columns, columns.length, r === 0 ? headerFace : void 0));
|
|
5284
5300
|
const cuts = supportedOcrColumnCuts(assigned);
|
|
@@ -5349,7 +5365,7 @@ function buildClusterTable(rows, columns, pageNum, lex) {
|
|
|
5349
5365
|
const nonEmptyCols = cells[r].filter((c) => c.text.trim()).length;
|
|
5350
5366
|
if (nonEmptyCols !== 1) continue;
|
|
5351
5367
|
if (cells[r][0].text.trim() !== "") continue;
|
|
5352
|
-
const contentText = _optionalChain([cells, 'access',
|
|
5368
|
+
const contentText = _optionalChain([cells, 'access', _147 => _147[r], 'access', _148 => _148.find, 'call', _149 => _149((c) => c.text.trim()), 'optionalAccess', _150 => _150.text, 'access', _151 => _151.trim, 'call', _152 => _152()]) || "";
|
|
5353
5369
|
if (/^[○●▶\-·]/.test(contentText)) continue;
|
|
5354
5370
|
for (let pr = r - 1; pr >= 0; pr--) {
|
|
5355
5371
|
if (cells[pr].some((c) => c.text.trim())) {
|
|
@@ -5582,7 +5598,7 @@ function stackedTableBands(items) {
|
|
|
5582
5598
|
const caption = (start, end) => lines.slice(start, end).some((line) => /^Table\s+\d+\s*[:.]/i.test(mergeLineSimple(line).trim()));
|
|
5583
5599
|
while (runs.length > 0 && !caption(runs[runs.length - 1].end, lines.length)) runs.pop();
|
|
5584
5600
|
if (runs.length < 2) return null;
|
|
5585
|
-
if (runs.some((run, i) => !caption(run.end, _nullishCoalesce(_optionalChain([runs, 'access',
|
|
5601
|
+
if (runs.some((run, i) => !caption(run.end, _nullishCoalesce(_optionalChain([runs, 'access', _153 => _153[i + 1], 'optionalAccess', _154 => _154.start]), () => ( lines.length))))) return null;
|
|
5586
5602
|
const tables = runs.map((run) => lines.slice(run.start, run.end).flat());
|
|
5587
5603
|
const between = runs.slice(0, -1).map((run, i) => lines.slice(run.end, runs[i + 1].start).flat());
|
|
5588
5604
|
const tail = lines.slice(runs[runs.length - 1].end);
|
|
@@ -5850,7 +5866,7 @@ function splitTrailingColumnRegion(items) {
|
|
|
5850
5866
|
}
|
|
5851
5867
|
function panelBlocks(items, panel, pageNum) {
|
|
5852
5868
|
const lines = groupByY([...items].sort((a, b) => b.y - a.y || a.x - b.x));
|
|
5853
|
-
const faceOf = (line) => _nullishCoalesce(_optionalChain([dominantStyle, 'call',
|
|
5869
|
+
const faceOf = (line) => _nullishCoalesce(_optionalChain([dominantStyle, 'call', _155 => _155(line), 'optionalAccess', _156 => _156.fontName]), () => ( ""));
|
|
5854
5870
|
const runs = [];
|
|
5855
5871
|
for (const line of lines) {
|
|
5856
5872
|
const last = runs[runs.length - 1];
|
|
@@ -6032,7 +6048,7 @@ function validWrapBands(items, bands) {
|
|
|
6032
6048
|
}
|
|
6033
6049
|
function inheritedWrapBands(items) {
|
|
6034
6050
|
const source = XY_WRAP_ITEMS.get(items[0]);
|
|
6035
|
-
const present = _optionalChain([source, 'optionalAccess',
|
|
6051
|
+
const present = _optionalChain([source, 'optionalAccess', _157 => _157.length]) === items.length ? new Set(items) : null;
|
|
6036
6052
|
const sameLeaf = present && source.every((item) => present.has(item));
|
|
6037
6053
|
return sameLeaf ? validWrapBands(items, _nullishCoalesce(XY_WRAP_BANDS.get(items[0]), () => ( []))) : [];
|
|
6038
6054
|
}
|
|
@@ -6071,7 +6087,7 @@ function wrappedLineBands(items, inherited) {
|
|
|
6071
6087
|
left: box.x,
|
|
6072
6088
|
right: box.x + box.width,
|
|
6073
6089
|
y: row.reduce((n, i) => n + i.y, 0) / row.length,
|
|
6074
|
-
fontSize: _nullishCoalesce(_optionalChain([dominantStyle, 'call',
|
|
6090
|
+
fontSize: _nullishCoalesce(_optionalChain([dominantStyle, 'call', _158 => _158(row), 'optionalAccess', _159 => _159.fontSize]), () => ( 0)),
|
|
6075
6091
|
sources: row.map((item) => ({ item, state: { ...item } }))
|
|
6076
6092
|
};
|
|
6077
6093
|
});
|
|
@@ -6207,10 +6223,10 @@ function pushLineParagraphs(out, yLines, pageNum, lex) {
|
|
|
6207
6223
|
const lines = attachDropCaps(yLines).map((items) => ({ items, text: mergeLineSimple(items) })).filter((l) => l.text.trim());
|
|
6208
6224
|
const geo = lines.map((l) => {
|
|
6209
6225
|
const b = computeBBox(l.items, pageNum);
|
|
6210
|
-
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',
|
|
6226
|
+
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', _160 => _160(l.items), 'optionalAccess', _161 => _161.fontSize]), () => ( 0)) };
|
|
6211
6227
|
});
|
|
6212
6228
|
const joins = bodyLineJoins(geo, lex);
|
|
6213
|
-
const first = _optionalChain([lines, 'access',
|
|
6229
|
+
const first = _optionalChain([lines, 'access', _162 => _162[0], 'optionalAccess', _163 => _163.items, 'access', _164 => _164[0]]);
|
|
6214
6230
|
const bands = first ? _nullishCoalesce(XY_WRAP_BANDS.get(first), () => ( [])) : [];
|
|
6215
6231
|
const hasBand = (top, bottom) => {
|
|
6216
6232
|
let lo = 0, hi = bands.length;
|
|
@@ -6287,15 +6303,15 @@ function computeMedianFontSizeFromFreq(freq) {
|
|
|
6287
6303
|
function detectHeadings(blocks, medianFontSize) {
|
|
6288
6304
|
for (let bi = 0; bi < blocks.length; bi++) {
|
|
6289
6305
|
const block = blocks[bi];
|
|
6290
|
-
if (block.type !== "paragraph" || !block.text || !_optionalChain([block, 'access',
|
|
6306
|
+
if (block.type !== "paragraph" || !block.text || !_optionalChain([block, 'access', _165 => _165.style, 'optionalAccess', _166 => _166.fontSize])) continue;
|
|
6291
6307
|
const text = block.text.trim();
|
|
6292
6308
|
if (text.length === 0 || text.length > 200) continue;
|
|
6293
6309
|
if (/^\d+$/.test(text) && !isChapterNumber(block, blocks[bi + 1], medianFontSize)) continue;
|
|
6294
6310
|
const ratio = block.style.fontSize / medianFontSize;
|
|
6295
6311
|
let level = 0;
|
|
6296
|
-
if (ratio >=
|
|
6297
|
-
else if (ratio >=
|
|
6298
|
-
else if (ratio >=
|
|
6312
|
+
if (ratio >= _chunkNW2CKOFLcjs.HEADING_RATIO_H1) level = 1;
|
|
6313
|
+
else if (ratio >= _chunkNW2CKOFLcjs.HEADING_RATIO_H2) level = 2;
|
|
6314
|
+
else if (ratio >= _chunkNW2CKOFLcjs.HEADING_RATIO_H3) level = 3;
|
|
6299
6315
|
if (level > 0) {
|
|
6300
6316
|
block.type = "heading";
|
|
6301
6317
|
block.level = level;
|
|
@@ -6304,21 +6320,21 @@ function detectHeadings(blocks, medianFontSize) {
|
|
|
6304
6320
|
}
|
|
6305
6321
|
}
|
|
6306
6322
|
function isChapterNumber(block, next, medianFontSize) {
|
|
6307
|
-
const size = _nullishCoalesce(_optionalChain([block, 'access',
|
|
6308
|
-
const nextSize = _nullishCoalesce(_optionalChain([next, 'optionalAccess',
|
|
6309
|
-
const text = _nullishCoalesce(_optionalChain([next, 'optionalAccess',
|
|
6310
|
-
const a = block.bbox, b = _optionalChain([next, 'optionalAccess',
|
|
6311
|
-
return /^\d{1,2}$/.test(_nullishCoalesce(_optionalChain([block, 'access',
|
|
6323
|
+
const size = _nullishCoalesce(_optionalChain([block, 'access', _167 => _167.style, 'optionalAccess', _168 => _168.fontSize]), () => ( 0));
|
|
6324
|
+
const nextSize = _nullishCoalesce(_optionalChain([next, 'optionalAccess', _169 => _169.style, 'optionalAccess', _170 => _170.fontSize]), () => ( 0));
|
|
6325
|
+
const text = _nullishCoalesce(_optionalChain([next, 'optionalAccess', _171 => _171.text, 'optionalAccess', _172 => _172.trim, 'call', _173 => _173()]), () => ( ""));
|
|
6326
|
+
const a = block.bbox, b = _optionalChain([next, 'optionalAccess', _174 => _174.bbox]);
|
|
6327
|
+
return /^\d{1,2}$/.test(_nullishCoalesce(_optionalChain([block, 'access', _175 => _175.text, 'optionalAccess', _176 => _176.trim, 'call', _177 => _177()]), () => ( ""))) && size >= medianFontSize * 2.5 && !!next && (next.type === "paragraph" || next.type === "heading") && next.pageNumber === block.pageNumber && nextSize >= medianFontSize * _chunkNW2CKOFLcjs.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;
|
|
6312
6328
|
}
|
|
6313
6329
|
function mergeStackedHeadingLines(blocks, medianFontSize) {
|
|
6314
6330
|
for (let i = 0; i < blocks.length - 1; ) {
|
|
6315
6331
|
const a = blocks[i], b = blocks[i + 1];
|
|
6316
6332
|
const ab = a.bbox, bb = b.bbox;
|
|
6317
|
-
const af = _nullishCoalesce(_optionalChain([a, 'access',
|
|
6333
|
+
const af = _nullishCoalesce(_optionalChain([a, 'access', _178 => _178.style, 'optionalAccess', _179 => _179.fontSize]), () => ( 0)), bf = _nullishCoalesce(_optionalChain([b, 'access', _180 => _180.style, 'optionalAccess', _181 => _181.fontSize]), () => ( 0));
|
|
6318
6334
|
const gap = ab && bb ? ab.y - (bb.y + bb.height) : Infinity;
|
|
6319
|
-
const centered = ab && bb && _optionalChain([a, 'access',
|
|
6335
|
+
const centered = ab && bb && _optionalChain([a, 'access', _182 => _182.style, 'optionalAccess', _183 => _183.fontName]) === _optionalChain([b, 'access', _184 => _184.style, 'optionalAccess', _185 => _185.fontName]) && Math.abs(ab.x + ab.width / 2 - (bb.x + bb.width / 2)) <= Math.max(5, af * 0.5);
|
|
6320
6336
|
const sameAnchor = ab && bb && Math.abs(ab.x - bb.x) <= 5;
|
|
6321
|
-
const wrapped = sameAnchor && _optionalChain([a, 'access',
|
|
6337
|
+
const wrapped = sameAnchor && _optionalChain([a, 'access', _186 => _186.style, 'optionalAccess', _187 => _187.fontName]) === _optionalChain([b, 'access', _188 => _188.style, 'optionalAccess', _189 => _189.fontName]) && af === bf && ab.width >= bb.width * 0.95 && (_nullishCoalesce(_optionalChain([a, 'access', _190 => _190.text, 'optionalAccess', _191 => _191.trim, 'call', _192 => _192(), 'access', _193 => _193.split, 'call', _194 => _194(/\s+/), 'access', _195 => _195.length]), () => ( 0))) >= 3;
|
|
6322
6338
|
const displayStack = centered && gap <= Math.min(af, bf) * 0.3 && Math.max(af, bf) <= Math.min(af, bf) * 1.45;
|
|
6323
6339
|
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)) {
|
|
6324
6340
|
i++;
|
|
@@ -6347,25 +6363,25 @@ function detectTypographyHeadings(blocks) {
|
|
|
6347
6363
|
if (page.some((block) => block.type === "heading")) continue;
|
|
6348
6364
|
const faceWeight = /* @__PURE__ */ new Map();
|
|
6349
6365
|
for (const block of page) {
|
|
6350
|
-
if (block.type !== "paragraph" || !block.text || !_optionalChain([block, 'access',
|
|
6366
|
+
if (block.type !== "paragraph" || !block.text || !_optionalChain([block, 'access', _196 => _196.style, 'optionalAccess', _197 => _197.fontName])) continue;
|
|
6351
6367
|
const faces = FACE_CHARS.get(block);
|
|
6352
6368
|
if (faces) for (const [face, n] of faces) faceWeight.set(face, (_nullishCoalesce(faceWeight.get(face), () => ( 0))) + n);
|
|
6353
6369
|
else faceWeight.set(block.style.fontName, (_nullishCoalesce(faceWeight.get(block.style.fontName), () => ( 0))) + block.text.length);
|
|
6354
6370
|
}
|
|
6355
|
-
const bodyFace = _optionalChain([[...faceWeight], 'access',
|
|
6371
|
+
const bodyFace = _optionalChain([[...faceWeight], 'access', _198 => _198.sort, 'call', _199 => _199((a, b) => b[1] - a[1]), 'access', _200 => _200[0], 'optionalAccess', _201 => _201[0]]);
|
|
6356
6372
|
if (!bodyFace || (_nullishCoalesce(faceWeight.get(bodyFace), () => ( 0))) < 250) continue;
|
|
6357
6373
|
const sizeWeight = /* @__PURE__ */ new Map();
|
|
6358
6374
|
for (const block of page) {
|
|
6359
|
-
if (block.type !== "paragraph" || !_optionalChain([block, 'access',
|
|
6375
|
+
if (block.type !== "paragraph" || !_optionalChain([block, 'access', _202 => _202.style, 'optionalAccess', _203 => _203.fontSize])) continue;
|
|
6360
6376
|
const faces = FACE_CHARS.get(block);
|
|
6361
|
-
const chars = faces ? _nullishCoalesce(faces.get(bodyFace), () => ( 0)) : block.style.fontName === bodyFace ? _nullishCoalesce(_optionalChain([block, 'access',
|
|
6377
|
+
const chars = faces ? _nullishCoalesce(faces.get(bodyFace), () => ( 0)) : block.style.fontName === bodyFace ? _nullishCoalesce(_optionalChain([block, 'access', _204 => _204.text, 'optionalAccess', _205 => _205.length]), () => ( 0)) : 0;
|
|
6362
6378
|
if (chars) sizeWeight.set(block.style.fontSize, (_nullishCoalesce(sizeWeight.get(block.style.fontSize), () => ( 0))) + chars);
|
|
6363
6379
|
}
|
|
6364
|
-
const bodySize = _nullishCoalesce(_optionalChain([[...sizeWeight], 'access',
|
|
6380
|
+
const bodySize = _nullishCoalesce(_optionalChain([[...sizeWeight], 'access', _206 => _206.sort, 'call', _207 => _207((a, b) => b[1] - a[1]), 'access', _208 => _208[0], 'optionalAccess', _209 => _209[0]]), () => ( 0));
|
|
6365
6381
|
for (let i = 0; i < page.length; i++) {
|
|
6366
6382
|
const block = page[i];
|
|
6367
6383
|
const { text, bbox, style } = block;
|
|
6368
|
-
if (block.type !== "paragraph" || !text || !bbox || !_optionalChain([style, 'optionalAccess',
|
|
6384
|
+
if (block.type !== "paragraph" || !text || !bbox || !_optionalChain([style, 'optionalAccess', _210 => _210.fontName]) || !style.fontSize) continue;
|
|
6369
6385
|
const title = text.trim();
|
|
6370
6386
|
const numbered = /^\d+(?:\.\d+)*\.?\s+[A-Z가-힣]/.test(title);
|
|
6371
6387
|
const faces = FACE_CHARS.get(block);
|
|
@@ -6395,16 +6411,16 @@ function detectDocumentStyleHeadings(blocks) {
|
|
|
6395
6411
|
for (const page of byPage.values()) {
|
|
6396
6412
|
const faceChars = /* @__PURE__ */ new Map();
|
|
6397
6413
|
for (const block of page) {
|
|
6398
|
-
if (block.type !== "paragraph" || !block.text || !_optionalChain([block, 'access',
|
|
6414
|
+
if (block.type !== "paragraph" || !block.text || !_optionalChain([block, 'access', _211 => _211.style, 'optionalAccess', _212 => _212.fontName])) continue;
|
|
6399
6415
|
faceChars.set(block.style.fontName, (_nullishCoalesce(faceChars.get(block.style.fontName), () => ( 0))) + block.text.length);
|
|
6400
6416
|
}
|
|
6401
|
-
const bodyFace = _optionalChain([[...faceChars], 'access',
|
|
6417
|
+
const bodyFace = _optionalChain([[...faceChars], 'access', _213 => _213.sort, 'call', _214 => _214((a, b) => b[1] - a[1]), 'access', _215 => _215[0], 'optionalAccess', _216 => _216[0]]);
|
|
6402
6418
|
if (!bodyFace || (_nullishCoalesce(faceChars.get(bodyFace), () => ( 0))) < 100) continue;
|
|
6403
|
-
const labels = page.filter((b) => b.type === "paragraph" && b.text && b.bbox && _optionalChain([b, 'access',
|
|
6419
|
+
const labels = page.filter((b) => b.type === "paragraph" && b.text && b.bbox && _optionalChain([b, 'access', _217 => _217.style, 'optionalAccess', _218 => _218.fontName]) && b.style.fontName !== bodyFace && b.text.trim().length >= 3 && b.text.trim().length <= 40);
|
|
6404
6420
|
for (const label of labels) {
|
|
6405
|
-
const peers = labels.filter((b) => _optionalChain([b, 'access',
|
|
6421
|
+
const peers = labels.filter((b) => _optionalChain([b, 'access', _219 => _219.style, 'optionalAccess', _220 => _220.fontName]) === _optionalChain([label, 'access', _221 => _221.style, 'optionalAccess', _222 => _222.fontName]) && Math.abs(b.bbox.y - label.bbox.y) <= 3 && Math.abs(b.bbox.x - label.bbox.x) >= 60);
|
|
6406
6422
|
if (peers.length < 2) continue;
|
|
6407
|
-
const value = page.find((b) => b.type === "paragraph" && b.bbox && _optionalChain([b, 'access',
|
|
6423
|
+
const value = page.find((b) => b.type === "paragraph" && b.bbox && _optionalChain([b, 'access', _223 => _223.style, 'optionalAccess', _224 => _224.fontName]) !== _optionalChain([label, 'access', _225 => _225.style, 'optionalAccess', _226 => _226.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);
|
|
6408
6424
|
if (value) {
|
|
6409
6425
|
label.type = "heading";
|
|
6410
6426
|
label.level = 2;
|
|
@@ -6413,7 +6429,7 @@ function detectDocumentStyleHeadings(blocks) {
|
|
|
6413
6429
|
const first = page.find((b) => b.type !== "image" && b.type !== "separator");
|
|
6414
6430
|
const second = page[page.indexOf(first) + 1];
|
|
6415
6431
|
const third = page[page.indexOf(first) + 2];
|
|
6416
|
-
if (!first || !second || !third || first.type !== "list" && first.type !== "paragraph" || second.type !== "paragraph" || !first.text || !second.text || !first.bbox || !second.bbox || !_optionalChain([first, 'access',
|
|
6432
|
+
if (!first || !second || !third || first.type !== "list" && first.type !== "paragraph" || second.type !== "paragraph" || !first.text || !second.text || !first.bbox || !second.bbox || !_optionalChain([first, 'access', _227 => _227.style, 'optionalAccess', _228 => _228.fontName]) || !_optionalChain([second, 'access', _229 => _229.style, 'optionalAccess', _230 => _230.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', _231 => _231.style, 'optionalAccess', _232 => _232.fontName]) !== bodyFace) continue;
|
|
6417
6433
|
first.type = "heading";
|
|
6418
6434
|
first.level = 1;
|
|
6419
6435
|
first.text = `${first.text.trim()} ${second.text.trim()}`;
|
|
@@ -6437,18 +6453,18 @@ function detectSiblingStyleHeadings(blocks) {
|
|
|
6437
6453
|
for (const page of byPage.values()) {
|
|
6438
6454
|
const bodyChars = /* @__PURE__ */ new Map();
|
|
6439
6455
|
for (const block of page) {
|
|
6440
|
-
if (block.type !== "paragraph" || !block.text || !_optionalChain([block, 'access',
|
|
6456
|
+
if (block.type !== "paragraph" || !block.text || !_optionalChain([block, 'access', _233 => _233.style, 'optionalAccess', _234 => _234.fontName])) continue;
|
|
6441
6457
|
const face = block.style.fontName;
|
|
6442
6458
|
bodyChars.set(face, (_nullishCoalesce(bodyChars.get(face), () => ( 0))) + block.text.length);
|
|
6443
6459
|
}
|
|
6444
|
-
const bodyFace = _optionalChain([[...bodyChars], 'access',
|
|
6445
|
-
const anchors = page.filter((b) => b.type === "heading" && b.text && _optionalChain([b, 'access',
|
|
6460
|
+
const bodyFace = _optionalChain([[...bodyChars], 'access', _235 => _235.sort, 'call', _236 => _236((a, b) => b[1] - a[1]), 'access', _237 => _237[0], 'optionalAccess', _238 => _238[0]]);
|
|
6461
|
+
const anchors = page.filter((b) => b.type === "heading" && b.text && _optionalChain([b, 'access', _239 => _239.style, 'optionalAccess', _240 => _240.fontName]) && b.style.fontName !== bodyFace);
|
|
6446
6462
|
for (const anchor of anchors) {
|
|
6447
6463
|
const numbered = /^([A-Z])\.\d+\s+/.exec(anchor.text.trim());
|
|
6448
6464
|
const lettered = /^([A-Z])\s+/.exec(anchor.text.trim());
|
|
6449
|
-
const peers = anchors.filter((b) => _optionalChain([b, 'access',
|
|
6465
|
+
const peers = anchors.filter((b) => _optionalChain([b, 'access', _241 => _241.style, 'optionalAccess', _242 => _242.fontName]) === _optionalChain([anchor, 'access', _243 => _243.style, 'optionalAccess', _244 => _244.fontName]) && Math.abs((_nullishCoalesce(_optionalChain([b, 'access', _245 => _245.style, 'optionalAccess', _246 => _246.fontSize]), () => ( 0))) - (_nullishCoalesce(_optionalChain([anchor, 'access', _247 => _247.style, 'optionalAccess', _248 => _248.fontSize]), () => ( 0)))) < 0.5);
|
|
6450
6466
|
if (peers.length < 2 && !numbered && !lettered) continue;
|
|
6451
|
-
const candidates = page.filter((b) => b.type === "paragraph" && b.text && b.bbox && _optionalChain([b, 'access',
|
|
6467
|
+
const candidates = page.filter((b) => b.type === "paragraph" && b.text && b.bbox && _optionalChain([b, 'access', _249 => _249.style, 'optionalAccess', _250 => _250.fontName]) === _optionalChain([anchor, 'access', _251 => _251.style, 'optionalAccess', _252 => _252.fontName]) && Math.abs((_nullishCoalesce(_optionalChain([b, 'access', _253 => _253.style, 'optionalAccess', _254 => _254.fontSize]), () => ( 0))) - (_nullishCoalesce(_optionalChain([anchor, 'access', _255 => _255.style, 'optionalAccess', _256 => _256.fontSize]), () => ( 0)))) < 0.5 && b.text.trim().length >= 3 && b.text.trim().length <= 80 && b.bbox.height <= (_nullishCoalesce(_optionalChain([b, 'access', _257 => _257.style, 'optionalAccess', _258 => _258.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()));
|
|
6452
6468
|
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));
|
|
6453
6469
|
if (siblings.length < (numbered || lettered ? 1 : 2)) continue;
|
|
6454
6470
|
for (const sibling of siblings) {
|
|
@@ -6467,13 +6483,13 @@ function detectRepeatedPageLabels(blocks) {
|
|
|
6467
6483
|
}
|
|
6468
6484
|
for (const page of byPage.values()) {
|
|
6469
6485
|
const bodyChars = /* @__PURE__ */ new Map();
|
|
6470
|
-
for (const b of page) if (b.type === "paragraph" && b.text && _optionalChain([b, 'access',
|
|
6486
|
+
for (const b of page) if (b.type === "paragraph" && b.text && _optionalChain([b, 'access', _259 => _259.style, 'optionalAccess', _260 => _260.fontName])) {
|
|
6471
6487
|
const faces = FACE_CHARS.get(b);
|
|
6472
6488
|
if (faces) for (const [face, n] of faces) bodyChars.set(face, (_nullishCoalesce(bodyChars.get(face), () => ( 0))) + n);
|
|
6473
6489
|
else bodyChars.set(b.style.fontName, (_nullishCoalesce(bodyChars.get(b.style.fontName), () => ( 0))) + b.text.length);
|
|
6474
6490
|
}
|
|
6475
|
-
const bodyFace = _optionalChain([[...bodyChars], 'access',
|
|
6476
|
-
const candidates = page.filter((b) => b.type === "paragraph" && b.text && b.bbox && _optionalChain([b, 'access',
|
|
6491
|
+
const bodyFace = _optionalChain([[...bodyChars], 'access', _261 => _261.sort, 'call', _262 => _262((a, b) => b[1] - a[1]), 'access', _263 => _263[0], 'optionalAccess', _264 => _264[0]]);
|
|
6492
|
+
const candidates = page.filter((b) => b.type === "paragraph" && b.text && b.bbox && _optionalChain([b, 'access', _265 => _265.style, 'optionalAccess', _266 => _266.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);
|
|
6477
6493
|
const groups = /* @__PURE__ */ new Map();
|
|
6478
6494
|
for (const b of candidates) {
|
|
6479
6495
|
const key = `${b.style.fontName}:${b.style.fontSize}`;
|
|
@@ -6509,19 +6525,19 @@ function detectPageLeadHeadings(blocks) {
|
|
|
6509
6525
|
for (const page of byPage.values()) {
|
|
6510
6526
|
const content = page.filter((b) => b.type !== "image" && b.type !== "separator" && !(b.type === "paragraph" && !b.style));
|
|
6511
6527
|
const [first, second, third] = content;
|
|
6512
|
-
if (!_optionalChain([first, 'optionalAccess',
|
|
6528
|
+
if (!_optionalChain([first, 'optionalAccess', _267 => _267.bbox]) || !first.text || !_optionalChain([first, 'access', _268 => _268.style, 'optionalAccess', _269 => _269.fontSize]) || !second) continue;
|
|
6513
6529
|
const firstText = first.text.trim();
|
|
6514
6530
|
const captionLike = /^(?:Figure|Fig\.?|Table|표|그림)\s*\d/i;
|
|
6515
6531
|
const hasImage = page.some((b) => b.type === "image");
|
|
6516
|
-
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',
|
|
6532
|
+
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', _270 => _270.text, 'optionalAccess', _271 => _271.trim, 'call', _272 => _272()]), () => ( ""))) && (_nullishCoalesce(_optionalChain([second, 'access', _273 => _273.text, 'optionalAccess', _274 => _274.length]), () => ( 0))) >= 100 && second.bbox && first.bbox.y - (second.bbox.y + second.bbox.height) >= first.style.fontSize);
|
|
6517
6533
|
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);
|
|
6518
|
-
const firstIsSection = first.type === "list" && /^\d+\.\s+[A-Z][A-Z\s]{12,}$/.test(firstText) && second.type === "paragraph" && (_nullishCoalesce(_optionalChain([second, 'access',
|
|
6534
|
+
const firstIsSection = first.type === "list" && /^\d+\.\s+[A-Z][A-Z\s]{12,}$/.test(firstText) && second.type === "paragraph" && (_nullishCoalesce(_optionalChain([second, 'access', _275 => _275.text, 'optionalAccess', _276 => _276.length]), () => ( 0))) >= 100;
|
|
6519
6535
|
if (firstIsTitle || firstAboveProse || firstIsSection) {
|
|
6520
6536
|
first.type = "heading";
|
|
6521
6537
|
first.level = 1;
|
|
6522
6538
|
}
|
|
6523
|
-
if (first.type !== "heading" || captionLike.test(firstText) || second.type !== "paragraph" || !second.text || !second.bbox || !_optionalChain([second, 'access',
|
|
6524
|
-
const distinctFace = _optionalChain([third, 'access',
|
|
6539
|
+
if (first.type !== "heading" || captionLike.test(firstText) || second.type !== "paragraph" || !second.text || !second.bbox || !_optionalChain([second, 'access', _277 => _277.style, 'optionalAccess', _278 => _278.fontName]) || !second.style.fontSize || !_optionalChain([third, 'optionalAccess', _279 => _279.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;
|
|
6540
|
+
const distinctFace = _optionalChain([third, 'access', _280 => _280.style, 'optionalAccess', _281 => _281.fontName]) !== second.style.fontName;
|
|
6525
6541
|
const namedContents = /^Table of Contents$/i.test(second.text.trim());
|
|
6526
6542
|
if (distinctFace && third.text.length >= 60 || namedContents) {
|
|
6527
6543
|
second.type = "heading";
|
|
@@ -6532,24 +6548,24 @@ function detectPageLeadHeadings(blocks) {
|
|
|
6532
6548
|
function refineDocumentStyleHeadings(blocks) {
|
|
6533
6549
|
const faceChars = /* @__PURE__ */ new Map();
|
|
6534
6550
|
for (const block of blocks) {
|
|
6535
|
-
if (block.type !== "paragraph" || !block.text || !_optionalChain([block, 'access',
|
|
6551
|
+
if (block.type !== "paragraph" || !block.text || !_optionalChain([block, 'access', _282 => _282.style, 'optionalAccess', _283 => _283.fontName])) continue;
|
|
6536
6552
|
faceChars.set(block.style.fontName, (_nullishCoalesce(faceChars.get(block.style.fontName), () => ( 0))) + block.text.length);
|
|
6537
6553
|
}
|
|
6538
6554
|
const [bodyFace, bodyChars] = _nullishCoalesce([...faceChars].sort((a, b) => b[1] - a[1])[0], () => ( []));
|
|
6539
6555
|
if (!bodyFace || !bodyChars || bodyChars < 300) return;
|
|
6540
6556
|
for (let i = 0; i < blocks.length; i++) {
|
|
6541
6557
|
const block = blocks[i];
|
|
6542
|
-
const text = _nullishCoalesce(_optionalChain([block, 'access',
|
|
6558
|
+
const text = _nullishCoalesce(_optionalChain([block, 'access', _284 => _284.text, 'optionalAccess', _285 => _285.trim, 'call', _286 => _286()]), () => ( ""));
|
|
6543
6559
|
if (block.type === "heading" && /(?:https?:\/\/|www\.|^arxiv:|^doi:)/i.test(text)) {
|
|
6544
6560
|
block.type = "paragraph";
|
|
6545
6561
|
block.level = void 0;
|
|
6546
6562
|
continue;
|
|
6547
6563
|
}
|
|
6548
6564
|
const box = block.bbox, style = block.style;
|
|
6549
|
-
if (block.type !== "paragraph" || !box || !_optionalChain([style, 'optionalAccess',
|
|
6565
|
+
if (block.type !== "paragraph" || !box || !_optionalChain([style, 'optionalAccess', _287 => _287.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;
|
|
6550
6566
|
const previous = blocks[i - 1], next = blocks[i + 1];
|
|
6551
|
-
const pb = _optionalChain([previous, 'optionalAccess',
|
|
6552
|
-
if (!pb || !nb || previous.pageNumber !== block.pageNumber || next.pageNumber !== block.pageNumber || previous.type !== "paragraph" && previous.type !== "heading" || next.type !== "paragraph" || _optionalChain([next, 'access',
|
|
6567
|
+
const pb = _optionalChain([previous, 'optionalAccess', _288 => _288.bbox]), nb = _optionalChain([next, 'optionalAccess', _289 => _289.bbox]);
|
|
6568
|
+
if (!pb || !nb || previous.pageNumber !== block.pageNumber || next.pageNumber !== block.pageNumber || previous.type !== "paragraph" && previous.type !== "heading" || next.type !== "paragraph" || _optionalChain([next, 'access', _290 => _290.style, 'optionalAccess', _291 => _291.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;
|
|
6553
6569
|
block.type = "heading";
|
|
6554
6570
|
block.level = 2;
|
|
6555
6571
|
}
|
|
@@ -6599,7 +6615,7 @@ function detectMarkerHeadings(blocks) {
|
|
|
6599
6615
|
block.level = 4;
|
|
6600
6616
|
continue;
|
|
6601
6617
|
}
|
|
6602
|
-
if (/^[가-힣]{2,6}$/.test(text) && _optionalChain([block, 'access',
|
|
6618
|
+
if (/^[가-힣]{2,6}$/.test(text) && _optionalChain([block, 'access', _292 => _292.style, 'optionalAccess', _293 => _293.fontSize])) {
|
|
6603
6619
|
const prev = blocks[i - 1];
|
|
6604
6620
|
const next = blocks[i + 1];
|
|
6605
6621
|
const prevIsStructural = !prev || prev.type === "table" || prev.type === "heading" || prev.type === "separator";
|
|
@@ -6640,7 +6656,7 @@ function detectTableCaptions(blocks) {
|
|
|
6640
6656
|
block.table.caption = blocks[i - 1].text.trim();
|
|
6641
6657
|
blocks.splice(i - 1, 1);
|
|
6642
6658
|
i--;
|
|
6643
|
-
} else if (isCaptionCandidate(blocks[i + 1], block) && _optionalChain([blocks, 'access',
|
|
6659
|
+
} else if (isCaptionCandidate(blocks[i + 1], block) && _optionalChain([blocks, 'access', _294 => _294[i + 2], 'optionalAccess', _295 => _295.type]) !== "table") {
|
|
6644
6660
|
const cap = blocks[i + 1].bbox, tbl = block.bbox;
|
|
6645
6661
|
block.table.caption = blocks[i + 1].text.trim();
|
|
6646
6662
|
if (cap && tbl && cap.y + cap.height <= tbl.y + 1) block.table.captionBelow = true;
|
|
@@ -6878,7 +6894,7 @@ function removeHeaderFooterBlocks(blocks, pageHeights, warnings, notes, tables =
|
|
|
6878
6894
|
const bottomEntries = [];
|
|
6879
6895
|
for (let bi = 0; bi < blocks.length; bi++) {
|
|
6880
6896
|
const b = blocks[bi];
|
|
6881
|
-
const text = !tables ? _optionalChain([b, 'access',
|
|
6897
|
+
const text = !tables ? _optionalChain([b, 'access', _296 => _296.text, 'optionalAccess', _297 => _297.trim, 'call', _298 => _298()]) : b.type === "table" && b.table ? b.table.cells.flat().map((c) => c.text.trim()).filter(Boolean).join(" | ") : void 0;
|
|
6882
6898
|
if (!b.bbox || !b.pageNumber || !text) continue;
|
|
6883
6899
|
const ph = pageHeights.get(b.bbox.page) || pageHeights.get(b.pageNumber);
|
|
6884
6900
|
if (!ph) continue;
|
|
@@ -6911,7 +6927,7 @@ function removeHeaderFooterBlocks(blocks, pageHeights, warnings, notes, tables =
|
|
|
6911
6927
|
for (const [p, count] of patternCount) {
|
|
6912
6928
|
const pages = [..._nullishCoalesce(patternPages.get(p), () => ( []))];
|
|
6913
6929
|
const span2 = pages.length ? Math.max(...pages) - Math.min(...pages) + 1 : 0;
|
|
6914
|
-
const varying = !tables && (_nullishCoalesce(_optionalChain([patternNumbers, 'access',
|
|
6930
|
+
const varying = !tables && (_nullishCoalesce(_optionalChain([patternNumbers, 'access', _299 => _299.get, 'call', _300 => _300(p), 'optionalAccess', _301 => _301.size]), () => ( 0))) > 1;
|
|
6915
6931
|
const occ = _nullishCoalesce(patternOcc.get(p), () => ( []));
|
|
6916
6932
|
const dense = pages.length >= span2 * 0.4;
|
|
6917
6933
|
const loose = looseVaryingNumber(occ, entries === topEntries) && (entries === bottomEntries || dense || tracksPages(occ));
|
|
@@ -6923,8 +6939,8 @@ function removeHeaderFooterBlocks(blocks, pageHeights, warnings, notes, tables =
|
|
|
6923
6939
|
for (const e of entries) {
|
|
6924
6940
|
const norm = e.text.replace(/\d+/g, "#");
|
|
6925
6941
|
if (!repeatedPatterns.has(norm)) continue;
|
|
6926
|
-
const noteMark = _optionalChain([e, 'access',
|
|
6927
|
-
if (noteMark && _optionalChain([notes, 'optionalAccess',
|
|
6942
|
+
const noteMark = _optionalChain([e, 'access', _302 => _302.text, 'access', _303 => _303.match, 'call', _304 => _304(/^\d{1,3}\)/), 'optionalAccess', _305 => _305[0]]);
|
|
6943
|
+
if (noteMark && _optionalChain([notes, 'optionalAccess', _306 => _306.get, 'call', _307 => _307(e.page), 'optionalAccess', _308 => _308.marks, 'access', _309 => _309.some, 'call', _310 => _310((m) => m.mark === noteMark)])) continue;
|
|
6928
6944
|
const cand = blocks[e.blockIdx];
|
|
6929
6945
|
const cb = cand.bbox;
|
|
6930
6946
|
const tableNote = /^(?:주\s*(?:\d+\s*[).:]|[::])|(?:자료|출처)\s*[::]|\*\s+\S)/.test(e.text.replace(/ \| /g, " ")) && blocks.some((o) => {
|
|
@@ -6938,7 +6954,7 @@ function removeHeaderFooterBlocks(blocks, pageHeights, warnings, notes, tables =
|
|
|
6938
6954
|
if (bi === e.blockIdx) continue;
|
|
6939
6955
|
const o = blocks[bi];
|
|
6940
6956
|
if (!o.bbox || o.bbox.page !== cb.page) continue;
|
|
6941
|
-
const oNorm = _optionalChain([o, 'access',
|
|
6957
|
+
const oNorm = _optionalChain([o, 'access', _311 => _311.text, 'optionalAccess', _312 => _312.trim, 'call', _313 => _313(), 'access', _314 => _314.replace, 'call', _315 => _315(/\d+/g, "#")]);
|
|
6942
6958
|
if (oNorm && repeatedPatterns.has(oNorm)) continue;
|
|
6943
6959
|
const overlap2 = Math.min(cb.y + cb.height, o.bbox.y + o.bbox.height) - Math.max(cb.y, o.bbox.y);
|
|
6944
6960
|
if (overlap2 >= cb.height * 0.5) {
|
|
@@ -7066,7 +7082,7 @@ function recordRowRules(table, cells, bbox, hs) {
|
|
|
7066
7082
|
function markImageCell(cell) {
|
|
7067
7083
|
IMAGE_CELLS.add(cell);
|
|
7068
7084
|
}
|
|
7069
|
-
var emptyCell = (cell) => !cell || !_optionalChain([cell, 'access',
|
|
7085
|
+
var emptyCell = (cell) => !cell || !_optionalChain([cell, 'access', _316 => _316.text, 'optionalAccess', _317 => _317.trim, 'call', _318 => _318()]) && !_optionalChain([cell, 'access', _319 => _319.blocks, 'optionalAccess', _320 => _320.length]) && !IMAGE_CELLS.has(cell);
|
|
7070
7086
|
function trimTable(table) {
|
|
7071
7087
|
let cols = table.cols;
|
|
7072
7088
|
while (cols > 0 && table.cells.every((row) => emptyCell(row[cols - 1]))) cols--;
|
|
@@ -7082,7 +7098,7 @@ function trimTable(table) {
|
|
|
7082
7098
|
function trimTrailingEmptyTableCols(blocks) {
|
|
7083
7099
|
for (const b of blocks) {
|
|
7084
7100
|
if (b.type !== "table" || !b.table) continue;
|
|
7085
|
-
for (const row of b.table.cells) for (const cell of row) if (_optionalChain([cell, 'access',
|
|
7101
|
+
for (const row of b.table.cells) for (const cell of row) if (_optionalChain([cell, 'access', _321 => _321.blocks, 'optionalAccess', _322 => _322.length])) trimTrailingEmptyTableCols(cell.blocks);
|
|
7086
7102
|
trimTable(b.table);
|
|
7087
7103
|
}
|
|
7088
7104
|
}
|
|
@@ -7102,7 +7118,7 @@ function mergeSliverColumns(grid, colXs, maxWidth) {
|
|
|
7102
7118
|
}
|
|
7103
7119
|
const ok = owner.every((row) => {
|
|
7104
7120
|
const o = row[c];
|
|
7105
|
-
return !!o && (o.colSpan > 1 || !o.text.trim() && !_optionalChain([o, 'access',
|
|
7121
|
+
return !!o && (o.colSpan > 1 || !o.text.trim() && !_optionalChain([o, 'access', _323 => _323.blocks, 'optionalAccess', _324 => _324.length]));
|
|
7106
7122
|
});
|
|
7107
7123
|
if (!ok) continue;
|
|
7108
7124
|
const spanning = /* @__PURE__ */ new Set();
|
|
@@ -7129,7 +7145,7 @@ var multiply = (m, t) => [
|
|
|
7129
7145
|
m[1] * t[4] + m[3] * t[5] + m[5]
|
|
7130
7146
|
];
|
|
7131
7147
|
function hollowCircle(image) {
|
|
7132
|
-
if (!_optionalChain([image, 'optionalAccess',
|
|
7148
|
+
if (!_optionalChain([image, 'optionalAccess', _325 => _325.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;
|
|
7133
7149
|
const stride = image.kind === _pdfmjs.ImageKind.RGB_24BPP ? 3 : image.kind === _pdfmjs.ImageKind.RGBA_32BPP ? 4 : 0;
|
|
7134
7150
|
const { width, height, data } = image;
|
|
7135
7151
|
if (!stride || data.length < width * height * stride) return false;
|
|
@@ -7194,9 +7210,9 @@ function smallVisibleImagePaints(fnArray, argsArray) {
|
|
|
7194
7210
|
const op = fnArray[i], args = argsArray[i];
|
|
7195
7211
|
if (op === _pdfmjs.OPS.save || op === _pdfmjs.OPS.paintFormXObjectBegin) {
|
|
7196
7212
|
stack.push({ ctm, alpha, clip, unknownClip });
|
|
7197
|
-
const matrix = op === _pdfmjs.OPS.paintFormXObjectBegin ? _optionalChain([args, 'optionalAccess',
|
|
7213
|
+
const matrix = op === _pdfmjs.OPS.paintFormXObjectBegin ? _optionalChain([args, 'optionalAccess', _326 => _326[0]]) : void 0;
|
|
7198
7214
|
if (Array.isArray(matrix) && matrix.length >= 6) ctm = multiply(ctm, matrix);
|
|
7199
|
-
const bounds = op === _pdfmjs.OPS.paintFormXObjectBegin ? _optionalChain([args, 'optionalAccess',
|
|
7215
|
+
const bounds = op === _pdfmjs.OPS.paintFormXObjectBegin ? _optionalChain([args, 'optionalAccess', _327 => _327[1]]) : void 0;
|
|
7200
7216
|
if (Array.isArray(bounds) && bounds.length === 4) {
|
|
7201
7217
|
const box = rectangle(bounds[0], bounds[1], bounds[2] - bounds[0], bounds[3] - bounds[1]);
|
|
7202
7218
|
if (box && ctm[1] === 0 && ctm[2] === 0) intersectClip(box);
|
|
@@ -7204,17 +7220,17 @@ function smallVisibleImagePaints(fnArray, argsArray) {
|
|
|
7204
7220
|
}
|
|
7205
7221
|
} else if (op === _pdfmjs.OPS.restore || op === _pdfmjs.OPS.paintFormXObjectEnd) {
|
|
7206
7222
|
const state = stack.pop();
|
|
7207
|
-
ctm = _nullishCoalesce(_optionalChain([state, 'optionalAccess',
|
|
7208
|
-
alpha = _nullishCoalesce(_optionalChain([state, 'optionalAccess',
|
|
7209
|
-
clip = _nullishCoalesce(_optionalChain([state, 'optionalAccess',
|
|
7210
|
-
unknownClip = _nullishCoalesce(_optionalChain([state, 'optionalAccess',
|
|
7223
|
+
ctm = _nullishCoalesce(_optionalChain([state, 'optionalAccess', _328 => _328.ctm]), () => ( [1, 0, 0, 1, 0, 0]));
|
|
7224
|
+
alpha = _nullishCoalesce(_optionalChain([state, 'optionalAccess', _329 => _329.alpha]), () => ( 1));
|
|
7225
|
+
clip = _nullishCoalesce(_optionalChain([state, 'optionalAccess', _330 => _330.clip]), () => ( null));
|
|
7226
|
+
unknownClip = _nullishCoalesce(_optionalChain([state, 'optionalAccess', _331 => _331.unknownClip]), () => ( false));
|
|
7211
7227
|
} else if (op === _pdfmjs.OPS.setGState) {
|
|
7212
|
-
for (const [key, value] of _nullishCoalesce(_optionalChain([args, 'optionalAccess',
|
|
7228
|
+
for (const [key, value] of _nullishCoalesce(_optionalChain([args, 'optionalAccess', _332 => _332[0]]), () => ( []))) {
|
|
7213
7229
|
if (key === "ca") alpha = typeof value === "number" ? value : 0;
|
|
7214
7230
|
}
|
|
7215
7231
|
} else if (op === _pdfmjs.OPS.constructPath) {
|
|
7216
7232
|
const [operations, coordinates] = args;
|
|
7217
|
-
pathRect = pathRect === void 0 && _optionalChain([operations, 'optionalAccess',
|
|
7233
|
+
pathRect = pathRect === void 0 && _optionalChain([operations, 'optionalAccess', _333 => _333.length]) === 1 && operations[0] === _pdfmjs.OPS.rectangle && _optionalChain([coordinates, 'optionalAccess', _334 => _334.length]) >= 4 && ctm[1] === 0 && ctm[2] === 0 ? rectangle(coordinates[0], coordinates[1], coordinates[2], coordinates[3]) : null;
|
|
7218
7234
|
} else if (op === _pdfmjs.OPS.clip || op === _pdfmjs.OPS.eoClip) pendingClip = true;
|
|
7219
7235
|
else if ([
|
|
7220
7236
|
_pdfmjs.OPS.endPath,
|
|
@@ -7234,7 +7250,7 @@ function smallVisibleImagePaints(fnArray, argsArray) {
|
|
|
7234
7250
|
pendingClip = false;
|
|
7235
7251
|
pathRect = void 0;
|
|
7236
7252
|
} else if (op === _pdfmjs.OPS.transform && Array.isArray(args) && args.length >= 6) ctm = multiply(ctm, args);
|
|
7237
|
-
else if (op === _pdfmjs.OPS.paintImageXObject && typeof _optionalChain([args, 'optionalAccess',
|
|
7253
|
+
else if (op === _pdfmjs.OPS.paintImageXObject && typeof _optionalChain([args, 'optionalAccess', _335 => _335[0]]) === "string") {
|
|
7238
7254
|
if (typeof args[1] !== "number" || typeof args[2] !== "number" || args[1] < 16 || args[1] > 128 || args[2] < 16 || args[2] > 128) continue;
|
|
7239
7255
|
const box = extractImageRegions([_pdfmjs.OPS.transform, _pdfmjs.OPS.paintImageXObject], [ctm, args])[0];
|
|
7240
7256
|
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;
|
|
@@ -7253,14 +7269,14 @@ async function restoreImageBullets(items, page, fnArray, argsArray, shapes = /*
|
|
|
7253
7269
|
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];
|
|
7254
7270
|
if (!line || /^[○●•◦□■∙]/.test(line.text.trim()) || !/\p{L}/u.test(line.text)) continue;
|
|
7255
7271
|
const row = items.filter((item) => Math.abs(item.y - line.y) <= 2 && item.x >= line.x);
|
|
7256
|
-
if (row.reduce((n, item) => n + (_nullishCoalesce(_optionalChain([item, 'access',
|
|
7272
|
+
if (row.reduce((n, item) => n + (_nullishCoalesce(_optionalChain([item, 'access', _336 => _336.text, 'access', _337 => _337.match, 'call', _338 => _338(/\p{L}/gu), 'optionalAccess', _339 => _339.length]), () => ( 0))), 0) < 12 || items.some((item) => item !== line && Math.abs(item.y - line.y) <= 2 && item.x < line.x)) continue;
|
|
7257
7273
|
candidates.push({ id, x: box.x1, width, line });
|
|
7258
7274
|
}
|
|
7259
7275
|
let restored = 0;
|
|
7260
7276
|
const used = /* @__PURE__ */ new Set();
|
|
7261
7277
|
for (const candidate of candidates) {
|
|
7262
7278
|
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);
|
|
7263
|
-
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',
|
|
7279
|
+
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', _340 => _340.text, 'access', _341 => _341.match, 'call', _342 => _342(/\p{L}/gu), 'optionalAccess', _343 => _343.length]), () => ( 0))) >= 12).sort((a, b) => b.y - a.y);
|
|
7264
7280
|
const numberedList = numbered.some((item, index) => index > 0 && item.text.trim().charCodeAt(0) === numbered[index - 1].text.trim().charCodeAt(0) + 1);
|
|
7265
7281
|
if (!same.length && !numberedList || used.has(candidate.line)) continue;
|
|
7266
7282
|
if (!shapes.has(candidate.id)) shapes.set(candidate.id, hollowCircle(await resolveImagePixels(page, candidate.id)));
|
|
@@ -7326,7 +7342,7 @@ function groupFlowBoxUnits(blocks, grids, hs, vs, images) {
|
|
|
7326
7342
|
return units;
|
|
7327
7343
|
}
|
|
7328
7344
|
function arrowDirection(image) {
|
|
7329
|
-
if (!_optionalChain([image, 'optionalAccess',
|
|
7345
|
+
if (!_optionalChain([image, 'optionalAccess', _344 => _344.data]) || image.width < 16 || image.width > 128 || image.height < 16 || image.height > 128) return 0;
|
|
7330
7346
|
const { width, height, data } = image;
|
|
7331
7347
|
const stride = image.kind === _pdfmjs.ImageKind.RGB_24BPP ? 3 : image.kind === _pdfmjs.ImageKind.RGBA_32BPP ? 4 : 0;
|
|
7332
7348
|
if (!stride || data.length < width * height * stride) return 0;
|
|
@@ -7394,7 +7410,7 @@ function isSideTabTable(box, table, others, pageWidth, pageHeight) {
|
|
|
7394
7410
|
function removeSideTabs(blocks, pageWidths) {
|
|
7395
7411
|
const edges = /* @__PURE__ */ new Map();
|
|
7396
7412
|
for (const b of blocks) {
|
|
7397
|
-
if (!b.bbox || b.pageNumber === void 0 || [..._nullishCoalesce(_optionalChain([b, 'access',
|
|
7413
|
+
if (!b.bbox || b.pageNumber === void 0 || [..._nullishCoalesce(_optionalChain([b, 'access', _345 => _345.text, 'optionalAccess', _346 => _346.trim, 'call', _347 => _347()]), () => ( ""))].length <= MAX_CHARS) continue;
|
|
7398
7414
|
const e = _nullishCoalesce(edges.get(b.pageNumber), () => ( { lefts: [], rights: [] }));
|
|
7399
7415
|
e.lefts.push(b.bbox.x);
|
|
7400
7416
|
e.rights.push(b.bbox.x + b.bbox.width);
|
|
@@ -7410,7 +7426,7 @@ function removeSideTabs(blocks, pageWidths) {
|
|
|
7410
7426
|
const fallback = all.length ? { left: q(all.map((e) => e.left), 0.5), right: q(all.map((e) => e.right), 0.5) } : void 0;
|
|
7411
7427
|
const key = (b) => {
|
|
7412
7428
|
const w = b.pageNumber !== void 0 ? pageWidths.get(b.pageNumber) : void 0;
|
|
7413
|
-
const text = _optionalChain([b, 'access',
|
|
7429
|
+
const text = _optionalChain([b, 'access', _348 => _348.text, 'optionalAccess', _349 => _349.trim, 'call', _350 => _350()]);
|
|
7414
7430
|
const area = _nullishCoalesce((b.pageNumber !== void 0 ? body.get(b.pageNumber) : void 0), () => ( fallback));
|
|
7415
7431
|
if (b.type === "table") {
|
|
7416
7432
|
if (!w || !b.bbox || !b.table || !SIDE_TAB_TABLES.has(b.table)) return null;
|
|
@@ -7846,16 +7862,16 @@ function isProseSpread(items) {
|
|
|
7846
7862
|
for (let i = 1; i < sorted.length; i++) {
|
|
7847
7863
|
gaps.push(sorted[i].x - (sorted[i - 1].x + sorted[i - 1].w));
|
|
7848
7864
|
}
|
|
7849
|
-
const maxGap =
|
|
7865
|
+
const maxGap = _chunkC3BOYTY5cjs.safeMax.call(void 0, gaps);
|
|
7850
7866
|
const avgLen = items.reduce((s, i) => s + i.text.length, 0) / items.length;
|
|
7851
7867
|
if (items.length >= 4 && maxGap < 40 && avgLen < 5) return true;
|
|
7852
|
-
const minGap =
|
|
7868
|
+
const minGap = _chunkC3BOYTY5cjs.safeMin.call(void 0, gaps);
|
|
7853
7869
|
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)));
|
|
7854
7870
|
}
|
|
7855
7871
|
function detectColumns(yLines) {
|
|
7856
7872
|
const allItems = yLines.flat();
|
|
7857
7873
|
if (allItems.length === 0) return null;
|
|
7858
|
-
const pageWidth =
|
|
7874
|
+
const pageWidth = _chunkC3BOYTY5cjs.safeMax.call(void 0, allItems.map((i) => i.x + i.w)) - _chunkC3BOYTY5cjs.safeMin.call(void 0, allItems.map((i) => i.x));
|
|
7859
7875
|
if (pageWidth < 100) return null;
|
|
7860
7876
|
let bigoLineIdx = -1;
|
|
7861
7877
|
for (let i = 0; i < yLines.length; i++) {
|
|
@@ -8080,7 +8096,7 @@ var UNDER_BOX_PAIR_MAX_EM = 2.2;
|
|
|
8080
8096
|
var UNDER_BOX_PAIR_OVERLAP = 0.8;
|
|
8081
8097
|
function markUnderlineItems(items, horizontals, verticals, nonRules) {
|
|
8082
8098
|
const underlines = [];
|
|
8083
|
-
if (_optionalChain([nonRules, 'optionalAccess',
|
|
8099
|
+
if (_optionalChain([nonRules, 'optionalAccess', _351 => _351.size])) horizontals = horizontals.filter((line) => !nonRules.has(line));
|
|
8084
8100
|
if (items.length === 0 || horizontals.length === 0) return underlines;
|
|
8085
8101
|
const tightOwners = /* @__PURE__ */ new Map();
|
|
8086
8102
|
const tightlyOwned = (line) => {
|
|
@@ -8186,7 +8202,7 @@ function hasBoxTopPair(line, maxH, horizontals, cellItems) {
|
|
|
8186
8202
|
if (ow <= 0) continue;
|
|
8187
8203
|
const overlap2 = Math.min(line.x2, o.x2) - Math.max(line.x1, o.x1);
|
|
8188
8204
|
if (overlap2 / Math.max(w, ow) < UNDER_BOX_PAIR_OVERLAP) continue;
|
|
8189
|
-
const covered = _nullishCoalesce(_optionalChain([cellItems, 'optionalAccess',
|
|
8205
|
+
const covered = _nullishCoalesce(_optionalChain([cellItems, 'optionalAccess', _352 => _352.reduce, 'call', _353 => _353((sum, item) => {
|
|
8190
8206
|
const below = item.y - o.y1;
|
|
8191
8207
|
if (below < 0.5 || below > 3 || !item.text.trim()) return sum;
|
|
8192
8208
|
return sum + Math.max(0, Math.min(o.x2, item.x + item.w) - Math.max(o.x1, item.x));
|
|
@@ -8253,13 +8269,13 @@ function partTex(group) {
|
|
|
8253
8269
|
const base = Math.min(...g.filter((i) => i.fontSize >= size * SCRIPT_SIZE_RATIO).map((i) => i.y));
|
|
8254
8270
|
let s = "", run = "";
|
|
8255
8271
|
const flush = () => {
|
|
8256
|
-
if (run) s +=
|
|
8272
|
+
if (run) s += _chunkNW2CKOFLcjs.toTex.call(void 0, run);
|
|
8257
8273
|
run = "";
|
|
8258
8274
|
};
|
|
8259
8275
|
g.forEach((it, k) => {
|
|
8260
8276
|
if (it.fontSize < size * SCRIPT_SIZE_RATIO && it.y - base >= size * SCRIPT_RISE_EM) {
|
|
8261
8277
|
flush();
|
|
8262
|
-
s += `^{${
|
|
8278
|
+
s += `^{${_chunkNW2CKOFLcjs.toTex.call(void 0, it.text)}}`;
|
|
8263
8279
|
return;
|
|
8264
8280
|
}
|
|
8265
8281
|
if (k && it.x - (g[k - 1].x + g[k - 1].w) > spaceGapThreshold(it.fontSize)) run += " ";
|
|
@@ -8431,12 +8447,12 @@ function rebuildUnitLine(items, grid) {
|
|
|
8431
8447
|
function prependUnitRow(cells, cols, line, usedItems) {
|
|
8432
8448
|
const text = cleanCellText(line.map((item) => item.text).join(""));
|
|
8433
8449
|
cells.unshift(Array.from({ length: cols }, (_, c) => ({ text: c === 0 ? text : "", colSpan: c === 0 ? cols : 1, rowSpan: 1 })));
|
|
8434
|
-
for (const cell of cells[0])
|
|
8450
|
+
for (const cell of cells[0]) _chunkNW2CKOFLcjs.CELL_EDGES.set(cell, NO_EDGES);
|
|
8435
8451
|
for (const item of line) usedItems.add(item);
|
|
8436
8452
|
}
|
|
8437
8453
|
function attachUnitRow(items, grid, cells, cols, usedItems) {
|
|
8438
8454
|
const all = cells.flat();
|
|
8439
|
-
if (all.filter((c) => c.text.trim()).length * 2 < all.length || UNIT.test(_nullishCoalesce(_optionalChain([cells, 'access',
|
|
8455
|
+
if (all.filter((c) => c.text.trim()).length * 2 < all.length || UNIT.test(_nullishCoalesce(_optionalChain([cells, 'access', _354 => _354[0], 'optionalAccess', _355 => _355[0], 'optionalAccess', _356 => _356.text]), () => ( "")))) return false;
|
|
8440
8456
|
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);
|
|
8441
8457
|
let nearest = Infinity;
|
|
8442
8458
|
for (const it of above) nearest = Math.min(nearest, it.y);
|
|
@@ -8471,7 +8487,7 @@ function closeShadedTableEdges(clipGrids, horizontals, verticals, fillRects) {
|
|
|
8471
8487
|
let hs = horizontals, vs = verticals;
|
|
8472
8488
|
const restored = [];
|
|
8473
8489
|
for (const grid of clipGrids) {
|
|
8474
|
-
if (grid.clipParent || grid.rowYs.length !== 2 || grid.colXs.length < 3 || !_optionalChain([grid, 'access',
|
|
8490
|
+
if (grid.clipParent || grid.rowYs.length !== 2 || grid.colXs.length < 3 || !_optionalChain([grid, 'access', _357 => _357.cells, 'optionalAccess', _358 => _358.length]) || grid.cells.some((c) => c.filler || c.rowSpan !== 1 || c.colSpan !== 1)) continue;
|
|
8475
8491
|
const { x1, x2, y1: mid, y2: top } = grid.bbox;
|
|
8476
8492
|
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;
|
|
8477
8493
|
const topRule = hs.find((h) => near2(h.y1, top) && near2(h.x1, x1) && near2(h.x2, x2));
|
|
@@ -8935,7 +8951,7 @@ function takeFrameSpanningText(items, cutX, pageNum, lex) {
|
|
|
8935
8951
|
const rows = groupByY([...items].sort((a, b) => b.y - a.y || a.x - b.x)).map((line) => {
|
|
8936
8952
|
const runs = [];
|
|
8937
8953
|
for (const item of [...line].sort((a, b) => a.x - b.x)) {
|
|
8938
|
-
const run = runs[runs.length - 1], prev = _optionalChain([run, 'optionalAccess',
|
|
8954
|
+
const run = runs[runs.length - 1], prev = _optionalChain([run, 'optionalAccess', _359 => _359[run.length - 1]]);
|
|
8939
8955
|
if (prev && item.x - (prev.x + prev.w) <= Math.max(prev.fontSize, item.fontSize) * 0.6) run.push(item);
|
|
8940
8956
|
else runs.push([item]);
|
|
8941
8957
|
}
|
|
@@ -8979,7 +8995,7 @@ function groupFrameParagraphUnits(units, frames) {
|
|
|
8979
8995
|
for (const unit of units) for (const block of unit) source.set(block, unit);
|
|
8980
8996
|
const members = /* @__PURE__ */ new Map(), emitted = /* @__PURE__ */ new Set();
|
|
8981
8997
|
for (const frame of frames) {
|
|
8982
|
-
if (frame.length < 2 || frame.some((block) => block.type !== "paragraph" || _optionalChain([source, 'access',
|
|
8998
|
+
if (frame.length < 2 || frame.some((block) => block.type !== "paragraph" || _optionalChain([source, 'access', _360 => _360.get, 'call', _361 => _361(block), 'optionalAccess', _362 => _362.length]) !== 1)) continue;
|
|
8983
8999
|
for (const block of frame) members.set(block, frame);
|
|
8984
9000
|
}
|
|
8985
9001
|
const out = [];
|
|
@@ -8992,7 +9008,7 @@ function groupFrameParagraphUnits(units, frames) {
|
|
|
8992
9008
|
}
|
|
8993
9009
|
}
|
|
8994
9010
|
for (const unit of out) {
|
|
8995
|
-
if (unit.length < 2 || _optionalChain([FRAME_READING_UNITS, 'access',
|
|
9011
|
+
if (unit.length < 2 || _optionalChain([FRAME_READING_UNITS, 'access', _363 => _363.get, 'call', _364 => _364(unit[0]), 'optionalAccess', _365 => _365.blocks]) === unit) continue;
|
|
8996
9012
|
const bs = unit.map((b) => b.bbox).filter((b) => !!b);
|
|
8997
9013
|
if (bs.length !== unit.length) continue;
|
|
8998
9014
|
const x = Math.min(...bs.map((b) => b.x)), y = Math.min(...bs.map((b) => b.y));
|
|
@@ -9009,14 +9025,14 @@ function groupFrameParagraphUnits(units, frames) {
|
|
|
9009
9025
|
function recordFrameTitle(table, source, pageNum) {
|
|
9010
9026
|
if (!CLIP_TABLES.has(table) || table.rows !== 1 || table.cols !== 3 || source.length < 2) return;
|
|
9011
9027
|
const cells = table.cells[0];
|
|
9012
|
-
if (cells.length !== 3 || cells.some((c) => c.colSpan !== 1 || c.rowSpan !== 1 || _optionalChain([c, 'access',
|
|
9028
|
+
if (cells.length !== 3 || cells.some((c) => c.colSpan !== 1 || c.rowSpan !== 1 || _optionalChain([c, 'access', _366 => _366.blocks, 'optionalAccess', _367 => _367.length]) || c.text.includes("\n"))) return;
|
|
9013
9029
|
const [label, spacer, title] = cells;
|
|
9014
9030
|
if (!/^(?:붙임|별첨|첨부|부록)\s*\d{1,3}$/.test(label.text.trim()) || spacer.text.trim() || !title.text.trim()) return;
|
|
9015
9031
|
if (cells.some((c) => {
|
|
9016
|
-
const e =
|
|
9032
|
+
const e = _chunkNW2CKOFLcjs.CELL_EDGES.get(c);
|
|
9017
9033
|
return !e || e.t || e.b || e.l || e.r;
|
|
9018
9034
|
})) return;
|
|
9019
|
-
const xs = TABLE_COLXS.get(table), style = dominantStyle(source), fs = _nullishCoalesce(_optionalChain([style, 'optionalAccess',
|
|
9035
|
+
const xs = TABLE_COLXS.get(table), style = dominantStyle(source), fs = _nullishCoalesce(_optionalChain([style, 'optionalAccess', _368 => _368.fontSize]), () => ( 0));
|
|
9020
9036
|
if (!xs || xs.length !== 4 || fs <= 0) return;
|
|
9021
9037
|
const width = xs[3] - xs[0], gap = xs[2] - xs[1];
|
|
9022
9038
|
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;
|
|
@@ -9074,7 +9090,7 @@ function extendNestedShadedHeaders(clipGrids, lineGrids, horizontals, verticals,
|
|
|
9074
9090
|
const extended = [];
|
|
9075
9091
|
for (let i = 0; i < clipGrids.length; i++) {
|
|
9076
9092
|
const c = clipGrids[i], parent = c.clipParent;
|
|
9077
|
-
if (!parent || c.rowYs.length !== 2 || c.colXs.length < 3 || !_optionalChain([c, 'access',
|
|
9093
|
+
if (!parent || c.rowYs.length !== 2 || c.colXs.length < 3 || !_optionalChain([c, 'access', _369 => _369.cells, 'optionalAccess', _370 => _370.length]) || c.cells.some((cell) => cell.filler || cell.rowSpan !== 1 || cell.colSpan !== 1)) continue;
|
|
9078
9094
|
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;
|
|
9079
9095
|
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;
|
|
9080
9096
|
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)));
|
|
@@ -9097,7 +9113,7 @@ function attachSideTabBlocks(tab, body, pageNum) {
|
|
|
9097
9113
|
bbox: computeBBox(items, pageNum),
|
|
9098
9114
|
style: dominantStyle(items)
|
|
9099
9115
|
});
|
|
9100
|
-
const prefix = ordered.filter((g) => !_optionalChain([caps, 'optionalAccess',
|
|
9116
|
+
const prefix = ordered.filter((g) => !_optionalChain([caps, 'optionalAccess', _371 => _371.has, 'call', _372 => _372(g)])).map((g) => ({
|
|
9101
9117
|
type: "paragraph",
|
|
9102
9118
|
text: g.text.trim(),
|
|
9103
9119
|
pageNumber: pageNum,
|
|
@@ -9106,7 +9122,7 @@ function attachSideTabBlocks(tab, body, pageNum) {
|
|
|
9106
9122
|
}));
|
|
9107
9123
|
const groups = /* @__PURE__ */ new Map();
|
|
9108
9124
|
for (const g of ordered) {
|
|
9109
|
-
const cap = _optionalChain([caps, 'optionalAccess',
|
|
9125
|
+
const cap = _optionalChain([caps, 'optionalAccess', _373 => _373.get, 'call', _374 => _374(g)]);
|
|
9110
9126
|
if (cap) groups.set(cap, [..._nullishCoalesce(groups.get(cap), () => ( [])), g]);
|
|
9111
9127
|
}
|
|
9112
9128
|
for (const [cap, glyphs] of groups) {
|
|
@@ -9140,7 +9156,7 @@ function extractPageBlocksWithLines(items, pageNum, opList, pageWidth, pageHeigh
|
|
|
9140
9156
|
const filled = fillBlanks(items, horizontals, verticals);
|
|
9141
9157
|
items = filled.items;
|
|
9142
9158
|
horizontals = filled.horizontals;
|
|
9143
|
-
const prevPage = _optionalChain([carry, 'optionalAccess',
|
|
9159
|
+
const prevPage = _optionalChain([carry, 'optionalAccess', _375 => _375.page]) === pageNum - 1 ? carry.clip : void 0;
|
|
9144
9160
|
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 };
|
|
9145
9161
|
if (carry) {
|
|
9146
9162
|
carry.page = pageNum;
|
|
@@ -9397,14 +9413,14 @@ function extractBlocksWithGrids(items, pageNum, pageWidth, pageHeight, grids, ho
|
|
|
9397
9413
|
if (!assignedItems.has(textItems[ti])) usedItems.delete(owners[ti]);
|
|
9398
9414
|
}
|
|
9399
9415
|
}
|
|
9400
|
-
if (unitLine.length > 0 && rebuiltUsed && !/^\s*\(\s*단위\s*[::]/.test(_nullishCoalesce(_optionalChain([finalGrid, 'access',
|
|
9416
|
+
if (unitLine.length > 0 && rebuiltUsed && !/^\s*\(\s*단위\s*[::]/.test(_nullishCoalesce(_optionalChain([finalGrid, 'access', _376 => _376[0], 'optionalAccess', _377 => _377[0], 'optionalAccess', _378 => _378.text]), () => ( "")))) {
|
|
9401
9417
|
prependUnitRow(finalGrid, numCols, unitLine, usedItems);
|
|
9402
9418
|
finalRows++;
|
|
9403
9419
|
}
|
|
9404
9420
|
if (!rebuiltUsed && attachUnitRow(items, grid, finalGrid, numCols, usedItems)) finalRows++;
|
|
9405
9421
|
let semanticOneColumn = false;
|
|
9406
9422
|
if (!grid.cells && !nestedAttached && numCols === 1 && numGridRows >= 2) {
|
|
9407
|
-
const populatedRows = finalGrid.filter((row) => _optionalChain([row, 'access',
|
|
9423
|
+
const populatedRows = finalGrid.filter((row) => _optionalChain([row, 'access', _379 => _379[0], 'optionalAccess', _380 => _380.text, 'access', _381 => _381.trim, 'call', _382 => _382()]));
|
|
9408
9424
|
if (populatedRows.length >= 4) {
|
|
9409
9425
|
const fontSizes = tableItems.map((item) => item.fontSize).filter((size) => size > 0).sort((a, b) => a - b);
|
|
9410
9426
|
const medianFont = _nullishCoalesce(fontSizes[Math.floor(fontSizes.length / 2)], () => ( 0));
|
|
@@ -9500,7 +9516,7 @@ function extractBlocksWithGrids(items, pageNum, pageWidth, pageHeight, grids, ho
|
|
|
9500
9516
|
height: grid.bbox.y2 - grid.bbox.y1
|
|
9501
9517
|
};
|
|
9502
9518
|
if (numRows === 1 && numCols === 1 && gridW < pageWidth * 0.35) {
|
|
9503
|
-
const prose = _nullishCoalesce(_optionalChain([finalGrid, 'access',
|
|
9519
|
+
const prose = _nullishCoalesce(_optionalChain([finalGrid, 'access', _383 => _383[0], 'optionalAccess', _384 => _384[0], 'optionalAccess', _385 => _385.text]), () => ( ""));
|
|
9504
9520
|
const besideLines = (side) => new Set(side.map((it) => Math.round(it.y / 3))).size;
|
|
9505
9521
|
const rightLines = items.filter((it) => it.x >= grid.bbox.x2 + 3 && it.y >= grid.bbox.y1 && it.y <= grid.bbox.y2);
|
|
9506
9522
|
const leftLines = items.filter((it) => it.x + it.w <= grid.bbox.x1 - 3 && it.y >= grid.bbox.y1 && it.y <= grid.bbox.y2);
|
|
@@ -9519,8 +9535,8 @@ function extractBlocksWithGrids(items, pageNum, pageWidth, pageHeight, grids, ho
|
|
|
9519
9535
|
}
|
|
9520
9536
|
}
|
|
9521
9537
|
if (!grid.cells && !nestedAttached && shouldDemoteTable(irTable)) {
|
|
9522
|
-
const paragraphs = numRows === 1 && numCols === 1 ? _optionalChain([irTable, 'access',
|
|
9523
|
-
if (_optionalChain([paragraphs, 'optionalAccess',
|
|
9538
|
+
const paragraphs = numRows === 1 && numCols === 1 ? _optionalChain([irTable, 'access', _386 => _386.cells, 'access', _387 => _387[0], 'optionalAccess', _388 => _388[0], 'optionalAccess', _389 => _389.blocks]) : void 0;
|
|
9539
|
+
if (_optionalChain([paragraphs, 'optionalAccess', _390 => _390.length])) {
|
|
9524
9540
|
blocks.push(...paragraphs);
|
|
9525
9541
|
frameParagraphUnits.push(paragraphs);
|
|
9526
9542
|
recordFrameReadingUnit(paragraphs, tableBbox);
|
|
@@ -9567,7 +9583,7 @@ function extractBlocksWithGrids(items, pageNum, pageWidth, pageHeight, grids, ho
|
|
|
9567
9583
|
const clusterResults = (proseColumns ? [] : detectClusterTables(clusterItems, pageNum, void 0, lex)).filter((cr) => {
|
|
9568
9584
|
const b = cr.bbox;
|
|
9569
9585
|
const overlapX = (x) => Math.min(x.x + x.width, b.x + b.width) - Math.max(x.x, b.x);
|
|
9570
|
-
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',
|
|
9586
|
+
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', _391 => _391.text, 'optionalAccess', _392 => _392.match, 'call', _393 => _393(/\p{L}/gu), 'optionalAccess', _394 => _394.length]), () => ( 0))) >= 10 && overlapX(x.bbox) >= 0.8 * b.width : x.type === "table" && !ocrPage && _optionalChain([x, 'access', _395 => _395.table, 'optionalAccess', _396 => _396.cols]) === cr.table.cols && overlapX(x.bbox) >= 0.5 * Math.min(x.bbox.width, b.width)));
|
|
9571
9587
|
});
|
|
9572
9588
|
if (clusterResults.length > 0) {
|
|
9573
9589
|
const ciToIdx = /* @__PURE__ */ new Map();
|
|
@@ -9604,7 +9620,7 @@ function extractBlocksWithGrids(items, pageNum, pageWidth, pageHeight, grids, ho
|
|
|
9604
9620
|
groupSizes.push(1);
|
|
9605
9621
|
}
|
|
9606
9622
|
const allY = remaining.map((i) => i.y);
|
|
9607
|
-
const pageH =
|
|
9623
|
+
const pageH = _chunkC3BOYTY5cjs.safeMax.call(void 0, allY) - _chunkC3BOYTY5cjs.safeMin.call(void 0, allY);
|
|
9608
9624
|
const gapThreshold = Math.max(15, pageH * 0.03);
|
|
9609
9625
|
const sides = frameColumnTextBands(remaining, spanning, gx);
|
|
9610
9626
|
const textBlocks = [];
|
|
@@ -9620,7 +9636,7 @@ function extractBlocksWithGrids(items, pageNum, pageWidth, pageHeight, grids, ho
|
|
|
9620
9636
|
finalTextBlocks.push(...detectListBlocks(textBlocks));
|
|
9621
9637
|
} else {
|
|
9622
9638
|
const allY = remaining.map((i) => i.y);
|
|
9623
|
-
const pageH =
|
|
9639
|
+
const pageH = _chunkC3BOYTY5cjs.safeMax.call(void 0, allY) - _chunkC3BOYTY5cjs.safeMin.call(void 0, allY);
|
|
9624
9640
|
const gapThreshold = Math.max(15, pageH * 0.03);
|
|
9625
9641
|
const groups = xyCutOrder(remaining, gapThreshold);
|
|
9626
9642
|
const textBlocks = [];
|
|
@@ -9952,7 +9968,7 @@ function extractPageBlocksFallback(items, pageNum, fullPage = false, detectTable
|
|
|
9952
9968
|
blocks.push(...columnTextToBlocks(tableText, pageNum, bbox, dominantStyle(items)));
|
|
9953
9969
|
} else {
|
|
9954
9970
|
const allY = items.map((i) => i.y);
|
|
9955
|
-
const pageHeight =
|
|
9971
|
+
const pageHeight = _chunkC3BOYTY5cjs.safeMax.call(void 0, allY) - _chunkC3BOYTY5cjs.safeMin.call(void 0, allY);
|
|
9956
9972
|
const gapThreshold = Math.max(15, pageHeight * 0.03);
|
|
9957
9973
|
const orderedGroups = proseCutX !== null ? splitTwoColumnProse(items, proseCutX) : xyCutOrder(items, gapThreshold, 0, void 0, minGap);
|
|
9958
9974
|
for (const group of orderedGroups) {
|
|
@@ -9984,19 +10000,19 @@ function mergeOcrImageRegions(blocks, page, regions, ocrBlocks) {
|
|
|
9984
10000
|
const overlapH = Math.max(0, Math.min(b.y + b.height, region.y2) - Math.max(b.y, region.y1));
|
|
9985
10001
|
return overlapW * overlapH >= b.width * b.height * 0.8;
|
|
9986
10002
|
});
|
|
9987
|
-
const labels = candidates.filter((b) => b.type === "paragraph" && b.bbox.height <= 24 && (_nullishCoalesce(_optionalChain([b, 'access',
|
|
10003
|
+
const labels = candidates.filter((b) => b.type === "paragraph" && b.bbox.height <= 24 && (_nullishCoalesce(_optionalChain([b, 'access', _397 => _397.text, 'optionalAccess', _398 => _398.match, 'call', _399 => _399(/[\p{L}\p{N}]/gu), 'optionalAccess', _400 => _400.length]), () => ( 0))) >= 2);
|
|
9988
10004
|
const axisFragments = rotatedAxisFragments(candidates);
|
|
9989
10005
|
const accepted = candidates.filter((b) => {
|
|
9990
|
-
if (b.type === "paragraph") return (_nullishCoalesce(_optionalChain([b, 'access',
|
|
10006
|
+
if (b.type === "paragraph") return (_nullishCoalesce(_optionalChain([b, 'access', _401 => _401.text, 'optionalAccess', _402 => _402.match, 'call', _403 => _403(/[\p{L}\p{N}]/gu), 'optionalAccess', _404 => _404.length]), () => ( 0))) >= 2 || !axisFragments.has(b) && (supportedDiagramLabel(b, labels, region) || axisTick(b, candidates));
|
|
9991
10007
|
const t = b.table;
|
|
9992
10008
|
if (b.type !== "table" || !t || UNRULED_REGION_TABLES.has(b)) return false;
|
|
9993
10009
|
const lone = t.cells.filter((row) => row.filter((c) => c.text.trim()).length === 1 && row.some((c) => c.colSpan === t.cols)).length;
|
|
9994
10010
|
if (t.rows >= 2 && lone * 2 >= t.rows) return false;
|
|
9995
10011
|
if (t.rows === 1 && t.cols === 1) {
|
|
9996
|
-
const text = _nullishCoalesce(_optionalChain([t, 'access',
|
|
9997
|
-
return (_nullishCoalesce(_optionalChain([text, 'access',
|
|
10012
|
+
const text = _nullishCoalesce(_optionalChain([t, 'access', _405 => _405.cells, 'access', _406 => _406[0], 'optionalAccess', _407 => _407[0], 'optionalAccess', _408 => _408.text]), () => ( ""));
|
|
10013
|
+
return (_nullishCoalesce(_optionalChain([text, 'access', _409 => _409.match, 'call', _410 => _410(/\n/g), 'optionalAccess', _411 => _411.length]), () => ( 0))) >= 5 && (_nullishCoalesce(_optionalChain([text, 'access', _412 => _412.match, 'call', _413 => _413(/\d/g), 'optionalAccess', _414 => _414.length]), () => ( 0))) >= text.length * 0.25;
|
|
9998
10014
|
}
|
|
9999
|
-
const headerLabels = _nullishCoalesce(_optionalChain([t, 'access',
|
|
10015
|
+
const headerLabels = _nullishCoalesce(_optionalChain([t, 'access', _415 => _415.cells, 'access', _416 => _416[0], 'optionalAccess', _417 => _417.filter, 'call', _418 => _418((c) => c.text.replace(/[^A-Za-z가-힣]/g, "").length >= 2), 'access', _419 => _419.length]), () => ( 0));
|
|
10000
10016
|
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);
|
|
10001
10017
|
});
|
|
10002
10018
|
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, () => ( "")))) : []);
|
|
@@ -10013,14 +10029,14 @@ function mergeOcrImageRegions(blocks, page, regions, ocrBlocks) {
|
|
|
10013
10029
|
for (const block of selected) {
|
|
10014
10030
|
if (seen2.has(block)) continue;
|
|
10015
10031
|
const frame = FRAME_READING_UNITS.get(block);
|
|
10016
|
-
const source = _optionalChain([frame, 'optionalAccess',
|
|
10032
|
+
const source = _optionalChain([frame, 'optionalAccess', _420 => _420.blocks, 'access', _421 => _421.every, 'call', _422 => _422((member) => selectedSet.has(member))]) ? frame.blocks : [block];
|
|
10017
10033
|
source.forEach((member) => seen2.add(member));
|
|
10018
10034
|
const available = source.filter((member) => !hasOriginal(member));
|
|
10019
10035
|
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 }));
|
|
10020
10036
|
for (const unit of units) {
|
|
10021
10037
|
const b = unit.bbox;
|
|
10022
10038
|
const index = blocks.findIndex((existing) => {
|
|
10023
|
-
const e = _nullishCoalesce(_optionalChain([FRAME_READING_UNITS, 'access',
|
|
10039
|
+
const e = _nullishCoalesce(_optionalChain([FRAME_READING_UNITS, 'access', _423 => _423.get, 'call', _424 => _424(existing), 'optionalAccess', _425 => _425.bbox]), () => ( existing.bbox));
|
|
10024
10040
|
if (existing.pageNumber !== page || !e) return false;
|
|
10025
10041
|
const beside = e.y < region.y2 && e.y + e.height > region.y1 && e.x >= region.x2 - 1;
|
|
10026
10042
|
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;
|
|
@@ -10038,16 +10054,16 @@ function mergeOcrImageRegions(blocks, page, regions, ocrBlocks) {
|
|
|
10038
10054
|
}
|
|
10039
10055
|
function axisTick(block, candidates) {
|
|
10040
10056
|
const b = block.bbox;
|
|
10041
|
-
if (!/^\d$/u.test(_nullishCoalesce(_optionalChain([block, 'access',
|
|
10042
|
-
const numeric = candidates.filter((o) => o !== block && o.type === "paragraph" && o.bbox && /^[\d\s.,%+−-]+$/u.test(_nullishCoalesce(_optionalChain([o, 'access',
|
|
10057
|
+
if (!/^\d$/u.test(_nullishCoalesce(_optionalChain([block, 'access', _426 => _426.text, 'optionalAccess', _427 => _427.trim, 'call', _428 => _428()]), () => ( "")))) return false;
|
|
10058
|
+
const numeric = candidates.filter((o) => o !== block && o.type === "paragraph" && o.bbox && /^[\d\s.,%+−-]+$/u.test(_nullishCoalesce(_optionalChain([o, 'access', _429 => _429.text, 'optionalAccess', _430 => _430.trim, 'call', _431 => _431()]), () => ( ""))) && /\d/u.test(_nullishCoalesce(o.text, () => ( ""))) && Math.max(o.bbox.height, b.height) <= Math.min(o.bbox.height, b.height) * 2);
|
|
10043
10059
|
const cy = b.y + b.height / 2, right = b.x + b.width;
|
|
10044
10060
|
const row = numeric.filter((o) => Math.abs(o.bbox.y + o.bbox.height / 2 - cy) <= Math.min(o.bbox.height, b.height) * 0.35);
|
|
10045
10061
|
const column = numeric.filter((o) => Math.abs(o.bbox.x + o.bbox.width - right) <= Math.max(o.bbox.height, b.height) * 0.5);
|
|
10046
10062
|
return row.length >= 2 || column.length >= 2;
|
|
10047
10063
|
}
|
|
10048
10064
|
function supportedDiagramLabel(block, labels, region) {
|
|
10049
|
-
const b = block.bbox, text = _nullishCoalesce(_optionalChain([block, 'access',
|
|
10050
|
-
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',
|
|
10065
|
+
const b = block.bbox, text = _nullishCoalesce(_optionalChain([block, 'access', _432 => _432.text, 'optionalAccess', _433 => _433.trim, 'call', _434 => _434()]), () => ( ""));
|
|
10066
|
+
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', _435 => _435.text, 'optionalAccess', _436 => _436.match, 'call', _437 => _437(/\p{N}/gu), 'optionalAccess', _438 => _438.length]), () => ( 0))) >= 2).length < 2) return false;
|
|
10051
10067
|
let above = false, below = false;
|
|
10052
10068
|
for (const label of labels) {
|
|
10053
10069
|
const a = label.bbox, em = Math.max(b.height, a.height);
|
|
@@ -10062,7 +10078,7 @@ function rotatedAxisFragments(candidates) {
|
|
|
10062
10078
|
const paragraphs = candidates.filter((b) => b.type === "paragraph" && b.bbox.height <= 24);
|
|
10063
10079
|
const axes = [];
|
|
10064
10080
|
for (const block of paragraphs) {
|
|
10065
|
-
const b = block.bbox, text = _nullishCoalesce(_optionalChain([block, 'access',
|
|
10081
|
+
const b = block.bbox, text = _nullishCoalesce(_optionalChain([block, 'access', _439 => _439.text, 'optionalAccess', _440 => _440.trim, 'call', _441 => _441()]), () => ( ""));
|
|
10066
10082
|
if (!/^[\d\s.,%+−-]+$/u.test(text) || !/\d/u.test(text) || b.width > b.height * 6) continue;
|
|
10067
10083
|
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);
|
|
10068
10084
|
if (axis) axis.push(block);
|
|
@@ -10079,8 +10095,8 @@ function rotatedAxisFragments(candidates) {
|
|
|
10079
10095
|
const em = Math.max(...axis.map((a) => a.bbox.height)), right = axis[0].bbox.x + axis[0].bbox.width;
|
|
10080
10096
|
if (top - bottom < em * 6) continue;
|
|
10081
10097
|
const left = paragraphs.filter((block) => {
|
|
10082
|
-
const b = block.bbox, text = _nullishCoalesce(_optionalChain([block, 'access',
|
|
10083
|
-
return /\p{Script=Latin}/u.test(text) && (_nullishCoalesce(_optionalChain([text, 'access',
|
|
10098
|
+
const b = block.bbox, text = _nullishCoalesce(_optionalChain([block, 'access', _442 => _442.text, 'optionalAccess', _443 => _443.trim, 'call', _444 => _444()]), () => ( ""));
|
|
10099
|
+
return /\p{Script=Latin}/u.test(text) && (_nullishCoalesce(_optionalChain([text, 'access', _445 => _445.match, 'call', _446 => _446(/[\p{L}\p{N}]/gu), 'optionalAccess', _447 => _447.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;
|
|
10084
10100
|
});
|
|
10085
10101
|
const stack = left.filter((a) => left.some((b) => {
|
|
10086
10102
|
if (a === b || !aligned(a, b)) return false;
|
|
@@ -10090,7 +10106,7 @@ function rotatedAxisFragments(candidates) {
|
|
|
10090
10106
|
if (stack.length < 2) continue;
|
|
10091
10107
|
for (const block of paragraphs) {
|
|
10092
10108
|
const b = block.bbox;
|
|
10093
|
-
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',
|
|
10109
|
+
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', _448 => _448.text, 'optionalAccess', _449 => _449.trim, 'call', _450 => _450()]), () => ( ""))) && stack.some((s) => aligned(s, block))) fragments.add(block);
|
|
10094
10110
|
}
|
|
10095
10111
|
}
|
|
10096
10112
|
return fragments;
|
|
@@ -10191,4 +10207,4 @@ function rowParagraphs(block) {
|
|
|
10191
10207
|
|
|
10192
10208
|
|
|
10193
10209
|
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.grayCrop = grayCrop; exports.inkStats = inkStats; exports.splitRowBands = splitRowBands; exports.leadingTriangle = leadingTriangle; exports.leaderRuns = leaderRuns; exports.inkBounds = inkBounds; exports.bracketFeatures = bracketFeatures; exports.romanStems = romanStems; exports.circledAt = circledAt; exports.quoteHead = quoteHead; exports.edgeTrim = edgeTrim; exports.tallInkCount = tallInkCount; exports.gapGlyphs = gapGlyphs; exports.ringBullet = ringBullet; exports.dashRatio = dashRatio; exports.discAt = discAt; exports.serifOne = serifOne; exports.starRun = starRun; exports.bracketShape = bracketShape; exports.leadingBullet = leadingBullet; exports.rememberOcrTextGaps = rememberOcrTextGaps; exports.copyOcrTextGaps = copyOcrTextGaps; exports.findOcrTextGaps = findOcrTextGaps; 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;
|
|
10194
|
-
//# sourceMappingURL=chunk-
|
|
10210
|
+
//# sourceMappingURL=chunk-73MRAQXA.cjs.map
|