@react-three/fiber 9.0.0-rc.3 → 9.0.0-rc.5
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 +1076 -1076
- package/dist/declarations/src/core/events.d.ts +91 -91
- package/dist/declarations/src/core/hooks.d.ts +51 -50
- 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 -87
- package/dist/declarations/src/core/store.d.ts +130 -130
- package/dist/declarations/src/core/utils.d.ts +186 -185
- 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/declarations/src/web/use-measure.d.ts +34 -34
- package/dist/{events-484fb9c5.cjs.prod.js → events-60ed2d7b.cjs.prod.js} +150 -134
- package/dist/{events-64d1e225.esm.js → events-a7b08b1a.esm.js} +151 -134
- package/dist/{events-c2452172.cjs.dev.js → events-b4061ace.cjs.dev.js} +150 -134
- package/dist/react-three-fiber.cjs.dev.js +51 -49
- package/dist/react-three-fiber.cjs.prod.js +51 -49
- package/dist/react-three-fiber.esm.js +52 -49
- package/native/package.json +5 -5
- package/package.json +88 -88
- package/readme.md +253 -253
- package/native/dist/react-three-fiber-native.cjs.d.ts +0 -2
- package/native/dist/react-three-fiber-native.cjs.dev.js +0 -550
- package/native/dist/react-three-fiber-native.cjs.js +0 -7
- package/native/dist/react-three-fiber-native.cjs.prod.js +0 -550
- package/native/dist/react-three-fiber-native.esm.js +0 -497
|
@@ -12,29 +12,29 @@ var threeTypes = /*#__PURE__*/Object.freeze({
|
|
|
12
12
|
__proto__: null
|
|
13
13
|
});
|
|
14
14
|
|
|
15
|
-
/**
|
|
16
|
-
* Returns the instance's initial (outmost) root.
|
|
15
|
+
/**
|
|
16
|
+
* Returns the instance's initial (outmost) root.
|
|
17
17
|
*/
|
|
18
18
|
function findInitialRoot(instance) {
|
|
19
19
|
let root = instance.root;
|
|
20
20
|
while (root.getState().previousRoot) root = root.getState().previousRoot;
|
|
21
21
|
return root;
|
|
22
22
|
}
|
|
23
|
-
/**
|
|
24
|
-
* Safely flush async effects when testing, simulating a legacy root.
|
|
23
|
+
/**
|
|
24
|
+
* Safely flush async effects when testing, simulating a legacy root.
|
|
25
25
|
*/
|
|
26
26
|
const act = React.act;
|
|
27
27
|
const isOrthographicCamera = def => def && def.isOrthographicCamera;
|
|
28
28
|
const isRef = obj => obj && obj.hasOwnProperty('current');
|
|
29
29
|
|
|
30
|
-
/**
|
|
31
|
-
* An SSR-friendly useLayoutEffect.
|
|
32
|
-
*
|
|
33
|
-
* React currently throws a warning when using useLayoutEffect on the server.
|
|
34
|
-
* To get around it, we can conditionally useEffect on the server (no-op) and
|
|
35
|
-
* useLayoutEffect elsewhere.
|
|
36
|
-
*
|
|
37
|
-
* @see https://github.com/facebook/react/issues/14927
|
|
30
|
+
/**
|
|
31
|
+
* An SSR-friendly useLayoutEffect.
|
|
32
|
+
*
|
|
33
|
+
* React currently throws a warning when using useLayoutEffect on the server.
|
|
34
|
+
* To get around it, we can conditionally useEffect on the server (no-op) and
|
|
35
|
+
* useLayoutEffect elsewhere.
|
|
36
|
+
*
|
|
37
|
+
* @see https://github.com/facebook/react/issues/14927
|
|
38
38
|
*/
|
|
39
39
|
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.useLayoutEffect : React.useEffect;
|
|
40
40
|
function useMutableCallback(fn) {
|
|
@@ -42,8 +42,8 @@ function useMutableCallback(fn) {
|
|
|
42
42
|
useIsomorphicLayoutEffect(() => void (ref.current = fn), [fn]);
|
|
43
43
|
return ref;
|
|
44
44
|
}
|
|
45
|
-
/**
|
|
46
|
-
* Bridges renderer Context and StrictMode from a primary renderer.
|
|
45
|
+
/**
|
|
46
|
+
* Bridges renderer Context and StrictMode from a primary renderer.
|
|
47
47
|
*/
|
|
48
48
|
function useBridge() {
|
|
49
49
|
const fiber = useFiber();
|
|
@@ -95,8 +95,8 @@ function calculateDpr(dpr) {
|
|
|
95
95
|
return Array.isArray(dpr) ? Math.min(Math.max(dpr[0], target), dpr[1]) : dpr;
|
|
96
96
|
}
|
|
97
97
|
|
|
98
|
-
/**
|
|
99
|
-
* Returns instance root state
|
|
98
|
+
/**
|
|
99
|
+
* Returns instance root state
|
|
100
100
|
*/
|
|
101
101
|
function getRootState(obj) {
|
|
102
102
|
var _r3f;
|
|
@@ -110,6 +110,7 @@ const is = {
|
|
|
110
110
|
num: a => typeof a === 'number',
|
|
111
111
|
boo: a => typeof a === 'boolean',
|
|
112
112
|
und: a => a === void 0,
|
|
113
|
+
nul: a => a === null,
|
|
113
114
|
arr: a => Array.isArray(a),
|
|
114
115
|
equ(a, b, {
|
|
115
116
|
arrays = 'shallow',
|
|
@@ -278,6 +279,18 @@ const RESERVED_PROPS = [...REACT_INTERNAL_PROPS,
|
|
|
278
279
|
// Behavior flags
|
|
279
280
|
'dispose'];
|
|
280
281
|
const MEMOIZED_PROTOTYPES = new Map();
|
|
282
|
+
function getMemoizedPrototype(root) {
|
|
283
|
+
let ctor = MEMOIZED_PROTOTYPES.get(root.constructor);
|
|
284
|
+
try {
|
|
285
|
+
if (!ctor) {
|
|
286
|
+
ctor = new root.constructor();
|
|
287
|
+
MEMOIZED_PROTOTYPES.set(root.constructor, ctor);
|
|
288
|
+
}
|
|
289
|
+
} catch (e) {
|
|
290
|
+
// ...
|
|
291
|
+
}
|
|
292
|
+
return ctor;
|
|
293
|
+
}
|
|
281
294
|
|
|
282
295
|
// This function prepares a set of changes to be applied to the instance
|
|
283
296
|
function diffProps(instance, newProps) {
|
|
@@ -314,12 +327,8 @@ function diffProps(instance, newProps) {
|
|
|
314
327
|
// For removed props, try to set default values, if possible
|
|
315
328
|
if (root.constructor && root.constructor.length === 0) {
|
|
316
329
|
// create a blank slate of the instance and copy the particular parameter.
|
|
317
|
-
|
|
318
|
-
if (!ctor)
|
|
319
|
-
ctor = new root.constructor();
|
|
320
|
-
MEMOIZED_PROTOTYPES.set(root.constructor, ctor);
|
|
321
|
-
}
|
|
322
|
-
changedProps[key] = ctor[key];
|
|
330
|
+
const ctor = getMemoizedPrototype(root);
|
|
331
|
+
if (!is.und(ctor)) changedProps[key] = ctor[key];
|
|
323
332
|
} else {
|
|
324
333
|
// instance does not have constructor, just set it to 0
|
|
325
334
|
changedProps[key] = 0;
|
|
@@ -361,7 +370,13 @@ function applyProps(object, props) {
|
|
|
361
370
|
|
|
362
371
|
// Copy if properties match signatures
|
|
363
372
|
if (target != null && target.copy && value != null && value.constructor && target.constructor === value.constructor) {
|
|
364
|
-
target
|
|
373
|
+
// fetch the default state of the target
|
|
374
|
+
const ctor = getMemoizedPrototype(root);
|
|
375
|
+
// The target key was originally null or undefined, which indicates that the object which
|
|
376
|
+
// is now present was externally set by the user, we should therefore assign the value directly
|
|
377
|
+
if (!is.und(ctor) && (is.und(ctor[key]) || is.nul(ctor[key]))) root[key] = value;
|
|
378
|
+
// Otherwise copy is correct
|
|
379
|
+
else target.copy(value);
|
|
365
380
|
}
|
|
366
381
|
// Layers have no copy function, we must therefore copy the mask property
|
|
367
382
|
else if (target instanceof THREE.Layers && value instanceof THREE.Layers) {
|
|
@@ -444,9 +459,9 @@ function makeId(event) {
|
|
|
444
459
|
return (event.eventObject || event.object).uuid + '/' + event.index + event.instanceId;
|
|
445
460
|
}
|
|
446
461
|
|
|
447
|
-
/**
|
|
448
|
-
* Release pointer captures.
|
|
449
|
-
* This is called by releasePointerCapture in the API, and when an object is removed.
|
|
462
|
+
/**
|
|
463
|
+
* Release pointer captures.
|
|
464
|
+
* This is called by releasePointerCapture in the API, and when an object is removed.
|
|
450
465
|
*/
|
|
451
466
|
function releaseInternalPointerCapture(capturedMap, obj, captures, pointerId) {
|
|
452
467
|
const captureData = captures.get(obj);
|
|
@@ -781,19 +796,19 @@ function createEvents(store) {
|
|
|
781
796
|
if (!(instance != null && instance.eventCount)) return;
|
|
782
797
|
const handlers = instance.handlers;
|
|
783
798
|
|
|
784
|
-
/*
|
|
785
|
-
MAYBE TODO, DELETE IF NOT:
|
|
786
|
-
Check if the object is captured, captured events should not have intersects running in parallel
|
|
787
|
-
But wouldn't it be better to just replace capturedMap with a single entry?
|
|
788
|
-
Also, are we OK with straight up making picking up multiple objects impossible?
|
|
789
|
-
|
|
790
|
-
const pointerId = (data as ThreeEvent<PointerEvent>).pointerId
|
|
791
|
-
if (pointerId !== undefined) {
|
|
792
|
-
const capturedMeshSet = internal.capturedMap.get(pointerId)
|
|
793
|
-
if (capturedMeshSet) {
|
|
794
|
-
const captured = capturedMeshSet.get(eventObject)
|
|
795
|
-
if (captured && captured.localState.stopped) return
|
|
796
|
-
}
|
|
799
|
+
/*
|
|
800
|
+
MAYBE TODO, DELETE IF NOT:
|
|
801
|
+
Check if the object is captured, captured events should not have intersects running in parallel
|
|
802
|
+
But wouldn't it be better to just replace capturedMap with a single entry?
|
|
803
|
+
Also, are we OK with straight up making picking up multiple objects impossible?
|
|
804
|
+
|
|
805
|
+
const pointerId = (data as ThreeEvent<PointerEvent>).pointerId
|
|
806
|
+
if (pointerId !== undefined) {
|
|
807
|
+
const capturedMeshSet = internal.capturedMap.get(pointerId)
|
|
808
|
+
if (capturedMeshSet) {
|
|
809
|
+
const captured = capturedMeshSet.get(eventObject)
|
|
810
|
+
if (captured && captured.localState.stopped) return
|
|
811
|
+
}
|
|
797
812
|
}*/
|
|
798
813
|
|
|
799
814
|
if (isPointerMove) {
|
|
@@ -1059,7 +1074,7 @@ const createStore = (invalidate, advance) => {
|
|
|
1059
1074
|
oldDpr = viewport.dpr;
|
|
1060
1075
|
// Update camera & renderer
|
|
1061
1076
|
updateCamera(camera, size);
|
|
1062
|
-
gl.setPixelRatio(viewport.dpr);
|
|
1077
|
+
if (viewport.dpr > 0) gl.setPixelRatio(viewport.dpr);
|
|
1063
1078
|
const updateStyle = typeof HTMLCanvasElement !== 'undefined' && gl.domElement instanceof HTMLCanvasElement;
|
|
1064
1079
|
gl.setSize(size.width, size.height, updateStyle);
|
|
1065
1080
|
}
|
|
@@ -1084,11 +1099,11 @@ const createStore = (invalidate, advance) => {
|
|
|
1084
1099
|
return rootStore;
|
|
1085
1100
|
};
|
|
1086
1101
|
|
|
1087
|
-
/**
|
|
1088
|
-
* Exposes an object's {@link Instance}.
|
|
1089
|
-
* @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#useInstanceHandle
|
|
1090
|
-
*
|
|
1091
|
-
* **Note**: this is an escape hatch to react-internal fields. Expect this to change significantly between versions.
|
|
1102
|
+
/**
|
|
1103
|
+
* Exposes an object's {@link Instance}.
|
|
1104
|
+
* @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#useInstanceHandle
|
|
1105
|
+
*
|
|
1106
|
+
* **Note**: this is an escape hatch to react-internal fields. Expect this to change significantly between versions.
|
|
1092
1107
|
*/
|
|
1093
1108
|
function useInstanceHandle(ref) {
|
|
1094
1109
|
const instance = React.useRef(null);
|
|
@@ -1096,9 +1111,9 @@ function useInstanceHandle(ref) {
|
|
|
1096
1111
|
return instance;
|
|
1097
1112
|
}
|
|
1098
1113
|
|
|
1099
|
-
/**
|
|
1100
|
-
* Returns the R3F Canvas' Zustand store. Useful for [transient updates](https://github.com/pmndrs/zustand#transient-updates-for-often-occurring-state-changes).
|
|
1101
|
-
* @see https://docs.pmnd.rs/react-three-fiber/api/hooks#usestore
|
|
1114
|
+
/**
|
|
1115
|
+
* Returns the R3F Canvas' Zustand store. Useful for [transient updates](https://github.com/pmndrs/zustand#transient-updates-for-often-occurring-state-changes).
|
|
1116
|
+
* @see https://docs.pmnd.rs/react-three-fiber/api/hooks#usestore
|
|
1102
1117
|
*/
|
|
1103
1118
|
function useStore() {
|
|
1104
1119
|
const store = React.useContext(context);
|
|
@@ -1106,18 +1121,18 @@ function useStore() {
|
|
|
1106
1121
|
return store;
|
|
1107
1122
|
}
|
|
1108
1123
|
|
|
1109
|
-
/**
|
|
1110
|
-
* Accesses R3F's internal state, containing renderer, canvas, scene, etc.
|
|
1111
|
-
* @see https://docs.pmnd.rs/react-three-fiber/api/hooks#usethree
|
|
1124
|
+
/**
|
|
1125
|
+
* Accesses R3F's internal state, containing renderer, canvas, scene, etc.
|
|
1126
|
+
* @see https://docs.pmnd.rs/react-three-fiber/api/hooks#usethree
|
|
1112
1127
|
*/
|
|
1113
1128
|
function useThree(selector = state => state, equalityFn) {
|
|
1114
1129
|
return useStore()(selector, equalityFn);
|
|
1115
1130
|
}
|
|
1116
1131
|
|
|
1117
|
-
/**
|
|
1118
|
-
* Executes a callback before render in a shared frame loop.
|
|
1119
|
-
* Can order effects with render priority or manually render with a positive priority.
|
|
1120
|
-
* @see https://docs.pmnd.rs/react-three-fiber/api/hooks#useframe
|
|
1132
|
+
/**
|
|
1133
|
+
* Executes a callback before render in a shared frame loop.
|
|
1134
|
+
* Can order effects with render priority or manually render with a positive priority.
|
|
1135
|
+
* @see https://docs.pmnd.rs/react-three-fiber/api/hooks#useframe
|
|
1121
1136
|
*/
|
|
1122
1137
|
function useFrame(callback, renderPriority = 0) {
|
|
1123
1138
|
const store = useStore();
|
|
@@ -1129,9 +1144,9 @@ function useFrame(callback, renderPriority = 0) {
|
|
|
1129
1144
|
return null;
|
|
1130
1145
|
}
|
|
1131
1146
|
|
|
1132
|
-
/**
|
|
1133
|
-
* Returns a node graph of an object with named nodes & materials.
|
|
1134
|
-
* @see https://docs.pmnd.rs/react-three-fiber/api/hooks#usegraph
|
|
1147
|
+
/**
|
|
1148
|
+
* Returns a node graph of an object with named nodes & materials.
|
|
1149
|
+
* @see https://docs.pmnd.rs/react-three-fiber/api/hooks#usegraph
|
|
1135
1150
|
*/
|
|
1136
1151
|
function useGraph(object) {
|
|
1137
1152
|
return React.useMemo(() => buildGraph(object), [object]);
|
|
@@ -1167,11 +1182,11 @@ function loadingFn(extensions, onProgress) {
|
|
|
1167
1182
|
};
|
|
1168
1183
|
}
|
|
1169
1184
|
|
|
1170
|
-
/**
|
|
1171
|
-
* Synchronously loads and caches assets with a three loader.
|
|
1172
|
-
*
|
|
1173
|
-
* Note: this hook's caller must be wrapped with `React.Suspense`
|
|
1174
|
-
* @see https://docs.pmnd.rs/react-three-fiber/api/hooks#useloader
|
|
1185
|
+
/**
|
|
1186
|
+
* Synchronously loads and caches assets with a three loader.
|
|
1187
|
+
*
|
|
1188
|
+
* Note: this hook's caller must be wrapped with `React.Suspense`
|
|
1189
|
+
* @see https://docs.pmnd.rs/react-three-fiber/api/hooks#useloader
|
|
1175
1190
|
*/
|
|
1176
1191
|
function useLoader(loader, input, extensions, onProgress) {
|
|
1177
1192
|
// Use suspense to load async assets
|
|
@@ -1183,16 +1198,16 @@ function useLoader(loader, input, extensions, onProgress) {
|
|
|
1183
1198
|
return Array.isArray(input) ? results : results[0];
|
|
1184
1199
|
}
|
|
1185
1200
|
|
|
1186
|
-
/**
|
|
1187
|
-
* Preloads an asset into cache as a side-effect.
|
|
1201
|
+
/**
|
|
1202
|
+
* Preloads an asset into cache as a side-effect.
|
|
1188
1203
|
*/
|
|
1189
1204
|
useLoader.preload = function (loader, input, extensions) {
|
|
1190
1205
|
const keys = Array.isArray(input) ? input : [input];
|
|
1191
1206
|
return preload(loadingFn(extensions), [loader, ...keys]);
|
|
1192
1207
|
};
|
|
1193
1208
|
|
|
1194
|
-
/**
|
|
1195
|
-
* Removes a loaded asset from cache.
|
|
1209
|
+
/**
|
|
1210
|
+
* Removes a loaded asset from cache.
|
|
1196
1211
|
*/
|
|
1197
1212
|
useLoader.clear = function (loader, input) {
|
|
1198
1213
|
const keys = Array.isArray(input) ? input : [input];
|
|
@@ -1310,7 +1325,7 @@ function handleContainerEffects(parent, child, beforeChild) {
|
|
|
1310
1325
|
child.object.dispatchEvent({
|
|
1311
1326
|
type: 'added'
|
|
1312
1327
|
});
|
|
1313
|
-
//
|
|
1328
|
+
// expect-error https://github.com/mrdoob/three.js/pull/16934
|
|
1314
1329
|
parent.object.dispatchEvent({
|
|
1315
1330
|
type: 'childadded',
|
|
1316
1331
|
child: child.object
|
|
@@ -1626,17 +1641,20 @@ const shallowLoose = {
|
|
|
1626
1641
|
objects: 'shallow',
|
|
1627
1642
|
strict: false
|
|
1628
1643
|
};
|
|
1629
|
-
|
|
1630
|
-
const
|
|
1631
|
-
if (isRenderer(customRenderer)) return customRenderer;
|
|
1632
|
-
return new THREE.WebGLRenderer({
|
|
1633
|
-
powerPreference: 'high-performance',
|
|
1644
|
+
async function createRendererInstance(gl, canvas) {
|
|
1645
|
+
const defaultProps = {
|
|
1634
1646
|
canvas: canvas,
|
|
1647
|
+
powerPreference: 'high-performance',
|
|
1635
1648
|
antialias: true,
|
|
1636
|
-
alpha: true
|
|
1649
|
+
alpha: true
|
|
1650
|
+
};
|
|
1651
|
+
const customRenderer = typeof gl === 'function' ? await gl(defaultProps) : gl;
|
|
1652
|
+
if (isRenderer(customRenderer)) return customRenderer;
|
|
1653
|
+
return new THREE.WebGLRenderer({
|
|
1654
|
+
...defaultProps,
|
|
1637
1655
|
...gl
|
|
1638
1656
|
});
|
|
1639
|
-
}
|
|
1657
|
+
}
|
|
1640
1658
|
function computeInitialSize(canvas, size) {
|
|
1641
1659
|
if (!size && typeof HTMLCanvasElement !== 'undefined' && canvas instanceof HTMLCanvasElement && canvas.parentElement) {
|
|
1642
1660
|
const {
|
|
@@ -1717,7 +1735,7 @@ function createRoot(canvas) {
|
|
|
1717
1735
|
let configured = false;
|
|
1718
1736
|
let lastCamera;
|
|
1719
1737
|
return {
|
|
1720
|
-
configure(props = {}) {
|
|
1738
|
+
async configure(props = {}) {
|
|
1721
1739
|
let {
|
|
1722
1740
|
gl: glConfig,
|
|
1723
1741
|
size: propsSize,
|
|
@@ -1741,7 +1759,7 @@ function createRoot(canvas) {
|
|
|
1741
1759
|
// Set up renderer (one time only!)
|
|
1742
1760
|
let gl = state.gl;
|
|
1743
1761
|
if (!state.gl) state.set({
|
|
1744
|
-
gl: gl = createRendererInstance(glConfig, canvas)
|
|
1762
|
+
gl: gl = await createRendererInstance(glConfig, canvas)
|
|
1745
1763
|
});
|
|
1746
1764
|
|
|
1747
1765
|
// Set up raycaster (one time only!)
|
|
@@ -1811,6 +1829,31 @@ function createRoot(canvas) {
|
|
|
1811
1829
|
});
|
|
1812
1830
|
}
|
|
1813
1831
|
|
|
1832
|
+
// Store events internally
|
|
1833
|
+
if (events && !state.events.handlers) state.set({
|
|
1834
|
+
events: events(store)
|
|
1835
|
+
});
|
|
1836
|
+
// Check size, allow it to take on container bounds initially
|
|
1837
|
+
const size = computeInitialSize(canvas, propsSize);
|
|
1838
|
+
if (!is.equ(size, state.size, shallowLoose)) {
|
|
1839
|
+
state.setSize(size.width, size.height, size.top, size.left);
|
|
1840
|
+
}
|
|
1841
|
+
// Check pixelratio
|
|
1842
|
+
if (dpr && state.viewport.dpr !== calculateDpr(dpr)) state.setDpr(dpr);
|
|
1843
|
+
// Check frameloop
|
|
1844
|
+
if (state.frameloop !== frameloop) state.setFrameloop(frameloop);
|
|
1845
|
+
// Check pointer missed
|
|
1846
|
+
if (!state.onPointerMissed) state.set({
|
|
1847
|
+
onPointerMissed
|
|
1848
|
+
});
|
|
1849
|
+
// Check performance
|
|
1850
|
+
if (performance && !is.equ(performance, state.performance, shallowLoose)) state.set(state => ({
|
|
1851
|
+
performance: {
|
|
1852
|
+
...state.performance,
|
|
1853
|
+
...performance
|
|
1854
|
+
}
|
|
1855
|
+
}));
|
|
1856
|
+
|
|
1814
1857
|
// Set up XR (one time only!)
|
|
1815
1858
|
if (!state.xr) {
|
|
1816
1859
|
var _gl$xr;
|
|
@@ -1892,30 +1935,6 @@ function createRoot(canvas) {
|
|
|
1892
1935
|
|
|
1893
1936
|
// Set gl props
|
|
1894
1937
|
if (glConfig && !is.fun(glConfig) && !isRenderer(glConfig) && !is.equ(glConfig, gl, shallowLoose)) applyProps(gl, glConfig);
|
|
1895
|
-
// Store events internally
|
|
1896
|
-
if (events && !state.events.handlers) state.set({
|
|
1897
|
-
events: events(store)
|
|
1898
|
-
});
|
|
1899
|
-
// Check size, allow it to take on container bounds initially
|
|
1900
|
-
const size = computeInitialSize(canvas, propsSize);
|
|
1901
|
-
if (!is.equ(size, state.size, shallowLoose)) {
|
|
1902
|
-
state.setSize(size.width, size.height, size.top, size.left);
|
|
1903
|
-
}
|
|
1904
|
-
// Check pixelratio
|
|
1905
|
-
if (dpr && state.viewport.dpr !== calculateDpr(dpr)) state.setDpr(dpr);
|
|
1906
|
-
// Check frameloop
|
|
1907
|
-
if (state.frameloop !== frameloop) state.setFrameloop(frameloop);
|
|
1908
|
-
// Check pointer missed
|
|
1909
|
-
if (!state.onPointerMissed) state.set({
|
|
1910
|
-
onPointerMissed
|
|
1911
|
-
});
|
|
1912
|
-
// Check performance
|
|
1913
|
-
if (performance && !is.equ(performance, state.performance, shallowLoose)) state.set(state => ({
|
|
1914
|
-
performance: {
|
|
1915
|
-
...state.performance,
|
|
1916
|
-
...performance
|
|
1917
|
-
}
|
|
1918
|
-
}));
|
|
1919
1938
|
|
|
1920
1939
|
// Set locals
|
|
1921
1940
|
onCreated = onCreatedCallback;
|
|
@@ -1924,7 +1943,7 @@ function createRoot(canvas) {
|
|
|
1924
1943
|
},
|
|
1925
1944
|
render(children) {
|
|
1926
1945
|
// The root has to be configured before it can be rendered
|
|
1927
|
-
if (!configured)
|
|
1946
|
+
if (!configured) throw "The root has to be configured before it can be rendered, call 'configure' first!";
|
|
1928
1947
|
reconciler.updateContainer( /*#__PURE__*/jsx(Provider, {
|
|
1929
1948
|
store: store,
|
|
1930
1949
|
children: children,
|
|
@@ -1938,12 +1957,6 @@ function createRoot(canvas) {
|
|
|
1938
1957
|
}
|
|
1939
1958
|
};
|
|
1940
1959
|
}
|
|
1941
|
-
function render(children, canvas, config) {
|
|
1942
|
-
console.warn('R3F.render is no longer supported in React 18. Use createRoot instead!');
|
|
1943
|
-
const root = createRoot(canvas);
|
|
1944
|
-
root.configure(config);
|
|
1945
|
-
return root.render(children);
|
|
1946
|
-
}
|
|
1947
1960
|
function Provider({
|
|
1948
1961
|
store,
|
|
1949
1962
|
children,
|
|
@@ -2009,10 +2022,10 @@ function Portal({
|
|
|
2009
2022
|
children,
|
|
2010
2023
|
container
|
|
2011
2024
|
}) {
|
|
2012
|
-
/** This has to be a component because it would not be able to call useThree/useStore otherwise since
|
|
2013
|
-
* if this is our environment, then we are not in r3f's renderer but in react-dom, it would trigger
|
|
2014
|
-
* the "R3F hooks can only be used within the Canvas component!" warning:
|
|
2015
|
-
* <Canvas>
|
|
2025
|
+
/** This has to be a component because it would not be able to call useThree/useStore otherwise since
|
|
2026
|
+
* if this is our environment, then we are not in r3f's renderer but in react-dom, it would trigger
|
|
2027
|
+
* the "R3F hooks can only be used within the Canvas component!" warning:
|
|
2028
|
+
* <Canvas>
|
|
2016
2029
|
* {createPortal(...)} */
|
|
2017
2030
|
const {
|
|
2018
2031
|
events,
|
|
@@ -2081,12 +2094,16 @@ function Portal({
|
|
|
2081
2094
|
return store;
|
|
2082
2095
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
2083
2096
|
}, [previousRoot, container]);
|
|
2084
|
-
return
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2097
|
+
return (
|
|
2098
|
+
/*#__PURE__*/
|
|
2099
|
+
// @ts-ignore, reconciler types are not maintained
|
|
2100
|
+
jsx(Fragment, {
|
|
2101
|
+
children: reconciler.createPortal( /*#__PURE__*/jsx(context.Provider, {
|
|
2102
|
+
value: usePortalStore,
|
|
2103
|
+
children: children
|
|
2104
|
+
}), usePortalStore, null)
|
|
2105
|
+
})
|
|
2106
|
+
);
|
|
2090
2107
|
}
|
|
2091
2108
|
|
|
2092
2109
|
function createSubs(callback, subs) {
|
|
@@ -2100,21 +2117,21 @@ const globalEffects = new Set();
|
|
|
2100
2117
|
const globalAfterEffects = new Set();
|
|
2101
2118
|
const globalTailEffects = new Set();
|
|
2102
2119
|
|
|
2103
|
-
/**
|
|
2104
|
-
* Adds a global render callback which is called each frame.
|
|
2105
|
-
* @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#addEffect
|
|
2120
|
+
/**
|
|
2121
|
+
* Adds a global render callback which is called each frame.
|
|
2122
|
+
* @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#addEffect
|
|
2106
2123
|
*/
|
|
2107
2124
|
const addEffect = callback => createSubs(callback, globalEffects);
|
|
2108
2125
|
|
|
2109
|
-
/**
|
|
2110
|
-
* Adds a global after-render callback which is called each frame.
|
|
2111
|
-
* @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#addAfterEffect
|
|
2126
|
+
/**
|
|
2127
|
+
* Adds a global after-render callback which is called each frame.
|
|
2128
|
+
* @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#addAfterEffect
|
|
2112
2129
|
*/
|
|
2113
2130
|
const addAfterEffect = callback => createSubs(callback, globalAfterEffects);
|
|
2114
2131
|
|
|
2115
|
-
/**
|
|
2116
|
-
* Adds a global callback which is called when rendering stops.
|
|
2117
|
-
* @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#addTail
|
|
2132
|
+
/**
|
|
2133
|
+
* Adds a global callback which is called when rendering stops.
|
|
2134
|
+
* @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#addTail
|
|
2118
2135
|
*/
|
|
2119
2136
|
const addTail = callback => createSubs(callback, globalTailEffects);
|
|
2120
2137
|
function run(effects, timestamp) {
|
|
@@ -2202,9 +2219,9 @@ function loop(timestamp) {
|
|
|
2202
2219
|
}
|
|
2203
2220
|
}
|
|
2204
2221
|
|
|
2205
|
-
/**
|
|
2206
|
-
* Invalidates the view, requesting a frame to be rendered. Will globally invalidate unless passed a root's state.
|
|
2207
|
-
* @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#invalidate
|
|
2222
|
+
/**
|
|
2223
|
+
* Invalidates the view, requesting a frame to be rendered. Will globally invalidate unless passed a root's state.
|
|
2224
|
+
* @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#invalidate
|
|
2208
2225
|
*/
|
|
2209
2226
|
function invalidate(state, frames = 1) {
|
|
2210
2227
|
var _state$gl$xr2;
|
|
@@ -2231,9 +2248,9 @@ function invalidate(state, frames = 1) {
|
|
|
2231
2248
|
}
|
|
2232
2249
|
}
|
|
2233
2250
|
|
|
2234
|
-
/**
|
|
2235
|
-
* Advances the frameloop and runs render effects, useful for when manually rendering via `frameloop="never"`.
|
|
2236
|
-
* @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#advance
|
|
2251
|
+
/**
|
|
2252
|
+
* Advances the frameloop and runs render effects, useful for when manually rendering via `frameloop="never"`.
|
|
2253
|
+
* @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#advance
|
|
2237
2254
|
*/
|
|
2238
2255
|
function advance(timestamp, runGlobalEffects = true, state, frame) {
|
|
2239
2256
|
if (runGlobalEffects) flushGlobalEffects('before', timestamp);
|
|
@@ -2327,4 +2344,4 @@ function createPointerEvents(store) {
|
|
|
2327
2344
|
};
|
|
2328
2345
|
}
|
|
2329
2346
|
|
|
2330
|
-
export {
|
|
2347
|
+
export { useThree as A, Block as B, useFrame as C, useGraph as D, ErrorBoundary as E, useLoader as F, _roots as _, useMutableCallback as a, useIsomorphicLayoutEffect as b, createRoot as c, unmountComponentAtNode as d, extend as e, createPointerEvents as f, createEvents as g, flushGlobalEffects as h, isRef as i, addEffect as j, addAfterEffect as k, addTail as l, invalidate as m, advance as n, createPortal as o, context as p, applyProps as q, reconciler as r, getRootState as s, threeTypes as t, useBridge as u, dispose as v, act as w, buildGraph as x, useInstanceHandle as y, useStore as z };
|