@react-three/fiber 8.0.0-beta.4 → 8.0.0-beta.7

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.
@@ -1,21 +1,20 @@
1
1
  import * as THREE from 'three';
2
- import type { UseStore } from 'zustand';
2
+ import type { UseBoundStore } from 'zustand';
3
3
  import type { RootState } from './store';
4
4
  export interface Intersection extends THREE.Intersection {
5
5
  eventObject: THREE.Object3D;
6
6
  }
7
7
  export interface IntersectionEvent<TSourceEvent> extends Intersection {
8
+ eventObject: THREE.Object3D;
8
9
  intersections: Intersection[];
9
- stopped: boolean;
10
10
  unprojectedPoint: THREE.Vector3;
11
+ pointer: THREE.Vector2;
12
+ delta: number;
11
13
  ray: THREE.Ray;
12
14
  camera: Camera;
13
15
  stopPropagation: () => void;
14
- sourceEvent: TSourceEvent;
15
16
  nativeEvent: TSourceEvent;
16
- delta: number;
17
- spaceX: number;
18
- spaceY: number;
17
+ stopped: boolean;
19
18
  }
20
19
  export declare type Camera = THREE.OrthographicCamera | THREE.PerspectiveCamera;
21
20
  export declare type ThreeEvent<TEvent> = IntersectionEvent<TEvent>;
@@ -47,8 +46,14 @@ export declare type EventHandlers = {
47
46
  onPointerCancel?: (event: ThreeEvent<PointerEvent>) => void;
48
47
  onWheel?: (event: ThreeEvent<WheelEvent>) => void;
49
48
  };
