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
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var _chunkHX4UUF7Ycjs = require('./chunk-HX4UUF7Y.cjs');
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
var
|
|
9
|
+
var _chunkEMGF6EEVcjs = require('./chunk-EMGF6EEV.cjs');
|
|
10
10
|
|
|
11
11
|
// src/pdf/image-regions.ts
|
|
12
12
|
var _pdfmjs = require('pdfjs-dist/legacy/build/pdf.mjs');
|
|
@@ -69,6 +69,8 @@ function extractLines(fnArray, argsArray) {
|
|
|
69
69
|
const horizontals = [];
|
|
70
70
|
const verticals = [];
|
|
71
71
|
const clipRects = [];
|
|
72
|
+
const fillRects = [];
|
|
73
|
+
let pathRects = [];
|
|
72
74
|
let pendingClip = false;
|
|
73
75
|
let lineWidth = 1;
|
|
74
76
|
let ctm = [1, 0, 0, 1, 0, 0];
|
|
@@ -84,6 +86,8 @@ function extractLines(fnArray, argsArray) {
|
|
|
84
86
|
currentPath.push({ x1: tx1, y1: ty1, x2: tx2, y2: ty2 });
|
|
85
87
|
}
|
|
86
88
|
function pushRectangle(rx, ry, rw, rh) {
|
|
89
|
+
const [ax, ay] = applyCtm(rx, ry), [bx, by] = applyCtm(rx + rw, ry + rh);
|
|
90
|
+
pathRects.push({ x1: Math.min(ax, bx), y1: Math.min(ay, by), x2: Math.max(ax, bx), y2: Math.max(ay, by) });
|
|
87
91
|
const effH = Math.abs(rh) * Math.hypot(ctm[2], ctm[3]);
|
|
88
92
|
const effW = Math.abs(rw) * Math.hypot(ctm[0], ctm[1]);
|
|
89
93
|
if (effH < ORIENTATION_TOL * 2) {
|
|
@@ -97,7 +101,12 @@ function extractLines(fnArray, argsArray) {
|
|
|
97
101
|
pushSeg(rx, ry + rh, rx, ry);
|
|
98
102
|
}
|
|
99
103
|
}
|
|
100
|
-
function flushPath(isStroke, fromFill = false) {
|
|
104
|
+
function flushPath(isStroke, fromFill = false, filled = fromFill) {
|
|
105
|
+
if (filled) {
|
|
106
|
+
if (pathRects.length) for (const r of pathRects) fillRects.push(r);
|
|
107
|
+
else captureClipRect(currentPath, fillRects, 0.3, 0.3);
|
|
108
|
+
}
|
|
109
|
+
pathRects = [];
|
|
101
110
|
if (!isStroke) {
|
|
102
111
|
if (pendingClip) captureClipRect(currentPath, clipRects);
|
|
103
112
|
pendingClip = false;
|
|
@@ -208,7 +217,7 @@ function extractLines(fnArray, argsArray) {
|
|
|
208
217
|
} else if (afterOp === _pdfmjs.OPS.fill || afterOp === _pdfmjs.OPS.eoFill) {
|
|
209
218
|
flushPath(true, true);
|
|
210
219
|
} else if (afterOp === _pdfmjs.OPS.fillStroke || afterOp === _pdfmjs.OPS.eoFillStroke || afterOp === _pdfmjs.OPS.closeFillStroke || afterOp === _pdfmjs.OPS.closeEOFillStroke) {
|
|
211
|
-
flushPath(true);
|
|
220
|
+
flushPath(true, false, true);
|
|
212
221
|
} else if (afterOp === _pdfmjs.OPS.endPath) {
|
|
213
222
|
flushPath(false);
|
|
214
223
|
}
|
|
@@ -227,7 +236,7 @@ function extractLines(fnArray, argsArray) {
|
|
|
227
236
|
case _pdfmjs.OPS.eoFillStroke:
|
|
228
237
|
case _pdfmjs.OPS.closeFillStroke:
|
|
229
238
|
case _pdfmjs.OPS.closeEOFillStroke:
|
|
230
|
-
flushPath(true);
|
|
239
|
+
flushPath(true, false, true);
|
|
231
240
|
break;
|
|
232
241
|
case _pdfmjs.OPS.endPath:
|
|
233
242
|
flushPath(false);
|
|
@@ -238,11 +247,11 @@ function extractLines(fnArray, argsArray) {
|
|
|
238
247
|
break;
|
|
239
248
|
}
|
|
240
249
|
}
|
|
241
|
-
return { horizontals, verticals, clipRects };
|
|
250
|
+
return { horizontals, verticals, clipRects, fillRects };
|
|
242
251
|
}
|
|
243
252
|
var CLIP_MIN_W = 4;
|
|
244
253
|
var CLIP_MIN_H = 2;
|
|
245
|
-
function captureClipRect(path, out) {
|
|
254
|
+
function captureClipRect(path, out, minW = CLIP_MIN_W, minH = CLIP_MIN_H) {
|
|
246
255
|
if (path.length < 3 || path.length > 5) return;
|
|
247
256
|
let x1 = Infinity, y1 = Infinity, x2 = -Infinity, y2 = -Infinity;
|
|
248
257
|
for (const s of path) {
|
|
@@ -253,7 +262,7 @@ function captureClipRect(path, out) {
|
|
|
253
262
|
y1 = Math.min(y1, s.y1, s.y2);
|
|
254
263
|
y2 = Math.max(y2, s.y1, s.y2);
|
|
255
264
|
}
|
|
256
|
-
if (x2 - x1 <
|
|
265
|
+
if (x2 - x1 < minW || y2 - y1 < minH) return;
|
|
257
266
|
out.push({ x1, y1, x2, y2 });
|
|
258
267
|
}
|
|
259
268
|
function classifyAndAdd(seg, lineWidth, horizontals, verticals, fromFill = false) {
|
|
@@ -960,20 +969,24 @@ function linesIntersect(a, b) {
|
|
|
960
969
|
|
|
961
970
|
// src/pdf/clip-cells.ts
|
|
962
971
|
var CLIP_EDGE_TOL = 1.5;
|
|
972
|
+
var CLIP_ADJ_GAP = 0.15;
|
|
963
973
|
var CLIP_MIN_GROUP = 2;
|
|
964
974
|
var CLIP_MAX_PAGE_FRAC = 0.75;
|
|
965
975
|
var TITLED_FRAME_MIN_TOP = 0.2;
|
|
966
976
|
var TITLED_FRAME_MIN_WIDTH = 0.6;
|
|
967
977
|
var HEADER_BAND = 0.08;
|
|
968
978
|
var CLIP_MIN_W2 = 4;
|
|
979
|
+
var NARROW_FILL_MIN_W = 1;
|
|
969
980
|
var CLIP_MIN_H2 = 2;
|
|
970
981
|
var STROKE_NEAR = 2;
|
|
971
982
|
var STROKE_COVER = 0.5;
|
|
972
983
|
var CLIP_MIN_INVISIBLE = 0;
|
|
984
|
+
var CLIP_COORD_TOL = 0.3;
|
|
973
985
|
var overlap = (a1, a2, b1, b2) => Math.min(a2, b2) - Math.max(a1, b1);
|
|
974
986
|
function adjacent(a, b) {
|
|
975
|
-
|
|
976
|
-
if ((Math.abs(a.
|
|
987
|
+
const al = (u, v) => Math.abs(u - v) <= CLIP_COORD_TOL;
|
|
988
|
+
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;
|
|
989
|
+
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;
|
|
977
990
|
return false;
|
|
978
991
|
}
|
|
979
992
|
function contains(a, b) {
|
|
@@ -984,7 +997,7 @@ function clusterCoords(values) {
|
|
|
984
997
|
const out = [];
|
|
985
998
|
let run = [];
|
|
986
999
|
for (const v of sorted) {
|
|
987
|
-
if (run.length > 0 && v - run[run.length - 1] >
|
|
1000
|
+
if (run.length > 0 && v - run[run.length - 1] > CLIP_COORD_TOL) {
|
|
988
1001
|
out.push(run.reduce((s, x) => s + x, 0) / run.length);
|
|
989
1002
|
run = [];
|
|
990
1003
|
}
|
|
@@ -1010,7 +1023,7 @@ function edgeStroked(lines, dir, pos, a1, a2) {
|
|
|
1010
1023
|
}
|
|
1011
1024
|
return false;
|
|
1012
1025
|
}
|
|
1013
|
-
function buildClipCellGrids(rects, strokedH, strokedV, pageWidth, pageHeight, textPoints = []) {
|
|
1026
|
+
function buildClipCellGrids(rects, strokedH, strokedV, pageWidth, pageHeight, textPoints = [], fillRects = []) {
|
|
1014
1027
|
const pageArea = pageWidth * pageHeight;
|
|
1015
1028
|
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;
|
|
1016
1029
|
const cells = [];
|
|
@@ -1021,15 +1034,45 @@ function buildClipCellGrids(rects, strokedH, strokedV, pageWidth, pageHeight, te
|
|
|
1021
1034
|
}
|
|
1022
1035
|
if (cells.length < 1) return { grids: [], containers: [] };
|
|
1023
1036
|
const parent = new Array(cells.length).fill(-1);
|
|
1037
|
+
const area = (r) => (r.x2 - r.x1) * (r.y2 - r.y1);
|
|
1024
1038
|
for (let i = 0; i < cells.length; i++) {
|
|
1025
1039
|
for (let j = 0; j < cells.length; j++) {
|
|
1026
|
-
if (i === j || !contains(cells[j], cells[i])) continue;
|
|
1040
|
+
if (i === j || area(cells[j]) <= area(cells[i]) || !contains(cells[j], cells[i])) continue;
|
|
1027
1041
|
const cur = parent[i];
|
|
1028
1042
|
if (cur < 0 || contains(cells[cur], cells[j])) parent[i] = j;
|
|
1029
1043
|
}
|
|
1030
1044
|
}
|
|
1031
1045
|
const isContainer = new Array(cells.length).fill(false);
|
|
1032
1046
|
for (const p of parent) if (p >= 0) isContainer[p] = true;
|
|
1047
|
+
const tileParent = new Array(cells.length).fill(false);
|
|
1048
|
+
const tableClip = new Array(cells.length).fill(false);
|
|
1049
|
+
for (let p = 0; p < cells.length; p++) {
|
|
1050
|
+
if (!isContainer[p]) continue;
|
|
1051
|
+
let n = 0, x1 = Infinity, y1 = Infinity, x2 = -Infinity, y2 = -Infinity;
|
|
1052
|
+
for (let i = 0; i < cells.length; i++) {
|
|
1053
|
+
if (parent[i] !== p) continue;
|
|
1054
|
+
const k = cells[i];
|
|
1055
|
+
n++;
|
|
1056
|
+
x1 = Math.min(x1, k.x1);
|
|
1057
|
+
y1 = Math.min(y1, k.y1);
|
|
1058
|
+
x2 = Math.max(x2, k.x2);
|
|
1059
|
+
y2 = Math.max(y2, k.y2);
|
|
1060
|
+
}
|
|
1061
|
+
if (n < CLIP_MIN_GROUP) continue;
|
|
1062
|
+
const c = cells[p];
|
|
1063
|
+
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;
|
|
1064
|
+
}
|
|
1065
|
+
for (let p = 0; p < cells.length; p++) {
|
|
1066
|
+
if (tileParent[p]) tableClip[p] = !cells.some((q, i) => i !== p && parent[i] === parent[p] && !tileParent[i] && adjacent(q, cells[p]));
|
|
1067
|
+
}
|
|
1068
|
+
const effParent = (i) => {
|
|
1069
|
+
let p = parent[i];
|
|
1070
|
+
for (let steps = 0; p >= 0 && steps <= cells.length; steps++) {
|
|
1071
|
+
if (!tableClip[p] && (isGridMember(p) || loneFrame(p))) return p;
|
|
1072
|
+
p = parent[p];
|
|
1073
|
+
}
|
|
1074
|
+
return -1;
|
|
1075
|
+
};
|
|
1033
1076
|
const root = cells.map((_, i) => i);
|
|
1034
1077
|
const find = (i) => {
|
|
1035
1078
|
while (root[i] !== i) {
|
|
@@ -1039,8 +1082,9 @@ function buildClipCellGrids(rects, strokedH, strokedV, pageWidth, pageHeight, te
|
|
|
1039
1082
|
return i;
|
|
1040
1083
|
};
|
|
1041
1084
|
for (let i = 0; i < cells.length; i++) {
|
|
1085
|
+
if (tableClip[i]) continue;
|
|
1042
1086
|
for (let j = i + 1; j < cells.length; j++) {
|
|
1043
|
-
if (parent[i] !== parent[j]) continue;
|
|
1087
|
+
if (tableClip[j] || parent[i] !== parent[j]) continue;
|
|
1044
1088
|
if (adjacent(cells[i], cells[j])) {
|
|
1045
1089
|
const ra = find(i), rb = find(j);
|
|
1046
1090
|
if (ra !== rb) root[ra] = rb;
|
|
@@ -1060,12 +1104,13 @@ function buildClipCellGrids(rects, strokedH, strokedV, pageWidth, pageHeight, te
|
|
|
1060
1104
|
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);
|
|
1061
1105
|
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);
|
|
1062
1106
|
const loneFrame = (i) => isContainer[i] && !isGridMember(i) && (framed(cells[i]) || titledFrame(cells[i]));
|
|
1063
|
-
const parentAttachable = (i) =>
|
|
1107
|
+
const parentAttachable = (i) => effParent(i) >= 0;
|
|
1064
1108
|
const onlyChild = (i) => parent[i] >= 0 && parent.filter((p) => p === parent[i]).length === 1;
|
|
1065
1109
|
const grids = [];
|
|
1066
1110
|
for (const idxs of groups.values()) {
|
|
1067
1111
|
const first = idxs[0];
|
|
1068
|
-
|
|
1112
|
+
if (tableClip[first]) continue;
|
|
1113
|
+
const parentRect = parentAttachable(first) ? cells[effParent(first)] : void 0;
|
|
1069
1114
|
if (idxs.length < CLIP_MIN_GROUP) {
|
|
1070
1115
|
if (!loneFrame(first) && !((parentRect || onlyChild(first)) && framed(cells[first]))) continue;
|
|
1071
1116
|
const r = cells[first];
|
|
@@ -1111,13 +1156,14 @@ function buildClipCellGrids(rects, strokedH, strokedV, pageWidth, pageHeight, te
|
|
|
1111
1156
|
for (let rr = 0; rr < numRows; rr++) {
|
|
1112
1157
|
for (let cc = 0; cc < numCols; cc++) {
|
|
1113
1158
|
if (occupied[rr][cc]) continue;
|
|
1114
|
-
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] } });
|
|
1159
|
+
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 });
|
|
1115
1160
|
}
|
|
1116
1161
|
}
|
|
1162
|
+
addNarrowEdgeCols(colXs, rowYs, out, fillRects);
|
|
1117
1163
|
grids.push({
|
|
1118
1164
|
rowYs,
|
|
1119
1165
|
colXs,
|
|
1120
|
-
bbox: { x1: colXs[0], y1: rowYs[numRows], x2: colXs[
|
|
1166
|
+
bbox: { x1: colXs[0], y1: rowYs[numRows], x2: colXs[colXs.length - 1], y2: rowYs[0] },
|
|
1121
1167
|
vertexRadius: 1,
|
|
1122
1168
|
cells: out,
|
|
1123
1169
|
...parentRect ? { clipParent: parentRect } : {}
|
|
@@ -1125,6 +1171,41 @@ function buildClipCellGrids(rects, strokedH, strokedV, pageWidth, pageHeight, te
|
|
|
1125
1171
|
}
|
|
1126
1172
|
return { grids, containers };
|
|
1127
1173
|
}
|
|
1174
|
+
function addNarrowEdgeCols(colXs, rowYs, out, fills) {
|
|
1175
|
+
if (!fills.length) return;
|
|
1176
|
+
const rowIdx = (y) => {
|
|
1177
|
+
const i = nearestIndex(rowYs, y);
|
|
1178
|
+
return Math.abs(rowYs[i] - y) <= CLIP_COORD_TOL ? i : -1;
|
|
1179
|
+
};
|
|
1180
|
+
for (const side of ["l", "r"]) {
|
|
1181
|
+
const edge = side === "l" ? colXs[0] : colXs[colXs.length - 1];
|
|
1182
|
+
const hits = fills.filter((f) => {
|
|
1183
|
+
const w = f.x2 - f.x1;
|
|
1184
|
+
if (w < NARROW_FILL_MIN_W || w >= CLIP_MIN_W2 || Math.abs((side === "l" ? f.x2 : f.x1) - edge) > CLIP_COORD_TOL) return false;
|
|
1185
|
+
const r0 = rowIdx(f.y2), r1 = rowIdx(f.y1);
|
|
1186
|
+
return r0 >= 0 && r1 > r0;
|
|
1187
|
+
});
|
|
1188
|
+
if (!hits.length) continue;
|
|
1189
|
+
let x = side === "l" ? Infinity : -Infinity;
|
|
1190
|
+
for (const f of hits) x = side === "l" ? Math.min(x, f.x1) : Math.max(x, f.x2);
|
|
1191
|
+
if (side === "l") {
|
|
1192
|
+
colXs.unshift(x);
|
|
1193
|
+
for (const c of out) c.col++;
|
|
1194
|
+
} else colXs.push(x);
|
|
1195
|
+
const col = side === "l" ? 0 : colXs.length - 2;
|
|
1196
|
+
const [cx1, cx2] = [colXs[col], colXs[col + 1]];
|
|
1197
|
+
const taken = new Array(rowYs.length - 1).fill(false);
|
|
1198
|
+
for (const f of hits) {
|
|
1199
|
+
const r0 = rowIdx(f.y2), r1 = rowIdx(f.y1);
|
|
1200
|
+
if (taken.slice(r0, r1).some(Boolean)) continue;
|
|
1201
|
+
taken.fill(true, r0, r1);
|
|
1202
|
+
out.push({ row: r0, col, rowSpan: r1 - r0, colSpan: 1, bbox: { x1: cx1, y1: rowYs[r1], x2: cx2, y2: rowYs[r0] } });
|
|
1203
|
+
}
|
|
1204
|
+
for (let r = 0; r < taken.length; r++) {
|
|
1205
|
+
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 });
|
|
1206
|
+
}
|
|
1207
|
+
}
|
|
1208
|
+
}
|
|
1128
1209
|
function dropGridsInside(lineGrids, clipGrids, containers = []) {
|
|
1129
1210
|
if (clipGrids.length === 0 && containers.length === 0) return lineGrids;
|
|
1130
1211
|
const area = (b) => Math.max(0, b.x2 - b.x1) * Math.max(0, b.y2 - b.y1);
|
|
@@ -1296,7 +1377,7 @@ function cellTextToString(items) {
|
|
|
1296
1377
|
lines.push(curLine);
|
|
1297
1378
|
const merged = mergeSuperscriptRows(lines);
|
|
1298
1379
|
const textLines = merged.map((line) => {
|
|
1299
|
-
const s = line
|
|
1380
|
+
const s = sortLineByX(line);
|
|
1300
1381
|
if (s.length === 1) return s[0].text;
|
|
1301
1382
|
const evenSpaced = detectEvenSpacedItems(s);
|
|
1302
1383
|
let result = s[0].text;
|
|
@@ -1418,7 +1499,7 @@ function mergeCellTextLines(textLines) {
|
|
|
1418
1499
|
merged[merged.length - 1] = prev + curr.trim();
|
|
1419
1500
|
} else if (/[,(]$/.test(prev.trim()) && curr.trim().length <= 15) {
|
|
1420
1501
|
merged[merged.length - 1] = prev + curr.trim();
|
|
1421
|
-
} else if (/[\d,]$/.test(prev) && /^[\d,]+[)\]]?$/.test(curr.trim()) && curr.trim().length <= 10) {
|
|
1502
|
+
} 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()))) {
|
|
1422
1503
|
merged[merged.length - 1] = prev + curr.trim();
|
|
1423
1504
|
} else {
|
|
1424
1505
|
merged.push(curr);
|
|
@@ -1538,11 +1619,24 @@ function normalizeUndersegmentedTable(originalCells, colXs, items) {
|
|
|
1538
1619
|
return n;
|
|
1539
1620
|
};
|
|
1540
1621
|
if (countNonEmptyRows(rebuilt) <= countNonEmptyRows(originalCells)) return null;
|
|
1541
|
-
|
|
1622
|
+
const origBody = numRows > 1 ? originalCells.slice(1) : originalCells;
|
|
1623
|
+
if (countNonEmptyCols(rebuilt, numCols) < countNonEmptyCols(origBody, numCols)) return null;
|
|
1542
1624
|
return rebuilt;
|
|
1543
1625
|
}
|
|
1544
1626
|
|
|
1545
1627
|
// src/pdf/text-line.ts
|
|
1628
|
+
function sortLineByX(items) {
|
|
1629
|
+
items.sort((a, b) => a.x - b.x);
|
|
1630
|
+
for (let i = 1; i < items.length; i++) {
|
|
1631
|
+
for (let j = i; j > 0; j--) {
|
|
1632
|
+
const a = items[j - 1], b = items[j];
|
|
1633
|
+
if (b.x - a.x > 1 || a.seq === void 0 || b.seq === void 0 || b.seq >= a.seq) break;
|
|
1634
|
+
items[j - 1] = b;
|
|
1635
|
+
items[j] = a;
|
|
1636
|
+
}
|
|
1637
|
+
}
|
|
1638
|
+
return items;
|
|
1639
|
+
}
|
|
1546
1640
|
function filterHiddenText(items, pageWidth, pageHeight) {
|
|
1547
1641
|
let hiddenCount = 0;
|
|
1548
1642
|
const visible = [];
|
|
@@ -1605,7 +1699,9 @@ function dominantStyle(items) {
|
|
|
1605
1699
|
function normalizeItems(rawItems) {
|
|
1606
1700
|
const items = [];
|
|
1607
1701
|
const spacePositions = [];
|
|
1702
|
+
let seq = 0;
|
|
1608
1703
|
for (const i of rawItems) {
|
|
1704
|
+
seq++;
|
|
1609
1705
|
if (typeof i.str !== "string") continue;
|
|
1610
1706
|
const x = Math.round(i.transform[4]);
|
|
1611
1707
|
const y = Math.round(i.transform[5]);
|
|
@@ -1625,11 +1721,11 @@ function normalizeItems(rawItems) {
|
|
|
1625
1721
|
}
|
|
1626
1722
|
const split = splitEvenSpacedItem(text, x, w, fontSize);
|
|
1627
1723
|
if (split) {
|
|
1628
|
-
|
|
1629
|
-
items.push({ text: s.text, x: s.x, y, w: s.w, h, fontSize, fontName: i.fontName || "", isHidden });
|
|
1630
|
-
}
|
|
1724
|
+
split.forEach((s, k) => {
|
|
1725
|
+
items.push({ text: s.text, x: s.x, y, w: s.w, h, fontSize, fontName: i.fontName || "", isHidden, seq: seq + k / 1e3 });
|
|
1726
|
+
});
|
|
1631
1727
|
} else {
|
|
1632
|
-
items.push({ text, x, y, w, h, fontSize, fontName: i.fontName || "", isHidden });
|
|
1728
|
+
items.push({ text, x, y, w, h, fontSize, fontName: i.fontName || "", isHidden, seq });
|
|
1633
1729
|
}
|
|
1634
1730
|
}
|
|
1635
1731
|
const sorted = items.sort((a, b) => b.y - a.y || a.x - b.x);
|
|
@@ -1727,7 +1823,7 @@ function mergeSuperscriptLines(lines) {
|
|
|
1727
1823
|
}
|
|
1728
1824
|
function mergeLineSimple(items) {
|
|
1729
1825
|
if (items.length <= 1) return _optionalChain([items, 'access', _10 => _10[0], 'optionalAccess', _11 => _11.text]) || "";
|
|
1730
|
-
const sorted = [...items]
|
|
1826
|
+
const sorted = sortLineByX([...items]);
|
|
1731
1827
|
const isEvenSpaced = detectEvenSpacedItems(sorted);
|
|
1732
1828
|
let result = sorted[0].text;
|
|
1733
1829
|
for (let i = 1; i < sorted.length; i++) {
|
|
@@ -1781,9 +1877,9 @@ function detectHeadings(blocks, medianFontSize) {
|
|
|
1781
1877
|
if (/^\d+$/.test(text)) continue;
|
|
1782
1878
|
const ratio = block.style.fontSize / medianFontSize;
|
|
1783
1879
|
let level = 0;
|
|
1784
|
-
if (ratio >=
|
|
1785
|
-
else if (ratio >=
|
|
1786
|
-
else if (ratio >=
|
|
1880
|
+
if (ratio >= _chunkHX4UUF7Ycjs.HEADING_RATIO_H1) level = 1;
|
|
1881
|
+
else if (ratio >= _chunkHX4UUF7Ycjs.HEADING_RATIO_H2) level = 2;
|
|
1882
|
+
else if (ratio >= _chunkHX4UUF7Ycjs.HEADING_RATIO_H3) level = 3;
|
|
1787
1883
|
if (level > 0) {
|
|
1788
1884
|
block.type = "heading";
|
|
1789
1885
|
block.level = level;
|
|
@@ -2145,6 +2241,52 @@ function removeHeaderFooterBlocks(blocks, pageHeights, warnings) {
|
|
|
2145
2241
|
return [...removeSet].sort((a, b) => a - b);
|
|
2146
2242
|
}
|
|
2147
2243
|
|
|
2244
|
+
// src/pdf/table-meta.ts
|
|
2245
|
+
var CLIP_TABLES = /* @__PURE__ */ new WeakSet();
|
|
2246
|
+
var TABLE_COLXS = /* @__PURE__ */ new WeakMap();
|
|
2247
|
+
var EMPTY_PARTS = /* @__PURE__ */ new WeakSet();
|
|
2248
|
+
var IMAGE_CELLS = /* @__PURE__ */ new WeakSet();
|
|
2249
|
+
var FILLER_CELLS = /* @__PURE__ */ new WeakSet();
|
|
2250
|
+
var CELL_LINES = /* @__PURE__ */ new WeakMap();
|
|
2251
|
+
function recordCellLines(cell, items) {
|
|
2252
|
+
const lines = [];
|
|
2253
|
+
for (const it of [...items].sort((a, b) => b.y - a.y)) {
|
|
2254
|
+
const fs = it.fontSize || it.h;
|
|
2255
|
+
const last = lines[lines.length - 1];
|
|
2256
|
+
if (last && Math.abs(last.y - it.y) <= Math.max(3, Math.min(fs, last.h) * 0.6)) {
|
|
2257
|
+
last.l = Math.min(last.l, it.x);
|
|
2258
|
+
last.r = Math.max(last.r, it.x + it.w);
|
|
2259
|
+
last.h = Math.max(last.h, fs);
|
|
2260
|
+
} else lines.push({ y: it.y, l: it.x, r: it.x + it.w, h: fs });
|
|
2261
|
+
}
|
|
2262
|
+
CELL_LINES.set(cell, lines);
|
|
2263
|
+
}
|
|
2264
|
+
|
|
2265
|
+
// src/pdf/table-trim.ts
|
|
2266
|
+
function markImageCell(cell) {
|
|
2267
|
+
IMAGE_CELLS.add(cell);
|
|
2268
|
+
}
|
|
2269
|
+
var emptyCell = (cell) => !cell || !_optionalChain([cell, 'access', _27 => _27.text, 'optionalAccess', _28 => _28.trim, 'call', _29 => _29()]) && !_optionalChain([cell, 'access', _30 => _30.blocks, 'optionalAccess', _31 => _31.length]) && !IMAGE_CELLS.has(cell);
|
|
2270
|
+
function trimTable(table) {
|
|
2271
|
+
let cols = table.cols;
|
|
2272
|
+
while (cols > 0 && table.cells.every((row) => emptyCell(row[cols - 1]))) cols--;
|
|
2273
|
+
if (cols === table.cols || cols === 0) return;
|
|
2274
|
+
table.cells = table.cells.map((row) => row.slice(0, cols));
|
|
2275
|
+
for (const row of table.cells) {
|
|
2276
|
+
for (let c = 0; c < row.length; c++) {
|
|
2277
|
+
if (c + row[c].colSpan > cols) row[c].colSpan = cols - c;
|
|
2278
|
+
}
|
|
2279
|
+
}
|
|
2280
|
+
table.cols = cols;
|
|
2281
|
+
}
|
|
2282
|
+
function trimTrailingEmptyTableCols(blocks) {
|
|
2283
|
+
for (const b of blocks) {
|
|
2284
|
+
if (b.type !== "table" || !b.table) continue;
|
|
2285
|
+
for (const row of b.table.cells) for (const cell of row) if (_optionalChain([cell, 'access', _32 => _32.blocks, 'optionalAccess', _33 => _33.length])) trimTrailingEmptyTableCols(cell.blocks);
|
|
2286
|
+
trimTable(b.table);
|
|
2287
|
+
}
|
|
2288
|
+
}
|
|
2289
|
+
|
|
2148
2290
|
// src/pdf/cluster-detector.ts
|
|
2149
2291
|
var Y_TOL = 3;
|
|
2150
2292
|
var COL_CLUSTER_TOL = 15;
|
|
@@ -2199,12 +2341,12 @@ function isTwoColumnProse(r) {
|
|
|
2199
2341
|
if (t.rows < 8) return false;
|
|
2200
2342
|
const dense = [];
|
|
2201
2343
|
for (let c = 0; c < t.cols; c++) {
|
|
2202
|
-
const filled = t.cells.filter((row) => _optionalChain([row, 'access',
|
|
2344
|
+
const filled = t.cells.filter((row) => _optionalChain([row, 'access', _34 => _34[c], 'optionalAccess', _35 => _35.text, 'access', _36 => _36.trim, 'call', _37 => _37()])).length;
|
|
2203
2345
|
if (filled / t.rows >= 0.3) dense.push(c);
|
|
2204
2346
|
}
|
|
2205
2347
|
if (dense.length !== 2) return false;
|
|
2206
2348
|
for (const c of dense) {
|
|
2207
|
-
const lens = t.cells.map((row) => _nullishCoalesce(_optionalChain([row, 'access',
|
|
2349
|
+
const lens = t.cells.map((row) => _nullishCoalesce(_optionalChain([row, 'access', _38 => _38[c], 'optionalAccess', _39 => _39.text, 'access', _40 => _40.replace, 'call', _41 => _41(/\s+/g, ""), 'access', _42 => _42.length]), () => ( 0))).filter((n) => n > 0);
|
|
2208
2350
|
const avg = lens.reduce((s, v) => s + v, 0) / (lens.length || 1);
|
|
2209
2351
|
if (avg < 12) return false;
|
|
2210
2352
|
}
|
|
@@ -2241,18 +2383,16 @@ function findTwoColumnProseCutX(items) {
|
|
|
2241
2383
|
const right = [];
|
|
2242
2384
|
let twoSide = 0;
|
|
2243
2385
|
for (const line of lines) {
|
|
2244
|
-
|
|
2245
|
-
let hasR = false;
|
|
2386
|
+
const L = [], R = [];
|
|
2246
2387
|
for (const i of line.items) {
|
|
2247
|
-
if (i.x + i.w <= cutX)
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
2388
|
+
if (i.x + i.w <= cutX) L.push(i);
|
|
2389
|
+
else if (i.x >= cutX) R.push(i);
|
|
2390
|
+
}
|
|
2391
|
+
if (L.length && R.length) {
|
|
2392
|
+
twoSide++;
|
|
2393
|
+
left.push(...L);
|
|
2394
|
+
right.push(...R);
|
|
2254
2395
|
}
|
|
2255
|
-
if (hasL && hasR) twoSide++;
|
|
2256
2396
|
}
|
|
2257
2397
|
if (twoSide / lines.length < 0.55) return null;
|
|
2258
2398
|
if (left.length < 5 || right.length < 5) return null;
|
|
@@ -2681,7 +2821,7 @@ function buildClusterTable(rows, columns, pageNum) {
|
|
|
2681
2821
|
const nonEmptyCols = cells[r].filter((c) => c.text.trim()).length;
|
|
2682
2822
|
if (nonEmptyCols !== 1) continue;
|
|
2683
2823
|
if (cells[r][0].text.trim() !== "") continue;
|
|
2684
|
-
const contentText = _optionalChain([cells, 'access',
|
|
2824
|
+
const contentText = _optionalChain([cells, 'access', _43 => _43[r], 'access', _44 => _44.find, 'call', _45 => _45((c) => c.text.trim()), 'optionalAccess', _46 => _46.text, 'access', _47 => _47.trim, 'call', _48 => _48()]) || "";
|
|
2685
2825
|
if (/^[○●▶\-·]/.test(contentText)) continue;
|
|
2686
2826
|
for (let pr = r - 1; pr >= 0; pr--) {
|
|
2687
2827
|
if (cells[pr].some((c) => c.text.trim())) {
|
|
@@ -3046,14 +3186,14 @@ function isProseSpread(items) {
|
|
|
3046
3186
|
for (let i = 1; i < sorted.length; i++) {
|
|
3047
3187
|
gaps.push(sorted[i].x - (sorted[i - 1].x + sorted[i - 1].w));
|
|
3048
3188
|
}
|
|
3049
|
-
const maxGap =
|
|
3189
|
+
const maxGap = _chunkEMGF6EEVcjs.safeMax.call(void 0, gaps);
|
|
3050
3190
|
const avgLen = items.reduce((s, i) => s + i.text.length, 0) / items.length;
|
|
3051
3191
|
return maxGap < 40 && avgLen < 5;
|
|
3052
3192
|
}
|
|
3053
3193
|
function detectColumns(yLines) {
|
|
3054
3194
|
const allItems = yLines.flat();
|
|
3055
3195
|
if (allItems.length === 0) return null;
|
|
3056
|
-
const pageWidth =
|
|
3196
|
+
const pageWidth = _chunkEMGF6EEVcjs.safeMax.call(void 0, allItems.map((i) => i.x + i.w)) - _chunkEMGF6EEVcjs.safeMin.call(void 0, allItems.map((i) => i.x));
|
|
3057
3197
|
if (pageWidth < 100) return null;
|
|
3058
3198
|
let bigoLineIdx = -1;
|
|
3059
3199
|
for (let i = 0; i < yLines.length; i++) {
|
|
@@ -3376,7 +3516,7 @@ function extractPageBlocksWithLines(items, pageNum, opList, pageWidth, pageHeigh
|
|
|
3376
3516
|
if (items.length === 0) return [];
|
|
3377
3517
|
const extracted = extractLines(opList.fnArray, opList.argsArray);
|
|
3378
3518
|
let { horizontals, verticals } = extracted;
|
|
3379
|
-
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: [] };
|
|
3519
|
+
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: [] };
|
|
3380
3520
|
const clipGrids = clipResult.grids;
|
|
3381
3521
|
if (extraLines) {
|
|
3382
3522
|
horizontals = horizontals.concat(extraLines.horizontals);
|
|
@@ -3394,7 +3534,8 @@ function extractPageBlocksWithLines(items, pageNum, opList, pageWidth, pageHeigh
|
|
|
3394
3534
|
const lineGrids = detectTables ? buildTableGrids(horizontals, verticals) : [];
|
|
3395
3535
|
const grids = [...clipGrids, ...dropGridsInside(lineGrids, clipGrids, clipResult.containers)];
|
|
3396
3536
|
if (grids.length > 0) {
|
|
3397
|
-
|
|
3537
|
+
const imageRegions = extractImageRegions(opList.fnArray, opList.argsArray).filter((r) => r.x2 - r.x1 >= 8 && r.y2 - r.y1 >= 8);
|
|
3538
|
+
return extractBlocksWithGrids(items, pageNum, grids, horizontals, verticals, imageRegions);
|
|
3398
3539
|
}
|
|
3399
3540
|
return extractPageBlocksFallback(items, pageNum, true, detectTables);
|
|
3400
3541
|
}
|
|
@@ -3526,7 +3667,7 @@ function buildFrameCellBlocks(cellItems, nested, pageNum) {
|
|
|
3526
3667
|
const text = blocks.map((b) => b.type === "table" && b.table ? b.table.cells.flat().map((c) => c.text).filter(Boolean).join("\n") : _nullishCoalesce(b.text, () => ( ""))).filter(Boolean).join("\n");
|
|
3527
3668
|
return { blocks, text };
|
|
3528
3669
|
}
|
|
3529
|
-
function extractBlocksWithGrids(items, pageNum, grids, horizontals, verticals) {
|
|
3670
|
+
function extractBlocksWithGrids(items, pageNum, grids, horizontals, verticals, imageRegions = []) {
|
|
3530
3671
|
const blocks = [];
|
|
3531
3672
|
const usedItems = /* @__PURE__ */ new Set();
|
|
3532
3673
|
const pendingNested = [];
|
|
@@ -3558,7 +3699,8 @@ function extractBlocksWithGrids(items, pageNum, grids, horizontals, verticals) {
|
|
|
3558
3699
|
h: i.h,
|
|
3559
3700
|
fontSize: i.fontSize,
|
|
3560
3701
|
fontName: i.fontName,
|
|
3561
|
-
hasSpaceBefore: i.hasSpaceBefore
|
|
3702
|
+
hasSpaceBefore: i.hasSpaceBefore,
|
|
3703
|
+
seq: i.seq
|
|
3562
3704
|
}));
|
|
3563
3705
|
const cellTextMap = mapTextToCells(textItems, cells);
|
|
3564
3706
|
const assignedItems = /* @__PURE__ */ new Set();
|
|
@@ -3584,11 +3726,21 @@ function extractBlocksWithGrids(items, pageNum, grids, horizontals, verticals) {
|
|
|
3584
3726
|
colSpan: cell.colSpan,
|
|
3585
3727
|
rowSpan: cell.rowSpan
|
|
3586
3728
|
};
|
|
3729
|
+
const b = cell.bbox;
|
|
3730
|
+
const isBackdrop = (r) => r.x1 <= b.x1 + 1 && r.x2 >= b.x2 - 1 && r.y1 <= b.y1 + 1 && r.y2 >= b.y2 - 1;
|
|
3731
|
+
if (imageRegions.some((r) => {
|
|
3732
|
+
const cx = (r.x1 + r.x2) / 2, cy = (r.y1 + r.y2) / 2;
|
|
3733
|
+
return cx > b.x1 && cx < b.x2 && cy > b.y1 && cy < b.y2 && !isBackdrop(r);
|
|
3734
|
+
})) {
|
|
3735
|
+
markImageCell(irGrid[cell.row][cell.col]);
|
|
3736
|
+
}
|
|
3737
|
+
if (cell.filler && !cellItems.length) FILLER_CELLS.add(irGrid[cell.row][cell.col]);
|
|
3738
|
+
if (grid.cells && cellItems.length) recordCellLines(irGrid[cell.row][cell.col], cellItems);
|
|
3587
3739
|
}
|
|
3588
3740
|
let finalGrid = irGrid;
|
|
3589
3741
|
let finalRows = numRows;
|
|
3590
3742
|
let rebuiltUsed = false;
|
|
3591
|
-
if (numRows <= 2 && numCols >= 3 && !nestedAttached) {
|
|
3743
|
+
if (!grid.cells && numRows <= 2 && numCols >= 3 && !nestedAttached) {
|
|
3592
3744
|
const rebuilt = normalizeUndersegmentedTable(irGrid, grid.colXs, textItems);
|
|
3593
3745
|
if (rebuilt) {
|
|
3594
3746
|
rebuiltUsed = true;
|
|
@@ -3607,8 +3759,11 @@ function extractBlocksWithGrids(items, pageNum, grids, horizontals, verticals) {
|
|
|
3607
3759
|
cells: finalGrid,
|
|
3608
3760
|
hasHeader: finalRows > 1
|
|
3609
3761
|
};
|
|
3762
|
+
TABLE_COLXS.set(irTable, grid.colXs);
|
|
3610
3763
|
const hasContent = finalGrid.some((row) => row.some((cell) => cell.text.trim() !== ""));
|
|
3611
|
-
|
|
3764
|
+
const emptyPart = !hasContent && !!grid.cells && !grid.clipParent && !nestedAttached;
|
|
3765
|
+
if (!hasContent && !emptyPart) continue;
|
|
3766
|
+
if (emptyPart) EMPTY_PARTS.add(irTable);
|
|
3612
3767
|
if (grid.clipParent) {
|
|
3613
3768
|
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 };
|
|
3614
3769
|
pendingNested.push({ parent: grid.clipParent, block: { type: "table", table: irTable, pageNumber: pageNum, bbox: nb } });
|
|
@@ -3633,6 +3788,7 @@ function extractBlocksWithGrids(items, pageNum, grids, horizontals, verticals) {
|
|
|
3633
3788
|
}
|
|
3634
3789
|
continue;
|
|
3635
3790
|
}
|
|
3791
|
+
if (grid.cells) CLIP_TABLES.add(irTable);
|
|
3636
3792
|
blocks.push({ type: "table", table: irTable, pageNumber: pageNum, bbox: tableBbox });
|
|
3637
3793
|
}
|
|
3638
3794
|
for (const p of pendingNested) blocks.push(p.block);
|
|
@@ -3670,7 +3826,7 @@ function extractBlocksWithGrids(items, pageNum, grids, horizontals, verticals) {
|
|
|
3670
3826
|
{
|
|
3671
3827
|
const rects = remaining.map((i) => ({ x: i.x, y: i.y, w: i.w, h: i.h > 0 ? i.h : i.fontSize }));
|
|
3672
3828
|
for (const b of blocks) {
|
|
3673
|
-
if (b.bbox) rects.push({ x: b.bbox.x, y: b.bbox.y, w: b.bbox.width, h: b.bbox.height });
|
|
3829
|
+
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 });
|
|
3674
3830
|
}
|
|
3675
3831
|
gutterX = detectColumnGutter(rects);
|
|
3676
3832
|
}
|
|
@@ -3678,7 +3834,7 @@ function extractBlocksWithGrids(items, pageNum, grids, horizontals, verticals) {
|
|
|
3678
3834
|
if (gutterX !== null) {
|
|
3679
3835
|
const gx = gutterX;
|
|
3680
3836
|
const allY = remaining.map((i) => i.y);
|
|
3681
|
-
const pageH =
|
|
3837
|
+
const pageH = _chunkEMGF6EEVcjs.safeMax.call(void 0, allY) - _chunkEMGF6EEVcjs.safeMin.call(void 0, allY);
|
|
3682
3838
|
const gapThreshold = Math.max(15, pageH * 0.03);
|
|
3683
3839
|
const sides = [
|
|
3684
3840
|
remaining.filter((i) => i.x + i.w <= gx),
|
|
@@ -3698,7 +3854,7 @@ function extractBlocksWithGrids(items, pageNum, grids, horizontals, verticals) {
|
|
|
3698
3854
|
finalTextBlocks = detectListBlocks(textBlocks);
|
|
3699
3855
|
} else {
|
|
3700
3856
|
const allY = remaining.map((i) => i.y);
|
|
3701
|
-
const pageH =
|
|
3857
|
+
const pageH = _chunkEMGF6EEVcjs.safeMax.call(void 0, allY) - _chunkEMGF6EEVcjs.safeMin.call(void 0, allY);
|
|
3702
3858
|
const groups = xyCutOrder(remaining, Math.max(15, pageH * 0.03));
|
|
3703
3859
|
const textBlocks = [];
|
|
3704
3860
|
for (const group of groups) {
|
|
@@ -3747,53 +3903,13 @@ function extractBlocksWithGrids(items, pageNum, grids, horizontals, verticals) {
|
|
|
3747
3903
|
for (const u of units) for (const b of u) ordered.push(b);
|
|
3748
3904
|
return mergeAdjacentTableBlocks(ordered);
|
|
3749
3905
|
}
|
|
3750
|
-
var NEIGHBOR_TABLE_EPSILON = 0.2;
|
|
3751
|
-
function mergeCrossPageTables(blocks) {
|
|
3752
|
-
for (let i = blocks.length - 2; i >= 0; i--) {
|
|
3753
|
-
const prev = blocks[i];
|
|
3754
|
-
const curr = blocks[i + 1];
|
|
3755
|
-
if (prev.type !== "table" || curr.type !== "table" || !prev.table || !curr.table) continue;
|
|
3756
|
-
if (!prev.pageNumber || !curr.pageNumber || curr.pageNumber !== prev.pageNumber + 1) continue;
|
|
3757
|
-
if (prev.table.cols !== curr.table.cols) continue;
|
|
3758
|
-
if (!prev.bbox || !curr.bbox) continue;
|
|
3759
|
-
const width = Math.max(prev.bbox.width, curr.bbox.width, 1);
|
|
3760
|
-
const leftDiff = Math.abs(prev.bbox.x - curr.bbox.x);
|
|
3761
|
-
const rightDiff = Math.abs(prev.bbox.x + prev.bbox.width - (curr.bbox.x + curr.bbox.width));
|
|
3762
|
-
if (leftDiff > width * NEIGHBOR_TABLE_EPSILON || rightDiff > width * NEIGHBOR_TABLE_EPSILON) continue;
|
|
3763
|
-
let currCells = curr.table.cells;
|
|
3764
|
-
if (currCells.length > 1 && prev.table.cells.length > 0 && rowTextsEqual(prev.table.cells[0], currCells[0])) {
|
|
3765
|
-
currCells = currCells.slice(1);
|
|
3766
|
-
}
|
|
3767
|
-
if (currCells.length === 0) {
|
|
3768
|
-
blocks.splice(i + 1, 1);
|
|
3769
|
-
continue;
|
|
3770
|
-
}
|
|
3771
|
-
const merged = {
|
|
3772
|
-
rows: prev.table.rows + currCells.length,
|
|
3773
|
-
cols: prev.table.cols,
|
|
3774
|
-
cells: [...prev.table.cells, ...currCells],
|
|
3775
|
-
hasHeader: prev.table.hasHeader,
|
|
3776
|
-
caption: prev.table.caption
|
|
3777
|
-
};
|
|
3778
|
-
blocks[i] = { ...prev, table: merged };
|
|
3779
|
-
blocks.splice(i + 1, 1);
|
|
3780
|
-
}
|
|
3781
|
-
}
|
|
3782
|
-
function rowTextsEqual(a, b) {
|
|
3783
|
-
if (a.length !== b.length) return false;
|
|
3784
|
-
const norm = (t) => t.replace(/\s+/g, "");
|
|
3785
|
-
for (let i = 0; i < a.length; i++) {
|
|
3786
|
-
if (norm(a[i].text) !== norm(b[i].text)) return false;
|
|
3787
|
-
}
|
|
3788
|
-
return a.some((c) => c.text.trim() !== "");
|
|
3789
|
-
}
|
|
3790
3906
|
function mergeAdjacentTableBlocks(blocks) {
|
|
3791
3907
|
if (blocks.length <= 1) return blocks;
|
|
3792
3908
|
const result = [blocks[0]];
|
|
3793
3909
|
for (let i = 1; i < blocks.length; i++) {
|
|
3794
3910
|
const prev = result[result.length - 1];
|
|
3795
3911
|
const curr = blocks[i];
|
|
3796
|
-
if (prev.type === "table" && curr.type === "table" && prev.table && curr.table && prev.table.cols === curr.table.cols) {
|
|
3912
|
+
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)) {
|
|
3797
3913
|
const merged = {
|
|
3798
3914
|
rows: prev.table.rows + curr.table.rows,
|
|
3799
3915
|
cols: prev.table.cols,
|
|
@@ -3906,7 +4022,7 @@ function extractPageBlocksFallback(items, pageNum, fullPage = false, detectTable
|
|
|
3906
4022
|
blocks.push({ type: "paragraph", text: tableText, pageNumber: pageNum, bbox, style: dominantStyle(items) });
|
|
3907
4023
|
} else {
|
|
3908
4024
|
const allY = items.map((i) => i.y);
|
|
3909
|
-
const pageHeight =
|
|
4025
|
+
const pageHeight = _chunkEMGF6EEVcjs.safeMax.call(void 0, allY) - _chunkEMGF6EEVcjs.safeMin.call(void 0, allY);
|
|
3910
4026
|
const gapThreshold = Math.max(15, pageHeight * 0.03);
|
|
3911
4027
|
const orderedGroups = proseCutX !== null ? splitTwoColumnProse(items, proseCutX) : xyCutOrder(items, gapThreshold);
|
|
3912
4028
|
for (const group of orderedGroups) {
|
|
@@ -3944,5 +4060,11 @@ function extractPageBlocksFallback(items, pageNum, fullPage = false, detectTable
|
|
|
3944
4060
|
|
|
3945
4061
|
|
|
3946
4062
|
|
|
3947
|
-
|
|
3948
|
-
|
|
4063
|
+
|
|
4064
|
+
|
|
4065
|
+
|
|
4066
|
+
|
|
4067
|
+
|
|
4068
|
+
|
|
4069
|
+
exports.extractImageRegions = extractImageRegions; exports.filterHiddenText = filterHiddenText; exports.collapseEvenSpacing = collapseEvenSpacing; exports.normalizeItems = normalizeItems; exports.computeMedianFontSizeFromFreq = computeMedianFontSizeFromFreq; exports.detectHeadings = detectHeadings; exports.detectMarkerHeadings = detectMarkerHeadings; exports.detectTableCaptions = detectTableCaptions; exports.detectKoreanListBlocks = detectKoreanListBlocks; exports.removeHeaderFooterBlocks = removeHeaderFooterBlocks; exports.CLIP_TABLES = CLIP_TABLES; exports.TABLE_COLXS = TABLE_COLXS; exports.EMPTY_PARTS = EMPTY_PARTS; exports.IMAGE_CELLS = IMAGE_CELLS; exports.FILLER_CELLS = FILLER_CELLS; exports.CELL_LINES = CELL_LINES; exports.trimTrailingEmptyTableCols = trimTrailingEmptyTableCols; exports.extractPageBlocksWithLines = extractPageBlocksWithLines;
|
|
4070
|
+
//# sourceMappingURL=chunk-NOAQRCV6.cjs.map
|