kordoc 4.17.4 → 4.17.6
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/dist/{-SQRLFE4N.js → -Y6U3UTVZ.js} +11 -11
- package/dist/{chunk-RCS7WXOM.js → chunk-226C4AJR.js} +2 -2
- package/dist/{chunk-ODVIUG6Q.js → chunk-2WUE6JIT.js} +2 -2
- package/dist/{chunk-AOONZC4S.cjs → chunk-4LU6NGTL.cjs} +3 -3
- package/dist/{chunk-AOONZC4S.cjs.map → chunk-4LU6NGTL.cjs.map} +1 -1
- package/dist/{chunk-HY33WBAH.js → chunk-5VHV6W7W.js} +2 -2
- package/dist/{chunk-W3OY3SLY.js → chunk-6A4Z6VYA.js} +2 -2
- package/dist/{chunk-IERSVUW6.js → chunk-7F7CUU22.js} +2 -2
- package/dist/{chunk-TMHMJUYU.js → chunk-7R7NFGHY.js} +6 -6
- package/dist/{chunk-VJP7O6BL.js → chunk-AYMTRCLC.js} +2 -2
- package/dist/{chunk-P2ZPPRM7.js → chunk-B3RQHQCC.js} +2 -2
- package/dist/{chunk-PTMYCK7R.js → chunk-BPLEMV4B.js} +2 -2
- package/dist/{chunk-WNF3TSV3.cjs → chunk-CZOPNDTO.cjs} +426 -324
- package/dist/chunk-CZOPNDTO.cjs.map +1 -0
- package/dist/{chunk-EXBZHI25.cjs → chunk-FVESLY6V.cjs} +2 -2
- package/dist/{chunk-EXBZHI25.cjs.map → chunk-FVESLY6V.cjs.map} +1 -1
- package/dist/{chunk-7TE6TK52.js → chunk-HRJAAWEP.js} +2 -2
- package/dist/{chunk-AFXX3YSP.cjs → chunk-L5JX2GAM.cjs} +6 -6
- package/dist/{chunk-AFXX3YSP.cjs.map → chunk-L5JX2GAM.cjs.map} +1 -1
- package/dist/{chunk-GNORDND5.cjs → chunk-LLFXHX7K.cjs} +12 -12
- package/dist/{chunk-GNORDND5.cjs.map → chunk-LLFXHX7K.cjs.map} +1 -1
- package/dist/{chunk-O5T5OIJM.js → chunk-MOM67IND.js} +2 -2
- package/dist/{chunk-AAQR4RIX.js → chunk-MOVFO74W.js} +2 -2
- package/dist/{chunk-4D52VUGA.js → chunk-PGHIQ6E5.js} +3 -3
- package/dist/{chunk-PVJFCDND.js → chunk-QKEPDJ2D.js} +341 -239
- package/dist/chunk-QKEPDJ2D.js.map +1 -0
- package/dist/{chunk-KIYHQQVO.cjs → chunk-S26THA3Q.cjs} +3 -3
- package/dist/{chunk-KIYHQQVO.cjs.map → chunk-S26THA3Q.cjs.map} +1 -1
- package/dist/{chunk-DD6AY6EI.js → chunk-T5O6HEHG.js} +2 -2
- package/dist/{chunk-PNXJYEOR.js → chunk-TOCNK4VO.js} +2 -2
- package/dist/{chunk-FSCVZR4A.js → chunk-U6NLEEIN.js} +4 -4
- package/dist/{chunk-HQ6TM2JE.js → chunk-VHIGYTRO.js} +3 -3
- package/dist/{chunk-YBIWPCUX.js → chunk-YCMPQRHV.js} +342 -240
- package/dist/chunk-YCMPQRHV.js.map +1 -0
- package/dist/{chunk-NNNRN6BY.js → chunk-ZQA7Q3GV.js} +2 -2
- package/dist/{chunk-6DXSRQ65.js → chunk-ZQBBMUFA.js} +2 -2
- package/dist/{chunk-SSY6FQLS.js → chunk-ZS5KKM4L.js} +10 -10
- package/dist/chunks-S72SPTCL.js +10 -0
- package/dist/cli.js +26 -26
- package/dist/{formula-U37MTMBD.cjs → formula-3IQFGZXS.cjs} +9 -9
- package/dist/{formula-U37MTMBD.cjs.map → formula-3IQFGZXS.cjs.map} +1 -1
- package/dist/{formula-WZH5CMA3.js → formula-B72X7SFX.js} +3 -3
- package/dist/{formula-U3MJXXIL.js → formula-U7K3K4AE.js} +4 -4
- package/dist/{image-ocr-OXU55EW3.cjs → image-ocr-GYYVTTDG.cjs} +15 -15
- package/dist/{image-ocr-OXU55EW3.cjs.map → image-ocr-GYYVTTDG.cjs.map} +1 -1
- package/dist/{image-ocr-HYWDBN72.js → image-ocr-UGL5PWJ3.js} +6 -6
- package/dist/{image-ocr-V6MICC6R.js → image-ocr-YCBQ7HUD.js} +9 -9
- package/dist/index.cjs +259 -259
- package/dist/index.js +5 -5
- package/dist/mcp.js +22 -22
- package/dist/{model-bundle-AHBUQ6SD.js → model-bundle-Z4KSW4P5.js} +5 -5
- package/dist/{models-UF7B5LLG.js → models-HCI2GHBA.js} +5 -5
- package/dist/{parser-IXRGUYZW.cjs → parser-MZKMFBI3.cjs} +175 -157
- package/dist/parser-MZKMFBI3.cjs.map +1 -0
- package/dist/{parser-T4FBG2FR.js → parser-NFOHA5VI.js} +28 -10
- package/dist/{parser-F6N6ID25.js.map → parser-NFOHA5VI.js.map} +1 -1
- package/dist/{parser-F6N6ID25.js → parser-XCHUEHOX.js} +31 -13
- package/dist/{parser-T4FBG2FR.js.map → parser-XCHUEHOX.js.map} +1 -1
- package/dist/pdf-ocr-PXU6MBUZ.cjs +16 -0
- package/dist/{pdf-ocr-2CITOAIG.cjs.map → pdf-ocr-PXU6MBUZ.cjs.map} +1 -1
- package/dist/pdf-ocr-QQ6MJCXT.js +19 -0
- package/dist/pdf-ocr-WADZZ2YQ.js +15 -0
- package/dist/{profile-io-GM3NVLV3.js → profile-io-3BZXXOIW.js} +3 -3
- package/dist/{rasterize-4A3LJXTG.js → rasterize-SLLX5CQN.js} +3 -3
- package/dist/{redact-doc-SQ7C3LIG.js → redact-doc-CCOUCCQA.js} +11 -11
- package/dist/{render-6LTQZG4W.js → render-7OLLRV4U.js} +7 -7
- package/dist/seal-WGSATSQC.js +10 -0
- package/dist/{setup-DGBJOROA.js → setup-GONHHIMX.js} +3 -3
- package/dist/visual-C5D42ZAJ.js +20 -0
- package/dist/{watch-DJVJRSLE.js → watch-EWWEQI33.js} +12 -12
- package/package.json +1 -1
- package/dist/chunk-PVJFCDND.js.map +0 -1
- package/dist/chunk-WNF3TSV3.cjs.map +0 -1
- package/dist/chunk-YBIWPCUX.js.map +0 -1
- package/dist/chunks-VNSLMJQD.js +0 -10
- package/dist/parser-IXRGUYZW.cjs.map +0 -1
- package/dist/pdf-ocr-2CITOAIG.cjs +0 -16
- package/dist/pdf-ocr-RG2MFWBX.js +0 -15
- package/dist/pdf-ocr-U7Z4IUMA.js +0 -19
- package/dist/seal-ROSVLTRQ.js +0 -10
- package/dist/visual-6W34SFIW.js +0 -20
- /package/dist/{-SQRLFE4N.js.map → -Y6U3UTVZ.js.map} +0 -0
- /package/dist/{chunk-RCS7WXOM.js.map → chunk-226C4AJR.js.map} +0 -0
- /package/dist/{chunk-ODVIUG6Q.js.map → chunk-2WUE6JIT.js.map} +0 -0
- /package/dist/{chunk-HY33WBAH.js.map → chunk-5VHV6W7W.js.map} +0 -0
- /package/dist/{chunk-W3OY3SLY.js.map → chunk-6A4Z6VYA.js.map} +0 -0
- /package/dist/{chunk-IERSVUW6.js.map → chunk-7F7CUU22.js.map} +0 -0
- /package/dist/{chunk-TMHMJUYU.js.map → chunk-7R7NFGHY.js.map} +0 -0
- /package/dist/{chunk-VJP7O6BL.js.map → chunk-AYMTRCLC.js.map} +0 -0
- /package/dist/{chunk-P2ZPPRM7.js.map → chunk-B3RQHQCC.js.map} +0 -0
- /package/dist/{chunk-PTMYCK7R.js.map → chunk-BPLEMV4B.js.map} +0 -0
- /package/dist/{chunk-7TE6TK52.js.map → chunk-HRJAAWEP.js.map} +0 -0
- /package/dist/{chunk-O5T5OIJM.js.map → chunk-MOM67IND.js.map} +0 -0
- /package/dist/{chunk-AAQR4RIX.js.map → chunk-MOVFO74W.js.map} +0 -0
- /package/dist/{chunk-4D52VUGA.js.map → chunk-PGHIQ6E5.js.map} +0 -0
- /package/dist/{chunk-DD6AY6EI.js.map → chunk-T5O6HEHG.js.map} +0 -0
- /package/dist/{chunk-PNXJYEOR.js.map → chunk-TOCNK4VO.js.map} +0 -0
- /package/dist/{chunk-FSCVZR4A.js.map → chunk-U6NLEEIN.js.map} +0 -0
- /package/dist/{chunk-HQ6TM2JE.js.map → chunk-VHIGYTRO.js.map} +0 -0
- /package/dist/{chunk-NNNRN6BY.js.map → chunk-ZQA7Q3GV.js.map} +0 -0
- /package/dist/{chunk-6DXSRQ65.js.map → chunk-ZQBBMUFA.js.map} +0 -0
- /package/dist/{chunk-SSY6FQLS.js.map → chunk-ZS5KKM4L.js.map} +0 -0
- /package/dist/{chunks-VNSLMJQD.js.map → chunks-S72SPTCL.js.map} +0 -0
- /package/dist/{formula-WZH5CMA3.js.map → formula-B72X7SFX.js.map} +0 -0
- /package/dist/{formula-U3MJXXIL.js.map → formula-U7K3K4AE.js.map} +0 -0
- /package/dist/{image-ocr-HYWDBN72.js.map → image-ocr-UGL5PWJ3.js.map} +0 -0
- /package/dist/{image-ocr-V6MICC6R.js.map → image-ocr-YCBQ7HUD.js.map} +0 -0
- /package/dist/{model-bundle-AHBUQ6SD.js.map → model-bundle-Z4KSW4P5.js.map} +0 -0
- /package/dist/{models-UF7B5LLG.js.map → models-HCI2GHBA.js.map} +0 -0
- /package/dist/{pdf-ocr-RG2MFWBX.js.map → pdf-ocr-QQ6MJCXT.js.map} +0 -0
- /package/dist/{pdf-ocr-U7Z4IUMA.js.map → pdf-ocr-WADZZ2YQ.js.map} +0 -0
- /package/dist/{profile-io-GM3NVLV3.js.map → profile-io-3BZXXOIW.js.map} +0 -0
- /package/dist/{rasterize-4A3LJXTG.js.map → rasterize-SLLX5CQN.js.map} +0 -0
- /package/dist/{redact-doc-SQ7C3LIG.js.map → redact-doc-CCOUCCQA.js.map} +0 -0
- /package/dist/{render-6LTQZG4W.js.map → render-7OLLRV4U.js.map} +0 -0
- /package/dist/{seal-ROSVLTRQ.js.map → seal-WGSATSQC.js.map} +0 -0
- /package/dist/{setup-DGBJOROA.js.map → setup-GONHHIMX.js.map} +0 -0
- /package/dist/{visual-6W34SFIW.js.map → visual-C5D42ZAJ.js.map} +0 -0
- /package/dist/{watch-DJVJRSLE.js.map → watch-EWWEQI33.js.map} +0 -0
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import {
|
|
3
3
|
KordocError,
|
|
4
4
|
OPTIONAL_DEP_INSTALL_HINT
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-T5O6HEHG.js";
|
|
6
6
|
|
|
7
7
|
// src/render/rasterize.ts
|
|
8
8
|
var densityExponent = null;
|
|
@@ -88,4 +88,4 @@ export {
|
|
|
88
88
|
rasterizeSvg,
|
|
89
89
|
rasterizePageSvg
|
|
90
90
|
};
|
|
91
|
-
//# sourceMappingURL=chunk-
|
|
91
|
+
//# sourceMappingURL=chunk-MOM67IND.js.map
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
ensureModelsIn,
|
|
4
4
|
getModelStatusIn,
|
|
5
5
|
getModelsDir
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-HRJAAWEP.js";
|
|
7
7
|
|
|
8
8
|
// src/ocr/models.ts
|
|
9
9
|
import { join } from "path";
|
|
@@ -93,4 +93,4 @@ export {
|
|
|
93
93
|
parseCharacterDict,
|
|
94
94
|
ocrModelPath
|
|
95
95
|
};
|
|
96
|
-
//# sourceMappingURL=chunk-
|
|
96
|
+
//# sourceMappingURL=chunk-MOVFO74W.js.map
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
3
|
parseRenderStyles
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-6A4Z6VYA.js";
|
|
5
5
|
import {
|
|
6
6
|
KordocError,
|
|
7
7
|
precheckZipSize
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-T5O6HEHG.js";
|
|
9
9
|
|
|
10
10
|
// src/form/seal.ts
|
|
11
11
|
import JSZip from "jszip";
|
|
@@ -1057,4 +1057,4 @@ export {
|
|
|
1057
1057
|
patchZipEntries,
|
|
1058
1058
|
placeSealHwpx
|
|
1059
1059
|
};
|
|
1060
|
-
//# sourceMappingURL=chunk-
|
|
1060
|
+
//# sourceMappingURL=chunk-PGHIQ6E5.js.map
|
|
@@ -5,11 +5,11 @@ import {
|
|
|
5
5
|
HEADING_RATIO_H2,
|
|
6
6
|
HEADING_RATIO_H3,
|
|
7
7
|
tidyScriptTags
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-2WUE6JIT.js";
|
|
9
9
|
import {
|
|
10
10
|
safeMax,
|
|
11
11
|
safeMin
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-T5O6HEHG.js";
|
|
13
13
|
|
|
14
14
|
// src/pdf/line-extract.ts
|
|
15
15
|
import { OPS } from "pdfjs-dist/legacy/build/pdf.mjs";
|
|
@@ -3163,6 +3163,324 @@ function panelBlocks(items, panel, pageNum) {
|
|
|
3163
3163
|
});
|
|
3164
3164
|
}
|
|
3165
3165
|
|
|
3166
|
+
// src/pdf/xy-cut.ts
|
|
3167
|
+
var MAX_XYCUT_DEPTH = 50;
|
|
3168
|
+
var XYCUT_MIN_GAP = 5;
|
|
3169
|
+
var CROSS_LAYOUT_BETA = 2;
|
|
3170
|
+
var CROSS_OVERLAP_RATIO = 0.1;
|
|
3171
|
+
var CROSS_MIN_OVERLAPS = 2;
|
|
3172
|
+
var CROSS_MAX_MASK_RATIO = 0.2;
|
|
3173
|
+
var NARROW_ELEMENT_WIDTH_RATIO = 0.1;
|
|
3174
|
+
var PROSE_GUTTER_MIN_GAP = 6;
|
|
3175
|
+
var XY_WRAP_BANDS = /* @__PURE__ */ new WeakMap();
|
|
3176
|
+
var XY_WRAP_ITEMS = /* @__PURE__ */ new WeakMap();
|
|
3177
|
+
var leaf = (items, wrapped) => {
|
|
3178
|
+
wrapped = validWrapBands(items, wrapped);
|
|
3179
|
+
const source = wrapped.length ? [...items] : [];
|
|
3180
|
+
for (const item of items) {
|
|
3181
|
+
if (wrapped.length) {
|
|
3182
|
+
XY_WRAP_BANDS.set(item, wrapped);
|
|
3183
|
+
XY_WRAP_ITEMS.set(item, source);
|
|
3184
|
+
} else {
|
|
3185
|
+
XY_WRAP_BANDS.delete(item);
|
|
3186
|
+
XY_WRAP_ITEMS.delete(item);
|
|
3187
|
+
}
|
|
3188
|
+
}
|
|
3189
|
+
return [items];
|
|
3190
|
+
};
|
|
3191
|
+
function xyCutOrder(items, gapThreshold, depth = 0, wrapped) {
|
|
3192
|
+
if (items.length === 0) return [];
|
|
3193
|
+
const newRegion = wrapped === void 0;
|
|
3194
|
+
wrapped ??= inheritedWrapBands(items);
|
|
3195
|
+
if (items.length <= 2 || depth >= MAX_XYCUT_DEPTH) return leaf(items, wrapped);
|
|
3196
|
+
if (depth === 0 && items.length >= 3) {
|
|
3197
|
+
const cross = identifyCrossLayoutItems(items);
|
|
3198
|
+
if (cross.size > 0 && cross.size <= items.length * CROSS_MAX_MASK_RATIO) {
|
|
3199
|
+
const rest = items.filter((i) => !cross.has(i));
|
|
3200
|
+
if (rest.length > 0) {
|
|
3201
|
+
const groups = xyCutOrder(rest, gapThreshold, 1);
|
|
3202
|
+
return mergeCrossLayoutGroups(groups, [...cross]);
|
|
3203
|
+
}
|
|
3204
|
+
}
|
|
3205
|
+
}
|
|
3206
|
+
const minGap = Math.max(XYCUT_MIN_GAP, gapThreshold);
|
|
3207
|
+
const sortedY = [...items].sort((a, b) => b.y - a.y);
|
|
3208
|
+
let hCut = findHorizontalCut(sortedY, wrapped);
|
|
3209
|
+
if (newRegion && hCut.gap >= minGap) {
|
|
3210
|
+
wrapped = wrappedLineBands(items, wrapped);
|
|
3211
|
+
hCut = findHorizontalCut(sortedY, wrapped);
|
|
3212
|
+
}
|
|
3213
|
+
const vCut = findVerticalCutWithOutlierFilter(items, minGap);
|
|
3214
|
+
const hValid = hCut.gap >= minGap;
|
|
3215
|
+
const vValid = (vCut.gap >= minGap || vCut.gap >= PROSE_GUTTER_MIN_GAP && isProseGutter(items, vCut.position)) && !splitsSpacedLabel(items, vCut.position);
|
|
3216
|
+
let useHorizontal;
|
|
3217
|
+
if (hValid && vValid) useHorizontal = vCut.gap <= hCut.gap * 1.5 || staggeredSides(items, vCut.position);
|
|
3218
|
+
else if (hValid) useHorizontal = true;
|
|
3219
|
+
else if (vValid) useHorizontal = false;
|
|
3220
|
+
else return splitEdgeSpannedColumns(items, gapThreshold, depth) ?? leaf(items, wrapped);
|
|
3221
|
+
if (useHorizontal) {
|
|
3222
|
+
const upper = items.filter((i) => i.y > hCut.position);
|
|
3223
|
+
const lower = items.filter((i) => i.y <= hCut.position);
|
|
3224
|
+
if (upper.length > 0 && lower.length > 0 && upper.length < items.length) {
|
|
3225
|
+
return [...xyCutOrder(upper, gapThreshold, depth + 1, wrapped), ...xyCutOrder(lower, gapThreshold, depth + 1, wrapped)];
|
|
3226
|
+
}
|
|
3227
|
+
} else {
|
|
3228
|
+
const left = items.filter((i) => i.x + i.w / 2 < vCut.position);
|
|
3229
|
+
const right = items.filter((i) => i.x + i.w / 2 >= vCut.position);
|
|
3230
|
+
if (left.length > 0 && right.length > 0 && left.length < items.length) {
|
|
3231
|
+
return [...xyCutOrder(left, gapThreshold, depth + 1), ...xyCutOrder(right, gapThreshold, depth + 1)];
|
|
3232
|
+
}
|
|
3233
|
+
}
|
|
3234
|
+
return leaf(items, wrapped);
|
|
3235
|
+
}
|
|
3236
|
+
function splitsSpacedLabel(items, cutX) {
|
|
3237
|
+
const lone = (i) => /^[가-힣]$/.test(i.text.trim());
|
|
3238
|
+
const sameRow = (a, b) => Math.min(a.y, b.y) > Math.max(a.y - a.h, b.y - b.h);
|
|
3239
|
+
const left = items.filter((i) => i.x + i.w / 2 < cutX);
|
|
3240
|
+
const right = items.filter((i) => i.x + i.w / 2 >= cutX);
|
|
3241
|
+
let spaced = 0;
|
|
3242
|
+
for (const r of right) {
|
|
3243
|
+
if (right.some((o) => o !== r && o.x < r.x && sameRow(o, r))) continue;
|
|
3244
|
+
const row = left.filter((l2) => sameRow(l2, r));
|
|
3245
|
+
if (row.length === 0) continue;
|
|
3246
|
+
const l = row.reduce((a, b) => b.x + b.w > a.x + a.w ? b : a);
|
|
3247
|
+
if (!lone(l) || !lone(r)) return false;
|
|
3248
|
+
spaced++;
|
|
3249
|
+
}
|
|
3250
|
+
return spaced > 0;
|
|
3251
|
+
}
|
|
3252
|
+
function staggeredSides(items, cutX) {
|
|
3253
|
+
const left = items.filter((i) => i.x + i.w / 2 < cutX);
|
|
3254
|
+
const right = items.filter((i) => i.x + i.w / 2 >= cutX);
|
|
3255
|
+
if (left.length * right.length > 2e5) return false;
|
|
3256
|
+
const shareRow = (a, b) => Math.min(a.y, b.y) > Math.max(a.y - a.h, b.y - b.h);
|
|
3257
|
+
if (left.some((a) => right.some((b) => shareRow(a, b)))) return false;
|
|
3258
|
+
const sides = [...items].sort((a, b) => b.y - a.y).map((i) => i.x + i.w / 2 < cutX);
|
|
3259
|
+
let switches = 0;
|
|
3260
|
+
for (let k = 1; k < sides.length; k++) if (sides[k] !== sides[k - 1]) switches++;
|
|
3261
|
+
return switches >= 3;
|
|
3262
|
+
}
|
|
3263
|
+
function identifyCrossLayoutItems(items) {
|
|
3264
|
+
const cross = /* @__PURE__ */ new Set();
|
|
3265
|
+
if (items.length < 3) return cross;
|
|
3266
|
+
let maxWidth = 0;
|
|
3267
|
+
for (const i of items) {
|
|
3268
|
+
if (i.w > maxWidth) maxWidth = i.w;
|
|
3269
|
+
}
|
|
3270
|
+
const threshold = CROSS_LAYOUT_BETA * maxWidth;
|
|
3271
|
+
for (const item of items) {
|
|
3272
|
+
if (item.w < threshold) continue;
|
|
3273
|
+
let overlaps = 0;
|
|
3274
|
+
for (const other of items) {
|
|
3275
|
+
if (other === item) continue;
|
|
3276
|
+
const left = Math.max(item.x, other.x);
|
|
3277
|
+
const right = Math.min(item.x + item.w, other.x + other.w);
|
|
3278
|
+
const overlapW = right - left;
|
|
3279
|
+
if (overlapW <= 0) continue;
|
|
3280
|
+
const smaller = Math.min(item.w, other.w);
|
|
3281
|
+
if (smaller > 0 && overlapW / smaller >= CROSS_OVERLAP_RATIO) {
|
|
3282
|
+
overlaps++;
|
|
3283
|
+
if (overlaps >= CROSS_MIN_OVERLAPS) break;
|
|
3284
|
+
}
|
|
3285
|
+
}
|
|
3286
|
+
if (overlaps >= CROSS_MIN_OVERLAPS) cross.add(item);
|
|
3287
|
+
}
|
|
3288
|
+
return cross;
|
|
3289
|
+
}
|
|
3290
|
+
function mergeCrossLayoutGroups(groups, cross) {
|
|
3291
|
+
if (cross.length === 0) return groups;
|
|
3292
|
+
const sortedCross = [...cross].sort((a, b) => b.y + b.h - (a.y + a.h) || a.x - b.x);
|
|
3293
|
+
const groupTop = (g) => {
|
|
3294
|
+
let top = -Infinity;
|
|
3295
|
+
for (const i of g) {
|
|
3296
|
+
const t = i.y + i.h;
|
|
3297
|
+
if (t > top) top = t;
|
|
3298
|
+
}
|
|
3299
|
+
return top;
|
|
3300
|
+
};
|
|
3301
|
+
const result = [];
|
|
3302
|
+
let gi = 0, ci = 0;
|
|
3303
|
+
while (gi < groups.length || ci < sortedCross.length) {
|
|
3304
|
+
if (ci >= sortedCross.length) {
|
|
3305
|
+
result.push(groups[gi++]);
|
|
3306
|
+
continue;
|
|
3307
|
+
}
|
|
3308
|
+
if (gi >= groups.length) {
|
|
3309
|
+
result.push([sortedCross[ci++]]);
|
|
3310
|
+
continue;
|
|
3311
|
+
}
|
|
3312
|
+
const crossTop = sortedCross[ci].y + sortedCross[ci].h;
|
|
3313
|
+
if (crossTop >= groupTop(groups[gi])) result.push([sortedCross[ci++]]);
|
|
3314
|
+
else result.push(groups[gi++]);
|
|
3315
|
+
}
|
|
3316
|
+
return result;
|
|
3317
|
+
}
|
|
3318
|
+
function validWrapBands(items, bands) {
|
|
3319
|
+
if (!bands.length) return [];
|
|
3320
|
+
const present = new Set(items);
|
|
3321
|
+
return bands.filter((b) => b.sources.every(({ item: a, state: s }) => present.has(a) && a.text === s.text && a.x === s.x && a.y === s.y && a.w === s.w && a.h === s.h && a.fontSize === s.fontSize && a.fontName === s.fontName && a.isHidden === s.isHidden && a.hasSpaceBefore === s.hasSpaceBefore && a.syntheticSpace === s.syntheticSpace && a.strike === s.strike && a.underline === s.underline && a.seq === s.seq && a.rotated === s.rotated));
|
|
3322
|
+
}
|
|
3323
|
+
function inheritedWrapBands(items) {
|
|
3324
|
+
const source = XY_WRAP_ITEMS.get(items[0]);
|
|
3325
|
+
const present = source?.length === items.length ? new Set(items) : null;
|
|
3326
|
+
const sameLeaf = present && source.every((item) => present.has(item));
|
|
3327
|
+
return sameLeaf ? validWrapBands(items, XY_WRAP_BANDS.get(items[0]) ?? []) : [];
|
|
3328
|
+
}
|
|
3329
|
+
function tocRecordBoundaries(rows) {
|
|
3330
|
+
const out = /* @__PURE__ */ new Set();
|
|
3331
|
+
if (rows.length < 2) return out;
|
|
3332
|
+
const records = rows.map((row, index) => {
|
|
3333
|
+
const visible = row.filter((i) => i.text.trim()).sort((a, b) => a.x - b.x);
|
|
3334
|
+
let start = visible.length - 1;
|
|
3335
|
+
if (start < 1 || !/^\d+$/.test(visible[start].text.trim())) return null;
|
|
3336
|
+
for (; start > 0; start--) {
|
|
3337
|
+
const a = visible[start - 1], b = visible[start];
|
|
3338
|
+
if (!/^\d+$/.test(a.text.trim()) || b.x - (a.x + a.w) > 0.5 * b.fontSize) break;
|
|
3339
|
+
}
|
|
3340
|
+
const nums = visible.slice(start), label = visible.slice(0, start).filter((i) => !/^[·.⋯…]{4,}$/.test(i.text.trim()));
|
|
3341
|
+
const fs = nums[0].fontSize;
|
|
3342
|
+
if (!/^\d{1,4}$/.test(nums.map((i) => i.text.trim()).join("")) || fs <= 0 || !label.some((i) => /[\p{L}]/u.test(i.text)) || nums[0].x - Math.max(...label.map((i) => i.x + i.w)) < Math.max(2 * fs, 30)) return null;
|
|
3343
|
+
return { right: Math.max(...nums.map((i) => i.x + i.w)), fs, index };
|
|
3344
|
+
}).filter((record) => record !== null).sort((a, b) => a.right - b.right);
|
|
3345
|
+
for (let i = 0; i + 1 < records.length; i++) {
|
|
3346
|
+
const a = records[i], b = records[i + 1];
|
|
3347
|
+
if (Math.abs(a.right - b.right) <= 0.5 * Math.min(a.fs, b.fs) && Math.abs(a.fs - b.fs) <= 0.15 * Math.min(a.fs, b.fs)) {
|
|
3348
|
+
if (a.index + 1 < rows.length) out.add(a.index);
|
|
3349
|
+
if (b.index + 1 < rows.length) out.add(b.index);
|
|
3350
|
+
}
|
|
3351
|
+
}
|
|
3352
|
+
return out;
|
|
3353
|
+
}
|
|
3354
|
+
function wrappedLineBands(items, inherited) {
|
|
3355
|
+
const rows = groupByY(items);
|
|
3356
|
+
const records = tocRecordBoundaries(rows);
|
|
3357
|
+
const lines = rows.map((row) => {
|
|
3358
|
+
const box = computeBBox(row, 0);
|
|
3359
|
+
return {
|
|
3360
|
+
text: mergeLineSimple(row).replace(/<\/?u>|~~/g, ""),
|
|
3361
|
+
left: box.x,
|
|
3362
|
+
right: box.x + box.width,
|
|
3363
|
+
y: row.reduce((n, i) => n + i.y, 0) / row.length,
|
|
3364
|
+
fontSize: dominantStyle(row)?.fontSize ?? 0,
|
|
3365
|
+
sources: row.map((item) => ({ item, state: { ...item } }))
|
|
3366
|
+
};
|
|
3367
|
+
});
|
|
3368
|
+
const joins = bodyLineJoins(lines);
|
|
3369
|
+
const fresh = lines.slice(0, -1).flatMap((line, i) => joins[i] === "\n" || records.has(i) || line.text.trim() === lines[i + 1].text.trim() ? [] : [{ top: line.y, bottom: lines[i + 1].y, sources: [...line.sources, ...lines[i + 1].sources] }]);
|
|
3370
|
+
const freshKeys = new Set(fresh.map((b) => `${b.top}:${b.bottom}`));
|
|
3371
|
+
return [...inherited.filter((b) => !freshKeys.has(`${b.top}:${b.bottom}`)), ...fresh].sort((a, b) => b.top - a.top);
|
|
3372
|
+
}
|
|
3373
|
+
function findHorizontalCut(sorted, wrapped) {
|
|
3374
|
+
if (sorted.length < 2) return { position: 0, gap: 0 };
|
|
3375
|
+
let largestGap = 0;
|
|
3376
|
+
let position = 0;
|
|
3377
|
+
let wrapIndex = 0;
|
|
3378
|
+
for (let i = 1; i < sorted.length; i++) {
|
|
3379
|
+
const prevBottom = sorted[i - 1].y - sorted[i - 1].h;
|
|
3380
|
+
const currTop = sorted[i].y;
|
|
3381
|
+
const gap = prevBottom - currTop;
|
|
3382
|
+
if (gap <= 0) continue;
|
|
3383
|
+
const at = (prevBottom + currTop) / 2;
|
|
3384
|
+
while (wrapIndex < wrapped.length && at <= wrapped[wrapIndex].bottom) wrapIndex++;
|
|
3385
|
+
const band = wrapped[wrapIndex];
|
|
3386
|
+
if (gap > largestGap && !(band && at < band.top && at > band.bottom)) {
|
|
3387
|
+
largestGap = gap;
|
|
3388
|
+
position = at;
|
|
3389
|
+
}
|
|
3390
|
+
}
|
|
3391
|
+
return { position, gap: largestGap };
|
|
3392
|
+
}
|
|
3393
|
+
function findVerticalCutWithOutlierFilter(items, minGap) {
|
|
3394
|
+
const edgeCut = findVerticalCut(items);
|
|
3395
|
+
if (edgeCut.gap >= minGap) return edgeCut;
|
|
3396
|
+
if (items.length >= 3) {
|
|
3397
|
+
let minX = Infinity, maxX = -Infinity;
|
|
3398
|
+
for (const i of items) {
|
|
3399
|
+
if (i.x < minX) minX = i.x;
|
|
3400
|
+
const r = i.x + i.w;
|
|
3401
|
+
if (r > maxX) maxX = r;
|
|
3402
|
+
}
|
|
3403
|
+
const narrowThreshold = (maxX - minX) * NARROW_ELEMENT_WIDTH_RATIO;
|
|
3404
|
+
const filtered = items.filter((i) => i.w >= narrowThreshold);
|
|
3405
|
+
if (filtered.length >= 2 && filtered.length < items.length && filtered.length >= items.length * 0.7) {
|
|
3406
|
+
const filteredCut = findVerticalCut(filtered);
|
|
3407
|
+
if (filteredCut.gap > edgeCut.gap && filteredCut.gap >= minGap) {
|
|
3408
|
+
return filteredCut;
|
|
3409
|
+
}
|
|
3410
|
+
}
|
|
3411
|
+
}
|
|
3412
|
+
return edgeCut;
|
|
3413
|
+
}
|
|
3414
|
+
function findVerticalCut(items) {
|
|
3415
|
+
if (items.length < 2) return { position: 0, gap: 0 };
|
|
3416
|
+
const sorted = [...items].sort((a, b) => a.x - b.x || a.x + a.w - (b.x + b.w));
|
|
3417
|
+
let largestGap = 0;
|
|
3418
|
+
let position = 0;
|
|
3419
|
+
let prevRight = null;
|
|
3420
|
+
for (const it of sorted) {
|
|
3421
|
+
const left = it.x;
|
|
3422
|
+
const right = it.x + it.w;
|
|
3423
|
+
if (prevRight !== null && left > prevRight) {
|
|
3424
|
+
const gap = left - prevRight;
|
|
3425
|
+
if (gap > largestGap) {
|
|
3426
|
+
largestGap = gap;
|
|
3427
|
+
position = (prevRight + left) / 2;
|
|
3428
|
+
}
|
|
3429
|
+
}
|
|
3430
|
+
prevRight = prevRight === null ? right : Math.max(prevRight, right);
|
|
3431
|
+
}
|
|
3432
|
+
return { position, gap: largestGap };
|
|
3433
|
+
}
|
|
3434
|
+
function isProseGutter(items, x) {
|
|
3435
|
+
const sideLines = (side) => {
|
|
3436
|
+
const lines = [];
|
|
3437
|
+
for (const item of [...side].sort((a, b) => b.y - a.y)) {
|
|
3438
|
+
const line = lines.find((l) => Math.abs(l.y - item.y) <= 2);
|
|
3439
|
+
if (line) {
|
|
3440
|
+
line.chars += item.text.length;
|
|
3441
|
+
line.left = Math.min(line.left, item.x);
|
|
3442
|
+
line.right = Math.max(line.right, item.x + item.w);
|
|
3443
|
+
} else lines.push({ y: item.y, chars: item.text.length, left: item.x, right: item.x + item.w });
|
|
3444
|
+
}
|
|
3445
|
+
return lines;
|
|
3446
|
+
};
|
|
3447
|
+
const left = sideLines(items.filter((i) => i.x + i.w / 2 < x));
|
|
3448
|
+
const right = sideLines(items.filter((i) => i.x + i.w / 2 >= x));
|
|
3449
|
+
if (left.length < 4 || right.length < 4) return false;
|
|
3450
|
+
const prose = (lines) => {
|
|
3451
|
+
const width = Math.max(...lines.map((l) => l.right)) - Math.min(...lines.map((l) => l.left));
|
|
3452
|
+
const full = lines.filter((l) => l.chars >= 25 && l.right - l.left >= width * 0.6).length;
|
|
3453
|
+
return full >= lines.length * 0.6;
|
|
3454
|
+
};
|
|
3455
|
+
if (!prose(left) || !prose(right)) return false;
|
|
3456
|
+
const span = (lines) => [Math.min(...lines.map((l) => l.y)), Math.max(...lines.map((l) => l.y))];
|
|
3457
|
+
const [l0, l1] = span(left), [r0, r1] = span(right);
|
|
3458
|
+
return Math.min(l1, r1) - Math.max(l0, r0) >= Math.min(l1 - l0, r1 - r0) * 0.5;
|
|
3459
|
+
}
|
|
3460
|
+
function splitEdgeSpannedColumns(items, gapThreshold, depth) {
|
|
3461
|
+
let minX = Infinity, maxX = -Infinity;
|
|
3462
|
+
for (const i of items) {
|
|
3463
|
+
minX = Math.min(minX, i.x);
|
|
3464
|
+
maxX = Math.max(maxX, i.x + i.w);
|
|
3465
|
+
}
|
|
3466
|
+
const narrow = items.filter((i) => i.w < (maxX - minX) * 0.5);
|
|
3467
|
+
if (narrow.length === items.length || narrow.length < 8) return null;
|
|
3468
|
+
const cut = findVerticalCut(narrow);
|
|
3469
|
+
if (cut.gap < PROSE_GUTTER_MIN_GAP || !isProseGutter(narrow, cut.position)) return null;
|
|
3470
|
+
const crossing = items.filter((i) => i.x < cut.position && i.x + i.w > cut.position);
|
|
3471
|
+
const rest = items.filter((i) => !crossing.includes(i));
|
|
3472
|
+
const restTop = Math.max(...rest.map((i) => i.y)), restBottom = Math.min(...rest.map((i) => i.y));
|
|
3473
|
+
const above = crossing.filter((i) => i.y > restTop), below = crossing.filter((i) => i.y < restBottom);
|
|
3474
|
+
if (above.length + below.length !== crossing.length) return null;
|
|
3475
|
+
const left = rest.filter((i) => i.x + i.w / 2 < cut.position), right = rest.filter((i) => i.x + i.w / 2 >= cut.position);
|
|
3476
|
+
return [
|
|
3477
|
+
...above.length ? [above] : [],
|
|
3478
|
+
...xyCutOrder(left, gapThreshold, depth + 1),
|
|
3479
|
+
...xyCutOrder(right, gapThreshold, depth + 1),
|
|
3480
|
+
...below.length ? [below] : []
|
|
3481
|
+
];
|
|
3482
|
+
}
|
|
3483
|
+
|
|
3166
3484
|
// src/pdf/paragraph-lines.ts
|
|
3167
3485
|
var FACE_CHARS = /* @__PURE__ */ new WeakMap();
|
|
3168
3486
|
function hasNumberedStyledTitle(lines) {
|
|
@@ -3180,6 +3498,26 @@ function pushLineParagraphs(out, yLines, pageNum, lex) {
|
|
|
3180
3498
|
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: dominantStyle(l.items)?.fontSize ?? 0 };
|
|
3181
3499
|
});
|
|
3182
3500
|
const joins = bodyLineJoins(geo, lex);
|
|
3501
|
+
const first = lines[0]?.items[0];
|
|
3502
|
+
const bands = first ? XY_WRAP_BANDS.get(first) ?? [] : [];
|
|
3503
|
+
const hasBand = (top, bottom) => {
|
|
3504
|
+
let lo = 0, hi = bands.length;
|
|
3505
|
+
while (lo < hi) {
|
|
3506
|
+
const mid = lo + hi >>> 1;
|
|
3507
|
+
if (bands[mid].top > top + 3) lo = mid + 1;
|
|
3508
|
+
else hi = mid;
|
|
3509
|
+
}
|
|
3510
|
+
for (; lo < bands.length && bands[lo].top >= top - 3; lo++) {
|
|
3511
|
+
if (Math.abs(bands[lo].bottom - bottom) <= 3) return true;
|
|
3512
|
+
}
|
|
3513
|
+
return false;
|
|
3514
|
+
};
|
|
3515
|
+
for (let i = 0; i + 1 < geo.length; i++) {
|
|
3516
|
+
if (joins[i] === "\n" && Math.abs(geo[i + 1].fontSize - geo[i].fontSize) <= 0.15 * geo[i].fontSize && !startsNewItem(geo[i].text, geo[i + 1].text) && hasBand(geo[i].y, geo[i + 1].y)) {
|
|
3517
|
+
joins[i] = wrapJoiner(geo[i].text, geo[i + 1].text, lex);
|
|
3518
|
+
}
|
|
3519
|
+
}
|
|
3520
|
+
for (const i of tocRecordBoundaries(lines.map((line) => line.items))) joins[i] = "\n";
|
|
3183
3521
|
for (let i = 0; i + 1 < geo.length; i++) {
|
|
3184
3522
|
if (/^\d{1,2}$/.test(geo[i].text.trim()) && geo[i].fontSize >= geo[i + 1].fontSize * 1.2) joins[i] = "\n";
|
|
3185
3523
|
}
|
|
@@ -4863,242 +5201,6 @@ function findRuledColumnDivider(regions, horizontals, verticals, pageWidth, page
|
|
|
4863
5201
|
return candidates.length === 1 ? candidates[0] : null;
|
|
4864
5202
|
}
|
|
4865
5203
|
|
|
4866
|
-
// src/pdf/xy-cut.ts
|
|
4867
|
-
var MAX_XYCUT_DEPTH = 50;
|
|
4868
|
-
var XYCUT_MIN_GAP = 5;
|
|
4869
|
-
var CROSS_LAYOUT_BETA = 2;
|
|
4870
|
-
var CROSS_OVERLAP_RATIO = 0.1;
|
|
4871
|
-
var CROSS_MIN_OVERLAPS = 2;
|
|
4872
|
-
var CROSS_MAX_MASK_RATIO = 0.2;
|
|
4873
|
-
var NARROW_ELEMENT_WIDTH_RATIO = 0.1;
|
|
4874
|
-
var PROSE_GUTTER_MIN_GAP = 6;
|
|
4875
|
-
function xyCutOrder(items, gapThreshold, depth = 0) {
|
|
4876
|
-
if (items.length === 0) return [];
|
|
4877
|
-
if (items.length <= 2 || depth >= MAX_XYCUT_DEPTH) return [items];
|
|
4878
|
-
if (depth === 0 && items.length >= 3) {
|
|
4879
|
-
const cross = identifyCrossLayoutItems(items);
|
|
4880
|
-
if (cross.size > 0 && cross.size <= items.length * CROSS_MAX_MASK_RATIO) {
|
|
4881
|
-
const rest = items.filter((i) => !cross.has(i));
|
|
4882
|
-
if (rest.length > 0) {
|
|
4883
|
-
const groups = xyCutOrder(rest, gapThreshold, 1);
|
|
4884
|
-
return mergeCrossLayoutGroups(groups, [...cross]);
|
|
4885
|
-
}
|
|
4886
|
-
}
|
|
4887
|
-
}
|
|
4888
|
-
const minGap = Math.max(XYCUT_MIN_GAP, gapThreshold);
|
|
4889
|
-
const hCut = findHorizontalCut(items);
|
|
4890
|
-
const vCut = findVerticalCutWithOutlierFilter(items, minGap);
|
|
4891
|
-
const hValid = hCut.gap >= minGap;
|
|
4892
|
-
const vValid = (vCut.gap >= minGap || vCut.gap >= PROSE_GUTTER_MIN_GAP && isProseGutter(items, vCut.position)) && !splitsSpacedLabel(items, vCut.position);
|
|
4893
|
-
let useHorizontal;
|
|
4894
|
-
if (hValid && vValid) useHorizontal = vCut.gap <= hCut.gap * 1.5 || staggeredSides(items, vCut.position);
|
|
4895
|
-
else if (hValid) useHorizontal = true;
|
|
4896
|
-
else if (vValid) useHorizontal = false;
|
|
4897
|
-
else return splitEdgeSpannedColumns(items, gapThreshold, depth) ?? [items];
|
|
4898
|
-
if (useHorizontal) {
|
|
4899
|
-
const upper = items.filter((i) => i.y > hCut.position);
|
|
4900
|
-
const lower = items.filter((i) => i.y <= hCut.position);
|
|
4901
|
-
if (upper.length > 0 && lower.length > 0 && upper.length < items.length) {
|
|
4902
|
-
return [...xyCutOrder(upper, gapThreshold, depth + 1), ...xyCutOrder(lower, gapThreshold, depth + 1)];
|
|
4903
|
-
}
|
|
4904
|
-
} else {
|
|
4905
|
-
const left = items.filter((i) => i.x + i.w / 2 < vCut.position);
|
|
4906
|
-
const right = items.filter((i) => i.x + i.w / 2 >= vCut.position);
|
|
4907
|
-
if (left.length > 0 && right.length > 0 && left.length < items.length) {
|
|
4908
|
-
return [...xyCutOrder(left, gapThreshold, depth + 1), ...xyCutOrder(right, gapThreshold, depth + 1)];
|
|
4909
|
-
}
|
|
4910
|
-
}
|
|
4911
|
-
return [items];
|
|
4912
|
-
}
|
|
4913
|
-
function splitsSpacedLabel(items, cutX) {
|
|
4914
|
-
const lone = (i) => /^[가-힣]$/.test(i.text.trim());
|
|
4915
|
-
const sameRow = (a, b) => Math.min(a.y, b.y) > Math.max(a.y - a.h, b.y - b.h);
|
|
4916
|
-
const left = items.filter((i) => i.x + i.w / 2 < cutX);
|
|
4917
|
-
const right = items.filter((i) => i.x + i.w / 2 >= cutX);
|
|
4918
|
-
let spaced = 0;
|
|
4919
|
-
for (const r of right) {
|
|
4920
|
-
if (right.some((o) => o !== r && o.x < r.x && sameRow(o, r))) continue;
|
|
4921
|
-
const row = left.filter((l2) => sameRow(l2, r));
|
|
4922
|
-
if (row.length === 0) continue;
|
|
4923
|
-
const l = row.reduce((a, b) => b.x + b.w > a.x + a.w ? b : a);
|
|
4924
|
-
if (!lone(l) || !lone(r)) return false;
|
|
4925
|
-
spaced++;
|
|
4926
|
-
}
|
|
4927
|
-
return spaced > 0;
|
|
4928
|
-
}
|
|
4929
|
-
function staggeredSides(items, cutX) {
|
|
4930
|
-
const left = items.filter((i) => i.x + i.w / 2 < cutX);
|
|
4931
|
-
const right = items.filter((i) => i.x + i.w / 2 >= cutX);
|
|
4932
|
-
if (left.length * right.length > 2e5) return false;
|
|
4933
|
-
const shareRow = (a, b) => Math.min(a.y, b.y) > Math.max(a.y - a.h, b.y - b.h);
|
|
4934
|
-
if (left.some((a) => right.some((b) => shareRow(a, b)))) return false;
|
|
4935
|
-
const sides = [...items].sort((a, b) => b.y - a.y).map((i) => i.x + i.w / 2 < cutX);
|
|
4936
|
-
let switches = 0;
|
|
4937
|
-
for (let k = 1; k < sides.length; k++) if (sides[k] !== sides[k - 1]) switches++;
|
|
4938
|
-
return switches >= 3;
|
|
4939
|
-
}
|
|
4940
|
-
function identifyCrossLayoutItems(items) {
|
|
4941
|
-
const cross = /* @__PURE__ */ new Set();
|
|
4942
|
-
if (items.length < 3) return cross;
|
|
4943
|
-
let maxWidth = 0;
|
|
4944
|
-
for (const i of items) {
|
|
4945
|
-
if (i.w > maxWidth) maxWidth = i.w;
|
|
4946
|
-
}
|
|
4947
|
-
const threshold = CROSS_LAYOUT_BETA * maxWidth;
|
|
4948
|
-
for (const item of items) {
|
|
4949
|
-
if (item.w < threshold) continue;
|
|
4950
|
-
let overlaps = 0;
|
|
4951
|
-
for (const other of items) {
|
|
4952
|
-
if (other === item) continue;
|
|
4953
|
-
const left = Math.max(item.x, other.x);
|
|
4954
|
-
const right = Math.min(item.x + item.w, other.x + other.w);
|
|
4955
|
-
const overlapW = right - left;
|
|
4956
|
-
if (overlapW <= 0) continue;
|
|
4957
|
-
const smaller = Math.min(item.w, other.w);
|
|
4958
|
-
if (smaller > 0 && overlapW / smaller >= CROSS_OVERLAP_RATIO) {
|
|
4959
|
-
overlaps++;
|
|
4960
|
-
if (overlaps >= CROSS_MIN_OVERLAPS) break;
|
|
4961
|
-
}
|
|
4962
|
-
}
|
|
4963
|
-
if (overlaps >= CROSS_MIN_OVERLAPS) cross.add(item);
|
|
4964
|
-
}
|
|
4965
|
-
return cross;
|
|
4966
|
-
}
|
|
4967
|
-
function mergeCrossLayoutGroups(groups, cross) {
|
|
4968
|
-
if (cross.length === 0) return groups;
|
|
4969
|
-
const sortedCross = [...cross].sort((a, b) => b.y + b.h - (a.y + a.h) || a.x - b.x);
|
|
4970
|
-
const groupTop = (g) => {
|
|
4971
|
-
let top = -Infinity;
|
|
4972
|
-
for (const i of g) {
|
|
4973
|
-
const t = i.y + i.h;
|
|
4974
|
-
if (t > top) top = t;
|
|
4975
|
-
}
|
|
4976
|
-
return top;
|
|
4977
|
-
};
|
|
4978
|
-
const result = [];
|
|
4979
|
-
let gi = 0, ci = 0;
|
|
4980
|
-
while (gi < groups.length || ci < sortedCross.length) {
|
|
4981
|
-
if (ci >= sortedCross.length) {
|
|
4982
|
-
result.push(groups[gi++]);
|
|
4983
|
-
continue;
|
|
4984
|
-
}
|
|
4985
|
-
if (gi >= groups.length) {
|
|
4986
|
-
result.push([sortedCross[ci++]]);
|
|
4987
|
-
continue;
|
|
4988
|
-
}
|
|
4989
|
-
const crossTop = sortedCross[ci].y + sortedCross[ci].h;
|
|
4990
|
-
if (crossTop >= groupTop(groups[gi])) result.push([sortedCross[ci++]]);
|
|
4991
|
-
else result.push(groups[gi++]);
|
|
4992
|
-
}
|
|
4993
|
-
return result;
|
|
4994
|
-
}
|
|
4995
|
-
function findHorizontalCut(items) {
|
|
4996
|
-
if (items.length < 2) return { position: 0, gap: 0 };
|
|
4997
|
-
const sorted = [...items].sort((a, b) => b.y - a.y);
|
|
4998
|
-
let largestGap = 0;
|
|
4999
|
-
let position = 0;
|
|
5000
|
-
for (let i = 1; i < sorted.length; i++) {
|
|
5001
|
-
const prevBottom = sorted[i - 1].y - sorted[i - 1].h;
|
|
5002
|
-
const currTop = sorted[i].y;
|
|
5003
|
-
const gap = prevBottom - currTop;
|
|
5004
|
-
if (gap > largestGap) {
|
|
5005
|
-
largestGap = gap;
|
|
5006
|
-
position = (prevBottom + currTop) / 2;
|
|
5007
|
-
}
|
|
5008
|
-
}
|
|
5009
|
-
return { position, gap: largestGap };
|
|
5010
|
-
}
|
|
5011
|
-
function findVerticalCutWithOutlierFilter(items, minGap) {
|
|
5012
|
-
const edgeCut = findVerticalCut(items);
|
|
5013
|
-
if (edgeCut.gap >= minGap) return edgeCut;
|
|
5014
|
-
if (items.length >= 3) {
|
|
5015
|
-
let minX = Infinity, maxX = -Infinity;
|
|
5016
|
-
for (const i of items) {
|
|
5017
|
-
if (i.x < minX) minX = i.x;
|
|
5018
|
-
const r = i.x + i.w;
|
|
5019
|
-
if (r > maxX) maxX = r;
|
|
5020
|
-
}
|
|
5021
|
-
const narrowThreshold = (maxX - minX) * NARROW_ELEMENT_WIDTH_RATIO;
|
|
5022
|
-
const filtered = items.filter((i) => i.w >= narrowThreshold);
|
|
5023
|
-
if (filtered.length >= 2 && filtered.length < items.length && filtered.length >= items.length * 0.7) {
|
|
5024
|
-
const filteredCut = findVerticalCut(filtered);
|
|
5025
|
-
if (filteredCut.gap > edgeCut.gap && filteredCut.gap >= minGap) {
|
|
5026
|
-
return filteredCut;
|
|
5027
|
-
}
|
|
5028
|
-
}
|
|
5029
|
-
}
|
|
5030
|
-
return edgeCut;
|
|
5031
|
-
}
|
|
5032
|
-
function findVerticalCut(items) {
|
|
5033
|
-
if (items.length < 2) return { position: 0, gap: 0 };
|
|
5034
|
-
const sorted = [...items].sort((a, b) => a.x - b.x || a.x + a.w - (b.x + b.w));
|
|
5035
|
-
let largestGap = 0;
|
|
5036
|
-
let position = 0;
|
|
5037
|
-
let prevRight = null;
|
|
5038
|
-
for (const it of sorted) {
|
|
5039
|
-
const left = it.x;
|
|
5040
|
-
const right = it.x + it.w;
|
|
5041
|
-
if (prevRight !== null && left > prevRight) {
|
|
5042
|
-
const gap = left - prevRight;
|
|
5043
|
-
if (gap > largestGap) {
|
|
5044
|
-
largestGap = gap;
|
|
5045
|
-
position = (prevRight + left) / 2;
|
|
5046
|
-
}
|
|
5047
|
-
}
|
|
5048
|
-
prevRight = prevRight === null ? right : Math.max(prevRight, right);
|
|
5049
|
-
}
|
|
5050
|
-
return { position, gap: largestGap };
|
|
5051
|
-
}
|
|
5052
|
-
function isProseGutter(items, x) {
|
|
5053
|
-
const sideLines = (side) => {
|
|
5054
|
-
const lines = [];
|
|
5055
|
-
for (const item of [...side].sort((a, b) => b.y - a.y)) {
|
|
5056
|
-
const line = lines.find((l) => Math.abs(l.y - item.y) <= 2);
|
|
5057
|
-
if (line) {
|
|
5058
|
-
line.chars += item.text.length;
|
|
5059
|
-
line.left = Math.min(line.left, item.x);
|
|
5060
|
-
line.right = Math.max(line.right, item.x + item.w);
|
|
5061
|
-
} else lines.push({ y: item.y, chars: item.text.length, left: item.x, right: item.x + item.w });
|
|
5062
|
-
}
|
|
5063
|
-
return lines;
|
|
5064
|
-
};
|
|
5065
|
-
const left = sideLines(items.filter((i) => i.x + i.w / 2 < x));
|
|
5066
|
-
const right = sideLines(items.filter((i) => i.x + i.w / 2 >= x));
|
|
5067
|
-
if (left.length < 4 || right.length < 4) return false;
|
|
5068
|
-
const prose = (lines) => {
|
|
5069
|
-
const width = Math.max(...lines.map((l) => l.right)) - Math.min(...lines.map((l) => l.left));
|
|
5070
|
-
const full = lines.filter((l) => l.chars >= 25 && l.right - l.left >= width * 0.6).length;
|
|
5071
|
-
return full >= lines.length * 0.6;
|
|
5072
|
-
};
|
|
5073
|
-
if (!prose(left) || !prose(right)) return false;
|
|
5074
|
-
const span = (lines) => [Math.min(...lines.map((l) => l.y)), Math.max(...lines.map((l) => l.y))];
|
|
5075
|
-
const [l0, l1] = span(left), [r0, r1] = span(right);
|
|
5076
|
-
return Math.min(l1, r1) - Math.max(l0, r0) >= Math.min(l1 - l0, r1 - r0) * 0.5;
|
|
5077
|
-
}
|
|
5078
|
-
function splitEdgeSpannedColumns(items, gapThreshold, depth) {
|
|
5079
|
-
let minX = Infinity, maxX = -Infinity;
|
|
5080
|
-
for (const i of items) {
|
|
5081
|
-
minX = Math.min(minX, i.x);
|
|
5082
|
-
maxX = Math.max(maxX, i.x + i.w);
|
|
5083
|
-
}
|
|
5084
|
-
const narrow = items.filter((i) => i.w < (maxX - minX) * 0.5);
|
|
5085
|
-
if (narrow.length === items.length || narrow.length < 8) return null;
|
|
5086
|
-
const cut = findVerticalCut(narrow);
|
|
5087
|
-
if (cut.gap < PROSE_GUTTER_MIN_GAP || !isProseGutter(narrow, cut.position)) return null;
|
|
5088
|
-
const crossing = items.filter((i) => i.x < cut.position && i.x + i.w > cut.position);
|
|
5089
|
-
const rest = items.filter((i) => !crossing.includes(i));
|
|
5090
|
-
const restTop = Math.max(...rest.map((i) => i.y)), restBottom = Math.min(...rest.map((i) => i.y));
|
|
5091
|
-
const above = crossing.filter((i) => i.y > restTop), below = crossing.filter((i) => i.y < restBottom);
|
|
5092
|
-
if (above.length + below.length !== crossing.length) return null;
|
|
5093
|
-
const left = rest.filter((i) => i.x + i.w / 2 < cut.position), right = rest.filter((i) => i.x + i.w / 2 >= cut.position);
|
|
5094
|
-
return [
|
|
5095
|
-
...above.length ? [above] : [],
|
|
5096
|
-
...xyCutOrder(left, gapThreshold, depth + 1),
|
|
5097
|
-
...xyCutOrder(right, gapThreshold, depth + 1),
|
|
5098
|
-
...below.length ? [below] : []
|
|
5099
|
-
];
|
|
5100
|
-
}
|
|
5101
|
-
|
|
5102
5204
|
// src/pdf/two-column.ts
|
|
5103
5205
|
var GUTTER_SCAN_LO = 0.3;
|
|
5104
5206
|
var GUTTER_SCAN_HI = 0.7;
|
|
@@ -7429,4 +7531,4 @@ export {
|
|
|
7429
7531
|
joinCellEdges,
|
|
7430
7532
|
extractPageBlocksWithLines
|
|
7431
7533
|
};
|
|
7432
|
-
//# sourceMappingURL=chunk-
|
|
7534
|
+
//# sourceMappingURL=chunk-QKEPDJ2D.js.map
|