@react-three/fiber 9.0.0-rc.5 → 9.0.0-rc.6

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 (31) hide show
  1. package/CHANGELOG.md +1088 -1076
  2. package/dist/declarations/src/core/events.d.ts +91 -91
  3. package/dist/declarations/src/core/hooks.d.ts +51 -51
  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 +52 -52
  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 +186 -186
  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 +62 -62
  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-a7b08b1a.esm.js → events-06bc1550.esm.js} +84 -88
  18. package/dist/{events-b4061ace.cjs.dev.js → events-4464c9d4.cjs.dev.js} +84 -88
  19. package/dist/{events-60ed2d7b.cjs.prod.js → events-79ccf613.cjs.prod.js} +84 -88
  20. package/dist/react-three-fiber.cjs.dev.js +7 -201
  21. package/dist/react-three-fiber.cjs.prod.js +7 -201
  22. package/dist/react-three-fiber.esm.js +6 -201
  23. package/native/dist/react-three-fiber-native.cjs.d.ts +2 -0
  24. package/native/dist/react-three-fiber-native.cjs.dev.js +554 -0
  25. package/native/dist/react-three-fiber-native.cjs.js +7 -0
  26. package/native/dist/react-three-fiber-native.cjs.prod.js +554 -0
  27. package/native/dist/react-three-fiber-native.esm.js +502 -0
  28. package/native/package.json +5 -5
  29. package/package.json +87 -88
  30. package/readme.md +253 -253
  31. package/dist/declarations/src/web/use-measure.d.ts +0 -34
@@ -12,29 +12,29 @@ var threeTypes = /*#__PURE__*/Object.freeze({
12
12
  __proto__: null
13
13
  });
14
14
 
15
- /**
16
- * Returns the instance's initial (outmost) root.
15
+ /**
16
+ * Returns the instance's initial (outmost) root.
17
17
  */
18
18
  function findInitialRoot(instance) {
19
19
  let root = instance.root;
20
20
  while (root.getState().previousRoot) root = root.getState().previousRoot;
21
21
  return root;
22
22
  }
23
- /**
24
- * Safely flush async effects when testing, simulating a legacy root.
23
+ /**
24
+ * Safely flush async effects when testing, simulating a legacy root.
25
25
  */
26
26
  const act = React.act;
27
27
  const isOrthographicCamera = def => def && def.isOrthographicCamera;
28
28
  const isRef = obj => obj && obj.hasOwnProperty('current');
29
29
 
30
- /**
31
- * An SSR-friendly useLayoutEffect.
32
- *
33
- * React currently throws a warning when using useLayoutEffect on the server.
34
- * To get around it, we can conditionally useEffect on the server (no-op) and
35
- * useLayoutEffect elsewhere.
36
- *
37
- * @see https://github.com/facebook/react/issues/14927
30
+ /**
31
+ * An SSR-friendly useLayoutEffect.
32
+ *
33
+ * React currently throws a warning when using useLayoutEffect on the server.
34
+ * To get around it, we can conditionally useEffect on the server (no-op) and
35
+ * useLayoutEffect elsewhere.
36
+ *
37
+ * @see https://github.com/facebook/react/issues/14927
38
38
  */
39
39
  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.useLayoutEffect : React.useEffect;
