@loaders.gl/core 4.0.0-alpha.23 → 4.0.0-alpha.24

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 +40 -100
  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/null-worker-node.js +1 -1
  7. package/dist/null-worker.js +1 -1
  8. package/package.json +4 -7
  9. package/dist/bundle.js +0 -5
  10. package/dist/core-addons/write-file-browser.js +0 -60
  11. package/dist/index.js +0 -105
  12. package/dist/iterators/batch-iterators/timed-batch-iterator.js +0 -22
  13. package/dist/iterators/make-iterator/make-array-buffer-iterator.js +0 -27
  14. package/dist/iterators/make-iterator/make-blob-iterator.js +0 -21
  15. package/dist/iterators/make-iterator/make-iterator.js +0 -37
  16. package/dist/iterators/make-iterator/make-stream-iterator.js +0 -96
  17. package/dist/iterators/make-iterator/make-string-iterator.js +0 -24
  18. package/dist/iterators/make-stream/make-dom-stream.js +0 -47
  19. package/dist/iterators/make-stream/make-node-stream.js +0 -85
  20. package/dist/javascript-utils/is-type.js +0 -41
  21. package/dist/lib/api/encode-table.js +0 -54
  22. package/dist/lib/api/encode.js +0 -121
  23. package/dist/lib/api/load-in-batches.js +0 -40
  24. package/dist/lib/api/load.js +0 -43
  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 -54
  28. package/dist/lib/api/parse.js +0 -87
  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 -258
  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 -61
  35. package/dist/lib/fetch/fetch-file.node.js +0 -57
  36. package/dist/lib/fetch/read-array-buffer.js +0 -41
  37. package/dist/lib/fetch/read-file.js +0 -29
  38. package/dist/lib/fetch/write-file.js +0 -22
  39. package/dist/lib/filesystems/browser-filesystem.js +0 -127
  40. package/dist/lib/filesystems/read-array-buffer.js +0 -29
  41. package/dist/lib/init.js +0 -17
  42. package/dist/lib/loader-utils/check-errors.js +0 -46
  43. package/dist/lib/loader-utils/get-data.js +0 -130
  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 -44
  49. package/dist/lib/loader-utils/option-utils.js +0 -162
  50. package/dist/lib/progress/fetch-progress.js +0 -60
  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 -51
  57. package/dist/workers/null-worker.js +0 -5
