hwpx2f 0.0.0-stage → 0.1.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.
Files changed (73) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +124 -2
  3. package/THIRD_PARTY_NOTICES.md +75 -0
  4. package/dist/cli.js +76 -0
  5. package/dist/index.d.ts +11 -0
  6. package/dist/index.js +32 -0
  7. package/dist/lib/chunk-36PRCVPO.js +131 -0
  8. package/dist/lib/chunk-45BAITEX.js +9749 -0
  9. package/dist/lib/chunk-4NRZ6MWV.js +133 -0
  10. package/dist/lib/chunk-6CFXTS7A.js +11971 -0
  11. package/dist/lib/chunk-6CPCDYOD.js +104 -0
  12. package/dist/lib/chunk-B6MTS4XP.js +313 -0
  13. package/dist/lib/chunk-BX24E7EG.js +1427 -0
  14. package/dist/lib/chunk-C64I2SU4.js +82 -0
  15. package/dist/lib/chunk-CEKQASS3.js +258 -0
  16. package/dist/lib/chunk-CMWTKXM2.js +204 -0
  17. package/dist/lib/chunk-E6KSYRHG.js +2189 -0
  18. package/dist/lib/chunk-IZDWVMTV.js +28786 -0
  19. package/dist/lib/chunk-JK6YR5NT.js +4276 -0
  20. package/dist/lib/chunk-O6FSHPNE.js +111 -0
  21. package/dist/lib/chunk-OYXOOP2U.js +199 -0
  22. package/dist/lib/chunk-PM4KBWF4.js +49 -0
  23. package/dist/lib/chunk-R5F3GHLO.js +290 -0
  24. package/dist/lib/chunk-R76DWHJR.js +1596 -0
  25. package/dist/lib/chunk-RFS3RTSR.js +6876 -0
  26. package/dist/lib/chunk-RYJRNK5Z.js +47 -0
  27. package/dist/lib/chunk-UOXPGSFH.js +43 -0
  28. package/dist/lib/chunk-UZH4UBMX.js +44 -0
  29. package/dist/lib/chunk-VZTE4GKI.js +52 -0
  30. package/dist/lib/chunk-WEOKEO6L.js +35291 -0
  31. package/dist/lib/detect-4XZNNYZA-O7IPA4XQ.js +32 -0
  32. package/dist/lib/dist-HVSOXNCJ.js +263 -0
  33. package/dist/lib/formula-LC62GV4D-K3VFC5GV.js +1173 -0
  34. package/dist/lib/generator-KYTTL4OS-TRAQ66QE.js +14 -0
  35. package/dist/lib/hancom-EM62ZVDM-WZKVI7XB.js +91 -0
  36. package/dist/lib/image-ocr-ZUZQXLYS-U66LBMRA.js +293 -0
  37. package/dist/lib/page-images-VCIFZAXK-KJLWQDRH.js +95 -0
  38. package/dist/lib/page-range-7R3JU6SQ-MDDQRZVK.js +10 -0
  39. package/dist/lib/parser-JQNH5QMM-HFFI4HYK.js +4310 -0
  40. package/dist/lib/pdf-ocr-C3MBR6J2-J3UGJKWT.js +46 -0
  41. package/dist/lib/to-hwpx-JUT2SOTT-MOPPK6OW.js +17 -0
  42. package/dist/notices/core-util-is/LICENSE +19 -0
  43. package/dist/notices/entities/LICENSE +11 -0
  44. package/dist/notices/immediate/LICENSE.txt +20 -0
  45. package/dist/notices/inherits/LICENSE +16 -0
  46. package/dist/notices/jszip/LICENSE.markdown +651 -0
  47. package/dist/notices/kordoc/LICENSE +21 -0
  48. package/dist/notices/kordoc/NOTICE +376 -0
  49. package/dist/notices/kordoc/THIRD_PARTY/apache-2.0.LICENSE +201 -0
  50. package/dist/notices/kordoc/THIRD_PARTY/claw-hwp.LICENSE +21 -0
  51. package/dist/notices/kordoc/THIRD_PARTY/hayro-pdf.txt +361 -0
  52. package/dist/notices/kordoc/THIRD_PARTY/hml-equation-parser.LICENSE +201 -0
  53. package/dist/notices/kordoc/THIRD_PARTY/hml-equation-parser.txt +35 -0
  54. package/dist/notices/kordoc/THIRD_PARTY/korean-report-hwpx.LICENSE +21 -0
  55. package/dist/notices/kordoc/THIRD_PARTY/memchr.LICENSE +21 -0
  56. package/dist/notices/kordoc/THIRD_PARTY/opendataloader-pdf.txt +32 -0
  57. package/dist/notices/kordoc/THIRD_PARTY/pix2text.txt +17 -0
  58. package/dist/notices/kordoc/THIRD_PARTY/quick-xml.LICENSE +23 -0
  59. package/dist/notices/kordoc/THIRD_PARTY/rhwp-forms.txt +35 -0
  60. package/dist/notices/lie/license.md +7 -0
  61. package/dist/notices/linkify-it/LICENSE +22 -0
  62. package/dist/notices/markdown-it/LICENSE +22 -0
  63. package/dist/notices/mdurl/LICENSE +45 -0
  64. package/dist/notices/pako/LICENSE +21 -0
  65. package/dist/notices/process-nextick-args/license.md +19 -0
  66. package/dist/notices/punycode.js/LICENSE-MIT.txt +20 -0
  67. package/dist/notices/readable-stream/LICENSE +47 -0
  68. package/dist/notices/safe-buffer/LICENSE +21 -0
  69. package/dist/notices/setimmediate/LICENSE.txt +20 -0
  70. package/dist/notices/string_decoder/LICENSE +48 -0
  71. package/dist/notices/uc.micro/LICENSE.txt +20 -0
  72. package/dist/notices/util-deprecate/LICENSE +24 -0
  73. package/package.json +66 -4
