@react-three/fiber 8.4.1 → 8.5.0

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.
@@ -1,11 +1,9 @@
1
- import * as React from 'react';
2
- import type { Options as ResizeOptions } from 'react-use-measure';
3
- import { RenderProps } from '../core';
4
- export interface Props extends Omit<RenderProps<HTMLCanvasElement>, 'size'>, React.HTMLAttributes<HTMLDivElement> {
5
- children: React.ReactNode;
6
- fallback?: React.ReactNode;
7
- resize?: ResizeOptions;
8
- eventSource?: HTMLElement;
9
- eventPrefix?: 'offset' | 'client' | 'page' | 'layer' | 'screen';
10
- }
11
- export declare const Canvas: React.ForwardRefExoticComponent<Props & React.RefAttributes<HTMLCanvasElement>>;
1
+ import * as React from 'react';
2
+ import type { Options as ResizeOptions } from 'react-use-measure';
3
+ import { RenderProps } from '../core';
4
+ export interface Props extends Omit<RenderProps<HTMLCanvasElement>, 'size'>, React.HTMLAttributes<HTMLDivElement> {
5
+ children: React.ReactNode;
6
+ fallback?: React.ReactNode;
7
+ resize?: ResizeOptions;
8
+ }
9
+ export declare const Canvas: React.ForwardRefExoticComponent<Props & React.RefAttributes<HTMLCanvasElement>>;
@@ -1,4 +1,4 @@
1
- import { UseBoundStore } from 'zustand';
2
- import { RootState } from '../core/store';
3
- import { EventManager } from '../core/events';
4
- export declare function createPointerEvents(store: UseBoundStore<RootState>): EventManager<HTMLElement>;
1
+ import { UseBoundStore } from 'zustand';
2
+ import { RootState } from '../core/store';
3
+ import { EventManager } from '../core/events';
4
+ export declare function createPointerEvents(store: UseBoundStore<RootState>): EventManager<HTMLElement>;
@@ -869,11 +869,7 @@ function createRenderer(_roots, _getEventPriority) {
869
869
  ...props
870
870
  }, root) {
871
871
  let name = `${type[0].toUpperCase()}${type.slice(1)}`;
872
- let instance; // Auto-attach geometries and materials
873
-
874
- if (attach === undefined) {
875
- if (name.endsWith('Geometry')) attach = 'geometry';else if (name.endsWith('Material')) attach = 'material';
876
- }
872
+ let instance;
877
873
 
878
874
  if (type === 'primitive') {
879
875
  if (props.object === undefined) throw new Error("R3F: Primitives without 'object' are invalid!");
@@ -904,6 +900,11 @@ function createRenderer(_roots, _getEventPriority) {
904
900
  args
905
901
  }
906
902
  });
903
+ } // Auto-attach geometries and materials
904
+
905
+
906
+ if (instance.__r3f.attach === undefined) {
907
+ if (instance instanceof THREE__namespace.BufferGeometry) instance.__r3f.attach = 'geometry';else if (instance instanceof THREE__namespace.Material) instance.__r3f.attach = 'material';
907
908
  } // It should NOT call onUpdate on object instanciation, because it hasn't been added to the
908
909
  // view yet. If the callback relies on references for instance, they won't be ready yet, this is
909
910
  // why it passes "true" here
