@react-three/fiber 10.0.0-canary.979dc2d → 10.0.0-canary.98da52a

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