@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
|
@@ -38,29 +38,29 @@ var threeTypes = /*#__PURE__*/Object.freeze({
|
|
|
38
38
|
__proto__: null
|
|
39
39
|
});
|
|
40
40
|
|
|
41
|
-
/**
|
|
42
|
-
* Returns the instance's initial (outmost) root.
|
|
41
|
+
/**
|
|
42
|
+
* Returns the instance's initial (outmost) root.
|
|
43
43
|
*/
|
|
44
44
|
function findInitialRoot(instance) {
|
|
45
45
|
let root = instance.root;
|
|
46
46
|
while (root.getState().previousRoot) root = root.getState().previousRoot;
|
|
47
47
|
return root;
|
|
48
48
|
}
|
|
49
|
-
/**
|
|
50
|
-
* Safely flush async effects when testing, simulating a legacy root.
|
|
49
|
+
/**
|
|
50
|
+
* Safely flush async effects when testing, simulating a legacy root.
|
|
51
51
|
*/
|
|
52
52
|
const act = React__namespace.act;
|
|
53
53
|
const isOrthographicCamera = def => def && def.isOrthographicCamera;
|
|
54
54
|
const isRef = obj => obj && obj.hasOwnProperty('current');
|
|
55
55
|
|
|
56
|
-
/**
|
|
57
|
-
* An SSR-friendly useLayoutEffect.
|
|
58
|
-
*
|
|
59
|
-
* React currently throws a warning when using useLayoutEffect on the server.
|
|
60
|
-
* To get around it, we can conditionally useEffect on the server (no-op) and
|
|
61
|
-
* useLayoutEffect elsewhere.
|
|
62
|
-
*
|
|
63
|
-
* @see https://github.com/facebook/react/issues/14927
|
|
56
|
+
/**
|
|
57
|
+
* An SSR-friendly useLayoutEffect.
|
|
58
|
+
*
|
|
59
|
+
* React currently throws a warning when using useLayoutEffect on the server.
|
|
60
|
+
* To get around it, we can conditionally useEffect on the server (no-op) and
|
|
61
|
+
* useLayoutEffect elsewhere.
|
|
62
|
+
*
|
|
63
|
+
* @see https://github.com/facebook/react/issues/14927
|
|
64
64
|
*/
|
|
65
65
|
const useIsomorphicLayoutEffect = /* @__PURE__ */((_window$document, _window$navigator) => typeof window !== 'undefined' && (((_window$document = window.document) == null ? void 0 : _window$document.createElement) || ((_window$navigator = window.navigator) == null ? void 0 : _window$navigator.product) === 'ReactNative'))() ? React__namespace.useLayoutEffect : React__namespace.useEffect;
|
|
66
66
|
function useMutableCallback(fn) {
|
|
@@ -68,8 +68,8 @@ function useMutableCallback(fn) {
|
|
|
68
68
|
useIsomorphicLayoutEffect(() => void (ref.current = fn), [fn]);
|
|
69
69
|
return ref;
|
|
70
70
|
}
|
|
71
|
-
/**
|
|
72
|
-
* Bridges renderer Context and StrictMode from a primary renderer.
|
|
71
|
+
/**
|
|
72
|
+
* Bridges renderer Context and StrictMode from a primary renderer.
|
|
73
73
|
*/
|
|
74
74
|
function useBridge() {
|
|
75
75
|
const fiber = itsFine.useFiber();
|
|
@@ -121,8 +121,8 @@ function calculateDpr(dpr) {
|
|
|
121
121
|
return Array.isArray(dpr) ? Math.min(Math.max(dpr[0], target), dpr[1]) : dpr;
|
|
122
122
|
}
|
|
123
123
|
|
|
124
|
-
/**
|
|
125
|
-
* Returns instance root state
|
|
124
|
+
/**
|
|
125
|
+
* Returns instance root state
|
|
126
126
|
*/
|
|
127
127
|
function getRootState(obj) {
|
|
128
128
|
var _r3f;
|
|
@@ -230,10 +230,7 @@ function prepare(target, root, type, props) {
|
|
|
230
230
|
handlers: {},
|
|
231
231
|
isHidden: false
|
|
232
232
|
};
|
|
233
|
-
if (object)
|
|
234
|
-
object.__r3f = instance;
|
|
235
|
-
if (type) applyProps(object, instance.props);
|
|
236
|
-
}
|
|
233
|
+
if (object) object.__r3f = instance;
|
|
237
234
|
}
|
|
238
235
|
return instance;
|
|
239
236
|
}
|
|
@@ -485,9 +482,9 @@ function makeId(event) {
|
|
|
485
482
|
return (event.eventObject || event.object).uuid + '/' + event.index + event.instanceId;
|
|
486
483
|
}
|
|
487
484
|
|
|
488
|
-
/**
|
|
489
|
-
* Release pointer captures.
|
|
490
|
-
* This is called by releasePointerCapture in the API, and when an object is removed.
|
|
485
|
+
/**
|
|
486
|
+
* Release pointer captures.
|
|
487
|
+
* This is called by releasePointerCapture in the API, and when an object is removed.
|
|
491
488
|
*/
|
|
492
489
|
function releaseInternalPointerCapture(capturedMap, obj, captures, pointerId) {
|
|
493
490
|
const captureData = captures.get(obj);
|
|
@@ -822,19 +819,19 @@ function createEvents(store) {
|
|
|
822
819
|
if (!(instance != null && instance.eventCount)) return;
|
|
823
820
|
const handlers = instance.handlers;
|
|
824
821
|
|
|
825
|
-
/*
|
|
826
|
-
MAYBE TODO, DELETE IF NOT:
|
|
827
|
-
Check if the object is captured, captured events should not have intersects running in parallel
|
|
828
|
-
But wouldn't it be better to just replace capturedMap with a single entry?
|
|
829
|
-
Also, are we OK with straight up making picking up multiple objects impossible?
|
|
830
|
-
|
|
831
|
-
const pointerId = (data as ThreeEvent<PointerEvent>).pointerId
|
|
832
|
-
if (pointerId !== undefined) {
|
|
833
|
-
const capturedMeshSet = internal.capturedMap.get(pointerId)
|
|
834
|
-
if (capturedMeshSet) {
|
|
835
|
-
const captured = capturedMeshSet.get(eventObject)
|
|
836
|
-
if (captured && captured.localState.stopped) return
|
|
837
|
-
}
|
|
822
|
+
/*
|
|
823
|
+
MAYBE TODO, DELETE IF NOT:
|
|
824
|
+
Check if the object is captured, captured events should not have intersects running in parallel
|
|
825
|
+
But wouldn't it be better to just replace capturedMap with a single entry?
|
|
826
|
+
Also, are we OK with straight up making picking up multiple objects impossible?
|
|
827
|
+
|
|
828
|
+
const pointerId = (data as ThreeEvent<PointerEvent>).pointerId
|
|
829
|
+
if (pointerId !== undefined) {
|
|
830
|
+
const capturedMeshSet = internal.capturedMap.get(pointerId)
|
|
831
|
+
if (capturedMeshSet) {
|
|
832
|
+
const captured = capturedMeshSet.get(eventObject)
|
|
833
|
+
if (captured && captured.localState.stopped) return
|
|
834
|
+
}
|
|
838
835
|
}*/
|
|
839
836
|
|
|
840
837
|
if (isPointerMove) {
|
|
@@ -1125,11 +1122,11 @@ const createStore = (invalidate, advance) => {
|
|
|
1125
1122
|
return rootStore;
|
|
1126
1123
|
};
|
|
1127
1124
|
|
|
1128
|
-
/**
|
|
1129
|
-
* Exposes an object's {@link Instance}.
|
|
1130
|
-
* @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#useInstanceHandle
|
|
1131
|
-
*
|
|
1132
|
-
* **Note**: this is an escape hatch to react-internal fields. Expect this to change significantly between versions.
|
|
1125
|
+
/**
|
|
1126
|
+
* Exposes an object's {@link Instance}.
|
|
1127
|
+
* @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#useInstanceHandle
|
|
1128
|
+
*
|
|
1129
|
+
* **Note**: this is an escape hatch to react-internal fields. Expect this to change significantly between versions.
|
|
1133
1130
|
*/
|
|
1134
1131
|
function useInstanceHandle(ref) {
|
|
1135
1132
|
const instance = React__namespace.useRef(null);
|
|
@@ -1137,9 +1134,9 @@ function useInstanceHandle(ref) {
|
|
|
1137
1134
|
return instance;
|
|
1138
1135
|
}
|
|
1139
1136
|
|
|
1140
|
-
/**
|
|
1141
|
-
* Returns the R3F Canvas' Zustand store. Useful for [transient updates](https://github.com/pmndrs/zustand#transient-updates-for-often-occurring-state-changes).
|
|
1142
|
-
* @see https://docs.pmnd.rs/react-three-fiber/api/hooks#usestore
|
|
1137
|
+
/**
|
|
1138
|
+
* Returns the R3F Canvas' Zustand store. Useful for [transient updates](https://github.com/pmndrs/zustand#transient-updates-for-often-occurring-state-changes).
|
|
1139
|
+
* @see https://docs.pmnd.rs/react-three-fiber/api/hooks#usestore
|
|
1143
1140
|
*/
|
|
1144
1141
|
function useStore() {
|
|
1145
1142
|
const store = React__namespace.useContext(context);
|
|
@@ -1147,18 +1144,18 @@ function useStore() {
|
|
|
1147
1144
|
return store;
|
|
1148
1145
|
}
|
|
1149
1146
|
|
|
1150
|
-
/**
|
|
1151
|
-
* Accesses R3F's internal state, containing renderer, canvas, scene, etc.
|
|
1152
|
-
* @see https://docs.pmnd.rs/react-three-fiber/api/hooks#usethree
|
|
1147
|
+
/**
|
|
1148
|
+
* Accesses R3F's internal state, containing renderer, canvas, scene, etc.
|
|
1149
|
+
* @see https://docs.pmnd.rs/react-three-fiber/api/hooks#usethree
|
|
1153
1150
|
*/
|
|
1154
1151
|
function useThree(selector = state => state, equalityFn) {
|
|
1155
1152
|
return useStore()(selector, equalityFn);
|
|
1156
1153
|
}
|
|
1157
1154
|
|
|
1158
|
-
/**
|
|
1159
|
-
* Executes a callback before render in a shared frame loop.
|
|
1160
|
-
* Can order effects with render priority or manually render with a positive priority.
|
|
1161
|
-
* @see https://docs.pmnd.rs/react-three-fiber/api/hooks#useframe
|
|
1155
|
+
/**
|
|
1156
|
+
* Executes a callback before render in a shared frame loop.
|
|
1157
|
+
* Can order effects with render priority or manually render with a positive priority.
|
|
1158
|
+
* @see https://docs.pmnd.rs/react-three-fiber/api/hooks#useframe
|
|
1162
1159
|
*/
|
|
1163
1160
|
function useFrame(callback, renderPriority = 0) {
|
|
1164
1161
|
const store = useStore();
|
|
@@ -1170,9 +1167,9 @@ function useFrame(callback, renderPriority = 0) {
|
|
|
1170
1167
|
return null;
|
|
1171
1168
|
}
|
|
1172
1169
|
|
|
1173
|
-
/**
|
|
1174
|
-
* Returns a node graph of an object with named nodes & materials.
|
|
1175
|
-
* @see https://docs.pmnd.rs/react-three-fiber/api/hooks#usegraph
|
|
1170
|
+
/**
|
|
1171
|
+
* Returns a node graph of an object with named nodes & materials.
|
|
1172
|
+
* @see https://docs.pmnd.rs/react-three-fiber/api/hooks#usegraph
|
|
1176
1173
|
*/
|
|
1177
1174
|
function useGraph(object) {
|
|
1178
1175
|
return React__namespace.useMemo(() => buildGraph(object), [object]);
|
|
@@ -1208,11 +1205,11 @@ function loadingFn(extensions, onProgress) {
|
|
|
1208
1205
|
};
|
|
1209
1206
|
}
|
|
1210
1207
|
|
|
1211
|
-
/**
|
|
1212
|
-
* Synchronously loads and caches assets with a three loader.
|
|
1213
|
-
*
|
|
1214
|
-
* Note: this hook's caller must be wrapped with `React.Suspense`
|
|
1215
|
-
* @see https://docs.pmnd.rs/react-three-fiber/api/hooks#useloader
|
|
1208
|
+
/**
|
|
1209
|
+
* Synchronously loads and caches assets with a three loader.
|
|
1210
|
+
*
|
|
1211
|
+
* Note: this hook's caller must be wrapped with `React.Suspense`
|
|
1212
|
+
* @see https://docs.pmnd.rs/react-three-fiber/api/hooks#useloader
|
|
1216
1213
|
*/
|
|
1217
1214
|
function useLoader(loader, input, extensions, onProgress) {
|
|
1218
1215
|
// Use suspense to load async assets
|
|
@@ -1224,16 +1221,16 @@ function useLoader(loader, input, extensions, onProgress) {
|
|
|
1224
1221
|
return Array.isArray(input) ? results : results[0];
|
|
1225
1222
|
}
|
|
1226
1223
|
|
|
1227
|
-
/**
|
|
1228
|
-
* Preloads an asset into cache as a side-effect.
|
|
1224
|
+
/**
|
|
1225
|
+
* Preloads an asset into cache as a side-effect.
|
|
1229
1226
|
*/
|
|
1230
1227
|
useLoader.preload = function (loader, input, extensions) {
|
|
1231
1228
|
const keys = Array.isArray(input) ? input : [input];
|
|
1232
1229
|
return suspendReact.preload(loadingFn(extensions), [loader, ...keys]);
|
|
1233
1230
|
};
|
|
1234
1231
|
|
|
1235
|
-
/**
|
|
1236
|
-
* Removes a loaded asset from cache.
|
|
1232
|
+
/**
|
|
1233
|
+
* Removes a loaded asset from cache.
|
|
1237
1234
|
*/
|
|
1238
1235
|
useLoader.clear = function (loader, input) {
|
|
1239
1236
|
const keys = Array.isArray(input) ? input : [input];
|
|
@@ -1335,11 +1332,11 @@ function handleContainerEffects(parent, child, beforeChild) {
|
|
|
1335
1332
|
// Create object
|
|
1336
1333
|
child.object = (_child$props$object = child.props.object) != null ? _child$props$object : new target(...((_child$props$args = child.props.args) != null ? _child$props$args : []));
|
|
1337
1334
|
child.object.__r3f = child;
|
|
1338
|
-
|
|
1339
|
-
// Set initial props
|
|
1340
|
-
applyProps(child.object, child.props);
|
|
1341
1335
|
}
|
|
1342
1336
|
|
|
1337
|
+
// Set initial props
|
|
1338
|
+
applyProps(child.object, child.props);
|
|
1339
|
+
|
|
1343
1340
|
// Append instance
|
|
1344
1341
|
if (child.props.attach) {
|
|
1345
1342
|
attach(parent, child);
|
|
@@ -1351,7 +1348,6 @@ function handleContainerEffects(parent, child, beforeChild) {
|
|
|
1351
1348
|
child.object.dispatchEvent({
|
|
1352
1349
|
type: 'added'
|
|
1353
1350
|
});
|
|
1354
|
-
// expect-error https://github.com/mrdoob/three.js/pull/16934
|
|
1355
1351
|
parent.object.dispatchEvent({
|
|
1356
1352
|
type: 'childadded',
|
|
1357
1353
|
child: child.object
|
|
@@ -2048,10 +2044,10 @@ function Portal({
|
|
|
2048
2044
|
children,
|
|
2049
2045
|
container
|
|
2050
2046
|
}) {
|
|
2051
|
-
/** This has to be a component because it would not be able to call useThree/useStore otherwise since
|
|
2052
|
-
* if this is our environment, then we are not in r3f's renderer but in react-dom, it would trigger
|
|
2053
|
-
* the "R3F hooks can only be used within the Canvas component!" warning:
|
|
2054
|
-
* <Canvas>
|
|
2047
|
+
/** This has to be a component because it would not be able to call useThree/useStore otherwise since
|
|
2048
|
+
* if this is our environment, then we are not in r3f's renderer but in react-dom, it would trigger
|
|
2049
|
+
* the "R3F hooks can only be used within the Canvas component!" warning:
|
|
2050
|
+
* <Canvas>
|
|
2055
2051
|
* {createPortal(...)} */
|
|
2056
2052
|
const {
|
|
2057
2053
|
events,
|
|
@@ -2143,21 +2139,21 @@ const globalEffects = new Set();
|
|
|
2143
2139
|
const globalAfterEffects = new Set();
|
|
2144
2140
|
const globalTailEffects = new Set();
|
|
2145
2141
|
|
|
2146
|
-
/**
|
|
2147
|
-
* Adds a global render callback which is called each frame.
|
|
2148
|
-
* @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#addEffect
|
|
2142
|
+
/**
|
|
2143
|
+
* Adds a global render callback which is called each frame.
|
|
2144
|
+
* @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#addEffect
|
|
2149
2145
|
*/
|
|
2150
2146
|
const addEffect = callback => createSubs(callback, globalEffects);
|
|
2151
2147
|
|
|
2152
|
-
/**
|
|
2153
|
-
* Adds a global after-render callback which is called each frame.
|
|
2154
|
-
* @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#addAfterEffect
|
|
2148
|
+
/**
|
|
2149
|
+
* Adds a global after-render callback which is called each frame.
|
|
2150
|
+
* @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#addAfterEffect
|
|
2155
2151
|
*/
|
|
2156
2152
|
const addAfterEffect = callback => createSubs(callback, globalAfterEffects);
|
|
2157
2153
|
|
|
2158
|
-
/**
|
|
2159
|
-
* Adds a global callback which is called when rendering stops.
|
|
2160
|
-
* @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#addTail
|
|
2154
|
+
/**
|
|
2155
|
+
* Adds a global callback which is called when rendering stops.
|
|
2156
|
+
* @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#addTail
|
|
2161
2157
|
*/
|
|
2162
2158
|
const addTail = callback => createSubs(callback, globalTailEffects);
|
|
2163
2159
|
function run(effects, timestamp) {
|
|
@@ -2229,7 +2225,7 @@ function loop(timestamp) {
|
|
|
2229
2225
|
repeat += update(timestamp, state);
|
|
2230
2226
|
}
|
|
2231
2227
|
}
|
|
2232
|
-
useFrameInProgress =
|
|
2228
|
+
useFrameInProgress = false;
|
|
2233
2229
|
|
|
2234
2230
|
// Run after-effects
|
|
2235
2231
|
flushGlobalEffects('after', timestamp);
|
|
@@ -2245,9 +2241,9 @@ function loop(timestamp) {
|
|
|
2245
2241
|
}
|
|
2246
2242
|
}
|
|
2247
2243
|
|
|
2248
|
-
/**
|
|
2249
|
-
* Invalidates the view, requesting a frame to be rendered. Will globally invalidate unless passed a root's state.
|
|
2250
|
-
* @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#invalidate
|
|
2244
|
+
/**
|
|
2245
|
+
* Invalidates the view, requesting a frame to be rendered. Will globally invalidate unless passed a root's state.
|
|
2246
|
+
* @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#invalidate
|
|
2251
2247
|
*/
|
|
2252
2248
|
function invalidate(state, frames = 1) {
|
|
2253
2249
|
var _state$gl$xr2;
|
|
@@ -2274,9 +2270,9 @@ function invalidate(state, frames = 1) {
|
|
|
2274
2270
|
}
|
|
2275
2271
|
}
|
|
2276
2272
|
|
|
2277
|
-
/**
|
|
2278
|
-
* Advances the frameloop and runs render effects, useful for when manually rendering via `frameloop="never"`.
|
|
2279
|
-
* @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#advance
|
|
2273
|
+
/**
|
|
2274
|
+
* Advances the frameloop and runs render effects, useful for when manually rendering via `frameloop="never"`.
|
|
2275
|
+
* @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#advance
|
|
2280
2276
|
*/
|
|
2281
2277
|
function advance(timestamp, runGlobalEffects = true, state, frame) {
|
|
2282
2278
|
if (runGlobalEffects) flushGlobalEffects('before', timestamp);
|
|
@@ -2308,7 +2304,7 @@ function createPointerEvents(store) {
|
|
|
2308
2304
|
compute(event, state, previous) {
|
|
2309
2305
|
// https://github.com/pmndrs/react-three-fiber/pull/782
|
|
2310
2306
|
// Events trigger outside of canvas when moved, use offsetX/Y by default and allow overrides
|
|
2311
|
-
state.pointer.set(event.offsetX / state.size.width * 2 - 1, -(event.offsetY / state.size.height) * 2 + 1);
|
|
2307
|
+
state.pointer.set((event.offsetX - state.size.left) / state.size.width * 2 - 1, -((event.offsetY - state.size.top) / state.size.height) * 2 + 1);
|
|
2312
2308
|
state.raycaster.setFromCamera(state.pointer, state.camera);
|
|
2313
2309
|
},
|
|
2314
2310
|
connected: undefined,
|
|
@@ -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-4464c9d4.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');
|
|
@@ -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, {
|