@react-three/fiber 9.5.0 → 9.6.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.
Files changed (28) hide show
  1. package/CHANGELOG.md +1198 -1192
  2. package/dist/declarations/src/core/events.d.ts +92 -92
  3. package/dist/declarations/src/core/hooks.d.ts +53 -53
  4. package/dist/declarations/src/core/index.d.ts +13 -13
  5. package/dist/declarations/src/core/loop.d.ts +31 -31
  6. package/dist/declarations/src/core/reconciler.d.ts +50 -50
  7. package/dist/declarations/src/core/renderer.d.ts +89 -89
  8. package/dist/declarations/src/core/store.d.ts +130 -130
  9. package/dist/declarations/src/core/utils.d.ts +262 -262
  10. package/dist/declarations/src/index.d.ts +6 -6
  11. package/dist/declarations/src/native/Canvas.d.ts +13 -13
  12. package/dist/declarations/src/native/events.d.ts +4 -4
  13. package/dist/declarations/src/native.d.ts +6 -6
  14. package/dist/declarations/src/three-types.d.ts +68 -68
  15. package/dist/declarations/src/web/Canvas.d.ts +23 -23
  16. package/dist/declarations/src/web/events.d.ts +4 -4
  17. package/dist/{events-238e0986.cjs.prod.js → events-11ca7a92.cjs.prod.js} +100 -87
  18. package/dist/{events-358c3764.cjs.dev.js → events-508aad4b.cjs.dev.js} +100 -87
  19. package/dist/{events-5a94e5eb.esm.js → events-760a1017.esm.js} +100 -87
  20. package/dist/react-three-fiber.cjs.dev.js +4 -4
  21. package/dist/react-three-fiber.cjs.prod.js +4 -4
  22. package/dist/react-three-fiber.esm.js +5 -5
  23. package/native/dist/react-three-fiber-native.cjs.dev.js +4 -4
  24. package/native/dist/react-three-fiber-native.cjs.prod.js +4 -4
  25. package/native/dist/react-three-fiber-native.esm.js +5 -5
  26. package/native/package.json +5 -5
  27. package/package.json +1 -1
  28. package/readme.md +253 -253
@@ -36,17 +36,17 @@ var threeTypes = /*#__PURE__*/Object.freeze({
36
36
  __proto__: null
37
37
  });
38
38
 
39
- /**
40
- * Returns the instance's initial (outmost) root.
39
+ /**
40
+ * Returns the instance's initial (outmost) root.
41
41
  */
42
42
  function findInitialRoot(instance) {
43
43
  let root = instance.root;
44
44
  while (root.getState().previousRoot) root = root.getState().previousRoot;
45
45
  return root;
46
46
  }
47
- /**
48
- * Safely flush async effects when testing, simulating a legacy root.
49
- * @deprecated Import from React instead. import { act } from 'react'
47
+ /**
48
+ * Safely flush async effects when testing, simulating a legacy root.
49
+ * @deprecated Import from React instead. import { act } from 'react'
50
50
  */
51
51
  // Reference with computed key to break Webpack static analysis
52
52
  // https://github.com/webpack/webpack/issues/14814
@@ -55,14 +55,14 @@ const isOrthographicCamera = def => def && def.isOrthographicCamera;
55
55
  const isRef = obj => obj && obj.hasOwnProperty('current');
56
56
  const isColorRepresentation = value => value != null && (typeof value === 'string' || typeof value === 'number' || value.isColor);
57
57
 
58
- /**
59
- * An SSR-friendly useLayoutEffect.
60
- *
61
- * React currently throws a warning when using useLayoutEffect on the server.
62
- * To get around it, we can conditionally useEffect on the server (no-op) and
63
- * useLayoutEffect elsewhere.
64
- *
65
- * @see https://github.com/facebook/react/issues/14927
58
+ /**
59
+ * An SSR-friendly useLayoutEffect.
60
+ *
61
+ * React currently throws a warning when using useLayoutEffect on the server.
62
+ * To get around it, we can conditionally useEffect on the server (no-op) and
63
+ * useLayoutEffect elsewhere.
64
+ *
65
+ * @see https://github.com/facebook/react/issues/14927
66
66
  */
