@react-three/fiber 10.0.0-canary.8f5b4d3 → 10.0.0-canary.975e1e7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/dist/chunks/webgl.cjs +27 -0
  2. package/dist/chunks/webgl.mjs +11 -0
  3. package/dist/chunks/webgpu.cjs +37 -0
  4. package/dist/chunks/webgpu.mjs +21 -0
  5. package/dist/extension.cjs +12 -0
  6. package/dist/extension.d.cts +56 -0
  7. package/dist/extension.d.mts +56 -0
  8. package/dist/extension.d.ts +56 -0
  9. package/dist/extension.mjs +1 -0
  10. package/dist/index.cjs +97 -15308
  11. package/dist/index.d.cts +123 -3729
  12. package/dist/index.d.mts +123 -3729
  13. package/dist/index.d.ts +123 -3729
  14. package/dist/index.mjs +10 -15209
  15. package/dist/legacy.cjs +97 -15267
  16. package/dist/legacy.d.cts +114 -3735
  17. package/dist/legacy.d.mts +114 -3735
  18. package/dist/legacy.d.ts +114 -3735
  19. package/dist/legacy.mjs +14 -15171
  20. package/dist/shared/fiber.Bw8YnGg5.d.cts +701 -0
  21. package/dist/shared/fiber.Bw8YnGg5.d.mts +701 -0
  22. package/dist/shared/fiber.Bw8YnGg5.d.ts +701 -0
  23. package/dist/shared/fiber.COTqIf4o.mjs +15031 -0
  24. package/dist/shared/fiber.COk97oyZ.cjs +15129 -0
  25. package/dist/shared/fiber.D9dtW9DT.cjs +367 -0
  26. package/dist/shared/fiber.D9zziEOb.mjs +337 -0
  27. package/dist/shared/fiber.DAg-9ieU.d.ts +2852 -0
  28. package/dist/shared/fiber.Ddgoyqql.d.mts +2852 -0
  29. package/dist/shared/fiber.DiPB625B.d.cts +2852 -0
  30. package/dist/webgpu/index.cjs +100 -16123
  31. package/dist/webgpu/index.d.cts +128 -4093
  32. package/dist/webgpu/index.d.mts +128 -4093
  33. package/dist/webgpu/index.d.ts +128 -4093
  34. package/dist/webgpu/index.mjs +17 -16009
  35. package/package.json +9 -6
  36. package/readme.md +1 -1
  37. package/react-reconciler/constants.d.ts +0 -7
  38. package/react-reconciler/constants.js +0 -1
  39. package/react-reconciler/index.d.ts +0 -1044
  40. package/react-reconciler/index.js +0 -208
@@ -1,4056 +1,89 @@
1
- import * as three_webgpu from 'three/webgpu';
2
- import { CubeRenderTarget, RenderTarget, WebGPURenderer, Node, StorageTexture, Data3DTexture, CanvasTarget, ShaderNodeObject, Euler as Euler$2, Color as Color$2, ColorRepresentation as ColorRepresentation$1, Layers as Layers$1, Raycaster, Intersection as Intersection$1, BufferGeometry, Matrix4 as Matrix4$1, Quaternion as Quaternion$1, Vector2 as Vector2$1, Vector3 as Vector3$1, Vector4 as Vector4$1, Matrix3 as Matrix3$1, Loader as Loader$1, ColorSpace, Texture as Texture$1, CubeTexture, Scene, Object3D, Frustum, OrthographicCamera, WebGPURendererParameters } from 'three/webgpu';
3
- import { Inspector } from 'three/addons/inspector/Inspector.js';
4
- import * as THREE$1 from 'three';
5
- import { Color as Color$1, ColorRepresentation, Euler as Euler$1, Loader, RenderTargetOptions as RenderTargetOptions$1 } from 'three';
6
- import * as React$1 from 'react';
7
- import { ReactNode, Component, RefObject, JSX } from 'react';
1
+ import * as ThreeWebGPU from 'three/webgpu';
2
+ import { WebGPURenderer, WebGPURendererParameters, RenderTarget } from 'three/webgpu';
3
+ import { M as MutableOrReadonlyParameters$1, a as MathRepresentation$1, V as VectorRepresentation$1, b as MathTypes$1, c as MathType$1, d as MathProps$1, e as Vector2$1, f as Vector3$1, g as Vector4$1, C as Color$1, L as Layers$1, Q as Quaternion$1, E as Euler$1, h as Matrix3$1, i as Matrix4$1, R as RaycastableRepresentation$1, j as EventProps$1, G as GeometryTransformProps$1, k as GeometryProps$1, T as TSLNodeInput$1, N as NodeProps$1, l as ReactProps$1, m as ConstructorRepresentation, n as ElementProps$1, o as ThreeElement$1, p as ThreeToJSXElements$1, O as Object3DMethod$1, q as ThreeElementsOf$1, r as ElementOf$1, J as RendererFactory, I as BaseRendererProps, s as CanvasProps, u as ReconcilerRoot, v as RenderTargetOptions } from '../shared/fiber.DAg-9ieU.js';
4
+ export { a7 as Args, a8 as ArgsProp, a4 as AttachFnType, a5 as AttachType, ae as BackgroundConfig, af as BackgroundProp, b8 as Block, $ as CameraProps, Y as CanvasSchedulerConfig, a6 as Catalogue, P as ColorManagementConfig, S as DefaultGLProps, X as DefaultRendererProps, aO as DisposeOptions, ay as Environment, aw as EnvironmentCube, aR as EnvironmentLoaderProps, av as EnvironmentMap, ax as EnvironmentPortal, au as EnvironmentProps, b9 as ErrorBoundary, am as Extensions, bD as FROM_REF, a2 as FiberRoot, bE as FromRefMarker, U as GLProps, ai as GLTFLike, ad as GlobalEffectType, ac as GlobalRenderCallback, ab as HostConfig, ak as InferLoadResult, a1 as InjectState, ag as InputLike, aa as Instance, a9 as InstanceProps, aH as IsObject, x as LegacyInternalState, y as LegacyRenderer, t as LegacyRootState, aj as LoaderInstance, ah as LoaderLike, al as LoaderResult, aI as MappedTextureType, bH as ONCE, H as OffscreenCanvas, bJ as OnceValue, b2 as Portal, aA as PresetsType, an as PrimaryCanvasEntry, ba as REACT_INTERNAL_PROPS, bi as RESERVED_PROPS, a0 as RenderProps, K as Renderer, Z as RendererConfigExtended, _ as RendererProps, a3 as Root, aL as Texture, aM as TextureInput, aN as TextureResult, aJ as UseTextureOptions, aP as UseTexturesReturn, z as WebGLDefaultProps, W as WebGLProps, A as WebGLShadowConfig, a$ as _roots, aU as addAfterEffect, aT as addEffect, aV as addTail, aX as advance, bn as applyProps, bk as attach, bd as buildGraph, bo as calculateDpr, aD as createEvents, w as createPointerEvents, b1 as createPortal, b4 as createStore, bl as detach, bm as diffProps, be as dispose, w as events, aY as extend, bb as findInitialRoot, b3 as flushSync, bF as fromRef, bf as getInstanceProps, ap as getPrimary, at as getPrimaryIds, bc as getRootState, B as getThree, bp as getUuidPrefix, bC as hasConstructor, ar as hasPrimary, D as hasThree, aW as invalidate, bh as invalidateInstance, bs as is, bv as isColorRepresentation, bB as isCopyable, bG as isFromRef, by as isLayers, bw as isObject3D, bK as isOnce, bt as isOrthographicCamera, bu as isRef, a_ as isRenderer, bx as isTexture, bz as isUniform, bA as isVectorLike, bI as once, bg as prepare, az as presetsObj, aZ as reconciler, ao as registerPrimary, aC as removeInteractivity, bj as resolve, aB as swapInteractivity, b0 as unmountComponentAtNode, as as unregisterPrimary, bq as updateCamera, br as updateFrustum, b7 as useBridge, aS as useEnvironment, aF as useGraph, aE as useInstanceHandle, b5 as useIsomorphicLayoutEffect, aG as useLoader, b6 as useMutableCallback, aK as useTexture, aQ as useTextures, aq as waitForPrimary, F as whenThree } from '../shared/fiber.DAg-9ieU.js';
5
+ import { a6 as RootState, a5 as InternalState, n as Properties } from '../shared/fiber.Bw8YnGg5.js';
6
+ export { A as Act, B as Bridge, C as Camera, i as ComputeFunction, w as Disposable, f as DomEvent, D as Dpr, v as EquConfig, g as EventHandlers, k as EventManager, E as Events, h as FilterFunction, $ as ForRegisteredRenderer, G as FrameCallback, z as FrameNextCallback, x as FrameNextState, y as FrameState, F as Frameloop, I as Intersection, e as IntersectionEvent, p as IsAllOptional, o as IsOptional, M as Mutable, N as NonFunctionKeys, u as ObjectMap, K as OcclusionSupport, O as Overwrite, c as Performance, l as PointerCaptureTarget, P as PointerState, a0 as R3FRenderTarget, a1 as R3FRendererSupport, Z as Register, _ as RegisteredRenderer, b as RenderCallback, Y as RendererProvider, Q as RendererSupport, R as RootExtension, d as RootStore, t as SetBlock, a as Size, S as Subscription, q as ThreeCamera, J as ThreeCore, T as ThreeEvent, H as ThreeNamespace, U as UnblockProps, V as Viewport, m as VisibilityEntry, W as WebGLSupport, L as WebGPUSupport, X as XRManager, j as XRPointerConfig, a3 as context, r as registerRootExtension, s as setRenderOverride, a2 as useStore } from '../shared/fiber.Bw8YnGg5.js';
7
+ import { Texture } from 'three';
8
8
  import { StoreApi } from 'zustand';
9
- import { UseBoundStoreWithEqualityFn } from 'zustand/traditional';
10
- import { FrameTimingState, FrameCallback as FrameCallback$1, SchedulerApi, UseFrameNextOptions, FrameNextControls } from '@pmndrs/scheduler';
9
+ import { FrameCallback, UseFrameNextOptions, FrameNextControls } from '@pmndrs/scheduler';
11
10
  export { AddPhaseOptions, FrameControls, FrameNextControls, FrameTimingState, RootOptions, Scheduler, SchedulerApi, UseFrameNextOptions, UseFrameOptions, getScheduler } from '@pmndrs/scheduler';
