@react-three/tsl 10.0.0-canary.04087d8 → 10.0.0-canary.0aed646

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.
package/dist/index.d.cts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { RootState, useStore } from '@react-three/fiber/extension';
2
2
  import * as three_webgpu from 'three/webgpu';
3
3
  import { Node, StorageTexture, Storage3DTexture, StorageArrayTexture, Data3DTexture, RenderPipeline, Vector2, Vector3, Vector4, Color, Matrix2, Matrix3, Matrix4 } from 'three/webgpu';
4
+ import { Fn } from 'three/tsl';
4
5
 
5
6
  //* Buffer Types (useBuffers) ========================================
6
7
 
@@ -57,6 +58,40 @@ type NodeRecord<T extends NodeLike = NodeLike> = Record<string, T>
57
58
  */
58
59
  type NodeStore = Record<string, NodeLike | NodeRecord>
59
60
 
61
+ /** What `Fn()` returns (its members are what matters here, not its signature). */
62
+ type FnNodeLike = ReturnType<typeof Fn>
63
+
64
+ /**
65
+ * What an unregistered node read is: `useNodes().wobble`, `useNodes('fx').blur`, a creator's
66
+ * `nodes.wobble`, `state.nodes.wobble` in `useFrame`.
67
+ *
68
+ * Why it is loose: the read goes through a string name, and TypeScript cannot know what the entry
69
+ * under that name holds: a float, a vec3, a texture sample, or an `Fn()` to call. three's types
70
+ * only give operator methods to a node whose node type is known, and only an `Fn()` can be called,
71
+ * so the broad `NodeLike` allowed neither and every read needed a cast.
72
+ *
73
+ * So this has every member that any of three's nodes or an `Fn()` has, each typed `any`, and can
74
+ * be called. `nodes.wobble.mul(2)`, `material.colorNode = nodes.wobble` and `nodes.rimLightFn()`
75
+ * compile, and a misspelt member is still an error. It is a deliberate simplification: results of
76
+ * its own methods and calls are `any`.
77
+ *
78
+ * A single `as` gives it an exact type: `nodes.wobble as Node<'vec3'>`, `nodes.fn as typeof fn`.
79
+ * For exact types without casts, register the nodes (`nodes` / `nodeScopes` in `Register`) or pass
80
+ * a schema to the reader: `useNodes<{ blur: Node<'vec4'> }>('fx')`, `nodes.scope<Schema>('fx')`.
81
+ */
82
+ interface LooseNode extends TSLLooseMembers<Node<TSLNodeTypeName> | FnNodeLike> {
83
+ (...args: any[]): any
84
+ }
85
+
86
+ /**
87
+ * A root entry of an unregistered node map: a node (its members) or a scope of nodes (any other
88
+ * name), since the type cannot tell which a name holds.
89
+ */
90
+ type LooseNodeEntry = LooseNode & { readonly [name: string]: LooseNode }
91
+
92
+ /** An unregistered node map read: `state.nodes`, `useNodes()`. */
93
+ type LooseNodeStore = Record<string, LooseNodeEntry>
94
+
60
95
  //* Storage Types (useGPUStorage) ========================================
61
96
 
62
97
  /**
@@ -93,17 +128,23 @@ type StorageStore = Record<string, StorageLike | StorageRecord>
93
128
  */
