@danielsimonjr/mathts-matrix 0.6.2 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +18 -1
- package/dist/index.js +35 -10
- package/dist/integrity-LIWCCDIJ.js +13 -0
- package/dist/resolve-DDCEWHWX.js +8 -0
- package/package.json +3 -3
- package/dist/integrity-X3CLNVGW.js +0 -78
- package/dist/resolve-VJX3YTS6.js +0 -43
package/dist/index.d.ts
CHANGED
|
@@ -2278,6 +2278,23 @@ interface LUResult {
|
|
|
2278
2278
|
* @throws {Error} if `A` is singular (zero pivot encountered).
|
|
2279
2279
|
*/
|
|
2280
2280
|
declare function lu(A: DenseMatrix): LUResult;
|
|
2281
|
+
/**
|
|
2282
|
+
* Solve the dense linear system `A · x = b` using a precomputed LU factorisation
|
|
2283
|
+
* (from {@link lu}), where `P · A = L · U`.
|
|
2284
|
+
*
|
|
2285
|
+
* Applies the row permutation to `b` (`(P·b)[i] = b[P[i]]`), forward-substitutes
|
|
2286
|
+
* the unit-lower-triangular `L`, then back-substitutes the upper-triangular `U`.
|
|
2287
|
+
* Each call is O(n²), so factor **once** with `lu()` and call `luSolve` repeatedly
|
|
2288
|
+
* to solve many right-hand sides against the same matrix — the pattern the stiff
|
|
2289
|
+
* Rosenbrock/RODAS ODE steps use (the iteration matrix is solved against 3–6
|
|
2290
|
+
* successive RHS per step).
|
|
2291
|
+
*
|
|
2292
|
+
* @param fac An `LUResult` produced by {@link lu}.
|
|
2293
|
+
* @param b Right-hand side vector of length `n` (`number[]` or `Float64Array`).
|
|
2294
|
+
* @returns The solution vector `x` as a `number[]` of length `n`.
|
|
2295
|
+
* @throws {Error} if `b.length` does not equal the factor dimension `n`.
|
|
2296
|
+
*/
|
|
2297
|
+
declare function luSolve(fac: LUResult, b: ArrayLike<number>): number[];
|
|
2281
2298
|
|
|
2282
2299
|
/**
|
|
2283
2300
|
* Cholesky Decomposition (DenseMatrix primitive)
|
|
@@ -3024,4 +3041,4 @@ declare function initializeParallelMatrix(): Promise<void>;
|
|
|
3024
3041
|
*/
|
|
3025
3042
|
declare function terminateParallelMatrix(): Promise<void>;
|
|
3026
3043
|
|
|
3027
|
-
export { BUILTIN_SHADERS, type BackendHints, BackendManager, BackendRegistry, type BackendType, BatchExecutor, type CholeskyResult, DEFAULT_BACKEND_HINTS, DEFAULT_EXTENDED_HINTS, DenseMatrix, type EigOptions, type EigResult, type ExpmOptions, type ExtendedBackendHints, GPUBackend, type GPUBackendOptions, type GPUBackendStatus, GPUMatrixBackend, type GPUMatrixBackendConfig, JSBackend, type LQResult, type LUResult, type LogmOptions, Matrix, type MatrixBackend, type MatrixEntry, type MatrixIndex, type MatrixType, type OperationType, ParallelBackend, type ParallelBackendConfig, type PinvOptions, type QLResult, type QROptions, type QRPivotedOptions, type QRPivotedResult, type QRResult, type RQResult, type SVDOptions, type SVDResult, type SchurOptions, type SchurResult, type SliceSpec, SparseMatrix, type SqrtmOptions, type SyncConfig, SyncManager, type SyncStrategy, WASMBackend, type WASMBackendConfig, type WasmFeatures, abs, add, backendManager, backendRegistry, cholesky, clearFeatureCache, column, cond, condest, createBackendManager, createGPUMatrixBackend, createParallelBackend, createSyncManager, createWASMBackend, destroyGlobalGPUBackend, detectWasmFeatures, diag, diagonal, divide, dotMultiply, eig, eigWasm, eigvals, eigvalsWasm, exp, getCachedFeatures, getGlobalGPUBackend, gpuMatrixBackend, identity, initializeGlobalGPUBackend, initializeParallelMatrix, isAtomicsAvailable, isDenseMatrix, isMatrix, isSharedMemoryAvailable, isSparseMatrix, isWasmAvailable, jsBackend, log, lowRankApprox, lq, lu, matrix, matrixExpm, matrixLogm, pinv as matrixPinv, matrixSchur, matrixSqrtm, max, mean, min, multiply, norm, norm2, normFro, ones, parallelBackend, parallelDiag, parallelDotMultiply, parallelIdentity, parallelMatrix, parallelMatrixAbs, parallelMatrixAdd, parallelMatrixColumn, parallelMatrixCos, parallelMatrixDiagonal, parallelMatrixDistance, parallelMatrixDivide, parallelMatrixDot, parallelMatrixExp, parallelMatrixHistogram, parallelMatrixLog, parallelMatrixMatvec, parallelMatrixMax, parallelMatrixMean, parallelMatrixMin, parallelMatrixMultiply, parallelMatrixNorm, parallelMatrixOperations, parallelMatrixOuter, parallelMatrixRow, parallelMatrixSin, parallelMatrixSize, parallelMatrixSqrt, parallelMatrixSquare, parallelMatrixStd, parallelMatrixSubset, parallelMatrixSubtract, parallelMatrixSum, parallelMatrixTan, parallelMatrixTrace, parallelMatrixTranspose, parallelMatrixVariance, parallelOnes, parallelRandom, parallelUnaryMinus, parallelZeros, pinv$1 as pinv, pow, powerIteration, ql, qr, qrPivoted, random, row, rq, singularValues, size, spectralRadiusWasm, sqrt, square, subset, subtract, sum, svd, svdWasm, terminateParallelMatrix, trace, transpose, typedMatrixOperations, unaryMinus, wasmBackend, zeros };
|
|
3044
|
+
export { BUILTIN_SHADERS, type BackendHints, BackendManager, BackendRegistry, type BackendType, BatchExecutor, type CholeskyResult, DEFAULT_BACKEND_HINTS, DEFAULT_EXTENDED_HINTS, DenseMatrix, type EigOptions, type EigResult, type ExpmOptions, type ExtendedBackendHints, GPUBackend, type GPUBackendOptions, type GPUBackendStatus, GPUMatrixBackend, type GPUMatrixBackendConfig, JSBackend, type LQResult, type LUResult, type LogmOptions, Matrix, type MatrixBackend, type MatrixEntry, type MatrixIndex, type MatrixType, type OperationType, ParallelBackend, type ParallelBackendConfig, type PinvOptions, type QLResult, type QROptions, type QRPivotedOptions, type QRPivotedResult, type QRResult, type RQResult, type SVDOptions, type SVDResult, type SchurOptions, type SchurResult, type SliceSpec, SparseMatrix, type SqrtmOptions, type SyncConfig, SyncManager, type SyncStrategy, WASMBackend, type WASMBackendConfig, type WasmFeatures, abs, add, backendManager, backendRegistry, cholesky, clearFeatureCache, column, cond, condest, createBackendManager, createGPUMatrixBackend, createParallelBackend, createSyncManager, createWASMBackend, destroyGlobalGPUBackend, detectWasmFeatures, diag, diagonal, divide, dotMultiply, eig, eigWasm, eigvals, eigvalsWasm, exp, getCachedFeatures, getGlobalGPUBackend, gpuMatrixBackend, identity, initializeGlobalGPUBackend, initializeParallelMatrix, isAtomicsAvailable, isDenseMatrix, isMatrix, isSharedMemoryAvailable, isSparseMatrix, isWasmAvailable, jsBackend, log, lowRankApprox, lq, lu, luSolve, matrix, matrixExpm, matrixLogm, pinv as matrixPinv, matrixSchur, matrixSqrtm, max, mean, min, multiply, norm, norm2, normFro, ones, parallelBackend, parallelDiag, parallelDotMultiply, parallelIdentity, parallelMatrix, parallelMatrixAbs, parallelMatrixAdd, parallelMatrixColumn, parallelMatrixCos, parallelMatrixDiagonal, parallelMatrixDistance, parallelMatrixDivide, parallelMatrixDot, parallelMatrixExp, parallelMatrixHistogram, parallelMatrixLog, parallelMatrixMatvec, parallelMatrixMax, parallelMatrixMean, parallelMatrixMin, parallelMatrixMultiply, parallelMatrixNorm, parallelMatrixOperations, parallelMatrixOuter, parallelMatrixRow, parallelMatrixSin, parallelMatrixSize, parallelMatrixSqrt, parallelMatrixSquare, parallelMatrixStd, parallelMatrixSubset, parallelMatrixSubtract, parallelMatrixSum, parallelMatrixTan, parallelMatrixTrace, parallelMatrixTranspose, parallelMatrixVariance, parallelOnes, parallelRandom, parallelUnaryMinus, parallelZeros, pinv$1 as pinv, pow, powerIteration, ql, qr, qrPivoted, random, row, rq, singularValues, size, spectralRadiusWasm, sqrt, square, subset, subtract, sum, svd, svdWasm, terminateParallelMatrix, trace, transpose, typedMatrixOperations, unaryMinus, wasmBackend, zeros };
|
package/dist/index.js
CHANGED
|
@@ -2499,7 +2499,7 @@ var WASMBackend = class {
|
|
|
2499
2499
|
*/
|
|
2500
2500
|
async resolveAsWasmPath() {
|
|
2501
2501
|
const isNode = typeof process !== "undefined" && process.versions?.node !== void 0;
|
|
2502
|
-
const { resolvePackagedWasm, defaultWasmLocation } = await import("./resolve-
|
|
2502
|
+
const { resolvePackagedWasm, defaultWasmLocation } = await import("./resolve-DDCEWHWX.js");
|
|
2503
2503
|
if (isNode) {
|
|
2504
2504
|
const found = await resolvePackagedWasm(import.meta.url, "mathts-as.wasm");
|
|
2505
2505
|
if (found) return found;
|
|
@@ -2525,7 +2525,7 @@ var WASMBackend = class {
|
|
|
2525
2525
|
Date
|
|
2526
2526
|
};
|
|
2527
2527
|
const isNode = typeof process !== "undefined" && process.versions?.node !== void 0;
|
|
2528
|
-
const { loadWasmManifest, verifyWasmIntegrity } = await import("./integrity-
|
|
2528
|
+
const { loadWasmManifest, verifyWasmIntegrity } = await import("./integrity-LIWCCDIJ.js");
|
|
2529
2529
|
let instance;
|
|
2530
2530
|
if (isNode) {
|
|
2531
2531
|
const fs = await import("fs");
|
|
@@ -4289,7 +4289,7 @@ var WasmLoader = class _WasmLoader {
|
|
|
4289
4289
|
if (this.compiledModule) return;
|
|
4290
4290
|
const path = wasmPath || await this.getDefaultWasmPath();
|
|
4291
4291
|
const startTime = performance.now();
|
|
4292
|
-
const { loadWasmManifest, verifyWasmIntegrity } = await import("./integrity-
|
|
4292
|
+
const { loadWasmManifest, verifyWasmIntegrity } = await import("./integrity-LIWCCDIJ.js");
|
|
4293
4293
|
if (this.isNode) {
|
|
4294
4294
|
const fs = await import("fs");
|
|
4295
4295
|
const { promisify } = await import("util");
|
|
@@ -4350,20 +4350,20 @@ var WasmLoader = class _WasmLoader {
|
|
|
4350
4350
|
async getDefaultWasmPath() {
|
|
4351
4351
|
const wasmFile = "mathts-as.wasm";
|
|
4352
4352
|
if (this.isNode) {
|
|
4353
|
-
const { resolvePackagedWasm } = await import("./resolve-
|
|
4353
|
+
const { resolvePackagedWasm } = await import("./resolve-DDCEWHWX.js");
|
|
4354
4354
|
const found = await resolvePackagedWasm(import.meta.url, wasmFile);
|
|
4355
4355
|
if (found) return found;
|
|
4356
|
-
const { defaultWasmLocation: defaultWasmLocation2 } = await import("./resolve-
|
|
4356
|
+
const { defaultWasmLocation: defaultWasmLocation2 } = await import("./resolve-DDCEWHWX.js");
|
|
4357
4357
|
return defaultWasmLocation2(import.meta.url, wasmFile);
|
|
4358
4358
|
}
|
|
4359
|
-
const { defaultWasmLocation } = await import("./resolve-
|
|
4359
|
+
const { defaultWasmLocation } = await import("./resolve-DDCEWHWX.js");
|
|
4360
4360
|
return defaultWasmLocation(import.meta.url, wasmFile, { browser: true });
|
|
4361
4361
|
}
|
|
4362
4362
|
async loadNodeWasm(path, totalStart) {
|
|
4363
4363
|
const fs = await import("fs");
|
|
4364
4364
|
const { promisify } = await import("util");
|
|
4365
4365
|
const readFile = promisify(fs.readFile);
|
|
4366
|
-
const { verifyWasmIntegrity } = await import("./integrity-
|
|
4366
|
+
const { verifyWasmIntegrity } = await import("./integrity-LIWCCDIJ.js");
|
|
4367
4367
|
const readStart = performance.now();
|
|
4368
4368
|
const buffer = await readFile(path);
|
|
4369
4369
|
const readEnd = performance.now();
|
|
@@ -4384,7 +4384,7 @@ var WasmLoader = class _WasmLoader {
|
|
|
4384
4384
|
return instance.exports;
|
|
4385
4385
|
}
|
|
4386
4386
|
async loadBrowserWasm(path, totalStart) {
|
|
4387
|
-
const { loadWasmManifest, verifyWasmIntegrity } = await import("./integrity-
|
|
4387
|
+
const { loadWasmManifest, verifyWasmIntegrity } = await import("./integrity-LIWCCDIJ.js");
|
|
4388
4388
|
const manifest = await loadWasmManifest(path);
|
|
4389
4389
|
if (!manifest && typeof WebAssembly.instantiateStreaming === "function") {
|
|
4390
4390
|
const instStart2 = performance.now();
|
|
@@ -6492,6 +6492,30 @@ function lu(A) {
|
|
|
6492
6492
|
P: perm
|
|
6493
6493
|
};
|
|
6494
6494
|
}
|
|
6495
|
+
function luSolve(fac, b) {
|
|
6496
|
+
const n = fac.P.length;
|
|
6497
|
+
if (b.length !== n) {
|
|
6498
|
+
throw new Error(
|
|
6499
|
+
`luSolve: right-hand side length ${b.length} does not match factor dimension ${n}`
|
|
6500
|
+
);
|
|
6501
|
+
}
|
|
6502
|
+
const L = fac.L.toFloat64Array();
|
|
6503
|
+
const U = fac.U.toFloat64Array();
|
|
6504
|
+
const P = fac.P;
|
|
6505
|
+
const y = new Array(n);
|
|
6506
|
+
for (let i = 0; i < n; i++) {
|
|
6507
|
+
let s = b[P[i]];
|
|
6508
|
+
for (let k = 0; k < i; k++) s -= L[i * n + k] * y[k];
|
|
6509
|
+
y[i] = s;
|
|
6510
|
+
}
|
|
6511
|
+
const x = new Array(n);
|
|
6512
|
+
for (let i = n - 1; i >= 0; i--) {
|
|
6513
|
+
let s = y[i];
|
|
6514
|
+
for (let k = i + 1; k < n; k++) s -= U[i * n + k] * x[k];
|
|
6515
|
+
x[i] = s / U[i * n + i];
|
|
6516
|
+
}
|
|
6517
|
+
return x;
|
|
6518
|
+
}
|
|
6495
6519
|
|
|
6496
6520
|
// src/operations/cholesky.ts
|
|
6497
6521
|
init_DenseMatrix();
|
|
@@ -7556,7 +7580,7 @@ function ql(A) {
|
|
|
7556
7580
|
}
|
|
7557
7581
|
|
|
7558
7582
|
// src/operations/condest.ts
|
|
7559
|
-
function
|
|
7583
|
+
function luSolve2(L, U, perm, n, b) {
|
|
7560
7584
|
const pb = new Array(n);
|
|
7561
7585
|
for (let i = 0; i < n; i++) pb[i] = b[perm[i]];
|
|
7562
7586
|
const y = new Array(n);
|
|
@@ -7646,7 +7670,7 @@ function condest(A, p = 1) {
|
|
|
7646
7670
|
return Infinity;
|
|
7647
7671
|
}
|
|
7648
7672
|
const norm1Inv = hagerNormEstimate(
|
|
7649
|
-
(v) =>
|
|
7673
|
+
(v) => luSolve2(L, U, perm, n, v),
|
|
7650
7674
|
(v) => luSolveTranspose(L, U, perm, n, v),
|
|
7651
7675
|
n
|
|
7652
7676
|
);
|
|
@@ -8544,6 +8568,7 @@ export {
|
|
|
8544
8568
|
lowRankApprox,
|
|
8545
8569
|
lq,
|
|
8546
8570
|
lu,
|
|
8571
|
+
luSolve,
|
|
8547
8572
|
matrix,
|
|
8548
8573
|
matrixExpm,
|
|
8549
8574
|
matrixLogm,
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import "./chunk-4VMDO6W2.js";
|
|
2
|
+
|
|
3
|
+
// src/backends/wasm/integrity.ts
|
|
4
|
+
import {
|
|
5
|
+
sha384OfBuffer,
|
|
6
|
+
loadWasmManifest,
|
|
7
|
+
verifyWasmIntegrity
|
|
8
|
+
} from "@danielsimonjr/mathts-core/internal";
|
|
9
|
+
export {
|
|
10
|
+
loadWasmManifest,
|
|
11
|
+
sha384OfBuffer,
|
|
12
|
+
verifyWasmIntegrity
|
|
13
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@danielsimonjr/mathts-matrix",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "Matrix operations for MathTS with WASM/WebGPU backend support",
|
|
5
5
|
"author": "Daniel Simon Jr.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -32,9 +32,9 @@
|
|
|
32
32
|
"build:prod": "tsup src/index.ts --format esm --dts --clean --minify --treeshake && node scripts/copy-wasm.mjs"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@danielsimonjr/mathts-core": "^0.
|
|
35
|
+
"@danielsimonjr/mathts-core": "^0.13.0",
|
|
36
36
|
"@danielsimonjr/mathts-gpu": "^0.2.0",
|
|
37
|
-
"@danielsimonjr/mathts-parallel": "^0.6.
|
|
37
|
+
"@danielsimonjr/mathts-parallel": "^0.6.3"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"@types/node": "^25.5.2",
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import "./chunk-4VMDO6W2.js";
|
|
2
|
-
|
|
3
|
-
// src/backends/wasm/integrity.ts
|
|
4
|
-
var ALGO = "sha384";
|
|
5
|
-
async function sha384OfBuffer(buffer) {
|
|
6
|
-
const bytes = buffer instanceof Uint8Array ? buffer : new Uint8Array(buffer);
|
|
7
|
-
const isNode = typeof process !== "undefined" && process.versions?.node !== void 0;
|
|
8
|
-
let digest;
|
|
9
|
-
if (isNode) {
|
|
10
|
-
const { createHash } = await import("crypto");
|
|
11
|
-
const hash = createHash(ALGO);
|
|
12
|
-
hash.update(bytes);
|
|
13
|
-
digest = new Uint8Array(hash.digest());
|
|
14
|
-
} else {
|
|
15
|
-
const copy = new ArrayBuffer(bytes.byteLength);
|
|
16
|
-
new Uint8Array(copy).set(bytes);
|
|
17
|
-
const out = await crypto.subtle.digest("SHA-384", copy);
|
|
18
|
-
digest = new Uint8Array(out);
|
|
19
|
-
}
|
|
20
|
-
let binary = "";
|
|
21
|
-
for (let i = 0; i < digest.length; i++) binary += String.fromCharCode(digest[i]);
|
|
22
|
-
const b64 = typeof btoa === "function" ? btoa(binary) : Buffer.from(digest).toString("base64");
|
|
23
|
-
return `sha384-${b64}`;
|
|
24
|
-
}
|
|
25
|
-
async function loadWasmManifest(wasmPath) {
|
|
26
|
-
const isNode = typeof process !== "undefined" && process.versions?.node !== void 0;
|
|
27
|
-
const manifestPath = wasmPath.replace(/[^/\\]+$/, "wasm-manifest.json");
|
|
28
|
-
try {
|
|
29
|
-
if (isNode) {
|
|
30
|
-
const fs = await import("fs");
|
|
31
|
-
const { promisify } = await import("util");
|
|
32
|
-
const readFile = promisify(fs.readFile);
|
|
33
|
-
const text = await readFile(manifestPath, "utf8");
|
|
34
|
-
return JSON.parse(text);
|
|
35
|
-
} else {
|
|
36
|
-
const res = await fetch(manifestPath);
|
|
37
|
-
if (!res.ok) return null;
|
|
38
|
-
return await res.json();
|
|
39
|
-
}
|
|
40
|
-
} catch {
|
|
41
|
-
return null;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
async function verifyWasmIntegrity(buffer, wasmPath, options = {}) {
|
|
45
|
-
const fileName = wasmPath.split(/[/\\]/).pop() || wasmPath;
|
|
46
|
-
const manifest = options.manifest !== void 0 ? options.manifest : await loadWasmManifest(wasmPath);
|
|
47
|
-
if (!manifest) {
|
|
48
|
-
if (options.required) {
|
|
49
|
-
throw new Error(
|
|
50
|
-
`WASM integrity check failed: no manifest at sibling of "${wasmPath}" (required)`
|
|
51
|
-
);
|
|
52
|
-
}
|
|
53
|
-
if (typeof console !== "undefined") {
|
|
54
|
-
console.warn(
|
|
55
|
-
`[wasm-integrity] no manifest found beside "${wasmPath}"; skipping SHA-384 verification (set options.required=true to fail closed)`
|
|
56
|
-
);
|
|
57
|
-
}
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
const expected = manifest[fileName];
|
|
61
|
-
if (!expected) {
|
|
62
|
-
if (options.required) {
|
|
63
|
-
throw new Error(`WASM integrity check failed: manifest has no entry for "${fileName}"`);
|
|
64
|
-
}
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
|
-
const actual = await sha384OfBuffer(buffer);
|
|
68
|
-
if (actual !== expected) {
|
|
69
|
-
throw new Error(
|
|
70
|
-
`WASM integrity check failed for "${fileName}": expected ${expected}, got ${actual}`
|
|
71
|
-
);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
export {
|
|
75
|
-
loadWasmManifest,
|
|
76
|
-
sha384OfBuffer,
|
|
77
|
-
verifyWasmIntegrity
|
|
78
|
-
};
|
package/dist/resolve-VJX3YTS6.js
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import "./chunk-4VMDO6W2.js";
|
|
2
|
-
|
|
3
|
-
// src/backends/wasm/resolve.ts
|
|
4
|
-
async function resolvePackagedWasm(metaUrl, wasmFile) {
|
|
5
|
-
const isNode = typeof process !== "undefined" && process.versions?.node !== void 0;
|
|
6
|
-
if (!isNode) return null;
|
|
7
|
-
const { fileURLToPath } = await import("url");
|
|
8
|
-
const { dirname, join } = await import("path");
|
|
9
|
-
const { existsSync } = await import("fs");
|
|
10
|
-
let dir = dirname(fileURLToPath(metaUrl));
|
|
11
|
-
for (let depth = 0; depth < 8; depth++) {
|
|
12
|
-
const candidates = [join(dir, "wasm", wasmFile), join(dir, "dist", "wasm", wasmFile)];
|
|
13
|
-
for (const candidate of candidates) {
|
|
14
|
-
if (existsSync(candidate)) return candidate;
|
|
15
|
-
}
|
|
16
|
-
const parent = dirname(dir);
|
|
17
|
-
if (parent === dir) break;
|
|
18
|
-
dir = parent;
|
|
19
|
-
}
|
|
20
|
-
return null;
|
|
21
|
-
}
|
|
22
|
-
async function defaultWasmLocation(metaUrl, wasmFile, opts) {
|
|
23
|
-
if (opts?.browser) {
|
|
24
|
-
return new URL(`./wasm/${wasmFile}`, metaUrl).href;
|
|
25
|
-
}
|
|
26
|
-
const { fileURLToPath } = await import("url");
|
|
27
|
-
const { dirname, join } = await import("path");
|
|
28
|
-
const { existsSync } = await import("fs");
|
|
29
|
-
let dir = dirname(fileURLToPath(metaUrl));
|
|
30
|
-
for (let depth = 0; depth < 8; depth++) {
|
|
31
|
-
if (existsSync(join(dir, "package.json"))) {
|
|
32
|
-
return join(dir, "dist", "wasm", wasmFile);
|
|
33
|
-
}
|
|
34
|
-
const parent = dirname(dir);
|
|
35
|
-
if (parent === dir) break;
|
|
36
|
-
dir = parent;
|
|
37
|
-
}
|
|
38
|
-
return join(dirname(fileURLToPath(metaUrl)), "wasm", wasmFile);
|
|
39
|
-
}
|
|
40
|
-
export {
|
|
41
|
-
defaultWasmLocation,
|
|
42
|
-
resolvePackagedWasm
|
|
43
|
-
};
|