UNPKG

@loaders.gl/core

Version:

Framework-independent loaders for 3D graphics formats

39 lines (33 loc) 1.28 kB
import _typeof from "@babel/runtime/helpers/esm/typeof"; import assert from '../utils/assert'; export function getTransferList(object) { var recursive = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true; var transfers = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : []; if (!object) {} else if (object instanceof ArrayBuffer) { transfers.push(object); } else if (object.buffer && object.buffer instanceof ArrayBuffer) { transfers.push(object.buffer); } else if (recursive && _typeof(object) === 'object') { for (var key in object) { getTransferList(object[key], recursive, transfers); } } return transfers; } var workerURLCache = new Map(); export function getWorkerURL(workerSource) { assert(typeof workerSource === 'string', 'worker source'); if (workerSource.startsWith('url(') && workerSource.endsWith(')')) { return workerSource.match(/^url\((.*)\)$/)[1]; } var workerURL = workerURLCache.get(workerSource); if (!workerURL) { var blob = new Blob([workerSource], { type: 'application/javascript' }); workerURL = URL.createObjectURL(blob); workerURLCache.set(workerSource, workerURL); } return workerURL; } //# sourceMappingURL=worker-utils.js.map