@react-three/fiber 8.15.1 → 8.15.3

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 CHANGED
@@ -1,5 +1,17 @@
1
1
  # @react-three/fiber
2
2
 
3
+ ## 8.15.3
4
+
5
+ ### Patch Changes
6
+
7
+ - beab4344: fix(native): workaround Android content policy for Blob URI
8
+
9
+ ## 8.15.2
10
+
11
+ ### Patch Changes
12
+
13
+ - 086d3932: fix: size check and raycaster camera
14
+
3
15
  ## 8.15.1
4
16
 
5
17
  ### Patch Changes
@@ -1423,7 +1423,7 @@ const createStore = (invalidate, advance) => {
1423
1423
  } = rootState.getState();
1424
1424
 
1425
1425
  // Resize camera and renderer on changes to size and pixelratio
1426
- if (size !== oldSize || viewport.dpr !== oldDpr) {
1426
+ if (size.width !== oldSize.width || size.height !== oldSize.height || viewport.dpr !== oldDpr) {
1427
1427
  var _size$updateStyle;
1428
1428
  oldSize = size;
1429
1429
  oldDpr = viewport.dpr;
@@ -1713,8 +1713,23 @@ const createRendererInstance = (gl, canvas) => {
1713
1713
  });
1714
1714
  };
1715
1715
  function computeInitialSize(canvas, defaultSize) {
1716
- if (defaultSize) return defaultSize;
1717
- if (typeof HTMLCanvasElement !== 'undefined' && canvas instanceof HTMLCanvasElement && canvas.parentElement) {
1716
+ const defaultStyle = typeof HTMLCanvasElement !== 'undefined' && canvas instanceof HTMLCanvasElement;
1717
+ if (defaultSize) {
1718
+ const {
1719
+ width,
1720
+ height,
1721
+ top,
1722
+ left,
1723
+ updateStyle = defaultStyle
1724
+ } = defaultSize;
1725
+ return {
1726
+ width,
1727
+ height,
1728
+ top,
1729
+ left,
1730
+ updateStyle
1731
+ };
1732
+ } else if (typeof HTMLCanvasElement !== 'undefined' && canvas instanceof HTMLCanvasElement && canvas.parentElement) {
1718
1733
  const {
1719
1734
  width,
1720
1735
  height,
@@ -1725,14 +1740,16 @@ function computeInitialSize(canvas, defaultSize) {
1725
1740
  width,
1726
1741
  height,
1727
1742
  top,
1728
- left
1743
+ left,
1744
+ updateStyle: defaultStyle
1729
1745
  };
1730
1746
  } else if (typeof OffscreenCanvas !== 'undefined' && canvas instanceof OffscreenCanvas) {
1731
1747
  return {
1732
1748
  width: canvas.width,
1733
1749
  height: canvas.height,
1734
1750
  top: 0,
1735
- left: 0
1751
+ left: 0,
1752
+ updateStyle: defaultStyle
1736
1753
  };
1737
1754
  }
1738
1755
  return {
@@ -1835,6 +1852,10 @@ function createRoot(canvas) {
1835
1852
  state.set({
1836
1853
  camera
1837
1854
  });
1855
+
1856
+ // Configure raycaster
1857
+ // https://github.com/pmndrs/react-xr/issues/300
1858
+ raycaster.camera = camera;
1838
1859
  }
1839
1860
 
1840
1861
  // Set up scene (one time only!)
@@ -1450,7 +1450,7 @@ const createStore = (invalidate, advance) => {
1450
1450
  } = rootState.getState();
1451
1451
 
1452
1452
  // Resize camera and renderer on changes to size and pixelratio
1453
- if (size !== oldSize || viewport.dpr !== oldDpr) {
1453
+ if (size.width !== oldSize.width || size.height !== oldSize.height || viewport.dpr !== oldDpr) {
1454
1454
  var _size$updateStyle;
1455
1455
  oldSize = size;
1456
1456
  oldDpr = viewport.dpr;
@@ -1740,8 +1740,23 @@ const createRendererInstance = (gl, canvas) => {
1740
1740
  });
1741
1741
  };
1742
1742
  function computeInitialSize(canvas, defaultSize) {
1743
- if (defaultSize) return defaultSize;
1744
- if (typeof HTMLCanvasElement !== 'undefined' && canvas instanceof HTMLCanvasElement && canvas.parentElement) {
1743
+ const defaultStyle = typeof HTMLCanvasElement !== 'undefined' && canvas instanceof HTMLCanvasElement;
1744
+ if (defaultSize) {
1745
+ const {
1746
+ width,
1747
+ height,
1748
+ top,
1749
+ left,
1750
+ updateStyle = defaultStyle
1751
+ } = defaultSize;
1752
+ return {
1753
+ width,
1754
+ height,
1755
+ top,
1756
+ left,
1757
+ updateStyle
1758
+ };
1759
+ } else if (typeof HTMLCanvasElement !== 'undefined' && canvas instanceof HTMLCanvasElement && canvas.parentElement) {
1745
1760
  const {
1746
1761
  width,
1747
1762
  height,
@@ -1752,14 +1767,16 @@ function computeInitialSize(canvas, defaultSize) {
1752
1767
  width,
1753
1768
  height,
1754
1769
  top,
1755
- left
1770
+ left,
1771
+ updateStyle: defaultStyle
1756
1772
  };
1757
1773
  } else if (typeof OffscreenCanvas !== 'undefined' && canvas instanceof OffscreenCanvas) {
1758
1774
  return {
1759
1775
  width: canvas.width,
1760
1776
  height: canvas.height,
1761
1777
  top: 0,
1762
- left: 0
1778
+ left: 0,
1779
+ updateStyle: defaultStyle
1763
1780
  };
1764
1781
  }
1765
1782
  return {
@@ -1862,6 +1879,10 @@ function createRoot(canvas) {
1862
1879
  state.set({
1863
1880
  camera
1864
1881
  });
1882
+
1883
+ // Configure raycaster
1884
+ // https://github.com/pmndrs/react-xr/issues/300
1885
+ raycaster.camera = camera;
1865
1886
  }
1866
1887
 
1867
1888
  // Set up scene (one time only!)
@@ -1450,7 +1450,7 @@ const createStore = (invalidate, advance) => {
1450
1450
  } = rootState.getState();
1451
1451
 
1452
1452
  // Resize camera and renderer on changes to size and pixelratio
1453
- if (size !== oldSize || viewport.dpr !== oldDpr) {
1453
+ if (size.width !== oldSize.width || size.height !== oldSize.height || viewport.dpr !== oldDpr) {
1454
1454
  var _size$updateStyle;
1455
1455
  oldSize = size;
1456
1456
  oldDpr = viewport.dpr;
@@ -1740,8 +1740,23 @@ const createRendererInstance = (gl, canvas) => {
1740
1740
  });
1741
1741
  };
1742
1742
  function computeInitialSize(canvas, defaultSize) {
1743
- if (defaultSize) return defaultSize;
1744
- if (typeof HTMLCanvasElement !== 'undefined' && canvas instanceof HTMLCanvasElement && canvas.parentElement) {
1743
+ const defaultStyle = typeof HTMLCanvasElement !== 'undefined' && canvas instanceof HTMLCanvasElement;
1744
+ if (defaultSize) {
1745
+ const {
1746
+ width,
1747
+ height,
1748
+ top,
1749
+ left,
1750
+ updateStyle = defaultStyle
1751
+ } = defaultSize;
1752
+ return {
1753
+ width,
1754
+ height,
1755
+ top,
1756
+ left,
1757
+ updateStyle
1758
+ };
1759
+ } else if (typeof HTMLCanvasElement !== 'undefined' && canvas instanceof HTMLCanvasElement && canvas.parentElement) {
1745
1760
  const {
1746
1761
  width,
1747
1762
  height,
@@ -1752,14 +1767,16 @@ function computeInitialSize(canvas, defaultSize) {
1752
1767
  width,
1753
1768
  height,
1754
1769
  top,
1755
- left
1770
+ left,
1771
+ updateStyle: defaultStyle
1756
1772
  };
1757
1773
  } else if (typeof OffscreenCanvas !== 'undefined' && canvas instanceof OffscreenCanvas) {
1758
1774
  return {
1759
1775
  width: canvas.width,
1760
1776
  height: canvas.height,
1761
1777
  top: 0,
1762
- left: 0
1778
+ left: 0,
1779
+ updateStyle: defaultStyle
1763
1780
  };
1764
1781
  }
1765
1782
  return {
@@ -1862,6 +1879,10 @@ function createRoot(canvas) {
1862
1879
  state.set({
1863
1880
  camera
1864
1881
  });
1882
+
1883
+ // Configure raycaster
1884
+ // https://github.com/pmndrs/react-xr/issues/300
1885
+ raycaster.camera = camera;
1865
1886
  }
1866
1887
 
1867
1888
  // Set up scene (one time only!)
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var index = require('./index-34a45f4c.cjs.dev.js');
5
+ var index = require('./index-d26c5c57.cjs.dev.js');
6
6
  var _extends = require('@babel/runtime/helpers/extends');
7
7
  var React = require('react');
8
8
  var THREE = require('three');
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var index = require('./index-f4d4539a.cjs.prod.js');
5
+ var index = require('./index-e6d64601.cjs.prod.js');
6
6
  var _extends = require('@babel/runtime/helpers/extends');
7
7
  var React = require('react');
8
8
  var THREE = require('three');
@@ -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-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';
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-594193f5.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-594193f5.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';
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var index = require('../../dist/index-34a45f4c.cjs.dev.js');
5
+ var index = require('../../dist/index-d26c5c57.cjs.dev.js');
6
6
  var _extends = require('@babel/runtime/helpers/extends');
7
7
  var React = require('react');
8
8
  var THREE = require('three');
@@ -283,6 +283,7 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(function CanvasWrapper(p
283
283
  });
284
284
 
285
285
  function polyfills() {
286
+ // http://stackoverflow.com/questions/105034
286
287
  function uuidv4() {
287
288
  return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c => {
288
289
  const r = Math.random() * 16 | 0,
@@ -292,47 +293,80 @@ function polyfills() {
292
293
  }
293
294
 
294
295
  // 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
- };
296
+ // https://github.com/facebook/react-native/pull/39276
297
+ if (reactNative.Platform.OS !== 'web') {
298
+ try {
299
+ const blob = new Blob([new ArrayBuffer(4)]);
300
+ const url = URL.createObjectURL(blob);
301
+ URL.revokeObjectURL(url);
302
+ } catch (_) {
303
+ const BlobManager = require('react-native/Libraries/Blob/BlobManager.js');
304
+ let BLOB_URL_PREFIX = null;
305
+ const {
306
+ BlobModule
307
+ } = reactNative.NativeModules;
308
+ if (BlobModule && typeof BlobModule.BLOB_URI_SCHEME === 'string') {
309
+ BLOB_URL_PREFIX = BlobModule.BLOB_URI_SCHEME + ':';
310
+ if (typeof BlobModule.BLOB_URI_HOST === 'string') {
311
+ BLOB_URL_PREFIX += `//${BlobModule.BLOB_URI_HOST}/`;
318
312
  }
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;
313
+ }
314
+ URL.createObjectURL = function createObjectURL(blob) {
315
+ const data = blob.data;
316
+ if (BLOB_URL_PREFIX === null) {
317
+ // https://github.com/pmndrs/react-three-fiber/issues/3058
318
+ // throw new Error('Cannot create URL for blob!')
319
+ return `data:${blob.type};base64,${data._base64}`;
325
320
  }
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
- };
321
+ return `${BLOB_URL_PREFIX}${data.blobId}?offset=${data.offset}&size=${blob.size}`;
322
+ };
323
+ BlobManager.createFromParts = function createFromParts(parts, options) {
324
+ const blobId = uuidv4();
325
+ const items = parts.map(part => {
326
+ if (part instanceof ArrayBuffer || ArrayBuffer.isView(part)) {
327
+ const data = base64Js.fromByteArray(new Uint8Array(part));
328
+ return {
329
+ data,
330
+ type: 'string'
331
+ };
332
+ } else if (part instanceof Blob) {
333
+ return {
334
+ data: part.data,
335
+ type: 'blob'
336
+ };
337
+ } else {
338
+ return {
339
+ data: String(part),
340
+ type: 'string'
341
+ };
342
+ }
343
+ });
344
+ const size = items.reduce((acc, curr) => {
345
+ if (curr.type === 'string') {
346
+ return acc + global.unescape(encodeURI(curr.data)).length;
347
+ } else {
348
+ return acc + curr.data.size;
349
+ }
350
+ }, 0);
351
+ reactNative.NativeModules.BlobModule.createFromParts(items, blobId);
352
+ const blob = BlobManager.createFromOptions({
353
+ blobId,
354
+ offset: 0,
355
+ size,
356
+ type: options ? options.type : '',
357
+ lastModified: options ? options.lastModified : Date.now()
358
+ });
359
+ if (BLOB_URL_PREFIX === null) {
360
+ let data = '';
361
+ for (const item of items) {
362
+ var _item$data$_base;
363
+ data += (_item$data$_base = item.data._base64) != null ? _item$data$_base : item.data;
364
+ }
365
+ blob.data._base64 = data;
366
+ }
367
+ return blob;
368
+ };
369
+ }
336
370
  }
337
371
  async function getAsset(input) {
338
372
  if (typeof input === 'string') {
@@ -360,7 +394,7 @@ function polyfills() {
360
394
 
361
395
  // Create safe URI for JSI
362
396
  if (input.startsWith('data:')) {
363
- const [header, data] = input.split(',');
397
+ const [header, data] = input.split(';base64,');
364
398
  const [, type] = header.split('/');
365
399
  const uri = fs__namespace.cacheDirectory + uuidv4() + `.${type}`;
366
400
  await fs__namespace.writeAsStringAsync(uri, data, {
@@ -396,6 +430,7 @@ function polyfills() {
396
430
  this.manager.itemStart(url);
397
431
  const texture = new THREE__namespace.Texture();
398
432
  getAsset(url).then(async uri => {
433
+ // https://github.com/expo/expo-three/pull/266
399
434
  const {
400
435
  width,
401
436
  height
@@ -404,17 +439,17 @@ function polyfills() {
404
439
  height
405
440
  }), rej));
406
441
  texture.image = {
442
+ // Special case for EXGLImageUtils::loadImage
407
443
  data: {
408
444
  localUri: uri
409
445
  },
410
446
  width,
411
447
  height
412
448
  };
413
- texture.flipY = true;
414
- texture.unpackAlignment = 1;
449
+ texture.flipY = true; // Since expo-gl@12.4.0
415
450
  texture.needsUpdate = true;
416
451
 
417
- // Force non-DOM upload for EXGL fast paths
452
+ // Force non-DOM upload for EXGL texImage2D
418
453
  // @ts-ignore
419
454
  texture.isDataTexture = true;
420
455
  onLoad == null ? void 0 : onLoad(texture);
@@ -427,7 +462,7 @@ function polyfills() {
427
462
  return texture;
428
463
  };
429
464
 
430
- // Fetches assets via XMLHttpRequest
465
+ // Fetches assets via FS
431
466
  THREE__namespace.FileLoader.prototype.load = function load(url, onLoad, onProgress, onError) {
432
467
  if (this.path && typeof url === 'string') url = this.path + url;
433
468
  this.manager.itemStart(url);
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var index = require('../../dist/index-f4d4539a.cjs.prod.js');
5
+ var index = require('../../dist/index-e6d64601.cjs.prod.js');
6
6
  var _extends = require('@babel/runtime/helpers/extends');
7
7
  var React = require('react');
8
8
  var THREE = require('three');
@@ -283,6 +283,7 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(function CanvasWrapper(p
283
283
  });
284
284
 
285
285
  function polyfills() {
286
+ // http://stackoverflow.com/questions/105034
286
287
  function uuidv4() {
287
288
  return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c => {
288
289
  const r = Math.random() * 16 | 0,
@@ -292,47 +293,80 @@ function polyfills() {
292
293
  }
293
294
 
294
295
  // 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
- };
296
+ // https://github.com/facebook/react-native/pull/39276
297
+ if (reactNative.Platform.OS !== 'web') {
298
+ try {
299
+ const blob = new Blob([new ArrayBuffer(4)]);
300
+ const url = URL.createObjectURL(blob);
301
+ URL.revokeObjectURL(url);
302
+ } catch (_) {
303
+ const BlobManager = require('react-native/Libraries/Blob/BlobManager.js');
304
+ let BLOB_URL_PREFIX = null;
305
+ const {
306
+ BlobModule
307
+ } = reactNative.NativeModules;
308
+ if (BlobModule && typeof BlobModule.BLOB_URI_SCHEME === 'string') {
309
+ BLOB_URL_PREFIX = BlobModule.BLOB_URI_SCHEME + ':';
310
+ if (typeof BlobModule.BLOB_URI_HOST === 'string') {
311
+ BLOB_URL_PREFIX += `//${BlobModule.BLOB_URI_HOST}/`;
318
312
  }
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;
313
+ }
314
+ URL.createObjectURL = function createObjectURL(blob) {
315
+ const data = blob.data;
316
+ if (BLOB_URL_PREFIX === null) {
317
+ // https://github.com/pmndrs/react-three-fiber/issues/3058
318
+ // throw new Error('Cannot create URL for blob!')
319
+ return `data:${blob.type};base64,${data._base64}`;
325
320
  }
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
- };
321
+ return `${BLOB_URL_PREFIX}${data.blobId}?offset=${data.offset}&size=${blob.size}`;
322
+ };
323
+ BlobManager.createFromParts = function createFromParts(parts, options) {
324
+ const blobId = uuidv4();
325
+ const items = parts.map(part => {
326
+ if (part instanceof ArrayBuffer || ArrayBuffer.isView(part)) {
327
+ const data = base64Js.fromByteArray(new Uint8Array(part));
328
+ return {
329
+ data,
330
+ type: 'string'
331
+ };
332
+ } else if (part instanceof Blob) {
333
+ return {
334
+ data: part.data,
335
+ type: 'blob'
336
+ };
337
+ } else {
338
+ return {
339
+ data: String(part),
340
+ type: 'string'
341
+ };
342
+ }
343
+ });
344
+ const size = items.reduce((acc, curr) => {
345
+ if (curr.type === 'string') {
346
+ return acc + global.unescape(encodeURI(curr.data)).length;
347
+ } else {
348
+ return acc + curr.data.size;
349
+ }
350
+ }, 0);
351
+ reactNative.NativeModules.BlobModule.createFromParts(items, blobId);
352
+ const blob = BlobManager.createFromOptions({
353
+ blobId,
354
+ offset: 0,
355
+ size,
356
+ type: options ? options.type : '',
357
+ lastModified: options ? options.lastModified : Date.now()
358
+ });
359
+ if (BLOB_URL_PREFIX === null) {
360
+ let data = '';
361
+ for (const item of items) {
362
+ var _item$data$_base;
363
+ data += (_item$data$_base = item.data._base64) != null ? _item$data$_base : item.data;
364
+ }
365
+ blob.data._base64 = data;
366
+ }
367
+ return blob;
368
+ };
369
+ }
336
370
  }
337
371
  async function getAsset(input) {
338
372
  if (typeof input === 'string') {
@@ -360,7 +394,7 @@ function polyfills() {
360
394
 
361
395
  // Create safe URI for JSI
362
396
  if (input.startsWith('data:')) {
363
- const [header, data] = input.split(',');
397
+ const [header, data] = input.split(';base64,');
364
398
  const [, type] = header.split('/');
365
399
  const uri = fs__namespace.cacheDirectory + uuidv4() + `.${type}`;
366
400
  await fs__namespace.writeAsStringAsync(uri, data, {
@@ -396,6 +430,7 @@ function polyfills() {
396
430
  this.manager.itemStart(url);
397
431
  const texture = new THREE__namespace.Texture();
398
432
  getAsset(url).then(async uri => {
433
+ // https://github.com/expo/expo-three/pull/266
399
434
  const {
400
435
  width,
401
436
  height
@@ -404,17 +439,17 @@ function polyfills() {
404
439
  height
405
440
  }), rej));
406
441
  texture.image = {
442
+ // Special case for EXGLImageUtils::loadImage
407
443
  data: {
408
444
  localUri: uri
409
445
  },
410
446
  width,
411
447
  height
412
448
  };
413
- texture.flipY = true;
414
- texture.unpackAlignment = 1;
449
+ texture.flipY = true; // Since expo-gl@12.4.0
415
450
  texture.needsUpdate = true;
416
451
 
417
- // Force non-DOM upload for EXGL fast paths
452
+ // Force non-DOM upload for EXGL texImage2D
418
453
  // @ts-ignore
419
454
  texture.isDataTexture = true;
420
455
  onLoad == null ? void 0 : onLoad(texture);
@@ -427,7 +462,7 @@ function polyfills() {
427
462
  return texture;
428
463
  };
429
464
 
430
- // Fetches assets via XMLHttpRequest
465
+ // Fetches assets via FS
431
466
  THREE__namespace.FileLoader.prototype.load = function load(url, onLoad, onProgress, onError) {
432
467
  if (this.path && typeof url === 'string') url = this.path + url;
433
468
  this.manager.itemStart(url);
@@ -1,9 +1,9 @@
1
- import { c as createEvents, e as extend, u as useMutableCallback, b as createRoot, E as ErrorBoundary, B as Block, d as unmountComponentAtNode } from '../../dist/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 '../../dist/index-5918012a.esm.js';
1
+ import { c as createEvents, e as extend, u as useMutableCallback, b as createRoot, E as ErrorBoundary, B as Block, d as unmountComponentAtNode } from '../../dist/index-594193f5.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 '../../dist/index-594193f5.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';
6
- import { PanResponder, PixelRatio, View, StyleSheet, NativeModules, Image, Platform } from 'react-native';
6
+ import { PanResponder, PixelRatio, View, StyleSheet, Platform, NativeModules, Image } from 'react-native';
7
7
  import { GLView } from 'expo-gl';
8
8
  import { FiberProvider, useContextBridge } from 'its-fine';
9
9
  import { Asset } from 'expo-asset';
@@ -258,6 +258,7 @@ const Canvas = /*#__PURE__*/React.forwardRef(function CanvasWrapper(props, ref)
258
258
  });
259
259
 
260
260
  function polyfills() {
261
+ // http://stackoverflow.com/questions/105034
261
262
  function uuidv4() {
262
263
  return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c => {
263
264
  const r = Math.random() * 16 | 0,
@@ -267,47 +268,80 @@ function polyfills() {
267
268
  }
268
269
 
269
270
  // Patch Blob for ArrayBuffer if unsupported
270
- try {
271
- new Blob([new ArrayBuffer(4)]);
272
- } catch (_) {
273
- const BlobManager = require('react-native/Libraries/Blob/BlobManager.js');
274
- BlobManager.createFromParts = function createFromParts(parts, options) {
275
- const blobId = uuidv4();
276
- const items = parts.map(part => {
277
- if (part instanceof ArrayBuffer || ArrayBuffer.isView(part)) {
278
- const data = fromByteArray(new Uint8Array(part));
279
- return {
280
- data,
281
- type: 'string'
282
- };
283
- } else if (part instanceof Blob) {
284
- return {
285
- data: part.data,
286
- type: 'blob'
287
- };
288
- } else {
289
- return {
290
- data: String(part),
291
- type: 'string'
292
- };
271
+ // https://github.com/facebook/react-native/pull/39276
272
+ if (Platform.OS !== 'web') {
273
+ try {
274
+ const blob = new Blob([new ArrayBuffer(4)]);
275
+ const url = URL.createObjectURL(blob);
276
+ URL.revokeObjectURL(url);
277
+ } catch (_) {
278
+ const BlobManager = require('react-native/Libraries/Blob/BlobManager.js');
279
+ let BLOB_URL_PREFIX = null;
280
+ const {
281
+ BlobModule
282
+ } = NativeModules;
283
+ if (BlobModule && typeof BlobModule.BLOB_URI_SCHEME === 'string') {
284
+ BLOB_URL_PREFIX = BlobModule.BLOB_URI_SCHEME + ':';
285
+ if (typeof BlobModule.BLOB_URI_HOST === 'string') {
286
+ BLOB_URL_PREFIX += `//${BlobModule.BLOB_URI_HOST}/`;
293
287
  }
294
- });
295
- const size = items.reduce((acc, curr) => {
296
- if (curr.type === 'string') {
297
- return acc + global.unescape(encodeURI(curr.data)).length;
298
- } else {
299
- return acc + curr.data.size;
288
+ }
289
+ URL.createObjectURL = function createObjectURL(blob) {
290
+ const data = blob.data;
291
+ if (BLOB_URL_PREFIX === null) {
292
+ // https://github.com/pmndrs/react-three-fiber/issues/3058
293
+ // throw new Error('Cannot create URL for blob!')
294
+ return `data:${blob.type};base64,${data._base64}`;
300
295
  }
301
- }, 0);
302
- NativeModules.BlobModule.createFromParts(items, blobId);
303
- return BlobManager.createFromOptions({
304
- blobId,
305
- offset: 0,
306
- size,
307
- type: options ? options.type : '',
308
- lastModified: options ? options.lastModified : Date.now()
309
- });
310
- };
296
+ return `${BLOB_URL_PREFIX}${data.blobId}?offset=${data.offset}&size=${blob.size}`;
297
+ };
298
+ BlobManager.createFromParts = function createFromParts(parts, options) {
299
+ const blobId = uuidv4();
300
+ const items = parts.map(part => {
301
+ if (part instanceof ArrayBuffer || ArrayBuffer.isView(part)) {
302
+ const data = fromByteArray(new Uint8Array(part));
303
+ return {
304
+ data,
305
+ type: 'string'
306
+ };
307
+ } else if (part instanceof Blob) {
308
+ return {
309
+ data: part.data,
310
+ type: 'blob'
311
+ };
312
+ } else {
313
+ return {
314
+ data: String(part),
315
+ type: 'string'
316
+ };
317
+ }
318
+ });
319
+ const size = items.reduce((acc, curr) => {
320
+ if (curr.type === 'string') {
321
+ return acc + global.unescape(encodeURI(curr.data)).length;
322
+ } else {
323
+ return acc + curr.data.size;
324
+ }
325
+ }, 0);
326
+ NativeModules.BlobModule.createFromParts(items, blobId);
327
+ const blob = BlobManager.createFromOptions({
328
+ blobId,
329
+ offset: 0,
330
+ size,
331
+ type: options ? options.type : '',
332
+ lastModified: options ? options.lastModified : Date.now()
333
+ });
334
+ if (BLOB_URL_PREFIX === null) {
335
+ let data = '';
336
+ for (const item of items) {
337
+ var _item$data$_base;
338
+ data += (_item$data$_base = item.data._base64) != null ? _item$data$_base : item.data;
339
+ }
340
+ blob.data._base64 = data;
341
+ }
342
+ return blob;
343
+ };
344
+ }
311
345
  }
312
346
  async function getAsset(input) {
313
347
  if (typeof input === 'string') {
@@ -335,7 +369,7 @@ function polyfills() {
335
369
 
336
370
  // Create safe URI for JSI
337
371
  if (input.startsWith('data:')) {
338
- const [header, data] = input.split(',');
372
+ const [header, data] = input.split(';base64,');
339
373
  const [, type] = header.split('/');
340
374
  const uri = fs.cacheDirectory + uuidv4() + `.${type}`;
341
375
  await fs.writeAsStringAsync(uri, data, {
@@ -371,6 +405,7 @@ function polyfills() {
371
405
  this.manager.itemStart(url);
372
406
  const texture = new THREE.Texture();
373
407
  getAsset(url).then(async uri => {
408
+ // https://github.com/expo/expo-three/pull/266
374
409
  const {
375
410
  width,
376
411
  height
@@ -379,17 +414,17 @@ function polyfills() {
379
414
  height
380
415
  }), rej));
381
416
  texture.image = {
417
+ // Special case for EXGLImageUtils::loadImage
382
418
  data: {
383
419
  localUri: uri
384
420
  },
385
421
  width,
386
422
  height
387
423
  };
388
- texture.flipY = true;
389
- texture.unpackAlignment = 1;
424
+ texture.flipY = true; // Since expo-gl@12.4.0
390
425
  texture.needsUpdate = true;
391
426
 
392
- // Force non-DOM upload for EXGL fast paths
427
+ // Force non-DOM upload for EXGL texImage2D
393
428
  // @ts-ignore
394
429
  texture.isDataTexture = true;
395
430
  onLoad == null ? void 0 : onLoad(texture);
@@ -402,7 +437,7 @@ function polyfills() {
402
437
  return texture;
403
438
  };
404
439
 
405
- // Fetches assets via XMLHttpRequest
440
+ // Fetches assets via FS
406
441
  THREE.FileLoader.prototype.load = function load(url, onLoad, onProgress, onError) {
407
442
  if (this.path && typeof url === 'string') url = this.path + url;
408
443
  this.manager.itemStart(url);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-three/fiber",
3
- "version": "8.15.1",
3
+ "version": "8.15.3",
4
4
  "description": "A React renderer for Threejs",
5
5
  "keywords": [
6
6
  "react",