@loaders.gl/core 3.4.11 → 3.4.13

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.
Files changed (57) hide show
  1. package/dist/dist.min.js +24 -72
  2. package/dist/es5/lib/init.js +1 -1
  3. package/dist/es5/null-loader.js +1 -1
  4. package/dist/esm/lib/init.js +1 -1
  5. package/dist/esm/null-loader.js +1 -1
  6. package/dist/lib/fetch/read-file.d.ts +1 -1
  7. package/dist/lib/fetch/read-file.d.ts.map +1 -1
  8. package/dist/null-worker.js +1 -1
  9. package/package.json +4 -6
  10. package/dist/bundle.js +0 -5
  11. package/dist/core-addons/write-file-browser.js +0 -60
  12. package/dist/index.js +0 -104
  13. package/dist/iterators/batch-iterators/timed-batch-iterator.js +0 -22
  14. package/dist/iterators/make-iterator/make-array-buffer-iterator.js +0 -27
  15. package/dist/iterators/make-iterator/make-blob-iterator.js +0 -21
  16. package/dist/iterators/make-iterator/make-iterator.js +0 -37
  17. package/dist/iterators/make-iterator/make-stream-iterator.js +0 -96
  18. package/dist/iterators/make-iterator/make-string-iterator.js +0 -24
  19. package/dist/iterators/make-stream/make-dom-stream.js +0 -46
  20. package/dist/iterators/make-stream/make-node-stream.js +0 -82
  21. package/dist/javascript-utils/is-type.js +0 -41
  22. package/dist/lib/api/encode.js +0 -120
  23. package/dist/lib/api/load-in-batches.js +0 -33
  24. package/dist/lib/api/load.js +0 -42
  25. package/dist/lib/api/loader-options.js +0 -7
  26. package/dist/lib/api/parse-in-batches.js +0 -117
  27. package/dist/lib/api/parse-sync.js +0 -59
  28. package/dist/lib/api/parse.js +0 -82
  29. package/dist/lib/api/register-loaders.js +0 -35
  30. package/dist/lib/api/save.js +0 -15
  31. package/dist/lib/api/select-loader.js +0 -253
  32. package/dist/lib/common.js +0 -2
  33. package/dist/lib/fetch/fetch-error-message.js +0 -25
  34. package/dist/lib/fetch/fetch-file.js +0 -27
  35. package/dist/lib/fetch/read-array-buffer.js +0 -41
  36. package/dist/lib/fetch/read-file.js +0 -29
  37. package/dist/lib/fetch/write-file.js +0 -22
  38. package/dist/lib/filesystems/browser-filesystem.js +0 -126
  39. package/dist/lib/filesystems/filesystem.js +0 -2
  40. package/dist/lib/filesystems/read-array-buffer.js +0 -29
  41. package/dist/lib/init.js +0 -16
  42. package/dist/lib/loader-utils/check-errors.js +0 -30
  43. package/dist/lib/loader-utils/get-data.js +0 -129
  44. package/dist/lib/loader-utils/get-fetch-function.js +0 -31
  45. package/dist/lib/loader-utils/loader-context.js +0 -59
  46. package/dist/lib/loader-utils/loggers.js +0 -41
  47. package/dist/lib/loader-utils/normalize-loader.js +0 -52
  48. package/dist/lib/loader-utils/option-defaults.js +0 -43
  49. package/dist/lib/loader-utils/option-utils.js +0 -160
  50. package/dist/lib/progress/fetch-progress.js +0 -59
  51. package/dist/lib/utils/log.js +0 -6
  52. package/dist/lib/utils/mime-type-utils.js +0 -42
  53. package/dist/lib/utils/resource-utils.js +0 -90
  54. package/dist/lib/utils/response-utils.js +0 -115
  55. package/dist/lib/utils/url-utils.js +0 -14
  56. package/dist/null-loader.js +0 -56
  57. package/dist/workers/null-worker.js +0 -5
