@react-three/fiber 10.0.0-canary.cdaab7c → 10.0.0-canary.d0fe0de

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