@zh-keyboard/pinyin 1.1.0 → 1.1.2

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/dist/index.js CHANGED
@@ -1,37 +1,23 @@
1
- "use strict";
2
-
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
2
  //#region data/rime-api.js
4
3
  async function createRimeModule(moduleArg = {}) {
5
- let moduleRtn;
6
- const Module = moduleArg;
7
- const ENVIRONMENT_IS_WEB = !!globalThis.window;
8
- const ENVIRONMENT_IS_WORKER = !!globalThis.WorkerGlobalScope;
9
- const ENVIRONMENT_IS_NODE = globalThis.process?.versions?.node && globalThis.process?.type != "renderer";
10
- if (ENVIRONMENT_IS_NODE) {
11
- const { createRequire } = await import("node:module");
12
- var require$1 = createRequire(require("url").pathToFileURL(__filename).href);
13
- }
14
- if (!Module.expectedDataFileDownloads) Module.expectedDataFileDownloads = 0;
15
- Module.expectedDataFileDownloads++;
4
+ var moduleRtn;
5
+ var Module = moduleArg;
6
+ var ENVIRONMENT_IS_WEB = true;
7
+ var ENVIRONMENT_IS_WORKER = false;
8
+ if (!Module["expectedDataFileDownloads"]) Module["expectedDataFileDownloads"] = 0;
9
+ Module["expectedDataFileDownloads"]++;
16
10
  (() => {
17
- const isPthread = typeof ENVIRONMENT_IS_PTHREAD != "undefined" && ENVIRONMENT_IS_PTHREAD;
18
- const isWasmWorker = typeof ENVIRONMENT_IS_WASM_WORKER != "undefined" && ENVIRONMENT_IS_WASM_WORKER;
19
- if (isPthread || isWasmWorker) return;
20
- const isNode = globalThis.process && globalThis.process.versions && globalThis.process.versions.node && globalThis.process.type != "renderer";
11
+ if (typeof ENVIRONMENT_IS_PTHREAD != "undefined" && ENVIRONMENT_IS_PTHREAD || typeof ENVIRONMENT_IS_WASM_WORKER != "undefined" && ENVIRONMENT_IS_WASM_WORKER) return;
21
12
  async function loadPackage(metadata) {
22
- let PACKAGE_PATH = "";
23
- if (typeof window === "object") PACKAGE_PATH = window.encodeURIComponent(`${window.location.pathname.substring(0, window.location.pathname.lastIndexOf("/"))}/`);
24
- else if (typeof process === "undefined" && typeof location !== "undefined") PACKAGE_PATH = encodeURIComponent(`${location.pathname.substring(0, location.pathname.lastIndexOf("/"))}/`);
25
- const PACKAGE_NAME = "/home/zzx/work/librime/wasm/dist/rime-api.data";
26
- const REMOTE_PACKAGE_BASE = "rime-api.data";
27
- const REMOTE_PACKAGE_NAME = Module.locateFile ? Module.locateFile(REMOTE_PACKAGE_BASE, "") : REMOTE_PACKAGE_BASE;
28
- const REMOTE_PACKAGE_SIZE = metadata.remote_package_size;
13
+ if (typeof window === "object") window["encodeURIComponent"](window.location.pathname.substring(0, window.location.pathname.lastIndexOf("/")) + "/");
14
+ else if (typeof process === "undefined" && typeof location !== "undefined") encodeURIComponent(location.pathname.substring(0, location.pathname.lastIndexOf("/")) + "/");
15
+ var PACKAGE_NAME = "/home/zzx/work/librime/wasm/dist/rime-api.data";
16
+ var REMOTE_PACKAGE_BASE = "rime-api.data";
17
+ var REMOTE_PACKAGE_NAME = Module["locateFile"] ? Module["locateFile"](REMOTE_PACKAGE_BASE, "") : REMOTE_PACKAGE_BASE;
18
+ var REMOTE_PACKAGE_SIZE = metadata["remote_package_size"];
29
19
  async function fetchRemotePackage(packageName, packageSize) {
30
- if (isNode) {
31
- const contents = require$1("node:fs").readFileSync(packageName);
32
- return new Uint8Array(contents).buffer;
33
- }
34
- if (!Module.dataFileDownloads) Module.dataFileDownloads = {};
20
+ if (!Module["dataFileDownloads"]) Module["dataFileDownloads"] = {};
35
21
  try {
36
22
  var response = await fetch(packageName);
37
23
  } catch (e) {
@@ -42,24 +28,24 @@ async function createRimeModule(moduleArg = {}) {
42
28
  const headers = response.headers;
43
29
  const total = Number(headers.get("Content-Length") || packageSize);
44
30
  let loaded = 0;
45
- Module.setStatus && Module.setStatus("Downloading data...");
31
+ Module["setStatus"] && Module["setStatus"]("Downloading data...");
46
32
  const reader = response.body.getReader();
47
33
  while (1) {
48
- const { done, value } = await reader.read();
34
+ var { done, value } = await reader.read();
49
35
  if (done) break;
50
36
  chunks.push(value);
51
37
  loaded += value.length;
52
- Module.dataFileDownloads[packageName] = {
38
+ Module["dataFileDownloads"][packageName] = {
53
39
  loaded,
54
40
  total
55
41
  };
56
42
  let totalLoaded = 0;
57
43
  let totalSize = 0;
58
- for (const download of Object.values(Module.dataFileDownloads)) {
44
+ for (const download of Object.values(Module["dataFileDownloads"])) {
59
45
  totalLoaded += download.loaded;
60
46
  totalSize += download.total;
61
47
  }
62
- Module.setStatus && Module.setStatus(`Downloading data... (${totalLoaded}/${totalSize})`);
48
+ Module["setStatus"] && Module["setStatus"](`Downloading data... (${totalLoaded}/${totalSize})`);
63
49
  }
64
50
  const packageData = new Uint8Array(chunks.map((c) => c.length).reduce((a, b) => a + b, 0));
65
51
  let offset = 0;
@@ -69,41 +55,41 @@ async function createRimeModule(moduleArg = {}) {
69
55
  }
70
56
  return packageData.buffer;
71
57
  }
72
- let fetchPromise;
73
- let fetched = Module.getPreloadedPackage && Module.getPreloadedPackage(REMOTE_PACKAGE_NAME, REMOTE_PACKAGE_SIZE);
58
+ var fetchPromise;
59
+ var fetched = Module["getPreloadedPackage"] && Module["getPreloadedPackage"](REMOTE_PACKAGE_NAME, REMOTE_PACKAGE_SIZE);
74
60
  if (!fetched) fetchPromise = fetchRemotePackage(REMOTE_PACKAGE_NAME, REMOTE_PACKAGE_SIZE);
75
- async function runWithFS(Module$1) {
61
+ async function runWithFS(Module) {
76
62
  function assert(check, msg) {
77
63
  if (!check) throw new Error(msg);
78
64
  }
79
- Module$1.FS_createPath("/", "rime", true, true);
80
- Module$1.FS_createPath("/rime", "opencc", true, true);
81
- for (const file of metadata.files) {
82
- const name = file.filename;
83
- Module$1.addRunDependency(`fp ${name}`);
65
+ Module["FS_createPath"]("/", "rime", true, true);
66
+ Module["FS_createPath"]("/rime", "opencc", true, true);
67
+ for (var file of metadata["files"]) {
68
+ var name = file["filename"];
69
+ Module["addRunDependency"](`fp ${name}`);
84
70
  }
85
71
  async function processPackageData(arrayBuffer) {
86
72
  assert(arrayBuffer, "Loading data file failed.");
87
- assert(arrayBuffer.constructor.name === ArrayBuffer.name, `bad input to processPackageData ${arrayBuffer.constructor.name}`);
88
- const byteArray = new Uint8Array(arrayBuffer);
89
- for (const file of metadata.files) {
90
- const name = file.filename;
91
- const data = byteArray.subarray(file.start, file.end);
92
- Module$1.FS_createDataFile(name, null, data, true, true, true);
93
- Module$1.removeRunDependency(`fp ${name}`);
73
+ assert(arrayBuffer.constructor.name === ArrayBuffer.name, "bad input to processPackageData " + arrayBuffer.constructor.name);
74
+ var byteArray = new Uint8Array(arrayBuffer);
75
+ for (var file of metadata["files"]) {
76
+ var name = file["filename"];
77
+ var data = byteArray.subarray(file["start"], file["end"]);
78
+ Module["FS_createDataFile"](name, null, data, true, true, true);
79
+ Module["removeRunDependency"](`fp ${name}`);
94
80
  }
95
- Module$1.removeRunDependency("datafile_/home/zzx/work/librime/wasm/dist/rime-api.data");
81
+ Module["removeRunDependency"]("datafile_/home/zzx/work/librime/wasm/dist/rime-api.data");
96
82
  }
97
- Module$1.addRunDependency("datafile_/home/zzx/work/librime/wasm/dist/rime-api.data");
98
- if (!Module$1.preloadResults) Module$1.preloadResults = {};
99
- Module$1.preloadResults[PACKAGE_NAME] = { fromCache: false };
83
+ Module["addRunDependency"]("datafile_/home/zzx/work/librime/wasm/dist/rime-api.data");
84
+ if (!Module["preloadResults"]) Module["preloadResults"] = {};
85
+ Module["preloadResults"][PACKAGE_NAME] = { fromCache: false };
100
86
  if (!fetched) fetched = await fetchPromise;
101
87
  processPackageData(fetched);
102
88
  }
103
- if (Module.calledRun) runWithFS(Module);
89
+ if (Module["calledRun"]) runWithFS(Module);
104
90
  else {
105
- if (!Module.preRun) Module.preRun = [];
106
- Module.preRun.push(runWithFS);
91
+ if (!Module["preRun"]) Module["preRun"] = [];
92
+ Module["preRun"].push(runWithFS);
107
93
  }
108
94
  }
109
95
  loadPackage({
@@ -142,128 +128,82 @@ async function createRimeModule(moduleArg = {}) {
142
128
  remote_package_size: 1027747
143
129
  });
144
130
  })();
145
- let arguments_ = [];
146
- let thisProgram = "./this.program";
147
- let quit_ = (status, toThrow) => {
131
+ var thisProgram = "./this.program";
132
+ var quit_ = (status, toThrow) => {
148
133
  throw toThrow;
149
134
  };
150
- const _scriptName = require("url").pathToFileURL(__filename).href;
151
- let scriptDirectory = "";
135
+ var _scriptName = require("url").pathToFileURL(__filename).href;
136
+ var scriptDirectory = "";
152
137
  function locateFile(path) {
153
- if (Module.locateFile) return Module.locateFile(path, scriptDirectory);
138
+ if (Module["locateFile"]) return Module["locateFile"](path, scriptDirectory);
154
139
  return scriptDirectory + path;
155
140
  }
156
- let readAsync, readBinary;
157
- if (ENVIRONMENT_IS_NODE) {
158
- var fs = require$1("node:fs");
159
- if (_scriptName.startsWith("file:")) scriptDirectory = `${require$1("node:path").dirname(require$1("node:url").fileURLToPath(_scriptName))}/`;
160
- readBinary = (filename) => {
161
- filename = isFileURI(filename) ? new URL(filename) : filename;
162
- const ret = fs.readFileSync(filename);
163
- return ret;
164
- };
165
- readAsync = async (filename, binary = true) => {
166
- filename = isFileURI(filename) ? new URL(filename) : filename;
167
- const ret = fs.readFileSync(filename, binary ? void 0 : "utf8");
168
- return ret;
169
- };
170
- if (process.argv.length > 1) thisProgram = process.argv[1].replace(/\\/g, "/");
171
- arguments_ = process.argv.slice(2);
172
- quit_ = (status, toThrow) => {
173
- process.exitCode = status;
174
- throw toThrow;
175
- };
176
- } else if (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER) {
141
+ var readAsync, readBinary;
142
+ if (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER) {
177
143
  try {
178
144
  scriptDirectory = new URL(".", _scriptName).href;
179
145
  } catch {}
180
- {
181
- if (ENVIRONMENT_IS_WORKER) readBinary = (url) => {
182
- const xhr = new XMLHttpRequest();
183
- xhr.open("GET", url, false);
184
- xhr.responseType = "arraybuffer";
185
- xhr.send(null);
186
- return new Uint8Array(xhr.response);
187
- };
188
- readAsync = async (url) => {
189
- if (isFileURI(url)) return new Promise((resolve, reject) => {
190
- const xhr = new XMLHttpRequest();
191
- xhr.open("GET", url, true);
192
- xhr.responseType = "arraybuffer";
193
- xhr.onload = () => {
194
- if (xhr.status == 200 || xhr.status == 0 && xhr.response) {
195
- resolve(xhr.response);
196
- return;
197
- }
198
- reject(xhr.status);
199
- };
200
- xhr.onerror = reject;
201
- xhr.send(null);
202
- });
203
- const response = await fetch(url, { credentials: "same-origin" });
204
- if (response.ok) return response.arrayBuffer();
205
- throw new Error(`${response.status} : ${response.url}`);
206
- };
207
- }
146
+ readAsync = async (url) => {
147
+ var response = await fetch(url, { credentials: "same-origin" });
148
+ if (response.ok) return response.arrayBuffer();
149
+ throw new Error(response.status + " : " + response.url);
150
+ };
208
151
  }
209
- let out = console.log.bind(console);
210
- let err = console.error.bind(console);
211
- let wasmBinary;
212
- let ABORT = false;
213
- let EXITSTATUS;
214
- var isFileURI = (filename) => filename.startsWith("file://");
215
- let readyPromiseResolve, readyPromiseReject;
216
- let HEAP8, HEAPU8, HEAP16, HEAPU16, HEAP32, HEAPU32, HEAPF32, HEAPF64;
217
- let HEAP64, HEAPU64;
218
- let runtimeInitialized = false;
152
+ var out = console.log.bind(console);
153
+ var err = console.error.bind(console);
154
+ var wasmBinary;
155
+ var ABORT = false;
156
+ var EXITSTATUS;
157
+ var readyPromiseResolve, readyPromiseReject, HEAP8, HEAPU8, HEAP16, HEAP32, HEAPU32, HEAP64;
158
+ var runtimeInitialized = false;
219
159
  function updateMemoryViews() {
220
- const b = wasmMemory.buffer;
160
+ var b = wasmMemory.buffer;
221
161
  HEAP8 = new Int8Array(b);
222
162
  HEAP16 = new Int16Array(b);
223
163
  HEAPU8 = new Uint8Array(b);
224
- HEAPU16 = new Uint16Array(b);
164
+ new Uint16Array(b);
225
165
  HEAP32 = new Int32Array(b);
226
166
  HEAPU32 = new Uint32Array(b);
227
- HEAPF32 = new Float32Array(b);
228
- HEAPF64 = new Float64Array(b);
167
+ new Float32Array(b);
168
+ new Float64Array(b);
229
169
  HEAP64 = new BigInt64Array(b);
230
- HEAPU64 = new BigUint64Array(b);
170
+ new BigUint64Array(b);
231
171
  }
232
172
  function preRun() {
233
- if (Module.preRun) {
234
- if (typeof Module.preRun == "function") Module.preRun = [Module.preRun];
235
- while (Module.preRun.length) addOnPreRun(Module.preRun.shift());
173
+ if (Module["preRun"]) {
174
+ if (typeof Module["preRun"] == "function") Module["preRun"] = [Module["preRun"]];
175
+ while (Module["preRun"].length) addOnPreRun(Module["preRun"].shift());
236
176
  }
237
177
  callRuntimeCallbacks(onPreRuns);
238
178
  }
239
179
  function initRuntime() {
240
180
  runtimeInitialized = true;
241
- if (!Module.noFSInit && !FS.initialized) FS.init();
181
+ if (!Module["noFSInit"] && !FS.initialized) FS.init();
242
182
  TTY.init();
243
- wasmExports.Q();
183
+ wasmExports["Q"]();
244
184
  FS.ignorePermissions = false;
245
185
  }
246
186
  function postRun() {
247
- if (Module.postRun) {
248
- if (typeof Module.postRun == "function") Module.postRun = [Module.postRun];
249
- while (Module.postRun.length) addOnPostRun(Module.postRun.shift());
187
+ if (Module["postRun"]) {
188
+ if (typeof Module["postRun"] == "function") Module["postRun"] = [Module["postRun"]];
189
+ while (Module["postRun"].length) addOnPostRun(Module["postRun"].shift());
250
190
  }
251
191
  callRuntimeCallbacks(onPostRuns);
252
192
  }
253
193
  function abort(what) {
254
- Module.onAbort?.(what);
255
- what = `Aborted(${what})`;
194
+ Module["onAbort"]?.(what);
195
+ what = "Aborted(" + what + ")";
256
196
  err(what);
257
197
  ABORT = true;
258
198
  what += ". Build with -sASSERTIONS for more info.";
259
199
  if (runtimeInitialized) ___trap();
260
- const e = new WebAssembly.RuntimeError(what);
200
+ var e = new WebAssembly.RuntimeError(what);
261
201
  readyPromiseReject?.(e);
262
202
  throw e;
263
203
  }
264
- let wasmBinaryFile;
204
+ var wasmBinaryFile;
265
205
  function findWasmBinary() {
266
- if (Module.locateFile) return locateFile("rime-api.wasm");
206
+ if (Module["locateFile"]) return locateFile("rime-api.wasm");
267
207
  return new URL("rime-api.wasm", require("url").pathToFileURL(__filename).href).href;
268
208
  }
269
209
  function getBinarySync(file) {
@@ -273,26 +213,24 @@ async function createRimeModule(moduleArg = {}) {
273
213
  }
274
214
  async function getWasmBinary(binaryFile) {
275
215
  if (!wasmBinary) try {
276
- const response = await readAsync(binaryFile);
216
+ var response = await readAsync(binaryFile);
277
217
  return new Uint8Array(response);
278
218
  } catch {}
279
219
  return getBinarySync(binaryFile);
280
220
  }
281
221
  async function instantiateArrayBuffer(binaryFile, imports) {
282
222
  try {
283
- const binary = await getWasmBinary(binaryFile);
284
- const instance = await WebAssembly.instantiate(binary, imports);
285
- return instance;
223
+ var binary = await getWasmBinary(binaryFile);
224
+ return await WebAssembly.instantiate(binary, imports);
286
225
  } catch (reason) {
287
226
  err(`failed to asynchronously prepare wasm: ${reason}`);
288
227
  abort(reason);
289
228
  }
290
229
  }
291
230
  async function instantiateAsync(binary, binaryFile, imports) {
292
- if (!binary && !isFileURI(binaryFile) && !ENVIRONMENT_IS_NODE) try {
293
- const response = fetch(binaryFile, { credentials: "same-origin" });
294
- const instantiationResult = await WebAssembly.instantiateStreaming(response, imports);
295
- return instantiationResult;
231
+ if (!binary) try {
232
+ var response = fetch(binaryFile, { credentials: "same-origin" });
233
+ return await WebAssembly.instantiateStreaming(response, imports);
296
234
  } catch (reason) {
297
235
  err(`wasm streaming compile failed: ${reason}`);
298
236
  err("falling back to ArrayBuffer instantiation");
@@ -300,30 +238,27 @@ async function createRimeModule(moduleArg = {}) {
300
238
  return instantiateArrayBuffer(binaryFile, imports);
301
239
  }
302
240
  function getWasmImports() {
303
- const imports = { a: wasmImports };
304
- return imports;
241
+ return { a: wasmImports };
305
242
  }
306
243
  async function createWasm() {
307
- function receiveInstance(instance, module$1) {
244
+ function receiveInstance(instance, module) {
308
245
  wasmExports = instance.exports;
309
246
  wasmExports = applySignatureConversions(wasmExports);
310
247
  assignWasmExports(wasmExports);
311
248
  updateMemoryViews();
312
249
  return wasmExports;
313
250
  }
314
- function receiveInstantiationResult(result$1) {
315
- return receiveInstance(result$1.instance);
251
+ function receiveInstantiationResult(result) {
252
+ return receiveInstance(result["instance"]);
316
253
  }
317
- const info = getWasmImports();
318
- if (Module.instantiateWasm) return new Promise((resolve, reject) => {
319
- Module.instantiateWasm(info, (inst, mod) => {
254
+ var info = getWasmImports();
255
+ if (Module["instantiateWasm"]) return new Promise((resolve, reject) => {
256
+ Module["instantiateWasm"](info, (inst, mod) => {
320
257
  resolve(receiveInstance(inst, mod));
321
258
  });
322
259
  });
323
260
  wasmBinaryFile ??= findWasmBinary();
324
- const result = await instantiateAsync(wasmBinary, wasmBinaryFile, info);
325
- const exports$1 = receiveInstantiationResult(result);
326
- return exports$1;
261
+ return receiveInstantiationResult(await instantiateAsync(wasmBinary, wasmBinaryFile, info));
327
262
  }
328
263
  class ExitStatus {
329
264
  name = "ExitStatus";
@@ -339,17 +274,16 @@ async function createRimeModule(moduleArg = {}) {
339
274
  var addOnPostRun = (cb) => onPostRuns.push(cb);
340
275
  var onPreRuns = [];
341
276
  var addOnPreRun = (cb) => onPreRuns.push(cb);
342
- let noExitRuntime = true;
277
+ var noExitRuntime = true;
343
278
  var PATH = {
344
279
  isAbs: (path) => path.charAt(0) === "/",
345
280
  splitPath: (filename) => {
346
- const splitPathRe = /^(\/?|)([\s\S]*?)((?:\.{1,2}|[^/]+?)?(\.[^./]*|))\/*$/;
347
- return splitPathRe.exec(filename).slice(1);
281
+ return /^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/.exec(filename).slice(1);
348
282
  },
349
283
  normalizeArray: (parts, allowAboveRoot) => {
350
- let up = 0;
351
- for (let i = parts.length - 1; i >= 0; i--) {
352
- const last = parts[i];
284
+ var up = 0;
285
+ for (var i = parts.length - 1; i >= 0; i--) {
286
+ var last = parts[i];
353
287
  if (last === ".") parts.splice(i, 1);
354
288
  else if (last === "..") {
355
289
  parts.splice(i, 1);
@@ -363,44 +297,34 @@ async function createRimeModule(moduleArg = {}) {
363
297
  return parts;
364
298
  },
365
299
  normalize: (path) => {
366
- const isAbsolute = PATH.isAbs(path);
367
- const trailingSlash = path.slice(-1) === "/";
300
+ var isAbsolute = PATH.isAbs(path), trailingSlash = path.slice(-1) === "/";
368
301
  path = PATH.normalizeArray(path.split("/").filter((p) => !!p), !isAbsolute).join("/");
369
302
  if (!path && !isAbsolute) path = ".";
370
303
  if (path && trailingSlash) path += "/";
371
304
  return (isAbsolute ? "/" : "") + path;
372
305
  },
373
306
  dirname: (path) => {
374
- const result = PATH.splitPath(path);
375
- const root = result[0];
376
- let dir = result[1];
307
+ var result = PATH.splitPath(path), root = result[0], dir = result[1];
377
308
  if (!root && !dir) return ".";
378
309
  if (dir) dir = dir.slice(0, -1);
379
310
  return root + dir;
380
311
  },
381
- basename: (path) => path && path.match(/([^/]+|\/)\/*$/)[1],
312
+ basename: (path) => path && path.match(/([^\/]+|\/)\/*$/)[1],
382
313
  join: (...paths) => PATH.normalize(paths.join("/")),
383
- join2: (l, r) => PATH.normalize(`${l}/${r}`)
384
- };
385
- const initRandomFill = () => {
386
- if (ENVIRONMENT_IS_NODE) {
387
- const nodeCrypto = require$1("node:crypto");
388
- return (view) => nodeCrypto.randomFillSync(view);
389
- }
390
- return (view) => crypto.getRandomValues(view);
314
+ join2: (l, r) => PATH.normalize(l + "/" + r)
391
315
  };
392
- let randomFill = (view) => {
316
+ var initRandomFill = () => (view) => crypto.getRandomValues(view);
317
+ var randomFill = (view) => {
393
318
  (randomFill = initRandomFill())(view);
394
319
  };
395
320
  var PATH_FS = {
396
321
  resolve: (...args) => {
397
- let resolvedPath = "";
398
- let resolvedAbsolute = false;
399
- for (let i = args.length - 1; i >= -1 && !resolvedAbsolute; i--) {
400
- const path = i >= 0 ? args[i] : FS.cwd();
322
+ var resolvedPath = "", resolvedAbsolute = false;
323
+ for (var i = args.length - 1; i >= -1 && !resolvedAbsolute; i--) {
324
+ var path = i >= 0 ? args[i] : FS.cwd();
401
325
  if (typeof path != "string") throw new TypeError("Arguments to path.resolve must be strings");
402
326
  else if (!path) return "";
403
- resolvedPath = `${path}/${resolvedPath}`;
327
+ resolvedPath = path + "/" + resolvedPath;
404
328
  resolvedAbsolute = PATH.isAbs(path);
405
329
  }
406
330
  resolvedPath = PATH.normalizeArray(resolvedPath.split("/").filter((p) => !!p), !resolvedAbsolute).join("/");
@@ -410,44 +334,44 @@ async function createRimeModule(moduleArg = {}) {
410
334
  from = PATH_FS.resolve(from).slice(1);
411
335
  to = PATH_FS.resolve(to).slice(1);
412
336
  function trim(arr) {
413
- let start = 0;
337
+ var start = 0;
414
338
  for (; start < arr.length; start++) if (arr[start] !== "") break;
415
- let end = arr.length - 1;
339
+ var end = arr.length - 1;
416
340
  for (; end >= 0; end--) if (arr[end] !== "") break;
417
341
  if (start > end) return [];
418
342
  return arr.slice(start, end - start + 1);
419
343
  }
420
- const fromParts = trim(from.split("/"));
421
- const toParts = trim(to.split("/"));
422
- const length = Math.min(fromParts.length, toParts.length);
423
- let samePartsLength = length;
344
+ var fromParts = trim(from.split("/"));
345
+ var toParts = trim(to.split("/"));
346
+ var length = Math.min(fromParts.length, toParts.length);
347
+ var samePartsLength = length;
424
348
  for (var i = 0; i < length; i++) if (fromParts[i] !== toParts[i]) {
425
349
  samePartsLength = i;
426
350
  break;
427
351
  }
428
- let outputParts = [];
352
+ var outputParts = [];
429
353
  for (var i = samePartsLength; i < fromParts.length; i++) outputParts.push("..");
430
354
  outputParts = outputParts.concat(toParts.slice(samePartsLength));
431
355
  return outputParts.join("/");
432
356
  }
433
357
  };
434
- const UTF8Decoder = new TextDecoder();
435
- const findStringEnd = (heapOrArray, idx, maxBytesToRead, ignoreNul) => {
436
- const maxIdx = idx + maxBytesToRead;
358
+ var UTF8Decoder = new TextDecoder();
359
+ var findStringEnd = (heapOrArray, idx, maxBytesToRead, ignoreNul) => {
360
+ var maxIdx = idx + maxBytesToRead;
437
361
  if (ignoreNul) return maxIdx;
438
362
  while (heapOrArray[idx] && !(idx >= maxIdx)) ++idx;
439
363
  return idx;
440
364
  };
441
- const UTF8ArrayToString = (heapOrArray, idx = 0, maxBytesToRead, ignoreNul) => {
365
+ var UTF8ArrayToString = (heapOrArray, idx = 0, maxBytesToRead, ignoreNul) => {
442
366
  idx >>>= 0;
443
- const endPtr = findStringEnd(heapOrArray, idx, maxBytesToRead, ignoreNul);
367
+ var endPtr = findStringEnd(heapOrArray, idx, maxBytesToRead, ignoreNul);
444
368
  return UTF8Decoder.decode(heapOrArray.buffer ? heapOrArray.subarray(idx, endPtr) : new Uint8Array(heapOrArray.slice(idx, endPtr)));
445
369
  };
446
- let FS_stdin_getChar_buffer = [];
447
- const lengthBytesUTF8 = (str) => {
448
- let len = 0;
449
- for (let i = 0; i < str.length; ++i) {
450
- const c = str.charCodeAt(i);
370
+ var FS_stdin_getChar_buffer = [];
371
+ var lengthBytesUTF8 = (str) => {
372
+ var len = 0;
373
+ for (var i = 0; i < str.length; ++i) {
374
+ var c = str.charCodeAt(i);
451
375
  if (c <= 127) len++;
452
376
  else if (c <= 2047) len += 2;
453
377
  else if (c >= 55296 && c <= 57343) {
@@ -457,13 +381,13 @@ async function createRimeModule(moduleArg = {}) {
457
381
  }
458
382
  return len;
459
383
  };
460
- const stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
384
+ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
461
385
  outIdx >>>= 0;
462
386
  if (!(maxBytesToWrite > 0)) return 0;
463
- const startIdx = outIdx;
464
- const endIdx = outIdx + maxBytesToWrite - 1;
465
- for (let i = 0; i < str.length; ++i) {
466
- const u = str.codePointAt(i);
387
+ var startIdx = outIdx;
388
+ var endIdx = outIdx + maxBytesToWrite - 1;
389
+ for (var i = 0; i < str.length; ++i) {
390
+ var u = str.codePointAt(i);
467
391
  if (u <= 127) {
468
392
  if (outIdx >= endIdx) break;
469
393
  heap[outIdx++ >>> 0] = u;
@@ -488,29 +412,17 @@ async function createRimeModule(moduleArg = {}) {
488
412
  heap[outIdx >>> 0] = 0;
489
413
  return outIdx - startIdx;
490
414
  };
491
- const intArrayFromString = (stringy, dontAddNull, length) => {
492
- const len = length > 0 ? length : lengthBytesUTF8(stringy) + 1;
493
- const u8array = new Array(len);
494
- const numBytesWritten = stringToUTF8Array(stringy, u8array, 0, u8array.length);
415
+ var intArrayFromString = (stringy, dontAddNull, length) => {
416
+ var len = length > 0 ? length : lengthBytesUTF8(stringy) + 1;
417
+ var u8array = new Array(len);
418
+ var numBytesWritten = stringToUTF8Array(stringy, u8array, 0, u8array.length);
495
419
  if (dontAddNull) u8array.length = numBytesWritten;
496
420
  return u8array;
497
421
  };
498
- const FS_stdin_getChar = () => {
422
+ var FS_stdin_getChar = () => {
499
423
  if (!FS_stdin_getChar_buffer.length) {
500
- let result = null;
501
- if (ENVIRONMENT_IS_NODE) {
502
- const BUFSIZE = 256;
503
- const buf = Buffer.alloc(BUFSIZE);
504
- let bytesRead = 0;
505
- const fd = process.stdin.fd;
506
- try {
507
- bytesRead = fs.readSync(fd, buf, 0, BUFSIZE);
508
- } catch (e) {
509
- if (e.toString().includes("EOF")) bytesRead = 0;
510
- else throw e;
511
- }
512
- if (bytesRead > 0) result = buf.slice(0, bytesRead).toString("utf-8");
513
- } else if (globalThis.window?.prompt) {
424
+ var result = null;
425
+ if (globalThis.window?.prompt) {
514
426
  result = window.prompt("Input: ");
515
427
  if (result !== null) result += "\n";
516
428
  }
@@ -533,7 +445,7 @@ async function createRimeModule(moduleArg = {}) {
533
445
  },
534
446
  stream_ops: {
535
447
  open(stream) {
536
- const tty = TTY.ttys[stream.node.rdev];
448
+ var tty = TTY.ttys[stream.node.rdev];
537
449
  if (!tty) throw new FS.ErrnoError(43);
538
450
  stream.tty = tty;
539
451
  stream.seekable = false;
@@ -546,8 +458,8 @@ async function createRimeModule(moduleArg = {}) {
546
458
  },
547
459
  read(stream, buffer, offset, length, pos) {
548
460
  if (!stream.tty || !stream.tty.ops.get_char) throw new FS.ErrnoError(60);
549
- let bytesRead = 0;
550
- for (let i = 0; i < length; i++) {
461
+ var bytesRead = 0;
462
+ for (var i = 0; i < length; i++) {
551
463
  var result;
552
464
  try {
553
465
  result = stream.tty.ops.get_char(stream.tty);
@@ -653,11 +565,11 @@ async function createRimeModule(moduleArg = {}) {
653
565
  }
654
566
  }
655
567
  };
656
- const zeroMemory = (ptr, size) => HEAPU8.fill(0, ptr, ptr + size);
657
- const alignMemory = (size, alignment) => Math.ceil(size / alignment) * alignment;
658
- const mmapAlloc = (size) => {
568
+ var zeroMemory = (ptr, size) => HEAPU8.fill(0, ptr, ptr + size);
569
+ var alignMemory = (size, alignment) => Math.ceil(size / alignment) * alignment;
570
+ var mmapAlloc = (size) => {
659
571
  size = alignMemory(size, 65536);
660
- const ptr = _emscripten_builtin_memalign(65536, size);
572
+ var ptr = _emscripten_builtin_memalign(65536, size);
661
573
  if (ptr) zeroMemory(ptr, size);
662
574
  return ptr;
663
575
  };
@@ -712,7 +624,7 @@ async function createRimeModule(moduleArg = {}) {
712
624
  stream: FS.chrdev_stream_ops
713
625
  }
714
626
  };
715
- const node = FS.createNode(parent, name, mode, dev);
627
+ var node = FS.createNode(parent, name, mode, dev);
716
628
  if (FS.isDir(node.mode)) {
717
629
  node.node_ops = MEMFS.ops_table.dir.node;
718
630
  node.stream_ops = MEMFS.ops_table.dir.stream;
@@ -742,12 +654,11 @@ async function createRimeModule(moduleArg = {}) {
742
654
  return new Uint8Array(node.contents);
743
655
  },
744
656
  expandFileStorage(node, newCapacity) {
745
- const prevCapacity = node.contents ? node.contents.length : 0;
657
+ var prevCapacity = node.contents ? node.contents.length : 0;
746
658
  if (prevCapacity >= newCapacity) return;
747
- const CAPACITY_DOUBLING_MAX = 1024 * 1024;
748
- newCapacity = Math.max(newCapacity, prevCapacity * (prevCapacity < CAPACITY_DOUBLING_MAX ? 2 : 1.125) >>> 0);
659
+ newCapacity = Math.max(newCapacity, prevCapacity * (prevCapacity < 1024 * 1024 ? 2 : 1.125) >>> 0);
749
660
  if (prevCapacity != 0) newCapacity = Math.max(newCapacity, 256);
750
- const oldContents = node.contents;
661
+ var oldContents = node.contents;
751
662
  node.contents = new Uint8Array(newCapacity);
752
663
  if (node.usedBytes > 0) node.contents.set(oldContents.subarray(0, node.usedBytes), 0);
753
664
  },
@@ -757,7 +668,7 @@ async function createRimeModule(moduleArg = {}) {
757
668
  node.contents = null;
758
669
  node.usedBytes = 0;
759
670
  } else {
760
- const oldContents = node.contents;
671
+ var oldContents = node.contents;
761
672
  node.contents = new Uint8Array(newSize);
762
673
  if (oldContents) node.contents.set(oldContents.subarray(0, Math.min(newSize, node.usedBytes)));
763
674
  node.usedBytes = newSize;
@@ -765,7 +676,7 @@ async function createRimeModule(moduleArg = {}) {
765
676
  },
766
677
  node_ops: {
767
678
  getattr(node) {
768
- const attr = {};
679
+ var attr = {};
769
680
  attr.dev = FS.isChrdev(node.mode) ? node.id : 1;
770
681
  attr.ino = node.id;
771
682
  attr.mode = node.mode;
@@ -804,12 +715,12 @@ async function createRimeModule(moduleArg = {}) {
804
715
  return MEMFS.createNode(parent, name, mode, dev);
805
716
  },
806
717
  rename(old_node, new_dir, new_name) {
807
- let new_node;
718
+ var new_node;
808
719
  try {
809
720
  new_node = FS.lookupNode(new_dir, new_name);
810
721
  } catch (e) {}
811
722
  if (new_node) {
812
- if (FS.isDir(old_node.mode)) for (const i in new_node.contents) throw new FS.ErrnoError(55);
723
+ if (FS.isDir(old_node.mode)) for (var i in new_node.contents) throw new FS.ErrnoError(55);
813
724
  FS.hashRemoveNode(new_node);
814
725
  }
815
726
  delete old_node.parent.contents[old_node.name];
@@ -822,8 +733,7 @@ async function createRimeModule(moduleArg = {}) {
822
733
  parent.ctime = parent.mtime = Date.now();
823
734
  },
824
735
  rmdir(parent, name) {
825
- const node = FS.lookupNode(parent, name);
826
- for (const i in node.contents) throw new FS.ErrnoError(55);
736
+ for (var i in FS.lookupNode(parent, name).contents) throw new FS.ErrnoError(55);
827
737
  delete parent.contents[name];
828
738
  parent.ctime = parent.mtime = Date.now();
829
739
  },
@@ -835,7 +745,7 @@ async function createRimeModule(moduleArg = {}) {
835
745
  ];
836
746
  },
837
747
  symlink(parent, newname, oldpath) {
838
- const node = MEMFS.createNode(parent, newname, 41471, 0);
748
+ var node = MEMFS.createNode(parent, newname, 41471, 0);
839
749
  node.link = oldpath;
840
750
  return node;
841
751
  },
@@ -846,17 +756,17 @@ async function createRimeModule(moduleArg = {}) {
846
756
  },
847
757
  stream_ops: {
848
758
  read(stream, buffer, offset, length, position) {
849
- const contents = stream.node.contents;
759
+ var contents = stream.node.contents;
850
760
  if (position >= stream.node.usedBytes) return 0;
851
- const size = Math.min(stream.node.usedBytes - position, length);
761
+ var size = Math.min(stream.node.usedBytes - position, length);
852
762
  if (size > 8 && contents.subarray) buffer.set(contents.subarray(position, position + size), offset);
853
- else for (let i = 0; i < size; i++) buffer[offset + i] = contents[position + i];
763
+ else for (var i = 0; i < size; i++) buffer[offset + i] = contents[position + i];
854
764
  return size;
855
765
  },
856
766
  write(stream, buffer, offset, length, position, canOwn) {
857
767
  if (buffer.buffer === HEAP8.buffer) canOwn = false;
858
768
  if (!length) return 0;
859
- const node = stream.node;
769
+ var node = stream.node;
860
770
  node.mtime = node.ctime = Date.now();
861
771
  if (buffer.subarray && (!node.contents || node.contents.subarray)) {
862
772
  if (canOwn) {
@@ -874,12 +784,12 @@ async function createRimeModule(moduleArg = {}) {
874
784
  }
875
785
  MEMFS.expandFileStorage(node, position + length);
876
786
  if (node.contents.subarray && buffer.subarray) node.contents.set(buffer.subarray(offset, offset + length), position);
877
- else for (let i = 0; i < length; i++) node.contents[position + i] = buffer[offset + i];
787
+ else for (var i = 0; i < length; i++) node.contents[position + i] = buffer[offset + i];
878
788
  node.usedBytes = Math.max(node.usedBytes, position + length);
879
789
  return length;
880
790
  },
881
791
  llseek(stream, offset, whence) {
882
- let position = offset;
792
+ var position = offset;
883
793
  if (whence === 1) position += stream.position;
884
794
  else if (whence === 2) {
885
795
  if (FS.isFile(stream.node.mode)) position += stream.node.usedBytes;
@@ -889,9 +799,9 @@ async function createRimeModule(moduleArg = {}) {
889
799
  },
890
800
  mmap(stream, length, position, prot, flags) {
891
801
  if (!FS.isFile(stream.node.mode)) throw new FS.ErrnoError(43);
892
- let ptr;
893
- let allocated;
894
- let contents = stream.node.contents;
802
+ var ptr;
803
+ var allocated;
804
+ var contents = stream.node.contents;
895
805
  if (!(flags & 2) && contents && contents.buffer === HEAP8.buffer) {
896
806
  allocated = false;
897
807
  ptr = contents.byteOffset;
@@ -916,21 +826,20 @@ async function createRimeModule(moduleArg = {}) {
916
826
  }
917
827
  }
918
828
  };
919
- const FS_modeStringToFlags = (str) => {
920
- const flagModes = {
921
- "r": 0,
829
+ var FS_modeStringToFlags = (str) => {
830
+ var flags = {
831
+ r: 0,
922
832
  "r+": 2,
923
- "w": 577,
833
+ w: 577,
924
834
  "w+": 578,
925
- "a": 1089,
835
+ a: 1089,
926
836
  "a+": 1090
927
- };
928
- const flags = flagModes[str];
929
- if (typeof flags == "undefined") throw new TypeError(`Unknown file open mode: ${str}`);
837
+ }[str];
838
+ if (typeof flags == "undefined") throw new Error(`Unknown file open mode: ${str}`);
930
839
  return flags;
931
840
  };
932
- const FS_getMode = (canRead, canWrite) => {
933
- let mode = 0;
841
+ var FS_getMode = (canRead, canWrite) => {
842
+ var mode = 0;
934
843
  if (canRead) mode |= 365;
935
844
  if (canWrite) mode |= 146;
936
845
  return mode;
@@ -953,13 +862,13 @@ async function createRimeModule(moduleArg = {}) {
953
862
  else if (mount.idbPersistState === "idb") mount.idbPersistState = "again";
954
863
  },
955
864
  mount: (mount) => {
956
- const mnt = MEMFS.mount(mount);
865
+ var mnt = MEMFS.mount(mount);
957
866
  if (mount?.opts?.autoPersist) {
958
867
  mount.idbPersistState = 0;
959
- const memfs_node_ops = mnt.node_ops;
868
+ var memfs_node_ops = mnt.node_ops;
960
869
  mnt.node_ops = { ...mnt.node_ops };
961
870
  mnt.node_ops.mknod = (parent, name, mode, dev) => {
962
- const node = memfs_node_ops.mknod(parent, name, mode, dev);
871
+ var node = memfs_node_ops.mknod(parent, name, mode, dev);
963
872
  node.node_ops = mnt.node_ops;
964
873
  node.idbfs_mount = mnt.mount;
965
874
  node.memfs_stream_ops = node.stream_ops;
@@ -969,7 +878,7 @@ async function createRimeModule(moduleArg = {}) {
969
878
  return node.memfs_stream_ops.write(stream, buffer, offset, length, position, canOwn);
970
879
  };
971
880
  node.stream_ops.close = (stream) => {
972
- const n = stream.node;
881
+ var n = stream.node;
973
882
  if (n.isModified) {
974
883
  IDBFS.queuePersist(n.idbfs_mount);
975
884
  n.isModified = false;
@@ -987,24 +896,24 @@ async function createRimeModule(moduleArg = {}) {
987
896
  return mnt;
988
897
  },
989
898
  syncfs: (mount, populate, callback) => {
990
- IDBFS.getLocalSet(mount, (err$1, local) => {
991
- if (err$1) return callback(err$1);
992
- IDBFS.getRemoteSet(mount, (err$2, remote) => {
993
- if (err$2) return callback(err$2);
994
- const src = populate ? remote : local;
995
- const dst = populate ? local : remote;
899
+ IDBFS.getLocalSet(mount, (err, local) => {
900
+ if (err) return callback(err);
901
+ IDBFS.getRemoteSet(mount, (err, remote) => {
902
+ if (err) return callback(err);
903
+ var src = populate ? remote : local;
904
+ var dst = populate ? local : remote;
996
905
  IDBFS.reconcile(src, dst, callback);
997
906
  });
998
907
  });
999
908
  },
1000
909
  quit: () => {
1001
- for (const value of Object.values(IDBFS.dbs)) value.close();
910
+ for (var value of Object.values(IDBFS.dbs)) value.close();
1002
911
  IDBFS.dbs = {};
1003
912
  },
1004
913
  getDB: (name, callback) => {
1005
- let db = IDBFS.dbs[name];
914
+ var db = IDBFS.dbs[name];
1006
915
  if (db) return callback(null, db);
1007
- let req;
916
+ var req;
1008
917
  try {
1009
918
  req = IDBFS.indexedDB().open(name, IDBFS.DB_VERSION);
1010
919
  } catch (e) {
@@ -1012,11 +921,11 @@ async function createRimeModule(moduleArg = {}) {
1012
921
  }
1013
922
  if (!req) return callback("Unable to connect to IndexedDB");
1014
923
  req.onupgradeneeded = (e) => {
1015
- const db$1 = e.target.result;
1016
- const transaction = e.target.transaction;
1017
- let fileStore;
1018
- if (db$1.objectStoreNames.contains(IDBFS.DB_STORE_NAME)) fileStore = transaction.objectStore(IDBFS.DB_STORE_NAME);
1019
- else fileStore = db$1.createObjectStore(IDBFS.DB_STORE_NAME);
924
+ var db = e.target.result;
925
+ var transaction = e.target.transaction;
926
+ var fileStore;
927
+ if (db.objectStoreNames.contains(IDBFS.DB_STORE_NAME)) fileStore = transaction.objectStore(IDBFS.DB_STORE_NAME);
928
+ else fileStore = db.createObjectStore(IDBFS.DB_STORE_NAME);
1020
929
  if (!fileStore.indexNames.contains("timestamp")) fileStore.createIndex("timestamp", "timestamp", { unique: false });
1021
930
  };
1022
931
  req.onsuccess = () => {
@@ -1030,16 +939,16 @@ async function createRimeModule(moduleArg = {}) {
1030
939
  };
1031
940
  },
1032
941
  getLocalSet: (mount, callback) => {
1033
- const entries = {};
942
+ var entries = {};
1034
943
  function isRealDir(p) {
1035
944
  return p !== "." && p !== "..";
1036
945
  }
1037
946
  function toAbsolute(root) {
1038
947
  return (p) => PATH.join2(root, p);
1039
948
  }
1040
- const check = FS.readdir(mount.mountpoint).filter(isRealDir).map(toAbsolute(mount.mountpoint));
949
+ var check = FS.readdir(mount.mountpoint).filter(isRealDir).map(toAbsolute(mount.mountpoint));
1041
950
  while (check.length) {
1042
- const path = check.pop();
951
+ var path = check.pop();
1043
952
  var stat;
1044
953
  try {
1045
954
  stat = FS.stat(path);
@@ -1055,19 +964,18 @@ async function createRimeModule(moduleArg = {}) {
1055
964
  });
1056
965
  },
1057
966
  getRemoteSet: (mount, callback) => {
1058
- const entries = {};
1059
- IDBFS.getDB(mount.mountpoint, (err$1, db) => {
1060
- if (err$1) return callback(err$1);
967
+ var entries = {};
968
+ IDBFS.getDB(mount.mountpoint, (err, db) => {
969
+ if (err) return callback(err);
1061
970
  try {
1062
- const transaction = db.transaction([IDBFS.DB_STORE_NAME], "readonly");
971
+ var transaction = db.transaction([IDBFS.DB_STORE_NAME], "readonly");
1063
972
  transaction.onerror = (e) => {
1064
973
  callback(e.target.error);
1065
974
  e.preventDefault();
1066
975
  };
1067
- const store = transaction.objectStore(IDBFS.DB_STORE_NAME);
1068
- const index = store.index("timestamp");
976
+ var index = transaction.objectStore(IDBFS.DB_STORE_NAME).index("timestamp");
1069
977
  index.openKeyCursor().onsuccess = (event) => {
1070
- const cursor = event.target.result;
978
+ var cursor = event.target.result;
1071
979
  if (!cursor) return callback(null, {
1072
980
  type: "remote",
1073
981
  db,
@@ -1082,10 +990,9 @@ async function createRimeModule(moduleArg = {}) {
1082
990
  });
1083
991
  },
1084
992
  loadLocalEntry: (path, callback) => {
1085
- let stat, node;
993
+ var stat, node;
1086
994
  try {
1087
- const lookup = FS.lookupPath(path);
1088
- node = lookup.node;
995
+ node = FS.lookupPath(path).node;
1089
996
  stat = FS.stat(path);
1090
997
  } catch (e) {
1091
998
  return callback(e);
@@ -1101,15 +1008,15 @@ async function createRimeModule(moduleArg = {}) {
1101
1008
  mode: stat.mode,
1102
1009
  contents: node.contents
1103
1010
  });
1104
- } else return callback(new Error("node type not supported"));
1011
+ } else return callback(/* @__PURE__ */ new Error("node type not supported"));
1105
1012
  },
1106
1013
  storeLocalEntry: (path, entry, callback) => {
1107
1014
  try {
1108
- if (FS.isDir(entry.mode)) FS.mkdirTree(path, entry.mode);
1109
- else if (FS.isFile(entry.mode)) FS.writeFile(path, entry.contents, { canOwn: true });
1110
- else return callback(new Error("node type not supported"));
1111
- FS.chmod(path, entry.mode);
1112
- FS.utime(path, entry.timestamp, entry.timestamp);
1015
+ if (FS.isDir(entry["mode"])) FS.mkdirTree(path, entry["mode"]);
1016
+ else if (FS.isFile(entry["mode"])) FS.writeFile(path, entry["contents"], { canOwn: true });
1017
+ else return callback(/* @__PURE__ */ new Error("node type not supported"));
1018
+ FS.chmod(path, entry["mode"]);
1019
+ FS.utime(path, entry["timestamp"], entry["timestamp"]);
1113
1020
  } catch (e) {
1114
1021
  return callback(e);
1115
1022
  }
@@ -1117,7 +1024,7 @@ async function createRimeModule(moduleArg = {}) {
1117
1024
  },
1118
1025
  removeLocalEntry: (path, callback) => {
1119
1026
  try {
1120
- const stat = FS.stat(path);
1027
+ var stat = FS.stat(path);
1121
1028
  if (FS.isDir(stat.mode)) FS.rmdir(path);
1122
1029
  else if (FS.isFile(stat.mode)) FS.unlink(path);
1123
1030
  } catch (e) {
@@ -1126,7 +1033,7 @@ async function createRimeModule(moduleArg = {}) {
1126
1033
  callback(null);
1127
1034
  },
1128
1035
  loadRemoteEntry: (store, path, callback) => {
1129
- const req = store.get(path);
1036
+ var req = store.get(path);
1130
1037
  req.onsuccess = (event) => callback(null, event.target.result);
1131
1038
  req.onerror = (e) => {
1132
1039
  callback(e.target.error);
@@ -1147,7 +1054,7 @@ async function createRimeModule(moduleArg = {}) {
1147
1054
  };
1148
1055
  },
1149
1056
  removeRemoteEntry: (store, path, callback) => {
1150
- const req = store.delete(path);
1057
+ var req = store.delete(path);
1151
1058
  req.onsuccess = (event) => callback();
1152
1059
  req.onerror = (e) => {
1153
1060
  callback(e.target.error);
@@ -1155,85 +1062,84 @@ async function createRimeModule(moduleArg = {}) {
1155
1062
  };
1156
1063
  },
1157
1064
  reconcile: (src, dst, callback) => {
1158
- let total = 0;
1159
- const create = [];
1065
+ var total = 0;
1066
+ var create = [];
1160
1067
  for (var [key, e] of Object.entries(src.entries)) {
1161
- const e2 = dst.entries[key];
1162
- if (!e2 || e.timestamp.getTime() != e2.timestamp.getTime()) {
1068
+ var e2 = dst.entries[key];
1069
+ if (!e2 || e["timestamp"].getTime() != e2["timestamp"].getTime()) {
1163
1070
  create.push(key);
1164
1071
  total++;
1165
1072
  }
1166
1073
  }
1167
- const remove = [];
1074
+ var remove = [];
1168
1075
  for (var key of Object.keys(dst.entries)) if (!src.entries[key]) {
1169
1076
  remove.push(key);
1170
1077
  total++;
1171
1078
  }
1172
1079
  if (!total) return callback(null);
1173
- let errored = false;
1174
- const db = src.type === "remote" ? src.db : dst.db;
1175
- const transaction = db.transaction([IDBFS.DB_STORE_NAME], "readwrite");
1176
- const store = transaction.objectStore(IDBFS.DB_STORE_NAME);
1177
- function done(err$1) {
1178
- if (err$1 && !errored) {
1080
+ var errored = false;
1081
+ var transaction = (src.type === "remote" ? src.db : dst.db).transaction([IDBFS.DB_STORE_NAME], "readwrite");
1082
+ var store = transaction.objectStore(IDBFS.DB_STORE_NAME);
1083
+ function done(err) {
1084
+ if (err && !errored) {
1179
1085
  errored = true;
1180
- return callback(err$1);
1086
+ return callback(err);
1181
1087
  }
1182
1088
  }
1183
- transaction.onerror = transaction.onabort = (e$1) => {
1184
- done(e$1.target.error);
1185
- e$1.preventDefault();
1089
+ transaction.onerror = transaction.onabort = (e) => {
1090
+ done(e.target.error);
1091
+ e.preventDefault();
1186
1092
  };
1187
- transaction.oncomplete = (e$1) => {
1093
+ transaction.oncomplete = (e) => {
1188
1094
  if (!errored) callback(null);
1189
1095
  };
1190
- for (const path of create.sort()) if (dst.type === "local") IDBFS.loadRemoteEntry(store, path, (err$1, entry) => {
1191
- if (err$1) return done(err$1);
1096
+ for (const path of create.sort()) if (dst.type === "local") IDBFS.loadRemoteEntry(store, path, (err, entry) => {
1097
+ if (err) return done(err);
1192
1098
  IDBFS.storeLocalEntry(path, entry, done);
1193
1099
  });
1194
- else IDBFS.loadLocalEntry(path, (err$1, entry) => {
1195
- if (err$1) return done(err$1);
1100
+ else IDBFS.loadLocalEntry(path, (err, entry) => {
1101
+ if (err) return done(err);
1196
1102
  IDBFS.storeRemoteEntry(store, path, entry, done);
1197
1103
  });
1198
- for (const path of remove.sort().reverse()) if (dst.type === "local") IDBFS.removeLocalEntry(path, done);
1104
+ for (var path of remove.sort().reverse()) if (dst.type === "local") IDBFS.removeLocalEntry(path, done);
1199
1105
  else IDBFS.removeRemoteEntry(store, path, done);
1200
1106
  }
1201
1107
  };
1202
- const asyncLoad = async (url) => {
1203
- const arrayBuffer = await readAsync(url);
1108
+ var asyncLoad = async (url) => {
1109
+ var arrayBuffer = await readAsync(url);
1204
1110
  return new Uint8Array(arrayBuffer);
1205
1111
  };
1206
- const FS_createDataFile = (...args) => FS.createDataFile(...args);
1207
- const getUniqueRunDependency = (id) => id;
1208
- let runDependencies = 0;
1209
- let dependenciesFulfilled = null;
1210
- const removeRunDependency = (id) => {
1112
+ var FS_createDataFile = (...args) => FS.createDataFile(...args);
1113
+ var getUniqueRunDependency = (id) => id;
1114
+ var runDependencies = 0;
1115
+ var dependenciesFulfilled = null;
1116
+ var removeRunDependency = (id) => {
1211
1117
  runDependencies--;
1212
- Module.monitorRunDependencies?.(runDependencies);
1118
+ Module["monitorRunDependencies"]?.(runDependencies);
1213
1119
  if (runDependencies == 0) {
1214
1120
  if (dependenciesFulfilled) {
1215
- const callback = dependenciesFulfilled;
1121
+ var callback = dependenciesFulfilled;
1216
1122
  dependenciesFulfilled = null;
1217
1123
  callback();
1218
1124
  }
1219
1125
  }
1220
1126
  };
1221
- const addRunDependency = (id) => {
1127
+ var addRunDependency = (id) => {
1222
1128
  runDependencies++;
1223
- Module.monitorRunDependencies?.(runDependencies);
1129
+ Module["monitorRunDependencies"]?.(runDependencies);
1224
1130
  };
1225
- let preloadPlugins = [];
1226
- const FS_handledByPreloadPlugin = async (byteArray, fullname) => {
1131
+ var preloadPlugins = [];
1132
+ var FS_handledByPreloadPlugin = async (byteArray, fullname) => {
1227
1133
  if (typeof Browser != "undefined") Browser.init();
1228
- for (const plugin of preloadPlugins) if (plugin.canHandle(fullname)) return plugin.handle(byteArray, fullname);
1134
+ for (var plugin of preloadPlugins) if (plugin["canHandle"](fullname)) return plugin["handle"](byteArray, fullname);
1229
1135
  return byteArray;
1230
1136
  };
1231
- const FS_preloadFile = async (parent, name, url, canRead, canWrite, dontCreateFile, canOwn, preFinish) => {
1232
- const fullname = name ? PATH_FS.resolve(PATH.join2(parent, name)) : parent;
1233
- const dep = getUniqueRunDependency(`cp ${fullname}`);
1137
+ var FS_preloadFile = async (parent, name, url, canRead, canWrite, dontCreateFile, canOwn, preFinish) => {
1138
+ var fullname = name ? PATH_FS.resolve(PATH.join2(parent, name)) : parent;
1139
+ var dep = getUniqueRunDependency(`cp ${fullname}`);
1234
1140
  addRunDependency(dep);
1235
1141
  try {
1236
- let byteArray = url;
1142
+ var byteArray = url;
1237
1143
  if (typeof url == "string") byteArray = await asyncLoad(url);
1238
1144
  byteArray = await FS_handledByPreloadPlugin(byteArray, fullname);
1239
1145
  preFinish?.();
@@ -1242,7 +1148,7 @@ async function createRimeModule(moduleArg = {}) {
1242
1148
  removeRunDependency(dep);
1243
1149
  }
1244
1150
  };
1245
- const FS_createPreloadedFile = (parent, name, url, canRead, canWrite, onload, onerror, dontCreateFile, canOwn, preFinish) => {
1151
+ var FS_createPreloadedFile = (parent, name, url, canRead, canWrite, onload, onerror, dontCreateFile, canOwn, preFinish) => {
1246
1152
  FS_preloadFile(parent, name, url, canRead, canWrite, dontCreateFile, canOwn, preFinish).then(onload).catch(onerror);
1247
1153
  };
1248
1154
  var FS = {
@@ -1331,19 +1237,19 @@ async function createRimeModule(moduleArg = {}) {
1331
1237
  lookupPath(path, opts = {}) {
1332
1238
  if (!path) throw new FS.ErrnoError(44);
1333
1239
  opts.follow_mount ??= true;
1334
- if (!PATH.isAbs(path)) path = `${FS.cwd()}/${path}`;
1335
- linkloop: for (let nlinks = 0; nlinks < 40; nlinks++) {
1336
- const parts = path.split("/").filter((p) => !!p);
1337
- let current = FS.root;
1338
- let current_path = "/";
1339
- for (let i = 0; i < parts.length; i++) {
1340
- const islast = i === parts.length - 1;
1240
+ if (!PATH.isAbs(path)) path = FS.cwd() + "/" + path;
1241
+ linkloop: for (var nlinks = 0; nlinks < 40; nlinks++) {
1242
+ var parts = path.split("/").filter((p) => !!p);
1243
+ var current = FS.root;
1244
+ var current_path = "/";
1245
+ for (var i = 0; i < parts.length; i++) {
1246
+ var islast = i === parts.length - 1;
1341
1247
  if (islast && opts.parent) break;
1342
1248
  if (parts[i] === ".") continue;
1343
1249
  if (parts[i] === "..") {
1344
1250
  current_path = PATH.dirname(current_path);
1345
1251
  if (FS.isRoot(current)) {
1346
- path = `${current_path}/${parts.slice(i + 1).join("/")}`;
1252
+ path = current_path + "/" + parts.slice(i + 1).join("/");
1347
1253
  nlinks--;
1348
1254
  continue linkloop;
1349
1255
  } else current = current.parent;
@@ -1359,9 +1265,9 @@ async function createRimeModule(moduleArg = {}) {
1359
1265
  if (FS.isMountpoint(current) && (!islast || opts.follow_mount)) current = current.mounted.root;
1360
1266
  if (FS.isLink(current.mode) && (!islast || opts.follow)) {
1361
1267
  if (!current.node_ops.readlink) throw new FS.ErrnoError(52);
1362
- let link = current.node_ops.readlink(current);
1363
- if (!PATH.isAbs(link)) link = `${PATH.dirname(current_path)}/${link}`;
1364
- path = `${link}/${parts.slice(i + 1).join("/")}`;
1268
+ var link = current.node_ops.readlink(current);
1269
+ if (!PATH.isAbs(link)) link = PATH.dirname(current_path) + "/" + link;
1270
+ path = link + "/" + parts.slice(i + 1).join("/");
1365
1271
  continue linkloop;
1366
1272
  }
1367
1273
  }
@@ -1373,10 +1279,10 @@ async function createRimeModule(moduleArg = {}) {
1373
1279
  throw new FS.ErrnoError(32);
1374
1280
  },
1375
1281
  getPath(node) {
1376
- let path;
1282
+ var path;
1377
1283
  while (true) {
1378
1284
  if (FS.isRoot(node)) {
1379
- const mount = node.mount.mountpoint;
1285
+ var mount = node.mount.mountpoint;
1380
1286
  if (!path) return mount;
1381
1287
  return mount[mount.length - 1] !== "/" ? `${mount}/${path}` : mount + path;
1382
1288
  }
@@ -1385,20 +1291,20 @@ async function createRimeModule(moduleArg = {}) {
1385
1291
  }
1386
1292
  },
1387
1293
  hashName(parentid, name) {
1388
- let hash = 0;
1389
- for (let i = 0; i < name.length; i++) hash = (hash << 5) - hash + name.charCodeAt(i) | 0;
1294
+ var hash = 0;
1295
+ for (var i = 0; i < name.length; i++) hash = (hash << 5) - hash + name.charCodeAt(i) | 0;
1390
1296
  return (parentid + hash >>> 0) % FS.nameTable.length;
1391
1297
  },
1392
1298
  hashAddNode(node) {
1393
- const hash = FS.hashName(node.parent.id, node.name);
1299
+ var hash = FS.hashName(node.parent.id, node.name);
1394
1300
  node.name_next = FS.nameTable[hash];
1395
1301
  FS.nameTable[hash] = node;
1396
1302
  },
1397
1303
  hashRemoveNode(node) {
1398
- const hash = FS.hashName(node.parent.id, node.name);
1304
+ var hash = FS.hashName(node.parent.id, node.name);
1399
1305
  if (FS.nameTable[hash] === node) FS.nameTable[hash] = node.name_next;
1400
1306
  else {
1401
- let current = FS.nameTable[hash];
1307
+ var current = FS.nameTable[hash];
1402
1308
  while (current) {
1403
1309
  if (current.name_next === node) {
1404
1310
  current.name_next = node.name_next;
@@ -1409,17 +1315,17 @@ async function createRimeModule(moduleArg = {}) {
1409
1315
  }
1410
1316
  },
1411
1317
  lookupNode(parent, name) {
1412
- const errCode = FS.mayLookup(parent);
1318
+ var errCode = FS.mayLookup(parent);
1413
1319
  if (errCode) throw new FS.ErrnoError(errCode);
1414
- const hash = FS.hashName(parent.id, name);
1415
- for (let node = FS.nameTable[hash]; node; node = node.name_next) {
1416
- const nodeName = node.name;
1320
+ var hash = FS.hashName(parent.id, name);
1321
+ for (var node = FS.nameTable[hash]; node; node = node.name_next) {
1322
+ var nodeName = node.name;
1417
1323
  if (node.parent.id === parent.id && nodeName === name) return node;
1418
1324
  }
1419
1325
  return FS.lookup(parent, name);
1420
1326
  },
1421
1327
  createNode(parent, name, mode, rdev) {
1422
- const node = new FS.FSNode(parent, name, mode, rdev);
1328
+ var node = new FS.FSNode(parent, name, mode, rdev);
1423
1329
  FS.hashAddNode(node);
1424
1330
  return node;
1425
1331
  },
@@ -1454,7 +1360,7 @@ async function createRimeModule(moduleArg = {}) {
1454
1360
  return (mode & 49152) === 49152;
1455
1361
  },
1456
1362
  flagsToPermissionString(flag) {
1457
- let perms = [
1363
+ var perms = [
1458
1364
  "r",
1459
1365
  "w",
1460
1366
  "rw"
@@ -1471,7 +1377,7 @@ async function createRimeModule(moduleArg = {}) {
1471
1377
  },
1472
1378
  mayLookup(dir) {
1473
1379
  if (!FS.isDir(dir.mode)) return 54;
1474
- const errCode = FS.nodePermissions(dir, "x");
1380
+ var errCode = FS.nodePermissions(dir, "x");
1475
1381
  if (errCode) return errCode;
1476
1382
  if (!dir.node_ops.lookup) return 2;
1477
1383
  return 0;
@@ -1479,19 +1385,19 @@ async function createRimeModule(moduleArg = {}) {
1479
1385
  mayCreate(dir, name) {
1480
1386
  if (!FS.isDir(dir.mode)) return 54;
1481
1387
  try {
1482
- const node = FS.lookupNode(dir, name);
1388
+ FS.lookupNode(dir, name);
1483
1389
  return 20;
1484
1390
  } catch (e) {}
1485
1391
  return FS.nodePermissions(dir, "wx");
1486
1392
  },
1487
1393
  mayDelete(dir, name, isdir) {
1488
- let node;
1394
+ var node;
1489
1395
  try {
1490
1396
  node = FS.lookupNode(dir, name);
1491
1397
  } catch (e) {
1492
1398
  return e.errno;
1493
1399
  }
1494
- const errCode = FS.nodePermissions(dir, "wx");
1400
+ var errCode = FS.nodePermissions(dir, "wx");
1495
1401
  if (errCode) return errCode;
1496
1402
  if (isdir) {
1497
1403
  if (!FS.isDir(node.mode)) return 54;
@@ -1502,23 +1408,23 @@ async function createRimeModule(moduleArg = {}) {
1502
1408
  mayOpen(node, flags) {
1503
1409
  if (!node) return 44;
1504
1410
  if (FS.isLink(node.mode)) return 32;
1505
- const mode = FS.flagsToPermissionString(flags);
1411
+ var mode = FS.flagsToPermissionString(flags);
1506
1412
  if (FS.isDir(node.mode)) {
1507
1413
  if (mode !== "r" || flags & 576) return 31;
1508
1414
  }
1509
1415
  return FS.nodePermissions(node, mode);
1510
1416
  },
1511
- checkOpExists(op, err$1) {
1512
- if (!op) throw new FS.ErrnoError(err$1);
1417
+ checkOpExists(op, err) {
1418
+ if (!op) throw new FS.ErrnoError(err);
1513
1419
  return op;
1514
1420
  },
1515
1421
  MAX_OPEN_FDS: 4096,
1516
1422
  nextfd() {
1517
- for (let fd = 0; fd <= FS.MAX_OPEN_FDS; fd++) if (!FS.streams[fd]) return fd;
1423
+ for (var fd = 0; fd <= FS.MAX_OPEN_FDS; fd++) if (!FS.streams[fd]) return fd;
1518
1424
  throw new FS.ErrnoError(33);
1519
1425
  },
1520
1426
  getStreamChecked(fd) {
1521
- const stream = FS.getStream(fd);
1427
+ var stream = FS.getStream(fd);
1522
1428
  if (!stream) throw new FS.ErrnoError(8);
1523
1429
  return stream;
1524
1430
  },
@@ -1534,21 +1440,20 @@ async function createRimeModule(moduleArg = {}) {
1534
1440
  FS.streams[fd] = null;
1535
1441
  },
1536
1442
  dupStream(origStream, fd = -1) {
1537
- const stream = FS.createStream(origStream, fd);
1443
+ var stream = FS.createStream(origStream, fd);
1538
1444
  stream.stream_ops?.dup?.(stream);
1539
1445
  return stream;
1540
1446
  },
1541
1447
  doSetAttr(stream, node, attr) {
1542
- let setattr = stream?.stream_ops.setattr;
1543
- const arg = setattr ? stream : node;
1448
+ var setattr = stream?.stream_ops.setattr;
1449
+ var arg = setattr ? stream : node;
1544
1450
  setattr ??= node.node_ops.setattr;
1545
1451
  FS.checkOpExists(setattr, 63);
1546
1452
  setattr(arg, attr);
1547
1453
  },
1548
1454
  chrdev_stream_ops: {
1549
1455
  open(stream) {
1550
- const device = FS.getDevice(stream.node.rdev);
1551
- stream.stream_ops = device.stream_ops;
1456
+ stream.stream_ops = FS.getDevice(stream.node.rdev).stream_ops;
1552
1457
  stream.stream_ops.open?.(stream);
1553
1458
  },
1554
1459
  llseek() {
@@ -1563,10 +1468,10 @@ async function createRimeModule(moduleArg = {}) {
1563
1468
  },
1564
1469
  getDevice: (dev) => FS.devices[dev],
1565
1470
  getMounts(mount) {
1566
- const mounts = [];
1567
- const check = [mount];
1471
+ var mounts = [];
1472
+ var check = [mount];
1568
1473
  while (check.length) {
1569
- const m = check.pop();
1474
+ var m = check.pop();
1570
1475
  mounts.push(m);
1571
1476
  check.push(...m.mounts);
1572
1477
  }
@@ -1579,8 +1484,8 @@ async function createRimeModule(moduleArg = {}) {
1579
1484
  }
1580
1485
  FS.syncFSRequests++;
1581
1486
  if (FS.syncFSRequests > 1) err(`warning: ${FS.syncFSRequests} FS.syncfs operations in flight at once, probably just doing extra work`);
1582
- const mounts = FS.getMounts(FS.root.mount);
1583
- let completed = 0;
1487
+ var mounts = FS.getMounts(FS.root.mount);
1488
+ var completed = 0;
1584
1489
  function doCallback(errCode) {
1585
1490
  FS.syncFSRequests--;
1586
1491
  return callback(errCode);
@@ -1595,28 +1500,28 @@ async function createRimeModule(moduleArg = {}) {
1595
1500
  }
1596
1501
  if (++completed >= mounts.length) doCallback(null);
1597
1502
  }
1598
- for (const mount of mounts) if (mount.type.syncfs) mount.type.syncfs(mount, populate, done);
1503
+ for (var mount of mounts) if (mount.type.syncfs) mount.type.syncfs(mount, populate, done);
1599
1504
  else done(null);
1600
1505
  },
1601
1506
  mount(type, opts, mountpoint) {
1602
- const root = mountpoint === "/";
1603
- const pseudo = !mountpoint;
1604
- let node;
1507
+ var root = mountpoint === "/";
1508
+ var pseudo = !mountpoint;
1509
+ var node;
1605
1510
  if (root && FS.root) throw new FS.ErrnoError(10);
1606
1511
  else if (!root && !pseudo) {
1607
- const lookup = FS.lookupPath(mountpoint, { follow_mount: false });
1512
+ var lookup = FS.lookupPath(mountpoint, { follow_mount: false });
1608
1513
  mountpoint = lookup.path;
1609
1514
  node = lookup.node;
1610
1515
  if (FS.isMountpoint(node)) throw new FS.ErrnoError(10);
1611
1516
  if (!FS.isDir(node.mode)) throw new FS.ErrnoError(54);
1612
1517
  }
1613
- const mount = {
1518
+ var mount = {
1614
1519
  type,
1615
1520
  opts,
1616
1521
  mountpoint,
1617
1522
  mounts: []
1618
1523
  };
1619
- const mountRoot = type.mount(mount);
1524
+ var mountRoot = type.mount(mount);
1620
1525
  mountRoot.mount = mount;
1621
1526
  mount.root = mountRoot;
1622
1527
  if (root) FS.root = mountRoot;
@@ -1627,30 +1532,29 @@ async function createRimeModule(moduleArg = {}) {
1627
1532
  return mountRoot;
1628
1533
  },
1629
1534
  unmount(mountpoint) {
1630
- const lookup = FS.lookupPath(mountpoint, { follow_mount: false });
1535
+ var lookup = FS.lookupPath(mountpoint, { follow_mount: false });
1631
1536
  if (!FS.isMountpoint(lookup.node)) throw new FS.ErrnoError(28);
1632
- const node = lookup.node;
1633
- const mount = node.mounted;
1634
- const mounts = FS.getMounts(mount);
1635
- for (let [hash, current] of Object.entries(FS.nameTable)) while (current) {
1636
- const next = current.name_next;
1537
+ var node = lookup.node;
1538
+ var mount = node.mounted;
1539
+ var mounts = FS.getMounts(mount);
1540
+ for (var [hash, current] of Object.entries(FS.nameTable)) while (current) {
1541
+ var next = current.name_next;
1637
1542
  if (mounts.includes(current.mount)) FS.destroyNode(current);
1638
1543
  current = next;
1639
1544
  }
1640
1545
  node.mounted = null;
1641
- const idx = node.mount.mounts.indexOf(mount);
1546
+ var idx = node.mount.mounts.indexOf(mount);
1642
1547
  node.mount.mounts.splice(idx, 1);
1643
1548
  },
1644
1549
  lookup(parent, name) {
1645
1550
  return parent.node_ops.lookup(parent, name);
1646
1551
  },
1647
1552
  mknod(path, mode, dev) {
1648
- const lookup = FS.lookupPath(path, { parent: true });
1649
- const parent = lookup.node;
1650
- const name = PATH.basename(path);
1553
+ var parent = FS.lookupPath(path, { parent: true }).node;
1554
+ var name = PATH.basename(path);
1651
1555
  if (!name) throw new FS.ErrnoError(28);
1652
1556
  if (name === "." || name === "..") throw new FS.ErrnoError(20);
1653
- const errCode = FS.mayCreate(parent, name);
1557
+ var errCode = FS.mayCreate(parent, name);
1654
1558
  if (errCode) throw new FS.ErrnoError(errCode);
1655
1559
  if (!parent.node_ops.mknod) throw new FS.ErrnoError(63);
1656
1560
  return parent.node_ops.mknod(parent, name, mode, dev);
@@ -1662,7 +1566,7 @@ async function createRimeModule(moduleArg = {}) {
1662
1566
  return FS.statfsNode(stream.node);
1663
1567
  },
1664
1568
  statfsNode(node) {
1665
- const rtn = {
1569
+ var rtn = {
1666
1570
  bsize: 4096,
1667
1571
  frsize: 4096,
1668
1572
  blocks: 1e6,
@@ -1688,9 +1592,9 @@ async function createRimeModule(moduleArg = {}) {
1688
1592
  return FS.mknod(path, mode, 0);
1689
1593
  },
1690
1594
  mkdirTree(path, mode) {
1691
- const dirs = path.split("/");
1692
- let d = "";
1693
- for (const dir of dirs) {
1595
+ var dirs = path.split("/");
1596
+ var d = "";
1597
+ for (var dir of dirs) {
1694
1598
  if (!dir) continue;
1695
1599
  if (d || PATH.isAbs(path)) d += "/";
1696
1600
  d += dir;
@@ -1711,39 +1615,36 @@ async function createRimeModule(moduleArg = {}) {
1711
1615
  },
1712
1616
  symlink(oldpath, newpath) {
1713
1617
  if (!PATH_FS.resolve(oldpath)) throw new FS.ErrnoError(44);
1714
- const lookup = FS.lookupPath(newpath, { parent: true });
1715
- const parent = lookup.node;
1618
+ var parent = FS.lookupPath(newpath, { parent: true }).node;
1716
1619
  if (!parent) throw new FS.ErrnoError(44);
1717
- const newname = PATH.basename(newpath);
1718
- const errCode = FS.mayCreate(parent, newname);
1620
+ var newname = PATH.basename(newpath);
1621
+ var errCode = FS.mayCreate(parent, newname);
1719
1622
  if (errCode) throw new FS.ErrnoError(errCode);
1720
1623
  if (!parent.node_ops.symlink) throw new FS.ErrnoError(63);
1721
1624
  return parent.node_ops.symlink(parent, newname, oldpath);
1722
1625
  },
1723
1626
  rename(old_path, new_path) {
1724
- const old_dirname = PATH.dirname(old_path);
1725
- const new_dirname = PATH.dirname(new_path);
1726
- const old_name = PATH.basename(old_path);
1727
- const new_name = PATH.basename(new_path);
1728
- let lookup, old_dir, new_dir;
1729
- lookup = FS.lookupPath(old_path, { parent: true });
1730
- old_dir = lookup.node;
1627
+ var old_dirname = PATH.dirname(old_path);
1628
+ var new_dirname = PATH.dirname(new_path);
1629
+ var old_name = PATH.basename(old_path);
1630
+ var new_name = PATH.basename(new_path);
1631
+ var lookup = FS.lookupPath(old_path, { parent: true }), old_dir = lookup.node, new_dir;
1731
1632
  lookup = FS.lookupPath(new_path, { parent: true });
1732
1633
  new_dir = lookup.node;
1733
1634
  if (!old_dir || !new_dir) throw new FS.ErrnoError(44);
1734
1635
  if (old_dir.mount !== new_dir.mount) throw new FS.ErrnoError(75);
1735
- const old_node = FS.lookupNode(old_dir, old_name);
1736
- let relative = PATH_FS.relative(old_path, new_dirname);
1636
+ var old_node = FS.lookupNode(old_dir, old_name);
1637
+ var relative = PATH_FS.relative(old_path, new_dirname);
1737
1638
  if (relative.charAt(0) !== ".") throw new FS.ErrnoError(28);
1738
1639
  relative = PATH_FS.relative(new_path, old_dirname);
1739
1640
  if (relative.charAt(0) !== ".") throw new FS.ErrnoError(55);
1740
- let new_node;
1641
+ var new_node;
1741
1642
  try {
1742
1643
  new_node = FS.lookupNode(new_dir, new_name);
1743
1644
  } catch (e) {}
1744
1645
  if (old_node === new_node) return;
1745
- const isdir = FS.isDir(old_node.mode);
1746
- let errCode = FS.mayDelete(old_dir, old_name, isdir);
1646
+ var isdir = FS.isDir(old_node.mode);
1647
+ var errCode = FS.mayDelete(old_dir, old_name, isdir);
1747
1648
  if (errCode) throw new FS.ErrnoError(errCode);
1748
1649
  errCode = new_node ? FS.mayDelete(new_dir, new_name, isdir) : FS.mayCreate(new_dir, new_name);
1749
1650
  if (errCode) throw new FS.ErrnoError(errCode);
@@ -1764,11 +1665,10 @@ async function createRimeModule(moduleArg = {}) {
1764
1665
  }
1765
1666
  },
1766
1667
  rmdir(path) {
1767
- const lookup = FS.lookupPath(path, { parent: true });
1768
- const parent = lookup.node;
1769
- const name = PATH.basename(path);
1770
- const node = FS.lookupNode(parent, name);
1771
- const errCode = FS.mayDelete(parent, name, true);
1668
+ var parent = FS.lookupPath(path, { parent: true }).node;
1669
+ var name = PATH.basename(path);
1670
+ var node = FS.lookupNode(parent, name);
1671
+ var errCode = FS.mayDelete(parent, name, true);
1772
1672
  if (errCode) throw new FS.ErrnoError(errCode);
1773
1673
  if (!parent.node_ops.rmdir) throw new FS.ErrnoError(63);
1774
1674
  if (FS.isMountpoint(node)) throw new FS.ErrnoError(10);
@@ -1776,18 +1676,15 @@ async function createRimeModule(moduleArg = {}) {
1776
1676
  FS.destroyNode(node);
1777
1677
  },
1778
1678
  readdir(path) {
1779
- const lookup = FS.lookupPath(path, { follow: true });
1780
- const node = lookup.node;
1781
- const readdir = FS.checkOpExists(node.node_ops.readdir, 54);
1782
- return readdir(node);
1679
+ var node = FS.lookupPath(path, { follow: true }).node;
1680
+ return FS.checkOpExists(node.node_ops.readdir, 54)(node);
1783
1681
  },
1784
1682
  unlink(path) {
1785
- const lookup = FS.lookupPath(path, { parent: true });
1786
- const parent = lookup.node;
1683
+ var parent = FS.lookupPath(path, { parent: true }).node;
1787
1684
  if (!parent) throw new FS.ErrnoError(44);
1788
- const name = PATH.basename(path);
1789
- const node = FS.lookupNode(parent, name);
1790
- const errCode = FS.mayDelete(parent, name, false);
1685
+ var name = PATH.basename(path);
1686
+ var node = FS.lookupNode(parent, name);
1687
+ var errCode = FS.mayDelete(parent, name, false);
1791
1688
  if (errCode) throw new FS.ErrnoError(errCode);
1792
1689
  if (!parent.node_ops.unlink) throw new FS.ErrnoError(63);
1793
1690
  if (FS.isMountpoint(node)) throw new FS.ErrnoError(10);
@@ -1795,23 +1692,20 @@ async function createRimeModule(moduleArg = {}) {
1795
1692
  FS.destroyNode(node);
1796
1693
  },
1797
1694
  readlink(path) {
1798
- const lookup = FS.lookupPath(path);
1799
- const link = lookup.node;
1695
+ var link = FS.lookupPath(path).node;
1800
1696
  if (!link) throw new FS.ErrnoError(44);
1801
1697
  if (!link.node_ops.readlink) throw new FS.ErrnoError(28);
1802
1698
  return link.node_ops.readlink(link);
1803
1699
  },
1804
1700
  stat(path, dontFollow) {
1805
- const lookup = FS.lookupPath(path, { follow: !dontFollow });
1806
- const node = lookup.node;
1807
- const getattr = FS.checkOpExists(node.node_ops.getattr, 63);
1808
- return getattr(node);
1701
+ var node = FS.lookupPath(path, { follow: !dontFollow }).node;
1702
+ return FS.checkOpExists(node.node_ops.getattr, 63)(node);
1809
1703
  },
1810
1704
  fstat(fd) {
1811
- const stream = FS.getStreamChecked(fd);
1812
- const node = stream.node;
1813
- let getattr = stream.stream_ops.getattr;
1814
- const arg = getattr ? stream : node;
1705
+ var stream = FS.getStreamChecked(fd);
1706
+ var node = stream.node;
1707
+ var getattr = stream.stream_ops.getattr;
1708
+ var arg = getattr ? stream : node;
1815
1709
  getattr ??= node.node_ops.getattr;
1816
1710
  FS.checkOpExists(getattr, 63);
1817
1711
  return getattr(arg);
@@ -1827,18 +1721,16 @@ async function createRimeModule(moduleArg = {}) {
1827
1721
  });
1828
1722
  },
1829
1723
  chmod(path, mode, dontFollow) {
1830
- let node;
1831
- if (typeof path == "string") {
1832
- const lookup = FS.lookupPath(path, { follow: !dontFollow });
1833
- node = lookup.node;
1834
- } else node = path;
1724
+ var node;
1725
+ if (typeof path == "string") node = FS.lookupPath(path, { follow: !dontFollow }).node;
1726
+ else node = path;
1835
1727
  FS.doChmod(null, node, mode, dontFollow);
1836
1728
  },
1837
1729
  lchmod(path, mode) {
1838
1730
  FS.chmod(path, mode, true);
1839
1731
  },
1840
1732
  fchmod(fd, mode) {
1841
- const stream = FS.getStreamChecked(fd);
1733
+ var stream = FS.getStreamChecked(fd);
1842
1734
  FS.doChmod(stream, stream.node, mode, false);
1843
1735
  },
1844
1736
  doChown(stream, node, dontFollow) {
@@ -1848,24 +1740,22 @@ async function createRimeModule(moduleArg = {}) {
1848
1740
  });
1849
1741
  },
1850
1742
  chown(path, uid, gid, dontFollow) {
1851
- let node;
1852
- if (typeof path == "string") {
1853
- const lookup = FS.lookupPath(path, { follow: !dontFollow });
1854
- node = lookup.node;
1855
- } else node = path;
1743
+ var node;
1744
+ if (typeof path == "string") node = FS.lookupPath(path, { follow: !dontFollow }).node;
1745
+ else node = path;
1856
1746
  FS.doChown(null, node, dontFollow);
1857
1747
  },
1858
1748
  lchown(path, uid, gid) {
1859
1749
  FS.chown(path, uid, gid, true);
1860
1750
  },
1861
1751
  fchown(fd, uid, gid) {
1862
- const stream = FS.getStreamChecked(fd);
1752
+ var stream = FS.getStreamChecked(fd);
1863
1753
  FS.doChown(stream, stream.node, false);
1864
1754
  },
1865
1755
  doTruncate(stream, node, len) {
1866
1756
  if (FS.isDir(node.mode)) throw new FS.ErrnoError(31);
1867
1757
  if (!FS.isFile(node.mode)) throw new FS.ErrnoError(28);
1868
- const errCode = FS.nodePermissions(node, "w");
1758
+ var errCode = FS.nodePermissions(node, "w");
1869
1759
  if (errCode) throw new FS.ErrnoError(errCode);
1870
1760
  FS.doSetAttr(stream, node, {
1871
1761
  size: len,
@@ -1874,23 +1764,19 @@ async function createRimeModule(moduleArg = {}) {
1874
1764
  },
1875
1765
  truncate(path, len) {
1876
1766
  if (len < 0) throw new FS.ErrnoError(28);
1877
- let node;
1878
- if (typeof path == "string") {
1879
- const lookup = FS.lookupPath(path, { follow: true });
1880
- node = lookup.node;
1881
- } else node = path;
1767
+ var node;
1768
+ if (typeof path == "string") node = FS.lookupPath(path, { follow: true }).node;
1769
+ else node = path;
1882
1770
  FS.doTruncate(null, node, len);
1883
1771
  },
1884
1772
  ftruncate(fd, len) {
1885
- const stream = FS.getStreamChecked(fd);
1773
+ var stream = FS.getStreamChecked(fd);
1886
1774
  if (len < 0 || (stream.flags & 2097155) === 0) throw new FS.ErrnoError(28);
1887
1775
  FS.doTruncate(stream, stream.node, len);
1888
1776
  },
1889
1777
  utime(path, atime, mtime) {
1890
- const lookup = FS.lookupPath(path, { follow: true });
1891
- const node = lookup.node;
1892
- const setattr = FS.checkOpExists(node.node_ops.setattr, 63);
1893
- setattr(node, {
1778
+ var node = FS.lookupPath(path, { follow: true }).node;
1779
+ FS.checkOpExists(node.node_ops.setattr, 63)(node, {
1894
1780
  atime,
1895
1781
  mtime
1896
1782
  });
@@ -1900,19 +1786,19 @@ async function createRimeModule(moduleArg = {}) {
1900
1786
  flags = typeof flags == "string" ? FS_modeStringToFlags(flags) : flags;
1901
1787
  if (flags & 64) mode = mode & 4095 | 32768;
1902
1788
  else mode = 0;
1903
- let node;
1904
- let isDirPath;
1789
+ var node;
1790
+ var isDirPath;
1905
1791
  if (typeof path == "object") node = path;
1906
1792
  else {
1907
1793
  isDirPath = path.endsWith("/");
1908
- const lookup = FS.lookupPath(path, {
1794
+ var lookup = FS.lookupPath(path, {
1909
1795
  follow: !(flags & 131072),
1910
1796
  noent_okay: true
1911
1797
  });
1912
1798
  node = lookup.node;
1913
1799
  path = lookup.path;
1914
1800
  }
1915
- let created = false;
1801
+ var created = false;
1916
1802
  if (flags & 64) if (node) {
1917
1803
  if (flags & 128) throw new FS.ErrnoError(20);
1918
1804
  } else if (isDirPath) throw new FS.ErrnoError(31);
@@ -1924,12 +1810,12 @@ async function createRimeModule(moduleArg = {}) {
1924
1810
  if (FS.isChrdev(node.mode)) flags &= -513;
1925
1811
  if (flags & 65536 && !FS.isDir(node.mode)) throw new FS.ErrnoError(54);
1926
1812
  if (!created) {
1927
- const errCode = FS.mayOpen(node, flags);
1813
+ var errCode = FS.mayOpen(node, flags);
1928
1814
  if (errCode) throw new FS.ErrnoError(errCode);
1929
1815
  }
1930
1816
  if (flags & 512 && !created) FS.truncate(node, 0);
1931
1817
  flags &= -131713;
1932
- const stream = FS.createStream({
1818
+ var stream = FS.createStream({
1933
1819
  node,
1934
1820
  path: FS.getPath(node),
1935
1821
  flags,
@@ -1972,10 +1858,10 @@ async function createRimeModule(moduleArg = {}) {
1972
1858
  if ((stream.flags & 2097155) === 1) throw new FS.ErrnoError(8);
1973
1859
  if (FS.isDir(stream.node.mode)) throw new FS.ErrnoError(31);
1974
1860
  if (!stream.stream_ops.read) throw new FS.ErrnoError(28);
1975
- const seeking = typeof position != "undefined";
1861
+ var seeking = typeof position != "undefined";
1976
1862
  if (!seeking) position = stream.position;
1977
1863
  else if (!stream.seekable) throw new FS.ErrnoError(70);
1978
- const bytesRead = stream.stream_ops.read(stream, buffer, offset, length, position);
1864
+ var bytesRead = stream.stream_ops.read(stream, buffer, offset, length, position);
1979
1865
  if (!seeking) stream.position += bytesRead;
1980
1866
  return bytesRead;
1981
1867
  },
@@ -1986,10 +1872,10 @@ async function createRimeModule(moduleArg = {}) {
1986
1872
  if (FS.isDir(stream.node.mode)) throw new FS.ErrnoError(31);
1987
1873
  if (!stream.stream_ops.write) throw new FS.ErrnoError(28);
1988
1874
  if (stream.seekable && stream.flags & 1024) FS.llseek(stream, 0, 2);
1989
- const seeking = typeof position != "undefined";
1875
+ var seeking = typeof position != "undefined";
1990
1876
  if (!seeking) position = stream.position;
1991
1877
  else if (!stream.seekable) throw new FS.ErrnoError(70);
1992
- const bytesWritten = stream.stream_ops.write(stream, buffer, offset, length, position, canOwn);
1878
+ var bytesWritten = stream.stream_ops.write(stream, buffer, offset, length, position, canOwn);
1993
1879
  if (!seeking) stream.position += bytesWritten;
1994
1880
  return bytesWritten;
1995
1881
  },
@@ -2012,10 +1898,9 @@ async function createRimeModule(moduleArg = {}) {
2012
1898
  opts.flags = opts.flags || 0;
2013
1899
  opts.encoding = opts.encoding || "binary";
2014
1900
  if (opts.encoding !== "utf8" && opts.encoding !== "binary") abort(`Invalid encoding type "${opts.encoding}"`);
2015
- const stream = FS.open(path, opts.flags);
2016
- const stat = FS.stat(path);
2017
- const length = stat.size;
2018
- let buf = new Uint8Array(length);
1901
+ var stream = FS.open(path, opts.flags);
1902
+ var length = FS.stat(path).size;
1903
+ var buf = new Uint8Array(length);
2019
1904
  FS.read(stream, buf, 0, length, 0);
2020
1905
  if (opts.encoding === "utf8") buf = UTF8ArrayToString(buf);
2021
1906
  FS.close(stream);
@@ -2023,7 +1908,7 @@ async function createRimeModule(moduleArg = {}) {
2023
1908
  },
2024
1909
  writeFile(path, data, opts = {}) {
2025
1910
  opts.flags = opts.flags || 577;
2026
- const stream = FS.open(path, opts.flags, opts.mode);
1911
+ var stream = FS.open(path, opts.flags, opts.mode);
2027
1912
  if (typeof data == "string") data = new Uint8Array(intArrayFromString(data, true));
2028
1913
  if (ArrayBuffer.isView(data)) FS.write(stream, data, 0, data.byteLength, void 0, opts.canOwn);
2029
1914
  else abort("Unsupported data type");
@@ -2031,10 +1916,10 @@ async function createRimeModule(moduleArg = {}) {
2031
1916
  },
2032
1917
  cwd: () => FS.currentPath,
2033
1918
  chdir(path) {
2034
- const lookup = FS.lookupPath(path, { follow: true });
1919
+ var lookup = FS.lookupPath(path, { follow: true });
2035
1920
  if (lookup.node === null) throw new FS.ErrnoError(44);
2036
1921
  if (!FS.isDir(lookup.node.mode)) throw new FS.ErrnoError(54);
2037
- const errCode = FS.nodePermissions(lookup.node, "x");
1922
+ var errCode = FS.nodePermissions(lookup.node, "x");
2038
1923
  if (errCode) throw new FS.ErrnoError(errCode);
2039
1924
  FS.currentPath = lookup.path;
2040
1925
  },
@@ -2055,9 +1940,8 @@ async function createRimeModule(moduleArg = {}) {
2055
1940
  TTY.register(FS.makedev(6, 0), TTY.default_tty1_ops);
2056
1941
  FS.mkdev("/dev/tty", FS.makedev(5, 0));
2057
1942
  FS.mkdev("/dev/tty1", FS.makedev(6, 0));
2058
- const randomBuffer = new Uint8Array(1024);
2059
- let randomLeft = 0;
2060
- const randomByte = () => {
1943
+ var randomBuffer = new Uint8Array(1024), randomLeft = 0;
1944
+ var randomByte = () => {
2061
1945
  if (randomLeft === 0) {
2062
1946
  randomFill(randomBuffer);
2063
1947
  randomLeft = randomBuffer.byteLength;
@@ -2071,16 +1955,16 @@ async function createRimeModule(moduleArg = {}) {
2071
1955
  },
2072
1956
  createSpecialDirectories() {
2073
1957
  FS.mkdir("/proc");
2074
- const proc_self = FS.mkdir("/proc/self");
1958
+ var proc_self = FS.mkdir("/proc/self");
2075
1959
  FS.mkdir("/proc/self/fd");
2076
1960
  FS.mount({ mount() {
2077
- const node = FS.createNode(proc_self, "fd", 16895, 73);
1961
+ var node = FS.createNode(proc_self, "fd", 16895, 73);
2078
1962
  node.stream_ops = { llseek: MEMFS.stream_ops.llseek };
2079
1963
  node.node_ops = {
2080
1964
  lookup(parent, name) {
2081
- const fd = +name;
2082
- const stream = FS.getStreamChecked(fd);
2083
- const ret = {
1965
+ var fd = +name;
1966
+ var stream = FS.getStreamChecked(fd);
1967
+ var ret = {
2084
1968
  parent: null,
2085
1969
  mount: { mountpoint: "fake" },
2086
1970
  node_ops: { readlink: () => stream.path },
@@ -2103,12 +1987,12 @@ async function createRimeModule(moduleArg = {}) {
2103
1987
  else FS.symlink("/dev/tty", "/dev/stdout");
2104
1988
  if (error) FS.createDevice("/dev", "stderr", null, error);
2105
1989
  else FS.symlink("/dev/tty1", "/dev/stderr");
2106
- const stdin = FS.open("/dev/stdin", 0);
2107
- const stdout = FS.open("/dev/stdout", 1);
2108
- const stderr = FS.open("/dev/stderr", 1);
1990
+ FS.open("/dev/stdin", 0);
1991
+ FS.open("/dev/stdout", 1);
1992
+ FS.open("/dev/stderr", 1);
2109
1993
  },
2110
1994
  staticInit() {
2111
- FS.nameTable = Array.from({ length: 4096 });
1995
+ FS.nameTable = new Array(4096);
2112
1996
  FS.mount(MEMFS, {}, "/");
2113
1997
  FS.createDefaultDirectories();
2114
1998
  FS.createDefaultDevices();
@@ -2120,17 +2004,17 @@ async function createRimeModule(moduleArg = {}) {
2120
2004
  },
2121
2005
  init(input, output, error) {
2122
2006
  FS.initialized = true;
2123
- input ??= Module.stdin;
2124
- output ??= Module.stdout;
2125
- error ??= Module.stderr;
2007
+ input ??= Module["stdin"];
2008
+ output ??= Module["stdout"];
2009
+ error ??= Module["stderr"];
2126
2010
  FS.createStandardStreams(input, output, error);
2127
2011
  },
2128
2012
  quit() {
2129
2013
  FS.initialized = false;
2130
- for (const stream of FS.streams) if (stream) FS.close(stream);
2014
+ for (var stream of FS.streams) if (stream) FS.close(stream);
2131
2015
  },
2132
2016
  findObject(path, dontResolveLastLink) {
2133
- const ret = FS.analyzePath(path, dontResolveLastLink);
2017
+ var ret = FS.analyzePath(path, dontResolveLastLink);
2134
2018
  if (!ret.exists) return null;
2135
2019
  return ret.object;
2136
2020
  },
@@ -2139,7 +2023,7 @@ async function createRimeModule(moduleArg = {}) {
2139
2023
  var lookup = FS.lookupPath(path, { follow: !dontResolveLastLink });
2140
2024
  path = lookup.path;
2141
2025
  } catch (e) {}
2142
- const ret = {
2026
+ var ret = {
2143
2027
  isRoot: false,
2144
2028
  exists: false,
2145
2029
  error: 0,
@@ -2169,9 +2053,9 @@ async function createRimeModule(moduleArg = {}) {
2169
2053
  },
2170
2054
  createPath(parent, path, canRead, canWrite) {
2171
2055
  parent = typeof parent == "string" ? parent : FS.getPath(parent);
2172
- const parts = path.split("/").reverse();
2056
+ var parts = path.split("/").reverse();
2173
2057
  while (parts.length) {
2174
- const part = parts.pop();
2058
+ var part = parts.pop();
2175
2059
  if (!part) continue;
2176
2060
  var current = PATH.join2(parent, part);
2177
2061
  try {
@@ -2184,36 +2068,36 @@ async function createRimeModule(moduleArg = {}) {
2184
2068
  return current;
2185
2069
  },
2186
2070
  createFile(parent, name, properties, canRead, canWrite) {
2187
- const path = PATH.join2(typeof parent == "string" ? parent : FS.getPath(parent), name);
2188
- const mode = FS_getMode(canRead, canWrite);
2071
+ var path = PATH.join2(typeof parent == "string" ? parent : FS.getPath(parent), name);
2072
+ var mode = FS_getMode(canRead, canWrite);
2189
2073
  return FS.create(path, mode);
2190
2074
  },
2191
2075
  createDataFile(parent, name, data, canRead, canWrite, canOwn) {
2192
- let path = name;
2076
+ var path = name;
2193
2077
  if (parent) {
2194
2078
  parent = typeof parent == "string" ? parent : FS.getPath(parent);
2195
2079
  path = name ? PATH.join2(parent, name) : parent;
2196
2080
  }
2197
- const mode = FS_getMode(canRead, canWrite);
2198
- const node = FS.create(path, mode);
2081
+ var mode = FS_getMode(canRead, canWrite);
2082
+ var node = FS.create(path, mode);
2199
2083
  if (data) {
2200
2084
  if (typeof data == "string") {
2201
- const arr = Array.from({ length: data.length });
2202
- for (let i = 0, len = data.length; i < len; ++i) arr[i] = data.charCodeAt(i);
2085
+ var arr = new Array(data.length);
2086
+ for (var i = 0, len = data.length; i < len; ++i) arr[i] = data.charCodeAt(i);
2203
2087
  data = arr;
2204
2088
  }
2205
2089
  FS.chmod(node, mode | 146);
2206
- const stream = FS.open(node, 577);
2090
+ var stream = FS.open(node, 577);
2207
2091
  FS.write(stream, data, 0, data.length, 0, canOwn);
2208
2092
  FS.close(stream);
2209
2093
  FS.chmod(node, mode);
2210
2094
  }
2211
2095
  },
2212
2096
  createDevice(parent, name, input, output) {
2213
- const path = PATH.join2(typeof parent == "string" ? parent : FS.getPath(parent), name);
2214
- const mode = FS_getMode(!!input, !!output);
2097
+ var path = PATH.join2(typeof parent == "string" ? parent : FS.getPath(parent), name);
2098
+ var mode = FS_getMode(!!input, !!output);
2215
2099
  FS.createDevice.major ??= 64;
2216
- const dev = FS.makedev(FS.createDevice.major++, 0);
2100
+ var dev = FS.makedev(FS.createDevice.major++, 0);
2217
2101
  FS.registerDevice(dev, {
2218
2102
  open(stream) {
2219
2103
  stream.seekable = false;
@@ -2222,8 +2106,8 @@ async function createRimeModule(moduleArg = {}) {
2222
2106
  if (output?.buffer?.length) output(10);
2223
2107
  },
2224
2108
  read(stream, buffer, offset, length, pos) {
2225
- let bytesRead = 0;
2226
- for (let i = 0; i < length; i++) {
2109
+ var bytesRead = 0;
2110
+ for (var i = 0; i < length; i++) {
2227
2111
  var result;
2228
2112
  try {
2229
2113
  result = input();
@@ -2264,42 +2148,42 @@ async function createRimeModule(moduleArg = {}) {
2264
2148
  lengthKnown = false;
2265
2149
  chunks = [];
2266
2150
  get(idx) {
2267
- if (idx > this.length - 1 || idx < 0) return void 0;
2268
- const chunkOffset = idx % this.chunkSize;
2269
- const chunkNum = idx / this.chunkSize | 0;
2151
+ if (idx > this.length - 1 || idx < 0) return;
2152
+ var chunkOffset = idx % this.chunkSize;
2153
+ var chunkNum = idx / this.chunkSize | 0;
2270
2154
  return this.getter(chunkNum)[chunkOffset];
2271
2155
  }
2272
2156
  setDataGetter(getter) {
2273
2157
  this.getter = getter;
2274
2158
  }
2275
2159
  cacheLength() {
2276
- const xhr = new XMLHttpRequest();
2160
+ var xhr = new XMLHttpRequest();
2277
2161
  xhr.open("HEAD", url, false);
2278
2162
  xhr.send(null);
2279
- if (!(xhr.status >= 200 && xhr.status < 300 || xhr.status === 304)) abort(`Couldn't load ${url}. Status: ${xhr.status}`);
2280
- let datalength = Number(xhr.getResponseHeader("Content-length"));
2281
- let header;
2282
- const hasByteServing = (header = xhr.getResponseHeader("Accept-Ranges")) && header === "bytes";
2283
- const usesGzip = (header = xhr.getResponseHeader("Content-Encoding")) && header === "gzip";
2284
- let chunkSize = 1024 * 1024;
2163
+ if (!(xhr.status >= 200 && xhr.status < 300 || xhr.status === 304)) abort("Couldn't load " + url + ". Status: " + xhr.status);
2164
+ var datalength = Number(xhr.getResponseHeader("Content-length"));
2165
+ var header;
2166
+ var hasByteServing = (header = xhr.getResponseHeader("Accept-Ranges")) && header === "bytes";
2167
+ var usesGzip = (header = xhr.getResponseHeader("Content-Encoding")) && header === "gzip";
2168
+ var chunkSize = 1024 * 1024;
2285
2169
  if (!hasByteServing) chunkSize = datalength;
2286
- const doXHR = (from, to) => {
2287
- if (from > to) abort(`invalid range (${from}, ${to}) or no bytes requested!`);
2288
- if (to > datalength - 1) abort(`only ${datalength} bytes available! programmer error!`);
2289
- const xhr$1 = new XMLHttpRequest();
2290
- xhr$1.open("GET", url, false);
2291
- if (datalength !== chunkSize) xhr$1.setRequestHeader("Range", `bytes=${from}-${to}`);
2292
- xhr$1.responseType = "arraybuffer";
2293
- if (xhr$1.overrideMimeType) xhr$1.overrideMimeType("text/plain; charset=x-user-defined");
2294
- xhr$1.send(null);
2295
- if (!(xhr$1.status >= 200 && xhr$1.status < 300 || xhr$1.status === 304)) abort(`Couldn't load ${url}. Status: ${xhr$1.status}`);
2296
- if (xhr$1.response !== void 0) return new Uint8Array(xhr$1.response || []);
2297
- return intArrayFromString(xhr$1.responseText || "", true);
2170
+ var doXHR = (from, to) => {
2171
+ if (from > to) abort("invalid range (" + from + ", " + to + ") or no bytes requested!");
2172
+ if (to > datalength - 1) abort("only " + datalength + " bytes available! programmer error!");
2173
+ var xhr = new XMLHttpRequest();
2174
+ xhr.open("GET", url, false);
2175
+ if (datalength !== chunkSize) xhr.setRequestHeader("Range", "bytes=" + from + "-" + to);
2176
+ xhr.responseType = "arraybuffer";
2177
+ if (xhr.overrideMimeType) xhr.overrideMimeType("text/plain; charset=x-user-defined");
2178
+ xhr.send(null);
2179
+ if (!(xhr.status >= 200 && xhr.status < 300 || xhr.status === 304)) abort("Couldn't load " + url + ". Status: " + xhr.status);
2180
+ if (xhr.response !== void 0) return new Uint8Array(xhr.response || []);
2181
+ return intArrayFromString(xhr.responseText || "", true);
2298
2182
  };
2299
- const lazyArray = this;
2183
+ var lazyArray = this;
2300
2184
  lazyArray.setDataGetter((chunkNum) => {
2301
- const start = chunkNum * chunkSize;
2302
- let end = (chunkNum + 1) * chunkSize - 1;
2185
+ var start = chunkNum * chunkSize;
2186
+ var end = (chunkNum + 1) * chunkSize - 1;
2303
2187
  end = Math.min(end, datalength - 1);
2304
2188
  if (typeof lazyArray.chunks[chunkNum] == "undefined") lazyArray.chunks[chunkNum] = doXHR(start, end);
2305
2189
  if (typeof lazyArray.chunks[chunkNum] == "undefined") abort("doXHR failed!");
@@ -2326,33 +2210,32 @@ async function createRimeModule(moduleArg = {}) {
2326
2210
  }
2327
2211
  if (globalThis.XMLHttpRequest) {
2328
2212
  if (!ENVIRONMENT_IS_WORKER) abort("Cannot do synchronous binary XHRs outside webworkers in modern browsers. Use --embed-file or --preload-file in emcc");
2329
- const lazyArray = new LazyUint8Array();
2330
2213
  var properties = {
2331
2214
  isDevice: false,
2332
- contents: lazyArray
2215
+ contents: new LazyUint8Array()
2333
2216
  };
2334
2217
  } else var properties = {
2335
2218
  isDevice: false,
2336
2219
  url
2337
2220
  };
2338
- const node = FS.createFile(parent, name, properties, canRead, canWrite);
2221
+ var node = FS.createFile(parent, name, properties, canRead, canWrite);
2339
2222
  if (properties.contents) node.contents = properties.contents;
2340
2223
  else if (properties.url) {
2341
2224
  node.contents = null;
2342
2225
  node.url = properties.url;
2343
2226
  }
2344
- Object.defineProperties(node, { usedBytes: { get() {
2227
+ Object.defineProperties(node, { usedBytes: { get: function() {
2345
2228
  return this.contents.length;
2346
2229
  } } });
2347
- const stream_ops = {};
2230
+ var stream_ops = {};
2348
2231
  for (const [key, fn] of Object.entries(node.stream_ops)) stream_ops[key] = (...args) => {
2349
2232
  FS.forceLoadFile(node);
2350
2233
  return fn(...args);
2351
2234
  };
2352
2235
  function writeChunks(stream, buffer, offset, length, position) {
2353
- const contents = stream.node.contents;
2236
+ var contents = stream.node.contents;
2354
2237
  if (position >= contents.length) return 0;
2355
- const size = Math.min(contents.length - position, length);
2238
+ var size = Math.min(contents.length - position, length);
2356
2239
  if (contents.slice) for (var i = 0; i < size; i++) buffer[offset + i] = contents[position + i];
2357
2240
  else for (var i = 0; i < size; i++) buffer[offset + i] = contents.get(position + i);
2358
2241
  return size;
@@ -2363,7 +2246,7 @@ async function createRimeModule(moduleArg = {}) {
2363
2246
  };
2364
2247
  stream_ops.mmap = (stream, length, position, prot, flags) => {
2365
2248
  FS.forceLoadFile(node);
2366
- const ptr = mmapAlloc(length);
2249
+ var ptr = mmapAlloc(length);
2367
2250
  if (!ptr) throw new FS.ErrnoError(48);
2368
2251
  writeChunks(stream, HEAP8, ptr, length, position);
2369
2252
  return {
@@ -2375,26 +2258,23 @@ async function createRimeModule(moduleArg = {}) {
2375
2258
  return node;
2376
2259
  }
2377
2260
  };
2378
- const UTF8ToString = (ptr, maxBytesToRead, ignoreNul) => {
2261
+ var UTF8ToString = (ptr, maxBytesToRead, ignoreNul) => {
2379
2262
  ptr >>>= 0;
2380
2263
  if (!ptr) return "";
2381
- const end = findStringEnd(HEAPU8, ptr, maxBytesToRead, ignoreNul);
2264
+ var end = findStringEnd(HEAPU8, ptr, maxBytesToRead, ignoreNul);
2382
2265
  return UTF8Decoder.decode(HEAPU8.subarray(ptr >>> 0, end >>> 0));
2383
2266
  };
2384
2267
  var SYSCALLS = {
2385
2268
  calculateAt(dirfd, path, allowEmpty) {
2386
2269
  if (PATH.isAbs(path)) return path;
2387
- let dir;
2270
+ var dir;
2388
2271
  if (dirfd === -100) dir = FS.cwd();
2389
- else {
2390
- const dirstream = SYSCALLS.getStreamFromFD(dirfd);
2391
- dir = dirstream.path;
2392
- }
2272
+ else dir = SYSCALLS.getStreamFromFD(dirfd).path;
2393
2273
  if (path.length == 0) {
2394
2274
  if (!allowEmpty) throw new FS.ErrnoError(44);
2395
2275
  return dir;
2396
2276
  }
2397
- return `${dir}/${path}`;
2277
+ return dir + "/" + path;
2398
2278
  },
2399
2279
  writeStat(buf, stat) {
2400
2280
  HEAPU32[buf >>> 2 >>> 0] = stat.dev;
@@ -2406,9 +2286,9 @@ async function createRimeModule(moduleArg = {}) {
2406
2286
  HEAP64[buf + 24 >>> 3 >>> 0] = BigInt(stat.size);
2407
2287
  HEAP32[buf + 32 >>> 2 >>> 0] = 4096;
2408
2288
  HEAP32[buf + 36 >>> 2 >>> 0] = stat.blocks;
2409
- const atime = stat.atime.getTime();
2410
- const mtime = stat.mtime.getTime();
2411
- const ctime = stat.ctime.getTime();
2289
+ var atime = stat.atime.getTime();
2290
+ var mtime = stat.mtime.getTime();
2291
+ var ctime = stat.ctime.getTime();
2412
2292
  HEAP64[buf + 40 >>> 3 >>> 0] = BigInt(Math.floor(atime / 1e3));
2413
2293
  HEAPU32[buf + 48 >>> 2 >>> 0] = atime % 1e3 * 1e3 * 1e3;
2414
2294
  HEAP64[buf + 56 >>> 3 >>> 0] = BigInt(Math.floor(mtime / 1e3));
@@ -2433,22 +2313,20 @@ async function createRimeModule(moduleArg = {}) {
2433
2313
  doMsync(addr, stream, len, flags, offset) {
2434
2314
  if (!FS.isFile(stream.node.mode)) throw new FS.ErrnoError(43);
2435
2315
  if (flags & 2) return 0;
2436
- const buffer = HEAPU8.slice(addr, addr + len);
2316
+ var buffer = HEAPU8.slice(addr, addr + len);
2437
2317
  FS.msync(stream, buffer, offset, len, flags);
2438
2318
  },
2439
2319
  getStreamFromFD(fd) {
2440
- const stream = FS.getStreamChecked(fd);
2441
- return stream;
2320
+ return FS.getStreamChecked(fd);
2442
2321
  },
2443
2322
  varargs: void 0,
2444
2323
  getStr(ptr) {
2445
- const ret = UTF8ToString(ptr);
2446
- return ret;
2324
+ return UTF8ToString(ptr);
2447
2325
  }
2448
2326
  };
2449
- const INT53_MAX = 9007199254740992;
2450
- const INT53_MIN = -9007199254740992;
2451
- const bigintToI53Checked = (num) => num < INT53_MIN || num > INT53_MAX ? Number.NaN : Number(num);
2327
+ var INT53_MAX = 9007199254740992;
2328
+ var INT53_MIN = -9007199254740992;
2329
+ var bigintToI53Checked = (num) => num < INT53_MIN || num > INT53_MAX ? NaN : Number(num);
2452
2330
  function ___syscall_chmod(path, mode) {
2453
2331
  path >>>= 0;
2454
2332
  try {
@@ -2466,10 +2344,9 @@ async function createRimeModule(moduleArg = {}) {
2466
2344
  path = SYSCALLS.getStr(path);
2467
2345
  path = SYSCALLS.calculateAt(dirfd, path);
2468
2346
  if (amode & -8) return -28;
2469
- const lookup = FS.lookupPath(path, { follow: true });
2470
- const node = lookup.node;
2347
+ var node = FS.lookupPath(path, { follow: true }).node;
2471
2348
  if (!node) return -44;
2472
- let perms = "";
2349
+ var perms = "";
2473
2350
  if (amode & 4) perms += "r";
2474
2351
  if (amode & 2) perms += "w";
2475
2352
  if (amode & 1) perms += "x";
@@ -2489,40 +2366,35 @@ async function createRimeModule(moduleArg = {}) {
2489
2366
  return -e.errno;
2490
2367
  }
2491
2368
  }
2492
- const syscallGetVarargI = () => {
2493
- const ret = HEAP32[+SYSCALLS.varargs >>> 2 >>> 0];
2369
+ var syscallGetVarargI = () => {
2370
+ var ret = HEAP32[+SYSCALLS.varargs >>> 2 >>> 0];
2494
2371
  SYSCALLS.varargs += 4;
2495
2372
  return ret;
2496
2373
  };
2497
- const syscallGetVarargP = syscallGetVarargI;
2374
+ var syscallGetVarargP = syscallGetVarargI;
2498
2375
  function ___syscall_fcntl64(fd, cmd, varargs) {
2499
2376
  varargs >>>= 0;
2500
2377
  SYSCALLS.varargs = varargs;
2501
2378
  try {
2502
- const stream = SYSCALLS.getStreamFromFD(fd);
2379
+ var stream = SYSCALLS.getStreamFromFD(fd);
2503
2380
  switch (cmd) {
2504
- case 0: {
2381
+ case 0:
2505
2382
  var arg = syscallGetVarargI();
2506
2383
  if (arg < 0) return -28;
2507
2384
  while (FS.streams[arg]) arg++;
2508
- let newStream;
2509
- newStream = FS.dupStream(stream, arg);
2510
- return newStream.fd;
2511
- }
2385
+ return FS.dupStream(stream, arg).fd;
2512
2386
  case 1:
2513
2387
  case 2: return 0;
2514
2388
  case 3: return stream.flags;
2515
- case 4: {
2389
+ case 4:
2516
2390
  var arg = syscallGetVarargI();
2517
2391
  stream.flags |= arg;
2518
2392
  return 0;
2519
- }
2520
- case 12: {
2393
+ case 12:
2521
2394
  var arg = syscallGetVarargP();
2522
- const offset = 0;
2395
+ var offset = 0;
2523
2396
  HEAP16[arg + offset >>> 1 >>> 0] = 2;
2524
2397
  return 0;
2525
- }
2526
2398
  case 13:
2527
2399
  case 14: return 0;
2528
2400
  }
@@ -2534,7 +2406,7 @@ async function createRimeModule(moduleArg = {}) {
2534
2406
  }
2535
2407
  function ___syscall_fdatasync(fd) {
2536
2408
  try {
2537
- const stream = SYSCALLS.getStreamFromFD(fd);
2409
+ SYSCALLS.getStreamFromFD(fd);
2538
2410
  return 0;
2539
2411
  } catch (e) {
2540
2412
  if (typeof FS == "undefined" || !(e.name === "ErrnoError")) throw e;
@@ -2561,14 +2433,14 @@ async function createRimeModule(moduleArg = {}) {
2561
2433
  return -e.errno;
2562
2434
  }
2563
2435
  }
2564
- const stringToUTF8 = (str, outPtr, maxBytesToWrite) => stringToUTF8Array(str, HEAPU8, outPtr, maxBytesToWrite);
2436
+ var stringToUTF8 = (str, outPtr, maxBytesToWrite) => stringToUTF8Array(str, HEAPU8, outPtr, maxBytesToWrite);
2565
2437
  function ___syscall_getcwd(buf, size) {
2566
2438
  buf >>>= 0;
2567
2439
  size >>>= 0;
2568
2440
  try {
2569
2441
  if (size === 0) return -28;
2570
- const cwd = FS.cwd();
2571
- const cwdLengthInBytes = lengthBytesUTF8(cwd) + 1;
2442
+ var cwd = FS.cwd();
2443
+ var cwdLengthInBytes = lengthBytesUTF8(cwd) + 1;
2572
2444
  if (size < cwdLengthInBytes) return -68;
2573
2445
  stringToUTF8(cwd, buf, size);
2574
2446
  return cwdLengthInBytes;
@@ -2581,23 +2453,22 @@ async function createRimeModule(moduleArg = {}) {
2581
2453
  dirp >>>= 0;
2582
2454
  count >>>= 0;
2583
2455
  try {
2584
- const stream = SYSCALLS.getStreamFromFD(fd);
2456
+ var stream = SYSCALLS.getStreamFromFD(fd);
2585
2457
  stream.getdents ||= FS.readdir(stream.path);
2586
- const struct_size = 280;
2587
- let pos = 0;
2588
- const off = FS.llseek(stream, 0, 1);
2589
- const startIdx = Math.floor(off / struct_size);
2590
- const endIdx = Math.min(stream.getdents.length, startIdx + Math.floor(count / struct_size));
2458
+ var struct_size = 280;
2459
+ var pos = 0;
2460
+ var off = FS.llseek(stream, 0, 1);
2461
+ var startIdx = Math.floor(off / struct_size);
2462
+ var endIdx = Math.min(stream.getdents.length, startIdx + Math.floor(count / struct_size));
2591
2463
  for (var idx = startIdx; idx < endIdx; idx++) {
2592
2464
  var id;
2593
2465
  var type;
2594
- const name = stream.getdents[idx];
2466
+ var name = stream.getdents[idx];
2595
2467
  if (name === ".") {
2596
2468
  id = stream.node.id;
2597
2469
  type = 4;
2598
2470
  } else if (name === "..") {
2599
- const lookup = FS.lookupPath(stream.path, { parent: true });
2600
- id = lookup.node.id;
2471
+ id = FS.lookupPath(stream.path, { parent: true }).node.id;
2601
2472
  type = 4;
2602
2473
  } else {
2603
2474
  var child;
@@ -2628,16 +2499,15 @@ async function createRimeModule(moduleArg = {}) {
2628
2499
  varargs >>>= 0;
2629
2500
  SYSCALLS.varargs = varargs;
2630
2501
  try {
2631
- const stream = SYSCALLS.getStreamFromFD(fd);
2502
+ var stream = SYSCALLS.getStreamFromFD(fd);
2632
2503
  switch (op) {
2633
- case 21509: {
2504
+ case 21509:
2634
2505
  if (!stream.tty) return -59;
2635
2506
  return 0;
2636
- }
2637
- case 21505: {
2507
+ case 21505:
2638
2508
  if (!stream.tty) return -59;
2639
2509
  if (stream.tty.ops.ioctl_tcgets) {
2640
- const termios = stream.tty.ops.ioctl_tcgets(stream);
2510
+ var termios = stream.tty.ops.ioctl_tcgets(stream);
2641
2511
  var argp = syscallGetVarargP();
2642
2512
  HEAP32[argp >>> 2 >>> 0] = termios.c_iflag || 0;
2643
2513
  HEAP32[argp + 4 >>> 2 >>> 0] = termios.c_oflag || 0;
@@ -2647,24 +2517,22 @@ async function createRimeModule(moduleArg = {}) {
2647
2517
  return 0;
2648
2518
  }
2649
2519
  return 0;
2650
- }
2651
2520
  case 21510:
2652
2521
  case 21511:
2653
- case 21512: {
2522
+ case 21512:
2654
2523
  if (!stream.tty) return -59;
2655
2524
  return 0;
2656
- }
2657
2525
  case 21506:
2658
2526
  case 21507:
2659
- case 21508: {
2527
+ case 21508:
2660
2528
  if (!stream.tty) return -59;
2661
2529
  if (stream.tty.ops.ioctl_tcsets) {
2662
2530
  var argp = syscallGetVarargP();
2663
- const c_iflag = HEAP32[argp >>> 2 >>> 0];
2664
- const c_oflag = HEAP32[argp + 4 >>> 2 >>> 0];
2665
- const c_cflag = HEAP32[argp + 8 >>> 2 >>> 0];
2666
- const c_lflag = HEAP32[argp + 12 >>> 2 >>> 0];
2667
- const c_cc = [];
2531
+ var c_iflag = HEAP32[argp >>> 2 >>> 0];
2532
+ var c_oflag = HEAP32[argp + 4 >>> 2 >>> 0];
2533
+ var c_cflag = HEAP32[argp + 8 >>> 2 >>> 0];
2534
+ var c_lflag = HEAP32[argp + 12 >>> 2 >>> 0];
2535
+ var c_cc = [];
2668
2536
  for (var i = 0; i < 32; i++) c_cc.push(HEAP8[argp + i + 17 >>> 0]);
2669
2537
  return stream.tty.ops.ioctl_tcsets(stream.tty, op, {
2670
2538
  c_iflag,
@@ -2675,40 +2543,33 @@ async function createRimeModule(moduleArg = {}) {
2675
2543
  });
2676
2544
  }
2677
2545
  return 0;
2678
- }
2679
- case 21519: {
2546
+ case 21519:
2680
2547
  if (!stream.tty) return -59;
2681
2548
  var argp = syscallGetVarargP();
2682
2549
  HEAP32[argp >>> 2 >>> 0] = 0;
2683
2550
  return 0;
2684
- }
2685
- case 21520: {
2551
+ case 21520:
2686
2552
  if (!stream.tty) return -59;
2687
2553
  return -28;
2688
- }
2689
2554
  case 21537:
2690
- case 21531: {
2555
+ case 21531:
2691
2556
  var argp = syscallGetVarargP();
2692
2557
  return FS.ioctl(stream, op, argp);
2693
- }
2694
- case 21523: {
2558
+ case 21523:
2695
2559
  if (!stream.tty) return -59;
2696
2560
  if (stream.tty.ops.ioctl_tiocgwinsz) {
2697
- const winsize = stream.tty.ops.ioctl_tiocgwinsz(stream.tty);
2561
+ var winsize = stream.tty.ops.ioctl_tiocgwinsz(stream.tty);
2698
2562
  var argp = syscallGetVarargP();
2699
2563
  HEAP16[argp >>> 1 >>> 0] = winsize[0];
2700
2564
  HEAP16[argp + 2 >>> 1 >>> 0] = winsize[1];
2701
2565
  }
2702
2566
  return 0;
2703
- }
2704
- case 21524: {
2567
+ case 21524:
2705
2568
  if (!stream.tty) return -59;
2706
2569
  return 0;
2707
- }
2708
- case 21515: {
2570
+ case 21515:
2709
2571
  if (!stream.tty) return -59;
2710
2572
  return 0;
2711
- }
2712
2573
  default: return -28;
2713
2574
  }
2714
2575
  } catch (e) {
@@ -2744,8 +2605,8 @@ async function createRimeModule(moduleArg = {}) {
2744
2605
  buf >>>= 0;
2745
2606
  try {
2746
2607
  path = SYSCALLS.getStr(path);
2747
- const nofollow = flags & 256;
2748
- const allowEmpty = flags & 4096;
2608
+ var nofollow = flags & 256;
2609
+ var allowEmpty = flags & 4096;
2749
2610
  flags = flags & -6401;
2750
2611
  path = SYSCALLS.calculateAt(dirfd, path, allowEmpty);
2751
2612
  return SYSCALLS.writeStat(buf, nofollow ? FS.lstat(path) : FS.stat(path));
@@ -2761,7 +2622,7 @@ async function createRimeModule(moduleArg = {}) {
2761
2622
  try {
2762
2623
  path = SYSCALLS.getStr(path);
2763
2624
  path = SYSCALLS.calculateAt(dirfd, path);
2764
- const mode = varargs ? syscallGetVarargI() : 0;
2625
+ var mode = varargs ? syscallGetVarargI() : 0;
2765
2626
  return FS.open(path, flags, mode).fd;
2766
2627
  } catch (e) {
2767
2628
  if (typeof FS == "undefined" || !(e.name === "ErrnoError")) throw e;
@@ -2776,9 +2637,9 @@ async function createRimeModule(moduleArg = {}) {
2776
2637
  path = SYSCALLS.getStr(path);
2777
2638
  path = SYSCALLS.calculateAt(dirfd, path);
2778
2639
  if (bufsize <= 0) return -28;
2779
- const ret = FS.readlink(path);
2780
- const len = Math.min(bufsize, lengthBytesUTF8(ret));
2781
- const endChar = HEAP8[buf + len >>> 0];
2640
+ var ret = FS.readlink(path);
2641
+ var len = Math.min(bufsize, lengthBytesUTF8(ret));
2642
+ var endChar = HEAP8[buf + len >>> 0];
2782
2643
  stringToUTF8(ret, buf, bufsize + 1);
2783
2644
  HEAP8[buf + len >>> 0] = endChar;
2784
2645
  return len;
@@ -2851,14 +2712,14 @@ async function createRimeModule(moduleArg = {}) {
2851
2712
  return -e.errno;
2852
2713
  }
2853
2714
  }
2854
- const __abort_js = () => abort("");
2855
- let runtimeKeepaliveCounter = 0;
2856
- const __emscripten_runtime_keepalive_clear = () => {
2715
+ var __abort_js = () => abort("");
2716
+ var runtimeKeepaliveCounter = 0;
2717
+ var __emscripten_runtime_keepalive_clear = () => {
2857
2718
  noExitRuntime = false;
2858
2719
  runtimeKeepaliveCounter = 0;
2859
2720
  };
2860
- const isLeapYear = (year) => year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0);
2861
- const MONTH_DAYS_LEAP_CUMULATIVE = [
2721
+ var isLeapYear = (year) => year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0);
2722
+ var MONTH_DAYS_LEAP_CUMULATIVE = [
2862
2723
  0,
2863
2724
  31,
2864
2725
  60,
@@ -2872,7 +2733,7 @@ async function createRimeModule(moduleArg = {}) {
2872
2733
  305,
2873
2734
  335
2874
2735
  ];
2875
- const MONTH_DAYS_REGULAR_CUMULATIVE = [
2736
+ var MONTH_DAYS_REGULAR_CUMULATIVE = [
2876
2737
  0,
2877
2738
  31,
2878
2739
  59,
@@ -2886,16 +2747,13 @@ async function createRimeModule(moduleArg = {}) {
2886
2747
  304,
2887
2748
  334
2888
2749
  ];
2889
- const ydayFromDate = (date) => {
2890
- const leap = isLeapYear(date.getFullYear());
2891
- const monthDaysCumulative = leap ? MONTH_DAYS_LEAP_CUMULATIVE : MONTH_DAYS_REGULAR_CUMULATIVE;
2892
- const yday = monthDaysCumulative[date.getMonth()] + date.getDate() - 1;
2893
- return yday;
2750
+ var ydayFromDate = (date) => {
2751
+ return (isLeapYear(date.getFullYear()) ? MONTH_DAYS_LEAP_CUMULATIVE : MONTH_DAYS_REGULAR_CUMULATIVE)[date.getMonth()] + date.getDate() - 1;
2894
2752
  };
2895
2753
  function __localtime_js(time, tmPtr) {
2896
2754
  time = bigintToI53Checked(time);
2897
2755
  tmPtr >>>= 0;
2898
- const date = new Date(time * 1e3);
2756
+ var date = /* @__PURE__ */ new Date(time * 1e3);
2899
2757
  HEAP32[tmPtr >>> 2 >>> 0] = date.getSeconds();
2900
2758
  HEAP32[tmPtr + 4 >>> 2 >>> 0] = date.getMinutes();
2901
2759
  HEAP32[tmPtr + 8 >>> 2 >>> 0] = date.getHours();
@@ -2903,13 +2761,13 @@ async function createRimeModule(moduleArg = {}) {
2903
2761
  HEAP32[tmPtr + 16 >>> 2 >>> 0] = date.getMonth();
2904
2762
  HEAP32[tmPtr + 20 >>> 2 >>> 0] = date.getFullYear() - 1900;
2905
2763
  HEAP32[tmPtr + 24 >>> 2 >>> 0] = date.getDay();
2906
- const yday = ydayFromDate(date) | 0;
2764
+ var yday = ydayFromDate(date) | 0;
2907
2765
  HEAP32[tmPtr + 28 >>> 2 >>> 0] = yday;
2908
2766
  HEAP32[tmPtr + 36 >>> 2 >>> 0] = -(date.getTimezoneOffset() * 60);
2909
- const start = new Date(date.getFullYear(), 0, 1);
2910
- const summerOffset = new Date(date.getFullYear(), 6, 1).getTimezoneOffset();
2911
- const winterOffset = start.getTimezoneOffset();
2912
- const dst = (summerOffset != winterOffset && date.getTimezoneOffset() == Math.min(winterOffset, summerOffset)) | 0;
2767
+ var start = new Date(date.getFullYear(), 0, 1);
2768
+ var summerOffset = new Date(date.getFullYear(), 6, 1).getTimezoneOffset();
2769
+ var winterOffset = start.getTimezoneOffset();
2770
+ var dst = (summerOffset != winterOffset && date.getTimezoneOffset() == Math.min(winterOffset, summerOffset)) | 0;
2913
2771
  HEAP32[tmPtr + 32 >>> 2 >>> 0] = dst;
2914
2772
  }
2915
2773
  function __mmap_js(len, prot, flags, fd, offset, allocated, addr) {
@@ -2918,9 +2776,9 @@ async function createRimeModule(moduleArg = {}) {
2918
2776
  allocated >>>= 0;
2919
2777
  addr >>>= 0;
2920
2778
  try {
2921
- const stream = SYSCALLS.getStreamFromFD(fd);
2922
- const res = FS.mmap(stream, len, offset, prot, flags);
2923
- const ptr = res.ptr;
2779
+ var stream = SYSCALLS.getStreamFromFD(fd);
2780
+ var res = FS.mmap(stream, len, offset, prot, flags);
2781
+ var ptr = res.ptr;
2924
2782
  HEAP32[allocated >>> 2 >>> 0] = res.allocated;
2925
2783
  HEAPU32[addr >>> 2 >>> 0] = ptr;
2926
2784
  return 0;
@@ -2934,40 +2792,40 @@ async function createRimeModule(moduleArg = {}) {
2934
2792
  len >>>= 0;
2935
2793
  offset = bigintToI53Checked(offset);
2936
2794
  try {
2937
- const stream = SYSCALLS.getStreamFromFD(fd);
2795
+ var stream = SYSCALLS.getStreamFromFD(fd);
2938
2796
  if (prot & 2) SYSCALLS.doMsync(addr, stream, len, flags, offset);
2939
2797
  } catch (e) {
2940
2798
  if (typeof FS == "undefined" || !(e.name === "ErrnoError")) throw e;
2941
2799
  return -e.errno;
2942
2800
  }
2943
2801
  }
2944
- const timers = {};
2945
- const handleException = (e) => {
2802
+ var timers = {};
2803
+ var handleException = (e) => {
2946
2804
  if (e instanceof ExitStatus || e == "unwind") return EXITSTATUS;
2947
2805
  quit_(1, e);
2948
2806
  };
2949
- const keepRuntimeAlive = () => noExitRuntime || runtimeKeepaliveCounter > 0;
2950
- const _proc_exit = (code) => {
2807
+ var keepRuntimeAlive = () => noExitRuntime || runtimeKeepaliveCounter > 0;
2808
+ var _proc_exit = (code) => {
2951
2809
  EXITSTATUS = code;
2952
2810
  if (!keepRuntimeAlive()) {
2953
- Module.onExit?.(code);
2811
+ Module["onExit"]?.(code);
2954
2812
  ABORT = true;
2955
2813
  }
2956
2814
  quit_(code, new ExitStatus(code));
2957
2815
  };
2958
- const exitJS = (status, implicit) => {
2816
+ var exitJS = (status, implicit) => {
2959
2817
  EXITSTATUS = status;
2960
2818
  _proc_exit(status);
2961
2819
  };
2962
- const _exit = exitJS;
2963
- const maybeExit = () => {
2820
+ var _exit = exitJS;
2821
+ var maybeExit = () => {
2964
2822
  if (!keepRuntimeAlive()) try {
2965
2823
  _exit(EXITSTATUS);
2966
2824
  } catch (e) {
2967
2825
  handleException(e);
2968
2826
  }
2969
2827
  };
2970
- const callUserCallback = (func) => {
2828
+ var callUserCallback = (func) => {
2971
2829
  if (ABORT) return;
2972
2830
  try {
2973
2831
  return func();
@@ -2977,45 +2835,42 @@ async function createRimeModule(moduleArg = {}) {
2977
2835
  maybeExit();
2978
2836
  }
2979
2837
  };
2980
- const _emscripten_get_now = () => performance.now();
2981
- const __setitimer_js = (which, timeout_ms) => {
2838
+ var _emscripten_get_now = () => performance.now();
2839
+ var __setitimer_js = (which, timeout_ms) => {
2982
2840
  if (timers[which]) {
2983
2841
  clearTimeout(timers[which].id);
2984
2842
  delete timers[which];
2985
2843
  }
2986
2844
  if (!timeout_ms) return 0;
2987
- const id = setTimeout(() => {
2988
- delete timers[which];
2989
- callUserCallback(() => __emscripten_timeout(which, _emscripten_get_now()));
2990
- }, timeout_ms);
2991
2845
  timers[which] = {
2992
- id,
2846
+ id: setTimeout(() => {
2847
+ delete timers[which];
2848
+ callUserCallback(() => __emscripten_timeout(which, _emscripten_get_now()));
2849
+ }, timeout_ms),
2993
2850
  timeout_ms
2994
2851
  };
2995
2852
  return 0;
2996
2853
  };
2997
- const __tzset_js = function(timezone, daylight, std_name, dst_name) {
2854
+ var __tzset_js = function(timezone, daylight, std_name, dst_name) {
2998
2855
  timezone >>>= 0;
2999
2856
  daylight >>>= 0;
3000
2857
  std_name >>>= 0;
3001
2858
  dst_name >>>= 0;
3002
- const currentYear = new Date().getFullYear();
3003
- const winter = new Date(currentYear, 0, 1);
3004
- const summer = new Date(currentYear, 6, 1);
3005
- const winterOffset = winter.getTimezoneOffset();
3006
- const summerOffset = summer.getTimezoneOffset();
3007
- const stdTimezoneOffset = Math.max(winterOffset, summerOffset);
2859
+ var currentYear = (/* @__PURE__ */ new Date()).getFullYear();
2860
+ var winter = new Date(currentYear, 0, 1);
2861
+ var summer = new Date(currentYear, 6, 1);
2862
+ var winterOffset = winter.getTimezoneOffset();
2863
+ var summerOffset = summer.getTimezoneOffset();
2864
+ var stdTimezoneOffset = Math.max(winterOffset, summerOffset);
3008
2865
  HEAPU32[timezone >>> 2 >>> 0] = stdTimezoneOffset * 60;
3009
2866
  HEAP32[daylight >>> 2 >>> 0] = Number(winterOffset != summerOffset);
3010
- const extractZone = (timezoneOffset) => {
3011
- const sign = timezoneOffset >= 0 ? "-" : "+";
3012
- const absOffset = Math.abs(timezoneOffset);
3013
- const hours = String(Math.floor(absOffset / 60)).padStart(2, "0");
3014
- const minutes = String(absOffset % 60).padStart(2, "0");
3015
- return `UTC${sign}${hours}${minutes}`;
2867
+ var extractZone = (timezoneOffset) => {
2868
+ var sign = timezoneOffset >= 0 ? "-" : "+";
2869
+ var absOffset = Math.abs(timezoneOffset);
2870
+ return `UTC${sign}${String(Math.floor(absOffset / 60)).padStart(2, "0")}${String(absOffset % 60).padStart(2, "0")}`;
3016
2871
  };
3017
- const winterName = extractZone(winterOffset);
3018
- const summerName = extractZone(summerOffset);
2872
+ var winterName = extractZone(winterOffset);
2873
+ var summerName = extractZone(summerOffset);
3019
2874
  if (summerOffset < winterOffset) {
3020
2875
  stringToUTF8(winterName, std_name, 17);
3021
2876
  stringToUTF8(summerName, dst_name, 17);
@@ -3024,25 +2879,24 @@ async function createRimeModule(moduleArg = {}) {
3024
2879
  stringToUTF8(summerName, std_name, 17);
3025
2880
  }
3026
2881
  };
3027
- const _emscripten_date_now = () => Date.now();
3028
- const nowIsMonotonic = 1;
3029
- const checkWasiClock = (clock_id) => clock_id >= 0 && clock_id <= 3;
2882
+ var _emscripten_date_now = () => Date.now();
2883
+ var nowIsMonotonic = 1;
2884
+ var checkWasiClock = (clock_id) => clock_id >= 0 && clock_id <= 3;
3030
2885
  function _clock_time_get(clk_id, ignored_precision, ptime) {
3031
2886
  ignored_precision = bigintToI53Checked(ignored_precision);
3032
2887
  ptime >>>= 0;
3033
2888
  if (!checkWasiClock(clk_id)) return 28;
3034
- let now;
2889
+ var now;
3035
2890
  if (clk_id === 0) now = _emscripten_date_now();
3036
2891
  else if (nowIsMonotonic) now = _emscripten_get_now();
3037
2892
  else return 52;
3038
- const nsec = Math.round(now * 1e3 * 1e3);
2893
+ var nsec = Math.round(now * 1e3 * 1e3);
3039
2894
  HEAP64[ptime >>> 3 >>> 0] = BigInt(nsec);
3040
2895
  return 0;
3041
2896
  }
3042
- const getHeapMax = () => 4294901760;
3043
- const growMemory = (size) => {
3044
- const oldHeapSize = wasmMemory.buffer.byteLength;
3045
- const pages = (size - oldHeapSize + 65535) / 65536 | 0;
2897
+ var getHeapMax = () => 4294901760;
2898
+ var growMemory = (size) => {
2899
+ var pages = (size - wasmMemory.buffer.byteLength + 65535) / 65536 | 0;
3046
2900
  try {
3047
2901
  wasmMemory.grow(pages);
3048
2902
  updateMemoryViews();
@@ -3051,35 +2905,32 @@ async function createRimeModule(moduleArg = {}) {
3051
2905
  };
3052
2906
  function _emscripten_resize_heap(requestedSize) {
3053
2907
  requestedSize >>>= 0;
3054
- const oldSize = HEAPU8.length;
3055
- const maxHeapSize = getHeapMax();
2908
+ var oldSize = HEAPU8.length;
2909
+ var maxHeapSize = getHeapMax();
3056
2910
  if (requestedSize > maxHeapSize) return false;
3057
- for (let cutDown = 1; cutDown <= 4; cutDown *= 2) {
3058
- let overGrownHeapSize = oldSize * (1 + .2 / cutDown);
2911
+ for (var cutDown = 1; cutDown <= 4; cutDown *= 2) {
2912
+ var overGrownHeapSize = oldSize * (1 + .2 / cutDown);
3059
2913
  overGrownHeapSize = Math.min(overGrownHeapSize, requestedSize + 100663296);
3060
- const newSize = Math.min(maxHeapSize, alignMemory(Math.max(requestedSize, overGrownHeapSize), 65536));
3061
- const replacement = growMemory(newSize);
3062
- if (replacement) return true;
2914
+ if (growMemory(Math.min(maxHeapSize, alignMemory(Math.max(requestedSize, overGrownHeapSize), 65536)))) return true;
3063
2915
  }
3064
2916
  return false;
3065
2917
  }
3066
- const ENV = {};
3067
- const getExecutableName = () => thisProgram || "./this.program";
3068
- const getEnvStrings = () => {
2918
+ var ENV = {};
2919
+ var getExecutableName = () => thisProgram || "./this.program";
2920
+ var getEnvStrings = () => {
3069
2921
  if (!getEnvStrings.strings) {
3070
- const lang = `${(globalThis.navigator?.language ?? "C").replace("-", "_")}.UTF-8`;
3071
- const env = {
2922
+ var env = {
3072
2923
  USER: "web_user",
3073
2924
  LOGNAME: "web_user",
3074
2925
  PATH: "/",
3075
2926
  PWD: "/",
3076
2927
  HOME: "/home/web_user",
3077
- LANG: lang,
2928
+ LANG: (globalThis.navigator?.language ?? "C").replace("-", "_") + ".UTF-8",
3078
2929
  _: getExecutableName()
3079
2930
  };
3080
2931
  for (var x in ENV) if (ENV[x] === void 0) delete env[x];
3081
2932
  else env[x] = ENV[x];
3082
- const strings = [];
2933
+ var strings = [];
3083
2934
  for (var x in env) strings.push(`${x}=${env[x]}`);
3084
2935
  getEnvStrings.strings = strings;
3085
2936
  }
@@ -3088,10 +2939,10 @@ async function createRimeModule(moduleArg = {}) {
3088
2939
  function _environ_get(__environ, environ_buf) {
3089
2940
  __environ >>>= 0;
3090
2941
  environ_buf >>>= 0;
3091
- let bufSize = 0;
3092
- let envp = 0;
3093
- for (const string of getEnvStrings()) {
3094
- const ptr = environ_buf + bufSize;
2942
+ var bufSize = 0;
2943
+ var envp = 0;
2944
+ for (var string of getEnvStrings()) {
2945
+ var ptr = environ_buf + bufSize;
3095
2946
  HEAPU32[__environ + envp >>> 2 >>> 0] = ptr;
3096
2947
  bufSize += stringToUTF8(string, ptr, Infinity) + 1;
3097
2948
  envp += 4;
@@ -3101,16 +2952,16 @@ async function createRimeModule(moduleArg = {}) {
3101
2952
  function _environ_sizes_get(penviron_count, penviron_buf_size) {
3102
2953
  penviron_count >>>= 0;
3103
2954
  penviron_buf_size >>>= 0;
3104
- const strings = getEnvStrings();
2955
+ var strings = getEnvStrings();
3105
2956
  HEAPU32[penviron_count >>> 2 >>> 0] = strings.length;
3106
- let bufSize = 0;
3107
- for (const string of strings) bufSize += lengthBytesUTF8(string) + 1;
2957
+ var bufSize = 0;
2958
+ for (var string of strings) bufSize += lengthBytesUTF8(string) + 1;
3108
2959
  HEAPU32[penviron_buf_size >>> 2 >>> 0] = bufSize;
3109
2960
  return 0;
3110
2961
  }
3111
2962
  function _fd_close(fd) {
3112
2963
  try {
3113
- const stream = SYSCALLS.getStreamFromFD(fd);
2964
+ var stream = SYSCALLS.getStreamFromFD(fd);
3114
2965
  FS.close(stream);
3115
2966
  return 0;
3116
2967
  } catch (e) {
@@ -3121,13 +2972,11 @@ async function createRimeModule(moduleArg = {}) {
3121
2972
  function _fd_fdstat_get(fd, pbuf) {
3122
2973
  pbuf >>>= 0;
3123
2974
  try {
3124
- const rightsBase = 0;
3125
- const rightsInheriting = 0;
3126
- const flags = 0;
3127
- {
3128
- const stream = SYSCALLS.getStreamFromFD(fd);
3129
- var type = stream.tty ? 2 : FS.isDir(stream.mode) ? 3 : FS.isLink(stream.mode) ? 7 : 4;
3130
- }
2975
+ var rightsBase = 0;
2976
+ var rightsInheriting = 0;
2977
+ var flags = 0;
2978
+ var stream = SYSCALLS.getStreamFromFD(fd);
2979
+ var type = stream.tty ? 2 : FS.isDir(stream.mode) ? 3 : FS.isLink(stream.mode) ? 7 : 4;
3131
2980
  HEAP8[pbuf >>> 0] = type;
3132
2981
  HEAP16[pbuf + 2 >>> 1 >>> 0] = flags;
3133
2982
  HEAP64[pbuf + 8 >>> 3 >>> 0] = BigInt(rightsBase);
@@ -3138,13 +2987,13 @@ async function createRimeModule(moduleArg = {}) {
3138
2987
  return e.errno;
3139
2988
  }
3140
2989
  }
3141
- const doReadv = (stream, iov, iovcnt, offset) => {
3142
- let ret = 0;
3143
- for (let i = 0; i < iovcnt; i++) {
3144
- const ptr = HEAPU32[iov >>> 2 >>> 0];
3145
- const len = HEAPU32[iov + 4 >>> 2 >>> 0];
2990
+ var doReadv = (stream, iov, iovcnt, offset) => {
2991
+ var ret = 0;
2992
+ for (var i = 0; i < iovcnt; i++) {
2993
+ var ptr = HEAPU32[iov >>> 2 >>> 0];
2994
+ var len = HEAPU32[iov + 4 >>> 2 >>> 0];
3146
2995
  iov += 8;
3147
- const curr = FS.read(stream, HEAP8, ptr, len, offset);
2996
+ var curr = FS.read(stream, HEAP8, ptr, len, offset);
3148
2997
  if (curr < 0) return -1;
3149
2998
  ret += curr;
3150
2999
  if (curr < len) break;
@@ -3159,8 +3008,7 @@ async function createRimeModule(moduleArg = {}) {
3159
3008
  pnum >>>= 0;
3160
3009
  try {
3161
3010
  if (isNaN(offset)) return 61;
3162
- const stream = SYSCALLS.getStreamFromFD(fd);
3163
- const num = doReadv(stream, iov, iovcnt, offset);
3011
+ var num = doReadv(SYSCALLS.getStreamFromFD(fd), iov, iovcnt, offset);
3164
3012
  HEAPU32[pnum >>> 2 >>> 0] = num;
3165
3013
  return 0;
3166
3014
  } catch (e) {
@@ -3173,8 +3021,7 @@ async function createRimeModule(moduleArg = {}) {
3173
3021
  iovcnt >>>= 0;
3174
3022
  pnum >>>= 0;
3175
3023
  try {
3176
- const stream = SYSCALLS.getStreamFromFD(fd);
3177
- const num = doReadv(stream, iov, iovcnt);
3024
+ var num = doReadv(SYSCALLS.getStreamFromFD(fd), iov, iovcnt);
3178
3025
  HEAPU32[pnum >>> 2 >>> 0] = num;
3179
3026
  return 0;
3180
3027
  } catch (e) {
@@ -3187,7 +3034,7 @@ async function createRimeModule(moduleArg = {}) {
3187
3034
  newOffset >>>= 0;
3188
3035
  try {
3189
3036
  if (isNaN(offset)) return 61;
3190
- const stream = SYSCALLS.getStreamFromFD(fd);
3037
+ var stream = SYSCALLS.getStreamFromFD(fd);
3191
3038
  FS.llseek(stream, offset, whence);
3192
3039
  HEAP64[newOffset >>> 3 >>> 0] = BigInt(stream.position);
3193
3040
  if (stream.getdents && offset === 0 && whence === 0) stream.getdents = null;
@@ -3197,13 +3044,13 @@ async function createRimeModule(moduleArg = {}) {
3197
3044
  return e.errno;
3198
3045
  }
3199
3046
  }
3200
- const doWritev = (stream, iov, iovcnt, offset) => {
3201
- let ret = 0;
3202
- for (let i = 0; i < iovcnt; i++) {
3203
- const ptr = HEAPU32[iov >>> 2 >>> 0];
3204
- const len = HEAPU32[iov + 4 >>> 2 >>> 0];
3047
+ var doWritev = (stream, iov, iovcnt, offset) => {
3048
+ var ret = 0;
3049
+ for (var i = 0; i < iovcnt; i++) {
3050
+ var ptr = HEAPU32[iov >>> 2 >>> 0];
3051
+ var len = HEAPU32[iov + 4 >>> 2 >>> 0];
3205
3052
  iov += 8;
3206
- const curr = FS.write(stream, HEAP8, ptr, len, offset);
3053
+ var curr = FS.write(stream, HEAP8, ptr, len, offset);
3207
3054
  if (curr < 0) return -1;
3208
3055
  ret += curr;
3209
3056
  if (curr < len) break;
@@ -3216,8 +3063,7 @@ async function createRimeModule(moduleArg = {}) {
3216
3063
  iovcnt >>>= 0;
3217
3064
  pnum >>>= 0;
3218
3065
  try {
3219
- const stream = SYSCALLS.getStreamFromFD(fd);
3220
- const num = doWritev(stream, iov, iovcnt);
3066
+ var num = doWritev(SYSCALLS.getStreamFromFD(fd), iov, iovcnt);
3221
3067
  HEAPU32[pnum >>> 2 >>> 0] = num;
3222
3068
  return 0;
3223
3069
  } catch (e) {
@@ -3236,109 +3082,106 @@ async function createRimeModule(moduleArg = {}) {
3236
3082
  return e.errno;
3237
3083
  }
3238
3084
  }
3239
- const getCFunc = (ident) => {
3240
- const func = Module[`_${ident}`];
3241
- return func;
3085
+ var getCFunc = (ident) => {
3086
+ return Module["_" + ident];
3242
3087
  };
3243
- const writeArrayToMemory = (array, buffer) => {
3088
+ var writeArrayToMemory = (array, buffer) => {
3244
3089
  HEAP8.set(array, buffer >>> 0);
3245
3090
  };
3246
- const stackAlloc = (sz) => __emscripten_stack_alloc(sz);
3247
- const stringToUTF8OnStack = (str) => {
3248
- const size = lengthBytesUTF8(str) + 1;
3249
- const ret = stackAlloc(size);
3091
+ var stackAlloc = (sz) => __emscripten_stack_alloc(sz);
3092
+ var stringToUTF8OnStack = (str) => {
3093
+ var size = lengthBytesUTF8(str) + 1;
3094
+ var ret = stackAlloc(size);
3250
3095
  stringToUTF8(str, ret, size);
3251
3096
  return ret;
3252
3097
  };
3253
- const stackSave = () => _emscripten_stack_get_current();
3254
- const stackRestore = (val) => __emscripten_stack_restore(val);
3255
- const ccall = (ident, returnType, argTypes, args, opts) => {
3256
- const toC = {
3098
+ var stackSave = () => _emscripten_stack_get_current();
3099
+ var stackRestore = (val) => __emscripten_stack_restore(val);
3100
+ var ccall = (ident, returnType, argTypes, args, opts) => {
3101
+ var toC = {
3257
3102
  string: (str) => {
3258
- let ret$1 = 0;
3259
- if (str !== null && str !== void 0 && str !== 0) ret$1 = stringToUTF8OnStack(str);
3260
- return ret$1;
3103
+ var ret = 0;
3104
+ if (str !== null && str !== void 0 && str !== 0) ret = stringToUTF8OnStack(str);
3105
+ return ret;
3261
3106
  },
3262
3107
  array: (arr) => {
3263
- const ret$1 = stackAlloc(arr.length);
3264
- writeArrayToMemory(arr, ret$1);
3265
- return ret$1;
3108
+ var ret = stackAlloc(arr.length);
3109
+ writeArrayToMemory(arr, ret);
3110
+ return ret;
3266
3111
  }
3267
3112
  };
3268
- function convertReturnValue(ret$1) {
3269
- if (returnType === "string") return UTF8ToString(ret$1);
3270
- if (returnType === "pointer") return ret$1 >>> 0;
3271
- if (returnType === "boolean") return Boolean(ret$1);
3272
- return ret$1;
3273
- }
3274
- const func = getCFunc(ident);
3275
- const cArgs = [];
3276
- let stack = 0;
3277
- if (args) for (let i = 0; i < args.length; i++) {
3278
- const converter = toC[argTypes[i]];
3113
+ function convertReturnValue(ret) {
3114
+ if (returnType === "string") return UTF8ToString(ret);
3115
+ if (returnType === "pointer") return ret >>> 0;
3116
+ if (returnType === "boolean") return Boolean(ret);
3117
+ return ret;
3118
+ }
3119
+ var func = getCFunc(ident);
3120
+ var cArgs = [];
3121
+ var stack = 0;
3122
+ if (args) for (var i = 0; i < args.length; i++) {
3123
+ var converter = toC[argTypes[i]];
3279
3124
  if (converter) {
3280
3125
  if (stack === 0) stack = stackSave();
3281
3126
  cArgs[i] = converter(args[i]);
3282
3127
  } else cArgs[i] = args[i];
3283
3128
  }
3284
- let ret = func(...cArgs);
3285
- function onDone(ret$1) {
3129
+ var ret = func(...cArgs);
3130
+ function onDone(ret) {
3286
3131
  if (stack !== 0) stackRestore(stack);
3287
- return convertReturnValue(ret$1);
3132
+ return convertReturnValue(ret);
3288
3133
  }
3289
3134
  ret = onDone(ret);
3290
3135
  return ret;
3291
3136
  };
3292
- const FS_createPath = (...args) => FS.createPath(...args);
3293
- const FS_unlink = (...args) => FS.unlink(...args);
3294
- const FS_createLazyFile = (...args) => FS.createLazyFile(...args);
3295
- const FS_createDevice = (...args) => FS.createDevice(...args);
3137
+ var FS_createPath = (...args) => FS.createPath(...args);
3138
+ var FS_unlink = (...args) => FS.unlink(...args);
3139
+ var FS_createLazyFile = (...args) => FS.createLazyFile(...args);
3140
+ var FS_createDevice = (...args) => FS.createDevice(...args);
3296
3141
  FS.createPreloadedFile = FS_createPreloadedFile;
3297
3142
  FS.preloadFile = FS_preloadFile;
3298
3143
  FS.staticInit();
3299
- {
3300
- if (Module.noExitRuntime) noExitRuntime = Module.noExitRuntime;
3301
- if (Module.preloadPlugins) preloadPlugins = Module.preloadPlugins;
3302
- if (Module.print) out = Module.print;
3303
- if (Module.printErr) err = Module.printErr;
3304
- if (Module.wasmBinary) wasmBinary = Module.wasmBinary;
3305
- if (Module.arguments) arguments_ = Module.arguments;
3306
- if (Module.thisProgram) thisProgram = Module.thisProgram;
3307
- if (Module.preInit) {
3308
- if (typeof Module.preInit == "function") Module.preInit = [Module.preInit];
3309
- while (Module.preInit.length > 0) Module.preInit.shift()();
3310
- }
3144
+ if (Module["noExitRuntime"]) noExitRuntime = Module["noExitRuntime"];
3145
+ if (Module["preloadPlugins"]) preloadPlugins = Module["preloadPlugins"];
3146
+ if (Module["print"]) out = Module["print"];
3147
+ if (Module["printErr"]) err = Module["printErr"];
3148
+ if (Module["wasmBinary"]) wasmBinary = Module["wasmBinary"];
3149
+ if (Module["arguments"]) Module["arguments"];
3150
+ if (Module["thisProgram"]) thisProgram = Module["thisProgram"];
3151
+ if (Module["preInit"]) {
3152
+ if (typeof Module["preInit"] == "function") Module["preInit"] = [Module["preInit"]];
3153
+ while (Module["preInit"].length > 0) Module["preInit"].shift()();
3311
3154
  }
3312
- Module.addRunDependency = addRunDependency;
3313
- Module.removeRunDependency = removeRunDependency;
3314
- Module.ccall = ccall;
3315
- Module.FS_preloadFile = FS_preloadFile;
3316
- Module.FS_unlink = FS_unlink;
3317
- Module.FS_createPath = FS_createPath;
3318
- Module.FS_createDevice = FS_createDevice;
3319
- Module.FS = FS;
3320
- Module.FS_createDataFile = FS_createDataFile;
3321
- Module.FS_createLazyFile = FS_createLazyFile;
3322
- let _free, _malloc, _rime_wasm_init, _rime_wasm_process_input, _rime_wasm_pick_candidate, _rime_wasm_flip_page, _rime_wasm_clear_input, _rime_wasm_set_option, _rime_wasm_get_version, _rime_wasm_destroy, _emscripten_builtin_memalign, __emscripten_timeout, ___trap, __emscripten_stack_restore, __emscripten_stack_alloc, _emscripten_stack_get_current, memory, __indirect_function_table, wasmMemory;
3323
- function assignWasmExports(wasmExports$1) {
3324
- _free = Module._free = wasmExports$1.R;
3325
- _malloc = Module._malloc = wasmExports$1.S;
3326
- _rime_wasm_init = Module._rime_wasm_init = wasmExports$1.T;
3327
- _rime_wasm_process_input = Module._rime_wasm_process_input = wasmExports$1.U;
3328
- _rime_wasm_pick_candidate = Module._rime_wasm_pick_candidate = wasmExports$1.V;
3329
- _rime_wasm_flip_page = Module._rime_wasm_flip_page = wasmExports$1.W;
3330
- _rime_wasm_clear_input = Module._rime_wasm_clear_input = wasmExports$1.X;
3331
- _rime_wasm_set_option = Module._rime_wasm_set_option = wasmExports$1.Y;
3332
- _rime_wasm_get_version = Module._rime_wasm_get_version = wasmExports$1.Z;
3333
- _rime_wasm_destroy = Module._rime_wasm_destroy = wasmExports$1._;
3334
- _emscripten_builtin_memalign = wasmExports$1.$;
3335
- __emscripten_timeout = wasmExports$1.aa;
3336
- ___trap = wasmExports$1.ba;
3337
- __emscripten_stack_restore = wasmExports$1.ca;
3338
- __emscripten_stack_alloc = wasmExports$1.da;
3339
- _emscripten_stack_get_current = wasmExports$1.ea;
3340
- memory = wasmMemory = wasmExports$1.P;
3341
- __indirect_function_table = wasmExports$1.__indirect_function_table;
3155
+ Module["addRunDependency"] = addRunDependency;
3156
+ Module["removeRunDependency"] = removeRunDependency;
3157
+ Module["ccall"] = ccall;
3158
+ Module["FS_preloadFile"] = FS_preloadFile;
3159
+ Module["FS_unlink"] = FS_unlink;
3160
+ Module["FS_createPath"] = FS_createPath;
3161
+ Module["FS_createDevice"] = FS_createDevice;
3162
+ Module["FS"] = FS;
3163
+ Module["FS_createDataFile"] = FS_createDataFile;
3164
+ Module["FS_createLazyFile"] = FS_createLazyFile;
3165
+ var _emscripten_builtin_memalign, __emscripten_timeout, ___trap, __emscripten_stack_restore, __emscripten_stack_alloc, _emscripten_stack_get_current, wasmMemory;
3166
+ function assignWasmExports(wasmExports) {
3167
+ Module["_free"] = wasmExports["R"];
3168
+ Module["_malloc"] = wasmExports["S"];
3169
+ Module["_rime_wasm_init"] = wasmExports["T"];
3170
+ Module["_rime_wasm_process_input"] = wasmExports["U"];
3171
+ Module["_rime_wasm_pick_candidate"] = wasmExports["V"];
3172
+ Module["_rime_wasm_flip_page"] = wasmExports["W"];
3173
+ Module["_rime_wasm_clear_input"] = wasmExports["X"];
3174
+ Module["_rime_wasm_set_option"] = wasmExports["Y"];
3175
+ Module["_rime_wasm_get_version"] = wasmExports["Z"];
3176
+ Module["_rime_wasm_destroy"] = wasmExports["_"];
3177
+ _emscripten_builtin_memalign = wasmExports["$"];
3178
+ __emscripten_timeout = wasmExports["aa"];
3179
+ ___trap = wasmExports["ba"];
3180
+ __emscripten_stack_restore = wasmExports["ca"];
3181
+ __emscripten_stack_alloc = wasmExports["da"];
3182
+ _emscripten_stack_get_current = wasmExports["ea"];
3183
+ wasmMemory = wasmExports["P"];
3184
+ wasmExports["__indirect_function_table"];
3342
3185
  }
3343
3186
  var wasmImports = {
3344
3187
  r: ___syscall_chmod,
@@ -3383,16 +3226,16 @@ async function createRimeModule(moduleArg = {}) {
3383
3226
  m: _proc_exit,
3384
3227
  p: _random_get
3385
3228
  };
3386
- function applySignatureConversions(wasmExports$1) {
3387
- wasmExports$1 = Object.assign({}, wasmExports$1);
3388
- const makeWrapper_pp = (f) => (a0) => f(a0) >>> 0;
3389
- const makeWrapper_ppp = (f) => (a0, a1) => f(a0, a1) >>> 0;
3390
- const makeWrapper_p = (f) => () => f() >>> 0;
3391
- wasmExports$1.S = makeWrapper_pp(wasmExports$1.S);
3392
- wasmExports$1.$ = makeWrapper_ppp(wasmExports$1.$);
3393
- wasmExports$1.da = makeWrapper_pp(wasmExports$1.da);
3394
- wasmExports$1.ea = makeWrapper_p(wasmExports$1.ea);
3395
- return wasmExports$1;
3229
+ function applySignatureConversions(wasmExports) {
3230
+ wasmExports = Object.assign({}, wasmExports);
3231
+ var makeWrapper_pp = (f) => (a0) => f(a0) >>> 0;
3232
+ var makeWrapper_ppp = (f) => (a0, a1) => f(a0, a1) >>> 0;
3233
+ var makeWrapper_p = (f) => () => f() >>> 0;
3234
+ wasmExports["S"] = makeWrapper_pp(wasmExports["S"]);
3235
+ wasmExports["$"] = makeWrapper_ppp(wasmExports["$"]);
3236
+ wasmExports["da"] = makeWrapper_pp(wasmExports["da"]);
3237
+ wasmExports["ea"] = makeWrapper_p(wasmExports["ea"]);
3238
+ return wasmExports;
3396
3239
  }
3397
3240
  function run() {
3398
3241
  if (runDependencies > 0) {
@@ -3405,23 +3248,22 @@ async function createRimeModule(moduleArg = {}) {
3405
3248
  return;
3406
3249
  }
3407
3250
  function doRun() {
3408
- Module.calledRun = true;
3251
+ Module["calledRun"] = true;
3409
3252
  if (ABORT) return;
3410
3253
  initRuntime();
3411
3254
  readyPromiseResolve?.(Module);
3412
- Module.onRuntimeInitialized?.();
3255
+ Module["onRuntimeInitialized"]?.();
3413
3256
  postRun();
3414
3257
  }
3415
- if (Module.setStatus) {
3416
- Module.setStatus("Running...");
3258
+ if (Module["setStatus"]) {
3259
+ Module["setStatus"]("Running...");
3417
3260
  setTimeout(() => {
3418
- setTimeout(() => Module.setStatus(""), 1);
3261
+ setTimeout(() => Module["setStatus"](""), 1);
3419
3262
  doRun();
3420
3263
  }, 1);
3421
3264
  } else doRun();
3422
3265
  }
3423
- let wasmExports;
3424
- wasmExports = await createWasm();
3266
+ var wasmExports = await createWasm();
3425
3267
  run();
3426
3268
  if (runtimeInitialized) moduleRtn = Module;
3427
3269
  else moduleRtn = new Promise((resolve, reject) => {
@@ -3430,13 +3272,11 @@ async function createRimeModule(moduleArg = {}) {
3430
3272
  });
3431
3273
  return moduleRtn;
3432
3274
  }
3433
- var rime_api_default = createRimeModule;
3434
-
3435
3275
  //#endregion
3436
3276
  //#region src/rime.ts
3437
- function syncfs(module$1, populate) {
3277
+ function syncfs(module, populate) {
3438
3278
  return new Promise((resolve, reject) => {
3439
- module$1.FS.syncfs(populate, (err) => {
3279
+ module.FS.syncfs(populate, (err) => {
3440
3280
  if (err) reject(err);
3441
3281
  else resolve();
3442
3282
  });
@@ -3444,7 +3284,7 @@ function syncfs(module$1, populate) {
3444
3284
  }
3445
3285
  async function createRimeEngine(options = {}) {
3446
3286
  const wasmDir = options.wasmDir ?? ".";
3447
- const Module = await rime_api_default({ locateFile(file) {
3287
+ const Module = await createRimeModule({ locateFile(file) {
3448
3288
  return `${wasmDir}/${file}`;
3449
3289
  } });
3450
3290
  try {
@@ -3481,7 +3321,7 @@ async function createRimeEngine(options = {}) {
3481
3321
  const json = Module.ccall(fn, "string", argTypes, args);
3482
3322
  return JSON.parse(json);
3483
3323
  }
3484
- const engine = {
3324
+ return {
3485
3325
  processInput(keys) {
3486
3326
  return callJson("rime_wasm_process_input", ["string"], [keys]);
3487
3327
  },
@@ -3512,9 +3352,7 @@ async function createRimeEngine(options = {}) {
3512
3352
  syncfs(Module, false).catch(() => {});
3513
3353
  }
3514
3354
  };
3515
- return engine;
3516
3355
  }
3517
-
3518
3356
  //#endregion
3519
3357
  //#region src/index.ts
3520
3358
  /**
@@ -3560,23 +3398,19 @@ var RimePinyinEngine = class {
3560
3398
  return state;
3561
3399
  }
3562
3400
  async pickCandidate(index) {
3563
- const engine = await this.getEngine();
3564
- return engine.pickCandidate(index);
3401
+ return (await this.getEngine()).pickCandidate(index);
3565
3402
  }
3566
3403
  async clearInput() {
3567
- const engine = await this.getEngine();
3568
- return engine.clearInput();
3404
+ return (await this.getEngine()).clearInput();
3569
3405
  }
3570
3406
  async setSimplified(simplified) {
3571
- const engine = await this.getEngine();
3572
- return engine.setOption("zh_simp", simplified);
3407
+ return (await this.getEngine()).setOption("zh_simp", simplified);
3573
3408
  }
3574
3409
  async destroy() {
3575
- const engine = await this.getEngine();
3576
- return engine.destroy();
3410
+ return (await this.getEngine()).destroy();
3577
3411
  }
3578
3412
  };
3579
-
3580
3413
  //#endregion
3581
- exports.RimePinyinEngine = RimePinyinEngine
3414
+ exports.RimePinyinEngine = RimePinyinEngine;
3415
+
3582
3416
  //# sourceMappingURL=index.js.map