From dec205b234fbc08d8593af78ecc233f7544e07b8 Mon Sep 17 00:00:00 2001 From: Max Richter Date: Mon, 15 Apr 2024 22:13:43 +0200 Subject: [PATCH] feat: some moving around --- Cargo.lock | 50 ++++++++++++-- Cargo.toml | 2 +- .../src/lib/graph-interface}/AddMenu.svelte | 0 .../lib/graph-interface}/BoxSelection.svelte | 0 .../src/lib/graph-interface}/Camera.svelte | 0 .../background/Background.frag | 0 .../background/Background.story.svelte | 0 .../background/Background.svelte | 0 .../background/Background.vert | 0 .../lib/graph-interface}/debug/Debug.svelte | 0 .../src/lib/graph-interface}/debug/index.ts | 0 .../src/lib/graph-interface}/debug/store.ts | 0 .../lib/graph-interface}/edges/Edge.svelte | 0 .../edges/FloatingEdge.svelte | 0 .../edges/createEdgeGeometry.ts | 0 .../src/lib/graph-interface}/edges/utils.ts | 0 .../src/lib/graph-interface}/graph-manager.ts | 28 +++++++- .../lib/graph-interface}/graph/Graph.svelte | 7 +- .../graph-interface}/graph/GraphView.svelte | 0 .../lib/graph-interface}/graph/Wrapper.svelte | 0 .../src/lib/graph-interface}/graph/context.ts | 0 .../src/lib/graph-interface}/graph/stores.ts | 0 .../graph-interface}/helpers/EventEmitter.ts | 0 .../src/lib/graph-interface}/helpers/index.ts | 0 .../graph-interface}/helpers/localStore.ts | 0 .../lib/graph-interface}/helpers/throttle.ts | 0 .../lib/graph-interface}/history-manager.ts | 0 .../src/lib/graph-interface}/index.ts | 0 .../src/lib/graph-interface}/node/Node.frag | 0 .../src/lib/graph-interface}/node/Node.svelte | 4 +- .../src/lib/graph-interface}/node/Node.vert | 0 .../graph-interface}/node/NodeHeader.svelte | 0 .../lib/graph-interface/node/NodeInput.svelte | 25 +++++++ .../node/NodeParameter.svelte | 0 app/src/lib/helpers/fastHash.test.ts | 11 +++ app/src/lib/helpers/fastHash.ts | 14 ++++ app/src/lib/runtime-executor.ts | 60 +++++++++++++++- app/src/routes/+page.svelte | 5 +- nodes/max/plantarium/array/Cargo.toml | 2 + nodes/max/plantarium/array/src/input.json | 10 +++ nodes/max/plantarium/array/src/lib.rs | 46 ++++++------- nodes/max/plantarium/float/Cargo.toml | 1 + nodes/max/plantarium/float/src/input.json | 7 ++ nodes/max/plantarium/float/src/lib.rs | 16 ++--- nodes/max/plantarium/math/Cargo.toml | 1 + nodes/max/plantarium/math/src/input.json | 27 ++++++++ nodes/max/plantarium/math/src/lib.rs | 25 ++----- nodes/max/plantarium/output/src/lib.rs | 2 +- nodes/max/plantarium/stem/.gitignore | 6 ++ nodes/max/plantarium/stem/Cargo.toml | 23 +++++++ nodes/max/plantarium/stem/package.json | 5 ++ nodes/max/plantarium/stem/src/input.json | 27 ++++++++ nodes/max/plantarium/stem/src/lib.rs | 20 ++++++ nodes/max/plantarium/stem/tests/web.rs | 13 ++++ nodes/max/plantarium/sum/Cargo.toml | 2 + nodes/max/plantarium/sum/src/input.json | 7 ++ nodes/max/plantarium/sum/src/lib.rs | 46 +++++++------ packages/graph-interface/.eslintignore | 13 ---- packages/graph-interface/.eslintrc.cjs | 31 --------- packages/graph-interface/.gitignore | 11 --- packages/graph-interface/.npmrc | 1 - packages/graph-interface/.prettierignore | 4 -- packages/graph-interface/.prettierrc | 8 --- packages/graph-interface/README.md | 58 ---------------- packages/graph-interface/package.json | 65 ------------------ packages/graph-interface/src/app.d.ts | 13 ---- packages/graph-interface/src/app.html | 12 ---- .../src/lib/node/NodeInput.svelte | 23 ------- .../graph-interface/src/routes/+page.svelte | 3 - packages/graph-interface/static/favicon.png | Bin 1571 -> 0 bytes packages/graph-interface/svelte.config.js | 18 ----- packages/graph-interface/tsconfig.json | 18 ----- packages/graph-interface/vite.config.ts | 18 ----- packages/macros/Cargo.toml | 12 ++++ packages/macros/src/lib.rs | 65 ++++++++++++++++++ packages/node-registry/src/lib/registry.ts | 3 +- packages/types/index.ts | 1 + packages/types/inputs.ts | 2 + packages/ui/src/index.test.ts | 7 -- packages/ui/src/lib/Input.svelte | 9 +-- packages/ui/src/lib/elements/Checkbox.svelte | 4 +- packages/ui/src/lib/elements/Float.svelte | 3 +- packages/ui/src/lib/elements/Integer.svelte | 3 +- packages/ui/src/lib/elements/Select.svelte | 3 +- packages/utils/src/lib.rs | 10 +++ packages/utils/src/tree.rs | 4 ++ 86 files changed, 505 insertions(+), 409 deletions(-) rename {packages/graph-interface/src/lib => app/src/lib/graph-interface}/AddMenu.svelte (100%) rename {packages/graph-interface/src/lib => app/src/lib/graph-interface}/BoxSelection.svelte (100%) rename {packages/graph-interface/src/lib => app/src/lib/graph-interface}/Camera.svelte (100%) rename {packages/graph-interface/src/lib => app/src/lib/graph-interface}/background/Background.frag (100%) rename {packages/graph-interface/src/lib => app/src/lib/graph-interface}/background/Background.story.svelte (100%) rename {packages/graph-interface/src/lib => app/src/lib/graph-interface}/background/Background.svelte (100%) rename {packages/graph-interface/src/lib => app/src/lib/graph-interface}/background/Background.vert (100%) rename {packages/graph-interface/src/lib => app/src/lib/graph-interface}/debug/Debug.svelte (100%) rename {packages/graph-interface/src/lib => app/src/lib/graph-interface}/debug/index.ts (100%) rename {packages/graph-interface/src/lib => app/src/lib/graph-interface}/debug/store.ts (100%) rename {packages/graph-interface/src/lib => app/src/lib/graph-interface}/edges/Edge.svelte (100%) rename {packages/graph-interface/src/lib => app/src/lib/graph-interface}/edges/FloatingEdge.svelte (100%) rename {packages/graph-interface/src/lib => app/src/lib/graph-interface}/edges/createEdgeGeometry.ts (100%) rename {packages/graph-interface/src/lib => app/src/lib/graph-interface}/edges/utils.ts (100%) rename {packages/graph-interface/src/lib => app/src/lib/graph-interface}/graph-manager.ts (94%) rename {packages/graph-interface/src/lib => app/src/lib/graph-interface}/graph/Graph.svelte (99%) rename {packages/graph-interface/src/lib => app/src/lib/graph-interface}/graph/GraphView.svelte (100%) rename {packages/graph-interface/src/lib => app/src/lib/graph-interface}/graph/Wrapper.svelte (100%) rename {packages/graph-interface/src/lib => app/src/lib/graph-interface}/graph/context.ts (100%) rename {packages/graph-interface/src/lib => app/src/lib/graph-interface}/graph/stores.ts (100%) rename {packages/graph-interface/src/lib => app/src/lib/graph-interface}/helpers/EventEmitter.ts (100%) rename {packages/graph-interface/src/lib => app/src/lib/graph-interface}/helpers/index.ts (100%) rename {packages/graph-interface/src/lib => app/src/lib/graph-interface}/helpers/localStore.ts (100%) rename {packages/graph-interface/src/lib => app/src/lib/graph-interface}/helpers/throttle.ts (100%) rename {packages/graph-interface/src/lib => app/src/lib/graph-interface}/history-manager.ts (100%) rename {packages/graph-interface/src/lib => app/src/lib/graph-interface}/index.ts (100%) rename {packages/graph-interface/src/lib => app/src/lib/graph-interface}/node/Node.frag (100%) rename {packages/graph-interface/src/lib => app/src/lib/graph-interface}/node/Node.svelte (95%) rename {packages/graph-interface/src/lib => app/src/lib/graph-interface}/node/Node.vert (100%) rename {packages/graph-interface/src/lib => app/src/lib/graph-interface}/node/NodeHeader.svelte (100%) create mode 100644 app/src/lib/graph-interface/node/NodeInput.svelte rename {packages/graph-interface/src/lib => app/src/lib/graph-interface}/node/NodeParameter.svelte (100%) create mode 100644 app/src/lib/helpers/fastHash.test.ts create mode 100644 app/src/lib/helpers/fastHash.ts create mode 100644 nodes/max/plantarium/array/src/input.json create mode 100644 nodes/max/plantarium/float/src/input.json create mode 100644 nodes/max/plantarium/math/src/input.json create mode 100644 nodes/max/plantarium/stem/.gitignore create mode 100644 nodes/max/plantarium/stem/Cargo.toml create mode 100644 nodes/max/plantarium/stem/package.json create mode 100644 nodes/max/plantarium/stem/src/input.json create mode 100644 nodes/max/plantarium/stem/src/lib.rs create mode 100644 nodes/max/plantarium/stem/tests/web.rs create mode 100644 nodes/max/plantarium/sum/src/input.json delete mode 100644 packages/graph-interface/.eslintignore delete mode 100644 packages/graph-interface/.eslintrc.cjs delete mode 100644 packages/graph-interface/.gitignore delete mode 100644 packages/graph-interface/.npmrc delete mode 100644 packages/graph-interface/.prettierignore delete mode 100644 packages/graph-interface/.prettierrc delete mode 100644 packages/graph-interface/README.md delete mode 100644 packages/graph-interface/package.json delete mode 100644 packages/graph-interface/src/app.d.ts delete mode 100644 packages/graph-interface/src/app.html delete mode 100644 packages/graph-interface/src/lib/node/NodeInput.svelte delete mode 100644 packages/graph-interface/src/routes/+page.svelte delete mode 100644 packages/graph-interface/static/favicon.png delete mode 100644 packages/graph-interface/svelte.config.js delete mode 100644 packages/graph-interface/tsconfig.json delete mode 100644 packages/graph-interface/vite.config.ts create mode 100644 packages/macros/Cargo.toml create mode 100644 packages/macros/src/lib.rs delete mode 100644 packages/ui/src/index.test.ts 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 825b9e65af7c104cfb07089bb28659393b4f2097..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1571 zcmV+;2Hg3HP)Px)-AP12RCwC$UE6KzI1p6{F2N z1VK2vi|pOpn{~#djwYcWXTI_im_u^TJgMZ4JMOsSj!0ma>B?-(Hr@X&W@|R-$}W@Z zgj#$x=!~7LGqHW?IO8+*oE1MyDp!G=L0#^lUx?;!fXv@l^6SvTnf^ac{5OurzC#ZMYc20lI%HhX816AYVs1T3heS1*WaWH z%;x>)-J}YB5#CLzU@GBR6sXYrD>Vw(Fmt#|JP;+}<#6b63Ike{Fuo!?M{yEffez;| zp!PfsuaC)>h>-AdbnwN13g*1LowNjT5?+lFVd#9$!8Z9HA|$*6dQ8EHLu}U|obW6f z2%uGv?vr=KNq7YYa2Roj;|zooo<)lf=&2yxM@e`kM$CmCR#x>gI>I|*Ubr({5Y^rb zghxQU22N}F51}^yfDSt786oMTc!W&V;d?76)9KXX1 z+6Okem(d}YXmmOiZq$!IPk5t8nnS{%?+vDFz3BevmFNgpIod~R{>@#@5x9zJKEHLHv!gHeK~n)Ld!M8DB|Kfe%~123&Hz1Z(86nU7*G5chmyDe ziV7$pB7pJ=96hpxHv9rCR29%bLOXlKU<_13_M8x)6;P8E1Kz6G<&P?$P^%c!M5`2` zfY2zg;VK5~^>TJGQzc+33-n~gKt{{of8GzUkWmU110IgI0DLxRIM>0US|TsM=L|@F z0Bun8U!cRB7-2apz=y-7*UxOxz@Z0)@QM)9wSGki1AZ38ceG7Q72z5`i;i=J`ILzL z@iUO?SBBG-0cQuo+an4TsLy-g-x;8P4UVwk|D8{W@U1Zi z!M)+jqy@nQ$p?5tsHp-6J304Q={v-B>66$P0IDx&YT(`IcZ~bZfmn11#rXd7<5s}y zBi9eim&zQc0Dk|2>$bs0PnLmDfMP5lcXRY&cvJ=zKxI^f0%-d$tD!`LBf9^jMSYUA zI8U?CWdY@}cRq6{5~y+)#h1!*-HcGW@+gZ4B};0OnC~`xQOyH19z*TA!!BJ%9s0V3F?CAJ{hTd#*tf+ur-W9MOURF-@B77_-OshsY}6 zOXRY=5%C^*26z?l)1=$bz30!so5tfABdSYzO+H=CpV~aaUefmjvfZ3Ttu9W&W3Iu6 zROlh0MFA5h;my}8lB0tAV-Rvc2Zs_CCSJnx@d`**$idgy-iMob4dJWWw|21b4NB=LfsYp0Aeh{Ov)yztQi;eL4y5 zMi>8^SzKqk8~k?UiQK^^-5d8c%bV?$F8%X~czyiaKCI2=UH { - 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 @@ - +