@react-three/fiber 8.16.7 → 8.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/dist/{index-4664c596.cjs.prod.js → events-2e7e6eab.cjs.prod.js} +100 -3
- package/dist/{index-ba8afaa4.esm.js → events-3515660a.esm.js} +99 -4
- package/dist/{index-f983265a.cjs.dev.js → events-c54ce65e.cjs.dev.js} +100 -3
- package/dist/react-three-fiber.cjs.dev.js +210 -120
- package/dist/react-three-fiber.cjs.prod.js +210 -120
- package/dist/react-three-fiber.esm.js +172 -83
- package/native/dist/react-three-fiber-native.cjs.dev.js +201 -133
- package/native/dist/react-three-fiber-native.cjs.prod.js +201 -133
- package/native/dist/react-three-fiber-native.esm.js +167 -101
- package/package.json +3 -2
- package/dist/declarations/src/core/events.d.ts +0 -93
- package/dist/declarations/src/core/hooks.d.ts +0 -57
- package/dist/declarations/src/core/index.d.ts +0 -87
- package/dist/declarations/src/core/loop.d.ts +0 -38
- package/dist/declarations/src/core/renderer.d.ts +0 -58
- package/dist/declarations/src/core/store.d.ts +0 -138
- package/dist/declarations/src/core/utils.d.ts +0 -134
- package/dist/declarations/src/index.d.ts +0 -12
- package/dist/declarations/src/native/Canvas.d.ts +0 -14
- package/dist/declarations/src/native/events.d.ts +0 -5
- package/dist/declarations/src/native/polyfills.d.ts +0 -1
- package/dist/declarations/src/native.d.ts +0 -12
- package/dist/declarations/src/three-types.d.ts +0 -393
- package/dist/declarations/src/web/Canvas.d.ts +0 -24
- package/dist/declarations/src/web/events.d.ts +0 -5
|
@@ -1,100 +1,189 @@
|
|
|
1
|
-
import { c as
|
|
2
|
-
export { t as ReactThreeFiber,
|
|
1
|
+
import { c as createPointerEvents, 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 './events-3515660a.esm.js';
|
|
2
|
+
export { t as ReactThreeFiber, z as _roots, x as act, p as addAfterEffect, o as addEffect, q as addTail, n as advance, k as applyProps, y as buildGraph, g as context, f as createEvents, c as createPointerEvents, h as createPortal, b as createRoot, l as dispose, c as events, e as extend, s as flushGlobalEffects, v as flushSync, w as getRootState, m as invalidate, j as reconciler, r as render, d as unmountComponentAtNode, F as useFrame, G as useGraph, A as useInstanceHandle, H as useLoader, C as useStore, D as useThree } from './events-3515660a.esm.js';
|
|
3
3
|
import * as React from 'react';
|
|
4
|
+
import { useState, useRef, useEffect, useMemo } from 'react';
|
|
4
5
|
import * as THREE from 'three';
|
|
5
|
-
import
|
|
6
|
+
import createDebounce from 'debounce';
|
|
6
7
|
import { FiberProvider, useContextBridge } from 'its-fine';
|
|
7
8
|
import { jsx } from 'react/jsx-runtime';
|
|
8
9
|
import 'react-reconciler/constants';
|
|
9
10
|
import 'zustand';
|
|
11
|
+
import 'suspend-react';
|
|
10
12
|
import 'react-reconciler';
|
|
11
13
|
import 'scheduler';
|
|
12
|
-
import 'suspend-react';
|
|
13
14
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
target.addEventListener(eventName, event, {
|
|
70
|
-
passive
|
|
71
|
-
});
|
|
72
|
-
});
|
|
73
|
-
},
|
|
74
|
-
disconnect: () => {
|
|
15
|
+
/* eslint-disable react-hooks/rules-of-hooks */
|
|
16
|
+
function useMeasure({
|
|
17
|
+
debounce,
|
|
18
|
+
scroll,
|
|
19
|
+
polyfill,
|
|
20
|
+
offsetSize
|
|
21
|
+
} = {
|
|
22
|
+
debounce: 0,
|
|
23
|
+
scroll: false,
|
|
24
|
+
offsetSize: false
|
|
25
|
+
}) {
|
|
26
|
+
const ResizeObserver = polyfill || typeof window !== 'undefined' && window.ResizeObserver;
|
|
27
|
+
const [bounds, set] = useState({
|
|
28
|
+
left: 0,
|
|
29
|
+
top: 0,
|
|
30
|
+
width: 0,
|
|
31
|
+
height: 0,
|
|
32
|
+
bottom: 0,
|
|
33
|
+
right: 0,
|
|
34
|
+
x: 0,
|
|
35
|
+
y: 0
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
// In test mode
|
|
39
|
+
if (!ResizeObserver) {
|
|
40
|
+
// @ts-ignore
|
|
41
|
+
bounds.width = 1280;
|
|
42
|
+
// @ts-ignore
|
|
43
|
+
bounds.height = 800;
|
|
44
|
+
return [() => {}, bounds, () => {}];
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// keep all state in a ref
|
|
48
|
+
const state = useRef({
|
|
49
|
+
element: null,
|
|
50
|
+
scrollContainers: null,
|
|
51
|
+
resizeObserver: null,
|
|
52
|
+
lastBounds: bounds
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
// set actual debounce values early, so effects know if they should react accordingly
|
|
56
|
+
const scrollDebounce = debounce ? typeof debounce === 'number' ? debounce : debounce.scroll : null;
|
|
57
|
+
const resizeDebounce = debounce ? typeof debounce === 'number' ? debounce : debounce.resize : null;
|
|
58
|
+
|
|
59
|
+
// make sure to update state only as long as the component is truly mounted
|
|
60
|
+
const mounted = useRef(false);
|
|
61
|
+
useEffect(() => {
|
|
62
|
+
mounted.current = true;
|
|
63
|
+
return () => void (mounted.current = false);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
// memoize handlers, so event-listeners know when they should update
|
|
67
|
+
const [forceRefresh, resizeChange, scrollChange] = useMemo(() => {
|
|
68
|
+
const callback = () => {
|
|
69
|
+
if (!state.current.element) return;
|
|
75
70
|
const {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
71
|
+
left,
|
|
72
|
+
top,
|
|
73
|
+
width,
|
|
74
|
+
height,
|
|
75
|
+
bottom,
|
|
76
|
+
right,
|
|
77
|
+
x,
|
|
78
|
+
y
|
|
79
|
+
} = state.current.element.getBoundingClientRect();
|
|
80
|
+
const size = {
|
|
81
|
+
left,
|
|
82
|
+
top,
|
|
83
|
+
width,
|
|
84
|
+
height,
|
|
85
|
+
bottom,
|
|
86
|
+
right,
|
|
87
|
+
x,
|
|
88
|
+
y
|
|
89
|
+
};
|
|
90
|
+
if (state.current.element instanceof HTMLElement && offsetSize) {
|
|
91
|
+
size.height = state.current.element.offsetHeight;
|
|
92
|
+
size.width = state.current.element.offsetWidth;
|
|
93
93
|
}
|
|
94
|
+
Object.freeze(size);
|
|
95
|
+
if (mounted.current && !areBoundsEqual(state.current.lastBounds, size)) set(state.current.lastBounds = size);
|
|
96
|
+
};
|
|
97
|
+
return [callback, resizeDebounce ? createDebounce(callback, resizeDebounce) : callback, scrollDebounce ? createDebounce(callback, scrollDebounce) : callback];
|
|
98
|
+
}, [set, offsetSize, scrollDebounce, resizeDebounce]);
|
|
99
|
+
|
|
100
|
+
// cleanup current scroll-listeners / observers
|
|
101
|
+
function removeListeners() {
|
|
102
|
+
if (state.current.scrollContainers) {
|
|
103
|
+
state.current.scrollContainers.forEach(element => element.removeEventListener('scroll', scrollChange, true));
|
|
104
|
+
state.current.scrollContainers = null;
|
|
105
|
+
}
|
|
106
|
+
if (state.current.resizeObserver) {
|
|
107
|
+
state.current.resizeObserver.disconnect();
|
|
108
|
+
state.current.resizeObserver = null;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// add scroll-listeners / observers
|
|
113
|
+
function addListeners() {
|
|
114
|
+
if (!state.current.element) return;
|
|
115
|
+
state.current.resizeObserver = new ResizeObserver(scrollChange);
|
|
116
|
+
state.current.resizeObserver.observe(state.current.element);
|
|
117
|
+
if (scroll && state.current.scrollContainers) {
|
|
118
|
+
state.current.scrollContainers.forEach(scrollContainer => scrollContainer.addEventListener('scroll', scrollChange, {
|
|
119
|
+
capture: true,
|
|
120
|
+
passive: true
|
|
121
|
+
}));
|
|
94
122
|
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// the ref we expose to the user
|
|
126
|
+
const ref = node => {
|
|
127
|
+
if (!node || node === state.current.element) return;
|
|
128
|
+
removeListeners();
|
|
129
|
+
state.current.element = node;
|
|
130
|
+
state.current.scrollContainers = findScrollContainers(node);
|
|
131
|
+
addListeners();
|
|
95
132
|
};
|
|
133
|
+
|
|
134
|
+
// add general event listeners
|
|
135
|
+
useOnWindowScroll(scrollChange, Boolean(scroll));
|
|
136
|
+
useOnWindowResize(resizeChange);
|
|
137
|
+
|
|
138
|
+
// respond to changes that are relevant for the listeners
|
|
139
|
+
useEffect(() => {
|
|
140
|
+
removeListeners();
|
|
141
|
+
addListeners();
|
|
142
|
+
}, [scroll, scrollChange, resizeChange]);
|
|
143
|
+
|
|
144
|
+
// remove all listeners when the components unmounts
|
|
145
|
+
useEffect(() => removeListeners, []);
|
|
146
|
+
return [ref, bounds, forceRefresh];
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// Adds native resize listener to window
|
|
150
|
+
function useOnWindowResize(onWindowResize) {
|
|
151
|
+
useEffect(() => {
|
|
152
|
+
const cb = onWindowResize;
|
|
153
|
+
window.addEventListener('resize', cb);
|
|
154
|
+
return () => void window.removeEventListener('resize', cb);
|
|
155
|
+
}, [onWindowResize]);
|
|
156
|
+
}
|
|
157
|
+
function useOnWindowScroll(onScroll, enabled) {
|
|
158
|
+
useEffect(() => {
|
|
159
|
+
if (enabled) {
|
|
160
|
+
const cb = onScroll;
|
|
161
|
+
window.addEventListener('scroll', cb, {
|
|
162
|
+
capture: true,
|
|
163
|
+
passive: true
|
|
164
|
+
});
|
|
165
|
+
return () => void window.removeEventListener('scroll', cb, true);
|
|
166
|
+
}
|
|
167
|
+
}, [onScroll, enabled]);
|
|
96
168
|
}
|
|
97
169
|
|
|
170
|
+
// Returns a list of scroll offsets
|
|
171
|
+
function findScrollContainers(element) {
|
|
172
|
+
const result = [];
|
|
173
|
+
if (!element || element === document.body) return result;
|
|
174
|
+
const {
|
|
175
|
+
overflow,
|
|
176
|
+
overflowX,
|
|
177
|
+
overflowY
|
|
178
|
+
} = window.getComputedStyle(element);
|
|
179
|
+
if ([overflow, overflowX, overflowY].some(prop => prop === 'auto' || prop === 'scroll')) result.push(element);
|
|
180
|
+
return [...result, ...findScrollContainers(element.parentElement)];
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
// Checks if element boundaries are equal
|
|
184
|
+
const keys = ['x', 'y', 'top', 'bottom', 'left', 'right', 'width', 'height'];
|
|
185
|
+
const areBoundsEqual = (a, b) => keys.every(key => a[key] === b[key]);
|
|
186
|
+
|
|
98
187
|
const CanvasImpl = /*#__PURE__*/React.forwardRef(function Canvas({
|
|
99
188
|
children,
|
|
100
189
|
fallback,
|
|
@@ -245,4 +334,4 @@ const Canvas = /*#__PURE__*/React.forwardRef(function CanvasWrapper(props, ref)
|
|
|
245
334
|
});
|
|
246
335
|
});
|
|
247
336
|
|
|
248
|
-
export { Canvas
|
|
337
|
+
export { Canvas };
|