@react-three/fiber 8.0.0-beta-03 → 8.0.0-beta-04
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/dist/declarations/src/core/events.d.ts +1 -0
- package/dist/declarations/src/{web → core}/index.d.ts +2 -4
- package/dist/declarations/src/index.d.ts +3 -1
- package/dist/declarations/src/native/Canvas.d.ts +2 -5
- package/dist/declarations/src/native/events.d.ts +0 -1
- package/dist/declarations/src/native.d.ts +3 -1
- package/dist/declarations/src/web/Canvas.d.ts +1 -1
- package/dist/declarations/src/web/events.d.ts +0 -1
- package/dist/{hooks-7b7e01e6.cjs.prod.js → index-eb414398.cjs.prod.js} +276 -60
- package/dist/{hooks-15c12e3e.esm.js → index-fccd77b0.esm.js} +265 -54
- package/dist/{hooks-6526f63c.cjs.dev.js → index-ff3eb68b.cjs.dev.js} +276 -60
- package/dist/react-three-fiber.cjs.dev.js +53 -274
- package/dist/react-three-fiber.cjs.prod.js +53 -274
- package/dist/react-three-fiber.esm.js +29 -250
- package/native/dist/react-three-fiber-native.cjs.dev.js +135 -336
- package/native/dist/react-three-fiber-native.cjs.prod.js +135 -336
- package/native/dist/react-three-fiber-native.esm.js +110 -311
- package/package.json +2 -1
- package/dist/declarations/src/native/index.d.ts +0 -36
|
@@ -2,17 +2,17 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var index = require('./index-eb414398.cjs.prod.js');
|
|
6
6
|
var _extends = require('@babel/runtime/helpers/extends');
|
|
7
7
|
var React = require('react');
|
|
8
8
|
var THREE = require('three');
|
|
9
9
|
var mergeRefs = require('react-merge-refs');
|
|
10
10
|
var useMeasure = require('react-use-measure');
|
|
11
|
-
var constants = require('react-reconciler/constants');
|
|
12
|
-
require('react-reconciler');
|
|
13
|
-
require('scheduler');
|
|
14
11
|
require('suspend-react');
|
|
12
|
+
require('react-reconciler/constants');
|
|
15
13
|
require('zustand');
|
|
14
|
+
require('react-reconciler');
|
|
15
|
+
require('scheduler');
|
|
16
16
|
|
|
17
17
|
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
|
|
18
18
|
|
|
@@ -41,66 +41,25 @@ var THREE__namespace = /*#__PURE__*/_interopNamespace(THREE);
|
|
|
41
41
|
var mergeRefs__default = /*#__PURE__*/_interopDefault(mergeRefs);
|
|
42
42
|
var useMeasure__default = /*#__PURE__*/_interopDefault(useMeasure);
|
|
43
43
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
const WHEEL = 'wheel'; // https://github.com/facebook/react/tree/main/packages/react-reconciler#getcurrenteventpriority
|
|
57
|
-
// Gives React a clue as to how import the current interaction is
|
|
58
|
-
|
|
59
|
-
function getEventPriority() {
|
|
60
|
-
var _window, _window$event;
|
|
61
|
-
|
|
62
|
-
let name = (_window = window) == null ? void 0 : (_window$event = _window.event) == null ? void 0 : _window$event.type;
|
|
63
|
-
|
|
64
|
-
switch (name) {
|
|
65
|
-
case CLICK:
|
|
66
|
-
case CONTEXTMENU:
|
|
67
|
-
case DBLCLICK:
|
|
68
|
-
case POINTERCANCEL:
|
|
69
|
-
case POINTERDOWN:
|
|
70
|
-
case POINTERUP:
|
|
71
|
-
return constants.DiscreteEventPriority;
|
|
72
|
-
|
|
73
|
-
case POINTERMOVE:
|
|
74
|
-
case POINTEROUT:
|
|
75
|
-
case POINTEROVER:
|
|
76
|
-
case POINTERENTER:
|
|
77
|
-
case POINTERLEAVE:
|
|
78
|
-
case WHEEL:
|
|
79
|
-
return constants.ContinuousEventPriority;
|
|
80
|
-
|
|
81
|
-
default:
|
|
82
|
-
return constants.DefaultEventPriority;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
44
|
+
const DOM_EVENTS = {
|
|
45
|
+
onClick: ['click', false],
|
|
46
|
+
onContextMenu: ['contextmenu', false],
|
|
47
|
+
onDoubleClick: ['dblclick', false],
|
|
48
|
+
onWheel: ['wheel', true],
|
|
49
|
+
onPointerDown: ['pointerdown', true],
|
|
50
|
+
onPointerUp: ['pointerup', true],
|
|
51
|
+
onPointerLeave: ['pointerleave', true],
|
|
52
|
+
onPointerMove: ['pointermove', true],
|
|
53
|
+
onPointerCancel: ['pointercancel', true],
|
|
54
|
+
onLostPointerCapture: ['lostpointercapture', true]
|
|
55
|
+
};
|
|
85
56
|
function createPointerEvents(store) {
|
|
86
57
|
const {
|
|
87
58
|
handlePointer
|
|
88
|
-
} =
|
|
89
|
-
const names = {
|
|
90
|
-
onClick: [CLICK, false],
|
|
91
|
-
onContextMenu: [CONTEXTMENU, false],
|
|
92
|
-
onDoubleClick: [DBLCLICK, false],
|
|
93
|
-
onWheel: [WHEEL, true],
|
|
94
|
-
onPointerDown: [POINTERDOWN, true],
|
|
95
|
-
onPointerUp: [POINTERUP, true],
|
|
96
|
-
onPointerLeave: [POINTERLEAVE, true],
|
|
97
|
-
onPointerMove: [POINTERMOVE, true],
|
|
98
|
-
onPointerCancel: [POINTERCANCEL, true],
|
|
99
|
-
onLostPointerCapture: ['lostpointercapture', true]
|
|
100
|
-
};
|
|
59
|
+
} = index.createEvents(store);
|
|
101
60
|
return {
|
|
102
61
|
connected: false,
|
|
103
|
-
handlers: Object.keys(
|
|
62
|
+
handlers: Object.keys(DOM_EVENTS).reduce((acc, key) => ({ ...acc,
|
|
104
63
|
[key]: handlePointer(key)
|
|
105
64
|
}), {}),
|
|
106
65
|
connect: target => {
|
|
@@ -117,7 +76,7 @@ function createPointerEvents(store) {
|
|
|
117
76
|
}
|
|
118
77
|
}));
|
|
119
78
|
Object.entries((_events$handlers = events == null ? void 0 : events.handlers) != null ? _events$handlers : []).forEach(([name, event]) => {
|
|
120
|
-
const [eventName, passive] =
|
|
79
|
+
const [eventName, passive] = DOM_EVENTS[name];
|
|
121
80
|
target.addEventListener(eventName, event, {
|
|
122
81
|
passive
|
|
123
82
|
});
|
|
@@ -134,7 +93,7 @@ function createPointerEvents(store) {
|
|
|
134
93
|
|
|
135
94
|
Object.entries((_events$handlers2 = events.handlers) != null ? _events$handlers2 : []).forEach(([name, event]) => {
|
|
136
95
|
if (events && events.connected instanceof HTMLElement) {
|
|
137
|
-
const [eventName] =
|
|
96
|
+
const [eventName] = DOM_EVENTS[name];
|
|
138
97
|
events.connected.removeEventListener(eventName, event);
|
|
139
98
|
}
|
|
140
99
|
});
|
|
@@ -148,189 +107,6 @@ function createPointerEvents(store) {
|
|
|
148
107
|
};
|
|
149
108
|
}
|
|
150
109
|
|
|
151
|
-
const roots = new Map();
|
|
152
|
-
const {
|
|
153
|
-
invalidate,
|
|
154
|
-
advance
|
|
155
|
-
} = hooks.createLoop(roots);
|
|
156
|
-
const {
|
|
157
|
-
reconciler,
|
|
158
|
-
applyProps
|
|
159
|
-
} = hooks.createRenderer(roots, getEventPriority);
|
|
160
|
-
|
|
161
|
-
const createRendererInstance = (gl, canvas) => {
|
|
162
|
-
const customRenderer = typeof gl === 'function' ? gl(canvas) : gl;
|
|
163
|
-
if (hooks.isRenderer(customRenderer)) return customRenderer;
|
|
164
|
-
const renderer = new THREE__namespace.WebGLRenderer({
|
|
165
|
-
powerPreference: 'high-performance',
|
|
166
|
-
canvas: canvas,
|
|
167
|
-
antialias: true,
|
|
168
|
-
alpha: true,
|
|
169
|
-
...gl
|
|
170
|
-
}); // Set color management
|
|
171
|
-
|
|
172
|
-
renderer.outputEncoding = THREE__namespace.sRGBEncoding;
|
|
173
|
-
renderer.toneMapping = THREE__namespace.ACESFilmicToneMapping; // Set gl props
|
|
174
|
-
|
|
175
|
-
if (gl) applyProps(renderer, gl);
|
|
176
|
-
return renderer;
|
|
177
|
-
};
|
|
178
|
-
|
|
179
|
-
function createRoot(canvas, config) {
|
|
180
|
-
return {
|
|
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
|
-
}
|
|
200
|
-
|
|
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();
|
|
205
|
-
|
|
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
|
|
210
|
-
|
|
211
|
-
if (state.size.width !== size.width || state.size.height !== size.height) state.setSize(size.width, size.height); // Check frameloop
|
|
212
|
-
|
|
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
|
|
215
|
-
|
|
216
|
-
const linearChanged = props.linear !== state.internal.lastProps.linear;
|
|
217
|
-
|
|
218
|
-
if (linearChanged) {
|
|
219
|
-
unmountComponentAtNode(canvas);
|
|
220
|
-
fiber = undefined;
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
if (!fiber) {
|
|
225
|
-
// If no root has been found, make one
|
|
226
|
-
// Create gl
|
|
227
|
-
const glRenderer = createRendererInstance(gl, canvas); // Create store
|
|
228
|
-
|
|
229
|
-
store = hooks.createStore(applyProps, invalidate, advance, {
|
|
230
|
-
gl: glRenderer,
|
|
231
|
-
size,
|
|
232
|
-
...props
|
|
233
|
-
});
|
|
234
|
-
const state = store.getState(); // Create renderer
|
|
235
|
-
|
|
236
|
-
fiber = reconciler.createContainer(store, constants.ConcurrentRoot, false, null); // Map it
|
|
237
|
-
|
|
238
|
-
roots.set(canvas, {
|
|
239
|
-
fiber,
|
|
240
|
-
store
|
|
241
|
-
}); // Store events internally
|
|
242
|
-
|
|
243
|
-
if (events) state.set({
|
|
244
|
-
events: events(store)
|
|
245
|
-
});
|
|
246
|
-
}
|
|
247
|
-
|
|
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
|
-
}
|
|
263
|
-
|
|
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);
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
function Provider({
|
|
270
|
-
store,
|
|
271
|
-
element,
|
|
272
|
-
onCreated,
|
|
273
|
-
target
|
|
274
|
-
}) {
|
|
275
|
-
React__namespace.useEffect(() => {
|
|
276
|
-
const state = store.getState(); // Flag the canvas active, rendering will now begin
|
|
277
|
-
|
|
278
|
-
state.set(state => ({
|
|
279
|
-
internal: { ...state.internal,
|
|
280
|
-
active: true
|
|
281
|
-
}
|
|
282
|
-
})); // Connect events
|
|
283
|
-
|
|
284
|
-
state.events.connect == null ? void 0 : state.events.connect(target); // Notifiy that init is completed, the scene graph exists, but nothing has yet rendered
|
|
285
|
-
|
|
286
|
-
if (onCreated) onCreated(state); // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
287
|
-
}, []);
|
|
288
|
-
return /*#__PURE__*/React__namespace.createElement(hooks.context.Provider, {
|
|
289
|
-
value: store
|
|
290
|
-
}, element);
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
function unmountComponentAtNode(canvas, callback) {
|
|
294
|
-
const root = roots.get(canvas);
|
|
295
|
-
const fiber = root == null ? void 0 : root.fiber;
|
|
296
|
-
|
|
297
|
-
if (fiber) {
|
|
298
|
-
const state = root == null ? void 0 : root.store.getState();
|
|
299
|
-
if (state) state.internal.active = false;
|
|
300
|
-
reconciler.updateContainer(null, fiber, null, () => {
|
|
301
|
-
if (state) {
|
|
302
|
-
setTimeout(() => {
|
|
303
|
-
try {
|
|
304
|
-
var _state$gl, _state$gl$renderLists, _state$gl2, _state$gl3;
|
|
305
|
-
|
|
306
|
-
state.events.disconnect == null ? void 0 : state.events.disconnect();
|
|
307
|
-
(_state$gl = state.gl) == null ? void 0 : (_state$gl$renderLists = _state$gl.renderLists) == null ? void 0 : _state$gl$renderLists.dispose == null ? void 0 : _state$gl$renderLists.dispose();
|
|
308
|
-
(_state$gl2 = state.gl) == null ? void 0 : _state$gl2.forceContextLoss == null ? void 0 : _state$gl2.forceContextLoss();
|
|
309
|
-
if ((_state$gl3 = state.gl) != null && _state$gl3.xr) state.internal.xr.disconnect();
|
|
310
|
-
hooks.dispose(state);
|
|
311
|
-
roots.delete(canvas);
|
|
312
|
-
if (callback) callback(canvas);
|
|
313
|
-
} catch (e) {
|
|
314
|
-
/* ... */
|
|
315
|
-
}
|
|
316
|
-
}, 500);
|
|
317
|
-
}
|
|
318
|
-
});
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
const act = React__namespace.unstable_act;
|
|
323
|
-
|
|
324
|
-
function createPortal(children, container) {
|
|
325
|
-
return reconciler.createPortal(children, container, null, null);
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
reconciler.injectIntoDevTools({
|
|
329
|
-
bundleType: 0 ,
|
|
330
|
-
rendererPackageName: '@react-three/fiber',
|
|
331
|
-
version: '18.0.0'
|
|
332
|
-
});
|
|
333
|
-
|
|
334
110
|
const CANVAS_PROPS = ['gl', 'events', 'shadows', 'linear', 'flat', 'orthographic', 'frameloop', 'dpr', 'performance', 'clock', 'raycaster', 'camera', 'onPointerMissed', 'onCreated'];
|
|
335
111
|
|
|
336
112
|
function Block({
|
|
@@ -376,7 +152,7 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(function Canvas({
|
|
|
376
152
|
// Create a known catalogue of Threejs-native elements
|
|
377
153
|
// This will include the entire THREE namespace by default, users can extend
|
|
378
154
|
// their own elements by using the createRoot API instead
|
|
379
|
-
React__namespace.useMemo(() =>
|
|
155
|
+
React__namespace.useMemo(() => index.extend(THREE__namespace), []);
|
|
380
156
|
const [containerRef, {
|
|
381
157
|
width,
|
|
382
158
|
height
|
|
@@ -389,8 +165,9 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(function Canvas({
|
|
|
389
165
|
...resize
|
|
390
166
|
});
|
|
391
167
|
const canvasRef = React__namespace.useRef(null);
|
|
392
|
-
const
|
|
393
|
-
const
|
|
168
|
+
const [canvas, setCanvas] = React__namespace.useState(null);
|
|
169
|
+
const canvasProps = index.pick(props, CANVAS_PROPS);
|
|
170
|
+
const divProps = index.omit(props, CANVAS_PROPS);
|
|
394
171
|
const [block, setBlock] = React__namespace.useState(false);
|
|
395
172
|
const [error, setError] = React__namespace.useState(false); // Suspend this component if block is a promise (2nd run)
|
|
396
173
|
|
|
@@ -398,8 +175,8 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(function Canvas({
|
|
|
398
175
|
|
|
399
176
|
if (error) throw error;
|
|
400
177
|
|
|
401
|
-
if (width > 0 && height > 0) {
|
|
402
|
-
createRoot(
|
|
178
|
+
if (width > 0 && height > 0 && canvas) {
|
|
179
|
+
index.createRoot(canvas, { ...canvasProps,
|
|
403
180
|
size: {
|
|
404
181
|
width,
|
|
405
182
|
height
|
|
@@ -414,10 +191,12 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(function Canvas({
|
|
|
414
191
|
}, children)));
|
|
415
192
|
}
|
|
416
193
|
|
|
417
|
-
React__namespace.
|
|
418
|
-
|
|
419
|
-
return () => unmountComponentAtNode(container);
|
|
194
|
+
React__namespace.useLayoutEffect(() => {
|
|
195
|
+
setCanvas(canvasRef.current);
|
|
420
196
|
}, []);
|
|
197
|
+
React__namespace.useEffect(() => {
|
|
198
|
+
return () => index.unmountComponentAtNode(canvas);
|
|
199
|
+
}, [canvas]);
|
|
421
200
|
return /*#__PURE__*/React__namespace.createElement("div", _extends({
|
|
422
201
|
ref: containerRef,
|
|
423
202
|
style: {
|
|
@@ -435,27 +214,27 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(function Canvas({
|
|
|
435
214
|
}, fallback));
|
|
436
215
|
});
|
|
437
216
|
|
|
438
|
-
exports.ReactThreeFiber =
|
|
439
|
-
exports.
|
|
440
|
-
exports.
|
|
441
|
-
exports.
|
|
442
|
-
exports.
|
|
443
|
-
exports.
|
|
444
|
-
exports.
|
|
445
|
-
exports.
|
|
446
|
-
exports.
|
|
447
|
-
exports.
|
|
448
|
-
exports.
|
|
449
|
-
exports.
|
|
217
|
+
exports.ReactThreeFiber = index.threeTypes;
|
|
218
|
+
exports._roots = index.roots;
|
|
219
|
+
exports.act = index.act;
|
|
220
|
+
exports.addAfterEffect = index.addAfterEffect;
|
|
221
|
+
exports.addEffect = index.addEffect;
|
|
222
|
+
exports.addTail = index.addTail;
|
|
223
|
+
exports.advance = index.advance;
|
|
224
|
+
exports.applyProps = index.applyProps;
|
|
225
|
+
exports.context = index.context;
|
|
226
|
+
exports.createPortal = index.createPortal;
|
|
227
|
+
exports.createRoot = index.createRoot;
|
|
228
|
+
exports.dispose = index.dispose;
|
|
229
|
+
exports.extend = index.extend;
|
|
230
|
+
exports.invalidate = index.invalidate;
|
|
231
|
+
exports.reconciler = index.reconciler;
|
|
232
|
+
exports.render = index.render;
|
|
233
|
+
exports.unmountComponentAtNode = index.unmountComponentAtNode;
|
|
234
|
+
exports.useFrame = index.useFrame;
|
|
235
|
+
exports.useGraph = index.useGraph;
|
|
236
|
+
exports.useLoader = index.useLoader;
|
|
237
|
+
exports.useStore = index.useStore;
|
|
238
|
+
exports.useThree = index.useThree;
|
|
450
239
|
exports.Canvas = Canvas;
|
|
451
|
-
exports._roots = roots;
|
|
452
|
-
exports.act = act;
|
|
453
|
-
exports.advance = advance;
|
|
454
|
-
exports.applyProps = applyProps;
|
|
455
|
-
exports.createPortal = createPortal;
|
|
456
|
-
exports.createRoot = createRoot;
|
|
457
240
|
exports.events = createPointerEvents;
|
|
458
|
-
exports.invalidate = invalidate;
|
|
459
|
-
exports.reconciler = reconciler;
|
|
460
|
-
exports.render = render;
|
|
461
|
-
exports.unmountComponentAtNode = unmountComponentAtNode;
|