@react-three/fiber 8.0.9 → 8.0.12
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 +1 -1
- package/dist/declarations/src/core/index.d.ts +8 -4
- package/dist/declarations/src/core/store.d.ts +3 -2
- package/dist/declarations/src/core/utils.d.ts +7 -6
- package/dist/declarations/src/index.d.ts +3 -3
- package/dist/declarations/src/native/Canvas.d.ts +1 -1
- package/dist/declarations/src/native.d.ts +3 -3
- package/dist/declarations/src/three-types.d.ts +3 -1
- package/dist/{index-4e14a95b.esm.js → index-38c121a8.esm.js} +122 -93
- package/dist/{index-4dae9cc6.cjs.prod.js → index-e322e5c8.cjs.prod.js} +125 -100
- package/dist/{index-49237346.cjs.dev.js → index-f67eaa0c.cjs.dev.js} +125 -100
- package/dist/react-three-fiber.cjs.dev.js +42 -25
- package/dist/react-three-fiber.cjs.prod.js +42 -25
- package/dist/react-three-fiber.esm.js +38 -19
- package/native/dist/react-three-fiber-native.cjs.dev.js +53 -38
- package/native/dist/react-three-fiber-native.cjs.prod.js +53 -38
- package/native/dist/react-three-fiber-native.esm.js +50 -33
- package/package.json +2 -2
|
@@ -19,14 +19,12 @@ function _interopNamespace(e) {
|
|
|
19
19
|
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
20
20
|
Object.defineProperty(n, k, d.get ? d : {
|
|
21
21
|
enumerable: true,
|
|
22
|
-
get: function () {
|
|
23
|
-
return e[k];
|
|
24
|
-
}
|
|
22
|
+
get: function () { return e[k]; }
|
|
25
23
|
});
|
|
26
24
|
}
|
|
27
25
|
});
|
|
28
26
|
}
|
|
29
|
-
n[
|
|
27
|
+
n["default"] = e;
|
|
30
28
|
return Object.freeze(n);
|
|
31
29
|
}
|
|
32
30
|
|
|
@@ -39,9 +37,10 @@ var threeTypes = /*#__PURE__*/Object.freeze({
|
|
|
39
37
|
__proto__: null
|
|
40
38
|
});
|
|
41
39
|
|
|
42
|
-
// React currently throws a warning when using useLayoutEffect on the server.
|
|
40
|
+
const isOrthographicCamera = def => def && def.isOrthographicCamera; // React currently throws a warning when using useLayoutEffect on the server.
|
|
43
41
|
// To get around it, we can conditionally useEffect on the server (no-op) and
|
|
44
42
|
// useLayoutEffect on the client.
|
|
43
|
+
|
|
45
44
|
const isSSR = typeof window === 'undefined' || !window.navigator || /ServerSideRendering|^Deno\//.test(window.navigator.userAgent);
|
|
46
45
|
const useIsomorphicLayoutEffect = isSSR ? React__namespace.useEffect : React__namespace.useLayoutEffect;
|
|
47
46
|
function useMutableCallback(fn) {
|
|
@@ -94,29 +93,6 @@ const getRootState = obj => {
|
|
|
94
93
|
|
|
95
94
|
return (_r3f = obj.__r3f) == null ? void 0 : _r3f.root.getState();
|
|
96
95
|
};
|
|
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
96
|
// A collection of compare functions
|
|
121
97
|
const is = {
|
|
122
98
|
obj: a => a === Object(a) && !is.arr(a) && typeof a !== 'function',
|
|
@@ -342,12 +318,16 @@ function applyProps$1(instance, data) {
|
|
|
342
318
|
|
|
343
319
|
if (value === DEFAULT + 'remove') {
|
|
344
320
|
if (targetProp && targetProp.constructor) {
|
|
321
|
+
var _memoized$args;
|
|
322
|
+
|
|
345
323
|
// use the prop constructor to find the default it should be
|
|
346
|
-
value = new targetProp.constructor(...memoized.args);
|
|
324
|
+
value = new targetProp.constructor(...((_memoized$args = memoized.args) != null ? _memoized$args : []));
|
|
347
325
|
} else if (currentInstance.constructor) {
|
|
326
|
+
var _currentInstance$__r;
|
|
327
|
+
|
|
348
328
|
// create a blank slate of the instance and copy the particular parameter.
|
|
349
329
|
// @ts-ignore
|
|
350
|
-
const defaultClassCall = new currentInstance.constructor(...currentInstance.__r3f.memoizedProps.args);
|
|
330
|
+
const defaultClassCall = new currentInstance.constructor(...((_currentInstance$__r = currentInstance.__r3f.memoizedProps.args) != null ? _currentInstance$__r : []));
|
|
351
331
|
value = defaultClassCall[targetProp]; // destory the instance
|
|
352
332
|
|
|
353
333
|
if (defaultClassCall.dispose) defaultClassCall.dispose(); // instance does not have constructor, just set it to 0
|
|
@@ -362,35 +342,35 @@ function applyProps$1(instance, data) {
|
|
|
362
342
|
localState.eventCount = Object.keys(localState.handlers).length;
|
|
363
343
|
} // Special treatment for objects with support for set/copy, and layers
|
|
364
344
|
else if (targetProp && targetProp.set && (targetProp.copy || targetProp instanceof THREE__namespace.Layers)) {
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
// https://github.com/pmndrs/react-three-fiber/issues/344
|
|
381
|
-
|
|
382
|
-
const supportsColorManagement = THREE__namespace.ColorManagement;
|
|
383
|
-
if (!supportsColorManagement && !rootState.linear && isColor) targetProp.convertSRGBToLinear();
|
|
384
|
-
} // Else, just overwrite the value
|
|
385
|
-
|
|
386
|
-
} else {
|
|
387
|
-
currentInstance[key] = value; // Auto-convert sRGB textures, for now ...
|
|
345
|
+
// If value is an array
|
|
346
|
+
if (Array.isArray(value)) {
|
|
347
|
+
if (targetProp.fromArray) targetProp.fromArray(value);else targetProp.set(...value);
|
|
348
|
+
} // Test again target.copy(class) next ...
|
|
349
|
+
else if (targetProp.copy && value && value.constructor && targetProp.constructor.name === value.constructor.name) {
|
|
350
|
+
targetProp.copy(value);
|
|
351
|
+
} // If nothing else fits, just set the single value, ignore undefined
|
|
352
|
+
// https://github.com/pmndrs/react-three-fiber/issues/274
|
|
353
|
+
else if (value !== undefined) {
|
|
354
|
+
const isColor = targetProp instanceof THREE__namespace.Color; // Allow setting array scalars
|
|
355
|
+
|
|
356
|
+
if (!isColor && targetProp.setScalar) targetProp.setScalar(value); // Layers have no copy function, we must therefore copy the mask property
|
|
357
|
+
else if (targetProp instanceof THREE__namespace.Layers && value instanceof THREE__namespace.Layers) targetProp.mask = value.mask; // Otherwise just set ...
|
|
358
|
+
else targetProp.set(value); // For versions of three which don't support THREE.ColorManagement,
|
|
359
|
+
// Auto-convert sRGB colors
|
|
388
360
|
// https://github.com/pmndrs/react-three-fiber/issues/344
|
|
389
361
|
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
362
|
+
const supportsColorManagement = THREE__namespace.ColorManagement;
|
|
363
|
+
if (!supportsColorManagement && !rootState.linear && isColor) targetProp.convertSRGBToLinear();
|
|
364
|
+
} // Else, just overwrite the value
|
|
365
|
+
|
|
366
|
+
} else {
|
|
367
|
+
currentInstance[key] = value; // Auto-convert sRGB textures, for now ...
|
|
368
|
+
// https://github.com/pmndrs/react-three-fiber/issues/344
|
|
369
|
+
|
|
370
|
+
if (!rootState.linear && currentInstance[key] instanceof THREE__namespace.Texture) {
|
|
371
|
+
currentInstance[key].encoding = THREE__namespace.sRGBEncoding;
|
|
393
372
|
}
|
|
373
|
+
}
|
|
394
374
|
|
|
395
375
|
invalidateInstance(instance);
|
|
396
376
|
});
|
|
@@ -416,6 +396,25 @@ function invalidateInstance(instance) {
|
|
|
416
396
|
function updateInstance(instance) {
|
|
417
397
|
instance.onUpdate == null ? void 0 : instance.onUpdate(instance);
|
|
418
398
|
}
|
|
399
|
+
function updateCamera(camera, size) {
|
|
400
|
+
// https://github.com/pmndrs/react-three-fiber/issues/92
|
|
401
|
+
// Do not mess with the camera if it belongs to the user
|
|
402
|
+
if (!camera.manual) {
|
|
403
|
+
if (isOrthographicCamera(camera)) {
|
|
404
|
+
camera.left = size.width / -2;
|
|
405
|
+
camera.right = size.width / 2;
|
|
406
|
+
camera.top = size.height / 2;
|
|
407
|
+
camera.bottom = size.height / -2;
|
|
408
|
+
} else {
|
|
409
|
+
camera.aspect = size.width / size.height;
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
camera.updateProjectionMatrix(); // https://github.com/pmndrs/react-three-fiber/issues/178
|
|
413
|
+
// Update matrix world since the renderer is a frame late
|
|
414
|
+
|
|
415
|
+
camera.updateMatrixWorld();
|
|
416
|
+
}
|
|
417
|
+
}
|
|
419
418
|
|
|
420
419
|
function makeId(event) {
|
|
421
420
|
return (event.eventObject || event.object).uuid + '/' + event.index + event.instanceId;
|
|
@@ -1055,7 +1054,7 @@ function createRenderer(roots, getEventPriority) {
|
|
|
1055
1054
|
});
|
|
1056
1055
|
}
|
|
1057
1056
|
|
|
1058
|
-
const reconciler = Reconciler__default[
|
|
1057
|
+
const reconciler = Reconciler__default["default"]({
|
|
1059
1058
|
createInstance,
|
|
1060
1059
|
removeChild,
|
|
1061
1060
|
appendChild,
|
|
@@ -1188,12 +1187,12 @@ function createRenderer(roots, getEventPriority) {
|
|
|
1188
1187
|
};
|
|
1189
1188
|
}
|
|
1190
1189
|
|
|
1190
|
+
const privateKeys = ['set', 'get', 'setSize', 'setFrameloop', 'setDpr', 'events', 'invalidate', 'advance', 'size', 'viewport'];
|
|
1191
1191
|
const isRenderer = def => !!(def != null && def.render);
|
|
1192
|
-
const isOrthographicCamera = def => def && def.isOrthographicCamera;
|
|
1193
1192
|
const context = /*#__PURE__*/React__namespace.createContext(null);
|
|
1194
1193
|
|
|
1195
1194
|
const createStore = (invalidate, advance) => {
|
|
1196
|
-
const rootState = create__default[
|
|
1195
|
+
const rootState = create__default["default"]((set, get) => {
|
|
1197
1196
|
const position = new THREE__namespace.Vector3();
|
|
1198
1197
|
const defaultTarget = new THREE__namespace.Vector3();
|
|
1199
1198
|
const tempTarget = new THREE__namespace.Vector3();
|
|
@@ -1396,24 +1395,7 @@ const createStore = (invalidate, advance) => {
|
|
|
1396
1395
|
} = rootState.getState();
|
|
1397
1396
|
|
|
1398
1397
|
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
|
-
|
|
1398
|
+
updateCamera(camera, size); // Update renderer
|
|
1417
1399
|
|
|
1418
1400
|
gl.setPixelRatio(viewport.dpr);
|
|
1419
1401
|
gl.setSize(size.width, size.height);
|
|
@@ -1952,56 +1934,101 @@ function Portal({
|
|
|
1952
1934
|
* {createPortal(...)} */
|
|
1953
1935
|
const {
|
|
1954
1936
|
events,
|
|
1937
|
+
size,
|
|
1955
1938
|
...rest
|
|
1956
1939
|
} = state;
|
|
1957
1940
|
const previousRoot = useStore();
|
|
1958
1941
|
const [raycaster] = React__namespace.useState(() => new THREE__namespace.Raycaster());
|
|
1959
1942
|
const [pointer] = React__namespace.useState(() => new THREE__namespace.Vector2());
|
|
1960
|
-
const inject = React__namespace.useCallback((
|
|
1961
|
-
const intersect = { ...
|
|
1962
|
-
};
|
|
1943
|
+
const inject = React__namespace.useCallback((rootState, injectState) => {
|
|
1944
|
+
const intersect = { ...rootState
|
|
1945
|
+
}; // all prev state props
|
|
1946
|
+
// Only the fields of "rootState" that do not differ from injectState
|
|
1947
|
+
// Some props should be off-limits
|
|
1948
|
+
// Otherwise filter out the props that are different and let the inject layer take precedence
|
|
1949
|
+
|
|
1950
|
+
Object.keys(rootState).forEach(key => {
|
|
1951
|
+
if ( // Some props should be off-limits
|
|
1952
|
+
privateKeys.includes(key) || // Otherwise filter out the props that are different and let the inject layer take precedence
|
|
1953
|
+
rootState[key] !== injectState[key]) {
|
|
1954
|
+
delete intersect[key];
|
|
1955
|
+
}
|
|
1956
|
+
});
|
|
1957
|
+
let viewport = undefined;
|
|
1963
1958
|
|
|
1964
|
-
if (injectState) {
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
});
|
|
1959
|
+
if (injectState && size) {
|
|
1960
|
+
const camera = injectState.camera; // Calculate the override viewport, if present
|
|
1961
|
+
|
|
1962
|
+
viewport = rootState.viewport.getCurrentViewport(camera, new THREE__namespace.Vector3(), size); // Update the portal camera, if it differs from the previous layer
|
|
1963
|
+
|
|
1964
|
+
if (camera !== rootState.camera) updateCamera(camera, size);
|
|
1971
1965
|
}
|
|
1972
1966
|
|
|
1973
|
-
return {
|
|
1967
|
+
return { // The intersect consists of the previous root state
|
|
1968
|
+
...intersect,
|
|
1969
|
+
// Portals have their own scene, which forms the root, a raycaster and a pointer
|
|
1974
1970
|
scene: container,
|
|
1975
|
-
previousRoot,
|
|
1976
1971
|
raycaster,
|
|
1977
|
-
|
|
1972
|
+
pointer,
|
|
1973
|
+
mouse: pointer,
|
|
1974
|
+
// Their previous root is the layer before it
|
|
1975
|
+
previousRoot,
|
|
1976
|
+
// Events, size and viewport can be overridden by the inject layer
|
|
1977
|
+
events: { ...rootState.events,
|
|
1978
1978
|
...(injectState == null ? void 0 : injectState.events),
|
|
1979
|
-
pointer,
|
|
1980
|
-
mouse: pointer,
|
|
1981
1979
|
...events
|
|
1982
1980
|
},
|
|
1981
|
+
size: { ...rootState.size,
|
|
1982
|
+
...size
|
|
1983
|
+
},
|
|
1984
|
+
viewport: { ...rootState.viewport,
|
|
1985
|
+
...viewport
|
|
1986
|
+
},
|
|
1983
1987
|
...rest
|
|
1984
1988
|
};
|
|
1985
1989
|
}, [state]);
|
|
1986
|
-
const [
|
|
1987
|
-
|
|
1990
|
+
const [usePortalStore] = React__namespace.useState(() => {
|
|
1991
|
+
// Create a mirrored store, based on the previous root with a few overrides ...
|
|
1992
|
+
const previousState = previousRoot.getState();
|
|
1993
|
+
const store = create__default["default"]((set, get) => ({ ...previousState,
|
|
1994
|
+
scene: container,
|
|
1995
|
+
raycaster,
|
|
1996
|
+
pointer,
|
|
1997
|
+
mouse: pointer,
|
|
1998
|
+
previousRoot,
|
|
1999
|
+
events: { ...previousState.events,
|
|
2000
|
+
...events
|
|
2001
|
+
},
|
|
2002
|
+
size: { ...previousState.size,
|
|
2003
|
+
...size
|
|
2004
|
+
},
|
|
2005
|
+
...rest,
|
|
2006
|
+
// Set and get refer to this root-state
|
|
1988
2007
|
set,
|
|
1989
2008
|
get,
|
|
2009
|
+
// Layers are allowed to override events
|
|
1990
2010
|
setEvents: events => set(state => ({ ...state,
|
|
1991
2011
|
events: { ...state.events,
|
|
1992
2012
|
...events
|
|
1993
2013
|
}
|
|
1994
2014
|
}))
|
|
1995
2015
|
}));
|
|
1996
|
-
previousRoot.subscribe(state => useInjectStore.setState(injectState => inject(state, injectState)));
|
|
1997
2016
|
return store;
|
|
1998
2017
|
});
|
|
1999
2018
|
React__namespace.useEffect(() => {
|
|
2000
|
-
|
|
2019
|
+
// Subscribe to previous root-state and copy changes over to the mirrored portal-state
|
|
2020
|
+
const unsub = previousRoot.subscribe(prev => usePortalStore.setState(state => inject(prev, state)));
|
|
2021
|
+
return () => {
|
|
2022
|
+
unsub();
|
|
2023
|
+
usePortalStore.destroy();
|
|
2024
|
+
};
|
|
2025
|
+
}, []);
|
|
2026
|
+
React__namespace.useEffect(() => {
|
|
2027
|
+
usePortalStore.setState(injectState => inject(previousRoot.getState(), injectState));
|
|
2001
2028
|
}, [inject]);
|
|
2002
2029
|
return /*#__PURE__*/React__namespace.createElement(React__namespace.Fragment, null, reconciler.createPortal( /*#__PURE__*/React__namespace.createElement(context.Provider, {
|
|
2003
|
-
value:
|
|
2004
|
-
}, children),
|
|
2030
|
+
value: usePortalStore
|
|
2031
|
+
}, children), usePortalStore, null));
|
|
2005
2032
|
}
|
|
2006
2033
|
|
|
2007
2034
|
reconciler.injectIntoDevTools({
|
|
@@ -2027,8 +2054,6 @@ exports.dispose = dispose;
|
|
|
2027
2054
|
exports.extend = extend;
|
|
2028
2055
|
exports.getRootState = getRootState;
|
|
2029
2056
|
exports.invalidate = invalidate;
|
|
2030
|
-
exports.omit = omit;
|
|
2031
|
-
exports.pick = pick;
|
|
2032
2057
|
exports.reconciler = reconciler;
|
|
2033
2058
|
exports.render = render;
|
|
2034
2059
|
exports.roots = roots;
|