@@ -1043,13 +1044,13 @@ function createRenderer(_roots, _getEventPriority) {
1043
1044
  const newInstance = createInstance(type, newProps, instance.__r3f.root); // https://github.com/pmndrs/react-three-fiber/issues/1348
1044
1045
  // When args change the instance has to be re-constructed, which then
1045
1046
  // forces r3f to re-parent the children and non-scene objects
1046
- // This can not include primitives, which should not have declarative children
1047
1047
 
1048
- if (type !== 'primitive' && instance.children) {
1049
- instance.children.forEach(child => appendChild(newInstance, child));
1050
- instance.children = [];
1048
+ for (const child of instance.children) {
1049
+ if (child.__r3f) appendChild(newInstance, child);
1051
1050
  }
1052
1051
 
1052
+ instance.children = instance.children.filter(child => !child.__r3f);
1053
+
1053
1054
  instance.__r3f.objects.forEach(child => appendChild(newInstance, child));
1054
1055
 
1055
1056
  instance.__r3f.objects = [];
@@ -1169,11 +1170,11 @@ function createRenderer(_roots, _getEventPriority) {
1169
1170
  hideInstance(instance) {
1170
1171
  var _instance$__r3f4;
1171
1172
 
1172
- // Deatch while the instance is hidden
1173
+ // Detach while the instance is hidden
1173
1174
  const {
1174
1175
  attach: type,
1175
1176
  parent
1176
- } = (_instance$__r3f4 = instance == null ? void 0 : instance.__r3f) != null ? _instance$__r3f4 : {};
1177
+ } = (_instance$__r3f4 = instance.__r3f) != null ? _instance$__r3f4 : {};
1177
1178
  if (type && parent) detach(parent, instance, type);
1178
1179
  if (instance.isObject3D) instance.visible = false;
1179
1180
  invalidateInstance(instance);
@@ -1186,7 +1187,7 @@ function createRenderer(_roots, _getEventPriority) {
1186
1187
  const {
1187
1188
  attach: type,
1188
1189
  parent
1189
- } = (_instance$__r3f5 = instance == null ? void 0 : instance.__r3f) != null ? _instance$__r3f5 : {};
1190
+ } = (_instance$__r3f5 = instance.__r3f) != null ? _instance$__r3f5 : {};
1190
1191
  if (type && parent) attach(parent, instance, type);
1191
1192
  if (instance.isObject3D && props.visible == null || props.visible) instance.visible = true;
1192
1193
  invalidateInstance(instance);
@@ -869,11 +869,7 @@ function createRenderer(_roots, _getEventPriority) {
869
869
  ...props
870
870
  }, root) {
871
871
  let name = `${type[0].toUpperCase()}${type.slice(1)}`;
872
- let instance; // Auto-attach geometries and materials
873
-
874
- if (attach === undefined) {
875
- if (name.endsWith('Geometry')) attach = 'geometry';else if (name.endsWith('Material')) attach = 'material';
876
- }
872
+ let instance;
877
873
 
878
874
  if (type === 'primitive') {
879
875
  if (props.object === undefined) throw new Error("R3F: Primitives without 'object' are invalid!");
@@ -904,6 +900,11 @@ function createRenderer(_roots, _getEventPriority) {
904
900
  args
905
901
  }
906
902
  });
903
+ } // Auto-attach geometries and materials
904
+
905
+
906
+ if (instance.__r3f.attach === undefined) {
907
+ if (instance instanceof THREE__namespace.BufferGeometry) instance.__r3f.attach = 'geometry';else if (instance instanceof THREE__namespace.Material) instance.__r3f.attach = 'material';
907
908
  } // It should NOT call onUpdate on object instanciation, because it hasn't been added to the
908
909
  // view yet. If the callback relies on references for instance, they won't be ready yet, this is
909
910
  // why it passes "true" here
@@ -1043,13 +1044,13 @@ function createRenderer(_roots, _getEventPriority) {
1043
1044
  const newInstance = createInstance(type, newProps, instance.__r3f.root); // https://github.com/pmndrs/react-three-fiber/issues/1348
1044
1045
  // When args change the instance has to be re-constructed, which then
1045
1046
  // forces r3f to re-parent the children and non-scene objects
1046
- // This can not include primitives, which should not have declarative children
1047
1047
 
1048
- if (type !== 'primitive' && instance.children) {
1049
- instance.children.forEach(child => appendChild(newInstance, child));
1050
- instance.children = [];
1048
+ for (const child of instance.children) {
1049
+ if (child.__r3f) appendChild(newInstance, child);
1051
1050
  }
1052
1051
 
1052
+ instance.children = instance.children.filter(child => !child.__r3f);
1053
+
1053
1054
  instance.__r3f.objects.forEach(child => appendChild(newInstance, child));
1054
1055
 
1055
1056
  instance.__r3f.objects = [];
@@ -1169,11 +1170,11 @@ function createRenderer(_roots, _getEventPriority) {
1169
1170
  hideInstance(instance) {
1170
1171
  var _instance$__r3f4;
1171
1172
 
1172
- // Deatch while the instance is hidden
1173
+ // Detach while the instance is hidden
1173
1174
  const {
1174
1175
  attach: type,
1175
1176
  parent
1176
- } = (_instance$__r3f4 = instance == null ? void 0 : instance.__r3f) != null ? _instance$__r3f4 : {};
1177
+ } = (_instance$__r3f4 = instance.__r3f) != null ? _instance$__r3f4 : {};
1177
1178
  if (type && parent) detach(parent, instance, type);
1178
1179
  if (instance.isObject3D) instance.visible = false;
1179
1180
  invalidateInstance(instance);
@@ -1186,7 +1187,7 @@ function createRenderer(_roots, _getEventPriority) {
1186
1187
  const {
1187
1188
  attach: type,
1188
1189
  parent
1189
- } = (_instance$__r3f5 = instance == null ? void 0 : instance.__r3f) != null ? _instance$__r3f5 : {};
1190
+ } = (_instance$__r3f5 = instance.__r3f) != null ? _instance$__r3f5 : {};
1190
1191
  if (type && parent) attach(parent, instance, type);
1191
1192
  if (instance.isObject3D && props.visible == null || props.visible) instance.visible = true;
1192
1193
  invalidateInstance(instance);
@@ -842,11 +842,7 @@ function createRenderer(_roots, _getEventPriority) {
842
842
  ...props
843
843
  }, root) {
844
844
  let name = `${type[0].toUpperCase()}${type.slice(1)}`;
845
- let instance; // Auto-attach geometries and materials
846
-
847
- if (attach === undefined) {
848
- if (name.endsWith('Geometry')) attach = 'geometry';else if (name.endsWith('Material')) attach = 'material';
849
- }
845
+ let instance;
850
846
 
851
847
  if (type === 'primitive') {
852
848
  if (props.object === undefined) throw new Error("R3F: Primitives without 'object' are invalid!");
@@ -877,6 +873,11 @@ function createRenderer(_roots, _getEventPriority) {
877
873
  args
878
874
  }
879
875
  });
876
+ } // Auto-attach geometries and materials
877
+
878
+
879
+ if (instance.__r3f.attach === undefined) {
880
+ if (instance instanceof THREE.BufferGeometry) instance.__r3f.attach = 'geometry';else if (instance instanceof THREE.Material) instance.__r3f.attach = 'material';
880
881
  } // It should NOT call onUpdate on object instanciation, because it hasn't been added to the
881
882
  // view yet. If the callback relies on references for instance, they won't be ready yet, this is
882
883
  // why it passes "true" here
@@ -1016,13 +1017,13 @@ function createRenderer(_roots, _getEventPriority) {
1016
1017
  const newInstance = createInstance(type, newProps, instance.__r3f.root); // https://github.com/pmndrs/react-three-fiber/issues/1348
1017
1018
  // When args change the instance has to be re-constructed, which then
1018
1019
  // forces r3f to re-parent the children and non-scene objects
1019
- // This can not include primitives, which should not have declarative children
1020
1020
 
1021
- if (type !== 'primitive' && instance.children) {
1022
- instance.children.forEach(child => appendChild(newInstance, child));
1023
- instance.children = [];
1021
+ for (const child of instance.children) {
1022
+ if (child.__r3f) appendChild(newInstance, child);
1024
1023
  }
1025
1024
 
1025
+ instance.children = instance.children.filter(child => !child.__r3f);
1026
+
1026
1027
  instance.__r3f.objects.forEach(child => appendChild(newInstance, child));
1027
1028
 
1028
1029
  instance.__r3f.objects = [];
@@ -1142,11 +1143,11 @@ function createRenderer(_roots, _getEventPriority) {
1142
1143
  hideInstance(instance) {
1143
1144
  var _instance$__r3f4;
1144
1145
 
1145
- // Deatch while the instance is hidden
1146
+ // Detach while the instance is hidden
1146
1147
  const {
1147
1148
  attach: type,
1148
1149
  parent
1149
- } = (_instance$__r3f4 = instance == null ? void 0 : instance.__r3f) != null ? _instance$__r3f4 : {};
1150
+ } = (_instance$__r3f4 = instance.__r3f) != null ? _instance$__r3f4 : {};
1150
1151
  if (type && parent) detach(parent, instance, type);
1151
1152
  if (instance.isObject3D) instance.visible = false;
1152
1153
  invalidateInstance(instance);
@@ -1159,7 +1160,7 @@ function createRenderer(_roots, _getEventPriority) {
1159
1160
  const {
1160
1161
  attach: type,
1161
1162
  parent
1162
- } = (_instance$__r3f5 = instance == null ? void 0 : instance.__r3f) != null ? _instance$__r3f5 : {};
1163
+ } = (_instance$__r3f5 = instance.__r3f) != null ? _instance$__r3f5 : {};
1163
1164
  if (type && parent) attach(parent, instance, type);
1164
1165
  if (instance.isObject3D && props.visible == null || props.visible) instance.visible = true;
1165
1166
  invalidateInstance(instance);
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var index = require('./index-bcd3e47c.cjs.dev.js');
5
+ var index = require('./index-2bf2b90e.cjs.dev.js');
6
6
  var _extends = require('@babel/runtime/helpers/extends');
7
7
  var React = require('react');
8
8
  var THREE = require('three');
@@ -126,8 +126,6 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(function Canvas({
126
126
  style,
127
127
  gl,
128
128
  events = createPointerEvents,
129
- eventSource,
130
- eventPrefix,
131
129
  shadows,
132
130
  linear,
133
131
  flat,
@@ -186,21 +184,7 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(function Canvas({
186
184
  // Pass mutable reference to onPointerMissed so it's free to update
187
185
  onPointerMissed: (...args) => handlePointerMissed.current == null ? void 0 : handlePointerMissed.current(...args),
188
186
  onCreated: state => {
189
- // Connect to event source
190
- state.events.connect == null ? void 0 : state.events.connect(eventSource ? eventSource : divRef.current); // Set up compute function
191
-
192
- if (eventPrefix) {
193
- state.setEvents({
194
- compute: (event, state) => {
195
- const x = event[eventPrefix + 'X'];
196
- const y = event[eventPrefix + 'Y'];
197
- state.pointer.set(x / state.size.width * 2 - 1, -(y / state.size.height) * 2 + 1);
198
- state.raycaster.setFromCamera(state.pointer, state.camera);
199
- }
200
- });
201
- } // Call onCreated callback
202
-
203
-
187
+ state.events.connect == null ? void 0 : state.events.connect(divRef.current);
204
188
  onCreated == null ? void 0 : onCreated(state);
205
189
  }
206
190
  });
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var index = require('./index-e086bd20.cjs.prod.js');
5
+ var index = require('./index-aea5c5ce.cjs.prod.js');
6
6
  var _extends = require('@babel/runtime/helpers/extends');
7
7
  var React = require('react');
8
8
  var THREE = require('three');
@@ -126,8 +126,6 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(function Canvas({
126
126
  style,
127
127
  gl,
128
128
  events = createPointerEvents,
129
- eventSource,
130
- eventPrefix,
131
129
  shadows,
132
130
  linear,
133
131
  flat,
@@ -186,21 +184,7 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(function Canvas({
186
184
  // Pass mutable reference to onPointerMissed so it's free to update
187
185
  onPointerMissed: (...args) => handlePointerMissed.current == null ? void 0 : handlePointerMissed.current(...args),
188
186
  onCreated: state => {
189
- // Connect to event source
190
- state.events.connect == null ? void 0 : state.events.connect(eventSource ? eventSource : divRef.current); // Set up compute function
191
-
192
- if (eventPrefix) {
193
- state.setEvents({
194
- compute: (event, state) => {
195
- const x = event[eventPrefix + 'X'];
196
- const y = event[eventPrefix + 'Y'];
197
- state.pointer.set(x / state.size.width * 2 - 1, -(y / state.size.height) * 2 + 1);
198
- state.raycaster.setFromCamera(state.pointer, state.camera);
199
- }
200
- });
201
- } // Call onCreated callback
202
-
203
-
187
+ state.events.connect == null ? void 0 : state.events.connect(divRef.current);
204
188
  onCreated == null ? void 0 : onCreated(state);
205
189
  }
206
190
  });
@@ -1,5 +1,5 @@
1
- import { c as createEvents, e as extend, u as useMutableCallback, a as createRoot, E as ErrorBoundary, B as Block, b as useIsomorphicLayoutEffect, d as unmountComponentAtNode } from './index-212b30d8.esm.js';
2
- export { t as ReactThreeFiber, s as _roots, q as act, n as addAfterEffect, m as addEffect, o as addTail, l as advance, i as applyProps, f as context, c as createEvents, g as createPortal, a as createRoot, j as dispose, e as extend, p as getRootState, k as invalidate, h as reconciler, r as render, d as unmountComponentAtNode, x as useFrame, y as useGraph, z as useLoader, v as useStore, w as useThree } from './index-212b30d8.esm.js';
1
+ import { c as createEvents, e as extend, u as useMutableCallback, a as createRoot, E as ErrorBoundary, B as Block, b as useIsomorphicLayoutEffect, d as unmountComponentAtNode } from './index-ea463076.esm.js';
2
+ export { t as ReactThreeFiber, s as _roots, q as act, n as addAfterEffect, m as addEffect, o as addTail, l as advance, i as applyProps, f as context, c as createEvents, g as createPortal, a as createRoot, j as dispose, e as extend, p as getRootState, k as invalidate, h as reconciler, r as render, d as unmountComponentAtNode, x as useFrame, y as useGraph, z as useLoader, v as useStore, w as useThree } from './index-ea463076.esm.js';
3
3
  import _extends from '@babel/runtime/helpers/esm/extends';
4
4
  import * as React from 'react';
5
5
  import * as THREE from 'three';
@@ -99,8 +99,6 @@ const Canvas = /*#__PURE__*/React.forwardRef(function Canvas({
99
99
  style,
100
100
  gl,
101
101
  events = createPointerEvents,
102
- eventSource,
103
- eventPrefix,
104
102
  shadows,
105
103
  linear,
106
104
  flat,
@@ -159,21 +157,7 @@ const Canvas = /*#__PURE__*/React.forwardRef(function Canvas({
159
157
  // Pass mutable reference to onPointerMissed so it's free to update
160
158
  onPointerMissed: (...args) => handlePointerMissed.current == null ? void 0 : handlePointerMissed.current(...args),
161
159
  onCreated: state => {
162
- // Connect to event source
163
- state.events.connect == null ? void 0 : state.events.connect(eventSource ? eventSource : divRef.current); // Set up compute function
164
-
165
- if (eventPrefix) {
166
- state.setEvents({
167
- compute: (event, state) => {
168
- const x = event[eventPrefix + 'X'];
169
- const y = event[eventPrefix + 'Y'];
170
- state.pointer.set(x / state.size.width * 2 - 1, -(y / state.size.height) * 2 + 1);
171
- state.raycaster.setFromCamera(state.pointer, state.camera);
172
- }
173
- });
174
- } // Call onCreated callback
175
-
176
-
160
+ state.events.connect == null ? void 0 : state.events.connect(divRef.current);
177
161
  onCreated == null ? void 0 : onCreated(state);
178
162
  }
179
163
  });
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var index = require('../../dist/index-bcd3e47c.cjs.dev.js');
5
+ var index = require('../../dist/index-2bf2b90e.cjs.dev.js');
6
6
  var _extends = require('@babel/runtime/helpers/extends');
7
7
  var React = require('react');
8
8
  var THREE = require('three');
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var index = require('../../dist/index-e086bd20.cjs.prod.js');
5
+ var index = require('../../dist/index-aea5c5ce.cjs.prod.js');
6
6
  var _extends = require('@babel/runtime/helpers/extends');
7
7
  var React = require('react');
8
8
  var THREE = require('three');
@@ -1,5 +1,5 @@
1
- import { c as createEvents, e as extend, u as useMutableCallback, a as createRoot, E as ErrorBoundary, B as Block, d as unmountComponentAtNode } from '../../dist/index-212b30d8.esm.js';
2
- export { t as ReactThreeFiber, s as _roots, q as act, n as addAfterEffect, m as addEffect, o as addTail, l as advance, i as applyProps, f as context, g as createPortal, a as createRoot, j as dispose, e as extend, p as getRootState, k as invalidate, h as reconciler, r as render, d as unmountComponentAtNode, x as useFrame, y as useGraph, z as useLoader, v as useStore, w as useThree } from '../../dist/index-212b30d8.esm.js';
1
+ import { c as createEvents, e as extend, u as useMutableCallback, a as createRoot, E as ErrorBoundary, B as Block, d as unmountComponentAtNode } from '../../dist/index-ea463076.esm.js';
2
+ export { t as ReactThreeFiber, s as _roots, q as act, n as addAfterEffect, m as addEffect, o as addTail, l as advance, i as applyProps, f as context, g as createPortal, a as createRoot, j as dispose, e as extend, p as getRootState, k as invalidate, h as reconciler, r as render, d as unmountComponentAtNode, x as useFrame, y as useGraph, z as useLoader, v as useStore, w as useThree } from '../../dist/index-ea463076.esm.js';
3
3
  import _extends from '@babel/runtime/helpers/esm/extends';
4
4
  import * as React from 'react';
5
5
  import * as THREE from 'three';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-three/fiber",
3
- "version": "8.4.1",
3
+ "version": "8.5.0",
4
4
  "description": "A React renderer for Threejs",
5
5
  "keywords": [
6
6
  "react",