diff --git a/Cargo.lock b/Cargo.lock index 7c10827..4282edf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7,11 +7,13 @@ name = "array" version = "0.1.0" dependencies = [ "console_error_panic_hook", + "macros", "serde", "serde-wasm-bindgen", "utils", "wasm-bindgen", "wasm-bindgen-test", + "web-sys", ] [[package]] @@ -41,6 +43,7 @@ name = "float" version = "0.1.0" dependencies = [ "console_error_panic_hook", + "macros", "serde", "serde-wasm-bindgen", "utils", @@ -69,11 +72,21 @@ version = "0.4.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" +[[package]] +name = "macros" +version = "0.1.0" +dependencies = [ + "quote", + "serde_json", + "syn 1.0.109", +] + [[package]] name = "math" version = "0.1.0" dependencies = [ "console_error_panic_hook", + "macros", "serde", "serde-wasm-bindgen", "utils", @@ -172,7 +185,7 @@ checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.59", ] [[package]] @@ -187,15 +200,42 @@ dependencies = [ ] [[package]] -name = "sum" +name = "stem" version = "0.1.0" dependencies = [ "console_error_panic_hook", + "macros", "serde", "serde-wasm-bindgen", "utils", "wasm-bindgen", "wasm-bindgen-test", + "web-sys", +] + +[[package]] +name = "sum" +version = "0.1.0" +dependencies = [ + "console_error_panic_hook", + "macros", + "serde", + "serde-wasm-bindgen", + "utils", + "wasm-bindgen", + "wasm-bindgen-test", + "web-sys", +] + +[[package]] +name = "syn" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", ] [[package]] @@ -258,7 +298,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn", + "syn 2.0.59", "wasm-bindgen-shared", ] @@ -292,7 +332,7 @@ checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.59", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -325,7 +365,7 @@ checksum = "b7f89739351a2e03cb94beb799d47fb2cac01759b40ec441f7de39b00cbf7ef0" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.59", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index fc776d9..a0c8ee1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [workspace] resolver = "2" -members = ["nodes/max/plantarium/*", "packages/utils"] +members = ["nodes/max/plantarium/*", "packages/macros", "packages/utils"] [profile.release] diff --git a/packages/graph-interface/src/lib/AddMenu.svelte b/app/src/lib/graph-interface/AddMenu.svelte similarity index 100% rename from packages/graph-interface/src/lib/AddMenu.svelte rename to app/src/lib/graph-interface/AddMenu.svelte diff --git a/packages/graph-interface/src/lib/BoxSelection.svelte b/app/src/lib/graph-interface/BoxSelection.svelte similarity index 100% rename from packages/graph-interface/src/lib/BoxSelection.svelte rename to app/src/lib/graph-interface/BoxSelection.svelte diff --git a/packages/graph-interface/src/lib/Camera.svelte b/app/src/lib/graph-interface/Camera.svelte similarity index 100% rename from packages/graph-interface/src/lib/Camera.svelte rename to app/src/lib/graph-interface/Camera.svelte diff --git a/packages/graph-interface/src/lib/background/Background.frag b/app/src/lib/graph-interface/background/Background.frag similarity index 100% rename from packages/graph-interface/src/lib/background/Background.frag rename to app/src/lib/graph-interface/background/Background.frag diff --git a/packages/graph-interface/src/lib/background/Background.story.svelte b/app/src/lib/graph-interface/background/Background.story.svelte similarity index 100% rename from packages/graph-interface/src/lib/background/Background.story.svelte rename to app/src/lib/graph-interface/background/Background.story.svelte diff --git a/packages/graph-interface/src/lib/background/Background.svelte b/app/src/lib/graph-interface/background/Background.svelte similarity index 100% rename from packages/graph-interface/src/lib/background/Background.svelte rename to app/src/lib/graph-interface/background/Background.svelte diff --git a/packages/graph-interface/src/lib/background/Background.vert b/app/src/lib/graph-interface/background/Background.vert similarity index 100% rename from packages/graph-interface/src/lib/background/Background.vert rename to app/src/lib/graph-interface/background/Background.vert diff --git a/packages/graph-interface/src/lib/debug/Debug.svelte b/app/src/lib/graph-interface/debug/Debug.svelte similarity index 100% rename from packages/graph-interface/src/lib/debug/Debug.svelte rename to app/src/lib/graph-interface/debug/Debug.svelte diff --git a/packages/graph-interface/src/lib/debug/index.ts b/app/src/lib/graph-interface/debug/index.ts similarity index 100% rename from packages/graph-interface/src/lib/debug/index.ts rename to app/src/lib/graph-interface/debug/index.ts diff --git a/packages/graph-interface/src/lib/debug/store.ts b/app/src/lib/graph-interface/debug/store.ts similarity index 100% rename from packages/graph-interface/src/lib/debug/store.ts rename to app/src/lib/graph-interface/debug/store.ts diff --git a/packages/graph-interface/src/lib/edges/Edge.svelte b/app/src/lib/graph-interface/edges/Edge.svelte similarity index 100% rename from packages/graph-interface/src/lib/edges/Edge.svelte rename to app/src/lib/graph-interface/edges/Edge.svelte diff --git a/packages/graph-interface/src/lib/edges/FloatingEdge.svelte b/app/src/lib/graph-interface/edges/FloatingEdge.svelte similarity index 100% rename from packages/graph-interface/src/lib/edges/FloatingEdge.svelte rename to app/src/lib/graph-interface/edges/FloatingEdge.svelte diff --git a/packages/graph-interface/src/lib/edges/createEdgeGeometry.ts b/app/src/lib/graph-interface/edges/createEdgeGeometry.ts similarity index 100% rename from packages/graph-interface/src/lib/edges/createEdgeGeometry.ts rename to app/src/lib/graph-interface/edges/createEdgeGeometry.ts diff --git a/packages/graph-interface/src/lib/edges/utils.ts b/app/src/lib/graph-interface/edges/utils.ts similarity index 100% rename from packages/graph-interface/src/lib/edges/utils.ts rename to app/src/lib/graph-interface/edges/utils.ts diff --git a/packages/graph-interface/src/lib/graph-manager.ts b/app/src/lib/graph-interface/graph-manager.ts similarity index 94% rename from packages/graph-interface/src/lib/graph-manager.ts rename to app/src/lib/graph-interface/graph-manager.ts index c7fd509..5bfb41c 100644 --- a/packages/graph-interface/src/lib/graph-manager.ts +++ b/app/src/lib/graph-interface/graph-manager.ts @@ -1,9 +1,10 @@ -import { writable, type Writable } from "svelte/store"; +import { get, writable, type Writable } from "svelte/store"; import type { Graph, Node, Edge, Socket, NodeRegistry, } from "@nodes/types"; import { HistoryManager } from "./history-manager.js" import EventEmitter from "./helpers/EventEmitter.js"; import throttle from "./helpers/throttle.js"; import { createLogger } from "./helpers/index.js"; +import type { NodeInput } from "@nodes/types"; const logger = createLogger("graph-manager"); @@ -17,6 +18,8 @@ export class GraphManager extends EventEmitter<{ "save": Graph, "result": any }> private _nodes: Map = new Map(); nodes: Writable> = writable(new Map()); + settingTypes: NodeInput[] = []; + settings: Writable> = writable({}); private _edges: Edge[] = []; edges: Writable = writable([]); @@ -51,7 +54,8 @@ export class GraphManager extends EventEmitter<{ "save": Graph, "result": any }> props: node.props, })) as Node[]; const edges = this._edges.map(edge => [edge[0].id, edge[1], edge[2].id, edge[3]]) as Graph["edges"]; - return { id: this.graph.id, nodes, edges }; + const settings = get(this.settings); + return { id: this.graph.id, settings, nodes, edges }; } execute() { } @@ -141,6 +145,12 @@ export class GraphManager extends EventEmitter<{ "save": Graph, "result": any }> this.status.set("loading"); this.id.set(graph.id); + if (graph.settings) { + this.settings.set(graph.settings); + } else { + this.settings.set({}); + } + const nodeIds = Array.from(new Set([...graph.nodes.map(n => n.type)])); await this.nodeRegistry.load(nodeIds); @@ -155,6 +165,20 @@ export class GraphManager extends EventEmitter<{ "save": Graph, "result": any }> node.tmp.type = nodeType; } + let settings: Record = {}; + const types = this.getNodeTypes(); + for (const type of types) { + if (type.inputs) { + for (const key in type.inputs) { + let settingId = type.inputs[key].setting; + if (settingId) { + settings[settingId] = type.inputs[key]; + } + } + } + } + console.log(settings); + this.history.reset(); this._init(this.graph); diff --git a/packages/graph-interface/src/lib/graph/Graph.svelte b/app/src/lib/graph-interface/graph/Graph.svelte similarity index 99% rename from packages/graph-interface/src/lib/graph/Graph.svelte rename to app/src/lib/graph-interface/graph/Graph.svelte index b838b01..61b4e6d 100644 --- a/packages/graph-interface/src/lib/graph/Graph.svelte +++ b/app/src/lib/graph-interface/graph/Graph.svelte @@ -106,7 +106,12 @@ if (!node?.inputs) { return 5; } - const height = 5 + 10 * Object.keys(node.inputs).filter((i) => i !== 'seed').length; + const height = + 5 + + 10 * + Object.keys(node.inputs) + .filter((i) => i !== 'seed') + .filter((p) => node?.inputs && !('setting' in node?.inputs?.[p])).length; nodeHeightCache[nodeTypeId] = height; return height; } diff --git a/packages/graph-interface/src/lib/graph/GraphView.svelte b/app/src/lib/graph-interface/graph/GraphView.svelte similarity index 100% rename from packages/graph-interface/src/lib/graph/GraphView.svelte rename to app/src/lib/graph-interface/graph/GraphView.svelte diff --git a/packages/graph-interface/src/lib/graph/Wrapper.svelte b/app/src/lib/graph-interface/graph/Wrapper.svelte similarity index 100% rename from packages/graph-interface/src/lib/graph/Wrapper.svelte rename to app/src/lib/graph-interface/graph/Wrapper.svelte diff --git a/packages/graph-interface/src/lib/graph/context.ts b/app/src/lib/graph-interface/graph/context.ts similarity index 100% rename from packages/graph-interface/src/lib/graph/context.ts rename to app/src/lib/graph-interface/graph/context.ts diff --git a/packages/graph-interface/src/lib/graph/stores.ts b/app/src/lib/graph-interface/graph/stores.ts similarity index 100% rename from packages/graph-interface/src/lib/graph/stores.ts rename to app/src/lib/graph-interface/graph/stores.ts diff --git a/packages/graph-interface/src/lib/helpers/EventEmitter.ts b/app/src/lib/graph-interface/helpers/EventEmitter.ts similarity index 100% rename from packages/graph-interface/src/lib/helpers/EventEmitter.ts rename to app/src/lib/graph-interface/helpers/EventEmitter.ts diff --git a/packages/graph-interface/src/lib/helpers/index.ts b/app/src/lib/graph-interface/helpers/index.ts similarity index 100% rename from packages/graph-interface/src/lib/helpers/index.ts rename to app/src/lib/graph-interface/helpers/index.ts diff --git a/packages/graph-interface/src/lib/helpers/localStore.ts b/app/src/lib/graph-interface/helpers/localStore.ts similarity index 100% rename from packages/graph-interface/src/lib/helpers/localStore.ts rename to app/src/lib/graph-interface/helpers/localStore.ts diff --git a/packages/graph-interface/src/lib/helpers/throttle.ts b/app/src/lib/graph-interface/helpers/throttle.ts similarity index 100% rename from packages/graph-interface/src/lib/helpers/throttle.ts rename to app/src/lib/graph-interface/helpers/throttle.ts diff --git a/packages/graph-interface/src/lib/history-manager.ts b/app/src/lib/graph-interface/history-manager.ts similarity index 100% rename from packages/graph-interface/src/lib/history-manager.ts rename to app/src/lib/graph-interface/history-manager.ts diff --git a/packages/graph-interface/src/lib/index.ts b/app/src/lib/graph-interface/index.ts similarity index 100% rename from packages/graph-interface/src/lib/index.ts rename to app/src/lib/graph-interface/index.ts diff --git a/packages/graph-interface/src/lib/node/Node.frag b/app/src/lib/graph-interface/node/Node.frag similarity index 100% rename from packages/graph-interface/src/lib/node/Node.frag rename to app/src/lib/graph-interface/node/Node.frag diff --git a/packages/graph-interface/src/lib/node/Node.svelte b/app/src/lib/graph-interface/node/Node.svelte similarity index 95% rename from packages/graph-interface/src/lib/node/Node.svelte rename to app/src/lib/graph-interface/node/Node.svelte index ffd7af6..d46987c 100644 --- a/packages/graph-interface/src/lib/node/Node.svelte +++ b/app/src/lib/graph-interface/node/Node.svelte @@ -22,7 +22,9 @@ const type = node?.tmp?.type; - const parameters = Object.entries(type?.inputs || {}).filter((p) => p[1].type !== 'seed'); + const parameters = Object.entries(type?.inputs || {}) + .filter((p) => p[1].type !== 'seed') + .filter((p) => !('setting' in p[1])); let ref: HTMLDivElement; let meshRef: Mesh; diff --git a/packages/graph-interface/src/lib/node/Node.vert b/app/src/lib/graph-interface/node/Node.vert similarity index 100% rename from packages/graph-interface/src/lib/node/Node.vert rename to app/src/lib/graph-interface/node/Node.vert diff --git a/packages/graph-interface/src/lib/node/NodeHeader.svelte b/app/src/lib/graph-interface/node/NodeHeader.svelte similarity index 100% rename from packages/graph-interface/src/lib/node/NodeHeader.svelte rename to app/src/lib/graph-interface/node/NodeHeader.svelte diff --git a/app/src/lib/graph-interface/node/NodeInput.svelte b/app/src/lib/graph-interface/node/NodeInput.svelte new file mode 100644 index 0000000..75df924 --- /dev/null +++ b/app/src/lib/graph-interface/node/NodeInput.svelte @@ -0,0 +1,25 @@ + + + + diff --git a/packages/graph-interface/src/lib/node/NodeParameter.svelte b/app/src/lib/graph-interface/node/NodeParameter.svelte similarity index 100% rename from packages/graph-interface/src/lib/node/NodeParameter.svelte rename to app/src/lib/graph-interface/node/NodeParameter.svelte diff --git a/app/src/lib/helpers/fastHash.test.ts b/app/src/lib/helpers/fastHash.test.ts new file mode 100644 index 0000000..cbd1595 --- /dev/null +++ b/app/src/lib/helpers/fastHash.test.ts @@ -0,0 +1,11 @@ +import { test, expect } from 'vitest'; +import fastHash from './fastHash'; + +test('Hashes dont clash', () => { + const hashA = fastHash('abcdef'); + const hashB = fastHash('abcde'); + const hashC = fastHash('abcde'); + + expect(hashA).not.toEqual(hashB); + expect(hashB).toEqual(hashC); +}); diff --git a/app/src/lib/helpers/fastHash.ts b/app/src/lib/helpers/fastHash.ts new file mode 100644 index 0000000..ef3debb --- /dev/null +++ b/app/src/lib/helpers/fastHash.ts @@ -0,0 +1,14 @@ +// Shamelessly copied from +// https://stackoverflow.com/a/8831937 + +export default function (input: string) { + if (input.length === 0) return 0; + + let hash = 0; + for (let i = 0; i < input.length; i++) { + hash = (hash << 5) - hash + input.charCodeAt(i); + hash = hash & hash; + } + + return hash; +} diff --git a/app/src/lib/runtime-executor.ts b/app/src/lib/runtime-executor.ts index c882884..c185f87 100644 --- a/app/src/lib/runtime-executor.ts +++ b/app/src/lib/runtime-executor.ts @@ -1,12 +1,23 @@ import type { Graph, NodeRegistry, NodeType, RuntimeExecutor } from "@nodes/types"; import { encodeFloat } from "./helpers/encode"; import { concat_encoded, encode } from "./helpers/flat_tree"; +import fastHash from "./helpers/fastHash"; + + +async function hashIntArray(arr: Int32Array): Promise { + const hashBuffer = await crypto.subtle.digest('SHA-256', arr.buffer); + const hashArray = Array.from(new Uint8Array(hashBuffer)); + const hashHex = hashArray.map(byte => byte.toString(16).padStart(2, '0')).join(''); + return hashHex; +} export class MemoryRuntimeExecutor implements RuntimeExecutor { private typeMap: Map = new Map(); + private cache: Record = {}; + constructor(private registry: NodeRegistry) { } private getNodeTypes(graph: Graph) { @@ -111,6 +122,8 @@ export class MemoryRuntimeExecutor implements RuntimeExecutor { // here we store the intermediate results of the nodes const results: Record = {}; + console.log(this.cache); + for (const node of sortedNodes) { const node_type = this.typeMap.get(node.type)!; @@ -139,24 +152,65 @@ export class MemoryRuntimeExecutor implements RuntimeExecutor { } + + console.log(" "); + console.log("--> EXECUTING NODE " + node_type.id, node.id); + + // execute the node and store the result try { + const a0 = performance.now(); + const node_inputs = Object.entries(inputs); + const cacheKey = `${node.id}/${fastHash(node_inputs.map(([_, value]: [string, any]) => { + if (value instanceof Int32Array) { + return hashIntArray(value); + } + console.log(value); + return `${value}` + }).join("/"))}`; + + const a1 = performance.now(); + console.log(`${a1 - a0}ms hashed inputs: ${node.id} -> ${cacheKey}`); + + if (this.cache[cacheKey] && this.cache[cacheKey].eol > Date.now()) { + results[node.id] = this.cache[cacheKey].value; + console.log(`Using cached value`); + continue; + } + const transformed_inputs = node_inputs.map(([key, value]: [string, any]) => { const input_type = node_type.inputs?.[key]!; if (value instanceof Int32Array) { - return [...value.slice(0, value.length)]; + let _v = new Array(value.length); + for (let i = 0; i < value.length; i++) { + _v[i] = value[i]; + } + return _v; } if (input_type.type === "float") { return encode(encodeFloat(value as number)); } + return value; }); + + const a2 = performance.now(); + + console.log(`${a2 - a1}ms TRANSFORMED_INPUTS`); + const _inputs = concat_encoded(transformed_inputs); - // console.log(`Executing node ${node_type.id || node.id}`, { _inputs, inputs, node_type }); + const a3 = performance.now(); results[node.id] = node_type.execute(_inputs) as number; - // console.log("--> result", results[node.id]); + const duration = performance.now() - a3; + if (duration > 5) { + this.cache[cacheKey] = { eol: Date.now() + 10_000, value: results[node.id] }; + console.log(`Caching for 10 seconds`); + } + console.log(`${duration}ms Executed`); + const a4 = performance.now(); + console.log(`${a4 - a0}ms e2e duration`); } catch (e) { console.error(`Error executing node ${node_type.id || node.id}`, e); } diff --git a/app/src/routes/+page.svelte b/app/src/routes/+page.svelte index 9eb3051..a770278 100644 --- a/app/src/routes/+page.svelte +++ b/app/src/routes/+page.svelte @@ -1,6 +1,6 @@ - - - diff --git a/packages/graph-interface/src/routes/+page.svelte b/packages/graph-interface/src/routes/+page.svelte deleted file mode 100644 index 0a45b69..0000000 --- a/packages/graph-interface/src/routes/+page.svelte +++ /dev/null @@ -1,3 +0,0 @@ -

Welcome to your library project

-

Create your package using @sveltejs/package and preview/showcase your work with SvelteKit

-

Visit kit.svelte.dev to read the documentation

diff --git a/packages/graph-interface/static/favicon.png b/packages/graph-interface/static/favicon.png deleted file mode 100644 index 825b9e6..0000000 Binary files a/packages/graph-interface/static/favicon.png and /dev/null differ diff --git a/packages/graph-interface/svelte.config.js b/packages/graph-interface/svelte.config.js deleted file mode 100644 index 2b35fe1..0000000 --- a/packages/graph-interface/svelte.config.js +++ /dev/null @@ -1,18 +0,0 @@ -import adapter from '@sveltejs/adapter-auto'; -import { vitePreprocess } from '@sveltejs/vite-plugin-svelte'; - -/** @type {import('@sveltejs/kit').Config} */ -const config = { - // Consult https://kit.svelte.dev/docs/integrations#preprocessors - // for more information about preprocessors - preprocess: vitePreprocess(), - - kit: { - // adapter-auto only supports some environments, see https://kit.svelte.dev/docs/adapter-auto for a list. - // If your environment is not supported or you settled on a specific environment, switch out the adapter. - // See https://kit.svelte.dev/docs/adapters for more information about adapters. - adapter: adapter() - } -}; - -export default config; diff --git a/packages/graph-interface/tsconfig.json b/packages/graph-interface/tsconfig.json deleted file mode 100644 index e9454e7..0000000 --- a/packages/graph-interface/tsconfig.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "extends": "./.svelte-kit/tsconfig.json", - "compilerOptions": { - "allowJs": true, - "checkJs": true, - "esModuleInterop": true, - "forceConsistentCasingInFileNames": true, - "resolveJsonModule": true, - "skipLibCheck": true, - "sourceMap": true, - "strict": true, - "module": "NodeNext", - "moduleResolution": "NodeNext", - "types": [ - "vite-plugin-glsl/ext" - ] - } -} diff --git a/packages/graph-interface/vite.config.ts b/packages/graph-interface/vite.config.ts deleted file mode 100644 index 2b5a1b2..0000000 --- a/packages/graph-interface/vite.config.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { sveltekit } from '@sveltejs/kit/vite'; -import glsl from "vite-plugin-glsl"; -import { defineConfig } from 'vite'; -import { exec } from 'child_process'; -const dev = import.meta.env; - -export default defineConfig({ - plugins: [sveltekit(), glsl(), { - name: 'postbuild-commands', // the name of your custom plugin. Could be anything. - closeBundle: async () => { - return; - // run pnpm run package - exec('pnpm run package', (err, stdout, stderr) => { - console.log(stdout); - }); - } - },] -}); diff --git a/packages/macros/Cargo.toml b/packages/macros/Cargo.toml new file mode 100644 index 0000000..cbfc0a1 --- /dev/null +++ b/packages/macros/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "macros" +version = "0.1.0" +edition = "2021" + +[lib] +proc-macro = true + +[dependencies] +syn = { version = "1.0", features = ["full"] } +serde_json = "1.0" +quote = "1.0" diff --git a/packages/macros/src/lib.rs b/packages/macros/src/lib.rs new file mode 100644 index 0000000..1b6dc52 --- /dev/null +++ b/packages/macros/src/lib.rs @@ -0,0 +1,65 @@ +extern crate proc_macro; +use proc_macro::TokenStream; +use quote::quote; +use serde_json::Value; +use std::env; +use std::fs; +use std::path::Path; +use syn::{parse_macro_input, LitStr}; + +#[proc_macro] +pub fn generate_input_types(input: TokenStream) -> TokenStream { + let input_string = parse_macro_input!(input as LitStr).value(); + + // Validate JSON format + let json: Value = match serde_json::from_str(&input_string) { + Ok(json) => json, + Err(e) => panic!("Invalid JSON input: {}", e), + }; + + // Convert the validated JSON back to a pretty-printed string + let formatted_json = serde_json::to_string_pretty(&json).expect("Failed to serialize JSON"); + + // Generate the output function + let expanded = quote! { + #[wasm_bindgen] + pub fn get_input_types() -> String { + String::from(#formatted_json) + } + }; + + // Convert the generated code back to a TokenStream + TokenStream::from(expanded) +} + +#[proc_macro] +pub fn generate_input_types_file(input: TokenStream) -> TokenStream { + let file_path = syn::parse_macro_input!(input as syn::LitStr).value(); + + // Retrieve the directory containing the Cargo.toml file + let project_dir = env::var("CARGO_MANIFEST_DIR").unwrap(); + let full_path = Path::new(&project_dir).join(&file_path); + + // Read the JSON file content + let json_content = fs::read_to_string(full_path).unwrap_or_else(|err| { + panic!( + "Failed to read JSON file at '{}/{}': {}", + project_dir, file_path, err + ) + }); + + // Optionally, validate that the content is valid JSON + let _: Value = serde_json::from_str(&json_content) + .unwrap_or_else(|_| panic!("JSON file contains invalid JSON")); + + // Generate the function that returns the JSON string + let expanded = quote! { + #[wasm_bindgen] + pub fn get_input_types() -> String { + String::from(#json_content) + } + }; + + // Convert the generated code back to a TokenStream + TokenStream::from(expanded) +} diff --git a/packages/node-registry/src/lib/registry.ts b/packages/node-registry/src/lib/registry.ts index edb30e7..1a18fd3 100644 --- a/packages/node-registry/src/lib/registry.ts +++ b/packages/node-registry/src/lib/registry.ts @@ -8,7 +8,7 @@ export async function getNodeWrapper(id: `${string}/${string}/${string}`) { let wrapperCode = await wrapperReponse.text(); wrapperCode = wrapperCode.replace("wasm = val;", `if(wasm) return; wasm = val;`); - const wasmWrapper = await import(/*@vite-ignore*/`data:text/javascript;base64,${btoa(wrapperCode)}?id=${id}`); + const wasmWrapper = await import(/*@vite-ignore*/`data:text/javascript;base64,${btoa(wrapperCode)}#${id}${Math.random().toString().slice(2)}`); return wasmWrapper; } @@ -41,6 +41,7 @@ export async function getNode(id: `${string}/${string}/${string}`) { const inputTypes = JSON.parse(rawInputs); return { id, outputs, inputs: inputTypes } } catch (e) { + console.log(rawInputs); console.log("Failed to parse input types for node", { id, rawInputs }); } diff --git a/packages/types/index.ts b/packages/types/index.ts index 3258e13..aa6c9b0 100644 --- a/packages/types/index.ts +++ b/packages/types/index.ts @@ -89,6 +89,7 @@ export type Graph = { title?: string; lastModified?: string; }, + settings?: Record, nodes: Node[]; edges: [number, number, number, string][]; } diff --git a/packages/types/inputs.ts b/packages/types/inputs.ts index c387e38..bd5c776 100644 --- a/packages/types/inputs.ts +++ b/packages/types/inputs.ts @@ -26,11 +26,13 @@ type NodeInputSelect = { type NodeInputSeed = { type: "seed" + value?: number; } type DefaultOptions = { internal?: boolean; external?: boolean; + setting?: string; label?: string; } diff --git a/packages/ui/src/index.test.ts b/packages/ui/src/index.test.ts deleted file mode 100644 index e07cbbd..0000000 --- a/packages/ui/src/index.test.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { describe, it, expect } from 'vitest'; - -describe('sum test', () => { - it('adds 1 + 2 to equal 3', () => { - expect(1 + 2).toBe(3); - }); -}); diff --git a/packages/ui/src/lib/Input.svelte b/packages/ui/src/lib/Input.svelte index 9918321..27788c2 100644 --- a/packages/ui/src/lib/Input.svelte +++ b/packages/ui/src/lib/Input.svelte @@ -8,14 +8,15 @@ export let input: NodeInput; export let value: any; + export let id: string; {#if input.type === "float"} - + {:else if input.type === "integer"} - + {:else if input.type === "boolean"} - + {:else if input.type === "select"} - {/if} diff --git a/packages/ui/src/lib/elements/Checkbox.svelte b/packages/ui/src/lib/elements/Checkbox.svelte index 64f801c..bb5cdec 100644 --- a/packages/ui/src/lib/elements/Checkbox.svelte +++ b/packages/ui/src/lib/elements/Checkbox.svelte @@ -1,8 +1,10 @@ - +