kordoc 4.16.2 → 4.17.0
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 +14 -13
- package/dist/{-4G6MA4X6.js → -PRAKO6M4.js} +11 -11
- package/dist/{chunk-AUWGDP4G.js → chunk-2KF5WZCR.js} +2 -2
- package/dist/{chunk-UTP2WCHS.js → chunk-4GSF2R7T.js} +4 -4
- package/dist/{chunk-TXUKTOG2.js → chunk-4XVNQAK5.js} +219 -23
- package/dist/chunk-4XVNQAK5.js.map +1 -0
- package/dist/chunk-5CDUL6PH.js +250 -0
- package/dist/chunk-5CDUL6PH.js.map +1 -0
- package/dist/{chunk-4VODJKFL.js → chunk-6RGGYQQC.js} +3 -3
- package/dist/{chunk-DES2LGFZ.js → chunk-A55JGNKD.js} +2 -2
- package/dist/chunk-AKB72TEH.cjs +248 -0
- package/dist/chunk-AKB72TEH.cjs.map +1 -0
- package/dist/{chunk-LEIAEWZ7.js → chunk-BFT5IM2R.js} +2 -2
- package/dist/{chunk-KIOQ4N37.js → chunk-BLPR4HRF.js} +2 -2
- package/dist/{chunk-JELRWAZC.js → chunk-BZG7K44Z.js} +2 -2
- package/dist/{chunk-F4NRLLY4.js → chunk-EFO6JZY6.js} +2 -2
- package/dist/chunk-GS7T56RP.cjs.map +1 -1
- package/dist/{chunk-JFLAM3MM.js → chunk-I5DJOP62.js} +2 -2
- package/dist/chunk-I5DJOP62.js.map +1 -0
- package/dist/chunk-J55UQC5H.cjs.map +1 -1
- package/dist/{chunk-QOCS7W7R.js → chunk-K2VYABZ3.js} +86 -43
- package/dist/chunk-K2VYABZ3.js.map +1 -0
- package/dist/chunk-MJBCXW5R.js +248 -0
- package/dist/chunk-MJBCXW5R.js.map +1 -0
- package/dist/{chunk-MLIS253L.js → chunk-ML4NHUR7.js} +2 -2
- package/dist/{chunk-GO5IFOUF.js → chunk-N6V7LQBL.js} +2 -2
- package/dist/{chunk-FKUDAIJI.cjs → chunk-O7OUX6NU.cjs} +12 -12
- package/dist/chunk-O7OUX6NU.cjs.map +1 -0
- package/dist/{chunk-S2PL227Q.js → chunk-PHID6WNG.js} +2 -2
- package/dist/{chunk-IQGIT2VX.js → chunk-QJWVMPB6.js} +34 -17
- package/dist/chunk-QJWVMPB6.js.map +1 -0
- package/dist/{chunk-STM3ORY7.cjs → chunk-QNJLLF4J.cjs} +2 -2
- package/dist/chunk-QNJLLF4J.cjs.map +1 -0
- package/dist/{chunk-FSDJLAOW.js → chunk-QPJXYJIK.js} +55 -1
- package/dist/chunk-QPJXYJIK.js.map +1 -0
- package/dist/{chunk-XTFN5WKS.cjs → chunk-R2BUANHQ.cjs} +6 -6
- package/dist/chunk-R2BUANHQ.cjs.map +1 -0
- package/dist/{chunk-OXLPVQYK.js → chunk-TDQ6XDB3.js} +3 -3
- package/dist/{chunk-SFEQYKYJ.js → chunk-WN6OD2CQ.js} +218 -22
- package/dist/chunk-WN6OD2CQ.js.map +1 -0
- package/dist/{chunk-5KS5PWJR.js → chunk-WY5JAR4O.js} +2 -2
- package/dist/{chunk-CEIATRDW.cjs → chunk-WYON5ANU.cjs} +3 -3
- package/dist/chunk-WYON5ANU.cjs.map +1 -0
- package/dist/{chunk-WDQTFAXY.cjs → chunk-XEPKOC2O.cjs} +240 -44
- package/dist/chunk-XEPKOC2O.cjs.map +1 -0
- package/dist/{chunk-7KNGSQU7.js → chunk-YZ5HHS6A.js} +2 -2
- package/dist/{chunk-P6ZDXTV6.js → chunk-ZF6KHPB7.js} +2 -2
- package/dist/chunks-YBFBLJ4G.js +10 -0
- package/dist/cli.js +36 -54
- package/dist/cli.js.map +1 -1
- package/dist/{formula-NARUOXRX.js → formula-7MMFBRGJ.js} +4 -4
- package/dist/{formula-WIMV5TUX.cjs → formula-ECNOZT36.cjs} +9 -9
- package/dist/formula-ECNOZT36.cjs.map +1 -0
- package/dist/{formula-EPKLPDU7.js → formula-SHBXRXOJ.js} +3 -3
- package/dist/{image-ocr-3WJ4QH3T.js → image-ocr-P6ECJCT2.js} +8 -8
- package/dist/{image-ocr-5BUJQ4TK.js → image-ocr-QCT3A7X5.js} +6 -6
- package/dist/{image-ocr-AXWXR6JV.cjs → image-ocr-VUDSP2B4.cjs} +15 -15
- package/dist/image-ocr-VUDSP2B4.cjs.map +1 -0
- package/dist/index.cjs +768 -710
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +106 -48
- package/dist/index.js.map +1 -1
- package/dist/mcp.js +38 -43
- package/dist/mcp.js.map +1 -1
- package/dist/{model-bundle-IMBW7D2Z.js → model-bundle-OUHGCEZY.js} +5 -5
- package/dist/{models-SY75IBOE.js → models-6D6LMOTH.js} +5 -5
- package/dist/page-range-QHHFTL7X.cjs.map +1 -1
- package/dist/{parser-ZQM3664Z.js → parser-CTRB7PKD.js} +257 -46
- package/dist/parser-CTRB7PKD.js.map +1 -0
- package/dist/{parser-2LU4EVU3.cjs → parser-RQ4PJRTJ.cjs} +411 -200
- package/dist/parser-RQ4PJRTJ.cjs.map +1 -0
- package/dist/{parser-N6476XAC.js → parser-ZPRQ3SSU.js} +260 -49
- package/dist/parser-ZPRQ3SSU.js.map +1 -0
- package/dist/pdf-ocr-462ZFSHX.js +15 -0
- package/dist/pdf-ocr-L35FQYGP.js +18 -0
- package/dist/pdf-ocr-STK5EQFF.cjs +16 -0
- package/dist/pdf-ocr-STK5EQFF.cjs.map +1 -0
- package/dist/{profile-io-GJPKCYPT.js → profile-io-YZUW6MAN.js} +3 -3
- package/dist/{rasterize-UOALJQDS.js → rasterize-OUR2QJXX.js} +3 -3
- package/dist/{redact-doc-22SYW3KH.js → redact-doc-4OQKG4SM.js} +11 -11
- package/dist/{render-MJ4H3R23.js → render-XNO6PZJO.js} +7 -7
- package/dist/seal-CJ7C44JN.js +10 -0
- package/dist/{setup-2URYVUEO.js → setup-UU3EIHNI.js} +3 -3
- package/dist/visual-QRMRFPUK.js +20 -0
- package/dist/{watch-ALXZGTOB.js → watch-SR6Q5SQN.js} +12 -12
- package/package.json +2 -2
- package/dist/chunk-3IB7LBHC.js +0 -57
- package/dist/chunk-3IB7LBHC.js.map +0 -1
- package/dist/chunk-62W7QCEX.cjs +0 -57
- package/dist/chunk-62W7QCEX.cjs.map +0 -1
- package/dist/chunk-CEIATRDW.cjs.map +0 -1
- package/dist/chunk-FKUDAIJI.cjs.map +0 -1
- package/dist/chunk-FSDJLAOW.js.map +0 -1
- package/dist/chunk-IQGIT2VX.js.map +0 -1
- package/dist/chunk-J3IF6KGW.js +0 -59
- package/dist/chunk-J3IF6KGW.js.map +0 -1
- package/dist/chunk-JFLAM3MM.js.map +0 -1
- package/dist/chunk-QOCS7W7R.js.map +0 -1
- package/dist/chunk-SFEQYKYJ.js.map +0 -1
- package/dist/chunk-STM3ORY7.cjs.map +0 -1
- package/dist/chunk-TXUKTOG2.js.map +0 -1
- package/dist/chunk-WDQTFAXY.cjs.map +0 -1
- package/dist/chunk-XTFN5WKS.cjs.map +0 -1
- package/dist/chunks-NUNIKS2J.js +0 -10
- package/dist/formula-WIMV5TUX.cjs.map +0 -1
- package/dist/image-ocr-AXWXR6JV.cjs.map +0 -1
- package/dist/parser-2LU4EVU3.cjs.map +0 -1
- package/dist/parser-N6476XAC.js.map +0 -1
- package/dist/parser-ZQM3664Z.js.map +0 -1
- package/dist/pdf-ocr-6DEE23IP.js +0 -15
- package/dist/pdf-ocr-GHEJVPX2.cjs +0 -16
- package/dist/pdf-ocr-GHEJVPX2.cjs.map +0 -1
- package/dist/pdf-ocr-MQTWODVU.js +0 -18
- package/dist/seal-XWMRUTI4.js +0 -10
- package/dist/visual-USPS4QRC.js +0 -20
- /package/dist/{-4G6MA4X6.js.map → -PRAKO6M4.js.map} +0 -0
- /package/dist/{chunk-AUWGDP4G.js.map → chunk-2KF5WZCR.js.map} +0 -0
- /package/dist/{chunk-UTP2WCHS.js.map → chunk-4GSF2R7T.js.map} +0 -0
- /package/dist/{chunk-4VODJKFL.js.map → chunk-6RGGYQQC.js.map} +0 -0
- /package/dist/{chunk-DES2LGFZ.js.map → chunk-A55JGNKD.js.map} +0 -0
- /package/dist/{chunk-LEIAEWZ7.js.map → chunk-BFT5IM2R.js.map} +0 -0
- /package/dist/{chunk-KIOQ4N37.js.map → chunk-BLPR4HRF.js.map} +0 -0
- /package/dist/{chunk-JELRWAZC.js.map → chunk-BZG7K44Z.js.map} +0 -0
- /package/dist/{chunk-F4NRLLY4.js.map → chunk-EFO6JZY6.js.map} +0 -0
- /package/dist/{chunk-MLIS253L.js.map → chunk-ML4NHUR7.js.map} +0 -0
- /package/dist/{chunk-GO5IFOUF.js.map → chunk-N6V7LQBL.js.map} +0 -0
- /package/dist/{chunk-S2PL227Q.js.map → chunk-PHID6WNG.js.map} +0 -0
- /package/dist/{chunk-OXLPVQYK.js.map → chunk-TDQ6XDB3.js.map} +0 -0
- /package/dist/{chunk-5KS5PWJR.js.map → chunk-WY5JAR4O.js.map} +0 -0
- /package/dist/{chunk-7KNGSQU7.js.map → chunk-YZ5HHS6A.js.map} +0 -0
- /package/dist/{chunk-P6ZDXTV6.js.map → chunk-ZF6KHPB7.js.map} +0 -0
- /package/dist/{chunks-NUNIKS2J.js.map → chunks-YBFBLJ4G.js.map} +0 -0
- /package/dist/{formula-NARUOXRX.js.map → formula-7MMFBRGJ.js.map} +0 -0
- /package/dist/{formula-EPKLPDU7.js.map → formula-SHBXRXOJ.js.map} +0 -0
- /package/dist/{image-ocr-3WJ4QH3T.js.map → image-ocr-P6ECJCT2.js.map} +0 -0
- /package/dist/{image-ocr-5BUJQ4TK.js.map → image-ocr-QCT3A7X5.js.map} +0 -0
- /package/dist/{model-bundle-IMBW7D2Z.js.map → model-bundle-OUHGCEZY.js.map} +0 -0
- /package/dist/{models-SY75IBOE.js.map → models-6D6LMOTH.js.map} +0 -0
- /package/dist/{pdf-ocr-6DEE23IP.js.map → pdf-ocr-462ZFSHX.js.map} +0 -0
- /package/dist/{pdf-ocr-MQTWODVU.js.map → pdf-ocr-L35FQYGP.js.map} +0 -0
- /package/dist/{profile-io-GJPKCYPT.js.map → profile-io-YZUW6MAN.js.map} +0 -0
- /package/dist/{rasterize-UOALJQDS.js.map → rasterize-OUR2QJXX.js.map} +0 -0
- /package/dist/{redact-doc-22SYW3KH.js.map → redact-doc-4OQKG4SM.js.map} +0 -0
- /package/dist/{render-MJ4H3R23.js.map → render-XNO6PZJO.js.map} +0 -0
- /package/dist/{seal-XWMRUTI4.js.map → seal-CJ7C44JN.js.map} +0 -0
- /package/dist/{setup-2URYVUEO.js.map → setup-UU3EIHNI.js.map} +0 -0
- /package/dist/{visual-USPS4QRC.js.map → visual-QRMRFPUK.js.map} +0 -0
- /package/dist/{watch-ALXZGTOB.js.map → watch-SR6Q5SQN.js.map} +0 -0
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
|
+
CELL_EDGES,
|
|
3
4
|
HEADING_RATIO_H1,
|
|
4
5
|
HEADING_RATIO_H2,
|
|
5
6
|
HEADING_RATIO_H3,
|
|
6
7
|
tidyScriptTags
|
|
7
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-5CDUL6PH.js";
|
|
8
9
|
import {
|
|
9
10
|
safeMax,
|
|
10
11
|
safeMin
|
|
11
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-ZF6KHPB7.js";
|
|
12
13
|
|
|
13
14
|
// src/pdf/line-extract.ts
|
|
14
15
|
import { OPS } from "pdfjs-dist/legacy/build/pdf.mjs";
|
|
@@ -30,6 +31,9 @@ function extractLines(fnArray, argsArray) {
|
|
|
30
31
|
const colorStack = [];
|
|
31
32
|
let fillAlpha = 1, strokeAlpha = 1;
|
|
32
33
|
const alphaStack = [];
|
|
34
|
+
let strokeColor = 0;
|
|
35
|
+
const strokeColorStack = [];
|
|
36
|
+
const nonRules = /* @__PURE__ */ new Set();
|
|
33
37
|
const hiddenBoxes = [];
|
|
34
38
|
const paintedFills = /* @__PURE__ */ new Map();
|
|
35
39
|
const thinFill = /* @__PURE__ */ new Set();
|
|
@@ -97,6 +101,7 @@ function extractLines(fnArray, argsArray) {
|
|
|
97
101
|
for (const r of pathRects) painted.push(r);
|
|
98
102
|
paintedFills.set(fillColor, painted);
|
|
99
103
|
}
|
|
104
|
+
const areaFill = fromFill && (pathRects.length > 0 || thickPath(currentPath));
|
|
100
105
|
pathRects = [];
|
|
101
106
|
pathRectSegs = [];
|
|
102
107
|
if (!isStroke) {
|
|
@@ -107,6 +112,9 @@ function extractLines(fnArray, argsArray) {
|
|
|
107
112
|
}
|
|
108
113
|
pendingClip = false;
|
|
109
114
|
const effWidth = lineWidth * ctmScale();
|
|
115
|
+
const outs = [horizontals, verticals, shortH, shortV, thinShortH, thinShortV];
|
|
116
|
+
const white = (fromFill ? fillColor : strokeColor) === 16777215;
|
|
117
|
+
const from = white || areaFill ? outs.map((o) => o.length) : void 0;
|
|
110
118
|
currentPath.forEach((seg, k) => {
|
|
111
119
|
const role = segRole[k];
|
|
112
120
|
if (role === "hidden") return;
|
|
@@ -118,6 +126,9 @@ function extractLines(fnArray, argsArray) {
|
|
|
118
126
|
}
|
|
119
127
|
classifyAndAdd(seg, effWidth, horizontals, verticals, fromFill, fromFill ? void 0 : { h: shortH, v: shortV });
|
|
120
128
|
});
|
|
129
|
+
if (from) outs.forEach((o, k) => {
|
|
130
|
+
for (let n = from[k]; n < o.length; n++) if (white || k < 2 && !thinFill.has(o[n])) nonRules.add(o[n]);
|
|
131
|
+
});
|
|
121
132
|
currentPath = [];
|
|
122
133
|
}
|
|
123
134
|
for (let i = 0; i < fnArray.length; i++) {
|
|
@@ -130,11 +141,13 @@ function extractLines(fnArray, argsArray) {
|
|
|
130
141
|
case OPS.save:
|
|
131
142
|
ctmStack.push(ctm.slice());
|
|
132
143
|
colorStack.push(fillColor);
|
|
144
|
+
strokeColorStack.push(strokeColor);
|
|
133
145
|
alphaStack.push([fillAlpha, strokeAlpha]);
|
|
134
146
|
break;
|
|
135
147
|
case OPS.restore:
|
|
136
148
|
ctm = ctmStack.pop() ?? [1, 0, 0, 1, 0, 0];
|
|
137
149
|
fillColor = colorStack.pop() ?? 0;
|
|
150
|
+
strokeColor = strokeColorStack.pop() ?? 0;
|
|
138
151
|
[fillAlpha, strokeAlpha] = alphaStack.pop() ?? [1, 1];
|
|
139
152
|
break;
|
|
140
153
|
case OPS.setGState: {
|
|
@@ -152,12 +165,18 @@ function extractLines(fnArray, argsArray) {
|
|
|
152
165
|
fillColor = c[0] << 16 | c[1] << 8 | c[2];
|
|
153
166
|
break;
|
|
154
167
|
}
|
|
168
|
+
case OPS.setStrokeRGBColor: {
|
|
169
|
+
const c = args;
|
|
170
|
+
strokeColor = c[0] << 16 | c[1] << 8 | c[2];
|
|
171
|
+
break;
|
|
172
|
+
}
|
|
155
173
|
case OPS.transform:
|
|
156
174
|
case OPS.paintFormXObjectBegin: {
|
|
157
175
|
let t = args;
|
|
158
176
|
if (op === OPS.paintFormXObjectBegin) {
|
|
159
177
|
ctmStack.push(ctm.slice());
|
|
160
178
|
colorStack.push(fillColor);
|
|
179
|
+
strokeColorStack.push(strokeColor);
|
|
161
180
|
alphaStack.push([fillAlpha, strokeAlpha]);
|
|
162
181
|
const m = args[0];
|
|
163
182
|
if (!Array.isArray(m) || m.length < 6) break;
|
|
@@ -176,6 +195,7 @@ function extractLines(fnArray, argsArray) {
|
|
|
176
195
|
case OPS.paintFormXObjectEnd:
|
|
177
196
|
ctm = ctmStack.pop() ?? [1, 0, 0, 1, 0, 0];
|
|
178
197
|
fillColor = colorStack.pop() ?? 0;
|
|
198
|
+
strokeColor = strokeColorStack.pop() ?? 0;
|
|
179
199
|
[fillAlpha, strokeAlpha] = alphaStack.pop() ?? [1, 1];
|
|
180
200
|
break;
|
|
181
201
|
case OPS.constructPath: {
|
|
@@ -287,7 +307,8 @@ function extractLines(fnArray, argsArray) {
|
|
|
287
307
|
fillRects,
|
|
288
308
|
hiddenBoxes,
|
|
289
309
|
shortH,
|
|
290
|
-
shortV
|
|
310
|
+
shortV,
|
|
311
|
+
nonRules
|
|
291
312
|
};
|
|
292
313
|
}
|
|
293
314
|
var SHORT_CHAIN_POS_TOL = 0.5;
|
|
@@ -342,6 +363,17 @@ function chainShortSegments(longs, shorts, dir, chainable = (l) => !l.fromFill)
|
|
|
342
363
|
}
|
|
343
364
|
var CLIP_MIN_W = 4;
|
|
344
365
|
var CLIP_MIN_H = 2;
|
|
366
|
+
function thickPath(path) {
|
|
367
|
+
if (!path.length) return false;
|
|
368
|
+
let x1 = Infinity, y1 = Infinity, x2 = -Infinity, y2 = -Infinity;
|
|
369
|
+
for (const s of path) {
|
|
370
|
+
x1 = Math.min(x1, s.x1, s.x2);
|
|
371
|
+
x2 = Math.max(x2, s.x1, s.x2);
|
|
372
|
+
y1 = Math.min(y1, s.y1, s.y2);
|
|
373
|
+
y2 = Math.max(y2, s.y1, s.y2);
|
|
374
|
+
}
|
|
375
|
+
return Math.min(x2 - x1, y2 - y1) > THIN_FILL_MAX;
|
|
376
|
+
}
|
|
345
377
|
function captureClipRect(path, out, minW = CLIP_MIN_W, minH = CLIP_MIN_H) {
|
|
346
378
|
if (path.length < 3 || path.length > 5) return;
|
|
347
379
|
let x1 = Infinity, y1 = Infinity, x2 = -Infinity, y2 = -Infinity;
|
|
@@ -465,7 +497,7 @@ var CHAIN_GAP = 3;
|
|
|
465
497
|
function chainCollinearRules(horizontals) {
|
|
466
498
|
if (horizontals.length <= 1) return horizontals;
|
|
467
499
|
const sorted = [...horizontals].sort((a, b) => a.y1 - b.y1 || a.x1 - b.x1);
|
|
468
|
-
const
|
|
500
|
+
const rules2 = [];
|
|
469
501
|
let bandStart = 0;
|
|
470
502
|
const flushBand = (end) => {
|
|
471
503
|
const band = sorted.slice(bandStart, end).sort((a, b) => a.x1 - b.x1);
|
|
@@ -476,11 +508,11 @@ function chainCollinearRules(horizontals) {
|
|
|
476
508
|
if (seg.x2 > cur.x2) cur.x2 = seg.x2;
|
|
477
509
|
if (seg.lineWidth > cur.lineWidth) cur.lineWidth = seg.lineWidth;
|
|
478
510
|
} else {
|
|
479
|
-
|
|
511
|
+
rules2.push(cur);
|
|
480
512
|
cur = { ...seg };
|
|
481
513
|
}
|
|
482
514
|
}
|
|
483
|
-
|
|
515
|
+
rules2.push(cur);
|
|
484
516
|
};
|
|
485
517
|
for (let i = 1; i <= sorted.length; i++) {
|
|
486
518
|
if (i === sorted.length || sorted[i].y1 - sorted[bandStart].y1 > CHAIN_Y_TOL) {
|
|
@@ -488,7 +520,7 @@ function chainCollinearRules(horizontals) {
|
|
|
488
520
|
bandStart = i;
|
|
489
521
|
}
|
|
490
522
|
}
|
|
491
|
-
return
|
|
523
|
+
return rules2;
|
|
492
524
|
}
|
|
493
525
|
function closeOpenTableEdges(horizontals, verticals) {
|
|
494
526
|
if (horizontals.length < EDGE_MIN_RULES) return verticals;
|
|
@@ -754,7 +786,7 @@ function bridgeSkippedRowVerticals(horizontals, verticals, items) {
|
|
|
754
786
|
if (hi - lo > BRIDGE_MIN_GAP && hi - lo <= 40) gaps.push({ x, lo, hi, spanLo: s[i - 1].y1, spanHi: s[i].y2 });
|
|
755
787
|
}
|
|
756
788
|
}
|
|
757
|
-
const
|
|
789
|
+
const rules2 = chainCollinearRules(horizontals);
|
|
758
790
|
const added = [];
|
|
759
791
|
const done = /* @__PURE__ */ new Set();
|
|
760
792
|
for (const g of gaps) {
|
|
@@ -764,7 +796,7 @@ function bridgeSkippedRowVerticals(horizontals, verticals, items) {
|
|
|
764
796
|
if (band.length < BRIDGE_MIN_COLUMNS) continue;
|
|
765
797
|
const xs = band.map((o) => o.x);
|
|
766
798
|
const x1 = Math.min(...xs), x2 = Math.max(...xs);
|
|
767
|
-
const ruled = (y) =>
|
|
799
|
+
const ruled = (y) => rules2.some((h) => Math.abs(h.y1 - y) <= BRIDGE_ENDPOINT_TOL && h.x1 <= x1 + BRIDGE_ENDPOINT_TOL && h.x2 >= x2 - BRIDGE_ENDPOINT_TOL);
|
|
768
800
|
if (!ruled(g.lo) || !ruled(g.hi)) continue;
|
|
769
801
|
const rowItems = items.filter((it) => {
|
|
770
802
|
const cy = it.y + (it.h || it.fontSize) / 2;
|
|
@@ -1093,7 +1125,7 @@ function clusterCoordinates(values, tolerance) {
|
|
|
1093
1125
|
function chainVerticals(vs) {
|
|
1094
1126
|
if (vs.length <= 1) return vs.map((v) => ({ y1: v.y1, y2: v.y2 }));
|
|
1095
1127
|
const sorted = [...vs].sort((a, b) => a.x1 - b.x1 || a.y1 - b.y1);
|
|
1096
|
-
const
|
|
1128
|
+
const rules2 = [];
|
|
1097
1129
|
let bandStart = 0;
|
|
1098
1130
|
const flushBand = (end) => {
|
|
1099
1131
|
const band = sorted.slice(bandStart, end).sort((a, b) => a.y1 - b.y1);
|
|
@@ -1103,11 +1135,11 @@ function chainVerticals(vs) {
|
|
|
1103
1135
|
if (seg.y1 - cur.y2 <= CUT_VCHAIN_GAP) {
|
|
1104
1136
|
if (seg.y2 > cur.y2) cur.y2 = seg.y2;
|
|
1105
1137
|
} else {
|
|
1106
|
-
|
|
1138
|
+
rules2.push(cur);
|
|
1107
1139
|
cur = { y1: seg.y1, y2: seg.y2 };
|
|
1108
1140
|
}
|
|
1109
1141
|
}
|
|
1110
|
-
|
|
1142
|
+
rules2.push(cur);
|
|
1111
1143
|
};
|
|
1112
1144
|
for (let i = 1; i <= sorted.length; i++) {
|
|
1113
1145
|
if (i === sorted.length || sorted[i].x1 - sorted[bandStart].x1 > CUT_VCHAIN_X_TOL) {
|
|
@@ -1115,7 +1147,7 @@ function chainVerticals(vs) {
|
|
|
1115
1147
|
bandStart = i;
|
|
1116
1148
|
}
|
|
1117
1149
|
}
|
|
1118
|
-
return
|
|
1150
|
+
return rules2;
|
|
1119
1151
|
}
|
|
1120
1152
|
function splitStackedGroup(group) {
|
|
1121
1153
|
const hs = group.filter((l) => l.type === "h");
|
|
@@ -1465,11 +1497,42 @@ function buildClipCellGrids(rects, strokedH, strokedV, pageWidth, pageHeight, te
|
|
|
1465
1497
|
}
|
|
1466
1498
|
}
|
|
1467
1499
|
}
|
|
1500
|
+
const stacked = /* @__PURE__ */ new Set();
|
|
1501
|
+
if (ruledGaps.some((g) => g.axis === "y" && g.both && g.hi - g.lo > STACKED_TABLE_GAP)) {
|
|
1502
|
+
for (let i = 0; i < cells.length; i++) {
|
|
1503
|
+
if (tableClip[i]) continue;
|
|
1504
|
+
const k = edgeBin(cells[i].y2);
|
|
1505
|
+
for (let d = -1; d <= 1; d++) {
|
|
1506
|
+
if ((startsY.get(k + d) ?? []).some((j) => j !== i && !tableClip[j] && parent[j] === parent[i] && adjacent(cells[i], cells[j]))) stacked.add(find(i));
|
|
1507
|
+
}
|
|
1508
|
+
}
|
|
1509
|
+
}
|
|
1510
|
+
const comp = cells.map((_, i) => find(i));
|
|
1468
1511
|
for (const g of ruledGaps) {
|
|
1469
1512
|
if (tableClip[g.i] || tableClip[g.j]) continue;
|
|
1513
|
+
if (g.axis === "y" && g.both && g.hi - g.lo > STACKED_TABLE_GAP && comp[g.i] !== comp[g.j] && stacked.has(comp[g.i]) && stacked.has(comp[g.j])) continue;
|
|
1470
1514
|
const ra = find(g.i), rb = find(g.j);
|
|
1471
1515
|
if (ra !== rb) root[ra] = rb;
|
|
1472
1516
|
}
|
|
1517
|
+
if (prev.lastCells.length) {
|
|
1518
|
+
const headTop = pageHeight * (1 - HEADER_BAND);
|
|
1519
|
+
let top = -Infinity;
|
|
1520
|
+
for (let i = 0; i < cells.length; i++) if (parent[i] < 0 && !tableClip[i]) top = Math.max(top, cells[i].y2);
|
|
1521
|
+
const band = cells.flatMap((c, i) => parent[i] < 0 && !tableClip[i] && Math.abs(c.y2 - top) <= CLIP_COORD_TOL ? [i] : []);
|
|
1522
|
+
const y1 = band.length ? cells[band[0]].y1 : 0;
|
|
1523
|
+
if (band.length >= 2 && band.every((i) => Math.abs(cells[i].y1 - y1) <= CLIP_COORD_TOL) && !textPoints.some((p) => p.y > top + CLIP_EDGE_TOL && p.y < headTop)) {
|
|
1524
|
+
for (let f = 0; f < cells.length; f++) {
|
|
1525
|
+
const b = cells[f];
|
|
1526
|
+
if (parent[f] >= 0 || tableClip[f] || Math.abs(b.y2 - y1) > CLIP_ADJ_GAP) continue;
|
|
1527
|
+
const on = band.filter((i) => cells[i].x1 >= b.x1 - CLIP_COORD_TOL && cells[i].x2 <= b.x2 + CLIP_COORD_TOL);
|
|
1528
|
+
if (on.length < 2 || !on.some((i) => adjacent(cells[i], b))) continue;
|
|
1529
|
+
for (const i of on) {
|
|
1530
|
+
const ra = find(i), rb = find(f);
|
|
1531
|
+
if (ra !== rb) root[ra] = rb;
|
|
1532
|
+
}
|
|
1533
|
+
}
|
|
1534
|
+
}
|
|
1535
|
+
}
|
|
1473
1536
|
const groups = /* @__PURE__ */ new Map();
|
|
1474
1537
|
for (let i = 0; i < cells.length; i++) {
|
|
1475
1538
|
const r = find(i);
|
|
@@ -1529,6 +1592,8 @@ function buildClipCellGrids(rects, strokedH, strokedV, pageWidth, pageHeight, te
|
|
|
1529
1592
|
if (invisible / edges < CLIP_MIN_INVISIBLE) continue;
|
|
1530
1593
|
const colXs = dropSliverGaps(clusterCoords(members.flatMap((r) => [r.x1, r.x2])));
|
|
1531
1594
|
const rowYs = clusterCoords(members.flatMap((r) => [r.y1, r.y2])).reverse();
|
|
1595
|
+
const band = parentRect ? void 0 : carriedBandTop(colXs, rowYs[0], strokedH, strokedV, textPoints, cells, prev.lastCells, headY);
|
|
1596
|
+
if (band !== void 0) rowYs.unshift(band);
|
|
1532
1597
|
const numRows = rowYs.length - 1, numCols = colXs.length - 1;
|
|
1533
1598
|
if (numRows < 1 || numCols < 1) continue;
|
|
1534
1599
|
const occupied = Array.from({ length: numRows }, () => new Array(numCols).fill(false));
|
|
@@ -1575,6 +1640,7 @@ function buildClipCellGrids(rects, strokedH, strokedV, pageWidth, pageHeight, te
|
|
|
1575
1640
|
return { grids, containers, page: { lastCells, clips: cells } };
|
|
1576
1641
|
}
|
|
1577
1642
|
var CLIP_SPACING_MAX = 3;
|
|
1643
|
+
var STACKED_TABLE_GAP = 2.6;
|
|
1578
1644
|
function findRuledGaps(cells, parent, strokedH, strokedV) {
|
|
1579
1645
|
const al = (u, v) => Math.abs(u - v) <= CLIP_COORD_TOL;
|
|
1580
1646
|
const occupied = (i, j, x1, y1, x2, y2) => cells.some((k, n) => n !== i && n !== j && parent[n] === parent[i] && overlap(k.x1, k.x2, x1, x2) > CLIP_ADJ_GAP && overlap(k.y1, k.y2, y1, y2) > CLIP_ADJ_GAP);
|
|
@@ -1704,6 +1770,20 @@ function closeGaps(members, gaps) {
|
|
|
1704
1770
|
}
|
|
1705
1771
|
return out;
|
|
1706
1772
|
}
|
|
1773
|
+
function carriedBandTop(colXs, top, strokedH, strokedV, textPoints, cells, prevLast, headY) {
|
|
1774
|
+
const x1 = colXs[0], x2 = colXs[colXs.length - 1];
|
|
1775
|
+
if (!prevLast.some((b) => overlap(b.x1, b.x2, x1, x2) > CLIP_EDGE_TOL)) return void 0;
|
|
1776
|
+
let y;
|
|
1777
|
+
for (const l of strokedH) {
|
|
1778
|
+
if (l.y1 > top + CLIP_MIN_H2 && l.x1 <= x1 + STROKE_NEAR && l.x2 >= x2 - STROKE_NEAR && (y === void 0 || l.y1 < y)) y = l.y1;
|
|
1779
|
+
}
|
|
1780
|
+
if (y === void 0 || !edgeStroked(strokedV, "v", x1, top, y) || !edgeStroked(strokedV, "v", x2, top, y)) return void 0;
|
|
1781
|
+
const above = Math.max(y, headY);
|
|
1782
|
+
const inX = (x) => x > x1 && x < x2;
|
|
1783
|
+
if (textPoints.some((p) => inX(p.x) && p.y > top && p.y < above)) return void 0;
|
|
1784
|
+
if (cells.some((c) => overlap(c.x1, c.x2, x1, x2) > CLIP_EDGE_TOL && c.y1 >= top - CLIP_EDGE_TOL && c.y1 < above)) return void 0;
|
|
1785
|
+
return y;
|
|
1786
|
+
}
|
|
1707
1787
|
function addNarrowEdgeCols(colXs, rowYs, out, fills) {
|
|
1708
1788
|
if (!fills.length) return;
|
|
1709
1789
|
const rowIdx = (y) => {
|
|
@@ -3688,6 +3768,9 @@ function removeHeaderFooterBlocks(blocks, pageHeights, warnings, notes, tables =
|
|
|
3688
3768
|
// src/pdf/table-meta.ts
|
|
3689
3769
|
var CLIP_TABLES = /* @__PURE__ */ new WeakSet();
|
|
3690
3770
|
var TABLE_COLXS = /* @__PURE__ */ new WeakMap();
|
|
3771
|
+
var TABLE_ROWYS = /* @__PURE__ */ new WeakMap();
|
|
3772
|
+
var TABLE_TAIL = /* @__PURE__ */ new WeakMap();
|
|
3773
|
+
var PART_COLXS = /* @__PURE__ */ new WeakMap();
|
|
3691
3774
|
var EMPTY_PARTS = /* @__PURE__ */ new WeakSet();
|
|
3692
3775
|
var IMAGE_CELLS = /* @__PURE__ */ new WeakSet();
|
|
3693
3776
|
var FILLER_CELLS = /* @__PURE__ */ new WeakSet();
|
|
@@ -3706,6 +3789,34 @@ function recordCellLines(cell, items) {
|
|
|
3706
3789
|
}
|
|
3707
3790
|
CELL_LINES.set(cell, lines);
|
|
3708
3791
|
}
|
|
3792
|
+
var ROW_RULES = /* @__PURE__ */ new WeakMap();
|
|
3793
|
+
function ruleCover(hs, y, x1, x2) {
|
|
3794
|
+
const segs = hs.filter((l) => Math.abs(l.y1 - y) <= 1.5 && l.x2 > x1 && l.x1 < x2).map((l) => [Math.max(l.x1, x1), Math.min(l.x2, x2)]).sort((a, b) => a[0] - b[0]);
|
|
3795
|
+
let len = 0, end = x1;
|
|
3796
|
+
for (const [a, b] of segs) if (b > end) {
|
|
3797
|
+
len += b - Math.max(a, end);
|
|
3798
|
+
end = b;
|
|
3799
|
+
}
|
|
3800
|
+
return x2 > x1 ? len / (x2 - x1) : 0;
|
|
3801
|
+
}
|
|
3802
|
+
function recordRowRules(table, cells, bbox, hs) {
|
|
3803
|
+
const real = cells.filter((c) => !c.filler);
|
|
3804
|
+
const edge = (y, pick) => {
|
|
3805
|
+
let w = 0, covered = 0;
|
|
3806
|
+
for (const c of real) if (Math.abs(pick(c) - y) <= 1) {
|
|
3807
|
+
w += c.bbox.x2 - c.bbox.x1;
|
|
3808
|
+
covered += ruleCover(hs, y, c.bbox.x1, c.bbox.x2) * (c.bbox.x2 - c.bbox.x1);
|
|
3809
|
+
}
|
|
3810
|
+
return w > 0 && covered >= 0.9 * w;
|
|
3811
|
+
};
|
|
3812
|
+
let innerRuled = 0, innerOpen = 0;
|
|
3813
|
+
for (const c of real) {
|
|
3814
|
+
if (Math.abs(c.bbox.y1 - bbox.y1) <= 1) continue;
|
|
3815
|
+
if (ruleCover(hs, c.bbox.y1, c.bbox.x1 + 0.5, c.bbox.x2 - 0.5) >= 0.9) innerRuled++;
|
|
3816
|
+
else innerOpen++;
|
|
3817
|
+
}
|
|
3818
|
+
ROW_RULES.set(table, { top: edge(bbox.y2, (c) => c.bbox.y2), bottom: edge(bbox.y1, (c) => c.bbox.y1), innerRuled, innerOpen });
|
|
3819
|
+
}
|
|
3709
3820
|
|
|
3710
3821
|
// src/pdf/table-trim.ts
|
|
3711
3822
|
function markImageCell(cell) {
|
|
@@ -5516,6 +5627,76 @@ function headerLineAbove(free, colXs, top) {
|
|
|
5516
5627
|
return cols;
|
|
5517
5628
|
}
|
|
5518
5629
|
|
|
5630
|
+
// src/pdf/cell-edges.ts
|
|
5631
|
+
var CLIP_CELL_EDGES = /* @__PURE__ */ new WeakMap();
|
|
5632
|
+
var NO_EDGES = Object.freeze({ t: false, b: false, l: false, r: false });
|
|
5633
|
+
var EDGE_NEAR2 = 1.6;
|
|
5634
|
+
var EDGE_COVER = 0.6;
|
|
5635
|
+
var EDGE_SLACK = 3;
|
|
5636
|
+
var DASH_GAP = 3;
|
|
5637
|
+
var TIP_MAX = 1.5;
|
|
5638
|
+
function rules(lines, dir) {
|
|
5639
|
+
const sorted = [...lines].sort((a, b) => dir === "h" ? a.y1 - b.y1 : a.x1 - b.x1);
|
|
5640
|
+
return { dir, pos: sorted.map((l) => dir === "h" ? l.y1 : l.x1), lines: sorted };
|
|
5641
|
+
}
|
|
5642
|
+
function seen(r, at, a1, a2) {
|
|
5643
|
+
const len = a2 - a1;
|
|
5644
|
+
if (len <= 0) return false;
|
|
5645
|
+
const covered = coverage(r, at, a1, a2);
|
|
5646
|
+
return covered >= len * EDGE_COVER && len - covered <= EDGE_SLACK;
|
|
5647
|
+
}
|
|
5648
|
+
function coverage(r, at, a1, a2) {
|
|
5649
|
+
let i = 0, j = r.pos.length;
|
|
5650
|
+
while (i < j) {
|
|
5651
|
+
const m = i + j >> 1;
|
|
5652
|
+
if (r.pos[m] < at - EDGE_NEAR2) i = m + 1;
|
|
5653
|
+
else j = m;
|
|
5654
|
+
}
|
|
5655
|
+
const spans = [];
|
|
5656
|
+
for (; i < r.pos.length && r.pos[i] <= at + EDGE_NEAR2; i++) {
|
|
5657
|
+
const l = r.lines[i];
|
|
5658
|
+
const l1 = r.dir === "h" ? Math.min(l.x1, l.x2) : Math.min(l.y1, l.y2), l2 = r.dir === "h" ? Math.max(l.x1, l.x2) : Math.max(l.y1, l.y2);
|
|
5659
|
+
const lo = Math.max(a1, l1), hi = Math.min(a2, l2);
|
|
5660
|
+
if (hi <= lo || l1 < a1 !== l2 > a2 && hi - lo < TIP_MAX) continue;
|
|
5661
|
+
spans.push([lo, hi]);
|
|
5662
|
+
}
|
|
5663
|
+
if (!spans.length) return 0;
|
|
5664
|
+
spans.sort((p, q) => p[0] - q[0]);
|
|
5665
|
+
let covered = 0, s = spans[0][0], e = spans[0][1];
|
|
5666
|
+
for (const [lo, hi] of spans.slice(1)) {
|
|
5667
|
+
if (lo <= e + DASH_GAP) e = Math.max(e, hi);
|
|
5668
|
+
else {
|
|
5669
|
+
covered += e - s;
|
|
5670
|
+
s = lo;
|
|
5671
|
+
e = hi;
|
|
5672
|
+
}
|
|
5673
|
+
}
|
|
5674
|
+
return covered + e - s;
|
|
5675
|
+
}
|
|
5676
|
+
function edgesOf(box, h, v) {
|
|
5677
|
+
return {
|
|
5678
|
+
t: seen(h, box.y2, box.x1, box.x2),
|
|
5679
|
+
b: seen(h, box.y1, box.x1, box.x2),
|
|
5680
|
+
l: seen(v, box.x1, box.y1, box.y2),
|
|
5681
|
+
r: seen(v, box.x2, box.y1, box.y2)
|
|
5682
|
+
};
|
|
5683
|
+
}
|
|
5684
|
+
function recordClipCellEdges(grids, horizontals, verticals, nonRules) {
|
|
5685
|
+
if (!grids.some((g) => g.cells)) return;
|
|
5686
|
+
const h = rules(nonRules?.size ? horizontals.filter((l) => !nonRules.has(l)) : horizontals, "h");
|
|
5687
|
+
const v = rules(nonRules?.size ? verticals.filter((l) => !nonRules.has(l)) : verticals, "v");
|
|
5688
|
+
for (const g of grids) for (const c of g.cells ?? []) CLIP_CELL_EDGES.set(c, edgesOf(c.bbox, h, v));
|
|
5689
|
+
}
|
|
5690
|
+
function takeClipCellEdges(from, to) {
|
|
5691
|
+
const e = CLIP_CELL_EDGES.get(from);
|
|
5692
|
+
if (e) CELL_EDGES.set(to, e);
|
|
5693
|
+
}
|
|
5694
|
+
function joinCellEdges(a, b) {
|
|
5695
|
+
const u = CELL_EDGES.get(a), d = CELL_EDGES.get(b);
|
|
5696
|
+
if (!u || !d) return;
|
|
5697
|
+
CELL_EDGES.set(a, { t: u.t, b: d.b, l: u.l || d.l, r: u.r || d.r });
|
|
5698
|
+
}
|
|
5699
|
+
|
|
5519
5700
|
// src/pdf/page-frame.ts
|
|
5520
5701
|
function isPageFrameGrid(grid, cells, pageWidth, pageHeight, items = []) {
|
|
5521
5702
|
const b = grid.bbox;
|
|
@@ -5770,8 +5951,8 @@ function detectRuledBandTables(horizontals, verticals, items, pageNum) {
|
|
|
5770
5951
|
};
|
|
5771
5952
|
for (const g of groups) {
|
|
5772
5953
|
if (g.length < 2) continue;
|
|
5773
|
-
const
|
|
5774
|
-
const x1 = Math.min(...
|
|
5954
|
+
const rules2 = [...g].sort((a, b) => b.y1 - a.y1);
|
|
5955
|
+
const x1 = Math.min(...rules2.map((r) => r.x1)), x2 = Math.max(...rules2.map((r) => r.x2));
|
|
5775
5956
|
let run = [];
|
|
5776
5957
|
const flush = () => {
|
|
5777
5958
|
if (run.length >= 2) emit(run, x1, x2);
|
|
@@ -5785,8 +5966,8 @@ function detectRuledBandTables(horizontals, verticals, items, pageNum) {
|
|
|
5785
5966
|
run = [];
|
|
5786
5967
|
};
|
|
5787
5968
|
let title = null;
|
|
5788
|
-
for (let i = 0; i + 1 <
|
|
5789
|
-
const top =
|
|
5969
|
+
for (let i = 0; i + 1 < rules2.length; i++) {
|
|
5970
|
+
const top = rules2[i].y1, bottom = rules2[i + 1].y1;
|
|
5790
5971
|
const band = lines.filter((l) => l[0].y < top && l[0].y > bottom);
|
|
5791
5972
|
const inside = !band.some((l) => l.some((it) => it.x < x1 - EDGE_TOL3 || it.x + it.w > x2 + EDGE_TOL3));
|
|
5792
5973
|
const fs = median(band.flat().map((it) => it.fontSize).filter((s) => s > 0)) || 10;
|
|
@@ -6204,6 +6385,7 @@ function extractPageBlocksWithLines(items, pageNum, opList, pageWidth, pageHeigh
|
|
|
6204
6385
|
for (const line of streamLines(items)) lex.addLine(mergeLineSimple(line));
|
|
6205
6386
|
const extracted = extractLines(opList.fnArray, opList.argsArray);
|
|
6206
6387
|
let { horizontals, verticals } = extracted;
|
|
6388
|
+
const rawRules = extracted.horizontals.concat(extracted.shortH);
|
|
6207
6389
|
const filled = fillBlanks(items, horizontals, verticals);
|
|
6208
6390
|
items = filled.items;
|
|
6209
6391
|
horizontals = filled.horizontals;
|
|
@@ -6214,6 +6396,7 @@ function extractPageBlocksWithLines(items, pageNum, opList, pageWidth, pageHeigh
|
|
|
6214
6396
|
carry.clip = clipResult.page;
|
|
6215
6397
|
}
|
|
6216
6398
|
const clipGrids = clipResult.grids;
|
|
6399
|
+
recordClipCellEdges(clipGrids, horizontals.concat(extracted.shortH), verticals.concat(extracted.shortV), extracted.nonRules);
|
|
6217
6400
|
if (clipGrids.length === 0) {
|
|
6218
6401
|
horizontals = chainShortSegments(horizontals, extracted.shortH, "h");
|
|
6219
6402
|
verticals = chainShortSegments(verticals, extracted.shortV, "v");
|
|
@@ -6245,7 +6428,7 @@ function extractPageBlocksWithLines(items, pageNum, opList, pageWidth, pageHeigh
|
|
|
6245
6428
|
if (detectTables && clipGrids.length === 0 && ruled.length === 0 && lineGrids.length === 0) ruled.push(...detectTextBoxTables(extracted.hiddenBoxes, items, pageNum));
|
|
6246
6429
|
if (ruled.length > 0) {
|
|
6247
6430
|
const imageRegions = extractImageRegions(opList.fnArray, opList.argsArray).filter((r) => r.x2 - r.x1 >= 8 && r.y2 - r.y1 >= 8);
|
|
6248
|
-
return extractBlocksWithGrids(items, pageNum, pageWidth, pageHeight, grids, horizontals, verticals, imageRegions, lex, ruled);
|
|
6431
|
+
return extractBlocksWithGrids(items, pageNum, pageWidth, pageHeight, grids, horizontals, verticals, imageRegions, lex, ruled, rawRules);
|
|
6249
6432
|
}
|
|
6250
6433
|
if (detectTables && stackedTableBands(items)) {
|
|
6251
6434
|
return extractPageBlocksFallback(items, pageNum, true, detectTables, lex);
|
|
@@ -6256,7 +6439,7 @@ function extractPageBlocksWithLines(items, pageNum, opList, pageWidth, pageHeigh
|
|
|
6256
6439
|
}
|
|
6257
6440
|
if (grids.length > 0) {
|
|
6258
6441
|
const imageRegions = extractImageRegions(opList.fnArray, opList.argsArray).filter((r) => r.x2 - r.x1 >= 8 && r.y2 - r.y1 >= 8);
|
|
6259
|
-
return extractBlocksWithGrids(items, pageNum, pageWidth, pageHeight, grids, horizontals, verticals, imageRegions, lex);
|
|
6442
|
+
return extractBlocksWithGrids(items, pageNum, pageWidth, pageHeight, grids, horizontals, verticals, imageRegions, lex, [], rawRules);
|
|
6260
6443
|
}
|
|
6261
6444
|
const figures = extractImageRegions(opList.fnArray, opList.argsArray).filter((r) => r.x2 - r.x1 >= 40 && r.y2 - r.y1 >= 40).map((r) => ({ x: r.x1, y: r.y1, w: r.x2 - r.x1, h: r.y2 - r.y1 }));
|
|
6262
6445
|
return extractPageBlocksFallback(items, pageNum, true, detectTables, lex, figures);
|
|
@@ -6399,7 +6582,7 @@ function buildFrameCellBlocks(cellItems, nested, pageNum, wrap) {
|
|
|
6399
6582
|
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");
|
|
6400
6583
|
return { blocks, text };
|
|
6401
6584
|
}
|
|
6402
|
-
function extractBlocksWithGrids(items, pageNum, pageWidth, pageHeight, grids, horizontals, verticals, imageRegions = [], lex, ruled = []) {
|
|
6585
|
+
function extractBlocksWithGrids(items, pageNum, pageWidth, pageHeight, grids, horizontals, verticals, imageRegions = [], lex, ruled = [], rawRules = horizontals) {
|
|
6403
6586
|
const ocrPage = items.length > 0 && items.every((i) => i.fontName === "ocr");
|
|
6404
6587
|
const blocks = [];
|
|
6405
6588
|
const usedItems = /* @__PURE__ */ new Set();
|
|
@@ -6461,6 +6644,7 @@ function extractBlocksWithGrids(items, pageNum, pageWidth, pageHeight, grids, ho
|
|
|
6461
6644
|
const built = buildFrameCellBlocks(cellItems, nested, pageNum, { box: cell.bbox, lex });
|
|
6462
6645
|
irGrid[cell.row][cell.col] = { text: built.text, colSpan: cell.colSpan, rowSpan: cell.rowSpan, blocks: built.blocks };
|
|
6463
6646
|
if (cellItems.length) recordCellLines(irGrid[cell.row][cell.col], cellItems);
|
|
6647
|
+
takeClipCellEdges(cell, irGrid[cell.row][cell.col]);
|
|
6464
6648
|
continue;
|
|
6465
6649
|
}
|
|
6466
6650
|
irGrid[cell.row][cell.col] = {
|
|
@@ -6478,6 +6662,7 @@ function extractBlocksWithGrids(items, pageNum, pageWidth, pageHeight, grids, ho
|
|
|
6478
6662
|
}
|
|
6479
6663
|
if (cell.filler && !cellItems.length) FILLER_CELLS.add(irGrid[cell.row][cell.col]);
|
|
6480
6664
|
if (grid.cells && cellItems.length) recordCellLines(irGrid[cell.row][cell.col], cellItems);
|
|
6665
|
+
takeClipCellEdges(cell, irGrid[cell.row][cell.col]);
|
|
6481
6666
|
}
|
|
6482
6667
|
let finalGrid = irGrid;
|
|
6483
6668
|
let finalRows = numRows;
|
|
@@ -6521,6 +6706,7 @@ function extractBlocksWithGrids(items, pageNum, pageWidth, pageHeight, grids, ho
|
|
|
6521
6706
|
const inset = line.length ? grid.bbox.x2 - (line[line.length - 1].x + line[line.length - 1].w) : 0;
|
|
6522
6707
|
if (line.length && /^\s*\(\s*단위\s*[::]/.test(text) && inset >= 4.6 && inset <= 5.6) {
|
|
6523
6708
|
finalGrid.unshift(Array.from({ length: numCols }, (_, c) => ({ text: c === 0 ? cleanCellText(text) : "", colSpan: c === 0 ? numCols : 1, rowSpan: 1 })));
|
|
6709
|
+
if (grid.cells) for (const u of finalGrid[0]) CELL_EDGES.set(u, NO_EDGES);
|
|
6524
6710
|
finalRows++;
|
|
6525
6711
|
for (const item of line) usedItems.add(item);
|
|
6526
6712
|
}
|
|
@@ -6574,8 +6760,12 @@ function extractBlocksWithGrids(items, pageNum, pageWidth, pageHeight, grids, ho
|
|
|
6574
6760
|
hasHeader: finalRows > 1,
|
|
6575
6761
|
...semanticOneColumn ? { renderAsTable: true } : {}
|
|
6576
6762
|
};
|
|
6577
|
-
if (grid.cells)
|
|
6763
|
+
if (grid.cells) {
|
|
6764
|
+
CLIP_TABLES.add(irTable);
|
|
6765
|
+
recordRowRules(irTable, grid.cells, grid.bbox, rawRules);
|
|
6766
|
+
}
|
|
6578
6767
|
TABLE_COLXS.set(irTable, grid.colXs);
|
|
6768
|
+
if (grid.cells && finalRows === numRows) TABLE_ROWYS.set(irTable, grid.rowYs);
|
|
6579
6769
|
if (grid.continues) CONT_PARTS.set(irTable, grid.continues);
|
|
6580
6770
|
const hasContent = finalGrid.some((row) => row.some((cell) => cell.text.trim() !== ""));
|
|
6581
6771
|
const emptyPart = !hasContent && !!grid.cells && !grid.clipParent && !nestedAttached;
|
|
@@ -7071,12 +7261,18 @@ export {
|
|
|
7071
7261
|
removeHeaderFooterBlocks,
|
|
7072
7262
|
CLIP_TABLES,
|
|
7073
7263
|
TABLE_COLXS,
|
|
7264
|
+
TABLE_ROWYS,
|
|
7265
|
+
TABLE_TAIL,
|
|
7266
|
+
PART_COLXS,
|
|
7074
7267
|
EMPTY_PARTS,
|
|
7075
7268
|
IMAGE_CELLS,
|
|
7076
7269
|
FILLER_CELLS,
|
|
7077
7270
|
CONT_PARTS,
|
|
7078
7271
|
CELL_LINES,
|
|
7272
|
+
ROW_RULES,
|
|
7079
7273
|
trimTrailingEmptyTableCols,
|
|
7274
|
+
NO_EDGES,
|
|
7275
|
+
joinCellEdges,
|
|
7080
7276
|
extractPageBlocksWithLines
|
|
7081
7277
|
};
|
|
7082
|
-
//# sourceMappingURL=chunk-
|
|
7278
|
+
//# sourceMappingURL=chunk-WN6OD2CQ.js.map
|