@n3rdw1z4rd/core 0.20.0 → 0.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/dist/graph/doc.d.ts +141 -0
  2. package/dist/graph/doc.js +173 -0
  3. package/dist/graph/evaluate.d.ts +114 -0
  4. package/dist/graph/evaluate.js +319 -0
  5. package/dist/graph/index.d.ts +9 -0
  6. package/dist/graph/index.js +9 -0
  7. package/dist/graph/node.d.ts +153 -0
  8. package/dist/graph/node.js +94 -0
  9. package/dist/graph/nodes.d.ts +11 -0
  10. package/dist/graph/nodes.js +399 -0
  11. package/dist/graph/script.d.ts +56 -0
  12. package/dist/graph/script.js +98 -0
  13. package/dist/graph/sources.d.ts +11 -0
  14. package/dist/graph/sources.js +263 -0
  15. package/dist/graph/subgraph.d.ts +36 -0
  16. package/dist/graph/subgraph.js +280 -0
  17. package/dist/graph/types.d.ts +56 -0
  18. package/dist/graph/types.js +67 -0
  19. package/dist/graph.cjs +1709 -0
  20. package/dist/graph.d.cts +568 -0
  21. package/dist/index.cjs +53 -52
  22. package/dist/rng-Dhqq7owV.cjs +642 -0
  23. package/dist/{spatial-partition-3d-Ba-VBveM.cjs → spatial-partition-3d-CmSCL87Z.cjs} +19 -660
  24. package/dist/three/adaptive-grid.d.ts +43 -0
  25. package/dist/three/adaptive-grid.js +127 -0
  26. package/dist/three/ecs.d.ts +5 -3
  27. package/dist/three/ecs.js +5 -3
  28. package/dist/three/editor-camera.d.ts +93 -0
  29. package/dist/three/editor-camera.js +174 -0
  30. package/dist/three/index.d.ts +6 -1
  31. package/dist/three/index.js +6 -1
  32. package/dist/three/picking.d.ts +34 -0
  33. package/dist/three/picking.js +59 -0
  34. package/dist/three/schema.d.ts +139 -0
  35. package/dist/three/schema.js +214 -0
  36. package/dist/three/world.d.ts +192 -0
  37. package/dist/three/world.js +363 -0
  38. package/dist/three.cjs +970 -23
  39. package/dist/three.d.cts +497 -5
  40. package/dist/vite.cjs +40 -0
  41. package/dist/vite.d.cts +35 -0
  42. package/dist/vite.d.ts +35 -0
  43. package/dist/vite.js +39 -0
  44. package/package.json +21 -1
