@react-three/fiber 10.0.0-canary.ea31ccd → 10.0.0-canary.ee5a08a

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