@react-three/fiber 9.0.0-rc.0 → 9.0.0-rc.10
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 +24 -0
- package/dist/declarations/src/core/events.d.ts +1 -0
- package/dist/declarations/src/core/hooks.d.ts +13 -12
- package/dist/declarations/src/core/index.d.ts +1 -1
- package/dist/declarations/src/core/reconciler.d.ts +0 -5
- package/dist/declarations/src/core/renderer.d.ts +5 -3
- package/dist/declarations/src/core/utils.d.ts +80 -31
- package/dist/declarations/src/native/Canvas.d.ts +2 -3
- package/dist/declarations/src/three-types.d.ts +5 -1
- package/dist/declarations/src/web/Canvas.d.ts +3 -4
- package/dist/{events-5a08b43f.esm.js → events-aba3c3d1.esm.js} +972 -979
- package/dist/{events-aef54ace.cjs.prod.js → events-b02714fc.cjs.dev.js} +970 -977
- package/dist/{events-fa0fb3db.cjs.dev.js → events-bd708dc8.cjs.prod.js} +970 -978
- package/dist/react-three-fiber.cjs.dev.js +60 -252
- package/dist/react-three-fiber.cjs.prod.js +60 -252
- package/dist/react-three-fiber.esm.js +59 -251
- package/native/dist/react-three-fiber-native.cjs.dev.js +63 -63
- package/native/dist/react-three-fiber-native.cjs.prod.js +63 -63
- package/native/dist/react-three-fiber-native.esm.js +64 -63
- package/package.json +11 -12
- package/dist/declarations/src/web/use-measure.d.ts +0 -34
|
@@ -2,17 +2,17 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var events = require('./events-
|
|
5
|
+
var events = require('./events-b02714fc.cjs.dev.js');
|
|
6
6
|
var React = require('react');
|
|
7
7
|
var THREE = require('three');
|
|
8
|
-
var
|
|
8
|
+
var useMeasure = require('react-use-measure');
|
|
9
9
|
var itsFine = require('its-fine');
|
|
10
10
|
var jsxRuntime = require('react/jsx-runtime');
|
|
11
11
|
require('react-reconciler/constants');
|
|
12
12
|
require('zustand/traditional');
|
|
13
|
-
require('suspend-react');
|
|
14
13
|
require('react-reconciler');
|
|
15
14
|
require('scheduler');
|
|
15
|
+
require('suspend-react');
|
|
16
16
|
|
|
17
17
|
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
|
|
18
18
|
|
|
@@ -36,203 +36,10 @@ function _interopNamespace(e) {
|
|
|
36
36
|
|
|
37
37
|
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
38
38
|
var THREE__namespace = /*#__PURE__*/_interopNamespace(THREE);
|
|
39
|
-
var
|
|
40
|
-
|
|
41
|
-
/* eslint-disable react-hooks/rules-of-hooks */
|
|
42
|
-
function useMeasure({
|
|
43
|
-
debounce,
|
|
44
|
-
scroll,
|
|
45
|
-
polyfill,
|
|
46
|
-
offsetSize
|
|
47
|
-
} = {
|
|
48
|
-
debounce: 0,
|
|
49
|
-
scroll: false,
|
|
50
|
-
offsetSize: false
|
|
51
|
-
}) {
|
|
52
|
-
const ResizeObserver = polyfill || typeof window !== 'undefined' && window.ResizeObserver;
|
|
53
|
-
const [bounds, set] = React.useState({
|
|
54
|
-
left: 0,
|
|
55
|
-
top: 0,
|
|
56
|
-
width: 0,
|
|
57
|
-
height: 0,
|
|
58
|
-
bottom: 0,
|
|
59
|
-
right: 0,
|
|
60
|
-
x: 0,
|
|
61
|
-
y: 0
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
// In test mode
|
|
65
|
-
if (!ResizeObserver) {
|
|
66
|
-
// @ts-ignore
|
|
67
|
-
bounds.width = 1280;
|
|
68
|
-
// @ts-ignore
|
|
69
|
-
bounds.height = 800;
|
|
70
|
-
return [() => {}, bounds, () => {}];
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
// keep all state in a ref
|
|
74
|
-
const state = React.useRef({
|
|
75
|
-
element: null,
|
|
76
|
-
scrollContainers: null,
|
|
77
|
-
resizeObserver: null,
|
|
78
|
-
lastBounds: bounds,
|
|
79
|
-
orientationHandler: null
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
// set actual debounce values early, so effects know if they should react accordingly
|
|
83
|
-
const scrollDebounce = debounce ? typeof debounce === 'number' ? debounce : debounce.scroll : null;
|
|
84
|
-
const resizeDebounce = debounce ? typeof debounce === 'number' ? debounce : debounce.resize : null;
|
|
85
|
-
|
|
86
|
-
// make sure to update state only as long as the component is truly mounted
|
|
87
|
-
const mounted = React.useRef(false);
|
|
88
|
-
React.useEffect(() => {
|
|
89
|
-
mounted.current = true;
|
|
90
|
-
return () => void (mounted.current = false);
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
// memoize handlers, so event-listeners know when they should update
|
|
94
|
-
const [forceRefresh, resizeChange, scrollChange] = React.useMemo(() => {
|
|
95
|
-
const callback = () => {
|
|
96
|
-
if (!state.current.element) return;
|
|
97
|
-
const {
|
|
98
|
-
left,
|
|
99
|
-
top,
|
|
100
|
-
width,
|
|
101
|
-
height,
|
|
102
|
-
bottom,
|
|
103
|
-
right,
|
|
104
|
-
x,
|
|
105
|
-
y
|
|
106
|
-
} = state.current.element.getBoundingClientRect();
|
|
107
|
-
const size = {
|
|
108
|
-
left,
|
|
109
|
-
top,
|
|
110
|
-
width,
|
|
111
|
-
height,
|
|
112
|
-
bottom,
|
|
113
|
-
right,
|
|
114
|
-
x,
|
|
115
|
-
y
|
|
116
|
-
};
|
|
117
|
-
if (state.current.element instanceof HTMLElement && offsetSize) {
|
|
118
|
-
size.height = state.current.element.offsetHeight;
|
|
119
|
-
size.width = state.current.element.offsetWidth;
|
|
120
|
-
}
|
|
121
|
-
Object.freeze(size);
|
|
122
|
-
if (mounted.current && !areBoundsEqual(state.current.lastBounds, size)) set(state.current.lastBounds = size);
|
|
123
|
-
};
|
|
124
|
-
return [callback, resizeDebounce ? createDebounce__default["default"](callback, resizeDebounce) : callback, scrollDebounce ? createDebounce__default["default"](callback, scrollDebounce) : callback];
|
|
125
|
-
}, [set, offsetSize, scrollDebounce, resizeDebounce]);
|
|
126
|
-
|
|
127
|
-
// cleanup current scroll-listeners / observers
|
|
128
|
-
function removeListeners() {
|
|
129
|
-
if (state.current.scrollContainers) {
|
|
130
|
-
state.current.scrollContainers.forEach(element => element.removeEventListener('scroll', scrollChange, true));
|
|
131
|
-
state.current.scrollContainers = null;
|
|
132
|
-
}
|
|
133
|
-
if (state.current.resizeObserver) {
|
|
134
|
-
state.current.resizeObserver.disconnect();
|
|
135
|
-
state.current.resizeObserver = null;
|
|
136
|
-
}
|
|
137
|
-
if (state.current.orientationHandler) {
|
|
138
|
-
if ('orientation' in screen && 'removeEventListener' in screen.orientation) {
|
|
139
|
-
screen.orientation.removeEventListener('change', state.current.orientationHandler);
|
|
140
|
-
} else if ('onorientationchange' in window) {
|
|
141
|
-
window.removeEventListener('orientationchange', state.current.orientationHandler);
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
// add scroll-listeners / observers
|
|
147
|
-
function addListeners() {
|
|
148
|
-
var _state$current$resize;
|
|
149
|
-
if (!state.current.element) return;
|
|
150
|
-
state.current.resizeObserver = new ResizeObserver(resizeChange);
|
|
151
|
-
(_state$current$resize = state.current.resizeObserver) == null ? void 0 : _state$current$resize.observe(state.current.element);
|
|
152
|
-
if (scroll && state.current.scrollContainers) {
|
|
153
|
-
state.current.scrollContainers.forEach(scrollContainer => scrollContainer.addEventListener('scroll', scrollChange, {
|
|
154
|
-
capture: true,
|
|
155
|
-
passive: true
|
|
156
|
-
}));
|
|
157
|
-
}
|
|
39
|
+
var useMeasure__default = /*#__PURE__*/_interopDefault(useMeasure);
|
|
158
40
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
scrollChange();
|
|
162
|
-
};
|
|
163
|
-
|
|
164
|
-
// Use screen.orientation if available
|
|
165
|
-
if ('orientation' in screen && 'addEventListener' in screen.orientation) {
|
|
166
|
-
screen.orientation.addEventListener('change', state.current.orientationHandler);
|
|
167
|
-
} else if ('onorientationchange' in window) {
|
|
168
|
-
// Fallback to orientationchange event
|
|
169
|
-
window.addEventListener('orientationchange', state.current.orientationHandler);
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
// the ref we expose to the user
|
|
174
|
-
const ref = node => {
|
|
175
|
-
if (!node || node === state.current.element) return;
|
|
176
|
-
removeListeners();
|
|
177
|
-
state.current.element = node;
|
|
178
|
-
state.current.scrollContainers = findScrollContainers(node);
|
|
179
|
-
addListeners();
|
|
180
|
-
};
|
|
181
|
-
|
|
182
|
-
// add general event listeners
|
|
183
|
-
useOnWindowScroll(scrollChange, Boolean(scroll));
|
|
184
|
-
useOnWindowResize(resizeChange);
|
|
185
|
-
|
|
186
|
-
// respond to changes that are relevant for the listeners
|
|
187
|
-
React.useEffect(() => {
|
|
188
|
-
removeListeners();
|
|
189
|
-
addListeners();
|
|
190
|
-
}, [scroll, scrollChange, resizeChange]);
|
|
191
|
-
|
|
192
|
-
// remove all listeners when the components unmounts
|
|
193
|
-
React.useEffect(() => removeListeners, []);
|
|
194
|
-
return [ref, bounds, forceRefresh];
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
// Adds native resize listener to window
|
|
198
|
-
function useOnWindowResize(onWindowResize) {
|
|
199
|
-
React.useEffect(() => {
|
|
200
|
-
const cb = onWindowResize;
|
|
201
|
-
window.addEventListener('resize', cb);
|
|
202
|
-
return () => void window.removeEventListener('resize', cb);
|
|
203
|
-
}, [onWindowResize]);
|
|
204
|
-
}
|
|
205
|
-
function useOnWindowScroll(onScroll, enabled) {
|
|
206
|
-
React.useEffect(() => {
|
|
207
|
-
if (enabled) {
|
|
208
|
-
const cb = onScroll;
|
|
209
|
-
window.addEventListener('scroll', cb, {
|
|
210
|
-
capture: true,
|
|
211
|
-
passive: true
|
|
212
|
-
});
|
|
213
|
-
return () => void window.removeEventListener('scroll', cb, true);
|
|
214
|
-
}
|
|
215
|
-
}, [onScroll, enabled]);
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
// Returns a list of scroll offsets
|
|
219
|
-
function findScrollContainers(element) {
|
|
220
|
-
const result = [];
|
|
221
|
-
if (!element || element === document.body) return result;
|
|
222
|
-
const {
|
|
223
|
-
overflow,
|
|
224
|
-
overflowX,
|
|
225
|
-
overflowY
|
|
226
|
-
} = window.getComputedStyle(element);
|
|
227
|
-
if ([overflow, overflowX, overflowY].some(prop => prop === 'auto' || prop === 'scroll')) result.push(element);
|
|
228
|
-
return [...result, ...findScrollContainers(element.parentElement)];
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
// Checks if element boundaries are equal
|
|
232
|
-
const keys = ['x', 'y', 'top', 'bottom', 'left', 'right', 'width', 'height'];
|
|
233
|
-
const areBoundsEqual = (a, b) => keys.every(key => a[key] === b[key]);
|
|
234
|
-
|
|
235
|
-
const CanvasImpl = /*#__PURE__*/React__namespace.forwardRef(function Canvas({
|
|
41
|
+
function CanvasImpl({
|
|
42
|
+
ref,
|
|
236
43
|
children,
|
|
237
44
|
fallback,
|
|
238
45
|
resize,
|
|
@@ -255,13 +62,13 @@ const CanvasImpl = /*#__PURE__*/React__namespace.forwardRef(function Canvas({
|
|
|
255
62
|
onPointerMissed,
|
|
256
63
|
onCreated,
|
|
257
64
|
...props
|
|
258
|
-
}
|
|
65
|
+
}) {
|
|
259
66
|
// Create a known catalogue of Threejs-native elements
|
|
260
67
|
// This will include the entire THREE namespace by default, users can extend
|
|
261
68
|
// their own elements by using the createRoot API instead
|
|
262
69
|
React__namespace.useMemo(() => events.extend(THREE__namespace), []);
|
|
263
70
|
const Bridge = events.useBridge();
|
|
264
|
-
const [containerRef, containerRect] =
|
|
71
|
+
const [containerRef, containerRect] = useMeasure__default["default"]({
|
|
265
72
|
scroll: true,
|
|
266
73
|
debounce: {
|
|
267
74
|
scroll: 50,
|
|
@@ -271,7 +78,7 @@ const CanvasImpl = /*#__PURE__*/React__namespace.forwardRef(function Canvas({
|
|
|
271
78
|
});
|
|
272
79
|
const canvasRef = React__namespace.useRef(null);
|
|
273
80
|
const divRef = React__namespace.useRef(null);
|
|
274
|
-
React__namespace.useImperativeHandle(
|
|
81
|
+
React__namespace.useImperativeHandle(ref, () => canvasRef.current);
|
|
275
82
|
const handlePointerMissed = events.useMutableCallback(onPointerMissed);
|
|
276
83
|
const [block, setBlock] = React__namespace.useState(false);
|
|
277
84
|
const [error, setError] = React__namespace.useState(false);
|
|
@@ -285,52 +92,55 @@ const CanvasImpl = /*#__PURE__*/React__namespace.forwardRef(function Canvas({
|
|
|
285
92
|
const canvas = canvasRef.current;
|
|
286
93
|
if (containerRect.width > 0 && containerRect.height > 0 && canvas) {
|
|
287
94
|
if (!root.current) root.current = events.createRoot(canvas);
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
95
|
+
async function run() {
|
|
96
|
+
await root.current.configure({
|
|
97
|
+
gl,
|
|
98
|
+
scene,
|
|
99
|
+
events: events$1,
|
|
100
|
+
shadows,
|
|
101
|
+
linear,
|
|
102
|
+
flat,
|
|
103
|
+
legacy,
|
|
104
|
+
orthographic,
|
|
105
|
+
frameloop,
|
|
106
|
+
dpr,
|
|
107
|
+
performance,
|
|
108
|
+
raycaster,
|
|
109
|
+
camera,
|
|
110
|
+
size: containerRect,
|
|
111
|
+
// Pass mutable reference to onPointerMissed so it's free to update
|
|
112
|
+
onPointerMissed: (...args) => handlePointerMissed.current == null ? void 0 : handlePointerMissed.current(...args),
|
|
113
|
+
onCreated: state => {
|
|
114
|
+
// Connect to event source
|
|
115
|
+
state.events.connect == null ? void 0 : state.events.connect(eventSource ? events.isRef(eventSource) ? eventSource.current : eventSource : divRef.current);
|
|
116
|
+
// Set up compute function
|
|
117
|
+
if (eventPrefix) {
|
|
118
|
+
state.setEvents({
|
|
119
|
+
compute: (event, state) => {
|
|
120
|
+
const x = event[eventPrefix + 'X'];
|
|
121
|
+
const y = event[eventPrefix + 'Y'];
|
|
122
|
+
state.pointer.set(x / state.size.width * 2 - 1, -(y / state.size.height) * 2 + 1);
|
|
123
|
+
state.raycaster.setFromCamera(state.pointer, state.camera);
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
// Call onCreated callback
|
|
128
|
+
onCreated == null ? void 0 : onCreated(state);
|
|
318
129
|
}
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
}),
|
|
330
|
-
children: children
|
|
130
|
+
});
|
|
131
|
+
root.current.render( /*#__PURE__*/jsxRuntime.jsx(Bridge, {
|
|
132
|
+
children: /*#__PURE__*/jsxRuntime.jsx(events.ErrorBoundary, {
|
|
133
|
+
set: setError,
|
|
134
|
+
children: /*#__PURE__*/jsxRuntime.jsx(React__namespace.Suspense, {
|
|
135
|
+
fallback: /*#__PURE__*/jsxRuntime.jsx(events.Block, {
|
|
136
|
+
set: setBlock
|
|
137
|
+
}),
|
|
138
|
+
children: children
|
|
139
|
+
})
|
|
331
140
|
})
|
|
332
|
-
})
|
|
333
|
-
}
|
|
141
|
+
}));
|
|
142
|
+
}
|
|
143
|
+
run();
|
|
334
144
|
}
|
|
335
145
|
});
|
|
336
146
|
React__namespace.useEffect(() => {
|
|
@@ -367,20 +177,19 @@ const CanvasImpl = /*#__PURE__*/React__namespace.forwardRef(function Canvas({
|
|
|
367
177
|
})
|
|
368
178
|
})
|
|
369
179
|
});
|
|
370
|
-
}
|
|
180
|
+
}
|
|
371
181
|
|
|
372
182
|
/**
|
|
373
183
|
* A DOM canvas which accepts threejs elements as children.
|
|
374
184
|
* @see https://docs.pmnd.rs/react-three-fiber/api/canvas
|
|
375
185
|
*/
|
|
376
|
-
|
|
186
|
+
function Canvas(props) {
|
|
377
187
|
return /*#__PURE__*/jsxRuntime.jsx(itsFine.FiberProvider, {
|
|
378
188
|
children: /*#__PURE__*/jsxRuntime.jsx(CanvasImpl, {
|
|
379
|
-
...props
|
|
380
|
-
ref: ref
|
|
189
|
+
...props
|
|
381
190
|
})
|
|
382
191
|
});
|
|
383
|
-
}
|
|
192
|
+
}
|
|
384
193
|
|
|
385
194
|
exports.ReactThreeFiber = events.threeTypes;
|
|
386
195
|
exports._roots = events._roots;
|
|
@@ -402,7 +211,6 @@ exports.flushGlobalEffects = events.flushGlobalEffects;
|
|
|
402
211
|
exports.getRootState = events.getRootState;
|
|
403
212
|
exports.invalidate = events.invalidate;
|
|
404
213
|
exports.reconciler = events.reconciler;
|
|
405
|
-
exports.render = events.render;
|
|
406
214
|
exports.unmountComponentAtNode = events.unmountComponentAtNode;
|
|
407
215
|
exports.useFrame = events.useFrame;
|
|
408
216
|
exports.useGraph = events.useGraph;
|