@tensor-cad/engine 0.1.0 → 0.1.1
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/index.js +24 -5
- package/node.js +24 -5
- package/package.json +1 -1
- package/tensorcad.wasm +0 -0
package/index.js
CHANGED
|
@@ -176,15 +176,34 @@ function unwrap(text) {
|
|
|
176
176
|
function point(options) {
|
|
177
177
|
return options ? JSON.stringify(options) : "";
|
|
178
178
|
}
|
|
179
|
+
var WASM_MAGIC = [0, 97, 115, 109];
|
|
180
|
+
function looksLikeWasm(bytes) {
|
|
181
|
+
if (bytes.byteLength < 4)
|
|
182
|
+
return false;
|
|
183
|
+
const head = new Uint8Array(bytes, 0, 4);
|
|
184
|
+
return WASM_MAGIC.every((b, i) => head[i] === b);
|
|
185
|
+
}
|
|
179
186
|
async function bytesOf(wasm) {
|
|
180
187
|
if (wasm && typeof wasm !== "string" && !(wasm instanceof URL))
|
|
181
188
|
return wasm;
|
|
182
|
-
const
|
|
183
|
-
const
|
|
184
|
-
|
|
185
|
-
|
|
189
|
+
const urls = wasm ? [wasm] : [new URL("./tensorcad.wasm", import.meta.url)];
|
|
190
|
+
const tried = [];
|
|
191
|
+
for (const url of urls) {
|
|
192
|
+
try {
|
|
193
|
+
const response = await fetch(url);
|
|
194
|
+
if (!response.ok) {
|
|
195
|
+
tried.push(`${String(url)} (${response.status})`);
|
|
196
|
+
continue;
|
|
197
|
+
}
|
|
198
|
+
const bytes = await response.arrayBuffer();
|
|
199
|
+
if (looksLikeWasm(bytes))
|
|
200
|
+
return bytes;
|
|
201
|
+
tried.push(`${String(url)} (not WebAssembly — ${bytes.byteLength} bytes)`);
|
|
202
|
+
} catch (error) {
|
|
203
|
+
tried.push(`${String(url)} (${error.message})`);
|
|
204
|
+
}
|
|
186
205
|
}
|
|
187
|
-
|
|
206
|
+
throw new EngineError(`Could not load the engine. Tried ${tried.join(", ")}. ` + `Pass \`wasm\` to createEngine() if it lives somewhere else.`);
|
|
188
207
|
}
|
|
189
208
|
async function createEngine(options = {}) {
|
|
190
209
|
if (typeof globalThis.Go !== "function") {
|
package/node.js
CHANGED
|
@@ -757,15 +757,34 @@ function unwrap(text) {
|
|
|
757
757
|
function point(options) {
|
|
758
758
|
return options ? JSON.stringify(options) : "";
|
|
759
759
|
}
|
|
760
|
+
var WASM_MAGIC = [0, 97, 115, 109];
|
|
761
|
+
function looksLikeWasm(bytes) {
|
|
762
|
+
if (bytes.byteLength < 4)
|
|
763
|
+
return false;
|
|
764
|
+
const head = new Uint8Array(bytes, 0, 4);
|
|
765
|
+
return WASM_MAGIC.every((b, i) => head[i] === b);
|
|
766
|
+
}
|
|
760
767
|
async function bytesOf(wasm) {
|
|
761
768
|
if (wasm && typeof wasm !== "string" && !(wasm instanceof URL))
|
|
762
769
|
return wasm;
|
|
763
|
-
const
|
|
764
|
-
const
|
|
765
|
-
|
|
766
|
-
|
|
770
|
+
const urls = wasm ? [wasm] : [new URL("../wasm/tensorcad.wasm", import.meta.url)];
|
|
771
|
+
const tried = [];
|
|
772
|
+
for (const url of urls) {
|
|
773
|
+
try {
|
|
774
|
+
const response = await fetch(url);
|
|
775
|
+
if (!response.ok) {
|
|
776
|
+
tried.push(`${String(url)} (${response.status})`);
|
|
777
|
+
continue;
|
|
778
|
+
}
|
|
779
|
+
const bytes = await response.arrayBuffer();
|
|
780
|
+
if (looksLikeWasm(bytes))
|
|
781
|
+
return bytes;
|
|
782
|
+
tried.push(`${String(url)} (not WebAssembly — ${bytes.byteLength} bytes)`);
|
|
783
|
+
} catch (error) {
|
|
784
|
+
tried.push(`${String(url)} (${error.message})`);
|
|
785
|
+
}
|
|
767
786
|
}
|
|
768
|
-
|
|
787
|
+
throw new EngineError(`Could not load the engine. Tried ${tried.join(", ")}. ` + `Pass \`wasm\` to createEngine() if it lives somewhere else.`);
|
|
769
788
|
}
|
|
770
789
|
async function createEngine(options = {}) {
|
|
771
790
|
if (typeof globalThis.Go !== "function") {
|
package/package.json
CHANGED
package/tensorcad.wasm
CHANGED
|
Binary file
|