feat: trying to remove wasm-bindgen
This commit is contained in:
@@ -22,7 +22,8 @@
|
||||
"idb": "^8.0.3",
|
||||
"jsondiffpatch": "^0.7.3",
|
||||
"tailwindcss": "^4.1.18",
|
||||
"three": "^0.182.0"
|
||||
"three": "^0.182.0",
|
||||
"wabt": "^1.0.39"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@iconify-json/tabler": "^1.2.26",
|
||||
|
||||
@@ -3,7 +3,7 @@ import fs from "fs/promises";
|
||||
import path from "path";
|
||||
|
||||
export async function getWasm(id: `${string}/${string}/${string}`) {
|
||||
const filePath = path.resolve(`../nodes/${id}/pkg/index_bg.wasm`);
|
||||
const filePath = path.resolve(`../nodes/${id}/pkg/node.wasm`);
|
||||
|
||||
try {
|
||||
await fs.access(filePath);
|
||||
|
||||
@@ -244,13 +244,14 @@ export class MemoryRuntimeExecutor implements RuntimeExecutor {
|
||||
}
|
||||
this.perf?.addPoint("cache-hit", 0);
|
||||
|
||||
log.group(`executing ${node_type.id || node.id}`);
|
||||
log.group(`executing ${node_type.id}-${node.id}`);
|
||||
log.log(`Inputs:`, inputs);
|
||||
a = performance.now();
|
||||
results[node.id] = node_type.execute(encoded_inputs);
|
||||
log.log("Executed", node.type, node.id)
|
||||
b = performance.now();
|
||||
|
||||
if (this.cache) {
|
||||
if (this.cache && node.id !== outputNode.id) {
|
||||
this.cache.set(inputHash, results[node.id]);
|
||||
}
|
||||
|
||||
|
||||
8
app/src/routes/dev/+layout.svelte
Normal file
8
app/src/routes/dev/+layout.svelte
Normal file
@@ -0,0 +1,8 @@
|
||||
<script lang="ts">
|
||||
import type { Snippet } from "svelte";
|
||||
const { children } = $props<{ children?: Snippet }>();
|
||||
</script>
|
||||
|
||||
<main class="w-screen overflow-x-hidden">
|
||||
{@render children()}
|
||||
</main>
|
||||
@@ -1,29 +1,120 @@
|
||||
<script lang="ts">
|
||||
import Grid from "$lib/grid";
|
||||
import NodeHTML from "$lib/graph-interface/node/NodeHTML.svelte";
|
||||
import { localState } from "$lib/helpers/localState.svelte";
|
||||
import Panel from "$lib/sidebar/Panel.svelte";
|
||||
import Sidebar from "$lib/sidebar/Sidebar.svelte";
|
||||
import { IndexDBCache, RemoteNodeRegistry } from "@nodarium/registry";
|
||||
import { type NodeId, type NodeInstance } from "@nodarium/types";
|
||||
import Code from "./Code.svelte";
|
||||
import Grid from "$lib/grid";
|
||||
import {
|
||||
concatEncodedArrays,
|
||||
createWasmWrapper,
|
||||
encodeNestedArray,
|
||||
} from "@nodarium/utils";
|
||||
|
||||
const registryCache = new IndexDBCache("node-registry");
|
||||
const nodeRegistry = new RemoteNodeRegistry("", registryCache);
|
||||
|
||||
let activeNode = localState<NodeId | undefined>(
|
||||
"node.dev.activeNode",
|
||||
undefined,
|
||||
);
|
||||
|
||||
let nodeWasm = $state<ArrayBuffer>();
|
||||
let nodeInstance = $state<NodeInstance>();
|
||||
let nodeWasmWrapper = $state<ReturnType<typeof createWasmWrapper>>();
|
||||
|
||||
async function fetchNodeData(nodeId?: NodeId) {
|
||||
console.log("FETCHING", { nodeId });
|
||||
nodeWasm = undefined;
|
||||
nodeInstance = undefined;
|
||||
|
||||
if (!nodeId) return;
|
||||
|
||||
const data = await nodeRegistry.fetchNodeDefinition(nodeId);
|
||||
nodeWasm = await nodeRegistry.fetchArrayBuffer("nodes/" + nodeId + ".wasm");
|
||||
nodeInstance = {
|
||||
id: 0,
|
||||
type: nodeId,
|
||||
position: [0, 0] as [number, number],
|
||||
props: {},
|
||||
state: {
|
||||
type: data,
|
||||
},
|
||||
};
|
||||
nodeWasmWrapper = createWasmWrapper(nodeWasm);
|
||||
}
|
||||
|
||||
$effect(() => {
|
||||
fetchNodeData(activeNode.value);
|
||||
});
|
||||
|
||||
$effect(() => {
|
||||
if (nodeInstance?.props && nodeWasmWrapper) {
|
||||
const keys = Object.keys(nodeInstance.state.type?.inputs || {});
|
||||
let ins = Object.values(nodeInstance.props) as number[];
|
||||
if (keys[0] === "plant") {
|
||||
ins = [[0, 0, 0, 0, 0, 0, 0, 0], ...ins];
|
||||
}
|
||||
const inputs = concatEncodedArrays(encodeNestedArray(ins));
|
||||
nodeWasmWrapper?.execute(inputs);
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<div class="node-wrapper absolute bottom-8 left-8">
|
||||
{#if nodeInstance}
|
||||
<NodeHTML inView position="relative" z={5} bind:node={nodeInstance} />
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<Grid.Row>
|
||||
<Grid.Cell></Grid.Cell>
|
||||
<Grid.Cell>
|
||||
<Sidebar>
|
||||
<Panel
|
||||
id="node-store"
|
||||
classes="text-green-400"
|
||||
title="Node Store"
|
||||
icon="i-[tabler--database]"
|
||||
>
|
||||
<div class="p-4">
|
||||
<input type="text" class="bg-red rounded-sm p-2" />
|
||||
</div>
|
||||
</Panel>
|
||||
</Sidebar>
|
||||
<pre>
|
||||
<code>
|
||||
{JSON.stringify(nodeInstance?.props)}
|
||||
</code>
|
||||
</pre>
|
||||
</Grid.Cell>
|
||||
|
||||
<Grid.Cell>
|
||||
<div class="h-screen w-[80vw] overflow-y-auto">
|
||||
{#if nodeWasm}
|
||||
<Code wasm={nodeWasm} />
|
||||
{/if}
|
||||
</div>
|
||||
</Grid.Cell>
|
||||
</Grid.Row>
|
||||
|
||||
<Sidebar>
|
||||
<Panel
|
||||
id="node-store"
|
||||
classes="text-green-400"
|
||||
title="Node Store"
|
||||
icon="i-[tabler--database]"
|
||||
>
|
||||
<div class="p-4 flex flex-col gap-2">
|
||||
{#await nodeRegistry.fetchCollection("max/plantarium")}
|
||||
<p>Loading Nodes...</p>
|
||||
{:then result}
|
||||
{#each result.nodes as n}
|
||||
<button
|
||||
class="cursor-pointer p-2 bg-layer-1 {activeNode.value === n.id
|
||||
? 'outline outline-offset-1'
|
||||
: ''}"
|
||||
onclick={() => (activeNode.value = n.id)}>{n.id}</button
|
||||
>
|
||||
{/each}
|
||||
{/await}
|
||||
</div>
|
||||
</Panel>
|
||||
</Sidebar>
|
||||
|
||||
<style>
|
||||
:global body {
|
||||
height: 100vh;
|
||||
width: 100vw;
|
||||
overflow: hidden;
|
||||
}
|
||||
</style>
|
||||
|
||||
26
app/src/routes/dev/Code.svelte
Normal file
26
app/src/routes/dev/Code.svelte
Normal file
@@ -0,0 +1,26 @@
|
||||
<script lang="ts">
|
||||
import wabtInit from "wabt";
|
||||
|
||||
const { wasm } = $props<{ wasm: ArrayBuffer }>();
|
||||
|
||||
async function toWat(arrayBuffer: ArrayBuffer) {
|
||||
const wabt = await wabtInit();
|
||||
|
||||
const module = wabt.readWasm(new Uint8Array(arrayBuffer), {
|
||||
readDebugNames: true,
|
||||
});
|
||||
|
||||
module.generateNames();
|
||||
module.applyNames();
|
||||
|
||||
return module.toText({ foldExprs: false, inlineExport: false });
|
||||
}
|
||||
</script>
|
||||
|
||||
{#await toWat(wasm)}
|
||||
<p>Converting to WAT</p>
|
||||
{:then c}
|
||||
<pre>
|
||||
<code class="text-gray-50">{c}</code>
|
||||
</pre>
|
||||
{/await}
|
||||
Reference in New Issue
Block a user