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,104 @@
1
+ import { createRequire as __hwpx2fRequire } from 'node:module'; const require = __hwpx2fRequire(import.meta.url);
2
+ import {
3
+ MAX_PIXELS
4
+ } from "./chunk-CEKQASS3.js";
5
+ import {
6
+ KordocError
7
+ } from "./chunk-OYXOOP2U.js";
8
+
9
+ // node_modules/kordoc/dist/chunk-PJBJ6ZQD.js
10
+ var MAX_HEIC_PIXELS = 16383 * 16383;
11
+ var loading;
12
+ function loadLibheif() {
13
+ return loading ??= import("libheif-js/libheif-wasm/libheif-bundle.js").then(
14
+ (mod) => mod.default ?? mod,
15
+ (e) => {
16
+ loading = void 0;
17
+ throw new KordocError(`HEIC\xB7HEIF \uC774\uBBF8\uC9C0\uB97C \uC77D\uC73C\uB824\uBA74 optional dependency 'libheif-js' \uAC00 \uD544\uC694\uD569\uB2C8\uB2E4. \`npm install libheif-js\` \uD6C4 \uB2E4\uC2DC \uC2E4\uD589\uD558\uC138\uC694. \uC6D0\uC778: ${e.message}`);
18
+ }
19
+ );
20
+ }
21
+ var hasLibheif = () => loadLibheif().then(() => true, () => false);
22
+ async function heicToRgba(bytes, maxPixels = MAX_HEIC_PIXELS) {
23
+ const libheif = (await loadLibheif())();
24
+ const log = console.log;
25
+ console.log = () => {
26
+ };
27
+ let images = [];
28
+ try {
29
+ images = new libheif.HeifDecoder().decode(bytes);
30
+ const img = images.find((i) => i.is_primary()) ?? images[0];
31
+ if (!img) throw new KordocError("HEIC\xB7HEIF \uB514\uCF54\uB529 \uC2E4\uD328: \uC774\uBBF8\uC9C0\uAC00 \uC5C6\uC2B5\uB2C8\uB2E4");
32
+ const width = img.get_width(), height = img.get_height();
33
+ if (width * height > maxPixels) throw new KordocError(`HEIC\xB7HEIF \uC774\uBBF8\uC9C0\uAC00 \uB108\uBB34 \uD07D\uB2C8\uB2E4 (${width}\xD7${height})`);
34
+ const data = new Uint8ClampedArray(width * height * 4);
35
+ await new Promise((resolve, reject) => img.display({ data, width, height }, (out) => out ? resolve() : reject(new KordocError("HEIC\xB7HEIF \uB514\uCF54\uB529 \uC2E4\uD328"))));
36
+ return { data: new Uint8Array(data.buffer), width, height };
37
+ } finally {
38
+ console.log = log;
39
+ for (const i of images) i.free();
40
+ }
41
+ }
42
+ function dcxPages(b) {
43
+ if (b.length < 8 || b[0] !== 177 || b[1] !== 104 || b[2] !== 222 || b[3] !== 58) return [];
44
+ const v = new DataView(b.buffer, b.byteOffset, b.byteLength), offs = [];
45
+ for (let o = 4; o + 4 <= b.length && offs.length < 1023; o += 4) {
46
+ const off = v.getUint32(o, true);
47
+ if (!off) break;
48
+ if (off >= b.length || offs.length && off <= offs[offs.length - 1]) return [];
49
+ offs.push(off);
50
+ }
51
+ return offs.map((off, i) => b.subarray(off, offs[i + 1] > off ? offs[i + 1] : b.length));
52
+ }
53
+ function pcxToRgba(b) {
54
+ if (b.length < 128 || b[0] !== 10 || b[2] !== 1) return null;
55
+ const v = new DataView(b.buffer, b.byteOffset, b.byteLength);
56
+ const bits = b[3], planes = b[65], line = v.getUint16(66, true);
57
+ const width = v.getUint16(8, true) - v.getUint16(4, true) + 1, height = v.getUint16(10, true) - v.getUint16(6, true) + 1;
58
+ const mono = bits === 1 && [1, 2, 4].includes(planes), gray = bits === 8 && planes === 1, rgb = bits === 8 && planes === 3;
59
+ if (!(mono || gray || rgb) || width <= 0 || height <= 0 || width * height > MAX_PIXELS || line * 8 < width * bits) return null;
60
+ const stride = line * planes;
61
+ if (stride * height > MAX_PIXELS * 4) return null;
62
+ const raw = new Uint8Array(stride * height);
63
+ let i = 128, o = 0;
64
+ while (o < raw.length) {
65
+ if (i >= b.length) return null;
66
+ const c = b[i++];
67
+ if (c < 192) {
68
+ raw[o++] = c;
69
+ continue;
70
+ }
71
+ if (i >= b.length) return null;
72
+ raw.fill(b[i++], o, Math.min(o + (c & 63), raw.length));
73
+ o += c & 63;
74
+ }
75
+ const tail = b.length - 769;
76
+ const pal = gray ? tail >= 128 && b[tail] === 12 ? b.subarray(tail + 1) : null : b.subarray(16, 64);
77
+ const rgba = new Uint8Array(width * height * 4);
78
+ for (let y = 0; y < height; y++) {
79
+ const row = y * stride;
80
+ for (let x = 0; x < width; x++) {
81
+ const d = (y * width + x) * 4;
82
+ if (rgb) rgba.set([raw[row + x], raw[row + line + x], raw[row + 2 * line + x], 255], d);
83
+ else {
84
+ let k = 0;
85
+ if (mono) for (let p = 0; p < planes; p++) k |= (raw[row + p * line + (x >> 3)] >> 7 - (x & 7) & 1) << p;
86
+ else k = raw[row + x];
87
+ if (mono && planes === 1) k *= 255;
88
+ else if (pal) {
89
+ rgba.set([pal[k * 3], pal[k * 3 + 1], pal[k * 3 + 2], 255], d);
90
+ continue;
91
+ }
92
+ rgba.set([k, k, k, 255], d);
93
+ }
94
+ }
95
+ }
96
+ return { data: rgba, width, height, dpi: v.getUint16(12, true) };
97
+ }
98
+
99
+ export {
100
+ hasLibheif,
101
+ heicToRgba,
102
+ dcxPages,
103
+ pcxToRgba
104
+ };
@@ -0,0 +1,313 @@
1
+ import { createRequire as __hwpx2fRequire } from 'node:module'; const require = __hwpx2fRequire(import.meta.url);
2
+ import {
3
+ KordocError
4
+ } from "./chunk-OYXOOP2U.js";
5
+
6
+ // node_modules/kordoc/dist/chunk-AO7VWHM6.js
7
+ var TRUTHY = /* @__PURE__ */ new Set(["1", "true", "yes", "on"]);
8
+ function envFlag(name) {
9
+ const v = process.env[name];
10
+ return !!v && TRUTHY.has(v.trim().toLowerCase());
11
+ }
12
+ function isOfflineMode() {
13
+ return envFlag("KORDOC_OFFLINE");
14
+ }
15
+ function assertNetworkAllowed(what, hint) {
16
+ if (!isOfflineMode()) return;
17
+ throw new KordocError(
18
+ `\uD3D0\uC1C4\uB9DD \uBAA8\uB4DC(KORDOC_OFFLINE)\uC5D0\uC11C \uCC28\uB2E8\uB428: ${what}` + (hint ? ` \u2014 ${hint}` : "")
19
+ );
20
+ }
21
+
22
+ // node_modules/kordoc/dist/chunk-RFG7XYN7.js
23
+ import { createHash as createHash2 } from "crypto";
24
+ import { createReadStream } from "fs";
25
+ import { mkdir, stat, unlink as unlink2, rename } from "fs/promises";
26
+ import { createWriteStream } from "fs";
27
+ import { homedir } from "os";
28
+ import { join as join2, dirname as dirname2 } from "path";
29
+ import { pipeline } from "stream/promises";
30
+ import { Readable } from "stream";
31
+ import { createHash, randomUUID } from "node:crypto";
32
+ import { readFileSync, readlinkSync } from "node:fs";
33
+ import { readdir, unlink } from "node:fs/promises";
34
+ import { hostname } from "node:os";
35
+ import { basename, dirname, join } from "node:path";
36
+ var scope;
37
+ function ownerScope() {
38
+ if (scope) return scope;
39
+ let namespace = "";
40
+ if (process.platform === "linux") {
41
+ try {
42
+ const boot = readFileSync("/proc/sys/kernel/random/boot_id", "utf8").trim();
43
+ if (!boot) throw new Error("Kernel boot identity unavailable");
44
+ namespace = `${boot}:${readlinkSync("/proc/self/ns/pid")}`;
45
+ } catch {
46
+ namespace = randomUUID();
47
+ }
48
+ }
49
+ scope = createHash("sha256").update(`${process.platform}\0${hostname()}\0${namespace}`).digest("hex").slice(0, 32);
50
+ return scope;
51
+ }
52
+ function modelDownloadPartialPath(localPath) {
53
+ return `${localPath}.kordoc-${ownerScope()}-${process.pid}-${randomUUID()}.part`;
54
+ }
55
+ async function cleanupModelDownloadPartials(localPath) {
56
+ const dir = dirname(localPath);
57
+ const prefix = `${basename(localPath)}.kordoc-${ownerScope()}-`;
58
+ let entries;
59
+ try {
60
+ entries = await readdir(dir, { withFileTypes: true });
61
+ } catch {
62
+ return;
63
+ }
64
+ for (const entry of entries) {
65
+ if (!entry.isFile() || !entry.name.startsWith(prefix)) continue;
66
+ const match = /^([1-9]\d*)-([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})\.part$/.exec(entry.name.slice(prefix.length));
67
+ if (!match) continue;
68
+ const pid = Number(match[1]);
69
+ if (!Number.isSafeInteger(pid) || pid > 2147483647) continue;
70
+ try {
71
+ process.kill(pid, 0);
72
+ continue;
73
+ } catch (err) {
74
+ if (err.code !== "ESRCH") continue;
75
+ }
76
+ try {
77
+ await unlink(join(dir, entry.name));
78
+ } catch {
79
+ }
80
+ }
81
+ }
82
+ var MFD_MODEL = {
83
+ name: "Pix2Text MFD",
84
+ filename: "mfd.onnx",
85
+ url: "https://huggingface.co/breezedeus/pix2text-mfd/resolve/main/mfd-v20240618.onnx",
86
+ sha256: "51a8854743b17ae654729af8db82a630c1ccfa06debf4856c8b28055f87d02c1",
87
+ sizeMb: 42
88
+ };
89
+ var MFR_ENCODER_MODEL = {
90
+ name: "Pix2Text MFR encoder",
91
+ filename: "encoder_model.onnx",
92
+ url: "https://huggingface.co/breezedeus/pix2text-mfr/resolve/main/encoder_model.onnx",
93
+ sha256: "bd8d5c322792e9ec45793af5569e9748f82a3d728a9e00213dbfc56c1486f37d",
94
+ sizeMb: 87
95
+ };
96
+ var MFR_DECODER_MODEL = {
97
+ name: "Pix2Text MFR decoder",
98
+ filename: "decoder_model.onnx",
99
+ url: "https://huggingface.co/breezedeus/pix2text-mfr/resolve/main/decoder_model.onnx",
100
+ sha256: "fd0f92d7a012f3dae41e1ac79421aea0ea888b5a66cb3f9a004e424f82f3daed",
101
+ sizeMb: 30
102
+ };
103
+ var MFR_TOKENIZER = {
104
+ name: "Pix2Text MFR tokenizer",
105
+ filename: "tokenizer.json",
106
+ url: "https://huggingface.co/breezedeus/pix2text-mfr/resolve/main/tokenizer.json",
107
+ sha256: "3e2ab757277d22639bec28c9d7972e352d3d1dba223051fa674002dc5ab64df3",
108
+ sizeMb: 1
109
+ };
110
+ var ALL_FORMULA_MODELS = [
111
+ MFD_MODEL,
112
+ MFR_ENCODER_MODEL,
113
+ MFR_DECODER_MODEL,
114
+ MFR_TOKENIZER
115
+ ];
116
+ function getModelsDir(subdir) {
117
+ const override = process.env.KORDOC_MODEL_CACHE;
118
+ if (override && override.trim()) {
119
+ return join2(override, subdir);
120
+ }
121
+ return join2(homedir(), ".cache", "kordoc", "models", subdir);
122
+ }
123
+ function getFormulaModelsDir() {
124
+ return getModelsDir("pix2text");
125
+ }
126
+ async function getModelStatusIn(dir, specs) {
127
+ const result = [];
128
+ for (const spec of specs) {
129
+ const localPath = join2(dir, spec.filename);
130
+ let exists = false;
131
+ try {
132
+ const s = await stat(localPath);
133
+ exists = s.isFile() && s.size > 0;
134
+ } catch {
135
+ exists = false;
136
+ }
137
+ if (!exists) {
138
+ result.push({ spec, localPath, exists: false, verified: false });
139
+ continue;
140
+ }
141
+ try {
142
+ const actual = await sha256OfFile(localPath);
143
+ if (actual === spec.sha256) {
144
+ result.push({ spec, localPath, exists: true, verified: true });
145
+ } else {
146
+ result.push({
147
+ spec,
148
+ localPath,
149
+ exists: true,
150
+ verified: false,
151
+ invalidReason: `SHA256 mismatch: expected ${spec.sha256}, got ${actual}`
152
+ });
153
+ }
154
+ } catch (e) {
155
+ result.push({
156
+ spec,
157
+ localPath,
158
+ exists: true,
159
+ verified: false,
160
+ invalidReason: `SHA compute failed: ${e.message}`
161
+ });
162
+ }
163
+ }
164
+ return result;
165
+ }
166
+ async function getFormulaModelStatus() {
167
+ return getModelStatusIn(getFormulaModelsDir(), ALL_FORMULA_MODELS);
168
+ }
169
+ async function ensureModelsIn(dir, specs, onProgress) {
170
+ await mkdir(dir, { recursive: true });
171
+ for (const spec of specs) {
172
+ const localPath = join2(dir, spec.filename);
173
+ await cleanupModelDownloadPartials(localPath);
174
+ if (await isExistingValid(localPath, spec.sha256)) {
175
+ onProgress?.({
176
+ spec,
177
+ downloaded: 0,
178
+ total: null,
179
+ phase: "skip",
180
+ message: "\uC774\uBBF8 \uC874\uC7AC + SHA \uC77C\uCE58"
181
+ });
182
+ continue;
183
+ }
184
+ await downloadToFile(spec, localPath, onProgress);
185
+ }
186
+ }
187
+ async function ensureFormulaModels(onProgress) {
188
+ return ensureModelsIn(getFormulaModelsDir(), ALL_FORMULA_MODELS, onProgress);
189
+ }
190
+ async function ensureSingleModel(spec, onProgress) {
191
+ const dir = getFormulaModelsDir();
192
+ await mkdir(dir, { recursive: true });
193
+ const localPath = join2(dir, spec.filename);
194
+ await cleanupModelDownloadPartials(localPath);
195
+ if (await isExistingValid(localPath, spec.sha256)) {
196
+ onProgress?.({ spec, downloaded: 0, total: null, phase: "skip" });
197
+ return;
198
+ }
199
+ await downloadToFile(spec, localPath, onProgress);
200
+ }
201
+ async function isExistingValid(localPath, sha256Expected) {
202
+ try {
203
+ const s = await stat(localPath);
204
+ if (!s.isFile() || s.size === 0) return false;
205
+ } catch {
206
+ return false;
207
+ }
208
+ try {
209
+ const actual = await sha256OfFile(localPath);
210
+ return actual === sha256Expected;
211
+ } catch {
212
+ return false;
213
+ }
214
+ }
215
+ async function downloadToFile(spec, localPath, onProgress) {
216
+ assertNetworkAllowed(
217
+ `${spec.name} \uBAA8\uB378 \uB2E4\uC6B4\uB85C\uB4DC`,
218
+ spec.offlineHint ?? "\uC628\uB77C\uC778 PC\uC5D0\uC11C `kordoc models --export <\uB514\uB809\uD1A0\uB9AC>` \uB85C \uB0B4\uBCF4\uB0B8 \uB4A4 \uC774 PC\uC5D0\uC11C `kordoc models --import <\uB514\uB809\uD1A0\uB9AC>` \uD558\uAC70\uB098, KORDOC_MODEL_CACHE \uB85C \uBAA8\uB378 \uCE90\uC2DC \uACBD\uB85C\uB97C \uC9C0\uC815\uD558\uC138\uC694"
219
+ );
220
+ const partPath = modelDownloadPartialPath(localPath);
221
+ await mkdir(dirname2(localPath), { recursive: true });
222
+ try {
223
+ const resp = await fetch(spec.url, {
224
+ headers: {
225
+ // HF CDN 은 UA 없으면 가끔 403 을 뱉는다
226
+ "User-Agent": "kordoc-formula-ocr/1.0 (+https://github.com/chrisryugj/kordoc)"
227
+ }
228
+ });
229
+ if (!resp.ok || !resp.body) {
230
+ throw new Error(
231
+ `${spec.name} \uB2E4\uC6B4\uB85C\uB4DC \uC2E4\uD328: HTTP ${resp.status} ${resp.statusText} (${spec.url})`
232
+ );
233
+ }
234
+ const lenHeader = resp.headers.get("content-length");
235
+ const total = lenHeader ? Number.parseInt(lenHeader, 10) : null;
236
+ let downloaded = 0;
237
+ const maxBytes = Math.max(spec.sizeMb * 1.5, spec.sizeMb + 8) * 1024 * 1024;
238
+ const ws = createWriteStream(partPath);
239
+ try {
240
+ const reader = Readable.fromWeb(resp.body);
241
+ reader.on("data", (chunk) => {
242
+ downloaded += chunk.length;
243
+ if (downloaded > maxBytes) reader.destroy(new Error(`\uC751\uB2F5\uC774 \uC608\uC0C1 \uD06C\uAE30(${spec.sizeMb}MB)\uB97C \uD06C\uAC8C \uB118\uC2B5\uB2C8\uB2E4`));
244
+ onProgress?.({
245
+ spec,
246
+ downloaded,
247
+ total,
248
+ phase: "download"
249
+ });
250
+ });
251
+ await pipeline(reader, ws);
252
+ } catch (e) {
253
+ throw new Error(`${spec.name} \uC2A4\uD2B8\uB9AC\uBC0D \uC2E4\uD328: ${e.message}`);
254
+ }
255
+ onProgress?.({
256
+ spec,
257
+ downloaded,
258
+ total,
259
+ phase: "verify"
260
+ });
261
+ let actual;
262
+ try {
263
+ actual = await sha256OfFile(partPath);
264
+ } catch (e) {
265
+ throw new Error(`${spec.name} SHA \uACC4\uC0B0 \uC2E4\uD328: ${e.message}`);
266
+ }
267
+ if (actual !== spec.sha256) {
268
+ throw new Error(
269
+ `${spec.name} SHA256 mismatch: expected ${spec.sha256}, got ${actual} \u2014 \uBAA8\uB378 URL \uC774 \uC624\uC5FC\uB418\uC5C8\uAC70\uB098 \uC804\uC1A1 \uC911 \uC190\uC0C1\uB418\uC5C8\uC2B5\uB2C8\uB2E4.`
270
+ );
271
+ }
272
+ try {
273
+ await rename(partPath, localPath);
274
+ } catch (err) {
275
+ if (!await isExistingValid(localPath, spec.sha256)) throw err;
276
+ }
277
+ onProgress?.({
278
+ spec,
279
+ downloaded,
280
+ total,
281
+ phase: "done"
282
+ });
283
+ } finally {
284
+ try {
285
+ await unlink2(partPath);
286
+ } catch {
287
+ }
288
+ }
289
+ }
290
+ async function sha256OfFile(p) {
291
+ const h = createHash2("sha256");
292
+ const stream = createReadStream(p);
293
+ await pipeline(stream, async function* (src) {
294
+ for await (const chunk of src) {
295
+ h.update(chunk);
296
+ }
297
+ });
298
+ return h.digest("hex");
299
+ }
300
+
301
+ export {
302
+ MFD_MODEL,
303
+ MFR_ENCODER_MODEL,
304
+ MFR_DECODER_MODEL,
305
+ MFR_TOKENIZER,
306
+ ALL_FORMULA_MODELS,
307
+ getModelsDir,
308
+ getFormulaModelsDir,
309
+ getFormulaModelStatus,
310
+ ensureModelsIn,
311
+ ensureFormulaModels,
312
+ ensureSingleModel
313
+ };