12
- import { Options } from 'react-use-measure';
13
- import * as react_jsx_runtime from 'react/jsx-runtime';
14
- import { GroundedSkybox } from 'three/examples/jsm/objects/GroundedSkybox.js';
15
-
16
- function _mergeNamespaces(n, m) {
17
- m.forEach(function (e) {
18
- e && typeof e !== 'string' && !Array.isArray(e) && Object.keys(e).forEach(function (k) {
19
- if (k !== 'default' && !(k in n)) {
20
- var d = Object.getOwnPropertyDescriptor(e, k);
21
- Object.defineProperty(n, k, d.get ? d : {
22
- enumerable: true,
23
- get: function () { return e[k]; }
24
- });
25
- }
26
- });
27
- });
28
- return Object.freeze(n);
29
- }
30
-
31
- /**
32
- * @fileoverview Internal Three.js re-exports - WEBGPU ONLY ENTRY
33
- *
34
- * Pure WebGPU path - no WebGL legacy.
35
- * Use this for the explicit webgpu import path: @react-three/fiber/webgpu
36
- *
37
- * This is for apps that want ONLY WebGPU with no legacy fallback.
38
- * Attempting to use WebGLRenderer will cause type/runtime errors (intentional).
39
- */
40
- declare const R3F_BUILD_LEGACY = false;
41
- declare const R3F_BUILD_WEBGPU = true;
42
-
43
- declare const WebGLRenderer: {
44
- new (): {};
45
- };
46
- type WebGLRendererParameters = never;
47
- type WebGLShadowMap = never;
48
-
49
- declare const WebGLRenderTarget: any;
50
-
51
- declare const WebGLCubeRenderTarget: any;
52
-
53
- var THREE = /*#__PURE__*/_mergeNamespaces({
54
- __proto__: null,
55
- CubeRenderTargetCompat: CubeRenderTarget,
56
- Inspector: Inspector,
57
- R3F_BUILD_LEGACY: R3F_BUILD_LEGACY,
58
- R3F_BUILD_WEBGPU: R3F_BUILD_WEBGPU,
59
- RenderTargetCompat: RenderTarget,
60
- WebGLCubeRenderTarget: WebGLCubeRenderTarget,
61
- WebGLRenderTarget: WebGLRenderTarget,
62
- WebGLRenderer: WebGLRenderer,
63
- WebGLRendererParameters: WebGLRendererParameters,
64
- WebGLShadowMap: WebGLShadowMap
65
- }, [three_webgpu]);
66
-
67
- //* Utility Types ==============================
68
-
69
- type NonFunctionKeys<P> = { [K in keyof P]-?: P[K] extends Function ? never : K }[keyof P]
70
- type Overwrite<P, O> = Omit<P, NonFunctionKeys<O>> & O
71
- type Properties<T> = Pick<T, NonFunctionKeys<T>>
72
- type Mutable<P> = { -readonly [K in keyof P]: P[K] }
73
- type IsOptional<T> = undefined extends T ? true : false
74
- type IsAllOptional<T extends any[]> = T extends [infer First, ...infer Rest]
75
- ? IsOptional<First> extends true
76
- ? IsAllOptional<Rest>
77
- : false
78
- : true
79
-
80
- //* Camera Types ==============================
81
-
82
- type ThreeCamera = (THREE$1.OrthographicCamera | THREE$1.PerspectiveCamera) & { manual?: boolean }
83
-
84
- //* Act Type ==============================
85
-
86
- type Act = <T = any>(cb: () => Promise<T>) => Promise<T>
87
-
88
- //* Bridge & Block Types ==============================
89
-
90
- type Bridge = React$1.FC<{ children?: React$1.ReactNode }>
91
-
92
- type SetBlock = false | Promise<null> | null
93
- type UnblockProps = { set: React$1.Dispatch<React$1.SetStateAction<SetBlock>>; children: React$1.ReactNode }
94
-
95
- //* Object Map Type ==============================
96
-
97
- /* Original version
98
- export interface ObjectMap {
99
- nodes: { [name: string]: THREE.Object3D }
100
- materials: { [name: string]: THREE.Material }
101
- meshes: { [name: string]: THREE.Mesh }
102
- }
103
- */
104
- /* This version is an expansion found in a PR by itsdouges that seems abandoned but looks useful.
105
- It allows expansion but falls back to the original shape. (deleted due to stale, but If it doesnt conflict
106
- I will keep the use here)
107
- https://github.com/pmndrs/react-three-fiber/commits/generic-object-map/
108
- His description is:
109
- The object map type is now generic and can optionally declare the available properties for nodes, materials, and meshes.
110
- */
111
- interface ObjectMap<
112
- T extends { nodes?: string; materials?: string; meshes?: string } = {
113
- nodes: string
114
- materials: string
115
- meshes: string
116
- },
117
- > {
118
- nodes: Record<T['nodes'] extends string ? T['nodes'] : string, THREE$1.Object3D>
119
- materials: Record<T['materials'] extends string ? T['materials'] : string, THREE$1.Material>
120
- meshes: Record<T['meshes'] extends string ? T['meshes'] : string, THREE$1.Mesh>
121
- }
122
-
123
- //* Equality Config ==============================
124
-
125
- interface EquConfig {
126
- /** Compare arrays by reference equality a === b (default), or by shallow equality */
127
- arrays?: 'reference' | 'shallow'
128
- /** Compare objects by reference equality a === b (default), or by shallow equality */
129
- objects?: 'reference' | 'shallow'
130
- /** If true the keys in both a and b must match 1:1 (default), if false a's keys must intersect b's */
131
- strict?: boolean
132
- }
133
-
134
- //* Disposable Type ==============================
135
-
136
- interface Disposable {
137
- type?: string
138
- dispose?: () => void
139
- }
140
-
141
- //* Event-related Types =====================================
142
-
143
- interface Intersection extends THREE$1.Intersection {
144
- /** The event source (the object which registered the handler) */
145
- eventObject: THREE$1.Object3D
146
- }
147
-
148
- type Camera = THREE$1.OrthographicCamera | THREE$1.PerspectiveCamera
149
-
150
- interface IntersectionEvent<TSourceEvent> extends Intersection {
151
- /** The event source (the object which registered the handler) */
152
- eventObject: THREE$1.Object3D
153
- /** An array of intersections */
154
- intersections: Intersection[]
155
- /** vec3.set(pointer.x, pointer.y, 0).unproject(camera) */
156
- unprojectedPoint: THREE$1.Vector3
157
- /** Normalized event coordinates */
158
- pointer: THREE$1.Vector2
159
- /** pointerId of the original event for multiple pointer events */
160
- pointerId: number
161
- /** Delta between first click and this event */
162
- delta: number
163
- /** The ray that pierced it */
164
- ray: THREE$1.Ray
165
- /** The camera that was used by the raycaster */
166
- camera: Camera
167
- /** stopPropagation will stop underlying handlers from firing */
168
- stopPropagation: () => void
169
- /** The original host event */
170
- nativeEvent: TSourceEvent
171
- /** If the event was stopped by calling stopPropagation */
172
- stopped: boolean
173
- }
174
-
175
- type ThreeEvent<TEvent> = IntersectionEvent<TEvent> & Properties<TEvent>
176
- type DomEvent = PointerEvent | MouseEvent | WheelEvent
177
-
178
- /** DOM event handlers registered on the canvas element */
179
- interface Events {
180
- onClick: EventListener
181
- onContextMenu: EventListener
182
- onDoubleClick: EventListener
183
- onWheel: EventListener
184
- onPointerDown: EventListener
185
- onPointerUp: EventListener
186
- onPointerLeave: EventListener
187
- onPointerMove: EventListener
188
- onPointerCancel: EventListener
189
- onLostPointerCapture: EventListener
190
- onDragEnter: EventListener
191
- onDragLeave: EventListener
192
- onDragOver: EventListener
193
- onDrop: EventListener
194
- }
195
-
196
- /** Event handlers that can be attached to R3F objects (meshes, groups, etc.) */
197
- interface EventHandlers {
198
- onClick?: (event: ThreeEvent<MouseEvent>) => void
199
- onContextMenu?: (event: ThreeEvent<MouseEvent>) => void
200
- onDoubleClick?: (event: ThreeEvent<MouseEvent>) => void
201
- /** Fires continuously while dragging over the object */
202
- onDragOver?: (event: ThreeEvent<DragEvent>) => void
203
- /** Fires once when drag enters the object */
204
- onDragOverEnter?: (event: ThreeEvent<DragEvent>) => void
205
- /** Fires once when drag leaves the object */
206
- onDragOverLeave?: (event: ThreeEvent<DragEvent>) => void
207
- /** Fires when drag misses this object (for objects that have drag handlers) */
208
- onDragOverMissed?: (event: DragEvent) => void
209
- /** Fires when a drop occurs on this object */
210
- onDrop?: (event: ThreeEvent<DragEvent>) => void
211
- /** Fires when a drop misses this object (for objects that have drop handlers) */
212
- onDropMissed?: (event: DragEvent) => void
213
- onPointerUp?: (event: ThreeEvent<PointerEvent>) => void
214
- onPointerDown?: (event: ThreeEvent<PointerEvent>) => void
215
- onPointerOver?: (event: ThreeEvent<PointerEvent>) => void
216
- onPointerOut?: (event: ThreeEvent<PointerEvent>) => void
217
- onPointerEnter?: (event: ThreeEvent<PointerEvent>) => void
218
- onPointerLeave?: (event: ThreeEvent<PointerEvent>) => void
219
- onPointerMove?: (event: ThreeEvent<PointerEvent>) => void
220
- onPointerMissed?: (event: MouseEvent) => void
221
- onPointerCancel?: (event: ThreeEvent<PointerEvent>) => void
222
- onWheel?: (event: ThreeEvent<WheelEvent>) => void
223
- onLostPointerCapture?: (event: ThreeEvent<PointerEvent>) => void
224
-
225
- //* Visibility Events --------------------------------
226
- /** Fires when object enters/exits camera frustum. Receives true when in view, false when out. */
227
- onFramed?: (inView: boolean) => void
228
- /** Fires when object occlusion state changes (WebGPU only, requires occlusionTest=true on object) */
229
- onOccluded?: (occluded: boolean) => void
230
- /** Fires when combined visibility changes (frustum + occlusion + visible prop) */
231
- onVisible?: (visible: boolean) => void
232
- }
233
-
234
- type FilterFunction = (items: THREE$1.Intersection[], state: RootState) => THREE$1.Intersection[]
235
- type ComputeFunction = (event: DomEvent, root: RootState, previous?: RootState) => void
236
-
237
- /** Configuration for XR pointer registration (controllers/hands) */
238
- interface XRPointerConfig {
239
- /** Ray origin (updated each frame by XR system) */
240
- ray: THREE$1.Ray
241
- /** Optional: custom compute function for this pointer */
242
- compute?: (state: RootState) => void
243
- /** Pointer type identifier */
244
- type: 'controller' | 'hand' | 'gaze'
245
- /** Which hand (for controller/hand types) */
246
- handedness?: 'left' | 'right'
247
- }
248
-
249
- interface EventManager<TTarget> {
250
- /** Determines if the event layer is active */
251
- enabled: boolean
252
- /** Event layer priority, higher prioritized layers come first and may stop(-propagate) lower layer */
253
- priority: number
254
- /** The compute function needs to set up the raycaster and an xy- pointer */
255
- compute?: ComputeFunction
256
- /** The filter can re-order or re-structure the intersections */
257
- filter?: FilterFunction
258
- /** The target node the event layer is tied to */
259
- connected?: TTarget
260
- /** All the pointer event handlers through which the host forwards native events */
261
- handlers?: Events
262
- /** Allows re-connecting to another target */
263
- connect?: (target: TTarget) => void
264
- /** Removes all existing events handlers from the target */
265
- disconnect?: () => void
266
- /** Triggers a onPointerMove with the last known event. This can be useful to enable raycasting without
267
- * explicit user interaction, for instance when the camera moves a hoverable object underneath the cursor.
268
- * @param pointerId - Optional pointer ID to update specific pointer only
269
- */
270
- update?: (pointerId?: number) => void
271
- /** Defer pointer move raycasting to frame start (default: true) */
272
- frameTimedRaycasts?: boolean
273
- /** Always fire raycaster immediately on scroll events (default: true) */
274
- alwaysFireOnScroll?: boolean
275
- /** Automatically re-raycast every frame to detect hover changes from moving objects/camera (default: false) */
276
- updateOnFrame?: boolean
277
- /** Flush deferred pointer raycasts. Called by scheduler at frame start (input phase). */
278
- flush?: () => void
279
- /** Register an XR pointer (controller/hand). Returns assigned pointerId */
280
- registerPointer?: (config: XRPointerConfig) => number
281
- /** Unregister an XR pointer */
282
- unregisterPointer?: (pointerId: number) => void
283
- }
284
-
285
- interface PointerCaptureTarget {
286
- intersection: Intersection
287
- target: Element
288
- }
289
-
290
- //* Visibility System Types =====================================
291
-
292
- /** Entry in the visibility registry for tracking object visibility state */
293
- interface VisibilityEntry {
294
- object: THREE$1.Object3D
295
- handlers: Pick<EventHandlers, 'onFramed' | 'onOccluded' | 'onVisible'>
296
- lastFramedState: boolean | null
297
- lastOccludedState: boolean | null
298
- lastVisibleState: boolean | null
299
- }
300
-
301
- //* Scheduler Types (useFrame) ==============================
302
- //
303
- // The generic, framework-agnostic scheduler types now live in @pmndrs/scheduler.
304
- // This file re-exports them and layers r3f's RootState-aware frame state on top,
305
- // so existing `#types` imports across the codebase keep resolving unchanged.
306
-
307
-
308
-
309
- // Frame State (r3f-specific) --------------------------------
310
-
311
- /**
312
- * State passed to useFrame callbacks (extends RootState with timing).
313
- */
314
- interface FrameNextState extends RootState, FrameTimingState {}
315
-
316
- /** Alias for FrameNextState */
317
- type FrameState = FrameNextState
318
-
319
- // Callback Types (r3f-specific) --------------------------------
320
-
321
- /**
322
- * Callback function for useFrame. Receives the full r3f RootState plus timing.
323
- */
324
- type FrameNextCallback = FrameCallback$1<RootState>
325
-
326
- /** Alias for FrameNextCallback */
327
- type FrameCallback = FrameNextCallback
328
-
329
- //* Buffer Types (useBuffers) ========================================
330
-
331
- /**
332
- * Buffer-like types for GPU compute and storage operations.
333
- * Includes raw CPU arrays, Three.js buffer attributes, and TSL buffer nodes.
334
- *
335
- * @example
336
- * ```tsx
337
- * const { positions, velocities } = useBuffers(() => ({
338
- * positions: instancedArray(count, 'vec3'), // StorageBufferNode
339
- * velocities: new Float32Array(count * 3), // TypedArray
340
- * }), 'particles')
341
- * ```
342
- */
343
- type BufferLike =
344
- | Float32Array
345
- | Uint32Array
346
- | Int32Array
347
- | Float64Array
348
- | Uint8Array
349
- | Int8Array
350
- | Uint16Array
351
- | Int16Array
352
- | THREE$1.BufferAttribute // Base class for all buffer attributes
353
- | Node // TSL buffer nodes (instancedArray, storage)
354
-
355
- /** Flat record of buffer-like values (no nested scopes) */
356
- type BufferRecord = Record<string, BufferLike>
357
-
358
- /**
359
- * Buffer store that can contain both root-level buffers and scoped buffer objects.
360
- * Structure: { positions: Float32Array, particles: { vel: StorageBufferNode } }
361
- */
362
- type BufferStore = Record<string, BufferLike | BufferRecord>
363
-
364
- //* Storage Types (useGPUStorage) ========================================
365
-
366
- /**
367
- * GPU storage types for texture-based storage operations.
368
- * Includes Three.js storage textures and TSL storage texture nodes.
369
- *
370
- * @example
371
- * ```tsx
372
- * const { heightMap } = useGPUStorage(() => ({
373
- * heightMap: new StorageTexture(512, 512),
374
- * }), 'terrain')
375
- * ```
376
- */
377
- type StorageLike =
378
- | StorageTexture // GPU storage texture
379
- | Data3DTexture // 3D texture (can be used as storage)
380
- | Node // TSL storage texture nodes (storageTexture)
381
-
382
- /** Flat record of storage-like values (no nested scopes) */
383
- type StorageRecord = Record<string, StorageLike>
384
-
385
- /**
386
- * Storage store that can contain both root-level storage and scoped storage objects.
387
- * Structure: { heightMap: StorageTexture, terrain: { normal: StorageTextureNode } }
388
- */
389
- type StorageStore = Record<string, StorageLike | StorageRecord>
390
-
391
- //* Renderer Types ========================================
392
-
393
- /** Default renderer type - union of WebGL and WebGPU renderers */
394
- type R3FRenderer = THREE$1.WebGLRenderer | WebGPURenderer
395
-
396
- //* Core Store Types ========================================
397
-
398
- type Subscription = {
399
- ref: React$1.RefObject<RenderCallback>
400
- priority: number
401
- store: RootStore
402
- }
403
-
404
- /** Per-pointer state for multi-touch and XR support */
405
- type PointerState = {
406
- /** Objects currently hovered by this pointer */
407
- hovered: Map<string, ThreeEvent<DomEvent>>
408
- /** Objects capturing this pointer */
409
- captured: Map<THREE$1.Object3D, PointerCaptureTarget>
410
- /** Initial click position [x, y] */
411
- initialClick: [x: number, y: number]
412
- /** Objects hit on initial click */
413
- initialHits: THREE$1.Object3D[]
414
- }
415
-
416
- type Dpr = number | [min: number, max: number]
417
-
418
- interface Size {
419
- width: number
420
- height: number
421
- top: number
422
- left: number
423
- }
424
-
425
- type Frameloop = 'always' | 'demand' | 'never'
426
-
427
- interface Viewport extends Size {
428
- /** The initial pixel ratio */
429
- initialDpr: number
430
- /** Current pixel ratio */
431
- dpr: number
432
- /** size.width / viewport.width */
433
- factor: number
434
- /** Camera distance */
435
- distance: number
436
- /** Camera aspect ratio: width / height */
437
- aspect: number
438
- }
439
-
440
- type RenderCallback = (state: RootState, delta: number, frame?: XRFrame) => void
441
-
442
- interface Performance {
443
- /** Current performance normal, between min and max */
444
- current: number
445
- /** How low the performance can go, between 0 and max */
446
- min: number
447
- /** How high the performance can go, between min and max */
448
- max: number
449
- /** Time until current returns to max in ms */
450
- debounce: number
451
- /** Sets current to min, puts the system in regression */
452
- regress: () => void
453
- }
454
-
455
- interface InternalState {
456
- interaction: THREE$1.Object3D[]
457
- subscribers: Subscription[]
458
- /** Per-pointer state (hover, capture, click tracking) - replaces hovered, capturedMap, initialClick, initialHits */
459
- pointerMap: Map<number, PointerState>
460
- /** Pointers needing raycast this frame (used with frameTimedRaycasts) */
461
- pointerDirty: Map<number, DomEvent>
462
- /** Last event received (for events.update() compatibility) */
463
- lastEvent: React$1.RefObject<DomEvent | null>
464
- /** @deprecated Use pointerMap.get(pointerId).hovered instead */
465
- hovered: Map<string, ThreeEvent<DomEvent>>
466
- /** @deprecated Use pointerMap.get(pointerId).captured instead */
467
- capturedMap: Map<number, Map<THREE$1.Object3D, PointerCaptureTarget>>
468
- /** @deprecated Use pointerMap.get(pointerId).initialClick instead */
469
- initialClick: [x: number, y: number]
470
- /** @deprecated Use pointerMap.get(pointerId).initialHits instead */
471
- initialHits: THREE$1.Object3D[]
472
- /** Visibility event registry (onFramed, onOccluded, onVisible) */
473
- visibilityRegistry: Map<string, VisibilityEntry>
474
- /** Whether occlusion queries are enabled (WebGPU only) */
475
- occlusionEnabled: boolean
476
- /** Reference to the invisible occlusion observer mesh */
477
- occlusionObserver: THREE$1.Mesh | null
478
- /** Cached occlusion results from render pass - keyed by Object3D */
479
- occlusionCache: Map<THREE$1.Object3D, boolean | null>
480
- /** Internal helper group for R3F system objects (occlusion observer, etc.) */
481
- helperGroup: THREE$1.Group | null
482
- active: boolean
483
- priority: number
484
- frames: number
485
- subscribe: (callback: React$1.RefObject<RenderCallback>, priority: number, store: RootStore) => () => void
486
- /** Internal renderer storage - use state.renderer or state.gl to access */
487
- actualRenderer: R3FRenderer
488
- /** Global scheduler reference (for useFrame hook) */
489
- scheduler: SchedulerApi | null
490
- /** This root's unique ID in the global scheduler */
491
- rootId?: string
492
- /** Function to unregister this root from the global scheduler */
493
- unregisterRoot?: () => void
494
- /** Container for child attachment (scene for root, original container for portals) */
495
- container?: THREE$1.Object3D
496
- /**
497
- * CanvasTarget for multi-canvas WebGPU rendering.
498
- * Created for all WebGPU canvases to support renderer sharing.
499
- * @see https://threejs.org/docs/#api/en/renderers/common/CanvasTarget
500
- */
501
- canvasTarget?: CanvasTarget
502
- /**
503
- * Whether multi-canvas rendering is active.
504
- * True when any canvas uses `renderer={{ primaryCanvas: 'id' }}` to share a renderer.
505
- * When true, setCanvasTarget is called before each render.
506
- */
507
- isMultiCanvas?: boolean
508
- /**
509
- * Whether this canvas is a secondary canvas sharing another's renderer.
510
- * True when `target` prop is used.
511
- */
512
- isSecondary?: boolean
513
- /**
514
- * The id of the primary canvas this secondary canvas targets.
515
- * Only set when isSecondary is true.
516
- */
517
- targetId?: string
518
- /**
519
- * Function to unregister this primary canvas from the registry.
520
- * Only set when this canvas has an `id` prop.
521
- */
522
- unregisterPrimary?: () => void
523
- /** Whether canvas dimensions are forced to even numbers */
524
- forceEven?: boolean
525
- }
526
-
527
- interface XRManager {
528
- connect: () => void
529
- disconnect: () => void
530
- }
531
-
532
- //* Root State Interface ====================================
533
-
534
- interface RootState {
535
- /** Set current state */
536
- set: StoreApi<RootState>['setState']
537
- /** Get current state */
538
- get: StoreApi<RootState>['getState']
539
- /**
540
- * Reference to the authoritative store for shared TSL resources (uniforms, nodes, etc).
541
- * - For primary/independent canvases: points to its own store (self-reference)
542
- * - For secondary canvases: points to the primary canvas's store
543
- *
544
- * Hooks like useNodes/useUniforms should read from primaryStore to ensure
545
- * consistent shared state across all canvases sharing a renderer.
546
- */
547
- primaryStore: RootStore
548
- /** @deprecated Use `renderer` instead. The instance of the renderer (typed as WebGLRenderer for backwards compat) */
549
- gl: THREE$1.WebGLRenderer
550
- /** The renderer instance - type depends on entry point (WebGPU, Legacy, or union for default) */
551
- renderer: R3FRenderer
552
- /** Inspector of the webGPU Renderer. Init in the canvas */
553
- inspector: any // Inspector type from three/webgpu
554
-
555
- /** Default camera */
556
- camera: ThreeCamera
557
- /** Camera frustum for visibility checks - auto-updated each frame when autoUpdateFrustum is true */
558
- frustum: THREE$1.Frustum
559
- /** Whether to automatically update the frustum each frame (default: true) */
560
- autoUpdateFrustum: boolean
561
- /** Default scene (may be overridden in portals to point to the portal container) */
562
- scene: THREE$1.Scene
563
- /** The actual root THREE.Scene - always points to the true scene, even inside portals */
564
- rootScene: THREE$1.Scene
565
- /** Default raycaster */
566
- raycaster: THREE$1.Raycaster
567
- /** Event layer interface, contains the event handler and the node they're connected to */
568
- events: EventManager<any>
569
- /** XR interface */
570
- xr: XRManager
571
- /** Currently used controls */
572
- controls: THREE$1.EventDispatcher | null
573
- /** Normalized event coordinates */
574
- pointer: THREE$1.Vector2
575
- /** @deprecated Normalized event coordinates, use "pointer" instead! */
576
- mouse: THREE$1.Vector2
577
- /** Color space assigned to 8-bit input textures (color maps). Most textures are authored in sRGB. */
578
- textureColorSpace: THREE$1.ColorSpace
579
- /** Render loop flags */
580
- frameloop: Frameloop
581
- performance: Performance
582
- /** Reactive pixel-size of the canvas */
583
- size: Size
584
- /** Reactive size of the viewport in threejs units */
585
- viewport: Viewport & {
586
- getCurrentViewport: (
587
- camera?: ThreeCamera,
588
- target?: THREE$1.Vector3 | Parameters<THREE$1.Vector3['set']>,
589
- size?: Size,
590
- ) => Omit<Viewport, 'dpr' | 'initialDpr'>
591
- }
592
- /** Flags the canvas for render, but doesn't render in itself */
593
- invalidate: (frames?: number, stackFrames?: boolean) => void
594
- /** Advance (render) one step */
595
- advance: (timestamp: number, runGlobalEffects?: boolean) => void
596
- /** Shortcut to setting the event layer */
597
- setEvents: (events: Partial<EventManager<any>>) => void
598
- /** Shortcut to manual sizing. No args resets to props/container. Single arg creates square. */
599
- setSize: (width?: number, height?: number, top?: number, left?: number) => void
600
- /** Shortcut to manual setting the pixel ratio */
601
- setDpr: (dpr: Dpr) => void
602
- /** Shortcut to setting frameloop flags. No args resets to 'always'. */
603
- setFrameloop: (frameloop?: Frameloop) => void
604
- /** Set error state to propagate to error boundary */
605
- setError: (error: Error | null) => void
606
- /** Current error state (null when no error) */
607
- error: Error | null
608
- /** Global TSL uniform nodes - root-level uniforms + scoped sub-objects. Use useUniforms() hook */
609
- uniforms: UniformStore
610
- /** Global TSL nodes - root-level nodes + scoped sub-objects. Use useNodes() hook */
611
- nodes: Record<string, any>
612
- /** Global TSL buffer nodes - root-level buffers + scoped sub-objects. Use useBuffers() hook */
613
- buffers: BufferStore
614
- /** Global GPU storage (textures, etc.) - root-level storage + scoped sub-objects. Use useGPUStorage() hook */
615
- gpuStorage: StorageStore
616
- /** Global Texture registry (key → Texture, usually keyed by URL) - use useTextures() hook for access + lifecycle */
617
- textures: Map<string, THREE$1.Texture>
618
- /** Internal: refcount per texture key, driven by mounted useTexture consumers (registry enrollment is on by default) */
619
- _textureRefs: Map<string, number>
620
- /** WebGPU RenderPipeline instance - use useRenderPipeline() hook */
621
- renderPipeline: ThreeRenderPipeline | null
622
- /** Global TSL pass nodes for render pipeline - use useRenderPipeline() hook */
623
- passes: Record<string, any>
624
- /** Internal version counter for HMR - incremented by rebuildNodes/rebuildUniforms to bust memoization */
625
- _hmrVersion: number
626
- /** Internal: whether setSize() has taken ownership of canvas dimensions */
627
- _sizeImperative: boolean
628
- /** Internal: stored size props from Canvas for reset functionality */
629
- _sizeProps: { width?: number; height?: number } | null
630
- /** When the canvas was clicked but nothing was hit */
631
- onPointerMissed?: (event: MouseEvent) => void
632
- /** When a dragover event has missed any target */
633
- onDragOverMissed?: (event: DragEvent) => void
634
- /** When a drop event has missed any target */
635
- onDropMissed?: (event: DragEvent) => void
636
- /** If this state model is layered (via createPortal) then this contains the previous layer */
637
- previousRoot?: RootStore
638
- /** Internals */
639
- internal: InternalState
640
- // flags for triggers
641
- // if we are using the webGl renderer, this will be true
642
- isLegacy: boolean
643
- // regardless of renderer, if the system supports webGpu, this will be true
644
- webGPUSupported: boolean
645
- //if we are on native
646
- isNative: boolean
647
- }
648
-
649
- type RootStore = UseBoundStoreWithEqualityFn<StoreApi<RootState>>
650
-
651
- //* Base Renderer Types =====================================
652
-
653
- // Shim for OffscreenCanvas since it was removed from DOM types
654
- interface OffscreenCanvas$1 extends EventTarget {}
655
-
656
- interface BaseRendererProps {
657
- canvas: HTMLCanvasElement | OffscreenCanvas$1
658
- powerPreference?: 'high-performance' | 'low-power' | 'default'
659
- antialias?: boolean
660
- alpha?: boolean
661
- }
662
-
663
- type RendererFactory<TRenderer, TParams> =
664
- | TRenderer
665
- | ((defaultProps: TParams) => TRenderer)
666
- | ((defaultProps: TParams) => Promise<TRenderer>)
667
-
668
- interface Renderer {
669
- render: (scene: THREE$1.Scene, camera: THREE$1.Camera) => any
670
- }
671
-
672
- //* Color Management Config ==============================
673
-
674
- /**
675
- * Color management configuration shared by both WebGL and WebGPU renderers.
676
- */
677
- interface ColorManagementConfig {
678
- /**
679
- * Color space assigned to 8-bit input textures (color maps).
680
- * Defaults to sRGB. Most textures are authored in sRGB.
681
- * @default THREE.SRGBColorSpace
682
- */
683
- textureColorSpace?: THREE$1.ColorSpace
684
- }
685
-
686
- //* WebGL Renderer Props ==============================
687
-
688
- type DefaultGLProps = Omit<THREE$1.WebGLRendererParameters, 'canvas'> & {
689
- canvas: HTMLCanvasElement | OffscreenCanvas$1
690
- }
691
-
692
- type GLProps =
693
- | Renderer
694
- | ((defaultProps: DefaultGLProps) => Renderer)
695
- | ((defaultProps: DefaultGLProps) => Promise<Renderer>)
696
- | (Partial<Properties<THREE$1.WebGLRenderer> | THREE$1.WebGLRendererParameters> & ColorManagementConfig)
697
-
698
- //* WebGPU Renderer Props ==============================
699
-
700
- type DefaultRendererProps = {
701
- canvas: HTMLCanvasElement | OffscreenCanvas$1
702
- [key: string]: any
703
- }
704
-
705
- /**
706
- * Canvas-level scheduler configuration.
707
- * Controls render timing relative to other canvases.
708
- */
709
- interface CanvasSchedulerConfig {
710
- /**
711
- * Render this canvas after another canvas completes.
712
- * Pass the `id` of another canvas.
713
- */
714
- after?: string
715
- /**
716
- * Limit this canvas's render rate (frames per second).
717
- */
718
- fps?: number
719
- }
720
-
721
- /**
722
- * Extended renderer configuration for multi-canvas support and color management.
723
- */
724
- interface RendererConfigExtended extends ColorManagementConfig {
725
- /** Share renderer from another canvas (WebGPU only) */
726
- primaryCanvas?: string
727
- /** Canvas-level scheduler options */
728
- scheduler?: CanvasSchedulerConfig
729
- }
730
-
731
- type RendererProps =
732
- | any // WebGPURenderer
733
- | ((defaultProps: DefaultRendererProps) => any)
734
- | ((defaultProps: DefaultRendererProps) => Promise<any>)
735
- | (Partial<Properties<any> | Record<string, any>> & RendererConfigExtended)
736
-
737
- //* Camera Props ==============================
738
-
739
- type CameraProps = (
740
- | THREE$1.Camera
741
- | Partial<
742
- ThreeElement<typeof THREE$1.Camera> &
743
- ThreeElement<typeof THREE$1.PerspectiveCamera> &
744
- ThreeElement<typeof THREE$1.OrthographicCamera>
745
- >
746
- ) & {
747
- /** Flags the camera as manual, putting projection into your own hands */
748
- manual?: boolean
749
- }
750
-
751
- //* Render Props ==============================
752
-
753
- interface RenderProps<TCanvas extends HTMLCanvasElement | OffscreenCanvas$1> {
754
- /**
755
- * Unique identifier for multi-canvas renderer sharing.
756
- * Makes this canvas targetable by other canvases using the `primaryCanvas` prop.
757
- * Also sets the HTML `id` attribute on the canvas element.
758
- * @example <Canvas id="main-viewer">...</Canvas>
759
- */
760
- id?: string
761
- /**
762
- * Share the renderer from another canvas instead of creating a new one.
763
- * Pass the `id` of the primary canvas to share its WebGPURenderer.
764
- * Only available with WebGPU (not legacy WebGL).
765
- *
766
- * Note: This is extracted from `renderer={{ primaryCanvas: "id" }}` by Canvas.
767
- * @internal
768
- */
769
- primaryCanvas?: string
770
- /**
771
- * Canvas-level scheduler options. Controls render timing relative to other canvases.
772
- *
773
- * Note: This is extracted from `renderer={{ scheduler: {...} }}` by Canvas.
774
- * @internal
775
- */
776
- scheduler?: CanvasSchedulerConfig
777
- /** A threejs renderer instance or props that go into the default renderer */
778
- gl?: GLProps
779
- /** A WebGPU renderer instance or props that go into the default renderer */
780
- renderer?: RendererProps
781
- /** Dimensions to fit the renderer to. Will measure canvas dimensions if omitted */
782
- size?: Size
783
- /**
784
- * Enables shadows (by default PCFsoft). Can accept `gl.shadowMap` options for fine-tuning,
785
- * but also strings: 'basic' | 'percentage' | 'soft' | 'variance'.
786
- * @see https://threejs.org/docs/#api/en/renderers/WebGLRenderer.shadowMap
787
- */
788
- shadows?: boolean | 'basic' | 'percentage' | 'soft' | 'variance' | Partial<THREE$1.WebGLShadowMap>
789
- /** Creates an orthographic camera */
790
- orthographic?: boolean
791
- /**
792
- * R3F's render mode. Set to `demand` to only render on state change or `never` to take control.
793
- * @see https://docs.pmnd.rs/react-three-fiber/advanced/scaling-performance#on-demand-rendering
794
- */
795
- frameloop?: Frameloop
796
- /**
797
- * R3F performance options for adaptive performance.
798
- * @see https://docs.pmnd.rs/react-three-fiber/advanced/scaling-performance#movement-regression
799
- */
800
- performance?: Partial<Omit<Performance, 'regress'>>
801
- /** Target pixel ratio. Can clamp between a range: `[min, max]` */
802
- dpr?: Dpr
803
- /** Props that go into the default raycaster */
804
- raycaster?: Partial<THREE$1.Raycaster>
805
- /** A `THREE.Scene` instance or props that go into the default scene */
806
- scene?: THREE$1.Scene | Partial<THREE$1.Scene>
807
- /** A `THREE.Camera` instance or props that go into the default camera */
808
- camera?: CameraProps
809
- /** An R3F event manager to manage elements' pointer events */
810
- events?: (store: RootStore) => EventManager<HTMLElement>
811
- /** Callback after the canvas has rendered (but not yet committed) */
812
- onCreated?: (state: RootState) => void
813
- /** Response for pointer clicks that have missed any target */
814
- onPointerMissed?: (event: MouseEvent) => void
815
- /** Response for dragover events that have missed any target */
816
- onDragOverMissed?: (event: DragEvent) => void
817
- /** Response for drop events that have missed any target */
818
- onDropMissed?: (event: DragEvent) => void
819
- /** Whether to automatically update the frustum each frame (default: true) */
820
- autoUpdateFrustum?: boolean
821
- /**
822
- * Enable WebGPU occlusion queries for onOccluded/onVisible events.
823
- * Auto-enabled when any object uses onOccluded or onVisible handlers.
824
- * Only works with WebGPU renderer - WebGL will log a warning.
825
- */
826
- occlusion?: boolean
827
- /** Internal: stored size props from Canvas for reset functionality */
828
- _sizeProps?: { width?: number; height?: number } | null
829
- /** Force canvas dimensions to even numbers (fixes Safari rendering issues with odd/fractional sizes) */
830
- forceEven?: boolean
831
- }
832
-
833
- //* Reconciler Root ==============================
834
-
835
- interface ReconcilerRoot<TCanvas extends HTMLCanvasElement | OffscreenCanvas$1> {
836
- configure: (config?: RenderProps<TCanvas>) => Promise<ReconcilerRoot<TCanvas>>
837
- render: (element: ReactNode) => RootStore
838
- unmount: () => void
839
- }
840
-
841
- //* Inject State ==============================
842
-
843
- type InjectState = Partial<
844
- Omit<RootState, 'events'> & {
845
- events?: {
846
- enabled?: boolean
847
- priority?: number
848
- compute?: ComputeFunction
849
- connected?: any
850
- }
851
- /**
852
- * When true (default), injects a THREE.Scene between container and children if container isn't already a Scene.
853
- * This ensures state.scene is always a real THREE.Scene with proper properties (background, environment, fog).
854
- * Set to false to use the container directly as scene (anti-pattern, but supported for edge cases).
855
- */
856
- injectScene?: boolean
857
- }
858
- >
859
-
860
- //* Reconciler Types ==============================
861
-
862
- // FiberRoot is an opaque internal React type - we define it locally
863
- // to avoid bundling @types/react-reconciler which causes absolute path issues
864
- type FiberRoot = any
865
-
866
- interface Root {
867
- fiber: FiberRoot
868
- store: RootStore
869
- }
870
-
871
- type AttachFnType<O = any> = (parent: any, self: O) => () => void
872
- type AttachType<O = any> = string | AttachFnType<O>
873
-
874
- type ConstructorRepresentation<T = any> = new (...args: any[]) => T
875
-
876
- interface Catalogue {
877
- [name: string]: ConstructorRepresentation
878
- }
879
-
880
- // TODO: handle constructor overloads
881
- // https://github.com/pmndrs/react-three-fiber/pull/2931
882
- // https://github.com/microsoft/TypeScript/issues/37079
883
- type Args<T> = T extends ConstructorRepresentation
884
- ? T extends typeof Color$1
885
- ? [r: number, g: number, b: number] | [color: ColorRepresentation]
886
- : ConstructorParameters<T>
887
- : any[]
888
-
889
- type ArgsProp<P> = P extends ConstructorRepresentation
890
- ? IsAllOptional<ConstructorParameters<P>> extends true
891
- ? { args?: Args<P> }
892
- : { args: Args<P> }
893
- : { args: unknown[] }
894
-
895
- type InstanceProps<T = any, P = any> = ArgsProp<P> & {
896
- object?: T
897
- dispose?: null
898
- attach?: AttachType<T>
899
- onUpdate?: (self: T) => void
900
- }
901
-
902
- interface Instance<O = any> {
903
- root: RootStore
904
- type: string
905
- parent: Instance | null
906
- children: Instance[]
907
- props: InstanceProps<O> & Record<string, unknown>
908
- object: O & { __r3f?: Instance<O> }
909
- eventCount: number
910
- handlers: Partial<EventHandlers>
911
- attach?: AttachType<O>
912
- previousAttach?: any
913
- isHidden: boolean
914
- /** Set of props that have been applied via once() */
915
- appliedOnce?: Set<string>
916
- }
917
-
918
- interface HostConfig {
919
- type: string
920
- props: Instance['props']
921
- container: RootStore
922
- instance: Instance
923
- textInstance: void
924
- suspenseInstance: Instance
925
- hydratableInstance: never
926
- formInstance: never
927
- publicInstance: Instance['object']
928
- hostContext: {}
929
- childSet: never
930
- timeoutHandle: number | undefined
931
- noTimeout: -1
932
- TransitionStatus: null
933
- }
934
- declare global {
935
- var IS_REACT_ACT_ENVIRONMENT: boolean | undefined
936
- }
937
-
938
- //* Loop Types ==============================
939
-
940
- type GlobalRenderCallback = (timestamp: number) => void
941
-
942
- type GlobalEffectType = 'before' | 'after' | 'tail'
943
-
944
- declare const presetsObj: {
945
- apartment: string;
946
- city: string;
947
- dawn: string;
948
- forest: string;
949
- lobby: string;
950
- night: string;
951
- park: string;
952
- studio: string;
953
- sunset: string;
954
- warehouse: string;
955
- };
956
- type PresetsType = keyof typeof presetsObj;
957
-
958
- //* Background Types ==============================
959
-
960
- /**
961
- * Expanded object form for background configuration.
962
- * Allows separate textures for background (visual backdrop) and environment (PBR lighting).
963
- */
964
- interface BackgroundConfig {
965
- /** HDRI preset name: 'apartment', 'city', 'dawn', 'forest', 'lobby', 'night', 'park', 'studio', 'sunset', 'warehouse' */
966
- preset?: PresetsType
967
- /** Files for cube texture (6 faces) or single HDR/EXR */
968
- files?: string | string[]
969
- /** Separate files for scene.background (visual backdrop) */
970
- backgroundMap?: string | string[]
971
- backgroundRotation?: Euler$1 | [number, number, number]
972
- backgroundBlurriness?: number
973
- backgroundIntensity?: number
974
- /** Separate files for scene.environment (PBR lighting/reflections) */
975
- envMap?: string | string[]
976
- environmentRotation?: Euler$1 | [number, number, number]
977
- environmentIntensity?: number
978
- path?: string
979
- extensions?: (loader: Loader) => void
980
- }
981
-
982
- /**
983
- * Background prop type for Canvas.
984
- *
985
- * String detection priority:
986
- * 1. Preset - exact match against known presets (apartment, city, dawn, forest, lobby, night, park, studio, sunset, warehouse)
987
- * 2. URL - starts with /, ./, ../, http://, https://, OR has image extension
988
- * 3. Color - default fallback (CSS color names, hex values, rgb(), etc.)
989
- *
990
- * @example Color
991
- * ```tsx
992
- * <Canvas background="red" />
993
- * <Canvas background="#ff0000" />
994
- * <Canvas background={0xff0000} />
995
- * ```
996
- *
997
- * @example Preset
998
- * ```tsx
999
- * <Canvas background="city" />
1000
- * ```
1001
- *
1002
- * @example URL
1003
- * ```tsx
1004
- * <Canvas background="/path/to/env.hdr" />
1005
- * <Canvas background="./sky.jpg" />
1006
- * ```
1007
- *
1008
- * @example Object form
1009
- * ```tsx
1010
- * <Canvas background={{
1011
- * files: ['px.png', 'nx.png', 'py.png', 'ny.png', 'pz.png', 'nz.png'],
1012
- * backgroundMap: 'path/to/sky.jpg',
1013
- * envMap: 'path/to/lighting.hdr',
1014
- * backgroundBlurriness: 0.5,
1015
- * }} />
1016
- * ```
1017
- */
1018
- type BackgroundProp =
1019
- | ColorRepresentation // "red", "#ff0000", 0xff0000
1020
- | string // URL or preset
1021
- | BackgroundConfig // Expanded object form
1022
-
1023
- //* Canvas Types ==============================
1024
-
1025
- interface CanvasProps
1026
- extends
1027
- Omit<RenderProps<HTMLCanvasElement>, 'size' | 'primaryCanvas' | 'scheduler'>,
1028
- React$1.HTMLAttributes<HTMLDivElement> {
1029
- children?: React$1.ReactNode
1030
- ref?: React$1.Ref<HTMLCanvasElement>
1031
- /** Canvas fallback content, similar to img's alt prop */
1032
- fallback?: React$1.ReactNode
1033
- /**
1034
- * Options to pass to useMeasure.
1035
- * @see https://github.com/pmndrs/react-use-measure#api
1036
- */
1037
- resize?: Options
1038
- /** The target where events are being subscribed to, default: the div that wraps canvas */
1039
- eventSource?: HTMLElement | React$1.RefObject<HTMLElement | null>
1040
- /** The event prefix that is cast into canvas pointer x/y events, default: "offset" */
1041
- eventPrefix?: 'offset' | 'client' | 'page' | 'layer' | 'screen'
1042
- /** Enable/disable automatic HMR refresh for TSL nodes and uniforms, default: true in dev */
1043
- hmr?: boolean
1044
- /** Canvas resolution width in pixels. If omitted, uses container width. */
1045
- width?: number
1046
- /** Canvas resolution height in pixels. If omitted, uses container height. */
1047
- height?: number
1048
- /** Force canvas dimensions to even numbers (fixes Safari rendering issues with odd/fractional sizes) */
1049
- forceEven?: boolean
1050
- /**
1051
- * Scene background configuration.
1052
- * Accepts colors, URLs, presets, or an expanded object for separate background/environment.
1053
- * @see BackgroundProp for full documentation and examples
1054
- */
1055
- background?: BackgroundProp
1056
- }
1057
-
1058
- //* Loader Types ==============================
1059
-
1060
- type InputLike = string | string[] | string[][] | Readonly<string | string[] | string[][]>
1061
-
1062
- // Define a loader-like interface that matches THREE.Loader's load signature
1063
- // This works for both generic and non-generic THREE.Loader instances
1064
- interface LoaderLike {
1065
- load(
1066
- url: InputLike,
1067
- onLoad?: (result: any) => void,
1068
- onProgress?: (event: ProgressEvent<EventTarget>) => void,
1069
- onError?: (error: unknown) => void,
1070
- ): any
1071
- }
1072
-
1073
- type GLTFLike = { scene: THREE$1.Object3D }
1074
-
1075
- type LoaderInstance<T extends LoaderLike | ConstructorRepresentation<LoaderLike>> =
1076
- T extends ConstructorRepresentation<LoaderLike> ? InstanceType<T> : T
1077
-
1078
- // Infer result type from the load method's callback parameter
1079
- type InferLoadResult<T> = T extends {
1080
- load(url: any, onLoad?: (result: infer R) => void, ...args: any[]): any
1081
- }
1082
- ? R
1083
- : T extends ConstructorRepresentation<any>
1084
- ? InstanceType<T> extends {
1085
- load(url: any, onLoad?: (result: infer R) => void, ...args: any[]): any
1086
- }
1087
- ? R
1088
- : any
1089
- : any
1090
-
1091
- type LoaderResult<T extends LoaderLike | ConstructorRepresentation<LoaderLike>> =
1092
- InferLoadResult<LoaderInstance<T>> extends infer R ? (R extends GLTFLike ? R & ObjectMap : R) : never
1093
-
1094
- type Extensions<T extends LoaderLike | ConstructorRepresentation<LoaderLike>> = (
1095
- loader: LoaderInstance<T>,
1096
- ) => void
1097
-
1098
- //* Renderer Props ========================================
1099
-
1100
- type WebGLDefaultProps = Omit<THREE$1.WebGLRendererParameters, 'canvas'> & BaseRendererProps
1101
-
1102
- type WebGLProps =
1103
- | RendererFactory<THREE$1.WebGLRenderer, WebGLDefaultProps>
1104
- | Partial<Properties<THREE$1.WebGLRenderer> | THREE$1.WebGLRendererParameters>
1105
-
1106
- interface WebGLShadowConfig {
1107
- shadows?: boolean | 'basic' | 'percentage' | 'soft' | 'variance' | Partial<THREE$1.WebGLShadowMap>
1108
- }
1109
-
1110
- //* Legacy-specific Types ========================================
1111
-
1112
- /** Legacy (WebGL) renderer type - re-exported as R3FRenderer from @react-three/fiber/legacy */
1113
- type LegacyRenderer = THREE$1.WebGLRenderer
1114
-
1115
- /** Legacy internal state with narrowed renderer type */
1116
- interface LegacyInternalState extends Omit<InternalState, 'actualRenderer'> {
1117
- actualRenderer: THREE$1.WebGLRenderer
1118
- }
1119
-
1120
- /**
1121
- * Legacy-specific RootState with narrowed renderer type.
1122
- * Automatically used when importing from `@react-three/fiber/legacy`.
1123
- *
1124
- * @example
1125
- * ```tsx
1126
- * import { useThree } from '@react-three/fiber/legacy'
1127
- *
1128
- * function MyComponent() {
1129
- * const { renderer } = useThree()
1130
- * // renderer is typed as THREE.WebGLRenderer
1131
- * renderer.shadowMap.enabled = true
1132
- * }
1133
- * ```
1134
- */
1135
- interface LegacyRootState extends Omit<RootState, 'renderer' | 'internal'> {
1136
- /** The WebGL renderer instance */
1137
- renderer: THREE$1.WebGLRenderer
1138
- /** Internals with WebGL renderer */
1139
- internal: LegacyInternalState
1140
- }
1141
-
1142
- //* RenderTarget Types ==============================
1143
-
1144
-
1145
- type RenderTargetOptions = RenderTargetOptions$1
1146
-
1147
- //* Global Types ==============================
1148
-
1149
- declare global {
1150
- /**
1151
- * Uniform node type.
1152
- *
1153
- * This is three's own `UniformNode`, not a re-declaration of it. It previously was a
1154
- * hand-rolled `interface UniformNode<T> extends Node { value: T }`, which shadowed the real
1155
- * exported type globally — so R3F's ~58 references resolved to an approximation that was
1156
- * missing members three actually ships (`setName` among them) and had drifted to the wrong
1157
- * arity when three made `UniformNode` two-parameter.
1158
- *
1159
- * three's signature is `UniformNode<TNodeType, TValue>`. R3F only ever varies the value type,
1160
- * so the node type is fixed to `unknown` and the single parameter is kept for call-site
1161
- * ergonomics. The result is three's structural type, so members stay in sync with the
1162
- * installed three instead of needing to be mirrored by hand.
1163
- */
1164
- type UniformNode<T = unknown> = three_webgpu.UniformNode<unknown, T>
1165
-
1166
- /**
1167
- * ShaderCallable - the return type of Fn()
1168
- * A callable shader function node that can be invoked with parameters.
1169
- * The function returns a ShaderNodeObject when called.
1170
- *
1171
- * @example
1172
- * ```tsx
1173
- * // Define a shader function
1174
- * const blendColorFn = Fn(([color1, color2, factor]) => {
1175
- * return mix(color1, color2, factor)
1176
- * })
1177
- *
1178
- * // Type when retrieving from nodes store
1179
- * const { blendColorFn } = nodes as { blendColorFn: ShaderCallable }
1180
- *
1181
- * // Or with specific return type
1182
- * const { myFn } = nodes as { myFn: ShaderCallable<THREE.Node> }
1183
- * ```
1184
- */
1185
- type ShaderCallable<R extends Node = Node> = ((...params: unknown[]) => ShaderNodeObject<R>) & Node
1186
-
1187
- /**
1188
- * ShaderNodeRef - a ShaderNodeObject wrapper around a Node
1189
- * This is the common return type for TSL operations (add, mul, sin, etc.)
1190
- *
1191
- * @example
1192
- * ```tsx
1193
- * const { wobble } = nodes as { wobble: ShaderNodeRef }
1194
- * ```
1195
- */
1196
- type ShaderNodeRef<T extends Node = Node> = ShaderNodeObject<T>
1197
-
1198
- /**
1199
- * TSLNodeType - Union of all common TSL node types
1200
- * Used by ScopedStore to properly type node access from the store.
1201
- *
1202
- * Includes:
1203
- * - Node: base Three.js node type
1204
- * - ShaderCallable: function nodes created with Fn()
1205
- * - ShaderNodeObject: wrapped nodes from TSL operations (sin, mul, mix, etc.)
1206
- *
1207
- * @example
1208
- * ```tsx
1209
- * // In useLocalNodes, nodes are typed as TSLNodeType
1210
- * const { positionNode, blendColorFn } = useLocalNodes(({ nodes }) => ({
1211
- * positionNode: nodes.myPosition, // Works - Node is in union
1212
- * blendColorFn: nodes.myFn, // Works - ShaderCallable is in union
1213
- * }))
1214
- *
1215
- * // Can narrow with type guard or assertion when needed
1216
- * if (typeof blendColorFn === 'function') {
1217
- * blendColorFn(someColor, 0.5)
1218
- * }
1219
- * ```
1220
- */
1221
- type TSLNodeType = Node | ShaderCallable<Node> | ShaderNodeObject<Node>
1222
-
1223
- /** Flat record of uniform nodes (no nested scopes) */
1224
- type UniformRecord<T extends UniformNode = UniformNode> = Record<string, T>
1225
-
1226
- /**
1227
- * Uniform store that can contain both root-level uniforms and scoped uniform objects
1228
- * Used by state.uniforms which has structure like:
1229
- * { uTime: UniformNode, player: { uHealth: UniformNode }, enemy: { uHealth: UniformNode } }
1230
- */
1231
- type UniformStore = Record<string, UniformNode | UniformRecord>
1232
-
1233
- /**
1234
- * Helper to safely access a uniform node from the store.
1235
- * Use this when accessing state.uniforms to get proper typing.
1236
- * @example
1237
- * const uTime = uniforms.uTime as UniformNode<number>
1238
- * const uColor = uniforms.uColor as UniformNode<import('three/webgpu').Color>
1239
- */
1240
- type GetUniform<T = unknown> = UniformNode<T>
1241
-
1242
- /**
1243
- * Acceptable input values for useUniforms - raw values that get converted to UniformNodes
1244
- * Supports:
1245
- * - Primitives: number, string (color), boolean
1246
- * - Three.js types: Color, Vector2/3/4, Matrix3/4, Euler, Quaternion
1247
- * - Plain objects: { x, y, z, w } converted to vectors
1248
- * - TSL nodes: color(), vec3(), float() for type casting
1249
- * - UniformNode: existing uniforms (reused as-is)
1250
- */
1251
- type UniformValue =
1252
- | number
1253
- | string
1254
- | boolean
1255
- | three_webgpu.Color
1256
- | three_webgpu.Vector2
1257
- | three_webgpu.Vector3
1258
- | three_webgpu.Vector4
1259
- | three_webgpu.Matrix3
1260
- | three_webgpu.Matrix4
1261
- | three_webgpu.Euler
1262
- | three_webgpu.Quaternion
1263
- | { x: number; y?: number; z?: number; w?: number } // Plain objects converted to vectors
1264
- | { r: number; g: number; b: number; a?: number } // Plain objects converted to Color
1265
- | Node // TSL nodes like color(), vec3(), float() for type casting
1266
- | UniformNode
1267
-
1268
- /** Input record for useUniforms - accepts raw values or UniformNodes */
1269
- type UniformInputRecord = Record<string, UniformValue>
1270
- }
1271
-
1272
- //* Module Augmentation ==============================
1273
-
1274
- declare module 'three/tsl' {
1275
- /**
1276
- * Fn with array parameter destructuring
1277
- * @example Fn(([uv, skew]) => { ... })
1278
- */
1279
- export function Fn<R extends Node = Node>(
1280
- jsFunc: (inputs: ShaderNodeObject<Node>[]) => ShaderNodeObject<R>,
1281
- ): ShaderCallable<R>
1282
-
1283
- /**
1284
- * Fn with object parameter destructuring
1285
- * @example Fn(({ color, intensity }) => { ... })
1286
- */
1287
- export function Fn<T extends Record<string, unknown>, R extends Node = Node>(
1288
- jsFunc: (inputs: T) => ShaderNodeObject<R>,
1289
- ): ShaderCallable<R>
1290
-
1291
- /**
1292
- * Fn with array params + layout
1293
- * @example Fn(([a, b]) => { ... }, { layout: [...] })
1294
- */
1295
- export function Fn<R extends Node = Node>(
1296
- jsFunc: (inputs: ShaderNodeObject<Node>[]) => ShaderNodeObject<R>,
1297
- layout: { layout?: unknown },
1298
- ): ShaderCallable<R>
1299
-
1300
- /**
1301
- * Fn with object params + layout
1302
- */
1303
- export function Fn<T extends Record<string, unknown>, R extends Node = Node>(
1304
- jsFunc: (inputs: T) => ShaderNodeObject<R>,
1305
- layout: { layout?: unknown },
1306
- ): ShaderCallable<R>
1307
- }
1308
-
1309
- declare global {
1310
- /**
1311
- * three's own render pipeline type. Named here so the rest of R3F refers to three's shape
1312
- * rather than `any`. three r183 renamed `PostProcessing` to `RenderPipeline`; our peer floor
1313
- * is r185, so the new name is the only one.
1314
- */
1315
- type ThreeRenderPipeline = three_webgpu.RenderPipeline
1316
-
1317
- /** Pass record - stores TSL pass nodes for render pipeline */
1318
- type PassRecord = Record<string, any>
1319
-
1320
- /** Setup callback - runs first to configure MRT, create additional passes */
1321
- type RenderPipelineSetupCallback = (state: RootState) => PassRecord | void
1322
-
1323
- /** Main callback - runs second to configure outputNode, create effect passes */
1324
- type RenderPipelineMainCallback = (state: RootState) => PassRecord | void
1325
-
1326
- /** Return type for useRenderPipeline hook */
1327
- interface UseRenderPipelineReturn {
1328
- /** Current passes from state */
1329
- passes: PassRecord
1330
- /** RenderPipeline instance (null if not initialized) */
1331
- renderPipeline: ThreeRenderPipeline | null
1332
- /** Clear all passes from state */
1333
- clearPasses: () => void
1334
- /** Reset RenderPipeline entirely (clears PP + passes) */
1335
- reset: () => void
1336
- /** Re-run setup/main callbacks with current closure values */
1337
- rebuild: () => void
1338
- /** True when RenderPipeline is configured and ready */
1339
- isReady: boolean
1340
- }
1341
- }
1342
-
1343
- type MutableOrReadonlyParameters<T extends (...args: any) => any> = Parameters<T> | Readonly<Parameters<T>>
1344
-
1345
- interface MathRepresentation {
1346
- set(...args: number[]): any
1347
- }
1348
- interface VectorRepresentation extends MathRepresentation {
1349
- setScalar(value: number): any
1350
- }
1351
- type MathTypes = MathRepresentation | Euler$2 | Color$2
1352
-
1353
- type MathType<T extends MathTypes> = T extends Color$2
1354
- ? Args<typeof Color$2> | ColorRepresentation$1
1355
- : T extends VectorRepresentation | Layers$1 | Euler$2
1356
- ? T | MutableOrReadonlyParameters<T['set']> | number
1357
- : T | MutableOrReadonlyParameters<T['set']>
1358
-
1359
- type MathProps<P> = {
1360
- [K in keyof P as P[K] extends MathTypes ? K : never]: P[K] extends MathTypes ? MathType<P[K]> : never
1361
- }
1362
-
1363
- type Vector2 = MathType<Vector2$1>
1364
- type Vector3 = MathType<Vector3$1>
1365
- type Vector4 = MathType<Vector4$1>
1366
- type Color = MathType<Color$2>
1367
- type Layers = MathType<Layers$1>
1368
- type Quaternion = MathType<Quaternion$1>
1369
- type Euler = MathType<Euler$2>
1370
- type Matrix3 = MathType<Matrix3$1>
1371
- type Matrix4 = MathType<Matrix4$1>
1372
-
1373
- interface RaycastableRepresentation {
1374
- raycast(raycaster: Raycaster, intersects: Intersection$1[]): void
1375
- }
1376
- type EventProps<P> = P extends RaycastableRepresentation ? Partial<EventHandlers> : {}
1377
-
1378
- /**
1379
- * Props for geometry transform methods that can be called with `once()`.
1380
- * These methods modify the geometry in-place and only make sense to call once on mount.
1381
- *
1382
- * @example
1383
- * import { once } from '@react-three/fiber'
1384
- *
1385
- * <boxGeometry args={[1, 1, 1]} rotateX={once(Math.PI / 2)} />
1386
- * <planeGeometry args={[10, 10]} translate={once(0, 0, 5)} />
1387
- * <bufferGeometry applyMatrix4={once(matrix)} center={once()} />
1388
- */
1389
- interface GeometryTransformProps {
1390
- /** Rotate the geometry about the X axis (radians). Use with once(). */
1391
- rotateX?: number
1392
- /** Rotate the geometry about the Y axis (radians). Use with once(). */
1393
- rotateY?: number
1394
- /** Rotate the geometry about the Z axis (radians). Use with once(). */
1395
- rotateZ?: number
1396
- /** Translate the geometry (x, y, z). Use with once(). */
1397
- translate?: [x: number, y: number, z: number]
1398
- /** Scale the geometry (x, y, z). Use with once(). */
1399
- scale?: [x: number, y: number, z: number]
1400
- /** Center the geometry based on bounding box. Use with once(). */
1401
- center?: true
1402
- /** Apply a Matrix4 transformation. Use with once(). */
1403
- applyMatrix4?: Matrix4$1
1404
- /** Apply a Quaternion rotation. Use with once(). */
1405
- applyQuaternion?: Quaternion$1
1406
- }
1407
-
1408
- type GeometryProps<P> = P extends BufferGeometry ? GeometryTransformProps : {}
1409
-
1410
- /**
1411
- * Workaround for @types/three TSL node type issues.
1412
- * The Node base class has properties that subclasses (OperatorNode, ConstNode, etc.) don't inherit.
1413
- * This transforms `Node | null` properties to accept any object with node-like shape.
1414
- */
1415
- type TSLNodeInput = { nodeType?: string | null; uuid?: string } | null
1416
-
1417
- /**
1418
- * For node material properties (colorNode, positionNode, etc.), accept broader types
1419
- * since @types/three has broken inheritance for TSL node subclasses.
1420
- */
1421
- type NodeProps<P> = {
1422
- [K in keyof P as P[K] extends Node | null ? K : never]?: TSLNodeInput
1423
- }
1424
-
1425
- interface ReactProps<P> {
1426
- children?: React.ReactNode
1427
- ref?: React.Ref<P>
1428
- key?: React.Key
1429
- }
1430
-
1431
- type ElementProps<T extends ConstructorRepresentation, P = InstanceType<T>> = Partial<
1432
- Overwrite<P, MathProps<P> & ReactProps<P> & EventProps<P> & GeometryProps<P> & NodeProps<P>>
1433
- >
1434
-
1435
- type ThreeElement<T extends ConstructorRepresentation> = Mutable<
1436
- Overwrite<ElementProps<T>, Omit<InstanceProps<InstanceType<T>, T>, 'object'>>
1437
- >
1438
-
1439
- type ThreeToJSXElements<T extends Record<string, any>> = {
1440
- [K in keyof T & string as Uncapitalize<K>]: T[K] extends ConstructorRepresentation ? ThreeElement<T[K]> : never
1441
- }
1442
-
1443
- type ThreeExports = typeof import('three/webgpu')
1444
- type ThreeElementsImpl = ThreeToJSXElements<ThreeExports>
1445
-
1446
- interface ThreeElements extends Omit<ThreeElementsImpl, 'audio' | 'source' | 'line' | 'path'> {
1447
- primitive: Omit<ThreeElement<any>, 'args'> & { object: object }
1448
- // Conflicts with DOM types can be accessed through a three* prefix
1449
- threeAudio: ThreeElementsImpl['audio']
1450
- threeSource: ThreeElementsImpl['source']
1451
- threeLine: ThreeElementsImpl['line']
1452
- threePath: ThreeElementsImpl['path']
1453
- }
1454
-
1455
- declare module 'react' {
1456
- namespace JSX {
1457
- interface IntrinsicElements extends ThreeElements {}
1458
- }
1459
- }
1460
-
1461
- declare module 'react/jsx-runtime' {
1462
- namespace JSX {
1463
- interface IntrinsicElements extends ThreeElements {}
1464
- }
1465
- }
1466
-
1467
- declare module 'react/jsx-dev-runtime' {
1468
- namespace JSX {
1469
- interface IntrinsicElements extends ThreeElements {}
1470
- }
1471
- }
1472
-
1473
- type three_d_Color = Color;
1474
- type three_d_ElementProps<T extends ConstructorRepresentation, P = InstanceType<T>> = ElementProps<T, P>;
1475
- type three_d_Euler = Euler;
1476
- type three_d_EventProps<P> = EventProps<P>;
1477
- type three_d_GeometryProps<P> = GeometryProps<P>;
1478
- type three_d_GeometryTransformProps = GeometryTransformProps;
1479
- type three_d_Layers = Layers;
1480
- type three_d_MathProps<P> = MathProps<P>;
1481
- type three_d_MathRepresentation = MathRepresentation;
1482
- type three_d_MathType<T extends MathTypes> = MathType<T>;
1483
- type three_d_MathTypes = MathTypes;
1484
- type three_d_Matrix3 = Matrix3;
1485
- type three_d_Matrix4 = Matrix4;
1486
- type three_d_MutableOrReadonlyParameters<T extends (...args: any) => any> = MutableOrReadonlyParameters<T>;
1487
- type three_d_NodeProps<P> = NodeProps<P>;
1488
- type three_d_Quaternion = Quaternion;
1489
- type three_d_RaycastableRepresentation = RaycastableRepresentation;
1490
- type three_d_ReactProps<P> = ReactProps<P>;
1491
- type three_d_TSLNodeInput = TSLNodeInput;
1492
- type three_d_ThreeElement<T extends ConstructorRepresentation> = ThreeElement<T>;
1493
- type three_d_ThreeElements = ThreeElements;
1494
- type three_d_ThreeElementsImpl = ThreeElementsImpl;
1495
- type three_d_ThreeExports = ThreeExports;
1496
- type three_d_ThreeToJSXElements<T extends Record<string, any>> = ThreeToJSXElements<T>;
1497
- type three_d_Vector2 = Vector2;
1498
- type three_d_Vector3 = Vector3;
1499
- type three_d_Vector4 = Vector4;
1500
- type three_d_VectorRepresentation = VectorRepresentation;
1501
- declare namespace three_d {
1502
- export type { three_d_Color as Color, three_d_ElementProps as ElementProps, three_d_Euler as Euler, three_d_EventProps as EventProps, three_d_GeometryProps as GeometryProps, three_d_GeometryTransformProps as GeometryTransformProps, three_d_Layers as Layers, three_d_MathProps as MathProps, three_d_MathRepresentation as MathRepresentation, three_d_MathType as MathType, three_d_MathTypes as MathTypes, three_d_Matrix3 as Matrix3, three_d_Matrix4 as Matrix4, three_d_MutableOrReadonlyParameters as MutableOrReadonlyParameters, three_d_NodeProps as NodeProps, three_d_Quaternion as Quaternion, three_d_RaycastableRepresentation as RaycastableRepresentation, three_d_ReactProps as ReactProps, three_d_TSLNodeInput as TSLNodeInput, three_d_ThreeElement as ThreeElement, three_d_ThreeElements as ThreeElements, three_d_ThreeElementsImpl as ThreeElementsImpl, three_d_ThreeExports as ThreeExports, three_d_ThreeToJSXElements as ThreeToJSXElements, three_d_Vector2 as Vector2, three_d_Vector3 as Vector3, three_d_Vector4 as Vector4, three_d_VectorRepresentation as VectorRepresentation };
1503
- }
1504
-
1505
- /**
1506
- * @fileoverview Registry for primary canvases that can be targeted by secondary canvases
1507
- *
1508
- * Enables multi-canvas WebGPU rendering where multiple Canvas components share
1509
- * a single WebGPURenderer using Three.js CanvasTarget API.
1510
- *
1511
- * Primary canvas: Has `id` prop, creates its own renderer, registers here
1512
- * Secondary canvas: Has `renderer={{ primaryCanvas: 'id' }}`, shares primary's renderer via CanvasTarget
1513
- */
1514
-
1515
- interface PrimaryCanvasEntry {
1516
- /** The WebGPURenderer instance owned by this primary canvas */
1517
- renderer: WebGPURenderer;
1518
- /** The zustand store for this canvas */
1519
- store: RootStore;
1520
- }
1521
- /**
1522
- * Register a primary canvas that can be targeted by secondary canvases.
1523
- *
1524
- * @param id - Unique identifier for this primary canvas
1525
- * @param renderer - The WebGPURenderer owned by this canvas
1526
- * @param store - The zustand store for this canvas
1527
- * @returns Cleanup function to unregister on unmount
1528
- */
1529
- declare function registerPrimary(id: string, renderer: WebGPURenderer, store: RootStore): () => void;
1530
- /**
1531
- * Get a registered primary canvas by id.
1532
- *
1533
- * @param id - The id of the primary canvas to look up
1534
- * @returns The primary canvas entry or undefined if not found
1535
- */
1536
- declare function getPrimary(id: string): PrimaryCanvasEntry | undefined;
1537
- /**
1538
- * Wait for a primary canvas to be registered.
1539
- * Returns immediately if already registered, otherwise waits.
1540
- *
1541
- * @param id - The id of the primary canvas to wait for
1542
- * @param timeout - Optional timeout in ms (default: 5000)
1543
- * @returns Promise that resolves with the primary canvas entry
1544
- */
1545
- declare function waitForPrimary(id: string, timeout?: number): Promise<PrimaryCanvasEntry>;
1546
- /**
1547
- * Check if a primary canvas with the given id exists.
1548
- *
1549
- * @param id - The id to check
1550
- * @returns True if a primary canvas with this id is registered
1551
- */
1552
- declare function hasPrimary(id: string): boolean;
1553
- /**
1554
- * Unregister a primary canvas. Called on unmount.
1555
- *
1556
- * @param id - The id of the primary canvas to unregister
1557
- */
1558
- declare function unregisterPrimary(id: string): void;
1559
- /**
1560
- * Get all registered primary canvas ids. Useful for debugging.
1561
- */
1562
- declare function getPrimaryIds(): string[];
1563
-
1564
- type EnvironmentLoaderProps = {
1565
- files?: string | string[];
1566
- path?: string;
1567
- preset?: PresetsType;
1568
- extensions?: (loader: Loader$1) => void;
1569
- colorSpace?: ColorSpace;
1570
- };
1571
- /**
1572
- * Loads environment textures for reflections and lighting.
1573
- * Supports HDR files, presets, and cubemaps.
1574
- *
1575
- * @example Basic usage
1576
- * ```jsx
1577
- * const texture = useEnvironment({ preset: 'sunset' })
1578
- * ```
1579
- */
1580
- declare function useEnvironment({ files, path, preset, colorSpace, extensions, }?: Partial<EnvironmentLoaderProps>): Texture$1<unknown, THREE$1.TextureEventMap> | CubeTexture<unknown>;
1581
- declare namespace useEnvironment {
1582
- var preload: (preloadOptions?: EnvironmentLoaderPreloadOptions) => void;
1583
- var clear: (clearOptions?: EnvironmentLoaderClearOptions) => void;
1584
- }
1585
- /**
1586
- * Options accepted by `useEnvironment.preload`.
1587
- *
1588
- * `colorSpace` is deliberately omitted: preload only warms the loader cache, and colorSpace is
1589
- * applied to the texture by `useEnvironment()` at use time, per consumer. Accepting it here would
1590
- * advertise an option this function silently ignores.
1591
- *
1592
- * This previously read `Omit<…, 'encoding'>` — omitting a key that does not exist on
1593
- * `EnvironmentLoaderProps`, a leftover from three's pre-`colorSpace` `encoding` API. That made the
1594
- * type equivalent to the full props, so `colorSpace` was accepted and then dropped on the floor.
1595
- */
1596
- type EnvironmentLoaderPreloadOptions = Omit<EnvironmentLoaderProps, 'colorSpace'>;
1597
- type EnvironmentLoaderClearOptions = Pick<EnvironmentLoaderProps, 'files' | 'preset'>;
1598
-
1599
- /**
1600
- * Props for Environment component that sets up global cubemap for PBR materials and backgrounds.
1601
- *
1602
- * @property children - React children to render into custom environment portal
1603
- * @property frames - Number of frames to render the environment. Use 1 for static, Infinity for animated (default: 1)
1604
- * @property near - Near clipping plane for cube camera (default: 0.1)
1605
- * @property far - Far clipping plane for cube camera (default: 1000)
1606
- * @property resolution - Resolution of the cube render target (default: 256)
1607
- * @property background - Whether to set scene.background. Can be true, false, or "only" (which only sets background) (default: false)
1608
- *
1609
- * @property blur - @deprecated Use backgroundBlurriness instead
1610
- * @property backgroundBlurriness - Blur factor between 0 and 1 for background (default: 0, requires three.js 0.146+)
1611
- * @property backgroundIntensity - Intensity factor for background (default: 1, requires three.js 0.163+)
1612
- * @property backgroundRotation - Rotation for background as Euler angles (default: [0,0,0], requires three.js 0.163+)
1613
- * @property environmentIntensity - Intensity factor for environment lighting (default: 1, requires three.js 0.163+)
1614
- * @property environmentRotation - Rotation for environment as Euler angles (default: [0,0,0], requires three.js 0.163+)
1615
- *
1616
- * @property map - Pre-existing texture to use as environment map
1617
- * @property preset - HDRI Haven preset: 'apartment', 'city', 'dawn', 'forest', 'lobby', 'night', 'park', 'studio', 'sunset', 'warehouse'. Not for production use.
1618
- * @property scene - Custom THREE.Scene or ref to apply environment to (default: uses default scene)
1619
- * @property ground - Ground projection settings. Use true for defaults or object with:
1620
- * - height: Height of camera used to create env map (default: 15)
1621
- * - radius: Radius of the world (default: 60)
1622
- * - scale: Scale of backside projected sphere (default: 1000)
1623
- *
1624
- * Additional loader props:
1625
- * @property files - File path(s) for environment. Supports .hdr, .exr, gainmap .jpg/.webp, or array of 6 cube faces
1626
- * @property path - Base path for file loading
1627
- * @property extensions - Texture extensions override
1628
- */
1629
- type EnvironmentProps = {
1630
- children?: React$1.ReactNode;
1631
- frames?: number;
1632
- near?: number;
1633
- far?: number;
1634
- resolution?: number;
1635
- background?: boolean | 'only';
1636
- /** deprecated, use backgroundBlurriness */
1637
- blur?: number;
1638
- backgroundBlurriness?: number;
1639
- backgroundIntensity?: number;
1640
- backgroundRotation?: Euler;
1641
- environmentIntensity?: number;
1642
- environmentRotation?: Euler;
1643
- map?: Texture$1;
1644
- preset?: PresetsType;
1645
- scene?: Scene | React$1.RefObject<Scene>;
1646
- ground?: boolean | {
1647
- radius?: number;
1648
- height?: number;
1649
- scale?: number;
1650
- };
1651
- /** Solid color for background (alternative to files/preset) */
1652
- color?: ColorRepresentation$1;
1653
- /** Separate files for background (when different from environment files) */
1654
- backgroundFiles?: string | string[];
1655
- } & EnvironmentLoaderProps;
1656
- /**
1657
- * Internal component that applies a pre-existing texture as environment map.
1658
- * Sets scene.environment and optionally scene.background.
1659
- *
1660
- * @example
1661
- * ```jsx
1662
- * <CubeCamera>{(texture) => <EnvironmentMap map={texture} />}</CubeCamera>
1663
- * ```
1664
- */
1665
- declare function EnvironmentMap({ scene, background, map, ...config }: EnvironmentProps): null;
1666
- /**
1667
- * Internal component that loads environment textures from files or presets.
1668
- * Uses HDRLoader for .hdr, EXRLoader for .exr, UltraHDRLoader for .jpg/.jpeg HDR,
1669
- * GainMapLoader for gainmap .webp, or CubeTextureLoader for arrays of images.
1670
- *
1671
- * @example With preset
1672
- * ```jsx
1673
- * <EnvironmentCube preset="sunset" />
1674
- * ```
1675
- *
1676
- * @example From HDR file
1677
- * ```jsx
1678
- * <EnvironmentCube files="environment.hdr" />
1679
- * ```
1680
- *
1681
- * @example From gainmap (smallest footprint)
1682
- * ```jsx
1683
- * <EnvironmentCube files={['file.webp', 'file-gainmap.webp', 'file.json']} />
1684
- * ```
1685
- *
1686
- * @example From cube faces
1687
- * ```jsx
1688
- * <EnvironmentCube files={['px.png', 'nx.png', 'py.png', 'ny.png', 'pz.png', 'nz.png']} />
1689
- * ```
1690
- */
1691
- declare function EnvironmentCube({ background, scene, blur, backgroundBlurriness, backgroundIntensity, backgroundRotation, environmentIntensity, environmentRotation, ...rest }: EnvironmentProps): null;
1692
- /**
1693
- * Internal component that renders custom environment using a portal and cube camera.
1694
- * Renders children into an off-buffer and films with a cube camera to create environment map.
1695
- * Can be static (frames=1) or animated (frames=Infinity).
1696
- *
1697
- * @example Custom environment with sphere
1698
- * ```jsx
1699
- * <EnvironmentPortal background near={1} far={1000} resolution={256}>
1700
- * <mesh scale={100}>
1701
- * <sphereGeometry args={[1, 64, 64]} />
1702
- * <meshBasicMaterial map={texture} side={THREE.BackSide} />
1703
- * </mesh>
1704
- * </EnvironmentPortal>
1705
- * ```
1706
- *
1707
- * @example Animated environment
1708
- * ```jsx
1709
- * <EnvironmentPortal frames={Infinity} resolution={256}>
1710
- * <Float>
1711
- * <mesh />
1712
- * </Float>
1713
- * </EnvironmentPortal>
1714
- * ```
1715
- *
1716
- * @example Mixed with preset
1717
- * ```jsx
1718
- * <EnvironmentPortal preset="warehouse">
1719
- * <mesh />
1720
- * </EnvironmentPortal>
1721
- * ```
1722
- */
1723
- declare function EnvironmentPortal({ children, near, far, resolution, frames, map, background, blur, backgroundBlurriness, backgroundIntensity, backgroundRotation, environmentIntensity, environmentRotation, scene, files, path, preset, extensions, }: EnvironmentProps): react_jsx_runtime.JSX.Element;
1724
- declare module '@react-three/fiber' {
1725
- interface ThreeElements {
1726
- groundProjectedEnvImpl: ThreeElement<typeof GroundedSkybox>;
1727
- }
1728
- }
1729
- /**
1730
- * Sets up a global environment map for PBR materials and backgrounds.
1731
- * Affects scene.environment and optionally scene.background unless a custom scene is passed.
1732
- *
1733
- * Supports multiple input methods:
1734
- * - **Presets**: Selection of HDRI Haven assets (apartment, city, dawn, forest, lobby, night, park, studio, sunset, warehouse)
1735
- * - **Files**: HDR (.hdr), EXR (.exr), gainmap JPEG (.jpg), gainmap WebP (.webp), or cube faces (array of 6 images)
1736
- * - **Texture**: Pre-existing cube texture via `map` prop
1737
- * - **Custom Scene**: Render children into environment using portal and cube camera
1738
- * - **Ground Projection**: Project environment onto ground plane
1739
- *
1740
- * @remarks
1741
- * - Preset property is NOT meant for production and may fail (relies on CDNs)
1742
- * - Gainmap format has the smallest file footprint
1743
- * - Use `frames={Infinity}` for animated environments with low resolution for performance
1744
- * - Ground projection places models on the "ground" within the environment map
1745
- * - Supports self-hosting with @pmndrs/assets using dynamic imports
1746
- *
1747
- * @example Basic preset usage
1748
- * ```jsx
1749
- * <Environment preset="sunset" />
1750
- * ```
1751
- *
1752
- * @example From HDR file
1753
- * ```jsx
1754
- * <Environment files="/hdr/environment.hdr" />
1755
- * ```
1756
- *
1757
- * @example From gainmap (smallest footprint)
1758
- * ```jsx
1759
- * <Environment files={['file.webp', 'file-gainmap.webp', 'file.json']} />
1760
- * ```
1761
- *
1762
- * @example With self-hosted assets
1763
- * ```jsx
1764
- * import { suspend } from 'suspend-react'
1765
- * const city = import('@pmndrs/assets/hdri/city.exr').then(m => m.default)
1766
- *
1767
- * <Environment files={suspend(city)} />
1768
- * ```
1769
- *
1770
- * @example From existing texture
1771
- * ```jsx
1772
- * <CubeCamera>{(texture) => <Environment map={texture} />}</CubeCamera>
1773
- * ```
1774
- *
1775
- * @example Custom environment scene
1776
- * ```jsx
1777
- * <Environment background near={1} far={1000} resolution={256}>
1778
- * <mesh scale={100}>
1779
- * <sphereGeometry args={[1, 64, 64]} />
1780
- * <meshBasicMaterial map={texture} side={THREE.BackSide} />
1781
- * </mesh>
1782
- * </Environment>
1783
- * ```
1784
- *
1785
- * @example Animated environment
1786
- * ```jsx
1787
- * <Environment frames={Infinity} resolution={256}>
1788
- * <Float>
1789
- * <mesh />
1790
- * </Float>
1791
- * </Environment>
1792
- * ```
1793
- *
1794
- * @example Mixed custom scene with preset
1795
- * ```jsx
1796
- * <Environment background preset="warehouse">
1797
- * <mesh />
1798
- * </Environment>
1799
- * ```
1800
- *
1801
- * @example With ground projection
1802
- * ```jsx
1803
- * <Environment ground={{ height: 15, radius: 60 }} preset="city" />
1804
- * ```
1805
- *
1806
- * @example As background only
1807
- * ```jsx
1808
- * <Environment background="only" preset="sunset" />
1809
- * ```
1810
- *
1811
- * @example With rotation and intensity
1812
- * ```jsx
1813
- * <Environment
1814
- * background
1815
- * backgroundBlurriness={0.5}
1816
- * backgroundIntensity={0.8}
1817
- * backgroundRotation={[0, Math.PI / 2, 0]}
1818
- * environmentIntensity={1.2}
1819
- * environmentRotation={[0, Math.PI / 4, 0]}
1820
- * preset="studio"
1821
- * />
1822
- * ```
1823
- */
1824
- declare function Environment(props: EnvironmentProps): react_jsx_runtime.JSX.Element;
1825
-
1826
- /**
1827
- * Moves every trace of interactivity from one object to its replacement, for reconstruction.
1828
- *
1829
- * When `args` or a `primitive`'s `object` changes, R3F builds a new three object and keeps the same
1830
- * instance. Removing the old object from the interaction state and registering the new one from
1831
- * scratch makes events *work* again (#3778), but it forgets what was in flight: a pointer resting on
1832
- * the object fires a second `onPointerEnter` without ever having left, and an active pointer capture
1833
- * is dropped mid-drag. Rewriting the references instead keeps the interaction continuous across a
1834
- * swap the user never asked to see (#3744).
1835
- *
1836
- * Captures are re-keyed rather than released, so the DOM-level capture on `captureData.target` is
1837
- * left alone — releasing and re-acquiring it is precisely the glitch being avoided.
1838
- *
1839
- * Visibility handlers are deliberately not transferred: that registry is keyed by `object.uuid`, so
1840
- * the replacement re-registers itself through `applyProps`. The old entry is dropped here so it
1841
- * cannot outlive the object it described.
1842
- */
1843
- declare function swapInteractivity(store: RootStore, object: Object3D, newObject: Object3D): void;
1844
- declare function removeInteractivity(store: RootStore, object: Object3D): void;
1845
- declare function createEvents(store: RootStore): {
1846
- handlePointer: (name: string) => (event: DomEvent) => void;
1847
- flushDeferredPointers: () => void;
1848
- processDeferredPointer: (event: DomEvent, pointerId: number) => void;
1849
- };
1850
- /** Default R3F event manager for web */
1851
- declare function createPointerEvents(store: RootStore): EventManager<HTMLElement>;
1852
-
1853
- /**
1854
- * Gets or creates a memoized loader instance from a loader constructor or returns the loader if it's already an instance.
1855
- * This allows external code to access loader methods like abort().
1856
- */
1857
- declare function getLoader<L extends LoaderLike | ConstructorRepresentation<LoaderLike>>(Proto: L): L extends ConstructorRepresentation<infer T> ? T : L;
1858
- /**
1859
- * Synchronously loads and caches assets with a three loader.
1860
- *
1861
- * Note: this hook's caller must be wrapped with `React.Suspense`
1862
- * @see https://docs.pmnd.rs/react-three-fiber/api/hooks#useloader
1863
- */
1864
- declare function useLoader<I extends InputLike, L extends LoaderLike | ConstructorRepresentation<LoaderLike>>(loader: L, input: I, extensions?: Extensions<L>, onProgress?: (event: ProgressEvent<EventTarget>) => void, cacheKey?: InputLike): I extends any[] ? LoaderResult<L>[] : LoaderResult<L>;
1865
- declare namespace useLoader {
1866
- var preload: <I extends InputLike, L extends LoaderLike | ConstructorRepresentation<LoaderLike>>(loader: L, input: I, extensions?: Extensions<L>, onProgress?: (event: ProgressEvent<EventTarget>) => void, cacheKey?: InputLike) => void;
1867
- var clear: <I extends InputLike, L extends LoaderLike | ConstructorRepresentation<LoaderLike>>(loader: L, input: I, cacheKey?: InputLike) => void;
1868
- var loader: typeof getLoader;
1869
- }
1870
-
1871
- /**
1872
- * Frame hook with phase-based ordering, priority, and FPS throttling.
1873
- *
1874
- * Always delivers full RootState — works both inside and outside Canvas context:
1875
- * - Inside Canvas: Full RootState (renderer, scene, camera, etc.)
1876
- * - Outside Canvas: The job registers immediately but the callback is held until a
1877
- * Canvas adopts it, then runs with full RootState. For hostless / standalone
1878
- * frame loops with no Canvas, use `@pmndrs/scheduler` directly.
1879
- *
1880
- * Returns a controls object for manual stepping, pausing, and resuming.
1881
- *
1882
- * @param callback - Function called each frame with (state, delta). Optional if you only need scheduler access.
1883
- * @param priorityOrOptions - Either a priority number (backwards compat) or options object
1884
- * @returns Controls object with step(), stepAll(), pause(), resume(), isPaused, id, scheduler
1885
- *
1886
- * @example
1887
- * // Simple priority (backwards compat)
1888
- * useFrame((state, delta) => { ... }, 5)
1889
- *
1890
- * @example
1891
- * // With phase-based ordering
1892
- * useFrame((state, delta) => { ... }, { phase: 'physics' })
1893
- *
1894
- * @example
1895
- * // Outside Canvas - callback waits for a Canvas, then always has full state
1896
- * function UI() {
1897
- * useFrame((state, delta) => { syncUI(state.camera) });
1898
- * return <button>...</button>;
1899
- * }
1900
- *
1901
- * @example
1902
- * // Hostless / standalone loop (no Canvas) - use @pmndrs/scheduler directly
1903
- * import { getScheduler } from '@pmndrs/scheduler'
1904
- * getScheduler().register((state, delta) => { updateGame(delta) })
1905
- *
1906
- * @example
1907
- * // Scheduler-only access (no callback)
1908
- * const { scheduler } = useFrame()
1909
- * scheduler.pauseJob('some-job-id')
1910
- *
1911
- * @see https://docs.pmnd.rs/react-three-fiber/api/hooks#useframe
1912
- */
1913
- declare function useFrame(callback?: FrameNextCallback, priorityOrOptions?: number | UseFrameNextOptions): FrameNextControls;
1914
-
1915
- declare const IsObject: (url: unknown) => url is Record<string, string>;
1916
- type TextureArray<T> = T extends string[] ? Texture$1[] : never;
1917
- type TextureRecord<T> = T extends Record<string, string> ? {
1918
- [key in keyof T]: Texture$1;
1919
- } : never;
1920
- type SingleTexture<T> = T extends string ? Texture$1 : never;
1921
- type MappedTextureType<T extends string[] | string | Record<string, string>> = TextureArray<T> | TextureRecord<T> | SingleTexture<T>;
1922
- /** Options for useTexture hook */
1923
- type UseTextureOptions<Url extends string[] | string | Record<string, string>> = {
1924
- /** Callback when texture(s) finish loading */
1925
- onLoad?: (texture: MappedTextureType<Url>) => void;
1926
- /**
1927
- * Register the texture(s) in R3F's global texture registry for access via useTextures().
1928
- * When true (the default):
1929
- * - Textures persist until explicitly disposed
1930
- * - On mount, returns existing registered textures if available (preserving modifications like colorSpace)
1931
- *
1932
- * Reads are taken once at mount — a mounted `useTexture` does not re-render when the registry
1933
- * changes. To react to registry swaps, use `useTextures(s => s.get(key))` instead.
1934
- *
1935
- * Pass `false` to opt out of registry enrollment entirely.
1936
- * @default true
1937
- */
1938
- cache?: boolean;
1939
- };
1940
- /**
1941
- * Load texture(s) using Three's TextureLoader with Suspense support.
1942
- *
1943
- * @param input - URL string, array of URLs, or object mapping keys to URLs
1944
- * @param optionsOrOnLoad - Options object or legacy onLoad callback
1945
- *
1946
- * @example
1947
- * ```tsx
1948
- * // Single texture
1949
- * const diffuse = useTexture('/textures/diffuse.png')
1950
- *
1951
- * // Multiple textures (array)
1952
- * const [diffuse, normal] = useTexture(['/diffuse.png', '/normal.png'])
1953
- *
1954
- * // Named textures (object)
1955
- * const { diffuse, normal } = useTexture({
1956
- * diffuse: '/diffuse.png',
1957
- * normal: '/normal.png'
1958
- * })
1959
- *
1960
- * // Textures are registered in the global registry by default — the same texture
1961
- * // object is shared across components and modifications (colorSpace, wrapS, etc.) are preserved
1962
- * const diffuse = useTexture('/diffuse.png')
1963
- * diffuse.colorSpace = THREE.SRGBColorSpace
1964
- *
1965
- * // Another component gets the SAME texture with colorSpace already set
1966
- * const sameDiffuse = useTexture('/diffuse.png')
1967
- *
1968
- * // Opt out of registry enrollment for a one-off texture
1969
- * const scratch = useTexture('/scratch.png', { cache: false })
1970
- *
1971
- * // Access the registry directly
1972
- * const { get } = useTextures()
1973
- * const cached = get('/diffuse.png')
1974
- * ```
1975
- */
1976
- declare function useTexture<Url extends string[] | string | Record<string, string>>(input: Url, optionsOrOnLoad?: UseTextureOptions<Url> | ((texture: MappedTextureType<Url>) => void)): MappedTextureType<Url>;
1977
- declare namespace useTexture {
1978
- var preload: (url: string | string[]) => void;
1979
- var clear: (input: string | string[]) => void;
1980
- }
1981
- declare const Texture: ({ children, input, onLoad, cache, }: {
1982
- children?: (texture: ReturnType<typeof useTexture>) => ReactNode;
1983
- input: Parameters<typeof useTexture>[0];
1984
- onLoad?: Parameters<typeof useTexture>[1];
1985
- cache?: boolean;
1986
- }) => react_jsx_runtime.JSX.Element;
1987
-
1988
- /** Accepted shapes for a registry read: a single key, a list of keys, or a name→key map. */
1989
- type TextureInput = string | string[] | Record<string, string>;
1990
- /** Result of a `get()` read, mirroring the input shape. */
1991
- type TextureResult<Input extends TextureInput> = Input extends string ? Texture$1 | undefined : Input extends string[] ? (Texture$1 | undefined)[] : {
1992
- [K in keyof Input]: Texture$1 | undefined;
1993
- };
1994
- /** Options for `dispose()`. */
1995
- interface DisposeOptions {
1996
- /** Dispose even if the texture still has active references (default false). */
1997
- force?: boolean;
1998
- }
1999
- interface UseTexturesReturn {
2000
- /** The live registry Map (key → Texture). Treat as read-only. */
2001
- readonly all: Map<string, Texture$1>;
2002
- /** Read one texture, an array of textures, or a name→texture record (mirrors the input shape). */
2003
- get<Input extends TextureInput>(input: Input): TextureResult<Input>;
2004
- /** Check whether a key exists in the registry. */
2005
- has(key: string): boolean;
2006
- /**
2007
- * Register a texture (or a record of textures) that has no URL — e.g. a render
2008
- * target or procedural texture. URL-loaded textures are registered automatically
2009
- * by `useTexture` (registry enrollment is on by default).
2010
- */
2011
- add(key: string, texture: Texture$1): void;
2012
- add(record: Record<string, Texture$1>): void;
2013
- /**
2014
- * Dispose a texture's GPU resources and remove it from the registry.
2015
- * Refcount-aware: if the key is still in use by a mounted `useTexture` consumer it is
2016
- * skipped (with a warning) unless `{ force: true }` is passed.
2017
- * @returns true if disposed, false if skipped.
2018
- */
2019
- dispose(key: string, options?: DisposeOptions): boolean;
2020
- /** Dispose every texture in the registry and clear it. Use on scene teardown. */
2021
- disposeAll(): void;
2022
- }
2023
- /**
2024
- * Reactive Texture registry — load once with `useTexture`, reach the textures from anywhere.
2025
- *
2026
- * This is a registry of plain `Texture` objects (not TSL nodes), so the same texture can feed
2027
- * a material map, a heightmap sampler, or anything else. It does **not** load — pair it with
2028
- * `useTexture` for loading (registry enrollment is on by default); `useTextures` is for access and lifecycle.
2029
- *
2030
- * The returned handle is **reactive**: the calling component re-renders when the registry
2031
- * changes. Pass a selector to scope the subscription to a single read.
2032
- *
2033
- * @example
2034
- * ```tsx
2035
- * // Load + register once (anywhere in the tree) — registered by default
2036
- * useTexture({ map: '/diffuse.jpg', normalMap: '/normal.jpg' })
2037
- *
2038
- * // Reach them from another component — record form lands straight into a material
2039
- * const { map, normalMap } = useTextures().get({ map: '/diffuse.jpg', normalMap: '/normal.jpg' })
2040
- * return <meshStandardMaterial map={map} normalMap={normalMap} />
2041
- *
2042
- * // A set of heightmaps at once
2043
- * const [a, b, c] = useTextures().get(['/h0.png', '/h1.png', '/h2.png'])
2044
- *
2045
- * // Register a non-URL texture (render target / procedural)
2046
- * useTextures().add('rt-main', renderTarget.texture)
2047
- *
2048
- * // Deliberate GPU cleanup (refcount-aware; force to override)
2049
- * useTextures().dispose('/diffuse.jpg')
2050
- * useTextures().disposeAll() // scene teardown
2051
- * ```
2052
- *
2053
- * @remarks
2054
- * **Future expansion:** an imperative async loader (e.g. `await useTextures().load('/x.jpg')`) is
2055
- * intentionally not included yet. It would let non-React code (loading screens, dynamic streaming)
2056
- * populate the registry without Suspense, at the cost of putting loading back into this hook. It
2057
- * will be added only if a concrete consumer needs imperative loading; for now, loading lives in
2058
- * `useTexture`.
2059
- */
2060
- declare function useTextures(): UseTexturesReturn;
2061
- declare function useTextures<T>(selector: (registry: UseTexturesReturn) => T): T;
2062
-
2063
- /**
2064
- * Creates a render target compatible with the current renderer.
2065
- *
2066
- * - Legacy build: Returns WebGLRenderTarget
2067
- * - WebGPU build: Returns RenderTarget
2068
- * - Default build: Returns whichever matches the active renderer
2069
- *
2070
- * @example
2071
- * ```tsx
2072
- * // Use canvas size
2073
- * const fbo = useRenderTarget()
2074
- *
2075
- * // Use canvas size with options
2076
- * const fbo = useRenderTarget({ samples: 4 })
2077
- *
2078
- * // Square render target
2079
- * const fbo = useRenderTarget(512)
2080
- *
2081
- * // Square render target with options
2082
- * const fbo = useRenderTarget(512, { depthBuffer: true })
2083
- *
2084
- * // Explicit dimensions
2085
- * const fbo = useRenderTarget(512, 256)
2086
- *
2087
- * // Explicit dimensions with options
2088
- * const fbo = useRenderTarget(512, 256, { samples: 4 })
2089
- * ```
2090
- */
2091
- declare function useRenderTarget(options?: RenderTargetOptions): RenderTarget;
2092
- declare function useRenderTarget(size: number, options?: RenderTargetOptions): RenderTarget;
2093
- declare function useRenderTarget(width: number, height: number, options?: RenderTargetOptions): RenderTarget;
2094
-
2095
- /**
2096
- * Returns the R3F Canvas' Zustand store. Useful for [transient updates](https://github.com/pmndrs/zustand#transient-updates-for-often-occurring-state-changes).
2097
- * @see https://docs.pmnd.rs/react-three-fiber/api/hooks#usestore
2098
- */
2099
- declare function useStore(): RootStore;
2100
- /**
2101
- * Accesses R3F's internal state, containing renderer, canvas, scene, etc.
2102
- * @see https://docs.pmnd.rs/react-three-fiber/api/hooks#usethree
2103
- */
2104
- declare function useThree<T = RootState>(selector?: (state: RootState) => T, equalityFn?: <T>(state: T, newState: T) => boolean): T;
2105
- /**
2106
- * Exposes an object's {@link Instance}.
2107
- * @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#useInstanceHandle
2108
- *
2109
- * **Note**: this is an escape hatch to react-internal fields. Expect this to change significantly between versions.
2110
- */
2111
- declare function useInstanceHandle<T>(ref: React.RefObject<T>): React.RefObject<Instance<T>>;
2112
- /**
2113
- * Returns a node graph of an object with named nodes & materials.
2114
- * @see https://docs.pmnd.rs/react-three-fiber/api/hooks#usegraph
2115
- */
2116
- declare function useGraph(object: Object3D): ObjectMap;
2117
-
2118
- /**
2119
- * Adds a global render callback which is called each frame BEFORE rendering.
2120
- *
2121
- * @deprecated Use `useFrame(callback, { phase: 'start' })` instead.
2122
- * This function will be removed in a future version.
2123
- *
2124
- * @param callback - Function called each frame with timestamp
2125
- * @returns Unsubscribe function
2126
- *
2127
- * @example
2128
- * // OLD (deprecated)
2129
- * const unsub = addEffect((timestamp) => { ... })
2130
- *
2131
- * // NEW
2132
- * useFrame((state, delta) => { ... }, { phase: 'start' })
2133
- *
2134
- * @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#addEffect
2135
- */
2136
- declare function addEffect(callback: GlobalRenderCallback): () => void;
2137
- /**
2138
- * Adds a global after-render callback which is called each frame AFTER rendering.
2139
- *
2140
- * @deprecated Use `useFrame(callback, { phase: 'finish' })` instead.
2141
- * This function will be removed in a future version.
2142
- *
2143
- * @param callback - Function called each frame with timestamp
2144
- * @returns Unsubscribe function
2145
- *
2146
- * @example
2147
- * // OLD (deprecated)
2148
- * const unsub = addAfterEffect((timestamp) => { ... })
2149
- *
2150
- * // NEW
2151
- * useFrame((state, delta) => { ... }, { phase: 'finish' })
2152
- *
2153
- * @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#addAfterEffect
2154
- */
2155
- declare function addAfterEffect(callback: GlobalRenderCallback): () => void;
2156
- /**
2157
- * Adds a global callback which is called when rendering stops.
2158
- *
2159
- * @deprecated Use `scheduler.onIdle(callback)` instead.
2160
- * This function will be removed in a future version.
2161
- *
2162
- * @param callback - Function called when rendering stops
2163
- * @returns Unsubscribe function
2164
- *
2165
- * @example
2166
- * // OLD (deprecated)
2167
- * const unsub = addTail((timestamp) => { ... })
2168
- *
2169
- * // NEW
2170
- * const { scheduler } = useFrame()
2171
- * const unsub = scheduler.onIdle((timestamp) => { ... })
2172
- *
2173
- * @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#addTail
2174
- */
2175
- declare function addTail(callback: GlobalRenderCallback): () => void;
2176
- /**
2177
- * Invalidates the view, requesting a frame to be rendered.
2178
- * In demand mode, this triggers the scheduler to run frames.
2179
- *
2180
- * @param state - Optional root state (ignored in new scheduler, kept for backwards compat)
2181
- * @param frames - Number of frames to request (default: 1)
2182
- * @param stackFrames - If false, sets pendingFrames to frames. If true, adds to existing pendingFrames (default: false)
2183
- *
2184
- * @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#invalidate
2185
- */
2186
- declare function invalidate(state?: RootState, frames?: number, stackFrames?: boolean): void;
2187
- /**
2188
- * Advances the frameloop and runs render effects.
2189
- * Useful for when manually rendering via `frameloop="never"`.
2190
- *
2191
- * @param timestamp - The timestamp to use for this frame
2192
- * @param runGlobalEffects - Ignored (kept for backwards compat, global effects always run)
2193
- * @param state - Ignored (kept for backwards compat)
2194
- * @param frame - Ignored (kept for backwards compat)
2195
- *
2196
- * @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#advance
2197
- */
2198
- declare function advance(timestamp: number): void;
2199
-
2200
- /* eslint-disable @definitelytyped/no-unnecessary-generics */
2201
- declare function ReactReconciler<
2202
- Type,
2203
- Props,
2204
- Container,
2205
- Instance,
2206
- TextInstance,
2207
- SuspenseInstance,
2208
- HydratableInstance,
2209
- FormInstance,
2210
- PublicInstance,
2211
- HostContext,
2212
- ChildSet,
2213
- TimeoutHandle,
2214
- NoTimeout,
2215
- TransitionStatus,
2216
- >(
2217
- /* eslint-enable @definitelytyped/no-unnecessary-generics */
2218
- config: ReactReconciler.HostConfig<
2219
- Type,
2220
- Props,
2221
- Container,
2222
- Instance,
2223
- TextInstance,
2224
- SuspenseInstance,
2225
- HydratableInstance,
2226
- FormInstance,
2227
- PublicInstance,
2228
- HostContext,
2229
- ChildSet,
2230
- TimeoutHandle,
2231
- NoTimeout,
2232
- TransitionStatus
2233
- >,
2234
- ): ReactReconciler.Reconciler<Container, Instance, TextInstance, SuspenseInstance, FormInstance, PublicInstance>;
2235
-
2236
- declare namespace ReactReconciler {
2237
- interface HostConfig<
2238
- Type,
2239
- Props,
2240
- Container,
2241
- Instance,
2242
- TextInstance,
2243
- SuspenseInstance,
2244
- HydratableInstance,
2245
- FormInstance,
2246
- PublicInstance,
2247
- HostContext,
2248
- ChildSet,
2249
- TimeoutHandle,
2250
- NoTimeout,
2251
- TransitionStatus,
2252
- > {
2253
- // -------------------
2254
- // Modes
2255
- // -------------------
2256
- /**
2257
- * The reconciler has two modes: mutation mode and persistent mode. You must specify one of them.
2258
- *
2259
- * If your target platform is similar to the DOM and has methods similar to `appendChild`, `removeChild`, and so on, you'll want to use the **mutation mode**. This is the same mode used by React DOM, React ART, and the classic React Native renderer.
2260
- *
2261
- * ```js
2262
- * const HostConfig = {
2263
- * // ...
2264
- * supportsMutation: true,
2265
- * // ...
2266
- * }
2267
- * ```
2268
- *
2269
- * Depending on the mode, the reconciler will call different methods on your host config.
2270
- *
2271
- * If you're not sure which one you want, you likely need the mutation mode.
2272
- */
2273
- supportsMutation: boolean;
2274
-
2275
- /**
2276
- * The reconciler has two modes: mutation mode and persistent mode. You must specify one of them.
2277
- *
2278
- * If your target platform has immutable trees, you'll want the **persistent mode** instead. In that mode, existing nodes are never mutated, and instead every change clones the parent tree and then replaces the whole parent tree at the root. This is the node used by the new React Native renderer, codenamed "Fabric".
2279
- *
2280
- * ```js
2281
- * const HostConfig = {
2282
- * // ...
2283
- * supportsPersistence: true,
2284
- * // ...
2285
- * }
2286
- * ```
2287
- *
2288
- * Depending on the mode, the reconciler will call different methods on your host config.
2289
- *
2290
- * If you're not sure which one you want, you likely need the mutation mode.
2291
- */
2292
- supportsPersistence: boolean;
2293
-
2294
- // -------------------
2295
- // Core Methods
2296
- // -------------------
2297
-
2298
- /**
2299
- * This method should return a newly created node. For example, the DOM renderer would call `document.createElement(type)` here and then set the properties from `props`.
2300
- *
2301
- * You can use `rootContainer` to access the root container associated with that tree. For example, in the DOM renderer, this is useful to get the correct `document` reference that the root belongs to.
2302
- *
2303
- * The `hostContext` parameter lets you keep track of some information about your current place in the tree. To learn more about it, see `getChildHostContext` below.
2304
- *
2305
- * The `internalHandle` data structure is meant to be opaque. If you bend the rules and rely on its internal fields, be aware that it may change significantly between versions. You're taking on additional maintenance risk by reading from it, and giving up all guarantees if you write something to it.
2306
- *
2307
- * This method happens **in the render phase**. It can (and usually should) mutate the node it has just created before returning it, but it must not modify any other nodes. It must not register any event handlers on the parent tree. This is because an instance being created doesn't guarantee it would be placed in the tree — it could be left unused and later collected by GC. If you need to do something when an instance is definitely in the tree, look at `commitMount` instead.
2308
- */
2309
- createInstance(
2310
- type: Type,
2311
- props: Props,
2312
- rootContainer: Container,
2313
- hostContext: HostContext,
2314
- internalHandle: OpaqueHandle,
2315
- ): Instance;
2316
-
2317
- /**
2318
- * Same as `createInstance`, but for text nodes. If your renderer doesn't support text nodes, you can throw here.
2319
- */
2320
- createTextInstance(
2321
- text: string,
2322
- rootContainer: Container,
2323
- hostContext: HostContext,
2324
- internalHandle: OpaqueHandle,
2325
- ): TextInstance;
2326
-
2327
- /**
2328
- * This method should mutate the `parentInstance` and add the child to its list of children. For example, in the DOM this would translate to a `parentInstance.appendChild(child)` call.
2329
- *
2330
- * This method happens **in the render phase**. It can mutate `parentInstance` and `child`, but it must not modify any other nodes. It's called while the tree is still being built up and not connected to the actual tree on the screen.
2331
- */
2332
- appendInitialChild(parentInstance: Instance, child: Instance | TextInstance): void;
2333
-
2334
- /**
2335
- * In this method, you can perform some final mutations on the `instance`. Unlike with `createInstance`, by the time `finalizeInitialChildren` is called, all the initial children have already been added to the `instance`, but the instance itself has not yet been connected to the tree on the screen.
2336
- *
2337
- * This method happens **in the render phase**. It can mutate `instance`, but it must not modify any other nodes. It's called while the tree is still being built up and not connected to the actual tree on the screen.
2338
- *
2339
- * There is a second purpose to this method. It lets you specify whether there is some work that needs to happen when the node is connected to the tree on the screen. If you return `true`, the instance will receive a `commitMount` call later. See its documentation below.
2340
- *
2341
- * If you don't want to do anything here, you should return `false`.
2342
- */
2343
- finalizeInitialChildren(
2344
- instance: Instance,
2345
- type: Type,
2346
- props: Props,
2347
- rootContainer: Container,
2348
- hostContext: HostContext,
2349
- ): boolean;
2350
-
2351
- /**
2352
- * Some target platforms support setting an instance's text content without manually creating a text node. For example, in the DOM, you can set `node.textContent` instead of creating a text node and appending it.
2353
- *
2354
- * If you return `true` from this method, React will assume that this node's children are text, and will not create nodes for them. It will instead rely on you to have filled that text during `createInstance`. This is a performance optimization. For example, the DOM renderer returns `true` only if `type` is a known text-only parent (like `'textarea'`) or if `props.children` has a `'string'` type. If you return `true`, you will need to implement `resetTextContent` too.
2355
- *
2356
- * If you don't want to do anything here, you should return `false`.
2357
- *
2358
- * This method happens **in the render phase**. Do not mutate the tree from it.
2359
- */
2360
- shouldSetTextContent(type: Type, props: Props): boolean;
2361
-
2362
- /**
2363
- * This method lets you return the initial host context from the root of the tree. See `getChildHostContext` for the explanation of host context.
2364
- *
2365
- * If you don't intend to use host context, you can return `null`.
2366
- *
2367
- * This method happens **in the render phase**. Do not mutate the tree from it.
2368
- */
2369
- getRootHostContext(rootContainer: Container): HostContext | null;
2370
-
2371
- /**
2372
- * Host context lets you track some information about where you are in the tree so that it's available inside `createInstance` as the `hostContext` parameter. For example, the DOM renderer uses it to track whether it's inside an HTML or an SVG tree, because `createInstance` implementation needs to be different for them.
2373
- *
2374
- * If the node of this `type` does not influence the context you want to pass down, you can return `parentHostContext`. Alternatively, you can return any custom object representing the information you want to pass down.
2375
- *
2376
- * If you don't want to do anything here, return `parentHostContext`.
2377
- *
2378
- * This method happens **in the render phase**. Do not mutate the tree from it.
2379
- */
2380
- getChildHostContext(parentHostContext: HostContext, type: Type, rootContainer: Container): HostContext;
2381
-
2382
- /**
2383
- * Determines what object gets exposed as a ref. You'll likely want to return the `instance` itself. But in some cases it might make sense to only expose some part of it.
2384
- *
2385
- * If you don't want to do anything here, return `instance`.
2386
- */
2387
- getPublicInstance(instance: Instance | TextInstance): PublicInstance;
2388
-
2389
- /**
2390
- * This method lets you store some information before React starts making changes to the tree on the screen. For example, the DOM renderer stores the current text selection so that it can later restore it. This method is mirrored by `resetAfterCommit`.
2391
- *
2392
- * Even if you don't want to do anything here, you need to return `null` from it.
2393
- */
2394
- prepareForCommit(containerInfo: Container): Record<string, any> | null;
2395
-
2396
- /**
2397
- * This method is called right after React has performed the tree mutations. You can use it to restore something you've stored in `prepareForCommit` — for example, text selection.
2398
- *
2399
- * You can leave it empty.
2400
- */
2401
- resetAfterCommit(containerInfo: Container): void;
2402
-
2403
- /**
2404
- * This method is called for a container that's used as a portal target. Usually you can leave it empty.
2405
- */
2406
- preparePortalMount(containerInfo: Container): void;
2407
-
2408
- /**
2409
- * You can proxy this to `setTimeout` or its equivalent in your environment.
2410
- */
2411
- scheduleTimeout(fn: (...args: unknown[]) => unknown, delay?: number): TimeoutHandle;
2412
-
2413
- /**
2414
- * You can proxy this to `clearTimeout` or its equivalent in your environment.
2415
- */
2416
- cancelTimeout(id: TimeoutHandle): void;
2417
-
2418
- /**
2419
- * This is a property (not a function) that should be set to something that can never be a valid timeout ID. For example, you can set it to `-1`.
2420
- */
2421
- noTimeout: NoTimeout;
2422
-
2423
- /**
2424
- * Set this to true to indicate that your renderer supports `scheduleMicrotask`. We use microtasks as part of our discrete event implementation in React DOM. If you're not sure if your renderer should support this, you probably should. The option to not implement `scheduleMicrotask` exists so that platforms with more control over user events, like React Native, can choose to use a different mechanism.
2425
- */
2426
- supportsMicrotasks?: boolean;
2427
-
2428
- /**
2429
- * Optional. You can proxy this to `queueMicrotask` or its equivalent in your environment.
2430
- */
2431
- scheduleMicrotask?(fn: () => unknown): void;
2432
-
2433
- /**
2434
- * This is a property (not a function) that should be set to `true` if your renderer is the main one on the page. For example, if you're writing a renderer for the Terminal, it makes sense to set it to `true`, but if your renderer is used *on top of* React DOM or some other existing renderer, set it to `false`.
2435
- */
2436
- isPrimaryRenderer: boolean;
2437
-
2438
- /**
2439
- * Whether the renderer shouldn't trigger missing `act()` warnings
2440
- */
2441
- warnsIfNotActing?: boolean;
2442
-
2443
- getInstanceFromNode(node: any): Fiber | null | undefined;
2444
-
2445
- beforeActiveInstanceBlur(): void;
2446
-
2447
- afterActiveInstanceBlur(): void;
2448
-
2449
- prepareScopeUpdate(scopeInstance: any, instance: any): void;
2450
-
2451
- getInstanceFromScope(scopeInstance: any): null | Instance;
2452
-
2453
- detachDeletedInstance(node: Instance): void;
2454
-
2455
- // -------------------
2456
- // Mutation Methods
2457
- // (optional)
2458
- // If you're using React in mutation mode (you probably do), you'll need to implement a few more methods.
2459
- // -------------------
2460
-
2461
- /**
2462
- * This method should mutate the `parentInstance` and add the child to its list of children. For example, in the DOM this would translate to a `parentInstance.appendChild(child)` call.
2463
- *
2464
- * Although this method currently runs in the commit phase, you still should not mutate any other nodes in it. If you need to do some additional work when a node is definitely connected to the visible tree, look at `commitMount`.
2465
- */
2466
- appendChild?(parentInstance: Instance, child: Instance | TextInstance): void;
2467
-
2468
- /**
2469
- * Same as `appendChild`, but for when a node is attached to the root container. This is useful if attaching to the root has a slightly different implementation, or if the root container nodes are of a different type than the rest of the tree.
2470
- */
2471
- appendChildToContainer?(container: Container, child: Instance | TextInstance): void;
2472
-
2473
- /**
2474
- * This method should mutate the `parentInstance` and place the `child` before `beforeChild` in the list of its children. For example, in the DOM this would translate to a `parentInstance.insertBefore(child, beforeChild)` call.
2475
- *
2476
- * Note that React uses this method both for insertions and for reordering nodes. Similar to DOM, it is expected that you can call `insertBefore` to reposition an existing child. Do not mutate any other parts of the tree from it.
2477
- */
2478
- insertBefore?(
2479
- parentInstance: Instance,
2480
- child: Instance | TextInstance,
2481
- beforeChild: Instance | TextInstance | SuspenseInstance,
2482
- ): void;
2483
-
2484
- /**
2485
- * Same as `insertBefore`, but for when a node is attached to the root container. This is useful if attaching to the root has a slightly different implementation, or if the root container nodes are of a different type than the rest of the tree.
2486
- */
2487
- insertInContainerBefore?(
2488
- container: Container,
2489
- child: Instance | TextInstance,
2490
- beforeChild: Instance | TextInstance | SuspenseInstance,
2491
- ): void;
2492
-
2493
- /**
2494
- * This method should mutate the `parentInstance` to remove the `child` from the list of its children.
2495
- *
2496
- * React will only call it for the top-level node that is being removed. It is expected that garbage collection would take care of the whole subtree. You are not expected to traverse the child tree in it.
2497
- */
2498
- removeChild?(parentInstance: Instance, child: Instance | TextInstance | SuspenseInstance): void;
2499
-
2500
- /**
2501
- * Same as `removeChild`, but for when a node is detached from the root container. This is useful if attaching to the root has a slightly different implementation, or if the root container nodes are of a different type than the rest of the tree.
2502
- */
2503
- removeChildFromContainer?(container: Container, child: Instance | TextInstance | SuspenseInstance): void;
2504
-
2505
- /**
2506
- * If you returned `true` from `shouldSetTextContent` for the previous props, but returned `false` from `shouldSetTextContent` for the next props, React will call this method so that you can clear the text content you were managing manually. For example, in the DOM you could set `node.textContent = ''`.
2507
- *
2508
- * If you never return `true` from `shouldSetTextContent`, you can leave it empty.
2509
- */
2510
- resetTextContent?(instance: Instance): void;
2511
-
2512
- /**
2513
- * This method should mutate the `textInstance` and update its text content to `nextText`.
2514
- *
2515
- * Here, `textInstance` is a node created by `createTextInstance`.
2516
- */
2517
- commitTextUpdate?(textInstance: TextInstance, oldText: string, newText: string): void;
2518
-
2519
- /**
2520
- * This method is only called if you returned `true` from `finalizeInitialChildren` for this instance.
2521
- *
2522
- * It lets you do some additional work after the node is actually attached to the tree on the screen for the first time. For example, the DOM renderer uses it to trigger focus on nodes with the `autoFocus` attribute.
2523
- *
2524
- * Note that `commitMount` does not mirror `removeChild` one to one because `removeChild` is only called for the top-level removed node. This is why ideally `commitMount` should not mutate any nodes other than the `instance` itself. For example, if it registers some events on some node above, it will be your responsibility to traverse the tree in `removeChild` and clean them up, which is not ideal.
2525
- *
2526
- * The `internalHandle` data structure is meant to be opaque. If you bend the rules and rely on its internal fields, be aware that it may change significantly between versions. You're taking on additional maintenance risk by reading from it, and giving up all guarantees if you write something to it.
2527
- *
2528
- * If you never return `true` from `finalizeInitialChildren`, you can leave it empty.
2529
- */
2530
- commitMount?(instance: Instance, type: Type, props: Props, internalInstanceHandle: OpaqueHandle): void;
2531
-
2532
- /**
2533
- * This method should mutate the instance to match nextProps.
2534
- *
2535
- * The internalHandle data structure is meant to be opaque. If you bend the rules and rely on its internal fields, be aware that it may change significantly between versions. You're taking on additional maintenance risk by reading from it, and giving up all guarantees if you write something to it.
2536
- */
2537
- commitUpdate?(
2538
- instance: Instance,
2539
- type: Type,
2540
- prevProps: Props,
2541
- nextProps: Props,
2542
- internalHandle: OpaqueHandle,
2543
- ): void;
2544
-
2545
- /**
2546
- * This method should make the `instance` invisible without removing it from the tree. For example, it can apply visual styling to hide it. It is used by Suspense to hide the tree while the fallback is visible.
2547
- */
2548
- hideInstance?(instance: Instance): void;
2549
-
2550
- /**
2551
- * Same as `hideInstance`, but for nodes created by `createTextInstance`.
2552
- */
2553
- hideTextInstance?(textInstance: TextInstance): void;
2554
-
2555
- /**
2556
- * This method should make the `instance` visible, undoing what `hideInstance` did.
2557
- */
2558
- unhideInstance?(instance: Instance, props: Props): void;
2559
-
2560
- /**
2561
- * Same as `unhideInstance`, but for nodes created by `createTextInstance`.
2562
- */
2563
- unhideTextInstance?(textInstance: TextInstance, text: string): void;
2564
-
2565
- /**
2566
- * This method should mutate the `container` root node and remove all children from it.
2567
- */
2568
- clearContainer?(container: Container): void;
2569
-
2570
- // -------------------
2571
- // Persistence Methods
2572
- // (optional)
2573
- // If you use the persistent mode instead of the mutation mode, you would still need the "Core Methods". However, instead of the Mutation Methods above you will implement a different set of methods that performs cloning nodes and replacing them at the root level. You can find a list of them in the "Persistence" section [listed in this file](https://github.com/facebook/react/blob/master/packages/react-reconciler/src/forks/ReactFiberConfig.custom.js). File an issue if you need help.
2574
- // -------------------
2575
- cloneInstance?(
2576
- instance: Instance,
2577
- type: Type,
2578
- oldProps: Props,
2579
- newProps: Props,
2580
- keepChildren: boolean,
2581
- recyclableInstance: null | Instance,
2582
- ): Instance;
2583
- createContainerChildSet?(container: Container): ChildSet;
2584
- appendChildToContainerChildSet?(childSet: ChildSet, child: Instance | TextInstance): void;
2585
- finalizeContainerChildren?(container: Container, newChildren: ChildSet): void;
2586
- replaceContainerChildren?(container: Container, newChildren: ChildSet): void;
2587
- cloneHiddenInstance?(
2588
- instance: Instance,
2589
- type: Type,
2590
- props: Props,
2591
- internalInstanceHandle: OpaqueHandle,
2592
- ): Instance;
2593
- cloneHiddenTextInstance?(instance: Instance, text: Type, internalInstanceHandle: OpaqueHandle): TextInstance;
2594
-
2595
- // -------------------
2596
- // Hydration Methods
2597
- // (optional)
2598
- // You can optionally implement hydration to "attach" to the existing tree during the initial render instead of creating it from scratch. For example, the DOM renderer uses this to attach to an HTML markup.
2599
- //
2600
- // To support hydration, you need to declare `supportsHydration: true` and then implement the methods in the "Hydration" section [listed in this file](https://github.com/facebook/react/blob/master/packages/react-reconciler/src/forks/ReactFiberConfig.custom.js). File an issue if you need help.
2601
- // -------------------
2602
- supportsHydration: boolean;
2603
-
2604
- canHydrateInstance?(instance: HydratableInstance, type: Type, props: Props): null | Instance;
2605
-
2606
- canHydrateTextInstance?(instance: HydratableInstance, text: string): null | TextInstance;
2607
-
2608
- canHydrateSuspenseInstance?(instance: HydratableInstance): null | SuspenseInstance;
2609
-
2610
- isSuspenseInstancePending?(instance: SuspenseInstance): boolean;
2611
-
2612
- isSuspenseInstanceFallback?(instance: SuspenseInstance): boolean;
2613
-
2614
- registerSuspenseInstanceRetry?(instance: SuspenseInstance, callback: () => void): void;
2615
-
2616
- getNextHydratableSibling?(instance: HydratableInstance): null | HydratableInstance;
2617
-
2618
- getFirstHydratableChild?(parentInstance: Container | Instance): null | HydratableInstance;
2619
-
2620
- hydrateInstance?(
2621
- instance: Instance,
2622
- type: Type,
2623
- props: Props,
2624
- rootContainerInstance: Container,
2625
- hostContext: HostContext,
2626
- internalInstanceHandle: any,
2627
- ): null | any[];
2628
-
2629
- hydrateTextInstance?(textInstance: TextInstance, text: string, internalInstanceHandle: any): boolean;
2630
-
2631
- hydrateSuspenseInstance?(suspenseInstance: SuspenseInstance, internalInstanceHandle: any): void;
2632
-
2633
- getNextHydratableInstanceAfterSuspenseInstance?(suspenseInstance: SuspenseInstance): null | HydratableInstance;
2634
-
2635
- // Returns the SuspenseInstance if this node is a direct child of a
2636
- // SuspenseInstance. I.e. if its previous sibling is a Comment with
2637
- // SUSPENSE_x_START_DATA. Otherwise, null.
2638
- getParentSuspenseInstance?(targetInstance: any): null | SuspenseInstance;
2639
-
2640
- commitHydratedContainer?(container: Container): void;
2641
-
2642
- commitHydratedSuspenseInstance?(suspenseInstance: SuspenseInstance): void;
2643
-
2644
- didNotMatchHydratedContainerTextInstance?(
2645
- parentContainer: Container,
2646
- textInstance: TextInstance,
2647
- text: string,
2648
- ): void;
2649
-
2650
- didNotMatchHydratedTextInstance?(
2651
- parentType: Type,
2652
- parentProps: Props,
2653
- parentInstance: Instance,
2654
- textInstance: TextInstance,
2655
- text: string,
2656
- ): void;
2657
-
2658
- didNotHydrateContainerInstance?(parentContainer: Container, instance: HydratableInstance): void;
2659
-
2660
- didNotHydrateInstance?(
2661
- parentType: Type,
2662
- parentProps: Props,
2663
- parentInstance: Instance,
2664
- instance: HydratableInstance,
2665
- ): void;
2666
-
2667
- didNotFindHydratableContainerInstance?(parentContainer: Container, type: Type, props: Props): void;
2668
-
2669
- didNotFindHydratableContainerTextInstance?(parentContainer: Container, text: string): void;
2670
-
2671
- didNotFindHydratableContainerSuspenseInstance?(parentContainer: Container): void;
2672
-
2673
- didNotFindHydratableInstance?(
2674
- parentType: Type,
2675
- parentProps: Props,
2676
- parentInstance: Instance,
2677
- type: Type,
2678
- props: Props,
2679
- ): void;
2680
-
2681
- didNotFindHydratableTextInstance?(
2682
- parentType: Type,
2683
- parentProps: Props,
2684
- parentInstance: Instance,
2685
- text: string,
2686
- ): void;
2687
-
2688
- didNotFindHydratableSuspenseInstance?(parentType: Type, parentProps: Props, parentInstance: Instance): void;
2689
-
2690
- errorHydratingContainer?(parentContainer: Container): void;
2691
-
2692
- // Undocumented
2693
- // https://github.com/facebook/react/pull/26722
2694
- NotPendingTransition: TransitionStatus | null;
2695
- HostTransitionContext: ReactContext<TransitionStatus>;
2696
-
2697
- // https://github.com/facebook/react/pull/28751
2698
- setCurrentUpdatePriority(newPriority: EventPriority): void;
2699
- getCurrentUpdatePriority(): EventPriority;
2700
- resolveUpdatePriority(): EventPriority;
2701
-
2702
- // https://github.com/facebook/react/pull/28804
2703
- resetFormInstance(form: FormInstance): void;
2704
-
2705
- // https://github.com/facebook/react/pull/25105
2706
- requestPostPaintCallback(callback: (time: number) => void): void;
2707
-
2708
- // https://github.com/facebook/react/pull/26025
2709
- shouldAttemptEagerTransition(): boolean;
2710
-
2711
- // https://github.com/facebook/react/pull/31528
2712
- trackSchedulerEvent(): void;
2713
-
2714
- // https://github.com/facebook/react/pull/31008
2715
- resolveEventType(): null | string;
2716
- resolveEventTimeStamp(): number;
2717
-
2718
- /**
2719
- * This method is called during render to determine if the Host Component type and props require some kind of loading process to complete before committing an update.
2720
- */
2721
- maySuspendCommit(type: Type, props: Props): boolean;
2722
-
2723
- /**
2724
- * This method may be called during render if the Host Component type and props might suspend a commit. It can be used to initiate any work that might shorten the duration of a suspended commit.
2725
- */
2726
- preloadInstance(type: Type, props: Props): boolean;
2727
-
2728
- /**
2729
- * This method is called just before the commit phase. Use it to set up any necessary state while any Host Components that might suspend this commit are evaluated to determine if the commit must be suspended.
2730
- */
2731
- startSuspendingCommit(): void;
2732
-
2733
- /**
2734
- * This method is called after `startSuspendingCommit` for each Host Component that indicated it might suspend a commit.
2735
- */
2736
- suspendInstance(type: Type, props: Props): void;
2737
-
2738
- /**
2739
- * This method is called after all `suspendInstance` calls are complete.
2740
- *
2741
- * Return `null` if the commit can happen immediately.
2742
- *
2743
- * Return `(initiateCommit: Function) => Function` if the commit must be suspended. The argument to this callback will initiate the commit when called. The return value is a cancellation function that the Reconciler can use to abort the commit.
2744
- */
2745
- waitForCommitToBeReady():
2746
- | ((initiateCommit: (...args: unknown[]) => unknown) => (...args: unknown[]) => unknown)
2747
- | null;
2748
- }
2749
-
2750
- interface Thenable<T> {
2751
- then(resolve: () => T, reject?: () => T): T;
2752
- }
2753
-
2754
- type RootTag = 0 | 1 | 2;
2755
-
2756
- type WorkTag =
2757
- | 0
2758
- | 1
2759
- | 2
2760
- | 3
2761
- | 4
2762
- | 5
2763
- | 6
2764
- | 7
2765
- | 8
2766
- | 9
2767
- | 10
2768
- | 11
2769
- | 12
2770
- | 13
2771
- | 14
2772
- | 15
2773
- | 16
2774
- | 17
2775
- | 18
2776
- | 19
2777
- | 20
2778
- | 21
2779
- | 22
2780
- | 23
2781
- | 24;
2782
-
2783
- type HookType =
2784
- | "useState"
2785
- | "useReducer"
2786
- | "useContext"
2787
- | "useRef"
2788
- | "useEffect"
2789
- | "useLayoutEffect"
2790
- | "useCallback"
2791
- | "useMemo"
2792
- | "useImperativeHandle"
2793
- | "useDebugValue"
2794
- | "useDeferredValue"
2795
- | "useTransition"
2796
- | "useMutableSource"
2797
- | "useOpaqueIdentifier"
2798
- | "useCacheRefresh";
2799
-
2800
- interface Source {
2801
- fileName: string;
2802
- lineNumber: number;
2803
- }
2804
-
2805
- // TODO: Ideally these types would be opaque but that doesn't work well with
2806
- // our reconciler fork infra, since these leak into non-reconciler packages.
2807
- type LanePriority = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17;
2808
-
2809
- type Lanes = number;
2810
- type Lane = number;
2811
-
2812
- type Flags = number;
2813
-
2814
- type TypeOfMode = number;
2815
-
2816
- type EventPriority = number;
2817
-
2818
- interface ReactProvider<T> {
2819
- $$typeof: symbol | number;
2820
- type: ReactProviderType<T>;
2821
- key: null | string;
2822
- ref: null;
2823
- props: {
2824
- value: T;
2825
- children?: ReactNode;
2826
- };
2827
- }
2828
-
2829
- interface ReactProviderType<T> {
2830
- $$typeof: symbol | number;
2831
- _context: ReactContext<T>;
2832
- }
2833
-
2834
- interface ReactConsumer<T> {
2835
- $$typeof: symbol | number;
2836
- type: ReactContext<T>;
2837
- key: null | string;
2838
- ref: null;
2839
- props: {
2840
- children: (value: T) => ReactNode;
2841
- unstable_observedBits?: number;
2842
- };
2843
- }
2844
-
2845
- interface ReactContext<T> {
2846
- $$typeof: symbol | number;
2847
- Consumer: ReactContext<T>;
2848
- Provider: ReactProviderType<T>;
2849
- _currentValue: T;
2850
- _currentValue2: T;
2851
- _threadCount: number;
2852
- // DEV only
2853
- _currentRenderer?: {
2854
- [key: string]: any;
2855
- } | null;
2856
- _currentRenderer2?: {
2857
- [key: string]: any;
2858
- } | null;
2859
- // This value may be added by application code
2860
- // to improve DEV tooling display names
2861
- displayName?: string;
2862
- }
2863
-
2864
- interface ReactPortal {
2865
- $$typeof: symbol | number;
2866
- key: null | string;
2867
- containerInfo: any;
2868
- children: ReactNode;
2869
- // TODO: figure out the API for cross-renderer implementation.
2870
- implementation: any;
2871
- }
2872
-
2873
- interface RefObject {
2874
- current: any;
2875
- }
2876
-
2877
- interface ContextDependency<T> {
2878
- context: ReactContext<T>;
2879
- observedBits: number;
2880
- next: ContextDependency<unknown> | null;
2881
- }
2882
-
2883
- interface Dependencies {
2884
- lanes: Lanes;
2885
- firstContext: ContextDependency<unknown> | null;
2886
- }
2887
-
2888
- interface Fiber {
2889
- // These first fields are conceptually members of an Instance. This used to
2890
- // be split into a separate type and intersected with the other Fiber fields,
2891
- // but until Flow fixes its intersection bugs, we've merged them into a
2892
- // single type.
2893
-
2894
- // An Instance is shared between all versions of a component. We can easily
2895
- // break this out into a separate object to avoid copying so much to the
2896
- // alternate versions of the tree. We put this on a single object for now to
2897
- // minimize the number of objects created during the initial render.
2898
-
2899
- // Tag identifying the type of fiber.
2900
- tag: WorkTag;
2901
-
2902
- // Unique identifier of this child.
2903
- key: null | string;
2904
-
2905
- // The value of element.type which is used to preserve the identity during
2906
- // reconciliation of this child.
2907
- elementType: any;
2908
-
2909
- // The resolved function/class/ associated with this fiber.
2910
- type: any;
2911
-
2912
- // The local state associated with this fiber.
2913
- stateNode: any;
2914
-
2915
- // Conceptual aliases
2916
- // parent : Instance -> return The parent happens to be the same as the
2917
- // return fiber since we've merged the fiber and instance.
2918
-
2919
- // Remaining fields belong to Fiber
2920
-
2921
- // The Fiber to return to after finishing processing this one.
2922
- // This is effectively the parent, but there can be multiple parents (two)
2923
- // so this is only the parent of the thing we're currently processing.
2924
- // It is conceptually the same as the return address of a stack frame.
2925
- return: Fiber | null;
2926
-
2927
- // Singly Linked List Tree Structure.
2928
- child: Fiber | null;
2929
- sibling: Fiber | null;
2930
- index: number;
2931
-
2932
- // The ref last used to attach this node.
2933
- // I'll avoid adding an owner field for prod and model that as functions.
2934
- ref:
2935
- | null
2936
- | (((handle: unknown) => void) & {
2937
- _stringRef?: string | null;
2938
- })
2939
- | RefObject;
2940
-
2941
- // Input is the data coming into process this fiber. Arguments. Props.
2942
- pendingProps: any; // This type will be more specific once we overload the tag.
2943
- memoizedProps: any; // The props used to create the output.
2944
-
2945
- // A queue of state updates and callbacks.
2946
- updateQueue: unknown;
2947
-
2948
- // The state used to create the output
2949
- memoizedState: any;
2950
-
2951
- // Dependencies (contexts, events) for this fiber, if it has any
2952
- dependencies: Dependencies | null;
2953
-
2954
- // Bitfield that describes properties about the fiber and its subtree. E.g.
2955
- // the ConcurrentMode flag indicates whether the subtree should be async-by-
2956
- // default. When a fiber is created, it inherits the mode of its
2957
- // parent. Additional flags can be set at creation time, but after that the
2958
- // value should remain unchanged throughout the fiber's lifetime, particularly
2959
- // before its child fibers are created.
2960
- mode: TypeOfMode;
2961
-
2962
- // Effect
2963
- flags: Flags;
2964
- subtreeFlags: Flags;
2965
- deletions: Fiber[] | null;
2966
-
2967
- // Singly linked list fast path to the next fiber with side-effects.
2968
- nextEffect: Fiber | null;
2969
-
2970
- // The first and last fiber with side-effect within this subtree. This allows
2971
- // us to reuse a slice of the linked list when we reuse the work done within
2972
- // this fiber.
2973
- firstEffect: Fiber | null;
2974
- lastEffect: Fiber | null;
2975
-
2976
- lanes: Lanes;
2977
- childLanes: Lanes;
2978
-
2979
- // This is a pooled version of a Fiber. Every fiber that gets updated will
2980
- // eventually have a pair. There are cases when we can clean up pairs to save
2981
- // memory if we need to.
2982
- alternate: Fiber | null;
2983
-
2984
- // Time spent rendering this Fiber and its descendants for the current update.
2985
- // This tells us how well the tree makes use of sCU for memoization.
2986
- // It is reset to 0 each time we render and only updated when we don't bailout.
2987
- // This field is only set when the enableProfilerTimer flag is enabled.
2988
- actualDuration?: number;
2989
-
2990
- // If the Fiber is currently active in the "render" phase,
2991
- // This marks the time at which the work began.
2992
- // This field is only set when the enableProfilerTimer flag is enabled.
2993
- actualStartTime?: number;
2994
-
2995
- // Duration of the most recent render time for this Fiber.
2996
- // This value is not updated when we bailout for memoization purposes.
2997
- // This field is only set when the enableProfilerTimer flag is enabled.
2998
- selfBaseDuration?: number;
2999
-
3000
- // Sum of base times for all descendants of this Fiber.
3001
- // This value bubbles up during the "complete" phase.
3002
- // This field is only set when the enableProfilerTimer flag is enabled.
3003
- treeBaseDuration?: number;
3004
-
3005
- // Conceptual aliases
3006
- // workInProgress : Fiber -> alternate The alternate used for reuse happens
3007
- // to be the same as work in progress.
3008
- // __DEV__ only
3009
- _debugID?: number;
3010
- _debugSource?: Source | null;
3011
- _debugOwner?: Fiber | null;
3012
- _debugIsCurrentlyTiming?: boolean;
3013
- _debugNeedsRemount?: boolean;
3014
-
3015
- // Used to verify that the order of hooks does not change between renders.
3016
- _debugHookTypes?: HookType[] | null;
3017
- }
3018
-
3019
- type FiberRoot = any;
3020
-
3021
- // Concurrent related struct
3022
- type MutableSource = any;
3023
-
3024
- type OpaqueHandle = any;
3025
- type OpaqueRoot = any;
3026
-
3027
- // 0 is PROD, 1 is DEV.
3028
- // Might add PROFILE later.
3029
- type BundleType = 0 | 1;
3030
-
3031
- interface DevToolsConfig<Instance, TextInstance, RendererInspectionConfig> {
3032
- bundleType: BundleType;
3033
- version: string;
3034
- rendererPackageName: string;
3035
- // Note: this actually *does* depend on Fiber internal fields.
3036
- // Used by "inspect clicked DOM element" in React DevTools.
3037
- findFiberByHostInstance?: (instance: Instance | TextInstance) => Fiber | null;
3038
- rendererConfig?: RendererInspectionConfig;
3039
- }
3040
-
3041
- interface SuspenseHydrationCallbacks<SuspenseInstance> {
3042
- onHydrated?: (suspenseInstance: SuspenseInstance) => void;
3043
- onDeleted?: (suspenseInstance: SuspenseInstance) => void;
3044
- }
3045
-
3046
- interface TransitionTracingCallbacks {
3047
- onTransitionStart?: (transitionName: string, startTime: number) => void;
3048
- onTransitionProgress?: (
3049
- transitionName: string,
3050
- startTime: number,
3051
- currentTime: number,
3052
- pending: Array<{ name: null | string }>,
3053
- ) => void;
3054
- onTransitionIncomplete?: (
3055
- transitionName: string,
3056
- startTime: number,
3057
- deletions: Array<{
3058
- type: string;
3059
- name?: string;
3060
- newName?: string;
3061
- endTime: number;
3062
- }>,
3063
- ) => void;
3064
- onTransitionComplete?: (transitionName: string, startTime: number, endTime: number) => void;
3065
- onMarkerProgress?: (
3066
- transitionName: string,
3067
- marker: string,
3068
- startTime: number,
3069
- currentTime: number,
3070
- pending: Array<{ name: null | string }>,
3071
- ) => void;
3072
- onMarkerIncomplete?: (
3073
- transitionName: string,
3074
- marker: string,
3075
- startTime: number,
3076
- deletions: Array<{
3077
- type: string;
3078
- name?: string;
3079
- newName?: string;
3080
- endTime: number;
3081
- }>,
3082
- ) => void;
3083
- onMarkerComplete?: (transitionName: string, marker: string, startTime: number, endTime: number) => void;
3084
- }
3085
-
3086
- interface ComponentSelector {
3087
- $$typeof: symbol | number;
3088
- value: React$AbstractComponent<never, unknown>;
3089
- }
3090
-
3091
- interface HasPseudoClassSelector {
3092
- $$typeof: symbol | number;
3093
- value: Selector[];
3094
- }
3095
-
3096
- interface RoleSelector {
3097
- $$typeof: symbol | number;
3098
- value: string;
3099
- }
3100
-
3101
- interface TextSelector {
3102
- $$typeof: symbol | number;
3103
- value: string;
3104
- }
3105
-
3106
- interface TestNameSelector {
3107
- $$typeof: symbol | number;
3108
- value: string;
3109
- }
3110
-
3111
- type Selector = ComponentSelector | HasPseudoClassSelector | RoleSelector | TextSelector | TestNameSelector;
3112
-
3113
- // TODO can not find React$AbstractComponent def
3114
- type React$AbstractComponent<Config, Instance = any> = any;
3115
-
3116
- interface BoundingRect {
3117
- x: number;
3118
- y: number;
3119
- width: number;
3120
- height: number;
3121
- }
3122
-
3123
- type IntersectionObserverOptions = any;
3124
-
3125
- interface BaseErrorInfo {
3126
- componentStack?: string;
3127
- }
3128
-
3129
- interface Reconciler<Container, Instance, TextInstance, SuspenseInstance, FormInstance, PublicInstance> {
3130
- createContainer(
3131
- containerInfo: Container,
3132
- tag: RootTag,
3133
- hydrationCallbacks: null | SuspenseHydrationCallbacks<SuspenseInstance>,
3134
- isStrictMode: boolean,
3135
- concurrentUpdatesByDefaultOverride: null | boolean,
3136
- identifierPrefix: string,
3137
- onUncaughtError: (error: Error, info: BaseErrorInfo & { errorBoundary?: Component }) => void,
3138
- onCaughtError: (error: Error, info: BaseErrorInfo) => void,
3139
- onRecoverableError: (error: Error, info: BaseErrorInfo) => void,
3140
- onDefaultTransitionIndicator: () => void,
3141
- transitionCallbacks: null | TransitionTracingCallbacks,
3142
- ): OpaqueRoot;
3143
-
3144
- createPortal(
3145
- children: ReactNode,
3146
- containerInfo: any, // TODO: figure out the API for cross-renderer implementation.
3147
- implementation: any,
3148
- key?: string | null,
3149
- ): ReactPortal;
3150
-
3151
- registerMutableSourceForHydration(root: FiberRoot, mutableSource: MutableSource): void;
3152
-
3153
- createComponentSelector(component: React$AbstractComponent<never, unknown>): ComponentSelector;
3154
-
3155
- createHasPseudoClassSelector(selectors: Selector[]): HasPseudoClassSelector;
3156
-
3157
- createRoleSelector(role: string): RoleSelector;
3158
-
3159
- createTextSelector(text: string): TextSelector;
3160
-
3161
- createTestNameSelector(id: string): TestNameSelector;
3162
-
3163
- getFindAllNodesFailureDescription(hostRoot: Instance, selectors: Selector[]): string | null;
3164
-
3165
- findAllNodes(hostRoot: Instance, selectors: Selector[]): Instance[];
3166
-
3167
- findBoundingRects(hostRoot: Instance, selectors: Selector[]): BoundingRect[];
3168
-
3169
- focusWithin(hostRoot: Instance, selectors: Selector[]): boolean;
3170
-
3171
- observeVisibleRects(
3172
- hostRoot: Instance,
3173
- selectors: Selector[],
3174
- callback: (intersections: Array<{ ratio: number; rect: BoundingRect }>) => void,
3175
- options?: IntersectionObserverOptions,
3176
- ): { disconnect: () => void };
3177
-
3178
- createHydrationContainer(
3179
- initialChildren: ReactNode,
3180
- callback: (() => void) | null | undefined,
3181
- containerInfo: Container,
3182
- tag: RootTag,
3183
- hydrationCallbacks: null | SuspenseHydrationCallbacks<SuspenseInstance>,
3184
- isStrictMode: boolean,
3185
- concurrentUpdatesByDefaultOverride: null | boolean,
3186
- identifierPrefix: string,
3187
- onRecoverableError: (error: Error) => void,
3188
- transitionCallbacks: null | TransitionTracingCallbacks,
3189
- ): OpaqueRoot;
3190
-
3191
- updateContainer(
3192
- element: ReactNode,
3193
- container: OpaqueRoot,
3194
- parentComponent?: Component<any, any> | null,
3195
- callback?: (() => void) | null,
3196
- ): Lane;
3197
-
3198
- batchedUpdates<A, R>(fn: (a: A) => R, a: A): R;
3199
-
3200
- deferredUpdates<A>(fn: () => A): A;
3201
-
3202
- discreteUpdates<A, B, C, D, R>(fn: (arg0: A, arg1: B, arg2: C, arg3: D) => R, a: A, b: B, c: C, d: D): R;
3203
-
3204
- flushControlled(fn: () => any): void;
3205
-
3206
- flushSync(): void;
3207
- flushSync<R>(fn: () => R): R;
3208
-
3209
- isAlreadyRendering(): boolean;
3210
-
3211
- flushPassiveEffects(): boolean;
3212
-
3213
- getPublicRootInstance(container: OpaqueRoot): Component<any, any> | PublicInstance | null;
3214
-
3215
- attemptSynchronousHydration(fiber: Fiber): void;
3216
-
3217
- attemptDiscreteHydration(fiber: Fiber): void;
3218
-
3219
- attemptContinuousHydration(fiber: Fiber): void;
3220
-
3221
- attemptHydrationAtCurrentPriority(fiber: Fiber): void;
3222
-
3223
- getCurrentUpdatePriority(): LanePriority;
3224
-
3225
- runWithPriority<T>(priority: LanePriority, fn: () => T): T;
3226
-
3227
- findHostInstance(component: any): PublicInstance | null;
3228
-
3229
- findHostInstanceWithWarning(component: any, methodName: string): PublicInstance | null;
3230
-
3231
- findHostInstanceWithNoPortals(fiber: Fiber): PublicInstance | null;
3232
-
3233
- shouldError(fiber: Fiber): boolean | undefined;
3234
-
3235
- shouldSuspend(fiber: Fiber): boolean;
3236
-
3237
- injectIntoDevTools(devToolsConfig: DevToolsConfig<Instance, TextInstance, any>): boolean;
3238
- }
3239
- }
3240
-
3241
- declare function extend<T extends ConstructorRepresentation>(objects: T): React$1.ExoticComponent<ThreeElement<T>>;
3242
- declare function extend<T extends Catalogue>(objects: T): void;
3243
- declare const reconciler: ReactReconciler.Reconciler<RootStore, Instance<any>, void, Instance<any>, never, any>;
3244
-
3245
- declare const isRenderer: (def: any) => boolean;
3246
- interface OffscreenCanvas extends EventTarget {
3247
- }
3248
- declare const _roots: Map<HTMLCanvasElement | OffscreenCanvas, Root>;
3249
- declare function createRoot<TCanvas extends HTMLCanvasElement | OffscreenCanvas>(canvas: TCanvas): ReconcilerRoot<TCanvas>;
3250
- declare function unmountComponentAtNode<TCanvas extends HTMLCanvasElement | OffscreenCanvas>(canvas: TCanvas, callback?: (canvas: TCanvas) => void): void;
3251
- declare function createPortal(children: ReactNode, container: Object3D | RefObject<Object3D | null> | RefObject<Object3D>, state?: InjectState): JSX.Element;
3252
- interface PortalProps {
3253
- children: ReactNode;
3254
- state?: InjectState;
3255
- container: Object3D | RefObject<Object3D | null> | RefObject<Object3D>;
3256
- }
3257
- declare function Portal({ children, container, state }: PortalProps): JSX.Element;
3258
- /**
3259
- * Force React to flush any updates inside the provided callback synchronously and immediately.
3260
- * All the same caveats documented for react-dom's `flushSync` apply here (see https://react.dev/reference/react-dom/flushSync).
3261
- * Nevertheless, sometimes one needs to render synchronously, for example to keep DOM and 3D changes in lock-step without
3262
- * having to revert to a non-React solution. Note: this will only flush updates within the `Canvas` root.
3263
- */
3264
- declare function flushSync<R>(fn: () => R): R;
3265
-
3266
- declare const context: React$1.Context<RootStore>;
3267
- declare const createStore: (invalidate: (state?: RootState, frames?: number, stackFrames?: boolean) => void, advance: (timestamp: number, runGlobalEffects?: boolean, state?: RootState, frame?: XRFrame) => void) => RootStore;
3268
-
3269
- /**
3270
- * An SSR-friendly useLayoutEffect.
3271
- *
3272
- * React currently throws a warning when using useLayoutEffect on the server.
3273
- * To get around it, we can conditionally useEffect on the server (no-op) and
3274
- * useLayoutEffect elsewhere.
3275
- *
3276
- * @see https://github.com/facebook/react/issues/14927
3277
- */
3278
- declare const useIsomorphicLayoutEffect: typeof React$1.useLayoutEffect;
3279
- /**
3280
- * Creates a stable ref that always contains the latest callback.
3281
- * Useful for avoiding dependency arrays while ensuring the latest closure is called.
3282
- *
3283
- * @param fn - The callback function to wrap
3284
- * @returns A ref containing the current callback
3285
- */
3286
- declare function useMutableCallback<T>(fn: T): React$1.RefObject<T>;
3287
- /**
3288
- * Bridges renderer Context and StrictMode from a primary renderer.
3289
- * Used to maintain React context when rendering into portals or secondary canvases.
3290
- *
3291
- * @returns A Bridge component that wraps children with the parent renderer's context
3292
- */
3293
- declare function useBridge(): Bridge;
3294
- /**
3295
- * Internal component that blocks rendering until a promise resolves.
3296
- * Used for suspense-like blocking behavior.
3297
- *
3298
- * @param set - Function to set the blocking promise
3299
- */
3300
- declare function Block({ set }: Omit<UnblockProps, 'children'>): null;
3301
- /**
3302
- * Error boundary component for catching and handling errors in the React tree.
3303
- * Forwards errors to a state setter for external handling.
3304
- *
3305
- * NOTE: static members get down-level transpiled to mutations which break tree-shaking
3306
- */
3307
- declare const ErrorBoundary: {
3308
- new (props: {
3309
- set: React$1.Dispatch<Error | undefined>;
3310
- children: React$1.ReactNode;
3311
- }): {
3312
- state: {
3313
- error: boolean;
3314
- };
3315
- componentDidCatch(err: Error): void;
3316
- render(): React$1.ReactNode;
3317
- context: unknown;
3318
- setState<K extends "error">(state: {
3319
- error: boolean;
3320
- } | ((prevState: Readonly<{
3321
- error: boolean;
3322
- }>, props: Readonly<{
3323
- set: React$1.Dispatch<Error | undefined>;
3324
- children: React$1.ReactNode;
3325
- }>) => {
3326
- error: boolean;
3327
- } | Pick<{
3328
- error: boolean;
3329
- }, K> | null) | Pick<{
3330
- error: boolean;
3331
- }, K> | null, callback?: (() => void) | undefined): void;
3332
- forceUpdate(callback?: (() => void) | undefined): void;
3333
- readonly props: Readonly<{
3334
- set: React$1.Dispatch<Error | undefined>;
3335
- children: React$1.ReactNode;
3336
- }>;
3337
- componentDidMount?(): void;
3338
- shouldComponentUpdate?(nextProps: Readonly<{
3339
- set: React$1.Dispatch<Error | undefined>;
3340
- children: React$1.ReactNode;
3341
- }>, nextState: Readonly<{
3342
- error: boolean;
3343
- }>, nextContext: any): boolean;
3344
- componentWillUnmount?(): void;
3345
- getSnapshotBeforeUpdate?(prevProps: Readonly<{
3346
- set: React$1.Dispatch<Error | undefined>;
3347
- children: React$1.ReactNode;
3348
- }>, prevState: Readonly<{
3349
- error: boolean;
3350
- }>): any;
3351
- componentDidUpdate?(prevProps: Readonly<{
3352
- set: React$1.Dispatch<Error | undefined>;
3353
- children: React$1.ReactNode;
3354
- }>, prevState: Readonly<{
3355
- error: boolean;
3356
- }>, snapshot?: any): void;
3357
- componentWillMount?(): void;
3358
- UNSAFE_componentWillMount?(): void;
3359
- componentWillReceiveProps?(nextProps: Readonly<{
3360
- set: React$1.Dispatch<Error | undefined>;
3361
- children: React$1.ReactNode;
3362
- }>, nextContext: any): void;
3363
- UNSAFE_componentWillReceiveProps?(nextProps: Readonly<{
3364
- set: React$1.Dispatch<Error | undefined>;
3365
- children: React$1.ReactNode;
3366
- }>, nextContext: any): void;
3367
- componentWillUpdate?(nextProps: Readonly<{
3368
- set: React$1.Dispatch<Error | undefined>;
3369
- children: React$1.ReactNode;
3370
- }>, nextState: Readonly<{
3371
- error: boolean;
3372
- }>, nextContext: any): void;
3373
- UNSAFE_componentWillUpdate?(nextProps: Readonly<{
3374
- set: React$1.Dispatch<Error | undefined>;
3375
- children: React$1.ReactNode;
3376
- }>, nextState: Readonly<{
3377
- error: boolean;
3378
- }>, nextContext: any): void;
3379
- };
3380
- new (props: {
3381
- set: React$1.Dispatch<Error | undefined>;
3382
- children: React$1.ReactNode;
3383
- }, context: any): {
3384
- state: {
3385
- error: boolean;
3386
- };
3387
- componentDidCatch(err: Error): void;
3388
- render(): React$1.ReactNode;
3389
- context: unknown;
3390
- setState<K extends "error">(state: {
3391
- error: boolean;
3392
- } | ((prevState: Readonly<{
3393
- error: boolean;
3394
- }>, props: Readonly<{
3395
- set: React$1.Dispatch<Error | undefined>;
3396
- children: React$1.ReactNode;
3397
- }>) => {
3398
- error: boolean;
3399
- } | Pick<{
3400
- error: boolean;
3401
- }, K> | null) | Pick<{
3402
- error: boolean;
3403
- }, K> | null, callback?: (() => void) | undefined): void;
3404
- forceUpdate(callback?: (() => void) | undefined): void;
3405
- readonly props: Readonly<{
3406
- set: React$1.Dispatch<Error | undefined>;
3407
- children: React$1.ReactNode;
3408
- }>;
3409
- componentDidMount?(): void;
3410
- shouldComponentUpdate?(nextProps: Readonly<{
3411
- set: React$1.Dispatch<Error | undefined>;
3412
- children: React$1.ReactNode;
3413
- }>, nextState: Readonly<{
3414
- error: boolean;
3415
- }>, nextContext: any): boolean;
3416
- componentWillUnmount?(): void;
3417
- getSnapshotBeforeUpdate?(prevProps: Readonly<{
3418
- set: React$1.Dispatch<Error | undefined>;
3419
- children: React$1.ReactNode;
3420
- }>, prevState: Readonly<{
3421
- error: boolean;
3422
- }>): any;
3423
- componentDidUpdate?(prevProps: Readonly<{
3424
- set: React$1.Dispatch<Error | undefined>;
3425
- children: React$1.ReactNode;
3426
- }>, prevState: Readonly<{
3427
- error: boolean;
3428
- }>, snapshot?: any): void;
3429
- componentWillMount?(): void;
3430
- UNSAFE_componentWillMount?(): void;
3431
- componentWillReceiveProps?(nextProps: Readonly<{
3432
- set: React$1.Dispatch<Error | undefined>;
3433
- children: React$1.ReactNode;
3434
- }>, nextContext: any): void;
3435
- UNSAFE_componentWillReceiveProps?(nextProps: Readonly<{
3436
- set: React$1.Dispatch<Error | undefined>;
3437
- children: React$1.ReactNode;
3438
- }>, nextContext: any): void;
3439
- componentWillUpdate?(nextProps: Readonly<{
3440
- set: React$1.Dispatch<Error | undefined>;
3441
- children: React$1.ReactNode;
3442
- }>, nextState: Readonly<{
3443
- error: boolean;
3444
- }>, nextContext: any): void;
3445
- UNSAFE_componentWillUpdate?(nextProps: Readonly<{
3446
- set: React$1.Dispatch<Error | undefined>;
3447
- children: React$1.ReactNode;
3448
- }>, nextState: Readonly<{
3449
- error: boolean;
3450
- }>, nextContext: any): void;
3451
- };
3452
- getDerivedStateFromError: () => {
3453
- error: boolean;
3454
- };
3455
- contextType?: React$1.Context<any> | undefined;
3456
- propTypes?: any;
3457
- };
3458
-
3459
- /**
3460
- * React internal props that should not be passed to Three.js objects.
3461
- */
3462
- declare const REACT_INTERNAL_PROPS: string[];
3463
- /**
3464
- * Returns the instance's initial (outermost) root.
3465
- * Traverses through previousRoot links to find the original root store.
3466
- *
3467
- * @param instance - R3F instance to find root for
3468
- * @returns The outermost root store
3469
- */
3470
- declare function findInitialRoot<T>(instance: Instance<T>): RootStore;
3471
- /**
3472
- * Returns instance root state.
3473
- * If the object doesn't have __r3f (e.g., child meshes in primitives/GLTFs),
3474
- * traverses ancestors to find the nearest managed parent.
3475
- *
3476
- * @param obj - Three.js object to get root state for
3477
- * @returns Root state if found, undefined otherwise
3478
- */
3479
- declare function getRootState<T extends Object3D = Object3D>(obj: T): RootState | undefined;
3480
- /**
3481
- * Collects nodes, materials, and meshes from a Three.js Object3D hierarchy.
3482
- * Handles duplicate material names by appending UUID prefixes.
3483
- *
3484
- * @param object - Root object to traverse
3485
- * @returns ObjectMap containing named nodes, materials, and meshes
3486
- *
3487
- * @example
3488
- * const { nodes, materials, meshes } = buildGraph(gltf.scene)
3489
- * // Access by name: nodes.Head, materials.Metal, meshes.Body
3490
- */
3491
- declare function buildGraph(object: Object3D): ObjectMap;
3492
- /**
3493
- * Disposes an object and all its disposable properties.
3494
- * Skips Scene objects as they should not be disposed automatically.
3495
- *
3496
- * @param obj - Object to dispose
3497
- */
3498
- declare function dispose<T extends Disposable>(obj: T): void;
3499
- /**
3500
- * Extracts instance props from React reconciler fiber props.
3501
- * Filters out React-internal props (children, key, ref).
3502
- *
3503
- * @param queue - Pending props from reconciler fiber
3504
- * @returns Props object without React-internal keys
3505
- */
3506
- declare function getInstanceProps<T = any>(pendingProps: Record<string, unknown>): Instance<T>['props'];
3507
- /**
3508
- * Creates or retrieves an R3F instance descriptor for a Three.js object.
3509
- * Each object in the scene carries a LocalState descriptor (__r3f).
3510
- *
3511
- * @param target - Target object to prepare
3512
- * @param root - Root store for this instance
3513
- * @param type - String identifier for the object type
3514
- * @param props - Initial props for the instance
3515
- * @returns Instance descriptor
3516
- */
3517
- declare function prepare<T = any>(target: T, root: RootStore, type: string, props: Instance<T>['props']): Instance<T>;
3518
- /**
3519
- * Triggers an update for an instance.
3520
- * Calls onUpdate callback and invalidates the frame if necessary.
3521
- *
3522
- * @param instance - Instance to invalidate
3523
- */
3524
- declare function invalidateInstance(instance: Instance): void;
3525
-
3526
- /**
3527
- * Reserved prop names that should not be applied to Three.js objects.
3528
- */
3529
- declare const RESERVED_PROPS: string[];
3530
- /**
3531
- * Resolves a potentially pierced property key (e.g., 'material-color' → material.color).
3532
- * First tries the entire key as a single property, then attempts piercing.
3533
- *
3534
- * @param root - Root object to resolve from
3535
- * @param key - Property key (may contain dashes for piercing)
3536
- * @returns Object containing root, key, and target value
3537
- *
3538
- * @example
3539
- * resolve(mesh, 'material-color')
3540
- * // => { root: mesh.material, key: 'color', target: mesh.material.color }
3541
- */
3542
- declare function resolve(root: any, key: string): {
3543
- root: any;
3544
- key: string;
3545
- target: any;
3546
- };
3547
- /**
3548
- * Attaches a child instance to a parent instance.
3549
- * Handles both string-based attachment (e.g., 'geometry', 'material-map')
3550
- * and function-based attachment for custom logic.
3551
- *
3552
- * @param parent - Parent instance
3553
- * @param child - Child instance to attach
3554
- *
3555
- * @example
3556
- * // String attachment
3557
- * <bufferGeometry attach="geometry" />
3558
- * // Array attachment
3559
- * <light attach="lights-0" />
3560
- * // Function attachment
3561
- * <thing attach={(parent, self) => { parent.customProp = self }} />
3562
- */
3563
- declare function attach(parent: Instance, child: Instance): void;
3564
- /**
3565
- * Detaches a child instance from a parent instance.
3566
- * Restores the previous value or deletes the property if it was never set.
3567
- *
3568
- * @param parent - Parent instance
3569
- * @param child - Child instance to detach
3570
- */
3571
- declare function detach(parent: Instance, child: Instance): void;
3572
- /**
3573
- * Compares old and new props to determine which properties have changed.
3574
- * Also handles resetting removed props for HMR/fast-refresh.
3575
- *
3576
- * @param instance - Instance to diff props for
3577
- * @param newProps - New props to compare against
3578
- * @returns Object containing only changed props
3579
- *
3580
- * @example
3581
- * const changes = diffProps(instance, { position: [1, 2, 3], color: 'red' })
3582
- * // => { position: [1, 2, 3] } (only if position changed)
3583
- */
3584
- declare function diffProps<T = any>(instance: Instance<T>, newProps: Instance<T>['props']): Instance<T>['props'];
3585
- /**
3586
- * Applies a set of props to a Three.js object.
3587
- * Handles special cases like colors, vectors, textures, events, and pierced props.
3588
- *
3589
- * @param object - Three.js object to apply props to
3590
- * @param props - Props to apply
3591
- * @returns The object with props applied
3592
- *
3593
- * @example
3594
- * applyProps(mesh, { position: [0, 1, 0], 'material-color': 'red' })
3595
- */
3596
- declare function applyProps<T = any>(object: Instance<T>['object'], props: Instance<T>['props']): Instance<T>['object'];
3597
-
3598
- /**
3599
- * Calculates the device pixel ratio for rendering.
3600
- * Handles array DPR ranges [min, max] to clamp devicePixelRatio.
3601
- *
3602
- * @param dpr - Target DPR value or [min, max] range
3603
- * @returns Calculated DPR value
3604
- *
3605
- * @example
3606
- * calculateDpr(2) // => 2
3607
- * calculateDpr([1, 2]) // => clamps window.devicePixelRatio between 1 and 2
3608
- */
3609
- declare function calculateDpr(dpr: Dpr): number;
3610
- /**
3611
- * Extracts the first segment of a UUID string (before the first hyphen).
3612
- * Used for creating unique material names when duplicates exist.
3613
- *
3614
- * @param uuid - UUID string to extract prefix from
3615
- * @returns First segment of the UUID
3616
- *
3617
- * @example
3618
- * getUuidPrefix('a1b2c3d4-e5f6-g7h8-i9j0') // => 'a1b2c3d4'
3619
- */
3620
- declare function getUuidPrefix(uuid: string): string;
3621
- /**
3622
- * Updates camera projection based on viewport size.
3623
- * Adjusts aspect ratio for perspective cameras or bounds for orthographic cameras.
3624
- * Respects camera.manual flag - manual cameras are not modified.
3625
- *
3626
- * @param camera - Camera to update
3627
- * @param size - Current viewport size
3628
- */
3629
- declare function updateCamera(camera: ThreeCamera, size: Size): void;
3630
- /**
3631
- * Updates a frustum from a camera's projection and world matrices.
3632
- * If no target frustum is provided, creates and returns a new one.
3633
- *
3634
- * @param camera - Camera to extract frustum from
3635
- * @param frustum - Optional existing frustum to update (creates new if not provided)
3636
- * @returns The updated or newly created frustum
3637
- *
3638
- * @example
3639
- * // Create new frustum
3640
- * const frustum = updateFrustum(camera)
3641
- *
3642
- * // Update existing frustum (no allocation)
3643
- * updateFrustum(camera, existingFrustum)
3644
- *
3645
- * // Use for visibility checks
3646
- * if (frustum.containsPoint(point)) { ... }
3647
- * if (frustum.intersectsObject(mesh)) { ... }
3648
- */
3649
- declare function updateFrustum(camera: ThreeCamera, frustum?: Frustum): Frustum;
3650
-
3651
- declare const is: {
3652
- obj: (a: any) => boolean;
3653
- fun: (a: any) => a is Function;
3654
- str: (a: any) => a is string;
3655
- num: (a: any) => a is number;
3656
- boo: (a: any) => a is boolean;
3657
- und: (a: any) => boolean;
3658
- nul: (a: any) => boolean;
3659
- arr: (a: any) => a is any[];
3660
- equ(a: any, b: any, { arrays, objects, strict }?: EquConfig): boolean;
3661
- };
3662
- declare const isOrthographicCamera: (def: ThreeCamera) => def is OrthographicCamera;
3663
- declare const isRef: (obj: unknown) => obj is React.RefObject<unknown>;
3664
- declare const isColorRepresentation: (value: unknown) => value is ColorRepresentation$1;
3665
- declare const isObject3D: (object: any) => object is Object3D;
3666
- declare const isTexture: (value: unknown) => value is Texture$1;
3667
- type VectorLike = {
3668
- set: (...args: any[]) => void;
3669
- constructor?: Function;
3670
- };
3671
- declare const isVectorLike: (object: unknown) => object is VectorLike;
3672
- type Copyable = {
3673
- copy: (...args: any[]) => void;
3674
- constructor?: Function;
3675
- };
3676
- declare const isCopyable: (object: unknown) => object is Copyable;
3677
- declare const hasConstructor: (object: unknown) => object is {
3678
- constructor?: Function;
3679
- };
3680
-
3681
- /**
3682
- * Symbol marker for deferred ref resolution.
3683
- * Used to identify values that should be resolved from refs after mount.
3684
- */
3685
- declare const FROM_REF: unique symbol;
3686
- /**
3687
- * Defers prop application until the referenced object is available.
3688
- * Useful for props like `target` that need sibling refs to be populated.
3689
- *
3690
- * @param ref - React ref object to resolve at mount time
3691
- * @returns A marker value that applyProps will resolve after mount
3692
- *
3693
- * @example
3694
- * const targetRef = useRef<THREE.Object3D>(null)
3695
- *
3696
- * <group ref={targetRef} position={[-3, -2, -15]} />
3697
- * <spotLight target={fromRef(targetRef)} intensity={100} />
3698
- */
3699
- declare function fromRef<T>(ref: React$1.RefObject<T | null>): T;
3700
- /**
3701
- * Type guard to check if a value is a fromRef marker.
3702
- *
3703
- * @param value - Value to check
3704
- * @returns True if value is a fromRef marker
3705
- */
3706
- declare function isFromRef(value: unknown): value is {
3707
- [FROM_REF]: React$1.RefObject<any>;
3708
- };
3709
-
3710
- /**
3711
- * Symbol marker for mount-only method calls.
3712
- * Used to identify methods that should only be called once on initial mount.
3713
- */
3714
- declare const ONCE: unique symbol;
3715
- /**
3716
- * Marks a method call to be executed only on initial mount.
3717
- * Useful for geometry transforms that should not be reapplied on every render.
3718
- *
3719
- * When `args` prop changes (triggering reconstruction), the method will be
3720
- * called again on the new instance since appliedOnce is not carried over.
3721
- *
3722
- * @param args - Arguments to pass to the method
3723
- * @returns A marker value that applyProps will execute once
3724
- *
3725
- * @example
3726
- * // Rotate geometry on mount
3727
- * <boxGeometry args={[1, 1, 1]} rotateX={once(Math.PI / 2)} />
3728
- *
3729
- * // Multiple arguments
3730
- * <bufferGeometry applyMatrix4={once(matrix)} />
3731
- *
3732
- * // No arguments
3733
- * <geometry center={once()} />
3734
- */
3735
- declare function once<T>(...args: T[]): T;
3736
- /**
3737
- * Type guard to check if a value is a once marker.
3738
- *
3739
- * @param value - Value to check
3740
- * @returns True if value is a once marker
3741
- */
3742
- declare function isOnce(value: unknown): value is {
3743
- [ONCE]: any[] | true;
3744
- };
3745
-
3746
- /**
3747
- * A DOM canvas which accepts threejs elements as children.
3748
- * @see https://docs.pmnd.rs/react-three-fiber/api/canvas
3749
- */
3750
- declare function Canvas(props: CanvasProps): react_jsx_runtime.JSX.Element;
3751
-
3752
- /**
3753
- * ScopedStore - Type-safe wrapper for nested stores (uniforms, nodes)
3754
- *
3755
- * Provides TypeScript-friendly access to uniform/node stores where the runtime
3756
- * structure is `Record<string, T | Record<string, T>>` (leaf nodes or nested scopes).
3757
- *
3758
- * The wrapper uses a Proxy to:
3759
- * 1. Return `T` for property access (type assumption: assumes leaf node)
3760
- * 2. Provide `.scope(key)` method for explicit nested access
3761
- * 3. Support iteration methods: has(), keys(), Object.keys(), for...in
3762
- *
3763
- * @example
3764
- * ```tsx
3765
- * useLocalNodes(({ uniforms }) => ({
3766
- * wobble: sin(uniforms.uTime.mul(2)), // No cast needed!
3767
- * playerHealth: uniforms.scope('player').uHealth // Explicit scope access
3768
- * }))
3769
- * ```
3770
- */
3771
-
3772
- /** Keys reserved for methods (excluded from index signature) */
3773
- type MethodKeys = 'scope' | 'has' | 'keys';
3774
- /**
3775
- * Type-safe wrapper interface for accessing nested store data.
3776
- * Property access returns `T` (assumes leaf node).
3777
- * Use `.scope(key)` for nested object access.
3778
- *
3779
- * Uses mapped type with key filtering to exclude method names from index signature,
3780
- * allowing methods to have their correct return types.
3781
- */
3782
- type ScopedStoreType<T> = {
3783
- /** Direct property access returns the leaf type T (method keys excluded) */
3784
- readonly [K in string as K extends MethodKeys ? never : K]: T;
3785
- } & {
3786
- /** Access a nested scope by key. Returns empty wrapper if scope doesn't exist. */
3787
- scope(key: string): ScopedStoreType<T>;
3788
- /** Check if a key exists in the store */
3789
- has(key: string): boolean;
3790
- /** Get all keys in the store */
3791
- keys(): string[];
3792
- };
3793
- /**
3794
- * Create a type-safe ScopedStore wrapper around store data.
3795
- * @param data - The raw store data (uniforms or nodes from RootState)
3796
- * @returns A ScopedStoreType wrapper with type-safe access
3797
- */
3798
- declare function createScopedStore<T>(data: Record<string, any>): ScopedStoreType<T>;
3799
- /**
3800
- * State type passed to creator functions with ScopedStore wrappers.
3801
- * Provides type-safe access to uniforms, nodes, buffers, and gpuStorage without manual casting.
3802
- */
3803
- type CreatorState = Omit<RootState, 'uniforms' | 'nodes' | 'buffers' | 'gpuStorage'> & {
3804
- /** Type-safe uniform access - property access returns UniformNode */
3805
- uniforms: ScopedStoreType<UniformNode>;
3806
- /** Type-safe node access - property access returns TSLNodeType (Node | ShaderCallable | ShaderNodeObject) */
3807
- nodes: ScopedStoreType<TSLNodeType>;
3808
- /** Type-safe buffer access - property access returns BufferLike (TypedArrays, BufferAttributes, TSL nodes) */
3809
- buffers: ScopedStoreType<BufferLike>;
3810
- /** Type-safe GPU storage access - property access returns StorageLike (StorageTexture, TSL nodes) */
3811
- gpuStorage: ScopedStoreType<StorageLike>;
3812
- };
3813
-
3814
- /** Creator function that returns uniform inputs (can be raw values or UniformNodes) */
3815
- type UniformCreator<T extends UniformInputRecord = UniformInputRecord> = (state: CreatorState) => T;
3816
- /** Function signature for removeUniforms util */
3817
- type RemoveUniformsFn = (names: string | string[], scope?: string) => void;
3818
- /** Function signature for clearUniforms util */
3819
- type ClearUniformsFn = (scope?: string) => void;
3820
- /** Function signature for rebuildUniforms util */
3821
- type RebuildUniformsFn = (scope?: string) => void;
3822
- /** Return type with utils included */
3823
- type UniformsWithUtils<T extends UniformRecord = UniformRecord> = T & {
3824
- removeUniforms: RemoveUniformsFn;
3825
- clearUniforms: ClearUniformsFn;
3826
- rebuildUniforms: RebuildUniformsFn;
3827
- };
3828
- declare function useUniforms(): UniformsWithUtils<UniformRecord & Record<string, UniformRecord>>;
3829
- declare function useUniforms(scope: string): UniformsWithUtils;
3830
- declare function useUniforms<T extends UniformInputRecord>(creator: UniformCreator<T>): UniformsWithUtils<UniformRecord<UniformNode>>;
3831
- declare function useUniforms<T extends UniformInputRecord>(creator: UniformCreator<T>, scope: string): UniformsWithUtils<UniformRecord<UniformNode>>;
3832
- declare function useUniforms<T extends UniformInputRecord>(uniforms: T): UniformsWithUtils<UniformRecord<UniformNode>>;
3833
- declare function useUniforms<T extends UniformInputRecord>(uniforms: T, scope: string): UniformsWithUtils<UniformRecord<UniformNode>>;
3834
- /**
3835
- * Global rebuildUniforms function for HMR integration.
3836
- * Invalidates cached uniforms and increments _hmrVersion to trigger re-creation.
3837
- * Call this when HMR is detected to refresh all uniform creators.
3838
- *
3839
- * Resolves to the primary store so shared TSL resources rebuild on the
3840
- * authoritative store.
3841
- *
3842
- * @param store - The R3F store (from useStore or context)
3843
- * @param scope - Optional scope to rebuild ('root' for root only, string for specific scope, undefined for all)
3844
- */
3845
- declare function rebuildAllUniforms(store: ReturnType<typeof useStore>, scope?: string): void;
3846
- /**
3847
- * Remove uniforms by name from root level or a scope
3848
- * @deprecated Use `const { removeUniforms } = useUniforms()` instead
3849
- */
3850
- declare function removeUniforms(set: ReturnType<typeof useStore>['setState'], names: string[], scope?: string): void;
3851
- /**
3852
- * Clear all uniforms from a scope (removes the entire scope object)
3853
- * @deprecated Use `const { clearUniforms } = useUniforms()` instead
3854
- */
3855
- declare function clearScope(set: ReturnType<typeof useStore>['setState'], scope: string): void;
3856
- /**
3857
- * Clear all root-level uniforms (preserves scopes)
3858
- * @deprecated Use `const { clearUniforms } = useUniforms()` with `clearUniforms('root')` instead
3859
- */
3860
- declare function clearRootUniforms(set: ReturnType<typeof useStore>['setState']): void;
3861
-
3862
- /**
3863
- * Supported uniform value types:
3864
- * - Raw values: number, boolean, Vector2, Vector3, Vector4, Color, Matrix3, Matrix4
3865
- * - String colors: '#ff0000', 'red', 'rgb(255,0,0)' (auto-converted to Color)
3866
- * - TSL nodes: color(), vec3(), float(), etc. (for type casting)
3867
- * - UniformNode: existing uniforms (reused as-is)
3868
- */
3869
- type UniformValue = number | boolean | string | Vector2$1 | Vector3$1 | Vector4$1 | Color$2 | Matrix3$1 | Matrix4$1 | Node | UniformNode;
3870
- /**
3871
- * Widen literal types to their base types:
3872
- * - 0 → number
3873
- * - true → boolean
3874
- * - '#ff0000' → Color (string colors are converted to Color objects)
3875
- * - Node → Node (TSL nodes passed through for uniform type casting)
3876
- */
3877
- type Widen<T> = T extends number ? number : T extends boolean ? boolean : T extends string ? Color$2 : T;
3878
- declare function useUniform<T extends UniformValue>(name: string): UniformNode<T>;
3879
- declare function useUniform<T extends UniformValue>(name: string, value: T): UniformNode<Widen<T>>;
3880
-
3881
- /**
3882
- * Minimal interface for TSL nodes.
3883
- * Used instead of Three.js's Node type because the @types/three definitions
3884
- * have inconsistencies where OperatorNode, ConstNode, etc. don't properly
3885
- * extend Node with all required properties.
3886
- */
3887
- interface TSLNodeLike {
3888
- uuid?: string;
3889
- nodeType?: string | null;
3890
- /** label method for chaining - sets the node's label and returns self */
3891
- label?: ((label: string) => TSLNodeLike) | string;
3892
- setName?: (name: string) => this;
11
+ import { JSX } from 'react';
12
+ import 'react-use-measure';
13
+ import 'react/jsx-runtime';
14
+ import 'zustand/traditional';
15
+ import 'three/tsl';
16
+
17
+ /**
18
+ * The `ReactThreeFiber` namespace of the WebGPU entry: the shared element types plus this entry's JSX map.
19
+ *
20
+ * Explicit aliases, not `export type *`: rollup-dts otherwise re-exports the types as namespace values
21
+ * and the built declaration fails to compile for consumers.
22
+ */
23
+
24
+
25
+ type MutableOrReadonlyParameters<T extends (...args: any) => any> = MutableOrReadonlyParameters$1<T>
26
+ type MathRepresentation = MathRepresentation$1
27
+ type VectorRepresentation = VectorRepresentation$1
28
+ type MathTypes = MathTypes$1
29
+ type MathType<T extends MathTypes$1> = MathType$1<T>
30
+ type MathProps<P> = MathProps$1<P>
31
+ type Vector2 = Vector2$1
32
+ type Vector3 = Vector3$1
33
+ type Vector4 = Vector4$1
34
+ type Color = Color$1
35
+ type Layers = Layers$1
36
+ type Quaternion = Quaternion$1
37
+ type Euler = Euler$1
38
+ type Matrix3 = Matrix3$1
39
+ type Matrix4 = Matrix4$1
40
+ type RaycastableRepresentation = RaycastableRepresentation$1
41
+ type EventProps<P> = EventProps$1<P>
42
+ type GeometryTransformProps = GeometryTransformProps$1
43
+ type GeometryProps<P> = GeometryProps$1<P>
44
+ type TSLNodeInput = TSLNodeInput$1
45
+ type NodeProps<P> = NodeProps$1<P>
46
+ type ReactProps<P> = ReactProps$1<P>
47
+ type ElementProps<T extends ConstructorRepresentation, P = InstanceType<T>> = ElementProps$1<T, P>
48
+ type ThreeElement<T extends ConstructorRepresentation> = ThreeElement$1<T>
49
+ type ThreeToJSXElements<T extends Record<string, any>> = ThreeToJSXElements$1<T>
50
+ type Object3DMethod = Object3DMethod$1
51
+ type ThreeElementsOf<T extends Record<string, any>> = ThreeElementsOf$1<T>
52
+ type ElementOf<E, K extends string> = ElementOf$1<E, K>
53
+
54
+ type webgpu_d_Color = Color;
55
+ type webgpu_d_ElementOf<E, K extends string> = ElementOf<E, K>;
56
+ type webgpu_d_ElementProps<T extends ConstructorRepresentation, P = InstanceType<T>> = ElementProps<T, P>;
57
+ type webgpu_d_Euler = Euler;
58
+ type webgpu_d_EventProps<P> = EventProps<P>;
59
+ type webgpu_d_GeometryProps<P> = GeometryProps<P>;
60
+ type webgpu_d_GeometryTransformProps = GeometryTransformProps;
61
+ type webgpu_d_Layers = Layers;
62
+ type webgpu_d_MathProps<P> = MathProps<P>;
63
+ type webgpu_d_MathRepresentation = MathRepresentation;
64
+ type webgpu_d_MathType<T extends MathTypes$1> = MathType<T>;
65
+ type webgpu_d_MathTypes = MathTypes;
66
+ type webgpu_d_Matrix3 = Matrix3;
67
+ type webgpu_d_Matrix4 = Matrix4;
68
+ type webgpu_d_MutableOrReadonlyParameters<T extends (...args: any) => any> = MutableOrReadonlyParameters<T>;
69
+ type webgpu_d_NodeProps<P> = NodeProps<P>;
70
+ type webgpu_d_Object3DMethod = Object3DMethod;
71
+ type webgpu_d_Quaternion = Quaternion;
72
+ type webgpu_d_RaycastableRepresentation = RaycastableRepresentation;
73
+ type webgpu_d_ReactProps<P> = ReactProps<P>;
74
+ type webgpu_d_TSLNodeInput = TSLNodeInput;
75
+ type webgpu_d_ThreeElement<T extends ConstructorRepresentation> = ThreeElement<T>;
76
+ type webgpu_d_ThreeElements = ThreeElements;
77
+ type webgpu_d_ThreeElementsOf<T extends Record<string, any>> = ThreeElementsOf<T>;
78
+ type webgpu_d_ThreeExports = ThreeExports;
79
+ type webgpu_d_ThreeToJSXElements<T extends Record<string, any>> = ThreeToJSXElements<T>;
80
+ type webgpu_d_Vector2 = Vector2;
81
+ type webgpu_d_Vector3 = Vector3;
82
+ type webgpu_d_Vector4 = Vector4;
83
+ type webgpu_d_VectorRepresentation = VectorRepresentation;
84
+ declare namespace webgpu_d {
85
+ export type { webgpu_d_Color as Color, webgpu_d_ElementOf as ElementOf, webgpu_d_ElementProps as ElementProps, webgpu_d_Euler as Euler, webgpu_d_EventProps as EventProps, webgpu_d_GeometryProps as GeometryProps, webgpu_d_GeometryTransformProps as GeometryTransformProps, webgpu_d_Layers as Layers, webgpu_d_MathProps as MathProps, webgpu_d_MathRepresentation as MathRepresentation, webgpu_d_MathType as MathType, webgpu_d_MathTypes as MathTypes, webgpu_d_Matrix3 as Matrix3, webgpu_d_Matrix4 as Matrix4, webgpu_d_MutableOrReadonlyParameters as MutableOrReadonlyParameters, webgpu_d_NodeProps as NodeProps, webgpu_d_Object3DMethod as Object3DMethod, webgpu_d_Quaternion as Quaternion, webgpu_d_RaycastableRepresentation as RaycastableRepresentation, webgpu_d_ReactProps as ReactProps, webgpu_d_TSLNodeInput as TSLNodeInput, webgpu_d_ThreeElement as ThreeElement, webgpu_d_ThreeElements as ThreeElements, webgpu_d_ThreeElementsOf as ThreeElementsOf, webgpu_d_ThreeExports as ThreeExports, webgpu_d_ThreeToJSXElements as ThreeToJSXElements, webgpu_d_Vector2 as Vector2, webgpu_d_Vector3 as Vector3, webgpu_d_Vector4 as Vector4, webgpu_d_VectorRepresentation as VectorRepresentation };
3893
86
  }
3894
- /** TSL node type - alias for compatibility */
3895
- type TSLNode = TSLNodeLike;
3896
- /**
3897
- * A record of TSL nodes - allows mixed node types (OperatorNode, ConstNode, etc.)
3898
- * Uses TSLNodeLike for broader compatibility with Three.js's TSL type definitions.
3899
- */
3900
- type NodeRecord<T extends TSLNodeLike = TSLNodeLike> = Record<string, T>;
3901
- /**
3902
- * Creator function that returns a record of nodes.
3903
- * Uses TSLNodeLike constraint to allow mixed node types
3904
- * (e.g., { n: OperatorNode; color: ConstNode<Color> }) to pass type checking.
3905
- */
3906
- type NodeCreator<T extends Record<string, TSLNodeLike>> = (state: CreatorState) => T;
3907
- /** Function signature for removeNodes util */
3908
- type RemoveNodesFn = (names: string | string[], scope?: string) => void;
3909
- /** Function signature for clearNodes util */
3910
- type ClearNodesFn = (scope?: string) => void;
3911
- /** Function signature for rebuildNodes util */
3912
- type RebuildNodesFn = (scope?: string) => void;
3913
- /** Return type with utils included */
3914
- type NodesWithUtils<T extends Record<string, TSLNodeLike> = Record<string, TSLNodeLike>> = T & {
3915
- removeNodes: RemoveNodesFn;
3916
- clearNodes: ClearNodesFn;
3917
- rebuildNodes: RebuildNodesFn;
3918
- };
3919
- declare function useNodes(): NodesWithUtils<Record<string, TSLNodeLike> & Record<string, Record<string, TSLNodeLike>>>;
3920
- declare function useNodes(scope: string): NodesWithUtils<Record<string, TSLNodeLike>>;
3921
- declare function useNodes<T extends Record<string, TSLNodeLike>>(creator: NodeCreator<T>): NodesWithUtils<T>;
3922
- declare function useNodes<T extends Record<string, TSLNodeLike>>(creator: NodeCreator<T>, scope: string): NodesWithUtils<T>;
3923
- /**
3924
- * Global rebuildNodes function for HMR integration.
3925
- * Invalidates cached nodes and increments _hmrVersion to trigger re-creation.
3926
- * Call this when HMR is detected to refresh all node creators.
3927
- *
3928
- * Resolves to the primary store so shared TSL resources rebuild on the
3929
- * authoritative store.
3930
- *
3931
- * @param store - The R3F store (from useStore or context)
3932
- * @param scope - Optional scope to rebuild ('root' for root only, string for specific scope, undefined for all)
3933
- */
3934
- declare function rebuildAllNodes(store: ReturnType<typeof useStore>, scope?: string): void;
3935
- /**
3936
- * Remove nodes by name from root level or a scope
3937
- * @deprecated Use `const { removeNodes } = useNodes()` instead
3938
- */
3939
- declare function removeNodes(set: ReturnType<typeof useStore>['setState'], names: string[], scope?: string): void;
3940
- /**
3941
- * Clear all nodes from a scope (removes the entire scope object)
3942
- * @deprecated Use `const { clearNodes } = useNodes()` instead
3943
- */
3944
- declare function clearNodeScope(set: ReturnType<typeof useStore>['setState'], scope: string): void;
3945
- /**
3946
- * Clear all root-level nodes (preserves scopes)
3947
- * @deprecated Use `const { clearNodes } = useNodes()` with `clearNodes('root')` instead
3948
- */
3949
- declare function clearRootNodes(set: ReturnType<typeof useStore>['setState']): void;
3950
-
3951
- /** Creator receives CreatorState with ScopedStore wrappers for type-safe access. Returns any record. */
3952
- type LocalNodeCreator<T extends Record<string, unknown>> = (state: CreatorState) => T;
3953
- /**
3954
- * Creates local values that rebuild when uniforms, nodes, or textures change.
3955
- *
3956
- * Unlike `useNodes`, this does NOT register to the global store.
3957
- * Use for component-specific nodes/values that depend on shared resources.
3958
- *
3959
- * @example
3960
- * ```tsx
3961
- * // Destructure what you need from state
3962
- * const { wobble, uTime } = useLocalNodes(({ uniforms, nodes }) => ({
3963
- * wobble: sin(uniforms.uTime.mul(2)),
3964
- * uTime: uniforms.uTime, // can return uniforms too
3965
- * }))
3966
- *
3967
- * // Or access anything else from RootState
3968
- * const { scaled } = useLocalNodes(({ camera, nodes }) => ({
3969
- * scaled: nodes.basePos.mul(camera.zoom),
3970
- * }))
3971
- *
3972
- * // Type-safe uniform access
3973
- * const { colorNode } = useLocalNodes(({ uniforms }) => {
3974
- * const uValue = uniforms.myUniform as UniformNode<number>
3975
- * return { colorNode: mix(colorA, colorB, uValue) }
3976
- * })
3977
- * ```
3978
- */
3979
- declare function useLocalNodes<T extends Record<string, unknown>>(creator: LocalNodeCreator<T>): T;
3980
-
3981
- /**
3982
- * Creator function that returns a record of buffers.
3983
- * Receives CreatorState with access to existing buffers, gpuStorage, uniforms, nodes, etc.
3984
- */
3985
- type BufferCreator<T extends Record<string, BufferLike>> = (state: CreatorState) => T;
3986
- /** Function signature for removeBuffers util */
3987
- type RemoveBuffersFn = (names: string | string[], scope?: string) => void;
3988
- /** Function signature for clearBuffers util */
3989
- type ClearBuffersFn = (scope?: string) => void;
3990
- /** Function signature for rebuildBuffers util */
3991
- type RebuildBuffersFn = (scope?: string) => void;
3992
- /** Function signature for disposeBuffers util - releases GPU resources */
3993
- type DisposeBuffersFn = (names: string | string[], scope?: string) => void;
3994
- /** Return type with utils included */
3995
- type BuffersWithUtils<T extends Record<string, BufferLike> = Record<string, BufferLike>> = T & {
3996
- removeBuffers: RemoveBuffersFn;
3997
- clearBuffers: ClearBuffersFn;
3998
- rebuildBuffers: RebuildBuffersFn;
3999
- disposeBuffers: DisposeBuffersFn;
4000
- };
4001
- declare function useBuffers(): BuffersWithUtils<Record<string, BufferLike> & Record<string, Record<string, BufferLike>>>;
4002
- declare function useBuffers(scope: string): BuffersWithUtils<Record<string, BufferLike>>;
4003
- declare function useBuffers<T extends Record<string, BufferLike>>(creator: BufferCreator<T>): BuffersWithUtils<T>;
4004
- declare function useBuffers<T extends Record<string, BufferLike>>(creator: BufferCreator<T>, scope: string): BuffersWithUtils<T>;
4005
- /**
4006
- * Global rebuildBuffers function for HMR integration.
4007
- * Invalidates cached buffers and increments _hmrVersion to trigger re-creation.
4008
- * Call this when HMR is detected to refresh all buffer creators.
4009
- *
4010
- * Resolves to the primary store so shared TSL resources rebuild on the
4011
- * authoritative store.
4012
- *
4013
- * @param store - The R3F store (from useStore or context)
4014
- * @param scope - Optional scope to rebuild ('root' for root only, string for specific scope, undefined for all)
4015
- */
4016
- declare function rebuildAllBuffers(store: ReturnType<typeof useStore>, scope?: string): void;
4017
-
4018
- /**
4019
- * Creator function that returns a record of GPU storage objects.
4020
- * Receives CreatorState with access to existing buffers, gpuStorage, uniforms, nodes, etc.
4021
- */
4022
- type StorageCreator<T extends Record<string, StorageLike>> = (state: CreatorState) => T;
4023
- /** Function signature for removeStorage util */
4024
- type RemoveStorageFn = (names: string | string[], scope?: string) => void;
4025
- /** Function signature for clearStorage util */
4026
- type ClearStorageFn = (scope?: string) => void;
4027
- /** Function signature for rebuildStorage util */
4028
- type RebuildStorageFn = (scope?: string) => void;
4029
- /** Function signature for disposeStorage util - releases GPU resources */
4030
- type DisposeStorageFn = (names: string | string[], scope?: string) => void;
4031
- /** Return type with utils included */
4032
- type StorageWithUtils<T extends Record<string, StorageLike> = Record<string, StorageLike>> = T & {
4033
- removeStorage: RemoveStorageFn;
4034
- clearStorage: ClearStorageFn;
4035
- rebuildStorage: RebuildStorageFn;
4036
- disposeStorage: DisposeStorageFn;
4037
- };
4038
- declare function useGPUStorage(): StorageWithUtils<Record<string, StorageLike> & Record<string, Record<string, StorageLike>>>;
4039
- declare function useGPUStorage(scope: string): StorageWithUtils<Record<string, StorageLike>>;
4040
- declare function useGPUStorage<T extends Record<string, StorageLike>>(creator: StorageCreator<T>): StorageWithUtils<T>;
4041
- declare function useGPUStorage<T extends Record<string, StorageLike>>(creator: StorageCreator<T>, scope: string): StorageWithUtils<T>;
4042
- /**
4043
- * Global rebuildStorage function for HMR integration.
4044
- * Invalidates cached storage and increments _hmrVersion to trigger re-creation.
4045
- * Call this when HMR is detected to refresh all storage creators.
4046
- *
4047
- * Resolves to the primary store so shared TSL resources rebuild on the
4048
- * authoritative store.
4049
- *
4050
- * @param store - The R3F store (from useStore or context)
4051
- * @param scope - Optional scope to rebuild ('root' for root only, string for specific scope, undefined for all)
4052
- */
4053
- declare function rebuildAllStorage(store: ReturnType<typeof useStore>, scope?: string): void;
4054
87
 
4055
88
  /**
4056
89
  * Re-export from core - useTextures is now a core R3F hook (a reactive Texture registry).
@@ -4062,12 +95,12 @@ declare function rebuildAllStorage(store: ReturnType<typeof useStore>, scope?: s
4062
95
  * @deprecated The registry now stores plain `Texture` objects, not TSL nodes. Use `Texture` directly.
4063
96
  * Kept as an alias for backwards compatibility.
4064
97
  */
4065
- type TextureEntry = Texture$1;
98
+ type TextureEntry = Texture;
4066
99
  /**
4067
100
  * @deprecated The registry now stores plain `Texture` objects, not TSL nodes. Use `Texture` directly.
4068
101
  * Kept as an alias for backwards compatibility.
4069
102
  */
4070
- type TextureNode = Texture$1;
103
+ type TextureNode = Texture;
4071
104
 
4072
105
  interface TextureOperations {
4073
106
  add: (key: string, value: any) => void;
@@ -4077,45 +110,6 @@ interface TextureOperations {
4077
110
  }
4078
111
  declare function createTextureOperations(set: StoreApi<RootState>['setState']): TextureOperations;
4079
112
 
4080
- /**
4081
- * Hook for managing WebGPU RenderPipeline with automatic scenePass setup.
4082
- *
4083
- * Features:
4084
- * - Creates RenderPipeline instance if not exists
4085
- * - Creates default scenePass (no MRT) automatically
4086
- * - Callbacks receive full RootState for flexibility
4087
- * - No auto-cleanup on unmount - use reset() for explicit cleanup
4088
- * - Scene/camera changes trigger scenePass recreation
4089
- *
4090
- * @param mainCB - Main callback to configure outputNode and create effect passes
4091
- * @param setupCB - Optional setup callback to configure MRT on scenePass
4092
- * @returns { passes, renderPipeline, clearPasses, reset, rebuild }
4093
- *
4094
- * @example
4095
- * ```tsx
4096
- * // Simple effect
4097
- * useRenderPipeline(({ renderPipeline, passes }) => {
4098
- * renderPipeline.outputNode = bloom(passes.scenePass.getTextureNode())
4099
- * })
4100
- *
4101
- * // With MRT setup
4102
- * useRenderPipeline(
4103
- * ({ renderPipeline, passes }) => {
4104
- * const beauty = passes.scenePass.getTextureNode().toInspector('Color')
4105
- * const vel = passes.scenePass.getTextureNode('velocity')
4106
- * renderPipeline.outputNode = motionBlur(beauty, vel)
4107
- * },
4108
- * ({ passes }) => {
4109
- * passes.scenePass.setMRT(mrt({ output, velocity }))
4110
- * }
4111
- * )
4112
- *
4113
- * // Read-only access
4114
- * const { renderPipeline, passes } = useRenderPipeline()
4115
- * ```
4116
- */
4117
- declare function useRenderPipeline(mainCB?: RenderPipelineMainCallback, setupCB?: RenderPipelineSetupCallback): UseRenderPipelineReturn;
4118
-
4119
113
  //* Renderer Props ========================================
4120
114
 
4121
115
  type WebGPUDefaultProps = Omit<WebGPURendererParameters, 'canvas'> & BaseRendererProps
@@ -4163,5 +157,46 @@ interface WebGPURootState extends Omit<RootState, 'renderer' | 'gl' | 'internal'
4163
157
  internal: WebGPUInternalState
4164
158
  }
4165
159
 
4166
- export { Block, Canvas, Environment, EnvironmentCube, EnvironmentMap, EnvironmentPortal, ErrorBoundary, FROM_REF, IsObject, ONCE, Portal, R3F_BUILD_LEGACY, R3F_BUILD_WEBGPU, REACT_INTERNAL_PROPS, RESERVED_PROPS, three_d as ReactThreeFiber, Texture, _roots, addAfterEffect, addEffect, addTail, advance, applyProps, attach, buildGraph, calculateDpr, clearNodeScope, clearRootNodes, clearRootUniforms, clearScope, context, createEvents, createPointerEvents, createPortal, createRoot, createScopedStore, createStore, createTextureOperations, detach, diffProps, dispose, createPointerEvents as events, extend, findInitialRoot, flushSync, fromRef, getInstanceProps, getPrimary, getPrimaryIds, getRootState, getUuidPrefix, hasConstructor, hasPrimary, invalidate, invalidateInstance, is, isColorRepresentation, isCopyable, isFromRef, isObject3D, isOnce, isOrthographicCamera, isRef, isRenderer, isTexture, isVectorLike, once, prepare, presetsObj, rebuildAllBuffers, rebuildAllNodes, rebuildAllStorage, rebuildAllUniforms, reconciler, registerPrimary, removeInteractivity, removeNodes, removeUniforms, resolve, swapInteractivity, unmountComponentAtNode, unregisterPrimary, updateCamera, updateFrustum, useBridge, useBuffers, useEnvironment, useFrame, useGPUStorage, useGraph, useInstanceHandle, useIsomorphicLayoutEffect, useLoader, useLocalNodes, useMutableCallback, useNodes, useRenderPipeline, useRenderTarget, useStore, useTexture, useTextures, useThree, useUniform, useUniforms, waitForPrimary };
4167
- export type { Act, Args, ArgsProp, AttachFnType, AttachType, BackgroundConfig, BackgroundProp, BaseRendererProps, Bridge, BufferCreator, BufferLike, BufferRecord, BufferStore, BuffersWithUtils, Camera, CameraProps, CanvasProps, CanvasSchedulerConfig, Catalogue, ClearBuffersFn, ClearNodesFn, ClearStorageFn, ClearUniformsFn, Color, ColorManagementConfig, ComputeFunction, ConstructorRepresentation, CreatorState, DefaultGLProps, DefaultRendererProps, Disposable, DisposeBuffersFn, DisposeOptions, DisposeStorageFn, DomEvent, Dpr, ElementProps, EnvironmentLoaderProps, EnvironmentProps, EquConfig, Euler, EventHandlers, EventManager, EventProps, Events, Extensions, FiberRoot, FilterFunction, FrameCallback, FrameNextCallback, FrameNextState, FrameState, Frameloop, GLProps, GLTFLike, GeometryProps, GeometryTransformProps, GlobalEffectType, GlobalRenderCallback, HostConfig, InferLoadResult, InjectState, InputLike, Instance, InstanceProps, WebGPUInternalState as InternalState, Intersection, IntersectionEvent, IsAllOptional, IsOptional, Layers, LegacyInternalState, LegacyRenderer, LegacyRootState, LoaderInstance, LoaderLike, LoaderResult, LocalNodeCreator, MappedTextureType, MathProps, MathRepresentation, MathType, MathTypes, Matrix3, Matrix4, Mutable, MutableOrReadonlyParameters, NodeCreator, NodeProps, NodeRecord, NodesWithUtils, NonFunctionKeys, ObjectMap, OffscreenCanvas$1 as OffscreenCanvas, Overwrite, Performance, PointerCaptureTarget, PointerState, PresetsType, PrimaryCanvasEntry, Properties, Quaternion, WebGPUR3FRenderer as R3FRenderer, RaycastableRepresentation, ReactProps, RebuildBuffersFn, RebuildNodesFn, RebuildStorageFn, RebuildUniformsFn, ReconcilerRoot, RemoveBuffersFn, RemoveNodesFn, RemoveStorageFn, RemoveUniformsFn, RenderCallback, RenderProps, RenderTargetOptions, Renderer, RendererConfigExtended, RendererFactory, RendererProps, Root, WebGPURootState as RootState, RootStore, ScopedStoreType, SetBlock, Size, StorageCreator, StorageLike, StorageRecord, StorageStore, StorageWithUtils, Subscription, TSLNode, TSLNodeInput, TextureEntry, TextureInput, TextureNode, TextureOperations, TextureResult, ThreeCamera, ThreeElement, ThreeElements, ThreeElementsImpl, ThreeEvent, ThreeExports, ThreeToJSXElements, UnblockProps, UniformCreator, UniformValue, UniformsWithUtils, UseTextureOptions, UseTexturesReturn, Vector2, Vector3, Vector4, VectorRepresentation, Viewport, VisibilityEntry, WebGLDefaultProps, WebGLProps, WebGLShadowConfig, WebGPUDefaultProps, WebGPUProps, WebGPUShadowConfig, XRManager, XRPointerConfig };
160
+ declare const R3F_BUILD_LEGACY = false;
161
+ declare const R3F_BUILD_WEBGPU = true;
162
+ /** Create a root that always constructs a WebGPURenderer. */
163
+ declare function createRoot<TCanvas extends HTMLCanvasElement | OffscreenCanvas>(canvas: TCanvas): ReconcilerRoot<TCanvas>;
164
+
165
+ /** `useThree` narrowed to WebGPU state — `state.renderer` is a `WebGPURenderer`. */
166
+ type UseThreeWebGPU = <T = WebGPURootState>(selector?: (state: WebGPURootState) => T, equalityFn?: <U>(state: U, newState: U) => boolean) => T;
167
+ /** `useFrame` narrowed to WebGPU state — the callback's `state.renderer` is a `WebGPURenderer`. */
168
+ type UseFrameWebGPU = (callback?: FrameCallback<WebGPURootState>, priorityOrOptions?: number | UseFrameNextOptions) => FrameNextControls;
169
+ declare const useThree: UseThreeWebGPU;
170
+ declare const useFrame: UseFrameWebGPU;
171
+ /** `useRenderTarget` narrowed to the target this entry's renderer produces. */
172
+ declare const useRenderTarget: {
173
+ (options?: RenderTargetOptions): RenderTarget;
174
+ (size: number, options?: RenderTargetOptions): RenderTarget;
175
+ (width: number, height: number, options?: RenderTargetOptions): RenderTarget;
176
+ };
177
+
178
+ /** Canvas props on the WebGPU entry: `onCreated` receives `WebGPURootState`. */
179
+ type WebGPUCanvasProps = Omit<CanvasProps, 'onCreated'> & {
180
+ /** Callback after the canvas has rendered (but not yet committed); `state.renderer` is a `WebGPURenderer` */
181
+ onCreated?: (state: WebGPURootState) => void;
182
+ };
183
+
184
+ /**
185
+ * A DOM canvas which accepts threejs elements as children, rendered with WebGPU. `onCreated` is
186
+ * typed against `WebGPURootState`.
187
+ * @see https://docs.pmnd.rs/react-three-fiber/api/canvas
188
+ */
189
+ declare const Canvas: (props: WebGPUCanvasProps) => JSX.Element;
190
+ /** Three.js constructors available as JSX elements on this entry. */
191
+ type ThreeExports = typeof ThreeWebGPU;
192
+ interface ThreeElements extends ThreeElementsOf$1<ThreeExports> {
193
+ }
194
+ declare module 'react' {
195
+ namespace JSX {
196
+ interface IntrinsicElements extends ThreeElements {
197
+ }
198
+ }
199
+ }
200
+
201
+ export { BaseRendererProps, RootState as BaseRootState, Canvas, Color$1 as Color, ConstructorRepresentation, ElementOf$1 as ElementOf, ElementProps$1 as ElementProps, Euler$1 as Euler, EventProps$1 as EventProps, GeometryProps$1 as GeometryProps, GeometryTransformProps$1 as GeometryTransformProps, Layers$1 as Layers, MathProps$1 as MathProps, MathRepresentation$1 as MathRepresentation, MathType$1 as MathType, MathTypes$1 as MathTypes, Matrix3$1 as Matrix3, Matrix4$1 as Matrix4, MutableOrReadonlyParameters$1 as MutableOrReadonlyParameters, NodeProps$1 as NodeProps, Object3DMethod$1 as Object3DMethod, Properties, Quaternion$1 as Quaternion, R3F_BUILD_LEGACY, R3F_BUILD_WEBGPU, RaycastableRepresentation$1 as RaycastableRepresentation, ReactProps$1 as ReactProps, webgpu_d as ReactThreeFiber, ReconcilerRoot, RenderTargetOptions, RendererFactory, TSLNodeInput$1 as TSLNodeInput, ThreeElement$1 as ThreeElement, ThreeElementsOf$1 as ThreeElementsOf, ThreeToJSXElements$1 as ThreeToJSXElements, Vector2$1 as Vector2, Vector3$1 as Vector3, Vector4$1 as Vector4, VectorRepresentation$1 as VectorRepresentation, createRoot, createTextureOperations, useFrame, useRenderTarget, useThree };
202
+ export type { WebGPUCanvasProps as CanvasProps, WebGPUInternalState as InternalState, WebGPUR3FRenderer as R3FRenderer, WebGPURootState as RootState, TextureEntry, TextureNode, TextureOperations, ThreeElements, ThreeExports, UseFrameWebGPU, UseThreeWebGPU, WebGPUCanvasProps, WebGPUDefaultProps, WebGPUProps, WebGPUShadowConfig };