@@ -1,129 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getReadableStream = exports.getAsyncIterableFromData = exports.getArrayBufferOrStringFromData = exports.getArrayBufferOrStringFromDataSync = void 0;
4
- const loader_utils_1 = require("@loaders.gl/loader-utils");
5
- const is_type_1 = require("../../javascript-utils/is-type");
6
- const make_iterator_1 = require("../../iterators/make-iterator/make-iterator");
7
- const response_utils_1 = require("../utils/response-utils");
8
- const ERR_DATA = 'Cannot convert supplied data type';
9
- // eslint-disable-next-line complexity
10
- function getArrayBufferOrStringFromDataSync(data, loader, options) {
11
- if (loader.text && typeof data === 'string') {
12
- return data;
13
- }
14
- if ((0, is_type_1.isBuffer)(data)) {
15
- // @ts-ignore
16
- data = data.buffer;
17
- }
18
- if (data instanceof ArrayBuffer) {
19
- const arrayBuffer = data;
20
- if (loader.text && !loader.binary) {
21
- const textDecoder = new TextDecoder('utf8');
22
- return textDecoder.decode(arrayBuffer);
23
- }
24
- return arrayBuffer;
25
- }
26
- // We may need to handle offsets
27
- if (ArrayBuffer.isView(data)) {
28
- // TextDecoder is invoked on typed arrays and will handle offsets
29
- if (loader.text && !loader.binary) {
30
- const textDecoder = new TextDecoder('utf8');
31
- return textDecoder.decode(data);
32
- }
33
- let arrayBuffer = data.buffer;
34
- // Since we are returning the underlying arrayBuffer, we must create a new copy
35
- // if this typed array / Buffer is a partial view into the ArryayBuffer
36
- // TODO - this is a potentially unnecessary copy
37
- const byteLength = data.byteLength || data.length;
38
- if (data.byteOffset !== 0 || byteLength !== arrayBuffer.byteLength) {
39
- // console.warn(`loaders.gl copying arraybuffer of length ${byteLength}`);
40
- arrayBuffer = arrayBuffer.slice(data.byteOffset, data.byteOffset + byteLength);
41
- }
42
- return arrayBuffer;
43
- }
44
- throw new Error(ERR_DATA);
45
- }
46
- exports.getArrayBufferOrStringFromDataSync = getArrayBufferOrStringFromDataSync;
47
- // Convert async iterator to a promise
48
- async function getArrayBufferOrStringFromData(data, loader, options) {
49
- const isArrayBuffer = data instanceof ArrayBuffer || ArrayBuffer.isView(data);
50
- if (typeof data === 'string' || isArrayBuffer) {
51
- return getArrayBufferOrStringFromDataSync(data, loader, options);
52
- }
53
- // Blobs and files are FileReader compatible
54
- if ((0, is_type_1.isBlob)(data)) {
55
- data = await (0, response_utils_1.makeResponse)(data);
56
- }
57
- if ((0, is_type_1.isResponse)(data)) {
58
- const response = data;
59
- await (0, response_utils_1.checkResponse)(response);
60
- return loader.binary ? await response.arrayBuffer() : await response.text();
61
- }
62
- if ((0, is_type_1.isReadableStream)(data)) {
63
- // @ts-expect-error TS2559 options type
64
- data = (0, make_iterator_1.makeIterator)(data, options);
65
- }
66
- if ((0, is_type_1.isIterable)(data) || (0, is_type_1.isAsyncIterable)(data)) {
67
- // Assume arrayBuffer iterator - attempt to concatenate
68
- return (0, loader_utils_1.concatenateArrayBuffersAsync)(data);
69
- }
70
- throw new Error(ERR_DATA);
71
- }
72
- exports.getArrayBufferOrStringFromData = getArrayBufferOrStringFromData;
73
- async function getAsyncIterableFromData(data, options) {
74
- if ((0, is_type_1.isIterator)(data)) {
75
- return data;
76
- }
77
- if ((0, is_type_1.isResponse)(data)) {
78
- const response = data;
79
- // Note Since this function is not async, we currently can't load error message, just status
80
- await (0, response_utils_1.checkResponse)(response);
81
- // TODO - bug in polyfill, body can be a Promise under Node.js
82
- // eslint-disable-next-line @typescript-eslint/await-thenable
83
- const body = await response.body;
84
- // TODO - body can be null?
85
- return (0, make_iterator_1.makeIterator)(body, options);
86
- }
87
- if ((0, is_type_1.isBlob)(data) || (0, is_type_1.isReadableStream)(data)) {
88
- return (0, make_iterator_1.makeIterator)(data, options);
89
- }
90
- if ((0, is_type_1.isAsyncIterable)(data)) {
91
- return data[Symbol.asyncIterator]();
92
- }
93
- return getIterableFromData(data);
94
- }
95
- exports.getAsyncIterableFromData = getAsyncIterableFromData;
96
- async function getReadableStream(data) {
97
- if ((0, is_type_1.isReadableStream)(data)) {
98
- return data;
99
- }
100
- if ((0, is_type_1.isResponse)(data)) {
101
- // @ts-ignore
102
- return data.body;
103
- }
104
- const response = await (0, response_utils_1.makeResponse)(data);
105
- // @ts-ignore
106
- return response.body;
107
- }
108
- exports.getReadableStream = getReadableStream;
109
- // HELPERS
110
- function getIterableFromData(data) {
111
- // generate an iterator that emits a single chunk
112
- if (ArrayBuffer.isView(data)) {
113
- return (function* oneChunk() {
114
- yield data.buffer;
115
- })();
116
- }
117
- if (data instanceof ArrayBuffer) {
118
- return (function* oneChunk() {
119
- yield data;
120
- })();
121
- }
122
- if ((0, is_type_1.isIterator)(data)) {
123
- return data;
124
- }
125
- if ((0, is_type_1.isIterable)(data)) {
126
- return data[Symbol.iterator]();
127
- }
128
- throw new Error(ERR_DATA);
129
- }
@@ -1,31 +0,0 @@
1
- "use strict";
2
- // loaders.gl, MIT license
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.getFetchFunction = void 0;
5
- const is_type_1 = require("../../javascript-utils/is-type");
6
- const fetch_file_1 = require("../fetch/fetch-file");
7
- const option_utils_1 = require("./option-utils");
8
- /**
9
- * Gets the current fetch function from options and context
10
- * @param options
11
- * @param context
12
- */
13
- function getFetchFunction(options, context) {
14
- const globalOptions = (0, option_utils_1.getGlobalLoaderOptions)();
15
- const fetchOptions = options || globalOptions;
16
- // options.fetch can be a function
17
- if (typeof fetchOptions.fetch === 'function') {
18
- return fetchOptions.fetch;
19
- }
20
- // options.fetch can be an options object
21
- if ((0, is_type_1.isObject)(fetchOptions.fetch)) {
22
- return (url) => (0, fetch_file_1.fetchFile)(url, fetchOptions);
23
- }
24
- // else refer to context (from parent loader) if available
25
- if (context?.fetch) {
26
- return context?.fetch;
27
- }
28
- // else return the default fetch function
29
- return fetch_file_1.fetchFile;
30
- }
31
- exports.getFetchFunction = getFetchFunction;
@@ -1,59 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getLoadersFromContext = exports.getLoaderContext = void 0;
4
- const get_fetch_function_1 = require("./get-fetch-function");
5
- const url_utils_1 = require("../utils/url-utils");
6
- const loader_utils_1 = require("@loaders.gl/loader-utils");
7
- /**
8
- * "sub" loaders invoked by other loaders get a "context" injected on `this`
9
- * The context will inject core methods like `parse` and contain information
10
- * about loaders and options passed in to the top-level `parse` call.
11
- *
12
- * @param context
13
- * @param options
14
- * @param previousContext
15
- */
16
- function getLoaderContext(context, options, parentContext) {
17
- // For recursive calls, we already have a context
18
- // TODO - add any additional loaders to context?
19
- if (parentContext) {
20
- return parentContext;
21
- }
22
- const newContext = {
23
- fetch: (0, get_fetch_function_1.getFetchFunction)(options, context),
24
- ...context
25
- };
26
- // Parse URLs so that subloaders can easily generate correct strings
27
- if (newContext.url) {
28
- const baseUrl = (0, url_utils_1.stripQueryString)(newContext.url);
29
- newContext.baseUrl = baseUrl;
30
- newContext.queryString = (0, url_utils_1.extractQueryString)(newContext.url);
31
- newContext.filename = loader_utils_1.path.filename(baseUrl);
32
- newContext.baseUrl = loader_utils_1.path.dirname(baseUrl);
33
- }
34
- // Recursive loading does not use single loader
35
- if (!Array.isArray(newContext.loaders)) {
36
- newContext.loaders = null;
37
- }
38
- return newContext;
39
- }
40
- exports.getLoaderContext = getLoaderContext;
41
- // eslint-disable-next-line complexity
42
- function getLoadersFromContext(loaders, context) {
43
- // A single non-array loader is force selected, but only on top-level (context === null)
44
- if (!context && loaders && !Array.isArray(loaders)) {
45
- return loaders;
46
- }
47
- // Create a merged list
48
- let candidateLoaders;
49
- if (loaders) {
50
- candidateLoaders = Array.isArray(loaders) ? loaders : [loaders];
51
- }
52
- if (context && context.loaders) {
53
- const contextLoaders = Array.isArray(context.loaders) ? context.loaders : [context.loaders];
54
- candidateLoaders = candidateLoaders ? [...candidateLoaders, ...contextLoaders] : contextLoaders;
55
- }
56
- // If no loaders, return null to look in globally registered loaders
57
- return candidateLoaders && candidateLoaders.length ? candidateLoaders : null;
58
- }
59
- exports.getLoadersFromContext = getLoadersFromContext;
@@ -1,41 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ConsoleLog = exports.NullLog = exports.probeLog = void 0;
4
- // probe.gl Log compatible loggers
5
- const log_1 = require("@probe.gl/log");
6
- exports.probeLog = new log_1.Log({ id: 'loaders.gl' });
7
- // Logs nothing
8
- class NullLog {
9
- log() {
10
- return () => { };
11
- }
12
- info() {
13
- return () => { };
14
- }
15
- warn() {
16
- return () => { };
17
- }
18
- error() {
19
- return () => { };
20
- }
21
- }
22
- exports.NullLog = NullLog;
23
- // Logs to console
24
- class ConsoleLog {
25
- constructor() {
26
- this.console = console; // eslint-disable-line
27
- }
28
- log(...args) {
29
- return this.console.log.bind(this.console, ...args);
30
- }
31
- info(...args) {
32
- return this.console.info.bind(this.console, ...args);
33
- }
34
- warn(...args) {
35
- return this.console.warn.bind(this.console, ...args);
36
- }
37
- error(...args) {
38
- return this.console.error.bind(this.console, ...args);
39
- }
40
- }
41
- exports.ConsoleLog = ConsoleLog;
@@ -1,52 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.normalizeLoader = exports.isLoaderObject = void 0;
4
- const loader_utils_1 = require("@loaders.gl/loader-utils");
5
- function isLoaderObject(loader) {
6
- if (!loader) {
7
- return false;
8
- }
9
- if (Array.isArray(loader)) {
10
- loader = loader[0];
11
- }
12
- const hasExtensions = Array.isArray(loader?.extensions);
13
- /* Now handled by types and worker loaders do not have these
14
- let hasParser =
15
- loader.parseTextSync ||
16
- loader.parseSync ||
17
- loader.parse ||
18
- loader.parseStream || // TODO Remove, Replace with parseInBatches
19
- loader.parseInBatches;
20
- */
21
- return hasExtensions;
22
- }
23
- exports.isLoaderObject = isLoaderObject;
24
- function normalizeLoader(loader) {
25
- // This error is fairly easy to trigger by mixing up import statements etc
26
- // So we make an exception and add a developer error message for this case
27
- // To help new users from getting stuck here
28
- (0, loader_utils_1.assert)(loader, 'null loader');
29
- (0, loader_utils_1.assert)(isLoaderObject(loader), 'invalid loader');
30
- // NORMALIZE [LOADER, OPTIONS] => LOADER
31
- // If [loader, options], create a new loaders object with options merged in
32
- let options;
33
- if (Array.isArray(loader)) {
34
- options = loader[1];
35
- loader = loader[0];
36
- loader = {
37
- ...loader,
38
- options: { ...loader.options, ...options }
39
- };
40
- }
41
- // NORMALIZE text and binary flags
42
- // Ensure at least one of text/binary flags are properly set
43
- // @ts-expect-error
44
- if (loader?.parseTextSync || loader?.parseText) {
45
- loader.text = true;
46
- }
47
- if (!loader.text) {
48
- loader.binary = true;
49
- }
50
- return loader;
51
- }
52
- exports.normalizeLoader = normalizeLoader;
@@ -1,43 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.REMOVED_LOADER_OPTIONS = exports.DEFAULT_LOADER_OPTIONS = void 0;
4
- const loader_utils_1 = require("@loaders.gl/loader-utils");
5
- const loggers_1 = require("./loggers");
6
- exports.DEFAULT_LOADER_OPTIONS = {
7
- // baseUri
8
- fetch: null,
9
- mimeType: undefined,
10
- nothrow: false,
11
- log: new loggers_1.ConsoleLog(),
12
- CDN: 'https://unpkg.com/@loaders.gl',
13
- worker: true,
14
- maxConcurrency: 3,
15
- maxMobileConcurrency: 1,
16
- reuseWorkers: loader_utils_1.isBrowser,
17
- _nodeWorkers: false,
18
- _workerType: '',
19
- limit: 0,
20
- _limitMB: 0,
21
- batchSize: 'auto',
22
- batchDebounceMs: 0,
23
- metadata: false,
24
- transforms: []
25
- };
26
- exports.REMOVED_LOADER_OPTIONS = {
27
- throws: 'nothrow',
28
- dataType: '(no longer used)',
29
- uri: 'baseUri',
30
- // Warn if fetch options are used on top-level
31
- method: 'fetch.method',
32
- headers: 'fetch.headers',
33
- body: 'fetch.body',
34
- mode: 'fetch.mode',
35
- credentials: 'fetch.credentials',
36
- cache: 'fetch.cache',
37
- redirect: 'fetch.redirect',
38
- referrer: 'fetch.referrer',
39
- referrerPolicy: 'fetch.referrerPolicy',
40
- integrity: 'fetch.integrity',
41
- keepalive: 'fetch.keepalive',
42
- signal: 'fetch.signal'
43
- };
@@ -1,160 +0,0 @@
1
- "use strict";
2
- // loaders.gl, MIT license
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.normalizeOptions = exports.setGlobalOptions = exports.getGlobalLoaderOptions = exports.getGlobalLoaderState = void 0;
5
- const is_type_1 = require("../../javascript-utils/is-type");
6
- const loggers_1 = require("./loggers");
7
- const option_defaults_1 = require("./option-defaults");
8
- /**
9
- * Helper for safely accessing global loaders.gl variables
10
- * Wraps initialization of global variable in function to defeat overly aggressive tree-shakers
11
- */
12
- function getGlobalLoaderState() {
13
- // @ts-ignore
14
- globalThis.loaders = globalThis.loaders || {};
15
- // @ts-ignore
16
- const { loaders } = globalThis;
17
- // Add _state object to keep separate from modules added to globalThis.loaders
18
- loaders._state = loaders._state || {};
19
- return loaders._state;
20
- }
21
- exports.getGlobalLoaderState = getGlobalLoaderState;
22
- /**
23
- * Store global loader options on the global object to increase chances of cross loaders-version interoperability
24
- * NOTE: This use case is not reliable but can help when testing new versions of loaders.gl with existing frameworks
25
- * @returns global loader options merged with default loader options
26
- */
27
- const getGlobalLoaderOptions = () => {
28
- const state = getGlobalLoaderState();
29
- // Ensure all default loader options from this library are mentioned
30
- state.globalOptions = state.globalOptions || { ...option_defaults_1.DEFAULT_LOADER_OPTIONS };
31
- return state.globalOptions;
32
- };
33
- exports.getGlobalLoaderOptions = getGlobalLoaderOptions;
34
- /**
35
- * Set global loader options
36
- * @param options
37
- */
38
- function setGlobalOptions(options) {
39
- const state = getGlobalLoaderState();
40
- const globalOptions = (0, exports.getGlobalLoaderOptions)();
41
- state.globalOptions = normalizeOptionsInternal(globalOptions, options);
42
- }
43
- exports.setGlobalOptions = setGlobalOptions;
44
- /**
45
- * Merges options with global opts and loader defaults, also injects baseUri
46
- * @param options
47
- * @param loader
48
- * @param loaders
49
- * @param url
50
- */
51
- function normalizeOptions(options, loader, loaders, url) {
52
- loaders = loaders || [];
53
- loaders = Array.isArray(loaders) ? loaders : [loaders];
54
- validateOptions(options, loaders);
55
- return normalizeOptionsInternal(loader, options, url);
56
- }
57
- exports.normalizeOptions = normalizeOptions;
58
- // VALIDATE OPTIONS
59
- /**
60
- * Warn for unsupported options
61
- * @param options
62
- * @param loaders
63
- */
64
- function validateOptions(options, loaders) {
65
- // Check top level options
66
- validateOptionsObject(options, null, option_defaults_1.DEFAULT_LOADER_OPTIONS, option_defaults_1.REMOVED_LOADER_OPTIONS, loaders);
67
- for (const loader of loaders) {
68
- // Get the scoped, loader specific options from the user supplied options
69
- const idOptions = (options && options[loader.id]) || {};
70
- // Get scoped, loader specific default and deprecated options from the selected loader
71
- const loaderOptions = (loader.options && loader.options[loader.id]) || {};
72
- const deprecatedOptions = (loader.deprecatedOptions && loader.deprecatedOptions[loader.id]) || {};
73
- // Validate loader specific options
74
- validateOptionsObject(idOptions, loader.id, loaderOptions, deprecatedOptions, loaders);
75
- }
76
- }
77
- // eslint-disable-next-line max-params, complexity
78
- function validateOptionsObject(options, id, defaultOptions, deprecatedOptions, loaders) {
79
- const loaderName = id || 'Top level';
80
- const prefix = id ? `${id}.` : '';
81
- for (const key in options) {
82
- // If top level option value is an object it could options for a loader, so ignore
83
- const isSubOptions = !id && (0, is_type_1.isObject)(options[key]);
84
- const isBaseUriOption = key === 'baseUri' && !id;
85
- const isWorkerUrlOption = key === 'workerUrl' && id;
86
- // <loader>.workerUrl requires special handling as it is now auto-generated and no longer specified as a default option.
87
- if (!(key in defaultOptions) && !isBaseUriOption && !isWorkerUrlOption) {
88
- // Issue deprecation warnings
89
- if (key in deprecatedOptions) {
90
- loggers_1.probeLog.warn(`${loaderName} loader option \'${prefix}${key}\' no longer supported, use \'${deprecatedOptions[key]}\'`)();
91
- }
92
- else if (!isSubOptions) {
93
- const suggestion = findSimilarOption(key, loaders);
94
- loggers_1.probeLog.warn(`${loaderName} loader option \'${prefix}${key}\' not recognized. ${suggestion}`)();
95
- }
96
- }
97
- }
98
- }
99
- function findSimilarOption(optionKey, loaders) {
100
- const lowerCaseOptionKey = optionKey.toLowerCase();
101
- let bestSuggestion = '';
102
- for (const loader of loaders) {
103
- for (const key in loader.options) {
104
- if (optionKey === key) {
105
- return `Did you mean \'${loader.id}.${key}\'?`;
106
- }
107
- const lowerCaseKey = key.toLowerCase();
108
- const isPartialMatch = lowerCaseOptionKey.startsWith(lowerCaseKey) || lowerCaseKey.startsWith(lowerCaseOptionKey);
109
- if (isPartialMatch) {
110
- bestSuggestion = bestSuggestion || `Did you mean \'${loader.id}.${key}\'?`;
111
- }
112
- }
113
- }
114
- return bestSuggestion;
115
- }
116
- function normalizeOptionsInternal(loader, options, url) {
117
- const loaderDefaultOptions = loader.options || {};
118
- const mergedOptions = { ...loaderDefaultOptions };
119
- addUrlOptions(mergedOptions, url);
120
- // LOGGING: options.log can be set to `null` to defeat logging
121
- if (mergedOptions.log === null) {
122
- mergedOptions.log = new loggers_1.NullLog();
123
- }
124
- mergeNestedFields(mergedOptions, (0, exports.getGlobalLoaderOptions)());
125
- mergeNestedFields(mergedOptions, options);
126
- return mergedOptions;
127
- }
128
- // Merge nested options objects
129
- function mergeNestedFields(mergedOptions, options) {
130
- for (const key in options) {
131
- // Check for nested options
132
- // object in options => either no key in defaultOptions or object in defaultOptions
133
- if (key in options) {
134
- const value = options[key];
135
- if ((0, is_type_1.isPureObject)(value) && (0, is_type_1.isPureObject)(mergedOptions[key])) {
136
- mergedOptions[key] = {
137
- ...mergedOptions[key],
138
- ...options[key]
139
- };
140
- }
141
- else {
142
- mergedOptions[key] = options[key];
143
- }
144
- }
145
- // else: No need to merge nested opts, and the initial merge already copied over the nested options
146
- }
147
- }
148
- /**
149
- * Harvest information from the url
150
- * @deprecated This is mainly there to support a hack in the GLTFLoader
151
- * TODO - baseUri should be a directory, i.e. remove file component from baseUri
152
- * TODO - extract extension?
153
- * TODO - extract query parameters?
154
- * TODO - should these be injected on context instead of options?
155
- */
156
- function addUrlOptions(options, url) {
157
- if (url && !('baseUri' in options)) {
158
- options.baseUri = url;
159
- }
160
- }
@@ -1,59 +0,0 @@
1
- "use strict";
2
- // Forked from github AnthumChris/fetch-progress-indicators under MIT license
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- /**
5
- * Intercepts the Response stream and creates a new Response
6
- */
7
- async function fetchProgress(response, onProgress, // TODO better callback types
8
- onDone = () => { }, onError = () => { }) {
9
- response = await response;
10
- if (!response.ok) {
11
- // ERROR checking needs to be done separately
12
- return response;
13
- }
14
- const body = response.body;
15
- if (!body) {
16
- // 'ReadableStream not yet supported in this browser.
17
- return response;
18
- }
19
- const contentLength = response.headers.get('content-length') || 0;
20
- const totalBytes = contentLength ? parseInt(contentLength) : 0;
21
- if (!(totalBytes > 0)) {
22
- return response;
23
- }
24
- // Currently override only implemented in browser
25
- if (typeof ReadableStream === 'undefined' || !body.getReader) {
26
- return response;
27
- }
28
- // Create a new stream that invisbly wraps original stream
29
- const progressStream = new ReadableStream({
30
- async start(controller) {
31
- const reader = body.getReader();
32
- await read(controller, reader, 0, totalBytes, onProgress, onDone, onError);
33
- }
34
- });
35
- return new Response(progressStream);
36
- }
37
- exports.default = fetchProgress;
38
- // Forward to original streams controller
39
- // TODO - this causes a crazy deep "async stack"... rewrite as async iterator?
40
- // eslint-disable-next-line max-params
41
- async function read(controller, reader, loadedBytes, totalBytes, onProgress, onDone, onError) {
42
- try {
43
- const { done, value } = await reader.read();
44
- if (done) {
45
- onDone();
46
- controller.close();
47
- return;
48
- }
49
- loadedBytes += value.byteLength;
50
- const percent = Math.round((loadedBytes / totalBytes) * 100);
51
- onProgress(percent, { loadedBytes, totalBytes });
52
- controller.enqueue(value);
53
- await read(controller, reader, loadedBytes, totalBytes, onProgress, onDone, onError);
54
- }
55
- catch (error) {
56
- controller.error(error);
57
- onError(error);
58
- }
59
- }
@@ -1,6 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.log = void 0;
4
- // loaders.gl, MIT license
5
- const log_1 = require("@probe.gl/log");
6
- exports.log = new log_1.Log({ id: 'loaders.gl' });
@@ -1,42 +0,0 @@
1
- "use strict";
2
- // TODO - build/integrate proper MIME type parsing
3
- // https://mimesniff.spec.whatwg.org/
4
- Object.defineProperty(exports, "__esModule", { value: true });
5
- exports.parseMIMETypeFromURL = exports.parseMIMEType = void 0;
6
- const DATA_URL_PATTERN = /^data:([-\w.]+\/[-\w.+]+)(;|,)/;
7
- const MIME_TYPE_PATTERN = /^([-\w.]+\/[-\w.+]+)/;
8
- /**
9
- * Remove extra data like `charset` from MIME types
10
- * @param mimeString
11
- * @returns A clean MIME type, or an empty string
12
- *
13
- * @todo - handle more advanced MIMETYpes, multiple types
14
- * @todo - extract charset etc
15
- */
16
- function parseMIMEType(mimeString) {
17
- // If resource is a data url, extract any embedded mime type
18
- const matches = MIME_TYPE_PATTERN.exec(mimeString);
19
- if (matches) {
20
- return matches[1];
21
- }
22
- return mimeString;
23
- }
24
- exports.parseMIMEType = parseMIMEType;
25
- /**
26
- * Extract MIME type from data URL
27
- *
28
- * @param mimeString
29
- * @returns A clean MIME type, or an empty string
30
- *
31
- * @todo - handle more advanced MIMETYpes, multiple types
32
- * @todo - extract charset etc
33
- */
34
- function parseMIMETypeFromURL(url) {
35
- // If resource is a data URL, extract any embedded mime type
36
- const matches = DATA_URL_PATTERN.exec(url);
37
- if (matches) {
38
- return matches[1];
39
- }
40
- return '';
41
- }
42
- exports.parseMIMETypeFromURL = parseMIMETypeFromURL;