@react-three/fiber 10.0.0-canary.de17310 → 10.0.0-canary.e3891fb

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 (38) 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 +8 -273
  6. package/dist/extension.d.cts +14 -624
  7. package/dist/extension.d.mts +14 -624
  8. package/dist/extension.d.ts +14 -624
  9. package/dist/extension.mjs +1 -258
  10. package/dist/index.cjs +97 -15406
  11. package/dist/index.d.cts +121 -3574
  12. package/dist/index.d.mts +121 -3574
  13. package/dist/index.d.ts +121 -3546
  14. package/dist/index.mjs +10 -15305
  15. package/dist/legacy.cjs +97 -15364
  16. package/dist/legacy.d.cts +111 -3545
  17. package/dist/legacy.d.mts +111 -3545
  18. package/dist/legacy.d.ts +111 -3519
  19. package/dist/legacy.mjs +12 -15264
  20. package/dist/shared/fiber.2dyldILT.d.mts +2775 -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.C4GU39Za.d.ts +2775 -0
  24. package/dist/shared/fiber.Cg2YRc54.d.cts +2775 -0
  25. package/dist/shared/fiber.Cx-UAmMb.d.ts +48 -0
  26. package/dist/shared/fiber.DAl4H27x.d.cts +48 -0
  27. package/dist/shared/fiber.I5Q4dVvl.d.cts +778 -0
  28. package/dist/shared/fiber.I5Q4dVvl.d.mts +778 -0
  29. package/dist/shared/fiber.I5Q4dVvl.d.ts +778 -0
  30. package/dist/shared/fiber.L0cJPxh2.cjs +15151 -0
  31. package/dist/shared/fiber.UW5CRgts.mjs +15053 -0
  32. package/dist/shared/fiber.khFlPHPf.cjs +397 -0
  33. package/dist/webgpu/index.cjs +101 -15399
  34. package/dist/webgpu/index.d.cts +113 -3555
  35. package/dist/webgpu/index.d.mts +113 -3555
  36. package/dist/webgpu/index.d.ts +113 -3527
  37. package/dist/webgpu/index.mjs +17 -15300
  38. package/package.json +1 -3
