@react-three/fiber 8.14.5 → 8.14.6

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,11 @@
1
1
  # @react-three/fiber
2
2
 
3
+ ## 8.14.6
4
+
5
+ ### Patch Changes
6
+
7
+ - 465fa0fb: fix(native): revert usage of networking stack
8
+
3
9
  ## 8.14.5
4
10
 
5
11
  ### Patch Changes
@@ -1 +1 @@
1
- export declare function polyfills(): void;
1
+ export declare function _polyfills(): void;
@@ -10,8 +10,7 @@ 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 fs = require('expo-file-system');
14
- var base64Js = require('base64-js');
13
+ var expoFileSystem = require('expo-file-system');
15
14
  require('react-reconciler/constants');
16
15
  require('zustand');
17
16
  require('react-reconciler');
@@ -38,7 +37,6 @@ function _interopNamespace(e) {
38
37
 
39
38
  var React__namespace = /*#__PURE__*/_interopNamespace(React);
40
39
  var THREE__namespace = /*#__PURE__*/_interopNamespace(THREE);
41
- var fs__namespace = /*#__PURE__*/_interopNamespace(fs);
42
40
 
43
41
  /** Default R3F event manager for react-native */
44
42
  function createTouchEvents(store) {
@@ -281,101 +279,22 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(function CanvasWrapper(p
281
279
  })));
282
280
  });
283
281
 
284
- function polyfills() {
285
- function uuidv4() {
286
- return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c => {
287
- const r = Math.random() * 16 | 0,
288
- v = c == 'x' ? r : r & 0x3 | 0x8;
289
- return v.toString(16);
290
- });
291
- }
292
-
293
- // Patch Blob for ArrayBuffer if unsupported
294
- if (reactNative.Platform.OS !== 'web') {
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
- }
338
- async function getAsset(input) {
339
- if (typeof input === 'string') {
340
- // Don't process storage or data uris
341
- if (input.startsWith('file:') || input.startsWith('data:')) return input;
342
-
343
- // Unpack Blobs from react-native BlobManager
344
- if (input.startsWith('blob:')) {
345
- const blob = await new Promise((res, rej) => {
346
- const xhr = new XMLHttpRequest();
347
- xhr.open('GET', input);
348
- xhr.responseType = 'blob';
349
- xhr.onload = () => res(xhr.response);
350
- xhr.onerror = rej;
351
- xhr.send();
352
- });
353
- const data = await new Promise((res, rej) => {
354
- const reader = new FileReader();
355
- reader.onload = () => res(reader.result);
356
- reader.onerror = rej;
357
- reader.readAsText(blob);
358
- });
359
- return `data:${blob.type};base64,${data}`;
360
- }
361
- }
362
-
363
- // Download bundler module or external URL
364
- const asset = await expoAsset.Asset.fromModule(input).downloadAsync();
365
- let uri = asset.localUri || asset.uri;
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;
366
286
 
367
- // Unpack assets in Android Release Mode
368
- if (!uri.includes(':')) {
369
- const file = `${fs__namespace.cacheDirectory}ExponentAsset-${asset.hash}.${asset.type}`;
370
- await fs__namespace.copyAsync({
371
- from: uri,
372
- to: file
373
- });
374
- uri = file;
375
- }
376
- return uri;
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
293
+ });
377
294
  }
