Compare commits
8 Commits
571bb2a5d3
...
feat/zig-b
| Author | SHA1 | Date | |
|---|---|---|---|
| 9b94159f8e | |||
| aa4d7f73a8 | |||
| 1efb94b09c | |||
|
|
5570d975f5 | ||
|
|
8c1ba2ee65 | ||
|
|
3e019e4e21 | ||
|
|
a58b19e935 | ||
|
|
714d01da94 |
@@ -6,7 +6,10 @@ members = [
|
|||||||
"packages/types",
|
"packages/types",
|
||||||
"packages/utils",
|
"packages/utils",
|
||||||
]
|
]
|
||||||
exclude = ["nodes/max/plantarium/.template"]
|
exclude = [
|
||||||
|
"nodes/max/plantarium/.template",
|
||||||
|
"nodes/max/plantarium/zig"
|
||||||
|
]
|
||||||
|
|
||||||
[profile.release]
|
[profile.release]
|
||||||
lto = true
|
lto = true
|
||||||
|
|||||||
@@ -28,7 +28,7 @@
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@iconify-json/tabler": "^1.2.26",
|
"@iconify-json/tabler": "^1.2.26",
|
||||||
"@iconify/tailwind4": "^1.2.1",
|
"@iconify/tailwind4": "^1.2.1",
|
||||||
"@nodarium/types": "link:../packages/types",
|
"@nodarium/types": "workspace:",
|
||||||
"@sveltejs/adapter-static": "^3.0.10",
|
"@sveltejs/adapter-static": "^3.0.10",
|
||||||
"@sveltejs/vite-plugin-svelte": "^6.2.4",
|
"@sveltejs/vite-plugin-svelte": "^6.2.4",
|
||||||
"@tsconfig/svelte": "^5.0.6",
|
"@tsconfig/svelte": "^5.0.6",
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { HTML } from "@threlte/extras";
|
import type { NodeId, NodeInstance } from '@nodarium/types';
|
||||||
import { onMount } from "svelte";
|
import { HTML } from '@threlte/extras';
|
||||||
import type { NodeInstance, NodeId } from "@nodarium/types";
|
import { onMount } from 'svelte';
|
||||||
import { getGraphManager, getGraphState } from "../graph-state.svelte";
|
import { getGraphManager, getGraphState } from '../graph-state.svelte';
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
onnode: (n: NodeInstance) => void;
|
onnode: (n: NodeInstance) => void;
|
||||||
@@ -14,6 +14,7 @@
|
|||||||
const graphState = getGraphState();
|
const graphState = getGraphState();
|
||||||
|
|
||||||
let input: HTMLInputElement;
|
let input: HTMLInputElement;
|
||||||
|
let wrapper: HTMLDivElement;
|
||||||
let value = $state<string>();
|
let value = $state<string>();
|
||||||
let activeNodeId = $state<NodeId>();
|
let activeNodeId = $state<NodeId>();
|
||||||
|
|
||||||
@@ -22,10 +23,10 @@
|
|||||||
: graph.getNodeDefinitions();
|
: graph.getNodeDefinitions();
|
||||||
|
|
||||||
function filterNodes() {
|
function filterNodes() {
|
||||||
return allNodes.filter((node) => node.id.includes(value ?? ""));
|
return allNodes.filter((node) => node.id.includes(value ?? ''));
|
||||||
}
|
}
|
||||||
|
|
||||||
const nodes = $derived(value === "" ? allNodes : filterNodes());
|
const nodes = $derived(value === '' ? allNodes : filterNodes());
|
||||||
$effect(() => {
|
$effect(() => {
|
||||||
if (nodes) {
|
if (nodes) {
|
||||||
if (activeNodeId === undefined) {
|
if (activeNodeId === undefined) {
|
||||||
@@ -39,38 +40,38 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
function handleNodeCreation(nodeType: NodeInstance["type"]) {
|
function handleNodeCreation(nodeType: NodeInstance['type']) {
|
||||||
if (!graphState.addMenuPosition) return;
|
if (!graphState.addMenuPosition) return;
|
||||||
onnode?.({
|
onnode?.({
|
||||||
id: -1,
|
id: -1,
|
||||||
type: nodeType,
|
type: nodeType,
|
||||||
position: [...graphState.addMenuPosition],
|
position: [...graphState.addMenuPosition],
|
||||||
props: {},
|
props: {},
|
||||||
state: {},
|
state: {}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleKeyDown(event: KeyboardEvent) {
|
function handleKeyDown(event: KeyboardEvent) {
|
||||||
event.stopImmediatePropagation();
|
event.stopImmediatePropagation();
|
||||||
|
|
||||||
if (event.key === "Escape") {
|
if (event.key === 'Escape') {
|
||||||
graphState.addMenuPosition = null;
|
graphState.addMenuPosition = null;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.key === "ArrowDown") {
|
if (event.key === 'ArrowDown') {
|
||||||
const index = nodes.findIndex((node) => node.id === activeNodeId);
|
const index = nodes.findIndex((node) => node.id === activeNodeId);
|
||||||
activeNodeId = nodes[(index + 1) % nodes.length].id;
|
activeNodeId = nodes[(index + 1) % nodes.length].id;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.key === "ArrowUp") {
|
if (event.key === 'ArrowUp') {
|
||||||
const index = nodes.findIndex((node) => node.id === activeNodeId);
|
const index = nodes.findIndex((node) => node.id === activeNodeId);
|
||||||
activeNodeId = nodes[(index - 1 + nodes.length) % nodes.length].id;
|
activeNodeId = nodes[(index - 1 + nodes.length) % nodes.length].id;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.key === "Enter") {
|
if (event.key === 'Enter') {
|
||||||
if (activeNodeId && graphState.addMenuPosition) {
|
if (activeNodeId && graphState.addMenuPosition) {
|
||||||
handleNodeCreation(activeNodeId);
|
handleNodeCreation(activeNodeId);
|
||||||
}
|
}
|
||||||
@@ -81,6 +82,16 @@
|
|||||||
onMount(() => {
|
onMount(() => {
|
||||||
input.disabled = false;
|
input.disabled = false;
|
||||||
setTimeout(() => input.focus(), 50);
|
setTimeout(() => input.focus(), 50);
|
||||||
|
|
||||||
|
const rect = wrapper.getBoundingClientRect();
|
||||||
|
const deltaY = rect.bottom - window.innerHeight;
|
||||||
|
const deltaX = rect.right - window.innerWidth;
|
||||||
|
if (deltaY > 0) {
|
||||||
|
wrapper.style.marginTop = `-${deltaY + 30}px`;
|
||||||
|
}
|
||||||
|
if (deltaX > 0) {
|
||||||
|
wrapper.style.marginLeft = `-${deltaX + 30}px`;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@@ -89,7 +100,7 @@
|
|||||||
position.z={graphState.addMenuPosition?.[1]}
|
position.z={graphState.addMenuPosition?.[1]}
|
||||||
transform={false}
|
transform={false}
|
||||||
>
|
>
|
||||||
<div class="add-menu-wrapper">
|
<div class="add-menu-wrapper" bind:this={wrapper}>
|
||||||
<div class="header">
|
<div class="header">
|
||||||
<input
|
<input
|
||||||
id="add-menu"
|
id="add-menu"
|
||||||
@@ -112,7 +123,7 @@
|
|||||||
tabindex="0"
|
tabindex="0"
|
||||||
aria-selected={node.id === activeNodeId}
|
aria-selected={node.id === activeNodeId}
|
||||||
onkeydown={(event) => {
|
onkeydown={(event) => {
|
||||||
if (event.key === "Enter") {
|
if (event.key === 'Enter') {
|
||||||
handleNodeCreation(node.id);
|
handleNodeCreation(node.id);
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
@@ -125,7 +136,7 @@
|
|||||||
activeNodeId = node.id;
|
activeNodeId = node.id;
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{node.id.split("/").at(-1)}
|
{node.id.split('/').at(-1)}
|
||||||
</div>
|
</div>
|
||||||
{/each}
|
{/each}
|
||||||
</div>
|
</div>
|
||||||
@@ -167,6 +178,8 @@
|
|||||||
min-height: none;
|
min-height: none;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
color: var(--text-color);
|
color: var(--text-color);
|
||||||
|
max-height: 300px;
|
||||||
|
overflow-y: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
.result {
|
.result {
|
||||||
|
|||||||
@@ -58,7 +58,9 @@ export class GraphState {
|
|||||||
|
|
||||||
wrapper = $state<HTMLDivElement>(null!);
|
wrapper = $state<HTMLDivElement>(null!);
|
||||||
rect: DOMRect = $derived(
|
rect: DOMRect = $derived(
|
||||||
(this.wrapper && this.width && this.height) ? this.wrapper.getBoundingClientRect() : new DOMRect(0, 0, 0, 0)
|
(this.wrapper && this.width && this.height)
|
||||||
|
? this.wrapper.getBoundingClientRect()
|
||||||
|
: new DOMRect(0, 0, 0, 0)
|
||||||
);
|
);
|
||||||
|
|
||||||
camera = $state<OrthographicCamera>(null!);
|
camera = $state<OrthographicCamera>(null!);
|
||||||
@@ -333,4 +335,8 @@ export class GraphState {
|
|||||||
&& node.position[1] < this.cameraBounds[3]
|
&& node.position[1] < this.cameraBounds[3]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
openNodePalette() {
|
||||||
|
this.addMenuPosition = [this.mousePosition[0], this.mousePosition[1]];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,23 +1,23 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import type { Edge, NodeInstance } from "@nodarium/types";
|
import type { Edge, NodeInstance } from '@nodarium/types';
|
||||||
import { createKeyMap } from "../../helpers/createKeyMap";
|
import { Canvas } from '@threlte/core';
|
||||||
import AddMenu from "../components/AddMenu.svelte";
|
import { HTML } from '@threlte/extras';
|
||||||
import Background from "../background/Background.svelte";
|
import { createKeyMap } from '../../helpers/createKeyMap';
|
||||||
import BoxSelection from "../components/BoxSelection.svelte";
|
import Background from '../background/Background.svelte';
|
||||||
import EdgeEl from "../edges/Edge.svelte";
|
import AddMenu from '../components/AddMenu.svelte';
|
||||||
import NodeEl from "../node/Node.svelte";
|
import BoxSelection from '../components/BoxSelection.svelte';
|
||||||
import Camera from "../components/Camera.svelte";
|
import Camera from '../components/Camera.svelte';
|
||||||
import { Canvas } from "@threlte/core";
|
import HelpView from '../components/HelpView.svelte';
|
||||||
import HelpView from "../components/HelpView.svelte";
|
import Debug from '../debug/Debug.svelte';
|
||||||
import { getGraphManager, getGraphState } from "../graph-state.svelte";
|
import EdgeEl from '../edges/Edge.svelte';
|
||||||
import { HTML } from "@threlte/extras";
|
import { getGraphManager, getGraphState } from '../graph-state.svelte';
|
||||||
import { maxZoom, minZoom } from "./constants";
|
import NodeEl from '../node/Node.svelte';
|
||||||
import Debug from "../debug/Debug.svelte";
|
import { maxZoom, minZoom } from './constants';
|
||||||
import { FileDropEventManager } from "./drop.events";
|
import { FileDropEventManager } from './drop.events';
|
||||||
import { MouseEventManager } from "./mouse.events";
|
import { MouseEventManager } from './mouse.events';
|
||||||
|
|
||||||
const {
|
const {
|
||||||
keymap,
|
keymap
|
||||||
}: {
|
}: {
|
||||||
keymap: ReturnType<typeof createKeyMap>;
|
keymap: ReturnType<typeof createKeyMap>;
|
||||||
} = $props();
|
} = $props();
|
||||||
@@ -45,19 +45,18 @@
|
|||||||
const newNode = graph.createNode({
|
const newNode = graph.createNode({
|
||||||
type: node.type,
|
type: node.type,
|
||||||
position: node.position,
|
position: node.position,
|
||||||
props: node.props,
|
props: node.props
|
||||||
});
|
});
|
||||||
if (!newNode) return;
|
if (!newNode) return;
|
||||||
|
|
||||||
if (graphState.activeSocket) {
|
if (graphState.activeSocket) {
|
||||||
if (typeof graphState.activeSocket.index === "number") {
|
if (typeof graphState.activeSocket.index === 'number') {
|
||||||
const socketType =
|
const socketType = graphState.activeSocket.node.state?.type?.outputs?.[
|
||||||
graphState.activeSocket.node.state?.type?.outputs?.[
|
|
||||||
graphState.activeSocket.index
|
graphState.activeSocket.index
|
||||||
];
|
];
|
||||||
|
|
||||||
const input = Object.entries(newNode?.state?.type?.inputs || {}).find(
|
const input = Object.entries(newNode?.state?.type?.inputs || {}).find(
|
||||||
(inp) => inp[1].type === socketType,
|
(inp) => inp[1].type === socketType
|
||||||
);
|
);
|
||||||
|
|
||||||
if (input) {
|
if (input) {
|
||||||
@@ -65,12 +64,11 @@
|
|||||||
graphState.activeSocket.node,
|
graphState.activeSocket.node,
|
||||||
graphState.activeSocket.index,
|
graphState.activeSocket.index,
|
||||||
newNode,
|
newNode,
|
||||||
input[0],
|
input[0]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const socketType =
|
const socketType = graphState.activeSocket.node.state?.type?.inputs?.[
|
||||||
graphState.activeSocket.node.state?.type?.inputs?.[
|
|
||||||
graphState.activeSocket.index
|
graphState.activeSocket.index
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -85,7 +83,7 @@
|
|||||||
newNode,
|
newNode,
|
||||||
output.indexOf(output),
|
output.indexOf(output),
|
||||||
graphState.activeSocket.node,
|
graphState.activeSocket.node,
|
||||||
graphState.activeSocket.index,
|
graphState.activeSocket.index
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -97,15 +95,15 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<svelte:window
|
<svelte:window
|
||||||
onmousemove={(ev) => mouseEvents.handleMouseMove(ev)}
|
onmousemove={(ev) => mouseEvents.handleWindowMouseMove(ev)}
|
||||||
onmouseup={(ev) => mouseEvents.handleMouseUp(ev)}
|
onmouseup={(ev) => mouseEvents.handleWindowMouseUp(ev)}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
onwheel={(ev) => mouseEvents.handleMouseScroll(ev)}
|
onwheel={(ev) => mouseEvents.handleMouseScroll(ev)}
|
||||||
bind:this={graphState.wrapper}
|
bind:this={graphState.wrapper}
|
||||||
class="graph-wrapper"
|
class="graph-wrapper"
|
||||||
style="height: 100%;"
|
style="height: 100%"
|
||||||
class:is-panning={graphState.isPanning}
|
class:is-panning={graphState.isPanning}
|
||||||
class:is-hovering={graphState.hoveredNodeId !== -1}
|
class:is-hovering={graphState.hoveredNodeId !== -1}
|
||||||
aria-label="Graph"
|
aria-label="Graph"
|
||||||
@@ -115,6 +113,7 @@
|
|||||||
bind:clientHeight={graphState.height}
|
bind:clientHeight={graphState.height}
|
||||||
onkeydown={(ev) => keymap.handleKeyboardEvent(ev)}
|
onkeydown={(ev) => keymap.handleKeyboardEvent(ev)}
|
||||||
onmousedown={(ev) => mouseEvents.handleMouseDown(ev)}
|
onmousedown={(ev) => mouseEvents.handleMouseDown(ev)}
|
||||||
|
oncontextmenu={(ev) => mouseEvents.handleContextMenu(ev)}
|
||||||
{...fileDropEvents.getEventListenerProps()}
|
{...fileDropEvents.getEventListenerProps()}
|
||||||
>
|
>
|
||||||
<input
|
<input
|
||||||
@@ -147,20 +146,18 @@
|
|||||||
<BoxSelection
|
<BoxSelection
|
||||||
cameraPosition={graphState.cameraPosition}
|
cameraPosition={graphState.cameraPosition}
|
||||||
p1={{
|
p1={{
|
||||||
x:
|
x: graphState.cameraPosition[0]
|
||||||
graphState.cameraPosition[0] +
|
+ (graphState.mouseDown[0] - graphState.width / 2)
|
||||||
(graphState.mouseDown[0] - graphState.width / 2) /
|
/ graphState.cameraPosition[2],
|
||||||
graphState.cameraPosition[2],
|
y: graphState.cameraPosition[1]
|
||||||
y:
|
+ (graphState.mouseDown[1] - graphState.height / 2)
|
||||||
graphState.cameraPosition[1] +
|
/ graphState.cameraPosition[2]
|
||||||
(graphState.mouseDown[1] - graphState.height / 2) /
|
|
||||||
graphState.cameraPosition[2],
|
|
||||||
}}
|
}}
|
||||||
p2={{ x: graphState.mousePosition[0], y: graphState.mousePosition[1] }}
|
p2={{ x: graphState.mousePosition[0], y: graphState.mousePosition[1] }}
|
||||||
/>
|
/>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
{#if graph.status === "idle"}
|
{#if graph.status === 'idle'}
|
||||||
{#if graphState.addMenuPosition}
|
{#if graphState.addMenuPosition}
|
||||||
<AddMenu onnode={handleNodeCreation} />
|
<AddMenu onnode={handleNodeCreation} />
|
||||||
{/if}
|
{/if}
|
||||||
@@ -207,9 +204,9 @@
|
|||||||
{/each}
|
{/each}
|
||||||
</div>
|
</div>
|
||||||
</HTML>
|
</HTML>
|
||||||
{:else if graph.status === "loading"}
|
{:else if graph.status === 'loading'}
|
||||||
<span>Loading</span>
|
<span>Loading</span>
|
||||||
{:else if graph.status === "error"}
|
{:else if graph.status === 'error'}
|
||||||
<span>Error</span>
|
<span>Error</span>
|
||||||
{/if}
|
{/if}
|
||||||
</Canvas>
|
</Canvas>
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { animate, lerp } from '$lib/helpers';
|
import { animate, lerp } from '$lib/helpers';
|
||||||
import { type NodeInstance } from '@nodarium/types';
|
import { type NodeInstance } from '@nodarium/types';
|
||||||
import type { GraphManager } from '../graph-manager.svelte';
|
import type { GraphManager } from '../graph-manager.svelte';
|
||||||
import type { GraphState } from '../graph-state.svelte';
|
import { type GraphState } from '../graph-state.svelte';
|
||||||
import { snapToGrid as snapPointToGrid } from '../helpers';
|
import { snapToGrid as snapPointToGrid } from '../helpers';
|
||||||
import { maxZoom, minZoom, zoomSpeed } from './constants';
|
import { maxZoom, minZoom, zoomSpeed } from './constants';
|
||||||
import { EdgeInteractionManager } from './edge.events';
|
import { EdgeInteractionManager } from './edge.events';
|
||||||
@@ -16,7 +16,7 @@ export class MouseEventManager {
|
|||||||
this.edgeInteractionManager = new EdgeInteractionManager(graph, state);
|
this.edgeInteractionManager = new EdgeInteractionManager(graph, state);
|
||||||
}
|
}
|
||||||
|
|
||||||
handleMouseUp(event: MouseEvent) {
|
handleWindowMouseUp(event: MouseEvent) {
|
||||||
this.edgeInteractionManager.handleMouseUp();
|
this.edgeInteractionManager.handleMouseUp();
|
||||||
this.state.isPanning = false;
|
this.state.isPanning = false;
|
||||||
if (!this.state.mouseDown) return;
|
if (!this.state.mouseDown) return;
|
||||||
@@ -151,7 +151,19 @@ export class MouseEventManager {
|
|||||||
this.state.addMenuPosition = null;
|
this.state.addMenuPosition = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handleContextMenu(event: MouseEvent) {
|
||||||
|
if (!this.state.addMenuPosition) {
|
||||||
|
event.preventDefault();
|
||||||
|
this.state.openNodePalette();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
handleMouseDown(event: MouseEvent) {
|
handleMouseDown(event: MouseEvent) {
|
||||||
|
// Right click
|
||||||
|
if (event.button === 2) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (this.state.mouseDown) return;
|
if (this.state.mouseDown) return;
|
||||||
this.state.edgeEndPosition = null;
|
this.state.edgeEndPosition = null;
|
||||||
|
|
||||||
@@ -229,7 +241,7 @@ export class MouseEventManager {
|
|||||||
this.state.edgeEndPosition = null;
|
this.state.edgeEndPosition = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
handleMouseMove(event: MouseEvent) {
|
handleWindowMouseMove(event: MouseEvent) {
|
||||||
let mx = event.clientX - this.state.rect.x;
|
let mx = event.clientX - this.state.rect.x;
|
||||||
let my = event.clientY - this.state.rect.y;
|
let my = event.clientY - this.state.rect.y;
|
||||||
|
|
||||||
|
|||||||
@@ -59,9 +59,7 @@ export function setupKeymaps(keymap: Keymap, graph: GraphManager, graphState: Gr
|
|||||||
key: 'A',
|
key: 'A',
|
||||||
shift: true,
|
shift: true,
|
||||||
description: 'Add new Node',
|
description: 'Add new Node',
|
||||||
callback: () => {
|
callback: () => graphState.openNodePalette()
|
||||||
graphState.addMenuPosition = [graphState.mousePosition[0], graphState.mousePosition[1]];
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
keymap.addShortcut({
|
keymap.addShortcut({
|
||||||
|
|||||||
@@ -5,17 +5,17 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { humanizeDuration } from "$lib/helpers";
|
import { humanizeDuration } from '$lib/helpers';
|
||||||
import { localState } from "$lib/helpers/localState.svelte";
|
import { localState } from '$lib/helpers/localState.svelte';
|
||||||
import Monitor from "$lib/performance/Monitor.svelte";
|
import Monitor from '$lib/performance/Monitor.svelte';
|
||||||
import { Number } from "@nodarium/ui";
|
import { Number } from '@nodarium/ui';
|
||||||
import { writable } from "svelte/store";
|
import { writable } from 'svelte/store';
|
||||||
|
|
||||||
function calculateStandardDeviation(array: number[]) {
|
function calculateStandardDeviation(array: number[]) {
|
||||||
const n = array.length;
|
const n = array.length;
|
||||||
const mean = array.reduce((a, b) => a + b) / n;
|
const mean = array.reduce((a, b) => a + b) / n;
|
||||||
return Math.sqrt(
|
return Math.sqrt(
|
||||||
array.map((x) => Math.pow(x - mean, 2)).reduce((a, b) => a + b) / n,
|
array.map((x) => Math.pow(x - mean, 2)).reduce((a, b) => a + b) / n
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
type Props = {
|
type Props = {
|
||||||
@@ -25,21 +25,21 @@
|
|||||||
const { run }: Props = $props();
|
const { run }: Props = $props();
|
||||||
|
|
||||||
let isRunning = $state(false);
|
let isRunning = $state(false);
|
||||||
let amount = localState<number>("nodes.benchmark.samples", 500);
|
let amount = localState<number>('nodes.benchmark.samples', 500);
|
||||||
let samples = $state(0);
|
let samples = $state(0);
|
||||||
let warmUp = writable(0);
|
let warmUp = writable(0);
|
||||||
let warmUpAmount = 10;
|
let warmUpAmount = 10;
|
||||||
let status = "";
|
let status = '';
|
||||||
|
|
||||||
const copyContent = async (text?: string | number) => {
|
const copyContent = async (text?: string | number) => {
|
||||||
if (!text) return;
|
if (!text) return;
|
||||||
if (typeof text !== "string") {
|
if (typeof text !== 'string') {
|
||||||
text = (Math.floor(text * 100) / 100).toString();
|
text = (Math.floor(text * 100) / 100).toString();
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
await navigator.clipboard.writeText(text);
|
await navigator.clipboard.writeText(text);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error("Failed to copy: ", err);
|
console.error('Failed to copy: ', err);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -74,7 +74,7 @@
|
|||||||
stdev: calculateStandardDeviation(results),
|
stdev: calculateStandardDeviation(results),
|
||||||
samples: results,
|
samples: results,
|
||||||
duration: performance.now() - a,
|
duration: performance.now() - a,
|
||||||
avg: results.reduce((a, b) => a + b) / results.length,
|
avg: results.reduce((a, b) => a + b) / results.length
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
@@ -90,42 +90,43 @@
|
|||||||
<label for="bench-avg">Average </label>
|
<label for="bench-avg">Average </label>
|
||||||
<button
|
<button
|
||||||
id="bench-avg"
|
id="bench-avg"
|
||||||
onkeydown={(ev) => ev.key === "Enter" && copyContent(result?.avg)}
|
onkeydown={(ev) => ev.key === 'Enter' && copyContent(result?.avg)}
|
||||||
onclick={() => copyContent(result?.avg)}
|
onclick={() => copyContent(result?.avg)}
|
||||||
>{Math.floor(result.avg * 100) / 100}</button
|
|
||||||
>
|
>
|
||||||
|
{Math.floor(result.avg * 100) / 100}
|
||||||
|
</button>
|
||||||
<i
|
<i
|
||||||
role="button"
|
role="button"
|
||||||
tabindex="0"
|
tabindex="0"
|
||||||
onkeydown={(ev) => ev.key === "Enter" && copyContent(result?.avg)}
|
onkeydown={(ev) => ev.key === 'Enter' && copyContent(result?.avg)}
|
||||||
onclick={() => copyContent(result?.avg)}>(click to copy)</i
|
onclick={() => copyContent(result?.avg)}
|
||||||
>
|
>(click to copy)</i>
|
||||||
<label for="bench-stdev">Standard Deviation σ</label>
|
<label for="bench-stdev">Standard Deviation σ</label>
|
||||||
<button id="bench-stdev" onclick={() => copyContent(result?.stdev)}
|
<button id="bench-stdev" onclick={() => copyContent(result?.stdev)}>
|
||||||
>{Math.floor(result.stdev * 100) / 100}</button
|
{Math.floor(result.stdev * 100) / 100}
|
||||||
>
|
</button>
|
||||||
<i
|
<i
|
||||||
role="button"
|
role="button"
|
||||||
tabindex="0"
|
tabindex="0"
|
||||||
onkeydown={(ev) => ev.key === "Enter" && copyContent(result?.avg)}
|
onkeydown={(ev) => ev.key === 'Enter' && copyContent(result?.avg)}
|
||||||
onclick={() => copyContent(result?.stdev + "")}>(click to copy)</i
|
onclick={() => copyContent(result?.stdev + '')}
|
||||||
>
|
>(click to copy)</i>
|
||||||
<div>
|
<div>
|
||||||
<button onclick={() => (isRunning = false)}>reset</button>
|
<button onclick={() => (isRunning = false)}>reset</button>
|
||||||
</div>
|
</div>
|
||||||
{:else if isRunning}
|
{:else if isRunning}
|
||||||
<p>WarmUp ({$warmUp}/{warmUpAmount})</p>
|
<p>WarmUp ({$warmUp}/{warmUpAmount})</p>
|
||||||
<progress value={$warmUp} max={warmUpAmount}
|
<progress value={$warmUp} max={warmUpAmount}>
|
||||||
>{Math.floor(($warmUp / warmUpAmount) * 100)}%</progress
|
{Math.floor(($warmUp / warmUpAmount) * 100)}%
|
||||||
>
|
</progress>
|
||||||
<p>Progress ({samples}/{amount.value})</p>
|
<p>Progress ({samples}/{amount.value})</p>
|
||||||
<progress value={samples} max={amount.value}
|
<progress value={samples} max={amount.value}>
|
||||||
>{Math.floor((samples / amount.value) * 100)}%</progress
|
{Math.floor((samples / amount.value) * 100)}%
|
||||||
>
|
</progress>
|
||||||
{:else}
|
{:else}
|
||||||
<label for="bench-samples">Samples</label>
|
<label for="bench-samples">Samples</label>
|
||||||
<Number id="bench-sample" bind:value={amount.value} max={1000} />
|
<Number id="bench-sample" bind:value={amount.value} max={1000} />
|
||||||
<button onclick={benchmark} disabled={isRunning}> start </button>
|
<button onclick={benchmark} disabled={isRunning}>start</button>
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
13
flake.nix
13
flake.nix
@@ -4,7 +4,7 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
outputs = {nixpkgs, ...}: let
|
outputs = {nixpkgs, ...}: let
|
||||||
systems = ["aarch64-darwin" "x86_64-linux"];
|
systems = ["aarch64-darwin" "x86_64-darwin" "aarch64-linux" "x86_64-linux"];
|
||||||
eachSystem = function:
|
eachSystem = function:
|
||||||
nixpkgs.lib.genAttrs systems (system:
|
nixpkgs.lib.genAttrs systems (system:
|
||||||
function {
|
function {
|
||||||
@@ -19,14 +19,15 @@
|
|||||||
pkgs.nodejs_24
|
pkgs.nodejs_24
|
||||||
pkgs.pnpm_10
|
pkgs.pnpm_10
|
||||||
|
|
||||||
# wasm/rust stuff
|
# wasm stuff
|
||||||
pkgs.rustc
|
pkgs.rustc
|
||||||
pkgs.cargo
|
pkgs.cargo
|
||||||
pkgs.rust-analyzer
|
pkgs.rust-analyzer
|
||||||
pkgs.rustfmt
|
pkgs.rustfmt
|
||||||
pkgs.wasm-bindgen-cli
|
pkgs.binaryen
|
||||||
pkgs.wasm-pack
|
|
||||||
pkgs.lld
|
pkgs.lld
|
||||||
|
pkgs.zig
|
||||||
|
pkgs.zls
|
||||||
|
|
||||||
# frontend
|
# frontend
|
||||||
pkgs.vscode-langservers-extracted
|
pkgs.vscode-langservers-extracted
|
||||||
@@ -35,6 +36,10 @@
|
|||||||
pkgs.tailwindcss-language-server
|
pkgs.tailwindcss-language-server
|
||||||
pkgs.svelte-language-server
|
pkgs.svelte-language-server
|
||||||
];
|
];
|
||||||
|
|
||||||
|
shellHook = ''
|
||||||
|
unset ZIG_GLOBAL_CACHE_DIR
|
||||||
|
'';
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
2
nodes/max/plantarium/zig/.gitignore
vendored
Normal file
2
nodes/max/plantarium/zig/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
.zig-cache/
|
||||||
|
zig-out/
|
||||||
19
nodes/max/plantarium/zig/build.zig
Normal file
19
nodes/max/plantarium/zig/build.zig
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
const std = @import("std");
|
||||||
|
|
||||||
|
pub fn build(b: *std.Build) void {
|
||||||
|
const target = b.resolveTargetQuery(.{ .os_tag = .freestanding, .abi = .none, .cpu_arch = .wasm32 });
|
||||||
|
const release = b.option(bool, "release", "To build a wasm release") orelse false;
|
||||||
|
|
||||||
|
const exe = b.addExecutable(.{
|
||||||
|
.name = "zig",
|
||||||
|
.root_module = b.createModule(.{
|
||||||
|
.root_source_file = b.path("src/main.zig"),
|
||||||
|
.target = target,
|
||||||
|
.optimize = if (release) .ReleaseSmall else .Debug,
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
exe.rdynamic = true;
|
||||||
|
exe.entry = .disabled;
|
||||||
|
|
||||||
|
b.installArtifact(exe);
|
||||||
|
}
|
||||||
81
nodes/max/plantarium/zig/build.zig.zon
Normal file
81
nodes/max/plantarium/zig/build.zig.zon
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
.{
|
||||||
|
// This is the default name used by packages depending on this one. For
|
||||||
|
// example, when a user runs `zig fetch --save <url>`, this field is used
|
||||||
|
// as the key in the `dependencies` table. Although the user can choose a
|
||||||
|
// different name, most users will stick with this provided value.
|
||||||
|
//
|
||||||
|
// It is redundant to include "zig" in this name because it is already
|
||||||
|
// within the Zig package namespace.
|
||||||
|
.name = .math,
|
||||||
|
// This is a [Semantic Version](https://semver.org/).
|
||||||
|
// In a future version of Zig it will be used for package deduplication.
|
||||||
|
.version = "0.0.0",
|
||||||
|
// Together with name, this represents a globally unique package
|
||||||
|
// identifier. This field is generated by the Zig toolchain when the
|
||||||
|
// package is first created, and then *never changes*. This allows
|
||||||
|
// unambiguous detection of one package being an updated version of
|
||||||
|
// another.
|
||||||
|
//
|
||||||
|
// When forking a Zig project, this id should be regenerated (delete the
|
||||||
|
// field and run `zig build`) if the upstream project is still maintained.
|
||||||
|
// Otherwise, the fork is *hostile*, attempting to take control over the
|
||||||
|
// original project's identity. Thus it is recommended to leave the comment
|
||||||
|
// on the following line intact, so that it shows up in code reviews that
|
||||||
|
// modify the field.
|
||||||
|
.fingerprint = 0xa927044d8d610b01, // Changing this has security and trust implications.
|
||||||
|
// Tracks the earliest Zig version that the package considers to be a
|
||||||
|
// supported use case.
|
||||||
|
.minimum_zig_version = "0.15.2",
|
||||||
|
// This field is optional.
|
||||||
|
// Each dependency must either provide a `url` and `hash`, or a `path`.
|
||||||
|
// `zig build --fetch` can be used to fetch all dependencies of a package, recursively.
|
||||||
|
// Once all dependencies are fetched, `zig build` no longer requires
|
||||||
|
// internet connectivity.
|
||||||
|
.dependencies = .{
|
||||||
|
// See `zig fetch --save <url>` for a command-line interface for adding dependencies.
|
||||||
|
//.example = .{
|
||||||
|
// // When updating this field to a new URL, be sure to delete the corresponding
|
||||||
|
// // `hash`, otherwise you are communicating that you expect to find the old hash at
|
||||||
|
// // the new URL. If the contents of a URL change this will result in a hash mismatch
|
||||||
|
// // which will prevent zig from using it.
|
||||||
|
// .url = "https://example.com/foo.tar.gz",
|
||||||
|
//
|
||||||
|
// // This is computed from the file contents of the directory of files that is
|
||||||
|
// // obtained after fetching `url` and applying the inclusion rules given by
|
||||||
|
// // `paths`.
|
||||||
|
// //
|
||||||
|
// // This field is the source of truth; packages do not come from a `url`; they
|
||||||
|
// // come from a `hash`. `url` is just one of many possible mirrors for how to
|
||||||
|
// // obtain a package matching this `hash`.
|
||||||
|
// //
|
||||||
|
// // Uses the [multihash](https://multiformats.io/multihash/) format.
|
||||||
|
// .hash = "...",
|
||||||
|
//
|
||||||
|
// // When this is provided, the package is found in a directory relative to the
|
||||||
|
// // build root. In this case the package's hash is irrelevant and therefore not
|
||||||
|
// // computed. This field and `url` are mutually exclusive.
|
||||||
|
// .path = "foo",
|
||||||
|
//
|
||||||
|
// // When this is set to `true`, a package is declared to be lazily
|
||||||
|
// // fetched. This makes the dependency only get fetched if it is
|
||||||
|
// // actually used.
|
||||||
|
// .lazy = false,
|
||||||
|
//},
|
||||||
|
},
|
||||||
|
// Specifies the set of files and directories that are included in this package.
|
||||||
|
// Only files and directories listed here are included in the `hash` that
|
||||||
|
// is computed for this package. Only files listed here will remain on disk
|
||||||
|
// when using the zig package manager. As a rule of thumb, one should list
|
||||||
|
// files required for compilation plus any license(s).
|
||||||
|
// Paths are relative to the build root. Use the empty string (`""`) to refer to
|
||||||
|
// the build root itself.
|
||||||
|
// A directory listed here means that all files within, recursively, are included.
|
||||||
|
.paths = .{
|
||||||
|
"build.zig",
|
||||||
|
"build.zig.zon",
|
||||||
|
"src",
|
||||||
|
// For example...
|
||||||
|
//"LICENSE",
|
||||||
|
//"README.md",
|
||||||
|
},
|
||||||
|
}
|
||||||
27
nodes/max/plantarium/zig/src/input.json
Normal file
27
nodes/max/plantarium/zig/src/input.json
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
{
|
||||||
|
"id": "max/nodarium/zig",
|
||||||
|
"outputs": [
|
||||||
|
"float"
|
||||||
|
],
|
||||||
|
"inputs": {
|
||||||
|
"op_type": {
|
||||||
|
"label": "type",
|
||||||
|
"type": "select",
|
||||||
|
"options": [
|
||||||
|
"add",
|
||||||
|
"subtract",
|
||||||
|
"multiply",
|
||||||
|
"divide"
|
||||||
|
],
|
||||||
|
"internal": true
|
||||||
|
},
|
||||||
|
"a": {
|
||||||
|
"type": "float",
|
||||||
|
"value": 2
|
||||||
|
},
|
||||||
|
"b": {
|
||||||
|
"type": "float",
|
||||||
|
"value": 2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
29
nodes/max/plantarium/zig/src/main.zig
Normal file
29
nodes/max/plantarium/zig/src/main.zig
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
const std = @import("std");
|
||||||
|
|
||||||
|
const def = @embedFile("input.json");
|
||||||
|
|
||||||
|
export fn execute(ptr: *anyopaque, len: c_int) c_int {
|
||||||
|
_ = ptr; // autofix
|
||||||
|
_ = len; // autofix
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
export fn __alloc(len: c_int) ?*anyopaque {
|
||||||
|
if (len < 0) return null;
|
||||||
|
const mem = std.heap.wasm_allocator.alloc(u8, @intCast(len)) catch return null;
|
||||||
|
return mem.ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
export fn __free(ptr: *anyopaque, len: c_int) void {
|
||||||
|
if (len < 1) return;
|
||||||
|
const mem: [*]u8 = @ptrCast(@alignCast(ptr));
|
||||||
|
std.heap.wasm_allocator.free(mem[0..@intCast(len)]);
|
||||||
|
}
|
||||||
|
|
||||||
|
export fn getDefinitionPtr() *const anyopaque {
|
||||||
|
return def.ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
export fn getDefinitionLen() usize {
|
||||||
|
return def.len;
|
||||||
|
}
|
||||||
@@ -10,8 +10,8 @@
|
|||||||
"author": "",
|
"author": "",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@nodarium/types": "link:../types",
|
"@nodarium/types": "workspace:",
|
||||||
"@nodarium/utils": "link:../utils",
|
"@nodarium/utils": "workspace:",
|
||||||
"idb": "^8.0.3"
|
"idb": "^8.0.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,7 +30,7 @@
|
|||||||
"svelte": "^4.0.0"
|
"svelte": "^4.0.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@nodarium/types": "link:../types",
|
"@nodarium/types": "workspace:",
|
||||||
"@sveltejs/adapter-static": "^3.0.10",
|
"@sveltejs/adapter-static": "^3.0.10",
|
||||||
"@sveltejs/kit": "^2.50.0",
|
"@sveltejs/kit": "^2.50.0",
|
||||||
"@sveltejs/package": "^2.5.7",
|
"@sveltejs/package": "^2.5.7",
|
||||||
|
|||||||
@@ -1,10 +1,7 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import type { NodeInput } from '@nodarium/types';
|
import type { NodeInput } from '@nodarium/types';
|
||||||
|
|
||||||
import Checkbox from './inputs/Checkbox.svelte';
|
import { Checkbox, Number, Select, Vec3 } from './index.js';
|
||||||
import Number from './inputs/Number.svelte';
|
|
||||||
import Select from './inputs/Select.svelte';
|
|
||||||
import Vec3 from './inputs/Vec3.svelte';
|
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
input: NodeInput;
|
input: NodeInput;
|
||||||
@@ -16,7 +13,7 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#if input.type === 'float'}
|
{#if input.type === 'float'}
|
||||||
<Number bind:value min={input?.min} max={input?.max} step={0.01} />
|
<Number bind:value min={input?.min} max={input?.max} step={input?.step} />
|
||||||
{:else if input.type === 'integer'}
|
{:else if input.type === 'integer'}
|
||||||
<Number bind:value min={input?.min} max={input?.max} />
|
<Number bind:value min={input?.min} max={input?.max} />
|
||||||
{:else if input.type === 'boolean'}
|
{:else if input.type === 'boolean'}
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
export { default as Input } from './Input.svelte';
|
export { default as Input } from './Input.svelte';
|
||||||
export { default as Checkbox } from './inputs/Checkbox.svelte';
|
export { default as Checkbox } from './inputs/Checkbox.svelte';
|
||||||
export { default as Float } from './inputs/Float.svelte';
|
export { default as Float, default as Number } from './inputs/Float.svelte';
|
||||||
export { default as Integer } from './inputs/Integer.svelte';
|
export { default as Integer } from './inputs/Integer.svelte';
|
||||||
export { default as Number } from './inputs/Number.svelte';
|
|
||||||
export { default as Select } from './inputs/Select.svelte';
|
export { default as Select } from './inputs/Select.svelte';
|
||||||
export { default as Vec3 } from './inputs/Vec3.svelte';
|
export { default as Vec3 } from './inputs/Vec3.svelte';
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
let {
|
let {
|
||||||
value = $bindable(0.5),
|
value = $bindable(0.5),
|
||||||
step = 0.01,
|
step,
|
||||||
min = $bindable(0),
|
min = $bindable(0),
|
||||||
max = $bindable(1),
|
max = $bindable(1),
|
||||||
id
|
id
|
||||||
@@ -22,8 +22,11 @@
|
|||||||
max = value;
|
max = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// svelte-ignore state_referenced_locally only use initial values
|
||||||
|
const precision = ((step || value).toString().split('.')[1] || '').length;
|
||||||
|
|
||||||
function strip(input: number) {
|
function strip(input: number) {
|
||||||
return +parseFloat(input + '').toPrecision(2);
|
return +parseFloat(input + '').toFixed(precision);
|
||||||
}
|
}
|
||||||
|
|
||||||
let inputEl: HTMLInputElement | undefined = $state();
|
let inputEl: HTMLInputElement | undefined = $state();
|
||||||
@@ -94,14 +97,22 @@
|
|||||||
} else {
|
} else {
|
||||||
value = Math.max(Math.min(min + (max - min) * vx, max), min);
|
value = Math.max(Math.min(min + (max - min) * vx, max), min);
|
||||||
}
|
}
|
||||||
(ev.target as HTMLElement)?.blur();
|
|
||||||
|
value = strip(value);
|
||||||
|
|
||||||
|
// With ctrl + outside of input ev.target becomes HTMLDocument
|
||||||
|
if (ev.target instanceof HTMLElement) {
|
||||||
|
ev.target?.blur();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$effect(() => {
|
$effect(() => {
|
||||||
if ((value || 0).toString().length > 5) {
|
if (value.toString().length > 5) {
|
||||||
value = strip(value || 0);
|
value = strip(value);
|
||||||
}
|
}
|
||||||
value !== undefined && handleChange();
|
value !== undefined && handleChange();
|
||||||
});
|
});
|
||||||
|
|
||||||
let width = $derived(
|
let width = $derived(
|
||||||
Number.isFinite(value) ? Math.max((value?.toString().length ?? 1) * 8, 50) + 'px' : '20px'
|
Number.isFinite(value) ? Math.max((value?.toString().length ?? 1) * 8, 50) + 'px' : '20px'
|
||||||
);
|
);
|
||||||
@@ -137,12 +148,12 @@
|
|||||||
border-radius: var(--border-radius, 2px);
|
border-radius: var(--border-radius, 2px);
|
||||||
}
|
}
|
||||||
|
|
||||||
input[type='number']::-webkit-inner-spin-button,
|
input[type="number"]::-webkit-inner-spin-button,
|
||||||
input[type='number']::-webkit-outer-spin-button {
|
input[type="number"]::-webkit-outer-spin-button {
|
||||||
-webkit-appearance: none;
|
-webkit-appearance: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
input[type='number'] {
|
input[type="number"] {
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
-webkit-appearance: textfield;
|
-webkit-appearance: textfield;
|
||||||
-moz-appearance: textfield;
|
-moz-appearance: textfield;
|
||||||
|
|||||||
@@ -1,3 +1,8 @@
|
|||||||
|
<!--
|
||||||
|
@component
|
||||||
|
@deprecated use Float.svelte
|
||||||
|
-->
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
interface Props {
|
interface Props {
|
||||||
value?: number;
|
value?: number;
|
||||||
|
|||||||
@@ -1,177 +0,0 @@
|
|||||||
<script lang="ts">
|
|
||||||
interface Props {
|
|
||||||
value?: number;
|
|
||||||
step?: number;
|
|
||||||
min?: number;
|
|
||||||
max?: number;
|
|
||||||
id?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
let {
|
|
||||||
value = $bindable(1),
|
|
||||||
step = 1,
|
|
||||||
min = $bindable(0),
|
|
||||||
max = $bindable(1),
|
|
||||||
id: _id
|
|
||||||
}: Props = $props();
|
|
||||||
const uid = $props.id();
|
|
||||||
const id = $derived(_id || uid);
|
|
||||||
|
|
||||||
if (min > max) {
|
|
||||||
[min, max] = [max, min];
|
|
||||||
}
|
|
||||||
if (value > max) {
|
|
||||||
max = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
function strip(input: number) {
|
|
||||||
return +parseFloat(input + '').toPrecision(2);
|
|
||||||
}
|
|
||||||
|
|
||||||
let inputEl = $state() as HTMLInputElement;
|
|
||||||
|
|
||||||
let prev = -1;
|
|
||||||
function update() {
|
|
||||||
if (prev === value) return;
|
|
||||||
if (value.toString().length > 5) {
|
|
||||||
value = strip(value);
|
|
||||||
}
|
|
||||||
prev = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
function handleChange(change: number) {
|
|
||||||
value = Math.max(min ?? -Infinity, Math.min(+value + change, max ?? Infinity));
|
|
||||||
}
|
|
||||||
|
|
||||||
function handleKeyDown(ev: KeyboardEvent) {
|
|
||||||
if (ev.key === 'Escape' || ev.key === 'Enter') {
|
|
||||||
inputEl?.blur();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$effect(() => {
|
|
||||||
update();
|
|
||||||
});
|
|
||||||
|
|
||||||
let ratio = $derived(((value - min) / (max - min)) * 100);
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<div class="component-wrapper">
|
|
||||||
<button onclick={() => handleChange(-step)}>-</button>
|
|
||||||
<input
|
|
||||||
bind:value
|
|
||||||
bind:this={inputEl}
|
|
||||||
{id}
|
|
||||||
{step}
|
|
||||||
{max}
|
|
||||||
{min}
|
|
||||||
type="number"
|
|
||||||
onkeydown={handleKeyDown}
|
|
||||||
/>
|
|
||||||
<button onclick={() => handleChange(+step)}>+</button>
|
|
||||||
</div>
|
|
||||||
<div class="slider">
|
|
||||||
<input
|
|
||||||
type="range"
|
|
||||||
bind:value
|
|
||||||
{min}
|
|
||||||
{max}
|
|
||||||
{step}
|
|
||||||
style={`background: linear-gradient(90deg, var(--text-color) ${ratio}%, var(--layer-2, #4b4b4b) ${ratio}%)`}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<style>
|
|
||||||
:root {
|
|
||||||
--slider-height: 4px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.component-wrapper {
|
|
||||||
display: flex;
|
|
||||||
background-color: var(--layer-2, #4b4b4b);
|
|
||||||
user-select: none;
|
|
||||||
transition: box-shadow 0.3s ease;
|
|
||||||
border: solid 1px var(--outline);
|
|
||||||
overflow: hidden;
|
|
||||||
border-radius: 0 var(--border-radius, 2px); /* only top */
|
|
||||||
}
|
|
||||||
|
|
||||||
input[type='number']::-webkit-inner-spin-button,
|
|
||||||
input[type='number']::-webkit-outer-spin-button {
|
|
||||||
-webkit-appearance: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
input[type='number'] {
|
|
||||||
-webkit-appearance: textfield;
|
|
||||||
-moz-appearance: textfield;
|
|
||||||
appearance: textfield;
|
|
||||||
cursor: pointer;
|
|
||||||
font-family: var(--font-family);
|
|
||||||
font-variant-numeric: tabular-nums;
|
|
||||||
color: var(--text-color);
|
|
||||||
background-color: transparent;
|
|
||||||
padding: var(--padding, 6px);
|
|
||||||
font-size: 1em;
|
|
||||||
padding-inline: 10px;
|
|
||||||
text-align: center;
|
|
||||||
border: none;
|
|
||||||
border-style: none;
|
|
||||||
flex: 1;
|
|
||||||
width: 72%;
|
|
||||||
}
|
|
||||||
|
|
||||||
button {
|
|
||||||
background-color: transparent;
|
|
||||||
border: none;
|
|
||||||
cursor: pointer;
|
|
||||||
line-height: 0px;
|
|
||||||
margin: 0;
|
|
||||||
color: var(--text-color);
|
|
||||||
margin-inline: 6px;
|
|
||||||
}
|
|
||||||
|
|
||||||
div input[type='number'] {
|
|
||||||
color: var(--text-color);
|
|
||||||
background-color: transparent;
|
|
||||||
padding: var(--padding, 6px);
|
|
||||||
padding-inline: 0px;
|
|
||||||
text-align: center;
|
|
||||||
border: none;
|
|
||||||
border-style: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
.slider {
|
|
||||||
position: relative;
|
|
||||||
margin-top: -1px; /* hide edge */
|
|
||||||
}
|
|
||||||
|
|
||||||
input[type='range'] {
|
|
||||||
position: absolute;
|
|
||||||
appearance: none;
|
|
||||||
width: 100%;
|
|
||||||
height: var(--slider-height);
|
|
||||||
background: var(--layer-2, #4b4b4b);
|
|
||||||
cursor: pointer;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Thumb: for Chrome, Safari, Edge */
|
|
||||||
input[type='range']::-webkit-slider-thumb {
|
|
||||||
-webkit-appearance: none;
|
|
||||||
appearance: none;
|
|
||||||
width: 12px;
|
|
||||||
height: var(--slider-height);
|
|
||||||
background: var(--text-color);
|
|
||||||
box-shadow: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Thumb: for Firefox */
|
|
||||||
input[type='range']::-moz-range-thumb {
|
|
||||||
border: none;
|
|
||||||
width: 12px;
|
|
||||||
height: var(--slider-height);
|
|
||||||
background: var(--text-color);
|
|
||||||
box-shadow: none;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import Number from './Number.svelte';
|
import { Number } from '$lib/index.js';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
value?: any;
|
value?: any;
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import '$lib/app.css';
|
import '$lib/app.css';
|
||||||
import { Checkbox, Details, Float, Integer, Number, Select, ShortCut, Vec3 } from '$lib/index.js';
|
import { Checkbox, Details, Number, Select, ShortCut, Vec3 } from '$lib/index.js';
|
||||||
import Section from './Section.svelte';
|
import Section from './Section.svelte';
|
||||||
|
|
||||||
let intValue = $state(0);
|
let intValue = $state(0);
|
||||||
let floatValue = $state(0.2);
|
let floatValue = $state(0.2);
|
||||||
|
let float2Value = $state(0.02);
|
||||||
|
let float3Value = $state(1);
|
||||||
let vecValue = $state([0.2, 0.3, 0.4]);
|
let vecValue = $state([0.2, 0.3, 0.4]);
|
||||||
const options = ['strawberry', 'raspberry', 'chickpeas'];
|
const options = ['strawberry', 'raspberry', 'chickpeas'];
|
||||||
let selectValue = $state(0);
|
let selectValue = $state(0);
|
||||||
@@ -30,22 +32,22 @@
|
|||||||
<Select bind:value={themeIndex} options={themes}></Select>
|
<Select bind:value={themeIndex} options={themes}></Select>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<Section title="Integer" value={intValue}>
|
<Section title="Integer (step inherit)" value={intValue}>
|
||||||
<Integer bind:value={intValue} />
|
<Number bind:value={intValue} max={2} />
|
||||||
</Section>
|
</Section>
|
||||||
|
|
||||||
<Section title="Float" value={floatValue}>
|
<Section title="Float (step inherit)" value={floatValue}>
|
||||||
<Float bind:value={floatValue} />
|
|
||||||
</Section>
|
|
||||||
|
|
||||||
<Section title="Number" value={intValue}>
|
|
||||||
<Number bind:value={intValue} />
|
|
||||||
</Section>
|
|
||||||
|
|
||||||
<Section title="Number (float)" value={floatValue}>
|
|
||||||
<Number bind:value={floatValue} />
|
<Number bind:value={floatValue} />
|
||||||
</Section>
|
</Section>
|
||||||
|
|
||||||
|
<Section title="Float 2 (step inherit)" value={intValue}>
|
||||||
|
<Number bind:value={float2Value} />
|
||||||
|
</Section>
|
||||||
|
|
||||||
|
<Section title="Float (0.01 step)" value={floatValue}>
|
||||||
|
<Number bind:value={float3Value} step={0.01} max={3} />
|
||||||
|
</Section>
|
||||||
|
|
||||||
<Section title="Vec3" value={JSON.stringify(vecValue)}>
|
<Section title="Vec3" value={JSON.stringify(vecValue)}>
|
||||||
<Vec3 bind:value={vecValue} />
|
<Vec3 bind:value={vecValue} />
|
||||||
</Section>
|
</Section>
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
"author": "",
|
"author": "",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@nodarium/types": "link:../types"
|
"@nodarium/types": "workspace:"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"vite": "^7.3.1",
|
"vite": "^7.3.1",
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ interface NodariumExports extends WebAssembly.Exports {
|
|||||||
execute: (ptr: number, len: number) => number;
|
execute: (ptr: number, len: number) => number;
|
||||||
__free: (ptr: number, len: number) => void;
|
__free: (ptr: number, len: number) => void;
|
||||||
__alloc: (len: number) => number;
|
__alloc: (len: number) => number;
|
||||||
|
getDefinitionPtr: () => number;
|
||||||
|
getDefinitionLen: () => number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createWasmWrapper(buffer: ArrayBuffer) {
|
export function createWasmWrapper(buffer: ArrayBuffer) {
|
||||||
@@ -19,8 +21,8 @@ export function createWasmWrapper(buffer: ArrayBuffer) {
|
|||||||
if (!exports) return;
|
if (!exports) return;
|
||||||
const view = new Uint8Array(exports.memory.buffer, ptr, len);
|
const view = new Uint8Array(exports.memory.buffer, ptr, len);
|
||||||
console.log("RUST:", new TextDecoder().decode(view));
|
console.log("RUST:", new TextDecoder().decode(view));
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const module = new WebAssembly.Module(buffer);
|
const module = new WebAssembly.Module(buffer);
|
||||||
@@ -43,12 +45,22 @@ export function createWasmWrapper(buffer: ArrayBuffer) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function get_definition() {
|
function get_definition() {
|
||||||
const sections = WebAssembly.Module.customSections(module, "nodarium_definition");
|
|
||||||
if (sections.length > 0) {
|
|
||||||
const decoder = new TextDecoder();
|
const decoder = new TextDecoder();
|
||||||
|
const sections = WebAssembly.Module.customSections(
|
||||||
|
module,
|
||||||
|
"nodarium_definition",
|
||||||
|
);
|
||||||
|
if (sections.length > 0) {
|
||||||
const jsonString = decoder.decode(sections[0]);
|
const jsonString = decoder.decode(sections[0]);
|
||||||
return JSON.parse(jsonString);
|
return JSON.parse(jsonString);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const ptr = exports.getDefinitionPtr();
|
||||||
|
const len = exports.getDefinitionLen();
|
||||||
|
|
||||||
|
const view = new Uint8Array(exports.memory.buffer, ptr, len);
|
||||||
|
const jsonString = decoder.decode(view);
|
||||||
|
return JSON.parse(jsonString);
|
||||||
}
|
}
|
||||||
|
|
||||||
return { execute, get_definition };
|
return { execute, get_definition };
|
||||||
|
|||||||
10
pnpm-lock.yaml
generated
10
pnpm-lock.yaml
generated
@@ -70,7 +70,7 @@ importers:
|
|||||||
specifier: ^1.2.1
|
specifier: ^1.2.1
|
||||||
version: 1.2.1(tailwindcss@4.1.18)
|
version: 1.2.1(tailwindcss@4.1.18)
|
||||||
'@nodarium/types':
|
'@nodarium/types':
|
||||||
specifier: link:../packages/types
|
specifier: 'workspace:'
|
||||||
version: link:../packages/types
|
version: link:../packages/types
|
||||||
'@sveltejs/adapter-static':
|
'@sveltejs/adapter-static':
|
||||||
specifier: ^3.0.10
|
specifier: ^3.0.10
|
||||||
@@ -118,10 +118,10 @@ importers:
|
|||||||
packages/registry:
|
packages/registry:
|
||||||
dependencies:
|
dependencies:
|
||||||
'@nodarium/types':
|
'@nodarium/types':
|
||||||
specifier: link:../types
|
specifier: 'workspace:'
|
||||||
version: link:../types
|
version: link:../types
|
||||||
'@nodarium/utils':
|
'@nodarium/utils':
|
||||||
specifier: link:../utils
|
specifier: 'workspace:'
|
||||||
version: link:../utils
|
version: link:../utils
|
||||||
idb:
|
idb:
|
||||||
specifier: ^8.0.3
|
specifier: ^8.0.3
|
||||||
@@ -155,7 +155,7 @@ importers:
|
|||||||
version: 4.1.18
|
version: 4.1.18
|
||||||
devDependencies:
|
devDependencies:
|
||||||
'@nodarium/types':
|
'@nodarium/types':
|
||||||
specifier: link:../types
|
specifier: 'workspace:'
|
||||||
version: link:../types
|
version: link:../types
|
||||||
'@sveltejs/adapter-static':
|
'@sveltejs/adapter-static':
|
||||||
specifier: ^3.0.10
|
specifier: ^3.0.10
|
||||||
@@ -215,7 +215,7 @@ importers:
|
|||||||
packages/utils:
|
packages/utils:
|
||||||
dependencies:
|
dependencies:
|
||||||
'@nodarium/types':
|
'@nodarium/types':
|
||||||
specifier: link:../types
|
specifier: 'workspace:'
|
||||||
version: link:../types
|
version: link:../types
|
||||||
devDependencies:
|
devDependencies:
|
||||||
vite:
|
vite:
|
||||||
|
|||||||
Reference in New Issue
Block a user