@@ -0,0 +1,568 @@
1
+ //#region src/graph/types.d.ts
2
+ /**
3
+ * Pin types. A type is a name (`number`, `vec2`, `entity`…) with a color for the editor;
4
+ * a trailing `[]` in a port declaration (`vec2[]`) makes the port a **list port** — it takes
5
+ * or produces a whole list instead of one value at a time (see {@link GraphEvaluator}).
6
+ *
7
+ * `any` connects to everything. Other compatibility is declared with `accepts`:
8
+ * `types.define('vec2', '#4ea8de', { accepts: ['number'] })` would let a number plug into a
9
+ * vec2 pin (the node then gets the number as-is — coercion is the node's business).
10
+ *
11
+ * @module
12
+ */
13
+ /** @category Graph */
14
+ export interface PortTypeDef {
15
+ name: string;
16
+ /** pin / wire color in the editor */
17
+ color: string;
18
+ /** other types that may connect into a pin of this type */
19
+ accepts: string[];
20
+ }
21
+ /** A parsed port type: `vec2[]` → `{ base: 'vec2', list: true }`. @category Graph */
22
+ export interface ParsedType {
23
+ base: string;
24
+ list: boolean;
25
+ }
26
+ /** @category Graph */
27
+ export declare function parseType(type: string): ParsedType;
28
+ /**
29
+ * Known pin types and which connect to which.
30
+ *
31
+ * @category Graph
32
+ */
33
+ export declare class TypeRegistry {
34
+ private readonly types;
35
+ constructor();
36
+ define(name: string, color: string, options?: {
37
+ accepts?: string[];
38
+ }): PortTypeDef;
39
+ get(name: string): PortTypeDef | undefined;
40
+ /** The color for a type (unknown types get `any`'s). */
41
+ color(name: string): string;
42
+ /**
43
+ * Whether an output of type `from` may connect to an input of type `to`. List-ness never
44
+ * blocks a connection: one value into a list port becomes a one-item list, and a list
45
+ * into a single-value port broadcasts.
46
+ */
47
+ canConnect(from: string, to: string): boolean;
48
+ all(): PortTypeDef[];
49
+ }
50
+ /**
51
+ * The default pin types (colors match the apparatus palette).
52
+ *
53
+ * @category Graph
54
+ */
55
+ export declare const portTypes: TypeRegistry;
56
+ //#endregion
57
+ //#region src/graph/node.d.ts
58
+ /**
59
+ * Node definitions: a node is a function with a typed interface.
60
+ *
61
+ * - **inputs** are pins wired from other nodes' outputs. An unconnected input uses the
62
+ * value set on the node in the editor (an inline widget), or its `default`.
63
+ * - **params** are settings shown as widgets on the node; they can't be wired.
64
+ * - **outputs** are what `run` returns.
65
+ *
66
+ * Built-in nodes are written in TypeScript with {@link defineNode}; script nodes are plain
67
+ * ES modules with the same exports (see {@link compileNodeScript}), so logic is code you
68
+ * write by hand and the graph only wires data between functions.
69
+ *
70
+ * ```ts
71
+ * defineNode({
72
+ * type: 'shapes/ball',
73
+ * inputs: { at: 'vec2', radius: { type: 'number', default: 8, min: 0.5 } },
74
+ * params: { color: { type: 'color', default: '#e8554e' } },
75
+ * outputs: { entity: 'entity' },
76
+ * run: ({ at, radius }, { color }) => ({ entity: { shape: 'ball', x: at.x, y: at.y, r: radius, color } }),
77
+ * });
78
+ * ```
79
+ *
80
+ * @module
81
+ */
82
+ /** How a value is edited in the editor (for params, and unconnected inputs). @category Graph */
83
+ export interface WidgetSpec {
84
+ default?: unknown;
85
+ label?: string;
86
+ min?: number;
87
+ max?: number;
88
+ step?: number;
89
+ /** choices for `enum` */
90
+ options?: readonly string[];
91
+ /** `string` params: a multi-line editor (code, text) */
92
+ multiline?: boolean;
93
+ }
94
+ /** An input or output: a type string, or a type with widget settings. @category Graph */
95
+ export type PortSpec = string | ({
96
+ type: string;
97
+ optional?: boolean;
98
+ description?: string;
99
+ /** list inputs only: accept several links, concatenated in the order they were made */
100
+ multi?: boolean;
101
+ } & WidgetSpec);
102
+ /** A param: a widget on the node. Types: number, boolean, string, color, enum, vec2. @category Graph */
103
+ export type ParamSpec = {
104
+ type: string;
105
+ description?: string;
106
+ } & WidgetSpec;
107
+ /** What `run` gets besides its inputs and params. @category Graph */
108
+ export interface RunContext {
109
+ /** the node instance's id */
110
+ nodeId: string;
111
+ /** the node's type, and its source module (if it has one) — behaviour nodes pass these on */
112
+ type: string;
113
+ source?: string;
114
+ /** while broadcasting over lists: this call's index (else 0) and the call count (else 1) */
115
+ index: number;
116
+ count: number;
117
+ /** anything the host passes to the evaluator (e.g. a seed) */
118
+ env: Record<string, unknown>;
119
+ /** seconds since play started, the last frame's duration and the frame number (all 0 outside animation) */
120
+ time: number;
121
+ dt: number;
122
+ frame: number;
123
+ }
124
+ /** @category Graph */
125
+ export type RunFn = (inputs: Record<string, any>, params: Record<string, any>, ctx: RunContext) => Record<string, unknown> | void | Promise<Record<string, unknown> | void>;
126
+ /** A node type, as declared. @category Graph */
127
+ export interface NodeSpec {
128
+ /** unique, e.g. `math/add`; the key nodes are saved with */
129
+ type: string;
130
+ title?: string;
131
+ /** for the add-node menu, e.g. `math` */
132
+ category?: string;
133
+ description?: string;
134
+ inputs?: Record<string, PortSpec>;
135
+ params?: Record<string, ParamSpec>;
136
+ outputs?: Record<string, PortSpec>;
137
+ run: RunFn;
138
+ /**
139
+ * An output node (a viewport, an exporter…): what evaluation is for. By default the
140
+ * evaluator only runs output nodes and what they depend on.
141
+ */
142
+ output?: boolean;
143
+ /**
144
+ * Re-run every frame (with `ctx.time` / `ctx.dt`) while the host animates the graph.
145
+ * The type's default; each node can switch it (`GraphNode.animate`). Default false.
146
+ */
147
+ animate?: boolean;
148
+ /**
149
+ * An equivalent ES module (see {@link compileNodeScript}): a script node's own code, or a
150
+ * built-in's code written out so it can be viewed and forked into a custom node.
151
+ */
152
+ source?: string;
153
+ }
154
+ /** @category Graph */
155
+ export interface Port extends ParsedType, WidgetSpec {
156
+ name: string;
157
+ /** as declared, e.g. `vec2[]` */
158
+ type: string;
159
+ optional: boolean;
160
+ /** accepts several links (list inputs) */
161
+ multi: boolean;
162
+ description?: string;
163
+ }
164
+ /** @category Graph */
165
+ export interface Param extends WidgetSpec {
166
+ name: string;
167
+ type: string;
168
+ description?: string;
169
+ }
170
+ /** A node type with its ports parsed. @category Graph */
171
+ export interface NodeDef {
172
+ readonly type: string;
173
+ readonly title: string;
174
+ readonly category: string;
175
+ readonly description: string;
176
+ readonly inputs: readonly Port[];
177
+ readonly params: readonly Param[];
178
+ readonly outputs: readonly Port[];
179
+ readonly run: RunFn;
180
+ readonly output: boolean;
181
+ readonly animate: boolean;
182
+ readonly source?: string;
183
+ /** bumped whenever a type is re-registered, so cached results are dropped */
184
+ readonly revision: number;
185
+ }
186
+ /**
187
+ * Checks and normalizes a node spec.
188
+ *
189
+ * @category Graph
190
+ */
191
+ export declare function defineNode(spec: NodeSpec): NodeDef;
192
+ /**
193
+ * Node types by name.
194
+ *
195
+ * @category Graph
196
+ */
197
+ export declare class NodeRegistry {
198
+ private readonly defs;
199
+ private readonly listeners;
200
+ register(spec: NodeSpec | NodeDef): NodeDef;
201
+ unregister(type: string): void;
202
+ get(type: string): NodeDef | undefined;
203
+ has(type: string): boolean;
204
+ all(): NodeDef[];
205
+ /** Called when a type is registered (or replaced) or removed; returns an unsubscribe. */
206
+ onChange(listener: (def: NodeDef, removed: boolean) => void): () => void;
207
+ }
208
+ //#endregion
209
+ //#region src/graph/doc.d.ts
210
+ /**
211
+ * The graph document: plain JSON, saved and shared as-is.
212
+ *
213
+ * ```json
214
+ * {
215
+ * "format": "n3rdw1z4rd.graph", "version": 1,
216
+ * "nodes": [{ "id": "a1", "type": "list/grid2d", "pos": [0, 0], "values": { "cols": 14 } }],
217
+ * "links": [{ "id": "l1", "from": { "node": "a1", "port": "points" }, "to": { "node": "b2", "port": "at" } }],
218
+ * "scripts": { "my/ball": "export const inputs = …" }
219
+ * }
220
+ * ```
221
+ *
222
+ * `values` holds the node's params and the values of its unconnected inputs; `scripts` holds
223
+ * the source of the script node types the graph uses, so a graph file is self-contained.
224
+ *
225
+ * @module
226
+ */
227
+ export declare const GRAPH_FORMAT = "n3rdw1z4rd.graph";
228
+ export declare const GRAPH_VERSION = 1;
229
+ /** @category Graph */
230
+ export interface GraphNode {
231
+ id: string;
232
+ type: string;
233
+ /** top-left, in graph units */
234
+ pos: [number, number];
235
+ /** set when resized (e.g. an output viewport) */
236
+ size?: [number, number];
237
+ /** params and unconnected-input values, by name */
238
+ values: Record<string, unknown>;
239
+ /** shown instead of the type's title */
240
+ title?: string;
241
+ collapsed?: boolean;
242
+ /** re-run every frame while animating (overrides the type's default) */
243
+ animate?: boolean;
244
+ /** switched off: doesn't run; downstream treats it like a failed node (skipped) */
245
+ disabled?: boolean;
246
+ }
247
+ /** @category Graph */
248
+ export interface PortRef {
249
+ node: string;
250
+ port: string;
251
+ }
252
+ /** @category Graph */
253
+ export interface GraphLink {
254
+ id: string;
255
+ from: PortRef;
256
+ to: PortRef;
257
+ }
258
+ /**
259
+ * A group: a titled, colored frame around nodes. Purely visual — the evaluator ignores it;
260
+ * the nodes "in" a group are the ones inside its rectangle.
261
+ *
262
+ * @category Graph
263
+ */
264
+ export interface GraphGroup {
265
+ id: string;
266
+ title: string;
267
+ color: string;
268
+ /** x, y, width, height in graph units */
269
+ rect: [number, number, number, number];
270
+ }
271
+ /**
272
+ * A subgraph node type: an inner graph plus its interface. Each input feeds one or more inner
273
+ * input ports; each output reads one inner output port.
274
+ *
275
+ * @category Graph
276
+ */
277
+ export interface SubgraphDef {
278
+ title: string;
279
+ nodes: GraphNode[];
280
+ links: GraphLink[];
281
+ groups?: GraphGroup[];
282
+ inputs: {
283
+ name: string;
284
+ type: string;
285
+ multi?: boolean;
286
+ to: PortRef[];
287
+ }[];
288
+ outputs: {
289
+ name: string;
290
+ type: string;
291
+ from: PortRef;
292
+ }[];
293
+ }
294
+ /** @category Graph */
295
+ export interface GraphDoc {
296
+ format: typeof GRAPH_FORMAT;
297
+ version: number;
298
+ nodes: GraphNode[];
299
+ links: GraphLink[];
300
+ /** script node type → ES module source */
301
+ scripts?: Record<string, string>;
302
+ /** frames around nodes (visual only) */
303
+ groups?: GraphGroup[];
304
+ /** subgraph node types: type → definition (see subgraph.ts) */
305
+ subgraphs?: Record<string, SubgraphDef>;
306
+ meta?: Record<string, unknown>;
307
+ }
308
+ /** @category Graph */
309
+ export declare function createGraph(): GraphDoc;
310
+ /** A short id, unique within a graph (random part + counter). @category Graph */
311
+ export declare function graphId(prefix?: string): string;
312
+ /** Checks a parsed JSON value is a graph document and fills in missing optional parts. @category Graph */
313
+ export declare function normalizeGraph(raw: unknown): GraphDoc;
314
+ /** @category Graph */
315
+ export declare function getNode(doc: GraphDoc, id: string): GraphNode | undefined;
316
+ /** The link into an input, if any (the first, for a multi input). @category Graph */
317
+ export declare function linkInto(doc: GraphDoc, node: string, port: string): GraphLink | undefined;
318
+ /** Every link into an input, in the order they were made. @category Graph */
319
+ export declare function linksInto(doc: GraphDoc, node: string, port: string): GraphLink[];
320
+ /** Adds a node of `def`'s type with its default values. @category Graph */
321
+ export declare function addNode(doc: GraphDoc, def: NodeDef, pos?: [number, number], values?: Record<string, unknown>): GraphNode;
322
+ /** Removes a node and every link to or from it. @category Graph */
323
+ export declare function removeNode(doc: GraphDoc, id: string): void;
324
+ /** @category Graph */
325
+ export type ConnectCheck = {
326
+ ok: true;
327
+ } | {
328
+ ok: false;
329
+ reason: string;
330
+ };
331
+ /**
332
+ * Whether `from` (an output) may connect to `to` (an input): both exist, the types fit,
333
+ * and it wouldn't make a cycle. An input's existing link doesn't block (it gets replaced).
334
+ *
335
+ * @category Graph
336
+ */
337
+ export declare function canConnect(doc: GraphDoc, registry: NodeRegistry, from: PortRef, to: PortRef, types?: TypeRegistry): ConnectCheck;
338
+ /**
339
+ * Connects an output to an input; throws if it can't. A plain input's existing link is
340
+ * replaced; a multi input keeps its links and adds this one (an identical link isn't doubled).
341
+ *
342
+ * @category Graph
343
+ */
344
+ export declare function connect(doc: GraphDoc, registry: NodeRegistry, from: PortRef, to: PortRef, types?: TypeRegistry): GraphLink;
345
+ /** @category Graph */
346
+ export declare function disconnect(doc: GraphDoc, linkId: string): void;
347
+ //#endregion
348
+ //#region src/graph/evaluate.d.ts
349
+ /**
350
+ * Evaluates a graph: runs the nodes the outputs depend on, in dependency order, passing
351
+ * values along the links.
352
+ *
353
+ * - **Lazy:** only output nodes (`output: true`) and what they depend on run, unless you
354
+ * name other targets.
355
+ * - **Memoized:** a node re-runs only when its params / input values, an upstream result or
356
+ * its type changed since the last evaluation; otherwise its previous outputs are reused.
357
+ * - **List broadcasting:** a list wired into a single-value input runs the node once per
358
+ * item (several lists: longest wins, shorter ones repeat their last item) and every
359
+ * output becomes a list. A list port (`vec2[]`) takes the whole list instead; one value
360
+ * wired into it arrives as a one-item list. A list output of a broadcast node is
361
+ * flattened into the result list.
362
+ * - **Animation (optional):** a node with `animate` on (per node, or its type's default)
363
+ * re-runs on every evaluation that passes a new `frame`, and so does everything downstream
364
+ * of it; the rest stays cached. {@link GraphEvaluator.animated} tells the host whether any
365
+ * output depends on an animated node — if not, there's nothing to re-evaluate per frame.
366
+ * - **Disabled nodes** (`GraphNode.disabled`) don't run; downstream they count as failed
367
+ * (blocked, or left out of a multi input).
368
+ * - **Errors stay local:** a throwing node gets an `error`; nodes downstream of it are
369
+ * `blocked` (skipped) and don't run; the rest of the graph still evaluates. A **multi**
370
+ * input leaves failed sources out instead (listed in `skipped`), so one broken branch
371
+ * doesn't take down everything it feeds into.
372
+ *
373
+ * Nodes must treat their inputs as read-only: values are shared with upstream caches.
374
+ *
375
+ * @category Graph
376
+ */
377
+ export declare class GraphEvaluator {
378
+ readonly registry: NodeRegistry;
379
+ private readonly cache;
380
+ private stamp;
381
+ constructor(registry: NodeRegistry);
382
+ /** The last result of a node. */
383
+ result(nodeId: string): NodeResult | undefined;
384
+ /** Forgets cached results (all, or one node's), so they re-run next time. */
385
+ invalidate(nodeId?: string): void;
386
+ /** The animated nodes the outputs (or `targets`) depend on; empty: no need to evaluate per frame. */
387
+ animated(doc: GraphDoc, targets?: string[]): string[];
388
+ evaluate(doc: GraphDoc, options?: EvaluateOptions): Promise<EvaluateResult>;
389
+ private defaultTargets;
390
+ /** Dependency order (upstream first) of the targets and everything they depend on. */
391
+ private order;
392
+ private run;
393
+ private store;
394
+ }
395
+ /** @category Graph */
396
+ export interface EvaluateOptions {
397
+ /** nodes to evaluate (with their dependencies); default: the output nodes, or every node if there are none */
398
+ targets?: string[];
399
+ /** passed to every node as `ctx.env` (not part of the cache key: `invalidate()` when it changes) */
400
+ env?: Record<string, unknown>;
401
+ /** the current frame while animating: animated nodes re-run when it changes */
402
+ frame?: FrameInfo;
403
+ /**
404
+ * Values for inputs that have no link, by `"<node>:<port>"` — how a subgraph's inputs
405
+ * reach its inner nodes. Bump `externalsStamp` when they change.
406
+ */
407
+ externals?: Map<string, {
408
+ value: unknown;
409
+ list: boolean;
410
+ }[]>;
411
+ externalsStamp?: number;
412
+ /** prefixes `ctx.nodeId` (`<scope>/<id>`), so instances of a subgraph make distinct ids */
413
+ scope?: string;
414
+ }
415
+ /**
416
+ * A key a node's `run` may add to its result: `{ [OUTPUT_LISTS]: { out: true } }` marks outputs
417
+ * as lists regardless of their declared type.
418
+ *
419
+ * @category Graph
420
+ */
421
+ export declare const OUTPUT_LISTS = "__lists";
422
+ /** @category Graph */
423
+ export interface FrameInfo {
424
+ /** seconds since animation started */
425
+ time: number;
426
+ /** seconds since the last frame */
427
+ dt: number;
428
+ /** frame number */
429
+ frame: number;
430
+ }
431
+ /** @category Graph */
432
+ export interface NodeResult {
433
+ /** output values by port name */
434
+ outputs: Record<string, unknown>;
435
+ /** which outputs are lists */
436
+ lists: Record<string, boolean>;
437
+ /** the node threw (or couldn't run) */
438
+ error?: string;
439
+ /** switched off by the user: didn't run */
440
+ disabled?: boolean;
441
+ /** an upstream node failed, was blocked or is disabled, so this one didn't run: its id */
442
+ blocked?: string;
443
+ /** multi inputs only: sources that failed and were left out (the node still ran) */
444
+ skipped?: string[];
445
+ /** time spent in run(), ms */
446
+ ms: number;
447
+ /** changes whenever the node actually re-ran */
448
+ stamp: number;
449
+ }
450
+ /** @category Graph */
451
+ export interface EvaluateResult {
452
+ /** every evaluated node, upstream first */
453
+ order: string[];
454
+ /** the nodes that actually ran (the rest reused cached results) */
455
+ ran: string[];
456
+ results: Map<string, NodeResult>;
457
+ }
458
+ //#endregion
459
+ //#region src/graph/nodes.d.ts
460
+ /** @category Graph */
461
+ export declare const BUILTIN_NODES: NodeSpec[];
462
+ /**
463
+ * A registry with the built-in nodes.
464
+ *
465
+ * @category Graph
466
+ */
467
+ export declare function createNodeRegistry(): NodeRegistry;
468
+ //#endregion
469
+ //#region src/graph/script.d.ts
470
+ /**
471
+ * Script nodes: a node type written as a plain ES module, compiled at runtime.
472
+ *
473
+ * ```js
474
+ * export const title = 'Ball'; // optional: title, category, description, output, animate
475
+ * export const inputs = { at: 'vec2', radius: { type: 'number', default: 8 } };
476
+ * export const params = { color: { type: 'color', default: '#e8554e' } };
477
+ * export const outputs = { entity: 'entity' };
478
+ * export function run({ at, radius }, { color }, ctx) {
479
+ * return { entity: { shape: 'ball', x: at.x, y: at.y, r: radius, color } };
480
+ * }
481
+ * ```
482
+ *
483
+ * The module is imported from a `data:` URL, which works in browsers, workers and Node.
484
+ * It runs with the page's (or worker's) privileges — treat shared scripts as untrusted and
485
+ * evaluate them in a worker.
486
+ *
487
+ * @module
488
+ */
489
+ /**
490
+ * Compiles a script node's source into a node type named `type`.
491
+ *
492
+ * @category Graph
493
+ */
494
+ export declare function compileNodeScript(type: string, source: string): Promise<NodeDef>;
495
+ /**
496
+ * A behaviour: what a behaviour node evaluates to. The host runs `source`'s `step` (and
497
+ * `setup`) against whatever it's attached to, with `params`.
498
+ *
499
+ * @category Graph
500
+ */
501
+ export interface BehaviorValue {
502
+ kind: 'behavior';
503
+ /** the behaviour node's type */
504
+ type: string;
505
+ /** the node instance (for error reports) */
506
+ node: string;
507
+ /** its inputs and params at evaluation time */
508
+ params: Record<string, unknown>;
509
+ /** the module with step / setup */
510
+ source: string;
511
+ }
512
+ /**
513
+ * The `run` of a behaviour node: packs its inputs, params and source into a {@link BehaviorValue}
514
+ * on the `behavior` output. Behaviour modules (exporting `step`, no `run`) get it automatically.
515
+ *
516
+ * @category Graph
517
+ */
518
+ export declare function behaviorRun(inputs: Record<string, unknown>, params: Record<string, unknown>, ctx: RunContext): {
519
+ behavior: BehaviorValue;
520
+ };
521
+ /** A starting point for a new script node. @category Graph */
522
+ export declare const SCRIPT_NODE_TEMPLATE = "// A node is a function with a typed interface.\n// inputs: pins wired from other nodes (an unconnected one uses its widget value / default)\n// params: widgets on the node\n// outputs: what run() returns\n// A \"type[]\" pin takes (or gives) a whole list; a list wired into a plain pin runs\n// run() once per item and collects the results into lists.\n\nexport const inputs = {\n a: { type: 'number', default: 1 },\n b: { type: 'number', default: 2 },\n};\n\nexport const params = {\n scale: { type: 'number', default: 1, min: 0, max: 10, step: 0.1 },\n};\n\nexport const outputs = {\n result: 'number',\n};\n\nexport function run({ a, b }, { scale }, ctx) {\n return { result: (a + b) * scale };\n}\n";
523
+ //#endregion
524
+ //#region src/graph/sources.d.ts
525
+ /**
526
+ * The built-in nodes as script modules: the same interface and behaviour as the TypeScript
527
+ * definitions in `nodes.ts`, written self-contained so the editor can show a built-in's code
528
+ * and fork it into a custom node. A test compiles each one and checks it matches.
529
+ *
530
+ * @module
531
+ */
532
+ /** @category Graph */
533
+ export declare const BUILTIN_SOURCES: Record<string, string>;
534
+ //#endregion
535
+ //#region src/graph/subgraph.d.ts
536
+ /**
537
+ * Subgraphs: a selection of nodes collapsed into one node type. The inner graph is stored in
538
+ * `doc.subgraphs[type]` with its interface — every wire that crossed the selection's edge
539
+ * became an input or output. A subgraph node evaluates its inner graph (with its own cache per
540
+ * instance), feeding the inner ports from its inputs.
541
+ *
542
+ * @module
543
+ */
544
+ /** The node spec for a subgraph type: runs the inner graph. */
545
+ export declare function subgraphSpec(type: string, def: SubgraphDef, registry: NodeRegistry): NodeSpec;
546
+ /**
547
+ * Registers (or updates) every subgraph type a document defines. Unchanged definitions are
548
+ * left alone (so their nodes keep their caches). Definitions may use each other.
549
+ */
550
+ export declare function registerSubgraphs(doc: GraphDoc, registry: NodeRegistry): void;
551
+ /** A free type name for a subgraph (`subgraph/name`, `subgraph/name-2`, …). */
552
+ export declare function freeSubgraphType(doc: GraphDoc, registry: NodeRegistry, name: string): string;
553
+ /**
554
+ * Collapses nodes into a new subgraph type and puts one node of it in their place, wired to
555
+ * everything they were wired to. Output nodes (like a viewport) can't go into a subgraph.
556
+ */
557
+ export declare function collapseToSubgraph(doc: GraphDoc, registry: NodeRegistry, nodeIds: string[], title?: string): {
558
+ type: string;
559
+ node: GraphNode;
560
+ };
561
+ /**
562
+ * Replaces a subgraph node with a copy of its inner nodes (fresh ids), wired as the
563
+ * subgraph's inputs and outputs were. Returns the new node ids. The type stays defined.
564
+ * `defs`: where the definitions are (default: `doc.subgraphs`; pass the top-level document's
565
+ * when `doc` is itself a subgraph's inner graph).
566
+ */
567
+ export declare function expandSubgraph(doc: GraphDoc, nodeId: string, defs?: Record<string, SubgraphDef> | undefined): string[];
568
+ //#endregion