kordoc 4.5.0 → 4.6.1
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 +11 -0
- package/dist/{-CWYIC4ES.js → -6XJ6MCQG.js} +9 -9
- package/dist/{chunk-ZHNUH2IW.js → chunk-3VTMSSDW.js} +2 -2
- package/dist/{chunk-TCPO6XAY.cjs → chunk-AC3K3FZJ.cjs} +8 -8
- package/dist/chunk-AC3K3FZJ.cjs.map +1 -0
- package/dist/{chunk-TP4P7M4I.js → chunk-AFPD74JJ.js} +2 -2
- package/dist/{chunk-NBOVSNSR.js → chunk-B2OQOTRT.js} +224 -30
- package/dist/chunk-B2OQOTRT.js.map +1 -0
- package/dist/{chunk-XYSTZIIL.js → chunk-BCG2PKQU.js} +2 -2
- package/dist/{chunk-2CF2WXBG.js → chunk-BGSGUONP.js} +225 -31
- package/dist/chunk-BGSGUONP.js.map +1 -0
- package/dist/chunk-DCZVOIEO.cjs.map +1 -1
- package/dist/{chunk-FT2EXMMP.js → chunk-EACTUWYE.js} +8 -8
- package/dist/{chunk-FT2EXMMP.js.map → chunk-EACTUWYE.js.map} +1 -1
- package/dist/chunk-GS7T56RP.cjs.map +1 -1
- package/dist/{chunk-CBUC73JM.js → chunk-IDHBO6AG.js} +3 -3
- package/dist/{chunk-UEWW3DH2.js → chunk-MVTX6ODZ.js} +1 -1
- package/dist/chunk-MVTX6ODZ.js.map +1 -0
- package/dist/{chunk-WDIPTY3Q.js → chunk-PV2EXXGI.js} +3 -3
- package/dist/{chunk-U3ZNF4SO.cjs → chunk-SHYF2BB2.cjs} +231 -37
- package/dist/chunk-SHYF2BB2.cjs.map +1 -0
- package/dist/{chunk-UQ6KDJWE.cjs → chunk-TUU535RB.cjs} +4 -3
- package/dist/chunk-TUU535RB.cjs.map +1 -0
- package/dist/{chunk-M4I5F6GK.js → chunk-VCA4SZ2D.js} +8 -8
- package/dist/{chunk-M4I5F6GK.js.map → chunk-VCA4SZ2D.js.map} +1 -1
- package/dist/{chunk-45EUJ2P6.js → chunk-VO24F4BJ.js} +33 -17
- package/dist/{chunk-45EUJ2P6.js.map → chunk-VO24F4BJ.js.map} +1 -1
- package/dist/{chunk-GLPLLT4Q.cjs → chunk-W5KRKBYR.cjs} +4 -4
- package/dist/chunk-W5KRKBYR.cjs.map +1 -0
- package/dist/{chunk-7ZQKECQT.js → chunk-XZDJXYUC.js} +2 -2
- package/dist/{chunk-EYLOFSA5.js → chunk-YUVKU5CW.js} +4 -3
- package/dist/chunk-YUVKU5CW.js.map +1 -0
- package/dist/{chunk-GCHH4WHT.js → chunk-YXXHH6WC.js} +2 -2
- package/dist/chunk-ZV5OKQ3Z.cjs.map +1 -1
- package/dist/{chunk-TTEHX4FN.js → chunk-ZYVULRYF.js} +4 -3
- package/dist/chunk-ZYVULRYF.js.map +1 -0
- package/dist/chunks-4HEG6ZPG.js +10 -0
- package/dist/cli.js +47 -22
- package/dist/cli.js.map +1 -1
- package/dist/formula-CG4S7TWO.cjs.map +1 -1
- package/dist/{image-ocr-BWQIUUVC.js → image-ocr-7VYYQH5F.js} +5 -5
- package/dist/image-ocr-7VYYQH5F.js.map +1 -0
- package/dist/{image-ocr-KZ4MGVJ3.cjs → image-ocr-MLUPV4FM.cjs} +10 -10
- package/dist/image-ocr-MLUPV4FM.cjs.map +1 -0
- package/dist/{image-ocr-EDZOUU6Q.js → image-ocr-Y3WDYG4I.js} +6 -6
- package/dist/image-ocr-Y3WDYG4I.js.map +1 -0
- package/dist/index.cjs +203 -187
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +13 -1
- package/dist/index.d.ts +13 -1
- package/dist/index.js +28 -12
- package/dist/index.js.map +1 -1
- package/dist/mcp.js +20 -18
- package/dist/mcp.js.map +1 -1
- package/dist/page-range-P7SDW6LR.cjs.map +1 -1
- package/dist/{parser-JLEKXA2Z.js → parser-FMYUF4DT.js} +8 -8
- package/dist/{parser-JLEKXA2Z.js.map → parser-FMYUF4DT.js.map} +1 -1
- package/dist/{parser-7G2QFIYZ.cjs → parser-QOFG3K3Y.cjs} +30 -30
- package/dist/parser-QOFG3K3Y.cjs.map +1 -0
- package/dist/{parser-6OJOFJ64.js → parser-ZDJ7QTLL.js} +7 -7
- package/dist/{parser-6OJOFJ64.js.map → parser-ZDJ7QTLL.js.map} +1 -1
- package/dist/{pdf-ocr-OWUZLWQ3.js → pdf-ocr-BFWPYON4.js} +5 -5
- package/dist/pdf-ocr-CBJAL5DC.js +12 -0
- package/dist/pdf-ocr-MYZNSEK4.cjs +13 -0
- package/dist/pdf-ocr-MYZNSEK4.cjs.map +1 -0
- package/dist/{profile-io-FMPT6VEZ.js → profile-io-L5EH4JAD.js} +3 -3
- package/dist/{rasterize-LARCX6CS.js → rasterize-7AR662AL.js} +2 -2
- package/dist/render-CAFQT7S4.js +10 -0
- package/dist/seal-ESAC3IZR.js +10 -0
- package/dist/{watch-Y2VKD2MN.js → watch-ZPKLNQTD.js} +9 -9
- package/package.json +1 -1
- package/dist/chunk-2CF2WXBG.js.map +0 -1
- package/dist/chunk-EYLOFSA5.js.map +0 -1
- package/dist/chunk-GLPLLT4Q.cjs.map +0 -1
- package/dist/chunk-NBOVSNSR.js.map +0 -1
- package/dist/chunk-TCPO6XAY.cjs.map +0 -1
- package/dist/chunk-TTEHX4FN.js.map +0 -1
- package/dist/chunk-U3ZNF4SO.cjs.map +0 -1
- package/dist/chunk-UEWW3DH2.js.map +0 -1
- package/dist/chunk-UQ6KDJWE.cjs.map +0 -1
- package/dist/chunks-EYDY4Y6O.js +0 -10
- package/dist/image-ocr-BWQIUUVC.js.map +0 -1
- package/dist/image-ocr-EDZOUU6Q.js.map +0 -1
- package/dist/image-ocr-KZ4MGVJ3.cjs.map +0 -1
- package/dist/parser-7G2QFIYZ.cjs.map +0 -1
- package/dist/pdf-ocr-364VNE6N.cjs +0 -13
- package/dist/pdf-ocr-364VNE6N.cjs.map +0 -1
- package/dist/pdf-ocr-YQGMCT53.js +0 -12
- package/dist/render-4WHQ7JCX.js +0 -10
- package/dist/seal-BX6YA6PI.js +0 -10
- /package/dist/{-CWYIC4ES.js.map → -6XJ6MCQG.js.map} +0 -0
- /package/dist/{chunk-ZHNUH2IW.js.map → chunk-3VTMSSDW.js.map} +0 -0
- /package/dist/{chunk-TP4P7M4I.js.map → chunk-AFPD74JJ.js.map} +0 -0
- /package/dist/{chunk-XYSTZIIL.js.map → chunk-BCG2PKQU.js.map} +0 -0
- /package/dist/{chunk-CBUC73JM.js.map → chunk-IDHBO6AG.js.map} +0 -0
- /package/dist/{chunk-WDIPTY3Q.js.map → chunk-PV2EXXGI.js.map} +0 -0
- /package/dist/{chunk-7ZQKECQT.js.map → chunk-XZDJXYUC.js.map} +0 -0
- /package/dist/{chunk-GCHH4WHT.js.map → chunk-YXXHH6WC.js.map} +0 -0
- /package/dist/{chunks-EYDY4Y6O.js.map → chunks-4HEG6ZPG.js.map} +0 -0
- /package/dist/{pdf-ocr-OWUZLWQ3.js.map → pdf-ocr-BFWPYON4.js.map} +0 -0
- /package/dist/{pdf-ocr-YQGMCT53.js.map → pdf-ocr-CBJAL5DC.js.map} +0 -0
- /package/dist/{profile-io-FMPT6VEZ.js.map → profile-io-L5EH4JAD.js.map} +0 -0
- /package/dist/{rasterize-LARCX6CS.js.map → rasterize-7AR662AL.js.map} +0 -0
- /package/dist/{render-4WHQ7JCX.js.map → render-CAFQT7S4.js.map} +0 -0
- /package/dist/{seal-BX6YA6PI.js.map → seal-ESAC3IZR.js.map} +0 -0
- /package/dist/{watch-Y2VKD2MN.js.map → watch-ZPKLNQTD.js.map} +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
sanitizeHref
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-YUVKU5CW.js";
|
|
4
4
|
|
|
5
5
|
// src/shared/pua.ts
|
|
6
6
|
var BMP_SYMBOL_MAP = {
|
|
@@ -772,4 +772,4 @@ export {
|
|
|
772
772
|
encodePng,
|
|
773
773
|
inlineImagesIntoMarkdown
|
|
774
774
|
};
|
|
775
|
-
//# sourceMappingURL=chunk-
|
|
775
|
+
//# sourceMappingURL=chunk-BCG2PKQU.js.map
|
|
@@ -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-MVTX6ODZ.js";
|
|
7
7
|
import {
|
|
8
8
|
safeMax,
|
|
9
9
|
safeMin
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-ZYVULRYF.js";
|
|
11
11
|
|
|
12
12
|
// src/pdf/image-regions.ts
|
|
13
13
|
import { OPS } from "pdfjs-dist/legacy/build/pdf.mjs";
|
|
@@ -2684,6 +2684,149 @@ function findVerticalCut(items) {
|
|
|
2684
2684
|
return { position, gap: largestGap };
|
|
2685
2685
|
}
|
|
2686
2686
|
|
|
2687
|
+
// src/pdf/two-column.ts
|
|
2688
|
+
var GUTTER_SCAN_LO = 0.3;
|
|
2689
|
+
var GUTTER_SCAN_HI = 0.7;
|
|
2690
|
+
var GUTTER_MAX_SAMPLES = 400;
|
|
2691
|
+
var WIDE_RECT_RATIO = 0.55;
|
|
2692
|
+
var GUTTER_MAX_COVER_RATIO = 0.06;
|
|
2693
|
+
var SIDE_MIN_COUNT = 5;
|
|
2694
|
+
var SIDE_MIN_HEIGHT_RATIO = 0.3;
|
|
2695
|
+
var SIDE_MIN_VSPAN_RATIO = 0.45;
|
|
2696
|
+
var SIDE_MIN_WIDTH_SYMMETRY = 0.5;
|
|
2697
|
+
var MIN_CONTENT_SPAN = 300;
|
|
2698
|
+
var TEXT_RECT_MAX_H = 20;
|
|
2699
|
+
var ROW_Y_TOL = 2;
|
|
2700
|
+
var SIDE_MIN_TEXT_ROWS = 12;
|
|
2701
|
+
var CROSS_ROW_TINY_GAP = 12;
|
|
2702
|
+
var MAX_TINY_GAP_ROWS = 1;
|
|
2703
|
+
var MAX_BOTH_SIDE_ROW_RATIO = 0.65;
|
|
2704
|
+
var BLOCK_DOMINANT_TEXT_RECTS = 10;
|
|
2705
|
+
function detectColumnGutter(rects) {
|
|
2706
|
+
if (rects.length < 8) return null;
|
|
2707
|
+
let minX = Infinity;
|
|
2708
|
+
let maxX = -Infinity;
|
|
2709
|
+
for (const r of rects) {
|
|
2710
|
+
if (r.x < minX) minX = r.x;
|
|
2711
|
+
if (r.x + r.w > maxX) maxX = r.x + r.w;
|
|
2712
|
+
}
|
|
2713
|
+
const span = maxX - minX;
|
|
2714
|
+
if (!Number.isFinite(span) || span < MIN_CONTENT_SPAN) return null;
|
|
2715
|
+
const narrow = rects.filter((r) => r.w < span * WIDE_RECT_RATIO && r.w > 0 && r.h > 0);
|
|
2716
|
+
if (narrow.length < SIDE_MIN_COUNT * 2) return null;
|
|
2717
|
+
let totalH = 0;
|
|
2718
|
+
for (const r of narrow) totalH += r.h;
|
|
2719
|
+
if (totalH <= 0) return null;
|
|
2720
|
+
const lo = minX + span * GUTTER_SCAN_LO;
|
|
2721
|
+
const hi = minX + span * GUTTER_SCAN_HI;
|
|
2722
|
+
const step = Math.max(2, (hi - lo) / GUTTER_MAX_SAMPLES);
|
|
2723
|
+
let gutterX = 0;
|
|
2724
|
+
let bestCover = Infinity;
|
|
2725
|
+
for (let x = lo; x <= hi; x += step) {
|
|
2726
|
+
let cover = 0;
|
|
2727
|
+
for (const r of narrow) {
|
|
2728
|
+
if (r.x < x && r.x + r.w > x) cover += r.h;
|
|
2729
|
+
}
|
|
2730
|
+
if (cover < bestCover) {
|
|
2731
|
+
bestCover = cover;
|
|
2732
|
+
gutterX = x;
|
|
2733
|
+
}
|
|
2734
|
+
}
|
|
2735
|
+
if (bestCover > totalH * GUTTER_MAX_COVER_RATIO) return null;
|
|
2736
|
+
const left = [];
|
|
2737
|
+
const right = [];
|
|
2738
|
+
for (const r of narrow) {
|
|
2739
|
+
if (r.x + r.w <= gutterX) left.push(r);
|
|
2740
|
+
else if (r.x >= gutterX) right.push(r);
|
|
2741
|
+
}
|
|
2742
|
+
if (left.length < SIDE_MIN_COUNT || right.length < SIDE_MIN_COUNT) return null;
|
|
2743
|
+
const sideStats = (side) => {
|
|
2744
|
+
let sMinX = Infinity, sMaxR = -Infinity, sMinY = Infinity, sMaxT = -Infinity, hSum = 0;
|
|
2745
|
+
for (const r of side) {
|
|
2746
|
+
if (r.x < sMinX) sMinX = r.x;
|
|
2747
|
+
if (r.x + r.w > sMaxR) sMaxR = r.x + r.w;
|
|
2748
|
+
if (r.y < sMinY) sMinY = r.y;
|
|
2749
|
+
if (r.y + r.h > sMaxT) sMaxT = r.y + r.h;
|
|
2750
|
+
hSum += r.h;
|
|
2751
|
+
}
|
|
2752
|
+
return { width: sMaxR - sMinX, vspan: sMaxT - sMinY, minY: sMinY, maxT: sMaxT, hSum };
|
|
2753
|
+
};
|
|
2754
|
+
const L = sideStats(left);
|
|
2755
|
+
const R = sideStats(right);
|
|
2756
|
+
if (Math.min(L.hSum, R.hSum) / Math.max(L.hSum, R.hSum) < SIDE_MIN_HEIGHT_RATIO) return null;
|
|
2757
|
+
const unionVspan = Math.max(L.maxT, R.maxT) - Math.min(L.minY, R.minY);
|
|
2758
|
+
if (unionVspan <= 0) return null;
|
|
2759
|
+
if (L.vspan / unionVspan < SIDE_MIN_VSPAN_RATIO) return null;
|
|
2760
|
+
if (R.vspan / unionVspan < SIDE_MIN_VSPAN_RATIO) return null;
|
|
2761
|
+
if (Math.min(L.width, R.width) / Math.max(L.width, R.width) < SIDE_MIN_WIDTH_SYMMETRY) return null;
|
|
2762
|
+
const textRects = (side) => side.filter((r) => r.h <= TEXT_RECT_MAX_H);
|
|
2763
|
+
const lText = textRects(left);
|
|
2764
|
+
const rText = textRects(right);
|
|
2765
|
+
if (lText.length + rText.length >= BLOCK_DOMINANT_TEXT_RECTS) {
|
|
2766
|
+
const rows = /* @__PURE__ */ new Map();
|
|
2767
|
+
const rowKey = (y) => Math.round(y / ROW_Y_TOL);
|
|
2768
|
+
for (const r of lText) {
|
|
2769
|
+
const k = rowKey(r.y);
|
|
2770
|
+
const e = rows.get(k) ?? { lEnd: -Infinity, rStart: Infinity };
|
|
2771
|
+
if (r.x + r.w > e.lEnd) e.lEnd = r.x + r.w;
|
|
2772
|
+
rows.set(k, e);
|
|
2773
|
+
}
|
|
2774
|
+
const lRowCount = rows.size;
|
|
2775
|
+
for (const r of rText) {
|
|
2776
|
+
const k = rowKey(r.y);
|
|
2777
|
+
const e = rows.get(k) ?? { lEnd: -Infinity, rStart: Infinity };
|
|
2778
|
+
if (r.x < e.rStart) e.rStart = r.x;
|
|
2779
|
+
rows.set(k, e);
|
|
2780
|
+
}
|
|
2781
|
+
let rRowCount = 0;
|
|
2782
|
+
let bothRows = 0;
|
|
2783
|
+
let tinyGapRows = 0;
|
|
2784
|
+
for (const e of rows.values()) {
|
|
2785
|
+
if (e.rStart < Infinity) rRowCount++;
|
|
2786
|
+
if (e.lEnd > -Infinity && e.rStart < Infinity) {
|
|
2787
|
+
bothRows++;
|
|
2788
|
+
if (e.rStart - e.lEnd < CROSS_ROW_TINY_GAP) tinyGapRows++;
|
|
2789
|
+
}
|
|
2790
|
+
}
|
|
2791
|
+
if (lRowCount < SIDE_MIN_TEXT_ROWS || rRowCount < SIDE_MIN_TEXT_ROWS) return null;
|
|
2792
|
+
if (tinyGapRows > MAX_TINY_GAP_ROWS) return null;
|
|
2793
|
+
if (bothRows / Math.min(lRowCount, rRowCount) > MAX_BOTH_SIDE_ROW_RATIO) return null;
|
|
2794
|
+
}
|
|
2795
|
+
return gutterX;
|
|
2796
|
+
}
|
|
2797
|
+
function orderByGutter(units, rectOf, gutterX) {
|
|
2798
|
+
const left = [];
|
|
2799
|
+
const right = [];
|
|
2800
|
+
const cross = [];
|
|
2801
|
+
for (const u of units) {
|
|
2802
|
+
const r = rectOf(u);
|
|
2803
|
+
const top = r.y + r.h;
|
|
2804
|
+
if (r.x < gutterX && r.x + r.w > gutterX) cross.push({ u, top });
|
|
2805
|
+
else if (r.x + r.w <= gutterX) left.push({ u, top });
|
|
2806
|
+
else right.push({ u, top });
|
|
2807
|
+
}
|
|
2808
|
+
const byTopDesc = (a, b) => b.top - a.top;
|
|
2809
|
+
cross.sort(byTopDesc);
|
|
2810
|
+
left.sort(byTopDesc);
|
|
2811
|
+
right.sort(byTopDesc);
|
|
2812
|
+
const bandOf = (top) => {
|
|
2813
|
+
let k = 0;
|
|
2814
|
+
while (k < cross.length && cross[k].top > top) k++;
|
|
2815
|
+
return k;
|
|
2816
|
+
};
|
|
2817
|
+
const ordered = [];
|
|
2818
|
+
for (let k = 0; k <= cross.length; k++) {
|
|
2819
|
+
for (const t of left) {
|
|
2820
|
+
if (bandOf(t.top) === k) ordered.push(t.u);
|
|
2821
|
+
}
|
|
2822
|
+
for (const t of right) {
|
|
2823
|
+
if (bandOf(t.top) === k) ordered.push(t.u);
|
|
2824
|
+
}
|
|
2825
|
+
if (k < cross.length) ordered.push(cross[k].u);
|
|
2826
|
+
}
|
|
2827
|
+
return ordered;
|
|
2828
|
+
}
|
|
2829
|
+
|
|
2687
2830
|
// src/pdf/columns.ts
|
|
2688
2831
|
function isProseSpread(items) {
|
|
2689
2832
|
if (items.length < 4) return false;
|
|
@@ -2901,7 +3044,7 @@ function buildGridTable(lines, columns) {
|
|
|
2901
3044
|
}
|
|
2902
3045
|
|
|
2903
3046
|
// src/pdf/page-blocks.ts
|
|
2904
|
-
function extractPageBlocksWithLines(items, pageNum, opList, pageWidth, pageHeight, extraLines) {
|
|
3047
|
+
function extractPageBlocksWithLines(items, pageNum, opList, pageWidth, pageHeight, extraLines, detectTables = true) {
|
|
2905
3048
|
if (items.length === 0) return [];
|
|
2906
3049
|
let { horizontals, verticals } = extractLines(opList.fnArray, opList.argsArray);
|
|
2907
3050
|
if (extraLines) {
|
|
@@ -2915,11 +3058,11 @@ function extractPageBlocksWithLines(items, pageNum, opList, pageWidth, pageHeigh
|
|
|
2915
3058
|
verticals = bridgeSplitColumnVerticals(horizontals, verticals);
|
|
2916
3059
|
markStrikethroughItems(items, horizontals);
|
|
2917
3060
|
wrapStrikethroughRuns(items);
|
|
2918
|
-
const grids = buildTableGrids(horizontals, verticals);
|
|
3061
|
+
const grids = detectTables ? buildTableGrids(horizontals, verticals) : [];
|
|
2919
3062
|
if (grids.length > 0) {
|
|
2920
3063
|
return extractBlocksWithGrids(items, pageNum, grids, horizontals, verticals);
|
|
2921
3064
|
}
|
|
2922
|
-
return extractPageBlocksFallback(items, pageNum, true);
|
|
3065
|
+
return extractPageBlocksFallback(items, pageNum, true, detectTables);
|
|
2923
3066
|
}
|
|
2924
3067
|
var STRIKE_MAX_THICKNESS = 2;
|
|
2925
3068
|
var STRIKE_MAX_THICKNESS_RATIO = 0.25;
|
|
@@ -3117,6 +3260,9 @@ function extractBlocksWithGrids(items, pageNum, grids, horizontals, verticals) {
|
|
|
3117
3260
|
blocks.push({ type: "table", table: irTable, pageNumber: pageNum, bbox: tableBbox });
|
|
3118
3261
|
}
|
|
3119
3262
|
let remaining = items.filter((i) => !usedItems.has(i));
|
|
3263
|
+
const groupSizes = [];
|
|
3264
|
+
let finalTextBlocks = [];
|
|
3265
|
+
let gutterX = null;
|
|
3120
3266
|
if (remaining.length > 0) {
|
|
3121
3267
|
remaining.sort((a, b) => b.y - a.y || a.x - b.x);
|
|
3122
3268
|
const clusterItems = remaining.map((i) => ({
|
|
@@ -3143,9 +3289,37 @@ function extractBlocksWithGrids(items, pageNum, grids, horizontals, verticals) {
|
|
|
3143
3289
|
}
|
|
3144
3290
|
remaining = remaining.filter((_, idx) => !usedClusterIndices.has(idx));
|
|
3145
3291
|
}
|
|
3146
|
-
|
|
3147
|
-
|
|
3148
|
-
|
|
3292
|
+
}
|
|
3293
|
+
{
|
|
3294
|
+
const rects = remaining.map((i) => ({ x: i.x, y: i.y, w: i.w, h: i.h > 0 ? i.h : i.fontSize }));
|
|
3295
|
+
for (const b of blocks) {
|
|
3296
|
+
if (b.bbox) rects.push({ x: b.bbox.x, y: b.bbox.y, w: b.bbox.width, h: b.bbox.height });
|
|
3297
|
+
}
|
|
3298
|
+
gutterX = detectColumnGutter(rects);
|
|
3299
|
+
}
|
|
3300
|
+
if (remaining.length > 0) {
|
|
3301
|
+
if (gutterX !== null) {
|
|
3302
|
+
const gx = gutterX;
|
|
3303
|
+
const allY = remaining.map((i) => i.y);
|
|
3304
|
+
const pageH = safeMax(allY) - safeMin(allY);
|
|
3305
|
+
const gapThreshold = Math.max(15, pageH * 0.03);
|
|
3306
|
+
const sides = [
|
|
3307
|
+
remaining.filter((i) => i.x + i.w <= gx),
|
|
3308
|
+
remaining.filter((i) => i.x < gx && i.x + i.w > gx),
|
|
3309
|
+
remaining.filter((i) => i.x >= gx)
|
|
3310
|
+
];
|
|
3311
|
+
const textBlocks = [];
|
|
3312
|
+
for (const side of sides) {
|
|
3313
|
+
if (side.length === 0) continue;
|
|
3314
|
+
for (const group of xyCutOrder(side, gapThreshold)) {
|
|
3315
|
+
if (group.length === 0) continue;
|
|
3316
|
+
const groupBlocks = extractPageBlocksFallback(group, pageNum);
|
|
3317
|
+
for (const b of groupBlocks) textBlocks.push(b);
|
|
3318
|
+
groupSizes.push(groupBlocks.length);
|
|
3319
|
+
}
|
|
3320
|
+
}
|
|
3321
|
+
finalTextBlocks = detectListBlocks(textBlocks);
|
|
3322
|
+
} else {
|
|
3149
3323
|
const allY = remaining.map((i) => i.y);
|
|
3150
3324
|
const pageH = safeMax(allY) - safeMin(allY);
|
|
3151
3325
|
const groups = xyCutOrder(remaining, Math.max(15, pageH * 0.03));
|
|
@@ -3158,26 +3332,43 @@ function extractBlocksWithGrids(items, pageNum, grids, horizontals, verticals) {
|
|
|
3158
3332
|
}
|
|
3159
3333
|
finalTextBlocks = detectListBlocks(textBlocks);
|
|
3160
3334
|
}
|
|
3161
|
-
|
|
3162
|
-
|
|
3163
|
-
|
|
3164
|
-
|
|
3165
|
-
|
|
3166
|
-
|
|
3335
|
+
}
|
|
3336
|
+
const units = blocks.map((b) => [b]);
|
|
3337
|
+
let off = 0;
|
|
3338
|
+
for (const size of groupSizes) {
|
|
3339
|
+
const unit = finalTextBlocks.slice(off, off + size);
|
|
3340
|
+
off += size;
|
|
3341
|
+
if (unit.length > 0) units.push(unit);
|
|
3342
|
+
}
|
|
3343
|
+
const unitTopY = (u) => {
|
|
3344
|
+
let top = 0;
|
|
3345
|
+
for (const b of u) {
|
|
3346
|
+
if (b.bbox && b.bbox.y + b.bbox.height > top) top = b.bbox.y + b.bbox.height;
|
|
3167
3347
|
}
|
|
3168
|
-
|
|
3169
|
-
|
|
3348
|
+
return top;
|
|
3349
|
+
};
|
|
3350
|
+
if (gutterX !== null && units.length > 1) {
|
|
3351
|
+
const gx = gutterX;
|
|
3352
|
+
const unitRect = (u) => {
|
|
3353
|
+
let minX = Infinity, minY = Infinity, maxR = -Infinity, maxT = -Infinity;
|
|
3170
3354
|
for (const b of u) {
|
|
3171
|
-
if (b.bbox
|
|
3172
|
-
|
|
3173
|
-
|
|
3355
|
+
if (!b.bbox) continue;
|
|
3356
|
+
if (b.bbox.x < minX) minX = b.bbox.x;
|
|
3357
|
+
if (b.bbox.y < minY) minY = b.bbox.y;
|
|
3358
|
+
if (b.bbox.x + b.bbox.width > maxR) maxR = b.bbox.x + b.bbox.width;
|
|
3359
|
+
if (b.bbox.y + b.bbox.height > maxT) maxT = b.bbox.y + b.bbox.height;
|
|
3360
|
+
}
|
|
3361
|
+
if (!Number.isFinite(minX)) return { x: gx - 1, y: 0, w: 2, h: 0 };
|
|
3362
|
+
return { x: minX, y: minY, w: maxR - minX, h: maxT - minY };
|
|
3174
3363
|
};
|
|
3175
|
-
|
|
3176
|
-
const
|
|
3177
|
-
|
|
3178
|
-
return mergeAdjacentTableBlocks(ordered);
|
|
3364
|
+
const ordered2 = [];
|
|
3365
|
+
for (const u of orderByGutter(units, unitRect, gx)) for (const b of u) ordered2.push(b);
|
|
3366
|
+
return mergeAdjacentTableBlocks(ordered2);
|
|
3179
3367
|
}
|
|
3180
|
-
|
|
3368
|
+
units.sort((a, b) => unitTopY(b) - unitTopY(a));
|
|
3369
|
+
const ordered = [];
|
|
3370
|
+
for (const u of units) for (const b of u) ordered.push(b);
|
|
3371
|
+
return mergeAdjacentTableBlocks(ordered);
|
|
3181
3372
|
}
|
|
3182
3373
|
var NEIGHBOR_TABLE_EPSILON = 0.2;
|
|
3183
3374
|
function mergeCrossPageTables(blocks) {
|
|
@@ -3285,7 +3476,7 @@ function splitTwoColumnProse(items, cutX) {
|
|
|
3285
3476
|
}
|
|
3286
3477
|
return groups;
|
|
3287
3478
|
}
|
|
3288
|
-
function extractPageBlocksFallback(items, pageNum, fullPage = false) {
|
|
3479
|
+
function extractPageBlocksFallback(items, pageNum, fullPage = false, detectTables = true) {
|
|
3289
3480
|
if (items.length === 0) return [];
|
|
3290
3481
|
const blocks = [];
|
|
3291
3482
|
const clusterItems = items.map((i) => ({
|
|
@@ -3298,7 +3489,7 @@ function extractPageBlocksFallback(items, pageNum, fullPage = false) {
|
|
|
3298
3489
|
fontName: i.fontName,
|
|
3299
3490
|
hasSpaceBefore: i.hasSpaceBefore
|
|
3300
3491
|
}));
|
|
3301
|
-
const clusterResults = detectClusterTables(clusterItems, pageNum);
|
|
3492
|
+
const clusterResults = detectTables ? detectClusterTables(clusterItems, pageNum) : [];
|
|
3302
3493
|
if (clusterResults.length > 0) {
|
|
3303
3494
|
const ciToIdx = /* @__PURE__ */ new Map();
|
|
3304
3495
|
for (let ci = 0; ci < clusterItems.length; ci++) ciToIdx.set(clusterItems[ci], ci);
|
|
@@ -3326,9 +3517,12 @@ function extractPageBlocksFallback(items, pageNum, fullPage = false) {
|
|
|
3326
3517
|
return by - ay;
|
|
3327
3518
|
});
|
|
3328
3519
|
} else {
|
|
3329
|
-
|
|
3520
|
+
let proseCutX = fullPage ? findTwoColumnProseCutX(items) : null;
|
|
3521
|
+
if (proseCutX === null && fullPage) {
|
|
3522
|
+
proseCutX = detectColumnGutter(items.map((i) => ({ x: i.x, y: i.y, w: i.w, h: i.h > 0 ? i.h : i.fontSize })));
|
|
3523
|
+
}
|
|
3330
3524
|
const allYLines = mergeSuperscriptLines(groupByY(items));
|
|
3331
|
-
const columns = proseCutX !== null ? null : detectColumns(allYLines);
|
|
3525
|
+
const columns = proseCutX !== null || !detectTables ? null : detectColumns(allYLines);
|
|
3332
3526
|
if (columns && columns.length >= 3) {
|
|
3333
3527
|
const tableText = extractWithColumns(allYLines, columns);
|
|
3334
3528
|
const bbox = computeBBox(items, pageNum);
|
|
@@ -3341,7 +3535,7 @@ function extractPageBlocksFallback(items, pageNum, fullPage = false) {
|
|
|
3341
3535
|
for (const group of orderedGroups) {
|
|
3342
3536
|
if (group.length === 0) continue;
|
|
3343
3537
|
const yLines = mergeSuperscriptLines(groupByY(group));
|
|
3344
|
-
const groupColumns = detectColumns(yLines);
|
|
3538
|
+
const groupColumns = detectTables ? detectColumns(yLines) : null;
|
|
3345
3539
|
if (groupColumns && groupColumns.length >= 3) {
|
|
3346
3540
|
const tableText = extractWithColumns(yLines, groupColumns);
|
|
3347
3541
|
const bbox = computeBBox(group, pageNum);
|
|
@@ -3357,7 +3551,7 @@ function extractPageBlocksFallback(items, pageNum, fullPage = false) {
|
|
|
3357
3551
|
}
|
|
3358
3552
|
}
|
|
3359
3553
|
}
|
|
3360
|
-
return detectSpecialKoreanTables(blocks);
|
|
3554
|
+
return detectTables ? detectSpecialKoreanTables(blocks) : blocks;
|
|
3361
3555
|
}
|
|
3362
3556
|
|
|
3363
3557
|
export {
|
|
@@ -3374,4 +3568,4 @@ export {
|
|
|
3374
3568
|
extractPageBlocksWithLines,
|
|
3375
3569
|
mergeCrossPageTables
|
|
3376
3570
|
};
|
|
3377
|
-
//# sourceMappingURL=chunk-
|
|
3571
|
+
//# sourceMappingURL=chunk-BGSGUONP.js.map
|