@react-three/fiber 8.0.27 → 8.2.1

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.
@@ -37,12 +37,19 @@ var threeTypes = /*#__PURE__*/Object.freeze({
37
37
  __proto__: null
38
38
  });
39
39
 
40
- const isOrthographicCamera = def => def && def.isOrthographicCamera; // React currently throws a warning when using useLayoutEffect on the server.
41
- // To get around it, we can conditionally useEffect on the server (no-op) and
42
- // useLayoutEffect on the client.
40
+ var _window$document, _window$navigator;
41
+ const isOrthographicCamera = def => def && def.isOrthographicCamera;
42
+ /**
43
+ * An SSR-friendly useLayoutEffect.
44
+ *
45
+ * React currently throws a warning when using useLayoutEffect on the server.
46
+ * To get around it, we can conditionally useEffect on the server (no-op) and
47
+ * useLayoutEffect elsewhere.
48
+ *
49
+ * @see https://github.com/facebook/react/issues/14927
50
+ */
43
51
 
44
- const isSSR = typeof window === 'undefined' || !window.navigator || /ServerSideRendering|^Deno\//.test(window.navigator.userAgent);
45
- const useIsomorphicLayoutEffect = isSSR ? React__namespace.useEffect : React__namespace.useLayoutEffect;
52
+ const useIsomorphicLayoutEffect = typeof window !== 'undefined' && ((_window$document = window.document) != null && _window$document.createElement || ((_window$navigator = window.navigator) == null ? void 0 : _window$navigator.product) === 'ReactNative') ? React__namespace.useLayoutEffect : React__namespace.useEffect;
46
53
  function useMutableCallback(fn) {
47
54
  const ref = React__namespace.useRef(fn);
48
55
  useIsomorphicLayoutEffect(() => void (ref.current = fn), [fn]);
@@ -855,7 +862,7 @@ let extend = objects => void (catalogue = { ...catalogue,
855
862
  ...objects
856
863
  });
857
864
 
858
- function createRenderer(roots, getEventPriority) {
865
+ function createRenderer(_roots, _getEventPriority) {
859
866
  function createInstance(type, {
860
867
  args = [],
861
868
  attach,
@@ -1071,10 +1078,10 @@ function createRenderer(roots, getEventPriority) {
1071
1078
  appendChild,
1072
1079
  appendInitialChild: appendChild,
1073
1080
  insertBefore,
1074
- supportsMicrotask: true,
1075
- warnsIfNotActing: true,
1076
1081
  supportsMutation: true,
1077
1082
  isPrimaryRenderer: false,
1083
+ supportsPersistence: false,
1084
+ supportsHydration: false,
1078
1085
  noTimeout: -1,
1079
1086
  appendChildToContainer: (container, child) => {
1080
1087
  const scene = container.getState().scene; // Link current root to the default scene
@@ -1093,10 +1100,10 @@ function createRenderer(roots, getEventPriority) {
1093
1100
  const localState = (_instance$__r3f2 = instance == null ? void 0 : instance.__r3f) != null ? _instance$__r3f2 : {}; // https://github.com/facebook/react/issues/20271
1094
1101
  // Returning true will trigger commitMount
1095
1102
 
1096
- return !!localState.handlers;
1103
+ return Boolean(localState.handlers);
1097
1104
  },
1098
1105
 
1099
- prepareUpdate(instance, type, oldProps, newProps) {
1106
+ prepareUpdate(instance, _type, oldProps, newProps) {
1100
1107
  // Create diff-sets
1101
1108
  if (instance.__r3f.primitive && newProps.object && newProps.object !== instance) {
1102
1109
  return [true];
@@ -1113,7 +1120,7 @@ function createRenderer(roots, getEventPriority) {
1113
1120
  ...restOld
1114
1121
  } = oldProps; // Throw if an object or literal was passed for args
1115
1122
 
1116
- 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
1123
+ 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-instantiated
1117
1124
 
1118
1125
  if (argsNew.some((value, index) => value !== argsOld[index])) return [true]; // Create a diff-set, flag if there are any changes
1119
1126
 
@@ -1124,13 +1131,13 @@ function createRenderer(roots, getEventPriority) {
1124
1131
  }
1125
1132
  },
1126
1133
 
1127
- commitUpdate(instance, [reconstruct, diff], type, oldProps, newProps, fiber) {
1134
+ commitUpdate(instance, [reconstruct, diff], type, _oldProps, newProps, fiber) {
1128
1135
  // Reconstruct when args or <primitive object={...} have changes
1129
1136
  if (reconstruct) switchInstance(instance, type, newProps, fiber); // Otherwise just overwrite props
1130
1137
  else applyProps$1(instance, diff);
1131
1138
  },
1132
1139
 
1133
- commitMount(instance, type, props, int) {
1140
+ commitMount(instance, _type, _props, _int) {
1134
1141
  var _instance$__r3f3;
1135
1142
 
1136
1143
  // https://github.com/facebook/react/issues/20271
@@ -1143,13 +1150,11 @@ function createRenderer(roots, getEventPriority) {
1143
1150
  },
1144
1151
 
1145
1152
  getPublicInstance: instance => instance,
1146
- shouldDeprioritizeSubtree: () => false,
1147
1153
  prepareForCommit: () => null,
1148
1154
  preparePortalMount: container => prepare(container.getState().scene),
1149
1155
  resetAfterCommit: () => {},
1150
1156
  shouldSetTextContent: () => false,
1151
1157
  clearContainer: () => false,
1152
- detachDeletedInstance: () => {},
1153
1158
 
1154
1159
  hideInstance(instance) {
1155
1160
  var _instance$__r3f4;
@@ -1177,20 +1182,23 @@ function createRenderer(roots, getEventPriority) {
1177
1182
  invalidateInstance(instance);
1178
1183
  },
1179
1184
 
1180
- createTextInstance: () => {},
1185
+ createTextInstance: () => {
1186
+ throw new Error('Text is not allowed in the R3F tree! This could be stray whitespace or characters.');
1187
+ },
1181
1188
  hideTextInstance: () => {
1182
- throw new Error('Text is not allowed in the R3F tree.');
1189
+ throw new Error('Text is not allowed in the R3F tree! This could be stray whitespace or characters.');
1183
1190
  },
1184
1191
  unhideTextInstance: () => {},
1185
- getCurrentEventPriority: () => getEventPriority ? getEventPriority() : constants.DefaultEventPriority,
1186
- // @ts-ignore
1187
- now: typeof performance !== 'undefined' && is.fun(performance.now) ? performance.now : is.fun(Date.now) ? Date.now : undefined,
1192
+ // https://github.com/pmndrs/react-three-fiber/pull/2360#discussion_r916356874
1188
1193
  // @ts-ignore
1194
+ getCurrentEventPriority: () => _getEventPriority ? _getEventPriority() : constants.DefaultEventPriority,
1195
+ beforeActiveInstanceBlur: () => {},
1196
+ afterActiveInstanceBlur: () => {},
1197
+ detachDeletedInstance: () => {},
1198
+ now: typeof performance !== 'undefined' && is.fun(performance.now) ? performance.now : is.fun(Date.now) ? Date.now : () => 0,
1199
+ // https://github.com/pmndrs/react-three-fiber/pull/2360#discussion_r920883503
1189
1200
  scheduleTimeout: is.fun(setTimeout) ? setTimeout : undefined,
1190
- // @ts-ignore
1191
- cancelTimeout: is.fun(clearTimeout) ? clearTimeout : undefined,
1192
- setTimeout: is.fun(setTimeout) ? setTimeout : undefined,
1193
- clearTimeout: is.fun(clearTimeout) ? clearTimeout : undefined
1201
+ cancelTimeout: is.fun(clearTimeout) ? clearTimeout : undefined
1194
1202
  });
1195
1203
  return {
1196
1204
  reconciler,
@@ -1211,7 +1219,9 @@ const createStore = (invalidate, advance) => {
1211
1219
  function getCurrentViewport(camera = get().camera, target = defaultTarget, size = get().size) {
1212
1220
  const {
1213
1221
  width,
1214
- height
1222
+ height,
1223
+ top,
1224
+ left
1215
1225
  } = size;
1216
1226
  const aspect = width / height;
1217
1227
  if (target instanceof THREE__namespace.Vector3) tempTarget.copy(target);else tempTarget.set(...target);
@@ -1221,6 +1231,8 @@ const createStore = (invalidate, advance) => {
1221
1231
  return {
1222
1232
  width: width / camera.zoom,
1223
1233
  height: height / camera.zoom,
1234
+ top,
1235
+ left,
1224
1236
  factor: 1,
1225
1237
  distance,
1226
1238
  aspect
@@ -1234,6 +1246,8 @@ const createStore = (invalidate, advance) => {
1234
1246
  return {
1235
1247
  width: w,
1236
1248
  height: h,
1249
+ top,
1250
+ left,
1237
1251
  factor: width / w,
1238
1252
  distance,
1239
1253
  aspect
@@ -1250,7 +1264,7 @@ const createStore = (invalidate, advance) => {
1250
1264
  }));
1251
1265
 
1252
1266
  const pointer = new THREE__namespace.Vector2();
1253
- return {
1267
+ const rootState = {
1254
1268
  set,
1255
1269
  get,
1256
1270
  // Mock objects that have to be configured
@@ -1293,6 +1307,8 @@ const createStore = (invalidate, advance) => {
1293
1307
  size: {
1294
1308
  width: 0,
1295
1309
  height: 0,
1310
+ top: 0,
1311
+ left: 0,
1296
1312
  updateStyle: false
1297
1313
  },
1298
1314
  viewport: {
@@ -1300,6 +1316,8 @@ const createStore = (invalidate, advance) => {
1300
1316
  dpr: 0,
1301
1317
  width: 0,
1302
1318
  height: 0,
1319
+ top: 0,
1320
+ left: 0,
1303
1321
  aspect: 0,
1304
1322
  distance: 0,
1305
1323
  factor: 0,
@@ -1310,11 +1328,13 @@ const createStore = (invalidate, advance) => {
1310
1328
  ...events
1311
1329
  }
1312
1330
  })),
1313
- setSize: (width, height, updateStyle) => {
1331
+ setSize: (width, height, updateStyle, top, left) => {
1314
1332
  const camera = get().camera;
1315
1333
  const size = {
1316
1334
  width,
1317
1335
  height,
1336
+ top: top || 0,
1337
+ left: left || 0,
1318
1338
  updateStyle
1319
1339
  };
1320
1340
  set(state => ({
@@ -1388,6 +1408,7 @@ const createStore = (invalidate, advance) => {
1388
1408
  }
1389
1409
  }
1390
1410
  };
1411
+ return rootState;
1391
1412
  });
1392
1413
  const state = rootState.getState();
1393
1414
  let oldSize = state.size;
@@ -1429,15 +1450,17 @@ const createStore = (invalidate, advance) => {
1429
1450
  };
1430
1451
 
1431
1452
  function createSubs(callback, subs) {
1432
- const index = subs.length;
1433
- subs.push(callback);
1434
- return () => void subs.splice(index, 1);
1453
+ const sub = {
1454
+ callback
1455
+ };
1456
+ subs.add(sub);
1457
+ return () => void subs.delete(sub);
1435
1458
  }
1436
1459
 
1437
1460
  let i;
1438
- let globalEffects = [];
1439
- let globalAfterEffects = [];
1440
- let globalTailEffects = [];
1461
+ let globalEffects = new Set();
1462
+ let globalAfterEffects = new Set();
1463
+ let globalTailEffects = new Set();
1441
1464
  /**
1442
1465
  * Adds a global render callback which is called each frame.
1443
1466
  * @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#addEffect
@@ -1458,7 +1481,9 @@ const addAfterEffect = callback => createSubs(callback, globalAfterEffects);
1458
1481
  const addTail = callback => createSubs(callback, globalTailEffects);
1459
1482
 
1460
1483
  function run(effects, timestamp) {
1461
- for (i = 0; i < effects.length; i++) effects[i](timestamp);
1484
+ effects.forEach(({
1485
+ callback
1486
+ }) => callback(timestamp));
1462
1487
  }
1463
1488
 
1464
1489
  let subscribers;
@@ -1500,7 +1525,7 @@ function createLoop(roots) {
1500
1525
  running = true;
1501
1526
  repeat = 0; // Run effects
1502
1527
 
1503
- if (globalEffects.length) run(globalEffects, timestamp); // Render all roots
1528
+ if (globalEffects.size) run(globalEffects, timestamp); // Render all roots
1504
1529
 
1505
1530
  roots.forEach(root => {
1506
1531
  var _state$gl$xr;
@@ -1512,11 +1537,11 @@ function createLoop(roots) {
1512
1537
  }
1513
1538
  }); // Run after-effects
1514
1539
 
1515
- if (globalAfterEffects.length) run(globalAfterEffects, timestamp); // Stop the loop if nothing invalidates it
1540
+ if (globalAfterEffects.size) run(globalAfterEffects, timestamp); // Stop the loop if nothing invalidates it
1516
1541
 
1517
1542
  if (repeat === 0) {
1518
1543
  // Tail call effects, they are called when rendering stops
1519
- if (globalTailEffects.length) run(globalTailEffects, timestamp); // Flag end of operation
1544
+ if (globalTailEffects.size) run(globalTailEffects, timestamp); // Flag end of operation
1520
1545
 
1521
1546
  running = false;
1522
1547
  return cancelAnimationFrame(frame);
@@ -1695,8 +1720,6 @@ function createRoot(canvas) {
1695
1720
  let configured = false;
1696
1721
  return {
1697
1722
  configure(props = {}) {
1698
- var _canvas$parentElement, _canvas$parentElement2, _canvas$parentElement3, _canvas$parentElement4;
1699
-
1700
1723
  let {
1701
1724
  gl: glConfig,
1702
1725
  size,
@@ -1834,11 +1857,22 @@ function createRoot(canvas) {
1834
1857
 
1835
1858
  if (dpr && state.viewport.dpr !== calculateDpr(dpr)) state.setDpr(dpr); // Check size, allow it to take on container bounds initially
1836
1859
 
1837
- size = size || {
1838
- width: (_canvas$parentElement = (_canvas$parentElement2 = canvas.parentElement) == null ? void 0 : _canvas$parentElement2.clientWidth) != null ? _canvas$parentElement : 0,
1839
- height: (_canvas$parentElement3 = (_canvas$parentElement4 = canvas.parentElement) == null ? void 0 : _canvas$parentElement4.clientHeight) != null ? _canvas$parentElement3 : 0
1840
- };
1841
- if (!is.equ(size, state.size, shallowLoose)) state.setSize(size.width, size.height, size.updateStyle); // Check frameloop
1860
+ size = size || (canvas.parentElement ? {
1861
+ width: canvas.parentElement.clientWidth,
1862
+ height: canvas.parentElement.clientHeight,
1863
+ top: canvas.parentElement.clientTop,
1864
+ left: canvas.parentElement.clientLeft
1865
+ } : {
1866
+ width: 0,
1867
+ height: 0,
1868
+ top: 0,
1869
+ left: 0
1870
+ });
1871
+
1872
+ if (!is.equ(size, state.size, shallowLoose)) {
1873
+ state.setSize(size.width, size.height, size.updateStyle, size.top, size.left);
1874
+ } // Check frameloop
1875
+
1842
1876
 
1843
1877
  if (state.frameloop !== frameloop) state.setFrameloop(frameloop); // Check pointer missed
1844
1878
 
@@ -37,12 +37,19 @@ var threeTypes = /*#__PURE__*/Object.freeze({
37
37
  __proto__: null
38
38
  });
39
39
 
40
- const isOrthographicCamera = def => def && def.isOrthographicCamera; // React currently throws a warning when using useLayoutEffect on the server.
41
- // To get around it, we can conditionally useEffect on the server (no-op) and
42
- // useLayoutEffect on the client.
40
+ var _window$document, _window$navigator;
41
+ const isOrthographicCamera = def => def && def.isOrthographicCamera;
42
+ /**
43
+ * An SSR-friendly useLayoutEffect.
44
+ *
45
+ * React currently throws a warning when using useLayoutEffect on the server.
46
+ * To get around it, we can conditionally useEffect on the server (no-op) and
47
+ * useLayoutEffect elsewhere.
48
+ *
49
+ * @see https://github.com/facebook/react/issues/14927
50
+ */
43
51
 
44
- const isSSR = typeof window === 'undefined' || !window.navigator || /ServerSideRendering|^Deno\//.test(window.navigator.userAgent);
45
- const useIsomorphicLayoutEffect = isSSR ? React__namespace.useEffect : React__namespace.useLayoutEffect;
52
+ const useIsomorphicLayoutEffect = typeof window !== 'undefined' && ((_window$document = window.document) != null && _window$document.createElement || ((_window$navigator = window.navigator) == null ? void 0 : _window$navigator.product) === 'ReactNative') ? React__namespace.useLayoutEffect : React__namespace.useEffect;
46
53
  function useMutableCallback(fn) {
47
54
  const ref = React__namespace.useRef(fn);
48
55
  useIsomorphicLayoutEffect(() => void (ref.current = fn), [fn]);
@@ -855,7 +862,7 @@ let extend = objects => void (catalogue = { ...catalogue,
855
862
  ...objects
856
863
  });
857
864
 
858
- function createRenderer(roots, getEventPriority) {
865
+ function createRenderer(_roots, _getEventPriority) {
859
866
  function createInstance(type, {
860
867
  args = [],
861
868
  attach,
@@ -1071,10 +1078,10 @@ function createRenderer(roots, getEventPriority) {
1071
1078
  appendChild,
1072
1079
  appendInitialChild: appendChild,
1073
1080
  insertBefore,
1074
- supportsMicrotask: true,
1075
- warnsIfNotActing: true,
1076
1081
  supportsMutation: true,
1077
1082
  isPrimaryRenderer: false,
1083
+ supportsPersistence: false,
1084
+ supportsHydration: false,
1078
1085
  noTimeout: -1,
1079
1086
  appendChildToContainer: (container, child) => {
1080
1087
  const scene = container.getState().scene; // Link current root to the default scene
@@ -1093,10 +1100,10 @@ function createRenderer(roots, getEventPriority) {
1093
1100
  const localState = (_instance$__r3f2 = instance == null ? void 0 : instance.__r3f) != null ? _instance$__r3f2 : {}; // https://github.com/facebook/react/issues/20271
1094
1101
  // Returning true will trigger commitMount
1095
1102
 
1096
- return !!localState.handlers;
1103
+ return Boolean(localState.handlers);
1097
1104
  },
1098
1105
 
1099
- prepareUpdate(instance, type, oldProps, newProps) {
1106
+ prepareUpdate(instance, _type, oldProps, newProps) {
1100
1107
  // Create diff-sets
1101
1108
  if (instance.__r3f.primitive && newProps.object && newProps.object !== instance) {
1102
1109
  return [true];
@@ -1113,7 +1120,7 @@ function createRenderer(roots, getEventPriority) {
1113
1120
  ...restOld
1114
1121
  } = oldProps; // Throw if an object or literal was passed for args
1115
1122
 
1116
- 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
1123
+ 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-instantiated
1117
1124
 
1118
1125
  if (argsNew.some((value, index) => value !== argsOld[index])) return [true]; // Create a diff-set, flag if there are any changes
1119
1126
 
@@ -1124,13 +1131,13 @@ function createRenderer(roots, getEventPriority) {
1124
1131
  }
1125
1132
  },
1126
1133
 
1127
- commitUpdate(instance, [reconstruct, diff], type, oldProps, newProps, fiber) {
1134
+ commitUpdate(instance, [reconstruct, diff], type, _oldProps, newProps, fiber) {
1128
1135
  // Reconstruct when args or <primitive object={...} have changes
1129
1136
  if (reconstruct) switchInstance(instance, type, newProps, fiber); // Otherwise just overwrite props
1130
1137
  else applyProps$1(instance, diff);
1131
1138
  },
1132
1139
 
1133
- commitMount(instance, type, props, int) {
1140
+ commitMount(instance, _type, _props, _int) {
1134
1141
  var _instance$__r3f3;
1135
1142
 
1136
1143
  // https://github.com/facebook/react/issues/20271
@@ -1143,13 +1150,11 @@ function createRenderer(roots, getEventPriority) {
1143
1150
  },
1144
1151
 
1145
1152
  getPublicInstance: instance => instance,
1146
- shouldDeprioritizeSubtree: () => false,
1147
1153
  prepareForCommit: () => null,
1148
1154
  preparePortalMount: container => prepare(container.getState().scene),
1149
1155
  resetAfterCommit: () => {},
1150
1156
  shouldSetTextContent: () => false,
1151
1157
  clearContainer: () => false,
1152
- detachDeletedInstance: () => {},
1153
1158
 
1154
1159
  hideInstance(instance) {
1155
1160
  var _instance$__r3f4;
@@ -1177,20 +1182,23 @@ function createRenderer(roots, getEventPriority) {
1177
1182
  invalidateInstance(instance);
1178
1183
  },
1179
1184
 
1180
- createTextInstance: () => {},
1185
+ createTextInstance: () => {
1186
+ throw new Error('Text is not allowed in the R3F tree! This could be stray whitespace or characters.');
1187
+ },
1181
1188
  hideTextInstance: () => {
1182
- throw new Error('Text is not allowed in the R3F tree.');
1189
+ throw new Error('Text is not allowed in the R3F tree! This could be stray whitespace or characters.');
1183
1190
  },
1184
1191
  unhideTextInstance: () => {},
1185
- getCurrentEventPriority: () => getEventPriority ? getEventPriority() : constants.DefaultEventPriority,
1186
- // @ts-ignore
1187
- now: typeof performance !== 'undefined' && is.fun(performance.now) ? performance.now : is.fun(Date.now) ? Date.now : undefined,
1192
+ // https://github.com/pmndrs/react-three-fiber/pull/2360#discussion_r916356874
1188
1193
  // @ts-ignore
1194
+ getCurrentEventPriority: () => _getEventPriority ? _getEventPriority() : constants.DefaultEventPriority,
1195
+ beforeActiveInstanceBlur: () => {},
1196
+ afterActiveInstanceBlur: () => {},
1197
+ detachDeletedInstance: () => {},
1198
+ now: typeof performance !== 'undefined' && is.fun(performance.now) ? performance.now : is.fun(Date.now) ? Date.now : () => 0,
1199
+ // https://github.com/pmndrs/react-three-fiber/pull/2360#discussion_r920883503
1189
1200
  scheduleTimeout: is.fun(setTimeout) ? setTimeout : undefined,
1190
- // @ts-ignore
1191
- cancelTimeout: is.fun(clearTimeout) ? clearTimeout : undefined,
1192
- setTimeout: is.fun(setTimeout) ? setTimeout : undefined,
1193
- clearTimeout: is.fun(clearTimeout) ? clearTimeout : undefined
1201
+ cancelTimeout: is.fun(clearTimeout) ? clearTimeout : undefined
1194
1202
  });
1195
1203
  return {
1196
1204
  reconciler,
@@ -1211,7 +1219,9 @@ const createStore = (invalidate, advance) => {
1211
1219
  function getCurrentViewport(camera = get().camera, target = defaultTarget, size = get().size) {
1212
1220
  const {
1213
1221
  width,
1214
- height
1222
+ height,
1223
+ top,
1224
+ left
1215
1225
  } = size;
1216
1226
  const aspect = width / height;
1217
1227
  if (target instanceof THREE__namespace.Vector3) tempTarget.copy(target);else tempTarget.set(...target);
@@ -1221,6 +1231,8 @@ const createStore = (invalidate, advance) => {
1221
1231
  return {
1222
1232
  width: width / camera.zoom,
1223
1233
  height: height / camera.zoom,
1234
+ top,
1235
+ left,
1224
1236
  factor: 1,
1225
1237
  distance,
1226
1238
  aspect
@@ -1234,6 +1246,8 @@ const createStore = (invalidate, advance) => {
1234
1246
  return {
1235
1247
  width: w,
1236
1248
  height: h,
1249
+ top,
1250
+ left,
1237
1251
  factor: width / w,
1238
1252
  distance,
1239
1253
  aspect
@@ -1250,7 +1264,7 @@ const createStore = (invalidate, advance) => {
1250
1264
  }));
1251
1265
 
1252
1266
  const pointer = new THREE__namespace.Vector2();
1253
- return {
1267
+ const rootState = {
1254
1268
  set,
1255
1269
  get,
1256
1270
  // Mock objects that have to be configured
@@ -1293,6 +1307,8 @@ const createStore = (invalidate, advance) => {
1293
1307
  size: {
1294
1308
  width: 0,
1295
1309
  height: 0,
1310
+ top: 0,
1311
+ left: 0,
1296
1312
  updateStyle: false
1297
1313
  },
1298
1314
  viewport: {
@@ -1300,6 +1316,8 @@ const createStore = (invalidate, advance) => {
1300
1316
  dpr: 0,
1301
1317
  width: 0,
1302
1318
  height: 0,
1319
+ top: 0,
1320
+ left: 0,
1303
1321
  aspect: 0,
1304
1322
  distance: 0,
1305
1323
  factor: 0,
@@ -1310,11 +1328,13 @@ const createStore = (invalidate, advance) => {
1310
1328
  ...events
1311
1329
  }
1312
1330
  })),
1313
- setSize: (width, height, updateStyle) => {
1331
+ setSize: (width, height, updateStyle, top, left) => {
1314
1332
  const camera = get().camera;
1315
1333
  const size = {
1316
1334
  width,
1317
1335
  height,
1336
+ top: top || 0,
1337
+ left: left || 0,
1318
1338
  updateStyle
1319
1339
  };
1320
1340
  set(state => ({
@@ -1388,6 +1408,7 @@ const createStore = (invalidate, advance) => {
1388
1408
  }
1389
1409
  }
1390
1410
  };
1411
+ return rootState;
1391
1412
  });
1392
1413
  const state = rootState.getState();
1393
1414
  let oldSize = state.size;
@@ -1429,15 +1450,17 @@ const createStore = (invalidate, advance) => {
1429
1450
  };
1430
1451
 
1431
1452
  function createSubs(callback, subs) {
1432
- const index = subs.length;
1433
- subs.push(callback);
1434
- return () => void subs.splice(index, 1);
1453
+ const sub = {
1454
+ callback
1455
+ };
1456
+ subs.add(sub);
1457
+ return () => void subs.delete(sub);
1435
1458
  }
1436
1459
 
1437
1460
  let i;
1438
- let globalEffects = [];
1439
- let globalAfterEffects = [];
1440
- let globalTailEffects = [];
1461
+ let globalEffects = new Set();
1462
+ let globalAfterEffects = new Set();
1463
+ let globalTailEffects = new Set();
1441
1464
  /**
1442
1465
  * Adds a global render callback which is called each frame.
1443
1466
  * @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#addEffect
@@ -1458,7 +1481,9 @@ const addAfterEffect = callback => createSubs(callback, globalAfterEffects);
1458
1481
  const addTail = callback => createSubs(callback, globalTailEffects);
1459
1482
 
1460
1483
  function run(effects, timestamp) {
1461
- for (i = 0; i < effects.length; i++) effects[i](timestamp);
1484
+ effects.forEach(({
1485
+ callback
1486
+ }) => callback(timestamp));
1462
1487
  }
1463
1488
 
1464
1489
  let subscribers;
@@ -1500,7 +1525,7 @@ function createLoop(roots) {
1500
1525
  running = true;
1501
1526
  repeat = 0; // Run effects
1502
1527
 
1503
- if (globalEffects.length) run(globalEffects, timestamp); // Render all roots
1528
+ if (globalEffects.size) run(globalEffects, timestamp); // Render all roots
1504
1529
 
1505
1530
  roots.forEach(root => {
1506
1531
  var _state$gl$xr;
@@ -1512,11 +1537,11 @@ function createLoop(roots) {
1512
1537
  }
1513
1538
  }); // Run after-effects
1514
1539
 
1515
- if (globalAfterEffects.length) run(globalAfterEffects, timestamp); // Stop the loop if nothing invalidates it
1540
+ if (globalAfterEffects.size) run(globalAfterEffects, timestamp); // Stop the loop if nothing invalidates it
1516
1541
 
1517
1542
  if (repeat === 0) {
1518
1543
  // Tail call effects, they are called when rendering stops
1519
- if (globalTailEffects.length) run(globalTailEffects, timestamp); // Flag end of operation
1544
+ if (globalTailEffects.size) run(globalTailEffects, timestamp); // Flag end of operation
1520
1545
 
1521
1546
  running = false;
1522
1547
  return cancelAnimationFrame(frame);
@@ -1695,8 +1720,6 @@ function createRoot(canvas) {
1695
1720
  let configured = false;
1696
1721
  return {
1697
1722
  configure(props = {}) {
1698
- var _canvas$parentElement, _canvas$parentElement2, _canvas$parentElement3, _canvas$parentElement4;
1699
-
1700
1723
  let {
1701
1724
  gl: glConfig,
1702
1725
  size,
@@ -1834,11 +1857,22 @@ function createRoot(canvas) {
1834
1857
 
1835
1858
  if (dpr && state.viewport.dpr !== calculateDpr(dpr)) state.setDpr(dpr); // Check size, allow it to take on container bounds initially
1836
1859
 
1837
- size = size || {
1838
- width: (_canvas$parentElement = (_canvas$parentElement2 = canvas.parentElement) == null ? void 0 : _canvas$parentElement2.clientWidth) != null ? _canvas$parentElement : 0,
1839
- height: (_canvas$parentElement3 = (_canvas$parentElement4 = canvas.parentElement) == null ? void 0 : _canvas$parentElement4.clientHeight) != null ? _canvas$parentElement3 : 0
1840
- };
1841
- if (!is.equ(size, state.size, shallowLoose)) state.setSize(size.width, size.height, size.updateStyle); // Check frameloop
1860
+ size = size || (canvas.parentElement ? {
1861
+ width: canvas.parentElement.clientWidth,
1862
+ height: canvas.parentElement.clientHeight,
1863
+ top: canvas.parentElement.clientTop,
1864
+ left: canvas.parentElement.clientLeft
1865
+ } : {
1866
+ width: 0,
1867
+ height: 0,
1868
+ top: 0,
1869
+ left: 0
1870
+ });
1871
+
1872
+ if (!is.equ(size, state.size, shallowLoose)) {
1873
+ state.setSize(size.width, size.height, size.updateStyle, size.top, size.left);
1874
+ } // Check frameloop
1875
+
1842
1876
 
1843
1877
  if (state.frameloop !== frameloop) state.setFrameloop(frameloop); // Check pointer missed
1844
1878
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var index = require('./index-acc8c265.cjs.dev.js');
5
+ var index = require('./index-6716e497.cjs.dev.js');
6
6
  var _extends = require('@babel/runtime/helpers/extends');
7
7
  var React = require('react');
8
8
  var THREE = require('three');
@@ -144,10 +144,7 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(function Canvas({
144
144
  // This will include the entire THREE namespace by default, users can extend
145
145
  // their own elements by using the createRoot API instead
146
146
  React__namespace.useMemo(() => index.extend(THREE__namespace), []);
147
- const [containerRef, {
148
- width,
149
- height
150
- }] = useMeasure__default["default"]({
147
+ const [containerRef, containerRect] = useMeasure__default["default"]({
151
148
  scroll: true,
152
149
  debounce: {
153
150
  scroll: 50,
@@ -168,7 +165,7 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(function Canvas({
168
165
  if (error) throw error;
169
166
  const root = React__namespace.useRef(null);
170
167
 
171
- if (width > 0 && height > 0 && canvas) {
168
+ if (containerRect.width > 0 && containerRect.height > 0 && canvas) {
172
169
  if (!root.current) root.current = index.createRoot(canvas);
173
170
  root.current.configure({
174
171
  gl,
@@ -183,10 +180,7 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(function Canvas({
183
180
  performance,
184
181
  raycaster,
185
182
  camera,
186
- size: {
187
- width,
188
- height
189
- },
183
+ size: containerRect,
190
184
  // Pass mutable reference to onPointerMissed so it's free to update
191
185
  onPointerMissed: (...args) => handlePointerMissed.current == null ? void 0 : handlePointerMissed.current(...args),
192
186
  onCreated: state => {
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var index = require('./index-c30de6b8.cjs.prod.js');
5
+ var index = require('./index-8296e46a.cjs.prod.js');
6
6
  var _extends = require('@babel/runtime/helpers/extends');
7
7
  var React = require('react');
8
8
  var THREE = require('three');
@@ -144,10 +144,7 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(function Canvas({
144
144
  // This will include the entire THREE namespace by default, users can extend
145
145
  // their own elements by using the createRoot API instead
146
146
  React__namespace.useMemo(() => index.extend(THREE__namespace), []);
147
- const [containerRef, {
148
- width,
149
- height
150
- }] = useMeasure__default["default"]({
147
+ const [containerRef, containerRect] = useMeasure__default["default"]({
151
148
  scroll: true,
152
149
  debounce: {
153
150
  scroll: 50,
@@ -168,7 +165,7 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(function Canvas({
168
165
  if (error) throw error;
169
166
  const root = React__namespace.useRef(null);
170
167
 
171
- if (width > 0 && height > 0 && canvas) {
168
+ if (containerRect.width > 0 && containerRect.height > 0 && canvas) {
172
169
  if (!root.current) root.current = index.createRoot(canvas);
173
170
  root.current.configure({
174
171
  gl,
@@ -183,10 +180,7 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(function Canvas({
183
180
  performance,
184
181
  raycaster,
185
182
  camera,
186
- size: {
187
- width,
188
- height
189
- },
183
+ size: containerRect,
190
184
  // Pass mutable reference to onPointerMissed so it's free to update
191
185
  onPointerMissed: (...args) => handlePointerMissed.current == null ? void 0 : handlePointerMissed.current(...args),
192
186
  onCreated: state => {