@react-three/fiber 8.12.1 → 8.12.2

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.
package/CHANGELOG.md CHANGED
@@ -1,10 +1,16 @@
1
1
  # @react-three/fiber
2
2
 
3
+ ## 8.12.2
4
+
5
+ ### Patch Changes
6
+
7
+ - c5193468: fix: safeguard window.devicePixelRatio
8
+
3
9
  ## 8.12.1
4
10
 
5
11
  ### Patch Changes
6
12
 
7
- - 572f25fa: add support for onlostpointercapture
13
+ - 571f07ac: fix: safeguard window.devicePixelRatio
8
14
 
9
15
  ## 8.12.0
10
16
 
@@ -45,7 +45,6 @@ export declare type EventHandlers = {
45
45
  onPointerMove?: (event: ThreeEvent<PointerEvent>) => void;
46
46
  onPointerMissed?: (event: MouseEvent) => void;
47
47
  onPointerCancel?: (event: ThreeEvent<PointerEvent>) => void;
48
- onLostPointerCapture?: (event: ThreeEvent<PointerEvent>) => void;
49
48
  onWheel?: (event: ThreeEvent<WheelEvent>) => void;
50
49
  };
51
50
  export declare type FilterFunction = (items: THREE.Intersection[], state: RootState) => THREE.Intersection[];
@@ -432,7 +432,10 @@ const DEFAULT = '__default';
432
432
  const DEFAULTS = new Map();
433
433
  const isDiffSet = def => def && !!def.memoized && !!def.changes;
434
434
  function calculateDpr(dpr) {
435
- const target = typeof window !== 'undefined' ? window.devicePixelRatio : 1;
435
+ var _window$devicePixelRa;
436
+ // Err on the side of progress by assuming 2x dpr if we can't detect it
437
+ // This will happen in workers where window is defined but dpr isn't.
438
+ const target = typeof window !== 'undefined' ? (_window$devicePixelRa = window.devicePixelRatio) != null ? _window$devicePixelRa : 2 : 1;
436
439
  return Array.isArray(dpr) ? Math.min(Math.max(dpr[0], target), dpr[1]) : dpr;
437
440
  }
438
441
 
