@react-three/fiber 10.0.0-canary.2c50459 → 10.0.0-canary.2e64646

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