@react-three/fiber 8.0.0-alpha-08 → 8.0.0-alpha-09
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 +2 -2
- package/dist/declarations/src/core/hooks.d.ts +1 -1
- package/dist/declarations/src/core/renderer.d.ts +4 -15
- package/dist/declarations/src/core/utils.d.ts +27 -0
- package/dist/declarations/src/web/Canvas.d.ts +1 -1
- package/dist/declarations/src/web/events.d.ts +2 -1
- package/dist/declarations/src/web/index.d.ts +1 -1
- package/dist/react-three-fiber.cjs.dev.js +265 -268
- package/dist/react-three-fiber.cjs.prod.js +265 -268
- package/dist/react-three-fiber.esm.js +266 -269
- package/package.json +1 -1
- package/dist/declarations/src/core/is.d.ts +0 -9
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import * as THREE from 'three';
|
|
2
2
|
import * as React from 'react';
|
|
3
|
-
import { DefaultEventPriority, ConcurrentRoot } from 'react-reconciler/constants';
|
|
3
|
+
import { DefaultEventPriority, IdleEventPriority, ContinuousEventPriority, DiscreteEventPriority, ConcurrentRoot } from 'react-reconciler/constants';
|
|
4
4
|
import create from 'zustand';
|
|
5
5
|
import shallow from 'zustand/shallow';
|
|
6
6
|
import Reconciler from 'react-reconciler';
|
|
7
|
-
import { unstable_now, unstable_runWithPriority, unstable_IdlePriority } from 'scheduler';
|
|
8
7
|
import { useAsset } from 'use-asset';
|
|
9
8
|
import mergeRefs from 'react-merge-refs';
|
|
10
9
|
import useMeasure from 'react-use-measure';
|
|
@@ -13,6 +12,9 @@ var threeTypes = /*#__PURE__*/Object.freeze({
|
|
|
13
12
|
__proto__: null
|
|
14
13
|
});
|
|
15
14
|
|
|
15
|
+
const DEFAULT = '__default';
|
|
16
|
+
const isDiffSet = def => def && !!def.memoized && !!def.changes;
|
|
17
|
+
// A collection of compare functions
|
|
16
18
|
const is = {
|
|
17
19
|
obj: a => a === Object(a) && !is.arr(a) && typeof a !== 'function',
|
|
18
20
|
fun: a => typeof a === 'function',
|
|
@@ -38,7 +40,178 @@ const is = {
|
|
|
38
40
|
return is.und(i) ? a === b : true;
|
|
39
41
|
}
|
|
40
42
|
|
|
41
|
-
};
|
|
43
|
+
}; // Each object in the scene carries a small LocalState descriptor
|
|
44
|
+
|
|
45
|
+
function prepare(object, state) {
|
|
46
|
+
const instance = object;
|
|
47
|
+
|
|
48
|
+
if (state != null && state.primitive || !instance.__r3f) {
|
|
49
|
+
instance.__r3f = {
|
|
50
|
+
root: null,
|
|
51
|
+
memoizedProps: {},
|
|
52
|
+
handlers: {
|
|
53
|
+
count: 0
|
|
54
|
+
},
|
|
55
|
+
objects: [],
|
|
56
|
+
...state
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return object;
|
|
61
|
+
} // Shallow check arrays, but check objects atomically
|
|
62
|
+
|
|
63
|
+
function checkShallow(a, b) {
|
|
64
|
+
if (is.arr(a) && is.equ(a, b)) return true;
|
|
65
|
+
if (a === b) return true;
|
|
66
|
+
return false;
|
|
67
|
+
} // This function prepares a set of changes to be applied to the instance
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
function diffProps(instance, {
|
|
71
|
+
children: cN,
|
|
72
|
+
key: kN,
|
|
73
|
+
ref: rN,
|
|
74
|
+
...props
|
|
75
|
+
}, {
|
|
76
|
+
children: cP,
|
|
77
|
+
key: kP,
|
|
78
|
+
ref: rP,
|
|
79
|
+
...previous
|
|
80
|
+
} = {}, remove = false) {
|
|
81
|
+
var _instance$__r3f;
|
|
82
|
+
|
|
83
|
+
const localState = (_instance$__r3f = instance == null ? void 0 : instance.__r3f) != null ? _instance$__r3f : {};
|
|
84
|
+
const entries = Object.entries(props);
|
|
85
|
+
const changes = []; // Catch removed props, prepend them so they can be reset or removed
|
|
86
|
+
|
|
87
|
+
if (remove) {
|
|
88
|
+
const previousKeys = Object.keys(previous);
|
|
89
|
+
|
|
90
|
+
for (let i = 0; i < previousKeys.length; i++) if (!props.hasOwnProperty(previousKeys[i])) entries.unshift([previousKeys[i], DEFAULT + 'remove']);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
entries.forEach(([key, value]) => {
|
|
94
|
+
var _instance$__r3f2;
|
|
95
|
+
|
|
96
|
+
// Bail out on primitive object
|
|
97
|
+
if ((_instance$__r3f2 = instance.__r3f) != null && _instance$__r3f2.primitive && key === 'object') return; // When props match bail out
|
|
98
|
+
|
|
99
|
+
if (checkShallow(value, previous[key])) return;
|
|
100
|
+
let currentInstance = instance;
|
|
101
|
+
let targetProp = currentInstance[key]; // Collect handlers and bail out
|
|
102
|
+
|
|
103
|
+
if (/^on(Pointer|Click|DoubleClick|ContextMenu|Wheel)/.test(key)) return changes.push([key, value, true, currentInstance, targetProp]); // Revolve dashed props
|
|
104
|
+
|
|
105
|
+
if (key.includes('-')) {
|
|
106
|
+
const entries = key.split('-');
|
|
107
|
+
targetProp = entries.reduce((acc, key) => acc[key], instance); // If the target is atomic, it forces us to switch the root
|
|
108
|
+
|
|
109
|
+
if (!(targetProp && targetProp.set)) {
|
|
110
|
+
const [name, ...reverseEntries] = entries.reverse();
|
|
111
|
+
currentInstance = reverseEntries.reverse().reduce((acc, key) => acc[key], instance);
|
|
112
|
+
key = name;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
changes.push([key, value, false, currentInstance, targetProp]);
|
|
117
|
+
});
|
|
118
|
+
const memoized = { ...props
|
|
119
|
+
};
|
|
120
|
+
if (localState.memoizedProps && localState.memoizedProps.args) memoized.args = localState.memoizedProps.args;
|
|
121
|
+
if (localState.memoizedProps && localState.memoizedProps.attach) memoized.attach = localState.memoizedProps.attach;
|
|
122
|
+
return {
|
|
123
|
+
memoized,
|
|
124
|
+
changes
|
|
125
|
+
};
|
|
126
|
+
} // This function applies a set of changes to the instance
|
|
127
|
+
|
|
128
|
+
function applyProps$1(instance, data) {
|
|
129
|
+
var _instance$__r3f3, _root$getState, _localState$handlers, _localState$handlers2;
|
|
130
|
+
|
|
131
|
+
// Filter equals, events and reserved props
|
|
132
|
+
const localState = (_instance$__r3f3 = instance == null ? void 0 : instance.__r3f) != null ? _instance$__r3f3 : {};
|
|
133
|
+
const root = localState.root;
|
|
134
|
+
const rootState = (_root$getState = root == null ? void 0 : root.getState == null ? void 0 : root.getState()) != null ? _root$getState : {};
|
|
135
|
+
const {
|
|
136
|
+
memoized,
|
|
137
|
+
changes
|
|
138
|
+
} = isDiffSet(data) ? data : diffProps(instance, data);
|
|
139
|
+
const prevHandlers = (_localState$handlers = localState.handlers) == null ? void 0 : _localState$handlers.count; // Prepare memoized props
|
|
140
|
+
|
|
141
|
+
if (instance.__r3f) instance.__r3f.memoizedProps = memoized;
|
|
142
|
+
changes.forEach(([key, value, isEvent, currentInstance, targetProp]) => {
|
|
143
|
+
// https://github.com/mrdoob/three.js/issues/21209
|
|
144
|
+
// HMR/fast-refresh relies on the ability to cancel out props, but threejs
|
|
145
|
+
// has no means to do this. Hence we curate a small collection of value-classes
|
|
146
|
+
// with their respective constructor/set arguments
|
|
147
|
+
// For removed props, try to set default values, if possible
|
|
148
|
+
if (value === DEFAULT + 'remove') {
|
|
149
|
+
if (targetProp && targetProp.constructor) {
|
|
150
|
+
// use the prop constructor to find the default it should be
|
|
151
|
+
value = new targetProp.constructor(memoized.args);
|
|
152
|
+
} else if (currentInstance.constructor) {
|
|
153
|
+
// create a blank slate of the instance and copy the particular parameter.
|
|
154
|
+
// @ts-ignore
|
|
155
|
+
const defaultClassCall = new currentInstance.constructor(currentInstance.__r3f.memoizedProps.args);
|
|
156
|
+
value = defaultClassCall[targetProp]; // destory the instance
|
|
157
|
+
|
|
158
|
+
if (defaultClassCall.dispose) defaultClassCall.dispose(); // instance does not have constructor, just set it to 0
|
|
159
|
+
} else value = 0;
|
|
160
|
+
} // Deal with pointer events ...
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
if (isEvent) {
|
|
164
|
+
if (value) localState.handlers[key] = value;else delete localState.handlers[key];
|
|
165
|
+
localState.handlers.count = Object.keys(localState.handlers).length;
|
|
166
|
+
} // Special treatment for objects with support for set/copy, and layers
|
|
167
|
+
else if (targetProp && targetProp.set && (targetProp.copy || targetProp instanceof THREE.Layers)) {
|
|
168
|
+
// If value is an array
|
|
169
|
+
if (Array.isArray(value)) {
|
|
170
|
+
if (targetProp.fromArray) targetProp.fromArray(value);else targetProp.set(...value);
|
|
171
|
+
} // Test again target.copy(class) next ...
|
|
172
|
+
else if (targetProp.copy && value && value.constructor && targetProp.constructor.name === value.constructor.name) targetProp.copy(value); // If nothing else fits, just set the single value, ignore undefined
|
|
173
|
+
// https://github.com/react-spring/react-three-fiber/issues/274
|
|
174
|
+
else if (value !== undefined) {
|
|
175
|
+
const isColor = targetProp instanceof THREE.Color; // Allow setting array scalars
|
|
176
|
+
|
|
177
|
+
if (!isColor && targetProp.setScalar) targetProp.setScalar(value); // Layers have no copy function, we must therefore copy the mask property
|
|
178
|
+
else if (targetProp instanceof THREE.Layers && value instanceof THREE.Layers) targetProp.mask = value.mask; // Otherwise just set ...
|
|
179
|
+
else targetProp.set(value); // Auto-convert sRGB colors, for now ...
|
|
180
|
+
// https://github.com/react-spring/react-three-fiber/issues/344
|
|
181
|
+
|
|
182
|
+
if (!rootState.linear && isColor) targetProp.convertSRGBToLinear();
|
|
183
|
+
} // Else, just overwrite the value
|
|
184
|
+
|
|
185
|
+
} else {
|
|
186
|
+
currentInstance[key] = value; // Auto-convert sRGB textures, for now ...
|
|
187
|
+
// https://github.com/react-spring/react-three-fiber/issues/344
|
|
188
|
+
|
|
189
|
+
if (!rootState.linear && currentInstance[key] instanceof THREE.Texture) currentInstance[key].encoding = THREE.sRGBEncoding;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
invalidateInstance(instance);
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
if (rootState.internal && instance.raycast && prevHandlers !== ((_localState$handlers2 = localState.handlers) == null ? void 0 : _localState$handlers2.count)) {
|
|
196
|
+
// Pre-emptively remove the instance from the interaction manager
|
|
197
|
+
const index = rootState.internal.interaction.indexOf(instance);
|
|
198
|
+
if (index > -1) rootState.internal.interaction.splice(index, 1); // Add the instance to the interaction manager only when it has handlers
|
|
199
|
+
|
|
200
|
+
if (localState.handlers.count) rootState.internal.interaction.push(instance);
|
|
201
|
+
} // Call the update lifecycle when it is being updated, but only when it is part of the scene
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
if (changes.length && instance.parent) updateInstance(instance);
|
|
205
|
+
}
|
|
206
|
+
function invalidateInstance(instance) {
|
|
207
|
+
var _instance$__r3f4, _instance$__r3f4$root;
|
|
208
|
+
|
|
209
|
+
const state = (_instance$__r3f4 = instance.__r3f) == null ? void 0 : (_instance$__r3f4$root = _instance$__r3f4.root) == null ? void 0 : _instance$__r3f4$root.getState == null ? void 0 : _instance$__r3f4$root.getState();
|
|
210
|
+
if (state && state.internal.frames === 0) state.invalidate();
|
|
211
|
+
}
|
|
212
|
+
function updateInstance(instance) {
|
|
213
|
+
instance.onUpdate == null ? void 0 : instance.onUpdate(instance);
|
|
214
|
+
}
|
|
42
215
|
|
|
43
216
|
function makeId(event) {
|
|
44
217
|
return (event.eventObject || event.object).uuid + '/' + event.index + event.instanceId;
|
|
@@ -385,8 +558,6 @@ function createEvents(store) {
|
|
|
385
558
|
};
|
|
386
559
|
}
|
|
387
560
|
|
|
388
|
-
const isDiffSet = def => def && !!def.memoized && !!def.changes;
|
|
389
|
-
|
|
390
561
|
// Type guard to tell a store from a portal
|
|
391
562
|
const isStore = def => def && !!def.getState;
|
|
392
563
|
|
|
@@ -404,191 +575,13 @@ const getContainer = (container, child) => {
|
|
|
404
575
|
};
|
|
405
576
|
};
|
|
406
577
|
|
|
407
|
-
const DEFAULT = '__default';
|
|
408
|
-
const EMPTY = {};
|
|
409
578
|
let catalogue = {};
|
|
410
579
|
|
|
411
580
|
let extend = objects => void (catalogue = { ...catalogue,
|
|
412
581
|
...objects
|
|
413
|
-
});
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
function checkShallow(a, b) {
|
|
417
|
-
if (is.arr(a) && is.equ(a, b)) return true;
|
|
418
|
-
if (a === b) return true;
|
|
419
|
-
return false;
|
|
420
|
-
} // Each object in the scene carries a small LocalState descriptor
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
function prepare(object, state) {
|
|
424
|
-
const instance = object;
|
|
425
|
-
|
|
426
|
-
if (state != null && state.primitive || !instance.__r3f) {
|
|
427
|
-
instance.__r3f = {
|
|
428
|
-
root: null,
|
|
429
|
-
memoizedProps: {},
|
|
430
|
-
handlers: {
|
|
431
|
-
count: 0
|
|
432
|
-
},
|
|
433
|
-
objects: [],
|
|
434
|
-
...state
|
|
435
|
-
};
|
|
436
|
-
}
|
|
437
|
-
|
|
438
|
-
return object;
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
function createRenderer(roots) {
|
|
442
|
-
// This function prepares a set of changes to be applied to the instance
|
|
443
|
-
function diffProps(instance, {
|
|
444
|
-
children: cN,
|
|
445
|
-
key: kN,
|
|
446
|
-
ref: rN,
|
|
447
|
-
...props
|
|
448
|
-
}, {
|
|
449
|
-
children: cP,
|
|
450
|
-
key: kP,
|
|
451
|
-
ref: rP,
|
|
452
|
-
...previous
|
|
453
|
-
} = {}, accumulative = false) {
|
|
454
|
-
var _instance$__r3f;
|
|
455
|
-
|
|
456
|
-
const localState = (_instance$__r3f = instance == null ? void 0 : instance.__r3f) != null ? _instance$__r3f : {};
|
|
457
|
-
const entries = Object.entries(props);
|
|
458
|
-
const changes = []; // Catch removed props, prepend them so they can be reset or removed
|
|
459
|
-
|
|
460
|
-
if (accumulative) {
|
|
461
|
-
const previousKeys = Object.keys(previous);
|
|
462
|
-
|
|
463
|
-
for (let i = 0; i < previousKeys.length; i++) if (!props.hasOwnProperty(previousKeys[i])) entries.unshift([previousKeys[i], DEFAULT + 'remove']);
|
|
464
|
-
}
|
|
465
|
-
|
|
466
|
-
entries.forEach(([key, value]) => {
|
|
467
|
-
var _instance$__r3f2;
|
|
468
|
-
|
|
469
|
-
// Bail out on primitive object
|
|
470
|
-
if ((_instance$__r3f2 = instance.__r3f) != null && _instance$__r3f2.primitive && key === 'object') return; // When props match bail out
|
|
471
|
-
|
|
472
|
-
if (checkShallow(value, previous[key])) return;
|
|
473
|
-
let currentInstance = instance;
|
|
474
|
-
let targetProp = currentInstance[key]; // Collect handlers and bail out
|
|
475
|
-
|
|
476
|
-
if (/^on(Pointer|Click|DoubleClick|ContextMenu|Wheel)/.test(key)) return changes.push([key, value, true, currentInstance, targetProp]); // Revolve dashed props
|
|
477
|
-
|
|
478
|
-
if (key.includes('-')) {
|
|
479
|
-
const entries = key.split('-');
|
|
480
|
-
targetProp = entries.reduce((acc, key) => acc[key], instance); // If the target is atomic, it forces us to switch the root
|
|
481
|
-
|
|
482
|
-
if (!(targetProp && targetProp.set)) {
|
|
483
|
-
const [name, ...reverseEntries] = entries.reverse();
|
|
484
|
-
currentInstance = reverseEntries.reverse().reduce((acc, key) => acc[key], instance);
|
|
485
|
-
key = name;
|
|
486
|
-
}
|
|
487
|
-
}
|
|
488
|
-
|
|
489
|
-
changes.push([key, value, false, currentInstance, targetProp]);
|
|
490
|
-
});
|
|
491
|
-
const memoized = { ...props
|
|
492
|
-
};
|
|
493
|
-
if (localState.memoizedProps && localState.memoizedProps.args) memoized.args = localState.memoizedProps.args;
|
|
494
|
-
if (localState.memoizedProps && localState.memoizedProps.attach) memoized.attach = localState.memoizedProps.attach;
|
|
495
|
-
return {
|
|
496
|
-
accumulative,
|
|
497
|
-
memoized,
|
|
498
|
-
changes
|
|
499
|
-
};
|
|
500
|
-
}
|
|
501
|
-
|
|
502
|
-
function applyProps(instance, data) {
|
|
503
|
-
var _instance$__r3f3, _root$getState, _localState$handlers, _localState$handlers2;
|
|
504
|
-
|
|
505
|
-
// Filter equals, events and reserved props
|
|
506
|
-
const localState = (_instance$__r3f3 = instance == null ? void 0 : instance.__r3f) != null ? _instance$__r3f3 : {};
|
|
507
|
-
const root = localState.root;
|
|
508
|
-
const rootState = (_root$getState = root == null ? void 0 : root.getState == null ? void 0 : root.getState()) != null ? _root$getState : {};
|
|
509
|
-
const {
|
|
510
|
-
memoized,
|
|
511
|
-
changes
|
|
512
|
-
} = isDiffSet(data) ? data : diffProps(instance, data);
|
|
513
|
-
const prevHandlers = (_localState$handlers = localState.handlers) == null ? void 0 : _localState$handlers.count; // Prepare memoized props
|
|
514
|
-
|
|
515
|
-
if (instance.__r3f) instance.__r3f.memoizedProps = memoized;
|
|
516
|
-
changes.forEach(([key, value, isEvent, currentInstance, targetProp]) => {
|
|
517
|
-
// https://github.com/mrdoob/three.js/issues/21209
|
|
518
|
-
// HMR/fast-refresh relies on the ability to cancel out props, but threejs
|
|
519
|
-
// has no means to do this. Hence we curate a small collection of value-classes
|
|
520
|
-
// with their respective constructor/set arguments
|
|
521
|
-
// For removed props, try to set default values, if possible
|
|
522
|
-
if (value === DEFAULT + 'remove') {
|
|
523
|
-
if (targetProp && targetProp.constructor) {
|
|
524
|
-
// use the prop constructor to find the default it should be
|
|
525
|
-
value = new targetProp.constructor(memoized.args);
|
|
526
|
-
} else if (currentInstance.constructor) {
|
|
527
|
-
// create a blank slate of the instance and copy the particular parameter.
|
|
528
|
-
// @ts-ignore
|
|
529
|
-
const defaultClassCall = new currentInstance.constructor(currentInstance.__r3f.memoizedProps.args);
|
|
530
|
-
value = defaultClassCall[targetProp]; // destory the instance
|
|
531
|
-
|
|
532
|
-
if (defaultClassCall.dispose) defaultClassCall.dispose(); // instance does not have constructor, just set it to 0
|
|
533
|
-
} else value = 0;
|
|
534
|
-
} // Deal with pointer events ...
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
if (isEvent) {
|
|
538
|
-
if (value) localState.handlers[key] = value;else delete localState.handlers[key];
|
|
539
|
-
localState.handlers.count = Object.keys(localState.handlers).length;
|
|
540
|
-
} // Special treatment for objects with support for set/copy, and layers
|
|
541
|
-
else if (targetProp && targetProp.set && (targetProp.copy || targetProp instanceof THREE.Layers)) {
|
|
542
|
-
// If value is an array
|
|
543
|
-
if (Array.isArray(value)) {
|
|
544
|
-
if (targetProp.fromArray) targetProp.fromArray(value);else targetProp.set(...value);
|
|
545
|
-
} // Test again target.copy(class) next ...
|
|
546
|
-
else if (targetProp.copy && value && value.constructor && targetProp.constructor.name === value.constructor.name) targetProp.copy(value); // If nothing else fits, just set the single value, ignore undefined
|
|
547
|
-
// https://github.com/react-spring/react-three-fiber/issues/274
|
|
548
|
-
else if (value !== undefined) {
|
|
549
|
-
const isColor = targetProp instanceof THREE.Color; // Allow setting array scalars
|
|
550
|
-
|
|
551
|
-
if (!isColor && targetProp.setScalar) targetProp.setScalar(value); // Layers have no copy function, we must therefore copy the mask property
|
|
552
|
-
else if (targetProp instanceof THREE.Layers && value instanceof THREE.Layers) targetProp.mask = value.mask; // Otherwise just set ...
|
|
553
|
-
else targetProp.set(value); // Auto-convert sRGB colors, for now ...
|
|
554
|
-
// https://github.com/react-spring/react-three-fiber/issues/344
|
|
555
|
-
|
|
556
|
-
if (!rootState.linear && isColor) targetProp.convertSRGBToLinear();
|
|
557
|
-
} // Else, just overwrite the value
|
|
558
|
-
|
|
559
|
-
} else {
|
|
560
|
-
currentInstance[key] = value; // Auto-convert sRGB textures, for now ...
|
|
561
|
-
// https://github.com/react-spring/react-three-fiber/issues/344
|
|
562
|
-
|
|
563
|
-
if (!rootState.linear && currentInstance[key] instanceof THREE.Texture) currentInstance[key].encoding = THREE.sRGBEncoding;
|
|
564
|
-
}
|
|
565
|
-
|
|
566
|
-
invalidateInstance(instance);
|
|
567
|
-
});
|
|
568
|
-
|
|
569
|
-
if (rootState.internal && instance.raycast && prevHandlers !== ((_localState$handlers2 = localState.handlers) == null ? void 0 : _localState$handlers2.count)) {
|
|
570
|
-
// Pre-emptively remove the instance from the interaction manager
|
|
571
|
-
const index = rootState.internal.interaction.indexOf(instance);
|
|
572
|
-
if (index > -1) rootState.internal.interaction.splice(index, 1); // Add the instance to the interaction manager only when it has handlers
|
|
573
|
-
|
|
574
|
-
if (localState.handlers.count) rootState.internal.interaction.push(instance);
|
|
575
|
-
} // Call the update lifecycle when it is being updated, but only when it is part of the scene
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
if (changes.length && instance.parent) updateInstance(instance);
|
|
579
|
-
}
|
|
580
|
-
|
|
581
|
-
function invalidateInstance(instance) {
|
|
582
|
-
var _instance$__r3f4, _instance$__r3f4$root;
|
|
583
|
-
|
|
584
|
-
const state = (_instance$__r3f4 = instance.__r3f) == null ? void 0 : (_instance$__r3f4$root = _instance$__r3f4.root) == null ? void 0 : _instance$__r3f4$root.getState == null ? void 0 : _instance$__r3f4$root.getState();
|
|
585
|
-
if (state && state.internal.frames === 0) state.invalidate();
|
|
586
|
-
}
|
|
587
|
-
|
|
588
|
-
function updateInstance(instance) {
|
|
589
|
-
instance.onUpdate == null ? void 0 : instance.onUpdate(instance);
|
|
590
|
-
}
|
|
582
|
+
});
|
|
591
583
|
|
|
584
|
+
function createRenderer(roots, getEventPriority) {
|
|
592
585
|
function createInstance(type, {
|
|
593
586
|
args = [],
|
|
594
587
|
...props
|
|
@@ -648,7 +641,7 @@ function createRenderer(roots) {
|
|
|
648
641
|
// why it passes "true" here
|
|
649
642
|
|
|
650
643
|
|
|
651
|
-
applyProps(instance, props);
|
|
644
|
+
applyProps$1(instance, props);
|
|
652
645
|
return instance;
|
|
653
646
|
}
|
|
654
647
|
|
|
@@ -800,7 +793,7 @@ function createRenderer(roots) {
|
|
|
800
793
|
|
|
801
794
|
|
|
802
795
|
if (shouldDispose && child.dispose && child.type !== 'Scene') {
|
|
803
|
-
|
|
796
|
+
reconciler.runWithPriority(IdleEventPriority, () => {
|
|
804
797
|
try {
|
|
805
798
|
child.dispose();
|
|
806
799
|
} catch (e) {
|
|
@@ -845,25 +838,6 @@ function createRenderer(roots) {
|
|
|
845
838
|
}
|
|
846
839
|
|
|
847
840
|
const reconciler = Reconciler({
|
|
848
|
-
now: unstable_now,
|
|
849
|
-
createInstance,
|
|
850
|
-
removeChild,
|
|
851
|
-
appendChild,
|
|
852
|
-
appendInitialChild: appendChild,
|
|
853
|
-
insertBefore,
|
|
854
|
-
warnsIfNotActing: true,
|
|
855
|
-
supportsMutation: true,
|
|
856
|
-
isPrimaryRenderer: false,
|
|
857
|
-
getCurrentEventPriority: () => DefaultEventPriority,
|
|
858
|
-
// @ts-ignore
|
|
859
|
-
scheduleTimeout: is.fun(setTimeout) ? setTimeout : undefined,
|
|
860
|
-
// @ts-ignore
|
|
861
|
-
cancelTimeout: is.fun(clearTimeout) ? clearTimeout : undefined,
|
|
862
|
-
// @ts-ignore
|
|
863
|
-
setTimeout: is.fun(setTimeout) ? setTimeout : undefined,
|
|
864
|
-
// @ts-ignore
|
|
865
|
-
clearTimeout: is.fun(clearTimeout) ? clearTimeout : undefined,
|
|
866
|
-
noTimeout: -1,
|
|
867
841
|
appendChildToContainer: (parentInstance, child) => {
|
|
868
842
|
const {
|
|
869
843
|
container,
|
|
@@ -900,10 +874,9 @@ function createRenderer(roots) {
|
|
|
900
874
|
},
|
|
901
875
|
|
|
902
876
|
commitUpdate(instance, [reconstruct, diff], type, oldProps, newProps, fiber) {
|
|
903
|
-
//console.log(type)
|
|
904
877
|
// Reconstruct when args or <primitive object={...} have changes
|
|
905
878
|
if (reconstruct) switchInstance(instance, type, newProps, fiber); // Otherwise just overwrite props
|
|
906
|
-
else applyProps(instance, diff);
|
|
879
|
+
else applyProps$1(instance, diff);
|
|
907
880
|
},
|
|
908
881
|
|
|
909
882
|
hideInstance(instance) {
|
|
@@ -920,62 +893,45 @@ function createRenderer(roots) {
|
|
|
920
893
|
}
|
|
921
894
|
},
|
|
922
895
|
|
|
923
|
-
|
|
896
|
+
createInstance,
|
|
897
|
+
removeChild,
|
|
898
|
+
appendChild,
|
|
899
|
+
appendInitialChild: appendChild,
|
|
900
|
+
insertBefore,
|
|
901
|
+
warnsIfNotActing: true,
|
|
902
|
+
supportsMutation: true,
|
|
903
|
+
isPrimaryRenderer: false,
|
|
904
|
+
getCurrentEventPriority: () => getEventPriority ? getEventPriority() : DefaultEventPriority,
|
|
905
|
+
// @ts-ignore
|
|
906
|
+
now: is.fun(performance.now) ? performance.now : is.fun(Date.now) ? Date.now : undefined,
|
|
907
|
+
// @ts-ignore
|
|
908
|
+
scheduleTimeout: is.fun(setTimeout) ? setTimeout : undefined,
|
|
909
|
+
// @ts-ignore
|
|
910
|
+
cancelTimeout: is.fun(clearTimeout) ? clearTimeout : undefined,
|
|
911
|
+
setTimeout: is.fun(setTimeout) ? setTimeout : undefined,
|
|
912
|
+
clearTimeout: is.fun(clearTimeout) ? clearTimeout : undefined,
|
|
913
|
+
noTimeout: -1,
|
|
914
|
+
hideTextInstance: () => {
|
|
924
915
|
throw new Error('Text is not allowed in the R3F tree.');
|
|
925
916
|
},
|
|
926
|
-
|
|
927
|
-
getPublicInstance
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
},
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
createTextInstance() {},
|
|
941
|
-
|
|
942
|
-
finalizeInitialChildren() {
|
|
943
|
-
return false;
|
|
944
|
-
},
|
|
945
|
-
|
|
946
|
-
commitMount() {// noop
|
|
947
|
-
},
|
|
948
|
-
|
|
949
|
-
shouldDeprioritizeSubtree() {
|
|
950
|
-
return false;
|
|
951
|
-
},
|
|
952
|
-
|
|
953
|
-
prepareForCommit() {
|
|
954
|
-
return null;
|
|
955
|
-
},
|
|
956
|
-
|
|
957
|
-
preparePortalMount(containerInfo) {
|
|
958
|
-
prepare(containerInfo);
|
|
959
|
-
},
|
|
960
|
-
|
|
961
|
-
resetAfterCommit() {// noop
|
|
962
|
-
},
|
|
963
|
-
|
|
964
|
-
shouldSetTextContent() {
|
|
965
|
-
return false;
|
|
966
|
-
},
|
|
967
|
-
|
|
968
|
-
clearContainer() {
|
|
969
|
-
return false;
|
|
970
|
-
},
|
|
971
|
-
|
|
972
|
-
detachDeletedInstance() {// noop
|
|
973
|
-
}
|
|
974
|
-
|
|
917
|
+
// prettier-ignore
|
|
918
|
+
getPublicInstance: instance => instance,
|
|
919
|
+
getRootHostContext: () => null,
|
|
920
|
+
getChildHostContext: parentHostContext => parentHostContext,
|
|
921
|
+
createTextInstance: () => {},
|
|
922
|
+
finalizeInitialChildren: () => false,
|
|
923
|
+
commitMount: () => {},
|
|
924
|
+
shouldDeprioritizeSubtree: () => false,
|
|
925
|
+
prepareForCommit: () => null,
|
|
926
|
+
preparePortalMount: containerInfo => prepare(containerInfo),
|
|
927
|
+
resetAfterCommit: () => {},
|
|
928
|
+
shouldSetTextContent: () => false,
|
|
929
|
+
clearContainer: () => false,
|
|
930
|
+
detachDeletedInstance: () => {}
|
|
975
931
|
});
|
|
976
932
|
return {
|
|
977
933
|
reconciler,
|
|
978
|
-
applyProps
|
|
934
|
+
applyProps: applyProps$1
|
|
979
935
|
};
|
|
980
936
|
}
|
|
981
937
|
|
|
@@ -1326,20 +1282,61 @@ function createLoop(roots) {
|
|
|
1326
1282
|
};
|
|
1327
1283
|
}
|
|
1328
1284
|
|
|
1285
|
+
// @ts-ignore
|
|
1286
|
+
const CLICK = 'click';
|
|
1287
|
+
const CONTEXTMENU = 'contextmenu';
|
|
1288
|
+
const DBLCLICK = 'dblclick';
|
|
1289
|
+
const POINTERCANCEL = 'pointercancel';
|
|
1290
|
+
const POINTERDOWN = 'pointerdown';
|
|
1291
|
+
const POINTERUP = 'pointerup';
|
|
1292
|
+
const POINTERMOVE = 'pointermove';
|
|
1293
|
+
const POINTEROUT = 'pointerout';
|
|
1294
|
+
const POINTEROVER = 'pointerover';
|
|
1295
|
+
const POINTERENTER = 'pointerenter';
|
|
1296
|
+
const POINTERLEAVE = 'pointerleave';
|
|
1297
|
+
const WHEEL = 'wheel'; // https://github.com/facebook/react/tree/main/packages/react-reconciler#getcurrenteventpriority
|
|
1298
|
+
// Gives React a clue as to how import the current interaction is
|
|
1299
|
+
|
|
1300
|
+
function getEventPriority() {
|
|
1301
|
+
var _window, _window$event;
|
|
1302
|
+
|
|
1303
|
+
let name = (_window = window) == null ? void 0 : (_window$event = _window.event) == null ? void 0 : _window$event.type;
|
|
1304
|
+
|
|
1305
|
+
switch (name) {
|
|
1306
|
+
case CLICK:
|
|
1307
|
+
case CONTEXTMENU:
|
|
1308
|
+
case DBLCLICK:
|
|
1309
|
+
case POINTERCANCEL:
|
|
1310
|
+
case POINTERDOWN:
|
|
1311
|
+
case POINTERUP:
|
|
1312
|
+
return DiscreteEventPriority;
|
|
1313
|
+
|
|
1314
|
+
case POINTERMOVE:
|
|
1315
|
+
case POINTEROUT:
|
|
1316
|
+
case POINTEROVER:
|
|
1317
|
+
case POINTERENTER:
|
|
1318
|
+
case POINTERLEAVE:
|
|
1319
|
+
case WHEEL:
|
|
1320
|
+
return ContinuousEventPriority;
|
|
1321
|
+
|
|
1322
|
+
default:
|
|
1323
|
+
return DefaultEventPriority;
|
|
1324
|
+
}
|
|
1325
|
+
}
|
|
1329
1326
|
function createPointerEvents(store) {
|
|
1330
1327
|
const {
|
|
1331
1328
|
handlePointer
|
|
1332
1329
|
} = createEvents(store);
|
|
1333
1330
|
const names = {
|
|
1334
|
-
onClick: [
|
|
1335
|
-
onContextMenu: [
|
|
1336
|
-
onDoubleClick: [
|
|
1337
|
-
onWheel: [
|
|
1338
|
-
onPointerDown: [
|
|
1339
|
-
onPointerUp: [
|
|
1340
|
-
onPointerLeave: [
|
|
1341
|
-
onPointerMove: [
|
|
1342
|
-
onPointerCancel: [
|
|
1331
|
+
onClick: [CLICK, false],
|
|
1332
|
+
onContextMenu: [CONTEXTMENU, false],
|
|
1333
|
+
onDoubleClick: [DBLCLICK, false],
|
|
1334
|
+
onWheel: [WHEEL, true],
|
|
1335
|
+
onPointerDown: [POINTERDOWN, true],
|
|
1336
|
+
onPointerUp: [POINTERUP, true],
|
|
1337
|
+
onPointerLeave: [POINTERLEAVE, true],
|
|
1338
|
+
onPointerMove: [POINTERMOVE, true],
|
|
1339
|
+
onPointerCancel: [POINTERCANCEL, true],
|
|
1343
1340
|
onLostPointerCapture: ['lostpointercapture', true]
|
|
1344
1341
|
};
|
|
1345
1342
|
return {
|
|
@@ -1576,7 +1573,7 @@ const {
|
|
|
1576
1573
|
const {
|
|
1577
1574
|
reconciler,
|
|
1578
1575
|
applyProps
|
|
1579
|
-
} = createRenderer();
|
|
1576
|
+
} = createRenderer(roots, getEventPriority);
|
|
1580
1577
|
|
|
1581
1578
|
const createRendererInstance = (gl, canvas) => isRenderer(gl) ? gl : new THREE.WebGLRenderer({
|
|
1582
1579
|
powerPreference: 'high-performance',
|
package/package.json
CHANGED