67
67
  const useIsomorphicLayoutEffect = /* @__PURE__ */((_window$document, _window$navigator) => typeof window !== 'undefined' && (((_window$document = window.document) == null ? void 0 : _window$document.createElement) || ((_window$navigator = window.navigator) == null ? void 0 : _window$navigator.product) === 'ReactNative'))() ? React__namespace.useLayoutEffect : React__namespace.useEffect;
68
68
  function useMutableCallback(fn) {
@@ -70,8 +70,8 @@ function useMutableCallback(fn) {
70
70
  useIsomorphicLayoutEffect(() => void (ref.current = fn), [fn]);
71
71
  return ref;
72
72
  }
73
- /**
74
- * Bridges renderer Context and StrictMode from a primary renderer.
73
+ /**
74
+ * Bridges renderer Context and StrictMode from a primary renderer.
75
75
  */
76
76
  function useBridge() {
77
77
  const fiber = itsFine.useFiber();
@@ -123,8 +123,8 @@ function calculateDpr(dpr) {
123
123
  return Array.isArray(dpr) ? Math.min(Math.max(dpr[0], target), dpr[1]) : dpr;
124
124
  }
125
125
 
126
- /**
127
- * Returns instance root state
126
+ /**
127
+ * Returns instance root state
128
128
  */
129
129
  function getRootState(obj) {
130
130
  var _r3f;
@@ -449,6 +449,19 @@ function applyProps(object, props) {
449
449
  // Otherwise just set single value
450
450
  else target.set(value);
451
451
  }
452
+ // ShaderMaterial uniforms must keep a stable target reference
453
+ else if (root instanceof THREE__namespace.ShaderMaterial && key === 'uniforms' && is.obj(value)) {
454
+ if (!is.obj(root.uniforms)) root.uniforms = {};
455
+ const uniforms = root.uniforms;
456
+ const nextUniforms = value;
457
+ for (const name in nextUniforms) {
458
+ const uniform = nextUniforms[name];
459
+ const targetUniform = uniforms[name];
460
+ if (targetUniform) Object.assign(targetUniform, uniform);else uniforms[name] = {
461
+ ...uniform
462
+ };
463
+ }
464
+ }
452
465
  // Else, just overwrite the value
453
466
  else {
454
467
  var _root$key;
@@ -514,9 +527,9 @@ function makeId(event) {
514
527
  return (event.eventObject || event.object).uuid + '/' + event.index + event.instanceId;
515
528
  }
516
529
 
517
- /**
518
- * Release pointer captures.
519
- * This is called by releasePointerCapture in the API, and when an object is removed.
530
+ /**
531
+ * Release pointer captures.
532
+ * This is called by releasePointerCapture in the API, and when an object is removed.
520
533
  */
521
534
  function releaseInternalPointerCapture(capturedMap, obj, captures, pointerId) {
522
535
  const captureData = captures.get(obj);
@@ -770,7 +783,7 @@ function createEvents(store) {
770
783
  internal
771
784
  } = store.getState();
772
785
  for (const hoveredObj of internal.hovered.values()) {
773
- // When no objects were hit or the the hovered object wasn't found underneath the cursor
786
+ // When no objects were hit or the hovered object wasn't found underneath the cursor
774
787
  // we call onPointerOut and delete the object from the hovered-elements map
775
788
  if (!intersections.length || !intersections.find(hit => hit.object === hoveredObj.object && hit.index === hoveredObj.index && hit.instanceId === hoveredObj.instanceId)) {
776
789
  const eventObject = hoveredObj.eventObject;
@@ -863,19 +876,19 @@ function createEvents(store) {
863
876
  if (!(instance != null && instance.eventCount)) return;
864
877
  const handlers = instance.handlers;
865
878
 
866
- /*
867
- MAYBE TODO, DELETE IF NOT:
868
- Check if the object is captured, captured events should not have intersects running in parallel
869
- But wouldn't it be better to just replace capturedMap with a single entry?
870
- Also, are we OK with straight up making picking up multiple objects impossible?
871
-
872
- const pointerId = (data as ThreeEvent<PointerEvent>).pointerId
873
- if (pointerId !== undefined) {
874
- const capturedMeshSet = internal.capturedMap.get(pointerId)
875
- if (capturedMeshSet) {
876
- const captured = capturedMeshSet.get(eventObject)
877
- if (captured && captured.localState.stopped) return
878
- }
879
+ /*
880
+ MAYBE TODO, DELETE IF NOT:
881
+ Check if the object is captured, captured events should not have intersects running in parallel
882
+ But wouldn't it be better to just replace capturedMap with a single entry?
883
+ Also, are we OK with straight up making picking up multiple objects impossible?
884
+
885
+ const pointerId = (data as ThreeEvent<PointerEvent>).pointerId
886
+ if (pointerId !== undefined) {
887
+ const capturedMeshSet = internal.capturedMap.get(pointerId)
888
+ if (capturedMeshSet) {
889
+ const captured = capturedMeshSet.get(eventObject)
890
+ if (captured && captured.localState.stopped) return
891
+ }
879
892
  }*/
880
893
 
881
894
  if (isPointerMove) {
@@ -1166,11 +1179,11 @@ const createStore = (invalidate, advance) => {
1166
1179
  return rootStore;
1167
1180
  };
1168
1181
 
1169
- /**
1170
- * Exposes an object's {@link Instance}.
1171
- * @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#useInstanceHandle
1172
- *
1173
- * **Note**: this is an escape hatch to react-internal fields. Expect this to change significantly between versions.
1182
+ /**
1183
+ * Exposes an object's {@link Instance}.
1184
+ * @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#useInstanceHandle
1185
+ *
1186
+ * **Note**: this is an escape hatch to react-internal fields. Expect this to change significantly between versions.
1174
1187
  */
1175
1188
  function useInstanceHandle(ref) {
1176
1189
  const instance = React__namespace.useRef(null);
@@ -1178,9 +1191,9 @@ function useInstanceHandle(ref) {
1178
1191
  return instance;
1179
1192
  }
1180
1193
 
1181
- /**
1182
- * Returns the R3F Canvas' Zustand store. Useful for [transient updates](https://github.com/pmndrs/zustand#transient-updates-for-often-occurring-state-changes).
1183
- * @see https://docs.pmnd.rs/react-three-fiber/api/hooks#usestore
1194
+ /**
1195
+ * Returns the R3F Canvas' Zustand store. Useful for [transient updates](https://github.com/pmndrs/zustand#transient-updates-for-often-occurring-state-changes).
1196
+ * @see https://docs.pmnd.rs/react-three-fiber/api/hooks#usestore
1184
1197
  */
1185
1198
  function useStore() {
1186
1199
  const store = React__namespace.useContext(context);
@@ -1188,18 +1201,18 @@ function useStore() {
1188
1201
  return store;
1189
1202
  }
1190
1203
 
1191
- /**
1192
- * Accesses R3F's internal state, containing renderer, canvas, scene, etc.
1193
- * @see https://docs.pmnd.rs/react-three-fiber/api/hooks#usethree
1204
+ /**
1205
+ * Accesses R3F's internal state, containing renderer, canvas, scene, etc.
1206
+ * @see https://docs.pmnd.rs/react-three-fiber/api/hooks#usethree
1194
1207
  */
1195
1208
  function useThree(selector = state => state, equalityFn) {
1196
1209
  return useStore()(selector, equalityFn);
1197
1210
  }
1198
1211
 
1199
- /**
1200
- * Executes a callback before render in a shared frame loop.
1201
- * Can order effects with render priority or manually render with a positive priority.
1202
- * @see https://docs.pmnd.rs/react-three-fiber/api/hooks#useframe
1212
+ /**
1213
+ * Executes a callback before render in a shared frame loop.
1214
+ * Can order effects with render priority or manually render with a positive priority.
1215
+ * @see https://docs.pmnd.rs/react-three-fiber/api/hooks#useframe
1203
1216
  */
1204
1217
  function useFrame(callback, renderPriority = 0) {
1205
1218
  const store = useStore();
@@ -1211,9 +1224,9 @@ function useFrame(callback, renderPriority = 0) {
1211
1224
  return null;
1212
1225
  }
1213
1226
 
1214
- /**
1215
- * Returns a node graph of an object with named nodes & materials.
1216
- * @see https://docs.pmnd.rs/react-three-fiber/api/hooks#usegraph
1227
+ /**
1228
+ * Returns a node graph of an object with named nodes & materials.
1229
+ * @see https://docs.pmnd.rs/react-three-fiber/api/hooks#usegraph
1217
1230
  */
1218
1231
  function useGraph(object) {
1219
1232
  return React__namespace.useMemo(() => buildGraph(object), [object]);
@@ -1249,11 +1262,11 @@ function loadingFn(extensions, onProgress) {
1249
1262
  };
1250
1263
  }
1251
1264
 
1252
- /**
1253
- * Synchronously loads and caches assets with a three loader.
1254
- *
1255
- * Note: this hook's caller must be wrapped with `React.Suspense`
1256
- * @see https://docs.pmnd.rs/react-three-fiber/api/hooks#useloader
1265
+ /**
1266
+ * Synchronously loads and caches assets with a three loader.
1267
+ *
1268
+ * Note: this hook's caller must be wrapped with `React.Suspense`
1269
+ * @see https://docs.pmnd.rs/react-three-fiber/api/hooks#useloader
1257
1270
  */
1258
1271
  function useLoader(loader, input, extensions, onProgress) {
1259
1272
  // Use suspense to load async assets
@@ -1265,16 +1278,16 @@ function useLoader(loader, input, extensions, onProgress) {
1265
1278
  return Array.isArray(input) ? results : results[0];
1266
1279
  }
1267
1280
 
1268
- /**
1269
- * Preloads an asset into cache as a side-effect.
1281
+ /**
1282
+ * Preloads an asset into cache as a side-effect.
1270
1283
  */
1271
1284
  useLoader.preload = function (loader, input, extensions) {
1272
1285
  const keys = Array.isArray(input) ? input : [input];
1273
1286
  return suspendReact.preload(loadingFn(extensions), [loader, ...keys]);
1274
1287
  };
1275
1288
 
1276
- /**
1277
- * Removes a loaded asset from cache.
1289
+ /**
1290
+ * Removes a loaded asset from cache.
1278
1291
  */
1279
1292
  useLoader.clear = function (loader, input) {
1280
1293
  const keys = Array.isArray(input) ? input : [input];
@@ -1296,7 +1309,7 @@ useLoader.clear = function (loader, input) {
1296
1309
 
1297
1310
  var packageData = {
1298
1311
  name: "@react-three/fiber",
1299
- version: "9.5.0",
1312
+ version: "9.6.0",
1300
1313
  description: "A React renderer for Threejs",
1301
1314
  keywords: [
1302
1315
  "react",
@@ -15876,10 +15889,10 @@ function Portal({
15876
15889
  children,
15877
15890
  container
15878
15891
  }) {
15879
- /** This has to be a component because it would not be able to call useThree/useStore otherwise since
15880
- * if this is our environment, then we are not in r3f's renderer but in react-dom, it would trigger
15881
- * the "R3F hooks can only be used within the Canvas component!" warning:
15882
- * <Canvas>
15892
+ /** This has to be a component because it would not be able to call useThree/useStore otherwise since
15893
+ * if this is our environment, then we are not in r3f's renderer but in react-dom, it would trigger
15894
+ * the "R3F hooks can only be used within the Canvas component!" warning:
15895
+ * <Canvas>
15883
15896
  * {createPortal(...)} */
15884
15897
  const {
15885
15898
  events,
@@ -15960,11 +15973,11 @@ function Portal({
15960
15973
  );
15961
15974
  }
15962
15975
 
15963
- /**
15964
- * Force React to flush any updates inside the provided callback synchronously and immediately.
15965
- * All the same caveats documented for react-dom's `flushSync` apply here (see https://react.dev/reference/react-dom/flushSync).
15966
- * Nevertheless, sometimes one needs to render synchronously, for example to keep DOM and 3D changes in lock-step without
15967
- * having to revert to a non-React solution. Note: this will only flush updates within the `Canvas` root.
15976
+ /**
15977
+ * Force React to flush any updates inside the provided callback synchronously and immediately.
15978
+ * All the same caveats documented for react-dom's `flushSync` apply here (see https://react.dev/reference/react-dom/flushSync).
15979
+ * Nevertheless, sometimes one needs to render synchronously, for example to keep DOM and 3D changes in lock-step without
15980
+ * having to revert to a non-React solution. Note: this will only flush updates within the `Canvas` root.
15968
15981
  */
15969
15982
  function flushSync(fn) {
15970
15983
  // @ts-ignore - reconciler types are not maintained
@@ -15982,21 +15995,21 @@ const globalEffects = new Set();
15982
15995
  const globalAfterEffects = new Set();
15983
15996
  const globalTailEffects = new Set();
15984
15997
 
15985
- /**
15986
- * Adds a global render callback which is called each frame.
15987
- * @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#addEffect
15998
+ /**
15999
+ * Adds a global render callback which is called each frame.
16000
+ * @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#addEffect
15988
16001
  */
15989
16002
  const addEffect = callback => createSubs(callback, globalEffects);
15990
16003
 
15991
- /**
15992
- * Adds a global after-render callback which is called each frame.
15993
- * @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#addAfterEffect
16004
+ /**
16005
+ * Adds a global after-render callback which is called each frame.
16006
+ * @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#addAfterEffect
15994
16007
  */
15995
16008
  const addAfterEffect = callback => createSubs(callback, globalAfterEffects);
15996
16009
 
15997
- /**
15998
- * Adds a global callback which is called when rendering stops.
15999
- * @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#addTail
16010
+ /**
16011
+ * Adds a global callback which is called when rendering stops.
16012
+ * @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#addTail
16000
16013
  */
16001
16014
  const addTail = callback => createSubs(callback, globalTailEffects);
16002
16015
  function run(effects, timestamp) {
@@ -16084,9 +16097,9 @@ function loop(timestamp) {
16084
16097
  }
16085
16098
  }
16086
16099
 
16087
- /**
16088
- * Invalidates the view, requesting a frame to be rendered. Will globally invalidate unless passed a root's state.
16089
- * @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#invalidate
16100
+ /**
16101
+ * Invalidates the view, requesting a frame to be rendered. Will globally invalidate unless passed a root's state.
16102
+ * @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#invalidate
16090
16103
  */
16091
16104
  function invalidate(state, frames = 1) {
16092
16105
  var _state$gl$xr2;
@@ -16101,7 +16114,7 @@ function invalidate(state, frames = 1) {
16101
16114
  //called from within a useFrame, it means the user wants an additional frame
16102
16115
  state.internal.frames = 2;
16103
16116
  } else {
16104
- //the user need a new frame, no need to increment further than 1
16117
+ //the user needs a new frame, no need to increment further than 1
16105
16118
  state.internal.frames = 1;
16106
16119
  }
16107
16120
  }
@@ -16113,9 +16126,9 @@ function invalidate(state, frames = 1) {
16113
16126
  }
16114
16127
  }
16115
16128
 
16116
- /**
16117
- * Advances the frameloop and runs render effects, useful for when manually rendering via `frameloop="never"`.
16118
- * @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#advance
16129
+ /**
16130
+ * Advances the frameloop and runs render effects, useful for when manually rendering via `frameloop="never"`.
16131
+ * @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#advance
16119
16132
  */
16120
16133
  function advance(timestamp, runGlobalEffects = true, state, frame) {
16121
16134
  if (runGlobalEffects) flushGlobalEffects('before', timestamp);