kordoc 4.24.47 → 4.24.48
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/NOTICE +21 -0
- package/README.md +3 -3
- package/dist/{-PWMZE4CC.js → -3EMVBTE7.js} +22 -22
- package/dist/{chunk-SUIH5LY7.js → chunk-3UY7ARXP.js} +2 -2
- package/dist/{chunk-TN5ZK2WN.js → chunk-4N2ESXR2.js} +2 -2
- package/dist/{chunk-2VXVBB5Q.js → chunk-6YUMHSBG.js} +3 -3
- package/dist/{chunk-T5J4GW6B.js → chunk-7EL6BCO5.js} +2 -2
- package/dist/{chunk-GRQXAWNW.js → chunk-7F5SKDUG.js} +2 -2
- package/dist/{chunk-UFY6XX4U.cjs → chunk-A6EOKPKG.cjs} +46 -25
- package/dist/chunk-A6EOKPKG.cjs.map +1 -0
- package/dist/{chunk-AB7MYMPZ.js → chunk-AC7FZDVP.js} +2 -2
- package/dist/{chunk-HMD35PMD.js → chunk-D4TKVZKB.js} +3 -3
- package/dist/{chunk-A67OXFXM.js → chunk-D7SOY3VR.js} +25 -4
- package/dist/chunk-D7SOY3VR.js.map +1 -0
- package/dist/{chunk-56FEGA44.js → chunk-E47LO7XG.js} +11 -11
- package/dist/{chunk-BP5GDQBT.js → chunk-E5RJLP2S.js} +5 -5
- package/dist/{chunk-AO3YFJVW.js → chunk-FQMPHPHE.js} +2 -2
- package/dist/{chunk-MOWJOFIH.js → chunk-GFWCBYAI.js} +2 -2
- package/dist/chunk-GOYAJVR6.js +120 -0
- package/dist/chunk-GOYAJVR6.js.map +1 -0
- package/dist/{chunk-SQ5Q4Q3R.js → chunk-HW3DZ7TY.js} +7 -7
- package/dist/{chunk-Q3UCWUEV.js → chunk-JC2TMUU5.js} +6 -6
- package/dist/{chunk-OAKJNKAS.js → chunk-KTGOULMH.js} +145 -5
- package/dist/chunk-KTGOULMH.js.map +1 -0
- package/dist/{chunk-X7RBVVDC.cjs → chunk-LBH4KAQM.cjs} +3 -2
- package/dist/chunk-LBH4KAQM.cjs.map +1 -0
- package/dist/{chunk-O2652KK3.cjs → chunk-LHZL52HO.cjs} +3 -3
- package/dist/{chunk-O2652KK3.cjs.map → chunk-LHZL52HO.cjs.map} +1 -1
- package/dist/{chunk-3CWVQNFL.cjs → chunk-MHAPDR6T.cjs} +60 -60
- package/dist/{chunk-3CWVQNFL.cjs.map → chunk-MHAPDR6T.cjs.map} +1 -1
- package/dist/{chunk-KSE5HSU3.js → chunk-MHLTZ3VI.js} +8 -5
- package/dist/chunk-MHLTZ3VI.js.map +1 -0
- package/dist/{chunk-NYIJU4Q6.js → chunk-MYIRYP6D.js} +10 -10
- package/dist/{chunk-FI7ULBC6.js → chunk-N6B5BINC.js} +6 -6
- package/dist/{chunk-BO2IJGNZ.js → chunk-NLPIXQOV.js} +2 -2
- package/dist/{chunk-2CBIY2OH.js → chunk-OBNOOHAW.js} +2 -2
- package/dist/{chunk-2CBIY2OH.js.map → chunk-OBNOOHAW.js.map} +1 -1
- package/dist/{chunk-IPXFIH5E.js → chunk-OO4DHHTG.js} +8 -5
- package/dist/chunk-OO4DHHTG.js.map +1 -0
- package/dist/{chunk-HFQFCAEJ.js → chunk-OQPIN2OY.js} +2 -2
- package/dist/{chunk-PM46GSMV.js → chunk-OUUI7I5V.js} +146 -6
- package/dist/chunk-OUUI7I5V.js.map +1 -0
- package/dist/chunk-PHU4VSNF.js +119 -0
- package/dist/chunk-PHU4VSNF.js.map +1 -0
- package/dist/{chunk-KIVWAZKL.js → chunk-QJBVP2BS.js} +2 -2
- package/dist/{chunk-4MNRUPS5.js → chunk-QM65ELZE.js} +24 -3
- package/dist/chunk-QM65ELZE.js.map +1 -0
- package/dist/{chunk-LMHE4HDR.cjs → chunk-QOBWIFJA.cjs} +237 -97
- package/dist/chunk-QOBWIFJA.cjs.map +1 -0
- package/dist/{chunk-FOTG4MMD.js → chunk-REERG473.js} +6 -6
- package/dist/{chunk-57BKTVR5.js → chunk-SHYNOLL6.js} +2 -2
- package/dist/{chunk-IWC6PTMT.js → chunk-SI3GXM7Z.js} +2 -2
- package/dist/chunk-SJXTCW7I.cjs +122 -0
- package/dist/chunk-SJXTCW7I.cjs.map +1 -0
- package/dist/{chunk-LEUAWTMU.js → chunk-SUOJQHIN.js} +6 -6
- package/dist/{chunk-RQ4XTX4J.cjs → chunk-TOOOWCKQ.cjs} +98 -98
- package/dist/{chunk-RQ4XTX4J.cjs.map → chunk-TOOOWCKQ.cjs.map} +1 -1
- package/dist/{chunk-VKVDMH7X.js → chunk-TQ4QOCKT.js} +2 -1
- package/dist/chunk-TQ4QOCKT.js.map +1 -0
- package/dist/{chunk-VL43TUO6.js → chunk-UJ3TZF4Y.js} +2 -2
- package/dist/{chunk-U556XJW6.js → chunk-UN2F6EKQ.js} +2 -1
- package/dist/chunk-UN2F6EKQ.js.map +1 -0
- package/dist/{chunk-BKK2SMVM.cjs → chunk-VXHZPUMS.cjs} +2 -2
- package/dist/{chunk-BKK2SMVM.cjs.map → chunk-VXHZPUMS.cjs.map} +1 -1
- package/dist/{chunk-TGLXN6VH.js → chunk-WICMTKWR.js} +3 -3
- package/dist/{chunk-YLYSJSEP.js → chunk-WO6PZMMB.js} +2 -2
- package/dist/{chunk-Z5TDZDWU.js → chunk-WVUR3HYW.js} +48 -34
- package/dist/chunk-WVUR3HYW.js.map +1 -0
- package/dist/{chunk-WAFJUSUF.cjs → chunk-YFTD6WOP.cjs} +11 -8
- package/dist/chunk-YFTD6WOP.cjs.map +1 -0
- package/dist/chunks-QTVEFJOS.js +11 -0
- package/dist/cli.js +46 -45
- package/dist/cli.js.map +1 -1
- package/dist/{formula-V6CNOC4G.cjs → formula-7RJOEJHX.cjs} +9 -9
- package/dist/{formula-V6CNOC4G.cjs.map → formula-7RJOEJHX.cjs.map} +1 -1
- package/dist/{formula-W5MTLANP.js → formula-DUHNPES2.js} +4 -4
- package/dist/{formula-2BQBGPM2.js → formula-XNCKOV6K.js} +3 -3
- package/dist/generator-6BFIABTF.js +10 -0
- package/dist/generator-XJLIBYDJ.js +17 -0
- package/dist/generator-XXVCF6TG.cjs +11 -0
- package/dist/{generator-U2BRFTJ4.cjs.map → generator-XXVCF6TG.cjs.map} +1 -1
- package/dist/{hancom-MP7D7HWW.cjs → hancom-7F53R77A.cjs} +5 -5
- package/dist/{hancom-MP7D7HWW.cjs.map → hancom-7F53R77A.cjs.map} +1 -1
- package/dist/{hancom-7SU4XBXJ.js → hancom-D4E3WBPI.js} +2 -2
- package/dist/{hancom-RNJWH63M.js → hancom-IPF6HM5F.js} +2 -2
- package/dist/{image-ocr-2WSZULNO.js → image-ocr-NFCTNIL5.js} +7 -7
- package/dist/{image-ocr-COBRSG6O.js → image-ocr-PYOXD5K4.js} +10 -10
- package/dist/{image-ocr-MVOSHIY5.cjs → image-ocr-ZLAPJMES.cjs} +27 -27
- package/dist/{image-ocr-MVOSHIY5.cjs.map → image-ocr-ZLAPJMES.cjs.map} +1 -1
- package/dist/index.cjs +1518 -1504
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +42 -28
- package/dist/index.js.map +1 -1
- package/dist/mcp.js +37 -37
- package/dist/memo-CNW6ZJFE.js +17 -0
- package/dist/{model-bundle-LFLRW2SI.js → model-bundle-TIHWFIN5.js} +5 -5
- package/dist/{models-UGOWUUAL.js → models-YBHBEM6J.js} +5 -5
- package/dist/{parse-worker-v2-LCCTZWPT.js → parse-worker-v2-Q7ST3SDO.js} +24 -23
- package/dist/parse-worker-v2-Q7ST3SDO.js.map +1 -0
- package/dist/{parser-JAL2OOOL.js → parser-7JSQYNLS.js} +377 -36
- package/dist/parser-7JSQYNLS.js.map +1 -0
- package/dist/{parser-RE52HQXO.cjs → parser-A76QS3VJ.cjs} +668 -327
- package/dist/parser-A76QS3VJ.cjs.map +1 -0
- package/dist/{parser-J56FGU6P.js → parser-V25GYLBJ.js} +374 -33
- package/dist/parser-V25GYLBJ.js.map +1 -0
- package/dist/pdf-ocr-5YCDSSLG.cjs +42 -0
- package/dist/{pdf-ocr-5O336TCR.cjs.map → pdf-ocr-5YCDSSLG.cjs.map} +1 -1
- package/dist/{pdf-ocr-NQ3HAL77.js → pdf-ocr-GEAW23FB.js} +9 -9
- package/dist/{pdf-ocr-PQZZVFI5.js → pdf-ocr-IJXT6ZJR.js} +6 -6
- package/dist/{profile-io-K22CB2ZB.js → profile-io-Y7SMMS2R.js} +3 -3
- package/dist/{rasterize-A6B5K4QN.js → rasterize-MLEHT6PU.js} +3 -3
- package/dist/{redact-doc-TPXMML5Q.js → redact-doc-GPO2UTTJ.js} +22 -22
- package/dist/{render-ROFIMWW5.js → render-TNWY53S4.js} +13 -13
- package/dist/{rewrite-fallback-WG7Z3LR3.js → rewrite-fallback-AHGTN757.js} +14 -14
- package/dist/seal-7HBR3HBQ.js +16 -0
- package/dist/{setup-J5SHDFIE.js → setup-TJ57DQ6I.js} +3 -3
- package/dist/to-hwpx-6JF6Q2TZ.js +21 -0
- package/dist/{to-hwpx-X7JE6YJB.js → to-hwpx-DLVARUND.js} +5 -5
- package/dist/to-hwpx-XLQUY2L2.cjs +16 -0
- package/dist/{to-hwpx-RWDQB3T2.cjs.map → to-hwpx-XLQUY2L2.cjs.map} +1 -1
- package/dist/visual-VBDQUUKP.js +37 -0
- package/dist/{watch-WZBW6UE7.js → watch-6CHDQ355.js} +23 -23
- package/package.json +3 -2
- package/dist/chunk-4MNRUPS5.js.map +0 -1
- package/dist/chunk-A67OXFXM.js.map +0 -1
- package/dist/chunk-AYM7XTI2.js +0 -31
- package/dist/chunk-AYM7XTI2.js.map +0 -1
- package/dist/chunk-CQ33HCSU.js +0 -32
- package/dist/chunk-CQ33HCSU.js.map +0 -1
- package/dist/chunk-IPXFIH5E.js.map +0 -1
- package/dist/chunk-KSE5HSU3.js.map +0 -1
- package/dist/chunk-LMHE4HDR.cjs.map +0 -1
- package/dist/chunk-OAKJNKAS.js.map +0 -1
- package/dist/chunk-PM46GSMV.js.map +0 -1
- package/dist/chunk-U556XJW6.js.map +0 -1
- package/dist/chunk-UFY6XX4U.cjs.map +0 -1
- package/dist/chunk-VKVDMH7X.js.map +0 -1
- package/dist/chunk-WAFJUSUF.cjs.map +0 -1
- package/dist/chunk-WPLAEJU5.cjs +0 -31
- package/dist/chunk-WPLAEJU5.cjs.map +0 -1
- package/dist/chunk-X7RBVVDC.cjs.map +0 -1
- package/dist/chunk-Z5TDZDWU.js.map +0 -1
- package/dist/chunks-SHXTE5HM.js +0 -11
- package/dist/generator-E4VQKPRP.js +0 -10
- package/dist/generator-MBR4V3JQ.js +0 -17
- package/dist/generator-U2BRFTJ4.cjs +0 -11
- package/dist/memo-QJ5RKTBN.js +0 -17
- package/dist/parse-worker-v2-LCCTZWPT.js.map +0 -1
- package/dist/parser-J56FGU6P.js.map +0 -1
- package/dist/parser-JAL2OOOL.js.map +0 -1
- package/dist/parser-RE52HQXO.cjs.map +0 -1
- package/dist/pdf-ocr-5O336TCR.cjs +0 -42
- package/dist/seal-35U76WY2.js +0 -16
- package/dist/to-hwpx-RWDQB3T2.cjs +0 -16
- package/dist/to-hwpx-XQULU2I7.js +0 -21
- package/dist/visual-4HRP2VIH.js +0 -37
- /package/dist/{-PWMZE4CC.js.map → -3EMVBTE7.js.map} +0 -0
- /package/dist/{chunk-SUIH5LY7.js.map → chunk-3UY7ARXP.js.map} +0 -0
- /package/dist/{chunk-TN5ZK2WN.js.map → chunk-4N2ESXR2.js.map} +0 -0
- /package/dist/{chunk-2VXVBB5Q.js.map → chunk-6YUMHSBG.js.map} +0 -0
- /package/dist/{chunk-T5J4GW6B.js.map → chunk-7EL6BCO5.js.map} +0 -0
- /package/dist/{chunk-GRQXAWNW.js.map → chunk-7F5SKDUG.js.map} +0 -0
- /package/dist/{chunk-AB7MYMPZ.js.map → chunk-AC7FZDVP.js.map} +0 -0
- /package/dist/{chunk-HMD35PMD.js.map → chunk-D4TKVZKB.js.map} +0 -0
- /package/dist/{chunk-56FEGA44.js.map → chunk-E47LO7XG.js.map} +0 -0
- /package/dist/{chunk-BP5GDQBT.js.map → chunk-E5RJLP2S.js.map} +0 -0
- /package/dist/{chunk-AO3YFJVW.js.map → chunk-FQMPHPHE.js.map} +0 -0
- /package/dist/{chunk-MOWJOFIH.js.map → chunk-GFWCBYAI.js.map} +0 -0
- /package/dist/{chunk-SQ5Q4Q3R.js.map → chunk-HW3DZ7TY.js.map} +0 -0
- /package/dist/{chunk-Q3UCWUEV.js.map → chunk-JC2TMUU5.js.map} +0 -0
- /package/dist/{chunk-NYIJU4Q6.js.map → chunk-MYIRYP6D.js.map} +0 -0
- /package/dist/{chunk-FI7ULBC6.js.map → chunk-N6B5BINC.js.map} +0 -0
- /package/dist/{chunk-BO2IJGNZ.js.map → chunk-NLPIXQOV.js.map} +0 -0
- /package/dist/{chunk-HFQFCAEJ.js.map → chunk-OQPIN2OY.js.map} +0 -0
- /package/dist/{chunk-KIVWAZKL.js.map → chunk-QJBVP2BS.js.map} +0 -0
- /package/dist/{chunk-FOTG4MMD.js.map → chunk-REERG473.js.map} +0 -0
- /package/dist/{chunk-57BKTVR5.js.map → chunk-SHYNOLL6.js.map} +0 -0
- /package/dist/{chunk-IWC6PTMT.js.map → chunk-SI3GXM7Z.js.map} +0 -0
- /package/dist/{chunk-LEUAWTMU.js.map → chunk-SUOJQHIN.js.map} +0 -0
- /package/dist/{chunk-VL43TUO6.js.map → chunk-UJ3TZF4Y.js.map} +0 -0
- /package/dist/{chunk-TGLXN6VH.js.map → chunk-WICMTKWR.js.map} +0 -0
- /package/dist/{chunk-YLYSJSEP.js.map → chunk-WO6PZMMB.js.map} +0 -0
- /package/dist/{chunks-SHXTE5HM.js.map → chunks-QTVEFJOS.js.map} +0 -0
- /package/dist/{formula-W5MTLANP.js.map → formula-DUHNPES2.js.map} +0 -0
- /package/dist/{formula-2BQBGPM2.js.map → formula-XNCKOV6K.js.map} +0 -0
- /package/dist/{generator-E4VQKPRP.js.map → generator-6BFIABTF.js.map} +0 -0
- /package/dist/{generator-MBR4V3JQ.js.map → generator-XJLIBYDJ.js.map} +0 -0
- /package/dist/{hancom-7SU4XBXJ.js.map → hancom-D4E3WBPI.js.map} +0 -0
- /package/dist/{hancom-RNJWH63M.js.map → hancom-IPF6HM5F.js.map} +0 -0
- /package/dist/{image-ocr-2WSZULNO.js.map → image-ocr-NFCTNIL5.js.map} +0 -0
- /package/dist/{image-ocr-COBRSG6O.js.map → image-ocr-PYOXD5K4.js.map} +0 -0
- /package/dist/{memo-QJ5RKTBN.js.map → memo-CNW6ZJFE.js.map} +0 -0
- /package/dist/{model-bundle-LFLRW2SI.js.map → model-bundle-TIHWFIN5.js.map} +0 -0
- /package/dist/{models-UGOWUUAL.js.map → models-YBHBEM6J.js.map} +0 -0
- /package/dist/{pdf-ocr-NQ3HAL77.js.map → pdf-ocr-GEAW23FB.js.map} +0 -0
- /package/dist/{pdf-ocr-PQZZVFI5.js.map → pdf-ocr-IJXT6ZJR.js.map} +0 -0
- /package/dist/{profile-io-K22CB2ZB.js.map → profile-io-Y7SMMS2R.js.map} +0 -0
- /package/dist/{rasterize-A6B5K4QN.js.map → rasterize-MLEHT6PU.js.map} +0 -0
- /package/dist/{redact-doc-TPXMML5Q.js.map → redact-doc-GPO2UTTJ.js.map} +0 -0
- /package/dist/{render-ROFIMWW5.js.map → render-TNWY53S4.js.map} +0 -0
- /package/dist/{rewrite-fallback-WG7Z3LR3.js.map → rewrite-fallback-AHGTN757.js.map} +0 -0
- /package/dist/{seal-35U76WY2.js.map → seal-7HBR3HBQ.js.map} +0 -0
- /package/dist/{setup-J5SHDFIE.js.map → setup-TJ57DQ6I.js.map} +0 -0
- /package/dist/{to-hwpx-X7JE6YJB.js.map → to-hwpx-6JF6Q2TZ.js.map} +0 -0
- /package/dist/{to-hwpx-XQULU2I7.js.map → to-hwpx-DLVARUND.js.map} +0 -0
- /package/dist/{visual-4HRP2VIH.js.map → visual-VBDQUUKP.js.map} +0 -0
- /package/dist/{watch-WZBW6UE7.js.map → watch-6CHDQ355.js.map} +0 -0
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
QR_UNAVAILABLE,
|
|
4
|
+
blocksToPages,
|
|
5
|
+
loadQrReader
|
|
6
|
+
} from "./chunk-GOYAJVR6.js";
|
|
5
7
|
import {
|
|
6
8
|
encodePng
|
|
7
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-TQ4QOCKT.js";
|
|
8
10
|
import {
|
|
9
11
|
hasRequestedPagesAfter,
|
|
10
12
|
parsePageRange
|
|
@@ -62,7 +64,7 @@ import {
|
|
|
62
64
|
stripAbsorbedRunningLines,
|
|
63
65
|
trimTrailingEmptyTableCols,
|
|
64
66
|
wrapJoiner
|
|
65
|
-
} from "./chunk-
|
|
67
|
+
} from "./chunk-QM65ELZE.js";
|
|
66
68
|
import {
|
|
67
69
|
validateOcrOptions
|
|
68
70
|
} from "./chunk-IIOBUTXH.js";
|
|
@@ -75,12 +77,12 @@ import {
|
|
|
75
77
|
stripScriptTags,
|
|
76
78
|
toTex,
|
|
77
79
|
unframeLayoutTables
|
|
78
|
-
} from "./chunk-
|
|
80
|
+
} from "./chunk-OBNOOHAW.js";
|
|
79
81
|
import {
|
|
80
82
|
assignTableIds,
|
|
81
83
|
blocksToMarkdown,
|
|
82
84
|
escapeLiteralDollar
|
|
83
|
-
} from "./chunk-
|
|
85
|
+
} from "./chunk-MHLTZ3VI.js";
|
|
84
86
|
import {
|
|
85
87
|
WINGDINGS,
|
|
86
88
|
enclosedNumber,
|
|
@@ -91,16 +93,232 @@ import {
|
|
|
91
93
|
handwritingFallbackModels,
|
|
92
94
|
ocrModelsCached,
|
|
93
95
|
resolveOcrModels
|
|
94
|
-
} from "./chunk-
|
|
95
|
-
import "./chunk-
|
|
96
|
-
import "./chunk-
|
|
96
|
+
} from "./chunk-7EL6BCO5.js";
|
|
97
|
+
import "./chunk-OQPIN2OY.js";
|
|
98
|
+
import "./chunk-QJBVP2BS.js";
|
|
97
99
|
import {
|
|
98
100
|
KordocError,
|
|
99
101
|
sanitizeHref
|
|
100
|
-
} from "./chunk-
|
|
102
|
+
} from "./chunk-SHYNOLL6.js";
|
|
101
103
|
|
|
102
|
-
// src/pdf/image-
|
|
104
|
+
// src/pdf/image-blank.ts
|
|
103
105
|
import { createHash } from "crypto";
|
|
106
|
+
var SMALL_IMAGE_DIM = 128;
|
|
107
|
+
var NEAR = 64;
|
|
108
|
+
var isWordByte = (c) => c !== void 0 && (c === 95 || c >= 48 && c <= 57 || (c | 32) >= 97 && (c | 32) <= 122);
|
|
109
|
+
function blankLargeImageStreams(bytes) {
|
|
110
|
+
const blanked = { byRaw: /* @__PURE__ */ new Map(), sizes: /* @__PURE__ */ new Set() };
|
|
111
|
+
const buf = Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
112
|
+
const str = (a, b) => buf.toString("latin1", Math.max(0, a), Math.min(buf.length, b));
|
|
113
|
+
const each = function* (word) {
|
|
114
|
+
for (let i = buf.indexOf(word); i >= 0; i = buf.indexOf(word, i + 1)) if (!isWordByte(buf[i + word.length])) yield i;
|
|
115
|
+
};
|
|
116
|
+
if (!each("/Encrypt").next().done) return blanked;
|
|
117
|
+
const masks = /* @__PURE__ */ new Set();
|
|
118
|
+
for (const key of ["/SMask", "/Mask"]) {
|
|
119
|
+
for (const i of each(key)) {
|
|
120
|
+
const ref = /^\s+(\d+)\s+(\d+)\s+R\b/.exec(str(i + key.length, i + key.length + NEAR));
|
|
121
|
+
if (ref) masks.add(`${ref[1]} ${ref[2]}`);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
let lengths;
|
|
125
|
+
const dicts = /* @__PURE__ */ new Map();
|
|
126
|
+
let pos = 0;
|
|
127
|
+
for (; ; ) {
|
|
128
|
+
let at = buf.indexOf("obj", pos);
|
|
129
|
+
let m = null;
|
|
130
|
+
while (at >= 0 && (isWordByte(buf[at + 3]) || !(m = /(\d+)\s+(\d+)\s+$/.exec(str(Math.max(pos, at - NEAR), at))))) at = buf.indexOf("obj", at + 1);
|
|
131
|
+
if (at < 0 || !m) break;
|
|
132
|
+
pos = at + 3;
|
|
133
|
+
const head = buf.indexOf("stream", pos);
|
|
134
|
+
const end = buf.indexOf("endobj", pos);
|
|
135
|
+
if (head < 0 || end >= 0 && end < head) continue;
|
|
136
|
+
const dict = str(pos, head);
|
|
137
|
+
const dictStart = pos;
|
|
138
|
+
const start = head + 6 + (buf[head + 6] === 13 ? 2 : 1);
|
|
139
|
+
let length;
|
|
140
|
+
const direct = /\/Length\s+(\d+)\b(?!\s+\d+\s+R)/.exec(dict);
|
|
141
|
+
if (direct) length = Number(direct[1]);
|
|
142
|
+
else {
|
|
143
|
+
const ref = /\/Length\s+(\d+)\s+(\d+)\s+R\b/.exec(dict);
|
|
144
|
+
if (ref) {
|
|
145
|
+
lengths ??= indirectLengths();
|
|
146
|
+
length = lengths.get(`${ref[1]} ${ref[2]}`);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
const stop = length === void 0 ? -1 : start + length;
|
|
150
|
+
if (stop < 0 || !/^\s*endstream/.test(str(stop, stop + 16))) {
|
|
151
|
+
const e = buf.indexOf("endstream", start);
|
|
152
|
+
if (e < 0) break;
|
|
153
|
+
pos = e;
|
|
154
|
+
continue;
|
|
155
|
+
}
|
|
156
|
+
pos = stop;
|
|
157
|
+
if (!/\/Subtype\s*\/Image\b/.test(dict) || masks.has(`${m[1]} ${m[2]}`) || /\/(?:SMask|Mask|SMaskInData)\b/.test(dict) || /\/(?:ImageMask|IM)\s+true\b/.test(dict)) continue;
|
|
158
|
+
const w = /\/Width\s+(\d+)\b(?!\s+\d+\s+R)/.exec(dict), h = /\/Height\s+(\d+)\b(?!\s+\d+\s+R)/.exec(dict);
|
|
159
|
+
if (!w || !h || Number(w[1]) <= SMALL_IMAGE_DIM && Number(h[1]) <= SMALL_IMAGE_DIM) continue;
|
|
160
|
+
const bpcs = [...dict.matchAll(/\/BitsPerComponent\s+(\d+)\b(?!\s+\d+\s+R)/g)];
|
|
161
|
+
if (bpcs.length !== 1 || (dict.match(/\/BitsPerComponent\b/g) ?? []).length !== 1) continue;
|
|
162
|
+
const bpc = bpcs[0];
|
|
163
|
+
const digits = dictStart + bpc.index + bpc[0].length - bpc[1].length;
|
|
164
|
+
bytes.fill(32, digits, digits + bpc[1].length - 1);
|
|
165
|
+
bytes[digits + bpc[1].length - 1] = 48;
|
|
166
|
+
const data = bytes.subarray(start, stop);
|
|
167
|
+
const raw = createHash("sha1").update(data).digest("hex");
|
|
168
|
+
const shape = dict.replace(/\s+/g, " ").trim();
|
|
169
|
+
blanked.byRaw.set(raw, (blanked.byRaw.get(raw) ?? true) && (dicts.get(raw) ?? shape) === shape);
|
|
170
|
+
blanked.sizes.add(`${w[1]}x${h[1]}`);
|
|
171
|
+
dicts.set(raw, shape);
|
|
172
|
+
data.fill(0);
|
|
173
|
+
}
|
|
174
|
+
return blanked;
|
|
175
|
+
function indirectLengths() {
|
|
176
|
+
const found = /* @__PURE__ */ new Map();
|
|
177
|
+
for (let i = buf.indexOf("obj"); i >= 0; i = buf.indexOf("obj", i + 1)) {
|
|
178
|
+
const num = /(\d+)\s+(\d+)\s+$/.exec(str(i - NEAR, i));
|
|
179
|
+
const value = num && /^\s*(\d+)\s*endobj/.exec(str(i + 3, i + 3 + NEAR));
|
|
180
|
+
if (value) found.set(`${num[1]} ${num[2]}`, Number(value[1]));
|
|
181
|
+
}
|
|
182
|
+
return found;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// src/pdf/pdfium-images.ts
|
|
187
|
+
import { createHash as createHash2 } from "crypto";
|
|
188
|
+
var IMAGE_OBJECT = 3;
|
|
189
|
+
var FORM_OBJECT = 5;
|
|
190
|
+
function hasPdfiumFunctions(m) {
|
|
191
|
+
const fns = [
|
|
192
|
+
"_FPDF_LoadPage",
|
|
193
|
+
"_FPDF_ClosePage",
|
|
194
|
+
"_FPDFPage_CountObjects",
|
|
195
|
+
"_FPDFPage_GetObject",
|
|
196
|
+
"_FPDFPageObj_GetType",
|
|
197
|
+
"_FPDFFormObj_CountObjects",
|
|
198
|
+
"_FPDFFormObj_GetObject",
|
|
199
|
+
"_FPDFPage_GetAnnotCount",
|
|
200
|
+
"_FPDFPage_GetAnnot",
|
|
201
|
+
"_FPDFPage_CloseAnnot",
|
|
202
|
+
"_FPDFAnnot_GetObjectCount",
|
|
203
|
+
"_FPDFAnnot_GetObject",
|
|
204
|
+
"_FPDFImageObj_GetImagePixelSize",
|
|
205
|
+
"_FPDFImageObj_GetImageDataRaw",
|
|
206
|
+
"_FPDFImageObj_GetBitmap",
|
|
207
|
+
"_FPDFBitmap_GetBuffer",
|
|
208
|
+
"_FPDFBitmap_GetWidth",
|
|
209
|
+
"_FPDFBitmap_GetHeight",
|
|
210
|
+
"_FPDFBitmap_GetStride",
|
|
211
|
+
"_FPDFBitmap_GetFormat",
|
|
212
|
+
"_FPDFBitmap_Destroy"
|
|
213
|
+
];
|
|
214
|
+
return fns.every((f) => typeof m[f] === "function") && typeof m.wasmExports?.malloc === "function" && typeof m.wasmExports.free === "function" && m.HEAPU8 instanceof Uint8Array && m.HEAPU32 instanceof Uint32Array;
|
|
215
|
+
}
|
|
216
|
+
async function openPdfiumImages(buffer, blanked) {
|
|
217
|
+
const mod = await import("@hyzyla/pdfium").catch(() => null);
|
|
218
|
+
if (!mod) return null;
|
|
219
|
+
const lib = await mod.PDFiumLibrary.init().catch(() => null);
|
|
220
|
+
if (!lib) return null;
|
|
221
|
+
const doc = await lib.loadDocument(new Uint8Array(buffer)).catch(() => null);
|
|
222
|
+
if (!doc) {
|
|
223
|
+
lib.destroy();
|
|
224
|
+
return null;
|
|
225
|
+
}
|
|
226
|
+
const m = lib.module;
|
|
227
|
+
const docHandle = doc.documentIdx;
|
|
228
|
+
if (!m || typeof docHandle !== "number" || !hasPdfiumFunctions(m)) {
|
|
229
|
+
doc.destroy();
|
|
230
|
+
lib.destroy();
|
|
231
|
+
return null;
|
|
232
|
+
}
|
|
233
|
+
let open = null;
|
|
234
|
+
const closePage = () => {
|
|
235
|
+
if (!open) return;
|
|
236
|
+
for (const a of open.annots) m._FPDFPage_CloseAnnot(a);
|
|
237
|
+
m._FPDF_ClosePage(open.page);
|
|
238
|
+
open = null;
|
|
239
|
+
};
|
|
240
|
+
const pixelSize = (obj) => {
|
|
241
|
+
const p = m.wasmExports.malloc(8);
|
|
242
|
+
const ok = m._FPDFImageObj_GetImagePixelSize(obj, p, p + 4);
|
|
243
|
+
const size = ok ? [m.HEAPU32[p >> 2], m.HEAPU32[(p >> 2) + 1]] : [0, 0];
|
|
244
|
+
m.wasmExports.free(p);
|
|
245
|
+
return size;
|
|
246
|
+
};
|
|
247
|
+
const rawHash = (obj) => {
|
|
248
|
+
const n = m._FPDFImageObj_GetImageDataRaw(obj, 0, 0);
|
|
249
|
+
if (!n) return "";
|
|
250
|
+
const p = m.wasmExports.malloc(n);
|
|
251
|
+
m._FPDFImageObj_GetImageDataRaw(obj, p, n);
|
|
252
|
+
const hash = createHash2("sha1").update(m.HEAPU8.subarray(p, p + n)).digest("hex");
|
|
253
|
+
m.wasmExports.free(p);
|
|
254
|
+
return hash;
|
|
255
|
+
};
|
|
256
|
+
return {
|
|
257
|
+
page(pageNumber) {
|
|
258
|
+
closePage();
|
|
259
|
+
const page = m._FPDF_LoadPage(docHandle, pageNumber - 1);
|
|
260
|
+
if (!page) return [];
|
|
261
|
+
open = { page, annots: [] };
|
|
262
|
+
const out = [];
|
|
263
|
+
const walk = (count, get, depth) => {
|
|
264
|
+
for (let i = 0; i < count; i++) {
|
|
265
|
+
const obj = get(i);
|
|
266
|
+
const type = m._FPDFPageObj_GetType(obj);
|
|
267
|
+
if (type === FORM_OBJECT && depth < 32) walk(m._FPDFFormObj_CountObjects(obj), (j) => m._FPDFFormObj_GetObject(obj, j), depth + 1);
|
|
268
|
+
if (type !== IMAGE_OBJECT) continue;
|
|
269
|
+
const [width, height] = pixelSize(obj);
|
|
270
|
+
if (width <= SMALL_IMAGE_DIM && height <= SMALL_IMAGE_DIM) continue;
|
|
271
|
+
const raw = rawHash(obj);
|
|
272
|
+
out.push({ width, height, raw, blanked: blanked.byRaw.has(raw), sameRawSamePixels: blanked.byRaw.get(raw) === true, handle: obj });
|
|
273
|
+
}
|
|
274
|
+
};
|
|
275
|
+
walk(m._FPDFPage_CountObjects(page), (i) => m._FPDFPage_GetObject(page, i), 0);
|
|
276
|
+
for (let i = 0; i < m._FPDFPage_GetAnnotCount(page); i++) {
|
|
277
|
+
const annot = m._FPDFPage_GetAnnot(page, i);
|
|
278
|
+
if (!annot) continue;
|
|
279
|
+
open.annots.push(annot);
|
|
280
|
+
walk(m._FPDFAnnot_GetObjectCount(annot), (j) => m._FPDFAnnot_GetObject(annot, j), 0);
|
|
281
|
+
}
|
|
282
|
+
return out;
|
|
283
|
+
},
|
|
284
|
+
decode(image) {
|
|
285
|
+
const bitmap = m._FPDFImageObj_GetBitmap(image.handle);
|
|
286
|
+
if (!bitmap) return null;
|
|
287
|
+
try {
|
|
288
|
+
const w = m._FPDFBitmap_GetWidth(bitmap), h = m._FPDFBitmap_GetHeight(bitmap);
|
|
289
|
+
const stride = m._FPDFBitmap_GetStride(bitmap), format = m._FPDFBitmap_GetFormat(bitmap);
|
|
290
|
+
const bpp = format === 1 ? 1 : format === 2 ? 3 : format === 3 || format === 4 ? 4 : 0;
|
|
291
|
+
if (!bpp || w !== image.width || h !== image.height) return null;
|
|
292
|
+
const src = m.HEAPU8, base = m._FPDFBitmap_GetBuffer(bitmap);
|
|
293
|
+
const rgba = new Uint8Array(w * h * 4);
|
|
294
|
+
for (let y = 0; y < h; y++) {
|
|
295
|
+
for (let x = 0, s = base + y * stride, d = y * w * 4; x < w; x++, s += bpp, d += 4) {
|
|
296
|
+
if (bpp === 1) {
|
|
297
|
+
rgba[d] = rgba[d + 1] = rgba[d + 2] = src[s];
|
|
298
|
+
rgba[d + 3] = 255;
|
|
299
|
+
continue;
|
|
300
|
+
}
|
|
301
|
+
rgba[d] = src[s + 2];
|
|
302
|
+
rgba[d + 1] = src[s + 1];
|
|
303
|
+
rgba[d + 2] = src[s];
|
|
304
|
+
rgba[d + 3] = format === 4 ? src[s + 3] : 255;
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
return rgba;
|
|
308
|
+
} finally {
|
|
309
|
+
m._FPDFBitmap_Destroy(bitmap);
|
|
310
|
+
}
|
|
311
|
+
},
|
|
312
|
+
close() {
|
|
313
|
+
closePage();
|
|
314
|
+
doc.destroy();
|
|
315
|
+
lib.destroy();
|
|
316
|
+
}
|
|
317
|
+
};
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
// src/pdf/image-extract.ts
|
|
321
|
+
import { createHash as createHash3 } from "crypto";
|
|
104
322
|
import { OPS, ImageKind } from "pdfjs-dist/legacy/build/pdf.mjs";
|
|
105
323
|
var IMAGE_RESOLVE_TIMEOUT_MS = 5e3;
|
|
106
324
|
function resolveImgData(page, objId) {
|
|
@@ -134,11 +352,11 @@ var MIN_DIM = 8;
|
|
|
134
352
|
var MAX_PIXELS = 36e6;
|
|
135
353
|
var MAX_IMAGES_PER_DOC = 200;
|
|
136
354
|
var MAX_TOTAL_IMAGE_BYTES = 128 * 1024 * 1024;
|
|
137
|
-
function createPdfImageState() {
|
|
138
|
-
return { imageIndex: 0, totalBytes: 0, seen: /* @__PURE__ */ new Map(), globalKeys: /* @__PURE__ */ new Map(), capWarned: false };
|
|
355
|
+
function createPdfImageState(blanked) {
|
|
356
|
+
return { imageIndex: 0, totalBytes: 0, seen: /* @__PURE__ */ new Map(), globalKeys: /* @__PURE__ */ new Map(), capWarned: false, blanked, rawKeys: /* @__PURE__ */ new Map(), pdfiumGlobal: /* @__PURE__ */ new Map() };
|
|
139
357
|
}
|
|
140
358
|
function contentHash(data) {
|
|
141
|
-
return
|
|
359
|
+
return createHash3("sha1").update(data).digest("hex");
|
|
142
360
|
}
|
|
143
361
|
var NO_BYTES = new Uint8Array(0);
|
|
144
362
|
function toRgba(img, convert = true) {
|
|
@@ -183,30 +401,88 @@ function toRgba(img, convert = true) {
|
|
|
183
401
|
}
|
|
184
402
|
return null;
|
|
185
403
|
}
|
|
186
|
-
async function extractPageImages(page, fnArray, argsArray, pageNumber, state, warnings, withBytes = true) {
|
|
404
|
+
async function extractPageImages(page, fnArray, argsArray, pageNumber, state, warnings, withBytes = true, readQr) {
|
|
187
405
|
const blocks = [];
|
|
188
406
|
const images = [];
|
|
189
407
|
const pageSeenIds = /* @__PURE__ */ new Set();
|
|
408
|
+
let pdfiumQueue;
|
|
409
|
+
let unpairedSizes;
|
|
410
|
+
const pdfiumById = /* @__PURE__ */ new Map();
|
|
411
|
+
const takePdfium = (match) => {
|
|
412
|
+
const k = pdfiumQueue.findIndex(match);
|
|
413
|
+
return k < 0 ? void 0 : pdfiumQueue.splice(k, 1)[0];
|
|
414
|
+
};
|
|
415
|
+
const reusedRaws = [];
|
|
416
|
+
const consume = (raw) => {
|
|
417
|
+
if (pdfiumQueue) takePdfium((x) => x.raw === raw);
|
|
418
|
+
else reusedRaws.push(raw);
|
|
419
|
+
};
|
|
420
|
+
const pairable = (w, h) => {
|
|
421
|
+
if (!pdfiumQueue) {
|
|
422
|
+
pdfiumQueue = state.blanked.decoder.page(pageNumber);
|
|
423
|
+
unpairedSizes = pairingCounts(fnArray, argsArray, pdfiumQueue);
|
|
424
|
+
for (const raw of reusedRaws) takePdfium((x) => x.raw === raw);
|
|
425
|
+
}
|
|
426
|
+
return w !== void 0 && !unpairedSizes.has(`${w}x${h}`) && !unpairedSizes.has("repeat");
|
|
427
|
+
};
|
|
428
|
+
let pristine;
|
|
429
|
+
let paintIndex = -1;
|
|
190
430
|
for (let i = 0; i < fnArray.length; i++) {
|
|
191
431
|
const op = fnArray[i];
|
|
192
432
|
let imgData = null;
|
|
193
433
|
let dedupeId = null;
|
|
434
|
+
let fromPristine = false;
|
|
194
435
|
if (op === OPS.paintImageXObject || op === OPS.paintImageXObjectRepeat) {
|
|
436
|
+
paintIndex++;
|
|
437
|
+
const paints = op === OPS.paintImageXObjectRepeat ? (argsArray[i]?.[3]?.length ?? 2) / 2 : 1;
|
|
195
438
|
const objId = argsArray[i]?.[0];
|
|
196
|
-
if (typeof objId !== "string"
|
|
439
|
+
if (typeof objId !== "string") continue;
|
|
440
|
+
if (pageSeenIds.has(objId)) {
|
|
441
|
+
const first = pdfiumById.get(objId);
|
|
442
|
+
if (first) for (let k = 0; k < paints; k++) consume(first.raw);
|
|
443
|
+
continue;
|
|
444
|
+
}
|
|
445
|
+
if (capReached(state, pageNumber, warnings)) continue;
|
|
446
|
+
if (state.blanked) {
|
|
447
|
+
const w2 = op === OPS.paintImageXObject ? argsArray[i]?.[1] : void 0;
|
|
448
|
+
const h2 = op === OPS.paintImageXObject ? argsArray[i]?.[2] : void 0;
|
|
449
|
+
const large = w2 === void 0 || h2 === void 0 || w2 > SMALL_IMAGE_DIM || h2 > SMALL_IMAGE_DIM;
|
|
450
|
+
const known = state.pdfiumGlobal.get(objId);
|
|
451
|
+
const reuse = known && (!known.blanked || known.sameRawSamePixels && state.rawKeys.has(known.raw));
|
|
452
|
+
let image;
|
|
453
|
+
if (reuse) {
|
|
454
|
+
image = known;
|
|
455
|
+
for (let k = 0; k < paints; k++) consume(known.raw);
|
|
456
|
+
} else {
|
|
457
|
+
image = large && pairable(w2, h2) ? takePdfium((x) => x.width === w2 && x.height === h2) ?? null : null;
|
|
458
|
+
if (image) for (let k = 1; k < paints; k++) consume(image.raw);
|
|
459
|
+
if (image && objId.startsWith("g_")) state.pdfiumGlobal.set(objId, image);
|
|
460
|
+
}
|
|
461
|
+
pdfiumById.set(objId, image);
|
|
462
|
+
const block = image?.blanked ? await extractPdfiumImage(image, pageNumber, state, warnings, withBytes, images, readQr) : UNDECODED;
|
|
463
|
+
if (block !== UNDECODED) {
|
|
464
|
+
pageSeenIds.add(objId);
|
|
465
|
+
if (block) blocks.push(block);
|
|
466
|
+
continue;
|
|
467
|
+
}
|
|
468
|
+
fromPristine = large && (!!image?.blanked || !image && (w2 === void 0 || state.blanked.sizes.has(`${w2}x${h2}`)));
|
|
469
|
+
}
|
|
197
470
|
pageSeenIds.add(objId);
|
|
198
471
|
dedupeId = objId;
|
|
199
472
|
} else if (op !== OPS.paintInlineImageXObject) {
|
|
200
473
|
continue;
|
|
201
474
|
}
|
|
202
|
-
if (state
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
475
|
+
if (capReached(state, pageNumber, warnings)) continue;
|
|
476
|
+
if (fromPristine) {
|
|
477
|
+
if (!pristine) {
|
|
478
|
+
const p = await (await state.blanked.pristine()).getPage(pageNumber);
|
|
479
|
+
const ops = await p.getOperatorList();
|
|
480
|
+
pristine = { page: p, ids: paintImageIds(ops.fnArray, ops.argsArray) };
|
|
206
481
|
}
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
482
|
+
dedupeId = pristine.ids[paintIndex];
|
|
483
|
+
if (typeof dedupeId !== "string") continue;
|
|
484
|
+
imgData = await resolveImgData(pristine.page, dedupeId);
|
|
485
|
+
} else if (dedupeId) {
|
|
210
486
|
imgData = await resolveImgData(page, dedupeId);
|
|
211
487
|
} else {
|
|
212
488
|
imgData = argsArray[i]?.[0];
|
|
@@ -225,7 +501,7 @@ async function extractPageImages(page, fnArray, argsArray, pageNumber, state, wa
|
|
|
225
501
|
if (globalId) state.globalKeys.set(globalId, hash);
|
|
226
502
|
}
|
|
227
503
|
if (state.seen.has(hash)) continue;
|
|
228
|
-
const rgba = toRgba(imgData, withBytes);
|
|
504
|
+
const rgba = toRgba(imgData, withBytes || !!readQr);
|
|
229
505
|
if (!rgba) continue;
|
|
230
506
|
state.imageIndex++;
|
|
231
507
|
const filename = `image_${String(state.imageIndex).padStart(3, "0")}.png`;
|
|
@@ -235,10 +511,63 @@ async function extractPageImages(page, fnArray, argsArray, pageNumber, state, wa
|
|
|
235
511
|
state.totalBytes += png.length;
|
|
236
512
|
images.push({ filename, data: png, mimeType: "image/png" });
|
|
237
513
|
}
|
|
238
|
-
|
|
514
|
+
const qr = readQr ? await readQr({ data: rgba, width: w, height: h }) : [];
|
|
515
|
+
blocks.push({ type: "image", text: filename, pageNumber, ...qr.length ? { qr } : {} });
|
|
239
516
|
}
|
|
517
|
+
pristine?.page.cleanup();
|
|
240
518
|
return { blocks, images };
|
|
241
519
|
}
|
|
520
|
+
function paintImageIds(fnArray, argsArray) {
|
|
521
|
+
const ids = [];
|
|
522
|
+
for (let i = 0; i < fnArray.length; i++) if (fnArray[i] === OPS.paintImageXObject || fnArray[i] === OPS.paintImageXObjectRepeat) ids.push(argsArray[i]?.[0]);
|
|
523
|
+
return ids;
|
|
524
|
+
}
|
|
525
|
+
function pairingCounts(fnArray, argsArray, pdfium) {
|
|
526
|
+
const count = /* @__PURE__ */ new Map();
|
|
527
|
+
const unpaired = /* @__PURE__ */ new Set();
|
|
528
|
+
for (let i = 0; i < fnArray.length; i++) {
|
|
529
|
+
if (fnArray[i] === OPS.paintImageXObjectRepeat) unpaired.add("repeat");
|
|
530
|
+
if (fnArray[i] !== OPS.paintImageXObject) continue;
|
|
531
|
+
const w = argsArray[i]?.[1], h = argsArray[i]?.[2];
|
|
532
|
+
if (w > SMALL_IMAGE_DIM || h > SMALL_IMAGE_DIM) count.set(`${w}x${h}`, (count.get(`${w}x${h}`) ?? 0) + 1);
|
|
533
|
+
}
|
|
534
|
+
for (const x of pdfium) count.set(`${x.width}x${x.height}`, (count.get(`${x.width}x${x.height}`) ?? 0) - 1);
|
|
535
|
+
for (const [size, n] of count) if (n !== 0) unpaired.add(size);
|
|
536
|
+
return unpaired;
|
|
537
|
+
}
|
|
538
|
+
function capReached(state, pageNumber, warnings) {
|
|
539
|
+
if (state.imageIndex < MAX_IMAGES_PER_DOC && state.totalBytes < MAX_TOTAL_IMAGE_BYTES) return false;
|
|
540
|
+
if (!state.capWarned) {
|
|
541
|
+
state.capWarned = true;
|
|
542
|
+
warnings.push({ page: pageNumber, message: `\uC774\uBBF8\uC9C0 \uCD94\uCD9C \uC0C1\uD55C \uB3C4\uB2EC (${MAX_IMAGES_PER_DOC}\uAC1C/128MB) \u2014 \uC774\uD6C4 \uC774\uBBF8\uC9C0 \uC0DD\uB7B5`, code: "SKIPPED_IMAGE" });
|
|
543
|
+
}
|
|
544
|
+
return true;
|
|
545
|
+
}
|
|
546
|
+
var UNDECODED = /* @__PURE__ */ Symbol("undecoded");
|
|
547
|
+
async function extractPdfiumImage(image, pageNumber, state, warnings, withBytes, images, readQr) {
|
|
548
|
+
const { width: w, height: h } = image;
|
|
549
|
+
if (w < MIN_DIM || h < MIN_DIM) return null;
|
|
550
|
+
if (w * h > MAX_PIXELS) {
|
|
551
|
+
warnings.push({ page: pageNumber, message: `\uC774\uBBF8\uC9C0 \uD06C\uAE30 \uCD08\uACFC\uB85C \uCD94\uCD9C \uC0DD\uB7B5 (${w}\xD7${h})`, code: "SKIPPED_IMAGE" });
|
|
552
|
+
return null;
|
|
553
|
+
}
|
|
554
|
+
if (image.sameRawSamePixels && state.rawKeys.has(image.raw)) return null;
|
|
555
|
+
const rgba = state.blanked.decoder.decode(image);
|
|
556
|
+
if (!rgba) return UNDECODED;
|
|
557
|
+
const hash = `${w}x${h}kPh${contentHash(rgba)}`;
|
|
558
|
+
state.rawKeys.set(image.raw, hash);
|
|
559
|
+
if (state.seen.has(hash)) return null;
|
|
560
|
+
state.imageIndex++;
|
|
561
|
+
const filename = `image_${String(state.imageIndex).padStart(3, "0")}.png`;
|
|
562
|
+
state.seen.set(hash, filename);
|
|
563
|
+
if (withBytes) {
|
|
564
|
+
const png = encodePng(w, h, rgba);
|
|
565
|
+
state.totalBytes += png.length;
|
|
566
|
+
images.push({ filename, data: png, mimeType: "image/png" });
|
|
567
|
+
}
|
|
568
|
+
const qr = readQr ? await readQr({ data: rgba, width: w, height: h }) : [];
|
|
569
|
+
return { type: "image", text: filename, pageNumber, ...qr.length ? { qr } : {} };
|
|
570
|
+
}
|
|
242
571
|
function injectPageImageBlocks(blocks, pageImages) {
|
|
243
572
|
if (pageImages.size === 0) return;
|
|
244
573
|
const lastIndexForPage = /* @__PURE__ */ new Map();
|
|
@@ -2036,7 +2365,7 @@ function fillNestedContinuation(blocks, at) {
|
|
|
2036
2365
|
import { OPS as OPS3 } from "pdfjs-dist/legacy/build/pdf.mjs";
|
|
2037
2366
|
|
|
2038
2367
|
// src/pdf/known-font-glyphs.ts
|
|
2039
|
-
import { createHash as
|
|
2368
|
+
import { createHash as createHash4 } from "crypto";
|
|
2040
2369
|
var FACES = {
|
|
2041
2370
|
"HCRDotum": 1,
|
|
2042
2371
|
"HCRDotum-Bold": 2,
|
|
@@ -2440,7 +2769,7 @@ var KNOWN = {
|
|
|
2440
2769
|
function knownFontPua(name, outline, width) {
|
|
2441
2770
|
const face = FACES[name?.replace(/^[A-Z]{6}\+/, "") ?? ""];
|
|
2442
2771
|
if (!face) return null;
|
|
2443
|
-
const hit = KNOWN[
|
|
2772
|
+
const hit = KNOWN[createHash4("sha256").update(JSON.stringify([outline.upm, width, outline.contours])).digest("hex").slice(0, 16)];
|
|
2444
2773
|
return hit && hit[1] & face ? hit[0] : null;
|
|
2445
2774
|
}
|
|
2446
2775
|
|
|
@@ -4294,7 +4623,7 @@ function mergeLinkRuns(markdown) {
|
|
|
4294
4623
|
|
|
4295
4624
|
// src/pdf/formula-ocr.ts
|
|
4296
4625
|
async function applyFormulaOcr(buffer, blocks, pageFilter, effectivePageCount, warnings, _onProgress) {
|
|
4297
|
-
const formulaMod = await import("./formula-
|
|
4626
|
+
const formulaMod = await import("./formula-DUHNPES2.js");
|
|
4298
4627
|
const { FormulaPipeline, ensureFormulaModels } = formulaMod;
|
|
4299
4628
|
await ensureFormulaModels((p) => {
|
|
4300
4629
|
if (p.phase === "download" && p.total) {
|
|
@@ -4475,10 +4804,10 @@ var PDFJS_DOCUMENT_OPTIONS = {
|
|
|
4475
4804
|
// 오류만 — 경고("Warning: Indexing all PDF objects")를 console.log 로 stdout 에 찍어 MCP·CLI JSON 을 깼다
|
|
4476
4805
|
...pdfjsAssets
|
|
4477
4806
|
};
|
|
4478
|
-
async function loadPdfWithTimeout(buffer) {
|
|
4807
|
+
async function loadPdfWithTimeout(buffer, data) {
|
|
4479
4808
|
const loadingTask = getDocument({
|
|
4480
4809
|
// pdfjs transfers its input to the worker; retain the caller's buffer for reuse.
|
|
4481
|
-
data: new Uint8Array(buffer.slice(0)),
|
|
4810
|
+
data: data ?? new Uint8Array(buffer.slice(0)),
|
|
4482
4811
|
...PDFJS_DOCUMENT_OPTIONS
|
|
4483
4812
|
});
|
|
4484
4813
|
let timer;
|
|
@@ -4505,7 +4834,14 @@ async function parsePdfDocument(buffer, options) {
|
|
|
4505
4834
|
if (ocrOptionError) throw new KordocError(ocrOptionError);
|
|
4506
4835
|
const autoOcr = options?.ocr === void 0 && await ocrModelsCached(resolveOcrModels(options)) && (options?.ocrRec !== "auto" || await ocrModelsCached(handwritingFallbackModels(resolveOcrModels(options))));
|
|
4507
4836
|
const ocrBuffer = options?.ocr || autoOcr ? buffer : null;
|
|
4508
|
-
const
|
|
4837
|
+
const pdfjsData = new Uint8Array(buffer.slice(0));
|
|
4838
|
+
const blanked = blankLargeImageStreams(pdfjsData);
|
|
4839
|
+
const pdfium = blanked.byRaw.size > 0 ? await openPdfiumImages(buffer, blanked) : null;
|
|
4840
|
+
const doc = await loadPdfWithTimeout(buffer, blanked.byRaw.size === 0 || pdfium ? pdfjsData : void 0).catch((e) => {
|
|
4841
|
+
pdfium?.close();
|
|
4842
|
+
throw e;
|
|
4843
|
+
});
|
|
4844
|
+
let pristine;
|
|
4509
4845
|
try {
|
|
4510
4846
|
const pageCount = doc.numPages;
|
|
4511
4847
|
if (pageCount === 0) throw new KordocError("PDF\uC5D0 \uD398\uC774\uC9C0\uAC00 \uC5C6\uC2B5\uB2C8\uB2E4.");
|
|
@@ -4530,7 +4866,9 @@ async function parsePdfDocument(buffer, options) {
|
|
|
4530
4866
|
const skippedImagePages = /* @__PURE__ */ new Map();
|
|
4531
4867
|
const uncoveredImageRegions = /* @__PURE__ */ new Map();
|
|
4532
4868
|
const largeImageRegions = /* @__PURE__ */ new Set();
|
|
4533
|
-
const imageState = createPdfImageState();
|
|
4869
|
+
const imageState = createPdfImageState(pdfium ? { decoder: pdfium, sizes: blanked.sizes, pristine: () => pristine ??= loadPdfWithTimeout(buffer) } : void 0);
|
|
4870
|
+
const readQr = options?.qrCodes ? await loadQrReader() : null;
|
|
4871
|
+
if (options?.qrCodes && !readQr) warnings.push(QR_UNAVAILABLE);
|
|
4534
4872
|
const imageBulletShapes = /* @__PURE__ */ new Map();
|
|
4535
4873
|
const imageArrowDirections = /* @__PURE__ */ new Map();
|
|
4536
4874
|
const extractedImages = [];
|
|
@@ -4674,7 +5012,7 @@ async function parsePdfDocument(buffer, options) {
|
|
|
4674
5012
|
if (stamp.length) pageBlocks.unshift({ type: "paragraph", text: [...stamp].sort((a, b) => a.y - b.y).map((it) => it.text).join(" "), pageNumber: i });
|
|
4675
5013
|
for (const b of pageBlocks) blocks.push(b);
|
|
4676
5014
|
try {
|
|
4677
|
-
const { blocks: imgBlocks, images: pageImages } = await extractPageImages(page, opList.fnArray, opList.argsArray, i, imageState, warnings, options?.images !== false);
|
|
5015
|
+
const { blocks: imgBlocks, images: pageImages } = await extractPageImages(page, opList.fnArray, opList.argsArray, i, imageState, warnings, options?.images !== false, readQr ?? void 0);
|
|
4678
5016
|
if (imgBlocks.length > 0) pageImageBlocks.set(i, imgBlocks);
|
|
4679
5017
|
extractedImages.push(...pageImages);
|
|
4680
5018
|
} catch {
|
|
@@ -4731,10 +5069,10 @@ async function parsePdfDocument(buffer, options) {
|
|
|
4731
5069
|
}
|
|
4732
5070
|
if (targets.size > 0) {
|
|
4733
5071
|
try {
|
|
4734
|
-
const { runPdfOcr } = await import("./pdf-ocr-
|
|
5072
|
+
const { runPdfOcr } = await import("./pdf-ocr-GEAW23FB.js");
|
|
4735
5073
|
const mode = typeof options?.ocr === "function" ? options.ocr : "builtin";
|
|
4736
5074
|
const regionPages = new Map([...ocrRegions].filter(([p]) => options?.ocr !== "force" && !isImageBased && !pageQuality.find((q) => q.page === p)?.needsOcr));
|
|
4737
|
-
const { builtinOcrConfig } = await import("./pdf-ocr-
|
|
5075
|
+
const { builtinOcrConfig } = await import("./pdf-ocr-GEAW23FB.js");
|
|
4738
5076
|
const ocrPageBlocks = await runPdfOcr(ocrBuffer, targets, mode, warnings, options?.onProgress, options?.tables !== false, vectorPageOps, regionPages, builtinOcrConfig(options), ocrLinesOut);
|
|
4739
5077
|
for (const obs of ocrPageBlocks.values()) stripScriptTags({ blocks: obs });
|
|
4740
5078
|
if (ocrPageBlocks.size > 0) {
|
|
@@ -4912,6 +5250,9 @@ async function parsePdfDocument(buffer, options) {
|
|
|
4912
5250
|
} finally {
|
|
4913
5251
|
await doc.destroy().catch(() => {
|
|
4914
5252
|
});
|
|
5253
|
+
pdfium?.close();
|
|
5254
|
+
await pristine?.then((d) => d.destroy()).catch(() => {
|
|
5255
|
+
});
|
|
4915
5256
|
}
|
|
4916
5257
|
}
|
|
4917
5258
|
async function extractPdfMetadata(doc, metadata) {
|
|
@@ -4979,4 +5320,4 @@ export {
|
|
|
4979
5320
|
parsePdfDocument,
|
|
4980
5321
|
removeHeaderFooterBlocks
|
|
4981
5322
|
};
|
|
4982
|
-
//# sourceMappingURL=parser-
|
|
5323
|
+
//# sourceMappingURL=parser-7JSQYNLS.js.map
|