kordoc 4.14.2 → 4.14.3
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 +38 -5
- package/dist/{-AQKXLFIM.js → -7XBPXCXN.js} +13 -11
- package/dist/{chunk-FOJZNMMK.js → chunk-2LQGSDZ6.js} +1 -1
- package/dist/chunk-2LQGSDZ6.js.map +1 -0
- package/dist/chunk-4R67INKT.js +1002 -0
- package/dist/chunk-4R67INKT.js.map +1 -0
- package/dist/{chunk-ILU76UF3.js → chunk-4RJ5D7MT.js} +2 -2
- package/dist/chunk-4RJ5D7MT.js.map +1 -0
- package/dist/{chunk-EQZI77PP.cjs → chunk-5VVS2QIJ.cjs} +3 -3
- package/dist/{chunk-EQZI77PP.cjs.map → chunk-5VVS2QIJ.cjs.map} +1 -1
- package/dist/{chunk-3DUADAY2.js → chunk-A275ZQLX.js} +209 -87
- package/dist/chunk-A275ZQLX.js.map +1 -0
- package/dist/{chunk-EISO3POT.js → chunk-CVEERPMP.js} +788 -194
- package/dist/chunk-CVEERPMP.js.map +1 -0
- package/dist/{chunk-ZWD734EY.js → chunk-D6KQKMU3.js} +2 -2
- package/dist/{chunk-QOMNEWCQ.cjs → chunk-EBZUZC6F.cjs} +305 -31
- package/dist/chunk-EBZUZC6F.cjs.map +1 -0
- package/dist/{chunk-HR2XNERB.cjs → chunk-EMGF6EEV.cjs} +2 -2
- package/dist/{chunk-HR2XNERB.cjs.map → chunk-EMGF6EEV.cjs.map} +1 -1
- package/dist/{chunk-GDW4YP7K.js → chunk-FAZR34CA.js} +2 -2
- package/dist/{chunk-TNCKOL2O.js → chunk-GTINVM5K.js} +2 -2
- package/dist/{chunk-L7DMSMAG.cjs → chunk-HX4UUF7Y.cjs} +1 -1
- package/dist/chunk-HX4UUF7Y.cjs.map +1 -0
- package/dist/{chunk-UET462HB.js → chunk-I4NNYWIR.js} +2 -2
- package/dist/chunk-IH56ZISC.js +620 -0
- package/dist/chunk-IH56ZISC.js.map +1 -0
- package/dist/{chunk-EDNJLUSE.js → chunk-IHZEFW4L.js} +2 -2
- package/dist/chunk-IW2CB755.cjs +1002 -0
- package/dist/chunk-IW2CB755.cjs.map +1 -0
- package/dist/{chunk-ZWOFQRIB.js → chunk-JCVIOLBF.js} +3 -3
- package/dist/{chunk-JQEFP45L.js → chunk-L5EH2NVO.js} +2 -2
- package/dist/{chunk-247ANM72.cjs → chunk-NOAQRCV6.cjs} +219 -97
- package/dist/chunk-NOAQRCV6.cjs.map +1 -0
- package/dist/{chunk-7IAQ4HOK.js → chunk-NQCUAGLR.js} +1 -1
- package/dist/chunk-NQCUAGLR.js.map +1 -0
- package/dist/{chunk-NS55SM7A.js → chunk-O2PGQNYE.js} +2 -2
- package/dist/{chunk-QC5T6D4J.js → chunk-QGW7NMTX.js} +299 -25
- package/dist/chunk-QGW7NMTX.js.map +1 -0
- package/dist/{chunk-A7QC2ZVP.js → chunk-UVVEBI22.js} +209 -87
- package/dist/chunk-UVVEBI22.js.map +1 -0
- package/dist/chunk-VJHAUMCF.js +949 -0
- package/dist/chunk-VJHAUMCF.js.map +1 -0
- package/dist/{chunk-C7FQBSON.js → chunk-VNFJPTU4.js} +2 -2
- package/dist/{chunk-VQ5W4MYO.js → chunk-VYOGXNQ3.js} +298 -24
- package/dist/chunk-VYOGXNQ3.js.map +1 -0
- package/dist/{chunk-DOGPOY4B.js → chunk-WB5LW52Z.js} +2 -2
- package/dist/{chunk-TSFS5VKD.js → chunk-YGBZABI4.js} +332 -141
- package/dist/chunk-YGBZABI4.js.map +1 -0
- package/dist/chunks-I7TEMJXH.js +10 -0
- package/dist/cli.js +228 -97
- package/dist/cli.js.map +1 -1
- package/dist/{formula-PJJ6S3Z2.cjs → formula-CPO2TZGB.cjs} +9 -9
- package/dist/{formula-PJJ6S3Z2.cjs.map → formula-CPO2TZGB.cjs.map} +1 -1
- package/dist/{formula-5S7WWXGH.js → formula-NOIDZEBA.js} +4 -4
- package/dist/{formula-JGFTXWYT.js → formula-X44GV7TN.js} +3 -3
- package/dist/{image-ocr-WCAYXLOA.js → image-ocr-72RAR4WR.js} +34 -16
- package/dist/image-ocr-72RAR4WR.js.map +1 -0
- package/dist/{image-ocr-FLIL7MGN.js → image-ocr-R6W6A75P.js} +32 -14
- package/dist/image-ocr-R6W6A75P.js.map +1 -0
- package/dist/{image-ocr-ZTYAGV3W.cjs → image-ocr-SUGT64ZM.cjs} +36 -18
- package/dist/image-ocr-SUGT64ZM.cjs.map +1 -0
- package/dist/index.cjs +2416 -1184
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +62 -25
- package/dist/index.d.ts +62 -25
- package/dist/index.js +1853 -621
- package/dist/index.js.map +1 -1
- package/dist/mcp.js +74 -53
- package/dist/mcp.js.map +1 -1
- package/dist/{model-bundle-FSPZZ2EM.js → model-bundle-57CLEBCO.js} +5 -5
- package/dist/{models-CJPAQK5R.js → models-7ELIFTD7.js} +5 -5
- package/dist/{parser-SCUTZAIJ.js → parser-4NKAYWAX.js} +261 -241
- package/dist/parser-4NKAYWAX.js.map +1 -0
- package/dist/{parser-A4TMPJAM.js → parser-HWFQRSUQ.js} +261 -241
- package/dist/parser-HWFQRSUQ.js.map +1 -0
- package/dist/{parser-VCXE4I5A.cjs → parser-RANGXGBD.cjs} +289 -269
- package/dist/parser-RANGXGBD.cjs.map +1 -0
- package/dist/pdf-ocr-BNC34MNU.js +13 -0
- package/dist/pdf-ocr-QX2GB33Q.js +16 -0
- package/dist/pdf-ocr-VHSFACH7.cjs +14 -0
- package/dist/{pdf-ocr-MBZZ57LD.cjs.map → pdf-ocr-VHSFACH7.cjs.map} +1 -1
- package/dist/{profile-io-LBM263K7.js → profile-io-V52PL5ZO.js} +3 -3
- package/dist/{rasterize-46RG4ZF6.js → rasterize-ZIGLJDOG.js} +3 -3
- package/dist/redact-TIQEQI3M.js +18 -0
- package/dist/redact-doc-KXZ3TZAG.js +1216 -0
- package/dist/redact-doc-KXZ3TZAG.js.map +1 -0
- package/dist/{render-NGP5T24S.js → render-U5PE6V2E.js} +7 -7
- package/dist/seal-DNXJBILR.js +10 -0
- package/dist/{setup-AU4OCHNH.js → setup-YRDM4ODP.js} +3 -3
- package/dist/visual-5XWMA4EV.js +19 -0
- package/dist/{watch-MKPUCPXM.js → watch-5IOLBATT.js} +12 -12
- package/package.json +2 -2
- package/dist/chunk-247ANM72.cjs.map +0 -1
- package/dist/chunk-3DUADAY2.js.map +0 -1
- package/dist/chunk-422427XJ.cjs +0 -571
- package/dist/chunk-422427XJ.cjs.map +0 -1
- package/dist/chunk-7IAQ4HOK.js.map +0 -1
- package/dist/chunk-A7QC2ZVP.js.map +0 -1
- package/dist/chunk-DZIXKL7E.js +0 -145
- package/dist/chunk-DZIXKL7E.js.map +0 -1
- package/dist/chunk-EISO3POT.js.map +0 -1
- package/dist/chunk-EP7KOI2V.js +0 -571
- package/dist/chunk-EP7KOI2V.js.map +0 -1
- package/dist/chunk-FOJZNMMK.js.map +0 -1
- package/dist/chunk-ILU76UF3.js.map +0 -1
- package/dist/chunk-KVWV4ULP.js +0 -516
- package/dist/chunk-KVWV4ULP.js.map +0 -1
- package/dist/chunk-L7DMSMAG.cjs.map +0 -1
- package/dist/chunk-QC5T6D4J.js.map +0 -1
- package/dist/chunk-QOMNEWCQ.cjs.map +0 -1
- package/dist/chunk-TSFS5VKD.js.map +0 -1
- package/dist/chunk-VQ5W4MYO.js.map +0 -1
- package/dist/chunks-SX77P5CV.js +0 -10
- package/dist/image-ocr-FLIL7MGN.js.map +0 -1
- package/dist/image-ocr-WCAYXLOA.js.map +0 -1
- package/dist/image-ocr-ZTYAGV3W.cjs.map +0 -1
- package/dist/parser-A4TMPJAM.js.map +0 -1
- package/dist/parser-SCUTZAIJ.js.map +0 -1
- package/dist/parser-VCXE4I5A.cjs.map +0 -1
- package/dist/pdf-ocr-76SAUXMZ.js +0 -13
- package/dist/pdf-ocr-CPU55CVF.js +0 -16
- package/dist/pdf-ocr-MBZZ57LD.cjs +0 -14
- package/dist/redact-7ILEAUTS.js +0 -12
- package/dist/seal-RGUPOLXD.js +0 -10
- package/dist/visual-NZLYIYEM.js +0 -19
- /package/dist/{-AQKXLFIM.js.map → -7XBPXCXN.js.map} +0 -0
- /package/dist/{chunk-ZWD734EY.js.map → chunk-D6KQKMU3.js.map} +0 -0
- /package/dist/{chunk-GDW4YP7K.js.map → chunk-FAZR34CA.js.map} +0 -0
- /package/dist/{chunk-TNCKOL2O.js.map → chunk-GTINVM5K.js.map} +0 -0
- /package/dist/{chunk-UET462HB.js.map → chunk-I4NNYWIR.js.map} +0 -0
- /package/dist/{chunk-EDNJLUSE.js.map → chunk-IHZEFW4L.js.map} +0 -0
- /package/dist/{chunk-ZWOFQRIB.js.map → chunk-JCVIOLBF.js.map} +0 -0
- /package/dist/{chunk-JQEFP45L.js.map → chunk-L5EH2NVO.js.map} +0 -0
- /package/dist/{chunk-NS55SM7A.js.map → chunk-O2PGQNYE.js.map} +0 -0
- /package/dist/{chunk-C7FQBSON.js.map → chunk-VNFJPTU4.js.map} +0 -0
- /package/dist/{chunk-DOGPOY4B.js.map → chunk-WB5LW52Z.js.map} +0 -0
- /package/dist/{chunks-SX77P5CV.js.map → chunks-I7TEMJXH.js.map} +0 -0
- /package/dist/{formula-5S7WWXGH.js.map → formula-NOIDZEBA.js.map} +0 -0
- /package/dist/{formula-JGFTXWYT.js.map → formula-X44GV7TN.js.map} +0 -0
- /package/dist/{model-bundle-FSPZZ2EM.js.map → model-bundle-57CLEBCO.js.map} +0 -0
- /package/dist/{models-CJPAQK5R.js.map → models-7ELIFTD7.js.map} +0 -0
- /package/dist/{pdf-ocr-76SAUXMZ.js.map → pdf-ocr-BNC34MNU.js.map} +0 -0
- /package/dist/{pdf-ocr-CPU55CVF.js.map → pdf-ocr-QX2GB33Q.js.map} +0 -0
- /package/dist/{profile-io-LBM263K7.js.map → profile-io-V52PL5ZO.js.map} +0 -0
- /package/dist/{rasterize-46RG4ZF6.js.map → rasterize-ZIGLJDOG.js.map} +0 -0
- /package/dist/{redact-7ILEAUTS.js.map → redact-TIQEQI3M.js.map} +0 -0
- /package/dist/{render-NGP5T24S.js.map → render-U5PE6V2E.js.map} +0 -0
- /package/dist/{seal-RGUPOLXD.js.map → seal-DNXJBILR.js.map} +0 -0
- /package/dist/{setup-AU4OCHNH.js.map → setup-YRDM4ODP.js.map} +0 -0
- /package/dist/{visual-NZLYIYEM.js.map → visual-5XWMA4EV.js.map} +0 -0
- /package/dist/{watch-MKPUCPXM.js.map → watch-5IOLBATT.js.map} +0 -0
|
@@ -3,11 +3,11 @@ import {
|
|
|
3
3
|
HEADING_RATIO_H1,
|
|
4
4
|
HEADING_RATIO_H2,
|
|
5
5
|
HEADING_RATIO_H3
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-NQCUAGLR.js";
|
|
7
7
|
import {
|
|
8
8
|
safeMax,
|
|
9
9
|
safeMin
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-I4NNYWIR.js";
|
|
11
11
|
|
|
12
12
|
// src/pdf/image-regions.ts
|
|
13
13
|
import { OPS } from "pdfjs-dist/legacy/build/pdf.mjs";
|
|
@@ -70,6 +70,8 @@ function extractLines(fnArray, argsArray) {
|
|
|
70
70
|
const horizontals = [];
|
|
71
71
|
const verticals = [];
|
|
72
72
|
const clipRects = [];
|
|
73
|
+
const fillRects = [];
|
|
74
|
+
let pathRects = [];
|
|
73
75
|
let pendingClip = false;
|
|
74
76
|
let lineWidth = 1;
|
|
75
77
|
let ctm = [1, 0, 0, 1, 0, 0];
|
|
@@ -85,6 +87,8 @@ function extractLines(fnArray, argsArray) {
|
|
|
85
87
|
currentPath.push({ x1: tx1, y1: ty1, x2: tx2, y2: ty2 });
|
|
86
88
|
}
|
|
87
89
|
function pushRectangle(rx, ry, rw, rh) {
|
|
90
|
+
const [ax, ay] = applyCtm(rx, ry), [bx, by] = applyCtm(rx + rw, ry + rh);
|
|
91
|
+
pathRects.push({ x1: Math.min(ax, bx), y1: Math.min(ay, by), x2: Math.max(ax, bx), y2: Math.max(ay, by) });
|
|
88
92
|
const effH = Math.abs(rh) * Math.hypot(ctm[2], ctm[3]);
|
|
89
93
|
const effW = Math.abs(rw) * Math.hypot(ctm[0], ctm[1]);
|
|
90
94
|
if (effH < ORIENTATION_TOL * 2) {
|
|
@@ -98,7 +102,12 @@ function extractLines(fnArray, argsArray) {
|
|
|
98
102
|
pushSeg(rx, ry + rh, rx, ry);
|
|
99
103
|
}
|
|
100
104
|
}
|
|
101
|
-
function flushPath(isStroke, fromFill = false) {
|
|
105
|
+
function flushPath(isStroke, fromFill = false, filled = fromFill) {
|
|
106
|
+
if (filled) {
|
|
107
|
+
if (pathRects.length) for (const r of pathRects) fillRects.push(r);
|
|
108
|
+
else captureClipRect(currentPath, fillRects, 0.3, 0.3);
|
|
109
|
+
}
|
|
110
|
+
pathRects = [];
|
|
102
111
|
if (!isStroke) {
|
|
103
112
|
if (pendingClip) captureClipRect(currentPath, clipRects);
|
|
104
113
|
pendingClip = false;
|
|
@@ -209,7 +218,7 @@ function extractLines(fnArray, argsArray) {
|
|
|
209
218
|
} else if (afterOp === OPS2.fill || afterOp === OPS2.eoFill) {
|
|
210
219
|
flushPath(true, true);
|
|
211
220
|
} else if (afterOp === OPS2.fillStroke || afterOp === OPS2.eoFillStroke || afterOp === OPS2.closeFillStroke || afterOp === OPS2.closeEOFillStroke) {
|
|
212
|
-
flushPath(true);
|
|
221
|
+
flushPath(true, false, true);
|
|
213
222
|
} else if (afterOp === OPS2.endPath) {
|
|
214
223
|
flushPath(false);
|
|
215
224
|
}
|
|
@@ -228,7 +237,7 @@ function extractLines(fnArray, argsArray) {
|
|
|
228
237
|
case OPS2.eoFillStroke:
|
|
229
238
|
case OPS2.closeFillStroke:
|
|
230
239
|
case OPS2.closeEOFillStroke:
|
|
231
|
-
flushPath(true);
|
|
240
|
+
flushPath(true, false, true);
|
|
232
241
|
break;
|
|
233
242
|
case OPS2.endPath:
|
|
234
243
|
flushPath(false);
|
|
@@ -239,11 +248,11 @@ function extractLines(fnArray, argsArray) {
|
|
|
239
248
|
break;
|
|
240
249
|
}
|
|
241
250
|
}
|
|
242
|
-
return { horizontals, verticals, clipRects };
|
|
251
|
+
return { horizontals, verticals, clipRects, fillRects };
|
|
243
252
|
}
|
|
244
253
|
var CLIP_MIN_W = 4;
|
|
245
254
|
var CLIP_MIN_H = 2;
|
|
246
|
-
function captureClipRect(path, out) {
|
|
255
|
+
function captureClipRect(path, out, minW = CLIP_MIN_W, minH = CLIP_MIN_H) {
|
|
247
256
|
if (path.length < 3 || path.length > 5) return;
|
|
248
257
|
let x1 = Infinity, y1 = Infinity, x2 = -Infinity, y2 = -Infinity;
|
|
249
258
|
for (const s of path) {
|
|
@@ -254,7 +263,7 @@ function captureClipRect(path, out) {
|
|
|
254
263
|
y1 = Math.min(y1, s.y1, s.y2);
|
|
255
264
|
y2 = Math.max(y2, s.y1, s.y2);
|
|
256
265
|
}
|
|
257
|
-
if (x2 - x1 <
|
|
266
|
+
if (x2 - x1 < minW || y2 - y1 < minH) return;
|
|
258
267
|
out.push({ x1, y1, x2, y2 });
|
|
259
268
|
}
|
|
260
269
|
function classifyAndAdd(seg, lineWidth, horizontals, verticals, fromFill = false) {
|
|
@@ -961,20 +970,24 @@ function linesIntersect(a, b) {
|
|
|
961
970
|
|
|
962
971
|
// src/pdf/clip-cells.ts
|
|
963
972
|
var CLIP_EDGE_TOL = 1.5;
|
|
973
|
+
var CLIP_ADJ_GAP = 0.15;
|
|
964
974
|
var CLIP_MIN_GROUP = 2;
|
|
965
975
|
var CLIP_MAX_PAGE_FRAC = 0.75;
|
|
966
976
|
var TITLED_FRAME_MIN_TOP = 0.2;
|
|
967
977
|
var TITLED_FRAME_MIN_WIDTH = 0.6;
|
|
968
978
|
var HEADER_BAND = 0.08;
|
|
969
979
|
var CLIP_MIN_W2 = 4;
|
|
980
|
+
var NARROW_FILL_MIN_W = 1;
|
|
970
981
|
var CLIP_MIN_H2 = 2;
|
|
971
982
|
var STROKE_NEAR = 2;
|
|
972
983
|
var STROKE_COVER = 0.5;
|
|
973
984
|
var CLIP_MIN_INVISIBLE = 0;
|
|
985
|
+
var CLIP_COORD_TOL = 0.3;
|
|
974
986
|
var overlap = (a1, a2, b1, b2) => Math.min(a2, b2) - Math.max(a1, b1);
|
|
975
987
|
function adjacent(a, b) {
|
|
976
|
-
|
|
977
|
-
if ((Math.abs(a.
|
|
988
|
+
const al = (u, v) => Math.abs(u - v) <= CLIP_COORD_TOL;
|
|
989
|
+
if ((Math.abs(a.x2 - b.x1) <= CLIP_ADJ_GAP || Math.abs(b.x2 - a.x1) <= CLIP_ADJ_GAP) && overlap(a.y1, a.y2, b.y1, b.y2) > CLIP_EDGE_TOL && (al(a.y1, b.y1) || al(a.y2, b.y2))) return true;
|
|
990
|
+
if ((Math.abs(a.y2 - b.y1) <= CLIP_ADJ_GAP || Math.abs(b.y2 - a.y1) <= CLIP_ADJ_GAP) && overlap(a.x1, a.x2, b.x1, b.x2) > CLIP_EDGE_TOL && (al(a.x1, b.x1) || al(a.x2, b.x2))) return true;
|
|
978
991
|
return false;
|
|
979
992
|
}
|
|
980
993
|
function contains(a, b) {
|
|
@@ -985,7 +998,7 @@ function clusterCoords(values) {
|
|
|
985
998
|
const out = [];
|
|
986
999
|
let run = [];
|
|
987
1000
|
for (const v of sorted) {
|
|
988
|
-
if (run.length > 0 && v - run[run.length - 1] >
|
|
1001
|
+
if (run.length > 0 && v - run[run.length - 1] > CLIP_COORD_TOL) {
|
|
989
1002
|
out.push(run.reduce((s, x) => s + x, 0) / run.length);
|
|
990
1003
|
run = [];
|
|
991
1004
|
}
|
|
@@ -1011,7 +1024,7 @@ function edgeStroked(lines, dir, pos, a1, a2) {
|
|
|
1011
1024
|
}
|
|
1012
1025
|
return false;
|
|
1013
1026
|
}
|
|
1014
|
-
function buildClipCellGrids(rects, strokedH, strokedV, pageWidth, pageHeight, textPoints = []) {
|
|
1027
|
+
function buildClipCellGrids(rects, strokedH, strokedV, pageWidth, pageHeight, textPoints = [], fillRects = []) {
|
|
1015
1028
|
const pageArea = pageWidth * pageHeight;
|
|
1016
1029
|
const sameRect = (a, b) => Math.abs(a.x1 - b.x1) <= CLIP_EDGE_TOL && Math.abs(a.x2 - b.x2) <= CLIP_EDGE_TOL && Math.abs(a.y1 - b.y1) <= CLIP_EDGE_TOL && Math.abs(a.y2 - b.y2) <= CLIP_EDGE_TOL;
|
|
1017
1030
|
const cells = [];
|
|
@@ -1022,15 +1035,45 @@ function buildClipCellGrids(rects, strokedH, strokedV, pageWidth, pageHeight, te
|
|
|
1022
1035
|
}
|
|
1023
1036
|
if (cells.length < 1) return { grids: [], containers: [] };
|
|
1024
1037
|
const parent = new Array(cells.length).fill(-1);
|
|
1038
|
+
const area = (r) => (r.x2 - r.x1) * (r.y2 - r.y1);
|
|
1025
1039
|
for (let i = 0; i < cells.length; i++) {
|
|
1026
1040
|
for (let j = 0; j < cells.length; j++) {
|
|
1027
|
-
if (i === j || !contains(cells[j], cells[i])) continue;
|
|
1041
|
+
if (i === j || area(cells[j]) <= area(cells[i]) || !contains(cells[j], cells[i])) continue;
|
|
1028
1042
|
const cur = parent[i];
|
|
1029
1043
|
if (cur < 0 || contains(cells[cur], cells[j])) parent[i] = j;
|
|
1030
1044
|
}
|
|
1031
1045
|
}
|
|
1032
1046
|
const isContainer = new Array(cells.length).fill(false);
|
|
1033
1047
|
for (const p of parent) if (p >= 0) isContainer[p] = true;
|
|
1048
|
+
const tileParent = new Array(cells.length).fill(false);
|
|
1049
|
+
const tableClip = new Array(cells.length).fill(false);
|
|
1050
|
+
for (let p = 0; p < cells.length; p++) {
|
|
1051
|
+
if (!isContainer[p]) continue;
|
|
1052
|
+
let n = 0, x1 = Infinity, y1 = Infinity, x2 = -Infinity, y2 = -Infinity;
|
|
1053
|
+
for (let i = 0; i < cells.length; i++) {
|
|
1054
|
+
if (parent[i] !== p) continue;
|
|
1055
|
+
const k = cells[i];
|
|
1056
|
+
n++;
|
|
1057
|
+
x1 = Math.min(x1, k.x1);
|
|
1058
|
+
y1 = Math.min(y1, k.y1);
|
|
1059
|
+
x2 = Math.max(x2, k.x2);
|
|
1060
|
+
y2 = Math.max(y2, k.y2);
|
|
1061
|
+
}
|
|
1062
|
+
if (n < CLIP_MIN_GROUP) continue;
|
|
1063
|
+
const c = cells[p];
|
|
1064
|
+
if (Math.max(Math.abs(x1 - c.x1), Math.abs(x2 - c.x2), Math.abs(y1 - c.y1), Math.abs(y2 - c.y2)) <= CLIP_COORD_TOL) tileParent[p] = true;
|
|
1065
|
+
}
|
|
1066
|
+
for (let p = 0; p < cells.length; p++) {
|
|
1067
|
+
if (tileParent[p]) tableClip[p] = !cells.some((q, i) => i !== p && parent[i] === parent[p] && !tileParent[i] && adjacent(q, cells[p]));
|
|
1068
|
+
}
|
|
1069
|
+
const effParent = (i) => {
|
|
1070
|
+
let p = parent[i];
|
|
1071
|
+
for (let steps = 0; p >= 0 && steps <= cells.length; steps++) {
|
|
1072
|
+
if (!tableClip[p] && (isGridMember(p) || loneFrame(p))) return p;
|
|
1073
|
+
p = parent[p];
|
|
1074
|
+
}
|
|
1075
|
+
return -1;
|
|
1076
|
+
};
|
|
1034
1077
|
const root = cells.map((_, i) => i);
|
|
1035
1078
|
const find = (i) => {
|
|
1036
1079
|
while (root[i] !== i) {
|
|
@@ -1040,8 +1083,9 @@ function buildClipCellGrids(rects, strokedH, strokedV, pageWidth, pageHeight, te
|
|
|
1040
1083
|
return i;
|
|
1041
1084
|
};
|
|
1042
1085
|
for (let i = 0; i < cells.length; i++) {
|
|
1086
|
+
if (tableClip[i]) continue;
|
|
1043
1087
|
for (let j = i + 1; j < cells.length; j++) {
|
|
1044
|
-
if (parent[i] !== parent[j]) continue;
|
|
1088
|
+
if (tableClip[j] || parent[i] !== parent[j]) continue;
|
|
1045
1089
|
if (adjacent(cells[i], cells[j])) {
|
|
1046
1090
|
const ra = find(i), rb = find(j);
|
|
1047
1091
|
if (ra !== rb) root[ra] = rb;
|
|
@@ -1061,12 +1105,13 @@ function buildClipCellGrids(rects, strokedH, strokedV, pageWidth, pageHeight, te
|
|
|
1061
1105
|
const framed = (r) => edgeStroked(strokedH, "h", r.y1, r.x1, r.x2) && edgeStroked(strokedH, "h", r.y2, r.x1, r.x2) && edgeStroked(strokedV, "v", r.x1, r.y1, r.y2) && edgeStroked(strokedV, "v", r.x2, r.y1, r.y2);
|
|
1062
1106
|
const titledFrame = (r) => r.y1 >= pageHeight * TITLED_FRAME_MIN_TOP && r.x2 - r.x1 >= pageWidth * TITLED_FRAME_MIN_WIDTH && textPoints.some((p) => p.y < r.y1 && p.y > pageHeight * HEADER_BAND && p.x >= r.x1 - CLIP_EDGE_TOL && p.x <= r.x2 + CLIP_EDGE_TOL) && textPoints.some((p) => p.x > r.x1 && p.x < r.x2 && p.y > r.y1 && p.y < r.y2);
|
|
1063
1107
|
const loneFrame = (i) => isContainer[i] && !isGridMember(i) && (framed(cells[i]) || titledFrame(cells[i]));
|
|
1064
|
-
const parentAttachable = (i) =>
|
|
1108
|
+
const parentAttachable = (i) => effParent(i) >= 0;
|
|
1065
1109
|
const onlyChild = (i) => parent[i] >= 0 && parent.filter((p) => p === parent[i]).length === 1;
|
|
1066
1110
|
const grids = [];
|
|
1067
1111
|
for (const idxs of groups.values()) {
|
|
1068
1112
|
const first = idxs[0];
|
|
1069
|
-
|
|
1113
|
+
if (tableClip[first]) continue;
|
|
1114
|
+
const parentRect = parentAttachable(first) ? cells[effParent(first)] : void 0;
|
|
1070
1115
|
if (idxs.length < CLIP_MIN_GROUP) {
|
|
1071
1116
|
if (!loneFrame(first) && !((parentRect || onlyChild(first)) && framed(cells[first]))) continue;
|
|
1072
1117
|
const r = cells[first];
|
|
@@ -1112,13 +1157,14 @@ function buildClipCellGrids(rects, strokedH, strokedV, pageWidth, pageHeight, te
|
|
|
1112
1157
|
for (let rr = 0; rr < numRows; rr++) {
|
|
1113
1158
|
for (let cc = 0; cc < numCols; cc++) {
|
|
1114
1159
|
if (occupied[rr][cc]) continue;
|
|
1115
|
-
out.push({ row: rr, col: cc, rowSpan: 1, colSpan: 1, bbox: { x1: colXs[cc], y1: rowYs[rr + 1], x2: colXs[cc + 1], y2: rowYs[rr] } });
|
|
1160
|
+
out.push({ row: rr, col: cc, rowSpan: 1, colSpan: 1, bbox: { x1: colXs[cc], y1: rowYs[rr + 1], x2: colXs[cc + 1], y2: rowYs[rr] }, filler: true });
|
|
1116
1161
|
}
|
|
1117
1162
|
}
|
|
1163
|
+
addNarrowEdgeCols(colXs, rowYs, out, fillRects);
|
|
1118
1164
|
grids.push({
|
|
1119
1165
|
rowYs,
|
|
1120
1166
|
colXs,
|
|
1121
|
-
bbox: { x1: colXs[0], y1: rowYs[numRows], x2: colXs[
|
|
1167
|
+
bbox: { x1: colXs[0], y1: rowYs[numRows], x2: colXs[colXs.length - 1], y2: rowYs[0] },
|
|
1122
1168
|
vertexRadius: 1,
|
|
1123
1169
|
cells: out,
|
|
1124
1170
|
...parentRect ? { clipParent: parentRect } : {}
|
|
@@ -1126,6 +1172,41 @@ function buildClipCellGrids(rects, strokedH, strokedV, pageWidth, pageHeight, te
|
|
|
1126
1172
|
}
|
|
1127
1173
|
return { grids, containers };
|
|
1128
1174
|
}
|
|
1175
|
+
function addNarrowEdgeCols(colXs, rowYs, out, fills) {
|
|
1176
|
+
if (!fills.length) return;
|
|
1177
|
+
const rowIdx = (y) => {
|
|
1178
|
+
const i = nearestIndex(rowYs, y);
|
|
1179
|
+
return Math.abs(rowYs[i] - y) <= CLIP_COORD_TOL ? i : -1;
|
|
1180
|
+
};
|
|
1181
|
+
for (const side of ["l", "r"]) {
|
|
1182
|
+
const edge = side === "l" ? colXs[0] : colXs[colXs.length - 1];
|
|
1183
|
+
const hits = fills.filter((f) => {
|
|
1184
|
+
const w = f.x2 - f.x1;
|
|
1185
|
+
if (w < NARROW_FILL_MIN_W || w >= CLIP_MIN_W2 || Math.abs((side === "l" ? f.x2 : f.x1) - edge) > CLIP_COORD_TOL) return false;
|
|
1186
|
+
const r0 = rowIdx(f.y2), r1 = rowIdx(f.y1);
|
|
1187
|
+
return r0 >= 0 && r1 > r0;
|
|
1188
|
+
});
|
|
1189
|
+
if (!hits.length) continue;
|
|
1190
|
+
let x = side === "l" ? Infinity : -Infinity;
|
|
1191
|
+
for (const f of hits) x = side === "l" ? Math.min(x, f.x1) : Math.max(x, f.x2);
|
|
1192
|
+
if (side === "l") {
|
|
1193
|
+
colXs.unshift(x);
|
|
1194
|
+
for (const c of out) c.col++;
|
|
1195
|
+
} else colXs.push(x);
|
|
1196
|
+
const col = side === "l" ? 0 : colXs.length - 2;
|
|
1197
|
+
const [cx1, cx2] = [colXs[col], colXs[col + 1]];
|
|
1198
|
+
const taken = new Array(rowYs.length - 1).fill(false);
|
|
1199
|
+
for (const f of hits) {
|
|
1200
|
+
const r0 = rowIdx(f.y2), r1 = rowIdx(f.y1);
|
|
1201
|
+
if (taken.slice(r0, r1).some(Boolean)) continue;
|
|
1202
|
+
taken.fill(true, r0, r1);
|
|
1203
|
+
out.push({ row: r0, col, rowSpan: r1 - r0, colSpan: 1, bbox: { x1: cx1, y1: rowYs[r1], x2: cx2, y2: rowYs[r0] } });
|
|
1204
|
+
}
|
|
1205
|
+
for (let r = 0; r < taken.length; r++) {
|
|
1206
|
+
if (!taken[r]) out.push({ row: r, col, rowSpan: 1, colSpan: 1, bbox: { x1: cx1, y1: rowYs[r + 1], x2: cx2, y2: rowYs[r] }, filler: true });
|
|
1207
|
+
}
|
|
1208
|
+
}
|
|
1209
|
+
}
|
|
1129
1210
|
function dropGridsInside(lineGrids, clipGrids, containers = []) {
|
|
1130
1211
|
if (clipGrids.length === 0 && containers.length === 0) return lineGrids;
|
|
1131
1212
|
const area = (b) => Math.max(0, b.x2 - b.x1) * Math.max(0, b.y2 - b.y1);
|
|
@@ -1297,7 +1378,7 @@ function cellTextToString(items) {
|
|
|
1297
1378
|
lines.push(curLine);
|
|
1298
1379
|
const merged = mergeSuperscriptRows(lines);
|
|
1299
1380
|
const textLines = merged.map((line) => {
|
|
1300
|
-
const s = line
|
|
1381
|
+
const s = sortLineByX(line);
|
|
1301
1382
|
if (s.length === 1) return s[0].text;
|
|
1302
1383
|
const evenSpaced = detectEvenSpacedItems(s);
|
|
1303
1384
|
let result = s[0].text;
|
|
@@ -1419,7 +1500,7 @@ function mergeCellTextLines(textLines) {
|
|
|
1419
1500
|
merged[merged.length - 1] = prev + curr.trim();
|
|
1420
1501
|
} else if (/[,(]$/.test(prev.trim()) && curr.trim().length <= 15) {
|
|
1421
1502
|
merged[merged.length - 1] = prev + curr.trim();
|
|
1422
|
-
} else if (/[\d,]$/.test(prev) && /^[\d,]+[)\]]?$/.test(curr.trim()) && curr.trim().length <= 10) {
|
|
1503
|
+
} else if (/[\d,]$/.test(prev) && /^[\d,]+[)\]]?$/.test(curr.trim()) && curr.trim().length <= 10 && !(/\d{1,3}(,\d{3})+$/.test(prev) && /^\d{1,3}(,\d{3})+$/.test(curr.trim()))) {
|
|
1423
1504
|
merged[merged.length - 1] = prev + curr.trim();
|
|
1424
1505
|
} else {
|
|
1425
1506
|
merged.push(curr);
|
|
@@ -1539,11 +1620,24 @@ function normalizeUndersegmentedTable(originalCells, colXs, items) {
|
|
|
1539
1620
|
return n;
|
|
1540
1621
|
};
|
|
1541
1622
|
if (countNonEmptyRows(rebuilt) <= countNonEmptyRows(originalCells)) return null;
|
|
1542
|
-
|
|
1623
|
+
const origBody = numRows > 1 ? originalCells.slice(1) : originalCells;
|
|
1624
|
+
if (countNonEmptyCols(rebuilt, numCols) < countNonEmptyCols(origBody, numCols)) return null;
|
|
1543
1625
|
return rebuilt;
|
|
1544
1626
|
}
|
|
1545
1627
|
|
|
1546
1628
|
// src/pdf/text-line.ts
|
|
1629
|
+
function sortLineByX(items) {
|
|
1630
|
+
items.sort((a, b) => a.x - b.x);
|
|
1631
|
+
for (let i = 1; i < items.length; i++) {
|
|
1632
|
+
for (let j = i; j > 0; j--) {
|
|
1633
|
+
const a = items[j - 1], b = items[j];
|
|
1634
|
+
if (b.x - a.x > 1 || a.seq === void 0 || b.seq === void 0 || b.seq >= a.seq) break;
|
|
1635
|
+
items[j - 1] = b;
|
|
1636
|
+
items[j] = a;
|
|
1637
|
+
}
|
|
1638
|
+
}
|
|
1639
|
+
return items;
|
|
1640
|
+
}
|
|
1547
1641
|
function filterHiddenText(items, pageWidth, pageHeight) {
|
|
1548
1642
|
let hiddenCount = 0;
|
|
1549
1643
|
const visible = [];
|
|
@@ -1606,7 +1700,9 @@ function dominantStyle(items) {
|
|
|
1606
1700
|
function normalizeItems(rawItems) {
|
|
1607
1701
|
const items = [];
|
|
1608
1702
|
const spacePositions = [];
|
|
1703
|
+
let seq = 0;
|
|
1609
1704
|
for (const i of rawItems) {
|
|
1705
|
+
seq++;
|
|
1610
1706
|
if (typeof i.str !== "string") continue;
|
|
1611
1707
|
const x = Math.round(i.transform[4]);
|
|
1612
1708
|
const y = Math.round(i.transform[5]);
|
|
@@ -1626,11 +1722,11 @@ function normalizeItems(rawItems) {
|
|
|
1626
1722
|
}
|
|
1627
1723
|
const split = splitEvenSpacedItem(text, x, w, fontSize);
|
|
1628
1724
|
if (split) {
|
|
1629
|
-
|
|
1630
|
-
items.push({ text: s.text, x: s.x, y, w: s.w, h, fontSize, fontName: i.fontName || "", isHidden });
|
|
1631
|
-
}
|
|
1725
|
+
split.forEach((s, k) => {
|
|
1726
|
+
items.push({ text: s.text, x: s.x, y, w: s.w, h, fontSize, fontName: i.fontName || "", isHidden, seq: seq + k / 1e3 });
|
|
1727
|
+
});
|
|
1632
1728
|
} else {
|
|
1633
|
-
items.push({ text, x, y, w, h, fontSize, fontName: i.fontName || "", isHidden });
|
|
1729
|
+
items.push({ text, x, y, w, h, fontSize, fontName: i.fontName || "", isHidden, seq });
|
|
1634
1730
|
}
|
|
1635
1731
|
}
|
|
1636
1732
|
const sorted = items.sort((a, b) => b.y - a.y || a.x - b.x);
|
|
@@ -1728,7 +1824,7 @@ function mergeSuperscriptLines(lines) {
|
|
|
1728
1824
|
}
|
|
1729
1825
|
function mergeLineSimple(items) {
|
|
1730
1826
|
if (items.length <= 1) return items[0]?.text || "";
|
|
1731
|
-
const sorted = [...items]
|
|
1827
|
+
const sorted = sortLineByX([...items]);
|
|
1732
1828
|
const isEvenSpaced = detectEvenSpacedItems(sorted);
|
|
1733
1829
|
let result = sorted[0].text;
|
|
1734
1830
|
for (let i = 1; i < sorted.length; i++) {
|
|
@@ -2146,6 +2242,52 @@ function removeHeaderFooterBlocks(blocks, pageHeights, warnings) {
|
|
|
2146
2242
|
return [...removeSet].sort((a, b) => a - b);
|
|
2147
2243
|
}
|
|
2148
2244
|
|
|
2245
|
+
// src/pdf/table-meta.ts
|
|
2246
|
+
var CLIP_TABLES = /* @__PURE__ */ new WeakSet();
|
|
2247
|
+
var TABLE_COLXS = /* @__PURE__ */ new WeakMap();
|
|
2248
|
+
var EMPTY_PARTS = /* @__PURE__ */ new WeakSet();
|
|
2249
|
+
var IMAGE_CELLS = /* @__PURE__ */ new WeakSet();
|
|
2250
|
+
var FILLER_CELLS = /* @__PURE__ */ new WeakSet();
|
|
2251
|
+
var CELL_LINES = /* @__PURE__ */ new WeakMap();
|
|
2252
|
+
function recordCellLines(cell, items) {
|
|
2253
|
+
const lines = [];
|
|
2254
|
+
for (const it of [...items].sort((a, b) => b.y - a.y)) {
|
|
2255
|
+
const fs = it.fontSize || it.h;
|
|
2256
|
+
const last = lines[lines.length - 1];
|
|
2257
|
+
if (last && Math.abs(last.y - it.y) <= Math.max(3, Math.min(fs, last.h) * 0.6)) {
|
|
2258
|
+
last.l = Math.min(last.l, it.x);
|
|
2259
|
+
last.r = Math.max(last.r, it.x + it.w);
|
|
2260
|
+
last.h = Math.max(last.h, fs);
|
|
2261
|
+
} else lines.push({ y: it.y, l: it.x, r: it.x + it.w, h: fs });
|
|
2262
|
+
}
|
|
2263
|
+
CELL_LINES.set(cell, lines);
|
|
2264
|
+
}
|
|
2265
|
+
|
|
2266
|
+
// src/pdf/table-trim.ts
|
|
2267
|
+
function markImageCell(cell) {
|
|
2268
|
+
IMAGE_CELLS.add(cell);
|
|
2269
|
+
}
|
|
2270
|
+
var emptyCell = (cell) => !cell || !cell.text?.trim() && !cell.blocks?.length && !IMAGE_CELLS.has(cell);
|
|
2271
|
+
function trimTable(table) {
|
|
2272
|
+
let cols = table.cols;
|
|
2273
|
+
while (cols > 0 && table.cells.every((row) => emptyCell(row[cols - 1]))) cols--;
|
|
2274
|
+
if (cols === table.cols || cols === 0) return;
|
|
2275
|
+
table.cells = table.cells.map((row) => row.slice(0, cols));
|
|
2276
|
+
for (const row of table.cells) {
|
|
2277
|
+
for (let c = 0; c < row.length; c++) {
|
|
2278
|
+
if (c + row[c].colSpan > cols) row[c].colSpan = cols - c;
|
|
2279
|
+
}
|
|
2280
|
+
}
|
|
2281
|
+
table.cols = cols;
|
|
2282
|
+
}
|
|
2283
|
+
function trimTrailingEmptyTableCols(blocks) {
|
|
2284
|
+
for (const b of blocks) {
|
|
2285
|
+
if (b.type !== "table" || !b.table) continue;
|
|
2286
|
+
for (const row of b.table.cells) for (const cell of row) if (cell.blocks?.length) trimTrailingEmptyTableCols(cell.blocks);
|
|
2287
|
+
trimTable(b.table);
|
|
2288
|
+
}
|
|
2289
|
+
}
|
|
2290
|
+
|
|
2149
2291
|
// src/pdf/cluster-detector.ts
|
|
2150
2292
|
var Y_TOL = 3;
|
|
2151
2293
|
var COL_CLUSTER_TOL = 15;
|
|
@@ -2242,18 +2384,16 @@ function findTwoColumnProseCutX(items) {
|
|
|
2242
2384
|
const right = [];
|
|
2243
2385
|
let twoSide = 0;
|
|
2244
2386
|
for (const line of lines) {
|
|
2245
|
-
|
|
2246
|
-
let hasR = false;
|
|
2387
|
+
const L = [], R = [];
|
|
2247
2388
|
for (const i of line.items) {
|
|
2248
|
-
if (i.x + i.w <= cutX)
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
|
|
2389
|
+
if (i.x + i.w <= cutX) L.push(i);
|
|
2390
|
+
else if (i.x >= cutX) R.push(i);
|
|
2391
|
+
}
|
|
2392
|
+
if (L.length && R.length) {
|
|
2393
|
+
twoSide++;
|
|
2394
|
+
left.push(...L);
|
|
2395
|
+
right.push(...R);
|
|
2255
2396
|
}
|
|
2256
|
-
if (hasL && hasR) twoSide++;
|
|
2257
2397
|
}
|
|
2258
2398
|
if (twoSide / lines.length < 0.55) return null;
|
|
2259
2399
|
if (left.length < 5 || right.length < 5) return null;
|
|
@@ -3377,7 +3517,7 @@ function extractPageBlocksWithLines(items, pageNum, opList, pageWidth, pageHeigh
|
|
|
3377
3517
|
if (items.length === 0) return [];
|
|
3378
3518
|
const extracted = extractLines(opList.fnArray, opList.argsArray);
|
|
3379
3519
|
let { horizontals, verticals } = extracted;
|
|
3380
|
-
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 }))) : { grids: [], containers: [] };
|
|
3520
|
+
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) : { grids: [], containers: [] };
|
|
3381
3521
|
const clipGrids = clipResult.grids;
|
|
3382
3522
|
if (extraLines) {
|
|
3383
3523
|
horizontals = horizontals.concat(extraLines.horizontals);
|
|
@@ -3395,7 +3535,8 @@ function extractPageBlocksWithLines(items, pageNum, opList, pageWidth, pageHeigh
|
|
|
3395
3535
|
const lineGrids = detectTables ? buildTableGrids(horizontals, verticals) : [];
|
|
3396
3536
|
const grids = [...clipGrids, ...dropGridsInside(lineGrids, clipGrids, clipResult.containers)];
|
|
3397
3537
|
if (grids.length > 0) {
|
|
3398
|
-
|
|
3538
|
+
const imageRegions = extractImageRegions(opList.fnArray, opList.argsArray).filter((r) => r.x2 - r.x1 >= 8 && r.y2 - r.y1 >= 8);
|
|
3539
|
+
return extractBlocksWithGrids(items, pageNum, grids, horizontals, verticals, imageRegions);
|
|
3399
3540
|
}
|
|
3400
3541
|
return extractPageBlocksFallback(items, pageNum, true, detectTables);
|
|
3401
3542
|
}
|
|
@@ -3527,7 +3668,7 @@ function buildFrameCellBlocks(cellItems, nested, pageNum) {
|
|
|
3527
3668
|
const text = blocks.map((b) => b.type === "table" && b.table ? b.table.cells.flat().map((c) => c.text).filter(Boolean).join("\n") : b.text ?? "").filter(Boolean).join("\n");
|
|
3528
3669
|
return { blocks, text };
|
|
3529
3670
|
}
|
|
3530
|
-
function extractBlocksWithGrids(items, pageNum, grids, horizontals, verticals) {
|
|
3671
|
+
function extractBlocksWithGrids(items, pageNum, grids, horizontals, verticals, imageRegions = []) {
|
|
3531
3672
|
const blocks = [];
|
|
3532
3673
|
const usedItems = /* @__PURE__ */ new Set();
|
|
3533
3674
|
const pendingNested = [];
|
|
@@ -3559,7 +3700,8 @@ function extractBlocksWithGrids(items, pageNum, grids, horizontals, verticals) {
|
|
|
3559
3700
|
h: i.h,
|
|
3560
3701
|
fontSize: i.fontSize,
|
|
3561
3702
|
fontName: i.fontName,
|
|
3562
|
-
hasSpaceBefore: i.hasSpaceBefore
|
|
3703
|
+
hasSpaceBefore: i.hasSpaceBefore,
|
|
3704
|
+
seq: i.seq
|
|
3563
3705
|
}));
|
|
3564
3706
|
const cellTextMap = mapTextToCells(textItems, cells);
|
|
3565
3707
|
const assignedItems = /* @__PURE__ */ new Set();
|
|
@@ -3585,11 +3727,21 @@ function extractBlocksWithGrids(items, pageNum, grids, horizontals, verticals) {
|
|
|
3585
3727
|
colSpan: cell.colSpan,
|
|
3586
3728
|
rowSpan: cell.rowSpan
|
|
3587
3729
|
};
|
|
3730
|
+
const b = cell.bbox;
|
|
3731
|
+
const isBackdrop = (r) => r.x1 <= b.x1 + 1 && r.x2 >= b.x2 - 1 && r.y1 <= b.y1 + 1 && r.y2 >= b.y2 - 1;
|
|
3732
|
+
if (imageRegions.some((r) => {
|
|
3733
|
+
const cx = (r.x1 + r.x2) / 2, cy = (r.y1 + r.y2) / 2;
|
|
3734
|
+
return cx > b.x1 && cx < b.x2 && cy > b.y1 && cy < b.y2 && !isBackdrop(r);
|
|
3735
|
+
})) {
|
|
3736
|
+
markImageCell(irGrid[cell.row][cell.col]);
|
|
3737
|
+
}
|
|
3738
|
+
if (cell.filler && !cellItems.length) FILLER_CELLS.add(irGrid[cell.row][cell.col]);
|
|
3739
|
+
if (grid.cells && cellItems.length) recordCellLines(irGrid[cell.row][cell.col], cellItems);
|
|
3588
3740
|
}
|
|
3589
3741
|
let finalGrid = irGrid;
|
|
3590
3742
|
let finalRows = numRows;
|
|
3591
3743
|
let rebuiltUsed = false;
|
|
3592
|
-
if (numRows <= 2 && numCols >= 3 && !nestedAttached) {
|
|
3744
|
+
if (!grid.cells && numRows <= 2 && numCols >= 3 && !nestedAttached) {
|
|
3593
3745
|
const rebuilt = normalizeUndersegmentedTable(irGrid, grid.colXs, textItems);
|
|
3594
3746
|
if (rebuilt) {
|
|
3595
3747
|
rebuiltUsed = true;
|
|
@@ -3608,8 +3760,11 @@ function extractBlocksWithGrids(items, pageNum, grids, horizontals, verticals) {
|
|
|
3608
3760
|
cells: finalGrid,
|
|
3609
3761
|
hasHeader: finalRows > 1
|
|
3610
3762
|
};
|
|
3763
|
+
TABLE_COLXS.set(irTable, grid.colXs);
|
|
3611
3764
|
const hasContent = finalGrid.some((row) => row.some((cell) => cell.text.trim() !== ""));
|
|
3612
|
-
|
|
3765
|
+
const emptyPart = !hasContent && !!grid.cells && !grid.clipParent && !nestedAttached;
|
|
3766
|
+
if (!hasContent && !emptyPart) continue;
|
|
3767
|
+
if (emptyPart) EMPTY_PARTS.add(irTable);
|
|
3613
3768
|
if (grid.clipParent) {
|
|
3614
3769
|
const nb = { page: pageNum, x: grid.bbox.x1, y: grid.bbox.y1, width: grid.bbox.x2 - grid.bbox.x1, height: grid.bbox.y2 - grid.bbox.y1 };
|
|
3615
3770
|
pendingNested.push({ parent: grid.clipParent, block: { type: "table", table: irTable, pageNumber: pageNum, bbox: nb } });
|
|
@@ -3634,6 +3789,7 @@ function extractBlocksWithGrids(items, pageNum, grids, horizontals, verticals) {
|
|
|
3634
3789
|
}
|
|
3635
3790
|
continue;
|
|
3636
3791
|
}
|
|
3792
|
+
if (grid.cells) CLIP_TABLES.add(irTable);
|
|
3637
3793
|
blocks.push({ type: "table", table: irTable, pageNumber: pageNum, bbox: tableBbox });
|
|
3638
3794
|
}
|
|
3639
3795
|
for (const p of pendingNested) blocks.push(p.block);
|
|
@@ -3671,7 +3827,7 @@ function extractBlocksWithGrids(items, pageNum, grids, horizontals, verticals) {
|
|
|
3671
3827
|
{
|
|
3672
3828
|
const rects = remaining.map((i) => ({ x: i.x, y: i.y, w: i.w, h: i.h > 0 ? i.h : i.fontSize }));
|
|
3673
3829
|
for (const b of blocks) {
|
|
3674
|
-
if (b.bbox) rects.push({ x: b.bbox.x, y: b.bbox.y, w: b.bbox.width, h: b.bbox.height });
|
|
3830
|
+
if (b.bbox && !(b.table && EMPTY_PARTS.has(b.table))) rects.push({ x: b.bbox.x, y: b.bbox.y, w: b.bbox.width, h: b.bbox.height });
|
|
3675
3831
|
}
|
|
3676
3832
|
gutterX = detectColumnGutter(rects);
|
|
3677
3833
|
}
|
|
@@ -3748,53 +3904,13 @@ function extractBlocksWithGrids(items, pageNum, grids, horizontals, verticals) {
|
|
|
3748
3904
|
for (const u of units) for (const b of u) ordered.push(b);
|
|
3749
3905
|
return mergeAdjacentTableBlocks(ordered);
|
|
3750
3906
|
}
|
|
3751
|
-
var NEIGHBOR_TABLE_EPSILON = 0.2;
|
|
3752
|
-
function mergeCrossPageTables(blocks) {
|
|
3753
|
-
for (let i = blocks.length - 2; i >= 0; i--) {
|
|
3754
|
-
const prev = blocks[i];
|
|
3755
|
-
const curr = blocks[i + 1];
|
|
3756
|
-
if (prev.type !== "table" || curr.type !== "table" || !prev.table || !curr.table) continue;
|
|
3757
|
-
if (!prev.pageNumber || !curr.pageNumber || curr.pageNumber !== prev.pageNumber + 1) continue;
|
|
3758
|
-
if (prev.table.cols !== curr.table.cols) continue;
|
|
3759
|
-
if (!prev.bbox || !curr.bbox) continue;
|
|
3760
|
-
const width = Math.max(prev.bbox.width, curr.bbox.width, 1);
|
|
3761
|
-
const leftDiff = Math.abs(prev.bbox.x - curr.bbox.x);
|
|
3762
|
-
const rightDiff = Math.abs(prev.bbox.x + prev.bbox.width - (curr.bbox.x + curr.bbox.width));
|
|
3763
|
-
if (leftDiff > width * NEIGHBOR_TABLE_EPSILON || rightDiff > width * NEIGHBOR_TABLE_EPSILON) continue;
|
|
3764
|
-
let currCells = curr.table.cells;
|
|
3765
|
-
if (currCells.length > 1 && prev.table.cells.length > 0 && rowTextsEqual(prev.table.cells[0], currCells[0])) {
|
|
3766
|
-
currCells = currCells.slice(1);
|
|
3767
|
-
}
|
|
3768
|
-
if (currCells.length === 0) {
|
|
3769
|
-
blocks.splice(i + 1, 1);
|
|
3770
|
-
continue;
|
|
3771
|
-
}
|
|
3772
|
-
const merged = {
|
|
3773
|
-
rows: prev.table.rows + currCells.length,
|
|
3774
|
-
cols: prev.table.cols,
|
|
3775
|
-
cells: [...prev.table.cells, ...currCells],
|
|
3776
|
-
hasHeader: prev.table.hasHeader,
|
|
3777
|
-
caption: prev.table.caption
|
|
3778
|
-
};
|
|
3779
|
-
blocks[i] = { ...prev, table: merged };
|
|
3780
|
-
blocks.splice(i + 1, 1);
|
|
3781
|
-
}
|
|
3782
|
-
}
|
|
3783
|
-
function rowTextsEqual(a, b) {
|
|
3784
|
-
if (a.length !== b.length) return false;
|
|
3785
|
-
const norm = (t) => t.replace(/\s+/g, "");
|
|
3786
|
-
for (let i = 0; i < a.length; i++) {
|
|
3787
|
-
if (norm(a[i].text) !== norm(b[i].text)) return false;
|
|
3788
|
-
}
|
|
3789
|
-
return a.some((c) => c.text.trim() !== "");
|
|
3790
|
-
}
|
|
3791
3907
|
function mergeAdjacentTableBlocks(blocks) {
|
|
3792
3908
|
if (blocks.length <= 1) return blocks;
|
|
3793
3909
|
const result = [blocks[0]];
|
|
3794
3910
|
for (let i = 1; i < blocks.length; i++) {
|
|
3795
3911
|
const prev = result[result.length - 1];
|
|
3796
3912
|
const curr = blocks[i];
|
|
3797
|
-
if (prev.type === "table" && curr.type === "table" && prev.table && curr.table && prev.table.cols === curr.table.cols) {
|
|
3913
|
+
if (prev.type === "table" && curr.type === "table" && prev.table && curr.table && prev.table.cols === curr.table.cols && !CLIP_TABLES.has(prev.table) && !CLIP_TABLES.has(curr.table)) {
|
|
3798
3914
|
const merged = {
|
|
3799
3915
|
rows: prev.table.rows + curr.table.rows,
|
|
3800
3916
|
cols: prev.table.cols,
|
|
@@ -3943,7 +4059,13 @@ export {
|
|
|
3943
4059
|
detectTableCaptions,
|
|
3944
4060
|
detectKoreanListBlocks,
|
|
3945
4061
|
removeHeaderFooterBlocks,
|
|
3946
|
-
|
|
3947
|
-
|
|
4062
|
+
CLIP_TABLES,
|
|
4063
|
+
TABLE_COLXS,
|
|
4064
|
+
EMPTY_PARTS,
|
|
4065
|
+
IMAGE_CELLS,
|
|
4066
|
+
FILLER_CELLS,
|
|
4067
|
+
CELL_LINES,
|
|
4068
|
+
trimTrailingEmptyTableCols,
|
|
4069
|
+
extractPageBlocksWithLines
|
|
3948
4070
|
};
|
|
3949
|
-
//# sourceMappingURL=chunk-
|
|
4071
|
+
//# sourceMappingURL=chunk-A275ZQLX.js.map
|