@react-three/fiber 8.0.0-beta-02 → 8.0.0-beta-03
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 +36 -0
- package/dist/declarations/src/core/events.d.ts +4 -4
- package/dist/declarations/src/core/renderer.d.ts +5 -5
- package/dist/declarations/src/core/store.d.ts +11 -5
- package/dist/declarations/src/core/utils.d.ts +8 -1
- package/dist/declarations/src/index.d.ts +2 -1
- package/dist/declarations/src/native/index.d.ts +3 -4
- package/dist/declarations/src/native.d.ts +2 -1
- package/dist/declarations/src/three-types.d.ts +5 -16
- package/dist/declarations/src/web/Canvas.d.ts +1 -1
- package/dist/declarations/src/web/index.d.ts +3 -4
- package/dist/{hooks-c89a6f88.esm.js → hooks-15c12e3e.esm.js} +218 -134
- package/dist/{hooks-dd693347.cjs.dev.js → hooks-6526f63c.cjs.dev.js} +225 -137
- package/dist/{hooks-e01f12ec.cjs.prod.js → hooks-7b7e01e6.cjs.prod.js} +225 -137
- package/dist/react-three-fiber.cjs.dev.js +188 -184
- package/dist/react-three-fiber.cjs.prod.js +188 -184
- package/dist/react-three-fiber.esm.js +184 -180
- package/native/dist/react-three-fiber-native.cjs.dev.js +208 -209
- package/native/dist/react-three-fiber-native.cjs.prod.js +208 -209
- package/native/dist/react-three-fiber-native.esm.js +206 -207
- package/package.json +7 -8
- package/readme.md +10 -10
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
import { c as createEvents, a as createLoop, b as createRenderer, d as calculateDpr, e as createStore, f as context, g as dispose, i as isRenderer } from './hooks-
|
|
2
|
-
export { t as ReactThreeFiber, k as addAfterEffect, j as addEffect, l as addTail, f as context, g as dispose, h as extend, n as useFrame,
|
|
3
|
-
import * as THREE from 'three';
|
|
4
|
-
import * as React from 'react';
|
|
5
|
-
import { DefaultEventPriority, ContinuousEventPriority, DiscreteEventPriority, ConcurrentRoot } from 'react-reconciler/constants';
|
|
1
|
+
import { c as createEvents, a as createLoop, b as createRenderer, d as calculateDpr, e as createStore, f as context, g as dispose, i as isRenderer, h as extend, p as pick, o as omit } from './hooks-15c12e3e.esm.js';
|
|
2
|
+
export { t as ReactThreeFiber, k as addAfterEffect, j as addEffect, l as addTail, f as context, g as dispose, h as extend, n as useFrame, q as useGraph, r as useLoader, u as useStore, m as useThree } from './hooks-15c12e3e.esm.js';
|
|
6
3
|
import _extends from '@babel/runtime/helpers/esm/extends';
|
|
4
|
+
import * as React from 'react';
|
|
5
|
+
import * as THREE from 'three';
|
|
7
6
|
import mergeRefs from 'react-merge-refs';
|
|
8
7
|
import useMeasure from 'react-use-measure';
|
|
9
|
-
import
|
|
10
|
-
import omit from 'lodash-es/omit';
|
|
8
|
+
import { DefaultEventPriority, ContinuousEventPriority, DiscreteEventPriority, ConcurrentRoot } from 'react-reconciler/constants';
|
|
11
9
|
import 'react-reconciler';
|
|
10
|
+
import 'scheduler';
|
|
12
11
|
import 'suspend-react';
|
|
13
12
|
import 'zustand';
|
|
14
13
|
|
|
@@ -119,111 +118,6 @@ function createPointerEvents(store) {
|
|
|
119
118
|
};
|
|
120
119
|
}
|
|
121
120
|
|
|
122
|
-
const CANVAS_PROPS = ['gl', 'events', 'size', 'shadows', 'linear', 'flat', 'orthographic', 'frameloop', 'dpr', 'performance', 'clock', 'raycaster', 'camera', 'onPointerMissed', 'onCreated']; // React currently throws a warning when using useLayoutEffect on the server.
|
|
123
|
-
// To get around it, we can conditionally useEffect on the server (no-op) and
|
|
124
|
-
// useLayoutEffect in the browser.
|
|
125
|
-
|
|
126
|
-
const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? React.useLayoutEffect : React.useEffect;
|
|
127
|
-
|
|
128
|
-
function Block({
|
|
129
|
-
set
|
|
130
|
-
}) {
|
|
131
|
-
useIsomorphicLayoutEffect(() => {
|
|
132
|
-
set(new Promise(() => null));
|
|
133
|
-
return () => set(false);
|
|
134
|
-
}, []);
|
|
135
|
-
return null;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
class ErrorBoundary extends React.Component {
|
|
139
|
-
constructor(...args) {
|
|
140
|
-
super(...args);
|
|
141
|
-
this.state = {
|
|
142
|
-
error: false
|
|
143
|
-
};
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
componentDidCatch(error) {
|
|
147
|
-
this.props.set(error);
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
render() {
|
|
151
|
-
return this.state.error ? null : this.props.children;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
ErrorBoundary.getDerivedStateFromError = () => ({
|
|
157
|
-
error: true
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
const Canvas = /*#__PURE__*/React.forwardRef(function Canvas({
|
|
161
|
-
children,
|
|
162
|
-
fallback,
|
|
163
|
-
resize,
|
|
164
|
-
style,
|
|
165
|
-
events,
|
|
166
|
-
...props
|
|
167
|
-
}, forwardedRef) {
|
|
168
|
-
const canvasProps = pick(props, CANVAS_PROPS);
|
|
169
|
-
const divProps = omit(props, CANVAS_PROPS);
|
|
170
|
-
const [containerRef, {
|
|
171
|
-
width,
|
|
172
|
-
height
|
|
173
|
-
}] = useMeasure({
|
|
174
|
-
scroll: true,
|
|
175
|
-
debounce: {
|
|
176
|
-
scroll: 50,
|
|
177
|
-
resize: 0
|
|
178
|
-
},
|
|
179
|
-
...resize
|
|
180
|
-
});
|
|
181
|
-
const canvasRef = React.useRef(null);
|
|
182
|
-
const [block, setBlock] = React.useState(false);
|
|
183
|
-
const [error, setError] = React.useState(false); // Suspend this component if block is a promise (2nd run)
|
|
184
|
-
|
|
185
|
-
if (block) throw block; // Throw exception outwards if anything within canvas throws
|
|
186
|
-
|
|
187
|
-
if (error) throw error; // Execute JSX in the reconciler as a layout-effect
|
|
188
|
-
|
|
189
|
-
useIsomorphicLayoutEffect(() => {
|
|
190
|
-
if (width > 0 && height > 0) {
|
|
191
|
-
render( /*#__PURE__*/React.createElement(ErrorBoundary, {
|
|
192
|
-
set: setError
|
|
193
|
-
}, /*#__PURE__*/React.createElement(React.Suspense, {
|
|
194
|
-
fallback: /*#__PURE__*/React.createElement(Block, {
|
|
195
|
-
set: setBlock
|
|
196
|
-
})
|
|
197
|
-
}, children)), canvasRef.current, { ...canvasProps,
|
|
198
|
-
size: {
|
|
199
|
-
width,
|
|
200
|
-
height
|
|
201
|
-
},
|
|
202
|
-
events: events || createPointerEvents
|
|
203
|
-
});
|
|
204
|
-
}
|
|
205
|
-
}, [width, height, children, canvasProps]);
|
|
206
|
-
React.useEffect(() => {
|
|
207
|
-
const container = canvasRef.current;
|
|
208
|
-
return () => unmountComponentAtNode(container);
|
|
209
|
-
}, []);
|
|
210
|
-
return /*#__PURE__*/React.createElement("div", _extends({
|
|
211
|
-
ref: containerRef,
|
|
212
|
-
style: {
|
|
213
|
-
position: 'relative',
|
|
214
|
-
width: '100%',
|
|
215
|
-
height: '100%',
|
|
216
|
-
overflow: 'hidden',
|
|
217
|
-
...style
|
|
218
|
-
}
|
|
219
|
-
}, divProps), /*#__PURE__*/React.createElement("canvas", {
|
|
220
|
-
ref: mergeRefs([canvasRef, forwardedRef]),
|
|
221
|
-
style: {
|
|
222
|
-
display: 'block'
|
|
223
|
-
}
|
|
224
|
-
}, fallback));
|
|
225
|
-
});
|
|
226
|
-
|
|
227
121
|
const roots = new Map();
|
|
228
122
|
const {
|
|
229
123
|
invalidate,
|
|
@@ -254,86 +148,92 @@ const createRendererInstance = (gl, canvas) => {
|
|
|
254
148
|
|
|
255
149
|
function createRoot(canvas, config) {
|
|
256
150
|
return {
|
|
257
|
-
render: element =>
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
151
|
+
render: element => {
|
|
152
|
+
var _store;
|
|
153
|
+
|
|
154
|
+
let {
|
|
155
|
+
gl,
|
|
156
|
+
size,
|
|
157
|
+
events,
|
|
158
|
+
onCreated,
|
|
159
|
+
...props
|
|
160
|
+
} = config || {}; // Allow size to take on container bounds initially
|
|
161
|
+
|
|
162
|
+
if (!size) {
|
|
163
|
+
var _canvas$parentElement, _canvas$parentElement2, _canvas$parentElement3, _canvas$parentElement4;
|
|
164
|
+
|
|
165
|
+
size = {
|
|
166
|
+
width: (_canvas$parentElement = (_canvas$parentElement2 = canvas.parentElement) == null ? void 0 : _canvas$parentElement2.clientWidth) != null ? _canvas$parentElement : 0,
|
|
167
|
+
height: (_canvas$parentElement3 = (_canvas$parentElement4 = canvas.parentElement) == null ? void 0 : _canvas$parentElement4.clientHeight) != null ? _canvas$parentElement3 : 0
|
|
168
|
+
};
|
|
169
|
+
}
|
|
270
170
|
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
171
|
+
let root = roots.get(canvas);
|
|
172
|
+
let fiber = root == null ? void 0 : root.fiber;
|
|
173
|
+
let store = root == null ? void 0 : root.store;
|
|
174
|
+
let state = (_store = store) == null ? void 0 : _store.getState();
|
|
274
175
|
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
}
|
|
176
|
+
if (fiber && state) {
|
|
177
|
+
// When a root was found, see if any fundamental props must be changed or exchanged
|
|
178
|
+
// Check pixelratio
|
|
179
|
+
if (props.dpr !== undefined && state.viewport.dpr !== calculateDpr(props.dpr)) state.setDpr(props.dpr); // Check size
|
|
280
180
|
|
|
281
|
-
|
|
282
|
-
let fiber = root == null ? void 0 : root.fiber;
|
|
283
|
-
let store = root == null ? void 0 : root.store;
|
|
284
|
-
let state = (_store = store) == null ? void 0 : _store.getState();
|
|
181
|
+
if (state.size.width !== size.width || state.size.height !== size.height) state.setSize(size.width, size.height); // Check frameloop
|
|
285
182
|
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
// Check pixelratio
|
|
289
|
-
if (props.dpr !== undefined && state.viewport.dpr !== calculateDpr(props.dpr)) state.setDpr(props.dpr); // Check size
|
|
183
|
+
if (state.frameloop !== props.frameloop) state.setFrameloop(props.frameloop); // For some props we want to reset the entire root
|
|
184
|
+
// Changes to the color-space
|
|
290
185
|
|
|
291
|
-
|
|
292
|
-
// Changes to the color-space
|
|
186
|
+
const linearChanged = props.linear !== state.internal.lastProps.linear;
|
|
293
187
|
|
|
294
|
-
|
|
188
|
+
if (linearChanged) {
|
|
189
|
+
unmountComponentAtNode(canvas);
|
|
190
|
+
fiber = undefined;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
295
193
|
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
}
|
|
194
|
+
if (!fiber) {
|
|
195
|
+
// If no root has been found, make one
|
|
196
|
+
// Create gl
|
|
197
|
+
const glRenderer = createRendererInstance(gl, canvas); // Create store
|
|
301
198
|
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
199
|
+
store = createStore(applyProps, invalidate, advance, {
|
|
200
|
+
gl: glRenderer,
|
|
201
|
+
size,
|
|
202
|
+
...props
|
|
203
|
+
});
|
|
204
|
+
const state = store.getState(); // Create renderer
|
|
306
205
|
|
|
307
|
-
|
|
308
|
-
gl: glRenderer,
|
|
309
|
-
size,
|
|
310
|
-
...props
|
|
311
|
-
});
|
|
312
|
-
const state = store.getState(); // Create renderer
|
|
206
|
+
fiber = reconciler.createContainer(store, ConcurrentRoot, false, null); // Map it
|
|
313
207
|
|
|
314
|
-
|
|
208
|
+
roots.set(canvas, {
|
|
209
|
+
fiber,
|
|
210
|
+
store
|
|
211
|
+
}); // Store events internally
|
|
315
212
|
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
213
|
+
if (events) state.set({
|
|
214
|
+
events: events(store)
|
|
215
|
+
});
|
|
216
|
+
}
|
|
320
217
|
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
218
|
+
if (store && fiber) {
|
|
219
|
+
reconciler.updateContainer( /*#__PURE__*/React.createElement(Provider, {
|
|
220
|
+
store: store,
|
|
221
|
+
element: element,
|
|
222
|
+
onCreated: onCreated,
|
|
223
|
+
target: canvas
|
|
224
|
+
}), fiber, null, () => undefined);
|
|
225
|
+
return store;
|
|
226
|
+
} else {
|
|
227
|
+
throw 'Error creating root!';
|
|
228
|
+
}
|
|
229
|
+
},
|
|
230
|
+
unmount: () => unmountComponentAtNode(canvas)
|
|
231
|
+
};
|
|
232
|
+
}
|
|
325
233
|
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
element: element,
|
|
330
|
-
onCreated: onCreated,
|
|
331
|
-
target: canvas
|
|
332
|
-
}), fiber, null, () => undefined);
|
|
333
|
-
return store;
|
|
334
|
-
} else {
|
|
335
|
-
throw 'Error creating root!';
|
|
336
|
-
}
|
|
234
|
+
function render(element, canvas, config = {}) {
|
|
235
|
+
console.warn('R3F.render is no longer supported in React 18. Use createRoot instead!');
|
|
236
|
+
return createRoot(canvas, config).render(element);
|
|
337
237
|
}
|
|
338
238
|
|
|
339
239
|
function Provider({
|
|
@@ -389,7 +289,7 @@ function unmountComponentAtNode(canvas, callback) {
|
|
|
389
289
|
}
|
|
390
290
|
}
|
|
391
291
|
|
|
392
|
-
const act =
|
|
292
|
+
const act = React.unstable_act;
|
|
393
293
|
|
|
394
294
|
function createPortal(children, container) {
|
|
395
295
|
return reconciler.createPortal(children, container, null, null);
|
|
@@ -401,4 +301,108 @@ reconciler.injectIntoDevTools({
|
|
|
401
301
|
version: '18.0.0'
|
|
402
302
|
});
|
|
403
303
|
|
|
304
|
+
const CANVAS_PROPS = ['gl', 'events', 'shadows', 'linear', 'flat', 'orthographic', 'frameloop', 'dpr', 'performance', 'clock', 'raycaster', 'camera', 'onPointerMissed', 'onCreated'];
|
|
305
|
+
|
|
306
|
+
function Block({
|
|
307
|
+
set
|
|
308
|
+
}) {
|
|
309
|
+
React.useLayoutEffect(() => {
|
|
310
|
+
set(new Promise(() => null));
|
|
311
|
+
return () => set(false);
|
|
312
|
+
}, [set]);
|
|
313
|
+
return null;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
class ErrorBoundary extends React.Component {
|
|
317
|
+
constructor(...args) {
|
|
318
|
+
super(...args);
|
|
319
|
+
this.state = {
|
|
320
|
+
error: false
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
componentDidCatch(error) {
|
|
325
|
+
this.props.set(error);
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
render() {
|
|
329
|
+
return this.state.error ? null : this.props.children;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
ErrorBoundary.getDerivedStateFromError = () => ({
|
|
335
|
+
error: true
|
|
336
|
+
});
|
|
337
|
+
|
|
338
|
+
const Canvas = /*#__PURE__*/React.forwardRef(function Canvas({
|
|
339
|
+
children,
|
|
340
|
+
fallback,
|
|
341
|
+
resize,
|
|
342
|
+
style,
|
|
343
|
+
events,
|
|
344
|
+
...props
|
|
345
|
+
}, forwardedRef) {
|
|
346
|
+
// Create a known catalogue of Threejs-native elements
|
|
347
|
+
// This will include the entire THREE namespace by default, users can extend
|
|
348
|
+
// their own elements by using the createRoot API instead
|
|
349
|
+
React.useMemo(() => extend(THREE), []);
|
|
350
|
+
const [containerRef, {
|
|
351
|
+
width,
|
|
352
|
+
height
|
|
353
|
+
}] = useMeasure({
|
|
354
|
+
scroll: true,
|
|
355
|
+
debounce: {
|
|
356
|
+
scroll: 50,
|
|
357
|
+
resize: 0
|
|
358
|
+
},
|
|
359
|
+
...resize
|
|
360
|
+
});
|
|
361
|
+
const canvasRef = React.useRef(null);
|
|
362
|
+
const canvasProps = pick(props, CANVAS_PROPS);
|
|
363
|
+
const divProps = omit(props, CANVAS_PROPS);
|
|
364
|
+
const [block, setBlock] = React.useState(false);
|
|
365
|
+
const [error, setError] = React.useState(false); // Suspend this component if block is a promise (2nd run)
|
|
366
|
+
|
|
367
|
+
if (block) throw block; // Throw exception outwards if anything within canvas throws
|
|
368
|
+
|
|
369
|
+
if (error) throw error;
|
|
370
|
+
|
|
371
|
+
if (width > 0 && height > 0) {
|
|
372
|
+
createRoot(canvasRef.current, { ...canvasProps,
|
|
373
|
+
size: {
|
|
374
|
+
width,
|
|
375
|
+
height
|
|
376
|
+
},
|
|
377
|
+
events: events || createPointerEvents
|
|
378
|
+
}).render( /*#__PURE__*/React.createElement(ErrorBoundary, {
|
|
379
|
+
set: setError
|
|
380
|
+
}, /*#__PURE__*/React.createElement(React.Suspense, {
|
|
381
|
+
fallback: /*#__PURE__*/React.createElement(Block, {
|
|
382
|
+
set: setBlock
|
|
383
|
+
})
|
|
384
|
+
}, children)));
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
React.useEffect(() => {
|
|
388
|
+
const container = canvasRef.current;
|
|
389
|
+
return () => unmountComponentAtNode(container);
|
|
390
|
+
}, []);
|
|
391
|
+
return /*#__PURE__*/React.createElement("div", _extends({
|
|
392
|
+
ref: containerRef,
|
|
393
|
+
style: {
|
|
394
|
+
position: 'relative',
|
|
395
|
+
width: '100%',
|
|
396
|
+
height: '100%',
|
|
397
|
+
overflow: 'hidden',
|
|
398
|
+
...style
|
|
399
|
+
}
|
|
400
|
+
}, divProps), /*#__PURE__*/React.createElement("canvas", {
|
|
401
|
+
ref: mergeRefs([canvasRef, forwardedRef]),
|
|
402
|
+
style: {
|
|
403
|
+
display: 'block'
|
|
404
|
+
}
|
|
405
|
+
}, fallback));
|
|
406
|
+
});
|
|
407
|
+
|
|
404
408
|
export { Canvas, roots as _roots, act, advance, applyProps, createPortal, createRoot, createPointerEvents as events, invalidate, reconciler, render, unmountComponentAtNode };
|