@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
|
@@ -2,16 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var hooks = require('./hooks-
|
|
6
|
-
var THREE = require('three');
|
|
7
|
-
var React = require('react');
|
|
8
|
-
var constants = require('react-reconciler/constants');
|
|
5
|
+
var hooks = require('./hooks-6526f63c.cjs.dev.js');
|
|
9
6
|
var _extends = require('@babel/runtime/helpers/extends');
|
|
7
|
+
var React = require('react');
|
|
8
|
+
var THREE = require('three');
|
|
10
9
|
var mergeRefs = require('react-merge-refs');
|
|
11
10
|
var useMeasure = require('react-use-measure');
|
|
12
|
-
var
|
|
13
|
-
var omit = require('lodash-es/omit');
|
|
11
|
+
var constants = require('react-reconciler/constants');
|
|
14
12
|
require('react-reconciler');
|
|
13
|
+
require('scheduler');
|
|
15
14
|
require('suspend-react');
|
|
16
15
|
require('zustand');
|
|
17
16
|
|
|
@@ -26,21 +25,21 @@ function _interopNamespace(e) {
|
|
|
26
25
|
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
27
26
|
Object.defineProperty(n, k, d.get ? d : {
|
|
28
27
|
enumerable: true,
|
|
29
|
-
get: function () {
|
|
28
|
+
get: function () {
|
|
29
|
+
return e[k];
|
|
30
|
+
}
|
|
30
31
|
});
|
|
31
32
|
}
|
|
32
33
|
});
|
|
33
34
|
}
|
|
34
|
-
n[
|
|
35
|
+
n['default'] = e;
|
|
35
36
|
return Object.freeze(n);
|
|
36
37
|
}
|
|
37
38
|
|
|
38
|
-
var THREE__namespace = /*#__PURE__*/_interopNamespace(THREE);
|
|
39
39
|
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
40
|
+
var THREE__namespace = /*#__PURE__*/_interopNamespace(THREE);
|
|
40
41
|
var mergeRefs__default = /*#__PURE__*/_interopDefault(mergeRefs);
|
|
41
42
|
var useMeasure__default = /*#__PURE__*/_interopDefault(useMeasure);
|
|
42
|
-
var pick__default = /*#__PURE__*/_interopDefault(pick);
|
|
43
|
-
var omit__default = /*#__PURE__*/_interopDefault(omit);
|
|
44
43
|
|
|
45
44
|
// @ts-ignore
|
|
46
45
|
const CLICK = 'click';
|
|
@@ -149,111 +148,6 @@ function createPointerEvents(store) {
|
|
|
149
148
|
};
|
|
150
149
|
}
|
|
151
150
|
|
|
152
|
-
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.
|
|
153
|
-
// To get around it, we can conditionally useEffect on the server (no-op) and
|
|
154
|
-
// useLayoutEffect in the browser.
|
|
155
|
-
|
|
156
|
-
const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? React__namespace.useLayoutEffect : React__namespace.useEffect;
|
|
157
|
-
|
|
158
|
-
function Block({
|
|
159
|
-
set
|
|
160
|
-
}) {
|
|
161
|
-
useIsomorphicLayoutEffect(() => {
|
|
162
|
-
set(new Promise(() => null));
|
|
163
|
-
return () => set(false);
|
|
164
|
-
}, []);
|
|
165
|
-
return null;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
class ErrorBoundary extends React__namespace.Component {
|
|
169
|
-
constructor(...args) {
|
|
170
|
-
super(...args);
|
|
171
|
-
this.state = {
|
|
172
|
-
error: false
|
|
173
|
-
};
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
componentDidCatch(error) {
|
|
177
|
-
this.props.set(error);
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
render() {
|
|
181
|
-
return this.state.error ? null : this.props.children;
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
ErrorBoundary.getDerivedStateFromError = () => ({
|
|
187
|
-
error: true
|
|
188
|
-
});
|
|
189
|
-
|
|
190
|
-
const Canvas = /*#__PURE__*/React__namespace.forwardRef(function Canvas({
|
|
191
|
-
children,
|
|
192
|
-
fallback,
|
|
193
|
-
resize,
|
|
194
|
-
style,
|
|
195
|
-
events,
|
|
196
|
-
...props
|
|
197
|
-
}, forwardedRef) {
|
|
198
|
-
const canvasProps = pick__default["default"](props, CANVAS_PROPS);
|
|
199
|
-
const divProps = omit__default["default"](props, CANVAS_PROPS);
|
|
200
|
-
const [containerRef, {
|
|
201
|
-
width,
|
|
202
|
-
height
|
|
203
|
-
}] = useMeasure__default["default"]({
|
|
204
|
-
scroll: true,
|
|
205
|
-
debounce: {
|
|
206
|
-
scroll: 50,
|
|
207
|
-
resize: 0
|
|
208
|
-
},
|
|
209
|
-
...resize
|
|
210
|
-
});
|
|
211
|
-
const canvasRef = React__namespace.useRef(null);
|
|
212
|
-
const [block, setBlock] = React__namespace.useState(false);
|
|
213
|
-
const [error, setError] = React__namespace.useState(false); // Suspend this component if block is a promise (2nd run)
|
|
214
|
-
|
|
215
|
-
if (block) throw block; // Throw exception outwards if anything within canvas throws
|
|
216
|
-
|
|
217
|
-
if (error) throw error; // Execute JSX in the reconciler as a layout-effect
|
|
218
|
-
|
|
219
|
-
useIsomorphicLayoutEffect(() => {
|
|
220
|
-
if (width > 0 && height > 0) {
|
|
221
|
-
render( /*#__PURE__*/React__namespace.createElement(ErrorBoundary, {
|
|
222
|
-
set: setError
|
|
223
|
-
}, /*#__PURE__*/React__namespace.createElement(React__namespace.Suspense, {
|
|
224
|
-
fallback: /*#__PURE__*/React__namespace.createElement(Block, {
|
|
225
|
-
set: setBlock
|
|
226
|
-
})
|
|
227
|
-
}, children)), canvasRef.current, { ...canvasProps,
|
|
228
|
-
size: {
|
|
229
|
-
width,
|
|
230
|
-
height
|
|
231
|
-
},
|
|
232
|
-
events: events || createPointerEvents
|
|
233
|
-
});
|
|
234
|
-
}
|
|
235
|
-
}, [width, height, children, canvasProps]);
|
|
236
|
-
React__namespace.useEffect(() => {
|
|
237
|
-
const container = canvasRef.current;
|
|
238
|
-
return () => unmountComponentAtNode(container);
|
|
239
|
-
}, []);
|
|
240
|
-
return /*#__PURE__*/React__namespace.createElement("div", _extends({
|
|
241
|
-
ref: containerRef,
|
|
242
|
-
style: {
|
|
243
|
-
position: 'relative',
|
|
244
|
-
width: '100%',
|
|
245
|
-
height: '100%',
|
|
246
|
-
overflow: 'hidden',
|
|
247
|
-
...style
|
|
248
|
-
}
|
|
249
|
-
}, divProps), /*#__PURE__*/React__namespace.createElement("canvas", {
|
|
250
|
-
ref: mergeRefs__default["default"]([canvasRef, forwardedRef]),
|
|
251
|
-
style: {
|
|
252
|
-
display: 'block'
|
|
253
|
-
}
|
|
254
|
-
}, fallback));
|
|
255
|
-
});
|
|
256
|
-
|
|
257
151
|
const roots = new Map();
|
|
258
152
|
const {
|
|
259
153
|
invalidate,
|
|
@@ -284,86 +178,92 @@ const createRendererInstance = (gl, canvas) => {
|
|
|
284
178
|
|
|
285
179
|
function createRoot(canvas, config) {
|
|
286
180
|
return {
|
|
287
|
-
render: element =>
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
181
|
+
render: element => {
|
|
182
|
+
var _store;
|
|
183
|
+
|
|
184
|
+
let {
|
|
185
|
+
gl,
|
|
186
|
+
size,
|
|
187
|
+
events,
|
|
188
|
+
onCreated,
|
|
189
|
+
...props
|
|
190
|
+
} = config || {}; // Allow size to take on container bounds initially
|
|
191
|
+
|
|
192
|
+
if (!size) {
|
|
193
|
+
var _canvas$parentElement, _canvas$parentElement2, _canvas$parentElement3, _canvas$parentElement4;
|
|
194
|
+
|
|
195
|
+
size = {
|
|
196
|
+
width: (_canvas$parentElement = (_canvas$parentElement2 = canvas.parentElement) == null ? void 0 : _canvas$parentElement2.clientWidth) != null ? _canvas$parentElement : 0,
|
|
197
|
+
height: (_canvas$parentElement3 = (_canvas$parentElement4 = canvas.parentElement) == null ? void 0 : _canvas$parentElement4.clientHeight) != null ? _canvas$parentElement3 : 0
|
|
198
|
+
};
|
|
199
|
+
}
|
|
291
200
|
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
onCreated,
|
|
297
|
-
...props
|
|
298
|
-
} = {}) {
|
|
299
|
-
var _store;
|
|
201
|
+
let root = roots.get(canvas);
|
|
202
|
+
let fiber = root == null ? void 0 : root.fiber;
|
|
203
|
+
let store = root == null ? void 0 : root.store;
|
|
204
|
+
let state = (_store = store) == null ? void 0 : _store.getState();
|
|
300
205
|
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
206
|
+
if (fiber && state) {
|
|
207
|
+
// When a root was found, see if any fundamental props must be changed or exchanged
|
|
208
|
+
// Check pixelratio
|
|
209
|
+
if (props.dpr !== undefined && state.viewport.dpr !== hooks.calculateDpr(props.dpr)) state.setDpr(props.dpr); // Check size
|
|
304
210
|
|
|
305
|
-
|
|
306
|
-
width: (_canvas$parentElement = (_canvas$parentElement2 = canvas.parentElement) == null ? void 0 : _canvas$parentElement2.clientWidth) != null ? _canvas$parentElement : 0,
|
|
307
|
-
height: (_canvas$parentElement3 = (_canvas$parentElement4 = canvas.parentElement) == null ? void 0 : _canvas$parentElement4.clientHeight) != null ? _canvas$parentElement3 : 0
|
|
308
|
-
};
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
let root = roots.get(canvas);
|
|
312
|
-
let fiber = root == null ? void 0 : root.fiber;
|
|
313
|
-
let store = root == null ? void 0 : root.store;
|
|
314
|
-
let state = (_store = store) == null ? void 0 : _store.getState();
|
|
211
|
+
if (state.size.width !== size.width || state.size.height !== size.height) state.setSize(size.width, size.height); // Check frameloop
|
|
315
212
|
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
// Check pixelratio
|
|
319
|
-
if (props.dpr !== undefined && state.viewport.dpr !== hooks.calculateDpr(props.dpr)) state.setDpr(props.dpr); // Check size
|
|
213
|
+
if (state.frameloop !== props.frameloop) state.setFrameloop(props.frameloop); // For some props we want to reset the entire root
|
|
214
|
+
// Changes to the color-space
|
|
320
215
|
|
|
321
|
-
|
|
322
|
-
// Changes to the color-space
|
|
216
|
+
const linearChanged = props.linear !== state.internal.lastProps.linear;
|
|
323
217
|
|
|
324
|
-
|
|
218
|
+
if (linearChanged) {
|
|
219
|
+
unmountComponentAtNode(canvas);
|
|
220
|
+
fiber = undefined;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
325
223
|
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
}
|
|
224
|
+
if (!fiber) {
|
|
225
|
+
// If no root has been found, make one
|
|
226
|
+
// Create gl
|
|
227
|
+
const glRenderer = createRendererInstance(gl, canvas); // Create store
|
|
331
228
|
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
229
|
+
store = hooks.createStore(applyProps, invalidate, advance, {
|
|
230
|
+
gl: glRenderer,
|
|
231
|
+
size,
|
|
232
|
+
...props
|
|
233
|
+
});
|
|
234
|
+
const state = store.getState(); // Create renderer
|
|
336
235
|
|
|
337
|
-
|
|
338
|
-
gl: glRenderer,
|
|
339
|
-
size,
|
|
340
|
-
...props
|
|
341
|
-
});
|
|
342
|
-
const state = store.getState(); // Create renderer
|
|
236
|
+
fiber = reconciler.createContainer(store, constants.ConcurrentRoot, false, null); // Map it
|
|
343
237
|
|
|
344
|
-
|
|
238
|
+
roots.set(canvas, {
|
|
239
|
+
fiber,
|
|
240
|
+
store
|
|
241
|
+
}); // Store events internally
|
|
345
242
|
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
243
|
+
if (events) state.set({
|
|
244
|
+
events: events(store)
|
|
245
|
+
});
|
|
246
|
+
}
|
|
350
247
|
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
248
|
+
if (store && fiber) {
|
|
249
|
+
reconciler.updateContainer( /*#__PURE__*/React__namespace.createElement(Provider, {
|
|
250
|
+
store: store,
|
|
251
|
+
element: element,
|
|
252
|
+
onCreated: onCreated,
|
|
253
|
+
target: canvas
|
|
254
|
+
}), fiber, null, () => undefined);
|
|
255
|
+
return store;
|
|
256
|
+
} else {
|
|
257
|
+
throw 'Error creating root!';
|
|
258
|
+
}
|
|
259
|
+
},
|
|
260
|
+
unmount: () => unmountComponentAtNode(canvas)
|
|
261
|
+
};
|
|
262
|
+
}
|
|
355
263
|
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
element: element,
|
|
360
|
-
onCreated: onCreated,
|
|
361
|
-
target: canvas
|
|
362
|
-
}), fiber, null, () => undefined);
|
|
363
|
-
return store;
|
|
364
|
-
} else {
|
|
365
|
-
throw 'Error creating root!';
|
|
366
|
-
}
|
|
264
|
+
function render(element, canvas, config = {}) {
|
|
265
|
+
console.warn('R3F.render is no longer supported in React 18. Use createRoot instead!');
|
|
266
|
+
return createRoot(canvas, config).render(element);
|
|
367
267
|
}
|
|
368
268
|
|
|
369
269
|
function Provider({
|
|
@@ -419,7 +319,7 @@ function unmountComponentAtNode(canvas, callback) {
|
|
|
419
319
|
}
|
|
420
320
|
}
|
|
421
321
|
|
|
422
|
-
const act =
|
|
322
|
+
const act = React__namespace.unstable_act;
|
|
423
323
|
|
|
424
324
|
function createPortal(children, container) {
|
|
425
325
|
return reconciler.createPortal(children, container, null, null);
|
|
@@ -431,6 +331,110 @@ reconciler.injectIntoDevTools({
|
|
|
431
331
|
version: '18.0.0'
|
|
432
332
|
});
|
|
433
333
|
|
|
334
|
+
const CANVAS_PROPS = ['gl', 'events', 'shadows', 'linear', 'flat', 'orthographic', 'frameloop', 'dpr', 'performance', 'clock', 'raycaster', 'camera', 'onPointerMissed', 'onCreated'];
|
|
335
|
+
|
|
336
|
+
function Block({
|
|
337
|
+
set
|
|
338
|
+
}) {
|
|
339
|
+
React__namespace.useLayoutEffect(() => {
|
|
340
|
+
set(new Promise(() => null));
|
|
341
|
+
return () => set(false);
|
|
342
|
+
}, [set]);
|
|
343
|
+
return null;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
class ErrorBoundary extends React__namespace.Component {
|
|
347
|
+
constructor(...args) {
|
|
348
|
+
super(...args);
|
|
349
|
+
this.state = {
|
|
350
|
+
error: false
|
|
351
|
+
};
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
componentDidCatch(error) {
|
|
355
|
+
this.props.set(error);
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
render() {
|
|
359
|
+
return this.state.error ? null : this.props.children;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
ErrorBoundary.getDerivedStateFromError = () => ({
|
|
365
|
+
error: true
|
|
366
|
+
});
|
|
367
|
+
|
|
368
|
+
const Canvas = /*#__PURE__*/React__namespace.forwardRef(function Canvas({
|
|
369
|
+
children,
|
|
370
|
+
fallback,
|
|
371
|
+
resize,
|
|
372
|
+
style,
|
|
373
|
+
events,
|
|
374
|
+
...props
|
|
375
|
+
}, forwardedRef) {
|
|
376
|
+
// Create a known catalogue of Threejs-native elements
|
|
377
|
+
// This will include the entire THREE namespace by default, users can extend
|
|
378
|
+
// their own elements by using the createRoot API instead
|
|
379
|
+
React__namespace.useMemo(() => hooks.extend(THREE__namespace), []);
|
|
380
|
+
const [containerRef, {
|
|
381
|
+
width,
|
|
382
|
+
height
|
|
383
|
+
}] = useMeasure__default['default']({
|
|
384
|
+
scroll: true,
|
|
385
|
+
debounce: {
|
|
386
|
+
scroll: 50,
|
|
387
|
+
resize: 0
|
|
388
|
+
},
|
|
389
|
+
...resize
|
|
390
|
+
});
|
|
391
|
+
const canvasRef = React__namespace.useRef(null);
|
|
392
|
+
const canvasProps = hooks.pick(props, CANVAS_PROPS);
|
|
393
|
+
const divProps = hooks.omit(props, CANVAS_PROPS);
|
|
394
|
+
const [block, setBlock] = React__namespace.useState(false);
|
|
395
|
+
const [error, setError] = React__namespace.useState(false); // Suspend this component if block is a promise (2nd run)
|
|
396
|
+
|
|
397
|
+
if (block) throw block; // Throw exception outwards if anything within canvas throws
|
|
398
|
+
|
|
399
|
+
if (error) throw error;
|
|
400
|
+
|
|
401
|
+
if (width > 0 && height > 0) {
|
|
402
|
+
createRoot(canvasRef.current, { ...canvasProps,
|
|
403
|
+
size: {
|
|
404
|
+
width,
|
|
405
|
+
height
|
|
406
|
+
},
|
|
407
|
+
events: events || createPointerEvents
|
|
408
|
+
}).render( /*#__PURE__*/React__namespace.createElement(ErrorBoundary, {
|
|
409
|
+
set: setError
|
|
410
|
+
}, /*#__PURE__*/React__namespace.createElement(React__namespace.Suspense, {
|
|
411
|
+
fallback: /*#__PURE__*/React__namespace.createElement(Block, {
|
|
412
|
+
set: setBlock
|
|
413
|
+
})
|
|
414
|
+
}, children)));
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
React__namespace.useEffect(() => {
|
|
418
|
+
const container = canvasRef.current;
|
|
419
|
+
return () => unmountComponentAtNode(container);
|
|
420
|
+
}, []);
|
|
421
|
+
return /*#__PURE__*/React__namespace.createElement("div", _extends({
|
|
422
|
+
ref: containerRef,
|
|
423
|
+
style: {
|
|
424
|
+
position: 'relative',
|
|
425
|
+
width: '100%',
|
|
426
|
+
height: '100%',
|
|
427
|
+
overflow: 'hidden',
|
|
428
|
+
...style
|
|
429
|
+
}
|
|
430
|
+
}, divProps), /*#__PURE__*/React__namespace.createElement("canvas", {
|
|
431
|
+
ref: mergeRefs__default['default']([canvasRef, forwardedRef]),
|
|
432
|
+
style: {
|
|
433
|
+
display: 'block'
|
|
434
|
+
}
|
|
435
|
+
}, fallback));
|
|
436
|
+
});
|
|
437
|
+
|
|
434
438
|
exports.ReactThreeFiber = hooks.threeTypes;
|
|
435
439
|
exports.addAfterEffect = hooks.addAfterEffect;
|
|
436
440
|
exports.addEffect = hooks.addEffect;
|