@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.
- package/CHANGELOG.md +1088 -1076
- package/dist/declarations/src/core/events.d.ts +91 -91
- package/dist/declarations/src/core/hooks.d.ts +51 -51
- package/dist/declarations/src/core/index.d.ts +13 -13
- package/dist/declarations/src/core/loop.d.ts +31 -31
- package/dist/declarations/src/core/reconciler.d.ts +52 -52
- package/dist/declarations/src/core/renderer.d.ts +89 -89
- package/dist/declarations/src/core/store.d.ts +130 -130
- package/dist/declarations/src/core/utils.d.ts +186 -186
- package/dist/declarations/src/index.d.ts +6 -6
- package/dist/declarations/src/native/Canvas.d.ts +13 -13
- package/dist/declarations/src/native/events.d.ts +4 -4
- package/dist/declarations/src/native.d.ts +6 -6
- package/dist/declarations/src/three-types.d.ts +62 -62
- package/dist/declarations/src/web/Canvas.d.ts +23 -23
- package/dist/declarations/src/web/events.d.ts +4 -4
- package/dist/{events-a7b08b1a.esm.js → events-06bc1550.esm.js} +84 -88
- package/dist/{events-b4061ace.cjs.dev.js → events-4464c9d4.cjs.dev.js} +84 -88
- package/dist/{events-60ed2d7b.cjs.prod.js → events-79ccf613.cjs.prod.js} +84 -88
- package/dist/react-three-fiber.cjs.dev.js +7 -201
- package/dist/react-three-fiber.cjs.prod.js +7 -201
- package/dist/react-three-fiber.esm.js +6 -201
- package/native/dist/react-three-fiber-native.cjs.d.ts +2 -0
- package/native/dist/react-three-fiber-native.cjs.dev.js +554 -0
- package/native/dist/react-three-fiber-native.cjs.js +7 -0
- package/native/dist/react-three-fiber-native.cjs.prod.js +554 -0
- package/native/dist/react-three-fiber-native.esm.js +502 -0
- package/native/package.json +5 -5
- package/package.json +87 -88
- package/readme.md +253 -253
- package/dist/declarations/src/web/use-measure.d.ts +0 -34
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var events = require('./events-
|
|
5
|
+
var events = require('./events-79ccf613.cjs.prod.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');
|
|
@@ -36,201 +36,7 @@ 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
|
-
}
|
|
158
|
-
|
|
159
|
-
// Handle orientation changes
|
|
160
|
-
state.current.orientationHandler = () => {
|
|
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]);
|
|
39
|
+
var useMeasure__default = /*#__PURE__*/_interopDefault(useMeasure);
|
|
234
40
|
|
|
235
41
|
function CanvasImpl({
|
|
236
42
|
ref,
|
|
@@ -262,7 +68,7 @@ function CanvasImpl({
|
|
|
262
68
|
// their own elements by using the createRoot API instead
|
|
263
69
|
React__namespace.useMemo(() => events.extend(THREE__namespace), []);
|
|
264
70
|
const Bridge = events.useBridge();
|
|
265
|
-
const [containerRef, containerRect] =
|
|
71
|
+
const [containerRef, containerRect] = useMeasure__default["default"]({
|
|
266
72
|
scroll: true,
|
|
267
73
|
debounce: {
|
|
268
74
|
scroll: 50,
|
|
@@ -373,9 +179,9 @@ function CanvasImpl({
|
|
|
373
179
|
});
|
|
374
180
|
}
|
|
375
181
|
|
|
376
|
-
/**
|
|
377
|
-
* A DOM canvas which accepts threejs elements as children.
|
|
378
|
-
* @see https://docs.pmnd.rs/react-three-fiber/api/canvas
|
|
182
|
+
/**
|
|
183
|
+
* A DOM canvas which accepts threejs elements as children.
|
|
184
|
+
* @see https://docs.pmnd.rs/react-three-fiber/api/canvas
|
|
379
185
|
*/
|
|
380
186
|
function Canvas(props) {
|
|
381
187
|
return /*#__PURE__*/jsxRuntime.jsx(itsFine.FiberProvider, {
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { e as extend, u as useBridge, a as useMutableCallback, b as useIsomorphicLayoutEffect, c as createRoot, i as isRef, E as ErrorBoundary, B as Block, d as unmountComponentAtNode, f as createPointerEvents } from './events-
|
|
2
|
-
export { t as ReactThreeFiber, _ as _roots, w as act, k as addAfterEffect, j as addEffect, l as addTail, n as advance, q as applyProps, x as buildGraph, p as context, g as createEvents, o as createPortal, c as createRoot, v as dispose, f as events, e as extend, h as flushGlobalEffects, s as getRootState, m as invalidate, r as reconciler, d as unmountComponentAtNode, C as useFrame, D as useGraph, y as useInstanceHandle, F as useLoader, z as useStore, A as useThree } from './events-
|
|
1
|
+
import { e as extend, u as useBridge, a as useMutableCallback, b as useIsomorphicLayoutEffect, c as createRoot, i as isRef, E as ErrorBoundary, B as Block, d as unmountComponentAtNode, f as createPointerEvents } from './events-06bc1550.esm.js';
|
|
2
|
+
export { t as ReactThreeFiber, _ as _roots, w as act, k as addAfterEffect, j as addEffect, l as addTail, n as advance, q as applyProps, x as buildGraph, p as context, g as createEvents, o as createPortal, c as createRoot, v as dispose, f as events, e as extend, h as flushGlobalEffects, s as getRootState, m as invalidate, r as reconciler, d as unmountComponentAtNode, C as useFrame, D as useGraph, y as useInstanceHandle, F as useLoader, z as useStore, A as useThree } from './events-06bc1550.esm.js';
|
|
3
3
|
import * as React from 'react';
|
|
4
|
-
import { useState, useRef, useEffect, useMemo } from 'react';
|
|
5
4
|
import * as THREE from 'three';
|
|
6
|
-
import
|
|
5
|
+
import useMeasure from 'react-use-measure';
|
|
7
6
|
import { FiberProvider } from 'its-fine';
|
|
8
7
|
import { jsx } from 'react/jsx-runtime';
|
|
9
8
|
import 'react-reconciler/constants';
|
|
@@ -12,200 +11,6 @@ import 'react-reconciler';
|
|
|
12
11
|
import 'scheduler';
|
|
13
12
|
import 'suspend-react';
|
|
14
13
|
|
|
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
|
-
orientationHandler: null
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
// set actual debounce values early, so effects know if they should react accordingly
|
|
57
|
-
const scrollDebounce = debounce ? typeof debounce === 'number' ? debounce : debounce.scroll : null;
|
|
58
|
-
const resizeDebounce = debounce ? typeof debounce === 'number' ? debounce : debounce.resize : null;
|
|
59
|
-
|
|
60
|
-
// make sure to update state only as long as the component is truly mounted
|
|
61
|
-
const mounted = useRef(false);
|
|
62
|
-
useEffect(() => {
|
|
63
|
-
mounted.current = true;
|
|
64
|
-
return () => void (mounted.current = false);
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
// memoize handlers, so event-listeners know when they should update
|
|
68
|
-
const [forceRefresh, resizeChange, scrollChange] = useMemo(() => {
|
|
69
|
-
const callback = () => {
|
|
70
|
-
if (!state.current.element) return;
|
|
71
|
-
const {
|
|
72
|
-
left,
|
|
73
|
-
top,
|
|
74
|
-
width,
|
|
75
|
-
height,
|
|
76
|
-
bottom,
|
|
77
|
-
right,
|
|
78
|
-
x,
|
|
79
|
-
y
|
|
80
|
-
} = state.current.element.getBoundingClientRect();
|
|
81
|
-
const size = {
|
|
82
|
-
left,
|
|
83
|
-
top,
|
|
84
|
-
width,
|
|
85
|
-
height,
|
|
86
|
-
bottom,
|
|
87
|
-
right,
|
|
88
|
-
x,
|
|
89
|
-
y
|
|
90
|
-
};
|
|
91
|
-
if (state.current.element instanceof HTMLElement && offsetSize) {
|
|
92
|
-
size.height = state.current.element.offsetHeight;
|
|
93
|
-
size.width = state.current.element.offsetWidth;
|
|
94
|
-
}
|
|
95
|
-
Object.freeze(size);
|
|
96
|
-
if (mounted.current && !areBoundsEqual(state.current.lastBounds, size)) set(state.current.lastBounds = size);
|
|
97
|
-
};
|
|
98
|
-
return [callback, resizeDebounce ? createDebounce(callback, resizeDebounce) : callback, scrollDebounce ? createDebounce(callback, scrollDebounce) : callback];
|
|
99
|
-
}, [set, offsetSize, scrollDebounce, resizeDebounce]);
|
|
100
|
-
|
|
101
|
-
// cleanup current scroll-listeners / observers
|
|
102
|
-
function removeListeners() {
|
|
103
|
-
if (state.current.scrollContainers) {
|
|
104
|
-
state.current.scrollContainers.forEach(element => element.removeEventListener('scroll', scrollChange, true));
|
|
105
|
-
state.current.scrollContainers = null;
|
|
106
|
-
}
|
|
107
|
-
if (state.current.resizeObserver) {
|
|
108
|
-
state.current.resizeObserver.disconnect();
|
|
109
|
-
state.current.resizeObserver = null;
|
|
110
|
-
}
|
|
111
|
-
if (state.current.orientationHandler) {
|
|
112
|
-
if ('orientation' in screen && 'removeEventListener' in screen.orientation) {
|
|
113
|
-
screen.orientation.removeEventListener('change', state.current.orientationHandler);
|
|
114
|
-
} else if ('onorientationchange' in window) {
|
|
115
|
-
window.removeEventListener('orientationchange', state.current.orientationHandler);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
// add scroll-listeners / observers
|
|
121
|
-
function addListeners() {
|
|
122
|
-
var _state$current$resize;
|
|
123
|
-
if (!state.current.element) return;
|
|
124
|
-
state.current.resizeObserver = new ResizeObserver(resizeChange);
|
|
125
|
-
(_state$current$resize = state.current.resizeObserver) == null ? void 0 : _state$current$resize.observe(state.current.element);
|
|
126
|
-
if (scroll && state.current.scrollContainers) {
|
|
127
|
-
state.current.scrollContainers.forEach(scrollContainer => scrollContainer.addEventListener('scroll', scrollChange, {
|
|
128
|
-
capture: true,
|
|
129
|
-
passive: true
|
|
130
|
-
}));
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
// Handle orientation changes
|
|
134
|
-
state.current.orientationHandler = () => {
|
|
135
|
-
scrollChange();
|
|
136
|
-
};
|
|
137
|
-
|
|
138
|
-
// Use screen.orientation if available
|
|
139
|
-
if ('orientation' in screen && 'addEventListener' in screen.orientation) {
|
|
140
|
-
screen.orientation.addEventListener('change', state.current.orientationHandler);
|
|
141
|
-
} else if ('onorientationchange' in window) {
|
|
142
|
-
// Fallback to orientationchange event
|
|
143
|
-
window.addEventListener('orientationchange', state.current.orientationHandler);
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
// the ref we expose to the user
|
|
148
|
-
const ref = node => {
|
|
149
|
-
if (!node || node === state.current.element) return;
|
|
150
|
-
removeListeners();
|
|
151
|
-
state.current.element = node;
|
|
152
|
-
state.current.scrollContainers = findScrollContainers(node);
|
|
153
|
-
addListeners();
|
|
154
|
-
};
|
|
155
|
-
|
|
156
|
-
// add general event listeners
|
|
157
|
-
useOnWindowScroll(scrollChange, Boolean(scroll));
|
|
158
|
-
useOnWindowResize(resizeChange);
|
|
159
|
-
|
|
160
|
-
// respond to changes that are relevant for the listeners
|
|
161
|
-
useEffect(() => {
|
|
162
|
-
removeListeners();
|
|
163
|
-
addListeners();
|
|
164
|
-
}, [scroll, scrollChange, resizeChange]);
|
|
165
|
-
|
|
166
|
-
// remove all listeners when the components unmounts
|
|
167
|
-
useEffect(() => removeListeners, []);
|
|
168
|
-
return [ref, bounds, forceRefresh];
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
// Adds native resize listener to window
|
|
172
|
-
function useOnWindowResize(onWindowResize) {
|
|
173
|
-
useEffect(() => {
|
|
174
|
-
const cb = onWindowResize;
|
|
175
|
-
window.addEventListener('resize', cb);
|
|
176
|
-
return () => void window.removeEventListener('resize', cb);
|
|
177
|
-
}, [onWindowResize]);
|
|
178
|
-
}
|
|
179
|
-
function useOnWindowScroll(onScroll, enabled) {
|
|
180
|
-
useEffect(() => {
|
|
181
|
-
if (enabled) {
|
|
182
|
-
const cb = onScroll;
|
|
183
|
-
window.addEventListener('scroll', cb, {
|
|
184
|
-
capture: true,
|
|
185
|
-
passive: true
|
|
186
|
-
});
|
|
187
|
-
return () => void window.removeEventListener('scroll', cb, true);
|
|
188
|
-
}
|
|
189
|
-
}, [onScroll, enabled]);
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
// Returns a list of scroll offsets
|
|
193
|
-
function findScrollContainers(element) {
|
|
194
|
-
const result = [];
|
|
195
|
-
if (!element || element === document.body) return result;
|
|
196
|
-
const {
|
|
197
|
-
overflow,
|
|
198
|
-
overflowX,
|
|
199
|
-
overflowY
|
|
200
|
-
} = window.getComputedStyle(element);
|
|
201
|
-
if ([overflow, overflowX, overflowY].some(prop => prop === 'auto' || prop === 'scroll')) result.push(element);
|
|
202
|
-
return [...result, ...findScrollContainers(element.parentElement)];
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
// Checks if element boundaries are equal
|
|
206
|
-
const keys = ['x', 'y', 'top', 'bottom', 'left', 'right', 'width', 'height'];
|
|
207
|
-
const areBoundsEqual = (a, b) => keys.every(key => a[key] === b[key]);
|
|
208
|
-
|
|
209
14
|
function CanvasImpl({
|
|
210
15
|
ref,
|
|
211
16
|
children,
|
|
@@ -347,9 +152,9 @@ function CanvasImpl({
|
|
|
347
152
|
});
|
|
348
153
|
}
|
|
349
154
|
|
|
350
|
-
/**
|
|
351
|
-
* A DOM canvas which accepts threejs elements as children.
|
|
352
|
-
* @see https://docs.pmnd.rs/react-three-fiber/api/canvas
|
|
155
|
+
/**
|
|
156
|
+
* A DOM canvas which accepts threejs elements as children.
|
|
157
|
+
* @see https://docs.pmnd.rs/react-three-fiber/api/canvas
|
|
353
158
|
*/
|
|
354
159
|
function Canvas(props) {
|
|
355
160
|
return /*#__PURE__*/jsx(FiberProvider, {
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export * from "../../dist/declarations/src/native";
|
|
2
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicmVhY3QtdGhyZWUtZmliZXItbmF0aXZlLmNqcy5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vZGlzdC9kZWNsYXJhdGlvbnMvc3JjL25hdGl2ZS5kLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBIn0=
|