@react-three/fiber 8.0.0-beta.2 → 8.0.0-beta.5
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/dist/declarations/src/core/events.d.ts +3 -3
- package/dist/declarations/src/core/hooks.d.ts +6 -2
- package/dist/declarations/src/core/index.d.ts +5 -5
- package/dist/declarations/src/core/renderer.d.ts +7 -6
- package/dist/declarations/src/core/store.d.ts +3 -3
- package/dist/declarations/src/native/Canvas.d.ts +2 -2
- package/dist/declarations/src/native/events.d.ts +2 -2
- package/dist/declarations/src/web/Canvas.d.ts +2 -2
- package/dist/declarations/src/web/events.d.ts +2 -2
- package/dist/{index-e78dd2f0.esm.js → index-32069e53.esm.js} +168 -132
- package/dist/{index-05ebefd3.cjs.dev.js → index-5dc2de40.cjs.dev.js} +169 -132
- package/dist/{index-85b2df17.cjs.prod.js → index-e2a317e2.cjs.prod.js} +169 -132
- package/dist/react-three-fiber.cjs.dev.js +3 -2
- package/dist/react-three-fiber.cjs.prod.js +3 -2
- package/dist/react-three-fiber.esm.js +3 -3
- package/native/dist/react-three-fiber-native.cjs.dev.js +4 -3
- package/native/dist/react-three-fiber-native.cjs.prod.js +4 -3
- package/native/dist/react-three-fiber-native.esm.js +4 -4
- package/package.json +8 -7
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var React = require('react');
|
|
4
|
-
var suspendReact = require('suspend-react');
|
|
5
3
|
var THREE = require('three');
|
|
4
|
+
var React = require('react');
|
|
6
5
|
var constants = require('react-reconciler/constants');
|
|
7
6
|
var create = require('zustand');
|
|
8
7
|
var Reconciler = require('react-reconciler');
|
|
9
8
|
var scheduler = require('scheduler');
|
|
9
|
+
var suspendReact = require('suspend-react');
|
|
10
10
|
|
|
11
11
|
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
|
|
12
12
|
|
|
@@ -30,8 +30,8 @@ function _interopNamespace(e) {
|
|
|
30
30
|
return Object.freeze(n);
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
34
33
|
var THREE__namespace = /*#__PURE__*/_interopNamespace(THREE);
|
|
34
|
+
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
35
35
|
var create__default = /*#__PURE__*/_interopDefault(create);
|
|
36
36
|
var Reconciler__default = /*#__PURE__*/_interopDefault(Reconciler);
|
|
37
37
|
|
|
@@ -95,7 +95,7 @@ const is = {
|
|
|
95
95
|
const isArr = is.arr(a);
|
|
96
96
|
if (isArr && arrays === 'reference') return a === b; // Array or Object, shallow compare first to see if it's a match
|
|
97
97
|
|
|
98
|
-
if ((isArr || isObj) && a
|
|
98
|
+
if ((isArr || isObj) && a === b) return true; // Last resort, go through keys
|
|
99
99
|
|
|
100
100
|
let i;
|
|
101
101
|
|
|
@@ -103,7 +103,13 @@ const is = {
|
|
|
103
103
|
|
|
104
104
|
for (i in strict ? b : a) if (a[i] !== b[i]) return false;
|
|
105
105
|
|
|
106
|
-
|
|
106
|
+
if (is.und(i)) {
|
|
107
|
+
if (isArr && a.length === 0 && b.length === 0) return true;
|
|
108
|
+
if (isObj && Object.keys(a).length === 0 && Object.keys(b).length === 0) return true;
|
|
109
|
+
if (a !== b) return false;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return true;
|
|
107
113
|
}
|
|
108
114
|
|
|
109
115
|
}; // Collects nodes and materials from a THREE.Object3D
|
|
@@ -138,7 +144,9 @@ function prepare(object, state) {
|
|
|
138
144
|
|
|
139
145
|
if (state != null && state.primitive || !instance.__r3f) {
|
|
140
146
|
instance.__r3f = {
|
|
147
|
+
type: '',
|
|
141
148
|
root: null,
|
|
149
|
+
previousAttach: null,
|
|
142
150
|
memoizedProps: {},
|
|
143
151
|
eventCount: 0,
|
|
144
152
|
handlers: {},
|
|
@@ -166,32 +174,42 @@ function resolve(instance, key) {
|
|
|
166
174
|
target,
|
|
167
175
|
key
|
|
168
176
|
};
|
|
169
|
-
}
|
|
177
|
+
} // Checks if a dash-cased string ends with an integer
|
|
170
178
|
|
|
179
|
+
|
|
180
|
+
const INDEX_REGEX = /-\d+$/;
|
|
171
181
|
function attach(parent, child, type) {
|
|
172
182
|
if (is.str(type)) {
|
|
183
|
+
// If attaching into an array (foo-0), create one
|
|
184
|
+
if (INDEX_REGEX.test(type)) {
|
|
185
|
+
const root = type.replace(INDEX_REGEX, '');
|
|
186
|
+
const {
|
|
187
|
+
target,
|
|
188
|
+
key
|
|
189
|
+
} = resolve(parent, root);
|
|
190
|
+
if (!Array.isArray(target[key])) target[key] = [];
|
|
191
|
+
}
|
|
192
|
+
|
|
173
193
|
const {
|
|
174
194
|
target,
|
|
175
195
|
key
|
|
176
196
|
} = resolve(parent, type);
|
|
177
|
-
|
|
197
|
+
child.__r3f.previousAttach = target[key];
|
|
178
198
|
target[key] = child;
|
|
179
|
-
} else
|
|
180
|
-
const [attach] = type;
|
|
181
|
-
if (is.str(attach)) parent[attach](child);else if (is.fun(attach)) attach(parent, child);
|
|
182
|
-
}
|
|
199
|
+
} else child.__r3f.previousAttach = type(parent, child);
|
|
183
200
|
}
|
|
184
201
|
function detach(parent, child, type) {
|
|
202
|
+
var _child$__r3f, _child$__r3f2;
|
|
203
|
+
|
|
185
204
|
if (is.str(type)) {
|
|
186
205
|
const {
|
|
187
206
|
target,
|
|
188
207
|
key
|
|
189
208
|
} = resolve(parent, type);
|
|
190
|
-
target[key] =
|
|
191
|
-
} else
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
}
|
|
209
|
+
target[key] = child.__r3f.previousAttach;
|
|
210
|
+
} else (_child$__r3f = child.__r3f) == null ? void 0 : _child$__r3f.previousAttach == null ? void 0 : _child$__r3f.previousAttach(parent, child);
|
|
211
|
+
|
|
212
|
+
(_child$__r3f2 = child.__r3f) == null ? true : delete _child$__r3f2.previousAttach;
|
|
195
213
|
} // This function prepares a set of changes to be applied to the instance
|
|
196
214
|
|
|
197
215
|
function diffProps(instance, {
|
|
@@ -279,11 +297,11 @@ function applyProps$1(instance, data) {
|
|
|
279
297
|
if (value === DEFAULT + 'remove') {
|
|
280
298
|
if (targetProp && targetProp.constructor) {
|
|
281
299
|
// use the prop constructor to find the default it should be
|
|
282
|
-
value = new targetProp.constructor(memoized.args);
|
|
300
|
+
value = new targetProp.constructor(...memoized.args);
|
|
283
301
|
} else if (currentInstance.constructor) {
|
|
284
302
|
// create a blank slate of the instance and copy the particular parameter.
|
|
285
303
|
// @ts-ignore
|
|
286
|
-
const defaultClassCall = new currentInstance.constructor(currentInstance.__r3f.memoizedProps.args);
|
|
304
|
+
const defaultClassCall = new currentInstance.constructor(...currentInstance.__r3f.memoizedProps.args);
|
|
287
305
|
value = defaultClassCall[targetProp]; // destory the instance
|
|
288
306
|
|
|
289
307
|
if (defaultClassCall.dispose) defaultClassCall.dispose(); // instance does not have constructor, just set it to 0
|
|
@@ -311,20 +329,10 @@ function applyProps$1(instance, data) {
|
|
|
311
329
|
|
|
312
330
|
if (!isColor && targetProp.setScalar) targetProp.setScalar(value); // Layers have no copy function, we must therefore copy the mask property
|
|
313
331
|
else if (targetProp instanceof THREE__namespace.Layers && value instanceof THREE__namespace.Layers) targetProp.mask = value.mask; // Otherwise just set ...
|
|
314
|
-
else targetProp.set(value);
|
|
315
|
-
// https://github.com/pmndrs/react-three-fiber/issues/344
|
|
316
|
-
|
|
317
|
-
if (!rootState.linear && isColor) targetProp.convertSRGBToLinear();
|
|
332
|
+
else targetProp.set(value);
|
|
318
333
|
} // Else, just overwrite the value
|
|
319
334
|
|
|
320
|
-
} else
|
|
321
|
-
currentInstance[key] = value; // Auto-convert sRGB textures, for now ...
|
|
322
|
-
// https://github.com/pmndrs/react-three-fiber/issues/344
|
|
323
|
-
|
|
324
|
-
if (!rootState.linear && currentInstance[key] instanceof THREE__namespace.Texture) {
|
|
325
|
-
currentInstance[key].encoding = THREE__namespace.sRGBEncoding;
|
|
326
|
-
}
|
|
327
|
-
}
|
|
335
|
+
} else currentInstance[key] = value;
|
|
328
336
|
|
|
329
337
|
invalidateInstance(instance);
|
|
330
338
|
return instance;
|
|
@@ -775,23 +783,6 @@ function createEvents(store) {
|
|
|
775
783
|
};
|
|
776
784
|
}
|
|
777
785
|
|
|
778
|
-
// Type guard to tell a store from a portal
|
|
779
|
-
const isStore = def => def && !!def.getState;
|
|
780
|
-
|
|
781
|
-
const getContainer = (container, child) => {
|
|
782
|
-
var _container$__r3f$root, _container$__r3f;
|
|
783
|
-
|
|
784
|
-
return {
|
|
785
|
-
// If the container is not a root-store then it must be a THREE.Object3D into which part of the
|
|
786
|
-
// scene is portalled into. Now there can be two variants of this, either that object is part of
|
|
787
|
-
// the regular jsx tree, in which case it already has __r3f with a valid root attached, or it lies
|
|
788
|
-
// outside react, in which case we must take the root of the child that is about to be attached to it.
|
|
789
|
-
root: isStore(container) ? container : (_container$__r3f$root = (_container$__r3f = container.__r3f) == null ? void 0 : _container$__r3f.root) != null ? _container$__r3f$root : child.__r3f.root,
|
|
790
|
-
// The container is the eventual target into which objects are mounted, it has to be a THREE.Object3D
|
|
791
|
-
container: isStore(container) ? container.getState().scene : container
|
|
792
|
-
};
|
|
793
|
-
};
|
|
794
|
-
|
|
795
786
|
let catalogue = {};
|
|
796
787
|
|
|
797
788
|
let extend = objects => void (catalogue = { ...catalogue,
|
|
@@ -803,22 +794,9 @@ function createRenderer(roots, getEventPriority) {
|
|
|
803
794
|
args = [],
|
|
804
795
|
attach,
|
|
805
796
|
...props
|
|
806
|
-
}, root
|
|
797
|
+
}, root) {
|
|
807
798
|
let name = `${type[0].toUpperCase()}${type.slice(1)}`;
|
|
808
|
-
let instance; //
|
|
809
|
-
// Portals do not give us a root, they are themselves treated as a root by the reconciler
|
|
810
|
-
// In order to figure out the actual root we have to climb through fiber internals :(
|
|
811
|
-
|
|
812
|
-
if (!isStore(root) && internalInstanceHandle) {
|
|
813
|
-
const fn = node => {
|
|
814
|
-
if (!node.return) return node.stateNode && node.stateNode.containerInfo;else return fn(node.return);
|
|
815
|
-
};
|
|
816
|
-
|
|
817
|
-
root = fn(internalInstanceHandle);
|
|
818
|
-
} // Assert that by now we have a valid root
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
if (!root || !isStore(root)) throw `No valid root for ${name}!`; // Auto-attach geometries and materials
|
|
799
|
+
let instance; // Auto-attach geometries and materials
|
|
822
800
|
|
|
823
801
|
if (attach === undefined) {
|
|
824
802
|
if (name.endsWith('Geometry')) attach = 'geometry';else if (name.endsWith('Material')) attach = 'material';
|
|
@@ -828,6 +806,7 @@ function createRenderer(roots, getEventPriority) {
|
|
|
828
806
|
if (props.object === undefined) throw `Primitives without 'object' are invalid!`;
|
|
829
807
|
const object = props.object;
|
|
830
808
|
instance = prepare(object, {
|
|
809
|
+
type,
|
|
831
810
|
root,
|
|
832
811
|
attach,
|
|
833
812
|
primitive: true
|
|
@@ -844,19 +823,21 @@ function createRenderer(roots, getEventPriority) {
|
|
|
844
823
|
// Append memoized props with args so it's not forgotten
|
|
845
824
|
|
|
846
825
|
instance = prepare(new target(...args), {
|
|
826
|
+
type,
|
|
847
827
|
root,
|
|
848
828
|
attach,
|
|
849
829
|
// TODO: Figure out what this is for
|
|
850
830
|
memoizedProps: {
|
|
851
|
-
args
|
|
831
|
+
args
|
|
852
832
|
}
|
|
853
833
|
});
|
|
854
834
|
} // It should NOT call onUpdate on object instanciation, because it hasn't been added to the
|
|
855
835
|
// view yet. If the callback relies on references for instance, they won't be ready yet, this is
|
|
856
836
|
// why it passes "true" here
|
|
837
|
+
// There is no reason to apply props to injects
|
|
857
838
|
|
|
858
839
|
|
|
859
|
-
applyProps$1(instance, props);
|
|
840
|
+
if (name !== 'inject') applyProps$1(instance, props);
|
|
860
841
|
return instance;
|
|
861
842
|
}
|
|
862
843
|
|
|
@@ -978,11 +959,11 @@ function createRenderer(roots, getEventPriority) {
|
|
|
978
959
|
}
|
|
979
960
|
|
|
980
961
|
function switchInstance(instance, type, newProps, fiber) {
|
|
981
|
-
var _instance$__r3f;
|
|
962
|
+
var _instance$__r3f, _instance$__r3f2;
|
|
982
963
|
|
|
983
964
|
const parent = (_instance$__r3f = instance.__r3f) == null ? void 0 : _instance$__r3f.parent;
|
|
984
965
|
if (!parent) return;
|
|
985
|
-
const newInstance = createInstance(type, newProps, instance.__r3f.root); // https://github.com/pmndrs/react-three-fiber/issues/1348
|
|
966
|
+
const newInstance = createInstance(type, newProps, (_instance$__r3f2 = instance.__r3f) == null ? void 0 : _instance$__r3f2.root); // https://github.com/pmndrs/react-three-fiber/issues/1348
|
|
986
967
|
// When args change the instance has to be re-constructed, which then
|
|
987
968
|
// forces r3f to re-parent the children and non-scene objects
|
|
988
969
|
// This can not include primitives, which should not have declarative children
|
|
@@ -1015,19 +996,38 @@ function createRenderer(roots, getEventPriority) {
|
|
|
1015
996
|
}
|
|
1016
997
|
|
|
1017
998
|
const reconciler = Reconciler__default['default']({
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
999
|
+
createInstance,
|
|
1000
|
+
removeChild,
|
|
1001
|
+
appendChild,
|
|
1002
|
+
appendInitialChild: appendChild,
|
|
1003
|
+
insertBefore,
|
|
1004
|
+
supportsMicrotask: true,
|
|
1005
|
+
warnsIfNotActing: true,
|
|
1006
|
+
supportsMutation: true,
|
|
1007
|
+
isPrimaryRenderer: false,
|
|
1008
|
+
noTimeout: -1,
|
|
1009
|
+
appendChildToContainer: (container, child) => {
|
|
1010
|
+
const scene = container.getState().scene; // Link current root to the default scene
|
|
1011
|
+
|
|
1012
|
+
scene.__r3f.root = container;
|
|
1013
|
+
appendChild(scene, child);
|
|
1014
|
+
},
|
|
1015
|
+
removeChildFromContainer: (container, child) => removeChild(container.getState().scene, child),
|
|
1016
|
+
insertInContainerBefore: (container, child, beforeChild) => insertBefore(container.getState().scene, child, beforeChild),
|
|
1017
|
+
getRootHostContext: () => null,
|
|
1018
|
+
getChildHostContext: parentHostContext => parentHostContext,
|
|
1019
|
+
|
|
1020
|
+
finalizeInitialChildren(instance) {
|
|
1021
|
+
var _instance$__r3f3;
|
|
1022
|
+
|
|
1023
|
+
const localState = (_instance$__r3f3 = instance == null ? void 0 : instance.__r3f) != null ? _instance$__r3f3 : {}; // https://github.com/facebook/react/issues/20271
|
|
1024
|
+
// Returning true will trigger commitMount
|
|
1023
1025
|
|
|
1024
|
-
|
|
1025
|
-
appendChild(container, child);
|
|
1026
|
+
return !!localState.handlers;
|
|
1026
1027
|
},
|
|
1027
|
-
removeChildFromContainer: (parentInstance, child) => removeChild(getContainer(parentInstance, child).container, child),
|
|
1028
|
-
insertInContainerBefore: (parentInstance, child, beforeChild) => insertBefore(getContainer(parentInstance, child).container, child, beforeChild),
|
|
1029
1028
|
|
|
1030
1029
|
prepareUpdate(instance, type, oldProps, newProps) {
|
|
1030
|
+
// Create diff-sets
|
|
1031
1031
|
if (instance.__r3f.primitive && newProps.object && newProps.object !== instance) {
|
|
1032
1032
|
return [true];
|
|
1033
1033
|
} else {
|
|
@@ -1060,40 +1060,58 @@ function createRenderer(roots, getEventPriority) {
|
|
|
1060
1060
|
else applyProps$1(instance, diff);
|
|
1061
1061
|
},
|
|
1062
1062
|
|
|
1063
|
+
commitMount(instance, type, props, int) {
|
|
1064
|
+
var _instance$__r3f4;
|
|
1065
|
+
|
|
1066
|
+
// https://github.com/facebook/react/issues/20271
|
|
1067
|
+
// This will make sure events are only added once to the central container
|
|
1068
|
+
const localState = (_instance$__r3f4 = instance == null ? void 0 : instance.__r3f) != null ? _instance$__r3f4 : {};
|
|
1069
|
+
|
|
1070
|
+
if (instance.raycast && localState.handlers && localState.eventCount) {
|
|
1071
|
+
instance.__r3f.root.getState().internal.interaction.push(instance);
|
|
1072
|
+
}
|
|
1073
|
+
},
|
|
1074
|
+
|
|
1075
|
+
getPublicInstance: instance => instance,
|
|
1076
|
+
shouldDeprioritizeSubtree: () => false,
|
|
1077
|
+
prepareForCommit: () => null,
|
|
1078
|
+
preparePortalMount: container => prepare(container.getState().scene),
|
|
1079
|
+
resetAfterCommit: () => {},
|
|
1080
|
+
shouldSetTextContent: () => false,
|
|
1081
|
+
clearContainer: () => false,
|
|
1082
|
+
detachDeletedInstance: () => {},
|
|
1083
|
+
createTextInstance: () => {},
|
|
1084
|
+
|
|
1063
1085
|
hideInstance(instance) {
|
|
1064
|
-
var _instance$
|
|
1086
|
+
var _instance$__r3f5;
|
|
1065
1087
|
|
|
1066
1088
|
// Deatch while the instance is hidden
|
|
1067
1089
|
const {
|
|
1068
1090
|
attach: type,
|
|
1069
1091
|
parent
|
|
1070
|
-
} = (_instance$
|
|
1092
|
+
} = (_instance$__r3f5 = instance == null ? void 0 : instance.__r3f) != null ? _instance$__r3f5 : {};
|
|
1071
1093
|
if (type && parent) detach(parent, instance, type);
|
|
1072
1094
|
if (instance.isObject3D) instance.visible = false;
|
|
1073
1095
|
invalidateInstance(instance);
|
|
1074
1096
|
},
|
|
1075
1097
|
|
|
1076
1098
|
unhideInstance(instance, props) {
|
|
1077
|
-
var _instance$
|
|
1099
|
+
var _instance$__r3f6;
|
|
1078
1100
|
|
|
1079
1101
|
// Re-attach when the instance is unhidden
|
|
1080
1102
|
const {
|
|
1081
1103
|
attach: type,
|
|
1082
1104
|
parent
|
|
1083
|
-
} = (_instance$
|
|
1105
|
+
} = (_instance$__r3f6 = instance == null ? void 0 : instance.__r3f) != null ? _instance$__r3f6 : {};
|
|
1084
1106
|
if (type && parent) attach(parent, instance, type);
|
|
1085
1107
|
if (instance.isObject3D && props.visible == null || props.visible) instance.visible = true;
|
|
1086
1108
|
invalidateInstance(instance);
|
|
1087
1109
|
},
|
|
1088
1110
|
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
insertBefore,
|
|
1094
|
-
warnsIfNotActing: true,
|
|
1095
|
-
supportsMutation: true,
|
|
1096
|
-
isPrimaryRenderer: false,
|
|
1111
|
+
hideTextInstance: () => {
|
|
1112
|
+
throw new Error('Text is not allowed in the R3F tree.');
|
|
1113
|
+
},
|
|
1114
|
+
// prettier-ignore
|
|
1097
1115
|
getCurrentEventPriority: () => getEventPriority ? getEventPriority() : constants.DefaultEventPriority,
|
|
1098
1116
|
// @ts-ignore
|
|
1099
1117
|
now: typeof performance !== 'undefined' && is.fun(performance.now) ? performance.now : is.fun(Date.now) ? Date.now : undefined,
|
|
@@ -1102,47 +1120,7 @@ function createRenderer(roots, getEventPriority) {
|
|
|
1102
1120
|
// @ts-ignore
|
|
1103
1121
|
cancelTimeout: is.fun(clearTimeout) ? clearTimeout : undefined,
|
|
1104
1122
|
setTimeout: is.fun(setTimeout) ? setTimeout : undefined,
|
|
1105
|
-
clearTimeout: is.fun(clearTimeout) ? clearTimeout : undefined
|
|
1106
|
-
noTimeout: -1,
|
|
1107
|
-
hideTextInstance: () => {
|
|
1108
|
-
throw new Error('Text is not allowed in the R3F tree.');
|
|
1109
|
-
},
|
|
1110
|
-
// prettier-ignore
|
|
1111
|
-
getPublicInstance: instance => instance,
|
|
1112
|
-
getRootHostContext: () => null,
|
|
1113
|
-
getChildHostContext: parentHostContext => parentHostContext,
|
|
1114
|
-
createTextInstance: () => {},
|
|
1115
|
-
|
|
1116
|
-
finalizeInitialChildren(instance) {
|
|
1117
|
-
var _instance$__r3f4;
|
|
1118
|
-
|
|
1119
|
-
// https://github.com/facebook/react/issues/20271
|
|
1120
|
-
// Returning true will trigger commitMount
|
|
1121
|
-
const localState = (_instance$__r3f4 = instance == null ? void 0 : instance.__r3f) != null ? _instance$__r3f4 : {};
|
|
1122
|
-
return !!localState.handlers;
|
|
1123
|
-
},
|
|
1124
|
-
|
|
1125
|
-
commitMount(instance)
|
|
1126
|
-
/*, type, props*/
|
|
1127
|
-
{
|
|
1128
|
-
var _instance$__r3f5;
|
|
1129
|
-
|
|
1130
|
-
// https://github.com/facebook/react/issues/20271
|
|
1131
|
-
// This will make sure events are only added once to the central container
|
|
1132
|
-
const localState = (_instance$__r3f5 = instance == null ? void 0 : instance.__r3f) != null ? _instance$__r3f5 : {};
|
|
1133
|
-
|
|
1134
|
-
if (instance.raycast && localState.handlers && localState.eventCount) {
|
|
1135
|
-
instance.__r3f.root.getState().internal.interaction.push(instance);
|
|
1136
|
-
}
|
|
1137
|
-
},
|
|
1138
|
-
|
|
1139
|
-
shouldDeprioritizeSubtree: () => false,
|
|
1140
|
-
prepareForCommit: () => null,
|
|
1141
|
-
preparePortalMount: containerInfo => prepare(containerInfo),
|
|
1142
|
-
resetAfterCommit: () => {},
|
|
1143
|
-
shouldSetTextContent: () => false,
|
|
1144
|
-
clearContainer: () => false,
|
|
1145
|
-
detachDeletedInstance: () => {}
|
|
1123
|
+
clearTimeout: is.fun(clearTimeout) ? clearTimeout : undefined
|
|
1146
1124
|
});
|
|
1147
1125
|
return {
|
|
1148
1126
|
reconciler,
|
|
@@ -1489,6 +1467,43 @@ function useStore() {
|
|
|
1489
1467
|
function useThree(selector = state => state, equalityFn) {
|
|
1490
1468
|
return useStore()(selector, equalityFn);
|
|
1491
1469
|
}
|
|
1470
|
+
function useInject(state) {
|
|
1471
|
+
const useOriginalStore = useStore();
|
|
1472
|
+
const useInjectStore = React__namespace.useMemo(() => {
|
|
1473
|
+
const useInjected = (sel = state => state) => {
|
|
1474
|
+
// Execute the useStore hook with the selector once, to maintain reactivity, result doesn't matter
|
|
1475
|
+
useOriginalStore(sel); // Inject data and return the result, either selected or raw
|
|
1476
|
+
|
|
1477
|
+
return sel({ ...useOriginalStore.getState(),
|
|
1478
|
+
...state
|
|
1479
|
+
});
|
|
1480
|
+
};
|
|
1481
|
+
|
|
1482
|
+
useInjected.setState = useOriginalStore.setState;
|
|
1483
|
+
useInjected.destroy = useOriginalStore.destroy; // Patch getState
|
|
1484
|
+
|
|
1485
|
+
useInjected.getState = () => {
|
|
1486
|
+
return { ...useOriginalStore.getState(),
|
|
1487
|
+
...state
|
|
1488
|
+
};
|
|
1489
|
+
}; // Patch subscribe
|
|
1490
|
+
|
|
1491
|
+
|
|
1492
|
+
useInjected.subscribe = listener => {
|
|
1493
|
+
return useOriginalStore.subscribe((current, previous) => listener({ ...current,
|
|
1494
|
+
...state
|
|
1495
|
+
}, previous));
|
|
1496
|
+
};
|
|
1497
|
+
|
|
1498
|
+
return useInjected;
|
|
1499
|
+
}, [useOriginalStore, state]); // Return the patched store and a provider component
|
|
1500
|
+
|
|
1501
|
+
return React__namespace.useMemo(() => [({
|
|
1502
|
+
children
|
|
1503
|
+
}) => /*#__PURE__*/React__namespace.createElement(context.Provider, {
|
|
1504
|
+
value: useInjectStore
|
|
1505
|
+
}, children), useInjectStore], [useInjectStore]);
|
|
1506
|
+
}
|
|
1492
1507
|
function useFrame(callback, renderPriority = 0) {
|
|
1493
1508
|
const subscribe = useStore().getState().internal.subscribe; // Update ref
|
|
1494
1509
|
|
|
@@ -1652,7 +1667,7 @@ function createRoot(canvas) {
|
|
|
1652
1667
|
|
|
1653
1668
|
const handleSessionChange = () => {
|
|
1654
1669
|
const gl = store.getState().gl;
|
|
1655
|
-
gl.xr.enabled = gl.xr.isPresenting; // @ts-
|
|
1670
|
+
gl.xr.enabled = gl.xr.isPresenting; // @ts-ignore
|
|
1656
1671
|
// WebXRManager's signature is incorrect.
|
|
1657
1672
|
// See: https://github.com/pmndrs/react-three-fiber/pull/2017#discussion_r790134505
|
|
1658
1673
|
|
|
@@ -1694,6 +1709,7 @@ function createRoot(canvas) {
|
|
|
1694
1709
|
} // Set color management
|
|
1695
1710
|
|
|
1696
1711
|
|
|
1712
|
+
if (THREE__namespace.ColorManagement) THREE__namespace.ColorManagement.legacyMode = false;
|
|
1697
1713
|
const outputEncoding = linear ? THREE__namespace.LinearEncoding : THREE__namespace.sRGBEncoding;
|
|
1698
1714
|
const toneMapping = flat ? THREE__namespace.NoToneMapping : THREE__namespace.ACESFilmicToneMapping;
|
|
1699
1715
|
if (gl.outputEncoding !== outputEncoding) gl.outputEncoding = outputEncoding;
|
|
@@ -1809,10 +1825,29 @@ function unmountComponentAtNode(canvas, callback) {
|
|
|
1809
1825
|
}
|
|
1810
1826
|
}
|
|
1811
1827
|
|
|
1812
|
-
|
|
1828
|
+
function createPortal(children, container, state) {
|
|
1829
|
+
return /*#__PURE__*/React__namespace.createElement(Portal, {
|
|
1830
|
+
children: children,
|
|
1831
|
+
container: container,
|
|
1832
|
+
state: state
|
|
1833
|
+
});
|
|
1834
|
+
}
|
|
1813
1835
|
|
|
1814
|
-
function
|
|
1815
|
-
|
|
1836
|
+
function Portal({
|
|
1837
|
+
state,
|
|
1838
|
+
children,
|
|
1839
|
+
container
|
|
1840
|
+
}) {
|
|
1841
|
+
/** This has to be a component because it would not be able to call useThree/useStore otherwise since
|
|
1842
|
+
* if this is our environment, then we are in in r3f's renderer but in react-dom, it would trigger
|
|
1843
|
+
* the "R3F hooks can only be used within the Canvas component!" warning:
|
|
1844
|
+
* <Canvas>
|
|
1845
|
+
* {createPortal(...)} */
|
|
1846
|
+
const portalState = React__namespace.useMemo(() => ({ ...state,
|
|
1847
|
+
scene: container
|
|
1848
|
+
}), [state, container]);
|
|
1849
|
+
const [PortalProvider, portalRoot] = useInject(portalState);
|
|
1850
|
+
return /*#__PURE__*/React__namespace.createElement(React__namespace.Fragment, null, reconciler.createPortal( /*#__PURE__*/React__namespace.createElement(PortalProvider, null, children), portalRoot, null));
|
|
1816
1851
|
}
|
|
1817
1852
|
|
|
1818
1853
|
reconciler.injectIntoDevTools({
|
|
@@ -1820,6 +1855,7 @@ reconciler.injectIntoDevTools({
|
|
|
1820
1855
|
rendererPackageName: '@react-three/fiber',
|
|
1821
1856
|
version: '18.0.0'
|
|
1822
1857
|
});
|
|
1858
|
+
const act = React__namespace.unstable_act;
|
|
1823
1859
|
|
|
1824
1860
|
exports.act = act;
|
|
1825
1861
|
exports.addAfterEffect = addAfterEffect;
|
|
@@ -1843,6 +1879,7 @@ exports.threeTypes = threeTypes;
|
|
|
1843
1879
|
exports.unmountComponentAtNode = unmountComponentAtNode;
|
|
1844
1880
|
exports.useFrame = useFrame;
|
|
1845
1881
|
exports.useGraph = useGraph;
|
|
1882
|
+
exports.useInject = useInject;
|
|
1846
1883
|
exports.useLoader = useLoader;
|
|
1847
1884
|
exports.useStore = useStore;
|
|
1848
1885
|
exports.useThree = useThree;
|