49
+ export declare type FilterFunction = (items: THREE.Intersection[], state: RootState) => THREE.Intersection[];
50
+ export declare type ComputeFunction = (event: DomEvent, root: RootState, previous?: RootState) => void;
50
51
  export interface EventManager<TTarget> {
51
- connected: TTarget | boolean;
52
+ enabled: boolean;
53
+ priority: number;
54
+ compute?: ComputeFunction;
55
+ filter?: FilterFunction;
56
+ connected?: TTarget;
52
57
  handlers?: Events;
53
58
  connect?: (target: TTarget) => void;
54
59
  disconnect?: () => void;
@@ -58,7 +63,7 @@ export interface PointerCaptureTarget {
58
63
  target: Element;
59
64
  }
60
65
  export declare function getEventPriority(): any;
61
- export declare function removeInteractivity(store: UseStore<RootState>, object: THREE.Object3D): void;
62
- export declare function createEvents(store: UseStore<RootState>): {
66
+ export declare function removeInteractivity(store: UseBoundStore<RootState>, object: THREE.Object3D): void;
67
+ export declare function createEvents(store: UseBoundStore<RootState>): {
63
68
  handlePointer: (name: string) => (event: DomEvent) => void;
64
69
  };
@@ -10,12 +10,16 @@ export declare type Extensions = (loader: THREE.Loader) => void;
10
10
  export declare type LoaderResult<T> = T extends any[] ? Loader<T[number]> : Loader<T>;
11
11
  export declare type ConditionalType<Child, Parent, Truthy, Falsy> = Child extends Parent ? Truthy : Falsy;
12
12
  export declare type BranchingReturn<T, Parent, Coerced> = ConditionalType<T, Parent, Coerced, T>;
13
- export declare function useStore(): import("zustand").UseStore<RootState, import("zustand").StoreApi<RootState>>;
13
+ declare type noop = (...args: any[]) => any;
14
+ declare type PickFunction<T extends noop> = (...args: Parameters<T>) => ReturnType<T>;
15
+ export declare function useStore(): import("zustand").UseBoundStore<RootState, import("zustand").StoreApi<RootState>>;
14
16
  export declare function useThree<T = RootState>(selector?: StateSelector<RootState, T>, equalityFn?: EqualityChecker<T>): T;
15
17
  export declare function useFrame(callback: RenderCallback, renderPriority?: number): null;
16
18
  export declare function useGraph(object: THREE.Object3D): ObjectMap;
19
+ export declare function useMemoizedFn<T extends noop>(fn?: T): PickFunction<T>;
17
20
  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>;
18
21
  export declare namespace useLoader {
19
22
  var preload: <T, U extends string | string[]>(Proto: new () => LoaderResult<T>, input: U, extensions?: Extensions | undefined) => undefined;
20
23
  var clear: <T, U extends string | string[]>(Proto: new () => LoaderResult<T>, input: U) => void;
21
24
  }
25
+ export {};
@@ -1,12 +1,12 @@
1
1
  /// <reference types="react-reconciler" />
2
2
  import * as THREE from 'three';
3
3
  import * as React from 'react';
4
- import { UseStore } from 'zustand';
4
+ import { UseBoundStore } from 'zustand';
5
5
  import { Renderer, StoreProps, context, RootState, Size } from './store';
6
6
  import { extend, Root } from './renderer';
7
7
  import { addEffect, addAfterEffect, addTail } from './loop';
8
- import { EventManager } from './events';
9
- import { dispose } from './utils';
8
+ import { EventManager, ComputeFunction } from './events';
9
+ import { dispose, getRootState } from './utils';
10
10
  declare const roots: Map<Element, Root>;
11
11
  declare const invalidate: (state?: RootState | undefined) => void, advance: (timestamp: number, runGlobalEffects?: boolean, state?: RootState | undefined, frame?: THREE.XRFrame | undefined) => void;
12
12
  declare const reconciler: import("react-reconciler").Reconciler<unknown, unknown, unknown, unknown, unknown>, applyProps: typeof import("./utils").applyProps;
@@ -16,19 +16,27 @@ declare type Properties<T> = Pick<T, {
16
16
  declare type GLProps = Renderer | ((canvas: HTMLCanvasElement) => Renderer) | Partial<Properties<THREE.WebGLRenderer> | THREE.WebGLRendererParameters> | undefined;
17
17
  export declare type RenderProps<TCanvas extends Element> = Omit<StoreProps, 'gl' | 'events' | 'size'> & {
18
18
  gl?: GLProps;
19
- events?: (store: UseStore<RootState>) => EventManager<TCanvas>;
19
+ events?: (store: UseBoundStore<RootState>) => EventManager<TCanvas>;
20
20
  size?: Size;
21
21
  onCreated?: (state: RootState) => void;
22
22
  };
23
23
  export declare type ReconcilerRoot<TCanvas extends Element> = {
24
24
  configure: (config?: RenderProps<TCanvas>) => ReconcilerRoot<TCanvas>;
25
- render: (element: React.ReactNode) => UseStore<RootState>;
25
+ render: (element: React.ReactNode) => UseBoundStore<RootState>;
26
26
  unmount: () => void;
27
27
  };
28
28
  declare function createRoot<TCanvas extends Element>(canvas: TCanvas): ReconcilerRoot<TCanvas>;
29
- declare function render<TCanvas extends Element>(element: React.ReactNode, canvas: TCanvas, config?: RenderProps<TCanvas>): UseStore<RootState>;
29
+ declare function render<TCanvas extends Element>(children: React.ReactNode, canvas: TCanvas, config: RenderProps<TCanvas>): UseBoundStore<RootState>;
30
30
  declare function unmountComponentAtNode<TElement extends Element>(canvas: TElement, callback?: (canvas: TElement) => void): void;
31
+ export declare type InjectState = Partial<Omit<RootState, 'set' | 'get' | 'setSize' | 'setFrameloop' | 'setDpr' | 'events' | 'invalidate' | 'advance' | 'performance' | 'internal'> & {
32
+ events: {
33
+ enabled?: boolean;
34
+ priority?: number;
35
+ compute?: ComputeFunction;
36
+ connected?: any;
37
+ };
38
+ }>;
39
+ declare function createPortal(children: React.ReactNode, container: THREE.Object3D, state?: InjectState): React.ReactNode;
31
40
  declare const act: any;
32
- declare function createPortal(children: React.ReactNode, container: THREE.Object3D): React.ReactNode;
33
41
  export * from './hooks';
34
- export { context, render, createRoot, unmountComponentAtNode, createPortal, reconciler, applyProps, dispose, invalidate, advance, extend, addEffect, addAfterEffect, addTail, act, roots as _roots, };
42
+ export { context, render, createRoot, unmountComponentAtNode, createPortal, reconciler, applyProps, dispose, invalidate, advance, extend, addEffect, addAfterEffect, addTail, getRootState, act, roots as _roots, };
@@ -1,38 +1,29 @@
1
1
  import * as THREE from 'three';
2
- import { UseStore } from 'zustand';
2
+ import { UseBoundStore } from 'zustand';
3
3
  import Reconciler from 'react-reconciler';
4
4
  import { prepare, applyProps } from './utils';
5
5
  import { RootState } from './store';
6
6
  import { EventHandlers } from './events';
7
7
  export declare type Root = {
8
8
  fiber: Reconciler.FiberRoot;
9
- store: UseStore<RootState>;
9
+ store: UseBoundStore<RootState>;
10
10
  };
11
- export declare type HostContext = React.MutableRefObject<{
12
- [key: string]: any;
13
- } | null>;
14
11
  export declare type LocalState = {
15
12
  type: string;
16
- root: UseStore<RootState>;
17
- context: React.MutableRefObject<{
18
- [key: string]: any;
19
- } | null>;
20
- getContext: () => {
21
- [key: string]: any;
22
- };
13
+ root: UseBoundStore<RootState>;
23
14
  objects: Instance[];
24
15
  parent: Instance | null;
25
16
  primitive?: boolean;
26
17
  eventCount: number;
27
18
  handlers: Partial<EventHandlers>;
28
19
  attach?: AttachType;
29
- previousAttach?: any;
20
+ previousAttach: any;
30
21
  memoizedProps: {
31
22
  [key: string]: any;
32
23
  };
33
24
  };
34
- export declare type AttachFnType = (parent: Instance, self: Instance) => void;
35
- export declare type AttachType = string | [attach: string | AttachFnType, detach: string | AttachFnType];
25
+ export declare type AttachFnType = (parent: Instance, self: Instance) => () => void;
26
+ export declare type AttachType = string | AttachFnType;
36
27
  export declare type BaseInstance = Omit<THREE.Object3D, 'children' | 'attach' | 'add' | 'remove' | 'raycast'> & {
37
28
  __r3f: LocalState;
38
29
  children: Instance[];
@@ -1,7 +1,7 @@
1
1
  import * as THREE from 'three';
2
2
  import * as React from 'react';
3
3
  import * as ReactThreeFiber from '../three-types';
4
- import { GetState, SetState, UseStore } from 'zustand';
4
+ import { GetState, SetState, StoreApi, UseBoundStore } from 'zustand';
5
5
  import { DomEvent, EventManager, PointerCaptureTarget, ThreeEvent } from './events';
6
6
  export interface Intersection extends THREE.Intersection {
7
7
  eventObject: THREE.Object3D;
@@ -23,11 +23,6 @@ export declare type Viewport = Size & {
23
23
  aspect: number;
24
24
  };
25
25
  export declare type Camera = THREE.OrthographicCamera | THREE.PerspectiveCamera;
26
- export declare type Raycaster = THREE.Raycaster & {
27
- enabled: boolean;
28
- filter?: FilterFunction;
29
- computeOffsets?: ComputeOffsetsFunction;
30
- };
31
26
  export declare type RenderCallback = (state: RootState, delta: number, frame?: THREE.XRFrame) => void;
32
27
  export declare type Performance = {
33
28
  current: number;
@@ -59,7 +54,7 @@ export declare type RootState = {
59
54
  camera: Camera & {
60
55
  manual?: boolean;
61
56
  };
62
- raycaster: Raycaster;
57
+ raycaster: THREE.Raycaster;
63
58
  events: EventManager<any>;
64
59
  xr: {
65
60
  connect: () => void;
@@ -67,7 +62,7 @@ export declare type RootState = {
67
62
  };
68
63
  scene: THREE.Scene;
69
64
  controls: THREE.EventDispatcher | null;
70
- mouse: THREE.Vector2;
65
+ pointer: THREE.Vector2;
71
66
  clock: THREE.Clock;
72
67
  linear: boolean;
73
68
  flat: boolean;
@@ -75,7 +70,7 @@ export declare type RootState = {
75
70
  performance: Performance;
76
71
  size: Size;
77
72
  viewport: Viewport & {
78
- getCurrentViewport: (camera?: Camera, target?: THREE.Vector3, size?: Size) => Omit<Viewport, 'dpr' | 'initialDpr'>;
73
+ getCurrentViewport: (camera?: Camera, target?: THREE.Vector3 | Parameters<THREE.Vector3['set']>, size?: Size) => Omit<Viewport, 'dpr' | 'initialDpr'>;
79
74
  };
80
75
  set: SetState<RootState>;
81
76
  get: GetState<RootState>;
@@ -85,15 +80,9 @@ export declare type RootState = {
85
80
  setDpr: (dpr: Dpr) => void;
86
81
  setFrameloop: (frameloop?: 'always' | 'demand' | 'never') => void;
87
82
  onPointerMissed?: (event: MouseEvent) => void;
83
+ previousRoot?: UseBoundStore<RootState, StoreApi<RootState>>;
88
84
  internal: InternalState;
89
85
  };
90
- export declare type FilterFunction = (items: THREE.Intersection[], state: RootState) => THREE.Intersection[];
91
- export declare type ComputeOffsetsFunction = (event: any, state: RootState) => {
92
- offsetX: number;
93
- offsetY: number;
94
- width?: number;
95
- height?: number;
96
- };
97
86
  export declare type StoreProps = {
98
87
  gl: THREE.WebGLRenderer;
99
88
  size: Size;
@@ -104,12 +93,12 @@ export declare type StoreProps = {
104
93
  frameloop?: 'always' | 'demand' | 'never';
105
94
  performance?: Partial<Omit<Performance, 'regress'>>;
106
95
  dpr?: Dpr;
107
- raycaster?: Partial<Raycaster>;
96
+ raycaster?: Partial<THREE.Raycaster>;
108
97
  camera?: (Camera | Partial<ReactThreeFiber.Object3DNode<THREE.Camera, typeof THREE.Camera> & ReactThreeFiber.Object3DNode<THREE.PerspectiveCamera, typeof THREE.PerspectiveCamera> & ReactThreeFiber.Object3DNode<THREE.OrthographicCamera, typeof THREE.OrthographicCamera>>) & {
109
98
  manual?: boolean;
110
99
  };
111
100
  onPointerMissed?: (event: MouseEvent) => void;
112
101
  };
113
- declare const context: React.Context<UseStore<RootState, import("zustand").StoreApi<RootState>>>;
114
- declare const createStore: (invalidate: (state?: RootState | undefined) => void, advance: (timestamp: number, runGlobalEffects?: boolean | undefined, state?: RootState | undefined, frame?: THREE.XRFrame | undefined) => void) => UseStore<RootState>;
102
+ declare const context: React.Context<UseBoundStore<RootState, StoreApi<RootState>>>;
103
+ declare const createStore: (invalidate: (state?: RootState | undefined) => void, advance: (timestamp: number, runGlobalEffects?: boolean | undefined, state?: RootState | undefined, frame?: THREE.XRFrame | undefined) => void) => UseBoundStore<RootState>;
115
104
  export { createStore, context };
@@ -1,6 +1,6 @@
1
1
  import * as THREE from 'three';
2
2
  import { AttachType, Instance, InstanceProps, LocalState } from './renderer';
3
- import { Dpr } from './store';
3
+ import { Dpr, RootState } from './store';
4
4
  export declare const DEFAULT = "__default";
5
5
  export declare type DiffSet = {
6
6
  memoized: {
@@ -21,6 +21,7 @@ export declare type ObjectMap = {
21
21
  };
22
22
  };
23
23
  export declare function calculateDpr(dpr: Dpr): number;
24
+ export declare const getRootState: (obj: THREE.Object3D) => RootState | undefined;
24
25
  export declare function filterKeys<TObj extends {
25
26
  [key: string]: any;
26
27
  }, TOmit extends boolean, TKey extends keyof TObj>(obj: TObj, omit: TOmit, ...keys: TKey[]): TOmit extends true ? Omit<TObj, TKey> : Pick<TObj, TKey>;
@@ -1,6 +1,6 @@
1
1
  import * as React from 'react';
2
2
  import { View, ViewProps, ViewStyle } from 'react-native';
3
- import { UseStore } from 'zustand';
3
+ import { UseBoundStore } from 'zustand';
4
4
  import { RenderProps } from '../core';
5
5
  import { RootState } from '../core/store';
6
6
  import { EventManager } from '../core/events';
@@ -8,6 +8,6 @@ export interface Props extends Omit<RenderProps<HTMLCanvasElement>, 'size' | 'ev
8
8
  children: React.ReactNode;
9
9
  fallback?: React.ReactNode;
10
10
  style?: ViewStyle;
11
- events?: (store: UseStore<RootState>) => EventManager<any>;
11
+ events?: (store: UseBoundStore<RootState>) => EventManager<any>;
12
12
  }
13
13
  export declare const Canvas: React.ForwardRefExoticComponent<Props & React.RefAttributes<View>>;
@@ -1,5 +1,5 @@
1
- import { UseStore } from 'zustand';
1
+ import { UseBoundStore } from 'zustand';
2
2
  import { RootState } from '../core/store';
3
3
  import { EventManager } from '../core/events';
4
4
  import { View } from 'react-native';
5
- export declare function createTouchEvents(store: UseStore<RootState>): EventManager<View>;
5
+ export declare function createTouchEvents(store: UseBoundStore<RootState>): EventManager<View>;
@@ -320,11 +320,6 @@ declare global {
320
320
  fog: FogProps;
321
321
  fogExp2: FogExp2Props;
322
322
  shape: ShapeProps;
323
- inject: {
324
- children: React.ReactNode;
325
- } & {
326
- [key: string]: any;
327
- };
328
323
  }
329
324
  }
330
325
  }
@@ -1,6 +1,6 @@
1
1
  import * as React from 'react';
2
2
  import type { Options as ResizeOptions } from 'react-use-measure';
3
- import { UseStore } from 'zustand';
3
+ import { UseBoundStore } from 'zustand';
4
4
  import { RenderProps } from '../core';
5
5
  import { RootState } from '../core/store';
6
6
  import { EventManager } from '../core/events';
@@ -8,6 +8,6 @@ export interface Props extends Omit<RenderProps<HTMLCanvasElement>, 'size' | 'ev
8
8
  children: React.ReactNode;
9
9
  fallback?: React.ReactNode;
10
10
  resize?: ResizeOptions;
11
- events?: (store: UseStore<RootState>) => EventManager<any>;
11
+ events?: (store: UseBoundStore<RootState>) => EventManager<any>;
12
12
  }
13
13
  export declare const Canvas: React.ForwardRefExoticComponent<Props & React.RefAttributes<HTMLCanvasElement>>;
@@ -1,4 +1,4 @@
1
- import { UseStore } from 'zustand';
1
+ import { UseBoundStore } from 'zustand';
2
2
  import { RootState } from '../core/store';
3
3
  import { EventManager } from '../core/events';
4
- export declare function createPointerEvents(store: UseStore<RootState>): EventManager<HTMLElement>;
4
+ export declare function createPointerEvents(store: UseBoundStore<RootState>): EventManager<HTMLElement>;