@gnsx/react-three-fiber 10.0.1 → 10.0.3

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
@@ -57,1076 +57,1076 @@ var THREE = /*#__PURE__*/_mergeNamespaces({
57
57
  WebGLRendererParameters: WebGLRendererParameters
58
58
  }, [three_webgpu]);
59
59
 
60
- //* Utility Types ==============================
61
-
62
- type NonFunctionKeys<P> = { [K in keyof P]-?: P[K] extends Function ? never : K }[keyof P]
63
- type Overwrite<P, O> = Omit<P, NonFunctionKeys<O>> & O
64
- type Properties<T> = Pick<T, NonFunctionKeys<T>>
65
- type Mutable<P> = { -readonly [K in keyof P]: P[K] }
66
- type IsOptional<T> = undefined extends T ? true : false
67
- type IsAllOptional<T extends any[]> = T extends [infer First, ...infer Rest]
68
- ? IsOptional<First> extends true
69
- ? IsAllOptional<Rest>
70
- : false
71
- : true
72
-
73
- //* Camera Types ==============================
74
-
75
- type ThreeCamera = (THREE$1.OrthographicCamera | THREE$1.PerspectiveCamera) & { manual?: boolean }
76
-
77
- //* Act Type ==============================
78
-
79
- type Act = <T = any>(cb: () => Promise<T>) => Promise<T>
80
-
81
- //* Bridge & Block Types ==============================
82
-
83
- type Bridge = React$1.FC<{ children?: React$1.ReactNode }>
84
-
85
- type SetBlock = false | Promise<null> | null
86
- type UnblockProps = { set: React$1.Dispatch<React$1.SetStateAction<SetBlock>>; children: React$1.ReactNode }
87
-
88
- //* Object Map Type ==============================
89
-
90
- /* Original version
91
- export interface ObjectMap {
92
- nodes: { [name: string]: THREE.Object3D }
93
- materials: { [name: string]: THREE.Material }
94
- meshes: { [name: string]: THREE.Mesh }
95
- }
96
- */
97
- /* This version is an expansion found in a PR by itsdouges that seems abandoned but looks useful.
98
- It allows expansion but falls back to the original shape. (deleted due to stale, but If it doesnt conflict
99
- I will keep the use here)
100
- https://github.com/pmndrs/react-three-fiber/commits/generic-object-map/
101
- His description is:
102
- The object map type is now generic and can optionally declare the available properties for nodes, materials, and meshes.
103
- */
104
- interface ObjectMap<
105
- T extends { nodes?: string; materials?: string; meshes?: string } = {
106
- nodes: string
107
- materials: string
108
- meshes: string
109
- },
110
- > {
111
- nodes: Record<T['nodes'] extends string ? T['nodes'] : string, THREE$1.Object3D>
112
- materials: Record<T['materials'] extends string ? T['materials'] : string, THREE$1.Material>
113
- meshes: Record<T['meshes'] extends string ? T['meshes'] : string, THREE$1.Mesh>
114
- }
115
-
116
- //* Equality Config ==============================
117
-
118
- interface EquConfig {
119
- /** Compare arrays by reference equality a === b (default), or by shallow equality */
120
- arrays?: 'reference' | 'shallow'
121
- /** Compare objects by reference equality a === b (default), or by shallow equality */
122
- objects?: 'reference' | 'shallow'
123
- /** If true the keys in both a and b must match 1:1 (default), if false a's keys must intersect b's */
124
- strict?: boolean
125
- }
126
-
127
- //* Disposable Type ==============================
128
-
129
- interface Disposable {
130
- type?: string
131
- dispose?: () => void
60
+ //* Utility Types ==============================
61
+
62
+ type NonFunctionKeys<P> = { [K in keyof P]-?: P[K] extends Function ? never : K }[keyof P]
63
+ type Overwrite<P, O> = Omit<P, NonFunctionKeys<O>> & O
64
+ type Properties<T> = Pick<T, NonFunctionKeys<T>>
65
+ type Mutable<P> = { -readonly [K in keyof P]: P[K] }
66
+ type IsOptional<T> = undefined extends T ? true : false
67
+ type IsAllOptional<T extends any[]> = T extends [infer First, ...infer Rest]
68
+ ? IsOptional<First> extends true
69
+ ? IsAllOptional<Rest>
70
+ : false
71
+ : true
72
+
73
+ //* Camera Types ==============================
74
+
75
+ type ThreeCamera = (THREE$1.OrthographicCamera | THREE$1.PerspectiveCamera) & { manual?: boolean }
76
+
77
+ //* Act Type ==============================
78
+
79
+ type Act = <T = any>(cb: () => Promise<T>) => Promise<T>
80
+
81
+ //* Bridge & Block Types ==============================
82
+
83
+ type Bridge = React$1.FC<{ children?: React$1.ReactNode }>
84
+
85
+ type SetBlock = false | Promise<null> | null
86
+ type UnblockProps = { set: React$1.Dispatch<React$1.SetStateAction<SetBlock>>; children: React$1.ReactNode }
87
+
88
+ //* Object Map Type ==============================
89
+
90
+ /* Original version
91
+ export interface ObjectMap {
92
+ nodes: { [name: string]: THREE.Object3D }
93
+ materials: { [name: string]: THREE.Material }
94
+ meshes: { [name: string]: THREE.Mesh }
95
+ }
96
+ */
97
+ /* This version is an expansion found in a PR by itsdouges that seems abandoned but looks useful.
98
+ It allows expansion but falls back to the original shape. (deleted due to stale, but If it doesnt conflict
99
+ I will keep the use here)
100
+ https://github.com/pmndrs/react-three-fiber/commits/generic-object-map/
101
+ His description is:
102
+ The object map type is now generic and can optionally declare the available properties for nodes, materials, and meshes.
103
+ */
104
+ interface ObjectMap<
105
+ T extends { nodes?: string; materials?: string; meshes?: string } = {
106
+ nodes: string
107
+ materials: string
108
+ meshes: string
109
+ },
110
+ > {
111
+ nodes: Record<T['nodes'] extends string ? T['nodes'] : string, THREE$1.Object3D>
112
+ materials: Record<T['materials'] extends string ? T['materials'] : string, THREE$1.Material>
113
+ meshes: Record<T['meshes'] extends string ? T['meshes'] : string, THREE$1.Mesh>
114
+ }
115
+
116
+ //* Equality Config ==============================
117
+
118
+ interface EquConfig {
119
+ /** Compare arrays by reference equality a === b (default), or by shallow equality */
120
+ arrays?: 'reference' | 'shallow'
121
+ /** Compare objects by reference equality a === b (default), or by shallow equality */
122
+ objects?: 'reference' | 'shallow'
123
+ /** If true the keys in both a and b must match 1:1 (default), if false a's keys must intersect b's */
124
+ strict?: boolean
125
+ }
126
+
127
+ //* Disposable Type ==============================
128
+
129
+ interface Disposable {
130
+ type?: string
131
+ dispose?: () => void
132
132
  }
133
133
 
134
- //* Event-related Types =====================================
135
-
136
- interface Intersection extends THREE$1.Intersection {
137
- /** The event source (the object which registered the handler) */
138
- eventObject: THREE$1.Object3D
139
- }
140
-
141
- type Camera = THREE$1.OrthographicCamera | THREE$1.PerspectiveCamera
142
-
143
- interface IntersectionEvent<TSourceEvent> extends Intersection {
144
- /** The event source (the object which registered the handler) */
145
- eventObject: THREE$1.Object3D
146
- /** An array of intersections */
147
- intersections: Intersection[]
148
- /** vec3.set(pointer.x, pointer.y, 0).unproject(camera) */
149
- unprojectedPoint: THREE$1.Vector3
150
- /** Normalized event coordinates */
151
- pointer: THREE$1.Vector2
152
- /** pointerId of the original event for multiple pointer events */
153
- pointerId: number
154
- /** Delta between first click and this event */
155
- delta: number
156
- /** The ray that pierced it */
157
- ray: THREE$1.Ray
158
- /** The camera that was used by the raycaster */
159
- camera: Camera
160
- /** stopPropagation will stop underlying handlers from firing */
161
- stopPropagation: () => void
162
- /** The original host event */
163
- nativeEvent: TSourceEvent
164
- /** If the event was stopped by calling stopPropagation */
165
- stopped: boolean
166
- }
167
-
168
- type ThreeEvent<TEvent> = IntersectionEvent<TEvent> & Properties<TEvent>
169
- type DomEvent = PointerEvent | MouseEvent | WheelEvent
170
-
171
- /** DOM event handlers registered on the canvas element */
172
- interface Events {
173
- onClick: EventListener
174
- onContextMenu: EventListener
175
- onDoubleClick: EventListener
176
- onWheel: EventListener
177
- onPointerDown: EventListener
178
- onPointerUp: EventListener
179
- onPointerLeave: EventListener
180
- onPointerMove: EventListener
181
- onPointerCancel: EventListener
182
- onLostPointerCapture: EventListener
183
- onDragEnter: EventListener
184
- onDragLeave: EventListener
185
- onDragOver: EventListener
186
- onDrop: EventListener
187
- }
188
-
189
- /** Event handlers that can be attached to R3F objects (meshes, groups, etc.) */
190
- interface EventHandlers {
191
- onClick?: (event: ThreeEvent<MouseEvent>) => void
192
- onContextMenu?: (event: ThreeEvent<MouseEvent>) => void
193
- onDoubleClick?: (event: ThreeEvent<MouseEvent>) => void
194
- /** Fires continuously while dragging over the object */
195
- onDragOver?: (event: ThreeEvent<DragEvent>) => void
196
- /** Fires once when drag enters the object */
197
- onDragOverEnter?: (event: ThreeEvent<DragEvent>) => void
198
- /** Fires once when drag leaves the object */
199
- onDragOverLeave?: (event: ThreeEvent<DragEvent>) => void
200
- /** Fires when drag misses this object (for objects that have drag handlers) */
201
- onDragOverMissed?: (event: DragEvent) => void
202
- /** Fires when a drop occurs on this object */
203
- onDrop?: (event: ThreeEvent<DragEvent>) => void
204
- /** Fires when a drop misses this object (for objects that have drop handlers) */
205
- onDropMissed?: (event: DragEvent) => void
206
- onPointerUp?: (event: ThreeEvent<PointerEvent>) => void
207
- onPointerDown?: (event: ThreeEvent<PointerEvent>) => void
208
- onPointerOver?: (event: ThreeEvent<PointerEvent>) => void
209
- onPointerOut?: (event: ThreeEvent<PointerEvent>) => void
210
- onPointerEnter?: (event: ThreeEvent<PointerEvent>) => void
211
- onPointerLeave?: (event: ThreeEvent<PointerEvent>) => void
212
- onPointerMove?: (event: ThreeEvent<PointerEvent>) => void
213
- onPointerMissed?: (event: MouseEvent) => void
214
- onPointerCancel?: (event: ThreeEvent<PointerEvent>) => void
215
- onWheel?: (event: ThreeEvent<WheelEvent>) => void
216
- onLostPointerCapture?: (event: ThreeEvent<PointerEvent>) => void
217
-
218
- //* Visibility Events --------------------------------
219
- /** Fires when object enters/exits camera frustum. Receives true when in view, false when out. */
220
- onFramed?: (inView: boolean) => void
221
- /** Fires when object occlusion state changes (WebGPU only, requires occlusionTest=true on object) */
222
- onOccluded?: (occluded: boolean) => void
223
- /** Fires when combined visibility changes (frustum + occlusion + visible prop) */
224
- onVisible?: (visible: boolean) => void
225
- }
226
-
227
- type FilterFunction = (items: THREE$1.Intersection[], state: RootState) => THREE$1.Intersection[]
228
- type ComputeFunction = (event: DomEvent, root: RootState, previous?: RootState) => void
229
-
230
- /** Configuration for XR pointer registration (controllers/hands) */
231
- interface XRPointerConfig {
232
- /** Ray origin (updated each frame by XR system) */
233
- ray: THREE$1.Ray
234
- /** Optional: custom compute function for this pointer */
235
- compute?: (state: RootState) => void
236
- /** Pointer type identifier */
237
- type: 'controller' | 'hand' | 'gaze'
238
- /** Which hand (for controller/hand types) */
239
- handedness?: 'left' | 'right'
240
- }
241
-
242
- interface EventManager<TTarget> {
243
- /** Determines if the event layer is active */
244
- enabled: boolean
245
- /** Event layer priority, higher prioritized layers come first and may stop(-propagate) lower layer */
246
- priority: number
247
- /** The compute function needs to set up the raycaster and an xy- pointer */
248
- compute?: ComputeFunction
249
- /** The filter can re-order or re-structure the intersections */
250
- filter?: FilterFunction
251
- /** The target node the event layer is tied to */
252
- connected?: TTarget
253
- /** All the pointer event handlers through which the host forwards native events */
254
- handlers?: Events
255
- /** Allows re-connecting to another target */
256
- connect?: (target: TTarget) => void
257
- /** Removes all existing events handlers from the target */
258
- disconnect?: () => void
259
- /** Triggers a onPointerMove with the last known event. This can be useful to enable raycasting without
260
- * explicit user interaction, for instance when the camera moves a hoverable object underneath the cursor.
261
- * @param pointerId - Optional pointer ID to update specific pointer only
262
- */
263
- update?: (pointerId?: number) => void
264
- /** Defer pointer move raycasting to frame start (default: true) */
265
- frameTimedRaycasts?: boolean
266
- /** Always fire raycaster immediately on scroll events (default: true) */
267
- alwaysFireOnScroll?: boolean
268
- /** Automatically re-raycast every frame to detect hover changes from moving objects/camera (default: false) */
269
- updateOnFrame?: boolean
270
- /** Flush deferred pointer raycasts. Called by scheduler at frame start (input phase). */
271
- flush?: () => void
272
- /** Register an XR pointer (controller/hand). Returns assigned pointerId */
273
- registerPointer?: (config: XRPointerConfig) => number
274
- /** Unregister an XR pointer */
275
- unregisterPointer?: (pointerId: number) => void
276
- }
277
-
278
- interface PointerCaptureTarget {
279
- intersection: Intersection
280
- target: Element
281
- }
282
-
283
- //* Visibility System Types =====================================
284
-
285
- /** Entry in the visibility registry for tracking object visibility state */
286
- interface VisibilityEntry {
287
- object: THREE$1.Object3D
288
- handlers: Pick<EventHandlers, 'onFramed' | 'onOccluded' | 'onVisible'>
289
- lastFramedState: boolean | null
290
- lastOccludedState: boolean | null
291
- lastVisibleState: boolean | null
134
+ //* Event-related Types =====================================
135
+
136
+ interface Intersection extends THREE$1.Intersection {
137
+ /** The event source (the object which registered the handler) */
138
+ eventObject: THREE$1.Object3D
139
+ }
140
+
141
+ type Camera = THREE$1.OrthographicCamera | THREE$1.PerspectiveCamera
142
+
143
+ interface IntersectionEvent<TSourceEvent> extends Intersection {
144
+ /** The event source (the object which registered the handler) */
145
+ eventObject: THREE$1.Object3D
146
+ /** An array of intersections */
147
+ intersections: Intersection[]
148
+ /** vec3.set(pointer.x, pointer.y, 0).unproject(camera) */
149
+ unprojectedPoint: THREE$1.Vector3
150
+ /** Normalized event coordinates */
151
+ pointer: THREE$1.Vector2
152
+ /** pointerId of the original event for multiple pointer events */
153
+ pointerId: number
154
+ /** Delta between first click and this event */
155
+ delta: number
156
+ /** The ray that pierced it */
157
+ ray: THREE$1.Ray
158
+ /** The camera that was used by the raycaster */
159
+ camera: Camera
160
+ /** stopPropagation will stop underlying handlers from firing */
161
+ stopPropagation: () => void
162
+ /** The original host event */
163
+ nativeEvent: TSourceEvent
164
+ /** If the event was stopped by calling stopPropagation */
165
+ stopped: boolean
166
+ }
167
+
168
+ type ThreeEvent<TEvent> = IntersectionEvent<TEvent> & Properties<TEvent>
169
+ type DomEvent = PointerEvent | MouseEvent | WheelEvent
170
+
171
+ /** DOM event handlers registered on the canvas element */
172
+ interface Events {
173
+ onClick: EventListener
174
+ onContextMenu: EventListener
175
+ onDoubleClick: EventListener
176
+ onWheel: EventListener
177
+ onPointerDown: EventListener
178
+ onPointerUp: EventListener
179
+ onPointerLeave: EventListener
180
+ onPointerMove: EventListener
181
+ onPointerCancel: EventListener
182
+ onLostPointerCapture: EventListener
183
+ onDragEnter: EventListener
184
+ onDragLeave: EventListener
185
+ onDragOver: EventListener
186
+ onDrop: EventListener
187
+ }
188
+
189
+ /** Event handlers that can be attached to R3F objects (meshes, groups, etc.) */
190
+ interface EventHandlers {
191
+ onClick?: (event: ThreeEvent<MouseEvent>) => void
192
+ onContextMenu?: (event: ThreeEvent<MouseEvent>) => void
193
+ onDoubleClick?: (event: ThreeEvent<MouseEvent>) => void
194
+ /** Fires continuously while dragging over the object */
195
+ onDragOver?: (event: ThreeEvent<DragEvent>) => void
196
+ /** Fires once when drag enters the object */
197
+ onDragOverEnter?: (event: ThreeEvent<DragEvent>) => void
198
+ /** Fires once when drag leaves the object */
199
+ onDragOverLeave?: (event: ThreeEvent<DragEvent>) => void
200
+ /** Fires when drag misses this object (for objects that have drag handlers) */
201
+ onDragOverMissed?: (event: DragEvent) => void
202
+ /** Fires when a drop occurs on this object */
203
+ onDrop?: (event: ThreeEvent<DragEvent>) => void
204
+ /** Fires when a drop misses this object (for objects that have drop handlers) */
205
+ onDropMissed?: (event: DragEvent) => void
206
+ onPointerUp?: (event: ThreeEvent<PointerEvent>) => void
207
+ onPointerDown?: (event: ThreeEvent<PointerEvent>) => void
208
+ onPointerOver?: (event: ThreeEvent<PointerEvent>) => void
209
+ onPointerOut?: (event: ThreeEvent<PointerEvent>) => void
210
+ onPointerEnter?: (event: ThreeEvent<PointerEvent>) => void
211
+ onPointerLeave?: (event: ThreeEvent<PointerEvent>) => void
212
+ onPointerMove?: (event: ThreeEvent<PointerEvent>) => void
213
+ onPointerMissed?: (event: MouseEvent) => void
214
+ onPointerCancel?: (event: ThreeEvent<PointerEvent>) => void
215
+ onWheel?: (event: ThreeEvent<WheelEvent>) => void
216
+ onLostPointerCapture?: (event: ThreeEvent<PointerEvent>) => void
217
+
218
+ //* Visibility Events --------------------------------
219
+ /** Fires when object enters/exits camera frustum. Receives true when in view, false when out. */
220
+ onFramed?: (inView: boolean) => void
221
+ /** Fires when object occlusion state changes (WebGPU only, requires occlusionTest=true on object) */
222
+ onOccluded?: (occluded: boolean) => void
223
+ /** Fires when combined visibility changes (frustum + occlusion + visible prop) */
224
+ onVisible?: (visible: boolean) => void
225
+ }
226
+
227
+ type FilterFunction = (items: THREE$1.Intersection[], state: RootState) => THREE$1.Intersection[]
228
+ type ComputeFunction = (event: DomEvent, root: RootState, previous?: RootState) => void
229
+
230
+ /** Configuration for XR pointer registration (controllers/hands) */
231
+ interface XRPointerConfig {
232
+ /** Ray origin (updated each frame by XR system) */
233
+ ray: THREE$1.Ray
234
+ /** Optional: custom compute function for this pointer */
235
+ compute?: (state: RootState) => void
236
+ /** Pointer type identifier */
237
+ type: 'controller' | 'hand' | 'gaze'
238
+ /** Which hand (for controller/hand types) */
239
+ handedness?: 'left' | 'right'
292
240
  }
293
241
 
294
- //* Scheduler Types (useFrame) ==============================
295
-
296
-
297
-
298
- // Public Options --------------------------------
299
-
300
- /**
301
- * Options for useFrame hook
302
- */
303
- interface UseFrameNextOptions {
304
- /** Optional stable id for the job. Auto-generated if not provided */
305
- id?: string
306
- /** Named phase to run in. Default: 'update' */
307
- phase?: string
308
- /** Run before this phase or job id */
309
- before?: string | string[]
310
- /** Run after this phase or job id */
311
- after?: string | string[]
312
- /** Priority within phase. Higher runs first. Default: 0 */
313
- priority?: number
314
- /** Max frames per second for this job */
315
- fps?: number
316
- /** If true, skip frames when behind. If false, try to catch up. Default: true */
317
- drop?: boolean
318
- /** Enable/disable without unregistering. Default: true */
319
- enabled?: boolean
320
- }
321
-
322
- /** Alias for UseFrameNextOptions */
323
- type UseFrameOptions = UseFrameNextOptions
324
-
325
- /**
326
- * Options for addPhase
327
- */
328
- interface AddPhaseOptions {
329
- /** Insert this phase before the specified phase */
330
- before?: string
331
- /** Insert this phase after the specified phase */
332
- after?: string
333
- }
334
-
335
- // Frame State --------------------------------
336
-
337
- /**
338
- * Timing-only state for independent/outside mode (no RootState)
339
- */
340
- interface FrameTimingState {
341
- /** High-resolution timestamp from RAF (ms) */
342
- time: number
343
- /** Time since last frame in seconds (for legacy compatibility with THREE.Clock) */
344
- delta: number
345
- /** Elapsed time since first frame in seconds (for legacy compatibility with THREE.Clock) */
346
- elapsed: number
347
- /** Incrementing frame counter */
348
- frame: number
349
- }
350
-
351
- /**
352
- * State passed to useFrame callbacks (extends RootState with timing)
353
- */
354
- interface FrameNextState extends RootState, FrameTimingState {}
355
-
356
- /** Alias for FrameNextState */
357
- type FrameState = FrameNextState
358
-
359
- // Root Options --------------------------------
360
-
361
- /**
362
- * Options for registerRoot
363
- */
364
- interface RootOptions {
365
- /** State provider for callbacks. Optional in independent mode. */
366
- getState?: () => any
367
- /** Error handler for job errors. Falls back to console.error if not provided. */
368
- onError?: (error: Error) => void
369
- }
370
-
371
- // Callback Types --------------------------------
372
-
373
- /**
374
- * Callback function for useFrame
375
- */
376
- type FrameNextCallback = (state: FrameNextState, delta: number) => void
377
-
378
- /** Alias for FrameNextCallback */
379
- type FrameCallback = FrameNextCallback
380
-
381
- // Controls returned from useFrame --------------------------------
382
-
383
- /**
384
- * Controls object returned from useFrame hook
385
- */
386
- interface FrameNextControls {
387
- /** The job's unique ID */
388
- id: string
389
- /** Access to the global scheduler for frame loop control */
390
- scheduler: SchedulerApi
391
- /** Manually step this job only (bypasses FPS limiting) */
392
- step(timestamp?: number): void
393
- /** Manually step ALL jobs in the scheduler */
394
- stepAll(timestamp?: number): void
395
- /** Pause this job (set enabled=false) */
396
- pause(): void
397
- /** Resume this job (set enabled=true) */
398
- resume(): void
399
- /** Reactive paused state - automatically triggers re-render when changed */
400
- isPaused: boolean
401
- }
402
-
403
- /** Alias for FrameNextControls */
404
- type FrameControls = FrameNextControls
405
-
406
- // Scheduler Interface --------------------------------
407
-
408
- /**
409
- * Public interface for the global Scheduler
410
- */
411
- interface SchedulerApi {
412
- //* Phase Management --------------------------------
413
-
414
- /** Add a named phase to the scheduler */
415
- addPhase(name: string, options?: AddPhaseOptions): void
416
- /** Get the ordered list of phase names */
417
- readonly phases: string[]
418
- /** Check if a phase exists */
419
- hasPhase(name: string): boolean
420
-
421
- //* Root Management --------------------------------
422
-
423
- /** Register a root (Canvas) with the scheduler. Returns unsubscribe function. */
424
- registerRoot(id: string, options?: RootOptions): () => void
425
- /** Unregister a root */
426
- unregisterRoot(id: string): void
427
- /** Generate a unique root ID */
428
- generateRootId(): string
429
- /** Get the number of registered roots */
430
- getRootCount(): number
431
- /** Check if any root is registered and ready */
432
- readonly isReady: boolean
433
- /** Subscribe to root-ready event. Fires immediately if already ready. Returns unsubscribe. */
434
- onRootReady(callback: () => void): () => void
435
-
436
- //* Job Registration --------------------------------
437
-
438
- /** Register a job with the scheduler (returns unsubscribe function) */
439
- register(
440
- callback: FrameNextCallback,
441
- options?: {
442
- id?: string
443
- rootId?: string
444
- phase?: string
445
- before?: string | string[]
446
- after?: string | string[]
447
- priority?: number
448
- fps?: number
449
- drop?: boolean
450
- enabled?: boolean
451
- },
452
- ): () => void
453
- /** Update a job's options */
454
- updateJob(
455
- id: string,
456
- options: {
457
- priority?: number
458
- fps?: number
459
- drop?: boolean
460
- enabled?: boolean
461
- phase?: string
462
- before?: string | string[]
463
- after?: string | string[]
464
- },
465
- ): void
466
- /** Unregister a job by ID */
467
- unregister(id: string, rootId?: string): void
468
- /** Get the number of registered jobs */
469
- getJobCount(): number
470
- /** Get all job IDs */
471
- getJobIds(): string[]
472
-
473
- //* Global Jobs (for legacy addEffect/addAfterEffect) --------------------------------
474
-
475
- /** Register a global job (runs once per frame, not per-root). Returns unsubscribe function. */
476
- registerGlobal(phase: 'before' | 'after', id: string, callback: (timestamp: number) => void): () => void
477
-
478
- //* Idle Callbacks (for legacy addTail) --------------------------------
479
-
480
- /** Register an idle callback (fires when loop stops). Returns unsubscribe function. */
481
- onIdle(callback: (timestamp: number) => void): () => void
482
-
483
- //* Frame Loop Control --------------------------------
484
-
485
- /** Start the scheduler loop */
486
- start(): void
487
- /** Stop the scheduler loop */
488
- stop(): void
489
- /** Check if the scheduler is running */
490
- readonly isRunning: boolean
491
- /** Get/set the frameloop mode ('always', 'demand', 'never') */
492
- frameloop: Frameloop
493
- /** Independent mode - runs without Canvas, callbacks receive timing-only state */
494
- independent: boolean
495
-
496
- //* Manual Stepping --------------------------------
497
-
498
- /** Manually step all jobs once (for frameloop='never' or testing) */
499
- step(timestamp?: number): void
500
- /** Manually step a single job by ID */
501
- stepJob(id: string, timestamp?: number): void
502
- /** Request frame(s) to be rendered (for frameloop='demand') */
503
- invalidate(frames?: number): void
504
-
505
- //* Per-Job Control --------------------------------
506
-
507
- /** Check if a job is paused */
508
- isJobPaused(id: string): boolean
509
- /** Pause a job */
510
- pauseJob(id: string): void
511
- /** Resume a job */
512
- resumeJob(id: string): void
513
- /** Subscribe to job state changes (for reactive isPaused). Returns unsubscribe function. */
514
- subscribeJobState(id: string, listener: () => void): () => void
242
+ interface EventManager<TTarget> {
243
+ /** Determines if the event layer is active */
244
+ enabled: boolean
245
+ /** Event layer priority, higher prioritized layers come first and may stop(-propagate) lower layer */
246
+ priority: number
247
+ /** The compute function needs to set up the raycaster and an xy- pointer */
248
+ compute?: ComputeFunction
249
+ /** The filter can re-order or re-structure the intersections */
250
+ filter?: FilterFunction
251
+ /** The target node the event layer is tied to */
252
+ connected?: TTarget
253
+ /** All the pointer event handlers through which the host forwards native events */
254
+ handlers?: Events
255
+ /** Allows re-connecting to another target */
256
+ connect?: (target: TTarget) => void
257
+ /** Removes all existing events handlers from the target */
258
+ disconnect?: () => void
259
+ /** Triggers a onPointerMove with the last known event. This can be useful to enable raycasting without
260
+ * explicit user interaction, for instance when the camera moves a hoverable object underneath the cursor.
261
+ * @param pointerId - Optional pointer ID to update specific pointer only
262
+ */
263
+ update?: (pointerId?: number) => void
264
+ /** Defer pointer move raycasting to frame start (default: true) */
265
+ frameTimedRaycasts?: boolean
266
+ /** Always fire raycaster immediately on scroll events (default: true) */
267
+ alwaysFireOnScroll?: boolean
268
+ /** Automatically re-raycast every frame to detect hover changes from moving objects/camera (default: false) */
269
+ updateOnFrame?: boolean
270
+ /** Flush deferred pointer raycasts. Called by scheduler at frame start (input phase). */
271
+ flush?: () => void
272
+ /** Register an XR pointer (controller/hand). Returns assigned pointerId */
273
+ registerPointer?: (config: XRPointerConfig) => number
274
+ /** Unregister an XR pointer */
275
+ unregisterPointer?: (pointerId: number) => void
276
+ }
277
+
278
+ interface PointerCaptureTarget {
279
+ intersection: Intersection
280
+ target: Element
281
+ }
282
+
283
+ //* Visibility System Types =====================================
284
+
285
+ /** Entry in the visibility registry for tracking object visibility state */
286
+ interface VisibilityEntry {
287
+ object: THREE$1.Object3D
288
+ handlers: Pick<EventHandlers, 'onFramed' | 'onOccluded' | 'onVisible'>
289
+ lastFramedState: boolean | null
290
+ lastOccludedState: boolean | null
291
+ lastVisibleState: boolean | null
292
+ }
293
+
294
+ //* Scheduler Types (useFrame) ==============================
295
+
296
+
297
+
298
+ // Public Options --------------------------------
299
+
300
+ /**
301
+ * Options for useFrame hook
302
+ */
303
+ interface UseFrameNextOptions {
304
+ /** Optional stable id for the job. Auto-generated if not provided */
305
+ id?: string
306
+ /** Named phase to run in. Default: 'update' */
307
+ phase?: string
308
+ /** Run before this phase or job id */
309
+ before?: string | string[]
310
+ /** Run after this phase or job id */
311
+ after?: string | string[]
312
+ /** Priority within phase. Higher runs first. Default: 0 */
313
+ priority?: number
314
+ /** Max frames per second for this job */
315
+ fps?: number
316
+ /** If true, skip frames when behind. If false, try to catch up. Default: true */
317
+ drop?: boolean
318
+ /** Enable/disable without unregistering. Default: true */
319
+ enabled?: boolean
320
+ }
321
+
322
+ /** Alias for UseFrameNextOptions */
323
+ type UseFrameOptions = UseFrameNextOptions
324
+
325
+ /**
326
+ * Options for addPhase
327
+ */
328
+ interface AddPhaseOptions {
329
+ /** Insert this phase before the specified phase */
330
+ before?: string
331
+ /** Insert this phase after the specified phase */
332
+ after?: string
333
+ }
334
+
335
+ // Frame State --------------------------------
336
+
337
+ /**
338
+ * Timing-only state for independent/outside mode (no RootState)
339
+ */
340
+ interface FrameTimingState {
341
+ /** High-resolution timestamp from RAF (ms) */
342
+ time: number
343
+ /** Time since last frame in seconds (for legacy compatibility with THREE.Clock) */
344
+ delta: number
345
+ /** Elapsed time since first frame in seconds (for legacy compatibility with THREE.Clock) */
346
+ elapsed: number
347
+ /** Incrementing frame counter */
348
+ frame: number
349
+ }
350
+
351
+ /**
352
+ * State passed to useFrame callbacks (extends RootState with timing)
353
+ */
354
+ interface FrameNextState extends RootState, FrameTimingState {}
355
+
356
+ /** Alias for FrameNextState */
357
+ type FrameState = FrameNextState
358
+
359
+ // Root Options --------------------------------
360
+
361
+ /**
362
+ * Options for registerRoot
363
+ */
364
+ interface RootOptions {
365
+ /** State provider for callbacks. Optional in independent mode. */
366
+ getState?: () => any
367
+ /** Error handler for job errors. Falls back to console.error if not provided. */
368
+ onError?: (error: Error) => void
369
+ }
370
+
371
+ // Callback Types --------------------------------
372
+
373
+ /**
374
+ * Callback function for useFrame
375
+ */
376
+ type FrameNextCallback = (state: FrameNextState, delta: number) => void
377
+
378
+ /** Alias for FrameNextCallback */
379
+ type FrameCallback = FrameNextCallback
380
+
381
+ // Controls returned from useFrame --------------------------------
382
+
383
+ /**
384
+ * Controls object returned from useFrame hook
385
+ */
386
+ interface FrameNextControls {
387
+ /** The job's unique ID */
388
+ id: string
389
+ /** Access to the global scheduler for frame loop control */
390
+ scheduler: SchedulerApi
391
+ /** Manually step this job only (bypasses FPS limiting) */
392
+ step(timestamp?: number): void
393
+ /** Manually step ALL jobs in the scheduler */
394
+ stepAll(timestamp?: number): void
395
+ /** Pause this job (set enabled=false) */
396
+ pause(): void
397
+ /** Resume this job (set enabled=true) */
398
+ resume(): void
399
+ /** Reactive paused state - automatically triggers re-render when changed */
400
+ isPaused: boolean
401
+ }
402
+
403
+ /** Alias for FrameNextControls */
404
+ type FrameControls = FrameNextControls
405
+
406
+ // Scheduler Interface --------------------------------
407
+
408
+ /**
409
+ * Public interface for the global Scheduler
410
+ */
411
+ interface SchedulerApi {
412
+ //* Phase Management --------------------------------
413
+
414
+ /** Add a named phase to the scheduler */
415
+ addPhase(name: string, options?: AddPhaseOptions): void
416
+ /** Get the ordered list of phase names */
417
+ readonly phases: string[]
418
+ /** Check if a phase exists */
419
+ hasPhase(name: string): boolean
420
+
421
+ //* Root Management --------------------------------
422
+
423
+ /** Register a root (Canvas) with the scheduler. Returns unsubscribe function. */
424
+ registerRoot(id: string, options?: RootOptions): () => void
425
+ /** Unregister a root */
426
+ unregisterRoot(id: string): void
427
+ /** Generate a unique root ID */
428
+ generateRootId(): string
429
+ /** Get the number of registered roots */
430
+ getRootCount(): number
431
+ /** Check if any root is registered and ready */
432
+ readonly isReady: boolean
433
+ /** Subscribe to root-ready event. Fires immediately if already ready. Returns unsubscribe. */
434
+ onRootReady(callback: () => void): () => void
435
+
436
+ //* Job Registration --------------------------------
437
+
438
+ /** Register a job with the scheduler (returns unsubscribe function) */
439
+ register(
440
+ callback: FrameNextCallback,
441
+ options?: {
442
+ id?: string
443
+ rootId?: string
444
+ phase?: string
445
+ before?: string | string[]
446
+ after?: string | string[]
447
+ priority?: number
448
+ fps?: number
449
+ drop?: boolean
450
+ enabled?: boolean
451
+ },
452
+ ): () => void
453
+ /** Update a job's options */
454
+ updateJob(
455
+ id: string,
456
+ options: {
457
+ priority?: number
458
+ fps?: number
459
+ drop?: boolean
460
+ enabled?: boolean
461
+ phase?: string
462
+ before?: string | string[]
463
+ after?: string | string[]
464
+ },
465
+ ): void
466
+ /** Unregister a job by ID */
467
+ unregister(id: string, rootId?: string): void
468
+ /** Get the number of registered jobs */
469
+ getJobCount(): number
470
+ /** Get all job IDs */
471
+ getJobIds(): string[]
472
+
473
+ //* Global Jobs (for legacy addEffect/addAfterEffect) --------------------------------
474
+
475
+ /** Register a global job (runs once per frame, not per-root). Returns unsubscribe function. */
476
+ registerGlobal(phase: 'before' | 'after', id: string, callback: (timestamp: number) => void): () => void
477
+
478
+ //* Idle Callbacks (for legacy addTail) --------------------------------
479
+
480
+ /** Register an idle callback (fires when loop stops). Returns unsubscribe function. */
481
+ onIdle(callback: (timestamp: number) => void): () => void
482
+
483
+ //* Frame Loop Control --------------------------------
484
+
485
+ /** Start the scheduler loop */
486
+ start(): void
487
+ /** Stop the scheduler loop */
488
+ stop(): void
489
+ /** Check if the scheduler is running */
490
+ readonly isRunning: boolean
491
+ /** Get/set the frameloop mode ('always', 'demand', 'never') */
492
+ frameloop: Frameloop
493
+ /** Independent mode - runs without Canvas, callbacks receive timing-only state */
494
+ independent: boolean
495
+
496
+ //* Manual Stepping --------------------------------
497
+
498
+ /** Manually step all jobs once (for frameloop='never' or testing) */
499
+ step(timestamp?: number): void
500
+ /** Manually step a single job by ID */
501
+ stepJob(id: string, timestamp?: number): void
502
+ /** Request frame(s) to be rendered (for frameloop='demand') */
503
+ invalidate(frames?: number): void
504
+
505
+ //* Per-Job Control --------------------------------
506
+
507
+ /** Check if a job is paused */
508
+ isJobPaused(id: string): boolean
509
+ /** Pause a job */
510
+ pauseJob(id: string): void
511
+ /** Resume a job */
512
+ resumeJob(id: string): void
513
+ /** Subscribe to job state changes (for reactive isPaused). Returns unsubscribe function. */
514
+ subscribeJobState(id: string, listener: () => void): () => void
515
+ }
516
+
517
+ //* Buffer Types (useBuffers) ========================================
518
+
519
+ /**
520
+ * Buffer-like types for GPU compute and storage operations.
521
+ * Includes raw CPU arrays, Three.js buffer attributes, and TSL buffer nodes.
522
+ *
523
+ * @example
524
+ * ```tsx
525
+ * const { positions, velocities } = useBuffers(() => ({
526
+ * positions: instancedArray(count, 'vec3'), // StorageBufferNode
527
+ * velocities: new Float32Array(count * 3), // TypedArray
528
+ * }), 'particles')
529
+ * ```
530
+ */
531
+ type BufferLike =
532
+ | Float32Array
533
+ | Uint32Array
534
+ | Int32Array
535
+ | Float64Array
536
+ | Uint8Array
537
+ | Int8Array
538
+ | Uint16Array
539
+ | Int16Array
540
+ | THREE$1.BufferAttribute // Base class for all buffer attributes
541
+ | Node // TSL buffer nodes (instancedArray, storage)
542
+
543
+ /** Flat record of buffer-like values (no nested scopes) */
544
+ type BufferRecord = Record<string, BufferLike>
545
+
546
+ /**
547
+ * Buffer store that can contain both root-level buffers and scoped buffer objects.
548
+ * Structure: { positions: Float32Array, particles: { vel: StorageBufferNode } }
549
+ */
550
+ type BufferStore = Record<string, BufferLike | BufferRecord>
551
+
552
+ //* Storage Types (useGPUStorage) ========================================
553
+
554
+ /**
555
+ * GPU storage types for texture-based storage operations.
556
+ * Includes Three.js storage textures and TSL storage texture nodes.
557
+ *
558
+ * @example
559
+ * ```tsx
560
+ * const { heightMap } = useGPUStorage(() => ({
561
+ * heightMap: new StorageTexture(512, 512),
562
+ * }), 'terrain')
563
+ * ```
564
+ */
565
+ type StorageLike =
566
+ | StorageTexture // GPU storage texture
567
+ | Data3DTexture // 3D texture (can be used as storage)
568
+ | Node // TSL storage texture nodes (storageTexture)
569
+
570
+ /** Flat record of storage-like values (no nested scopes) */
571
+ type StorageRecord = Record<string, StorageLike>
572
+
573
+ /**
574
+ * Storage store that can contain both root-level storage and scoped storage objects.
575
+ * Structure: { heightMap: StorageTexture, terrain: { normal: StorageTextureNode } }
576
+ */
577
+ type StorageStore = Record<string, StorageLike | StorageRecord>
578
+
579
+ //* Renderer Types ========================================
580
+
581
+ /** Default renderer type - union of WebGL and WebGPU renderers */
582
+ type R3FRenderer = THREE$1.WebGLRenderer | WebGPURenderer
583
+
584
+ //* Core Store Types ========================================
585
+
586
+ type Subscription = {
587
+ ref: React$1.RefObject<RenderCallback>
588
+ priority: number
589
+ store: RootStore
590
+ }
591
+
592
+ /** Per-pointer state for multi-touch and XR support */
593
+ type PointerState = {
594
+ /** Objects currently hovered by this pointer */
595
+ hovered: Map<string, ThreeEvent<DomEvent>>
596
+ /** Objects capturing this pointer */
597
+ captured: Map<THREE$1.Object3D, PointerCaptureTarget>
598
+ /** Initial click position [x, y] */
599
+ initialClick: [x: number, y: number]
600
+ /** Objects hit on initial click */
601
+ initialHits: THREE$1.Object3D[]
602
+ }
603
+
604
+ type Dpr = number | [min: number, max: number]
605
+
606
+ interface Size {
607
+ width: number
608
+ height: number
609
+ top: number
610
+ left: number
611
+ }
612
+
613
+ type Frameloop = 'always' | 'demand' | 'never'
614
+
615
+ interface Viewport extends Size {
616
+ /** The initial pixel ratio */
617
+ initialDpr: number
618
+ /** Current pixel ratio */
619
+ dpr: number
620
+ /** size.width / viewport.width */
621
+ factor: number
622
+ /** Camera distance */
623
+ distance: number
624
+ /** Camera aspect ratio: width / height */
625
+ aspect: number
626
+ }
627
+
628
+ type RenderCallback = (state: RootState, delta: number, frame?: XRFrame) => void
629
+
630
+ interface Performance {
631
+ /** Current performance normal, between min and max */
632
+ current: number
633
+ /** How low the performance can go, between 0 and max */
634
+ min: number
635
+ /** How high the performance can go, between min and max */
636
+ max: number
637
+ /** Time until current returns to max in ms */
638
+ debounce: number
639
+ /** Sets current to min, puts the system in regression */
640
+ regress: () => void
641
+ }
642
+
643
+ interface InternalState {
644
+ interaction: THREE$1.Object3D[]
645
+ subscribers: Subscription[]
646
+ /** Per-pointer state (hover, capture, click tracking) - replaces hovered, capturedMap, initialClick, initialHits */
647
+ pointerMap: Map<number, PointerState>
648
+ /** Pointers needing raycast this frame (used with frameTimedRaycasts) */
649
+ pointerDirty: Map<number, DomEvent>
650
+ /** Last event received (for events.update() compatibility) */
651
+ lastEvent: React$1.RefObject<DomEvent | null>
652
+ /** @deprecated Use pointerMap.get(pointerId).hovered instead */
653
+ hovered: Map<string, ThreeEvent<DomEvent>>
654
+ /** @deprecated Use pointerMap.get(pointerId).captured instead */
655
+ capturedMap: Map<number, Map<THREE$1.Object3D, PointerCaptureTarget>>
656
+ /** @deprecated Use pointerMap.get(pointerId).initialClick instead */
657
+ initialClick: [x: number, y: number]
658
+ /** @deprecated Use pointerMap.get(pointerId).initialHits instead */
659
+ initialHits: THREE$1.Object3D[]
660
+ /** Visibility event registry (onFramed, onOccluded, onVisible) */
661
+ visibilityRegistry: Map<string, VisibilityEntry>
662
+ /** Whether occlusion queries are enabled (WebGPU only) */
663
+ occlusionEnabled: boolean
664
+ /** Reference to the invisible occlusion observer mesh */
665
+ occlusionObserver: THREE$1.Mesh | null
666
+ /** Cached occlusion results from render pass - keyed by Object3D */
667
+ occlusionCache: Map<THREE$1.Object3D, boolean | null>
668
+ /** Internal helper group for R3F system objects (occlusion observer, etc.) */
669
+ helperGroup: THREE$1.Group | null
670
+ active: boolean
671
+ priority: number
672
+ frames: number
673
+ subscribe: (callback: React$1.RefObject<RenderCallback>, priority: number, store: RootStore) => () => void
674
+ /** Internal renderer storage - use state.renderer or state.gl to access */
675
+ actualRenderer: R3FRenderer
676
+ /** Global scheduler reference (for useFrame hook) */
677
+ scheduler: SchedulerApi | null
678
+ /** This root's unique ID in the global scheduler */
679
+ rootId?: string
680
+ /** Function to unregister this root from the global scheduler */
681
+ unregisterRoot?: () => void
682
+ /** Container for child attachment (scene for root, original container for portals) */
683
+ container?: THREE$1.Object3D
684
+ /**
685
+ * CanvasTarget for multi-canvas WebGPU rendering.
686
+ * Created for all WebGPU canvases to support renderer sharing.
687
+ * @see https://threejs.org/docs/#api/en/renderers/common/CanvasTarget
688
+ */
689
+ canvasTarget?: CanvasTarget
690
+ /**
691
+ * Whether multi-canvas rendering is active.
692
+ * True when any canvas uses `target` prop to share a renderer.
693
+ * When true, setCanvasTarget is called before each render.
694
+ */
695
+ isMultiCanvas?: boolean
696
+ /**
697
+ * Whether this canvas is a secondary canvas sharing another's renderer.
698
+ * True when `target` prop is used.
699
+ */
700
+ isSecondary?: boolean
701
+ /**
702
+ * The id of the primary canvas this secondary canvas targets.
703
+ * Only set when isSecondary is true.
704
+ */
705
+ targetId?: string
706
+ /**
707
+ * Function to unregister this primary canvas from the registry.
708
+ * Only set when this canvas has an `id` prop.
709
+ */
710
+ unregisterPrimary?: () => void
711
+ /** Whether canvas dimensions are forced to even numbers */
712
+ forceEven?: boolean
713
+ }
714
+
715
+ interface XRManager {
716
+ connect: () => void
717
+ disconnect: () => void
718
+ }
719
+
720
+ //* Root State Interface ====================================
721
+
722
+ interface RootState {
723
+ /** Set current state */
724
+ set: StoreApi<RootState>['setState']
725
+ /** Get current state */
726
+ get: StoreApi<RootState>['getState']
727
+ /**
728
+ * Reference to the authoritative store for shared TSL resources (uniforms, nodes, etc).
729
+ * - For primary/independent canvases: points to its own store (self-reference)
730
+ * - For secondary canvases: points to the primary canvas's store
731
+ *
732
+ * Hooks like useNodes/useUniforms should read from primaryStore to ensure
733
+ * consistent shared state across all canvases sharing a renderer.
734
+ */
735
+ primaryStore: RootStore
736
+ /** @deprecated Use `renderer` instead. The instance of the renderer (typed as WebGLRenderer for backwards compat) */
737
+ gl: THREE$1.WebGLRenderer
738
+ /** The renderer instance - type depends on entry point (WebGPU, Legacy, or union for default) */
739
+ renderer: R3FRenderer
740
+ /** Inspector of the webGPU Renderer. Init in the canvas */
741
+ inspector: any // Inspector type from three/webgpu
742
+
743
+ /** Default camera */
744
+ camera: ThreeCamera
745
+ /** Camera frustum for visibility checks - auto-updated each frame when autoUpdateFrustum is true */
746
+ frustum: THREE$1.Frustum
747
+ /** Whether to automatically update the frustum each frame (default: true) */
748
+ autoUpdateFrustum: boolean
749
+ /** Default scene (may be overridden in portals to point to the portal container) */
750
+ scene: THREE$1.Scene
751
+ /** The actual root THREE.Scene - always points to the true scene, even inside portals */
752
+ rootScene: THREE$1.Scene
753
+ /** Default raycaster */
754
+ raycaster: THREE$1.Raycaster
755
+ /** Event layer interface, contains the event handler and the node they're connected to */
756
+ events: EventManager<any>
757
+ /** XR interface */
758
+ xr: XRManager
759
+ /** Currently used controls */
760
+ controls: THREE$1.EventDispatcher | null
761
+ /** Normalized event coordinates */
762
+ pointer: THREE$1.Vector2
763
+ /** @deprecated Normalized event coordinates, use "pointer" instead! */
764
+ mouse: THREE$1.Vector2
765
+ /** Color space assigned to 8-bit input textures (color maps). Most textures are authored in sRGB. */
766
+ textureColorSpace: THREE$1.ColorSpace
767
+ /** Render loop flags */
768
+ frameloop: Frameloop
769
+ performance: Performance
770
+ /** Reactive pixel-size of the canvas */
771
+ size: Size
772
+ /** Reactive size of the viewport in threejs units */
773
+ viewport: Viewport & {
774
+ getCurrentViewport: (
775
+ camera?: ThreeCamera,
776
+ target?: THREE$1.Vector3 | Parameters<THREE$1.Vector3['set']>,
777
+ size?: Size,
778
+ ) => Omit<Viewport, 'dpr' | 'initialDpr'>
779
+ }
780
+ /** Flags the canvas for render, but doesn't render in itself */
781
+ invalidate: (frames?: number, stackFrames?: boolean) => void
782
+ /** Advance (render) one step */
783
+ advance: (timestamp: number, runGlobalEffects?: boolean) => void
784
+ /** Shortcut to setting the event layer */
785
+ setEvents: (events: Partial<EventManager<any>>) => void
786
+ /** Shortcut to manual sizing. No args resets to props/container. Single arg creates square. */
787
+ setSize: (width?: number, height?: number, top?: number, left?: number) => void
788
+ /** Shortcut to manual setting the pixel ratio */
789
+ setDpr: (dpr: Dpr) => void
790
+ /** Shortcut to setting frameloop flags */
791
+ setFrameloop: (frameloop: Frameloop) => void
792
+ /** Set error state to propagate to error boundary */
793
+ setError: (error: Error | null) => void
794
+ /** Current error state (null when no error) */
795
+ error: Error | null
796
+ /** Global TSL uniform nodes - root-level uniforms + scoped sub-objects. Use useUniforms() hook */
797
+ uniforms: UniformStore
798
+ /** Global TSL nodes - root-level nodes + scoped sub-objects. Use useNodes() hook */
799
+ nodes: Record<string, any>
800
+ /** Global TSL buffer nodes - root-level buffers + scoped sub-objects. Use useBuffers() hook */
801
+ buffers: BufferStore
802
+ /** Global GPU storage (textures, etc.) - root-level storage + scoped sub-objects. Use useGPUStorage() hook */
803
+ gpuStorage: StorageStore
804
+ /** Global TSL texture nodes - use useTextures() hook for operations */
805
+ textures: Map<string, any>
806
+ /** WebGPU RenderPipeline instance - use useRenderPipeline() hook */
807
+ renderPipeline: any | null // THREE.PostProcessing (will be THREE.RenderPipeline in future Three.js release)
808
+ /** Global TSL pass nodes for render pipeline - use useRenderPipeline() hook */
809
+ passes: Record<string, any>
810
+ /** Internal version counter for HMR - incremented by rebuildNodes/rebuildUniforms to bust memoization */
811
+ _hmrVersion: number
812
+ /** Internal: whether setSize() has taken ownership of canvas dimensions */
813
+ _sizeImperative: boolean
814
+ /** Internal: stored size props from Canvas for reset functionality */
815
+ _sizeProps: { width?: number; height?: number } | null
816
+ /** When the canvas was clicked but nothing was hit */
817
+ onPointerMissed?: (event: MouseEvent) => void
818
+ /** When a dragover event has missed any target */
819
+ onDragOverMissed?: (event: DragEvent) => void
820
+ /** When a drop event has missed any target */
821
+ onDropMissed?: (event: DragEvent) => void
822
+ /** If this state model is layered (via createPortal) then this contains the previous layer */
823
+ previousRoot?: RootStore
824
+ /** Internals */
825
+ internal: InternalState
826
+ // flags for triggers
827
+ // if we are using the webGl renderer, this will be true
828
+ isLegacy: boolean
829
+ // regardless of renderer, if the system supports webGpu, this will be true
830
+ webGPUSupported: boolean
831
+ //if we are on native
832
+ isNative: boolean
515
833
  }
516
834
 
517
- //* Buffer Types (useBuffers) ========================================
518
-
519
- /**
520
- * Buffer-like types for GPU compute and storage operations.
521
- * Includes raw CPU arrays, Three.js buffer attributes, and TSL buffer nodes.
522
- *
523
- * @example
524
- * ```tsx
525
- * const { positions, velocities } = useBuffers(() => ({
526
- * positions: instancedArray(count, 'vec3'), // StorageBufferNode
527
- * velocities: new Float32Array(count * 3), // TypedArray
528
- * }), 'particles')
529
- * ```
530
- */
531
- type BufferLike =
532
- | Float32Array
533
- | Uint32Array
534
- | Int32Array
535
- | Float64Array
536
- | Uint8Array
537
- | Int8Array
538
- | Uint16Array
539
- | Int16Array
540
- | THREE$1.BufferAttribute // Base class for all buffer attributes
541
- | Node // TSL buffer nodes (instancedArray, storage)
542
-
543
- /** Flat record of buffer-like values (no nested scopes) */
544
- type BufferRecord = Record<string, BufferLike>
545
-
546
- /**
547
- * Buffer store that can contain both root-level buffers and scoped buffer objects.
548
- * Structure: { positions: Float32Array, particles: { vel: StorageBufferNode } }
549
- */
550
- type BufferStore = Record<string, BufferLike | BufferRecord>
551
-
552
- //* Storage Types (useGPUStorage) ========================================
553
-
554
- /**
555
- * GPU storage types for texture-based storage operations.
556
- * Includes Three.js storage textures and TSL storage texture nodes.
557
- *
558
- * @example
559
- * ```tsx
560
- * const { heightMap } = useGPUStorage(() => ({
561
- * heightMap: new StorageTexture(512, 512),
562
- * }), 'terrain')
563
- * ```
564
- */
565
- type StorageLike =
566
- | StorageTexture // GPU storage texture
567
- | Data3DTexture // 3D texture (can be used as storage)
568
- | Node // TSL storage texture nodes (storageTexture)
569
-
570
- /** Flat record of storage-like values (no nested scopes) */
571
- type StorageRecord = Record<string, StorageLike>
572
-
573
- /**
574
- * Storage store that can contain both root-level storage and scoped storage objects.
575
- * Structure: { heightMap: StorageTexture, terrain: { normal: StorageTextureNode } }
576
- */
577
- type StorageStore = Record<string, StorageLike | StorageRecord>
578
-
579
- //* Renderer Types ========================================
580
-
581
- /** Default renderer type - union of WebGL and WebGPU renderers */
582
- type R3FRenderer = THREE$1.WebGLRenderer | WebGPURenderer
583
-
584
- //* Core Store Types ========================================
585
-
586
- type Subscription = {
587
- ref: React$1.RefObject<RenderCallback>
588
- priority: number
589
- store: RootStore
590
- }
591
-
592
- /** Per-pointer state for multi-touch and XR support */
593
- type PointerState = {
594
- /** Objects currently hovered by this pointer */
595
- hovered: Map<string, ThreeEvent<DomEvent>>
596
- /** Objects capturing this pointer */
597
- captured: Map<THREE$1.Object3D, PointerCaptureTarget>
598
- /** Initial click position [x, y] */
599
- initialClick: [x: number, y: number]
600
- /** Objects hit on initial click */
601
- initialHits: THREE$1.Object3D[]
602
- }
603
-
604
- type Dpr = number | [min: number, max: number]
605
-
606
- interface Size {
607
- width: number
608
- height: number
609
- top: number
610
- left: number
611
- }
612
-
613
- type Frameloop = 'always' | 'demand' | 'never'
614
-
615
- interface Viewport extends Size {
616
- /** The initial pixel ratio */
617
- initialDpr: number
618
- /** Current pixel ratio */
619
- dpr: number
620
- /** size.width / viewport.width */
621
- factor: number
622
- /** Camera distance */
623
- distance: number
624
- /** Camera aspect ratio: width / height */
625
- aspect: number
626
- }
627
-
628
- type RenderCallback = (state: RootState, delta: number, frame?: XRFrame) => void
629
-
630
- interface Performance {
631
- /** Current performance normal, between min and max */
632
- current: number
633
- /** How low the performance can go, between 0 and max */
634
- min: number
635
- /** How high the performance can go, between min and max */
636
- max: number
637
- /** Time until current returns to max in ms */
638
- debounce: number
639
- /** Sets current to min, puts the system in regression */
640
- regress: () => void
641
- }
642
-
643
- interface InternalState {
644
- interaction: THREE$1.Object3D[]
645
- subscribers: Subscription[]
646
- /** Per-pointer state (hover, capture, click tracking) - replaces hovered, capturedMap, initialClick, initialHits */
647
- pointerMap: Map<number, PointerState>
648
- /** Pointers needing raycast this frame (used with frameTimedRaycasts) */
649
- pointerDirty: Map<number, DomEvent>
650
- /** Last event received (for events.update() compatibility) */
651
- lastEvent: React$1.RefObject<DomEvent | null>
652
- /** @deprecated Use pointerMap.get(pointerId).hovered instead */
653
- hovered: Map<string, ThreeEvent<DomEvent>>
654
- /** @deprecated Use pointerMap.get(pointerId).captured instead */
655
- capturedMap: Map<number, Map<THREE$1.Object3D, PointerCaptureTarget>>
656
- /** @deprecated Use pointerMap.get(pointerId).initialClick instead */
657
- initialClick: [x: number, y: number]
658
- /** @deprecated Use pointerMap.get(pointerId).initialHits instead */
659
- initialHits: THREE$1.Object3D[]
660
- /** Visibility event registry (onFramed, onOccluded, onVisible) */
661
- visibilityRegistry: Map<string, VisibilityEntry>
662
- /** Whether occlusion queries are enabled (WebGPU only) */
663
- occlusionEnabled: boolean
664
- /** Reference to the invisible occlusion observer mesh */
665
- occlusionObserver: THREE$1.Mesh | null
666
- /** Cached occlusion results from render pass - keyed by Object3D */
667
- occlusionCache: Map<THREE$1.Object3D, boolean | null>
668
- /** Internal helper group for R3F system objects (occlusion observer, etc.) */
669
- helperGroup: THREE$1.Group | null
670
- active: boolean
671
- priority: number
672
- frames: number
673
- subscribe: (callback: React$1.RefObject<RenderCallback>, priority: number, store: RootStore) => () => void
674
- /** Internal renderer storage - use state.renderer or state.gl to access */
675
- actualRenderer: R3FRenderer
676
- /** Global scheduler reference (for useFrame hook) */
677
- scheduler: SchedulerApi | null
678
- /** This root's unique ID in the global scheduler */
679
- rootId?: string
680
- /** Function to unregister this root from the global scheduler */
681
- unregisterRoot?: () => void
682
- /** Container for child attachment (scene for root, original container for portals) */
683
- container?: THREE$1.Object3D
684
- /**
685
- * CanvasTarget for multi-canvas WebGPU rendering.
686
- * Created for all WebGPU canvases to support renderer sharing.
687
- * @see https://threejs.org/docs/#api/en/renderers/common/CanvasTarget
688
- */
689
- canvasTarget?: CanvasTarget
690
- /**
691
- * Whether multi-canvas rendering is active.
692
- * True when any canvas uses `target` prop to share a renderer.
693
- * When true, setCanvasTarget is called before each render.
694
- */
695
- isMultiCanvas?: boolean
696
- /**
697
- * Whether this canvas is a secondary canvas sharing another's renderer.
698
- * True when `target` prop is used.
699
- */
700
- isSecondary?: boolean
701
- /**
702
- * The id of the primary canvas this secondary canvas targets.
703
- * Only set when isSecondary is true.
704
- */
705
- targetId?: string
706
- /**
707
- * Function to unregister this primary canvas from the registry.
708
- * Only set when this canvas has an `id` prop.
709
- */
710
- unregisterPrimary?: () => void
711
- /** Whether canvas dimensions are forced to even numbers */
712
- forceEven?: boolean
713
- }
714
-
715
- interface XRManager {
716
- connect: () => void
717
- disconnect: () => void
718
- }
719
-
720
- //* Root State Interface ====================================
721
-
722
- interface RootState {
723
- /** Set current state */
724
- set: StoreApi<RootState>['setState']
725
- /** Get current state */
726
- get: StoreApi<RootState>['getState']
727
- /**
728
- * Reference to the authoritative store for shared TSL resources (uniforms, nodes, etc).
729
- * - For primary/independent canvases: points to its own store (self-reference)
730
- * - For secondary canvases: points to the primary canvas's store
731
- *
732
- * Hooks like useNodes/useUniforms should read from primaryStore to ensure
733
- * consistent shared state across all canvases sharing a renderer.
734
- */
735
- primaryStore: RootStore
736
- /** @deprecated Use `renderer` instead. The instance of the renderer (typed as WebGLRenderer for backwards compat) */
737
- gl: THREE$1.WebGLRenderer
738
- /** The renderer instance - type depends on entry point (WebGPU, Legacy, or union for default) */
739
- renderer: R3FRenderer
740
- /** Inspector of the webGPU Renderer. Init in the canvas */
741
- inspector: any // Inspector type from three/webgpu
742
-
743
- /** Default camera */
744
- camera: ThreeCamera
745
- /** Camera frustum for visibility checks - auto-updated each frame when autoUpdateFrustum is true */
746
- frustum: THREE$1.Frustum
747
- /** Whether to automatically update the frustum each frame (default: true) */
748
- autoUpdateFrustum: boolean
749
- /** Default scene (may be overridden in portals to point to the portal container) */
750
- scene: THREE$1.Scene
751
- /** The actual root THREE.Scene - always points to the true scene, even inside portals */
752
- rootScene: THREE$1.Scene
753
- /** Default raycaster */
754
- raycaster: THREE$1.Raycaster
755
- /** Event layer interface, contains the event handler and the node they're connected to */
756
- events: EventManager<any>
757
- /** XR interface */
758
- xr: XRManager
759
- /** Currently used controls */
760
- controls: THREE$1.EventDispatcher | null
761
- /** Normalized event coordinates */
762
- pointer: THREE$1.Vector2
763
- /** @deprecated Normalized event coordinates, use "pointer" instead! */
764
- mouse: THREE$1.Vector2
765
- /** Color space assigned to 8-bit input textures (color maps). Most textures are authored in sRGB. */
766
- textureColorSpace: THREE$1.ColorSpace
767
- /** Render loop flags */
768
- frameloop: Frameloop
769
- performance: Performance
770
- /** Reactive pixel-size of the canvas */
771
- size: Size
772
- /** Reactive size of the viewport in threejs units */
773
- viewport: Viewport & {
774
- getCurrentViewport: (
775
- camera?: ThreeCamera,
776
- target?: THREE$1.Vector3 | Parameters<THREE$1.Vector3['set']>,
777
- size?: Size,
778
- ) => Omit<Viewport, 'dpr' | 'initialDpr'>
779
- }
780
- /** Flags the canvas for render, but doesn't render in itself */
781
- invalidate: (frames?: number, stackFrames?: boolean) => void
782
- /** Advance (render) one step */
783
- advance: (timestamp: number, runGlobalEffects?: boolean) => void
784
- /** Shortcut to setting the event layer */
785
- setEvents: (events: Partial<EventManager<any>>) => void
786
- /** Shortcut to manual sizing. No args resets to props/container. Single arg creates square. */
787
- setSize: (width?: number, height?: number, top?: number, left?: number) => void
788
- /** Shortcut to manual setting the pixel ratio */
789
- setDpr: (dpr: Dpr) => void
790
- /** Shortcut to setting frameloop flags */
791
- setFrameloop: (frameloop: Frameloop) => void
792
- /** Set error state to propagate to error boundary */
793
- setError: (error: Error | null) => void
794
- /** Current error state (null when no error) */
795
- error: Error | null
796
- /** Global TSL uniform nodes - root-level uniforms + scoped sub-objects. Use useUniforms() hook */
797
- uniforms: UniformStore
798
- /** Global TSL nodes - root-level nodes + scoped sub-objects. Use useNodes() hook */
799
- nodes: Record<string, any>
800
- /** Global TSL buffer nodes - root-level buffers + scoped sub-objects. Use useBuffers() hook */
801
- buffers: BufferStore
802
- /** Global GPU storage (textures, etc.) - root-level storage + scoped sub-objects. Use useGPUStorage() hook */
803
- gpuStorage: StorageStore
804
- /** Global TSL texture nodes - use useTextures() hook for operations */
805
- textures: Map<string, any>
806
- /** WebGPU RenderPipeline instance - use useRenderPipeline() hook */
807
- renderPipeline: any | null // THREE.PostProcessing (will be THREE.RenderPipeline in future Three.js release)
808
- /** Global TSL pass nodes for render pipeline - use useRenderPipeline() hook */
809
- passes: Record<string, any>
810
- /** Internal version counter for HMR - incremented by rebuildNodes/rebuildUniforms to bust memoization */
811
- _hmrVersion: number
812
- /** Internal: whether setSize() has taken ownership of canvas dimensions */
813
- _sizeImperative: boolean
814
- /** Internal: stored size props from Canvas for reset functionality */
815
- _sizeProps: { width?: number; height?: number } | null
816
- /** When the canvas was clicked but nothing was hit */
817
- onPointerMissed?: (event: MouseEvent) => void
818
- /** When a dragover event has missed any target */
819
- onDragOverMissed?: (event: DragEvent) => void
820
- /** When a drop event has missed any target */
821
- onDropMissed?: (event: DragEvent) => void
822
- /** If this state model is layered (via createPortal) then this contains the previous layer */
823
- previousRoot?: RootStore
824
- /** Internals */
825
- internal: InternalState
826
- // flags for triggers
827
- // if we are using the webGl renderer, this will be true
828
- isLegacy: boolean
829
- // regardless of renderer, if the system supports webGpu, this will be true
830
- webGPUSupported: boolean
831
- //if we are on native
832
- isNative: boolean
833
- }
834
-
835
835
  type RootStore = UseBoundStoreWithEqualityFn<StoreApi<RootState>>
836
836
 
837
- //* Base Renderer Types =====================================
838
-
839
- // Shim for OffscreenCanvas since it was removed from DOM types
840
- interface OffscreenCanvas$1 extends EventTarget {}
841
-
842
- interface BaseRendererProps {
843
- canvas: HTMLCanvasElement | OffscreenCanvas$1
844
- powerPreference?: 'high-performance' | 'low-power' | 'default'
845
- antialias?: boolean
846
- alpha?: boolean
847
- }
848
-
849
- type RendererFactory<TRenderer, TParams> =
850
- | TRenderer
851
- | ((defaultProps: TParams) => TRenderer)
852
- | ((defaultProps: TParams) => Promise<TRenderer>)
853
-
854
- interface Renderer {
855
- render: (scene: THREE$1.Scene, camera: THREE$1.Camera) => any
856
- }
857
-
858
- //* Color Management Config ==============================
859
-
860
- /**
861
- * Color management configuration shared by both WebGL and WebGPU renderers.
862
- */
863
- interface ColorManagementConfig {
864
- /**
865
- * Color space assigned to 8-bit input textures (color maps).
866
- * Defaults to sRGB. Most textures are authored in sRGB.
867
- * @default THREE.SRGBColorSpace
868
- */
869
- textureColorSpace?: THREE$1.ColorSpace
870
- }
871
-
872
- //* WebGL Renderer Props ==============================
873
-
874
- type DefaultGLProps = Omit<THREE$1.WebGLRendererParameters, 'canvas'> & {
875
- canvas: HTMLCanvasElement | OffscreenCanvas$1
876
- }
877
-
878
- type GLProps =
879
- | Renderer
880
- | ((defaultProps: DefaultGLProps) => Renderer)
881
- | ((defaultProps: DefaultGLProps) => Promise<Renderer>)
882
- | (Partial<Properties<THREE$1.WebGLRenderer> | THREE$1.WebGLRendererParameters> & ColorManagementConfig)
883
-
884
- //* WebGPU Renderer Props ==============================
885
-
886
- type DefaultRendererProps = {
887
- canvas: HTMLCanvasElement | OffscreenCanvas$1
888
- [key: string]: any
889
- }
890
-
891
- /**
892
- * Canvas-level scheduler configuration.
893
- * Controls render timing relative to other canvases.
894
- */
895
- interface CanvasSchedulerConfig {
896
- /**
897
- * Render this canvas after another canvas completes.
898
- * Pass the `id` of another canvas.
899
- */
900
- after?: string
901
- /**
902
- * Limit this canvas's render rate (frames per second).
903
- */
904
- fps?: number
905
- }
906
-
907
- /**
908
- * Extended renderer configuration for multi-canvas support and color management.
909
- */
910
- interface RendererConfigExtended extends ColorManagementConfig {
911
- /** Share renderer from another canvas (WebGPU only) */
912
- primaryCanvas?: string
913
- /** Canvas-level scheduler options */
914
- scheduler?: CanvasSchedulerConfig
915
- }
916
-
917
- type RendererProps =
918
- | any // WebGPURenderer
919
- | ((defaultProps: DefaultRendererProps) => any)
920
- | ((defaultProps: DefaultRendererProps) => Promise<any>)
921
- | (Partial<Properties<any> | Record<string, any>> & RendererConfigExtended)
922
-
923
- //* Camera Props ==============================
924
-
925
- type CameraProps = (
926
- | THREE$1.Camera
927
- | Partial<
928
- ThreeElement<typeof THREE$1.Camera> &
929
- ThreeElement<typeof THREE$1.PerspectiveCamera> &
930
- ThreeElement<typeof THREE$1.OrthographicCamera>
931
- >
932
- ) & {
933
- /** Flags the camera as manual, putting projection into your own hands */
934
- manual?: boolean
935
- }
936
-
937
- //* Render Props ==============================
938
-
939
- interface RenderProps<TCanvas extends HTMLCanvasElement | OffscreenCanvas$1> {
940
- /**
941
- * Unique identifier for multi-canvas renderer sharing.
942
- * Makes this canvas targetable by other canvases using the `primaryCanvas` prop.
943
- * Also sets the HTML `id` attribute on the canvas element.
944
- * @example <Canvas id="main-viewer">...</Canvas>
945
- */
946
- id?: string
947
- /**
948
- * Share the renderer from another canvas instead of creating a new one.
949
- * Pass the `id` of the primary canvas to share its WebGPURenderer.
950
- * Only available with WebGPU (not legacy WebGL).
951
- *
952
- * Note: This is extracted from `renderer={{ primaryCanvas: "id" }}` by Canvas.
953
- * @internal
954
- */
955
- primaryCanvas?: string
956
- /**
957
- * Canvas-level scheduler options. Controls render timing relative to other canvases.
958
- *
959
- * Note: This is extracted from `renderer={{ scheduler: {...} }}` by Canvas.
960
- * @internal
961
- */
962
- scheduler?: CanvasSchedulerConfig
963
- /** A threejs renderer instance or props that go into the default renderer */
964
- gl?: GLProps
965
- /** A WebGPU renderer instance or props that go into the default renderer */
966
- renderer?: RendererProps
967
- /** Dimensions to fit the renderer to. Will measure canvas dimensions if omitted */
968
- size?: Size
969
- /**
970
- * Enables shadows (by default PCFsoft). Can accept `gl.shadowMap` options for fine-tuning,
971
- * but also strings: 'basic' | 'percentage' | 'soft' | 'variance'.
972
- * @see https://threejs.org/docs/#api/en/renderers/WebGLRenderer.shadowMap
973
- */
974
- shadows?: boolean | 'basic' | 'percentage' | 'soft' | 'variance' | Partial<THREE$1.WebGLShadowMap>
975
- /** Creates an orthographic camera */
976
- orthographic?: boolean
977
- /**
978
- * R3F's render mode. Set to `demand` to only render on state change or `never` to take control.
979
- * @see https://docs.pmnd.rs/react-three-fiber/advanced/scaling-performance#on-demand-rendering
980
- */
981
- frameloop?: Frameloop
982
- /**
983
- * R3F performance options for adaptive performance.
984
- * @see https://docs.pmnd.rs/react-three-fiber/advanced/scaling-performance#movement-regression
985
- */
986
- performance?: Partial<Omit<Performance, 'regress'>>
987
- /** Target pixel ratio. Can clamp between a range: `[min, max]` */
988
- dpr?: Dpr
989
- /** Props that go into the default raycaster */
990
- raycaster?: Partial<THREE$1.Raycaster>
991
- /** A `THREE.Scene` instance or props that go into the default scene */
992
- scene?: THREE$1.Scene | Partial<THREE$1.Scene>
993
- /** A `THREE.Camera` instance or props that go into the default camera */
994
- camera?: CameraProps
995
- /** An R3F event manager to manage elements' pointer events */
996
- events?: (store: RootStore) => EventManager<HTMLElement>
997
- /** Callback after the canvas has rendered (but not yet committed) */
998
- onCreated?: (state: RootState) => void
999
- /** Response for pointer clicks that have missed any target */
1000
- onPointerMissed?: (event: MouseEvent) => void
1001
- /** Response for dragover events that have missed any target */
1002
- onDragOverMissed?: (event: DragEvent) => void
1003
- /** Response for drop events that have missed any target */
1004
- onDropMissed?: (event: DragEvent) => void
1005
- /** Whether to automatically update the frustum each frame (default: true) */
1006
- autoUpdateFrustum?: boolean
1007
- /**
1008
- * Enable WebGPU occlusion queries for onOccluded/onVisible events.
1009
- * Auto-enabled when any object uses onOccluded or onVisible handlers.
1010
- * Only works with WebGPU renderer - WebGL will log a warning.
1011
- */
1012
- occlusion?: boolean
1013
- /** Internal: stored size props from Canvas for reset functionality */
1014
- _sizeProps?: { width?: number; height?: number } | null
1015
- /** Force canvas dimensions to even numbers (fixes Safari rendering issues with odd/fractional sizes) */
1016
- forceEven?: boolean
1017
- }
1018
-
1019
- //* Reconciler Root ==============================
1020
-
1021
- interface ReconcilerRoot<TCanvas extends HTMLCanvasElement | OffscreenCanvas$1> {
1022
- configure: (config?: RenderProps<TCanvas>) => Promise<ReconcilerRoot<TCanvas>>
1023
- render: (element: ReactNode) => RootStore
1024
- unmount: () => void
1025
- }
1026
-
1027
- //* Inject State ==============================
1028
-
1029
- type InjectState = Partial<
1030
- Omit<RootState, 'events'> & {
1031
- events?: {
1032
- enabled?: boolean
1033
- priority?: number
1034
- compute?: ComputeFunction
1035
- connected?: any
1036
- }
1037
- /**
1038
- * When true (default), injects a THREE.Scene between container and children if container isn't already a Scene.
1039
- * This ensures state.scene is always a real THREE.Scene with proper properties (background, environment, fog).
1040
- * Set to false to use the container directly as scene (anti-pattern, but supported for edge cases).
1041
- */
1042
- injectScene?: boolean
1043
- }
837
+ //* Base Renderer Types =====================================
838
+
839
+ // Shim for OffscreenCanvas since it was removed from DOM types
840
+ interface OffscreenCanvas$1 extends EventTarget {}
841
+
842
+ interface BaseRendererProps {
843
+ canvas: HTMLCanvasElement | OffscreenCanvas$1
844
+ powerPreference?: 'high-performance' | 'low-power' | 'default'
845
+ antialias?: boolean
846
+ alpha?: boolean
847
+ }
848
+
849
+ type RendererFactory<TRenderer, TParams> =
850
+ | TRenderer
851
+ | ((defaultProps: TParams) => TRenderer)
852
+ | ((defaultProps: TParams) => Promise<TRenderer>)
853
+
854
+ interface Renderer {
855
+ render: (scene: THREE$1.Scene, camera: THREE$1.Camera) => any
856
+ }
857
+
858
+ //* Color Management Config ==============================
859
+
860
+ /**
861
+ * Color management configuration shared by both WebGL and WebGPU renderers.
862
+ */
863
+ interface ColorManagementConfig {
864
+ /**
865
+ * Color space assigned to 8-bit input textures (color maps).
866
+ * Defaults to sRGB. Most textures are authored in sRGB.
867
+ * @default THREE.SRGBColorSpace
868
+ */
869
+ textureColorSpace?: THREE$1.ColorSpace
870
+ }
871
+
872
+ //* WebGL Renderer Props ==============================
873
+
874
+ type DefaultGLProps = Omit<THREE$1.WebGLRendererParameters, 'canvas'> & {
875
+ canvas: HTMLCanvasElement | OffscreenCanvas$1
876
+ }
877
+
878
+ type GLProps =
879
+ | Renderer
880
+ | ((defaultProps: DefaultGLProps) => Renderer)
881
+ | ((defaultProps: DefaultGLProps) => Promise<Renderer>)
882
+ | (Partial<Properties<THREE$1.WebGLRenderer> | THREE$1.WebGLRendererParameters> & ColorManagementConfig)
883
+
884
+ //* WebGPU Renderer Props ==============================
885
+
886
+ type DefaultRendererProps = {
887
+ canvas: HTMLCanvasElement | OffscreenCanvas$1
888
+ [key: string]: any
889
+ }
890
+
891
+ /**
892
+ * Canvas-level scheduler configuration.
893
+ * Controls render timing relative to other canvases.
894
+ */
895
+ interface CanvasSchedulerConfig {
896
+ /**
897
+ * Render this canvas after another canvas completes.
898
+ * Pass the `id` of another canvas.
899
+ */
900
+ after?: string
901
+ /**
902
+ * Limit this canvas's render rate (frames per second).
903
+ */
904
+ fps?: number
905
+ }
906
+
907
+ /**
908
+ * Extended renderer configuration for multi-canvas support and color management.
909
+ */
910
+ interface RendererConfigExtended extends ColorManagementConfig {
911
+ /** Share renderer from another canvas (WebGPU only) */
912
+ primaryCanvas?: string
913
+ /** Canvas-level scheduler options */
914
+ scheduler?: CanvasSchedulerConfig
915
+ }
916
+
917
+ type RendererProps =
918
+ | any // WebGPURenderer
919
+ | ((defaultProps: DefaultRendererProps) => any)
920
+ | ((defaultProps: DefaultRendererProps) => Promise<any>)
921
+ | (Partial<Properties<any> | Record<string, any>> & RendererConfigExtended)
922
+
923
+ //* Camera Props ==============================
924
+
925
+ type CameraProps = (
926
+ | THREE$1.Camera
927
+ | Partial<
928
+ ThreeElement<typeof THREE$1.Camera> &
929
+ ThreeElement<typeof THREE$1.PerspectiveCamera> &
930
+ ThreeElement<typeof THREE$1.OrthographicCamera>
931
+ >
932
+ ) & {
933
+ /** Flags the camera as manual, putting projection into your own hands */
934
+ manual?: boolean
935
+ }
936
+
937
+ //* Render Props ==============================
938
+
939
+ interface RenderProps<TCanvas extends HTMLCanvasElement | OffscreenCanvas$1> {
940
+ /**
941
+ * Unique identifier for multi-canvas renderer sharing.
942
+ * Makes this canvas targetable by other canvases using the `primaryCanvas` prop.
943
+ * Also sets the HTML `id` attribute on the canvas element.
944
+ * @example <Canvas id="main-viewer">...</Canvas>
945
+ */
946
+ id?: string
947
+ /**
948
+ * Share the renderer from another canvas instead of creating a new one.
949
+ * Pass the `id` of the primary canvas to share its WebGPURenderer.
950
+ * Only available with WebGPU (not legacy WebGL).
951
+ *
952
+ * Note: This is extracted from `renderer={{ primaryCanvas: "id" }}` by Canvas.
953
+ * @internal
954
+ */
955
+ primaryCanvas?: string
956
+ /**
957
+ * Canvas-level scheduler options. Controls render timing relative to other canvases.
958
+ *
959
+ * Note: This is extracted from `renderer={{ scheduler: {...} }}` by Canvas.
960
+ * @internal
961
+ */
962
+ scheduler?: CanvasSchedulerConfig
963
+ /** A threejs renderer instance or props that go into the default renderer */
964
+ gl?: GLProps
965
+ /** A WebGPU renderer instance or props that go into the default renderer */
966
+ renderer?: RendererProps
967
+ /** Dimensions to fit the renderer to. Will measure canvas dimensions if omitted */
968
+ size?: Size
969
+ /**
970
+ * Enables shadows (by default PCFsoft). Can accept `gl.shadowMap` options for fine-tuning,
971
+ * but also strings: 'basic' | 'percentage' | 'soft' | 'variance'.
972
+ * @see https://threejs.org/docs/#api/en/renderers/WebGLRenderer.shadowMap
973
+ */
974
+ shadows?: boolean | 'basic' | 'percentage' | 'soft' | 'variance' | Partial<THREE$1.WebGLShadowMap>
975
+ /** Creates an orthographic camera */
976
+ orthographic?: boolean
977
+ /**
978
+ * R3F's render mode. Set to `demand` to only render on state change or `never` to take control.
979
+ * @see https://docs.pmnd.rs/react-three-fiber/advanced/scaling-performance#on-demand-rendering
980
+ */
981
+ frameloop?: Frameloop
982
+ /**
983
+ * R3F performance options for adaptive performance.
984
+ * @see https://docs.pmnd.rs/react-three-fiber/advanced/scaling-performance#movement-regression
985
+ */
986
+ performance?: Partial<Omit<Performance, 'regress'>>
987
+ /** Target pixel ratio. Can clamp between a range: `[min, max]` */
988
+ dpr?: Dpr
989
+ /** Props that go into the default raycaster */
990
+ raycaster?: Partial<THREE$1.Raycaster>
991
+ /** A `THREE.Scene` instance or props that go into the default scene */
992
+ scene?: THREE$1.Scene | Partial<THREE$1.Scene>
993
+ /** A `THREE.Camera` instance or props that go into the default camera */
994
+ camera?: CameraProps
995
+ /** An R3F event manager to manage elements' pointer events */
996
+ events?: (store: RootStore) => EventManager<HTMLElement>
997
+ /** Callback after the canvas has rendered (but not yet committed) */
998
+ onCreated?: (state: RootState) => void
999
+ /** Response for pointer clicks that have missed any target */
1000
+ onPointerMissed?: (event: MouseEvent) => void
1001
+ /** Response for dragover events that have missed any target */
1002
+ onDragOverMissed?: (event: DragEvent) => void
1003
+ /** Response for drop events that have missed any target */
1004
+ onDropMissed?: (event: DragEvent) => void
1005
+ /** Whether to automatically update the frustum each frame (default: true) */
1006
+ autoUpdateFrustum?: boolean
1007
+ /**
1008
+ * Enable WebGPU occlusion queries for onOccluded/onVisible events.
1009
+ * Auto-enabled when any object uses onOccluded or onVisible handlers.
1010
+ * Only works with WebGPU renderer - WebGL will log a warning.
1011
+ */
1012
+ occlusion?: boolean
1013
+ /** Internal: stored size props from Canvas for reset functionality */
1014
+ _sizeProps?: { width?: number; height?: number } | null
1015
+ /** Force canvas dimensions to even numbers (fixes Safari rendering issues with odd/fractional sizes) */
1016
+ forceEven?: boolean
1017
+ }
1018
+
1019
+ //* Reconciler Root ==============================
1020
+
1021
+ interface ReconcilerRoot<TCanvas extends HTMLCanvasElement | OffscreenCanvas$1> {
1022
+ configure: (config?: RenderProps<TCanvas>) => Promise<ReconcilerRoot<TCanvas>>
1023
+ render: (element: ReactNode) => RootStore
1024
+ unmount: () => void
1025
+ }
1026
+
1027
+ //* Inject State ==============================
1028
+
1029
+ type InjectState = Partial<
1030
+ Omit<RootState, 'events'> & {
1031
+ events?: {
1032
+ enabled?: boolean
1033
+ priority?: number
1034
+ compute?: ComputeFunction
1035
+ connected?: any
1036
+ }
1037
+ /**
1038
+ * When true (default), injects a THREE.Scene between container and children if container isn't already a Scene.
1039
+ * This ensures state.scene is always a real THREE.Scene with proper properties (background, environment, fog).
1040
+ * Set to false to use the container directly as scene (anti-pattern, but supported for edge cases).
1041
+ */
1042
+ injectScene?: boolean
1043
+ }
1044
1044
  >
1045
1045
 
1046
- //* Reconciler Types ==============================
1047
-
1048
- // FiberRoot is an opaque internal React type - we define it locally
1049
- // to avoid bundling @types/react-reconciler which causes absolute path issues
1050
- type FiberRoot = any
1051
-
1052
- interface Root {
1053
- fiber: FiberRoot
1054
- store: RootStore
1055
- }
1056
-
1057
- type AttachFnType<O = any> = (parent: any, self: O) => () => void
1058
- type AttachType<O = any> = string | AttachFnType<O>
1059
-
1060
- type ConstructorRepresentation<T = any> = new (...args: any[]) => T
1061
-
1062
- interface Catalogue {
1063
- [name: string]: ConstructorRepresentation
1064
- }
1065
-
1066
- // TODO: handle constructor overloads
1067
- // https://github.com/pmndrs/react-three-fiber/pull/2931
1068
- // https://github.com/microsoft/TypeScript/issues/37079
1069
- type Args<T> = T extends ConstructorRepresentation
1070
- ? T extends typeof Color$1
1071
- ? [r: number, g: number, b: number] | [color: ColorRepresentation]
1072
- : ConstructorParameters<T>
1073
- : any[]
1074
-
1075
- type ArgsProp<P> = P extends ConstructorRepresentation
1076
- ? IsAllOptional<ConstructorParameters<P>> extends true
1077
- ? { args?: Args<P> }
1078
- : { args: Args<P> }
1079
- : { args: unknown[] }
1080
-
1081
- type InstanceProps<T = any, P = any> = ArgsProp<P> & {
1082
- object?: T
1083
- dispose?: null
1084
- attach?: AttachType<T>
1085
- onUpdate?: (self: T) => void
1086
- }
1087
-
1088
- interface Instance<O = any> {
1089
- root: RootStore
1090
- type: string
1091
- parent: Instance | null
1092
- children: Instance[]
1093
- props: InstanceProps<O> & Record<string, unknown>
1094
- object: O & { __r3f?: Instance<O> }
1095
- eventCount: number
1096
- handlers: Partial<EventHandlers>
1097
- attach?: AttachType<O>
1098
- previousAttach?: any
1099
- isHidden: boolean
1100
- /** Deferred ref props to apply in commitMount */
1101
- deferredRefs?: Array<{ prop: string; ref: React$1.RefObject<any> }>
1102
- /** Set of props that have been applied via once() */
1103
- appliedOnce?: Set<string>
1104
- }
1105
-
1106
- interface HostConfig {
1107
- type: string
1108
- props: Instance['props']
1109
- container: RootStore
1110
- instance: Instance
1111
- textInstance: void
1112
- suspenseInstance: Instance
1113
- hydratableInstance: never
1114
- formInstance: never
1115
- publicInstance: Instance['object']
1116
- hostContext: {}
1117
- childSet: never
1118
- timeoutHandle: number | undefined
1119
- noTimeout: -1
1120
- TransitionStatus: null
1121
- }
1122
- declare global {
1123
- var IS_REACT_ACT_ENVIRONMENT: boolean | undefined
1046
+ //* Reconciler Types ==============================
1047
+
1048
+ // FiberRoot is an opaque internal React type - we define it locally
1049
+ // to avoid bundling @types/react-reconciler which causes absolute path issues
1050
+ type FiberRoot = any
1051
+
1052
+ interface Root {
1053
+ fiber: FiberRoot
1054
+ store: RootStore
1124
1055
  }
1125
1056
 
1126
- //* Loop Types ==============================
1127
-
1128
- type GlobalRenderCallback = (timestamp: number) => void
1129
-
1057
+ type AttachFnType<O = any> = (parent: any, self: O) => () => void
1058
+ type AttachType<O = any> = string | AttachFnType<O>
1059
+
1060
+ type ConstructorRepresentation<T = any> = new (...args: any[]) => T
1061
+
1062
+ interface Catalogue {
1063
+ [name: string]: ConstructorRepresentation
1064
+ }
1065
+
1066
+ // TODO: handle constructor overloads
1067
+ // https://github.com/pmndrs/react-three-fiber/pull/2931
1068
+ // https://github.com/microsoft/TypeScript/issues/37079
1069
+ type Args<T> = T extends ConstructorRepresentation
1070
+ ? T extends typeof Color$1
1071
+ ? [r: number, g: number, b: number] | [color: ColorRepresentation]
1072
+ : ConstructorParameters<T>
1073
+ : any[]
1074
+
1075
+ type ArgsProp<P> = P extends ConstructorRepresentation
1076
+ ? IsAllOptional<ConstructorParameters<P>> extends true
1077
+ ? { args?: Args<P> }
1078
+ : { args: Args<P> }
1079
+ : { args: unknown[] }
1080
+
1081
+ type InstanceProps<T = any, P = any> = ArgsProp<P> & {
1082
+ object?: T
1083
+ dispose?: null
1084
+ attach?: AttachType<T>
1085
+ onUpdate?: (self: T) => void
1086
+ }
1087
+
1088
+ interface Instance<O = any> {
1089
+ root: RootStore
1090
+ type: string
1091
+ parent: Instance | null
1092
+ children: Instance[]
1093
+ props: InstanceProps<O> & Record<string, unknown>
1094
+ object: O & { __r3f?: Instance<O> }
1095
+ eventCount: number
1096
+ handlers: Partial<EventHandlers>
1097
+ attach?: AttachType<O>
1098
+ previousAttach?: any
1099
+ isHidden: boolean
1100
+ /** Deferred ref props to apply in commitMount */
1101
+ deferredRefs?: Array<{ prop: string; ref: React$1.RefObject<any> }>
1102
+ /** Set of props that have been applied via once() */
1103
+ appliedOnce?: Set<string>
1104
+ }
1105
+
1106
+ interface HostConfig {
1107
+ type: string
1108
+ props: Instance['props']
1109
+ container: RootStore
1110
+ instance: Instance
1111
+ textInstance: void
1112
+ suspenseInstance: Instance
1113
+ hydratableInstance: never
1114
+ formInstance: never
1115
+ publicInstance: Instance['object']
1116
+ hostContext: {}
1117
+ childSet: never
1118
+ timeoutHandle: number | undefined
1119
+ noTimeout: -1
1120
+ TransitionStatus: null
1121
+ }
1122
+ declare global {
1123
+ var IS_REACT_ACT_ENVIRONMENT: boolean | undefined
1124
+ }
1125
+
1126
+ //* Loop Types ==============================
1127
+
1128
+ type GlobalRenderCallback = (timestamp: number) => void
1129
+
1130
1130
  type GlobalEffectType = 'before' | 'after' | 'tail'
1131
1131
 
1132
1132
  declare const presetsObj: {
@@ -1143,647 +1143,647 @@ declare const presetsObj: {
1143
1143
  };
1144
1144
  type PresetsType = keyof typeof presetsObj;
1145
1145
 
1146
- //* Background Types ==============================
1147
-
1148
- /**
1149
- * Expanded object form for background configuration.
1150
- * Allows separate textures for background (visual backdrop) and environment (PBR lighting).
1151
- */
1152
- interface BackgroundConfig {
1153
- /** HDRI preset name: 'apartment', 'city', 'dawn', 'forest', 'lobby', 'night', 'park', 'studio', 'sunset', 'warehouse' */
1154
- preset?: PresetsType
1155
- /** Files for cube texture (6 faces) or single HDR/EXR */
1156
- files?: string | string[]
1157
- /** Separate files for scene.background (visual backdrop) */
1158
- backgroundMap?: string | string[]
1159
- backgroundRotation?: Euler$1 | [number, number, number]
1160
- backgroundBlurriness?: number
1161
- backgroundIntensity?: number
1162
- /** Separate files for scene.environment (PBR lighting/reflections) */
1163
- envMap?: string | string[]
1164
- environmentRotation?: Euler$1 | [number, number, number]
1165
- environmentIntensity?: number
1166
- path?: string
1167
- extensions?: (loader: Loader) => void
1168
- }
1169
-
1170
- /**
1171
- * Background prop type for Canvas.
1172
- *
1173
- * String detection priority:
1174
- * 1. Preset - exact match against known presets (apartment, city, dawn, forest, lobby, night, park, studio, sunset, warehouse)
1175
- * 2. URL - starts with /, ./, ../, http://, https://, OR has image extension
1176
- * 3. Color - default fallback (CSS color names, hex values, rgb(), etc.)
1177
- *
1178
- * @example Color
1179
- * ```tsx
1180
- * <Canvas background="red" />
1181
- * <Canvas background="#ff0000" />
1182
- * <Canvas background={0xff0000} />
1183
- * ```
1184
- *
1185
- * @example Preset
1186
- * ```tsx
1187
- * <Canvas background="city" />
1188
- * ```
1189
- *
1190
- * @example URL
1191
- * ```tsx
1192
- * <Canvas background="/path/to/env.hdr" />
1193
- * <Canvas background="./sky.jpg" />
1194
- * ```
1195
- *
1196
- * @example Object form
1197
- * ```tsx
1198
- * <Canvas background={{
1199
- * files: ['px.png', 'nx.png', 'py.png', 'ny.png', 'pz.png', 'nz.png'],
1200
- * backgroundMap: 'path/to/sky.jpg',
1201
- * envMap: 'path/to/lighting.hdr',
1202
- * backgroundBlurriness: 0.5,
1203
- * }} />
1204
- * ```
1205
- */
1206
- type BackgroundProp =
1207
- | ColorRepresentation // "red", "#ff0000", 0xff0000
1208
- | string // URL or preset
1209
- | BackgroundConfig // Expanded object form
1210
-
1211
- //* Canvas Types ==============================
1212
-
1213
- interface CanvasProps
1214
- extends
1215
- Omit<RenderProps<HTMLCanvasElement>, 'size' | 'primaryCanvas' | 'scheduler'>,
1216
- React$1.HTMLAttributes<HTMLDivElement> {
1217
- children?: React$1.ReactNode
1218
- ref?: React$1.Ref<HTMLCanvasElement>
1219
- /** Canvas fallback content, similar to img's alt prop */
1220
- fallback?: React$1.ReactNode
1221
- /**
1222
- * Options to pass to useMeasure.
1223
- * @see https://github.com/pmndrs/react-use-measure#api
1224
- */
1225
- resize?: Options
1226
- /** The target where events are being subscribed to, default: the div that wraps canvas */
1227
- eventSource?: HTMLElement | React$1.RefObject<HTMLElement | null>
1228
- /** The event prefix that is cast into canvas pointer x/y events, default: "offset" */
1229
- eventPrefix?: 'offset' | 'client' | 'page' | 'layer' | 'screen'
1230
- /** Enable/disable automatic HMR refresh for TSL nodes and uniforms, default: true in dev */
1231
- hmr?: boolean
1232
- /** Canvas resolution width in pixels. If omitted, uses container width. */
1233
- width?: number
1234
- /** Canvas resolution height in pixels. If omitted, uses container height. */
1235
- height?: number
1236
- /** Force canvas dimensions to even numbers (fixes Safari rendering issues with odd/fractional sizes) */
1237
- forceEven?: boolean
1238
- /**
1239
- * Scene background configuration.
1240
- * Accepts colors, URLs, presets, or an expanded object for separate background/environment.
1241
- * @see BackgroundProp for full documentation and examples
1242
- */
1243
- background?: BackgroundProp
1146
+ //* Background Types ==============================
1147
+
1148
+ /**
1149
+ * Expanded object form for background configuration.
1150
+ * Allows separate textures for background (visual backdrop) and environment (PBR lighting).
1151
+ */
1152
+ interface BackgroundConfig {
1153
+ /** HDRI preset name: 'apartment', 'city', 'dawn', 'forest', 'lobby', 'night', 'park', 'studio', 'sunset', 'warehouse' */
1154
+ preset?: PresetsType
1155
+ /** Files for cube texture (6 faces) or single HDR/EXR */
1156
+ files?: string | string[]
1157
+ /** Separate files for scene.background (visual backdrop) */
1158
+ backgroundMap?: string | string[]
1159
+ backgroundRotation?: Euler$1 | [number, number, number]
1160
+ backgroundBlurriness?: number
1161
+ backgroundIntensity?: number
1162
+ /** Separate files for scene.environment (PBR lighting/reflections) */
1163
+ envMap?: string | string[]
1164
+ environmentRotation?: Euler$1 | [number, number, number]
1165
+ environmentIntensity?: number
1166
+ path?: string
1167
+ extensions?: (loader: Loader) => void
1244
1168
  }
1245
1169
 
1246
- //* Loader Types ==============================
1247
-
1248
- type InputLike = string | string[] | string[][] | Readonly<string | string[] | string[][]>
1249
-
1250
- // Define a loader-like interface that matches THREE.Loader's load signature
1251
- // This works for both generic and non-generic THREE.Loader instances
1252
- interface LoaderLike {
1253
- load(
1254
- url: InputLike,
1255
- onLoad?: (result: any) => void,
1256
- onProgress?: (event: ProgressEvent<EventTarget>) => void,
1257
- onError?: (error: unknown) => void,
1258
- ): any
1259
- }
1260
-
1261
- type GLTFLike = { scene: THREE$1.Object3D }
1262
-
1263
- type LoaderInstance<T extends LoaderLike | ConstructorRepresentation<LoaderLike>> =
1264
- T extends ConstructorRepresentation<LoaderLike> ? InstanceType<T> : T
1265
-
1266
- // Infer result type from the load method's callback parameter
1267
- type InferLoadResult<T> = T extends {
1268
- load(url: any, onLoad?: (result: infer R) => void, ...args: any[]): any
1269
- }
1270
- ? R
1271
- : T extends ConstructorRepresentation<any>
1272
- ? InstanceType<T> extends {
1273
- load(url: any, onLoad?: (result: infer R) => void, ...args: any[]): any
1274
- }
1275
- ? R
1276
- : any
1277
- : any
1278
-
1279
- type LoaderResult<T extends LoaderLike | ConstructorRepresentation<LoaderLike>> =
1280
- InferLoadResult<LoaderInstance<T>> extends infer R ? (R extends GLTFLike ? R & ObjectMap : R) : never
1281
-
1282
- type Extensions<T extends LoaderLike | ConstructorRepresentation<LoaderLike>> = (
1283
- loader: LoaderInstance<T>,
1170
+ /**
1171
+ * Background prop type for Canvas.
1172
+ *
1173
+ * String detection priority:
1174
+ * 1. Preset - exact match against known presets (apartment, city, dawn, forest, lobby, night, park, studio, sunset, warehouse)
1175
+ * 2. URL - starts with /, ./, ../, http://, https://, OR has image extension
1176
+ * 3. Color - default fallback (CSS color names, hex values, rgb(), etc.)
1177
+ *
1178
+ * @example Color
1179
+ * ```tsx
1180
+ * <Canvas background="red" />
1181
+ * <Canvas background="#ff0000" />
1182
+ * <Canvas background={0xff0000} />
1183
+ * ```
1184
+ *
1185
+ * @example Preset
1186
+ * ```tsx
1187
+ * <Canvas background="city" />
1188
+ * ```
1189
+ *
1190
+ * @example URL
1191
+ * ```tsx
1192
+ * <Canvas background="/path/to/env.hdr" />
1193
+ * <Canvas background="./sky.jpg" />
1194
+ * ```
1195
+ *
1196
+ * @example Object form
1197
+ * ```tsx
1198
+ * <Canvas background={{
1199
+ * files: ['px.png', 'nx.png', 'py.png', 'ny.png', 'pz.png', 'nz.png'],
1200
+ * backgroundMap: 'path/to/sky.jpg',
1201
+ * envMap: 'path/to/lighting.hdr',
1202
+ * backgroundBlurriness: 0.5,
1203
+ * }} />
1204
+ * ```
1205
+ */
1206
+ type BackgroundProp =
1207
+ | ColorRepresentation // "red", "#ff0000", 0xff0000
1208
+ | string // URL or preset
1209
+ | BackgroundConfig // Expanded object form
1210
+
1211
+ //* Canvas Types ==============================
1212
+
1213
+ interface CanvasProps
1214
+ extends
1215
+ Omit<RenderProps<HTMLCanvasElement>, 'size' | 'primaryCanvas' | 'scheduler'>,
1216
+ React$1.HTMLAttributes<HTMLDivElement> {
1217
+ children?: React$1.ReactNode
1218
+ ref?: React$1.Ref<HTMLCanvasElement>
1219
+ /** Canvas fallback content, similar to img's alt prop */
1220
+ fallback?: React$1.ReactNode
1221
+ /**
1222
+ * Options to pass to useMeasure.
1223
+ * @see https://github.com/pmndrs/react-use-measure#api
1224
+ */
1225
+ resize?: Options
1226
+ /** The target where events are being subscribed to, default: the div that wraps canvas */
1227
+ eventSource?: HTMLElement | React$1.RefObject<HTMLElement | null>
1228
+ /** The event prefix that is cast into canvas pointer x/y events, default: "offset" */
1229
+ eventPrefix?: 'offset' | 'client' | 'page' | 'layer' | 'screen'
1230
+ /** Enable/disable automatic HMR refresh for TSL nodes and uniforms, default: true in dev */
1231
+ hmr?: boolean
1232
+ /** Canvas resolution width in pixels. If omitted, uses container width. */
1233
+ width?: number
1234
+ /** Canvas resolution height in pixels. If omitted, uses container height. */
1235
+ height?: number
1236
+ /** Force canvas dimensions to even numbers (fixes Safari rendering issues with odd/fractional sizes) */
1237
+ forceEven?: boolean
1238
+ /**
1239
+ * Scene background configuration.
1240
+ * Accepts colors, URLs, presets, or an expanded object for separate background/environment.
1241
+ * @see BackgroundProp for full documentation and examples
1242
+ */
1243
+ background?: BackgroundProp
1244
+ }
1245
+
1246
+ //* Loader Types ==============================
1247
+
1248
+ type InputLike = string | string[] | string[][] | Readonly<string | string[] | string[][]>
1249
+
1250
+ // Define a loader-like interface that matches THREE.Loader's load signature
1251
+ // This works for both generic and non-generic THREE.Loader instances
1252
+ interface LoaderLike {
1253
+ load(
1254
+ url: InputLike,
1255
+ onLoad?: (result: any) => void,
1256
+ onProgress?: (event: ProgressEvent<EventTarget>) => void,
1257
+ onError?: (error: unknown) => void,
1258
+ ): any
1259
+ }
1260
+
1261
+ type GLTFLike = { scene: THREE$1.Object3D }
1262
+
1263
+ type LoaderInstance<T extends LoaderLike | ConstructorRepresentation<LoaderLike>> =
1264
+ T extends ConstructorRepresentation<LoaderLike> ? InstanceType<T> : T
1265
+
1266
+ // Infer result type from the load method's callback parameter
1267
+ type InferLoadResult<T> = T extends {
1268
+ load(url: any, onLoad?: (result: infer R) => void, ...args: any[]): any
1269
+ }
1270
+ ? R
1271
+ : T extends ConstructorRepresentation<any>
1272
+ ? InstanceType<T> extends {
1273
+ load(url: any, onLoad?: (result: infer R) => void, ...args: any[]): any
1274
+ }
1275
+ ? R
1276
+ : any
1277
+ : any
1278
+
1279
+ type LoaderResult<T extends LoaderLike | ConstructorRepresentation<LoaderLike>> =
1280
+ InferLoadResult<LoaderInstance<T>> extends infer R ? (R extends GLTFLike ? R & ObjectMap : R) : never
1281
+
1282
+ type Extensions<T extends LoaderLike | ConstructorRepresentation<LoaderLike>> = (
1283
+ loader: LoaderInstance<T>,
1284
1284
  ) => void
1285
1285
 
1286
- //* Renderer Props ========================================
1287
-
1288
- type WebGLDefaultProps = Omit<THREE$1.WebGLRendererParameters, 'canvas'> & BaseRendererProps
1289
-
1290
- type WebGLProps =
1291
- | RendererFactory<THREE$1.WebGLRenderer, WebGLDefaultProps>
1292
- | Partial<Properties<THREE$1.WebGLRenderer> | THREE$1.WebGLRendererParameters>
1293
-
1294
- interface WebGLShadowConfig {
1295
- shadows?: boolean | 'basic' | 'percentage' | 'soft' | 'variance' | Partial<THREE$1.WebGLShadowMap>
1296
- }
1297
-
1298
- //* Legacy-specific Types ========================================
1299
-
1300
- /** Legacy (WebGL) renderer type - re-exported as R3FRenderer from @react-three/fiber/legacy */
1301
- type LegacyRenderer = THREE$1.WebGLRenderer
1302
-
1303
- /** Legacy internal state with narrowed renderer type */
1304
- interface LegacyInternalState extends Omit<InternalState, 'actualRenderer'> {
1305
- actualRenderer: THREE$1.WebGLRenderer
1306
- }
1307
-
1308
- /**
1309
- * Legacy-specific RootState with narrowed renderer type.
1310
- * Automatically used when importing from `@react-three/fiber/legacy`.
1311
- *
1312
- * @example
1313
- * ```tsx
1314
- * import { useThree } from '@react-three/fiber/legacy'
1315
- *
1316
- * function MyComponent() {
1317
- * const { renderer } = useThree()
1318
- * // renderer is typed as THREE.WebGLRenderer
1319
- * renderer.shadowMap.enabled = true
1320
- * }
1321
- * ```
1322
- */
1323
- interface LegacyRootState extends Omit<RootState, 'renderer' | 'internal'> {
1324
- /** The WebGL renderer instance */
1325
- renderer: THREE$1.WebGLRenderer
1326
- /** Internals with WebGL renderer */
1327
- internal: LegacyInternalState
1286
+ //* Renderer Props ========================================
1287
+
1288
+ type WebGLDefaultProps = Omit<THREE$1.WebGLRendererParameters, 'canvas'> & BaseRendererProps
1289
+
1290
+ type WebGLProps =
1291
+ | RendererFactory<THREE$1.WebGLRenderer, WebGLDefaultProps>
1292
+ | Partial<Properties<THREE$1.WebGLRenderer> | THREE$1.WebGLRendererParameters>
1293
+
1294
+ interface WebGLShadowConfig {
1295
+ shadows?: boolean | 'basic' | 'percentage' | 'soft' | 'variance' | Partial<THREE$1.WebGLShadowMap>
1296
+ }
1297
+
1298
+ //* Legacy-specific Types ========================================
1299
+
1300
+ /** Legacy (WebGL) renderer type - re-exported as R3FRenderer from @react-three/fiber/legacy */
1301
+ type LegacyRenderer = THREE$1.WebGLRenderer
1302
+
1303
+ /** Legacy internal state with narrowed renderer type */
1304
+ interface LegacyInternalState extends Omit<InternalState, 'actualRenderer'> {
1305
+ actualRenderer: THREE$1.WebGLRenderer
1306
+ }
1307
+
1308
+ /**
1309
+ * Legacy-specific RootState with narrowed renderer type.
1310
+ * Automatically used when importing from `@react-three/fiber/legacy`.
1311
+ *
1312
+ * @example
1313
+ * ```tsx
1314
+ * import { useThree } from '@react-three/fiber/legacy'
1315
+ *
1316
+ * function MyComponent() {
1317
+ * const { renderer } = useThree()
1318
+ * // renderer is typed as THREE.WebGLRenderer
1319
+ * renderer.shadowMap.enabled = true
1320
+ * }
1321
+ * ```
1322
+ */
1323
+ interface LegacyRootState extends Omit<RootState, 'renderer' | 'internal'> {
1324
+ /** The WebGL renderer instance */
1325
+ renderer: THREE$1.WebGLRenderer
1326
+ /** Internals with WebGL renderer */
1327
+ internal: LegacyInternalState
1328
1328
  }
1329
1329
 
1330
- //* RenderTarget Types ==============================
1331
-
1332
-
1330
+ //* RenderTarget Types ==============================
1331
+
1332
+
1333
1333
  type RenderTargetOptions = RenderTargetOptions$1
1334
1334
 
1335
- //* Global Types ==============================
1336
-
1337
- declare global {
1338
- /** Uniform node type - a Node with a value property (matches Three.js UniformNode) */
1339
- interface UniformNode<T = unknown> extends Node {
1340
- value: T
1341
- }
1342
-
1343
- /**
1344
- * ShaderCallable - the return type of Fn()
1345
- * A callable shader function node that can be invoked with parameters.
1346
- * The function returns a ShaderNodeObject when called.
1347
- *
1348
- * @example
1349
- * ```tsx
1350
- * // Define a shader function
1351
- * const blendColorFn = Fn(([color1, color2, factor]) => {
1352
- * return mix(color1, color2, factor)
1353
- * })
1354
- *
1355
- * // Type when retrieving from nodes store
1356
- * const { blendColorFn } = nodes as { blendColorFn: ShaderCallable }
1357
- *
1358
- * // Or with specific return type
1359
- * const { myFn } = nodes as { myFn: ShaderCallable<THREE.Node> }
1360
- * ```
1361
- */
1362
- type ShaderCallable<R extends Node = Node> = ((...params: unknown[]) => ShaderNodeObject<R>) & Node
1363
-
1364
- /**
1365
- * ShaderNodeRef - a ShaderNodeObject wrapper around a Node
1366
- * This is the common return type for TSL operations (add, mul, sin, etc.)
1367
- *
1368
- * @example
1369
- * ```tsx
1370
- * const { wobble } = nodes as { wobble: ShaderNodeRef }
1371
- * ```
1372
- */
1373
- type ShaderNodeRef<T extends Node = Node> = ShaderNodeObject<T>
1374
-
1375
- /**
1376
- * TSLNodeType - Union of all common TSL node types
1377
- * Used by ScopedStore to properly type node access from the store.
1378
- *
1379
- * Includes:
1380
- * - Node: base Three.js node type
1381
- * - ShaderCallable: function nodes created with Fn()
1382
- * - ShaderNodeObject: wrapped nodes from TSL operations (sin, mul, mix, etc.)
1383
- *
1384
- * @example
1385
- * ```tsx
1386
- * // In useLocalNodes, nodes are typed as TSLNodeType
1387
- * const { positionNode, blendColorFn } = useLocalNodes(({ nodes }) => ({
1388
- * positionNode: nodes.myPosition, // Works - Node is in union
1389
- * blendColorFn: nodes.myFn, // Works - ShaderCallable is in union
1390
- * }))
1391
- *
1392
- * // Can narrow with type guard or assertion when needed
1393
- * if (typeof blendColorFn === 'function') {
1394
- * blendColorFn(someColor, 0.5)
1395
- * }
1396
- * ```
1397
- */
1398
- type TSLNodeType = Node | ShaderCallable<Node> | ShaderNodeObject<Node>
1399
-
1400
- /** Flat record of uniform nodes (no nested scopes) */
1401
- type UniformRecord<T extends UniformNode = UniformNode> = Record<string, T>
1402
-
1403
- /**
1404
- * Uniform store that can contain both root-level uniforms and scoped uniform objects
1405
- * Used by state.uniforms which has structure like:
1406
- * { uTime: UniformNode, player: { uHealth: UniformNode }, enemy: { uHealth: UniformNode } }
1407
- */
1408
- type UniformStore = Record<string, UniformNode | UniformRecord>
1409
-
1410
- /**
1411
- * Helper to safely access a uniform node from the store.
1412
- * Use this when accessing state.uniforms to get proper typing.
1413
- * @example
1414
- * const uTime = uniforms.uTime as UniformNode<number>
1415
- * const uColor = uniforms.uColor as UniformNode<import('three/webgpu').Color>
1416
- */
1417
- type GetUniform<T = unknown> = UniformNode<T>
1418
-
1419
- /**
1420
- * Acceptable input values for useUniforms - raw values that get converted to UniformNodes
1421
- * Supports:
1422
- * - Primitives: number, string (color), boolean
1423
- * - Three.js types: Color, Vector2/3/4, Matrix3/4, Euler, Quaternion
1424
- * - Plain objects: { x, y, z, w } converted to vectors
1425
- * - TSL nodes: color(), vec3(), float() for type casting
1426
- * - UniformNode: existing uniforms (reused as-is)
1427
- */
1428
- type UniformValue =
1429
- | number
1430
- | string
1431
- | boolean
1432
- | three_webgpu.Color
1433
- | three_webgpu.Vector2
1434
- | three_webgpu.Vector3
1435
- | three_webgpu.Vector4
1436
- | three_webgpu.Matrix3
1437
- | three_webgpu.Matrix4
1438
- | three_webgpu.Euler
1439
- | three_webgpu.Quaternion
1440
- | { x: number; y?: number; z?: number; w?: number } // Plain objects converted to vectors
1441
- | { r: number; g: number; b: number; a?: number } // Plain objects converted to Color
1442
- | Node // TSL nodes like color(), vec3(), float() for type casting
1443
- | UniformNode
1444
-
1445
- /** Input record for useUniforms - accepts raw values or UniformNodes */
1446
- type UniformInputRecord = Record<string, UniformValue>
1447
- }
1448
-
1449
- //* Module Augmentation ==============================
1450
-
1451
- declare module 'three/tsl' {
1452
- /**
1453
- * Fn with array parameter destructuring
1454
- * @example Fn(([uv, skew]) => { ... })
1455
- */
1456
- export function Fn<R extends Node = Node>(
1457
- jsFunc: (inputs: ShaderNodeObject<Node>[]) => ShaderNodeObject<R>,
1458
- ): ShaderCallable<R>
1459
-
1460
- /**
1461
- * Fn with object parameter destructuring
1462
- * @example Fn(({ color, intensity }) => { ... })
1463
- */
1464
- export function Fn<T extends Record<string, unknown>, R extends Node = Node>(
1465
- jsFunc: (inputs: T) => ShaderNodeObject<R>,
1466
- ): ShaderCallable<R>
1467
-
1468
- /**
1469
- * Fn with array params + layout
1470
- * @example Fn(([a, b]) => { ... }, { layout: [...] })
1471
- */
1472
- export function Fn<R extends Node = Node>(
1473
- jsFunc: (inputs: ShaderNodeObject<Node>[]) => ShaderNodeObject<R>,
1474
- layout: { layout?: unknown },
1475
- ): ShaderCallable<R>
1476
-
1477
- /**
1478
- * Fn with object params + layout
1479
- */
1480
- export function Fn<T extends Record<string, unknown>, R extends Node = Node>(
1481
- jsFunc: (inputs: T) => ShaderNodeObject<R>,
1482
- layout: { layout?: unknown },
1483
- ): ShaderCallable<R>
1335
+ //* Global Types ==============================
1336
+
1337
+ declare global {
1338
+ /** Uniform node type - a Node with a value property (matches Three.js UniformNode) */
1339
+ interface UniformNode<T = unknown> extends Node {
1340
+ value: T
1341
+ }
1342
+
1343
+ /**
1344
+ * ShaderCallable - the return type of Fn()
1345
+ * A callable shader function node that can be invoked with parameters.
1346
+ * The function returns a ShaderNodeObject when called.
1347
+ *
1348
+ * @example
1349
+ * ```tsx
1350
+ * // Define a shader function
1351
+ * const blendColorFn = Fn(([color1, color2, factor]) => {
1352
+ * return mix(color1, color2, factor)
1353
+ * })
1354
+ *
1355
+ * // Type when retrieving from nodes store
1356
+ * const { blendColorFn } = nodes as { blendColorFn: ShaderCallable }
1357
+ *
1358
+ * // Or with specific return type
1359
+ * const { myFn } = nodes as { myFn: ShaderCallable<THREE.Node> }
1360
+ * ```
1361
+ */
1362
+ type ShaderCallable<R extends Node = Node> = ((...params: unknown[]) => ShaderNodeObject<R>) & Node
1363
+
1364
+ /**
1365
+ * ShaderNodeRef - a ShaderNodeObject wrapper around a Node
1366
+ * This is the common return type for TSL operations (add, mul, sin, etc.)
1367
+ *
1368
+ * @example
1369
+ * ```tsx
1370
+ * const { wobble } = nodes as { wobble: ShaderNodeRef }
1371
+ * ```
1372
+ */
1373
+ type ShaderNodeRef<T extends Node = Node> = ShaderNodeObject<T>
1374
+
1375
+ /**
1376
+ * TSLNodeType - Union of all common TSL node types
1377
+ * Used by ScopedStore to properly type node access from the store.
1378
+ *
1379
+ * Includes:
1380
+ * - Node: base Three.js node type
1381
+ * - ShaderCallable: function nodes created with Fn()
1382
+ * - ShaderNodeObject: wrapped nodes from TSL operations (sin, mul, mix, etc.)
1383
+ *
1384
+ * @example
1385
+ * ```tsx
1386
+ * // In useLocalNodes, nodes are typed as TSLNodeType
1387
+ * const { positionNode, blendColorFn } = useLocalNodes(({ nodes }) => ({
1388
+ * positionNode: nodes.myPosition, // Works - Node is in union
1389
+ * blendColorFn: nodes.myFn, // Works - ShaderCallable is in union
1390
+ * }))
1391
+ *
1392
+ * // Can narrow with type guard or assertion when needed
1393
+ * if (typeof blendColorFn === 'function') {
1394
+ * blendColorFn(someColor, 0.5)
1395
+ * }
1396
+ * ```
1397
+ */
1398
+ type TSLNodeType = Node | ShaderCallable<Node> | ShaderNodeObject<Node>
1399
+
1400
+ /** Flat record of uniform nodes (no nested scopes) */
1401
+ type UniformRecord<T extends UniformNode = UniformNode> = Record<string, T>
1402
+
1403
+ /**
1404
+ * Uniform store that can contain both root-level uniforms and scoped uniform objects
1405
+ * Used by state.uniforms which has structure like:
1406
+ * { uTime: UniformNode, player: { uHealth: UniformNode }, enemy: { uHealth: UniformNode } }
1407
+ */
1408
+ type UniformStore = Record<string, UniformNode | UniformRecord>
1409
+
1410
+ /**
1411
+ * Helper to safely access a uniform node from the store.
1412
+ * Use this when accessing state.uniforms to get proper typing.
1413
+ * @example
1414
+ * const uTime = uniforms.uTime as UniformNode<number>
1415
+ * const uColor = uniforms.uColor as UniformNode<import('three/webgpu').Color>
1416
+ */
1417
+ type GetUniform<T = unknown> = UniformNode<T>
1418
+
1419
+ /**
1420
+ * Acceptable input values for useUniforms - raw values that get converted to UniformNodes
1421
+ * Supports:
1422
+ * - Primitives: number, string (color), boolean
1423
+ * - Three.js types: Color, Vector2/3/4, Matrix3/4, Euler, Quaternion
1424
+ * - Plain objects: { x, y, z, w } converted to vectors
1425
+ * - TSL nodes: color(), vec3(), float() for type casting
1426
+ * - UniformNode: existing uniforms (reused as-is)
1427
+ */
1428
+ type UniformValue =
1429
+ | number
1430
+ | string
1431
+ | boolean
1432
+ | three_webgpu.Color
1433
+ | three_webgpu.Vector2
1434
+ | three_webgpu.Vector3
1435
+ | three_webgpu.Vector4
1436
+ | three_webgpu.Matrix3
1437
+ | three_webgpu.Matrix4
1438
+ | three_webgpu.Euler
1439
+ | three_webgpu.Quaternion
1440
+ | { x: number; y?: number; z?: number; w?: number } // Plain objects converted to vectors
1441
+ | { r: number; g: number; b: number; a?: number } // Plain objects converted to Color
1442
+ | Node // TSL nodes like color(), vec3(), float() for type casting
1443
+ | UniformNode
1444
+
1445
+ /** Input record for useUniforms - accepts raw values or UniformNodes */
1446
+ type UniformInputRecord = Record<string, UniformValue>
1447
+ }
1448
+
1449
+ //* Module Augmentation ==============================
1450
+
1451
+ declare module 'three/tsl' {
1452
+ /**
1453
+ * Fn with array parameter destructuring
1454
+ * @example Fn(([uv, skew]) => { ... })
1455
+ */
1456
+ export function Fn<R extends Node = Node>(
1457
+ jsFunc: (inputs: ShaderNodeObject<Node>[]) => ShaderNodeObject<R>,
1458
+ ): ShaderCallable<R>
1459
+
1460
+ /**
1461
+ * Fn with object parameter destructuring
1462
+ * @example Fn(({ color, intensity }) => { ... })
1463
+ */
1464
+ export function Fn<T extends Record<string, unknown>, R extends Node = Node>(
1465
+ jsFunc: (inputs: T) => ShaderNodeObject<R>,
1466
+ ): ShaderCallable<R>
1467
+
1468
+ /**
1469
+ * Fn with array params + layout
1470
+ * @example Fn(([a, b]) => { ... }, { layout: [...] })
1471
+ */
1472
+ export function Fn<R extends Node = Node>(
1473
+ jsFunc: (inputs: ShaderNodeObject<Node>[]) => ShaderNodeObject<R>,
1474
+ layout: { layout?: unknown },
1475
+ ): ShaderCallable<R>
1476
+
1477
+ /**
1478
+ * Fn with object params + layout
1479
+ */
1480
+ export function Fn<T extends Record<string, unknown>, R extends Node = Node>(
1481
+ jsFunc: (inputs: T) => ShaderNodeObject<R>,
1482
+ layout: { layout?: unknown },
1483
+ ): ShaderCallable<R>
1484
+ }
1485
+
1486
+ /**
1487
+ * RenderPipeline Types for useRenderPipeline hook (WebGPU only)
1488
+ */
1489
+
1490
+
1491
+
1492
+ declare global {
1493
+ /** Pass record - stores TSL pass nodes for render pipeline */
1494
+ type PassRecord = Record<string, any>
1495
+
1496
+ /** Setup callback - runs first to configure MRT, create additional passes */
1497
+ type RenderPipelineSetupCallback = (state: RootState) => PassRecord | void
1498
+
1499
+ /** Main callback - runs second to configure outputNode, create effect passes */
1500
+ type RenderPipelineMainCallback = (state: RootState) => PassRecord | void
1501
+
1502
+ /** Return type for useRenderPipeline hook */
1503
+ interface UseRenderPipelineReturn {
1504
+ /** Current passes from state */
1505
+ passes: PassRecord
1506
+ /** RenderPipeline instance (null if not initialized) */
1507
+ renderPipeline: any | null // THREE.PostProcessing (will be THREE.RenderPipeline in future Three.js release)
1508
+ /** Clear all passes from state */
1509
+ clearPasses: () => void
1510
+ /** Reset RenderPipeline entirely (clears PP + passes) */
1511
+ reset: () => void
1512
+ /** Re-run setup/main callbacks with current closure values */
1513
+ rebuild: () => void
1514
+ /** True when RenderPipeline is configured and ready */
1515
+ isReady: boolean
1516
+ }
1517
+ }
1518
+
1519
+ //* useFrameNext Types ==============================
1520
+
1521
+
1522
+
1523
+ //* Global Type Declarations ==============================
1524
+
1525
+ declare global {
1526
+ // Job --------------------------------
1527
+
1528
+ /**
1529
+ * Internal job representation in the scheduler
1530
+ */
1531
+ interface Job {
1532
+ /** Unique identifier */
1533
+ id: string
1534
+ /** The callback to execute */
1535
+ callback: FrameNextCallback
1536
+ /** Phase this job belongs to */
1537
+ phase: string
1538
+ /** Run before these phases/job ids */
1539
+ before: Set<string>
1540
+ /** Run after these phases/job ids */
1541
+ after: Set<string>
1542
+ /** Priority within phase (higher first) */
1543
+ priority: number
1544
+ /** Insertion order for deterministic tie-breaking */
1545
+ index: number
1546
+ /** Max FPS for this job (undefined = no limit) */
1547
+ fps?: number
1548
+ /** Drop frames when behind (true) or catch up (false) */
1549
+ drop: boolean
1550
+ /** Last run timestamp (ms) */
1551
+ lastRun?: number
1552
+ /** Whether job is enabled */
1553
+ enabled: boolean
1554
+ /** Internal flag: system jobs (like default render) don't block user render takeover */
1555
+ system?: boolean
1556
+ }
1557
+
1558
+ // Phase Graph --------------------------------
1559
+
1560
+ /**
1561
+ * A node in the phase graph
1562
+ */
1563
+ interface PhaseNode {
1564
+ /** Phase name */
1565
+ name: string
1566
+ /** Whether this was auto-generated from a before/after constraint */
1567
+ isAutoGenerated: boolean
1568
+ }
1569
+
1570
+ /**
1571
+ * Options for creating a job from hook options
1572
+ */
1573
+ interface JobOptions {
1574
+ id?: string
1575
+ phase?: string
1576
+ before?: string | string[]
1577
+ after?: string | string[]
1578
+ priority?: number
1579
+ fps?: number
1580
+ drop?: boolean
1581
+ enabled?: boolean
1582
+ }
1583
+
1584
+ // Frame Loop State --------------------------------
1585
+
1586
+ /**
1587
+ * Internal frame loop state
1588
+ */
1589
+ interface FrameLoopState {
1590
+ /** Whether the loop is running */
1591
+ running: boolean
1592
+ /** Current RAF handle */
1593
+ rafHandle: number | null
1594
+ /** Last frame timestamp in ms (null = uninitialized) */
1595
+ lastTime: number | null
1596
+ /** Frame counter */
1597
+ frameCount: number
1598
+ /** Elapsed time since first frame in ms */
1599
+ elapsedTime: number
1600
+ /** createdAt timestamp in ms */
1601
+ createdAt: number
1602
+ }
1603
+
1604
+ // Root Entry --------------------------------
1605
+
1606
+ /**
1607
+ * Internal representation of a registered root (Canvas).
1608
+ * Tracks jobs and manages rebuild state for this root.
1609
+ * @internal
1610
+ */
1611
+ interface RootEntry {
1612
+ /** Unique identifier for this root */
1613
+ id: string
1614
+ /** Function to get the root's current state. Returns any to support independent mode. */
1615
+ getState: () => any
1616
+ /** Map of job IDs to Job objects */
1617
+ jobs: Map<string, Job>
1618
+ /** Cached sorted job list for execution order */
1619
+ sortedJobs: Job[]
1620
+ /** Whether sortedJobs needs rebuilding */
1621
+ needsRebuild: boolean
1622
+ }
1623
+
1624
+ /**
1625
+ * Internal representation of a global job (deprecated API).
1626
+ * Global jobs run once per frame, not per-root.
1627
+ * Used by legacy addEffect/addAfterEffect APIs.
1628
+ * @internal
1629
+ * @deprecated Use useFrame with phases instead
1630
+ */
1631
+ interface GlobalJob {
1632
+ /** Unique identifier for this global job */
1633
+ id: string
1634
+ /** Callback invoked with RAF timestamp in ms */
1635
+ callback: (timestamp: number) => void
1636
+ }
1637
+
1638
+ // HMR Support --------------------------------
1639
+
1640
+ /**
1641
+ * Hot Module Replacement data structure for preserving scheduler state
1642
+ * @internal
1643
+ */
1644
+ interface HMRData {
1645
+ /** Shared data object for storing values across reloads */
1646
+ data: Record<string, any>
1647
+ /** Optional function to accept HMR updates */
1648
+ accept?: () => void
1649
+ }
1650
+
1651
+ // Default Phases --------------------------------
1652
+
1653
+ /**
1654
+ * Default phase names for the scheduler
1655
+ */
1656
+ type DefaultPhase = 'start' | 'input' | 'physics' | 'update' | 'render' | 'finish'
1657
+ }
1658
+
1659
+ type MutableOrReadonlyParameters<T extends (...args: any) => any> = Parameters<T> | Readonly<Parameters<T>>
1660
+
1661
+ interface MathRepresentation {
1662
+ set(...args: number[]): any
1663
+ }
1664
+ interface VectorRepresentation extends MathRepresentation {
1665
+ setScalar(value: number): any
1666
+ }
1667
+ type MathTypes = MathRepresentation | Euler$2 | Color$2
1668
+
1669
+ type MathType<T extends MathTypes> = T extends Color$2
1670
+ ? Args<typeof Color$2> | ColorRepresentation$1
1671
+ : T extends VectorRepresentation | Layers$1 | Euler$2
1672
+ ? T | MutableOrReadonlyParameters<T['set']> | number
1673
+ : T | MutableOrReadonlyParameters<T['set']>
1674
+
1675
+ type MathProps<P> = {
1676
+ [K in keyof P as P[K] extends MathTypes ? K : never]: P[K] extends MathTypes ? MathType<P[K]> : never
1677
+ }
1678
+
1679
+ type Vector2 = MathType<Vector2$1>
1680
+ type Vector3 = MathType<Vector3$1>
1681
+ type Vector4 = MathType<Vector4$1>
1682
+ type Color = MathType<Color$2>
1683
+ type Layers = MathType<Layers$1>
1684
+ type Quaternion = MathType<Quaternion$1>
1685
+ type Euler = MathType<Euler$2>
1686
+ type Matrix3 = MathType<Matrix3$1>
1687
+ type Matrix4 = MathType<Matrix4$1>
1688
+
1689
+ interface RaycastableRepresentation {
1690
+ raycast(raycaster: Raycaster, intersects: Intersection$1[]): void
1691
+ }
1692
+ type EventProps<P> = P extends RaycastableRepresentation ? Partial<EventHandlers> : {}
1693
+
1694
+ /**
1695
+ * Props for geometry transform methods that can be called with `once()`.
1696
+ * These methods modify the geometry in-place and only make sense to call once on mount.
1697
+ *
1698
+ * @example
1699
+ * import { once } from '@react-three/fiber'
1700
+ *
1701
+ * <boxGeometry args={[1, 1, 1]} rotateX={once(Math.PI / 2)} />
1702
+ * <planeGeometry args={[10, 10]} translate={once(0, 0, 5)} />
1703
+ * <bufferGeometry applyMatrix4={once(matrix)} center={once()} />
1704
+ */
1705
+ interface GeometryTransformProps {
1706
+ /** Rotate the geometry about the X axis (radians). Use with once(). */
1707
+ rotateX?: number
1708
+ /** Rotate the geometry about the Y axis (radians). Use with once(). */
1709
+ rotateY?: number
1710
+ /** Rotate the geometry about the Z axis (radians). Use with once(). */
1711
+ rotateZ?: number
1712
+ /** Translate the geometry (x, y, z). Use with once(). */
1713
+ translate?: [x: number, y: number, z: number]
1714
+ /** Scale the geometry (x, y, z). Use with once(). */
1715
+ scale?: [x: number, y: number, z: number]
1716
+ /** Center the geometry based on bounding box. Use with once(). */
1717
+ center?: true
1718
+ /** Apply a Matrix4 transformation. Use with once(). */
1719
+ applyMatrix4?: Matrix4$1
1720
+ /** Apply a Quaternion rotation. Use with once(). */
1721
+ applyQuaternion?: Quaternion$1
1722
+ }
1723
+
1724
+ type GeometryProps<P> = P extends BufferGeometry ? GeometryTransformProps : {}
1725
+
1726
+ /**
1727
+ * Workaround for @types/three TSL node type issues.
1728
+ * The Node base class has properties that subclasses (OperatorNode, ConstNode, etc.) don't inherit.
1729
+ * This transforms `Node | null` properties to accept any object with node-like shape.
1730
+ */
1731
+ type TSLNodeInput = { nodeType?: string | null; uuid?: string } | null
1732
+
1733
+ /**
1734
+ * For node material properties (colorNode, positionNode, etc.), accept broader types
1735
+ * since @types/three has broken inheritance for TSL node subclasses.
1736
+ */
1737
+ type NodeProps<P> = {
1738
+ [K in keyof P as P[K] extends Node | null ? K : never]?: TSLNodeInput
1739
+ }
1740
+
1741
+ interface ReactProps<P> {
1742
+ children?: React.ReactNode
1743
+ ref?: React.Ref<P>
1744
+ key?: React.Key
1745
+ }
1746
+
1747
+ type ElementProps<T extends ConstructorRepresentation, P = InstanceType<T>> = Partial<
1748
+ Overwrite<P, MathProps<P> & ReactProps<P> & EventProps<P> & GeometryProps<P> & NodeProps<P>>
1749
+ >
1750
+
1751
+ type ThreeElement<T extends ConstructorRepresentation> = Mutable<
1752
+ Overwrite<ElementProps<T>, Omit<InstanceProps<InstanceType<T>, T>, 'object'>>
1753
+ >
1754
+
1755
+ type ThreeToJSXElements<T extends Record<string, any>> = {
1756
+ [K in keyof T & string as Uncapitalize<K>]: T[K] extends ConstructorRepresentation ? ThreeElement<T[K]> : never
1757
+ }
1758
+
1759
+ type ThreeExports = typeof THREE
1760
+ type ThreeElementsImpl = ThreeToJSXElements<ThreeExports>
1761
+
1762
+ interface ThreeElements extends Omit<ThreeElementsImpl, 'audio' | 'source' | 'line' | 'path'> {
1763
+ primitive: Omit<ThreeElement<any>, 'args'> & { object: object }
1764
+ // Conflicts with DOM types can be accessed through a three* prefix
1765
+ threeAudio: ThreeElementsImpl['audio']
1766
+ threeSource: ThreeElementsImpl['source']
1767
+ threeLine: ThreeElementsImpl['line']
1768
+ threePath: ThreeElementsImpl['path']
1484
1769
  }
1485
1770
 
1486
- /**
1487
- * RenderPipeline Types for useRenderPipeline hook (WebGPU only)
1488
- */
1489
-
1490
-
1491
-
1492
- declare global {
1493
- /** Pass record - stores TSL pass nodes for render pipeline */
1494
- type PassRecord = Record<string, any>
1495
-
1496
- /** Setup callback - runs first to configure MRT, create additional passes */
1497
- type RenderPipelineSetupCallback = (state: RootState) => PassRecord | void
1498
-
1499
- /** Main callback - runs second to configure outputNode, create effect passes */
1500
- type RenderPipelineMainCallback = (state: RootState) => PassRecord | void
1501
-
1502
- /** Return type for useRenderPipeline hook */
1503
- interface UseRenderPipelineReturn {
1504
- /** Current passes from state */
1505
- passes: PassRecord
1506
- /** RenderPipeline instance (null if not initialized) */
1507
- renderPipeline: any | null // THREE.PostProcessing (will be THREE.RenderPipeline in future Three.js release)
1508
- /** Clear all passes from state */
1509
- clearPasses: () => void
1510
- /** Reset RenderPipeline entirely (clears PP + passes) */
1511
- reset: () => void
1512
- /** Re-run setup/main callbacks with current closure values */
1513
- rebuild: () => void
1514
- /** True when RenderPipeline is configured and ready */
1515
- isReady: boolean
1516
- }
1771
+ declare module 'react' {
1772
+ namespace JSX {
1773
+ interface IntrinsicElements extends ThreeElements {}
1774
+ }
1517
1775
  }
1518
1776
 
1519
- //* useFrameNext Types ==============================
1520
-
1521
-
1522
-
1523
- //* Global Type Declarations ==============================
1524
-
1525
- declare global {
1526
- // Job --------------------------------
1527
-
1528
- /**
1529
- * Internal job representation in the scheduler
1530
- */
1531
- interface Job {
1532
- /** Unique identifier */
1533
- id: string
1534
- /** The callback to execute */
1535
- callback: FrameNextCallback
1536
- /** Phase this job belongs to */
1537
- phase: string
1538
- /** Run before these phases/job ids */
1539
- before: Set<string>
1540
- /** Run after these phases/job ids */
1541
- after: Set<string>
1542
- /** Priority within phase (higher first) */
1543
- priority: number
1544
- /** Insertion order for deterministic tie-breaking */
1545
- index: number
1546
- /** Max FPS for this job (undefined = no limit) */
1547
- fps?: number
1548
- /** Drop frames when behind (true) or catch up (false) */
1549
- drop: boolean
1550
- /** Last run timestamp (ms) */
1551
- lastRun?: number
1552
- /** Whether job is enabled */
1553
- enabled: boolean
1554
- /** Internal flag: system jobs (like default render) don't block user render takeover */
1555
- system?: boolean
1556
- }
1557
-
1558
- // Phase Graph --------------------------------
1559
-
1560
- /**
1561
- * A node in the phase graph
1562
- */
1563
- interface PhaseNode {
1564
- /** Phase name */
1565
- name: string
1566
- /** Whether this was auto-generated from a before/after constraint */
1567
- isAutoGenerated: boolean
1568
- }
1569
-
1570
- /**
1571
- * Options for creating a job from hook options
1572
- */
1573
- interface JobOptions {
1574
- id?: string
1575
- phase?: string
1576
- before?: string | string[]
1577
- after?: string | string[]
1578
- priority?: number
1579
- fps?: number
1580
- drop?: boolean
1581
- enabled?: boolean
1582
- }
1583
-
1584
- // Frame Loop State --------------------------------
1585
-
1586
- /**
1587
- * Internal frame loop state
1588
- */
1589
- interface FrameLoopState {
1590
- /** Whether the loop is running */
1591
- running: boolean
1592
- /** Current RAF handle */
1593
- rafHandle: number | null
1594
- /** Last frame timestamp in ms (null = uninitialized) */
1595
- lastTime: number | null
1596
- /** Frame counter */
1597
- frameCount: number
1598
- /** Elapsed time since first frame in ms */
1599
- elapsedTime: number
1600
- /** createdAt timestamp in ms */
1601
- createdAt: number
1602
- }
1603
-
1604
- // Root Entry --------------------------------
1605
-
1606
- /**
1607
- * Internal representation of a registered root (Canvas).
1608
- * Tracks jobs and manages rebuild state for this root.
1609
- * @internal
1610
- */
1611
- interface RootEntry {
1612
- /** Unique identifier for this root */
1613
- id: string
1614
- /** Function to get the root's current state. Returns any to support independent mode. */
1615
- getState: () => any
1616
- /** Map of job IDs to Job objects */
1617
- jobs: Map<string, Job>
1618
- /** Cached sorted job list for execution order */
1619
- sortedJobs: Job[]
1620
- /** Whether sortedJobs needs rebuilding */
1621
- needsRebuild: boolean
1622
- }
1623
-
1624
- /**
1625
- * Internal representation of a global job (deprecated API).
1626
- * Global jobs run once per frame, not per-root.
1627
- * Used by legacy addEffect/addAfterEffect APIs.
1628
- * @internal
1629
- * @deprecated Use useFrame with phases instead
1630
- */
1631
- interface GlobalJob {
1632
- /** Unique identifier for this global job */
1633
- id: string
1634
- /** Callback invoked with RAF timestamp in ms */
1635
- callback: (timestamp: number) => void
1636
- }
1637
-
1638
- // HMR Support --------------------------------
1639
-
1640
- /**
1641
- * Hot Module Replacement data structure for preserving scheduler state
1642
- * @internal
1643
- */
1644
- interface HMRData {
1645
- /** Shared data object for storing values across reloads */
1646
- data: Record<string, any>
1647
- /** Optional function to accept HMR updates */
1648
- accept?: () => void
1649
- }
1650
-
1651
- // Default Phases --------------------------------
1652
-
1653
- /**
1654
- * Default phase names for the scheduler
1655
- */
1656
- type DefaultPhase = 'start' | 'input' | 'physics' | 'update' | 'render' | 'finish'
1777
+ declare module 'react/jsx-runtime' {
1778
+ namespace JSX {
1779
+ interface IntrinsicElements extends ThreeElements {}
1780
+ }
1657
1781
  }
1658
1782
 
1659
- type MutableOrReadonlyParameters<T extends (...args: any) => any> = Parameters<T> | Readonly<Parameters<T>>
1660
-
1661
- interface MathRepresentation {
1662
- set(...args: number[]): any
1663
- }
1664
- interface VectorRepresentation extends MathRepresentation {
1665
- setScalar(value: number): any
1666
- }
1667
- type MathTypes = MathRepresentation | Euler$2 | Color$2
1668
-
1669
- type MathType<T extends MathTypes> = T extends Color$2
1670
- ? Args<typeof Color$2> | ColorRepresentation$1
1671
- : T extends VectorRepresentation | Layers$1 | Euler$2
1672
- ? T | MutableOrReadonlyParameters<T['set']> | number
1673
- : T | MutableOrReadonlyParameters<T['set']>
1674
-
1675
- type MathProps<P> = {
1676
- [K in keyof P as P[K] extends MathTypes ? K : never]: P[K] extends MathTypes ? MathType<P[K]> : never
1677
- }
1678
-
1679
- type Vector2 = MathType<Vector2$1>
1680
- type Vector3 = MathType<Vector3$1>
1681
- type Vector4 = MathType<Vector4$1>
1682
- type Color = MathType<Color$2>
1683
- type Layers = MathType<Layers$1>
1684
- type Quaternion = MathType<Quaternion$1>
1685
- type Euler = MathType<Euler$2>
1686
- type Matrix3 = MathType<Matrix3$1>
1687
- type Matrix4 = MathType<Matrix4$1>
1688
-
1689
- interface RaycastableRepresentation {
1690
- raycast(raycaster: Raycaster, intersects: Intersection$1[]): void
1691
- }
1692
- type EventProps<P> = P extends RaycastableRepresentation ? Partial<EventHandlers> : {}
1693
-
1694
- /**
1695
- * Props for geometry transform methods that can be called with `once()`.
1696
- * These methods modify the geometry in-place and only make sense to call once on mount.
1697
- *
1698
- * @example
1699
- * import { once } from '@react-three/fiber'
1700
- *
1701
- * <boxGeometry args={[1, 1, 1]} rotateX={once(Math.PI / 2)} />
1702
- * <planeGeometry args={[10, 10]} translate={once(0, 0, 5)} />
1703
- * <bufferGeometry applyMatrix4={once(matrix)} center={once()} />
1704
- */
1705
- interface GeometryTransformProps {
1706
- /** Rotate the geometry about the X axis (radians). Use with once(). */
1707
- rotateX?: number
1708
- /** Rotate the geometry about the Y axis (radians). Use with once(). */
1709
- rotateY?: number
1710
- /** Rotate the geometry about the Z axis (radians). Use with once(). */
1711
- rotateZ?: number
1712
- /** Translate the geometry (x, y, z). Use with once(). */
1713
- translate?: [x: number, y: number, z: number]
1714
- /** Scale the geometry (x, y, z). Use with once(). */
1715
- scale?: [x: number, y: number, z: number]
1716
- /** Center the geometry based on bounding box. Use with once(). */
1717
- center?: true
1718
- /** Apply a Matrix4 transformation. Use with once(). */
1719
- applyMatrix4?: Matrix4$1
1720
- /** Apply a Quaternion rotation. Use with once(). */
1721
- applyQuaternion?: Quaternion$1
1722
- }
1723
-
1724
- type GeometryProps<P> = P extends BufferGeometry ? GeometryTransformProps : {}
1725
-
1726
- /**
1727
- * Workaround for @types/three TSL node type issues.
1728
- * The Node base class has properties that subclasses (OperatorNode, ConstNode, etc.) don't inherit.
1729
- * This transforms `Node | null` properties to accept any object with node-like shape.
1730
- */
1731
- type TSLNodeInput = { nodeType?: string | null; uuid?: string } | null
1732
-
1733
- /**
1734
- * For node material properties (colorNode, positionNode, etc.), accept broader types
1735
- * since @types/three has broken inheritance for TSL node subclasses.
1736
- */
1737
- type NodeProps<P> = {
1738
- [K in keyof P as P[K] extends Node | null ? K : never]?: TSLNodeInput
1739
- }
1740
-
1741
- interface ReactProps<P> {
1742
- children?: React.ReactNode
1743
- ref?: React.Ref<P>
1744
- key?: React.Key
1745
- }
1746
-
1747
- type ElementProps<T extends ConstructorRepresentation, P = InstanceType<T>> = Partial<
1748
- Overwrite<P, MathProps<P> & ReactProps<P> & EventProps<P> & GeometryProps<P> & NodeProps<P>>
1749
- >
1750
-
1751
- type ThreeElement<T extends ConstructorRepresentation> = Mutable<
1752
- Overwrite<ElementProps<T>, Omit<InstanceProps<InstanceType<T>, T>, 'object'>>
1753
- >
1754
-
1755
- type ThreeToJSXElements<T extends Record<string, any>> = {
1756
- [K in keyof T & string as Uncapitalize<K>]: T[K] extends ConstructorRepresentation ? ThreeElement<T[K]> : never
1757
- }
1758
-
1759
- type ThreeExports = typeof THREE
1760
- type ThreeElementsImpl = ThreeToJSXElements<ThreeExports>
1761
-
1762
- interface ThreeElements extends Omit<ThreeElementsImpl, 'audio' | 'source' | 'line' | 'path'> {
1763
- primitive: Omit<ThreeElement<any>, 'args'> & { object: object }
1764
- // Conflicts with DOM types can be accessed through a three* prefix
1765
- threeAudio: ThreeElementsImpl['audio']
1766
- threeSource: ThreeElementsImpl['source']
1767
- threeLine: ThreeElementsImpl['line']
1768
- threePath: ThreeElementsImpl['path']
1769
- }
1770
-
1771
- declare module 'react' {
1772
- namespace JSX {
1773
- interface IntrinsicElements extends ThreeElements {}
1774
- }
1775
- }
1776
-
1777
- declare module 'react/jsx-runtime' {
1778
- namespace JSX {
1779
- interface IntrinsicElements extends ThreeElements {}
1780
- }
1781
- }
1782
-
1783
- declare module 'react/jsx-dev-runtime' {
1784
- namespace JSX {
1785
- interface IntrinsicElements extends ThreeElements {}
1786
- }
1783
+ declare module 'react/jsx-dev-runtime' {
1784
+ namespace JSX {
1785
+ interface IntrinsicElements extends ThreeElements {}
1786
+ }
1787
1787
  }
1788
1788
 
1789
1789
  type three_d_Color = Color;
@@ -1893,7 +1893,7 @@ type EnvironmentLoaderProps = {
1893
1893
  * const texture = useEnvironment({ preset: 'sunset' })
1894
1894
  * ```
1895
1895
  */
1896
- declare function useEnvironment({ files, path, preset, colorSpace, extensions, }?: Partial<EnvironmentLoaderProps>): Texture$1<unknown> | CubeTexture;
1896
+ declare function useEnvironment({ files, path, preset, colorSpace, extensions, }?: Partial<EnvironmentLoaderProps>): Texture$1<unknown, THREE$1.TextureEventMap> | CubeTexture<unknown>;
1897
1897
  declare namespace useEnvironment {
1898
1898
  var preload: (preloadOptions?: EnvironmentLoaderPreloadOptions) => void;
1899
1899
  var clear: (clearOptions?: EnvironmentLoaderClearOptions) => void;