40
40
  function useMutableCallback(fn) {
@@ -42,8 +42,8 @@ function useMutableCallback(fn) {
42
42
  useIsomorphicLayoutEffect(() => void (ref.current = fn), [fn]);
43
43
  return ref;
44
44
  }
45
- /**
46
- * Bridges renderer Context and StrictMode from a primary renderer.
45
+ /**
46
+ * Bridges renderer Context and StrictMode from a primary renderer.
47
47
  */
48
48
  function useBridge() {
49
49
  const fiber = useFiber();
@@ -95,8 +95,8 @@ function calculateDpr(dpr) {
95
95
  return Array.isArray(dpr) ? Math.min(Math.max(dpr[0], target), dpr[1]) : dpr;
96
96
  }
97
97
 
98
- /**
99
- * Returns instance root state
98
+ /**
99
+ * Returns instance root state
100
100
  */
101
101
  function getRootState(obj) {
102
102
  var _r3f;
@@ -204,10 +204,7 @@ function prepare(target, root, type, props) {
204
204
  handlers: {},
205
205
  isHidden: false
206
206
  };
207
- if (object) {
208
- object.__r3f = instance;
209
- if (type) applyProps(object, instance.props);
210
- }
207
+ if (object) object.__r3f = instance;
211
208
  }
212
209
  return instance;
213
210
  }
@@ -459,9 +456,9 @@ function makeId(event) {
459
456
  return (event.eventObject || event.object).uuid + '/' + event.index + event.instanceId;
460
457
  }
461
458
 
462
- /**
463
- * Release pointer captures.
464
- * This is called by releasePointerCapture in the API, and when an object is removed.
459
+ /**
460
+ * Release pointer captures.
461
+ * This is called by releasePointerCapture in the API, and when an object is removed.
465
462
  */
466
463
  function releaseInternalPointerCapture(capturedMap, obj, captures, pointerId) {
467
464
  const captureData = captures.get(obj);
@@ -796,19 +793,19 @@ function createEvents(store) {
796
793
  if (!(instance != null && instance.eventCount)) return;
797
794
  const handlers = instance.handlers;
798
795
 
799
- /*
800
- MAYBE TODO, DELETE IF NOT:
801
- Check if the object is captured, captured events should not have intersects running in parallel
802
- But wouldn't it be better to just replace capturedMap with a single entry?
803
- Also, are we OK with straight up making picking up multiple objects impossible?
804
-
805
- const pointerId = (data as ThreeEvent<PointerEvent>).pointerId
806
- if (pointerId !== undefined) {
807
- const capturedMeshSet = internal.capturedMap.get(pointerId)
808
- if (capturedMeshSet) {
809
- const captured = capturedMeshSet.get(eventObject)
810
- if (captured && captured.localState.stopped) return
811
- }
796
+ /*
797
+ MAYBE TODO, DELETE IF NOT:
798
+ Check if the object is captured, captured events should not have intersects running in parallel
799
+ But wouldn't it be better to just replace capturedMap with a single entry?
800
+ Also, are we OK with straight up making picking up multiple objects impossible?
801
+
802
+ const pointerId = (data as ThreeEvent<PointerEvent>).pointerId
803
+ if (pointerId !== undefined) {
804
+ const capturedMeshSet = internal.capturedMap.get(pointerId)
805
+ if (capturedMeshSet) {
806
+ const captured = capturedMeshSet.get(eventObject)
807
+ if (captured && captured.localState.stopped) return
808
+ }
812
809
  }*/
813
810
 
814
811
  if (isPointerMove) {
@@ -1099,11 +1096,11 @@ const createStore = (invalidate, advance) => {
1099
1096
  return rootStore;
1100
1097
  };
1101
1098
 
1102
- /**
1103
- * Exposes an object's {@link Instance}.
1104
- * @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#useInstanceHandle
1105
- *
1106
- * **Note**: this is an escape hatch to react-internal fields. Expect this to change significantly between versions.
1099
+ /**
1100
+ * Exposes an object's {@link Instance}.
1101
+ * @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#useInstanceHandle
1102
+ *
1103
+ * **Note**: this is an escape hatch to react-internal fields. Expect this to change significantly between versions.
1107
1104
  */
1108
1105
  function useInstanceHandle(ref) {
1109
1106
  const instance = React.useRef(null);
@@ -1111,9 +1108,9 @@ function useInstanceHandle(ref) {
1111
1108
  return instance;
1112
1109
  }
1113
1110
 
1114
- /**
1115
- * Returns the R3F Canvas' Zustand store. Useful for [transient updates](https://github.com/pmndrs/zustand#transient-updates-for-often-occurring-state-changes).
1116
- * @see https://docs.pmnd.rs/react-three-fiber/api/hooks#usestore
1111
+ /**
1112
+ * Returns the R3F Canvas' Zustand store. Useful for [transient updates](https://github.com/pmndrs/zustand#transient-updates-for-often-occurring-state-changes).
1113
+ * @see https://docs.pmnd.rs/react-three-fiber/api/hooks#usestore
1117
1114
  */
1118
1115
  function useStore() {
1119
1116
  const store = React.useContext(context);
@@ -1121,18 +1118,18 @@ function useStore() {
1121
1118
  return store;
1122
1119
  }
1123
1120
 
1124
- /**
1125
- * Accesses R3F's internal state, containing renderer, canvas, scene, etc.
1126
- * @see https://docs.pmnd.rs/react-three-fiber/api/hooks#usethree
1121
+ /**
1122
+ * Accesses R3F's internal state, containing renderer, canvas, scene, etc.
1123
+ * @see https://docs.pmnd.rs/react-three-fiber/api/hooks#usethree
1127
1124
  */
1128
1125
  function useThree(selector = state => state, equalityFn) {
1129
1126
  return useStore()(selector, equalityFn);
1130
1127
  }
1131
1128
 
1132
- /**
1133
- * Executes a callback before render in a shared frame loop.
1134
- * Can order effects with render priority or manually render with a positive priority.
1135
- * @see https://docs.pmnd.rs/react-three-fiber/api/hooks#useframe
1129
+ /**
1130
+ * Executes a callback before render in a shared frame loop.
1131
+ * Can order effects with render priority or manually render with a positive priority.
1132
+ * @see https://docs.pmnd.rs/react-three-fiber/api/hooks#useframe
1136
1133
  */
1137
1134
  function useFrame(callback, renderPriority = 0) {
1138
1135
  const store = useStore();
@@ -1144,9 +1141,9 @@ function useFrame(callback, renderPriority = 0) {
1144
1141
  return null;
1145
1142
  }
1146
1143
 
1147
- /**
1148
- * Returns a node graph of an object with named nodes & materials.
1149
- * @see https://docs.pmnd.rs/react-three-fiber/api/hooks#usegraph
1144
+ /**
1145
+ * Returns a node graph of an object with named nodes & materials.
1146
+ * @see https://docs.pmnd.rs/react-three-fiber/api/hooks#usegraph
1150
1147
  */
1151
1148
  function useGraph(object) {
1152
1149
  return React.useMemo(() => buildGraph(object), [object]);
@@ -1182,11 +1179,11 @@ function loadingFn(extensions, onProgress) {
1182
1179
  };
1183
1180
  }
1184
1181
 
1185
- /**
1186
- * Synchronously loads and caches assets with a three loader.
1187
- *
1188
- * Note: this hook's caller must be wrapped with `React.Suspense`
1189
- * @see https://docs.pmnd.rs/react-three-fiber/api/hooks#useloader
1182
+ /**
1183
+ * Synchronously loads and caches assets with a three loader.
1184
+ *
1185
+ * Note: this hook's caller must be wrapped with `React.Suspense`
1186
+ * @see https://docs.pmnd.rs/react-three-fiber/api/hooks#useloader
1190
1187
  */
1191
1188
  function useLoader(loader, input, extensions, onProgress) {
1192
1189
  // Use suspense to load async assets
@@ -1198,16 +1195,16 @@ function useLoader(loader, input, extensions, onProgress) {
1198
1195
  return Array.isArray(input) ? results : results[0];
1199
1196
  }
1200
1197
 
1201
- /**
1202
- * Preloads an asset into cache as a side-effect.
1198
+ /**
1199
+ * Preloads an asset into cache as a side-effect.
1203
1200
  */
1204
1201
  useLoader.preload = function (loader, input, extensions) {
1205
1202
  const keys = Array.isArray(input) ? input : [input];
1206
1203
  return preload(loadingFn(extensions), [loader, ...keys]);
1207
1204
  };
1208
1205
 
1209
- /**
1210
- * Removes a loaded asset from cache.
1206
+ /**
1207
+ * Removes a loaded asset from cache.
1211
1208
  */
1212
1209
  useLoader.clear = function (loader, input) {
1213
1210
  const keys = Array.isArray(input) ? input : [input];
@@ -1309,11 +1306,11 @@ function handleContainerEffects(parent, child, beforeChild) {
1309
1306
  // Create object
1310
1307
  child.object = (_child$props$object = child.props.object) != null ? _child$props$object : new target(...((_child$props$args = child.props.args) != null ? _child$props$args : []));
1311
1308
  child.object.__r3f = child;
1312
-
1313
- // Set initial props
1314
- applyProps(child.object, child.props);
1315
1309
  }
1316
1310
 
1311
+ // Set initial props
1312
+ applyProps(child.object, child.props);
1313
+
1317
1314
  // Append instance
1318
1315
  if (child.props.attach) {
1319
1316
  attach(parent, child);
@@ -1325,7 +1322,6 @@ function handleContainerEffects(parent, child, beforeChild) {
1325
1322
  child.object.dispatchEvent({
1326
1323
  type: 'added'
1327
1324
  });
1328
- // expect-error https://github.com/mrdoob/three.js/pull/16934
1329
1325
  parent.object.dispatchEvent({
1330
1326
  type: 'childadded',
1331
1327
  child: child.object
@@ -2022,10 +2018,10 @@ function Portal({
2022
2018
  children,
2023
2019
  container
2024
2020
  }) {
2025
- /** This has to be a component because it would not be able to call useThree/useStore otherwise since
2026
- * if this is our environment, then we are not in r3f's renderer but in react-dom, it would trigger
2027
- * the "R3F hooks can only be used within the Canvas component!" warning:
2028
- * <Canvas>
2021
+ /** This has to be a component because it would not be able to call useThree/useStore otherwise since
2022
+ * if this is our environment, then we are not in r3f's renderer but in react-dom, it would trigger
2023
+ * the "R3F hooks can only be used within the Canvas component!" warning:
2024
+ * <Canvas>
2029
2025
  * {createPortal(...)} */
2030
2026
  const {
2031
2027
  events,
@@ -2117,21 +2113,21 @@ const globalEffects = new Set();
2117
2113
  const globalAfterEffects = new Set();
2118
2114
  const globalTailEffects = new Set();
2119
2115
 
2120
- /**
2121
- * Adds a global render callback which is called each frame.
2122
- * @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#addEffect
2116
+ /**
2117
+ * Adds a global render callback which is called each frame.
2118
+ * @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#addEffect
2123
2119
  */
2124
2120
  const addEffect = callback => createSubs(callback, globalEffects);
2125
2121
 
2126
- /**
2127
- * Adds a global after-render callback which is called each frame.
2128
- * @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#addAfterEffect
2122
+ /**
2123
+ * Adds a global after-render callback which is called each frame.
2124
+ * @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#addAfterEffect
2129
2125
  */
2130
2126
  const addAfterEffect = callback => createSubs(callback, globalAfterEffects);
2131
2127
 
2132
- /**
2133
- * Adds a global callback which is called when rendering stops.
2134
- * @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#addTail
2128
+ /**
2129
+ * Adds a global callback which is called when rendering stops.
2130
+ * @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#addTail
2135
2131
  */
2136
2132
  const addTail = callback => createSubs(callback, globalTailEffects);
2137
2133
  function run(effects, timestamp) {
@@ -2203,7 +2199,7 @@ function loop(timestamp) {
2203
2199
  repeat += update(timestamp, state);
2204
2200
  }
2205
2201
  }
2206
- useFrameInProgress = true;
2202
+ useFrameInProgress = false;
2207
2203
 
2208
2204
  // Run after-effects
2209
2205
  flushGlobalEffects('after', timestamp);
@@ -2219,9 +2215,9 @@ function loop(timestamp) {
2219
2215
  }
2220
2216
  }
2221
2217
 
2222
- /**
2223
- * Invalidates the view, requesting a frame to be rendered. Will globally invalidate unless passed a root's state.
2224
- * @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#invalidate
2218
+ /**
2219
+ * Invalidates the view, requesting a frame to be rendered. Will globally invalidate unless passed a root's state.
2220
+ * @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#invalidate
2225
2221
  */
2226
2222
  function invalidate(state, frames = 1) {
2227
2223
  var _state$gl$xr2;
@@ -2248,9 +2244,9 @@ function invalidate(state, frames = 1) {
2248
2244
  }
2249
2245
  }
2250
2246
 
2251
- /**
2252
- * Advances the frameloop and runs render effects, useful for when manually rendering via `frameloop="never"`.
2253
- * @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#advance
2247
+ /**
2248
+ * Advances the frameloop and runs render effects, useful for when manually rendering via `frameloop="never"`.
2249
+ * @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#advance
2254
2250
  */
2255
2251
  function advance(timestamp, runGlobalEffects = true, state, frame) {
2256
2252
  if (runGlobalEffects) flushGlobalEffects('before', timestamp);
@@ -2282,7 +2278,7 @@ function createPointerEvents(store) {
2282
2278
  compute(event, state, previous) {
2283
2279
  // https://github.com/pmndrs/react-three-fiber/pull/782
2284
2280
  // Events trigger outside of canvas when moved, use offsetX/Y by default and allow overrides
2285
- state.pointer.set(event.offsetX / state.size.width * 2 - 1, -(event.offsetY / state.size.height) * 2 + 1);
2281
+ state.pointer.set((event.offsetX - state.size.left) / state.size.width * 2 - 1, -((event.offsetY - state.size.top) / state.size.height) * 2 + 1);
2286
2282
  state.raycaster.setFromCamera(state.pointer, state.camera);
2287
2283
  },
2288
2284
  connected: undefined,
@@ -38,29 +38,29 @@ var threeTypes = /*#__PURE__*/Object.freeze({
38
38
  __proto__: null
39
39
  });
40
40
 
41
- /**
42
- * Returns the instance's initial (outmost) root.
41
+ /**
42
+ * Returns the instance's initial (outmost) root.
43
43
  */
44
44
  function findInitialRoot(instance) {
45
45
  let root = instance.root;
46
46
  while (root.getState().previousRoot) root = root.getState().previousRoot;
47
47
  return root;
48
48
  }
49
- /**
50
- * Safely flush async effects when testing, simulating a legacy root.
49
+ /**
50
+ * Safely flush async effects when testing, simulating a legacy root.
51
51
  */
52
52
  const act = React__namespace.act;
53
53
  const isOrthographicCamera = def => def && def.isOrthographicCamera;
54
54
  const isRef = obj => obj && obj.hasOwnProperty('current');
55
55
 
56
- /**
57
- * An SSR-friendly useLayoutEffect.
58
- *
59
- * React currently throws a warning when using useLayoutEffect on the server.
60
- * To get around it, we can conditionally useEffect on the server (no-op) and
61
- * useLayoutEffect elsewhere.
62
- *
63
- * @see https://github.com/facebook/react/issues/14927
56
+ /**
57
+ * An SSR-friendly useLayoutEffect.
58
+ *
59
+ * React currently throws a warning when using useLayoutEffect on the server.
60
+ * To get around it, we can conditionally useEffect on the server (no-op) and
61
+ * useLayoutEffect elsewhere.
62
+ *
63
+ * @see https://github.com/facebook/react/issues/14927
64
64
  */
65
65
  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;
66
66
  function useMutableCallback(fn) {
@@ -68,8 +68,8 @@ function useMutableCallback(fn) {
68
68
  useIsomorphicLayoutEffect(() => void (ref.current = fn), [fn]);
69
69
  return ref;
70
70
  }
71
- /**
72
- * Bridges renderer Context and StrictMode from a primary renderer.
71
+ /**
72
+ * Bridges renderer Context and StrictMode from a primary renderer.
73
73
  */
74
74
  function useBridge() {
75
75
  const fiber = itsFine.useFiber();
@@ -121,8 +121,8 @@ function calculateDpr(dpr) {
121
121
  return Array.isArray(dpr) ? Math.min(Math.max(dpr[0], target), dpr[1]) : dpr;
122
122
  }
123
123
 
124
- /**
125
- * Returns instance root state
124
+ /**
125
+ * Returns instance root state
126
126
  */
127
127
  function getRootState(obj) {
128
128
  var _r3f;
@@ -230,10 +230,7 @@ function prepare(target, root, type, props) {
230
230
  handlers: {},
231
231
  isHidden: false
232
232
  };
233
- if (object) {
234
- object.__r3f = instance;
235
- if (type) applyProps(object, instance.props);
236
- }
233
+ if (object) object.__r3f = instance;
237
234
  }
238
235
  return instance;
239
236
  }
@@ -485,9 +482,9 @@ function makeId(event) {
485
482
  return (event.eventObject || event.object).uuid + '/' + event.index + event.instanceId;
486
483
  }
487
484
 
488
- /**
489
- * Release pointer captures.
490
- * This is called by releasePointerCapture in the API, and when an object is removed.
485
+ /**
486
+ * Release pointer captures.
487
+ * This is called by releasePointerCapture in the API, and when an object is removed.
491
488
  */
492
489
  function releaseInternalPointerCapture(capturedMap, obj, captures, pointerId) {
493
490
  const captureData = captures.get(obj);
@@ -822,19 +819,19 @@ function createEvents(store) {
822
819
  if (!(instance != null && instance.eventCount)) return;
823
820
  const handlers = instance.handlers;
824
821
 
825
- /*
826
- MAYBE TODO, DELETE IF NOT:
827
- Check if the object is captured, captured events should not have intersects running in parallel
828
- But wouldn't it be better to just replace capturedMap with a single entry?
829
- Also, are we OK with straight up making picking up multiple objects impossible?
830
-
831
- const pointerId = (data as ThreeEvent<PointerEvent>).pointerId
832
- if (pointerId !== undefined) {
833
- const capturedMeshSet = internal.capturedMap.get(pointerId)
834
- if (capturedMeshSet) {
835
- const captured = capturedMeshSet.get(eventObject)
836
- if (captured && captured.localState.stopped) return
837
- }
822
+ /*
823
+ MAYBE TODO, DELETE IF NOT:
824
+ Check if the object is captured, captured events should not have intersects running in parallel
825
+ But wouldn't it be better to just replace capturedMap with a single entry?
826
+ Also, are we OK with straight up making picking up multiple objects impossible?
827
+
828
+ const pointerId = (data as ThreeEvent<PointerEvent>).pointerId
829
+ if (pointerId !== undefined) {
830
+ const capturedMeshSet = internal.capturedMap.get(pointerId)
831
+ if (capturedMeshSet) {
832
+ const captured = capturedMeshSet.get(eventObject)
833
+ if (captured && captured.localState.stopped) return
834
+ }
838
835
  }*/
839
836
 
840
837
  if (isPointerMove) {
@@ -1125,11 +1122,11 @@ const createStore = (invalidate, advance) => {
1125
1122
  return rootStore;
1126
1123
  };
1127
1124
 
1128
- /**
1129
- * Exposes an object's {@link Instance}.
1130
- * @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#useInstanceHandle
1131
- *
1132
- * **Note**: this is an escape hatch to react-internal fields. Expect this to change significantly between versions.
1125
+ /**
1126
+ * Exposes an object's {@link Instance}.
1127
+ * @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#useInstanceHandle
1128
+ *
1129
+ * **Note**: this is an escape hatch to react-internal fields. Expect this to change significantly between versions.
1133
1130
  */
1134
1131
  function useInstanceHandle(ref) {
1135
1132
  const instance = React__namespace.useRef(null);
@@ -1137,9 +1134,9 @@ function useInstanceHandle(ref) {
1137
1134
  return instance;
1138
1135
  }
1139
1136
 
1140
- /**
1141
- * Returns the R3F Canvas' Zustand store. Useful for [transient updates](https://github.com/pmndrs/zustand#transient-updates-for-often-occurring-state-changes).
1142
- * @see https://docs.pmnd.rs/react-three-fiber/api/hooks#usestore
1137
+ /**
1138
+ * Returns the R3F Canvas' Zustand store. Useful for [transient updates](https://github.com/pmndrs/zustand#transient-updates-for-often-occurring-state-changes).
1139
+ * @see https://docs.pmnd.rs/react-three-fiber/api/hooks#usestore
1143
1140
  */
1144
1141
  function useStore() {
1145
1142
  const store = React__namespace.useContext(context);
@@ -1147,18 +1144,18 @@ function useStore() {
1147
1144
  return store;
1148
1145
  }
1149
1146
 
1150
- /**
1151
- * Accesses R3F's internal state, containing renderer, canvas, scene, etc.
1152
- * @see https://docs.pmnd.rs/react-three-fiber/api/hooks#usethree
1147
+ /**
1148
+ * Accesses R3F's internal state, containing renderer, canvas, scene, etc.
1149
+ * @see https://docs.pmnd.rs/react-three-fiber/api/hooks#usethree
1153
1150
  */
1154
1151
  function useThree(selector = state => state, equalityFn) {
1155
1152
  return useStore()(selector, equalityFn);
1156
1153
  }
1157
1154
 
1158
- /**
1159
- * Executes a callback before render in a shared frame loop.
1160
- * Can order effects with render priority or manually render with a positive priority.
1161
- * @see https://docs.pmnd.rs/react-three-fiber/api/hooks#useframe
1155
+ /**
1156
+ * Executes a callback before render in a shared frame loop.
1157
+ * Can order effects with render priority or manually render with a positive priority.
1158
+ * @see https://docs.pmnd.rs/react-three-fiber/api/hooks#useframe
1162
1159
  */
1163
1160
  function useFrame(callback, renderPriority = 0) {
1164
1161
  const store = useStore();
@@ -1170,9 +1167,9 @@ function useFrame(callback, renderPriority = 0) {
1170
1167
  return null;
1171
1168
  }
1172
1169
 
1173
- /**
1174
- * Returns a node graph of an object with named nodes & materials.
1175
- * @see https://docs.pmnd.rs/react-three-fiber/api/hooks#usegraph
1170
+ /**
1171
+ * Returns a node graph of an object with named nodes & materials.
1172
+ * @see https://docs.pmnd.rs/react-three-fiber/api/hooks#usegraph
1176
1173
  */
1177
1174
  function useGraph(object) {
1178
1175
  return React__namespace.useMemo(() => buildGraph(object), [object]);
@@ -1208,11 +1205,11 @@ function loadingFn(extensions, onProgress) {
1208
1205
  };
1209
1206
  }
1210
1207
 
1211
- /**
1212
- * Synchronously loads and caches assets with a three loader.
1213
- *
1214
- * Note: this hook's caller must be wrapped with `React.Suspense`
1215
- * @see https://docs.pmnd.rs/react-three-fiber/api/hooks#useloader
1208
+ /**
1209
+ * Synchronously loads and caches assets with a three loader.
1210
+ *
1211
+ * Note: this hook's caller must be wrapped with `React.Suspense`
1212
+ * @see https://docs.pmnd.rs/react-three-fiber/api/hooks#useloader
1216
1213
  */
1217
1214
  function useLoader(loader, input, extensions, onProgress) {
1218
1215
  // Use suspense to load async assets
@@ -1224,16 +1221,16 @@ function useLoader(loader, input, extensions, onProgress) {
1224
1221
  return Array.isArray(input) ? results : results[0];
1225
1222
  }
1226
1223
 
1227
- /**
1228
- * Preloads an asset into cache as a side-effect.
1224
+ /**
1225
+ * Preloads an asset into cache as a side-effect.
1229
1226
  */
1230
1227
  useLoader.preload = function (loader, input, extensions) {
1231
1228
  const keys = Array.isArray(input) ? input : [input];
1232
1229
  return suspendReact.preload(loadingFn(extensions), [loader, ...keys]);
1233
1230
  };
1234
1231
 
1235
- /**
1236
- * Removes a loaded asset from cache.
1232
+ /**
1233
+ * Removes a loaded asset from cache.
1237
1234
  */
1238
1235
  useLoader.clear = function (loader, input) {
1239
1236
  const keys = Array.isArray(input) ? input : [input];
@@ -1335,11 +1332,11 @@ function handleContainerEffects(parent, child, beforeChild) {
1335
1332
  // Create object
1336
1333
  child.object = (_child$props$object = child.props.object) != null ? _child$props$object : new target(...((_child$props$args = child.props.args) != null ? _child$props$args : []));
1337
1334
  child.object.__r3f = child;
1338
-
1339
- // Set initial props
1340
- applyProps(child.object, child.props);
1341
1335
  }
1342
1336
 
1337
+ // Set initial props
1338
+ applyProps(child.object, child.props);
1339
+
1343
1340
  // Append instance
1344
1341
  if (child.props.attach) {
1345
1342
  attach(parent, child);
@@ -1351,7 +1348,6 @@ function handleContainerEffects(parent, child, beforeChild) {
1351
1348
  child.object.dispatchEvent({
1352
1349
  type: 'added'
1353
1350
  });
1354
- // expect-error https://github.com/mrdoob/three.js/pull/16934
1355
1351
  parent.object.dispatchEvent({
1356
1352
  type: 'childadded',
1357
1353
  child: child.object
@@ -2048,10 +2044,10 @@ function Portal({
2048
2044
  children,
2049
2045
  container
2050
2046
  }) {
2051
- /** This has to be a component because it would not be able to call useThree/useStore otherwise since
2052
- * if this is our environment, then we are not in r3f's renderer but in react-dom, it would trigger
2053
- * the "R3F hooks can only be used within the Canvas component!" warning:
2054
- * <Canvas>
2047
+ /** This has to be a component because it would not be able to call useThree/useStore otherwise since
2048
+ * if this is our environment, then we are not in r3f's renderer but in react-dom, it would trigger
2049
+ * the "R3F hooks can only be used within the Canvas component!" warning:
2050
+ * <Canvas>
2055
2051
  * {createPortal(...)} */
2056
2052
  const {
2057
2053
  events,
@@ -2143,21 +2139,21 @@ const globalEffects = new Set();
2143
2139
  const globalAfterEffects = new Set();
2144
2140
  const globalTailEffects = new Set();
2145
2141
 
2146
- /**
2147
- * Adds a global render callback which is called each frame.
2148
- * @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#addEffect
2142
+ /**
2143
+ * Adds a global render callback which is called each frame.
2144
+ * @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#addEffect
2149
2145
  */
2150
2146
  const addEffect = callback => createSubs(callback, globalEffects);
2151
2147
 
2152
- /**
2153
- * Adds a global after-render callback which is called each frame.
2154
- * @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#addAfterEffect
2148
+ /**
2149
+ * Adds a global after-render callback which is called each frame.
2150
+ * @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#addAfterEffect
2155
2151
  */
2156
2152
  const addAfterEffect = callback => createSubs(callback, globalAfterEffects);
2157
2153
 
2158
- /**
2159
- * Adds a global callback which is called when rendering stops.
2160
- * @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#addTail
2154
+ /**
2155
+ * Adds a global callback which is called when rendering stops.
2156
+ * @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#addTail
2161
2157
  */
2162
2158
  const addTail = callback => createSubs(callback, globalTailEffects);
2163
2159
  function run(effects, timestamp) {
@@ -2229,7 +2225,7 @@ function loop(timestamp) {
2229
2225
  repeat += update(timestamp, state);
2230
2226
  }
2231
2227
  }
2232
- useFrameInProgress = true;
2228
+ useFrameInProgress = false;
2233
2229
 
2234
2230
  // Run after-effects
2235
2231
  flushGlobalEffects('after', timestamp);
@@ -2245,9 +2241,9 @@ function loop(timestamp) {
2245
2241
  }
2246
2242
  }
2247
2243
 
2248
- /**
2249
- * Invalidates the view, requesting a frame to be rendered. Will globally invalidate unless passed a root's state.
2250
- * @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#invalidate
2244
+ /**
2245
+ * Invalidates the view, requesting a frame to be rendered. Will globally invalidate unless passed a root's state.
2246
+ * @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#invalidate
2251
2247
  */
2252
2248
  function invalidate(state, frames = 1) {
2253
2249
  var _state$gl$xr2;
@@ -2274,9 +2270,9 @@ function invalidate(state, frames = 1) {
2274
2270
  }
2275
2271
  }
2276
2272
 
2277
- /**
2278
- * Advances the frameloop and runs render effects, useful for when manually rendering via `frameloop="never"`.
2279
- * @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#advance
2273
+ /**
2274
+ * Advances the frameloop and runs render effects, useful for when manually rendering via `frameloop="never"`.
2275
+ * @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#advance
2280
2276
  */
2281
2277
  function advance(timestamp, runGlobalEffects = true, state, frame) {
2282
2278
  if (runGlobalEffects) flushGlobalEffects('before', timestamp);
@@ -2308,7 +2304,7 @@ function createPointerEvents(store) {
2308
2304
  compute(event, state, previous) {
2309
2305
  // https://github.com/pmndrs/react-three-fiber/pull/782
2310
2306
  // Events trigger outside of canvas when moved, use offsetX/Y by default and allow overrides
2311
- state.pointer.set(event.offsetX / state.size.width * 2 - 1, -(event.offsetY / state.size.height) * 2 + 1);
2307
+ state.pointer.set((event.offsetX - state.size.left) / state.size.width * 2 - 1, -((event.offsetY - state.size.top) / state.size.height) * 2 + 1);
2312
2308
  state.raycaster.setFromCamera(state.pointer, state.camera);
2313
2309
  },
2314
2310
  connected: undefined,