94
129
  interface TSLRootState {
95
130
  /**
96
- * TSL uniform nodes - root-level uniforms + scoped sub-objects. Use useUniforms(). Typed by name
97
- * once you register them (see `Register`), so `useFrame(({ uniforms }) => uniforms.uTime.value)`
98
- * needs no cast.
131
+ * TSL uniform nodes - root-level uniforms + scoped sub-objects. Use useUniforms(). Each read is a
132
+ * `LooseUniformNode`, usable without casts, or typed by name once you register them (see
133
+ * `Register`), so `useFrame(({ uniforms }) => uniforms.uTime.value)` needs no cast either way.
99
134
  */
100
135
  uniforms: AppUniforms
101
- /** TSL nodes - root-level nodes + scoped sub-objects. Use useNodes() */
102
- nodes: NodeStore
103
- /** Buffers - root-level buffers + scoped sub-objects. Use useBuffers() */
104
- buffers: BufferStore
105
- /** GPU storage (textures, etc.) - root-level storage + scoped sub-objects. Use useGPUStorage() */
106
- gpuStorage: StorageStore
136
+ /**
137
+ * TSL nodes - root-level nodes + scoped sub-objects. Use useNodes(). Each read is a `LooseNode`,
138
+ * usable without casts, or typed by name once you register your nodes (see `Register`).
139
+ */
140
+ nodes: AppNodes
141
+ /** Buffers - root-level buffers + scoped sub-objects. Use useBuffers(). Typed by name once registered */
142
+ buffers: AppBuffers
143
+ /**
144
+ * GPU storage (textures, etc.) - root-level storage + scoped sub-objects. Use useGPUStorage().
145
+ * Typed by name once registered
146
+ */
147
+ gpuStorage: AppGPUStorage
107
148
  /** Internal: bumped by hot reloads and rebuilds to re-run creators */
108
149
  _hmrVersion: number
109
150
  /** The canvas's RenderPipeline, once useRenderPipeline created one. Per canvas, not shared. */
@@ -113,17 +154,11 @@ interface TSLRootState {
113
154
  }
114
155
 
115
156
  // Every fiber entry shares one core, and so one RootState: augmenting it through the root entry
116
- // reaches /legacy, /webgpu and /extension as well.
157
+ // reaches /legacy and /extension as well.
117
158
  declare module '@react-three/fiber' {
118
159
  interface RootState extends TSLRootState {}
119
160
  }
120
161
 
121
- // /webgpu exports WebGPURootState as RootState. Augmenting the base state it extends reaches both,
122
- // and also the stores (useStore(), get(), primaryStore) typed with the base.
123
- declare module '@react-three/fiber/webgpu' {
124
- interface BaseRootState extends TSLRootState {}
125
- }
126
-
127
162
  declare module '@react-three/fiber/extension' {
128
163
  interface RootState extends TSLRootState {}
129
164
  }
@@ -233,6 +268,69 @@ declare global {
233
268
  */
234
269
  type UniformStore = Record<string, UniformNode | UniformRecord>
235
270
 
271
+ //* Loose reads ==============================
272
+
273
+ /** Every shader node type three's TSL declarations type separately. */
274
+ type TSLNodeTypeName =
275
+ | 'float'
276
+ | 'int'
277
+ | 'uint'
278
+ | 'bool'
279
+ | 'vec2'
280
+ | 'vec3'
281
+ | 'vec4'
282
+ | 'ivec2'
283
+ | 'ivec3'
284
+ | 'ivec4'
285
+ | 'uvec2'
286
+ | 'uvec3'
287
+ | 'uvec4'
288
+ | 'bvec2'
289
+ | 'bvec3'
290
+ | 'bvec4'
291
+ | 'color'
292
+ | 'mat2'
293
+ | 'mat3'
294
+ | 'mat4'
295
+
296
+ /** Every member of every constituent of `T`, each typed `any`. */
297
+ type TSLLooseMembers<T> = { [K in T extends unknown ? keyof T : never]: any }
298
+
299
+ /**
300
+ * What an unregistered uniform read is: `useUniforms().uTime`, `useUniforms('fx').blur`,
301
+ * `useUniform('uTime')`, a creator's `uniforms.uTime`, `state.uniforms.uTime` in `useFrame`.
302
+ *
303
+ * Why it is loose: the read goes through a string name, and TypeScript cannot know what a
304
+ * runtime entry under that name holds. three's types only give the operator methods (`.mul`,
305
+ * `.add`, swizzles, `.toVar()`, ...) to a node whose node type is known, so `UniformNode<unknown>`
306
+ * had none of them and every read needed a cast.
307
+ *
308
+ * So this has every member that any of three's uniform nodes has (float, vec3, color, mat4, ...),
309
+ * each typed `any`. Every operator, TSL function and material slot accepts it, and a misspelt member
310
+ * (`.valeu`) is still an error. It is a deliberate simplification: results of its own methods are
311
+ * `any`, and nothing checks that `cross()` gets a vec3.
312
+ *
313
+ * It converts to an exact type with a single `as`, since every member is `any`:
314
+ * `uniforms.uColor as UniformNode<'color', Color>`, or `as Node<'vec3'>`. A node typed as a float
315
+ * uniform would cover the operators with exact result types, but three's node types are not
316
+ * comparable to one another, so it could only be cast through `unknown`.
317
+ *
318
+ * Exact types without casts: register the uniforms (`Register` in `@react-three/tsl`, which also
319
+ * catches typos in the name), or pass a schema to the reader (`useUniforms<{ blur: number }>('fx')`,
320
+ * `useUniform<Color>('uColor')`, `uniforms.scope<{ uHealth: UniformNode<'float', number> }>('player')`).
321
+ */
322
+ interface LooseUniformNode extends TSLLooseMembers<three_webgpu.UniformNode<TSLNodeTypeName, any>> {}
323
+
324
+ /**
325
+ * A root entry of an unregistered uniform map: a uniform (its members) or a scope of uniforms (any
326
+ * other name), since the type cannot tell which a name holds. `uniforms.uTime.mul(2)` and
327
+ * `uniforms.player.uHealth` both read.
328
+ */
329
+ type LooseUniformEntry = LooseUniformNode & { readonly [name: string]: LooseUniformNode }
330
+
331
+ /** An unregistered uniform map read: `state.uniforms`, `useUniforms()`. */
332
+ type LooseUniformStore = Record<string, LooseUniformEntry>
333
+
236
334
  /**
237
335
  * Helper to safely access a uniform node from the store.
238
336
  * Use this when accessing state.uniforms to get proper typing.
@@ -314,13 +412,18 @@ declare global {
314
412
  /**
315
413
  * State passed to pipeline callbacks after the active pipeline has been created.
316
414
  *
415
+ * The same state `useNodes` / `useLocalNodes` creators get: `uniforms`, `nodes`, `buffers`,
416
+ * `gpuStorage` and `textures` are the wrapped views, entries staged earlier in the render
417
+ * included. Reads through them are tracked, so a read resource that appears, is replaced or is
418
+ * removed re-runs the callbacks.
419
+ *
317
420
  * `passes.scenePass` is required here: the hook installs the default scene pass before either
318
421
  * callback runs, so callbacks can use it without a guard or a cast.
319
422
  *
320
423
  * `renderer` is narrowed to `WebGPURenderer` and `isLegacy` to `false`: the hook throws under
321
424
  * the legacy renderer before either callback can run, so a callback never sees WebGL.
322
425
  */
323
- type RenderPipelineCallbackState = RootState & {
426
+ type RenderPipelineCallbackState = CreatorState & {
324
427
  renderPipeline: ThreeRenderPipeline
325
428
  passes: PassRecord & { scenePass: ScenePassNode }
326
429
  renderer: three_webgpu.WebGPURenderer
@@ -331,7 +434,7 @@ declare global {
331
434
  * What a callback may return to register entries into `state.passes`.
332
435
  *
333
436
  * `scenePass` is reserved. The hook owns that entry and its lifecycle: it caches the pass it
334
- * created, and `rebuild()` / `reset()` dispose that cached pass. A callback overwriting the
437
+ * created, and `rebuild()`, `reset()` and unmount dispose that cached pass. A callback overwriting the
335
438
  * store entry would leave the store pointing at a node the hook never disposes, and the hook
336
439
  * disposing a pass nothing references. So returning it is a type error.
337
440
  */
@@ -343,15 +446,31 @@ declare global {
343
446
  /** Main callback - runs second to configure outputNode, create effect passes */
344
447
  type RenderPipelineMainCallback = (state: RenderPipelineCallbackState) => RegisteredPasses | void
345
448
 
449
+ /** Options for a configuring useRenderPipeline call */
450
+ interface RenderPipelineOptions {
451
+ /**
452
+ * Keep the pipeline rendering after the component unmounts, until another component configures
453
+ * the canvas's pipeline, `reset()`, or the canvas unmounts. Off by default: an owner frees its
454
+ * pipeline and scene pass when it unmounts. A remount is a new owner with a new pipeline either way.
455
+ */
456
+ persist?: boolean
457
+ }
458
+
346
459
  /** The imperative half of useRenderPipeline's return value, present in every state */
347
460
  interface UseRenderPipelineActions {
348
461
  /** Current passes from state */
349
462
  passes: PassRecord
350
- /** Clear all passes from state */
463
+ /** Clear the passes record. From a reader, acts on the pipeline that is rendering. */
351
464
  clearPasses: () => void
352
- /** Reset RenderPipeline entirely (clears PP + passes) */
465
+ /**
466
+ * Free the pipeline and its scene pass now. The previous owner takes over, or the canvas
467
+ * goes back to plain rendering. From a reader, acts on the pipeline that is rendering.
468
+ */
353
469
  reset: () => void
354
- /** Re-run setup/main callbacks with current closure values */
470
+ /**
471
+ * Re-run setup/main callbacks with current closure values, against a fresh scene pass. From
472
+ * a reader, rebuilds the pipeline that is rendering.
473
+ */
355
474
  rebuild: () => void
356
475
  }
357
476
 
@@ -371,9 +490,9 @@ declare global {
371
490
  renderPipeline: ThreeRenderPipeline
372
491
  }
373
492
  | {
374
- /** False until the pipeline has been created */
493
+ /** False until a configuring call has created the pipeline */
375
494
  isReady: false
376
- /** Not initialized yet, or torn down by reset() */
495
+ /** No owner yet, or torn down by reset() or the owner unmounting */
377
496
  renderPipeline: null
378
497
  }
379
498
  )
@@ -395,13 +514,14 @@ type ResourceLeafGuard<T> = (value: unknown) => value is T;
395
514
  *
396
515
  * @example
397
516
  * ```tsx
398
- * // With uniforms registered (see `Register` and the Typed Uniforms guide), reads are typed by name
517
+ * // With uniforms registered (see `Register` and the Typed Resources guide), reads are typed by name
399
518
  * useLocalNodes(({ uniforms }) => ({
400
519
  * wobble: sin(uniforms.uTime.mul(2)),
401
520
  * playerHealth: uniforms.scope('player').uHealth, // or uniforms.player.uHealth
402
521
  * }), [])
403
522
  *
404
- * // Without registration, give a scope its schema
523
+ * // Without registration a read is loose: TSL takes it as is. A scope schema makes it exact.
524
+ * useLocalNodes(({ uniforms }) => ({ wobble: sin(uniforms.uTime.mul(2)) }), [])
405
525
  * useLocalNodes(({ uniforms }) => {
406
526
  * const player = uniforms.scope<{ uHealth: UniformNode<'float', number> }>('player')
407
527
  * return { damage: player.uHealth.mul(2) }
@@ -414,16 +534,19 @@ type ResourceLeafGuard<T> = (value: unknown) => value is T;
414
534
  * Property access returns `T` (assumes leaf node).
415
535
  * Use `.scope(key)` for nested object access.
416
536
  *
537
+ * `TLeaf` is what a scope schema must hold (`scope<{ uHealth: UniformNode<'float', number> }>()`),
538
+ * `TRead` what a leaf reads as without one. They differ for uniforms and nodes, whose unregistered
539
+ * reads are the loose `LooseUniformNode` / `LooseNode` (see those types for why).
417
540
  */
418
- type ScopedStoreMethods<TLeaf> = {
541
+ type ScopedStoreMethods<TLeaf, TRead extends TLeaf = TLeaf> = {
419
542
  /** Access a nested scope by key. Returns empty wrapper if scope doesn't exist. */
420
- scope<TScope extends Record<string, TLeaf> = Record<string, TLeaf>>(key: string): ScopedStoreType<TLeaf, TScope>;
543
+ scope<TScope extends Record<string, TLeaf> = Record<string, TRead>>(key: string): ScopedStoreType<TLeaf, TScope, TRead>;
421
544
  /** Check if a key exists in the store */
422
545
  has(key: string): boolean;
423
546
  /** Get all keys in the store */
424
547
  keys(): string[];
425
548
  };
426
- type ScopedStoreType<TLeaf, TEntries extends Record<string, TLeaf> = Record<string, TLeaf>> = Readonly<TEntries> & ScopedStoreMethods<TLeaf>;
549
+ type ScopedStoreType<TLeaf, TEntries extends Record<string, TLeaf> = Record<string, TLeaf>, TRead extends TLeaf = TLeaf> = Readonly<TEntries> & ScopedStoreMethods<TLeaf, TRead>;
427
550
  interface ScopedStoreData<TLeaf> {
428
551
  [key: string]: TLeaf | ScopedStoreData<TLeaf>;
429
552
  }
@@ -440,18 +563,18 @@ declare function createScopedStore<TLeaf>(data: ScopedStoreData<TLeaf>, isLeaf:
440
563
  type CreatorState = Omit<RootState, 'uniforms' | 'nodes' | 'buffers' | 'gpuStorage'> & {
441
564
  /** Type-safe uniform access - property access returns UniformNode, typed by name when registered */
442
565
  uniforms: CreatorUniforms;
443
- /** Type-safe node access for real, callable, and legacy structural nodes */
444
- nodes: ScopedStoreType<NodeLike>;
445
- /** Type-safe buffer access - property access returns BufferLike (TypedArrays, BufferAttributes, TSL nodes) */
446
- buffers: ScopedStoreType<BufferLike>;
447
- /** Type-safe GPU storage access - property access returns StorageLike (StorageTexture, TSL nodes) */
448
- gpuStorage: ScopedStoreType<StorageLike>;
566
+ /** Node access: each read a `LooseNode` (callable, every operator), typed by name when registered */
567
+ nodes: CreatorNodes;
568
+ /** Buffer access: typed by name when registered, BufferLike (typed arrays, attributes, nodes) otherwise */
569
+ buffers: CreatorBuffers;
570
+ /** GPU storage access: typed by name when registered, StorageLike (storage textures, nodes) otherwise */
571
+ gpuStorage: CreatorGPUStorage;
449
572
  };
450
573
 
451
574
  /**
452
- * @fileoverview Typed uniforms by registration (the TanStack Router `Register` pattern).
575
+ * @fileoverview Typed TSL resources by registration (the TanStack Router `Register` pattern).
453
576
  *
454
- * Nothing registered: every type below falls back to the loose shapes the hooks have always had.
577
+ * Nothing registered: every type below falls back to loose reads (`LooseUniformNode`, `LooseNode`).
455
578
  * Registered once, anywhere in the app:
456
579
  *
457
580
  * ```ts
@@ -471,14 +594,25 @@ type CreatorState = Omit<RootState, 'uniforms' | 'nodes' | 'buffers' | 'gpuStora
471
594
  *
472
595
  * then `useUniforms().uTime`, `useUniforms('player').uHealth`, `useUniform('uTime')`,
473
596
  * `useFrame(({ uniforms }) => uniforms.uTime)`, `useThree((s) => s.uniforms.uTime)` and a creator's
474
- * `({ uniforms }) => uniforms.uTime` are typed by name, with no generics.
597
+ * `({ uniforms }) => uniforms.uTime` are typed by name, with no generics. Nodes register the same
598
+ * way, by their node types: `nodes: { wobble: Node<'float'>; rimLight: typeof rimLightFn }` and
599
+ * `nodeScopes: { fx: { blur: Node<'vec4'> } }`, and so do buffers (`buffers` / `bufferScopes`) and
600
+ * GPU storage (`gpuStorage` / `gpuStorageScopes`). Docs: docs/webgpu/typed-resources.mdx.
601
+ *
602
+ * Unregistered reads are loose: `LooseUniformNode` / `LooseNode`, which every operator accepts and
603
+ * a single `as` makes exact (see those types for why).
475
604
  */
476
605
 
477
606
  /**
478
- * Augment this to type uniforms by name. Recognised keys:
607
+ * Augment this to type TSL resources by name. Recognised keys:
479
608
  * - `uniforms`: the root-level uniform inputs (e.g. `typeof globalUniforms`)
480
- * - `scopes`: named scopes and their inputs (e.g. `{ player: typeof playerUniforms }`)
481
- * - `strict`: `false` makes unregistered root keys loose instead of errors (default: strict)
609
+ * - `scopes`: named uniform scopes and their inputs (e.g. `{ player: typeof playerUniforms }`)
610
+ * - `nodes`: the root-level nodes by node type (e.g. `{ wobble: Node<'float'>; rim: typeof rimFn }`)
611
+ * - `nodeScopes`: named node scopes and their nodes (e.g. `{ fx: { blur: Node<'vec4'> } }`)
612
+ * - `buffers` / `bufferScopes`: buffers by name (e.g. `{ positions: StorageBufferNode<'vec3'> }`)
613
+ * - `gpuStorage` / `gpuStorageScopes`: GPU storage by name (e.g. `{ heightMap: StorageTexture }`)
614
+ * - `strict`: `false` makes unregistered root keys loose instead of errors (default: strict), for
615
+ * every resource family alike
482
616
  */
483
617
  interface Register {
484
618
  }
@@ -503,9 +637,11 @@ type TypedUniforms = UniformNodesFor<RegisteredUniforms> & {
503
637
  };
504
638
  /**
505
639
  * What `state.uniforms` and `useUniforms()` are: the registered shape (strict by default, so a typo
506
- * is an error), or today's loose `UniformStore` when nothing is registered.
640
+ * is an error), or the loose `LooseUniformStore` when nothing is registered. With `strict: false`
641
+ * an unregistered root key reads loose too. A loose read is a `LooseUniformNode`: every operator and
642
+ * material slot accepts it, and a single `as` gives it an exact type (see that type for why).
507
643
  */
508
- type AppUniforms = IsRegistered extends true ? IsStrict extends true ? TypedUniforms : TypedUniforms & UniformStore : UniformStore;
644
+ type AppUniforms = IsRegistered extends true ? IsStrict extends true ? TypedUniforms : TypedUniforms & LooseUniformStore : LooseUniformStore;
509
645
  /** Creator input at root level: new keys are free, registered keys must keep their registered type. */
510
646
  type RootUniformInput = Partial<RegisteredUniforms> & UniformInputRecord;
511
647
  /** Creator input for scope `S`: checked against the registered scope, free for any other scope. */
@@ -515,13 +651,101 @@ type RegisteredScopeUniforms<S extends keyof RegisteredScopes> = UniformNodesFor
515
651
  /** A registered root uniform's node. */
516
652
  type RegisteredUniform<K extends keyof RegisteredUniforms> = UniformNodesFor<RegisteredUniforms>[K];
517
653
  /**
518
- * `uniforms` in a creator (`useNodes(({ uniforms }) => ...)`). Unregistered: any name is a
519
- * `UniformNode`, as before. Registered: typed by name like `state.uniforms`, and `.scope(name)` is
654
+ * `uniforms` in a creator (`useNodes(({ uniforms }) => ...)`). Unregistered: any name reads as a
655
+ * `LooseUniformNode` (or, by dot access, a scope of them), and `.scope(name)` as a record of them
656
+ * unless given a schema. Registered: typed by name like `state.uniforms`, and `.scope(name)` is
520
657
  * typed for registered scopes.
521
658
  */
522
659
  type CreatorUniforms = IsRegistered extends true ? {
523
- scope<S extends keyof RegisteredScopes & string>(key: S): ScopedStoreType<UniformNode, RegisteredScopeUniforms<S>>;
524
- } & Readonly<AppUniforms> & ScopedStoreMethods<UniformNode> : ScopedStoreType<UniformNode>;
660
+ scope<S extends keyof RegisteredScopes & string>(key: S): ScopedStoreType<UniformNode, RegisteredScopeUniforms<S>, LooseUniformNode>;
661
+ } & Readonly<AppUniforms> & ScopedStoreMethods<UniformNode, LooseUniformNode> : ScopedStoreType<UniformNode, LooseUniformStore, LooseUniformNode>;
662
+ /** The registered root-level nodes, or `{}` when none are registered. */
663
+ type RegisteredNodes = Register extends {
664
+ nodes: infer N extends NodeRecord;
665
+ } ? N : {};
666
+ /** The registered node scopes and their nodes, or `{}` when none are registered. */
667
+ type RegisteredNodeScopes = Register extends {
668
+ nodeScopes: infer S extends Record<string, NodeRecord>;
669
+ } ? S : {};
670
+ type IsNodesRegistered = Register extends {
671
+ nodes: any;
672
+ } | {
673
+ nodeScopes: any;
674
+ } ? true : false;
675
+ type TypedNodes = RegisteredNodes & RegisteredNodeScopes;
676
+ /**
677
+ * What `state.nodes` and `useNodes()` are: the registered shape (strict by default, so a typo is an
678
+ * error), or the loose `LooseNodeStore` when no nodes are registered. With `strict: false` an
679
+ * unregistered root key reads loose too.
680
+ */
681
+ type AppNodes = IsNodesRegistered extends true ? IsStrict extends true ? TypedNodes : TypedNodes & LooseNodeStore : LooseNodeStore;
682
+ /** Creator output at root level: new keys are free, registered keys must keep their registered type. */
683
+ type RootNodeInput = Partial<RegisteredNodes> & NodeRecord;
684
+ /** Creator output for scope `S`: checked against the registered scope, free for any other scope. */
685
+ type ScopeNodeInput<S extends string> = S extends keyof RegisteredNodeScopes ? Partial<RegisteredNodeScopes[S]> : unknown;
686
+ /**
687
+ * `nodes` in a creator. Unregistered: any name reads as a `LooseNode` (or, by dot access, a scope of
688
+ * them). Registered: typed by name like `state.nodes`, and `.scope(name)` is typed for registered
689
+ * scopes.
690
+ */
691
+ type CreatorNodes = IsNodesRegistered extends true ? {
692
+ scope<S extends keyof RegisteredNodeScopes & string>(key: S): ScopedStoreType<NodeLike, RegisteredNodeScopes[S], LooseNode>;
693
+ } & Readonly<AppNodes> & ScopedStoreMethods<NodeLike, LooseNode> : ScopedStoreType<NodeLike, LooseNodeStore, LooseNode>;
694
+ /** A node reader's result for an explicit schema `T`, or loose nodes when none was given. */
695
+ type ReadNodes<T extends NodeRecord> = NodeRecord extends T ? Record<string, LooseNode> : T;
696
+ /** The registered root-level buffers, or `{}` when none are registered. */
697
+ type RegisteredBuffers = Register extends {
698
+ buffers: infer B extends BufferRecord;
699
+ } ? B : {};
700
+ /** The registered buffer scopes and their buffers, or `{}` when none are registered. */
701
+ type RegisteredBufferScopes = Register extends {
702
+ bufferScopes: infer S extends Record<string, BufferRecord>;
703
+ } ? S : {};
704
+ type IsBuffersRegistered = Register extends {
705
+ buffers: any;
706
+ } | {
707
+ bufferScopes: any;
708
+ } ? true : false;
709
+ type TypedBuffers = RegisteredBuffers & RegisteredBufferScopes;
710
+ /** What `state.buffers` and `useBuffers()` are: the registered shape, or `BufferStore` when none are. */
711
+ type AppBuffers = IsBuffersRegistered extends true ? IsStrict extends true ? TypedBuffers : TypedBuffers & BufferStore : BufferStore;
712
+ /** Creator output at root level: new keys are free, registered keys must keep their registered type. */
713
+ type RootBufferInput = Partial<RegisteredBuffers> & BufferRecord;
714
+ /** Creator output for scope `S`: checked against the registered scope, free for any other scope. */
715
+ type ScopeBufferInput<S extends string> = S extends keyof RegisteredBufferScopes ? Partial<RegisteredBufferScopes[S]> : unknown;
716
+ /** `buffers` in a creator: typed by name when registered, `BufferLike` reads otherwise. */
717
+ type CreatorBuffers = IsBuffersRegistered extends true ? {
718
+ scope<S extends keyof RegisteredBufferScopes & string>(key: S): ScopedStoreType<BufferLike, RegisteredBufferScopes[S]>;
719
+ } & Readonly<AppBuffers> & ScopedStoreMethods<BufferLike> : ScopedStoreType<BufferLike>;
720
+ /** The registered root-level GPU storage, or `{}` when none is registered. */
721
+ type RegisteredGPUStorage = Register extends {
722
+ gpuStorage: infer G extends StorageRecord;
723
+ } ? G : {};
724
+ /** The registered GPU storage scopes and their entries, or `{}` when none are registered. */
725
+ type RegisteredGPUStorageScopes = Register extends {
726
+ gpuStorageScopes: infer S extends Record<string, StorageRecord>;
727
+ } ? S : {};
728
+ type IsGPUStorageRegistered = Register extends {
729
+ gpuStorage: any;
730
+ } | {
731
+ gpuStorageScopes: any;
732
+ } ? true : false;
733
+ type TypedGPUStorage = RegisteredGPUStorage & RegisteredGPUStorageScopes;
734
+ /** What `state.gpuStorage` and `useGPUStorage()` are: the registered shape, or `StorageStore`. */
735
+ type AppGPUStorage = IsGPUStorageRegistered extends true ? IsStrict extends true ? TypedGPUStorage : TypedGPUStorage & StorageStore : StorageStore;
736
+ /** Creator output at root level: new keys are free, registered keys must keep their registered type. */
737
+ type RootGPUStorageInput = Partial<RegisteredGPUStorage> & StorageRecord;
738
+ /** Creator output for scope `S`: checked against the registered scope, free for any other scope. */
739
+ type ScopeGPUStorageInput<S extends string> = S extends keyof RegisteredGPUStorageScopes ? Partial<RegisteredGPUStorageScopes[S]> : unknown;
740
+ /** `gpuStorage` in a creator: typed by name when registered, `StorageLike` reads otherwise. */
741
+ type CreatorGPUStorage = IsGPUStorageRegistered extends true ? {
742
+ scope<S extends keyof RegisteredGPUStorageScopes & string>(key: S): ScopedStoreType<StorageLike, RegisteredGPUStorageScopes[S]>;
743
+ } & Readonly<AppGPUStorage> & ScopedStoreMethods<StorageLike> : ScopedStoreType<StorageLike>;
744
+ /**
745
+ * A reader's result for an explicit schema `T`, or loose uniforms when none was given (`T` is then
746
+ * its constraint, `UniformInputRecord`): `useUniforms<{ blur: number }>('fx')` vs `useUniforms('fx')`.
747
+ */
748
+ type ReadUniforms<T extends UniformInputRecord> = UniformInputRecord extends T ? Record<string, LooseUniformNode> : UniformNodesFor<T>;
525
749
 
526
750
  /** Uniforms that exist on every primary canvas from the start. See configureTSL. */
527
751
  interface TSLConfig {
@@ -565,7 +789,7 @@ declare function useUniforms<T extends RootUniformInput>(uniforms: T): UniformsW
565
789
  declare function useUniforms<T extends UniformInputRecord, S extends string>(uniforms: T & ScopeUniformInput<S>, scope: S): UniformsWithUtils<UniformNodesFor<T>>;
566
790
  declare function useUniforms(): UniformsWithUtils<AppUniforms>;
567
791
  declare function useUniforms<S extends keyof RegisteredScopes & string>(scope: S): UniformsWithUtils<RegisteredScopeUniforms<S>>;
568
- declare function useUniforms<T extends UniformInputRecord>(scope?: string): UniformsWithUtils<UniformNodesFor<T>>;
792
+ declare function useUniforms<T extends UniformInputRecord>(scope?: string): UniformsWithUtils<ReadUniforms<T>>;
569
793
  /**
570
794
  * Global rebuildUniforms function for HMR integration.
571
795
  * Invalidates cached uniforms and increments _hmrVersion to trigger re-creation.
@@ -587,8 +811,10 @@ declare function rebuildAllUniforms(store: ReturnType<typeof useStore>, scope?:
587
811
  * - UniformNode: existing uniforms (reused as-is)
588
812
  */
589
813
  type UniformValue = number | boolean | string | Vector2 | Vector3 | Vector4 | Color | Matrix2 | Matrix3 | Matrix4 | Node | UniformNode;
814
+ /** `useUniform<T>(name)`'s result: exact for an explicit `T`, a `LooseUniformNode` without one. */
815
+ type ReadUniform<T extends UniformValue> = UniformValue extends T ? LooseUniformNode : UniformNodeFor<T>;
590
816
  declare function useUniform<K extends keyof RegisteredUniforms & string>(name: K): RegisteredUniform<K>;
591
- declare function useUniform<T extends UniformValue = UniformValue>(name: string): UniformNodeFor<T>;
817
+ declare function useUniform<T extends UniformValue = UniformValue>(name: string): ReadUniform<T>;
592
818
  declare function useUniform<T extends UniformValue>(name: string, value: T): UniformNodeFor<T>;
593
819
 
594
820
  /**
@@ -618,12 +844,12 @@ type NodesWithUtils<T extends Record<string, unknown> = NodeRecord> = T & {
618
844
  clearNodes: ClearNodesFn;
619
845
  rebuildNodes: RebuildNodesFn;
620
846
  };
621
- declare function useNodes(): NodesWithUtils<NodeStore>;
622
- declare function useNodes(scope: string): NodesWithUtils<NodeRecord>;
623
- declare function useNodes<T extends NodeRecord>(scope?: string): NodesWithUtils<T>;
624
- declare function useNodes<T extends NodeRecord>(creator: NodeCreator<T>): NodesWithUtils<T>;
625
- declare function useNodes<T extends NodeRecord>(creator: NodeCreator<T>, scope: string): NodesWithUtils<T>;
626
- declare function useNodes(creatorOrScope?: NodeCreator<NodeRecord> | string, scope?: string): NodesWithUtils<Record<string, unknown>>;
847
+ declare function useNodes(): NodesWithUtils<AppNodes>;
848
+ declare function useNodes<S extends keyof RegisteredNodeScopes & string>(scope: S): NodesWithUtils<RegisteredNodeScopes[S]>;
849
+ declare function useNodes<T extends NodeRecord>(scope?: string): NodesWithUtils<ReadNodes<T>>;
850
+ declare function useNodes<T extends RootNodeInput>(creator: NodeCreator<T>): NodesWithUtils<T>;
851
+ declare function useNodes<T extends NodeRecord, S extends string>(creator: (state: CreatorState) => T & ScopeNodeInput<S>, scope: S): NodesWithUtils<T>;
852
+ declare function useNodes<S extends string | undefined>(creatorOrScope: NodeCreator<NodeRecord> | string | undefined, scope: S & (string extends S ? unknown : never)): NodesWithUtils<Record<string, unknown>>;
627
853
  /**
628
854
  * Global rebuildNodes function for HMR integration.
629
855
  * Invalidates cached nodes and increments _hmrVersion to trigger re-creation.
@@ -694,8 +920,8 @@ type LocalNodeInstaller = (state: CreatorState) => LocalNodeInstall;
694
920
  *
695
921
  * @example
696
922
  * ```tsx
697
- * // Resource-driven composition: no surrounding JS inputs. `uniforms.uTime` is typed when the
698
- * // app registers its uniforms (see `Register`); otherwise give a scope its schema or cast.
923
+ * // Resource-driven composition: no surrounding JS inputs. `uniforms.uTime` is typed by name when
924
+ * // the app registers its uniforms (see `Register`), and a loose node TSL accepts as is otherwise.
699
925
  * const { wobble, uTime } = useLocalNodes(({ uniforms, nodes }) => ({
700
926
  * wobble: sin(uniforms.uTime.mul(2)),
701
927
  * uTime: uniforms.uTime, // can return uniforms too
@@ -706,10 +932,10 @@ type LocalNodeInstaller = (state: CreatorState) => LocalNodeInstall;
706
932
  * result: pattern === 'noise' ? nodes.noise : nodes.stripes,
707
933
  * }), [pattern])
708
934
  *
709
- * // An unregistered uniform, cast to its type
710
- * const { colorNode } = useLocalNodes(({ uniforms }) => {
711
- * const uValue = uniforms.myUniform as UniformNode<'float', number>
712
- * return { colorNode: mix(colorA, colorB, uValue) }
935
+ * // An unregistered uniform works as is; one `as` gives its exact type where that matters
936
+ * const { colorNode, facing } = useLocalNodes(({ uniforms }) => {
937
+ * const uDir = uniforms.uDir as UniformNode<'vec3', Vector3> // cross() wants a vec3
938
+ * return { colorNode: mix(colorA, colorB, uniforms.myUniform), facing: cross(uDir, normalView) }
713
939
  * }, [])
714
940
  * ```
715
941
  */
@@ -740,11 +966,13 @@ type BuffersWithUtils<T extends BufferRecordType | BufferStore = BufferRecordTyp
740
966
  rebuildBuffers: RebuildBuffersFn;
741
967
  disposeBuffers: DisposeBuffersFn;
742
968
  };
743
- declare function useBuffers(): BuffersWithUtils<BufferStore>;
969
+ declare function useBuffers(): BuffersWithUtils<AppBuffers>;
970
+ declare function useBuffers<S extends keyof RegisteredBufferScopes & string>(scope: S): BuffersWithUtils<RegisteredBufferScopes[S]>;
744
971
  declare function useBuffers(scope: string): BuffersWithUtils<Record<string, BufferLike>>;
745
972
  declare function useBuffers<T extends Record<string, BufferLike>>(scope?: string): BuffersWithUtils<T>;
746
- declare function useBuffers<T extends Record<string, BufferLike>>(creator: BufferCreator<T>): BuffersWithUtils<T>;
747
- declare function useBuffers<T extends Record<string, BufferLike>>(creator: BufferCreator<T>, scope: string): BuffersWithUtils<T>;
973
+ declare function useBuffers<T extends RootBufferInput>(creator: BufferCreator<T>): BuffersWithUtils<T>;
974
+ declare function useBuffers<T extends Record<string, BufferLike>, S extends string>(creator: (state: CreatorState) => T & ScopeBufferInput<S>, scope: S): BuffersWithUtils<T>;
975
+ declare function useBuffers<S extends string | undefined>(creator: BufferCreator<BufferRecord>, scope: S & (string extends S ? unknown : never)): BuffersWithUtils<BufferRecord>;
748
976
  /**
749
977
  * Global rebuildBuffers function for HMR integration.
750
978
  * Invalidates cached buffers and increments _hmrVersion to trigger re-creation.
@@ -782,11 +1010,13 @@ type StorageWithUtils<T extends StorageRecordType | StorageStore = StorageRecord
782
1010
  rebuildStorage: RebuildStorageFn;
783
1011
  disposeStorage: DisposeStorageFn;
784
1012
  };
785
- declare function useGPUStorage(): StorageWithUtils<StorageStore>;
1013
+ declare function useGPUStorage(): StorageWithUtils<AppGPUStorage>;
1014
+ declare function useGPUStorage<S extends keyof RegisteredGPUStorageScopes & string>(scope: S): StorageWithUtils<RegisteredGPUStorageScopes[S]>;
786
1015
  declare function useGPUStorage(scope: string): StorageWithUtils<Record<string, StorageLike>>;
787
1016
  declare function useGPUStorage<T extends Record<string, StorageLike>>(scope?: string): StorageWithUtils<T>;
788
- declare function useGPUStorage<T extends Record<string, StorageLike>>(creator: StorageCreator<T>): StorageWithUtils<T>;
789
- declare function useGPUStorage<T extends Record<string, StorageLike>>(creator: StorageCreator<T>, scope: string): StorageWithUtils<T>;
1017
+ declare function useGPUStorage<T extends RootGPUStorageInput>(creator: StorageCreator<T>): StorageWithUtils<T>;
1018
+ declare function useGPUStorage<T extends Record<string, StorageLike>, S extends string>(creator: (state: CreatorState) => T & ScopeGPUStorageInput<S>, scope: S): StorageWithUtils<T>;
1019
+ declare function useGPUStorage<S extends string | undefined>(creator: StorageCreator<StorageRecord>, scope: S & (string extends S ? unknown : never)): StorageWithUtils<StorageRecord>;
790
1020
  /**
791
1021
  * Global rebuildStorage function for HMR integration.
792
1022
  * Invalidates cached storage and increments _hmrVersion to trigger re-creation.
@@ -804,11 +1034,15 @@ declare function rebuildAllStorage(store: ReturnType<typeof useStore>, scope?: s
804
1034
  * Hook for managing WebGPU RenderPipeline with automatic scenePass setup.
805
1035
  *
806
1036
  * Features:
807
- * - Creates RenderPipeline instance if not exists
808
- * - Creates default scenePass (no MRT) automatically
809
- * - Callbacks receive full RootState for flexibility
810
- * - No auto-cleanup on unmount - use reset() for explicit cleanup
811
- * - Scene/camera changes trigger scenePass recreation
1037
+ * - A call with a callback owns the canvas's pipeline: it creates the pipeline and a default
1038
+ * scenePass (no MRT), and frees both when it unmounts (opt out with `persist`)
1039
+ * - A call without callbacks only reads: it never creates, keeps alive or frees the pipeline
1040
+ * - The most recently mounted owner renders; when it unmounts, the previous owner takes over again
1041
+ * - StrictMode and Fast Refresh remounts reuse the graph instead of rebuilding it
1042
+ * - Callbacks receive the same state as creators (`uniforms`, `nodes`, ... wrapped, including
1043
+ * entries staged earlier in the render), and their reads are tracked as in useLocalNodes: a read
1044
+ * resource that appears, is replaced or is removed re-runs them
1045
+ * - Callbacks re-run on a hot update (`_hmrVersion`), on scene/camera change and on rebuild()
812
1046
  * - A replaced scenePass is disposed once the new graph is installed, so rebuild() does not
813
1047
  * strand its render target (and MRT attachments) on the GPU
814
1048
  * - Any run that changes the output node sets RenderPipeline.needsUpdate, so rebuild() actually
@@ -816,6 +1050,7 @@ declare function rebuildAllStorage(store: ReturnType<typeof useStore>, scope?: s
816
1050
  *
817
1051
  * @param mainCB - Main callback to configure outputNode and create effect passes
818
1052
  * @param setupCB - Optional setup callback to configure MRT on scenePass
1053
+ * @param options - `persist: true` keeps the pipeline after the component unmounts
819
1054
  * @returns { passes, renderPipeline, clearPasses, reset, rebuild }
820
1055
  *
821
1056
  * @example
@@ -841,7 +1076,7 @@ declare function rebuildAllStorage(store: ReturnType<typeof useStore>, scope?: s
841
1076
  * const { renderPipeline, passes } = useRenderPipeline()
842
1077
  * ```
843
1078
  */
844
- declare function useRenderPipeline(mainCB?: RenderPipelineMainCallback, setupCB?: RenderPipelineSetupCallback): UseRenderPipelineReturn;
1079
+ declare function useRenderPipeline(mainCB?: RenderPipelineMainCallback, setupCB?: RenderPipelineSetupCallback, options?: RenderPipelineOptions): UseRenderPipelineReturn;
845
1080
 
846
1081
  export { configureTSL, createScopedStore, rebuildAllBuffers, rebuildAllNodes, rebuildAllStorage, rebuildAllUniforms, useBuffers, useGPUStorage, useLocalNodes, useNodes, useRenderPipeline, useUniform, useUniforms };
847
- export type { AppUniforms, BufferCreator, BufferLike, BufferRecord, BufferStore, BuffersWithUtils, ClearBuffersFn, ClearNodesFn, ClearStorageFn, ClearUniformsFn, CreatorState, DisposeBuffersFn, DisposeStorageFn, LocalNodeCreator, LocalNodeInstall, LocalNodeInstaller, NodeCreator, NodeLike, NodeRecord, NodeStore, NodesWithUtils, RebuildBuffersFn, RebuildNodesFn, RebuildStorageFn, RebuildUniformsFn, Register, RegisteredScopeUniforms, RegisteredScopes, RegisteredUniform, RegisteredUniforms, RemoveBuffersFn, RemoveNodesFn, RemoveStorageFn, RemoveUniformsFn, RootUniformInput, ScopeUniformInput, ScopedStoreType, StorageCreator, StorageLike, StorageRecord, StorageStore, StorageWithUtils, TSLConfig, TSLNode, TSLNodeLike, TSLRootState, UniformCreator, UniformValue, UniformsWithUtils };
1082
+ export type { AppBuffers, AppGPUStorage, AppNodes, AppUniforms, BufferCreator, BufferLike, BufferRecord, BufferStore, BuffersWithUtils, ClearBuffersFn, ClearNodesFn, ClearStorageFn, ClearUniformsFn, CreatorState, DisposeBuffersFn, DisposeStorageFn, FnNodeLike, LocalNodeCreator, LocalNodeInstall, LocalNodeInstaller, LooseNode, LooseNodeEntry, LooseNodeStore, NodeCreator, NodeLike, NodeRecord, NodeStore, NodesWithUtils, RebuildBuffersFn, RebuildNodesFn, RebuildStorageFn, RebuildUniformsFn, Register, RegisteredBufferScopes, RegisteredBuffers, RegisteredGPUStorage, RegisteredGPUStorageScopes, RegisteredNodeScopes, RegisteredNodes, RegisteredScopeUniforms, RegisteredScopes, RegisteredUniform, RegisteredUniforms, RemoveBuffersFn, RemoveNodesFn, RemoveStorageFn, RemoveUniformsFn, RootBufferInput, RootGPUStorageInput, RootNodeInput, RootUniformInput, ScopeBufferInput, ScopeGPUStorageInput, ScopeNodeInput, ScopeUniformInput, ScopedStoreType, StorageCreator, StorageLike, StorageRecord, StorageStore, StorageWithUtils, TSLConfig, TSLNode, TSLNodeLike, TSLRootState, UniformCreator, UniformValue, UniformsWithUtils };