@react-three/fiber 8.2.2 → 8.3.1
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 +18 -0
- package/dist/declarations/src/core/hooks.d.ts +2 -1
- package/dist/declarations/src/core/utils.d.ts +2 -2
- package/dist/declarations/src/three-types.d.ts +5 -4
- package/dist/{index-af244448.esm.js → index-212b30d8.esm.js} +45 -23
- package/dist/{index-2a5b06d3.cjs.dev.js → index-bcd3e47c.cjs.dev.js} +45 -23
- package/dist/{index-876a6569.cjs.prod.js → index-e086bd20.cjs.prod.js} +45 -23
- package/dist/react-three-fiber.cjs.dev.js +1 -1
- package/dist/react-three-fiber.cjs.prod.js +1 -1
- package/dist/react-three-fiber.esm.js +2 -2
- package/native/dist/react-three-fiber-native.cjs.dev.js +5 -3
- package/native/dist/react-three-fiber-native.cjs.prod.js +5 -3
- package/native/dist/react-three-fiber-native.esm.js +6 -4
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @react-three/fiber
|
|
2
2
|
|
|
3
|
+
## 8.3.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- aaeb2b8: fix(types): accept readonly arrays for vector props
|
|
8
|
+
|
|
9
|
+
## 8.3.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- 9c450ec: feat: improve errors
|
|
14
|
+
|
|
15
|
+
## 8.2.3
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- b8d2eab: fix: improve useLoader signature, initial size on createRoot
|
|
20
|
+
|
|
3
21
|
## 8.2.2
|
|
4
22
|
|
|
5
23
|
### Patch Changes
|
|
@@ -3,6 +3,7 @@ import { StateSelector, EqualityChecker } from 'zustand';
|
|
|
3
3
|
import { GLTF } from 'three/examples/jsm/loaders/GLTFLoader';
|
|
4
4
|
import { RootState, RenderCallback } from './store';
|
|
5
5
|
import { ObjectMap } from './utils';
|
|
6
|
+
import { LoadingManager } from 'three';
|
|
6
7
|
export interface Loader<T> extends THREE.Loader {
|
|
7
8
|
load(url: string, onLoad?: (result: T) => void, onProgress?: (event: ProgressEvent) => void, onError?: (event: ErrorEvent) => void): unknown;
|
|
8
9
|
}
|
|
@@ -14,7 +15,7 @@ export declare function useStore(): import("zustand").UseBoundStore<RootState, i
|
|
|
14
15
|
export declare function useThree<T = RootState>(selector?: StateSelector<RootState, T>, equalityFn?: EqualityChecker<T>): T;
|
|
15
16
|
export declare function useFrame(callback: RenderCallback, renderPriority?: number): null;
|
|
16
17
|
export declare function useGraph(object: THREE.Object3D): ObjectMap;
|
|
17
|
-
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
|
+
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>;
|
|
18
19
|
export declare namespace useLoader {
|
|
19
20
|
var preload: <T, U extends string | string[]>(Proto: new () => LoaderResult<T>, input: U, extensions?: Extensions | undefined) => undefined;
|
|
20
21
|
var clear: <T, U extends string | string[]>(Proto: new () => LoaderResult<T>, input: U) => void;
|
|
@@ -13,7 +13,7 @@ export declare type UnblockProps = {
|
|
|
13
13
|
};
|
|
14
14
|
export declare function Block({ set }: Omit<UnblockProps, 'children'>): null;
|
|
15
15
|
export declare class ErrorBoundary extends React.Component<{
|
|
16
|
-
set: React.Dispatch<
|
|
16
|
+
set: React.Dispatch<Error | undefined>;
|
|
17
17
|
children: React.ReactNode;
|
|
18
18
|
}, {
|
|
19
19
|
error: boolean;
|
|
@@ -24,7 +24,7 @@ export declare class ErrorBoundary extends React.Component<{
|
|
|
24
24
|
static getDerivedStateFromError: () => {
|
|
25
25
|
error: boolean;
|
|
26
26
|
};
|
|
27
|
-
componentDidCatch(
|
|
27
|
+
componentDidCatch(err: Error): void;
|
|
28
28
|
render(): React.ReactNode;
|
|
29
29
|
}
|
|
30
30
|
export declare const DEFAULT = "__default";
|
|
@@ -8,10 +8,11 @@ export declare type NonFunctionKeys<T> = {
|
|
|
8
8
|
export declare type Overwrite<T, O> = Omit<T, NonFunctionKeys<O>> & O;
|
|
9
9
|
declare type Args<T> = T extends new (...args: any) => any ? ConstructorParameters<T> : T;
|
|
10
10
|
export declare type Euler = THREE.Euler | Parameters<THREE.Euler['set']>;
|
|
11
|
-
export declare type Matrix4 = THREE.Matrix4 | Parameters<THREE.Matrix4['set']>;
|
|
12
|
-
|
|
13
|
-
export declare type
|
|
14
|
-
export declare type
|
|
11
|
+
export declare type Matrix4 = THREE.Matrix4 | Parameters<THREE.Matrix4['set']> | Readonly<THREE.Matrix4['set']>;
|
|
12
|
+
declare type VectorLike<VectorClass extends THREE.Vector> = VectorClass | Parameters<VectorClass['set']> | Readonly<Parameters<VectorClass['set']>> | Parameters<VectorClass['setScalar']>[0];
|
|
13
|
+
export declare type Vector2 = VectorLike<THREE.Vector2>;
|
|
14
|
+
export declare type Vector3 = VectorLike<THREE.Vector3>;
|
|
15
|
+
export declare type Vector4 = VectorLike<THREE.Vector4>;
|
|
15
16
|
export declare type Color = ConstructorParameters<typeof THREE.Color> | THREE.Color | number | string;
|
|
16
17
|
export declare type ColorArray = typeof THREE.Color | Parameters<THREE.Color['set']>;
|
|
17
18
|
export declare type Layers = THREE.Layers | Parameters<THREE.Layers['set']>[0];
|
|
@@ -45,8 +45,8 @@ class ErrorBoundary extends React.Component {
|
|
|
45
45
|
};
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
componentDidCatch(
|
|
49
|
-
this.props.set(
|
|
48
|
+
componentDidCatch(err) {
|
|
49
|
+
this.props.set(err);
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
render() {
|
|
@@ -849,7 +849,7 @@ function createRenderer(_roots, _getEventPriority) {
|
|
|
849
849
|
}
|
|
850
850
|
|
|
851
851
|
if (type === 'primitive') {
|
|
852
|
-
if (props.object === undefined) throw
|
|
852
|
+
if (props.object === undefined) throw new Error("R3F: Primitives without 'object' are invalid!");
|
|
853
853
|
const object = props.object;
|
|
854
854
|
instance = prepare(object, {
|
|
855
855
|
type,
|
|
@@ -861,11 +861,11 @@ function createRenderer(_roots, _getEventPriority) {
|
|
|
861
861
|
const target = catalogue[name];
|
|
862
862
|
|
|
863
863
|
if (!target) {
|
|
864
|
-
throw
|
|
864
|
+
throw new Error(`R3F: ${name} is not part of the THREE namespace! Did you forget to extend? See: https://docs.pmnd.rs/react-three-fiber/api/objects#using-3rd-party-objects-declaratively`);
|
|
865
865
|
} // Throw if an object or literal was passed for args
|
|
866
866
|
|
|
867
867
|
|
|
868
|
-
if (!Array.isArray(args)) throw 'The args prop must be an array!'; // Instanciate new object, link it to the root
|
|
868
|
+
if (!Array.isArray(args)) throw new Error('R3F: The args prop must be an array!'); // Instanciate new object, link it to the root
|
|
869
869
|
// Append memoized props with args so it's not forgotten
|
|
870
870
|
|
|
871
871
|
instance = prepare(new target(...args), {
|
|
@@ -1103,7 +1103,7 @@ function createRenderer(_roots, _getEventPriority) {
|
|
|
1103
1103
|
...restOld
|
|
1104
1104
|
} = oldProps; // Throw if an object or literal was passed for args
|
|
1105
1105
|
|
|
1106
|
-
if (!Array.isArray(argsNew)) throw '
|
|
1106
|
+
if (!Array.isArray(argsNew)) throw new Error('R3F: the args prop must be an array!'); // If it has new props or arguments, then it needs to be re-instantiated
|
|
1107
1107
|
|
|
1108
1108
|
if (argsNew.some((value, index) => value !== argsOld[index])) return [true]; // Create a diff-set, flag if there are any changes
|
|
1109
1109
|
|
|
@@ -1566,7 +1566,7 @@ function createLoop(roots) {
|
|
|
1566
1566
|
|
|
1567
1567
|
function useStore() {
|
|
1568
1568
|
const store = React.useContext(context);
|
|
1569
|
-
if (!store) throw
|
|
1569
|
+
if (!store) throw new Error('R3F: Hooks can only be used within the Canvas component!');
|
|
1570
1570
|
return store;
|
|
1571
1571
|
}
|
|
1572
1572
|
/**
|
|
@@ -1610,7 +1610,7 @@ function loadingFn(extensions, onProgress) {
|
|
|
1610
1610
|
return Promise.all(input.map(input => new Promise((res, reject) => loader.load(input, data => {
|
|
1611
1611
|
if (data.scene) Object.assign(data, buildGraph(data.scene));
|
|
1612
1612
|
res(data);
|
|
1613
|
-
}, onProgress, error => reject(`Could not load ${input}: ${error.message}`)))));
|
|
1613
|
+
}, onProgress, error => reject(new Error(`Could not load ${input}: ${error.message})`))))));
|
|
1614
1614
|
};
|
|
1615
1615
|
}
|
|
1616
1616
|
/**
|
|
@@ -1673,11 +1673,43 @@ const createRendererInstance = (gl, canvas) => {
|
|
|
1673
1673
|
});
|
|
1674
1674
|
};
|
|
1675
1675
|
|
|
1676
|
+
function isCanvas(maybeCanvas) {
|
|
1677
|
+
return maybeCanvas instanceof HTMLCanvasElement;
|
|
1678
|
+
}
|
|
1679
|
+
|
|
1680
|
+
function computeInitialSize(canvas, defaultSize) {
|
|
1681
|
+
if (defaultSize) {
|
|
1682
|
+
return defaultSize;
|
|
1683
|
+
}
|
|
1684
|
+
|
|
1685
|
+
if (isCanvas(canvas) && canvas.parentElement) {
|
|
1686
|
+
const {
|
|
1687
|
+
width,
|
|
1688
|
+
height,
|
|
1689
|
+
top,
|
|
1690
|
+
left
|
|
1691
|
+
} = canvas.parentElement.getBoundingClientRect();
|
|
1692
|
+
return {
|
|
1693
|
+
width,
|
|
1694
|
+
height,
|
|
1695
|
+
top,
|
|
1696
|
+
left
|
|
1697
|
+
};
|
|
1698
|
+
}
|
|
1699
|
+
|
|
1700
|
+
return {
|
|
1701
|
+
width: 0,
|
|
1702
|
+
height: 0,
|
|
1703
|
+
top: 0,
|
|
1704
|
+
left: 0
|
|
1705
|
+
};
|
|
1706
|
+
}
|
|
1707
|
+
|
|
1676
1708
|
function createRoot(canvas) {
|
|
1677
1709
|
// Check against mistaken use of createRoot
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1710
|
+
const prevRoot = roots.get(canvas);
|
|
1711
|
+
const prevFiber = prevRoot == null ? void 0 : prevRoot.fiber;
|
|
1712
|
+
const prevStore = prevRoot == null ? void 0 : prevRoot.store;
|
|
1681
1713
|
if (prevRoot) console.warn('R3F.createRoot should only be called once!'); // Report when an error was detected in a previous render
|
|
1682
1714
|
// https://github.com/pmndrs/react-three-fiber/pull/2261
|
|
1683
1715
|
|
|
@@ -1701,7 +1733,7 @@ function createRoot(canvas) {
|
|
|
1701
1733
|
configure(props = {}) {
|
|
1702
1734
|
let {
|
|
1703
1735
|
gl: glConfig,
|
|
1704
|
-
size,
|
|
1736
|
+
size: propsSize,
|
|
1705
1737
|
events,
|
|
1706
1738
|
onCreated: onCreatedCallback,
|
|
1707
1739
|
shadows = false,
|
|
@@ -1836,17 +1868,7 @@ function createRoot(canvas) {
|
|
|
1836
1868
|
|
|
1837
1869
|
if (dpr && state.viewport.dpr !== calculateDpr(dpr)) state.setDpr(dpr); // Check size, allow it to take on container bounds initially
|
|
1838
1870
|
|
|
1839
|
-
size =
|
|
1840
|
-
width: canvas.parentElement.clientWidth,
|
|
1841
|
-
height: canvas.parentElement.clientHeight,
|
|
1842
|
-
top: canvas.parentElement.clientTop,
|
|
1843
|
-
left: canvas.parentElement.clientLeft
|
|
1844
|
-
} : {
|
|
1845
|
-
width: 0,
|
|
1846
|
-
height: 0,
|
|
1847
|
-
top: 0,
|
|
1848
|
-
left: 0
|
|
1849
|
-
});
|
|
1871
|
+
const size = computeInitialSize(canvas, propsSize);
|
|
1850
1872
|
|
|
1851
1873
|
if (!is.equ(size, state.size, shallowLoose)) {
|
|
1852
1874
|
state.setSize(size.width, size.height, size.updateStyle, size.top, size.left);
|
|
@@ -72,8 +72,8 @@ class ErrorBoundary extends React__namespace.Component {
|
|
|
72
72
|
};
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
-
componentDidCatch(
|
|
76
|
-
this.props.set(
|
|
75
|
+
componentDidCatch(err) {
|
|
76
|
+
this.props.set(err);
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
render() {
|
|
@@ -876,7 +876,7 @@ function createRenderer(_roots, _getEventPriority) {
|
|
|
876
876
|
}
|
|
877
877
|
|
|
878
878
|
if (type === 'primitive') {
|
|
879
|
-
if (props.object === undefined) throw
|
|
879
|
+
if (props.object === undefined) throw new Error("R3F: Primitives without 'object' are invalid!");
|
|
880
880
|
const object = props.object;
|
|
881
881
|
instance = prepare(object, {
|
|
882
882
|
type,
|
|
@@ -888,11 +888,11 @@ function createRenderer(_roots, _getEventPriority) {
|
|
|
888
888
|
const target = catalogue[name];
|
|
889
889
|
|
|
890
890
|
if (!target) {
|
|
891
|
-
throw
|
|
891
|
+
throw new Error(`R3F: ${name} is not part of the THREE namespace! Did you forget to extend? See: https://docs.pmnd.rs/react-three-fiber/api/objects#using-3rd-party-objects-declaratively`);
|
|
892
892
|
} // Throw if an object or literal was passed for args
|
|
893
893
|
|
|
894
894
|
|
|
895
|
-
if (!Array.isArray(args)) throw 'The args prop must be an array!'; // Instanciate new object, link it to the root
|
|
895
|
+
if (!Array.isArray(args)) throw new Error('R3F: The args prop must be an array!'); // Instanciate new object, link it to the root
|
|
896
896
|
// Append memoized props with args so it's not forgotten
|
|
897
897
|
|
|
898
898
|
instance = prepare(new target(...args), {
|
|
@@ -1130,7 +1130,7 @@ function createRenderer(_roots, _getEventPriority) {
|
|
|
1130
1130
|
...restOld
|
|
1131
1131
|
} = oldProps; // Throw if an object or literal was passed for args
|
|
1132
1132
|
|
|
1133
|
-
if (!Array.isArray(argsNew)) throw '
|
|
1133
|
+
if (!Array.isArray(argsNew)) throw new Error('R3F: the args prop must be an array!'); // If it has new props or arguments, then it needs to be re-instantiated
|
|
1134
1134
|
|
|
1135
1135
|
if (argsNew.some((value, index) => value !== argsOld[index])) return [true]; // Create a diff-set, flag if there are any changes
|
|
1136
1136
|
|
|
@@ -1593,7 +1593,7 @@ function createLoop(roots) {
|
|
|
1593
1593
|
|
|
1594
1594
|
function useStore() {
|
|
1595
1595
|
const store = React__namespace.useContext(context);
|
|
1596
|
-
if (!store) throw
|
|
1596
|
+
if (!store) throw new Error('R3F: Hooks can only be used within the Canvas component!');
|
|
1597
1597
|
return store;
|
|
1598
1598
|
}
|
|
1599
1599
|
/**
|
|
@@ -1637,7 +1637,7 @@ function loadingFn(extensions, onProgress) {
|
|
|
1637
1637
|
return Promise.all(input.map(input => new Promise((res, reject) => loader.load(input, data => {
|
|
1638
1638
|
if (data.scene) Object.assign(data, buildGraph(data.scene));
|
|
1639
1639
|
res(data);
|
|
1640
|
-
}, onProgress, error => reject(`Could not load ${input}: ${error.message}`)))));
|
|
1640
|
+
}, onProgress, error => reject(new Error(`Could not load ${input}: ${error.message})`))))));
|
|
1641
1641
|
};
|
|
1642
1642
|
}
|
|
1643
1643
|
/**
|
|
@@ -1700,11 +1700,43 @@ const createRendererInstance = (gl, canvas) => {
|
|
|
1700
1700
|
});
|
|
1701
1701
|
};
|
|
1702
1702
|
|
|
1703
|
+
function isCanvas(maybeCanvas) {
|
|
1704
|
+
return maybeCanvas instanceof HTMLCanvasElement;
|
|
1705
|
+
}
|
|
1706
|
+
|
|
1707
|
+
function computeInitialSize(canvas, defaultSize) {
|
|
1708
|
+
if (defaultSize) {
|
|
1709
|
+
return defaultSize;
|
|
1710
|
+
}
|
|
1711
|
+
|
|
1712
|
+
if (isCanvas(canvas) && canvas.parentElement) {
|
|
1713
|
+
const {
|
|
1714
|
+
width,
|
|
1715
|
+
height,
|
|
1716
|
+
top,
|
|
1717
|
+
left
|
|
1718
|
+
} = canvas.parentElement.getBoundingClientRect();
|
|
1719
|
+
return {
|
|
1720
|
+
width,
|
|
1721
|
+
height,
|
|
1722
|
+
top,
|
|
1723
|
+
left
|
|
1724
|
+
};
|
|
1725
|
+
}
|
|
1726
|
+
|
|
1727
|
+
return {
|
|
1728
|
+
width: 0,
|
|
1729
|
+
height: 0,
|
|
1730
|
+
top: 0,
|
|
1731
|
+
left: 0
|
|
1732
|
+
};
|
|
1733
|
+
}
|
|
1734
|
+
|
|
1703
1735
|
function createRoot(canvas) {
|
|
1704
1736
|
// Check against mistaken use of createRoot
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1737
|
+
const prevRoot = roots.get(canvas);
|
|
1738
|
+
const prevFiber = prevRoot == null ? void 0 : prevRoot.fiber;
|
|
1739
|
+
const prevStore = prevRoot == null ? void 0 : prevRoot.store;
|
|
1708
1740
|
if (prevRoot) console.warn('R3F.createRoot should only be called once!'); // Report when an error was detected in a previous render
|
|
1709
1741
|
// https://github.com/pmndrs/react-three-fiber/pull/2261
|
|
1710
1742
|
|
|
@@ -1728,7 +1760,7 @@ function createRoot(canvas) {
|
|
|
1728
1760
|
configure(props = {}) {
|
|
1729
1761
|
let {
|
|
1730
1762
|
gl: glConfig,
|
|
1731
|
-
size,
|
|
1763
|
+
size: propsSize,
|
|
1732
1764
|
events,
|
|
1733
1765
|
onCreated: onCreatedCallback,
|
|
1734
1766
|
shadows = false,
|
|
@@ -1863,17 +1895,7 @@ function createRoot(canvas) {
|
|
|
1863
1895
|
|
|
1864
1896
|
if (dpr && state.viewport.dpr !== calculateDpr(dpr)) state.setDpr(dpr); // Check size, allow it to take on container bounds initially
|
|
1865
1897
|
|
|
1866
|
-
size =
|
|
1867
|
-
width: canvas.parentElement.clientWidth,
|
|
1868
|
-
height: canvas.parentElement.clientHeight,
|
|
1869
|
-
top: canvas.parentElement.clientTop,
|
|
1870
|
-
left: canvas.parentElement.clientLeft
|
|
1871
|
-
} : {
|
|
1872
|
-
width: 0,
|
|
1873
|
-
height: 0,
|
|
1874
|
-
top: 0,
|
|
1875
|
-
left: 0
|
|
1876
|
-
});
|
|
1898
|
+
const size = computeInitialSize(canvas, propsSize);
|
|
1877
1899
|
|
|
1878
1900
|
if (!is.equ(size, state.size, shallowLoose)) {
|
|
1879
1901
|
state.setSize(size.width, size.height, size.updateStyle, size.top, size.left);
|
|
@@ -72,8 +72,8 @@ class ErrorBoundary extends React__namespace.Component {
|
|
|
72
72
|
};
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
-
componentDidCatch(
|
|
76
|
-
this.props.set(
|
|
75
|
+
componentDidCatch(err) {
|
|
76
|
+
this.props.set(err);
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
render() {
|
|
@@ -876,7 +876,7 @@ function createRenderer(_roots, _getEventPriority) {
|
|
|
876
876
|
}
|
|
877
877
|
|
|
878
878
|
if (type === 'primitive') {
|
|
879
|
-
if (props.object === undefined) throw
|
|
879
|
+
if (props.object === undefined) throw new Error("R3F: Primitives without 'object' are invalid!");
|
|
880
880
|
const object = props.object;
|
|
881
881
|
instance = prepare(object, {
|
|
882
882
|
type,
|
|
@@ -888,11 +888,11 @@ function createRenderer(_roots, _getEventPriority) {
|
|
|
888
888
|
const target = catalogue[name];
|
|
889
889
|
|
|
890
890
|
if (!target) {
|
|
891
|
-
throw
|
|
891
|
+
throw new Error(`R3F: ${name} is not part of the THREE namespace! Did you forget to extend? See: https://docs.pmnd.rs/react-three-fiber/api/objects#using-3rd-party-objects-declaratively`);
|
|
892
892
|
} // Throw if an object or literal was passed for args
|
|
893
893
|
|
|
894
894
|
|
|
895
|
-
if (!Array.isArray(args)) throw 'The args prop must be an array!'; // Instanciate new object, link it to the root
|
|
895
|
+
if (!Array.isArray(args)) throw new Error('R3F: The args prop must be an array!'); // Instanciate new object, link it to the root
|
|
896
896
|
// Append memoized props with args so it's not forgotten
|
|
897
897
|
|
|
898
898
|
instance = prepare(new target(...args), {
|
|
@@ -1130,7 +1130,7 @@ function createRenderer(_roots, _getEventPriority) {
|
|
|
1130
1130
|
...restOld
|
|
1131
1131
|
} = oldProps; // Throw if an object or literal was passed for args
|
|
1132
1132
|
|
|
1133
|
-
if (!Array.isArray(argsNew)) throw '
|
|
1133
|
+
if (!Array.isArray(argsNew)) throw new Error('R3F: the args prop must be an array!'); // If it has new props or arguments, then it needs to be re-instantiated
|
|
1134
1134
|
|
|
1135
1135
|
if (argsNew.some((value, index) => value !== argsOld[index])) return [true]; // Create a diff-set, flag if there are any changes
|
|
1136
1136
|
|
|
@@ -1593,7 +1593,7 @@ function createLoop(roots) {
|
|
|
1593
1593
|
|
|
1594
1594
|
function useStore() {
|
|
1595
1595
|
const store = React__namespace.useContext(context);
|
|
1596
|
-
if (!store) throw
|
|
1596
|
+
if (!store) throw new Error('R3F: Hooks can only be used within the Canvas component!');
|
|
1597
1597
|
return store;
|
|
1598
1598
|
}
|
|
1599
1599
|
/**
|
|
@@ -1637,7 +1637,7 @@ function loadingFn(extensions, onProgress) {
|
|
|
1637
1637
|
return Promise.all(input.map(input => new Promise((res, reject) => loader.load(input, data => {
|
|
1638
1638
|
if (data.scene) Object.assign(data, buildGraph(data.scene));
|
|
1639
1639
|
res(data);
|
|
1640
|
-
}, onProgress, error => reject(`Could not load ${input}: ${error.message}`)))));
|
|
1640
|
+
}, onProgress, error => reject(new Error(`Could not load ${input}: ${error.message})`))))));
|
|
1641
1641
|
};
|
|
1642
1642
|
}
|
|
1643
1643
|
/**
|
|
@@ -1700,11 +1700,43 @@ const createRendererInstance = (gl, canvas) => {
|
|
|
1700
1700
|
});
|
|
1701
1701
|
};
|
|
1702
1702
|
|
|
1703
|
+
function isCanvas(maybeCanvas) {
|
|
1704
|
+
return maybeCanvas instanceof HTMLCanvasElement;
|
|
1705
|
+
}
|
|
1706
|
+
|
|
1707
|
+
function computeInitialSize(canvas, defaultSize) {
|
|
1708
|
+
if (defaultSize) {
|
|
1709
|
+
return defaultSize;
|
|
1710
|
+
}
|
|
1711
|
+
|
|
1712
|
+
if (isCanvas(canvas) && canvas.parentElement) {
|
|
1713
|
+
const {
|
|
1714
|
+
width,
|
|
1715
|
+
height,
|
|
1716
|
+
top,
|
|
1717
|
+
left
|
|
1718
|
+
} = canvas.parentElement.getBoundingClientRect();
|
|
1719
|
+
return {
|
|
1720
|
+
width,
|
|
1721
|
+
height,
|
|
1722
|
+
top,
|
|
1723
|
+
left
|
|
1724
|
+
};
|
|
1725
|
+
}
|
|
1726
|
+
|
|
1727
|
+
return {
|
|
1728
|
+
width: 0,
|
|
1729
|
+
height: 0,
|
|
1730
|
+
top: 0,
|
|
1731
|
+
left: 0
|
|
1732
|
+
};
|
|
1733
|
+
}
|
|
1734
|
+
|
|
1703
1735
|
function createRoot(canvas) {
|
|
1704
1736
|
// Check against mistaken use of createRoot
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1737
|
+
const prevRoot = roots.get(canvas);
|
|
1738
|
+
const prevFiber = prevRoot == null ? void 0 : prevRoot.fiber;
|
|
1739
|
+
const prevStore = prevRoot == null ? void 0 : prevRoot.store;
|
|
1708
1740
|
if (prevRoot) console.warn('R3F.createRoot should only be called once!'); // Report when an error was detected in a previous render
|
|
1709
1741
|
// https://github.com/pmndrs/react-three-fiber/pull/2261
|
|
1710
1742
|
|
|
@@ -1728,7 +1760,7 @@ function createRoot(canvas) {
|
|
|
1728
1760
|
configure(props = {}) {
|
|
1729
1761
|
let {
|
|
1730
1762
|
gl: glConfig,
|
|
1731
|
-
size,
|
|
1763
|
+
size: propsSize,
|
|
1732
1764
|
events,
|
|
1733
1765
|
onCreated: onCreatedCallback,
|
|
1734
1766
|
shadows = false,
|
|
@@ -1863,17 +1895,7 @@ function createRoot(canvas) {
|
|
|
1863
1895
|
|
|
1864
1896
|
if (dpr && state.viewport.dpr !== calculateDpr(dpr)) state.setDpr(dpr); // Check size, allow it to take on container bounds initially
|
|
1865
1897
|
|
|
1866
|
-
size =
|
|
1867
|
-
width: canvas.parentElement.clientWidth,
|
|
1868
|
-
height: canvas.parentElement.clientHeight,
|
|
1869
|
-
top: canvas.parentElement.clientTop,
|
|
1870
|
-
left: canvas.parentElement.clientLeft
|
|
1871
|
-
} : {
|
|
1872
|
-
width: 0,
|
|
1873
|
-
height: 0,
|
|
1874
|
-
top: 0,
|
|
1875
|
-
left: 0
|
|
1876
|
-
});
|
|
1898
|
+
const size = computeInitialSize(canvas, propsSize);
|
|
1877
1899
|
|
|
1878
1900
|
if (!is.equ(size, state.size, shallowLoose)) {
|
|
1879
1901
|
state.setSize(size.width, size.height, size.updateStyle, size.top, size.left);
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var index = require('./index-
|
|
5
|
+
var index = require('./index-bcd3e47c.cjs.dev.js');
|
|
6
6
|
var _extends = require('@babel/runtime/helpers/extends');
|
|
7
7
|
var React = require('react');
|
|
8
8
|
var THREE = require('three');
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var index = require('./index-
|
|
5
|
+
var index = require('./index-e086bd20.cjs.prod.js');
|
|
6
6
|
var _extends = require('@babel/runtime/helpers/extends');
|
|
7
7
|
var React = require('react');
|
|
8
8
|
var THREE = require('three');
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { c as createEvents, e as extend, u as useMutableCallback, a as createRoot, E as ErrorBoundary, B as Block, b as useIsomorphicLayoutEffect, d as unmountComponentAtNode } from './index-
|
|
2
|
-
export { t as ReactThreeFiber, s as _roots, q as act, n as addAfterEffect, m as addEffect, o as addTail, l as advance, i as applyProps, f as context, c as createEvents, g as createPortal, a as createRoot, j as dispose, e as extend, p as getRootState, k as invalidate, h as reconciler, r as render, d as unmountComponentAtNode, x as useFrame, y as useGraph, z as useLoader, v as useStore, w as useThree } from './index-
|
|
1
|
+
import { c as createEvents, e as extend, u as useMutableCallback, a as createRoot, E as ErrorBoundary, B as Block, b as useIsomorphicLayoutEffect, d as unmountComponentAtNode } from './index-212b30d8.esm.js';
|
|
2
|
+
export { t as ReactThreeFiber, s as _roots, q as act, n as addAfterEffect, m as addEffect, o as addTail, l as advance, i as applyProps, f as context, c as createEvents, g as createPortal, a as createRoot, j as dispose, e as extend, p as getRootState, k as invalidate, h as reconciler, r as render, d as unmountComponentAtNode, x as useFrame, y as useGraph, z as useLoader, v as useStore, w as useThree } from './index-212b30d8.esm.js';
|
|
3
3
|
import _extends from '@babel/runtime/helpers/esm/extends';
|
|
4
4
|
import * as React from 'react';
|
|
5
5
|
import * as THREE from 'three';
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var index = require('../../dist/index-
|
|
5
|
+
var index = require('../../dist/index-bcd3e47c.cjs.dev.js');
|
|
6
6
|
var _extends = require('@babel/runtime/helpers/extends');
|
|
7
7
|
var React = require('react');
|
|
8
8
|
var THREE = require('three');
|
|
@@ -39,6 +39,8 @@ var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
|
39
39
|
var THREE__namespace = /*#__PURE__*/_interopNamespace(THREE);
|
|
40
40
|
var Pressability__default = /*#__PURE__*/_interopDefault(Pressability);
|
|
41
41
|
|
|
42
|
+
/* eslint-enable import/default, import/no-named-as-default, import/no-named-as-default-member */
|
|
43
|
+
|
|
42
44
|
const EVENTS = {
|
|
43
45
|
PRESS: 'onPress',
|
|
44
46
|
PRESSIN: 'onPressIn',
|
|
@@ -144,7 +146,7 @@ function getAsset(input) {
|
|
|
144
146
|
return expAsset.fromModule(input);
|
|
145
147
|
|
|
146
148
|
default:
|
|
147
|
-
throw 'Invalid asset! Must be a URI or module.';
|
|
149
|
+
throw new Error('R3F: Invalid asset! Must be a URI or module.');
|
|
148
150
|
}
|
|
149
151
|
}
|
|
150
152
|
|
|
@@ -272,7 +274,7 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(({
|
|
|
272
274
|
React__namespace.useImperativeHandle(forwardedRef, () => viewRef.current);
|
|
273
275
|
const handlePointerMissed = index.useMutableCallback(onPointerMissed);
|
|
274
276
|
const [block, setBlock] = React__namespace.useState(false);
|
|
275
|
-
const [error, setError] = React__namespace.useState(
|
|
277
|
+
const [error, setError] = React__namespace.useState(undefined); // Suspend this component if block is a promise (2nd run)
|
|
276
278
|
|
|
277
279
|
if (block) throw block; // Throw exception outwards if anything within canvas throws
|
|
278
280
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var index = require('../../dist/index-
|
|
5
|
+
var index = require('../../dist/index-e086bd20.cjs.prod.js');
|
|
6
6
|
var _extends = require('@babel/runtime/helpers/extends');
|
|
7
7
|
var React = require('react');
|
|
8
8
|
var THREE = require('three');
|
|
@@ -39,6 +39,8 @@ var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
|
39
39
|
var THREE__namespace = /*#__PURE__*/_interopNamespace(THREE);
|
|
40
40
|
var Pressability__default = /*#__PURE__*/_interopDefault(Pressability);
|
|
41
41
|
|
|
42
|
+
/* eslint-enable import/default, import/no-named-as-default, import/no-named-as-default-member */
|
|
43
|
+
|
|
42
44
|
const EVENTS = {
|
|
43
45
|
PRESS: 'onPress',
|
|
44
46
|
PRESSIN: 'onPressIn',
|
|
@@ -144,7 +146,7 @@ function getAsset(input) {
|
|
|
144
146
|
return expAsset.fromModule(input);
|
|
145
147
|
|
|
146
148
|
default:
|
|
147
|
-
throw 'Invalid asset! Must be a URI or module.';
|
|
149
|
+
throw new Error('R3F: Invalid asset! Must be a URI or module.');
|
|
148
150
|
}
|
|
149
151
|
}
|
|
150
152
|
|
|
@@ -272,7 +274,7 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(({
|
|
|
272
274
|
React__namespace.useImperativeHandle(forwardedRef, () => viewRef.current);
|
|
273
275
|
const handlePointerMissed = index.useMutableCallback(onPointerMissed);
|
|
274
276
|
const [block, setBlock] = React__namespace.useState(false);
|
|
275
|
-
const [error, setError] = React__namespace.useState(
|
|
277
|
+
const [error, setError] = React__namespace.useState(undefined); // Suspend this component if block is a promise (2nd run)
|
|
276
278
|
|
|
277
279
|
if (block) throw block; // Throw exception outwards if anything within canvas throws
|
|
278
280
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { c as createEvents, e as extend, u as useMutableCallback, a as createRoot, E as ErrorBoundary, B as Block, d as unmountComponentAtNode } from '../../dist/index-
|
|
2
|
-
export { t as ReactThreeFiber, s as _roots, q as act, n as addAfterEffect, m as addEffect, o as addTail, l as advance, i as applyProps, f as context, g as createPortal, a as createRoot, j as dispose, e as extend, p as getRootState, k as invalidate, h as reconciler, r as render, d as unmountComponentAtNode, x as useFrame, y as useGraph, z as useLoader, v as useStore, w as useThree } from '../../dist/index-
|
|
1
|
+
import { c as createEvents, e as extend, u as useMutableCallback, a as createRoot, E as ErrorBoundary, B as Block, d as unmountComponentAtNode } from '../../dist/index-212b30d8.esm.js';
|
|
2
|
+
export { t as ReactThreeFiber, s as _roots, q as act, n as addAfterEffect, m as addEffect, o as addTail, l as advance, i as applyProps, f as context, g as createPortal, a as createRoot, j as dispose, e as extend, p as getRootState, k as invalidate, h as reconciler, r as render, d as unmountComponentAtNode, x as useFrame, y as useGraph, z as useLoader, v as useStore, w as useThree } from '../../dist/index-212b30d8.esm.js';
|
|
3
3
|
import _extends from '@babel/runtime/helpers/esm/extends';
|
|
4
4
|
import * as React from 'react';
|
|
5
5
|
import * as THREE from 'three';
|
|
@@ -12,6 +12,8 @@ import 'react-reconciler';
|
|
|
12
12
|
import 'scheduler';
|
|
13
13
|
import 'suspend-react';
|
|
14
14
|
|
|
15
|
+
/* eslint-enable import/default, import/no-named-as-default, import/no-named-as-default-member */
|
|
16
|
+
|
|
15
17
|
const EVENTS = {
|
|
16
18
|
PRESS: 'onPress',
|
|
17
19
|
PRESSIN: 'onPressIn',
|
|
@@ -117,7 +119,7 @@ function getAsset(input) {
|
|
|
117
119
|
return expAsset.fromModule(input);
|
|
118
120
|
|
|
119
121
|
default:
|
|
120
|
-
throw 'Invalid asset! Must be a URI or module.';
|
|
122
|
+
throw new Error('R3F: Invalid asset! Must be a URI or module.');
|
|
121
123
|
}
|
|
122
124
|
}
|
|
123
125
|
|
|
@@ -245,7 +247,7 @@ const Canvas = /*#__PURE__*/React.forwardRef(({
|
|
|
245
247
|
React.useImperativeHandle(forwardedRef, () => viewRef.current);
|
|
246
248
|
const handlePointerMissed = useMutableCallback(onPointerMissed);
|
|
247
249
|
const [block, setBlock] = React.useState(false);
|
|
248
|
-
const [error, setError] = React.useState(
|
|
250
|
+
const [error, setError] = React.useState(undefined); // Suspend this component if block is a promise (2nd run)
|
|
249
251
|
|
|
250
252
|
if (block) throw block; // Throw exception outwards if anything within canvas throws
|
|
251
253
|
|