kordoc 4.6.0 → 4.7.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/LICENSE +21 -21
- package/NOTICE +176 -176
- package/README.md +962 -958
- package/THIRD_PARTY/apache-2.0.LICENSE +201 -201
- package/THIRD_PARTY/claw-hwp.LICENSE +21 -21
- package/THIRD_PARTY/hml-equation-parser.LICENSE +201 -201
- package/THIRD_PARTY/hml-equation-parser.txt +35 -35
- package/THIRD_PARTY/opendataloader-pdf.txt +32 -32
- package/THIRD_PARTY/pix2text.txt +17 -17
- package/THIRD_PARTY/rhwp-forms.txt +35 -35
- package/dist/{-DEVLQKIT.js → -MK2223RL.js} +12 -12
- package/dist/{chunk-3FFPHTXD.js → chunk-3H5X63BQ.js} +1 -1
- package/dist/chunk-3H5X63BQ.js.map +1 -0
- package/dist/{chunk-IBVMJIHR.js → chunk-3VTMSSDW.js} +2 -2
- package/dist/chunk-3VTMSSDW.js.map +1 -0
- package/dist/{chunk-HPRGVU6A.cjs → chunk-5QTHHQQE.cjs} +6 -6
- package/dist/chunk-5QTHHQQE.cjs.map +1 -0
- package/dist/{chunk-6GBLFQMA.js → chunk-5RPYBC2Q.js} +1 -1
- package/dist/chunk-5RPYBC2Q.js.map +1 -0
- package/dist/{chunk-7BTO44Q7.js → chunk-6PIR74EA.js} +13 -13
- package/dist/chunk-6PIR74EA.js.map +1 -0
- package/dist/{chunk-W34QSJFF.js → chunk-7FCNOKOR.js} +1 -1
- package/dist/chunk-7FCNOKOR.js.map +1 -0
- package/dist/{chunk-MSMSHU2F.js → chunk-AEYNY6FG.js} +3 -3
- package/dist/chunk-AEYNY6FG.js.map +1 -0
- package/dist/{chunk-KC63W72C.js → chunk-AFPD74JJ.js} +2 -2
- package/dist/chunk-AFPD74JJ.js.map +1 -0
- package/dist/{chunk-IHK5LCYX.js → chunk-BCG2PKQU.js} +2 -2
- package/dist/chunk-BCG2PKQU.js.map +1 -0
- package/dist/{chunk-I42DND3B.cjs → chunk-C27PPXRZ.cjs} +342 -29
- package/dist/chunk-C27PPXRZ.cjs.map +1 -0
- package/dist/{chunk-X34YWRL5.cjs → chunk-DCZVOIEO.cjs} +1 -1
- package/dist/chunk-DCZVOIEO.cjs.map +1 -0
- package/dist/{chunk-O5EK52TG.js → chunk-DZIXKL7E.js} +1 -1
- package/dist/chunk-DZIXKL7E.js.map +1 -0
- package/dist/{chunk-AIQ3ISQU.js → chunk-GE43BE46.js} +1 -1
- package/dist/chunk-GE43BE46.js.map +1 -0
- package/dist/{chunk-2CENWSAW.js → chunk-GIWKBPII.js} +335 -22
- package/dist/chunk-GIWKBPII.js.map +1 -0
- package/dist/chunk-GS7T56RP.cjs.map +1 -1
- package/dist/{chunk-6XPXIG57.js → chunk-GZDOWYJM.js} +2 -2
- package/dist/chunk-GZDOWYJM.js.map +1 -0
- package/dist/{chunk-OPL22SYF.js → chunk-IDHBO6AG.js} +3 -3
- package/dist/chunk-IDHBO6AG.js.map +1 -0
- package/dist/{chunk-3TBUDJDE.js → chunk-MOL7MDBG.js} +1 -1
- package/dist/chunk-MOL7MDBG.js.map +1 -0
- package/dist/{chunk-PSAHY5XW.js → chunk-MVTX6ODZ.js} +1 -1
- package/dist/chunk-MVTX6ODZ.js.map +1 -0
- package/dist/{chunk-2CABQYTT.js → chunk-P2NWNJMR.js} +3 -3
- package/dist/chunk-P2NWNJMR.js.map +1 -0
- package/dist/{chunk-PQDNCWAZ.js → chunk-PEVPKD6Z.js} +336 -23
- package/dist/chunk-PEVPKD6Z.js.map +1 -0
- package/dist/{chunk-UQ4NSK66.js → chunk-PV2EXXGI.js} +3 -3
- package/dist/chunk-PV2EXXGI.js.map +1 -0
- package/dist/{chunk-WX7WQTOT.cjs → chunk-TUU535RB.cjs} +2 -2
- package/dist/chunk-TUU535RB.cjs.map +1 -0
- package/dist/{chunk-YNJDNP44.js → chunk-UAFSPWU7.js} +1 -1
- package/dist/chunk-UAFSPWU7.js.map +1 -0
- package/dist/{chunk-CARNWWGI.cjs → chunk-W5KRKBYR.cjs} +4 -4
- package/dist/chunk-W5KRKBYR.cjs.map +1 -0
- package/dist/{chunk-VNEV6VKD.js → chunk-XZDJXYUC.js} +2 -2
- package/dist/chunk-XZDJXYUC.js.map +1 -0
- package/dist/{chunk-UGKXJA3W.js → chunk-YUVKU5CW.js} +2 -2
- package/dist/chunk-YUVKU5CW.js.map +1 -0
- package/dist/{chunk-KQOTL4WI.js → chunk-YXXHH6WC.js} +2 -2
- package/dist/chunk-YXXHH6WC.js.map +1 -0
- package/dist/{chunk-MGGU3ZRK.cjs → chunk-ZV5OKQ3Z.cjs} +1 -1
- package/dist/chunk-ZV5OKQ3Z.cjs.map +1 -0
- package/dist/{chunk-ZYQ5X6PG.js → chunk-ZYVULRYF.js} +2 -2
- package/dist/chunk-ZYVULRYF.js.map +1 -0
- package/dist/chunks-4HEG6ZPG.js +10 -0
- package/dist/cli.js +24 -24
- package/dist/cli.js.map +1 -1
- package/dist/{formula-WKGP3D3Y.cjs → formula-CG4S7TWO.cjs} +8 -8
- package/dist/formula-CG4S7TWO.cjs.map +1 -0
- package/dist/{formula-ETB6MESN.js → formula-JLYS73QL.js} +2 -2
- package/dist/formula-JLYS73QL.js.map +1 -0
- package/dist/{formula-KW4NI5IO.js → formula-LIVQSCMM.js} +2 -2
- package/dist/formula-LIVQSCMM.js.map +1 -0
- package/dist/{image-ocr-C6U7YHRC.js → image-ocr-3A3HZX6O.js} +5 -5
- package/dist/image-ocr-3A3HZX6O.js.map +1 -0
- package/dist/{image-ocr-YIBJCOUQ.js → image-ocr-4MHEX4MN.js} +7 -7
- package/dist/image-ocr-4MHEX4MN.js.map +1 -0
- package/dist/{image-ocr-YID6TDN5.cjs → image-ocr-OB5PCQUU.cjs} +11 -11
- package/dist/image-ocr-OB5PCQUU.cjs.map +1 -0
- package/dist/index.cjs +185 -185
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +7 -7
- package/dist/index.js.map +1 -1
- package/dist/mcp.js +20 -20
- package/dist/mcp.js.map +1 -1
- package/dist/{models-6VMAVZR6.js → models-6SIKLKRH.js} +3 -3
- package/dist/page-range-737B4EZW.js +8 -0
- package/dist/page-range-LNMXJU6W.js +7 -0
- package/dist/page-range-P7SDW6LR.cjs +8 -0
- package/dist/page-range-P7SDW6LR.cjs.map +1 -0
- package/dist/{parser-GFXZV2VJ.js → parser-EIVCD4NS.js} +10 -10
- package/dist/parser-EIVCD4NS.js.map +1 -0
- package/dist/{parser-SHM3JEH6.js → parser-EQN4YKU4.js} +8 -8
- package/dist/parser-EQN4YKU4.js.map +1 -0
- package/dist/{parser-EYCVDUJA.cjs → parser-VACM3DFR.cjs} +28 -28
- package/dist/parser-VACM3DFR.cjs.map +1 -0
- package/dist/pdf-ocr-N62EWEX4.js +12 -0
- package/dist/pdf-ocr-NPYDUIC5.js +15 -0
- package/dist/pdf-ocr-OBPQ4F4D.cjs +13 -0
- package/dist/pdf-ocr-OBPQ4F4D.cjs.map +1 -0
- package/dist/{profile-io-FQZNNA3O.js → profile-io-L5EH4JAD.js} +3 -3
- package/dist/{rasterize-QGKFNTXO.js → rasterize-7AR662AL.js} +2 -2
- package/dist/rasterize-7AR662AL.js.map +1 -0
- package/dist/{redact-W5K3ILQH.js → redact-7ILEAUTS.js} +2 -2
- package/dist/render-CAFQT7S4.js +10 -0
- package/dist/seal-ESAC3IZR.js +10 -0
- package/dist/{setup-I4I75QJU.js → setup-GUQT5ELJ.js} +1 -1
- package/dist/setup-GUQT5ELJ.js.map +1 -0
- package/dist/{watch-OIVXH2RN.js → watch-MONT6CGI.js} +12 -12
- package/dist/watch-MONT6CGI.js.map +1 -0
- package/package.json +103 -103
- package/templates//352/260/204/354/235/264/352/270/260/354/225/210/353/254/270_/354/230/210/354/213/234/352/260/222.json +9 -9
- package/templates//354/235/274/353/260/230/352/270/260/354/225/210/353/254/270_/354/230/210/354/213/234/352/260/222.json +24 -24
- package/dist/chunk-2CABQYTT.js.map +0 -1
- package/dist/chunk-2CENWSAW.js.map +0 -1
- package/dist/chunk-3FFPHTXD.js.map +0 -1
- package/dist/chunk-3TBUDJDE.js.map +0 -1
- package/dist/chunk-6GBLFQMA.js.map +0 -1
- package/dist/chunk-6XPXIG57.js.map +0 -1
- package/dist/chunk-7BTO44Q7.js.map +0 -1
- package/dist/chunk-AIQ3ISQU.js.map +0 -1
- package/dist/chunk-CARNWWGI.cjs.map +0 -1
- package/dist/chunk-HPRGVU6A.cjs.map +0 -1
- package/dist/chunk-I42DND3B.cjs.map +0 -1
- package/dist/chunk-IBVMJIHR.js.map +0 -1
- package/dist/chunk-IHK5LCYX.js.map +0 -1
- package/dist/chunk-KC63W72C.js.map +0 -1
- package/dist/chunk-KQOTL4WI.js.map +0 -1
- package/dist/chunk-MGGU3ZRK.cjs.map +0 -1
- package/dist/chunk-MSMSHU2F.js.map +0 -1
- package/dist/chunk-O5EK52TG.js.map +0 -1
- package/dist/chunk-OPL22SYF.js.map +0 -1
- package/dist/chunk-PQDNCWAZ.js.map +0 -1
- package/dist/chunk-PSAHY5XW.js.map +0 -1
- package/dist/chunk-UGKXJA3W.js.map +0 -1
- package/dist/chunk-UQ4NSK66.js.map +0 -1
- package/dist/chunk-VNEV6VKD.js.map +0 -1
- package/dist/chunk-W34QSJFF.js.map +0 -1
- package/dist/chunk-WX7WQTOT.cjs.map +0 -1
- package/dist/chunk-X34YWRL5.cjs.map +0 -1
- package/dist/chunk-YNJDNP44.js.map +0 -1
- package/dist/chunk-ZYQ5X6PG.js.map +0 -1
- package/dist/chunks-Y2VE2WCJ.js +0 -10
- package/dist/formula-ETB6MESN.js.map +0 -1
- package/dist/formula-KW4NI5IO.js.map +0 -1
- package/dist/formula-WKGP3D3Y.cjs.map +0 -1
- package/dist/image-ocr-C6U7YHRC.js.map +0 -1
- package/dist/image-ocr-YIBJCOUQ.js.map +0 -1
- package/dist/image-ocr-YID6TDN5.cjs.map +0 -1
- package/dist/page-range-CIRRJPXJ.js +0 -7
- package/dist/page-range-OF5I4PQY.js +0 -8
- package/dist/page-range-TPIRSA3J.cjs +0 -8
- package/dist/page-range-TPIRSA3J.cjs.map +0 -1
- package/dist/parser-EYCVDUJA.cjs.map +0 -1
- package/dist/parser-GFXZV2VJ.js.map +0 -1
- package/dist/parser-SHM3JEH6.js.map +0 -1
- package/dist/pdf-ocr-TMAWPOHC.cjs +0 -13
- package/dist/pdf-ocr-TMAWPOHC.cjs.map +0 -1
- package/dist/pdf-ocr-UKFYODLP.js +0 -15
- package/dist/pdf-ocr-ZG4UVUIT.js +0 -12
- package/dist/rasterize-QGKFNTXO.js.map +0 -1
- package/dist/render-YFIWQYVB.js +0 -10
- package/dist/seal-GZ7NDWLR.js +0 -10
- package/dist/setup-I4I75QJU.js.map +0 -1
- package/dist/watch-OIVXH2RN.js.map +0 -1
- /package/dist/{-DEVLQKIT.js.map → -MK2223RL.js.map} +0 -0
- /package/dist/{chunks-Y2VE2WCJ.js.map → chunks-4HEG6ZPG.js.map} +0 -0
- /package/dist/{models-6VMAVZR6.js.map → models-6SIKLKRH.js.map} +0 -0
- /package/dist/{page-range-CIRRJPXJ.js.map → page-range-737B4EZW.js.map} +0 -0
- /package/dist/{page-range-OF5I4PQY.js.map → page-range-LNMXJU6W.js.map} +0 -0
- /package/dist/{pdf-ocr-UKFYODLP.js.map → pdf-ocr-N62EWEX4.js.map} +0 -0
- /package/dist/{pdf-ocr-ZG4UVUIT.js.map → pdf-ocr-NPYDUIC5.js.map} +0 -0
- /package/dist/{profile-io-FQZNNA3O.js.map → profile-io-L5EH4JAD.js.map} +0 -0
- /package/dist/{redact-W5K3ILQH.js.map → redact-7ILEAUTS.js.map} +0 -0
- /package/dist/{render-YFIWQYVB.js.map → render-CAFQT7S4.js.map} +0 -0
- /package/dist/{seal-GZ7NDWLR.js.map → seal-ESAC3IZR.js.map} +0 -0
|
@@ -3,11 +3,11 @@ import {
|
|
|
3
3
|
HEADING_RATIO_H1,
|
|
4
4
|
HEADING_RATIO_H2,
|
|
5
5
|
HEADING_RATIO_H3
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-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;
|
|
@@ -2900,6 +3043,123 @@ function buildGridTable(lines, columns) {
|
|
|
2900
3043
|
return md.join("\n");
|
|
2901
3044
|
}
|
|
2902
3045
|
|
|
3046
|
+
// src/pdf/underline.ts
|
|
3047
|
+
var UNDER_MAX_THICKNESS = 2;
|
|
3048
|
+
var UNDER_BELOW_EM = 0.72;
|
|
3049
|
+
var UNDER_BELOW_MIN_PT = 3;
|
|
3050
|
+
var UNDER_ABOVE_PT = 1;
|
|
3051
|
+
var UNDER_MIN_OVERLAP_RATIO = 0.6;
|
|
3052
|
+
var UNDER_OWNER_PAD_EM = 0.75;
|
|
3053
|
+
var UNDER_OWNER_PAD_MIN_PT = 4;
|
|
3054
|
+
var UNDER_MIN_COVERAGE = 0.6;
|
|
3055
|
+
var UNDER_GRID_EPS = 2;
|
|
3056
|
+
var UNDER_COLUMN_GAP_EM = 2;
|
|
3057
|
+
var UNDER_REPEATED_SPAN_LEVELS = 3;
|
|
3058
|
+
var UNDER_SPAN_OVERLAP_RATIO = 0.8;
|
|
3059
|
+
var UNDER_BOX_PAIR_MIN_EM = 0.5;
|
|
3060
|
+
var UNDER_BOX_PAIR_MAX_EM = 2.2;
|
|
3061
|
+
var UNDER_BOX_PAIR_OVERLAP = 0.8;
|
|
3062
|
+
function markUnderlineItems(items, horizontals, verticals) {
|
|
3063
|
+
if (items.length === 0 || horizontals.length === 0) return;
|
|
3064
|
+
for (const line of horizontals) {
|
|
3065
|
+
if (line.lineWidth > UNDER_MAX_THICKNESS) continue;
|
|
3066
|
+
if (touchesVertical(line, verticals)) continue;
|
|
3067
|
+
if (isRepeatedSpanRule(line, horizontals)) continue;
|
|
3068
|
+
const matches = [];
|
|
3069
|
+
for (const item of items) {
|
|
3070
|
+
const h = item.h > 0 ? item.h : item.fontSize;
|
|
3071
|
+
if (h <= 0 || item.w <= 0 || !item.text.trim()) continue;
|
|
3072
|
+
const below = Math.max(h * UNDER_BELOW_EM, UNDER_BELOW_MIN_PT);
|
|
3073
|
+
if (line.y1 < item.y - below || line.y1 > item.y + UNDER_ABOVE_PT) continue;
|
|
3074
|
+
const overlap = Math.min(line.x2, item.x + item.w) - Math.max(line.x1, item.x);
|
|
3075
|
+
if (overlap / item.w < UNDER_MIN_OVERLAP_RATIO) continue;
|
|
3076
|
+
matches.push(item);
|
|
3077
|
+
}
|
|
3078
|
+
if (matches.length === 0) continue;
|
|
3079
|
+
let x1 = Infinity, x2 = -Infinity, maxH = 0, covered = 0;
|
|
3080
|
+
for (const m of matches) {
|
|
3081
|
+
x1 = Math.min(x1, m.x);
|
|
3082
|
+
x2 = Math.max(x2, m.x + m.w);
|
|
3083
|
+
maxH = Math.max(maxH, m.h > 0 ? m.h : m.fontSize);
|
|
3084
|
+
covered += m.w;
|
|
3085
|
+
}
|
|
3086
|
+
const pad = Math.max(maxH * UNDER_OWNER_PAD_EM, UNDER_OWNER_PAD_MIN_PT);
|
|
3087
|
+
if (line.x1 < x1 - pad || line.x2 > x2 + pad) continue;
|
|
3088
|
+
if (covered < (line.x2 - line.x1) * UNDER_MIN_COVERAGE) continue;
|
|
3089
|
+
if (hasBoxTopPair(line, maxH, horizontals)) continue;
|
|
3090
|
+
matches.sort((a, b) => a.x - b.x);
|
|
3091
|
+
let hole = false;
|
|
3092
|
+
for (let i = 1; i < matches.length; i++) {
|
|
3093
|
+
if (matches[i].x - (matches[i - 1].x + matches[i - 1].w) > maxH * UNDER_COLUMN_GAP_EM) {
|
|
3094
|
+
hole = true;
|
|
3095
|
+
break;
|
|
3096
|
+
}
|
|
3097
|
+
}
|
|
3098
|
+
if (hole) continue;
|
|
3099
|
+
for (const m of matches) m.underline = true;
|
|
3100
|
+
}
|
|
3101
|
+
}
|
|
3102
|
+
function touchesVertical(line, verticals) {
|
|
3103
|
+
for (const v of verticals) {
|
|
3104
|
+
if (v.x1 < line.x1 - UNDER_GRID_EPS || v.x1 > line.x2 + UNDER_GRID_EPS) continue;
|
|
3105
|
+
const lo = Math.min(v.y1, v.y2), hi = Math.max(v.y1, v.y2);
|
|
3106
|
+
if (lo <= line.y1 + UNDER_GRID_EPS && hi >= line.y1 - UNDER_GRID_EPS) return true;
|
|
3107
|
+
}
|
|
3108
|
+
return false;
|
|
3109
|
+
}
|
|
3110
|
+
function hasBoxTopPair(line, maxH, horizontals) {
|
|
3111
|
+
const w = line.x2 - line.x1;
|
|
3112
|
+
if (w <= 0) return false;
|
|
3113
|
+
for (const o of horizontals) {
|
|
3114
|
+
if (o === line) continue;
|
|
3115
|
+
const dy = o.y1 - line.y1;
|
|
3116
|
+
if (dy < maxH * UNDER_BOX_PAIR_MIN_EM || dy > maxH * UNDER_BOX_PAIR_MAX_EM) continue;
|
|
3117
|
+
const ow = o.x2 - o.x1;
|
|
3118
|
+
if (ow <= 0) continue;
|
|
3119
|
+
const overlap = Math.min(line.x2, o.x2) - Math.max(line.x1, o.x1);
|
|
3120
|
+
if (overlap / Math.max(w, ow) >= UNDER_BOX_PAIR_OVERLAP) return true;
|
|
3121
|
+
}
|
|
3122
|
+
return false;
|
|
3123
|
+
}
|
|
3124
|
+
function isRepeatedSpanRule(line, horizontals) {
|
|
3125
|
+
const w = line.x2 - line.x1;
|
|
3126
|
+
if (w <= 0) return false;
|
|
3127
|
+
const ys = [];
|
|
3128
|
+
for (const o of horizontals) {
|
|
3129
|
+
const ow = o.x2 - o.x1;
|
|
3130
|
+
if (ow <= 0) continue;
|
|
3131
|
+
const overlap = Math.min(line.x2, o.x2) - Math.max(line.x1, o.x1);
|
|
3132
|
+
if (overlap / Math.max(w, ow) < UNDER_SPAN_OVERLAP_RATIO) continue;
|
|
3133
|
+
if (!ys.some((y) => Math.abs(y - o.y1) < 2)) ys.push(o.y1);
|
|
3134
|
+
}
|
|
3135
|
+
return ys.length >= UNDER_REPEATED_SPAN_LEVELS;
|
|
3136
|
+
}
|
|
3137
|
+
function wrapUnderlineRuns(items) {
|
|
3138
|
+
const marked = items.filter((i) => i.underline);
|
|
3139
|
+
if (marked.length === 0) return;
|
|
3140
|
+
const lines = /* @__PURE__ */ new Map();
|
|
3141
|
+
for (const item of marked) {
|
|
3142
|
+
const key = Math.round(item.y / 3);
|
|
3143
|
+
const arr = lines.get(key) || [];
|
|
3144
|
+
arr.push(item);
|
|
3145
|
+
lines.set(key, arr);
|
|
3146
|
+
}
|
|
3147
|
+
for (const arr of lines.values()) {
|
|
3148
|
+
arr.sort((a, b) => a.x - b.x);
|
|
3149
|
+
let runStart = 0;
|
|
3150
|
+
for (let i = 1; i <= arr.length; i++) {
|
|
3151
|
+
const prev = arr[i - 1];
|
|
3152
|
+
const em = Math.max(prev.h > 0 ? prev.h : prev.fontSize, 1);
|
|
3153
|
+
const gap = i < arr.length ? arr[i].x - (prev.x + prev.w) : Infinity;
|
|
3154
|
+
if (gap > em) {
|
|
3155
|
+
arr[runStart].text = "<u>" + arr[runStart].text;
|
|
3156
|
+
prev.text = prev.text + "</u>";
|
|
3157
|
+
runStart = i;
|
|
3158
|
+
}
|
|
3159
|
+
}
|
|
3160
|
+
}
|
|
3161
|
+
}
|
|
3162
|
+
|
|
2903
3163
|
// src/pdf/page-blocks.ts
|
|
2904
3164
|
function extractPageBlocksWithLines(items, pageNum, opList, pageWidth, pageHeight, extraLines, detectTables = true) {
|
|
2905
3165
|
if (items.length === 0) return [];
|
|
@@ -2915,6 +3175,8 @@ function extractPageBlocksWithLines(items, pageNum, opList, pageWidth, pageHeigh
|
|
|
2915
3175
|
verticals = bridgeSplitColumnVerticals(horizontals, verticals);
|
|
2916
3176
|
markStrikethroughItems(items, horizontals);
|
|
2917
3177
|
wrapStrikethroughRuns(items);
|
|
3178
|
+
markUnderlineItems(items, horizontals, verticals);
|
|
3179
|
+
wrapUnderlineRuns(items);
|
|
2918
3180
|
const grids = detectTables ? buildTableGrids(horizontals, verticals) : [];
|
|
2919
3181
|
if (grids.length > 0) {
|
|
2920
3182
|
return extractBlocksWithGrids(items, pageNum, grids, horizontals, verticals);
|
|
@@ -3117,6 +3379,9 @@ function extractBlocksWithGrids(items, pageNum, grids, horizontals, verticals) {
|
|
|
3117
3379
|
blocks.push({ type: "table", table: irTable, pageNumber: pageNum, bbox: tableBbox });
|
|
3118
3380
|
}
|
|
3119
3381
|
let remaining = items.filter((i) => !usedItems.has(i));
|
|
3382
|
+
const groupSizes = [];
|
|
3383
|
+
let finalTextBlocks = [];
|
|
3384
|
+
let gutterX = null;
|
|
3120
3385
|
if (remaining.length > 0) {
|
|
3121
3386
|
remaining.sort((a, b) => b.y - a.y || a.x - b.x);
|
|
3122
3387
|
const clusterItems = remaining.map((i) => ({
|
|
@@ -3143,9 +3408,37 @@ function extractBlocksWithGrids(items, pageNum, grids, horizontals, verticals) {
|
|
|
3143
3408
|
}
|
|
3144
3409
|
remaining = remaining.filter((_, idx) => !usedClusterIndices.has(idx));
|
|
3145
3410
|
}
|
|
3146
|
-
|
|
3147
|
-
|
|
3148
|
-
|
|
3411
|
+
}
|
|
3412
|
+
{
|
|
3413
|
+
const rects = remaining.map((i) => ({ x: i.x, y: i.y, w: i.w, h: i.h > 0 ? i.h : i.fontSize }));
|
|
3414
|
+
for (const b of blocks) {
|
|
3415
|
+
if (b.bbox) rects.push({ x: b.bbox.x, y: b.bbox.y, w: b.bbox.width, h: b.bbox.height });
|
|
3416
|
+
}
|
|
3417
|
+
gutterX = detectColumnGutter(rects);
|
|
3418
|
+
}
|
|
3419
|
+
if (remaining.length > 0) {
|
|
3420
|
+
if (gutterX !== null) {
|
|
3421
|
+
const gx = gutterX;
|
|
3422
|
+
const allY = remaining.map((i) => i.y);
|
|
3423
|
+
const pageH = safeMax(allY) - safeMin(allY);
|
|
3424
|
+
const gapThreshold = Math.max(15, pageH * 0.03);
|
|
3425
|
+
const sides = [
|
|
3426
|
+
remaining.filter((i) => i.x + i.w <= gx),
|
|
3427
|
+
remaining.filter((i) => i.x < gx && i.x + i.w > gx),
|
|
3428
|
+
remaining.filter((i) => i.x >= gx)
|
|
3429
|
+
];
|
|
3430
|
+
const textBlocks = [];
|
|
3431
|
+
for (const side of sides) {
|
|
3432
|
+
if (side.length === 0) continue;
|
|
3433
|
+
for (const group of xyCutOrder(side, gapThreshold)) {
|
|
3434
|
+
if (group.length === 0) continue;
|
|
3435
|
+
const groupBlocks = extractPageBlocksFallback(group, pageNum);
|
|
3436
|
+
for (const b of groupBlocks) textBlocks.push(b);
|
|
3437
|
+
groupSizes.push(groupBlocks.length);
|
|
3438
|
+
}
|
|
3439
|
+
}
|
|
3440
|
+
finalTextBlocks = detectListBlocks(textBlocks);
|
|
3441
|
+
} else {
|
|
3149
3442
|
const allY = remaining.map((i) => i.y);
|
|
3150
3443
|
const pageH = safeMax(allY) - safeMin(allY);
|
|
3151
3444
|
const groups = xyCutOrder(remaining, Math.max(15, pageH * 0.03));
|
|
@@ -3158,26 +3451,43 @@ function extractBlocksWithGrids(items, pageNum, grids, horizontals, verticals) {
|
|
|
3158
3451
|
}
|
|
3159
3452
|
finalTextBlocks = detectListBlocks(textBlocks);
|
|
3160
3453
|
}
|
|
3161
|
-
|
|
3162
|
-
|
|
3163
|
-
|
|
3164
|
-
|
|
3165
|
-
|
|
3166
|
-
|
|
3454
|
+
}
|
|
3455
|
+
const units = blocks.map((b) => [b]);
|
|
3456
|
+
let off = 0;
|
|
3457
|
+
for (const size of groupSizes) {
|
|
3458
|
+
const unit = finalTextBlocks.slice(off, off + size);
|
|
3459
|
+
off += size;
|
|
3460
|
+
if (unit.length > 0) units.push(unit);
|
|
3461
|
+
}
|
|
3462
|
+
const unitTopY = (u) => {
|
|
3463
|
+
let top = 0;
|
|
3464
|
+
for (const b of u) {
|
|
3465
|
+
if (b.bbox && b.bbox.y + b.bbox.height > top) top = b.bbox.y + b.bbox.height;
|
|
3167
3466
|
}
|
|
3168
|
-
|
|
3169
|
-
|
|
3467
|
+
return top;
|
|
3468
|
+
};
|
|
3469
|
+
if (gutterX !== null && units.length > 1) {
|
|
3470
|
+
const gx = gutterX;
|
|
3471
|
+
const unitRect = (u) => {
|
|
3472
|
+
let minX = Infinity, minY = Infinity, maxR = -Infinity, maxT = -Infinity;
|
|
3170
3473
|
for (const b of u) {
|
|
3171
|
-
if (b.bbox
|
|
3172
|
-
|
|
3173
|
-
|
|
3474
|
+
if (!b.bbox) continue;
|
|
3475
|
+
if (b.bbox.x < minX) minX = b.bbox.x;
|
|
3476
|
+
if (b.bbox.y < minY) minY = b.bbox.y;
|
|
3477
|
+
if (b.bbox.x + b.bbox.width > maxR) maxR = b.bbox.x + b.bbox.width;
|
|
3478
|
+
if (b.bbox.y + b.bbox.height > maxT) maxT = b.bbox.y + b.bbox.height;
|
|
3479
|
+
}
|
|
3480
|
+
if (!Number.isFinite(minX)) return { x: gx - 1, y: 0, w: 2, h: 0 };
|
|
3481
|
+
return { x: minX, y: minY, w: maxR - minX, h: maxT - minY };
|
|
3174
3482
|
};
|
|
3175
|
-
|
|
3176
|
-
const
|
|
3177
|
-
|
|
3178
|
-
return mergeAdjacentTableBlocks(ordered);
|
|
3483
|
+
const ordered2 = [];
|
|
3484
|
+
for (const u of orderByGutter(units, unitRect, gx)) for (const b of u) ordered2.push(b);
|
|
3485
|
+
return mergeAdjacentTableBlocks(ordered2);
|
|
3179
3486
|
}
|
|
3180
|
-
|
|
3487
|
+
units.sort((a, b) => unitTopY(b) - unitTopY(a));
|
|
3488
|
+
const ordered = [];
|
|
3489
|
+
for (const u of units) for (const b of u) ordered.push(b);
|
|
3490
|
+
return mergeAdjacentTableBlocks(ordered);
|
|
3181
3491
|
}
|
|
3182
3492
|
var NEIGHBOR_TABLE_EPSILON = 0.2;
|
|
3183
3493
|
function mergeCrossPageTables(blocks) {
|
|
@@ -3326,7 +3636,10 @@ function extractPageBlocksFallback(items, pageNum, fullPage = false, detectTable
|
|
|
3326
3636
|
return by - ay;
|
|
3327
3637
|
});
|
|
3328
3638
|
} else {
|
|
3329
|
-
|
|
3639
|
+
let proseCutX = fullPage ? findTwoColumnProseCutX(items) : null;
|
|
3640
|
+
if (proseCutX === null && fullPage) {
|
|
3641
|
+
proseCutX = detectColumnGutter(items.map((i) => ({ x: i.x, y: i.y, w: i.w, h: i.h > 0 ? i.h : i.fontSize })));
|
|
3642
|
+
}
|
|
3330
3643
|
const allYLines = mergeSuperscriptLines(groupByY(items));
|
|
3331
3644
|
const columns = proseCutX !== null || !detectTables ? null : detectColumns(allYLines);
|
|
3332
3645
|
if (columns && columns.length >= 3) {
|
|
@@ -3374,4 +3687,4 @@ export {
|
|
|
3374
3687
|
extractPageBlocksWithLines,
|
|
3375
3688
|
mergeCrossPageTables
|
|
3376
3689
|
};
|
|
3377
|
-
//# sourceMappingURL=chunk-
|
|
3690
|
+
//# sourceMappingURL=chunk-PEVPKD6Z.js.map
|