@react-three/fiber 8.0.0-alpha.0 → 8.0.0-beta-04

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.
Files changed (33) hide show
  1. package/CHANGELOG.md +103 -0
  2. package/dist/declarations/src/core/events.d.ts +64 -59
  3. package/dist/declarations/src/core/hooks.d.ts +21 -29
  4. package/dist/declarations/src/core/index.d.ts +31 -0
  5. package/dist/declarations/src/core/loop.d.ts +12 -12
  6. package/dist/declarations/src/core/renderer.d.ts +50 -52
  7. package/dist/declarations/src/core/store.d.ts +117 -106
  8. package/dist/declarations/src/core/utils.d.ts +50 -0
  9. package/dist/declarations/src/index.d.ts +10 -7
  10. package/dist/declarations/src/native/Canvas.d.ts +13 -0
  11. package/dist/declarations/src/native/events.d.ts +5 -0
  12. package/dist/declarations/src/native/hooks.d.ts +9 -0
  13. package/dist/declarations/src/native.d.ts +10 -0
  14. package/dist/declarations/src/three-types.d.ts +309 -320
  15. package/dist/declarations/src/web/Canvas.d.ts +13 -13
  16. package/dist/declarations/src/web/events.d.ts +4 -4
  17. package/dist/index-eb414398.cjs.prod.js +1805 -0
  18. package/dist/index-fccd77b0.esm.js +1750 -0
  19. package/dist/index-ff3eb68b.cjs.dev.js +1805 -0
  20. package/dist/react-three-fiber.cjs.dev.js +108 -1734
  21. package/dist/react-three-fiber.cjs.prod.js +108 -1734
  22. package/dist/react-three-fiber.esm.js +63 -1686
  23. package/native/dist/react-three-fiber-native.cjs.d.ts +1 -0
  24. package/native/dist/react-three-fiber-native.cjs.dev.js +388 -0
  25. package/native/dist/react-three-fiber-native.cjs.js +7 -0
  26. package/native/dist/react-three-fiber-native.cjs.prod.js +388 -0
  27. package/native/dist/react-three-fiber-native.esm.js +336 -0
  28. package/native/package.json +5 -0
  29. package/package.json +19 -8
  30. package/readme.md +10 -10
  31. package/__mocks__/react-use-measure/index.ts +0 -22
  32. package/dist/declarations/src/core/is.d.ts +0 -9
  33. package/dist/declarations/src/web/index.d.ts +0 -30