@@ -619,7 +622,7 @@ function diffProps(instance, {
619
622
  // When props match bail out
620
623
  if (is.equ(value, previous[key])) return;
621
624
  // Collect handlers and bail out
622
- if (/^on(LostPointer|Pointer|Click|DoubleClick|ContextMenu|Wheel)/.test(key)) return changes.push([key, value, true, []]);
625
+ if (/^on(Pointer|Click|DoubleClick|ContextMenu|Wheel)/.test(key)) return changes.push([key, value, true, []]);
623
626
  // Split dashed props
624
627
  let entries = [];
625
628
  if (key.includes('-')) entries = key.split('-');
@@ -1086,6 +1089,25 @@ function createEvents(store) {
1086
1089
  case 'onPointerLeave':
1087
1090
  case 'onPointerCancel':
1088
1091
  return () => cancelPointer([]);
1092
+ case 'onLostPointerCapture':
1093
+ return event => {
1094
+ const {
1095
+ internal
1096
+ } = store.getState();
1097
+ if ('pointerId' in event && internal.capturedMap.has(event.pointerId)) {
1098
+ // If the object event interface had onLostPointerCapture, we'd call it here on every
1099
+ // object that's getting removed. We call it on the next frame because onLostPointerCapture
1100
+ // fires before onPointerUp. Otherwise pointerUp would never be called if the event didn't
1101
+ // happen in the object it originated from, leaving components in a in-between state.
1102
+ requestAnimationFrame(() => {
1103
+ // Only release if pointer-up didn't do it already
1104
+ if (internal.capturedMap.has(event.pointerId)) {
1105
+ internal.capturedMap.delete(event.pointerId);
1106
+ cancelPointer([]);
1107
+ }
1108
+ });
1109
+ }
1110
+ };
1089
1111
  }
1090
1112
 
1091
1113
  // Any other pointer goes here ...
@@ -1100,7 +1122,6 @@ function createEvents(store) {
1100
1122
 
1101
1123
  // Get fresh intersects
1102
1124
  const isPointerMove = name === 'onPointerMove';
1103
- const isLostPointerCapture = name === 'onLostPointerCapture';
1104
1125
  const isClickEvent = name === 'onClick' || name === 'onContextMenu' || name === 'onDoubleClick';
1105
1126
  const filter = isPointerMove ? filterPointerEvents : undefined;
1106
1127
  const hits = intersect(event, filter);
@@ -1120,7 +1141,6 @@ function createEvents(store) {
1120
1141
  if (onPointerMissed) onPointerMissed(event);
1121
1142
  }
1122
1143
  }
1123
-
1124
1144
  // Take care of unhover
1125
1145
  if (isPointerMove) cancelPointer(hits);
1126
1146
  function onIntersect(data) {
@@ -1164,24 +1184,6 @@ function createEvents(store) {
1164
1184
  }
1165
1185
  // Call mouse move
1166
1186
  handlers.onPointerMove == null ? void 0 : handlers.onPointerMove(data);
1167
- } else if (isLostPointerCapture) {
1168
- const {
1169
- internal
1170
- } = store.getState();
1171
- if ('pointerId' in event && internal.capturedMap.has(event.pointerId)) {
1172
- // If the object event interface had onLostPointerCapture, we'd call it here on every
1173
- // object that's getting removed. We call it on the next frame because onLostPointerCapture
1174
- // fires before onPointerUp. Otherwise pointerUp would never be called if the event didn't
1175
- // happen in the object it originated from, leaving components in a in-between state.
1176
- requestAnimationFrame(() => {
1177
- // Only release if pointer-up didn't do it already
1178
- if (internal.capturedMap.has(event.pointerId)) {
1179
- internal.capturedMap.delete(event.pointerId);
1180
- cancelPointer([]);
1181
- handlers.onLostPointerCapture == null ? void 0 : handlers.onLostPointerCapture(data);
1182
- }
1183
- });
1184
- }
1185
1187
  } else {
1186
1188
  // All other events ...
1187
1189
  const handler = handlers[name];
@@ -405,7 +405,10 @@ const DEFAULT = '__default';
405
405
  const DEFAULTS = new Map();
406
406
  const isDiffSet = def => def && !!def.memoized && !!def.changes;
407
407
  function calculateDpr(dpr) {
408
- const target = typeof window !== 'undefined' ? window.devicePixelRatio : 1;
408
+ var _window$devicePixelRa;
409
+ // Err on the side of progress by assuming 2x dpr if we can't detect it
410
+ // This will happen in workers where window is defined but dpr isn't.
411
+ const target = typeof window !== 'undefined' ? (_window$devicePixelRa = window.devicePixelRatio) != null ? _window$devicePixelRa : 2 : 1;
409
412
  return Array.isArray(dpr) ? Math.min(Math.max(dpr[0], target), dpr[1]) : dpr;
410
413
  }
411
414
 
@@ -592,7 +595,7 @@ function diffProps(instance, {
592
595
  // When props match bail out
593
596
  if (is.equ(value, previous[key])) return;
594
597
  // Collect handlers and bail out
595
- if (/^on(LostPointer|Pointer|Click|DoubleClick|ContextMenu|Wheel)/.test(key)) return changes.push([key, value, true, []]);
598
+ if (/^on(Pointer|Click|DoubleClick|ContextMenu|Wheel)/.test(key)) return changes.push([key, value, true, []]);
596
599
  // Split dashed props
597
600
  let entries = [];
598
601
  if (key.includes('-')) entries = key.split('-');
@@ -1059,6 +1062,25 @@ function createEvents(store) {
1059
1062
  case 'onPointerLeave':
1060
1063
  case 'onPointerCancel':
1061
1064
  return () => cancelPointer([]);
1065
+ case 'onLostPointerCapture':
1066
+ return event => {
1067
+ const {
1068
+ internal
1069
+ } = store.getState();
1070
+ if ('pointerId' in event && internal.capturedMap.has(event.pointerId)) {
1071
+ // If the object event interface had onLostPointerCapture, we'd call it here on every
1072
+ // object that's getting removed. We call it on the next frame because onLostPointerCapture
1073
+ // fires before onPointerUp. Otherwise pointerUp would never be called if the event didn't
1074
+ // happen in the object it originated from, leaving components in a in-between state.
1075
+ requestAnimationFrame(() => {
1076
+ // Only release if pointer-up didn't do it already
1077
+ if (internal.capturedMap.has(event.pointerId)) {
1078
+ internal.capturedMap.delete(event.pointerId);
1079
+ cancelPointer([]);
1080
+ }
1081
+ });
1082
+ }
1083
+ };
1062
1084
  }
1063
1085
 
1064
1086
  // Any other pointer goes here ...
@@ -1073,7 +1095,6 @@ function createEvents(store) {
1073
1095
 
1074
1096
  // Get fresh intersects
1075
1097
  const isPointerMove = name === 'onPointerMove';
1076
- const isLostPointerCapture = name === 'onLostPointerCapture';
1077
1098
  const isClickEvent = name === 'onClick' || name === 'onContextMenu' || name === 'onDoubleClick';
1078
1099
  const filter = isPointerMove ? filterPointerEvents : undefined;
1079
1100
  const hits = intersect(event, filter);
@@ -1093,7 +1114,6 @@ function createEvents(store) {
1093
1114
  if (onPointerMissed) onPointerMissed(event);
1094
1115
  }
1095
1116
  }
1096
-
1097
1117
  // Take care of unhover
1098
1118
  if (isPointerMove) cancelPointer(hits);
1099
1119
  function onIntersect(data) {
@@ -1137,24 +1157,6 @@ function createEvents(store) {
1137
1157
  }
1138
1158
  // Call mouse move
1139
1159
  handlers.onPointerMove == null ? void 0 : handlers.onPointerMove(data);
1140
- } else if (isLostPointerCapture) {
1141
- const {
1142
- internal
1143
- } = store.getState();
1144
- if ('pointerId' in event && internal.capturedMap.has(event.pointerId)) {
1145
- // If the object event interface had onLostPointerCapture, we'd call it here on every
1146
- // object that's getting removed. We call it on the next frame because onLostPointerCapture
1147
- // fires before onPointerUp. Otherwise pointerUp would never be called if the event didn't
1148
- // happen in the object it originated from, leaving components in a in-between state.
1149
- requestAnimationFrame(() => {
1150
- // Only release if pointer-up didn't do it already
1151
- if (internal.capturedMap.has(event.pointerId)) {
1152
- internal.capturedMap.delete(event.pointerId);
1153
- cancelPointer([]);
1154
- handlers.onLostPointerCapture == null ? void 0 : handlers.onLostPointerCapture(data);
1155
- }
1156
- });
1157
- }
1158
1160
  } else {
1159
1161
  // All other events ...
1160
1162
  const handler = handlers[name];
@@ -432,7 +432,10 @@ const DEFAULT = '__default';
432
432
  const DEFAULTS = new Map();
433
433
  const isDiffSet = def => def && !!def.memoized && !!def.changes;
434
434
  function calculateDpr(dpr) {
435
- const target = typeof window !== 'undefined' ? window.devicePixelRatio : 1;
435
+ var _window$devicePixelRa;
436
+ // Err on the side of progress by assuming 2x dpr if we can't detect it
437
+ // This will happen in workers where window is defined but dpr isn't.
438
+ const target = typeof window !== 'undefined' ? (_window$devicePixelRa = window.devicePixelRatio) != null ? _window$devicePixelRa : 2 : 1;
436
439
  return Array.isArray(dpr) ? Math.min(Math.max(dpr[0], target), dpr[1]) : dpr;
437
440
  }
438
441
 
@@ -619,7 +622,7 @@ function diffProps(instance, {
619
622
  // When props match bail out
620
623
  if (is.equ(value, previous[key])) return;
621
624
  // Collect handlers and bail out
622
- if (/^on(LostPointer|Pointer|Click|DoubleClick|ContextMenu|Wheel)/.test(key)) return changes.push([key, value, true, []]);
625
+ if (/^on(Pointer|Click|DoubleClick|ContextMenu|Wheel)/.test(key)) return changes.push([key, value, true, []]);
623
626
  // Split dashed props
624
627
  let entries = [];
625
628
  if (key.includes('-')) entries = key.split('-');
@@ -1086,6 +1089,25 @@ function createEvents(store) {
1086
1089
  case 'onPointerLeave':
1087
1090
  case 'onPointerCancel':
1088
1091
  return () => cancelPointer([]);
1092
+ case 'onLostPointerCapture':
1093
+ return event => {
1094
+ const {
1095
+ internal
1096
+ } = store.getState();
1097
+ if ('pointerId' in event && internal.capturedMap.has(event.pointerId)) {
1098
+ // If the object event interface had onLostPointerCapture, we'd call it here on every
1099
+ // object that's getting removed. We call it on the next frame because onLostPointerCapture
1100
+ // fires before onPointerUp. Otherwise pointerUp would never be called if the event didn't
1101
+ // happen in the object it originated from, leaving components in a in-between state.
1102
+ requestAnimationFrame(() => {
1103
+ // Only release if pointer-up didn't do it already
1104
+ if (internal.capturedMap.has(event.pointerId)) {
1105
+ internal.capturedMap.delete(event.pointerId);
1106
+ cancelPointer([]);
1107
+ }
1108
+ });
1109
+ }
1110
+ };
1089
1111
  }
1090
1112
 
1091
1113
  // Any other pointer goes here ...
@@ -1100,7 +1122,6 @@ function createEvents(store) {
1100
1122
 
1101
1123
  // Get fresh intersects
1102
1124
  const isPointerMove = name === 'onPointerMove';
1103
- const isLostPointerCapture = name === 'onLostPointerCapture';
1104
1125
  const isClickEvent = name === 'onClick' || name === 'onContextMenu' || name === 'onDoubleClick';
1105
1126
  const filter = isPointerMove ? filterPointerEvents : undefined;
1106
1127
  const hits = intersect(event, filter);
@@ -1120,7 +1141,6 @@ function createEvents(store) {
1120
1141
  if (onPointerMissed) onPointerMissed(event);
1121
1142
  }
1122
1143
  }
1123
-
1124
1144
  // Take care of unhover
1125
1145
  if (isPointerMove) cancelPointer(hits);
1126
1146
  function onIntersect(data) {
@@ -1164,24 +1184,6 @@ function createEvents(store) {
1164
1184
  }
1165
1185
  // Call mouse move
1166
1186
  handlers.onPointerMove == null ? void 0 : handlers.onPointerMove(data);
1167
- } else if (isLostPointerCapture) {
1168
- const {
1169
- internal
1170
- } = store.getState();
1171
- if ('pointerId' in event && internal.capturedMap.has(event.pointerId)) {
1172
- // If the object event interface had onLostPointerCapture, we'd call it here on every
1173
- // object that's getting removed. We call it on the next frame because onLostPointerCapture
1174
- // fires before onPointerUp. Otherwise pointerUp would never be called if the event didn't
1175
- // happen in the object it originated from, leaving components in a in-between state.
1176
- requestAnimationFrame(() => {
1177
- // Only release if pointer-up didn't do it already
1178
- if (internal.capturedMap.has(event.pointerId)) {
1179
- internal.capturedMap.delete(event.pointerId);
1180
- cancelPointer([]);
1181
- handlers.onLostPointerCapture == null ? void 0 : handlers.onLostPointerCapture(data);
1182
- }
1183
- });
1184
- }
1185
1187
  } else {
1186
1188
  // All other events ...
1187
1189
  const handler = handlers[name];
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var index = require('./index-12cac964.cjs.dev.js');
5
+ var index = require('./index-ab4b9c97.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('./index-ca508128.cjs.prod.js');
5
+ var index = require('./index-1fcbd5a8.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 useIsomorphicLayoutEffect, b as createRoot, i as isRef, E as ErrorBoundary, B as Block, d as unmountComponentAtNode } from './index-faa0fc56.esm.js';
2
- export { t as ReactThreeFiber, w as _roots, v as act, o as addAfterEffect, n as addEffect, p as addTail, m as advance, j as applyProps, f as context, c as createEvents, g as createPortal, b as createRoot, k as dispose, e as extend, q as flushGlobalEffects, s as getRootState, l as invalidate, h as reconciler, r as render, d as unmountComponentAtNode, A as useFrame, C as useGraph, x as useInstanceHandle, D as useLoader, y as useStore, z as useThree } from './index-faa0fc56.esm.js';
1
+ import { c as createEvents, e as extend, u as useMutableCallback, a as useIsomorphicLayoutEffect, b as createRoot, i as isRef, E as ErrorBoundary, B as Block, d as unmountComponentAtNode } from './index-21bbaaf9.esm.js';
2
+ export { t as ReactThreeFiber, w as _roots, v as act, o as addAfterEffect, n as addEffect, p as addTail, m as advance, j as applyProps, f as context, c as createEvents, g as createPortal, b as createRoot, k as dispose, e as extend, q as flushGlobalEffects, s as getRootState, l as invalidate, h as reconciler, r as render, d as unmountComponentAtNode, A as useFrame, C as useGraph, x as useInstanceHandle, D as useLoader, y as useStore, z as useThree } from './index-21bbaaf9.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';
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var index = require('../../dist/index-12cac964.cjs.dev.js');
5
+ var index = require('../../dist/index-ab4b9c97.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-ca508128.cjs.prod.js');
5
+ var index = require('../../dist/index-1fcbd5a8.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, b as createRoot, E as ErrorBoundary, B as Block, d as unmountComponentAtNode } from '../../dist/index-faa0fc56.esm.js';
2
- export { t as ReactThreeFiber, w as _roots, v as act, o as addAfterEffect, n as addEffect, p as addTail, m as advance, j as applyProps, f as context, c as createEvents, g as createPortal, b as createRoot, k as dispose, e as extend, q as flushGlobalEffects, s as getRootState, l as invalidate, h as reconciler, r as render, d as unmountComponentAtNode, A as useFrame, C as useGraph, x as useInstanceHandle, D as useLoader, y as useStore, z as useThree } from '../../dist/index-faa0fc56.esm.js';
1
+ import { c as createEvents, e as extend, u as useMutableCallback, b as createRoot, E as ErrorBoundary, B as Block, d as unmountComponentAtNode } from '../../dist/index-21bbaaf9.esm.js';
2
+ export { t as ReactThreeFiber, w as _roots, v as act, o as addAfterEffect, n as addEffect, p as addTail, m as advance, j as applyProps, f as context, c as createEvents, g as createPortal, b as createRoot, k as dispose, e as extend, q as flushGlobalEffects, s as getRootState, l as invalidate, h as reconciler, r as render, d as unmountComponentAtNode, A as useFrame, C as useGraph, x as useInstanceHandle, D as useLoader, y as useStore, z as useThree } from '../../dist/index-21bbaaf9.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.12.1",
3
+ "version": "8.12.2",
4
4
  "description": "A React renderer for Threejs",
5
5
  "keywords": [
6
6
  "react",