@react-three/fiber 8.14.6 → 8.15.0

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.
@@ -374,12 +374,12 @@ function createRenderer(_roots, _getEventPriority) {
374
374
  }
375
375
 
376
376
  var _window$document, _window$navigator;
377
- /**
378
- * Returns `true` with correct TS type inference if an object has a configurable color space (since r152).
377
+ /**
378
+ * Returns `true` with correct TS type inference if an object has a configurable color space (since r152).
379
379
  */
380
380
  const hasColorSpace = object => 'colorSpace' in object || 'outputColorSpace' in object;
381
- /**
382
- * The current THREE.ColorManagement instance, if present.
381
+ /**
382
+ * The current THREE.ColorManagement instance, if present.
383
383
  */
384
384
  const getColorManagement = () => {
385
385
  var _ColorManagement;
@@ -388,14 +388,14 @@ const getColorManagement = () => {
388
388
  const isOrthographicCamera = def => def && def.isOrthographicCamera;
389
389
  const isRef = obj => obj && obj.hasOwnProperty('current');
390
390
 
391
- /**
392
- * An SSR-friendly useLayoutEffect.
393
- *
394
- * React currently throws a warning when using useLayoutEffect on the server.
395
- * To get around it, we can conditionally useEffect on the server (no-op) and
396
- * useLayoutEffect elsewhere.
397
- *
398
- * @see https://github.com/facebook/react/issues/14927
391
+ /**
392
+ * An SSR-friendly useLayoutEffect.
393
+ *
394
+ * React currently throws a warning when using useLayoutEffect on the server.
395
+ * To get around it, we can conditionally useEffect on the server (no-op) and
396
+ * useLayoutEffect elsewhere.
397
+ *
398
+ * @see https://github.com/facebook/react/issues/14927
399
399
  */
400
400
  const useIsomorphicLayoutEffect = typeof window !== 'undefined' && ((_window$document = window.document) != null && _window$document.createElement || ((_window$navigator = window.navigator) == null ? void 0 : _window$navigator.product) === 'ReactNative') ? React__namespace.useLayoutEffect : React__namespace.useEffect;
401
401
  function useMutableCallback(fn) {
@@ -440,8 +440,8 @@ function calculateDpr(dpr) {
440
440
  return Array.isArray(dpr) ? Math.min(Math.max(dpr[0], target), dpr[1]) : dpr;
441
441
  }
442
442
 
443
- /**
444
- * Returns instance root state
443
+ /**
444
+ * Returns instance root state
445
445
  */
446
446
  const getRootState = obj => {
447
447
  var _r3f;
@@ -497,7 +497,9 @@ const is = {
497
497
  }
498
498
  };
499
499
 
500
- // Collects nodes and materials from a THREE.Object3D
500
+ /**
501
+ * Collects nodes and materials from a THREE.Object3D.
502
+ */
501
503
  function buildGraph(object) {
502
504
  const data = {
503
505
  nodes: {},
@@ -836,9 +838,9 @@ function getEventPriority() {
836
838
  }
837
839
  }
838
840
 
839
- /**
840
- * Release pointer captures.
841
- * This is called by releasePointerCapture in the API, and when an object is removed.
841
+ /**
842
+ * Release pointer captures.
843
+ * This is called by releasePointerCapture in the API, and when an object is removed.
842
844
  */
843
845
  function releaseInternalPointerCapture(capturedMap, obj, captures, pointerId) {
844
846
  const captureData = captures.get(obj);
@@ -1173,19 +1175,19 @@ function createEvents(store) {
1173
1175
  // Check presence of handlers
1174
1176
  if (!(instance != null && instance.eventCount)) return;
1175
1177
 
1176
- /*
1177
- MAYBE TODO, DELETE IF NOT:
1178
- Check if the object is captured, captured events should not have intersects running in parallel
1179
- But wouldn't it be better to just replace capturedMap with a single entry?
1180
- Also, are we OK with straight up making picking up multiple objects impossible?
1181
-
1182
- const pointerId = (data as ThreeEvent<PointerEvent>).pointerId
1183
- if (pointerId !== undefined) {
1184
- const capturedMeshSet = internal.capturedMap.get(pointerId)
1185
- if (capturedMeshSet) {
1186
- const captured = capturedMeshSet.get(eventObject)
1187
- if (captured && captured.localState.stopped) return
1188
- }
1178
+ /*
1179
+ MAYBE TODO, DELETE IF NOT:
1180
+ Check if the object is captured, captured events should not have intersects running in parallel
1181
+ But wouldn't it be better to just replace capturedMap with a single entry?
1182
+ Also, are we OK with straight up making picking up multiple objects impossible?
1183
+
1184
+ const pointerId = (data as ThreeEvent<PointerEvent>).pointerId
1185
+ if (pointerId !== undefined) {
1186
+ const capturedMeshSet = internal.capturedMap.get(pointerId)
1187
+ if (capturedMeshSet) {
1188
+ const captured = capturedMeshSet.get(eventObject)
1189
+ if (captured && captured.localState.stopped) return
1190
+ }
1189
1191
  }*/
1190
1192
 
1191
1193
  if (isPointerMove) {
@@ -1491,21 +1493,21 @@ let globalEffects = new Set();
1491
1493
  let globalAfterEffects = new Set();
1492
1494
  let globalTailEffects = new Set();
1493
1495
 
1494
- /**
1495
- * Adds a global render callback which is called each frame.
1496
- * @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#addEffect
1496
+ /**
1497
+ * Adds a global render callback which is called each frame.
1498
+ * @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#addEffect
1497
1499
  */
1498
1500
  const addEffect = callback => createSubs(callback, globalEffects);
1499
1501
 
1500
- /**
1501
- * Adds a global after-render callback which is called each frame.
1502
- * @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#addAfterEffect
1502
+ /**
1503
+ * Adds a global after-render callback which is called each frame.
1504
+ * @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#addAfterEffect
1503
1505
  */
1504
1506
  const addAfterEffect = callback => createSubs(callback, globalAfterEffects);
1505
1507
 
1506
- /**
1507
- * Adds a global callback which is called when rendering stops.
1508
- * @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#addTail
1508
+ /**
1509
+ * Adds a global callback which is called when rendering stops.
1510
+ * @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#addTail
1509
1511
  */
1510
1512
  const addTail = callback => createSubs(callback, globalTailEffects);
1511
1513
  function run(effects, timestamp) {
@@ -1604,24 +1606,24 @@ function createLoop(roots) {
1604
1606
  }
1605
1607
  return {
1606
1608
  loop,
1607
- /**
1608
- * Invalidates the view, requesting a frame to be rendered. Will globally invalidate unless passed a root's state.
1609
- * @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#invalidate
1609
+ /**
1610
+ * Invalidates the view, requesting a frame to be rendered. Will globally invalidate unless passed a root's state.
1611
+ * @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#invalidate
1610
1612
  */
1611
1613
  invalidate,
1612
- /**
1613
- * Advances the frameloop and runs render effects, useful for when manually rendering via `frameloop="never"`.
1614
- * @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#advance
1614
+ /**
1615
+ * Advances the frameloop and runs render effects, useful for when manually rendering via `frameloop="never"`.
1616
+ * @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#advance
1615
1617
  */
1616
1618
  advance
1617
1619
  };
1618
1620
  }
1619
1621
 
1620
- /**
1621
- * Exposes an object's {@link LocalState}.
1622
- * @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#useInstanceHandle
1623
- *
1624
- * **Note**: this is an escape hatch to react-internal fields. Expect this to change significantly between versions.
1622
+ /**
1623
+ * Exposes an object's {@link LocalState}.
1624
+ * @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#useInstanceHandle
1625
+ *
1626
+ * **Note**: this is an escape hatch to react-internal fields. Expect this to change significantly between versions.
1625
1627
  */
1626
1628
  function useInstanceHandle(ref) {
1627
1629
  const instance = React__namespace.useRef(null);
@@ -1634,18 +1636,18 @@ function useStore() {
1634
1636
  return store;
1635
1637
  }
1636
1638
 
1637
- /**
1638
- * Accesses R3F's internal state, containing renderer, canvas, scene, etc.
1639
- * @see https://docs.pmnd.rs/react-three-fiber/api/hooks#usethree
1639
+ /**
1640
+ * Accesses R3F's internal state, containing renderer, canvas, scene, etc.
1641
+ * @see https://docs.pmnd.rs/react-three-fiber/api/hooks#usethree
1640
1642
  */
1641
1643
  function useThree(selector = state => state, equalityFn) {
1642
1644
  return useStore()(selector, equalityFn);
1643
1645
  }
1644
1646
 
1645
- /**
1646
- * Executes a callback before render in a shared frame loop.
1647
- * Can order effects with render priority or manually render with a positive priority.
1648
- * @see https://docs.pmnd.rs/react-three-fiber/api/hooks#useframe
1647
+ /**
1648
+ * Executes a callback before render in a shared frame loop.
1649
+ * Can order effects with render priority or manually render with a positive priority.
1650
+ * @see https://docs.pmnd.rs/react-three-fiber/api/hooks#useframe
1649
1651
  */
1650
1652
  function useFrame(callback, renderPriority = 0) {
1651
1653
  const store = useStore();
@@ -1657,9 +1659,9 @@ function useFrame(callback, renderPriority = 0) {
1657
1659
  return null;
1658
1660
  }
1659
1661
 
1660
- /**
1661
- * Returns a node graph of an object with named nodes & materials.
1662
- * @see https://docs.pmnd.rs/react-three-fiber/api/hooks#usegraph
1662
+ /**
1663
+ * Returns a node graph of an object with named nodes & materials.
1664
+ * @see https://docs.pmnd.rs/react-three-fiber/api/hooks#usegraph
1663
1665
  */
1664
1666
  function useGraph(object) {
1665
1667
  return React__namespace.useMemo(() => buildGraph(object), [object]);
@@ -1682,11 +1684,11 @@ function loadingFn(extensions, onProgress) {
1682
1684
  };
1683
1685
  }
1684
1686
 
1685
- /**
1686
- * Synchronously loads and caches assets with a three loader.
1687
- *
1688
- * Note: this hook's caller must be wrapped with `React.Suspense`
1689
- * @see https://docs.pmnd.rs/react-three-fiber/api/hooks#useloader
1687
+ /**
1688
+ * Synchronously loads and caches assets with a three loader.
1689
+ *
1690
+ * Note: this hook's caller must be wrapped with `React.Suspense`
1691
+ * @see https://docs.pmnd.rs/react-three-fiber/api/hooks#useloader
1690
1692
  */
1691
1693
  function useLoader(Proto, input, extensions, onProgress) {
1692
1694
  // Use suspense to load async assets
@@ -1698,16 +1700,16 @@ function useLoader(Proto, input, extensions, onProgress) {
1698
1700
  return Array.isArray(input) ? results : results[0];
1699
1701
  }
1700
1702
 
1701
- /**
1702
- * Preloads an asset into cache as a side-effect.
1703
+ /**
1704
+ * Preloads an asset into cache as a side-effect.
1703
1705
  */
1704
1706
  useLoader.preload = function (Proto, input, extensions) {
1705
1707
  const keys = Array.isArray(input) ? input : [input];
1706
1708
  return suspendReact.preload(loadingFn(extensions), [Proto, ...keys]);
1707
1709
  };
1708
1710
 
1709
- /**
1710
- * Removes a loaded asset from cache.
1711
+ /**
1712
+ * Removes a loaded asset from cache.
1711
1713
  */
1712
1714
  useLoader.clear = function (Proto, input) {
1713
1715
  const keys = Array.isArray(input) ? input : [input];
@@ -2082,10 +2084,10 @@ function Portal({
2082
2084
  children,
2083
2085
  container
2084
2086
  }) {
2085
- /** This has to be a component because it would not be able to call useThree/useStore otherwise since
2086
- * if this is our environment, then we are not in r3f's renderer but in react-dom, it would trigger
2087
- * the "R3F hooks can only be used within the Canvas component!" warning:
2088
- * <Canvas>
2087
+ /** This has to be a component because it would not be able to call useThree/useStore otherwise since
2088
+ * if this is our environment, then we are not in r3f's renderer but in react-dom, it would trigger
2089
+ * the "R3F hooks can only be used within the Canvas component!" warning:
2090
+ * <Canvas>
2089
2091
  * {createPortal(...)} */
2090
2092
  const {
2091
2093
  events,
@@ -2211,6 +2213,7 @@ exports.addEffect = addEffect;
2211
2213
  exports.addTail = addTail;
2212
2214
  exports.advance = advance;
2213
2215
  exports.applyProps = applyProps;
2216
+ exports.buildGraph = buildGraph;
2214
2217
  exports.context = context;
2215
2218
  exports.createEvents = createEvents;
2216
2219
  exports.createPortal = createPortal;
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var index = require('./index-886811f8.cjs.dev.js');
5
+ var index = require('./index-34a45f4c.cjs.dev.js');
6
6
  var _extends = require('@babel/runtime/helpers/extends');
7
7
  var React = require('react');
8
8
  var THREE = require('three');
@@ -251,9 +251,9 @@ const CanvasImpl = /*#__PURE__*/React__namespace.forwardRef(function Canvas({
251
251
  }, fallback)));
252
252
  });
253
253
 
254
- /**
255
- * A DOM canvas which accepts threejs elements as children.
256
- * @see https://docs.pmnd.rs/react-three-fiber/api/canvas
254
+ /**
255
+ * A DOM canvas which accepts threejs elements as children.
256
+ * @see https://docs.pmnd.rs/react-three-fiber/api/canvas
257
257
  */
258
258
  const Canvas = /*#__PURE__*/React__namespace.forwardRef(function CanvasWrapper(props, ref) {
259
259
  return /*#__PURE__*/React__namespace.createElement(itsFine.FiberProvider, null, /*#__PURE__*/React__namespace.createElement(CanvasImpl, _extends({}, props, {
@@ -269,6 +269,7 @@ exports.addEffect = index.addEffect;
269
269
  exports.addTail = index.addTail;
270
270
  exports.advance = index.advance;
271
271
  exports.applyProps = index.applyProps;
272
+ exports.buildGraph = index.buildGraph;
272
273
  exports.context = index.context;
273
274
  exports.createEvents = index.createEvents;
274
275
  exports.createPortal = index.createPortal;
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var index = require('./index-0ed4bbca.cjs.prod.js');
5
+ var index = require('./index-f4d4539a.cjs.prod.js');
6
6
  var _extends = require('@babel/runtime/helpers/extends');
7
7
  var React = require('react');
8
8
  var THREE = require('three');
@@ -251,9 +251,9 @@ const CanvasImpl = /*#__PURE__*/React__namespace.forwardRef(function Canvas({
251
251
  }, fallback)));
252
252
  });
253
253
 
254
- /**
255
- * A DOM canvas which accepts threejs elements as children.
256
- * @see https://docs.pmnd.rs/react-three-fiber/api/canvas
254
+ /**
255
+ * A DOM canvas which accepts threejs elements as children.
256
+ * @see https://docs.pmnd.rs/react-three-fiber/api/canvas
257
257
  */
258
258
  const Canvas = /*#__PURE__*/React__namespace.forwardRef(function CanvasWrapper(props, ref) {
259
259
  return /*#__PURE__*/React__namespace.createElement(itsFine.FiberProvider, null, /*#__PURE__*/React__namespace.createElement(CanvasImpl, _extends({}, props, {
@@ -269,6 +269,7 @@ exports.addEffect = index.addEffect;
269
269
  exports.addTail = index.addTail;
270
270
  exports.advance = index.advance;
271
271
  exports.applyProps = index.applyProps;
272
+ exports.buildGraph = index.buildGraph;
272
273
  exports.context = index.context;
273
274
  exports.createEvents = index.createEvents;
274
275
  exports.createPortal = index.createPortal;
@@ -1,5 +1,5 @@
1
- import { c as createEvents, e as extend, u as useMutableCallback, a as useIsomorphicLayoutEffect, b as createRoot, i as isRef, E as ErrorBoundary, B as Block, d as unmountComponentAtNode } from './index-563322db.esm.js';
2
- export { t as ReactThreeFiber, w as _roots, v as act, o as addAfterEffect, n as addEffect, p as addTail, m as advance, j as applyProps, f as context, c as createEvents, g as createPortal, b as createRoot, k as dispose, e as extend, q as flushGlobalEffects, s as getRootState, l as invalidate, h as reconciler, r as render, d as unmountComponentAtNode, A as useFrame, C as useGraph, x as useInstanceHandle, D as useLoader, y as useStore, z as useThree } from './index-563322db.esm.js';
1
+ import { c as createEvents, e as extend, u as useMutableCallback, a as useIsomorphicLayoutEffect, b as createRoot, i as isRef, E as ErrorBoundary, B as Block, d as unmountComponentAtNode } from './index-5918012a.esm.js';
2
+ export { t as ReactThreeFiber, x as _roots, v as act, o as addAfterEffect, n as addEffect, p as addTail, m as advance, j as applyProps, w as buildGraph, f as context, c as createEvents, g as createPortal, b as createRoot, k as dispose, e as extend, q as flushGlobalEffects, s as getRootState, l as invalidate, h as reconciler, r as render, d as unmountComponentAtNode, C as useFrame, D as useGraph, y as useInstanceHandle, F as useLoader, z as useStore, A as useThree } from './index-5918012a.esm.js';
3
3
  import _extends from '@babel/runtime/helpers/esm/extends';
4
4
  import * as React from 'react';
5
5
  import * as THREE from 'three';
@@ -224,9 +224,9 @@ const CanvasImpl = /*#__PURE__*/React.forwardRef(function Canvas({
224
224
  }, fallback)));
225
225
  });
226
226
 
227
- /**
228
- * A DOM canvas which accepts threejs elements as children.
229
- * @see https://docs.pmnd.rs/react-three-fiber/api/canvas
227
+ /**
228
+ * A DOM canvas which accepts threejs elements as children.
229
+ * @see https://docs.pmnd.rs/react-three-fiber/api/canvas
230
230
  */
231
231
  const Canvas = /*#__PURE__*/React.forwardRef(function CanvasWrapper(props, ref) {
232
232
  return /*#__PURE__*/React.createElement(FiberProvider, null, /*#__PURE__*/React.createElement(CanvasImpl, _extends({}, props, {
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var index = require('../../dist/index-886811f8.cjs.dev.js');
5
+ var index = require('../../dist/index-34a45f4c.cjs.dev.js');
6
6
  var _extends = require('@babel/runtime/helpers/extends');
7
7
  var React = require('react');
8
8
  var THREE = require('three');
@@ -10,7 +10,9 @@ var reactNative = require('react-native');
10
10
  var expoGl = require('expo-gl');
11
11
  var itsFine = require('its-fine');
12
12
  var expoAsset = require('expo-asset');
13
- var expoFileSystem = require('expo-file-system');
13
+ var fs = require('expo-file-system');
14
+ var base64Js = require('base64-js');
15
+ var buffer = require('buffer');
14
16
  require('react-reconciler/constants');
15
17
  require('zustand');
16
18
  require('react-reconciler');
@@ -37,6 +39,7 @@ function _interopNamespace(e) {
37
39
 
38
40
  var React__namespace = /*#__PURE__*/_interopNamespace(React);
39
41
  var THREE__namespace = /*#__PURE__*/_interopNamespace(THREE);
42
+ var fs__namespace = /*#__PURE__*/_interopNamespace(fs);
40
43
 
41
44
  /** Default R3F event manager for react-native */
42
45
  function createTouchEvents(store) {
@@ -120,9 +123,9 @@ function createTouchEvents(store) {
120
123
  };
121
124
  }
122
125
 
123
- /**
124
- * A native canvas which accepts threejs elements as children.
125
- * @see https://docs.pmnd.rs/react-three-fiber/api/canvas
126
+ /**
127
+ * A native canvas which accepts threejs elements as children.
128
+ * @see https://docs.pmnd.rs/react-three-fiber/api/canvas
126
129
  */
127
130
  const CanvasImpl = /*#__PURE__*/React__namespace.forwardRef(({
128
131
  children,
@@ -269,9 +272,9 @@ const CanvasImpl = /*#__PURE__*/React__namespace.forwardRef(({
269
272
  }));
270
273
  });
271
274
 
272
- /**
273
- * A native canvas which accepts threejs elements as children.
274
- * @see https://docs.pmnd.rs/react-three-fiber/api/canvas
275
+ /**
276
+ * A native canvas which accepts threejs elements as children.
277
+ * @see https://docs.pmnd.rs/react-three-fiber/api/canvas
275
278
  */
276
279
  const Canvas = /*#__PURE__*/React__namespace.forwardRef(function CanvasWrapper(props, ref) {
277
280
  return /*#__PURE__*/React__namespace.createElement(itsFine.FiberProvider, null, /*#__PURE__*/React__namespace.createElement(CanvasImpl, _extends({}, props, {
@@ -279,41 +282,130 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(function CanvasWrapper(p
279
282
  })));
280
283
  });
281
284
 
282
- async function getAsset(input) {
283
- const asset = typeof input === 'string' ? expoAsset.Asset.fromURI(input) : expoAsset.Asset.fromModule(input);
284
- await asset.downloadAsync();
285
- let localUri = asset.localUri || asset.uri;
286
-
287
- // Unpack assets in Android Release Mode
288
- if (!localUri.includes('://')) {
289
- localUri = `${expoFileSystem.cacheDirectory}ExponentAsset-${asset.hash}.${asset.type}`;
290
- await expoFileSystem.copyAsync({
291
- from: localUri,
292
- to: localUri
285
+ function polyfills() {
286
+ function uuidv4() {
287
+ return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c => {
288
+ const r = Math.random() * 16 | 0,
289
+ v = c == 'x' ? r : r & 0x3 | 0x8;
290
+ return v.toString(16);
293
291
  });
294
292
  }
295
- return localUri;
296
- }
297
- function _polyfills() {
293
+
294
+ // Patch Blob for ArrayBuffer if unsupported
295
+ try {
296
+ new Blob([new ArrayBuffer(4)]);
297
+ } catch (_) {
298
+ const BlobManager = require('react-native/Libraries/Blob/BlobManager.js');
299
+ BlobManager.createFromParts = function createFromParts(parts, options) {
300
+ const blobId = uuidv4();
301
+ const items = parts.map(part => {
302
+ if (part instanceof ArrayBuffer || ArrayBuffer.isView(part)) {
303
+ const data = base64Js.fromByteArray(new Uint8Array(part));
304
+ return {
305
+ data,
306
+ type: 'string'
307
+ };
308
+ } else if (part instanceof Blob) {
309
+ return {
310
+ data: part.data,
311
+ type: 'blob'
312
+ };
313
+ } else {
314
+ return {
315
+ data: String(part),
316
+ type: 'string'
317
+ };
318
+ }
319
+ });
320
+ const size = items.reduce((acc, curr) => {
321
+ if (curr.type === 'string') {
322
+ return acc + global.unescape(encodeURI(curr.data)).length;
323
+ } else {
324
+ return acc + curr.data.size;
325
+ }
326
+ }, 0);
327
+ reactNative.NativeModules.BlobModule.createFromParts(items, blobId);
328
+ return BlobManager.createFromOptions({
329
+ blobId,
330
+ offset: 0,
331
+ size,
332
+ type: options ? options.type : '',
333
+ lastModified: options ? options.lastModified : Date.now()
334
+ });
335
+ };
336
+ }
337
+ async function getAsset(input) {
338
+ if (typeof input === 'string') {
339
+ // Don't process storage
340
+ if (input.startsWith('file:')) return input;
341
+
342
+ // Unpack Blobs from react-native BlobManager
343
+ if (input.startsWith('blob:')) {
344
+ const blob = await new Promise((res, rej) => {
345
+ const xhr = new XMLHttpRequest();
346
+ xhr.open('GET', input);
347
+ xhr.responseType = 'blob';
348
+ xhr.onload = () => res(xhr.response);
349
+ xhr.onerror = rej;
350
+ xhr.send();
351
+ });
352
+ const data = await new Promise((res, rej) => {
353
+ const reader = new FileReader();
354
+ reader.onload = () => res(reader.result);
355
+ reader.onerror = rej;
356
+ reader.readAsText(blob);
357
+ });
358
+ input = `data:${blob.type};base64,${data}`;
359
+ }
360
+
361
+ // Create safe URI for JSI
362
+ if (input.startsWith('data:')) {
363
+ const [header, data] = input.split(',');
364
+ const [, type] = header.split('/');
365
+ const uri = fs__namespace.cacheDirectory + uuidv4() + `.${type}`;
366
+ await fs__namespace.writeAsStringAsync(uri, data, {
367
+ encoding: fs__namespace.EncodingType.Base64
368
+ });
369
+ return uri;
370
+ }
371
+ }
372
+
373
+ // Download bundler module or external URL
374
+ const asset = await expoAsset.Asset.fromModule(input).downloadAsync();
375
+ let uri = asset.localUri || asset.uri;
376
+
377
+ // Unpack assets in Android Release Mode
378
+ if (!uri.includes(':')) {
379
+ const file = `${fs__namespace.cacheDirectory}ExponentAsset-${asset.hash}.${asset.type}`;
380
+ await fs__namespace.copyAsync({
381
+ from: uri,
382
+ to: file
383
+ });
384
+ uri = file;
385
+ }
386
+ return uri;
387
+ }
388
+
298
389
  // Don't pre-process urls, let expo-asset generate an absolute URL
299
390
  const extractUrlBase = THREE__namespace.LoaderUtils.extractUrlBase.bind(THREE__namespace.LoaderUtils);
300
391
  THREE__namespace.LoaderUtils.extractUrlBase = url => typeof url === 'string' ? extractUrlBase(url) : './';
301
392
 
302
393
  // There's no Image in native, so create a data texture instead
303
394
  THREE__namespace.TextureLoader.prototype.load = function load(url, onLoad, onProgress, onError) {
304
- if (this.path) url = this.path + url;
395
+ if (this.path && typeof url === 'string') url = this.path + url;
396
+ this.manager.itemStart(url);
305
397
  const texture = new THREE__namespace.Texture();
306
- getAsset(url).then(async localUri => {
398
+ getAsset(url).then(async uri => {
307
399
  const {
308
400
  width,
309
401
  height
310
- } = await new Promise((res, rej) => reactNative.Image.getSize(localUri, (width, height) => res({
402
+ } = await new Promise((res, rej) => reactNative.Image.getSize(uri, (width, height) => res({
311
403
  width,
312
404
  height
313
405
  }), rej));
314
406
  texture.image = {
315
407
  data: {
316
- localUri
408
+ localUri: uri
317
409
  },
318
410
  width,
319
411
  height
@@ -326,52 +418,35 @@ function _polyfills() {
326
418
  // @ts-ignore
327
419
  texture.isDataTexture = true;
328
420
  onLoad == null ? void 0 : onLoad(texture);
329
- }).catch(onError);
421
+ }).catch(error => {
422
+ onError == null ? void 0 : onError(error);
423
+ this.manager.itemError(url);
424
+ }).finally(() => {
425
+ this.manager.itemEnd(url);
426
+ });
330
427
  return texture;
331
428
  };
332
429
 
333
430
  // Fetches assets via XMLHttpRequest
334
431
  THREE__namespace.FileLoader.prototype.load = function load(url, onLoad, onProgress, onError) {
335
- if (this.path) url = this.path + url;
336
- const request = new XMLHttpRequest();
337
- getAsset(url).then(localUri => {
338
- request.open('GET', localUri, true);
339
- request.addEventListener('load', event => {
340
- if (request.status === 200) {
341
- onLoad == null ? void 0 : onLoad(request.response);
342
- this.manager.itemEnd(url);
343
- } else {
344
- onError == null ? void 0 : onError(event);
345
- this.manager.itemError(url);
346
- this.manager.itemEnd(url);
347
- }
348
- }, false);
349
- request.addEventListener('progress', event => {
350
- onProgress == null ? void 0 : onProgress(event);
351
- }, false);
352
- request.addEventListener('error', event => {
353
- onError == null ? void 0 : onError(event);
354
- this.manager.itemError(url);
355
- this.manager.itemEnd(url);
356
- }, false);
357
- request.addEventListener('abort', event => {
358
- onError == null ? void 0 : onError(event);
359
- this.manager.itemError(url);
360
- this.manager.itemEnd(url);
361
- }, false);
362
- if (this.responseType) request.responseType = this.responseType;
363
- if (this.withCredentials) request.withCredentials = this.withCredentials;
364
- for (const header in this.requestHeader) {
365
- request.setRequestHeader(header, this.requestHeader[header]);
366
- }
367
- request.send(null);
368
- this.manager.itemStart(url);
369
- }).catch(onError);
370
- return request;
432
+ if (this.path && typeof url === 'string') url = this.path + url;
433
+ this.manager.itemStart(url);
434
+ getAsset(url).then(async uri => {
435
+ const base64 = await fs__namespace.readAsStringAsync(uri, {
436
+ encoding: fs__namespace.EncodingType.Base64
437
+ });
438
+ const data = buffer.Buffer.from(base64, 'base64');
439
+ onLoad == null ? void 0 : onLoad(data.buffer);
440
+ }).catch(error => {
441
+ onError == null ? void 0 : onError(error);
442
+ this.manager.itemError(url);
443
+ }).finally(() => {
444
+ this.manager.itemEnd(url);
445
+ });
371
446
  };
372
447
  }
373
448
 
374
- if (reactNative.Platform.OS !== 'web') _polyfills();
449
+ if (reactNative.Platform.OS !== 'web') polyfills();
375
450
 
376
451
  exports.ReactThreeFiber = index.threeTypes;
377
452
  exports._roots = index.roots;
@@ -381,6 +456,7 @@ exports.addEffect = index.addEffect;
381
456
  exports.addTail = index.addTail;
382
457
  exports.advance = index.advance;
383
458
  exports.applyProps = index.applyProps;
459
+ exports.buildGraph = index.buildGraph;
384
460
  exports.context = index.context;
385
461
  exports.createEvents = index.createEvents;
386
462
  exports.createPortal = index.createPortal;