@react-three/fiber 8.15.2 → 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,11 @@
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
+
3
9
  ## 8.15.2
4
10
 
5
11
  ### Patch Changes
@@ -294,47 +294,79 @@ function polyfills() {
294
294
 
295
295
  // Patch Blob for ArrayBuffer if unsupported
296
296
  // https://github.com/facebook/react-native/pull/39276
297
- try {
298
- new Blob([new ArrayBuffer(4)]);
299
- } catch (_) {
300
- const BlobManager = require('react-native/Libraries/Blob/BlobManager.js');
301
- BlobManager.createFromParts = function createFromParts(parts, options) {
302
- const blobId = uuidv4();
303
- const items = parts.map(part => {
304
- if (part instanceof ArrayBuffer || ArrayBuffer.isView(part)) {
305
- const data = base64Js.fromByteArray(new Uint8Array(part));
306
- return {
307
- data,
308
- type: 'string'
309
- };
310
- } else if (part instanceof Blob) {
311
- return {
312
- data: part.data,
313
- type: 'blob'
314
- };
315
- } else {
316
- return {
317
- data: String(part),
318
- type: 'string'
319
- };
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}/`;
320
312
  }
321
- });
322
- const size = items.reduce((acc, curr) => {
323
- if (curr.type === 'string') {
324
- return acc + global.unescape(encodeURI(curr.data)).length;
325
- } else {
326
- 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}`;
327
320
  }
328
- }, 0);
329
- reactNative.NativeModules.BlobModule.createFromParts(items, blobId);
330
- return BlobManager.createFromOptions({
331
- blobId,
332
- offset: 0,
333
- size,
334
- type: options ? options.type : '',
335
- lastModified: options ? options.lastModified : Date.now()
336
- });
337
- };
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
+ }
338
370
  }
339
371
  async function getAsset(input) {
340
372
  if (typeof input === 'string') {
@@ -294,47 +294,79 @@ function polyfills() {
294
294
 
295
295
  // Patch Blob for ArrayBuffer if unsupported
296
296
  // https://github.com/facebook/react-native/pull/39276
297
- try {
298
- new Blob([new ArrayBuffer(4)]);
299
- } catch (_) {
300
- const BlobManager = require('react-native/Libraries/Blob/BlobManager.js');
301
- BlobManager.createFromParts = function createFromParts(parts, options) {
302
- const blobId = uuidv4();
303
- const items = parts.map(part => {
304
- if (part instanceof ArrayBuffer || ArrayBuffer.isView(part)) {
305
- const data = base64Js.fromByteArray(new Uint8Array(part));
306
- return {
307
- data,
308
- type: 'string'
309
- };
310
- } else if (part instanceof Blob) {
311
- return {
312
- data: part.data,
313
- type: 'blob'
314
- };
315
- } else {
316
- return {
317
- data: String(part),
318
- type: 'string'
319
- };
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}/`;
320
312
  }
321
- });
322
- const size = items.reduce((acc, curr) => {
323
- if (curr.type === 'string') {
324
- return acc + global.unescape(encodeURI(curr.data)).length;
325
- } else {
326
- 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}`;
327
320
  }
328
- }, 0);
329
- reactNative.NativeModules.BlobModule.createFromParts(items, blobId);
330
- return BlobManager.createFromOptions({
331
- blobId,
332
- offset: 0,
333
- size,
334
- type: options ? options.type : '',
335
- lastModified: options ? options.lastModified : Date.now()
336
- });
337
- };
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
+ }
338
370
  }
339
371
  async function getAsset(input) {
340
372
  if (typeof input === 'string') {
@@ -3,7 +3,7 @@ export { t as ReactThreeFiber, x 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, 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';
@@ -269,47 +269,79 @@ function polyfills() {
269
269
 
270
270
  // Patch Blob for ArrayBuffer if unsupported
271
271
  // https://github.com/facebook/react-native/pull/39276
272
- try {
273
- new Blob([new ArrayBuffer(4)]);
274
- } catch (_) {
275
- const BlobManager = require('react-native/Libraries/Blob/BlobManager.js');
276
- BlobManager.createFromParts = function createFromParts(parts, options) {
277
- const blobId = uuidv4();
278
- const items = parts.map(part => {
279
- if (part instanceof ArrayBuffer || ArrayBuffer.isView(part)) {
280
- const data = fromByteArray(new Uint8Array(part));
281
- return {
282
- data,
283
- type: 'string'
284
- };
285
- } else if (part instanceof Blob) {
286
- return {
287
- data: part.data,
288
- type: 'blob'
289
- };
290
- } else {
291
- return {
292
- data: String(part),
293
- type: 'string'
294
- };
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}/`;
295
287
  }
296
- });
297
- const size = items.reduce((acc, curr) => {
298
- if (curr.type === 'string') {
299
- return acc + global.unescape(encodeURI(curr.data)).length;
300
- } else {
301
- 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}`;
302
295
  }
303
- }, 0);
304
- NativeModules.BlobModule.createFromParts(items, blobId);
305
- return BlobManager.createFromOptions({
306
- blobId,
307
- offset: 0,
308
- size,
309
- type: options ? options.type : '',
310
- lastModified: options ? options.lastModified : Date.now()
311
- });
312
- };
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
+ }
313
345
  }
314
346
  async function getAsset(input) {
315
347
  if (typeof input === 'string') {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-three/fiber",
3
- "version": "8.15.2",
3
+ "version": "8.15.3",
4
4
  "description": "A React renderer for Threejs",
5
5
  "keywords": [
6
6
  "react",