@@ -0,0 +1,82 @@
1
+ import { createRequire as __hwpx2fRequire } from 'node:module'; const require = __hwpx2fRequire(import.meta.url);
2
+
3
+ // node_modules/kordoc/dist/chunk-L3U4XTBO.js
4
+ function similarity(a, b) {
5
+ if (a === b) return 1;
6
+ if (!a || !b) return 0;
7
+ const maxLen = Math.max(a.length, b.length);
8
+ if (maxLen === 0) return 1;
9
+ return 1 - levenshtein(a, b) / maxLen;
10
+ }
11
+ function normalizedSimilarity(a, b) {
12
+ return similarity(normalize(a), normalize(b));
13
+ }
14
+ function normalize(s) {
15
+ return s.replace(/\s+/g, " ").trim();
16
+ }
17
+ var MAX_LEVENSHTEIN_LEN = 1e4;
18
+ function textProfile(text) {
19
+ const s = normalize(text);
20
+ const count = /* @__PURE__ */ new Map();
21
+ for (let i = 0; i < s.length; i++) count.set(s.charCodeAt(i), (count.get(s.charCodeAt(i)) ?? 0) + 1);
22
+ const codes = Uint16Array.from([...count.keys()].sort((x, y) => x - y));
23
+ return { len: s.length, codes, counts: Uint32Array.from(codes, (c) => count.get(c)) };
24
+ }
25
+ function similarityUpperBound(a, b) {
26
+ const maxLen = Math.max(a.len, b.len);
27
+ if (maxLen === 0 || a.len + b.len > MAX_LEVENSHTEIN_LEN) return 1;
28
+ let common = 0;
29
+ for (let i = 0, j = 0; i < a.codes.length && j < b.codes.length; ) {
30
+ if (a.codes[i] === b.codes[j]) common += Math.min(a.counts[i++], b.counts[j++]);
31
+ else if (a.codes[i] < b.codes[j]) i++;
32
+ else j++;
33
+ }
34
+ return common / maxLen;
35
+ }
36
+ function approxDistance(a, b) {
37
+ const bigramCounts = (s) => {
38
+ const m = /* @__PURE__ */ new Map();
39
+ for (let i = 0; i < s.length - 1; i++) {
40
+ const g = s.slice(i, i + 2);
41
+ m.set(g, (m.get(g) ?? 0) + 1);
42
+ }
43
+ return m;
44
+ };
45
+ const ca = bigramCounts(a);
46
+ const cb = bigramCounts(b);
47
+ let inter = 0;
48
+ for (const [g, n] of ca) inter += Math.min(n, cb.get(g) ?? 0);
49
+ const total = Math.max(a.length - 1, 0) + Math.max(b.length - 1, 0);
50
+ const dice = total > 0 ? 2 * inter / total : 1;
51
+ return Math.round(Math.max(a.length, b.length) * (1 - dice));
52
+ }
53
+ function levenshtein(a, b) {
54
+ if (a.length + b.length > MAX_LEVENSHTEIN_LEN) {
55
+ return approxDistance(a, b);
56
+ }
57
+ if (a.length > b.length) [a, b] = [b, a];
58
+ const m = a.length;
59
+ const n = b.length;
60
+ let prev = Array.from({ length: m + 1 }, (_, i) => i);
61
+ let curr = new Array(m + 1);
62
+ for (let j = 1; j <= n; j++) {
63
+ curr[0] = j;
64
+ for (let i = 1; i <= m; i++) {
65
+ if (a[i - 1] === b[j - 1]) {
66
+ curr[i] = prev[i - 1];
67
+ } else {
68
+ curr[i] = 1 + Math.min(prev[i - 1], prev[i], curr[i - 1]);
69
+ }
70
+ }
71
+ ;
72
+ [prev, curr] = [curr, prev];
73
+ }
74
+ return prev[m];
75
+ }
76
+
77
+ export {
78
+ similarity,
79
+ normalizedSimilarity,
80
+ textProfile,
81
+ similarityUpperBound
82
+ };
@@ -0,0 +1,258 @@
1
+ import { createRequire as __hwpx2fRequire } from 'node:module'; const require = __hwpx2fRequire(import.meta.url);
2
+
3
+ // node_modules/kordoc/dist/chunk-5PEMTYTM.js
4
+ import { promisify } from "node:util";
5
+ import { deflate, deflateSync } from "node:zlib";
6
+ var deflateAsync = promisify(deflate);
7
+ var CRC_TABLE = (() => {
8
+ const table = new Uint32Array(256);
9
+ for (let n = 0; n < 256; n++) {
10
+ let c = n;
11
+ for (let k = 0; k < 8; k++) {
12
+ c = c & 1 ? 3988292384 ^ c >>> 1 : c >>> 1;
13
+ }
14
+ table[n] = c >>> 0;
15
+ }
16
+ return table;
17
+ })();
18
+ function crc32(bytes) {
19
+ let c = 4294967295;
20
+ for (let i = 0; i < bytes.length; i++) {
21
+ c = CRC_TABLE[(c ^ bytes[i]) & 255] ^ c >>> 8;
22
+ }
23
+ return (c ^ 4294967295) >>> 0;
24
+ }
25
+ var BI_RGB = 0;
26
+ var BI_RLE8 = 1;
27
+ var BI_RLE4 = 2;
28
+ var BI_BITFIELDS = 3;
29
+ var BI_ALPHABITFIELDS = 6;
30
+ var MAX_DIM = 32767;
31
+ var MAX_PIXELS = 36e6;
32
+ function bmpToPng(bmp) {
33
+ const px = bmpToRgba(bmp);
34
+ return px && encodePng(px.width, px.height, px.data);
35
+ }
36
+ function bmpToRgba(bmp) {
37
+ if (bmp.length < 26 || bmp[0] !== 66 || bmp[1] !== 77) return null;
38
+ const dv = new DataView(bmp.buffer, bmp.byteOffset, bmp.byteLength);
39
+ const dataOffset = dv.getUint32(10, true);
40
+ const headerSize = dv.getUint32(14, true);
41
+ const core = headerSize === 12;
42
+ if (!core && headerSize < 40 || bmp.length < 14 + headerSize) return null;
43
+ const width = core ? dv.getUint16(18, true) : dv.getInt32(18, true);
44
+ const rawHeight = core ? dv.getInt16(20, true) : dv.getInt32(22, true);
45
+ const bitCount = dv.getUint16(core ? 24 : 28, true);
46
+ const compression = core ? BI_RGB : dv.getUint32(30, true);
47
+ if (width <= 0 || rawHeight === 0) return null;
48
+ if (width > MAX_DIM || Math.abs(rawHeight) > MAX_DIM) return null;
49
+ const topDown = rawHeight < 0;
50
+ const height = Math.abs(rawHeight);
51
+ if (width * height > MAX_PIXELS) return null;
52
+ const rle = compression === BI_RLE8 || compression === BI_RLE4;
53
+ if (rle && (topDown || bitCount !== (compression === BI_RLE8 ? 8 : 4))) return null;
54
+ const fields = compression === BI_BITFIELDS || compression === BI_ALPHABITFIELDS;
55
+ let masks = null;
56
+ if (fields) {
57
+ if (bitCount !== 16 && bitCount !== 32 || bmp.length < 70) return null;
58
+ const alpha = compression === BI_ALPHABITFIELDS || headerSize >= 56;
59
+ masks = [dv.getUint32(54, true), dv.getUint32(58, true), dv.getUint32(62, true), alpha ? dv.getUint32(66, true) : 0];
60
+ } else if (compression === BI_RGB && bitCount === 16) masks = [31744, 992, 31, 0];
61
+ else if (compression !== BI_RGB && !rle) return null;
62
+ if (![1, 4, 8, 16, 24, 32].includes(bitCount)) return null;
63
+ let palette = null;
64
+ if (bitCount <= 8) {
65
+ const start = 14 + headerSize + (headerSize === 40 && fields ? compression === BI_ALPHABITFIELDS ? 16 : 12 : 0);
66
+ const entry = core ? 3 : 4;
67
+ const want = (core ? 0 : dv.getUint32(46, true)) || 1 << bitCount;
68
+ const count = Math.min(want, 256, Math.floor((Math.min(dataOffset, bmp.length) - start) / entry));
69
+ if (count <= 0) return null;
70
+ palette = new Uint8Array(256 * 3);
71
+ for (let k = 0; k < count; k++) {
72
+ const o = start + k * entry;
73
+ palette[k * 3] = bmp[o + 2];
74
+ palette[k * 3 + 1] = bmp[o + 1];
75
+ palette[k * 3 + 2] = bmp[o];
76
+ }
77
+ }
78
+ const rgba = new Uint8Array(width * height * 4);
79
+ const putIndex = (dst, k) => {
80
+ rgba[dst] = palette[k * 3];
81
+ rgba[dst + 1] = palette[k * 3 + 1];
82
+ rgba[dst + 2] = palette[k * 3 + 2];
83
+ rgba[dst + 3] = 255;
84
+ };
85
+ if (rle) {
86
+ if (dataOffset >= bmp.length) return null;
87
+ decodeRle(bmp, dataOffset, compression === BI_RLE4, width, height, (x, y, k) => putIndex(((height - 1 - y) * width + x) * 4, k));
88
+ return { data: rgba, width, height };
89
+ }
90
+ const rowStride = (width * bitCount + 31 >>> 5) * 4;
91
+ if (dataOffset + rowStride * height > bmp.length) return null;
92
+ const channels = masks?.map(maskChannel);
93
+ let anyAlpha = 0;
94
+ for (let y = 0; y < height; y++) {
95
+ const row = dataOffset + (topDown ? y : height - 1 - y) * rowStride;
96
+ let dst = y * width * 4;
97
+ for (let x = 0; x < width; x++, dst += 4) {
98
+ if (palette) {
99
+ const bit = x * bitCount;
100
+ putIndex(dst, bmp[row + (bit >>> 3)] >> 8 - bitCount - (bit & 7) & (1 << bitCount) - 1);
101
+ } else if (channels) {
102
+ const v = bitCount === 16 ? dv.getUint16(row + x * 2, true) : dv.getUint32(row + x * 4, true);
103
+ for (let c = 0; c < 4; c++) rgba[dst + c] = channels[c](v);
104
+ } else {
105
+ const src = row + x * (bitCount >> 3);
106
+ rgba[dst] = bmp[src + 2];
107
+ rgba[dst + 1] = bmp[src + 1];
108
+ rgba[dst + 2] = bmp[src];
109
+ const a = bitCount === 32 ? bmp[src + 3] : 255;
110
+ rgba[dst + 3] = a;
111
+ anyAlpha |= a;
112
+ }
113
+ }
114
+ }
115
+ if (bitCount === 32 && !channels && anyAlpha === 0) {
116
+ for (let i = 3; i < rgba.length; i += 4) rgba[i] = 255;
117
+ }
118
+ return { data: rgba, width, height };
119
+ }
120
+ function maskChannel(mask) {
121
+ if (!mask) return () => 255;
122
+ let shift = 0;
123
+ while (!(mask >>> shift & 1)) shift++;
124
+ const max = mask >>> shift;
125
+ return (v) => Math.round(((v & mask) >>> shift) * 255 / max);
126
+ }
127
+ function decodeRle(b, start, four, width, height, put) {
128
+ for (let y2 = 0; y2 < height; y2++) for (let x2 = 0; x2 < width; x2++) put(x2, y2, 0);
129
+ const set = (x2, y2, k) => {
130
+ if (x2 < width && y2 < height) put(x2, y2, k);
131
+ };
132
+ let x = 0, y = 0, i = start;
133
+ while (i + 1 < b.length && y < height) {
134
+ const n = b[i], v = b[i + 1];
135
+ i += 2;
136
+ if (n > 0) {
137
+ for (let k = 0, m = Math.min(n, width - x); k < m; k++) set(x + k, y, four ? k & 1 ? v & 15 : v >> 4 : v);
138
+ x += n;
139
+ } else if (v === 0) {
140
+ x = 0;
141
+ y++;
142
+ } else if (v === 1) {
143
+ return;
144
+ } else if (v === 2) {
145
+ x += b[i] ?? 0;
146
+ y += b[i + 1] ?? 0;
147
+ i += 2;
148
+ } else {
149
+ for (let k = 0, m = Math.min(v, width - x); k < m; k++) set(x + k, y, four ? (b[i + (k >> 1)] ?? 0) >> (k & 1 ? 0 : 4) & 15 : b[i + k] ?? 0);
150
+ x += v;
151
+ const bytes = four ? v + 1 >> 1 : v;
152
+ i += bytes + (bytes & 1);
153
+ }
154
+ }
155
+ }
156
+ var PNG_SIGNATURE = Uint8Array.of(137, 80, 78, 71, 13, 10, 26, 10);
157
+ function chunk(type, data) {
158
+ const body = new Uint8Array(4 + data.length);
159
+ body[0] = type.charCodeAt(0);
160
+ body[1] = type.charCodeAt(1);
161
+ body[2] = type.charCodeAt(2);
162
+ body[3] = type.charCodeAt(3);
163
+ body.set(data, 4);
164
+ const out = new Uint8Array(8 + data.length + 4);
165
+ const dv = new DataView(out.buffer);
166
+ dv.setUint32(0, data.length, false);
167
+ out.set(body, 4);
168
+ dv.setUint32(8 + data.length, crc32(body), false);
169
+ return out;
170
+ }
171
+ function encodePng(width, height, rgba) {
172
+ return assemblePng(width, height, deflateSync(pngScanlines(width, height, rgba, 4)));
173
+ }
174
+ async function encodePngAsync(width, height, pixels, channels = 4) {
175
+ const raw = pngScanlines(width, height, pixels, channels);
176
+ const idat = await deflateAsync(raw).catch(() => deflateSync(raw));
177
+ return assemblePng(width, height, idat);
178
+ }
179
+ function pngScanlineBytes(width, height) {
180
+ return (width * 4 + 1) * height;
181
+ }
182
+ function pngScanlines(width, height, pixels, channels) {
183
+ const stride = width * 4;
184
+ const raw = new Uint8Array(pngScanlineBytes(width, height));
185
+ for (let y = 0; y < height; y++) {
186
+ const rowStart = y * (stride + 1) + 1;
187
+ if (channels === 4) {
188
+ const source = y * stride;
189
+ raw.set(pixels.subarray(source, source + stride), rowStart);
190
+ } else {
191
+ let source = y * width * 3;
192
+ for (let dst = rowStart; dst < rowStart + stride; dst += 4, source += 3) {
193
+ raw[dst] = pixels[source];
194
+ raw[dst + 1] = pixels[source + 1];
195
+ raw[dst + 2] = pixels[source + 2];
196
+ raw[dst + 3] = 255;
197
+ }
198
+ }
199
+ }
200
+ return raw;
201
+ }
202
+ function assemblePng(width, height, idat) {
203
+ const ihdr = new Uint8Array(13);
204
+ const iv = new DataView(ihdr.buffer);
205
+ iv.setUint32(0, width, false);
206
+ iv.setUint32(4, height, false);
207
+ ihdr[8] = 8;
208
+ ihdr[9] = 6;
209
+ const ihdrChunk = chunk("IHDR", ihdr);
210
+ const idatChunk = chunk("IDAT", idat);
211
+ const iendChunk = chunk("IEND", new Uint8Array(0));
212
+ const out = new Uint8Array(PNG_SIGNATURE.length + ihdrChunk.length + idatChunk.length + iendChunk.length);
213
+ let o = 0;
214
+ out.set(PNG_SIGNATURE, o);
215
+ o += PNG_SIGNATURE.length;
216
+ out.set(ihdrChunk, o);
217
+ o += ihdrChunk.length;
218
+ out.set(idatChunk, o);
219
+ o += idatChunk.length;
220
+ out.set(iendChunk, o);
221
+ return out;
222
+ }
223
+ function inlineImagesIntoMarkdown(markdown, images, opts) {
224
+ const compress = opts?.compress !== false;
225
+ const uris = /* @__PURE__ */ new Map();
226
+ for (const img of images) {
227
+ let bytes = img.data;
228
+ let mime = img.mimeType;
229
+ if (compress && mime === "image/bmp") {
230
+ const png = bmpToPng(img.data);
231
+ if (png) {
232
+ bytes = png;
233
+ mime = "image/png";
234
+ }
235
+ }
236
+ uris.set(img.filename, `data:${mime};base64,${Buffer.from(bytes).toString("base64")}`);
237
+ }
238
+ if (uris.size === 0) return markdown;
239
+ let out = markdown.replace(/!\[image\]\((?:images\/)?([^()\s]+)\)/g, (m, name) => {
240
+ const uri = uris.get(name);
241
+ return uri !== void 0 ? `![image](${uri})` : m;
242
+ });
243
+ out = out.replace(/(<img\b[^>]*\bsrc=")(?:images\/)?([^"]*)(")/g, (m, pre, name, post) => {
244
+ const uri = uris.get(name);
245
+ return uri !== void 0 ? `${pre}${uri}${post}` : m;
246
+ });
247
+ return out;
248
+ }
249
+
250
+ export {
251
+ MAX_PIXELS,
252
+ bmpToPng,
253
+ bmpToRgba,
254
+ encodePng,
255
+ encodePngAsync,
256
+ pngScanlineBytes,
257
+ inlineImagesIntoMarkdown
258
+ };
@@ -0,0 +1,204 @@
1
+ import { createRequire as __hwpx2fRequire } from 'node:module'; const require = __hwpx2fRequire(import.meta.url);
2
+
3
+ // node_modules/kordoc/dist/chunk-Y6BVOW4Y.js
4
+ var CFB_MAGIC = Buffer.from([208, 207, 17, 224, 161, 177, 26, 225]);
5
+ var END_OF_CHAIN = 4294967294;
6
+ var FREE_SECT = 4294967295;
7
+ var MAX_CHAIN_LENGTH = 1e6;
8
+ var MAX_DIR_ENTRIES = 1e5;
9
+ var MAX_STREAM_SIZE = 100 * 1024 * 1024;
10
+ function parseLenientCfb(data) {
11
+ if (data.length < 512) throw new Error("CFB \uD30C\uC77C\uC774 \uB108\uBB34 \uC9E7\uC2B5\uB2C8\uB2E4 (\uCD5C\uC18C 512\uBC14\uC774\uD2B8)");
12
+ if (!data.subarray(0, 8).equals(CFB_MAGIC)) throw new Error("CFB \uB9E4\uC9C1 \uBC14\uC774\uD2B8 \uBD88\uC77C\uCE58");
13
+ const sectorSizeShift = data.readUInt16LE(30);
14
+ if (sectorSizeShift < 7 || sectorSizeShift > 16) throw new Error("\uC720\uD6A8\uD558\uC9C0 \uC54A\uC740 \uC139\uD130 \uD06C\uAE30 \uC2DC\uD504\uD2B8: " + sectorSizeShift);
15
+ const sectorSize = 1 << sectorSizeShift;
16
+ const miniSectorSizeShift = data.readUInt16LE(32);
17
+ if (miniSectorSizeShift > 16) throw new Error("\uC720\uD6A8\uD558\uC9C0 \uC54A\uC740 \uBBF8\uB2C8 \uC139\uD130 \uD06C\uAE30 \uC2DC\uD504\uD2B8: " + miniSectorSizeShift);
18
+ const miniSectorSize = 1 << miniSectorSizeShift;
19
+ const headerFatSectorCount = data.readUInt32LE(44);
20
+ if (headerFatSectorCount > 1e4) throw new Error("FAT \uC139\uD130 \uC218\uAC00 \uB108\uBB34 \uB9CE\uC2B5\uB2C8\uB2E4: " + headerFatSectorCount);
21
+ const maxRealSectors = Math.ceil(Math.max(0, data.length - 512) / sectorSize);
22
+ const maxFatSectors = Math.max(1, Math.ceil(maxRealSectors / (sectorSize / 4)));
23
+ const fatSectorCount = Math.min(headerFatSectorCount, maxFatSectors);
24
+ const firstDirSector = data.readUInt32LE(48);
25
+ const miniStreamCutoff = data.readUInt32LE(56);
26
+ const firstMiniFatSector = data.readUInt32LE(60);
27
+ const miniFatSectorCount = data.readUInt32LE(64);
28
+ const firstDifatSector = data.readUInt32LE(68);
29
+ const difatSectorCount = data.readUInt32LE(72);
30
+ function sectorOffset(id) {
31
+ return 512 + id * sectorSize;
32
+ }
33
+ function readSectorData(id) {
34
+ const off = sectorOffset(id);
35
+ if (off + sectorSize > data.length) return Buffer.alloc(0);
36
+ return data.subarray(off, off + sectorSize);
37
+ }
38
+ const fatSectors = [];
39
+ for (let i = 0; i < 109 && fatSectors.length < fatSectorCount; i++) {
40
+ const sid = data.readUInt32LE(76 + i * 4);
41
+ if (sid === FREE_SECT || sid === END_OF_CHAIN) break;
42
+ fatSectors.push(sid);
43
+ }
44
+ let difatSector = firstDifatSector;
45
+ const visitedDifat = /* @__PURE__ */ new Set();
46
+ for (let d = 0; d < difatSectorCount && difatSector !== END_OF_CHAIN && difatSector !== FREE_SECT; d++) {
47
+ if (visitedDifat.has(difatSector)) break;
48
+ visitedDifat.add(difatSector);
49
+ const buf = readSectorData(difatSector);
50
+ if (buf.length < sectorSize) break;
51
+ const entriesPerSector = sectorSize / 4 - 1;
52
+ for (let i = 0; i < entriesPerSector && fatSectors.length < fatSectorCount; i++) {
53
+ const sid = buf.readUInt32LE(i * 4);
54
+ if (sid === FREE_SECT || sid === END_OF_CHAIN) continue;
55
+ fatSectors.push(sid);
56
+ }
57
+ difatSector = buf.readUInt32LE(entriesPerSector * 4);
58
+ }
59
+ const entriesPerFatSector = sectorSize / 4;
60
+ const fatTable = new Uint32Array(fatSectors.length * entriesPerFatSector);
61
+ for (let fi = 0; fi < fatSectors.length; fi++) {
62
+ const buf = readSectorData(fatSectors[fi]);
63
+ for (let i = 0; i < entriesPerFatSector; i++) {
64
+ fatTable[fi * entriesPerFatSector + i] = i * 4 + 3 < buf.length ? buf.readUInt32LE(i * 4) : FREE_SECT;
65
+ }
66
+ }
67
+ function readChain(startSector, maxBytes) {
68
+ if (startSector === END_OF_CHAIN || startSector === FREE_SECT) return Buffer.alloc(0);
69
+ if (maxBytes > MAX_STREAM_SIZE) throw new Error("\uC2A4\uD2B8\uB9BC\uC774 \uB108\uBB34 \uD07D\uB2C8\uB2E4");
70
+ const chunks = [];
71
+ let current = startSector;
72
+ let totalRead = 0;
73
+ const visited = /* @__PURE__ */ new Set();
74
+ while (current !== END_OF_CHAIN && current !== FREE_SECT && totalRead < maxBytes) {
75
+ if (visited.has(current)) break;
76
+ if (visited.size > MAX_CHAIN_LENGTH) break;
77
+ visited.add(current);
78
+ const buf = readSectorData(current);
79
+ const remaining = maxBytes - totalRead;
80
+ chunks.push(remaining < sectorSize ? buf.subarray(0, remaining) : buf);
81
+ totalRead += Math.min(buf.length, remaining);
82
+ current = current < fatTable.length ? fatTable[current] : END_OF_CHAIN;
83
+ }
84
+ return Buffer.concat(chunks);
85
+ }
86
+ let miniFatTable = null;
87
+ function getMiniFatTable() {
88
+ if (miniFatTable) return miniFatTable;
89
+ if (miniFatSectorCount === 0 || firstMiniFatSector === END_OF_CHAIN) {
90
+ miniFatTable = new Uint32Array(0);
91
+ return miniFatTable;
92
+ }
93
+ const miniFatData = readChain(firstMiniFatSector, miniFatSectorCount * sectorSize);
94
+ const entries = miniFatData.length / 4;
95
+ miniFatTable = new Uint32Array(entries);
96
+ for (let i = 0; i < entries; i++) {
97
+ miniFatTable[i] = miniFatData.readUInt32LE(i * 4);
98
+ }
99
+ return miniFatTable;
100
+ }
101
+ const dirData = readChain(firstDirSector, MAX_DIR_ENTRIES * 128);
102
+ const dirEntries = [];
103
+ for (let offset = 0; offset + 128 <= dirData.length && dirEntries.length < MAX_DIR_ENTRIES; offset += 128) {
104
+ const nameLen = dirData.readUInt16LE(offset + 64);
105
+ if (nameLen <= 0 || nameLen > 64) {
106
+ dirEntries.push({ name: "", type: 0, startSector: 0, size: 0, left: FREE_SECT, right: FREE_SECT, child: FREE_SECT });
107
+ continue;
108
+ }
109
+ const nameBytes = nameLen - 2;
110
+ const name = nameBytes > 0 ? dirData.subarray(offset, offset + nameBytes).toString("utf16le") : "";
111
+ const type = dirData[offset + 66];
112
+ const startSector = dirData.readUInt32LE(offset + 116);
113
+ const size = dirData.readUInt32LE(offset + 120);
114
+ dirEntries.push({ name, type, startSector, size, left: dirData.readUInt32LE(offset + 68), right: dirData.readUInt32LE(offset + 72), child: dirData.readUInt32LE(offset + 76) });
115
+ }
116
+ let miniStreamData = null;
117
+ function getMiniStream() {
118
+ if (miniStreamData) return miniStreamData;
119
+ const root = dirEntries[0];
120
+ if (!root || root.type !== 5) {
121
+ miniStreamData = Buffer.alloc(0);
122
+ return miniStreamData;
123
+ }
124
+ miniStreamData = readChain(root.startSector, root.size || MAX_STREAM_SIZE);
125
+ return miniStreamData;
126
+ }
127
+ function readMiniStream(startSector, size) {
128
+ const mft = getMiniFatTable();
129
+ const ms = getMiniStream();
130
+ if (mft.length === 0 || ms.length === 0) return Buffer.alloc(0);
131
+ const chunks = [];
132
+ let current = startSector;
133
+ let totalRead = 0;
134
+ const visited = /* @__PURE__ */ new Set();
135
+ while (current !== END_OF_CHAIN && current !== FREE_SECT && totalRead < size) {
136
+ if (visited.has(current)) break;
137
+ if (visited.size > MAX_CHAIN_LENGTH) break;
138
+ visited.add(current);
139
+ const off = current * miniSectorSize;
140
+ const remaining = size - totalRead;
141
+ const chunkSize = Math.min(miniSectorSize, remaining);
142
+ if (off + chunkSize <= ms.length) {
143
+ chunks.push(ms.subarray(off, off + chunkSize));
144
+ }
145
+ totalRead += chunkSize;
146
+ current = current < mft.length ? mft[current] : END_OF_CHAIN;
147
+ }
148
+ return Buffer.concat(chunks);
149
+ }
150
+ function readStreamData(entry) {
151
+ if (entry.size === 0) return Buffer.alloc(0);
152
+ if (entry.size < miniStreamCutoff) {
153
+ const miniResult = readMiniStream(entry.startSector, entry.size);
154
+ if (miniResult.length > 0) return miniResult;
155
+ }
156
+ return readChain(entry.startSector, entry.size);
157
+ }
158
+ function findChild(parent, name) {
159
+ const pending = [parent.child];
160
+ const visited = /* @__PURE__ */ new Set();
161
+ while (pending.length) {
162
+ const id = pending.pop();
163
+ if (id === END_OF_CHAIN || id === FREE_SECT || id >= dirEntries.length || visited.has(id)) continue;
164
+ visited.add(id);
165
+ const e = dirEntries[id];
166
+ if (e.name === name) return e;
167
+ pending.push(e.left, e.right);
168
+ }
169
+ return null;
170
+ }
171
+ function findEntryByPath(path) {
172
+ const parts = path.replace(/^\//, "").split("/").filter(Boolean);
173
+ const last = parts.pop();
174
+ if (last === void 0) return null;
175
+ const root = dirEntries.find((e) => e.type === 5);
176
+ if (root) {
177
+ let current = root;
178
+ for (const part of parts) {
179
+ const next = current ? findChild(current, part) : null;
180
+ current = next && next.type === 1 ? next : null;
181
+ }
182
+ const hit = current ? findChild(current, last) : null;
183
+ if (hit && (hit.type === 1 || hit.type === 2 || hit.type === 5)) return hit;
184
+ }
185
+ const named = dirEntries.filter((e) => e.name === last && (e.type === 1 || e.type === 2 || e.type === 5));
186
+ return named.length === 1 ? named[0] : null;
187
+ }
188
+ return {
189
+ findStream(path) {
190
+ const normalized = path.replace(/^\//, "");
191
+ const entry = findEntryByPath(normalized);
192
+ if (!entry || entry.type !== 2) return null;
193
+ const stream = readStreamData(entry);
194
+ return stream.length > 0 ? stream : null;
195
+ },
196
+ entries() {
197
+ return dirEntries.filter((e) => e.type === 2);
198
+ }
199
+ };
200
+ }
201
+
202
+ export {
203
+ parseLenientCfb
204
+ };