@react-three/fiber 8.0.8 → 8.0.11
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/events.d.ts +69 -69
- package/dist/declarations/src/core/hooks.d.ts +21 -21
- package/dist/declarations/src/core/index.d.ts +60 -56
- package/dist/declarations/src/core/loop.d.ts +13 -13
- package/dist/declarations/src/core/renderer.d.ts +51 -51
- package/dist/declarations/src/core/store.d.ts +92 -91
- package/dist/declarations/src/core/utils.d.ts +80 -83
- package/dist/declarations/src/index.d.ts +10 -10
- package/dist/declarations/src/native/Canvas.d.ts +8 -8
- package/dist/declarations/src/native/events.d.ts +4 -4
- package/dist/declarations/src/native.d.ts +10 -10
- package/dist/declarations/src/three-types.d.ts +327 -327
- package/dist/declarations/src/web/Canvas.d.ts +9 -9
- package/dist/declarations/src/web/events.d.ts +4 -4
- package/dist/{index-548cf96a.esm.js → index-3c7aae97.esm.js} +84 -66
- package/dist/{index-c4e0ac66.cjs.prod.js → index-e936c560.cjs.prod.js} +84 -68
- package/dist/{index-b8ee55f0.cjs.dev.js → index-f7939a95.cjs.dev.js} +84 -68
- package/dist/react-three-fiber.cjs.dev.js +40 -21
- package/dist/react-three-fiber.cjs.prod.js +40 -21
- package/dist/react-three-fiber.esm.js +41 -22
- package/native/dist/react-three-fiber-native.cjs.dev.js +50 -34
- package/native/dist/react-three-fiber-native.cjs.prod.js +50 -34
- package/native/dist/react-three-fiber-native.esm.js +51 -35
- package/package.json +1 -1
|
@@ -39,11 +39,17 @@ var threeTypes = /*#__PURE__*/Object.freeze({
|
|
|
39
39
|
__proto__: null
|
|
40
40
|
});
|
|
41
41
|
|
|
42
|
-
// React currently throws a warning when using useLayoutEffect on the server.
|
|
42
|
+
const isOrthographicCamera = def => def && def.isOrthographicCamera; // React currently throws a warning when using useLayoutEffect on the server.
|
|
43
43
|
// To get around it, we can conditionally useEffect on the server (no-op) and
|
|
44
44
|
// useLayoutEffect on the client.
|
|
45
|
+
|
|
45
46
|
const isSSR = typeof window === 'undefined' || !window.navigator || /ServerSideRendering|^Deno\//.test(window.navigator.userAgent);
|
|
46
47
|
const useIsomorphicLayoutEffect = isSSR ? React__namespace.useEffect : React__namespace.useLayoutEffect;
|
|
48
|
+
function useMutableCallback(fn) {
|
|
49
|
+
const ref = React__namespace.useRef(fn);
|
|
50
|
+
useIsomorphicLayoutEffect(() => void (ref.current = fn), [fn]);
|
|
51
|
+
return ref;
|
|
52
|
+
}
|
|
47
53
|
function Block({
|
|
48
54
|
set
|
|
49
55
|
}) {
|
|
@@ -75,11 +81,6 @@ ErrorBoundary.getDerivedStateFromError = () => ({
|
|
|
75
81
|
error: true
|
|
76
82
|
});
|
|
77
83
|
|
|
78
|
-
function useMemoizedFn(fn) {
|
|
79
|
-
const fnRef = React__namespace.useRef(fn);
|
|
80
|
-
useIsomorphicLayoutEffect(() => void (fnRef.current = fn), [fn]);
|
|
81
|
-
return (...args) => fnRef.current == null ? void 0 : fnRef.current(...args);
|
|
82
|
-
}
|
|
83
84
|
const DEFAULT = '__default';
|
|
84
85
|
const isDiffSet = def => def && !!def.memoized && !!def.changes;
|
|
85
86
|
function calculateDpr(dpr) {
|
|
@@ -94,29 +95,6 @@ const getRootState = obj => {
|
|
|
94
95
|
|
|
95
96
|
return (_r3f = obj.__r3f) == null ? void 0 : _r3f.root.getState();
|
|
96
97
|
};
|
|
97
|
-
/**
|
|
98
|
-
* Picks or omits keys from an object
|
|
99
|
-
* `omit` will filter out keys, and otherwise cherry-pick them.
|
|
100
|
-
*/
|
|
101
|
-
|
|
102
|
-
function filterKeys(obj, omit, ...keys) {
|
|
103
|
-
const keysToSelect = new Set(keys);
|
|
104
|
-
return Object.entries(obj).reduce((acc, [key, value]) => {
|
|
105
|
-
const shouldInclude = !omit;
|
|
106
|
-
if (keysToSelect.has(key) === shouldInclude) acc[key] = value;
|
|
107
|
-
return acc;
|
|
108
|
-
}, {});
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* Clones an object and cherry-picks keys.
|
|
112
|
-
*/
|
|
113
|
-
|
|
114
|
-
const pick = (obj, keys) => filterKeys(obj, false, ...keys);
|
|
115
|
-
/**
|
|
116
|
-
* Clones an object and prunes or omits keys.
|
|
117
|
-
*/
|
|
118
|
-
|
|
119
|
-
const omit = (obj, keys) => filterKeys(obj, true, ...keys);
|
|
120
98
|
// A collection of compare functions
|
|
121
99
|
const is = {
|
|
122
100
|
obj: a => a === Object(a) && !is.arr(a) && typeof a !== 'function',
|
|
@@ -342,12 +320,16 @@ function applyProps$1(instance, data) {
|
|
|
342
320
|
|
|
343
321
|
if (value === DEFAULT + 'remove') {
|
|
344
322
|
if (targetProp && targetProp.constructor) {
|
|
323
|
+
var _memoized$args;
|
|
324
|
+
|
|
345
325
|
// use the prop constructor to find the default it should be
|
|
346
|
-
value = new targetProp.constructor(...memoized.args);
|
|
326
|
+
value = new targetProp.constructor(...((_memoized$args = memoized.args) != null ? _memoized$args : []));
|
|
347
327
|
} else if (currentInstance.constructor) {
|
|
328
|
+
var _currentInstance$__r;
|
|
329
|
+
|
|
348
330
|
// create a blank slate of the instance and copy the particular parameter.
|
|
349
331
|
// @ts-ignore
|
|
350
|
-
const defaultClassCall = new currentInstance.constructor(...currentInstance.__r3f.memoizedProps.args);
|
|
332
|
+
const defaultClassCall = new currentInstance.constructor(...((_currentInstance$__r = currentInstance.__r3f.memoizedProps.args) != null ? _currentInstance$__r : []));
|
|
351
333
|
value = defaultClassCall[targetProp]; // destory the instance
|
|
352
334
|
|
|
353
335
|
if (defaultClassCall.dispose) defaultClassCall.dispose(); // instance does not have constructor, just set it to 0
|
|
@@ -416,6 +398,25 @@ function invalidateInstance(instance) {
|
|
|
416
398
|
function updateInstance(instance) {
|
|
417
399
|
instance.onUpdate == null ? void 0 : instance.onUpdate(instance);
|
|
418
400
|
}
|
|
401
|
+
function updateCamera(camera, size) {
|
|
402
|
+
// https://github.com/pmndrs/react-three-fiber/issues/92
|
|
403
|
+
// Do not mess with the camera if it belongs to the user
|
|
404
|
+
if (!camera.manual) {
|
|
405
|
+
if (isOrthographicCamera(camera)) {
|
|
406
|
+
camera.left = size.width / -2;
|
|
407
|
+
camera.right = size.width / 2;
|
|
408
|
+
camera.top = size.height / 2;
|
|
409
|
+
camera.bottom = size.height / -2;
|
|
410
|
+
} else {
|
|
411
|
+
camera.aspect = size.width / size.height;
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
camera.updateProjectionMatrix(); // https://github.com/pmndrs/react-three-fiber/issues/178
|
|
415
|
+
// Update matrix world since the renderer is a frame late
|
|
416
|
+
|
|
417
|
+
camera.updateMatrixWorld();
|
|
418
|
+
}
|
|
419
|
+
}
|
|
419
420
|
|
|
420
421
|
function makeId(event) {
|
|
421
422
|
return (event.eventObject || event.object).uuid + '/' + event.index + event.instanceId;
|
|
@@ -1188,8 +1189,8 @@ function createRenderer(roots, getEventPriority) {
|
|
|
1188
1189
|
};
|
|
1189
1190
|
}
|
|
1190
1191
|
|
|
1192
|
+
const privateKeys = ['set', 'get', 'setSize', 'setFrameloop', 'setDpr', 'events', 'invalidate', 'advance', 'performance', 'internal', 'size', 'viewport'];
|
|
1191
1193
|
const isRenderer = def => !!(def != null && def.render);
|
|
1192
|
-
const isOrthographicCamera = def => def && def.isOrthographicCamera;
|
|
1193
1194
|
const context = /*#__PURE__*/React__namespace.createContext(null);
|
|
1194
1195
|
|
|
1195
1196
|
const createStore = (invalidate, advance) => {
|
|
@@ -1396,24 +1397,7 @@ const createStore = (invalidate, advance) => {
|
|
|
1396
1397
|
} = rootState.getState();
|
|
1397
1398
|
|
|
1398
1399
|
if (size !== oldSize || viewport.dpr !== oldDpr) {
|
|
1399
|
-
//
|
|
1400
|
-
// Do not mess with the camera if it belongs to the user
|
|
1401
|
-
if (!camera.manual) {
|
|
1402
|
-
if (isOrthographicCamera(camera)) {
|
|
1403
|
-
camera.left = size.width / -2;
|
|
1404
|
-
camera.right = size.width / 2;
|
|
1405
|
-
camera.top = size.height / 2;
|
|
1406
|
-
camera.bottom = size.height / -2;
|
|
1407
|
-
} else {
|
|
1408
|
-
camera.aspect = size.width / size.height;
|
|
1409
|
-
}
|
|
1410
|
-
|
|
1411
|
-
camera.updateProjectionMatrix(); // https://github.com/pmndrs/react-three-fiber/issues/178
|
|
1412
|
-
// Update matrix world since the renderer is a frame late
|
|
1413
|
-
|
|
1414
|
-
camera.updateMatrixWorld();
|
|
1415
|
-
} // Update renderer
|
|
1416
|
-
|
|
1400
|
+
updateCamera(camera, size); // Update renderer
|
|
1417
1401
|
|
|
1418
1402
|
gl.setPixelRatio(viewport.dpr);
|
|
1419
1403
|
gl.setSize(size.width, size.height);
|
|
@@ -1580,12 +1564,11 @@ function useThree(selector = state => state, equalityFn) {
|
|
|
1580
1564
|
|
|
1581
1565
|
function useFrame(callback, renderPriority = 0) {
|
|
1582
1566
|
const store = useStore();
|
|
1583
|
-
const subscribe = store.getState().internal.subscribe; //
|
|
1567
|
+
const subscribe = store.getState().internal.subscribe; // Memoize ref
|
|
1584
1568
|
|
|
1585
|
-
const ref =
|
|
1586
|
-
React__namespace.useLayoutEffect(() => void (ref.current = callback), [callback]); // Subscribe on mount, unsubscribe on unmount
|
|
1569
|
+
const ref = useMutableCallback(callback); // Subscribe on mount, unsubscribe on unmount
|
|
1587
1570
|
|
|
1588
|
-
|
|
1571
|
+
useIsomorphicLayoutEffect(() => subscribe(ref, renderPriority, store), [renderPriority, subscribe, store]);
|
|
1589
1572
|
return null;
|
|
1590
1573
|
}
|
|
1591
1574
|
/**
|
|
@@ -1953,6 +1936,7 @@ function Portal({
|
|
|
1953
1936
|
* {createPortal(...)} */
|
|
1954
1937
|
const {
|
|
1955
1938
|
events,
|
|
1939
|
+
size,
|
|
1956
1940
|
...rest
|
|
1957
1941
|
} = state;
|
|
1958
1942
|
const previousRoot = useStore();
|
|
@@ -1964,45 +1948,79 @@ function Portal({
|
|
|
1964
1948
|
|
|
1965
1949
|
if (injectState) {
|
|
1966
1950
|
// Only the fields of "state" that do not differ from injectState
|
|
1951
|
+
// Some props should be off-limits
|
|
1952
|
+
// Otherwise filter out the props that are different and let the inject layer take precedence
|
|
1967
1953
|
Object.keys(state).forEach(key => {
|
|
1968
1954
|
if ( // Some props should be off-limits
|
|
1969
|
-
!
|
|
1955
|
+
!privateKeys.includes(key) && // Otherwise filter out the props that are different and let the inject layer take precedence
|
|
1970
1956
|
state[key] !== injectState[key]) delete intersect[key];
|
|
1971
1957
|
});
|
|
1972
1958
|
}
|
|
1973
1959
|
|
|
1974
|
-
|
|
1960
|
+
let viewport = undefined;
|
|
1961
|
+
|
|
1962
|
+
if (injectState && size) {
|
|
1963
|
+
const camera = injectState.camera; // Calculate the override viewport, if present
|
|
1964
|
+
|
|
1965
|
+
viewport = state.viewport.getCurrentViewport(camera, new THREE__namespace.Vector3(), size); // Update the portal camera, if it differs from the previous layer
|
|
1966
|
+
|
|
1967
|
+
if (camera !== state.camera) updateCamera(camera, size);
|
|
1968
|
+
}
|
|
1969
|
+
|
|
1970
|
+
return { // The intersect consists of the previous root state
|
|
1971
|
+
...intersect,
|
|
1972
|
+
// Portals have their own scene, which forms the root, a raycaster and a pointer
|
|
1975
1973
|
scene: container,
|
|
1976
|
-
previousRoot,
|
|
1977
1974
|
raycaster,
|
|
1975
|
+
pointer,
|
|
1976
|
+
mouse: pointer,
|
|
1977
|
+
// Their previous root is the layer before it
|
|
1978
|
+
previousRoot,
|
|
1979
|
+
// Events, size and viewport can be overridden by the inject layer
|
|
1978
1980
|
events: { ...state.events,
|
|
1979
1981
|
...(injectState == null ? void 0 : injectState.events),
|
|
1980
|
-
pointer,
|
|
1981
|
-
mouse: pointer,
|
|
1982
1982
|
...events
|
|
1983
1983
|
},
|
|
1984
|
+
size: { ...state.size,
|
|
1985
|
+
...size
|
|
1986
|
+
},
|
|
1987
|
+
viewport: { ...state.viewport,
|
|
1988
|
+
...viewport
|
|
1989
|
+
},
|
|
1984
1990
|
...rest
|
|
1985
1991
|
};
|
|
1986
1992
|
}, [state]);
|
|
1987
|
-
const [
|
|
1988
|
-
|
|
1993
|
+
const [usePortalStore] = React__namespace.useState(() => {
|
|
1994
|
+
// Create a mirrored store, based on the previous root with a few overrides ...
|
|
1995
|
+
new THREE__namespace.Vector3();
|
|
1996
|
+
const previousState = previousRoot.getState();
|
|
1997
|
+
const store = create__default['default']((set, get) => ({ ...inject(previousState),
|
|
1998
|
+
// Set and get refer to this root-state
|
|
1989
1999
|
set,
|
|
1990
2000
|
get,
|
|
2001
|
+
// Layers are allowed to override events
|
|
1991
2002
|
setEvents: events => set(state => ({ ...state,
|
|
1992
2003
|
events: { ...state.events,
|
|
1993
2004
|
...events
|
|
1994
2005
|
}
|
|
1995
2006
|
}))
|
|
1996
2007
|
}));
|
|
1997
|
-
previousRoot.subscribe(state => useInjectStore.setState(injectState => inject(state, injectState)));
|
|
1998
2008
|
return store;
|
|
1999
2009
|
});
|
|
2000
2010
|
React__namespace.useEffect(() => {
|
|
2001
|
-
|
|
2011
|
+
// Subscribe to previous root-state and copy changes over to the mirrored portal-state
|
|
2012
|
+
const unsub = previousRoot.subscribe(prev => usePortalStore.setState(state => inject(prev, state)));
|
|
2013
|
+
return () => {
|
|
2014
|
+
unsub();
|
|
2015
|
+
usePortalStore.destroy();
|
|
2016
|
+
};
|
|
2017
|
+
}, []);
|
|
2018
|
+
React__namespace.useEffect(() => {
|
|
2019
|
+
usePortalStore.setState(injectState => inject(previousRoot.getState(), injectState));
|
|
2002
2020
|
}, [inject]);
|
|
2003
2021
|
return /*#__PURE__*/React__namespace.createElement(React__namespace.Fragment, null, reconciler.createPortal( /*#__PURE__*/React__namespace.createElement(context.Provider, {
|
|
2004
|
-
value:
|
|
2005
|
-
}, children),
|
|
2022
|
+
value: usePortalStore
|
|
2023
|
+
}, children), usePortalStore, null));
|
|
2006
2024
|
}
|
|
2007
2025
|
|
|
2008
2026
|
reconciler.injectIntoDevTools({
|
|
@@ -2028,8 +2046,6 @@ exports.dispose = dispose;
|
|
|
2028
2046
|
exports.extend = extend;
|
|
2029
2047
|
exports.getRootState = getRootState;
|
|
2030
2048
|
exports.invalidate = invalidate;
|
|
2031
|
-
exports.omit = omit;
|
|
2032
|
-
exports.pick = pick;
|
|
2033
2049
|
exports.reconciler = reconciler;
|
|
2034
2050
|
exports.render = render;
|
|
2035
2051
|
exports.roots = roots;
|
|
@@ -2039,6 +2055,6 @@ exports.useFrame = useFrame;
|
|
|
2039
2055
|
exports.useGraph = useGraph;
|
|
2040
2056
|
exports.useIsomorphicLayoutEffect = useIsomorphicLayoutEffect;
|
|
2041
2057
|
exports.useLoader = useLoader;
|
|
2042
|
-
exports.
|
|
2058
|
+
exports.useMutableCallback = useMutableCallback;
|
|
2043
2059
|
exports.useStore = useStore;
|
|
2044
2060
|
exports.useThree = useThree;
|
|
@@ -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-f7939a95.cjs.dev.js');
|
|
6
6
|
var _extends = require('@babel/runtime/helpers/extends');
|
|
7
7
|
var React = require('react');
|
|
8
8
|
var THREE = require('three');
|
|
@@ -119,25 +119,35 @@ function createPointerEvents(store) {
|
|
|
119
119
|
};
|
|
120
120
|
}
|
|
121
121
|
|
|
122
|
-
const CANVAS_PROPS = ['gl', 'events', 'shadows', 'linear', 'flat', 'legacy', 'orthographic', 'frameloop', 'dpr', 'performance', 'raycaster', 'camera', 'onPointerMissed', 'onCreated'];
|
|
123
122
|
/**
|
|
124
123
|
* A DOM canvas which accepts threejs elements as children.
|
|
125
124
|
* @see https://docs.pmnd.rs/react-three-fiber/api/canvas
|
|
126
125
|
*/
|
|
127
|
-
|
|
128
126
|
const Canvas = /*#__PURE__*/React__namespace.forwardRef(function Canvas({
|
|
129
127
|
children,
|
|
130
128
|
fallback,
|
|
131
129
|
resize,
|
|
132
130
|
style,
|
|
131
|
+
gl,
|
|
133
132
|
events = createPointerEvents,
|
|
133
|
+
shadows,
|
|
134
|
+
linear,
|
|
135
|
+
flat,
|
|
136
|
+
legacy,
|
|
137
|
+
orthographic,
|
|
138
|
+
frameloop,
|
|
139
|
+
dpr,
|
|
140
|
+
performance,
|
|
141
|
+
raycaster,
|
|
142
|
+
camera,
|
|
143
|
+
onPointerMissed,
|
|
144
|
+
onCreated,
|
|
134
145
|
...props
|
|
135
146
|
}, forwardedRef) {
|
|
136
147
|
// Create a known catalogue of Threejs-native elements
|
|
137
148
|
// This will include the entire THREE namespace by default, users can extend
|
|
138
149
|
// their own elements by using the createRoot API instead
|
|
139
150
|
React__namespace.useMemo(() => index.extend(THREE__namespace), []);
|
|
140
|
-
const onPointerMissed = index.useMemoizedFn(props.onPointerMissed);
|
|
141
151
|
const [containerRef, {
|
|
142
152
|
width,
|
|
143
153
|
height
|
|
@@ -149,15 +159,10 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(function Canvas({
|
|
|
149
159
|
},
|
|
150
160
|
...resize
|
|
151
161
|
});
|
|
152
|
-
const meshRef = React__namespace.useRef(null);
|
|
153
162
|
const canvasRef = React__namespace.useRef(null);
|
|
163
|
+
const meshRef = React__namespace.useRef(null);
|
|
154
164
|
const [canvas, setCanvas] = React__namespace.useState(null);
|
|
155
|
-
const
|
|
156
|
-
onPointerMissed
|
|
157
|
-
}, CANVAS_PROPS);
|
|
158
|
-
const divProps = index.omit({ ...props,
|
|
159
|
-
onPointerMissed
|
|
160
|
-
}, CANVAS_PROPS);
|
|
165
|
+
const handlePointerMissed = index.useMutableCallback(onPointerMissed);
|
|
161
166
|
const [block, setBlock] = React__namespace.useState(false);
|
|
162
167
|
const [error, setError] = React__namespace.useState(false); // Suspend this component if block is a promise (2nd run)
|
|
163
168
|
|
|
@@ -168,16 +173,29 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(function Canvas({
|
|
|
168
173
|
|
|
169
174
|
if (width > 0 && height > 0 && canvas) {
|
|
170
175
|
if (!root.current) root.current = index.createRoot(canvas);
|
|
171
|
-
root.current.configure({
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
+
root.current.configure({
|
|
177
|
+
gl,
|
|
178
|
+
events,
|
|
179
|
+
shadows,
|
|
180
|
+
linear,
|
|
181
|
+
flat,
|
|
182
|
+
legacy,
|
|
183
|
+
orthographic,
|
|
184
|
+
frameloop,
|
|
185
|
+
dpr,
|
|
186
|
+
performance,
|
|
187
|
+
raycaster,
|
|
188
|
+
camera,
|
|
176
189
|
size: {
|
|
177
190
|
width,
|
|
178
191
|
height
|
|
179
192
|
},
|
|
180
|
-
|
|
193
|
+
// Pass mutable reference to onPointerMissed so it's free to update
|
|
194
|
+
onPointerMissed: (...args) => handlePointerMissed.current == null ? void 0 : handlePointerMissed.current(...args),
|
|
195
|
+
onCreated: state => {
|
|
196
|
+
state.events.connect == null ? void 0 : state.events.connect(meshRef.current);
|
|
197
|
+
onCreated == null ? void 0 : onCreated(state);
|
|
198
|
+
}
|
|
181
199
|
});
|
|
182
200
|
root.current.render( /*#__PURE__*/React__namespace.createElement(index.ErrorBoundary, {
|
|
183
201
|
set: setError
|
|
@@ -189,10 +207,11 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(function Canvas({
|
|
|
189
207
|
}
|
|
190
208
|
|
|
191
209
|
index.useIsomorphicLayoutEffect(() => {
|
|
192
|
-
|
|
193
|
-
setCanvas(canvas);
|
|
194
|
-
return () => index.unmountComponentAtNode(canvas);
|
|
210
|
+
setCanvas(canvasRef.current);
|
|
195
211
|
}, []);
|
|
212
|
+
React__namespace.useEffect(() => {
|
|
213
|
+
if (canvas) return () => index.unmountComponentAtNode(canvas);
|
|
214
|
+
}, [canvas]);
|
|
196
215
|
return /*#__PURE__*/React__namespace.createElement("div", _extends({
|
|
197
216
|
ref: mergeRefs__default['default']([meshRef, containerRef]),
|
|
198
217
|
style: {
|
|
@@ -202,7 +221,7 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(function Canvas({
|
|
|
202
221
|
overflow: 'hidden',
|
|
203
222
|
...style
|
|
204
223
|
}
|
|
205
|
-
},
|
|
224
|
+
}, props), /*#__PURE__*/React__namespace.createElement("canvas", {
|
|
206
225
|
ref: mergeRefs__default['default']([canvasRef, forwardedRef]),
|
|
207
226
|
style: {
|
|
208
227
|
display: 'block'
|
|
@@ -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-e936c560.cjs.prod.js');
|
|
6
6
|
var _extends = require('@babel/runtime/helpers/extends');
|
|
7
7
|
var React = require('react');
|
|
8
8
|
var THREE = require('three');
|
|
@@ -119,25 +119,35 @@ function createPointerEvents(store) {
|
|
|
119
119
|
};
|
|
120
120
|
}
|
|
121
121
|
|
|
122
|
-
const CANVAS_PROPS = ['gl', 'events', 'shadows', 'linear', 'flat', 'legacy', 'orthographic', 'frameloop', 'dpr', 'performance', 'raycaster', 'camera', 'onPointerMissed', 'onCreated'];
|
|
123
122
|
/**
|
|
124
123
|
* A DOM canvas which accepts threejs elements as children.
|
|
125
124
|
* @see https://docs.pmnd.rs/react-three-fiber/api/canvas
|
|
126
125
|
*/
|
|
127
|
-
|
|
128
126
|
const Canvas = /*#__PURE__*/React__namespace.forwardRef(function Canvas({
|
|
129
127
|
children,
|
|
130
128
|
fallback,
|
|
131
129
|
resize,
|
|
132
130
|
style,
|
|
131
|
+
gl,
|
|
133
132
|
events = createPointerEvents,
|
|
133
|
+
shadows,
|
|
134
|
+
linear,
|
|
135
|
+
flat,
|
|
136
|
+
legacy,
|
|
137
|
+
orthographic,
|
|
138
|
+
frameloop,
|
|
139
|
+
dpr,
|
|
140
|
+
performance,
|
|
141
|
+
raycaster,
|
|
142
|
+
camera,
|
|
143
|
+
onPointerMissed,
|
|
144
|
+
onCreated,
|
|
134
145
|
...props
|
|
135
146
|
}, forwardedRef) {
|
|
136
147
|
// Create a known catalogue of Threejs-native elements
|
|
137
148
|
// This will include the entire THREE namespace by default, users can extend
|
|
138
149
|
// their own elements by using the createRoot API instead
|
|
139
150
|
React__namespace.useMemo(() => index.extend(THREE__namespace), []);
|
|
140
|
-
const onPointerMissed = index.useMemoizedFn(props.onPointerMissed);
|
|
141
151
|
const [containerRef, {
|
|
142
152
|
width,
|
|
143
153
|
height
|
|
@@ -149,15 +159,10 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(function Canvas({
|
|
|
149
159
|
},
|
|
150
160
|
...resize
|
|
151
161
|
});
|
|
152
|
-
const meshRef = React__namespace.useRef(null);
|
|
153
162
|
const canvasRef = React__namespace.useRef(null);
|
|
163
|
+
const meshRef = React__namespace.useRef(null);
|
|
154
164
|
const [canvas, setCanvas] = React__namespace.useState(null);
|
|
155
|
-
const
|
|
156
|
-
onPointerMissed
|
|
157
|
-
}, CANVAS_PROPS);
|
|
158
|
-
const divProps = index.omit({ ...props,
|
|
159
|
-
onPointerMissed
|
|
160
|
-
}, CANVAS_PROPS);
|
|
165
|
+
const handlePointerMissed = index.useMutableCallback(onPointerMissed);
|
|
161
166
|
const [block, setBlock] = React__namespace.useState(false);
|
|
162
167
|
const [error, setError] = React__namespace.useState(false); // Suspend this component if block is a promise (2nd run)
|
|
163
168
|
|
|
@@ -168,16 +173,29 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(function Canvas({
|
|
|
168
173
|
|
|
169
174
|
if (width > 0 && height > 0 && canvas) {
|
|
170
175
|
if (!root.current) root.current = index.createRoot(canvas);
|
|
171
|
-
root.current.configure({
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
+
root.current.configure({
|
|
177
|
+
gl,
|
|
178
|
+
events,
|
|
179
|
+
shadows,
|
|
180
|
+
linear,
|
|
181
|
+
flat,
|
|
182
|
+
legacy,
|
|
183
|
+
orthographic,
|
|
184
|
+
frameloop,
|
|
185
|
+
dpr,
|
|
186
|
+
performance,
|
|
187
|
+
raycaster,
|
|
188
|
+
camera,
|
|
176
189
|
size: {
|
|
177
190
|
width,
|
|
178
191
|
height
|
|
179
192
|
},
|
|
180
|
-
|
|
193
|
+
// Pass mutable reference to onPointerMissed so it's free to update
|
|
194
|
+
onPointerMissed: (...args) => handlePointerMissed.current == null ? void 0 : handlePointerMissed.current(...args),
|
|
195
|
+
onCreated: state => {
|
|
196
|
+
state.events.connect == null ? void 0 : state.events.connect(meshRef.current);
|
|
197
|
+
onCreated == null ? void 0 : onCreated(state);
|
|
198
|
+
}
|
|
181
199
|
});
|
|
182
200
|
root.current.render( /*#__PURE__*/React__namespace.createElement(index.ErrorBoundary, {
|
|
183
201
|
set: setError
|
|
@@ -189,10 +207,11 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(function Canvas({
|
|
|
189
207
|
}
|
|
190
208
|
|
|
191
209
|
index.useIsomorphicLayoutEffect(() => {
|
|
192
|
-
|
|
193
|
-
setCanvas(canvas);
|
|
194
|
-
return () => index.unmountComponentAtNode(canvas);
|
|
210
|
+
setCanvas(canvasRef.current);
|
|
195
211
|
}, []);
|
|
212
|
+
React__namespace.useEffect(() => {
|
|
213
|
+
if (canvas) return () => index.unmountComponentAtNode(canvas);
|
|
214
|
+
}, [canvas]);
|
|
196
215
|
return /*#__PURE__*/React__namespace.createElement("div", _extends({
|
|
197
216
|
ref: mergeRefs__default['default']([meshRef, containerRef]),
|
|
198
217
|
style: {
|
|
@@ -202,7 +221,7 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(function Canvas({
|
|
|
202
221
|
overflow: 'hidden',
|
|
203
222
|
...style
|
|
204
223
|
}
|
|
205
|
-
},
|
|
224
|
+
}, props), /*#__PURE__*/React__namespace.createElement("canvas", {
|
|
206
225
|
ref: mergeRefs__default['default']([canvasRef, forwardedRef]),
|
|
207
226
|
style: {
|
|
208
227
|
display: 'block'
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { c as createEvents, e as extend, u as
|
|
2
|
-
export { t as ReactThreeFiber,
|
|
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-3c7aae97.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 './index-3c7aae97.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';
|
|
@@ -89,25 +89,35 @@ function createPointerEvents(store) {
|
|
|
89
89
|
};
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
-
const CANVAS_PROPS = ['gl', 'events', 'shadows', 'linear', 'flat', 'legacy', 'orthographic', 'frameloop', 'dpr', 'performance', 'raycaster', 'camera', 'onPointerMissed', 'onCreated'];
|
|
93
92
|
/**
|
|
94
93
|
* A DOM canvas which accepts threejs elements as children.
|
|
95
94
|
* @see https://docs.pmnd.rs/react-three-fiber/api/canvas
|
|
96
95
|
*/
|
|
97
|
-
|
|
98
96
|
const Canvas = /*#__PURE__*/React.forwardRef(function Canvas({
|
|
99
97
|
children,
|
|
100
98
|
fallback,
|
|
101
99
|
resize,
|
|
102
100
|
style,
|
|
101
|
+
gl,
|
|
103
102
|
events = createPointerEvents,
|
|
103
|
+
shadows,
|
|
104
|
+
linear,
|
|
105
|
+
flat,
|
|
106
|
+
legacy,
|
|
107
|
+
orthographic,
|
|
108
|
+
frameloop,
|
|
109
|
+
dpr,
|
|
110
|
+
performance,
|
|
111
|
+
raycaster,
|
|
112
|
+
camera,
|
|
113
|
+
onPointerMissed,
|
|
114
|
+
onCreated,
|
|
104
115
|
...props
|
|
105
116
|
}, forwardedRef) {
|
|
106
117
|
// Create a known catalogue of Threejs-native elements
|
|
107
118
|
// This will include the entire THREE namespace by default, users can extend
|
|
108
119
|
// their own elements by using the createRoot API instead
|
|
109
120
|
React.useMemo(() => extend(THREE), []);
|
|
110
|
-
const onPointerMissed = useMemoizedFn(props.onPointerMissed);
|
|
111
121
|
const [containerRef, {
|
|
112
122
|
width,
|
|
113
123
|
height
|
|
@@ -119,15 +129,10 @@ const Canvas = /*#__PURE__*/React.forwardRef(function Canvas({
|
|
|
119
129
|
},
|
|
120
130
|
...resize
|
|
121
131
|
});
|
|
122
|
-
const meshRef = React.useRef(null);
|
|
123
132
|
const canvasRef = React.useRef(null);
|
|
133
|
+
const meshRef = React.useRef(null);
|
|
124
134
|
const [canvas, setCanvas] = React.useState(null);
|
|
125
|
-
const
|
|
126
|
-
onPointerMissed
|
|
127
|
-
}, CANVAS_PROPS);
|
|
128
|
-
const divProps = omit({ ...props,
|
|
129
|
-
onPointerMissed
|
|
130
|
-
}, CANVAS_PROPS);
|
|
135
|
+
const handlePointerMissed = useMutableCallback(onPointerMissed);
|
|
131
136
|
const [block, setBlock] = React.useState(false);
|
|
132
137
|
const [error, setError] = React.useState(false); // Suspend this component if block is a promise (2nd run)
|
|
133
138
|
|
|
@@ -138,16 +143,29 @@ const Canvas = /*#__PURE__*/React.forwardRef(function Canvas({
|
|
|
138
143
|
|
|
139
144
|
if (width > 0 && height > 0 && canvas) {
|
|
140
145
|
if (!root.current) root.current = createRoot(canvas);
|
|
141
|
-
root.current.configure({
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
+
root.current.configure({
|
|
147
|
+
gl,
|
|
148
|
+
events,
|
|
149
|
+
shadows,
|
|
150
|
+
linear,
|
|
151
|
+
flat,
|
|
152
|
+
legacy,
|
|
153
|
+
orthographic,
|
|
154
|
+
frameloop,
|
|
155
|
+
dpr,
|
|
156
|
+
performance,
|
|
157
|
+
raycaster,
|
|
158
|
+
camera,
|
|
146
159
|
size: {
|
|
147
160
|
width,
|
|
148
161
|
height
|
|
149
162
|
},
|
|
150
|
-
|
|
163
|
+
// Pass mutable reference to onPointerMissed so it's free to update
|
|
164
|
+
onPointerMissed: (...args) => handlePointerMissed.current == null ? void 0 : handlePointerMissed.current(...args),
|
|
165
|
+
onCreated: state => {
|
|
166
|
+
state.events.connect == null ? void 0 : state.events.connect(meshRef.current);
|
|
167
|
+
onCreated == null ? void 0 : onCreated(state);
|
|
168
|
+
}
|
|
151
169
|
});
|
|
152
170
|
root.current.render( /*#__PURE__*/React.createElement(ErrorBoundary, {
|
|
153
171
|
set: setError
|
|
@@ -159,10 +177,11 @@ const Canvas = /*#__PURE__*/React.forwardRef(function Canvas({
|
|
|
159
177
|
}
|
|
160
178
|
|
|
161
179
|
useIsomorphicLayoutEffect(() => {
|
|
162
|
-
|
|
163
|
-
setCanvas(canvas);
|
|
164
|
-
return () => unmountComponentAtNode(canvas);
|
|
180
|
+
setCanvas(canvasRef.current);
|
|
165
181
|
}, []);
|
|
182
|
+
React.useEffect(() => {
|
|
183
|
+
if (canvas) return () => unmountComponentAtNode(canvas);
|
|
184
|
+
}, [canvas]);
|
|
166
185
|
return /*#__PURE__*/React.createElement("div", _extends({
|
|
167
186
|
ref: mergeRefs([meshRef, containerRef]),
|
|
168
187
|
style: {
|
|
@@ -172,7 +191,7 @@ const Canvas = /*#__PURE__*/React.forwardRef(function Canvas({
|
|
|
172
191
|
overflow: 'hidden',
|
|
173
192
|
...style
|
|
174
193
|
}
|
|
175
|
-
},
|
|
194
|
+
}, props), /*#__PURE__*/React.createElement("canvas", {
|
|
176
195
|
ref: mergeRefs([canvasRef, forwardedRef]),
|
|
177
196
|
style: {
|
|
178
197
|
display: 'block'
|