@@ -0,0 +1,1805 @@
1
+ 'use strict';
2
+
3
+ var React = require('react');
4
+ var suspendReact = require('suspend-react');
5
+ var THREE = require('three');
6
+ var constants = require('react-reconciler/constants');
7
+ var create = require('zustand');
8
+ var Reconciler = require('react-reconciler');
9
+ var scheduler = require('scheduler');
10
+
11
+ function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
12
+
13
+ function _interopNamespace(e) {
14
+ if (e && e.__esModule) return e;
15
+ var n = Object.create(null);
16
+ if (e) {
17
+ Object.keys(e).forEach(function (k) {
18
+ if (k !== 'default') {
19
+ var d = Object.getOwnPropertyDescriptor(e, k);
20
+ Object.defineProperty(n, k, d.get ? d : {
21
+ enumerable: true,
22
+ get: function () {
23
+ return e[k];
24
+ }
25
+ });
26
+ }
27
+ });
28
+ }
29
+ n['default'] = e;
30
+ return Object.freeze(n);
31
+ }
32
+
33
+ var React__namespace = /*#__PURE__*/_interopNamespace(React);
34
+ var THREE__namespace = /*#__PURE__*/_interopNamespace(THREE);
35
+ var create__default = /*#__PURE__*/_interopDefault(create);
36
+ var Reconciler__default = /*#__PURE__*/_interopDefault(Reconciler);
37
+
38
+ var threeTypes = /*#__PURE__*/Object.freeze({
39
+ __proto__: null
40
+ });
41
+
42
+ const DEFAULT = '__default';
43
+ const isDiffSet = def => def && !!def.memoized && !!def.changes;
44
+ function calculateDpr(dpr) {
45
+ return Array.isArray(dpr) ? Math.min(Math.max(dpr[0], window.devicePixelRatio), dpr[1]) : dpr;
46
+ }
47
+ /**
48
+ * Picks or omits keys from an object
49
+ * `omit` will filter out keys, and otherwise cherry-pick them.
50
+ */
51
+
52
+ function filterKeys(obj, omit, ...keys) {
53
+ const keysToSelect = new Set(keys);
54
+ return Object.entries(obj).reduce((acc, [key, value]) => {
55
+ const shouldInclude = !omit;
56
+
57
+ if (keysToSelect.has(key) === shouldInclude) {
58
+ acc[key] = value;
59
+ }
60
+
61
+ return acc;
62
+ }, {});
63
+ }
64
+ /**
65
+ * Clones an object and cherry-picks keys.
66
+ */
67
+
68
+ const pick = (obj, keys) => filterKeys(obj, false, ...keys);
69
+ /**
70
+ * Clones an object and prunes or omits keys.
71
+ */
72
+
73
+ const omit = (obj, keys) => filterKeys(obj, true, ...keys); // A collection of compare functions
74
+
75
+ const is = {
76
+ obj: a => a === Object(a) && !is.arr(a) && typeof a !== 'function',
77
+ fun: a => typeof a === 'function',
78
+ str: a => typeof a === 'string',
79
+ num: a => typeof a === 'number',
80
+ und: a => a === void 0,
81
+ arr: a => Array.isArray(a),
82
+
83
+ equ(a, b) {
84
+ // Wrong type or one of the two undefined, doesn't match
85
+ if (typeof a !== typeof b || !!a !== !!b) return false; // Atomic, just compare a against b
86
+
87
+ if (is.str(a) || is.num(a) || is.obj(a)) return a === b; // Array, shallow compare first to see if it's a match
88
+
89
+ if (is.arr(a) && a == b) return true; // Last resort, go through keys
90
+
91
+ let i;
92
+
93
+ for (i in a) if (!(i in b)) return false;
94
+
95
+ for (i in b) if (a[i] !== b[i]) return false;
96
+
97
+ return is.und(i) ? a === b : true;
98
+ }
99
+
100
+ }; // Collects nodes and materials from a THREE.Object3D
101
+
102
+ function buildGraph(object) {
103
+ const data = {
104
+ nodes: {},
105
+ materials: {}
106
+ };
107
+
108
+ if (object) {
109
+ object.traverse(obj => {
110
+ if (obj.name) data.nodes[obj.name] = obj;
111
+ if (obj.material && !data.materials[obj.material.name]) data.materials[obj.material.name] = obj.material;
112
+ });
113
+ }
114
+
115
+ return data;
116
+ } // Disposes an object and all its properties
117
+
118
+ function dispose(obj) {
119
+ if (obj.dispose && obj.type !== 'Scene') obj.dispose();
120
+
121
+ for (const p in obj) {
122
+ p.dispose == null ? void 0 : p.dispose();
123
+ delete obj[p];
124
+ }
125
+ } // Each object in the scene carries a small LocalState descriptor
126
+
127
+ function prepare(object, state) {
128
+ const instance = object;
129
+
130
+ if (state != null && state.primitive || !instance.__r3f) {
131
+ instance.__r3f = {
132
+ root: null,
133
+ memoizedProps: {},
134
+ eventCount: 0,
135
+ handlers: {},
136
+ objects: [],
137
+ parent: null,
138
+ ...state
139
+ };
140
+ }
141
+
142
+ return object;
143
+ }
144
+
145
+ function resolve(instance, key) {
146
+ let target = instance;
147
+
148
+ if (key.includes('-')) {
149
+ const entries = key.split('-');
150
+ const last = entries.pop();
151
+ target = entries.reduce((acc, key) => acc[key], instance);
152
+ return {
153
+ target,
154
+ key: last
155
+ };
156
+ } else return {
157
+ target,
158
+ key
159
+ };
160
+ }
161
+
162
+ function attach(parent, child, type) {
163
+ if (is.str(type)) {
164
+ const {
165
+ target,
166
+ key
167
+ } = resolve(parent, type);
168
+ parent.__r3f.previousAttach = target[key];
169
+ target[key] = child;
170
+ } else if (is.arr(type)) {
171
+ const [attach] = type;
172
+ if (is.str(attach)) parent[attach](child);else if (is.fun(attach)) attach(parent, child);
173
+ }
174
+ }
175
+ function detach(parent, child, type) {
176
+ if (is.str(type)) {
177
+ const {
178
+ target,
179
+ key
180
+ } = resolve(parent, type);
181
+ target[key] = parent.__r3f.previousAttach;
182
+ } else if (is.arr(type)) {
183
+ const [, detach] = type;
184
+ if (is.str(detach)) parent[detach](child);else if (is.fun(detach)) detach(parent, child);
185
+ }
186
+ } // Shallow check arrays, but check objects atomically
187
+
188
+ function checkShallow(a, b) {
189
+ if (is.arr(a) && is.equ(a, b)) return true;
190
+ if (a === b) return true;
191
+ return false;
192
+ } // This function prepares a set of changes to be applied to the instance
193
+
194
+
195
+ function diffProps(instance, {
196
+ children: cN,
197
+ key: kN,
198
+ ref: rN,
199
+ ...props
200
+ }, {
201
+ children: cP,
202
+ key: kP,
203
+ ref: rP,
204
+ ...previous
205
+ } = {}, remove = false) {
206
+ var _instance$__r3f;
207
+
208
+ const localState = (_instance$__r3f = instance == null ? void 0 : instance.__r3f) != null ? _instance$__r3f : {};
209
+ const entries = Object.entries(props);
210
+ const changes = []; // Catch removed props, prepend them so they can be reset or removed
211
+
212
+ if (remove) {
213
+ const previousKeys = Object.keys(previous);
214
+
215
+ for (let i = 0; i < previousKeys.length; i++) {
216
+ if (!props.hasOwnProperty(previousKeys[i])) entries.unshift([previousKeys[i], DEFAULT + 'remove']);
217
+ }
218
+ }
219
+
220
+ entries.forEach(([key, value]) => {
221
+ var _instance$__r3f2;
222
+
223
+ // Bail out on primitive object
224
+ if ((_instance$__r3f2 = instance.__r3f) != null && _instance$__r3f2.primitive && key === 'object') return; // When props match bail out
225
+
226
+ if (checkShallow(value, previous[key])) return; // Collect handlers and bail out
227
+
228
+ if (/^on(Pointer|Click|DoubleClick|ContextMenu|Wheel)/.test(key)) return changes.push([key, value, true, []]); // Split dashed props
229
+
230
+ let entries = [];
231
+ if (key.includes('-')) entries = key.split('-');
232
+ changes.push([key, value, false, entries]);
233
+ });
234
+ const memoized = { ...props
235
+ };
236
+ if (localState.memoizedProps && localState.memoizedProps.args) memoized.args = localState.memoizedProps.args;
237
+ if (localState.memoizedProps && localState.memoizedProps.attach) memoized.attach = localState.memoizedProps.attach;
238
+ return {
239
+ memoized,
240
+ changes
241
+ };
242
+ } // This function applies a set of changes to the instance
243
+
244
+ function applyProps$1(instance, data) {
245
+ var _instance$__r3f3, _root$getState;
246
+
247
+ // Filter equals, events and reserved props
248
+ const localState = (_instance$__r3f3 = instance == null ? void 0 : instance.__r3f) != null ? _instance$__r3f3 : {};
249
+ const root = localState.root;
250
+ const rootState = (_root$getState = root == null ? void 0 : root.getState == null ? void 0 : root.getState()) != null ? _root$getState : {};
251
+ const {
252
+ memoized,
253
+ changes
254
+ } = isDiffSet(data) ? data : diffProps(instance, data);
255
+ const prevHandlers = localState.eventCount; // Prepare memoized props
256
+
257
+ if (instance.__r3f) instance.__r3f.memoizedProps = memoized;
258
+ changes.forEach(([key, value, isEvent, keys]) => {
259
+ let currentInstance = instance;
260
+ let targetProp = currentInstance[key]; // Revolve dashed props
261
+
262
+ if (keys.length) {
263
+ targetProp = keys.reduce((acc, key) => acc[key], instance); // If the target is atomic, it forces us to switch the root
264
+
265
+ if (!(targetProp && targetProp.set)) {
266
+ const [name, ...reverseEntries] = keys.reverse();
267
+ currentInstance = reverseEntries.reverse().reduce((acc, key) => acc[key], instance);
268
+ key = name;
269
+ }
270
+ } // https://github.com/mrdoob/three.js/issues/21209
271
+ // HMR/fast-refresh relies on the ability to cancel out props, but threejs
272
+ // has no means to do this. Hence we curate a small collection of value-classes
273
+ // with their respective constructor/set arguments
274
+ // For removed props, try to set default values, if possible
275
+
276
+
277
+ if (value === DEFAULT + 'remove') {
278
+ if (targetProp && targetProp.constructor) {
279
+ // use the prop constructor to find the default it should be
280
+ value = new targetProp.constructor(memoized.args);
281
+ } else if (currentInstance.constructor) {
282
+ // create a blank slate of the instance and copy the particular parameter.
283
+ // @ts-ignore
284
+ const defaultClassCall = new currentInstance.constructor(currentInstance.__r3f.memoizedProps.args);
285
+ value = defaultClassCall[targetProp]; // destory the instance
286
+
287
+ if (defaultClassCall.dispose) defaultClassCall.dispose(); // instance does not have constructor, just set it to 0
288
+ } else {
289
+ value = 0;
290
+ }
291
+ } // Deal with pointer events ...
292
+
293
+
294
+ if (isEvent) {
295
+ if (value) localState.handlers[key] = value;else delete localState.handlers[key];
296
+ localState.eventCount = Object.keys(localState.handlers).length;
297
+ } // Special treatment for objects with support for set/copy, and layers
298
+ else if (targetProp && targetProp.set && (targetProp.copy || targetProp instanceof THREE__namespace.Layers)) {
299
+ // If value is an array
300
+ if (Array.isArray(value)) {
301
+ if (targetProp.fromArray) targetProp.fromArray(value);else targetProp.set(...value);
302
+ } // Test again target.copy(class) next ...
303
+ else if (targetProp.copy && value && value.constructor && targetProp.constructor.name === value.constructor.name) {
304
+ targetProp.copy(value);
305
+ } // If nothing else fits, just set the single value, ignore undefined
306
+ // https://github.com/pmndrs/react-three-fiber/issues/274
307
+ else if (value !== undefined) {
308
+ const isColor = targetProp instanceof THREE__namespace.Color; // Allow setting array scalars
309
+
310
+ if (!isColor && targetProp.setScalar) targetProp.setScalar(value); // Layers have no copy function, we must therefore copy the mask property
311
+ else if (targetProp instanceof THREE__namespace.Layers && value instanceof THREE__namespace.Layers) targetProp.mask = value.mask; // Otherwise just set ...
312
+ else targetProp.set(value); // Auto-convert sRGB colors, for now ...
313
+ // https://github.com/pmndrs/react-three-fiber/issues/344
314
+
315
+ if (!rootState.linear && isColor) targetProp.convertSRGBToLinear();
316
+ } // Else, just overwrite the value
317
+
318
+ } else {
319
+ currentInstance[key] = value; // Auto-convert sRGB textures, for now ...
320
+ // https://github.com/pmndrs/react-three-fiber/issues/344
321
+
322
+ if (!rootState.linear && currentInstance[key] instanceof THREE__namespace.Texture) {
323
+ currentInstance[key].encoding = THREE__namespace.sRGBEncoding;
324
+ }
325
+ }
326
+
327
+ invalidateInstance(instance);
328
+ return instance;
329
+ });
330
+
331
+ if (localState.parent && rootState.internal && instance.raycast && prevHandlers !== localState.eventCount) {
332
+ // Pre-emptively remove the instance from the interaction manager
333
+ const index = rootState.internal.interaction.indexOf(instance);
334
+ if (index > -1) rootState.internal.interaction.splice(index, 1); // Add the instance to the interaction manager only when it has handlers
335
+
336
+ if (localState.eventCount) rootState.internal.interaction.push(instance);
337
+ } // Call the update lifecycle when it is being updated, but only when it is part of the scene
338
+
339
+
340
+ if (changes.length && instance.parent) updateInstance(instance);
341
+ }
342
+ function invalidateInstance(instance) {
343
+ var _instance$__r3f4, _instance$__r3f4$root;
344
+
345
+ 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();
346
+ if (state && state.internal.frames === 0) state.invalidate();
347
+ }
348
+ function updateInstance(instance) {
349
+ instance.onUpdate == null ? void 0 : instance.onUpdate(instance);
350
+ }
351
+
352
+ function makeId(event) {
353
+ return (event.eventObject || event.object).uuid + '/' + event.index + event.instanceId;
354
+ } // https://github.com/facebook/react/tree/main/packages/react-reconciler#getcurrenteventpriority
355
+ // Gives React a clue as to how import the current interaction is
356
+
357
+
358
+ function getEventPriority() {
359
+ var _window, _window$event;
360
+
361
+ let name = (_window = window) == null ? void 0 : (_window$event = _window.event) == null ? void 0 : _window$event.type;
362
+
363
+ switch (name) {
364
+ case 'click':
365
+ case 'contextmenu':
366
+ case 'dblclick':
367
+ case 'pointercancel':
368
+ case 'pointerdown':
369
+ case 'pointerup':
370
+ return constants.DiscreteEventPriority;
371
+
372
+ case 'pointermove':
373
+ case 'pointerout':
374
+ case 'pointerover':
375
+ case 'pointerenter':
376
+ case 'pointerleave':
377
+ case 'wheel':
378
+ return constants.ContinuousEventPriority;
379
+
380
+ default:
381
+ return constants.DefaultEventPriority;
382
+ }
383
+ }
384
+ /**
385
+ * Release pointer captures.
386
+ * This is called by releasePointerCapture in the API, and when an object is removed.
387
+ */
388
+
389
+ function releaseInternalPointerCapture(capturedMap, obj, captures, pointerId) {
390
+ const captureData = captures.get(obj);
391
+
392
+ if (captureData) {
393
+ captures.delete(obj); // If this was the last capturing object for this pointer
394
+
395
+ if (captures.size === 0) {
396
+ capturedMap.delete(pointerId);
397
+ captureData.target.releasePointerCapture(pointerId);
398
+ }
399
+ }
400
+ }
401
+
402
+ function removeInteractivity(store, object) {
403
+ const {
404
+ internal
405
+ } = store.getState(); // Removes every trace of an object from the data store
406
+
407
+ internal.interaction = internal.interaction.filter(o => o !== object);
408
+ internal.initialHits = internal.initialHits.filter(o => o !== object);
409
+ internal.hovered.forEach((value, key) => {
410
+ if (value.eventObject === object || value.object === object) {
411
+ internal.hovered.delete(key);
412
+ }
413
+ });
414
+ internal.capturedMap.forEach((captures, pointerId) => {
415
+ releaseInternalPointerCapture(internal.capturedMap, object, captures, pointerId);
416
+ });
417
+ }
418
+ function createEvents(store) {
419
+ const temp = new THREE__namespace.Vector3();
420
+ /** Sets up defaultRaycaster */
421
+
422
+ function prepareRay(event) {
423
+ var _raycaster$computeOff;
424
+
425
+ const state = store.getState();
426
+ const {
427
+ raycaster,
428
+ mouse,
429
+ camera,
430
+ size
431
+ } = state; // https://github.com/pmndrs/react-three-fiber/pull/782
432
+ // Events trigger outside of canvas when moved
433
+
434
+ const {
435
+ offsetX,
436
+ offsetY
437
+ } = (_raycaster$computeOff = raycaster.computeOffsets == null ? void 0 : raycaster.computeOffsets(event, state)) != null ? _raycaster$computeOff : event;
438
+ const {
439
+ width,
440
+ height
441
+ } = size;
442
+ mouse.set(offsetX / width * 2 - 1, -(offsetY / height) * 2 + 1);
443
+ raycaster.setFromCamera(mouse, camera);
444
+ }
445
+ /** Calculates delta */
446
+
447
+
448
+ function calculateDistance(event) {
449
+ const {
450
+ internal
451
+ } = store.getState();
452
+ const dx = event.offsetX - internal.initialClick[0];
453
+ const dy = event.offsetY - internal.initialClick[1];
454
+ return Math.round(Math.sqrt(dx * dx + dy * dy));
455
+ }
456
+ /** Returns true if an instance has a valid pointer-event registered, this excludes scroll, clicks etc */
457
+
458
+
459
+ function filterPointerEvents(objects) {
460
+ return objects.filter(obj => ['Move', 'Over', 'Enter', 'Out', 'Leave'].some(name => {
461
+ var _r3f;
462
+
463
+ return (_r3f = obj.__r3f) == null ? void 0 : _r3f.handlers['onPointer' + name];
464
+ }));
465
+ }
466
+
467
+ function intersect(filter) {
468
+ const state = store.getState();
469
+ const {
470
+ raycaster,
471
+ internal
472
+ } = state; // Skip event handling when noEvents is set
473
+
474
+ if (!raycaster.enabled) return [];
475
+ const seen = new Set();
476
+ const intersections = []; // Allow callers to eliminate event objects
477
+
478
+ const eventsObjects = filter ? filter(internal.interaction) : internal.interaction; // Intersect known handler objects and filter against duplicates
479
+
480
+ let intersects = raycaster.intersectObjects(eventsObjects, true).filter(item => {
481
+ const id = makeId(item);
482
+ if (seen.has(id)) return false;
483
+ seen.add(id);
484
+ return true;
485
+ }); // https://github.com/mrdoob/three.js/issues/16031
486
+ // Allow custom userland intersect sort order
487
+
488
+ if (raycaster.filter) intersects = raycaster.filter(intersects, state);
489
+
490
+ for (const intersect of intersects) {
491
+ let eventObject = intersect.object; // Bubble event up
492
+
493
+ while (eventObject) {
494
+ var _r3f2;
495
+
496
+ if ((_r3f2 = eventObject.__r3f) != null && _r3f2.eventCount) intersections.push({ ...intersect,
497
+ eventObject
498
+ });
499
+ eventObject = eventObject.parent;
500
+ }
501
+ }
502
+
503
+ return intersections;
504
+ }
505
+ /** Creates filtered intersects and returns an array of positive hits */
506
+
507
+
508
+ function patchIntersects(intersections, event) {
509
+ const {
510
+ internal
511
+ } = store.getState(); // If the interaction is captured, make all capturing targets part of the
512
+ // intersect.
513
+
514
+ if ('pointerId' in event && internal.capturedMap.has(event.pointerId)) {
515
+ for (let captureData of internal.capturedMap.get(event.pointerId).values()) {
516
+ intersections.push(captureData.intersection);
517
+ }
518
+ }
519
+
520
+ return intersections;
521
+ }
522
+ /** Handles intersections by forwarding them to handlers */
523
+
524
+
525
+ function handleIntersects(intersections, event, delta, callback) {
526
+ const {
527
+ raycaster,
528
+ mouse,
529
+ camera,
530
+ internal
531
+ } = store.getState(); // If anything has been found, forward it to the event listeners
532
+
533
+ if (intersections.length) {
534
+ const unprojectedPoint = temp.set(mouse.x, mouse.y, 0).unproject(camera);
535
+ const localState = {
536
+ stopped: false
537
+ };
538
+
539
+ for (const hit of intersections) {
540
+ const hasPointerCapture = id => {
541
+ var _internal$capturedMap, _internal$capturedMap2;
542
+
543
+ return (_internal$capturedMap = (_internal$capturedMap2 = internal.capturedMap.get(id)) == null ? void 0 : _internal$capturedMap2.has(hit.eventObject)) != null ? _internal$capturedMap : false;
544
+ };
545
+
546
+ const setPointerCapture = id => {
547
+ const captureData = {
548
+ intersection: hit,
549
+ target: event.target
550
+ };
551
+
552
+ if (internal.capturedMap.has(id)) {
553
+ // if the pointerId was previously captured, we add the hit to the
554
+ // event capturedMap.
555
+ internal.capturedMap.get(id).set(hit.eventObject, captureData);
556
+ } else {
557
+ // if the pointerId was not previously captured, we create a map
558
+ // containing the hitObject, and the hit. hitObject is used for
559
+ // faster access.
560
+ internal.capturedMap.set(id, new Map([[hit.eventObject, captureData]]));
561
+ } // Call the original event now
562
+ event.target.setPointerCapture(id);
563
+ };
564
+
565
+ const releasePointerCapture = id => {
566
+ const captures = internal.capturedMap.get(id);
567
+
568
+ if (captures) {
569
+ releaseInternalPointerCapture(internal.capturedMap, hit.eventObject, captures, id);
570
+ }
571
+ }; // Add native event props
572
+
573
+
574
+ let extractEventProps = {}; // This iterates over the event's properties including the inherited ones. Native PointerEvents have most of their props as getters which are inherited, but polyfilled PointerEvents have them all as their own properties (i.e. not inherited). We can't use Object.keys() or Object.entries() as they only return "own" properties; nor Object.getPrototypeOf(event) as that *doesn't* return "own" properties, only inherited ones.
575
+
576
+ for (let prop in event) {
577
+ let property = event[prop]; // Only copy over atomics, leave functions alone as these should be
578
+ // called as event.nativeEvent.fn()
579
+
580
+ if (typeof property !== 'function') extractEventProps[prop] = property;
581
+ }
582
+
583
+ let raycastEvent = { ...hit,
584
+ ...extractEventProps,
585
+ spaceX: mouse.x,
586
+ spaceY: mouse.y,
587
+ intersections,
588
+ stopped: localState.stopped,
589
+ delta,
590
+ unprojectedPoint,
591
+ ray: raycaster.ray,
592
+ camera: camera,
593
+ // Hijack stopPropagation, which just sets a flag
594
+ stopPropagation: () => {
595
+ // https://github.com/pmndrs/react-three-fiber/issues/596
596
+ // Events are not allowed to stop propagation if the pointer has been captured
597
+ const capturesForPointer = 'pointerId' in event && internal.capturedMap.get(event.pointerId); // We only authorize stopPropagation...
598
+
599
+ if ( // ...if this pointer hasn't been captured
600
+ !capturesForPointer || // ... or if the hit object is capturing the pointer
601
+ capturesForPointer.has(hit.eventObject)) {
602
+ raycastEvent.stopped = localState.stopped = true; // Propagation is stopped, remove all other hover records
603
+ // An event handler is only allowed to flush other handlers if it is hovered itself
604
+
605
+ if (internal.hovered.size && Array.from(internal.hovered.values()).find(i => i.eventObject === hit.eventObject)) {
606
+ // Objects cannot flush out higher up objects that have already caught the event
607
+ const higher = intersections.slice(0, intersections.indexOf(hit));
608
+ cancelPointer([...higher, hit]);
609
+ }
610
+ }
611
+ },
612
+ // there should be a distinction between target and currentTarget
613
+ target: {
614
+ hasPointerCapture,
615
+ setPointerCapture,
616
+ releasePointerCapture
617
+ },
618
+ currentTarget: {
619
+ hasPointerCapture,
620
+ setPointerCapture,
621
+ releasePointerCapture
622
+ },
623
+ sourceEvent: event,
624
+ // deprecated
625
+ nativeEvent: event
626
+ }; // Call subscribers
627
+
628
+ callback(raycastEvent); // Event bubbling may be interrupted by stopPropagation
629
+
630
+ if (localState.stopped === true) break;
631
+ }
632
+ }
633
+
634
+ return intersections;
635
+ }
636
+
637
+ function cancelPointer(hits) {
638
+ const {
639
+ internal
640
+ } = store.getState();
641
+ Array.from(internal.hovered.values()).forEach(hoveredObj => {
642
+ // When no objects were hit or the the hovered object wasn't found underneath the cursor
643
+ // we call onPointerOut and delete the object from the hovered-elements map
644
+ if (!hits.length || !hits.find(hit => hit.object === hoveredObj.object && hit.index === hoveredObj.index && hit.instanceId === hoveredObj.instanceId)) {
645
+ const eventObject = hoveredObj.eventObject;
646
+ const instance = eventObject.__r3f;
647
+ const handlers = instance == null ? void 0 : instance.handlers;
648
+ internal.hovered.delete(makeId(hoveredObj));
649
+
650
+ if (instance != null && instance.eventCount) {
651
+ // Clear out intersects, they are outdated by now
652
+ const data = { ...hoveredObj,
653
+ intersections: hits || []
654
+ };
655
+ handlers.onPointerOut == null ? void 0 : handlers.onPointerOut(data);
656
+ handlers.onPointerLeave == null ? void 0 : handlers.onPointerLeave(data);
657
+ }
658
+ }
659
+ });
660
+ }
661
+
662
+ const handlePointer = name => {
663
+ // Deal with cancelation
664
+ switch (name) {
665
+ case 'onPointerLeave':
666
+ case 'onPointerCancel':
667
+ return () => cancelPointer([]);
668
+
669
+ case 'onLostPointerCapture':
670
+ return event => {
671
+ const {
672
+ internal
673
+ } = store.getState();
674
+
675
+ if ('pointerId' in event && !internal.capturedMap.has(event.pointerId)) {
676
+ // If the object event interface had onLostPointerCapture, we'd call it here on every
677
+ // object that's getting removed.
678
+ internal.capturedMap.delete(event.pointerId);
679
+ cancelPointer([]);
680
+ }
681
+ };
682
+ } // Any other pointer goes here ...
683
+
684
+
685
+ return event => {
686
+ const {
687
+ onPointerMissed,
688
+ internal
689
+ } = store.getState();
690
+ prepareRay(event);
691
+ internal.lastEvent.current = event; // Get fresh intersects
692
+
693
+ const isPointerMove = name === 'onPointerMove';
694
+ const isClickEvent = name === 'onClick' || name === 'onContextMenu' || name === 'onDoubleClick';
695
+ const filter = isPointerMove ? filterPointerEvents : undefined;
696
+ const hits = patchIntersects(intersect(filter), event);
697
+ const delta = isClickEvent ? calculateDistance(event) : 0; // Save initial coordinates on pointer-down
698
+
699
+ if (name === 'onPointerDown') {
700
+ internal.initialClick = [event.offsetX, event.offsetY];
701
+ internal.initialHits = hits.map(hit => hit.eventObject);
702
+ } // If a click yields no results, pass it back to the user as a miss
703
+ // Missed events have to come first in order to establish user-land side-effect clean up
704
+
705
+
706
+ if (isClickEvent && !hits.length) {
707
+ if (delta <= 2) {
708
+ pointerMissed(event, internal.interaction);
709
+ if (onPointerMissed) onPointerMissed(event);
710
+ }
711
+ } // Take care of unhover
712
+
713
+
714
+ if (isPointerMove) cancelPointer(hits);
715
+ handleIntersects(hits, event, delta, data => {
716
+ const eventObject = data.eventObject;
717
+ const instance = eventObject.__r3f;
718
+ const handlers = instance == null ? void 0 : instance.handlers; // Check presence of handlers
719
+
720
+ if (!(instance != null && instance.eventCount)) return;
721
+
722
+ if (isPointerMove) {
723
+ // Move event ...
724
+ if (handlers.onPointerOver || handlers.onPointerEnter || handlers.onPointerOut || handlers.onPointerLeave) {
725
+ // When enter or out is present take care of hover-state
726
+ const id = makeId(data);
727
+ const hoveredItem = internal.hovered.get(id);
728
+
729
+ if (!hoveredItem) {
730
+ // If the object wasn't previously hovered, book it and call its handler
731
+ internal.hovered.set(id, data);
732
+ handlers.onPointerOver == null ? void 0 : handlers.onPointerOver(data);
733
+ handlers.onPointerEnter == null ? void 0 : handlers.onPointerEnter(data);
734
+ } else if (hoveredItem.stopped) {
735
+ // If the object was previously hovered and stopped, we shouldn't allow other items to proceed
736
+ data.stopPropagation();
737
+ }
738
+ } // Call mouse move
739
+
740
+
741
+ handlers.onPointerMove == null ? void 0 : handlers.onPointerMove(data);
742
+ } else {
743
+ // All other events ...
744
+ const handler = handlers[name];
745
+
746
+ if (handler) {
747
+ // Forward all events back to their respective handlers with the exception of click events,
748
+ // which must use the initial target
749
+ if (!isClickEvent || internal.initialHits.includes(eventObject)) {
750
+ // Missed events have to come first
751
+ pointerMissed(event, internal.interaction.filter(object => !internal.initialHits.includes(object))); // Now call the handler
752
+
753
+ handler(data);
754
+ }
755
+ } else {
756
+ // Trigger onPointerMissed on all elements that have pointer over/out handlers, but not click and weren't hit
757
+ if (isClickEvent && internal.initialHits.includes(eventObject)) {
758
+ pointerMissed(event, internal.interaction.filter(object => !internal.initialHits.includes(object)));
759
+ }
760
+ }
761
+ }
762
+ });
763
+ };
764
+ };
765
+
766
+ function pointerMissed(event, objects) {
767
+ objects.forEach(object => {
768
+ var _r3f3;
769
+
770
+ return (_r3f3 = object.__r3f) == null ? void 0 : _r3f3.handlers.onPointerMissed == null ? void 0 : _r3f3.handlers.onPointerMissed(event);
771
+ });
772
+ }
773
+
774
+ return {
775
+ handlePointer
776
+ };
777
+ }
778
+
779
+ // Type guard to tell a store from a portal
780
+ const isStore = def => def && !!def.getState;
781
+
782
+ const getContainer = (container, child) => {
783
+ var _container$__r3f$root, _container$__r3f;
784
+
785
+ return {
786
+ // If the container is not a root-store then it must be a THREE.Object3D into which part of the
787
+ // scene is portalled into. Now there can be two variants of this, either that object is part of
788
+ // the regular jsx tree, in which case it already has __r3f with a valid root attached, or it lies
789
+ // outside react, in which case we must take the root of the child that is about to be attached to it.
790
+ root: isStore(container) ? container : (_container$__r3f$root = (_container$__r3f = container.__r3f) == null ? void 0 : _container$__r3f.root) != null ? _container$__r3f$root : child.__r3f.root,
791
+ // The container is the eventual target into which objects are mounted, it has to be a THREE.Object3D
792
+ container: isStore(container) ? container.getState().scene : container
793
+ };
794
+ };
795
+
796
+ let catalogue = {};
797
+
798
+ let extend = objects => void (catalogue = { ...catalogue,
799
+ ...objects
800
+ });
801
+
802
+ function createRenderer(roots, getEventPriority) {
803
+ function createInstance(type, {
804
+ args = [],
805
+ attach,
806
+ ...props
807
+ }, root, hostContext, internalInstanceHandle) {
808
+ let name = `${type[0].toUpperCase()}${type.slice(1)}`;
809
+ let instance; // https://github.com/facebook/react/issues/17147
810
+ // Portals do not give us a root, they are themselves treated as a root by the reconciler
811
+ // In order to figure out the actual root we have to climb through fiber internals :(
812
+
813
+ if (!isStore(root) && internalInstanceHandle) {
814
+ const fn = node => {
815
+ if (!node.return) return node.stateNode && node.stateNode.containerInfo;else return fn(node.return);
816
+ };
817
+
818
+ root = fn(internalInstanceHandle);
819
+ } // Assert that by now we have a valid root
820
+
821
+
822
+ if (!root || !isStore(root)) throw `No valid root for ${name}!`; // Auto-attach geometries and materials
823
+
824
+ if (attach === undefined) {
825
+ if (name.endsWith('Geometry')) attach = 'geometry';else if (name.endsWith('Material')) attach = 'material';
826
+ }
827
+
828
+ if (type === 'primitive') {
829
+ if (props.object === undefined) throw `Primitives without 'object' are invalid!`;
830
+ const object = props.object;
831
+ instance = prepare(object, {
832
+ root,
833
+ attach,
834
+ primitive: true
835
+ });
836
+ } else {
837
+ const target = catalogue[name];
838
+
839
+ if (!target) {
840
+ throw `${name} is not part of the THREE namespace! Did you forget to extend? See: https://github.com/pmndrs/react-three-fiber/blob/master/markdown/api.md#using-3rd-party-objects-declaratively`;
841
+ } // Throw if an object or literal was passed for args
842
+
843
+
844
+ if (!Array.isArray(args)) throw 'The args prop must be an array!'; // Instanciate new object, link it to the root
845
+ // Append memoized props with args so it's not forgotten
846
+
847
+ instance = prepare(new target(...args), {
848
+ root,
849
+ attach,
850
+ // TODO: Figure out what this is for
851
+ memoizedProps: {
852
+ args: args.length === 0 ? null : args
853
+ }
854
+ });
855
+ } // It should NOT call onUpdate on object instanciation, because it hasn't been added to the
856
+ // view yet. If the callback relies on references for instance, they won't be ready yet, this is
857
+ // why it passes "true" here
858
+
859
+
860
+ applyProps$1(instance, props);
861
+ return instance;
862
+ }
863
+
864
+ function appendChild(parentInstance, child) {
865
+ let added = false;
866
+
867
+ if (child) {
868
+ // The attach attribute implies that the object attaches itself on the parent
869
+ if (child.__r3f.attach) {
870
+ attach(parentInstance, child, child.__r3f.attach);
871
+ } else if (child.isObject3D && parentInstance.isObject3D) {
872
+ // add in the usual parent-child way
873
+ parentInstance.add(child);
874
+ added = true;
875
+ } // This is for anything that used attach, and for non-Object3Ds that don't get attached to props;
876
+ // that is, anything that's a child in React but not a child in the scenegraph.
877
+
878
+
879
+ if (!added) parentInstance.__r3f.objects.push(child);
880
+ if (!child.__r3f) prepare(child, {});
881
+ child.__r3f.parent = parentInstance;
882
+ updateInstance(child);
883
+ invalidateInstance(child);
884
+ }
885
+ }
886
+
887
+ function insertBefore(parentInstance, child, beforeChild) {
888
+ let added = false;
889
+
890
+ if (child) {
891
+ if (child.__r3f.attach) {
892
+ attach(parentInstance, child, child.__r3f.attach);
893
+ } else if (child.isObject3D && parentInstance.isObject3D) {
894
+ child.parent = parentInstance;
895
+ child.dispatchEvent({
896
+ type: 'added'
897
+ });
898
+ const restSiblings = parentInstance.children.filter(sibling => sibling !== child);
899
+ const index = restSiblings.indexOf(beforeChild);
900
+ parentInstance.children = [...restSiblings.slice(0, index), child, ...restSiblings.slice(index)];
901
+ added = true;
902
+ }
903
+
904
+ if (!added) parentInstance.__r3f.objects.push(child);
905
+ if (!child.__r3f) prepare(child, {});
906
+ child.__r3f.parent = parentInstance;
907
+ updateInstance(child);
908
+ invalidateInstance(child);
909
+ }
910
+ }
911
+
912
+ function removeRecursive(array, parent, dispose = false) {
913
+ if (array) [...array].forEach(child => removeChild(parent, child, dispose));
914
+ }
915
+
916
+ function removeChild(parentInstance, child, dispose) {
917
+ if (child) {
918
+ var _parentInstance$__r3f, _child$__r3f2;
919
+
920
+ // Clear the parent reference
921
+ if (child.__r3f) child.__r3f.parent = null; // Remove child from the parents objects
922
+
923
+ if ((_parentInstance$__r3f = parentInstance.__r3f) != null && _parentInstance$__r3f.objects) parentInstance.__r3f.objects = parentInstance.__r3f.objects.filter(x => x !== child); // Remove attachment
924
+
925
+ if (child.__r3f.attach) {
926
+ detach(parentInstance, child, child.__r3f.attach);
927
+ } else if (child.isObject3D && parentInstance.isObject3D) {
928
+ var _child$__r3f;
929
+
930
+ parentInstance.remove(child); // Remove interactivity
931
+
932
+ if ((_child$__r3f = child.__r3f) != null && _child$__r3f.root) {
933
+ removeInteractivity(child.__r3f.root, child);
934
+ }
935
+ } // Allow objects to bail out of recursive dispose alltogether by passing dispose={null}
936
+ // Never dispose of primitives because their state may be kept outside of React!
937
+ // In order for an object to be able to dispose it has to have
938
+ // - a dispose method,
939
+ // - it cannot be a <primitive object={...} />
940
+ // - it cannot be a THREE.Scene, because three has broken it's own api
941
+ //
942
+ // Since disposal is recursive, we can check the optional dispose arg, which will be undefined
943
+ // when the reconciler calls it, but then carry our own check recursively
944
+
945
+
946
+ const isPrimitive = (_child$__r3f2 = child.__r3f) == null ? void 0 : _child$__r3f2.primitive;
947
+ const shouldDispose = dispose === undefined ? child.dispose !== null && !isPrimitive : dispose; // Remove nested child objects. Primitives should not have objects and children that are
948
+ // attached to them declaratively ...
949
+
950
+ if (!isPrimitive) {
951
+ var _child$__r3f3;
952
+
953
+ removeRecursive((_child$__r3f3 = child.__r3f) == null ? void 0 : _child$__r3f3.objects, child, shouldDispose);
954
+ removeRecursive(child.children, child, shouldDispose);
955
+ } // Remove references
956
+
957
+
958
+ if (child.__r3f) {
959
+ delete child.__r3f.root;
960
+ delete child.__r3f.objects;
961
+ delete child.__r3f.handlers;
962
+ delete child.__r3f.memoizedProps;
963
+ if (!isPrimitive) delete child.__r3f;
964
+ } // Dispose item whenever the reconciler feels like it
965
+
966
+
967
+ if (shouldDispose && child.dispose && child.type !== 'Scene') {
968
+ scheduler.unstable_scheduleCallback(scheduler.unstable_IdlePriority, () => {
969
+ try {
970
+ child.dispose();
971
+ } catch (e) {
972
+ /* ... */
973
+ }
974
+ });
975
+ }
976
+
977
+ invalidateInstance(parentInstance);
978
+ }
979
+ }
980
+
981
+ function switchInstance(instance, type, newProps, fiber) {
982
+ var _instance$__r3f;
983
+
984
+ const parent = (_instance$__r3f = instance.__r3f) == null ? void 0 : _instance$__r3f.parent;
985
+ if (!parent) return;
986
+ const newInstance = createInstance(type, newProps, instance.__r3f.root); // https://github.com/pmndrs/react-three-fiber/issues/1348
987
+ // When args change the instance has to be re-constructed, which then
988
+ // forces r3f to re-parent the children and non-scene objects
989
+ // This can not include primitives, which should not have declarative children
990
+
991
+ if (type !== 'primitive' && instance.children) {
992
+ instance.children.forEach(child => appendChild(newInstance, child));
993
+ instance.children = [];
994
+ }
995
+
996
+ instance.__r3f.objects.forEach(child => appendChild(newInstance, child));
997
+
998
+ instance.__r3f.objects = [];
999
+ removeChild(parent, instance);
1000
+ appendChild(parent, newInstance) // This evil hack switches the react-internal fiber node
1001
+ // https://github.com/facebook/react/issues/14983
1002
+ // https://github.com/facebook/react/pull/15021
1003
+ ;
1004
+ [fiber, fiber.alternate].forEach(fiber => {
1005
+ if (fiber !== null) {
1006
+ fiber.stateNode = newInstance;
1007
+
1008
+ if (fiber.ref) {
1009
+ if (typeof fiber.ref === 'function') fiber.ref(newInstance);else fiber.ref.current = newInstance;
1010
+ }
1011
+ }
1012
+ });
1013
+ }
1014
+
1015
+ const reconciler = Reconciler__default['default']({
1016
+ appendChildToContainer: (parentInstance, child) => {
1017
+ const {
1018
+ container,
1019
+ root
1020
+ } = getContainer(parentInstance, child); // Link current root to the default scene
1021
+
1022
+ container.__r3f.root = root;
1023
+ appendChild(container, child);
1024
+ },
1025
+ removeChildFromContainer: (parentInstance, child) => removeChild(getContainer(parentInstance, child).container, child),
1026
+ insertInContainerBefore: (parentInstance, child, beforeChild) => insertBefore(getContainer(parentInstance, child).container, child, beforeChild),
1027
+
1028
+ prepareUpdate(instance, type, oldProps, newProps) {
1029
+ if (instance.__r3f.primitive && newProps.object && newProps.object !== instance) {
1030
+ return [true];
1031
+ } else {
1032
+ // This is a data object, let's extract critical information about it
1033
+ const {
1034
+ args: argsNew = [],
1035
+ children: cN,
1036
+ ...restNew
1037
+ } = newProps;
1038
+ const {
1039
+ args: argsOld = [],
1040
+ children: cO,
1041
+ ...restOld
1042
+ } = oldProps; // Throw if an object or literal was passed for args
1043
+
1044
+ if (!Array.isArray(argsNew)) throw 'The args prop must be an array!'; // If it has new props or arguments, then it needs to be re-instanciated
1045
+
1046
+ if (argsNew.some((value, index) => value !== argsOld[index])) return [true]; // Create a diff-set, flag if there are any changes
1047
+
1048
+ const diff = diffProps(instance, restNew, restOld, true);
1049
+ if (diff.changes.length) return [false, diff]; // Otherwise do not touch the instance
1050
+
1051
+ return null;
1052
+ }
1053
+ },
1054
+
1055
+ commitUpdate(instance, [reconstruct, diff], type, oldProps, newProps, fiber) {
1056
+ // Reconstruct when args or <primitive object={...} have changes
1057
+ if (reconstruct) switchInstance(instance, type, newProps, fiber); // Otherwise just overwrite props
1058
+ else applyProps$1(instance, diff);
1059
+ },
1060
+
1061
+ hideInstance(instance) {
1062
+ var _instance$__r3f2;
1063
+
1064
+ // Deatch while the instance is hidden
1065
+ const {
1066
+ attach: type,
1067
+ parent
1068
+ } = (_instance$__r3f2 = instance == null ? void 0 : instance.__r3f) != null ? _instance$__r3f2 : {};
1069
+ if (type && parent) detach(parent, instance, type);
1070
+ if (instance.isObject3D) instance.visible = false;
1071
+ invalidateInstance(instance);
1072
+ },
1073
+
1074
+ unhideInstance(instance, props) {
1075
+ var _instance$__r3f3;
1076
+
1077
+ // Re-attach when the instance is unhidden
1078
+ const {
1079
+ attach: type,
1080
+ parent
1081
+ } = (_instance$__r3f3 = instance == null ? void 0 : instance.__r3f) != null ? _instance$__r3f3 : {};
1082
+ if (type && parent) attach(parent, instance, type);
1083
+ if (instance.isObject3D && props.visible == null || props.visible) instance.visible = true;
1084
+ invalidateInstance(instance);
1085
+ },
1086
+
1087
+ createInstance,
1088
+ removeChild,
1089
+ appendChild,
1090
+ appendInitialChild: appendChild,
1091
+ insertBefore,
1092
+ warnsIfNotActing: true,
1093
+ supportsMutation: true,
1094
+ isPrimaryRenderer: false,
1095
+ getCurrentEventPriority: () => getEventPriority ? getEventPriority() : constants.DefaultEventPriority,
1096
+ // @ts-ignore
1097
+ now: is.fun(performance.now) ? performance.now : is.fun(Date.now) ? Date.now : undefined,
1098
+ // @ts-ignore
1099
+ scheduleTimeout: is.fun(setTimeout) ? setTimeout : undefined,
1100
+ // @ts-ignore
1101
+ cancelTimeout: is.fun(clearTimeout) ? clearTimeout : undefined,
1102
+ setTimeout: is.fun(setTimeout) ? setTimeout : undefined,
1103
+ clearTimeout: is.fun(clearTimeout) ? clearTimeout : undefined,
1104
+ noTimeout: -1,
1105
+ hideTextInstance: () => {
1106
+ throw new Error('Text is not allowed in the R3F tree.');
1107
+ },
1108
+ // prettier-ignore
1109
+ getPublicInstance: instance => instance,
1110
+ getRootHostContext: () => null,
1111
+ getChildHostContext: parentHostContext => parentHostContext,
1112
+ createTextInstance: () => {},
1113
+
1114
+ finalizeInitialChildren(instance) {
1115
+ var _instance$__r3f4;
1116
+
1117
+ // https://github.com/facebook/react/issues/20271
1118
+ // Returning true will trigger commitMount
1119
+ const localState = (_instance$__r3f4 = instance == null ? void 0 : instance.__r3f) != null ? _instance$__r3f4 : {};
1120
+ return !!localState.handlers;
1121
+ },
1122
+
1123
+ commitMount(instance)
1124
+ /*, type, props*/
1125
+ {
1126
+ var _instance$__r3f5;
1127
+
1128
+ // https://github.com/facebook/react/issues/20271
1129
+ // This will make sure events are only added once to the central container
1130
+ const localState = (_instance$__r3f5 = instance == null ? void 0 : instance.__r3f) != null ? _instance$__r3f5 : {};
1131
+
1132
+ if (instance.raycast && localState.handlers && localState.eventCount) {
1133
+ instance.__r3f.root.getState().internal.interaction.push(instance);
1134
+ }
1135
+ },
1136
+
1137
+ shouldDeprioritizeSubtree: () => false,
1138
+ prepareForCommit: () => null,
1139
+ preparePortalMount: containerInfo => prepare(containerInfo),
1140
+ resetAfterCommit: () => {},
1141
+ shouldSetTextContent: () => false,
1142
+ clearContainer: () => false,
1143
+ detachDeletedInstance: () => {}
1144
+ });
1145
+ return {
1146
+ reconciler,
1147
+ applyProps: applyProps$1
1148
+ };
1149
+ }
1150
+
1151
+ const isRenderer = def => !!(def != null && def.render);
1152
+ const isOrthographicCamera = def => def && def.isOrthographicCamera;
1153
+ const context = /*#__PURE__*/React__namespace.createContext(null);
1154
+
1155
+ const createStore = (applyProps, invalidate, advance, props) => {
1156
+ const {
1157
+ gl,
1158
+ size,
1159
+ shadows = false,
1160
+ linear = false,
1161
+ flat = false,
1162
+ orthographic = false,
1163
+ frameloop = 'always',
1164
+ dpr = [1, 2],
1165
+ performance,
1166
+ clock = new THREE__namespace.Clock(),
1167
+ raycaster: raycastOptions,
1168
+ camera: cameraOptions,
1169
+ onPointerMissed
1170
+ } = props; // Set shadowmap
1171
+
1172
+ if (shadows) {
1173
+ gl.shadowMap.enabled = true;
1174
+ if (typeof shadows === 'object') Object.assign(gl.shadowMap, shadows);else gl.shadowMap.type = THREE__namespace.PCFSoftShadowMap;
1175
+ } // Set color preferences
1176
+
1177
+
1178
+ if (linear) gl.outputEncoding = THREE__namespace.LinearEncoding;
1179
+ if (flat) gl.toneMapping = THREE__namespace.NoToneMapping; // clock.elapsedTime is updated using advance(timestamp)
1180
+
1181
+ if (frameloop === 'never') {
1182
+ clock.stop();
1183
+ clock.elapsedTime = 0;
1184
+ }
1185
+
1186
+ const rootState = create__default['default']((set, get) => {
1187
+ // Create custom raycaster
1188
+ const raycaster = new THREE__namespace.Raycaster();
1189
+ const {
1190
+ params,
1191
+ ...options
1192
+ } = raycastOptions || {};
1193
+ applyProps(raycaster, {
1194
+ enabled: true,
1195
+ ...options,
1196
+ params: { ...raycaster.params,
1197
+ ...params
1198
+ }
1199
+ }); // Create default camera
1200
+
1201
+ const isCamera = cameraOptions instanceof THREE__namespace.Camera;
1202
+ const camera = isCamera ? cameraOptions : orthographic ? new THREE__namespace.OrthographicCamera(0, 0, 0, 0, 0.1, 1000) : new THREE__namespace.PerspectiveCamera(75, 0, 0.1, 1000);
1203
+
1204
+ if (!isCamera) {
1205
+ camera.position.z = 5;
1206
+ if (cameraOptions) applyProps(camera, cameraOptions); // Always look at center by default
1207
+
1208
+ if (!(cameraOptions != null && cameraOptions.rotation)) camera.lookAt(0, 0, 0);
1209
+ }
1210
+
1211
+ const initialDpr = calculateDpr(dpr);
1212
+ const position = new THREE__namespace.Vector3();
1213
+ const defaultTarget = new THREE__namespace.Vector3();
1214
+ const tempTarget = new THREE__namespace.Vector3();
1215
+
1216
+ function getCurrentViewport(camera = get().camera, target = defaultTarget, size = get().size) {
1217
+ const {
1218
+ width,
1219
+ height
1220
+ } = size;
1221
+ const aspect = width / height;
1222
+ if (target instanceof THREE__namespace.Vector3) tempTarget.copy(target);else tempTarget.set(...target);
1223
+ const distance = camera.getWorldPosition(position).distanceTo(tempTarget);
1224
+
1225
+ if (isOrthographicCamera(camera)) {
1226
+ return {
1227
+ width: width / camera.zoom,
1228
+ height: height / camera.zoom,
1229
+ factor: 1,
1230
+ distance,
1231
+ aspect
1232
+ };
1233
+ } else {
1234
+ const fov = camera.fov * Math.PI / 180; // convert vertical fov to radians
1235
+
1236
+ const h = 2 * Math.tan(fov / 2) * distance; // visible height
1237
+
1238
+ const w = h * (width / height);
1239
+ return {
1240
+ width: w,
1241
+ height: h,
1242
+ factor: width / w,
1243
+ distance,
1244
+ aspect
1245
+ };
1246
+ }
1247
+ }
1248
+
1249
+ let performanceTimeout = undefined;
1250
+
1251
+ const setPerformanceCurrent = current => set(state => ({
1252
+ performance: { ...state.performance,
1253
+ current
1254
+ }
1255
+ })); // Handle frame behavior in WebXR
1256
+
1257
+
1258
+ const handleXRFrame = timestamp => {
1259
+ const state = get();
1260
+ if (state.frameloop === 'never') return;
1261
+ advance(timestamp, true);
1262
+ }; // Toggle render switching on session
1263
+
1264
+
1265
+ const handleSessionChange = () => {
1266
+ gl.xr.enabled = gl.xr.isPresenting;
1267
+ gl.setAnimationLoop(gl.xr.isPresenting ? handleXRFrame : null); // If exiting session, request frame
1268
+
1269
+ if (!gl.xr.isPresenting) invalidate(get());
1270
+ }; // WebXR session manager
1271
+
1272
+
1273
+ const xr = {
1274
+ connect() {
1275
+ gl.xr.addEventListener('sessionstart', handleSessionChange);
1276
+ gl.xr.addEventListener('sessionend', handleSessionChange);
1277
+ },
1278
+
1279
+ disconnect() {
1280
+ gl.xr.removeEventListener('sessionstart', handleSessionChange);
1281
+ gl.xr.removeEventListener('sessionend', handleSessionChange);
1282
+ }
1283
+
1284
+ }; // Subscribe to WebXR session events
1285
+
1286
+ if (gl.xr) xr.connect();
1287
+ return {
1288
+ gl,
1289
+ set,
1290
+ get,
1291
+ invalidate: () => invalidate(get()),
1292
+ advance: (timestamp, runGlobalEffects) => advance(timestamp, runGlobalEffects, get()),
1293
+ linear,
1294
+ flat,
1295
+ scene: prepare(new THREE__namespace.Scene()),
1296
+ camera,
1297
+ controls: null,
1298
+ raycaster,
1299
+ clock,
1300
+ mouse: new THREE__namespace.Vector2(),
1301
+ frameloop,
1302
+ onPointerMissed,
1303
+ performance: {
1304
+ current: 1,
1305
+ min: 0.5,
1306
+ max: 1,
1307
+ debounce: 200,
1308
+ ...performance,
1309
+ regress: () => {
1310
+ const state = get(); // Clear timeout
1311
+
1312
+ if (performanceTimeout) clearTimeout(performanceTimeout); // Set lower bound performance
1313
+
1314
+ if (state.performance.current !== state.performance.min) setPerformanceCurrent(state.performance.min); // Go back to upper bound performance after a while unless something regresses meanwhile
1315
+
1316
+ performanceTimeout = setTimeout(() => setPerformanceCurrent(get().performance.max), state.performance.debounce);
1317
+ }
1318
+ },
1319
+ size: {
1320
+ width: 0,
1321
+ height: 0
1322
+ },
1323
+ viewport: {
1324
+ initialDpr,
1325
+ dpr: initialDpr,
1326
+ width: 0,
1327
+ height: 0,
1328
+ aspect: 0,
1329
+ distance: 0,
1330
+ factor: 0,
1331
+ getCurrentViewport
1332
+ },
1333
+ setSize: (width, height) => {
1334
+ const size = {
1335
+ width,
1336
+ height
1337
+ };
1338
+ set(state => ({
1339
+ size,
1340
+ viewport: { ...state.viewport,
1341
+ ...getCurrentViewport(camera, defaultTarget, size)
1342
+ }
1343
+ }));
1344
+ },
1345
+ setDpr: dpr => set(state => ({
1346
+ viewport: { ...state.viewport,
1347
+ dpr: calculateDpr(dpr)
1348
+ }
1349
+ })),
1350
+ setFrameloop: (frameloop = 'always') => set(() => ({
1351
+ frameloop
1352
+ })),
1353
+ events: {
1354
+ connected: false
1355
+ },
1356
+ internal: {
1357
+ active: false,
1358
+ priority: 0,
1359
+ frames: 0,
1360
+ lastProps: props,
1361
+ lastEvent: /*#__PURE__*/React__namespace.createRef(),
1362
+ interaction: [],
1363
+ hovered: new Map(),
1364
+ subscribers: [],
1365
+ initialClick: [0, 0],
1366
+ initialHits: [],
1367
+ capturedMap: new Map(),
1368
+ xr,
1369
+ subscribe: (ref, priority = 0) => {
1370
+ set(({
1371
+ internal
1372
+ }) => ({
1373
+ internal: { ...internal,
1374
+ // If this subscription was given a priority, it takes rendering into its own hands
1375
+ // For that reason we switch off automatic rendering and increase the manual flag
1376
+ // As long as this flag is positive there can be no internal rendering at all
1377
+ // because there could be multiple render subscriptions
1378
+ priority: internal.priority + (priority > 0 ? 1 : 0),
1379
+ // Register subscriber and sort layers from lowest to highest, meaning,
1380
+ // highest priority renders last (on top of the other frames)
1381
+ subscribers: [...internal.subscribers, {
1382
+ ref,
1383
+ priority
1384
+ }].sort((a, b) => a.priority - b.priority)
1385
+ }
1386
+ }));
1387
+ return () => {
1388
+ set(({
1389
+ internal
1390
+ }) => ({
1391
+ internal: { ...internal,
1392
+ // Decrease manual flag if this subscription had a priority
1393
+ priority: internal.priority - (priority > 0 ? 1 : 0),
1394
+ // Remove subscriber from list
1395
+ subscribers: internal.subscribers.filter(s => s.ref !== ref)
1396
+ }
1397
+ }));
1398
+ };
1399
+ }
1400
+ }
1401
+ };
1402
+ });
1403
+ const state = rootState.getState(); // Resize camera and renderer on changes to size and pixelratio
1404
+
1405
+ let oldSize = state.size;
1406
+ let oldDpr = state.viewport.dpr;
1407
+ rootState.subscribe(() => {
1408
+ const {
1409
+ camera,
1410
+ size,
1411
+ viewport,
1412
+ internal
1413
+ } = rootState.getState();
1414
+
1415
+ if (size !== oldSize || viewport.dpr !== oldDpr) {
1416
+ // https://github.com/pmndrs/react-three-fiber/issues/92
1417
+ // Do not mess with the camera if it belongs to the user
1418
+ if (!camera.manual && !(internal.lastProps.camera instanceof THREE__namespace.Camera)) {
1419
+ if (isOrthographicCamera(camera)) {
1420
+ camera.left = size.width / -2;
1421
+ camera.right = size.width / 2;
1422
+ camera.top = size.height / 2;
1423
+ camera.bottom = size.height / -2;
1424
+ } else {
1425
+ camera.aspect = size.width / size.height;
1426
+ }
1427
+
1428
+ camera.updateProjectionMatrix(); // https://github.com/pmndrs/react-three-fiber/issues/178
1429
+ // Update matrix world since the renderer is a frame late
1430
+
1431
+ camera.updateMatrixWorld();
1432
+ } // Update renderer
1433
+
1434
+
1435
+ gl.setPixelRatio(viewport.dpr);
1436
+ gl.setSize(size.width, size.height);
1437
+ oldSize = size;
1438
+ oldDpr = viewport.dpr;
1439
+ }
1440
+ }); // Update size
1441
+
1442
+ if (size) state.setSize(size.width, size.height); // Invalidate on any change
1443
+
1444
+ rootState.subscribe(state => invalidate(state)); // Return root state
1445
+
1446
+ return rootState;
1447
+ };
1448
+
1449
+ function useStore() {
1450
+ const store = React__namespace.useContext(context);
1451
+ if (!store) throw `R3F hooks can only be used within the Canvas component!`;
1452
+ return store;
1453
+ }
1454
+ function useThree(selector = state => state, equalityFn) {
1455
+ return useStore()(selector, equalityFn);
1456
+ }
1457
+ function useFrame(callback, renderPriority = 0) {
1458
+ const subscribe = useStore().getState().internal.subscribe; // Update ref
1459
+
1460
+ const ref = React__namespace.useRef(callback);
1461
+ React__namespace.useLayoutEffect(() => void (ref.current = callback), [callback]); // Subscribe on mount, unsubscribe on unmount
1462
+
1463
+ React__namespace.useLayoutEffect(() => subscribe(ref, renderPriority), [renderPriority, subscribe]);
1464
+ return null;
1465
+ }
1466
+ function useGraph(object) {
1467
+ return React__namespace.useMemo(() => buildGraph(object), [object]);
1468
+ }
1469
+
1470
+ function loadingFn(extensions, onProgress) {
1471
+ return function (Proto, ...input) {
1472
+ // Construct new loader and run extensions
1473
+ const loader = new Proto();
1474
+ if (extensions) extensions(loader); // Go through the urls and load them
1475
+
1476
+ return Promise.all(input.map(input => new Promise((res, reject) => loader.load(input, data => {
1477
+ if (data.scene) Object.assign(data, buildGraph(data.scene));
1478
+ res(data);
1479
+ }, onProgress, error => reject(`Could not load ${input}: ${error.message}`)))));
1480
+ };
1481
+ }
1482
+
1483
+ function useLoader(Proto, input, extensions, onProgress) {
1484
+ // Use suspense to load async assets
1485
+ const keys = Array.isArray(input) ? input : [input];
1486
+ const results = suspendReact.suspend(loadingFn(extensions, onProgress), [Proto, ...keys], {
1487
+ equal: is.equ
1488
+ }); // Return the object/s
1489
+
1490
+ return Array.isArray(input) ? results : results[0];
1491
+ }
1492
+
1493
+ useLoader.preload = function (Proto, input, extensions) {
1494
+ const keys = Array.isArray(input) ? input : [input];
1495
+ return suspendReact.preload(loadingFn(extensions), [Proto, ...keys]);
1496
+ };
1497
+
1498
+ useLoader.clear = function (Proto, input) {
1499
+ const keys = Array.isArray(input) ? input : [input];
1500
+ return suspendReact.clear([Proto, ...keys]);
1501
+ };
1502
+
1503
+ function createSubs(callback, subs) {
1504
+ const index = subs.length;
1505
+ subs.push(callback);
1506
+ return () => void subs.splice(index, 1);
1507
+ }
1508
+
1509
+ let i;
1510
+ let globalEffects = [];
1511
+ let globalAfterEffects = [];
1512
+ let globalTailEffects = [];
1513
+ const addEffect = callback => createSubs(callback, globalEffects);
1514
+ const addAfterEffect = callback => createSubs(callback, globalAfterEffects);
1515
+ const addTail = callback => createSubs(callback, globalTailEffects);
1516
+
1517
+ function run(effects, timestamp) {
1518
+ for (i = 0; i < effects.length; i++) effects[i](timestamp);
1519
+ }
1520
+
1521
+ function render$1(timestamp, state) {
1522
+ // Run local effects
1523
+ let delta = state.clock.getDelta(); // In frameloop='never' mode, clock times are updated using the provided timestamp
1524
+
1525
+ if (state.frameloop === 'never' && typeof timestamp === 'number') {
1526
+ delta = timestamp - state.clock.elapsedTime;
1527
+ state.clock.oldTime = state.clock.elapsedTime;
1528
+ state.clock.elapsedTime = timestamp;
1529
+ } // Call subscribers (useFrame)
1530
+
1531
+
1532
+ for (i = 0; i < state.internal.subscribers.length; i++) state.internal.subscribers[i].ref.current(state, delta); // Render content
1533
+
1534
+
1535
+ if (!state.internal.priority && state.gl.render) state.gl.render(state.scene, state.camera); // Decrease frame count
1536
+
1537
+ state.internal.frames = Math.max(0, state.internal.frames - 1);
1538
+ return state.frameloop === 'always' ? 1 : state.internal.frames;
1539
+ }
1540
+
1541
+ function createLoop(roots) {
1542
+ let running = false;
1543
+ let repeat;
1544
+
1545
+ function loop(timestamp) {
1546
+ running = true;
1547
+ repeat = 0; // Run effects
1548
+
1549
+ run(globalEffects, timestamp); // Render all roots
1550
+
1551
+ roots.forEach(root => {
1552
+ var _state$gl$xr;
1553
+
1554
+ const state = root.store.getState(); // If the frameloop is invalidated, do not run another frame
1555
+
1556
+ if (state.internal.active && (state.frameloop === 'always' || state.internal.frames > 0) && !((_state$gl$xr = state.gl.xr) != null && _state$gl$xr.isPresenting)) {
1557
+ repeat += render$1(timestamp, state);
1558
+ }
1559
+ }); // Run after-effects
1560
+
1561
+ run(globalAfterEffects, timestamp); // Keep on looping if anything invalidates the frameloop
1562
+
1563
+ if (repeat > 0) return requestAnimationFrame(loop); // Tail call effects, they are called when rendering stops
1564
+ else run(globalTailEffects, timestamp); // Flag end of operation
1565
+
1566
+ running = false;
1567
+ }
1568
+
1569
+ function invalidate(state) {
1570
+ var _state$gl$xr2;
1571
+
1572
+ if (!state) return roots.forEach(root => invalidate(root.store.getState()));
1573
+ if ((_state$gl$xr2 = state.gl.xr) != null && _state$gl$xr2.isPresenting || !state.internal.active || state.frameloop === 'never') return; // Increase frames, do not go higher than 60
1574
+
1575
+ state.internal.frames = Math.min(60, state.internal.frames + 1); // If the render-loop isn't active, start it
1576
+
1577
+ if (!running) {
1578
+ running = true;
1579
+ requestAnimationFrame(loop);
1580
+ }
1581
+ }
1582
+
1583
+ function advance(timestamp, runGlobalEffects = true, state) {
1584
+ if (runGlobalEffects) run(globalEffects, timestamp);
1585
+ if (!state) roots.forEach(root => render$1(timestamp, root.store.getState()));else render$1(timestamp, state);
1586
+ if (runGlobalEffects) run(globalAfterEffects, timestamp);
1587
+ }
1588
+
1589
+ return {
1590
+ loop,
1591
+ invalidate,
1592
+ advance
1593
+ };
1594
+ }
1595
+
1596
+ const roots = new Map();
1597
+ const {
1598
+ invalidate,
1599
+ advance
1600
+ } = createLoop(roots);
1601
+ const {
1602
+ reconciler,
1603
+ applyProps
1604
+ } = createRenderer(roots, getEventPriority);
1605
+
1606
+ const createRendererInstance = (gl, canvas) => {
1607
+ const customRenderer = typeof gl === 'function' ? gl(canvas) : gl;
1608
+ if (isRenderer(customRenderer)) return customRenderer;
1609
+ const renderer = new THREE__namespace.WebGLRenderer({
1610
+ powerPreference: 'high-performance',
1611
+ canvas: canvas,
1612
+ antialias: true,
1613
+ alpha: true,
1614
+ ...gl
1615
+ }); // Set color management
1616
+
1617
+ renderer.outputEncoding = THREE__namespace.sRGBEncoding;
1618
+ renderer.toneMapping = THREE__namespace.ACESFilmicToneMapping; // Set gl props
1619
+
1620
+ if (gl) applyProps(renderer, gl);
1621
+ return renderer;
1622
+ };
1623
+
1624
+ function createRoot(canvas, config) {
1625
+ return {
1626
+ render: element => {
1627
+ var _store;
1628
+
1629
+ let {
1630
+ gl,
1631
+ size,
1632
+ events,
1633
+ onCreated,
1634
+ ...props
1635
+ } = config || {}; // Allow size to take on container bounds initially
1636
+
1637
+ if (!size) {
1638
+ var _canvas$parentElement, _canvas$parentElement2, _canvas$parentElement3, _canvas$parentElement4;
1639
+
1640
+ size = {
1641
+ width: (_canvas$parentElement = (_canvas$parentElement2 = canvas.parentElement) == null ? void 0 : _canvas$parentElement2.clientWidth) != null ? _canvas$parentElement : 0,
1642
+ height: (_canvas$parentElement3 = (_canvas$parentElement4 = canvas.parentElement) == null ? void 0 : _canvas$parentElement4.clientHeight) != null ? _canvas$parentElement3 : 0
1643
+ };
1644
+ }
1645
+
1646
+ let root = roots.get(canvas);
1647
+ let fiber = root == null ? void 0 : root.fiber;
1648
+ let store = root == null ? void 0 : root.store;
1649
+ let state = (_store = store) == null ? void 0 : _store.getState();
1650
+
1651
+ if (fiber && state) {
1652
+ // When a root was found, see if any fundamental props must be changed or exchanged
1653
+ // Check pixelratio
1654
+ if (props.dpr !== undefined && state.viewport.dpr !== calculateDpr(props.dpr)) state.setDpr(props.dpr); // Check size
1655
+
1656
+ if (state.size.width !== size.width || state.size.height !== size.height) state.setSize(size.width, size.height); // Check frameloop
1657
+
1658
+ if (state.frameloop !== props.frameloop) state.setFrameloop(props.frameloop); // For some props we want to reset the entire root
1659
+ // Changes to the color-space
1660
+
1661
+ const linearChanged = props.linear !== state.internal.lastProps.linear;
1662
+
1663
+ if (linearChanged) {
1664
+ unmountComponentAtNode(canvas);
1665
+ fiber = undefined;
1666
+ }
1667
+ }
1668
+
1669
+ if (!fiber) {
1670
+ // If no root has been found, make one
1671
+ // Create gl
1672
+ const glRenderer = createRendererInstance(gl, canvas); // Create store
1673
+
1674
+ store = createStore(applyProps, invalidate, advance, {
1675
+ gl: glRenderer,
1676
+ size,
1677
+ ...props
1678
+ });
1679
+ const state = store.getState(); // Create renderer
1680
+
1681
+ fiber = reconciler.createContainer(store, constants.ConcurrentRoot, false, null); // Map it
1682
+
1683
+ roots.set(canvas, {
1684
+ fiber,
1685
+ store
1686
+ }); // Store events internally
1687
+
1688
+ if (events) state.set({
1689
+ events: events(store)
1690
+ });
1691
+ }
1692
+
1693
+ if (store && fiber) {
1694
+ reconciler.updateContainer( /*#__PURE__*/React__namespace.createElement(Provider, {
1695
+ store: store,
1696
+ element: element,
1697
+ onCreated: onCreated,
1698
+ target: canvas
1699
+ }), fiber, null, () => undefined);
1700
+ return store;
1701
+ } else {
1702
+ throw 'Error creating root!';
1703
+ }
1704
+ },
1705
+ unmount: () => unmountComponentAtNode(canvas)
1706
+ };
1707
+ }
1708
+
1709
+ function render(element, canvas, config = {}) {
1710
+ console.warn('R3F.render is no longer supported in React 18. Use createRoot instead!');
1711
+ return createRoot(canvas, config).render(element);
1712
+ }
1713
+
1714
+ function Provider({
1715
+ store,
1716
+ element,
1717
+ onCreated,
1718
+ target
1719
+ }) {
1720
+ React__namespace.useEffect(() => {
1721
+ const state = store.getState(); // Flag the canvas active, rendering will now begin
1722
+
1723
+ state.set(state => ({
1724
+ internal: { ...state.internal,
1725
+ active: true
1726
+ }
1727
+ })); // Connect events
1728
+
1729
+ state.events.connect == null ? void 0 : state.events.connect(target); // Notifiy that init is completed, the scene graph exists, but nothing has yet rendered
1730
+
1731
+ if (onCreated) onCreated(state); // eslint-disable-next-line react-hooks/exhaustive-deps
1732
+ }, []);
1733
+ return /*#__PURE__*/React__namespace.createElement(context.Provider, {
1734
+ value: store
1735
+ }, element);
1736
+ }
1737
+
1738
+ function unmountComponentAtNode(canvas, callback) {
1739
+ const root = roots.get(canvas);
1740
+ const fiber = root == null ? void 0 : root.fiber;
1741
+
1742
+ if (fiber) {
1743
+ const state = root == null ? void 0 : root.store.getState();
1744
+ if (state) state.internal.active = false;
1745
+ reconciler.updateContainer(null, fiber, null, () => {
1746
+ if (state) {
1747
+ setTimeout(() => {
1748
+ try {
1749
+ var _state$gl, _state$gl$renderLists, _state$gl2, _state$gl3;
1750
+
1751
+ state.events.disconnect == null ? void 0 : state.events.disconnect();
1752
+ (_state$gl = state.gl) == null ? void 0 : (_state$gl$renderLists = _state$gl.renderLists) == null ? void 0 : _state$gl$renderLists.dispose == null ? void 0 : _state$gl$renderLists.dispose();
1753
+ (_state$gl2 = state.gl) == null ? void 0 : _state$gl2.forceContextLoss == null ? void 0 : _state$gl2.forceContextLoss();
1754
+ if ((_state$gl3 = state.gl) != null && _state$gl3.xr) state.internal.xr.disconnect();
1755
+ dispose(state);
1756
+ roots.delete(canvas);
1757
+ if (callback) callback(canvas);
1758
+ } catch (e) {
1759
+ /* ... */
1760
+ }
1761
+ }, 500);
1762
+ }
1763
+ });
1764
+ }
1765
+ }
1766
+
1767
+ const act = React__namespace.unstable_act;
1768
+
1769
+ function createPortal(children, container) {
1770
+ return reconciler.createPortal(children, container, null, null);
1771
+ }
1772
+
1773
+ reconciler.injectIntoDevTools({
1774
+ bundleType: process.env.NODE_ENV === 'production' ? 0 : 1,
1775
+ rendererPackageName: '@react-three/fiber',
1776
+ version: '18.0.0'
1777
+ });
1778
+
1779
+ exports.act = act;
1780
+ exports.addAfterEffect = addAfterEffect;
1781
+ exports.addEffect = addEffect;
1782
+ exports.addTail = addTail;
1783
+ exports.advance = advance;
1784
+ exports.applyProps = applyProps;
1785
+ exports.buildGraph = buildGraph;
1786
+ exports.context = context;
1787
+ exports.createEvents = createEvents;
1788
+ exports.createPortal = createPortal;
1789
+ exports.createRoot = createRoot;
1790
+ exports.dispose = dispose;
1791
+ exports.extend = extend;
1792
+ exports.invalidate = invalidate;
1793
+ exports.is = is;
1794
+ exports.omit = omit;
1795
+ exports.pick = pick;
1796
+ exports.reconciler = reconciler;
1797
+ exports.render = render;
1798
+ exports.roots = roots;
1799
+ exports.threeTypes = threeTypes;
1800
+ exports.unmountComponentAtNode = unmountComponentAtNode;
1801
+ exports.useFrame = useFrame;
1802
+ exports.useGraph = useGraph;
1803
+ exports.useLoader = useLoader;
1804
+ exports.useStore = useStore;
1805
+ exports.useThree = useThree;