378
-
295
+ return localUri;
296
+ }
297
+ function _polyfills() {
379
298
  // Don't pre-process urls, let expo-asset generate an absolute URL
380
299
  const extractUrlBase = THREE__namespace.LoaderUtils.extractUrlBase.bind(THREE__namespace.LoaderUtils);
381
300
  THREE__namespace.LoaderUtils.extractUrlBase = url => typeof url === 'string' ? extractUrlBase(url) : './';
@@ -384,26 +303,17 @@ function polyfills() {
384
303
  THREE__namespace.TextureLoader.prototype.load = function load(url, onLoad, onProgress, onError) {
385
304
  if (this.path) url = this.path + url;
386
305
  const texture = new THREE__namespace.Texture();
387
- getAsset(url).then(async uri => {
388
- // Create safe URI for JSI
389
- if (uri.startsWith('data:')) {
390
- const [header, data] = uri.split(',');
391
- const [, type] = header.split('/');
392
- uri = fs__namespace.cacheDirectory + uuidv4() + `.${type}`;
393
- await fs__namespace.writeAsStringAsync(uri, data, {
394
- encoding: fs__namespace.EncodingType.Base64
395
- });
396
- }
306
+ getAsset(url).then(async localUri => {
397
307
  const {
398
308
  width,
399
309
  height
400
- } = await new Promise((res, rej) => reactNative.Image.getSize(uri, (width, height) => res({
310
+ } = await new Promise((res, rej) => reactNative.Image.getSize(localUri, (width, height) => res({
401
311
  width,
402
312
  height
403
313
  }), rej));
404
314
  texture.image = {
405
315
  data: {
406
- localUri: uri
316
+ localUri
407
317
  },
408
318
  width,
409
319
  height
@@ -424,15 +334,8 @@ function polyfills() {
424
334
  THREE__namespace.FileLoader.prototype.load = function load(url, onLoad, onProgress, onError) {
425
335
  if (this.path) url = this.path + url;
426
336
  const request = new XMLHttpRequest();
427
- getAsset(url).then(async uri => {
428
- // Make FS paths web-safe
429
- if (uri.startsWith('file://')) {
430
- const data = await fs__namespace.readAsStringAsync(uri, {
431
- encoding: fs__namespace.EncodingType.Base64
432
- });
433
- uri = `data:application/octet-stream;base64,${data}`;
434
- }
435
- request.open('GET', uri, true);
337
+ getAsset(url).then(localUri => {
338
+ request.open('GET', localUri, true);
436
339
  request.addEventListener('load', event => {
437
340
  if (request.status === 200) {
438
341
  onLoad == null ? void 0 : onLoad(request.response);
@@ -468,7 +371,7 @@ function polyfills() {
468
371
  };
469
372
  }
470
373
 
471
- polyfills();
374
+ if (reactNative.Platform.OS !== 'web') _polyfills();
472
375
 
473
376
  exports.ReactThreeFiber = index.threeTypes;
474
377
  exports._roots = index.roots;
@@ -10,8 +10,7 @@ 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 fs = require('expo-file-system');
14
- var base64Js = require('base64-js');
13
+ var expoFileSystem = require('expo-file-system');
15
14
  require('react-reconciler/constants');
16
15
  require('zustand');
17
16
  require('react-reconciler');
@@ -38,7 +37,6 @@ function _interopNamespace(e) {
38
37
 
39
38
  var React__namespace = /*#__PURE__*/_interopNamespace(React);
40
39
  var THREE__namespace = /*#__PURE__*/_interopNamespace(THREE);
41
- var fs__namespace = /*#__PURE__*/_interopNamespace(fs);
42
40
 
43
41
  /** Default R3F event manager for react-native */
44
42
  function createTouchEvents(store) {
@@ -281,101 +279,22 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(function CanvasWrapper(p
281
279
  })));
282
280
  });
283
281
 
284
- function polyfills() {
285
- function uuidv4() {
286
- return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c => {
287
- const r = Math.random() * 16 | 0,
288
- v = c == 'x' ? r : r & 0x3 | 0x8;
289
- return v.toString(16);
290
- });
291
- }
292
-
293
- // Patch Blob for ArrayBuffer if unsupported
294
- if (reactNative.Platform.OS !== 'web') {
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
- }
338
- async function getAsset(input) {
339
- if (typeof input === 'string') {
340
- // Don't process storage or data uris
341
- if (input.startsWith('file:') || input.startsWith('data:')) return input;
342
-
343
- // Unpack Blobs from react-native BlobManager
344
- if (input.startsWith('blob:')) {
345
- const blob = await new Promise((res, rej) => {
346
- const xhr = new XMLHttpRequest();
347
- xhr.open('GET', input);
348
- xhr.responseType = 'blob';
349
- xhr.onload = () => res(xhr.response);
350
- xhr.onerror = rej;
351
- xhr.send();
352
- });
353
- const data = await new Promise((res, rej) => {
354
- const reader = new FileReader();
355
- reader.onload = () => res(reader.result);
356
- reader.onerror = rej;
357
- reader.readAsText(blob);
358
- });
359
- return `data:${blob.type};base64,${data}`;
360
- }
361
- }
362
-
363
- // Download bundler module or external URL
364
- const asset = await expoAsset.Asset.fromModule(input).downloadAsync();
365
- let uri = asset.localUri || asset.uri;
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;
366
286
 
367
- // Unpack assets in Android Release Mode
368
- if (!uri.includes(':')) {
369
- const file = `${fs__namespace.cacheDirectory}ExponentAsset-${asset.hash}.${asset.type}`;
370
- await fs__namespace.copyAsync({
371
- from: uri,
372
- to: file
373
- });
374
- uri = file;
375
- }
376
- return uri;
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
293
+ });
377
294
  }
378
-
295
+ return localUri;
296
+ }
297
+ function _polyfills() {
379
298
  // Don't pre-process urls, let expo-asset generate an absolute URL
380
299
  const extractUrlBase = THREE__namespace.LoaderUtils.extractUrlBase.bind(THREE__namespace.LoaderUtils);
381
300
  THREE__namespace.LoaderUtils.extractUrlBase = url => typeof url === 'string' ? extractUrlBase(url) : './';
@@ -384,26 +303,17 @@ function polyfills() {
384
303
  THREE__namespace.TextureLoader.prototype.load = function load(url, onLoad, onProgress, onError) {
385
304
  if (this.path) url = this.path + url;
386
305
  const texture = new THREE__namespace.Texture();
387
- getAsset(url).then(async uri => {
388
- // Create safe URI for JSI
389
- if (uri.startsWith('data:')) {
390
- const [header, data] = uri.split(',');
391
- const [, type] = header.split('/');
392
- uri = fs__namespace.cacheDirectory + uuidv4() + `.${type}`;
393
- await fs__namespace.writeAsStringAsync(uri, data, {
394
- encoding: fs__namespace.EncodingType.Base64
395
- });
396
- }
306
+ getAsset(url).then(async localUri => {
397
307
  const {
398
308
  width,
399
309
  height
400
- } = await new Promise((res, rej) => reactNative.Image.getSize(uri, (width, height) => res({
310
+ } = await new Promise((res, rej) => reactNative.Image.getSize(localUri, (width, height) => res({
401
311
  width,
402
312
  height
403
313
  }), rej));
404
314
  texture.image = {
405
315
  data: {
406
- localUri: uri
316
+ localUri
407
317
  },
408
318
  width,
409
319
  height
@@ -424,15 +334,8 @@ function polyfills() {
424
334
  THREE__namespace.FileLoader.prototype.load = function load(url, onLoad, onProgress, onError) {
425
335
  if (this.path) url = this.path + url;
426
336
  const request = new XMLHttpRequest();
427
- getAsset(url).then(async uri => {
428
- // Make FS paths web-safe
429
- if (uri.startsWith('file://')) {
430
- const data = await fs__namespace.readAsStringAsync(uri, {
431
- encoding: fs__namespace.EncodingType.Base64
432
- });
433
- uri = `data:application/octet-stream;base64,${data}`;
434
- }
435
- request.open('GET', uri, true);
337
+ getAsset(url).then(localUri => {
338
+ request.open('GET', localUri, true);
436
339
  request.addEventListener('load', event => {
437
340
  if (request.status === 200) {
438
341
  onLoad == null ? void 0 : onLoad(request.response);
@@ -468,7 +371,7 @@ function polyfills() {
468
371
  };
469
372
  }
470
373
 
471
- polyfills();
374
+ if (reactNative.Platform.OS !== 'web') _polyfills();
472
375
 
473
376
  exports.ReactThreeFiber = index.threeTypes;
474
377
  exports._roots = index.roots;
@@ -3,12 +3,11 @@ export { t as ReactThreeFiber, w as _roots, v as act, o as addAfterEffect, n as
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, Platform, NativeModules, Image } from 'react-native';
6
+ import { PanResponder, PixelRatio, View, StyleSheet, Image, Platform } 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';
10
- import * as fs from 'expo-file-system';
11
- import { fromByteArray } from 'base64-js';
10
+ import { cacheDirectory, copyAsync } from 'expo-file-system';
12
11
  import 'react-reconciler/constants';
13
12
  import 'zustand';
14
13
  import 'react-reconciler';
@@ -256,101 +255,22 @@ const Canvas = /*#__PURE__*/React.forwardRef(function CanvasWrapper(props, ref)
256
255
  })));
257
256
  });
258
257
 
259
- function polyfills() {
260
- function uuidv4() {
261
- return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c => {
262
- const r = Math.random() * 16 | 0,
263
- v = c == 'x' ? r : r & 0x3 | 0x8;
264
- return v.toString(16);
265
- });
266
- }
267
-
268
- // Patch Blob for ArrayBuffer if unsupported
269
- if (Platform.OS !== 'web') {
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
- };
293
- }
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;
300
- }
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
- };
311
- }
312
- }
313
- async function getAsset(input) {
314
- if (typeof input === 'string') {
315
- // Don't process storage or data uris
316
- if (input.startsWith('file:') || input.startsWith('data:')) return input;
317
-
318
- // Unpack Blobs from react-native BlobManager
319
- if (input.startsWith('blob:')) {
320
- const blob = await new Promise((res, rej) => {
321
- const xhr = new XMLHttpRequest();
322
- xhr.open('GET', input);
323
- xhr.responseType = 'blob';
324
- xhr.onload = () => res(xhr.response);
325
- xhr.onerror = rej;
326
- xhr.send();
327
- });
328
- const data = await new Promise((res, rej) => {
329
- const reader = new FileReader();
330
- reader.onload = () => res(reader.result);
331
- reader.onerror = rej;
332
- reader.readAsText(blob);
333
- });
334
- return `data:${blob.type};base64,${data}`;
335
- }
336
- }
337
-
338
- // Download bundler module or external URL
339
- const asset = await Asset.fromModule(input).downloadAsync();
340
- let uri = asset.localUri || asset.uri;
258
+ async function getAsset(input) {
259
+ const asset = typeof input === 'string' ? Asset.fromURI(input) : Asset.fromModule(input);
260
+ await asset.downloadAsync();
261
+ let localUri = asset.localUri || asset.uri;
341
262
 
342
- // Unpack assets in Android Release Mode
343
- if (!uri.includes(':')) {
344
- const file = `${fs.cacheDirectory}ExponentAsset-${asset.hash}.${asset.type}`;
345
- await fs.copyAsync({
346
- from: uri,
347
- to: file
348
- });
349
- uri = file;
350
- }
351
- return uri;
263
+ // Unpack assets in Android Release Mode
264
+ if (!localUri.includes('://')) {
265
+ localUri = `${cacheDirectory}ExponentAsset-${asset.hash}.${asset.type}`;
266
+ await copyAsync({
267
+ from: localUri,
268
+ to: localUri
269
+ });
352
270
  }
353
-
271
+ return localUri;
272
+ }
273
+ function _polyfills() {
354
274
  // Don't pre-process urls, let expo-asset generate an absolute URL
355
275
  const extractUrlBase = THREE.LoaderUtils.extractUrlBase.bind(THREE.LoaderUtils);
356
276
  THREE.LoaderUtils.extractUrlBase = url => typeof url === 'string' ? extractUrlBase(url) : './';
@@ -359,26 +279,17 @@ function polyfills() {
359
279
  THREE.TextureLoader.prototype.load = function load(url, onLoad, onProgress, onError) {
360
280
  if (this.path) url = this.path + url;
361
281
  const texture = new THREE.Texture();
362
- getAsset(url).then(async uri => {
363
- // Create safe URI for JSI
364
- if (uri.startsWith('data:')) {
365
- const [header, data] = uri.split(',');
366
- const [, type] = header.split('/');
367
- uri = fs.cacheDirectory + uuidv4() + `.${type}`;
368
- await fs.writeAsStringAsync(uri, data, {
369
- encoding: fs.EncodingType.Base64
370
- });
371
- }
282
+ getAsset(url).then(async localUri => {
372
283
  const {
373
284
  width,
374
285
  height
375
- } = await new Promise((res, rej) => Image.getSize(uri, (width, height) => res({
286
+ } = await new Promise((res, rej) => Image.getSize(localUri, (width, height) => res({
376
287
  width,
377
288
  height
378
289
  }), rej));
379
290
  texture.image = {
380
291
  data: {
381
- localUri: uri
292
+ localUri
382
293
  },
383
294
  width,
384
295
  height
@@ -399,15 +310,8 @@ function polyfills() {
399
310
  THREE.FileLoader.prototype.load = function load(url, onLoad, onProgress, onError) {
400
311
  if (this.path) url = this.path + url;
401
312
  const request = new XMLHttpRequest();
402
- getAsset(url).then(async uri => {
403
- // Make FS paths web-safe
404
- if (uri.startsWith('file://')) {
405
- const data = await fs.readAsStringAsync(uri, {
406
- encoding: fs.EncodingType.Base64
407
- });
408
- uri = `data:application/octet-stream;base64,${data}`;
409
- }
410
- request.open('GET', uri, true);
313
+ getAsset(url).then(localUri => {
314
+ request.open('GET', localUri, true);
411
315
  request.addEventListener('load', event => {
412
316
  if (request.status === 200) {
413
317
  onLoad == null ? void 0 : onLoad(request.response);
@@ -443,6 +347,6 @@ function polyfills() {
443
347
  };
444
348
  }
445
349
 
446
- polyfills();
350
+ if (Platform.OS !== 'web') _polyfills();
447
351
 
448
352
  export { Canvas, createTouchEvents as events };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-three/fiber",
3
- "version": "8.14.5",
3
+ "version": "8.14.6",
4
4
  "description": "A React renderer for Threejs",
5
5
  "keywords": [
6
6
  "react",