kordoc 4.21.13 → 4.21.15
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 +10 -6
- package/dist/{-4UPN43UD.js → -HYTPLFLG.js} +11 -11
- package/dist/{chunk-DI7WHDXG.js → chunk-5B5LMAUW.js} +2 -2
- package/dist/{chunk-QOIZF57S.js → chunk-65GJ2MMG.js} +2 -2
- package/dist/{chunk-HIUHLJQD.js → chunk-6CVYB634.js} +2 -2
- package/dist/{chunk-JGAY3BHY.js → chunk-7JCSAOTM.js} +3 -3
- package/dist/{chunk-LOO3UV25.cjs → chunk-AFDLKT76.cjs} +3 -3
- package/dist/{chunk-LOO3UV25.cjs.map → chunk-AFDLKT76.cjs.map} +1 -1
- package/dist/{chunk-V7LTELVS.cjs → chunk-B5WKFVQN.cjs} +3 -3
- package/dist/{chunk-V7LTELVS.cjs.map → chunk-B5WKFVQN.cjs.map} +1 -1
- package/dist/{chunk-DU2HC36X.cjs → chunk-CHQLIGVR.cjs} +169 -147
- package/dist/chunk-CHQLIGVR.cjs.map +1 -0
- package/dist/{chunk-N4UL5NEO.js → chunk-CRDBLQU5.js} +32 -10
- package/dist/chunk-CRDBLQU5.js.map +1 -0
- package/dist/{chunk-VC2SS3OH.js → chunk-ER3N3QPL.js} +2 -2
- package/dist/{chunk-VXNR2JYB.js → chunk-FGC3EEQD.js} +2 -2
- package/dist/{chunk-DAR2TMBL.js → chunk-HIXDQ43L.js} +10 -10
- package/dist/{chunk-K23A2CP7.js → chunk-IJK4VDEU.js} +2 -2
- package/dist/{chunk-FW7QWLBL.js → chunk-LYWRIUZY.js} +3 -3
- package/dist/{chunk-YM4AEOS4.js → chunk-M4LXFLAV.js} +2 -2
- package/dist/{chunk-LXYM2EST.js → chunk-NHMRAR3I.js} +2 -2
- package/dist/{chunk-JQBUWC6W.js → chunk-NUUFPRNE.js} +2 -2
- package/dist/{chunk-YJ4J6EG5.js → chunk-OUBHY6W3.js} +2 -2
- package/dist/{chunk-WPZOIIM2.cjs → chunk-Q2BKBY3O.cjs} +2 -2
- package/dist/{chunk-WPZOIIM2.cjs.map → chunk-Q2BKBY3O.cjs.map} +1 -1
- package/dist/{chunk-IS2EXA5D.cjs → chunk-QA5KN5IT.cjs} +6 -6
- package/dist/{chunk-IS2EXA5D.cjs.map → chunk-QA5KN5IT.cjs.map} +1 -1
- package/dist/{chunk-57EOUEB4.cjs → chunk-SJJQ47DB.cjs} +13 -13
- package/dist/{chunk-57EOUEB4.cjs.map → chunk-SJJQ47DB.cjs.map} +1 -1
- package/dist/{chunk-UAEY6VPV.js → chunk-SQFCH4AY.js} +6 -6
- package/dist/{chunk-NX5A22B6.js → chunk-TJQ7ME2Z.js} +2 -2
- package/dist/{chunk-FFBZG5MK.js → chunk-VFGH2R4P.js} +2 -2
- package/dist/{chunk-3YD3SAQW.js → chunk-VOSAGXM6.js} +31 -9
- package/dist/chunk-VOSAGXM6.js.map +1 -0
- package/dist/{chunk-RMMMNE2V.js → chunk-W6TVVTVX.js} +4 -4
- package/dist/{chunk-C7OK4MBX.js → chunk-Y64SVE5C.js} +3 -3
- package/dist/{chunk-HCCQTNDS.js → chunk-YE3LPTBT.js} +2 -2
- package/dist/{chunk-6EB77P5L.js → chunk-ZCGVIGG5.js} +2 -2
- package/dist/{chunk-B7CZZBKZ.js → chunk-ZTEBJBJK.js} +2 -2
- package/dist/chunks-JUOKYHXK.js +10 -0
- package/dist/cli.js +30 -30
- package/dist/{formula-BCWYXJPE.cjs → formula-H7CXHNLU.cjs} +9 -9
- package/dist/{formula-BCWYXJPE.cjs.map → formula-H7CXHNLU.cjs.map} +1 -1
- package/dist/{formula-ZFB6JGOW.js → formula-NC3C6E3I.js} +3 -3
- package/dist/{formula-N4TZPWWU.js → formula-Q4OWMNYI.js} +4 -4
- package/dist/{image-ocr-7YHK7Q4C.js → image-ocr-BGNLPWT6.js} +6 -6
- package/dist/{image-ocr-4Y23NCW4.js → image-ocr-DV5NNNZW.js} +9 -9
- package/dist/{image-ocr-RE7BFBGV.cjs → image-ocr-LEOMPCGS.cjs} +15 -15
- package/dist/{image-ocr-RE7BFBGV.cjs.map → image-ocr-LEOMPCGS.cjs.map} +1 -1
- package/dist/index.cjs +276 -276
- package/dist/index.js +5 -5
- package/dist/mcp.js +22 -22
- package/dist/{model-bundle-WISSN6YF.js → model-bundle-VW3V7DPG.js} +5 -5
- package/dist/{models-SG4VHU65.js → models-YYIPIE24.js} +5 -5
- package/dist/{parse-worker-v2-VNLAK2VC.js → parse-worker-v2-3LIIZE2T.js} +12 -12
- package/dist/{parser-VPVVJDB3.js → parser-2RDVYJPK.js} +269 -42
- package/dist/parser-2RDVYJPK.js.map +1 -0
- package/dist/{parser-KYZD3NNB.cjs → parser-4LF556NR.cjs} +446 -219
- package/dist/parser-4LF556NR.cjs.map +1 -0
- package/dist/{parser-V3R7TKU5.js → parser-FSHPAFTU.js} +272 -45
- package/dist/parser-FSHPAFTU.js.map +1 -0
- package/dist/pdf-ocr-BEZS6VHS.cjs +19 -0
- package/dist/{pdf-ocr-G2SX5FKB.cjs.map → pdf-ocr-BEZS6VHS.cjs.map} +1 -1
- package/dist/pdf-ocr-LCVFTHGX.js +18 -0
- package/dist/pdf-ocr-WSPAXWEX.js +22 -0
- package/dist/{profile-io-72YURUWT.js → profile-io-C376OP4V.js} +3 -3
- package/dist/{rasterize-UPE2IZLP.js → rasterize-SCFDD6GF.js} +3 -3
- package/dist/{redact-doc-GW6ILR52.js → redact-doc-3XDM4LNR.js} +11 -11
- package/dist/{render-2XLPO3ZA.js → render-FILMNF4B.js} +7 -7
- package/dist/seal-JJP72252.js +10 -0
- package/dist/{setup-GE4JKPHY.js → setup-KWXKE26M.js} +3 -3
- package/dist/visual-ESQJOYNZ.js +20 -0
- package/dist/{watch-XBVNOG6B.js → watch-D4GFLFAR.js} +12 -12
- package/package.json +1 -1
- package/dist/chunk-3YD3SAQW.js.map +0 -1
- package/dist/chunk-DU2HC36X.cjs.map +0 -1
- package/dist/chunk-N4UL5NEO.js.map +0 -1
- package/dist/chunks-A67IJS56.js +0 -10
- package/dist/parser-KYZD3NNB.cjs.map +0 -1
- package/dist/parser-V3R7TKU5.js.map +0 -1
- package/dist/parser-VPVVJDB3.js.map +0 -1
- package/dist/pdf-ocr-G2SX5FKB.cjs +0 -19
- package/dist/pdf-ocr-KNNBYXVO.js +0 -22
- package/dist/pdf-ocr-PP2GGLS3.js +0 -18
- package/dist/seal-VLJCGOP7.js +0 -10
- package/dist/visual-7NPMIPSC.js +0 -20
- /package/dist/{-4UPN43UD.js.map → -HYTPLFLG.js.map} +0 -0
- /package/dist/{chunk-DI7WHDXG.js.map → chunk-5B5LMAUW.js.map} +0 -0
- /package/dist/{chunk-QOIZF57S.js.map → chunk-65GJ2MMG.js.map} +0 -0
- /package/dist/{chunk-HIUHLJQD.js.map → chunk-6CVYB634.js.map} +0 -0
- /package/dist/{chunk-JGAY3BHY.js.map → chunk-7JCSAOTM.js.map} +0 -0
- /package/dist/{chunk-VC2SS3OH.js.map → chunk-ER3N3QPL.js.map} +0 -0
- /package/dist/{chunk-VXNR2JYB.js.map → chunk-FGC3EEQD.js.map} +0 -0
- /package/dist/{chunk-DAR2TMBL.js.map → chunk-HIXDQ43L.js.map} +0 -0
- /package/dist/{chunk-K23A2CP7.js.map → chunk-IJK4VDEU.js.map} +0 -0
- /package/dist/{chunk-FW7QWLBL.js.map → chunk-LYWRIUZY.js.map} +0 -0
- /package/dist/{chunk-YM4AEOS4.js.map → chunk-M4LXFLAV.js.map} +0 -0
- /package/dist/{chunk-LXYM2EST.js.map → chunk-NHMRAR3I.js.map} +0 -0
- /package/dist/{chunk-JQBUWC6W.js.map → chunk-NUUFPRNE.js.map} +0 -0
- /package/dist/{chunk-YJ4J6EG5.js.map → chunk-OUBHY6W3.js.map} +0 -0
- /package/dist/{chunk-UAEY6VPV.js.map → chunk-SQFCH4AY.js.map} +0 -0
- /package/dist/{chunk-NX5A22B6.js.map → chunk-TJQ7ME2Z.js.map} +0 -0
- /package/dist/{chunk-FFBZG5MK.js.map → chunk-VFGH2R4P.js.map} +0 -0
- /package/dist/{chunk-RMMMNE2V.js.map → chunk-W6TVVTVX.js.map} +0 -0
- /package/dist/{chunk-C7OK4MBX.js.map → chunk-Y64SVE5C.js.map} +0 -0
- /package/dist/{chunk-HCCQTNDS.js.map → chunk-YE3LPTBT.js.map} +0 -0
- /package/dist/{chunk-6EB77P5L.js.map → chunk-ZCGVIGG5.js.map} +0 -0
- /package/dist/{chunk-B7CZZBKZ.js.map → chunk-ZTEBJBJK.js.map} +0 -0
- /package/dist/{chunks-A67IJS56.js.map → chunks-JUOKYHXK.js.map} +0 -0
- /package/dist/{formula-ZFB6JGOW.js.map → formula-NC3C6E3I.js.map} +0 -0
- /package/dist/{formula-N4TZPWWU.js.map → formula-Q4OWMNYI.js.map} +0 -0
- /package/dist/{image-ocr-7YHK7Q4C.js.map → image-ocr-BGNLPWT6.js.map} +0 -0
- /package/dist/{image-ocr-4Y23NCW4.js.map → image-ocr-DV5NNNZW.js.map} +0 -0
- /package/dist/{model-bundle-WISSN6YF.js.map → model-bundle-VW3V7DPG.js.map} +0 -0
- /package/dist/{models-SG4VHU65.js.map → models-YYIPIE24.js.map} +0 -0
- /package/dist/{parse-worker-v2-VNLAK2VC.js.map → parse-worker-v2-3LIIZE2T.js.map} +0 -0
- /package/dist/{pdf-ocr-KNNBYXVO.js.map → pdf-ocr-LCVFTHGX.js.map} +0 -0
- /package/dist/{pdf-ocr-PP2GGLS3.js.map → pdf-ocr-WSPAXWEX.js.map} +0 -0
- /package/dist/{profile-io-72YURUWT.js.map → profile-io-C376OP4V.js.map} +0 -0
- /package/dist/{rasterize-UPE2IZLP.js.map → rasterize-SCFDD6GF.js.map} +0 -0
- /package/dist/{redact-doc-GW6ILR52.js.map → redact-doc-3XDM4LNR.js.map} +0 -0
- /package/dist/{render-2XLPO3ZA.js.map → render-FILMNF4B.js.map} +0 -0
- /package/dist/{seal-VLJCGOP7.js.map → seal-JJP72252.js.map} +0 -0
- /package/dist/{setup-GE4JKPHY.js.map → setup-KWXKE26M.js.map} +0 -0
- /package/dist/{visual-7NPMIPSC.js.map → visual-ESQJOYNZ.js.map} +0 -0
- /package/dist/{watch-XBVNOG6B.js.map → watch-D4GFLFAR.js.map} +0 -0
|
@@ -4,15 +4,15 @@
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
var
|
|
7
|
+
var _chunkQA5KN5ITcjs = require('./chunk-QA5KN5IT.cjs');
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
|
|
11
|
-
var
|
|
11
|
+
var _chunkB5WKFVQNcjs = require('./chunk-B5WKFVQN.cjs');
|
|
12
12
|
|
|
13
13
|
|
|
14
14
|
|
|
15
|
-
var
|
|
15
|
+
var _chunkQ2BKBY3Ocjs = require('./chunk-Q2BKBY3O.cjs');
|
|
16
16
|
|
|
17
17
|
// src/ocr/models.ts
|
|
18
18
|
var _path = require('path');
|
|
@@ -40,10 +40,10 @@ var OCR_REC_DICT = {
|
|
|
40
40
|
};
|
|
41
41
|
var ALL_OCR_MODELS = [OCR_DET_MODEL, OCR_REC_MODEL, OCR_REC_DICT];
|
|
42
42
|
function getOcrModelsDir() {
|
|
43
|
-
return
|
|
43
|
+
return _chunkB5WKFVQNcjs.getModelsDir.call(void 0, "ppocr");
|
|
44
44
|
}
|
|
45
45
|
async function ensureOcrModels(onProgress) {
|
|
46
|
-
return
|
|
46
|
+
return _chunkB5WKFVQNcjs.ensureModelsIn.call(void 0, getOcrModelsDir(), ALL_OCR_MODELS, onProgress);
|
|
47
47
|
}
|
|
48
48
|
async function ocrModelsCached() {
|
|
49
49
|
const dir = getOcrModelsDir();
|
|
@@ -2123,7 +2123,7 @@ function tagScripts(text, lines) {
|
|
|
2123
2123
|
const [s, e, kind] = marks[m];
|
|
2124
2124
|
out = out.slice(0, s) + `<${kind}>` + out.slice(s, e) + `</${kind}>` + out.slice(e);
|
|
2125
2125
|
}
|
|
2126
|
-
return
|
|
2126
|
+
return _chunkQA5KN5ITcjs.tidyScriptTags.call(void 0, out);
|
|
2127
2127
|
}
|
|
2128
2128
|
|
|
2129
2129
|
// src/pdf/line-wrap.ts
|
|
@@ -2617,7 +2617,8 @@ function cellTextToString(items, wrap) {
|
|
|
2617
2617
|
const pad = Math.min(6, Math.max(0, contentLeft - wrap.box.x1), Math.max(0, wrap.box.x2 - cellRight));
|
|
2618
2618
|
const inner = wrap.box.x2 - wrap.box.x1 - 2 * pad;
|
|
2619
2619
|
const wide = lineEnds.slice(0, -1).map((a, i) => a.right - a.left + 1.5 * lineEnds[i + 1].firstCharW > inner);
|
|
2620
|
-
|
|
2620
|
+
const spaced = merged.map((s) => !!s[s.length - 1].spaceAfter);
|
|
2621
|
+
return scripted(mergeCellTextLines(textLines, { wraps, lex: wrap.lex, wide, spaced }));
|
|
2621
2622
|
}
|
|
2622
2623
|
function mergeSuperscriptRows(lines) {
|
|
2623
2624
|
if (lines.length <= 1) return lines;
|
|
@@ -2724,7 +2725,7 @@ function mergeCellTextLines(textLines, wrap) {
|
|
|
2724
2725
|
for (let i = 1; i < textLines.length; i++) {
|
|
2725
2726
|
const prev = merged[merged.length - 1];
|
|
2726
2727
|
const curr = textLines[i];
|
|
2727
|
-
if (wrap ? wrap.wraps[i - 1] && !startsNewItem(prev, curr) && wrapJoiner(prev, curr, wrap.lex, false) === "" : /[가-힣]$/.test(prev) && /^[가-힣]+$/.test(curr) && curr.length <= 8 && !curr.includes(" ")) {
|
|
2728
|
+
if (wrap ? wrap.wraps[i - 1] && !_optionalChain([wrap, 'access', _83 => _83.spaced, 'optionalAccess', _84 => _84[i - 1]]) && !startsNewItem(prev, curr) && wrapJoiner(prev, curr, wrap.lex, false) === "" : /[가-힣]$/.test(prev) && /^[가-힣]+$/.test(curr) && curr.length <= 8 && !curr.includes(" ")) {
|
|
2728
2729
|
merged[merged.length - 1] = prev + curr;
|
|
2729
2730
|
} else if (curr.trim().length <= 3 && /^[)\]%}]/.test(curr.trim())) {
|
|
2730
2731
|
merged[merged.length - 1] = prev + curr.trim();
|
|
@@ -2802,7 +2803,7 @@ function normalizeUndersegmentedTable(originalCells, colXs, items, rowYs) {
|
|
|
2802
2803
|
if (numRows > MAX_UNDERSEGMENTED_ROWS || numCols < MIN_UNDERSEGMENTED_COLUMNS) return null;
|
|
2803
2804
|
if (items.length === 0) return null;
|
|
2804
2805
|
if (numRows >= 3) {
|
|
2805
|
-
if (_optionalChain([rowYs, 'optionalAccess',
|
|
2806
|
+
if (_optionalChain([rowYs, 'optionalAccess', _85 => _85.length]) !== numRows + 1) return null;
|
|
2806
2807
|
const rebuilt2 = [];
|
|
2807
2808
|
let expanded = 0;
|
|
2808
2809
|
for (let r = 0; r < numRows; r++) {
|
|
@@ -2955,7 +2956,7 @@ function dominantStyle(items) {
|
|
|
2955
2956
|
let maxCount = 0, dominantSize = 0;
|
|
2956
2957
|
for (const i of items) {
|
|
2957
2958
|
if (i.fontSize <= 0) continue;
|
|
2958
|
-
const count = (freq.get(i.fontSize) || 0) + Math.max(1, _nullishCoalesce(_optionalChain([i, 'access',
|
|
2959
|
+
const count = (freq.get(i.fontSize) || 0) + Math.max(1, _nullishCoalesce(_optionalChain([i, 'access', _86 => _86.text, 'access', _87 => _87.match, 'call', _88 => _88(/[\p{L}\p{N}]/gu), 'optionalAccess', _89 => _89.length]), () => ( 0)));
|
|
2959
2960
|
freq.set(i.fontSize, count);
|
|
2960
2961
|
if (count > maxCount) {
|
|
2961
2962
|
maxCount = count;
|
|
@@ -2963,7 +2964,7 @@ function dominantStyle(items) {
|
|
|
2963
2964
|
}
|
|
2964
2965
|
}
|
|
2965
2966
|
if (dominantSize === 0) return void 0;
|
|
2966
|
-
const fontName = _optionalChain([items, 'access',
|
|
2967
|
+
const fontName = _optionalChain([items, 'access', _90 => _90.find, 'call', _91 => _91((i) => i.fontSize === dominantSize), 'optionalAccess', _92 => _92.fontName]) || void 0;
|
|
2967
2968
|
return fontName ? { fontSize: dominantSize, fontName } : { fontSize: dominantSize };
|
|
2968
2969
|
}
|
|
2969
2970
|
function normalizeItems(rawItems) {
|
|
@@ -2996,9 +2997,21 @@ function normalizeItems(rawItems) {
|
|
|
2996
2997
|
if (fontSize >= 14 && /^[A-Z0-9?!&'’](?: [A-Z0-9?!&'’]){2,}$/.test(text)) text = text.replace(/ /g, "");
|
|
2997
2998
|
const turned = Math.abs(i.transform[1]) > Math.abs(i.transform[0]) * 4;
|
|
2998
2999
|
const split = turned ? null : splitEvenSpacedItem(text, x, w, fontSize);
|
|
3000
|
+
const spaceAfter = i.spaceAfter;
|
|
2999
3001
|
if (split) {
|
|
3000
3002
|
split.forEach((s, k) => {
|
|
3001
|
-
items.push({
|
|
3003
|
+
items.push({
|
|
3004
|
+
text: s.text,
|
|
3005
|
+
x: s.x,
|
|
3006
|
+
y,
|
|
3007
|
+
w: s.w,
|
|
3008
|
+
h,
|
|
3009
|
+
fontSize,
|
|
3010
|
+
fontName: i.fontName || "",
|
|
3011
|
+
isHidden,
|
|
3012
|
+
seq: seq + k / 1e3,
|
|
3013
|
+
...spaceAfter && k === split.length - 1 ? { spaceAfter } : {}
|
|
3014
|
+
});
|
|
3002
3015
|
});
|
|
3003
3016
|
} else {
|
|
3004
3017
|
const rotated = Math.abs(i.transform[1]) > Math.abs(i.transform[0]) * 4;
|
|
@@ -3014,6 +3027,7 @@ function normalizeItems(rawItems) {
|
|
|
3014
3027
|
fontName: i.fontName || "",
|
|
3015
3028
|
isHidden,
|
|
3016
3029
|
seq,
|
|
3030
|
+
...spaceAfter ? { spaceAfter } : {},
|
|
3017
3031
|
...rotated ? { rotated: Math.max(1, w), ...i.transform[1] < 0 ? { rotatedDown: true } : {} } : {}
|
|
3018
3032
|
});
|
|
3019
3033
|
}
|
|
@@ -3095,7 +3109,7 @@ function splitAroundOverlays(c, overlays) {
|
|
|
3095
3109
|
const ov = overlays.filter((o) => {
|
|
3096
3110
|
for (let at = c.text.indexOf(o.text); at >= 0; at = c.text.indexOf(o.text, at + 1)) {
|
|
3097
3111
|
const prefix = c.text.slice(0, at);
|
|
3098
|
-
const est = c.x + glyphUnits(prefix.replace(/\s+/g, "")) * a0 + (_nullishCoalesce(_optionalChain([prefix, 'access',
|
|
3112
|
+
const est = c.x + glyphUnits(prefix.replace(/\s+/g, "")) * a0 + (_nullishCoalesce(_optionalChain([prefix, 'access', _93 => _93.match, 'call', _94 => _94(/\s+/g), 'optionalAccess', _95 => _95.length]), () => ( 0))) * ws;
|
|
3099
3113
|
if (Math.abs(est - o.x) <= OVERLAY_DUP_EM * fs) return false;
|
|
3100
3114
|
}
|
|
3101
3115
|
return true;
|
|
@@ -3220,7 +3234,7 @@ function mergeSuperscriptLines(lines) {
|
|
|
3220
3234
|
return result;
|
|
3221
3235
|
}
|
|
3222
3236
|
function mergeLineSimple(items) {
|
|
3223
|
-
if (items.length <= 1) return _optionalChain([items, 'access',
|
|
3237
|
+
if (items.length <= 1) return _optionalChain([items, 'access', _96 => _96[0], 'optionalAccess', _97 => _97.text]) || "";
|
|
3224
3238
|
const sorted = sortLineByX([...items]);
|
|
3225
3239
|
const isEvenSpaced = detectEvenSpacedItems(sorted);
|
|
3226
3240
|
let result = sorted[0].text;
|
|
@@ -3308,7 +3322,7 @@ function isProseTable(table) {
|
|
|
3308
3322
|
if (!(long > 0 && long >= total * 0.5 && longRows >= rows * 0.4)) return false;
|
|
3309
3323
|
for (let c = 0; c < table.cols; c++) {
|
|
3310
3324
|
const filled = table.cells.map((row) => row[c]).filter((cell) => cell && cell.colSpan < table.cols && cell.text.trim()).map((cell) => cell.text.trim());
|
|
3311
|
-
if (filled.length >= 3 && filled.length >= rows * 0.6 && filled.every((text) => text.length <= 30 && (_nullishCoalesce(_optionalChain([text, 'access',
|
|
3325
|
+
if (filled.length >= 3 && filled.length >= rows * 0.6 && filled.every((text) => text.length <= 30 && (_nullishCoalesce(_optionalChain([text, 'access', _98 => _98.match, 'call', _99 => _99(/\p{L}/gu), 'optionalAccess', _100 => _100.length]), () => ( 0))) >= 2)) return false;
|
|
3312
3326
|
}
|
|
3313
3327
|
return true;
|
|
3314
3328
|
}
|
|
@@ -3337,7 +3351,7 @@ var TICK = /^-?[\d,]+(?:\.\d+)?%?$/;
|
|
|
3337
3351
|
var QUANTITY = /^[-−–]?[\d,]*\.?\d+%?$/;
|
|
3338
3352
|
var quantity = (token) => Number(token.replace(/^[−–]/, "-").replace(/[,%]/g, ""));
|
|
3339
3353
|
function isValueAxisColumn(table, c) {
|
|
3340
|
-
const lines = table.cells.flatMap((row) => (_nullishCoalesce(_optionalChain([row, 'access',
|
|
3354
|
+
const lines = table.cells.flatMap((row) => (_nullishCoalesce(_optionalChain([row, 'access', _101 => _101[c], 'optionalAccess', _102 => _102.text]), () => ( ""))).split("\n").map((line) => line.trim().split(/\s+/)));
|
|
3341
3355
|
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));
|
|
3342
3356
|
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)]) {
|
|
3343
3357
|
const run = fallingRun(ticks);
|
|
@@ -3369,7 +3383,7 @@ function isChartTable(table, ocr = false) {
|
|
|
3369
3383
|
const numeric = texts.filter((text) => NUMERIC_CELL.test(text)).length;
|
|
3370
3384
|
if (numeric < texts.length * 0.5) return false;
|
|
3371
3385
|
for (let c = 0; c < table.cols; c++) {
|
|
3372
|
-
if (!ocr ? isValueAxisColumn(table, c) : hasValueAxis(table.cells.flatMap((row) => (_nullishCoalesce(_optionalChain([row, 'access',
|
|
3386
|
+
if (!ocr ? isValueAxisColumn(table, c) : hasValueAxis(table.cells.flatMap((row) => (_nullishCoalesce(_optionalChain([row, 'access', _103 => _103[c], 'optionalAccess', _104 => _104.text]), () => ( ""))).split(/\s+/)).filter((t) => TICK.test(t)).map((t) => Number(t.replace(/[,%]/g, ""))))) return true;
|
|
3373
3387
|
}
|
|
3374
3388
|
const values = texts.filter((text) => text.split(/\s+/).every((token) => QUANTITY.test(token))).length;
|
|
3375
3389
|
const cells = table.rows * table.cols;
|
|
@@ -3590,7 +3604,7 @@ function detectAlignedTwoColumnTables(rows, pageNum) {
|
|
|
3590
3604
|
continue;
|
|
3591
3605
|
}
|
|
3592
3606
|
const top = rows[i - 1];
|
|
3593
|
-
const title = _optionalChain([top, 'optionalAccess',
|
|
3607
|
+
const title = _optionalChain([top, 'optionalAccess', _105 => _105.items, 'access', _106 => _106.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;
|
|
3594
3608
|
const tableRows = title ? [title, ...body] : body;
|
|
3595
3609
|
const cells = tableRows.map((row, idx) => {
|
|
3596
3610
|
if (title && idx === 0) return [{ text: row.items[0].text, colSpan: 2, rowSpan: 1 }, { text: "", colSpan: 1, rowSpan: 1 }];
|
|
@@ -3646,12 +3660,12 @@ function isTwoColumnProse(r) {
|
|
|
3646
3660
|
if (t.rows < 8) return false;
|
|
3647
3661
|
const dense = [];
|
|
3648
3662
|
for (let c = 0; c < t.cols; c++) {
|
|
3649
|
-
const filled = t.cells.filter((row) => _optionalChain([row, 'access',
|
|
3663
|
+
const filled = t.cells.filter((row) => _optionalChain([row, 'access', _107 => _107[c], 'optionalAccess', _108 => _108.text, 'access', _109 => _109.trim, 'call', _110 => _110()])).length;
|
|
3650
3664
|
if (filled / t.rows >= 0.3) dense.push(c);
|
|
3651
3665
|
}
|
|
3652
3666
|
if (dense.length !== 2) return false;
|
|
3653
3667
|
for (const c of dense) {
|
|
3654
|
-
const lens = t.cells.map((row) => _nullishCoalesce(_optionalChain([row, 'access',
|
|
3668
|
+
const lens = t.cells.map((row) => _nullishCoalesce(_optionalChain([row, 'access', _111 => _111[c], 'optionalAccess', _112 => _112.text, 'access', _113 => _113.replace, 'call', _114 => _114(/\s+/g, ""), 'access', _115 => _115.length]), () => ( 0))).filter((n) => n > 0);
|
|
3655
3669
|
const avg = lens.reduce((s, v) => s + v, 0) / (lens.length || 1);
|
|
3656
3670
|
if (avg < 12) return false;
|
|
3657
3671
|
}
|
|
@@ -4065,7 +4079,7 @@ function assignRowItems(items, columns, numCols, headerFace) {
|
|
|
4065
4079
|
const runs = [];
|
|
4066
4080
|
for (const it of sorted) {
|
|
4067
4081
|
const last = runs[runs.length - 1];
|
|
4068
|
-
const prev = _optionalChain([last, 'optionalAccess',
|
|
4082
|
+
const prev = _optionalChain([last, 'optionalAccess', _116 => _116[last.length - 1]]);
|
|
4069
4083
|
if (prev && it.x - (prev.x + prev.w) <= Math.max(0.5, it.fontSize * 0.05) && !it.hasSpaceBefore) last.push(it);
|
|
4070
4084
|
else runs.push([it]);
|
|
4071
4085
|
}
|
|
@@ -4139,7 +4153,7 @@ function buildClusterTable(rows, columns, pageNum) {
|
|
|
4139
4153
|
() => Array.from({ length: numCols }, () => ({ text: "", colSpan: 1, rowSpan: 1 }))
|
|
4140
4154
|
);
|
|
4141
4155
|
const usedItems = /* @__PURE__ */ new Set();
|
|
4142
|
-
const headFaces = new Set(_optionalChain([rows, 'access',
|
|
4156
|
+
const headFaces = new Set(_optionalChain([rows, 'access', _117 => _117[0], 'optionalAccess', _118 => _118.items, 'access', _119 => _119.map, 'call', _120 => _120((i) => i.fontName)]));
|
|
4143
4157
|
const headerFace = headFaces.size === 1 && rows.slice(1).every((row) => row.items.every((i) => !headFaces.has(i.fontName))) ? [...headFaces][0] : void 0;
|
|
4144
4158
|
for (let r = 0; r < numRows; r++) {
|
|
4145
4159
|
const row = rows[r];
|
|
@@ -4169,7 +4183,7 @@ function buildClusterTable(rows, columns, pageNum) {
|
|
|
4169
4183
|
const nonEmptyCols = cells[r].filter((c) => c.text.trim()).length;
|
|
4170
4184
|
if (nonEmptyCols !== 1) continue;
|
|
4171
4185
|
if (cells[r][0].text.trim() !== "") continue;
|
|
4172
|
-
const contentText = _optionalChain([cells, 'access',
|
|
4186
|
+
const contentText = _optionalChain([cells, 'access', _121 => _121[r], 'access', _122 => _122.find, 'call', _123 => _123((c) => c.text.trim()), 'optionalAccess', _124 => _124.text, 'access', _125 => _125.trim, 'call', _126 => _126()]) || "";
|
|
4173
4187
|
if (/^[○●▶\-·]/.test(contentText)) continue;
|
|
4174
4188
|
for (let pr = r - 1; pr >= 0; pr--) {
|
|
4175
4189
|
if (cells[pr].some((c) => c.text.trim())) {
|
|
@@ -4370,7 +4384,8 @@ function topTableBand(items) {
|
|
|
4370
4384
|
fontSize: i.fontSize,
|
|
4371
4385
|
fontName: i.fontName,
|
|
4372
4386
|
hasSpaceBefore: i.hasSpaceBefore,
|
|
4373
|
-
syntheticSpace: i.syntheticSpace
|
|
4387
|
+
syntheticSpace: i.syntheticSpace,
|
|
4388
|
+
spaceAfter: i.spaceAfter
|
|
4374
4389
|
})), 1);
|
|
4375
4390
|
if (!candidate.some((t) => t.table.cols >= 3 && t.table.rows >= 3 && t.usedItems.size >= top.length * 0.75)) continue;
|
|
4376
4391
|
return { top, rest: lines.slice(n).flat() };
|
|
@@ -4424,7 +4439,7 @@ function stackedTableBands(items) {
|
|
|
4424
4439
|
const caption = (start, end) => lines.slice(start, end).some((line) => /^Table\s+\d+\s*[:.]/i.test(mergeLineSimple(line).trim()));
|
|
4425
4440
|
while (runs.length > 0 && !caption(runs[runs.length - 1].end, lines.length)) runs.pop();
|
|
4426
4441
|
if (runs.length < 2) return null;
|
|
4427
|
-
if (runs.some((run, i) => !caption(run.end, _nullishCoalesce(_optionalChain([runs, 'access',
|
|
4442
|
+
if (runs.some((run, i) => !caption(run.end, _nullishCoalesce(_optionalChain([runs, 'access', _127 => _127[i + 1], 'optionalAccess', _128 => _128.start]), () => ( lines.length))))) return null;
|
|
4428
4443
|
const tables = runs.map((run) => lines.slice(run.start, run.end).flat());
|
|
4429
4444
|
const between = runs.slice(0, -1).map((run, i) => lines.slice(run.end, runs[i + 1].start).flat());
|
|
4430
4445
|
const tail = lines.slice(runs[runs.length - 1].end);
|
|
@@ -4692,7 +4707,7 @@ function splitTrailingColumnRegion(items) {
|
|
|
4692
4707
|
}
|
|
4693
4708
|
function panelBlocks(items, panel, pageNum) {
|
|
4694
4709
|
const lines = groupByY([...items].sort((a, b) => b.y - a.y || a.x - b.x));
|
|
4695
|
-
const faceOf = (line) => _nullishCoalesce(_optionalChain([dominantStyle, 'call',
|
|
4710
|
+
const faceOf = (line) => _nullishCoalesce(_optionalChain([dominantStyle, 'call', _129 => _129(line), 'optionalAccess', _130 => _130.fontName]), () => ( ""));
|
|
4696
4711
|
const runs = [];
|
|
4697
4712
|
for (const line of lines) {
|
|
4698
4713
|
const last = runs[runs.length - 1];
|
|
@@ -4874,7 +4889,7 @@ function validWrapBands(items, bands) {
|
|
|
4874
4889
|
}
|
|
4875
4890
|
function inheritedWrapBands(items) {
|
|
4876
4891
|
const source = XY_WRAP_ITEMS.get(items[0]);
|
|
4877
|
-
const present = _optionalChain([source, 'optionalAccess',
|
|
4892
|
+
const present = _optionalChain([source, 'optionalAccess', _131 => _131.length]) === items.length ? new Set(items) : null;
|
|
4878
4893
|
const sameLeaf = present && source.every((item) => present.has(item));
|
|
4879
4894
|
return sameLeaf ? validWrapBands(items, _nullishCoalesce(XY_WRAP_BANDS.get(items[0]), () => ( []))) : [];
|
|
4880
4895
|
}
|
|
@@ -4913,7 +4928,7 @@ function wrappedLineBands(items, inherited) {
|
|
|
4913
4928
|
left: box.x,
|
|
4914
4929
|
right: box.x + box.width,
|
|
4915
4930
|
y: row.reduce((n, i) => n + i.y, 0) / row.length,
|
|
4916
|
-
fontSize: _nullishCoalesce(_optionalChain([dominantStyle, 'call',
|
|
4931
|
+
fontSize: _nullishCoalesce(_optionalChain([dominantStyle, 'call', _132 => _132(row), 'optionalAccess', _133 => _133.fontSize]), () => ( 0)),
|
|
4917
4932
|
sources: row.map((item) => ({ item, state: { ...item } }))
|
|
4918
4933
|
};
|
|
4919
4934
|
});
|
|
@@ -5049,10 +5064,10 @@ function pushLineParagraphs(out, yLines, pageNum, lex) {
|
|
|
5049
5064
|
const lines = attachDropCaps(yLines).map((items) => ({ items, text: mergeLineSimple(items) })).filter((l) => l.text.trim());
|
|
5050
5065
|
const geo = lines.map((l) => {
|
|
5051
5066
|
const b = computeBBox(l.items, pageNum);
|
|
5052
|
-
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',
|
|
5067
|
+
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', _134 => _134(l.items), 'optionalAccess', _135 => _135.fontSize]), () => ( 0)) };
|
|
5053
5068
|
});
|
|
5054
5069
|
const joins = bodyLineJoins(geo, lex);
|
|
5055
|
-
const first = _optionalChain([lines, 'access',
|
|
5070
|
+
const first = _optionalChain([lines, 'access', _136 => _136[0], 'optionalAccess', _137 => _137.items, 'access', _138 => _138[0]]);
|
|
5056
5071
|
const bands = first ? _nullishCoalesce(XY_WRAP_BANDS.get(first), () => ( [])) : [];
|
|
5057
5072
|
const hasBand = (top, bottom) => {
|
|
5058
5073
|
let lo = 0, hi = bands.length;
|
|
@@ -5071,6 +5086,9 @@ function pushLineParagraphs(out, yLines, pageNum, lex) {
|
|
|
5071
5086
|
joins[i] = wrapJoiner(geo[i].text, geo[i + 1].text, lex);
|
|
5072
5087
|
}
|
|
5073
5088
|
}
|
|
5089
|
+
for (let i = 0; i + 1 < lines.length; i++) {
|
|
5090
|
+
if (joins[i] === "" && lines[i].items.reduce((a, b) => b.x + b.w > a.x + a.w ? b : a).spaceAfter) joins[i] = " ";
|
|
5091
|
+
}
|
|
5074
5092
|
for (const i of tocRecordBoundaries(lines.map((line) => line.items))) joins[i] = "\n";
|
|
5075
5093
|
for (let i = 0; i + 1 < geo.length; i++) {
|
|
5076
5094
|
if (/^\d{1,2}$/.test(geo[i].text.trim()) && geo[i].fontSize >= geo[i + 1].fontSize * 1.2) joins[i] = "\n";
|
|
@@ -5118,15 +5136,15 @@ function computeMedianFontSizeFromFreq(freq) {
|
|
|
5118
5136
|
function detectHeadings(blocks, medianFontSize) {
|
|
5119
5137
|
for (let bi = 0; bi < blocks.length; bi++) {
|
|
5120
5138
|
const block = blocks[bi];
|
|
5121
|
-
if (block.type !== "paragraph" || !block.text || !_optionalChain([block, 'access',
|
|
5139
|
+
if (block.type !== "paragraph" || !block.text || !_optionalChain([block, 'access', _139 => _139.style, 'optionalAccess', _140 => _140.fontSize])) continue;
|
|
5122
5140
|
const text = block.text.trim();
|
|
5123
5141
|
if (text.length === 0 || text.length > 200) continue;
|
|
5124
5142
|
if (/^\d+$/.test(text) && !isChapterNumber(block, blocks[bi + 1], medianFontSize)) continue;
|
|
5125
5143
|
const ratio = block.style.fontSize / medianFontSize;
|
|
5126
5144
|
let level = 0;
|
|
5127
|
-
if (ratio >=
|
|
5128
|
-
else if (ratio >=
|
|
5129
|
-
else if (ratio >=
|
|
5145
|
+
if (ratio >= _chunkQA5KN5ITcjs.HEADING_RATIO_H1) level = 1;
|
|
5146
|
+
else if (ratio >= _chunkQA5KN5ITcjs.HEADING_RATIO_H2) level = 2;
|
|
5147
|
+
else if (ratio >= _chunkQA5KN5ITcjs.HEADING_RATIO_H3) level = 3;
|
|
5130
5148
|
if (level > 0) {
|
|
5131
5149
|
block.type = "heading";
|
|
5132
5150
|
block.level = level;
|
|
@@ -5135,21 +5153,21 @@ function detectHeadings(blocks, medianFontSize) {
|
|
|
5135
5153
|
}
|
|
5136
5154
|
}
|
|
5137
5155
|
function isChapterNumber(block, next, medianFontSize) {
|
|
5138
|
-
const size = _nullishCoalesce(_optionalChain([block, 'access',
|
|
5139
|
-
const nextSize = _nullishCoalesce(_optionalChain([next, 'optionalAccess',
|
|
5140
|
-
const text = _nullishCoalesce(_optionalChain([next, 'optionalAccess',
|
|
5141
|
-
const a = block.bbox, b = _optionalChain([next, 'optionalAccess',
|
|
5142
|
-
return /^\d{1,2}$/.test(_nullishCoalesce(_optionalChain([block, 'access',
|
|
5156
|
+
const size = _nullishCoalesce(_optionalChain([block, 'access', _141 => _141.style, 'optionalAccess', _142 => _142.fontSize]), () => ( 0));
|
|
5157
|
+
const nextSize = _nullishCoalesce(_optionalChain([next, 'optionalAccess', _143 => _143.style, 'optionalAccess', _144 => _144.fontSize]), () => ( 0));
|
|
5158
|
+
const text = _nullishCoalesce(_optionalChain([next, 'optionalAccess', _145 => _145.text, 'optionalAccess', _146 => _146.trim, 'call', _147 => _147()]), () => ( ""));
|
|
5159
|
+
const a = block.bbox, b = _optionalChain([next, 'optionalAccess', _148 => _148.bbox]);
|
|
5160
|
+
return /^\d{1,2}$/.test(_nullishCoalesce(_optionalChain([block, 'access', _149 => _149.text, 'optionalAccess', _150 => _150.trim, 'call', _151 => _151()]), () => ( ""))) && size >= medianFontSize * 2.5 && !!next && (next.type === "paragraph" || next.type === "heading") && next.pageNumber === block.pageNumber && nextSize >= medianFontSize * _chunkQA5KN5ITcjs.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;
|
|
5143
5161
|
}
|
|
5144
5162
|
function mergeStackedHeadingLines(blocks, medianFontSize) {
|
|
5145
5163
|
for (let i = 0; i < blocks.length - 1; ) {
|
|
5146
5164
|
const a = blocks[i], b = blocks[i + 1];
|
|
5147
5165
|
const ab = a.bbox, bb = b.bbox;
|
|
5148
|
-
const af = _nullishCoalesce(_optionalChain([a, 'access',
|
|
5166
|
+
const af = _nullishCoalesce(_optionalChain([a, 'access', _152 => _152.style, 'optionalAccess', _153 => _153.fontSize]), () => ( 0)), bf = _nullishCoalesce(_optionalChain([b, 'access', _154 => _154.style, 'optionalAccess', _155 => _155.fontSize]), () => ( 0));
|
|
5149
5167
|
const gap = ab && bb ? ab.y - (bb.y + bb.height) : Infinity;
|
|
5150
|
-
const centered = ab && bb && _optionalChain([a, 'access',
|
|
5168
|
+
const centered = ab && bb && _optionalChain([a, 'access', _156 => _156.style, 'optionalAccess', _157 => _157.fontName]) === _optionalChain([b, 'access', _158 => _158.style, 'optionalAccess', _159 => _159.fontName]) && Math.abs(ab.x + ab.width / 2 - (bb.x + bb.width / 2)) <= Math.max(5, af * 0.5);
|
|
5151
5169
|
const sameAnchor = ab && bb && Math.abs(ab.x - bb.x) <= 5;
|
|
5152
|
-
const wrapped = sameAnchor && _optionalChain([a, 'access',
|
|
5170
|
+
const wrapped = sameAnchor && _optionalChain([a, 'access', _160 => _160.style, 'optionalAccess', _161 => _161.fontName]) === _optionalChain([b, 'access', _162 => _162.style, 'optionalAccess', _163 => _163.fontName]) && af === bf && ab.width >= bb.width * 0.95 && (_nullishCoalesce(_optionalChain([a, 'access', _164 => _164.text, 'optionalAccess', _165 => _165.trim, 'call', _166 => _166(), 'access', _167 => _167.split, 'call', _168 => _168(/\s+/), 'access', _169 => _169.length]), () => ( 0))) >= 3;
|
|
5153
5171
|
const displayStack = centered && gap <= Math.min(af, bf) * 0.3 && Math.max(af, bf) <= Math.min(af, bf) * 1.45;
|
|
5154
5172
|
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)) {
|
|
5155
5173
|
i++;
|
|
@@ -5178,25 +5196,25 @@ function detectTypographyHeadings(blocks) {
|
|
|
5178
5196
|
if (page.some((block) => block.type === "heading")) continue;
|
|
5179
5197
|
const faceWeight = /* @__PURE__ */ new Map();
|
|
5180
5198
|
for (const block of page) {
|
|
5181
|
-
if (block.type !== "paragraph" || !block.text || !_optionalChain([block, 'access',
|
|
5199
|
+
if (block.type !== "paragraph" || !block.text || !_optionalChain([block, 'access', _170 => _170.style, 'optionalAccess', _171 => _171.fontName])) continue;
|
|
5182
5200
|
const faces = FACE_CHARS.get(block);
|
|
5183
5201
|
if (faces) for (const [face, n] of faces) faceWeight.set(face, (_nullishCoalesce(faceWeight.get(face), () => ( 0))) + n);
|
|
5184
5202
|
else faceWeight.set(block.style.fontName, (_nullishCoalesce(faceWeight.get(block.style.fontName), () => ( 0))) + block.text.length);
|
|
5185
5203
|
}
|
|
5186
|
-
const bodyFace = _optionalChain([[...faceWeight], 'access',
|
|
5204
|
+
const bodyFace = _optionalChain([[...faceWeight], 'access', _172 => _172.sort, 'call', _173 => _173((a, b) => b[1] - a[1]), 'access', _174 => _174[0], 'optionalAccess', _175 => _175[0]]);
|
|
5187
5205
|
if (!bodyFace || (_nullishCoalesce(faceWeight.get(bodyFace), () => ( 0))) < 250) continue;
|
|
5188
5206
|
const sizeWeight = /* @__PURE__ */ new Map();
|
|
5189
5207
|
for (const block of page) {
|
|
5190
|
-
if (block.type !== "paragraph" || !_optionalChain([block, 'access',
|
|
5208
|
+
if (block.type !== "paragraph" || !_optionalChain([block, 'access', _176 => _176.style, 'optionalAccess', _177 => _177.fontSize])) continue;
|
|
5191
5209
|
const faces = FACE_CHARS.get(block);
|
|
5192
|
-
const chars = faces ? _nullishCoalesce(faces.get(bodyFace), () => ( 0)) : block.style.fontName === bodyFace ? _nullishCoalesce(_optionalChain([block, 'access',
|
|
5210
|
+
const chars = faces ? _nullishCoalesce(faces.get(bodyFace), () => ( 0)) : block.style.fontName === bodyFace ? _nullishCoalesce(_optionalChain([block, 'access', _178 => _178.text, 'optionalAccess', _179 => _179.length]), () => ( 0)) : 0;
|
|
5193
5211
|
if (chars) sizeWeight.set(block.style.fontSize, (_nullishCoalesce(sizeWeight.get(block.style.fontSize), () => ( 0))) + chars);
|
|
5194
5212
|
}
|
|
5195
|
-
const bodySize = _nullishCoalesce(_optionalChain([[...sizeWeight], 'access',
|
|
5213
|
+
const bodySize = _nullishCoalesce(_optionalChain([[...sizeWeight], 'access', _180 => _180.sort, 'call', _181 => _181((a, b) => b[1] - a[1]), 'access', _182 => _182[0], 'optionalAccess', _183 => _183[0]]), () => ( 0));
|
|
5196
5214
|
for (let i = 0; i < page.length; i++) {
|
|
5197
5215
|
const block = page[i];
|
|
5198
5216
|
const { text, bbox, style } = block;
|
|
5199
|
-
if (block.type !== "paragraph" || !text || !bbox || !_optionalChain([style, 'optionalAccess',
|
|
5217
|
+
if (block.type !== "paragraph" || !text || !bbox || !_optionalChain([style, 'optionalAccess', _184 => _184.fontName]) || !style.fontSize) continue;
|
|
5200
5218
|
const title = text.trim();
|
|
5201
5219
|
const numbered = /^\d+(?:\.\d+)*\.?\s+[A-Z가-힣]/.test(title);
|
|
5202
5220
|
const faces = FACE_CHARS.get(block);
|
|
@@ -5226,16 +5244,16 @@ function detectDocumentStyleHeadings(blocks) {
|
|
|
5226
5244
|
for (const page of byPage.values()) {
|
|
5227
5245
|
const faceChars = /* @__PURE__ */ new Map();
|
|
5228
5246
|
for (const block of page) {
|
|
5229
|
-
if (block.type !== "paragraph" || !block.text || !_optionalChain([block, 'access',
|
|
5247
|
+
if (block.type !== "paragraph" || !block.text || !_optionalChain([block, 'access', _185 => _185.style, 'optionalAccess', _186 => _186.fontName])) continue;
|
|
5230
5248
|
faceChars.set(block.style.fontName, (_nullishCoalesce(faceChars.get(block.style.fontName), () => ( 0))) + block.text.length);
|
|
5231
5249
|
}
|
|
5232
|
-
const bodyFace = _optionalChain([[...faceChars], 'access',
|
|
5250
|
+
const bodyFace = _optionalChain([[...faceChars], 'access', _187 => _187.sort, 'call', _188 => _188((a, b) => b[1] - a[1]), 'access', _189 => _189[0], 'optionalAccess', _190 => _190[0]]);
|
|
5233
5251
|
if (!bodyFace || (_nullishCoalesce(faceChars.get(bodyFace), () => ( 0))) < 100) continue;
|
|
5234
|
-
const labels = page.filter((b) => b.type === "paragraph" && b.text && b.bbox && _optionalChain([b, 'access',
|
|
5252
|
+
const labels = page.filter((b) => b.type === "paragraph" && b.text && b.bbox && _optionalChain([b, 'access', _191 => _191.style, 'optionalAccess', _192 => _192.fontName]) && b.style.fontName !== bodyFace && b.text.trim().length >= 3 && b.text.trim().length <= 40);
|
|
5235
5253
|
for (const label of labels) {
|
|
5236
|
-
const peers = labels.filter((b) => _optionalChain([b, 'access',
|
|
5254
|
+
const peers = labels.filter((b) => _optionalChain([b, 'access', _193 => _193.style, 'optionalAccess', _194 => _194.fontName]) === _optionalChain([label, 'access', _195 => _195.style, 'optionalAccess', _196 => _196.fontName]) && Math.abs(b.bbox.y - label.bbox.y) <= 3 && Math.abs(b.bbox.x - label.bbox.x) >= 60);
|
|
5237
5255
|
if (peers.length < 2) continue;
|
|
5238
|
-
const value = page.find((b) => b.type === "paragraph" && b.bbox && _optionalChain([b, 'access',
|
|
5256
|
+
const value = page.find((b) => b.type === "paragraph" && b.bbox && _optionalChain([b, 'access', _197 => _197.style, 'optionalAccess', _198 => _198.fontName]) !== _optionalChain([label, 'access', _199 => _199.style, 'optionalAccess', _200 => _200.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);
|
|
5239
5257
|
if (value) {
|
|
5240
5258
|
label.type = "heading";
|
|
5241
5259
|
label.level = 2;
|
|
@@ -5244,7 +5262,7 @@ function detectDocumentStyleHeadings(blocks) {
|
|
|
5244
5262
|
const first = page.find((b) => b.type !== "image" && b.type !== "separator");
|
|
5245
5263
|
const second = page[page.indexOf(first) + 1];
|
|
5246
5264
|
const third = page[page.indexOf(first) + 2];
|
|
5247
|
-
if (!first || !second || !third || first.type !== "list" && first.type !== "paragraph" || second.type !== "paragraph" || !first.text || !second.text || !first.bbox || !second.bbox || !_optionalChain([first, 'access',
|
|
5265
|
+
if (!first || !second || !third || first.type !== "list" && first.type !== "paragraph" || second.type !== "paragraph" || !first.text || !second.text || !first.bbox || !second.bbox || !_optionalChain([first, 'access', _201 => _201.style, 'optionalAccess', _202 => _202.fontName]) || !_optionalChain([second, 'access', _203 => _203.style, 'optionalAccess', _204 => _204.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', _205 => _205.style, 'optionalAccess', _206 => _206.fontName]) !== bodyFace) continue;
|
|
5248
5266
|
first.type = "heading";
|
|
5249
5267
|
first.level = 1;
|
|
5250
5268
|
first.text = `${first.text.trim()} ${second.text.trim()}`;
|
|
@@ -5268,18 +5286,18 @@ function detectSiblingStyleHeadings(blocks) {
|
|
|
5268
5286
|
for (const page of byPage.values()) {
|
|
5269
5287
|
const bodyChars = /* @__PURE__ */ new Map();
|
|
5270
5288
|
for (const block of page) {
|
|
5271
|
-
if (block.type !== "paragraph" || !block.text || !_optionalChain([block, 'access',
|
|
5289
|
+
if (block.type !== "paragraph" || !block.text || !_optionalChain([block, 'access', _207 => _207.style, 'optionalAccess', _208 => _208.fontName])) continue;
|
|
5272
5290
|
const face = block.style.fontName;
|
|
5273
5291
|
bodyChars.set(face, (_nullishCoalesce(bodyChars.get(face), () => ( 0))) + block.text.length);
|
|
5274
5292
|
}
|
|
5275
|
-
const bodyFace = _optionalChain([[...bodyChars], 'access',
|
|
5276
|
-
const anchors = page.filter((b) => b.type === "heading" && b.text && _optionalChain([b, 'access',
|
|
5293
|
+
const bodyFace = _optionalChain([[...bodyChars], 'access', _209 => _209.sort, 'call', _210 => _210((a, b) => b[1] - a[1]), 'access', _211 => _211[0], 'optionalAccess', _212 => _212[0]]);
|
|
5294
|
+
const anchors = page.filter((b) => b.type === "heading" && b.text && _optionalChain([b, 'access', _213 => _213.style, 'optionalAccess', _214 => _214.fontName]) && b.style.fontName !== bodyFace);
|
|
5277
5295
|
for (const anchor of anchors) {
|
|
5278
5296
|
const numbered = /^([A-Z])\.\d+\s+/.exec(anchor.text.trim());
|
|
5279
5297
|
const lettered = /^([A-Z])\s+/.exec(anchor.text.trim());
|
|
5280
|
-
const peers = anchors.filter((b) => _optionalChain([b, 'access',
|
|
5298
|
+
const peers = anchors.filter((b) => _optionalChain([b, 'access', _215 => _215.style, 'optionalAccess', _216 => _216.fontName]) === _optionalChain([anchor, 'access', _217 => _217.style, 'optionalAccess', _218 => _218.fontName]) && Math.abs((_nullishCoalesce(_optionalChain([b, 'access', _219 => _219.style, 'optionalAccess', _220 => _220.fontSize]), () => ( 0))) - (_nullishCoalesce(_optionalChain([anchor, 'access', _221 => _221.style, 'optionalAccess', _222 => _222.fontSize]), () => ( 0)))) < 0.5);
|
|
5281
5299
|
if (peers.length < 2 && !numbered && !lettered) continue;
|
|
5282
|
-
const candidates = page.filter((b) => b.type === "paragraph" && b.text && b.bbox && _optionalChain([b, 'access',
|
|
5300
|
+
const candidates = page.filter((b) => b.type === "paragraph" && b.text && b.bbox && _optionalChain([b, 'access', _223 => _223.style, 'optionalAccess', _224 => _224.fontName]) === _optionalChain([anchor, 'access', _225 => _225.style, 'optionalAccess', _226 => _226.fontName]) && Math.abs((_nullishCoalesce(_optionalChain([b, 'access', _227 => _227.style, 'optionalAccess', _228 => _228.fontSize]), () => ( 0))) - (_nullishCoalesce(_optionalChain([anchor, 'access', _229 => _229.style, 'optionalAccess', _230 => _230.fontSize]), () => ( 0)))) < 0.5 && b.text.trim().length >= 3 && b.text.trim().length <= 80 && b.bbox.height <= (_nullishCoalesce(_optionalChain([b, 'access', _231 => _231.style, 'optionalAccess', _232 => _232.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()));
|
|
5283
5301
|
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));
|
|
5284
5302
|
if (siblings.length < (numbered || lettered ? 1 : 2)) continue;
|
|
5285
5303
|
for (const sibling of siblings) {
|
|
@@ -5298,13 +5316,13 @@ function detectRepeatedPageLabels(blocks) {
|
|
|
5298
5316
|
}
|
|
5299
5317
|
for (const page of byPage.values()) {
|
|
5300
5318
|
const bodyChars = /* @__PURE__ */ new Map();
|
|
5301
|
-
for (const b of page) if (b.type === "paragraph" && b.text && _optionalChain([b, 'access',
|
|
5319
|
+
for (const b of page) if (b.type === "paragraph" && b.text && _optionalChain([b, 'access', _233 => _233.style, 'optionalAccess', _234 => _234.fontName])) {
|
|
5302
5320
|
const faces = FACE_CHARS.get(b);
|
|
5303
5321
|
if (faces) for (const [face, n] of faces) bodyChars.set(face, (_nullishCoalesce(bodyChars.get(face), () => ( 0))) + n);
|
|
5304
5322
|
else bodyChars.set(b.style.fontName, (_nullishCoalesce(bodyChars.get(b.style.fontName), () => ( 0))) + b.text.length);
|
|
5305
5323
|
}
|
|
5306
|
-
const bodyFace = _optionalChain([[...bodyChars], 'access',
|
|
5307
|
-
const candidates = page.filter((b) => b.type === "paragraph" && b.text && b.bbox && _optionalChain([b, 'access',
|
|
5324
|
+
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]]);
|
|
5325
|
+
const candidates = page.filter((b) => b.type === "paragraph" && b.text && b.bbox && _optionalChain([b, 'access', _239 => _239.style, 'optionalAccess', _240 => _240.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);
|
|
5308
5326
|
const groups = /* @__PURE__ */ new Map();
|
|
5309
5327
|
for (const b of candidates) {
|
|
5310
5328
|
const key = `${b.style.fontName}:${b.style.fontSize}`;
|
|
@@ -5340,19 +5358,19 @@ function detectPageLeadHeadings(blocks) {
|
|
|
5340
5358
|
for (const page of byPage.values()) {
|
|
5341
5359
|
const content = page.filter((b) => b.type !== "image" && b.type !== "separator" && !(b.type === "paragraph" && !b.style));
|
|
5342
5360
|
const [first, second, third] = content;
|
|
5343
|
-
if (!_optionalChain([first, 'optionalAccess',
|
|
5361
|
+
if (!_optionalChain([first, 'optionalAccess', _241 => _241.bbox]) || !first.text || !_optionalChain([first, 'access', _242 => _242.style, 'optionalAccess', _243 => _243.fontSize]) || !second) continue;
|
|
5344
5362
|
const firstText = first.text.trim();
|
|
5345
5363
|
const captionLike = /^(?:Figure|Fig\.?|Table|표|그림)\s*\d/i;
|
|
5346
5364
|
const hasImage = page.some((b) => b.type === "image");
|
|
5347
|
-
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',
|
|
5365
|
+
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', _244 => _244.text, 'optionalAccess', _245 => _245.trim, 'call', _246 => _246()]), () => ( ""))) && (_nullishCoalesce(_optionalChain([second, 'access', _247 => _247.text, 'optionalAccess', _248 => _248.length]), () => ( 0))) >= 100 && second.bbox && first.bbox.y - (second.bbox.y + second.bbox.height) >= first.style.fontSize);
|
|
5348
5366
|
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);
|
|
5349
|
-
const firstIsSection = first.type === "list" && /^\d+\.\s+[A-Z][A-Z\s]{12,}$/.test(firstText) && second.type === "paragraph" && (_nullishCoalesce(_optionalChain([second, 'access',
|
|
5367
|
+
const firstIsSection = first.type === "list" && /^\d+\.\s+[A-Z][A-Z\s]{12,}$/.test(firstText) && second.type === "paragraph" && (_nullishCoalesce(_optionalChain([second, 'access', _249 => _249.text, 'optionalAccess', _250 => _250.length]), () => ( 0))) >= 100;
|
|
5350
5368
|
if (firstIsTitle || firstAboveProse || firstIsSection) {
|
|
5351
5369
|
first.type = "heading";
|
|
5352
5370
|
first.level = 1;
|
|
5353
5371
|
}
|
|
5354
|
-
if (first.type !== "heading" || captionLike.test(firstText) || second.type !== "paragraph" || !second.text || !second.bbox || !_optionalChain([second, 'access',
|
|
5355
|
-
const distinctFace = _optionalChain([third, 'access',
|
|
5372
|
+
if (first.type !== "heading" || captionLike.test(firstText) || second.type !== "paragraph" || !second.text || !second.bbox || !_optionalChain([second, 'access', _251 => _251.style, 'optionalAccess', _252 => _252.fontName]) || !second.style.fontSize || !_optionalChain([third, 'optionalAccess', _253 => _253.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;
|
|
5373
|
+
const distinctFace = _optionalChain([third, 'access', _254 => _254.style, 'optionalAccess', _255 => _255.fontName]) !== second.style.fontName;
|
|
5356
5374
|
const namedContents = /^Table of Contents$/i.test(second.text.trim());
|
|
5357
5375
|
if (distinctFace && third.text.length >= 60 || namedContents) {
|
|
5358
5376
|
second.type = "heading";
|
|
@@ -5363,24 +5381,24 @@ function detectPageLeadHeadings(blocks) {
|
|
|
5363
5381
|
function refineDocumentStyleHeadings(blocks) {
|
|
5364
5382
|
const faceChars = /* @__PURE__ */ new Map();
|
|
5365
5383
|
for (const block of blocks) {
|
|
5366
|
-
if (block.type !== "paragraph" || !block.text || !_optionalChain([block, 'access',
|
|
5384
|
+
if (block.type !== "paragraph" || !block.text || !_optionalChain([block, 'access', _256 => _256.style, 'optionalAccess', _257 => _257.fontName])) continue;
|
|
5367
5385
|
faceChars.set(block.style.fontName, (_nullishCoalesce(faceChars.get(block.style.fontName), () => ( 0))) + block.text.length);
|
|
5368
5386
|
}
|
|
5369
5387
|
const [bodyFace, bodyChars] = _nullishCoalesce([...faceChars].sort((a, b) => b[1] - a[1])[0], () => ( []));
|
|
5370
5388
|
if (!bodyFace || !bodyChars || bodyChars < 300) return;
|
|
5371
5389
|
for (let i = 0; i < blocks.length; i++) {
|
|
5372
5390
|
const block = blocks[i];
|
|
5373
|
-
const text = _nullishCoalesce(_optionalChain([block, 'access',
|
|
5391
|
+
const text = _nullishCoalesce(_optionalChain([block, 'access', _258 => _258.text, 'optionalAccess', _259 => _259.trim, 'call', _260 => _260()]), () => ( ""));
|
|
5374
5392
|
if (block.type === "heading" && /(?:https?:\/\/|www\.|^arxiv:|^doi:)/i.test(text)) {
|
|
5375
5393
|
block.type = "paragraph";
|
|
5376
5394
|
block.level = void 0;
|
|
5377
5395
|
continue;
|
|
5378
5396
|
}
|
|
5379
5397
|
const box = block.bbox, style = block.style;
|
|
5380
|
-
if (block.type !== "paragraph" || !box || !_optionalChain([style, 'optionalAccess',
|
|
5398
|
+
if (block.type !== "paragraph" || !box || !_optionalChain([style, 'optionalAccess', _261 => _261.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;
|
|
5381
5399
|
const previous = blocks[i - 1], next = blocks[i + 1];
|
|
5382
|
-
const pb = _optionalChain([previous, 'optionalAccess',
|
|
5383
|
-
if (!pb || !nb || previous.pageNumber !== block.pageNumber || next.pageNumber !== block.pageNumber || previous.type !== "paragraph" && previous.type !== "heading" || next.type !== "paragraph" || _optionalChain([next, 'access',
|
|
5400
|
+
const pb = _optionalChain([previous, 'optionalAccess', _262 => _262.bbox]), nb = _optionalChain([next, 'optionalAccess', _263 => _263.bbox]);
|
|
5401
|
+
if (!pb || !nb || previous.pageNumber !== block.pageNumber || next.pageNumber !== block.pageNumber || previous.type !== "paragraph" && previous.type !== "heading" || next.type !== "paragraph" || _optionalChain([next, 'access', _264 => _264.style, 'optionalAccess', _265 => _265.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;
|
|
5384
5402
|
block.type = "heading";
|
|
5385
5403
|
block.level = 2;
|
|
5386
5404
|
}
|
|
@@ -5430,7 +5448,7 @@ function detectMarkerHeadings(blocks) {
|
|
|
5430
5448
|
block.level = 4;
|
|
5431
5449
|
continue;
|
|
5432
5450
|
}
|
|
5433
|
-
if (/^[가-힣]{2,6}$/.test(text) && _optionalChain([block, 'access',
|
|
5451
|
+
if (/^[가-힣]{2,6}$/.test(text) && _optionalChain([block, 'access', _266 => _266.style, 'optionalAccess', _267 => _267.fontSize])) {
|
|
5434
5452
|
const prev = blocks[i - 1];
|
|
5435
5453
|
const next = blocks[i + 1];
|
|
5436
5454
|
const prevIsStructural = !prev || prev.type === "table" || prev.type === "heading" || prev.type === "separator";
|
|
@@ -5471,7 +5489,7 @@ function detectTableCaptions(blocks) {
|
|
|
5471
5489
|
block.table.caption = blocks[i - 1].text.trim();
|
|
5472
5490
|
blocks.splice(i - 1, 1);
|
|
5473
5491
|
i--;
|
|
5474
|
-
} else if (isCaptionCandidate(blocks[i + 1], block) && _optionalChain([blocks, 'access',
|
|
5492
|
+
} else if (isCaptionCandidate(blocks[i + 1], block) && _optionalChain([blocks, 'access', _268 => _268[i + 2], 'optionalAccess', _269 => _269.type]) !== "table") {
|
|
5475
5493
|
block.table.caption = blocks[i + 1].text.trim();
|
|
5476
5494
|
blocks.splice(i + 1, 1);
|
|
5477
5495
|
}
|
|
@@ -5690,7 +5708,7 @@ function removeHeaderFooterBlocks(blocks, pageHeights, warnings, notes, tables =
|
|
|
5690
5708
|
const bottomEntries = [];
|
|
5691
5709
|
for (let bi = 0; bi < blocks.length; bi++) {
|
|
5692
5710
|
const b = blocks[bi];
|
|
5693
|
-
const text = !tables ? _optionalChain([b, 'access',
|
|
5711
|
+
const text = !tables ? _optionalChain([b, 'access', _270 => _270.text, 'optionalAccess', _271 => _271.trim, 'call', _272 => _272()]) : b.type === "table" && b.table ? b.table.cells.flat().map((c) => c.text.trim()).filter(Boolean).join(" | ") : void 0;
|
|
5694
5712
|
if (!b.bbox || !b.pageNumber || !text) continue;
|
|
5695
5713
|
const ph = pageHeights.get(b.bbox.page) || pageHeights.get(b.pageNumber);
|
|
5696
5714
|
if (!ph) continue;
|
|
@@ -5721,7 +5739,7 @@ function removeHeaderFooterBlocks(blocks, pageHeights, warnings, notes, tables =
|
|
|
5721
5739
|
for (const [p, count] of patternCount) {
|
|
5722
5740
|
const pages = [..._nullishCoalesce(patternPages.get(p), () => ( []))];
|
|
5723
5741
|
const span2 = pages.length ? Math.max(...pages) - Math.min(...pages) + 1 : 0;
|
|
5724
|
-
const pageNumbered = !tables && (_nullishCoalesce(_optionalChain([patternNumbers, 'access',
|
|
5742
|
+
const pageNumbered = !tables && (_nullishCoalesce(_optionalChain([patternNumbers, 'access', _273 => _273.get, 'call', _274 => _274(p), 'optionalAccess', _275 => _275.size]), () => ( 0))) > 1;
|
|
5725
5743
|
if (count >= MIN_REPEAT2 && pages.length >= MIN_REPEAT2 && (pages.length >= span2 * 0.4 || pageNumbered)) {
|
|
5726
5744
|
repeatedPatterns.add(p);
|
|
5727
5745
|
}
|
|
@@ -5729,8 +5747,8 @@ function removeHeaderFooterBlocks(blocks, pageHeights, warnings, notes, tables =
|
|
|
5729
5747
|
for (const e of entries) {
|
|
5730
5748
|
const norm = e.text.replace(/\d+/g, "#");
|
|
5731
5749
|
if (!repeatedPatterns.has(norm)) continue;
|
|
5732
|
-
const noteMark = _optionalChain([e, 'access',
|
|
5733
|
-
if (noteMark && _optionalChain([notes, 'optionalAccess',
|
|
5750
|
+
const noteMark = _optionalChain([e, 'access', _276 => _276.text, 'access', _277 => _277.match, 'call', _278 => _278(/^\d{1,3}\)/), 'optionalAccess', _279 => _279[0]]);
|
|
5751
|
+
if (noteMark && _optionalChain([notes, 'optionalAccess', _280 => _280.get, 'call', _281 => _281(e.page), 'optionalAccess', _282 => _282.marks, 'access', _283 => _283.some, 'call', _284 => _284((m) => m.mark === noteMark)])) continue;
|
|
5734
5752
|
const cand = blocks[e.blockIdx];
|
|
5735
5753
|
const cb = cand.bbox;
|
|
5736
5754
|
const tableNote = /^(?:주\s*(?:\d+\s*[).:]|[::])|(?:자료|출처)\s*[::])/.test(e.text.replace(/ \| /g, " ")) && blocks.some((o) => {
|
|
@@ -5744,7 +5762,7 @@ function removeHeaderFooterBlocks(blocks, pageHeights, warnings, notes, tables =
|
|
|
5744
5762
|
if (bi === e.blockIdx) continue;
|
|
5745
5763
|
const o = blocks[bi];
|
|
5746
5764
|
if (!o.bbox || o.bbox.page !== cb.page) continue;
|
|
5747
|
-
const oNorm = _optionalChain([o, 'access',
|
|
5765
|
+
const oNorm = _optionalChain([o, 'access', _285 => _285.text, 'optionalAccess', _286 => _286.trim, 'call', _287 => _287(), 'access', _288 => _288.replace, 'call', _289 => _289(/\d+/g, "#")]);
|
|
5748
5766
|
if (oNorm && repeatedPatterns.has(oNorm)) continue;
|
|
5749
5767
|
const overlap2 = Math.min(cb.y + cb.height, o.bbox.y + o.bbox.height) - Math.max(cb.y, o.bbox.y);
|
|
5750
5768
|
if (overlap2 >= cb.height * 0.5) {
|
|
@@ -5819,7 +5837,7 @@ function recordRowRules(table, cells, bbox, hs) {
|
|
|
5819
5837
|
function markImageCell(cell) {
|
|
5820
5838
|
IMAGE_CELLS.add(cell);
|
|
5821
5839
|
}
|
|
5822
|
-
var emptyCell = (cell) => !cell || !_optionalChain([cell, 'access',
|
|
5840
|
+
var emptyCell = (cell) => !cell || !_optionalChain([cell, 'access', _290 => _290.text, 'optionalAccess', _291 => _291.trim, 'call', _292 => _292()]) && !_optionalChain([cell, 'access', _293 => _293.blocks, 'optionalAccess', _294 => _294.length]) && !IMAGE_CELLS.has(cell);
|
|
5823
5841
|
function trimTable(table) {
|
|
5824
5842
|
let cols = table.cols;
|
|
5825
5843
|
while (cols > 0 && table.cells.every((row) => emptyCell(row[cols - 1]))) cols--;
|
|
@@ -5835,7 +5853,7 @@ function trimTable(table) {
|
|
|
5835
5853
|
function trimTrailingEmptyTableCols(blocks) {
|
|
5836
5854
|
for (const b of blocks) {
|
|
5837
5855
|
if (b.type !== "table" || !b.table) continue;
|
|
5838
|
-
for (const row of b.table.cells) for (const cell of row) if (_optionalChain([cell, 'access',
|
|
5856
|
+
for (const row of b.table.cells) for (const cell of row) if (_optionalChain([cell, 'access', _295 => _295.blocks, 'optionalAccess', _296 => _296.length])) trimTrailingEmptyTableCols(cell.blocks);
|
|
5839
5857
|
trimTable(b.table);
|
|
5840
5858
|
}
|
|
5841
5859
|
}
|
|
@@ -5855,7 +5873,7 @@ function mergeSliverColumns(grid, colXs, maxWidth) {
|
|
|
5855
5873
|
}
|
|
5856
5874
|
const ok = owner.every((row) => {
|
|
5857
5875
|
const o = row[c];
|
|
5858
|
-
return !!o && (o.colSpan > 1 || !o.text.trim() && !_optionalChain([o, 'access',
|
|
5876
|
+
return !!o && (o.colSpan > 1 || !o.text.trim() && !_optionalChain([o, 'access', _297 => _297.blocks, 'optionalAccess', _298 => _298.length]));
|
|
5859
5877
|
});
|
|
5860
5878
|
if (!ok) continue;
|
|
5861
5879
|
const spanning = /* @__PURE__ */ new Set();
|
|
@@ -5882,7 +5900,7 @@ var multiply = (m, t) => [
|
|
|
5882
5900
|
m[1] * t[4] + m[3] * t[5] + m[5]
|
|
5883
5901
|
];
|
|
5884
5902
|
function hollowCircle(image) {
|
|
5885
|
-
if (!_optionalChain([image, 'optionalAccess',
|
|
5903
|
+
if (!_optionalChain([image, 'optionalAccess', _299 => _299.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;
|
|
5886
5904
|
const stride = image.kind === _pdfmjs.ImageKind.RGB_24BPP ? 3 : image.kind === _pdfmjs.ImageKind.RGBA_32BPP ? 4 : 0;
|
|
5887
5905
|
const { width, height, data } = image;
|
|
5888
5906
|
if (!stride || data.length < width * height * stride) return false;
|
|
@@ -5947,9 +5965,9 @@ function smallVisibleImagePaints(fnArray, argsArray) {
|
|
|
5947
5965
|
const op = fnArray[i], args = argsArray[i];
|
|
5948
5966
|
if (op === _pdfmjs.OPS.save || op === _pdfmjs.OPS.paintFormXObjectBegin) {
|
|
5949
5967
|
stack.push({ ctm, alpha, clip, unknownClip });
|
|
5950
|
-
const matrix = op === _pdfmjs.OPS.paintFormXObjectBegin ? _optionalChain([args, 'optionalAccess',
|
|
5968
|
+
const matrix = op === _pdfmjs.OPS.paintFormXObjectBegin ? _optionalChain([args, 'optionalAccess', _300 => _300[0]]) : void 0;
|
|
5951
5969
|
if (Array.isArray(matrix) && matrix.length >= 6) ctm = multiply(ctm, matrix);
|
|
5952
|
-
const bounds = op === _pdfmjs.OPS.paintFormXObjectBegin ? _optionalChain([args, 'optionalAccess',
|
|
5970
|
+
const bounds = op === _pdfmjs.OPS.paintFormXObjectBegin ? _optionalChain([args, 'optionalAccess', _301 => _301[1]]) : void 0;
|
|
5953
5971
|
if (Array.isArray(bounds) && bounds.length === 4) {
|
|
5954
5972
|
const box = rectangle(bounds[0], bounds[1], bounds[2] - bounds[0], bounds[3] - bounds[1]);
|
|
5955
5973
|
if (box && ctm[1] === 0 && ctm[2] === 0) intersectClip(box);
|
|
@@ -5957,17 +5975,17 @@ function smallVisibleImagePaints(fnArray, argsArray) {
|
|
|
5957
5975
|
}
|
|
5958
5976
|
} else if (op === _pdfmjs.OPS.restore || op === _pdfmjs.OPS.paintFormXObjectEnd) {
|
|
5959
5977
|
const state = stack.pop();
|
|
5960
|
-
ctm = _nullishCoalesce(_optionalChain([state, 'optionalAccess',
|
|
5961
|
-
alpha = _nullishCoalesce(_optionalChain([state, 'optionalAccess',
|
|
5962
|
-
clip = _nullishCoalesce(_optionalChain([state, 'optionalAccess',
|
|
5963
|
-
unknownClip = _nullishCoalesce(_optionalChain([state, 'optionalAccess',
|
|
5978
|
+
ctm = _nullishCoalesce(_optionalChain([state, 'optionalAccess', _302 => _302.ctm]), () => ( [1, 0, 0, 1, 0, 0]));
|
|
5979
|
+
alpha = _nullishCoalesce(_optionalChain([state, 'optionalAccess', _303 => _303.alpha]), () => ( 1));
|
|
5980
|
+
clip = _nullishCoalesce(_optionalChain([state, 'optionalAccess', _304 => _304.clip]), () => ( null));
|
|
5981
|
+
unknownClip = _nullishCoalesce(_optionalChain([state, 'optionalAccess', _305 => _305.unknownClip]), () => ( false));
|
|
5964
5982
|
} else if (op === _pdfmjs.OPS.setGState) {
|
|
5965
|
-
for (const [key, value] of _nullishCoalesce(_optionalChain([args, 'optionalAccess',
|
|
5983
|
+
for (const [key, value] of _nullishCoalesce(_optionalChain([args, 'optionalAccess', _306 => _306[0]]), () => ( []))) {
|
|
5966
5984
|
if (key === "ca") alpha = typeof value === "number" ? value : 0;
|
|
5967
5985
|
}
|
|
5968
5986
|
} else if (op === _pdfmjs.OPS.constructPath) {
|
|
5969
5987
|
const [operations, coordinates] = args;
|
|
5970
|
-
pathRect = pathRect === void 0 && _optionalChain([operations, 'optionalAccess',
|
|
5988
|
+
pathRect = pathRect === void 0 && _optionalChain([operations, 'optionalAccess', _307 => _307.length]) === 1 && operations[0] === _pdfmjs.OPS.rectangle && _optionalChain([coordinates, 'optionalAccess', _308 => _308.length]) >= 4 && ctm[1] === 0 && ctm[2] === 0 ? rectangle(coordinates[0], coordinates[1], coordinates[2], coordinates[3]) : null;
|
|
5971
5989
|
} else if (op === _pdfmjs.OPS.clip || op === _pdfmjs.OPS.eoClip) pendingClip = true;
|
|
5972
5990
|
else if ([
|
|
5973
5991
|
_pdfmjs.OPS.endPath,
|
|
@@ -5987,7 +6005,7 @@ function smallVisibleImagePaints(fnArray, argsArray) {
|
|
|
5987
6005
|
pendingClip = false;
|
|
5988
6006
|
pathRect = void 0;
|
|
5989
6007
|
} else if (op === _pdfmjs.OPS.transform && Array.isArray(args) && args.length >= 6) ctm = multiply(ctm, args);
|
|
5990
|
-
else if (op === _pdfmjs.OPS.paintImageXObject && typeof _optionalChain([args, 'optionalAccess',
|
|
6008
|
+
else if (op === _pdfmjs.OPS.paintImageXObject && typeof _optionalChain([args, 'optionalAccess', _309 => _309[0]]) === "string") {
|
|
5991
6009
|
if (typeof args[1] !== "number" || typeof args[2] !== "number" || args[1] < 16 || args[1] > 128 || args[2] < 16 || args[2] > 128) continue;
|
|
5992
6010
|
const box = extractImageRegions([_pdfmjs.OPS.transform, _pdfmjs.OPS.paintImageXObject], [ctm, args])[0];
|
|
5993
6011
|
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;
|
|
@@ -6006,14 +6024,14 @@ async function restoreImageBullets(items, page, fnArray, argsArray, shapes = /*
|
|
|
6006
6024
|
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];
|
|
6007
6025
|
if (!line || /^[○●•◦□■∙]/.test(line.text.trim()) || !/\p{L}/u.test(line.text)) continue;
|
|
6008
6026
|
const row = items.filter((item) => Math.abs(item.y - line.y) <= 2 && item.x >= line.x);
|
|
6009
|
-
if (row.reduce((n, item) => n + (_nullishCoalesce(_optionalChain([item, 'access',
|
|
6027
|
+
if (row.reduce((n, item) => n + (_nullishCoalesce(_optionalChain([item, 'access', _310 => _310.text, 'access', _311 => _311.match, 'call', _312 => _312(/\p{L}/gu), 'optionalAccess', _313 => _313.length]), () => ( 0))), 0) < 12 || items.some((item) => item !== line && Math.abs(item.y - line.y) <= 2 && item.x < line.x)) continue;
|
|
6010
6028
|
candidates.push({ id, x: box.x1, width, line });
|
|
6011
6029
|
}
|
|
6012
6030
|
let restored = 0;
|
|
6013
6031
|
const used = /* @__PURE__ */ new Set();
|
|
6014
6032
|
for (const candidate of candidates) {
|
|
6015
6033
|
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);
|
|
6016
|
-
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',
|
|
6034
|
+
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', _314 => _314.text, 'access', _315 => _315.match, 'call', _316 => _316(/\p{L}/gu), 'optionalAccess', _317 => _317.length]), () => ( 0))) >= 12).sort((a, b) => b.y - a.y);
|
|
6017
6035
|
const numberedList = numbered.some((item, index) => index > 0 && item.text.trim().charCodeAt(0) === numbered[index - 1].text.trim().charCodeAt(0) + 1);
|
|
6018
6036
|
if (!same.length && !numberedList || used.has(candidate.line)) continue;
|
|
6019
6037
|
if (!shapes.has(candidate.id)) shapes.set(candidate.id, hollowCircle(await resolveImagePixels(page, candidate.id)));
|
|
@@ -6079,7 +6097,7 @@ function groupFlowBoxUnits(blocks, grids, hs, vs, images) {
|
|
|
6079
6097
|
return units;
|
|
6080
6098
|
}
|
|
6081
6099
|
function arrowDirection(image) {
|
|
6082
|
-
if (!_optionalChain([image, 'optionalAccess',
|
|
6100
|
+
if (!_optionalChain([image, 'optionalAccess', _318 => _318.data]) || image.width < 16 || image.width > 128 || image.height < 16 || image.height > 128) return 0;
|
|
6083
6101
|
const { width, height, data } = image;
|
|
6084
6102
|
const stride = image.kind === _pdfmjs.ImageKind.RGB_24BPP ? 3 : image.kind === _pdfmjs.ImageKind.RGBA_32BPP ? 4 : 0;
|
|
6085
6103
|
if (!stride || data.length < width * height * stride) return 0;
|
|
@@ -6147,7 +6165,7 @@ function isSideTabTable(box, table, others, pageWidth, pageHeight) {
|
|
|
6147
6165
|
function removeSideTabs(blocks, pageWidths) {
|
|
6148
6166
|
const edges = /* @__PURE__ */ new Map();
|
|
6149
6167
|
for (const b of blocks) {
|
|
6150
|
-
if (!b.bbox || b.pageNumber === void 0 || [..._nullishCoalesce(_optionalChain([b, 'access',
|
|
6168
|
+
if (!b.bbox || b.pageNumber === void 0 || [..._nullishCoalesce(_optionalChain([b, 'access', _319 => _319.text, 'optionalAccess', _320 => _320.trim, 'call', _321 => _321()]), () => ( ""))].length <= MAX_CHARS) continue;
|
|
6151
6169
|
const e = _nullishCoalesce(edges.get(b.pageNumber), () => ( { lefts: [], rights: [] }));
|
|
6152
6170
|
e.lefts.push(b.bbox.x);
|
|
6153
6171
|
e.rights.push(b.bbox.x + b.bbox.width);
|
|
@@ -6163,7 +6181,7 @@ function removeSideTabs(blocks, pageWidths) {
|
|
|
6163
6181
|
const fallback = all.length ? { left: q(all.map((e) => e.left), 0.5), right: q(all.map((e) => e.right), 0.5) } : void 0;
|
|
6164
6182
|
const key = (b) => {
|
|
6165
6183
|
const w = b.pageNumber !== void 0 ? pageWidths.get(b.pageNumber) : void 0;
|
|
6166
|
-
const text = _optionalChain([b, 'access',
|
|
6184
|
+
const text = _optionalChain([b, 'access', _322 => _322.text, 'optionalAccess', _323 => _323.trim, 'call', _324 => _324()]);
|
|
6167
6185
|
const area = _nullishCoalesce((b.pageNumber !== void 0 ? body.get(b.pageNumber) : void 0), () => ( fallback));
|
|
6168
6186
|
if (b.type === "table") {
|
|
6169
6187
|
if (!w || !b.bbox || !b.table || !SIDE_TAB_TABLES.has(b.table)) return null;
|
|
@@ -6512,16 +6530,16 @@ function isProseSpread(items) {
|
|
|
6512
6530
|
for (let i = 1; i < sorted.length; i++) {
|
|
6513
6531
|
gaps.push(sorted[i].x - (sorted[i - 1].x + sorted[i - 1].w));
|
|
6514
6532
|
}
|
|
6515
|
-
const maxGap =
|
|
6533
|
+
const maxGap = _chunkQ2BKBY3Ocjs.safeMax.call(void 0, gaps);
|
|
6516
6534
|
const avgLen = items.reduce((s, i) => s + i.text.length, 0) / items.length;
|
|
6517
6535
|
if (items.length >= 4 && maxGap < 40 && avgLen < 5) return true;
|
|
6518
|
-
const minGap =
|
|
6536
|
+
const minGap = _chunkQ2BKBY3Ocjs.safeMin.call(void 0, gaps);
|
|
6519
6537
|
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;
|
|
6520
6538
|
}
|
|
6521
6539
|
function detectColumns(yLines) {
|
|
6522
6540
|
const allItems = yLines.flat();
|
|
6523
6541
|
if (allItems.length === 0) return null;
|
|
6524
|
-
const pageWidth =
|
|
6542
|
+
const pageWidth = _chunkQ2BKBY3Ocjs.safeMax.call(void 0, allItems.map((i) => i.x + i.w)) - _chunkQ2BKBY3Ocjs.safeMin.call(void 0, allItems.map((i) => i.x));
|
|
6525
6543
|
if (pageWidth < 100) return null;
|
|
6526
6544
|
let bigoLineIdx = -1;
|
|
6527
6545
|
for (let i = 0; i < yLines.length; i++) {
|
|
@@ -6746,7 +6764,7 @@ var UNDER_BOX_PAIR_MAX_EM = 2.2;
|
|
|
6746
6764
|
var UNDER_BOX_PAIR_OVERLAP = 0.8;
|
|
6747
6765
|
function markUnderlineItems(items, horizontals, verticals, nonRules) {
|
|
6748
6766
|
const underlines = [];
|
|
6749
|
-
if (_optionalChain([nonRules, 'optionalAccess',
|
|
6767
|
+
if (_optionalChain([nonRules, 'optionalAccess', _325 => _325.size])) horizontals = horizontals.filter((line) => !nonRules.has(line));
|
|
6750
6768
|
if (items.length === 0 || horizontals.length === 0) return underlines;
|
|
6751
6769
|
const tightOwners = /* @__PURE__ */ new Map();
|
|
6752
6770
|
const tightlyOwned = (line) => {
|
|
@@ -6852,7 +6870,7 @@ function hasBoxTopPair(line, maxH, horizontals, cellItems) {
|
|
|
6852
6870
|
if (ow <= 0) continue;
|
|
6853
6871
|
const overlap2 = Math.min(line.x2, o.x2) - Math.max(line.x1, o.x1);
|
|
6854
6872
|
if (overlap2 / Math.max(w, ow) < UNDER_BOX_PAIR_OVERLAP) continue;
|
|
6855
|
-
const covered = _nullishCoalesce(_optionalChain([cellItems, 'optionalAccess',
|
|
6873
|
+
const covered = _nullishCoalesce(_optionalChain([cellItems, 'optionalAccess', _326 => _326.reduce, 'call', _327 => _327((sum, item) => {
|
|
6856
6874
|
const below = item.y - o.y1;
|
|
6857
6875
|
if (below < 0.5 || below > 3 || !item.text.trim()) return sum;
|
|
6858
6876
|
return sum + Math.max(0, Math.min(o.x2, item.x + item.w) - Math.max(o.x1, item.x));
|
|
@@ -7056,8 +7074,8 @@ function edgesOf(box, h, v, hNear = EDGE_NEAR2) {
|
|
|
7056
7074
|
}
|
|
7057
7075
|
function recordClipCellEdges(grids, horizontals, verticals, nonRules) {
|
|
7058
7076
|
if (!grids.some((g) => g.cells)) return;
|
|
7059
|
-
const h = rules(_optionalChain([nonRules, 'optionalAccess',
|
|
7060
|
-
const v = rules(_optionalChain([nonRules, 'optionalAccess',
|
|
7077
|
+
const h = rules(_optionalChain([nonRules, 'optionalAccess', _328 => _328.size]) ? horizontals.filter((l) => !nonRules.has(l)) : horizontals, "h");
|
|
7078
|
+
const v = rules(_optionalChain([nonRules, 'optionalAccess', _329 => _329.size]) ? verticals.filter((l) => !nonRules.has(l)) : verticals, "v");
|
|
7061
7079
|
for (const g of grids) for (const c of _nullishCoalesce(g.cells, () => ( []))) {
|
|
7062
7080
|
const near2 = c.filler ? Math.min(EDGE_NEAR2, (c.bbox.y2 - c.bbox.y1) / 3) : EDGE_NEAR2;
|
|
7063
7081
|
CLIP_CELL_EDGES.set(c, edgesOf(c.bbox, h, v, near2));
|
|
@@ -7065,12 +7083,12 @@ function recordClipCellEdges(grids, horizontals, verticals, nonRules) {
|
|
|
7065
7083
|
}
|
|
7066
7084
|
function takeClipCellEdges(from, to) {
|
|
7067
7085
|
const e = CLIP_CELL_EDGES.get(from);
|
|
7068
|
-
if (e)
|
|
7086
|
+
if (e) _chunkQA5KN5ITcjs.CELL_EDGES.set(to, e);
|
|
7069
7087
|
}
|
|
7070
7088
|
function joinCellEdges(a, b) {
|
|
7071
|
-
const u =
|
|
7089
|
+
const u = _chunkQA5KN5ITcjs.CELL_EDGES.get(a), d = _chunkQA5KN5ITcjs.CELL_EDGES.get(b);
|
|
7072
7090
|
if (!u || !d) return;
|
|
7073
|
-
|
|
7091
|
+
_chunkQA5KN5ITcjs.CELL_EDGES.set(a, { t: u.t, b: d.b, l: u.l || d.l, r: u.r || d.r });
|
|
7074
7092
|
}
|
|
7075
7093
|
|
|
7076
7094
|
// src/pdf/table-unit-row.ts
|
|
@@ -7086,12 +7104,12 @@ function rebuildUnitLine(items, grid) {
|
|
|
7086
7104
|
function prependUnitRow(cells, cols, line, usedItems) {
|
|
7087
7105
|
const text = cleanCellText(line.map((item) => item.text).join(""));
|
|
7088
7106
|
cells.unshift(Array.from({ length: cols }, (_, c) => ({ text: c === 0 ? text : "", colSpan: c === 0 ? cols : 1, rowSpan: 1 })));
|
|
7089
|
-
for (const cell of cells[0])
|
|
7107
|
+
for (const cell of cells[0]) _chunkQA5KN5ITcjs.CELL_EDGES.set(cell, NO_EDGES);
|
|
7090
7108
|
for (const item of line) usedItems.add(item);
|
|
7091
7109
|
}
|
|
7092
7110
|
function attachUnitRow(items, grid, cells, cols, usedItems) {
|
|
7093
7111
|
const all = cells.flat();
|
|
7094
|
-
if (all.filter((c) => c.text.trim()).length * 2 < all.length || UNIT.test(_nullishCoalesce(_optionalChain([cells, 'access',
|
|
7112
|
+
if (all.filter((c) => c.text.trim()).length * 2 < all.length || UNIT.test(_nullishCoalesce(_optionalChain([cells, 'access', _330 => _330[0], 'optionalAccess', _331 => _331[0], 'optionalAccess', _332 => _332.text]), () => ( "")))) return false;
|
|
7095
7113
|
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);
|
|
7096
7114
|
let nearest = Infinity;
|
|
7097
7115
|
for (const it of above) nearest = Math.min(nearest, it.y);
|
|
@@ -7126,7 +7144,7 @@ function closeShadedTableEdges(clipGrids, horizontals, verticals, fillRects) {
|
|
|
7126
7144
|
let hs = horizontals, vs = verticals;
|
|
7127
7145
|
const restored = [];
|
|
7128
7146
|
for (const grid of clipGrids) {
|
|
7129
|
-
if (grid.clipParent || grid.rowYs.length !== 2 || grid.colXs.length < 3 || !_optionalChain([grid, 'access',
|
|
7147
|
+
if (grid.clipParent || grid.rowYs.length !== 2 || grid.colXs.length < 3 || !_optionalChain([grid, 'access', _333 => _333.cells, 'optionalAccess', _334 => _334.length]) || grid.cells.some((c) => c.filler || c.rowSpan !== 1 || c.colSpan !== 1)) continue;
|
|
7130
7148
|
const { x1, x2, y1: mid, y2: top } = grid.bbox;
|
|
7131
7149
|
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;
|
|
7132
7150
|
const topRule = hs.find((h) => near2(h.y1, top) && near2(h.x1, x1) && near2(h.x2, x2));
|
|
@@ -7538,7 +7556,7 @@ function takeFrameSpanningText(items, cutX, pageNum, lex) {
|
|
|
7538
7556
|
const rows = groupByY([...items].sort((a, b) => b.y - a.y || a.x - b.x)).map((line) => {
|
|
7539
7557
|
const runs = [];
|
|
7540
7558
|
for (const item of [...line].sort((a, b) => a.x - b.x)) {
|
|
7541
|
-
const run = runs[runs.length - 1], prev = _optionalChain([run, 'optionalAccess',
|
|
7559
|
+
const run = runs[runs.length - 1], prev = _optionalChain([run, 'optionalAccess', _335 => _335[run.length - 1]]);
|
|
7542
7560
|
if (prev && item.x - (prev.x + prev.w) <= Math.max(prev.fontSize, item.fontSize) * 0.6) run.push(item);
|
|
7543
7561
|
else runs.push([item]);
|
|
7544
7562
|
}
|
|
@@ -7582,7 +7600,7 @@ function groupFrameParagraphUnits(units, frames) {
|
|
|
7582
7600
|
for (const unit of units) for (const block of unit) source.set(block, unit);
|
|
7583
7601
|
const members = /* @__PURE__ */ new Map(), emitted = /* @__PURE__ */ new Set();
|
|
7584
7602
|
for (const frame of frames) {
|
|
7585
|
-
if (frame.length < 2 || frame.some((block) => block.type !== "paragraph" || _optionalChain([source, 'access',
|
|
7603
|
+
if (frame.length < 2 || frame.some((block) => block.type !== "paragraph" || _optionalChain([source, 'access', _336 => _336.get, 'call', _337 => _337(block), 'optionalAccess', _338 => _338.length]) !== 1)) continue;
|
|
7586
7604
|
for (const block of frame) members.set(block, frame);
|
|
7587
7605
|
}
|
|
7588
7606
|
const out = [];
|
|
@@ -7595,7 +7613,7 @@ function groupFrameParagraphUnits(units, frames) {
|
|
|
7595
7613
|
}
|
|
7596
7614
|
}
|
|
7597
7615
|
for (const unit of out) {
|
|
7598
|
-
if (unit.length < 2 || _optionalChain([FRAME_READING_UNITS, 'access',
|
|
7616
|
+
if (unit.length < 2 || _optionalChain([FRAME_READING_UNITS, 'access', _339 => _339.get, 'call', _340 => _340(unit[0]), 'optionalAccess', _341 => _341.blocks]) === unit) continue;
|
|
7599
7617
|
const bs = unit.map((b) => b.bbox).filter((b) => !!b);
|
|
7600
7618
|
if (bs.length !== unit.length) continue;
|
|
7601
7619
|
const x = Math.min(...bs.map((b) => b.x)), y = Math.min(...bs.map((b) => b.y));
|
|
@@ -7612,14 +7630,14 @@ function groupFrameParagraphUnits(units, frames) {
|
|
|
7612
7630
|
function recordFrameTitle(table, source, pageNum) {
|
|
7613
7631
|
if (!CLIP_TABLES.has(table) || table.rows !== 1 || table.cols !== 3 || source.length < 2) return;
|
|
7614
7632
|
const cells = table.cells[0];
|
|
7615
|
-
if (cells.length !== 3 || cells.some((c) => c.colSpan !== 1 || c.rowSpan !== 1 || _optionalChain([c, 'access',
|
|
7633
|
+
if (cells.length !== 3 || cells.some((c) => c.colSpan !== 1 || c.rowSpan !== 1 || _optionalChain([c, 'access', _342 => _342.blocks, 'optionalAccess', _343 => _343.length]) || c.text.includes("\n"))) return;
|
|
7616
7634
|
const [label, spacer, title] = cells;
|
|
7617
7635
|
if (!/^(?:붙임|별첨|첨부|부록)\s*\d{1,3}$/.test(label.text.trim()) || spacer.text.trim() || !title.text.trim()) return;
|
|
7618
7636
|
if (cells.some((c) => {
|
|
7619
|
-
const e =
|
|
7637
|
+
const e = _chunkQA5KN5ITcjs.CELL_EDGES.get(c);
|
|
7620
7638
|
return !e || e.t || e.b || e.l || e.r;
|
|
7621
7639
|
})) return;
|
|
7622
|
-
const xs = TABLE_COLXS.get(table), style = dominantStyle(source), fs = _nullishCoalesce(_optionalChain([style, 'optionalAccess',
|
|
7640
|
+
const xs = TABLE_COLXS.get(table), style = dominantStyle(source), fs = _nullishCoalesce(_optionalChain([style, 'optionalAccess', _344 => _344.fontSize]), () => ( 0));
|
|
7623
7641
|
if (!xs || xs.length !== 4 || fs <= 0) return;
|
|
7624
7642
|
const width = xs[3] - xs[0], gap = xs[2] - xs[1];
|
|
7625
7643
|
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;
|
|
@@ -7677,7 +7695,7 @@ function extendNestedShadedHeaders(clipGrids, lineGrids, horizontals, verticals,
|
|
|
7677
7695
|
const extended = [];
|
|
7678
7696
|
for (let i = 0; i < clipGrids.length; i++) {
|
|
7679
7697
|
const c = clipGrids[i], parent = c.clipParent;
|
|
7680
|
-
if (!parent || c.rowYs.length !== 2 || c.colXs.length < 3 || !_optionalChain([c, 'access',
|
|
7698
|
+
if (!parent || c.rowYs.length !== 2 || c.colXs.length < 3 || !_optionalChain([c, 'access', _345 => _345.cells, 'optionalAccess', _346 => _346.length]) || c.cells.some((cell) => cell.filler || cell.rowSpan !== 1 || cell.colSpan !== 1)) continue;
|
|
7681
7699
|
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;
|
|
7682
7700
|
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;
|
|
7683
7701
|
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)));
|
|
@@ -7700,7 +7718,7 @@ function attachSideTabBlocks(tab, body, pageNum) {
|
|
|
7700
7718
|
bbox: computeBBox(items, pageNum),
|
|
7701
7719
|
style: dominantStyle(items)
|
|
7702
7720
|
});
|
|
7703
|
-
const prefix = ordered.filter((g) => !_optionalChain([caps, 'optionalAccess',
|
|
7721
|
+
const prefix = ordered.filter((g) => !_optionalChain([caps, 'optionalAccess', _347 => _347.has, 'call', _348 => _348(g)])).map((g) => ({
|
|
7704
7722
|
type: "paragraph",
|
|
7705
7723
|
text: g.text.trim(),
|
|
7706
7724
|
pageNumber: pageNum,
|
|
@@ -7709,7 +7727,7 @@ function attachSideTabBlocks(tab, body, pageNum) {
|
|
|
7709
7727
|
}));
|
|
7710
7728
|
const groups = /* @__PURE__ */ new Map();
|
|
7711
7729
|
for (const g of ordered) {
|
|
7712
|
-
const cap = _optionalChain([caps, 'optionalAccess',
|
|
7730
|
+
const cap = _optionalChain([caps, 'optionalAccess', _349 => _349.get, 'call', _350 => _350(g)]);
|
|
7713
7731
|
if (cap) groups.set(cap, [..._nullishCoalesce(groups.get(cap), () => ( [])), g]);
|
|
7714
7732
|
}
|
|
7715
7733
|
for (const [cap, glyphs] of groups) {
|
|
@@ -7743,7 +7761,7 @@ function extractPageBlocksWithLines(items, pageNum, opList, pageWidth, pageHeigh
|
|
|
7743
7761
|
const filled = fillBlanks(items, horizontals, verticals);
|
|
7744
7762
|
items = filled.items;
|
|
7745
7763
|
horizontals = filled.horizontals;
|
|
7746
|
-
const prevPage = _optionalChain([carry, 'optionalAccess',
|
|
7764
|
+
const prevPage = _optionalChain([carry, 'optionalAccess', _351 => _351.page]) === pageNum - 1 ? carry.clip : void 0;
|
|
7747
7765
|
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 };
|
|
7748
7766
|
if (carry) {
|
|
7749
7767
|
carry.page = pageNum;
|
|
@@ -8000,6 +8018,7 @@ function extractBlocksWithGrids(items, pageNum, pageWidth, pageHeight, grids, ho
|
|
|
8000
8018
|
fontName: i.fontName,
|
|
8001
8019
|
hasSpaceBefore: i.hasSpaceBefore,
|
|
8002
8020
|
syntheticSpace: i.syntheticSpace,
|
|
8021
|
+
spaceAfter: i.spaceAfter,
|
|
8003
8022
|
seq: i.seq
|
|
8004
8023
|
}, cells).map((t) => {
|
|
8005
8024
|
owners.push(i);
|
|
@@ -8071,14 +8090,14 @@ function extractBlocksWithGrids(items, pageNum, pageWidth, pageHeight, grids, ho
|
|
|
8071
8090
|
if (!assignedItems.has(textItems[ti])) usedItems.delete(owners[ti]);
|
|
8072
8091
|
}
|
|
8073
8092
|
}
|
|
8074
|
-
if (unitLine.length > 0 && rebuiltUsed && !/^\s*\(\s*단위\s*[::]/.test(_nullishCoalesce(_optionalChain([finalGrid, 'access',
|
|
8093
|
+
if (unitLine.length > 0 && rebuiltUsed && !/^\s*\(\s*단위\s*[::]/.test(_nullishCoalesce(_optionalChain([finalGrid, 'access', _352 => _352[0], 'optionalAccess', _353 => _353[0], 'optionalAccess', _354 => _354.text]), () => ( "")))) {
|
|
8075
8094
|
prependUnitRow(finalGrid, numCols, unitLine, usedItems);
|
|
8076
8095
|
finalRows++;
|
|
8077
8096
|
}
|
|
8078
8097
|
if (!rebuiltUsed && attachUnitRow(items, grid, finalGrid, numCols, usedItems)) finalRows++;
|
|
8079
8098
|
let semanticOneColumn = false;
|
|
8080
8099
|
if (!grid.cells && !nestedAttached && numCols === 1 && numGridRows >= 2) {
|
|
8081
|
-
const populatedRows = finalGrid.filter((row) => _optionalChain([row, 'access',
|
|
8100
|
+
const populatedRows = finalGrid.filter((row) => _optionalChain([row, 'access', _355 => _355[0], 'optionalAccess', _356 => _356.text, 'access', _357 => _357.trim, 'call', _358 => _358()]));
|
|
8082
8101
|
if (populatedRows.length >= 4) {
|
|
8083
8102
|
const fontSizes = tableItems.map((item) => item.fontSize).filter((size) => size > 0).sort((a, b) => a - b);
|
|
8084
8103
|
const medianFont = _nullishCoalesce(fontSizes[Math.floor(fontSizes.length / 2)], () => ( 0));
|
|
@@ -8105,6 +8124,7 @@ function extractBlocksWithGrids(items, pageNum, pageWidth, pageHeight, grids, ho
|
|
|
8105
8124
|
fontName: i.fontName,
|
|
8106
8125
|
hasSpaceBefore: i.hasSpaceBefore,
|
|
8107
8126
|
syntheticSpace: i.syntheticSpace,
|
|
8127
|
+
spaceAfter: i.spaceAfter,
|
|
8108
8128
|
seq: i.seq
|
|
8109
8129
|
})))), colSpan: 1, rowSpan: 1 })));
|
|
8110
8130
|
finalRows++;
|
|
@@ -8173,7 +8193,7 @@ function extractBlocksWithGrids(items, pageNum, pageWidth, pageHeight, grids, ho
|
|
|
8173
8193
|
height: grid.bbox.y2 - grid.bbox.y1
|
|
8174
8194
|
};
|
|
8175
8195
|
if (numRows === 1 && numCols === 1 && gridW < pageWidth * 0.35) {
|
|
8176
|
-
const prose = _nullishCoalesce(_optionalChain([finalGrid, 'access',
|
|
8196
|
+
const prose = _nullishCoalesce(_optionalChain([finalGrid, 'access', _359 => _359[0], 'optionalAccess', _360 => _360[0], 'optionalAccess', _361 => _361.text]), () => ( ""));
|
|
8177
8197
|
const besideLines = (side) => new Set(side.map((it) => Math.round(it.y / 3))).size;
|
|
8178
8198
|
const rightLines = items.filter((it) => it.x >= grid.bbox.x2 + 3 && it.y >= grid.bbox.y1 && it.y <= grid.bbox.y2);
|
|
8179
8199
|
const leftLines = items.filter((it) => it.x + it.w <= grid.bbox.x1 - 3 && it.y >= grid.bbox.y1 && it.y <= grid.bbox.y2);
|
|
@@ -8192,8 +8212,8 @@ function extractBlocksWithGrids(items, pageNum, pageWidth, pageHeight, grids, ho
|
|
|
8192
8212
|
}
|
|
8193
8213
|
}
|
|
8194
8214
|
if (!grid.cells && !nestedAttached && shouldDemoteTable(irTable)) {
|
|
8195
|
-
const paragraphs = numRows === 1 && numCols === 1 ? _optionalChain([irTable, 'access',
|
|
8196
|
-
if (_optionalChain([paragraphs, 'optionalAccess',
|
|
8215
|
+
const paragraphs = numRows === 1 && numCols === 1 ? _optionalChain([irTable, 'access', _362 => _362.cells, 'access', _363 => _363[0], 'optionalAccess', _364 => _364[0], 'optionalAccess', _365 => _365.blocks]) : void 0;
|
|
8216
|
+
if (_optionalChain([paragraphs, 'optionalAccess', _366 => _366.length])) {
|
|
8197
8217
|
blocks.push(...paragraphs);
|
|
8198
8218
|
frameParagraphUnits.push(paragraphs);
|
|
8199
8219
|
recordFrameReadingUnit(paragraphs, tableBbox);
|
|
@@ -8229,13 +8249,14 @@ function extractBlocksWithGrids(items, pageNum, pageWidth, pageHeight, grids, ho
|
|
|
8229
8249
|
fontSize: i.fontSize,
|
|
8230
8250
|
fontName: i.fontName,
|
|
8231
8251
|
hasSpaceBefore: i.hasSpaceBefore,
|
|
8232
|
-
syntheticSpace: i.syntheticSpace
|
|
8252
|
+
syntheticSpace: i.syntheticSpace,
|
|
8253
|
+
spaceAfter: i.spaceAfter
|
|
8233
8254
|
}));
|
|
8234
8255
|
const proseColumns = findTwoColumnProseCutX(clusterItems) !== null || detectPersistentColumnGutter(remaining.map((i) => ({ x: i.x, y: i.y, w: i.w, h: i.h > 0 ? i.h : i.fontSize }))) !== null;
|
|
8235
8256
|
const clusterResults = (proseColumns ? [] : detectClusterTables(clusterItems, pageNum)).filter((cr) => {
|
|
8236
8257
|
const b = cr.bbox;
|
|
8237
8258
|
const overlapX = (x) => Math.min(x.x + x.width, b.x + b.width) - Math.max(x.x, b.x);
|
|
8238
|
-
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',
|
|
8259
|
+
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', _367 => _367.text, 'optionalAccess', _368 => _368.match, 'call', _369 => _369(/\p{L}/gu), 'optionalAccess', _370 => _370.length]), () => ( 0))) >= 10 && overlapX(x.bbox) >= 0.8 * b.width : x.type === "table" && !ocrPage && _optionalChain([x, 'access', _371 => _371.table, 'optionalAccess', _372 => _372.cols]) === cr.table.cols && overlapX(x.bbox) >= 0.5 * Math.min(x.bbox.width, b.width)));
|
|
8239
8260
|
});
|
|
8240
8261
|
if (clusterResults.length > 0) {
|
|
8241
8262
|
const ciToIdx = /* @__PURE__ */ new Map();
|
|
@@ -8272,7 +8293,7 @@ function extractBlocksWithGrids(items, pageNum, pageWidth, pageHeight, grids, ho
|
|
|
8272
8293
|
groupSizes.push(1);
|
|
8273
8294
|
}
|
|
8274
8295
|
const allY = remaining.map((i) => i.y);
|
|
8275
|
-
const pageH =
|
|
8296
|
+
const pageH = _chunkQ2BKBY3Ocjs.safeMax.call(void 0, allY) - _chunkQ2BKBY3Ocjs.safeMin.call(void 0, allY);
|
|
8276
8297
|
const gapThreshold = Math.max(15, pageH * 0.03);
|
|
8277
8298
|
const sides = frameColumnTextBands(remaining, spanning, gx);
|
|
8278
8299
|
const textBlocks = [];
|
|
@@ -8288,7 +8309,7 @@ function extractBlocksWithGrids(items, pageNum, pageWidth, pageHeight, grids, ho
|
|
|
8288
8309
|
finalTextBlocks.push(...detectListBlocks(textBlocks));
|
|
8289
8310
|
} else {
|
|
8290
8311
|
const allY = remaining.map((i) => i.y);
|
|
8291
|
-
const pageH =
|
|
8312
|
+
const pageH = _chunkQ2BKBY3Ocjs.safeMax.call(void 0, allY) - _chunkQ2BKBY3Ocjs.safeMin.call(void 0, allY);
|
|
8292
8313
|
const gapThreshold = Math.max(15, pageH * 0.03);
|
|
8293
8314
|
const groups = xyCutOrder(remaining, gapThreshold);
|
|
8294
8315
|
const textBlocks = [];
|
|
@@ -8555,7 +8576,8 @@ function extractPageBlocksFallback(items, pageNum, fullPage = false, detectTable
|
|
|
8555
8576
|
fontSize: i.fontSize,
|
|
8556
8577
|
fontName: i.fontName,
|
|
8557
8578
|
hasSpaceBefore: i.hasSpaceBefore,
|
|
8558
|
-
syntheticSpace: i.syntheticSpace
|
|
8579
|
+
syntheticSpace: i.syntheticSpace,
|
|
8580
|
+
spaceAfter: i.spaceAfter
|
|
8559
8581
|
}));
|
|
8560
8582
|
const textRects = items.map((i) => ({ x: i.x, y: i.y, w: i.w, h: i.h > 0 ? i.h : i.fontSize }));
|
|
8561
8583
|
const imagePanels = fullPage ? splitImagePanels(items, figures) : null;
|
|
@@ -8615,7 +8637,7 @@ function extractPageBlocksFallback(items, pageNum, fullPage = false, detectTable
|
|
|
8615
8637
|
blocks.push(...columnTextToBlocks(tableText, pageNum, bbox, dominantStyle(items)));
|
|
8616
8638
|
} else {
|
|
8617
8639
|
const allY = items.map((i) => i.y);
|
|
8618
|
-
const pageHeight =
|
|
8640
|
+
const pageHeight = _chunkQ2BKBY3Ocjs.safeMax.call(void 0, allY) - _chunkQ2BKBY3Ocjs.safeMin.call(void 0, allY);
|
|
8619
8641
|
const gapThreshold = Math.max(15, pageHeight * 0.03);
|
|
8620
8642
|
const orderedGroups = proseCutX !== null ? splitTwoColumnProse(items, proseCutX) : xyCutOrder(items, gapThreshold, 0, void 0, minGap);
|
|
8621
8643
|
for (const group of orderedGroups) {
|
|
@@ -8647,17 +8669,17 @@ function mergeOcrImageRegions(blocks, page, regions, ocrBlocks) {
|
|
|
8647
8669
|
const overlapH = Math.max(0, Math.min(b.y + b.height, region.y2) - Math.max(b.y, region.y1));
|
|
8648
8670
|
return overlapW * overlapH >= b.width * b.height * 0.8;
|
|
8649
8671
|
});
|
|
8650
|
-
const labels = candidates.filter((b) => b.type === "paragraph" && b.bbox.height <= 24 && (_nullishCoalesce(_optionalChain([b, 'access',
|
|
8672
|
+
const labels = candidates.filter((b) => b.type === "paragraph" && b.bbox.height <= 24 && (_nullishCoalesce(_optionalChain([b, 'access', _373 => _373.text, 'optionalAccess', _374 => _374.match, 'call', _375 => _375(/[\p{L}\p{N}]/gu), 'optionalAccess', _376 => _376.length]), () => ( 0))) >= 2);
|
|
8651
8673
|
const axisFragments = rotatedAxisFragments(candidates);
|
|
8652
8674
|
const accepted = candidates.filter((b) => {
|
|
8653
|
-
if (b.type === "paragraph") return (_nullishCoalesce(_optionalChain([b, 'access',
|
|
8675
|
+
if (b.type === "paragraph") return (_nullishCoalesce(_optionalChain([b, 'access', _377 => _377.text, 'optionalAccess', _378 => _378.match, 'call', _379 => _379(/[\p{L}\p{N}]/gu), 'optionalAccess', _380 => _380.length]), () => ( 0))) >= 2 || !axisFragments.has(b) && (supportedDiagramLabel(b, labels, region) || axisTick(b, candidates));
|
|
8654
8676
|
const t = b.table;
|
|
8655
8677
|
if (b.type !== "table" || !t || UNRULED_REGION_TABLES.has(b)) return false;
|
|
8656
8678
|
if (t.rows === 1 && t.cols === 1) {
|
|
8657
|
-
const text = _nullishCoalesce(_optionalChain([t, 'access',
|
|
8658
|
-
return (_nullishCoalesce(_optionalChain([text, 'access',
|
|
8679
|
+
const text = _nullishCoalesce(_optionalChain([t, 'access', _381 => _381.cells, 'access', _382 => _382[0], 'optionalAccess', _383 => _383[0], 'optionalAccess', _384 => _384.text]), () => ( ""));
|
|
8680
|
+
return (_nullishCoalesce(_optionalChain([text, 'access', _385 => _385.match, 'call', _386 => _386(/\n/g), 'optionalAccess', _387 => _387.length]), () => ( 0))) >= 5 && (_nullishCoalesce(_optionalChain([text, 'access', _388 => _388.match, 'call', _389 => _389(/\d/g), 'optionalAccess', _390 => _390.length]), () => ( 0))) >= text.length * 0.25;
|
|
8659
8681
|
}
|
|
8660
|
-
const headerLabels = _nullishCoalesce(_optionalChain([t, 'access',
|
|
8682
|
+
const headerLabels = _nullishCoalesce(_optionalChain([t, 'access', _391 => _391.cells, 'access', _392 => _392[0], 'optionalAccess', _393 => _393.filter, 'call', _394 => _394((c) => c.text.replace(/[^A-Za-z가-힣]/g, "").length >= 2), 'access', _395 => _395.length]), () => ( 0));
|
|
8661
8683
|
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);
|
|
8662
8684
|
});
|
|
8663
8685
|
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, () => ( "")))) : []);
|
|
@@ -8674,14 +8696,14 @@ function mergeOcrImageRegions(blocks, page, regions, ocrBlocks) {
|
|
|
8674
8696
|
for (const block of selected) {
|
|
8675
8697
|
if (seen2.has(block)) continue;
|
|
8676
8698
|
const frame = FRAME_READING_UNITS.get(block);
|
|
8677
|
-
const source = _optionalChain([frame, 'optionalAccess',
|
|
8699
|
+
const source = _optionalChain([frame, 'optionalAccess', _396 => _396.blocks, 'access', _397 => _397.every, 'call', _398 => _398((member) => selectedSet.has(member))]) ? frame.blocks : [block];
|
|
8678
8700
|
source.forEach((member) => seen2.add(member));
|
|
8679
8701
|
const available = source.filter((member) => !hasOriginal(member));
|
|
8680
8702
|
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 }));
|
|
8681
8703
|
for (const unit of units) {
|
|
8682
8704
|
const b = unit.bbox;
|
|
8683
8705
|
const index = blocks.findIndex((existing) => {
|
|
8684
|
-
const e = _nullishCoalesce(_optionalChain([FRAME_READING_UNITS, 'access',
|
|
8706
|
+
const e = _nullishCoalesce(_optionalChain([FRAME_READING_UNITS, 'access', _399 => _399.get, 'call', _400 => _400(existing), 'optionalAccess', _401 => _401.bbox]), () => ( existing.bbox));
|
|
8685
8707
|
if (existing.pageNumber !== page || !e) return false;
|
|
8686
8708
|
const beside = e.y < region.y2 && e.y + e.height > region.y1 && e.x >= region.x2 - 1;
|
|
8687
8709
|
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;
|
|
@@ -8699,16 +8721,16 @@ function mergeOcrImageRegions(blocks, page, regions, ocrBlocks) {
|
|
|
8699
8721
|
}
|
|
8700
8722
|
function axisTick(block, candidates) {
|
|
8701
8723
|
const b = block.bbox;
|
|
8702
|
-
if (!/^\d$/u.test(_nullishCoalesce(_optionalChain([block, 'access',
|
|
8703
|
-
const numeric = candidates.filter((o) => o !== block && o.type === "paragraph" && o.bbox && /^[\d\s.,%+−-]+$/u.test(_nullishCoalesce(_optionalChain([o, 'access',
|
|
8724
|
+
if (!/^\d$/u.test(_nullishCoalesce(_optionalChain([block, 'access', _402 => _402.text, 'optionalAccess', _403 => _403.trim, 'call', _404 => _404()]), () => ( "")))) return false;
|
|
8725
|
+
const numeric = candidates.filter((o) => o !== block && o.type === "paragraph" && o.bbox && /^[\d\s.,%+−-]+$/u.test(_nullishCoalesce(_optionalChain([o, 'access', _405 => _405.text, 'optionalAccess', _406 => _406.trim, 'call', _407 => _407()]), () => ( ""))) && /\d/u.test(_nullishCoalesce(o.text, () => ( ""))) && Math.max(o.bbox.height, b.height) <= Math.min(o.bbox.height, b.height) * 2);
|
|
8704
8726
|
const cy = b.y + b.height / 2, right = b.x + b.width;
|
|
8705
8727
|
const row = numeric.filter((o) => Math.abs(o.bbox.y + o.bbox.height / 2 - cy) <= Math.min(o.bbox.height, b.height) * 0.35);
|
|
8706
8728
|
const column = numeric.filter((o) => Math.abs(o.bbox.x + o.bbox.width - right) <= Math.max(o.bbox.height, b.height) * 0.5);
|
|
8707
8729
|
return row.length >= 2 || column.length >= 2;
|
|
8708
8730
|
}
|
|
8709
8731
|
function supportedDiagramLabel(block, labels, region) {
|
|
8710
|
-
const b = block.bbox, text = _nullishCoalesce(_optionalChain([block, 'access',
|
|
8711
|
-
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',
|
|
8732
|
+
const b = block.bbox, text = _nullishCoalesce(_optionalChain([block, 'access', _408 => _408.text, 'optionalAccess', _409 => _409.trim, 'call', _410 => _410()]), () => ( ""));
|
|
8733
|
+
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', _411 => _411.text, 'optionalAccess', _412 => _412.match, 'call', _413 => _413(/\p{N}/gu), 'optionalAccess', _414 => _414.length]), () => ( 0))) >= 2).length < 2) return false;
|
|
8712
8734
|
let above = false, below = false;
|
|
8713
8735
|
for (const label of labels) {
|
|
8714
8736
|
const a = label.bbox, em = Math.max(b.height, a.height);
|
|
@@ -8723,7 +8745,7 @@ function rotatedAxisFragments(candidates) {
|
|
|
8723
8745
|
const paragraphs = candidates.filter((b) => b.type === "paragraph" && b.bbox.height <= 24);
|
|
8724
8746
|
const axes = [];
|
|
8725
8747
|
for (const block of paragraphs) {
|
|
8726
|
-
const b = block.bbox, text = _nullishCoalesce(_optionalChain([block, 'access',
|
|
8748
|
+
const b = block.bbox, text = _nullishCoalesce(_optionalChain([block, 'access', _415 => _415.text, 'optionalAccess', _416 => _416.trim, 'call', _417 => _417()]), () => ( ""));
|
|
8727
8749
|
if (!/^[\d\s.,%+−-]+$/u.test(text) || !/\d/u.test(text) || b.width > b.height * 6) continue;
|
|
8728
8750
|
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);
|
|
8729
8751
|
if (axis) axis.push(block);
|
|
@@ -8740,8 +8762,8 @@ function rotatedAxisFragments(candidates) {
|
|
|
8740
8762
|
const em = Math.max(...axis.map((a) => a.bbox.height)), right = axis[0].bbox.x + axis[0].bbox.width;
|
|
8741
8763
|
if (top - bottom < em * 6) continue;
|
|
8742
8764
|
const left = paragraphs.filter((block) => {
|
|
8743
|
-
const b = block.bbox, text = _nullishCoalesce(_optionalChain([block, 'access',
|
|
8744
|
-
return /\p{Script=Latin}/u.test(text) && (_nullishCoalesce(_optionalChain([text, 'access',
|
|
8765
|
+
const b = block.bbox, text = _nullishCoalesce(_optionalChain([block, 'access', _418 => _418.text, 'optionalAccess', _419 => _419.trim, 'call', _420 => _420()]), () => ( ""));
|
|
8766
|
+
return /\p{Script=Latin}/u.test(text) && (_nullishCoalesce(_optionalChain([text, 'access', _421 => _421.match, 'call', _422 => _422(/[\p{L}\p{N}]/gu), 'optionalAccess', _423 => _423.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;
|
|
8745
8767
|
});
|
|
8746
8768
|
const stack = left.filter((a) => left.some((b) => {
|
|
8747
8769
|
if (a === b || !aligned(a, b)) return false;
|
|
@@ -8751,7 +8773,7 @@ function rotatedAxisFragments(candidates) {
|
|
|
8751
8773
|
if (stack.length < 2) continue;
|
|
8752
8774
|
for (const block of paragraphs) {
|
|
8753
8775
|
const b = block.bbox;
|
|
8754
|
-
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',
|
|
8776
|
+
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', _424 => _424.text, 'optionalAccess', _425 => _425.trim, 'call', _426 => _426()]), () => ( ""))) && stack.some((s) => aligned(s, block))) fragments.add(block);
|
|
8755
8777
|
}
|
|
8756
8778
|
}
|
|
8757
8779
|
return fragments;
|
|
@@ -8826,4 +8848,4 @@ function rowParagraphs(block) {
|
|
|
8826
8848
|
|
|
8827
8849
|
|
|
8828
8850
|
exports.OCR_DET_MODEL = OCR_DET_MODEL; exports.OCR_REC_MODEL = OCR_REC_MODEL; exports.OCR_REC_DICT = OCR_REC_DICT; exports.getOcrModelsDir = getOcrModelsDir; exports.ensureOcrModels = ensureOcrModels; exports.ocrModelsCached = ocrModelsCached; exports.parseCharacterDict = parseCharacterDict; exports.extractLines = extractLines; exports.extractImageRegions = extractImageRegions; exports.filterHiddenText = filterHiddenText; exports.collapseEvenSpacing = collapseEvenSpacing; exports.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.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.NO_EDGES = NO_EDGES; exports.joinCellEdges = joinCellEdges; exports.restoreImageBullets = restoreImageBullets; exports.detectRightArrowRegions = detectRightArrowRegions; exports.removeSideTabs = removeSideTabs; exports.extractPageBlocksWithLines = extractPageBlocksWithLines; exports.UNRULED_REGION_TABLES = UNRULED_REGION_TABLES; exports.mergeOcrImageRegions = mergeOcrImageRegions;
|
|
8829
|
-
//# sourceMappingURL=chunk-
|
|
8851
|
+
//# sourceMappingURL=chunk-CHQLIGVR.cjs.map
|