@react-three/fiber 9.0.0-alpha.2 → 9.0.0-alpha.4
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 +962 -522
- package/dist/declarations/src/core/events.d.ts +91 -69
- package/dist/declarations/src/core/hooks.d.ts +53 -27
- package/dist/declarations/src/core/index.d.ts +15 -60
- package/dist/declarations/src/core/loop.d.ts +31 -15
- package/dist/declarations/src/core/reconciler.d.ts +42 -0
- package/dist/declarations/src/core/renderer.d.ts +84 -40
- package/dist/declarations/src/core/stages.d.ts +64 -59
- package/dist/declarations/src/core/store.d.ts +134 -109
- package/dist/declarations/src/core/utils.d.ts +128 -80
- package/dist/declarations/src/index.d.ts +6 -10
- package/dist/declarations/src/native/Canvas.d.ts +14 -8
- package/dist/declarations/src/native/events.d.ts +4 -4
- package/dist/declarations/src/native.d.ts +6 -8
- package/dist/declarations/src/three-types.d.ts +56 -47
- package/dist/declarations/src/web/Canvas.d.ts +24 -11
- package/dist/declarations/src/web/events.d.ts +4 -4
- package/dist/{index-8128f248.cjs.prod.js → loop-7224f71f.cjs.prod.js} +1375 -1295
- package/dist/{index-5bd4d3cf.cjs.dev.js → loop-7f1fb121.cjs.dev.js} +1375 -1295
- package/dist/{index-47b7622a.esm.js → loop-bdf826ba.esm.js} +1372 -1295
- package/dist/react-three-fiber.cjs.d.ts +1 -0
- package/dist/react-three-fiber.cjs.dev.js +127 -116
- package/dist/react-three-fiber.cjs.prod.js +127 -116
- package/dist/react-three-fiber.esm.js +93 -85
- package/native/dist/react-three-fiber-native.cjs.d.ts +1 -0
- package/native/dist/react-three-fiber-native.cjs.dev.js +282 -213
- package/native/dist/react-three-fiber-native.cjs.prod.js +282 -213
- package/native/dist/react-three-fiber-native.esm.js +246 -182
- package/native/package.json +5 -5
- package/package.json +18 -12
- package/readme.md +253 -202
- package/dist/declarations/src/native/polyfills.d.ts +0 -1
|
@@ -1 +1,2 @@
|
|
|
1
1
|
export * from "./declarations/src/index";
|
|
2
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicmVhY3QtdGhyZWUtZmliZXIuY2pzLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuL2RlY2xhcmF0aW9ucy9zcmMvaW5kZXguZC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSJ9
|
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
+
var loop = require('./loop-7f1fb121.cjs.dev.js');
|
|
5
6
|
var _extends = require('@babel/runtime/helpers/extends');
|
|
6
7
|
var React = require('react');
|
|
7
8
|
var THREE = require('three');
|
|
8
9
|
var useMeasure = require('react-use-measure');
|
|
9
10
|
var itsFine = require('its-fine');
|
|
10
|
-
var index = require('./index-5bd4d3cf.cjs.dev.js');
|
|
11
11
|
require('react-reconciler/constants');
|
|
12
|
-
require('zustand');
|
|
12
|
+
require('zustand/traditional');
|
|
13
13
|
require('react-reconciler');
|
|
14
14
|
require('scheduler');
|
|
15
15
|
require('suspend-react');
|
|
@@ -50,64 +50,72 @@ const DOM_EVENTS = {
|
|
|
50
50
|
onPointerCancel: ['pointercancel', true],
|
|
51
51
|
onLostPointerCapture: ['lostpointercapture', true]
|
|
52
52
|
};
|
|
53
|
-
/** Default R3F event manager for web */
|
|
54
53
|
|
|
54
|
+
/** Default R3F event manager for web */
|
|
55
55
|
function createPointerEvents(store) {
|
|
56
56
|
const {
|
|
57
57
|
handlePointer
|
|
58
|
-
} =
|
|
58
|
+
} = loop.createEvents(store);
|
|
59
59
|
return {
|
|
60
60
|
priority: 1,
|
|
61
61
|
enabled: true,
|
|
62
|
-
|
|
63
62
|
compute(event, state, previous) {
|
|
64
63
|
// https://github.com/pmndrs/react-three-fiber/pull/782
|
|
65
64
|
// Events trigger outside of canvas when moved, use offsetX/Y by default and allow overrides
|
|
66
65
|
state.pointer.set(event.offsetX / state.size.width * 2 - 1, -(event.offsetY / state.size.height) * 2 + 1);
|
|
67
66
|
state.raycaster.setFromCamera(state.pointer, state.camera);
|
|
68
67
|
},
|
|
69
|
-
|
|
70
68
|
connected: undefined,
|
|
71
|
-
handlers: Object.keys(DOM_EVENTS).reduce((acc, key) => ({
|
|
69
|
+
handlers: Object.keys(DOM_EVENTS).reduce((acc, key) => ({
|
|
70
|
+
...acc,
|
|
72
71
|
[key]: handlePointer(key)
|
|
73
72
|
}), {}),
|
|
73
|
+
update: () => {
|
|
74
|
+
var _internal$lastEvent;
|
|
75
|
+
const {
|
|
76
|
+
events,
|
|
77
|
+
internal
|
|
78
|
+
} = store.getState();
|
|
79
|
+
if ((_internal$lastEvent = internal.lastEvent) != null && _internal$lastEvent.current && events.handlers) events.handlers.onPointerMove(internal.lastEvent.current);
|
|
80
|
+
},
|
|
74
81
|
connect: target => {
|
|
75
|
-
var _events$handlers;
|
|
76
|
-
|
|
77
82
|
const {
|
|
78
83
|
set,
|
|
79
84
|
events
|
|
80
85
|
} = store.getState();
|
|
81
86
|
events.disconnect == null ? void 0 : events.disconnect();
|
|
82
87
|
set(state => ({
|
|
83
|
-
events: {
|
|
88
|
+
events: {
|
|
89
|
+
...state.events,
|
|
84
90
|
connected: target
|
|
85
91
|
}
|
|
86
92
|
}));
|
|
87
|
-
|
|
88
|
-
const
|
|
89
|
-
|
|
90
|
-
passive
|
|
91
|
-
|
|
92
|
-
|
|
93
|
+
if (events.handlers) {
|
|
94
|
+
for (const name in events.handlers) {
|
|
95
|
+
const event = events.handlers[name];
|
|
96
|
+
const [eventName, passive] = DOM_EVENTS[name];
|
|
97
|
+
target.addEventListener(eventName, event, {
|
|
98
|
+
passive
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
}
|
|
93
102
|
},
|
|
94
103
|
disconnect: () => {
|
|
95
104
|
const {
|
|
96
105
|
set,
|
|
97
106
|
events
|
|
98
107
|
} = store.getState();
|
|
99
|
-
|
|
100
108
|
if (events.connected) {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
if (events && events.connected instanceof HTMLElement) {
|
|
109
|
+
if (events.handlers) {
|
|
110
|
+
for (const name in events.handlers) {
|
|
111
|
+
const event = events.handlers[name];
|
|
105
112
|
const [eventName] = DOM_EVENTS[name];
|
|
106
113
|
events.connected.removeEventListener(eventName, event);
|
|
107
114
|
}
|
|
108
|
-
}
|
|
115
|
+
}
|
|
109
116
|
set(state => ({
|
|
110
|
-
events: {
|
|
117
|
+
events: {
|
|
118
|
+
...state.events,
|
|
111
119
|
connected: undefined
|
|
112
120
|
}
|
|
113
121
|
}));
|
|
@@ -135,6 +143,7 @@ const CanvasImpl = /*#__PURE__*/React__namespace.forwardRef(function Canvas({
|
|
|
135
143
|
performance,
|
|
136
144
|
raycaster,
|
|
137
145
|
camera,
|
|
146
|
+
scene,
|
|
138
147
|
onPointerMissed,
|
|
139
148
|
onCreated,
|
|
140
149
|
stages,
|
|
@@ -143,8 +152,8 @@ const CanvasImpl = /*#__PURE__*/React__namespace.forwardRef(function Canvas({
|
|
|
143
152
|
// Create a known catalogue of Threejs-native elements
|
|
144
153
|
// This will include the entire THREE namespace by default, users can extend
|
|
145
154
|
// their own elements by using the createRoot API instead
|
|
146
|
-
React__namespace.useMemo(() =>
|
|
147
|
-
const Bridge =
|
|
155
|
+
React__namespace.useMemo(() => loop.extend(THREE__namespace), []);
|
|
156
|
+
const Bridge = loop.useBridge();
|
|
148
157
|
const [containerRef, containerRect] = useMeasure__default["default"]({
|
|
149
158
|
scroll: true,
|
|
150
159
|
debounce: {
|
|
@@ -155,72 +164,71 @@ const CanvasImpl = /*#__PURE__*/React__namespace.forwardRef(function Canvas({
|
|
|
155
164
|
});
|
|
156
165
|
const canvasRef = React__namespace.useRef(null);
|
|
157
166
|
const divRef = React__namespace.useRef(null);
|
|
158
|
-
const [canvas, setCanvas] = React__namespace.useState(null);
|
|
159
167
|
React__namespace.useImperativeHandle(forwardedRef, () => canvasRef.current);
|
|
160
|
-
const handlePointerMissed =
|
|
168
|
+
const handlePointerMissed = loop.useMutableCallback(onPointerMissed);
|
|
161
169
|
const [block, setBlock] = React__namespace.useState(false);
|
|
162
|
-
const [error, setError] = React__namespace.useState(false);
|
|
163
|
-
|
|
164
|
-
if (block) throw block; // Throw exception outwards if anything within canvas throws
|
|
170
|
+
const [error, setError] = React__namespace.useState(false);
|
|
165
171
|
|
|
172
|
+
// Suspend this component if block is a promise (2nd run)
|
|
173
|
+
if (block) throw block;
|
|
174
|
+
// Throw exception outwards if anything within canvas throws
|
|
166
175
|
if (error) throw error;
|
|
167
176
|
const root = React__namespace.useRef(null);
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
if (
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
index.useIsomorphicLayoutEffect(() => {
|
|
217
|
-
setCanvas(canvasRef.current);
|
|
218
|
-
}, []);
|
|
177
|
+
loop.useIsomorphicLayoutEffect(() => {
|
|
178
|
+
const canvas = canvasRef.current;
|
|
179
|
+
if (containerRect.width > 0 && containerRect.height > 0 && canvas) {
|
|
180
|
+
if (!root.current) root.current = loop.createRoot(canvas);
|
|
181
|
+
root.current.configure({
|
|
182
|
+
gl,
|
|
183
|
+
scene,
|
|
184
|
+
events,
|
|
185
|
+
shadows,
|
|
186
|
+
linear,
|
|
187
|
+
flat,
|
|
188
|
+
legacy,
|
|
189
|
+
orthographic,
|
|
190
|
+
frameloop,
|
|
191
|
+
dpr,
|
|
192
|
+
performance,
|
|
193
|
+
raycaster,
|
|
194
|
+
camera,
|
|
195
|
+
size: containerRect,
|
|
196
|
+
// Pass mutable reference to onPointerMissed so it's free to update
|
|
197
|
+
onPointerMissed: (...args) => handlePointerMissed.current == null ? void 0 : handlePointerMissed.current(...args),
|
|
198
|
+
onCreated: state => {
|
|
199
|
+
// Connect to event source
|
|
200
|
+
state.events.connect == null ? void 0 : state.events.connect(eventSource ? loop.isRef(eventSource) ? eventSource.current : eventSource : divRef.current);
|
|
201
|
+
// Set up compute function
|
|
202
|
+
if (eventPrefix) {
|
|
203
|
+
state.setEvents({
|
|
204
|
+
compute: (event, state) => {
|
|
205
|
+
const x = event[eventPrefix + 'X'];
|
|
206
|
+
const y = event[eventPrefix + 'Y'];
|
|
207
|
+
state.pointer.set(x / state.size.width * 2 - 1, -(y / state.size.height) * 2 + 1);
|
|
208
|
+
state.raycaster.setFromCamera(state.pointer, state.camera);
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
// Call onCreated callback
|
|
213
|
+
onCreated == null ? void 0 : onCreated(state);
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
root.current.render( /*#__PURE__*/React__namespace.createElement(Bridge, null, /*#__PURE__*/React__namespace.createElement(loop.ErrorBoundary, {
|
|
217
|
+
set: setError
|
|
218
|
+
}, /*#__PURE__*/React__namespace.createElement(React__namespace.Suspense, {
|
|
219
|
+
fallback: /*#__PURE__*/React__namespace.createElement(loop.Block, {
|
|
220
|
+
set: setBlock
|
|
221
|
+
})
|
|
222
|
+
}, children))));
|
|
223
|
+
}
|
|
224
|
+
});
|
|
219
225
|
React__namespace.useEffect(() => {
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
226
|
+
const canvas = canvasRef.current;
|
|
227
|
+
if (canvas) return () => loop.unmountComponentAtNode(canvas);
|
|
228
|
+
}, []);
|
|
223
229
|
|
|
230
|
+
// When the event source is not this div, we need to set pointer-events to none
|
|
231
|
+
// Or else the canvas will block events from reaching the event source
|
|
224
232
|
const pointerEvents = eventSource ? 'none' : 'auto';
|
|
225
233
|
return /*#__PURE__*/React__namespace.createElement("div", _extends({
|
|
226
234
|
ref: divRef,
|
|
@@ -245,44 +253,47 @@ const CanvasImpl = /*#__PURE__*/React__namespace.forwardRef(function Canvas({
|
|
|
245
253
|
}
|
|
246
254
|
}, fallback)));
|
|
247
255
|
});
|
|
248
|
-
/**
|
|
249
|
-
* A DOM canvas which accepts threejs elements as children.
|
|
250
|
-
* @see https://docs.pmnd.rs/react-three-fiber/api/canvas
|
|
251
|
-
*/
|
|
252
256
|
|
|
257
|
+
/**
|
|
258
|
+
* A DOM canvas which accepts threejs elements as children.
|
|
259
|
+
* @see https://docs.pmnd.rs/react-three-fiber/api/canvas
|
|
260
|
+
*/
|
|
253
261
|
const Canvas = /*#__PURE__*/React__namespace.forwardRef(function CanvasWrapper(props, ref) {
|
|
254
262
|
return /*#__PURE__*/React__namespace.createElement(itsFine.FiberProvider, null, /*#__PURE__*/React__namespace.createElement(CanvasImpl, _extends({}, props, {
|
|
255
263
|
ref: ref
|
|
256
264
|
})));
|
|
257
265
|
});
|
|
258
266
|
|
|
259
|
-
exports.FixedStage =
|
|
260
|
-
exports.
|
|
261
|
-
exports.
|
|
262
|
-
exports.
|
|
263
|
-
exports.
|
|
264
|
-
exports.
|
|
265
|
-
exports.
|
|
266
|
-
exports.
|
|
267
|
-
exports.
|
|
268
|
-
exports.
|
|
269
|
-
exports.
|
|
270
|
-
exports.
|
|
271
|
-
exports.
|
|
272
|
-
exports.
|
|
273
|
-
exports.
|
|
274
|
-
exports.
|
|
275
|
-
exports.
|
|
276
|
-
exports.
|
|
277
|
-
exports.
|
|
278
|
-
exports.
|
|
279
|
-
exports.
|
|
280
|
-
exports.
|
|
281
|
-
exports.
|
|
282
|
-
exports.
|
|
283
|
-
exports.
|
|
284
|
-
exports.
|
|
285
|
-
exports.
|
|
286
|
-
exports.
|
|
267
|
+
exports.FixedStage = loop.FixedStage;
|
|
268
|
+
exports.ReactThreeFiber = loop.threeTypes;
|
|
269
|
+
exports.Stage = loop.Stage;
|
|
270
|
+
exports.Stages = loop.Stages;
|
|
271
|
+
exports._roots = loop._roots;
|
|
272
|
+
exports.act = loop.act;
|
|
273
|
+
exports.addAfterEffect = loop.addAfterEffect;
|
|
274
|
+
exports.addEffect = loop.addEffect;
|
|
275
|
+
exports.addTail = loop.addTail;
|
|
276
|
+
exports.advance = loop.advance;
|
|
277
|
+
exports.applyProps = loop.applyProps;
|
|
278
|
+
exports.buildGraph = loop.buildGraph;
|
|
279
|
+
exports.context = loop.context;
|
|
280
|
+
exports.createEvents = loop.createEvents;
|
|
281
|
+
exports.createPortal = loop.createPortal;
|
|
282
|
+
exports.createRoot = loop.createRoot;
|
|
283
|
+
exports.dispose = loop.dispose;
|
|
284
|
+
exports.extend = loop.extend;
|
|
285
|
+
exports.flushGlobalEffects = loop.flushGlobalEffects;
|
|
286
|
+
exports.getRootState = loop.getRootState;
|
|
287
|
+
exports.invalidate = loop.invalidate;
|
|
288
|
+
exports.reconciler = loop.reconciler;
|
|
289
|
+
exports.render = loop.render;
|
|
290
|
+
exports.unmountComponentAtNode = loop.unmountComponentAtNode;
|
|
291
|
+
exports.useFrame = loop.useFrame;
|
|
292
|
+
exports.useGraph = loop.useGraph;
|
|
293
|
+
exports.useInstanceHandle = loop.useInstanceHandle;
|
|
294
|
+
exports.useLoader = loop.useLoader;
|
|
295
|
+
exports.useStore = loop.useStore;
|
|
296
|
+
exports.useThree = loop.useThree;
|
|
297
|
+
exports.useUpdate = loop.useUpdate;
|
|
287
298
|
exports.Canvas = Canvas;
|
|
288
299
|
exports.events = createPointerEvents;
|