@@ -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,44 +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
- useLocalLibraries: false,
13
- CDN: 'https://unpkg.com/@loaders.gl',
14
- worker: true,
15
- maxConcurrency: 3,
16
- maxMobileConcurrency: 1,
17
- reuseWorkers: loader_utils_1.isBrowser,
18
- _nodeWorkers: false,
19
- _workerType: '',
20
- limit: 0,
21
- _limitMB: 0,
22
- batchSize: 'auto',
23
- batchDebounceMs: 0,
24
- metadata: false,
25
- transforms: []
26
- };
27
- exports.REMOVED_LOADER_OPTIONS = {
28
- throws: 'nothrow',
29
- dataType: '(no longer used)',
30
- uri: 'baseUri',
31
- // Warn if fetch options are used on top-level
32
- method: 'fetch.method',
33
- headers: 'fetch.headers',
34
- body: 'fetch.body',
35
- mode: 'fetch.mode',
36
- credentials: 'fetch.credentials',
37
- cache: 'fetch.cache',
38
- redirect: 'fetch.redirect',
39
- referrer: 'fetch.referrer',
40
- referrerPolicy: 'fetch.referrerPolicy',
41
- integrity: 'fetch.integrity',
42
- keepalive: 'fetch.keepalive',
43
- signal: 'fetch.signal'
44
- };
@@ -1,162 +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
- function 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 = getGlobalLoaderOptions();
41
- // @ts-expect-error First param looks incorrect
42
- state.globalOptions = normalizeOptionsInternal(globalOptions, options);
43
- }
44
- exports.setGlobalOptions = setGlobalOptions;
45
- /**
46
- * Merges options with global opts and loader defaults, also injects baseUri
47
- * @param options
48
- * @param loader
49
- * @param loaders
50
- * @param url
51
- */
52
- function normalizeOptions(options, loader, loaders, url) {
53
- loaders = loaders || [];
54
- loaders = Array.isArray(loaders) ? loaders : [loaders];
55
- validateOptions(options, loaders);
56
- return normalizeOptionsInternal(loader, options, url);
57
- }
58
- exports.normalizeOptions = normalizeOptions;
59
- // VALIDATE OPTIONS
60
- /**
61
- * Warn for unsupported options
62
- * @param options
63
- * @param loaders
64
- */
65
- function validateOptions(options, loaders) {
66
- // Check top level options
67
- validateOptionsObject(options, null, option_defaults_1.DEFAULT_LOADER_OPTIONS, option_defaults_1.REMOVED_LOADER_OPTIONS, loaders);
68
- for (const loader of loaders) {
69
- // Get the scoped, loader specific options from the user supplied options
70
- const idOptions = ((options && options[loader.id]) || {});
71
- // Get scoped, loader specific default and deprecated options from the selected loader
72
- const loaderOptions = (loader.options && loader.options[loader.id]) || {};
73
- const deprecatedOptions = (loader.deprecatedOptions && loader.deprecatedOptions[loader.id]) || {};
74
- // Validate loader specific options
75
- // @ts-ignore
76
- validateOptionsObject(idOptions, loader.id, loaderOptions, deprecatedOptions, loaders);
77
- }
78
- }
79
- // eslint-disable-next-line max-params, complexity
80
- function validateOptionsObject(options, id, defaultOptions, deprecatedOptions, loaders) {
81
- const loaderName = id || 'Top level';
82
- const prefix = id ? `${id}.` : '';
83
- for (const key in options) {
84
- // If top level option value is an object it could options for a loader, so ignore
85
- const isSubOptions = !id && (0, is_type_1.isObject)(options[key]);
86
- const isBaseUriOption = key === 'baseUri' && !id;
87
- const isWorkerUrlOption = key === 'workerUrl' && id;
88
- // <loader>.workerUrl requires special handling as it is now auto-generated and no longer specified as a default option.
89
- if (!(key in defaultOptions) && !isBaseUriOption && !isWorkerUrlOption) {
90
- // Issue deprecation warnings
91
- if (key in deprecatedOptions) {
92
- loggers_1.probeLog.warn(`${loaderName} loader option \'${prefix}${key}\' no longer supported, use \'${deprecatedOptions[key]}\'`)();
93
- }
94
- else if (!isSubOptions) {
95
- const suggestion = findSimilarOption(key, loaders);
96
- loggers_1.probeLog.warn(`${loaderName} loader option \'${prefix}${key}\' not recognized. ${suggestion}`)();
97
- }
98
- }
99
- }
100
- }
101
- function findSimilarOption(optionKey, loaders) {
102
- const lowerCaseOptionKey = optionKey.toLowerCase();
103
- let bestSuggestion = '';
104
- for (const loader of loaders) {
105
- for (const key in loader.options) {
106
- if (optionKey === key) {
107
- return `Did you mean \'${loader.id}.${key}\'?`;
108
- }
109
- const lowerCaseKey = key.toLowerCase();
110
- const isPartialMatch = lowerCaseOptionKey.startsWith(lowerCaseKey) || lowerCaseKey.startsWith(lowerCaseOptionKey);
111
- if (isPartialMatch) {
112
- bestSuggestion = bestSuggestion || `Did you mean \'${loader.id}.${key}\'?`;
113
- }
114
- }
115
- }
116
- return bestSuggestion;
117
- }
118
- function normalizeOptionsInternal(loader, options, url) {
119
- const loaderDefaultOptions = loader.options || {};
120
- const mergedOptions = { ...loaderDefaultOptions };
121
- addUrlOptions(mergedOptions, url);
122
- // LOGGING: options.log can be set to `null` to defeat logging
123
- if (mergedOptions.log === null) {
124
- mergedOptions.log = new loggers_1.NullLog();
125
- }
126
- mergeNestedFields(mergedOptions, getGlobalLoaderOptions());
127
- mergeNestedFields(mergedOptions, options);
128
- return mergedOptions;
129
- }
130
- // Merge nested options objects
131
- function mergeNestedFields(mergedOptions, options) {
132
- for (const key in options) {
133
- // Check for nested options
134
- // object in options => either no key in defaultOptions or object in defaultOptions
135
- if (key in options) {
136
- const value = options[key];
137
- if ((0, is_type_1.isPureObject)(value) && (0, is_type_1.isPureObject)(mergedOptions[key])) {
138
- mergedOptions[key] = {
139
- ...mergedOptions[key],
140
- ...options[key]
141
- };
142
- }
143
- else {
144
- mergedOptions[key] = options[key];
145
- }
146
- }
147
- // else: No need to merge nested opts, and the initial merge already copied over the nested options
148
- }
149
- }
150
- /**
151
- * Harvest information from the url
152
- * @deprecated This is mainly there to support a hack in the GLTFLoader
153
- * TODO - baseUri should be a directory, i.e. remove file component from baseUri
154
- * TODO - extract extension?
155
- * TODO - extract query parameters?
156
- * TODO - should these be injected on context instead of options?
157
- */
158
- function addUrlOptions(options, url) {
159
- if (url && !('baseUri' in options)) {
160
- options.baseUri = url;
161
- }
162
- }
@@ -1,60 +0,0 @@
1
- "use strict";
2
- // Forked from github AnthumChris/fetch-progress-indicators under MIT license
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.fetchProgress = void 0;
5
- /**
6
- * Intercepts the Response stream and creates a new Response
7
- */
8
- async function fetchProgress(response, onProgress, // TODO better callback types
9
- onDone = () => { }, onError = () => { }) {
10
- response = await response;
11
- if (!response.ok) {
12
- // ERROR checking needs to be done separately
13
- return response;
14
- }
15
- const body = response.body;
16
- if (!body) {
17
- // 'ReadableStream not yet supported in this browser.
18
- return response;
19
- }
20
- const contentLength = response.headers.get('content-length') || 0;
21
- const totalBytes = contentLength ? parseInt(contentLength) : 0;
22
- if (!(totalBytes > 0)) {
23
- return response;
24
- }
25
- // Currently override only implemented in browser
26
- if (typeof ReadableStream === 'undefined' || !body.getReader) {
27
- return response;
28
- }
29
- // Create a new stream that invisbly wraps original stream
30
- const progressStream = new ReadableStream({
31
- async start(controller) {
32
- const reader = body.getReader();
33
- await read(controller, reader, 0, totalBytes, onProgress, onDone, onError);
34
- }
35
- });
36
- return new Response(progressStream);
37
- }
38
- exports.fetchProgress = fetchProgress;
39
- // Forward to original streams controller
40
- // TODO - this causes a crazy deep "async stack"... rewrite as async iterator?
41
- // eslint-disable-next-line max-params
42
- async function read(controller, reader, loadedBytes, totalBytes, onProgress, onDone, onError) {
43
- try {
44
- const { done, value } = await reader.read();
45
- if (done) {
46
- onDone();
47
- controller.close();
48
- return;
49
- }
50
- loadedBytes += value.byteLength;
51
- const percent = Math.round((loadedBytes / totalBytes) * 100);
52
- onProgress(percent, { loadedBytes, totalBytes });
53
- controller.enqueue(value);
54
- await read(controller, reader, loadedBytes, totalBytes, onProgress, onDone, onError);
55
- }
56
- catch (error) {
57
- controller.error(error);
58
- onError(error);
59
- }
60
- }
@@ -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;
@@ -1,90 +0,0 @@
1
- "use strict";
2
- // loaders.gl, MIT license
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.getResourceContentLength = exports.getResourceMIMEType = exports.getResourceUrl = void 0;
5
- const is_type_1 = require("../../javascript-utils/is-type");
6
- const mime_type_utils_1 = require("./mime-type-utils");
7
- const url_utils_1 = require("./url-utils");
8
- /**
9
- * Returns the URL associated with this resource.
10
- * The returned value may include a query string and need further processing.
11
- * If it cannot determine url, the corresponding value will be an empty string
12
- *
13
- * @todo string parameters are assumed to be URLs
14
- */
15
- function getResourceUrl(resource) {
16
- // If resource is a `Response`, it contains the information directly as a field
17
- if ((0, is_type_1.isResponse)(resource)) {
18
- const response = resource;
19
- return response.url;
20
- }
21
- // If the resource is a Blob or a File (subclass of Blob)
22
- if ((0, is_type_1.isBlob)(resource)) {
23
- const blob = resource;
24
- // File objects have a "name" property. Blob objects don't have any
25
- // url (name) information
26
- return blob.name || '';
27
- }
28
- if (typeof resource === 'string') {
29
- return resource;
30
- }
31
- // Unknown
32
- return '';
33
- }
34
- exports.getResourceUrl = getResourceUrl;
35
- /**
36
- * Returns the URL associated with this resource.
37
- * The returned value may include a query string and need further processing.
38
- * If it cannot determine url, the corresponding value will be an empty string
39
- *
40
- * @todo string parameters are assumed to be URLs
41
- */
42
- function getResourceMIMEType(resource) {
43
- // If resource is a response, it contains the information directly
44
- if ((0, is_type_1.isResponse)(resource)) {
45
- const response = resource;
46
- const contentTypeHeader = response.headers.get('content-type') || '';
47
- const noQueryUrl = (0, url_utils_1.stripQueryString)(response.url);
48
- return (0, mime_type_utils_1.parseMIMEType)(contentTypeHeader) || (0, mime_type_utils_1.parseMIMETypeFromURL)(noQueryUrl);
49
- }
50
- // If the resource is a Blob or a File (subclass of Blob)
51
- if ((0, is_type_1.isBlob)(resource)) {
52
- const blob = resource;
53
- return blob.type || '';
54
- }
55
- if (typeof resource === 'string') {
56
- return (0, mime_type_utils_1.parseMIMETypeFromURL)(resource);
57
- }
58
- // Unknown
59
- return '';
60
- }
61
- exports.getResourceMIMEType = getResourceMIMEType;
62
- /**
63
- * Returns (approximate) content length for a resource if it can be determined.
64
- * Returns -1 if content length cannot be determined.
65
- * @param resource
66
-
67
- * @note string parameters are NOT assumed to be URLs
68
- */
69
- function getResourceContentLength(resource) {
70
- if ((0, is_type_1.isResponse)(resource)) {
71
- const response = resource;
72
- return response.headers['content-length'] || -1;
73
- }
74
- if ((0, is_type_1.isBlob)(resource)) {
75
- const blob = resource;
76
- return blob.size;
77
- }
78
- if (typeof resource === 'string') {
79
- // TODO - handle data URL?
80
- return resource.length;
81
- }
82
- if (resource instanceof ArrayBuffer) {
83
- return resource.byteLength;
84
- }
85
- if (ArrayBuffer.isView(resource)) {
86
- return resource.byteLength;
87
- }
88
- return -1;
89
- }
90
- exports.getResourceContentLength = getResourceContentLength;
@@ -1,115 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.checkResponseSync = exports.checkResponse = exports.makeResponse = void 0;
4
- const is_type_1 = require("../../javascript-utils/is-type");
5
- const resource_utils_1 = require("./resource-utils");
6
- /**
7
- * Returns a Response object
8
- * Adds content-length header when possible
9
- *
10
- * @param resource
11
- */
12
- async function makeResponse(resource) {
13
- if ((0, is_type_1.isResponse)(resource)) {
14
- return resource;
15
- }
16
- // Add content-length header if possible
17
- const headers = {};
18
- const contentLength = (0, resource_utils_1.getResourceContentLength)(resource);
19
- if (contentLength >= 0) {
20
- headers['content-length'] = String(contentLength);
21
- }
22
- // `new Response(File)` does not preserve content-type and URL
23
- // so we add them here
24
- const url = (0, resource_utils_1.getResourceUrl)(resource);
25
- const type = (0, resource_utils_1.getResourceMIMEType)(resource);
26
- if (type) {
27
- headers['content-type'] = type;
28
- }
29
- // Add a custom header with initial bytes if available
30
- const initialDataUrl = await getInitialDataUrl(resource);
31
- if (initialDataUrl) {
32
- headers['x-first-bytes'] = initialDataUrl;
33
- }
34
- // TODO - is this the best way of handling strings?
35
- // Maybe package as data URL instead?
36
- if (typeof resource === 'string') {
37
- // Convert to ArrayBuffer to avoid Response treating it as a URL
38
- resource = new TextEncoder().encode(resource);
39
- }
40
- // Attempt to create a Response from the resource, adding headers and setting url
41
- const response = new Response(resource, { headers });
42
- // We can't control `Response.url` via constructor, use a property override to record URL.
43
- Object.defineProperty(response, 'url', { value: url });
44
- return response;
45
- }
46
- exports.makeResponse = makeResponse;
47
- /**
48
- * Checks response status (async) and throws a helpful error message if status is not OK.
49
- * @param response
50
- */
51
- async function checkResponse(response) {
52
- if (!response.ok) {
53
- const message = await getResponseError(response);
54
- throw new Error(message);
55
- }
56
- }
57
- exports.checkResponse = checkResponse;
58
- /**
59
- * Checks response status (sync) and throws a helpful error message if status is not OK.
60
- * @param response
61
- */
62
- function checkResponseSync(response) {
63
- if (!response.ok) {
64
- let message = `${response.status} ${response.statusText}`;
65
- message = message.length > 60 ? `${message.slice(0, 60)}...` : message;
66
- throw new Error(message);
67
- }
68
- }
69
- exports.checkResponseSync = checkResponseSync;
70
- // HELPERS
71
- async function getResponseError(response) {
72
- let message = `Failed to fetch resource ${response.url} (${response.status}): `;
73
- try {
74
- const contentType = response.headers.get('Content-Type');
75
- let text = response.statusText;
76
- if (contentType.includes('application/json')) {
77
- text += ` ${await response.text()}`;
78
- }
79
- message += text;
80
- message = message.length > 60 ? `${message.slice(0, 60)}...` : message;
81
- }
82
- catch (error) {
83
- // eslint forbids return in a finally statement, so we just catch here
84
- }
85
- return message;
86
- }
87
- async function getInitialDataUrl(resource) {
88
- const INITIAL_DATA_LENGTH = 5;
89
- if (typeof resource === 'string') {
90
- return `data:,${resource.slice(0, INITIAL_DATA_LENGTH)}`;
91
- }
92
- if (resource instanceof Blob) {
93
- const blobSlice = resource.slice(0, 5);
94
- return await new Promise((resolve) => {
95
- const reader = new FileReader();
96
- reader.onload = (event) => resolve(event?.target?.result);
97
- reader.readAsDataURL(blobSlice);
98
- });
99
- }
100
- if (resource instanceof ArrayBuffer) {
101
- const slice = resource.slice(0, INITIAL_DATA_LENGTH);
102
- const base64 = arrayBufferToBase64(slice);
103
- return `data:base64,${base64}`;
104
- }
105
- return null;
106
- }
107
- // https://stackoverflow.com/questions/9267899/arraybuffer-to-base64-encoded-string
108
- function arrayBufferToBase64(buffer) {
109
- let binary = '';
110
- const bytes = new Uint8Array(buffer);
111
- for (let i = 0; i < bytes.byteLength; i++) {
112
- binary += String.fromCharCode(bytes[i]);
113
- }
114
- return btoa(binary);
115
- }
@@ -1,14 +0,0 @@
1
- "use strict";
2
- // loaders.gl, MIT license
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.stripQueryString = exports.extractQueryString = void 0;
5
- const QUERY_STRING_PATTERN = /\?.*/;
6
- function extractQueryString(url) {
7
- const matches = url.match(QUERY_STRING_PATTERN);
8
- return matches && matches[0];
9
- }
10
- exports.extractQueryString = extractQueryString;
11
- function stripQueryString(url) {
12
- return url.replace(QUERY_STRING_PATTERN, '');
13
- }
14
- exports.stripQueryString = stripQueryString;
@@ -1,51 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.NullLoader = exports.NullWorkerLoader = void 0;
4
- // __VERSION__ is injected by babel-plugin-version-inline
5
- // @ts-ignore TS2304: Cannot find name '__VERSION__'.
6
- const VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';
7
- /**
8
- * Loads any data and returns null (or optionally passes through data unparsed)
9
- */
10
- exports.NullWorkerLoader = {
11
- name: 'Null loader',
12
- id: 'null',
13
- module: 'core',
14
- version: VERSION,
15
- worker: true,
16
- mimeTypes: ['application/x.empty'],
17
- extensions: ['null'],
18
- tests: [() => false],
19
- options: {
20
- null: {}
21
- }
22
- };
23
- /**
24
- * Loads any data and returns null (or optionally passes through data unparsed)
25
- */
26
- exports.NullLoader = {
27
- name: 'Null loader',
28
- id: 'null',
29
- module: 'core',
30
- version: VERSION,
31
- mimeTypes: ['application/x.empty'],
32
- extensions: ['null'],
33
- parse: async (arrayBuffer, options, context) => parseSync(arrayBuffer, options || {}, context),
34
- parseSync,
35
- parseInBatches: async function* generator(asyncIterator, options, context) {
36
- for await (const batch of asyncIterator) {
37
- yield parseSync(batch, options, context);
38
- }
39
- },
40
- tests: [() => false],
41
- options: {
42
- null: {}
43
- }
44
- };
45
- /**
46
- * Returns arguments passed to the parse API in a format that can be transferred to a
47
- * web worker. The `context` parameter is stripped using JSON.stringify & parse.
48
- */
49
- function parseSync(arrayBuffer, options, context) {
50
- return null;
51
- }
@@ -1,5 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const loader_utils_1 = require("@loaders.gl/loader-utils");
4
- const null_loader_1 = require("../null-loader");
5
- (0, loader_utils_1.createLoaderWorker)(null_loader_1.NullLoader);