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
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
var
|
|
7
|
+
var _chunkTUU535RBcjs = require('./chunk-TUU535RB.cjs');
|
|
8
8
|
|
|
9
9
|
// src/pdf/image-regions.ts
|
|
10
10
|
var _pdfmjs = require('pdfjs-dist/legacy/build/pdf.mjs');
|
|
@@ -1567,9 +1567,9 @@ function detectHeadings(blocks, medianFontSize) {
|
|
|
1567
1567
|
if (/^\d+$/.test(text)) continue;
|
|
1568
1568
|
const ratio = block.style.fontSize / medianFontSize;
|
|
1569
1569
|
let level = 0;
|
|
1570
|
-
if (ratio >=
|
|
1571
|
-
else if (ratio >=
|
|
1572
|
-
else if (ratio >=
|
|
1570
|
+
if (ratio >= _chunkTUU535RBcjs.HEADING_RATIO_H1) level = 1;
|
|
1571
|
+
else if (ratio >= _chunkTUU535RBcjs.HEADING_RATIO_H2) level = 2;
|
|
1572
|
+
else if (ratio >= _chunkTUU535RBcjs.HEADING_RATIO_H3) level = 3;
|
|
1573
1573
|
if (level > 0) {
|
|
1574
1574
|
block.type = "heading";
|
|
1575
1575
|
block.level = level;
|
|
@@ -2681,6 +2681,149 @@ function findVerticalCut(items) {
|
|
|
2681
2681
|
return { position, gap: largestGap };
|
|
2682
2682
|
}
|
|
2683
2683
|
|
|
2684
|
+
// src/pdf/two-column.ts
|
|
2685
|
+
var GUTTER_SCAN_LO = 0.3;
|
|
2686
|
+
var GUTTER_SCAN_HI = 0.7;
|
|
2687
|
+
var GUTTER_MAX_SAMPLES = 400;
|
|
2688
|
+
var WIDE_RECT_RATIO = 0.55;
|
|
2689
|
+
var GUTTER_MAX_COVER_RATIO = 0.06;
|
|
2690
|
+
var SIDE_MIN_COUNT = 5;
|
|
2691
|
+
var SIDE_MIN_HEIGHT_RATIO = 0.3;
|
|
2692
|
+
var SIDE_MIN_VSPAN_RATIO = 0.45;
|
|
2693
|
+
var SIDE_MIN_WIDTH_SYMMETRY = 0.5;
|
|
2694
|
+
var MIN_CONTENT_SPAN = 300;
|
|
2695
|
+
var TEXT_RECT_MAX_H = 20;
|
|
2696
|
+
var ROW_Y_TOL = 2;
|
|
2697
|
+
var SIDE_MIN_TEXT_ROWS = 12;
|
|
2698
|
+
var CROSS_ROW_TINY_GAP = 12;
|
|
2699
|
+
var MAX_TINY_GAP_ROWS = 1;
|
|
2700
|
+
var MAX_BOTH_SIDE_ROW_RATIO = 0.65;
|
|
2701
|
+
var BLOCK_DOMINANT_TEXT_RECTS = 10;
|
|
2702
|
+
function detectColumnGutter(rects) {
|
|
2703
|
+
if (rects.length < 8) return null;
|
|
2704
|
+
let minX = Infinity;
|
|
2705
|
+
let maxX = -Infinity;
|
|
2706
|
+
for (const r of rects) {
|
|
2707
|
+
if (r.x < minX) minX = r.x;
|
|
2708
|
+
if (r.x + r.w > maxX) maxX = r.x + r.w;
|
|
2709
|
+
}
|
|
2710
|
+
const span = maxX - minX;
|
|
2711
|
+
if (!Number.isFinite(span) || span < MIN_CONTENT_SPAN) return null;
|
|
2712
|
+
const narrow = rects.filter((r) => r.w < span * WIDE_RECT_RATIO && r.w > 0 && r.h > 0);
|
|
2713
|
+
if (narrow.length < SIDE_MIN_COUNT * 2) return null;
|
|
2714
|
+
let totalH = 0;
|
|
2715
|
+
for (const r of narrow) totalH += r.h;
|
|
2716
|
+
if (totalH <= 0) return null;
|
|
2717
|
+
const lo = minX + span * GUTTER_SCAN_LO;
|
|
2718
|
+
const hi = minX + span * GUTTER_SCAN_HI;
|
|
2719
|
+
const step = Math.max(2, (hi - lo) / GUTTER_MAX_SAMPLES);
|
|
2720
|
+
let gutterX = 0;
|
|
2721
|
+
let bestCover = Infinity;
|
|
2722
|
+
for (let x = lo; x <= hi; x += step) {
|
|
2723
|
+
let cover = 0;
|
|
2724
|
+
for (const r of narrow) {
|
|
2725
|
+
if (r.x < x && r.x + r.w > x) cover += r.h;
|
|
2726
|
+
}
|
|
2727
|
+
if (cover < bestCover) {
|
|
2728
|
+
bestCover = cover;
|
|
2729
|
+
gutterX = x;
|
|
2730
|
+
}
|
|
2731
|
+
}
|
|
2732
|
+
if (bestCover > totalH * GUTTER_MAX_COVER_RATIO) return null;
|
|
2733
|
+
const left = [];
|
|
2734
|
+
const right = [];
|
|
2735
|
+
for (const r of narrow) {
|
|
2736
|
+
if (r.x + r.w <= gutterX) left.push(r);
|
|
2737
|
+
else if (r.x >= gutterX) right.push(r);
|
|
2738
|
+
}
|
|
2739
|
+
if (left.length < SIDE_MIN_COUNT || right.length < SIDE_MIN_COUNT) return null;
|
|
2740
|
+
const sideStats = (side) => {
|
|
2741
|
+
let sMinX = Infinity, sMaxR = -Infinity, sMinY = Infinity, sMaxT = -Infinity, hSum = 0;
|
|
2742
|
+
for (const r of side) {
|
|
2743
|
+
if (r.x < sMinX) sMinX = r.x;
|
|
2744
|
+
if (r.x + r.w > sMaxR) sMaxR = r.x + r.w;
|
|
2745
|
+
if (r.y < sMinY) sMinY = r.y;
|
|
2746
|
+
if (r.y + r.h > sMaxT) sMaxT = r.y + r.h;
|
|
2747
|
+
hSum += r.h;
|
|
2748
|
+
}
|
|
2749
|
+
return { width: sMaxR - sMinX, vspan: sMaxT - sMinY, minY: sMinY, maxT: sMaxT, hSum };
|
|
2750
|
+
};
|
|
2751
|
+
const L = sideStats(left);
|
|
2752
|
+
const R = sideStats(right);
|
|
2753
|
+
if (Math.min(L.hSum, R.hSum) / Math.max(L.hSum, R.hSum) < SIDE_MIN_HEIGHT_RATIO) return null;
|
|
2754
|
+
const unionVspan = Math.max(L.maxT, R.maxT) - Math.min(L.minY, R.minY);
|
|
2755
|
+
if (unionVspan <= 0) return null;
|
|
2756
|
+
if (L.vspan / unionVspan < SIDE_MIN_VSPAN_RATIO) return null;
|
|
2757
|
+
if (R.vspan / unionVspan < SIDE_MIN_VSPAN_RATIO) return null;
|
|
2758
|
+
if (Math.min(L.width, R.width) / Math.max(L.width, R.width) < SIDE_MIN_WIDTH_SYMMETRY) return null;
|
|
2759
|
+
const textRects = (side) => side.filter((r) => r.h <= TEXT_RECT_MAX_H);
|
|
2760
|
+
const lText = textRects(left);
|
|
2761
|
+
const rText = textRects(right);
|
|
2762
|
+
if (lText.length + rText.length >= BLOCK_DOMINANT_TEXT_RECTS) {
|
|
2763
|
+
const rows = /* @__PURE__ */ new Map();
|
|
2764
|
+
const rowKey = (y) => Math.round(y / ROW_Y_TOL);
|
|
2765
|
+
for (const r of lText) {
|
|
2766
|
+
const k = rowKey(r.y);
|
|
2767
|
+
const e = _nullishCoalesce(rows.get(k), () => ( { lEnd: -Infinity, rStart: Infinity }));
|
|
2768
|
+
if (r.x + r.w > e.lEnd) e.lEnd = r.x + r.w;
|
|
2769
|
+
rows.set(k, e);
|
|
2770
|
+
}
|
|
2771
|
+
const lRowCount = rows.size;
|
|
2772
|
+
for (const r of rText) {
|
|
2773
|
+
const k = rowKey(r.y);
|
|
2774
|
+
const e = _nullishCoalesce(rows.get(k), () => ( { lEnd: -Infinity, rStart: Infinity }));
|
|
2775
|
+
if (r.x < e.rStart) e.rStart = r.x;
|
|
2776
|
+
rows.set(k, e);
|
|
2777
|
+
}
|
|
2778
|
+
let rRowCount = 0;
|
|
2779
|
+
let bothRows = 0;
|
|
2780
|
+
let tinyGapRows = 0;
|
|
2781
|
+
for (const e of rows.values()) {
|
|
2782
|
+
if (e.rStart < Infinity) rRowCount++;
|
|
2783
|
+
if (e.lEnd > -Infinity && e.rStart < Infinity) {
|
|
2784
|
+
bothRows++;
|
|
2785
|
+
if (e.rStart - e.lEnd < CROSS_ROW_TINY_GAP) tinyGapRows++;
|
|
2786
|
+
}
|
|
2787
|
+
}
|
|
2788
|
+
if (lRowCount < SIDE_MIN_TEXT_ROWS || rRowCount < SIDE_MIN_TEXT_ROWS) return null;
|
|
2789
|
+
if (tinyGapRows > MAX_TINY_GAP_ROWS) return null;
|
|
2790
|
+
if (bothRows / Math.min(lRowCount, rRowCount) > MAX_BOTH_SIDE_ROW_RATIO) return null;
|
|
2791
|
+
}
|
|
2792
|
+
return gutterX;
|
|
2793
|
+
}
|
|
2794
|
+
function orderByGutter(units, rectOf, gutterX) {
|
|
2795
|
+
const left = [];
|
|
2796
|
+
const right = [];
|
|
2797
|
+
const cross = [];
|
|
2798
|
+
for (const u of units) {
|
|
2799
|
+
const r = rectOf(u);
|
|
2800
|
+
const top = r.y + r.h;
|
|
2801
|
+
if (r.x < gutterX && r.x + r.w > gutterX) cross.push({ u, top });
|
|
2802
|
+
else if (r.x + r.w <= gutterX) left.push({ u, top });
|
|
2803
|
+
else right.push({ u, top });
|
|
2804
|
+
}
|
|
2805
|
+
const byTopDesc = (a, b) => b.top - a.top;
|
|
2806
|
+
cross.sort(byTopDesc);
|
|
2807
|
+
left.sort(byTopDesc);
|
|
2808
|
+
right.sort(byTopDesc);
|
|
2809
|
+
const bandOf = (top) => {
|
|
2810
|
+
let k = 0;
|
|
2811
|
+
while (k < cross.length && cross[k].top > top) k++;
|
|
2812
|
+
return k;
|
|
2813
|
+
};
|
|
2814
|
+
const ordered = [];
|
|
2815
|
+
for (let k = 0; k <= cross.length; k++) {
|
|
2816
|
+
for (const t of left) {
|
|
2817
|
+
if (bandOf(t.top) === k) ordered.push(t.u);
|
|
2818
|
+
}
|
|
2819
|
+
for (const t of right) {
|
|
2820
|
+
if (bandOf(t.top) === k) ordered.push(t.u);
|
|
2821
|
+
}
|
|
2822
|
+
if (k < cross.length) ordered.push(cross[k].u);
|
|
2823
|
+
}
|
|
2824
|
+
return ordered;
|
|
2825
|
+
}
|
|
2826
|
+
|
|
2684
2827
|
// src/pdf/columns.ts
|
|
2685
2828
|
function isProseSpread(items) {
|
|
2686
2829
|
if (items.length < 4) return false;
|
|
@@ -2689,14 +2832,14 @@ function isProseSpread(items) {
|
|
|
2689
2832
|
for (let i = 1; i < sorted.length; i++) {
|
|
2690
2833
|
gaps.push(sorted[i].x - (sorted[i - 1].x + sorted[i - 1].w));
|
|
2691
2834
|
}
|
|
2692
|
-
const maxGap =
|
|
2835
|
+
const maxGap = _chunkTUU535RBcjs.safeMax.call(void 0, gaps);
|
|
2693
2836
|
const avgLen = items.reduce((s, i) => s + i.text.length, 0) / items.length;
|
|
2694
2837
|
return maxGap < 40 && avgLen < 5;
|
|
2695
2838
|
}
|
|
2696
2839
|
function detectColumns(yLines) {
|
|
2697
2840
|
const allItems = yLines.flat();
|
|
2698
2841
|
if (allItems.length === 0) return null;
|
|
2699
|
-
const pageWidth =
|
|
2842
|
+
const pageWidth = _chunkTUU535RBcjs.safeMax.call(void 0, allItems.map((i) => i.x + i.w)) - _chunkTUU535RBcjs.safeMin.call(void 0, allItems.map((i) => i.x));
|
|
2700
2843
|
if (pageWidth < 100) return null;
|
|
2701
2844
|
let bigoLineIdx = -1;
|
|
2702
2845
|
for (let i = 0; i < yLines.length; i++) {
|
|
@@ -2897,6 +3040,123 @@ function buildGridTable(lines, columns) {
|
|
|
2897
3040
|
return md.join("\n");
|
|
2898
3041
|
}
|
|
2899
3042
|
|
|
3043
|
+
// src/pdf/underline.ts
|
|
3044
|
+
var UNDER_MAX_THICKNESS = 2;
|
|
3045
|
+
var UNDER_BELOW_EM = 0.72;
|
|
3046
|
+
var UNDER_BELOW_MIN_PT = 3;
|
|
3047
|
+
var UNDER_ABOVE_PT = 1;
|
|
3048
|
+
var UNDER_MIN_OVERLAP_RATIO = 0.6;
|
|
3049
|
+
var UNDER_OWNER_PAD_EM = 0.75;
|
|
3050
|
+
var UNDER_OWNER_PAD_MIN_PT = 4;
|
|
3051
|
+
var UNDER_MIN_COVERAGE = 0.6;
|
|
3052
|
+
var UNDER_GRID_EPS = 2;
|
|
3053
|
+
var UNDER_COLUMN_GAP_EM = 2;
|
|
3054
|
+
var UNDER_REPEATED_SPAN_LEVELS = 3;
|
|
3055
|
+
var UNDER_SPAN_OVERLAP_RATIO = 0.8;
|
|
3056
|
+
var UNDER_BOX_PAIR_MIN_EM = 0.5;
|
|
3057
|
+
var UNDER_BOX_PAIR_MAX_EM = 2.2;
|
|
3058
|
+
var UNDER_BOX_PAIR_OVERLAP = 0.8;
|
|
3059
|
+
function markUnderlineItems(items, horizontals, verticals) {
|
|
3060
|
+
if (items.length === 0 || horizontals.length === 0) return;
|
|
3061
|
+
for (const line of horizontals) {
|
|
3062
|
+
if (line.lineWidth > UNDER_MAX_THICKNESS) continue;
|
|
3063
|
+
if (touchesVertical(line, verticals)) continue;
|
|
3064
|
+
if (isRepeatedSpanRule(line, horizontals)) continue;
|
|
3065
|
+
const matches = [];
|
|
3066
|
+
for (const item of items) {
|
|
3067
|
+
const h = item.h > 0 ? item.h : item.fontSize;
|
|
3068
|
+
if (h <= 0 || item.w <= 0 || !item.text.trim()) continue;
|
|
3069
|
+
const below = Math.max(h * UNDER_BELOW_EM, UNDER_BELOW_MIN_PT);
|
|
3070
|
+
if (line.y1 < item.y - below || line.y1 > item.y + UNDER_ABOVE_PT) continue;
|
|
3071
|
+
const overlap = Math.min(line.x2, item.x + item.w) - Math.max(line.x1, item.x);
|
|
3072
|
+
if (overlap / item.w < UNDER_MIN_OVERLAP_RATIO) continue;
|
|
3073
|
+
matches.push(item);
|
|
3074
|
+
}
|
|
3075
|
+
if (matches.length === 0) continue;
|
|
3076
|
+
let x1 = Infinity, x2 = -Infinity, maxH = 0, covered = 0;
|
|
3077
|
+
for (const m of matches) {
|
|
3078
|
+
x1 = Math.min(x1, m.x);
|
|
3079
|
+
x2 = Math.max(x2, m.x + m.w);
|
|
3080
|
+
maxH = Math.max(maxH, m.h > 0 ? m.h : m.fontSize);
|
|
3081
|
+
covered += m.w;
|
|
3082
|
+
}
|
|
3083
|
+
const pad = Math.max(maxH * UNDER_OWNER_PAD_EM, UNDER_OWNER_PAD_MIN_PT);
|
|
3084
|
+
if (line.x1 < x1 - pad || line.x2 > x2 + pad) continue;
|
|
3085
|
+
if (covered < (line.x2 - line.x1) * UNDER_MIN_COVERAGE) continue;
|
|
3086
|
+
if (hasBoxTopPair(line, maxH, horizontals)) continue;
|
|
3087
|
+
matches.sort((a, b) => a.x - b.x);
|
|
3088
|
+
let hole = false;
|
|
3089
|
+
for (let i = 1; i < matches.length; i++) {
|
|
3090
|
+
if (matches[i].x - (matches[i - 1].x + matches[i - 1].w) > maxH * UNDER_COLUMN_GAP_EM) {
|
|
3091
|
+
hole = true;
|
|
3092
|
+
break;
|
|
3093
|
+
}
|
|
3094
|
+
}
|
|
3095
|
+
if (hole) continue;
|
|
3096
|
+
for (const m of matches) m.underline = true;
|
|
3097
|
+
}
|
|
3098
|
+
}
|
|
3099
|
+
function touchesVertical(line, verticals) {
|
|
3100
|
+
for (const v of verticals) {
|
|
3101
|
+
if (v.x1 < line.x1 - UNDER_GRID_EPS || v.x1 > line.x2 + UNDER_GRID_EPS) continue;
|
|
3102
|
+
const lo = Math.min(v.y1, v.y2), hi = Math.max(v.y1, v.y2);
|
|
3103
|
+
if (lo <= line.y1 + UNDER_GRID_EPS && hi >= line.y1 - UNDER_GRID_EPS) return true;
|
|
3104
|
+
}
|
|
3105
|
+
return false;
|
|
3106
|
+
}
|
|
3107
|
+
function hasBoxTopPair(line, maxH, horizontals) {
|
|
3108
|
+
const w = line.x2 - line.x1;
|
|
3109
|
+
if (w <= 0) return false;
|
|
3110
|
+
for (const o of horizontals) {
|
|
3111
|
+
if (o === line) continue;
|
|
3112
|
+
const dy = o.y1 - line.y1;
|
|
3113
|
+
if (dy < maxH * UNDER_BOX_PAIR_MIN_EM || dy > maxH * UNDER_BOX_PAIR_MAX_EM) continue;
|
|
3114
|
+
const ow = o.x2 - o.x1;
|
|
3115
|
+
if (ow <= 0) continue;
|
|
3116
|
+
const overlap = Math.min(line.x2, o.x2) - Math.max(line.x1, o.x1);
|
|
3117
|
+
if (overlap / Math.max(w, ow) >= UNDER_BOX_PAIR_OVERLAP) return true;
|
|
3118
|
+
}
|
|
3119
|
+
return false;
|
|
3120
|
+
}
|
|
3121
|
+
function isRepeatedSpanRule(line, horizontals) {
|
|
3122
|
+
const w = line.x2 - line.x1;
|
|
3123
|
+
if (w <= 0) return false;
|
|
3124
|
+
const ys = [];
|
|
3125
|
+
for (const o of horizontals) {
|
|
3126
|
+
const ow = o.x2 - o.x1;
|
|
3127
|
+
if (ow <= 0) continue;
|
|
3128
|
+
const overlap = Math.min(line.x2, o.x2) - Math.max(line.x1, o.x1);
|
|
3129
|
+
if (overlap / Math.max(w, ow) < UNDER_SPAN_OVERLAP_RATIO) continue;
|
|
3130
|
+
if (!ys.some((y) => Math.abs(y - o.y1) < 2)) ys.push(o.y1);
|
|
3131
|
+
}
|
|
3132
|
+
return ys.length >= UNDER_REPEATED_SPAN_LEVELS;
|
|
3133
|
+
}
|
|
3134
|
+
function wrapUnderlineRuns(items) {
|
|
3135
|
+
const marked = items.filter((i) => i.underline);
|
|
3136
|
+
if (marked.length === 0) return;
|
|
3137
|
+
const lines = /* @__PURE__ */ new Map();
|
|
3138
|
+
for (const item of marked) {
|
|
3139
|
+
const key = Math.round(item.y / 3);
|
|
3140
|
+
const arr = lines.get(key) || [];
|
|
3141
|
+
arr.push(item);
|
|
3142
|
+
lines.set(key, arr);
|
|
3143
|
+
}
|
|
3144
|
+
for (const arr of lines.values()) {
|
|
3145
|
+
arr.sort((a, b) => a.x - b.x);
|
|
3146
|
+
let runStart = 0;
|
|
3147
|
+
for (let i = 1; i <= arr.length; i++) {
|
|
3148
|
+
const prev = arr[i - 1];
|
|
3149
|
+
const em = Math.max(prev.h > 0 ? prev.h : prev.fontSize, 1);
|
|
3150
|
+
const gap = i < arr.length ? arr[i].x - (prev.x + prev.w) : Infinity;
|
|
3151
|
+
if (gap > em) {
|
|
3152
|
+
arr[runStart].text = "<u>" + arr[runStart].text;
|
|
3153
|
+
prev.text = prev.text + "</u>";
|
|
3154
|
+
runStart = i;
|
|
3155
|
+
}
|
|
3156
|
+
}
|
|
3157
|
+
}
|
|
3158
|
+
}
|
|
3159
|
+
|
|
2900
3160
|
// src/pdf/page-blocks.ts
|
|
2901
3161
|
function extractPageBlocksWithLines(items, pageNum, opList, pageWidth, pageHeight, extraLines, detectTables = true) {
|
|
2902
3162
|
if (items.length === 0) return [];
|
|
@@ -2912,6 +3172,8 @@ function extractPageBlocksWithLines(items, pageNum, opList, pageWidth, pageHeigh
|
|
|
2912
3172
|
verticals = bridgeSplitColumnVerticals(horizontals, verticals);
|
|
2913
3173
|
markStrikethroughItems(items, horizontals);
|
|
2914
3174
|
wrapStrikethroughRuns(items);
|
|
3175
|
+
markUnderlineItems(items, horizontals, verticals);
|
|
3176
|
+
wrapUnderlineRuns(items);
|
|
2915
3177
|
const grids = detectTables ? buildTableGrids(horizontals, verticals) : [];
|
|
2916
3178
|
if (grids.length > 0) {
|
|
2917
3179
|
return extractBlocksWithGrids(items, pageNum, grids, horizontals, verticals);
|
|
@@ -3114,6 +3376,9 @@ function extractBlocksWithGrids(items, pageNum, grids, horizontals, verticals) {
|
|
|
3114
3376
|
blocks.push({ type: "table", table: irTable, pageNumber: pageNum, bbox: tableBbox });
|
|
3115
3377
|
}
|
|
3116
3378
|
let remaining = items.filter((i) => !usedItems.has(i));
|
|
3379
|
+
const groupSizes = [];
|
|
3380
|
+
let finalTextBlocks = [];
|
|
3381
|
+
let gutterX = null;
|
|
3117
3382
|
if (remaining.length > 0) {
|
|
3118
3383
|
remaining.sort((a, b) => b.y - a.y || a.x - b.x);
|
|
3119
3384
|
const clusterItems = remaining.map((i) => ({
|
|
@@ -3140,11 +3405,39 @@ function extractBlocksWithGrids(items, pageNum, grids, horizontals, verticals) {
|
|
|
3140
3405
|
}
|
|
3141
3406
|
remaining = remaining.filter((_, idx) => !usedClusterIndices.has(idx));
|
|
3142
3407
|
}
|
|
3143
|
-
|
|
3144
|
-
|
|
3145
|
-
|
|
3408
|
+
}
|
|
3409
|
+
{
|
|
3410
|
+
const rects = remaining.map((i) => ({ x: i.x, y: i.y, w: i.w, h: i.h > 0 ? i.h : i.fontSize }));
|
|
3411
|
+
for (const b of blocks) {
|
|
3412
|
+
if (b.bbox) rects.push({ x: b.bbox.x, y: b.bbox.y, w: b.bbox.width, h: b.bbox.height });
|
|
3413
|
+
}
|
|
3414
|
+
gutterX = detectColumnGutter(rects);
|
|
3415
|
+
}
|
|
3416
|
+
if (remaining.length > 0) {
|
|
3417
|
+
if (gutterX !== null) {
|
|
3418
|
+
const gx = gutterX;
|
|
3146
3419
|
const allY = remaining.map((i) => i.y);
|
|
3147
|
-
const pageH =
|
|
3420
|
+
const pageH = _chunkTUU535RBcjs.safeMax.call(void 0, allY) - _chunkTUU535RBcjs.safeMin.call(void 0, allY);
|
|
3421
|
+
const gapThreshold = Math.max(15, pageH * 0.03);
|
|
3422
|
+
const sides = [
|
|
3423
|
+
remaining.filter((i) => i.x + i.w <= gx),
|
|
3424
|
+
remaining.filter((i) => i.x < gx && i.x + i.w > gx),
|
|
3425
|
+
remaining.filter((i) => i.x >= gx)
|
|
3426
|
+
];
|
|
3427
|
+
const textBlocks = [];
|
|
3428
|
+
for (const side of sides) {
|
|
3429
|
+
if (side.length === 0) continue;
|
|
3430
|
+
for (const group of xyCutOrder(side, gapThreshold)) {
|
|
3431
|
+
if (group.length === 0) continue;
|
|
3432
|
+
const groupBlocks = extractPageBlocksFallback(group, pageNum);
|
|
3433
|
+
for (const b of groupBlocks) textBlocks.push(b);
|
|
3434
|
+
groupSizes.push(groupBlocks.length);
|
|
3435
|
+
}
|
|
3436
|
+
}
|
|
3437
|
+
finalTextBlocks = detectListBlocks(textBlocks);
|
|
3438
|
+
} else {
|
|
3439
|
+
const allY = remaining.map((i) => i.y);
|
|
3440
|
+
const pageH = _chunkTUU535RBcjs.safeMax.call(void 0, allY) - _chunkTUU535RBcjs.safeMin.call(void 0, allY);
|
|
3148
3441
|
const groups = xyCutOrder(remaining, Math.max(15, pageH * 0.03));
|
|
3149
3442
|
const textBlocks = [];
|
|
3150
3443
|
for (const group of groups) {
|
|
@@ -3155,26 +3448,43 @@ function extractBlocksWithGrids(items, pageNum, grids, horizontals, verticals) {
|
|
|
3155
3448
|
}
|
|
3156
3449
|
finalTextBlocks = detectListBlocks(textBlocks);
|
|
3157
3450
|
}
|
|
3158
|
-
|
|
3159
|
-
|
|
3160
|
-
|
|
3161
|
-
|
|
3162
|
-
|
|
3163
|
-
|
|
3451
|
+
}
|
|
3452
|
+
const units = blocks.map((b) => [b]);
|
|
3453
|
+
let off = 0;
|
|
3454
|
+
for (const size of groupSizes) {
|
|
3455
|
+
const unit = finalTextBlocks.slice(off, off + size);
|
|
3456
|
+
off += size;
|
|
3457
|
+
if (unit.length > 0) units.push(unit);
|
|
3458
|
+
}
|
|
3459
|
+
const unitTopY = (u) => {
|
|
3460
|
+
let top = 0;
|
|
3461
|
+
for (const b of u) {
|
|
3462
|
+
if (b.bbox && b.bbox.y + b.bbox.height > top) top = b.bbox.y + b.bbox.height;
|
|
3164
3463
|
}
|
|
3165
|
-
|
|
3166
|
-
|
|
3464
|
+
return top;
|
|
3465
|
+
};
|
|
3466
|
+
if (gutterX !== null && units.length > 1) {
|
|
3467
|
+
const gx = gutterX;
|
|
3468
|
+
const unitRect = (u) => {
|
|
3469
|
+
let minX = Infinity, minY = Infinity, maxR = -Infinity, maxT = -Infinity;
|
|
3167
3470
|
for (const b of u) {
|
|
3168
|
-
if (b.bbox
|
|
3169
|
-
|
|
3170
|
-
|
|
3471
|
+
if (!b.bbox) continue;
|
|
3472
|
+
if (b.bbox.x < minX) minX = b.bbox.x;
|
|
3473
|
+
if (b.bbox.y < minY) minY = b.bbox.y;
|
|
3474
|
+
if (b.bbox.x + b.bbox.width > maxR) maxR = b.bbox.x + b.bbox.width;
|
|
3475
|
+
if (b.bbox.y + b.bbox.height > maxT) maxT = b.bbox.y + b.bbox.height;
|
|
3476
|
+
}
|
|
3477
|
+
if (!Number.isFinite(minX)) return { x: gx - 1, y: 0, w: 2, h: 0 };
|
|
3478
|
+
return { x: minX, y: minY, w: maxR - minX, h: maxT - minY };
|
|
3171
3479
|
};
|
|
3172
|
-
|
|
3173
|
-
const
|
|
3174
|
-
|
|
3175
|
-
return mergeAdjacentTableBlocks(ordered);
|
|
3480
|
+
const ordered2 = [];
|
|
3481
|
+
for (const u of orderByGutter(units, unitRect, gx)) for (const b of u) ordered2.push(b);
|
|
3482
|
+
return mergeAdjacentTableBlocks(ordered2);
|
|
3176
3483
|
}
|
|
3177
|
-
|
|
3484
|
+
units.sort((a, b) => unitTopY(b) - unitTopY(a));
|
|
3485
|
+
const ordered = [];
|
|
3486
|
+
for (const u of units) for (const b of u) ordered.push(b);
|
|
3487
|
+
return mergeAdjacentTableBlocks(ordered);
|
|
3178
3488
|
}
|
|
3179
3489
|
var NEIGHBOR_TABLE_EPSILON = 0.2;
|
|
3180
3490
|
function mergeCrossPageTables(blocks) {
|
|
@@ -3323,7 +3633,10 @@ function extractPageBlocksFallback(items, pageNum, fullPage = false, detectTable
|
|
|
3323
3633
|
return by - ay;
|
|
3324
3634
|
});
|
|
3325
3635
|
} else {
|
|
3326
|
-
|
|
3636
|
+
let proseCutX = fullPage ? findTwoColumnProseCutX(items) : null;
|
|
3637
|
+
if (proseCutX === null && fullPage) {
|
|
3638
|
+
proseCutX = detectColumnGutter(items.map((i) => ({ x: i.x, y: i.y, w: i.w, h: i.h > 0 ? i.h : i.fontSize })));
|
|
3639
|
+
}
|
|
3327
3640
|
const allYLines = mergeSuperscriptLines(groupByY(items));
|
|
3328
3641
|
const columns = proseCutX !== null || !detectTables ? null : detectColumns(allYLines);
|
|
3329
3642
|
if (columns && columns.length >= 3) {
|
|
@@ -3332,7 +3645,7 @@ function extractPageBlocksFallback(items, pageNum, fullPage = false, detectTable
|
|
|
3332
3645
|
blocks.push({ type: "paragraph", text: tableText, pageNumber: pageNum, bbox, style: dominantStyle(items) });
|
|
3333
3646
|
} else {
|
|
3334
3647
|
const allY = items.map((i) => i.y);
|
|
3335
|
-
const pageHeight =
|
|
3648
|
+
const pageHeight = _chunkTUU535RBcjs.safeMax.call(void 0, allY) - _chunkTUU535RBcjs.safeMin.call(void 0, allY);
|
|
3336
3649
|
const gapThreshold = Math.max(15, pageHeight * 0.03);
|
|
3337
3650
|
const orderedGroups = proseCutX !== null ? splitTwoColumnProse(items, proseCutX) : xyCutOrder(items, gapThreshold);
|
|
3338
3651
|
for (const group of orderedGroups) {
|
|
@@ -3371,4 +3684,4 @@ function extractPageBlocksFallback(items, pageNum, fullPage = false, detectTable
|
|
|
3371
3684
|
|
|
3372
3685
|
|
|
3373
3686
|
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.extractPageBlocksWithLines = extractPageBlocksWithLines; exports.mergeCrossPageTables = mergeCrossPageTables;
|
|
3374
|
-
//# sourceMappingURL=chunk-
|
|
3687
|
+
//# sourceMappingURL=chunk-C27PPXRZ.cjs.map
|