@@ -0,0 +1,2775 @@
1
+ import * as React$1 from 'react';
2
+ import { ReactNode, Component, RefObject, JSX } from 'react';
3
+ import { Options } from 'react-use-measure';
4
+ import * as THREE from 'three';
5
+ import { ColorRepresentation, Euler as Euler$1, Loader, RenderTargetOptions as RenderTargetOptions$1, ColorSpace, Texture as Texture$1, CubeTexture, Scene, Object3D } from 'three';
6
+ import { J as Properties, c as Size, F as Frameloop, e as Performance, D as Dpr, g as RootStore, p as EventManager, f as RootState, n as ComputeFunction, C as ConstructorRepresentation, _ as ObjectMap, I as InternalState, M as Mutable, O as Overwrite, y as Args, l as EventHandlers, B as InstanceProps, k as DomEvent, G as Instance, x as Catalogue, v as Root, a6 as ThreeCore, W as Bridge, Z as UnblockProps, a0 as Disposable, Q as ThreeCamera, $ as EquConfig } from './fiber.I5Q4dVvl.mjs';
7
+ import { WebGPURenderer, WebGPURendererParameters } from 'three/webgpu';
8
+ import * as react_jsx_runtime from 'react/jsx-runtime';
9
+
10
+ //* Base Renderer Types =====================================
11
+
12
+ // Shim for OffscreenCanvas since it was removed from DOM types
13
+ interface OffscreenCanvas$1 extends EventTarget {}
14
+
15
+ interface BaseRendererProps {
16
+ canvas: HTMLCanvasElement | OffscreenCanvas$1
17
+ powerPreference?: 'high-performance' | 'low-power' | 'default'
18
+ antialias?: boolean
19
+ alpha?: boolean
20
+ }
21
+
22
+ type RendererFactory<TRenderer, TParams> =
23
+ | TRenderer
24
+ | ((defaultProps: TParams) => TRenderer)
25
+ | ((defaultProps: TParams) => Promise<TRenderer>)
26
+
27
+ interface Renderer {
28
+ render: (scene: THREE.Scene, camera: THREE.Camera) => any
29
+ }
30
+
31
+ //* Color Management Config ==============================
32
+
33
+ /**
34
+ * Color management configuration shared by both WebGL and WebGPU renderers.
35
+ */
36
+ interface ColorManagementConfig {
37
+ /**
38
+ * Color space assigned to 8-bit input textures (color maps).
39
+ * Defaults to sRGB. Most textures are authored in sRGB.
40
+ * @default THREE.SRGBColorSpace
41
+ */
42
+ textureColorSpace?: THREE.ColorSpace
43
+ }
44
+
45
+ //* WebGL Renderer Props ==============================
46
+
47
+ type DefaultGLProps = Omit<THREE.WebGLRendererParameters, 'canvas'> & {
48
+ canvas: HTMLCanvasElement | OffscreenCanvas$1
49
+ }
50
+
51
+ type GLProps =
52
+ | Renderer
53
+ | ((defaultProps: DefaultGLProps) => Renderer)
54
+ | ((defaultProps: DefaultGLProps) => Promise<Renderer>)
55
+ | (Partial<Properties<THREE.WebGLRenderer> | THREE.WebGLRendererParameters> & ColorManagementConfig)
56
+
57
+ //* WebGPU Renderer Props ==============================
58
+
59
+ type DefaultRendererProps = {
60
+ canvas: HTMLCanvasElement | OffscreenCanvas$1
61
+ [key: string]: any
62
+ }
63
+
64
+ /**
65
+ * Canvas-level scheduler configuration.
66
+ * Controls render timing relative to other canvases.
67
+ */
68
+ interface CanvasSchedulerConfig {
69
+ /**
70
+ * Run this Canvas root before the referenced Canvas root id(s).
71
+ */
72
+ before?: string | string[]
73
+ /**
74
+ * Run this Canvas root after the referenced Canvas root id(s).
75
+ */
76
+ after?: string | string[]
77
+ /**
78
+ * Numeric root order. Lower values run first.
79
+ */
80
+ order?: number
81
+ /**
82
+ * Limit this Canvas's default render job (frames per second).
83
+ */
84
+ fps?: number
85
+ }
86
+
87
+ /**
88
+ * Extended renderer configuration for multi-canvas support and color management.
89
+ */
90
+ interface RendererConfigExtended extends ColorManagementConfig {
91
+ /** Share renderer from another canvas (WebGPU only) */
92
+ primaryCanvas?: string
93
+ /** Canvas-level scheduler options */
94
+ scheduler?: CanvasSchedulerConfig
95
+ }
96
+
97
+ /**
98
+ * The `renderer` prop: opt into three's WebGPU renderer.
99
+ * - `true` (the `<Canvas renderer>` shorthand) or `{}`: a default `WebGPURenderer`
100
+ * - a props bag: constructor parameters (`antialias`, `forceWebGL`, ...) and renderer properties
101
+ * (`toneMapping`, ...), plus `textureColorSpace`, `primaryCanvas` and `scheduler`
102
+ * - a renderer instance, or a sync/async factory receiving the default props. Structural, like
103
+ * the `gl` prop: anything with `render()`, so a wrapped or mocked renderer is accepted.
104
+ */
105
+ type RendererProps =
106
+ | boolean
107
+ | Renderer
108
+ | ((defaultProps: DefaultRendererProps) => Renderer)
109
+ | ((defaultProps: DefaultRendererProps) => Promise<Renderer>)
110
+ | (Partial<Properties<WebGPURenderer> & WebGPURendererParameters> & RendererConfigExtended)
111
+
112
+ //* Camera Props ==============================
113
+
114
+ type CameraProps = (
115
+ | THREE.Camera
116
+ | Partial<
117
+ ThreeElement<typeof THREE.Camera> &
118
+ ThreeElement<typeof THREE.PerspectiveCamera> &
119
+ ThreeElement<typeof THREE.OrthographicCamera>
120
+ >
121
+ ) & {
122
+ /** Flags the camera as manual, putting projection into your own hands */
123
+ manual?: boolean
124
+ }
125
+
126
+ //* Render Props ==============================
127
+
128
+ interface RenderProps<TCanvas extends HTMLCanvasElement | OffscreenCanvas$1> {
129
+ /**
130
+ * Unique identifier for multi-canvas renderer sharing.
131
+ * Makes this canvas targetable by other canvases using the `primaryCanvas` prop.
132
+ * Also sets the HTML `id` attribute on the canvas element.
133
+ * @example <Canvas id="main-viewer">...</Canvas>
134
+ */
135
+ id?: string
136
+ /**
137
+ * Share the renderer from another canvas instead of creating a new one.
138
+ * Pass the `id` of the primary canvas to share its WebGPURenderer.
139
+ * Only available with WebGPU (not legacy WebGL).
140
+ *
141
+ * Note: This is extracted from `renderer={{ primaryCanvas: "id" }}` by Canvas.
142
+ * @internal
143
+ */
144
+ primaryCanvas?: string
145
+ /**
146
+ * Canvas-level scheduler options. Controls render timing relative to other canvases.
147
+ *
148
+ * Note: This is extracted from `renderer={{ scheduler: {...} }}` by Canvas.
149
+ * @internal
150
+ */
151
+ scheduler?: CanvasSchedulerConfig
152
+ /** A threejs renderer instance or props that go into the default renderer */
153
+ gl?: GLProps
154
+ /** A WebGPU renderer instance or props that go into the default renderer */
155
+ renderer?: RendererProps
156
+ /** Dimensions to fit the renderer to. Will measure canvas dimensions if omitted */
157
+ size?: Size
158
+ /**
159
+ * Enables shadows (by default PCFsoft). Can accept `gl.shadowMap` options for fine-tuning,
160
+ * but also strings: 'basic' | 'percentage' | 'soft' | 'variance'.
161
+ * @see https://threejs.org/docs/#api/en/renderers/WebGLRenderer.shadowMap
162
+ */
163
+ shadows?: boolean | 'basic' | 'percentage' | 'soft' | 'variance' | Partial<THREE.WebGLShadowMap>
164
+ /** Creates an orthographic camera */
165
+ orthographic?: boolean
166
+ /**
167
+ * R3F's render mode. Set to `demand` to only render on state change or `never` to take control.
168
+ * @see https://docs.pmnd.rs/react-three-fiber/advanced/scaling-performance#on-demand-rendering
169
+ */
170
+ frameloop?: Frameloop
171
+ /**
172
+ * R3F performance options for adaptive performance.
173
+ * @see https://docs.pmnd.rs/react-three-fiber/advanced/scaling-performance#movement-regression
174
+ */
175
+ performance?: Partial<Omit<Performance, 'regress'>>
176
+ /** Target pixel ratio. Can clamp between a range: `[min, max]` */
177
+ dpr?: Dpr
178
+ /**
179
+ * Props that go into the default raycaster. `params` is merged into the raycaster's defaults,
180
+ * so a single threshold can be set: `raycaster={{ params: { Points: { threshold: 0.2 } } }}`.
181
+ */
182
+ raycaster?: Partial<Omit<THREE.Raycaster, 'params'>> & { params?: Partial<THREE.RaycasterParameters> }
183
+ /** A `THREE.Scene` instance or props that go into the default scene */
184
+ scene?: THREE.Scene | Partial<THREE.Scene>
185
+ /** A `THREE.Camera` instance or props that go into the default camera */
186
+ camera?: CameraProps
187
+ /** An R3F event manager to manage elements' pointer events */
188
+ events?: (store: RootStore) => EventManager<Element>
189
+ /** Callback after the canvas has rendered (but not yet committed) */
190
+ onCreated?: (state: RootState) => void
191
+ /** Response for pointer clicks that have missed any target */
192
+ onPointerMissed?: (event: MouseEvent) => void
193
+ /** Response for dragover events that have missed any target */
194
+ onDragOverMissed?: (event: DragEvent) => void
195
+ /** Response for drop events that have missed any target */
196
+ onDropMissed?: (event: DragEvent) => void
197
+ /** Whether to automatically update the frustum each frame (default: true) */
198
+ autoUpdateFrustum?: boolean
199
+ /**
200
+ * Enable WebGPU occlusion queries for onOccluded/onVisible events.
201
+ * Auto-enabled when any object uses onOccluded or onVisible handlers.
202
+ * Only works with WebGPU renderer - WebGL will log a warning.
203
+ */
204
+ occlusion?: boolean
205
+ /** Internal: stored size props from Canvas for reset functionality */
206
+ _sizeProps?: { width?: number; height?: number } | null
207
+ /** Force canvas dimensions to even numbers (fixes Safari rendering issues with odd/fractional sizes) */
208
+ forceEven?: boolean
209
+ }
210
+
211
+ //* Reconciler Root ==============================
212
+
213
+ interface ReconcilerRoot<TCanvas extends HTMLCanvasElement | OffscreenCanvas$1> {
214
+ configure: (config?: RenderProps<TCanvas>) => Promise<ReconcilerRoot<TCanvas>>
215
+ render: (element: ReactNode) => RootStore
216
+ unmount: () => void
217
+ }
218
+
219
+ //* Inject State ==============================
220
+
221
+ type InjectState = Partial<
222
+ Omit<RootState, 'events'> & {
223
+ events?: {
224
+ enabled?: boolean
225
+ priority?: number
226
+ compute?: ComputeFunction
227
+ connected?: any
228
+ }
229
+ /**
230
+ * When true (default), injects a THREE.Scene between container and children if container isn't already a Scene.
231
+ * This ensures state.scene is always a real THREE.Scene with proper properties (background, environment, fog).
232
+ * Set to false to use the container directly as scene (anti-pattern, but supported for edge cases).
233
+ */
234
+ injectScene?: boolean
235
+ }
236
+ >
237
+
238
+ //* Loop Types ==============================
239
+
240
+ type GlobalRenderCallback = (timestamp: number) => void
241
+
242
+ type GlobalEffectType = 'before' | 'after' | 'tail'
243
+
244
+ declare const presetsObj: {
245
+ apartment: string;
246
+ city: string;
247
+ dawn: string;
248
+ forest: string;
249
+ lobby: string;
250
+ night: string;
251
+ park: string;
252
+ studio: string;
253
+ sunset: string;
254
+ warehouse: string;
255
+ };
256
+ type PresetsType = keyof typeof presetsObj;
257
+
258
+ //* Background Types ==============================
259
+
260
+ /**
261
+ * Expanded object form for background configuration.
262
+ * Allows separate textures for background (visual backdrop) and environment (PBR lighting).
263
+ */
264
+ interface BackgroundConfig {
265
+ /** HDRI preset name: 'apartment', 'city', 'dawn', 'forest', 'lobby', 'night', 'park', 'studio', 'sunset', 'warehouse' */
266
+ preset?: PresetsType
267
+ /** Files for cube texture (6 faces) or single HDR/EXR */
268
+ files?: string | string[]
269
+ /** Separate files for scene.background (visual backdrop) */
270
+ backgroundMap?: string | string[]
271
+ backgroundRotation?: Euler$1 | [number, number, number]
272
+ backgroundBlurriness?: number
273
+ backgroundIntensity?: number
274
+ /** Separate files for scene.environment (PBR lighting/reflections) */
275
+ envMap?: string | string[]
276
+ environmentRotation?: Euler$1 | [number, number, number]
277
+ environmentIntensity?: number
278
+ path?: string
279
+ extensions?: (loader: Loader) => void
280
+ }
281
+
282
+ /**
283
+ * Background prop type for Canvas.
284
+ *
285
+ * String detection priority:
286
+ * 1. Preset - exact match against known presets (apartment, city, dawn, forest, lobby, night, park, studio, sunset, warehouse)
287
+ * 2. URL - starts with /, ./, ../, http://, https://, OR has image extension
288
+ * 3. Color - default fallback (CSS color names, hex values, rgb(), etc.)
289
+ *
290
+ * @example Color
291
+ * ```tsx
292
+ * <Canvas background="red" />
293
+ * <Canvas background="#ff0000" />
294
+ * <Canvas background={0xff0000} />
295
+ * ```
296
+ *
297
+ * @example Preset
298
+ * ```tsx
299
+ * <Canvas background="city" />
300
+ * ```
301
+ *
302
+ * @example URL
303
+ * ```tsx
304
+ * <Canvas background="/path/to/env.hdr" />
305
+ * <Canvas background="./sky.jpg" />
306
+ * ```
307
+ *
308
+ * @example Object form
309
+ * ```tsx
310
+ * <Canvas background={{
311
+ * files: ['px.png', 'nx.png', 'py.png', 'ny.png', 'pz.png', 'nz.png'],
312
+ * backgroundMap: 'path/to/sky.jpg',
313
+ * envMap: 'path/to/lighting.hdr',
314
+ * backgroundBlurriness: 0.5,
315
+ * }} />
316
+ * ```
317
+ */
318
+ type BackgroundProp =
319
+ | ColorRepresentation // "red", "#ff0000", 0xff0000
320
+ | string // URL or preset
321
+ | BackgroundConfig // Expanded object form
322
+
323
+ //* Canvas Types ==============================
324
+
325
+ interface CanvasProps
326
+ extends
327
+ Omit<RenderProps<HTMLCanvasElement>, 'size' | 'primaryCanvas' | 'scheduler'>,
328
+ React$1.HTMLAttributes<HTMLDivElement> {
329
+ children?: React$1.ReactNode
330
+ ref?: React$1.Ref<HTMLCanvasElement>
331
+ /** Canvas fallback content, similar to img's alt prop */
332
+ fallback?: React$1.ReactNode
333
+ /**
334
+ * Options to pass to useMeasure.
335
+ * @see https://github.com/pmndrs/react-use-measure#api
336
+ */
337
+ resize?: Options
338
+ /** The target where events are being subscribed to, default: the div that wraps canvas */
339
+ eventSource?: Element | React$1.RefObject<Element | null>
340
+ /** The event prefix that is cast into canvas pointer x/y events, default: "offset" */
341
+ eventPrefix?: 'offset' | 'client' | 'page' | 'layer' | 'screen'
342
+ /** Enable/disable automatic HMR refresh for TSL nodes and uniforms, default: true in dev */
343
+ hmr?: boolean
344
+ /** Canvas resolution width in pixels. If omitted, uses container width. */
345
+ width?: number
346
+ /** Canvas resolution height in pixels. If omitted, uses container height. */
347
+ height?: number
348
+ /** Force canvas dimensions to even numbers (fixes Safari rendering issues with odd/fractional sizes) */
349
+ forceEven?: boolean
350
+ /**
351
+ * Scene background configuration.
352
+ * Accepts colors, URLs, presets, or an expanded object for separate background/environment.
353
+ * @see BackgroundProp for full documentation and examples
354
+ */
355
+ background?: BackgroundProp
356
+ }
357
+
358
+ //* Loader Types ==============================
359
+
360
+ type InputLike = string | string[] | string[][] | Readonly<string | string[] | string[][]>
361
+
362
+ // Define a loader-like interface that matches THREE.Loader's load signature
363
+ // This works for both generic and non-generic THREE.Loader instances
364
+ interface LoaderLike {
365
+ load(
366
+ url: InputLike,
367
+ onLoad?: (result: any) => void,
368
+ onProgress?: (event: ProgressEvent<EventTarget>) => void,
369
+ onError?: (error: unknown) => void,
370
+ ): any
371
+ }
372
+
373
+ type GLTFLike = { scene: THREE.Object3D }
374
+
375
+ type LoaderInstance<T extends LoaderLike | ConstructorRepresentation<LoaderLike>> =
376
+ T extends ConstructorRepresentation<LoaderLike> ? InstanceType<T> : T
377
+
378
+ // Infer result type from the load method's callback parameter
379
+ type InferLoadResult<T> = T extends {
380
+ load(url: any, onLoad?: (result: infer R) => void, ...args: any[]): any
381
+ }
382
+ ? R
383
+ : T extends ConstructorRepresentation<any>
384
+ ? InstanceType<T> extends {
385
+ load(url: any, onLoad?: (result: infer R) => void, ...args: any[]): any
386
+ }
387
+ ? R
388
+ : any
389
+ : any
390
+
391
+ type LoaderResult<T extends LoaderLike | ConstructorRepresentation<LoaderLike>> =
392
+ InferLoadResult<LoaderInstance<T>> extends infer R ? (R extends GLTFLike ? R & ObjectMap : R) : never
393
+
394
+ type Extensions<T extends LoaderLike | ConstructorRepresentation<LoaderLike>> = (
395
+ loader: LoaderInstance<T>,
396
+ ) => void
397
+
398
+ //* Renderer Props ========================================
399
+
400
+ type WebGLDefaultProps = Omit<THREE.WebGLRendererParameters, 'canvas'> & BaseRendererProps
401
+
402
+ type WebGLProps =
403
+ | RendererFactory<THREE.WebGLRenderer, WebGLDefaultProps>
404
+ | Partial<Properties<THREE.WebGLRenderer> | THREE.WebGLRendererParameters>
405
+
406
+ interface WebGLShadowConfig {
407
+ shadows?: boolean | 'basic' | 'percentage' | 'soft' | 'variance' | Partial<THREE.WebGLShadowMap>
408
+ }
409
+
410
+ //* Legacy-specific Types ========================================
411
+
412
+ /** Legacy (WebGL) renderer type - re-exported as R3FRenderer from @react-three/fiber/legacy */
413
+ type LegacyRenderer = THREE.WebGLRenderer
414
+
415
+ /** Legacy internal state with narrowed renderer type */
416
+ interface LegacyInternalState extends Omit<InternalState, 'actualRenderer'> {
417
+ actualRenderer: THREE.WebGLRenderer
418
+ }
419
+
420
+ /**
421
+ * Legacy-specific RootState with narrowed renderer type.
422
+ * Automatically used when importing from `@react-three/fiber/legacy`.
423
+ *
424
+ * @example
425
+ * ```tsx
426
+ * import { useThree } from '@react-three/fiber/legacy'
427
+ *
428
+ * function MyComponent() {
429
+ * const { renderer } = useThree()
430
+ * // renderer is typed as THREE.WebGLRenderer
431
+ * renderer.shadowMap.enabled = true
432
+ * }
433
+ * ```
434
+ */
435
+ interface LegacyRootState extends Omit<RootState, 'renderer' | 'internal'> {
436
+ /** The WebGL renderer instance */
437
+ renderer: THREE.WebGLRenderer
438
+ /** Internals with WebGL renderer */
439
+ internal: LegacyInternalState
440
+ }
441
+
442
+ //* RenderTarget Types ==============================
443
+
444
+
445
+ type RenderTargetOptions = RenderTargetOptions$1
446
+
447
+ type MutableOrReadonlyParameters<T extends (...args: any) => any> = Parameters<T> | Readonly<Parameters<T>>
448
+
449
+ interface MathRepresentation {
450
+ set(...args: number[]): any
451
+ }
452
+ interface VectorRepresentation extends MathRepresentation {
453
+ setScalar(value: number): any
454
+ }
455
+ type MathTypes = MathRepresentation | THREE.Euler | THREE.Color
456
+
457
+ type MathType<T extends MathTypes> = T extends THREE.Color
458
+ ? Args<typeof THREE.Color> | THREE.ColorRepresentation
459
+ : T extends VectorRepresentation | THREE.Layers | THREE.Euler
460
+ ? T | MutableOrReadonlyParameters<T['set']> | number
461
+ : T | MutableOrReadonlyParameters<T['set']>
462
+
463
+ type MathProps<P> = {
464
+ [K in keyof P as P[K] extends MathTypes ? K : never]: P[K] extends MathTypes ? MathType<P[K]> : never
465
+ }
466
+
467
+ type Vector2 = MathType<THREE.Vector2>
468
+ type Vector3 = MathType<THREE.Vector3>
469
+ type Vector4 = MathType<THREE.Vector4>
470
+ type Color = MathType<THREE.Color>
471
+ type Layers = MathType<THREE.Layers>
472
+ type Quaternion = MathType<THREE.Quaternion>
473
+ type Euler = MathType<THREE.Euler>
474
+ type Matrix3 = MathType<THREE.Matrix3>
475
+ type Matrix4 = MathType<THREE.Matrix4>
476
+
477
+ interface RaycastableRepresentation {
478
+ raycast(raycaster: THREE.Raycaster, intersects: THREE.Intersection[]): void
479
+ }
480
+ type EventProps<P> = P extends RaycastableRepresentation ? Partial<EventHandlers> : {}
481
+
482
+ /**
483
+ * Props for geometry transform methods that can be called with `once()`.
484
+ * These methods modify the geometry in-place and only make sense to call once on mount.
485
+ *
486
+ * @example
487
+ * import { once } from '@react-three/fiber'
488
+ *
489
+ * <boxGeometry args={[1, 1, 1]} rotateX={once(Math.PI / 2)} />
490
+ * <planeGeometry args={[10, 10]} translate={once(0, 0, 5)} />
491
+ * <bufferGeometry applyMatrix4={once(matrix)} center={once()} />
492
+ */
493
+ interface GeometryTransformProps {
494
+ /** Rotate the geometry about the X axis (radians). Use with once(). */
495
+ rotateX?: number
496
+ /** Rotate the geometry about the Y axis (radians). Use with once(). */
497
+ rotateY?: number
498
+ /** Rotate the geometry about the Z axis (radians). Use with once(). */
499
+ rotateZ?: number
500
+ /** Translate the geometry (x, y, z). Use with once(). */
501
+ translate?: [x: number, y: number, z: number]
502
+ /** Scale the geometry (x, y, z). Use with once(). */
503
+ scale?: [x: number, y: number, z: number]
504
+ /** Center the geometry based on bounding box. Use with once(). */
505
+ center?: true
506
+ /** Apply a Matrix4 transformation. Use with once(). */
507
+ applyMatrix4?: THREE.Matrix4
508
+ /** Apply a Quaternion rotation. Use with once(). */
509
+ applyQuaternion?: THREE.Quaternion
510
+ }
511
+
512
+ type GeometryProps<P> = P extends THREE.BufferGeometry ? GeometryTransformProps : {}
513
+
514
+ /**
515
+ * Workaround for @types/three TSL node type issues.
516
+ * The Node base class has properties that subclasses (OperatorNode, ConstNode, etc.) don't inherit.
517
+ * This transforms `Node | null` properties to accept any object with node-like shape.
518
+ */
519
+ type TSLNodeInput = { nodeType?: string | null; uuid?: string } | null
520
+
521
+ /**
522
+ * For node material properties (colorNode, positionNode, etc.), accept broader types
523
+ * since @types/three has broken inheritance for TSL node subclasses. NodeClass requires
524
+ * `nodeType`, so this structural key test remains neutral to the selected Three entry.
525
+ */
526
+ type NodeProps<P> = {
527
+ [K in keyof P as NonNullable<P[K]> extends { nodeType: string | null } ? K : never]?: TSLNodeInput
528
+ }
529
+
530
+ interface ReactProps<P> {
531
+ children?: React.ReactNode
532
+ ref?: React.Ref<P>
533
+ key?: React.Key
534
+ }
535
+
536
+ type ElementProps<T extends ConstructorRepresentation, P = InstanceType<T>> = Partial<
537
+ Overwrite<P, MathProps<P> & ReactProps<P> & EventProps<P> & GeometryProps<P> & NodeProps<P>>
538
+ >
539
+
540
+ type ThreeElement<T extends ConstructorRepresentation> = Mutable<
541
+ Overwrite<ElementProps<T>, Omit<InstanceProps<InstanceType<T>, T>, 'object'>>
542
+ >
543
+
544
+ type ThreeToJSXElements<T extends Record<string, any>> = {
545
+ [K in keyof T & string as Uncapitalize<K>]: T[K] extends ConstructorRepresentation ? ThreeElement<T[K]> : never
546
+ }
547
+
548
+ /** Method names of Object3D, excluded from the `primitive` element's typed props. */
549
+ type Object3DMethod = NonNullable<
550
+ {
551
+ [K in keyof THREE.Object3D]-?: THREE.Object3D[K] extends (...args: any[]) => any ? K : never
552
+ }[keyof THREE.Object3D]
553
+ >
554
+
555
+ /** Look up a key present in a generic element map. */
556
+ type ElementOf<E, K extends string> = E[Extract<keyof E, K>]
557
+
558
+ /**
559
+ * The JSX element map derived from an entry's Three.js exports. Each entry declares its own
560
+ * `ThreeElements` from this (`src/index.tsx`, `src/legacy.tsx`, `src/webgpu/index.tsx`) and augments
561
+ * react's `IntrinsicElements` with it, so `/legacy` never advertises node materials and `/webgpu`
562
+ * never advertises a `<webGLRenderer>`.
563
+ */
564
+ type ThreeElementsOf<T extends Record<string, any>> = Omit<
565
+ ThreeToJSXElements<T>,
566
+ 'audio' | 'source' | 'line' | 'path'
567
+ > & {
568
+ /**
569
+ * `primitive` wraps a pre-existing object, so its props cannot be derived from one class.
570
+ * Events are typed from `EventHandlers` (`onClick={(e) => ...}` infers `e`), the ref is
571
+ * untyped, and any other prop is accepted and applied to the object by name. Object3D's own
572
+ * methods are left out of the typed surface: they return `this`, so a subclass element's
573
+ * props (`ThreeElements['group']`) could not be spread onto a primitive otherwise.
574
+ */
575
+ primitive: Omit<ThreeElement<typeof THREE.Object3D>, 'args' | 'object' | 'ref' | Object3DMethod> & {
576
+ object: object
577
+ ref?: React.Ref<any>
578
+ [prop: string]: unknown
579
+ }
580
+ // Conflicts with DOM types can be accessed through a three* prefix
581
+ threeAudio: ElementOf<ThreeToJSXElements<T>, 'audio'>
582
+ threeSource: ElementOf<ThreeToJSXElements<T>, 'source'>
583
+ threeLine: ElementOf<ThreeToJSXElements<T>, 'line'>
584
+ threePath: ElementOf<ThreeToJSXElements<T>, 'path'>
585
+ }
586
+
587
+ /**
588
+ * @fileoverview Registry for primary canvases that can be targeted by secondary canvases
589
+ *
590
+ * Enables multi-canvas WebGPU rendering where multiple Canvas components share
591
+ * a single WebGPURenderer using Three.js CanvasTarget API.
592
+ *
593
+ * Primary canvas: Has `id` prop, creates its own renderer, registers here
594
+ * Secondary canvas: Has `renderer={{ primaryCanvas: 'id' }}`, shares primary's renderer via CanvasTarget
595
+ */
596
+
597
+ interface PrimaryCanvasEntry {
598
+ /** The WebGPURenderer instance owned by this primary canvas */
599
+ renderer: WebGPURenderer;
600
+ /** The zustand store for this canvas */
601
+ store: RootStore;
602
+ }
603
+ /**
604
+ * Register a primary canvas that can be targeted by secondary canvases.
605
+ *
606
+ * @param id - Unique identifier for this primary canvas
607
+ * @param renderer - The WebGPURenderer owned by this canvas
608
+ * @param store - The zustand store for this canvas
609
+ * @returns Cleanup function to unregister on unmount
610
+ */
611
+ declare function registerPrimary(id: string, renderer: WebGPURenderer, store: RootStore): () => void;
612
+ /**
613
+ * Get a registered primary canvas by id.
614
+ *
615
+ * @param id - The id of the primary canvas to look up
616
+ * @returns The primary canvas entry or undefined if not found
617
+ */
618
+ declare function getPrimary(id: string): PrimaryCanvasEntry | undefined;
619
+ /**
620
+ * Wait for a primary canvas to be registered.
621
+ * Returns immediately if already registered, otherwise waits.
622
+ *
623
+ * @param id - The id of the primary canvas to wait for
624
+ * @param timeout - Optional timeout in ms (default: 5000)
625
+ * @returns Promise that resolves with the primary canvas entry
626
+ */
627
+ declare function waitForPrimary(id: string, timeout?: number): Promise<PrimaryCanvasEntry>;
628
+ /**
629
+ * Check if a primary canvas with the given id exists.
630
+ *
631
+ * @param id - The id to check
632
+ * @returns True if a primary canvas with this id is registered
633
+ */
634
+ declare function hasPrimary(id: string): boolean;
635
+ /**
636
+ * Unregister a primary canvas. Called on unmount.
637
+ *
638
+ * @param id - The id of the primary canvas to unregister
639
+ */
640
+ declare function unregisterPrimary(id: string): void;
641
+ /**
642
+ * Get all registered primary canvas ids. Useful for debugging.
643
+ */
644
+ declare function getPrimaryIds(): string[];
645
+
646
+ type EnvironmentLoaderProps = {
647
+ files?: string | string[];
648
+ path?: string;
649
+ preset?: PresetsType;
650
+ extensions?: (loader: Loader) => void;
651
+ colorSpace?: ColorSpace;
652
+ };
653
+ /**
654
+ * Loads environment textures for reflections and lighting.
655
+ * Supports HDR files, presets, and cubemaps.
656
+ *
657
+ * @example Basic usage
658
+ * ```jsx
659
+ * const texture = useEnvironment({ preset: 'sunset' })
660
+ * ```
661
+ */
662
+ declare function useEnvironment({ files, path, preset, colorSpace, extensions, }?: Partial<EnvironmentLoaderProps>): Texture$1<unknown, THREE.TextureEventMap> | CubeTexture<unknown>;
663
+ declare namespace useEnvironment {
664
+ var preload: (preloadOptions?: EnvironmentLoaderPreloadOptions) => void;
665
+ var clear: (clearOptions?: EnvironmentLoaderClearOptions) => void;
666
+ }
667
+ /**
668
+ * Options accepted by `useEnvironment.preload`.
669
+ *
670
+ * `colorSpace` is deliberately omitted: preload only warms the loader cache, and colorSpace is
671
+ * applied to the texture by `useEnvironment()` at use time, per consumer. Accepting it here would
672
+ * advertise an option this function silently ignores.
673
+ */
674
+ type EnvironmentLoaderPreloadOptions = Omit<EnvironmentLoaderProps, 'colorSpace'>;
675
+ type EnvironmentLoaderClearOptions = Pick<EnvironmentLoaderProps, 'files' | 'preset'>;
676
+
677
+ /**
678
+ * Props for Environment component that sets up global cubemap for PBR materials and backgrounds.
679
+ *
680
+ * @property children - React children to render into custom environment portal
681
+ * @property frames - Number of frames to render the environment. Use 1 for static, Infinity for animated (default: 1)
682
+ * @property near - Near clipping plane for cube camera (default: 0.1)
683
+ * @property far - Far clipping plane for cube camera (default: 1000)
684
+ * @property resolution - Resolution of the cube render target (default: 256)
685
+ * @property background - Whether to set scene.background. Can be true, false, or "only" (which only sets background) (default: false)
686
+ *
687
+ * @property blur - @deprecated Use backgroundBlurriness instead
688
+ * @property backgroundBlurriness - Blur factor between 0 and 1 for background (default: 0, requires three.js 0.146+)
689
+ * @property backgroundIntensity - Intensity factor for background (default: 1, requires three.js 0.163+)
690
+ * @property backgroundRotation - Rotation for background as Euler angles (default: [0,0,0], requires three.js 0.163+)
691
+ * @property environmentIntensity - Intensity factor for environment lighting (default: 1, requires three.js 0.163+)
692
+ * @property environmentRotation - Rotation for environment as Euler angles (default: [0,0,0], requires three.js 0.163+)
693
+ *
694
+ * @property map - Pre-existing texture to use as environment map
695
+ * @property preset - HDRI Haven preset: 'apartment', 'city', 'dawn', 'forest', 'lobby', 'night', 'park', 'studio', 'sunset', 'warehouse'. Not for production use.
696
+ * @property scene - Custom THREE.Scene or ref to apply environment to (default: uses default scene)
697
+ * @property ground - Ground projection settings. Use true for defaults or object with:
698
+ * - height: Height of camera used to create env map (default: 15)
699
+ * - radius: Radius of the world (default: 60)
700
+ * - scale: Scale of backside projected sphere (default: 1000)
701
+ *
702
+ * Additional loader props:
703
+ * @property files - File path(s) for environment. Supports .hdr, .exr, Ultra HDR .jpg, or array of 6 cube faces
704
+ * @property path - Base path for file loading
705
+ * @property extensions - Texture extensions override
706
+ */
707
+ type EnvironmentProps = {
708
+ children?: React$1.ReactNode;
709
+ frames?: number;
710
+ near?: number;
711
+ far?: number;
712
+ resolution?: number;
713
+ background?: boolean | 'only';
714
+ /** deprecated, use backgroundBlurriness */
715
+ blur?: number;
716
+ backgroundBlurriness?: number;
717
+ backgroundIntensity?: number;
718
+ backgroundRotation?: Euler;
719
+ environmentIntensity?: number;
720
+ environmentRotation?: Euler;
721
+ map?: Texture$1;
722
+ preset?: PresetsType;
723
+ scene?: Scene | React$1.RefObject<Scene>;
724
+ ground?: boolean | {
725
+ radius?: number;
726
+ height?: number;
727
+ scale?: number;
728
+ };
729
+ /** Solid color for background (alternative to files/preset) */
730
+ color?: ColorRepresentation;
731
+ /** Separate files for background (when different from environment files) */
732
+ backgroundFiles?: string | string[];
733
+ } & EnvironmentLoaderProps;
734
+ /**
735
+ * Internal component that applies a pre-existing texture as environment map.
736
+ * Sets scene.environment and optionally scene.background.
737
+ *
738
+ * @example
739
+ * ```jsx
740
+ * <CubeCamera>{(texture) => <EnvironmentMap map={texture} />}</CubeCamera>
741
+ * ```
742
+ */
743
+ declare function EnvironmentMap({ scene, background, map, ...config }: EnvironmentProps): null;
744
+ /**
745
+ * Internal component that loads environment textures from files or presets.
746
+ * Uses HDRLoader for .hdr, EXRLoader for .exr, UltraHDRLoader for .jpg/.jpeg Ultra HDR,
747
+ * or CubeTextureLoader for arrays of images.
748
+ *
749
+ * @example With preset
750
+ * ```jsx
751
+ * <EnvironmentCube preset="sunset" />
752
+ * ```
753
+ *
754
+ * @example From HDR file
755
+ * ```jsx
756
+ * <EnvironmentCube files="environment.hdr" />
757
+ * ```
758
+ *
759
+ * @example From an Ultra HDR JPEG (smallest footprint)
760
+ * ```jsx
761
+ * <EnvironmentCube files="file.jpg" />
762
+ * ```
763
+ *
764
+ * @example From cube faces
765
+ * ```jsx
766
+ * <EnvironmentCube files={['px.png', 'nx.png', 'py.png', 'ny.png', 'pz.png', 'nz.png']} />
767
+ * ```
768
+ */
769
+ declare function EnvironmentCube({ background, scene, blur, backgroundBlurriness, backgroundIntensity, backgroundRotation, environmentIntensity, environmentRotation, ...rest }: EnvironmentProps): null;
770
+ /**
771
+ * Internal component that renders custom environment using a portal and cube camera.
772
+ * Renders children into an off-buffer and films with a cube camera to create environment map.
773
+ * Can be static (frames=1) or animated (frames=Infinity).
774
+ *
775
+ * @example Custom environment with sphere
776
+ * ```jsx
777
+ * <EnvironmentPortal background near={1} far={1000} resolution={256}>
778
+ * <mesh scale={100}>
779
+ * <sphereGeometry args={[1, 64, 64]} />
780
+ * <meshBasicMaterial map={texture} side={THREE.BackSide} />
781
+ * </mesh>
782
+ * </EnvironmentPortal>
783
+ * ```
784
+ *
785
+ * @example Animated environment
786
+ * ```jsx
787
+ * <EnvironmentPortal frames={Infinity} resolution={256}>
788
+ * <Float>
789
+ * <mesh />
790
+ * </Float>
791
+ * </EnvironmentPortal>
792
+ * ```
793
+ *
794
+ * @example Mixed with preset
795
+ * ```jsx
796
+ * <EnvironmentPortal preset="warehouse">
797
+ * <mesh />
798
+ * </EnvironmentPortal>
799
+ * ```
800
+ */
801
+ 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;
802
+ /**
803
+ * Sets up a global environment map for PBR materials and backgrounds.
804
+ * Affects scene.environment and optionally scene.background unless a custom scene is passed.
805
+ *
806
+ * Supports multiple input methods:
807
+ * - **Presets**: Selection of HDRI Haven assets (apartment, city, dawn, forest, lobby, night, park, studio, sunset, warehouse)
808
+ * - **Files**: HDR (.hdr), EXR (.exr), Ultra HDR JPEG (.jpg), or cube faces (array of 6 images)
809
+ * - **Texture**: Pre-existing cube texture via `map` prop
810
+ * - **Custom Scene**: Render children into environment using portal and cube camera
811
+ * - **Ground Projection**: Project environment onto ground plane
812
+ *
813
+ * @remarks
814
+ * - Preset property is NOT meant for production and may fail (relies on CDNs)
815
+ * - Ultra HDR JPEG has the smallest file footprint
816
+ * - Use `frames={Infinity}` for animated environments with low resolution for performance
817
+ * - Ground projection places models on the "ground" within the environment map
818
+ * - Supports self-hosting with @pmndrs/assets using dynamic imports
819
+ *
820
+ * @example Basic preset usage
821
+ * ```jsx
822
+ * <Environment preset="sunset" />
823
+ * ```
824
+ *
825
+ * @example From HDR file
826
+ * ```jsx
827
+ * <Environment files="/hdr/environment.hdr" />
828
+ * ```
829
+ *
830
+ * @example From an Ultra HDR JPEG (smallest footprint)
831
+ * ```jsx
832
+ * <Environment files="file.jpg" />
833
+ * ```
834
+ *
835
+ * @example With self-hosted assets
836
+ * ```jsx
837
+ * import { suspend } from 'suspend-react'
838
+ * const city = import('@pmndrs/assets/hdri/city.exr').then(m => m.default)
839
+ *
840
+ * <Environment files={suspend(city)} />
841
+ * ```
842
+ *
843
+ * @example From existing texture
844
+ * ```jsx
845
+ * <CubeCamera>{(texture) => <Environment map={texture} />}</CubeCamera>
846
+ * ```
847
+ *
848
+ * @example Custom environment scene
849
+ * ```jsx
850
+ * <Environment background near={1} far={1000} resolution={256}>
851
+ * <mesh scale={100}>
852
+ * <sphereGeometry args={[1, 64, 64]} />
853
+ * <meshBasicMaterial map={texture} side={THREE.BackSide} />
854
+ * </mesh>
855
+ * </Environment>
856
+ * ```
857
+ *
858
+ * @example Animated environment
859
+ * ```jsx
860
+ * <Environment frames={Infinity} resolution={256}>
861
+ * <Float>
862
+ * <mesh />
863
+ * </Float>
864
+ * </Environment>
865
+ * ```
866
+ *
867
+ * @example Mixed custom scene with preset
868
+ * ```jsx
869
+ * <Environment background preset="warehouse">
870
+ * <mesh />
871
+ * </Environment>
872
+ * ```
873
+ *
874
+ * @example With ground projection
875
+ * ```jsx
876
+ * <Environment ground={{ height: 15, radius: 60 }} preset="city" />
877
+ * ```
878
+ *
879
+ * @example As background only
880
+ * ```jsx
881
+ * <Environment background="only" preset="sunset" />
882
+ * ```
883
+ *
884
+ * @example With rotation and intensity
885
+ * ```jsx
886
+ * <Environment
887
+ * background
888
+ * backgroundBlurriness={0.5}
889
+ * backgroundIntensity={0.8}
890
+ * backgroundRotation={[0, Math.PI / 2, 0]}
891
+ * environmentIntensity={1.2}
892
+ * environmentRotation={[0, Math.PI / 4, 0]}
893
+ * preset="studio"
894
+ * />
895
+ * ```
896
+ */
897
+ declare function Environment(props: EnvironmentProps): react_jsx_runtime.JSX.Element;
898
+
899
+ /**
900
+ * Moves every trace of interactivity from one object to its replacement, for reconstruction.
901
+ *
902
+ * When `args` or a `primitive`'s `object` changes, R3F builds a new three object and keeps the same
903
+ * instance. Removing the old object from the interaction state and registering the new one from
904
+ * scratch makes events *work* again (#3778), but it forgets what was in flight: a pointer resting on
905
+ * the object fires a second `onPointerEnter` without ever having left, and an active pointer capture
906
+ * is dropped mid-drag. Rewriting the references instead keeps the interaction continuous across a
907
+ * swap the user never asked to see (#3744).
908
+ *
909
+ * Captures are re-keyed rather than released, so the DOM-level capture on `captureData.target` is
910
+ * left alone — releasing and re-acquiring it is precisely the glitch being avoided.
911
+ *
912
+ * Visibility handlers are deliberately not transferred: that registry is keyed by `object.uuid`, so
913
+ * the replacement re-registers itself through `applyProps`. The old entry is dropped here so it
914
+ * cannot outlive the object it described.
915
+ */
916
+ declare function swapInteractivity(store: RootStore, object: THREE.Object3D, newObject: THREE.Object3D): void;
917
+ declare function removeInteractivity(store: RootStore, object: THREE.Object3D): void;
918
+ declare function createEvents(store: RootStore): {
919
+ handlePointer: (name: string) => (event: DomEvent) => void;
920
+ flushDeferredPointers: () => void;
921
+ processDeferredPointer: (event: DomEvent, pointerId: number) => void;
922
+ };
923
+ /** Default R3F event manager for web */
924
+ declare function createPointerEvents(store: RootStore): EventManager<Element>;
925
+
926
+ /**
927
+ * Gets or creates a memoized loader instance from a loader constructor or returns the loader if it's already an instance.
928
+ * This allows external code to access loader methods like abort().
929
+ */
930
+ declare function getLoader<L extends LoaderLike | ConstructorRepresentation<LoaderLike>>(Proto: L): L extends ConstructorRepresentation<infer T> ? T : L;
931
+ /**
932
+ * Synchronously loads and caches assets with a three loader.
933
+ *
934
+ * Note: this hook's caller must be wrapped with `React.Suspense`
935
+ * @see https://docs.pmnd.rs/react-three-fiber/api/hooks#useloader
936
+ */
937
+ declare function useLoader<I extends InputLike, L extends LoaderLike | ConstructorRepresentation<LoaderLike>>(loader: L, input: I, extensions?: Extensions<L>, onProgress?: (event: ProgressEvent<EventTarget>) => void, cacheKey?: InputLike): I extends any[] ? LoaderResult<L>[] : LoaderResult<L>;
938
+ declare namespace useLoader {
939
+ var preload: <I extends InputLike, L extends LoaderLike | ConstructorRepresentation<LoaderLike>>(loader: L, input: I, extensions?: Extensions<L>, onProgress?: (event: ProgressEvent<EventTarget>) => void, cacheKey?: InputLike) => void;
940
+ var clear: <I extends InputLike, L extends LoaderLike | ConstructorRepresentation<LoaderLike>>(loader: L, input: I, cacheKey?: InputLike) => void;
941
+ var loader: typeof getLoader;
942
+ }
943
+
944
+ declare const IsObject: (url: unknown) => url is Record<string, string>;
945
+ type TextureArray<T> = T extends string[] ? Texture$1[] : never;
946
+ type TextureRecord<T> = T extends Record<string, string> ? {
947
+ [key in keyof T]: Texture$1;
948
+ } : never;
949
+ type SingleTexture<T> = T extends string ? Texture$1 : never;
950
+ type MappedTextureType<T extends string[] | string | Record<string, string>> = TextureArray<T> | TextureRecord<T> | SingleTexture<T>;
951
+ /** Options for useTexture hook */
952
+ type UseTextureOptions<Url extends string[] | string | Record<string, string>> = {
953
+ /** Callback when texture(s) finish loading */
954
+ onLoad?: (texture: MappedTextureType<Url>) => void;
955
+ /**
956
+ * Register the texture(s) in R3F's global texture registry for access via useTextures().
957
+ * When true (the default):
958
+ * - Textures persist until explicitly disposed
959
+ * - On mount, returns existing registered textures if available (preserving modifications like colorSpace)
960
+ *
961
+ * Reads are taken once at mount — a mounted `useTexture` does not re-render when the registry
962
+ * changes. To react to registry swaps, use `useTextures(s => s.get(key))` instead.
963
+ *
964
+ * Pass `false` to opt out of registry enrollment entirely.
965
+ * @default true
966
+ */
967
+ cache?: boolean;
968
+ };
969
+ /**
970
+ * Load texture(s) using Three's TextureLoader with Suspense support.
971
+ *
972
+ * @param input - URL string, array of URLs, or object mapping keys to URLs
973
+ * @param optionsOrOnLoad - Options object or legacy onLoad callback
974
+ *
975
+ * @example
976
+ * ```tsx
977
+ * // Single texture
978
+ * const diffuse = useTexture('/textures/diffuse.png')
979
+ *
980
+ * // Multiple textures (array)
981
+ * const [diffuse, normal] = useTexture(['/diffuse.png', '/normal.png'])
982
+ *
983
+ * // Named textures (object)
984
+ * const { diffuse, normal } = useTexture({
985
+ * diffuse: '/diffuse.png',
986
+ * normal: '/normal.png'
987
+ * })
988
+ *
989
+ * // Textures are registered in the global registry by default — the same texture
990
+ * // object is shared across components and modifications (colorSpace, wrapS, etc.) are preserved
991
+ * const diffuse = useTexture('/diffuse.png')
992
+ * diffuse.colorSpace = THREE.SRGBColorSpace
993
+ *
994
+ * // Another component gets the SAME texture with colorSpace already set
995
+ * const sameDiffuse = useTexture('/diffuse.png')
996
+ *
997
+ * // Opt out of registry enrollment for a one-off texture
998
+ * const scratch = useTexture('/scratch.png', { cache: false })
999
+ *
1000
+ * // Access the registry directly
1001
+ * const { get } = useTextures()
1002
+ * const cached = get('/diffuse.png')
1003
+ * ```
1004
+ */
1005
+ declare function useTexture<Url extends string[] | string | Record<string, string>>(input: Url, optionsOrOnLoad?: UseTextureOptions<Url> | ((texture: MappedTextureType<Url>) => void)): MappedTextureType<Url>;
1006
+ declare namespace useTexture {
1007
+ var preload: (url: string | string[]) => void;
1008
+ var clear: (input: string | string[]) => void;
1009
+ }
1010
+ declare const Texture: ({ children, input, onLoad, cache, }: {
1011
+ children?: (texture: ReturnType<typeof useTexture>) => ReactNode;
1012
+ input: Parameters<typeof useTexture>[0];
1013
+ onLoad?: Parameters<typeof useTexture>[1];
1014
+ cache?: boolean;
1015
+ }) => react_jsx_runtime.JSX.Element;
1016
+
1017
+ /** Accepted shapes for a registry read: a single key, a list of keys, or a name→key map. */
1018
+ type TextureInput = string | string[] | Record<string, string>;
1019
+ /** Result of a `get()` read, mirroring the input shape. */
1020
+ type TextureResult<Input extends TextureInput> = Input extends string ? Texture$1 | undefined : Input extends string[] ? (Texture$1 | undefined)[] : {
1021
+ [K in keyof Input]: Texture$1 | undefined;
1022
+ };
1023
+ /** Options for `dispose()`. */
1024
+ interface DisposeOptions {
1025
+ /** Dispose even if the texture still has active references (default false). */
1026
+ force?: boolean;
1027
+ }
1028
+ interface UseTexturesReturn {
1029
+ /** The live registry Map (key → Texture). Treat as read-only. */
1030
+ readonly all: Map<string, Texture$1>;
1031
+ /** Read one texture, an array of textures, or a name→texture record (mirrors the input shape). */
1032
+ get<Input extends TextureInput>(input: Input): TextureResult<Input>;
1033
+ /** Check whether a key exists in the registry. */
1034
+ has(key: string): boolean;
1035
+ /**
1036
+ * Register a texture (or a record of textures) that has no URL — e.g. a render
1037
+ * target or procedural texture. URL-loaded textures are registered automatically
1038
+ * by `useTexture` (registry enrollment is on by default).
1039
+ */
1040
+ add(key: string, texture: Texture$1): void;
1041
+ add(record: Record<string, Texture$1>): void;
1042
+ /**
1043
+ * Dispose a texture's GPU resources and remove it from the registry.
1044
+ * Refcount-aware: if the key is still in use by a mounted `useTexture` consumer it is
1045
+ * skipped (with a warning) unless `{ force: true }` is passed.
1046
+ * @returns true if disposed, false if skipped.
1047
+ */
1048
+ dispose(key: string, options?: DisposeOptions): boolean;
1049
+ /** Dispose every texture in the registry and clear it. Use on scene teardown. */
1050
+ disposeAll(): void;
1051
+ }
1052
+ /**
1053
+ * Reactive Texture registry — load once with `useTexture`, reach the textures from anywhere.
1054
+ *
1055
+ * This is a registry of plain `Texture` objects (not TSL nodes), so the same texture can feed
1056
+ * a material map, a heightmap sampler, or anything else. It does **not** load — pair it with
1057
+ * `useTexture` for loading (registry enrollment is on by default); `useTextures` is for access and lifecycle.
1058
+ *
1059
+ * The returned handle is **reactive**: the calling component re-renders when the registry
1060
+ * changes. Pass a selector to scope the subscription to a single read.
1061
+ *
1062
+ * @example
1063
+ * ```tsx
1064
+ * // Load + register once (anywhere in the tree) — registered by default
1065
+ * useTexture({ map: '/diffuse.jpg', normalMap: '/normal.jpg' })
1066
+ *
1067
+ * // Reach them from another component — record form lands straight into a material
1068
+ * const { map, normalMap } = useTextures().get({ map: '/diffuse.jpg', normalMap: '/normal.jpg' })
1069
+ * return <meshStandardMaterial map={map} normalMap={normalMap} />
1070
+ *
1071
+ * // A set of heightmaps at once
1072
+ * const [a, b, c] = useTextures().get(['/h0.png', '/h1.png', '/h2.png'])
1073
+ *
1074
+ * // Register a non-URL texture (render target / procedural)
1075
+ * useTextures().add('rt-main', renderTarget.texture)
1076
+ *
1077
+ * // Deliberate GPU cleanup (refcount-aware; force to override)
1078
+ * useTextures().dispose('/diffuse.jpg')
1079
+ * useTextures().disposeAll() // scene teardown
1080
+ * ```
1081
+ *
1082
+ * @remarks
1083
+ * **Future expansion:** an imperative async loader (e.g. `await useTextures().load('/x.jpg')`) is
1084
+ * intentionally not included yet. It would let non-React code (loading screens, dynamic streaming)
1085
+ * populate the registry without Suspense, at the cost of putting loading back into this hook. It
1086
+ * will be added only if a concrete consumer needs imperative loading; for now, loading lives in
1087
+ * `useTexture`.
1088
+ */
1089
+ declare function useTextures(): UseTexturesReturn;
1090
+ declare function useTextures<T>(selector: (registry: UseTexturesReturn) => T): T;
1091
+
1092
+ /**
1093
+ * Exposes an object's {@link Instance}.
1094
+ * @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#useInstanceHandle
1095
+ *
1096
+ * **Note**: this is an escape hatch to react-internal fields. Expect this to change significantly between versions.
1097
+ */
1098
+ declare function useInstanceHandle<T>(ref: React.RefObject<T>): React.RefObject<Instance<T>>;
1099
+ /**
1100
+ * Returns a node graph of an object with named nodes & materials.
1101
+ * @see https://docs.pmnd.rs/react-three-fiber/api/hooks#usegraph
1102
+ */
1103
+ declare function useGraph(object: Object3D): ObjectMap;
1104
+
1105
+ /**
1106
+ * Adds a global render callback which is called each frame BEFORE rendering.
1107
+ *
1108
+ * @deprecated Use `useFrame(callback, { phase: 'start' })` instead.
1109
+ * This function will be removed in a future version.
1110
+ *
1111
+ * @param callback - Function called each frame with timestamp
1112
+ * @returns Unsubscribe function
1113
+ *
1114
+ * @example
1115
+ * // OLD (deprecated)
1116
+ * const unsub = addEffect((timestamp) => { ... })
1117
+ *
1118
+ * // NEW
1119
+ * useFrame((state, delta) => { ... }, { phase: 'start' })
1120
+ *
1121
+ * @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#addEffect
1122
+ */
1123
+ declare function addEffect(callback: GlobalRenderCallback): () => void;
1124
+ /**
1125
+ * Adds a global after-render callback which is called each frame AFTER rendering.
1126
+ *
1127
+ * @deprecated Use `useFrame(callback, { phase: 'finish' })` instead.
1128
+ * This function will be removed in a future version.
1129
+ *
1130
+ * @param callback - Function called each frame with timestamp
1131
+ * @returns Unsubscribe function
1132
+ *
1133
+ * @example
1134
+ * // OLD (deprecated)
1135
+ * const unsub = addAfterEffect((timestamp) => { ... })
1136
+ *
1137
+ * // NEW
1138
+ * useFrame((state, delta) => { ... }, { phase: 'finish' })
1139
+ *
1140
+ * @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#addAfterEffect
1141
+ */
1142
+ declare function addAfterEffect(callback: GlobalRenderCallback): () => void;
1143
+ /**
1144
+ * Adds a global callback which is called when rendering stops.
1145
+ *
1146
+ * @deprecated Use `scheduler.onIdle(callback)` instead.
1147
+ * This function will be removed in a future version.
1148
+ *
1149
+ * @param callback - Function called when rendering stops
1150
+ * @returns Unsubscribe function
1151
+ *
1152
+ * @example
1153
+ * // OLD (deprecated)
1154
+ * const unsub = addTail((timestamp) => { ... })
1155
+ *
1156
+ * // NEW
1157
+ * const { scheduler } = useFrame()
1158
+ * const unsub = scheduler.onIdle((timestamp) => { ... })
1159
+ *
1160
+ * @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#addTail
1161
+ */
1162
+ declare function addTail(callback: GlobalRenderCallback): () => void;
1163
+ /**
1164
+ * Invalidates the view, requesting a frame to be rendered.
1165
+ * In demand mode, this triggers the scheduler to run frames.
1166
+ *
1167
+ * With a state argument, only that root's jobs run on the requested frames; other
1168
+ * roots on 'demand' stay idle. Without one, every registered root is invalidated.
1169
+ *
1170
+ * @param state - Optional root state; targets the invalidation at that root
1171
+ * @param frames - Number of frames to request (default: 1)
1172
+ * @param stackFrames - If false, sets pendingFrames to frames. If true, adds to existing pendingFrames (default: false)
1173
+ *
1174
+ * @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#invalidate
1175
+ */
1176
+ declare function invalidate(state?: RootState, frames?: number, stackFrames?: boolean): void;
1177
+ /**
1178
+ * Advances the frameloop and runs render effects.
1179
+ * Useful for when manually rendering via `frameloop="never"`.
1180
+ *
1181
+ * With a state argument, only that root is stepped. Without one, every
1182
+ * registered root is stepped for backwards compatibility.
1183
+ *
1184
+ * @param timestamp - The timestamp to use for this frame
1185
+ * @param runGlobalEffects - Ignored (kept for backwards compat, global effects always run)
1186
+ * @param state - Optional root state; targets the manual step at that root
1187
+ *
1188
+ * @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#advance
1189
+ */
1190
+ declare function advance(timestamp: number, runGlobalEffects?: boolean, state?: RootState): void;
1191
+
1192
+ /* eslint-disable @definitelytyped/no-unnecessary-generics */
1193
+ declare function ReactReconciler<
1194
+ Type,
1195
+ Props,
1196
+ Container,
1197
+ Instance,
1198
+ TextInstance,
1199
+ SuspenseInstance,
1200
+ HydratableInstance,
1201
+ FormInstance,
1202
+ PublicInstance,
1203
+ HostContext,
1204
+ ChildSet,
1205
+ TimeoutHandle,
1206
+ NoTimeout,
1207
+ TransitionStatus,
1208
+ >(
1209
+ /* eslint-enable @definitelytyped/no-unnecessary-generics */
1210
+ config: ReactReconciler.HostConfig<
1211
+ Type,
1212
+ Props,
1213
+ Container,
1214
+ Instance,
1215
+ TextInstance,
1216
+ SuspenseInstance,
1217
+ HydratableInstance,
1218
+ FormInstance,
1219
+ PublicInstance,
1220
+ HostContext,
1221
+ ChildSet,
1222
+ TimeoutHandle,
1223
+ NoTimeout,
1224
+ TransitionStatus
1225
+ >,
1226
+ ): ReactReconciler.Reconciler<Container, Instance, TextInstance, SuspenseInstance, FormInstance, PublicInstance>;
1227
+
1228
+ declare namespace ReactReconciler {
1229
+ interface HostConfig<
1230
+ Type,
1231
+ Props,
1232
+ Container,
1233
+ Instance,
1234
+ TextInstance,
1235
+ SuspenseInstance,
1236
+ HydratableInstance,
1237
+ FormInstance,
1238
+ PublicInstance,
1239
+ HostContext,
1240
+ ChildSet,
1241
+ TimeoutHandle,
1242
+ NoTimeout,
1243
+ TransitionStatus,
1244
+ > {
1245
+ // -------------------
1246
+ // Modes
1247
+ // -------------------
1248
+ /**
1249
+ * The reconciler has two modes: mutation mode and persistent mode. You must specify one of them.
1250
+ *
1251
+ * 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.
1252
+ *
1253
+ * ```js
1254
+ * const HostConfig = {
1255
+ * // ...
1256
+ * supportsMutation: true,
1257
+ * // ...
1258
+ * }
1259
+ * ```
1260
+ *
1261
+ * Depending on the mode, the reconciler will call different methods on your host config.
1262
+ *
1263
+ * If you're not sure which one you want, you likely need the mutation mode.
1264
+ */
1265
+ supportsMutation: boolean;
1266
+
1267
+ /**
1268
+ * The reconciler has two modes: mutation mode and persistent mode. You must specify one of them.
1269
+ *
1270
+ * 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".
1271
+ *
1272
+ * ```js
1273
+ * const HostConfig = {
1274
+ * // ...
1275
+ * supportsPersistence: true,
1276
+ * // ...
1277
+ * }
1278
+ * ```
1279
+ *
1280
+ * Depending on the mode, the reconciler will call different methods on your host config.
1281
+ *
1282
+ * If you're not sure which one you want, you likely need the mutation mode.
1283
+ */
1284
+ supportsPersistence: boolean;
1285
+
1286
+ // -------------------
1287
+ // Core Methods
1288
+ // -------------------
1289
+
1290
+ /**
1291
+ * 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`.
1292
+ *
1293
+ * 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.
1294
+ *
1295
+ * 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.
1296
+ *
1297
+ * 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.
1298
+ *
1299
+ * 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.
1300
+ */
1301
+ createInstance(
1302
+ type: Type,
1303
+ props: Props,
1304
+ rootContainer: Container,
1305
+ hostContext: HostContext,
1306
+ internalHandle: OpaqueHandle,
1307
+ ): Instance;
1308
+
1309
+ /**
1310
+ * Same as `createInstance`, but for text nodes. If your renderer doesn't support text nodes, you can throw here.
1311
+ */
1312
+ createTextInstance(
1313
+ text: string,
1314
+ rootContainer: Container,
1315
+ hostContext: HostContext,
1316
+ internalHandle: OpaqueHandle,
1317
+ ): TextInstance;
1318
+
1319
+ /**
1320
+ * 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.
1321
+ *
1322
+ * 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.
1323
+ */
1324
+ appendInitialChild(parentInstance: Instance, child: Instance | TextInstance): void;
1325
+
1326
+ /**
1327
+ * 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.
1328
+ *
1329
+ * 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.
1330
+ *
1331
+ * 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.
1332
+ *
1333
+ * If you don't want to do anything here, you should return `false`.
1334
+ */
1335
+ finalizeInitialChildren(
1336
+ instance: Instance,
1337
+ type: Type,
1338
+ props: Props,
1339
+ rootContainer: Container,
1340
+ hostContext: HostContext,
1341
+ ): boolean;
1342
+
1343
+ /**
1344
+ * 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.
1345
+ *
1346
+ * 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.
1347
+ *
1348
+ * If you don't want to do anything here, you should return `false`.
1349
+ *
1350
+ * This method happens **in the render phase**. Do not mutate the tree from it.
1351
+ */
1352
+ shouldSetTextContent(type: Type, props: Props): boolean;
1353
+
1354
+ /**
1355
+ * This method lets you return the initial host context from the root of the tree. See `getChildHostContext` for the explanation of host context.
1356
+ *
1357
+ * If you don't intend to use host context, you can return `null`.
1358
+ *
1359
+ * This method happens **in the render phase**. Do not mutate the tree from it.
1360
+ */
1361
+ getRootHostContext(rootContainer: Container): HostContext | null;
1362
+
1363
+ /**
1364
+ * 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.
1365
+ *
1366
+ * 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.
1367
+ *
1368
+ * If you don't want to do anything here, return `parentHostContext`.
1369
+ *
1370
+ * This method happens **in the render phase**. Do not mutate the tree from it.
1371
+ */
1372
+ getChildHostContext(parentHostContext: HostContext, type: Type, rootContainer: Container): HostContext;
1373
+
1374
+ /**
1375
+ * 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.
1376
+ *
1377
+ * If you don't want to do anything here, return `instance`.
1378
+ */
1379
+ getPublicInstance(instance: Instance | TextInstance): PublicInstance;
1380
+
1381
+ /**
1382
+ * 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`.
1383
+ *
1384
+ * Even if you don't want to do anything here, you need to return `null` from it.
1385
+ */
1386
+ prepareForCommit(containerInfo: Container): Record<string, any> | null;
1387
+
1388
+ /**
1389
+ * 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.
1390
+ *
1391
+ * You can leave it empty.
1392
+ */
1393
+ resetAfterCommit(containerInfo: Container): void;
1394
+
1395
+ /**
1396
+ * This method is called for a container that's used as a portal target. Usually you can leave it empty.
1397
+ */
1398
+ preparePortalMount(containerInfo: Container): void;
1399
+
1400
+ /**
1401
+ * You can proxy this to `setTimeout` or its equivalent in your environment.
1402
+ */
1403
+ scheduleTimeout(fn: (...args: unknown[]) => unknown, delay?: number): TimeoutHandle;
1404
+
1405
+ /**
1406
+ * You can proxy this to `clearTimeout` or its equivalent in your environment.
1407
+ */
1408
+ cancelTimeout(id: TimeoutHandle): void;
1409
+
1410
+ /**
1411
+ * 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`.
1412
+ */
1413
+ noTimeout: NoTimeout;
1414
+
1415
+ /**
1416
+ * 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.
1417
+ */
1418
+ supportsMicrotasks?: boolean;
1419
+
1420
+ /**
1421
+ * Optional. You can proxy this to `queueMicrotask` or its equivalent in your environment.
1422
+ */
1423
+ scheduleMicrotask?(fn: () => unknown): void;
1424
+
1425
+ /**
1426
+ * 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`.
1427
+ */
1428
+ isPrimaryRenderer: boolean;
1429
+
1430
+ /**
1431
+ * Whether the renderer shouldn't trigger missing `act()` warnings
1432
+ */
1433
+ warnsIfNotActing?: boolean;
1434
+
1435
+ getInstanceFromNode(node: any): Fiber | null | undefined;
1436
+
1437
+ beforeActiveInstanceBlur(): void;
1438
+
1439
+ afterActiveInstanceBlur(): void;
1440
+
1441
+ prepareScopeUpdate(scopeInstance: any, instance: any): void;
1442
+
1443
+ getInstanceFromScope(scopeInstance: any): null | Instance;
1444
+
1445
+ detachDeletedInstance(node: Instance): void;
1446
+
1447
+ // -------------------
1448
+ // Mutation Methods
1449
+ // (optional)
1450
+ // If you're using React in mutation mode (you probably do), you'll need to implement a few more methods.
1451
+ // -------------------
1452
+
1453
+ /**
1454
+ * 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.
1455
+ *
1456
+ * 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`.
1457
+ */
1458
+ appendChild?(parentInstance: Instance, child: Instance | TextInstance): void;
1459
+
1460
+ /**
1461
+ * 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.
1462
+ */
1463
+ appendChildToContainer?(container: Container, child: Instance | TextInstance): void;
1464
+
1465
+ /**
1466
+ * 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.
1467
+ *
1468
+ * 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.
1469
+ */
1470
+ insertBefore?(
1471
+ parentInstance: Instance,
1472
+ child: Instance | TextInstance,
1473
+ beforeChild: Instance | TextInstance | SuspenseInstance,
1474
+ ): void;
1475
+
1476
+ /**
1477
+ * 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.
1478
+ */
1479
+ insertInContainerBefore?(
1480
+ container: Container,
1481
+ child: Instance | TextInstance,
1482
+ beforeChild: Instance | TextInstance | SuspenseInstance,
1483
+ ): void;
1484
+
1485
+ /**
1486
+ * This method should mutate the `parentInstance` to remove the `child` from the list of its children.
1487
+ *
1488
+ * 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.
1489
+ */
1490
+ removeChild?(parentInstance: Instance, child: Instance | TextInstance | SuspenseInstance): void;
1491
+
1492
+ /**
1493
+ * 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.
1494
+ */
1495
+ removeChildFromContainer?(container: Container, child: Instance | TextInstance | SuspenseInstance): void;
1496
+
1497
+ /**
1498
+ * 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 = ''`.
1499
+ *
1500
+ * If you never return `true` from `shouldSetTextContent`, you can leave it empty.
1501
+ */
1502
+ resetTextContent?(instance: Instance): void;
1503
+
1504
+ /**
1505
+ * This method should mutate the `textInstance` and update its text content to `nextText`.
1506
+ *
1507
+ * Here, `textInstance` is a node created by `createTextInstance`.
1508
+ */
1509
+ commitTextUpdate?(textInstance: TextInstance, oldText: string, newText: string): void;
1510
+
1511
+ /**
1512
+ * This method is only called if you returned `true` from `finalizeInitialChildren` for this instance.
1513
+ *
1514
+ * 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.
1515
+ *
1516
+ * 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.
1517
+ *
1518
+ * 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.
1519
+ *
1520
+ * If you never return `true` from `finalizeInitialChildren`, you can leave it empty.
1521
+ */
1522
+ commitMount?(instance: Instance, type: Type, props: Props, internalInstanceHandle: OpaqueHandle): void;
1523
+
1524
+ /**
1525
+ * This method should mutate the instance to match nextProps.
1526
+ *
1527
+ * 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.
1528
+ */
1529
+ commitUpdate?(
1530
+ instance: Instance,
1531
+ type: Type,
1532
+ prevProps: Props,
1533
+ nextProps: Props,
1534
+ internalHandle: OpaqueHandle,
1535
+ ): void;
1536
+
1537
+ /**
1538
+ * 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.
1539
+ */
1540
+ hideInstance?(instance: Instance): void;
1541
+
1542
+ /**
1543
+ * Same as `hideInstance`, but for nodes created by `createTextInstance`.
1544
+ */
1545
+ hideTextInstance?(textInstance: TextInstance): void;
1546
+
1547
+ /**
1548
+ * This method should make the `instance` visible, undoing what `hideInstance` did.
1549
+ */
1550
+ unhideInstance?(instance: Instance, props: Props): void;
1551
+
1552
+ /**
1553
+ * Same as `unhideInstance`, but for nodes created by `createTextInstance`.
1554
+ */
1555
+ unhideTextInstance?(textInstance: TextInstance, text: string): void;
1556
+
1557
+ /**
1558
+ * This method should mutate the `container` root node and remove all children from it.
1559
+ */
1560
+ clearContainer?(container: Container): void;
1561
+
1562
+ // -------------------
1563
+ // Persistence Methods
1564
+ // (optional)
1565
+ // 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.
1566
+ // -------------------
1567
+ cloneInstance?(
1568
+ instance: Instance,
1569
+ type: Type,
1570
+ oldProps: Props,
1571
+ newProps: Props,
1572
+ keepChildren: boolean,
1573
+ recyclableInstance: null | Instance,
1574
+ ): Instance;
1575
+ createContainerChildSet?(container: Container): ChildSet;
1576
+ appendChildToContainerChildSet?(childSet: ChildSet, child: Instance | TextInstance): void;
1577
+ finalizeContainerChildren?(container: Container, newChildren: ChildSet): void;
1578
+ replaceContainerChildren?(container: Container, newChildren: ChildSet): void;
1579
+ cloneHiddenInstance?(
1580
+ instance: Instance,
1581
+ type: Type,
1582
+ props: Props,
1583
+ internalInstanceHandle: OpaqueHandle,
1584
+ ): Instance;
1585
+ cloneHiddenTextInstance?(instance: Instance, text: Type, internalInstanceHandle: OpaqueHandle): TextInstance;
1586
+
1587
+ // -------------------
1588
+ // Hydration Methods
1589
+ // (optional)
1590
+ // 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.
1591
+ //
1592
+ // 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.
1593
+ // -------------------
1594
+ supportsHydration: boolean;
1595
+
1596
+ canHydrateInstance?(instance: HydratableInstance, type: Type, props: Props): null | Instance;
1597
+
1598
+ canHydrateTextInstance?(instance: HydratableInstance, text: string): null | TextInstance;
1599
+
1600
+ canHydrateSuspenseInstance?(instance: HydratableInstance): null | SuspenseInstance;
1601
+
1602
+ isSuspenseInstancePending?(instance: SuspenseInstance): boolean;
1603
+
1604
+ isSuspenseInstanceFallback?(instance: SuspenseInstance): boolean;
1605
+
1606
+ registerSuspenseInstanceRetry?(instance: SuspenseInstance, callback: () => void): void;
1607
+
1608
+ getNextHydratableSibling?(instance: HydratableInstance): null | HydratableInstance;
1609
+
1610
+ getFirstHydratableChild?(parentInstance: Container | Instance): null | HydratableInstance;
1611
+
1612
+ hydrateInstance?(
1613
+ instance: Instance,
1614
+ type: Type,
1615
+ props: Props,
1616
+ rootContainerInstance: Container,
1617
+ hostContext: HostContext,
1618
+ internalInstanceHandle: any,
1619
+ ): null | any[];
1620
+
1621
+ hydrateTextInstance?(textInstance: TextInstance, text: string, internalInstanceHandle: any): boolean;
1622
+
1623
+ hydrateSuspenseInstance?(suspenseInstance: SuspenseInstance, internalInstanceHandle: any): void;
1624
+
1625
+ getNextHydratableInstanceAfterSuspenseInstance?(suspenseInstance: SuspenseInstance): null | HydratableInstance;
1626
+
1627
+ // Returns the SuspenseInstance if this node is a direct child of a
1628
+ // SuspenseInstance. I.e. if its previous sibling is a Comment with
1629
+ // SUSPENSE_x_START_DATA. Otherwise, null.
1630
+ getParentSuspenseInstance?(targetInstance: any): null | SuspenseInstance;
1631
+
1632
+ commitHydratedContainer?(container: Container): void;
1633
+
1634
+ commitHydratedSuspenseInstance?(suspenseInstance: SuspenseInstance): void;
1635
+
1636
+ didNotMatchHydratedContainerTextInstance?(
1637
+ parentContainer: Container,
1638
+ textInstance: TextInstance,
1639
+ text: string,
1640
+ ): void;
1641
+
1642
+ didNotMatchHydratedTextInstance?(
1643
+ parentType: Type,
1644
+ parentProps: Props,
1645
+ parentInstance: Instance,
1646
+ textInstance: TextInstance,
1647
+ text: string,
1648
+ ): void;
1649
+
1650
+ didNotHydrateContainerInstance?(parentContainer: Container, instance: HydratableInstance): void;
1651
+
1652
+ didNotHydrateInstance?(
1653
+ parentType: Type,
1654
+ parentProps: Props,
1655
+ parentInstance: Instance,
1656
+ instance: HydratableInstance,
1657
+ ): void;
1658
+
1659
+ didNotFindHydratableContainerInstance?(parentContainer: Container, type: Type, props: Props): void;
1660
+
1661
+ didNotFindHydratableContainerTextInstance?(parentContainer: Container, text: string): void;
1662
+
1663
+ didNotFindHydratableContainerSuspenseInstance?(parentContainer: Container): void;
1664
+
1665
+ didNotFindHydratableInstance?(
1666
+ parentType: Type,
1667
+ parentProps: Props,
1668
+ parentInstance: Instance,
1669
+ type: Type,
1670
+ props: Props,
1671
+ ): void;
1672
+
1673
+ didNotFindHydratableTextInstance?(
1674
+ parentType: Type,
1675
+ parentProps: Props,
1676
+ parentInstance: Instance,
1677
+ text: string,
1678
+ ): void;
1679
+
1680
+ didNotFindHydratableSuspenseInstance?(parentType: Type, parentProps: Props, parentInstance: Instance): void;
1681
+
1682
+ errorHydratingContainer?(parentContainer: Container): void;
1683
+
1684
+ // Undocumented
1685
+ // https://github.com/facebook/react/pull/26722
1686
+ NotPendingTransition: TransitionStatus | null;
1687
+ HostTransitionContext: ReactContext<TransitionStatus>;
1688
+
1689
+ // https://github.com/facebook/react/pull/28751
1690
+ setCurrentUpdatePriority(newPriority: EventPriority): void;
1691
+ getCurrentUpdatePriority(): EventPriority;
1692
+ resolveUpdatePriority(): EventPriority;
1693
+
1694
+ // https://github.com/facebook/react/pull/28804
1695
+ resetFormInstance(form: FormInstance): void;
1696
+
1697
+ // https://github.com/facebook/react/pull/25105
1698
+ requestPostPaintCallback(callback: (time: number) => void): void;
1699
+
1700
+ // https://github.com/facebook/react/pull/26025
1701
+ shouldAttemptEagerTransition(): boolean;
1702
+
1703
+ // https://github.com/facebook/react/pull/31528
1704
+ trackSchedulerEvent(): void;
1705
+
1706
+ // https://github.com/facebook/react/pull/31008
1707
+ resolveEventType(): null | string;
1708
+ resolveEventTimeStamp(): number;
1709
+
1710
+ /**
1711
+ * 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.
1712
+ */
1713
+ maySuspendCommit(type: Type, props: Props): boolean;
1714
+
1715
+ /**
1716
+ * 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.
1717
+ */
1718
+ preloadInstance(type: Type, props: Props): boolean;
1719
+
1720
+ /**
1721
+ * 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.
1722
+ */
1723
+ startSuspendingCommit(): void;
1724
+
1725
+ /**
1726
+ * This method is called after `startSuspendingCommit` for each Host Component that indicated it might suspend a commit.
1727
+ */
1728
+ suspendInstance(type: Type, props: Props): void;
1729
+
1730
+ /**
1731
+ * This method is called after all `suspendInstance` calls are complete.
1732
+ *
1733
+ * Return `null` if the commit can happen immediately.
1734
+ *
1735
+ * 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.
1736
+ */
1737
+ waitForCommitToBeReady():
1738
+ | ((initiateCommit: (...args: unknown[]) => unknown) => (...args: unknown[]) => unknown)
1739
+ | null;
1740
+ }
1741
+
1742
+ interface Thenable<T> {
1743
+ then(resolve: () => T, reject?: () => T): T;
1744
+ }
1745
+
1746
+ type RootTag = 0 | 1 | 2;
1747
+
1748
+ type WorkTag =
1749
+ | 0
1750
+ | 1
1751
+ | 2
1752
+ | 3
1753
+ | 4
1754
+ | 5
1755
+ | 6
1756
+ | 7
1757
+ | 8
1758
+ | 9
1759
+ | 10
1760
+ | 11
1761
+ | 12
1762
+ | 13
1763
+ | 14
1764
+ | 15
1765
+ | 16
1766
+ | 17
1767
+ | 18
1768
+ | 19
1769
+ | 20
1770
+ | 21
1771
+ | 22
1772
+ | 23
1773
+ | 24;
1774
+
1775
+ type HookType =
1776
+ | "useState"
1777
+ | "useReducer"
1778
+ | "useContext"
1779
+ | "useRef"
1780
+ | "useEffect"
1781
+ | "useLayoutEffect"
1782
+ | "useCallback"
1783
+ | "useMemo"
1784
+ | "useImperativeHandle"
1785
+ | "useDebugValue"
1786
+ | "useDeferredValue"
1787
+ | "useTransition"
1788
+ | "useMutableSource"
1789
+ | "useOpaqueIdentifier"
1790
+ | "useCacheRefresh";
1791
+
1792
+ interface Source {
1793
+ fileName: string;
1794
+ lineNumber: number;
1795
+ }
1796
+
1797
+ // TODO: Ideally these types would be opaque but that doesn't work well with
1798
+ // our reconciler fork infra, since these leak into non-reconciler packages.
1799
+ type LanePriority = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17;
1800
+
1801
+ type Lanes = number;
1802
+ type Lane = number;
1803
+
1804
+ type Flags = number;
1805
+
1806
+ type TypeOfMode = number;
1807
+
1808
+ type EventPriority = number;
1809
+
1810
+ interface ReactProvider<T> {
1811
+ $$typeof: symbol | number;
1812
+ type: ReactProviderType<T>;
1813
+ key: null | string;
1814
+ ref: null;
1815
+ props: {
1816
+ value: T;
1817
+ children?: ReactNode;
1818
+ };
1819
+ }
1820
+
1821
+ interface ReactProviderType<T> {
1822
+ $$typeof: symbol | number;
1823
+ _context: ReactContext<T>;
1824
+ }
1825
+
1826
+ interface ReactConsumer<T> {
1827
+ $$typeof: symbol | number;
1828
+ type: ReactContext<T>;
1829
+ key: null | string;
1830
+ ref: null;
1831
+ props: {
1832
+ children: (value: T) => ReactNode;
1833
+ unstable_observedBits?: number;
1834
+ };
1835
+ }
1836
+
1837
+ interface ReactContext<T> {
1838
+ $$typeof: symbol | number;
1839
+ Consumer: ReactContext<T>;
1840
+ Provider: ReactProviderType<T>;
1841
+ _currentValue: T;
1842
+ _currentValue2: T;
1843
+ _threadCount: number;
1844
+ // DEV only
1845
+ _currentRenderer?: {
1846
+ [key: string]: any;
1847
+ } | null;
1848
+ _currentRenderer2?: {
1849
+ [key: string]: any;
1850
+ } | null;
1851
+ // This value may be added by application code
1852
+ // to improve DEV tooling display names
1853
+ displayName?: string;
1854
+ }
1855
+
1856
+ interface ReactPortal {
1857
+ $$typeof: symbol | number;
1858
+ key: null | string;
1859
+ containerInfo: any;
1860
+ children: ReactNode;
1861
+ // TODO: figure out the API for cross-renderer implementation.
1862
+ implementation: any;
1863
+ }
1864
+
1865
+ interface RefObject {
1866
+ current: any;
1867
+ }
1868
+
1869
+ interface ContextDependency<T> {
1870
+ context: ReactContext<T>;
1871
+ observedBits: number;
1872
+ next: ContextDependency<unknown> | null;
1873
+ }
1874
+
1875
+ interface Dependencies {
1876
+ lanes: Lanes;
1877
+ firstContext: ContextDependency<unknown> | null;
1878
+ }
1879
+
1880
+ interface Fiber {
1881
+ // These first fields are conceptually members of an Instance. This used to
1882
+ // be split into a separate type and intersected with the other Fiber fields,
1883
+ // but until Flow fixes its intersection bugs, we've merged them into a
1884
+ // single type.
1885
+
1886
+ // An Instance is shared between all versions of a component. We can easily
1887
+ // break this out into a separate object to avoid copying so much to the
1888
+ // alternate versions of the tree. We put this on a single object for now to
1889
+ // minimize the number of objects created during the initial render.
1890
+
1891
+ // Tag identifying the type of fiber.
1892
+ tag: WorkTag;
1893
+
1894
+ // Unique identifier of this child.
1895
+ key: null | string;
1896
+
1897
+ // The value of element.type which is used to preserve the identity during
1898
+ // reconciliation of this child.
1899
+ elementType: any;
1900
+
1901
+ // The resolved function/class/ associated with this fiber.
1902
+ type: any;
1903
+
1904
+ // The local state associated with this fiber.
1905
+ stateNode: any;
1906
+
1907
+ // Conceptual aliases
1908
+ // parent : Instance -> return The parent happens to be the same as the
1909
+ // return fiber since we've merged the fiber and instance.
1910
+
1911
+ // Remaining fields belong to Fiber
1912
+
1913
+ // The Fiber to return to after finishing processing this one.
1914
+ // This is effectively the parent, but there can be multiple parents (two)
1915
+ // so this is only the parent of the thing we're currently processing.
1916
+ // It is conceptually the same as the return address of a stack frame.
1917
+ return: Fiber | null;
1918
+
1919
+ // Singly Linked List Tree Structure.
1920
+ child: Fiber | null;
1921
+ sibling: Fiber | null;
1922
+ index: number;
1923
+
1924
+ // The ref last used to attach this node.
1925
+ // I'll avoid adding an owner field for prod and model that as functions.
1926
+ ref:
1927
+ | null
1928
+ | (((handle: unknown) => void) & {
1929
+ _stringRef?: string | null;
1930
+ })
1931
+ | RefObject;
1932
+
1933
+ // Input is the data coming into process this fiber. Arguments. Props.
1934
+ pendingProps: any; // This type will be more specific once we overload the tag.
1935
+ memoizedProps: any; // The props used to create the output.
1936
+
1937
+ // A queue of state updates and callbacks.
1938
+ updateQueue: unknown;
1939
+
1940
+ // The state used to create the output
1941
+ memoizedState: any;
1942
+
1943
+ // Dependencies (contexts, events) for this fiber, if it has any
1944
+ dependencies: Dependencies | null;
1945
+
1946
+ // Bitfield that describes properties about the fiber and its subtree. E.g.
1947
+ // the ConcurrentMode flag indicates whether the subtree should be async-by-
1948
+ // default. When a fiber is created, it inherits the mode of its
1949
+ // parent. Additional flags can be set at creation time, but after that the
1950
+ // value should remain unchanged throughout the fiber's lifetime, particularly
1951
+ // before its child fibers are created.
1952
+ mode: TypeOfMode;
1953
+
1954
+ // Effect
1955
+ flags: Flags;
1956
+ subtreeFlags: Flags;
1957
+ deletions: Fiber[] | null;
1958
+
1959
+ // Singly linked list fast path to the next fiber with side-effects.
1960
+ nextEffect: Fiber | null;
1961
+
1962
+ // The first and last fiber with side-effect within this subtree. This allows
1963
+ // us to reuse a slice of the linked list when we reuse the work done within
1964
+ // this fiber.
1965
+ firstEffect: Fiber | null;
1966
+ lastEffect: Fiber | null;
1967
+
1968
+ lanes: Lanes;
1969
+ childLanes: Lanes;
1970
+
1971
+ // This is a pooled version of a Fiber. Every fiber that gets updated will
1972
+ // eventually have a pair. There are cases when we can clean up pairs to save
1973
+ // memory if we need to.
1974
+ alternate: Fiber | null;
1975
+
1976
+ // Time spent rendering this Fiber and its descendants for the current update.
1977
+ // This tells us how well the tree makes use of sCU for memoization.
1978
+ // It is reset to 0 each time we render and only updated when we don't bailout.
1979
+ // This field is only set when the enableProfilerTimer flag is enabled.
1980
+ actualDuration?: number;
1981
+
1982
+ // If the Fiber is currently active in the "render" phase,
1983
+ // This marks the time at which the work began.
1984
+ // This field is only set when the enableProfilerTimer flag is enabled.
1985
+ actualStartTime?: number;
1986
+
1987
+ // Duration of the most recent render time for this Fiber.
1988
+ // This value is not updated when we bailout for memoization purposes.
1989
+ // This field is only set when the enableProfilerTimer flag is enabled.
1990
+ selfBaseDuration?: number;
1991
+
1992
+ // Sum of base times for all descendants of this Fiber.
1993
+ // This value bubbles up during the "complete" phase.
1994
+ // This field is only set when the enableProfilerTimer flag is enabled.
1995
+ treeBaseDuration?: number;
1996
+
1997
+ // Conceptual aliases
1998
+ // workInProgress : Fiber -> alternate The alternate used for reuse happens
1999
+ // to be the same as work in progress.
2000
+ // __DEV__ only
2001
+ _debugID?: number;
2002
+ _debugSource?: Source | null;
2003
+ _debugOwner?: Fiber | null;
2004
+ _debugIsCurrentlyTiming?: boolean;
2005
+ _debugNeedsRemount?: boolean;
2006
+
2007
+ // Used to verify that the order of hooks does not change between renders.
2008
+ _debugHookTypes?: HookType[] | null;
2009
+ }
2010
+
2011
+ type FiberRoot = any;
2012
+
2013
+ // Concurrent related struct
2014
+ type MutableSource = any;
2015
+
2016
+ type OpaqueHandle = any;
2017
+ type OpaqueRoot = any;
2018
+
2019
+ // 0 is PROD, 1 is DEV.
2020
+ // Might add PROFILE later.
2021
+ type BundleType = 0 | 1;
2022
+
2023
+ interface DevToolsConfig<Instance, TextInstance, RendererInspectionConfig> {
2024
+ bundleType: BundleType;
2025
+ version: string;
2026
+ rendererPackageName: string;
2027
+ // Note: this actually *does* depend on Fiber internal fields.
2028
+ // Used by "inspect clicked DOM element" in React DevTools.
2029
+ findFiberByHostInstance?: (instance: Instance | TextInstance) => Fiber | null;
2030
+ rendererConfig?: RendererInspectionConfig;
2031
+ }
2032
+
2033
+ interface SuspenseHydrationCallbacks<SuspenseInstance> {
2034
+ onHydrated?: (suspenseInstance: SuspenseInstance) => void;
2035
+ onDeleted?: (suspenseInstance: SuspenseInstance) => void;
2036
+ }
2037
+
2038
+ interface TransitionTracingCallbacks {
2039
+ onTransitionStart?: (transitionName: string, startTime: number) => void;
2040
+ onTransitionProgress?: (
2041
+ transitionName: string,
2042
+ startTime: number,
2043
+ currentTime: number,
2044
+ pending: Array<{ name: null | string }>,
2045
+ ) => void;
2046
+ onTransitionIncomplete?: (
2047
+ transitionName: string,
2048
+ startTime: number,
2049
+ deletions: Array<{
2050
+ type: string;
2051
+ name?: string;
2052
+ newName?: string;
2053
+ endTime: number;
2054
+ }>,
2055
+ ) => void;
2056
+ onTransitionComplete?: (transitionName: string, startTime: number, endTime: number) => void;
2057
+ onMarkerProgress?: (
2058
+ transitionName: string,
2059
+ marker: string,
2060
+ startTime: number,
2061
+ currentTime: number,
2062
+ pending: Array<{ name: null | string }>,
2063
+ ) => void;
2064
+ onMarkerIncomplete?: (
2065
+ transitionName: string,
2066
+ marker: string,
2067
+ startTime: number,
2068
+ deletions: Array<{
2069
+ type: string;
2070
+ name?: string;
2071
+ newName?: string;
2072
+ endTime: number;
2073
+ }>,
2074
+ ) => void;
2075
+ onMarkerComplete?: (transitionName: string, marker: string, startTime: number, endTime: number) => void;
2076
+ }
2077
+
2078
+ interface ComponentSelector {
2079
+ $$typeof: symbol | number;
2080
+ value: React$AbstractComponent<never, unknown>;
2081
+ }
2082
+
2083
+ interface HasPseudoClassSelector {
2084
+ $$typeof: symbol | number;
2085
+ value: Selector[];
2086
+ }
2087
+
2088
+ interface RoleSelector {
2089
+ $$typeof: symbol | number;
2090
+ value: string;
2091
+ }
2092
+
2093
+ interface TextSelector {
2094
+ $$typeof: symbol | number;
2095
+ value: string;
2096
+ }
2097
+
2098
+ interface TestNameSelector {
2099
+ $$typeof: symbol | number;
2100
+ value: string;
2101
+ }
2102
+
2103
+ type Selector = ComponentSelector | HasPseudoClassSelector | RoleSelector | TextSelector | TestNameSelector;
2104
+
2105
+ // TODO can not find React$AbstractComponent def
2106
+ type React$AbstractComponent<Config, Instance = any> = any;
2107
+
2108
+ interface BoundingRect {
2109
+ x: number;
2110
+ y: number;
2111
+ width: number;
2112
+ height: number;
2113
+ }
2114
+
2115
+ type IntersectionObserverOptions = any;
2116
+
2117
+ interface BaseErrorInfo {
2118
+ componentStack?: string;
2119
+ }
2120
+
2121
+ interface Reconciler<Container, Instance, TextInstance, SuspenseInstance, FormInstance, PublicInstance> {
2122
+ createContainer(
2123
+ containerInfo: Container,
2124
+ tag: RootTag,
2125
+ hydrationCallbacks: null | SuspenseHydrationCallbacks<SuspenseInstance>,
2126
+ isStrictMode: boolean,
2127
+ concurrentUpdatesByDefaultOverride: null | boolean,
2128
+ identifierPrefix: string,
2129
+ onUncaughtError: (error: Error, info: BaseErrorInfo & { errorBoundary?: Component }) => void,
2130
+ onCaughtError: (error: Error, info: BaseErrorInfo) => void,
2131
+ onRecoverableError: (error: Error, info: BaseErrorInfo) => void,
2132
+ onDefaultTransitionIndicator: () => void,
2133
+ transitionCallbacks: null | TransitionTracingCallbacks,
2134
+ ): OpaqueRoot;
2135
+
2136
+ createPortal(
2137
+ children: ReactNode,
2138
+ containerInfo: any, // TODO: figure out the API for cross-renderer implementation.
2139
+ implementation: any,
2140
+ key?: string | null,
2141
+ ): ReactPortal;
2142
+
2143
+ registerMutableSourceForHydration(root: FiberRoot, mutableSource: MutableSource): void;
2144
+
2145
+ createComponentSelector(component: React$AbstractComponent<never, unknown>): ComponentSelector;
2146
+
2147
+ createHasPseudoClassSelector(selectors: Selector[]): HasPseudoClassSelector;
2148
+
2149
+ createRoleSelector(role: string): RoleSelector;
2150
+
2151
+ createTextSelector(text: string): TextSelector;
2152
+
2153
+ createTestNameSelector(id: string): TestNameSelector;
2154
+
2155
+ getFindAllNodesFailureDescription(hostRoot: Instance, selectors: Selector[]): string | null;
2156
+
2157
+ findAllNodes(hostRoot: Instance, selectors: Selector[]): Instance[];
2158
+
2159
+ findBoundingRects(hostRoot: Instance, selectors: Selector[]): BoundingRect[];
2160
+
2161
+ focusWithin(hostRoot: Instance, selectors: Selector[]): boolean;
2162
+
2163
+ observeVisibleRects(
2164
+ hostRoot: Instance,
2165
+ selectors: Selector[],
2166
+ callback: (intersections: Array<{ ratio: number; rect: BoundingRect }>) => void,
2167
+ options?: IntersectionObserverOptions,
2168
+ ): { disconnect: () => void };
2169
+
2170
+ createHydrationContainer(
2171
+ initialChildren: ReactNode,
2172
+ callback: (() => void) | null | undefined,
2173
+ containerInfo: Container,
2174
+ tag: RootTag,
2175
+ hydrationCallbacks: null | SuspenseHydrationCallbacks<SuspenseInstance>,
2176
+ isStrictMode: boolean,
2177
+ concurrentUpdatesByDefaultOverride: null | boolean,
2178
+ identifierPrefix: string,
2179
+ onRecoverableError: (error: Error) => void,
2180
+ transitionCallbacks: null | TransitionTracingCallbacks,
2181
+ ): OpaqueRoot;
2182
+
2183
+ updateContainer(
2184
+ element: ReactNode,
2185
+ container: OpaqueRoot,
2186
+ parentComponent?: Component<any, any> | null,
2187
+ callback?: (() => void) | null,
2188
+ ): Lane;
2189
+
2190
+ batchedUpdates<A, R>(fn: (a: A) => R, a: A): R;
2191
+
2192
+ deferredUpdates<A>(fn: () => A): A;
2193
+
2194
+ 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;
2195
+
2196
+ flushControlled(fn: () => any): void;
2197
+
2198
+ flushSync(): void;
2199
+ flushSync<R>(fn: () => R): R;
2200
+
2201
+ isAlreadyRendering(): boolean;
2202
+
2203
+ flushPassiveEffects(): boolean;
2204
+
2205
+ getPublicRootInstance(container: OpaqueRoot): Component<any, any> | PublicInstance | null;
2206
+
2207
+ attemptSynchronousHydration(fiber: Fiber): void;
2208
+
2209
+ attemptDiscreteHydration(fiber: Fiber): void;
2210
+
2211
+ attemptContinuousHydration(fiber: Fiber): void;
2212
+
2213
+ attemptHydrationAtCurrentPriority(fiber: Fiber): void;
2214
+
2215
+ getCurrentUpdatePriority(): LanePriority;
2216
+
2217
+ runWithPriority<T>(priority: LanePriority, fn: () => T): T;
2218
+
2219
+ findHostInstance(component: any): PublicInstance | null;
2220
+
2221
+ findHostInstanceWithWarning(component: any, methodName: string): PublicInstance | null;
2222
+
2223
+ findHostInstanceWithNoPortals(fiber: Fiber): PublicInstance | null;
2224
+
2225
+ shouldError(fiber: Fiber): boolean | undefined;
2226
+
2227
+ shouldSuspend(fiber: Fiber): boolean;
2228
+
2229
+ injectIntoDevTools(devToolsConfig: DevToolsConfig<Instance, TextInstance, any>): boolean;
2230
+ }
2231
+ }
2232
+
2233
+ declare function extend<T extends ConstructorRepresentation>(objects: T): React$1.ExoticComponent<ThreeElement<T>>;
2234
+ declare function extend<T extends Catalogue>(objects: T): void;
2235
+ declare function extend(objects: Record<string, unknown>): void;
2236
+
2237
+ declare const reconciler: ReactReconciler.Reconciler<RootStore, Instance<any>, void, Instance<any>, never, any>;
2238
+
2239
+ declare const isRenderer: (def: any) => boolean;
2240
+ interface OffscreenCanvas extends EventTarget {
2241
+ }
2242
+ declare const _roots: Map<HTMLCanvasElement | OffscreenCanvas, Root>;
2243
+ declare function unmountComponentAtNode<TCanvas extends HTMLCanvasElement | OffscreenCanvas>(canvas: TCanvas, callback?: (canvas: TCanvas) => void): void;
2244
+ declare function createPortal(children: ReactNode, container: THREE.Object3D | RefObject<THREE.Object3D | null> | RefObject<THREE.Object3D>, state?: InjectState): JSX.Element;
2245
+ interface PortalProps {
2246
+ children: ReactNode;
2247
+ state?: InjectState;
2248
+ container: Object3D | RefObject<Object3D | null> | RefObject<Object3D>;
2249
+ }
2250
+ declare function Portal({ children, container, state }: PortalProps): JSX.Element;
2251
+ /**
2252
+ * Force React to flush any updates inside the provided callback synchronously and immediately.
2253
+ * All the same caveats documented for react-dom's `flushSync` apply here (see https://react.dev/reference/react-dom/flushSync).
2254
+ * Nevertheless, sometimes one needs to render synchronously, for example to keep DOM and 3D changes in lock-step without
2255
+ * having to revert to a non-React solution. Note: this will only flush updates within the `Canvas` root.
2256
+ */
2257
+ declare function flushSync<R>(fn: () => R): R;
2258
+
2259
+ declare const createStore: (invalidate: (state?: RootState, frames?: number, stackFrames?: boolean) => void, advance: (timestamp: number, runGlobalEffects?: boolean, state?: RootState, frame?: XRFrame) => void) => RootStore;
2260
+
2261
+ /** Whether any root has loaded a renderer yet. */
2262
+ declare function hasThree(): boolean;
2263
+ /**
2264
+ * Three's shared core: the classes and constants `three` and `three/webgpu` have in common.
2265
+ * Available once the first root's renderer support is loaded (during `configure()`), which is
2266
+ * before any element renders, any hook runs, or `onCreated` fires.
2267
+ */
2268
+ declare function getThree(): ThreeCore;
2269
+ /** Resolves with three's shared core as soon as a root has loaded one. */
2270
+ declare function whenThree(): Promise<ThreeCore>;
2271
+
2272
+ /**
2273
+ * An SSR-friendly useLayoutEffect.
2274
+ *
2275
+ * React currently throws a warning when using useLayoutEffect on the server.
2276
+ * To get around it, we can conditionally useEffect on the server (no-op) and
2277
+ * useLayoutEffect elsewhere.
2278
+ *
2279
+ * @see https://github.com/facebook/react/issues/14927
2280
+ */
2281
+ declare const useIsomorphicLayoutEffect: typeof React$1.useLayoutEffect;
2282
+ /**
2283
+ * Creates a stable ref that always contains the latest callback.
2284
+ * Useful for avoiding dependency arrays while ensuring the latest closure is called.
2285
+ *
2286
+ * @param fn - The callback function to wrap
2287
+ * @returns A ref containing the current callback
2288
+ */
2289
+ declare function useMutableCallback<T>(fn: T): React$1.RefObject<T>;
2290
+ /**
2291
+ * Bridges renderer Context and StrictMode from a primary renderer.
2292
+ * Used to maintain React context when rendering into portals or secondary canvases.
2293
+ *
2294
+ * @returns A Bridge component that wraps children with the parent renderer's context
2295
+ */
2296
+ declare function useBridge(): Bridge;
2297
+ /**
2298
+ * Internal component that blocks rendering until a promise resolves.
2299
+ * Used for suspense-like blocking behavior.
2300
+ *
2301
+ * @param set - Function to set the blocking promise
2302
+ */
2303
+ declare function Block({ set }: Omit<UnblockProps, 'children'>): null;
2304
+ /**
2305
+ * Error boundary component for catching and handling errors in the React tree.
2306
+ * Forwards errors to a state setter for external handling.
2307
+ *
2308
+ * NOTE: static members get down-level transpiled to mutations which break tree-shaking
2309
+ */
2310
+ declare const ErrorBoundary: {
2311
+ new (props: {
2312
+ set: React$1.Dispatch<Error | undefined>;
2313
+ children: React$1.ReactNode;
2314
+ }): {
2315
+ state: {
2316
+ error: boolean;
2317
+ };
2318
+ componentDidCatch(err: Error): void;
2319
+ render(): React$1.ReactNode;
2320
+ context: unknown;
2321
+ setState<K extends "error">(state: {
2322
+ error: boolean;
2323
+ } | ((prevState: Readonly<{
2324
+ error: boolean;
2325
+ }>, props: Readonly<{
2326
+ set: React$1.Dispatch<Error | undefined>;
2327
+ children: React$1.ReactNode;
2328
+ }>) => {
2329
+ error: boolean;
2330
+ } | Pick<{
2331
+ error: boolean;
2332
+ }, K> | null) | Pick<{
2333
+ error: boolean;
2334
+ }, K> | null, callback?: (() => void) | undefined): void;
2335
+ forceUpdate(callback?: (() => void) | undefined): void;
2336
+ readonly props: Readonly<{
2337
+ set: React$1.Dispatch<Error | undefined>;
2338
+ children: React$1.ReactNode;
2339
+ }>;
2340
+ componentDidMount?(): void;
2341
+ shouldComponentUpdate?(nextProps: Readonly<{
2342
+ set: React$1.Dispatch<Error | undefined>;
2343
+ children: React$1.ReactNode;
2344
+ }>, nextState: Readonly<{
2345
+ error: boolean;
2346
+ }>, nextContext: any): boolean;
2347
+ componentWillUnmount?(): void;
2348
+ getSnapshotBeforeUpdate?(prevProps: Readonly<{
2349
+ set: React$1.Dispatch<Error | undefined>;
2350
+ children: React$1.ReactNode;
2351
+ }>, prevState: Readonly<{
2352
+ error: boolean;
2353
+ }>): any;
2354
+ componentDidUpdate?(prevProps: Readonly<{
2355
+ set: React$1.Dispatch<Error | undefined>;
2356
+ children: React$1.ReactNode;
2357
+ }>, prevState: Readonly<{
2358
+ error: boolean;
2359
+ }>, snapshot?: any): void;
2360
+ componentWillMount?(): void;
2361
+ UNSAFE_componentWillMount?(): void;
2362
+ componentWillReceiveProps?(nextProps: Readonly<{
2363
+ set: React$1.Dispatch<Error | undefined>;
2364
+ children: React$1.ReactNode;
2365
+ }>, nextContext: any): void;
2366
+ UNSAFE_componentWillReceiveProps?(nextProps: Readonly<{
2367
+ set: React$1.Dispatch<Error | undefined>;
2368
+ children: React$1.ReactNode;
2369
+ }>, nextContext: any): void;
2370
+ componentWillUpdate?(nextProps: Readonly<{
2371
+ set: React$1.Dispatch<Error | undefined>;
2372
+ children: React$1.ReactNode;
2373
+ }>, nextState: Readonly<{
2374
+ error: boolean;
2375
+ }>, nextContext: any): void;
2376
+ UNSAFE_componentWillUpdate?(nextProps: Readonly<{
2377
+ set: React$1.Dispatch<Error | undefined>;
2378
+ children: React$1.ReactNode;
2379
+ }>, nextState: Readonly<{
2380
+ error: boolean;
2381
+ }>, nextContext: any): void;
2382
+ };
2383
+ new (props: {
2384
+ set: React$1.Dispatch<Error | undefined>;
2385
+ children: React$1.ReactNode;
2386
+ }, context: any): {
2387
+ state: {
2388
+ error: boolean;
2389
+ };
2390
+ componentDidCatch(err: Error): void;
2391
+ render(): React$1.ReactNode;
2392
+ context: unknown;
2393
+ setState<K extends "error">(state: {
2394
+ error: boolean;
2395
+ } | ((prevState: Readonly<{
2396
+ error: boolean;
2397
+ }>, props: Readonly<{
2398
+ set: React$1.Dispatch<Error | undefined>;
2399
+ children: React$1.ReactNode;
2400
+ }>) => {
2401
+ error: boolean;
2402
+ } | Pick<{
2403
+ error: boolean;
2404
+ }, K> | null) | Pick<{
2405
+ error: boolean;
2406
+ }, K> | null, callback?: (() => void) | undefined): void;
2407
+ forceUpdate(callback?: (() => void) | undefined): void;
2408
+ readonly props: Readonly<{
2409
+ set: React$1.Dispatch<Error | undefined>;
2410
+ children: React$1.ReactNode;
2411
+ }>;
2412
+ componentDidMount?(): void;
2413
+ shouldComponentUpdate?(nextProps: Readonly<{
2414
+ set: React$1.Dispatch<Error | undefined>;
2415
+ children: React$1.ReactNode;
2416
+ }>, nextState: Readonly<{
2417
+ error: boolean;
2418
+ }>, nextContext: any): boolean;
2419
+ componentWillUnmount?(): void;
2420
+ getSnapshotBeforeUpdate?(prevProps: Readonly<{
2421
+ set: React$1.Dispatch<Error | undefined>;
2422
+ children: React$1.ReactNode;
2423
+ }>, prevState: Readonly<{
2424
+ error: boolean;
2425
+ }>): any;
2426
+ componentDidUpdate?(prevProps: Readonly<{
2427
+ set: React$1.Dispatch<Error | undefined>;
2428
+ children: React$1.ReactNode;
2429
+ }>, prevState: Readonly<{
2430
+ error: boolean;
2431
+ }>, snapshot?: any): void;
2432
+ componentWillMount?(): void;
2433
+ UNSAFE_componentWillMount?(): void;
2434
+ componentWillReceiveProps?(nextProps: Readonly<{
2435
+ set: React$1.Dispatch<Error | undefined>;
2436
+ children: React$1.ReactNode;
2437
+ }>, nextContext: any): void;
2438
+ UNSAFE_componentWillReceiveProps?(nextProps: Readonly<{
2439
+ set: React$1.Dispatch<Error | undefined>;
2440
+ children: React$1.ReactNode;
2441
+ }>, nextContext: any): void;
2442
+ componentWillUpdate?(nextProps: Readonly<{
2443
+ set: React$1.Dispatch<Error | undefined>;
2444
+ children: React$1.ReactNode;
2445
+ }>, nextState: Readonly<{
2446
+ error: boolean;
2447
+ }>, nextContext: any): void;
2448
+ UNSAFE_componentWillUpdate?(nextProps: Readonly<{
2449
+ set: React$1.Dispatch<Error | undefined>;
2450
+ children: React$1.ReactNode;
2451
+ }>, nextState: Readonly<{
2452
+ error: boolean;
2453
+ }>, nextContext: any): void;
2454
+ };
2455
+ getDerivedStateFromError: () => {
2456
+ error: boolean;
2457
+ };
2458
+ contextType?: React$1.Context<any> | undefined;
2459
+ propTypes?: any;
2460
+ };
2461
+
2462
+ /**
2463
+ * React internal props that should not be passed to Three.js objects.
2464
+ */
2465
+ declare const REACT_INTERNAL_PROPS: string[];
2466
+ /**
2467
+ * Returns the instance's initial (outermost) root.
2468
+ * Traverses through previousRoot links to find the original root store.
2469
+ *
2470
+ * @param instance - R3F instance to find root for
2471
+ * @returns The outermost root store
2472
+ */
2473
+ declare function findInitialRoot<T>(instance: Instance<T>): RootStore;
2474
+ /**
2475
+ * Returns instance root state.
2476
+ * If the object doesn't have __r3f (e.g., child meshes in primitives/GLTFs),
2477
+ * traverses ancestors to find the nearest managed parent.
2478
+ *
2479
+ * @param obj - Three.js object to get root state for
2480
+ * @returns Root state if found, undefined otherwise
2481
+ */
2482
+ declare function getRootState<T extends THREE.Object3D = THREE.Object3D>(obj: T): RootState | undefined;
2483
+ /**
2484
+ * Collects nodes, materials, and meshes from a Three.js Object3D hierarchy.
2485
+ * Handles duplicate material names by appending UUID prefixes.
2486
+ *
2487
+ * @param object - Root object to traverse
2488
+ * @returns ObjectMap containing named nodes, materials, and meshes
2489
+ *
2490
+ * @example
2491
+ * const { nodes, materials, meshes } = buildGraph(gltf.scene)
2492
+ * // Access by name: nodes.Head, materials.Metal, meshes.Body
2493
+ */
2494
+ declare function buildGraph(object: THREE.Object3D): ObjectMap;
2495
+ /**
2496
+ * Disposes an object and all its disposable properties.
2497
+ * Skips Scene objects as they should not be disposed automatically.
2498
+ *
2499
+ * @param obj - Object to dispose
2500
+ */
2501
+ declare function dispose<T extends Disposable>(obj: T): void;
2502
+ /**
2503
+ * Extracts instance props from React reconciler fiber props.
2504
+ * Filters out React-internal props (children, key, ref).
2505
+ *
2506
+ * @param queue - Pending props from reconciler fiber
2507
+ * @returns Props object without React-internal keys
2508
+ */
2509
+ declare function getInstanceProps<T = any>(pendingProps: Record<string, unknown>): Instance<T>['props'];
2510
+ /**
2511
+ * Creates or retrieves an R3F instance descriptor for a Three.js object.
2512
+ * Each object in the scene carries a LocalState descriptor (__r3f).
2513
+ *
2514
+ * @param target - Target object to prepare
2515
+ * @param root - Root store for this instance
2516
+ * @param type - String identifier for the object type
2517
+ * @param props - Initial props for the instance
2518
+ * @returns Instance descriptor
2519
+ */
2520
+ declare function prepare<T = any>(target: T, root: RootStore, type: string, props: Instance<T>['props']): Instance<T>;
2521
+ /**
2522
+ * Triggers an update for an instance.
2523
+ * Invalidates the frame if the root is in demand mode.
2524
+ *
2525
+ * @param instance - Instance to invalidate
2526
+ */
2527
+ declare function invalidateInstance(instance: Instance): void;
2528
+
2529
+ /**
2530
+ * Reserved prop names that should not be applied to Three.js objects.
2531
+ */
2532
+ declare const RESERVED_PROPS: string[];
2533
+ /**
2534
+ * Resolves a potentially pierced property key (e.g., 'material-color' → material.color).
2535
+ * First tries the entire key as a single property, then attempts piercing.
2536
+ *
2537
+ * @param root - Root object to resolve from
2538
+ * @param key - Property key (may contain dashes for piercing)
2539
+ * @returns Object containing root, key, and target value
2540
+ *
2541
+ * @example
2542
+ * resolve(mesh, 'material-color')
2543
+ * // => { root: mesh.material, key: 'color', target: mesh.material.color }
2544
+ */
2545
+ declare function resolve(root: any, key: string): {
2546
+ root: any;
2547
+ key: string;
2548
+ target: any;
2549
+ };
2550
+ /**
2551
+ * Attaches a child instance to a parent instance.
2552
+ * Handles both string-based attachment (e.g., 'geometry', 'material-map')
2553
+ * and function-based attachment for custom logic.
2554
+ *
2555
+ * @param parent - Parent instance
2556
+ * @param child - Child instance to attach
2557
+ *
2558
+ * @example
2559
+ * // String attachment
2560
+ * <bufferGeometry attach="geometry" />
2561
+ * // Array attachment
2562
+ * <light attach="lights-0" />
2563
+ * // Function attachment
2564
+ * <thing attach={(parent, self) => { parent.customProp = self }} />
2565
+ */
2566
+ declare function attach(parent: Instance, child: Instance): void;
2567
+ /**
2568
+ * Detaches a child instance from a parent instance.
2569
+ * Restores the previous value or deletes the property if it was never set.
2570
+ *
2571
+ * @param parent - Parent instance
2572
+ * @param child - Child instance to detach
2573
+ */
2574
+ declare function detach(parent: Instance, child: Instance): void;
2575
+ /**
2576
+ * Compares old and new props to determine which properties have changed.
2577
+ * Also handles resetting removed props for HMR/fast-refresh.
2578
+ *
2579
+ * @param instance - Instance to diff props for
2580
+ * @param newProps - New props to compare against
2581
+ * @returns Object containing only changed props
2582
+ *
2583
+ * @example
2584
+ * const changes = diffProps(instance, { position: [1, 2, 3], color: 'red' })
2585
+ * // => { position: [1, 2, 3] } (only if position changed)
2586
+ */
2587
+ declare function diffProps<T = any>(instance: Instance<T>, newProps: Instance<T>['props']): Instance<T>['props'];
2588
+ /**
2589
+ * Applies a set of props to a Three.js object.
2590
+ * Handles special cases like colors, vectors, textures, events, and pierced props.
2591
+ *
2592
+ * @param object - Three.js object to apply props to
2593
+ * @param props - Props to apply
2594
+ * @returns The object with props applied
2595
+ *
2596
+ * @example
2597
+ * applyProps(mesh, { position: [0, 1, 0], 'material-color': 'red' })
2598
+ */
2599
+ declare function applyProps<T = any>(object: Instance<T>['object'], props: Instance<T>['props']): Instance<T>['object'];
2600
+
2601
+ /**
2602
+ * Calculates the device pixel ratio for rendering.
2603
+ * Handles array DPR ranges [min, max] to clamp devicePixelRatio.
2604
+ *
2605
+ * @param dpr - Target DPR value or [min, max] range
2606
+ * @returns Calculated DPR value
2607
+ *
2608
+ * @example
2609
+ * calculateDpr(2) // => 2
2610
+ * calculateDpr([1, 2]) // => clamps window.devicePixelRatio between 1 and 2
2611
+ */
2612
+ declare function calculateDpr(dpr: Dpr): number;
2613
+ /**
2614
+ * Extracts the first segment of a UUID string (before the first hyphen).
2615
+ * Used for creating unique material names when duplicates exist.
2616
+ *
2617
+ * @param uuid - UUID string to extract prefix from
2618
+ * @returns First segment of the UUID
2619
+ *
2620
+ * @example
2621
+ * getUuidPrefix('a1b2c3d4-e5f6-g7h8-i9j0') // => 'a1b2c3d4'
2622
+ */
2623
+ declare function getUuidPrefix(uuid: string): string;
2624
+ /**
2625
+ * Updates camera projection based on viewport size.
2626
+ * Adjusts aspect ratio for perspective cameras or bounds for orthographic cameras.
2627
+ * Respects camera.manual flag - manual cameras are not modified.
2628
+ *
2629
+ * @param camera - Camera to update
2630
+ * @param size - Current viewport size
2631
+ */
2632
+ declare function updateCamera(camera: ThreeCamera, size: Size): void;
2633
+ /**
2634
+ * Updates a frustum from a camera's projection and world matrices.
2635
+ * If no target frustum is provided, creates and returns a new one.
2636
+ *
2637
+ * @param camera - Camera to extract frustum from
2638
+ * @param frustum - Optional existing frustum to update (creates new if not provided)
2639
+ * @returns The updated or newly created frustum
2640
+ *
2641
+ * @example
2642
+ * // Create new frustum
2643
+ * const frustum = updateFrustum(camera)
2644
+ *
2645
+ * // Update existing frustum (no allocation)
2646
+ * updateFrustum(camera, existingFrustum)
2647
+ *
2648
+ * // Use for visibility checks
2649
+ * if (frustum.containsPoint(point)) { ... }
2650
+ * if (frustum.intersectsObject(mesh)) { ... }
2651
+ */
2652
+ declare function updateFrustum(camera: ThreeCamera, frustum?: THREE.Frustum): THREE.Frustum;
2653
+
2654
+ declare const is: {
2655
+ obj: (a: any) => boolean;
2656
+ fun: (a: any) => a is Function;
2657
+ str: (a: any) => a is string;
2658
+ num: (a: any) => a is number;
2659
+ boo: (a: any) => a is boolean;
2660
+ und: (a: any) => boolean;
2661
+ nul: (a: any) => boolean;
2662
+ arr: (a: any) => a is any[];
2663
+ equ(a: any, b: any, { arrays, objects, strict }?: EquConfig): boolean;
2664
+ };
2665
+ declare const isOrthographicCamera: (def: ThreeCamera) => def is THREE.OrthographicCamera;
2666
+ declare const isRef: (obj: unknown) => obj is React.RefObject<unknown>;
2667
+ declare const isColorRepresentation: (value: unknown) => value is THREE.ColorRepresentation;
2668
+ declare const isObject3D: (object: any) => object is THREE.Object3D;
2669
+ declare const isTexture: (value: unknown) => value is THREE.Texture;
2670
+ declare const isLayers: (value: unknown) => value is THREE.Layers;
2671
+ declare const isUniform: (value: unknown) => value is THREE.Uniform;
2672
+ type VectorLike = {
2673
+ set: (...args: any[]) => void;
2674
+ constructor?: Function;
2675
+ };
2676
+ declare const isVectorLike: (object: unknown) => object is VectorLike;
2677
+ type Copyable = {
2678
+ copy: (...args: any[]) => void;
2679
+ constructor?: Function;
2680
+ };
2681
+ declare const isCopyable: (object: unknown) => object is Copyable;
2682
+ declare const hasConstructor: (object: unknown) => object is {
2683
+ constructor?: Function;
2684
+ };
2685
+
2686
+ /**
2687
+ * Symbol marker for deferred ref resolution.
2688
+ * Used to identify values that should be resolved from refs after mount.
2689
+ */
2690
+ declare const FROM_REF: unique symbol;
2691
+ /** The marker `fromRef()` returns; resolved by the reconciler in `commitMount`. */
2692
+ interface FromRefMarker<T = unknown, R = T> {
2693
+ [FROM_REF]: React$1.RefObject<T | null>;
2694
+ /** Optional transform applied to the resolved ref before assignment. */
2695
+ transform?: (value: T) => R;
2696
+ }
2697
+ /**
2698
+ * Defers prop application until the referenced object is available.
2699
+ * Useful for props like `target` that need sibling refs to be populated.
2700
+ *
2701
+ * Only top-level props on a three element are resolved: a marker nested inside another value
2702
+ * (an array, an options object) is never seen. When the prop needs the sibling *wrapped* rather
2703
+ * than assigned as-is, pass a `transform`; it runs once the ref is populated and its result is
2704
+ * what gets assigned.
2705
+ *
2706
+ * @param ref - React ref object to resolve at mount time
2707
+ * @param transform - Optional mapping from the resolved object to the value the prop expects
2708
+ * @returns A marker value that the reconciler resolves after mount
2709
+ *
2710
+ * @example
2711
+ * const targetRef = useRef<THREE.Object3D>(null)
2712
+ *
2713
+ * <group ref={targetRef} position={[-3, -2, -15]} />
2714
+ * <spotLight target={fromRef(targetRef)} intensity={100} />
2715
+ *
2716
+ * @example
2717
+ * // Wrap the sibling: a node material's lightsNode needs a LightsNode, not the light itself
2718
+ * <meshPhongNodeMaterial lightsNode={fromRef(lightRef, (light) => lights([light]))} />
2719
+ */
2720
+ declare function fromRef<T>(ref: React$1.RefObject<T | null>): T;
2721
+ declare function fromRef<T, R>(ref: React$1.RefObject<T | null>, transform: (value: T) => R): R;
2722
+ /**
2723
+ * Type guard to check if a value is a fromRef marker.
2724
+ *
2725
+ * @param value - Value to check
2726
+ * @returns True if value is a fromRef marker
2727
+ */
2728
+ declare function isFromRef(value: unknown): value is FromRefMarker<any, unknown>;
2729
+
2730
+ /**
2731
+ * Symbol marker for mount-only method calls.
2732
+ * Used to identify methods that should only be called once on initial mount.
2733
+ */
2734
+ declare const ONCE: unique symbol;
2735
+ /**
2736
+ * Marks a method call to be executed only on initial mount.
2737
+ * Useful for geometry transforms that should not be reapplied on every render.
2738
+ *
2739
+ * When `args` prop changes (triggering reconstruction), the method will be
2740
+ * called again on the new instance since appliedOnce is not carried over.
2741
+ *
2742
+ * @param args - Arguments to pass to the method
2743
+ * @returns A marker value that applyProps will execute once
2744
+ *
2745
+ * @example
2746
+ * // Rotate geometry on mount
2747
+ * <boxGeometry args={[1, 1, 1]} rotateX={once(Math.PI / 2)} />
2748
+ *
2749
+ * // Multiple arguments
2750
+ * <bufferGeometry applyMatrix4={once(matrix)} />
2751
+ *
2752
+ * // No arguments
2753
+ * <geometry center={once()} />
2754
+ */
2755
+ declare function once<A extends unknown[]>(...args: A): OnceValue<A>;
2756
+ /**
2757
+ * What `once(...args)` is typed as, so the marker is assignable to the prop it targets:
2758
+ * the single argument itself (`rotateX={once(angle)}`), the argument tuple for multi-argument
2759
+ * methods (`translate={once(x, y, z)}`), or `true` for a bare call (`center={once()}`).
2760
+ *
2761
+ * The runtime value is always the marker object; only the declared type follows the prop.
2762
+ */
2763
+ type OnceValue<A extends unknown[]> = A extends [] ? true : A extends [infer Single] ? Single : A;
2764
+ /**
2765
+ * Type guard to check if a value is a once marker.
2766
+ *
2767
+ * @param value - Value to check
2768
+ * @returns True if value is a once marker
2769
+ */
2770
+ declare function isOnce(value: unknown): value is {
2771
+ [ONCE]: any[] | true;
2772
+ };
2773
+
2774
+ export { REACT_INTERNAL_PROPS as a$, Texture as aA, useTextures as aF, useEnvironment as aH, addEffect as aI, addAfterEffect as aJ, addTail as aK, invalidate as aL, advance as aM, extend as aN, reconciler as aO, isRenderer as aP, _roots as aQ, unmountComponentAtNode as aR, createPortal as aS, Portal as aT, flushSync as aU, createStore as aV, useIsomorphicLayoutEffect as aW, useMutableCallback as aX, useBridge as aY, Block as aZ, ErrorBoundary as a_, registerPrimary as ad, getPrimary as ae, waitForPrimary as af, hasPrimary as ag, unregisterPrimary as ah, getPrimaryIds as ai, EnvironmentMap as ak, EnvironmentCube as al, EnvironmentPortal as am, Environment as an, presetsObj as ao, swapInteractivity as aq, removeInteractivity as ar, createEvents as as, useInstanceHandle as at, useGraph as au, useLoader as av, IsObject as aw, useTexture as az, findInitialRoot as b0, getRootState as b1, buildGraph as b2, dispose as b3, getInstanceProps as b4, prepare as b5, invalidateInstance as b6, RESERVED_PROPS as b7, resolve as b8, attach as b9, detach as ba, diffProps as bb, applyProps as bc, calculateDpr as bd, getUuidPrefix as be, updateCamera as bf, updateFrustum as bg, is as bh, isOrthographicCamera as bi, isRef as bj, isColorRepresentation as bk, isObject3D as bl, isTexture as bm, isLayers as bn, isUniform as bo, isVectorLike as bp, isCopyable as bq, hasConstructor as br, FROM_REF as bs, fromRef as bu, isFromRef as bv, ONCE as bw, once as bx, isOnce as bz, createPointerEvents as u, getThree as v, hasThree as w, whenThree as x };
2775
+ export type { InputLike as $, Renderer as A, BaseRendererProps as B, Color as C, ColorManagementConfig as D, Euler as E, DefaultGLProps as F, GeometryTransformProps as G, GLProps as H, DefaultRendererProps as I, CanvasSchedulerConfig as J, RendererConfigExtended as K, Layers as L, MutableOrReadonlyParameters as M, NodeProps as N, Object3DMethod as O, RendererProps as P, Quaternion as Q, RaycastableRepresentation as R, CameraProps as S, TSLNodeInput as T, RenderProps as U, VectorRepresentation as V, InjectState as W, GlobalRenderCallback as X, GlobalEffectType as Y, BackgroundConfig as Z, BackgroundProp as _, MathRepresentation as a, LoaderLike as a0, GLTFLike as a1, LoaderInstance as a2, InferLoadResult as a3, LoaderResult as a4, Extensions as a5, WebGLDefaultProps as a6, WebGLProps as a7, WebGLShadowConfig as a8, LegacyRenderer as a9, TextureInput as aB, TextureResult as aC, DisposeOptions as aD, UseTexturesReturn as aE, EnvironmentLoaderProps as aG, LegacyInternalState as aa, LegacyRootState as ab, PrimaryCanvasEntry as ac, EnvironmentProps as aj, PresetsType as ap, MappedTextureType as ax, UseTextureOptions as ay, MathTypes as b, FromRefMarker as bt, OnceValue as by, MathType as c, MathProps as d, Vector2 as e, Vector3 as f, Vector4 as g, Matrix3 as h, Matrix4 as i, EventProps as j, GeometryProps as k, ReactProps as l, ElementProps as m, ThreeElement as n, ThreeToJSXElements as o, ThreeElementsOf as p, ElementOf as q, RenderTargetOptions as r, ReconcilerRoot as s, CanvasProps as t, OffscreenCanvas$1 as y, RendererFactory as z };