@react-three/fiber 9.0.0-alpha.0 → 9.0.0-alpha.2

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,95 @@
1
1
  # @react-three/fiber
2
2
 
3
+ ## 8.8.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 370d3ae5: refactor: pull context bridge from its-fine
8
+
9
+ ## 8.8.0
10
+
11
+ ### Minor Changes
12
+
13
+ - 46d8b440: bridge cross-container context
14
+
15
+ ## 8.7.4
16
+
17
+ ### Patch Changes
18
+
19
+ - 259c8895: fix: use self to get global context before window
20
+
21
+ ## 8.7.3
22
+
23
+ ### Patch Changes
24
+
25
+ - eb5a3be4: fix: if there is an eventsource pointerevent will be set to none
26
+
27
+ ## 8.7.2
28
+
29
+ ### Patch Changes
30
+
31
+ - 7f801e60: fix: events in portals carry the wrong raycaster, camera, etc
32
+
33
+ ## 8.7.1
34
+
35
+ ### Patch Changes
36
+
37
+ - 962cc270: fix: allow canvas eventsource to be a ref
38
+
39
+ ## 8.7.0
40
+
41
+ ### Minor Changes
42
+
43
+ - f5db1b78: feat: useInstanceHandle, flushGlobalEffects
44
+
45
+ ## 8.6.2
46
+
47
+ ### Patch Changes
48
+
49
+ - 57c12e9c: fix(types): @react-three/drei declaration files
50
+
51
+ ## 8.6.1
52
+
53
+ ### Patch Changes
54
+
55
+ - 7a0b5670: fix(core): don't append to unmounted containers
56
+
57
+ ## 8.6.0
58
+
59
+ ### Minor Changes
60
+
61
+ - 85c80e70: eventsource and eventprefix on the canvas component
62
+
63
+ ## 8.5.1
64
+
65
+ ### Patch Changes
66
+
67
+ - 87821d9: fix: null-check instance.children on reconstruct
68
+
69
+ ## 8.5.0
70
+
71
+ ### Minor Changes
72
+
73
+ - edc8252: feat: handle primitive children, auto-attach via instanceof
74
+
75
+ ## 8.3.1
76
+
77
+ ### Patch Changes
78
+
79
+ - aaeb2b8: fix(types): accept readonly arrays for vector props
80
+
81
+ ## 8.3.0
82
+
83
+ ### Minor Changes
84
+
85
+ - 9c450ec: feat: improve errors
86
+
87
+ ## 8.2.3
88
+
89
+ ### Patch Changes
90
+
91
+ - b8d2eab: fix: improve useLoader signature, initial size on createRoot
92
+
3
93
  ## 8.2.2
4
94
 
5
95
  ### Patch Changes
@@ -1,9 +1,12 @@
1
1
  import * as THREE from 'three';
2
+ import * as React from 'react';
2
3
  import { StateSelector, EqualityChecker } from 'zustand';
3
4
  import { GLTF } from 'three/examples/jsm/loaders/GLTFLoader';
4
5
  import { RootState, RenderCallback, StageTypes } from './store';
5
6
  import { ObjectMap } from './utils';
6
7
  import { UpdateCallback } from './stages';
8
+ import { LoadingManager } from 'three';
9
+ import { Instance } from './renderer';
7
10
  export interface Loader<T> extends THREE.Loader {
8
11
  load(url: string, onLoad?: (result: T) => void, onProgress?: (event: ProgressEvent) => void, onError?: (event: ErrorEvent) => void): unknown;
9
12
  }
@@ -11,12 +14,13 @@ export declare type Extensions = (loader: THREE.Loader) => void;
11
14
  export declare type LoaderResult<T> = T extends any[] ? Loader<T[number]> : Loader<T>;
12
15
  export declare type ConditionalType<Child, Parent, Truthy, Falsy> = Child extends Parent ? Truthy : Falsy;
13
16
  export declare type BranchingReturn<T, Parent, Coerced> = ConditionalType<T, Parent, Coerced, T>;
17
+ export declare function useInstanceHandle<O>(ref: React.MutableRefObject<O>): React.MutableRefObject<Instance>;
14
18
  export declare function useStore(): import("zustand").UseBoundStore<RootState, import("zustand").StoreApi<RootState>>;
15
19
  export declare function useThree<T = RootState>(selector?: StateSelector<RootState, T>, equalityFn?: EqualityChecker<T>): T;
16
20
  export declare function useFrame(callback: RenderCallback, renderPriority?: number): null;
17
21
  export declare function useUpdate(callback: UpdateCallback, stage?: StageTypes): void;
