@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
|
@@ -8,7 +8,6 @@ var constants = require('react-reconciler/constants');
|
|
|
8
8
|
var create = require('zustand');
|
|
9
9
|
var shallow = require('zustand/shallow');
|
|
10
10
|
var Reconciler = require('react-reconciler');
|
|
11
|
-
var scheduler = require('scheduler');
|
|
12
11
|
var useAsset = require('use-asset');
|
|
13
12
|
var mergeRefs = require('react-merge-refs');
|
|
14
13
|
var useMeasure = require('react-use-measure');
|
|
@@ -47,6 +46,9 @@ var threeTypes = /*#__PURE__*/Object.freeze({
|
|
|
47
46
|
__proto__: null
|
|
48
47
|
});
|
|
49
48
|
|
|
49
|
+
const DEFAULT = '__default';
|
|
50
|
+
const isDiffSet = def => def && !!def.memoized && !!def.changes;
|
|
51
|
+
// A collection of compare functions
|
|
50
52
|
const is = {
|
|
51
53
|
obj: a => a === Object(a) && !is.arr(a) && typeof a !== 'function',
|
|
52
54
|
fun: a => typeof a === 'function',
|
|
@@ -72,7 +74,178 @@ const is = {
|
|
|
72
74
|
return is.und(i) ? a === b : true;
|
|
73
75
|
}
|
|
74
76
|
|
|
75
|
-
};
|
|
77
|
+
}; // Each object in the scene carries a small LocalState descriptor
|
|
78
|
+
|
|
79
|
+
function prepare(object, state) {
|
|
80
|
+
const instance = object;
|
|
81
|
+
|
|
82
|
+
if (state != null && state.primitive || !instance.__r3f) {
|
|
83
|
+
instance.__r3f = {
|
|
84
|
+
root: null,
|
|
85
|
+
memoizedProps: {},
|
|
86
|
+
handlers: {
|
|
87
|
+
count: 0
|
|
88
|
+
},
|
|
89
|
+
objects: [],
|
|
90
|
+
...state
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return object;
|
|
95
|
+
} // Shallow check arrays, but check objects atomically
|
|
96
|
+
|
|
97
|
+
function checkShallow(a, b) {
|
|
98
|
+
if (is.arr(a) && is.equ(a, b)) return true;
|
|
99
|
+
if (a === b) return true;
|
|
100
|
+
return false;
|
|
101
|
+
} // This function prepares a set of changes to be applied to the instance
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
function diffProps(instance, {
|
|
105
|
+
children: cN,
|
|
106
|
+
key: kN,
|
|
107
|
+
ref: rN,
|
|
108
|
+
...props
|
|
109
|
+
}, {
|
|
110
|
+
children: cP,
|
|
111
|
+
key: kP,
|
|
112
|
+
ref: rP,
|
|
113
|
+
...previous
|
|
114
|
+
} = {}, remove = false) {
|
|
115
|
+
var _instance$__r3f;
|
|
116
|
+
|
|
117
|
+
const localState = (_instance$__r3f = instance == null ? void 0 : instance.__r3f) != null ? _instance$__r3f : {};
|
|
118
|
+
const entries = Object.entries(props);
|
|
119
|
+
const changes = []; // Catch removed props, prepend them so they can be reset or removed
|
|
120
|
+
|
|
121
|
+
if (remove) {
|
|
122
|
+
const previousKeys = Object.keys(previous);
|
|
123
|
+
|
|
124
|
+
for (let i = 0; i < previousKeys.length; i++) if (!props.hasOwnProperty(previousKeys[i])) entries.unshift([previousKeys[i], DEFAULT + 'remove']);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
entries.forEach(([key, value]) => {
|
|
128
|
+
var _instance$__r3f2;
|
|
129
|
+
|
|
130
|
+
// Bail out on primitive object
|
|
131
|
+
if ((_instance$__r3f2 = instance.__r3f) != null && _instance$__r3f2.primitive && key === 'object') return; // When props match bail out
|
|
132
|
+
|
|
133
|
+
if (checkShallow(value, previous[key])) return;
|
|
134
|
+
let currentInstance = instance;
|
|
135
|
+
let targetProp = currentInstance[key]; // Collect handlers and bail out
|
|
136
|
+
|
|
137
|
+
if (/^on(Pointer|Click|DoubleClick|ContextMenu|Wheel)/.test(key)) return changes.push([key, value, true, currentInstance, targetProp]); // Revolve dashed props
|
|
138
|
+
|
|
139
|
+
if (key.includes('-')) {
|
|
140
|
+
const entries = key.split('-');
|
|
141
|
+
targetProp = entries.reduce((acc, key) => acc[key], instance); // If the target is atomic, it forces us to switch the root
|
|
142
|
+
|
|
143
|
+
if (!(targetProp && targetProp.set)) {
|
|
144
|
+
const [name, ...reverseEntries] = entries.reverse();
|
|
145
|
+
currentInstance = reverseEntries.reverse().reduce((acc, key) => acc[key], instance);
|
|
146
|
+
key = name;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
changes.push([key, value, false, currentInstance, targetProp]);
|
|
151
|
+
});
|
|
152
|
+
const memoized = { ...props
|
|
153
|
+
};
|
|
154
|
+
if (localState.memoizedProps && localState.memoizedProps.args) memoized.args = localState.memoizedProps.args;
|
|
155
|
+
if (localState.memoizedProps && localState.memoizedProps.attach) memoized.attach = localState.memoizedProps.attach;
|
|
156
|
+
return {
|
|
157
|
+
memoized,
|
|
158
|
+
changes
|
|
159
|
+
};
|
|
160
|
+
} // This function applies a set of changes to the instance
|
|
161
|
+
|
|
162
|
+
function applyProps$1(instance, data) {
|
|
163
|
+
var _instance$__r3f3, _root$getState, _localState$handlers, _localState$handlers2;
|
|
164
|
+
|
|
165
|
+
// Filter equals, events and reserved props
|
|
166
|
+
const localState = (_instance$__r3f3 = instance == null ? void 0 : instance.__r3f) != null ? _instance$__r3f3 : {};
|
|
167
|
+
const root = localState.root;
|
|
168
|
+
const rootState = (_root$getState = root == null ? void 0 : root.getState == null ? void 0 : root.getState()) != null ? _root$getState : {};
|
|
169
|
+
const {
|
|
170
|
+
memoized,
|
|
171
|
+
changes
|
|
172
|
+
} = isDiffSet(data) ? data : diffProps(instance, data);
|
|
173
|
+
const prevHandlers = (_localState$handlers = localState.handlers) == null ? void 0 : _localState$handlers.count; // Prepare memoized props
|
|
174
|
+
|
|
175
|
+
if (instance.__r3f) instance.__r3f.memoizedProps = memoized;
|
|
176
|
+
changes.forEach(([key, value, isEvent, currentInstance, targetProp]) => {
|
|
177
|
+
// https://github.com/mrdoob/three.js/issues/21209
|
|
178
|
+
// HMR/fast-refresh relies on the ability to cancel out props, but threejs
|
|
179
|
+
// has no means to do this. Hence we curate a small collection of value-classes
|
|
180
|
+
// with their respective constructor/set arguments
|
|
181
|
+
// For removed props, try to set default values, if possible
|
|
182
|
+
if (value === DEFAULT + 'remove') {
|
|
183
|
+
if (targetProp && targetProp.constructor) {
|
|
184
|
+
// use the prop constructor to find the default it should be
|
|
185
|
+
value = new targetProp.constructor(memoized.args);
|
|
186
|
+
} else if (currentInstance.constructor) {
|
|
187
|
+
// create a blank slate of the instance and copy the particular parameter.
|
|
188
|
+
// @ts-ignore
|
|
189
|
+
const defaultClassCall = new currentInstance.constructor(currentInstance.__r3f.memoizedProps.args);
|
|
190
|
+
value = defaultClassCall[targetProp]; // destory the instance
|
|
191
|
+
|
|
192
|
+
if (defaultClassCall.dispose) defaultClassCall.dispose(); // instance does not have constructor, just set it to 0
|
|
193
|
+
} else value = 0;
|
|
194
|
+
} // Deal with pointer events ...
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
if (isEvent) {
|
|
198
|
+
if (value) localState.handlers[key] = value;else delete localState.handlers[key];
|
|
199
|
+
localState.handlers.count = Object.keys(localState.handlers).length;
|
|
200
|
+
} // Special treatment for objects with support for set/copy, and layers
|
|
201
|
+
else if (targetProp && targetProp.set && (targetProp.copy || targetProp instanceof THREE__namespace.Layers)) {
|
|
202
|
+
// If value is an array
|
|
203
|
+
if (Array.isArray(value)) {
|
|
204
|
+
if (targetProp.fromArray) targetProp.fromArray(value);else targetProp.set(...value);
|
|
205
|
+
} // Test again target.copy(class) next ...
|
|
206
|
+
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
|
|
207
|
+
// https://github.com/react-spring/react-three-fiber/issues/274
|
|
208
|
+
else if (value !== undefined) {
|
|
209
|
+
const isColor = targetProp instanceof THREE__namespace.Color; // Allow setting array scalars
|
|
210
|
+
|
|
211
|
+
if (!isColor && targetProp.setScalar) targetProp.setScalar(value); // Layers have no copy function, we must therefore copy the mask property
|
|
212
|
+
else if (targetProp instanceof THREE__namespace.Layers && value instanceof THREE__namespace.Layers) targetProp.mask = value.mask; // Otherwise just set ...
|
|
213
|
+
else targetProp.set(value); // Auto-convert sRGB colors, for now ...
|
|
214
|
+
// https://github.com/react-spring/react-three-fiber/issues/344
|
|
215
|
+
|
|
216
|
+
if (!rootState.linear && isColor) targetProp.convertSRGBToLinear();
|
|
217
|
+
} // Else, just overwrite the value
|
|
218
|
+
|
|
219
|
+
} else {
|
|
220
|
+
currentInstance[key] = value; // Auto-convert sRGB textures, for now ...
|
|
221
|
+
// https://github.com/react-spring/react-three-fiber/issues/344
|
|
222
|
+
|
|
223
|
+
if (!rootState.linear && currentInstance[key] instanceof THREE__namespace.Texture) currentInstance[key].encoding = THREE__namespace.sRGBEncoding;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
invalidateInstance(instance);
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
if (rootState.internal && instance.raycast && prevHandlers !== ((_localState$handlers2 = localState.handlers) == null ? void 0 : _localState$handlers2.count)) {
|
|
230
|
+
// Pre-emptively remove the instance from the interaction manager
|
|
231
|
+
const index = rootState.internal.interaction.indexOf(instance);
|
|
232
|
+
if (index > -1) rootState.internal.interaction.splice(index, 1); // Add the instance to the interaction manager only when it has handlers
|
|
233
|
+
|
|
234
|
+
if (localState.handlers.count) rootState.internal.interaction.push(instance);
|
|
235
|
+
} // Call the update lifecycle when it is being updated, but only when it is part of the scene
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
if (changes.length && instance.parent) updateInstance(instance);
|
|
239
|
+
}
|
|
240
|
+
function invalidateInstance(instance) {
|
|
241
|
+
var _instance$__r3f4, _instance$__r3f4$root;
|
|
242
|
+
|
|
243
|
+
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();
|
|
244
|
+
if (state && state.internal.frames === 0) state.invalidate();
|
|
245
|
+
}
|
|
246
|
+
function updateInstance(instance) {
|
|
247
|
+
instance.onUpdate == null ? void 0 : instance.onUpdate(instance);
|
|
248
|
+
}
|
|
76
249
|
|
|
77
250
|
function makeId(event) {
|
|
78
251
|
return (event.eventObject || event.object).uuid + '/' + event.index + event.instanceId;
|
|
@@ -419,8 +592,6 @@ function createEvents(store) {
|
|
|
419
592
|
};
|
|
420
593
|
}
|
|
421
594
|
|
|
422
|
-
const isDiffSet = def => def && !!def.memoized && !!def.changes;
|
|
423
|
-
|
|
424
595
|
// Type guard to tell a store from a portal
|
|
425
596
|
const isStore = def => def && !!def.getState;
|
|
426
597
|
|
|
@@ -438,191 +609,13 @@ const getContainer = (container, child) => {
|
|
|
438
609
|
};
|
|
439
610
|
};
|
|
440
611
|
|
|
441
|
-
const DEFAULT = '__default';
|
|
442
|
-
const EMPTY = {};
|
|
443
612
|
let catalogue = {};
|
|
444
613
|
|
|
445
614
|
let extend = objects => void (catalogue = { ...catalogue,
|
|
446
615
|
...objects
|
|
447
|
-
});
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
function checkShallow(a, b) {
|
|
451
|
-
if (is.arr(a) && is.equ(a, b)) return true;
|
|
452
|
-
if (a === b) return true;
|
|
453
|
-
return false;
|
|
454
|
-
} // Each object in the scene carries a small LocalState descriptor
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
function prepare(object, state) {
|
|
458
|
-
const instance = object;
|
|
459
|
-
|
|
460
|
-
if (state != null && state.primitive || !instance.__r3f) {
|
|
461
|
-
instance.__r3f = {
|
|
462
|
-
root: null,
|
|
463
|
-
memoizedProps: {},
|
|
464
|
-
handlers: {
|
|
465
|
-
count: 0
|
|
466
|
-
},
|
|
467
|
-
objects: [],
|
|
468
|
-
...state
|
|
469
|
-
};
|
|
470
|
-
}
|
|
471
|
-
|
|
472
|
-
return object;
|
|
473
|
-
}
|
|
474
|
-
|
|
475
|
-
function createRenderer(roots) {
|
|
476
|
-
// This function prepares a set of changes to be applied to the instance
|
|
477
|
-
function diffProps(instance, {
|
|
478
|
-
children: cN,
|
|
479
|
-
key: kN,
|
|
480
|
-
ref: rN,
|
|
481
|
-
...props
|
|
482
|
-
}, {
|
|
483
|
-
children: cP,
|
|
484
|
-
key: kP,
|
|
485
|
-
ref: rP,
|
|
486
|
-
...previous
|
|
487
|
-
} = {}, accumulative = false) {
|
|
488
|
-
var _instance$__r3f;
|
|
489
|
-
|
|
490
|
-
const localState = (_instance$__r3f = instance == null ? void 0 : instance.__r3f) != null ? _instance$__r3f : {};
|
|
491
|
-
const entries = Object.entries(props);
|
|
492
|
-
const changes = []; // Catch removed props, prepend them so they can be reset or removed
|
|
493
|
-
|
|
494
|
-
if (accumulative) {
|
|
495
|
-
const previousKeys = Object.keys(previous);
|
|
496
|
-
|
|
497
|
-
for (let i = 0; i < previousKeys.length; i++) if (!props.hasOwnProperty(previousKeys[i])) entries.unshift([previousKeys[i], DEFAULT + 'remove']);
|
|
498
|
-
}
|
|
499
|
-
|
|
500
|
-
entries.forEach(([key, value]) => {
|
|
501
|
-
var _instance$__r3f2;
|
|
502
|
-
|
|
503
|
-
// Bail out on primitive object
|
|
504
|
-
if ((_instance$__r3f2 = instance.__r3f) != null && _instance$__r3f2.primitive && key === 'object') return; // When props match bail out
|
|
505
|
-
|
|
506
|
-
if (checkShallow(value, previous[key])) return;
|
|
507
|
-
let currentInstance = instance;
|
|
508
|
-
let targetProp = currentInstance[key]; // Collect handlers and bail out
|
|
509
|
-
|
|
510
|
-
if (/^on(Pointer|Click|DoubleClick|ContextMenu|Wheel)/.test(key)) return changes.push([key, value, true, currentInstance, targetProp]); // Revolve dashed props
|
|
511
|
-
|
|
512
|
-
if (key.includes('-')) {
|
|
513
|
-
const entries = key.split('-');
|
|
514
|
-
targetProp = entries.reduce((acc, key) => acc[key], instance); // If the target is atomic, it forces us to switch the root
|
|
515
|
-
|
|
516
|
-
if (!(targetProp && targetProp.set)) {
|
|
517
|
-
const [name, ...reverseEntries] = entries.reverse();
|
|
518
|
-
currentInstance = reverseEntries.reverse().reduce((acc, key) => acc[key], instance);
|
|
519
|
-
key = name;
|
|
520
|
-
}
|
|
521
|
-
}
|
|
522
|
-
|
|
523
|
-
changes.push([key, value, false, currentInstance, targetProp]);
|
|
524
|
-
});
|
|
525
|
-
const memoized = { ...props
|
|
526
|
-
};
|
|
527
|
-
if (localState.memoizedProps && localState.memoizedProps.args) memoized.args = localState.memoizedProps.args;
|
|
528
|
-
if (localState.memoizedProps && localState.memoizedProps.attach) memoized.attach = localState.memoizedProps.attach;
|
|
529
|
-
return {
|
|
530
|
-
accumulative,
|
|
531
|
-
memoized,
|
|
532
|
-
changes
|
|
533
|
-
};
|
|
534
|
-
}
|
|
535
|
-
|
|
536
|
-
function applyProps(instance, data) {
|
|
537
|
-
var _instance$__r3f3, _root$getState, _localState$handlers, _localState$handlers2;
|
|
538
|
-
|
|
539
|
-
// Filter equals, events and reserved props
|
|
540
|
-
const localState = (_instance$__r3f3 = instance == null ? void 0 : instance.__r3f) != null ? _instance$__r3f3 : {};
|
|
541
|
-
const root = localState.root;
|
|
542
|
-
const rootState = (_root$getState = root == null ? void 0 : root.getState == null ? void 0 : root.getState()) != null ? _root$getState : {};
|
|
543
|
-
const {
|
|
544
|
-
memoized,
|
|
545
|
-
changes
|
|
546
|
-
} = isDiffSet(data) ? data : diffProps(instance, data);
|
|
547
|
-
const prevHandlers = (_localState$handlers = localState.handlers) == null ? void 0 : _localState$handlers.count; // Prepare memoized props
|
|
548
|
-
|
|
549
|
-
if (instance.__r3f) instance.__r3f.memoizedProps = memoized;
|
|
550
|
-
changes.forEach(([key, value, isEvent, currentInstance, targetProp]) => {
|
|
551
|
-
// https://github.com/mrdoob/three.js/issues/21209
|
|
552
|
-
// HMR/fast-refresh relies on the ability to cancel out props, but threejs
|
|
553
|
-
// has no means to do this. Hence we curate a small collection of value-classes
|
|
554
|
-
// with their respective constructor/set arguments
|
|
555
|
-
// For removed props, try to set default values, if possible
|
|
556
|
-
if (value === DEFAULT + 'remove') {
|
|
557
|
-
if (targetProp && targetProp.constructor) {
|
|
558
|
-
// use the prop constructor to find the default it should be
|
|
559
|
-
value = new targetProp.constructor(memoized.args);
|
|
560
|
-
} else if (currentInstance.constructor) {
|
|
561
|
-
// create a blank slate of the instance and copy the particular parameter.
|
|
562
|
-
// @ts-ignore
|
|
563
|
-
const defaultClassCall = new currentInstance.constructor(currentInstance.__r3f.memoizedProps.args);
|
|
564
|
-
value = defaultClassCall[targetProp]; // destory the instance
|
|
565
|
-
|
|
566
|
-
if (defaultClassCall.dispose) defaultClassCall.dispose(); // instance does not have constructor, just set it to 0
|
|
567
|
-
} else value = 0;
|
|
568
|
-
} // Deal with pointer events ...
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
if (isEvent) {
|
|
572
|
-
if (value) localState.handlers[key] = value;else delete localState.handlers[key];
|
|
573
|
-
localState.handlers.count = Object.keys(localState.handlers).length;
|
|
574
|
-
} // Special treatment for objects with support for set/copy, and layers
|
|
575
|
-
else if (targetProp && targetProp.set && (targetProp.copy || targetProp instanceof THREE__namespace.Layers)) {
|
|
576
|
-
// If value is an array
|
|
577
|
-
if (Array.isArray(value)) {
|
|
578
|
-
if (targetProp.fromArray) targetProp.fromArray(value);else targetProp.set(...value);
|
|
579
|
-
} // Test again target.copy(class) next ...
|
|
580
|
-
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
|
|
581
|
-
// https://github.com/react-spring/react-three-fiber/issues/274
|
|
582
|
-
else if (value !== undefined) {
|
|
583
|
-
const isColor = targetProp instanceof THREE__namespace.Color; // Allow setting array scalars
|
|
584
|
-
|
|
585
|
-
if (!isColor && targetProp.setScalar) targetProp.setScalar(value); // Layers have no copy function, we must therefore copy the mask property
|
|
586
|
-
else if (targetProp instanceof THREE__namespace.Layers && value instanceof THREE__namespace.Layers) targetProp.mask = value.mask; // Otherwise just set ...
|
|
587
|
-
else targetProp.set(value); // Auto-convert sRGB colors, for now ...
|
|
588
|
-
// https://github.com/react-spring/react-three-fiber/issues/344
|
|
589
|
-
|
|
590
|
-
if (!rootState.linear && isColor) targetProp.convertSRGBToLinear();
|
|
591
|
-
} // Else, just overwrite the value
|
|
592
|
-
|
|
593
|
-
} else {
|
|
594
|
-
currentInstance[key] = value; // Auto-convert sRGB textures, for now ...
|
|
595
|
-
// https://github.com/react-spring/react-three-fiber/issues/344
|
|
596
|
-
|
|
597
|
-
if (!rootState.linear && currentInstance[key] instanceof THREE__namespace.Texture) currentInstance[key].encoding = THREE__namespace.sRGBEncoding;
|
|
598
|
-
}
|
|
599
|
-
|
|
600
|
-
invalidateInstance(instance);
|
|
601
|
-
});
|
|
602
|
-
|
|
603
|
-
if (rootState.internal && instance.raycast && prevHandlers !== ((_localState$handlers2 = localState.handlers) == null ? void 0 : _localState$handlers2.count)) {
|
|
604
|
-
// Pre-emptively remove the instance from the interaction manager
|
|
605
|
-
const index = rootState.internal.interaction.indexOf(instance);
|
|
606
|
-
if (index > -1) rootState.internal.interaction.splice(index, 1); // Add the instance to the interaction manager only when it has handlers
|
|
607
|
-
|
|
608
|
-
if (localState.handlers.count) rootState.internal.interaction.push(instance);
|
|
609
|
-
} // Call the update lifecycle when it is being updated, but only when it is part of the scene
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
if (changes.length && instance.parent) updateInstance(instance);
|
|
613
|
-
}
|
|
614
|
-
|
|
615
|
-
function invalidateInstance(instance) {
|
|
616
|
-
var _instance$__r3f4, _instance$__r3f4$root;
|
|
617
|
-
|
|
618
|
-
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();
|
|
619
|
-
if (state && state.internal.frames === 0) state.invalidate();
|
|
620
|
-
}
|
|
621
|
-
|
|
622
|
-
function updateInstance(instance) {
|
|
623
|
-
instance.onUpdate == null ? void 0 : instance.onUpdate(instance);
|
|
624
|
-
}
|
|
616
|
+
});
|
|
625
617
|
|
|
618
|
+
function createRenderer(roots, getEventPriority) {
|
|
626
619
|
function createInstance(type, {
|
|
627
620
|
args = [],
|
|
628
621
|
...props
|
|
@@ -682,7 +675,7 @@ function createRenderer(roots) {
|
|
|
682
675
|
// why it passes "true" here
|
|
683
676
|
|
|
684
677
|
|
|
685
|
-
applyProps(instance, props);
|
|
678
|
+
applyProps$1(instance, props);
|
|
686
679
|
return instance;
|
|
687
680
|
}
|
|
688
681
|
|
|
@@ -834,7 +827,7 @@ function createRenderer(roots) {
|
|
|
834
827
|
|
|
835
828
|
|
|
836
829
|
if (shouldDispose && child.dispose && child.type !== 'Scene') {
|
|
837
|
-
|
|
830
|
+
reconciler.runWithPriority(constants.IdleEventPriority, () => {
|
|
838
831
|
try {
|
|
839
832
|
child.dispose();
|
|
840
833
|
} catch (e) {
|
|
@@ -879,25 +872,6 @@ function createRenderer(roots) {
|
|
|
879
872
|
}
|
|
880
873
|
|
|
881
874
|
const reconciler = Reconciler__default['default']({
|
|
882
|
-
now: scheduler.unstable_now,
|
|
883
|
-
createInstance,
|
|
884
|
-
removeChild,
|
|
885
|
-
appendChild,
|
|
886
|
-
appendInitialChild: appendChild,
|
|
887
|
-
insertBefore,
|
|
888
|
-
warnsIfNotActing: true,
|
|
889
|
-
supportsMutation: true,
|
|
890
|
-
isPrimaryRenderer: false,
|
|
891
|
-
getCurrentEventPriority: () => constants.DefaultEventPriority,
|
|
892
|
-
// @ts-ignore
|
|
893
|
-
scheduleTimeout: is.fun(setTimeout) ? setTimeout : undefined,
|
|
894
|
-
// @ts-ignore
|
|
895
|
-
cancelTimeout: is.fun(clearTimeout) ? clearTimeout : undefined,
|
|
896
|
-
// @ts-ignore
|
|
897
|
-
setTimeout: is.fun(setTimeout) ? setTimeout : undefined,
|
|
898
|
-
// @ts-ignore
|
|
899
|
-
clearTimeout: is.fun(clearTimeout) ? clearTimeout : undefined,
|
|
900
|
-
noTimeout: -1,
|
|
901
875
|
appendChildToContainer: (parentInstance, child) => {
|
|
902
876
|
const {
|
|
903
877
|
container,
|
|
@@ -934,10 +908,9 @@ function createRenderer(roots) {
|
|
|
934
908
|
},
|
|
935
909
|
|
|
936
910
|
commitUpdate(instance, [reconstruct, diff], type, oldProps, newProps, fiber) {
|
|
937
|
-
//console.log(type)
|
|
938
911
|
// Reconstruct when args or <primitive object={...} have changes
|
|
939
912
|
if (reconstruct) switchInstance(instance, type, newProps, fiber); // Otherwise just overwrite props
|
|
940
|
-
else applyProps(instance, diff);
|
|
913
|
+
else applyProps$1(instance, diff);
|
|
941
914
|
},
|
|
942
915
|
|
|
943
916
|
hideInstance(instance) {
|
|
@@ -954,62 +927,45 @@ function createRenderer(roots) {
|
|
|
954
927
|
}
|
|
955
928
|
},
|
|
956
929
|
|
|
957
|
-
|
|
930
|
+
createInstance,
|
|
931
|
+
removeChild,
|
|
932
|
+
appendChild,
|
|
933
|
+
appendInitialChild: appendChild,
|
|
934
|
+
insertBefore,
|
|
935
|
+
warnsIfNotActing: true,
|
|
936
|
+
supportsMutation: true,
|
|
937
|
+
isPrimaryRenderer: false,
|
|
938
|
+
getCurrentEventPriority: () => getEventPriority ? getEventPriority() : constants.DefaultEventPriority,
|
|
939
|
+
// @ts-ignore
|
|
940
|
+
now: is.fun(performance.now) ? performance.now : is.fun(Date.now) ? Date.now : undefined,
|
|
941
|
+
// @ts-ignore
|
|
942
|
+
scheduleTimeout: is.fun(setTimeout) ? setTimeout : undefined,
|
|
943
|
+
// @ts-ignore
|
|
944
|
+
cancelTimeout: is.fun(clearTimeout) ? clearTimeout : undefined,
|
|
945
|
+
setTimeout: is.fun(setTimeout) ? setTimeout : undefined,
|
|
946
|
+
clearTimeout: is.fun(clearTimeout) ? clearTimeout : undefined,
|
|
947
|
+
noTimeout: -1,
|
|
948
|
+
hideTextInstance: () => {
|
|
958
949
|
throw new Error('Text is not allowed in the R3F tree.');
|
|
959
950
|
},
|
|
960
|
-
|
|
961
|
-
getPublicInstance
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
},
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
createTextInstance() {},
|
|
975
|
-
|
|
976
|
-
finalizeInitialChildren() {
|
|
977
|
-
return false;
|
|
978
|
-
},
|
|
979
|
-
|
|
980
|
-
commitMount() {// noop
|
|
981
|
-
},
|
|
982
|
-
|
|
983
|
-
shouldDeprioritizeSubtree() {
|
|
984
|
-
return false;
|
|
985
|
-
},
|
|
986
|
-
|
|
987
|
-
prepareForCommit() {
|
|
988
|
-
return null;
|
|
989
|
-
},
|
|
990
|
-
|
|
991
|
-
preparePortalMount(containerInfo) {
|
|
992
|
-
prepare(containerInfo);
|
|
993
|
-
},
|
|
994
|
-
|
|
995
|
-
resetAfterCommit() {// noop
|
|
996
|
-
},
|
|
997
|
-
|
|
998
|
-
shouldSetTextContent() {
|
|
999
|
-
return false;
|
|
1000
|
-
},
|
|
1001
|
-
|
|
1002
|
-
clearContainer() {
|
|
1003
|
-
return false;
|
|
1004
|
-
},
|
|
1005
|
-
|
|
1006
|
-
detachDeletedInstance() {// noop
|
|
1007
|
-
}
|
|
1008
|
-
|
|
951
|
+
// prettier-ignore
|
|
952
|
+
getPublicInstance: instance => instance,
|
|
953
|
+
getRootHostContext: () => null,
|
|
954
|
+
getChildHostContext: parentHostContext => parentHostContext,
|
|
955
|
+
createTextInstance: () => {},
|
|
956
|
+
finalizeInitialChildren: () => false,
|
|
957
|
+
commitMount: () => {},
|
|
958
|
+
shouldDeprioritizeSubtree: () => false,
|
|
959
|
+
prepareForCommit: () => null,
|
|
960
|
+
preparePortalMount: containerInfo => prepare(containerInfo),
|
|
961
|
+
resetAfterCommit: () => {},
|
|
962
|
+
shouldSetTextContent: () => false,
|
|
963
|
+
clearContainer: () => false,
|
|
964
|
+
detachDeletedInstance: () => {}
|
|
1009
965
|
});
|
|
1010
966
|
return {
|
|
1011
967
|
reconciler,
|
|
1012
|
-
applyProps
|
|
968
|
+
applyProps: applyProps$1
|
|
1013
969
|
};
|
|
1014
970
|
}
|
|
1015
971
|
|
|
@@ -1360,20 +1316,61 @@ function createLoop(roots) {
|
|
|
1360
1316
|
};
|
|
1361
1317
|
}
|
|
1362
1318
|
|
|
1319
|
+
// @ts-ignore
|
|
1320
|
+
const CLICK = 'click';
|
|
1321
|
+
const CONTEXTMENU = 'contextmenu';
|
|
1322
|
+
const DBLCLICK = 'dblclick';
|
|
1323
|
+
const POINTERCANCEL = 'pointercancel';
|
|
1324
|
+
const POINTERDOWN = 'pointerdown';
|
|
1325
|
+
const POINTERUP = 'pointerup';
|
|
1326
|
+
const POINTERMOVE = 'pointermove';
|
|
1327
|
+
const POINTEROUT = 'pointerout';
|
|
1328
|
+
const POINTEROVER = 'pointerover';
|
|
1329
|
+
const POINTERENTER = 'pointerenter';
|
|
1330
|
+
const POINTERLEAVE = 'pointerleave';
|
|
1331
|
+
const WHEEL = 'wheel'; // https://github.com/facebook/react/tree/main/packages/react-reconciler#getcurrenteventpriority
|
|
1332
|
+
// Gives React a clue as to how import the current interaction is
|
|
1333
|
+
|
|
1334
|
+
function getEventPriority() {
|
|
1335
|
+
var _window, _window$event;
|
|
1336
|
+
|
|
1337
|
+
let name = (_window = window) == null ? void 0 : (_window$event = _window.event) == null ? void 0 : _window$event.type;
|
|
1338
|
+
|
|
1339
|
+
switch (name) {
|
|
1340
|
+
case CLICK:
|
|
1341
|
+
case CONTEXTMENU:
|
|
1342
|
+
case DBLCLICK:
|
|
1343
|
+
case POINTERCANCEL:
|
|
1344
|
+
case POINTERDOWN:
|
|
1345
|
+
case POINTERUP:
|
|
1346
|
+
return constants.DiscreteEventPriority;
|
|
1347
|
+
|
|
1348
|
+
case POINTERMOVE:
|
|
1349
|
+
case POINTEROUT:
|
|
1350
|
+
case POINTEROVER:
|
|
1351
|
+
case POINTERENTER:
|
|
1352
|
+
case POINTERLEAVE:
|
|
1353
|
+
case WHEEL:
|
|
1354
|
+
return constants.ContinuousEventPriority;
|
|
1355
|
+
|
|
1356
|
+
default:
|
|
1357
|
+
return constants.DefaultEventPriority;
|
|
1358
|
+
}
|
|
1359
|
+
}
|
|
1363
1360
|
function createPointerEvents(store) {
|
|
1364
1361
|
const {
|
|
1365
1362
|
handlePointer
|
|
1366
1363
|
} = createEvents(store);
|
|
1367
1364
|
const names = {
|
|
1368
|
-
onClick: [
|
|
1369
|
-
onContextMenu: [
|
|
1370
|
-
onDoubleClick: [
|
|
1371
|
-
onWheel: [
|
|
1372
|
-
onPointerDown: [
|
|
1373
|
-
onPointerUp: [
|
|
1374
|
-
onPointerLeave: [
|
|
1375
|
-
onPointerMove: [
|
|
1376
|
-
onPointerCancel: [
|
|
1365
|
+
onClick: [CLICK, false],
|
|
1366
|
+
onContextMenu: [CONTEXTMENU, false],
|
|
1367
|
+
onDoubleClick: [DBLCLICK, false],
|
|
1368
|
+
onWheel: [WHEEL, true],
|
|
1369
|
+
onPointerDown: [POINTERDOWN, true],
|
|
1370
|
+
onPointerUp: [POINTERUP, true],
|
|
1371
|
+
onPointerLeave: [POINTERLEAVE, true],
|
|
1372
|
+
onPointerMove: [POINTERMOVE, true],
|
|
1373
|
+
onPointerCancel: [POINTERCANCEL, true],
|
|
1377
1374
|
onLostPointerCapture: ['lostpointercapture', true]
|
|
1378
1375
|
};
|
|
1379
1376
|
return {
|
|
@@ -1610,7 +1607,7 @@ const {
|
|
|
1610
1607
|
const {
|
|
1611
1608
|
reconciler,
|
|
1612
1609
|
applyProps
|
|
1613
|
-
} = createRenderer();
|
|
1610
|
+
} = createRenderer(roots, getEventPriority);
|
|
1614
1611
|
|
|
1615
1612
|
const createRendererInstance = (gl, canvas) => isRenderer(gl) ? gl : new THREE__namespace.WebGLRenderer({
|
|
1616
1613
|
powerPreference: 'high-performance',
|