18
22
  export declare function useGraph(object: THREE.Object3D): ObjectMap;
19
- export declare function useLoader<T, U extends string | string[]>(Proto: new () => LoaderResult<T>, input: U, extensions?: Extensions, onProgress?: (event: ProgressEvent<EventTarget>) => void): U extends any[] ? BranchingReturn<T, GLTF, GLTF & ObjectMap>[] : BranchingReturn<T, GLTF, GLTF & ObjectMap>;
23
+ export declare function useLoader<T, U extends string | string[]>(Proto: new (manager?: LoadingManager) => LoaderResult<T>, input: U, extensions?: Extensions, onProgress?: (event: ProgressEvent<EventTarget>) => void): U extends any[] ? BranchingReturn<T, GLTF, GLTF & ObjectMap>[] : BranchingReturn<T, GLTF, GLTF & ObjectMap>;
20
24
  export declare namespace useLoader {
21
25
  var preload: <T, U extends string | string[]>(Proto: new () => LoaderResult<T>, input: U, extensions?: Extensions | undefined) => undefined;
22
26
  var clear: <T, U extends string | string[]>(Proto: new () => LoaderResult<T>, input: U) => void;
@@ -1,18 +1,16 @@
1
1
  /// <reference types="webxr" />
2
- /// <reference types="react-reconciler" />
3
2
  import * as THREE from 'three';
4
3
  import * as React from 'react';
5
- import { StoreApi, UseBoundStore } from 'zustand';
6
- import * as ReactThreeFiber from '../three-types';
4
+ import { UseBoundStore } from 'zustand';
5
+ import { ThreeElement } from '../three-types';
7
6
  import { Renderer, context, RootState, Size, Dpr, Performance, PrivateKeys, Frameloop } from './store';
8
- import { extend, Root } from './renderer';
7
+ import { reconciler, extend, Root } from './renderer';
9
8
  import { addEffect, addAfterEffect, addTail } from './loop';
10
9
  import { EventManager, ComputeFunction } from './events';
11
- import { dispose, getRootState, Camera } from './utils';
10
+ import { dispose, getRootState, Camera, applyProps } from './utils';
12
11
  import { Stage } from './stages';
13
12
  declare const roots: Map<Element, Root>;
14
13
  declare const invalidate: (state?: RootState | undefined, frames?: number) => void, advance: (timestamp: number, runGlobalEffects?: boolean, state?: RootState | undefined, frame?: XRFrame | undefined) => void;
15
- declare const reconciler: import("react-reconciler").Reconciler<UseBoundStore<RootState, StoreApi<RootState>>, import("./renderer").Instance, void, import("./renderer").Instance, import("./renderer").Instance>, applyProps: typeof import("./utils").applyProps;
16
14
  declare type Properties<T> = Pick<T, {
17
15
  [K in keyof T]: T[K] extends (_: any) => any ? never : K;
18
16
  }[keyof T]>;
@@ -29,7 +27,7 @@ export declare type RenderProps<TCanvas extends Element> = {
29
27
  performance?: Partial<Omit<Performance, 'regress'>>;
30
28
  dpr?: Dpr;
31
29
  raycaster?: Partial<THREE.Raycaster>;
32
- camera?: (Camera | Partial<ReactThreeFiber.Object3DNode<THREE.Camera, typeof THREE.Camera> & ReactThreeFiber.Object3DNode<THREE.PerspectiveCamera, typeof THREE.PerspectiveCamera> & ReactThreeFiber.Object3DNode<THREE.OrthographicCamera, typeof THREE.OrthographicCamera>>) & {
30
+ camera?: (Camera | Partial<ThreeElement<typeof THREE.Camera> & ThreeElement<typeof THREE.PerspectiveCamera> & ThreeElement<typeof THREE.OrthographicCamera>>) & {
33
31
  manual?: boolean;
34
32
  };
35
33
  events?: (store: UseBoundStore<RootState>) => EventManager<HTMLElement>;
@@ -56,6 +54,7 @@ export declare type InjectState = Partial<Omit<RootState, PrivateKeys> & {
56
54
  size?: Size;
57
55
  }>;
58
56
  declare function createPortal(children: React.ReactNode, container: THREE.Object3D, state?: InjectState): React.ReactNode;
59
- declare const act: any;
57
+ declare type Act = <T = any>(cb: () => Promise<T>) => Promise<T>;
58
+ declare const act: Act;
60
59
  export * from './hooks';
61
- export { context, render, createRoot, unmountComponentAtNode, createPortal, reconciler, applyProps, dispose, invalidate, advance, extend, addEffect, addAfterEffect, addTail, getRootState, act, roots as _roots, };
60
+ export { context, render, createRoot, unmountComponentAtNode, createPortal, reconciler, applyProps, dispose, invalidate, advance, extend, addEffect, addAfterEffect, addTail, getRootState, Act, act, roots as _roots, };
@@ -5,6 +5,8 @@ declare type GlobalRenderCallback = (timeStamp: number) => void;
5
5
  export declare const addEffect: (callback: GlobalRenderCallback) => () => void;
6
6
  export declare const addAfterEffect: (callback: GlobalRenderCallback) => () => void;
7
7
  export declare const addTail: (callback: GlobalRenderCallback) => () => void;
8
+ export declare type GlobalEffectType = 'before' | 'after' | 'tail';
9
+ export declare function flushGlobalEffects(type: GlobalEffectType, timestamp: number): void;
8
10
  export declare function createLoop<TCanvas>(roots: Map<TCanvas, Root>): {
9
11
  loop: (timestamp: number) => void;
10
12
  invalidate: (state?: RootState | undefined, frames?: number) => void;
@@ -1,51 +1,40 @@
1
- import * as THREE from 'three';
2
1
  import { UseBoundStore } from 'zustand';
3
2
  import Reconciler from 'react-reconciler';
4
- import { prepare, applyProps } from './utils';
5
3
  import { RootState } from './store';
6
4
  import { EventHandlers } from './events';
7
- export declare type Root = {
5
+ export interface Root {
8
6
  fiber: Reconciler.FiberRoot;
9
7
  store: UseBoundStore<RootState>;
10
- };
11
- export declare type LocalState = {
12
- type: string;
8
+ }
9
+ export declare type AttachFnType<O = any> = (parent: any, self: O) => () => void;
10
+ export declare type AttachType<O = any> = string | AttachFnType<O>;
11
+ export declare type ConstructorRepresentation = new (...args: any[]) => any;
12
+ export interface Catalogue {
13
+ [name: string]: ConstructorRepresentation;
14
+ }
15
+ export declare type Args<T> = T extends ConstructorRepresentation ? ConstructorParameters<T> : any[];
16
+ export interface InstanceProps<T = any> {
17
+ args?: Args<T>;
18
+ object?: T;
19
+ visible?: boolean;
20
+ dispose?: null;
21
+ attach?: AttachType<T>;
22
+ }
23
+ export interface Instance<O = any> {
13
24
  root: UseBoundStore<RootState>;
14
- objects: Instance[];
25
+ type: string;
15
26
  parent: Instance | null;
16
- primitive?: boolean;
27
+ children: Instance[];
28
+ props: InstanceProps<O> & Record<string, unknown>;
29
+ object: O & {
30
+ __r3f?: Instance<O>;
31
+ };
17
32
  eventCount: number;
18
33
  handlers: Partial<EventHandlers>;
19
- attach?: AttachType;
20
- previousAttach: any;
21
- memoizedProps: {
22
- [key: string]: any;
23
- };
24
- };
25
- export declare type AttachFnType = (parent: Instance, self: Instance) => () => void;
26
- export declare type AttachType = string | AttachFnType;
27
- export declare type BaseInstance = Omit<THREE.Object3D, 'children' | 'attach' | 'add' | 'remove' | 'raycast'> & {
28
- __r3f: LocalState;
29
- children: Instance[];
30
- remove: (...object: Instance[]) => Instance;
31
- add: (...object: Instance[]) => Instance;
32
- raycast?: (raycaster: THREE.Raycaster, intersects: THREE.Intersection[]) => void;
33
- };
34
- export declare type Instance = BaseInstance & {
35
- [key: string]: any;
36
- };
37
- export declare type InstanceProps = {
38
- [key: string]: unknown;
39
- } & {
40
- args?: any[];
41
- object?: object;
42
- visible?: boolean;
43
- dispose?: null;
44
- attach?: AttachType;
45
- };
46
- declare let extend: (objects: object) => void;
47
- declare function createRenderer<TCanvas>(_roots: Map<TCanvas, Root>, _getEventPriority?: () => any): {
48
- reconciler: Reconciler.Reconciler<UseBoundStore<RootState, import("zustand").StoreApi<RootState>>, Instance, void, Instance, Instance>;
49
- applyProps: typeof applyProps;
50
- };
51
- export { prepare, createRenderer, extend };
34
+ attach?: AttachType<O>;
35
+ previousAttach?: any;
36
+ isHidden: boolean;
37
+ }
38
+ declare const extend: (objects: Partial<Catalogue>) => void;
39
+ declare const reconciler: Reconciler.Reconciler<UseBoundStore<RootState, import("zustand").StoreApi<RootState>>, Instance<any>, void, Instance<any>, any>;
40
+ export { extend, reconciler };
@@ -21,7 +21,6 @@ export declare type Size = {
21
21
  height: number;
22
22
  top: number;
23
23
  left: number;
24
- updateStyle?: boolean;
25
24
  };
26
25
  export declare type Viewport = Size & {
27
26
  initialDpr: number;
@@ -98,7 +97,7 @@ export declare type RootState = {
98
97
  invalidate: (frames?: number) => void;
99
98
  advance: (timestamp: number, runGlobalEffects?: boolean) => void;
100
99
  setEvents: (events: Partial<EventManager<any>>) => void;
101
- setSize: (width: number, height: number, updateStyle?: boolean, top?: number, left?: number) => void;
100
+ setSize: (width: number, height: number, top?: number, left?: number) => void;
102
101
  setDpr: (dpr: Dpr) => void;
103
102
  setFrameloop: (frameloop: Frameloop) => void;
104
103
  onPointerMissed?: (event: MouseEvent) => void;
@@ -1,9 +1,12 @@
1
1
  import * as THREE from 'three';
2
2
  import * as React from 'react';
3
- import { AttachType, Instance, InstanceProps, LocalState } from './renderer';
4
- import { Dpr, RootState, Size } from './store';
3
+ import type { Fiber } from 'react-reconciler';
4
+ import type { UseBoundStore } from 'zustand';
5
+ import type { Dpr, RootState, Size } from './store';
6
+ import type { Instance } from './renderer';
5
7
  export declare type Camera = THREE.OrthographicCamera | THREE.PerspectiveCamera;
6
8
  export declare const isOrthographicCamera: (def: Camera) => def is THREE.OrthographicCamera;
9
+ export declare const isRef: (obj: any) => obj is React.MutableRefObject<unknown>;
7
10
  export declare const useIsomorphicLayoutEffect: typeof React.useLayoutEffect;
8
11
  export declare function useMutableCallback<T>(fn: T): React.MutableRefObject<T>;
9
12
  export declare type SetBlock = false | Promise<null> | null;
@@ -13,7 +16,7 @@ export declare type UnblockProps = {
13
16
  };
14
17
  export declare function Block({ set }: Omit<UnblockProps, 'children'>): null;
15
18
  export declare class ErrorBoundary extends React.Component<{
16
- set: React.Dispatch<any>;
19
+ set: React.Dispatch<Error | undefined>;
17
20
  children: React.ReactNode;
18
21
  }, {
19
22
  error: boolean;
@@ -24,35 +27,24 @@ export declare class ErrorBoundary extends React.Component<{
24
27
  static getDerivedStateFromError: () => {
25
28
  error: boolean;
26
29
  };
27
- componentDidCatch(error: any): void;
30
+ componentDidCatch(err: Error): void;
28
31
  render(): React.ReactNode;
29
32
  }
30
- export declare const DEFAULT = "__default";
31
- export declare type DiffSet = {
32
- memoized: {
33
- [key: string]: any;
34
- };
35
- changes: [key: string, value: unknown, isEvent: boolean, keys: string[]][];
36
- };
37
- export declare const isDiffSet: (def: any) => def is DiffSet;
38
- export declare type ClassConstructor = {
39
- new (): void;
40
- };
41
- export declare type ObjectMap = {
33
+ export interface ObjectMap {
42
34
  nodes: {
43
35
  [name: string]: THREE.Object3D;
44
36
  };
45
37
  materials: {
46
38
  [name: string]: THREE.Material;
47
39
  };
48
- };
40
+ }
49
41
  export declare function calculateDpr(dpr: Dpr): number;
50
- export declare const getRootState: (obj: THREE.Object3D) => RootState | undefined;
51
- export declare type EquConfig = {
42
+ export declare const getRootState: <T = THREE.Object3D<THREE.Event>>(obj: T) => RootState | undefined;
43
+ export interface EquConfig {
52
44
  arrays?: 'reference' | 'shallow';
53
45
  objects?: 'reference' | 'shallow';
54
46
  strict?: boolean;
55
- };
47
+ }
56
48
  export declare const is: {
57
49
  obj: (a: any) => boolean;
58
50
  fun: (a: any) => a is Function;
@@ -64,18 +56,25 @@ export declare const is: {
64
56
  equ(a: any, b: any, { arrays, objects, strict }?: EquConfig): boolean;
65
57
  };
66
58
  export declare function buildGraph(object: THREE.Object3D): ObjectMap;
67
- export declare function dispose<TObj extends {
68
- dispose?: () => void;
59
+ export interface Disposable {
69
60
  type?: string;
70
- [key: string]: any;
71
- }>(obj: TObj): void;
72
- export declare function prepare<T = THREE.Object3D>(object: T, state?: Partial<LocalState>): T;
73
- export declare function attach(parent: Instance, child: Instance, type: AttachType): void;
74
- export declare function detach(parent: Instance, child: Instance, type: AttachType): void;
75
- export declare function diffProps(instance: Instance, { children: cN, key: kN, ref: rN, ...props }: InstanceProps, { children: cP, key: kP, ref: rP, ...previous }?: InstanceProps, remove?: boolean): DiffSet;
76
- export declare function applyProps(instance: Instance, data: InstanceProps | DiffSet): Instance;
61
+ dispose?: () => void;
62
+ }
63
+ export declare function dispose<T extends Disposable>(obj: T): void;
64
+ export declare const REACT_INTERNAL_PROPS: string[];
65
+ export declare function getInstanceProps<T = any>(queue: Fiber['pendingProps']): Instance<T>['props'];
66
+ export declare function prepare<T = any>(target: T, root: UseBoundStore<RootState>, type: string, props: Instance<T>['props']): Instance<T>;
67
+ export declare function resolve(root: any, key: string): {
68
+ root: any;
69
+ key: string;
70
+ target: any;
71
+ };
72
+ export declare function attach(parent: Instance, child: Instance): void;
73
+ export declare function detach(parent: Instance, child: Instance): void;
74
+ export declare const RESERVED_PROPS: string[];
75
+ export declare function diffProps<T = any>(instance: Instance<T>, newProps: Instance<T>['props'], resetRemoved?: boolean): Instance<T>['props'];
76
+ export declare function applyProps<T = any>(object: Instance<T>['object'], props: Instance<T>['props']): Instance<T>['object'];
77
77
  export declare function invalidateInstance(instance: Instance): void;
78
- export declare function updateInstance(instance: Instance): void;
79
78
  export declare function updateCamera(camera: Camera & {
80
79
  manual?: boolean;
81
80
  }, size: Size): void;
@@ -1,7 +1,5 @@
1
1
  export * from './three-types';
2
- import * as ReactThreeFiber from './three-types';
3
- export { ReactThreeFiber };
4
- export type { BaseInstance, LocalState } from './core/renderer';
2
+ export type { AttachFnType, AttachType, ConstructorRepresentation, Catalogue, Args, InstanceProps, Instance, } from './core/renderer';
5
3
  export type { Intersection, Subscription, Dpr, Size, Viewport, RenderCallback, Performance, RootState, } from './core/store';
6
4
  export type { ThreeEvent, Events, EventManager, ComputeFunction } from './core/events';
7
5
  export type { ObjectMap, Camera } from './core/utils';
@@ -1,8 +1,8 @@
1
1
  import * as React from 'react';
2
2
  import { View, ViewProps, ViewStyle } from 'react-native';
3
3
  import { RenderProps } from '../core';
4
- export interface Props extends Omit<RenderProps<HTMLCanvasElement>, 'size' | 'dpr'>, ViewProps {
4
+ export interface CanvasProps extends Omit<RenderProps<HTMLCanvasElement>, 'size' | 'dpr'>, ViewProps {
5
5
  children: React.ReactNode;
6
6
  style?: ViewStyle;
7
7
  }
8
- export declare const Canvas: React.ForwardRefExoticComponent<Props & React.RefAttributes<View>>;
8
+ export declare const Canvas: React.ForwardRefExoticComponent<CanvasProps & React.RefAttributes<View>>;
@@ -1,7 +1,5 @@
1
1
  export * from './three-types';
2
- import * as ReactThreeFiber from './three-types';
3
- export { ReactThreeFiber };
4
- export type { BaseInstance, LocalState } from './core/renderer';
2
+ export type { AttachFnType, AttachType, ConstructorRepresentation, Catalogue, Args, InstanceProps, Instance, } from './core/renderer';
5
3
  export type { Intersection, Subscription, Dpr, Size, Viewport, RenderCallback, Performance, RootState, } from './core/store';
6
4
  export type { ThreeEvent, Events, EventManager, ComputeFunction } from './core/events';
7
5
  export type { ObjectMap, Camera } from './core/utils';